Skip to content

Commit

Permalink
Move the /SetOCGState handling into the OptionalContentConfig class…
Browse files Browse the repository at this point in the history
… (PR 15377 follow-up)

This helps ensure that /SetOCGState actions always take the `Usage` dictionary into account as expected.
  • Loading branch information
Snuffleupagus committed Mar 5, 2024
1 parent 935d94c commit 088940c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
28 changes: 28 additions & 0 deletions src/display/optional_content_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,34 @@ class OptionalContentConfig {
this.#cachedGetHash = null;
}

setOCGState({ state, preserveRB }) {
let operator;

for (const elem of state) {
switch (elem) {
case "ON":
case "OFF":
case "Toggle":
operator = elem;
continue;
}
switch (operator) {
case "ON":
this.setVisibility(elem, true);
break;
case "OFF":
this.setVisibility(elem, false);
break;
case "Toggle":
const group = this.getGroup(elem);
if (group) {
this.setVisibility(elem, !group.visible);
}
break;
}
}
}

get hasInitialVisibility() {
return this.#initialHash === null || this.getHash() === this.#initialHash;
}
Expand Down
26 changes: 1 addition & 25 deletions web/pdf_link_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,31 +517,7 @@ class PDFLinkService {
if (pdfDocument !== this.pdfDocument) {
return; // The document was closed while the optional content resolved.
}
let operator;

for (const elem of action.state) {
switch (elem) {
case "ON":
case "OFF":
case "Toggle":
operator = elem;
continue;
}
switch (operator) {
case "ON":
optionalContentConfig.setVisibility(elem, true);
break;
case "OFF":
optionalContentConfig.setVisibility(elem, false);
break;
case "Toggle":
const group = optionalContentConfig.getGroup(elem);
if (group) {
optionalContentConfig.setVisibility(elem, !group.visible);
}
break;
}
}
optionalContentConfig.setOCGState(action);

this.pdfViewer.optionalContentConfigPromise = Promise.resolve(
optionalContentConfig
Expand Down

0 comments on commit 088940c

Please sign in to comment.