String metrics in canvas :
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.font = "30px Arial";
var txt = "Hello World"
ctx.fillText("width:" + ctx.measureText(txt).width, 10, 50)
ctx.fillText(txt, 10, 100);
HTML canvas measureText() Method I can only take the width.
I was able to insert
in SVG, but it doesn't seem to be possible in canvas
There is a possible breakable:0/1 attribute between the letters.
lineheight
If you write 333 with point 0,0 and size:100 and getBounds
paper.getBounds.height is simply fontsize * 1.2
This page is auto-translated from /nishio/付箋の自動フォントサイズ調整 using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.