Change the signature of TranslatedFont
, and convert it to a proper class
In preparation for the next patch, this changes the signature of `TranslatedFont` to take an object rather than individual parameters. This also, in my opinion, makes the call-sites easier to read since it essentially provides a small bit of documentation of the arguments. Finally, since it was necessary to touch `TranslatedFont` anyway it seemed like a good idea to also convert it to a proper `class`.
This commit is contained in:
parent
0400109b87
commit
2619272d73
@ -803,11 +803,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
this.handler.send("UnsupportedFeature", {
|
this.handler.send("UnsupportedFeature", {
|
||||||
featureId: UNSUPPORTED_FEATURES.font,
|
featureId: UNSUPPORTED_FEATURES.font,
|
||||||
});
|
});
|
||||||
return new TranslatedFont(
|
return new TranslatedFont({
|
||||||
"g_font_error",
|
loadedName: "g_font_error",
|
||||||
new ErrorFont("Type3 font load error: " + reason),
|
font: new ErrorFont(`Type3 font load error: ${reason}`),
|
||||||
translated.font
|
dict: translated.font,
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(translated => {
|
.then(translated => {
|
||||||
@ -958,11 +958,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
loadFont: function PartialEvaluator_loadFont(fontName, font, resources) {
|
loadFont: function PartialEvaluator_loadFont(fontName, font, resources) {
|
||||||
function errorFont() {
|
function errorFont() {
|
||||||
return Promise.resolve(
|
return Promise.resolve(
|
||||||
new TranslatedFont(
|
new TranslatedFont({
|
||||||
"g_font_error",
|
loadedName: "g_font_error",
|
||||||
new ErrorFont("Font " + fontName + " is not available"),
|
font: new ErrorFont(`Font "${fontName}" is not available.`),
|
||||||
font
|
dict: font,
|
||||||
)
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1103,7 +1103,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fontCapability.resolve(
|
fontCapability.resolve(
|
||||||
new TranslatedFont(font.loadedName, translatedFont, font)
|
new TranslatedFont({
|
||||||
|
loadedName: font.loadedName,
|
||||||
|
font: translatedFont,
|
||||||
|
dict: font,
|
||||||
|
})
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.catch(reason => {
|
.catch(reason => {
|
||||||
@ -1126,11 +1130,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
} catch (ex) {}
|
} catch (ex) {}
|
||||||
|
|
||||||
fontCapability.resolve(
|
fontCapability.resolve(
|
||||||
new TranslatedFont(
|
new TranslatedFont({
|
||||||
font.loadedName,
|
loadedName: font.loadedName,
|
||||||
new ErrorFont(reason instanceof Error ? reason.message : reason),
|
font: new ErrorFont(
|
||||||
font
|
reason instanceof Error ? reason.message : reason
|
||||||
)
|
),
|
||||||
|
dict: font,
|
||||||
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
return fontCapability.promise;
|
return fontCapability.promise;
|
||||||
@ -3266,16 +3272,15 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
return PartialEvaluator;
|
return PartialEvaluator;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var TranslatedFont = (function TranslatedFontClosure() {
|
class TranslatedFont {
|
||||||
// eslint-disable-next-line no-shadow
|
constructor({ loadedName, font, dict }) {
|
||||||
function TranslatedFont(loadedName, font, dict) {
|
|
||||||
this.loadedName = loadedName;
|
this.loadedName = loadedName;
|
||||||
this.font = font;
|
this.font = font;
|
||||||
this.dict = dict;
|
this.dict = dict;
|
||||||
this.type3Loaded = null;
|
this.type3Loaded = null;
|
||||||
this.sent = false;
|
this.sent = false;
|
||||||
}
|
}
|
||||||
TranslatedFont.prototype = {
|
|
||||||
send(handler) {
|
send(handler) {
|
||||||
if (this.sent) {
|
if (this.sent) {
|
||||||
return;
|
return;
|
||||||
@ -3287,7 +3292,7 @@ var TranslatedFont = (function TranslatedFontClosure() {
|
|||||||
"Font",
|
"Font",
|
||||||
this.font.exportData(),
|
this.font.exportData(),
|
||||||
]);
|
]);
|
||||||
},
|
}
|
||||||
|
|
||||||
fallback(handler) {
|
fallback(handler) {
|
||||||
if (!this.font.data) {
|
if (!this.font.data) {
|
||||||
@ -3303,7 +3308,7 @@ var TranslatedFont = (function TranslatedFontClosure() {
|
|||||||
// font loading failed, attempt to resend *all* previously parsed glyphs.
|
// font loading failed, attempt to resend *all* previously parsed glyphs.
|
||||||
const glyphs = this.font.glyphCacheValues;
|
const glyphs = this.font.glyphCacheValues;
|
||||||
PartialEvaluator.buildFontPaths(this.font, glyphs, handler);
|
PartialEvaluator.buildFontPaths(this.font, glyphs, handler);
|
||||||
},
|
}
|
||||||
|
|
||||||
loadType3Data(evaluator, resources, parentOperatorList, task) {
|
loadType3Data(evaluator, resources, parentOperatorList, task) {
|
||||||
if (!this.font.isType3Font) {
|
if (!this.font.isType3Font) {
|
||||||
@ -3363,10 +3368,8 @@ var TranslatedFont = (function TranslatedFontClosure() {
|
|||||||
translatedFont.charProcOperatorList = charProcOperatorList;
|
translatedFont.charProcOperatorList = charProcOperatorList;
|
||||||
});
|
});
|
||||||
return this.type3Loaded;
|
return this.type3Loaded;
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
return TranslatedFont;
|
|
||||||
})();
|
|
||||||
|
|
||||||
var StateManager = (function StateManagerClosure() {
|
var StateManager = (function StateManagerClosure() {
|
||||||
// eslint-disable-next-line no-shadow
|
// eslint-disable-next-line no-shadow
|
||||||
|
Loading…
x
Reference in New Issue
Block a user