public void DrawLine( IElement element, IFrameContext context, PxPoint point1, PxPoint point2, Stroke strokeStyle ) { if (strokeStyle.Width <= 0) { return; } var strokeBrush = CreateBrush(element, context, strokeStyle.Brush, strokeStyle.Opacity); if (strokeBrush == null) { return; } var dx = Math.Abs(point1.X - point2.X); var dy = Math.Abs(point1.Y - point2.Y); if (MathEx.IsZero((float)Math.Sqrt((dx * dx) + (dy * dy)))) { return; } Target.DrawLine( point1.ToDx(), point2.ToDx(), strokeBrush, strokeStyle.Width, GetStrokeStyle(strokeStyle) ); }
public void BeginPath(D2D1.GeometrySink state, PxPoint point0, bool bFilled) { state.BeginFigure( point0.ToDx(), D2D1.FigureBegin.Filled ); }
public RotateTransform(Angle angle) { Angle = angle; Point = new PxPoint(0, 0); HasCentre = false; Matrix = PxMatrix.Rotate(angle.ToRadians()); }
public void DrawEllipse( IElement element, IFrameContext context, PxPoint pt, PxPoint radius, Fill fill, Stroke strokeStyle ) { if (MathEx.IsZero(radius.X) || MathEx.IsZero(radius.Y)) { return; } var ellipse = new D2D1.Ellipse( new DXM.RawVector2(pt.X, pt.Y), radius.X, radius.Y ); var fillBrush = CreateBrush(element, context, fill.Brush, fill.Opacity); var strokeBrush = strokeStyle.Width > 0 ? CreateBrush(element, context, strokeStyle.Brush, strokeStyle.Opacity) : null; if (fillBrush != null) { Target.FillEllipse(ellipse, fillBrush); } if (strokeBrush != null) { Target.DrawEllipse(ellipse, strokeBrush, strokeStyle.Width, GetStrokeStyle(strokeStyle)); } }
public CubicCurveCommand(PxPoint origin, PxPoint point1, PxPoint point2, PxPoint point3) { Point0 = origin; Point1 = point1; Point2 = point2; Point3 = point3; }
public void CreateQuadSegment(D2D1.GeometrySink state, PxPoint point0, PxPoint point1, PxPoint point2) { state.AddQuadraticBezier(new D2D1.QuadraticBezierSegment() { Point1 = point1.ToDx(), Point2 = point2.ToDx() }); }
public XyRect AddPoint(PxPoint pt) { return(new XyRect( Math.Min(_x1, pt.X), Math.Min(_y1, pt.Y), Math.Max(_x2, pt.X), Math.Max(_y2, pt.Y) )); }
public void CreateBezierSegment(D2D1.GeometrySink state, PxPoint point0, PxPoint point1, PxPoint point2, PxPoint point3) { state.AddBezier(new D2D1.BezierSegment() { Point1 = point1.ToDx(), Point2 = point2.ToDx(), Point3 = point3.ToDx() }); }
protected static IEnumerable <PathSegment> GetPathSegments(string attributeValue) { IList <IPathCommand> stack = null; var bounds = new XyRect(); var cursor = new PxPoint(0, 0); var start = new PxPoint(0, 0); IPathCommand previous = null; foreach (var command in GetCommands(attributeValue)) { var c = CreateSegment(cursor, previous, start, command.Key, command.Value); previous = c; if (command.Key == 'M' || command.Key == 'm') { if (stack != null) { //If we get here, we have an existing path that has not been closed. // We add a dummy closepath stack.Add(new ClosePathCommand(cursor, start, false)); yield return(new PathSegment(stack, bounds, false)); } stack = new List <IPathCommand>(); bounds = new XyRect(); start = c.NextPoint; stack.Add(c); } else if (command.Key == 'Z' || command.Key == 'z') { if (stack != null) { stack.Add(c); yield return(new PathSegment(stack, bounds, true)); } stack = null; bounds = new XyRect(); } else { stack?.Add(c); } cursor = c.NextPoint; bounds.AddPoint(cursor); } if (stack != null) { //If we get here, we have an existing path that has not been closed. // We add a dummy closepath stack.Add(new ClosePathCommand(cursor, start, false)); yield return(new PathSegment(stack, bounds, false)); } }
public RotateTransform(Angle angle, float x, float y) { Angle = angle; Point = new PxPoint(x, y); HasCentre = true; Matrix = PxMatrix.Translate(-x, -y) * PxMatrix.Rotate(angle.ToRadians()) * PxMatrix.Translate(x, y); }
public void CreateArcSegment(D2D1.GeometrySink state, PxPoint point0, PxPoint point1, bool isLargeArc, float axisRotation, float radiusX, float radiusY, bool sweepClockwise) { state.AddArc(new D2D1.ArcSegment() { ArcSize = isLargeArc ? D2D1.ArcSize.Large : D2D1.ArcSize.Small, Point = point1.ToDx(), RotationAngle = axisRotation, Size = new DX.Size2F(radiusX, radiusY), SweepDirection = sweepClockwise ? D2D1.SweepDirection.Clockwise : D2D1.SweepDirection.CounterClockwise }); }
public void DrawRectangle( IElement element, IFrameContext context, PxRectangle bounds, PxPoint radius, Fill fill, Stroke strokeStyle ) { if (MathEx.IsZero(bounds.Width) || MathEx.IsZero(bounds.Height)) { return; } var fillBrush = fill == null ? null : CreateBrush(element, context, fill.Brush, fill.Opacity); var strokeBrush = strokeStyle.Width > 0 ? CreateBrush(element, context, strokeStyle.Brush, strokeStyle.Opacity) : null; var rect = bounds.ToDx(); if (radius.X > 0 || radius.Y > 0) { var roundedRect = new D2D1.RoundedRectangle() { Rect = rect, RadiusX = MathEx.IsZero(radius.X) ? radius.Y : radius.X, RadiusY = MathEx.IsZero(radius.Y) ? radius.X : radius.Y }; if (fillBrush != null) { Target.FillRoundedRectangle(roundedRect, fillBrush); } if (strokeBrush != null) { Target.DrawRoundedRectangle(roundedRect, strokeBrush, strokeStyle.Width, GetStrokeStyle(strokeStyle)); } } else { if (fillBrush != null) { Target.FillRectangle(rect, fillBrush); } if (strokeBrush != null) { Target.DrawRectangle(rect, strokeBrush, strokeStyle.Width, GetStrokeStyle(strokeStyle)); } } }
public ArcPathCommand( PxPoint origin, float radiusX, float radiusY, float axisRotation, bool largeArcFlag, bool sweepFlag, PxPoint point1) { Point0 = origin; RadiusX = Math.Abs(radiusX); RadiusY = Math.Abs(radiusY); AxisRotation = axisRotation; LargeArcFlag = largeArcFlag; SweepFlag = sweepFlag; Point1 = point1; }
public MovePathCommand(PxPoint origin, PxPoint point1) { Point0 = origin; Point1 = point1; }
public static PxPoint ToPoint(this IList <float> list, int index, PxPoint cursor) { return(new PxPoint(list[index] + cursor.X, list[index + 1] + cursor.Y)); }
public ClosePathCommand(PxPoint origin, PxPoint point1, bool closePath) { Point0 = origin; Point1 = point1; ClosePath = closePath; }
public void CreateLineSegment(D2D1.GeometrySink state, PxPoint point0, PxPoint point1) { state.AddLine(point1.ToDx()); }
private static IPathCommand CreateSegment(PxPoint cursor, IPathCommand previous, PxPoint start, char command, IList <float> args) { switch (command) { case 'm': // relative moveto return(new MovePathCommand(cursor, args.ToPoint(0, cursor))); case 'M': // moveto return(new MovePathCommand(cursor, args.ToPoint(0))); case 'l': // relative lineto return(new LinePathCommand(cursor, args.ToPoint(0, cursor))); case 'L': // lineto return(new LinePathCommand(cursor, args.ToPoint(0))); case 'h': // relative horizontal lineto return(new LinePathCommand(cursor, new PxPoint(args[0], 0).Add(cursor))); case 'H': // horizontal lineto return(new LinePathCommand(cursor, new PxPoint(args[0], cursor.Y))); case 'v': // relative vertical lineto return(new LinePathCommand(cursor, new PxPoint(0, args[0]).Add(cursor))); case 'V': // vertical lineto return(new LinePathCommand(cursor, new PxPoint(cursor.X, args[0]))); case 'q': // relative curveto return(new QuadraticPathCommand(cursor, args.ToPoint(0, cursor), args.ToPoint(2, cursor))); case 'Q': // curveto return(new QuadraticPathCommand(cursor, args.ToPoint(0), args.ToPoint(2))); case 't': // relative shorthand/smooth curveto return(new QuadraticPathCommand(cursor, previous.ShortPoint, args.ToPoint(0, cursor))); case 'T': // shorthand/smooth curveto return(new QuadraticPathCommand(cursor, previous.ShortPoint, args.ToPoint(0))); case 'c': // relative curveto return(new CubicCurveCommand(cursor, args.ToPoint(0, cursor), args.ToPoint(2, cursor), args.ToPoint(4, cursor))); case 'C': // curveto return(new CubicCurveCommand(cursor, args.ToPoint(0), args.ToPoint(2), args.ToPoint(4))); case 's': // relative shorthand/smooth curveto return(new CubicCurveCommand(cursor, previous.ShortPoint, args.ToPoint(0, cursor), args.ToPoint(2, cursor))); case 'S': // shorthand/smooth curveto return(new CubicCurveCommand(cursor, previous.ShortPoint, args.ToPoint(0), args.ToPoint(2))); case 'Z': // closepath case 'z': // relative closepath return(new ClosePathCommand(cursor, start, true)); case 'a': return(new ArcPathCommand( cursor, args[0], args[1], args[2], Math.Abs(args[3]) > float.Epsilon, Math.Abs(args[4]) > float.Epsilon, args.ToPoint(5, cursor) )); case 'A': return(new ArcPathCommand(cursor, args[0], args[1], args[2], Math.Abs(args[3]) > float.Epsilon, Math.Abs(args[4]) > float.Epsilon, args.ToPoint(5))); default: throw new Exception(); } }
public QuadraticPathCommand(PxPoint origin, PxPoint point1, PxPoint point2) { Point0 = origin; Point1 = point1; Point2 = point2; }
public void ClosePath(D2D1.GeometrySink state, PxPoint point0, bool isClosed) { state.EndFigure(isClosed ? D2D1.FigureEnd.Closed : D2D1.FigureEnd.Open); }
public static DX.Vector2 ToDx(this PxPoint sz) { return(new DX.Vector2(sz.X, sz.Y)); }