Commit 7894ea9e authored by HeinrichAD's avatar HeinrichAD
Browse files

Add: shape-rendering; Fix: CurrentCulture

Fix:
Now the application make sure to set back the old culture even an error
occurred.
SvgColourConverter.ConvertFrom
SvgPathBuilder.ConvertTo
SvgDocument.Write
SvgExtentions.GetXML

Add:
Attribute: "shape-rendering"

Change:
- Many other properties were unknowingly overloaded. I changed them to
override.
- Some methods or structures need the [CLSCompliant(false)] Attribute.
For example the Enums.TryParse extension. This extension has the where
condition IConvertible. IConvertible is [CLSCompliant(false)] and that
the reason why it is correct to mark the Enums.TryParse extension also
as [CLSCompliant(false)].
- Property "float Opacity" in SvgElement was unknowingly overloaded in
SvgGradientStop as string [stop-opacity]. In the end this property was
only used as float. I changed the SvgGradientStop.Opacity property from
string to float and to override.
parent a1ff72df
...@@ -22,7 +22,7 @@ namespace Svg ...@@ -22,7 +22,7 @@ namespace Svg
r.Width = bounds.Width; r.Width = bounds.Width;
r.Height = bounds.Height; r.Height = bounds.Height;
} }
public static RectangleF GetRectangle(this SvgRectangle r) public static RectangleF GetRectangle(this SvgRectangle r)
{ {
return new RectangleF(r.X, r.Y, r.Width, r.Height); return new RectangleF(r.X, r.Y, r.Width, r.Height);
...@@ -49,50 +49,57 @@ namespace Svg ...@@ -49,50 +49,57 @@ namespace Svg
var result = ""; var result = "";
var currentCulture = Thread.CurrentThread.CurrentCulture; var currentCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; try
using (StringWriter str = new StringWriter())
{ {
using (XmlTextWriter xml = new XmlTextWriter(str)) Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
using (StringWriter str = new StringWriter())
{ {
elem.Write(xml); using (XmlTextWriter xml = new XmlTextWriter(str))
result = str.ToString(); {
elem.Write(xml);
result = str.ToString();
}
} }
} }
Thread.CurrentThread.CurrentCulture = currentCulture; finally
{
// Make sure to set back the old culture even an error occurred.
Thread.CurrentThread.CurrentCulture = currentCulture;
}
return result; return result;
} }
public static bool HasNonEmptyCustomAttribute(this SvgElement element, string name) public static bool HasNonEmptyCustomAttribute(this SvgElement element, string name)
{ {
return element.CustomAttributes.ContainsKey(name) && !string.IsNullOrEmpty(element.CustomAttributes[name]); return element.CustomAttributes.ContainsKey(name) && !string.IsNullOrEmpty(element.CustomAttributes[name]);
} }
public static void ApplyRecursive(this SvgElement elem, Action<SvgElement> action) public static void ApplyRecursive(this SvgElement elem, Action<SvgElement> action)
{ {
action(elem); action(elem);
if(!(elem is SvgDocument)) //don't apply action to subtree of documents if (!(elem is SvgDocument)) //don't apply action to subtree of documents
{ {
foreach (var element in elem.Children) foreach (var element in elem.Children)
{ {
element.ApplyRecursive(action); element.ApplyRecursive(action);
} }
} }
} }
public static void ApplyRecursiveDepthFirst(this SvgElement elem, Action<SvgElement> action) public static void ApplyRecursiveDepthFirst(this SvgElement elem, Action<SvgElement> action)
{ {
if(!(elem is SvgDocument)) //don't apply action to subtree of documents if (!(elem is SvgDocument)) //don't apply action to subtree of documents
{ {
foreach (var element in elem.Children) foreach (var element in elem.Children)
{ {
element.ApplyRecursiveDepthFirst(action); element.ApplyRecursiveDepthFirst(action);
} }
} }
action(elem); action(elem);
} }
} }
} }
...@@ -133,6 +133,7 @@ namespace Svg.Text ...@@ -133,6 +133,7 @@ namespace Svg.Text
} }
} }
[CLSCompliant(false)]
public struct TT_OFFSET_TABLE public struct TT_OFFSET_TABLE
{ {
public ushort uMajorVersion; public ushort uMajorVersion;
...@@ -143,6 +144,7 @@ namespace Svg.Text ...@@ -143,6 +144,7 @@ namespace Svg.Text
public ushort uRangeShift; public ushort uRangeShift;
} }
[CLSCompliant(false)]
public struct TT_TABLE_DIRECTORY public struct TT_TABLE_DIRECTORY
{ {
public byte[] szTag; public byte[] szTag;
...@@ -155,6 +157,7 @@ namespace Svg.Text ...@@ -155,6 +157,7 @@ namespace Svg.Text
} }
} }
[CLSCompliant(false)]
public struct TT_NAME_TABLE_HEADER public struct TT_NAME_TABLE_HEADER
{ {
public ushort uFSelector; public ushort uFSelector;
...@@ -162,6 +165,7 @@ namespace Svg.Text ...@@ -162,6 +165,7 @@ namespace Svg.Text
public ushort uStorageOffset; public ushort uStorageOffset;
} }
[CLSCompliant(false)]
public struct TT_NAME_RECORD public struct TT_NAME_RECORD
{ {
public ushort uPlatformID; public ushort uPlatformID;
......
...@@ -62,7 +62,7 @@ namespace Svg ...@@ -62,7 +62,7 @@ namespace Svg
/// Indicates which font family is to be used to render the text. /// Indicates which font family is to be used to render the text.
/// </summary> /// </summary>
[SvgAttribute("font-family")] [SvgAttribute("font-family")]
public virtual string FontFamily public override string FontFamily
{ {
get { return this.Attributes["font-family"] as string; } get { return this.Attributes["font-family"] as string; }
set { this.Attributes["font-family"] = value; } set { this.Attributes["font-family"] = value; }
...@@ -72,7 +72,7 @@ namespace Svg ...@@ -72,7 +72,7 @@ namespace Svg
/// Refers to the size of the font from baseline to baseline when multiple lines of text are set solid in a multiline layout environment. /// Refers to the size of the font from baseline to baseline when multiple lines of text are set solid in a multiline layout environment.
/// </summary> /// </summary>
[SvgAttribute("font-size")] [SvgAttribute("font-size")]
public virtual SvgUnit FontSize public override SvgUnit FontSize
{ {
get { return (this.Attributes["font-size"] == null) ? SvgUnit.Empty : (SvgUnit)this.Attributes["font-size"]; } get { return (this.Attributes["font-size"] == null) ? SvgUnit.Empty : (SvgUnit)this.Attributes["font-size"]; }
set { this.Attributes["font-size"] = value; } set { this.Attributes["font-size"] = value; }
...@@ -82,7 +82,7 @@ namespace Svg ...@@ -82,7 +82,7 @@ namespace Svg
/// Refers to the style of the font. /// Refers to the style of the font.
/// </summary> /// </summary>
[SvgAttribute("font-style")] [SvgAttribute("font-style")]
public virtual SvgFontStyle FontStyle public override SvgFontStyle FontStyle
{ {
get { return (this.Attributes["font-style"] == null) ? SvgFontStyle.All : (SvgFontStyle)this.Attributes["font-style"]; } get { return (this.Attributes["font-style"] == null) ? SvgFontStyle.All : (SvgFontStyle)this.Attributes["font-style"]; }
set { this.Attributes["font-style"] = value; } set { this.Attributes["font-style"] = value; }
...@@ -92,7 +92,7 @@ namespace Svg ...@@ -92,7 +92,7 @@ namespace Svg
/// Refers to the varient of the font. /// Refers to the varient of the font.
/// </summary> /// </summary>
[SvgAttribute("font-variant")] [SvgAttribute("font-variant")]
public virtual SvgFontVariant FontVariant public override 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; }
...@@ -102,7 +102,7 @@ namespace Svg ...@@ -102,7 +102,7 @@ namespace Svg
/// Refers to the boldness of the font. /// Refers to the boldness of the font.
/// </summary> /// </summary>
[SvgAttribute("font-weight")] [SvgAttribute("font-weight")]
public virtual SvgFontWeight FontWeight public override 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; }
......
...@@ -79,15 +79,6 @@ namespace Svg ...@@ -79,15 +79,6 @@ namespace Svg
return _path; return _path;
} }
/// <summary>
/// Gets or sets a value to determine if anti-aliasing should occur when the element is being rendered.
/// </summary>
protected override bool RequiresSmoothRendering
{
get { return true; }
}
/// <summary> /// <summary>
/// Gets the bounds of the element. /// Gets the bounds of the element.
/// </summary> /// </summary>
......
...@@ -13,10 +13,10 @@ namespace Svg ...@@ -13,10 +13,10 @@ namespace Svg
{ {
public abstract class SvgTextBase : SvgVisualElement public abstract class SvgTextBase : SvgVisualElement
{ {
protected SvgUnitCollection _x = new SvgUnitCollection(); [CLSCompliant(false)] protected SvgUnitCollection _x = new SvgUnitCollection();
protected SvgUnitCollection _y = new SvgUnitCollection(); [CLSCompliant(false)] protected SvgUnitCollection _y = new SvgUnitCollection();
protected SvgUnitCollection _dy = new SvgUnitCollection(); [CLSCompliant(false)] protected SvgUnitCollection _dy = new SvgUnitCollection();
protected SvgUnitCollection _dx = new SvgUnitCollection(); [CLSCompliant(false)] protected SvgUnitCollection _dx = new SvgUnitCollection();
private string _rotate; private string _rotate;
private List<float> _rotations = new List<float>(); private List<float> _rotations = new List<float>();
...@@ -215,15 +215,6 @@ namespace Svg ...@@ -215,15 +215,6 @@ namespace Svg
return this.Text; return this.Text;
} }
/// <summary>
/// Gets or sets a value to determine if anti-aliasing should occur when the element is being rendered.
/// </summary>
/// <value></value>
protected override bool RequiresSmoothRendering
{
get { return true; }
}
/// <summary> /// <summary>
/// Gets the bounds of the element. /// Gets the bounds of the element.
/// </summary> /// </summary>
......
...@@ -34,7 +34,6 @@ namespace Svg.UnitTests ...@@ -34,7 +34,6 @@ namespace Svg.UnitTests
[TestMethod] [TestMethod]
public void TestMultiThread() public void TestMultiThread()
{ {
bool valid = true;
Parallel.For(0, 10, (x) => Parallel.For(0, 10, (x) =>
{ {
LoadFile(); LoadFile();
......
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