Wednesday, 14 August 2013

OSX: CGGlyph to UniChar

OSX: CGGlyph to UniChar

I am currently writing a simple bitmap font generator using CoreGraphics
and CoreText. I am retrieving the kerning table of a font with:
CFDataRef kernTable = CTFontCopyTable(m_ctFontRef, kCTFontTableKern,
kCTFontTableOptionNoOptions);
and then parse it which works fine. The kerning pairs give me the glyph
indices (i.e. CGGlyph) for the kerning pairs, and I need to translate them
to unicode (i.e. UniChar), which unfortunately does not seem super easy.
The closest I got was using:
CGFontCopyGlyphNameForGlyph
to retrieve the glyph name of the CGGlyph, but I don't know how to convert
the name to unicode, as they are really just strings such as quoteleft.
Another thing I though about was parsing the kCTFontTableCmap myself to
manually do the mapping from the glyph to the unicode id, but that seems
to be a ton of extra work for the task. Is there any simple way of doing
this?
Thanks!

No comments:

Post a Comment