Merge pull request #17562 from Snuffleupagus/evaluator-more-async

Add more `async` code in the `PartialEvaluator`
This commit is contained in:
Jonas Jenwald 2024-01-23 10:35:27 +01:00 committed by GitHub
commit 8b24722113
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -526,13 +526,13 @@ class PartialEvaluator {
const args = group ? [matrix, null] : [matrix, bbox];
operatorList.addOp(OPS.paintFormXObjectBegin, args);
return this.getOperatorList({
await this.getOperatorList({
stream: xobj,
task,
resources: dict.get("Resources") || resources,
operatorList,
initialState,
}).then(function () {
});
operatorList.addOp(OPS.paintFormXObjectEnd, []);
if (group) {
@ -542,7 +542,6 @@ class PartialEvaluator {
if (optionalContent !== undefined) {
operatorList.addOp(OPS.endMarkedContent, []);
}
});
}
_sendImgData(objId, imgData, cacheGlobally = false) {
@ -1189,7 +1188,8 @@ class PartialEvaluator {
break;
}
}
return promise.then(function () {
await promise;
if (gStateObj.length > 0) {
operatorList.addOp(OPS.setGState, [gStateObj]);
}
@ -1197,7 +1197,6 @@ class PartialEvaluator {
if (isSimpleGState) {
localGStateCache.set(cacheKey, gStateRef, gStateObj);
}
});
}
loadFont(
@ -3429,13 +3428,11 @@ class PartialEvaluator {
});
}
extractDataStructures(dict, baseDict, properties) {
async extractDataStructures(dict, properties) {
const xref = this.xref;
let cidToGidBytes;
// 9.10.2
const toUnicodePromise = this.readToUnicode(
properties.toUnicode || dict.get("ToUnicode") || baseDict.get("ToUnicode")
);
const toUnicodePromise = this.readToUnicode(properties.toUnicode);
if (properties.composite) {
// CIDSystemInfo helps to match CID to glyphs
@ -3555,13 +3552,12 @@ class PartialEvaluator {
properties.baseEncodingName = baseEncodingName;
properties.hasEncoding = !!baseEncodingName || differences.length > 0;
properties.dict = dict;
return toUnicodePromise
.then(readToUnicode => {
properties.toUnicode = readToUnicode;
return this.buildToUnicode(properties);
})
.then(builtToUnicode => {
properties.toUnicode = await toUnicodePromise;
const builtToUnicode = await this.buildToUnicode(properties);
properties.toUnicode = builtToUnicode;
if (cidToGidBytes) {
properties.cidToGidMap = this.readCidToGidMap(
cidToGidBytes,
@ -3569,7 +3565,6 @@ class PartialEvaluator {
);
}
return properties;
});
}
/**
@ -3768,28 +3763,30 @@ class PartialEvaluator {
return new IdentityToUnicodeMap(properties.firstChar, properties.lastChar);
}
readToUnicode(cmapObj) {
async readToUnicode(cmapObj) {
if (!cmapObj) {
return Promise.resolve(null);
return null;
}
if (cmapObj instanceof Name) {
return CMapFactory.create({
const cmap = await CMapFactory.create({
encoding: cmapObj,
fetchBuiltInCMap: this._fetchBuiltInCMapBound,
useCMap: null,
}).then(function (cmap) {
});
if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xffff);
}
return new ToUnicodeMap(cmap.getMap());
});
} else if (cmapObj instanceof BaseStream) {
return CMapFactory.create({
}
if (cmapObj instanceof BaseStream) {
try {
const cmap = await CMapFactory.create({
encoding: cmapObj,
fetchBuiltInCMap: this._fetchBuiltInCMapBound,
useCMap: null,
}).then(
function (cmap) {
});
if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xffff);
}
@ -3818,8 +3815,7 @@ class PartialEvaluator {
map[charCode] = String.fromCodePoint(...str);
});
return new ToUnicodeMap(map);
},
reason => {
} catch (reason) {
if (reason instanceof AbortException) {
return null;
}
@ -3829,9 +3825,8 @@ class PartialEvaluator {
}
throw reason;
}
);
}
return Promise.resolve(null);
return null;
}
readCidToGidMap(glyphsData, toUnicode) {
@ -4020,7 +4015,7 @@ class PartialEvaluator {
}
let composite = false;
let hash, toUnicode;
let hash;
if (type.name === "Type0") {
// If font is a composite
// - get the descendant font
@ -4045,6 +4040,8 @@ class PartialEvaluator {
const firstChar = dict.get("FirstChar") || 0,
lastChar = dict.get("LastChar") || (composite ? 0xffff : 0xff);
const descriptor = dict.get("FontDescriptor");
const toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
if (descriptor) {
hash = new MurmurHash3_64();
@ -4082,7 +4079,6 @@ class PartialEvaluator {
hash.update(`${firstChar}-${lastChar}`); // Fixes issue10665_reduced.pdf
toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
if (toUnicode instanceof BaseStream) {
const stream = toUnicode.str || toUnicode;
const uint8array = stream.buffer
@ -4233,7 +4229,6 @@ class PartialEvaluator {
}
const newProperties = await this.extractDataStructures(
dict,
dict,
properties
);
@ -4397,11 +4392,7 @@ class PartialEvaluator {
properties.vertical = properties.cMap.vertical;
}
const newProperties = await this.extractDataStructures(
dict,
baseDict,
properties
);
const newProperties = await this.extractDataStructures(dict, properties);
this.extractWidths(dict, descriptor, newProperties);
return new Font(fontName.name, fontFile, newProperties);