Parse() public method

Parse a SVG path geometry string.
public Parse ( XGeometryContext context, string pathString, int startIndex ) : void
context XGeometryContext The geometry context.
pathString string The path geometry string
startIndex int The string start index.
return void
コード例 #1
0
ファイル: XPathGeometryParser.cs プロジェクト: Core2D/Core2D
        /// <summary>
        /// Parse a mini-language string representation of the <see cref="XPathGeometry"/>.
        /// </summary>
        /// <remarks>
        /// The path geometry syntax may start with a "wsp*Fwsp*(0|1)" which indicate the winding mode (F0 is EvenOdd while F1 is NonZero).
        /// </remarks>
        /// <param name="source">The string with geometry data.</param>
        /// <returns>The new instance of the <see cref="XPathGeometry"/> class.</returns>
        public static XPathGeometry Parse(string source)
        {
            var fillRule = XFillRule.EvenOdd;
            var geometry = XPathGeometry.Create(ImmutableArray.Create<XPathFigure>(), fillRule);

            if (source != null)
            {
                int curIndex = 0;
                while ((curIndex < source.Length) && Char.IsWhiteSpace(source, curIndex))
                {
                    curIndex++;
                }

                if (curIndex < source.Length)
                {
                    if (source[curIndex] == 'F')
                    {
                        curIndex++;

                        while ((curIndex < source.Length) && Char.IsWhiteSpace(source, curIndex))
                        {
                            curIndex++;
                        }

                        if ((curIndex == source.Length) || ((source[curIndex] != '0') && (source[curIndex] != '1')))
                        {
                            throw new FormatException("Illegal token.");
                        }

                        fillRule = source[curIndex] == '0' ? XFillRule.EvenOdd : XFillRule.Nonzero;
                        curIndex++;
                    }
                }

                var parser = new SvgToXPathGeometryParser();
                var context = new XPathGeometryContext(geometry);

                parser.Parse(context, source, curIndex);
            }

            geometry.FillRule = fillRule;

            return geometry;
        }
コード例 #2
0
        /// <summary>
        /// Parse a mini-language string representation of the <see cref="XPathGeometry"/>.
        /// </summary>
        /// <remarks>
        /// The path geometry syntax may start with a "wsp*Fwsp*(0|1)" which indicate the winding mode (F0 is EvenOdd while F1 is NonZero).
        /// </remarks>
        /// <param name="source">The string with geometry data.</param>
        /// <returns>The new instance of the <see cref="XPathGeometry"/> class.</returns>
        public static XPathGeometry Parse(string source)
        {
            var fillRule = XFillRule.EvenOdd;
            var geometry = XPathGeometry.Create(ImmutableArray.Create <XPathFigure>(), fillRule);

            if (source != null)
            {
                int curIndex = 0;
                while ((curIndex < source.Length) && Char.IsWhiteSpace(source, curIndex))
                {
                    curIndex++;
                }

                if (curIndex < source.Length)
                {
                    if (source[curIndex] == 'F')
                    {
                        curIndex++;

                        while ((curIndex < source.Length) && Char.IsWhiteSpace(source, curIndex))
                        {
                            curIndex++;
                        }

                        if ((curIndex == source.Length) || ((source[curIndex] != '0') && (source[curIndex] != '1')))
                        {
                            throw new FormatException("Illegal token.");
                        }

                        fillRule = source[curIndex] == '0' ? XFillRule.EvenOdd : XFillRule.Nonzero;
                        curIndex++;
                    }
                }

                var parser  = new SvgToXPathGeometryParser();
                var context = new XPathGeometryContext(geometry);

                parser.Parse(context, source, curIndex);
            }

            geometry.FillRule = fillRule;

            return(geometry);
        }