ios - iOS 中字体 Glyph Ascender 和 Descender 之间的关系是什么?

标签 ios objective-c fonts

我在 UILabel (iOS7) 中使用字体,遇到了一些我希望有人能解释的事情: 字体的 Glyph、Ascender 和 Descender 之间有什么关系?

从我读过的文档中,上升是基线上方字体的部分,下降是基线下方的部分(返回为负数)。组合的绝对值应该是字体的最大高度。

From Apple's documentation

例如,上升高度为 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/

相关文章:

pdf - 使用 itextsharp 将字体嵌入到 pdf 中

ios - 如何像 UITableViewCell 一样重用 UIView

objective-c - 更改 UIScrollView 中每个 UILabel 的颜色

css - 是否有一些好的和无张力的自定义字体可用于 sIFR、@font-face 等?

iphone - 用于在推文中查找主题标签的正则表达式无法正常工作

iPhone数据传输问题

html - safari 中的字体顶部被截断

ios - ScrollView contentSize 大于边界,但没有滚动

ios - 构建 xcode 项目时界面生成器 Storyboard 编译器错误

ios - 添加 CADisplayLink 到 Cocos2D