/// <summary> /// Parses the Path-String /// </summary> /// <param name="path">the Path-String</param> private void Parse(string path) { PathCommandTokenizer tok = new PathCommandTokenizer(path); PathCommand.PathCommandType cmd = PathCommand.PathCommandType.Nothing; PathCommandToken[] tmp; PathCommandToken t; while ((t = tok.GetNextToken()) != null) { switch (t.Type) { case PathCommandSequenceToken.CommandMoveTo: cmd = PathCommand.PathCommandType.MoveTo; tmp = new PathCommandToken[] { tok.GetNextToken(), tok.GetNextToken() }; list.Add(new PathCommand(cmd, tmp)); break; case PathCommandSequenceToken.CommandLineTo: cmd = PathCommand.PathCommandType.LineTo; tmp = new PathCommandToken[] { tok.GetNextToken(), tok.GetNextToken() }; list.Add(new PathCommand(cmd, tmp)); break; case PathCommandSequenceToken.Number: case PathCommandSequenceToken.Formula: tmp = new PathCommandToken[] { t, tok.GetNextToken() }; list.Add(new PathCommand(cmd, tmp)); break; case PathCommandSequenceToken.CommandClose: cmd = PathCommand.PathCommandType.CloseLine; list.Add(new PathCommand(cmd)); break; case PathCommandSequenceToken.CommandEnd: cmd = PathCommand.PathCommandType.EndLine; list.Add(new PathCommand(cmd)); break; } } }
/// <summary> /// Path as a string. /// </summary> /// <returns></returns> public override string ToString() { System.Text.StringBuilder ret = new System.Text.StringBuilder(); PathCommand.PathCommandType lastCommand = PathCommand.PathCommandType.Nothing; for (int i = 0; i < list.Count; i++) { int pcount = 0; switch (this[i].Command) { case PathCommand.PathCommandType.Nothing: break; case PathCommand.PathCommandType.MoveTo: if (lastCommand != this[i].Command) { ret.Append("m"); } pcount = 2; break; case PathCommand.PathCommandType.LineTo: if (lastCommand != this[i].Command) { ret.Append("l"); } pcount = 2; break; case PathCommand.PathCommandType.CloseLine: ret.Append("x"); break; case PathCommand.PathCommandType.EndLine: ret.Append("e"); break; } // only write needed chars for (int j = 0; j < pcount; j++) { switch (this[i].Param[j].Type) { case PathCommandSequenceToken.Formula: ret.Append(this[i].Param[j].ToString()); break; case PathCommandSequenceToken.Number: if ((lastCommand == this[i].Command)) { ret.Append(","); } else if (j == 1) { ret.Append(","); } if ((this[i].Param[j].Value) != 0) { ret.Append(this[i].Param[j].ToString()); } break; default: // every other should not appear ;-) // may throw an exeption here ?! break; } } lastCommand = this[i].Command; } return(ret.ToString()); }