Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default icons for FileAttachment annotations (bug 1230933) #15747

Merged
merged 1 commit into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/core/annotation.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://bugzilla.mozilla.org/attachment.cgi?id=8696459
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
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
Loading
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.