Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html5 canvas doesn't fill text at coordinates (0,0)

Why does the canvas not do anything for fillText(text, 0,0) but works for fillText(text, 10, 10)?

fillText(text, 0,0): http://jsfiddle.net/kFhQm/4/

fillText(text, 10, 10): http://jsfiddle.net/kFhQm/5/

like image 368
TheOne Avatar asked Jan 12 '13 01:01

TheOne


1 Answers

The second argument is the Y coordinate for the baseline of the text (the default textBaseline is "alphabetic") , so the text is being drawn above the visible canvas element when you use 0.

jsFiddle.

You could use a different number or alternatively, change the textBaseline property to something suitable, such as "top".

ctx.textBaseline = "top";

jsFiddle.

like image 134
alex Avatar answered Oct 02 '22 13:10

alex