mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-22 16:05:56 +02:00
Merge pull request #21001 from Snuffleupagus/getDestFromStructElement-unit-test
Add a unit-test for the `Catalog.#getDestFromStructElement` method
This commit is contained in:
commit
ada3438039
@ -29,6 +29,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
collectActions,
|
collectActions,
|
||||||
isNumberArray,
|
isNumberArray,
|
||||||
|
lookupRect,
|
||||||
MissingDataException,
|
MissingDataException,
|
||||||
PDF_VERSION_REGEXP,
|
PDF_VERSION_REGEXP,
|
||||||
recoverJsURL,
|
recoverJsURL,
|
||||||
@ -1597,7 +1598,7 @@ class Catalog {
|
|||||||
} else if (kids) {
|
} else if (kids) {
|
||||||
kidsArr = [kids];
|
kidsArr = [kids];
|
||||||
} else {
|
} else {
|
||||||
kidsArr = [];
|
continue;
|
||||||
}
|
}
|
||||||
for (const kid of kidsArr) {
|
for (const kid of kidsArr) {
|
||||||
const kidObj = xref.fetchIfRef(kid);
|
const kidObj = xref.fetchIfRef(kid);
|
||||||
@ -1623,7 +1624,7 @@ class Catalog {
|
|||||||
if (!(parentRaw instanceof Ref)) {
|
if (!(parentRaw instanceof Ref)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const parentDict = xref.fetchIfRef(parentRaw);
|
const parentDict = xref.fetch(parentRaw);
|
||||||
if (!(parentDict instanceof Dict)) {
|
if (!(parentDict instanceof Dict)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1648,10 +1649,10 @@ class Catalog {
|
|||||||
y = null;
|
y = null;
|
||||||
const attrs = seDict.get("A");
|
const attrs = seDict.get("A");
|
||||||
if (attrs instanceof Dict) {
|
if (attrs instanceof Dict) {
|
||||||
const bboxArr = attrs.getArray("BBox");
|
const bbox = lookupRect(attrs.getArray("BBox"), null);
|
||||||
if (isNumberArray(bboxArr, 4)) {
|
if (bbox) {
|
||||||
x = bboxArr[0];
|
x = bbox[0];
|
||||||
y = bboxArr[3]; // top of the bbox in PDF page coordinates
|
y = bbox[3]; // top of the bbox in PDF page coordinates
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2167,6 +2167,65 @@ describe("api", function () {
|
|||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("gets outline, with SE (Structure Element) entries", async function () {
|
||||||
|
const loadingTask = getDocument(
|
||||||
|
buildGetDocumentParams("outlines_se.pdf")
|
||||||
|
);
|
||||||
|
const pdfDoc = await loadingTask.promise;
|
||||||
|
const outline = await pdfDoc.getOutline();
|
||||||
|
|
||||||
|
expect(outline).toEqual([
|
||||||
|
{
|
||||||
|
action: null,
|
||||||
|
attachment: undefined,
|
||||||
|
dest: null,
|
||||||
|
url: null,
|
||||||
|
unsafeUrl: undefined,
|
||||||
|
newWindow: undefined,
|
||||||
|
setOCGState: undefined,
|
||||||
|
title: "P tags",
|
||||||
|
color: new Uint8ClampedArray([0, 0, 0]),
|
||||||
|
count: 2,
|
||||||
|
bold: false,
|
||||||
|
italic: false,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
action: null,
|
||||||
|
attachment: undefined,
|
||||||
|
dest: [{ num: 37, gen: 0 }, { name: "XYZ" }, null, null, null],
|
||||||
|
url: null,
|
||||||
|
unsafeUrl: undefined,
|
||||||
|
newWindow: undefined,
|
||||||
|
setOCGState: undefined,
|
||||||
|
title: "Hello ",
|
||||||
|
color: new Uint8ClampedArray([0, 0, 0]),
|
||||||
|
count: undefined,
|
||||||
|
bold: false,
|
||||||
|
italic: false,
|
||||||
|
items: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: null,
|
||||||
|
attachment: undefined,
|
||||||
|
dest: [{ num: 36, gen: 0 }, { name: "XYZ" }, null, null, null],
|
||||||
|
url: null,
|
||||||
|
unsafeUrl: undefined,
|
||||||
|
newWindow: undefined,
|
||||||
|
setOCGState: undefined,
|
||||||
|
title: "World ",
|
||||||
|
color: new Uint8ClampedArray([0, 0, 0]),
|
||||||
|
count: undefined,
|
||||||
|
bold: false,
|
||||||
|
italic: false,
|
||||||
|
items: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
await loadingTask.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
it("gets non-existent permissions", async function () {
|
it("gets non-existent permissions", async function () {
|
||||||
const permissions = await pdfDocument.getPermissions();
|
const permissions = await pdfDocument.getPermissions();
|
||||||
expect(permissions).toEqual(null);
|
expect(permissions).toEqual(null);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user