Skip to content

Instantly share code, notes, and snippets.

@bramstein
Created November 7, 2012 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bramstein/4031971 to your computer and use it in GitHub Desktop.
Save bramstein/4031971 to your computer and use it in GitHub Desktop.
Test for font fallback bug in Webkit
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