示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pg"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public IPathGeometry ToPathGeometry(AM.PathGeometry pg, double dx, double dy)
        {
            var factory = _serviceProvider.GetService <IFactory>();

            var geometry = factory.CreatePathGeometry(
                ImmutableArray.Create <IPathFigure>(),
                pg.FillRule == AM.FillRule.EvenOdd ? FillRule.EvenOdd : FillRule.Nonzero);

            var context = factory.CreateGeometryContext(geometry);

            foreach (var pf in pg.Figures)
            {
                context.BeginFigure(
                    factory.CreatePointShape(pf.StartPoint.X + dx, pf.StartPoint.Y + dy),
                    pf.IsFilled,
                    pf.IsClosed);

                foreach (var segment in pf.Segments)
                {
                    if (segment is AM.ArcSegment arcSegment)
                    {
                        context.ArcTo(
                            factory.CreatePointShape(arcSegment.Point.X + dx, arcSegment.Point.Y + dy),
                            factory.CreatePathSize(arcSegment.Size.Width, arcSegment.Size.Height),
                            arcSegment.RotationAngle,
                            arcSegment.IsLargeArc,
                            arcSegment.SweepDirection == AM.SweepDirection.Clockwise ? SweepDirection.Clockwise : SweepDirection.Counterclockwise);
                    }
                    else if (segment is AM.BezierSegment cubicBezierSegment)
                    {
                        context.CubicBezierTo(
                            factory.CreatePointShape(cubicBezierSegment.Point1.X + dx, cubicBezierSegment.Point1.Y + dy),
                            factory.CreatePointShape(cubicBezierSegment.Point2.X + dx, cubicBezierSegment.Point2.Y + dy),
                            factory.CreatePointShape(cubicBezierSegment.Point3.X + dx, cubicBezierSegment.Point3.Y + dy));
                    }
                    else if (segment is AM.LineSegment lineSegment)
                    {
                        context.LineTo(
                            factory.CreatePointShape(lineSegment.Point.X + dx, lineSegment.Point.Y + dy));
                    }
                    else if (segment is AM.QuadraticBezierSegment quadraticBezierSegment)
                    {
                        context.QuadraticBezierTo(
                            factory.CreatePointShape(quadraticBezierSegment.Point1.X + dx, quadraticBezierSegment.Point1.Y + dy),
                            factory.CreatePointShape(quadraticBezierSegment.Point2.X + dx, quadraticBezierSegment.Point2.Y + dy));
                    }
                    else
                    {
                        throw new NotSupportedException("Not supported segment type: " + segment.GetType());
                    }
                }
            }

            return(geometry);
        }
示例#2
0
        public void DrawPolygon(Polygon polygon, FillStyle fillStyle, LineStyle lineStyle,
                                PointStyle vertexStyle, bool fast)
        {
            Polygon viewPolygon = (Polygon)Viewport.GetViewGeometry(polygon);

            AM.PathGeometry          geometry        = new AM.PathGeometry();
            AM.StreamGeometryContext geometryContext = geometry.Open();
            DrawPolygonRing(viewPolygon.Shell, false, geometryContext);
            foreach (LinearRing hole in viewPolygon.Holes)
            {
                DrawPolygonRing(hole, true, geometryContext);
            }
            m_Context.DrawGeometry(new SolidColorBrush(fillStyle.Color.Argb),
                                   new Pen(new SolidColorBrush(lineStyle.Color.Argb)),
                                   geometry);
            DrawCoordinates(viewPolygon.Shell.Coordinates, vertexStyle, fast, true);
            foreach (LinearRing hole in viewPolygon.Holes)
            {
                DrawCoordinates(hole.Coordinates, vertexStyle, fast, true);
            }
        }