在OSX 10.6之前,ATSFontActivateFromFileSpecification / ATSFontActivateFromFileReference可用,可用于从文件加载字体.在Core Text中找不到任何类似的东西.
解决方法
您可以通过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);