Skip to content

Commit a1b9a62

Browse files
authored
Merge branch 'dotnetprojects:master' into master
2 parents aeff01b + 0e4eeee commit a1b9a62

File tree

6 files changed

+30
-26
lines changed

6 files changed

+30
-26
lines changed

Source/SVGImage/SVG/Animation/AnimationBase.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
namespace SVGImage.SVG.Animation
55
{
6+
using Shapes;
7+
using System.Globalization;
68
using Utils;
7-
using Shapes;
89

910
public abstract class AnimationBase : Shape
1011
{
@@ -16,11 +17,11 @@ protected AnimationBase(SVG svg, XmlNode node, Shape parent)
1617
{
1718
var d = XmlUtil.AttrValue(node, "dur", "");
1819
if (d.EndsWith("ms"))
19-
Duration = TimeSpan.FromMilliseconds(double.Parse(d.Substring(0, d.Length - 2)));
20+
Duration = TimeSpan.FromMilliseconds(double.Parse(d.Substring(0, d.Length - 2), NumberStyles.Number, CultureInfo.InvariantCulture));
2021
else if (d.EndsWith("s"))
21-
Duration = TimeSpan.FromSeconds(double.Parse(d.Substring(0, d.Length - 1)));
22+
Duration = TimeSpan.FromSeconds(double.Parse(d.Substring(0, d.Length - 1), NumberStyles.Number, CultureInfo.InvariantCulture));
2223
else
23-
Duration = TimeSpan.FromSeconds(double.Parse(d));
24+
Duration = TimeSpan.FromSeconds(double.Parse(d, NumberStyles.Number, CultureInfo.InvariantCulture));
2425
}
2526
}
2627
}

Source/SVGImage/SVG/PaintServers/PaintServerManager.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using System;
2-
using System.Xml;
3-
using System.Text;
42
using System.Collections.Generic;
53
using System.Reflection;
6-
4+
using System.Text;
75
using System.Windows.Media;
6+
using System.Xml;
87

98
namespace SVGImage.SVG.PaintServers
10-
{
9+
{
10+
using System.Globalization;
1111
using Utils;
1212

1313
public sealed class PaintServerManager
@@ -224,7 +224,7 @@ private int ParseColorNumber(string value)
224224
{
225225
if (value.EndsWith("%"))
226226
{
227-
var nr = double.Parse(value.Substring(0, value.Length - 1));
227+
var nr = double.Parse(value.Substring(0, value.Length - 1), NumberStyles.Number, CultureInfo.InvariantCulture);
228228
if (nr < 0)
229229
nr = 255 - nr; //TODO: what is this trying to do?
230230
var result = (int)Math.Round((nr * 255) / 100);

Source/SVGImage/SVG/SVGRender.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
using System;
1+
using SVGImage.SVG.Utils;
2+
using System;
3+
using System.Collections.Generic;
24
using System.IO;
3-
using System.Xml;
45
using System.Linq;
5-
using System.Collections.Generic;
6-
using SVGImage.SVG.Utils;
7-
86
using System.Windows;
97
using System.Windows.Media;
108
using System.Windows.Media.Animation;
9+
using System.Xml;
1110

1211
namespace SVGImage.SVG
1312
{
1413
using Animation;
15-
using Shapes;
1614
using FileLoaders;
17-
15+
using Shapes;
16+
using System.Globalization;
17+
1818
/// <summary>
1919
/// This is the class that creates the WPF Drawing object based on the information from the <see cref="SVG"/> class.
2020
/// </summary>
@@ -261,8 +261,8 @@ internal DrawingGroup LoadGroup(IList<Shape> elements, Rect? viewBox, bool isSwi
261261
{
262262
var animation = new DoubleAnimation
263263
{
264-
From = double.Parse(animateTransform.From),
265-
To = double.Parse(animateTransform.To),
264+
From = double.Parse(animateTransform.From, NumberStyles.Number, CultureInfo.InvariantCulture),
265+
To = double.Parse(animateTransform.To, NumberStyles.Number, CultureInfo.InvariantCulture),
266266
Duration = animateTransform.Duration
267267
};
268268
animation.RepeatBehavior = RepeatBehavior.Forever;
@@ -279,7 +279,7 @@ internal DrawingGroup LoadGroup(IList<Shape> elements, Rect? viewBox, bool isSwi
279279
if (animate.AttributeName == "r")
280280
{
281281
var animation = new DoubleAnimationUsingKeyFrames() { Duration = animate.Duration };
282-
foreach (var d in animate.Values.Split(';').Select(x => new LinearDoubleKeyFrame(double.Parse(x))))
282+
foreach (var d in animate.Values.Split(';').Select(x => new LinearDoubleKeyFrame(double.Parse(x, NumberStyles.Number, CultureInfo.InvariantCulture))))
283283
{
284284
animation.KeyFrames.Add(d);
285285
}
@@ -292,7 +292,7 @@ internal DrawingGroup LoadGroup(IList<Shape> elements, Rect? viewBox, bool isSwi
292292
{
293293
var animation = new PointAnimationUsingKeyFrames() { Duration = animate.Duration };
294294
foreach (var d in animate.Values.Split(';').Select(_ => new LinearPointKeyFrame(
295-
new Point(double.Parse(_), ((EllipseGeometry)g).Center.Y))))
295+
new Point(double.Parse(_, NumberStyles.Number, CultureInfo.InvariantCulture), ((EllipseGeometry)g).Center.Y))))
296296
{
297297
animation.KeyFrames.Add(d);
298298
}
@@ -303,7 +303,7 @@ internal DrawingGroup LoadGroup(IList<Shape> elements, Rect? viewBox, bool isSwi
303303
{
304304
var animation = new PointAnimationUsingKeyFrames() { Duration = animate.Duration };
305305
foreach (var d in animate.Values.Split(';').Select(_ => new LinearPointKeyFrame(
306-
new Point(((EllipseGeometry)g).Center.X, double.Parse(_)))))
306+
new Point(((EllipseGeometry)g).Center.X, double.Parse(_, NumberStyles.Number, CultureInfo.InvariantCulture)))))
307307
{
308308
animation.KeyFrames.Add(d);
309309
}

Source/SVGImage/SVG/Shapes/LengthPercentageOrNumber.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System;
22

33
namespace SVGImage.SVG.Shapes
4-
{
4+
{
5+
using System.Globalization;
56
using System.Text.RegularExpressions;
67

78
public struct LengthPercentageOrNumber
@@ -163,7 +164,7 @@ public LengthPercentageOrNumber(double value, LengthContext context)
163164
public static LengthPercentageOrNumber Parse(Shape owner, string value, LengthOrientation orientation = LengthOrientation.None)
164165
{
165166
var lengthMatch = _lengthRegex.Match(value.Trim());
166-
if(!lengthMatch.Success || !Double.TryParse(lengthMatch.Groups["Value"].Value, out double d))
167+
if(!lengthMatch.Success || !Double.TryParse(lengthMatch.Groups["Value"].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out double d))
167168
{
168169
throw new ArgumentException($"Invalid length/percentage/number value: {value}");
169170
}

Source/SVGImage/SVG/Shapes/TextShapeBase.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
namespace SVGImage.SVG.Shapes
66
{
7+
using System.Diagnostics;
8+
using System.Globalization;
79
using System.Linq;
8-
using System.Diagnostics;
910
using System.Text;
1011
using System.Text.RegularExpressions;
1112

@@ -127,7 +128,7 @@ protected override void ParseAtStart(SVG svg, XmlNode node)
127128
break;
128129
case "rotate":
129130
Rotate = attr.Value.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
130-
.Select(v => double.Parse(v)).ToList();
131+
.Select(v => double.Parse(v, NumberStyles.Number, CultureInfo.InvariantCulture)).ToList();
131132
break;
132133
case "textLength":
133134
TextLength = LengthPercentageOrNumber.Parse(this, attr.Value);

Source/SVGImage/SVG/Utils/BaselineHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using SVGImage.SVG.Shapes;
22
using System;
3+
using System.Globalization;
34

45
namespace SVGImage.SVG.Utils
56
{
@@ -32,7 +33,7 @@ public static LengthPercentageOrNumber EstimateBaselineShift(TextStyle textStyle
3233
//Based on previous estimation
3334
return new LengthPercentageOrNumber((-1) * (textStyle.FontSize + (textStyle.FontSize * 0.25)), new LengthContext(shape, LengthUnit.Number));
3435
}
35-
else if(textStyle.BaseLineShift.EndsWith("%") && Double.TryParse(textStyle.BaseLineShift.Substring(0, textStyle.BaseLineShift.Length - 1), out double d))
36+
else if(textStyle.BaseLineShift.EndsWith("%") && Double.TryParse(textStyle.BaseLineShift.Substring(0, textStyle.BaseLineShift.Length - 1), NumberStyles.Number, CultureInfo.InvariantCulture, out double d))
3637
{
3738
try
3839
{

0 commit comments

Comments
 (0)