相关疑难解决方法(0)

核心文本 - 字形的高度

我有2个属性字符串说'A'和'.'

我需要计算每个字符串的高度.目前返回的高度对于两者都是相同的,它似乎返回给定字体中最高字符的最大可能高度(即使字符串中不存在该字符).

我想得到每个这些字符的确切像素高度,这样我就可以调整它们周围的视图,使其符合角色(字形).我尝试过使用CTFramesetterSuggestFrameSizeWithConstraints()和CTLineGetTypographicBounds(),但它返回一个类似于属性字符串大小方法的数字.

非常感谢有关如何做到这一点的任何提示!

cocoa core-graphics core-text ios

8
推荐指数
1
解决办法
1563
查看次数

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

我正在处理 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?

fonts objective-c ios

5
推荐指数
1
解决办法
3218
查看次数

标签 统计

ios ×2

cocoa ×1

core-graphics ×1

core-text ×1

fonts ×1

objective-c ×1