diff --git a/libqpdf/QPDFFormFieldObjectHelper.cc b/libqpdf/QPDFFormFieldObjectHelper.cc index a8bd5cd..11efeef 100644 --- a/libqpdf/QPDFFormFieldObjectHelper.cc +++ b/libqpdf/QPDFFormFieldObjectHelper.cc @@ -18,7 +18,7 @@ using namespace qpdf; using FormField = qpdf::impl::FormField; -class QPDFFormFieldObjectHelper::Members: public qpdf::impl::FormField +class QPDFFormFieldObjectHelper::Members: public FormField { public: Members(QPDFObjectHandle const& oh) : @@ -34,44 +34,41 @@ QPDFFormFieldObjectHelper::QPDFFormFieldObjectHelper(QPDFObjectHandle o) : } QPDFFormFieldObjectHelper::QPDFFormFieldObjectHelper() : - QPDFObjectHelper(QPDFObjectHandle::newNull()), - m(std::make_shared(oh())) + QPDFObjectHelper(Null::temp()), + m(std::make_shared(QPDFObjectHandle())) { } bool QPDFFormFieldObjectHelper::isNull() { - return m->isNull(); -} - -bool -FormField::isNull() -{ - return oh().null(); + return m->null(); } QPDFFormFieldObjectHelper QPDFFormFieldObjectHelper::getParent() { - return {m->getParent()}; + return {Null::if_null(m->getParent().oh())}; } FormField FormField::getParent() { - return oh().getKey("/Parent"); // may be null + return {oh()["/Parent"]}; // maybe null } QPDFFormFieldObjectHelper QPDFFormFieldObjectHelper::getTopLevelField(bool* is_different) { - return {m->getTopLevelField(is_different)}; + return Null::if_null(m->getTopLevelField(is_different).oh()); } FormField FormField::getTopLevelField(bool* is_different) { + if (!obj) { + return {}; + } auto top_field = oh(); QPDFObjGen::set seen; while (seen.add(top_field) && !top_field.getKeyIfDict("/Parent").null()) { diff --git a/libqpdf/qpdf/FormField.hh b/libqpdf/qpdf/FormField.hh index af1b2d7..3c7c243 100644 --- a/libqpdf/qpdf/FormField.hh +++ b/libqpdf/qpdf/FormField.hh @@ -12,19 +12,25 @@ namespace qpdf::impl { // This object helper helps with form fields for interactive forms. Please see comments in // QPDFAcroFormDocumentHelper.hh for additional details. - class FormField: public QPDFObjectHelper + class FormField: public qpdf::BaseDictionary { public: - FormField() = delete; + FormField() = default; + FormField(FormField const&) = default; + FormField& operator=(FormField const&) = default; + FormField(FormField&&) = default; + FormField& operator=(FormField&&) = default; + ~FormField() = default; FormField(QPDFObjectHandle const& oh) : - QPDFObjectHelper(oh) + BaseDictionary(oh) { } - ~FormField() override = default; - - bool isNull(); + FormField(QPDFObjectHandle&& oh) : + BaseDictionary(std::move(oh)) + { + } // Return the field's parent. A form field object helper whose underlying object is null is // returned if there is no parent. This condition may be tested by calling isNull().