conmulligan
conmulligan

Reputation: 7148

Determining whether or not a font can render a Unicode character in Cocoa Touch

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?

Upvotes: 4

Views: 1897

Answers (3)

uchuugaka
uchuugaka

Reputation: 12782

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.

Upvotes: 1

Peter Phillips
Peter Phillips

Reputation: 244

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);

Upvotes: 3

Tony
Tony

Reputation: 3478

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.

Upvotes: 3

Related Questions