private void parseString(string d)
{
ISvgPathSeg seg;
string[] segs = rePathCmd.Split(d);
foreach(string s in segs)
{
string segment = s.Trim();
if(segment.Length > 0)
{
char cmd = (char) segment.ToCharArray(0,1)[0];
float[] coords = getCoords(segment);
int length = coords.Length;
switch(cmd)
{
#region moveto
case 'M':
for(int i = 0; i<length; i+=2)
{
if(i == 0)
{
seg = new SvgPathSegMovetoAbs(
coords[i],
coords[i+1]
);
}
else
{
seg = new SvgPathSegLinetoAbs(
coords[i],
coords[i+1]
);
}
AppendItem(seg);
}
break;
case 'm':
for(int i = 0; i<length; i+=2)
{
if(i == 0)
{
seg = new SvgPathSegMovetoRel(
coords[i],
coords[i+1]
);
}
else
{
seg = new SvgPathSegLinetoRel(
coords[i],
coords[i+1]
);
}
AppendItem(seg);
}
break;
#endregion
#region lineto
case 'L':
for(int i = 0; i<length; i+=2)
{
seg = new SvgPathSegLinetoAbs(
coords[i],
coords[i+1]
);
AppendItem(seg);
}
break;
case 'l':
for(int i = 0; i<length; i+=2)
{
seg = new SvgPathSegLinetoRel(
coords[i],
coords[i+1]
);
AppendItem(seg);
}
break;
case 'H':
for(int i = 0; i<length; i++)
{
seg = new SvgPathSegLinetoHorizontalAbs(
coords[i]
);
AppendItem(seg);
}
break;
case 'h':
for(int i = 0; i<length; i++)
{
seg = new SvgPathSegLinetoHorizontalRel(
coords[i]
);
AppendItem(seg);
}
break;
case 'V':
for(int i = 0; i<length; i++)
{
seg = new SvgPathSegLinetoVerticalAbs(
coords[i]
);
AppendItem(seg);
}
break;
case'v':
for(int i = 0; i<length; i++)
{
seg = new SvgPathSegLinetoVerticalRel(
coords[i]
);
AppendItem(seg);
}
break;
#endregion
#region beziers
case 'C':
for(int i = 0; i<length; i+=6)
{
seg = new SvgPathSegCurvetoCubicAbs(
coords[i+4],
coords[i+5],
coords[i],
coords[i+1],
coords[i+2],
coords[i+3]
);
AppendItem(seg);
}
break;
case 'c':
for(int i = 0; i<length; i+=6)
{
seg = new SvgPathSegCurvetoCubicRel(
coords[i+4],
coords[i+5],
coords[i],
coords[i+1],
coords[i+2],
coords[i+3]
);
AppendItem(seg);
}
break;
case 'S':
for(int i = 0; i<length; i+=4)
{
seg = new SvgPathSegCurvetoCubicSmoothAbs(
coords[i+2],
coords[i+3],
coords[i],
coords[i+1]
);
AppendItem(seg);
}
break;
case's':
for(int i = 0; i<length; i+=4)
{
seg = new SvgPathSegCurvetoCubicSmoothRel(
coords[i+2],
coords[i+3],
coords[i],
coords[i+1]
);
AppendItem(seg);
}
break;
case 'Q':
for(int i = 0; i<length; i+=4)
{
seg = new SvgPathSegCurvetoQuadraticAbs(
coords[i+2],
coords[i+3],
coords[i],
coords[i+1]
);
AppendItem(seg);
}
break;
case 'q':
for(int i = 0; i<length; i+=4)
{
seg = new SvgPathSegCurvetoQuadraticRel(
coords[i+2],
coords[i+3],
coords[i],
coords[i+1]
);
AppendItem(seg);
}
break;
case 'T':
for(int i = 0; i<length; i+=2)
{
seg = new SvgPathSegCurvetoQuadraticSmoothAbs(
coords[i],
coords[i+1]
);
AppendItem(seg);
}
break;
case 't':
for(int i = 0; i<length; i+=2)
{
seg = new SvgPathSegCurvetoQuadraticSmoothRel(
coords[i],
coords[i+1]
);
AppendItem(seg);
}
break;
#endregion
#region arcs
case 'A':
case 'a':
for(int i = 0; i<length; i+=7)
{
if(cmd=='A')
{
seg = new SvgPathSegArcAbs(
coords[i+5],
coords[i+6],
coords[i],
coords[i+1],
coords[i+2],
(coords[i+3]!=0),
(coords[i+4]!=0)
);
}
else
{
seg = new SvgPathSegArcRel(
coords[i+5],
coords[i+6],
coords[i],
coords[i+1],
coords[i+2],
(coords[i+3]!=0),
(coords[i+4]!=0)
);
}
AppendItem(seg);
}
break;
#endregion
#region close
case 'z':
case 'Z':
seg = new SvgPathSegClosePath();
AppendItem(seg);
break;
#endregion
#region Unknown path command
default:
throw new ApplicationException("Unknown path command");
#endregion
}
}
}
}