Mor*_*iak 3 fonts objective-c uifont ios emoji
我正在开发一个带有文本字段的应用程序.在这个字段中写的文本将被打印,我有一些问题,如表情符号,中文字符等...因为字体不提供这些字符.
这就是为什么我想获得字体提供的所有字符(字体被下载所以我可以直接处理文件或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.");
Run Code Online (Sandbox Code Playgroud)
这里CTFontGetGlyphsForCharacters返回false.这就是我想要的,因为所使用的字体不提供字符''.
问题是,当我更换NSString *characters = @""的NSString *characters = @"abc",CTFontGetGlyphsForCharacters返回再假.显然,我的字体为所有ASCII字符提供了一个字形.
我终于解决了:
- (BOOL)isCharacter:(unichar)character supportedByFont:(UIFont *)aFont
{
UniChar characters[] = { character };
CGGlyph glyphs[1] = { };
CTFontRef ctFont = CTFontCreateWithName((CFStringRef)aFont.fontName, aFont.pointSize, NULL);
BOOL ret = CTFontGetGlyphsForCharacters(ctFont, characters, glyphs, 1);
CFRelease(ctFont);
return ret;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2587 次 |
| 最近记录: |