【发布时间】:2014-10-21 12:22:55
【问题描述】:
我想知道使用 FreeType 2 获取文本边界框的最佳方法是什么?
为了得到行空间边界框的宽度,我遍历了文本的所有字符并得到它的前进和紧缩:
FT_Face face = ...;
text_bbox_width = 0;
while (*p_text)
{
...
FT_Get_Kerning(...);
text_bbox_width += (face->glyph->advance.x + kerning.x) >> 6;
}
如何获取行空间边界框高度?是否需要迭代或可以使用字体数据获得?即:
text_bbox_height = (face->ascender - face->descender) >> 6
【问题讨论】:
-
您希望字符串
...、---、___和Hfj的边界框高度相同吗?请注意,Freetype 不关心 line 间距;这可以小于、等于或大于绘制字符的“必要”空间。 -
@Jongware 是的,行高。