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

@ -1913,7 +1913,10 @@ class PartialEvaluator {
return;
}
// Other marked content types aren't supported yet.
args = [args[0].name];
args = [
args[0].name,
args[1] instanceof Dict ? args[1].get("MCID") : null,
];
break;
case OPS.beginMarkedContent:
@ -1973,6 +1976,7 @@ class PartialEvaluator {
stateManager = null,
normalizeWhitespace = false,
combineTextItems = false,
includeMarkedContent = false,
sink,
seenStyles = new Set(),
}) {
@ -2573,6 +2577,7 @@ class PartialEvaluator {
stateManager: xObjStateManager,
normalizeWhitespace,
combineTextItems,
includeMarkedContent,
sink: sinkWrapper,
seenStyles,
})
@ -2650,6 +2655,38 @@ class PartialEvaluator {
})
);
return;
case OPS.beginMarkedContent:
if (includeMarkedContent) {
textContent.items.push({
type: "beginMarkedContent",
tag: isName(args[0]) ? args[0].name : null,
});
}
break;
case OPS.beginMarkedContentProps:
if (includeMarkedContent) {
flushTextContentItem();
let mcid = null;
if (isDict(args[1])) {
mcid = args[1].get("MCID");
}
textContent.items.push({
type: "beginMarkedContentProps",
id: Number.isInteger(mcid)
? `${self.idFactory.getPageObjId()}_mcid${mcid}`
: null,
tag: isName(args[0]) ? args[0].name : null,
});
}
break;
case OPS.endMarkedContent:
if (includeMarkedContent) {
flushTextContentItem();
textContent.items.push({
type: "endMarkedContent",
});
}
break;
} // switch
if (textContent.items.length >= sink.desiredSize) {
// Wait for ready, if we reach highWaterMark.