Skip to content

Commit d46d472

Browse files
Fix annotations parsing
1 parent bd1202a commit d46d472

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

src/core/catalog.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ class ExtendedCatalog extends Catalog {
17611761
super(pdfManager, xref);
17621762

17631763
this.pages = this.getPages(this.toplevelPagesDict.get("Kids"));
1764-
this.roleMap = this.getRoleMap(this.structTreeRoot);
1764+
this.roleMap = this.getRoleMap(this.structTreeRootObject);
17651765
}
17661766

17671767
_convertStructToObject(struct) {
@@ -1779,12 +1779,12 @@ class ExtendedCatalog extends Catalog {
17791779
return struct;
17801780
}
17811781

1782-
get structTreeRoot() {
1782+
get structTreeRootObject() {
17831783
const structTreeRoot = this._catDict.get("StructTreeRoot");
17841784
if ((!structTreeRoot) instanceof Dict) {
17851785
return null;
17861786
}
1787-
return shadow(this, "structTreeRoot", structTreeRoot);
1787+
return shadow(this, "structTreeRootObject", structTreeRoot);
17881788
}
17891789

17901790
getTreeElement(el, page, ref) {
@@ -1953,14 +1953,14 @@ class ExtendedCatalog extends Catalog {
19531953
get structureTree() {
19541954
let structureTree = null;
19551955
if (
1956-
this.structTreeRoot &&
1957-
this.structTreeRoot instanceof Dict &&
1958-
this.structTreeRoot.has("K")
1956+
this.structTreeRootObject &&
1957+
this.structTreeRootObject instanceof Dict &&
1958+
this.structTreeRootObject.has("K")
19591959
) {
19601960
structureTree = this.getTreeElement(
1961-
this.structTreeRoot.get("K"),
1961+
this.structTreeRootObject.get("K"),
19621962
null,
1963-
this.structTreeRoot.getRaw("K")
1963+
this.structTreeRootObject.getRaw("K")
19641964
);
19651965
}
19661966
return shadow(this, "structureTree", structureTree);

src/core/document.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,11 @@ class Page {
529529
operatorList: opList,
530530
intent,
531531
})
532-
.then(function ([boundingBoxesByMCID, operationArray, boundingBoxesWithoutMCID]) {
532+
.then(function ([
533+
boundingBoxesByMCID,
534+
operationArray,
535+
boundingBoxesWithoutMCID,
536+
]) {
533537
MCIDBoundingBoxes = boundingBoxesByMCID;
534538
positionByOperationIndex = operationArray;
535539
noMCIDBoundingBoxes = boundingBoxesWithoutMCID;
@@ -573,7 +577,10 @@ class Page {
573577
if (intent & RenderingIntentFlag.OPLIST) {
574578
pageOpList.addOp(OPS.annotBBoxesAndOpPos, []);
575579
pageOpList.addOp(OPS.operationPosition, positionByOperationIndex);
576-
pageOpList.addOp(OPS.boundingBoxes, [MCIDBoundingBoxes, noMCIDBoundingBoxes]);
580+
pageOpList.addOp(OPS.boundingBoxes, [
581+
MCIDBoundingBoxes,
582+
noMCIDBoundingBoxes,
583+
]);
577584
}
578585
pageOpList.flush(/* lastChunk = */ true);
579586
return { length: pageOpList.totalLength };
@@ -623,22 +630,31 @@ class Page {
623630
canvas = false;
624631

625632
const annotationsBBoxesAndOperationPosition = [];
626-
for (const { opList, separateForm, separateCanvas, annotBBoxesAndOpPos } of opLists) {
633+
for (const {
634+
opList,
635+
separateForm,
636+
separateCanvas,
637+
annotBBoxesAndOpPos,
638+
} of opLists) {
627639
pageOpList.addOpList(opList);
628640

629-
630641
form ||= separateForm;
631642
canvas ||= separateCanvas;
632643

633644
annotationsBBoxesAndOperationPosition.push(
634-
annotBBoxesAndOpPos ? [
635-
annotBBoxesAndOpPos.operationPosition,
636-
annotBBoxesAndOpPos.boundingBoxes,
637-
] : []
645+
annotBBoxesAndOpPos
646+
? [
647+
annotBBoxesAndOpPos.operationPosition,
648+
annotBBoxesAndOpPos.boundingBoxes,
649+
]
650+
: []
638651
);
639652
}
640653
if (intent & RenderingIntentFlag.OPLIST) {
641-
pageOpList.addOp(OPS.annotBBoxesAndOpPos, annotationsBBoxesAndOperationPosition);
654+
pageOpList.addOp(
655+
OPS.annotBBoxesAndOpPos,
656+
annotationsBBoxesAndOperationPosition
657+
);
642658
pageOpList.addOp(OPS.operationPosition, positionByOperationIndex);
643659
pageOpList.addOp(OPS.boundingBoxes, [
644660
MCIDBoundingBoxes,
@@ -736,17 +752,14 @@ class Page {
736752

737753
const intentAny = !!(intent & RenderingIntentFlag.ANY),
738754
intentDisplay = !!(intent & RenderingIntentFlag.DISPLAY),
739-
intentPrint = !!(intent & RenderingIntentFlag.PRINT);
755+
intentPrint = !!(intent & RenderingIntentFlag.PRINT),
756+
intentOplist = !!(intent & RenderingIntentFlag.OPLIST);
740757

741758
for (const annotation of annotations) {
742759
// Get the annotation even if it's hidden because
743760
// JS can change its display.
744761
const isVisible = intentAny || (intentDisplay && annotation.viewable);
745-
if (
746-
isVisible ||
747-
(intentPrint && annotation.printable) ||
748-
intent & RenderingIntentFlag.OPLIST
749-
) {
762+
if (isVisible || (intentPrint && annotation.printable) || intentOplist) {
750763
annotationsData.push(annotation.data);
751764
}
752765

0 commit comments

Comments
 (0)