PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Sep 29, 2022 8:37 am

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: Sun Mar 24, 2013 12:01 am 
Offline

Joined: Sat Mar 23, 2013 11:48 pm
Posts: 11
Basically, a request for implementation of XCombineMode.Exclude support so that XGraphics.ExcludeClip can be implemented.

I use the GDI+ build and target GDI+ and PDF.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 30, 2022 9:36 pm 
Offline

Joined: Thu Jun 30, 2022 9:21 pm
Posts: 1
I have spent about a week figuring out how to do this and I finally have. To simulate an exclude path,
    1. Make an XGraphicsPath
    2. Add the shapes you want removed from the final shape. ex:
    Code:
    clipPath.AddRectangle(temp.X , temp.Y , width , height)

      * If these shapes are overlapping, this will not work as the overlaps will be filled in
      ** For paths/polygons, instead of adding paths to the clip path, you should:
      a. call
      Code:
      clipPath.StartFigure()

      b. Add all of the lines from your path/polygon into the clip path.
      Code:
      clipPath.AddLine(oldPoint, newPoint)

      c. call
      Code:
      clipPath.CloseFigure()

      d. Do this for each path you have.
    3. Add the final shape to the clip path. I have a big rectangle I'm cutting smaller rectangles out of, so now I'll add my large rectagle.
    4. Set the clip path's fill mode to alternate. This is the even-odd fill that SVGs and other stuff has.
    Code:
    clipPath.FillMode = XFillMode.Alternate

    5. Call the intersect clip on your XGraphics object with this clip path.
    Code:
    gfx.IntersectClip(clipPath)

    6. Draw the final shape with your XGraphics object. This should be the same shape you added in step 3.
    Code:
    gfx.DrawRectangle(xPen, xBrush, bigRect.X, bigRect.Y, bigWidth, bigHeight)
Now you will have your small shapes cut out of your large shape!
You can also call gfx.Save() before clipping and gfx.Restore() after drawing the final rectangle if you want.
I am 9 years late but hopefully this helps others.


Attachments:
File comment: Large shape with small paths cut out of it. Its a blurry picture but it is under 256 KB
Nature_celebrating_India-9 (3)-min_page-0001-min.jpg
Nature_celebrating_India-9 (3)-min_page-0001-min.jpg [ 38.01 KiB | Viewed 330 times ]
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 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