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
3c78ff5fb0
commit
70b6ddc5d9
@ -230,11 +230,44 @@ class OptionalContentConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setVisibility(id, visible = true) {
|
setVisibility(id, visible = true) {
|
||||||
if (!this.#groups.has(id)) {
|
const group = this.#groups.get(id);
|
||||||
|
if (!group) {
|
||||||
warn(`Optional content group not found: ${id}`);
|
warn(`Optional content group not found: ${id}`);
|
||||||
return;
|
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;
|
this.#cachedGetHash = null;
|
||||||
}
|
}
|
||||||
|
@ -517,31 +517,7 @@ class PDFLinkService {
|
|||||||
if (pdfDocument !== this.pdfDocument) {
|
if (pdfDocument !== this.pdfDocument) {
|
||||||
return; // The document was closed while the optional content resolved.
|
return; // The document was closed while the optional content resolved.
|
||||||
}
|
}
|
||||||
let operator;
|
optionalContentConfig.setOCGState(action);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pdfViewer.optionalContentConfigPromise = Promise.resolve(
|
this.pdfViewer.optionalContentConfigPromise = Promise.resolve(
|
||||||
optionalContentConfig
|
optionalContentConfig
|
||||||
|
Loading…
Reference in New Issue
Block a user