Пример #1
0
        /// <summary>
        /// Parse a PathFigureCollection string
        /// </summary>
        internal void ParseToGeometryContext(
            StreamGeometryContext context,
            string pathString,
            int startIndex)
        {
            // [BreakingChange] Dev10


            // From original code
            // This is only used in call to Double.Parse
            _formatProvider = System.Globalization.CultureInfo.InvariantCulture;

            _context    = context;
            _pathString = pathString;
            _pathLength = pathString.Length;
            _curIndex   = startIndex;

            _secondLastPoint = new Point(0, 0);
            _lastPoint       = new Point(0, 0);
            _lastStart       = new Point(0, 0);

            _figureStarted = false;

            bool first = true;

            char last_cmd = ' ';

            while (ReadToken()) // Empty path is allowed in XAML
            {
                char cmd = _token;

                if (first)
                {
                    if ((cmd != 'M') && (cmd != 'm'))  // Path starts with M|m
                    {
                        ThrowBadToken();
                    }

                    first = false;
                }

                switch (cmd)
                {
                case 'm':
                case 'M':
                    // XAML allows multiple points after M/m
                    _lastPoint = ReadPoint(cmd, !AllowComma);

                    context.BeginFigure(_lastPoint, IsFilled, !IsClosed);
                    _figureStarted = true;
                    _lastStart     = _lastPoint;
                    last_cmd       = 'M';

                    while (IsNumber(AllowComma))
                    {
                        _lastPoint = ReadPoint(cmd, !AllowComma);

                        context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin);
                        last_cmd = 'L';
                    }
                    break;

                case 'l':
                case 'L':
                case 'h':
                case 'H':
                case 'v':
                case 'V':
                    EnsureFigure();

                    do
                    {
                        switch (cmd)
                        {
                        case 'l': _lastPoint = ReadPoint(cmd, !AllowComma); break;

                        case 'L': _lastPoint = ReadPoint(cmd, !AllowComma); break;

                        case 'h': _lastPoint.X += ReadNumber(!AllowComma); break;

                        case 'H': _lastPoint.X = ReadNumber(!AllowComma); break;

                        case 'v': _lastPoint.Y += ReadNumber(!AllowComma); break;

                        case 'V': _lastPoint.Y = ReadNumber(!AllowComma); break;
                        }

                        context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin);
                    }while (IsNumber(AllowComma));

                    last_cmd = 'L';
                    break;

                case 'c':
                case 'C':           // cubic Bezier
                case 's':
                case 'S':           // smooth cublic Bezier
                    EnsureFigure();

                    do
                    {
                        Point p;

                        if ((cmd == 's') || (cmd == 'S'))
                        {
                            if (last_cmd == 'C')
                            {
                                p = Reflect();
                            }
                            else
                            {
                                p = _lastPoint;
                            }

                            _secondLastPoint = ReadPoint(cmd, !AllowComma);
                        }
                        else
                        {
                            p = ReadPoint(cmd, !AllowComma);

                            _secondLastPoint = ReadPoint(cmd, AllowComma);
                        }

                        _lastPoint = ReadPoint(cmd, AllowComma);

                        context.BezierTo(p, _secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin);

                        last_cmd = 'C';
                    }while (IsNumber(AllowComma));

                    break;

                case 'q':
                case 'Q':           // quadratic Bezier
                case 't':
                case 'T':           // smooth quadratic Bezier
                    EnsureFigure();

                    do
                    {
                        if ((cmd == 't') || (cmd == 'T'))
                        {
                            if (last_cmd == 'Q')
                            {
                                _secondLastPoint = Reflect();
                            }
                            else
                            {
                                _secondLastPoint = _lastPoint;
                            }

                            _lastPoint = ReadPoint(cmd, !AllowComma);
                        }
                        else
                        {
                            _secondLastPoint = ReadPoint(cmd, !AllowComma);
                            _lastPoint       = ReadPoint(cmd, AllowComma);
                        }

                        context.QuadraticBezierTo(_secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin);

                        last_cmd = 'Q';
                    }while (IsNumber(AllowComma));

                    break;

                case 'a':
                case 'A':
                    EnsureFigure();

                    do
                    {
                        // A 3,4 5, 0, 0, 6,7
                        double w        = ReadNumber(!AllowComma);
                        double h        = ReadNumber(AllowComma);
                        double rotation = ReadNumber(AllowComma);
                        bool   large    = ReadBool();
                        bool   sweep    = ReadBool();

                        _lastPoint = ReadPoint(cmd, AllowComma);

                        context.ArcTo(
                            _lastPoint,
                            new Size(w, h),
                            rotation,
                            large,
#if PBTCOMPILER
                            sweep,
#else
                            sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise,
#endif
                            IsStroked,
                            !IsSmoothJoin
                            );
                    }while (IsNumber(AllowComma));

                    last_cmd = 'A';
                    break;

                case 'z':
                case 'Z':
                    EnsureFigure();
                    context.SetClosedState(IsClosed);

                    _figureStarted = false;
                    last_cmd       = 'Z';

                    _lastPoint = _lastStart; // Set reference point to be first point of current figure
                    break;

                default:
                    ThrowBadToken();
                    break;
                }
            }
        }
Пример #2
0
 public static void Write(this StreamGeometryContext ctx, PathFigure pathFigure)
 {
     ctx.BeginFigure(pathFigure.StartPoint, pathFigure.IsFilled);
     pathFigure.Segments.ForEach(ctx.Write);
     ctx.SetClosedState(pathFigure.IsClosed);
 }
Пример #3
0
 public static void Write(this StreamGeometryContext ctx, LineGeometry lineGeometry)
 {
     ctx.BeginFigure(lineGeometry.StartPoint, false, false);
     ctx.LineTo(lineGeometry.EndPoint, true, false);
     ctx.SetClosedState(true);
 }