html canvas text size not accurate -


I am trying to center the text in a box, but ctx.measureText () Not returning the exact value when the code is run down, the text is not centered correctly. It runs under Google Chrome for me, but I could not find it to run under jsfiddle (sorry)

     

You accidentally use the string instead of font Text every time!

There is only one argument in the measurement text and you are giving it two. It should only be

width = ctx.measureText (text). Wide;

Here it is in jsfiddle:



Comments