From 87762afec477b0951681df65e6a8286f9d5a1c6a Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Wed, 2 Dec 2015 16:47:20 -0800 Subject: [PATCH] Remove glyph id's outside the range of valid glyphs. OTS does not like invalid glyph ids in a camp table. --- src/core/fonts.js | 15 ++++++++++----- test/pdfs/.gitignore | 1 + test/pdfs/issue5564_reduced.pdf | Bin 0 -> 1859 bytes test/test_manifest.json | 10 ++++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 test/pdfs/issue5564_reduced.pdf diff --git a/src/core/fonts.js b/src/core/fonts.js index fef393d33..a13a7ea4e 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -2798,11 +2798,15 @@ var Font = (function FontClosure() { }; } - function getRanges(glyphs) { + function getRanges(glyphs, numGlyphs) { // Array.sort() sorts by characters, not numerically, so convert to an // array of characters. var codes = []; for (var charCode in glyphs) { + // Remove an invalid glyph ID mappings to make OTS happy. + if (glyphs[charCode] >= numGlyphs) { + continue; + } codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] }); } codes.sort(function fontGetRangesSort(a, b) { @@ -2831,8 +2835,8 @@ var Font = (function FontClosure() { return ranges; } - function createCmapTable(glyphs) { - var ranges = getRanges(glyphs); + function createCmapTable(glyphs, numGlyphs) { + var ranges = getRanges(glyphs, numGlyphs); var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1; var cmap = '\x00\x00' + // version string16(numTables) + // numTables @@ -4335,7 +4339,7 @@ var Font = (function FontClosure() { this.toFontChar = newMapping.toFontChar; tables.cmap = { tag: 'cmap', - data: createCmapTable(newMapping.charCodeToGlyphId) + data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs) }; if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) { @@ -4473,7 +4477,8 @@ var Font = (function FontClosure() { builder.addTable('OS/2', createOS2Table(properties, newMapping.charCodeToGlyphId)); // Character to glyphs mapping - builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId)); + builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId, + numGlyphs)); // Font header builder.addTable('head', '\x00\x01\x00\x00' + // Version number diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 38a33eb86..49ec4bef9 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -22,6 +22,7 @@ !bug1020858.pdf !bug1050040.pdf !bug1200096.pdf +!issue5564_reduced.pdf !canvas.pdf !complex_ttf_font.pdf !extgstate.pdf diff --git a/test/pdfs/issue5564_reduced.pdf b/test/pdfs/issue5564_reduced.pdf new file mode 100644 index 0000000000000000000000000000000000000000..0eddb63e51dd2909519f1359f17da996e0beaa73 GIT binary patch literal 1859 zcmaJ>ZA=tL7={Xxj<&T;OC>ROPC__RVRvqC?;}AhcgIyD3gxb%1*^;L-m!SMOLvzd zMrqn&DbWNKKR`{CXbdJq3)a@eG?X4#u?CR-Kw28x+SG)ky|y-5ZB09~_mM-boBJ{I z-aF6x%=13;=9IhK`KZ7Oa(=uq_BB9|hH_0E1cilwa*IJtP$1 zTdqy+TJ_RN0zm=B z&>RkV3#`gV7Aqt<5SeUtLTLk_yiN7^uB0SEQN(&pR`A8R`WPdN-9(%c*UFr%RrG9$ zgsmk?0n9`6`vpaie1ZzA7zCrL;35uA72;`-suZPSNfqOPWOyQ4!oZ$}8ckL4c; z=5daut+O0m!*AmFO+3Hvw>wXQ#(Cp!=jE>){fMSDaP_InW2>*s85z01+y9Rt{KvQV z?mVBhc68$pz5Vm$<`uV^8y8gn^_}y>ciZ+L%ancKSig~3cHA{MJ~8o%p>Lf5m35oX z95d(Tp0#DOCEbMs#wx?9iov|IC(fTRvZ!*9q1Klb52D;xQ+xZ?bsNvw&h;#1(~UDn zjvhSFwf9iv-mcE$HxF*ycepeBc}jm=MSS0DM}_JvdJ+p{LKe~oNk zl9D<%#iKa(Jj%6fvQ*_<0BdfES}xiaCx?9?2a?q#|0mR4E$||z`+~+{6HP;w#;sZ< z^0;|cf`oTYxdEFO#ciUONk$}j3B+;^_g;&$_#gZVL6sX6;*jW&!p4iO5VVo11Rnoz zX-UIyDzxj-m{AFXWCG+!f`D68RE@kz$Pmi%>yk*O9)3IeQ=DybNS-}@pm7^QVr{%9 zUL~228vwJ6iH9neRJKy&wOTBpNtZL)3xb!-np`QtIyRE6$^LbC0U}L-UKh4K(pP?9 ztfm=jp0^I70vp3XuMgtcudf=RrNE9zH@rO5(_*Qh#0wtbo-K;t2Y9H^fKGhS!m