ios - How to check if a character is supported by a font -
ios - How to check if a character is supported by a font -
i'm working on app text field. text wrote in field printed , have issue characters emoji, chinese characters, etc... because font not provide these characters.
it's why want character provided font (the font downloaded can deal straight file or uifont object).
i heard ctfontgetglyphsforcharacters
i'm not sure function want , can't work.
here code :
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.");
here ctfontgetglyphsforcharacters
homecoming false. it's want because character '🐯' not provided font used. problem when replace nsstring *characters = @"🐯"
nsstring *characters = @"abc"
, ctfontgetglyphsforcharacters
homecoming 1 time again false. obviously, font provide glyph ascii characters.
i solve :
- (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); homecoming ret; }
ios objective-c fonts uifont emoji
Comments
Post a Comment