mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 19:08:59 +00:00
Code clean up: use range-style for loops wherever possible
Where not possible, use "auto" to get the iterator type. Editorial note: I have avoid this change for a long time because of not wanting to make gratuitous changes to version history, which can obscure when certain changes were made, but with having recently touched every single file to apply automatic code formatting and with making several broad changes to the API, I decided it was time to take the plunge and get rid of the older (pre-C++11) verbose iterator syntax. The new code is just easier to read and understand, and in many cases, it will be more effecient as fewer temporary copies are being made. m-holger, if you're reading, you can see that I've finally come around. :-)
This commit is contained in:
parent
7f023701dd
commit
4f24617e1e
@ -193,15 +193,12 @@ main(int argc, char* argv[])
|
|||||||
pdf.processFile(infilename);
|
pdf.processFile(infilename);
|
||||||
std::vector<QPDFPageObjectHelper> pages =
|
std::vector<QPDFPageObjectHelper> pages =
|
||||||
QPDFPageDocumentHelper(pdf).getAllPages();
|
QPDFPageDocumentHelper(pdf).getAllPages();
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& page: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
// Attach two token filters to each page of this file.
|
// Attach two token filters to each page of this file.
|
||||||
// When the file is written, or when the pages' contents
|
// When the file is written, or when the pages' contents
|
||||||
// are retrieved in any other way, the filters will be
|
// are retrieved in any other way, the filters will be
|
||||||
// applied. See comments on the filters for additional
|
// applied. See comments on the filters for additional
|
||||||
// details.
|
// details.
|
||||||
QPDFPageObjectHelper& page(*iter);
|
|
||||||
page.addContentTokenFilter(
|
page.addContentTokenFilter(
|
||||||
std::shared_ptr<QPDFObjectHandle::TokenFilter>(
|
std::shared_ptr<QPDFObjectHandle::TokenFilter>(
|
||||||
new StringReverser));
|
new StringReverser));
|
||||||
|
@ -131,14 +131,11 @@ main(int argc, char* argv[])
|
|||||||
// For each page...
|
// For each page...
|
||||||
std::vector<QPDFPageObjectHelper> pages =
|
std::vector<QPDFPageObjectHelper> pages =
|
||||||
QPDFPageDocumentHelper(qpdf).getAllPages();
|
QPDFPageDocumentHelper(qpdf).getAllPages();
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& page: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFPageObjectHelper& page(*iter);
|
|
||||||
// Get all images on the page.
|
// Get all images on the page.
|
||||||
std::map<std::string, QPDFObjectHandle> images = page.getImages();
|
std::map<std::string, QPDFObjectHandle> images = page.getImages();
|
||||||
for (auto& iter2: images) {
|
for (auto& iter: images) {
|
||||||
QPDFObjectHandle& image = iter2.second;
|
QPDFObjectHandle& image = iter.second;
|
||||||
QPDFObjectHandle image_dict = image.getDict();
|
QPDFObjectHandle image_dict = image.getDict();
|
||||||
QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace");
|
QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace");
|
||||||
QPDFObjectHandle bits_per_component =
|
QPDFObjectHandle bits_per_component =
|
||||||
|
@ -132,10 +132,7 @@ main(int argc, char* argv[])
|
|||||||
QPDFObjectHandle filetrailer = file.getTrailer();
|
QPDFObjectHandle filetrailer = file.getTrailer();
|
||||||
QPDFObjectHandle fileinfo;
|
QPDFObjectHandle fileinfo;
|
||||||
|
|
||||||
for (std::map<std::string, std::string>::const_iterator it =
|
for (auto const& it: Keys) {
|
||||||
Keys.begin();
|
|
||||||
Keys.end() != it;
|
|
||||||
++it) {
|
|
||||||
if (!fileinfo.isInitialized()) {
|
if (!fileinfo.isInitialized()) {
|
||||||
if (filetrailer.hasKey("/Info")) {
|
if (filetrailer.hasKey("/Info")) {
|
||||||
QTC::TC("examples", "pdf-mod-info has info");
|
QTC::TC("examples", "pdf-mod-info has info");
|
||||||
@ -146,12 +143,12 @@ main(int argc, char* argv[])
|
|||||||
filetrailer.replaceKey("/Info", fileinfo);
|
filetrailer.replaceKey("/Info", fileinfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (it->second == "") {
|
if (it.second == "") {
|
||||||
fileinfo.removeKey(it->first);
|
fileinfo.removeKey(it.first);
|
||||||
} else {
|
} else {
|
||||||
QPDFObjectHandle elt = fileinfo.newString(it->second);
|
QPDFObjectHandle elt = fileinfo.newString(it.second);
|
||||||
elt.makeDirect();
|
elt.makeDirect();
|
||||||
fileinfo.replaceKey(it->first, elt);
|
fileinfo.replaceKey(it.first, elt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QPDFWriter w(file, fl_tmp.c_str());
|
QPDFWriter w(file, fl_tmp.c_str());
|
||||||
|
@ -42,11 +42,7 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile)
|
|||||||
// For each page...
|
// For each page...
|
||||||
std::vector<QPDFPageObjectHelper> pages =
|
std::vector<QPDFPageObjectHelper> pages =
|
||||||
QPDFPageDocumentHelper(inpdf).getAllPages();
|
QPDFPageDocumentHelper(inpdf).getAllPages();
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& ph: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFPageObjectHelper& ph = *iter;
|
|
||||||
|
|
||||||
// Find a unique resource name for the new form XObject
|
// Find a unique resource name for the new form XObject
|
||||||
QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
|
QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
|
||||||
int min_suffix = 1;
|
int min_suffix = 1;
|
||||||
|
@ -52,23 +52,17 @@ main(int argc, char* argv[])
|
|||||||
QPDFAcroFormDocumentHelper afdh(qpdf);
|
QPDFAcroFormDocumentHelper afdh(qpdf);
|
||||||
QPDFPageDocumentHelper pdh(qpdf);
|
QPDFPageDocumentHelper pdh(qpdf);
|
||||||
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator page_iter =
|
for (auto const& page: pages) {
|
||||||
pages.begin();
|
|
||||||
page_iter != pages.end();
|
|
||||||
++page_iter) {
|
|
||||||
// Get all widget annotations for each page. Widget
|
// Get all widget annotations for each page. Widget
|
||||||
// annotations are the ones that contain the details of
|
// annotations are the ones that contain the details of
|
||||||
// what's in a form field.
|
// what's in a form field.
|
||||||
std::vector<QPDFAnnotationObjectHelper> annotations =
|
std::vector<QPDFAnnotationObjectHelper> annotations =
|
||||||
afdh.getWidgetAnnotationsForPage(*page_iter);
|
afdh.getWidgetAnnotationsForPage(page);
|
||||||
for (std::vector<QPDFAnnotationObjectHelper>::iterator annot_iter =
|
for (auto& annot: annotations) {
|
||||||
annotations.begin();
|
|
||||||
annot_iter != annotations.end();
|
|
||||||
++annot_iter) {
|
|
||||||
// For each annotation, find its associated field. If
|
// For each annotation, find its associated field. If
|
||||||
// it's a text field, set its value.
|
// it's a text field, set its value.
|
||||||
QPDFFormFieldObjectHelper ffh =
|
QPDFFormFieldObjectHelper ffh =
|
||||||
afdh.getFieldForAnnotation(*annot_iter);
|
afdh.getFieldForAnnotation(annot);
|
||||||
if (ffh.getFieldType() == "/Tx") {
|
if (ffh.getFieldType() == "/Tx") {
|
||||||
// Set the value. Passing false as the second
|
// Set the value. Passing false as the second
|
||||||
// value prevents qpdf from setting
|
// value prevents qpdf from setting
|
||||||
@ -81,7 +75,7 @@ main(int argc, char* argv[])
|
|||||||
// additional details, please see comments in
|
// additional details, please see comments in
|
||||||
// QPDFFormFieldObjectHelper.hh for this method.
|
// QPDFFormFieldObjectHelper.hh for this method.
|
||||||
ffh.setV(value, false);
|
ffh.setV(value, false);
|
||||||
ffh.generateAppearance(*annot_iter);
|
ffh.generateAppearance(annot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,7 @@ process(char const* whoami, char const* infile, std::string outprefix)
|
|||||||
int pageno_len =
|
int pageno_len =
|
||||||
QIntC::to_int(QUtil::uint_to_string(pages.size()).length());
|
QIntC::to_int(QUtil::uint_to_string(pages.size()).length());
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& page: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFPageObjectHelper& page(*iter);
|
|
||||||
std::string outfile =
|
std::string outfile =
|
||||||
outprefix + QUtil::int_to_string(++pageno, pageno_len) + ".pdf";
|
outprefix + QUtil::int_to_string(++pageno, pageno_len) + ".pdf";
|
||||||
QPDF outpdf;
|
QPDF outpdf;
|
||||||
|
@ -134,10 +134,7 @@ FuzzHelper::testPages()
|
|||||||
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
||||||
DiscardContents discard_contents;
|
DiscardContents discard_contents;
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& page: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFPageObjectHelper& page(*iter);
|
|
||||||
++pageno;
|
++pageno;
|
||||||
try {
|
try {
|
||||||
page.coalesceContentStreams();
|
page.coalesceContentStreams();
|
||||||
@ -150,11 +147,7 @@ FuzzHelper::testPages()
|
|||||||
|
|
||||||
std::vector<QPDFAnnotationObjectHelper> annotations =
|
std::vector<QPDFAnnotationObjectHelper> annotations =
|
||||||
afdh.getWidgetAnnotationsForPage(page);
|
afdh.getWidgetAnnotationsForPage(page);
|
||||||
for (std::vector<QPDFAnnotationObjectHelper>::iterator annot_iter =
|
for (auto& aoh: annotations) {
|
||||||
annotations.begin();
|
|
||||||
annot_iter != annotations.end();
|
|
||||||
++annot_iter) {
|
|
||||||
QPDFAnnotationObjectHelper& aoh = *annot_iter;
|
|
||||||
afdh.getFieldForAnnotation(aoh);
|
afdh.getFieldForAnnotation(aoh);
|
||||||
}
|
}
|
||||||
} catch (QPDFExc& e) {
|
} catch (QPDFExc& e) {
|
||||||
@ -172,11 +165,7 @@ FuzzHelper::testOutlines()
|
|||||||
queue.push_back(odh.getTopLevelOutlines());
|
queue.push_back(odh.getTopLevelOutlines());
|
||||||
while (!queue.empty()) {
|
while (!queue.empty()) {
|
||||||
std::vector<QPDFOutlineObjectHelper>& outlines = *(queue.begin());
|
std::vector<QPDFOutlineObjectHelper>& outlines = *(queue.begin());
|
||||||
for (std::vector<QPDFOutlineObjectHelper>::iterator iter =
|
for (auto& ol: outlines) {
|
||||||
outlines.begin();
|
|
||||||
iter != outlines.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFOutlineObjectHelper& ol = *iter;
|
|
||||||
ol.getDestPage();
|
ol.getDestPage();
|
||||||
queue.push_back(ol.getKids());
|
queue.push_back(ol.getKids());
|
||||||
}
|
}
|
||||||
|
119
libqpdf/QPDF.cc
119
libqpdf/QPDF.cc
@ -262,11 +262,8 @@ QPDF::~QPDF()
|
|||||||
// have the effect of undoing any modifications that may have been
|
// have the effect of undoing any modifications that may have been
|
||||||
// made to any of the objects.
|
// made to any of the objects.
|
||||||
this->m->xref_table.clear();
|
this->m->xref_table.clear();
|
||||||
for (std::map<QPDFObjGen, ObjCache>::iterator iter =
|
for (auto const& iter: this->m->obj_cache) {
|
||||||
this->m->obj_cache.begin();
|
QPDFObject::ObjAccessor::releaseResolved(iter.second.object.get());
|
||||||
iter != this->m->obj_cache.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObject::ObjAccessor::releaseResolved((*iter).second.object.get());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,18 +574,13 @@ QPDF::reconstruct_xref(QPDFExc& e)
|
|||||||
|
|
||||||
// Delete all references to type 1 (uncompressed) objects
|
// Delete all references to type 1 (uncompressed) objects
|
||||||
std::set<QPDFObjGen> to_delete;
|
std::set<QPDFObjGen> to_delete;
|
||||||
for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter =
|
for (auto const& iter: this->m->xref_table) {
|
||||||
this->m->xref_table.begin();
|
if (iter.second.getType() == 1) {
|
||||||
iter != this->m->xref_table.end();
|
to_delete.insert(iter.first);
|
||||||
++iter) {
|
|
||||||
if (((*iter).second).getType() == 1) {
|
|
||||||
to_delete.insert((*iter).first);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (std::set<QPDFObjGen>::iterator iter = to_delete.begin();
|
for (auto const& iter: to_delete) {
|
||||||
iter != to_delete.end();
|
this->m->xref_table.erase(iter);
|
||||||
++iter) {
|
|
||||||
this->m->xref_table.erase(*iter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->m->file->seek(0, SEEK_END);
|
this->m->file->seek(0, SEEK_END);
|
||||||
@ -1015,10 +1007,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle any deleted items now that we've read the /XRefStm.
|
// Handle any deleted items now that we've read the /XRefStm.
|
||||||
for (std::vector<QPDFObjGen>::iterator iter = deleted_items.begin();
|
for (auto const& og: deleted_items) {
|
||||||
iter != deleted_items.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjGen& og = *iter;
|
|
||||||
insertXrefEntry(og.getObj(), 0, 0, og.getGen());
|
insertXrefEntry(og.getObj(), 0, 0, og.getGen());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1351,12 +1340,9 @@ QPDF::insertXrefEntry(int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite)
|
|||||||
void
|
void
|
||||||
QPDF::showXRefTable()
|
QPDF::showXRefTable()
|
||||||
{
|
{
|
||||||
for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter =
|
for (auto const& iter: this->m->xref_table) {
|
||||||
this->m->xref_table.begin();
|
QPDFObjGen const& og = iter.first;
|
||||||
iter != this->m->xref_table.end();
|
QPDFXRefEntry const& entry = iter.second;
|
||||||
++iter) {
|
|
||||||
QPDFObjGen const& og = (*iter).first;
|
|
||||||
QPDFXRefEntry const& entry = (*iter).second;
|
|
||||||
*this->m->out_stream << og.getObj() << "/" << og.getGen() << ": ";
|
*this->m->out_stream << og.getObj() << "/" << og.getGen() << ": ";
|
||||||
switch (entry.getType()) {
|
switch (entry.getType()) {
|
||||||
case 1:
|
case 1:
|
||||||
@ -1390,27 +1376,19 @@ QPDF::fixDanglingReferences(bool force)
|
|||||||
// Create a set of all known indirect objects including those
|
// Create a set of all known indirect objects including those
|
||||||
// we've previously resolved and those that we have created.
|
// we've previously resolved and those that we have created.
|
||||||
std::set<QPDFObjGen> to_process;
|
std::set<QPDFObjGen> to_process;
|
||||||
for (std::map<QPDFObjGen, ObjCache>::iterator iter =
|
for (auto const& iter: this->m->obj_cache) {
|
||||||
this->m->obj_cache.begin();
|
to_process.insert(iter.first);
|
||||||
iter != this->m->obj_cache.end();
|
|
||||||
++iter) {
|
|
||||||
to_process.insert((*iter).first);
|
|
||||||
}
|
}
|
||||||
for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter =
|
for (auto const& iter: this->m->xref_table) {
|
||||||
this->m->xref_table.begin();
|
to_process.insert(iter.first);
|
||||||
iter != this->m->xref_table.end();
|
|
||||||
++iter) {
|
|
||||||
to_process.insert((*iter).first);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For each non-scalar item to process, put it in the queue.
|
// For each non-scalar item to process, put it in the queue.
|
||||||
std::list<QPDFObjectHandle> queue;
|
std::list<QPDFObjectHandle> queue;
|
||||||
queue.push_back(this->m->trailer);
|
queue.push_back(this->m->trailer);
|
||||||
for (std::set<QPDFObjGen>::iterator iter = to_process.begin();
|
for (auto const& iter: to_process) {
|
||||||
iter != to_process.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle obj = QPDFObjectHandle::Factory::newIndirect(
|
QPDFObjectHandle obj = QPDFObjectHandle::Factory::newIndirect(
|
||||||
this, (*iter).getObj(), (*iter).getGen());
|
this, iter.getObj(), iter.getGen());
|
||||||
if (obj.isDictionary() || obj.isArray()) {
|
if (obj.isDictionary() || obj.isArray()) {
|
||||||
queue.push_back(obj);
|
queue.push_back(obj);
|
||||||
} else if (obj.isStream()) {
|
} else if (obj.isStream()) {
|
||||||
@ -1428,21 +1406,15 @@ QPDF::fixDanglingReferences(bool force)
|
|||||||
if (obj.isDictionary()) {
|
if (obj.isDictionary()) {
|
||||||
std::map<std::string, QPDFObjectHandle> members =
|
std::map<std::string, QPDFObjectHandle> members =
|
||||||
obj.getDictAsMap();
|
obj.getDictAsMap();
|
||||||
for (std::map<std::string, QPDFObjectHandle>::iterator iter =
|
for (auto const& iter: members) {
|
||||||
members.begin();
|
to_check.push_back(iter.second);
|
||||||
iter != members.end();
|
|
||||||
++iter) {
|
|
||||||
to_check.push_back((*iter).second);
|
|
||||||
}
|
}
|
||||||
} else if (obj.isArray()) {
|
} else if (obj.isArray()) {
|
||||||
QPDF_Array* arr = dynamic_cast<QPDF_Array*>(
|
QPDF_Array* arr = dynamic_cast<QPDF_Array*>(
|
||||||
QPDFObjectHandle::ObjAccessor::getObject(obj).get());
|
QPDFObjectHandle::ObjAccessor::getObject(obj).get());
|
||||||
arr->addExplicitElementsToList(to_check);
|
arr->addExplicitElementsToList(to_check);
|
||||||
}
|
}
|
||||||
for (std::list<QPDFObjectHandle>::iterator iter = to_check.begin();
|
for (auto sub: to_check) {
|
||||||
iter != to_check.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle sub = *iter;
|
|
||||||
if (sub.isIndirect()) {
|
if (sub.isIndirect()) {
|
||||||
if (sub.getOwningQPDF() == this) {
|
if (sub.getOwningQPDF() == this) {
|
||||||
QPDFObjGen og(sub.getObjGen());
|
QPDFObjGen og(sub.getObjGen());
|
||||||
@ -1480,11 +1452,8 @@ QPDF::getAllObjects()
|
|||||||
// object cache.
|
// object cache.
|
||||||
fixDanglingReferences(true);
|
fixDanglingReferences(true);
|
||||||
std::vector<QPDFObjectHandle> result;
|
std::vector<QPDFObjectHandle> result;
|
||||||
for (std::map<QPDFObjGen, ObjCache>::iterator iter =
|
for (auto const& iter: this->m->obj_cache) {
|
||||||
this->m->obj_cache.begin();
|
QPDFObjGen const& og = iter.first;
|
||||||
iter != this->m->obj_cache.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjGen const& og = (*iter).first;
|
|
||||||
result.push_back(
|
result.push_back(
|
||||||
// line-break
|
// line-break
|
||||||
QPDFObjectHandle::Factory::newIndirect(
|
QPDFObjectHandle::Factory::newIndirect(
|
||||||
@ -1733,12 +1702,9 @@ QPDF::recoverStreamLength(
|
|||||||
QPDFObjGen this_obj(0, 0);
|
QPDFObjGen this_obj(0, 0);
|
||||||
|
|
||||||
// Make sure this is inside this object
|
// Make sure this is inside this object
|
||||||
for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter =
|
for (auto const& iter: this->m->xref_table) {
|
||||||
this->m->xref_table.begin();
|
QPDFObjGen const& og = iter.first;
|
||||||
iter != this->m->xref_table.end();
|
QPDFXRefEntry const& entry = iter.second;
|
||||||
++iter) {
|
|
||||||
QPDFObjGen const& og = (*iter).first;
|
|
||||||
QPDFXRefEntry const& entry = (*iter).second;
|
|
||||||
if (entry.getType() == 1) {
|
if (entry.getType() == 1) {
|
||||||
qpdf_offset_t obj_offset = entry.getOffset();
|
qpdf_offset_t obj_offset = entry.getOffset();
|
||||||
if ((obj_offset > stream_offset) &&
|
if ((obj_offset > stream_offset) &&
|
||||||
@ -2157,15 +2123,13 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
|
|||||||
// that some objects stored here might have been overridden by new
|
// that some objects stored here might have been overridden by new
|
||||||
// objects appended to the file, so it is necessary to recheck the
|
// objects appended to the file, so it is necessary to recheck the
|
||||||
// xref table and only cache what would actually be resolved here.
|
// xref table and only cache what would actually be resolved here.
|
||||||
for (std::map<int, int>::iterator iter = offsets.begin();
|
for (auto const& iter: offsets) {
|
||||||
iter != offsets.end();
|
int obj = iter.first;
|
||||||
++iter) {
|
|
||||||
int obj = (*iter).first;
|
|
||||||
QPDFObjGen og(obj, 0);
|
QPDFObjGen og(obj, 0);
|
||||||
QPDFXRefEntry const& entry = this->m->xref_table[og];
|
QPDFXRefEntry const& entry = this->m->xref_table[og];
|
||||||
if ((entry.getType() == 2) &&
|
if ((entry.getType() == 2) &&
|
||||||
(entry.getObjStreamNumber() == obj_stream_number)) {
|
(entry.getObjStreamNumber() == obj_stream_number)) {
|
||||||
int offset = (*iter).second;
|
int offset = iter.second;
|
||||||
input->seek(offset, SEEK_SET);
|
input->seek(offset, SEEK_SET);
|
||||||
QPDFObjectHandle oh = readObject(input, "", obj, 0, true);
|
QPDFObjectHandle oh = readObject(input, "", obj, 0, true);
|
||||||
this->m->obj_cache[og] = ObjCache(
|
this->m->obj_cache[og] = ObjCache(
|
||||||
@ -2317,11 +2281,7 @@ QPDF::copyForeignObject(QPDFObjectHandle foreign)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy any new objects and replace the reservations.
|
// Copy any new objects and replace the reservations.
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter =
|
for (auto& to_copy: obj_copier.to_copy) {
|
||||||
obj_copier.to_copy.begin();
|
|
||||||
iter != obj_copier.to_copy.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle& to_copy = *iter;
|
|
||||||
QPDFObjectHandle copy =
|
QPDFObjectHandle copy =
|
||||||
replaceForeignIndirectObjects(to_copy, obj_copier, true);
|
replaceForeignIndirectObjects(to_copy, obj_copier, true);
|
||||||
if (!to_copy.isStream()) {
|
if (!to_copy.isStream()) {
|
||||||
@ -2365,8 +2325,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top)
|
|||||||
}
|
}
|
||||||
QTC::TC("qpdf", "QPDF copy indirect");
|
QTC::TC("qpdf", "QPDF copy indirect");
|
||||||
obj_copier.visiting.insert(foreign_og);
|
obj_copier.visiting.insert(foreign_og);
|
||||||
std::map<QPDFObjGen, QPDFObjectHandle>::iterator mapping =
|
auto mapping = obj_copier.object_map.find(foreign_og);
|
||||||
obj_copier.object_map.find(foreign_og);
|
|
||||||
if (mapping == obj_copier.object_map.end()) {
|
if (mapping == obj_copier.object_map.end()) {
|
||||||
obj_copier.to_copy.push_back(foreign);
|
obj_copier.to_copy.push_back(foreign);
|
||||||
QPDFObjectHandle reservation;
|
QPDFObjectHandle reservation;
|
||||||
@ -2388,10 +2347,8 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top)
|
|||||||
} else if (foreign.isDictionary()) {
|
} else if (foreign.isDictionary()) {
|
||||||
QTC::TC("qpdf", "QPDF reserve dictionary");
|
QTC::TC("qpdf", "QPDF reserve dictionary");
|
||||||
std::set<std::string> keys = foreign.getKeys();
|
std::set<std::string> keys = foreign.getKeys();
|
||||||
for (std::set<std::string>::iterator iter = keys.begin();
|
for (auto const& key: keys) {
|
||||||
iter != keys.end();
|
reserveObjects(foreign.getKey(key), obj_copier, false);
|
||||||
++iter) {
|
|
||||||
reserveObjects(foreign.getKey(*iter), obj_copier, false);
|
|
||||||
}
|
}
|
||||||
} else if (foreign.isStream()) {
|
} else if (foreign.isStream()) {
|
||||||
QTC::TC("qpdf", "QPDF reserve stream");
|
QTC::TC("qpdf", "QPDF reserve stream");
|
||||||
@ -2412,8 +2369,7 @@ QPDF::replaceForeignIndirectObjects(
|
|||||||
if ((!top) && foreign.isIndirect()) {
|
if ((!top) && foreign.isIndirect()) {
|
||||||
QTC::TC("qpdf", "QPDF replace indirect");
|
QTC::TC("qpdf", "QPDF replace indirect");
|
||||||
QPDFObjGen foreign_og(foreign.getObjGen());
|
QPDFObjGen foreign_og(foreign.getObjGen());
|
||||||
std::map<QPDFObjGen, QPDFObjectHandle>::iterator mapping =
|
auto mapping = obj_copier.object_map.find(foreign_og);
|
||||||
obj_copier.object_map.find(foreign_og);
|
|
||||||
if (mapping == obj_copier.object_map.end()) {
|
if (mapping == obj_copier.object_map.end()) {
|
||||||
// This case would occur if this is a reference to a Page
|
// This case would occur if this is a reference to a Page
|
||||||
// or Pages object that we didn't traverse into.
|
// or Pages object that we didn't traverse into.
|
||||||
@ -2657,12 +2613,9 @@ QPDF::getXRefTable()
|
|||||||
void
|
void
|
||||||
QPDF::getObjectStreamData(std::map<int, int>& omap)
|
QPDF::getObjectStreamData(std::map<int, int>& omap)
|
||||||
{
|
{
|
||||||
for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter =
|
for (auto const& iter: this->m->xref_table) {
|
||||||
this->m->xref_table.begin();
|
QPDFObjGen const& og = iter.first;
|
||||||
iter != this->m->xref_table.end();
|
QPDFXRefEntry const& entry = iter.second;
|
||||||
++iter) {
|
|
||||||
QPDFObjGen const& og = (*iter).first;
|
|
||||||
QPDFXRefEntry const& entry = (*iter).second;
|
|
||||||
if (entry.getType() == 2) {
|
if (entry.getType() == 2) {
|
||||||
omap[og.getObj()] = entry.getObjStreamNumber();
|
omap[og.getObj()] = entry.getObjStreamNumber();
|
||||||
}
|
}
|
||||||
|
@ -182,11 +182,8 @@ QPDFAcroFormDocumentHelper::getFormFields()
|
|||||||
{
|
{
|
||||||
analyze();
|
analyze();
|
||||||
std::vector<QPDFFormFieldObjectHelper> result;
|
std::vector<QPDFFormFieldObjectHelper> result;
|
||||||
for (std::map<QPDFObjGen, std::vector<QPDFAnnotationObjectHelper>>::iterator
|
for (auto const& iter: this->m->field_to_annotations) {
|
||||||
iter = this->m->field_to_annotations.begin();
|
result.push_back(this->qpdf.getObjectByObjGen(iter.first));
|
||||||
iter != this->m->field_to_annotations.end();
|
|
||||||
++iter) {
|
|
||||||
result.push_back(this->qpdf.getObjectByObjGen((*iter).first));
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -299,17 +296,11 @@ QPDFAcroFormDocumentHelper::analyze()
|
|||||||
|
|
||||||
QPDFPageDocumentHelper dh(this->qpdf);
|
QPDFPageDocumentHelper dh(this->qpdf);
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto const& ph: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFPageObjectHelper ph(*iter);
|
|
||||||
std::vector<QPDFAnnotationObjectHelper> annots =
|
std::vector<QPDFAnnotationObjectHelper> annots =
|
||||||
getWidgetAnnotationsForPage(ph);
|
getWidgetAnnotationsForPage(ph);
|
||||||
for (std::vector<QPDFAnnotationObjectHelper>::iterator i2 =
|
for (auto const& iter: annots) {
|
||||||
annots.begin();
|
QPDFObjectHandle annot(iter.getObjectHandle());
|
||||||
i2 != annots.end();
|
|
||||||
++i2) {
|
|
||||||
QPDFObjectHandle annot((*i2).getObjectHandle());
|
|
||||||
QPDFObjGen og(annot.getObjGen());
|
QPDFObjGen og(annot.getObjGen());
|
||||||
if (this->m->annotation_to_field.count(og) == 0) {
|
if (this->m->annotation_to_field.count(og) == 0) {
|
||||||
QTC::TC("qpdf", "QPDFAcroFormDocumentHelper orphaned widget");
|
QTC::TC("qpdf", "QPDFAcroFormDocumentHelper orphaned widget");
|
||||||
@ -462,16 +453,10 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded()
|
|||||||
|
|
||||||
QPDFPageDocumentHelper pdh(this->qpdf);
|
QPDFPageDocumentHelper pdh(this->qpdf);
|
||||||
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator page_iter = pages.begin();
|
for (auto const& page: pages) {
|
||||||
page_iter != pages.end();
|
|
||||||
++page_iter) {
|
|
||||||
std::vector<QPDFAnnotationObjectHelper> annotations =
|
std::vector<QPDFAnnotationObjectHelper> annotations =
|
||||||
getWidgetAnnotationsForPage(*page_iter);
|
getWidgetAnnotationsForPage(page);
|
||||||
for (std::vector<QPDFAnnotationObjectHelper>::iterator annot_iter =
|
for (auto& aoh: annotations) {
|
||||||
annotations.begin();
|
|
||||||
annot_iter != annotations.end();
|
|
||||||
++annot_iter) {
|
|
||||||
QPDFAnnotationObjectHelper& aoh = *annot_iter;
|
|
||||||
QPDFFormFieldObjectHelper ffh = getFieldForAnnotation(aoh);
|
QPDFFormFieldObjectHelper ffh = getFieldForAnnotation(aoh);
|
||||||
if (ffh.getFieldType() == "/Btn") {
|
if (ffh.getFieldType() == "/Btn") {
|
||||||
// Rather than generating appearances for button
|
// Rather than generating appearances for button
|
||||||
|
@ -294,10 +294,7 @@ QPDFArgParser::handleBashArguments()
|
|||||||
bool last_was_backslash = false;
|
bool last_was_backslash = false;
|
||||||
enum { st_top, st_squote, st_dquote } state = st_top;
|
enum { st_top, st_squote, st_dquote } state = st_top;
|
||||||
std::string arg;
|
std::string arg;
|
||||||
for (std::string::iterator iter = this->m->bash_line.begin();
|
for (char ch: this->m->bash_line) {
|
||||||
iter != this->m->bash_line.end();
|
|
||||||
++iter) {
|
|
||||||
char ch = (*iter);
|
|
||||||
if (last_was_backslash) {
|
if (last_was_backslash) {
|
||||||
arg.append(1, ch);
|
arg.append(1, ch);
|
||||||
last_was_backslash = false;
|
last_was_backslash = false;
|
||||||
@ -560,13 +557,14 @@ QPDFArgParser::parseArgs()
|
|||||||
} else if (!oe.choices.empty()) {
|
} else if (!oe.choices.empty()) {
|
||||||
QTC::TC("libtests", "QPDFArgParser required choices");
|
QTC::TC("libtests", "QPDFArgParser required choices");
|
||||||
message += "{";
|
message += "{";
|
||||||
for (std::set<std::string>::iterator iter = oe.choices.begin();
|
bool first = true;
|
||||||
iter != oe.choices.end();
|
for (auto const& choice: oe.choices) {
|
||||||
++iter) {
|
if (first) {
|
||||||
if (iter != oe.choices.begin()) {
|
first = false;
|
||||||
|
} else {
|
||||||
message += ",";
|
message += ",";
|
||||||
}
|
}
|
||||||
message += *iter;
|
message += choice;
|
||||||
}
|
}
|
||||||
message += "}";
|
message += "}";
|
||||||
} else if (!oe.parameter_name.empty()) {
|
} else if (!oe.parameter_name.empty()) {
|
||||||
@ -624,11 +622,9 @@ QPDFArgParser::addChoicesToCompletions(
|
|||||||
{
|
{
|
||||||
if (option_table.count(option) != 0) {
|
if (option_table.count(option) != 0) {
|
||||||
OptionEntry& oe = option_table[option];
|
OptionEntry& oe = option_table[option];
|
||||||
for (std::set<std::string>::iterator iter = oe.choices.begin();
|
for (auto const& choice: oe.choices) {
|
||||||
iter != oe.choices.end();
|
|
||||||
++iter) {
|
|
||||||
QTC::TC("libtests", "QPDFArgParser complete choices");
|
QTC::TC("libtests", "QPDFArgParser complete choices");
|
||||||
this->m->completions.insert(extra_prefix + *iter);
|
this->m->completions.insert(extra_prefix + choice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -714,11 +710,9 @@ QPDFArgParser::handleCompletion()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string prefix = extra_prefix + this->m->bash_cur;
|
std::string prefix = extra_prefix + this->m->bash_cur;
|
||||||
for (std::set<std::string>::iterator iter = this->m->completions.begin();
|
for (auto const& iter: this->m->completions) {
|
||||||
iter != this->m->completions.end();
|
if (prefix.empty() || (iter.substr(0, prefix.length()) == prefix)) {
|
||||||
++iter) {
|
std::cout << iter << std::endl;
|
||||||
if (prefix.empty() || ((*iter).substr(0, prefix.length()) == prefix)) {
|
|
||||||
std::cout << *iter << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -852,10 +852,7 @@ QPDFJob::doCheck(QPDF& pdf)
|
|||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
||||||
DiscardContents discard_contents;
|
DiscardContents discard_contents;
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& page: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFPageObjectHelper& page(*iter);
|
|
||||||
++pageno;
|
++pageno;
|
||||||
try {
|
try {
|
||||||
page.parseContents(&discard_contents);
|
page.parseContents(&discard_contents);
|
||||||
@ -927,10 +924,7 @@ QPDFJob::doShowPages(QPDF& pdf)
|
|||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
auto& cout = *this->m->cout;
|
auto& cout = *this->m->cout;
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& ph: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFPageObjectHelper& ph(*iter);
|
|
||||||
QPDFObjectHandle page = ph.getObjectHandle();
|
QPDFObjectHandle page = ph.getObjectHandle();
|
||||||
++pageno;
|
++pageno;
|
||||||
|
|
||||||
@ -1058,12 +1052,9 @@ QPDFJob::doJSONObjects(QPDF& pdf, JSON& j)
|
|||||||
"trailer", pdf.getTrailer().getJSON(true));
|
"trailer", pdf.getTrailer().getJSON(true));
|
||||||
}
|
}
|
||||||
std::vector<QPDFObjectHandle> objects = pdf.getAllObjects();
|
std::vector<QPDFObjectHandle> objects = pdf.getAllObjects();
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = objects.begin();
|
for (auto& obj: objects) {
|
||||||
iter != objects.end();
|
if (all_objects || wanted_og.count(obj.getObjGen())) {
|
||||||
++iter) {
|
j_objects.addDictionaryMember(obj.unparse(), obj.getJSON(true));
|
||||||
if (all_objects || wanted_og.count((*iter).getObjGen())) {
|
|
||||||
j_objects.addDictionaryMember(
|
|
||||||
(*iter).unparse(), (*iter).getJSON(true));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1106,12 +1097,10 @@ QPDFJob::doJSONPages(QPDF& pdf, JSON& j)
|
|||||||
QPDFOutlineDocumentHelper odh(pdf);
|
QPDFOutlineDocumentHelper odh(pdf);
|
||||||
pdh.pushInheritedAttributesToPage();
|
pdh.pushInheritedAttributesToPage();
|
||||||
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
||||||
int pageno = 0;
|
int pageno = -1;
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& ph: pages) {
|
||||||
iter != pages.end();
|
++pageno;
|
||||||
++iter, ++pageno) {
|
|
||||||
JSON j_page = j_pages.addArrayElement(JSON::makeDictionary());
|
JSON j_page = j_pages.addArrayElement(JSON::makeDictionary());
|
||||||
QPDFPageObjectHelper& ph(*iter);
|
|
||||||
QPDFObjectHandle page = ph.getObjectHandle();
|
QPDFObjectHandle page = ph.getObjectHandle();
|
||||||
j_page.addDictionaryMember("object", page.getJSON());
|
j_page.addDictionaryMember("object", page.getJSON());
|
||||||
JSON j_images = j_page.addDictionaryMember("images", JSON::makeArray());
|
JSON j_images = j_page.addDictionaryMember("images", JSON::makeArray());
|
||||||
@ -1161,17 +1150,14 @@ QPDFJob::doJSONPages(QPDF& pdf, JSON& j)
|
|||||||
j_page.addDictionaryMember("outlines", JSON::makeArray());
|
j_page.addDictionaryMember("outlines", JSON::makeArray());
|
||||||
std::vector<QPDFOutlineObjectHelper> outlines =
|
std::vector<QPDFOutlineObjectHelper> outlines =
|
||||||
odh.getOutlinesForPage(page.getObjGen());
|
odh.getOutlinesForPage(page.getObjGen());
|
||||||
for (std::vector<QPDFOutlineObjectHelper>::iterator oiter =
|
for (auto& oiter: outlines) {
|
||||||
outlines.begin();
|
|
||||||
oiter != outlines.end();
|
|
||||||
++oiter) {
|
|
||||||
JSON j_outline = j_outlines.addArrayElement(JSON::makeDictionary());
|
JSON j_outline = j_outlines.addArrayElement(JSON::makeDictionary());
|
||||||
j_outline.addDictionaryMember(
|
j_outline.addDictionaryMember(
|
||||||
"object", (*oiter).getObjectHandle().getJSON());
|
"object", oiter.getObjectHandle().getJSON());
|
||||||
j_outline.addDictionaryMember(
|
j_outline.addDictionaryMember(
|
||||||
"title", JSON::makeString((*oiter).getTitle()));
|
"title", JSON::makeString(oiter.getTitle()));
|
||||||
j_outline.addDictionaryMember(
|
j_outline.addDictionaryMember(
|
||||||
"dest", (*oiter).getDest().getJSON(true));
|
"dest", oiter.getDest().getJSON(true));
|
||||||
}
|
}
|
||||||
j_page.addDictionaryMember("pageposfrom1", JSON::makeInt(1 + pageno));
|
j_page.addDictionaryMember("pageposfrom1", JSON::makeInt(1 + pageno));
|
||||||
}
|
}
|
||||||
@ -1188,10 +1174,8 @@ QPDFJob::doJSONPageLabels(QPDF& pdf, JSON& j)
|
|||||||
std::vector<QPDFObjectHandle> labels;
|
std::vector<QPDFObjectHandle> labels;
|
||||||
pldh.getLabelsForPageRange(
|
pldh.getLabelsForPageRange(
|
||||||
0, QIntC::to_int(pages.size()) - 1, 0, labels);
|
0, QIntC::to_int(pages.size()) - 1, 0, labels);
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = labels.begin();
|
for (auto iter = labels.begin(); iter != labels.end(); ++iter) {
|
||||||
iter != labels.end();
|
auto next = iter;
|
||||||
++iter) {
|
|
||||||
std::vector<QPDFObjectHandle>::iterator next = iter;
|
|
||||||
++next;
|
++next;
|
||||||
if (next == labels.end()) {
|
if (next == labels.end()) {
|
||||||
// This can't happen, so ignore it. This could only
|
// This can't happen, so ignore it. This could only
|
||||||
@ -1213,10 +1197,7 @@ add_outlines_to_json(
|
|||||||
JSON& j,
|
JSON& j,
|
||||||
std::map<QPDFObjGen, int>& page_numbers)
|
std::map<QPDFObjGen, int>& page_numbers)
|
||||||
{
|
{
|
||||||
for (std::vector<QPDFOutlineObjectHelper>::iterator iter = outlines.begin();
|
for (auto& ol: outlines) {
|
||||||
iter != outlines.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFOutlineObjectHelper& ol = *iter;
|
|
||||||
JSON jo = j.addArrayElement(JSON::makeDictionary());
|
JSON jo = j.addArrayElement(JSON::makeDictionary());
|
||||||
jo.addDictionaryMember("object", ol.getObjectHandle().getJSON());
|
jo.addDictionaryMember("object", ol.getObjectHandle().getJSON());
|
||||||
jo.addDictionaryMember("title", JSON::makeString(ol.getTitle()));
|
jo.addDictionaryMember("title", JSON::makeString(ol.getTitle()));
|
||||||
@ -1243,10 +1224,8 @@ QPDFJob::doJSONOutlines(QPDF& pdf, JSON& j)
|
|||||||
QPDFPageDocumentHelper dh(pdf);
|
QPDFPageDocumentHelper dh(pdf);
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto const& ph: pages) {
|
||||||
iter != pages.end();
|
QPDFObjectHandle oh = ph.getObjectHandle();
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle oh = (*iter).getObjectHandle();
|
|
||||||
page_numbers[oh.getObjGen()] = ++n;
|
page_numbers[oh.getObjGen()] = ++n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1268,17 +1247,11 @@ QPDFJob::doJSONAcroform(QPDF& pdf, JSON& j)
|
|||||||
QPDFPageDocumentHelper pdh(pdf);
|
QPDFPageDocumentHelper pdh(pdf);
|
||||||
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages();
|
||||||
int pagepos1 = 0;
|
int pagepos1 = 0;
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator page_iter = pages.begin();
|
for (auto const& page: pages) {
|
||||||
page_iter != pages.end();
|
|
||||||
++page_iter) {
|
|
||||||
++pagepos1;
|
++pagepos1;
|
||||||
std::vector<QPDFAnnotationObjectHelper> annotations =
|
std::vector<QPDFAnnotationObjectHelper> annotations =
|
||||||
afdh.getWidgetAnnotationsForPage(*page_iter);
|
afdh.getWidgetAnnotationsForPage(page);
|
||||||
for (std::vector<QPDFAnnotationObjectHelper>::iterator annot_iter =
|
for (auto& aoh: annotations) {
|
||||||
annotations.begin();
|
|
||||||
annot_iter != annotations.end();
|
|
||||||
++annot_iter) {
|
|
||||||
QPDFAnnotationObjectHelper& aoh = *annot_iter;
|
|
||||||
QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh);
|
QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh);
|
||||||
JSON j_field = j_fields.addArrayElement(JSON::makeDictionary());
|
JSON j_field = j_fields.addArrayElement(JSON::makeDictionary());
|
||||||
j_field.addDictionaryMember(
|
j_field.addDictionaryMember(
|
||||||
@ -1314,10 +1287,8 @@ QPDFJob::doJSONAcroform(QPDF& pdf, JSON& j)
|
|||||||
JSON j_choices =
|
JSON j_choices =
|
||||||
j_field.addDictionaryMember("choices", JSON::makeArray());
|
j_field.addDictionaryMember("choices", JSON::makeArray());
|
||||||
std::vector<std::string> choices = ffh.getChoices();
|
std::vector<std::string> choices = ffh.getChoices();
|
||||||
for (std::vector<std::string>::iterator iter = choices.begin();
|
for (auto const& choice: choices) {
|
||||||
iter != choices.end();
|
j_choices.addArrayElement(JSON::makeString(choice));
|
||||||
++iter) {
|
|
||||||
j_choices.addArrayElement(JSON::makeString(*iter));
|
|
||||||
}
|
}
|
||||||
JSON j_annot = j_field.addDictionaryMember(
|
JSON j_annot = j_field.addDictionaryMember(
|
||||||
"annotation", JSON::makeDictionary());
|
"annotation", JSON::makeDictionary());
|
||||||
@ -1688,10 +1659,8 @@ Please report this as a bug at\n\
|
|||||||
https://github.com/qpdf/qpdf/issues/new\n\
|
https://github.com/qpdf/qpdf/issues/new\n\
|
||||||
ideally with the file that caused the error and the output below. Thanks!\n\
|
ideally with the file that caused the error and the output below. Thanks!\n\
|
||||||
\n";
|
\n";
|
||||||
for (std::list<std::string>::iterator iter = errors.begin();
|
for (auto const& error: errors) {
|
||||||
iter != errors.end();
|
*(this->m->cerr) << error << std::endl;
|
||||||
++iter) {
|
|
||||||
*(this->m->cerr) << (*iter) << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1816,10 +1785,8 @@ QPDFJob::doProcess(
|
|||||||
QUtil::possible_repaired_encodings(password);
|
QUtil::possible_repaired_encodings(password);
|
||||||
// Represent to char const*, as required by the QPDF class.
|
// Represent to char const*, as required by the QPDF class.
|
||||||
std::vector<char const*> passwords;
|
std::vector<char const*> passwords;
|
||||||
for (std::vector<std::string>::iterator iter = passwords_str.begin();
|
for (auto const& iter: passwords_str) {
|
||||||
iter != passwords_str.end();
|
passwords.push_back(iter.c_str());
|
||||||
++iter) {
|
|
||||||
passwords.push_back((*iter).c_str());
|
|
||||||
}
|
}
|
||||||
// We always try the supplied password first because it is the
|
// We always try the supplied password first because it is the
|
||||||
// first string returned by possible_repaired_encodings. If there
|
// first string returned by possible_repaired_encodings. If there
|
||||||
@ -1835,13 +1802,11 @@ QPDFJob::doProcess(
|
|||||||
// attempt, which, like the first attempt, will be with the
|
// attempt, which, like the first attempt, will be with the
|
||||||
// supplied password.
|
// supplied password.
|
||||||
bool warned = false;
|
bool warned = false;
|
||||||
for (std::vector<char const*>::iterator iter = passwords.begin();
|
for (auto iter = passwords.begin(); iter != passwords.end(); ++iter) {
|
||||||
iter != passwords.end();
|
|
||||||
++iter) {
|
|
||||||
try {
|
try {
|
||||||
return doProcessOnce(fn, *iter, empty, used_for_input);
|
return doProcessOnce(fn, *iter, empty, used_for_input);
|
||||||
} catch (QPDFExc& e) {
|
} catch (QPDFExc& e) {
|
||||||
std::vector<char const*>::iterator next = iter;
|
auto next = iter;
|
||||||
++next;
|
++next;
|
||||||
if (next == passwords.end()) {
|
if (next == passwords.end()) {
|
||||||
throw e;
|
throw e;
|
||||||
@ -1961,10 +1926,7 @@ QPDFJob::doUnderOverlayForPage(
|
|||||||
resources = dest_page.getObjectHandle().replaceKeyAndGet(
|
resources = dest_page.getObjectHandle().replaceKeyAndGet(
|
||||||
"/Resources", QPDFObjectHandle::newDictionary());
|
"/Resources", QPDFObjectHandle::newDictionary());
|
||||||
}
|
}
|
||||||
for (std::vector<int>::iterator iter = pagenos[pageno].begin();
|
for (int from_pageno: pagenos[pageno]) {
|
||||||
iter != pagenos[pageno].end();
|
|
||||||
++iter) {
|
|
||||||
int from_pageno = *iter;
|
|
||||||
doIfVerbose([&](std::ostream& cout, std::string const& prefix) {
|
doIfVerbose([&](std::ostream& cout, std::string const& prefix) {
|
||||||
cout << " " << uo.which << " " << from_pageno << std::endl;
|
cout << " " << uo.which << " " << from_pageno << std::endl;
|
||||||
});
|
});
|
||||||
@ -2017,15 +1979,14 @@ QPDFJob::getUOPagenos(
|
|||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
size_t from_size = uo.from_pagenos.size();
|
size_t from_size = uo.from_pagenos.size();
|
||||||
size_t repeat_size = uo.repeat_pagenos.size();
|
size_t repeat_size = uo.repeat_pagenos.size();
|
||||||
for (std::vector<int>::iterator iter = uo.to_pagenos.begin();
|
for (int to_pageno: uo.to_pagenos) {
|
||||||
iter != uo.to_pagenos.end();
|
|
||||||
++iter, ++idx) {
|
|
||||||
if (idx < from_size) {
|
if (idx < from_size) {
|
||||||
pagenos[*iter].push_back(uo.from_pagenos.at(idx));
|
pagenos[to_pageno].push_back(uo.from_pagenos.at(idx));
|
||||||
} else if (repeat_size) {
|
} else if (repeat_size) {
|
||||||
pagenos[*iter].push_back(
|
pagenos[to_pageno].push_back(
|
||||||
uo.repeat_pagenos.at((idx - from_size) % repeat_size));
|
uo.repeat_pagenos.at((idx - from_size) % repeat_size));
|
||||||
}
|
}
|
||||||
|
++idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2206,21 +2167,15 @@ QPDFJob::handleTransformations(QPDF& pdf)
|
|||||||
if (m->externalize_inline_images ||
|
if (m->externalize_inline_images ||
|
||||||
(m->optimize_images && (!m->keep_inline_images))) {
|
(m->optimize_images && (!m->keep_inline_images))) {
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& ph: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFPageObjectHelper& ph(*iter);
|
|
||||||
ph.externalizeInlineImages(m->ii_min_bytes);
|
ph.externalizeInlineImages(m->ii_min_bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m->optimize_images) {
|
if (m->optimize_images) {
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& ph: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
++pageno;
|
++pageno;
|
||||||
QPDFPageObjectHelper& ph(*iter);
|
|
||||||
QPDFObjectHandle page = ph.getObjectHandle();
|
QPDFObjectHandle page = ph.getObjectHandle();
|
||||||
std::map<std::string, QPDFObjectHandle> images = ph.getImages();
|
std::map<std::string, QPDFObjectHandle> images = ph.getImages();
|
||||||
for (auto& iter2: images) {
|
for (auto& iter2: images) {
|
||||||
@ -2260,10 +2215,8 @@ QPDFJob::handleTransformations(QPDF& pdf)
|
|||||||
}
|
}
|
||||||
if (m->coalesce_contents) {
|
if (m->coalesce_contents) {
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& page: pages) {
|
||||||
iter != pages.end();
|
page.coalesceContentStreams();
|
||||||
++iter) {
|
|
||||||
(*iter).coalesceContentStreams();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m->flatten_rotation) {
|
if (m->flatten_rotation) {
|
||||||
@ -2428,10 +2381,7 @@ QPDFJob::handlePageSpecs(
|
|||||||
// actual pages.
|
// actual pages.
|
||||||
|
|
||||||
// Handle "." as a shortcut for the input file
|
// Handle "." as a shortcut for the input file
|
||||||
for (std::vector<QPDFJob::PageSpec>::iterator iter = m->page_specs.begin();
|
for (auto& page_spec: m->page_specs) {
|
||||||
iter != m->page_specs.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFJob::PageSpec& page_spec = *iter;
|
|
||||||
if (page_spec.filename == ".") {
|
if (page_spec.filename == ".") {
|
||||||
page_spec.filename = m->infilename.get();
|
page_spec.filename = m->infilename.get();
|
||||||
}
|
}
|
||||||
@ -2463,10 +2413,7 @@ QPDFJob::handlePageSpecs(
|
|||||||
page_spec_qpdfs[m->infilename.get()] = &pdf;
|
page_spec_qpdfs[m->infilename.get()] = &pdf;
|
||||||
std::vector<QPDFPageData> parsed_specs;
|
std::vector<QPDFPageData> parsed_specs;
|
||||||
std::map<unsigned long long, std::set<QPDFObjGen>> copied_pages;
|
std::map<unsigned long long, std::set<QPDFObjGen>> copied_pages;
|
||||||
for (std::vector<QPDFJob::PageSpec>::iterator iter = m->page_specs.begin();
|
for (auto& page_spec: m->page_specs) {
|
||||||
iter != m->page_specs.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFJob::PageSpec& page_spec = *iter;
|
|
||||||
if (page_spec_qpdfs.count(page_spec.filename) == 0) {
|
if (page_spec_qpdfs.count(page_spec.filename) == 0) {
|
||||||
// Open the PDF file and store the QPDF object. Throw a
|
// Open the PDF file and store the QPDF object. Throw a
|
||||||
// std::shared_ptr to the qpdf into a heap so that it
|
// std::shared_ptr to the qpdf into a heap so that it
|
||||||
@ -2523,17 +2470,14 @@ QPDFJob::handlePageSpecs(
|
|||||||
|
|
||||||
std::map<unsigned long long, bool> remove_unreferenced;
|
std::map<unsigned long long, bool> remove_unreferenced;
|
||||||
if (m->remove_unreferenced_page_resources != QPDFJob::re_no) {
|
if (m->remove_unreferenced_page_resources != QPDFJob::re_no) {
|
||||||
for (std::map<std::string, QPDF*>::iterator iter =
|
for (auto const& iter: page_spec_qpdfs) {
|
||||||
page_spec_qpdfs.begin();
|
std::string const& filename = iter.first;
|
||||||
iter != page_spec_qpdfs.end();
|
|
||||||
++iter) {
|
|
||||||
std::string const& filename = (*iter).first;
|
|
||||||
ClosedFileInputSource* cis = 0;
|
ClosedFileInputSource* cis = 0;
|
||||||
if (page_spec_cfis.count(filename)) {
|
if (page_spec_cfis.count(filename)) {
|
||||||
cis = page_spec_cfis[filename];
|
cis = page_spec_cfis[filename];
|
||||||
cis->stayOpen(true);
|
cis->stayOpen(true);
|
||||||
}
|
}
|
||||||
QPDF& other(*((*iter).second));
|
QPDF& other(*(iter.second));
|
||||||
auto other_uuid = other.getUniqueId();
|
auto other_uuid = other.getUniqueId();
|
||||||
if (remove_unreferenced.count(other_uuid) == 0) {
|
if (remove_unreferenced.count(other_uuid) == 0) {
|
||||||
remove_unreferenced[other_uuid] =
|
remove_unreferenced[other_uuid] =
|
||||||
@ -2556,10 +2500,8 @@ QPDFJob::handlePageSpecs(
|
|||||||
});
|
});
|
||||||
QPDFPageDocumentHelper dh(pdf);
|
QPDFPageDocumentHelper dh(pdf);
|
||||||
std::vector<QPDFPageObjectHelper> orig_pages = dh.getAllPages();
|
std::vector<QPDFPageObjectHelper> orig_pages = dh.getAllPages();
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = orig_pages.begin();
|
for (auto const& page: orig_pages) {
|
||||||
iter != orig_pages.end();
|
dh.removePage(page);
|
||||||
++iter) {
|
|
||||||
dh.removePage(*iter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m->collate && (parsed_specs.size() > 1)) {
|
if (m->collate && (parsed_specs.size() > 1)) {
|
||||||
@ -2601,10 +2543,7 @@ QPDFJob::handlePageSpecs(
|
|||||||
afdh_map;
|
afdh_map;
|
||||||
auto this_afdh = get_afdh_for_qpdf(afdh_map, &pdf);
|
auto this_afdh = get_afdh_for_qpdf(afdh_map, &pdf);
|
||||||
std::set<QPDFObjGen> referenced_fields;
|
std::set<QPDFObjGen> referenced_fields;
|
||||||
for (std::vector<QPDFPageData>::iterator iter = parsed_specs.begin();
|
for (auto& page_data: parsed_specs) {
|
||||||
iter != parsed_specs.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFPageData& page_data = *iter;
|
|
||||||
ClosedFileInputSource* cis = 0;
|
ClosedFileInputSource* cis = 0;
|
||||||
if (page_spec_cfis.count(page_data.filename)) {
|
if (page_spec_cfis.count(page_data.filename)) {
|
||||||
cis = page_spec_cfis[page_data.filename];
|
cis = page_spec_cfis[page_data.filename];
|
||||||
@ -2619,14 +2558,12 @@ QPDFJob::handlePageSpecs(
|
|||||||
cout << prefix << ": adding pages from " << page_data.filename
|
cout << prefix << ": adding pages from " << page_data.filename
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
});
|
});
|
||||||
for (std::vector<int>::iterator pageno_iter =
|
for (auto pageno_iter: page_data.selected_pages) {
|
||||||
page_data.selected_pages.begin();
|
|
||||||
pageno_iter != page_data.selected_pages.end();
|
|
||||||
++pageno_iter, ++out_pageno) {
|
|
||||||
// Pages are specified from 1 but numbered from 0 in the
|
// Pages are specified from 1 but numbered from 0 in the
|
||||||
// vector
|
// vector
|
||||||
int pageno = *pageno_iter - 1;
|
int pageno = pageno_iter - 1;
|
||||||
pldh.getLabelsForPageRange(pageno, pageno, out_pageno, new_labels);
|
pldh.getLabelsForPageRange(
|
||||||
|
pageno, pageno, out_pageno++, new_labels);
|
||||||
QPDFPageObjectHelper to_copy =
|
QPDFPageObjectHelper to_copy =
|
||||||
page_data.orig_pages.at(QIntC::to_size(pageno));
|
page_data.orig_pages.at(QIntC::to_size(pageno));
|
||||||
QPDFObjGen to_copy_og = to_copy.getObjectHandle().getObjGen();
|
QPDFObjGen to_copy_og = to_copy.getObjectHandle().getObjGen();
|
||||||
@ -2748,19 +2685,14 @@ QPDFJob::handleRotations(QPDF& pdf)
|
|||||||
QPDFPageDocumentHelper dh(pdf);
|
QPDFPageDocumentHelper dh(pdf);
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
||||||
int npages = QIntC::to_int(pages.size());
|
int npages = QIntC::to_int(pages.size());
|
||||||
for (std::map<std::string, QPDFJob::RotationSpec>::iterator iter =
|
for (auto const& iter: m->rotations) {
|
||||||
m->rotations.begin();
|
std::string const& range = iter.first;
|
||||||
iter != m->rotations.end();
|
QPDFJob::RotationSpec const& rspec = iter.second;
|
||||||
++iter) {
|
|
||||||
std::string const& range = (*iter).first;
|
|
||||||
QPDFJob::RotationSpec const& rspec = (*iter).second;
|
|
||||||
// range has been previously validated
|
// range has been previously validated
|
||||||
std::vector<int> to_rotate =
|
std::vector<int> to_rotate =
|
||||||
QUtil::parse_numrange(range.c_str(), npages);
|
QUtil::parse_numrange(range.c_str(), npages);
|
||||||
for (std::vector<int>::iterator i2 = to_rotate.begin();
|
for (int pageno_iter: to_rotate) {
|
||||||
i2 != to_rotate.end();
|
int pageno = pageno_iter - 1;
|
||||||
++i2) {
|
|
||||||
int pageno = *i2 - 1;
|
|
||||||
if ((pageno >= 0) && (pageno < npages)) {
|
if ((pageno >= 0) && (pageno < npages)) {
|
||||||
pages.at(QIntC::to_size(pageno))
|
pages.at(QIntC::to_size(pageno))
|
||||||
.rotatePage(rspec.angle, rspec.relative);
|
.rotatePage(rspec.angle, rspec.relative);
|
||||||
|
@ -1244,17 +1244,12 @@ QPDFObjectHandle::getResourceNames()
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
std::set<std::string> keys = getKeys();
|
std::set<std::string> keys = getKeys();
|
||||||
for (std::set<std::string>::iterator iter = keys.begin();
|
for (auto const& key: keys) {
|
||||||
iter != keys.end();
|
|
||||||
++iter) {
|
|
||||||
std::string const& key = *iter;
|
|
||||||
QPDFObjectHandle val = getKey(key);
|
QPDFObjectHandle val = getKey(key);
|
||||||
if (val.isDictionary()) {
|
if (val.isDictionary()) {
|
||||||
std::set<std::string> val_keys = val.getKeys();
|
std::set<std::string> val_keys = val.getKeys();
|
||||||
for (std::set<std::string>::iterator i2 = val_keys.begin();
|
for (auto const& val_key: val_keys) {
|
||||||
i2 != val_keys.end();
|
result.insert(val_key);
|
||||||
++i2) {
|
|
||||||
result.insert(*i2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1620,10 +1615,7 @@ QPDFObjectHandle::arrayOrStreamToStreamArray(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = result.begin();
|
for (auto const& item: result) {
|
||||||
iter != result.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle item = *iter;
|
|
||||||
std::string og = QUtil::int_to_string(item.getObjectID()) + " " +
|
std::string og = QUtil::int_to_string(item.getObjectID()) + " " +
|
||||||
QUtil::int_to_string(item.getGeneration());
|
QUtil::int_to_string(item.getGeneration());
|
||||||
if (first) {
|
if (first) {
|
||||||
@ -1660,11 +1652,9 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first)
|
|||||||
QTC::TC("qpdf", "QPDFObjectHandle prepend page contents");
|
QTC::TC("qpdf", "QPDFObjectHandle prepend page contents");
|
||||||
content_streams.push_back(new_contents);
|
content_streams.push_back(new_contents);
|
||||||
}
|
}
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = orig_contents.begin();
|
for (auto const& iter: orig_contents) {
|
||||||
iter != orig_contents.end();
|
|
||||||
++iter) {
|
|
||||||
QTC::TC("qpdf", "QPDFObjectHandle append page contents");
|
QTC::TC("qpdf", "QPDFObjectHandle append page contents");
|
||||||
content_streams.push_back(*iter);
|
content_streams.push_back(iter);
|
||||||
}
|
}
|
||||||
if (!first) {
|
if (!first) {
|
||||||
content_streams.push_back(new_contents);
|
content_streams.push_back(new_contents);
|
||||||
@ -1865,14 +1855,11 @@ QPDFObjectHandle::pipeContentStreams(
|
|||||||
arrayOrStreamToStreamArray(description, all_description);
|
arrayOrStreamToStreamArray(description, all_description);
|
||||||
bool need_newline = false;
|
bool need_newline = false;
|
||||||
Pl_Buffer buf("concatenated content stream buffer");
|
Pl_Buffer buf("concatenated content stream buffer");
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = streams.begin();
|
for (auto stream: streams) {
|
||||||
iter != streams.end();
|
|
||||||
++iter) {
|
|
||||||
if (need_newline) {
|
if (need_newline) {
|
||||||
buf.write(QUtil::unsigned_char_pointer("\n"), 1);
|
buf.write(QUtil::unsigned_char_pointer("\n"), 1);
|
||||||
}
|
}
|
||||||
LastChar lc(&buf);
|
LastChar lc(&buf);
|
||||||
QPDFObjectHandle stream = *iter;
|
|
||||||
std::string og = QUtil::int_to_string(stream.getObjectID()) + " " +
|
std::string og = QUtil::int_to_string(stream.getObjectID()) + " " +
|
||||||
QUtil::int_to_string(stream.getGeneration());
|
QUtil::int_to_string(stream.getGeneration());
|
||||||
std::string w_description = "content stream object " + og;
|
std::string w_description = "content stream object " + og;
|
||||||
@ -2920,13 +2907,11 @@ QPDFObjectHandle::copyObject(
|
|||||||
QTC::TC("qpdf", "QPDFObjectHandle clone dictionary");
|
QTC::TC("qpdf", "QPDFObjectHandle clone dictionary");
|
||||||
std::set<std::string> keys = getKeys();
|
std::set<std::string> keys = getKeys();
|
||||||
std::map<std::string, QPDFObjectHandle> items;
|
std::map<std::string, QPDFObjectHandle> items;
|
||||||
for (std::set<std::string>::iterator iter = keys.begin();
|
for (auto const& key: keys) {
|
||||||
iter != keys.end();
|
items[key] = getKey(key);
|
||||||
++iter) {
|
|
||||||
items[*iter] = getKey(*iter);
|
|
||||||
if ((!first_level_only) &&
|
if ((!first_level_only) &&
|
||||||
(cross_indirect || (!items[*iter].isIndirect()))) {
|
(cross_indirect || (!items[key].isIndirect()))) {
|
||||||
items[*iter].copyObject(
|
items[key].copyObject(
|
||||||
visited, cross_indirect, first_level_only, stop_at_streams);
|
visited, cross_indirect, first_level_only, stop_at_streams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,8 @@ QPDFPageDocumentHelper::getAllPages()
|
|||||||
{
|
{
|
||||||
std::vector<QPDFObjectHandle> const& pages_v = this->qpdf.getAllPages();
|
std::vector<QPDFObjectHandle> const& pages_v = this->qpdf.getAllPages();
|
||||||
std::vector<QPDFPageObjectHelper> pages;
|
std::vector<QPDFPageObjectHelper> pages;
|
||||||
for (std::vector<QPDFObjectHandle>::const_iterator iter = pages_v.begin();
|
for (auto const& iter: pages_v) {
|
||||||
iter != pages_v.end();
|
pages.push_back(QPDFPageObjectHelper(iter));
|
||||||
++iter) {
|
|
||||||
pages.push_back(QPDFPageObjectHelper(*iter));
|
|
||||||
}
|
}
|
||||||
return pages;
|
return pages;
|
||||||
}
|
}
|
||||||
@ -32,10 +30,8 @@ void
|
|||||||
QPDFPageDocumentHelper::removeUnreferencedResources()
|
QPDFPageDocumentHelper::removeUnreferencedResources()
|
||||||
{
|
{
|
||||||
std::vector<QPDFPageObjectHelper> pages = getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = getAllPages();
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& ph: pages) {
|
||||||
iter != pages.end();
|
ph.removeUnreferencedResources();
|
||||||
++iter) {
|
|
||||||
(*iter).removeUnreferencedResources();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,10 +67,7 @@ QPDFPageDocumentHelper::flattenAnnotations(
|
|||||||
" so form fields will not be flattened");
|
" so form fields will not be flattened");
|
||||||
}
|
}
|
||||||
std::vector<QPDFPageObjectHelper> pages = getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = getAllPages();
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& ph: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFPageObjectHelper ph(*iter);
|
|
||||||
QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
|
QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
|
||||||
if (!resources.isDictionary()) {
|
if (!resources.isDictionary()) {
|
||||||
// This should never happen and is not exercised in the
|
// This should never happen and is not exercised in the
|
||||||
@ -107,11 +100,7 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage(
|
|||||||
rotate = rotate_obj.getIntValueAsInt();
|
rotate = rotate_obj.getIntValueAsInt();
|
||||||
}
|
}
|
||||||
int next_fx = 1;
|
int next_fx = 1;
|
||||||
for (std::vector<QPDFAnnotationObjectHelper>::iterator iter =
|
for (auto& aoh: annots) {
|
||||||
annots.begin();
|
|
||||||
iter != annots.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFAnnotationObjectHelper& aoh(*iter);
|
|
||||||
QPDFObjectHandle as = aoh.getAppearanceStream("/N");
|
QPDFObjectHandle as = aoh.getAppearanceStream("/N");
|
||||||
bool is_widget = (aoh.getSubtype() == "/Widget");
|
bool is_widget = (aoh.getSubtype() == "/Widget");
|
||||||
bool process = true;
|
bool process = true;
|
||||||
|
@ -568,10 +568,7 @@ QPDFTokenizer::findEI(std::shared_ptr<InputSource> input)
|
|||||||
bool found_non_printable = false;
|
bool found_non_printable = false;
|
||||||
bool found_other = false;
|
bool found_other = false;
|
||||||
std::string value = t.getValue();
|
std::string value = t.getValue();
|
||||||
for (std::string::iterator iter = value.begin();
|
for (char ch: value) {
|
||||||
iter != value.end();
|
|
||||||
++iter) {
|
|
||||||
char ch = *iter;
|
|
||||||
if (((ch >= 'a') && (ch <= 'z')) ||
|
if (((ch >= 'a') && (ch <= 'z')) ||
|
||||||
((ch >= 'A') && (ch <= 'Z')) || (ch == '*')) {
|
((ch >= 'A') && (ch <= 'Z')) || (ch == '*')) {
|
||||||
// Treat '*' as alpha since there are valid
|
// Treat '*' as alpha since there are valid
|
||||||
|
@ -755,10 +755,8 @@ QPDFWriter::setEncryptionParameters(
|
|||||||
|
|
||||||
int P = 0;
|
int P = 0;
|
||||||
// Create the complement of P, then invert.
|
// Create the complement of P, then invert.
|
||||||
for (std::set<int>::iterator iter = bits_to_clear.begin();
|
for (int b: bits_to_clear) {
|
||||||
iter != bits_to_clear.end();
|
P |= (1 << (b - 1));
|
||||||
++iter) {
|
|
||||||
P |= (1 << ((*iter) - 1));
|
|
||||||
}
|
}
|
||||||
P = ~P;
|
P = ~P;
|
||||||
|
|
||||||
@ -1277,11 +1275,8 @@ QPDFWriter::assignCompressedObjectNumbers(QPDFObjGen const& og)
|
|||||||
|
|
||||||
// Reserve numbers for the objects that belong to this object
|
// Reserve numbers for the objects that belong to this object
|
||||||
// stream.
|
// stream.
|
||||||
for (std::set<QPDFObjGen>::iterator iter =
|
for (auto const& iter: this->m->object_stream_to_objects[objid]) {
|
||||||
this->m->object_stream_to_objects[objid].begin();
|
this->m->obj_renumber[iter] = this->m->next_objid++;
|
||||||
iter != this->m->object_stream_to_objects[objid].end();
|
|
||||||
++iter) {
|
|
||||||
this->m->obj_renumber[*iter] = this->m->next_objid++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1353,11 +1348,9 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object)
|
|||||||
}
|
}
|
||||||
} else if (object.isDictionary()) {
|
} else if (object.isDictionary()) {
|
||||||
std::set<std::string> keys = object.getKeys();
|
std::set<std::string> keys = object.getKeys();
|
||||||
for (std::set<std::string>::iterator iter = keys.begin();
|
for (auto const& key: keys) {
|
||||||
iter != keys.end();
|
|
||||||
++iter) {
|
|
||||||
if (!this->m->linearized) {
|
if (!this->m->linearized) {
|
||||||
enqueueObject(object.getKey(*iter));
|
enqueueObject(object.getKey(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1401,10 +1394,7 @@ QPDFWriter::writeTrailer(
|
|||||||
writeString(QUtil::int_to_string(size));
|
writeString(QUtil::int_to_string(size));
|
||||||
} else {
|
} else {
|
||||||
std::set<std::string> keys = trailer.getKeys();
|
std::set<std::string> keys = trailer.getKeys();
|
||||||
for (std::set<std::string>::iterator iter = keys.begin();
|
for (auto const& key: keys) {
|
||||||
iter != keys.end();
|
|
||||||
++iter) {
|
|
||||||
std::string const& key = *iter;
|
|
||||||
writeStringQDF(" ");
|
writeStringQDF(" ");
|
||||||
writeStringNoQDF(" ");
|
writeStringNoQDF(" ");
|
||||||
writeString(QPDF_Name::normalizeName(key));
|
writeString(QPDF_Name::normalizeName(key));
|
||||||
@ -1758,11 +1748,7 @@ QPDFWriter::unparseObject(
|
|||||||
writeStringQDF("\n");
|
writeStringQDF("\n");
|
||||||
|
|
||||||
std::set<std::string> keys = object.getKeys();
|
std::set<std::string> keys = object.getKeys();
|
||||||
for (std::set<std::string>::iterator iter = keys.begin();
|
for (auto const& key: keys) {
|
||||||
iter != keys.end();
|
|
||||||
++iter) {
|
|
||||||
std::string const& key = *iter;
|
|
||||||
|
|
||||||
writeStringQDF(indent);
|
writeStringQDF(indent);
|
||||||
writeStringQDF(" ");
|
writeStringQDF(" ");
|
||||||
writeStringNoQDF(" ");
|
writeStringNoQDF(" ");
|
||||||
@ -1930,12 +1916,9 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
|
|||||||
pushDiscardFilter(pp_ostream);
|
pushDiscardFilter(pp_ostream);
|
||||||
} else {
|
} else {
|
||||||
// Adjust offsets to skip over comment before first object
|
// Adjust offsets to skip over comment before first object
|
||||||
|
|
||||||
first = offsets.at(0);
|
first = offsets.at(0);
|
||||||
for (std::vector<qpdf_offset_t>::iterator iter = offsets.begin();
|
for (auto& iter: offsets) {
|
||||||
iter != offsets.end();
|
iter -= first;
|
||||||
++iter) {
|
|
||||||
*iter -= first;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take one pass at writing pairs of numbers so we can get
|
// Take one pass at writing pairs of numbers so we can get
|
||||||
@ -1960,12 +1943,9 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
|
|||||||
writeObjectStreamOffsets(offsets, first_obj);
|
writeObjectStreamOffsets(offsets, first_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = 0;
|
int count = -1;
|
||||||
for (std::set<QPDFObjGen>::iterator iter =
|
for (auto const& obj: this->m->object_stream_to_objects[old_id]) {
|
||||||
this->m->object_stream_to_objects[old_id].begin();
|
++count;
|
||||||
iter != this->m->object_stream_to_objects[old_id].end();
|
|
||||||
++iter, ++count) {
|
|
||||||
QPDFObjGen obj = *iter;
|
|
||||||
int new_obj = this->m->obj_renumber[obj];
|
int new_obj = this->m->obj_renumber[obj];
|
||||||
if (first_obj == -1) {
|
if (first_obj == -1) {
|
||||||
first_obj = new_obj;
|
first_obj = new_obj;
|
||||||
@ -2197,10 +2177,8 @@ QPDFWriter::generateID()
|
|||||||
if (trailer.hasKey("/Info")) {
|
if (trailer.hasKey("/Info")) {
|
||||||
QPDFObjectHandle info = trailer.getKey("/Info");
|
QPDFObjectHandle info = trailer.getKey("/Info");
|
||||||
std::set<std::string> keys = info.getKeys();
|
std::set<std::string> keys = info.getKeys();
|
||||||
for (std::set<std::string>::iterator iter = keys.begin();
|
for (auto const& key: keys) {
|
||||||
iter != keys.end();
|
QPDFObjectHandle obj = info.getKey(key);
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle obj = info.getKey(*iter);
|
|
||||||
if (obj.isString()) {
|
if (obj.isString()) {
|
||||||
seed += " ";
|
seed += " ";
|
||||||
seed += obj.getStringValue();
|
seed += obj.getStringValue();
|
||||||
@ -2235,10 +2213,7 @@ QPDFWriter::initializeSpecialStreams()
|
|||||||
// normalizing.
|
// normalizing.
|
||||||
std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages();
|
std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages();
|
||||||
int num = 0;
|
int num = 0;
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = pages.begin();
|
for (auto& page: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle& page = *iter;
|
|
||||||
this->m->page_object_to_seq[page.getObjGen()] = ++num;
|
this->m->page_object_to_seq[page.getObjGen()] = ++num;
|
||||||
QPDFObjectHandle contents = page.getKey("/Contents");
|
QPDFObjectHandle contents = page.getKey("/Contents");
|
||||||
std::vector<QPDFObjGen> contents_objects;
|
std::vector<QPDFObjGen> contents_objects;
|
||||||
@ -2322,9 +2297,7 @@ QPDFWriter::generateObjectStreams()
|
|||||||
}
|
}
|
||||||
unsigned int n = 0;
|
unsigned int n = 0;
|
||||||
int cur_ostream = 0;
|
int cur_ostream = 0;
|
||||||
for (std::vector<QPDFObjGen>::const_iterator iter = eligible.begin();
|
for (auto const& iter: eligible) {
|
||||||
iter != eligible.end();
|
|
||||||
++iter) {
|
|
||||||
if ((n % n_per) == 0) {
|
if ((n % n_per) == 0) {
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
QTC::TC("qpdf", "QPDFWriter generate >1 ostream");
|
QTC::TC("qpdf", "QPDFWriter generate >1 ostream");
|
||||||
@ -2339,7 +2312,7 @@ QPDFWriter::generateObjectStreams()
|
|||||||
this->m->pdf.makeIndirectObject(QPDFObjectHandle::newNull())
|
this->m->pdf.makeIndirectObject(QPDFObjectHandle::newNull())
|
||||||
.getObjectID();
|
.getObjectID();
|
||||||
}
|
}
|
||||||
this->m->object_to_object_stream[*iter] = cur_ostream;
|
this->m->object_to_object_stream[iter] = cur_ostream;
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2495,10 +2468,7 @@ QPDFWriter::doWriteSetup()
|
|||||||
if (this->m->linearized) {
|
if (this->m->linearized) {
|
||||||
// Page dictionaries are not allowed to be compressed objects.
|
// Page dictionaries are not allowed to be compressed objects.
|
||||||
std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages();
|
std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages();
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = pages.begin();
|
for (auto& page: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle& page = *iter;
|
|
||||||
QPDFObjGen og = page.getObjGen();
|
QPDFObjGen og = page.getObjGen();
|
||||||
if (this->m->object_to_object_stream.count(og)) {
|
if (this->m->object_to_object_stream.count(og)) {
|
||||||
QTC::TC("qpdf", "QPDFWriter uncompressing page dictionary");
|
QTC::TC("qpdf", "QPDFWriter uncompressing page dictionary");
|
||||||
@ -2521,12 +2491,9 @@ QPDFWriter::doWriteSetup()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate reverse mapping from object stream to objects
|
// Generate reverse mapping from object stream to objects
|
||||||
for (std::map<QPDFObjGen, int>::iterator iter =
|
for (auto const& iter: this->m->object_to_object_stream) {
|
||||||
this->m->object_to_object_stream.begin();
|
QPDFObjGen const& obj = iter.first;
|
||||||
iter != this->m->object_to_object_stream.end();
|
int stream = iter.second;
|
||||||
++iter) {
|
|
||||||
QPDFObjGen obj = (*iter).first;
|
|
||||||
int stream = (*iter).second;
|
|
||||||
this->m->object_stream_to_objects[stream].insert(obj);
|
this->m->object_stream_to_objects[stream].insert(obj);
|
||||||
this->m->max_ostream_index = std::max(
|
this->m->max_ostream_index = std::max(
|
||||||
this->m->max_ostream_index,
|
this->m->max_ostream_index,
|
||||||
@ -2591,11 +2558,9 @@ QPDFWriter::getWrittenXRefTable()
|
|||||||
{
|
{
|
||||||
std::map<QPDFObjGen, QPDFXRefEntry> result;
|
std::map<QPDFObjGen, QPDFXRefEntry> result;
|
||||||
|
|
||||||
for (std::map<int, QPDFXRefEntry>::iterator iter = this->m->xref.begin();
|
for (auto const& iter: this->m->xref) {
|
||||||
iter != this->m->xref.end();
|
if (iter.first != 0 && iter.second.getType() != 0) {
|
||||||
++iter) {
|
result[QPDFObjGen(iter.first, 0)] = iter.second;
|
||||||
if (iter->first != 0 && iter->second.getType() != 0) {
|
|
||||||
result[QPDFObjGen(iter->first, 0)] = iter->second;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2605,10 +2570,8 @@ QPDFWriter::getWrittenXRefTable()
|
|||||||
void
|
void
|
||||||
QPDFWriter::enqueuePart(std::vector<QPDFObjectHandle>& part)
|
QPDFWriter::enqueuePart(std::vector<QPDFObjectHandle>& part)
|
||||||
{
|
{
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = part.begin();
|
for (auto const& oh: part) {
|
||||||
iter != part.end();
|
enqueueObject(oh);
|
||||||
++iter) {
|
|
||||||
enqueueObject(*iter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2617,14 +2580,11 @@ QPDFWriter::writeEncryptionDictionary()
|
|||||||
{
|
{
|
||||||
this->m->encryption_dict_objid = openObject(this->m->encryption_dict_objid);
|
this->m->encryption_dict_objid = openObject(this->m->encryption_dict_objid);
|
||||||
writeString("<<");
|
writeString("<<");
|
||||||
for (std::map<std::string, std::string>::iterator iter =
|
for (auto const& iter: this->m->encryption_dictionary) {
|
||||||
this->m->encryption_dictionary.begin();
|
|
||||||
iter != this->m->encryption_dictionary.end();
|
|
||||||
++iter) {
|
|
||||||
writeString(" ");
|
writeString(" ");
|
||||||
writeString((*iter).first);
|
writeString(iter.first);
|
||||||
writeString(" ");
|
writeString(" ");
|
||||||
writeString((*iter).second);
|
writeString(iter.second);
|
||||||
}
|
}
|
||||||
writeString(" >>");
|
writeString(" >>");
|
||||||
closeObject(this->m->encryption_dict_objid);
|
closeObject(this->m->encryption_dict_objid);
|
||||||
@ -2937,10 +2897,8 @@ QPDFWriter::discardGeneration(
|
|||||||
// maps for QPDF that throw away generation numbers.
|
// maps for QPDF that throw away generation numbers.
|
||||||
|
|
||||||
out.clear();
|
out.clear();
|
||||||
for (std::map<QPDFObjGen, int>::const_iterator iter = in.begin();
|
for (auto const& iter: in) {
|
||||||
iter != in.end();
|
if (out.count(iter.first.getObj())) {
|
||||||
++iter) {
|
|
||||||
if (out.count((*iter).first.getObj())) {
|
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"QPDF cannot currently linearize files that contain"
|
"QPDF cannot currently linearize files that contain"
|
||||||
" multiple objects with the same object ID and different"
|
" multiple objects with the same object ID and different"
|
||||||
@ -2950,7 +2908,7 @@ QPDFWriter::discardGeneration(
|
|||||||
" linearizing, and then linearize the result of that"
|
" linearizing, and then linearize the result of that"
|
||||||
" conversion.");
|
" conversion.");
|
||||||
}
|
}
|
||||||
out[(*iter).first.getObj()] = (*iter).second;
|
out[iter.first.getObj()] = iter.second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3020,10 +2978,8 @@ QPDFWriter::writeLinearized()
|
|||||||
// Assign numbers to all compressed objects in the second half.
|
// Assign numbers to all compressed objects in the second half.
|
||||||
std::vector<QPDFObjectHandle>* vecs2[] = {&part7, &part8, &part9};
|
std::vector<QPDFObjectHandle>* vecs2[] = {&part7, &part8, &part9};
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = (*vecs2[i]).begin();
|
for (auto const& oh: *vecs2[i]) {
|
||||||
iter != (*vecs2[i]).end();
|
assignCompressedObjectNumbers(oh.getObjGen());
|
||||||
++iter) {
|
|
||||||
assignCompressedObjectNumbers((*iter).getObjGen());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int second_half_end = this->m->next_objid - 1;
|
int second_half_end = this->m->next_objid - 1;
|
||||||
@ -3049,10 +3005,8 @@ QPDFWriter::writeLinearized()
|
|||||||
// Assign numbers to all compressed objects in the first half
|
// Assign numbers to all compressed objects in the first half
|
||||||
std::vector<QPDFObjectHandle>* vecs1[] = {&part4, &part6};
|
std::vector<QPDFObjectHandle>* vecs1[] = {&part4, &part6};
|
||||||
for (int i = 0; i < 2; ++i) {
|
for (int i = 0; i < 2; ++i) {
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = (*vecs1[i]).begin();
|
for (auto const& oh: *vecs1[i]) {
|
||||||
iter != (*vecs1[i]).end();
|
assignCompressedObjectNumbers(oh.getObjGen());
|
||||||
++iter) {
|
|
||||||
assignCompressedObjectNumbers((*iter).getObjGen());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int first_half_end = this->m->next_objid - 1;
|
int first_half_end = this->m->next_objid - 1;
|
||||||
@ -3240,11 +3194,7 @@ QPDFWriter::writeLinearized()
|
|||||||
|
|
||||||
// Parts 4 through 9
|
// Parts 4 through 9
|
||||||
|
|
||||||
for (std::list<QPDFObjectHandle>::iterator iter =
|
for (auto const& cur_object: this->m->object_queue) {
|
||||||
this->m->object_queue.begin();
|
|
||||||
iter != this->m->object_queue.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle cur_object = (*iter);
|
|
||||||
if (cur_object.getObjectID() == part6_end_marker) {
|
if (cur_object.getObjectID() == part6_end_marker) {
|
||||||
first_half_max_obj_offset = this->m->pipeline->getCount();
|
first_half_max_obj_offset = this->m->pipeline->getCount();
|
||||||
}
|
}
|
||||||
@ -3390,11 +3340,8 @@ QPDFWriter::enqueueObjectsStandard()
|
|||||||
{
|
{
|
||||||
if (this->m->preserve_unreferenced_objects) {
|
if (this->m->preserve_unreferenced_objects) {
|
||||||
QTC::TC("qpdf", "QPDFWriter preserve unreferenced standard");
|
QTC::TC("qpdf", "QPDFWriter preserve unreferenced standard");
|
||||||
std::vector<QPDFObjectHandle> all = this->m->pdf.getAllObjects();
|
for (auto const& oh: this->m->pdf.getAllObjects()) {
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = all.begin();
|
enqueueObject(oh);
|
||||||
iter != all.end();
|
|
||||||
++iter) {
|
|
||||||
enqueueObject(*iter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3407,10 +3354,8 @@ QPDFWriter::enqueueObjectsStandard()
|
|||||||
// Root is already there, so enqueuing it a second time is a
|
// Root is already there, so enqueuing it a second time is a
|
||||||
// no-op.
|
// no-op.
|
||||||
std::set<std::string> keys = trailer.getKeys();
|
std::set<std::string> keys = trailer.getKeys();
|
||||||
for (std::set<std::string>::iterator iter = keys.begin();
|
for (auto const& key: keys) {
|
||||||
iter != keys.end();
|
enqueueObject(trailer.getKey(key));
|
||||||
++iter) {
|
|
||||||
enqueueObject(trailer.getKey(*iter));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3424,23 +3369,18 @@ QPDFWriter::enqueueObjectsPCLm()
|
|||||||
|
|
||||||
// enqueue all pages first
|
// enqueue all pages first
|
||||||
std::vector<QPDFObjectHandle> all = this->m->pdf.getAllPages();
|
std::vector<QPDFObjectHandle> all = this->m->pdf.getAllPages();
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = all.begin();
|
for (auto& page: all) {
|
||||||
iter != all.end();
|
|
||||||
++iter) {
|
|
||||||
// enqueue page
|
// enqueue page
|
||||||
enqueueObject(*iter);
|
enqueueObject(page);
|
||||||
|
|
||||||
// enqueue page contents stream
|
// enqueue page contents stream
|
||||||
enqueueObject((*iter).getKey("/Contents"));
|
enqueueObject(page.getKey("/Contents"));
|
||||||
|
|
||||||
// enqueue all the strips for each page
|
// enqueue all the strips for each page
|
||||||
QPDFObjectHandle strips =
|
QPDFObjectHandle strips = page.getKey("/Resources").getKey("/XObject");
|
||||||
(*iter).getKey("/Resources").getKey("/XObject");
|
|
||||||
std::set<std::string> keys = strips.getKeys();
|
std::set<std::string> keys = strips.getKeys();
|
||||||
for (std::set<std::string>::iterator image = keys.begin();
|
for (auto const& image: keys) {
|
||||||
image != keys.end();
|
enqueueObject(strips.getKey(image));
|
||||||
++image) {
|
|
||||||
enqueueObject(strips.getKey(*image));
|
|
||||||
enqueueObject(QPDFObjectHandle::newStream(
|
enqueueObject(QPDFObjectHandle::newStream(
|
||||||
&this->m->pdf, image_transform_content));
|
&this->m->pdf, image_transform_content));
|
||||||
}
|
}
|
||||||
|
@ -99,10 +99,8 @@ void
|
|||||||
QPDF_Array::setFromVector(std::vector<QPDFObjectHandle> const& v)
|
QPDF_Array::setFromVector(std::vector<QPDFObjectHandle> const& v)
|
||||||
{
|
{
|
||||||
this->elements = SparseOHArray();
|
this->elements = SparseOHArray();
|
||||||
for (std::vector<QPDFObjectHandle>::const_iterator iter = v.begin();
|
for (auto const& iter: v) {
|
||||||
iter != v.end();
|
this->elements.append(iter);
|
||||||
++iter) {
|
|
||||||
this->elements.append(*iter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,11 +12,8 @@ QPDF_Dictionary::QPDF_Dictionary(
|
|||||||
void
|
void
|
||||||
QPDF_Dictionary::releaseResolved()
|
QPDF_Dictionary::releaseResolved()
|
||||||
{
|
{
|
||||||
for (std::map<std::string, QPDFObjectHandle>::iterator iter =
|
for (auto& iter: this->items) {
|
||||||
this->items.begin();
|
QPDFObjectHandle::ReleaseResolver::releaseResolved(iter.second);
|
||||||
iter != this->items.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle::ReleaseResolver::releaseResolved((*iter).second);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -945,11 +945,7 @@ QPDF::initializeEncryption()
|
|||||||
|
|
||||||
if ((V == 4) || (V == 5)) {
|
if ((V == 4) || (V == 5)) {
|
||||||
QPDFObjectHandle CF = encryption_dict.getKey("/CF");
|
QPDFObjectHandle CF = encryption_dict.getKey("/CF");
|
||||||
std::set<std::string> keys = CF.getKeys();
|
for (auto const& filter: CF.getKeys()) {
|
||||||
for (std::set<std::string>::iterator iter = keys.begin();
|
|
||||||
iter != keys.end();
|
|
||||||
++iter) {
|
|
||||||
std::string const& filter = *iter;
|
|
||||||
QPDFObjectHandle cdict = CF.getKey(filter);
|
QPDFObjectHandle cdict = CF.getKey(filter);
|
||||||
if (cdict.isDictionary()) {
|
if (cdict.isDictionary()) {
|
||||||
encryption_method_e method = e_none;
|
encryption_method_e method = e_none;
|
||||||
|
@ -583,12 +583,9 @@ QPDF::checkLinearizationInternal()
|
|||||||
// uncompressed.
|
// uncompressed.
|
||||||
{ // local scope
|
{ // local scope
|
||||||
std::map<int, int> object_stream_data;
|
std::map<int, int> object_stream_data;
|
||||||
for (std::map<QPDFObjGen, QPDFXRefEntry>::const_iterator iter =
|
for (auto const& iter: this->m->xref_table) {
|
||||||
this->m->xref_table.begin();
|
QPDFObjGen const& og = iter.first;
|
||||||
iter != this->m->xref_table.end();
|
QPDFXRefEntry const& entry = iter.second;
|
||||||
++iter) {
|
|
||||||
QPDFObjGen const& og = (*iter).first;
|
|
||||||
QPDFXRefEntry const& entry = (*iter).second;
|
|
||||||
if (entry.getType() == 2) {
|
if (entry.getType() == 2) {
|
||||||
object_stream_data[og.getObj()] = entry.getObjStreamNumber();
|
object_stream_data[og.getObj()] = entry.getObjStreamNumber();
|
||||||
}
|
}
|
||||||
@ -613,10 +610,8 @@ QPDF::checkLinearizationInternal()
|
|||||||
}
|
}
|
||||||
qpdf_offset_t min_E = -1;
|
qpdf_offset_t min_E = -1;
|
||||||
qpdf_offset_t max_E = -1;
|
qpdf_offset_t max_E = -1;
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = this->m->part6.begin();
|
for (auto const& oh: this->m->part6) {
|
||||||
iter != this->m->part6.end();
|
QPDFObjGen og(oh.getObjGen());
|
||||||
++iter) {
|
|
||||||
QPDFObjGen og((*iter).getObjGen());
|
|
||||||
if (this->m->obj_cache.count(og) == 0) {
|
if (this->m->obj_cache.count(og) == 0) {
|
||||||
// All objects have to have been dereferenced to be classified.
|
// All objects have to have been dereferenced to be classified.
|
||||||
throw std::logic_error("linearization part6 object not in cache");
|
throw std::logic_error("linearization part6 object not in cache");
|
||||||
@ -651,19 +646,15 @@ QPDF::checkLinearizationInternal()
|
|||||||
// code.
|
// code.
|
||||||
if (!errors.empty()) {
|
if (!errors.empty()) {
|
||||||
result = false;
|
result = false;
|
||||||
for (std::list<std::string>::iterator iter = errors.begin();
|
for (auto const& error: errors) {
|
||||||
iter != errors.end();
|
*this->m->err_stream << "WARNING: " << error << std::endl;
|
||||||
++iter) {
|
|
||||||
*this->m->err_stream << "WARNING: " << (*iter) << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!warnings.empty()) {
|
if (!warnings.empty()) {
|
||||||
result = false;
|
result = false;
|
||||||
for (std::list<std::string>::iterator iter = warnings.begin();
|
for (auto const& warning: warnings) {
|
||||||
iter != warnings.end();
|
*this->m->err_stream << "WARNING: " << warning << std::endl;
|
||||||
++iter) {
|
|
||||||
*this->m->err_stream << "WARNING: " << (*iter) << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -678,10 +669,7 @@ QPDF::maxEnd(ObjUser const& ou)
|
|||||||
}
|
}
|
||||||
std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou];
|
std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou];
|
||||||
qpdf_offset_t end = 0;
|
qpdf_offset_t end = 0;
|
||||||
for (std::set<QPDFObjGen>::const_iterator iter = ogs.begin();
|
for (auto const& og: ogs) {
|
||||||
iter != ogs.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjGen const& og = *iter;
|
|
||||||
if (this->m->obj_cache.count(og) == 0) {
|
if (this->m->obj_cache.count(og) == 0) {
|
||||||
stopOnError("unknown object referenced in object user table");
|
stopOnError("unknown object referenced in object user table");
|
||||||
}
|
}
|
||||||
@ -855,28 +843,24 @@ QPDF::checkHPageOffset(
|
|||||||
computed_shared.insert(obj);
|
computed_shared.insert(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::set<int>::iterator iter = hint_shared.begin();
|
for (int iter: hint_shared) {
|
||||||
iter != hint_shared.end();
|
if (!computed_shared.count(iter)) {
|
||||||
++iter) {
|
|
||||||
if (!computed_shared.count(*iter)) {
|
|
||||||
// pdlin puts thumbnails here even though it shouldn't
|
// pdlin puts thumbnails here even though it shouldn't
|
||||||
warnings.push_back(
|
warnings.push_back(
|
||||||
"page " + QUtil::int_to_string(pageno) +
|
"page " + QUtil::int_to_string(pageno) +
|
||||||
": shared object " + QUtil::int_to_string(*iter) +
|
": shared object " + QUtil::int_to_string(iter) +
|
||||||
": in hint table but not computed list");
|
": in hint table but not computed list");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::set<int>::iterator iter = computed_shared.begin();
|
for (int iter: computed_shared) {
|
||||||
iter != computed_shared.end();
|
if (!hint_shared.count(iter)) {
|
||||||
++iter) {
|
|
||||||
if (!hint_shared.count(*iter)) {
|
|
||||||
// Acrobat does not put some things including at least
|
// Acrobat does not put some things including at least
|
||||||
// built-in fonts and procsets here, at least in some
|
// built-in fonts and procsets here, at least in some
|
||||||
// cases.
|
// cases.
|
||||||
warnings.push_back(
|
warnings.push_back(
|
||||||
"page " + QUtil::int_to_string(pageno) +
|
"page " + QUtil::int_to_string(pageno) +
|
||||||
": shared object " + QUtil::int_to_string(*iter) +
|
": shared object " + QUtil::int_to_string(iter) +
|
||||||
": in computed list but not hint table");
|
": in computed list but not hint table");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1290,13 +1274,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
std::set<QPDFObjGen> lc_outlines;
|
std::set<QPDFObjGen> lc_outlines;
|
||||||
std::set<QPDFObjGen> lc_root;
|
std::set<QPDFObjGen> lc_root;
|
||||||
|
|
||||||
for (std::map<QPDFObjGen, std::set<ObjUser>>::iterator oiter =
|
for (auto& oiter: this->m->object_to_obj_users) {
|
||||||
this->m->object_to_obj_users.begin();
|
QPDFObjGen const& og = oiter.first;
|
||||||
oiter != this->m->object_to_obj_users.end();
|
std::set<ObjUser>& ous = oiter.second;
|
||||||
++oiter) {
|
|
||||||
QPDFObjGen const& og = (*oiter).first;
|
|
||||||
|
|
||||||
std::set<ObjUser>& ous = (*oiter).second;
|
|
||||||
|
|
||||||
bool in_open_document = false;
|
bool in_open_document = false;
|
||||||
bool in_first_page = false;
|
bool in_first_page = false;
|
||||||
@ -1306,10 +1286,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
bool in_outlines = false;
|
bool in_outlines = false;
|
||||||
bool is_root = false;
|
bool is_root = false;
|
||||||
|
|
||||||
for (std::set<ObjUser>::iterator uiter = ous.begin();
|
for (auto const& ou: ous) {
|
||||||
uiter != ous.end();
|
|
||||||
++uiter) {
|
|
||||||
ObjUser const& ou = *uiter;
|
|
||||||
switch (ou.ou_type) {
|
switch (ou.ou_type) {
|
||||||
case ObjUser::ou_trailer_key:
|
case ObjUser::ou_trailer_key:
|
||||||
if (ou.key == "/Encrypt") {
|
if (ou.key == "/Encrypt") {
|
||||||
@ -1396,11 +1373,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
{ // local scope
|
{ // local scope
|
||||||
// Map all page objects to the containing object stream. This
|
// Map all page objects to the containing object stream. This
|
||||||
// should be a no-op in a properly linearized file.
|
// should be a no-op in a properly linearized file.
|
||||||
std::vector<QPDFObjectHandle> t = getAllPages();
|
for (auto oh: getAllPages()) {
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = t.begin();
|
pages.push_back(getUncompressedObject(oh, object_stream_data));
|
||||||
iter != t.end();
|
|
||||||
++iter) {
|
|
||||||
pages.push_back(getUncompressedObject(*iter, object_stream_data));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int npages = toI(pages.size());
|
int npages = toI(pages.size());
|
||||||
@ -1427,10 +1401,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
" calculating linearization data");
|
" calculating linearization data");
|
||||||
}
|
}
|
||||||
this->m->part4.push_back(objGenToIndirect(*(lc_root.begin())));
|
this->m->part4.push_back(objGenToIndirect(*(lc_root.begin())));
|
||||||
for (std::set<QPDFObjGen>::iterator iter = lc_open_document.begin();
|
for (auto const& og: lc_open_document) {
|
||||||
iter != lc_open_document.end();
|
this->m->part4.push_back(objGenToIndirect(og));
|
||||||
++iter) {
|
|
||||||
this->m->part4.push_back(objGenToIndirect(*iter));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Part 6: first page objects. Note: implementation note 124
|
// Part 6: first page objects. Note: implementation note 124
|
||||||
@ -1458,16 +1430,12 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
// groups private and shared objects contiguously for the sake of
|
// groups private and shared objects contiguously for the sake of
|
||||||
// hint tables.
|
// hint tables.
|
||||||
|
|
||||||
for (std::set<QPDFObjGen>::iterator iter = lc_first_page_private.begin();
|
for (auto const& og: lc_first_page_private) {
|
||||||
iter != lc_first_page_private.end();
|
this->m->part6.push_back(objGenToIndirect(og));
|
||||||
++iter) {
|
|
||||||
this->m->part6.push_back(objGenToIndirect(*iter));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::set<QPDFObjGen>::iterator iter = lc_first_page_shared.begin();
|
for (auto const& og: lc_first_page_shared) {
|
||||||
iter != lc_first_page_shared.end();
|
this->m->part6.push_back(objGenToIndirect(og));
|
||||||
++iter) {
|
|
||||||
this->m->part6.push_back(objGenToIndirect(*iter));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Place the outline dictionary if it goes in the first page section.
|
// Place the outline dictionary if it goes in the first page section.
|
||||||
@ -1511,10 +1479,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
" calculating linearization data");
|
" calculating linearization data");
|
||||||
}
|
}
|
||||||
std::set<QPDFObjGen> ogs = this->m->obj_user_to_objects[ou];
|
std::set<QPDFObjGen> ogs = this->m->obj_user_to_objects[ou];
|
||||||
for (std::set<QPDFObjGen>::iterator iter = ogs.begin();
|
for (auto const& og: ogs) {
|
||||||
iter != ogs.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjGen const& og = (*iter);
|
|
||||||
if (lc_other_page_private.count(og)) {
|
if (lc_other_page_private.count(og)) {
|
||||||
lc_other_page_private.erase(og);
|
lc_other_page_private.erase(og);
|
||||||
this->m->part7.push_back(objGenToIndirect(og));
|
this->m->part7.push_back(objGenToIndirect(og));
|
||||||
@ -1533,10 +1498,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
// Part 8: other pages' shared objects
|
// Part 8: other pages' shared objects
|
||||||
|
|
||||||
// Order is unimportant.
|
// Order is unimportant.
|
||||||
for (std::set<QPDFObjGen>::iterator iter = lc_other_page_shared.begin();
|
for (auto const& og: lc_other_page_shared) {
|
||||||
iter != lc_other_page_shared.end();
|
this->m->part8.push_back(objGenToIndirect(og));
|
||||||
++iter) {
|
|
||||||
this->m->part8.push_back(objGenToIndirect(*iter));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Part 9: other objects
|
// Part 9: other objects
|
||||||
@ -1555,10 +1518,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
stopOnError("found empty pages tree while"
|
stopOnError("found empty pages tree while"
|
||||||
" calculating linearization data");
|
" calculating linearization data");
|
||||||
}
|
}
|
||||||
for (std::set<QPDFObjGen>::iterator iter = pages_ogs.begin();
|
for (auto const& og: pages_ogs) {
|
||||||
iter != pages_ogs.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjGen const& og = *iter;
|
|
||||||
if (lc_other.count(og)) {
|
if (lc_other.count(og)) {
|
||||||
lc_other.erase(og);
|
lc_other.erase(og);
|
||||||
this->m->part9.push_back(objGenToIndirect(og));
|
this->m->part9.push_back(objGenToIndirect(og));
|
||||||
@ -1588,10 +1548,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
std::set<QPDFObjGen>& ogs =
|
std::set<QPDFObjGen>& ogs =
|
||||||
this->m
|
this->m
|
||||||
->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))];
|
->obj_user_to_objects[ObjUser(ObjUser::ou_thumb, toI(i))];
|
||||||
for (std::set<QPDFObjGen>::iterator iter = ogs.begin();
|
for (auto const& og: ogs) {
|
||||||
iter != ogs.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjGen const& og = *iter;
|
|
||||||
if (lc_thumbnail_private.count(og)) {
|
if (lc_thumbnail_private.count(og)) {
|
||||||
lc_thumbnail_private.erase(og);
|
lc_thumbnail_private.erase(og);
|
||||||
this->m->part9.push_back(objGenToIndirect(og));
|
this->m->part9.push_back(objGenToIndirect(og));
|
||||||
@ -1606,10 +1563,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Place shared thumbnail objects
|
// Place shared thumbnail objects
|
||||||
for (std::set<QPDFObjGen>::iterator iter = lc_thumbnail_shared.begin();
|
for (auto const& og: lc_thumbnail_shared) {
|
||||||
iter != lc_thumbnail_shared.end();
|
this->m->part9.push_back(objGenToIndirect(og));
|
||||||
++iter) {
|
|
||||||
this->m->part9.push_back(objGenToIndirect(*iter));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Place outlines unless in first page
|
// Place outlines unless in first page
|
||||||
@ -1618,10 +1573,8 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Place all remaining objects
|
// Place all remaining objects
|
||||||
for (std::set<QPDFObjGen>::iterator iter = lc_other.begin();
|
for (auto const& og: lc_other) {
|
||||||
iter != lc_other.end();
|
this->m->part9.push_back(objGenToIndirect(og));
|
||||||
++iter) {
|
|
||||||
this->m->part9.push_back(objGenToIndirect(*iter));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we got everything exactly once.
|
// Make sure we got everything exactly once.
|
||||||
@ -1658,10 +1611,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
|
|
||||||
std::vector<CHSharedObjectEntry>& shared =
|
std::vector<CHSharedObjectEntry>& shared =
|
||||||
this->m->c_shared_object_data.entries;
|
this->m->c_shared_object_data.entries;
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = this->m->part6.begin();
|
for (auto& oh: this->m->part6) {
|
||||||
iter != this->m->part6.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle& oh = *iter;
|
|
||||||
int obj = oh.getObjectID();
|
int obj = oh.getObjectID();
|
||||||
obj_to_index[obj] = toI(shared.size());
|
obj_to_index[obj] = toI(shared.size());
|
||||||
shared.push_back(CHSharedObjectEntry(obj));
|
shared.push_back(CHSharedObjectEntry(obj));
|
||||||
@ -1670,11 +1620,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
if (!this->m->part8.empty()) {
|
if (!this->m->part8.empty()) {
|
||||||
this->m->c_shared_object_data.first_shared_obj =
|
this->m->c_shared_object_data.first_shared_obj =
|
||||||
this->m->part8.at(0).getObjectID();
|
this->m->part8.at(0).getObjectID();
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter =
|
for (auto& oh: this->m->part8) {
|
||||||
this->m->part8.begin();
|
|
||||||
iter != this->m->part8.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle& oh = *iter;
|
|
||||||
int obj = oh.getObjectID();
|
int obj = oh.getObjectID();
|
||||||
obj_to_index[obj] = toI(shared.size());
|
obj_to_index[obj] = toI(shared.size());
|
||||||
shared.push_back(CHSharedObjectEntry(obj));
|
shared.push_back(CHSharedObjectEntry(obj));
|
||||||
@ -1696,10 +1642,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
|||||||
" calculating linearization data");
|
" calculating linearization data");
|
||||||
}
|
}
|
||||||
std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou];
|
std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou];
|
||||||
for (std::set<QPDFObjGen>::const_iterator iter = ogs.begin();
|
for (auto const& og: ogs) {
|
||||||
iter != ogs.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFObjGen const& og = *iter;
|
|
||||||
if ((this->m->object_to_obj_users[og].size() > 1) &&
|
if ((this->m->object_to_obj_users[og].size() > 1) &&
|
||||||
(obj_to_index.count(og.getObj()) > 0)) {
|
(obj_to_index.count(og.getObj()) > 0)) {
|
||||||
int idx = obj_to_index[og.getObj()];
|
int idx = obj_to_index[og.getObj()];
|
||||||
@ -1733,10 +1676,8 @@ QPDF::pushOutlinesToPart(
|
|||||||
this->m->c_outline_data.nobjects = 1;
|
this->m->c_outline_data.nobjects = 1;
|
||||||
lc_outlines.erase(outlines_og);
|
lc_outlines.erase(outlines_og);
|
||||||
part.push_back(outlines);
|
part.push_back(outlines);
|
||||||
for (std::set<QPDFObjGen>::iterator iter = lc_outlines.begin();
|
for (auto const& og: lc_outlines) {
|
||||||
iter != lc_outlines.end();
|
part.push_back(objGenToIndirect(og));
|
||||||
++iter) {
|
|
||||||
part.push_back(objGenToIndirect(*iter));
|
|
||||||
++this->m->c_outline_data.nobjects;
|
++this->m->c_outline_data.nobjects;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,10 +90,7 @@ QPDF::optimize(
|
|||||||
|
|
||||||
// Traverse document-level items
|
// Traverse document-level items
|
||||||
std::set<std::string> keys = this->m->trailer.getKeys();
|
std::set<std::string> keys = this->m->trailer.getKeys();
|
||||||
for (std::set<std::string>::iterator iter = keys.begin();
|
for (auto const& key: keys) {
|
||||||
iter != keys.end();
|
|
||||||
++iter) {
|
|
||||||
std::string const& key = *iter;
|
|
||||||
if (key == "/Root") {
|
if (key == "/Root") {
|
||||||
// handled separately
|
// handled separately
|
||||||
} else {
|
} else {
|
||||||
@ -105,17 +102,13 @@ QPDF::optimize(
|
|||||||
}
|
}
|
||||||
|
|
||||||
keys = root.getKeys();
|
keys = root.getKeys();
|
||||||
for (std::set<std::string>::iterator iter = keys.begin();
|
for (auto const& key: keys) {
|
||||||
iter != keys.end();
|
|
||||||
++iter) {
|
|
||||||
// Technically, /I keys from /Thread dictionaries are supposed
|
// Technically, /I keys from /Thread dictionaries are supposed
|
||||||
// to be handled separately, but we are going to disregard
|
// to be handled separately, but we are going to disregard
|
||||||
// that specification for now. There is loads of evidence
|
// that specification for now. There is loads of evidence
|
||||||
// that pdlin and Acrobat both disregard things like this from
|
// that pdlin and Acrobat both disregard things like this from
|
||||||
// time to time, so this is almost certain not to cause any
|
// time to time, so this is almost certain not to cause any
|
||||||
// problems.
|
// problems.
|
||||||
|
|
||||||
std::string const& key = *iter;
|
|
||||||
updateObjectMaps(
|
updateObjectMaps(
|
||||||
ObjUser(ObjUser::ou_root_key, key),
|
ObjUser(ObjUser::ou_root_key, key),
|
||||||
root.getKey(key),
|
root.getKey(key),
|
||||||
@ -212,10 +205,7 @@ QPDF::pushInheritedAttributesToPageInternal(
|
|||||||
|
|
||||||
std::set<std::string> inheritable_keys;
|
std::set<std::string> inheritable_keys;
|
||||||
std::set<std::string> keys = cur_pages.getKeys();
|
std::set<std::string> keys = cur_pages.getKeys();
|
||||||
for (std::set<std::string>::iterator iter = keys.begin();
|
for (auto const& key: keys) {
|
||||||
iter != keys.end();
|
|
||||||
++iter) {
|
|
||||||
std::string const& key = *iter;
|
|
||||||
if ((key == "/MediaBox") || (key == "/CropBox") ||
|
if ((key == "/MediaBox") || (key == "/CropBox") ||
|
||||||
(key == "/Resources") || (key == "/Rotate")) {
|
(key == "/Resources") || (key == "/Rotate")) {
|
||||||
if (!allow_changes) {
|
if (!allow_changes) {
|
||||||
@ -298,11 +288,7 @@ QPDF::pushInheritedAttributesToPageInternal(
|
|||||||
|
|
||||||
if (!inheritable_keys.empty()) {
|
if (!inheritable_keys.empty()) {
|
||||||
QTC::TC("qpdf", "QPDF opt inheritable keys");
|
QTC::TC("qpdf", "QPDF opt inheritable keys");
|
||||||
for (std::set<std::string>::iterator iter =
|
for (auto const& key: inheritable_keys) {
|
||||||
inheritable_keys.begin();
|
|
||||||
iter != inheritable_keys.end();
|
|
||||||
++iter) {
|
|
||||||
std::string const& key = (*iter);
|
|
||||||
key_ancestors[key].pop_back();
|
key_ancestors[key].pop_back();
|
||||||
if (key_ancestors[key].empty()) {
|
if (key_ancestors[key].empty()) {
|
||||||
QTC::TC("qpdf", "QPDF opt erase empty key ancestor");
|
QTC::TC("qpdf", "QPDF opt erase empty key ancestor");
|
||||||
@ -315,14 +301,11 @@ QPDF::pushInheritedAttributesToPageInternal(
|
|||||||
} else if (type == "/Page") {
|
} else if (type == "/Page") {
|
||||||
// Add all available inheritable attributes not present in
|
// Add all available inheritable attributes not present in
|
||||||
// this object to this object.
|
// this object to this object.
|
||||||
for (std::map<std::string, std::vector<QPDFObjectHandle>>::iterator
|
for (auto const& iter: key_ancestors) {
|
||||||
iter = key_ancestors.begin();
|
std::string const& key = iter.first;
|
||||||
iter != key_ancestors.end();
|
|
||||||
++iter) {
|
|
||||||
std::string const& key = (*iter).first;
|
|
||||||
if (!cur_pages.hasKey(key)) {
|
if (!cur_pages.hasKey(key)) {
|
||||||
QTC::TC("qpdf", "QPDF opt resource inherited");
|
QTC::TC("qpdf", "QPDF opt resource inherited");
|
||||||
cur_pages.replaceKey(key, (*iter).second.back());
|
cur_pages.replaceKey(key, iter.second.back());
|
||||||
} else {
|
} else {
|
||||||
QTC::TC("qpdf", "QPDF opt page resource hides ancestor");
|
QTC::TC("qpdf", "QPDF opt page resource hides ancestor");
|
||||||
}
|
}
|
||||||
@ -404,10 +387,7 @@ QPDF::updateObjectMapsInternal(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::set<std::string> keys = dict.getKeys();
|
std::set<std::string> keys = dict.getKeys();
|
||||||
for (std::set<std::string>::iterator iter = keys.begin();
|
for (auto const& key: keys) {
|
||||||
iter != keys.end();
|
|
||||||
++iter) {
|
|
||||||
std::string const& key = *iter;
|
|
||||||
if (is_page_node && (key == "/Thumb")) {
|
if (is_page_node && (key == "/Thumb")) {
|
||||||
// Traverse page thumbnail dictionaries as a special
|
// Traverse page thumbnail dictionaries as a special
|
||||||
// case.
|
// case.
|
||||||
@ -454,42 +434,28 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data)
|
|||||||
std::map<ObjUser, std::set<QPDFObjGen>> t_obj_user_to_objects;
|
std::map<ObjUser, std::set<QPDFObjGen>> t_obj_user_to_objects;
|
||||||
std::map<QPDFObjGen, std::set<ObjUser>> t_object_to_obj_users;
|
std::map<QPDFObjGen, std::set<ObjUser>> t_object_to_obj_users;
|
||||||
|
|
||||||
for (std::map<ObjUser, std::set<QPDFObjGen>>::iterator i1 =
|
for (auto const& i1: this->m->obj_user_to_objects) {
|
||||||
this->m->obj_user_to_objects.begin();
|
ObjUser const& ou = i1.first;
|
||||||
i1 != this->m->obj_user_to_objects.end();
|
std::set<QPDFObjGen> const& objects = i1.second;
|
||||||
++i1) {
|
for (auto const& og: objects) {
|
||||||
ObjUser const& ou = (*i1).first;
|
auto i2 = object_stream_data.find(og.getObj());
|
||||||
std::set<QPDFObjGen> const& objects = (*i1).second;
|
if (i2 == object_stream_data.end()) {
|
||||||
for (std::set<QPDFObjGen>::const_iterator i2 = objects.begin();
|
|
||||||
i2 != objects.end();
|
|
||||||
++i2) {
|
|
||||||
QPDFObjGen const& og = (*i2);
|
|
||||||
std::map<int, int>::const_iterator i3 =
|
|
||||||
object_stream_data.find(og.getObj());
|
|
||||||
if (i3 == object_stream_data.end()) {
|
|
||||||
t_obj_user_to_objects[ou].insert(og);
|
t_obj_user_to_objects[ou].insert(og);
|
||||||
} else {
|
} else {
|
||||||
t_obj_user_to_objects[ou].insert(QPDFObjGen((*i3).second, 0));
|
t_obj_user_to_objects[ou].insert(QPDFObjGen(i2->second, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::map<QPDFObjGen, std::set<ObjUser>>::iterator i1 =
|
for (auto const& i1: this->m->object_to_obj_users) {
|
||||||
this->m->object_to_obj_users.begin();
|
QPDFObjGen const& og = i1.first;
|
||||||
i1 != this->m->object_to_obj_users.end();
|
std::set<ObjUser> const& objusers = i1.second;
|
||||||
++i1) {
|
for (auto const& ou: objusers) {
|
||||||
QPDFObjGen const& og = (*i1).first;
|
auto i2 = object_stream_data.find(og.getObj());
|
||||||
std::set<ObjUser> const& objusers = (*i1).second;
|
if (i2 == object_stream_data.end()) {
|
||||||
for (std::set<ObjUser>::const_iterator i2 = objusers.begin();
|
|
||||||
i2 != objusers.end();
|
|
||||||
++i2) {
|
|
||||||
ObjUser const& ou = (*i2);
|
|
||||||
std::map<int, int>::const_iterator i3 =
|
|
||||||
object_stream_data.find(og.getObj());
|
|
||||||
if (i3 == object_stream_data.end()) {
|
|
||||||
t_object_to_obj_users[og].insert(ou);
|
t_object_to_obj_users[og].insert(ou);
|
||||||
} else {
|
} else {
|
||||||
t_object_to_obj_users[QPDFObjGen((*i3).second, 0)].insert(ou);
|
t_object_to_obj_users[QPDFObjGen(i2->second, 0)].insert(ou);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,8 +319,7 @@ int
|
|||||||
QPDF::findPage(QPDFObjGen const& og)
|
QPDF::findPage(QPDFObjGen const& og)
|
||||||
{
|
{
|
||||||
flattenPagesTree();
|
flattenPagesTree();
|
||||||
std::map<QPDFObjGen, int>::iterator it =
|
auto it = this->m->pageobj_to_pages_pos.find(og);
|
||||||
this->m->pageobj_to_pages_pos.find(og);
|
|
||||||
if (it == this->m->pageobj_to_pages_pos.end()) {
|
if (it == this->m->pageobj_to_pages_pos.end()) {
|
||||||
QTC::TC("qpdf", "QPDF_pages findPage not found");
|
QTC::TC("qpdf", "QPDF_pages findPage not found");
|
||||||
setLastObjectDescription("page object", og.getObj(), og.getGen());
|
setLastObjectDescription("page object", og.getObj(), og.getGen());
|
||||||
|
@ -786,14 +786,13 @@ QUtil::hex_decode(std::string const& input)
|
|||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
for (std::string::const_iterator p = input.begin(); p != input.end(); ++p) {
|
for (auto ch: input) {
|
||||||
char ch = *p;
|
|
||||||
bool skip = false;
|
bool skip = false;
|
||||||
if ((*p >= 'A') && (*p <= 'F')) {
|
if ((ch >= 'A') && (ch <= 'F')) {
|
||||||
ch = QIntC::to_char(ch - 'A' + 10);
|
ch = QIntC::to_char(ch - 'A' + 10);
|
||||||
} else if ((*p >= 'a') && (*p <= 'f')) {
|
} else if ((ch >= 'a') && (ch <= 'f')) {
|
||||||
ch = QIntC::to_char(ch - 'a' + 10);
|
ch = QIntC::to_char(ch - 'a' + 10);
|
||||||
} else if ((*p >= '0') && (*p <= '9')) {
|
} else if ((ch >= '0') && (ch <= '9')) {
|
||||||
ch = QIntC::to_char(ch - '0');
|
ch = QIntC::to_char(ch - '0');
|
||||||
} else {
|
} else {
|
||||||
skip = true;
|
skip = true;
|
||||||
@ -1921,12 +1920,10 @@ QUtil::possible_repaired_encodings(std::string supplied)
|
|||||||
// De-duplicate
|
// De-duplicate
|
||||||
std::vector<std::string> t;
|
std::vector<std::string> t;
|
||||||
std::set<std::string> seen;
|
std::set<std::string> seen;
|
||||||
for (std::vector<std::string>::iterator iter = result.begin();
|
for (auto const& iter: result) {
|
||||||
iter != result.end();
|
if (!seen.count(iter)) {
|
||||||
++iter) {
|
seen.insert(iter);
|
||||||
if (!seen.count(*iter)) {
|
t.push_back(iter);
|
||||||
seen.insert(*iter);
|
|
||||||
t.push_back(*iter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
|
@ -130,10 +130,8 @@ check_schema(
|
|||||||
std::list<std::string> errors;
|
std::list<std::string> errors;
|
||||||
std::cout << "--- " << description << std::endl;
|
std::cout << "--- " << description << std::endl;
|
||||||
assert(exp == obj.checkSchema(schema, flags, errors));
|
assert(exp == obj.checkSchema(schema, flags, errors));
|
||||||
for (std::list<std::string>::iterator iter = errors.begin();
|
for (auto const& error: errors) {
|
||||||
iter != errors.end();
|
std::cout << error << std::endl;
|
||||||
++iter) {
|
|
||||||
std::cout << *iter << std::endl;
|
|
||||||
}
|
}
|
||||||
std::cout << "---" << std::endl;
|
std::cout << "---" << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,8 @@ test_numrange(char const* range)
|
|||||||
} else {
|
} else {
|
||||||
std::vector<int> result = QUtil::parse_numrange(range, 15);
|
std::vector<int> result = QUtil::parse_numrange(range, 15);
|
||||||
std::cout << "numeric range " << range << " ->";
|
std::cout << "numeric range " << range << " ->";
|
||||||
for (std::vector<int>::iterator iter = result.begin();
|
for (int i: result) {
|
||||||
iter != result.end();
|
std::cout << " " << i;
|
||||||
++iter) {
|
|
||||||
std::cout << " " << *iter;
|
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -229,12 +229,10 @@ print_utf8(unsigned long val)
|
|||||||
// Emacs has trouble with utf-8 encoding files with characters
|
// Emacs has trouble with utf-8 encoding files with characters
|
||||||
// outside the 16-bit portion, so just show the character
|
// outside the 16-bit portion, so just show the character
|
||||||
// values.
|
// values.
|
||||||
for (std::string::iterator iter = result.begin(); iter != result.end();
|
for (auto const& ch: result) {
|
||||||
++iter) {
|
|
||||||
std::cout << " "
|
std::cout << " "
|
||||||
<< QUtil::int_to_string_base(
|
<< QUtil::int_to_string_base(
|
||||||
static_cast<int>(
|
static_cast<int>(static_cast<unsigned char>(ch)),
|
||||||
static_cast<unsigned char>(*iter)),
|
|
||||||
16,
|
16,
|
||||||
2);
|
2);
|
||||||
}
|
}
|
||||||
@ -289,11 +287,10 @@ print_utf16(unsigned long val)
|
|||||||
{
|
{
|
||||||
std::string result = QUtil::toUTF16(val);
|
std::string result = QUtil::toUTF16(val);
|
||||||
std::cout << "0x" << QUtil::uint_to_string_base(val, 16) << " ->";
|
std::cout << "0x" << QUtil::uint_to_string_base(val, 16) << " ->";
|
||||||
for (std::string::iterator iter = result.begin(); iter != result.end();
|
for (auto const& ch: result) {
|
||||||
++iter) {
|
|
||||||
std::cout << " "
|
std::cout << " "
|
||||||
<< QUtil::int_to_string_base(
|
<< QUtil::int_to_string_base(
|
||||||
static_cast<int>(static_cast<unsigned char>(*iter)),
|
static_cast<int>(static_cast<unsigned char>(ch)),
|
||||||
16,
|
16,
|
||||||
2);
|
2);
|
||||||
}
|
}
|
||||||
@ -516,10 +513,8 @@ void
|
|||||||
read_from_file_test()
|
read_from_file_test()
|
||||||
{
|
{
|
||||||
std::list<std::string> lines = QUtil::read_lines_from_file("other-file");
|
std::list<std::string> lines = QUtil::read_lines_from_file("other-file");
|
||||||
for (std::list<std::string>::iterator iter = lines.begin();
|
for (auto const& line: lines) {
|
||||||
iter != lines.end();
|
std::cout << line << std::endl;
|
||||||
++iter) {
|
|
||||||
std::cout << *iter << std::endl;
|
|
||||||
}
|
}
|
||||||
// Test the other versions and make sure we get the same results
|
// Test the other versions and make sure we get the same results
|
||||||
{
|
{
|
||||||
|
@ -383,14 +383,9 @@ test_5(QPDF& pdf, char const* arg2)
|
|||||||
QPDFPageDocumentHelper dh(pdf);
|
QPDFPageDocumentHelper dh(pdf);
|
||||||
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
std::vector<QPDFPageObjectHelper> pages = dh.getAllPages();
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& page: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFPageObjectHelper& page(*iter);
|
|
||||||
++pageno;
|
++pageno;
|
||||||
|
|
||||||
std::cout << "page " << pageno << ":" << std::endl;
|
std::cout << "page " << pageno << ":" << std::endl;
|
||||||
|
|
||||||
std::cout << " images:" << std::endl;
|
std::cout << " images:" << std::endl;
|
||||||
std::map<std::string, QPDFObjectHandle> images = page.getImages();
|
std::map<std::string, QPDFObjectHandle> images = page.getImages();
|
||||||
for (auto const& iter2: images) {
|
for (auto const& iter2: images) {
|
||||||
@ -714,19 +709,19 @@ test_15(QPDF& pdf, char const* arg2)
|
|||||||
// a shallow copy.
|
// a shallow copy.
|
||||||
QPDFObjectHandle page_template = pages.at(0);
|
QPDFObjectHandle page_template = pages.at(0);
|
||||||
std::vector<QPDFObjectHandle> new_pages;
|
std::vector<QPDFObjectHandle> new_pages;
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = contents.begin();
|
bool first = true;
|
||||||
iter != contents.end();
|
for (auto const& iter: contents) {
|
||||||
++iter) {
|
|
||||||
// We will retain indirect object references to other
|
// We will retain indirect object references to other
|
||||||
// indirect objects other than page content.
|
// indirect objects other than page content.
|
||||||
QPDFObjectHandle page = page_template.shallowCopy();
|
QPDFObjectHandle page = page_template.shallowCopy();
|
||||||
page.replaceKey("/Contents", *iter);
|
page.replaceKey("/Contents", iter);
|
||||||
if (iter == contents.begin()) {
|
if (first) {
|
||||||
// leave direct
|
// leave direct
|
||||||
new_pages.push_back(page);
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
new_pages.push_back(pdf.makeIndirectObject(page));
|
page = pdf.makeIndirectObject(page);
|
||||||
}
|
}
|
||||||
|
new_pages.push_back(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now insert the pages
|
// Now insert the pages
|
||||||
@ -1269,14 +1264,11 @@ test_35(QPDF& pdf, char const* arg2)
|
|||||||
attachments[filename] = stream.getStreamData();
|
attachments[filename] = stream.getStreamData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (std::map<std::string, std::shared_ptr<Buffer>>::iterator iter =
|
for (auto const& iter: attachments) {
|
||||||
attachments.begin();
|
std::string const& filename = iter.first;
|
||||||
iter != attachments.end();
|
|
||||||
++iter) {
|
|
||||||
std::string const& filename = (*iter).first;
|
|
||||||
std::string data = std::string(
|
std::string data = std::string(
|
||||||
reinterpret_cast<char const*>((*iter).second->getBuffer()),
|
reinterpret_cast<char const*>(iter.second->getBuffer()),
|
||||||
(*iter).second->getSize());
|
iter.second->getSize());
|
||||||
bool is_binary = false;
|
bool is_binary = false;
|
||||||
for (size_t i = 0; i < data.size(); ++i) {
|
for (size_t i = 0; i < data.size(); ++i) {
|
||||||
if ((data.at(i) < 0) || (data.at(i) > 126)) {
|
if ((data.at(i) < 0) || (data.at(i) > 126)) {
|
||||||
@ -1338,10 +1330,7 @@ test_37(QPDF& pdf, char const* arg2)
|
|||||||
// Parse content streams of all pages
|
// Parse content streams of all pages
|
||||||
std::vector<QPDFPageObjectHelper> pages =
|
std::vector<QPDFPageObjectHelper> pages =
|
||||||
QPDFPageDocumentHelper(pdf).getAllPages();
|
QPDFPageDocumentHelper(pdf).getAllPages();
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& page: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFPageObjectHelper& page(*iter);
|
|
||||||
ParserCallbacks cb;
|
ParserCallbacks cb;
|
||||||
page.parseContents(&cb);
|
page.parseContents(&cb);
|
||||||
}
|
}
|
||||||
@ -1364,16 +1353,11 @@ test_39(QPDF& pdf, char const* arg2)
|
|||||||
std::vector<QPDFPageObjectHelper> pages =
|
std::vector<QPDFPageObjectHelper> pages =
|
||||||
QPDFPageDocumentHelper(pdf).getAllPages();
|
QPDFPageDocumentHelper(pdf).getAllPages();
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator p_iter = pages.begin();
|
for (auto& page: pages) {
|
||||||
p_iter != pages.end();
|
|
||||||
++p_iter) {
|
|
||||||
std::cout << "page " << ++pageno << std::endl;
|
std::cout << "page " << ++pageno << std::endl;
|
||||||
std::map<std::string, QPDFObjectHandle> images = (*p_iter).getImages();
|
std::map<std::string, QPDFObjectHandle> images = page.getImages();
|
||||||
for (std::map<std::string, QPDFObjectHandle>::iterator i_iter =
|
for (auto& i_iter: images) {
|
||||||
images.begin();
|
QPDFObjectHandle image_dict = i_iter.second.getDict();
|
||||||
i_iter != images.end();
|
|
||||||
++i_iter) {
|
|
||||||
QPDFObjectHandle image_dict = (*i_iter).second.getDict();
|
|
||||||
std::cout << "filter: "
|
std::cout << "filter: "
|
||||||
<< image_dict.getKey("/Filter").unparseResolved()
|
<< image_dict.getKey("/Filter").unparseResolved()
|
||||||
<< ", color space: "
|
<< ", color space: "
|
||||||
@ -1404,10 +1388,8 @@ test_41(QPDF& pdf, char const* arg2)
|
|||||||
// with coalesce.pdf.
|
// with coalesce.pdf.
|
||||||
std::vector<QPDFPageObjectHelper> pages =
|
std::vector<QPDFPageObjectHelper> pages =
|
||||||
QPDFPageDocumentHelper(pdf).getAllPages();
|
QPDFPageDocumentHelper(pdf).getAllPages();
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& page: pages) {
|
||||||
iter != pages.end();
|
page.addContentTokenFilter(
|
||||||
++iter) {
|
|
||||||
(*iter).addContentTokenFilter(
|
|
||||||
std::shared_ptr<QPDFObjectHandle::TokenFilter>(new TokenFilter()));
|
std::shared_ptr<QPDFObjectHandle::TokenFilter>(new TokenFilter()));
|
||||||
}
|
}
|
||||||
QPDFWriter w(pdf, "a.pdf");
|
QPDFWriter w(pdf, "a.pdf");
|
||||||
@ -1537,11 +1519,7 @@ test_43(QPDF& pdf, char const* arg2)
|
|||||||
}
|
}
|
||||||
std::cout << "iterating over form fields\n";
|
std::cout << "iterating over form fields\n";
|
||||||
std::vector<QPDFFormFieldObjectHelper> form_fields = afdh.getFormFields();
|
std::vector<QPDFFormFieldObjectHelper> form_fields = afdh.getFormFields();
|
||||||
for (std::vector<QPDFFormFieldObjectHelper>::iterator iter =
|
for (auto& ffh: form_fields) {
|
||||||
form_fields.begin();
|
|
||||||
iter != form_fields.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFFormFieldObjectHelper ffh(*iter);
|
|
||||||
std::cout << "Field: " << ffh.getObjectHandle().unparse() << std::endl;
|
std::cout << "Field: " << ffh.getObjectHandle().unparse() << std::endl;
|
||||||
QPDFFormFieldObjectHelper node = ffh;
|
QPDFFormFieldObjectHelper node = ffh;
|
||||||
while (!node.isNull()) {
|
while (!node.isNull()) {
|
||||||
@ -1571,29 +1549,17 @@ test_43(QPDF& pdf, char const* arg2)
|
|||||||
std::cout << " Quadding: " << ffh.getQuadding() << std::endl;
|
std::cout << " Quadding: " << ffh.getQuadding() << std::endl;
|
||||||
std::vector<QPDFAnnotationObjectHelper> annotations =
|
std::vector<QPDFAnnotationObjectHelper> annotations =
|
||||||
afdh.getAnnotationsForField(ffh);
|
afdh.getAnnotationsForField(ffh);
|
||||||
for (std::vector<QPDFAnnotationObjectHelper>::iterator i2 =
|
for (auto& aoh: annotations) {
|
||||||
annotations.begin();
|
std::cout << " Annotation: " << aoh.getObjectHandle().unparse()
|
||||||
i2 != annotations.end();
|
|
||||||
++i2) {
|
|
||||||
std::cout << " Annotation: " << (*i2).getObjectHandle().unparse()
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "iterating over annotations per page\n";
|
std::cout << "iterating over annotations per page\n";
|
||||||
std::vector<QPDFPageObjectHelper> pages =
|
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
|
||||||
QPDFPageDocumentHelper(pdf).getAllPages();
|
std::cout << "Page: " << page.getObjectHandle().unparse() << std::endl;
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
std::cout << "Page: " << (*iter).getObjectHandle().unparse()
|
|
||||||
<< std::endl;
|
|
||||||
std::vector<QPDFAnnotationObjectHelper> annotations =
|
std::vector<QPDFAnnotationObjectHelper> annotations =
|
||||||
afdh.getWidgetAnnotationsForPage(*iter);
|
afdh.getWidgetAnnotationsForPage(page);
|
||||||
for (std::vector<QPDFAnnotationObjectHelper>::iterator i2 =
|
for (auto& ah: annotations) {
|
||||||
annotations.begin();
|
|
||||||
i2 != annotations.end();
|
|
||||||
++i2) {
|
|
||||||
QPDFAnnotationObjectHelper ah(*i2);
|
|
||||||
std::cout << " Annotation: " << ah.getObjectHandle().unparse()
|
std::cout << " Annotation: " << ah.getObjectHandle().unparse()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::cout
|
std::cout
|
||||||
@ -1623,10 +1589,7 @@ test_44(QPDF& pdf, char const* arg2)
|
|||||||
// Set form fields.
|
// Set form fields.
|
||||||
QPDFAcroFormDocumentHelper afdh(pdf);
|
QPDFAcroFormDocumentHelper afdh(pdf);
|
||||||
std::vector<QPDFFormFieldObjectHelper> fields = afdh.getFormFields();
|
std::vector<QPDFFormFieldObjectHelper> fields = afdh.getFormFields();
|
||||||
for (std::vector<QPDFFormFieldObjectHelper>::iterator iter = fields.begin();
|
for (auto& field: fields) {
|
||||||
iter != fields.end();
|
|
||||||
++iter) {
|
|
||||||
QPDFFormFieldObjectHelper& field(*iter);
|
|
||||||
QPDFObjectHandle ft = field.getInheritableFieldValue("/FT");
|
QPDFObjectHandle ft = field.getInheritableFieldValue("/FT");
|
||||||
if (ft.isName() && (ft.getName() == "/Tx")) {
|
if (ft.isName() && (ft.getName() == "/Tx")) {
|
||||||
// \xc3\xb7 is utf-8 for U+00F7 (divided by)
|
// \xc3\xb7 is utf-8 for U+00F7 (divided by)
|
||||||
@ -1950,23 +1913,16 @@ static void
|
|||||||
test_49(QPDF& pdf, char const* arg2)
|
test_49(QPDF& pdf, char const* arg2)
|
||||||
{
|
{
|
||||||
// Outlines
|
// Outlines
|
||||||
std::vector<QPDFPageObjectHelper> pages =
|
|
||||||
QPDFPageDocumentHelper(pdf).getAllPages();
|
|
||||||
QPDFOutlineDocumentHelper odh(pdf);
|
QPDFOutlineDocumentHelper odh(pdf);
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) {
|
||||||
iter != pages.end();
|
auto outlines =
|
||||||
++iter, ++pageno) {
|
odh.getOutlinesForPage(page.getObjectHandle().getObjGen());
|
||||||
std::vector<QPDFOutlineObjectHelper> outlines =
|
for (auto& ol: outlines) {
|
||||||
odh.getOutlinesForPage((*iter).getObjectHandle().getObjGen());
|
std::cout << "page " << pageno << ": " << ol.getTitle() << " -> "
|
||||||
for (std::vector<QPDFOutlineObjectHelper>::iterator oiter =
|
<< ol.getDest().unparseResolved() << std::endl;
|
||||||
outlines.begin();
|
|
||||||
oiter != outlines.end();
|
|
||||||
++oiter) {
|
|
||||||
std::cout << "page " << pageno << ": " << (*oiter).getTitle()
|
|
||||||
<< " -> " << (*oiter).getDest().unparseResolved()
|
|
||||||
<< std::endl;
|
|
||||||
}
|
}
|
||||||
|
++pageno;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1981,11 +1937,8 @@ test_50(QPDF& pdf, char const* arg2)
|
|||||||
std::cout << d1.getJSON().unparse() << std::endl;
|
std::cout << d1.getJSON().unparse() << std::endl;
|
||||||
// Top-level type mismatch
|
// Top-level type mismatch
|
||||||
d1.mergeResources(d2.getKey("/k1"));
|
d1.mergeResources(d2.getKey("/k1"));
|
||||||
std::set<std::string> names = d1.getResourceNames();
|
for (auto const& name: d1.getResourceNames()) {
|
||||||
for (std::set<std::string>::iterator iter = names.begin();
|
std::cout << name << std::endl;
|
||||||
iter != names.end();
|
|
||||||
++iter) {
|
|
||||||
std::cout << *iter << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2064,11 +2017,8 @@ test_53(QPDF& pdf, char const* arg2)
|
|||||||
root.replaceKey(
|
root.replaceKey(
|
||||||
"/Q1", pdf.makeIndirectObject(QPDFObjectHandle::newString("potato")));
|
"/Q1", pdf.makeIndirectObject(QPDFObjectHandle::newString("potato")));
|
||||||
std::cout << "all objects" << std::endl;
|
std::cout << "all objects" << std::endl;
|
||||||
std::vector<QPDFObjectHandle> all = pdf.getAllObjects();
|
for (auto& obj: pdf.getAllObjects()) {
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = all.begin();
|
std::cout << obj.unparse() << std::endl;
|
||||||
iter != all.end();
|
|
||||||
++iter) {
|
|
||||||
std::cout << (*iter).unparse() << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPDFWriter w(pdf, "a.pdf");
|
QPDFWriter w(pdf, "a.pdf");
|
||||||
|
@ -52,21 +52,17 @@ walk(
|
|||||||
|
|
||||||
if (obj.isArray()) {
|
if (obj.isArray()) {
|
||||||
std::vector<QPDFObjectHandle> array = obj.getArrayAsVector();
|
std::vector<QPDFObjectHandle> array = obj.getArrayAsVector();
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = array.begin();
|
for (auto& oh: array) {
|
||||||
iter != array.end();
|
if (!oh.isIndirect()) {
|
||||||
++iter) {
|
|
||||||
if (!iter->isIndirect()) {
|
|
||||||
// QPDF::GetAllObjects() enumerates all indirect objects.
|
// QPDF::GetAllObjects() enumerates all indirect objects.
|
||||||
// So only the direct objects are recursed here.
|
// So only the direct objects are recursed here.
|
||||||
walk(stream_number, *iter, result);
|
walk(stream_number, oh, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (obj.isDictionary()) {
|
} else if (obj.isDictionary()) {
|
||||||
std::set<std::string> keys = obj.getKeys();
|
std::set<std::string> keys = obj.getKeys();
|
||||||
for (std::set<std::string>::iterator iter = keys.begin();
|
for (auto const& key: keys) {
|
||||||
iter != keys.end();
|
QPDFObjectHandle item = obj.getKey(key);
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle item = obj.getKey(*iter);
|
|
||||||
if (!item.isIndirect()) {
|
if (!item.isIndirect()) {
|
||||||
// QPDF::GetAllObjects() enumerates all indirect objects.
|
// QPDF::GetAllObjects() enumerates all indirect objects.
|
||||||
// So only the direct objects are recursed here.
|
// So only the direct objects are recursed here.
|
||||||
@ -88,21 +84,19 @@ process(
|
|||||||
std::vector<QPDFObjectHandle> objs = qpdf.getAllObjects();
|
std::vector<QPDFObjectHandle> objs = qpdf.getAllObjects();
|
||||||
std::map<QPDFObjGen, QPDFXRefEntry> xrefs = qpdf.getXRefTable();
|
std::map<QPDFObjGen, QPDFXRefEntry> xrefs = qpdf.getXRefTable();
|
||||||
|
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = objs.begin();
|
for (auto const& oh: objs) {
|
||||||
iter != objs.end();
|
if (xrefs.count(oh.getObjGen()) == 0) {
|
||||||
++iter) {
|
std::cerr << oh.getObjectID() << "/" << oh.getGeneration()
|
||||||
if (xrefs.count(iter->getObjGen()) == 0) {
|
|
||||||
std::cerr << iter->getObjectID() << "/" << iter->getGeneration()
|
|
||||||
<< " is not found in xref table" << std::endl;
|
<< " is not found in xref table" << std::endl;
|
||||||
std::exit(2);
|
std::exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPDFXRefEntry xref = xrefs[iter->getObjGen()];
|
QPDFXRefEntry xref = xrefs[oh.getObjGen()];
|
||||||
size_t stream_number;
|
size_t stream_number;
|
||||||
|
|
||||||
switch (xref.getType()) {
|
switch (xref.getType()) {
|
||||||
case 0:
|
case 0:
|
||||||
std::cerr << iter->getObjectID() << "/" << iter->getGeneration()
|
std::cerr << oh.getObjectID() << "/" << oh.getGeneration()
|
||||||
<< " xref entry is free" << std::endl;
|
<< " xref entry is free" << std::endl;
|
||||||
std::exit(2);
|
std::exit(2);
|
||||||
case 1:
|
case 1:
|
||||||
@ -116,7 +110,7 @@ process(
|
|||||||
std::exit(2);
|
std::exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
walk(stream_number, *iter, result);
|
walk(stream_number, oh, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,11 +140,8 @@ main(int argc, char* argv[])
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::vector<std::pair<qpdf_offset_t, std::string>>::iterator
|
for (auto const& iter: table[i]) {
|
||||||
iter = table[i].begin();
|
std::cout << iter.second << std::endl;
|
||||||
iter != table[i].end();
|
|
||||||
++iter) {
|
|
||||||
std::cout << iter->second << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,10 +27,8 @@ main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
char const* infilename = argv[1];
|
char const* infilename = argv[1];
|
||||||
std::list<std::string> lines = QUtil::read_lines_from_file(infilename);
|
std::list<std::string> lines = QUtil::read_lines_from_file(infilename);
|
||||||
for (std::list<std::string>::iterator iter = lines.begin();
|
for (auto const& line: lines) {
|
||||||
iter != lines.end();
|
QPDFObjectHandle str = QPDFObjectHandle::newString(line);
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle str = QPDFObjectHandle::newString(*iter);
|
|
||||||
std::cout << str.getUTF8Value() << std::endl;
|
std::cout << str.getUTF8Value() << std::endl;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -27,10 +27,8 @@ main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
char const* infilename = argv[1];
|
char const* infilename = argv[1];
|
||||||
std::list<std::string> lines = QUtil::read_lines_from_file(infilename);
|
std::list<std::string> lines = QUtil::read_lines_from_file(infilename);
|
||||||
for (std::list<std::string>::iterator iter = lines.begin();
|
for (auto const& line: lines) {
|
||||||
iter != lines.end();
|
QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(line);
|
||||||
++iter) {
|
|
||||||
QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(*iter);
|
|
||||||
std::cout << str.getUTF8Value() << " // " << str.unparseBinary()
|
std::cout << str.getUTF8Value() << " // " << str.unparseBinary()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
@ -97,10 +97,8 @@ compare(QPDFObjectHandle a, QPDFObjectHandle b)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::set<std::string>::iterator iter = keys_a.begin();
|
for (auto const& key: keys_a) {
|
||||||
iter != keys_a.end();
|
if (!compare(a.getKey(key), b.getKey(key))) {
|
||||||
++iter) {
|
|
||||||
if (!compare(a.getKey(*iter), b.getKey(*iter))) {
|
|
||||||
std::cerr << "different dictionary item" << std::endl;
|
std::cerr << "different dictionary item" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -130,19 +128,17 @@ compare_xref_table(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter = a.begin();
|
for (auto const& iter: a) {
|
||||||
iter != a.end();
|
std::cout << "xref entry for " << iter.first.getObj() << "/"
|
||||||
++iter) {
|
<< iter.first.getGen() << std::endl;
|
||||||
std::cout << "xref entry for " << iter->first.getObj() << "/"
|
|
||||||
<< iter->first.getGen() << std::endl;
|
|
||||||
|
|
||||||
if (b.count(iter->first) == 0) {
|
if (b.count(iter.first) == 0) {
|
||||||
std::cerr << "not found" << std::endl;
|
std::cerr << "not found" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPDFXRefEntry xref_a = iter->second;
|
QPDFXRefEntry xref_a = iter.second;
|
||||||
QPDFXRefEntry xref_b = b[iter->first];
|
QPDFXRefEntry xref_b = b[iter.first];
|
||||||
if (xref_a.getType() != xref_b.getType()) {
|
if (xref_a.getType() != xref_b.getType()) {
|
||||||
std::cerr << "different xref entry type" << std::endl;
|
std::cerr << "different xref entry type" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
@ -235,10 +231,8 @@ main(int argc, char* argv[])
|
|||||||
|
|
||||||
std::cout << "--- compare between input and renumbered objects ---"
|
std::cout << "--- compare between input and renumbered objects ---"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = objs_in.begin();
|
for (auto const& iter: objs_in) {
|
||||||
iter != objs_in.end();
|
QPDFObjGen og_in = iter.getObjGen();
|
||||||
++iter) {
|
|
||||||
QPDFObjGen og_in = iter->getObjGen();
|
|
||||||
QPDFObjGen og_ren = w.getRenumberedObjGen(og_in);
|
QPDFObjGen og_ren = w.getRenumberedObjGen(og_in);
|
||||||
|
|
||||||
std::cout << "input " << og_in.getObj() << "/" << og_in.getGen()
|
std::cout << "input " << og_in.getObj() << "/" << og_in.getGen()
|
||||||
@ -250,7 +244,7 @@ main(int argc, char* argv[])
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!compare(*iter, qpdf_ren.getObjectByObjGen(og_ren))) {
|
if (!compare(iter, qpdf_ren.getObjectByObjGen(og_ren))) {
|
||||||
std::cerr << "different" << std::endl;
|
std::cerr << "different" << std::endl;
|
||||||
std::exit(2);
|
std::exit(2);
|
||||||
}
|
}
|
||||||
|
@ -99,14 +99,13 @@ static std::string
|
|||||||
sanitize(std::string const& value)
|
sanitize(std::string const& value)
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
for (std::string::const_iterator iter = value.begin(); iter != value.end();
|
for (auto const& iter: value) {
|
||||||
++iter) {
|
if ((iter >= 32) && (iter <= 126)) {
|
||||||
if ((*iter >= 32) && (*iter <= 126)) {
|
result.append(1, iter);
|
||||||
result.append(1, *iter);
|
|
||||||
} else {
|
} else {
|
||||||
result += "\\x" +
|
result += "\\x" +
|
||||||
QUtil::int_to_string_base(
|
QUtil::int_to_string_base(
|
||||||
static_cast<unsigned char>(*iter), 16, 2);
|
static_cast<unsigned char>(iter), 16, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -203,12 +202,10 @@ process(char const* filename, bool include_ignorable, size_t max_len)
|
|||||||
std::vector<QPDFPageObjectHelper> pages =
|
std::vector<QPDFPageObjectHelper> pages =
|
||||||
QPDFPageDocumentHelper(qpdf).getAllPages();
|
QPDFPageDocumentHelper(qpdf).getAllPages();
|
||||||
int pageno = 0;
|
int pageno = 0;
|
||||||
for (std::vector<QPDFPageObjectHelper>::iterator iter = pages.begin();
|
for (auto& page: pages) {
|
||||||
iter != pages.end();
|
|
||||||
++iter) {
|
|
||||||
++pageno;
|
++pageno;
|
||||||
Pl_Buffer plb("buffer");
|
Pl_Buffer plb("buffer");
|
||||||
(*iter).pipeContents(&plb);
|
page.pipeContents(&plb);
|
||||||
auto content_data = plb.getBufferSharedPointer();
|
auto content_data = plb.getBufferSharedPointer();
|
||||||
BufferInputSource* bis =
|
BufferInputSource* bis =
|
||||||
new BufferInputSource("content data", content_data.get());
|
new BufferInputSource("content data", content_data.get());
|
||||||
@ -223,20 +220,16 @@ process(char const* filename, bool include_ignorable, size_t max_len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tokenize object streams
|
// Tokenize object streams
|
||||||
std::vector<QPDFObjectHandle> all = qpdf.getAllObjects();
|
for (auto& obj: qpdf.getAllObjects()) {
|
||||||
for (std::vector<QPDFObjectHandle>::iterator iter = all.begin();
|
if (obj.isStream() && obj.getDict().getKey("/Type").isName() &&
|
||||||
iter != all.end();
|
obj.getDict().getKey("/Type").getName() == "/ObjStm") {
|
||||||
++iter) {
|
std::shared_ptr<Buffer> b = obj.getStreamData(qpdf_dl_specialized);
|
||||||
if ((*iter).isStream() && (*iter).getDict().getKey("/Type").isName() &&
|
|
||||||
(*iter).getDict().getKey("/Type").getName() == "/ObjStm") {
|
|
||||||
std::shared_ptr<Buffer> b =
|
|
||||||
(*iter).getStreamData(qpdf_dl_specialized);
|
|
||||||
BufferInputSource* bis =
|
BufferInputSource* bis =
|
||||||
new BufferInputSource("object stream data", b.get());
|
new BufferInputSource("object stream data", b.get());
|
||||||
is = std::shared_ptr<InputSource>(bis);
|
is = std::shared_ptr<InputSource>(bis);
|
||||||
dump_tokens(
|
dump_tokens(
|
||||||
is,
|
is,
|
||||||
"OBJECT STREAM " + QUtil::int_to_string((*iter).getObjectID()),
|
"OBJECT STREAM " + QUtil::int_to_string(obj.getObjectID()),
|
||||||
max_len,
|
max_len,
|
||||||
include_ignorable,
|
include_ignorable,
|
||||||
false,
|
false,
|
||||||
|
@ -21,26 +21,24 @@ main(int argc, char* argv[])
|
|||||||
|
|
||||||
std::map<QPDFObjGen, QPDFXRefEntry> xref = qpdf.getXRefTable();
|
std::map<QPDFObjGen, QPDFXRefEntry> xref = qpdf.getXRefTable();
|
||||||
|
|
||||||
for (std::map<QPDFObjGen, QPDFXRefEntry>::iterator iter = xref.begin();
|
for (auto const& iter: xref) {
|
||||||
iter != xref.end();
|
std::cout << iter.first.getObj() << "/" << iter.first.getGen()
|
||||||
++iter) {
|
|
||||||
std::cout << iter->first.getObj() << "/" << iter->first.getGen()
|
|
||||||
<< ", ";
|
<< ", ";
|
||||||
switch (iter->second.getType()) {
|
switch (iter.second.getType()) {
|
||||||
case 0:
|
case 0:
|
||||||
std::cout << "free entry" << std::endl;
|
std::cout << "free entry" << std::endl;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
std::cout << "uncompressed, offset = "
|
std::cout << "uncompressed, offset = "
|
||||||
<< iter->second.getOffset() << " (0x" << std::hex
|
<< iter.second.getOffset() << " (0x" << std::hex
|
||||||
<< iter->second.getOffset() << std::dec << ")"
|
<< iter.second.getOffset() << std::dec << ")"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
std::cout << "compressed, stream number = "
|
std::cout << "compressed, stream number = "
|
||||||
<< iter->second.getObjStreamNumber()
|
<< iter.second.getObjStreamNumber()
|
||||||
<< ", stream index = "
|
<< ", stream index = "
|
||||||
<< iter->second.getObjStreamIndex() << std::endl;
|
<< iter.second.getObjStreamIndex() << std::endl;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
std::cerr << "unknown" << std::endl;
|
std::cerr << "unknown" << std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user