Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Font Size In Pixels(Is there a way to compute the pixel height of a specified font?)
Font Size In Pixels [message #558220] Fri, 10 September 2010 10:43 Go to next message
Rhett Hudson is currently offline Rhett Hudson
Messages: 43
Registered: September 2010
Member
A couple times now I've run into a layout issue where I really need to know the height of a font. After poking around I found the CompartmentPattern in the examples. It has the same problem, since it's doing the same thing I want to do. It has to make layout decisions based on the size of a font. CompartmentPattern solves the problem by hard coding a pixel height.

That approach might be reasonable for some cases, but if the user has control of the typeface or the size of the font, then knowing the height when the code is compiled is tricky. Also, I imagine that font sizes (at least in physical pixels) might vary across platforms.

Is there a better solution?

Also, having seen CompartmentPattern, I'm now curious about Patterns. Smile
Re: Font Size In Pixels [message #558489 is a reply to message #558220] Mon, 13 September 2010 04:51 Go to previous messageGo to next message
Tim Kaiser is currently offline Tim Kaiser
Messages: 118
Registered: July 2009
Senior Member
Hi,

the Graphiti
org.eclipse.graphiti.mm.algorithms.styles.Font
class defines an attribute size.
You can read and modify: it's the height of the font.
Does it help?
Best, Tim

ps: regarding patterns i created a task in our backlog to provide
instructive material:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=325084
Re: Font Size In Pixels [message #558546 is a reply to message #558220] Mon, 13 September 2010 08:51 Go to previous messageGo to next message
Rhett Hudson is currently offline Rhett Hudson
Messages: 43
Registered: September 2010
Member
Thanks for your help. I noticed, after I'd asked the question, that the font sizes did seem to correspond to pixel height. So, if it's a vector font and it's being scaled, that's good for height.

I do have a portion of my graphical object whose width is dominated by the maximum width of a set of text labels. Ideally, I'd like to be able to set the default width for that rectangle so that, by default, all of the text labels are visible. Is there a way to get the "preferred width" of a text label?
Re: Font Size In Pixels [message #558975 is a reply to message #558220] Wed, 15 September 2010 04:32 Go to previous messageGo to next message
Tim Kaiser is currently offline Tim Kaiser
Messages: 118
Registered: July 2009
Senior Member
Hi,
i added a new interface
IUiLayoutService
which offers a method
calculateTextSize().
You can access it via
GraphitiUi.getUiLayoutService().

Does it work as expected?

Best regards, Tim
Re: Font Size In Pixels [message #559361 is a reply to message #558975] Thu, 16 September 2010 09:21 Go to previous message
Rhett Hudson is currently offline Rhett Hudson
Messages: 43
Registered: September 2010
Member
I believe that it does work as I expect. Thank you very much. I incorporated it into my layout and now I can read all my labels!

I should note, for those following the thread, that the size attribute of a font does not correspond to its height. My size 6 font, for instance, requires 10 pixels of height to render.

Previous Topic:Properties and Listeners
Next Topic:Font Size In Pixels
Goto Forum:
  


Current Time: Fri Aug 22 23:37:20 EDT 2014

Powered by FUDForum. Page generated in 0.01819 seconds