In KonvaJS Text Object there is a property fontSize like fontSize: 30 but I need to stretch the text according the width and height I give for it.
Here what I wrote:
var textX = new Konva.Text({
text: 'X',
align: 'center',
x: 60,
y: 60,
width: 60,
height: 40
});
What do you suggest to let the code work?
Text fonts may not incrementally scale to exactly fit a desired width, but you can come close.
pxtestFontsize (almost any reasonable test size will do),testFontsize*desiredWidth/measuredWidth,pxfont size in your Konva.Text.Notes: Some fonts do not scale with decimal precision so you might have to
.toFixed(0)the resulting scaled font size. Some fonts may not incrementally scale at all and you will get the nearest available font size -- which might not fill the desired width well.Example code: