way*_*neh 5 fonts objective-c ios
我正在处理 UILabel (iOS7) 中的字体并且遇到了一些我希望有人能解释的事情:字体的 Glyph、Ascender 和 Descender 之间有什么关系?
从我读过的文档中,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;
}
Run Code Online (Sandbox Code Playgroud)
这是上升器/下降器代码:
float adHeight = myLabel.font.ascender-myLabel.font.descender; //Descender is always a negative value
Run Code Online (Sandbox Code Playgroud)
那么为什么从 CTFontGetBoundingRectsForGlyphs 返回的 Glyph 高度不等于 Ascender 加 Descender?
字体中的每个字形(字母形状)都有不同的大小和形状,对吗?字符“A”的字形比字符“a”的字形高,“t”字形的顶部又不同。
Font.ascender 是所有字母形状(字形)的最大值,Font.descender 是最小值。
任何特定字体都可以很容易地具有额外高的字形,这意味着 Font.ascender 值与不包含该字符的字符串的尺寸没有关系。
| 归档时间: |
|
| 查看次数: |
3218 次 |
| 最近记录: |