Keep text centered in canvas

This commit is contained in:
Nicolò P 2023-08-29 10:12:24 +02:00
parent 41508af91e
commit 23a96ff6cd

View File

@ -37,7 +37,9 @@ document.addEventListener('DOMContentLoaded', () => {
} }
// Draw instrument ID as text // Draw instrument ID as text
ctx.font = '48px sans-serif'; ctx.font = '48px sans-serif';
ctx.fillText(idInstr, 45, 350); const txtWidth = Math.round(ctx.measureText(idInstr).width);
const txtLeftDist = (200 - txtWidth) / 2 + 25;
ctx.fillText(idInstr, txtLeftDist, 350);
erihsLogo.onload = () => { erihsLogo.onload = () => {
ctx.drawImage(erihsLogo, 25, 375, 200, 41) ctx.drawImage(erihsLogo, 25, 375, 200, 41)