- unsigned char str[2];
- str[0] = i;
- str[1] = 0;
-
- NSString *nsstr = [NSString stringWithCString:(char *) str
- encoding:NSISOLatin1StringEncoding];
- NSPoint advancement = { 0, };
- NSRect bbox = {{ 0, }, };
-
-# ifndef USE_IPHONE
-
- /* I can't believe we have to go through this bullshit just to
- convert a 'char' to an NSGlyph!!
-
- You might think that we could do
- NSGlyph glyph = [fid->nsfont glyphWithName:nsstr];
- but that doesn't work; my guess is that glyphWithName expects
- full Unicrud names like "LATIN CAPITAL LETTER A WITH ACUTE".
- */
- NSGlyph glyph;
- {
- NSTextStorage *ts = [[NSTextStorage alloc] initWithString:nsstr];
- [ts setFont:fid->nsfont];
- NSLayoutManager *lm = [[NSLayoutManager alloc] init];
-
- /* Without this, the layout manager ends up on a queue somewhere and is
- referenced again after we return to the command loop. Since we don't
- use this layout manager again, by that time it may have been garbage
- collected, and we crash. Setting this seems to cause `lm' to no
- longer be referenced once we exit this block. */
- [lm setBackgroundLayoutEnabled:NO];
-
- NSTextContainer *tc = [[NSTextContainer alloc] init];
- [lm addTextContainer:tc];
- [tc release]; // lm retains tc
- [ts addLayoutManager:lm];
- [lm release]; // ts retains lm
- glyph = [lm glyphAtIndex:0];
- [ts release];
- }
-
- /* Compute the bounding box and advancement by converting the glyph
- to a bezier path. There appears to be *no other way* to find out
- the bounding box of a character: [NSFont boundingRectForGlyph] and
- [NSString sizeWithAttributes] both return an advancement-sized
- rectangle, not a rectangle completely enclosing the glyph's ink.
- */
- advancement.x = advancement.y = 0;
- [bpath removeAllPoints];
- [bpath moveToPoint:advancement];
- [bpath appendBezierPathWithGlyph:glyph inFont:fid->nsfont];
- advancement = [bpath currentPoint];
- bbox = [bpath bounds];
-
-# else // USE_IPHONE