The CTFontRef provides excellent method such as CTFontGetGlyphsForCharacters for mapping character(s) to glyph(s). My question is, is there any method for invert mapping? That is say, can I get characters(s) by given glyph(s)? Since I found there is a CTFontCopyCharacterSet for getting all supported characters, I think there will be some nice solutions.
The CTFontRef provides excellent method such as CTFontGetGlyphsForCharacters for mapping character(s) to glyph(s). My
Share
I think you may end up having to parse the font’s mapping tables yourself. You can obtain access to the tables using
CGFontCopyTableForTag(); the table you’re after is the ‘cmap‘ table, the format of which is documented here:http://www.microsoft.com/typography/otspec/cmap.htm
and also here:
http://developer.apple.com/fonts/TTRefMan/RM06/Chap6cmap.html
Unfortunately, as you’ll discover by reading through these, the business of mapping characters to glyphs is decidedly non-trivial, and in addition any given font may have more than one mapping table (i.e. the set of characters that use a given glyph may depend on which mapping table format you—or the renderer—chooses).
Furthermore, advanced font technology like OpenType or AAT may result in the existence of glyphs for which there is no direct mapping from characters, but that are nevertheless present in the output as a result of substitutions made by the smart font technology. Inverting the OpenType or AAT substitution mechanisms would be tricky, and might also not lead to a single Unicode code point (or indeed even a single grapheme cluster).