How to add cut out part of an overlapping shape?

16 views
Skip to first unread message

Ryan

unread,
Jan 13, 2020, 5:27:15 PM1/13/20
to pdfne...@googlegroups.com
Question:
How to add cutouts to a shape so the underlying graphics of the page show through?

Something like the following, where the circle cuts out the rectangle?

Capture.PNG



Answer:

You want to use Winding so the inner fills are not filled. Essentially the Winding setting takes care of clipping for you. See the attached C# code for working example. Below is code snippet.

writer.Begin(page, ElementWriter.WriteMode.e_overlay);

builder
.PathBegin();

// draw rectangle
builder
.MoveTo(200, 500);
builder
.LineTo(500, 500);
builder
.LineTo(500, 300);
builder
.LineTo(200, 300);
builder
.LineTo(200, 500);

// draw cutout
builder
.MoveTo(400, 400);
builder
.CurveTo(400, 427.614, 377.614, 450, 350, 450);
builder
.CurveTo(322.386, 450, 300, 427.614, 300, 400);
builder
.CurveTo(300, 372.386, 322.386, 350, 350, 350);
builder
.CurveTo(377.614, 350, 400, 372.386, 400, 400);

// add additional cutouts here
// ..

Element element = builder.PathEnd();
element
.SetWindingFill(false); // Important! to get the cutouts correct
element
.SetPathStroke(false);
element
.SetPathFill(true);
GState gs = element.GetGState();
gs
.SetFillColorSpace(ColorSpace.CreateDeviceCMYK());
gs
.SetFillColor(new ColorPt(1, 0, 0, 0)); // cyan
writer
.WriteElement(element);

writer
.End();


ElementBuilderTest.cs.txt
Reply all
Reply to author
Forward
0 new messages