Commit 6c69a747b9f7a801be2ad58985f35886bd38239e
Committed by
Jay Berkenbilt
1 parent
70ccd807
Code clean up: use range-style for loops wherever possible
Remove variables obsoleted by commit 4f24617.
Showing
20 changed files
with
72 additions
and
166 deletions
examples/pdf-filter-tokens.cc
| @@ -191,9 +191,7 @@ main(int argc, char* argv[]) | @@ -191,9 +191,7 @@ main(int argc, char* argv[]) | ||
| 191 | try { | 191 | try { |
| 192 | QPDF pdf; | 192 | QPDF pdf; |
| 193 | pdf.processFile(infilename); | 193 | pdf.processFile(infilename); |
| 194 | - std::vector<QPDFPageObjectHelper> pages = | ||
| 195 | - QPDFPageDocumentHelper(pdf).getAllPages(); | ||
| 196 | - for (auto& page: pages) { | 194 | + for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 197 | // Attach two token filters to each page of this file. | 195 | // Attach two token filters to each page of this file. |
| 198 | // When the file is written, or when the pages' contents | 196 | // When the file is written, or when the pages' contents |
| 199 | // are retrieved in any other way, the filters will be | 197 | // are retrieved in any other way, the filters will be |
examples/pdf-invert-images.cc
| @@ -129,12 +129,9 @@ main(int argc, char* argv[]) | @@ -129,12 +129,9 @@ main(int argc, char* argv[]) | ||
| 129 | auto p = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(inv); | 129 | auto p = std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(inv); |
| 130 | 130 | ||
| 131 | // For each page... | 131 | // For each page... |
| 132 | - std::vector<QPDFPageObjectHelper> pages = | ||
| 133 | - QPDFPageDocumentHelper(qpdf).getAllPages(); | ||
| 134 | - for (auto& page: pages) { | 132 | + for (auto& page: QPDFPageDocumentHelper(qpdf).getAllPages()) { |
| 135 | // Get all images on the page. | 133 | // Get all images on the page. |
| 136 | - std::map<std::string, QPDFObjectHandle> images = page.getImages(); | ||
| 137 | - for (auto& iter: images) { | 134 | + for (auto& iter: page.getImages()) { |
| 138 | QPDFObjectHandle& image = iter.second; | 135 | QPDFObjectHandle& image = iter.second; |
| 139 | QPDFObjectHandle image_dict = image.getDict(); | 136 | QPDFObjectHandle image_dict = image.getDict(); |
| 140 | QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace"); | 137 | QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace"); |
examples/pdf-overlay-page.cc
| @@ -40,9 +40,7 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile) | @@ -40,9 +40,7 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile) | ||
| 40 | QPDFObjectHandle stamp_fo = inpdf.copyForeignObject(foreign_fo); | 40 | QPDFObjectHandle stamp_fo = inpdf.copyForeignObject(foreign_fo); |
| 41 | 41 | ||
| 42 | // For each page... | 42 | // For each page... |
| 43 | - std::vector<QPDFPageObjectHelper> pages = | ||
| 44 | - QPDFPageDocumentHelper(inpdf).getAllPages(); | ||
| 45 | - for (auto& ph: pages) { | 43 | + for (auto& ph: QPDFPageDocumentHelper(inpdf).getAllPages()) { |
| 46 | // Find a unique resource name for the new form XObject | 44 | // Find a unique resource name for the new form XObject |
| 47 | QPDFObjectHandle resources = ph.getAttribute("/Resources", true); | 45 | QPDFObjectHandle resources = ph.getAttribute("/Resources", true); |
| 48 | int min_suffix = 1; | 46 | int min_suffix = 1; |
examples/pdf-set-form-values.cc
| @@ -50,15 +50,11 @@ main(int argc, char* argv[]) | @@ -50,15 +50,11 @@ main(int argc, char* argv[]) | ||
| 50 | // illustrates how we can map from annotations to fields. | 50 | // illustrates how we can map from annotations to fields. |
| 51 | 51 | ||
| 52 | QPDFAcroFormDocumentHelper afdh(qpdf); | 52 | QPDFAcroFormDocumentHelper afdh(qpdf); |
| 53 | - QPDFPageDocumentHelper pdh(qpdf); | ||
| 54 | - std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); | ||
| 55 | - for (auto const& page: pages) { | 53 | + for (auto const& page: QPDFPageDocumentHelper(qpdf).getAllPages()) { |
| 56 | // Get all widget annotations for each page. Widget | 54 | // Get all widget annotations for each page. Widget |
| 57 | // annotations are the ones that contain the details of | 55 | // annotations are the ones that contain the details of |
| 58 | // what's in a form field. | 56 | // what's in a form field. |
| 59 | - std::vector<QPDFAnnotationObjectHelper> annotations = | ||
| 60 | - afdh.getWidgetAnnotationsForPage(page); | ||
| 61 | - for (auto& annot: annotations) { | 57 | + for (auto& annot: afdh.getWidgetAnnotationsForPage(page)) { |
| 62 | // For each annotation, find its associated field. If | 58 | // For each annotation, find its associated field. If |
| 63 | // it's a text field, set its value. | 59 | // it's a text field, set its value. |
| 64 | QPDFFormFieldObjectHelper ffh = | 60 | QPDFFormFieldObjectHelper ffh = |
fuzz/qpdf_fuzzer.cc
| @@ -131,10 +131,9 @@ FuzzHelper::testPages() | @@ -131,10 +131,9 @@ FuzzHelper::testPages() | ||
| 131 | QPDFAcroFormDocumentHelper afdh(*q); | 131 | QPDFAcroFormDocumentHelper afdh(*q); |
| 132 | afdh.generateAppearancesIfNeeded(); | 132 | afdh.generateAppearancesIfNeeded(); |
| 133 | pdh.flattenAnnotations(); | 133 | pdh.flattenAnnotations(); |
| 134 | - std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); | ||
| 135 | DiscardContents discard_contents; | 134 | DiscardContents discard_contents; |
| 136 | int pageno = 0; | 135 | int pageno = 0; |
| 137 | - for (auto& page: pages) { | 136 | + for (auto& page: pdh.getAllPages()) { |
| 138 | ++pageno; | 137 | ++pageno; |
| 139 | try { | 138 | try { |
| 140 | page.coalesceContentStreams(); | 139 | page.coalesceContentStreams(); |
| @@ -145,9 +144,7 @@ FuzzHelper::testPages() | @@ -145,9 +144,7 @@ FuzzHelper::testPages() | ||
| 145 | page_obj.getJSON(JSON::LATEST, true).unparse(); | 144 | page_obj.getJSON(JSON::LATEST, true).unparse(); |
| 146 | odh.getOutlinesForPage(page_obj.getObjGen()); | 145 | odh.getOutlinesForPage(page_obj.getObjGen()); |
| 147 | 146 | ||
| 148 | - std::vector<QPDFAnnotationObjectHelper> annotations = | ||
| 149 | - afdh.getWidgetAnnotationsForPage(page); | ||
| 150 | - for (auto& aoh: annotations) { | 147 | + for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) { |
| 151 | afdh.getFieldForAnnotation(aoh); | 148 | afdh.getFieldForAnnotation(aoh); |
| 152 | } | 149 | } |
| 153 | } catch (QPDFExc& e) { | 150 | } catch (QPDFExc& e) { |
| @@ -164,8 +161,7 @@ FuzzHelper::testOutlines() | @@ -164,8 +161,7 @@ FuzzHelper::testOutlines() | ||
| 164 | QPDFOutlineDocumentHelper odh(*q); | 161 | QPDFOutlineDocumentHelper odh(*q); |
| 165 | queue.push_back(odh.getTopLevelOutlines()); | 162 | queue.push_back(odh.getTopLevelOutlines()); |
| 166 | while (!queue.empty()) { | 163 | while (!queue.empty()) { |
| 167 | - std::vector<QPDFOutlineObjectHelper>& outlines = *(queue.begin()); | ||
| 168 | - for (auto& ol: outlines) { | 164 | + for (auto& ol: *(queue.begin())) { |
| 169 | ol.getDestPage(); | 165 | ol.getDestPage(); |
| 170 | queue.push_back(ol.getKids()); | 166 | queue.push_back(ol.getKids()); |
| 171 | } | 167 | } |
libqpdf/QPDF.cc
| @@ -2369,8 +2369,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | @@ -2369,8 +2369,7 @@ QPDF::reserveObjects(QPDFObjectHandle foreign, ObjCopier& obj_copier, bool top) | ||
| 2369 | } | 2369 | } |
| 2370 | } else if (foreign.isDictionary()) { | 2370 | } else if (foreign.isDictionary()) { |
| 2371 | QTC::TC("qpdf", "QPDF reserve dictionary"); | 2371 | QTC::TC("qpdf", "QPDF reserve dictionary"); |
| 2372 | - std::set<std::string> keys = foreign.getKeys(); | ||
| 2373 | - for (auto const& key: keys) { | 2372 | + for (auto const& key: foreign.getKeys()) { |
| 2374 | reserveObjects(foreign.getKey(key), obj_copier, false); | 2373 | reserveObjects(foreign.getKey(key), obj_copier, false); |
| 2375 | } | 2374 | } |
| 2376 | } else if (foreign.isStream()) { | 2375 | } else if (foreign.isStream()) { |
libqpdf/QPDFAcroFormDocumentHelper.cc
| @@ -294,12 +294,8 @@ QPDFAcroFormDocumentHelper::analyze() | @@ -294,12 +294,8 @@ QPDFAcroFormDocumentHelper::analyze() | ||
| 294 | // a file that contains this kind of error will probably not | 294 | // a file that contains this kind of error will probably not |
| 295 | // actually work with most viewers. | 295 | // actually work with most viewers. |
| 296 | 296 | ||
| 297 | - QPDFPageDocumentHelper dh(this->qpdf); | ||
| 298 | - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | ||
| 299 | - for (auto const& ph: pages) { | ||
| 300 | - std::vector<QPDFAnnotationObjectHelper> annots = | ||
| 301 | - getWidgetAnnotationsForPage(ph); | ||
| 302 | - for (auto const& iter: annots) { | 297 | + for (auto const& ph: QPDFPageDocumentHelper(this->qpdf).getAllPages()) { |
| 298 | + for (auto const& iter: getWidgetAnnotationsForPage(ph)) { | ||
| 303 | QPDFObjectHandle annot(iter.getObjectHandle()); | 299 | QPDFObjectHandle annot(iter.getObjectHandle()); |
| 304 | QPDFObjGen og(annot.getObjGen()); | 300 | QPDFObjGen og(annot.getObjGen()); |
| 305 | if (this->m->annotation_to_field.count(og) == 0) { | 301 | if (this->m->annotation_to_field.count(og) == 0) { |
| @@ -451,12 +447,8 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded() | @@ -451,12 +447,8 @@ QPDFAcroFormDocumentHelper::generateAppearancesIfNeeded() | ||
| 451 | return; | 447 | return; |
| 452 | } | 448 | } |
| 453 | 449 | ||
| 454 | - QPDFPageDocumentHelper pdh(this->qpdf); | ||
| 455 | - std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); | ||
| 456 | - for (auto const& page: pages) { | ||
| 457 | - std::vector<QPDFAnnotationObjectHelper> annotations = | ||
| 458 | - getWidgetAnnotationsForPage(page); | ||
| 459 | - for (auto& aoh: annotations) { | 450 | + for (auto const& page: QPDFPageDocumentHelper(this->qpdf).getAllPages()) { |
| 451 | + for (auto& aoh: getWidgetAnnotationsForPage(page)) { | ||
| 460 | QPDFFormFieldObjectHelper ffh = getFieldForAnnotation(aoh); | 452 | QPDFFormFieldObjectHelper ffh = getFieldForAnnotation(aoh); |
| 461 | if (ffh.getFieldType() == "/Btn") { | 453 | if (ffh.getFieldType() == "/Btn") { |
| 462 | // Rather than generating appearances for button | 454 | // Rather than generating appearances for button |
libqpdf/QPDFJob.cc
| @@ -867,11 +867,9 @@ QPDFJob::doCheck(QPDF& pdf) | @@ -867,11 +867,9 @@ QPDFJob::doCheck(QPDF& pdf) | ||
| 867 | w.write(); | 867 | w.write(); |
| 868 | 868 | ||
| 869 | // Parse all content streams | 869 | // Parse all content streams |
| 870 | - QPDFPageDocumentHelper dh(pdf); | ||
| 871 | - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | ||
| 872 | DiscardContents discard_contents; | 870 | DiscardContents discard_contents; |
| 873 | int pageno = 0; | 871 | int pageno = 0; |
| 874 | - for (auto& page: pages) { | 872 | + for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 875 | ++pageno; | 873 | ++pageno; |
| 876 | try { | 874 | try { |
| 877 | page.parseContents(&discard_contents); | 875 | page.parseContents(&discard_contents); |
| @@ -939,11 +937,9 @@ QPDFJob::doShowObj(QPDF& pdf) | @@ -939,11 +937,9 @@ QPDFJob::doShowObj(QPDF& pdf) | ||
| 939 | void | 937 | void |
| 940 | QPDFJob::doShowPages(QPDF& pdf) | 938 | QPDFJob::doShowPages(QPDF& pdf) |
| 941 | { | 939 | { |
| 942 | - QPDFPageDocumentHelper dh(pdf); | ||
| 943 | - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | ||
| 944 | int pageno = 0; | 940 | int pageno = 0; |
| 945 | auto& cout = *this->m->cout; | 941 | auto& cout = *this->m->cout; |
| 946 | - for (auto& ph: pages) { | 942 | + for (auto& ph: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 947 | QPDFObjectHandle page = ph.getObjectHandle(); | 943 | QPDFObjectHandle page = ph.getObjectHandle(); |
| 948 | ++pageno; | 944 | ++pageno; |
| 949 | 945 | ||
| @@ -966,8 +962,7 @@ QPDFJob::doShowPages(QPDF& pdf) | @@ -966,8 +962,7 @@ QPDFJob::doShowPages(QPDF& pdf) | ||
| 966 | } | 962 | } |
| 967 | 963 | ||
| 968 | cout << " content:" << std::endl; | 964 | cout << " content:" << std::endl; |
| 969 | - std::vector<QPDFObjectHandle> content = ph.getPageContents(); | ||
| 970 | - for (auto& iter2: content) { | 965 | + for (auto& iter2: ph.getPageContents()) { |
| 971 | cout << " " << iter2.unparse() << std::endl; | 966 | cout << " " << iter2.unparse() << std::endl; |
| 972 | } | 967 | } |
| 973 | } | 968 | } |
| @@ -1085,8 +1080,7 @@ QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf) | @@ -1085,8 +1080,7 @@ QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1085 | JSON::writeDictionaryOpen(p, first_object, 1); | 1080 | JSON::writeDictionaryOpen(p, first_object, 1); |
| 1086 | bool all_objects = m->json_objects.empty(); | 1081 | bool all_objects = m->json_objects.empty(); |
| 1087 | std::set<QPDFObjGen> wanted_og = getWantedJSONObjects(); | 1082 | std::set<QPDFObjGen> wanted_og = getWantedJSONObjects(); |
| 1088 | - std::vector<QPDFObjectHandle> objects = pdf.getAllObjects(); | ||
| 1089 | - for (auto& obj: objects) { | 1083 | + for (auto& obj: pdf.getAllObjects()) { |
| 1090 | std::string key = obj.unparse(); | 1084 | std::string key = obj.unparse(); |
| 1091 | if (this->m->json_version > 1) { | 1085 | if (this->m->json_version > 1) { |
| 1092 | key = "obj:" + key; | 1086 | key = "obj:" + key; |
| @@ -1140,20 +1134,17 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | @@ -1140,20 +1134,17 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1140 | JSON::writeDictionaryKey(p, first, "pages", 0); | 1134 | JSON::writeDictionaryKey(p, first, "pages", 0); |
| 1141 | bool first_page = true; | 1135 | bool first_page = true; |
| 1142 | JSON::writeArrayOpen(p, first_page, 1); | 1136 | JSON::writeArrayOpen(p, first_page, 1); |
| 1143 | - QPDFPageDocumentHelper pdh(pdf); | ||
| 1144 | QPDFPageLabelDocumentHelper pldh(pdf); | 1137 | QPDFPageLabelDocumentHelper pldh(pdf); |
| 1145 | QPDFOutlineDocumentHelper odh(pdf); | 1138 | QPDFOutlineDocumentHelper odh(pdf); |
| 1146 | - std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); | ||
| 1147 | int pageno = -1; | 1139 | int pageno = -1; |
| 1148 | - for (auto& ph: pages) { | 1140 | + for (auto& ph: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 1149 | ++pageno; | 1141 | ++pageno; |
| 1150 | JSON j_page = JSON::makeDictionary(); | 1142 | JSON j_page = JSON::makeDictionary(); |
| 1151 | QPDFObjectHandle page = ph.getObjectHandle(); | 1143 | QPDFObjectHandle page = ph.getObjectHandle(); |
| 1152 | j_page.addDictionaryMember( | 1144 | j_page.addDictionaryMember( |
| 1153 | "object", page.getJSON(this->m->json_version)); | 1145 | "object", page.getJSON(this->m->json_version)); |
| 1154 | JSON j_images = j_page.addDictionaryMember("images", JSON::makeArray()); | 1146 | JSON j_images = j_page.addDictionaryMember("images", JSON::makeArray()); |
| 1155 | - std::map<std::string, QPDFObjectHandle> images = ph.getImages(); | ||
| 1156 | - for (auto const& iter2: images) { | 1147 | + for (auto const& iter2: ph.getImages()) { |
| 1157 | JSON j_image = j_images.addArrayElement(JSON::makeDictionary()); | 1148 | JSON j_image = j_images.addArrayElement(JSON::makeDictionary()); |
| 1158 | j_image.addDictionaryMember("name", JSON::makeString(iter2.first)); | 1149 | j_image.addDictionaryMember("name", JSON::makeString(iter2.first)); |
| 1159 | QPDFObjectHandle image = iter2.second; | 1150 | QPDFObjectHandle image = iter2.second; |
| @@ -1195,8 +1186,7 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | @@ -1195,8 +1186,7 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1195 | j_page.addDictionaryMember("images", j_images); | 1186 | j_page.addDictionaryMember("images", j_images); |
| 1196 | JSON j_contents = | 1187 | JSON j_contents = |
| 1197 | j_page.addDictionaryMember("contents", JSON::makeArray()); | 1188 | j_page.addDictionaryMember("contents", JSON::makeArray()); |
| 1198 | - std::vector<QPDFObjectHandle> content = ph.getPageContents(); | ||
| 1199 | - for (auto& iter2: content) { | 1189 | + for (auto& iter2: ph.getPageContents()) { |
| 1200 | j_contents.addArrayElement(iter2.getJSON(this->m->json_version)); | 1190 | j_contents.addArrayElement(iter2.getJSON(this->m->json_version)); |
| 1201 | } | 1191 | } |
| 1202 | j_page.addDictionaryMember( | 1192 | j_page.addDictionaryMember( |
| @@ -1285,10 +1275,8 @@ void | @@ -1285,10 +1275,8 @@ void | ||
| 1285 | QPDFJob::doJSONOutlines(Pipeline* p, bool& first, QPDF& pdf) | 1275 | QPDFJob::doJSONOutlines(Pipeline* p, bool& first, QPDF& pdf) |
| 1286 | { | 1276 | { |
| 1287 | std::map<QPDFObjGen, int> page_numbers; | 1277 | std::map<QPDFObjGen, int> page_numbers; |
| 1288 | - QPDFPageDocumentHelper dh(pdf); | ||
| 1289 | - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | ||
| 1290 | int n = 0; | 1278 | int n = 0; |
| 1291 | - for (auto const& ph: pages) { | 1279 | + for (auto const& ph: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 1292 | QPDFObjectHandle oh = ph.getObjectHandle(); | 1280 | QPDFObjectHandle oh = ph.getObjectHandle(); |
| 1293 | page_numbers[oh.getObjGen()] = ++n; | 1281 | page_numbers[oh.getObjGen()] = ++n; |
| 1294 | } | 1282 | } |
| @@ -1309,14 +1297,10 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) | @@ -1309,14 +1297,10 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1309 | j_acroform.addDictionaryMember( | 1297 | j_acroform.addDictionaryMember( |
| 1310 | "needappearances", JSON::makeBool(afdh.getNeedAppearances())); | 1298 | "needappearances", JSON::makeBool(afdh.getNeedAppearances())); |
| 1311 | JSON j_fields = j_acroform.addDictionaryMember("fields", JSON::makeArray()); | 1299 | JSON j_fields = j_acroform.addDictionaryMember("fields", JSON::makeArray()); |
| 1312 | - QPDFPageDocumentHelper pdh(pdf); | ||
| 1313 | - std::vector<QPDFPageObjectHelper> pages = pdh.getAllPages(); | ||
| 1314 | int pagepos1 = 0; | 1300 | int pagepos1 = 0; |
| 1315 | - for (auto const& page: pages) { | 1301 | + for (auto const& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 1316 | ++pagepos1; | 1302 | ++pagepos1; |
| 1317 | - std::vector<QPDFAnnotationObjectHelper> annotations = | ||
| 1318 | - afdh.getWidgetAnnotationsForPage(page); | ||
| 1319 | - for (auto& aoh: annotations) { | 1303 | + for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) { |
| 1320 | QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh); | 1304 | QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh); |
| 1321 | JSON j_field = j_fields.addArrayElement(JSON::makeDictionary()); | 1305 | JSON j_field = j_fields.addArrayElement(JSON::makeDictionary()); |
| 1322 | j_field.addDictionaryMember( | 1306 | j_field.addDictionaryMember( |
| @@ -1355,8 +1339,7 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) | @@ -1355,8 +1339,7 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) | ||
| 1355 | j_field.addDictionaryMember("istext", JSON::makeBool(ffh.isText())); | 1339 | j_field.addDictionaryMember("istext", JSON::makeBool(ffh.isText())); |
| 1356 | JSON j_choices = | 1340 | JSON j_choices = |
| 1357 | j_field.addDictionaryMember("choices", JSON::makeArray()); | 1341 | j_field.addDictionaryMember("choices", JSON::makeArray()); |
| 1358 | - std::vector<std::string> choices = ffh.getChoices(); | ||
| 1359 | - for (auto const& choice: choices) { | 1342 | + for (auto const& choice: ffh.getChoices()) { |
| 1360 | j_choices.addArrayElement(JSON::makeString(choice)); | 1343 | j_choices.addArrayElement(JSON::makeString(choice)); |
| 1361 | } | 1344 | } |
| 1362 | JSON j_annot = j_field.addDictionaryMember( | 1345 | JSON j_annot = j_field.addDictionaryMember( |
| @@ -2282,19 +2265,16 @@ QPDFJob::handleTransformations(QPDF& pdf) | @@ -2282,19 +2265,16 @@ QPDFJob::handleTransformations(QPDF& pdf) | ||
| 2282 | }; | 2265 | }; |
| 2283 | if (m->externalize_inline_images || | 2266 | if (m->externalize_inline_images || |
| 2284 | (m->optimize_images && (!m->keep_inline_images))) { | 2267 | (m->optimize_images && (!m->keep_inline_images))) { |
| 2285 | - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | ||
| 2286 | - for (auto& ph: pages) { | 2268 | + for (auto& ph: dh.getAllPages()) { |
| 2287 | ph.externalizeInlineImages(m->ii_min_bytes); | 2269 | ph.externalizeInlineImages(m->ii_min_bytes); |
| 2288 | } | 2270 | } |
| 2289 | } | 2271 | } |
| 2290 | if (m->optimize_images) { | 2272 | if (m->optimize_images) { |
| 2291 | int pageno = 0; | 2273 | int pageno = 0; |
| 2292 | - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | ||
| 2293 | - for (auto& ph: pages) { | 2274 | + for (auto& ph: dh.getAllPages()) { |
| 2294 | ++pageno; | 2275 | ++pageno; |
| 2295 | QPDFObjectHandle page = ph.getObjectHandle(); | 2276 | QPDFObjectHandle page = ph.getObjectHandle(); |
| 2296 | - std::map<std::string, QPDFObjectHandle> images = ph.getImages(); | ||
| 2297 | - for (auto& iter2: images) { | 2277 | + for (auto& iter2: ph.getImages()) { |
| 2298 | std::string name = iter2.first; | 2278 | std::string name = iter2.first; |
| 2299 | QPDFObjectHandle& image = iter2.second; | 2279 | QPDFObjectHandle& image = iter2.second; |
| 2300 | ImageOptimizer* io = new ImageOptimizer( | 2280 | ImageOptimizer* io = new ImageOptimizer( |
| @@ -2330,8 +2310,7 @@ QPDFJob::handleTransformations(QPDF& pdf) | @@ -2330,8 +2310,7 @@ QPDFJob::handleTransformations(QPDF& pdf) | ||
| 2330 | m->flatten_annotations_required, m->flatten_annotations_forbidden); | 2310 | m->flatten_annotations_required, m->flatten_annotations_forbidden); |
| 2331 | } | 2311 | } |
| 2332 | if (m->coalesce_contents) { | 2312 | if (m->coalesce_contents) { |
| 2333 | - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | ||
| 2334 | - for (auto& page: pages) { | 2313 | + for (auto& page: dh.getAllPages()) { |
| 2335 | page.coalesceContentStreams(); | 2314 | page.coalesceContentStreams(); |
| 2336 | } | 2315 | } |
| 2337 | } | 2316 | } |
| @@ -2805,9 +2784,7 @@ QPDFJob::handleRotations(QPDF& pdf) | @@ -2805,9 +2784,7 @@ QPDFJob::handleRotations(QPDF& pdf) | ||
| 2805 | std::string const& range = iter.first; | 2784 | std::string const& range = iter.first; |
| 2806 | QPDFJob::RotationSpec const& rspec = iter.second; | 2785 | QPDFJob::RotationSpec const& rspec = iter.second; |
| 2807 | // range has been previously validated | 2786 | // range has been previously validated |
| 2808 | - std::vector<int> to_rotate = | ||
| 2809 | - QUtil::parse_numrange(range.c_str(), npages); | ||
| 2810 | - for (int pageno_iter: to_rotate) { | 2787 | + for (int pageno_iter: QUtil::parse_numrange(range.c_str(), npages)) { |
| 2811 | int pageno = pageno_iter - 1; | 2788 | int pageno = pageno_iter - 1; |
| 2812 | if ((pageno >= 0) && (pageno < npages)) { | 2789 | if ((pageno >= 0) && (pageno < npages)) { |
| 2813 | pages.at(QIntC::to_size(pageno)) | 2790 | pages.at(QIntC::to_size(pageno)) |
libqpdf/QPDFObjectHandle.cc
| @@ -1240,12 +1240,10 @@ QPDFObjectHandle::getResourceNames() | @@ -1240,12 +1240,10 @@ QPDFObjectHandle::getResourceNames() | ||
| 1240 | if (!isDictionary()) { | 1240 | if (!isDictionary()) { |
| 1241 | return result; | 1241 | return result; |
| 1242 | } | 1242 | } |
| 1243 | - std::set<std::string> keys = getKeys(); | ||
| 1244 | - for (auto const& key: keys) { | 1243 | + for (auto const& key: getKeys()) { |
| 1245 | QPDFObjectHandle val = getKey(key); | 1244 | QPDFObjectHandle val = getKey(key); |
| 1246 | if (val.isDictionary()) { | 1245 | if (val.isDictionary()) { |
| 1247 | - std::set<std::string> val_keys = val.getKeys(); | ||
| 1248 | - for (auto const& val_key: val_keys) { | 1246 | + for (auto const& val_key: val.getKeys()) { |
| 1249 | result.insert(val_key); | 1247 | result.insert(val_key); |
| 1250 | } | 1248 | } |
| 1251 | } | 1249 | } |
| @@ -1642,14 +1640,12 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first) | @@ -1642,14 +1640,12 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first) | ||
| 1642 | { | 1640 | { |
| 1643 | new_contents.assertStream(); | 1641 | new_contents.assertStream(); |
| 1644 | 1642 | ||
| 1645 | - std::vector<QPDFObjectHandle> orig_contents = getPageContents(); | ||
| 1646 | - | ||
| 1647 | std::vector<QPDFObjectHandle> content_streams; | 1643 | std::vector<QPDFObjectHandle> content_streams; |
| 1648 | if (first) { | 1644 | if (first) { |
| 1649 | QTC::TC("qpdf", "QPDFObjectHandle prepend page contents"); | 1645 | QTC::TC("qpdf", "QPDFObjectHandle prepend page contents"); |
| 1650 | content_streams.push_back(new_contents); | 1646 | content_streams.push_back(new_contents); |
| 1651 | } | 1647 | } |
| 1652 | - for (auto const& iter: orig_contents) { | 1648 | + for (auto const& iter: getPageContents()) { |
| 1653 | QTC::TC("qpdf", "QPDFObjectHandle append page contents"); | 1649 | QTC::TC("qpdf", "QPDFObjectHandle append page contents"); |
| 1654 | content_streams.push_back(iter); | 1650 | content_streams.push_back(iter); |
| 1655 | } | 1651 | } |
| @@ -1657,8 +1653,7 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first) | @@ -1657,8 +1653,7 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first) | ||
| 1657 | content_streams.push_back(new_contents); | 1653 | content_streams.push_back(new_contents); |
| 1658 | } | 1654 | } |
| 1659 | 1655 | ||
| 1660 | - QPDFObjectHandle contents = QPDFObjectHandle::newArray(content_streams); | ||
| 1661 | - this->replaceKey("/Contents", contents); | 1656 | + this->replaceKey("/Contents", newArray(content_streams)); |
| 1662 | } | 1657 | } |
| 1663 | 1658 | ||
| 1664 | void | 1659 | void |
| @@ -2927,9 +2922,8 @@ QPDFObjectHandle::copyObject( | @@ -2927,9 +2922,8 @@ QPDFObjectHandle::copyObject( | ||
| 2927 | new_obj = std::shared_ptr<QPDFObject>(new QPDF_Array(items)); | 2922 | new_obj = std::shared_ptr<QPDFObject>(new QPDF_Array(items)); |
| 2928 | } else if (isDictionary()) { | 2923 | } else if (isDictionary()) { |
| 2929 | QTC::TC("qpdf", "QPDFObjectHandle clone dictionary"); | 2924 | QTC::TC("qpdf", "QPDFObjectHandle clone dictionary"); |
| 2930 | - std::set<std::string> keys = getKeys(); | ||
| 2931 | std::map<std::string, QPDFObjectHandle> items; | 2925 | std::map<std::string, QPDFObjectHandle> items; |
| 2932 | - for (auto const& key: keys) { | 2926 | + for (auto const& key: getKeys()) { |
| 2933 | items[key] = getKey(key); | 2927 | items[key] = getKey(key); |
| 2934 | if ((!first_level_only) && | 2928 | if ((!first_level_only) && |
| 2935 | (cross_indirect || (!items[key].isIndirect()))) { | 2929 | (cross_indirect || (!items[key].isIndirect()))) { |
libqpdf/QPDFPageDocumentHelper.cc
| @@ -12,9 +12,8 @@ QPDFPageDocumentHelper::QPDFPageDocumentHelper(QPDF& qpdf) : | @@ -12,9 +12,8 @@ QPDFPageDocumentHelper::QPDFPageDocumentHelper(QPDF& qpdf) : | ||
| 12 | std::vector<QPDFPageObjectHelper> | 12 | std::vector<QPDFPageObjectHelper> |
| 13 | QPDFPageDocumentHelper::getAllPages() | 13 | QPDFPageDocumentHelper::getAllPages() |
| 14 | { | 14 | { |
| 15 | - std::vector<QPDFObjectHandle> const& pages_v = this->qpdf.getAllPages(); | ||
| 16 | std::vector<QPDFPageObjectHelper> pages; | 15 | std::vector<QPDFPageObjectHelper> pages; |
| 17 | - for (auto const& iter: pages_v) { | 16 | + for (auto const& iter: this->qpdf.getAllPages()) { |
| 18 | pages.push_back(QPDFPageObjectHelper(iter)); | 17 | pages.push_back(QPDFPageObjectHelper(iter)); |
| 19 | } | 18 | } |
| 20 | return pages; | 19 | return pages; |
| @@ -29,8 +28,7 @@ QPDFPageDocumentHelper::pushInheritedAttributesToPage() | @@ -29,8 +28,7 @@ QPDFPageDocumentHelper::pushInheritedAttributesToPage() | ||
| 29 | void | 28 | void |
| 30 | QPDFPageDocumentHelper::removeUnreferencedResources() | 29 | QPDFPageDocumentHelper::removeUnreferencedResources() |
| 31 | { | 30 | { |
| 32 | - std::vector<QPDFPageObjectHelper> pages = getAllPages(); | ||
| 33 | - for (auto& ph: pages) { | 31 | + for (auto& ph: getAllPages()) { |
| 34 | ph.removeUnreferencedResources(); | 32 | ph.removeUnreferencedResources(); |
| 35 | } | 33 | } |
| 36 | } | 34 | } |
| @@ -66,8 +64,7 @@ QPDFPageDocumentHelper::flattenAnnotations( | @@ -66,8 +64,7 @@ QPDFPageDocumentHelper::flattenAnnotations( | ||
| 66 | .warnIfPossible("document does not have updated appearance streams," | 64 | .warnIfPossible("document does not have updated appearance streams," |
| 67 | " so form fields will not be flattened"); | 65 | " so form fields will not be flattened"); |
| 68 | } | 66 | } |
| 69 | - std::vector<QPDFPageObjectHelper> pages = getAllPages(); | ||
| 70 | - for (auto& ph: pages) { | 67 | + for (auto& ph: getAllPages()) { |
| 71 | QPDFObjectHandle resources = ph.getAttribute("/Resources", true); | 68 | QPDFObjectHandle resources = ph.getAttribute("/Resources", true); |
| 72 | if (!resources.isDictionary()) { | 69 | if (!resources.isDictionary()) { |
| 73 | // This should never happen and is not exercised in the | 70 | // This should never happen and is not exercised in the |
libqpdf/QPDFTokenizer.cc
| @@ -567,8 +567,7 @@ QPDFTokenizer::findEI(std::shared_ptr<InputSource> input) | @@ -567,8 +567,7 @@ QPDFTokenizer::findEI(std::shared_ptr<InputSource> input) | ||
| 567 | bool found_alpha = false; | 567 | bool found_alpha = false; |
| 568 | bool found_non_printable = false; | 568 | bool found_non_printable = false; |
| 569 | bool found_other = false; | 569 | bool found_other = false; |
| 570 | - std::string value = t.getValue(); | ||
| 571 | - for (char ch: value) { | 570 | + for (char ch: t.getValue()) { |
| 572 | if (((ch >= 'a') && (ch <= 'z')) || | 571 | if (((ch >= 'a') && (ch <= 'z')) || |
| 573 | ((ch >= 'A') && (ch <= 'Z')) || (ch == '*')) { | 572 | ((ch >= 'A') && (ch <= 'Z')) || (ch == '*')) { |
| 574 | // Treat '*' as alpha since there are valid | 573 | // Treat '*' as alpha since there are valid |
libqpdf/QPDFWriter.cc
| @@ -1237,8 +1237,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | @@ -1237,8 +1237,7 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object) | ||
| 1237 | } | 1237 | } |
| 1238 | } | 1238 | } |
| 1239 | } else if (object.isDictionary()) { | 1239 | } else if (object.isDictionary()) { |
| 1240 | - std::set<std::string> keys = object.getKeys(); | ||
| 1241 | - for (auto const& key: keys) { | 1240 | + for (auto const& key: object.getKeys()) { |
| 1242 | if (!this->m->linearized) { | 1241 | if (!this->m->linearized) { |
| 1243 | enqueueObject(object.getKey(key)); | 1242 | enqueueObject(object.getKey(key)); |
| 1244 | } | 1243 | } |
| @@ -1283,8 +1282,7 @@ QPDFWriter::writeTrailer( | @@ -1283,8 +1282,7 @@ QPDFWriter::writeTrailer( | ||
| 1283 | writeString(" /Size "); | 1282 | writeString(" /Size "); |
| 1284 | writeString(QUtil::int_to_string(size)); | 1283 | writeString(QUtil::int_to_string(size)); |
| 1285 | } else { | 1284 | } else { |
| 1286 | - std::set<std::string> keys = trailer.getKeys(); | ||
| 1287 | - for (auto const& key: keys) { | 1285 | + for (auto const& key: trailer.getKeys()) { |
| 1288 | writeStringQDF(" "); | 1286 | writeStringQDF(" "); |
| 1289 | writeStringNoQDF(" "); | 1287 | writeStringNoQDF(" "); |
| 1290 | writeString(QPDF_Name::normalizeName(key)); | 1288 | writeString(QPDF_Name::normalizeName(key)); |
| @@ -1644,8 +1642,7 @@ QPDFWriter::unparseObject( | @@ -1644,8 +1642,7 @@ QPDFWriter::unparseObject( | ||
| 1644 | writeString("<<"); | 1642 | writeString("<<"); |
| 1645 | writeStringQDF("\n"); | 1643 | writeStringQDF("\n"); |
| 1646 | 1644 | ||
| 1647 | - std::set<std::string> keys = object.getKeys(); | ||
| 1648 | - for (auto const& key: keys) { | 1645 | + for (auto const& key: object.getKeys()) { |
| 1649 | writeStringQDF(indent); | 1646 | writeStringQDF(indent); |
| 1650 | writeStringQDF(" "); | 1647 | writeStringQDF(" "); |
| 1651 | writeStringNoQDF(" "); | 1648 | writeStringNoQDF(" "); |
| @@ -2074,8 +2071,7 @@ QPDFWriter::generateID() | @@ -2074,8 +2071,7 @@ QPDFWriter::generateID() | ||
| 2074 | seed += " QPDF "; | 2071 | seed += " QPDF "; |
| 2075 | if (trailer.hasKey("/Info")) { | 2072 | if (trailer.hasKey("/Info")) { |
| 2076 | QPDFObjectHandle info = trailer.getKey("/Info"); | 2073 | QPDFObjectHandle info = trailer.getKey("/Info"); |
| 2077 | - std::set<std::string> keys = info.getKeys(); | ||
| 2078 | - for (auto const& key: keys) { | 2074 | + for (auto const& key: info.getKeys()) { |
| 2079 | QPDFObjectHandle obj = info.getKey(key); | 2075 | QPDFObjectHandle obj = info.getKey(key); |
| 2080 | if (obj.isString()) { | 2076 | if (obj.isString()) { |
| 2081 | seed += " "; | 2077 | seed += " "; |
| @@ -2365,8 +2361,7 @@ QPDFWriter::doWriteSetup() | @@ -2365,8 +2361,7 @@ QPDFWriter::doWriteSetup() | ||
| 2365 | 2361 | ||
| 2366 | if (this->m->linearized) { | 2362 | if (this->m->linearized) { |
| 2367 | // Page dictionaries are not allowed to be compressed objects. | 2363 | // Page dictionaries are not allowed to be compressed objects. |
| 2368 | - std::vector<QPDFObjectHandle> pages = this->m->pdf.getAllPages(); | ||
| 2369 | - for (auto& page: pages) { | 2364 | + for (auto& page: this->m->pdf.getAllPages()) { |
| 2370 | QPDFObjGen og = page.getObjGen(); | 2365 | QPDFObjGen og = page.getObjGen(); |
| 2371 | if (this->m->object_to_object_stream.count(og)) { | 2366 | if (this->m->object_to_object_stream.count(og)) { |
| 2372 | QTC::TC("qpdf", "QPDFWriter uncompressing page dictionary"); | 2367 | QTC::TC("qpdf", "QPDFWriter uncompressing page dictionary"); |
| @@ -3251,8 +3246,7 @@ QPDFWriter::enqueueObjectsStandard() | @@ -3251,8 +3246,7 @@ QPDFWriter::enqueueObjectsStandard() | ||
| 3251 | // dictionary into the queue, handling direct objects recursively. | 3246 | // dictionary into the queue, handling direct objects recursively. |
| 3252 | // Root is already there, so enqueuing it a second time is a | 3247 | // Root is already there, so enqueuing it a second time is a |
| 3253 | // no-op. | 3248 | // no-op. |
| 3254 | - std::set<std::string> keys = trailer.getKeys(); | ||
| 3255 | - for (auto const& key: keys) { | 3249 | + for (auto const& key: trailer.getKeys()) { |
| 3256 | enqueueObject(trailer.getKey(key)); | 3250 | enqueueObject(trailer.getKey(key)); |
| 3257 | } | 3251 | } |
| 3258 | } | 3252 | } |
| @@ -3276,8 +3270,7 @@ QPDFWriter::enqueueObjectsPCLm() | @@ -3276,8 +3270,7 @@ QPDFWriter::enqueueObjectsPCLm() | ||
| 3276 | 3270 | ||
| 3277 | // enqueue all the strips for each page | 3271 | // enqueue all the strips for each page |
| 3278 | QPDFObjectHandle strips = page.getKey("/Resources").getKey("/XObject"); | 3272 | QPDFObjectHandle strips = page.getKey("/Resources").getKey("/XObject"); |
| 3279 | - std::set<std::string> keys = strips.getKeys(); | ||
| 3280 | - for (auto const& image: keys) { | 3273 | + for (auto const& image: strips.getKeys()) { |
| 3281 | enqueueObject(strips.getKey(image)); | 3274 | enqueueObject(strips.getKey(image)); |
| 3282 | enqueueObject(QPDFObjectHandle::newStream( | 3275 | enqueueObject(QPDFObjectHandle::newStream( |
| 3283 | &this->m->pdf, image_transform_content)); | 3276 | &this->m->pdf, image_transform_content)); |
libqpdf/QPDF_linearization.cc
| @@ -663,9 +663,8 @@ QPDF::maxEnd(ObjUser const& ou) | @@ -663,9 +663,8 @@ QPDF::maxEnd(ObjUser const& ou) | ||
| 663 | if (this->m->obj_user_to_objects.count(ou) == 0) { | 663 | if (this->m->obj_user_to_objects.count(ou) == 0) { |
| 664 | stopOnError("no entry in object user table for requested object user"); | 664 | stopOnError("no entry in object user table for requested object user"); |
| 665 | } | 665 | } |
| 666 | - std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou]; | ||
| 667 | qpdf_offset_t end = 0; | 666 | qpdf_offset_t end = 0; |
| 668 | - for (auto const& og: ogs) { | 667 | + for (auto const& og: this->m->obj_user_to_objects[ou]) { |
| 669 | if (this->m->obj_cache.count(og) == 0) { | 668 | if (this->m->obj_cache.count(og) == 0) { |
| 670 | stopOnError("unknown object referenced in object user table"); | 669 | stopOnError("unknown object referenced in object user table"); |
| 671 | } | 670 | } |
| @@ -1474,8 +1473,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1474,8 +1473,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1474 | stopOnError("found unreferenced page while" | 1473 | stopOnError("found unreferenced page while" |
| 1475 | " calculating linearization data"); | 1474 | " calculating linearization data"); |
| 1476 | } | 1475 | } |
| 1477 | - std::set<QPDFObjGen> ogs = this->m->obj_user_to_objects[ou]; | ||
| 1478 | - for (auto const& og: ogs) { | 1476 | + for (auto const& og: this->m->obj_user_to_objects[ou]) { |
| 1479 | if (lc_other_page_private.count(og)) { | 1477 | if (lc_other_page_private.count(og)) { |
| 1480 | lc_other_page_private.erase(og); | 1478 | lc_other_page_private.erase(og); |
| 1481 | this->m->part7.push_back(objGenToIndirect(og)); | 1479 | this->m->part7.push_back(objGenToIndirect(og)); |
| @@ -1637,8 +1635,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1637,8 +1635,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1637 | stopOnError("found unreferenced page while" | 1635 | stopOnError("found unreferenced page while" |
| 1638 | " calculating linearization data"); | 1636 | " calculating linearization data"); |
| 1639 | } | 1637 | } |
| 1640 | - std::set<QPDFObjGen> const& ogs = this->m->obj_user_to_objects[ou]; | ||
| 1641 | - for (auto const& og: ogs) { | 1638 | + for (auto const& og: this->m->obj_user_to_objects[ou]) { |
| 1642 | if ((this->m->object_to_obj_users[og].size() > 1) && | 1639 | if ((this->m->object_to_obj_users[og].size() > 1) && |
| 1643 | (obj_to_index.count(og.getObj()) > 0)) { | 1640 | (obj_to_index.count(og.getObj()) > 0)) { |
| 1644 | int idx = obj_to_index[og.getObj()]; | 1641 | int idx = obj_to_index[og.getObj()]; |
libqpdf/QPDF_optimization.cc
| @@ -90,8 +90,7 @@ QPDF::optimize( | @@ -90,8 +90,7 @@ QPDF::optimize( | ||
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | // Traverse document-level items | 92 | // Traverse document-level items |
| 93 | - std::set<std::string> keys = this->m->trailer.getKeys(); | ||
| 94 | - for (auto const& key: keys) { | 93 | + for (auto const& key: this->m->trailer.getKeys()) { |
| 95 | if (key == "/Root") { | 94 | if (key == "/Root") { |
| 96 | // handled separately | 95 | // handled separately |
| 97 | } else { | 96 | } else { |
| @@ -102,8 +101,7 @@ QPDF::optimize( | @@ -102,8 +101,7 @@ QPDF::optimize( | ||
| 102 | } | 101 | } |
| 103 | } | 102 | } |
| 104 | 103 | ||
| 105 | - keys = root.getKeys(); | ||
| 106 | - for (auto const& key: keys) { | 104 | + for (auto const& key: root.getKeys()) { |
| 107 | // Technically, /I keys from /Thread dictionaries are supposed | 105 | // Technically, /I keys from /Thread dictionaries are supposed |
| 108 | // to be handled separately, but we are going to disregard | 106 | // to be handled separately, but we are going to disregard |
| 109 | // that specification for now. There is loads of evidence | 107 | // that specification for now. There is loads of evidence |
| @@ -205,8 +203,7 @@ QPDF::pushInheritedAttributesToPageInternal( | @@ -205,8 +203,7 @@ QPDF::pushInheritedAttributesToPageInternal( | ||
| 205 | // that have values for this attribute. | 203 | // that have values for this attribute. |
| 206 | 204 | ||
| 207 | std::set<std::string> inheritable_keys; | 205 | std::set<std::string> inheritable_keys; |
| 208 | - std::set<std::string> keys = cur_pages.getKeys(); | ||
| 209 | - for (auto const& key: keys) { | 206 | + for (auto const& key: cur_pages.getKeys()) { |
| 210 | if ((key == "/MediaBox") || (key == "/CropBox") || | 207 | if ((key == "/MediaBox") || (key == "/CropBox") || |
| 211 | (key == "/Resources") || (key == "/Rotate")) { | 208 | (key == "/Resources") || (key == "/Rotate")) { |
| 212 | if (!allow_changes) { | 209 | if (!allow_changes) { |
| @@ -387,8 +384,7 @@ QPDF::updateObjectMapsInternal( | @@ -387,8 +384,7 @@ QPDF::updateObjectMapsInternal( | ||
| 387 | } | 384 | } |
| 388 | } | 385 | } |
| 389 | 386 | ||
| 390 | - std::set<std::string> keys = dict.getKeys(); | ||
| 391 | - for (auto const& key: keys) { | 387 | + for (auto const& key: dict.getKeys()) { |
| 392 | if (is_page_node && (key == "/Thumb")) { | 388 | if (is_page_node && (key == "/Thumb")) { |
| 393 | // Traverse page thumbnail dictionaries as a special | 389 | // Traverse page thumbnail dictionaries as a special |
| 394 | // case. | 390 | // case. |
| @@ -437,8 +433,8 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data) | @@ -437,8 +433,8 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data) | ||
| 437 | 433 | ||
| 438 | for (auto const& i1: this->m->obj_user_to_objects) { | 434 | for (auto const& i1: this->m->obj_user_to_objects) { |
| 439 | ObjUser const& ou = i1.first; | 435 | ObjUser const& ou = i1.first; |
| 440 | - std::set<QPDFObjGen> const& objects = i1.second; | ||
| 441 | - for (auto const& og: objects) { | 436 | + // Loop over objects. |
| 437 | + for (auto const& og: i1.second) { | ||
| 442 | auto i2 = object_stream_data.find(og.getObj()); | 438 | auto i2 = object_stream_data.find(og.getObj()); |
| 443 | if (i2 == object_stream_data.end()) { | 439 | if (i2 == object_stream_data.end()) { |
| 444 | t_obj_user_to_objects[ou].insert(og); | 440 | t_obj_user_to_objects[ou].insert(og); |
| @@ -450,8 +446,8 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data) | @@ -450,8 +446,8 @@ QPDF::filterCompressedObjects(std::map<int, int> const& object_stream_data) | ||
| 450 | 446 | ||
| 451 | for (auto const& i1: this->m->object_to_obj_users) { | 447 | for (auto const& i1: this->m->object_to_obj_users) { |
| 452 | QPDFObjGen const& og = i1.first; | 448 | QPDFObjGen const& og = i1.first; |
| 453 | - std::set<ObjUser> const& objusers = i1.second; | ||
| 454 | - for (auto const& ou: objusers) { | 449 | + // Loop over obj_users. |
| 450 | + for (auto const& ou: i1.second) { | ||
| 455 | auto i2 = object_stream_data.find(og.getObj()); | 451 | auto i2 = object_stream_data.find(og.getObj()); |
| 456 | if (i2 == object_stream_data.end()) { | 452 | if (i2 == object_stream_data.end()) { |
| 457 | t_object_to_obj_users[og].insert(ou); | 453 | t_object_to_obj_users[og].insert(ou); |
qpdf/test_driver.cc
| @@ -377,15 +377,12 @@ test_4(QPDF& pdf, char const* arg2) | @@ -377,15 +377,12 @@ test_4(QPDF& pdf, char const* arg2) | ||
| 377 | static void | 377 | static void |
| 378 | test_5(QPDF& pdf, char const* arg2) | 378 | test_5(QPDF& pdf, char const* arg2) |
| 379 | { | 379 | { |
| 380 | - QPDFPageDocumentHelper dh(pdf); | ||
| 381 | - std::vector<QPDFPageObjectHelper> pages = dh.getAllPages(); | ||
| 382 | int pageno = 0; | 380 | int pageno = 0; |
| 383 | - for (auto& page: pages) { | 381 | + for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 384 | ++pageno; | 382 | ++pageno; |
| 385 | std::cout << "page " << pageno << ":" << std::endl; | 383 | std::cout << "page " << pageno << ":" << std::endl; |
| 386 | std::cout << " images:" << std::endl; | 384 | std::cout << " images:" << std::endl; |
| 387 | - std::map<std::string, QPDFObjectHandle> images = page.getImages(); | ||
| 388 | - for (auto const& iter2: images) { | 385 | + for (auto const& iter2: page.getImages()) { |
| 389 | std::string const& name = iter2.first; | 386 | std::string const& name = iter2.first; |
| 390 | QPDFObjectHandle image = iter2.second; | 387 | QPDFObjectHandle image = iter2.second; |
| 391 | QPDFObjectHandle dict = image.getDict(); | 388 | QPDFObjectHandle dict = image.getDict(); |
| @@ -1319,9 +1316,7 @@ static void | @@ -1319,9 +1316,7 @@ static void | ||
| 1319 | test_37(QPDF& pdf, char const* arg2) | 1316 | test_37(QPDF& pdf, char const* arg2) |
| 1320 | { | 1317 | { |
| 1321 | // Parse content streams of all pages | 1318 | // Parse content streams of all pages |
| 1322 | - std::vector<QPDFPageObjectHelper> pages = | ||
| 1323 | - QPDFPageDocumentHelper(pdf).getAllPages(); | ||
| 1324 | - for (auto& page: pages) { | 1319 | + for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 1325 | ParserCallbacks cb; | 1320 | ParserCallbacks cb; |
| 1326 | page.parseContents(&cb); | 1321 | page.parseContents(&cb); |
| 1327 | } | 1322 | } |
| @@ -1341,10 +1336,8 @@ static void | @@ -1341,10 +1336,8 @@ static void | ||
| 1341 | test_39(QPDF& pdf, char const* arg2) | 1336 | test_39(QPDF& pdf, char const* arg2) |
| 1342 | { | 1337 | { |
| 1343 | // Display image filter and color set for each image on each page | 1338 | // Display image filter and color set for each image on each page |
| 1344 | - std::vector<QPDFPageObjectHelper> pages = | ||
| 1345 | - QPDFPageDocumentHelper(pdf).getAllPages(); | ||
| 1346 | int pageno = 0; | 1339 | int pageno = 0; |
| 1347 | - for (auto& page: pages) { | 1340 | + for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 1348 | std::cout << "page " << ++pageno << std::endl; | 1341 | std::cout << "page " << ++pageno << std::endl; |
| 1349 | std::map<std::string, QPDFObjectHandle> images = page.getImages(); | 1342 | std::map<std::string, QPDFObjectHandle> images = page.getImages(); |
| 1350 | for (auto& i_iter: images) { | 1343 | for (auto& i_iter: images) { |
| @@ -1377,9 +1370,7 @@ test_41(QPDF& pdf, char const* arg2) | @@ -1377,9 +1370,7 @@ test_41(QPDF& pdf, char const* arg2) | ||
| 1377 | { | 1370 | { |
| 1378 | // Apply a token filter. This test case is crafted to work | 1371 | // Apply a token filter. This test case is crafted to work |
| 1379 | // with coalesce.pdf. | 1372 | // with coalesce.pdf. |
| 1380 | - std::vector<QPDFPageObjectHelper> pages = | ||
| 1381 | - QPDFPageDocumentHelper(pdf).getAllPages(); | ||
| 1382 | - for (auto& page: pages) { | 1373 | + for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 1383 | page.addContentTokenFilter( | 1374 | page.addContentTokenFilter( |
| 1384 | std::shared_ptr<QPDFObjectHandle::TokenFilter>(new TokenFilter())); | 1375 | std::shared_ptr<QPDFObjectHandle::TokenFilter>(new TokenFilter())); |
| 1385 | } | 1376 | } |
| @@ -1509,8 +1500,7 @@ test_43(QPDF& pdf, char const* arg2) | @@ -1509,8 +1500,7 @@ test_43(QPDF& pdf, char const* arg2) | ||
| 1509 | return; | 1500 | return; |
| 1510 | } | 1501 | } |
| 1511 | std::cout << "iterating over form fields\n"; | 1502 | std::cout << "iterating over form fields\n"; |
| 1512 | - std::vector<QPDFFormFieldObjectHelper> form_fields = afdh.getFormFields(); | ||
| 1513 | - for (auto& ffh: form_fields) { | 1503 | + for (auto& ffh: afdh.getFormFields()) { |
| 1514 | std::cout << "Field: " << ffh.getObjectHandle().unparse() << std::endl; | 1504 | std::cout << "Field: " << ffh.getObjectHandle().unparse() << std::endl; |
| 1515 | QPDFFormFieldObjectHelper node = ffh; | 1505 | QPDFFormFieldObjectHelper node = ffh; |
| 1516 | while (!node.isNull()) { | 1506 | while (!node.isNull()) { |
| @@ -1548,9 +1538,7 @@ test_43(QPDF& pdf, char const* arg2) | @@ -1548,9 +1538,7 @@ test_43(QPDF& pdf, char const* arg2) | ||
| 1548 | std::cout << "iterating over annotations per page\n"; | 1538 | std::cout << "iterating over annotations per page\n"; |
| 1549 | for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { | 1539 | for (auto& page: QPDFPageDocumentHelper(pdf).getAllPages()) { |
| 1550 | std::cout << "Page: " << page.getObjectHandle().unparse() << std::endl; | 1540 | std::cout << "Page: " << page.getObjectHandle().unparse() << std::endl; |
| 1551 | - std::vector<QPDFAnnotationObjectHelper> annotations = | ||
| 1552 | - afdh.getWidgetAnnotationsForPage(page); | ||
| 1553 | - for (auto& ah: annotations) { | 1541 | + for (auto& ah: afdh.getWidgetAnnotationsForPage(page)) { |
| 1554 | std::cout << " Annotation: " << ah.getObjectHandle().unparse() | 1542 | std::cout << " Annotation: " << ah.getObjectHandle().unparse() |
| 1555 | << std::endl; | 1543 | << std::endl; |
| 1556 | std::cout | 1544 | std::cout |
| @@ -1578,9 +1566,7 @@ static void | @@ -1578,9 +1566,7 @@ static void | ||
| 1578 | test_44(QPDF& pdf, char const* arg2) | 1566 | test_44(QPDF& pdf, char const* arg2) |
| 1579 | { | 1567 | { |
| 1580 | // Set form fields. | 1568 | // Set form fields. |
| 1581 | - QPDFAcroFormDocumentHelper afdh(pdf); | ||
| 1582 | - std::vector<QPDFFormFieldObjectHelper> fields = afdh.getFormFields(); | ||
| 1583 | - for (auto& field: fields) { | 1569 | + for (auto& field: QPDFAcroFormDocumentHelper(pdf).getFormFields()) { |
| 1584 | QPDFObjectHandle ft = field.getInheritableFieldValue("/FT"); | 1570 | QPDFObjectHandle ft = field.getInheritableFieldValue("/FT"); |
| 1585 | if (ft.isName() && (ft.getName() == "/Tx")) { | 1571 | if (ft.isName() && (ft.getName() == "/Tx")) { |
| 1586 | // \xc3\xb7 is utf-8 for U+00F7 (divided by) | 1572 | // \xc3\xb7 is utf-8 for U+00F7 (divided by) |
qpdf/test_parsedoffset.cc
| @@ -51,8 +51,7 @@ walk( | @@ -51,8 +51,7 @@ walk( | ||
| 51 | result[stream_number].push_back(p); | 51 | result[stream_number].push_back(p); |
| 52 | 52 | ||
| 53 | if (obj.isArray()) { | 53 | if (obj.isArray()) { |
| 54 | - std::vector<QPDFObjectHandle> array = obj.getArrayAsVector(); | ||
| 55 | - for (auto& oh: array) { | 54 | + for (auto& oh: obj.getArrayAsVector()) { |
| 56 | if (!oh.isIndirect()) { | 55 | if (!oh.isIndirect()) { |
| 57 | // QPDF::GetAllObjects() enumerates all indirect objects. | 56 | // QPDF::GetAllObjects() enumerates all indirect objects. |
| 58 | // So only the direct objects are recursed here. | 57 | // So only the direct objects are recursed here. |
| @@ -60,8 +59,7 @@ walk( | @@ -60,8 +59,7 @@ walk( | ||
| 60 | } | 59 | } |
| 61 | } | 60 | } |
| 62 | } else if (obj.isDictionary()) { | 61 | } else if (obj.isDictionary()) { |
| 63 | - std::set<std::string> keys = obj.getKeys(); | ||
| 64 | - for (auto const& key: keys) { | 62 | + for (auto const& key: obj.getKeys()) { |
| 65 | QPDFObjectHandle item = obj.getKey(key); | 63 | QPDFObjectHandle item = obj.getKey(key); |
| 66 | if (!item.isIndirect()) { | 64 | if (!item.isIndirect()) { |
| 67 | // QPDF::GetAllObjects() enumerates all indirect objects. | 65 | // QPDF::GetAllObjects() enumerates all indirect objects. |
| @@ -81,10 +79,9 @@ process( | @@ -81,10 +79,9 @@ process( | ||
| 81 | { | 79 | { |
| 82 | QPDF qpdf; | 80 | QPDF qpdf; |
| 83 | qpdf.processFile(fn.c_str()); | 81 | qpdf.processFile(fn.c_str()); |
| 84 | - std::vector<QPDFObjectHandle> objs = qpdf.getAllObjects(); | ||
| 85 | std::map<QPDFObjGen, QPDFXRefEntry> xrefs = qpdf.getXRefTable(); | 82 | std::map<QPDFObjGen, QPDFXRefEntry> xrefs = qpdf.getXRefTable(); |
| 86 | 83 | ||
| 87 | - for (auto const& oh: objs) { | 84 | + for (auto const& oh: qpdf.getAllObjects()) { |
| 88 | if (xrefs.count(oh.getObjGen()) == 0) { | 85 | if (xrefs.count(oh.getObjGen()) == 0) { |
| 89 | std::cerr << oh.getObjectID() << "/" << oh.getGeneration() | 86 | std::cerr << oh.getObjectID() << "/" << oh.getGeneration() |
| 90 | << " is not found in xref table" << std::endl; | 87 | << " is not found in xref table" << std::endl; |
qpdf/test_pdf_doc_encoding.cc
| @@ -26,8 +26,7 @@ main(int argc, char* argv[]) | @@ -26,8 +26,7 @@ main(int argc, char* argv[]) | ||
| 26 | usage(); | 26 | usage(); |
| 27 | } | 27 | } |
| 28 | char const* infilename = argv[1]; | 28 | char const* infilename = argv[1]; |
| 29 | - std::list<std::string> lines = QUtil::read_lines_from_file(infilename); | ||
| 30 | - for (auto const& line: lines) { | 29 | + for (auto const& line: QUtil::read_lines_from_file(infilename)) { |
| 31 | QPDFObjectHandle str = QPDFObjectHandle::newString(line); | 30 | QPDFObjectHandle str = QPDFObjectHandle::newString(line); |
| 32 | std::cout << str.getUTF8Value() << std::endl; | 31 | std::cout << str.getUTF8Value() << std::endl; |
| 33 | } | 32 | } |
qpdf/test_pdf_unicode.cc
| @@ -26,8 +26,7 @@ main(int argc, char* argv[]) | @@ -26,8 +26,7 @@ main(int argc, char* argv[]) | ||
| 26 | usage(); | 26 | usage(); |
| 27 | } | 27 | } |
| 28 | char const* infilename = argv[1]; | 28 | char const* infilename = argv[1]; |
| 29 | - std::list<std::string> lines = QUtil::read_lines_from_file(infilename); | ||
| 30 | - for (auto const& line: lines) { | 29 | + for (auto const& line: QUtil::read_lines_from_file(infilename)) { |
| 31 | QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(line); | 30 | QPDFObjectHandle str = QPDFObjectHandle::newUnicodeString(line); |
| 32 | std::cout << str.getUTF8Value() << " // " << str.unparseBinary() | 31 | std::cout << str.getUTF8Value() << " // " << str.unparseBinary() |
| 33 | << std::endl; | 32 | << std::endl; |
qpdf/test_tokenizer.cc
| @@ -198,10 +198,8 @@ process(char const* filename, bool include_ignorable, size_t max_len) | @@ -198,10 +198,8 @@ process(char const* filename, bool include_ignorable, size_t max_len) | ||
| 198 | // Tokenize content streams, skipping inline images | 198 | // Tokenize content streams, skipping inline images |
| 199 | QPDF qpdf; | 199 | QPDF qpdf; |
| 200 | qpdf.processFile(filename); | 200 | qpdf.processFile(filename); |
| 201 | - std::vector<QPDFPageObjectHelper> pages = | ||
| 202 | - QPDFPageDocumentHelper(qpdf).getAllPages(); | ||
| 203 | int pageno = 0; | 201 | int pageno = 0; |
| 204 | - for (auto& page: pages) { | 202 | + for (auto& page: QPDFPageDocumentHelper(qpdf).getAllPages()) { |
| 205 | ++pageno; | 203 | ++pageno; |
| 206 | Pl_Buffer plb("buffer"); | 204 | Pl_Buffer plb("buffer"); |
| 207 | page.pipeContents(&plb); | 205 | page.pipeContents(&plb); |
qpdf/test_xref.cc
| @@ -19,9 +19,7 @@ main(int argc, char* argv[]) | @@ -19,9 +19,7 @@ main(int argc, char* argv[]) | ||
| 19 | QPDF qpdf; | 19 | QPDF qpdf; |
| 20 | qpdf.processFile(argv[1]); | 20 | qpdf.processFile(argv[1]); |
| 21 | 21 | ||
| 22 | - std::map<QPDFObjGen, QPDFXRefEntry> xref = qpdf.getXRefTable(); | ||
| 23 | - | ||
| 24 | - for (auto const& iter: xref) { | 22 | + for (auto const& iter: qpdf.getXRefTable()) { |
| 25 | std::cout << iter.first.getObj() << "/" << iter.first.getGen() | 23 | std::cout << iter.first.getObj() << "/" << iter.first.getGen() |
| 26 | << ", "; | 24 | << ", "; |
| 27 | switch (iter.second.getType()) { | 25 | switch (iter.second.getType()) { |