我在 UILabel (iOS7) 中使用字体,遇到了一些我希望有人能解释的事情: 字体的 Glyph、Ascender 和 Descender 之间有什么关系?
从我读过的文档中,上升是基线上方字体的部分,下降是基线下方的部分(返回为负数)。组合的绝对值应该是字体的最大高度。
例如,上升高度为 255,下降高度为 -64,总高度为 319。 然而字形高度返回为 228.4
编辑:这是字形代码:
CTFontRef ctFont = CTFontCreateWithName((__bridge CFStringRef)(uiFont.fontName), uiFont.pointSize, NULL);
UniChar ch = [msgLabel.text characterAtIndex:0];
CGGlyph glyph;
if (CTFontGetGlyphsForCharacters (ctFont, &ch, &glyph, 1)) {
CGRect bounds = CTFontGetBoundingRectsForGlyphs (ctFont, kCTFontOrientationDefault, &glyph, nil, 1);
float glyphHeight = bounds.size.height;
}
这是升序/降序代码:
float adHeight = myLabel.font.ascender-myLabel.font.descender; //Descender is always a negative value
那么为什么从 CTFontGetBoundingRectsForGlyphs 返回的字形高度不等于 Ascender 加上 Descender?
最佳答案
字体中的每个字形(字母形状)都是不同的大小和形状,对吗?字符“A”的字形比字符“a”的字形高,“t”字形的顶部再次不同。
Font.ascender 是所有字母形状(字形)的最大值,Font.descender 是最小值。
任何特定字体都可以很容易地具有超高字形,这意味着 Font.ascender 值与不包含该字符的字符串的尺寸无关。
关于ios - iOS 中字体 Glyph Ascender 和 Descender 之间的关系是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22647439/