Exemplo n.º 1
0
        /// <summary>
        /// Parse a PathFigureCollection string.
        /// </summary>
        internal static PathFigureCollection ParsePathFigureCollection(
            string pathString,
            IFormatProvider formatProvider)
        {
            PathStreamGeometryContext context = new PathStreamGeometryContext();

            AbbreviatedGeometryParser parser = new AbbreviatedGeometryParser();

            parser.ParseToGeometryContext(context, pathString, 0 /* curIndex */);

            PathGeometry pathGeometry = context.GetPathGeometry();

            return(pathGeometry.Figures);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Given a mini-language representation of a Geometry - write it to the supplied StreamGeometryContext
        /// </summary>
        /// <param name="context">context </param>
        /// <param name="pathString">path to parse</param>
        /// <param name="fillRule">returned fill rule, if the string contains a fill rule set explicitly at the beginning</param>
        private static void ParseStringToStreamGeometryContext(StreamGeometryContext context, string pathString, ref FillRule fillRule)
        {
            // Check to ensure that there's something to parse
            if (pathString == null)
            {
                return;
            }

            int curIndex = 0;

            // skip any leading space
            while ((curIndex < pathString.Length) && Char.IsWhiteSpace(pathString, curIndex))
            {
                curIndex++;
            }

            // Is there anything to look at?
            if (curIndex < pathString.Length)
            {
                // If so, we only care if the first non-WhiteSpace char encountered is 'F'
                if (pathString[curIndex] == 'F')
                {
                    curIndex++;

                    // Since we found 'F' the next non-WhiteSpace char must be 0 or 1 - look for it.
                    while ((curIndex < pathString.Length) && Char.IsWhiteSpace(pathString, curIndex))
                    {
                        curIndex++;
                    }

                    // If we ran out of text, this is an error, because 'F' cannot be specified without 0 or 1
                    // Also, if the next token isn't 0 or 1, this too is illegal
                    if ((curIndex == pathString.Length) ||
                        ((pathString[curIndex] != '0') &&
                         (pathString[curIndex] != '1')))
                    {
                        throw new FormatException("Token is not valid.");
                    }

                    fillRule = pathString[curIndex] == '0' ? FillRule.EvenOdd : FillRule.Nonzero;

                    // Increment curIndex to point to the next char
                    curIndex++;
                }
            }

            AbbreviatedGeometryParser parser = new AbbreviatedGeometryParser(pathString);

            parser.ParseToGeometryContext(context, curIndex);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parse a PathFigureCollection string.
        /// </summary>
        internal static PathFigureCollection ParsePathFigureCollection(
            string pathString,
            IFormatProvider formatProvider)
        {
            PathStreamGeometryContext context = new PathStreamGeometryContext();

            AbbreviatedGeometryParser parser = new AbbreviatedGeometryParser();

            parser.ParseToGeometryContext(context, pathString, 0 /* curIndex */);
            
            PathGeometry pathGeometry = context.GetPathGeometry();

            return pathGeometry.Figures;
        }