How can I wait for the first drag of the canvas to load the font font-face?

I have HTML5-canvas and write text using context.fillText(...); using the font @ font-face.
Displaying a page using Firefox (3.6) I have a problem that the font is not yet loaded on the first paint of the canvas, so the text will be displayed with a standard font.
I found a โ€œsolutionโ€ here, but it doesnโ€™t work, because the font is used only in the canvas, and the canvas is loaded and displayed using ajax using jQuery.
Is there a better solution than trying to use the setTimeout(repaintCanvas, 500); timeout setTimeout(repaintCanvas, 500); ?

+4
source share
2 answers

I think I found a solution using Reigel's answer:

 $.get('font/url.ttf', function() { // do canvas codes.... cause font is loaded... }); 

Also, use the font through font-family: 'fontfacename'; for the parent canvas element.
Maybe the font loads twice, I donโ€™t know. But without a second load, it will not display correctly.

+4
source

well, you could try this,

 $.get('font/url.ttf',function(){ // do canvas codes.... cause font is loaded... }); 
+4
source

All Articles