From 0b05111db80469d3f556209bfd856af1fda9b142 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 19 Jun 2018 09:26:41 -0400 Subject: Implement helper class for interactive forms --- libqpdf/QPDFAnnotationObjectHelper.cc | 75 +++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 libqpdf/QPDFAnnotationObjectHelper.cc (limited to 'libqpdf/QPDFAnnotationObjectHelper.cc') 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 +#include + +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(); +} -- cgit v1.2.3-54-g00ecf