Skip to content

Commit 485b3ed

Browse files
committed
Fixes Issue #60
1 parent 97ce300 commit 485b3ed

File tree

4 files changed

+303
-289
lines changed

4 files changed

+303
-289
lines changed

Source/SVGImage/SVG/Fill.cs

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,60 @@
66

77
namespace SVGImage.SVG
88
{
9-
public class Fill
10-
{
11-
public enum eFillRule
12-
{
13-
nonzero,
14-
evenodd
15-
}
9+
public class Fill
10+
{
11+
public enum eFillRule
12+
{
13+
nonzero,
14+
evenodd
15+
}
1616

17-
public eFillRule FillRule { get; set;}
17+
public eFillRule FillRule { get; set;}
1818

19-
public string PaintServerKey {get; set;}
19+
public string PaintServerKey {get; set;}
2020

21-
public double Opacity {get; set;}
21+
public double Opacity {get; set;}
2222

23-
public Fill(SVG svg)
24-
{
25-
this.FillRule = eFillRule.nonzero;
26-
this.Opacity = 100;
27-
}
23+
public Fill(SVG svg)
24+
{
25+
this.FillRule = eFillRule.nonzero;
26+
this.Opacity = 100;
27+
}
2828

29-
public Brush FillBrush(SVG svg, SVGRender svgRender, Shape shape, double elementOpacity, Rect bounds)
30-
{
31-
var paintServer = svg.PaintServers.GetServer(PaintServerKey);
32-
if(paintServer != null)
29+
public Brush FillBrush(SVG svg, SVGRender svgRender, Shape shape, double elementOpacity, Rect bounds)
30+
{
31+
var paintServer = svg.PaintServers.GetServer(PaintServerKey);
32+
if(paintServer != null)
3333
{
34-
if(paintServer is CurrentColorPaintServer)
34+
if(paintServer is CurrentColorPaintServer)
3535
{
36-
var shapePaintServer = svg.PaintServers.GetServer(shape.PaintServerKey);
37-
if(shapePaintServer != null)
36+
var shapePaintServer = svg.PaintServers.GetServer(shape.PaintServerKey);
37+
if(shapePaintServer != null)
3838
{
39-
return shapePaintServer.GetBrush(this.Opacity * elementOpacity, svg, svgRender, bounds);
39+
return shapePaintServer.GetBrush(this.Opacity * elementOpacity, svg, svgRender, bounds);
4040

41-
}
42-
}
43-
if (paintServer is InheritPaintServer)
44-
{
45-
var p = shape.RealParent ?? shape.Parent;
46-
while (p != null)
47-
{
48-
if(p.Fill != null)
41+
}
42+
}
43+
if (paintServer is InheritPaintServer)
44+
{
45+
var p = shape.RealParent ?? shape.Parent;
46+
while (p != null)
47+
{
48+
if(p.Fill != null)
4949
{
50-
var checkPaintServer = svg.PaintServers.GetServer(p.Fill.PaintServerKey);
51-
if(!(checkPaintServer is InheritPaintServer))
50+
var checkPaintServer = svg.PaintServers.GetServer(p.Fill.PaintServerKey);
51+
if(!(checkPaintServer is InheritPaintServer))
5252
{
53-
return checkPaintServer.GetBrush(this.Opacity * elementOpacity, svg, svgRender, bounds);
54-
}
55-
}
56-
p = p.RealParent ?? p.Parent;
57-
}
58-
return null;
59-
}
60-
return paintServer.GetBrush(this.Opacity * elementOpacity, svg, svgRender, bounds);
61-
}
62-
return null;
63-
}
64-
}
53+
return checkPaintServer.GetBrush(this.Opacity * elementOpacity, svg, svgRender, bounds);
54+
}
55+
}
56+
p = p.RealParent ?? p.Parent;
57+
}
58+
return null;
59+
}
60+
return paintServer.GetBrush(this.Opacity * elementOpacity, svg, svgRender, bounds);
61+
}
62+
return null;
63+
}
64+
}
6565
}

Source/SVGImage/SVG/PaintServer/PaintServerManager.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Reflection;
4+
using System.Text;
45
using System.Windows.Media;
56
using System.Xml;
67

@@ -176,12 +177,25 @@ private string ParseSolidRgbColor(string value)
176177
if (value.StartsWith("rgb("))
177178
{
178179
var newVal = value.Substring(4, value.Length - 5).Split(',');
179-
return ParseSolidColor("#" + ParseColorNumber(newVal[0]).ToString("x") + ParseColorNumber(newVal[1]).ToString("x") + ParseColorNumber(newVal[2]).ToString("x"));
180+
int alpha = 255;
181+
StringBuilder sb = new StringBuilder();
182+
sb.AppendFormat("#{0:X2}", alpha);
183+
sb.AppendFormat("{0:X2}", ParseColorNumber(newVal[0]));
184+
sb.AppendFormat("{0:X2}", ParseColorNumber(newVal[1]));
185+
sb.AppendFormat("{0:X2}", ParseColorNumber(newVal[2]));
186+
return ParseSolidColor(sb.ToString());
187+
//return ParseSolidColor("#" + ParseColorNumber(newVal[0]).ToString("x") + ParseColorNumber(newVal[1]).ToString("x") + ParseColorNumber(newVal[2]).ToString("x"));
180188
}
181189
if (value.StartsWith("rgba("))
182190
{
183191
var newVal = value.Substring(5, value.Length - 6).Split(',');
184-
return ParseSolidColor("#" + ParseColorNumber(newVal[0]).ToString("x") + ParseColorNumber(newVal[1]).ToString("x") + ParseColorNumber(newVal[2]).ToString("x") + ParseColorNumber(newVal[3]).ToString("x"));
192+
StringBuilder sb = new StringBuilder();
193+
sb.AppendFormat("#{0:X2}", ParseColorNumber(newVal[0]));
194+
sb.AppendFormat("{0:X2}", ParseColorNumber(newVal[1]));
195+
sb.AppendFormat("{0:X2}", ParseColorNumber(newVal[2]));
196+
sb.AppendFormat("{0:X2}", ParseColorNumber(newVal[3]));
197+
return ParseSolidColor(sb.ToString());
198+
//return ParseSolidColor("#" + ParseColorNumber(newVal[0]).ToString("x") + ParseColorNumber(newVal[1]).ToString("x") + ParseColorNumber(newVal[2]).ToString("x") + ParseColorNumber(newVal[3]).ToString("x"));
185199
}
186200

187201
return null;

Source/SVGImage/SVG/PaintServer/SolidColorPaintServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public override Brush GetBrush(double opacity, SVG svg, SVGRender svgRender, Rec
2323
if (Brush != null) return Brush;
2424
byte a = (byte)(255 * opacity / 100);
2525
Color c = this.Color;
26-
Color newcol = System.Windows.Media.Color.FromArgb(a, c.R, c.G, c.B);
26+
Color newcol = Color.FromArgb(a, c.R, c.G, c.B);
2727
Brush = new SolidColorBrush(newcol);
2828
return Brush;
2929
}

0 commit comments

Comments
 (0)