Exemple #1
0
        private void Initial()
        {
            string     _d               = _attrList.GetValue("d");
            SVGPathSeg lastSegment      = null;
            SVGPathSeg firstPathSegment = null;

            List <char>   _charList  = new List <char>();
            List <string> _valueList = new List <string>();

            SVGStringExtractor.ExtractPathSegList(_d, ref _charList, ref _valueList);
            _segList = new SVGPathSegList(_charList.Count);
            int i, j, paramsLength;

            for (i = 0; i < _charList.Count; i++)
            {
                //lastSegment = _segList.GetLastItem();
                char _char = _charList [i];

                string _value = _valueList [i];

                float[] parms = SVGStringExtractor.ExtractTransformValueAsPX(_value);
                paramsLength = parms.Length;

                switch (_char)
                {
                case 'Z':
                case 'z':
                    if (_segList.Count > 0 && firstPathSegment != null)
                    {
                        lastSegment = _segList.AppendItem(new SVGPathSegLinetoAbs(firstPathSegment.currentPoint.x, firstPathSegment.currentPoint.y, lastSegment));
                    }
                    _segList.AppendItem(CreateSVGPathSegClosePath());
                    firstPathSegment = null;
                    break;

                case 'M':
                    if (lastSegment != null && lastSegment.type != SVGPathSegTypes.Close && lastSegment.type != SVGPathSegTypes.MoveTo_Abs && lastSegment.type != SVGPathSegTypes.MoveTo_Rel)
                    {
                        firstPathSegment = null;
                    }
                    if (paramsLength < 2)
                    {
                        continue;
                    }
                    for (j = 0; j < paramsLength; j += 2)
                    {
                        if (paramsLength - j < 2)
                        {
                            continue;
                        }
                        lastSegment = _segList.AppendItem(new SVGPathSegMovetoAbs(parms [j], parms [j + 1], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'm':
                    if (lastSegment != null && lastSegment.type != SVGPathSegTypes.Close && lastSegment.type != SVGPathSegTypes.MoveTo_Abs && lastSegment.type != SVGPathSegTypes.MoveTo_Rel)
                    {
                        firstPathSegment = null;
                    }
                    if (paramsLength < 2)
                    {
                        continue;
                    }
                    for (j = 0; j < paramsLength; j += 2)
                    {
                        if (paramsLength - j < 2)
                        {
                            continue;
                        }
                        lastSegment = _segList.AppendItem(new SVGPathSegMovetoRel(parms [j], parms [j + 1], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'L':
                    if (paramsLength < 2)
                    {
                        continue;
                    }
                    for (j = 0; j < paramsLength; j += 2)
                    {
                        if (paramsLength - j < 2)
                        {
                            continue;
                        }
                        lastSegment = _segList.AppendItem(new SVGPathSegLinetoAbs(parms [j], parms [j + 1], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'l':
                    if (paramsLength < 2)
                    {
                        continue;
                    }
                    for (j = 0; j < paramsLength; j += 2)
                    {
                        if (paramsLength - j < 2)
                        {
                            continue;
                        }
                        lastSegment = _segList.AppendItem(new SVGPathSegLinetoRel(parms [j], parms [j + 1], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'C':
                    if (paramsLength < 6)
                    {
                        continue;
                    }
                    for (j = 0; j < paramsLength; j += 6)
                    {
                        if (paramsLength - j < 6)
                        {
                            continue;
                        }
                        lastSegment = _segList.AppendItem(new SVGPathSegCurvetoCubicAbs(parms [j], parms [j + 1], parms [j + 2], parms [j + 3], parms [j + 4], parms [j + 5], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'c':
                    if (paramsLength < 6)
                    {
                        continue;
                    }
                    for (j = 0; j < paramsLength; j += 6)
                    {
                        if (paramsLength - j < 6)
                        {
                            continue;
                        }
//                            Debug.Log(string.Format("CubicCurveRel: {0}, {1}, {2}, {3}, {4}, {5}", parms [j], parms [j + 1], parms [j + 2], parms [j + 3], parms [j + 4], parms [j + 5]));
                        lastSegment = _segList.AppendItem(new SVGPathSegCurvetoCubicRel(parms [j], parms [j + 1], parms [j + 2], parms [j + 3], parms [j + 4], parms [j + 5], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'S':
                    if (paramsLength < 4)
                    {
                        continue;
                    }
                    for (j = 0; j < paramsLength; j += 4)
                    {
                        if (paramsLength - j < 4)
                        {
                            continue;
                        }
                        lastSegment = _segList.AppendItem(new SVGPathSegCurvetoCubicSmoothAbs(parms [j], parms [j + 1], parms [j + 2], parms [j + 3], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 's':
                    if (paramsLength < 4)
                    {
                        continue;
                    }
                    for (j = 0; j < paramsLength; j += 4)
                    {
                        if (paramsLength - j < 4)
                        {
                            continue;
                        }
                        lastSegment = _segList.AppendItem(new SVGPathSegCurvetoCubicSmoothRel(parms [j], parms [j + 1], parms [j + 2], parms [j + 3], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'Q':
                    if (paramsLength < 4)
                    {
                        continue;
                    }
                    for (j = 0; j < paramsLength; j += 4)
                    {
                        if (paramsLength - j < 4)
                        {
                            continue;
                        }
                        lastSegment = _segList.AppendItem(new SVGPathSegCurvetoQuadraticAbs(parms [j], parms [j + 1], parms [j + 2], parms [j + 3], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'q':
                    if (paramsLength < 4)
                    {
                        continue;
                    }
                    for (j = 0; j < paramsLength; j += 4)
                    {
                        if (paramsLength - j < 4)
                        {
                            continue;
                        }
                        lastSegment = _segList.AppendItem(new SVGPathSegCurvetoQuadraticRel(parms [j], parms [j + 1], parms [j + 2], parms [j + 3], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'T':
                    if (paramsLength < 2)
                    {
                        continue;
                    }
                    for (j = 0; j < paramsLength; j += 2)
                    {
                        if (paramsLength - j < 2)
                        {
                            continue;
                        }
                        lastSegment = _segList.AppendItem(new SVGPathSegCurvetoQuadraticSmoothAbs(parms [j], parms [j + 1], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 't':
                    if (paramsLength < 2)
                    {
                        continue;
                    }
                    for (j = 0; j < paramsLength; j += 2)
                    {
                        if (paramsLength - j < 2)
                        {
                            continue;
                        }
                        lastSegment = _segList.AppendItem(new SVGPathSegCurvetoQuadraticSmoothRel(parms [j], parms [j + 1], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'A':
                    if (paramsLength < 7)
                    {
                        continue;
                    }
                    for (j = 0; j < paramsLength; j += 7)
                    {
                        if (paramsLength - j < 7)
                        {
                            continue;
                        }
                        lastSegment = _segList.AppendItem(new SVGPathSegArcAbs(parms [j], parms [j + 1], parms [j + 2], parms [j + 3] == 1f, parms [j + 4] == 1f, parms [j + 5], parms [j + 6], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'a':
                    if (paramsLength < 7)
                    {
                        continue;
                    }
                    for (j = 0; j < paramsLength; j += 7)
                    {
                        if (paramsLength - j < 7)
                        {
                            continue;
                        }
                        lastSegment = _segList.AppendItem(new SVGPathSegArcRel(parms [j], parms [j + 1], parms [j + 2], parms [j + 3] == 1f, parms [j + 4] == 1f, parms [j + 5], parms [j + 6], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'H':
                    for (j = 0; j < paramsLength; j++)
                    {
                        lastSegment = _segList.AppendItem(new SVGPathSegLinetoHorizontalAbs(parms [j], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'h':
                    for (j = 0; j < paramsLength; j++)
                    {
                        lastSegment = _segList.AppendItem(new SVGPathSegLinetoHorizontalRel(parms [j], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'V':
                    for (j = 0; j < paramsLength; j++)
                    {
                        lastSegment = _segList.AppendItem(new SVGPathSegLinetoVerticalAbs(parms [j], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;

                case 'v':
                    for (j = 0; j < paramsLength; j++)
                    {
                        lastSegment = _segList.AppendItem(new SVGPathSegLinetoVerticalRel(parms [j], lastSegment));
                        if (firstPathSegment == null)
                        {
                            firstPathSegment = lastSegment;
                        }
                    }
                    break;
                }
            }
        }
    /***********************************************************************************/
    private void Initial()
    {
        currentTransformList = new SVGTransformList(_attrList.GetValue("transform"));

        //-----------
        string _d = _attrList.GetValue("d");

        List <char>   _charList  = new List <char>();
        List <string> _valueList = new List <string>();

        SVGStringExtractor.ExtractPathSegList(_d, ref _charList, ref _valueList);
        _segList = new SVGPathSegList(_charList.Count);
        for (int i = 0; i < _charList.Count; i++)
        {
            char    _char  = _charList[i];
            string  _value = _valueList[i];
            float[] parms  = SVGStringExtractor.ExtractTransformValueAsPX(_value);
            switch (_char)
            {
            case 'Z':
            case 'z':
                _segList.AppendItem(CreateSVGPathSegClosePath());
                break;

            case 'M':
                _segList.AppendItem(new SVGPathSegMovetoAbs(parms[0], parms[1]));
                break;

            case 'm':
                _segList.AppendItem(new SVGPathSegMovetoRel(parms[0], parms[1]));
                break;

            case 'L':
                _segList.AppendItem(new SVGPathSegLinetoAbs(parms[0], parms[1]));
                break;

            case 'l':
                _segList.AppendItem(new SVGPathSegLinetoRel(parms[0], parms[1]));
                break;

            case 'C':
                _segList.AppendItem(new SVGPathSegCurvetoCubicAbs(parms[0], parms[1], parms[2], parms[3], parms[4], parms[5]));
                break;

            case 'c':
                _segList.AppendItem(new SVGPathSegCurvetoCubicRel(parms[0], parms[1], parms[2], parms[3], parms[4], parms[5]));
                break;

            case 'S':
                _segList.AppendItem(new SVGPathSegCurvetoCubicSmoothAbs(parms[0], parms[1], parms[2], parms[3]));
                break;

            case 's':
                _segList.AppendItem(new SVGPathSegCurvetoCubicSmoothRel(parms[0], parms[1], parms[2], parms[3]));
                break;

            case 'Q':
                _segList.AppendItem(new SVGPathSegCurvetoQuadraticAbs(parms[0], parms[1], parms[2], parms[3]));
                break;

            case 'q':
                _segList.AppendItem(new SVGPathSegCurvetoQuadraticRel(parms[0], parms[1], parms[2], parms[3]));
                break;

            case 'T':
                _segList.AppendItem(new SVGPathSegCurvetoQuadraticSmoothAbs(parms[0], parms[1]));
                break;

            case 't':
                _segList.AppendItem(new SVGPathSegCurvetoQuadraticSmoothRel(parms[0], parms[1]));
                break;

            case 'A':
                _segList.AppendItem(new SVGPathSegArcAbs(parms[0], parms[1], parms[2], parms[3] == 1f, parms[4] == 1f, parms[5], parms[6]));
                break;

            case 'a':
                _segList.AppendItem(new SVGPathSegArcRel(parms[0], parms[1], parms[2], parms[3] == 1f, parms[4] == 1f, parms[5], parms[6]));
                break;

            case 'H':
                _segList.AppendItem(new SVGPathSegLinetoHorizontalAbs(parms[0]));
                break;

            case 'h':
                _segList.AppendItem(new SVGPathSegLinetoHorizontalRel(parms[0]));
                break;

            case 'V':
                _segList.AppendItem(new SVGPathSegLinetoVerticalAbs(parms[0]));
                break;

            case 'v':
                _segList.AppendItem(new SVGPathSegLinetoVerticalRel(parms[0]));
                break;
            }
        }
    }