如何从 Mac 上的显示名称找到字体的完整路径?
我正在使用 Photoshop 的 javascript API 来查找给定 PSD 中的字体。
给定 API 返回的字体名称,我想找到该字体名称在光盘上对应的实际物理字体文件。
这一切都发生在 OSX 上运行的 python 程序中,所以我想我正在寻找以下之一:
- 一些 Photoshop javascript
- 一个 Python 函数
- 一个我可以从 python 调用的 OSX API
I am using the Photoshop's javascript API to find the fonts in a given PSD.
Given a font name returned by the API, I want to find the actual physical font file that font name corresponds to on the disc.
This is all happening in a python program running on OSX so I guess I'm looking for one of:
- Some Photoshop javascript
- A Python function
- An OSX API that I can call from python
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我遇到了类似的要求,最终采用了这种方法:
请注意,原始代码来自 PIL
I had encountered similar requirements and I ended up by this method:
Note that the original code is from PIL
打开一个终端(应用程序->实用程序->终端)并输入以下内容:
这将吐出具有您想要的名称的每个文件。
警告:可能有很多事情需要费力。
open up a terminal (Applications->Utilities->Terminal) and type this in:
This will spit out every file that has the name you want.
Warning: there may be alot to wade through.
我还没有找到任何可以直接执行此操作的东西。 我认为您必须遍历系统上的各种字体文件夹:
/System/Library/Fonts
、/Library/Fonts
,并且可能有一个用户-级目录以及~/Library/Fonts
。I haven't been able to find anything that does this directly. I think you'll have to iterate through the various font folders on the system:
/System/Library/Fonts
,/Library/Fonts
, and there can probably be a user-level directory as well~/Library/Fonts
.Cocoa 中必须有一个方法来获取字体列表,然后您必须使用 PyObjC 绑定来调用它。
根据您需要它们的用途,您可能只使用类似以下的内容。
There must be a method in Cocoa to get a list of fonts, then you would have to use the PyObjC bindings to call it..
Depending on what you need them for, you could probably just use something like the following..
使用
matplotlib
(pip3 install -U matplotlib
):示例输出
With
matplotlib
(pip3 install -U matplotlib
):Sample output
不幸的是,唯一未弃用的 API 位于 ApplicationServices 框架中,该框架没有桥支持文件,因此在桥中不可用。 如果您想使用 ctypes,可以在查找 ATSFontRef 后使用 ATSFontGetFileReference。
Cocoa 没有任何本机支持(至少从 10.5 开始),用于获取字体的位置。
Unfortunately the only API that isn't deprecated is located in the ApplicationServices framework, which doesn't have a bridge support file, and thus isn't available in the bridge. If you're wanting to use ctypes, you can use ATSFontGetFileReference after looking up the ATSFontRef.
Cocoa doesn't have any native support, at least as of 10.5, for getting the location of a font.