Skip to content

Commit

Permalink
Merge pull request #12478 from Snuffleupagus/async-translateFont
Browse files Browse the repository at this point in the history
Convert `PartialEvaluator.translateFont` to an `async` method
  • Loading branch information
timvandermeij authored Oct 15, 2020
2 parents ee665fc + bc6b47a commit b710fbc
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1111,15 +1111,7 @@ class PartialEvaluator {

font.translated = fontCapability.promise;

// TODO move promises into translate font
var translatedPromise;
try {
translatedPromise = this.translateFont(preEvaluatedFont);
} catch (e) {
translatedPromise = Promise.reject(e);
}

translatedPromise
this.translateFont(preEvaluatedFont)
.then(translatedFont => {
if (translatedFont.fontType !== undefined) {
var xrefFontStats = xref.stats.fontTypes;
Expand Down Expand Up @@ -3320,7 +3312,7 @@ class PartialEvaluator {
};
}

translateFont(preEvaluatedFont) {
async translateFont(preEvaluatedFont) {
var baseDict = preEvaluatedFont.baseDict;
var dict = preEvaluatedFont.dict;
var composite = preEvaluatedFont.composite;
Expand Down Expand Up @@ -3465,36 +3457,30 @@ class PartialEvaluator {
isType3Font: false,
};

var cMapPromise;
if (composite) {
var cidEncoding = baseDict.get("Encoding");
const cidEncoding = baseDict.get("Encoding");
if (isName(cidEncoding)) {
properties.cidEncoding = cidEncoding.name;
}
cMapPromise = CMapFactory.create({
const cMap = await CMapFactory.create({
encoding: cidEncoding,
fetchBuiltInCMap: this._fetchBuiltInCMapBound,
useCMap: null,
}).then(function (cMap) {
properties.cMap = cMap;
properties.vertical = properties.cMap.vertical;
});
} else {
cMapPromise = Promise.resolve(undefined);
properties.cMap = cMap;
properties.vertical = properties.cMap.vertical;
}

return cMapPromise
.then(() => {
return this.extractDataStructures(dict, baseDict, properties);
})
.then(newProperties => {
return this.extractDataStructures(dict, baseDict, properties).then(
newProperties => {
this.extractWidths(dict, descriptor, newProperties);

if (type === "Type3") {
newProperties.isType3Font = true;
}
return new Font(fontName.name, fontFile, newProperties);
});
}
);
}

static buildFontPaths(font, glyphs, handler) {
Expand Down

0 comments on commit b710fbc

Please sign in to comment.