Merge pull request #21505 from Snuffleupagus/StructTreeRoot-rm-init

Inline the `init` method in the `StructTreeRoot` constructor
This commit is contained in:
Tim van der Meij 2026-06-26 20:14:46 +02:00 committed by GitHub
commit 8bdd159699
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 34 deletions

View File

@ -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() {

View File

@ -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,