Commit edc594e1 authored by davescriven's avatar davescriven
Browse files

- Fixed [workitem:7526] whitespaces \t \r \n in path and points result in...

- Fixed [workitem:7526] whitespaces \t \r \n in path and points result in exception. The   SvgUnitCollectionConverter (SvgUnitCollection.cs) class had to split on \r, \t and \n aswell as ' ' and ','.
parent 773803a4
...@@ -46,9 +46,9 @@ namespace Svg ...@@ -46,9 +46,9 @@ namespace Svg
} }
} }
} }
catch catch (Exception exc)
{ {
Trace.TraceError("Error rendering points."); Trace.TraceError("Error rendering points: " + exc.Message);
} }
this.IsPathDirty = false; this.IsPathDirty = false;
} }
......
...@@ -34,7 +34,7 @@ namespace Svg ...@@ -34,7 +34,7 @@ namespace Svg
{ {
if (value is string) if (value is string)
{ {
string[] points = ((string)value).Split(new char[]{',', ' '}, StringSplitOptions.RemoveEmptyEntries); string[] points = ((string)value).Trim().Split(new char[] { ',', ' ', '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries);
SvgUnitCollection units = new SvgUnitCollection(); SvgUnitCollection units = new SvgUnitCollection();
foreach (string point in points) foreach (string point in points)
......
...@@ -26,7 +26,7 @@ namespace Svg ...@@ -26,7 +26,7 @@ namespace Svg
// http://www.w3.org/TR/CSS21/syndata.html#values // http://www.w3.org/TR/CSS21/syndata.html#values
// http://www.w3.org/TR/SVG11/coords.html#Units // http://www.w3.org/TR/SVG11/coords.html#Units
string unit = value as string; string unit = (string)value;
int identifierIndex = -1; int identifierIndex = -1;
for (int i = 0; i < unit.Length; i++) for (int i = 0; i < unit.Length; i++)
......
...@@ -32,7 +32,7 @@ namespace Svg ...@@ -32,7 +32,7 @@ namespace Svg
foreach (var commandSet in SplitCommands(path.TrimEnd(null))) foreach (var commandSet in SplitCommands(path.TrimEnd(null)))
{ {
coords = new List<float>(ParseCoordinates(commandSet)); coords = new List<float>(ParseCoordinates(commandSet.Trim()));
command = commandSet[0]; command = commandSet[0];
isRelative = char.IsLower(command); isRelative = char.IsLower(command);
// http://www.w3.org/TR/SVG11/paths.html#PathDataGeneralInformation // http://www.w3.org/TR/SVG11/paths.html#PathDataGeneralInformation
...@@ -211,17 +211,23 @@ namespace Svg ...@@ -211,17 +211,23 @@ namespace Svg
commandStart = i; commandStart = i;
if (!string.IsNullOrEmpty(command)) if (!string.IsNullOrEmpty(command))
{
yield return command; yield return command;
}
if (path.Length == i + 1) if (path.Length == i + 1)
{
yield return path[i].ToString(); yield return path[i].ToString();
}
} }
else if (path.Length == i + 1) else if (path.Length == i + 1)
{ {
command = path.Substring(commandStart, i - commandStart + 1).Trim(); command = path.Substring(commandStart, i - commandStart + 1).Trim();
if (!string.IsNullOrEmpty(command)) if (!string.IsNullOrEmpty(command))
{
yield return command; yield return command;
}
} }
} }
} }
...@@ -229,17 +235,21 @@ namespace Svg ...@@ -229,17 +235,21 @@ namespace Svg
private static IEnumerable<float> ParseCoordinates(string coords) private static IEnumerable<float> ParseCoordinates(string coords)
{ {
// TODO: Handle "1-1" (new PointF(1, -1); // TODO: Handle "1-1" (new PointF(1, -1);
var parts = coords.Remove(0, 1).Replace("-", " -").Split(new[] { ',', ' ' }, var parts = coords.Remove(0, 1).Replace("-", " -").Split(new[] { ',', ' '},
StringSplitOptions.RemoveEmptyEntries); StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < parts.Length; i++) for (var i = 0; i < parts.Length; i++)
yield return float.Parse(parts[i], NumberStyles.Float, CultureInfo.InvariantCulture); {
yield return float.Parse(parts[i].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture);
}
} }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{ {
if (value is string) if (value is string)
{
return Parse((string)value); return Parse((string)value);
}
return base.ConvertFrom(context, culture, value); return base.ConvertFrom(context, culture, value);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment