Commit 793997f0 authored by mrbean-bremen's avatar mrbean-bremen Committed by mrbean-bremen
Browse files

Write custom styles as styles instead of as properties

- fixes styles written as invalid properties
- fixes part of #129 (issues 2 an 3), added test images
parent 3cd48c3a
......@@ -33,8 +33,6 @@ namespace Svg
{ "clip", "auto" },
{ "clip-rule", "nonzero" },
{ "clipPathUnits", "userSpaceOnUse" },
{ "x", "0" },
{ "y", "0" },
{ "transform", "" },
// line
......
......@@ -65,11 +65,18 @@ namespace Svg
}
public void FlushStyles()
{
foreach (var s in _styles)
if (_styles.Any())
{
SvgElementFactory.SetPropertyValue(this, s.Key, s.Value.Last().Value, this.OwnerDocument);
var styles = new Dictionary<string, SortedDictionary<int, string>>();
foreach (var s in _styles)
{
if (!SvgElementFactory.SetPropertyValue(this, s.Key, s.Value.Last().Value, this.OwnerDocument, isStyle: true))
{
styles.Add(s.Key, s.Value);
}
}
_styles = styles;
}
_styles = null;
}
......@@ -77,7 +84,7 @@ namespace Svg
{
SortedDictionary<int, string> rules;
return (this.Attributes.ContainsKey(name) || this.CustomAttributes.ContainsKey(name) ||
(_styles != null && _styles.TryGetValue(name, out rules)) && (rules.ContainsKey(StyleSpecificity_InlineStyle) || rules.ContainsKey(StyleSpecificity_PresAttribute)));
(_styles.TryGetValue(name, out rules)) && (rules.ContainsKey(StyleSpecificity_InlineStyle) || rules.ContainsKey(StyleSpecificity_PresAttribute)));
}
public bool TryGetAttribute(string name, out string value)
{
......@@ -89,7 +96,7 @@ namespace Svg
}
if (this.CustomAttributes.TryGetValue(name, out value)) return true;
SortedDictionary<int, string> rules;
if (_styles != null && _styles.TryGetValue(name, out rules))
if (_styles.TryGetValue(name, out rules))
{
// Get staged styles that are
if (rules.TryGetValue(StyleSpecificity_InlineStyle, out value)) return true;
......@@ -564,7 +571,7 @@ namespace Svg
}
protected virtual void WriteAttributes(XmlTextWriter writer)
{
var styles = new Dictionary<string, string>();
var styles = _styles.ToDictionary(_styles => _styles.Key, _styles => _styles.Value.Last().Value);
bool writeStyle;
bool forceWrite;
......
......@@ -230,7 +230,7 @@ namespace Svg
private static Dictionary<Type, Dictionary<string, PropertyDescriptorCollection>> _propertyDescriptors = new Dictionary<Type, Dictionary<string, PropertyDescriptorCollection>>();
private static object syncLock = new object();
internal static void SetPropertyValue(SvgElement element, string attributeName, string attributeValue, SvgDocument document)
internal static bool SetPropertyValue(SvgElement element, string attributeName, string attributeValue, SvgDocument document, bool isStyle=false)
{
var elementType = element.GetType();
......@@ -298,10 +298,16 @@ namespace Svg
}
else
{
if (isStyle)
{
// custom styles shall remain as style
return false;
}
//attribute is not a svg attribute, store it in custom attributes
element.CustomAttributes[attributeName] = attributeValue;
}
}
return true;
}
/// <summary>
......
......@@ -176,6 +176,7 @@ __issue-084-01
__issue-109-01
__issue-116-01
__issue-123-01
__issue-129-01
__issue-143-01
__issue-191-01
__issue-202-01
......
This diff is collapsed.
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