Re: [css-fonts] Proposal for standardizing font timeout behavior

On Thu, Oct 30, 2014 at 3:03 PM, Ilya Grigorik <igrigorik@gmail.com> wrote:
> On Thu, Oct 30, 2014 at 1:43 AM, John Daggett <jdaggett@mozilla.com> wrote:
>> behavior on elements is fraught with problems. Consider the example
>> of a large document (think HTML5 spec) that uses a downloadable font
>> for headings:
>>
>>   @font-face { font-family: myfont; src: url(myfont.woff); }
>>
>>   h4 { font-family: myfont, fallback-serif; font-rendering: swap 3s; }
>>
>> The user agent starts the font load and lays out the first section
>> of the document. Headings appear in the fallback font. Because it's
>> a large document the font load takes more than 3 seconds, so
>> headings in the first section remain in the fallback font. But as
>> later sections are laid out, the font *is* available so in those
>> sections headings appear in the downloadable font.  But scroll back
>> up and the headings remain in the fallback font.
>
>
> This seems like an implementation issue. Personally, I'd expect the previous
> headings to be re-rendered with the desired font.

Whoops, I misread this example earlier; I thought it was an "optional" value.

This is *not* an implementation issue; this will be specified by the
spec.  The "swap" value defines that if the load completes before the
timeout, you swap; this applies to *all* of the headings.  It also
says that if the load completes *after* the timeout, you leave it at
the fallback; this *also* applies to *all* of the headings.

In other words, when a "swap" or "optional" font doesn't come in
before the timeout, it gets an "inactive" bool set on it, which makes
the current page treat it as not usable.  Anything else results in
inconsistent rendering in a long document.

(This bit of extra state should be exposed on the FontFace object, so
you can always turn the font on manually if you want, via script.)

>> CSS properties have an initial value which is the same across
>> browsers. The descriptors of the @font-face value have default
>> values which are the same across browsers. So you need to define an
>> initial value of the 'font-rendering' property and a default value
>> for the 'font-rendering' descriptor within @font-face rules. In
>> fact, to implement what you've described you need slightly different
>> values for the property, since I think you want the default value
>> for the descriptor to be "whatever the user agent timeout policy is"
>> and for the *property* you want an initial value of 'auto' to mean
>> "decide based on the 'font-rendering' descriptor value of the font".
>
> Gotcha, thanks for the context. However, as Brad mentioned.. couldn't this
> be set via UA stylesheet?

No, because (a) this is a descriptor on @font-face objects, not a
property on elements, so it's actually impossible to put this in the
UA stylesheet (no cascade to work with), and (b) it appears that UA
default behavior is slightly more complex than can be expressed via
the descriptor.  I think it's fine to UAs to have a richer set of
behaviors by default; we don't have to expose *everything* to authors
here, and they can do arbitrarily complex stuff with Font Loading if
they really want to.

~TJ

Received on Thursday, 30 October 2014 22:45:51 UTC