views:

94

answers:

2

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);?

+1  A: 

well, you could try this,

$.get('font/url.ttf',function(){
   // do canvas codes.... cause font is loaded...
});
Reigel
Thanx, but won't work. The font-file will be loaded but I think the browser does not recognoze that it's also the file for the @font-face.
alopix
A: 

I think I found a solution with the help of Reigel's answer:

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

Additionally use the font via font-family: 'fontfacename'; for the canvas' parent-element.
Could be that the font is loaded twice, don't know. But without the second load it won't be displayed right.

alopix