Closed jyasskin closed 3 years ago
Mostly agreed... the challenge is that if we have a permission scheme and/or UX allowing full access, and were on an operating system where enumeration was inherently async, and the enumeration order was not aligned, this would require the implementation to do a full enumeration and buffer the results, do a sort, then provide the enumeration to script.
Yep, sorting might remove the benefit of having FontIterator
be async iterable, unless getting the synchronous font names in FontMetadata requires parsing.
This is also mentioned in https://github.com/w3ctag/design-reviews/issues/399#issuecomment-530679815 (4th paragraph).
Would like to talk a bit about sorting. While it does remove some of the benefits of FontIterator
being async iterable, it exists a future where fonts can be async iterable and sorted, e.g. if system font enumeration data lives in an out-of-process cache and sortable.
As for which key to sort it with, I propose postscriptName
. It is used on the web as a unique identifier for @font-face src: local
matching.
Annecdotally, Apple systems deduplicate using that name table entry. https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html
Platform-specific Information
It is no longer recommended that fonts for use on macOS have PostScript names with the Macintosh platform ID and MacRoman platform-specific ID.
If two fonts are installed with the same PostScript name, Apple platforms treat them as duplicates and only one will be available for use.
Another convenient property of postscriptName
is that according to the OpenType name specs, it is encoded in a subset of ASCII.
PostScript name for the font; Name ID 6 specifies a string which is used to invoke a PostScript language font that corresponds to this OpenType font. When translated to ASCII, the name string must be no longer than 63 characters and restricted to the printable ASCII subset, codes 33 to 126, except for the 10 characters '[', ']', '(', ')', '{', '}', '<', '>', '/', '%'.
This makes using this field as the sorting key ideal, as it will be the same across all locales.
This property combined with the fact that postscriptName
can be used as a unique identifier, makes it an ideal candidate.
This is made explicit in the https://wicg.github.io/local-font-access/#dom-fontmanager-query algorithm now.
https://wicg.github.io/local-font-access/#fontiterator says "For each local font font on the system", but if that reflects the order fonts were installed, it reveals a lot of fingerprinting information. The spec should say that the fonts are sorted by some key.