1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 01:28:06 +02:00

[api-minor] Add basic support for the SetOCGState action (issue 15372)

Note that this patch implements the `SetOCGState`-handling in `PDFLinkService`, rather than as a new method in `OptionalContentConfig`[1], since this action is nothing but a series of `setVisibility`-calls and that it seems quite uncommon in real-world PDF documents.

The new functionality also required some tweaks in the `PDFLayerViewer`, to ensure that the `layersView` in the sidebar is updated correctly when the optional-content visibility changes from "outside" of `PDFLayerViewer`.

---
[1] We can obviously move this code into `OptionalContentConfig` instead, if deemed necessary, but for an initial implementation I figured that doing it this way might be acceptable.
This commit is contained in:
Jonas Jenwald 2022-08-31 17:50:28 +02:00
parent e9bdbe4574
commit cc4baa2fe9
10 changed files with 185 additions and 31 deletions

View file

@ -329,6 +329,7 @@ class Catalog {
url: data.url,
unsafeUrl: data.unsafeUrl,
newWindow: data.newWindow,
setOCGState: data.setOCGState,
title: stringToPDFString(title),
color: rgbColor,
count: Number.isInteger(count) ? count : undefined,
@ -1533,6 +1534,38 @@ class Catalog {
}
break;
case "SetOCGState":
const state = action.get("State");
const preserveRB = action.get("PreserveRB");
if (!Array.isArray(state) || state.length === 0) {
break;
}
const stateArr = [];
for (const elem of state) {
if (elem instanceof Name) {
switch (elem.name) {
case "ON":
case "OFF":
case "Toggle":
stateArr.push(elem.name);
break;
}
} else if (elem instanceof Ref) {
stateArr.push(elem.toString());
}
}
if (stateArr.length !== state.length) {
break; // Some of the original entries are not valid.
}
resultObj.setOCGState = {
state: stateArr,
preserveRB: typeof preserveRB === "boolean" ? preserveRB : true,
};
break;
case "JavaScript":
const jsAction = action.get("JS");
let js;