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

Merge pull request #16804 from Snuffleupagus/issue-16800

Take fill-alpha into account with default icons for FileAttachment annotations (issue 16800)
This commit is contained in:
Jonas Jenwald 2023-08-08 16:39:37 +02:00 committed by GitHub
commit 2e9f2e630c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 7 deletions

View file

@ -4653,6 +4653,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;
}
}

View file

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