Apple的文本渲染如何绘制字体没有的字形?

Gre*_*ley 3 unicode fonts core-text

我对字体和编码有基本的了解,但最近我不得不在我的舒适区之外做一些事情:将角色✖(0x2716"重乘x")变成a CGPathRef.

我使用Core Text CTFontGetGlyphsForCharacters来完成这项工作.我知道a CGGlyph实际上是给定字体支持的字形集的索引.我很快发现这个字形仅由iOS上的极少字体支持,包括Zapf Dingbats,这是我选择的字体.

这是我的问题:我可以使用任何字体的,,只需粘贴它.我在Pages中做了一个小实验,我将pas粘贴到文档中,选择它,然后不断更改字体.我做了类似的程序化实验.字形始终正确显示(并且从不更改).如果这些字体中很少有✖,这是如何工作的?如果给定的字体没有这样的符号,是否有一些"后备字形"(我猜这将是"后备字体")?如果是这样,有没有办法获得这些字形的编程访问?

一二三*_*一二三 9

Core Text中的后备字体列表称为"级联列表",它是CTFontDescriptor(the kCTFontCascadeListAttribute)的属性.

可以使用访问系统的默认级联列表CTFontCopyDefaultCascadeListForLanguages().由于某些原因,Apple的网站上没有记录此功能,但这里是来自'CTFont.h'头文件的文档:

/*!
    @function   CTFontCopyDefaultCascadeListForLanguages
    @abstract   Return an ordered list of CTFontDescriptorRef's for font
                fallback derived from the system default fallback region
                according to the given language preferences. The style of
                the given is also matched as well as the weight and width
                of the font is not one of the system UI font, otherwise
                the UI font fallback is applied.

    @param      font
                The font reference.

    @param      languagePrefList
                The language preference list - ordered array of
                CFStringRef's of ISO language codes.

    @result     The ordered list of fallback fonts - ordered array of
                CTFontDescriptors.
*/
CFArrayRef CTFontCopyDefaultCascadeListForLanguages(
    CTFontRef font,
    CFArrayRef languagePrefList ) CT_AVAILABLE(10_8, 6_0);
Run Code Online (Sandbox Code Playgroud)

在Mac OS X 10.10上,默认的英语级联列表包含26种字体,涵盖了大量语言和符号.

您可以CTFont通过将kCTFontCascadeListAttribute自定义属性设置CTFontDescriptor为回退CTFontDescriptor对象数组,为自己的实例自定义级联列表/回退字体.然后,把它变成一个CTFont有CTFontCreateWithFontDescriptor().如果您未在自己上设置自定义级联列表CTFontDescriptor,则默认情况下将使用全局列表.