1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

In the struct tree a kid can be a reference to an MCID entry (issue #19694)

This commit is contained in:
Calixte Denizet 2025-03-21 12:49:56 +01:00
parent a8c77633a1
commit dee80cb082

View file

@ -565,7 +565,10 @@ class StructElementNode {
const kids = this.dict.get("K");
if (Array.isArray(kids)) {
for (const kid of kids) {
const element = this.parseKid(pageObjId, kid);
const element = this.parseKid(
pageObjId,
this.dict.xref.fetchIfRef(kid)
);
if (element) {
this.kids.push(element);
}
@ -592,33 +595,26 @@ class StructElementNode {
});
}
// Find the dictionary for the kid.
let kidDict = null;
if (kid instanceof Ref) {
kidDict = this.dict.xref.fetch(kid);
} else if (kid instanceof Dict) {
kidDict = kid;
}
if (!kidDict) {
if (!(kid instanceof Dict)) {
return null;
}
const pageRef = kidDict.getRaw("Pg");
const pageRef = kid.getRaw("Pg");
if (pageRef instanceof Ref) {
pageObjId = pageRef.toString();
}
const type =
kidDict.get("Type") instanceof Name ? kidDict.get("Type").name : null;
const type = kid.get("Type") instanceof Name ? kid.get("Type").name : null;
if (type === "MCR") {
if (this.tree.pageDict.objId !== pageObjId) {
return null;
}
const kidRef = kidDict.getRaw("Stm");
const kidRef = kid.getRaw("Stm");
return new StructElement({
type: StructElementType.STREAM_CONTENT,
refObjId: kidRef instanceof Ref ? kidRef.toString() : null,
pageObjId,
mcid: kidDict.get("MCID"),
mcid: kid.get("MCID"),
});
}
@ -626,7 +622,7 @@ class StructElementNode {
if (this.tree.pageDict.objId !== pageObjId) {
return null;
}
const kidRef = kidDict.getRaw("Obj");
const kidRef = kid.getRaw("Obj");
return new StructElement({
type: StructElementType.OBJECT,
refObjId: kidRef instanceof Ref ? kidRef.toString() : null,
@ -636,7 +632,7 @@ class StructElementNode {
return new StructElement({
type: StructElementType.ELEMENT,
dict: kidDict,
dict: kid,
});
}
}