Slightly re-factor PartialEvaluator._simpleFontToUnicode
Given the sheer number of heuristics added to this method over the years, moving the *valid* unicode found case to the top should improve readability of the code.
This commit is contained in:
parent
c6cc7c6e6a
commit
fa47d4b9b1
@ -3526,11 +3526,16 @@ class PartialEvaluator {
|
||||
for (const charcode in encoding) {
|
||||
// a) Map the character code to a character name.
|
||||
let glyphName = encoding[charcode];
|
||||
// b) Look up the character name in the Adobe Glyph List (see the
|
||||
// Bibliography) to obtain the corresponding Unicode value.
|
||||
if (glyphName === "") {
|
||||
continue;
|
||||
} else if (glyphsUnicodeMap[glyphName] === undefined) {
|
||||
}
|
||||
// b) Look up the character name in the Adobe Glyph List (see the
|
||||
// Bibliography) to obtain the corresponding Unicode value.
|
||||
let unicode = glyphsUnicodeMap[glyphName];
|
||||
if (unicode !== undefined) {
|
||||
toUnicode[charcode] = String.fromCharCode(unicode);
|
||||
continue;
|
||||
}
|
||||
// (undocumented) c) Few heuristics to recognize unknown glyphs
|
||||
// NOTE: Adobe Reader does not do this step, but OSX Preview does
|
||||
let code = 0;
|
||||
@ -3562,10 +3567,7 @@ class PartialEvaluator {
|
||||
// containing glyph, i.e. base 16, codes instead.
|
||||
// In that case we need to re-parse the *entire* encoding to
|
||||
// prevent broken text-selection (fixes issue9655_reduced.pdf).
|
||||
if (
|
||||
Number.isNaN(code) &&
|
||||
Number.isInteger(parseInt(codeStr, 16))
|
||||
) {
|
||||
if (Number.isNaN(code) && Number.isInteger(parseInt(codeStr, 16))) {
|
||||
return this._simpleFontToUnicode(
|
||||
properties,
|
||||
/* forceGlyphs */ true
|
||||
@ -3573,11 +3575,12 @@ class PartialEvaluator {
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: // 'uniXXXX'/'uXXXX{XX}' glyphs
|
||||
const unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
|
||||
case "u": // 'uniXXXX'/'uXXXX{XX}' glyphs
|
||||
unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
|
||||
if (unicode !== -1) {
|
||||
code = unicode;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (code > 0 && code <= 0x10ffff && Number.isInteger(code)) {
|
||||
// If `baseEncodingName` is one the predefined encodings, and `code`
|
||||
@ -3594,9 +3597,6 @@ class PartialEvaluator {
|
||||
}
|
||||
toUnicode[charcode] = String.fromCodePoint(code);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
|
||||
}
|
||||
return toUnicode;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user