Skip to content

Commit a185318

Browse files
committed
Comments
1 parent dc33b24 commit a185318

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/canvas.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ var CanvasGraphics = (function canvasGraphics() {
103103
this.ctx.transform(0, -1, -1, 0, cw, ch);
104104
break;
105105
}
106+
// Scale so that canvas units are the same as PDF user space units
106107
this.ctx.scale(cw / mediaBox.width, ch / mediaBox.height);
107108
this.textDivs = [];
108109
this.textLayerQueue = [];
@@ -491,14 +492,18 @@ var CanvasGraphics = (function canvasGraphics() {
491492
pushTextDivs: function canvasGraphicsPushTextDivs(text) {
492493
var div = document.createElement('div');
493494
var fontSize = this.current.fontSize;
494-
var fontHeight = text.geom.vScale * fontSize;
495+
496+
// vScale and hScale already contain the scaling to pixel units
497+
// as mozCurrentTransform reflects ctx.scale() changes
498+
// (see beginDrawing())
499+
var fontHeight = fontSize * text.geom.vScale;
500+
div.dataset.canvasWidth = text.canvasWidth * text.geom.hScale;
495501

496502
div.style.fontSize = fontHeight + 'px';
497503
div.style.fontFamily = this.current.font.loadedName || 'sans-serif';
498504
div.style.left = text.geom.x + 'px';
499505
div.style.top = (text.geom.y - fontHeight) + 'px';
500506
div.innerHTML = text.str;
501-
div.dataset.canvasWidth = text.canvasWidth * text.geom.hScale;
502507
div.dataset.textLength = text.length;
503508
this.textDivs.push(div);
504509
},

src/metrics.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
'use strict';
55

6+
// The Metrics object contains glyph widths (in glyph space units).
7+
// As per PDF spec, for most fonts (Type 3 being an exception) a glyph
8+
// space unit corresponds to 1/1000th of text space unit.
69
var Metrics = {
710
'Courier': 600,
811
'Courier-Bold': 600,

0 commit comments

Comments
 (0)