-
- bbox.origin.x = 0;
- bbox.origin.y = [ff descender];
- bbox.size.width = size.width;
- bbox.size.height = size.height;
-
- advancement.x = size.width;
- advancement.y = 0;
-
+ UniChar uchar = [nsstr characterAtIndex: 0];
+ CGGlyph cgglyph = 0;
+
+ if (CTFontGetGlyphsForCharacters (ctfont, &uchar, &cgglyph, 1))
+ {
+ bbox = CTFontGetBoundingRectsForGlyphs (ctfont,
+ kCTFontDefaultOrientation,
+ &cgglyph, NULL, 1);
+ CGSize adv = { 0, };
+ CTFontGetAdvancesForGlyphs (ctfont, kCTFontDefaultOrientation,
+ &cgglyph, &adv, 1);
+ advancement.x = adv.width;
+ advancement.y = adv.height;
+
+ // Seems to be clipping by a pixel or two. Add a margin to be safe.
+ bbox.origin.x -= 2;
+ bbox.origin.y -= 2;
+ bbox.size.width += 4;
+ bbox.size.height += 4;
+ }