Unverified Commit 1cc35084 authored by mrbean-bremen's avatar mrbean-bremen
Browse files

Fixed handling of default values for radial gradients

- added possibility for class-specific default attribute values
- fixes load/save of W3C example pservers-grad-06-b
- fixes #397
parent e6d7d76b
...@@ -10,49 +10,93 @@ namespace Svg ...@@ -10,49 +10,93 @@ namespace Svg
/// </summary> /// </summary>
public static class SvgDefaults public static class SvgDefaults
{ {
//internal dictionary for the defaults // defaults that are specific to some elements
private static readonly Dictionary<string, string> _defaults = new Dictionary<string, string>(); private static Dictionary<string, Dictionary<string, string>> _propDefaults =
new Dictionary<string, Dictionary<string, string>>
{
{ "SvgRadialGradientServer", new Dictionary<string, string>
{ { "cx", "50%" }, { "cy", "50%" }, { "r", "50%" } } },
{ "SvgLinearGradientServer", new Dictionary<string, string>
{ { "x1", "0%" }, { "x2", "100%" }, { "y1", "0%" }, { "y2", "100%" } } },
};
static SvgDefaults() // common defaults
private static readonly Dictionary<string, string> _defaults =
new Dictionary<string, string>()
{ {
_defaults["d"] = ""; { "d", "" },
{ "viewBox", "0, 0, 0, 0" },
{ "visibility", "visible" },
{ "display", "inline" },
{ "enable-background", "accumulate" },
{ "opacity", "1" },
{ "clip", "auto" },
{ "clip-rule", "nonzero" },
{ "clipPathUnits", "userSpaceOnUse" },
{ "x", "0" },
{ "y", "0" },
{ "transform", "" },
// line
{ "x1", "0" },
{ "x2", "0" },
{ "y1", "0" },
{ "y2", "0" },
_defaults["viewBox"] = "0, 0, 0, 0"; // circle, ellipse
{ "cx", "0" },
{ "cy", "0" },
_defaults["visibility"] = "visible"; { "fill", "" },
_defaults["opacity"] = "1"; { "fill-opacity", "1" },
_defaults["clip-rule"] = "nonzero"; { "fill-rule", "nonzero" },
_defaults["transform"] = ""; { "stop-color", "black" },
_defaults["rx"] = "0"; { "stop-opacity", "1" },
_defaults["ry"] = "0";
_defaults["cx"] = "0";
_defaults["cy"] = "0";
_defaults["fill"] = ""; { "stroke", "none" },
_defaults["fill-opacity"] = "1"; { "stroke-opacity", "1" },
_defaults["fill-rule"] = "nonzero"; { "stroke-width", "1" },
{ "stroke-miterlimit", "4" },
{ "stroke-linecap", "butt" },
{ "stroke-linejoin", "miter" },
{ "stroke-dasharray", "none" },
{ "stroke-dashoffset", "0" },
_defaults["stroke"] = "none"; // marker
_defaults["stroke-opacity"] = "1"; { "markerUnits", "strokeWidth" },
_defaults["stroke-width"] = "1"; { "refX", "0" },
_defaults["stroke-miterlimit"] = "4"; { "refY", "0" },
_defaults["stroke-linecap"] = "butt"; { "markerWidth", "3" },
_defaults["stroke-linejoin"] = "miter"; { "markerHeight", "3" },
_defaults["stroke-dasharray"] = "none"; { "orient", "0" }
_defaults["stroke-dashoffset"] = "0"; };
static SvgDefaults()
{
} }
/// <summary> /// <summary>
/// Checks whether the property value is the default value of the svg definition. /// Checks whether the property value is the default value of the svg definition.
/// </summary> /// </summary>
/// <param name="attributeName">Name of the svg attribute</param> /// <param name="attributeName">Name of the svg attribute</param>
/// <param name="componentType">Class name of the svg element</param>
/// <param name="value">.NET value of the attribute</param> /// <param name="value">.NET value of the attribute</param>
public static bool IsDefault(string attributeName, string value) public static bool IsDefault(string attributeName, string componentType, string value)
{
Console.WriteLine(componentType + ": " + attributeName);
if (_propDefaults.ContainsKey(componentType))
{
if (_propDefaults[componentType].ContainsKey(attributeName))
{ {
return _propDefaults[componentType][attributeName] == value;
}
}
if (_defaults.ContainsKey(attributeName)) if (_defaults.ContainsKey(attributeName))
{ {
if (_defaults[attributeName] == value) return true; return _defaults[attributeName] == value;
} }
return false; return false;
} }
......
...@@ -600,7 +600,7 @@ namespace Svg ...@@ -600,7 +600,7 @@ namespace Svg
var type = propertyValue.GetType(); var type = propertyValue.GetType();
//Only write the attribute's value if it is not the default value, not null/empty, or we're forcing the write. //Only write the attribute's value if it is not the default value, not null/empty, or we're forcing the write.
if ((!string.IsNullOrEmpty(value) && !SvgDefaults.IsDefault(attr.Attribute.Name, value)) || forceWrite) if ((!string.IsNullOrEmpty(value) && !SvgDefaults.IsDefault(attr.Attribute.Name, attr.Property.ComponentType.Name, value)) || forceWrite)
{ {
if (writeStyle) if (writeStyle)
{ {
......
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