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.