pathPointsAsVectors() публичный Метод

public pathPointsAsVectors ( ) : Microsoft.Xna.Framework.Vector2[]
Результат Microsoft.Xna.Framework.Vector2[]
        /// <summary>
        /// takes in a parsed path and returns a list of points that can be used to draw the path
        /// </summary>
        /// <returns>The drawing points.</returns>
        /// <param name="segments">Segments.</param>
        public Vector2[] getDrawingPoints(List <SvgPathSegment> segments, float flatness = 3)
        {
            var path = new FauxGraphicsPath();

            for (var j = 0; j < segments.Count; j++)
            {
                var segment = segments[j];
                if (segment is SvgMoveToSegment)
                {
                    path.StartFigure();
                }
                else if (segment is SvgCubicCurveSegment)
                {
                    var cubicSegment = segment as SvgCubicCurveSegment;
                    path.AddBezier(toDrawPoint(segment.start), toDrawPoint(cubicSegment.firstCtrlPoint), toDrawPoint(cubicSegment.secondCtrlPoint), toDrawPoint(segment.end));
                }
                else if (segment is SvgClosePathSegment)
                {
                    // important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure.
                    if (path.PointCount > 0 && !path.PathPoints.GetValue(0).Equals(path.PathPoints.GetValue(path.PathPoints.Length - 1)))
                    {
                        var i = path.PathTypes.Length - 1;
                        while (i >= 0 && path.PathTypes[i] > 0)
                        {
                            i--;
                        }
                        if (i < 0)
                        {
                            i = 0;
                        }
                        path.AddLine(path.PathPoints.GetValue(path.PathPoints.Length - 1), path.PathPoints.GetValue(i));
                    }
                    path.CloseFigure();
                }
                else if (segment is SvgLineSegment)
                {
                    path.AddLine(toDrawPoint(segment.start), toDrawPoint(segment.end));
                }
                else if (segment is SvgQuadraticCurveSegment)
                {
                    var quadSegment = segment as SvgQuadraticCurveSegment;
                    path.AddBezier(toDrawPoint(segment.start), toDrawPoint(quadSegment.firstCtrlPoint), toDrawPoint(quadSegment.secondCtrlPoint), toDrawPoint(segment.end));
                }
                else
                {
                    Debug.warn("unknown type in getDrawingPoints");
                }
            }

            var matrix = System.Activator.CreateInstance(System.Type.GetType("System.Drawing.Drawing2D.Matrix, System.Drawing"));

            path.Flatten(matrix, flatness);

            return(path.pathPointsAsVectors());
        }
Пример #2
0
		/// <summary>
		/// takes in a parsed path and returns a list of points that can be used to draw the path
		/// </summary>
		/// <returns>The drawing points.</returns>
		/// <param name="segments">Segments.</param>
		public Vector2[] getDrawingPoints( List<SvgPathSegment> segments, float flatness = 3 )
		{
			var path = new FauxGraphicsPath();
			for( var j = 0; j < segments.Count; j++ )
			{
				var segment = segments[j];
				if( segment is SvgMoveToSegment )
				{
					path.StartFigure();
				}
				else if( segment is SvgCubicCurveSegment )
				{
					var cubicSegment = segment as SvgCubicCurveSegment;
					path.AddBezier( toDrawPoint( segment.start ), toDrawPoint( cubicSegment.firstCtrlPoint ), toDrawPoint( cubicSegment.secondCtrlPoint ), toDrawPoint( segment.end ) );
				}
				else if( segment is SvgClosePathSegment )
				{
					// important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure.
					if( path.PointCount > 0 && !path.PathPoints.GetValue( 0 ).Equals( path.PathPoints.GetValue( path.PathPoints.Length - 1 ) ) )
					{
						var i = path.PathTypes.Length - 1;
						while( i >= 0 && path.PathTypes[i] > 0 )
							i--;
						if( i < 0 )
							i = 0;
						path.AddLine( path.PathPoints.GetValue( path.PathPoints.Length - 1 ), path.PathPoints.GetValue( i ) );
					}
					path.CloseFigure();
				}
				else if( segment is SvgLineSegment )
				{
					path.AddLine( toDrawPoint( segment.start ), toDrawPoint( segment.end ) );
				}
				else if( segment is SvgQuadraticCurveSegment )
				{
					var quadSegment = segment as SvgQuadraticCurveSegment;
					path.AddBezier( toDrawPoint( segment.start ), toDrawPoint( quadSegment.firstCtrlPoint ), toDrawPoint( quadSegment.secondCtrlPoint ), toDrawPoint( segment.end ) );
				}
				else
				{
					Debug.warn( "unknown type in getDrawingPoints" );
				}
			}

			var matrix = System.Activator.CreateInstance( System.Type.GetType( "System.Drawing.Drawing2D.Matrix, System.Drawing" ) );
			path.Flatten( matrix, flatness );

			return path.pathPointsAsVectors();
		}