From 128185099fbfc9e38fe36cfa7df17df82dcbd4fb Mon Sep 17 00:00:00 2001 From: Ralf Kornelius Date: Thu, 20 Jun 2013 11:46:14 +0200 Subject: [PATCH] Support "none" in Fill value if inherited from parent Support "none" in Fill value if inherited from parent --- Source/Document Structure/SvgGroup.cs | 2 +- Source/Painting/SvgColourServer.cs | 7 ++++++- Source/SvgElement.cs | 25 ++++++++++++++----------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Source/Document Structure/SvgGroup.cs b/Source/Document Structure/SvgGroup.cs index 52ff11a..c6e2f7d 100644 --- a/Source/Document Structure/SvgGroup.cs +++ b/Source/Document Structure/SvgGroup.cs @@ -26,7 +26,7 @@ namespace Svg [SvgAttribute("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; } } diff --git a/Source/Painting/SvgColourServer.cs b/Source/Painting/SvgColourServer.cs index 8f2bcf7..9afddff 100644 --- a/Source/Painting/SvgColourServer.cs +++ b/Source/Painting/SvgColourServer.cs @@ -67,7 +67,12 @@ namespace Svg if (objColor == null) return false; - return this.Colour.ToArgb() == objColor.Colour.ToArgb(); + return this.GetHashCode() == objColor.GetHashCode(); + } + + public override int GetHashCode() + { + return _colour.GetHashCode(); } } } diff --git a/Source/SvgElement.cs b/Source/SvgElement.cs index 654a9e5..a959e10 100644 --- a/Source/SvgElement.cs +++ b/Source/SvgElement.cs @@ -350,12 +350,13 @@ namespace Svg var forceWrite = false; if ((attr.Attribute.Name == "fill") && (Parent != null)) { - var parentValue = ResolveParentAttributeValue(attr.Attribute.Name); - if (parentValue != null) + object parentValue; + if (TryResolveParentAttributeValue(attr.Attribute.Name, out parentValue)) { - if (parentValue.Equals(propertyValue)) + if ((parentValue == propertyValue) + || ((parentValue != null) && parentValue.Equals(propertyValue))) continue; - + forceWrite = true; } } @@ -370,7 +371,7 @@ namespace Svg 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)); writer.WriteAttributeString(attr.Attribute.NamespaceAndName, value); @@ -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 resolved = false; while (currentParent != null) { if (currentParent.Attributes.ContainsKey(attributeKey)) { - parentValue = currentParent.Attributes[attributeKey]; - if (parentValue != null) + resolved = true; + parentAttributeValue = currentParent.Attributes[attributeKey]; + if (parentAttributeValue != null) break; } currentParent = currentParent.Parent; } - return parentValue; + return resolved; } protected virtual void Write(XmlTextWriter writer) -- GitLab