加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 图形字符串的起源在哪里开始?

发布时间:2020-12-15 04:56:41 所属栏目:Java 来源:网络整理
导读:在核心 Java书中,它说 The width of the rectangle that the getStringBounds method returns is the horizontal extent of the string. The height of the rectangle is the sum of ascent,descent,and leading. The rectangle has its origin at the basel
在核心 Java书中,它说

The width of the rectangle that the getStringBounds method returns is the horizontal
extent of the string. The height of the rectangle is the sum of ascent,descent,and
leading. The rectangle has its origin at the baseline of the string. The top y -coordinate of the rectangle is negative. Thus,you can obtain string width,height,and
ascent as follows:

double stringWidth = bounds.getWidth();
double stringHeight = bounds.getHeight();
double ascent = -bounds.getY();

当说矩形的原点位于字符串的基线时,作者的意思是什么,而顶部的y坐标是上升?

字符串的边界矩形从哪里开始?

用测试字符串我得到以下内容:

w: 291.0
h: 91.265625
x:0.0
y:-72.38671875
descent: 15.8203125
leading: 3.0585938

这意味着矩形原点位于前导而不是基线,我对此是否正确?

解决方法

数学计算出来了:

72.38671875上升15.8203125下降3.0585938领先= 91.265625总高度

This tutorial on 2D Text有一个图像说明领先,下降和上升.

在您的具体情况下,72.38671875是上升的高度.这是从基线到最高雕文顶部的测量值.前导是下行器底部到下一行顶部之间的空间.

边界矩形相对于基线. FontMetrics.getStringBounds的API指出“返回的边界是基线相对坐标”,它解释了您的结果. x将始终为0,并且边界框的高度将是上升加上下降加上前导.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读