Commit 69c4a7ed authored by Ralf Kornelius's avatar Ralf Kornelius
Browse files

Write fill attribute value if it differs from parent element

If elements are nested in groups and have different fill values than
their containing group the fill value wouldn't be written correctly.
parent a31f24c1
...@@ -61,5 +61,13 @@ namespace Svg ...@@ -61,5 +61,13 @@ namespace Svg
} }
public override bool Equals(object obj)
{
var objColor = obj as SvgColourServer;
if (objColor == null)
return false;
return this.Colour.ToArgb() == objColor.Colour.ToArgb();
}
} }
} }
...@@ -347,17 +347,30 @@ namespace Svg ...@@ -347,17 +347,30 @@ namespace Svg
{ {
object propertyValue = attr.Property.GetValue(this); object propertyValue = attr.Property.GetValue(this);
var forceWrite = false;
if ((attr.Attribute.Name == "fill") && (Parent != null))
{
var parentValue = ResolveParentAttributeValue(attr.Attribute.Name);
if (parentValue != null)
{
if (parentValue.Equals(propertyValue))
continue;
forceWrite = true;
}
}
if (propertyValue != null) if (propertyValue != null)
{ {
var type = propertyValue.GetType(); var type = propertyValue.GetType();
string value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string)); string value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string));
if (!SvgDefaults.IsDefault(attr.Attribute.Name, value)) if (!SvgDefaults.IsDefault(attr.Attribute.Name, value) || forceWrite)
{ {
writer.WriteAttributeString(attr.Attribute.NamespaceAndName, value); writer.WriteAttributeString(attr.Attribute.NamespaceAndName, value);
} }
} }
else if(attr.Attribute.Name == "fill") //if fill equals null, write 'none' else if (attr.Attribute.Name == "fill") //if fill equals null, write 'none'
{ {
string value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string)); string value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string));
writer.WriteAttributeString(attr.Attribute.NamespaceAndName, value); writer.WriteAttributeString(attr.Attribute.NamespaceAndName, value);
...@@ -370,7 +383,27 @@ namespace Svg ...@@ -370,7 +383,27 @@ namespace Svg
{ {
writer.WriteAttributeString(item.Key, item.Value); writer.WriteAttributeString(item.Key, item.Value);
} }
}
private object ResolveParentAttributeValue(string attributeKey)
{
attributeKey = char.ToUpper(attributeKey[0]) + attributeKey.Substring(1);
object parentValue = null;
var currentParent = Parent;
while (currentParent != null)
{
if (currentParent.Attributes.ContainsKey(attributeKey))
{
parentValue = currentParent.Attributes[attributeKey];
if (parentValue != null)
break;
}
currentParent = currentParent.Parent;
}
return parentValue;
} }
protected virtual void Write(XmlTextWriter writer) protected virtual void Write(XmlTextWriter writer)
......
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