有没有办法通过网络检查计算机上安装了哪些字体?
有没有办法测试安装了哪些字体或者我可以读出所有字体? 我想在我们的产品中进行一项调查,看看我可以在我们的项目中使用哪些字体。
Is there a way to test what fonts are installed or maybe a way I can read out all of them? I want to do a survey in our product to see what fonts I can use on our projects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
有一个脚本可以用不同的字体呈现一堆 DIV,然后检查生成的 DIV 是否具有给定字体的正确尺寸。
http://www.lalit.org/lab/javascript-css-font-detect
There is a script that renders a bunch of DIVs in different fonts, then checks to see if the resulting DIV has the right dimensions for the given font.
http://www.lalit.org/lab/javascript-css-font-detect
只要 Flash 可用,就有可能。 请参阅 http://www. maratz.com/blog/archives/2006/08/18/detect-visitors-fonts-with-flash/
It is possible, so long as Flash is available. See http://www.maratz.com/blog/archives/2006/08/18/detect-visitors-fonts-with-flash/
从这个 问题。
Checkout the jQuery plug-in FontUnstack, from this question.
这是Windows 和 Mac 机器上最常见的字体列表(带有图像各有比较)。 我在选择项目中使用的字体时使用它。
Here's a list of the most common fonts on windows and mac machines (with image comparisons of each one). I use it when selecting which fonts to use on a project.
没有万无一失的方法可以通过浏览器确定客户端计算机上已安装(和可用)的字体。
Flash 可能允许您这样做,或者可能允许一些疯狂的(但写起来很有趣)JavaScript 对具有给定字体的元素的大小进行假设 - 但该脚本可能容易受到客户端设置差异的影响,无论它考虑多少种情况。
我强烈建议不要使用您提议的调查/部署方法。 您将做出一些不可能的决定 - 例如,多少百分比的可用性是可以接受的? 如果是 100%,那么当新用户出现没有这种字体时你会怎么做? 如果不是,那么您对体验下降感到满意的用户比例是多少?
您是否考虑过 sIFR 或者只是具有适当 alt 属性的图像元素?
如果您有特定的排版要求,可能值得关注:http://blog.typekit.com/ 。
There is no foolproof way of determining installed (and usable) fonts on a client machine through the browser.
Flash may allow you to do this, or possibly some crazy (but fun to write) JavaScript that makes assumptions about the size of elements with a given font - but this script may be susceptible to differences in client settings no matter how many cases it considers.
I would strongly recommend against the survey / deployment approach that you are proposing. You will have some impossible decisions to make - for example what percentage availability is acceptable? If it's 100%, what do you do when a new user comes along that doesn't have this font? If it's not, what proportion of your users are you comfortable with having a degraded experience?
Have you considered sIFR or simply an image element with appropriate alt attribute?
If you have specific typographic requirements, it may be worth keeping an eye on this: http://blog.typekit.com/.
您可以使用 Flash 获取客户端操作系统中安装的字体列表:
然后您可以使用 ExternalInterface 在 Flash 和 Javascript 之间移动此信息。 它不需要太多代码。
查看我的有关它的博客文章了解更多信息和演示实现。
You can get a list of fonts installed in the client OS with Flash:
You can then use the ExternalInterface to move this information between Flash and Javascript. It doesn't require much code.
Check out my blog post about it for more info and a demo implementation.
没有好的方法可以做到这一点。 不过,如果您有一个您想知道的字体列表,请创建一个具有始终存在的后备的类:
...
然后编写一个脚本来比较已知字体跨度和其他字体的宽度。 如果宽度不同,则该字体存在于客户端上。
There is no good way of doing this. Though if you have a list of fonts you're wondering about, create a class with a always-present fallback:
...
Then write a script that compares the width of the known font-span and each of the others. If the width differs, the font exists on the client.
我知道并非所有浏览器都支持它,但是 css 中有 @font-face,如所述 here,因此,如果您知道您的用户使用的是 IE(例如),您可以使用它来获取字体。
I know it's not supported by all browsers yet, but there's @font-face in css as described here, so if you know that your users are on IE (for example) you could use this to get the font.