Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change font size of Canvas without knowing font family

Tags:

People also ask

What font size does canvas use?

The default font is 10px sans-serif.

How do I edit text in canvas?

In the canvas toolbar, click the Select/Transform tool, then double-click text in the canvas. In the Layer's list, select a text layer, then in the Text editor (at the bottom of the Text Inspector's Format pane), drag within or double-click text.


Is there a way to only change the font size of a canvas context without having to know/write the font family.

 var ctx = document.getElementById("canvas").getContext("2d");   ctx.font = '20px Arial'; //Need to speficy both size and family...      

Note:

ctx.fontSize = '12px'; //doesn't exist so won't work... ctx.style.fontSize = '20 px' //doesn't exist so won't work...                           //we are changing the ctx, not the canvas itself 

Other note: I could do something like: detect where 'px' is, remove what's before 'px' and replace it by my font size. But I'd like something easier than that if possible.