Skip to content

Commit 37fb625

Browse files
committed
Fixes lineWidth/scale calculation for the fonts
1 parent 9d3afdd commit 37fb625

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/canvas.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
799799
this.applyTextTransforms();
800800

801801
var lineWidth = current.lineWidth;
802-
var scale = Math.abs(current.textMatrix[0] * fontMatrix[0]);
802+
var a1 = current.textMatrix[0], b1 = current.textMatrix[1];
803+
var a2 = fontMatrix[0], b2 = fontMatrix[1];
804+
var scale = Math.sqrt((a1 * a1 + b1 * b1) * (a2 * a2 + b2 * b2));
803805
if (scale == 0 || lineWidth == 0)
804806
lineWidth = this.getSinglePixelWidth();
805807
else
@@ -1340,7 +1342,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
13401342
},
13411343
getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
13421344
var inverse = this.ctx.mozCurrentTransformInverse;
1343-
return Math.abs(inverse[0] + inverse[2]);
1345+
// max of the current horizontal and vertical scale
1346+
return Math.sqrt(Math.max(
1347+
(inverse[0] * inverse[0] + inverse[1] * inverse[1]),
1348+
(inverse[2] * inverse[2] + inverse[3] * inverse[3])));
13441349
}
13451350
};
13461351

0 commit comments

Comments
 (0)