diff --git a/src/fonts.js b/src/fonts.js index 10c0819f7..bdd04d3a7 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -3903,9 +3903,10 @@ var Font = (function FontClosure() { var usedUnicodes = []; var unassignedUnicodeItems = []; + var toFontChar = this.cidToFontChar || this.toFontChar; for (var i = 1; i < numGlyphs; i++) { var cid = gidToCidMap[i] || i; - var unicode = this.toFontChar[cid]; + var unicode = toFontChar[cid]; if (!unicode || typeof unicode !== 'number' || isSpecialUnicode(unicode) || unicode in usedUnicodes) { unassignedUnicodeItems.push(i); @@ -3915,21 +3916,25 @@ var Font = (function FontClosure() { glyphs.push({ unicode: unicode, code: cid }); ids.push(i); } - // trying to fit as many unassigned symbols as we can - // in the range allocated for the user defined symbols - var unusedUnicode = CMAP_GLYPH_OFFSET; - for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; j++) { - var i = unassignedUnicodeItems[j]; - var cid = gidToCidMap[i] || i; - while (unusedUnicode in usedUnicodes) - unusedUnicode++; - if (unusedUnicode >= CMAP_GLYPH_OFFSET + GLYPH_AREA_SIZE) - break; - var unicode = unusedUnicode++; - this.toFontChar[cid] = unicode; - usedUnicodes[unicode] = true; - glyphs.push({ unicode: unicode, code: cid }); - ids.push(i); + // unassigned codepoints will never be used for non-Identity CMap + // because the input will be Unicode + if (!this.cidToFontChar) { + // trying to fit as many unassigned symbols as we can + // in the range allocated for the user defined symbols + var unusedUnicode = CMAP_GLYPH_OFFSET; + for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; j++) { + var i = unassignedUnicodeItems[j]; + var cid = gidToCidMap[i] || i; + while (unusedUnicode in usedUnicodes) + unusedUnicode++; + if (unusedUnicode >= CMAP_GLYPH_OFFSET + GLYPH_AREA_SIZE) + break; + var unicode = unusedUnicode++; + this.toFontChar[cid] = unicode; + usedUnicodes[unicode] = true; + glyphs.push({ unicode: unicode, code: cid }); + ids.push(i); + } } } else { this.useToFontChar = true; @@ -4394,6 +4399,11 @@ var Font = (function FontClosure() { if (cidEncoding.indexOf('Identity-') !== 0) { // input is already Unicode for non-Identity CMap encodings. this.cidToUnicode = []; + // For CIDFontType2, however, we need cid-to-Unicode conversion + // to rebuild cmap. + if (properties.type == 'CIDFontType2') { + this.cidToFontChar = cidToUnicodeMap; + } } else { // We don't have to do reverse conversions if the string is // already CID. @@ -4494,6 +4504,8 @@ var Font = (function FontClosure() { var cid = this.unicodeToCID[charcode] || charcode; width = this.widths[cid]; vmetric = this.vmetrics && this.vmetrics[cid]; + fontCharCode = charcode; + break; } fontCharCode = this.toFontChar[charcode] || charcode; break; diff --git a/test/pdfs/ohkubo-SS04.pdf.link b/test/pdfs/ohkubo-SS04.pdf.link new file mode 100644 index 000000000..979ad7bc7 --- /dev/null +++ b/test/pdfs/ohkubo-SS04.pdf.link @@ -0,0 +1 @@ +http://www.sapid.org/html2/PDF-ja/ohkubo-SS04.pdf \ No newline at end of file diff --git a/test/test_manifest.json b/test/test_manifest.json index 4cce61f7f..9b1c4ac58 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -930,6 +930,13 @@ "rounds": 1, "type": "eq" }, + { "id": "ohkubo-ss04", + "file": "pdfs/ohkubo-SS04.pdf", + "md5": "b8c334073ff5be74fac1f36130943ea5", + "rounds": 1, + "link": true, + "type": "eq" + }, { "id": "sfaa_japanese", "file": "pdfs/SFAA_Japanese.pdf", "md5": "b961bbc0d05bdd6d91041bca60ec8e8b",