Commit 988a63cc416efa6a2ddadab943e2a423a0292479
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.
Showing
3 changed files
with
6 additions
and
11 deletions
libqpdf/QPDF_optimization.cc
| ... | ... | @@ -215,15 +215,13 @@ QPDF::pushInheritedAttributesToPageInternal( |
| 215 | 215 | } |
| 216 | 216 | // Remove this resource from this node. It will be reattached at the page level. |
| 217 | 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 | 219 | // Warn when flattening, but not if the key is at the top level (i.e. "/Parent" not |
| 221 | 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 | 222 | warn( |
| 225 | 223 | qpdf_e_pages, |
| 226 | - m->last_object_description, | |
| 224 | + "Pages object: object " + cur_pages.id_gen().unparse(' '), | |
| 227 | 225 | 0, |
| 228 | 226 | ("Unknown key " + key + |
| 229 | 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 | 288 | if (check_duplicate) { |
| 289 | 289 | if (!m->pageobj_to_pages_pos.insert(std::make_pair(og, pos)).second) { |
| 290 | 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 | 291 | throw QPDFExc( |
| 294 | 292 | qpdf_e_pages, |
| 295 | 293 | m->file->getName(), |
| 296 | - m->last_object_description, | |
| 294 | + "page " + std::to_string(pos) + " (numbered from zero): object " + og.unparse(' '), | |
| 297 | 295 | 0, |
| 298 | 296 | "duplicate page reference found; this would cause loss of data"); |
| 299 | 297 | } |
| ... | ... | @@ -407,11 +405,10 @@ QPDF::findPage(QPDFObjGen og) |
| 407 | 405 | flattenPagesTree(); |
| 408 | 406 | auto it = m->pageobj_to_pages_pos.find(og); |
| 409 | 407 | if (it == m->pageobj_to_pages_pos.end()) { |
| 410 | - m->objects.setLastObjectDescription("page object", og); | |
| 411 | 408 | throw QPDFExc( |
| 412 | 409 | qpdf_e_pages, |
| 413 | 410 | m->file->getName(), |
| 414 | - m->last_object_description, | |
| 411 | + "page object: object " + og.unparse(' '), | |
| 415 | 412 | 0, |
| 416 | 413 | "page object not referenced in /Pages tree"); |
| 417 | 414 | } | ... | ... |
libqpdf/qpdf/QPDF_private.hh
| ... | ... | @@ -490,7 +490,6 @@ class QPDF::Doc |
| 490 | 490 | std::shared_ptr<QPDFObject> getObjectForParser(int id, int gen, bool parse_pdf); |
| 491 | 491 | std::shared_ptr<QPDFObject> getObjectForJSON(int id, int gen); |
| 492 | 492 | size_t tableSize(); |
| 493 | - void setLastObjectDescription(std::string const& description, QPDFObjGen og); | |
| 494 | 493 | |
| 495 | 494 | // For QPDFWriter: |
| 496 | 495 | |
| ... | ... | @@ -541,6 +540,7 @@ class QPDF::Doc |
| 541 | 540 | void resolveObjectsInStream(int obj_stream_number); |
| 542 | 541 | bool isCached(QPDFObjGen og); |
| 543 | 542 | bool isUnresolved(QPDFObjGen og); |
| 543 | + void setLastObjectDescription(std::string const& description, QPDFObjGen og); | |
| 544 | 544 | |
| 545 | 545 | private: |
| 546 | 546 | QPDF& qpdf; | ... | ... |