mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Add QPDFObjectHandle::newStream(QPDF *, std::string const&)
This makes the code simpler than having to create a buffer of a fixed size and copy the string to it.
This commit is contained in:
parent
75054c0b94
commit
43c404b45a
@ -65,10 +65,7 @@ static QPDFObjectHandle createPageContents(QPDF& pdf, std::string const& text)
|
||||
std::string contents =
|
||||
"BT /F1 24 Tf 72 720 Td (" + text + ") Tj ET\n"
|
||||
"q 144 0 0 144 234 324 cm /Im1 Do Q\n";
|
||||
PointerHolder<Buffer> b = new Buffer(contents.length());
|
||||
unsigned char* bp = b->getBuffer();
|
||||
memcpy(bp, (char*)contents.c_str(), contents.length());
|
||||
return QPDFObjectHandle::newStream(&pdf, b);
|
||||
return QPDFObjectHandle::newStream(&pdf, contents);
|
||||
}
|
||||
|
||||
QPDFObjectHandle newName(std::string const& name)
|
||||
|
@ -142,6 +142,12 @@ class QPDFObjectHandle
|
||||
QPDF_DLL
|
||||
static QPDFObjectHandle newStream(QPDF* qpdf, PointerHolder<Buffer> data);
|
||||
|
||||
// Create new stream with data from string. This method will
|
||||
// create a copy of the data rather than using the user-provided
|
||||
// buffer as in the PointerHolder<Buffer> version of newStream.
|
||||
QPDF_DLL
|
||||
static QPDFObjectHandle newStream(QPDF* qpdf, std::string const& data);
|
||||
|
||||
// Accessor methods. If an accessor method that is valid for only
|
||||
// a particular object type is called on an object of the wrong
|
||||
// type, an exception is thrown.
|
||||
|
@ -680,6 +680,15 @@ QPDFObjectHandle::newStream(QPDF* qpdf, PointerHolder<Buffer> data)
|
||||
return result;
|
||||
}
|
||||
|
||||
QPDFObjectHandle
|
||||
QPDFObjectHandle::newStream(QPDF* qpdf, std::string const& data)
|
||||
{
|
||||
PointerHolder<Buffer> b = new Buffer(data.length());
|
||||
unsigned char* bp = b->getBuffer();
|
||||
memcpy(bp, (char*)data.c_str(), data.length());
|
||||
return QPDFObjectHandle::newStream(qpdf, b);
|
||||
}
|
||||
|
||||
QPDFObjectHandle
|
||||
QPDFObjectHandle::shallowCopy()
|
||||
{
|
||||
|
@ -21,10 +21,7 @@ void usage()
|
||||
static QPDFObjectHandle createPageContents(QPDF& pdf, std::string const& text)
|
||||
{
|
||||
std::string contents = "BT /F1 15 Tf 72 720 Td (" + text + ") Tj ET\n";
|
||||
PointerHolder<Buffer> b = new Buffer(contents.length());
|
||||
unsigned char* bp = b->getBuffer();
|
||||
memcpy(bp, (char*)contents.c_str(), contents.length());
|
||||
return QPDFObjectHandle::newStream(&pdf, b);
|
||||
return QPDFObjectHandle::newStream(&pdf, contents);
|
||||
}
|
||||
|
||||
QPDFObjectHandle newName(std::string const& name)
|
||||
|
@ -73,10 +73,7 @@ static void checkPageContents(QPDFObjectHandle page,
|
||||
static QPDFObjectHandle createPageContents(QPDF& pdf, std::string const& text)
|
||||
{
|
||||
std::string contents = "BT /F1 15 Tf 72 720 Td (" + text + ") Tj ET\n";
|
||||
PointerHolder<Buffer> b = new Buffer(contents.length());
|
||||
unsigned char* bp = b->getBuffer();
|
||||
memcpy(bp, (char*)contents.c_str(), contents.length());
|
||||
return QPDFObjectHandle::newStream(&pdf, b);
|
||||
return QPDFObjectHandle::newStream(&pdf, contents);
|
||||
}
|
||||
|
||||
void runtest(int n, char const* filename)
|
||||
|
@ -173,11 +173,7 @@ std::string generate_page_contents(int pageno)
|
||||
|
||||
static QPDFObjectHandle create_page_contents(QPDF& pdf, int pageno)
|
||||
{
|
||||
std::string contents = generate_page_contents(pageno);
|
||||
PointerHolder<Buffer> b = new Buffer(contents.length());
|
||||
unsigned char* bp = b->getBuffer();
|
||||
memcpy(bp, (char*)contents.c_str(), contents.length());
|
||||
return QPDFObjectHandle::newStream(&pdf, b);
|
||||
return QPDFObjectHandle::newStream(&pdf, generate_page_contents(pageno));
|
||||
}
|
||||
|
||||
QPDFObjectHandle newName(std::string const& name)
|
||||
|
Loading…
Reference in New Issue
Block a user