Example #1
0
        static void DrawPathAlternateAndWinding(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "DrawPath (alternate / winding)");

            XPen pen = new XPen(XColors.Navy, 2.5);

            // Alternate fill mode
            XGraphicsPath path = new XGraphicsPath();

            path.FillMode = XFillMode.Alternate;
            path.AddLine(10, 130, 10, 40);
            path.AddBeziers(new XPoint[] { new XPoint(10, 40), new XPoint(30, 0), new XPoint(40, 20), new XPoint(60, 40),
                                           new XPoint(80, 60), new XPoint(100, 60), new XPoint(120, 40) });
            path.AddLine(120, 40, 120, 130);
            path.CloseFigure();
            path.AddEllipse(40, 80, 50, 40);
            gfx.DrawPath(pen, XBrushes.DarkOrange, path);

            // Winding fill mode
            path          = new XGraphicsPath();
            path.FillMode = XFillMode.Winding;
            path.AddLine(130, 130, 130, 40);
            path.AddBeziers(new XPoint[] { new XPoint(130, 40), new XPoint(150, 0), new XPoint(160, 20), new XPoint(180, 40),
                                           new XPoint(200, 60), new XPoint(220, 60), new XPoint(240, 40) });
            path.AddLine(240, 40, 240, 130);
            path.CloseFigure();
            path.AddEllipse(160, 80, 50, 40);
            gfx.DrawPath(pen, XBrushes.DarkOrange, path);

            EndBox(gfx);
        }
Example #2
0
    public XGraphicsPath DrawPath()
    {
        var curvepoints = new XPoint[] { A, E, D };
        var path        = new XGraphicsPath();

        path.AddCurve(curvepoints);
        path.AddLine(D, C);
        path.AddLine(C, B);
        path.CloseFigure();
        return(path);
    }
Example #3
0
        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);
        }
Example #4
0
        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);
            }
        }
Example #5
0
        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);
        }
Example #6
0
        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 XGraphicsPath Surrond(double distance)
    {
        var path = new XGraphicsPath();
        var O    = FindO();

        foreach (var curve in _curves)
        {
            var points = new XPoint[curve.Length];
            for (var i = 0; i < curve.Length; i++)
            {
                var point = curve[i];
                var x     = FindPlace(point.X, O.X, distance);
                var y     = FindPlace(point.Y, O.Y, distance);
                points[i] = new XPoint(x, y);
            }
            path.AddCurve(points);
        }
        foreach (var line in _lines)
        {
            var ax = FindPlace(line.Item1.X, O.X, distance);
            var ay = FindPlace(line.Item1.Y, O.Y, distance);
            var a  = new XPoint(ax, ay);
            var bx = FindPlace(line.Item2.X, O.X, distance);
            var by = FindPlace(line.Item2.Y, O.Y, distance);
            var b  = new XPoint(bx, by);
            path.AddLine(a, b);
        }
        path.CloseFigure();
        return(path);
    }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
        public void Fill(XGraphics graphics, XBrush brush)
        {
            XGraphicsPath path = new XGraphicsPath
            {
                FillMode = XFillMode.Winding
            };
            bool hasFigure = false;
            int  ptIndex   = 0;

            foreach (Command command in Commands)
            {
                switch (command)
                {
                case Command.MoveTo:
                    if (hasFigure)
                    {
                        path.CloseFigure();
                        hasFigure = false;
                    }
                    ptIndex++;
                    break;

                case Command.LineTo:
                    path.AddLine(Points[ptIndex - 1], Points[ptIndex]);
                    ptIndex  += 1;
                    hasFigure = true;
                    break;

                case Command.CubicCurveTo:
                    path.AddBezier(Points[ptIndex - 1], Points[ptIndex], Points[ptIndex + 1], Points[ptIndex + 2]);
                    ptIndex  += 3;
                    hasFigure = true;
                    break;

                case Command.CloseSubpath:
                    if (hasFigure)
                    {
                        path.CloseFigure();
                        hasFigure = false;
                    }
                    break;

                case Command.Rectangle:
                    path.AddRectangle(Points[ptIndex + 1].X, Points[ptIndex + 1].Y, Points[ptIndex].X, Points[ptIndex].Y);
                    ptIndex += 2;
                    path.CloseFigure();
                    hasFigure = false;
                    break;
                }
            }

            if (hasFigure)
            {
                path.CloseFigure();
            }

            graphics.DrawPath(brush, path);
        }
Example #11
0
        /// <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);
        }
Example #12
0
        public override void LineTo(double x, double y)
        {
            var point = new XPoint(x, y);

            CurrentPath.StartFigure();
            CurrentPath.AddLine(CurrentPathPoint, point);
            CurrentPath.CloseFigure();
            CurrentPathPoint = point;
        }
Example #13
0
        void RenderAlternatePath(XGraphics gfx)
        {
            gfx.TranslateTransform(15, 20);

            XPen pen = new XPen(XColors.Navy, 2.5);

            // Alternate fill mode
            XGraphicsPath path = new XGraphicsPath();

            path.FillMode = XFillMode.Alternate;
            path.AddLine(10, 130, 10, 40);
            path.AddBeziers(new XPoint[] { new XPoint(10, 40), new XPoint(30, 0), new XPoint(40, 20), new XPoint(60, 40),
                                           new XPoint(80, 60), new XPoint(100, 60), new XPoint(120, 40) });
            path.AddLine(120, 40, 120, 130);
            path.CloseFigure();
            path.AddEllipse(40, 80, 50, 40);
            gfx.DrawPath(pen, XBrushes.DarkOrange, path);
        }
Example #14
0
        void RenderWindingPath(XGraphics gfx)
        {
            gfx.TranslateTransform(15, 150);

            XPen pen = new XPen(XColors.Navy, 2.5);

            // Winding fill mode
            XGraphicsPath path = new XGraphicsPath();

            path          = new XGraphicsPath();
            path.FillMode = XFillMode.Winding;
            path.AddLine(130, 130, 130, 40);
            path.AddBeziers(new XPoint[] { new XPoint(130, 40), new XPoint(150, 0), new XPoint(160, 20), new XPoint(180, 40),
                                           new XPoint(200, 60), new XPoint(220, 60), new XPoint(240, 40) });
            path.AddLine(240, 40, 240, 130);
            path.CloseFigure();
            path.AddEllipse(160, 80, 50, 40);
            gfx.DrawPath(pen, XBrushes.DarkOrange, path);
        }
Example #15
0
        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);
        }
Example #16
0
        public static void AddLine(XGraphicsPath path, LineSegment segment, Random random, bool straightEdges)
        {
//      if (Settings.HandDrawnDoc && !straightEdges)
            if (!straightEdges)
            {
                var dx       = segment.End.X - segment.Start.X;
                var dy       = segment.End.Y - segment.Start.Y;
                var distance = (float)Math.Sqrt(dx * dx + dy * dy);
                var points   = random.Next(Math.Max(3, (int)(distance / 15)), Math.Max(6, (int)(distance / 8)));
                var lines    = points - 1;
                var last     = segment.Start;
                for (var line = 0; line < lines; ++line)
                {
                    Vector next;
                    if (line == 0)
                    {
                        next = last;
                    }
                    else if (line == lines - 1)
                    {
                        next = segment.End;
                    }
                    else
                    {
                        var fraction = line / (float)(lines - 1);
                        var x        = segment.Start.X + (segment.End.X - segment.Start.X) * fraction;
                        var y        = segment.Start.Y + (segment.End.Y - segment.Start.Y) * fraction;

                        x   += random.Next(-1, 2);
                        y   += random.Next(-1, 2);
                        next = new Vector(x, y);
                    }

                    path.AddLine(last.ToPointF(), next.ToPointF());
                    last = next;
                }
            }
            else
            {
                path.AddLine(segment.Start.ToPointF(), segment.End.ToPointF());
            }
        }
Example #17
0
        public static void DrawChevron(XGraphics graphics, PointF pos, float angle, float size, Brush fillBrush)
        {
            if (m_chevronPath == null)
            {
                var apex        = new PointF(0.5f, 0);
                var leftCorner  = new PointF(-0.5f, 0.5f);
                var rightCorner = new PointF(-0.5f, -0.5f);
                m_chevronPath = new XGraphicsPath();
                m_chevronPath.AddLine(apex, rightCorner);
                m_chevronPath.AddLine(rightCorner, leftCorner);
                m_chevronPath.AddLine(leftCorner, apex);
            }
            var state = graphics.Save();

            graphics.TranslateTransform(pos.X, pos.Y);
            graphics.RotateTransform(angle);
            graphics.ScaleTransform(size, size);
            graphics.DrawPath(fillBrush, m_chevronPath);
            graphics.Restore(state);
        }
Example #18
0
        private void DrawPathAlternateAndWinding(XGraphics gfx, int number)
        {
            base.BeginBox(gfx, number, "DrawPath (alternate / winding)");
            XPen          pen           = new XPen(XColors.Navy, 2.5);
            XGraphicsPath xGraphicsPath = new XGraphicsPath();

            xGraphicsPath.FillMode = XFillMode.Alternate;
            xGraphicsPath.AddLine(10, 130, 10, 40);
            xGraphicsPath.AddBeziers(new XPoint[]
            {
                new XPoint(10.0, 40.0),
                new XPoint(30.0, 0.0),
                new XPoint(40.0, 20.0),
                new XPoint(60.0, 40.0),
                new XPoint(80.0, 60.0),
                new XPoint(100.0, 60.0),
                new XPoint(120.0, 40.0)
            });
            xGraphicsPath.AddLine(120, 40, 120, 130);
            xGraphicsPath.CloseFigure();
            xGraphicsPath.AddEllipse(40, 80, 50, 40);
            gfx.DrawPath(pen, XBrushes.DarkOrange, xGraphicsPath);
            xGraphicsPath          = new XGraphicsPath();
            xGraphicsPath.FillMode = XFillMode.Winding;
            xGraphicsPath.AddLine(130, 130, 130, 40);
            xGraphicsPath.AddBeziers(new XPoint[]
            {
                new XPoint(130.0, 40.0),
                new XPoint(150.0, 0.0),
                new XPoint(160.0, 20.0),
                new XPoint(180.0, 40.0),
                new XPoint(200.0, 60.0),
                new XPoint(220.0, 60.0),
                new XPoint(240.0, 40.0)
            });
            xGraphicsPath.AddLine(240, 40, 240, 130);
            xGraphicsPath.CloseFigure();
            xGraphicsPath.AddEllipse(160, 80, 50, 40);
            gfx.DrawPath(pen, XBrushes.DarkOrange, xGraphicsPath);
            base.EndBox(gfx);
        }
Example #19
0
        public static void AddLine(XGraphicsPath path, LineSegment segment, Random random)
        {
            if (Settings.HandDrawn)
            {
                float  dx       = segment.End.X - segment.Start.X;
                float  dy       = segment.End.Y - segment.Start.Y;
                float  distance = (float)Math.Sqrt(dx * dx + dy * dy);
                int    points   = random.Next(Math.Max(3, (int)(distance / 15)), Math.Max(6, (int)(distance / 8)));
                int    lines    = points - 1;
                Vector last     = segment.Start;
                for (int line = 0; line < lines; ++line)
                {
                    Vector next;
                    if (line == 0)
                    {
                        next = last;
                    }
                    else if (line == lines - 1)
                    {
                        next = segment.End;
                    }
                    else
                    {
                        float fraction = (float)line / (float)(lines - 1);
                        float x        = segment.Start.X + (segment.End.X - segment.Start.X) * fraction;
                        float y        = segment.Start.Y + (segment.End.Y - segment.Start.Y) * fraction;

                        x   += random.Next(-1, 2);
                        y   += random.Next(-1, 2);
                        next = new Vector(x, y);
                    }

                    path.AddLine(last.ToPointF(), next.ToPointF());
                    last = next;
                }
            }
            else
            {
                path.AddLine(segment.Start.ToPointF(), segment.End.ToPointF());
            }
        }
Example #20
0
        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());
        }
Example #21
0
        public static XGraphicsPath GetPath(PathEx pathEx)
        {
            var path = new XGraphicsPath();

            path.FillMode = (XFillMode)Enum.Parse(typeof(XFillMode), pathEx.FillMode.ToString());
            path.StartFigure();
            var start = new XPoint();

            foreach (var segment in pathEx.Segments)
            {
                switch (segment.Type)
                {
                case PathEx.SegmentType.MoveTo:
                    start = PdfConverter.Convert(segment.Point1.ToPoint());
                    break;

                case PathEx.SegmentType.LineTo:
                    var end = PdfConverter.Convert(segment.Point1.ToPoint());
                    path.AddLine(start, end);
                    start = end;
                    break;

                case PathEx.SegmentType.BezierTo:
                    var p1   = PdfConverter.Convert(segment.Point1.ToPoint());
                    var p2   = PdfConverter.Convert(segment.Point2.ToPoint());
                    var bEnd = PdfConverter.Convert(segment.Point3.ToPoint());
                    path.AddBezier(start, p1, p2, bEnd);
                    start = bEnd;
                    break;

                case PathEx.SegmentType.FigureEnd:
                    if (segment.Closed)
                    {
                        path.CloseFigure();
                    }
                    break;
                }
            }
            return(path);
        }
Example #22
0
 public void AddLine(Point point1, Point point2)
 {
     Path.AddLine(point1, point2);
 }
Example #23
0
        internal static void SvgPath2Pdf(SvgPath element, XGraphics graphics)
        {
            if (element.Display == "none")
            {
                return;
            }
            var path = new XGraphicsPath {
                FillMode = XFillMode.Winding
            };

            foreach (var segment in element.PathData)
            {
                switch (segment)
                {
                case SvgMoveToSegment svgMoveToSegment:
                    Console.WriteLine($"{segment.GetType()}, start: {svgMoveToSegment.Start}, end: {svgMoveToSegment.End}");
                    path.StartFigure();
                    break;

                case SvgCubicCurveSegment svgCubicCurveSegment:
                    Console.WriteLine(
                        $"{segment.GetType()}, start: {svgCubicCurveSegment.Start}, first control: {svgCubicCurveSegment.FirstControlPoint}, second control: {svgCubicCurveSegment.SecondControlPoint}, end: {svgCubicCurveSegment.End}");
                    path.AddBezier(ConvertHelper.Point2XPoint(svgCubicCurveSegment.Start),
                                   ConvertHelper.Point2XPoint(svgCubicCurveSegment.FirstControlPoint),
                                   ConvertHelper.Point2XPoint(svgCubicCurveSegment.SecondControlPoint),
                                   ConvertHelper.Point2XPoint(svgCubicCurveSegment.End));
                    break;

                case SvgQuadraticCurveSegment svgQuadraticCurveSegment:
                    Console.WriteLine($"{segment.GetType()}, start: {svgQuadraticCurveSegment.Start}, control: {svgQuadraticCurveSegment.ControlPoint}, end: {svgQuadraticCurveSegment.End}");
                    var(start, control1, control2, end) = MathHelper.Quadratic2Cubic(svgQuadraticCurveSegment.Start, svgQuadraticCurveSegment.ControlPoint, svgQuadraticCurveSegment.End);
                    path.AddBezier(ConvertHelper.Point2XPoint(start),
                                   ConvertHelper.Point2XPoint(control1),
                                   ConvertHelper.Point2XPoint(control2),
                                   ConvertHelper.Point2XPoint(end));
                    break;

                case SvgLineSegment svgLineSegment:
                    Console.WriteLine($"{segment.GetType()}, start: {svgLineSegment.Start}, end: {svgLineSegment.End}");
                    path.AddLine(ConvertHelper.Point2XPoint(svgLineSegment.Start), ConvertHelper.Point2XPoint(svgLineSegment.End));
                    break;

                case SvgClosePathSegment svgClosePathSegment:
                    Console.WriteLine($"{segment.GetType()}, start: {svgClosePathSegment.Start}, end: {svgClosePathSegment.End}");
                    path.CloseFigure();
                    break;

                default:
                    Console.WriteLine(segment.GetType());
                    break;
                }
            }

            if (element.Fill != SvgPaintServer.None)
            {
                var brush = ConvertHelper.Fill2XBrush(element.Fill);
                graphics.DrawPath(brush, path);
            }

            if (element.Stroke != null)
            {
                var pen = ConvertHelper.Stroke2XPen(element.Stroke, element.StrokeWidth, element.StrokeLineCap, element.StrokeLineJoin);
                graphics.DrawPath(pen, path);
            }
        }
Example #24
0
 public override XPoint AddToPath(XGraphicsPath path, XPoint cursor, Base lastPathCommand = null)
 {
     path.AddLine(cursor, End.ToXPoint());
     return(End.ToXPoint());
 }
 public override void LineTo(double x, double y)
 {
     _graphicsPath.AddLine((float)_lastPoint.X, (float)_lastPoint.Y, (float)x, (float)y);
     _lastPoint = new RPoint(x, y);
 }
        /// <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);
        }
Example #27
0
        /// <summary>
        /// Draws the marker given through rendererInfo at the specified position. Position specifies
        /// the center of the marker.
        /// </summary>
        internal static void Draw(XGraphics graphics, XPoint pos, MarkerRendererInfo rendererInfo)
        {
#if SILVERLIGHT
            return; // BUG: Code crashs Silverlight Path class.

#pragma warning disable 0162
#endif

            if (rendererInfo.MarkerStyle == MarkerStyle.None)
            {
                return;
            }

            double size = rendererInfo.MarkerSize;
            double size2 = size / 2;
            double x0, y0, x1, y1;
            double g;

            XPen   foreground = new XPen(rendererInfo.MarkerForegroundColor, 0.5);
            XBrush background = new XSolidBrush(rendererInfo.MarkerBackgroundColor);

            XGraphicsPath gp = new XGraphicsPath();
            switch (rendererInfo.MarkerStyle)
            {
            case MarkerStyle.Square:
                x0 = pos.X - size2;
                y0 = pos.Y - size2;
                x1 = pos.X + size2;
                y1 = pos.Y + size2;
                gp.AddLine(x0, y0, x1, y0);
                gp.AddLine(x1, y0, x1, y1);
                gp.AddLine(x1, y1, x0, y1);
                gp.AddLine(x0, y1, x0, y0);
                break;

            case MarkerStyle.Diamond:
                gp.AddLine(x1                   = pos.X + size2, pos.Y, pos.X, y0 = pos.Y - size2);
                gp.AddLine(pos.X, y0, x0        = pos.X - size2, pos.Y);
                gp.AddLine(x0, pos.Y, pos.X, y1 = pos.Y + size2);
                gp.AddLine(pos.X, y1, x1, pos.Y);
                break;

            case MarkerStyle.Triangle:
                y0 = pos.Y + size / 2;
                y1 = pos.Y - size / 2;
                g  = Math.Sqrt(size * size * 4 / 3) / 2;
                gp.AddLine(pos.X, y1, pos.X + g, y0);
                gp.AddLine(pos.X + g, y0, pos.X - g, y0);
                gp.AddLine(pos.X - g, y0, pos.X, y1);
                break;

            case MarkerStyle.Plus:
                g = size2 / 4;
                gp.AddLine(pos.X - size2, pos.Y + g, pos.X - g, pos.Y + g);
                gp.AddLine(pos.X - g, pos.Y + g, pos.X - g, pos.Y + size2);
                gp.AddLine(pos.X - g, pos.Y + size2, pos.X + g, pos.Y + size2);
                gp.AddLine(pos.X + g, pos.Y + size2, pos.X + g, pos.Y + g);
                gp.AddLine(pos.X + g, pos.Y + g, pos.X + size2, pos.Y + g);
                gp.AddLine(pos.X + size2, pos.Y + g, pos.X + size2, pos.Y - g);
                gp.AddLine(pos.X + size2, pos.Y - g, pos.X + g, pos.Y - g);
                gp.AddLine(pos.X + g, pos.Y - g, pos.X + g, pos.Y - size2);
                gp.AddLine(pos.X + g, pos.Y - size2, pos.X - g, pos.Y - size2);
                gp.AddLine(pos.X - g, pos.Y - size2, pos.X - g, pos.Y - g);
                gp.AddLine(pos.X - g, pos.Y - g, pos.X - size2, pos.Y - g);
                gp.AddLine(pos.X - size2, pos.Y - g, pos.X - size2, pos.Y + g);
                break;

            case MarkerStyle.Circle:
            case MarkerStyle.Dot:
                x0 = pos.X - size2;
                y0 = pos.Y - size2;
                gp.AddEllipse(x0, y0, size, size);
                break;

            case MarkerStyle.Dash:
                x0 = pos.X - size2;
                y0 = pos.Y - size2 / 3;
                x1 = pos.X + size2;
                y1 = pos.Y + size2 / 3;
                gp.AddLine(x0, y0, x1, y0);
                gp.AddLine(x1, y0, x1, y1);
                gp.AddLine(x1, y1, x0, y1);
                gp.AddLine(x0, y1, x0, y0);
                break;

            case MarkerStyle.X:
                g = size / 4;
                gp.AddLine(pos.X - size2 + g, pos.Y - size2, pos.X, pos.Y - g);
                gp.AddLine(pos.X, pos.Y - g, pos.X + size2 - g, pos.Y - size2);
                gp.AddLine(pos.X + size2 - g, pos.Y - size2, pos.X + size2, pos.Y - size2 + g);
                gp.AddLine(pos.X + size2, pos.Y - size2 + g, pos.X + g, pos.Y);
                gp.AddLine(pos.X + g, pos.Y, pos.X + size2, pos.Y + size2 - g);
                gp.AddLine(pos.X + size2, pos.Y + size2 - g, pos.X + size2 - g, pos.Y + size2);
                gp.AddLine(pos.X + size2 - g, pos.Y + size2, pos.X, pos.Y + g);
                gp.AddLine(pos.X, pos.Y + g, pos.X - size2 + g, pos.Y + size2);
                gp.AddLine(pos.X - size2 + g, pos.Y + size2, pos.X - size2, pos.Y + size2 - g);
                gp.AddLine(pos.X - size2, pos.Y + size2 - g, pos.X - g, pos.Y);
                gp.AddLine(pos.X - g, pos.Y, pos.X - size2, pos.Y - size2 + g);
                break;

            case MarkerStyle.Star:
            {
                XPoint[] points = new XPoint[10];

                double radStep     = 2 * Math.PI / 5;
                double outerCircle = size / 2;
                double innerCircle = size / 5;
                // outer circle
                double rad = -(Math.PI / 2);         // 90�
                for (int idx = 0; idx < 10; idx += 2)
                {
                    points[idx].X = pos.X + outerCircle * Math.Cos(rad);
                    points[idx].Y = pos.Y + outerCircle * Math.Sin(rad);
                    rad          += radStep;
                }

                // inner circle
                rad = -(Math.PI / 4);         // 45�
                double x = innerCircle * Math.Cos(rad);
                double y = innerCircle * Math.Sin(rad);
                points[1].X = pos.X + x;
                points[1].Y = pos.Y + y;
                points[9].X = pos.X - x;
                points[9].Y = pos.Y + y;
                rad        += radStep;
                x           = innerCircle * Math.Cos(rad);
                y           = innerCircle * Math.Sin(rad);
                points[3].X = pos.X + x;
                points[3].Y = pos.Y + y;
                points[7].X = pos.X - x;
                points[7].Y = pos.Y + y;
                rad        += radStep;
                y           = innerCircle * Math.Sin(rad);
                points[5].X = pos.X;
                points[5].Y = pos.Y + y;
                gp.AddLines(points);
            }
            break;
            }

            gp.CloseFigure();
            if (rendererInfo.MarkerStyle != MarkerStyle.Dot)
            {
                graphics.DrawPath(background, gp);
                graphics.DrawPath(foreground, gp);
            }
        }