Pomax / lib-font

This library adds a new Font() object to the JavaScript toolbox, similar to new Image() for images
MIT License
729 stars 72 forks source link

Can we use this font to draw on canvas? #16

Closed quanghd closed 11 years ago

quanghd commented 11 years ago

I tried this code to draw on canvas but no result:

var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.font="30px "+font.fontFamily; ctx.fillText("Hello World", 10, 50);

Pomax commented 11 years ago

kind of missing the rest of the code that sets up the font object here. Also, did you do some debugging yourself to see what was in "font" on that third line? Does it have a fontFamily assigned? does the console show an error or warning? Is the fon't your trying to load actually called what you use as construction string, etc?

quanghd commented 11 years ago

Ok, i've found the problem. The fontFamily = 'A.C.M.E. Secret Agent' and it's illegal name to set to ctx.font. It's works when I change the font family to 'SecretAgent'.

Thanks,

Pomax commented 11 years ago

ah, yes for family names with special characters, you need to extra-quote the family name. That gets weird, so it's always a good idea to use a font name without spaces or special characters when using the Font object.