Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Text in a Box (Read 2311 times)
Henry
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 18
Joined: Feb 11th, 2008
Text in a Box
Aug 12th, 2009 at 12:01pm
Print Post  
Hi,

i must display some text in a ShapeNode, this text is too long to show this in a Node. There are no blancs in this Text an i can't use any line breaks.
The Node dont't diaplay any Text, it is empty!

I think i need a word-cut-methode, better a function wich calculate me the length in px for the Text so that i can cut this Text (with ... at the end).

Is there any solutions for this?

greeting
Henry
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Text in a Box
Reply #1 - Aug 12th, 2009 at 1:24pm
Print Post  
You can enable character wrapping by calling setWrapAtCharacter on the TextFormat object associated with the node and passing true as an argument. The following code illustrates this:

Code
Select All
node.getTextFormat().setWrapAtCharacter(true); 


Meppy
  
Back to top
 
IP Logged
 
Henry
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 18
Joined: Feb 11th, 2008
Re: Text in a Box
Reply #2 - Aug 12th, 2009 at 1:51pm
Print Post  
hi,

i don't want do brake the words, i want to cut the words on this point.
If i don't cut, the ShapeNode draws me nothing, no Text is to see if it larger tha the free space. I must use one word.
I have looked that i can calculate how many chars can i place in my box, but i need the FontRenderContext for this option an i dont have it.

Code
Select All
private String trimToPx(String iText, ShapeNode iNode) {
  Rectangle2D bounds =
    bNode.getFont().getStringBounds(iText, <here i need the FontRenderContex>);
  while (iNode.getBounds().width < bounds.getWidth()) {
    iText = iText.substring(1,iText.length()-1);
    bounds =
      bNode.getFont().getStringBounds(iText+"...", <here i need the FontRenderContex>);
  }
  return iText;
}
 



greetings
henry
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Text in a Box
Reply #3 - Aug 12th, 2009 at 3:35pm
Print Post  
Hi,

You could use Diagram.measureString to measure the string considering the current transforms applied to the diagram.

You might also try to assign to the node a TextFormat object whose NoWrap attribute is set to true. This should draw the text on one line and clip it if it's too long.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Henry
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 18
Joined: Feb 11th, 2008
Re: Text in a Box
Reply #4 - Aug 17th, 2009 at 12:21pm
Print Post  
Hi,

Diagram.measureString is perfekt!

thx
Henry
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint