]> git.parisson.com Git - pdf.js.git/commitdiff
Fixing defaultWidth; variables names
authornotmasteryet <async.processingjs@yahoo.com>
Fri, 16 Sep 2011 00:26:32 +0000 (19:26 -0500)
committernotmasteryet <async.processingjs@yahoo.com>
Fri, 16 Sep 2011 00:26:32 +0000 (19:26 -0500)
fonts.js
pdf.js

index 404c3f85342b029656c8ec07981a98d18c2078a5..2b40c1f49096bf2ba2885c75d4045180b2a7e793 100755 (executable)
--- a/fonts.js
+++ b/fonts.js
@@ -472,6 +472,7 @@ var Font = (function Font() {
     this.data = data;
     this.type = properties.type;
     this.textMatrix = properties.textMatrix;
+    this.defaultWidth = properties.defaultWidth;
     this.loadedName = getUniqueName();
     this.composite = properties.composite;
     this.loading = true;
@@ -1298,13 +1299,13 @@ var Font = (function Font() {
 
     charsToGlyphs: function fonts_chars2Glyphs(chars) {
       var charsCache = this.charsCache;
-      var str;
+      var glyphs;
 
       // if we translated this string before, just grab it from the cache
       if (charsCache) {
-        str = charsCache[chars];
-        if (str)
-          return str;
+        glyphs = charsCache[chars];
+        if (glyphs)
+          return glyphs;
       }
 
       // lazily create the translation cache
@@ -1315,7 +1316,8 @@ var Font = (function Font() {
       var encoding = this.encoding;
       if (!encoding)
         return chars;
-      var glyphs = [];
+
+      glyphs = [];
 
       if (this.composite) {
         // composite fonts have multi-byte strings convert the string from
@@ -1326,23 +1328,28 @@ var Font = (function Font() {
                                        // loop should never end on the last byte
         for (var i = 0; i < length; i++) {
           var charcode = int16([chars.charCodeAt(i++), chars.charCodeAt(i)]);
-          var unicode = encoding[charcode];
-          if ('undefined' == typeof(unicode)) {
+          var glyph = encoding[charcode];
+          if ('undefined' == typeof(glyph)) {
             warn('Unencoded charcode ' + charcode);
-            unicode = { unicode: charcode };
+            glyph = { unicode: charcode };
           }
-          glyphs.push(unicode);
+          glyphs.push(glyph);
+          // placing null after each word break charcode (ASCII SPACE)
+          if (charcode == 0x20)
+            glyphs.push(null);
         }
       }
       else {
         for (var i = 0; i < chars.length; ++i) {
           var charcode = chars.charCodeAt(i);
-          var unicode = encoding[charcode];
-          if ('undefined' == typeof(unicode)) {
+          var glyph = encoding[charcode];
+          if ('undefined' == typeof(glyph)) {
             warn('Unencoded charcode ' + charcode);
-            unicode = { unicode: charcode };
+            glyph = { unicode: charcode };
           }
-          glyphs.push(unicode);
+          glyphs.push(glyph);
+          if (charcode == 0x20)
+            glyphs.push(null);
         }
       }
 
diff --git a/pdf.js b/pdf.js
index b4fd9c7a2f4cfb15996176968023f1de847a7915..a8ae5523452af360985f174e67165772c1cf94d5 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -4294,7 +4294,6 @@ var PartialEvaluator = (function() {
             };
           }
         } else if (type == 'CIDFontType0') {
-          encoding = xref.fetchIfRef(dict.get('Encoding'));
           if (IsName(encoding)) {
             // Encoding is a predefined CMap
             if (encoding.name == 'Identity-H') {
@@ -4521,8 +4520,7 @@ var PartialEvaluator = (function() {
           }
         }
 
-        // TODO implement default widths for standard fonts metrics
-        var defaultWidth = 1000;
+        var defaultWidth = 0;
         var widths = Metrics[stdFontMap[baseFontName] || baseFontName];
         if (IsNum(widths)) {
           defaultWidth = widths;
@@ -4994,6 +4992,12 @@ var CanvasGraphics = (function() {
       var width = 0;
       for (var i = 0; i < glyphs.length; i++) {
         var glyph = glyphs[i];
+        if (glyph === null) {
+          // word break
+          width += wordSpacing;
+          continue;
+        }
+
         var unicode = glyph.unicode;
         var char = unicode >= 0x10000 ?
           String.fromCharCode(0xD800 | ((unicode - 0x10000) >> 10),
@@ -5001,11 +5005,8 @@ var CanvasGraphics = (function() {
 
         var charWidth = (glyph.width || defaultCharWidth) * fontSize * 0.001;
         charWidth += charSpacing;
-        if (unicode == 32)
-          charWidth += wordSpacing;
 
-        ctx.fillText(char, 0, 0);
-        ctx.translate(charWidth, 0);
+        ctx.fillText(char, width, 0);
         width += charWidth;
       }
       current.x += width;