JavaScript/CSS Font Detector

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.

Widths of same text in different fonts

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 NameWidthHeightDetected?
cursive55874true
monospace47377true
serif63172true
sans-serif60681true
fantasy38382true
default63172false
Arial60681true
Arial Black744101true
Arial Narrow50383true
Arial Rounded MT Bold63172false
Bookman Old Style70284true
Bradley Hand ITC64290true
Century66387true
Century Gothic68587true
Comic Sans MS580101true
Courier44065true
Courier New47377true
Georgia65182true
Gentium63172false
Impact58087true
King63172false
Lucida Console47372true
Lalit63172false
Modena63172false
Monotype Corsiva46785true
Papyrus464114true
Tahoma61687true
TeX63172false
Times57081true
Times New Roman57081true
Trebuchet MS62190true
Verdana72186true
Verona63172false

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值