Commit 4c059047 authored by davescriven's avatar davescriven
Browse files

- Resolved issue 6018 by applying the fixes recommended.

- Added initial custom/querystring 'parameters' implementation (#5652)
parent 610f1523
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using System.ComponentModel;
using System.Web.UI.WebControls;
using System.Diagnostics;
namespace Svg
{
......@@ -38,7 +39,7 @@ namespace Svg
}
float val = 0.0f;
float.TryParse((identifierIndex > -1) ? unit.Substring(0, identifierIndex) : unit, out val);
float.TryParse((identifierIndex > -1) ? unit.Substring(0, identifierIndex) : unit, NumberStyles.Float, CultureInfo.InvariantCulture, out val);
if (identifierIndex == -1)
{
......
......@@ -2,8 +2,8 @@
using System.Drawing;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace Svg
{
......@@ -13,7 +13,7 @@ namespace Svg
[TypeConverter(typeof(SvgViewBoxConverter))]
public struct SvgViewBox
{
public static readonly SvgViewBox Empty = new SvgViewBox(-1, -1, -1, -1);
public static readonly SvgViewBox Empty = new SvgViewBox();
/// <summary>
/// Gets or sets the position where the viewport starts horizontally.
......@@ -100,7 +100,10 @@ namespace Svg
throw new SvgException("The 'viewBox' attribute must be in the format 'minX, minY, width, height'.");
}
return new SvgViewBox(float.Parse(coords[0]), float.Parse(coords[1]), float.Parse(coords[2]), float.Parse(coords[3]));
return new SvgViewBox(float.Parse(coords[0], NumberStyles.Float, CultureInfo.InvariantCulture),
float.Parse(coords[1], NumberStyles.Float, CultureInfo.InvariantCulture),
float.Parse(coords[2], NumberStyles.Float, CultureInfo.InvariantCulture),
float.Parse(coords[3], NumberStyles.Float, CultureInfo.InvariantCulture));
}
return base.ConvertFrom(context, culture, value);
......
......@@ -88,11 +88,11 @@ namespace Svg
return null;
}
public static SvgDocument Open(Stream stream, ValidationEventHandler validationEventHandler)
public static SvgDocument Open(Stream stream, Dictionary<string, string> entities)
{
Trace.TraceInformation("Begin Read");
using (XmlTextReader reader = new XmlTextReader(stream))
using (SvgTextReader reader = new SvgTextReader(stream, entities))
{
Stack<SvgElement> elementStack = new Stack<SvgElement>();
StringBuilder value = new StringBuilder();
......@@ -100,10 +100,7 @@ namespace Svg
SvgElement parent = null;
SvgDocument svgDocument = null;
reader.XmlResolver = new SvgDtdResolver();
reader.EntityHandling = EntityHandling.ExpandEntities;
bool isEmpty;
// Don't need it
reader.WhitespaceHandling = WhitespaceHandling.None;
while (reader.Read())
......@@ -142,7 +139,9 @@ namespace Svg
// Need to process if the element is empty
if (isEmpty)
{
goto case XmlNodeType.EndElement;
}
break;
case XmlNodeType.EndElement:
......
......@@ -65,9 +65,9 @@ namespace Svg
}
/// <summary>
/// Renders the specified graphics.
/// Renders the <see cref="SvgElement"/> and contents to the specified <see cref="Graphics"/> object.
/// </summary>
/// <param name="graphics">The graphics.</param>
/// <param name="graphics">The <see cref="Graphics"/> object to render to.</param>
protected override void Render(Graphics graphics)
{
Matrix oldTransform = null;
......
......@@ -7,6 +7,7 @@ using System.Drawing.Drawing2D;
using System.Xml;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Globalization;
using Svg.Pathing;
......@@ -201,8 +202,8 @@ namespace Svg
for (int i = 0; i < parts.Length; i += 2)
{
x = float.Parse(parts[i]);
y = float.Parse(parts[i + 1]);
x = float.Parse(parts[i], NumberStyles.Float, CultureInfo.InvariantCulture);
y = float.Parse(parts[i + 1], NumberStyles.Float, CultureInfo.InvariantCulture);
point = new PointF(x, y);
if (relative)
......
......@@ -130,6 +130,7 @@
<Compile Include="SvgElementIdManager.cs" />
<Compile Include="DataTypes\SvgUnit.cs" />
<Compile Include="DataTypes\SvgUnitConverter.cs" />
<Compile Include="SvgTextReader.cs" />
<Compile Include="Text\SvgText.cs" />
<Compile Include="Text\SvgTextAnchor.cs" />
<Compile Include="Text\SvgTextSpan.cs" />
......
......@@ -27,7 +27,14 @@ namespace Svg
/// <exception cref="T:System.Exception">There is a runtime error (for example, an interrupted server connection). </exception>
public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
{
return Assembly.GetExecutingAssembly().GetManifestResourceStream("Svg.Resources.svg11.dtd");
if (absoluteUri.ToString().IndexOf("svg", StringComparison.InvariantCultureIgnoreCase) > -1)
{
return Assembly.GetExecutingAssembly().GetManifestResourceStream("Svg.Resources.svg11.dtd");
}
else
{
return base.GetEntity(absoluteUri, role, ofObjectToReturn);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using System.Collections.Specialized;
namespace Svg
{
internal sealed class SvgTextReader : XmlTextReader
{
private Dictionary<string, string> _entities;
private string _value;
private bool _customValue = false;
private string _localName;
public SvgTextReader(Stream stream, Dictionary<string, string> entities)
: base(stream)
{
this.EntityHandling = EntityHandling.ExpandCharEntities;
this._entities = entities;
}
/// <summary>
/// Gets the text value of the current node.
/// </summary>
/// <value></value>
/// <returns>The value returned depends on the <see cref="P:System.Xml.XmlTextReader.NodeType"/> of the node. The following table lists node types that have a value to return. All other node types return String.Empty.Node Type Value AttributeThe value of the attribute. CDATAThe content of the CDATA section. CommentThe content of the comment. DocumentTypeThe internal subset. ProcessingInstructionThe entire content, excluding the target. SignificantWhitespaceThe white space within an xml:space= 'preserve' scope. TextThe content of the text node. WhitespaceThe white space between markup. XmlDeclarationThe content of the declaration. </returns>
public override string Value
{
get
{
return (this._customValue) ? this._value : base.Value;
}
}
/// <summary>
/// Gets the local name of the current node.
/// </summary>
/// <value></value>
/// <returns>The name of the current node with the prefix removed. For example, LocalName is book for the element &lt;bk:book&gt;.For node types that do not have a name (like Text, Comment, and so on), this property returns String.Empty.</returns>
public override string LocalName
{
get
{
return (this._customValue) ? this._localName : base.LocalName;
}
}
private IDictionary<string, string> Entities
{
get
{
if (this._entities == null)
{
this._entities = new Dictionary<string, string>();
}
return this._entities;
}
}
/// <summary>
/// Moves to the next attribute.
/// </summary>
/// <returns>
/// true if there is a next attribute; false if there are no more attributes.
/// </returns>
public override bool MoveToNextAttribute()
{
bool moved = base.MoveToNextAttribute();
if (moved)
{
this._localName = base.LocalName;
if (this.ReadAttributeValue())
{
if (this.NodeType == XmlNodeType.EntityReference)
{
this.ResolveEntity();
}
else
{
this._value = base.Value;
}
}
this._customValue = true;
}
return moved;
}
/// <summary>
/// Reads the next node from the stream.
/// </summary>
/// <returns>
/// true if the next node was read successfully; false if there are no more nodes to read.
/// </returns>
/// <exception cref="T:System.Xml.XmlException">An error occurred while parsing the XML. </exception>
public override bool Read()
{
this._customValue = false;
bool read = base.Read();
if (this.NodeType == XmlNodeType.DocumentType)
{
this.ParseEntities();
}
return read;
}
private void ParseEntities()
{
const string entityText = "<!ENTITY";
string[] entities = this.Value.Split(new string[]{entityText}, StringSplitOptions.None);
string[] parts = null;
string name = null;
string value = null;
foreach (string entity in entities)
{
if (string.IsNullOrEmpty(entity.Trim()))
{
continue;
}
parts = entity.Trim().Split(new char[]{' ', '\t'}, StringSplitOptions.RemoveEmptyEntries);
name = parts[0];
value = parts[1].Split(new char[] { this.QuoteChar }, StringSplitOptions.RemoveEmptyEntries)[0];
this.Entities.Add(name, value);
}
}
/// <summary>
/// Resolves the entity reference for EntityReference nodes.
/// </summary>
public override void ResolveEntity()
{
if (this.NodeType == XmlNodeType.EntityReference)
{
if (this._entities.ContainsKey(this.Name))
{
this._value = this._entities[this.Name];
}
else
{
this._value = string.Empty;
}
this._customValue = true;
}
}
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Globalization;
namespace Svg.Transforms
{
......@@ -57,16 +58,16 @@ namespace Svg.Transforms
{
case "translate":
string[] coords = contents.Split(new char[]{',', ' '}, StringSplitOptions.RemoveEmptyEntries);
float x = float.Parse(coords[0].Trim());
float y = float.Parse(coords[1].Trim());
float x = float.Parse(coords[0].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture);
float y = float.Parse(coords[1].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture);
transformList.Add(new SvgTranslate(x, y));
break;
case "rotate":
float angle = float.Parse(contents);
float angle = float.Parse(contents, NumberStyles.Float, CultureInfo.InvariantCulture);
transformList.Add(new SvgRotate(angle));
break;
case "scale":
float scaleFactor = float.Parse(contents);
float scaleFactor = float.Parse(contents, NumberStyles.Float, CultureInfo.InvariantCulture);
transformList.Add(new SvgScale(scaleFactor));
break;
}
......
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