Commit 75efb088 authored by Tebjan Halm's avatar Tebjan Halm
Browse files

Revert "Working on making this export valid SVG documents."

parent 06d69e68
...@@ -85,12 +85,13 @@ namespace Svg ...@@ -85,12 +85,13 @@ namespace Svg
private bool IsInheritValue(object value) private bool IsInheritValue(object value)
{ {
return (value == null || return (value == null ||
(value is SvgFontWeight && (SvgFontWeight)value == SvgFontWeight.Inherit) || (value is SvgFontStyle && (SvgFontStyle)value == SvgFontStyle.inherit) ||
(value is SvgTextAnchor && (SvgTextAnchor)value == SvgTextAnchor.Inherit) || (value is SvgFontWeight && (SvgFontWeight)value == SvgFontWeight.inherit) ||
(value is SvgFontVariant && (SvgFontVariant)value == SvgFontVariant.Inherit) || (value is SvgTextAnchor && (SvgTextAnchor)value == SvgTextAnchor.inherit) ||
(value is SvgTextDecoration && (SvgTextDecoration)value == SvgTextDecoration.Inherit) || (value is SvgFontVariant && (SvgFontVariant)value == SvgFontVariant.inherit) ||
(value is SvgTextDecoration && (SvgTextDecoration)value == SvgTextDecoration.inherit) ||
(value is XmlSpaceHandling && (XmlSpaceHandling)value == XmlSpaceHandling.inherit) || (value is XmlSpaceHandling && (XmlSpaceHandling)value == XmlSpaceHandling.inherit) ||
(value is SvgOverflow && (SvgOverflow)value == SvgOverflow.Inherit) || (value is SvgOverflow && (SvgOverflow)value == SvgOverflow.inherit) ||
(value == SvgColourServer.Inherit) || (value == SvgColourServer.Inherit) ||
(value is string && (string)value == "inherit") (value is string && (string)value == "inherit")
); );
......
...@@ -11,8 +11,6 @@ using System.Xml; ...@@ -11,8 +11,6 @@ using System.Xml;
using System.Linq; using System.Linq;
using ExCSS; using ExCSS;
using Svg.Css; using Svg.Css;
using System.Threading;
using System.Globalization;
namespace Svg namespace Svg
{ {
...@@ -477,7 +475,7 @@ namespace Svg ...@@ -477,7 +475,7 @@ namespace Svg
renderer.ScaleTransform(bitmap.Width / size.Width, bitmap.Height / size.Height); renderer.ScaleTransform(bitmap.Width / size.Width, bitmap.Height / size.Height);
//EO, 2014-12-05: Requested to ensure proper zooming out (reduce size). Otherwise it clip the image. //EO, 2014-12-05: Requested to ensure proper zooming out (reduce size). Otherwise it clip the image.
this.Overflow = SvgOverflow.Auto; this.Overflow = SvgOverflow.auto;
this.Render(renderer); this.Render(renderer);
} }
...@@ -490,18 +488,6 @@ namespace Svg ...@@ -490,18 +488,6 @@ namespace Svg
//Trace.TraceInformation("End Render"); //Trace.TraceInformation("End Render");
} }
public override void Write(XmlTextWriter writer)
{
//Save previous culture and switch to invariant for writing
var previousCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
base.Write(writer);
//Switch culture back
Thread.CurrentThread.CurrentCulture = previousCulture;
}
public void Write(Stream stream) public void Write(Stream stream)
{ {
...@@ -513,7 +499,7 @@ namespace Svg ...@@ -513,7 +499,7 @@ namespace Svg
if (!String.IsNullOrEmpty(this.ExternalCSSHref)) if (!String.IsNullOrEmpty(this.ExternalCSSHref))
xmlWriter.WriteProcessingInstruction("xml-stylesheet", String.Format("type=\"text/css\" href=\"{0}\"", this.ExternalCSSHref)); xmlWriter.WriteProcessingInstruction("xml-stylesheet", String.Format("type=\"text/css\" href=\"{0}\"", this.ExternalCSSHref));
this.Write(xmlWriter); this.WriteElement(xmlWriter);
xmlWriter.Flush(); xmlWriter.Flush();
} }
......
...@@ -520,11 +520,16 @@ namespace Svg ...@@ -520,11 +520,16 @@ namespace Svg
this.Render(renderer); this.Render(renderer);
} }
/// <summary>Derrived classes may decide that the element should not be written. For example, the text element shouldn't be written if it's empty.</summary> public void WriteElement(XmlTextWriter writer)
public virtual bool ShouldWriteElement()
{ {
//Write any element who has a name. //Save previous culture and switch to invariant for writing
return (this.ElementName != String.Empty); var previousCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
this.Write(writer);
//Switch culture back
Thread.CurrentThread.CurrentCulture = previousCulture;
} }
protected virtual void WriteStartElement(XmlTextWriter writer) protected virtual void WriteStartElement(XmlTextWriter writer)
...@@ -532,8 +537,18 @@ namespace Svg ...@@ -532,8 +537,18 @@ namespace Svg
if (this.ElementName != String.Empty) if (this.ElementName != String.Empty)
{ {
writer.WriteStartElement(this.ElementName); writer.WriteStartElement(this.ElementName);
if (this.ElementName == "svg")
{
foreach (var ns in SvgAttributeAttribute.Namespaces)
{
if (string.IsNullOrEmpty(ns.Key))
writer.WriteAttributeString("xmlns", ns.Value);
else
writer.WriteAttributeString("xmlns:" + ns.Key, ns.Value);
}
writer.WriteAttributeString("version", "1.1");
}
} }
this.WriteAttributes(writer); this.WriteAttributes(writer);
} }
...@@ -557,12 +572,10 @@ namespace Svg ...@@ -557,12 +572,10 @@ namespace Svg
(!attr.Attribute.InAttributeDictionary || _attributes.ContainsKey(attr.Attribute.Name))) (!attr.Attribute.InAttributeDictionary || _attributes.ContainsKey(attr.Attribute.Name)))
{ {
object propertyValue = attr.Property.GetValue(this); object propertyValue = attr.Property.GetValue(this);
string value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string));
forceWrite = false; forceWrite = false;
writeStyle = (attr.Attribute.Name == "fill"); writeStyle = (attr.Attribute.Name == "fill");
if ((attr.Attribute.Name == "fill") && (Parent != null))
if (writeStyle && (Parent != null))
{ {
if(propertyValue == SvgColourServer.NotSet) continue; if(propertyValue == SvgColourServer.NotSet) continue;
...@@ -580,9 +593,9 @@ namespace Svg ...@@ -580,9 +593,9 @@ namespace Svg
if (propertyValue != null) if (propertyValue != null)
{ {
var type = propertyValue.GetType(); var type = propertyValue.GetType();
string value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string));
//Only write the attribute's value if it is not the default value, not null/empty, or we're forcing the write. if (!SvgDefaults.IsDefault(attr.Attribute.Name, value) || forceWrite)
if ((!string.IsNullOrEmpty(value) && !SvgDefaults.IsDefault(attr.Attribute.Name, value)) || forceWrite)
{ {
if (writeStyle) if (writeStyle)
{ {
...@@ -596,6 +609,7 @@ namespace Svg ...@@ -596,6 +609,7 @@ namespace Svg
} }
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));
if (writeStyle) if (writeStyle)
{ {
styles[attr.Attribute.Name] = value; styles[attr.Attribute.Name] = value;
...@@ -662,9 +676,9 @@ namespace Svg ...@@ -662,9 +676,9 @@ namespace Svg
return resolved; return resolved;
} }
public virtual void Write(XmlTextWriter writer) protected virtual void Write(XmlTextWriter writer)
{ {
if (ShouldWriteElement()) if (this.ElementName != String.Empty)
{ {
this.WriteStartElement(writer); this.WriteStartElement(writer);
this.WriteChildren(writer); this.WriteChildren(writer);
......
...@@ -173,7 +173,7 @@ namespace Svg ...@@ -173,7 +173,7 @@ namespace Svg
[SvgAttribute("font-style", true)] [SvgAttribute("font-style", true)]
public virtual SvgFontStyle FontStyle public virtual SvgFontStyle FontStyle
{ {
get { return (this.Attributes["font-style"] == null) ? SvgFontStyle.All : (SvgFontStyle)this.Attributes["font-style"]; } get { return (this.Attributes["font-style"] == null) ? SvgFontStyle.inherit : (SvgFontStyle)this.Attributes["font-style"]; }
set { this.Attributes["font-style"] = value; this.IsPathDirty = true; } set { this.Attributes["font-style"] = value; this.IsPathDirty = true; }
} }
...@@ -183,7 +183,7 @@ namespace Svg ...@@ -183,7 +183,7 @@ namespace Svg
[SvgAttribute("font-variant", true)] [SvgAttribute("font-variant", true)]
public virtual SvgFontVariant FontVariant public virtual SvgFontVariant FontVariant
{ {
get { return (this.Attributes["font-variant"] == null) ? SvgFontVariant.Inherit : (SvgFontVariant)this.Attributes["font-variant"]; } get { return (this.Attributes["font-variant"] == null) ? SvgFontVariant.inherit : (SvgFontVariant)this.Attributes["font-variant"]; }
set { this.Attributes["font-variant"] = value; this.IsPathDirty = true; } set { this.Attributes["font-variant"] = value; this.IsPathDirty = true; }
} }
...@@ -193,7 +193,7 @@ namespace Svg ...@@ -193,7 +193,7 @@ namespace Svg
[SvgAttribute("text-decoration", true)] [SvgAttribute("text-decoration", true)]
public virtual SvgTextDecoration TextDecoration public virtual SvgTextDecoration TextDecoration
{ {
get { return (this.Attributes["text-decoration"] == null) ? SvgTextDecoration.Inherit : (SvgTextDecoration)this.Attributes["text-decoration"]; } get { return (this.Attributes["text-decoration"] == null) ? SvgTextDecoration.inherit : (SvgTextDecoration)this.Attributes["text-decoration"]; }
set { this.Attributes["text-decoration"] = value; this.IsPathDirty = true; } set { this.Attributes["text-decoration"] = value; this.IsPathDirty = true; }
} }
...@@ -203,7 +203,7 @@ namespace Svg ...@@ -203,7 +203,7 @@ namespace Svg
[SvgAttribute("font-weight", true)] [SvgAttribute("font-weight", true)]
public virtual SvgFontWeight FontWeight public virtual SvgFontWeight FontWeight
{ {
get { return (this.Attributes["font-weight"] == null) ? SvgFontWeight.Inherit : (SvgFontWeight)this.Attributes["font-weight"]; } get { return (this.Attributes["font-weight"] == null) ? SvgFontWeight.inherit : (SvgFontWeight)this.Attributes["font-weight"]; }
set { this.Attributes["font-weight"] = value; this.IsPathDirty = true; } set { this.Attributes["font-weight"] = value; this.IsPathDirty = true; }
} }
...@@ -328,12 +328,12 @@ namespace Svg ...@@ -328,12 +328,12 @@ namespace Svg
// Get the font-weight // Get the font-weight
switch (this.FontWeight) switch (this.FontWeight)
{ {
//Note: Bold is not listed because it is = W700. case SvgFontWeight.bold:
case SvgFontWeight.Bolder: case SvgFontWeight.bolder:
case SvgFontWeight.W600: case SvgFontWeight.w600:
case SvgFontWeight.W700: case SvgFontWeight.w700:
case SvgFontWeight.W800: case SvgFontWeight.w800:
case SvgFontWeight.W900: case SvgFontWeight.w900:
fontStyle |= System.Drawing.FontStyle.Bold; fontStyle |= System.Drawing.FontStyle.Bold;
break; break;
} }
...@@ -341,8 +341,8 @@ namespace Svg ...@@ -341,8 +341,8 @@ namespace Svg
// Get the font-style // Get the font-style
switch (this.FontStyle) switch (this.FontStyle)
{ {
case SvgFontStyle.Italic: case SvgFontStyle.italic:
case SvgFontStyle.Oblique: case SvgFontStyle.oblique:
fontStyle |= System.Drawing.FontStyle.Italic; fontStyle |= System.Drawing.FontStyle.Italic;
break; break;
} }
...@@ -350,10 +350,10 @@ namespace Svg ...@@ -350,10 +350,10 @@ namespace Svg
// Get the text-decoration // Get the text-decoration
switch (this.TextDecoration) switch (this.TextDecoration)
{ {
case SvgTextDecoration.LineThrough: case SvgTextDecoration.lineThrough:
fontStyle |= System.Drawing.FontStyle.Strikeout; fontStyle |= System.Drawing.FontStyle.Strikeout;
break; break;
case SvgTextDecoration.Underline: case SvgTextDecoration.underline:
fontStyle |= System.Drawing.FontStyle.Underline; fontStyle |= System.Drawing.FontStyle.Underline;
break; break;
} }
......
...@@ -54,7 +54,7 @@ namespace Svg ...@@ -54,7 +54,7 @@ namespace Svg
{ {
using (XmlTextWriter xml = new XmlTextWriter(str)) using (XmlTextWriter xml = new XmlTextWriter(str))
{ {
elem.Write(xml); elem.WriteElement(xml);
result = str.ToString(); result = str.ToString();
} }
......
...@@ -84,7 +84,7 @@ namespace Svg ...@@ -84,7 +84,7 @@ namespace Svg
[SvgAttribute("font-style")] [SvgAttribute("font-style")]
public virtual SvgFontStyle FontStyle public virtual SvgFontStyle FontStyle
{ {
get { return (this.Attributes["font-style"] == null) ? SvgFontStyle.All : (SvgFontStyle)this.Attributes["font-style"]; } get { return (this.Attributes["font-style"] == null) ? SvgFontStyle.inherit : (SvgFontStyle)this.Attributes["font-style"]; }
set { this.Attributes["font-style"] = value; } set { this.Attributes["font-style"] = value; }
} }
...@@ -94,7 +94,7 @@ namespace Svg ...@@ -94,7 +94,7 @@ namespace Svg
[SvgAttribute("font-variant")] [SvgAttribute("font-variant")]
public virtual SvgFontVariant FontVariant public virtual SvgFontVariant FontVariant
{ {
get { return (this.Attributes["font-variant"] == null) ? SvgFontVariant.Inherit : (SvgFontVariant)this.Attributes["font-variant"]; } get { return (this.Attributes["font-variant"] == null) ? SvgFontVariant.inherit : (SvgFontVariant)this.Attributes["font-variant"]; }
set { this.Attributes["font-variant"] = value; } set { this.Attributes["font-variant"] = value; }
} }
...@@ -104,7 +104,7 @@ namespace Svg ...@@ -104,7 +104,7 @@ namespace Svg
[SvgAttribute("font-weight")] [SvgAttribute("font-weight")]
public virtual SvgFontWeight FontWeight public virtual SvgFontWeight FontWeight
{ {
get { return (this.Attributes["font-weight"] == null) ? SvgFontWeight.Inherit : (SvgFontWeight)this.Attributes["font-weight"]; } get { return (this.Attributes["font-weight"] == null) ? SvgFontWeight.inherit : (SvgFontWeight)this.Attributes["font-weight"]; }
set { this.Attributes["font-weight"] = value; } set { this.Attributes["font-weight"] = value; }
} }
......
...@@ -12,8 +12,7 @@ namespace Svg ...@@ -12,8 +12,7 @@ namespace Svg
[TypeConverter(typeof(SvgTextAnchorConverter))] [TypeConverter(typeof(SvgTextAnchorConverter))]
public enum SvgTextAnchor public enum SvgTextAnchor
{ {
/// <summary>The value is inherited from the parent element.</summary> inherit,
Inherit,
/// <summary> /// <summary>
/// The rendered characters are aligned such that the start of the text string is at the initial current text position. /// The rendered characters are aligned such that the start of the text string is at the initial current text position.
/// </summary> /// </summary>
......
...@@ -36,7 +36,7 @@ namespace Svg ...@@ -36,7 +36,7 @@ namespace Svg
[SvgAttribute("text-anchor", true)] [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; }
} }
...@@ -143,7 +143,7 @@ namespace Svg ...@@ -143,7 +143,7 @@ namespace Svg
{ {
this._rotate = value; this._rotate = value;
this._rotations.Clear(); this._rotations.Clear();
this._rotations.AddRange(from r in _rotate.Split(new char[] { ',', ' ', '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries) select float.Parse(r)); this._rotations.AddRange(from r in _rotate.Split(new char[] {',', ' ', '\r', '\n', '\t'}, StringSplitOptions.RemoveEmptyEntries) select float.Parse(r));
this.IsPathDirty = true; this.IsPathDirty = true;
OnAttributeChanged(new AttributeEventArgs { Attribute = "rotate", Value = value }); OnAttributeChanged(new AttributeEventArgs { Attribute = "rotate", Value = value });
} }
...@@ -167,7 +167,7 @@ namespace Svg ...@@ -167,7 +167,7 @@ namespace Svg
[SvgAttribute("lengthAdjust", true)] [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"]; }
set { this.Attributes["lengthAdjust"] = value; this.IsPathDirty = true; } set { this.Attributes["lengthAdjust"] = value; this.IsPathDirty = true; }
} }
...@@ -297,7 +297,7 @@ namespace Svg ...@@ -297,7 +297,7 @@ namespace Svg
{ {
//if there is a TSpan inside of this text element then path should not be null (even if this text is empty!) //if there is a TSpan inside of this text element then path should not be null (even if this text is empty!)
var nodes = GetContentNodes().Where(x => x is SvgContentNode && var nodes = GetContentNodes().Where(x => x is SvgContentNode &&
string.IsNullOrEmpty(x.Content.Trim(new[] { '\r', '\n', '\t' }))); string.IsNullOrEmpty(x.Content.Trim(new[] {'\r', '\n', '\t'})));
if (_path == null || IsPathDirty || nodes.Count() == 1) if (_path == null || IsPathDirty || nodes.Count() == 1)
{ {
...@@ -365,7 +365,7 @@ namespace Svg ...@@ -365,7 +365,7 @@ namespace Svg
var diff = (actLength - specLength); var diff = (actLength - specLength);
if (Math.Abs(diff) > 1.5) if (Math.Abs(diff) > 1.5)
{ {
if (this.LengthAdjust == SvgTextLengthAdjust.Spacing) if (this.LengthAdjust == SvgTextLengthAdjust.spacing)
{ {
origState.LetterSpacingAdjust = -1 * diff / (state.NumChars - origState.NumChars - 1); origState.LetterSpacingAdjust = -1 * diff / (state.NumChars - origState.NumChars - 1);
SetPath(origState, false); SetPath(origState, false);
...@@ -913,10 +913,5 @@ namespace Svg ...@@ -913,10 +913,5 @@ namespace Svg
} }
} }
/// <summary>Empty text elements are not legal - only write this element if it has children.</summary>
public override bool ShouldWriteElement()
{
return (this.HasChildren() || this.Nodes.Count > 0);
}
} }
} }
...@@ -42,14 +42,14 @@ namespace Svg ...@@ -42,14 +42,14 @@ namespace Svg
[SvgAttribute("method")] [SvgAttribute("method")]
public virtual SvgTextPathMethod Method public virtual SvgTextPathMethod Method
{ {
get { return (this.Attributes["method"] == null ? SvgTextPathMethod.Align : (SvgTextPathMethod)this.Attributes["method"]); } get { return (this.Attributes["method"] == null ? SvgTextPathMethod.align : (SvgTextPathMethod)this.Attributes["method"]); }
set { this.Attributes["method"] = value; } set { this.Attributes["method"] = value; }
} }
[SvgAttribute("spacing")] [SvgAttribute("spacing")]
public virtual SvgTextPathSpacing Spacing public virtual SvgTextPathSpacing Spacing
{ {
get { return (this.Attributes["spacing"] == null ? SvgTextPathSpacing.Exact : (SvgTextPathSpacing)this.Attributes["spacing"]); } get { return (this.Attributes["spacing"] == null ? SvgTextPathSpacing.exact : (SvgTextPathSpacing)this.Attributes["spacing"]); }
set { this.Attributes["spacing"] = value; } set { this.Attributes["spacing"] = value; }
} }
......
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