已安装的字体OS X/C列表

use*_*600 4 c python macos fonts

我正在尝试以编程方式获取C或Python中已安装字体的列表.我需要能够在OS X上执行此操作,有人知道如何操作吗?

Mil*_*les 13

安装了PyObjC的Python(适用于Mac OS X 10.5+的情况,因此这段代码无需安装任何东西即可运行):

import Cocoa
manager = Cocoa.NSFontManager.sharedFontManager()
font_families = list(manager.availableFontFamilies())
Run Code Online (Sandbox Code Playgroud)

(根据htw的回答)


Bro*_*olf 5

为什么不使用终端?

系统字体:

ls -R /System/Library/Fonts | grep ttf
Run Code Online (Sandbox Code Playgroud)

用户字体:

ls -R ~/Library/Fonts | grep ttf
Run Code Online (Sandbox Code Playgroud)

Mac OS X默认字体:

ls -R /Library/Fonts | grep ttf
Run Code Online (Sandbox Code Playgroud)

如果您需要在C程序中运行它:

void main()
{ 
    printf("System fonts: ");
    execl("/bin/ls","ls -R /System/Library/Fonts | grep ttf", "-l",0);
    printf("Mac OS X Default fonts: ");
    execl("/bin/ls","ls -R /Library/Fonts | grep ttf", "-l",0);
    printf("User fonts: ");
    execl("/bin/ls","ls -R ~/Library/Fonts | grep ttf", "-l",0);
}
Run Code Online (Sandbox Code Playgroud)