1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

[api-minor] Add basic support for the SetOCGState action (issue 15372)

Note that this patch implements the `SetOCGState`-handling in `PDFLinkService`, rather than as a new method in `OptionalContentConfig`[1], since this action is nothing but a series of `setVisibility`-calls and that it seems quite uncommon in real-world PDF documents.

The new functionality also required some tweaks in the `PDFLayerViewer`, to ensure that the `layersView` in the sidebar is updated correctly when the optional-content visibility changes from "outside" of `PDFLayerViewer`.

---
[1] We can obviously move this code into `OptionalContentConfig` instead, if deemed necessary, but for an initial implementation I figured that doing it this way might be acceptable.
This commit is contained in:
Jonas Jenwald 2022-08-31 17:50:28 +02:00
parent e9bdbe4574
commit cc4baa2fe9
10 changed files with 185 additions and 31 deletions

View file

@ -51,6 +51,7 @@
!issue7847_radial.pdf
!issue14953.pdf
!issue15367.pdf
!issue15372.pdf
!issue7446.pdf
!issue7492.pdf
!issue7544.pdf

BIN
test/pdfs/issue15372.pdf Normal file

Binary file not shown.

View file

@ -1540,6 +1540,7 @@ describe("api", function () {
url: null,
unsafeUrl: undefined,
newWindow: undefined,
setOCGState: undefined,
title: "Händel -- Halle🎆lujah",
color: new Uint8ClampedArray([0, 0, 0]),
count: undefined,
@ -1565,6 +1566,7 @@ describe("api", function () {
url: null,
unsafeUrl: undefined,
newWindow: undefined,
setOCGState: undefined,
title: "Previous Page",
color: new Uint8ClampedArray([0, 0, 0]),
count: undefined,
@ -1576,6 +1578,32 @@ describe("api", function () {
await loadingTask.destroy();
});
it("gets outline, with SetOCGState-actions (issue 15372)", async function () {
const loadingTask = getDocument(buildGetDocumentParams("issue15372.pdf"));
const pdfDoc = await loadingTask.promise;
const outline = await pdfDoc.getOutline();
expect(Array.isArray(outline)).toEqual(true);
expect(outline.length).toEqual(1);
expect(outline[0]).toEqual({
action: null,
dest: null,
url: null,
unsafeUrl: undefined,
newWindow: undefined,
setOCGState: { state: ["OFF", "ON", "50R"], preserveRB: false },
title: "Display Layer",
color: new Uint8ClampedArray([0, 0, 0]),
count: undefined,
bold: false,
italic: false,
items: [],
});
await loadingTask.destroy();
});
it("gets outline with non-displayable chars", async function () {
const loadingTask = getDocument(buildGetDocumentParams("issue14267.pdf"));
const pdfDoc = await loadingTask.promise;