Move the /SetOCGState handling into the OptionalContentConfig
class (PR 15377 follow-up)
This helps ensure that /SetOCGState actions always take the `Usage` dictionary into account as expected.
This commit is contained in:
parent
935d94c975
commit
f8ce385e0d
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user