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 12, 2024
1 parent 3c78ff5 commit 70b6ddc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
37 changes: 35 additions & 2 deletions src/display/optional_content_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,44 @@ class OptionalContentConfig {
}

setVisibility(id, visible = true) {
if (!this.#groups.has(id)) {
const group = this.#groups.get(id);
if (!group) {
warn(`Optional content group not found: ${id}`);
return;
}
this.#groups.get(id)._setVisible(INTERNAL, !!visible, /* userSet = */ true);
group._setVisible(INTERNAL, !!visible, /* userSet = */ true);

this.#cachedGetHash = null;
}

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

for (const elem of state) {
switch (elem) {
case "ON":
case "OFF":
case "Toggle":
operator = elem;
continue;
}

const group = this.#groups.get(elem);
if (!group) {
continue;
}
switch (operator) {
case "ON":
group._setVisible(INTERNAL, true);
break;
case "OFF":
group._setVisible(INTERNAL, false);
break;
case "Toggle":
group._setVisible(INTERNAL, !group.visible);
break;
}
}

this.#cachedGetHash = null;
}
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 70b6ddc

Please sign in to comment.