Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic DrawStyledText (Read 3839 times)
nezzy
YaBB Newbies
*
Offline



Posts: 25
Joined: May 31st, 2010
DrawStyledText
Nov 12th, 2010 at 10:55am
Print Post  
Hi.
I had previously some problems with blanks and carriage return in text, and saving it to a PDF file. I was then told to use the DrawStyledText method instead of DrawString. It worked very nice.
I now seem to have problems with words that are longer than 14 characters. If the word in a senctence is longer than 14 characters it doesn't show at all in the PDF document.
Am I missing something, or is this a "feature"?
Is there a work around?
Regards
Anders
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DrawStyledText
Reply #1 - Nov 12th, 2010 at 11:53am
Print Post  
Hi,

Currently DrawStyledText is implemented like this:

Code
Select All
System.Drawing.SolidBrush textBrush = new System.Drawing.SolidBrush(TextColor);

// Parse the text
Text.StyledText styledText = new Text.StyledText();
styledText.Setup(text, graphics, font);

// Setup the alignment options
Text.LayoutOptions options = new Text.LayoutOptions();
options.Alignment = format.Alignment;
options.LineAlignment = format.LineAlignment;

// Lay out the text
Text.Layout layout = new Text.Layout();
layout.LayoutInRectangle(styledText, textBounds, options, graphics, font);

// Render it
Text.DrawTextHint hint = new Text.DrawTextHint(graphics, font, textBrush, StringFormat.GenericDefault,
(format.Trimming & StringTrimming.EllipsisWord) != 0);
layout.Draw(0, 0, new Text.RenderTextCallback(DrawText), hint);

textBrush.Dispose(); 



Create your own version of the method and add options.SplitWords = true to work around that. The classes used in the code are from the MindFusion.Text namespace in mindfusion.common.dll.

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



Posts: 25
Joined: May 31st, 2010
Re: DrawStyledText
Reply #2 - Nov 12th, 2010 at 12:29pm
Print Post  
Hi.
Thank's for a quick reply.
So it's a bug?
I am working in a large project, where creating PDF document is vital. Will this be fixed in the next release?
Regards
Anders
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DrawStyledText
Reply #3 - Nov 12th, 2010 at 12:52pm
Print Post  
The method just uses the default setting where words are never split to a second line. We could add an overload the enables that, but it won't be available soon. You can implement your own DrawStyledText version that sets that SplitWords property as shown above. And the DrawText callback should look like this by the way:

Code
Select All
private void DrawText(string text, RectangleF dest, Text.DrawTextHint hint)
{
	// Render formatted text
	hint.Graphics.DrawString(
		text, hint.Font, hint.Brush, dest.X, dest.Y, hint.Format);
} 

  
Back to top
 
IP Logged
 
nezzy
YaBB Newbies
*
Offline



Posts: 25
Joined: May 31st, 2010
Re: DrawStyledText
Reply #4 - Nov 12th, 2010 at 1:27pm
Print Post  
Hi again.
OK. I can fix this like that. But it will look differently at the PDF compared to what is shown on screen.
Thanks.
Anders
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DrawStyledText
Reply #5 - Nov 12th, 2010 at 2:02pm
Print Post  
If you mean you don't want the long words to wrap on next line but get clipped, you could try setting a clip rectangle as big as node.Bounds, but draw the text inside much wider rectangle. I suppose that should implement text clipping similar to the one in Silverlight TextBlocks.

Stoyan
  
Back to top
 
IP Logged
 
nezzy
YaBB Newbies
*
Offline



Posts: 25
Joined: May 31st, 2010
Re: DrawStyledText
Reply #6 - Nov 12th, 2010 at 2:14pm
Print Post  
Sorry, but what is a clip rectangle?
Regards
Anders
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DrawStyledText
Reply #7 - Nov 12th, 2010 at 2:30pm
Print Post  
It's what you set using the Graphics.SetClip Method (RectangleF) method. Once it is specified, no Graphics method should draw outside that rectangle.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint