Delay Execution Of Javascript For Canvas Until Fonts Have Been Loaded
Solution 1:
Use Google's WebFontLoader script
https://github.com/typekit/webfontloader
WebFontLoader's fontactive
callback is the equivalent of the img element's onload
.
WebFontLoader is exactly on point and WebFontLoader is maintained by Adobe itself (TypeKit ! )--so it's very unlikely that this CDN-link will vanish.
While I recommend WebFontLoader, you can hack together a font.onload
yourself by detecting when the width of your element changes (changed width == the font has loaded).
Adobe has created the Adobe Blank
font for the purpose of testing when a font has loaded. AdobeBlank starts out with zero width. Here's how to use AdobeBlank as font.onload
as outlined by Dr. Ken Lunde in this useful TypeKit blog post: http://blog.typekit.com/2013/03/28/introducing-adobe-blank/
Include Adobe Blank as a data URI in the CSS file.
Specify ‘font-family: SomeWebFont, “Adobe Blank” in the CSS rule for some DOM element that contains text (and would therefore have a non-zero width when rendered using a regular font). One example would be a element that is absolutely positioned offscreen.
Check the width of the DOM element. If it’s zero, SomeWebFont hasn’t loaded yet. If it’s greater than zero, it has.
Good luck with your project!
Post a Comment for "Delay Execution Of Javascript For Canvas Until Fonts Have Been Loaded"