Skip to content

Commit

Permalink
Merge pull request #13354 from Snuffleupagus/preEvaluateFont-toUnicod…
Browse files Browse the repository at this point in the history
…e-export

Export the "raw" toUnicode-data from `PartialEvaluator.preEvaluateFont`
  • Loading branch information
timvandermeij committed May 8, 2021
2 parents e6435e3 + 6eef69d commit 0ec945c
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -3708,6 +3714,7 @@ class PartialEvaluator {
flags,
firstChar,
lastChar,
toUnicode,
};
const widths = dict.get("Widths");
return this.extractDataStructures(dict, dict, properties).then(
Expand Down Expand Up @@ -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"),
Expand All @@ -3812,7 +3820,7 @@ class PartialEvaluator {
flags: descriptor.get("Flags"),
italicAngle: descriptor.get("ItalicAngle"),
isType3Font: false,
cssFontInfo: preEvaluatedFont.cssFontInfo,
cssFontInfo,
};

if (composite) {
Expand Down

0 comments on commit 0ec945c

Please sign in to comment.