diff --git a/src/core/annotation.js b/src/core/annotation.js index 6aa8b4d2067ee..976b1369b85bd 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -447,6 +447,7 @@ class Annotation { this.setColor(dict.getArray("C")); this.setBorderStyle(dict); this.setAppearance(dict); + this.initAppearancePos = this.appearance?.pos; this.setOptionalContent(dict); const MK = dict.get("MK"); @@ -921,8 +922,10 @@ class Annotation { isUsingOwnCanvas, ]); - await evaluator.getOperatorList({ + const [MCIDBBoxes, opPos, noMCIDBBoxes] = await evaluator.getOperatorList({ + initStreamPos: this.initAppearancePos, stream: appearance, + intent, task, resources, operatorList: opList, @@ -934,7 +937,15 @@ class Annotation { opList.addOp(OPS.endMarkedContent, []); } this.reset(); - return { opList, separateForm: false, separateCanvas: isUsingOwnCanvas }; + return { + opList, + separateForm: false, + separateCanvas: isUsingOwnCanvas, + annotBBoxesAndOpPos: { + operationPosition: opPos, + boundingBoxes: [MCIDBBoxes, noMCIDBBoxes], + }, + }; } async save(evaluator, task, annotationStorage) { @@ -1743,7 +1754,8 @@ class WidgetAnnotation extends Annotation { ]); const stream = new StringStream(content); - await evaluator.getOperatorList({ + const [MCIDBBoxes, opPos, noMCIDBBoxes] = await evaluator.getOperatorList({ + intent, stream, task, resources: this._fieldResources.mergedResources, @@ -1754,7 +1766,15 @@ class WidgetAnnotation extends Annotation { if (optionalContent !== undefined) { opList.addOp(OPS.endMarkedContent, []); } - return { opList, separateForm: false, separateCanvas: false }; + return { + opList, + separateForm: false, + separateCanvas: false, + annotBBoxesAndOpPos: { + operationPosition: opPos, + boundingBoxes: [MCIDBBoxes, noMCIDBBoxes], + }, + }; } _getMKDict(rotation) { diff --git a/src/core/document.js b/src/core/document.js index bd074259d33bd..bc0c6673eb426 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -462,6 +462,7 @@ class Page { intent & RenderingIntentFlag.ANNOTATIONS_DISABLE ) { if (intent & RenderingIntentFlag.OPLIST) { + pageOpList.addOp(OPS.annotBBoxesAndOpPos, []); pageOpList.addOp(OPS.operationPosition, positionByOperationIndex); pageOpList.addOp(OPS.boundingBoxes, [MCIDBoundingBoxes, noMCIDBoundingBoxes]); } @@ -507,7 +508,8 @@ class Page { let form = false, canvas = false; - for (const { opList, separateForm, separateCanvas } of opLists) { + const annotationsBBoxesAndOperationPosition = []; + for (const { opList, separateForm, separateCanvas, annotBBoxesAndOpPos } of opLists) { pageOpList.addOpList(opList); if (separateForm) { @@ -516,8 +518,16 @@ class Page { if (separateCanvas) { canvas = separateCanvas; } + + annotationsBBoxesAndOperationPosition.push( + annotBBoxesAndOpPos ? [ + annotBBoxesAndOpPos.operationPosition, + annotBBoxesAndOpPos.boundingBoxes, + ] : [] + ); } if (intent & RenderingIntentFlag.OPLIST) { + pageOpList.addOp(OPS.annotBBoxesAndOpPos, annotationsBBoxesAndOperationPosition); pageOpList.addOp(OPS.operationPosition, positionByOperationIndex); pageOpList.addOp(OPS.boundingBoxes, [ MCIDBoundingBoxes, diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 5e750890af727..850d0d8aa0074 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -1636,6 +1636,7 @@ class PartialEvaluator { } getOperatorList({ + initStreamPos, stream, task, resources, @@ -1657,6 +1658,8 @@ class PartialEvaluator { var self = this; var xref = this.xref; let parsingText = false; + let prevStreamPos; + if (initStreamPos != null) stream.pos = initStreamPos; const localImageCache = new LocalImageCache(); const localColorSpaceCache = new LocalColorSpaceCache(); const localGStateCache = new LocalGStateCache(); @@ -1691,6 +1694,7 @@ class PartialEvaluator { const operation = {}; let stop, i, ii, cs, name, isValidName; while (!(stop = timeSlotManager.check())) { + if (prevStreamPos) stream.pos = prevStreamPos; // The arguments parsed by read() are used beyond this loop, so we // cannot reuse the same array on each iteration. Therefore we pass // in |null| as the initial value (see the comment on @@ -1703,6 +1707,7 @@ class PartialEvaluator { let fn = operation.fn; boundingBoxCalculator.incrementOperation(fn); + prevStreamPos = stream.pos; switch (fn | 0) { case OPS.paintXObject: // eagerly compile XForm objects diff --git a/src/shared/util.js b/src/shared/util.js index bf5e7ce0d2ee1..09250996650a4 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -365,7 +365,8 @@ const OPS = { paintSolidColorImageMask: 90, constructPath: 91, boundingBoxes: 100, - operationPosition: 101 + operationPosition: 101, + annotBBoxesAndOpPos: 102, }; const UNSUPPORTED_FEATURES = {