PDFsharp & MigraDoc Foundation

ExcludeClip in PDFSharp.Drawing.XGraphics?
Page 1 of 1

Author:  inexorabletash [ Sun Mar 24, 2013 12:01 am ]
Post subject:  ExcludeClip in PDFSharp.Drawing.XGraphics?

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.

Author:  rtseuztz [ Thu Jun 30, 2022 9:36 pm ]
Post subject:  Re: ExcludeClip in PDFSharp.Drawing.XGraphics?

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

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

      c. call

      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.
    clipPath.FillMode = XFillMode.Alternate

    5. Call the intersect clip on your XGraphics object with this clip path.

    6. Draw the final shape with your XGraphics object. This should be the same shape you added in step 3.
    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.

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 1373 times ]

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group