]> git.parisson.com Git - pdf.js.git/commitdiff
Sets proper unicode range for symbols; sanitize no-glyphs fonts
authornotmasteryet <async.processingjs@yahoo.com>
Sat, 18 Feb 2012 21:01:53 +0000 (15:01 -0600)
committernotmasteryet <async.processingjs@yahoo.com>
Sat, 18 Feb 2012 21:01:53 +0000 (15:01 -0600)
src/fonts.js
test/pdfs/issue1243.pdf.link [new file with mode: 0644]
test/test_manifest.json

index 0f9b6f9d09f4343f836882be50b7e5986817780d..cdb56efa784d0869817f0e31f36ce4d5c6d37c2a 100644 (file)
@@ -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 (file)
index 0000000..89187f7
--- /dev/null
@@ -0,0 +1 @@
+http://www.nsa.gov/public_info/_files/nash_letters/nash_letters1.pdf
index e09f16da92ad11cd39f457d0ac9d01926144ec53..e19aeb3a3fddf2e7af513f61e0a7534c38ad9119 100644 (file)
       "rounds": 1,
       "link": true,
       "type": "eq"
+    },
+    {  "id": "issue1243",
+      "file": "pdfs/issue1243.pdf",
+      "md5": "130c849b83513d5ac5e03c6421fc7489",
+      "rounds": 1,
+      "pageLimit": 2,
+      "link": true,
+      "type": "eq"
     }
 ]