From 133ed96f8f4f8efca120a893a62e9df20639f5b1 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Wed, 25 Oct 2023 09:41:22 +0200 Subject: [PATCH] Don't take into account the INVISIBLE flag for well-known annotations --- src/core/annotation.js | 15 ++++++++++++++- test/pdfs/issue17169.pdf.link | 1 + test/test_manifest.json | 8 ++++++++ test/unit/annotation_spec.js | 4 ++-- 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 test/pdfs/issue17169.pdf.link diff --git a/src/core/annotation.js b/src/core/annotation.js index d1516a71a..6d78ea384 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -838,6 +838,17 @@ class Annotation { */ setFlags(flags) { this.flags = Number.isInteger(flags) && flags > 0 ? flags : 0; + if ( + this.flags & AnnotationFlag.INVISIBLE && + this.constructor.name !== "Annotation" + ) { + // From the pdf spec v1.7, section 12.5.3 (Annotation Flags): + // If set, do not display the annotation if it does not belong to one of + // the standard annotation types and no annotation handler is available. + // + // So we can remove the flag in case we have a known annotation type. + this.flags ^= AnnotationFlag.INVISIBLE; + } } /** @@ -1817,7 +1828,9 @@ class WidgetAnnotation extends Annotation { // since the visibility can be changed by js code, hence in case // it's made viewable, we should render it (with visibility set to // hidden). - return !this._hasFlag(flags, AnnotationFlag.INVISIBLE); + // We don't take into account the `INVISIBLE` flag here, since we've a known + // annotation type. + return true; } /** @inheritdoc */ diff --git a/test/pdfs/issue17169.pdf.link b/test/pdfs/issue17169.pdf.link new file mode 100644 index 000000000..db14c73fa --- /dev/null +++ b/test/pdfs/issue17169.pdf.link @@ -0,0 +1 @@ +https://github.com/mozilla/pdf.js/files/13161366/stamp-signature.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index f58ffb1ed..bcd70169b 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -8181,5 +8181,13 @@ "lastPage": 2, "type": "eq", "forms": true + }, + { + "id": "issue17169", + "file": "pdfs/issue17169.pdf", + "md5": "fa57aa9442c5e2d6d9e61bbb8856a55f", + "link": true, + "rounds": 1, + "type": "eq" } ] diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index 78f323eae..6791d8419 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -4082,7 +4082,7 @@ describe("annotation", function () { const popupDict = new Dict(); popupDict.set("Type", Name.get("Annot")); popupDict.set("Subtype", Name.get("Popup")); - popupDict.set("F", 25); // not viewable + popupDict.set("F", 56); // not viewable popupDict.set("Parent", parentDict); const popupRef = Ref.get(13, 0); @@ -4097,7 +4097,7 @@ describe("annotation", function () { expect(data.annotationType).toEqual(AnnotationType.POPUP); // We should not modify the `annotationFlags` returned through // e.g., the API. - expect(data.annotationFlags).toEqual(25); + expect(data.annotationFlags).toEqual(56); // The popup should inherit the `viewable` property of the parent. expect(viewable).toEqual(true); }