]> git.parisson.com Git - pdf.js.git/commitdiff
Moving CID-0 encoding hack to fonts.js
authornotmasteryet <async.processingjs@yahoo.com>
Thu, 29 Sep 2011 02:19:49 +0000 (21:19 -0500)
committernotmasteryet <async.processingjs@yahoo.com>
Thu, 29 Sep 2011 02:19:49 +0000 (21:19 -0500)
fonts.js
pdf.js

index b565c67e76bf064f729cd4a53abf6cf9de29cdeb..22b6a6c990d10dfc099ce5994b12601921c0163c 100644 (file)
--- a/fonts.js
+++ b/fonts.js
@@ -429,6 +429,9 @@ var Font = (function Font() {
       return;
     }
 
+    // Trying to fix encoding using glyph widths and CIDSystemInfo
+    this.fixWidths(properties);
+
     if (!file) {
       // The file data is not specified. Trying to fix the font name
       // to be used with the canvas.font.
@@ -1403,6 +1406,63 @@ var Font = (function Font() {
       return stringToArray(otf.file);
     },
 
+    fixWidths: function font_fixWidths(properties) {
+      var encoding = properties.encoding;
+      if (encoding[0])
+        return;
+      var glyphsWidths = properties.widths;
+      if (!glyphsWidths)
+        return;
+
+      var cidSystemInfo = properties.cidSystemInfo;
+      var cidToUnicode;
+      if (cidSystemInfo) {
+        cidToUnicode = CIDToUnicodeMaps[cidSystemInfo.registry +
+          '-' + cidSystemInfo.ordering];
+      }
+      if (!cidToUnicode)
+        return;
+
+      encoding[0] = { unicode: 0, width: 0 };
+      var glyph = 1, i, j;
+      for (i = 0; i < cidToUnicode.length; ++i) {
+        var unicode = cidToUnicode[i];
+        if (isArray(unicode)) {
+          var length = unicode.length;
+          if (glyph in glyphsWidths) {
+            for (j = 0; j < length; j++) {
+              encoding[unicode[j]] = {
+                unicode: unicode[j],
+                width: glyphsWidths[glyph]
+              };
+            }
+          }
+          glyph++;
+        } else if (typeof unicode === 'object') {
+          var fillLength = unicode.f;
+          if (fillLength) {
+            unicode = unicode.c;
+            for (j = 0; j < fillLength; ++j) {
+              if (!(glyph in glyphsWidths))
+                continue;
+              encoding[unicode] = {
+                unicode: unicode,
+                width: glyphsWidths[glyph]
+              };
+              unicode++;
+              glyph++;
+            }
+          } else
+            glyph += unicode.s;
+        } else if (unicode) {
+          encoding[unicode] = {
+            unicode: unicode,
+            width: glyphsWidths[glyph++]
+          };
+        }
+      }
+    },
+
     bindWorker: function font_bindWorker(data) {
       postMessage({
         action: 'font',
diff --git a/pdf.js b/pdf.js
index 66e575abf417f5e0124a83f62dab1d14cce377bc..08c962406cba5f7a7bba4390613482c0dde956c9 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -4472,56 +4472,19 @@ var PartialEvaluator = (function partialEvaluator() {
         // Glyph ids are big-endian 2-byte values
         encoding = properties.encoding;
 
+        // CIDSystemInfo might help to match width and glyphs
+        var cidSystemInfo = dict.get('CIDSystemInfo');
+        if (isDict(cidSystemInfo)) {
+          properties.cidSystemInfo = {
+            registry: cidSystemInfo.get('Registry'),
+            ordering: cidSystemInfo.get('Ordering'),
+            supplement: cidSystemInfo.get('Supplement')
+          };
+        }
+
         var cidToGidMap = dict.get('CIDToGIDMap');
         if (!cidToGidMap || !isRef(cidToGidMap)) {
-          // trying to guess encoding from CIDSystemInfo
-          var cidSystemInfo = dict.get('CIDSystemInfo');
-          var cidToUnicode;
-          if (isDict(cidSystemInfo)) {
-            cidToUnicode = CIDToUnicodeMaps[
-              cidSystemInfo.get('Registry') + '-' +
-              cidSystemInfo.get('Ordering')];
-          }
-          if (cidToUnicode) {
-            encoding[0] = { unicode: 0, width: 0 };
-            var glyph = 1, i, j;
-            for (i = 0; i < cidToUnicode.length; ++i) {
-              var unicode = cidToUnicode[i];
-              if (isArray(unicode)) {
-                var length = unicode.length;
-                if (glyph in glyphsWidths) {
-                  for (j = 0; j < length; j++) {
-                    encoding[unicode[j]] = {
-                      unicode: unicode[j],
-                      width: glyphsWidths[glyph]
-                    };
-                  }
-                }
-                glyph++;
-              } else if (typeof unicode === 'object') {
-                var fillLength = unicode.f;
-                if (fillLength) {
-                  unicode = unicode.c;
-                  for (j = 0; j < fillLength; ++j) {
-                    if (!(glyph in glyphsWidths))
-                      continue;
-                    encoding[unicode] = {
-                      unicode: unicode,
-                      width: glyphsWidths[glyph]
-                    };
-                    unicode++;
-                    glyph++;
-                  }
-                } else
-                  glyph += unicode.s;
-              } else if (unicode) {
-                encoding[unicode] = {
-                  unicode: unicode,
-                  width: glyphsWidths[glyph++]
-                };
-              }
-            }
-          }
+
 
           return Object.create(GlyphsUnicode);
         }