Skip to content

Commit ada3438

Browse files
Merge pull request #21001 from Snuffleupagus/getDestFromStructElement-unit-test
Add a unit-test for the `Catalog.#getDestFromStructElement` method
2 parents 9026329 + d1f15fe commit ada3438

File tree

2 files changed

+66
-6
lines changed

2 files changed

+66
-6
lines changed

src/core/catalog.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
import {
3030
collectActions,
3131
isNumberArray,
32+
lookupRect,
3233
MissingDataException,
3334
PDF_VERSION_REGEXP,
3435
recoverJsURL,
@@ -1597,7 +1598,7 @@ class Catalog {
15971598
} else if (kids) {
15981599
kidsArr = [kids];
15991600
} else {
1600-
kidsArr = [];
1601+
continue;
16011602
}
16021603
for (const kid of kidsArr) {
16031604
const kidObj = xref.fetchIfRef(kid);
@@ -1623,7 +1624,7 @@ class Catalog {
16231624
if (!(parentRaw instanceof Ref)) {
16241625
break;
16251626
}
1626-
const parentDict = xref.fetchIfRef(parentRaw);
1627+
const parentDict = xref.fetch(parentRaw);
16271628
if (!(parentDict instanceof Dict)) {
16281629
break;
16291630
}
@@ -1648,10 +1649,10 @@ class Catalog {
16481649
y = null;
16491650
const attrs = seDict.get("A");
16501651
if (attrs instanceof Dict) {
1651-
const bboxArr = attrs.getArray("BBox");
1652-
if (isNumberArray(bboxArr, 4)) {
1653-
x = bboxArr[0];
1654-
y = bboxArr[3]; // top of the bbox in PDF page coordinates
1652+
const bbox = lookupRect(attrs.getArray("BBox"), null);
1653+
if (bbox) {
1654+
x = bbox[0];
1655+
y = bbox[3]; // top of the bbox in PDF page coordinates
16551656
}
16561657
}
16571658

test/unit/api_spec.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,65 @@ describe("api", function () {
21672167
await loadingTask.destroy();
21682168
});
21692169

2170+
it("gets outline, with SE (Structure Element) entries", async function () {
2171+
const loadingTask = getDocument(
2172+
buildGetDocumentParams("outlines_se.pdf")
2173+
);
2174+
const pdfDoc = await loadingTask.promise;
2175+
const outline = await pdfDoc.getOutline();
2176+
2177+
expect(outline).toEqual([
2178+
{
2179+
action: null,
2180+
attachment: undefined,
2181+
dest: null,
2182+
url: null,
2183+
unsafeUrl: undefined,
2184+
newWindow: undefined,
2185+
setOCGState: undefined,
2186+
title: "P tags",
2187+
color: new Uint8ClampedArray([0, 0, 0]),
2188+
count: 2,
2189+
bold: false,
2190+
italic: false,
2191+
items: [
2192+
{
2193+
action: null,
2194+
attachment: undefined,
2195+
dest: [{ num: 37, gen: 0 }, { name: "XYZ" }, null, null, null],
2196+
url: null,
2197+
unsafeUrl: undefined,
2198+
newWindow: undefined,
2199+
setOCGState: undefined,
2200+
title: "Hello ",
2201+
color: new Uint8ClampedArray([0, 0, 0]),
2202+
count: undefined,
2203+
bold: false,
2204+
italic: false,
2205+
items: [],
2206+
},
2207+
{
2208+
action: null,
2209+
attachment: undefined,
2210+
dest: [{ num: 36, gen: 0 }, { name: "XYZ" }, null, null, null],
2211+
url: null,
2212+
unsafeUrl: undefined,
2213+
newWindow: undefined,
2214+
setOCGState: undefined,
2215+
title: "World ",
2216+
color: new Uint8ClampedArray([0, 0, 0]),
2217+
count: undefined,
2218+
bold: false,
2219+
italic: false,
2220+
items: [],
2221+
},
2222+
],
2223+
},
2224+
]);
2225+
2226+
await loadingTask.destroy();
2227+
});
2228+
21702229
it("gets non-existent permissions", async function () {
21712230
const permissions = await pdfDocument.getPermissions();
21722231
expect(permissions).toEqual(null);

0 commit comments

Comments
 (0)