如何使用Core Text从文件加载字体(TTF)? [英] How can you load a font (TTF) from a file using Core Text?

查看:294
本文介绍了如何使用Core Text从文件加载字体(TTF)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Prior to OSX 10.6, ATSFontActivateFromFileSpecification/ATSFontActivateFromFileReference were available and could be used to load a font from a file. I can't find anything similar in Core Text.

推荐答案

你可以得到一个 CTFontRef 通过 CGFontRef 从字体文件中删除:

You can get a CTFontRef from a font file by going via a CGFontRef:

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);   

这篇关于如何使用Core Text从文件加载字体(TTF)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆