w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.49k stars 662 forks source link

[css-font-loading] [info discovery] List of available glyphs #6798

Open jespertheend opened 2 years ago

jespertheend commented 2 years ago

Not sure if I'm missing something obvious here, but I'd like to render user generated content in a specific font. And once it contains a missing glyph just swap the entire element with a different font, rather than just those missing glyphs.

The unicodeRange property is arbitrarily large (U+0-10FFFF), even though my font only contains a-z0-1 with a few extra characters.

tabatkins commented 2 years ago

Wrt info discovery, there's not a lot we can do if you're not setting up the unicode-range properly. Allowing that to work would encourage writing pages that trigger multiple useless font downloads before we finally discover one that works, which is a bad user experience.

But if you do write unicode-range to cover the actual characters of the font, then the FontFaceSet.check() method somewhat works. It's not designed for this use-case, but you can finagle it, by creating a dummy font that's not loaded with a default (full-coverage) unicode-range, and putting its name last in the .check() list, so if it falls back to that font due to bad character coverage, the method will return false.

jespertheend commented 2 years ago

The main reason why I'd want this functionality is so that I don't have to keep a list of available characters in sync with the actual characters (in case we add more characters later). Which I'd still have to do with a unicode-range. We only have a single font and would use system fonts in the case of special characters for only a small portion of the site, so no useless font downloads in our case.

But really this functionality would only fix a minor annoyance. I'm not sure this could warrant the bad user experience you'd get from encouraging multiple font downloads.