Skip to content

Commit

Permalink
Fix annotations parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ekaterina-chubrick committed Nov 11, 2024
1 parent bd1202a commit e57f8c2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ class Annotation {
const isLocked = !!(this.flags & AnnotationFlag.LOCKED);
const isContentLocked = !!(this.flags & AnnotationFlag.LOCKEDCONTENTS);

console.log(annotationGlobals.structTreeRoot);
if (annotationGlobals.structTreeRoot) {
let structParent = dict.get("StructParent");
structParent =
Expand Down
16 changes: 8 additions & 8 deletions src/core/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@ class ExtendedCatalog extends Catalog {
super(pdfManager, xref);

this.pages = this.getPages(this.toplevelPagesDict.get("Kids"));
this.roleMap = this.getRoleMap(this.structTreeRoot);
this.roleMap = this.getRoleMap(this.structTreeRootObject);
}

_convertStructToObject(struct) {
Expand All @@ -1779,12 +1779,12 @@ class ExtendedCatalog extends Catalog {
return struct;
}

get structTreeRoot() {
get structTreeRootObject() {
const structTreeRoot = this._catDict.get("StructTreeRoot");
if ((!structTreeRoot) instanceof Dict) {
return null;
}
return shadow(this, "structTreeRoot", structTreeRoot);
return shadow(this, "structTreeRootObject", structTreeRoot);
}

getTreeElement(el, page, ref) {
Expand Down Expand Up @@ -1953,14 +1953,14 @@ class ExtendedCatalog extends Catalog {
get structureTree() {
let structureTree = null;
if (
this.structTreeRoot &&
this.structTreeRoot instanceof Dict &&
this.structTreeRoot.has("K")
this.structTreeRootObject &&
this.structTreeRootObject instanceof Dict &&
this.structTreeRootObject.has("K")
) {
structureTree = this.getTreeElement(
this.structTreeRoot.get("K"),
this.structTreeRootObject.get("K"),
null,
this.structTreeRoot.getRaw("K")
this.structTreeRootObject.getRaw("K")
);
}
return shadow(this, "structureTree", structureTree);
Expand Down
46 changes: 31 additions & 15 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,11 @@ class Page {
operatorList: opList,
intent,
})
.then(function ([boundingBoxesByMCID, operationArray, boundingBoxesWithoutMCID]) {
.then(function ([
boundingBoxesByMCID,
operationArray,
boundingBoxesWithoutMCID,
]) {
MCIDBoundingBoxes = boundingBoxesByMCID;
positionByOperationIndex = operationArray;
noMCIDBoundingBoxes = boundingBoxesWithoutMCID;
Expand Down Expand Up @@ -573,7 +577,10 @@ class Page {
if (intent & RenderingIntentFlag.OPLIST) {
pageOpList.addOp(OPS.annotBBoxesAndOpPos, []);
pageOpList.addOp(OPS.operationPosition, positionByOperationIndex);
pageOpList.addOp(OPS.boundingBoxes, [MCIDBoundingBoxes, noMCIDBoundingBoxes]);
pageOpList.addOp(OPS.boundingBoxes, [
MCIDBoundingBoxes,
noMCIDBoundingBoxes,
]);
}
pageOpList.flush(/* lastChunk = */ true);
return { length: pageOpList.totalLength };
Expand Down Expand Up @@ -623,22 +630,31 @@ class Page {
canvas = false;

const annotationsBBoxesAndOperationPosition = [];
for (const { opList, separateForm, separateCanvas, annotBBoxesAndOpPos } of opLists) {
for (const {
opList,
separateForm,
separateCanvas,
annotBBoxesAndOpPos,
} of opLists) {
pageOpList.addOpList(opList);


form ||= separateForm;
canvas ||= separateCanvas;

annotationsBBoxesAndOperationPosition.push(
annotBBoxesAndOpPos ? [
annotBBoxesAndOpPos.operationPosition,
annotBBoxesAndOpPos.boundingBoxes,
] : []
annotBBoxesAndOpPos
? [
annotBBoxesAndOpPos.operationPosition,
annotBBoxesAndOpPos.boundingBoxes,
]
: []
);
}
if (intent & RenderingIntentFlag.OPLIST) {
pageOpList.addOp(OPS.annotBBoxesAndOpPos, annotationsBBoxesAndOperationPosition);
pageOpList.addOp(
OPS.annotBBoxesAndOpPos,
annotationsBBoxesAndOperationPosition
);
pageOpList.addOp(OPS.operationPosition, positionByOperationIndex);
pageOpList.addOp(OPS.boundingBoxes, [
MCIDBoundingBoxes,
Expand Down Expand Up @@ -736,17 +752,16 @@ class Page {

const intentAny = !!(intent & RenderingIntentFlag.ANY),
intentDisplay = !!(intent & RenderingIntentFlag.DISPLAY),
intentPrint = !!(intent & RenderingIntentFlag.PRINT);
intentPrint = !!(intent & RenderingIntentFlag.PRINT),
intentOplist = !!(intent & RenderingIntentFlag.OPLIST);

console.log(annotations);
for (const annotation of annotations) {
// Get the annotation even if it's hidden because
// JS can change its display.
const isVisible = intentAny || (intentDisplay && annotation.viewable);
if (
isVisible ||
(intentPrint && annotation.printable) ||
intent & RenderingIntentFlag.OPLIST
) {
console.log(isVisible, intentPrint && annotation.printable, intentOplist);
if (isVisible || (intentPrint && annotation.printable) || intentOplist) {
annotationsData.push(annotation.data);
}

Expand Down Expand Up @@ -782,6 +797,7 @@ class Page {
}

await Promise.all(textContentPromises);
console.log("annotationsData", annotationsData);
return annotationsData;
}

Expand Down

0 comments on commit e57f8c2

Please sign in to comment.