]> git.parisson.com Git - pdf.js.git/commitdiff
Fix cmap encoding records to pass the sanitizer in the case of a duplicate platform...
authorVivien Nicolas <21@vingtetun.org>
Tue, 6 Sep 2011 13:12:33 +0000 (15:12 +0200)
committerVivien Nicolas <21@vingtetun.org>
Tue, 6 Sep 2011 13:12:33 +0000 (15:12 +0200)
fonts.js

index 50eafc5669c95fa73296a277acaed6168dc78c57..f53a2098b702fce1d707f8d8ca0316ac66931fda 100755 (executable)
--- a/fonts.js
+++ b/fonts.js
@@ -857,9 +857,42 @@ var Font = (function Font() {
           });
         }
 
+        // Check that table are sorted by platformID then encodingID,
+        var tables = [records[0]];
+        for (var i = 1; i < numRecords; i++) {
+          // The sanitizer will drop the font if 2 tables have the same
+          // platformID and the same encodingID, this will be correct for
+          // most cases but if the font has been made for Mac it could
+          // exist a few platformID: 1, encodingID: 0 but with a different
+          // language field and that's correct. But the sanitizer does not
+          // seem to support this case.
+          var current = records[i];
+          var previous = records[i - 1];
+          if (((current.platformID << 16) + current.encodingID) <=
+             ((previous.platformID << 16) + previous.encodingID))
+                continue;
+          tables.push(current);
+        }
+
+        var missing = numRecords - tables.length;
+        if (numRecords - tables.length) {
+          numRecords = tables.length;
+          var data = string16(version) + string16(numRecords);
+
+          for (var i = 0; i < numRecords; i++) {
+            var table = tables[i];
+            data += string16(table.platformID) +
+                    string16(table.encodingID) +
+                    string32(table.offset);
+          }
+
+          for (var i = 0; i < data.length; i++)
+            cmap.data[i] = data.charCodeAt(i); 
+        }
+
         var encoding = properties.encoding;
         for (var i = 0; i < numRecords; i++) {
-          var table = records[i];
+          var table = tables[i];
           font.pos = start + table.offset;
 
           var format = int16(font.getBytes(2));