PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed Mar 20, 2019 5:41 pm

All times are UTC

Forum rules

Please read this before posting on this forum: Forum Rules

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Jun 22, 2013 6:14 pm 

Joined: Tue May 19, 2009 2:37 pm
Posts: 7
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:

      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);

         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:

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.

Reply with quote  
PostPosted: Sat Jun 22, 2013 9:23 pm 

Joined: Tue May 19, 2009 2:37 pm
Posts: 7
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):
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:

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 :)

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

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

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