How to reduce the font of the text in the canvas, so that it does not go beyond the canvas? using measureText and a while , in which the font is reduced, while it is wider than the canvas , the font goes into minuses and the width of the text is determined incorrectly. how to fix?
var forFont = 30; var topMeasure = context.measureText(top).width; console.log(topMeasure); while(topMeasure > canvas.width){ forFont--; } context.font = forFont + "pt Impact";