Skip to content

Commit 6ad1552

Browse files
committed
Switch canvas font to work with pixels instead of points. This also fixes line spacing issues where fonts are specified in points but line heights are specified in pixels.
Remove extraneous "normal" string from definitions. TODO: Place both declarations somewhere shared, like FontFace or FontUtils or perhaps make measureText have multiple methods (maybe renamed to TextUtils if that's not confusing)
1 parent 128fb6e commit 6ad1552

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/CanvasUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function drawText (ctx, text, x, y, width, height, fontFace, options) {
136136
}
137137

138138
ctx.fillStyle = options.color;
139-
ctx.font = fontFace.attributes.style + ' normal ' + fontFace.attributes.weight + ' ' + options.fontSize + 'pt ' + fontFace.family;
139+
ctx.font = fontFace.attributes.style + ' ' + fontFace.attributes.weight + ' ' + options.fontSize + 'px ' + fontFace.family;
140140

141141
textMetrics.lines.forEach(function (line, index) {
142142
currText = line.text;

lib/measureText.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module.exports = function measureText (text, width, fontFace, fontSize, lineHeig
5050
var tryLine;
5151
var currentLine;
5252

53-
ctx.font = fontFace.attributes.style + ' normal ' + fontFace.attributes.weight + ' ' + fontSize + 'pt ' + fontFace.family;
53+
ctx.font = fontFace.attributes.style + ' ' + fontFace.attributes.weight + ' ' + fontSize + 'px ' + fontFace.family;
5454
textMetrics = ctx.measureText(text);
5555

5656
measuredSize.width = textMetrics.width;

0 commit comments

Comments
 (0)