Android 如何获取给定字体的升序/降序和x高度
我需要找一个/和 通过使用以下代码,我可以找到下降器和总高度:Android 如何获取给定字体的升序/降序和x高度,android,fonts,fontmetrics,Android,Fonts,Fontmetrics,我需要找一个/和 通过使用以下代码,我可以找到下降器和总高度: 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 ? 谢谢我认为上升和下降高度通常是相同的,但我
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高度,但是你可以使用下面的技巧。另外,对于总高度,你是说从最高的上升点到最低的下降点的绝对距离吗?我在下面也包含了一些相关内容。我自己还没有测试过这些,但它应该可以工作(但如果我误解了您所说的话,请告诉我):
这就是我的工作原理:
Paint.FontMetrics fm = paint.getFontMetrics();
int totalHeight = (int)(fm.bottom - fm.top + .5f);
Paint.FontMetrics fm = paint.getFontMetrics();
int totalHeight = (int)(fm.bottom - fm.top + .5f);