コード例 #1
0
        /// <inheritdoc/>
        public override void Draw(object dc, QuadraticBezierShape quadraticBezier, double dx, double dy, object db, object r)
        {
            if (!quadraticBezier.IsFilled && !quadraticBezier.IsStroked)
            {
                return;
            }

            var _dc = dc as AM.DrawingContext;

            AM.IBrush brush = ToBrush(quadraticBezier.Style.Fill);
            AM.Pen    pen   = ToPen(quadraticBezier.Style, _scaleToPage);

            var sg = new AM.StreamGeometry();

            using (var sgc = sg.Open())
            {
                sgc.BeginFigure(
                    new A.Point(quadraticBezier.Point1.X, quadraticBezier.Point1.Y),
                    quadraticBezier.IsFilled);

                sgc.QuadraticBezierTo(
                    new A.Point(quadraticBezier.Point2.X, quadraticBezier.Point2.Y),
                    new A.Point(quadraticBezier.Point3.X, quadraticBezier.Point3.Y));

                sgc.EndFigure(false);
            }

            _dc.DrawGeometry(
                quadraticBezier.IsFilled ? brush : null,
                quadraticBezier.IsStroked ? pen : null,
                sg);
        }
コード例 #2
0
        /// <inheritdoc/>
        public override void Draw(object dc, XCubicBezier cubicBezier, double dx, double dy, ImmutableArray <XProperty> db, XRecord r)
        {
            if (!cubicBezier.IsFilled && !cubicBezier.IsStroked)
            {
                return;
            }

            var _dc = dc as AM.DrawingContext;

            AM.IBrush brush = ToBrush(cubicBezier.Style.Fill);
            AM.Pen    pen   = ToPen(cubicBezier.Style, _scaleToPage);

            var sg = new AM.StreamGeometry();

            using (var sgc = sg.Open())
            {
                sgc.BeginFigure(
                    new A.Point(cubicBezier.Point1.X, cubicBezier.Point1.Y),
                    cubicBezier.IsFilled);

                sgc.CubicBezierTo(
                    new A.Point(cubicBezier.Point2.X, cubicBezier.Point2.Y),
                    new A.Point(cubicBezier.Point3.X, cubicBezier.Point3.Y),
                    new A.Point(cubicBezier.Point4.X, cubicBezier.Point4.Y));

                sgc.EndFigure(false);
            }

            _dc.DrawGeometry(
                cubicBezier.IsFilled ? brush : null,
                cubicBezier.IsStroked ? pen : null,
                sg);
        }
コード例 #3
0
        public void Move_Line_RelativeVerticalLine()
        {
            StreamGeometry geometry = new StreamGeometry();
            MockContext context = new MockContext();
            PathMarkupParser target = new PathMarkupParser(geometry, context);

            target.Parse("M3,4 L5,6 v7");

            Assert.AreEqual("M3,4 L5,6 L5,13 ", context.Trace);
        }
コード例 #4
0
        public void Move_Line_HorizontalLine()
        {
            StreamGeometry geometry = new StreamGeometry();
            MockContext context = new MockContext();
            PathMarkupParser target = new PathMarkupParser(geometry, context);

            target.Parse("M3,4 L5,6 H7");

            Assert.AreEqual("M3,4 L5,6 L7,6 ", context.Trace);
        }
コード例 #5
0
        public void Move_RelativeLine_RelativeLine()
        {
            StreamGeometry geometry = new StreamGeometry();
            MockContext context = new MockContext();
            PathMarkupParser target = new PathMarkupParser(geometry, context);

            target.Parse("M3,4 l5,6 7,8");

            Assert.AreEqual("M3,4 L8,10 L15,18 ", context.Trace);
        }
コード例 #6
0
ファイル: LineDrawNode.cs プロジェクト: bangush/Core2D
 private void UpdateCurveGeometry()
 {
     if (Style.LineStyle.IsCurved)
     {
         CurveGeometry = CreateCurveGeometry(P0, P1, Style.LineStyle.Curvature, Style.LineStyle.CurveOrientation, Line.Start.Alignment, Line.End.Alignment);
     }
     else
     {
         CurveGeometry = null;
     }
 }
コード例 #7
0
        /// <summary>
        /// Creates a <see cref="StreamGeometry"/> from a string.
        /// </summary>
        /// <param name="s">The string.</param>
        /// <returns>A <see cref="StreamGeometry"/>.</returns>
        public static StreamGeometry Parse(string s)
        {
            StreamGeometry result = new StreamGeometry();

            using (StreamGeometryContext ctx = result.Open())
            {
                PathMarkupParser parser = new PathMarkupParser(ctx);
                parser.Parse(s);
                return result;
            }
        }
コード例 #8
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            StreamGeometry result = new StreamGeometry();

            using (StreamGeometryContext ctx = result.Open())
            {
                PathMarkupParser parser = new PathMarkupParser(result, ctx);
                parser.Parse((string)value);
                return result;
            }
        }
コード例 #9
0
        public static AM.Geometry ToGeometry(QuadraticBezierShapeViewModel quadraticBezier)
        {
            var sg = new AM.StreamGeometry();

            using var sgc = sg.Open();
            sgc.BeginFigure(
                new A.Point(quadraticBezier.Point1.X, quadraticBezier.Point1.Y),
                quadraticBezier.IsFilled);
            sgc.QuadraticBezierTo(
                new A.Point(quadraticBezier.Point2.X, quadraticBezier.Point2.Y),
                new A.Point(quadraticBezier.Point3.X, quadraticBezier.Point3.Y));
            sgc.EndFigure(false);
            return(sg);
        }
コード例 #10
0
        public static AM.Geometry ToGeometry(ICubicBezierShape cubicBezier)
        {
            var sg = new AM.StreamGeometry();

            using var sgc = sg.Open();
            sgc.BeginFigure(
                new A.Point(cubicBezier.Point1.X, cubicBezier.Point1.Y),
                cubicBezier.IsFilled);
            sgc.CubicBezierTo(
                new A.Point(cubicBezier.Point2.X, cubicBezier.Point2.Y),
                new A.Point(cubicBezier.Point3.X, cubicBezier.Point3.Y),
                new A.Point(cubicBezier.Point4.X, cubicBezier.Point4.Y));
            sgc.EndFigure(false);
            return(sg);
        }
コード例 #11
0
		public void TransformLine(TextView textView, DrawingContext drawingContext, VisualLine line)
		{
			if (markers == null)
			{
				return;
			}

			var markersInLine = markers.FindOverlappingSegments(line);

			foreach (var marker in markersInLine)
			{
				if (marker.EndOffset < textView.TextDocument.TextLength)
				{
					foreach (var r in VisualLineGeometryBuilder.GetRectsForSegment(textView, marker))
					{
						var startPoint = r.BottomLeft;
						var endPoint = r.BottomRight;

						var usedPen = new Pen(new SolidColorBrush(marker.MarkerColor), 1);

						const double offset = 2.5;

						var count = Math.Max((int) ((endPoint.X - startPoint.X)/offset) + 1, 4);

						var geometry = new StreamGeometry();

						using (var ctx = geometry.Open())
						{
							ctx.BeginFigure(startPoint, false);

							foreach (var point in CreatePoints(startPoint, endPoint, offset, count))
							{
								ctx.LineTo(point);
							}

							ctx.EndFigure(false);
						}

						drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
						break;
					}
				}
			}
		}
コード例 #12
0
        /// <inheritdoc/>
        public override void Draw(object dc, ArcShape arc, double dx, double dy, object db, object r)
        {
            if (!arc.IsFilled && !arc.IsStroked)
            {
                return;
            }

            var _dc = dc as AM.DrawingContext;

            AM.IBrush brush = ToBrush(arc.Style.Fill);
            AM.Pen    pen   = ToPen(arc.Style, _scaleToPage);

            var sg = new AM.StreamGeometry();

            using (var sgc = sg.Open())
            {
                var a = new WpfArc(
                    Point2.FromXY(arc.Point1.X, arc.Point1.Y),
                    Point2.FromXY(arc.Point2.X, arc.Point2.Y),
                    Point2.FromXY(arc.Point3.X, arc.Point3.Y),
                    Point2.FromXY(arc.Point4.X, arc.Point4.Y));

                sgc.BeginFigure(
                    new A.Point(a.Start.X + dx, a.Start.Y),
                    arc.IsFilled);

                sgc.ArcTo(
                    new A.Point(a.End.X + dx, a.End.Y + dy),
                    new A.Size(a.Radius.Width, a.Radius.Height),
                    0.0,
                    a.IsLargeArc,
                    AM.SweepDirection.Clockwise);

                sgc.EndFigure(false);
            }

            _dc.DrawGeometry(
                arc.IsFilled ? brush : null,
                arc.IsStroked ? pen : null,
                sg);
        }
コード例 #13
0
ファイル: LineDrawNode.cs プロジェクト: bangush/Core2D
        private AM.StreamGeometry CreateCurveGeometry(A.Point p0, A.Point p1, double curvature, CurveOrientation orientation, PointAlignment pt0a, PointAlignment pt1a)
        {
            var curveGeometry = new AM.StreamGeometry();

            using (var geometryContext = curveGeometry.Open())
            {
                geometryContext.BeginFigure(new A.Point(p0.X, p0.Y), false);
                double p0x = p0.X;
                double p0y = p0.Y;
                double p1x = p1.X;
                double p1y = p1.Y;
                LineShapeExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt0a, pt1a, ref p0x, ref p0y, ref p1x, ref p1y);
                var point1 = new A.Point(p0x, p0y);
                var point2 = new A.Point(p1x, p1y);
                var point3 = new A.Point(p1.X, p1.Y);
                geometryContext.CubicBezierTo(point1, point2, point3);
                geometryContext.EndFigure(false);
            }

            return(curveGeometry);
        }
コード例 #14
0
 private static void DrawLineCurveInternal(AM.DrawingContext _dc, AM.Pen pen, bool isStroked, ref A.Point pt1, ref A.Point pt2, double curvature, CurveOrientation orientation, PointAlignment pt1a, PointAlignment pt2a)
 {
     if (isStroked)
     {
         var sg = new AM.StreamGeometry();
         using (var sgc = sg.Open())
         {
             sgc.BeginFigure(new A.Point(pt1.X, pt1.Y), false);
             double p1x = pt1.X;
             double p1y = pt1.Y;
             double p2x = pt2.X;
             double p2y = pt2.Y;
             LineShapeExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt1a, pt2a, ref p1x, ref p1y, ref p2x, ref p2y);
             sgc.CubicBezierTo(
                 new A.Point(p1x, p1y),
                 new A.Point(p2x, p2y),
                 new A.Point(pt2.X, pt2.Y));
             sgc.EndFigure(false);
         }
         _dc.DrawGeometry(null, pen, sg);
     }
 }
コード例 #15
0
        public static AM.Geometry ToGeometry(ArcShapeViewModel arc)
        {
            var sg = new AM.StreamGeometry();

            using var sgc = sg.Open();
            var a = new WpfArc(
                Point2.FromXY(arc.Point1.X, arc.Point1.Y),
                Point2.FromXY(arc.Point2.X, arc.Point2.Y),
                Point2.FromXY(arc.Point3.X, arc.Point3.Y),
                Point2.FromXY(arc.Point4.X, arc.Point4.Y));

            sgc.BeginFigure(
                new A.Point(a.Start.X, a.Start.Y),
                arc.IsFilled);
            sgc.ArcTo(
                new A.Point(a.End.X, a.End.Y),
                new A.Size(a.Radius.Width, a.Radius.Height),
                0.0,
                a.IsLargeArc,
                AM.SweepDirection.Clockwise);
            sgc.EndFigure(false);
            return(sg);
        }
コード例 #16
0
        /// <inheritdoc/>
        public override void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray <XProperty> db, XRecord r)
        {
            if (!arc.IsFilled && !arc.IsStroked)
            {
                return;
            }

            var _dc = dc as AM.DrawingContext;

            AM.IBrush brush = ToBrush(arc.Style.Fill);
            AM.Pen    pen   = ToPen(arc.Style, _scaleToPage);

            var sg = new AM.StreamGeometry();

            using (var sgc = sg.Open())
            {
                var a = WpfArc.FromXArc(arc, dx, dy);

                sgc.BeginFigure(
                    new A.Point(a.Start.X, a.Start.Y),
                    arc.IsFilled);

                sgc.ArcTo(
                    new A.Point(a.End.X, a.End.Y),
                    new A.Size(a.Radius.Width, a.Radius.Height),
                    0.0,
                    a.IsLargeArc,
                    AM.SweepDirection.Clockwise);

                sgc.EndFigure(false);
            }

            _dc.DrawGeometry(
                arc.IsFilled ? brush : null,
                arc.IsStroked ? pen : null,
                sg);
        }
コード例 #17
0
        public override void DrawPolygon(RBrush brush, RPoint[] points)
        {
            if (points != null && points.Length > 0)
            {
                var g = new StreamGeometry();
                using (var context = g.Open())
                {
                    context.BeginFigure(Util.Convert(points[0]), true);
                    for (int i = 1; i < points.Length; i++)
                        context.LineTo(Util.Convert(points[i]));
                    context.EndFigure(false);
                }

                _g.DrawGeometry(((BrushAdapter)brush).Brush, null, g);
            }
        }
コード例 #18
0
 public PathMarkupParser(StreamGeometry geometry, StreamGeometryContext context)
 {
     this.geometry = geometry;
     this.context = context;
 }
コード例 #19
0
ファイル: AvaloniaRenderer.cs プロジェクト: Core2D/Core2D
 private static void DrawLineCurveInternal(AM.DrawingContext _dc, AM.Pen pen, bool isStroked, ref A.Point pt1, ref A.Point pt2, double curvature, CurveOrientation orientation, PointAlignment pt1a, PointAlignment pt2a)
 {
     if (isStroked)
     {
         var sg = new AM.StreamGeometry();
         using (var sgc = sg.Open())
         {
             sgc.BeginFigure(new A.Point(pt1.X, pt1.Y), false);
             double p1x = pt1.X;
             double p1y = pt1.Y;
             double p2x = pt2.X;
             double p2y = pt2.Y;
             XLineExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt1a, pt2a, ref p1x, ref p1y, ref p2x, ref p2y);
             sgc.CubicBezierTo(
                 new A.Point(p1x, p1y),
                 new A.Point(p2x, p2y),
                 new A.Point(pt2.X, pt2.Y));
             sgc.EndFigure(false);
         }
         _dc.DrawGeometry(null, pen, sg);
     }
 }
コード例 #20
0
ファイル: AvaloniaRenderer.cs プロジェクト: Core2D/Core2D
        /// <inheritdoc/>
        public override void Draw(object dc, XQuadraticBezier quadraticBezier, double dx, double dy, ImmutableArray<XProperty> db, XRecord r)
        {
            if (!quadraticBezier.IsFilled && !quadraticBezier.IsStroked)
                return;

            var _dc = dc as AM.DrawingContext;

            AM.IBrush brush = ToBrush(quadraticBezier.Style.Fill);
            AM.Pen pen = ToPen(quadraticBezier.Style, _scaleToPage);

            var sg = new AM.StreamGeometry();
            using (var sgc = sg.Open())
            {
                sgc.BeginFigure(
                    new A.Point(quadraticBezier.Point1.X, quadraticBezier.Point1.Y),
                    quadraticBezier.IsFilled);

                sgc.QuadraticBezierTo(
                    new A.Point(quadraticBezier.Point2.X, quadraticBezier.Point2.Y),
                    new A.Point(quadraticBezier.Point3.X, quadraticBezier.Point3.Y));

                sgc.EndFigure(false);
            }

            _dc.DrawGeometry(
                quadraticBezier.IsFilled ? brush : null,
                quadraticBezier.IsStroked ? pen : null,
                sg);
        }
コード例 #21
0
ファイル: AvaloniaRenderer.cs プロジェクト: Core2D/Core2D
        /// <inheritdoc/>
        public override void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray<XProperty> db, XRecord r)
        {
            if (!arc.IsFilled && !arc.IsStroked)
                return;

            var _dc = dc as AM.DrawingContext;

            AM.IBrush brush = ToBrush(arc.Style.Fill);
            AM.Pen pen = ToPen(arc.Style, _scaleToPage);

            var sg = new AM.StreamGeometry();
            using (var sgc = sg.Open())
            {
                var a = WpfArc.FromXArc(arc);

                sgc.BeginFigure(
                    new A.Point(a.Start.X + dx, a.Start.Y),
                    arc.IsFilled);

                sgc.ArcTo(
                    new A.Point(a.End.X + dx, a.End.Y + dy),
                    new A.Size(a.Radius.Width, a.Radius.Height),
                    0.0,
                    a.IsLargeArc,
                    AM.SweepDirection.Clockwise);

                sgc.EndFigure(false);
            }

            _dc.DrawGeometry(
                arc.IsFilled ? brush : null,
                arc.IsStroked ? pen : null,
                sg);
        }
コード例 #22
0
 public static string ToSource(AM.StreamGeometry sg)
 {
     return(sg.ToString());
 }
コード例 #23
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xpg"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static StreamGeometry ToStreamGeometry(this XPathGeometry xpg, double dx, double dy)
        {
            var sg = new StreamGeometry();

            using (var sgc = sg.Open())
            {
                var previous = default(XPoint);

                sgc.SetFillRule(xpg.FillRule == XFillRule.Nonzero ? FillRule.NonZero : FillRule.EvenOdd);

                foreach (var xpf in xpg.Figures)
                {
                    sgc.BeginFigure(new Point(xpf.StartPoint.X + dx, xpf.StartPoint.Y + dy), xpf.IsFilled);

                    previous = xpf.StartPoint;

                    foreach (var segment in xpf.Segments)
                    {
                        if (segment is XArcSegment)
                        {
                            var arcSegment = segment as XArcSegment;
                            sgc.ArcTo(
                                new Point(arcSegment.Point.X + dx, arcSegment.Point.Y + dy),
                                new Size(arcSegment.Size.Width,  arcSegment.Size.Height),
                                arcSegment.RotationAngle,
                                arcSegment.IsLargeArc,
                                arcSegment.SweepDirection == XSweepDirection.Clockwise ? SweepDirection.Clockwise : SweepDirection.CounterClockwise);

                            previous = arcSegment.Point;
                        }
                        else if (segment is XCubicBezierSegment)
                        {
                            var cubicBezierSegment = segment as XCubicBezierSegment;
                            sgc.CubicBezierTo(
                                new Point(cubicBezierSegment.Point1.X + dx, cubicBezierSegment.Point1.Y + dy),
                                new Point(cubicBezierSegment.Point2.X + dx, cubicBezierSegment.Point2.Y + dy),
                                new Point(cubicBezierSegment.Point3.X + dx, cubicBezierSegment.Point3.Y + dy));

                            previous = cubicBezierSegment.Point3;
                        }
                        else if (segment is XLineSegment)
                        {
                            var lineSegment = segment as XLineSegment;
                            sgc.LineTo(
                                new Point(lineSegment.Point.X + dx, lineSegment.Point.Y + dy));

                            previous = lineSegment.Point;
                        }
                        else if (segment is XPolyCubicBezierSegment)
                        {
                            var polyCubicBezierSegment = segment as XPolyCubicBezierSegment;
                            if (polyCubicBezierSegment.Points.Length >= 3)
                            {
                                sgc.CubicBezierTo(
                                    new Point(
                                        polyCubicBezierSegment.Points[0].X + dx,
                                        polyCubicBezierSegment.Points[0].Y + dy),
                                    new Point(
                                        polyCubicBezierSegment.Points[1].X + dx,
                                        polyCubicBezierSegment.Points[1].Y + dy),
                                    new Point(
                                        polyCubicBezierSegment.Points[2].X + dx,
                                        polyCubicBezierSegment.Points[2].Y + dy));

                                previous = polyCubicBezierSegment.Points[2];
                            }

                            if (polyCubicBezierSegment.Points.Length > 3
                                && polyCubicBezierSegment.Points.Length % 3 == 0)
                            {
                                for (int i = 3; i < polyCubicBezierSegment.Points.Length; i += 3)
                                {
                                    sgc.CubicBezierTo(
                                        new Point(
                                            polyCubicBezierSegment.Points[i].X + dx,
                                            polyCubicBezierSegment.Points[i].Y + dy),
                                        new Point(
                                            polyCubicBezierSegment.Points[i + 1].X + dx,
                                            polyCubicBezierSegment.Points[i + 1].Y + dy),
                                        new Point(
                                            polyCubicBezierSegment.Points[i + 2].X + dx,
                                            polyCubicBezierSegment.Points[i + 2].Y + dy));

                                    previous = polyCubicBezierSegment.Points[i + 2];
                                }
                            }
                        }
                        else if (segment is XPolyLineSegment)
                        {
                            var polyLineSegment = segment as XPolyLineSegment;
                            if (polyLineSegment.Points.Length >= 1)
                            {
                                sgc.LineTo(
                                    new Point(
                                        polyLineSegment.Points[0].X + dx,
                                        polyLineSegment.Points[0].Y + dy));

                                previous = polyLineSegment.Points[0];
                            }

                            if (polyLineSegment.Points.Length > 1)
                            {
                                for (int i = 1; i < polyLineSegment.Points.Length; i++)
                                {
                                    sgc.LineTo(
                                        new Point(
                                            polyLineSegment.Points[i].X + dx,
                                            polyLineSegment.Points[i].Y + dy));

                                    previous = polyLineSegment.Points[i];
                                }
                            }
                        }
                        else if (segment is XPolyQuadraticBezierSegment)
                        {
                            var polyQuadraticSegment = segment as XPolyQuadraticBezierSegment;
                            if (polyQuadraticSegment.Points.Length >= 2)
                            {
                                sgc.QuadraticBezierTo(
                                    new Point(
                                        polyQuadraticSegment.Points[0].X + dx,
                                        polyQuadraticSegment.Points[0].Y + dy),
                                    new Point(
                                        polyQuadraticSegment.Points[1].X + dx,
                                        polyQuadraticSegment.Points[1].Y + dy));

                                previous = polyQuadraticSegment.Points[1];
                            }

                            if (polyQuadraticSegment.Points.Length > 2
                                && polyQuadraticSegment.Points.Length % 2 == 0)
                            {
                                for (int i = 3; i < polyQuadraticSegment.Points.Length; i += 3)
                                {
                                    sgc.QuadraticBezierTo(
                                        new Point(
                                            polyQuadraticSegment.Points[i].X + dx,
                                            polyQuadraticSegment.Points[i].Y + dy),
                                        new Point(
                                            polyQuadraticSegment.Points[i + 1].X + dx,
                                            polyQuadraticSegment.Points[i + 1].Y + dy));

                                    previous = polyQuadraticSegment.Points[i + 1];
                                }
                            }
                        }
                        else if (segment is XQuadraticBezierSegment)
                        {
                            var quadraticBezierSegment = segment as XQuadraticBezierSegment;
                            sgc.QuadraticBezierTo(
                                new Point(
                                    quadraticBezierSegment.Point1.X + dx,
                                    quadraticBezierSegment.Point1.Y + dy),
                                new Point(
                                    quadraticBezierSegment.Point2.X + dx,
                                    quadraticBezierSegment.Point2.Y + dy));

                            previous = quadraticBezierSegment.Point2;
                        }
                        else
                        {
                            throw new NotSupportedException("Not supported segment type: " + segment.GetType());
                        }
                    }

                    sgc.EndFigure(xpf.IsClosed);
                }
            }

            return sg;
        }
コード例 #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="xpg"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public AM.StreamGeometry ToStreamGeometry(IPathGeometry xpg, double dx, double dy)
        {
            var sg = new AM.StreamGeometry();

            using (var sgc = sg.Open())
            {
                IPointShape previous = default;

                sgc.SetFillRule(xpg.FillRule == FillRule.Nonzero ? AM.FillRule.NonZero : AM.FillRule.EvenOdd);

                foreach (var xpf in xpg.Figures)
                {
                    sgc.BeginFigure(new A.Point(xpf.StartPoint.X + dx, xpf.StartPoint.Y + dy), xpf.IsFilled);

                    previous = xpf.StartPoint;

                    foreach (var segment in xpf.Segments)
                    {
                        if (segment is IArcSegment arcSegment)
                        {
                            sgc.ArcTo(
                                new A.Point(arcSegment.Point.X + dx, arcSegment.Point.Y + dy),
                                new A.Size(arcSegment.Size.Width, arcSegment.Size.Height),
                                arcSegment.RotationAngle,
                                arcSegment.IsLargeArc,
                                arcSegment.SweepDirection == SweepDirection.Clockwise ? AM.SweepDirection.Clockwise : AM.SweepDirection.CounterClockwise);

                            previous = arcSegment.Point;
                        }
                        else if (segment is ICubicBezierSegment cubicBezierSegment)
                        {
                            sgc.CubicBezierTo(
                                new A.Point(cubicBezierSegment.Point1.X + dx, cubicBezierSegment.Point1.Y + dy),
                                new A.Point(cubicBezierSegment.Point2.X + dx, cubicBezierSegment.Point2.Y + dy),
                                new A.Point(cubicBezierSegment.Point3.X + dx, cubicBezierSegment.Point3.Y + dy));

                            previous = cubicBezierSegment.Point3;
                        }
                        else if (segment is ILineSegment lineSegment)
                        {
                            sgc.LineTo(
                                new A.Point(lineSegment.Point.X + dx, lineSegment.Point.Y + dy));

                            previous = lineSegment.Point;
                        }
                        else if (segment is IPolyCubicBezierSegment polyCubicBezierSegment)
                        {
                            if (polyCubicBezierSegment.Points.Length >= 3)
                            {
                                sgc.CubicBezierTo(
                                    new A.Point(
                                        polyCubicBezierSegment.Points[0].X + dx,
                                        polyCubicBezierSegment.Points[0].Y + dy),
                                    new A.Point(
                                        polyCubicBezierSegment.Points[1].X + dx,
                                        polyCubicBezierSegment.Points[1].Y + dy),
                                    new A.Point(
                                        polyCubicBezierSegment.Points[2].X + dx,
                                        polyCubicBezierSegment.Points[2].Y + dy));

                                previous = polyCubicBezierSegment.Points[2];
                            }

                            if (polyCubicBezierSegment.Points.Length > 3 &&
                                polyCubicBezierSegment.Points.Length % 3 == 0)
                            {
                                for (int i = 3; i < polyCubicBezierSegment.Points.Length; i += 3)
                                {
                                    sgc.CubicBezierTo(
                                        new A.Point(
                                            polyCubicBezierSegment.Points[i].X + dx,
                                            polyCubicBezierSegment.Points[i].Y + dy),
                                        new A.Point(
                                            polyCubicBezierSegment.Points[i + 1].X + dx,
                                            polyCubicBezierSegment.Points[i + 1].Y + dy),
                                        new A.Point(
                                            polyCubicBezierSegment.Points[i + 2].X + dx,
                                            polyCubicBezierSegment.Points[i + 2].Y + dy));

                                    previous = polyCubicBezierSegment.Points[i + 2];
                                }
                            }
                        }
                        else if (segment is IPolyLineSegment polyLineSegment)
                        {
                            if (polyLineSegment.Points.Length >= 1)
                            {
                                sgc.LineTo(
                                    new A.Point(
                                        polyLineSegment.Points[0].X + dx,
                                        polyLineSegment.Points[0].Y + dy));

                                previous = polyLineSegment.Points[0];
                            }

                            if (polyLineSegment.Points.Length > 1)
                            {
                                for (int i = 1; i < polyLineSegment.Points.Length; i++)
                                {
                                    sgc.LineTo(
                                        new A.Point(
                                            polyLineSegment.Points[i].X + dx,
                                            polyLineSegment.Points[i].Y + dy));

                                    previous = polyLineSegment.Points[i];
                                }
                            }
                        }
                        else if (segment is IPolyQuadraticBezierSegment polyQuadraticSegment)
                        {
                            if (polyQuadraticSegment.Points.Length >= 2)
                            {
                                sgc.QuadraticBezierTo(
                                    new A.Point(
                                        polyQuadraticSegment.Points[0].X + dx,
                                        polyQuadraticSegment.Points[0].Y + dy),
                                    new A.Point(
                                        polyQuadraticSegment.Points[1].X + dx,
                                        polyQuadraticSegment.Points[1].Y + dy));

                                previous = polyQuadraticSegment.Points[1];
                            }

                            if (polyQuadraticSegment.Points.Length > 2 &&
                                polyQuadraticSegment.Points.Length % 2 == 0)
                            {
                                for (int i = 3; i < polyQuadraticSegment.Points.Length; i += 3)
                                {
                                    sgc.QuadraticBezierTo(
                                        new A.Point(
                                            polyQuadraticSegment.Points[i].X + dx,
                                            polyQuadraticSegment.Points[i].Y + dy),
                                        new A.Point(
                                            polyQuadraticSegment.Points[i + 1].X + dx,
                                            polyQuadraticSegment.Points[i + 1].Y + dy));

                                    previous = polyQuadraticSegment.Points[i + 1];
                                }
                            }
                        }
                        else if (segment is IQuadraticBezierSegment quadraticBezierSegment)
                        {
                            sgc.QuadraticBezierTo(
                                new A.Point(
                                    quadraticBezierSegment.Point1.X + dx,
                                    quadraticBezierSegment.Point1.Y + dy),
                                new A.Point(
                                    quadraticBezierSegment.Point2.X + dx,
                                    quadraticBezierSegment.Point2.Y + dy));

                            previous = quadraticBezierSegment.Point2;
                        }
                        else
                        {
                            throw new NotSupportedException("Not supported segment type: " + segment.GetType());
                        }
                    }

                    sgc.EndFigure(xpf.IsClosed);
                }
            }

            return(sg);
        }
コード例 #25
0
 /// <summary>
 /// Creates a <see cref="Geometry"/> from a string.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <returns>A <see cref="StreamGeometry"/>.</returns>
 public static Geometry Parse(string s) => StreamGeometry.Parse(s);
コード例 #26
0
 public PathMarkupParser(StreamGeometry geometry, StreamGeometryContext context)
 {
     this.geometry = geometry;
     this.context  = context;
 }
コード例 #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PathMarkupParser"/> class.
 /// </summary>
 /// <param name="geometry">The geometry in which the path should be stored.</param>
 /// <param name="context">The context for <paramref name="geometry"/>.</param>
 public PathMarkupParser(StreamGeometry geometry, StreamGeometryContext context)
 {
     _geometry = geometry;
     _context  = context;
 }
コード例 #28
0
        public static AM.Geometry?ToGeometry(this Path path, bool isFilled)
        {
            if (path.Commands == null)
            {
                return(null);
            }

            var streamGeometry = new AM.StreamGeometry();

            using var streamGeometryContext = streamGeometry.Open();

            streamGeometryContext.SetFillRule(path.FillType.ToSKPathFillType());

            bool endFigure  = false;
            bool haveFigure = false;

            for (int i = 0; i < path.Commands.Count; i++)
            {
                var pathCommand = path.Commands[i];
                var isLast      = i == path.Commands.Count - 1;

                switch (pathCommand)
                {
                case MoveToPathCommand moveToPathCommand:
                {
                    if (endFigure == true && haveFigure == false)
                    {
                        return(null);
                    }
                    if (haveFigure == true)
                    {
                        streamGeometryContext.EndFigure(false);
                    }
                    if (isLast == true)
                    {
                        return(streamGeometry);
                    }
                    else
                    {
                        if (path.Commands[i + 1] is MoveToPathCommand)
                        {
                            return(streamGeometry);
                        }

                        if (path.Commands[i + 1] is ClosePathCommand)
                        {
                            return(streamGeometry);
                        }
                    }
                    endFigure  = true;
                    haveFigure = false;
                    var x     = moveToPathCommand.X;
                    var y     = moveToPathCommand.Y;
                    var point = new A.Point(x, y);
                    streamGeometryContext.BeginFigure(point, isFilled);         // TODO: isFilled
                }
                break;

                case LineToPathCommand lineToPathCommand:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    haveFigure = true;
                    var x     = lineToPathCommand.X;
                    var y     = lineToPathCommand.Y;
                    var point = new A.Point(x, y);
                    streamGeometryContext.LineTo(point);
                }
                break;

                case ArcToPathCommand arcToPathCommand:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    haveFigure = true;
                    var x             = arcToPathCommand.X;
                    var y             = arcToPathCommand.Y;
                    var point         = new A.Point(x, y);
                    var rx            = arcToPathCommand.Rx;
                    var ry            = arcToPathCommand.Ry;
                    var size          = new A.Size(rx, ry);
                    var rotationAngle = arcToPathCommand.XAxisRotate;
                    var isLargeArc    = arcToPathCommand.LargeArc == PathArcSize.Large;
                    var sweep         = arcToPathCommand.Sweep.ToSweepDirection();
                    streamGeometryContext.ArcTo(point, size, rotationAngle, isLargeArc, sweep);
                }
                break;

                case QuadToPathCommand quadToPathCommand:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    haveFigure = true;
                    var x0       = quadToPathCommand.X0;
                    var y0       = quadToPathCommand.Y0;
                    var x1       = quadToPathCommand.X1;
                    var y1       = quadToPathCommand.Y1;
                    var control  = new A.Point(x0, y0);
                    var endPoint = new A.Point(x1, y1);
                    streamGeometryContext.QuadraticBezierTo(control, endPoint);
                }
                break;

                case CubicToPathCommand cubicToPathCommand:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    haveFigure = true;
                    var x0     = cubicToPathCommand.X0;
                    var y0     = cubicToPathCommand.Y0;
                    var x1     = cubicToPathCommand.X1;
                    var y1     = cubicToPathCommand.Y1;
                    var x2     = cubicToPathCommand.X2;
                    var y2     = cubicToPathCommand.Y2;
                    var point1 = new A.Point(x0, y0);
                    var point2 = new A.Point(x1, y1);
                    var point3 = new A.Point(x2, y2);
                    streamGeometryContext.CubicBezierTo(point1, point2, point3);
                }
                break;

                case ClosePathCommand _:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    if (haveFigure == false)
                    {
                        return(null);
                    }
                    endFigure  = false;
                    haveFigure = false;
                    streamGeometryContext.EndFigure(true);
                }
                break;

                default:
                    break;
                }
            }

            if (endFigure)
            {
                if (haveFigure == false)
                {
                    return(null);
                }
                streamGeometryContext.EndFigure(false);
            }

            return(streamGeometry);
        }
コード例 #29
0
        public static AM.StreamGeometry ToStreamGeometry(PathGeometryViewModel xpg)
        {
            var sg = new AM.StreamGeometry();

            using (var sgc = sg.Open())
            {
                PointShapeViewModel previous = default;

                sgc.SetFillRule(xpg.FillRule == FillRule.Nonzero ? AM.FillRule.NonZero : AM.FillRule.EvenOdd);

                foreach (var xpf in xpg.Figures)
                {
                    sgc.BeginFigure(new A.Point(xpf.StartPoint.X, xpf.StartPoint.Y), false);

                    previous = xpf.StartPoint;

                    foreach (var segment in xpf.Segments)
                    {
                        if (segment is ArcSegmentViewModel arcSegment)
                        {
                            sgc.ArcTo(
                                new A.Point(arcSegment.Point.X, arcSegment.Point.Y),
                                new A.Size(arcSegment.Size.Width, arcSegment.Size.Height),
                                arcSegment.RotationAngle,
                                arcSegment.IsLargeArc,
                                arcSegment.SweepDirection == SweepDirection.Clockwise ? AM.SweepDirection.Clockwise : AM.SweepDirection.CounterClockwise);

                            previous = arcSegment.Point;
                        }
                        else if (segment is CubicBezierSegmentViewModel cubicBezierSegment)
                        {
                            sgc.CubicBezierTo(
                                new A.Point(cubicBezierSegment.Point1.X, cubicBezierSegment.Point1.Y),
                                new A.Point(cubicBezierSegment.Point2.X, cubicBezierSegment.Point2.Y),
                                new A.Point(cubicBezierSegment.Point3.X, cubicBezierSegment.Point3.Y));

                            previous = cubicBezierSegment.Point3;
                        }
                        else if (segment is LineSegmentViewModel lineSegment)
                        {
                            sgc.LineTo(
                                new A.Point(lineSegment.Point.X, lineSegment.Point.Y));

                            previous = lineSegment.Point;
                        }
                        else if (segment is QuadraticBezierSegmentViewModel quadraticBezierSegment)
                        {
                            sgc.QuadraticBezierTo(
                                new A.Point(
                                    quadraticBezierSegment.Point1.X,
                                    quadraticBezierSegment.Point1.Y),
                                new A.Point(
                                    quadraticBezierSegment.Point2.X,
                                    quadraticBezierSegment.Point2.Y));

                            previous = quadraticBezierSegment.Point2;
                        }
                        else
                        {
                            throw new NotSupportedException("Not supported segment type: " + segment.GetType());
                        }
                    }

                    sgc.EndFigure(xpf.IsClosed);
                }
            }

            return(sg);
        }
コード例 #30
0
ファイル: PathMarkupParser.cs プロジェクト: mikel785/Perspex
 /// <summary>
 /// Initializes a new instance of the <see cref="PathMarkupParser"/> class.
 /// </summary>
 /// <param name="geometry">The geometry in which the path should be stored.</param>
 /// <param name="context">The context for <paramref name="geometry"/>.</param>
 public PathMarkupParser(StreamGeometry geometry, StreamGeometryContext context)
 {
     _geometry = geometry;
     _context = context;
 }