diff --git a/src/fonts.js b/src/fonts.js index 2884dcb2e..f637fcf09 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -11,6 +11,7 @@ var kMaxWaitForFontFace = 1000; // Unicode Private Use Area var kCmapGlyphOffset = 0xE000; var kSizeOfGlyphArea = 0x1900; +var kSymbolicFontGlyphOffset = 0xF000; // PDF Glyph Space Units are one Thousandth of a TextSpace Unit // except for Type 3 fonts @@ -1648,6 +1649,18 @@ var Font = (function FontClosure() { itemEncode(locaData, j, writeOffset); startOffset = endOffset; } + + if (writeOffset == 0) { + // glyf table cannot be empty -- redoing the glyf and loca tables + // to have single glyph with one point + var simpleGlyph = new Uint8Array( + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]); + for (var i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) + itemEncode(locaData, j, simpleGlyph.length); + glyf.data = simpleGlyph; + return; + } + glyf.data = newGlyfData.subarray(0, writeOffset); } @@ -1876,7 +1889,7 @@ var Font = (function FontClosure() { } } // if it is, replacing with meaningful toUnicode values - if (isIdentity) { + if (isIdentity && !this.isSymbolicFont) { var usedUnicodes = [], unassignedUnicodeItems = []; for (var i = 0, ii = glyphs.length; i < ii; i++) { var unicode = toUnicode[i + 1]; @@ -1928,6 +1941,16 @@ var Font = (function FontClosure() { } } + // Moving all symbolic font glyphs into 0xF000 - 0xF0FF range. + this.symbolicGlyphsOffset = 0; + if (this.isSymbolicFont) { + for (var i = 0, ii = glyphs.length; i < ii; i++) { + var code = glyphs[i].unicode; + glyphs[i].unicode = kSymbolicFontGlyphOffset | (code & 0xFF); + } + this.symbolicGlyphsOffset = kSymbolicFontGlyphOffset; + } + // remove glyph references outside range of avaialable glyphs for (var i = 0, ii = ids.length; i < ii; i++) { if (ids[i] >= numGlyphs) @@ -2315,7 +2338,8 @@ var Font = (function FontClosure() { break; } if (!this.hasEncoding || this.isSymbolicFont) { - unicode = this.useToUnicode ? this.toUnicode[charcode] : charcode; + unicode = this.useToUnicode ? this.toUnicode[charcode] : + (this.symbolicGlyphsOffset + charcode); break; } diff --git a/test/pdfs/issue1243.pdf.link b/test/pdfs/issue1243.pdf.link new file mode 100644 index 000000000..89187f785 --- /dev/null +++ b/test/pdfs/issue1243.pdf.link @@ -0,0 +1 @@ +http://www.nsa.gov/public_info/_files/nash_letters/nash_letters1.pdf diff --git a/test/pdfs/issue1257.pdf.link b/test/pdfs/issue1257.pdf.link new file mode 100644 index 000000000..5a8bdd15c --- /dev/null +++ b/test/pdfs/issue1257.pdf.link @@ -0,0 +1 @@ +http://hse-econ.fi/tervio/MediocritiesAndSuperstars.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index e9aebdc90..23a0f8ed9 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -487,5 +487,21 @@ "rounds": 1, "link": true, "type": "eq" + }, + { "id": "issue1243", + "file": "pdfs/issue1243.pdf", + "md5": "130c849b83513d5ac5e03c6421fc7489", + "rounds": 1, + "pageLimit": 2, + "link": true, + "type": "eq" + }, + { "id": "issue1257", + "file": "pdfs/issue1257.pdf", + "md5": "9111533826bc21ed774e8e01603a2f54", + "rounds": 1, + "pageLimit": 2, + "link": true, + "type": "eq" } ]