|Calculate minimal width of text in shape [message #698875]
||Wed, 20 July 2011 12:14
| Joerg Reichert
Registered: July 2009
My context: I create a shape with an icon and (multi-)text in the AddFeature and I want to set the width of the shape according to the length of the text. Is there already a Graphiti function for doing that?
My current approach is to multiply the text length with a certain factor but this works out not very well. I found another approch by using FontMetrics in another Eclipse forum post, but do not know how to get a drawable from a Graphiti shape.
GC gc = new GC(drawable);
FontMetrics fontMetrics = gc.getFontMetrics();
int width = fontMetrics.getAverageCharWidth() * text.toCharArray().length;
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Powered by FUDForum
. Page generated in 0.02760 seconds