1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

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.
This commit is contained in:
Jonas Jenwald 2022-11-25 17:00:57 +01:00
parent 4f1b6f345b
commit aa5b678f94
6 changed files with 42 additions and 2 deletions

View file

@ -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";
}
}

View file

@ -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));