CTLineGetTypographicBounds的问题

an0*_*an0 6 core-text ios

代码是从SimpleTextInput sampe代码中提取的,稍作修改.

创建框架:

self.font = [UIFont systemFontOfSize:18.f];
CTFontRef ctFont = CTFontCreateWithName((CFStringRef) self.font.fontName, self.font.pointSize, NULL);        
self.attributes = [[NSDictionary dictionaryWithObject:(id)ctFont forKey:(NSString *)kCTFontAttributeName] retain];
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:self.text attributes:self.attributes];    

_framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attributedString);

// Create the Core Text frame using our current view rect bounds
UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.bounds];
_frame =  CTFramesetterCreateFrame(_framesetter, CFRangeMake(0, 0), [path CGPath], NULL);
Run Code Online (Sandbox Code Playgroud)

线下面是帧(由获得的任何线CTFrameGetLines(_frame)):

CGFloat ascent, descent, leading;
CTLineGetTypographicBounds(line, &ascent, &descent, &leading);
CGPoint origin;
CTFrameGetLineOrigins(_frame, CFRangeMake(i, 1), &origin);
Run Code Online (Sandbox Code Playgroud)

问题:

  1. 从CTLineGetTypographicBounds或ctFont获得的上升是13.860352,而self.font.ascender是16.860352.这3点差异来自哪里?
  2. 下降是4.139648,前导是0,所以上升+下降+前导= 18,但是self.font.lineHeight和通过减去相邻线起点计算的线高是22.这4点差异来自哪里?

Car*_*loS 0

http://developer.apple.com/library/mac/#documentation/TextFonts/Conceptual/CocoaTextArchitecture/TypoFeatures/TextSystemFeatures.html 阅读此文档,您将知道行高是如何计算的,但我仍然不明白为什么CTLineGetTypgraphicBounds 的前导为零