Skip to content

Commit

Permalink
Add default icons for FileAttachment annotations (bug 1230933)
Browse files Browse the repository at this point in the history
*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.
  • Loading branch information
Snuffleupagus committed Nov 26, 2022
1 parent 4f1b6f3 commit aa5b678
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/core/annotation.js
Expand Up @@ -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";
}
}

Expand Down
15 changes: 14 additions & 1 deletion src/display/annotation_layer.js
Expand Up @@ -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));

Expand Down
1 change: 1 addition & 0 deletions test/pdfs/bug1230933.pdf.link
@@ -0,0 +1 @@
https://bugzilla.mozilla.org/attachment.cgi?id=8696459
8 changes: 8 additions & 0 deletions test/test_manifest.json
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions web/images/annotation-paperclip.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions web/images/annotation-pushpin.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit aa5b678

Please sign in to comment.