Reduce indentation when parsing new annotations in getOperatorList

This code has, over the years, become more complex and less indentation generally helps readability.
This commit is contained in:
Jonas Jenwald 2024-05-25 11:53:59 +02:00
parent ce52ce063e
commit 27436d52b2

View File

@ -436,15 +436,14 @@ 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) {
if (newAnnots) {
const annotationGlobalsPromise =
this.pdfManager.ensureDoc("annotationGlobals");
let imagePromises;
@ -453,7 +452,7 @@ class Page {
// 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) {
for (const { bitmapId, bitmap } of newAnnots) {
if (bitmapId && !bitmap && !missingBitmaps.has(bitmapId)) {
missingBitmaps.add(bitmapId);
}
@ -461,7 +460,7 @@ class Page {
const { isOffscreenCanvasSupported } = this.evaluatorOptions;
if (missingBitmaps.size > 0) {
const annotationWithBitmaps = newAnnotations.slice();
const annotationWithBitmaps = newAnnots.slice();
for (const [key, annotation] of annotationStorage) {
if (!key.startsWith(AnnotationEditorPrefix)) {
continue;
@ -479,14 +478,14 @@ class Page {
);
} else {
imagePromises = AnnotationFactory.generateImages(
newAnnotations,
newAnnots,
this.xref,
isOffscreenCanvasSupported
);
}
deletedAnnotations = new RefSet();
this.#replaceIdByRef(newAnnotations, deletedAnnotations, null);
this.#replaceIdByRef(newAnnots, deletedAnnotations, null);
newAnnotationsPromise = annotationGlobalsPromise.then(
annotationGlobals => {
@ -498,15 +497,17 @@ class Page {
annotationGlobals,
partialEvaluator,
task,
newAnnotations,
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", {