PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 2:10 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 
Offline

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


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

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


Top
 Profile  
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 37 guests


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:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group