Page MenuHomePhabricator

Collect font support metrics
Open, Needs TriagePublic

Description

Discussions such as T73240 could benefit from data on how widely specific fonts are supported and what kind of font substitution and glyph fallback is happening. Unfortunately, browsers don't expose that kind of information (developer toolbars can tell the font name, and Chrome shows some glyph fallback data, but not much, and all those are unavailable to scripts). Flash provides font data, but comes with problems of its own. Here are some ideas on how to detect font support:

  • you can determine whether a (non-monospace) font is supported by relying on the fact that the characters have different widths. So, we can programmatically create a div with font-family: FontUnderTest, monospace and then fill it with aaaaaaaaaa, bbbbbbbbbb etc and check its width. If it is changes, the font is supported. (It seems like a safe assumptions that on almost every machine monospace will resolve to a monospace font.) Monospace fonts can be tested with a non-monospace fallback.
  • support for a font does not necessarily mean it's actually being used (the OS can pretend to support the font but actually use something else, via things like fontconfig). For non-monospace fonts we can create a "font fingerprint" by measuring the width of aaaaaaaaaa etc. and creating a codepoint/width dataset. This will be specific to OS+browser, and depend on certain configuration settings, due to differences in default sizes, kerning and whatnot. But even so they might be specific enough to identify the fonts. At the very least, they can be used to tell whether two font specifications resolve to the same font.
  • glyph fallback could be tested by using @font-face and unicode-range and checking whether explicitly filtering out a codepoint changes its dimensions. (That assumes that glyph fallback works the same when the glyph is missing and it is outside the range specified for the font. I am not sure if that is the case, but it seems reasonable.)
  • more crazy stuff could be done with a canvas, although it might not be worth the effort.

See also: T108884: Collect font preference metrics

Event Timeline

Tgr raised the priority of this task from to Needs Triage.
Tgr updated the task description. (Show Details)
Tgr added a project: Analytics.
Tgr added a subscriber: Tgr.

Wikipedia:Typography links to some archived font surveys that break down the installed fonts for each of the three popular platforms (Windows, Mac, Linux). Some will regard those as outdated, but it provides a good base non the less.

Existing examples of doing font detection this way are flipping typical and fontdetect.js (the latter with an Apache license).