From 158790981c5337ed2960b1dec2c0366e75882fac Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 14 Jun 2014 22:51:13 +0200 Subject: [PATCH] Don't blindly trust toUnicode when building toFontChar for non-standard fonts without a font file (issue 4934) --- src/core/fonts.js | 15 +++++++++++---- test/pdfs/.gitignore | 1 + test/pdfs/issue4934.pdf | Bin 0 -> 1822 bytes test/test_manifest.json | 9 +++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 test/pdfs/issue4934.pdf diff --git a/src/core/fonts.js b/src/core/fonts.js index 1e18e23ad..d9e0eba28 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -2150,7 +2150,7 @@ var Glyph = (function GlyphClosure() { */ var Font = (function FontClosure() { function Font(name, file, properties) { - var charCode; + var charCode, glyphName; this.name = name; this.loadedName = properties.loadedName; @@ -2249,13 +2249,20 @@ var Font = (function FontClosure() { } else if (isStandardFont) { this.toFontChar = []; for (charCode in properties.defaultEncoding) { - var glyphName = properties.differences[charCode] || - properties.defaultEncoding[charCode]; + glyphName = (properties.differences[charCode] || + properties.defaultEncoding[charCode]); this.toFontChar[charCode] = GlyphsUnicode[glyphName]; } } else { + var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1); for (charCode in this.toUnicode) { - this.toFontChar[charCode] = this.toUnicode[charCode].charCodeAt(0); + unicodeCharCode = this.toUnicode[charCode].charCodeAt(0); + if (notCidFont) { + glyphName = (properties.differences[charCode] || + properties.defaultEncoding[charCode]); + unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode); + } + this.toFontChar[charCode] = unicodeCharCode; } } this.loadedName = fontName.split('-')[0]; diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 726a852d3..debc332f6 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -66,6 +66,7 @@ !noembed-sjis.pdf !vertical.pdf !bug878026.pdf +!issue4934.pdf !issue4650.pdf !issue3025.pdf !issue2099-1.pdf diff --git a/test/pdfs/issue4934.pdf b/test/pdfs/issue4934.pdf new file mode 100644 index 0000000000000000000000000000000000000000..6924fccad94d0e541dac5f3f40da0e5a26cd07f6 GIT binary patch literal 1822 zcmZ`)c}yHt81I#6hoa>WXi~!SAn8SC-pst6*+3WB1qv3S0qhZ=$*>H|kY#2&I}kvv zO%xMoOl=z*OruSzRNI);R;_JH38{@V(TYc;YD)=+f3!uhMGF;8{NC&?Yy-|@cHjGs z-*>+6rEks6&%hfcMivlNQl- zCOoWSOET>9YK^A2jb>B~^ijs-wYRiNY=PVuu{26M@PQj<+HuLNDO}ndgw` zq$wwu;t>p*yoh*-#tNmg{|PVHe98rzL`I^7k-!m<<&h}-pM{02K1>rt0%;|*H{424 zwadsBHUt!}1?kt!aH0hsn$mbd*StoJ3J!o5r3{;=!&cLM2x_3`=s_()h;%T8i*7CI zXQbRks_wJukVvRN&@xq}fpM2Jn6@h_&jst)Uez*dDtTVWQQXxYFRaA1sJx!ZE2pO* ztQPJjyFDWCWtQ5o4FJSY7ZocFaH3`d1Ha0^q~)zcY_VZBDE^Sxc2)D$SxDqK*!vY< z5YfnK3)0rlfSQNo+@ZsjfqAD*MVNTl?Kh@6)LfMo zE-KRn?UjeFcD%~1+&j_IvHH5_ZuSY}{w^tN{P8=#Fa1ewY9r5m`pD28q4?J8v2{Jq z2-C5vE*@LAevrNKqV(QLWw`28#nQ=UiJ5*vzgU}d<@&CS{XgE{<`M9bic^zIJY5$K zsH>)2<3D$IzBN(&TXWl{$(uzn$FE5}GwW_|nz}tB{@c5#b=cJ(yy@=i9_e~}*OA5N zKJQ9BIq>e(SFImAUx_<2C7D9ZzL`_UH#m!_zT+JKy}|SzqBd@$YnvZb>z-I@~J~s6Cip-C${qfK8JZbF&X}zz8C!HkN@V$FUKPEW(ta57L1{<~W#>VNygmaJS6qa9lJe8jW+n zY?#%FLgO$@wmFU?3XO;9ILDEqIFcA;$1)YoubTGdR;IP8NMhJh!+_g_UVHXk5wsN3 QvO~v&IGFVGypsI?0Fx#irvLx| literal 0 HcmV?d00001 diff --git a/test/test_manifest.json b/test/test_manifest.json index 77306d0d8..57eb4c9c0 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -436,6 +436,15 @@ "lastPage": 1, "type": "eq" }, + { "id": "issue4934", + "file": "pdfs/issue4934.pdf", + "md5": "6099da44f677702ae65a648b51a2226d", + "rounds": 1, + "link": false, + "firstPage": 1, + "lastPage": 1, + "type": "eq" + }, { "id": "txt2pdf", "file": "pdfs/txt2pdf.pdf", "md5": "02cefa0f5e8d96313bb05163b2f88c8c",