cocoa - 如何使用 Core Text 从文件加载字体 (TTF)?

标签 cocoa macos macos-carbon osx-snow-leopard core-text

在 OSX 10.6 之前,ATSFontActivateFromFileSpecification/ATSFontActivateFromFileReference 可用,可用于从文件加载字体。我在核心文本中找不到类似的内容。

最佳答案

您可以通过 CGFontRef 从字体文件中获取 CTFontRef:

CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/path/to/font"), kCFURLPOSIXPathStyle, false);
CGDataProviderRef dataProvider = CGDataProviderCreateWithURL(url);
CGFontRef theCGFont = CGFontCreateWithDataProvider(dataProvider);
CTFontRef theCTFont = CTFontCreateWithGraphicsFont(theCGFont);
CFRelease(theCGFont);
CFRelease(dataProvider);
CFRelease(url);

// do something with the CTFontRef here

CFRelease(theCTFont);   

关于cocoa - 如何使用 Core Text 从文件加载字体 (TTF)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2703085/

相关文章:

cocoa - 将字符串写入 NSPasteBoard

swift - 关闭 View Controller 不停止异步任务

c++ - Qt:如何在 Mac 的应用程序菜单中添加自定义菜单项?

macos - 如何查询所有 Finder 别名的目标?

python - 什么替代了 OSX 上 Python 中现已弃用的 Carbon.File.FSResolveAliasFile?

macos - 如何在 Objective-C 中读取和写入 plist 中的数据? (不是 iOS,OS X 的常规 Cocoa)

objective-c - 将 NSString 转换为 NSData 会强制尾随字节吗?

iphone - 将对象保存在内存中(iPhone SDK)

c++ - 谁能告诉我有关 Mac 上切换前端进程的事件处理程序或回调的信息?

objective-c - 如何阻止 HIToolbox 捕获我的异常?