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

Drawing order while using Brush filled Paths and Draw string
https://forum.pdfsharp.net/viewtopic.php?f=3&t=2489
Page 1 of 1

Author:  romias [ Sat Jun 22, 2013 6:14 pm ]
Post subject:  Drawing order while using Brush filled Paths and Draw string

I have a method to draw a rectangle with rounded corners using XGraphicPath and as XGraphics doesn't have the FillPath() method, I'm using an overload of the DrawPath() method that allows to provide a Brush.

Then, I draw some strings on top of the rectangled filled with a gradient brush.

The ISSUE is that my text is not visible, when filling the Path... if I remove the filling brush, the text appears... so I'm assuming the the text is BEHIND.

My code is as follow:

Code:
      public static void DrawFilledRoundRect(ref XGraphics g, XPen p, int x, int y, int width, int height, int radius, XColor color1, XColor color2, XLinearGradientMode orientation)
      {
         var gp = new XGraphicsPath();
         gp.FillMode = XFillMode.Winding;
         gp.AddLine(x + radius, y, x + width - (radius * 2), y);
         gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90);
         gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2));
         gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90);
         gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height);
         gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
         gp.AddLine(x, y + height - (radius * 2), x, y + radius);
         gp.AddArc(x, y, radius * 2, radius * 2, 180, 90);
         gp.CloseFigure();

         var b = new XLinearGradientBrush(new XRect(x, y, width, height), color1, color2, orientation);
         g.DrawPath(p, b, gp); // this could be the problem since using g.DrawPath(p,gp) shows text.
         
      }


After calling this method, I'm doing:

Code:
g.DrawString("XXXXXX", font, XBrushes.Black, new XRect(same as what is calling in the previous method));


The XGraphics object is the same... passed as reference explicilty just to be sure.

Any idea of what is going here?
I don't know what does PDFSharp behind scenes, but the code is working fine on plain GDI+.

I'm generating a PDF from GDI+ in ASP.NET MVC.

Author:  romias [ Sat Jun 22, 2013 9:23 pm ]
Post subject:  Re: Drawing order while using Brush filled Paths and Draw st

Follow up:

I just realized this has something to do with the use of XLinearGradientBrush.

If I do a more simpler code it works fine (red background and the lettes in the rectangle):
Code:
g.DrawRectangle(XPens.Black, XBrushes.Red, x, y, w, h);


But if I use a XLinearGradientBrush, it doesn't display the letters in the rectangle:

Code:
var myLinearGradientBrush = new XLinearGradientBrush(new XRect(x, y, w, h), color1, color2, XLinearGradientMode.Vertical);
g.DrawRectangle(XPens.Black, myLinearGradientBrush, x, y, w, h);


Any idea?

So far I will use just plain colors instead of gradients, but it could be nice to have the gradients back :)

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