Select to view content in your preferred language

Calculating the width for a TextSymbol

2946
2
08-20-2015 08:23 AM
GabrielUnmüßig
Deactivated User

Is there a way to get or calculate the displayed width of a TextSymbol? The TextSymbol.getWidth() method returns 0 because the geometry is a point. Im trying to draw selection markers around the symbol.

Text.png

0 Kudos
2 Replies
EricBader
Honored Contributor

Interesting.

Have you tried doing something with getting the font size from the text symbol and finding the length of the String value returned from TextSymbol.getText()?

I wonder if evaluating these two variables would give you a rough guesstimate if the size of the symbol.

0 Kudos
GabrielUnmüßig
Deactivated User

If tried that. The markers in the pictures are calculated that way. The width differs greatly for different fonts. The font size corresponds with height not width.

The font size in the pictures is 48. I've also tried to use the Java2D FontMetrics to calculate the width but the results vary from the displayed text.

5abf998f-7fb2-4cce-86f8-950c80c73e9d_1440149067006.png5abf998f-7fb2-4cce-86f8-950c80c73e9d_1440149068991.png5abf998f-7fb2-4cce-86f8-950c80c73e9d_1440149071227.png

0 Kudos