From 158156d5062a5ac335bcfde7893be4671affdc32 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 3 Jan 2019 19:09:00 -0500 Subject: Add basic appearance stream generation --- include/qpdf/QPDFAcroFormDocumentHelper.hh | 10 ++++++++++ include/qpdf/QPDFFormFieldObjectHelper.hh | 14 ++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'include') diff --git a/include/qpdf/QPDFAcroFormDocumentHelper.hh b/include/qpdf/QPDFAcroFormDocumentHelper.hh index 3a308467..281056b9 100644 --- a/include/qpdf/QPDFAcroFormDocumentHelper.hh +++ b/include/qpdf/QPDFAcroFormDocumentHelper.hh @@ -157,6 +157,16 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper QPDF_DLL void setNeedAppearances(bool); + // If /NeedAppearances is false, do nothing. Otherwise generate + // appearance streams for all widget annotations that need them. + // See comments in QPDFFormFieldObjectHelper.hh for + // generateAppearance for limitations. For checkbox and radio + // button fields, this code ensures that appearance state is + // consistent with the field's value and uses any pre-existing + // appearance streams. + QPDF_DLL + void generateAppearancesIfNeeded(); + private: void analyze(); void traverseField(QPDFObjectHandle field, diff --git a/include/qpdf/QPDFFormFieldObjectHelper.hh b/include/qpdf/QPDFFormFieldObjectHelper.hh index 7ab9a1c0..a03ce555 100644 --- a/include/qpdf/QPDFFormFieldObjectHelper.hh +++ b/include/qpdf/QPDFFormFieldObjectHelper.hh @@ -31,6 +31,8 @@ #include #include +class QPDFAnnotationObjectHelper; + class QPDFFormFieldObjectHelper: public QPDFObjectHelper { public: @@ -179,9 +181,21 @@ class QPDFFormFieldObjectHelper: public QPDFObjectHelper QPDF_DLL void setV(std::string const& utf8_value, bool need_appearances = true); + // Update the appearance stream for this field. Note that qpdf's + // abilitiy to generate appearance streams is limited. We only + // generate appearance streams for streams of type text or choice. + // The appearance uses the default parameters provided in the + // file, and it only supports ASCII characters. Quadding is + // currently ignored. While this functionality is limited, it + // should do a decent job on properly constructed PDF files when + // field values are restricted to ASCII characters. + QPDF_DLL + void generateAppearance(QPDFAnnotationObjectHelper&); + private: void setRadioButtonValue(QPDFObjectHandle name); void setCheckBoxValue(bool value); + void generateTextAppearance(QPDFAnnotationObjectHelper&); class Members { -- cgit v1.2.3-70-g09d2