Improve the "FontFallback" handling on the worker-thread
Remove the `Catalog.prototype.fontFallback` method, and move its code into `PDFDocument.prototype.fontFallback` instead, to reduce the indirection a little bit. Pass the `evaluatorOptions` directly to the `TranslatedFont.prototype.fallback` method, since nothing else in the `TranslatedFont`-class needs it now.
This commit is contained in:
parent
839e23f5c2
commit
d428db63c3
@ -1169,17 +1169,6 @@ class Catalog {
|
|||||||
return shadow(this, "jsActions", actions);
|
return shadow(this, "jsActions", actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fontFallback(id, handler) {
|
|
||||||
const translatedFonts = await Promise.all(this.fontCache);
|
|
||||||
|
|
||||||
for (const translatedFont of translatedFonts) {
|
|
||||||
if (translatedFont.loadedName === id) {
|
|
||||||
translatedFont.fallback(handler);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async cleanup(manuallyTriggered = false) {
|
async cleanup(manuallyTriggered = false) {
|
||||||
clearGlobalCaches();
|
clearGlobalCaches();
|
||||||
this.globalImageCache.clear(/* onlyData = */ manuallyTriggered);
|
this.globalImageCache.clear(/* onlyData = */ manuallyTriggered);
|
||||||
|
|||||||
@ -1745,8 +1745,15 @@ class PDFDocument {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fontFallback(id, handler) {
|
async fontFallback(id, handler) {
|
||||||
return this.catalog.fontFallback(id, handler);
|
const { catalog, pdfManager } = this;
|
||||||
|
|
||||||
|
for (const translatedFont of await Promise.all(catalog.fontCache)) {
|
||||||
|
if (translatedFont.loadedName === id) {
|
||||||
|
translatedFont.fallback(handler, pdfManager.evaluatorOptions);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async cleanup(manuallyTriggered = false) {
|
async cleanup(manuallyTriggered = false) {
|
||||||
|
|||||||
@ -1065,7 +1065,6 @@ class PartialEvaluator {
|
|||||||
loadedName: "g_font_error",
|
loadedName: "g_font_error",
|
||||||
font: new ErrorFont(`Type3 font load error: ${reason}`),
|
font: new ErrorFont(`Type3 font load error: ${reason}`),
|
||||||
dict: translated.font,
|
dict: translated.font,
|
||||||
evaluatorOptions: this.options,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1237,7 +1236,6 @@ class PartialEvaluator {
|
|||||||
loadedName: "g_font_error",
|
loadedName: "g_font_error",
|
||||||
font: new ErrorFont(`Font "${fontName}" is not available.`),
|
font: new ErrorFont(`Font "${fontName}" is not available.`),
|
||||||
dict: font,
|
dict: font,
|
||||||
evaluatorOptions: this.options,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let fontRef;
|
let fontRef;
|
||||||
@ -1364,7 +1362,6 @@ class PartialEvaluator {
|
|||||||
loadedName: font.loadedName,
|
loadedName: font.loadedName,
|
||||||
font: translatedFont,
|
font: translatedFont,
|
||||||
dict: font,
|
dict: font,
|
||||||
evaluatorOptions: this.options,
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
@ -1379,7 +1376,6 @@ class PartialEvaluator {
|
|||||||
reason instanceof Error ? reason.message : reason
|
reason instanceof Error ? reason.message : reason
|
||||||
),
|
),
|
||||||
dict: font,
|
dict: font,
|
||||||
evaluatorOptions: this.options,
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -4606,11 +4602,10 @@ class PartialEvaluator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TranslatedFont {
|
class TranslatedFont {
|
||||||
constructor({ loadedName, font, dict, evaluatorOptions }) {
|
constructor({ loadedName, font, dict }) {
|
||||||
this.loadedName = loadedName;
|
this.loadedName = loadedName;
|
||||||
this.font = font;
|
this.font = font;
|
||||||
this.dict = dict;
|
this.dict = dict;
|
||||||
this._evaluatorOptions = evaluatorOptions || DefaultPartialEvaluatorOptions;
|
|
||||||
this.type3Loaded = null;
|
this.type3Loaded = null;
|
||||||
this.type3Dependencies = font.isType3Font ? new Set() : null;
|
this.type3Dependencies = font.isType3Font ? new Set() : null;
|
||||||
this.sent = false;
|
this.sent = false;
|
||||||
@ -4629,7 +4624,7 @@ class TranslatedFont {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fallback(handler) {
|
fallback(handler, evaluatorOptions) {
|
||||||
if (!this.font.data) {
|
if (!this.font.data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -4645,7 +4640,7 @@ class TranslatedFont {
|
|||||||
this.font,
|
this.font,
|
||||||
/* glyphs = */ this.font.glyphCacheValues,
|
/* glyphs = */ this.font.glyphCacheValues,
|
||||||
handler,
|
handler,
|
||||||
this._evaluatorOptions
|
evaluatorOptions
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user