Example #1
0
    public SVGPathElement(Dictionary<string, string> attrList, SVGTransformList inheritTransformList,
                        SVGPaintable inheritPaintable, SVGGraphics r)
        : base(inheritTransformList)
    {
        Profiler.BeginSample("SVGPathElement constructor");
        _paintable = new SVGPaintable(inheritPaintable, attrList);
        _render = r;
        currentTransformList = new SVGTransformList(attrList.GetValue("transform"));

        string dstr = attrList.GetValue("d");
        int nbSegments = 0;
        for(int i = 0; i < dstr.Length; ++i) {
          switch(dstr[i]) {
          case 'Z':
          case 'z':
          case 'M':
          case 'm':
          case 'L':
          case 'l':
          case 'C':
          case 'c':
          case 'S':
          case 's':
          case 'Q':
          case 'q':
          case 'T':
          case 't':
          case 'A':
          case 'a':
          case 'H':
          case 'h':
          case 'V':
          case 'v':
        ++nbSegments;
        break;
          }
        }

        _segList = new SVGPathSegList(nbSegments); // optimization: count number of segments before starting
        for(int i = 0; i < dstr.Length;) {
          while(i < dstr.Length - 1 && dstr[i] == ' ') // skip whitespace before type character
        ++i;
          char _char = dstr[i];
          switch(_char) {
          case 'Z':
          case 'z':
        _segList.AppendItem(CreateSVGPathSegClosePath());
        ++i;
        break;
          case 'M': {
        try {
          float a = ReadFloat(dstr, ref i);
          float b = ReadFloat(dstr, ref i);
          _segList.AppendItem(new SVGPathSegMovetoAbs(a, b));
        } catch(Exception) {
          Debug.Log("exception when parsing " + dstr);
          throw;
        }
        break;
          }
          case 'm': {
        float a = ReadFloat(dstr, ref i);
        float b = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegMovetoRel(a, b));
        break;
          }
          case 'L': {
        float a = ReadFloat(dstr, ref i);
        float b = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegLinetoAbs(a, b));
        break;
          }
          case 'l': {
        float a = ReadFloat(dstr, ref i);
        float b = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegLinetoRel(a, b));
        break;
          }
          case 'C': {
        float a = ReadFloat(dstr, ref i);
        float b = ReadFloat(dstr, ref i);
        float c = ReadFloat(dstr, ref i);
        float d = ReadFloat(dstr, ref i);
        float e = ReadFloat(dstr, ref i);
        float f = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegCurvetoCubicAbs(a, b, c, d, e, f));
        break;
          }
          case 'c': {
        float a = ReadFloat(dstr, ref i);
        float b = ReadFloat(dstr, ref i);
        float c = ReadFloat(dstr, ref i);
        float d = ReadFloat(dstr, ref i);
        float e = ReadFloat(dstr, ref i);
        float f = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegCurvetoCubicRel(a, b, c, d, e, f));
        break;
          }
          case 'S': {
        float a = ReadFloat(dstr, ref i);
        float b = ReadFloat(dstr, ref i);
        float c = ReadFloat(dstr, ref i);
        float d = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegCurvetoCubicSmoothAbs(a, b, c, d));
        break;
          }
          case 's': {
        float a = ReadFloat(dstr, ref i);
        float b = ReadFloat(dstr, ref i);
        float c = ReadFloat(dstr, ref i);
        float d = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegCurvetoCubicSmoothRel(a, b, c, d));
        break;
          }
          case 'Q': {
        float a = ReadFloat(dstr, ref i);
        float b = ReadFloat(dstr, ref i);
        float c = ReadFloat(dstr, ref i);
        float d = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegCurvetoQuadraticAbs(a, b, c, d));
        break;
          }
          case 'q': {
        float a = ReadFloat(dstr, ref i);
        float b = ReadFloat(dstr, ref i);
        float c = ReadFloat(dstr, ref i);
        float d = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegCurvetoQuadraticRel(a, b, c, d));
        break;
          }
          case 'T': {
        float a = ReadFloat(dstr, ref i);
        float b = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegCurvetoQuadraticSmoothAbs(a, b));
        break;
          }
          case 't': {
        float a = ReadFloat(dstr, ref i);
        float b = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegCurvetoQuadraticSmoothRel(a, b));
        break;
          }
          case 'A': {
        float a = ReadFloat(dstr, ref i);
        float b = ReadFloat(dstr, ref i);
        float c = ReadFloat(dstr, ref i);
        bool d = ReadFloat(dstr, ref i) > 0;
        bool e = ReadFloat(dstr, ref i) > 0;
        float f = ReadFloat(dstr, ref i);
        float g = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegArcAbs(a, b, c, d, e, f, g));
        break;
          }
          case 'a': {
        float a = ReadFloat(dstr, ref i);
        float b = ReadFloat(dstr, ref i);
        float c = ReadFloat(dstr, ref i);
        bool d = ReadFloat(dstr, ref i) > 0;
        bool e = ReadFloat(dstr, ref i) > 0;
        float f = ReadFloat(dstr, ref i);
        float g = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegArcRel(a, b, c, d, e, f, g));
        break;
          }
          case 'H': {
        float a = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegLinetoHorizontalAbs(a));
        break;
          }
          case 'h': {
        float a = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegLinetoHorizontalRel(a));
        break;
          }
          case 'V': {
        float a = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegLinetoVerticalAbs(a));
        break;
          }
          case 'v': {
        float a = ReadFloat(dstr, ref i);
        _segList.AppendItem(new SVGPathSegLinetoVerticalRel(a));
        break;
          }
          default:
        ++i;
        break;
          }
        }

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

        //SVGStringExtractor.ExtractPathSegList(dstr, 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;
        //  }
        //}
        Profiler.EndSample();
    }
Example #2
0
    /***********************************************************************************/
    private void Initial()
    {
        currentTransformList = new SVGTransformList(_attrList.GetValue("transform"));
        _segList = new SVGPathSegList();

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

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

        SVGStringExtractor.ExtractPathSegList(_d, ref _charList, ref _valueList);
        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;
          }
        }
    }
Example #3
0
 internal void SetList(SVGPathSegList segList)
 {
     this._segList = segList;
 }