Commit 7ece1215 authored by Eric Domke's avatar Eric Domke
Browse files

Serialization Fixes

More serialization bug fixes and better fallback for font definition
problems.
parent ec0cf19d
......@@ -86,6 +86,13 @@ namespace Svg
if (objColor == null)
return false;
if ((this == SvgPaintServer.None && obj != SvgPaintServer.None) ||
(this != SvgPaintServer.None && obj == SvgPaintServer.None) ||
(this == SvgColourServer.NotSet && obj != SvgColourServer.NotSet) ||
(this != SvgColourServer.NotSet && obj == SvgColourServer.NotSet) ||
(this == SvgColourServer.Inherit && obj != SvgColourServer.Inherit) ||
(this != SvgColourServer.Inherit && obj == SvgColourServer.Inherit)) return false;
return this.GetHashCode() == objColor.GetHashCode();
}
......
......@@ -123,7 +123,7 @@ namespace Svg
/// <summary>
/// Gets or sets the color <see cref="SvgPaintServer"/> of this element which drives the currentColor property.
/// </summary>
[SvgAttribute("color")]
[SvgAttribute("color", true)]
public virtual SvgPaintServer Color
{
get { return (this.Attributes["color"] == null) ? SvgColourServer.NotSet : (SvgPaintServer)this.Attributes["color"]; }
......@@ -561,6 +561,10 @@ namespace Svg
}
protected virtual void WriteAttributes(XmlTextWriter writer)
{
var styles = new Dictionary<string, string>();
bool writeStyle;
bool forceWrite;
//properties
foreach (var attr in _svgPropertyAttributes)
{
......@@ -569,7 +573,8 @@ namespace Svg
{
object propertyValue = attr.Property.GetValue(this);
var forceWrite = false;
forceWrite = false;
writeStyle = (attr.Attribute.Name == "fill");
if ((attr.Attribute.Name == "fill") && (Parent != null))
{
if(propertyValue == SvgColourServer.NotSet) continue;
......@@ -592,18 +597,31 @@ namespace Svg
if (!SvgDefaults.IsDefault(attr.Attribute.Name, value) || forceWrite)
{
writer.WriteAttributeString(attr.Attribute.NamespaceAndName, value);
if (writeStyle)
{
styles[attr.Attribute.Name] = value;
}
else
{
writer.WriteAttributeString(attr.Attribute.NamespaceAndName, value);
}
}
}
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);
if (writeStyle)
{
styles[attr.Attribute.Name] = value;
}
else
{
writer.WriteAttributeString(attr.Attribute.NamespaceAndName, value);
}
}
}
}
//events
if(AutoPublishEvents)
{
......@@ -624,6 +642,13 @@ namespace Svg
{
writer.WriteAttributeString(item.Key, item.Value);
}
//write the style property
if (styles.Any())
{
writer.WriteAttributeString("style", (from s in styles
select s.Key + ":" + s.Value + ";").Aggregate((p,c) => p + c));
}
}
public bool AutoPublishEvents = true;
......@@ -663,14 +688,33 @@ namespace Svg
protected virtual void WriteChildren(XmlTextWriter writer)
{
//write the content
if(!String.IsNullOrEmpty(this.Content))
writer.WriteString(this.Content);
//write all children
foreach (SvgElement child in this.Children)
if (this.Nodes.Any())
{
child.Write(writer);
SvgContentNode content;
foreach (var node in this.Nodes)
{
content = node as SvgContentNode;
if (content == null)
{
((SvgElement)node).Write(writer);
}
else if (!string.IsNullOrEmpty(content.Content))
{
writer.WriteString(content.Content);
}
}
}
else
{
//write the content
if(!String.IsNullOrEmpty(this.Content))
writer.WriteString(this.Content);
//write all children
foreach (SvgElement child in this.Children)
{
child.Write(writer);
}
}
}
......
......@@ -18,7 +18,18 @@ namespace Svg
[SvgAttribute("ascent")]
public float Ascent
{
get { return (this.Attributes["ascent"] == null ? this.UnitsPerEm : (float)this.Attributes["ascent"]); }
get
{
if (this.Attributes["ascent"] == null)
{
var font = this.Parent as SvgFont;
return (font == null ? 0 : this.UnitsPerEm - font.VertOriginY);
}
else
{
return (float)this.Attributes["ascent"];
}
}
set { this.Attributes["ascent"] = value; }
}
......@@ -32,7 +43,18 @@ namespace Svg
[SvgAttribute("descent")]
public float Descent
{
get { return (this.Attributes["descent"] == null ? 0 : (float)this.Attributes["descent"]); }
get
{
if (this.Attributes["descent"] == null)
{
var font = this.Parent as SvgFont;
return (font == null ? 0 : font.VertOriginY);
}
else
{
return (float)this.Attributes["descent"];
}
}
set { this.Attributes["descent"] = value; }
}
......
......@@ -33,14 +33,14 @@ namespace Svg
/// Gets or sets the text anchor.
/// </summary>
/// <value>The text anchor.</value>
[SvgAttribute("text-anchor")]
[SvgAttribute("text-anchor", true)]
public virtual SvgTextAnchor TextAnchor
{
get { return (this.Attributes["text-anchor"] == null) ? SvgTextAnchor.inherit : (SvgTextAnchor)this.Attributes["text-anchor"]; }
set { this.Attributes["text-anchor"] = value; this.IsPathDirty = true; }
}
[SvgAttribute("baseline-shift")]
[SvgAttribute("baseline-shift", true)]
public virtual string BaselineShift
{
get { return this.Attributes["baseline-shift"] as string; }
......@@ -153,7 +153,7 @@ namespace Svg
/// <summary>
/// The pre-calculated length of the text
/// </summary>
[SvgAttribute("textLength")]
[SvgAttribute("textLength", true)]
public virtual SvgUnit TextLength
{
get { return (this.Attributes["textLength"] == null ? SvgUnit.None : (SvgUnit)this.Attributes["textLength"]); }
......@@ -164,7 +164,7 @@ namespace Svg
/// Gets or sets the text anchor.
/// </summary>
/// <value>The text anchor.</value>
[SvgAttribute("lengthAdjust")]
[SvgAttribute("lengthAdjust", true)]
public virtual SvgTextLengthAdjust LengthAdjust
{
get { return (this.Attributes["lengthAdjust"] == null) ? SvgTextLengthAdjust.spacing : (SvgTextLengthAdjust)this.Attributes["lengthAdjust"]; }
......@@ -174,7 +174,7 @@ namespace Svg
/// <summary>
/// Specifies spacing behavior between text characters.
/// </summary>
[SvgAttribute("letter-spacing")]
[SvgAttribute("letter-spacing", true)]
public virtual SvgUnit LetterSpacing
{
get { return (this.Attributes["letter-spacing"] == null ? SvgUnit.None : (SvgUnit)this.Attributes["letter-spacing"]); }
......@@ -184,7 +184,7 @@ namespace Svg
/// <summary>
/// Specifies spacing behavior between words.
/// </summary>
[SvgAttribute("word-spacing")]
[SvgAttribute("word-spacing", true)]
public virtual SvgUnit WordSpacing
{
get { return (this.Attributes["word-spacing"] == null ? SvgUnit.None : (SvgUnit)this.Attributes["word-spacing"]); }
......
......@@ -74,7 +74,7 @@ namespace SvgW3CTestRunner
doc.Write(memStream);
memStream.Position = 0;
var reader = new StreamReader(memStream);
System.IO.File.WriteAllText(@"C:\test.xml", reader.ReadToEnd());
System.IO.File.WriteAllText(@"C:\test.svg", reader.ReadToEnd());
memStream.Position = 0;
var baseUri = doc.BaseUri;
doc = SvgDocument.Open<SvgDocument>(memStream);
......
color-prof-01-f.svg
color-prop-01-b.svg
color-prop-02-f.svg
color-prop-03-t.svg
......@@ -52,7 +51,6 @@ pservers-grad-14-b.svg
pservers-grad-15-b.svg
pservers-grad-16-b.svg
pservers-grad-17-b.svg
pservers-grad-18-b.svg
pservers-grad-20-b.svg
pservers-grad-22-b.svg
pservers-grad-23-f.svg
......
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