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