Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Text Wrapping in not working in custom shape node (Read 5403 times)
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Text Wrapping in not working in custom shape node
Dec 29th, 2010 at 1:58pm
Print Post  
Hi Stoyan,

We are using CustomShaped ShapeNode in our application. In this shape we have one TextRegion defined which is outer left side of the node that contains the text of the node. Defination of shape is:
textAtTheLeft = new MindFusion.Diagramming.Wpf.Shape(
               Shapes.Rectangle.Outline,// reuse the rectangular shape
               null,// no decorations
               //Rohit: Perf changed
               new ElementTemplate[]// define text region
                   {
                       new LineTemplate(-300, 19, -50, 19),
                       new LineTemplate(-50, 19, -50, 79),
                       new LineTemplate(-50, 79, -300, 79),
                       new LineTemplate(-300, 79, -300, 19)
                   },
                   FillRule.EvenOdd,// doesn't matter here
                   "textAtTheLeft"// to access the shape later using Shape.FromId
               );

Since we are assigning text at runtime so if text length is higher than the TextArea length then we want
Either TextArea gets increase so that it can contain the whole text
Or TextArea remain the same but text get wrapped and come in two or more lines.


We have tried to increase the TextArea at runtime but it has not solved our problem. We have tried with following snippet:
Size size = diagram.MeasureString((node.Text, node, 600);
double textAreaW = size.Width * 4; // the width of the text area

node.TextTrimming = TextTrimming.None;
textAreaW = (-1 * textAreaW) - 240;
node.Shape.TextArea = new ElementTemplate[] {
new LineTemplate(textAreaW, 19, -50, 19),                     new LineTemplate(-50, 19, -50, 79),
new LineTemplate(-50, 79, textAreaW, 79),
                     new LineTemplate(textAreaW, 79, textAreaW, 19)};
node.TextAlignment = TextAlignment.Right;
              
Please suggest to resolve this issue.

Regards,
Bala
  
Back to top
 
IP Logged
 
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Re: Text Wrapping in not working in custom shape n
Reply #1 - Jan 3rd, 2011 at 5:10am
Print Post  
Hi,

Any update for above post?

Regards,
Bala
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Text Wrapping in not working in custom shape n
Reply #2 - Jan 3rd, 2011 at 12:57pm
Print Post  
The size of the text area is relative to the size of its containing node. Therefore assigning the value returned by the MeasureString as the width of the area will be interpreted incorrectly - as a percentage of the node's width. Instead you have to perform manual calculations of the text width expressed as a percentage of the node's width:

Code
Select All
Size size = diag.MeasureString(text, node, 600);
double padding = 5;
double areaWidth = size.Width * 100 / node.Bounds.Width + 50 + 2 * padding;

node.Shape.TextArea = new ElementTemplate[]
{
      new LineTemplate(-areaWidth, 19, -50, 19),
      new LineTemplate(-50, 19, -50, 79),
      new LineTemplate(-50, 79, -areaWidth, 79),
      new LineTemplate(-areaWidth, 79, -areaWidth, 19)
}; 


I have also added text padding as well as the hard-coded distance between the text area and the node - 50.

On a side note, resizing the node will cause the text area to get resized as well, so you may have to perform additional calculations when nodes get resized.

Let me know if this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Re: Text Wrapping in not working in custom shape n
Reply #3 - Jan 4th, 2011 at 10:12am
Print Post  
Hi Stoyan,

Thanks for the reply.

Tried the given solution but unfortunately it has not solved our problem.

Could you please suggest bit more on it.

Regards,
Bala
  
Back to top
 
IP Logged
 
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Re: Text Wrapping in not working in custom shape n
Reply #4 - Jan 6th, 2011 at 9:31am
Print Post  
Hi Stoyan,

Could you please let us know how to wrap the text?

We don't want to create new TextArea at runtime although we want that text area will remain the same and if text is larger than text will wrapped to next line. If Text length is such that it is not occupying in two complete lines than only text should be trimmed.

We have already tried following properties of node.
Node.TextTrimming = TextTrimming.None
Node.TextWrapping = TextWrapping.Wrap;

Please suggest us to resolve this issue.

Regards,
Bala
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Text Wrapping in not working in custom shape n
Reply #5 - Jan 6th, 2011 at 9:51am
Print Post  
What problem do you have with node.TextWrapping set to Wrap? It works perfectly fine from what I can see.

Stoyan
  
Back to top
 
IP Logged
 
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Re: Text Wrapping in not working in custom shape n
Reply #6 - Jan 6th, 2011 at 10:46am
Print Post  
Hi Stoyan,

Sent sample to your support id to demonstrate the issue.

Steps:
Run the application
Look at the node's text. Text is trimmed instead of wrapped in two lines than trimmed.

Requirement:
When run the application at that time also, text should be maximum visible to user.
1). If text is larger and cannot fit in the text area, than it should wrap to the second line.
2). If text is still not fit in the text area, decrease the font size till 7 and then check.
3). If still not fit than Trim the remaining text.

Please do suggest how we can achieve this?

Regards,
Bala
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Text Wrapping in not working in custom shape n
Reply #7 - Jan 6th, 2011 at 11:53am
Print Post  
Text is not wrapped because the text region has space for just a single line. Change the text-area definition elements to the following and the text will wrap on a second line:

new LineTemplate(-300, 0, -50, 0),
new LineTemplate(-50, 0, -50, 100),
new LineTemplate(-50, 100, -300, 100),
new LineTemplate(-300, 100, -300, 0)

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