Convert the handleSetFont methods, in src/core/evaluator.js, to be async

This commit is contained in:
Jonas Jenwald 2024-01-21 17:32:05 +01:00
parent fce822cde0
commit fc62eec901

View File

@ -1007,7 +1007,7 @@ class PartialEvaluator {
}); });
} }
handleSetFont( async handleSetFont(
resources, resources,
fontArgs, fontArgs,
fontRef, fontRef,
@ -1019,41 +1019,33 @@ class PartialEvaluator {
) { ) {
const fontName = fontArgs?.[0] instanceof Name ? fontArgs[0].name : null; const fontName = fontArgs?.[0] instanceof Name ? fontArgs[0].name : null;
return this.loadFont( let translated = await this.loadFont(
fontName, fontName,
fontRef, fontRef,
resources, resources,
fallbackFontDict, fallbackFontDict,
cssFontInfo cssFontInfo
) );
.then(translated => {
if (!translated.font.isType3Font) {
return translated;
}
return translated
.loadType3Data(this, resources, task)
.then(function () {
// Add the dependencies to the parent operatorList so they are
// resolved before Type3 operatorLists are executed synchronously.
operatorList.addDependencies(translated.type3Dependencies);
return translated; if (translated.font.isType3Font) {
}) try {
.catch( await translated.loadType3Data(this, resources, task);
reason => // Add the dependencies to the parent operatorList so they are
new TranslatedFont({ // resolved before Type3 operatorLists are executed synchronously.
loadedName: "g_font_error", operatorList.addDependencies(translated.type3Dependencies);
font: new ErrorFont(`Type3 font load error: ${reason}`), } catch (reason) {
dict: translated.font, translated = new TranslatedFont({
evaluatorOptions: this.options, loadedName: "g_font_error",
}) font: new ErrorFont(`Type3 font load error: ${reason}`),
); dict: translated.font,
}) evaluatorOptions: this.options,
.then(translated => { });
state.font = translated.font; }
translated.send(this.handler); }
return translated.loadedName;
}); state.font = translated.font;
translated.send(this.handler);
return translated.loadedName;
} }
handleText(chars, state) { handleText(chars, state) {
@ -2560,29 +2552,21 @@ class PartialEvaluator {
}; };
} }
function handleSetFont(fontName, fontRef) { async function handleSetFont(fontName, fontRef) {
return self const translated = await self.loadFont(fontName, fontRef, resources);
.loadFont(fontName, fontRef, resources)
.then(function (translated) { if (translated.font.isType3Font) {
if (!translated.font.isType3Font) { try {
return translated; await translated.loadType3Data(self, resources, task);
} } catch {
return translated // Ignore Type3-parsing errors, since we only use `loadType3Data`
.loadType3Data(self, resources, task) // here to ensure that we'll always obtain a useful /FontBBox.
.catch(function () { }
// Ignore Type3-parsing errors, since we only use `loadType3Data` }
// here to ensure that we'll always obtain a useful /FontBBox.
}) textState.loadedName = translated.loadedName;
.then(function () { textState.font = translated.font;
return translated; textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
});
})
.then(function (translated) {
textState.loadedName = translated.loadedName;
textState.font = translated.font;
textState.fontMatrix =
translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
});
} }
function applyInverseRotation(x, y, matrix) { function applyInverseRotation(x, y, matrix) {