我正在开发一款带文本字段的应用程序。在该字段中输入的文本将被打印,但我遇到了一些字符问题,如表情符号、汉字等,因为字体不提供这些字符。
这就是为什么我想获取由字体提供的所有字符(该字体已下载,因此我可以直接处理文件或使用UIFont对象)。
我听说过CTFontGetGlyphsForCharacters,但我不确定这个函数是否实现我想要的功能,也无法让它工作。
以下是我的代码:
这就是为什么我想获取由字体提供的所有字符(该字体已下载,因此我可以直接处理文件或使用UIFont对象)。
我听说过CTFontGetGlyphsForCharacters,但我不确定这个函数是否实现我想要的功能,也无法让它工作。
以下是我的代码:
CTFontRef fontRef = CTFontCreateWithName((CFStringRef)font.fontName, font.pointSize, NULL);
NSString *characters = @""; // emoji character
NSUInteger count = characters.length;
CGGlyph glyphs[count];
if (CTFontGetGlyphsForCharacters(fontRef, (const unichar*)[characters cStringUsingEncoding:NSUTF8StringEncoding], glyphs, count) == false)
NSLog(@"CTFontGetGlyphsForCharacters failed.");
在这里,CTFontGetGlyphsForCharacters
返回false。这正是我想要的,因为字体不包含字符“”。
问题出现在我将NSString *characters = @""
替换为NSString *characters = @"abc"
时,CTFontGetGlyphsForCharacters
再次返回false。显然,我的字体对所有ASCII字符都提供了字形。