I'm lost in a twisty maze of font handling APIs, all alike.
I've got a bunch of Quartz code, and I need to do fonty things. Right now I'm doing this kind of stuff:
<LJ-CUT text=" --More--(16%) ">
- CGContextSelectFont (cgc, "Helvetica Bold", 12, kCGEncodingMacRoman);
CGContextSetTextMatrix (cgc, CGAffineTransformIdentity);
CGContextSetTextDrawingMode (cgc, kCGTextFill);
CGContextSetShouldAntialias (cgc, YES);
CGContextShowTextAtPoint (cgc, x, y, string, length);
That's all well and good, but now I need per-char metrics: I need to know the ascent, descent, lbearing, rbearing, and bounding box of each character I'm drawing. As far as I can tell, the only thing Quartz will give you is rbearing (aka horizontal cursor motion):
- CGContextSetTextDrawingMode (cgc, kCGTextInvisible);
CGContextShowTextAtPoint (cgc, 0, 0, &c, 1);
CGPoint p = CGContextGetTextPosition (cgc);
So should I be using NSFont? ATSU? Something else? I can't tell... I tried to use NSFont, but I can't see how to attach an NSFont to an arbitrary CGContextRef (which might be either a window or bitmap context). I thought it might be:
- NSGraphicsContext *nsctx =
[NSGraphicsContext graphicsContextWithGraphicsPort:cgc flipped:NO];
If the answer is ATSU, please point me at some sample code that involves ATSU and Quartz but not Carbon/QuickDraw, because I haven't found any.
How does aglUseFont() relate to these other three font APIs (CG, ATSU, and NSFont)? How do I turn "Helvetica Bold" or "Courier" into the kind of "fontID" that it wants?
Update: I did solve this eventually; if you want to see the working code, see the query_font() and draw_string() functions in xscreensaver/OSX/jwxyz.m.