iOS中字体Glyph Ascender和Descender之间的关系是什么? [英] What is the relationship between a font Glyph Ascender and Descender in iOS?

查看:2954
本文介绍了iOS中字体Glyph Ascender和Descender之间的关系是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UILabel(iOS7)中的字体,并且遇到了一些我希望有人可以解释的内容:
字体的Glyph,Ascender和Descender之间的关系是什么?



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




例如一个255的Ascender和-64的Descender会给出319的总高度。
然而,雕文的高度返回值为228.4

编辑:这是Glyph代码:

  CTFontRef ctFont = CTFontCreateWithName((__ bridge CFStringRef)(uiFont.fontName),uiFont.pointSize,NULL); 
UniChar ch = [msgLabel.text characterAtIndex:0];
CGGlyph字形; (CTFontGetGlyphsForCharacters(ctFont,& ch,&glyph,1)){
CGRect bounds = CTFontGetBoundingRectsForGlyphs(ctFont,kCTFontOrientationDefault,& glyph,nil,1);
float glyphHeight = bounds.size.height;

$ / code>

这里是Ascender / Descender代码:

  float adHeight = myLabel.font.ascender-myLabel.font.descender;那么为什么从CTFontGetBoundingRectsForGlyphs返回的字形高度不等于Ascender的呢?为什么从CTFontGetBoundingRectsForGlyphs返回的字形高度不等于Ascender加上Descender?

解决方案

字体中的每个字形(字母形状)都是不同的大小和形状,对吧?字符'A'的字形高于字符'a'的字形,t字形的顶部又是不同的。



Font.ascender是所有字母形状(字形)的最大值和Font.descender是最小值。

任何特定的字体可以很容易地有一个额外的高字形,这意味着Font.ascender值与不包含该字符的字符串的维度无关。


I'm working with fonts in a UILabel (iOS7) and have come across something I'm hoping someone can explain: What is the relationship between a fonts' Glyph, Ascender, and Descender?

From the documents I've read the Ascender is the portion of a font above the baseline, the Descender is the portion below (returned as negative). The combined absolute values should be the max Height of the font.

For example an Ascender of 255 and a Descender of -64 would give a total height of 319. However the Glyph height is returned as 228.4

EDIT: Here's the Glyph code:

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;
}

And here's the Ascender/Descender code:

float adHeight = myLabel.font.ascender-myLabel.font.descender; //Descender is always a negative value

So why does the Glyph height returned from CTFontGetBoundingRectsForGlyphs not equal the Ascender plus Descender?

解决方案

Every glyph (letter shape) in the font is a different size and shape, right? The glyph for character 'A' is taller than the glyph for character 'a', the top of the 't' glyph is different again.

Font.ascender is the maximum value for all letter shapes (glyphs) and Font.descender is the minimum value.

Any particular font could easily have an extra tall glyph that meant the Font.ascender value had no relation to the dimensions of a string that didn't contain that character.

这篇关于iOS中字体Glyph Ascender和Descender之间的关系是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆