是否可以检测到浏览器何时使用后备字体而不是CSS中指定的主要字体? [英] Is it possible to detect when a browser is using a fallback font instead of the primary one specified in the CSS?

查看:74
本文介绍了是否可以检测到浏览器何时使用后备字体而不是CSS中指定的主要字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在文本字段中输入了字符,并且当前应用的字体不支持该字符,则该字符将使用备用字体。发生这种情况时,是否可以通过Java脚本或其他方法进行判断?尝试创建一个脚本来警告用户字体是否不支持某个字符。谢谢您的帮助!

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!

推荐答案

这听起来像是工作,例如 fontkit.js opentype.js ,甚至是 Font.js ,所有这些都可以测试字体字形支持。系统字体不会以这种方式覆盖(Font.js可能会起作用,它可能会报告测试的字形的宽度为0),但是这些通常是网络安全字体,我们已经确切知道支持哪些字形,因为每个人都使用相同的。但是,为了测试自定义字体中的孔,前面提到的三个孔中的任何一个都应该已经完成​​了您打算实现的操作。

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.

这篇关于是否可以检测到浏览器何时使用后备字体而不是CSS中指定的主要字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆