mirror of
https://gitee.com/csharpui/CPF.git
synced 2025-04-04 23:39:26 +08:00
解决SVG透明度和渐变显示问题
This commit is contained in:
parent
e35f7f1e41
commit
7f9eb19a7d
@ -217,6 +217,10 @@ namespace CPF.Controls
|
||||
{
|
||||
Invoke(() =>
|
||||
{
|
||||
if (!s.Equals(Source))
|
||||
{
|
||||
return;
|
||||
}
|
||||
SetImage(a);
|
||||
needDisposeImg = false;
|
||||
if (a == null)
|
||||
|
@ -2512,6 +2512,11 @@ namespace CPF.Controls
|
||||
{
|
||||
views.TryRemove(this, out _);
|
||||
base.Dispose(disposing);
|
||||
if (viewImpl != null)
|
||||
{
|
||||
viewImpl.Dispose();
|
||||
//viewImpl = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -529,11 +529,11 @@ namespace CPF.Controls
|
||||
RaiseEvent(e, nameof(Closed));
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
windowImpl.Dispose();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
//protected override void Dispose(bool disposing)
|
||||
//{
|
||||
// windowImpl.Dispose();
|
||||
// base.Dispose(disposing);
|
||||
//}
|
||||
}
|
||||
|
||||
public class ClosingEventArgs : EventArgs
|
||||
|
@ -147,8 +147,8 @@ namespace CPF.Svg
|
||||
|
||||
public override ViewFill GetBrush(double opacity)
|
||||
{
|
||||
byte a = (byte)(255 * opacity / 100);
|
||||
Color c = Color;
|
||||
byte a = (byte)(c.A * opacity / 100);
|
||||
Color newcol = Color.FromArgb(a, c.R, c.G, c.B);
|
||||
if (sb == null || sb.IsDisposed)
|
||||
{
|
||||
@ -158,7 +158,7 @@ namespace CPF.Svg
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
abstract class GradientColor : PaintServer
|
||||
internal abstract class GradientColor : PaintServer
|
||||
{
|
||||
// http://www.w3.org/TR/SVG11/pservers.html#LinearGradients
|
||||
List<GradientStop> m_stops = new List<GradientStop>();
|
||||
@ -244,7 +244,11 @@ namespace CPF.Svg
|
||||
{
|
||||
LinearGradientFill b = new LinearGradientFill();
|
||||
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.StartPoint = "0, 0";
|
||||
@ -336,7 +340,11 @@ namespace CPF.Svg
|
||||
{
|
||||
RadialGradientFill b = new RadialGradientFill();
|
||||
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.Center = "50%,50%";
|
||||
|
@ -7,240 +7,240 @@ using CPF.Drawing;
|
||||
|
||||
namespace CPF.Svg
|
||||
{
|
||||
class PathShape : SvgShape
|
||||
{
|
||||
//public class CommandSplitter
|
||||
//{
|
||||
// // 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)
|
||||
// string m_value;
|
||||
// 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' };
|
||||
// public CommandSplitter(string value)
|
||||
// {
|
||||
// m_value = value;
|
||||
// }
|
||||
// public string ReadNext()
|
||||
// {
|
||||
// int startpos = m_curPos;
|
||||
// if (startpos < 0)
|
||||
// startpos = 0;
|
||||
// if (startpos >= m_value.Length)
|
||||
// return string.Empty;
|
||||
// int cmdstart = m_value.IndexOfAny(m_commands, startpos);
|
||||
// int cmdend = cmdstart;
|
||||
// if (cmdstart >= 0)
|
||||
// cmdend = m_value.IndexOfAny(m_commands, cmdstart+1);
|
||||
// if (cmdend < 0)
|
||||
// {
|
||||
// int len = m_value.Length - startpos;
|
||||
// m_curPos = m_value.Length;
|
||||
// return m_value.Substring(startpos, len).Trim();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// int len = cmdend - startpos;
|
||||
// m_curPos = cmdend;
|
||||
// return m_value.Substring(startpos, len).Trim();
|
||||
// }
|
||||
// }
|
||||
|
||||
// ShapeUtil.StringSplitter m_splitter = new ShapeUtil.StringSplitter(string.Empty);
|
||||
// public ShapeUtil.StringSplitter SplitCommand(string command, out char cmd)
|
||||
// {
|
||||
// cmd = command[0];
|
||||
// m_splitter.SetString(command, 1);
|
||||
// return m_splitter;
|
||||
// }
|
||||
//}
|
||||
//public class PathElement
|
||||
//{
|
||||
// public char Command { get; protected set; }
|
||||
// public bool IsRelative
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return char.IsLower(Command);
|
||||
// }
|
||||
// }
|
||||
// protected PathElement(char command)
|
||||
// {
|
||||
// Command = command;
|
||||
// }
|
||||
//}
|
||||
//public class MoveTo : PathElement
|
||||
//{
|
||||
// public Point Point { get; private set; }
|
||||
// public MoveTo(char command, ShapeUtil.StringSplitter value) : base(command)
|
||||
// {
|
||||
// Point = value.ReadNextPoint();
|
||||
// }
|
||||
//}
|
||||
//public class LineTo : PathElement
|
||||
//{
|
||||
// public enum eType
|
||||
// {
|
||||
// Point,
|
||||
// Horizontal,
|
||||
// Vertical,
|
||||
// }
|
||||
// public eType PositionType { get; private set; }
|
||||
// public Point[] Points { get; private set; }
|
||||
// public LineTo(char command, ShapeUtil.StringSplitter value) : base(command)
|
||||
// {
|
||||
// if (char.ToLower(command) == 'h')
|
||||
// {
|
||||
// PositionType = eType.Horizontal;
|
||||
// double v = value.ReadNextValue();
|
||||
// Points = new Point[] { new Point((float)v, 0) };
|
||||
// return;
|
||||
// }
|
||||
// if (char.ToLower(command) == 'v')
|
||||
// {
|
||||
// PositionType = eType.Vertical;
|
||||
// double v = value.ReadNextValue();
|
||||
// Points = new Point[] { new Point(0, (float)v) };
|
||||
// return;
|
||||
// }
|
||||
|
||||
// PositionType = eType.Point;
|
||||
// List<Point> list = new List<Point>();
|
||||
// while (value.More)
|
||||
// {
|
||||
// Point p = value.ReadNextPoint();
|
||||
// list.Add(p);
|
||||
// }
|
||||
// Points = list.ToArray();
|
||||
// }
|
||||
//}
|
||||
class PathShape : SvgShape
|
||||
{
|
||||
//public class CommandSplitter
|
||||
//{
|
||||
// // 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)
|
||||
// string m_value;
|
||||
// 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' };
|
||||
// public CommandSplitter(string value)
|
||||
// {
|
||||
// m_value = value;
|
||||
// }
|
||||
// public string ReadNext()
|
||||
// {
|
||||
// int startpos = m_curPos;
|
||||
// if (startpos < 0)
|
||||
// startpos = 0;
|
||||
// if (startpos >= m_value.Length)
|
||||
// return string.Empty;
|
||||
// int cmdstart = m_value.IndexOfAny(m_commands, startpos);
|
||||
// int cmdend = cmdstart;
|
||||
// if (cmdstart >= 0)
|
||||
// cmdend = m_value.IndexOfAny(m_commands, cmdstart+1);
|
||||
// if (cmdend < 0)
|
||||
// {
|
||||
// int len = m_value.Length - startpos;
|
||||
// m_curPos = m_value.Length;
|
||||
// return m_value.Substring(startpos, len).Trim();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// int len = cmdend - startpos;
|
||||
// m_curPos = cmdend;
|
||||
// return m_value.Substring(startpos, len).Trim();
|
||||
// }
|
||||
// }
|
||||
|
||||
//public class CurveTo : PathElement
|
||||
//{
|
||||
// public Point CtrlPoint1 { get; private set; }
|
||||
// public Point CtrlPoint2 { get; private set; }
|
||||
// public Point Point { get; private set; }
|
||||
// public CurveTo(char command, ShapeUtil.StringSplitter value) : base(command)
|
||||
// {
|
||||
// CtrlPoint1 = value.ReadNextPoint();
|
||||
// CtrlPoint2 = value.ReadNextPoint();
|
||||
// Point = value.ReadNextPoint();
|
||||
// }
|
||||
// public CurveTo(char command, ShapeUtil.StringSplitter value, Point ctrlPoint1) : base(command)
|
||||
// {
|
||||
// CtrlPoint1 = ctrlPoint1;
|
||||
// CtrlPoint2 = value.ReadNextPoint();
|
||||
// Point = value.ReadNextPoint();
|
||||
// }
|
||||
//}
|
||||
//public class EllipticalArcTo : PathElement
|
||||
//{
|
||||
// public double RX { get; private set; }
|
||||
// public double RY { get; private set; }
|
||||
// public double AxisRotation { get; private set; }
|
||||
// public double X { get; private set; }
|
||||
// public double Y { get; private set; }
|
||||
// public bool Clockwise { get; private set; }
|
||||
// public bool LargeArc { get; private set; }
|
||||
// public EllipticalArcTo(char command, ShapeUtil.StringSplitter value) : base(command)
|
||||
// {
|
||||
// RX = value.ReadNextValue();
|
||||
// RY = value.ReadNextValue();
|
||||
// AxisRotation = value.ReadNextValue();
|
||||
// double arcflag = value.ReadNextValue();
|
||||
// LargeArc = (arcflag > 0);
|
||||
// double sweepflag = value.ReadNextValue();
|
||||
// Clockwise = (sweepflag > 0);
|
||||
// X = value.ReadNextValue();
|
||||
// Y = value.ReadNextValue();
|
||||
// }
|
||||
//}
|
||||
//List<PathElement> m_elements = new List<PathElement>();
|
||||
// ShapeUtil.StringSplitter m_splitter = new ShapeUtil.StringSplitter(string.Empty);
|
||||
// public ShapeUtil.StringSplitter SplitCommand(string command, out char cmd)
|
||||
// {
|
||||
// cmd = command[0];
|
||||
// m_splitter.SetString(command, 1);
|
||||
// return m_splitter;
|
||||
// }
|
||||
//}
|
||||
//public class PathElement
|
||||
//{
|
||||
// public char Command { get; protected set; }
|
||||
// public bool IsRelative
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return char.IsLower(Command);
|
||||
// }
|
||||
// }
|
||||
// protected PathElement(char command)
|
||||
// {
|
||||
// Command = command;
|
||||
// }
|
||||
//}
|
||||
//public class MoveTo : PathElement
|
||||
//{
|
||||
// public Point Point { get; private set; }
|
||||
// public MoveTo(char command, ShapeUtil.StringSplitter value) : base(command)
|
||||
// {
|
||||
// Point = value.ReadNextPoint();
|
||||
// }
|
||||
//}
|
||||
//public class LineTo : PathElement
|
||||
//{
|
||||
// public enum eType
|
||||
// {
|
||||
// Point,
|
||||
// Horizontal,
|
||||
// Vertical,
|
||||
// }
|
||||
// public eType PositionType { get; private set; }
|
||||
// public Point[] Points { get; private set; }
|
||||
// public LineTo(char command, ShapeUtil.StringSplitter value) : base(command)
|
||||
// {
|
||||
// if (char.ToLower(command) == 'h')
|
||||
// {
|
||||
// PositionType = eType.Horizontal;
|
||||
// double v = value.ReadNextValue();
|
||||
// Points = new Point[] { new Point((float)v, 0) };
|
||||
// return;
|
||||
// }
|
||||
// if (char.ToLower(command) == 'v')
|
||||
// {
|
||||
// PositionType = eType.Vertical;
|
||||
// double v = value.ReadNextValue();
|
||||
// Points = new Point[] { new Point(0, (float)v) };
|
||||
// return;
|
||||
// }
|
||||
|
||||
//public IList<PathElement> Elements
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return m_elements.AsReadOnly();
|
||||
// }
|
||||
//}
|
||||
// PositionType = eType.Point;
|
||||
// List<Point> list = new List<Point>();
|
||||
// while (value.More)
|
||||
// {
|
||||
// Point p = value.ReadNextPoint();
|
||||
// list.Add(p);
|
||||
// }
|
||||
// Points = list.ToArray();
|
||||
// }
|
||||
//}
|
||||
|
||||
public string Data { get; set; }
|
||||
//public class CurveTo : PathElement
|
||||
//{
|
||||
// public Point CtrlPoint1 { get; private set; }
|
||||
// public Point CtrlPoint2 { get; private set; }
|
||||
// public Point Point { get; private set; }
|
||||
// public CurveTo(char command, ShapeUtil.StringSplitter value) : base(command)
|
||||
// {
|
||||
// CtrlPoint1 = value.ReadNextPoint();
|
||||
// CtrlPoint2 = value.ReadNextPoint();
|
||||
// Point = value.ReadNextPoint();
|
||||
// }
|
||||
// public CurveTo(char command, ShapeUtil.StringSplitter value, Point ctrlPoint1) : base(command)
|
||||
// {
|
||||
// CtrlPoint1 = ctrlPoint1;
|
||||
// CtrlPoint2 = value.ReadNextPoint();
|
||||
// Point = value.ReadNextPoint();
|
||||
// }
|
||||
//}
|
||||
//public class EllipticalArcTo : PathElement
|
||||
//{
|
||||
// public double RX { get; private set; }
|
||||
// public double RY { get; private set; }
|
||||
// public double AxisRotation { get; private set; }
|
||||
// public double X { get; private set; }
|
||||
// public double Y { get; private set; }
|
||||
// public bool Clockwise { get; private set; }
|
||||
// public bool LargeArc { get; private set; }
|
||||
// public EllipticalArcTo(char command, ShapeUtil.StringSplitter value) : base(command)
|
||||
// {
|
||||
// RX = value.ReadNextValue();
|
||||
// RY = value.ReadNextValue();
|
||||
// AxisRotation = value.ReadNextValue();
|
||||
// double arcflag = value.ReadNextValue();
|
||||
// LargeArc = (arcflag > 0);
|
||||
// double sweepflag = value.ReadNextValue();
|
||||
// Clockwise = (sweepflag > 0);
|
||||
// X = value.ReadNextValue();
|
||||
// Y = value.ReadNextValue();
|
||||
// }
|
||||
//}
|
||||
//List<PathElement> m_elements = new List<PathElement>();
|
||||
|
||||
//public bool ClosePath { get; private set;}
|
||||
// http://apike.ca/prog_svg_paths.html
|
||||
public PathShape(XmlNode node) : base(node)
|
||||
{
|
||||
//ClosePath = false;
|
||||
string path = XmlUtil.AttrValue(node, "d", string.Empty);
|
||||
Data = path;
|
||||
//CommandSplitter cmd = new CommandSplitter(path);
|
||||
//string commandstring;
|
||||
//char command;
|
||||
//List<PathElement> elements = m_elements;
|
||||
//while (true)
|
||||
//{
|
||||
// commandstring = cmd.ReadNext();
|
||||
// if (commandstring.Length == 0)
|
||||
// break;
|
||||
// ShapeUtil.StringSplitter split = cmd.SplitCommand(commandstring, out command);
|
||||
// if (command == 'm' || command == 'M')
|
||||
// {
|
||||
// elements.Add(new MoveTo(command, split));
|
||||
// if (split.More)
|
||||
// elements.Add(new LineTo(command, split));
|
||||
// continue;
|
||||
// }
|
||||
// if (command == 'l' || command == 'L' || command == 'H' || command == 'h' || command == 'V' || command == 'v')
|
||||
// {
|
||||
// elements.Add(new LineTo(command, split));
|
||||
// continue;
|
||||
// }
|
||||
// if (command == 'c' || command == 'C')
|
||||
// {
|
||||
// while (split.More)
|
||||
// elements.Add(new CurveTo(command, split));
|
||||
// continue;
|
||||
// }
|
||||
// if (command == 's' || command == 'S')
|
||||
// {
|
||||
// while (split.More)
|
||||
// {
|
||||
// CurveTo lastshape = elements[elements.Count - 1] as CurveTo;
|
||||
// System.Diagnostics.Debug.Assert(lastshape != null);
|
||||
// elements.Add(new CurveTo(command, split, lastshape.CtrlPoint2));
|
||||
// }
|
||||
// continue;
|
||||
// }
|
||||
// if (command == 'a' || command == 'A')
|
||||
// {
|
||||
// elements.Add(new EllipticalArcTo(command, split));
|
||||
// while (split.More)
|
||||
// elements.Add(new EllipticalArcTo(command, split));
|
||||
// continue;
|
||||
// }
|
||||
// if (command == 'z' || command == 'Z')
|
||||
// {
|
||||
// ClosePath = true;
|
||||
// continue;
|
||||
// }
|
||||
//public IList<PathElement> Elements
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return m_elements.AsReadOnly();
|
||||
// }
|
||||
//}
|
||||
|
||||
// // extended format moveto or lineto can contain multiple points which should be translated into lineto
|
||||
// PathElement lastitem = elements[elements.Count-1];
|
||||
// if (lastitem is MoveTo || lastitem is LineTo || lastitem is CurveTo)
|
||||
// {
|
||||
// //Point p = Point.Parse(s);
|
||||
// //elements.Add(new LineTo(p));
|
||||
// continue;
|
||||
// }
|
||||
public string Data { get; set; }
|
||||
|
||||
//public bool ClosePath { get; private set;}
|
||||
// http://apike.ca/prog_svg_paths.html
|
||||
public PathShape(XmlNode node, SvgShape parent) : base(node, parent)
|
||||
{
|
||||
//ClosePath = false;
|
||||
string path = XmlUtil.AttrValue(node, "d", string.Empty);
|
||||
Data = path;
|
||||
//CommandSplitter cmd = new CommandSplitter(path);
|
||||
//string commandstring;
|
||||
//char command;
|
||||
//List<PathElement> elements = m_elements;
|
||||
//while (true)
|
||||
//{
|
||||
// commandstring = cmd.ReadNext();
|
||||
// if (commandstring.Length == 0)
|
||||
// break;
|
||||
// ShapeUtil.StringSplitter split = cmd.SplitCommand(commandstring, out command);
|
||||
// if (command == 'm' || command == 'M')
|
||||
// {
|
||||
// elements.Add(new MoveTo(command, split));
|
||||
// if (split.More)
|
||||
// elements.Add(new LineTo(command, split));
|
||||
// continue;
|
||||
// }
|
||||
// if (command == 'l' || command == 'L' || command == 'H' || command == 'h' || command == 'V' || command == 'v')
|
||||
// {
|
||||
// elements.Add(new LineTo(command, split));
|
||||
// continue;
|
||||
// }
|
||||
// if (command == 'c' || command == 'C')
|
||||
// {
|
||||
// while (split.More)
|
||||
// elements.Add(new CurveTo(command, split));
|
||||
// continue;
|
||||
// }
|
||||
// if (command == 's' || command == 'S')
|
||||
// {
|
||||
// while (split.More)
|
||||
// {
|
||||
// CurveTo lastshape = elements[elements.Count - 1] as CurveTo;
|
||||
// System.Diagnostics.Debug.Assert(lastshape != null);
|
||||
// elements.Add(new CurveTo(command, split, lastshape.CtrlPoint2));
|
||||
// }
|
||||
// continue;
|
||||
// }
|
||||
// if (command == 'a' || command == 'A')
|
||||
// {
|
||||
// elements.Add(new EllipticalArcTo(command, split));
|
||||
// while (split.More)
|
||||
// elements.Add(new EllipticalArcTo(command, split));
|
||||
// continue;
|
||||
// }
|
||||
// if (command == 'z' || command == 'Z')
|
||||
// {
|
||||
// ClosePath = true;
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// // extended format moveto or lineto can contain multiple points which should be translated into lineto
|
||||
// PathElement lastitem = elements[elements.Count-1];
|
||||
// if (lastitem is MoveTo || lastitem is LineTo || lastitem is CurveTo)
|
||||
// {
|
||||
// //Point p = Point.Parse(s);
|
||||
// //elements.Add(new LineTo(p));
|
||||
// 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()
|
||||
{
|
||||
return Data;
|
||||
return Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +206,10 @@ namespace CPF.Svg
|
||||
var fill = Fill;
|
||||
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;
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +63,8 @@ namespace CPF.Svg
|
||||
public float Opacity { get; set; } = 1;
|
||||
|
||||
public virtual Transform Transform { get; private set; }
|
||||
public SvgShape Parent { get; set; }
|
||||
public SvgShape(XmlNode node) : this(node, null) { }
|
||||
public SvgShape Parent { get; private set; }
|
||||
//public SvgShape(XmlNode node) : this(node, null) { }
|
||||
public SvgShape(XmlNode node, SvgShape parent) : base(node)
|
||||
{
|
||||
Parent = parent;
|
||||
@ -83,6 +83,18 @@ namespace CPF.Svg
|
||||
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)
|
||||
@ -308,7 +320,7 @@ namespace CPF.Svg
|
||||
public float Height { get; set; }
|
||||
public float RX { 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);
|
||||
Y = (float)XmlUtil.AttrValue(node, "y", 0);
|
||||
@ -399,7 +411,7 @@ namespace CPF.Svg
|
||||
public float CX { get; set; }
|
||||
public float CY { 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);
|
||||
CY = (float)XmlUtil.AttrValue(node, "cy", 0);
|
||||
@ -456,7 +468,7 @@ namespace CPF.Svg
|
||||
public float CY { get; set; }
|
||||
public float RX { 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);
|
||||
CY = (float)XmlUtil.AttrValue(node, "cy", 0);
|
||||
@ -510,7 +522,7 @@ namespace CPF.Svg
|
||||
{
|
||||
public Point P1 { 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 y1 = XmlUtil.AttrValue(node, "y1", 0);
|
||||
@ -532,7 +544,7 @@ namespace CPF.Svg
|
||||
class PolylineShape : SvgShape
|
||||
{
|
||||
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);
|
||||
ShapeUtil.StringSplitter split = new ShapeUtil.StringSplitter(points);
|
||||
@ -562,7 +574,7 @@ namespace CPF.Svg
|
||||
class PolygonShape : SvgShape
|
||||
{
|
||||
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);
|
||||
ShapeUtil.StringSplitter split = new ShapeUtil.StringSplitter(points);
|
||||
@ -595,7 +607,7 @@ namespace CPF.Svg
|
||||
public double X { get; set; }
|
||||
public double Y { 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);
|
||||
Y = XmlUtil.AttrValue(node, "y", 0);
|
||||
@ -646,21 +658,21 @@ namespace CPF.Svg
|
||||
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);
|
||||
shape.Parent = this;
|
||||
return shape;
|
||||
}
|
||||
public Group(XmlNode node, SvgShape parent) : base(node)
|
||||
{
|
||||
// parent on group must be set before children are added
|
||||
this.Parent = parent;
|
||||
//// parent on group must be set before children are added
|
||||
//this.Parent = parent;
|
||||
foreach (XmlNode childnode in node.ChildNodes)
|
||||
{
|
||||
SvgShape shape = AddToList(m_elements, childnode, this);
|
||||
if (shape != null)
|
||||
shape.Parent = this;
|
||||
//if (shape != null)
|
||||
// shape.Parent = this;
|
||||
}
|
||||
//if (Id.Length > 0)
|
||||
// svg.AddShape(Id, this);
|
||||
@ -671,37 +683,37 @@ namespace CPF.Svg
|
||||
return null;
|
||||
if (childnode.Name == SVGTags.sShapeRect)
|
||||
{
|
||||
list.Add(new RectangleShape(childnode));
|
||||
list.Add(new RectangleShape(childnode, parent));
|
||||
return list[list.Count - 1];
|
||||
}
|
||||
if (childnode.Name == SVGTags.sShapeCircle)
|
||||
{
|
||||
list.Add(new CircleShape(childnode));
|
||||
list.Add(new CircleShape(childnode, parent));
|
||||
return list[list.Count - 1];
|
||||
}
|
||||
if (childnode.Name == SVGTags.sShapeEllipse)
|
||||
{
|
||||
list.Add(new EllipseShape(childnode));
|
||||
list.Add(new EllipseShape(childnode, parent));
|
||||
return list[list.Count - 1];
|
||||
}
|
||||
if (childnode.Name == SVGTags.sShapeLine)
|
||||
{
|
||||
list.Add(new LineShape(childnode));
|
||||
list.Add(new LineShape(childnode, parent));
|
||||
return list[list.Count - 1];
|
||||
}
|
||||
if (childnode.Name == SVGTags.sShapePolyline)
|
||||
{
|
||||
list.Add(new PolylineShape(childnode));
|
||||
list.Add(new PolylineShape(childnode, parent));
|
||||
return list[list.Count - 1];
|
||||
}
|
||||
if (childnode.Name == SVGTags.sShapePolygon)
|
||||
{
|
||||
list.Add(new PolygonShape(childnode));
|
||||
list.Add(new PolygonShape(childnode, parent));
|
||||
return list[list.Count - 1];
|
||||
}
|
||||
if (childnode.Name == SVGTags.sShapePath)
|
||||
{
|
||||
list.Add(new PathShape(childnode));
|
||||
list.Add(new PathShape(childnode, parent));
|
||||
return list[list.Count - 1];
|
||||
}
|
||||
if (childnode.Name == SVGTags.sShapeGroup)
|
||||
@ -726,7 +738,7 @@ namespace CPF.Svg
|
||||
}
|
||||
if (childnode.Name == SVGTags.sShapeUse)
|
||||
{
|
||||
list.Add(new UseShape(childnode));
|
||||
list.Add(new UseShape(childnode, parent));
|
||||
return list[list.Count - 1];
|
||||
}
|
||||
//if (childnode.Name == SVGTags.sShapeImage)
|
||||
|
@ -25,11 +25,13 @@ namespace CPF.Svg
|
||||
get
|
||||
{
|
||||
|
||||
if (Color != null)
|
||||
return Color.GetBrush(Opacity);
|
||||
if (fillBrush != null)
|
||||
return fillBrush;
|
||||
return null;
|
||||
if (Color != null)
|
||||
{
|
||||
return Color.GetBrush(Opacity);
|
||||
}
|
||||
return fillBrush;
|
||||
}
|
||||
|
||||
set
|
||||
|
Loading…
Reference in New Issue
Block a user