Skip to content

Commit 686f275

Browse files
committed
Fix font and spaces
1 parent 9ebec03 commit 686f275

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/canvas.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,7 @@ var CanvasGraphics = (function canvasGraphics() {
494494
var fontHeight = text.geom.vScale * fontSize;
495495

496496
div.style.fontSize = fontHeight + 'px';
497-
// TODO: family should be '= font.loadedName', but some fonts don't
498-
// have spacing info (cf. fonts.js > Font > fields > htmx)
499-
div.style.fontFamily = 'serif';
497+
div.style.fontFamily = this.current.font.loadedName || 'serif';
500498
div.style.left = text.geom.x + 'px';
501499
div.style.top = (text.geom.y - fontHeight) + 'px';
502500
div.innerHTML = text.str;
@@ -560,8 +558,8 @@ var CanvasGraphics = (function canvasGraphics() {
560558
current.x += charWidth;
561559

562560
text.str += unicodeToChar(glyph.unicode);
563-
text.canvasWidth += charWidth;
564561
text.length++;
562+
text.canvasWidth += charWidth;
565563
}
566564
ctx.restore();
567565
} else {
@@ -582,9 +580,9 @@ var CanvasGraphics = (function canvasGraphics() {
582580
ctx.fillText(char, width, 0);
583581
width += charWidth;
584582

585-
text.str += char;
586-
text.canvasWidth += charWidth;
583+
text.str += char === ' ' ? ' ' : char;
587584
text.length++;
585+
text.canvasWidth += charWidth;
588586
}
589587

590588
current.x += width;

0 commit comments

Comments
 (0)