diff options
author | Jay Berkenbilt <ejb@ql.org> | 2018-06-19 15:26:41 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2018-06-21 21:57:13 +0200 |
commit | 0b05111db80469d3f556209bfd856af1fda9b142 (patch) | |
tree | 46aca07e5984bfda3b284bb70383b11840cb3436 /libqpdf/QPDFAnnotationObjectHelper.cc | |
parent | 0dadf17ab705fa2f96f0513278672978d73601ed (diff) | |
download | qpdf-0b05111db80469d3f556209bfd856af1fda9b142.tar.zst |
Implement helper class for interactive forms
Diffstat (limited to 'libqpdf/QPDFAnnotationObjectHelper.cc')
-rw-r--r-- | libqpdf/QPDFAnnotationObjectHelper.cc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/libqpdf/QPDFAnnotationObjectHelper.cc b/libqpdf/QPDFAnnotationObjectHelper.cc new file mode 100644 index 00000000..ee1d8180 --- /dev/null +++ b/libqpdf/QPDFAnnotationObjectHelper.cc @@ -0,0 +1,75 @@ +#include <qpdf/QPDFAnnotationObjectHelper.hh> +#include <qpdf/QTC.hh> + +QPDFAnnotationObjectHelper::Members::~Members() +{ +} + +QPDFAnnotationObjectHelper::Members::Members() +{ +} + +QPDFAnnotationObjectHelper::QPDFAnnotationObjectHelper(QPDFObjectHandle oh) : + QPDFObjectHelper(oh) +{ +} + +std::string +QPDFAnnotationObjectHelper::getSubtype() +{ + return this->oh.getKey("/Subtype").getName(); +} + +QPDFObjectHandle::Rectangle +QPDFAnnotationObjectHelper::getRect() +{ + return this->oh.getKey("/Rect").getArrayAsRectangle(); +} + +QPDFObjectHandle +QPDFAnnotationObjectHelper::getAppearanceDictionary() +{ + return this->oh.getKey("/AP"); +} + +std::string +QPDFAnnotationObjectHelper::getAppearanceState() +{ + if (this->oh.getKey("/AS").isName()) + { + QTC::TC("qpdf", "QPDFAnnotationObjectHelper AS present"); + return this->oh.getKey("/AS").getName(); + } + QTC::TC("qpdf", "QPDFAnnotationObjectHelper AS absent"); + return ""; +} + +QPDFObjectHandle +QPDFAnnotationObjectHelper::getAppearanceStream( + std::string const& which, + std::string const& state) +{ + QPDFObjectHandle ap = getAppearanceDictionary(); + std::string desired_state = state.empty() ? getAppearanceState() : state; + if (ap.isDictionary()) + { + QPDFObjectHandle ap_sub = ap.getKey(which); + if (ap_sub.isStream() && desired_state.empty()) + { + QTC::TC("qpdf", "QPDFAnnotationObjectHelper AP stream"); + return ap_sub; + } + if (ap_sub.isDictionary() && (! desired_state.empty())) + { + QTC::TC("qpdf", "QPDFAnnotationObjectHelper AP dictionary"); + QPDFObjectHandle ap_sub_val = ap_sub.getKey(desired_state); + if (ap_sub_val.isStream()) + { + QTC::TC("qpdf", "QPDFAnnotationObjectHelper AN sub stream"); + return ap_sub_val; + } + } + } + QTC::TC("qpdf", "QPDFAnnotationObjectHelper AN null"); + return QPDFObjectHandle::newNull(); +} |