如何获得伸/下降装置和x高给定字体 [英] How to get ascender/descender and x height for a given font

查看:128
本文介绍了如何获得伸/下降装置和x高给定字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个伸部 /的下伸和的 x高度 ..

I need to get a ascender/descender and x-height..

通过使用以下code我能找到的下降段,总高度:

By using following code I can find the descender and the total 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高度,但你可以使用一个技巧会像下面。此外,对于总高度,你从最高伸谈​​论的绝对距离到最低下降装置?我还包含一些为如下。我没有测试这些我自己,但它应该工作(但我知道,如果我misinter preting什么事你说):

I would think the ascender and descender height would typically be the same, but I wouldn't depend on it for every font. I don't really see a direct way to get to the x-height, but a trick you could use would be something like the below. Also, for the total height, are you talking about the absolute distance from the highest ascender to the lowest descender? I've also included something for that below. I haven't tested these myself, but it should work (but let me know if I'm misinterpreting something you've said):

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

这篇关于如何获得伸/下降装置和x高给定字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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