views:

14

answers:

0

Hi all,

I'm in a situation where I need to draw glyph characters. So, the logical course of action is this:

CTFontRef ref = CTFontCreateWithName(CFSTR("HiraKakuProN-W3"), 12, NULL);
CGFontRef ftRef = CTFontCopyGraphicsFont(ref, NULL);
CGContextSetFont(theContext, ftRef);

int count = [self.text length];
UniChar *chars = malloc(sizeof(UniChar) * count);
CGGlyph *glyphs = malloc(sizeof(CGGlyph) * count);
for (int i = 0; i < count; i++)
    chars[i] = [self.text characterAtIndex:i];
CTFontGetGlyphsForCharacters(ref, chars, glyphs, count);

CGContextShowGlyphsAtPoint(theContext,
                           self.frame.size.width / 2 - newSize.width / 2, 
                           self.frame.size.height / 2 + (size_t)self.font.ascender / 4,
                           glyphs, 
                           count);
free(chars);
free(glyphs);

"HiraKakuProN-W3" is great because it seems to work for most languages, but how can I get the preferred system font name? Everything I try seems to be returning Helvetica, which doesn't work for Eastern languages. If I set my system language to Simplified Chinese, for instance, functions are still returning Helvetica. I've tried to use the function CTFontCreateUIFontForLanguage, with no luck. Anyone know how to accurately detect what font the iPhone is using for displaying text?