]> git.parisson.com Git - pdf.js.git/commitdiff
Comments
authorArtur Adib <arturadib@gmail.com>
Mon, 28 Nov 2011 14:25:25 +0000 (09:25 -0500)
committerArtur Adib <arturadib@gmail.com>
Mon, 28 Nov 2011 14:25:25 +0000 (09:25 -0500)
src/canvas.js
src/metrics.js

index 0107570d9b983c3f1a31fa6699c3b3cc5ab9d500..ab1422758394927d881c7eb25eeda8424f6002d6 100644 (file)
@@ -103,6 +103,7 @@ var CanvasGraphics = (function canvasGraphics() {
           this.ctx.transform(0, -1, -1, 0, cw, ch);
           break;
       }
+      // Scale so that canvas units are the same as PDF user space units
       this.ctx.scale(cw / mediaBox.width, ch / mediaBox.height);
       this.textDivs = [];
       this.textLayerQueue = [];
@@ -491,14 +492,18 @@ var CanvasGraphics = (function canvasGraphics() {
     pushTextDivs: function canvasGraphicsPushTextDivs(text) {
       var div = document.createElement('div');
       var fontSize = this.current.fontSize;
-      var fontHeight = text.geom.vScale * fontSize;
+
+      // vScale and hScale already contain the scaling to pixel units
+      // as mozCurrentTransform reflects ctx.scale() changes
+      // (see beginDrawing())
+      var fontHeight = fontSize * text.geom.vScale;
+      div.dataset.canvasWidth = text.canvasWidth * text.geom.hScale;
 
       div.style.fontSize = fontHeight + 'px';
       div.style.fontFamily = this.current.font.loadedName || 'sans-serif';
       div.style.left = text.geom.x + 'px';
       div.style.top = (text.geom.y - fontHeight) + 'px';
       div.innerHTML = text.str;
-      div.dataset.canvasWidth = text.canvasWidth * text.geom.hScale;
       div.dataset.textLength = text.length;
       this.textDivs.push(div);
     },
index c21b4aed1ceaaf6553be76659b8b8f190a1d26c2..e64961aa78a9b1c454d0af52a5af3b5eae7d3a64 100644 (file)
@@ -3,6 +3,9 @@
 
 'use strict';
 
+// The Metrics object contains glyph widths (in glyph space units).
+// As per PDF spec, for most fonts (Type 3 being an exception) a glyph
+// space unit corresponds to 1/1000th of text space unit.
 var Metrics = {
   'Courier': 600,
   'Courier-Bold': 600,