Re: [css-font-loading] load, check and testing for character coverage

On Sun, May 17, 2015 at 11:31 PM, Cameron McCormack <cam@mcc.id.au> wrote:
> John Daggett:
>> Tab Atkins wrote:
>>
>> > Whether check() should be answering "is a load needed?" or "is
>> > everything you might need to render available?" is the question at
>> > hand; you can't just assume it.
>
> Tab,
>
> I think it would be helpful if you could detail all the ways that you
> envisage check() being used, because it seems like the discussion here
> might be pre-supposing what it’s good for and it’s difficult to evaluate
> without knowing this.
>
> John’s argument below that “is everything you might need to render
> available” is not a question that check() can answer makes sense to me.
> In which case, getting to what the precise question that check()
> answers, and what you would then use that answer to do, should help the
> discussion along.

With some caveats, it *is* a question that can be answered, and it's
the more useful question to answer.

When you call check() with some font list, you're asking "if I start
to draw into a canvas with this font list, will I get what I expect?".
If you "expect" to get the first font on the list, save for character
fallbacks to lesser fonts in the list, then we can *almost* answer
completely right.  By default we have to just assume that you're only
going to use characters you already know are in the font; if you
specify a string of sample text, we can be indeed be completely
correct if you didn't lie in the unicode-range of one or more faces.
By checking whether every font in the list is either (a) a loaded
downloadable font, or (b) a known system font, and that at least one
font can handle every sample character, we can give a definitive
answer to this.

If it returns "true", you can go ahead and start rendering.  If it
returns "false", you need to .load() that string and wait for it to
finish.  The third case is that the search for matching font faces
returns nothing, indicating that some of your sample characters can't
be rendered by *any* of the fonts in the list.  This is an error
condition; either you misspelled your font names, or you're planning
on using some characters that nothing can render.  Either way, we
definitely shouldn't return "true" (using that font string won't
render like you expected), and probably shouldn't return "false"
either (.load() won't do anything).  This is why, near the end of the
f2f, I suggested throwing in this case instead.

I think throwing captures it correctly.  It lets you know when you've
misspelled something, or have inadequate unicode-ranges, so that you
can fix these problems.  Both "true" and "false" have the very real
possibility of silently swallowing errors.

~TJ

Received on Friday, 22 May 2015 22:33:10 UTC