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

[api-minor] Let PDFPageProxy.getStructTree return null, rather than an empty structTree, for documents without any accessibility data (PR 13171 follow-up)

This is first of all consistent with existing API-methods, where we return `null` when the data in question doesn't exist. Secondly, it should also be (slightly) more efficient since there's less dummy-data that we need to transfer between threads.
Finally, this prevents us from adding an empty/unnecessary span to *every* single page even in documents without any structure tree data.
This commit is contained in:
Jonas Jenwald 2021-04-11 12:04:29 +02:00
parent ff4dae05b0
commit 5adee0cdd1
4 changed files with 72 additions and 1 deletions

View file

@ -1702,6 +1702,69 @@ describe("api", function () {
.catch(done.fail);
});
it("gets empty structure tree", async function () {
const tree = await page.getStructTree();
expect(tree).toEqual(null);
});
it("gets simple structure tree", async function () {
const loadingTask = getDocument(
buildGetDocumentParams("structure_simple.pdf")
);
const pdfDoc = await loadingTask.promise;
const pdfPage = await pdfDoc.getPage(1);
const tree = await pdfPage.getStructTree();
expect(tree).toEqual({
role: "Root",
children: [
{
role: "Document",
children: [
{
role: "H1",
children: [
{
role: "NonStruct",
children: [{ type: "content", id: "page2R_mcid0" }],
},
],
},
{
role: "P",
children: [
{
role: "NonStruct",
children: [{ type: "content", id: "page2R_mcid1" }],
},
],
},
{
role: "H2",
children: [
{
role: "NonStruct",
children: [{ type: "content", id: "page2R_mcid2" }],
},
],
},
{
role: "P",
children: [
{
role: "NonStruct",
children: [{ type: "content", id: "page2R_mcid3" }],
},
],
},
],
},
],
});
await loadingTask.destroy();
});
it("gets operator list", function (done) {
const promise = page.getOperatorList();
promise