From aa5b678f94cb130061c9e19b37d05acfcf8f52b4 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 25 Nov 2022 17:00:57 +0100 Subject: [PATCH] Add default icons for FileAttachment annotations (bug 1230933) *Please note:* This "borrows" the icons from Thunderbird. According to the PDF specification, see https://web.archive.org/web/20220309040754if_/https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#G11.2096626, we should be providing default icons for FileAttachment annotations without appearances. --- src/core/annotation.js | 7 ++++++- src/display/annotation_layer.js | 15 ++++++++++++++- test/pdfs/bug1230933.pdf.link | 1 + test/test_manifest.json | 8 ++++++++ web/images/annotation-paperclip.svg | 6 ++++++ web/images/annotation-pushpin.svg | 7 +++++++ 6 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 test/pdfs/bug1230933.pdf.link create mode 100644 web/images/annotation-paperclip.svg create mode 100644 web/images/annotation-pushpin.svg diff --git a/src/core/annotation.js b/src/core/annotation.js index b9bec56ff..50cd6ba09 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -4274,10 +4274,15 @@ class FileAttachmentAnnotation extends MarkupAnnotation { constructor(params) { super(params); - const file = new FileSpec(params.dict.get("FS"), params.xref); + const { dict, xref } = params; + const file = new FileSpec(dict.get("FS"), xref); this.data.annotationType = AnnotationType.FILEATTACHMENT; this.data.file = file.serializable; + + const name = dict.get("Name"); + this.data.name = + name instanceof Name ? stringToPDFString(name.name) : "PushPin"; } } diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 84ac665b1..2d311fafb 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -2509,7 +2509,20 @@ class FileAttachmentAnnotationElement extends AnnotationElement { render() { this.container.className = "fileAttachmentAnnotation"; - const trigger = document.createElement("div"); + let trigger; + if (this.data.hasAppearance) { + trigger = document.createElement("div"); + } else { + // Unfortunately it seems that it's not clearly specified exactly what + // names are actually valid, since Table 184 contains: + // Conforming readers shall provide predefined icon appearances for at + // least the following standard names: GraphPushPin, PaperclipTag. + // 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" + }.svg`; + } trigger.className = "popupTriggerArea"; trigger.addEventListener("dblclick", this._download.bind(this)); diff --git a/test/pdfs/bug1230933.pdf.link b/test/pdfs/bug1230933.pdf.link new file mode 100644 index 000000000..4e929ed1b --- /dev/null +++ b/test/pdfs/bug1230933.pdf.link @@ -0,0 +1 @@ +https://bugzilla.mozilla.org/attachment.cgi?id=8696459 diff --git a/test/test_manifest.json b/test/test_manifest.json index c096ba799..552d44d4b 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -6064,6 +6064,14 @@ "type": "eq", "annotations": true }, + { "id": "bug1230933", + "file": "pdfs/bug1230933.pdf", + "md5": "d8e7dce9ce79aa5a6121b21be8935429", + "link": true, + "rounds": 1, + "type": "eq", + "annotations": true + }, { "id": "issue14117", "file": "pdfs/issue14117.pdf", "md5": "9b1c33ad2f59f4e723c258e863149abf", diff --git a/web/images/annotation-paperclip.svg b/web/images/annotation-paperclip.svg new file mode 100644 index 000000000..2bed2250a --- /dev/null +++ b/web/images/annotation-paperclip.svg @@ -0,0 +1,6 @@ + + + + diff --git a/web/images/annotation-pushpin.svg b/web/images/annotation-pushpin.svg new file mode 100644 index 000000000..6e0896cf4 --- /dev/null +++ b/web/images/annotation-pushpin.svg @@ -0,0 +1,7 @@ + + + + +