Commit 6104ff9e authored by Tebjan Halm's avatar Tebjan Halm
Browse files

Merge pull request #140 from vvvv/revert-128-master

Revert "Working on making this export valid SVG documents."
parents 06d69e68 75efb088
......@@ -85,12 +85,13 @@ namespace Svg
private bool IsInheritValue(object value)
{
return (value == null ||
(value is SvgFontWeight && (SvgFontWeight)value == SvgFontWeight.Inherit) ||
(value is SvgTextAnchor && (SvgTextAnchor)value == SvgTextAnchor.Inherit) ||
(value is SvgFontVariant && (SvgFontVariant)value == SvgFontVariant.Inherit) ||
(value is SvgTextDecoration && (SvgTextDecoration)value == SvgTextDecoration.Inherit) ||
(value is SvgFontStyle && (SvgFontStyle)value == SvgFontStyle.inherit) ||
(value is SvgFontWeight && (SvgFontWeight)value == SvgFontWeight.inherit) ||
(value is SvgTextAnchor && (SvgTextAnchor)value == SvgTextAnchor.inherit) ||
(value is SvgFontVariant && (SvgFontVariant)value == SvgFontVariant.inherit) ||
(value is SvgTextDecoration && (SvgTextDecoration)value == SvgTextDecoration.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 is string && (string)value == "inherit")
);
......
......@@ -11,8 +11,6 @@ using System.Xml;
using System.Linq;
using ExCSS;
using Svg.Css;
using System.Threading;
using System.Globalization;
namespace Svg
{
......@@ -477,7 +475,7 @@ namespace Svg
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.
this.Overflow = SvgOverflow.Auto;
this.Overflow = SvgOverflow.auto;
this.Render(renderer);
}
......@@ -490,18 +488,6 @@ namespace Svg
//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)
{
......@@ -513,7 +499,7 @@ namespace Svg
if (!String.IsNullOrEmpty(this.ExternalCSSHref))
xmlWriter.WriteProcessingInstruction("xml-stylesheet", String.Format("type=\"text/css\" href=\"{0}\"", this.ExternalCSSHref));
this.Write(xmlWriter);
this.WriteElement(xmlWriter);
xmlWriter.Flush();
}
......
......@@ -520,11 +520,16 @@ namespace Svg
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 virtual bool ShouldWriteElement()
public void WriteElement(XmlTextWriter writer)
{
//Write any element who has a name.
return (this.ElementName != String.Empty);
//Save previous culture and switch to invariant for writing
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)
......@@ -532,8 +537,18 @@ namespace Svg
if (this.ElementName != String.Empty)
{
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);
}
......@@ -557,12 +572,10 @@ namespace Svg
(!attr.Attribute.InAttributeDictionary || _attributes.ContainsKey(attr.Attribute.Name)))
{
object propertyValue = attr.Property.GetValue(this);
string value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string));
forceWrite = false;
writeStyle = (attr.Attribute.Name == "fill");
if (writeStyle && (Parent != null))
if ((attr.Attribute.Name == "fill") && (Parent != null))
{
if(propertyValue == SvgColourServer.NotSet) continue;
......@@ -580,9 +593,9 @@ namespace Svg
if (propertyValue != null)
{
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.
if ((!string.IsNullOrEmpty(value) && !SvgDefaults.IsDefault(attr.Attribute.Name, value)) || forceWrite)
string value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string));
if (!SvgDefaults.IsDefault(attr.Attribute.Name, value) || forceWrite)
{
if (writeStyle)
{
......@@ -596,6 +609,7 @@ namespace Svg
}
else if(attr.Attribute.Name == "fill") //if fill equals null, write 'none'
{
string value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string));
if (writeStyle)
{
styles[attr.Attribute.Name] = value;
......@@ -662,9 +676,9 @@ namespace Svg
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.WriteChildren(writer);
......
......@@ -173,7 +173,7 @@ namespace Svg
[SvgAttribute("font-style", true)]
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; }
}
......@@ -183,7 +183,7 @@ namespace Svg
[SvgAttribute("font-variant", true)]
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; }
}
......@@ -193,7 +193,7 @@ namespace Svg
[SvgAttribute("text-decoration", true)]
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; }
}
......@@ -203,7 +203,7 @@ namespace Svg
[SvgAttribute("font-weight", true)]
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; }
}
......@@ -328,12 +328,12 @@ namespace Svg
// Get the font-weight
switch (this.FontWeight)
{
//Note: Bold is not listed because it is = W700.
case SvgFontWeight.Bolder:
case SvgFontWeight.W600:
case SvgFontWeight.W700:
case SvgFontWeight.W800:
case SvgFontWeight.W900:
case SvgFontWeight.bold:
case SvgFontWeight.bolder:
case SvgFontWeight.w600:
case SvgFontWeight.w700:
case SvgFontWeight.w800:
case SvgFontWeight.w900:
fontStyle |= System.Drawing.FontStyle.Bold;
break;
}
......@@ -341,8 +341,8 @@ namespace Svg
// Get the font-style
switch (this.FontStyle)
{
case SvgFontStyle.Italic:
case SvgFontStyle.Oblique:
case SvgFontStyle.italic:
case SvgFontStyle.oblique:
fontStyle |= System.Drawing.FontStyle.Italic;
break;
}
......@@ -350,10 +350,10 @@ namespace Svg
// Get the text-decoration
switch (this.TextDecoration)
{
case SvgTextDecoration.LineThrough:
case SvgTextDecoration.lineThrough:
fontStyle |= System.Drawing.FontStyle.Strikeout;
break;
case SvgTextDecoration.Underline:
case SvgTextDecoration.underline:
fontStyle |= System.Drawing.FontStyle.Underline;
break;
}
......
......@@ -54,7 +54,7 @@ namespace Svg
{
using (XmlTextWriter xml = new XmlTextWriter(str))
{
elem.Write(xml);
elem.WriteElement(xml);
result = str.ToString();
}
......
......@@ -84,7 +84,7 @@ namespace Svg
[SvgAttribute("font-style")]
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; }
}
......@@ -94,7 +94,7 @@ namespace Svg
[SvgAttribute("font-variant")]
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; }
}
......@@ -104,7 +104,7 @@ namespace Svg
[SvgAttribute("font-weight")]
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; }
}
......
......@@ -12,8 +12,7 @@ namespace Svg
[TypeConverter(typeof(SvgTextAnchorConverter))]
public enum SvgTextAnchor
{
/// <summary>The value is inherited from the parent element.</summary>
Inherit,
inherit,
/// <summary>
/// The rendered characters are aligned such that the start of the text string is at the initial current text position.
/// </summary>
......
......@@ -19,7 +19,7 @@ namespace Svg
protected SvgUnitCollection _dx = new SvgUnitCollection();
private string _rotate;
private List<float> _rotations = new List<float>();
/// <summary>
/// Gets or sets the text to be rendered.
/// </summary>
......@@ -36,7 +36,7 @@ namespace Svg
[SvgAttribute("text-anchor", true)]
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; }
}
......@@ -143,7 +143,7 @@ namespace Svg
{
this._rotate = value;
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;
OnAttributeChanged(new AttributeEventArgs { Attribute = "rotate", Value = value });
}
......@@ -167,7 +167,7 @@ namespace Svg
[SvgAttribute("lengthAdjust", true)]
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; }
}
......@@ -230,14 +230,14 @@ namespace Svg
/// <value>The bounds.</value>
public override System.Drawing.RectangleF Bounds
{
get
get
{
var path = this.Path(null);
foreach (var elem in this.Children.OfType<SvgVisualElement>())
{
path.AddPath(elem.Path(null), false);
}
return path.GetBounds();
return path.GetBounds();
}
}
......@@ -296,9 +296,9 @@ namespace Svg
public override GraphicsPath Path(ISvgRenderer renderer)
{
//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 &&
string.IsNullOrEmpty(x.Content.Trim(new[] { '\r', '\n', '\t' })));
var nodes = GetContentNodes().Where(x => x is SvgContentNode &&
string.IsNullOrEmpty(x.Content.Trim(new[] {'\r', '\n', '\t'})));
if (_path == null || IsPathDirty || nodes.Count() == 1)
{
renderer = (renderer ?? SvgRenderer.FromNull());
......@@ -365,7 +365,7 @@ namespace Svg
var diff = (actLength - specLength);
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);
SetPath(origState, false);
......@@ -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
[SvgAttribute("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; }
}
[SvgAttribute("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; }
}
......
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