Commit 81510829f126c6c050b414f9992b9c8cb24dc832

Authored by m-holger
1 parent faed776c

Enhance `QPDFAcroFormDocumentHelper` with `get()` for shared access and `validat…

…e()` for re-validation and repair of AcroForm structure.
include/qpdf/QPDFAcroFormDocumentHelper.hh
@@ -68,6 +68,21 @@ @@ -68,6 +68,21 @@
68 class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper 68 class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper
69 { 69 {
70 public: 70 public:
  71 + // Get a shared document helper for a given QPDF object.
  72 + //
  73 + // Retrieving a document helper for a QPDF object rather than creating a new one avoids repeated
  74 + // validation of the Acroform structure, which can be expensive.
  75 + QPDF_DLL
  76 + static QPDFAcroFormDocumentHelper& get(QPDF& qpdf);
  77 +
  78 + // Re-validate the AcroForm structure. This is useful if you have modified the structure of the
  79 + // AcroForm dictionary in a way that would invalidate the cache.
  80 + //
  81 + // If repair is true, the document will be repaired if possible if the validation encounters
  82 + // errors.
  83 + QPDF_DLL
  84 + void validate(bool repair = true);
  85 +
71 QPDF_DLL 86 QPDF_DLL
72 QPDFAcroFormDocumentHelper(QPDF&); 87 QPDFAcroFormDocumentHelper(QPDF&);
73 88
libqpdf/QPDFAcroFormDocumentHelper.cc
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 #include <qpdf/Pl_Buffer.hh> 3 #include <qpdf/Pl_Buffer.hh>
4 #include <qpdf/QPDFObjectHandle_private.hh> 4 #include <qpdf/QPDFObjectHandle_private.hh>
5 #include <qpdf/QPDFPageDocumentHelper.hh> 5 #include <qpdf/QPDFPageDocumentHelper.hh>
  6 +#include <qpdf/QPDF_private.hh>
6 #include <qpdf/QTC.hh> 7 #include <qpdf/QTC.hh>
7 #include <qpdf/QUtil.hh> 8 #include <qpdf/QUtil.hh>
8 #include <qpdf/ResourceFinder.hh> 9 #include <qpdf/ResourceFinder.hh>
@@ -21,6 +22,19 @@ QPDFAcroFormDocumentHelper::QPDFAcroFormDocumentHelper(QPDF&amp; qpdf) : @@ -21,6 +22,19 @@ QPDFAcroFormDocumentHelper::QPDFAcroFormDocumentHelper(QPDF&amp; qpdf) :
21 analyze(); 22 analyze();
22 } 23 }
23 24
  25 +QPDFAcroFormDocumentHelper&
  26 +QPDFAcroFormDocumentHelper::get(QPDF& qpdf)
  27 +{
  28 + return qpdf.acroform();
  29 +}
  30 +
  31 +void
  32 +QPDFAcroFormDocumentHelper::validate(bool repair)
  33 +{
  34 + invalidateCache();
  35 + analyze();
  36 +}
  37 +
24 void 38 void
25 QPDFAcroFormDocumentHelper::invalidateCache() 39 QPDFAcroFormDocumentHelper::invalidateCache()
26 { 40 {