rana123 rana123 - 12 days ago 5x
HTML Question

String length in twips java

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


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;