W3C home > Mailing lists > Public > www-style@w3.org > May 2012

[css3-fonts][cssom] Load events for webfonts?

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Thu, 24 May 2012 17:26:45 -0700
Message-ID: <CAAWBYDASJ-_iaCiyskOQ_hNTVW6NsUFHic0j1ncdR9GuTeaK2Q@mail.gmail.com>
To: www-style list <www-style@w3.org>
I couldn't find anything about this from a cursory search of the list.

Has any thought been given to exposing when fonts in @font-face are
loaded?  (Where "loaded" means "one of the sources is either
successfully downloaded and parsed, or is successfully found on the
local system, or all the sources fail".)

Our Docs team needs to know this information so it can do accurate
measurements of things, which are based on the metrics of the font
being used.  If a fallback font is being used because the main one
hasn't loaded yet, we'll do an initial sizing sweep, then watch for
the load using silly indirect means so we can redo all the sizing when
it loads and we swap out the fonts.

Right now, our technique is to render two spans positioned off-screen,
one with the fallback font and one with the @font-face font, and poll
the sizes on a timer until the second is a different size than the
first.  This is, of course, very silly.  It's also not reliable - if
the fallback font happens to produce a span the same width as the
loaded font, you'll never notice the load.  This may or may not be
okay for the overall sizing (depends on how close the metrics actually
are, and thus how much of a coincidence the same-size thing was), but
it's definitely bad that it means we have a timer running forever (or
until we hit our own timeout).

Other fairly advanced apps probably have similar needs.  Providing a
load event we can listen to instead of polling would be much less
fragile, more reliable, and cheaper for the user.

Preferably, it would be fired at the @font-face rule in the CSSOM, so
you don't have to go to any particular effort to figure out which font
it was.  If you do something more general like firing it at document,
you have to provide all the descriptors so you can distinguish
separate rules.


Received on Friday, 25 May 2012 00:27:34 UTC

This archive was generated by hypermail 2.4.0 : Monday, 23 January 2023 02:14:15 UTC