Commit 3f43b1878800eb2cde4e665a3c384f2bea15e406
1 parent
6ad83cfd
Refactor FormField class: replace inheritance from QPDFObjectHelper with BaseDic…
…tionary, modernize constructors, and clean up null handling logic.
Showing
2 changed files
with
22 additions
and
19 deletions
libqpdf/QPDFFormFieldObjectHelper.cc
| @@ -18,7 +18,7 @@ using namespace qpdf; | @@ -18,7 +18,7 @@ using namespace qpdf; | ||
| 18 | 18 | ||
| 19 | using FormField = qpdf::impl::FormField; | 19 | using FormField = qpdf::impl::FormField; |
| 20 | 20 | ||
| 21 | -class QPDFFormFieldObjectHelper::Members: public qpdf::impl::FormField | 21 | +class QPDFFormFieldObjectHelper::Members: public FormField |
| 22 | { | 22 | { |
| 23 | public: | 23 | public: |
| 24 | Members(QPDFObjectHandle const& oh) : | 24 | Members(QPDFObjectHandle const& oh) : |
| @@ -34,44 +34,41 @@ QPDFFormFieldObjectHelper::QPDFFormFieldObjectHelper(QPDFObjectHandle o) : | @@ -34,44 +34,41 @@ QPDFFormFieldObjectHelper::QPDFFormFieldObjectHelper(QPDFObjectHandle o) : | ||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | QPDFFormFieldObjectHelper::QPDFFormFieldObjectHelper() : | 36 | QPDFFormFieldObjectHelper::QPDFFormFieldObjectHelper() : |
| 37 | - QPDFObjectHelper(QPDFObjectHandle::newNull()), | ||
| 38 | - m(std::make_shared<Members>(oh())) | 37 | + QPDFObjectHelper(Null::temp()), |
| 38 | + m(std::make_shared<Members>(QPDFObjectHandle())) | ||
| 39 | { | 39 | { |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | bool | 42 | bool |
| 43 | QPDFFormFieldObjectHelper::isNull() | 43 | QPDFFormFieldObjectHelper::isNull() |
| 44 | { | 44 | { |
| 45 | - return m->isNull(); | ||
| 46 | -} | ||
| 47 | - | ||
| 48 | -bool | ||
| 49 | -FormField::isNull() | ||
| 50 | -{ | ||
| 51 | - return oh().null(); | 45 | + return m->null(); |
| 52 | } | 46 | } |
| 53 | 47 | ||
| 54 | QPDFFormFieldObjectHelper | 48 | QPDFFormFieldObjectHelper |
| 55 | QPDFFormFieldObjectHelper::getParent() | 49 | QPDFFormFieldObjectHelper::getParent() |
| 56 | { | 50 | { |
| 57 | - return {m->getParent()}; | 51 | + return {Null::if_null(m->getParent().oh())}; |
| 58 | } | 52 | } |
| 59 | 53 | ||
| 60 | FormField | 54 | FormField |
| 61 | FormField::getParent() | 55 | FormField::getParent() |
| 62 | { | 56 | { |
| 63 | - return oh().getKey("/Parent"); // may be null | 57 | + return {oh()["/Parent"]}; // maybe null |
| 64 | } | 58 | } |
| 65 | 59 | ||
| 66 | QPDFFormFieldObjectHelper | 60 | QPDFFormFieldObjectHelper |
| 67 | QPDFFormFieldObjectHelper::getTopLevelField(bool* is_different) | 61 | QPDFFormFieldObjectHelper::getTopLevelField(bool* is_different) |
| 68 | { | 62 | { |
| 69 | - return {m->getTopLevelField(is_different)}; | 63 | + return Null::if_null(m->getTopLevelField(is_different).oh()); |
| 70 | } | 64 | } |
| 71 | 65 | ||
| 72 | FormField | 66 | FormField |
| 73 | FormField::getTopLevelField(bool* is_different) | 67 | FormField::getTopLevelField(bool* is_different) |
| 74 | { | 68 | { |
| 69 | + if (!obj) { | ||
| 70 | + return {}; | ||
| 71 | + } | ||
| 75 | auto top_field = oh(); | 72 | auto top_field = oh(); |
| 76 | QPDFObjGen::set seen; | 73 | QPDFObjGen::set seen; |
| 77 | while (seen.add(top_field) && !top_field.getKeyIfDict("/Parent").null()) { | 74 | while (seen.add(top_field) && !top_field.getKeyIfDict("/Parent").null()) { |
libqpdf/qpdf/FormField.hh
| @@ -12,19 +12,25 @@ namespace qpdf::impl | @@ -12,19 +12,25 @@ namespace qpdf::impl | ||
| 12 | { | 12 | { |
| 13 | // This object helper helps with form fields for interactive forms. Please see comments in | 13 | // This object helper helps with form fields for interactive forms. Please see comments in |
| 14 | // QPDFAcroFormDocumentHelper.hh for additional details. | 14 | // QPDFAcroFormDocumentHelper.hh for additional details. |
| 15 | - class FormField: public QPDFObjectHelper | 15 | + class FormField: public qpdf::BaseDictionary |
| 16 | { | 16 | { |
| 17 | public: | 17 | public: |
| 18 | - FormField() = delete; | 18 | + FormField() = default; |
| 19 | + FormField(FormField const&) = default; | ||
| 20 | + FormField& operator=(FormField const&) = default; | ||
| 21 | + FormField(FormField&&) = default; | ||
| 22 | + FormField& operator=(FormField&&) = default; | ||
| 23 | + ~FormField() = default; | ||
| 19 | 24 | ||
| 20 | FormField(QPDFObjectHandle const& oh) : | 25 | FormField(QPDFObjectHandle const& oh) : |
| 21 | - QPDFObjectHelper(oh) | 26 | + BaseDictionary(oh) |
| 22 | { | 27 | { |
| 23 | } | 28 | } |
| 24 | 29 | ||
| 25 | - ~FormField() override = default; | ||
| 26 | - | ||
| 27 | - bool isNull(); | 30 | + FormField(QPDFObjectHandle&& oh) : |
| 31 | + BaseDictionary(std::move(oh)) | ||
| 32 | + { | ||
| 33 | + } | ||
| 28 | 34 | ||
| 29 | // Return the field's parent. A form field object helper whose underlying object is null is | 35 | // Return the field's parent. A form field object helper whose underlying object is null is |
| 30 | // returned if there is no parent. This condition may be tested by calling isNull(). | 36 | // returned if there is no parent. This condition may be tested by calling isNull(). |