From 2fcb5afc7b98b5572e3e40d7e86ff2f79e00b44d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 15 Oct 2019 14:06:54 +0200 Subject: [PATCH] Add a fallback for non-embedded *composite* Verdana fonts (issue 11242) Obviously this won't look exactly right, but considering that the PDF file doesn't bother embedding non-standard fonts this is the best that we can do here. --- src/core/fonts.js | 21 +++++++++++++++++---- test/pdfs/.gitignore | 1 + test/pdfs/issue11242_reduced.pdf | Bin 0 -> 2751 bytes test/test_manifest.json | 7 +++++++ 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 test/pdfs/issue11242_reduced.pdf diff --git a/src/core/fonts.js b/src/core/fonts.js index edb642be4..cd8c954f4 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -1203,10 +1203,10 @@ var Font = (function FontClosure() { this.remeasure = Object.keys(this.widths).length > 0; if (isStandardFont && type === 'CIDFontType2' && this.cidEncoding.startsWith('Identity-')) { - var GlyphMapForStandardFonts = getGlyphMapForStandardFonts(); + const GlyphMapForStandardFonts = getGlyphMapForStandardFonts(); // Standard fonts might be embedded as CID font without glyph mapping. // Building one based on GlyphMapForStandardFonts. - var map = []; + const map = []; for (charCode in GlyphMapForStandardFonts) { map[+charCode] = GlyphMapForStandardFonts[charCode]; } @@ -1247,7 +1247,8 @@ var Font = (function FontClosure() { getGlyphsUnicode(), this.differences); } else { - var glyphsUnicodeMap = getGlyphsUnicode(); + const glyphsUnicodeMap = getGlyphsUnicode(); + const map = []; this.toUnicode.forEach((charCode, unicodeCharCode) => { if (!this.composite) { var glyphName = (this.differences[charCode] || @@ -1257,8 +1258,20 @@ var Font = (function FontClosure() { unicodeCharCode = unicode; } } - this.toFontChar[charCode] = unicodeCharCode; + map[+charCode] = unicodeCharCode; }); + + // Attempt to improve the glyph mapping for (some) composite fonts that + // appear to lack meaningful ToUnicode data. + if (this.composite && this.toUnicode instanceof IdentityToUnicodeMap) { + if (/Verdana/i.test(name)) { // Fixes issue11242_reduced.pdf + const GlyphMapForStandardFonts = getGlyphMapForStandardFonts(); + for (charCode in GlyphMapForStandardFonts) { + map[+charCode] = GlyphMapForStandardFonts[charCode]; + } + } + } + this.toFontChar = map; } this.loadedName = fontName.split('-')[0]; this.fontType = getFontType(type, subtype); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 27729226d..28f44733c 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -84,6 +84,7 @@ !issue11016_reduced.pdf !issue11045.pdf !issue11150_reduced.pdf +!issue11242_reduced.pdf !bad-PageLabels.pdf !decodeACSuccessive.pdf !filled-background.pdf diff --git a/test/pdfs/issue11242_reduced.pdf b/test/pdfs/issue11242_reduced.pdf new file mode 100644 index 0000000000000000000000000000000000000000..469d178e1d827515a869d9e2d578ad8429d71f0a GIT binary patch literal 2751 zcmcguO-~y~7`D{gT$>(xn?tGKVDHTAe618k0t~@z(jc(XgXO~pFODnlTJ|D^{>dKt z586M{=b5#QV+l1;rJ|s`yx$+s`_3L*_RqVz7sSC|fB*5P&{E0z!*5c&d?~Waa$2pV z0qaU+!^cG>v(vIE@9L>|^-5IpNz$ZzYx47KvXY~mCgY7wawD?S`eEKky=zLnt?6aC zte~(CcU7(Ghvg08r&P{sh+0ZZ+h%mGq)QZ%!N2TnHJOzs^(Q$}U>gOo`YZ|NFmDiK zCH=;5Qw4o)Q|VW$8wkpI!?-9YP#wNb%2kz8$=+8>$jk0YeK!%=^}~lI^@m+jo5HCn zva|V3J(xaeSuDU0fFp8^c zIzzxmd3X%GR!1Uxx13Z<4&-n%kfVejdgbJovqe)cWx>vi>{mImR*szYV;MD|pbdyZ zjy%vMqX7}aSOyQ+TZn>!a*QA-@^&oqwIl|(a&Ti{Z54EL5HW|F03umO2T=ik1+ASP zO9!iv+#o^-Fn7@Lk>(K`g9rh6`J#Xbu>wUNBJYt!qz+TYh(N%hf#*bMc+NdJw4z8O zjaDZWN)ckU9Hv2?2tQgmxYqf`E+REoM}(ka7`$ z5W>Lc1R+O7fB_8(#L;jXlVVThC%t4IVYZHZJM9j2fla&WX#*qj!`h(VyGb`(e`#UKWK zgtmn!T6O{1haB}-mTHlQ<}T~$)Qf%wj2qyU8EJd__eFVL$+Nd9=Tu2 zdpzZPFBnefdn~ue-c)6JuC(%n$d36EHbADudA}>C_#W^^2QRYrk!*PU@z(&~1+$yu z`Sh;h)n%BI^cHuWEqYN|TuCRpxypOS81FnTiw-LERIW*?fRB(6a+{;V-J|eyk#RxF z#YHunendVd?7pFCIiIf)=i-aY%kijuacQpTxzJXySDG`XSJ=X6mW_L?y99oUwBt_jqk+v+Fs9ouULHgFe#T!Y6ncMI5;?a HcP{<`;5fN~ literal 0 HcmV?d00001 diff --git a/test/test_manifest.json b/test/test_manifest.json index 2fd3a1d93..d0dc9aadb 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -2167,6 +2167,13 @@ "rounds": 1, "type": "eq" }, + { "id": "issue11242", + "file": "pdfs/issue11242_reduced.pdf", + "md5": "ba50b6ee537f3e815ccfe0c99e598e05", + "link": false, + "rounds": 1, + "type": "eq" + }, { "id": "issue3323", "file": "pdfs/issue3323.pdf", "md5": "1a14ff574013caeafa9d598269988764",