public
Last active

  • Download Gist
testFont.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
function testFont(name) {
name = name.replace(/['"<>]/g,'');
 
var body = document.body,
test = document.createElement('div'),
ab = test.getElementsByTagName('b'),
installed = false,
template =
'<b style="width: auto !important; font:normal 10px/1 \'X\',sans-serif !important">ii</b>'+
'<b style="width: auto !important; font:normal 10px/1 \'X\',monospace !important">ii</b>';
 
if (name) {
test.innerHTML = template.replace(/X/g, name);
 
test.style.cssText = 'position: absolute; visibility: hidden; display: block !important';
 
body.insertBefore(test, body.firstChild);
 
installed = ab[0].offsetWidth === ab[1].offsetWidth;
 
body.removeChild(test);
}
 
return installed;
}

Strange, I seem to be getting off by 1px errors testing for HelveticaNeue-CondensedBold on iOS 5, but it works fine on Chrome on OSX.

I increased the font size to 1000px and the sizes are still off by 1px. I changed the character from ii to ww and then the test works fine. Just a heads up, not sure what's going on.

Meaning the font is installed, but is reporting that it isn't because the two <b>s are reporting different dims?

That's right, that's what seems to be happening, just on iOS 5.

EDIT: I'll see if I can make a reduced test case. It might possibly be something I'm doing in my CSS that messes it up.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.