Skip to content

Commit d92772e

Browse files
committed
Bug Fix: ArgumentNullException bug in gradient rendering
- Issue: Tests/Images/Dialog-information_red-test1.svg - Issue: Tests/Images/molumen_red_square_error_warning_icon.svg - Issue: Tests/Images/Images\router_andy_fitzsimon_r[1].svg - Issue: Tests/Images/switch_cisco_nico_[1].svg - Issue: Tests/Images/test1.svg
1 parent 5996b9a commit d92772e

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

Source/SVGImage/SVG/PaintServer/GradientColorPaintServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public GradientColorPaintServer(PaintServerManager owner, XmlNode node) : base(o
2828
{
2929
string refid = XmlUtil.AttrValue(node, "xlink:href", string.Empty);
3030
string paintServerKey = owner.Parse(refid.Substring(1));
31-
GradientColorPaintServer refcol = owner.GetServers()[paintServerKey] as GradientColorPaintServer;
31+
GradientColorPaintServer refcol = owner.GetServer(paintServerKey) as GradientColorPaintServer;
3232
if (refcol == null) return;
3333
this.m_stops = new List<GradientStop>(refcol.m_stops);
3434
}

Source/SVGImage/SVG/PaintServer/LinearGradientColorPaintServer.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using System.Windows;
1+
using System.Xml;
2+
3+
using System.Windows;
24
using System.Windows.Media;
3-
using System.Xml;
45

56
namespace SVGImage.SVG.PaintServer
67
{
@@ -28,6 +29,7 @@ public LinearGradientColorPaintServerPaintServer(PaintServerManager owner, Brush
2829
{
2930
Brush = newBrush;
3031
}
32+
3133
public override Brush GetBrush(double opacity, SVG svg, SVGRender svgRender, Rect bounds)
3234
{
3335
if (this.Brush != null) return this.Brush;
@@ -36,30 +38,30 @@ public override Brush GetBrush(double opacity, SVG svg, SVGRender svgRender, Rec
3638
foreach (GradientStop stop in this.Stops) b.GradientStops.Add(stop);
3739

3840
b.MappingMode = BrushMappingMode.RelativeToBoundingBox;
39-
b.StartPoint = new System.Windows.Point(0, 0);
40-
b.EndPoint = new System.Windows.Point(1, 0);
41+
b.StartPoint = new Point(0, 0);
42+
b.EndPoint = new Point(1, 0);
4143

4244
if (this.GradientUnits == SVGTags.sUserSpaceOnUse)
4345
{
4446
Transform tr = this.Transform as Transform;
4547
if (tr != null)
4648
{
47-
b.StartPoint = tr.Transform(new System.Windows.Point(this.X1, this.Y1));
48-
b.EndPoint = tr.Transform(new System.Windows.Point(this.X2, this.Y2));
49+
b.StartPoint = tr.Transform(new Point(this.X1, this.Y1));
50+
b.EndPoint = tr.Transform(new Point(this.X2, this.Y2));
4951
}
5052
else
5153
{
52-
b.StartPoint = new System.Windows.Point(this.X1, this.Y1);
53-
b.EndPoint = new System.Windows.Point(this.X2, this.Y2);
54+
b.StartPoint = new Point(this.X1, this.Y1);
55+
b.EndPoint = new Point(this.X2, this.Y2);
5456
}
5557
this.Transform = null;
5658
b.MappingMode = BrushMappingMode.Absolute;
5759
}
5860
else
5961
{
6062
this.Normalize();
61-
if (double.IsNaN(this.X1) == false) b.StartPoint = new System.Windows.Point(this.X1, this.Y1);
62-
if (double.IsNaN(this.X2) == false) b.EndPoint = new System.Windows.Point(this.X2, this.Y2);
63+
if (double.IsNaN(this.X1) == false) b.StartPoint = new Point(this.X1, this.Y1);
64+
if (double.IsNaN(this.X2) == false) b.EndPoint = new Point(this.X2, this.Y2);
6365
}
6466

6567
this.Brush = b;

Source/SVGImage/SVG/PaintServer/PaintServerManager.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,21 @@ public string Create(SVG svg, XmlNode node)
3737

3838
public void AddServer(string key, PaintServer server)
3939
{
40+
if (string.IsNullOrWhiteSpace(key))
41+
{
42+
return;
43+
}
44+
4045
m_servers[key] = server;
4146
}
4247

4348
public PaintServer GetServer(string serverKey)
4449
{
50+
if (string.IsNullOrWhiteSpace(serverKey))
51+
{
52+
return null;
53+
}
54+
4555
PaintServer result;
4656
if (serverKey != null && m_servers.TryGetValue(serverKey, out result)) return result;
4757
else return null;

Source/SVGImage/SVG/PaintServer/RadialGradientColorPaintServer.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using System.Windows;
1+
using System.Xml;
2+
3+
using System.Windows;
24
using System.Windows.Media;
3-
using System.Xml;
45

56
namespace SVGImage.SVG.PaintServer
67
{
@@ -40,15 +41,15 @@ public override Brush GetBrush(double opacity, SVG svg, SVGRender svgRender, Rec
4041
RadialGradientBrush b = new RadialGradientBrush();
4142
foreach (GradientStop stop in this.Stops) b.GradientStops.Add(stop);
4243

43-
b.GradientOrigin = new System.Windows.Point(0.5, 0.5);
44-
b.Center = new System.Windows.Point(0.5, 0.5);
44+
b.GradientOrigin = new Point(0.5, 0.5);
45+
b.Center = new Point(0.5, 0.5);
4546
b.RadiusX = 0.5;
4647
b.RadiusY = 0.5;
4748

4849
if (this.GradientUnits == SVGTags.sUserSpaceOnUse)
4950
{
50-
b.Center = new System.Windows.Point(this.CX, this.CY);
51-
b.GradientOrigin = new System.Windows.Point(this.FX, this.FY);
51+
b.Center = new Point(this.CX, this.CY);
52+
b.GradientOrigin = new Point(this.FX, this.FY);
5253
b.RadiusX = this.R;
5354
b.RadiusY = this.R;
5455
b.MappingMode = BrushMappingMode.Absolute;
@@ -58,12 +59,12 @@ public override Brush GetBrush(double opacity, SVG svg, SVGRender svgRender, Rec
5859
double scale = 1d / 100d;
5960
if (double.IsNaN(this.CX) == false && double.IsNaN(this.CY) == false)
6061
{
61-
//b.GradientOrigin = new System.Windows.Point(this.CX*scale, this.CY*scale);
62-
b.Center = new System.Windows.Point(this.CX /* *scale */, this.CY /* *scale */);
62+
//b.GradientOrigin = new Point(this.CX*scale, this.CY*scale);
63+
b.Center = new Point(this.CX /* *scale */, this.CY /* *scale */);
6364
}
6465
if (double.IsNaN(this.FX) == false && double.IsNaN(this.FY) == false)
6566
{
66-
b.GradientOrigin = new System.Windows.Point(this.FX * scale, this.FY * scale);
67+
b.GradientOrigin = new Point(this.FX * scale, this.FY * scale);
6768
}
6869
if (double.IsNaN(this.R) == false)
6970
{

0 commit comments

Comments
 (0)