From 70b6ddc5d967249d6082aa8116d65770da860546 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 5 Mar 2024 17:25:36 +0100 Subject: [PATCH] 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. --- src/display/optional_content_config.js | 37 ++++++++++++++++++++++++-- web/pdf_link_service.js | 26 +----------------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/display/optional_content_config.js b/src/display/optional_content_config.js index 20c6b71fb..366da2212 100644 --- a/src/display/optional_content_config.js +++ b/src/display/optional_content_config.js @@ -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; } diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js index 455a00ff4..e8b966090 100644 --- a/web/pdf_link_service.js +++ b/web/pdf_link_service.js @@ -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