mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-28 23:28:16 +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:
parent
6429ccc002
commit
fc9501a637
22 changed files with 911 additions and 14 deletions
|
@ -60,6 +60,7 @@ import { CipherTransformFactory } from "./crypto.js";
|
|||
import { ColorSpace } from "./colorspace.js";
|
||||
import { GlobalImageCache } from "./image_utils.js";
|
||||
import { MetadataParser } from "./metadata_parser.js";
|
||||
import { StructTreeRoot } from "./struct_tree.js";
|
||||
|
||||
function fetchDestination(dest) {
|
||||
return isDict(dest) ? dest.get("D") : dest;
|
||||
|
@ -200,6 +201,32 @@ class Catalog {
|
|||
return markInfo;
|
||||
}
|
||||
|
||||
get structTreeRoot() {
|
||||
let structTree = null;
|
||||
try {
|
||||
structTree = this._readStructTreeRoot();
|
||||
} catch (ex) {
|
||||
if (ex instanceof MissingDataException) {
|
||||
throw ex;
|
||||
}
|
||||
warn("Unable read to structTreeRoot info.");
|
||||
}
|
||||
return shadow(this, "structTreeRoot", structTree);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_readStructTreeRoot() {
|
||||
const obj = this._catDict.get("StructTreeRoot");
|
||||
if (!isDict(obj)) {
|
||||
return null;
|
||||
}
|
||||
const root = new StructTreeRoot(obj);
|
||||
root.init();
|
||||
return root;
|
||||
}
|
||||
|
||||
get toplevelPagesDict() {
|
||||
const pagesObj = this._catDict.get("Pages");
|
||||
if (!isDict(pagesObj)) {
|
||||
|
@ -2626,4 +2653,4 @@ const ObjectLoader = (function () {
|
|||
return ObjectLoader;
|
||||
})();
|
||||
|
||||
export { Catalog, FileSpec, ObjectLoader, XRef };
|
||||
export { Catalog, FileSpec, NumberTree, ObjectLoader, XRef };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue