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

Text disappearing when using XLinearGradientBrush: Bug?
https://forum.pdfsharp.net/viewtopic.php?f=2&t=319
Page 1 of 1

Author:  hansolav [ Sun Feb 10, 2008 3:09 am ]
Post subject:  Text disappearing when using XLinearGradientBrush: Bug?

Hi,

I believe I've found a bug that causes text to disappear when drawn with DrawString and XBrushes.Black immediately after drawing a rounded rectangle with a XLinearGradientBrush.
It could be that the bug is more general than that, but this is how I bumped into it. I'm using Pdfsharp 1.0.898.

The code below should illustrate the problem (at least it does on my machine). Try removing the DrawRoundedRectangle and see what happens.

Code:
            PdfDocument doc = new PdfDocument();
            PdfPage page = doc.AddPage();
            XGraphics gfx = XGraphics.FromPdfPage(page);

            XRect rect = new XRect(10, 10, 100, 100);
            gfx.DrawRoundedRectangle(
                new XPen(XColors.Black, 3),
                new XLinearGradientBrush(rect, XColors.Red, XColors.Green, XLinearGradientMode.Vertical),
                rect,
                new XSize(5, 5));

            gfx.DrawString("Some text that disappears", new XFont("Arial", 20), XBrushes.Black,
                new XRect(200, 200, 200, 200), XStringFormat.TopLeft);

            doc.Save("HelloWorld.pdf");
            Process.Start("HelloWorld.pdf");

Author:  lucwuyts [ Fri Jun 13, 2008 9:14 am ]
Post subject: 

I recently started using PDFSharp in a project where i need some graphics.

I seem to have the same problem with this Brush.

Did you find a solution??

Thanks,
Luc

Author:  Jaribal [ Sun Nov 10, 2013 4:58 am ]
Post subject:  Re: Text disappearing when using XLinearGradientBrush: Bug?

Hello, the text is disappearing only if it is over the XLinearGradientBrush and only if the text XBrush (foreground brush) is black.
So if you change the text brush to nearly black: new XSolidBrush(XColor.FromArgb(1,1,1)) then it works.

Author:  flagger [ Mon May 05, 2014 11:13 pm ]
Post subject:  Re: Text disappearing when using XLinearGradientBrush: Bug?

You can also workaround by saving the transformation state before using the XLinearGradientBrush and then restoring it after.

Code:
PdfDocument doc = new PdfDocument();
PdfPage page = doc.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);

XGraphicsState state = gfx.Save();
XRect rect = new XRect(10, 10, 100, 100);
gfx.DrawRoundedRectangle(
                new XPen(XColors.Black, 3),
                new XLinearGradientBrush(rect, XColors.Red, XColors.Green, XLinearGradientMode.Vertical),
                rect,
                new XSize(5, 5));
gfx.Restore(state);

gfx.DrawString("Some text that disappears", new XFont("Arial", 20), XBrushes.Black,
                new XRect(200, 200, 200, 200), XStringFormat.TopLeft);

doc.Save("HelloWorld.pdf");
Process.Start("HelloWorld.pdf");

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