public static List <PathCommand> ParseCommands(string s) { var parts = s.Split(' '); var commands = new List <PathCommand>(); var ci = CultureInfo.InvariantCulture; int startIndex = 0; while (startIndex < parts.Length) { var commandStr = parts[startIndex]; if (commandStr.Length != 1) { throw new SvgParseException(Messages.IncorrectPathData); } // Assume all not float string are commands float f; int endIndex = startIndex + 1; var values = new List <float>(); while (endIndex < parts.Length && float.TryParse(parts[endIndex], NumberStyles.Float, ci, out f)) { values.Add(f); endIndex++; } var command = new PathCommand(commandStr, values); commands.Add(command); startIndex = endIndex; } return(commands); }
public override IEnumerable <SvgAttribute> GetAttributes() { var baseAttributes = base.GetAttributes(); if (baseAttributes != null) { foreach (var attr in baseAttributes) { yield return(attr); } } var ci = CultureInfo.InvariantCulture; yield return(new SvgAttribute("stroke-width", () => StrokeWidth.ToString(ci), v => StrokeWidth = SvgAttribute.ParseFloatAttribute(v) )); yield return(new SvgAttribute("stroke", () => ColorTranslator.ToSvg(Stroke), v => Stroke = SvgAttribute.ParseColorAttribute(v, Stroke.A) )); yield return(new SvgAttribute("stroke-opacity", "1", () => ((double)Stroke.A / 255).ToString(ci), v => Stroke = SvgAttribute.ParseOpacityAttribute(v, Stroke) )); yield return(new SvgAttribute("fill", "", () => ColorTranslator.ToSvg(Fill), v => Fill = SvgAttribute.ParseColorAttribute(v, Fill.A) )); yield return(new SvgAttribute("fill-opacity", "1", () => ((double)Fill.A / 255).ToString(ci), v => Fill = SvgAttribute.ParseOpacityAttribute(v, Fill) )); yield return(new SvgAttribute("d", () => PathCommand.ToSvgString(Path), v => Path = PathCommand.ParseCommands(v) )); }