PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 7:57 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Feb 02, 2010 2:28 pm 
Offline

Joined: Mon Jan 04, 2010 2:44 pm
Posts: 23
Code:
using PdfSharp.Drawing;
using PdfSharp.Pdf;

namespace PDFSharpTest {
    class Program {
        static void Main(string[] args) {
            // Initialize drawing tools and variables
            PdfDocument doc = new PdfDocument();
            PdfPage page = doc.AddPage();
            XGraphics canvas = XGraphics.FromPdfPage(page);
            XFont font = new XFont("Arial", 10);
            XStringFormat format = new XStringFormat();
            format.Alignment = XStringAlignment.Near;
            string text = "Test string that\ncontains two\nline-feeds.";
            XPoint origin = new XPoint(72, 72);

            // Measure the text we're about to draw,
            XSize size = canvas.MeasureString(text, font);
            // draw a red rectangle,
            canvas.DrawRectangle(XPens.Red, new XRect(origin, size));
            // and draw the text within that rectangle.
            canvas.DrawString(text, font, XBrushes.Black, origin, format);

            doc.Save("test.pdf");
        }
    }
}
The above code does not do what the comments suggest it does. To whit, it measures the text and draws a red rectangle, but then it draws the majority of the text outside that rectangle. The PDF it generates is attached.

Is a case of DrawString handling control characters incorrectly, or merely a case of me not reading the documentation properly?


Attachments:
test.zip [1.32 KiB]
Downloaded 289 times
Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 03, 2010 9:08 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
This was already reported, but isn't resolved yet.
See also here:
viewtopic.php?p=2695#p2695

The GDI build (see also here: viewtopic.php?f=2&t=832 ) uses Graphics.MeasureString.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 08, 2010 9:39 pm 
Offline

Joined: Mon Jan 04, 2010 2:44 pm
Posts: 23
Thanks. I had gotten the idea somehow that that report had gotten lost in the noise while you were on vacation. Also, I wanted to make sure that there was a simple, self-contained test case; I know I like them better than more abstract ones where I have to add the right prologue and epilogue code.


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 09, 2010 8:52 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
DaleStan wrote:
Also, I wanted to make sure that there was a simple, self-contained test case

Good idea. But you don't mention if this occurs with a GDI build or a WPF build or both.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 09, 2010 2:36 pm 
Offline

Joined: Mon Jan 04, 2010 2:44 pm
Posts: 23
Oops. So I didn't. This happens in both builds of version 1.31, as downloaded from SF.net.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 411 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