|
Re: Measuring text [message #649406 is a reply to message #649066] |
Wed, 19 January 2011 07:20 |
Viliam Durina Messages: 13 Registered: July 2009 |
Junior Member |
|
|
Maybe you could go with, but I did not test:
GC gc = new GC(Display.getDefault());
You need GC to set the font, color, style etc., and then measure the texts. Don't forget to dispose the gc.
Viliam
On 17.1.2011 14:34, Greg Brown wrote:
> I'm looking for the equivalent of AWT's Font#getLineMetrics() and Font#getStringBounds() in AWT. I have seen this snippet:
>
> http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.swt.sn ippets/src/org/eclipse/swt/snippets/Snippet55.java?view=mark up&content-type=text%2Fvnd.viewcvs-markup&revision=H EAD
>
> but it appears to require the existence of a GC in order to measure the text. Is there any way to determine the size of a string without a GC? Specifically, I need this information in order to perform layout calculations, which occur before the GC is created for painting.
>
> If there is no existing public API for this, what is the recommended practice? In other words, how might I best simulate the behavior of AWT's getFontMetrics() and getStringBounds()?
>
> Thanks,
> Greg
>
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04420 seconds