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

标签 unicode fonts core-text

我对字体和编码有基本的了解,但最近我不得不做一些超出我舒适区的事情:将字符 ✖ ( 0x2716 "heavy multiplication x") 变成 CGPathRef .

我使用了 Core Text 的 CTFontGetGlyphsForCharacters来完成这项工作。据我所知 CGGlyph实际上是给定字体支持的字形集的索引。我很快发现 iOS 上只有极少数字体支持这种字形,包括 Zapf Dingbats,我选择了它。

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

最佳答案

Core Text 中的后备字体列表称为“级联列表”,它是 CTFontDescriptor 的一个属性。 ( 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);

在 Mac OS X 10.10 上,默认的英文级联列表包含 26 种字体,涵盖了广泛的语言和符号集。

您可以为自己的级联列表/后备字体自定义 CTFont实例通过设置 kCTFontCascadeListAttribute自定义属性 CTFontDescriptor到后备数组 CTFontDescriptor对象。然后,把它变成 CTFontCTFontCreateWithFontDescriptor() .如果您没有在 CTFontDescriptor 上设置自定义级联列表,默认使用全局列表。

关于unicode - Apple 的文本渲染如何绘制字体没有的字形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29069362/

相关文章:

PHP:如何创建编码为 "UTF-8 without BOM"的文件

python - 为什么我们需要 str 类型?为什么不只是字节串?

css - Google 的 Material Icon 字体是为抗锯齿设计的吗?

java - 如何在 Windows/Linux 上设置 Java Swing 应用程序的 DPI?

objective-c - Core Text 比 NSString drawInRect :? 小一点

ios - 如何获得 UIFont 的百分比 lineSpacing? (计算百分比值)

java - 使用带有 unicode 字符的 DocumentFilter.replace

html - 如何使网站上的文字看起来是手写的,但不可读

ios - 如何正确补偿CGContextRef坐标系,使原点在左上角

python - 如何在Python中替换unicode汉字?