I am trying to measure the width of a specific character from a webfont. The active event provided by Google's Webfont Loader fires slightly too early and the measurement it made on the default font.
A stripped down version of the script that I am working with:
window.WebFontConfig = {
google: {
families: ['Anonymous Pro:400,400italic,700,700italic']
},
active: function () {
$.fn.ready(MeasureM);
}
};
function MeasureM() {
var e = document.getElementById('div');
e.style.font = "15px/15px 'Anonymous Pro'";
e.appendChild(document.createTextNode('M'));
console.log(e.offsetWidth, e.offsetHeight);
}
(function () {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
The HTML element:
<div id="div" style="display: table;"></div>
For convenience a jsFiddle.
The issue that I am having appear to only happen in Firefox, is there a solution? Or, is there something that I am misunderstanding?