Nil*_*ect 19
遗憾的是,唯一未弃用的API位于ApplicationServices框架中,该框架没有桥接支持文件,因此在桥接器中不可用.如果您想使用ctypes,可以在查找ATSFontRef后使用ATSFontGetFileReference.
获取字体位置时,Cocoa没有任何本机支持,至少从10.5开始.
打开一个终端(Applications-> Utilities-> Terminal)并输入:
locate InsertFontHere
Run Code Online (Sandbox Code Playgroud)
这将吐出每个具有您想要名称的文件.
警告:可能会有很多趟过.
小智 6
我一直无法找到任何直接这样做的东西.我认为你必须通过该系统上的各种字体文件夹重复:/System/Library/Fonts
,/Library/Fonts
,并有可能可以是用户级目录以及~/Library/Fonts
.
在Cocoa中必须有一个方法来获取字体列表,然后你必须使用PyObjC绑定来调用它.
根据您的需要,您可能只需使用以下内容.
import os
def get_font_list():
fonts = []
for font_path in ["/Library/Fonts", os.path.expanduser("~/Library/Fonts")]:
if os.path.isdir(font_path):
fonts.extend(
[os.path.join(font_path, cur_font)
for cur_font in os.listdir(font_path)
]
)
return fonts
Run Code Online (Sandbox Code Playgroud)