From 321750bba6931d929cd3ea457db452bc9b1e3d75 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sat, 18 Feb 2012 15:01:53 -0600 Subject: [PATCH] Sets proper unicode range for symbols; sanitize no-glyphs fonts --- src/fonts.js | 20 +++++++++++++++++++- test/pdfs/issue1243.pdf.link | 1 + test/test_manifest.json | 8 ++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/pdfs/issue1243.pdf.link diff --git a/src/fonts.js b/src/fonts.js index 0f9b6f9d0..cdb56efa7 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -1648,6 +1648,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); } @@ -1928,6 +1940,11 @@ var Font = (function FontClosure() { } } + // If font is symbolic and cmap (3,0) present, the characters are + // located in 0xF000 - 0xF0FF range + this.symbolicGlyphsOffset = + this.isSymbolicFont && !hasShortCmap ? 0xF000 : 0; + // remove glyph references outside range of avaialable glyphs for (var i = 0, ii = ids.length; i < ii; i++) { if (ids[i] >= numGlyphs) @@ -2315,7 +2332,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/test_manifest.json b/test/test_manifest.json index e09f16da9..e19aeb3a3 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -480,5 +480,13 @@ "rounds": 1, "link": true, "type": "eq" + }, + { "id": "issue1243", + "file": "pdfs/issue1243.pdf", + "md5": "130c849b83513d5ac5e03c6421fc7489", + "rounds": 1, + "pageLimit": 2, + "link": true, + "type": "eq" } ]