Commit 12818509 authored by Ralf Kornelius's avatar Ralf Kornelius
Browse files

Support "none" in Fill value if inherited from parent

Support "none" in Fill value if inherited from parent
parent 69c4a7ed
...@@ -26,7 +26,7 @@ namespace Svg ...@@ -26,7 +26,7 @@ namespace Svg
[SvgAttribute("fill")] [SvgAttribute("fill")]
public override SvgPaintServer Fill public override SvgPaintServer Fill
{ {
get { return (this.Attributes["Fill"] == null) ? new SvgColourServer(Color.Transparent) : (SvgPaintServer)this.Attributes["Fill"]; } get { return (this.Attributes["Fill"] == null) ? null : (SvgPaintServer)this.Attributes["Fill"]; }
set { this.Attributes["Fill"] = value; } set { this.Attributes["Fill"] = value; }
} }
......
...@@ -67,7 +67,12 @@ namespace Svg ...@@ -67,7 +67,12 @@ namespace Svg
if (objColor == null) if (objColor == null)
return false; return false;
return this.Colour.ToArgb() == objColor.Colour.ToArgb(); return this.GetHashCode() == objColor.GetHashCode();
}
public override int GetHashCode()
{
return _colour.GetHashCode();
} }
} }
} }
...@@ -350,12 +350,13 @@ namespace Svg ...@@ -350,12 +350,13 @@ namespace Svg
var forceWrite = false; var forceWrite = false;
if ((attr.Attribute.Name == "fill") && (Parent != null)) if ((attr.Attribute.Name == "fill") && (Parent != null))
{ {
var parentValue = ResolveParentAttributeValue(attr.Attribute.Name); object parentValue;
if (parentValue != null) if (TryResolveParentAttributeValue(attr.Attribute.Name, out parentValue))
{ {
if (parentValue.Equals(propertyValue)) if ((parentValue == propertyValue)
|| ((parentValue != null) && parentValue.Equals(propertyValue)))
continue; continue;
forceWrite = true; forceWrite = true;
} }
} }
...@@ -370,7 +371,7 @@ namespace Svg ...@@ -370,7 +371,7 @@ namespace Svg
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);
...@@ -385,25 +386,27 @@ namespace Svg ...@@ -385,25 +386,27 @@ namespace Svg
} }
} }
private object ResolveParentAttributeValue(string attributeKey) private bool TryResolveParentAttributeValue(string attributeKey, out object parentAttributeValue)
{ {
attributeKey = char.ToUpper(attributeKey[0]) + attributeKey.Substring(1); parentAttributeValue = null;
object parentValue = null; attributeKey = char.ToUpper(attributeKey[0]) + attributeKey.Substring(1);
var currentParent = Parent; var currentParent = Parent;
var resolved = false;
while (currentParent != null) while (currentParent != null)
{ {
if (currentParent.Attributes.ContainsKey(attributeKey)) if (currentParent.Attributes.ContainsKey(attributeKey))
{ {
parentValue = currentParent.Attributes[attributeKey]; resolved = true;
if (parentValue != null) parentAttributeValue = currentParent.Attributes[attributeKey];
if (parentAttributeValue != null)
break; break;
} }
currentParent = currentParent.Parent; currentParent = currentParent.Parent;
} }
return parentValue; return resolved;
} }
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