OS X / C 已安装字体列表
我正在尝试以编程方式获取 C 或 Python 中已安装字体的列表。 我需要能够在 OS X 上执行此操作,有人知道怎么做吗?
I'm trying to programatically get a list of installed fonts in C or Python. I need to be able to do this on OS X, does anyone know how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
安装了 PyObjC 的 Python(Mac OS X 10.5+ 就是这种情况,因此此代码无需安装任何东西即可运行):(
基于 htw 的答案)
Python with PyObjC installed (which is the case for Mac OS X 10.5+, so this code will work without having to install anything):
(based on htw's answer)
为什么不使用终端?
系统字体:
用户字体:
Mac OS X 默认字体:
如果您需要在 C 程序中运行它:
Why not use the Terminal?
System Fonts:
User Fonts:
Mac OS X Default fonts:
If you need to run it inside your C program:
不完全是 C,但在 Objective-C 中,您可以通过 Cocoa 框架轻松获取已安装字体的列表:
您可以通过 PyObjC,如果你愿意的话。
在 C 中,我认为你可以使用 ATSUI 库在 Carbon 中做类似的事情,尽管我不完全确定如何做到这一点,因为我以前没有在 Carbon 中使用过字体。 尽管如此,通过浏览 ATSUI 文档,我建议查看
ATSUGetFontIDs
和ATSUGetIndFontName
函数。 以下是 ATSUI 文档的链接,了解更多信息。Not exactly C, but in Objective-C, you can easily get a list of installed fonts via the Cocoa framework:
You can access the Cocoa framework from Python via PyObjC, if you want.
In C, I think you can do something similar in Carbon with the ATSUI library, although I'm not entirely sure how to do this, since I haven't worked with fonts in Carbon before. Nevertheless, from browsing the ATSUI docs, I'd recommend looking into the
ATSUGetFontIDs
and theATSUGetIndFontName
functions. Here's a link to the ATSUI documentation for more information.您想要编写一个程序来完成它,还是想要使用一个程序来完成它? 有很多列出字体的程序,我想到的是 xlsfonts。
Do you want to write a program to do it, or do you want to use a program to do it? There are many programs that list fonts, xlsfonts comes to mind.
您可以使用 Objective-C 和 Cocoa 获取一系列可用字体。 您正在寻找的方法是
NSFontManager
的可用字体
。我不相信有一个标准方法来确定系统字体使用纯 C 语言。但是,您可以自由地混合 C 和 Objective-C,所以使用这种方法来做您想做的事情确实不应该太难想要。
You can get an array of available fonts using Objective-C and Cocoa. The method you are looking for is
NSFontManager
'savailableFonts
.I don't believe there is a standard way to determine what the system fonts are using pure C. However, you can freely mix C and Objective-C, so it really shouldn't be to hard to use this method to do what you'd like.