Merge pull request #18169 from Snuffleupagus/worker-shorter-code
Slightly shorten some worker-thread code
This commit is contained in:
commit
aac738c805
@ -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", {
|
||||
|
||||
@ -224,7 +224,7 @@ class PartialEvaluator {
|
||||
this.globalImageCache = globalImageCache;
|
||||
this.systemFontCache = systemFontCache;
|
||||
this.options = options || DefaultPartialEvaluatorOptions;
|
||||
this.parsingType3Font = false;
|
||||
this.type3FontRefs = null;
|
||||
|
||||
this._regionalImageCache = new RegionalImageCache();
|
||||
this._fetchBuiltInCMapBound = this.fetchBuiltInCMap.bind(this);
|
||||
@ -243,6 +243,10 @@ class PartialEvaluator {
|
||||
return shadow(this, "_pdfFunctionFactory", pdfFunctionFactory);
|
||||
}
|
||||
|
||||
get parsingType3Font() {
|
||||
return !!this.type3FontRefs;
|
||||
}
|
||||
|
||||
clone(newOptions = null) {
|
||||
const newEvaluator = Object.create(this);
|
||||
newEvaluator.options = Object.assign(
|
||||
@ -1253,7 +1257,7 @@ class PartialEvaluator {
|
||||
}
|
||||
}
|
||||
if (fontRef) {
|
||||
if (this.parsingType3Font && this.type3FontRefs.has(fontRef)) {
|
||||
if (this.type3FontRefs?.has(fontRef)) {
|
||||
return errorFont();
|
||||
}
|
||||
|
||||
@ -4633,7 +4637,6 @@ class TranslatedFont {
|
||||
// Compared to the parsing of e.g. an entire page, it doesn't really
|
||||
// make sense to only be able to render a Type3 glyph partially.
|
||||
const type3Evaluator = evaluator.clone({ ignoreErrors: false });
|
||||
type3Evaluator.parsingType3Font = true;
|
||||
// Prevent circular references in Type3 fonts.
|
||||
const type3FontRefs = new RefSet(evaluator.type3FontRefs);
|
||||
if (this.dict.objId && !type3FontRefs.has(this.dict.objId)) {
|
||||
|
||||
@ -710,11 +710,10 @@ class Parser {
|
||||
this.shift(); // 'stream'
|
||||
} else {
|
||||
// Bad stream length, scanning for endstream command.
|
||||
const actualLength = this.#findStreamLength(startPos);
|
||||
if (actualLength < 0) {
|
||||
length = this.#findStreamLength(startPos);
|
||||
if (length < 0) {
|
||||
throw new FormatError("Missing endstream command.");
|
||||
}
|
||||
length = actualLength;
|
||||
|
||||
lexer.nextChar();
|
||||
this.shift();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user