Created
November 7, 2012 14:37
-
-
Save bramstein/4031971 to your computer and use it in GitHub Desktop.
Test for font fallback bug in Webkit
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
function detectWebkitFallbackBug() { | |
var el = document.createElement('div'), | |
style = document.createElement('style'), | |
width = 0, | |
hasBug = false; | |
style.innerHTML = "@font-face{font-family:'__test__';src:url(data:application/x-font-woff;base64,) format('woff'),url(data:font/truetype;base64,) format('truetype');}"; | |
el.style.cssText = 'position:absolute;font-family:monospace;font-size:20px;'; | |
el.innerHTML = 'iii'; | |
document.body.appendChild(el); | |
document.head.appendChild(style); | |
width = el.clientWidth; | |
el.style.fontFamily = "'__test__', monospace, sans-serif"; | |
hasBug = width !== el.clientWidth; | |
document.head.removeChild(style); | |
document.body.removeChild(el); | |
return hasBug; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment