From e2819d0c676753397ea930c287081961499c84b8 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 8 Aug 2023 11:16:50 +0200 Subject: [PATCH] Take fill-alpha into account with default icons for FileAttachment annotations (issue 16800) --- src/core/annotation.js | 6 ++++++ src/display/annotation_layer.js | 21 +++++++++++++++------ test/annotation_layer_builder_overrides.css | 7 ++++++- test/pdfs/issue16800.pdf.link | 1 + test/test_manifest.json | 10 ++++++++++ 5 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 test/pdfs/issue16800.pdf.link diff --git a/src/core/annotation.js b/src/core/annotation.js index dd5ecbb67..f8acbc29b 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -4652,6 +4652,12 @@ class FileAttachmentAnnotation extends MarkupAnnotation { const name = dict.get("Name"); this.data.name = name instanceof Name ? stringToPDFString(name.name) : "PushPin"; + + const fillAlpha = dict.get("ca"); + this.data.fillAlpha = + typeof fillAlpha === "number" && fillAlpha >= 0 && fillAlpha <= 1 + ? fillAlpha + : null; } } diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index bb341e6fd..c0239b2b4 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -2798,8 +2798,9 @@ class FileAttachmentAnnotationElement extends AnnotationElement { render() { this.container.classList.add("fileAttachmentAnnotation"); + const { data } = this; let trigger; - if (this.data.hasAppearance) { + if (data.hasAppearance || data.fillAlpha === 0) { trigger = document.createElement("div"); } else { // Unfortunately it seems that it's not clearly specified exactly what @@ -2809,18 +2810,26 @@ class FileAttachmentAnnotationElement extends AnnotationElement { // Additional names may be supported as well. Default value: PushPin. trigger = document.createElement("img"); trigger.src = `${this.imageResourcesPath}annotation-${ - /paperclip/i.test(this.data.name) ? "paperclip" : "pushpin" + /paperclip/i.test(data.name) ? "paperclip" : "pushpin" }.svg`; + + if (data.fillAlpha && data.fillAlpha < 1) { + trigger.style = `filter: opacity(${Math.round( + data.fillAlpha * 100 + )}%);`; + + if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) { + this.container.classList.add("hasFillAlpha"); + } + } } trigger.classList.add("popupTriggerArea"); trigger.addEventListener("dblclick", this._download.bind(this)); this.#trigger = trigger; if ( - !this.data.popupRef && - (this.data.titleObj?.str || - this.data.contentsObj?.str || - this.data.richText) + !data.popupRef && + (data.titleObj?.str || data.contentsObj?.str || data.richText) ) { this._createPopup(); } diff --git a/test/annotation_layer_builder_overrides.css b/test/annotation_layer_builder_overrides.css index ac3ee7b3f..309c965ef 100644 --- a/test/annotation_layer_builder_overrides.css +++ b/test/annotation_layer_builder_overrides.css @@ -33,11 +33,16 @@ :is(.linkAnnotation, .buttonWidgetAnnotation.pushButton):not(.hasBorder) > a, .annotationLayer .popupTriggerArea::after, -.annotationLayer .fileAttachmentAnnotation .popupTriggerArea { +.annotationLayer + .fileAttachmentAnnotation:not(.hasFillAlpha) + .popupTriggerArea { opacity: 0.2; background: rgba(255, 255, 0, 1); box-shadow: 0 2px 10px rgba(255, 255, 0, 1); } +.annotationLayer .fileAttachmentAnnotation.hasFillAlpha { + outline: 2px solid yellow; +} .annotationLayer .hasClipPath::after { box-shadow: none; diff --git a/test/pdfs/issue16800.pdf.link b/test/pdfs/issue16800.pdf.link new file mode 100644 index 000000000..49792a70d --- /dev/null +++ b/test/pdfs/issue16800.pdf.link @@ -0,0 +1 @@ +https://github.com/mozilla/pdf.js/files/12287878/TS354.Week.2.slides.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index dbff94481..412ce2b9f 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -6270,6 +6270,16 @@ "type": "eq", "annotations": true }, + { "id": "issue16800", + "file": "pdfs/issue16800.pdf", + "md5": "771bc170a55f923d7903af28ccca196c", + "link": true, + "rounds": 1, + "firstPage": 2, + "lastPage": 2, + "type": "eq", + "annotations": true + }, { "id": "issue14117", "file": "pdfs/issue14117.pdf", "md5": "9b1c33ad2f59f4e723c258e863149abf",