THIS IS A HORRIBLE ABOMINATION! PCLs dont have access to System.Drawing so this class is a wrapper for accessing the GraphicsPath class. It has the full public API that Nez needs for SVG files but the whole mess is all accessed via reflection. It is slow as all hell and not recommended for production use. It's only purpose is so that Nez works with SVG files out of the box to get up and running fast.
Пример #1
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 System.Numerics.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();
		}