Browse Source

Re-factor heuristics to recognize unknown glyphs for |toUnicode|

Jonas Jenwald 11 years ago
parent
commit
b918df3547
  1. 36
      src/core/fonts.js

36
src/core/fonts.js

@ -4310,26 +4310,30 @@ var Font = (function FontClosure() {
var glyphName = encoding[charcode]; var glyphName = encoding[charcode];
// b) Look up the character name in the Adobe Glyph List (see the // b) Look up the character name in the Adobe Glyph List (see the
// Bibliography) to obtain the corresponding Unicode value. // Bibliography) to obtain the corresponding Unicode value.
if (glyphName === '' || !(glyphName in GlyphsUnicode)) { if (glyphName === '') {
continue;
} else if (GlyphsUnicode[glyphName] === undefined) {
// (undocumented) c) Few heuristics to recognize unknown glyphs // (undocumented) c) Few heuristics to recognize unknown glyphs
// NOTE: Adobe Reader does not do this step, but OSX Preview does // NOTE: Adobe Reader does not do this step, but OSX Preview does
var code; var code = 0;
// Gxx glyph switch (glyphName[0]) {
if (glyphName.length === 3 && case 'G': // Gxx glyph
glyphName[0] === 'G' && if (glyphName.length === 3) {
(code = parseInt(glyphName.substr(1), 16))) { code = parseInt(glyphName.substr(1), 16);
toUnicode[charcode] = String.fromCharCode(code);
} }
// g00xx glyph break;
if (glyphName.length === 5 && case 'g': // g00xx glyph
glyphName[0] === 'g' && if (glyphName.length === 5) {
(code = parseInt(glyphName.substr(1), 16))) { code = parseInt(glyphName.substr(1), 16);
toUnicode[charcode] = String.fromCharCode(code); }
break;
case 'C': // Cddd glyph
if (glyphName.length >= 3) {
code = +glyphName.substr(1);
}
break;
} }
// Cddd glyph if (code) {
if (glyphName.length >= 3 &&
glyphName[0] === 'C' &&
(code = +glyphName.substr(1))) {
toUnicode[charcode] = String.fromCharCode(code); toUnicode[charcode] = String.fromCharCode(code);
} }
continue; continue;

Loading…
Cancel
Save