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

Re: [css3-fonts] rethinking font load events

From: Sebastian Zartner <sebastianzartner@gmail.com>
Date: Fri, 7 Sep 2012 10:11:30 +0200
Message-ID: <CAERejNYOWMydMpqXHdC1ABB=-Kg0ziTpWsHd7CTr4Q_jS6UpQQ@mail.gmail.com>
To: "Tab Atkins Jr." <jackalmage@gmail.com>
Cc: Glenn Adams <glenn@skynav.com>, John Daggett <jdaggett@mozilla.com>, www-style list <www-style@w3.org>
> You do some work in function A.  A may or may not incidentally kick
> off some font loads (for example, it might insert some DOM nodes that
> get a 'font' property applied for a new font that hasn't been loaded
> yet).  You'd like to execute an additional function B, but if there
> are pending font loads, delay B until after they're finished (for
> example, B might do some measurements which will be affected by font
> metrics).
> Normally, you'd have to do this by adding some code to the end of A
> that (1) does a style flush (an ill-defined operation) so that any
> font loads that would be triggered by A's work are definitely started,
> (2) check FontLoader.readyState, (2a) if it's "idle", assume your work
> didn't trigger any font loads and call B immediately, (2b) if it's
> "loading", set up a listener for allcomplete that runs B.
> notifyAfterCompletion() lets you avoid some of these steps.  At the
> end of A, all you have to do is set up a listener for "allcomplete"
> that runs B, then call notifyAfterCompletion().

Sorry, but I still didn't understand the need for notifyAfterCompletion().
As you say "allcomplete" will always be fired when all fonts are
loaded, which the page currently needs. So if B is doing some
measurements being affected by font metrics, all you have to do is to
set up a listener for "allcomplete" and call B in it. If A then
triggers new fonts to be loaded, "allcomplete" will be fired as soon
as they are, which calls B. If A didn't trigger any new fonts to be
loaded, B won't be executed again.

Maybe the misunderstanding lies in when "allcomplete" is actually
triggered. So I assume you wouldn't trigger it if there are just
client fonts used in the page, i.e. B would not be executed at all.
I interpreted the event to mean "all fonts are loaded and displayed",
independent of having web fonts in the page or not. So the event would
always at least be fired once.

Received on Friday, 7 September 2012 08:11:58 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:21 UTC