Merge pull request #13354 from Snuffleupagus/preEvaluateFont-toUnicode-export

Export the "raw" toUnicode-data from `PartialEvaluator.preEvaluateFont`
This commit is contained in:
Tim van der Meij 2021-05-08 14:26:20 +02:00 committed by GitHub
commit 0ec945ce8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2978,10 +2978,9 @@ class PartialEvaluator {
const xref = this.xref; const xref = this.xref;
let cidToGidBytes; let cidToGidBytes;
// 9.10.2 // 9.10.2
const toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode"); const toUnicodePromise = this.readToUnicode(
const toUnicodePromise = toUnicode properties.toUnicode || dict.get("ToUnicode") || baseDict.get("ToUnicode")
? this.readToUnicode(toUnicode) );
: Promise.resolve(undefined);
if (properties.composite) { if (properties.composite) {
// CIDSystemInfo helps to match CID to glyphs // CIDSystemInfo helps to match CID to glyphs
@ -3289,8 +3288,10 @@ class PartialEvaluator {
); );
} }
readToUnicode(toUnicode) { readToUnicode(cmapObj) {
const cmapObj = toUnicode; if (!cmapObj) {
return Promise.resolve(null);
}
if (isName(cmapObj)) { if (isName(cmapObj)) {
return CMapFactory.create({ return CMapFactory.create({
encoding: cmapObj, encoding: cmapObj,
@ -3541,7 +3542,7 @@ class PartialEvaluator {
} }
let composite = false; let composite = false;
let uint8array; let hash, toUnicode;
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
@ -3563,10 +3564,12 @@ class PartialEvaluator {
composite = true; composite = true;
} }
const firstChar = dict.get("FirstChar") || 0,
lastChar = dict.get("LastChar") || (composite ? 0xffff : 0xff);
const descriptor = dict.get("FontDescriptor"); const descriptor = dict.get("FontDescriptor");
let hash;
if (descriptor) { if (descriptor) {
hash = new MurmurHash3_64(); hash = new MurmurHash3_64();
const encoding = baseDict.getRaw("Encoding"); const encoding = baseDict.getRaw("Encoding");
if (isName(encoding)) { if (isName(encoding)) {
hash.update(encoding.name); hash.update(encoding.name);
@ -3596,14 +3599,12 @@ class PartialEvaluator {
} }
} }
const firstChar = dict.get("FirstChar") || 0; hash.update(`${firstChar}-${lastChar}`); // Fixes issue10665_reduced.pdf
const lastChar = dict.get("LastChar") || (composite ? 0xffff : 0xff);
hash.update(`${firstChar}-${lastChar}`);
const toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode"); toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
if (isStream(toUnicode)) { if (isStream(toUnicode)) {
const stream = toUnicode.str || toUnicode; const stream = toUnicode.str || toUnicode;
uint8array = stream.buffer const uint8array = stream.buffer
? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength)
: new Uint8Array( : new Uint8Array(
stream.bytes.buffer, stream.bytes.buffer,
@ -3656,20 +3657,25 @@ class PartialEvaluator {
baseDict, baseDict,
composite, composite,
type: type.name, type: type.name,
firstChar,
lastChar,
toUnicode,
hash: hash ? hash.hexdigest() : "", hash: hash ? hash.hexdigest() : "",
}; };
} }
async translateFont(preEvaluatedFont) { async translateFont({
const baseDict = preEvaluatedFont.baseDict; descriptor,
const dict = preEvaluatedFont.dict; dict,
const composite = preEvaluatedFont.composite; baseDict,
let descriptor = preEvaluatedFont.descriptor; composite,
const type = preEvaluatedFont.type; type,
const maxCharIndex = composite ? 0xffff : 0xff; firstChar,
lastChar,
toUnicode,
cssFontInfo,
}) {
let properties; let properties;
const firstChar = dict.get("FirstChar") || 0;
const lastChar = dict.get("LastChar") || maxCharIndex;
if (!descriptor) { if (!descriptor) {
if (type === "Type3") { if (type === "Type3") {
@ -3708,6 +3714,7 @@ class PartialEvaluator {
flags, flags,
firstChar, firstChar,
lastChar, lastChar,
toUnicode,
}; };
const widths = dict.get("Widths"); const widths = dict.get("Widths");
return this.extractDataStructures(dict, dict, properties).then( return this.extractDataStructures(dict, dict, properties).then(
@ -3802,8 +3809,9 @@ class PartialEvaluator {
composite, composite,
fixedPitch: false, fixedPitch: false,
fontMatrix: dict.getArray("FontMatrix") || FONT_IDENTITY_MATRIX, fontMatrix: dict.getArray("FontMatrix") || FONT_IDENTITY_MATRIX,
firstChar: firstChar || 0, firstChar,
lastChar: lastChar || maxCharIndex, lastChar,
toUnicode,
bbox: descriptor.getArray("FontBBox"), bbox: descriptor.getArray("FontBBox"),
ascent: descriptor.get("Ascent"), ascent: descriptor.get("Ascent"),
descent: descriptor.get("Descent"), descent: descriptor.get("Descent"),
@ -3812,7 +3820,7 @@ class PartialEvaluator {
flags: descriptor.get("Flags"), flags: descriptor.get("Flags"),
italicAngle: descriptor.get("ItalicAngle"), italicAngle: descriptor.get("ItalicAngle"),
isType3Font: false, isType3Font: false,
cssFontInfo: preEvaluatedFont.cssFontInfo, cssFontInfo,
}; };
if (composite) { if (composite) {