diff options
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/QPDFAnnotationObjectHelper.cc | 21 | ||||
-rw-r--r-- | libqpdf/QPDFPageDocumentHelper.cc | 30 |
2 files changed, 38 insertions, 13 deletions
diff --git a/libqpdf/QPDFAnnotationObjectHelper.cc b/libqpdf/QPDFAnnotationObjectHelper.cc index ca4af907..3295fd3a 100644 --- a/libqpdf/QPDFAnnotationObjectHelper.cc +++ b/libqpdf/QPDFAnnotationObjectHelper.cc @@ -81,7 +81,8 @@ QPDFAnnotationObjectHelper::getAppearanceStream( std::string QPDFAnnotationObjectHelper::getPageContentForAppearance( - std::string const& name, int rotate) + std::string const& name, int rotate, + int required_flags, int forbidden_flags) { if (! getAppearanceStream("/N").isStream()) { @@ -168,11 +169,24 @@ QPDFAnnotationObjectHelper::getPageContentForAppearance( // appearance matrix. QPDFObjectHandle rect_obj = this->oh.getKey("/Rect"); - QPDFObjectHandle flags = this->oh.getKey("/F"); + QPDFObjectHandle flags_obj = this->oh.getKey("/F"); QPDFObjectHandle as = getAppearanceStream("/N").getDict(); QPDFObjectHandle bbox_obj = as.getKey("/BBox"); QPDFObjectHandle matrix_obj = as.getKey("/Matrix"); + int flags = flags_obj.isInteger() ? flags_obj.getIntValue() : 0; + + if (flags & forbidden_flags) + { + QTC::TC("qpdf", "QPDFAnnotationObjectHelper forbidden flags"); + return ""; + } + if ((flags & required_flags) != required_flags) + { + QTC::TC("qpdf", "QPDFAnnotationObjectHelper missing required flags"); + return ""; + } + if (! (bbox_obj.isRectangle() && rect_obj.isRectangle())) { return ""; @@ -188,8 +202,7 @@ QPDFAnnotationObjectHelper::getPageContentForAppearance( QTC::TC("qpdf", "QPDFAnnotationObjectHelper default matrix"); } QPDFObjectHandle::Rectangle rect = rect_obj.getArrayAsRectangle(); - bool do_rotate = (rotate && flags.isInteger() && - (flags.getIntValue() & 16)); + bool do_rotate = (rotate && (flags & an_no_rotate)); if (do_rotate) { // If the the annotation flags include the NoRotate bit and diff --git a/libqpdf/QPDFPageDocumentHelper.cc b/libqpdf/QPDFPageDocumentHelper.cc index d168f8de..1dacd672 100644 --- a/libqpdf/QPDFPageDocumentHelper.cc +++ b/libqpdf/QPDFPageDocumentHelper.cc @@ -68,7 +68,9 @@ QPDFPageDocumentHelper::removePage(QPDFPageObjectHelper page) void -QPDFPageDocumentHelper::flattenAnnotations() +QPDFPageDocumentHelper::flattenAnnotations( + int required_flags, + int forbidden_flags) { QPDFAcroFormDocumentHelper afdh(this->qpdf); if (afdh.getNeedAppearances()) @@ -97,7 +99,8 @@ QPDFPageDocumentHelper::flattenAnnotations() // test suite resources = QPDFObjectHandle::newDictionary(); } - flattenAnnotationsForPage(ph, resources, afdh); + flattenAnnotationsForPage(ph, resources, afdh, + required_flags, forbidden_flags); } if (! afdh.getNeedAppearances()) { @@ -109,7 +112,9 @@ void QPDFPageDocumentHelper::flattenAnnotationsForPage( QPDFPageObjectHelper& page, QPDFObjectHandle& resources, - QPDFAcroFormDocumentHelper& afdh) + QPDFAcroFormDocumentHelper& afdh, + int required_flags, + int forbidden_flags) { bool need_appearances = afdh.getNeedAppearances(); std::vector<QPDFAnnotationObjectHelper> annots = page.getAnnotations(); @@ -168,12 +173,12 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( while (next_fx <= max_fx) { std::string candidate = "/Fxo" + QUtil::int_to_string(next_fx); - ++next_fx; if (names.count(candidate) == 0) { name = candidate; break; } + ++next_fx; } if (name.empty()) { @@ -182,11 +187,18 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( // number of keys we're checking against. name = "/FxConflict"; } - resources.mergeResources( - QPDFObjectHandle::parse( - "<< /XObject << " + name + " null >> >>")); - resources.getKey("/XObject").replaceKey(name, as); - new_content += aoh.getPageContentForAppearance(name, rotate); + std::string content = aoh.getPageContentForAppearance( + name, rotate, required_flags, forbidden_flags); + if (! content.empty()) + { + resources.mergeResources( + QPDFObjectHandle::parse( + "<< /XObject << " + name + " null >> >>")); + resources.getKey("/XObject").replaceKey(name, as); + names.insert(name); + ++next_fx; + } + new_content += content; } else { |