]> git.parisson.com Git - pdf.js.git/commitdiff
Fix font and spaces
authorArtur Adib <arturadib@gmail.com>
Tue, 8 Nov 2011 21:05:11 +0000 (16:05 -0500)
committerArtur Adib <arturadib@gmail.com>
Tue, 8 Nov 2011 21:05:11 +0000 (16:05 -0500)
src/canvas.js

index 05f74f24e1b8b2c1e621b70c81b0da021c2d8092..83d9c34d1643edb85f928a50315b2fc33a7060f5 100644 (file)
@@ -494,9 +494,7 @@ var CanvasGraphics = (function canvasGraphics() {
       var fontHeight = text.geom.vScale * fontSize;
 
       div.style.fontSize = fontHeight + 'px';
-      // TODO: family should be '= font.loadedName', but some fonts don't 
-      // have spacing info (cf. fonts.js > Font > fields > htmx)
-      div.style.fontFamily = 'serif'; 
+      div.style.fontFamily = this.current.font.loadedName || 'serif';
       div.style.left = text.geom.x + 'px';
       div.style.top = (text.geom.y - fontHeight) + 'px';
       div.innerHTML = text.str;
@@ -560,8 +558,8 @@ var CanvasGraphics = (function canvasGraphics() {
           current.x += charWidth;
 
           text.str += unicodeToChar(glyph.unicode);
-          text.canvasWidth += charWidth;
           text.length++;
+          text.canvasWidth += charWidth;
         }
         ctx.restore();
       } else {
@@ -582,9 +580,9 @@ var CanvasGraphics = (function canvasGraphics() {
           ctx.fillText(char, width, 0);
           width += charWidth;
           
-          text.str += char;
-          text.canvasWidth += charWidth;
+          text.str += char === ' ' ? '&nbsp;' : char;
           text.length++;
+          text.canvasWidth += charWidth;
         }
 
         current.x += width;