解决SVG透明度和渐变显示问题

This commit is contained in:
小红帽 2024-01-18 22:09:17 +08:00
parent e35f7f1e41
commit 7f9eb19a7d
8 changed files with 318 additions and 268 deletions

View File

@ -217,6 +217,10 @@ namespace CPF.Controls
{ {
Invoke(() => Invoke(() =>
{ {
if (!s.Equals(Source))
{
return;
}
SetImage(a); SetImage(a);
needDisposeImg = false; needDisposeImg = false;
if (a == null) if (a == null)

View File

@ -2512,6 +2512,11 @@ namespace CPF.Controls
{ {
views.TryRemove(this, out _); views.TryRemove(this, out _);
base.Dispose(disposing); base.Dispose(disposing);
if (viewImpl != null)
{
viewImpl.Dispose();
//viewImpl = null;
}
} }
} }
/// <summary> /// <summary>

View File

@ -529,11 +529,11 @@ namespace CPF.Controls
RaiseEvent(e, nameof(Closed)); RaiseEvent(e, nameof(Closed));
} }
protected override void Dispose(bool disposing) //protected override void Dispose(bool disposing)
{ //{
windowImpl.Dispose(); // windowImpl.Dispose();
base.Dispose(disposing); // base.Dispose(disposing);
} //}
} }
public class ClosingEventArgs : EventArgs public class ClosingEventArgs : EventArgs

View File

@ -147,8 +147,8 @@ namespace CPF.Svg
public override ViewFill GetBrush(double opacity) public override ViewFill GetBrush(double opacity)
{ {
byte a = (byte)(255 * opacity / 100);
Color c = Color; Color c = Color;
byte a = (byte)(c.A * opacity / 100);
Color newcol = Color.FromArgb(a, c.R, c.G, c.B); Color newcol = Color.FromArgb(a, c.R, c.G, c.B);
if (sb == null || sb.IsDisposed) if (sb == null || sb.IsDisposed)
{ {
@ -158,7 +158,7 @@ namespace CPF.Svg
return sb; return sb;
} }
} }
abstract class GradientColor : PaintServer internal abstract class GradientColor : PaintServer
{ {
// http://www.w3.org/TR/SVG11/pservers.html#LinearGradients // http://www.w3.org/TR/SVG11/pservers.html#LinearGradients
List<GradientStop> m_stops = new List<GradientStop>(); List<GradientStop> m_stops = new List<GradientStop>();
@ -244,7 +244,11 @@ namespace CPF.Svg
{ {
LinearGradientFill b = new LinearGradientFill(); LinearGradientFill b = new LinearGradientFill();
foreach (GradientStop stop in Stops) foreach (GradientStop stop in Stops)
b.GradientStops.Add(stop); {
var c = stop.Color;
byte a = (byte)(c.A * opacity / 100);
b.GradientStops.Add(new GradientStop(Color.FromArgb(a, c.R, c.G, c.B), stop.Position));
}
//b.MappingMode = BrushMappingMode.RelativeToBoundingBox; //b.MappingMode = BrushMappingMode.RelativeToBoundingBox;
b.StartPoint = "0, 0"; b.StartPoint = "0, 0";
@ -336,7 +340,11 @@ namespace CPF.Svg
{ {
RadialGradientFill b = new RadialGradientFill(); RadialGradientFill b = new RadialGradientFill();
foreach (GradientStop stop in Stops) foreach (GradientStop stop in Stops)
b.GradientStops.Add(stop); {
var c = stop.Color;
byte a = (byte)(c.A * opacity / 100);
b.GradientStops.Add(new GradientStop(Color.FromArgb(a, c.R, c.G, c.B), stop.Position));
}
//b.GradientOrigin = new System.Windows.Point(0.5, 0.5); //b.GradientOrigin = new System.Windows.Point(0.5, 0.5);
b.Center = "50%,50%"; b.Center = "50%,50%";

View File

@ -7,240 +7,240 @@ using CPF.Drawing;
namespace CPF.Svg namespace CPF.Svg
{ {
class PathShape : SvgShape class PathShape : SvgShape
{ {
//public class CommandSplitter //public class CommandSplitter
//{ //{
// // http://www.w3.org/TR/SVGTiny12/paths.html // // http://www.w3.org/TR/SVGTiny12/paths.html
// // command is from one non numeric character to the next (-.,space is part of the numeric value since it defines a point) // // command is from one non numeric character to the next (-.,space is part of the numeric value since it defines a point)
// string m_value; // string m_value;
// int m_curPos = -1; // int m_curPos = -1;
// char[] m_commands = new char[] {'m', 'M', 'z', 'Z', 'A', 'a', 'L', 'l', 'h', 'H', 'v', 'V', 'c', 'C', 's', 'S' }; // char[] m_commands = new char[] {'m', 'M', 'z', 'Z', 'A', 'a', 'L', 'l', 'h', 'H', 'v', 'V', 'c', 'C', 's', 'S' };
// public CommandSplitter(string value) // public CommandSplitter(string value)
// { // {
// m_value = value; // m_value = value;
// } // }
// public string ReadNext() // public string ReadNext()
// { // {
// int startpos = m_curPos; // int startpos = m_curPos;
// if (startpos < 0) // if (startpos < 0)
// startpos = 0; // startpos = 0;
// if (startpos >= m_value.Length) // if (startpos >= m_value.Length)
// return string.Empty; // return string.Empty;
// int cmdstart = m_value.IndexOfAny(m_commands, startpos); // int cmdstart = m_value.IndexOfAny(m_commands, startpos);
// int cmdend = cmdstart; // int cmdend = cmdstart;
// if (cmdstart >= 0) // if (cmdstart >= 0)
// cmdend = m_value.IndexOfAny(m_commands, cmdstart+1); // cmdend = m_value.IndexOfAny(m_commands, cmdstart+1);
// if (cmdend < 0) // if (cmdend < 0)
// { // {
// int len = m_value.Length - startpos; // int len = m_value.Length - startpos;
// m_curPos = m_value.Length; // m_curPos = m_value.Length;
// return m_value.Substring(startpos, len).Trim(); // return m_value.Substring(startpos, len).Trim();
// } // }
// else // else
// { // {
// int len = cmdend - startpos; // int len = cmdend - startpos;
// m_curPos = cmdend; // m_curPos = cmdend;
// return m_value.Substring(startpos, len).Trim(); // return m_value.Substring(startpos, len).Trim();
// } // }
// } // }
// ShapeUtil.StringSplitter m_splitter = new ShapeUtil.StringSplitter(string.Empty); // ShapeUtil.StringSplitter m_splitter = new ShapeUtil.StringSplitter(string.Empty);
// public ShapeUtil.StringSplitter SplitCommand(string command, out char cmd) // public ShapeUtil.StringSplitter SplitCommand(string command, out char cmd)
// { // {
// cmd = command[0]; // cmd = command[0];
// m_splitter.SetString(command, 1); // m_splitter.SetString(command, 1);
// return m_splitter; // return m_splitter;
// } // }
//} //}
//public class PathElement //public class PathElement
//{ //{
// public char Command { get; protected set; } // public char Command { get; protected set; }
// public bool IsRelative // public bool IsRelative
// { // {
// get // get
// { // {
// return char.IsLower(Command); // return char.IsLower(Command);
// } // }
// } // }
// protected PathElement(char command) // protected PathElement(char command)
// { // {
// Command = command; // Command = command;
// } // }
//} //}
//public class MoveTo : PathElement //public class MoveTo : PathElement
//{ //{
// public Point Point { get; private set; } // public Point Point { get; private set; }
// public MoveTo(char command, ShapeUtil.StringSplitter value) : base(command) // public MoveTo(char command, ShapeUtil.StringSplitter value) : base(command)
// { // {
// Point = value.ReadNextPoint(); // Point = value.ReadNextPoint();
// } // }
//} //}
//public class LineTo : PathElement //public class LineTo : PathElement
//{ //{
// public enum eType // public enum eType
// { // {
// Point, // Point,
// Horizontal, // Horizontal,
// Vertical, // Vertical,
// } // }
// public eType PositionType { get; private set; } // public eType PositionType { get; private set; }
// public Point[] Points { get; private set; } // public Point[] Points { get; private set; }
// public LineTo(char command, ShapeUtil.StringSplitter value) : base(command) // public LineTo(char command, ShapeUtil.StringSplitter value) : base(command)
// { // {
// if (char.ToLower(command) == 'h') // if (char.ToLower(command) == 'h')
// { // {
// PositionType = eType.Horizontal; // PositionType = eType.Horizontal;
// double v = value.ReadNextValue(); // double v = value.ReadNextValue();
// Points = new Point[] { new Point((float)v, 0) }; // Points = new Point[] { new Point((float)v, 0) };
// return; // return;
// } // }
// if (char.ToLower(command) == 'v') // if (char.ToLower(command) == 'v')
// { // {
// PositionType = eType.Vertical; // PositionType = eType.Vertical;
// double v = value.ReadNextValue(); // double v = value.ReadNextValue();
// Points = new Point[] { new Point(0, (float)v) }; // Points = new Point[] { new Point(0, (float)v) };
// return; // return;
// } // }
// PositionType = eType.Point; // PositionType = eType.Point;
// List<Point> list = new List<Point>(); // List<Point> list = new List<Point>();
// while (value.More) // while (value.More)
// { // {
// Point p = value.ReadNextPoint(); // Point p = value.ReadNextPoint();
// list.Add(p); // list.Add(p);
// } // }
// Points = list.ToArray(); // Points = list.ToArray();
// } // }
//} //}
//public class CurveTo : PathElement //public class CurveTo : PathElement
//{ //{
// public Point CtrlPoint1 { get; private set; } // public Point CtrlPoint1 { get; private set; }
// public Point CtrlPoint2 { get; private set; } // public Point CtrlPoint2 { get; private set; }
// public Point Point { get; private set; } // public Point Point { get; private set; }
// public CurveTo(char command, ShapeUtil.StringSplitter value) : base(command) // public CurveTo(char command, ShapeUtil.StringSplitter value) : base(command)
// { // {
// CtrlPoint1 = value.ReadNextPoint(); // CtrlPoint1 = value.ReadNextPoint();
// CtrlPoint2 = value.ReadNextPoint(); // CtrlPoint2 = value.ReadNextPoint();
// Point = value.ReadNextPoint(); // Point = value.ReadNextPoint();
// } // }
// public CurveTo(char command, ShapeUtil.StringSplitter value, Point ctrlPoint1) : base(command) // public CurveTo(char command, ShapeUtil.StringSplitter value, Point ctrlPoint1) : base(command)
// { // {
// CtrlPoint1 = ctrlPoint1; // CtrlPoint1 = ctrlPoint1;
// CtrlPoint2 = value.ReadNextPoint(); // CtrlPoint2 = value.ReadNextPoint();
// Point = value.ReadNextPoint(); // Point = value.ReadNextPoint();
// } // }
//} //}
//public class EllipticalArcTo : PathElement //public class EllipticalArcTo : PathElement
//{ //{
// public double RX { get; private set; } // public double RX { get; private set; }
// public double RY { get; private set; } // public double RY { get; private set; }
// public double AxisRotation { get; private set; } // public double AxisRotation { get; private set; }
// public double X { get; private set; } // public double X { get; private set; }
// public double Y { get; private set; } // public double Y { get; private set; }
// public bool Clockwise { get; private set; } // public bool Clockwise { get; private set; }
// public bool LargeArc { get; private set; } // public bool LargeArc { get; private set; }
// public EllipticalArcTo(char command, ShapeUtil.StringSplitter value) : base(command) // public EllipticalArcTo(char command, ShapeUtil.StringSplitter value) : base(command)
// { // {
// RX = value.ReadNextValue(); // RX = value.ReadNextValue();
// RY = value.ReadNextValue(); // RY = value.ReadNextValue();
// AxisRotation = value.ReadNextValue(); // AxisRotation = value.ReadNextValue();
// double arcflag = value.ReadNextValue(); // double arcflag = value.ReadNextValue();
// LargeArc = (arcflag > 0); // LargeArc = (arcflag > 0);
// double sweepflag = value.ReadNextValue(); // double sweepflag = value.ReadNextValue();
// Clockwise = (sweepflag > 0); // Clockwise = (sweepflag > 0);
// X = value.ReadNextValue(); // X = value.ReadNextValue();
// Y = value.ReadNextValue(); // Y = value.ReadNextValue();
// } // }
//} //}
//List<PathElement> m_elements = new List<PathElement>(); //List<PathElement> m_elements = new List<PathElement>();
//public IList<PathElement> Elements //public IList<PathElement> Elements
//{ //{
// get // get
// { // {
// return m_elements.AsReadOnly(); // return m_elements.AsReadOnly();
// } // }
//} //}
public string Data { get; set; } public string Data { get; set; }
//public bool ClosePath { get; private set;} //public bool ClosePath { get; private set;}
// http://apike.ca/prog_svg_paths.html // http://apike.ca/prog_svg_paths.html
public PathShape(XmlNode node) : base(node) public PathShape(XmlNode node, SvgShape parent) : base(node, parent)
{ {
//ClosePath = false; //ClosePath = false;
string path = XmlUtil.AttrValue(node, "d", string.Empty); string path = XmlUtil.AttrValue(node, "d", string.Empty);
Data = path; Data = path;
//CommandSplitter cmd = new CommandSplitter(path); //CommandSplitter cmd = new CommandSplitter(path);
//string commandstring; //string commandstring;
//char command; //char command;
//List<PathElement> elements = m_elements; //List<PathElement> elements = m_elements;
//while (true) //while (true)
//{ //{
// commandstring = cmd.ReadNext(); // commandstring = cmd.ReadNext();
// if (commandstring.Length == 0) // if (commandstring.Length == 0)
// break; // break;
// ShapeUtil.StringSplitter split = cmd.SplitCommand(commandstring, out command); // ShapeUtil.StringSplitter split = cmd.SplitCommand(commandstring, out command);
// if (command == 'm' || command == 'M') // if (command == 'm' || command == 'M')
// { // {
// elements.Add(new MoveTo(command, split)); // elements.Add(new MoveTo(command, split));
// if (split.More) // if (split.More)
// elements.Add(new LineTo(command, split)); // elements.Add(new LineTo(command, split));
// continue; // continue;
// } // }
// if (command == 'l' || command == 'L' || command == 'H' || command == 'h' || command == 'V' || command == 'v') // if (command == 'l' || command == 'L' || command == 'H' || command == 'h' || command == 'V' || command == 'v')
// { // {
// elements.Add(new LineTo(command, split)); // elements.Add(new LineTo(command, split));
// continue; // continue;
// } // }
// if (command == 'c' || command == 'C') // if (command == 'c' || command == 'C')
// { // {
// while (split.More) // while (split.More)
// elements.Add(new CurveTo(command, split)); // elements.Add(new CurveTo(command, split));
// continue; // continue;
// } // }
// if (command == 's' || command == 'S') // if (command == 's' || command == 'S')
// { // {
// while (split.More) // while (split.More)
// { // {
// CurveTo lastshape = elements[elements.Count - 1] as CurveTo; // CurveTo lastshape = elements[elements.Count - 1] as CurveTo;
// System.Diagnostics.Debug.Assert(lastshape != null); // System.Diagnostics.Debug.Assert(lastshape != null);
// elements.Add(new CurveTo(command, split, lastshape.CtrlPoint2)); // elements.Add(new CurveTo(command, split, lastshape.CtrlPoint2));
// } // }
// continue; // continue;
// } // }
// if (command == 'a' || command == 'A') // if (command == 'a' || command == 'A')
// { // {
// elements.Add(new EllipticalArcTo(command, split)); // elements.Add(new EllipticalArcTo(command, split));
// while (split.More) // while (split.More)
// elements.Add(new EllipticalArcTo(command, split)); // elements.Add(new EllipticalArcTo(command, split));
// continue; // continue;
// } // }
// if (command == 'z' || command == 'Z') // if (command == 'z' || command == 'Z')
// { // {
// ClosePath = true; // ClosePath = true;
// continue; // continue;
// } // }
// // extended format moveto or lineto can contain multiple points which should be translated into lineto // // extended format moveto or lineto can contain multiple points which should be translated into lineto
// PathElement lastitem = elements[elements.Count-1]; // PathElement lastitem = elements[elements.Count-1];
// if (lastitem is MoveTo || lastitem is LineTo || lastitem is CurveTo) // if (lastitem is MoveTo || lastitem is LineTo || lastitem is CurveTo)
// { // {
// //Point p = Point.Parse(s); // //Point p = Point.Parse(s);
// //elements.Add(new LineTo(p)); // //elements.Add(new LineTo(p));
// continue; // continue;
// } // }
// System.Diagnostics.Debug.Assert(false, string.Format("type '{0}' not supported", commandstring)); // System.Diagnostics.Debug.Assert(false, string.Format("type '{0}' not supported", commandstring));
//} //}
} }
public override PathGeometry CreateGeometry() public override PathGeometry CreateGeometry()
{ {
return Data; return Data;
} }
} }
} }

View File

@ -206,7 +206,10 @@ namespace CPF.Svg
var fill = Fill; var fill = Fill;
foreach (var item in m_elements) foreach (var item in m_elements)
{ {
item.GetFill().FillBrush = fill; if (item.GetFill().Color == null)
{
item.GetFill().FillBrush = fill;
}
} }
} }
@ -245,7 +248,10 @@ namespace CPF.Svg
var fill = newValue as ViewFill; var fill = newValue as ViewFill;
foreach (var item in m_elements) foreach (var item in m_elements)
{ {
item.GetFill().FillBrush = fill; if (item.GetFill().Color == null)
{
item.GetFill().FillBrush = fill;
}
} }
} }
@ -505,9 +511,22 @@ namespace CPF.Svg
} }
if (item.Fill != null && item.Fill.FillBrush != null) if (item.Fill != null && item.Fill.FillBrush != null)
{ {
using (var brush = item.Fill.FillBrush.CreateBrush(item.Geometry.GetBounds(), Root.RenderScaling)) if (item.Fill.Color is GradientColor svgFill)
{ {
dc.FillPath(brush, item.Geometry); using (var brush = item.Fill.FillBrush.CreateBrush(svgFill.GradientUnits == SVGTags.sGradientUserSpace ? new Rect(0, 0, naturalSize.Width, naturalSize.Height) : item.Geometry.GetBounds(), Root.RenderScaling))
{
dc.FillPath(brush, item.Geometry);
}
}
else
{
if (item.Fill.Color != null)
{
using (var brush = item.Fill.FillBrush.CreateBrush(item.Geometry.GetBounds(), Root.RenderScaling))
{
dc.FillPath(brush, item.Geometry);
}
}
} }
} }
} }

View File

@ -63,8 +63,8 @@ namespace CPF.Svg
public float Opacity { get; set; } = 1; public float Opacity { get; set; } = 1;
public virtual Transform Transform { get; private set; } public virtual Transform Transform { get; private set; }
public SvgShape Parent { get; set; } public SvgShape Parent { get; private set; }
public SvgShape(XmlNode node) : this(node, null) { } //public SvgShape(XmlNode node) : this(node, null) { }
public SvgShape(XmlNode node, SvgShape parent) : base(node) public SvgShape(XmlNode node, SvgShape parent) : base(node)
{ {
Parent = parent; Parent = parent;
@ -83,6 +83,18 @@ namespace CPF.Svg
m_stroke.Opacity *= Opacity; m_stroke.Opacity *= Opacity;
} }
} }
if (parent != null && parent.Opacity != 1)
{
if (m_fill != null)
{
m_fill.Opacity *= parent.Opacity;
m_fill.FillBrush = null;
}
if (m_stroke != null)
{
m_stroke.Opacity *= parent.Opacity;
}
}
} }
} }
public SvgShape(List<ShapeUtil.Attribute> attrs, SvgShape parent) : base(null) public SvgShape(List<ShapeUtil.Attribute> attrs, SvgShape parent) : base(null)
@ -308,7 +320,7 @@ namespace CPF.Svg
public float Height { get; set; } public float Height { get; set; }
public float RX { get; set; } public float RX { get; set; }
public float RY { get; set; } public float RY { get; set; }
public RectangleShape(XmlNode node) : base(node) public RectangleShape(XmlNode node, SvgShape parent) : base(node, parent)
{ {
X = (float)XmlUtil.AttrValue(node, "x", 0); X = (float)XmlUtil.AttrValue(node, "x", 0);
Y = (float)XmlUtil.AttrValue(node, "y", 0); Y = (float)XmlUtil.AttrValue(node, "y", 0);
@ -399,7 +411,7 @@ namespace CPF.Svg
public float CX { get; set; } public float CX { get; set; }
public float CY { get; set; } public float CY { get; set; }
public float R { get; set; } public float R { get; set; }
public CircleShape(XmlNode node) : base(node) public CircleShape(XmlNode node, SvgShape parent) : base(node, parent)
{ {
CX = (float)XmlUtil.AttrValue(node, "cx", 0); CX = (float)XmlUtil.AttrValue(node, "cx", 0);
CY = (float)XmlUtil.AttrValue(node, "cy", 0); CY = (float)XmlUtil.AttrValue(node, "cy", 0);
@ -456,7 +468,7 @@ namespace CPF.Svg
public float CY { get; set; } public float CY { get; set; }
public float RX { get; set; } public float RX { get; set; }
public float RY { get; set; } public float RY { get; set; }
public EllipseShape(XmlNode node) : base(node) public EllipseShape(XmlNode node, SvgShape parent) : base(node, parent)
{ {
CX = (float)XmlUtil.AttrValue(node, "cx", 0); CX = (float)XmlUtil.AttrValue(node, "cx", 0);
CY = (float)XmlUtil.AttrValue(node, "cy", 0); CY = (float)XmlUtil.AttrValue(node, "cy", 0);
@ -510,7 +522,7 @@ namespace CPF.Svg
{ {
public Point P1 { get; private set; } public Point P1 { get; private set; }
public Point P2 { get; private set; } public Point P2 { get; private set; }
public LineShape(XmlNode node) : base(node) public LineShape(XmlNode node, SvgShape parent) : base(node, parent)
{ {
double x1 = XmlUtil.AttrValue(node, "x1", 0); double x1 = XmlUtil.AttrValue(node, "x1", 0);
double y1 = XmlUtil.AttrValue(node, "y1", 0); double y1 = XmlUtil.AttrValue(node, "y1", 0);
@ -532,7 +544,7 @@ namespace CPF.Svg
class PolylineShape : SvgShape class PolylineShape : SvgShape
{ {
public Point[] Points { get; private set; } public Point[] Points { get; private set; }
public PolylineShape(XmlNode node) : base(node) public PolylineShape(XmlNode node, SvgShape parent) : base(node, parent)
{ {
string points = XmlUtil.AttrValue(node, SVGTags.sPoints, string.Empty); string points = XmlUtil.AttrValue(node, SVGTags.sPoints, string.Empty);
ShapeUtil.StringSplitter split = new ShapeUtil.StringSplitter(points); ShapeUtil.StringSplitter split = new ShapeUtil.StringSplitter(points);
@ -562,7 +574,7 @@ namespace CPF.Svg
class PolygonShape : SvgShape class PolygonShape : SvgShape
{ {
public Point[] Points { get; private set; } public Point[] Points { get; private set; }
public PolygonShape(XmlNode node) : base(node) public PolygonShape(XmlNode node, SvgShape parent) : base(node, parent)
{ {
string points = XmlUtil.AttrValue(node, SVGTags.sPoints, string.Empty); string points = XmlUtil.AttrValue(node, SVGTags.sPoints, string.Empty);
ShapeUtil.StringSplitter split = new ShapeUtil.StringSplitter(points); ShapeUtil.StringSplitter split = new ShapeUtil.StringSplitter(points);
@ -595,7 +607,7 @@ namespace CPF.Svg
public double X { get; set; } public double X { get; set; }
public double Y { get; set; } public double Y { get; set; }
public string hRef { get; set; } public string hRef { get; set; }
public UseShape(XmlNode node) : base(node) public UseShape(XmlNode node, SvgShape parent) : base(node, parent)
{ {
X = XmlUtil.AttrValue(node, "x", 0); X = XmlUtil.AttrValue(node, "x", 0);
Y = XmlUtil.AttrValue(node, "y", 0); Y = XmlUtil.AttrValue(node, "y", 0);
@ -646,21 +658,21 @@ namespace CPF.Svg
get { return m_elements; } get { return m_elements; }
} }
SvgShape AddChild(SvgShape shape) //SvgShape AddChild(SvgShape shape)
//{
// m_elements.Add(shape);
// shape.Parent = this;
// return shape;
//}
public Group(XmlNode node, SvgShape parent) : base(node, parent)
{ {
m_elements.Add(shape); //// parent on group must be set before children are added
shape.Parent = this; //this.Parent = parent;
return shape;
}
public Group(XmlNode node, SvgShape parent) : base(node)
{
// parent on group must be set before children are added
this.Parent = parent;
foreach (XmlNode childnode in node.ChildNodes) foreach (XmlNode childnode in node.ChildNodes)
{ {
SvgShape shape = AddToList(m_elements, childnode, this); SvgShape shape = AddToList(m_elements, childnode, this);
if (shape != null) //if (shape != null)
shape.Parent = this; // shape.Parent = this;
} }
//if (Id.Length > 0) //if (Id.Length > 0)
// svg.AddShape(Id, this); // svg.AddShape(Id, this);
@ -671,37 +683,37 @@ namespace CPF.Svg
return null; return null;
if (childnode.Name == SVGTags.sShapeRect) if (childnode.Name == SVGTags.sShapeRect)
{ {
list.Add(new RectangleShape(childnode)); list.Add(new RectangleShape(childnode, parent));
return list[list.Count - 1]; return list[list.Count - 1];
} }
if (childnode.Name == SVGTags.sShapeCircle) if (childnode.Name == SVGTags.sShapeCircle)
{ {
list.Add(new CircleShape(childnode)); list.Add(new CircleShape(childnode, parent));
return list[list.Count - 1]; return list[list.Count - 1];
} }
if (childnode.Name == SVGTags.sShapeEllipse) if (childnode.Name == SVGTags.sShapeEllipse)
{ {
list.Add(new EllipseShape(childnode)); list.Add(new EllipseShape(childnode, parent));
return list[list.Count - 1]; return list[list.Count - 1];
} }
if (childnode.Name == SVGTags.sShapeLine) if (childnode.Name == SVGTags.sShapeLine)
{ {
list.Add(new LineShape(childnode)); list.Add(new LineShape(childnode, parent));
return list[list.Count - 1]; return list[list.Count - 1];
} }
if (childnode.Name == SVGTags.sShapePolyline) if (childnode.Name == SVGTags.sShapePolyline)
{ {
list.Add(new PolylineShape(childnode)); list.Add(new PolylineShape(childnode, parent));
return list[list.Count - 1]; return list[list.Count - 1];
} }
if (childnode.Name == SVGTags.sShapePolygon) if (childnode.Name == SVGTags.sShapePolygon)
{ {
list.Add(new PolygonShape(childnode)); list.Add(new PolygonShape(childnode, parent));
return list[list.Count - 1]; return list[list.Count - 1];
} }
if (childnode.Name == SVGTags.sShapePath) if (childnode.Name == SVGTags.sShapePath)
{ {
list.Add(new PathShape(childnode)); list.Add(new PathShape(childnode, parent));
return list[list.Count - 1]; return list[list.Count - 1];
} }
if (childnode.Name == SVGTags.sShapeGroup) if (childnode.Name == SVGTags.sShapeGroup)
@ -726,7 +738,7 @@ namespace CPF.Svg
} }
if (childnode.Name == SVGTags.sShapeUse) if (childnode.Name == SVGTags.sShapeUse)
{ {
list.Add(new UseShape(childnode)); list.Add(new UseShape(childnode, parent));
return list[list.Count - 1]; return list[list.Count - 1];
} }
//if (childnode.Name == SVGTags.sShapeImage) //if (childnode.Name == SVGTags.sShapeImage)

View File

@ -25,11 +25,13 @@ namespace CPF.Svg
get get
{ {
if (Color != null)
return Color.GetBrush(Opacity);
if (fillBrush != null) if (fillBrush != null)
return fillBrush; return fillBrush;
return null; if (Color != null)
{
return Color.GetBrush(Opacity);
}
return fillBrush;
} }
set set