Commit 988a63cc416efa6a2ddadab943e2a423a0292479

Authored by m-holger
1 parent e0ebf44f

Refactor `setLastObjectDescription` usage and move to private section

Streamline `setLastObjectDescription` usage by consolidating string construction at call sites. Relocate method to the private section to improve encapsulation and restrict access.
libqpdf/QPDF_optimization.cc
@@ -215,15 +215,13 @@ QPDF::pushInheritedAttributesToPageInternal( @@ -215,15 +215,13 @@ QPDF::pushInheritedAttributesToPageInternal(
215 } 215 }
216 // Remove this resource from this node. It will be reattached at the page level. 216 // Remove this resource from this node. It will be reattached at the page level.
217 cur_pages.removeKey(key); 217 cur_pages.removeKey(key);
218 - } else if (!((key == "/Type") || (key == "/Parent") || (key == "/Kids") ||  
219 - (key == "/Count"))) { 218 + } else if (!(key == "/Type" || key == "/Parent" || key == "/Kids" || key == "/Count")) {
220 // Warn when flattening, but not if the key is at the top level (i.e. "/Parent" not 219 // Warn when flattening, but not if the key is at the top level (i.e. "/Parent" not
221 // set), as we don't change these; but flattening removes intermediate /Pages nodes. 220 // set), as we don't change these; but flattening removes intermediate /Pages nodes.
222 - if ((warn_skipped_keys) && (cur_pages.hasKey("/Parent"))) {  
223 - m->objects.setLastObjectDescription("Pages object", cur_pages.getObjGen()); 221 + if (warn_skipped_keys && cur_pages.hasKey("/Parent")) {
224 warn( 222 warn(
225 qpdf_e_pages, 223 qpdf_e_pages,
226 - m->last_object_description, 224 + "Pages object: object " + cur_pages.id_gen().unparse(' '),
227 0, 225 0,
228 ("Unknown key " + key + 226 ("Unknown key " + key +
229 " in /Pages object is being discarded as a result of flattening the /Pages " 227 " in /Pages object is being discarded as a result of flattening the /Pages "
libqpdf/QPDF_pages.cc
@@ -288,12 +288,10 @@ QPDF::insertPageobjToPage(QPDFObjectHandle const& obj, int pos, bool check_dupli @@ -288,12 +288,10 @@ QPDF::insertPageobjToPage(QPDFObjectHandle const& obj, int pos, bool check_dupli
288 if (check_duplicate) { 288 if (check_duplicate) {
289 if (!m->pageobj_to_pages_pos.insert(std::make_pair(og, pos)).second) { 289 if (!m->pageobj_to_pages_pos.insert(std::make_pair(og, pos)).second) {
290 // The library never calls insertPageobjToPage in a way that causes this to happen. 290 // The library never calls insertPageobjToPage in a way that causes this to happen.
291 - m->objects.setLastObjectDescription(  
292 - "page " + std::to_string(pos) + " (numbered from zero)", og);  
293 throw QPDFExc( 291 throw QPDFExc(
294 qpdf_e_pages, 292 qpdf_e_pages,
295 m->file->getName(), 293 m->file->getName(),
296 - m->last_object_description, 294 + "page " + std::to_string(pos) + " (numbered from zero): object " + og.unparse(' '),
297 0, 295 0,
298 "duplicate page reference found; this would cause loss of data"); 296 "duplicate page reference found; this would cause loss of data");
299 } 297 }
@@ -407,11 +405,10 @@ QPDF::findPage(QPDFObjGen og) @@ -407,11 +405,10 @@ QPDF::findPage(QPDFObjGen og)
407 flattenPagesTree(); 405 flattenPagesTree();
408 auto it = m->pageobj_to_pages_pos.find(og); 406 auto it = m->pageobj_to_pages_pos.find(og);
409 if (it == m->pageobj_to_pages_pos.end()) { 407 if (it == m->pageobj_to_pages_pos.end()) {
410 - m->objects.setLastObjectDescription("page object", og);  
411 throw QPDFExc( 408 throw QPDFExc(
412 qpdf_e_pages, 409 qpdf_e_pages,
413 m->file->getName(), 410 m->file->getName(),
414 - m->last_object_description, 411 + "page object: object " + og.unparse(' '),
415 0, 412 0,
416 "page object not referenced in /Pages tree"); 413 "page object not referenced in /Pages tree");
417 } 414 }
libqpdf/qpdf/QPDF_private.hh
@@ -490,7 +490,6 @@ class QPDF::Doc @@ -490,7 +490,6 @@ class QPDF::Doc
490 std::shared_ptr<QPDFObject> getObjectForParser(int id, int gen, bool parse_pdf); 490 std::shared_ptr<QPDFObject> getObjectForParser(int id, int gen, bool parse_pdf);
491 std::shared_ptr<QPDFObject> getObjectForJSON(int id, int gen); 491 std::shared_ptr<QPDFObject> getObjectForJSON(int id, int gen);
492 size_t tableSize(); 492 size_t tableSize();
493 - void setLastObjectDescription(std::string const& description, QPDFObjGen og);  
494 493
495 // For QPDFWriter: 494 // For QPDFWriter:
496 495
@@ -541,6 +540,7 @@ class QPDF::Doc @@ -541,6 +540,7 @@ class QPDF::Doc
541 void resolveObjectsInStream(int obj_stream_number); 540 void resolveObjectsInStream(int obj_stream_number);
542 bool isCached(QPDFObjGen og); 541 bool isCached(QPDFObjGen og);
543 bool isUnresolved(QPDFObjGen og); 542 bool isUnresolved(QPDFObjGen og);
  543 + void setLastObjectDescription(std::string const& description, QPDFObjGen og);
544 544
545 private: 545 private:
546 QPDF& qpdf; 546 QPDF& qpdf;