Question

Is there a way to determine whether or not a font can render a particular Unicode character in Cocoa? Alternatively, is it possible to specify the default substitute character?

Was it helpful?

Solution

You can use CGFontGetGlyphWithGlyphName() for iOS older versions of iOS (2.0). Apple doesn't seem to document the glyph names but I believe they correspond to this Adobe list:

http://partners.adobe.com/public/developer/en/opentype/glyphlist.txt

For example, the glyph for é (U+00E9) is named "eacute" and the code to get the glyph would be:

CFStringRef name = CFStringCreateWithCString(NULL, "eacute", kCFStringEncodingUTF8);
CGGlyph glyph = CGFontGetGlyphWithGlyphName(font, name);

OTHER TIPS

Check out CTFontGetGlyphsForCharacters in the Core Text framework. If it returns zero for a given Unicode character's glyph index, then that character isn't supported in that font. The function returns false if any of the glyphs couldn't be found.

Since it is on iOS, you might need to build or find an app that does this. Ultimately, if the info is present for any individual glyph it is in the tables in the font file itself and that is pretty low level C work.

Much easier to build a tool that inspects the font and shows the glyph and glyph index (CGGlyph or NSGlyph value) then use the glyph index.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top