测试是否安装了字体
有没有一种简单的方法(在.Net中)来测试当前计算机上是否安装了字体?
Is there an easy way (in .Net) to test if a Font is installed on the current machine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有没有一种简单的方法(在.Net中)来测试当前计算机上是否安装了字体?
Is there an easy way (in .Net) to test if a Font is installed on the current machine?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(7)
离开 GvS 的答案:
Going off of GvS' answer:
就我而言,我需要检查扩展名
ex 的字体文件名:verdana.ttf = Verdana Regular,verdanai.ttf = Verdana Italic
In my case I need to check font filename with extension
ex: verdana.ttf = Verdana Regular, verdanai.ttf = Verdana Italic
我将这样做:
需要注意的一件事是
Name
属性并不总是您在 C:\WINDOWS\Fonts 中查找的内容。 例如,我安装了一种名为“Arabic Typsetting Regular”的字体。IsFontInstalled("Arabic Typesetting Regular")
将返回 false,但IsFontInstalled("Arabic Typesetting")
将返回 true。 (“Arabic Typesetting”是 Windows 字体预览工具中字体的名称。)就资源而言,我运行了一个测试,多次调用此方法,每次测试只用几毫秒就完成了。 我的机器有点强大,但除非您需要非常频繁地运行此查询,否则性能似乎非常好(即使您这样做,这就是缓存的用途)。
Here's how I would do it:
One thing to note with this is that the
Name
property is not always what you would expect from looking in C:\WINDOWS\Fonts. For example, I have a font installed called "Arabic Typsetting Regular".IsFontInstalled("Arabic Typesetting Regular")
will return false, butIsFontInstalled("Arabic Typesetting")
will return true. ("Arabic Typesetting" is the name of the font in Windows' font preview tool.)As far as resources go, I ran a test where I called this method several times, and the test finished in only a few milliseconds every time. My machine's a bit overpowered, but unless you'd need to run this query very frequently it seems the performance is very good (and even if you did, that's what caching is for).
使用
Font
创建提出的其他答案仅在FontStyle.Regular
可用时才有效。 某些字体(例如 Verlag Bold)没有常规样式。 创建将失败,并出现异常字体“Verlag Bold”不支持样式“Regular”。 您需要检查您的应用程序需要的样式。 解决方案如下:Other answers proposed using
Font
creation only work if theFontStyle.Regular
is available. Some fonts, for example Verlag Bold, do not have a regular style. Creation would fail with exception Font 'Verlag Bold' does not support style 'Regular'. You'll need to check for styles that your application will require. A solution follows:如何获取所有内容的列表安装的字体?
请参阅InstalledFontCollection 类 详细信息。
MSDN:
枚举已安装的字体
How do you get a list of all the installed fonts?
See InstalledFontCollection class for details.
MSDN:
Enumerating Installed Fonts
感谢 Jeff,我更好地阅读了 Font 类的文档:
这些知识的结果:
Thanks to Jeff, I have better read the documentation of the Font class:
The result of this knowledge: