Been looking around stackoverflow and google for ways to solve this issue im having but havent had much luck with a solution.
What is happening is my font-face font
Use this trick and bind an onerror
event to an Image
element.
Demo here: http://jsfiddle.net/g6LyK/ — works on the latest Chrome.
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'http://fonts.googleapis.com/css?family=Vast+Shadow';
document.getElementsByTagName('head')[0].appendChild(link);
// Trick from https://stackoverflow.com/questions/2635814/
var image = new Image;
image.src = link.href;
image.onerror = function() {
ctx.font = '50px "Vast Shadow"';
ctx.textBaseline = 'top';
ctx.fillText('Hello!', 20, 10);
};
According to an answer to this question, you might need to listen to the onreadystatechange event, checking if document.readystate === 'complete'.