CTLineGetTypographicBounds的问题

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

创build框架:

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); 

下面的行是框架的任何一行(通过CTFrameGetLines(_frame) ):

 CGFloat ascent, descent, leading; CTLineGetTypographicBounds(line, &ascent, &descent, &leading); CGPoint origin; CTFrameGetLineOrigins(_frame, CFRangeMake(i, 1), &origin); 

问题:

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