mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 19:08:59 +00:00
update code to new PointerHolder, and reintroduce change that was accidentally backed out
git-svn-id: svn+q:///qpdf/trunk@1031 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
parent
ce8b1ba6a5
commit
a7e269537d
@ -66,7 +66,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
// Copy text into a buffer without the null terminator
|
||||
PointerHolder<Buffer> b = new Buffer(strlen(content));
|
||||
unsigned char* bp = b.getPointer()->getBuffer();
|
||||
unsigned char* bp = b->getBuffer();
|
||||
memcpy(bp, (unsigned char*)content, strlen(content));
|
||||
|
||||
try
|
||||
|
@ -48,8 +48,8 @@ ImageInverter::provideStreamData(int objid, int generation,
|
||||
// image data. Then invert the image data and write the inverted
|
||||
// data to the pipeline.
|
||||
PointerHolder<Buffer> data = this->image_data[objid][generation];
|
||||
size_t size = data.getPointer()->getSize();
|
||||
unsigned char* buf = data.getPointer()->getBuffer();
|
||||
size_t size = data->getSize();
|
||||
unsigned char* buf = data->getBuffer();
|
||||
unsigned char ch;
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
@ -142,8 +142,7 @@ int main(int argc, char* argv[])
|
||||
p,
|
||||
QPDFObjectHandle::newNull(),
|
||||
QPDFObjectHandle::newNull(),
|
||||
inv->image_data[objid][gen].getPointer()->
|
||||
getSize());
|
||||
inv->image_data[objid][gen]->getSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,9 +51,8 @@ Pl_Buffer::getBuffer()
|
||||
unsigned char* p = b->getBuffer();
|
||||
while (! this->data.empty())
|
||||
{
|
||||
PointerHolder<Buffer> bph = this->data.front();
|
||||
PointerHolder<Buffer> bp = this->data.front();
|
||||
this->data.pop_front();
|
||||
Buffer* bp = bph.getPointer();
|
||||
size_t bytes = bp->getSize();
|
||||
memcpy(p, bp->getBuffer(), bytes);
|
||||
p += bytes;
|
||||
|
@ -854,7 +854,7 @@ QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj)
|
||||
int expected_size = entry_size * num_entries;
|
||||
|
||||
PointerHolder<Buffer> bp = xref_obj.getStreamData();
|
||||
int actual_size = bp.getPointer()->getSize();
|
||||
int actual_size = bp->getSize();
|
||||
|
||||
if (expected_size != actual_size)
|
||||
{
|
||||
@ -878,7 +878,7 @@ QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj)
|
||||
|
||||
bool saw_first_compressed_object = false;
|
||||
|
||||
unsigned char const* data = bp.getPointer()->getBuffer();
|
||||
unsigned char const* data = bp->getBuffer();
|
||||
for (int i = 0; i < num_entries; ++i)
|
||||
{
|
||||
// Read this entry
|
||||
@ -1200,6 +1200,20 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
|
||||
olist.pop_back();
|
||||
olist.pop_back();
|
||||
}
|
||||
else if ((value == "endobj") &&
|
||||
(! (in_array || in_dictionary)))
|
||||
{
|
||||
// Nothing in the PDF spec appears to allow empty
|
||||
// objects, but they have been encountered in
|
||||
// actual PDF files and Adobe Reader appears to
|
||||
// ignore them.
|
||||
warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(),
|
||||
this->last_object_description,
|
||||
input->getLastOffset(),
|
||||
"empty object treated as null"));
|
||||
object = QPDFObjectHandle::newNull();
|
||||
input->seek(input->getLastOffset(), SEEK_SET);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw QPDFExc(qpdf_e_damaged_pdf, input->getName(),
|
||||
|
@ -528,7 +528,7 @@ std::string
|
||||
QPDFObjectHandle::unparseResolved()
|
||||
{
|
||||
dereference();
|
||||
return this->obj.getPointer()->unparse();
|
||||
return this->obj->unparse();
|
||||
}
|
||||
|
||||
QPDFObjectHandle
|
||||
|
@ -527,8 +527,7 @@ QPDFWriter::writeString(std::string const& str)
|
||||
void
|
||||
QPDFWriter::writeBuffer(PointerHolder<Buffer>& b)
|
||||
{
|
||||
this->pipeline->write(b.getPointer()->getBuffer(),
|
||||
b.getPointer()->getSize());
|
||||
this->pipeline->write(b->getBuffer(), b->getSize());
|
||||
}
|
||||
|
||||
void
|
||||
@ -1038,7 +1037,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
|
||||
compress = false;
|
||||
}
|
||||
|
||||
this->cur_stream_length = stream_data.getPointer()->getSize();
|
||||
this->cur_stream_length = stream_data->getSize();
|
||||
if (is_metadata && this->encrypted && (! this->encrypt_metadata))
|
||||
{
|
||||
// Don't encrypt stream data for the metadata stream
|
||||
@ -1226,7 +1225,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
|
||||
writeStringQDF("\n ");
|
||||
writeString(" /Type /ObjStm");
|
||||
writeStringQDF("\n ");
|
||||
unsigned long length = stream_buffer.getPointer()->getSize();
|
||||
unsigned long length = stream_buffer->getSize();
|
||||
adjustAESStreamLength(length);
|
||||
writeString(" /Length " + QUtil::int_to_string(length));
|
||||
writeStringQDF("\n ");
|
||||
@ -1718,8 +1717,8 @@ QPDFWriter::writeHintStream(int hint_id)
|
||||
openObject(hint_id);
|
||||
setDataKey(hint_id);
|
||||
|
||||
unsigned char* hs = hint_buffer.getPointer()->getBuffer();
|
||||
unsigned long hlen = hint_buffer.getPointer()->getSize();
|
||||
unsigned char* hs = hint_buffer->getBuffer();
|
||||
unsigned long hlen = hint_buffer->getSize();
|
||||
|
||||
writeString("<< /Filter /FlateDecode /S ");
|
||||
writeString(QUtil::int_to_string(S));
|
||||
@ -1888,8 +1887,7 @@ QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset,
|
||||
writeStringQDF("\n ");
|
||||
writeString(" /Type /XRef");
|
||||
writeStringQDF("\n ");
|
||||
writeString(" /Length " +
|
||||
QUtil::int_to_string(xref_data.getPointer()->getSize()));
|
||||
writeString(" /Length " + QUtil::int_to_string(xref_data->getSize()));
|
||||
if (compressed)
|
||||
{
|
||||
writeStringQDF("\n ");
|
||||
@ -2251,7 +2249,7 @@ QPDFWriter::writeLinearized()
|
||||
activatePipelineStack();
|
||||
writeHintStream(hint_id);
|
||||
popPipelineStack(&hint_buffer);
|
||||
hint_length = hint_buffer.getPointer()->getSize();
|
||||
hint_length = hint_buffer->getSize();
|
||||
|
||||
// Restore hint offset
|
||||
this->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0);
|
||||
|
@ -370,16 +370,15 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter,
|
||||
if (this->stream_data.getPointer())
|
||||
{
|
||||
QTC::TC("qpdf", "QPDF_Stream pipe replaced stream data");
|
||||
Buffer& b = *(this->stream_data.getPointer());
|
||||
pipeline->write(b.getBuffer(), b.getSize());
|
||||
pipeline->write(this->stream_data->getBuffer(),
|
||||
this->stream_data->getSize());
|
||||
pipeline->finish();
|
||||
}
|
||||
else if (this->stream_provider.getPointer())
|
||||
{
|
||||
QPDFObjectHandle::StreamDataProvider& p =
|
||||
(*this->stream_provider.getPointer());
|
||||
Pl_Count count("stream provider count", pipeline);
|
||||
p.provideStreamData(this->objid, this->generation, &count);
|
||||
this->stream_provider->provideStreamData(
|
||||
this->objid, this->generation, &count);
|
||||
size_t actual_length = count.getCount();
|
||||
size_t desired_length =
|
||||
this->stream_dict.getKey("/Length").getIntValue();
|
||||
@ -424,7 +423,7 @@ QPDF_Stream::replaceStreamData(PointerHolder<Buffer> data,
|
||||
{
|
||||
this->stream_data = data;
|
||||
this->stream_provider = 0;
|
||||
replaceFilterData(filter, decode_parms, data.getPointer()->getSize());
|
||||
replaceFilterData(filter, decode_parms, data->getSize());
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -571,8 +571,7 @@ QPDF::decryptString(std::string& str, int objid, int generation)
|
||||
pl.write((unsigned char*)str.c_str(), str.length());
|
||||
pl.finish();
|
||||
PointerHolder<Buffer> buf = bufpl.getBuffer();
|
||||
str = std::string((char*)buf.getPointer()->getBuffer(),
|
||||
(size_t)buf.getPointer()->getSize());
|
||||
str = std::string((char*)buf->getBuffer(), (size_t)buf->getSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -176,7 +176,7 @@ char const* qpdf_get_error_full_text(qpdf_data qpdf, qpdf_error e)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return e->exc.getPointer()->what();
|
||||
return e->exc->what();
|
||||
}
|
||||
|
||||
enum qpdf_error_code_e qpdf_get_error_code(qpdf_data qpdf, qpdf_error e)
|
||||
@ -185,7 +185,7 @@ enum qpdf_error_code_e qpdf_get_error_code(qpdf_data qpdf, qpdf_error e)
|
||||
{
|
||||
return qpdf_e_success;
|
||||
}
|
||||
return e->exc.getPointer()->getErrorCode();
|
||||
return e->exc->getErrorCode();
|
||||
}
|
||||
|
||||
char const* qpdf_get_error_filename(qpdf_data qpdf, qpdf_error e)
|
||||
@ -194,7 +194,7 @@ char const* qpdf_get_error_filename(qpdf_data qpdf, qpdf_error e)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return e->exc.getPointer()->getFilename().c_str();
|
||||
return e->exc->getFilename().c_str();
|
||||
}
|
||||
|
||||
unsigned long qpdf_get_error_file_position(qpdf_data qpdf, qpdf_error e)
|
||||
@ -203,7 +203,7 @@ unsigned long qpdf_get_error_file_position(qpdf_data qpdf, qpdf_error e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return e->exc.getPointer()->getFilePosition();
|
||||
return e->exc->getFilePosition();
|
||||
}
|
||||
|
||||
char const* qpdf_get_error_message_detail(qpdf_data qpdf, qpdf_error e)
|
||||
@ -212,7 +212,7 @@ char const* qpdf_get_error_message_detail(qpdf_data qpdf, qpdf_error e)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return e->exc.getPointer()->getMessageDetail().c_str();
|
||||
return e->exc->getMessageDetail().c_str();
|
||||
}
|
||||
|
||||
void qpdf_set_suppress_warnings(qpdf_data qpdf, QPDF_BOOL value)
|
||||
|
@ -37,8 +37,7 @@ class Provider: public QPDFObjectHandle::StreamDataProvider
|
||||
virtual void provideStreamData(int objid, int generation,
|
||||
Pipeline* p)
|
||||
{
|
||||
p->write(b.getPointer()->getBuffer(),
|
||||
b.getPointer()->getSize());
|
||||
p->write(b->getBuffer(), b->getSize());
|
||||
if (this->bad_length)
|
||||
{
|
||||
unsigned char ch = ' ';
|
||||
@ -352,7 +351,7 @@ void runtest(int n, char const* filename)
|
||||
throw std::logic_error("test 7 run on file with no QStream");
|
||||
}
|
||||
PointerHolder<Buffer> b = new Buffer(20);
|
||||
unsigned char* bp = b.getPointer()->getBuffer();
|
||||
unsigned char* bp = b->getBuffer();
|
||||
memcpy(bp, (char*)"new data for stream\n", 20); // no null!
|
||||
qstream.replaceStreamData(
|
||||
b, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
|
||||
@ -380,8 +379,7 @@ void runtest(int n, char const* filename)
|
||||
PointerHolder<QPDFObjectHandle::StreamDataProvider> p = provider;
|
||||
qstream.replaceStreamData(
|
||||
p, QPDFObjectHandle::newName("/FlateDecode"),
|
||||
QPDFObjectHandle::newNull(),
|
||||
b.getPointer()->getSize());
|
||||
QPDFObjectHandle::newNull(), b->getSize());
|
||||
provider->badLength(true);
|
||||
try
|
||||
{
|
||||
@ -402,7 +400,7 @@ void runtest(int n, char const* filename)
|
||||
{
|
||||
QPDFObjectHandle root = pdf.getRoot();
|
||||
PointerHolder<Buffer> b1 = new Buffer(20);
|
||||
unsigned char* bp = b1.getPointer()->getBuffer();
|
||||
unsigned char* bp = b1->getBuffer();
|
||||
memcpy(bp, (char*)"data for new stream\n", 20); // no null!
|
||||
QPDFObjectHandle qstream = QPDFObjectHandle::newStream(&pdf, b1);
|
||||
QPDFObjectHandle rstream = QPDFObjectHandle::newStream(&pdf);
|
||||
@ -416,7 +414,7 @@ void runtest(int n, char const* filename)
|
||||
std::cout << "exception: " << e.what() << std::endl;
|
||||
}
|
||||
PointerHolder<Buffer> b2 = new Buffer(22);
|
||||
bp = b2.getPointer()->getBuffer();
|
||||
bp = b2->getBuffer();
|
||||
memcpy(bp, (char*)"data for other stream\n", 22); // no null!
|
||||
rstream.replaceStreamData(
|
||||
b2, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
|
||||
@ -430,10 +428,10 @@ void runtest(int n, char const* filename)
|
||||
else if (n == 10)
|
||||
{
|
||||
PointerHolder<Buffer> b1 = new Buffer(37);
|
||||
unsigned char* bp = b1.getPointer()->getBuffer();
|
||||
unsigned char* bp = b1->getBuffer();
|
||||
memcpy(bp, (char*)"BT /F1 12 Tf 72 620 Td (Baked) Tj ET\n", 37);
|
||||
PointerHolder<Buffer> b2 = new Buffer(38);
|
||||
bp = b2.getPointer()->getBuffer();
|
||||
bp = b2->getBuffer();
|
||||
memcpy(bp, (char*)"BT /F1 18 Tf 72 520 Td (Mashed) Tj ET\n", 38);
|
||||
|
||||
std::vector<QPDFObjectHandle> pages = pdf.getAllPages();
|
||||
@ -451,13 +449,13 @@ void runtest(int n, char const* filename)
|
||||
QPDFObjectHandle qstream = root.getKey("/QStream");
|
||||
PointerHolder<Buffer> b1 = qstream.getStreamData();
|
||||
PointerHolder<Buffer> b2 = qstream.getRawStreamData();
|
||||
if ((b1.getPointer()->getSize() == 7) &&
|
||||
(memcmp(b1.getPointer()->getBuffer(), "potato\n", 7) == 0))
|
||||
if ((b1->getSize() == 7) &&
|
||||
(memcmp(b1->getBuffer(), "potato\n", 7) == 0))
|
||||
{
|
||||
std::cout << "filtered stream data okay" << std::endl;
|
||||
}
|
||||
if ((b2.getPointer()->getSize() == 15) &&
|
||||
(memcmp(b2.getPointer()->getBuffer(), "706F7461746F0A\n", 15) == 0))
|
||||
if ((b2->getSize() == 15) &&
|
||||
(memcmp(b2->getBuffer(), "706F7461746F0A\n", 15) == 0))
|
||||
{
|
||||
std::cout << "raw stream data okay" << std::endl;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user