diff --git a/src/evaluator.js b/src/evaluator.js index 1597bed11..e34787e41 100644 --- a/src/evaluator.js +++ b/src/evaluator.js @@ -620,8 +620,18 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { } else { // parsing hex UTF-16BE numbers var str = []; - for (var i = 0, ii = token.length; i < ii; i += 4) - str.push(parseInt(token.substr(i, 4), 16)); + for (var k = 0, kk = token.length; k < kk; k += 4) { + var b = parseInt(token.substr(k, 4), 16); + if (b <= 0x10) { + k += 4; + b = (b << 16) | parseInt(token.substr(k, 4), 16); + b -= 0x10000; + str.push(0xD800 | (b >> 10)); + str.push(0xDC00 | (b & 0x3FF)); + break; + } + str.push(b); + } tokens.push(String.fromCharCode.apply(String, str)); token = ''; } diff --git a/src/fonts.js b/src/fonts.js index f8ae7de4c..aadaa8d71 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -823,6 +823,13 @@ var Font = (function FontClosure() { else this.rebuildToUnicode(properties); + this.toUnicodeOriginal = this.toUnicode.slice(); + for (var i = 0, j = 0xE000; i < this.toUnicode.length; i++) { + if (typeof this.toUnicode[i] == 'number') + break; + this.toUnicode[i] = j++; + } + if (!file) { // The file data is not specified. Trying to fix the font name // to be used with the canvas.font. @@ -1778,7 +1785,7 @@ var Font = (function FontClosure() { for (var i = 1; i < numGlyphs; i++) { var cid = gidToCidMap[i] || i; var unicode = this.toUnicode[cid]; - if (!unicode || isSpecialUnicode(unicode) || + if (!unicode || typeof unicode !== 'number' || isSpecialUnicode(unicode) || unicode in usedUnicodes) { unassignedUnicodeItems.push(i); continue; @@ -1825,7 +1832,7 @@ var Font = (function FontClosure() { var usedUnicodes = [], unassignedUnicodeItems = []; for (var i = 0, ii = glyphs.length; i < ii; i++) { var unicode = toUnicode[i + 1]; - if (!unicode || unicode in usedUnicodes) { + if (!unicode || typeof unicode !== 'number' || unicode in usedUnicodes) { unassignedUnicodeItems.push(i); continue; } @@ -1972,7 +1979,7 @@ var Font = (function FontClosure() { } properties.baseEncoding = encoding; } - if (properties.subtype == 'CIDFontType0C') { + if (false && properties.subtype == 'CIDFontType0C') { var toUnicode = []; for (var i = 0; i < charstrings.length; ++i) { var charstring = charstrings[i]; @@ -2270,8 +2277,8 @@ var Font = (function FontClosure() { break; } - var unicodeChars = !('toUnicode' in this) ? charcode : - this.toUnicode[charcode] || charcode; + var unicodeChars = !('toUnicodeOriginal' in this) ? charcode : + this.toUnicodeOriginal[charcode] || charcode; if (typeof unicodeChars === 'number') unicodeChars = String.fromCharCode(unicodeChars);