Last active
December 28, 2015 07:09
-
-
Save WebReflection/7461879 to your computer and use it in GitHub Desktop.
well, a weird trick to know if a font is usable inside canvas too
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*! (C) Andrea Giammarchi */ | |
| // @link https://gist.github.com/WebReflection/7461879 | |
| // @example | |
| // isFontLoaded('FontAwesome', '\uf06b') | |
| var isFontLoaded = function(canvas1, canvas2) { | |
| function reset(canvas, fontName) { | |
| var context = canvas.getContext('2d'); | |
| canvas.width = canvas.height = 16; | |
| context.clearRect(0, 0, 16, 16); | |
| context.fillStyle = "rgb(0,0,0)"; | |
| context.font = "16px '" + fontName + "'"; | |
| context.fillText('\uf06b', 0, 16); | |
| return canvas.toDataURL(); | |
| } | |
| return function (fontName, specialChar) { | |
| return reset(canvas1, 'default', specialChar) !== | |
| reset(canvas2, fontName, specialChar); | |
| }; | |
| }( | |
| document.createElement('canvas'), | |
| document.createElement('canvas') | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment