所以我有一个NSFont,我想得到任何字符的最大尺寸,即音高和字母高度。[font maximumAdvancement]似乎返回的NSSize为{pitch,0},因此这没有帮助。Bounding rect似乎也不起作用,来自
jwz's similar question
使现代化
:我用于获取贝塞尔尺寸的代码如下:
NSBezierPath *bezier = [NSBezierPath bezierPath];
NSGlyph g;
{
NSTextStorage *ts = [[NSTextStorage alloc] initWithString:@" "];
[ts setFont:font];
NSLayoutManager *lm = [[NSLayoutManager alloc] init];
NSTextContainer *tc = [[NSTextContainer alloc] init];
[lm addTextContainer:tc];
[tc release]; // lm retains tc
[ts addLayoutManager:lm];
[lm release]; // ts retains lm
g = [lm glyphAtIndex:0];
[ts release];
}
NSPoint pt = {0.0f};
[bezier moveToPoint:pt];
[bezier appendBezierPathWithGlyph:g inFont:font];
NSRect bounds = [bezier bounds];