mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
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:
parent
ce52ce063e
commit
27436d52b2
1 changed files with 62 additions and 61 deletions
|
@ -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;
|
||||
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 newAnnotations) {
|
||||
if (bitmapId && !bitmap && !missingBitmaps.has(bitmapId)) {
|
||||
missingBitmaps.add(bitmapId);
|
||||
// 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 = newAnnots.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 = newAnnotations.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
|
||||
);
|
||||
}
|
||||
|
||||
deletedAnnotations = new RefSet();
|
||||
this.#replaceIdByRef(newAnnotations, deletedAnnotations, null);
|
||||
|
||||
newAnnotationsPromise = annotationGlobalsPromise.then(
|
||||
annotationGlobals => {
|
||||
if (!annotationGlobals) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return AnnotationFactory.printNewAnnotations(
|
||||
annotationGlobals,
|
||||
partialEvaluator,
|
||||
task,
|
||||
newAnnotations,
|
||||
imagePromises
|
||||
);
|
||||
}
|
||||
// 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(newAnnots, deletedAnnotations, null);
|
||||
|
||||
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", {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue