public void BeginFigure_Adds_New_Figure() { var geometry = new XPathGeometry(); var target = new XPathGeometryContext(geometry); Assert.Equal(0, geometry.Figures.Length); target.BeginFigure(new XPoint()); Assert.Equal(1, geometry.Figures.Length); Assert.True(geometry.Figures[0].IsFilled); Assert.True(geometry.Figures[0].IsClosed); target.SetClosedState(false); Assert.False(geometry.Figures[0].IsClosed); }
public void CubicBezierTo_Adds_New_XCubicBezierSegment() { var geometry = new XPathGeometry(); var target = new XPathGeometryContext(geometry); target.BeginFigure(new XPoint()); Assert.Equal(0, geometry.Figures[0].Segments.Length); target.CubicBezierTo(new XPoint(), new XPoint(), new XPoint()); Assert.Equal(1, geometry.Figures[0].Segments.Length); var segment = geometry.Figures[0].Segments[0]; Assert.IsType <XCubicBezierSegment>(segment); Assert.True(segment.IsStroked); Assert.True(segment.IsSmoothJoin); }
public void PolyQuadraticBezierTo_Adds_New_XPolyQuadraticBezierSegment() { var geometry = new XPathGeometry(); var target = new XPathGeometryContext(geometry); target.BeginFigure(new XPoint()); Assert.Equal(0, geometry.Figures[0].Segments.Length); target.PolyQuadraticBezierTo(ImmutableArray.Create <XPoint>(new XPoint(), new XPoint(), new XPoint())); Assert.Equal(1, geometry.Figures[0].Segments.Length); var segment = geometry.Figures[0].Segments[0]; Assert.IsType <XPolyQuadraticBezierSegment>(segment); Assert.True(segment.IsStroked); Assert.True(segment.IsSmoothJoin); }
/// <summary> /// /// </summary> /// <param name="pg"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static XPathGeometry ToXPathGeometry(this PathGeometry pg, double dx, double dy) { var geometry = XPathGeometry.Create( ImmutableArray.Create <XPathFigure>(), pg.FillRule == FillRule.EvenOdd ? XFillRule.EvenOdd : XFillRule.Nonzero); var context = new XPathGeometryContext(geometry); foreach (var pf in pg.Figures) { context.BeginFigure( XPoint.Create(pf.StartPoint.X + dx, pf.StartPoint.Y + dy), pf.IsFilled, pf.IsClosed); foreach (var segment in pf.Segments) { if (segment is ArcSegment) { var arcSegment = segment as ArcSegment; context.ArcTo( XPoint.Create(arcSegment.Point.X + dx, arcSegment.Point.Y + dy), XPathSize.Create(arcSegment.Size.Width, arcSegment.Size.Height), arcSegment.RotationAngle, arcSegment.IsLargeArc, arcSegment.SweepDirection == SweepDirection.Clockwise ? XSweepDirection.Clockwise : XSweepDirection.Counterclockwise, arcSegment.IsStroked, arcSegment.IsSmoothJoin); } else if (segment is BezierSegment) { var cubicBezierSegment = segment as BezierSegment; context.CubicBezierTo( XPoint.Create(cubicBezierSegment.Point1.X + dx, cubicBezierSegment.Point1.Y + dy), XPoint.Create(cubicBezierSegment.Point2.X + dx, cubicBezierSegment.Point2.Y + dy), XPoint.Create(cubicBezierSegment.Point3.X + dx, cubicBezierSegment.Point3.Y + dy), cubicBezierSegment.IsStroked, cubicBezierSegment.IsSmoothJoin); } else if (segment is LineSegment) { var lineSegment = segment as LineSegment; context.LineTo( XPoint.Create(lineSegment.Point.X + dx, lineSegment.Point.Y + dy), lineSegment.IsStroked, lineSegment.IsSmoothJoin); } else if (segment is PolyBezierSegment) { var polyCubicBezierSegment = segment as PolyBezierSegment; context.PolyCubicBezierTo( ToXPoints(polyCubicBezierSegment.Points, dx, dy), polyCubicBezierSegment.IsStroked, polyCubicBezierSegment.IsSmoothJoin); } else if (segment is PolyLineSegment) { var polyLineSegment = segment as PolyLineSegment; context.PolyLineTo( ToXPoints(polyLineSegment.Points, dx, dy), polyLineSegment.IsStroked, polyLineSegment.IsSmoothJoin); } else if (segment is PolyQuadraticBezierSegment) { var polyQuadraticSegment = segment as PolyQuadraticBezierSegment; context.PolyQuadraticBezierTo( ToXPoints(polyQuadraticSegment.Points, dx, dy), polyQuadraticSegment.IsStroked, polyQuadraticSegment.IsSmoothJoin); } else if (segment is QuadraticBezierSegment) { var quadraticBezierSegment = segment as QuadraticBezierSegment; context.QuadraticBezierTo( XPoint.Create(quadraticBezierSegment.Point1.X + dx, quadraticBezierSegment.Point1.Y + dy), XPoint.Create(quadraticBezierSegment.Point2.X + dx, quadraticBezierSegment.Point2.Y + dy), quadraticBezierSegment.IsStroked, quadraticBezierSegment.IsSmoothJoin); } else { throw new NotSupportedException("Not supported segment type: " + segment.GetType()); } } } return(geometry); }