Commit 4c23d2c09459fbf6772800d30e8ace2ee0e4a9aa
1 parent
5ad81ce6
Refactor `QPDF::getAllPages` usage: replace with `Pages::all` across qpdflib.
Showing
7 changed files
with
17 additions
and
36 deletions
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -2099,22 +2099,22 @@ bool |
| 2099 | 2099 | QPDFObjectHandle::isPageObject() const |
| 2100 | 2100 | { |
| 2101 | 2101 | // See comments in QPDFObjectHandle.hh. |
| 2102 | - if (getOwningQPDF() == nullptr) { | |
| 2102 | + if (!qpdf()) { | |
| 2103 | 2103 | return false; |
| 2104 | 2104 | } |
| 2105 | 2105 | // getAllPages repairs /Type when traversing the page tree. |
| 2106 | - getOwningQPDF()->getAllPages(); | |
| 2106 | + (void)qpdf()->doc().pages().all(); | |
| 2107 | 2107 | return isDictionaryOfType("/Page"); |
| 2108 | 2108 | } |
| 2109 | 2109 | |
| 2110 | 2110 | bool |
| 2111 | 2111 | QPDFObjectHandle::isPagesObject() const |
| 2112 | 2112 | { |
| 2113 | - if (getOwningQPDF() == nullptr) { | |
| 2113 | + if (!qpdf()) { | |
| 2114 | 2114 | return false; |
| 2115 | 2115 | } |
| 2116 | 2116 | // getAllPages repairs /Type when traversing the page tree. |
| 2117 | - getOwningQPDF()->getAllPages(); | |
| 2117 | + (void)qpdf()->doc().pages().all(); | |
| 2118 | 2118 | return isDictionaryOfType("/Pages"); |
| 2119 | 2119 | } |
| 2120 | 2120 | ... | ... |
libqpdf/QPDFPageDocumentHelper.cc
| ... | ... | @@ -29,8 +29,10 @@ QPDFPageDocumentHelper::validate(bool repair) |
| 29 | 29 | std::vector<QPDFPageObjectHelper> |
| 30 | 30 | QPDFPageDocumentHelper::getAllPages() |
| 31 | 31 | { |
| 32 | + auto& pp = qpdf.doc().pages(); | |
| 32 | 33 | std::vector<QPDFPageObjectHelper> pages; |
| 33 | - for (auto const& iter: qpdf.getAllPages()) { | |
| 34 | + pages.reserve(pp.size()); | |
| 35 | + for (auto const& iter: pp.all()) { | |
| 34 | 36 | pages.emplace_back(iter); |
| 35 | 37 | } |
| 36 | 38 | return pages; | ... | ... |
libqpdf/QPDF_json.cc
| ... | ... | @@ -466,7 +466,6 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) |
| 466 | 466 | if (key == "qpdf") { |
| 467 | 467 | this->saw_qpdf = true; |
| 468 | 468 | if (!value.isArray()) { |
| 469 | - QTC::TC("qpdf", "QPDF_json qpdf not array"); | |
| 470 | 469 | error(value.getStart(), "\"qpdf\" must be an array"); |
| 471 | 470 | } else { |
| 472 | 471 | next_state = st_qpdf; |
| ... | ... | @@ -489,7 +488,6 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) |
| 489 | 488 | } |
| 490 | 489 | } |
| 491 | 490 | if (!okay) { |
| 492 | - QTC::TC("qpdf", "QPDF_json bad pdf version"); | |
| 493 | 491 | error(value.getStart(), "invalid PDF version (must be \"x.y\")"); |
| 494 | 492 | } |
| 495 | 493 | } else if (key == "jsonversion") { |
| ... | ... | @@ -503,7 +501,6 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) |
| 503 | 501 | } |
| 504 | 502 | } |
| 505 | 503 | if (!okay) { |
| 506 | - QTC::TC("qpdf", "QPDF_json bad json version"); | |
| 507 | 504 | error(value.getStart(), "invalid JSON version (must be numeric value 2)"); |
| 508 | 505 | } |
| 509 | 506 | } else if (key == "pushedinheritedpageresources") { |
| ... | ... | @@ -513,17 +510,15 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) |
| 513 | 510 | this->pdf.pushInheritedAttributesToPage(); |
| 514 | 511 | } |
| 515 | 512 | } else { |
| 516 | - QTC::TC("qpdf", "QPDF_json bad pushedinheritedpageresources"); | |
| 517 | 513 | error(value.getStart(), "pushedinheritedpageresources must be a boolean"); |
| 518 | 514 | } |
| 519 | 515 | } else if (key == "calledgetallpages") { |
| 520 | 516 | bool v; |
| 521 | 517 | if (value.getBool(v)) { |
| 522 | 518 | if (!this->must_be_complete && v) { |
| 523 | - this->pdf.getAllPages(); | |
| 519 | + (void)pdf.doc().pages().all(); | |
| 524 | 520 | } |
| 525 | 521 | } else { |
| 526 | - QTC::TC("qpdf", "QPDF_json bad calledgetallpages"); | |
| 527 | 522 | error(value.getStart(), "calledgetallpages must be a boolean"); |
| 528 | 523 | } |
| 529 | 524 | } else { |
| ... | ... | @@ -544,7 +539,6 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) |
| 544 | 539 | next_obj = objects.getObjectForJSON(obj, gen); |
| 545 | 540 | } |
| 546 | 541 | } else { |
| 547 | - QTC::TC("qpdf", "QPDF_json bad object key"); | |
| 548 | 542 | error(value.getStart(), "object key should be \"trailer\" or \"obj:n n R\""); |
| 549 | 543 | } |
| 550 | 544 | } else if (state == st_object_top) { |
| ... | ... | @@ -592,7 +586,6 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) |
| 592 | 586 | } |
| 593 | 587 | } else if (key == "stream") { |
| 594 | 588 | // Don't need to set saw_stream here since there's already an error. |
| 595 | - QTC::TC("qpdf", "QPDF_json trailer stream"); | |
| 596 | 589 | error(value.getStart(), "the trailer may not be a stream"); |
| 597 | 590 | } else { |
| 598 | 591 | // Ignore unknown keys for forward compatibility |
| ... | ... | @@ -618,7 +611,6 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) |
| 618 | 611 | this->saw_data = true; |
| 619 | 612 | std::string v; |
| 620 | 613 | if (!value.getString(v)) { |
| 621 | - QTC::TC("qpdf", "QPDF_json stream data not string"); | |
| 622 | 614 | error(value.getStart(), "\"stream.data\" must be a string"); |
| 623 | 615 | tos.object.replaceStreamData("", {}, {}); |
| 624 | 616 | } else { | ... | ... |
libqpdf/QPDF_objects.cc
| ... | ... | @@ -389,13 +389,11 @@ Objects::reconstruct_xref(QPDFExc& e, bool found_startxref) |
| 389 | 389 | } |
| 390 | 390 | check_warnings(); |
| 391 | 391 | if (!m->parsed) { |
| 392 | - m->parsed = true; | |
| 393 | - qpdf.getAllPages(); | |
| 394 | - check_warnings(); | |
| 395 | - if (m->all_pages.empty()) { | |
| 396 | - m->parsed = false; | |
| 392 | + m->parsed = !m->pages.empty(); | |
| 393 | + if (!m->parsed) { | |
| 397 | 394 | throw damagedPDF("", -1, "unable to find any pages while recovering damaged file"); |
| 398 | 395 | } |
| 396 | + check_warnings(); | |
| 399 | 397 | } |
| 400 | 398 | |
| 401 | 399 | // We could iterate through the objects looking for streams and try to find objects inside of | ... | ... |
libqpdf/QPDF_pages.cc
| ... | ... | @@ -305,7 +305,7 @@ Pages::pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys) |
| 305 | 305 | |
| 306 | 306 | // Calling getAllPages() resolves any duplicated page objects, repairs broken nodes, and detects |
| 307 | 307 | // loops, so we don't have to do those activities here. |
| 308 | - qpdf.getAllPages(); | |
| 308 | + (void)all(); | |
| 309 | 309 | |
| 310 | 310 | // key_ancestors is a mapping of page attribute keys to a stack of Pages nodes that contain |
| 311 | 311 | // values for them. | ... | ... |
libqpdf/qpdf-c.cc
| 1 | 1 | #include <qpdf/qpdf-c.h> |
| 2 | 2 | |
| 3 | -#include <qpdf/QPDF.hh> | |
| 3 | +#include <qpdf/QPDF_private.hh> | |
| 4 | 4 | |
| 5 | 5 | #include <qpdf/BufferInputSource.hh> |
| 6 | 6 | #include <qpdf/Pl_Buffer.hh> |
| ... | ... | @@ -1804,10 +1804,9 @@ qpdf_oh_replace_stream_data( |
| 1804 | 1804 | int |
| 1805 | 1805 | qpdf_get_num_pages(qpdf_data qpdf) |
| 1806 | 1806 | { |
| 1807 | - QTC::TC("qpdf", "qpdf-c called qpdf_num_pages"); | |
| 1808 | 1807 | int n = -1; |
| 1809 | 1808 | QPDF_ERROR_CODE code = |
| 1810 | - trap_errors(qpdf, [&n](qpdf_data q) { n = QIntC::to_int(q->qpdf->getAllPages().size()); }); | |
| 1809 | + trap_errors(qpdf, [&n](qpdf_data q) { n = QIntC::to_int(q->qpdf->doc().pages().size()); }); | |
| 1811 | 1810 | if (code & QPDF_ERRORS) { |
| 1812 | 1811 | return -1; |
| 1813 | 1812 | } |
| ... | ... | @@ -1817,10 +1816,10 @@ qpdf_get_num_pages(qpdf_data qpdf) |
| 1817 | 1816 | qpdf_oh |
| 1818 | 1817 | qpdf_get_page_n(qpdf_data qpdf, size_t i) |
| 1819 | 1818 | { |
| 1820 | - QTC::TC("qpdf", "qpdf-c called qpdf_get_page_n"); | |
| 1821 | 1819 | qpdf_oh result = 0; |
| 1822 | - QPDF_ERROR_CODE code = trap_errors( | |
| 1823 | - qpdf, [&result, i](qpdf_data q) { result = new_object(q, q->qpdf->getAllPages().at(i)); }); | |
| 1820 | + QPDF_ERROR_CODE code = trap_errors(qpdf, [&result, i](qpdf_data q) { | |
| 1821 | + result = new_object(q, q->qpdf->doc().pages().all().at(i)); | |
| 1822 | + }); | |
| 1824 | 1823 | if ((code & QPDF_ERRORS) || (result == 0)) { |
| 1825 | 1824 | return qpdf_oh_new_uninitialized(qpdf); |
| 1826 | 1825 | } | ... | ... |
qpdf/qpdf.testcov
| ... | ... | @@ -383,8 +383,6 @@ qpdf-c warn about oh error 1 |
| 383 | 383 | qpdf-c cleanup warned about unhandled error 0 |
| 384 | 384 | qpdf-c called qpdf_get_object_by_id 0 |
| 385 | 385 | qpdf-c called qpdf_replace_object 0 |
| 386 | -qpdf-c called qpdf_num_pages 0 | |
| 387 | -qpdf-c called qpdf_get_page_n 0 | |
| 388 | 386 | qpdf-c called qpdf_update_all_pages_cache 0 |
| 389 | 387 | qpdf-c called qpdf_find_page_by_id 0 |
| 390 | 388 | qpdf-c called qpdf_find_page_by_oh 0 |
| ... | ... | @@ -422,10 +420,7 @@ qpdf-c called qpdf_empty_pdf 0 |
| 422 | 420 | QPDF_json missing qpdf 0 |
| 423 | 421 | QPDF_json missing pdf version 0 |
| 424 | 422 | QPDF_json top-level scalar 0 |
| 425 | -QPDF_json bad pdf version 0 | |
| 426 | 423 | QPDF_json top-level array 0 |
| 427 | -QPDF_json bad object key 0 | |
| 428 | -QPDF_json trailer stream 0 | |
| 429 | 424 | QPDF_json missing trailer 0 |
| 430 | 425 | QPDF_json missing objects 0 |
| 431 | 426 | QPDF_json ignoring in st_ignore 0 |
| ... | ... | @@ -446,17 +441,12 @@ QPDF_json ignore unknown key in stream 0 |
| 446 | 441 | QPDF_json data and datafile 0 |
| 447 | 442 | QPDF_json no stream data in update mode 0 |
| 448 | 443 | QPDF_json updating existing stream 0 |
| 449 | -QPDF_json qpdf not array 0 | |
| 450 | 444 | QPDF_json more than two qpdf elements 0 |
| 451 | 445 | QPDF_json missing json version 0 |
| 452 | -QPDF_json bad json version 0 | |
| 453 | -QPDF_json bad calledgetallpages 0 | |
| 454 | -QPDF_json bad pushedinheritedpageresources 0 | |
| 455 | 446 | QPDFPageObjectHelper used fallback without copying 0 |
| 456 | 447 | QPDF skipping cache for known unchecked object 0 |
| 457 | 448 | QPDF recover xref stream 0 |
| 458 | 449 | QPDFJob json over/under no file 0 |
| 459 | 450 | QPDF_Array copy 1 |
| 460 | -QPDF_json stream data not string 0 | |
| 461 | 451 | QPDF_json stream datafile not string 0 |
| 462 | 452 | QPDF_json stream not a dictionary 0 | ... | ... |