From 6c3d66fb46b82794557a46d7d275057930932bf0 Mon Sep 17 00:00:00 2001 From: vyv03354 Date: Sun, 3 Mar 2013 13:38:40 +0900 Subject: [PATCH] Convert CID fonts using "ToUnicode" CMap if available --- src/fonts.js | 19 +++++++++++++------ test/pdfs/javauninstall-7.pdf.link | 1 + test/test_manifest.json | 8 ++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 test/pdfs/javauninstall-7.pdf.link diff --git a/src/fonts.js b/src/fonts.js index 7d6c909c2..b19947593 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -2401,7 +2401,7 @@ var Font = (function FontClosure() { this.defaultVMetrics = properties.defaultVMetrics; } - if (properties.toUnicode) + if (properties.toUnicode && properties.toUnicode.length > 0) this.toUnicode = properties.toUnicode; else this.rebuildToUnicode(properties); @@ -4331,12 +4331,12 @@ var Font = (function FontClosure() { rebuildToUnicode: function Font_rebuildToUnicode(properties) { var firstChar = properties.firstChar, lastChar = properties.lastChar; var map = []; - if (properties.composite) { - var isIdentityMap = this.cidToUnicode.length === 0; + var toUnicode = this.toUnicode || this.cidToUnicode; + if (toUnicode) { + var isIdentityMap = toUnicode.length === 0; for (var i = firstChar, ii = lastChar; i <= ii; i++) { // TODO missing map the character according font's CMap - var cid = i; - map[i] = isIdentityMap ? cid : this.cidToUnicode[cid]; + map[i] = isIdentityMap ? i : toUnicode[i]; } } else { for (var i = firstChar, ii = lastChar; i <= ii; i++) { @@ -4358,6 +4358,14 @@ var Font = (function FontClosure() { this.cidToUnicode = cidToUnicodeMap; this.unicodeToCID = unicodeToCIDMap; + var cidEncoding = properties.cidEncoding; + if (properties.toUnicode) { + if (cidEncoding && cidEncoding.indexOf('Identity-') !== 0) { + TODO('Need to create a reverse mapping from \'ToUnicode\' CMap'); + } + return; // 'ToUnicode' CMap will be used + } + var cidSystemInfo = properties.cidSystemInfo; var cidToUnicode; if (cidSystemInfo) { @@ -4368,7 +4376,6 @@ var Font = (function FontClosure() { if (!cidToUnicode) return; // identity encoding - var cidEncoding = properties.cidEncoding; var overwrite = HalfwidthCMaps[cidEncoding]; var cid = 1, i, j, k, ii; for (i = 0, ii = cidToUnicode.length; i < ii; ++i) { diff --git a/test/pdfs/javauninstall-7.pdf.link b/test/pdfs/javauninstall-7.pdf.link new file mode 100644 index 000000000..bff10581c --- /dev/null +++ b/test/pdfs/javauninstall-7.pdf.link @@ -0,0 +1 @@ +http://www.cyberagentfx.jp/gaikaex/pdf/javauninstall-7.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 738d13ee2..d44a54080 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -891,6 +891,14 @@ "rounds": 1, "type": "eq" }, + { "id": "javauninstall-7", + "file": "pdfs/javauninstall-7.pdf", + "md5": "c9eb59503923c9125b9660e348618675", + "rounds": 1, + "link": true, + "lastPage": 1, + "type": "eq" + }, { "id": "jst2007-5", "file": "pdfs/JST2007-5.pdf", "md5": "9efa6c37fc771b36a60535036d1910bb",