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

Tab Atkins wrote:

> Modified proposal based on advice on how to spec events properly:
> 
> [Constructor(DOMString type, optional FontFaceEventInit eventInitDict)]
> interface FontFaceEvent : Event {
>   readonly attribute DOMString? family;
>   readonly attribute DOMString? src;
>   readonly attribute DOMString? style;
>   readonly attribute DOMString? weight;
>   readonly attribute DOMString? stretch;
>   readonly attribute DOMString? unicodeRange;
>   readonly attribute DOMString? variant;
>   readonly attribute DOMString? featureSettings;
> };

Just to be clear, the mechanics of this are that for every font loaded
an event would fire containing the descriptor set for the @font-face
rule that loaded?  Does it fire for both the src url() case and the
src local() case?

I think you need to define some way to determine whether other font
loads are still pending, since a given page may require multiple fonts
due either to style selection or character handling.  Given the lazy
loading nature of downloadable fonts, just defining a simple load event
is insufficient.

With a "loads pending" attribute somewhere, the typical font handling
logic would be:

1. Make changes that might cause a font load

2. Check to see whether font loads are pending

3. If necessary, wait for font loads to complete

4. Do stuff that requires the fonts to be loaded

What's the error handling model here?  I think you need to define more
details about what happens when a font load fails.

> For the explicit font loading case, I've got two complementary
> proposals. Either will satisfy the use-cases outlined in this thread
> in slightly different ways, but they're both potentially useful,
> even together. 
>
> For one, make CSSFontFaceRule constructable, taking a single
> FontFaceDescriptors argument. Constructing it immediately kicks off
> the load (or does it async, whatever the traditional behavior is),
> and a FontFaceLoaded event fires as normal when the load finishes.
> 
> For two, add a method to CSSStyleSheet called loadAllFonts. It takes
> no arguments. Calling it immediately (or async or whatever, same
> deal) kicks off loads of any @font-faces that haven't yet started a
> load. It returns a boolean - true if the call caused some fonts to
> load, false if all fonts were already loaded and the call did
> nothing. Possibly, we can add load() to CSSFontFaceRule as well,
> which forces the load of just that rule. 

Neither one of these sound like great ideas to me, it pushes all the
style selection logic into script.  Better to have a method that loads
the font for a given family/weight/style/stretch combination. Possible
variations would be to also pass in the text in use and a separate
version version that loads all fonts for a *family*.

Loading all fonts in a stylesheet sounds like a bad idea, authors
could easily shoot themselves in the foot with this one.

Regards,

John Daggett

Received on Wednesday, 22 August 2012 04:43:48 UTC