通过使用以下代码,我可以找到下降器和总高度:
descender_height = paint.descent();
total_height = descender_height - paint.ascent();
//ascender = ?; is this always equal to descender height?
//x_height = ?; total_height - 2*descender_height ?
谢谢
我认为上升高度和下降高度通常是相同的,但我不会对每种字体都依赖它。我真的没有看到直接到达 x 高度的方法,但是您可以使用的技巧如下所示。另外,对于总高度,您是在谈论从最高上升点到最低下降点的绝对距离吗?我还在下面包含了一些内容。我自己没有测试过这些,但它应该可以工作(但如果我误解了你所说的话,请告诉我):
// Assuming TextPaint/Paint tp;
Rect bounds;
// this will just retrieve the bounding rect for 'x'
tp.getTextBounds("x", 0, 1, bounds);
int xHeight = bounds.height();
Paint.FontMetrics metrics = tp.getFontMetrics();
int totalHeight = metrics.top - metrics.bottom;
这对我有用:
Paint.FontMetrics fm = paint.getFontMetrics();
int totalHeight = (int)(fm.bottom - fm.top + .5f);