http://www.lalit.org/lab/javascript-css-font-detect
How does it work?
This code works on the simple principle that each character appears differently in different fonts. So different fonts will take different width and height for the same string of characters of same font-size.
We try to create a string with a specified font-face. If the font-face is not available, it takes up the font-face of the parent element. We then compare the width of the string with the specified font-face and width of the string with the font-face of the parent element,
if they are different, then the font exists,
otherwise not.
The string which we will use to generate the widths can be anything. But I guess we use ‘m’ or ‘w’ because these two characters take up the maximum width. And we use a trailing ‘l’ so that the same width fonts-faces can get separated based on the width of l character.
Javascript:
HTML:
This table below shows which fonts are present on envykok's system. (I have listed some of the most common and some uncommon fonts.)
Johan Sundström has presented this data in a more interesting and cool layout here. Thanks Johan!
Font Name | Width | Height | Detected? |
---|---|---|---|
cursive | 558 | 74 | true |
monospace | 473 | 77 | true |
serif | 631 | 72 | true |
sans-serif | 606 | 81 | true |
fantasy | 383 | 82 | true |
default | 631 | 72 | false |
Arial | 606 | 81 | true |
Arial Black | 744 | 101 | true |
Arial Narrow | 503 | 83 | true |
Arial Rounded MT Bold | 631 | 72 | false |
Bookman Old Style | 702 | 84 | true |
Bradley Hand ITC | 642 | 90 | true |
Century | 663 | 87 | true |
Century Gothic | 685 | 87 | true |
Comic Sans MS | 580 | 101 | true |
Courier | 440 | 65 | true |
Courier New | 473 | 77 | true |
Georgia | 651 | 82 | true |
Gentium | 631 | 72 | false |
Impact | 580 | 87 | true |
King | 631 | 72 | false |
Lucida Console | 473 | 72 | true |
Lalit | 631 | 72 | false |
Modena | 631 | 72 | false |
Monotype Corsiva | 467 | 85 | true |
Papyrus | 464 | 114 | true |
Tahoma | 616 | 87 | true |
TeX | 631 | 72 | false |
Times | 570 | 81 | true |
Times New Roman | 570 | 81 | true |
Trebuchet MS | 621 | 90 | true |
Verdana | 721 | 86 | true |
Verona | 631 | 72 | false |