Update canvas-renderer.ts

Fixes vertical alignment of text within divs
This commit is contained in:
haztheo 2022-08-18 17:20:44 +01:00 committed by GitHub
parent 6020386bbe
commit 66254512b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -146,12 +146,11 @@ export class CanvasRenderer extends Renderer {
renderTextWithLetterSpacing(text: TextBounds, letterSpacing: number, baseline: number): void { renderTextWithLetterSpacing(text: TextBounds, letterSpacing: number, baseline: number): void {
if (letterSpacing === 0) { if (letterSpacing === 0) {
this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + baseline); this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + text.bounds.height - baseline);
} else { } else {
const letters = segmentGraphemes(text.text); const letters = segmentGraphemes(text.text);
letters.reduce((left, letter) => { letters.reduce((left, letter) => {
this.ctx.fillText(letter, left, text.bounds.top + baseline); this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + text.bounds.height - baseline);
return left + this.ctx.measureText(letter).width; return left + this.ctx.measureText(letter).width;
}, text.bounds.left); }, text.bounds.left);
} }