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

Based on the discussion in this thread, and previous discussions linked by
John, the two things that are necessary are some type of load event for
font-face, and then some way to explicitly trigger font-face loading (as
they're normally triggered only on demand, when text is encountered that
you need to use the font on).

Based on that, here's my proposal for the event:

# IDL #

[Constructor(FontFaceDescriptors descriptors)]
interface FontFaceLoadEvent : 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;

dictionary FontFaceDescriptors {
  DOMString family;
  DOMString src;
  DOMString style;
  DOMString weight;
  DOMString stretch;
  DOMString unicodeRange;
  DOMString variant;
  DOMString featureSettings;

# Attributes #

For each attribute, if the corresponding descriptor is present in the
associated @font-face rule, the attribute's value is the cssText of that
descriptor.  Otherwise, the attribute's value is the value undefined.

# Behavior #

This event is fired at the document object whenever the src specified in an
@font-face rule is finished loading.
Bubbles: ?
Cancelable: ?

* Do we want info about which src was loaded?
* Should this event fire when none of the srces successfully load as well,
to indicate failure?
* I don't know whether it makes sense for it to bubble or cancel.

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.

Comments? Concerns?  Suggestions for something better?  I'd like to move
this over into a spec somewhere so we can implement it.


Received on Tuesday, 24 July 2012 18:52:40 UTC