Convert the PartialEvaluator.readToUnicode method to be async

This commit is contained in:
Jonas Jenwald 2024-01-22 12:44:32 +01:00
parent f5c01188dc
commit f21a30dfb4

View File

@ -3765,28 +3765,30 @@ class PartialEvaluator {
return new IdentityToUnicodeMap(properties.firstChar, properties.lastChar); return new IdentityToUnicodeMap(properties.firstChar, properties.lastChar);
} }
readToUnicode(cmapObj) { async readToUnicode(cmapObj) {
if (!cmapObj) { if (!cmapObj) {
return Promise.resolve(null); return null;
} }
if (cmapObj instanceof Name) { if (cmapObj instanceof Name) {
return CMapFactory.create({ const cmap = await CMapFactory.create({
encoding: cmapObj, encoding: cmapObj,
fetchBuiltInCMap: this._fetchBuiltInCMapBound, fetchBuiltInCMap: this._fetchBuiltInCMapBound,
useCMap: null, useCMap: null,
}).then(function (cmap) { });
if (cmap instanceof IdentityCMap) { if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xffff); return new IdentityToUnicodeMap(0, 0xffff);
} }
return new ToUnicodeMap(cmap.getMap()); return new ToUnicodeMap(cmap.getMap());
}); }
} else if (cmapObj instanceof BaseStream) { if (cmapObj instanceof BaseStream) {
return CMapFactory.create({ try {
const cmap = await CMapFactory.create({
encoding: cmapObj, encoding: cmapObj,
fetchBuiltInCMap: this._fetchBuiltInCMapBound, fetchBuiltInCMap: this._fetchBuiltInCMapBound,
useCMap: null, useCMap: null,
}).then( });
function (cmap) {
if (cmap instanceof IdentityCMap) { if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xffff); return new IdentityToUnicodeMap(0, 0xffff);
} }
@ -3815,8 +3817,7 @@ class PartialEvaluator {
map[charCode] = String.fromCodePoint(...str); map[charCode] = String.fromCodePoint(...str);
}); });
return new ToUnicodeMap(map); return new ToUnicodeMap(map);
}, } catch (reason) {
reason => {
if (reason instanceof AbortException) { if (reason instanceof AbortException) {
return null; return null;
} }
@ -3826,9 +3827,8 @@ class PartialEvaluator {
} }
throw reason; throw reason;
} }
);
} }
return Promise.resolve(null); return null;
} }
readCidToGidMap(glyphsData, toUnicode) { readCidToGidMap(glyphsData, toUnicode) {