private static void appendPath(PdfCanvas target, PdfPath path) { foreach (PdfSubpath subpath in path.Subpaths) { foreach (PdfPathSegment segment in subpath.Segments) { switch (segment.Type) { case PdfPathSegmentType.Point: target.CurrentPosition = ((PdfPointSegment)segment).Value; break; case PdfPathSegmentType.Line: PdfLineSegment line = (PdfLineSegment)segment; target.CurrentPosition = line.Start; target.AppendLineTo(line.End); break; case PdfPathSegmentType.Bezier: PdfBezierSegment bezier = (PdfBezierSegment)segment; target.CurrentPosition = bezier.Start; target.AppendCurveTo(bezier.FirstControl, bezier.SecondControl, bezier.End); break; case PdfPathSegmentType.Rectangle: target.AppendRectangle(((PdfRectangleSegment)segment).Bounds); break; case PdfPathSegmentType.CloseSubpath: target.ClosePath(); break; } } } }
private static void toGdiPath(PdfPath path, GraphicsPath gdiPath) { foreach (PdfSubpath subpath in path.Subpaths) { gdiPath.StartFigure(); foreach (PdfPathSegment segment in subpath.Segments) { switch (segment.Type) { case PdfPathSegmentType.Point: // A singlepoint open subpath produces no output. break; case PdfPathSegmentType.Line: PdfLineSegment line = (PdfLineSegment)segment; gdiPath.AddLine(line.Start.ToPointF(), line.End.ToPointF()); break; case PdfPathSegmentType.Bezier: PdfBezierSegment bezier = (PdfBezierSegment)segment; gdiPath.AddBezier(bezier.Start.ToPointF(), bezier.FirstControl.ToPointF(), bezier.SecondControl.ToPointF(), bezier.End.ToPointF() ); break; case PdfPathSegmentType.Rectangle: RectangleF rect = ((PdfRectangleSegment)segment).Bounds.ToRectangleF(); // GDI+ does not render rectangles with negative or very small width and height. Render such // rectangles by lines, but respect direction. Otherwise non-zero winding rule for // path filling will not work. gdiPath.AddLines(new PointF[] { rect.Location, new PointF(rect.X + rect.Width, rect.Y), new PointF(rect.X + rect.Width, rect.Y + rect.Height), new PointF(rect.X, rect.Y + rect.Height), rect.Location }); break; case PdfPathSegmentType.CloseSubpath: gdiPath.CloseFigure(); break; } } } }