public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); DrawGridlines(gfx); // Create a new graphical path XGraphicsPath path = new XGraphicsPath(); XSize size = new XSize(90, 140); double rotationAngle = 130; path.AddArc(new XPoint(100, 100), new XPoint(200, 200), size, rotationAngle, false, System.Windows.Media.SweepDirection.Clockwise); path.StartFigure(); path.AddArc(new XPoint(400, 100), new XPoint(500, 200), size, rotationAngle, false, System.Windows.Media.SweepDirection.Counterclockwise); path.StartFigure(); path.AddArc(new XPoint(100, 300), new XPoint(200, 400), size, rotationAngle, true, System.Windows.Media.SweepDirection.Clockwise); path.StartFigure(); path.AddArc(new XPoint(400, 300), new XPoint(500, 400), size, rotationAngle, true, System.Windows.Media.SweepDirection.Counterclockwise); path.StartFigure(); #if DEBUG_ gfx.WriteComment("PathArcSegment"); #endif gfx.DrawPath(XPens.Red, path); }
protected override void OnRender(PdfRendererContext ctx, Panel panel) { if (panel.BackgroundColor.A == 0 && panel.Border.Color.A == 0) { return; } var brush = panel.BackgroundColor.A > 0 ? new XSolidBrush(panel.BackgroundColor.ToXColor()) : null; var pen = panel.Border.Size > 0 ? new XPen(panel.Border.Color.ToXColor(), panel.Border.Size) : null; var radius = panel.ActualRadius; var path = new XGraphicsPath { FillMode = XFillMode.Alternate }; var shift = panel.Border.Size * 0.5f; var rect = new RectangleF(panel.BorderLayout.X + shift, panel.BorderLayout.Y + shift, panel.BorderLayout.Width - 2 * shift, panel.BorderLayout.Height - 2 * shift); path.AddLine(rect.X + radius.TopLeft, rect.Y, rect.Right - radius.TopRight, rect.Y); if (radius.TopRight > 0) { path.AddArc(rect.Right - 2 * radius.TopRight, rect.Y, 2 * radius.TopRight, 2 * radius.TopRight, 270, 90); } path.AddLine(rect.Right, rect.Y + radius.TopRight, rect.Right, rect.Bottom - radius.BottomRight); if (radius.BottomRight > 0) { path.AddArc(rect.Right - 2 * radius.BottomRight, rect.Bottom - 2 * radius.BottomRight, 2 * radius.BottomRight, 2 * radius.BottomRight, 0, 90); } path.AddLine(rect.Right - radius.BottomRight, rect.Bottom, rect.X + radius.BottomLeft, rect.Bottom); if (radius.BottomLeft > 0) { path.AddArc(rect.X, rect.Bottom - 2 * radius.BottomLeft, 2 * radius.BottomLeft, 2 * radius.BottomLeft, 90, 90); } path.AddLine(rect.Left, rect.Bottom - radius.BottomLeft, rect.Left, rect.Top + radius.TopLeft); if (radius.TopLeft > 0) { path.AddArc(rect.Left, rect.Top, 2 * radius.TopLeft, 2 * radius.TopLeft, 180, 90); } path.CloseFigure(); if (pen != null && brush != null) { ctx.Graphics.DrawPath(pen, brush, path); } else if (pen != null) { ctx.Graphics.DrawPath(pen, path); } else { ctx.Graphics.DrawPath(brush, path); } }
public override void ArcTo(double x, double y, double size, Corner corner) { float left = (float)(Math.Min(x, _lastPoint.X) - (corner == Corner.TopRight || corner == Corner.BottomRight ? size : 0)); float top = (float)(Math.Min(y, _lastPoint.Y) - (corner == Corner.BottomLeft || corner == Corner.BottomRight ? size : 0)); _graphicsPath.AddArc(left, top, (float)size * 2, (float)size * 2, GetStartAngle(corner), 90); _lastPoint = new RPoint(x, y); }
internal void Render(XUnit x, XUnit y, XUnit width, XUnit height, RoundedCorner roundedCorner) { // If there is no rounded corner, we can use the usual Render method. if (roundedCorner == RoundedCorner.None) { Render(x, y, width, height); return; } if (_shading == null || _brush == null) { return; } XGraphicsPath path = new XGraphicsPath(); switch (roundedCorner) { case RoundedCorner.TopLeft: path.AddArc(new XRect(x, y, width * 2, height * 2), 180, 90); // Error in CORE: _corePath.AddArc(). path.AddLine(new XPoint(x + width, y), new XPoint(x + width, y + height)); break; case RoundedCorner.TopRight: path.AddArc(new XRect(x - width, y, width * 2, height * 2), 270, 90); // Error in CORE: _corePath.AddArc(). path.AddLine(new XPoint(x + width, y + height), new XPoint(x, y + height)); break; case RoundedCorner.BottomRight: path.AddArc(new XRect(x - width, y - height, width * 2, height * 2), 0, 90); // Error in CORE: _corePath.AddArc(). path.AddLine(new XPoint(x, y + height), new XPoint(x, y)); break; case RoundedCorner.BottomLeft: path.AddArc(new XRect(x, y - height, width * 2, height * 2), 90, 90); // Error in CORE: _corePath.AddArc(). path.AddLine(new XPoint(x, y), new XPoint(x + width, y)); break; } path.CloseFigure(); _gfx.DrawPath(_brush, path); }
public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); XGraphicsPath path = new XGraphicsPath(); path.AddLine(50, 150, 50, 100); path.AddArc(50, 50, 100, 100, -180, 180); path.AddLine(150, 70, 200, 70); path.AddLine(200, 70, 200, 150); path.CloseFigure(); gfx.DrawPath(properties.Pen2.Pen, properties.Brush2.Brush, path); }
/// <inheritdoc/> public override void Draw(object dc, ArcShape arc, double dx, double dy, object db, object r) { var _gfx = dc as XGraphics; var a = new Spatial.Arc.GdiArc( Spatial.Point2.FromXY(arc.Point1.X, arc.Point1.Y), Spatial.Point2.FromXY(arc.Point2.X, arc.Point2.Y), Spatial.Point2.FromXY(arc.Point3.X, arc.Point3.Y), Spatial.Point2.FromXY(arc.Point4.X, arc.Point4.Y)); if (arc.IsFilled) { var path = new XGraphicsPath(); // NOTE: Not implemented in PdfSharp Core version. path.AddArc( _scaleToPage(a.X + dx), _scaleToPage(a.Y + dy), _scaleToPage(a.Width), _scaleToPage(a.Height), a.StartAngle, a.SweepAngle); if (arc.IsStroked) { _gfx.DrawPath( ToXPen(arc.Style, _scaleToPage, _sourceDpi, _targetDpi), ToXSolidBrush(arc.Style.Fill), path); } else { _gfx.DrawPath( ToXSolidBrush(arc.Style.Fill), path); } } else { if (arc.IsStroked) { _gfx.DrawArc( ToXPen(arc.Style, _scaleToPage, _sourceDpi, _targetDpi), _scaleToPage(a.X + dx), _scaleToPage(a.Y + dy), _scaleToPage(a.Width), _scaleToPage(a.Height), a.StartAngle, a.SweepAngle); } } }
private void DrawPathOpen(XGraphics gfx, int number) { base.BeginBox(gfx, number, "DrawPath (open)"); XPen xPen = new XPen(XColors.Navy, 3.1415926535897931); xPen.DashStyle = XDashStyle.Dash; XGraphicsPath xGraphicsPath = new XGraphicsPath(); xGraphicsPath.AddLine(10, 120, 50, 60); xGraphicsPath.AddArc(50, 20, 110, 80, 180, 180); xGraphicsPath.AddLine(160, 60, 220, 100); gfx.DrawPath(xPen, xGraphicsPath); base.EndBox(gfx); }
void RenderOpenPath(XGraphics gfx) { gfx.TranslateTransform(15, 20); XPen pen = new XPen(XColors.Navy, Math.PI); pen.DashStyle = XDashStyle.Dash; XGraphicsPath path = new XGraphicsPath(); path.AddLine(10, 120, 50, 60); path.AddArc(50, 20, 110, 80, 180, 180); path.AddLine(160, 60, 220, 100); gfx.DrawPath(pen, path); }
public override XPoint AddToPath(XGraphicsPath path, XPoint cursor, Base lastPathCommand = null) { if (Radii.Width == 0 || Radii.Height == 0) { path.AddLine(cursor, End.ToXPoint()); return(End.ToXPoint()); } if (End.X == cursor.X && End.Y == cursor.Y) { return(cursor); } path.AddArc(cursor, End.ToXPoint(), Radii.ToXSize(), XAxisRotation, IsLongArc, IsSweep ? XSweepDirection.Clockwise : XSweepDirection.Counterclockwise); return(End.ToXPoint()); }
/// <summary> /// /// </summary> /// <param name="gfx"></param> /// <param name="arc"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object gfx, Core2D.XArc arc, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r) { var _gfx = gfx as XGraphics; var a = Core2D.GdiArc.FromXArc(arc, dx, dy); if (arc.IsFilled) { var path = new XGraphicsPath(); // NOTE: Not implemented in PdfSharp Core version. path.AddArc( _scaleToPage(a.X), _scaleToPage(a.Y), _scaleToPage(a.Width), _scaleToPage(a.Height), a.StartAngle, a.SweepAngle); if (arc.IsStroked) { _gfx.DrawPath( ToXPen(arc.Style, _scaleToPage), ToXSolidBrush(arc.Style.Fill), path); } else { _gfx.DrawPath( ToXSolidBrush(arc.Style.Fill), path); } } else { if (arc.IsStroked) { _gfx.DrawArc( ToXPen(arc.Style, _scaleToPage), _scaleToPage(a.X), _scaleToPage(a.Y), _scaleToPage(a.Width), _scaleToPage(a.Height), a.StartAngle, a.SweepAngle); } } }
static void DrawPathOpen(XGraphics gfx, int number) { BeginBox(gfx, number, "DrawPath (open)"); XPen pen = new XPen(XColors.Navy, System.Math.PI); pen.DashStyle = XDashStyle.Dash; XGraphicsPath path = new XGraphicsPath(); path.AddLine(10, 120, 50, 60); path.AddArc(50, 20, 110, 80, 180, 180); path.AddLine(160, 60, 220, 100); gfx.DrawPath(pen, path); EndBox(gfx); }
public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); XGraphicsPath path = new XGraphicsPath(); path.AddLine(50, 150, 50, 100); path.AddArc(50, 50, 100, 100, -180, 180); path.AddLine(150, 70, 200, 70); path.AddLine(200, 70, 200, 150); path.CloseFigure(); XPen pen = new XPen(XColors.Red, 50); path.Widen(pen, new XMatrix(), 3); path.FillMode = this.properties.General.FillMode; gfx.DrawPath(properties.Pen2.Pen, properties.Brush2.Brush, path); }
/// <summary> /// Strokes a closed path. /// </summary> void DrawPathClosed(XGraphics gfx, int number) { BeginBox(gfx, number, "DrawPath (closed)"); XPen pen = new XPen(XColors.Navy, Math.PI); pen.DashStyle = XDashStyle.Dash; XGraphicsPath path = new XGraphicsPath(); path.AddLine(10, 120, 50, 60); path.AddArc(50, 20, 110, 80, 180, 180); path.AddLine(160, 60, 220, 100); path.CloseFigure(); gfx.DrawPath(pen, path); EndBox(gfx); }
/// <summary> /// /// </summary> /// <param name="pg"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="scale"></param> /// <returns></returns> public static XGraphicsPath ToXGraphicsPath(this Test2d.XPathGeometry pg, double dx, double dy, Func <double, double> scale) { var gp = new XGraphicsPath(); gp.FillMode = pg.FillRule == Test2d.XFillRule.EvenOdd ? XFillMode.Alternate : XFillMode.Winding; foreach (var pf in pg.Figures) { var startPoint = pf.StartPoint; foreach (var segment in pf.Segments) { if (segment is Test2d.XArcSegment) { #if CORE //var arcSegment = segment as Test2d.XArcSegment; // TODO: Convert WPF/SVG elliptical arc segment format to GDI+ bezier curves. //startPoint = arcSegment.Point; #endif #if WPF var arcSegment = segment as Test2d.XArcSegment; var point1 = new XPoint( scale(startPoint.X), scale(startPoint.Y)); var point2 = new XPoint( scale(arcSegment.Point.X), scale(arcSegment.Point.Y)); var size = new XSize( scale(arcSegment.Size.Width), scale(arcSegment.Size.Height)); gp.AddArc( point1, point2, size, arcSegment.RotationAngle, arcSegment.IsLargeArc, arcSegment.SweepDirection == Test2d.XSweepDirection.Clockwise ? XSweepDirection.Clockwise : XSweepDirection.Counterclockwise); startPoint = arcSegment.Point; #endif } else if (segment is Test2d.XBezierSegment) { var bezierSegment = segment as Test2d.XBezierSegment; gp.AddBezier( scale(startPoint.X), scale(startPoint.Y), scale(bezierSegment.Point1.X), scale(bezierSegment.Point1.Y), scale(bezierSegment.Point2.X), scale(bezierSegment.Point2.Y), scale(bezierSegment.Point3.X), scale(bezierSegment.Point3.Y)); startPoint = bezierSegment.Point3; } else if (segment is Test2d.XLineSegment) { var lineSegment = segment as Test2d.XLineSegment; gp.AddLine( scale(startPoint.X), scale(startPoint.Y), scale(lineSegment.Point.X), scale(lineSegment.Point.Y)); startPoint = lineSegment.Point; } else if (segment is Test2d.XPolyBezierSegment) { var polyBezierSegment = segment as Test2d.XPolyBezierSegment; if (polyBezierSegment.Points.Count >= 3) { gp.AddBezier( scale(startPoint.X), scale(startPoint.Y), scale(polyBezierSegment.Points[0].X), scale(polyBezierSegment.Points[0].Y), scale(polyBezierSegment.Points[1].X), scale(polyBezierSegment.Points[1].Y), scale(polyBezierSegment.Points[2].X), scale(polyBezierSegment.Points[2].Y)); } if (polyBezierSegment.Points.Count > 3 && polyBezierSegment.Points.Count % 3 == 0) { for (int i = 3; i < polyBezierSegment.Points.Count; i += 3) { gp.AddBezier( scale(polyBezierSegment.Points[i - 1].X), scale(polyBezierSegment.Points[i - 1].Y), scale(polyBezierSegment.Points[i].X), scale(polyBezierSegment.Points[i].Y), scale(polyBezierSegment.Points[i + 1].X), scale(polyBezierSegment.Points[i + 1].Y), scale(polyBezierSegment.Points[i + 2].X), scale(polyBezierSegment.Points[i + 2].Y)); } } startPoint = polyBezierSegment.Points.Last(); } else if (segment is Test2d.XPolyLineSegment) { var polyLineSegment = segment as Test2d.XPolyLineSegment; if (polyLineSegment.Points.Count >= 1) { gp.AddLine( scale(startPoint.X), scale(startPoint.Y), scale(polyLineSegment.Points[0].X), scale(polyLineSegment.Points[0].Y)); } if (polyLineSegment.Points.Count > 1) { for (int i = 1; i < polyLineSegment.Points.Count; i++) { gp.AddLine( scale(polyLineSegment.Points[i - 1].X), scale(polyLineSegment.Points[i - 1].Y), scale(polyLineSegment.Points[i].X), scale(polyLineSegment.Points[i].Y)); } } startPoint = polyLineSegment.Points.Last(); } else if (segment is Test2d.XPolyQuadraticBezierSegment) { var polyQuadraticSegment = segment as Test2d.XPolyQuadraticBezierSegment; if (polyQuadraticSegment.Points.Count >= 2) { var p1 = startPoint; var p2 = polyQuadraticSegment.Points[0]; var p3 = polyQuadraticSegment.Points[1]; double x1 = p1.X; double y1 = p1.Y; double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0; double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0; double x3 = x2 + (p3.X - p1.X) / 3.0; double y3 = y2 + (p3.Y - p1.Y) / 3.0; double x4 = p3.X; double y4 = p3.Y; gp.AddBezier( scale(x1 + dx), scale(y1 + dy), scale(x2 + dx), scale(y2 + dy), scale(x3 + dx), scale(y3 + dy), scale(x4 + dx), scale(y4 + dy)); } if (polyQuadraticSegment.Points.Count > 2 && polyQuadraticSegment.Points.Count % 2 == 0) { for (int i = 3; i < polyQuadraticSegment.Points.Count; i += 3) { var p1 = polyQuadraticSegment.Points[i - 1]; var p2 = polyQuadraticSegment.Points[i]; var p3 = polyQuadraticSegment.Points[i + 1]; double x1 = p1.X; double y1 = p1.Y; double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0; double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0; double x3 = x2 + (p3.X - p1.X) / 3.0; double y3 = y2 + (p3.Y - p1.Y) / 3.0; double x4 = p3.X; double y4 = p3.Y; gp.AddBezier( scale(x1 + dx), scale(y1 + dy), scale(x2 + dx), scale(y2 + dy), scale(x3 + dx), scale(y3 + dy), scale(x4 + dx), scale(y4 + dy)); } } startPoint = polyQuadraticSegment.Points.Last(); } else if (segment is Test2d.XQuadraticBezierSegment) { var qbezierSegment = segment as Test2d.XQuadraticBezierSegment; var p1 = startPoint; var p2 = qbezierSegment.Point1; var p3 = qbezierSegment.Point2; double x1 = p1.X; double y1 = p1.Y; double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0; double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0; double x3 = x2 + (p3.X - p1.X) / 3.0; double y3 = y2 + (p3.Y - p1.Y) / 3.0; double x4 = p3.X; double y4 = p3.Y; gp.AddBezier( scale(x1 + dx), scale(y1 + dy), scale(x2 + dx), scale(y2 + dy), scale(x3 + dx), scale(y3 + dy), scale(x4 + dx), scale(y4 + dy)); startPoint = qbezierSegment.Point2; } else { throw new NotSupportedException("Not supported segment type: " + segment.GetType()); } } if (pf.IsClosed) { gp.CloseFigure(); } else { gp.StartFigure(); } } return(gp); }