diff --git a/src/fonts.js b/src/fonts.js index 02c28a3c2..5c9cf1b02 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -5712,9 +5712,9 @@ var CFFFont = (function CFFFontClosure() { this.properties = properties; var parser = new CFFParser(file, properties); - var cff = parser.parse(); - var compiler = new CFFCompiler(cff); - this.readExtra(cff); + this.cff = parser.parse(); + var compiler = new CFFCompiler(this.cff); + this.readExtra(); try { this.data = compiler.compile(); } catch (e) { @@ -5726,12 +5726,10 @@ var CFFFont = (function CFFFontClosure() { } CFFFont.prototype = { - readExtra: function CFFFont_readExtra(cff) { + readExtra: function CFFFont_readExtra() { // charstrings contains info about glyphs (one element per glyph // containing mappings for {unicode, width}) - var charset = cff.charset.charset; - var encoding = cff.encoding ? cff.encoding.encoding : null; - var charstrings = this.getCharStrings(charset, encoding); + var charstrings = this.getCharStrings(); // create the mapping between charstring and glyph id var glyphIds = []; @@ -5740,21 +5738,39 @@ var CFFFont = (function CFFFontClosure() { this.charstrings = charstrings; this.glyphIds = glyphIds; - this.seacs = cff.seacs; + this.seacs = this.cff.seacs; }, - getCharStrings: function CFFFont_getCharStrings(charsets, encoding) { + getCharStrings: function CFFFont_getCharStrings() { + var cff = this.cff; + var charsets = cff.charset.charset; + var encoding = cff.encoding ? cff.encoding.encoding : null; var charstrings = []; var unicodeUsed = []; var unassignedUnicodeItems = []; var inverseEncoding = []; - // CID fonts don't have an encoding. - if (encoding !== null) + var gidStart = 0; + // Even though the CFF font may not actually be a CID font is could have + // CID information in the font descriptor. + if (this.properties.cidSystemInfo) { + // According to section 9.7.4.2 if the font is actually a CID font then + // we should use the charset to map CIDs to GIDs. If it is not actually + // a CID font then CIDs can be mapped directly to GIDs. + if (this.cff.isCIDFont) { + inverseEncoding = charsets; + } else { + for (var i = 0, ii = charsets.length; i < charsets.length; i++) { + inverseEncoding.push(i); + } + } + } else { for (var charcode in encoding) inverseEncoding[encoding[charcode]] = charcode | 0; - else - inverseEncoding = charsets; - var i = charsets[0] == '.notdef' ? 1 : 0; - for (var ii = charsets.length; i < ii; i++) { + if (charsets[0] === '.notedef') { + gidStart = 1; + } + } + + for (var i = gidStart, ii = charsets.length; i < ii; i++) { var glyph = charsets[i]; var code = inverseEncoding[i]; diff --git a/test/pdfs/bug816075.pdf b/test/pdfs/bug816075.pdf new file mode 100644 index 000000000..08d4186e2 Binary files /dev/null and b/test/pdfs/bug816075.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 9464cba5f..97040a35d 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -1012,6 +1012,13 @@ "rounds": 1, "type": "eq" }, + { "id": "bug816075", + "file": "pdfs/bug816075.pdf", + "md5": "7ec87c115c1f9ec41234cc7002555e82", + "rounds": 1, + "type": "eq", + "about": "A CIDFontType0 font with a CFF font that isn't actually CID." + }, { "id": "noembed-identity-2", "file": "pdfs/noembed-identity-2.pdf", "md5": "13b7d9ab9579d45c10bc8d499d087f21",