Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Font Size In Pixels
Font Size In Pixels [message #568176] Fri, 10 September 2010 14: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. :)
Re: Font Size In Pixels [message #568205 is a reply to message #568176] Mon, 13 September 2010 08: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 #568233 is a reply to message #568176] Mon, 13 September 2010 12: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 #569613 is a reply to message #568176] Wed, 15 September 2010 08: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 #569636 is a reply to message #569613] Thu, 16 September 2010 13: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:Font Size In Pixels
Next Topic:Searching For Linked PictogramElements Given An EObject
Goto Forum:
  


Current Time: Sat Oct 25 20:02:01 GMT 2014

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

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