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