Commit e64965e31be2e3b7059a9b8fe31bb345bddb4e2f
1 parent
79a9701f
Refactor `QPDF`: centralize access to `QPDFAcroFormDocumentHelper` using a dedic…
…ated `acroform()` method and update related references for improved performance, consistency and maintainability.
Showing
5 changed files
with
21 additions
and
4 deletions
include/qpdf/QPDF.hh
| ... | ... | @@ -57,6 +57,7 @@ class BitWriter; |
| 57 | 57 | class BufferInputSource; |
| 58 | 58 | class QPDFLogger; |
| 59 | 59 | class QPDFParser; |
| 60 | +class QPDFAcroFormDocumentHelper; | |
| 60 | 61 | |
| 61 | 62 | class QPDF |
| 62 | 63 | { |
| ... | ... | @@ -792,6 +793,7 @@ class QPDF |
| 792 | 793 | class JobSetter; |
| 793 | 794 | |
| 794 | 795 | inline bool reconstructed_xref() const; |
| 796 | + inline QPDFAcroFormDocumentHelper& acroform(); | |
| 795 | 797 | |
| 796 | 798 | // For testing only -- do not add to DLL |
| 797 | 799 | static bool test_json_validators(); | ... | ... |
libqpdf/QPDFFormFieldObjectHelper.cc
| ... | ... | @@ -5,6 +5,7 @@ |
| 5 | 5 | #include <qpdf/QPDFAcroFormDocumentHelper.hh> |
| 6 | 6 | #include <qpdf/QPDFAnnotationObjectHelper.hh> |
| 7 | 7 | #include <qpdf/QPDFObjectHandle_private.hh> |
| 8 | +#include <qpdf/QPDF_private.hh> | |
| 8 | 9 | #include <qpdf/QTC.hh> |
| 9 | 10 | #include <qpdf/QUtil.hh> |
| 10 | 11 | #include <cstdlib> |
| ... | ... | @@ -337,7 +338,7 @@ QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances) |
| 337 | 338 | QPDF& qpdf = oh().getQPDF( |
| 338 | 339 | "QPDFFormFieldObjectHelper::setV called with need_appearances = " |
| 339 | 340 | "true on an object that is not associated with an owning QPDF"); |
| 340 | - QPDFAcroFormDocumentHelper(qpdf).setNeedAppearances(true); | |
| 341 | + qpdf.acroform().setNeedAppearances(true); | |
| 341 | 342 | } |
| 342 | 343 | } |
| 343 | 344 | ... | ... |
libqpdf/QPDFJob.cc
| ... | ... | @@ -1180,7 +1180,7 @@ void |
| 1180 | 1180 | QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf) |
| 1181 | 1181 | { |
| 1182 | 1182 | JSON j_acroform = JSON::makeDictionary(); |
| 1183 | - QPDFAcroFormDocumentHelper afdh(pdf); | |
| 1183 | + auto& afdh = pdf.acroform(); | |
| 1184 | 1184 | j_acroform.addDictionaryMember("hasacroform", JSON::makeBool(afdh.hasAcroForm())); |
| 1185 | 1185 | j_acroform.addDictionaryMember("needappearances", JSON::makeBool(afdh.getNeedAppearances())); |
| 1186 | 1186 | JSON j_fields = j_acroform.addDictionaryMember("fields", JSON::makeArray()); |
| ... | ... | @@ -3013,7 +3013,7 @@ QPDFJob::doSplitPages(QPDF& pdf) |
| 3013 | 3013 | dh.removeUnreferencedResources(); |
| 3014 | 3014 | } |
| 3015 | 3015 | QPDFPageLabelDocumentHelper pldh(pdf); |
| 3016 | - QPDFAcroFormDocumentHelper afdh(pdf); | |
| 3016 | + auto& afdh = pdf.acroform(); | |
| 3017 | 3017 | std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages(); |
| 3018 | 3018 | size_t pageno_len = std::to_string(pages.size()).length(); |
| 3019 | 3019 | size_t num_pages = pages.size(); | ... | ... |
libqpdf/QPDFPageDocumentHelper.cc
| 1 | 1 | #include <qpdf/QPDFPageDocumentHelper.hh> |
| 2 | 2 | |
| 3 | 3 | #include <qpdf/QPDFAcroFormDocumentHelper.hh> |
| 4 | +#include <qpdf/QPDF_private.hh> | |
| 4 | 5 | #include <qpdf/QTC.hh> |
| 5 | 6 | #include <qpdf/QUtil.hh> |
| 6 | 7 | |
| ... | ... | @@ -55,7 +56,7 @@ QPDFPageDocumentHelper::removePage(QPDFPageObjectHelper page) |
| 55 | 56 | void |
| 56 | 57 | QPDFPageDocumentHelper::flattenAnnotations(int required_flags, int forbidden_flags) |
| 57 | 58 | { |
| 58 | - QPDFAcroFormDocumentHelper afdh(qpdf); | |
| 59 | + auto& afdh = qpdf.acroform(); | |
| 59 | 60 | if (afdh.getNeedAppearances()) { |
| 60 | 61 | qpdf.getRoot() |
| 61 | 62 | .getKey("/AcroForm") | ... | ... |
libqpdf/qpdf/QPDF_private.hh
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | |
| 4 | 4 | #include <qpdf/QPDF.hh> |
| 5 | 5 | |
| 6 | +#include <qpdf/QPDFAcroFormDocumentHelper.hh> | |
| 6 | 7 | #include <qpdf/QPDFObject_private.hh> |
| 7 | 8 | #include <qpdf/QPDFTokenizer_private.hh> |
| 8 | 9 | |
| ... | ... | @@ -547,6 +548,9 @@ class QPDF::Members |
| 547 | 548 | // Optimization data |
| 548 | 549 | std::map<ObjUser, std::set<QPDFObjGen>> obj_user_to_objects; |
| 549 | 550 | std::map<QPDFObjGen, std::set<ObjUser>> object_to_obj_users; |
| 551 | + | |
| 552 | + // Document Helpers; | |
| 553 | + std::unique_ptr<QPDFAcroFormDocumentHelper> acroform; | |
| 550 | 554 | }; |
| 551 | 555 | |
| 552 | 556 | // JobSetter class is restricted to QPDFJob. |
| ... | ... | @@ -569,4 +573,13 @@ QPDF::reconstructed_xref() const |
| 569 | 573 | return m->reconstructed_xref; |
| 570 | 574 | } |
| 571 | 575 | |
| 576 | +inline QPDFAcroFormDocumentHelper& | |
| 577 | +QPDF::acroform() | |
| 578 | +{ | |
| 579 | + if (!m->acroform) { | |
| 580 | + m->acroform = std::make_unique<QPDFAcroFormDocumentHelper>(*this); | |
| 581 | + } | |
| 582 | + return *m->acroform; | |
| 583 | +} | |
| 584 | + | |
| 572 | 585 | #endif // QPDF_PRIVATE_HH | ... | ... |