Ejemplo n.º 1
0
        private static CanvasGeometry CreateCookieCore(ICanvasResourceCreator resourceCreator, Matrix3x2 oneMatrix, float innerRadius, float sweepAngle)
        {
            // start tooth
            Vector2 startTooth = new Vector2(1, 0);
            // end tooth
            Vector2 endTooth = TransformerGeometry.GetRotationVector(sweepAngle);

            CanvasPathBuilder pathBuilder   = new CanvasPathBuilder(resourceCreator);
            CanvasArcSize     canvasArcSize = (sweepAngle < System.Math.PI) ? CanvasArcSize.Large : CanvasArcSize.Small;

            {
                // DonutAndCookie
                // start notch
                Vector2 startNotch = startTooth * innerRadius;
                // end notch
                Vector2 endNotch = endTooth * innerRadius;

                // start tooth point
                pathBuilder.BeginFigure(startNotch);
                // start notch point
                pathBuilder.AddArc(endNotch, innerRadius, innerRadius, sweepAngle, CanvasSweepDirection.CounterClockwise, canvasArcSize);
            }

            // end notch point
            pathBuilder.AddLine(endTooth);

            // end tooth point
            pathBuilder.AddArc(startTooth, 1, 1, sweepAngle, CanvasSweepDirection.Clockwise, canvasArcSize);

            pathBuilder.EndFigure(CanvasFigureLoop.Closed);

            return(CanvasGeometry.CreatePath(pathBuilder).Transform(oneMatrix));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// ctor
 /// </summary>
 public ArcElement()
 {
     _radiusX        = _radiusY = _angle = 0;
     _arcSize        = CanvasArcSize.Small;
     _sweepDirection = CanvasSweepDirection.Clockwise;
     _sweepDirection = 0;
     _x = _y = 0;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds a single arc to the path, specified by start and end points through which an ellipse will be fitted.
 /// </summary>
 /// <param name="point">Start Point</param>
 /// <param name="x">radiusX</param>
 /// <param name="y">radiusY</param>
 /// <param name="z">rotationAngle</param>
 /// <param name="sweepDirection"><see cref="CanvasSweepDirection"/></param>
 /// <param name="arcSize"><see cref="CanvasArcSize"/></param>
 public void AddArc(Vector2 point, float x, float y, float z, CanvasSweepDirection sweepDirection, CanvasArcSize arcSize)
 {
     _cmdBuilder.AppendLine($"    pathBuilder.AddArc(new Vector2({point.X}, {point.Y}), {x}, {y}, {z}, {sweepDirection}, {arcSize});");
 }
        protected void DrawGaugeArc(CanvasControl sender, CanvasDrawingSession ds, float startAngle, float endAngle, Color color, CanvasSweepDirection canvasSweepDirection, CanvasArcSize canvasArcSize)
        {
            using (CanvasPathBuilder cp = new CanvasPathBuilder(sender))
            {
                var startPoint = this.Center + Vector2.Transform(Vector2.UnitX, Matrix3x2.CreateRotation(startAngle)) * this.Radius;
                var endPoint   = this.Center + Vector2.Transform(Vector2.UnitX, Matrix3x2.CreateRotation(endAngle)) * this.Radius;

                cp.BeginFigure(startPoint);
                cp.AddArc(endPoint, this.Radius, this.Radius, 0, canvasSweepDirection, canvasArcSize);
                cp.EndFigure(CanvasFigureLoop.Open);

                using (var geometry = CanvasGeometry.CreatePath(cp))
                {
                    ds.DrawGeometry(geometry, color, c_arcThickness, this.ArcStrokeStyle);
                }
            }
        }
Ejemplo n.º 5
0
 public void AddArc(Vector2 point, float x, float y, float z, CanvasSweepDirection sweepDirection, CanvasArcSize arcSize)
 {
     wasAddArcCalled = true;
 }
Ejemplo n.º 6
0
 public void AddArc(Vector2 point, float x, float y, float z, CanvasSweepDirection sweepDirection, CanvasArcSize arcSize)
 {
     throw new NotSupportedException("This is never called, since we use CanvasGeometrySimplification.Lines on the geometry.");
 }
Ejemplo n.º 7
0
 public void AddArc(Vector2 endPoint, float radiusX, float radiusY, float rotationAngle, CanvasSweepDirection sweepDirection, CanvasArcSize arcSize)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Adds a single arc to the path, specified by start and end points through which
 /// an ellipse will be fitted.
 /// </summary>
 /// <param name="endPoint"> The end-point. </param>
 /// <param name="radiusX"> The radius X. </param>
 /// <param name="radiusY"> The radius Y. </param>
 /// <param name="rotationAngle"> The angle of rotation. </param>
 /// <param name="sweepDirection"> The direction for sweep. </param>
 /// <param name="arcSize"> The size of arc. </param>
 public void AddArc(Vector2 endPoint, float radiusX, float radiusY, float rotationAngle, CanvasSweepDirection sweepDirection, CanvasArcSize arcSize)
 {
 }
Ejemplo n.º 9
0
 public void AddArc(Vector2 point, float x, float y, float z, CanvasSweepDirection sweepDirection, CanvasArcSize arcSize)
 {
     // Ignored
 }
Ejemplo n.º 10
0
 public void AddArc(Vector2 endPoint, float radiusX, float radiusY, float rotationAngle, CanvasSweepDirection sweepDirection, CanvasArcSize arcSize)
 {
     System.Diagnostics.Debug.WriteLine(string.Format("Arc: {0}:{1}:{2}", endPoint, radiusX, radiusY));
 }
Ejemplo n.º 11
0
 public void AddArc(Vector2 endPoint, float radiusX, float radiusY, float rotationAngle, CanvasSweepDirection sweepDirection, CanvasArcSize arcSize)
 {
     _builder.AppendFormat("A {0} {1} {2} {3} {4} {5} {6} ",
                           radiusX, radiusY, rotationAngle, (int)arcSize, (int)sweepDirection, endPoint.X, endPoint.Y);
 }
Ejemplo n.º 12
0
 public void AddArc(Vector2 point, float x, float y, float z, CanvasSweepDirection sweepDirection, CanvasArcSize arcSize)
 {
     wasAddArcCalled = true;
 }
Ejemplo n.º 13
0
        /*public override object Clone()
         * {
         *  SVGPath clone = new SVGPath();
         *  clone._gp = (GraphicsPath)_gp.Clone();
         *  clone._ID = _ID;
         *  clone._strPath = (String)_strPath.Clone();
         *  return clone;
         * }*/

        private void parsePath(CanvasPathBuilder pb, String path)
        {
            char[]    delimiter        = { ' ' };
            string[]  commands         = Regex.Split(path, _regex1);
            string[]  values           = null;
            float[]   points           = new float[7];
            Vector2[] Vector2s         = new Vector2[4];
            Vector2   lastPoint        = new Vector2(0, 0);
            Vector2   lastControlPoint = new Vector2(0, 0);

            //Vector2 firstPoint = new Vector2(0, 0);
            //Vector2 firstPoint = new Vector2(0, 0);

            try
            {
                for (int i = 0; i < commands.Length; i++)
                {
                    String strCommand = commands[i];
                    char   action     = (strCommand != null && strCommand.Length > 0) ? strCommand[0] : ' ';
                    values = strCommand.Split(delimiter);

                    if (action == 'M')
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1));
                        points[1] = -(float)Convert.ToDouble(values[1]);
                        lastPoint = new Vector2(points[0], points[1]);
                        //firstPoint = new Vector2(points[0], points[1]);

                        pb.BeginFigure(lastPoint);
                    }
                    else if (action == 'm')
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.X;
                        points[1] = -(float)Convert.ToDouble(values[1]) + lastPoint.Y;

                        pb.BeginFigure(points[0], points[1]);
                        lastPoint.X = points[0];
                        lastPoint.Y = points[1];
                        pb.BeginFigure(lastPoint);
                    }
                    else if (action == 'L')//capital letter is absolute location
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1));
                        points[1] = -(float)Convert.ToDouble(values[1]);

                        pb.AddLine(points[0], points[1]);

                        lastPoint.X = points[0];
                        lastPoint.Y = points[1];
                    }
                    else if (action == 'l')//lowercase letter is relative location
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.X;
                        points[1] = -(float)Convert.ToDouble(values[1]) + lastPoint.Y;

                        pb.AddLine(points[0], points[1]);

                        lastPoint.X = points[0];
                        lastPoint.Y = points[1];
                    }
                    else if (action == 'H')
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1));

                        pb.AddLine(points[0], lastPoint.Y);

                        lastPoint.X = points[0];
                    }
                    else if (action == 'h')
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.X;

                        pb.AddLine(points[0], lastPoint.Y);

                        lastPoint.X = points[0];
                    }
                    else if (action == 'V')
                    {
                        points[0] = -(float)Convert.ToDouble(values[0].Substring(1));

                        pb.AddLine(lastPoint.X, points[0]);

                        lastPoint.Y = points[0];
                    }
                    else if (action == 'v')
                    {
                        points[0] = -(float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.Y;

                        pb.AddLine(lastPoint.X, points[0]);

                        lastPoint.Y = points[0];
                    }
                    else if (action == 'C')//cubic bezier, 2 control points
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1));
                        points[1] = -(float)Convert.ToDouble(values[1]);
                        points[2] = (float)Convert.ToDouble(values[2]);
                        points[3] = -(float)Convert.ToDouble(values[3]);
                        points[4] = (float)Convert.ToDouble(values[4]);
                        points[5] = -(float)Convert.ToDouble(values[5]);

                        Vector2s[0] = lastPoint;
                        Vector2s[1] = new Vector2(points[0], points[1]);
                        Vector2s[2] = new Vector2(points[2], points[3]);
                        Vector2s[3] = new Vector2(points[4], points[5]);

                        //_gp.AddBezier(Vector2s[0], Vector2s[1], Vector2s[2], Vector2s[3]);
                        pb.AddCubicBezier(Vector2s[1], Vector2s[2], Vector2s[3]);

                        lastPoint        = Vector2s[3];
                        lastControlPoint = Vector2s[2];
                    }
                    else if (action == 'c')
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.X;
                        points[1] = -(float)Convert.ToDouble(values[1]) + lastPoint.Y;
                        points[2] = (float)Convert.ToDouble(values[2]) + lastPoint.X;
                        points[3] = -(float)Convert.ToDouble(values[3]) + lastPoint.Y;
                        points[4] = (float)Convert.ToDouble(values[4]) + lastPoint.X;
                        points[5] = -(float)Convert.ToDouble(values[5]) + lastPoint.Y;

                        Vector2s[0] = lastPoint;
                        Vector2s[1] = new Vector2(points[0], points[1]);
                        Vector2s[2] = new Vector2(points[2], points[3]);
                        Vector2s[3] = new Vector2(points[4], points[5]);

                        //_gp.AddBezier(Vector2s[0], Vector2s[1], Vector2s[2], Vector2s[3]);
                        pb.AddCubicBezier(Vector2s[1], Vector2s[2], Vector2s[3]);

                        lastPoint        = Vector2s[3];
                        lastControlPoint = Vector2s[2];
                    }
                    else if (action == 'S')
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1));
                        points[1] = -(float)Convert.ToDouble(values[1]);
                        points[2] = (float)Convert.ToDouble(values[2]);
                        points[3] = -(float)Convert.ToDouble(values[3]);

                        Vector2s[0] = lastPoint;
                        Vector2s[1] = mirrorControlPoint(lastControlPoint, lastPoint);
                        Vector2s[2] = new Vector2(points[0], points[1]);
                        Vector2s[3] = new Vector2(points[2], points[3]);

                        //_gp.AddBezier(Vector2s[0], Vector2s[1], Vector2s[2], Vector2s[3]);
                        pb.AddCubicBezier(Vector2s[1], Vector2s[2], Vector2s[3]);

                        lastPoint        = Vector2s[3];
                        lastControlPoint = Vector2s[2];
                    }
                    else if (action == 's')
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.X;
                        points[1] = -(float)Convert.ToDouble(values[1]) + lastPoint.Y;
                        points[2] = (float)Convert.ToDouble(values[2]) + lastPoint.X;
                        points[3] = -(float)Convert.ToDouble(values[3]) + lastPoint.Y;

                        Vector2s[0] = lastPoint;
                        Vector2s[1] = mirrorControlPoint(lastControlPoint, lastPoint);
                        Vector2s[2] = new Vector2(points[0], points[1]);
                        Vector2s[3] = new Vector2(points[2], points[3]);

                        //_gp.AddBezier(Vector2s[0], Vector2s[1], Vector2s[2], Vector2s[3]);
                        pb.AddCubicBezier(Vector2s[1], Vector2s[2], Vector2s[3]);

                        lastPoint        = Vector2s[3];
                        lastControlPoint = Vector2s[2];
                    }
                    else if (action == 'Q')//quadratic bezier, 1 control point
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1));
                        points[1] = -(float)Convert.ToDouble(values[1]);
                        points[2] = (float)Convert.ToDouble(values[2]);
                        points[3] = -(float)Convert.ToDouble(values[3]);


                        //convert quadratic to cubic bezier
                        Vector2 QP0 = lastPoint;
                        Vector2 QP1 = new Vector2(points[0], points[1]);
                        Vector2 QP2 = new Vector2(points[2], points[3]);

                        Vector2 CP0 = QP0;
                        Vector2 CP3 = QP2;

                        //old
                        //Vector2 CP1 = new Vector2((QP0.X + 2.0f * QP1.X) / 3.0f, (QP0.Y + 2.0f * QP1.Y) / 3.0f);
                        //Vector2 CP2 = new Vector2((QP2.X + 2.0f * QP1.X) / 3.0f, (QP2.Y + 2.0f * QP1.Y) / 3.0f);

                        //new
                        Vector2 CP1 = new Vector2(QP0.X + 2.0f / 3.0f * (QP1.X - QP0.X), QP0.Y + 2.0f / 3.0f * (QP1.Y - QP0.Y));
                        Vector2 CP2 = new Vector2(QP2.X + 2.0f / 3.0f * (QP1.X - QP2.X), QP2.Y + 2.0f / 3.0f * (QP1.Y - QP2.Y));

                        //_gp.AddBezier(CP0, CP1, CP2, CP3);
                        //pb.AddCubicBezier(CP1, CP2, QP2);
                        pb.AddQuadraticBezier(QP1, QP2);

                        lastPoint = QP2;

                        lastControlPoint = QP1;
                    }
                    else if (action == 'q')
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.X;
                        points[1] = -(float)Convert.ToDouble(values[1]) + lastPoint.Y;
                        points[2] = (float)Convert.ToDouble(values[2]) + lastPoint.X;
                        points[3] = -(float)Convert.ToDouble(values[3]) + lastPoint.Y;


                        //convert quadratic to cubic bezier
                        Vector2 QP0 = lastPoint;
                        Vector2 QP1 = new Vector2(points[0], points[1]);
                        Vector2 QP2 = new Vector2(points[2], points[3]);

                        Vector2 CP0 = QP0;
                        Vector2 CP3 = QP2;

                        //old
                        //Vector2 CP1 = new Vector2((QP0.X + 2.0f * QP1.X) / 3.0f, (QP0.Y + 2.0f * QP1.Y) / 3.0f);
                        //Vector2 CP2 = new Vector2((QP2.X + 2.0f * QP1.X) / 3.0f, (QP2.Y + 2.0f * QP1.Y) / 3.0f);
                        //new
                        //Vector2 CP1 = new Vector2(QP0.X + 2.0f / 3.0f * (QP1.X - QP0.X), QP0.Y + 2.0f / 3.0f * (QP1.Y - QP0.Y));
                        //Vector2 CP2 = new Vector2(QP2.X + 2.0f / 3.0f * (QP1.X - QP2.X), QP2.Y + 2.0f / 3.0f * (QP1.Y - QP2.Y));

                        //_gp.AddBezier(CP0, CP1, CP2, CP3);
                        //pb.AddCubicBezier(CP1, CP2, QP2);
                        pb.AddQuadraticBezier(QP1, QP2);


                        lastPoint = QP2;

                        lastControlPoint = QP1;
                    }
                    else if (action == 'T')
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1));
                        points[1] = -(float)Convert.ToDouble(values[1]);

                        //convert quadratic to bezier
                        Vector2 QP0 = lastPoint;
                        Vector2 QP1 = mirrorControlPoint(lastControlPoint, QP0);
                        Vector2 QP2 = new Vector2(points[0], points[1]);

                        Vector2 CP0 = QP0;
                        Vector2 CP3 = QP2;

                        //Vector2 CP1 = new Vector2((QP0.X + 2.0f * QP1.X) / 3.0f, (QP0.Y + 2.0f * QP1.Y) / 3.0f);
                        //Vector2 CP2 = new Vector2((QP2.X + 2.0f * QP1.X) / 3.0f, (QP2.Y + 2.0f * QP1.Y) / 3.0f);

                        //Vector2 CP1 = new Vector2(QP0.X + 2.0f / 3.0f * (QP1.X - QP0.X), QP0.Y + 2.0f / 3.0f * (QP1.Y - QP0.Y));
                        //Vector2 CP2 = new Vector2(QP2.X + 2.0f / 3.0f * (QP1.X - QP2.X), QP2.Y + 2.0f / 3.0f * (QP1.Y - QP2.Y));


                        //_gp.AddBezier(CP0, CP1, CP2, CP3);
                        //pb.AddCubicBezier(CP1, CP2, QP2);
                        pb.AddQuadraticBezier(QP1, QP2);


                        lastPoint = QP2;

                        lastControlPoint = QP1;
                    }
                    else if (action == 't')
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.X;
                        points[1] = -(float)Convert.ToDouble(values[1]) + lastPoint.Y;

                        //convert quadratic to bezier
                        Vector2 QP0 = lastPoint;
                        Vector2 QP1 = mirrorControlPoint(lastControlPoint, QP0);
                        Vector2 QP2 = new Vector2(points[0], points[1]);

                        Vector2 CP0 = QP0;
                        Vector2 CP3 = QP2;

                        //Vector2 CP1 = new Vector2((QP0.X + 2.0f * QP1.X) / 3.0f, (QP0.Y + 2.0f * QP1.Y) / 3.0f);
                        //Vector2 CP2 = new Vector2((QP2.X + 2.0f * QP1.X) / 3.0f, (QP2.Y + 2.0f * QP1.Y) / 3.0f);

                        //Vector2 CP1 = new Vector2(QP0.X + 2.0f / 3.0f * (QP1.X - QP0.X), QP0.Y + 2.0f / 3.0f * (QP1.Y - QP0.Y));
                        //Vector2 CP2 = new Vector2(QP2.X + 2.0f / 3.0f * (QP1.X - QP2.X), QP2.Y + 2.0f / 3.0f * (QP1.Y - QP2.Y));


                        //_gp.AddBezier(CP0, CP1, CP2, CP3);
                        //pb.AddCubicBezier(CP1, CP2, QP2);
                        pb.AddQuadraticBezier(QP1, QP2);


                        lastPoint = QP2;

                        lastControlPoint = QP1;
                    }
                    else if (action == 'A')
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1)); //radiusX
                        points[1] = (float)Convert.ToDouble(values[1]);              //radiusY
                        points[2] = (float)Convert.ToDouble(values[2]);              //angle
                        points[3] = (float)Convert.ToDouble(values[3]);              //size
                        points[4] = (float)Convert.ToDouble(values[4]);              //sweep
                        points[5] = (float)Convert.ToDouble(values[5]);              //endX
                        points[6] = -(float)Convert.ToDouble(values[6]);             //endY

                        //SvgArcSize sas = points[3] == 0 ? SvgArcSize.Small : SvgArcSize.Large;
                        //SvgArcSweep sasw = points[4] == 0 ? SvgArcSweep.Negative : SvgArcSweep.Positive;
                        Vector2 endPoint = new Vector2(points[5], points[6]);

                        //SvgArcSegment arc = new SvgArcSegment(lastPoint, points[0], points[1], points[2], sas, sasw, endPoint);
                        //arc.AddToPath(_gp);

                        CanvasArcSize        arcSize = CanvasArcSize.Large;            //if size = 1, size is large.  0 for small
                        CanvasSweepDirection sweep   = CanvasSweepDirection.Clockwise; //if sweep == 1, sweep is clockwise or positive

                        if (points[3] == 0.0f)
                        {
                            arcSize = CanvasArcSize.Small;
                        }
                        if (points[4] == 0.0f)
                        {
                            sweep = CanvasSweepDirection.CounterClockwise;
                        }

                        pb.AddArc(new Vector2(points[5], points[6]), points[0], points[1], points[2], sweep, arcSize);


                        //AddArcToPath(_gp, lastPoint, points[0], points[1], points[2], (int)points[3], (int)points[4], endPoint);

                        lastPoint.X = points[5];
                        lastPoint.Y = points[6];
                    }
                    else if (action == 'a')
                    {
                        points[0] = (float)Convert.ToDouble(values[0].Substring(1));
                        points[1] = (float)Convert.ToDouble(values[1]);
                        points[2] = (float)Convert.ToDouble(values[2]);
                        points[3] = (float)Convert.ToDouble(values[3]);
                        points[4] = (float)Convert.ToDouble(values[4]);
                        points[5] = (float)Convert.ToDouble(values[5] + lastPoint.X);
                        points[6] = -(float)Convert.ToDouble(values[6] + lastPoint.Y);

                        //SvgArcSize sas = points[3] == 0 ? SvgArcSize.Small : SvgArcSize.Large;
                        //SvgArcSweep sasw = points[4] == 0 ? SvgArcSweep.Negative : SvgArcSweep.Positive;
                        Vector2 endPoint = new Vector2(points[5], points[6]);

                        //SvgArcSegment arc = new SvgArcSegment(lastPoint, points[0], points[1], points[2], sas, sasw, endPoint);
                        //arc.AddToPath(_gp);

                        CanvasArcSize        arcSize = CanvasArcSize.Large;            //if size = 1, size is large.  0 for small
                        CanvasSweepDirection sweep   = CanvasSweepDirection.Clockwise; //if sweep == 1, sweep is clockwise or positive

                        if (points[3] == 0.0f)
                        {
                            arcSize = CanvasArcSize.Small;
                        }
                        if (points[4] == 0.0f)
                        {
                            sweep = CanvasSweepDirection.CounterClockwise;
                        }

                        pb.AddArc(new Vector2(points[5], points[6]), points[0], points[1], points[2], sweep, arcSize);

                        //AddArcToPath(_gp, lastPoint, points[0], points[1], points[2], (int)points[3], (int)points[4], endPoint);

                        lastPoint.X = points[5];
                        lastPoint.Y = points[6];
                    }
                    else if (action == 'Z' || action == 'z')
                    {
                        pb.EndFigure(CanvasFigureLoop.Closed);
                    }
                }
                _cg = CanvasGeometry.CreatePath(pb);
            }
            catch (Exception exc)
            {
                Debug.WriteLine(exc.Message);
                Debug.WriteLine(exc.StackTrace);

                ErrorLogger.LogException("SVGPath", "parsePath", exc);
            }
        }