1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +02:00

Add support for basic structure tree for accessibility.

When a PDF is "marked" we now generate a separate DOM that represents
the structure tree from the PDF.  This DOM is inserted into the <canvas>
element and allows screen readers to walk the tree and have more
information about headings, images, links, etc. To link the structure
tree DOM (which is empty) to the text layer aria-owns is used. This
required modifying the text layer creation so that marked items are
now tracked.
This commit is contained in:
Brendan Dahl 2021-03-31 15:07:02 -07:00
parent 6429ccc002
commit fc9501a637
22 changed files with 911 additions and 14 deletions

View file

@ -58,6 +58,7 @@ import { calculateMD5 } from "./crypto.js";
import { Linearization } from "./parser.js";
import { OperatorList } from "./operator_list.js";
import { PartialEvaluator } from "./evaluator.js";
import { StructTreePage } from "./struct_tree.js";
import { XFAFactory } from "./xfa/factory.js";
const DEFAULT_USER_UNIT = 1.0;
@ -104,6 +105,10 @@ class Page {
static createObjId() {
return `p${pageIndex}_${++idCounters.obj}`;
}
static getPageObjId() {
return `page${ref.toString()}`;
}
};
}
@ -406,6 +411,7 @@ class Page {
handler,
task,
normalizeWhitespace,
includeMarkedContent,
sink,
combineTextItems,
}) {
@ -437,12 +443,22 @@ class Page {
task,
resources: this.resources,
normalizeWhitespace,
includeMarkedContent,
combineTextItems,
sink,
});
});
}
async getStructTree() {
const structTreeRoot = await this.pdfManager.ensureCatalog(
"structTreeRoot"
);
const tree = new StructTreePage(structTreeRoot, this.pageDict);
tree.parse();
return tree;
}
getAnnotationsData(intent) {
return this._parsedAnnotations.then(function (annotations) {
const annotationsData = [];
@ -604,6 +620,10 @@ class PDFDocument {
static createObjId() {
unreachable("Abstract method `createObjId` called.");
}
static getPageObjId() {
unreachable("Abstract method `getPageObjId` called.");
}
};
}