From 343e174951ce6745d4761627882dcfd4e658111e Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sat, 29 Oct 2011 09:29:19 -0500 Subject: [PATCH] Change cmap encoding for Type 1 --- src/fonts.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/fonts.js b/src/fonts.js index 6202b3279..5d70bf5e4 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -729,6 +729,12 @@ function isAdaptedUnicode(unicode) { unicode < kCmapGlyphOffset + kSizeOfGlyphArea; } +function isSpecialUnicode(unicode) { + return (unicode <= 0x1F || (unicode >= 127 && unicode < kSizeOfGlyphArea)) || + unicode >= kCmapGlyphOffset && + unicode < kCmapGlyphOffset + kSizeOfGlyphArea; +} + /** * 'Font' is the class the outside world should use, it encapsulate all the font * decoding logics whatever type it is (assuming the font type is supported). @@ -2744,11 +2750,28 @@ CFF.prototype = { getOrderedCharStrings: function cff_getOrderedCharStrings(glyphs, properties) { var charstrings = []; - for (var i = 0; i < glyphs.length; i++) { + var reverseMapping = {}; + var encoding = properties.baseEncoding; + var differences = properties.differences; + var i, length; + for (i = 0, length = encoding.length; i < length; ++i) { + if (encoding[i] && !isSpecialUnicode(i)) + reverseMapping[encoding[i]] = i; + } + for (i = 0, length = differences.length; i < length; ++i) { + if (differences[i] && !isSpecialUnicode(i)) + reverseMapping[differences[i]] = i; + } + reverseMapping['.notdef'] = 0; + var unusedUnicode = kCmapGlyphOffset; + for (i = 0, length = glyphs.length; i < length; i++) { var item = glyphs[i]; + var glyphName = item.glyph; + var unicode = glyphName in reverseMapping ? + reverseMapping[glyphName] : unusedUnicode++; charstrings.push({ - glyph: item.glyph, - unicode: adaptUnicode(i), + glyph: glyphName, + unicode: unicode, gid: i, charstring: item.data, width: item.width,