I ran into this problem in the latest version of Chromium. After creating the first element using the font family embedded via @ font-face, I get the wrong offsetXyz values. By the time the script is executed, hook.conload will already be running, and the font will thus already be loaded.
Here is what the script looks like (schematically):
var e = document.createElement("span"); e["innerText" in e?"innerText":"textContent"] = "fooBar"; e.style.fontFamily = "fontFaceEmbeddedFontFamily"; document.body.appendChild(e); alert(e.offsetWidth); // Returns two different values setTimeout(function() { alert(e.offsetWidth); // The latter being correct }, 1000);
The value is updated silently. There seems to be no way to wait for it to fix the values, but just setInterval - check the value and then display the solution. I do not like to do such dirty things.
Anyone have suggestions on how to proceed? It happens only when src: local(" ... ") not specified, so the problem is downloaded as a font.
javascript css fonts css3 font-face
Witiko
source share