Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I wait for first canvas-repaint until @font-face-font is loaded?

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

like image 555
dst Avatar asked Feb 27 '23 13:02

dst


1 Answers

well, you could try this,

$.get('font/url.ttf',function(){
   // do canvas codes.... cause font is loaded...
});
like image 192
Reigel Avatar answered Mar 22 '23 22:03

Reigel