Merge pull request #17562 from Snuffleupagus/evaluator-more-async
Add more `async` code in the `PartialEvaluator`
This commit is contained in:
commit
8b24722113
@ -526,13 +526,13 @@ class PartialEvaluator {
|
|||||||
const args = group ? [matrix, null] : [matrix, bbox];
|
const args = group ? [matrix, null] : [matrix, bbox];
|
||||||
operatorList.addOp(OPS.paintFormXObjectBegin, args);
|
operatorList.addOp(OPS.paintFormXObjectBegin, args);
|
||||||
|
|
||||||
return this.getOperatorList({
|
await this.getOperatorList({
|
||||||
stream: xobj,
|
stream: xobj,
|
||||||
task,
|
task,
|
||||||
resources: dict.get("Resources") || resources,
|
resources: dict.get("Resources") || resources,
|
||||||
operatorList,
|
operatorList,
|
||||||
initialState,
|
initialState,
|
||||||
}).then(function () {
|
});
|
||||||
operatorList.addOp(OPS.paintFormXObjectEnd, []);
|
operatorList.addOp(OPS.paintFormXObjectEnd, []);
|
||||||
|
|
||||||
if (group) {
|
if (group) {
|
||||||
@ -542,7 +542,6 @@ class PartialEvaluator {
|
|||||||
if (optionalContent !== undefined) {
|
if (optionalContent !== undefined) {
|
||||||
operatorList.addOp(OPS.endMarkedContent, []);
|
operatorList.addOp(OPS.endMarkedContent, []);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendImgData(objId, imgData, cacheGlobally = false) {
|
_sendImgData(objId, imgData, cacheGlobally = false) {
|
||||||
@ -1189,7 +1188,8 @@ class PartialEvaluator {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return promise.then(function () {
|
await promise;
|
||||||
|
|
||||||
if (gStateObj.length > 0) {
|
if (gStateObj.length > 0) {
|
||||||
operatorList.addOp(OPS.setGState, [gStateObj]);
|
operatorList.addOp(OPS.setGState, [gStateObj]);
|
||||||
}
|
}
|
||||||
@ -1197,7 +1197,6 @@ class PartialEvaluator {
|
|||||||
if (isSimpleGState) {
|
if (isSimpleGState) {
|
||||||
localGStateCache.set(cacheKey, gStateRef, gStateObj);
|
localGStateCache.set(cacheKey, gStateRef, gStateObj);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadFont(
|
loadFont(
|
||||||
@ -3429,13 +3428,11 @@ class PartialEvaluator {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
extractDataStructures(dict, baseDict, properties) {
|
async extractDataStructures(dict, properties) {
|
||||||
const xref = this.xref;
|
const xref = this.xref;
|
||||||
let cidToGidBytes;
|
let cidToGidBytes;
|
||||||
// 9.10.2
|
// 9.10.2
|
||||||
const toUnicodePromise = this.readToUnicode(
|
const toUnicodePromise = this.readToUnicode(properties.toUnicode);
|
||||||
properties.toUnicode || dict.get("ToUnicode") || baseDict.get("ToUnicode")
|
|
||||||
);
|
|
||||||
|
|
||||||
if (properties.composite) {
|
if (properties.composite) {
|
||||||
// CIDSystemInfo helps to match CID to glyphs
|
// CIDSystemInfo helps to match CID to glyphs
|
||||||
@ -3555,13 +3552,12 @@ class PartialEvaluator {
|
|||||||
properties.baseEncodingName = baseEncodingName;
|
properties.baseEncodingName = baseEncodingName;
|
||||||
properties.hasEncoding = !!baseEncodingName || differences.length > 0;
|
properties.hasEncoding = !!baseEncodingName || differences.length > 0;
|
||||||
properties.dict = dict;
|
properties.dict = dict;
|
||||||
return toUnicodePromise
|
|
||||||
.then(readToUnicode => {
|
properties.toUnicode = await toUnicodePromise;
|
||||||
properties.toUnicode = readToUnicode;
|
|
||||||
return this.buildToUnicode(properties);
|
const builtToUnicode = await this.buildToUnicode(properties);
|
||||||
})
|
|
||||||
.then(builtToUnicode => {
|
|
||||||
properties.toUnicode = builtToUnicode;
|
properties.toUnicode = builtToUnicode;
|
||||||
|
|
||||||
if (cidToGidBytes) {
|
if (cidToGidBytes) {
|
||||||
properties.cidToGidMap = this.readCidToGidMap(
|
properties.cidToGidMap = this.readCidToGidMap(
|
||||||
cidToGidBytes,
|
cidToGidBytes,
|
||||||
@ -3569,7 +3565,6 @@ class PartialEvaluator {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return properties;
|
return properties;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3768,28 +3763,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);
|
||||||
}
|
}
|
||||||
@ -3818,8 +3815,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;
|
||||||
}
|
}
|
||||||
@ -3829,9 +3825,8 @@ class PartialEvaluator {
|
|||||||
}
|
}
|
||||||
throw reason;
|
throw reason;
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return Promise.resolve(null);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
readCidToGidMap(glyphsData, toUnicode) {
|
readCidToGidMap(glyphsData, toUnicode) {
|
||||||
@ -4020,7 +4015,7 @@ class PartialEvaluator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let composite = false;
|
let composite = false;
|
||||||
let hash, toUnicode;
|
let hash;
|
||||||
if (type.name === "Type0") {
|
if (type.name === "Type0") {
|
||||||
// If font is a composite
|
// If font is a composite
|
||||||
// - get the descendant font
|
// - get the descendant font
|
||||||
@ -4045,6 +4040,8 @@ class PartialEvaluator {
|
|||||||
const firstChar = dict.get("FirstChar") || 0,
|
const firstChar = dict.get("FirstChar") || 0,
|
||||||
lastChar = dict.get("LastChar") || (composite ? 0xffff : 0xff);
|
lastChar = dict.get("LastChar") || (composite ? 0xffff : 0xff);
|
||||||
const descriptor = dict.get("FontDescriptor");
|
const descriptor = dict.get("FontDescriptor");
|
||||||
|
const toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
|
||||||
|
|
||||||
if (descriptor) {
|
if (descriptor) {
|
||||||
hash = new MurmurHash3_64();
|
hash = new MurmurHash3_64();
|
||||||
|
|
||||||
@ -4082,7 +4079,6 @@ class PartialEvaluator {
|
|||||||
|
|
||||||
hash.update(`${firstChar}-${lastChar}`); // Fixes issue10665_reduced.pdf
|
hash.update(`${firstChar}-${lastChar}`); // Fixes issue10665_reduced.pdf
|
||||||
|
|
||||||
toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
|
|
||||||
if (toUnicode instanceof BaseStream) {
|
if (toUnicode instanceof BaseStream) {
|
||||||
const stream = toUnicode.str || toUnicode;
|
const stream = toUnicode.str || toUnicode;
|
||||||
const uint8array = stream.buffer
|
const uint8array = stream.buffer
|
||||||
@ -4233,7 +4229,6 @@ class PartialEvaluator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newProperties = await this.extractDataStructures(
|
const newProperties = await this.extractDataStructures(
|
||||||
dict,
|
|
||||||
dict,
|
dict,
|
||||||
properties
|
properties
|
||||||
);
|
);
|
||||||
@ -4397,11 +4392,7 @@ class PartialEvaluator {
|
|||||||
properties.vertical = properties.cMap.vertical;
|
properties.vertical = properties.cMap.vertical;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newProperties = await this.extractDataStructures(
|
const newProperties = await this.extractDataStructures(dict, properties);
|
||||||
dict,
|
|
||||||
baseDict,
|
|
||||||
properties
|
|
||||||
);
|
|
||||||
this.extractWidths(dict, descriptor, newProperties);
|
this.extractWidths(dict, descriptor, newProperties);
|
||||||
|
|
||||||
return new Font(fontName.name, fontFile, newProperties);
|
return new Font(fontName.name, fontFile, newProperties);
|
||||||
|
Loading…
Reference in New Issue
Block a user