On OSX, the only way I've found to do it is:
- Make an NSTextStorage and NSLayoutManager;
- Get an NSGlyph from that;
- [NSBezierPath appendBezierPathWithGlyph];
- currentPoint to find the width;
- bounds to find the bounding box.
(You'd think you could get the NSGlyph with [NSFont glyphWithName], but that expects full Unicrud names like "LATIN CAPITAL LETTER A WITH ACUTE" and there is no way to get one of those from a single-character NSString, so I don't understand why that API even exists.)
Naturally, none of these APIs exist on iOS.
- [NSString sizeWithFont] gives us width and ascent, but nothing about the bounding box or bearings.
- [NSString drawAtPoint] to an offscreen CGContext returns the width of the character and the overall ascent of the font;
- CGFontGetGlyphBBoxes() might help (or it might just return the ascent/width again instead of the bounding box, I don't know) but there seems to again be no way to map a single-character NSString to a CGGlyph.
So I'm stuck with assuming that all characters have a 0 lbearing and rbearing, and things get clipped. See query_font() in xscreensaver/OSX/jwxyz.m.
Does the malloc on iOS contain any tricks for allocating out of a private heap? What the LISPMs called *default-cons-area* and PostScript called save/restore. E.g., it would be convenient to do something like this in my code:
#define malloc(x) malloc_in_heap (my_heap, x)
And then at the end, flush that heap in one swell foop, that is, I want to be able to say, "I swear that nothing references any pointer that has been allocated out of this area any more, regardless of whether all corresponding free calls have been made; unmap it all right now."
I know about NSAutoreleasePool, but that doesn't help with malloc, only NSObject.