Merge pull request #13354 from Snuffleupagus/preEvaluateFont-toUnicode-export
Export the "raw" toUnicode-data from `PartialEvaluator.preEvaluateFont`
This commit is contained in:
commit
0ec945ce8c
@ -2978,10 +2978,9 @@ class PartialEvaluator {
|
||||
const xref = this.xref;
|
||||
let cidToGidBytes;
|
||||
// 9.10.2
|
||||
const toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
|
||||
const toUnicodePromise = toUnicode
|
||||
? this.readToUnicode(toUnicode)
|
||||
: Promise.resolve(undefined);
|
||||
const toUnicodePromise = this.readToUnicode(
|
||||
properties.toUnicode || dict.get("ToUnicode") || baseDict.get("ToUnicode")
|
||||
);
|
||||
|
||||
if (properties.composite) {
|
||||
// CIDSystemInfo helps to match CID to glyphs
|
||||
@ -3289,8 +3288,10 @@ class PartialEvaluator {
|
||||
);
|
||||
}
|
||||
|
||||
readToUnicode(toUnicode) {
|
||||
const cmapObj = toUnicode;
|
||||
readToUnicode(cmapObj) {
|
||||
if (!cmapObj) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
if (isName(cmapObj)) {
|
||||
return CMapFactory.create({
|
||||
encoding: cmapObj,
|
||||
@ -3541,7 +3542,7 @@ class PartialEvaluator {
|
||||
}
|
||||
|
||||
let composite = false;
|
||||
let uint8array;
|
||||
let hash, toUnicode;
|
||||
if (type.name === "Type0") {
|
||||
// If font is a composite
|
||||
// - get the descendant font
|
||||
@ -3563,10 +3564,12 @@ class PartialEvaluator {
|
||||
composite = true;
|
||||
}
|
||||
|
||||
const firstChar = dict.get("FirstChar") || 0,
|
||||
lastChar = dict.get("LastChar") || (composite ? 0xffff : 0xff);
|
||||
const descriptor = dict.get("FontDescriptor");
|
||||
let hash;
|
||||
if (descriptor) {
|
||||
hash = new MurmurHash3_64();
|
||||
|
||||
const encoding = baseDict.getRaw("Encoding");
|
||||
if (isName(encoding)) {
|
||||
hash.update(encoding.name);
|
||||
@ -3596,14 +3599,12 @@ class PartialEvaluator {
|
||||
}
|
||||
}
|
||||
|
||||
const firstChar = dict.get("FirstChar") || 0;
|
||||
const lastChar = dict.get("LastChar") || (composite ? 0xffff : 0xff);
|
||||
hash.update(`${firstChar}-${lastChar}`);
|
||||
hash.update(`${firstChar}-${lastChar}`); // Fixes issue10665_reduced.pdf
|
||||
|
||||
const toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
|
||||
toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
|
||||
if (isStream(toUnicode)) {
|
||||
const stream = toUnicode.str || toUnicode;
|
||||
uint8array = stream.buffer
|
||||
const uint8array = stream.buffer
|
||||
? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength)
|
||||
: new Uint8Array(
|
||||
stream.bytes.buffer,
|
||||
@ -3656,20 +3657,25 @@ class PartialEvaluator {
|
||||
baseDict,
|
||||
composite,
|
||||
type: type.name,
|
||||
firstChar,
|
||||
lastChar,
|
||||
toUnicode,
|
||||
hash: hash ? hash.hexdigest() : "",
|
||||
};
|
||||
}
|
||||
|
||||
async translateFont(preEvaluatedFont) {
|
||||
const baseDict = preEvaluatedFont.baseDict;
|
||||
const dict = preEvaluatedFont.dict;
|
||||
const composite = preEvaluatedFont.composite;
|
||||
let descriptor = preEvaluatedFont.descriptor;
|
||||
const type = preEvaluatedFont.type;
|
||||
const maxCharIndex = composite ? 0xffff : 0xff;
|
||||
async translateFont({
|
||||
descriptor,
|
||||
dict,
|
||||
baseDict,
|
||||
composite,
|
||||
type,
|
||||
firstChar,
|
||||
lastChar,
|
||||
toUnicode,
|
||||
cssFontInfo,
|
||||
}) {
|
||||
let properties;
|
||||
const firstChar = dict.get("FirstChar") || 0;
|
||||
const lastChar = dict.get("LastChar") || maxCharIndex;
|
||||
|
||||
if (!descriptor) {
|
||||
if (type === "Type3") {
|
||||
@ -3708,6 +3714,7 @@ class PartialEvaluator {
|
||||
flags,
|
||||
firstChar,
|
||||
lastChar,
|
||||
toUnicode,
|
||||
};
|
||||
const widths = dict.get("Widths");
|
||||
return this.extractDataStructures(dict, dict, properties).then(
|
||||
@ -3802,8 +3809,9 @@ class PartialEvaluator {
|
||||
composite,
|
||||
fixedPitch: false,
|
||||
fontMatrix: dict.getArray("FontMatrix") || FONT_IDENTITY_MATRIX,
|
||||
firstChar: firstChar || 0,
|
||||
lastChar: lastChar || maxCharIndex,
|
||||
firstChar,
|
||||
lastChar,
|
||||
toUnicode,
|
||||
bbox: descriptor.getArray("FontBBox"),
|
||||
ascent: descriptor.get("Ascent"),
|
||||
descent: descriptor.get("Descent"),
|
||||
@ -3812,7 +3820,7 @@ class PartialEvaluator {
|
||||
flags: descriptor.get("Flags"),
|
||||
italicAngle: descriptor.get("ItalicAngle"),
|
||||
isType3Font: false,
|
||||
cssFontInfo: preEvaluatedFont.cssFontInfo,
|
||||
cssFontInfo,
|
||||
};
|
||||
|
||||
if (composite) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user