PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jul 14, 2024 10:43 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Drawstring problem
PostPosted: Thu Feb 18, 2010 3:16 pm 
Offline

Joined: Thu Feb 18, 2010 3:04 pm
Posts: 4
Hi,

when I'm using DrawString and use it in a rectangle (for example)

Code:
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
XRect rect = new XRect(100, 100, 20, 100);
gfx.DrawString("Hello, World!", font, XBrushes.Black, rect, XStringFormats.TopLeft);


no matter what the rectangle size is, it will draw on PDF the entire string.
In GDI+ it will draw only what can be seen inside the bounds of the rectangle.

And one more thing. If the string is empty or a few spaces " " it will produce error. But it should not.

Is there any way to fix this?


Top
 Profile  
Reply with quote  
 Post subject: Re: Drawstring problem
PostPosted: Thu Feb 18, 2010 3:42 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
dancer wrote:
no matter what the rectangle size is, it will draw on PDF the entire string.

The rectangle is used for alignment only, not for clipping.

Spaces should not cause problems. I must investigate this.

Which version and build do you use?
viewtopic.php?f=2&t=832

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Drawstring problem
PostPosted: Thu Feb 18, 2010 4:01 pm 
Offline

Joined: Thu Feb 18, 2010 3:04 pm
Posts: 4
Thank you very much for your answer.

this code creates problem

Code:
rect = new XRect(300, 100, 20, 100);
gfx.DrawString("      ", font, XBrushes.Black, rect, XStringFormats.BottomCenter);


the error it produces is: WidthAndHeightCannotBeNegative

The version I'm using is 1.31.1789.0

I understand what you told me about rectangle is used for alignment.
Could you, please, tell me is there any other way to draw only part of the string in the rectangle I want?

Thanks in advance


Top
 Profile  
Reply with quote  
 Post subject: Re: Drawstring problem
PostPosted: Wed Feb 24, 2010 2:17 pm 
Offline

Joined: Mon Jan 04, 2010 2:44 pm
Posts: 23
My admittedly-simplistic solution is to measure the string and chop off the last letter if it's too long.
Lather, rinse, repeat.

Depending on how many characters you generally need to drop, a binary search might be a better solution.


Top
 Profile  
Reply with quote  
 Post subject: Re: Drawstring problem
PostPosted: Tue Mar 02, 2010 12:08 pm 
Offline

Joined: Thu Feb 18, 2010 3:04 pm
Posts: 4
Thanks DaleStan for answer. Tried that already, but somehow measure string is not returning the right Size, I have no idea why. I did creating white rectangle over the part that I do not want to be visible. I Found no better solution.

Thomas, did you look at the problem when trying to draw empty string?


Top
 Profile  
Reply with quote  
 Post subject: Re: Drawstring problem
PostPosted: Sat Jan 12, 2013 8:44 am 
Offline

Joined: Sat Jan 12, 2013 8:19 am
Posts: 1
Hello,
I have the same problem during drawing strings with only whitespaces.
Is it a problem during conversion from float to double?
public static XSize FromSizeF(SizeF size) { return new XSize(size.Width, size.Height); }
public XSize(double width, double height) { ...
Any workaround?
Regards Jens

PdfSharp 1.32.2608.0


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group