Commit 837e0963 authored by Dan Backes's avatar Dan Backes
Browse files

Colors Fix, Perf Improvement, Thread Safety

-Fixes issues with colors not parsing correctly. Saving an SvgDocument
resulted in RGB color values being converted to well known color names.

-Compile regex statements to improve performance.

-Make rendering a document threadsafe.
parent efd6005f
Showing with 17 additions and 13 deletions
+17 -13
......@@ -115,7 +115,7 @@ namespace Svg
if (destinationType == typeof(string))
{
var colour = (Color)value;
return ColorTranslator.ToHtml(colour);
return "#" + colour.R.ToString("X2", null) + colour.G.ToString("X2", null) + colour.B.ToString("X2", null);
}
return base.ConvertTo(context, culture, value, destinationType);
......
......@@ -276,7 +276,7 @@ namespace Svg
private static IEnumerable<float> ParseCoordinates(string coords)
{
var parts = Regex.Split(coords.Remove(0, 1), @"[\s,]|(?=(?<!e)-)");
var parts = Regex.Split(coords.Remove(0, 1), @"[\s,]|(?=(?<!e)-)", RegexOptions.Compiled);
for (int i = 0; i < parts.Length; i++)
{
......
......@@ -157,30 +157,34 @@ namespace Svg
}
private static Dictionary<Type, Dictionary<string, PropertyDescriptorCollection>> _propertyDescriptors = new Dictionary<Type, Dictionary<string, PropertyDescriptorCollection>>();
private static object syncLock = new object();
private static void SetPropertyValue(SvgElement element, string attributeName, string attributeValue, SvgDocument document)
{
var elementType = element.GetType();
PropertyDescriptorCollection properties;
if (_propertyDescriptors.Keys.Contains(elementType))
lock (syncLock)
{
if (_propertyDescriptors[elementType].Keys.Contains(attributeName))
if (_propertyDescriptors.Keys.Contains(elementType))
{
properties = _propertyDescriptors[elementType][attributeName];
if (_propertyDescriptors[elementType].Keys.Contains(attributeName))
{
properties = _propertyDescriptors[elementType][attributeName];
}
else
{
properties = TypeDescriptor.GetProperties(elementType, new[] { new SvgAttributeAttribute(attributeName) });
_propertyDescriptors[elementType].Add(attributeName, properties);
}
}
else
{
properties = TypeDescriptor.GetProperties(elementType, new[] { new SvgAttributeAttribute(attributeName) });
_propertyDescriptors[elementType].Add(attributeName, properties);
}
}
else
{
properties = TypeDescriptor.GetProperties(elementType, new[] { new SvgAttributeAttribute(attributeName) });
_propertyDescriptors.Add(elementType, new Dictionary<string, PropertyDescriptorCollection>());
_propertyDescriptors.Add(elementType, new Dictionary<string, PropertyDescriptorCollection>());
_propertyDescriptors[elementType].Add(attributeName, properties);
_propertyDescriptors[elementType].Add(attributeName, properties);
}
}
if (properties.Count > 0)
......
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