I am trying to render font glyphs at a specific point with some precision, and am having quite a bit of trouble with it.
To begin with, the Text Position Y value never changes, so I cannot get the glyph's height at all. For example, in the following code, the assertion always fires:
CGContextSelectFont(g, "Arial", 32.0f, kCGEncodingFontSpecific);
char c = 'A';
CGPoint pt = CGPointMake(400, 400);
CGContextSetTextDrawingMode(g, kCGTextInvisible);
CGContextSetTextPosition(g, pt.x, pt.y);
CGContextShowText(g, &c, 1);
CGPoint pt2 = CGContextGetTextPosition(g);
assert(pt2.y != pt.y);
I have tried to work around this using some hard-coded width-to-height ratios, assuming the glyphs scale linearly. Note that the X value of the text position is updated correctly.
More importantly, however, is how the glyph renders in relation to the Text Position; some glyphs render with the Y value as the center of the glyph, some use the Y value as the top of the glyph, and others use the Y value as the bottom of the glyph. I can't hard-code all this data and hope to get my app done any time this year.
Is there anything I am doing incorrectly in the drawing code above? I can't find any reference in the Quartz docs related to vertical alignment, and am a little lost.
Thanks