mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-27 02:25:47 +02:00
Merge pull request #21505 from Snuffleupagus/StructTreeRoot-rm-init
Inline the `init` method in the `StructTreeRoot` constructor
This commit is contained in:
commit
8bdd159699
@ -354,15 +354,11 @@ class Catalog {
|
||||
}
|
||||
|
||||
#readStructTreeRoot() {
|
||||
const rawObj = this.#catDict.getRaw("StructTreeRoot");
|
||||
const obj = this.xref.fetchIfRef(rawObj);
|
||||
if (!(obj instanceof Dict)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const root = new StructTreeRoot(this.xref, obj, rawObj);
|
||||
root.init();
|
||||
return root;
|
||||
const rawObj = this.#catDict.getRaw("StructTreeRoot"),
|
||||
obj = this.xref.fetchIfRef(rawObj);
|
||||
return obj instanceof Dict
|
||||
? new StructTreeRoot(this.xref, obj, rawObj)
|
||||
: null;
|
||||
}
|
||||
|
||||
get toplevelPagesDict() {
|
||||
|
||||
@ -37,14 +37,31 @@ const StructElementType = {
|
||||
};
|
||||
|
||||
class StructTreeRoot {
|
||||
kidRefToPosition = undefined;
|
||||
|
||||
parentTree = null;
|
||||
|
||||
roleMap = new Map();
|
||||
|
||||
structParentIds = null;
|
||||
|
||||
constructor(xref, rootDict, rootRef) {
|
||||
this.xref = xref;
|
||||
this.dict = rootDict;
|
||||
this.ref = rootRef instanceof Ref ? rootRef : null;
|
||||
this.roleMap = new Map();
|
||||
this.structParentIds = null;
|
||||
this.kidRefToPosition = undefined;
|
||||
this.parentTree = null;
|
||||
|
||||
const roleMap = rootDict.get("RoleMap");
|
||||
if (roleMap instanceof Dict) {
|
||||
for (const [key, value] of roleMap) {
|
||||
if (value instanceof Name) {
|
||||
this.roleMap.set(key, value.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
const parentTree = rootDict.getRaw("ParentTree");
|
||||
if (parentTree) {
|
||||
this.parentTree = new NumberTree(parentTree, xref);
|
||||
}
|
||||
}
|
||||
|
||||
getKidPosition(kidRef) {
|
||||
@ -71,15 +88,6 @@ class StructTreeRoot {
|
||||
: -1;
|
||||
}
|
||||
|
||||
init() {
|
||||
this.readRoleMap();
|
||||
const parentTree = this.dict.get("ParentTree");
|
||||
if (!parentTree) {
|
||||
return;
|
||||
}
|
||||
this.parentTree = new NumberTree(parentTree, this.xref);
|
||||
}
|
||||
|
||||
#addIdToPage(pageRef, id, type) {
|
||||
if (!(pageRef instanceof Ref) || id < 0) {
|
||||
return;
|
||||
@ -97,18 +105,6 @@ class StructTreeRoot {
|
||||
this.#addIdToPage(pageRef, id, StructElementType.ANNOTATION);
|
||||
}
|
||||
|
||||
readRoleMap() {
|
||||
const roleMapDict = this.dict.get("RoleMap");
|
||||
if (!(roleMapDict instanceof Dict)) {
|
||||
return;
|
||||
}
|
||||
for (const [key, value] of roleMapDict) {
|
||||
if (value instanceof Name) {
|
||||
this.roleMap.set(key, value.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async canCreateStructureTree({
|
||||
catalogRef,
|
||||
pdfManager,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user