|
Re: Measuring text [message #649406 is a reply to message #649066] |
Wed, 19 January 2011 02:20   |
Eclipse User |
|
|
|
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
>
|
|
|
|
|
Re: Measuring text [message #649515 is a reply to message #649509] |
Wed, 19 January 2011 09:39  |
Eclipse User |
|
|
|
Hi Daniel,
Thanks for confirming that I need a GC for this. Any idea why that is? In AWT and Android, a drawing context is not necessary to measure text (though of course it is required to draw text). Just wondering what the difference might be.
Thanks,
Greg
|
|
|
Powered by
FUDForum. Page generated in 0.03778 seconds