PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

XGraphicsPath.Widen(...) broken in latest stable and beta
https://forum.pdfsharp.net/viewtopic.php?f=3&t=3286
Page 1 of 1

Author:  stefan.at.wpf [ Thu Feb 04, 2016 4:53 pm ]
Post subject:  XGraphicsPath.Widen(...) broken in latest stable and beta

For me the XGraphicsPath.Widen seems to be broken.

Given this original path:
Attachment:
pdfsharp_original.jpg
pdfsharp_original.jpg [ 11.56 KiB | Viewed 5471 times ]


I tried with XGraphicsPath.Widen(...) on both, Pdfsharp 1.32.3057 as well as 1.50.4000-beta3b.
Used code can be found at the end of this post.

On Pdfsharp 1.32.3057 the result looks as follows:
Attachment:
pdfsharp_stable.jpg
pdfsharp_stable.jpg [ 33.99 KiB | Viewed 5471 times ]


On Pdfsharp 1.50.4000-beta3b the widen method seems to do nothing, the result looks as follows:
Image

Here is the code I used:
Code:
        private XPoint cmPoint(double x, double y)
        {
            return new XPoint(
                XUnit.FromCentimeter(x),
                XUnit.FromCentimeter(y)
                );
        }


        private XGraphicsPath getMyPath2()
        {
            XGraphicsPath path = new XGraphicsPath();
                       
            path.AddLine(cmPoint(0, 0), cmPoint(5, 2));
            path.AddLine(cmPoint(5, 2), cmPoint(10, 0));
            path.AddLine(cmPoint(10, 0), cmPoint(10, 10));
            path.AddLine(cmPoint(10, 10), cmPoint(0, 10));
            path.CloseFigure();

            return path;
        }
       

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            // Create a temporary file
            string filename = String.Format("{0}_tempfile.pdf", Guid.NewGuid().ToString("D").ToUpper());

            XPen penBlack = new XPen(XColors.Black, 1);
            XPen penRed = new XPen(XColors.Red, 1);

            PdfDocument pdfDocument = new PdfDocument();

            PdfPage page = pdfDocument.AddPage();
            page.Size = PdfSharp.PageSize.A1;

            XGraphics gfx = XGraphics.FromPdfPage(page);

            //give us some space to the left and top
            gfx.TranslateTransform(XUnit.FromCentimeter(3), XUnit.FromCentimeter(3));

            XGraphicsPath path = getMyPath2();
            gfx.DrawPath(penBlack, path);

            path.Widen(new XPen(XColors.Red, XUnit.FromCentimeter(1)));
            gfx.DrawPath(penRed, path);

            // Save the pdfDocument...
            pdfDocument.Save(filename);
            // ...and start a viewer
            Process.Start(filename);
        }


Expected result:
The result of Pdfsharp 1.32.3057, but without these weird triangles.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/