字符串长度以缇为单位java [英] String length in twips java

查看:168
本文介绍了字符串长度以缇为单位java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 twips 中获取字符串长度?
java实现会很好。

Is there a way to get the string length in twips? java implementation would be good.

推荐答案

你可以得到一个char或String的宽度,显示在某个字体, FontMetrics.stringWidth()。这应该是Points中的大小。一个点等于20缇。

You can get the width of a char or String, displayed in a certain font, with FontMetrics.stringWidth(). This should be the size in Points. A point is equal to 20 twips.

所以这应该有效:

Font font = new Font("Arial", Font.PLAIN, 10);
FontMetrics fm = new FontMetrics(font);
int widthInTwips = fm.stringWidth("Hello World") * 20;

这篇关于字符串长度以缇为单位java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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