mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
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
3 changed files with 12 additions and 21 deletions
|
@ -1169,17 +1169,6 @@ class Catalog {
|
|||
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) {
|
||||
clearGlobalCaches();
|
||||
this.globalImageCache.clear(/* onlyData = */ manuallyTriggered);
|
||||
|
|
|
@ -1745,8 +1745,15 @@ class PDFDocument {
|
|||
}
|
||||
}
|
||||
|
||||
fontFallback(id, handler) {
|
||||
return this.catalog.fontFallback(id, handler);
|
||||
async 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) {
|
||||
|
|
|
@ -1065,7 +1065,6 @@ class PartialEvaluator {
|
|||
loadedName: "g_font_error",
|
||||
font: new ErrorFont(`Type3 font load error: ${reason}`),
|
||||
dict: translated.font,
|
||||
evaluatorOptions: this.options,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1237,7 +1236,6 @@ class PartialEvaluator {
|
|||
loadedName: "g_font_error",
|
||||
font: new ErrorFont(`Font "${fontName}" is not available.`),
|
||||
dict: font,
|
||||
evaluatorOptions: this.options,
|
||||
});
|
||||
|
||||
let fontRef;
|
||||
|
@ -1364,7 +1362,6 @@ class PartialEvaluator {
|
|||
loadedName: font.loadedName,
|
||||
font: translatedFont,
|
||||
dict: font,
|
||||
evaluatorOptions: this.options,
|
||||
})
|
||||
);
|
||||
})
|
||||
|
@ -1379,7 +1376,6 @@ class PartialEvaluator {
|
|||
reason instanceof Error ? reason.message : reason
|
||||
),
|
||||
dict: font,
|
||||
evaluatorOptions: this.options,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -4606,11 +4602,10 @@ class PartialEvaluator {
|
|||
}
|
||||
|
||||
class TranslatedFont {
|
||||
constructor({ loadedName, font, dict, evaluatorOptions }) {
|
||||
constructor({ loadedName, font, dict }) {
|
||||
this.loadedName = loadedName;
|
||||
this.font = font;
|
||||
this.dict = dict;
|
||||
this._evaluatorOptions = evaluatorOptions || DefaultPartialEvaluatorOptions;
|
||||
this.type3Loaded = null;
|
||||
this.type3Dependencies = font.isType3Font ? new Set() : null;
|
||||
this.sent = false;
|
||||
|
@ -4629,7 +4624,7 @@ class TranslatedFont {
|
|||
]);
|
||||
}
|
||||
|
||||
fallback(handler) {
|
||||
fallback(handler, evaluatorOptions) {
|
||||
if (!this.font.data) {
|
||||
return;
|
||||
}
|
||||
|
@ -4645,7 +4640,7 @@ class TranslatedFont {
|
|||
this.font,
|
||||
/* glyphs = */ this.font.glyphCacheValues,
|
||||
handler,
|
||||
this._evaluatorOptions
|
||||
evaluatorOptions
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue