Know how wide text will be on a Canvas

58 views
Skip to first unread message

Sean

unread,
Jul 5, 2012, 7:17:03 PM7/5/12
to google-we...@googlegroups.com
Hey guys, 

I was wondering if there was a way I can set the font in a canvas:
m_context.setFont("bold 12px sans-serif");

Then take some text, like Hello World! and know how many pixels wide that will be? I have a set space on my canvas, and I want to maximize the size of the text or justify it correctly. So if I know Hello World will take 50 pixels in the X-direction, but I have 75 pixels, I can start it at x+(75-50)/2.0 pixels and have it centered. 

Thanks!


Jim Douglas

unread,
Jul 5, 2012, 8:37:00 PM7/5/12
to Google Web Toolkit

Sean

unread,
Jul 6, 2012, 7:33:50 AM7/6/12
to google-we...@googlegroups.com
Ah, thank you!

Jim Douglas

unread,
Jul 6, 2012, 1:03:03 PM7/6/12
to Google Web Toolkit
Thanks for giving me a reason to go looking for it. I added the
incubator Canvas to my app a few years ago; I hadn't noticed that GWT
now includes an official Canvas implementation (as of 2.2,
apparently).

On Jul 6, 4:33 am, Sean <slough...@gmail.com> wrote:
> Ah, thank you!
>
>
>
>
>
>
>
> On Thursday, July 5, 2012 8:37:00 PM UTC-4, Jim Douglas wrote:
>
> >http://google-web-toolkit.googlecode.com/svn/javadoc/2.5/com/google/g...)
>
> >http://google-web-toolkit.googlecode.com/svn/javadoc/2.5/com/google/g...)
>
> >http://google-web-toolkit.googlecode.com/svn/javadoc/2.5/com/google/g...()
Reply all
Reply to author
Forward
0 new messages