Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String length in twips java

Tags:

java

html

string

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

like image 924
rana123 Avatar asked Jan 25 '26 07:01

rana123


1 Answers

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.

So this should work:

Font font = new Font("Arial", Font.PLAIN, 10);
FontMetrics fm = new FontMetrics(font);
int widthInTwips = fm.stringWidth("Hello World") * 20;
like image 108
Andreas Dolk Avatar answered Jan 26 '26 20:01

Andreas Dolk