如何获取给定字体的上升/下降和 x 高度
通过使用以下代码,我可以找到下降部分和总高度:
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 ?
谢谢
I need to get a ascender/descender and x-height..
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 ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为上升部分和下降部分的高度通常是相同的,但我不会对每种字体都依赖它。我确实没有看到达到 x 高度的直接方法,但您可以使用如下所示的技巧。另外,对于总高度,您是在谈论从最高上升部分到最低下降部分的绝对距离吗?我还在下面添加了一些内容。我自己还没有测试过这些,但它应该有效(但如果我误解了你所说的内容,请告诉我):
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):
这对我有用:
This is what worked for me: