Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ShapeNode - getting wrapped text lines (Read 4845 times)
Z
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Mar 9th, 2017
ShapeNode - getting wrapped text lines
Mar 13th, 2017 at 8:52am
Print Post  
Hi All,

Is there any possibility to get lines of wrapped text from ShapeNode?

I have found some extension method for TextBlock using ContentStart property (TextPointer).
Unfortunatelly ShapeNode does not expose ContentStart property and it is impossible to get access to TextPointer:
  var myTextPointer = myTextBlock.ContentStart.GetPositionAtOffset(...)

As a consequence, there is not possible to call another TextPointer methods:
  myTextPointer.GetLineStartPosition(...)
  myTextPointer.GetOffsetToPosition(...)

Is it possible to extend ShapeNode somehow to retrieve wrapped text lines?

Thanks in advance for any advice.

Z
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: ShapeNode - getting wrapped text lines
Reply #1 - Mar 13th, 2017 at 9:14am
Print Post  
Hi,

The control draws text using DrawingContext.DrawText(FormattedText) method and there are no TextBlocks involved.

If you use regular texts (EnableStyledText and PolygonalTextLayout are disabled) you could set up a FormattedText object with same font attributes as the node, and same layoutSize as the node minus TextPadding, then try using FormattedText API to get information about lines, e.g. check the FormattedText.GetMaxTextWidths.

If you use EnableStyledText or PolygonalTextLayout properties, the text lines are stored in internal data structures - we could implement some public methods to let you access them for next release.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Z
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Mar 9th, 2017
Re: ShapeNode - getting wrapped text lines
Reply #2 - Mar 13th, 2017 at 12:56pm
Print Post  
Hi Slavcho,

Thanks for quick reply.

FormattedText would be OK except the fact that layout properties (Width and Height) are read only.
Apart from that the constructor is a bit complex.

Workaround using TextBlock seems to be similar (but a bit simpler IMO) and requires three steps:
- preparing TextBlock with all font attributes taken from ShapeNode (as you suggested with FormattedText)
- finding the Grid ancestor of the actual ShapeNode (fortunatelly it is a Grid) and temporairly add this newly created TextBlock to this parent grid's children
- calculate TextBlock lines using following extension:
http://stackoverflow.com/questions/30378441/get-the-lines-of-the-textblock-accor...

For now it works correctly, but of course it would be great if MindFusion would add native public method (e.g. GetTextLines()) to the ShapeNode.
BTW, when the next release is planned?
Should I open a formal ticket with such requirement? Where?

Once again, thanks for help.

Z
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: ShapeNode - getting wrapped text lines
Reply #3 - Mar 13th, 2017 at 5:37pm
Print Post  
Hi,

The diagram sets MaxTextWidth and MaxTextHeight values of FormattedText to the ones from node's size. Width and Height return the actual dimensions of arranged text after that. You can post requests in Feature Requests section of the forum.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: ShapeNode - getting wrapped text lines
Reply #4 - Mar 21st, 2017 at 5:10pm
Print Post  
You can find ShapeNode.TextLines property implemented here -
https://mindfusion.eu/_beta/wpfdiag_textlines.zip

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Z
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Mar 9th, 2017
Re: ShapeNode - getting wrapped text lines
Reply #5 - Apr 27th, 2017 at 1:46pm
Print Post  
Hi Slavcho,

Thank you for your quick reply. Unfortunatelly I haven't received an e-mail so I wasn't aware, that the beta version has already been prepared.
Appreciate, that MF implemented this funcitonality so quickly.

I have tried using your libraries, but wasn't able to test it. Please find attached a simple solution (no libs).
On the right, there is an ItemsControl with 'TextLines' comming from ShapeNode (with wrapped text).

When you try to resize the node, there will be 'NullReferenceException' somewhere 'inside' TextLines.

Rregards,
Z
  

MindFusionMultiline.zip ( 9 KB | 206 Downloads )
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: ShapeNode - getting wrapped text lines
Reply #6 - Apr 28th, 2017 at 9:55am
Print Post  
Hi Z,

New build at https://mindfusion.eu/_beta/wpfdiag343.zip should fix it.

Btw. the Width and Height properties you set in the project are derived from FrameworkElement and the control does not use them, but they lead to some strange clipping when you resize the node. Set the Bounds property instead when you need to specify size.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Z
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Mar 9th, 2017
Re: ShapeNode - getting wrapped text lines
Reply #7 - Apr 28th, 2017 at 10:30am
Print Post  
Hi Slavcho,

Looks much better, thanks.

The only thing is that there seems to be too many 'empty lines' when the string contains 'Return' sign (see attached picture).

Regards,
Z
  

Multiline.PNG ( 51 KB | 135 Downloads )
Multiline.PNG
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: ShapeNode - getting wrapped text lines
Reply #8 - Apr 28th, 2017 at 10:41am
Print Post  
You might be getting an extra empty line because of the \r\n-s at the end of non-empty ones being drawn by listbox items. Try clearing them using value converters or by replacing the results returned by TextLines.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint