Commit 5ad81ce6049b685694c59c9c155314c99f6f2303

Authored by m-holger
1 parent bd197adf

Refactor `QPDF::getAllPages` usage: replace with `Pages::all` across `Doc::Linearization`.

Showing 1 changed file with 21 additions and 21 deletions
libqpdf/QPDF_linearization.cc
@@ -189,7 +189,7 @@ Lin::readLinearizationData() @@ -189,7 +189,7 @@ Lin::readLinearizationData()
189 // Various places in the code use linp.npages, which is initialized from N, to pre-allocate 189 // Various places in the code use linp.npages, which is initialized from N, to pre-allocate
190 // memory, so make sure it's accurate and bail right now if it's not. 190 // memory, so make sure it's accurate and bail right now if it's not.
191 no_ci_stop_if( 191 no_ci_stop_if(
192 - N != qpdf.getAllPages().size(), 192 + N != pages.size(),
193 "/N does not match number of pages", 193 "/N does not match number of pages",
194 "linearization dictionary" // 194 "linearization dictionary" //
195 ); 195 );
@@ -390,20 +390,20 @@ Lin::checkLinearizationInternal() @@ -390,20 +390,20 @@ Lin::checkLinearizationInternal()
390 // L: file size in bytes -- checked by isLinearized 390 // L: file size in bytes -- checked by isLinearized
391 391
392 // O: object number of first page 392 // O: object number of first page
393 - std::vector<QPDFObjectHandle> const& pages = qpdf.getAllPages();  
394 - if (p.first_page_object != pages.at(0).getObjectID()) { 393 + auto const& all_pages = pages.all();
  394 + if (p.first_page_object != all_pages.at(0).getObjectID()) {
395 linearizationWarning("first page object (/O) mismatch"); 395 linearizationWarning("first page object (/O) mismatch");
396 } 396 }
397 397
398 // N: number of pages 398 // N: number of pages
399 - size_t npages = pages.size(); 399 + size_t npages = all_pages.size();
400 if (std::cmp_not_equal(p.npages, npages)) { 400 if (std::cmp_not_equal(p.npages, npages)) {
401 // Not tested in the test suite 401 // Not tested in the test suite
402 linearizationWarning("page count (/N) mismatch"); 402 linearizationWarning("page count (/N) mismatch");
403 } 403 }
404 404
405 int i = 0; 405 int i = 0;
406 - for (auto const& page: pages) { 406 + for (auto const& page: all_pages) {
407 if (m->xref_table[page].getType() == 2) { 407 if (m->xref_table[page].getType() == 2) {
408 linearizationWarning( 408 linearizationWarning(
409 "page dictionary for page " + std::to_string(i) + " is compressed"); 409 "page dictionary for page " + std::to_string(i) + " is compressed");
@@ -485,8 +485,8 @@ Lin::checkLinearizationInternal() @@ -485,8 +485,8 @@ Lin::checkLinearizationInternal()
485 // Check hint tables 485 // Check hint tables
486 486
487 std::map<int, int> shared_idx_to_obj; 487 std::map<int, int> shared_idx_to_obj;
488 - checkHSharedObject(pages, shared_idx_to_obj);  
489 - checkHPageOffset(pages, shared_idx_to_obj); 488 + checkHSharedObject(all_pages, shared_idx_to_obj);
  489 + checkHPageOffset(all_pages, shared_idx_to_obj);
490 checkHOutlines(); 490 checkHOutlines();
491 } 491 }
492 492
@@ -1104,12 +1104,12 @@ Lin::calculateLinearizationData(T const&amp; object_stream_data) @@ -1104,12 +1104,12 @@ Lin::calculateLinearizationData(T const&amp; object_stream_data)
1104 1104
1105 // We seem to traverse the page tree a lot in this code, but we can address this for a future 1105 // We seem to traverse the page tree a lot in this code, but we can address this for a future
1106 // code optimization if necessary. Premature optimization is the root of all evil. 1106 // code optimization if necessary. Premature optimization is the root of all evil.
1107 - std::vector<QPDFObjectHandle> pages; 1107 + std::vector<QPDFObjectHandle> uc_pages;
1108 { // local scope 1108 { // local scope
1109 // Map all page objects to the containing object stream. This should be a no-op in a 1109 // Map all page objects to the containing object stream. This should be a no-op in a
1110 // properly linearized file. 1110 // properly linearized file.
1111 - for (auto oh: qpdf.getAllPages()) {  
1112 - pages.emplace_back(getUncompressedObject(oh, object_stream_data)); 1111 + for (auto oh: pages.all()) {
  1112 + uc_pages.emplace_back(getUncompressedObject(oh, object_stream_data));
1113 } 1113 }
1114 } 1114 }
1115 size_t npages = pages.size(); 1115 size_t npages = pages.size();
@@ -1144,12 +1144,12 @@ Lin::calculateLinearizationData(T const&amp; object_stream_data) @@ -1144,12 +1144,12 @@ Lin::calculateLinearizationData(T const&amp; object_stream_data)
1144 no_ci_stop_if( 1144 no_ci_stop_if(
1145 pages.empty(), "no pages found while calculating linearization data" // 1145 pages.empty(), "no pages found while calculating linearization data" //
1146 ); 1146 );
1147 - QPDFObjGen first_page_og(pages.at(0).getObjGen()); 1147 + QPDFObjGen first_page_og(uc_pages.at(0).getObjGen());
1148 no_ci_stop_if( 1148 no_ci_stop_if(
1149 !lc_first_page_private.erase(first_page_og), "unable to linearize first page" // 1149 !lc_first_page_private.erase(first_page_og), "unable to linearize first page" //
1150 ); 1150 );
1151 - m->c_linp.first_page_object = pages.at(0).getObjectID();  
1152 - m->part6.emplace_back(pages.at(0)); 1151 + m->c_linp.first_page_object = uc_pages.at(0).getObjectID();
  1152 + m->part6.emplace_back(uc_pages.at(0));
1153 1153
1154 // The PDF spec "recommends" an order for the rest of the objects, but we are going to disregard 1154 // The PDF spec "recommends" an order for the rest of the objects, but we are going to disregard
1155 // it except to the extent that it groups private and shared objects contiguously for the sake 1155 // it except to the extent that it groups private and shared objects contiguously for the sake
@@ -1180,13 +1180,13 @@ Lin::calculateLinearizationData(T const&amp; object_stream_data) @@ -1180,13 +1180,13 @@ Lin::calculateLinearizationData(T const&amp; object_stream_data)
1180 for (size_t i = 1; i < npages; ++i) { 1180 for (size_t i = 1; i < npages; ++i) {
1181 // Place this page's page object 1181 // Place this page's page object
1182 1182
1183 - QPDFObjGen page_og(pages.at(i).getObjGen()); 1183 + QPDFObjGen page_og(uc_pages.at(i).getObjGen());
1184 no_ci_stop_if( 1184 no_ci_stop_if(
1185 !lc_other_page_private.erase(page_og), 1185 !lc_other_page_private.erase(page_og),
1186 "unable to linearize page " + std::to_string(i) // 1186 "unable to linearize page " + std::to_string(i) //
1187 ); 1187 );
1188 1188
1189 - m->part7.emplace_back(pages.at(i)); 1189 + m->part7.emplace_back(uc_pages.at(i));
1190 1190
1191 // Place all non-shared objects referenced by this page, updating the page object count for 1191 // Place all non-shared objects referenced by this page, updating the page object count for
1192 // the hint table. 1192 // the hint table.
@@ -1242,7 +1242,7 @@ Lin::calculateLinearizationData(T const&amp; object_stream_data) @@ -1242,7 +1242,7 @@ Lin::calculateLinearizationData(T const&amp; object_stream_data)
1242 // Place private thumbnail images in page order. Slightly more information would be required if 1242 // Place private thumbnail images in page order. Slightly more information would be required if
1243 // we were going to bother with thumbnail hint tables. 1243 // we were going to bother with thumbnail hint tables.
1244 for (size_t i = 0; i < npages; ++i) { 1244 for (size_t i = 0; i < npages; ++i) {
1245 - QPDFObjectHandle thumb = pages.at(i).getKey("/Thumb"); 1245 + QPDFObjectHandle thumb = uc_pages.at(i).getKey("/Thumb");
1246 thumb = getUncompressedObject(thumb, object_stream_data); 1246 thumb = getUncompressedObject(thumb, object_stream_data);
1247 QPDFObjGen thumb_og(thumb.getObjGen()); 1247 QPDFObjGen thumb_og(thumb.getObjGen());
1248 // Output the thumbnail itself 1248 // Output the thumbnail itself
@@ -1439,8 +1439,8 @@ Lin::calculateHPageOffset(QPDFWriter::NewObjTable const&amp; new_obj, QPDFWriter::Ob @@ -1439,8 +1439,8 @@ Lin::calculateHPageOffset(QPDFWriter::NewObjTable const&amp; new_obj, QPDFWriter::Ob
1439 1439
1440 // We are purposely leaving some values set to their initial zero values. 1440 // We are purposely leaving some values set to their initial zero values.
1441 1441
1442 - std::vector<QPDFObjectHandle> const& pages = qpdf.getAllPages();  
1443 - size_t npages = pages.size(); 1442 + auto const& all_pages = pages.all();
  1443 + size_t npages = all_pages.size();
1444 CHPageOffset& cph = m->c_page_offset_data; 1444 CHPageOffset& cph = m->c_page_offset_data;
1445 std::vector<CHPageOffsetEntry>& cphe = cph.entries; 1445 std::vector<CHPageOffsetEntry>& cphe = cph.entries;
1446 1446
@@ -1466,7 +1466,7 @@ Lin::calculateHPageOffset(QPDFWriter::NewObjTable const&amp; new_obj, QPDFWriter::Ob @@ -1466,7 +1466,7 @@ Lin::calculateHPageOffset(QPDFWriter::NewObjTable const&amp; new_obj, QPDFWriter::Ob
1466 // assignments. 1466 // assignments.
1467 1467
1468 int nobjects = cphe.at(i).nobjects; 1468 int nobjects = cphe.at(i).nobjects;
1469 - int length = outputLengthNextN(pages.at(i).getObjectID(), nobjects, new_obj, obj); 1469 + int length = outputLengthNextN(all_pages.at(i).getObjectID(), nobjects, new_obj, obj);
1470 int nshared = cphe.at(i).nshared_objects; 1470 int nshared = cphe.at(i).nshared_objects;
1471 1471
1472 min_nobjects = std::min(min_nobjects, nobjects); 1472 min_nobjects = std::min(min_nobjects, nobjects);
@@ -1482,7 +1482,7 @@ Lin::calculateHPageOffset(QPDFWriter::NewObjTable const&amp; new_obj, QPDFWriter::Ob @@ -1482,7 +1482,7 @@ Lin::calculateHPageOffset(QPDFWriter::NewObjTable const&amp; new_obj, QPDFWriter::Ob
1482 } 1482 }
1483 1483
1484 ph.min_nobjects = min_nobjects; 1484 ph.min_nobjects = min_nobjects;
1485 - ph.first_page_offset = new_obj[obj[pages.at(0)].renumber].xref.getOffset(); 1485 + ph.first_page_offset = new_obj[obj[all_pages.at(0)].renumber].xref.getOffset();
1486 ph.nbits_delta_nobjects = nbits(max_nobjects - min_nobjects); 1486 ph.nbits_delta_nobjects = nbits(max_nobjects - min_nobjects);
1487 ph.min_page_length = min_length; 1487 ph.min_page_length = min_length;
1488 ph.nbits_delta_page_length = nbits(max_length - min_length); 1488 ph.nbits_delta_page_length = nbits(max_length - min_length);
@@ -1631,7 +1631,7 @@ Lin::writeHPageOffset(BitWriter&amp; w) @@ -1631,7 +1631,7 @@ Lin::writeHPageOffset(BitWriter&amp; w)
1631 w.writeBitsInt(t.nbits_shared_numerator, 16); // 12 1631 w.writeBitsInt(t.nbits_shared_numerator, 16); // 12
1632 w.writeBitsInt(t.shared_denominator, 16); // 13 1632 w.writeBitsInt(t.shared_denominator, 16); // 13
1633 1633
1634 - int nitems = toI(qpdf.getAllPages().size()); 1634 + int nitems = toI(pages.size());
1635 std::vector<HPageOffsetEntry>& entries = t.entries; 1635 std::vector<HPageOffsetEntry>& entries = t.entries;
1636 1636
1637 write_vector_int(w, nitems, entries, t.nbits_delta_nobjects, &HPageOffsetEntry::delta_nobjects); 1637 write_vector_int(w, nitems, entries, t.nbits_delta_nobjects, &HPageOffsetEntry::delta_nobjects);