Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to detect when a browser is using a fallback font instead of the primary one specified in the CSS?

If a character is entered in a text field and the currently applied font does not support that character, a backup font is used for that character. Is it possible to tell via Javascript or some other means when this is happening? Trying to create a script which alerts the user if a certain character is not supported by the font. Thanks for your help!

like image 224
Hendeca Avatar asked Feb 24 '16 18:02

Hendeca


People also ask

Why do we use fallback fonts in CSS?

Commonly Used Fallback Fonts There are no 100% completely web safe fonts. There is always a chance that a font is not found or is not installed properly. Therefore, it is very important to always use fallback fonts.


1 Answers

This sounds like a job for something like fontkit.js or opentype.js, or even Font.js, all of which can test fonts for glyph support. System fonts are not covered this way (Font.js might work, it'll probably report a width 0 for the tested glyph) but then these are typically the "web safe" fonts, of which we already know exactly which glyphs are supported because everyone uses the same ones. For testing "holes" in a custom font, though, any of the previously mentioned three should already do what you intended to implement.

like image 64
Mike 'Pomax' Kamermans Avatar answered Sep 28 '22 06:09

Mike 'Pomax' Kamermans