您可以使用CTFontGetGlyphsForCharacters()
來確定是否字體有特定的代碼點字形(請注意,增補字符需要檢查的代理對):
CTFontRef font = CTFontCreateWithName(CFSTR("Helvetica"), 12, NULL);
const UniChar code_point[] = { 0xD83C, 0xDCA1 }; // U+1F0A1
CGGlyph glyph[] = { 0, 0 };
bool has_glyph = CTFontGetGlyphsForCharacters(font, code_point, glyph, 2);
或者,在斯威夫特:
let font = CTFontCreateWithName("Helvetica", 12, nil)
var code_point: [UniChar] = [0xD83C, 0xDCA1]
var glyphs: [CGGlyph] = [0, 0]
let has_glyph = CTFontGetGlyphsForCharacters(font, &code_point, &glyph, 2)
如果要查看完整的一套TH後備字體的系統會嘗試加載字形,您需要檢查CTFontCopyDefaultCascadeListForLanguages()
返回的所有字體。查看answer to this question以獲取有關如何創建備用字體列表的信息。
也許使用'CTFontGetGlyphsForCharacters(...)'? – MirekE
你可以給我們這兩個代碼點嗎? –
@ZoffDino我沒有一個外國人傢伙得心應手,但是以?爲例,這個角色顯示爲?在iOS上: – Joey