diff --git a/src/core/document.js b/src/core/document.js index 691ba8802cee7..505cd9a75834b 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -436,77 +436,78 @@ class Page { options: this.evaluatorOptions, }); - const newAnnotationsByPage = !this.xfaFactory + const newAnnotsByPage = !this.xfaFactory ? getNewAnnotationsMap(annotationStorage) : null; + const newAnnots = newAnnotsByPage?.get(this.pageIndex); + let newAnnotationsPromise = Promise.resolve(null); let deletedAnnotations = null; - let newAnnotationsPromise = Promise.resolve(null); - if (newAnnotationsByPage) { - const newAnnotations = newAnnotationsByPage.get(this.pageIndex); - if (newAnnotations) { - const annotationGlobalsPromise = - this.pdfManager.ensureDoc("annotationGlobals"); - let imagePromises; - - // An annotation can contain a reference to a bitmap, but this bitmap - // is defined in another annotation. So we need to find this annotation - // and generate the bitmap. - const missingBitmaps = new Set(); - for (const { bitmapId, bitmap } of newAnnotations) { - if (bitmapId && !bitmap && !missingBitmaps.has(bitmapId)) { - missingBitmaps.add(bitmapId); - } + if (newAnnots) { + const annotationGlobalsPromise = + this.pdfManager.ensureDoc("annotationGlobals"); + let imagePromises; + + // An annotation can contain a reference to a bitmap, but this bitmap + // is defined in another annotation. So we need to find this annotation + // and generate the bitmap. + const missingBitmaps = new Set(); + for (const { bitmapId, bitmap } of newAnnots) { + if (bitmapId && !bitmap && !missingBitmaps.has(bitmapId)) { + missingBitmaps.add(bitmapId); } + } - const { isOffscreenCanvasSupported } = this.evaluatorOptions; - if (missingBitmaps.size > 0) { - const annotationWithBitmaps = newAnnotations.slice(); - for (const [key, annotation] of annotationStorage) { - if (!key.startsWith(AnnotationEditorPrefix)) { - continue; - } - if (annotation.bitmap && missingBitmaps.has(annotation.bitmapId)) { - annotationWithBitmaps.push(annotation); - } + const { isOffscreenCanvasSupported } = this.evaluatorOptions; + if (missingBitmaps.size > 0) { + const annotationWithBitmaps = newAnnots.slice(); + for (const [key, annotation] of annotationStorage) { + if (!key.startsWith(AnnotationEditorPrefix)) { + continue; + } + if (annotation.bitmap && missingBitmaps.has(annotation.bitmapId)) { + annotationWithBitmaps.push(annotation); } - // The array annotationWithBitmaps cannot be empty: the check above - // makes sure to have at least one annotation containing the bitmap. - imagePromises = AnnotationFactory.generateImages( - annotationWithBitmaps, - this.xref, - isOffscreenCanvasSupported - ); - } else { - imagePromises = AnnotationFactory.generateImages( - newAnnotations, - this.xref, - isOffscreenCanvasSupported - ); } + // The array annotationWithBitmaps cannot be empty: the check above + // makes sure to have at least one annotation containing the bitmap. + imagePromises = AnnotationFactory.generateImages( + annotationWithBitmaps, + this.xref, + isOffscreenCanvasSupported + ); + } else { + imagePromises = AnnotationFactory.generateImages( + newAnnots, + this.xref, + isOffscreenCanvasSupported + ); + } - deletedAnnotations = new RefSet(); - this.#replaceIdByRef(newAnnotations, deletedAnnotations, null); + deletedAnnotations = new RefSet(); + this.#replaceIdByRef(newAnnots, deletedAnnotations, null); - newAnnotationsPromise = annotationGlobalsPromise.then( - annotationGlobals => { - if (!annotationGlobals) { - return null; - } - - return AnnotationFactory.printNewAnnotations( - annotationGlobals, - partialEvaluator, - task, - newAnnotations, - imagePromises - ); + newAnnotationsPromise = annotationGlobalsPromise.then( + annotationGlobals => { + if (!annotationGlobals) { + return null; } - ); - } + + return AnnotationFactory.printNewAnnotations( + annotationGlobals, + partialEvaluator, + task, + newAnnots, + imagePromises + ); + } + ); } - const dataPromises = Promise.all([contentStreamPromise, resourcesPromise]); - const pageListPromise = dataPromises.then(([contentStream]) => { + + const pageListPromise = Promise.all([ + contentStreamPromise, + resourcesPromise, + ]).then(([contentStream]) => { const opList = new OperatorList(intent, sink); handler.send("StartRenderPage", {