mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Add support for "GoToE" actions with destinations (issue 17056)
This shouldn't be very common in practice, since "GoToE" actions themselves seem quite uncommon; see PR 15537.
This commit is contained in:
parent
da4fdc76a3
commit
bf9c33e60f
7 changed files with 62 additions and 19 deletions
|
@ -59,6 +59,21 @@ function fetchDestination(dest) {
|
|||
return Array.isArray(dest) ? dest : null;
|
||||
}
|
||||
|
||||
function fetchRemoteDest(action) {
|
||||
let dest = action.get("D");
|
||||
if (dest) {
|
||||
if (dest instanceof Name) {
|
||||
dest = dest.name;
|
||||
}
|
||||
if (typeof dest === "string") {
|
||||
return stringToPDFString(dest);
|
||||
} else if (Array.isArray(dest)) {
|
||||
return JSON.stringify(dest);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
class Catalog {
|
||||
constructor(pdfManager, xref) {
|
||||
this.pdfManager = pdfManager;
|
||||
|
@ -1514,19 +1529,9 @@ class Catalog {
|
|||
}
|
||||
|
||||
// NOTE: the destination is relative to the *remote* document.
|
||||
let remoteDest = action.get("D");
|
||||
if (remoteDest) {
|
||||
if (remoteDest instanceof Name) {
|
||||
remoteDest = remoteDest.name;
|
||||
}
|
||||
if (typeof url === "string") {
|
||||
const baseUrl = url.split("#")[0];
|
||||
if (typeof remoteDest === "string") {
|
||||
url = baseUrl + "#" + remoteDest;
|
||||
} else if (Array.isArray(remoteDest)) {
|
||||
url = baseUrl + "#" + JSON.stringify(remoteDest);
|
||||
}
|
||||
}
|
||||
const remoteDest = fetchRemoteDest(action);
|
||||
if (remoteDest && typeof url === "string") {
|
||||
url = /* baseUrl = */ url.split("#", 1)[0] + "#" + remoteDest;
|
||||
}
|
||||
// The 'NewWindow' property, equal to `LinkTarget.BLANK`.
|
||||
const newWindow = action.get("NewWindow");
|
||||
|
@ -1550,6 +1555,12 @@ class Catalog {
|
|||
|
||||
if (attachment) {
|
||||
resultObj.attachment = attachment;
|
||||
|
||||
// NOTE: the destination is relative to the *attachment*.
|
||||
const attachmentDest = fetchRemoteDest(action);
|
||||
if (attachmentDest) {
|
||||
resultObj.attachmentDest = attachmentDest;
|
||||
}
|
||||
} else {
|
||||
warn(`parseDestDictionary - unimplemented "GoToE" action.`);
|
||||
}
|
||||
|
|
|
@ -709,7 +709,7 @@ class LinkAnnotationElement extends AnnotationElement {
|
|||
this._bindNamedAction(link, data.action);
|
||||
isBound = true;
|
||||
} else if (data.attachment) {
|
||||
this._bindAttachment(link, data.attachment);
|
||||
this.#bindAttachment(link, data.attachment, data.attachmentDest);
|
||||
isBound = true;
|
||||
} else if (data.setOCGState) {
|
||||
this.#bindSetOCGState(link, data.setOCGState);
|
||||
|
@ -793,14 +793,16 @@ class LinkAnnotationElement extends AnnotationElement {
|
|||
* Bind attachments to the link element.
|
||||
* @param {Object} link
|
||||
* @param {Object} attachment
|
||||
* @param {str} [dest]
|
||||
*/
|
||||
_bindAttachment(link, attachment) {
|
||||
#bindAttachment(link, attachment, dest = null) {
|
||||
link.href = this.linkService.getAnchorUrl("");
|
||||
link.onclick = () => {
|
||||
this.downloadManager?.openOrDownloadData(
|
||||
this.container,
|
||||
attachment.content,
|
||||
attachment.filename
|
||||
attachment.filename,
|
||||
dest
|
||||
);
|
||||
return false;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue