本文介绍了CTLineGetTypographicBounds的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码是从中提取的修改。
The code is extracted from SimpleTextInput sampe code, with a bit modification.
创建框架:
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)
):
line below is any line of the frame (get by CTFrameGetLines(_frame)
):
CGFloat ascent, descent, leading;
CTLineGetTypographicBounds(line, &ascent, &descent, &leading);
CGPoint origin;
CTFrameGetLineOrigins(_frame, CFRangeMake(i, 1), &origin);
问题:
- 从CTLineGetTypographicBounds或ctFont获得的上升是13.860352,而self.font.ascender是16.860352。这3点差异来自哪里?
- 下降是4.139648,前导是0,所以上升+下降+前导= 18,但是self.font.lineHeight和行高减去邻近这个4点的差异来自哪里?
推荐答案
阅读本文档,您将了解如何计算行高,但我仍然不明白为什么CTLineGetTypographicBounds得到零导致
http://developer.apple.com/library/mac/#documentation/TextFonts/Conceptual/CocoaTextArchitecture/TypoFeatures/TextSystemFeatures.htmlread this doc and you will know how line-height is calculated, but I still don't get why CTLineGetTypographicBounds got a zero leading
这篇关于CTLineGetTypographicBounds的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!