如何获得给定字体的上升/下降和x高度

我需要得到一个ascender / descender和x-height .. 通过使用以下代码,我可以找到下降器和总高度:
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 ?
谢谢     
已邀请:
我认为ascender和descender高度通常是相同的,但我不会依赖于它的每一种字体。我真的没有看到直接进入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);
    

要回复问题请先登录注册