diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 2abb4db..9029399 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -2099,22 +2099,22 @@ bool QPDFObjectHandle::isPageObject() const { // See comments in QPDFObjectHandle.hh. - if (getOwningQPDF() == nullptr) { + if (!qpdf()) { return false; } // getAllPages repairs /Type when traversing the page tree. - getOwningQPDF()->getAllPages(); + (void)qpdf()->doc().pages().all(); return isDictionaryOfType("/Page"); } bool QPDFObjectHandle::isPagesObject() const { - if (getOwningQPDF() == nullptr) { + if (!qpdf()) { return false; } // getAllPages repairs /Type when traversing the page tree. - getOwningQPDF()->getAllPages(); + (void)qpdf()->doc().pages().all(); return isDictionaryOfType("/Pages"); } diff --git a/libqpdf/QPDFPageDocumentHelper.cc b/libqpdf/QPDFPageDocumentHelper.cc index 8f1c323..f0b4c33 100644 --- a/libqpdf/QPDFPageDocumentHelper.cc +++ b/libqpdf/QPDFPageDocumentHelper.cc @@ -29,8 +29,10 @@ QPDFPageDocumentHelper::validate(bool repair) std::vector QPDFPageDocumentHelper::getAllPages() { + auto& pp = qpdf.doc().pages(); std::vector pages; - for (auto const& iter: qpdf.getAllPages()) { + pages.reserve(pp.size()); + for (auto const& iter: pp.all()) { pages.emplace_back(iter); } return pages; diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc index e4a61f9..974d486 100644 --- a/libqpdf/QPDF_json.cc +++ b/libqpdf/QPDF_json.cc @@ -466,7 +466,6 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) if (key == "qpdf") { this->saw_qpdf = true; if (!value.isArray()) { - QTC::TC("qpdf", "QPDF_json qpdf not array"); error(value.getStart(), "\"qpdf\" must be an array"); } else { next_state = st_qpdf; @@ -489,7 +488,6 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) } } if (!okay) { - QTC::TC("qpdf", "QPDF_json bad pdf version"); error(value.getStart(), "invalid PDF version (must be \"x.y\")"); } } else if (key == "jsonversion") { @@ -503,7 +501,6 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) } } if (!okay) { - QTC::TC("qpdf", "QPDF_json bad json version"); error(value.getStart(), "invalid JSON version (must be numeric value 2)"); } } else if (key == "pushedinheritedpageresources") { @@ -513,17 +510,15 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) this->pdf.pushInheritedAttributesToPage(); } } else { - QTC::TC("qpdf", "QPDF_json bad pushedinheritedpageresources"); error(value.getStart(), "pushedinheritedpageresources must be a boolean"); } } else if (key == "calledgetallpages") { bool v; if (value.getBool(v)) { if (!this->must_be_complete && v) { - this->pdf.getAllPages(); + (void)pdf.doc().pages().all(); } } else { - QTC::TC("qpdf", "QPDF_json bad calledgetallpages"); error(value.getStart(), "calledgetallpages must be a boolean"); } } else { @@ -544,7 +539,6 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) next_obj = objects.getObjectForJSON(obj, gen); } } else { - QTC::TC("qpdf", "QPDF_json bad object key"); error(value.getStart(), "object key should be \"trailer\" or \"obj:n n R\""); } } else if (state == st_object_top) { @@ -592,7 +586,6 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) } } else if (key == "stream") { // Don't need to set saw_stream here since there's already an error. - QTC::TC("qpdf", "QPDF_json trailer stream"); error(value.getStart(), "the trailer may not be a stream"); } else { // Ignore unknown keys for forward compatibility @@ -618,7 +611,6 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) this->saw_data = true; std::string v; if (!value.getString(v)) { - QTC::TC("qpdf", "QPDF_json stream data not string"); error(value.getStart(), "\"stream.data\" must be a string"); tos.object.replaceStreamData("", {}, {}); } else { diff --git a/libqpdf/QPDF_objects.cc b/libqpdf/QPDF_objects.cc index 0ff6bfc..ea3144b 100644 --- a/libqpdf/QPDF_objects.cc +++ b/libqpdf/QPDF_objects.cc @@ -389,13 +389,11 @@ Objects::reconstruct_xref(QPDFExc& e, bool found_startxref) } check_warnings(); if (!m->parsed) { - m->parsed = true; - qpdf.getAllPages(); - check_warnings(); - if (m->all_pages.empty()) { - m->parsed = false; + m->parsed = !m->pages.empty(); + if (!m->parsed) { throw damagedPDF("", -1, "unable to find any pages while recovering damaged file"); } + check_warnings(); } // We could iterate through the objects looking for streams and try to find objects inside of diff --git a/libqpdf/QPDF_pages.cc b/libqpdf/QPDF_pages.cc index 98c9936..e05a4dc 100644 --- a/libqpdf/QPDF_pages.cc +++ b/libqpdf/QPDF_pages.cc @@ -305,7 +305,7 @@ Pages::pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys) // Calling getAllPages() resolves any duplicated page objects, repairs broken nodes, and detects // loops, so we don't have to do those activities here. - qpdf.getAllPages(); + (void)all(); // key_ancestors is a mapping of page attribute keys to a stack of Pages nodes that contain // values for them. diff --git a/libqpdf/qpdf-c.cc b/libqpdf/qpdf-c.cc index a491218..5740cba 100644 --- a/libqpdf/qpdf-c.cc +++ b/libqpdf/qpdf-c.cc @@ -1,6 +1,6 @@ #include -#include +#include #include #include @@ -1804,10 +1804,9 @@ qpdf_oh_replace_stream_data( int qpdf_get_num_pages(qpdf_data qpdf) { - QTC::TC("qpdf", "qpdf-c called qpdf_num_pages"); int n = -1; QPDF_ERROR_CODE code = - trap_errors(qpdf, [&n](qpdf_data q) { n = QIntC::to_int(q->qpdf->getAllPages().size()); }); + trap_errors(qpdf, [&n](qpdf_data q) { n = QIntC::to_int(q->qpdf->doc().pages().size()); }); if (code & QPDF_ERRORS) { return -1; } @@ -1817,10 +1816,10 @@ qpdf_get_num_pages(qpdf_data qpdf) qpdf_oh qpdf_get_page_n(qpdf_data qpdf, size_t i) { - QTC::TC("qpdf", "qpdf-c called qpdf_get_page_n"); qpdf_oh result = 0; - QPDF_ERROR_CODE code = trap_errors( - qpdf, [&result, i](qpdf_data q) { result = new_object(q, q->qpdf->getAllPages().at(i)); }); + QPDF_ERROR_CODE code = trap_errors(qpdf, [&result, i](qpdf_data q) { + result = new_object(q, q->qpdf->doc().pages().all().at(i)); + }); if ((code & QPDF_ERRORS) || (result == 0)) { return qpdf_oh_new_uninitialized(qpdf); } diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index d73deef..3445a02 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -383,8 +383,6 @@ qpdf-c warn about oh error 1 qpdf-c cleanup warned about unhandled error 0 qpdf-c called qpdf_get_object_by_id 0 qpdf-c called qpdf_replace_object 0 -qpdf-c called qpdf_num_pages 0 -qpdf-c called qpdf_get_page_n 0 qpdf-c called qpdf_update_all_pages_cache 0 qpdf-c called qpdf_find_page_by_id 0 qpdf-c called qpdf_find_page_by_oh 0 @@ -422,10 +420,7 @@ qpdf-c called qpdf_empty_pdf 0 QPDF_json missing qpdf 0 QPDF_json missing pdf version 0 QPDF_json top-level scalar 0 -QPDF_json bad pdf version 0 QPDF_json top-level array 0 -QPDF_json bad object key 0 -QPDF_json trailer stream 0 QPDF_json missing trailer 0 QPDF_json missing objects 0 QPDF_json ignoring in st_ignore 0 @@ -446,17 +441,12 @@ QPDF_json ignore unknown key in stream 0 QPDF_json data and datafile 0 QPDF_json no stream data in update mode 0 QPDF_json updating existing stream 0 -QPDF_json qpdf not array 0 QPDF_json more than two qpdf elements 0 QPDF_json missing json version 0 -QPDF_json bad json version 0 -QPDF_json bad calledgetallpages 0 -QPDF_json bad pushedinheritedpageresources 0 QPDFPageObjectHelper used fallback without copying 0 QPDF skipping cache for known unchecked object 0 QPDF recover xref stream 0 QPDFJob json over/under no file 0 QPDF_Array copy 1 -QPDF_json stream data not string 0 QPDF_json stream datafile not string 0 QPDF_json stream not a dictionary 0