Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » determine Font pixel height outside of GC
determine Font pixel height outside of GC [message #448102] Sun, 02 January 2005 02:15 Go to next message
Chris Gross is currently offline Chris GrossFriend
Messages: 471
Registered: July 2009
Senior Member
Can you determine the height of a font (the pixel height not the point
height) without GC? I'm trying to determine the height and I'm not inside a
paint event. The only option I can see is to create my own GC just to
figure out the font pixel height. That seems not very efficient.

-Chris
Re: determine Font pixel height outside of GC [message #448103 is a reply to message #448102] Sun, 02 January 2005 06:23 Go to previous messageGo to next message
Liam Morley is currently offline Liam MorleyFriend
Messages: 47
Registered: July 2009
Member
I'm pretty sure you have to create a GC; in places where I've seen it
implemented in internal eclipse functions (if I remember correctly),
they created a GC and disposed of it immediately afterwards. I'm
presuming you're setting the GC's font, then getting the font metrics.
(Then disposing the GC.) I'm not sure how else you'd do it, because the
# of pixels is going to depend on OS, screen resolution, etc... The
javadoc for FontMetrics says "FontMetrics are obtained from GCs using
the getFontMetrics() method."


Chris wrote:
> Can you determine the height of a font (the pixel height not the point
> height) without GC? I'm trying to determine the height and I'm not inside a
> paint event. The only option I can see is to create my own GC just to
> figure out the font pixel height. That seems not very efficient.
>
> -Chris
>
>


--
Liam Morley
Computer Science Undergraduate
Worcester Polytechnic Institute
Re: determine Font pixel height outside of GC [message #448105 is a reply to message #448103] Sun, 02 January 2005 12:05 Go to previous messageGo to next message
strus is currently offline strusFriend
Messages: 113
Registered: July 2009
Senior Member
In the paint event you can get the gc used : event.gc and find the
height of the font from this GC.

Liam Morley wrote:
> I'm pretty sure you have to create a GC; in places where I've seen it
> implemented in internal eclipse functions (if I remember correctly),
> they created a GC and disposed of it immediately afterwards. I'm
> presuming you're setting the GC's font, then getting the font metrics.
> (Then disposing the GC.) I'm not sure how else you'd do it, because the
> # of pixels is going to depend on OS, screen resolution, etc... The
> javadoc for FontMetrics says "FontMetrics are obtained from GCs using
> the getFontMetrics() method."
>
>
> Chris wrote:
>
>> Can you determine the height of a font (the pixel height not the point
>> height) without GC? I'm trying to determine the height and I'm not
>> inside a paint event. The only option I can see is to create my own
>> GC just to figure out the font pixel height. That seems not very
>> efficient.
>>
>> -Chris
>>
>
>
Re: determine Font pixel height outside of GC [message #448114 is a reply to message #448103] Mon, 03 January 2005 14:36 Go to previous messageGo to next message
Chris Gross is currently offline Chris GrossFriend
Messages: 471
Registered: July 2009
Senior Member
Yeah thats what I'm doing. I'll stick to that.

Thanks,
-Chris

"Liam Morley" <lmorley@wpi.edu> wrote in message
news:cr840m$suf$1@www.eclipse.org...
> I'm pretty sure you have to create a GC; in places where I've seen it
> implemented in internal eclipse functions (if I remember correctly), they
> created a GC and disposed of it immediately afterwards. I'm presuming
> you're setting the GC's font, then getting the font metrics. (Then
> disposing the GC.) I'm not sure how else you'd do it, because the # of
> pixels is going to depend on OS, screen resolution, etc... The javadoc for
> FontMetrics says "FontMetrics are obtained from GCs using the
> getFontMetrics() method."
>
>
> Chris wrote:
>> Can you determine the height of a font (the pixel height not the point
>> height) without GC? I'm trying to determine the height and I'm not
>> inside a paint event. The only option I can see is to create my own GC
>> just to figure out the font pixel height. That seems not very efficient.
>>
>> -Chris
>
>
> --
> Liam Morley
> Computer Science Undergraduate
> Worcester Polytechnic Institute
Re: determine Font pixel height outside of GC [message #448115 is a reply to message #448105] Mon, 03 January 2005 14:36 Go to previous message
Chris Gross is currently offline Chris GrossFriend
Messages: 471
Registered: July 2009
Senior Member
Thanks. I was aware of that. Unfortunatly I am not inside a paint event.

"strus" <strus_fr@yahoo.fr> wrote in message
news:cr8o7g$h6b$1@www.eclipse.org...
> In the paint event you can get the gc used : event.gc and find the height
> of the font from this GC.
>
> Liam Morley wrote:
>> I'm pretty sure you have to create a GC; in places where I've seen it
>> implemented in internal eclipse functions (if I remember correctly), they
>> created a GC and disposed of it immediately afterwards. I'm presuming
>> you're setting the GC's font, then getting the font metrics. (Then
>> disposing the GC.) I'm not sure how else you'd do it, because the # of
>> pixels is going to depend on OS, screen resolution, etc... The javadoc
>> for FontMetrics says "FontMetrics are obtained from GCs using the
>> getFontMetrics() method."
>>
>>
>> Chris wrote:
>>
>>> Can you determine the height of a font (the pixel height not the point
>>> height) without GC? I'm trying to determine the height and I'm not
>>> inside a paint event. The only option I can see is to create my own GC
>>> just to figure out the font pixel height. That seems not very
>>> efficient.
>>>
>>> -Chris
>>>
>>
Previous Topic:Widget not being displayed
Next Topic:Example of JDNC/Swing Extensions
Goto Forum:
  


Current Time: Thu Apr 25 08:41:59 GMT 2024

Powered by FUDForum. Page generated in 0.03376 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top