How does Apple's text rendering draw a glyph that a font doesn't have?

后端 未结 1 606
故里飘歌
故里飘歌 2021-01-13 03:48

I have a basic understanding of fonts and encoding, but recently I had to do something outside of my comfort zone: Turn the character ✖ (0x2716 \"heavy m

相关标签:
1条回答
  • 2021-01-13 04:30

    A list of fallback fonts in Core Text is known as a "cascade list", which is an attribute of a CTFontDescriptor (the kCTFontCascadeListAttribute).

    The system's default cascade list can be accessed using CTFontCopyDefaultCascadeListForLanguages(). For some reason this function isn't documented on Apple's website yet, but here's its documentation from the 'CTFont.h' header file:

    /*!
        @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);
    

    On Mac OS X 10.10, the default English cascade list contains 26 fonts that cover a wide set of languages and symbols.

    You can customise the cascade list/fallback fonts for your own CTFont instances by setting the kCTFontCascadeListAttribute attribute of a custom CTFontDescriptor to an array of fallback CTFontDescriptor objects. Then, turn it into a CTFont with CTFontCreateWithFontDescriptor(). If you don't set a custom cascade list on your CTFontDescriptor, it will use the global list by default.

    0 讨论(0)
提交回复
热议问题