Use case
Given a range of text in the DOM, what font(s) is being applied to that range?
- “Designer wants wider letter-spacing if Futura (1st font in stack) is displayed than if Century Gothic (2nd font) is displayed.” [1]
- To save requests/bandwidth, determine if a font is available on the user’s system before loading it.
Existing solutions
There are no exact solutions to this use case in the platform. Right now, developers are using either a canvas hack [2] or javascript hack [3].
See also:
- http://www.lalit.org/lab/javascript-css-font-detect/
- https://remysharp.com/2008/07/08/how-to-detect-if-a-font-is-installed-only-using-javascript
- https://www.browserleaks.com/fonts
Limitations
window.getComputedStyle(element)
Get computed style only returns you the font stack, so you can’t actually determine which font is being applied to an element (or a range of characters).
Security and privacy considerations
Fingerprinting:
Refs and acknowledgements
This proposal comes originally from Dave Newton.