]> git.parisson.com Git - pdf.js.git/commitdiff
Fix regression caused by pull request #491. Glyphs in positions that match complex...
authorAdil Allawi <adil@diwan.com>
Mon, 3 Oct 2011 09:16:18 +0000 (10:16 +0100)
committerAdil Allawi <adil@diwan.com>
Tue, 4 Oct 2011 15:18:38 +0000 (16:18 +0100)
fonts.js

index 50dfa2337f9b8e45fa11d92a649486122e9b8452..a4af5fb483561c3b5553233389319c30c5344c7f 100644 (file)
--- a/fonts.js
+++ b/fonts.js
@@ -11,6 +11,10 @@ var kMaxWaitForFontFace = 1000;
 
 // Unicode Private Use Area
 var kCmapGlyphOffset = 0xE000;
+var kSizeOfGlyphArea = 0x1900;
+
+//start of CJK block
+var kUnicodeCJKStart = 0x2E80;
 
 // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
 // except for Type 3 fonts
@@ -1212,19 +1216,25 @@ var Font = (function Font() {
         }
 
         var encoding = properties.encoding, i;
+
+        // offsetting glyphs to avoid problematic unicode ranges should only be
+        // done for fonts with a medium-sized glyph count otherwise we could
+        // overflow the glyph range or overwrite existing glyph positions
+        var cmapGlyphOffset = numGlyphs < kSizeOfGlyphArea ? kCmapGlyphOffset : 0;
+
         for (i in encoding) {
           if (encoding.hasOwnProperty(i)) {
             var unicode = encoding[i].unicode;
-            if (unicode <= 0x1f || (unicode >= 127 && unicode <= 255))
-              encoding[i].unicode = unicode += kCmapGlyphOffset;
+            if (unicode <= 0x1f || (unicode >= 127 && unicode <= kUnicodeCJKStart))
+              encoding[i].unicode = unicode += cmapGlyphOffset;
           }
         }
 
         var glyphs = [];
         for (i = 1; i < numGlyphs; i++) {
           glyphs.push({
-            unicode: i <= 0x1f || (i >= 127 && i <= 255) ?
-              i + kCmapGlyphOffset : i
+            unicode: i <= 0x1f || (i >= 127 && i < kUnicodeCJKStart) ?
+              i + cmapGlyphOffset : i
           });
         }
         cmap.data = createCMapTable(glyphs);