I have the following css rule in my document
font-family: "Trebuchet MS", Tahoma;
but I found out that some browsers have Trebuchet MS font
without symbols I need (some language with non-latin characters).
And in this case browser shows squares instead of symbols.
How can I check it (probably via javascript)?
(i.e. how can I check if some symbols are missing in the
font installed in my visitor's browser)
Windows' Character Map (found in the Programs > Accessories > System Tools menu) shows all the characters in a font in the form of a scrollable grid. From here you can select and copy a character or group of characters into your document.
The easy way to know what is in a font's character set is by viewing the software's glyph panel. For any font, begin by selecting the Entire Font option. From there, view the submenus, investigating categories of glyphs you might be interested in. (These categories closely mirror those in the OpenType panel.)
Right-click your font and select Properties . Select the tab "CharSet/Unicode". If the Font Encoding Type is not Symbol and the Supported Unicode Ranges list anything besides or in addition to Basic Latin and Latin-1 Supplement, your font is a Unicode font or is compatible with Unicode.
On Windows you may be able to detect from JavaScript which characters are missing from a font by:
a) creating a designer detector font that contains a very wide notdef character of say 100pt wide. The detector font needs to be a proportional font, constructed similar to the Adobe notdef font AND-Regular.otf
. (this link may be relevant too?).
b) Use the detector font as the fallback font (here I am using adobe notdef
as the detector font) e.g.
<div style="font-family: sans-serif, Segoe UI symbol, adobe notdef">
�test□▯😘😅
😗😎😎🌊🌊😀
</div>
Now you can test a single unicode character by putting it into a div with display: inline-block
to force minimum width.
If the glyph is not in the list of fonts, then the notdef glyph from the last font will be used, which will be 100pt wide, which can be detected in javascript from the offsetWidth of the div.
I explored the idea enough to validate that it is very likely to work, but I didn't have enough time to actually make working code, sorry!
I would expect the technique to work on other operating systems too (unless browsers render the .notdef
character in another font!).
Alternatively, you could use a zero width font like Adobe blank which has a zero width .notdef
character 0 (the AdobeBlank.otf
file is only 20kb). This could detect missing glyphs, because the div containing a missing glyph will end up with an offsetWidth == 0. However I think it would be a less reliable technique than using a very wide glyph, because there are valid glyphs with zero width so it woudl get false positives for valid zero width glyphs (particularly U+200B
and maybe other control characters?).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With