From eb6eff988371ffa7563e682838046b4d1b941a36 Mon Sep 17 00:00:00 2001 From: Paul Selormey Date: Sun, 24 Dec 2023 11:43:01 +0900 Subject: [PATCH] Release 5.1.1 (#91) * Bug fixes and code improvements - Fixed the issue #89 - Removed the private ControlLine class (no longer used as path is parsed with WPF parser) - Add IsDefault property to Fill and Stroke to make default fills and strokes known - Eliminated the 135, warning CA1416: This call site is reachable on all platforms. - Eliminated some "as" casts, with the new "is" syntax. * Updated Version Information --- Docs/index.md | 10 +- GitVersion.yml | 2 +- README.md | 10 +- Samples/ClipArtViewer/ClipArtViewer.csproj | 11 ++ .../ClipArtViewer/Properties/AssemblyInfo.cs | 4 + .../CustomBrushesExample.csproj | 11 ++ .../Properties/AssemblyInfo.cs | 4 + Samples/Example/Properties/AssemblyInfo.cs | 4 + .../Properties/AssemblyInfo.cs | 4 + .../SVGImage/DotNetProjects.SVGImage.csproj | 8 +- Source/SVGImage/Properties/AssemblyInfo.cs | 4 + Source/SVGImage/SVG/Fill.cs | 63 ++++++++- .../SVG/PaintServers/PaintServerManager.cs | 3 +- Source/SVGImage/SVG/SVGRender.cs | 123 +++++------------- Source/SVGImage/SVG/Shapes/CircleShape.cs | 16 +++ Source/SVGImage/SVG/Shapes/EllipseShape.cs | 16 +++ Source/SVGImage/SVG/Shapes/PathShape.cs | 3 +- Source/SVGImage/SVG/Shapes/PolygonShape.cs | 3 +- Source/SVGImage/SVG/Shapes/RectangleShape.cs | 3 +- Source/SVGImage/SVG/Shapes/Text.cs | 48 +++---- Source/SVGImage/SVG/Stroke.cs | 101 ++++++++++++-- Tests/SvgTestBox/Properties/AssemblyInfo.cs | 4 + .../SvgTestSuites/Properties/AssemblyInfo.cs | 4 + 23 files changed, 308 insertions(+), 151 deletions(-) diff --git a/Docs/index.md b/Docs/index.md index 0b2b09f..1ab8983 100644 --- a/Docs/index.md +++ b/Docs/index.md @@ -15,13 +15,13 @@ The respository includes * **Samples:** For sample applications * **Docs:** For the documentations (in markdown format). -The command lines installation options are: For the version `5.1.0` -* **.NET CLI:** dotnet add package DotNetProjects.SVGImage --version 5.1.0 -* **Package Manager:** NuGet\Install-Package DotNetProjects.SVGImage -Version 5.1.0 +The command lines installation options are: For the version `5.1.1` +* **.NET CLI:** dotnet add package DotNetProjects.SVGImage --version 5.1.1 +* **Package Manager:** NuGet\Install-Package DotNetProjects.SVGImage -Version 5.1.1 -For reference in projects use: For the version `5.1.0` +For reference in projects use: For the version `5.1.1` ```xml - + ``` ## How to build diff --git a/GitVersion.yml b/GitVersion.yml index a812e41..b1b4f41 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1 +1 @@ -next-version: 5.1.0 +next-version: 5.1.1 diff --git a/README.md b/README.md index f9a1063..7b6710b 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,13 @@ The respository includes * **Samples:** For sample applications * **Docs:** For the documentations (in markdown format). -The command lines installation options are: For the version `5.1.0` -* **.NET CLI:** dotnet add package DotNetProjects.SVGImage --version 5.1.0 -* **Package Manager:** NuGet\Install-Package DotNetProjects.SVGImage -Version 5.1.0 +The command lines installation options are: For the version `5.1.1` +* **.NET CLI:** dotnet add package DotNetProjects.SVGImage --version 5.1.1 +* **Package Manager:** NuGet\Install-Package DotNetProjects.SVGImage -Version 5.1.1 -For reference in projects use: For the version `5.1.0` +For reference in projects use: For the version `5.1.1` ```xml - + ``` ## How to build diff --git a/Samples/ClipArtViewer/ClipArtViewer.csproj b/Samples/ClipArtViewer/ClipArtViewer.csproj index 08e36ec..ce1f982 100644 --- a/Samples/ClipArtViewer/ClipArtViewer.csproj +++ b/Samples/ClipArtViewer/ClipArtViewer.csproj @@ -30,6 +30,17 @@ ClipArtViewer.ico + + $(DefineConstants);DOTNET40;NETFULL + $(DefineConstants);DOTNET45;NETFULL + $(DefineConstants);DOTNET46;NETFULL + $(DefineConstants);DOTNET47;NETFULL + $(DefineConstants);DOTNET48;NETFULL + $(DefineConstants);NETCORE + $(DefineConstants);NETCORE;NETNEXT + $(DefineConstants);NETCORE;NETNEXT + $(DefineConstants);NETCORE;NETNEXT + diff --git a/Samples/ClipArtViewer/Properties/AssemblyInfo.cs b/Samples/ClipArtViewer/Properties/AssemblyInfo.cs index d6798f2..0713209 100644 --- a/Samples/ClipArtViewer/Properties/AssemblyInfo.cs +++ b/Samples/ClipArtViewer/Properties/AssemblyInfo.cs @@ -4,6 +4,10 @@ using System.Runtime.InteropServices; using System.Windows; +#if NETNEXT +[assembly: System.Runtime.Versioning.SupportedOSPlatform("windows7.0")] +#endif + // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. diff --git a/Samples/CustomBrushesExample/CustomBrushesExample.csproj b/Samples/CustomBrushesExample/CustomBrushesExample.csproj index 4455840..aae39c8 100644 --- a/Samples/CustomBrushesExample/CustomBrushesExample.csproj +++ b/Samples/CustomBrushesExample/CustomBrushesExample.csproj @@ -25,6 +25,17 @@ CustomBrushesExample.ico + + $(DefineConstants);DOTNET40;NETFULL + $(DefineConstants);DOTNET45;NETFULL + $(DefineConstants);DOTNET46;NETFULL + $(DefineConstants);DOTNET47;NETFULL + $(DefineConstants);DOTNET48;NETFULL + $(DefineConstants);NETCORE + $(DefineConstants);NETCORE;NETNEXT + $(DefineConstants);NETCORE;NETNEXT + $(DefineConstants);NETCORE;NETNEXT + diff --git a/Samples/CustomBrushesExample/Properties/AssemblyInfo.cs b/Samples/CustomBrushesExample/Properties/AssemblyInfo.cs index 8267343..2e2417e 100644 --- a/Samples/CustomBrushesExample/Properties/AssemblyInfo.cs +++ b/Samples/CustomBrushesExample/Properties/AssemblyInfo.cs @@ -4,6 +4,10 @@ using System.Runtime.InteropServices; using System.Windows; +#if NETNEXT +[assembly: System.Runtime.Versioning.SupportedOSPlatform("windows7.0")] +#endif + // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. diff --git a/Samples/Example/Properties/AssemblyInfo.cs b/Samples/Example/Properties/AssemblyInfo.cs index 3c10cc6..e283cb4 100644 --- a/Samples/Example/Properties/AssemblyInfo.cs +++ b/Samples/Example/Properties/AssemblyInfo.cs @@ -4,6 +4,10 @@ using System.Runtime.InteropServices; using System.Windows; +#if NETNEXT +[assembly: System.Runtime.Versioning.SupportedOSPlatform("windows7.0")] +#endif + // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. diff --git a/Samples/IconConverterSample/Properties/AssemblyInfo.cs b/Samples/IconConverterSample/Properties/AssemblyInfo.cs index cbf533b..325b26e 100644 --- a/Samples/IconConverterSample/Properties/AssemblyInfo.cs +++ b/Samples/IconConverterSample/Properties/AssemblyInfo.cs @@ -4,6 +4,10 @@ using System.Runtime.InteropServices; using System.Windows; +#if NETNEXT +[assembly: System.Runtime.Versioning.SupportedOSPlatform("windows7.0")] +#endif + // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. diff --git a/Source/SVGImage/DotNetProjects.SVGImage.csproj b/Source/SVGImage/DotNetProjects.SVGImage.csproj index f087dac..b214cf0 100644 --- a/Source/SVGImage/DotNetProjects.SVGImage.csproj +++ b/Source/SVGImage/DotNetProjects.SVGImage.csproj @@ -11,9 +11,9 @@ DotNetProjects.SVGImage 2020-2023 DotNetProjects MIT - 5.1.0.0 - 5.1.0.0 - 5.1.0 + 5.1.1.0 + 5.1.1.0 + 5.1.1 Library Debug;Release @@ -31,7 +31,7 @@ Readme.md true - 5.0.118 + 5.1.0 diff --git a/Source/SVGImage/Properties/AssemblyInfo.cs b/Source/SVGImage/Properties/AssemblyInfo.cs index 1747c1d..fcd173e 100644 --- a/Source/SVGImage/Properties/AssemblyInfo.cs +++ b/Source/SVGImage/Properties/AssemblyInfo.cs @@ -2,6 +2,10 @@ using System.Windows; using System.Windows.Markup; +#if NETNEXT +[assembly: System.Runtime.Versioning.SupportedOSPlatform("windows7.0")] +#endif + //In order to begin building localizable applications, set //CultureYouAreCodingWith in your .csproj file //inside a . For example, if you are using US english diff --git a/Source/SVGImage/SVG/Fill.cs b/Source/SVGImage/SVG/Fill.cs index 67ae31d..6f0d082 100644 --- a/Source/SVGImage/SVG/Fill.cs +++ b/Source/SVGImage/SVG/Fill.cs @@ -1,4 +1,5 @@ -using System.Windows; +using System.Diagnostics; +using System.Windows; using System.Windows.Media; namespace SVGImage.SVG @@ -14,16 +15,66 @@ public enum eFillRule evenodd } - public eFillRule FillRule { get; set;} + private SVG _svg; - public string PaintServerKey {get; set;} + private bool _isDefault; - public double Opacity {get; set;} + private eFillRule _fillRule; + + private string _paintServerKey; + + private double _opacity; public Fill(SVG svg) { - this.FillRule = eFillRule.nonzero; - this.Opacity = 100; + _fillRule = eFillRule.nonzero; + _opacity = 100; + _isDefault = false; + _svg = svg; + } + + public static Fill CreateDefault(SVG svg, string fillColor) + { + var fill = new Fill(svg); + fill.PaintServerKey = svg.PaintServers.Parse(fillColor); + + fill._isDefault = true; + + return fill; + } + + public SVG get => _svg; + + public bool IsDefault + { + get => _isDefault; + set => _isDefault = value; + } + + public eFillRule FillRule { + get => _fillRule; + set { + Debug.Assert(_isDefault == false); + _fillRule = value; + } + } + + public string PaintServerKey + { + get => _paintServerKey; + set { + Debug.Assert(_isDefault == false); + _paintServerKey = value; + } + } + + public double Opacity + { + get => _opacity; + set { + Debug.Assert(_isDefault == false); + _opacity = value; + } } public bool IsEmpty(SVG svg) diff --git a/Source/SVGImage/SVG/PaintServers/PaintServerManager.cs b/Source/SVGImage/SVG/PaintServers/PaintServerManager.cs index 50356e2..0dae10f 100644 --- a/Source/SVGImage/SVG/PaintServers/PaintServerManager.cs +++ b/Source/SVGImage/SVG/PaintServers/PaintServerManager.cs @@ -244,7 +244,8 @@ private string ParseKnownColor(string value) private static void LoadKnownColors() { - if (m_knownColors == null) m_knownColors = new Dictionary(); + if (m_knownColors == null) + m_knownColors = new Dictionary(StringComparer.OrdinalIgnoreCase); if (m_knownColors.Count == 0) { PropertyInfo[] propinfos = typeof(Colors).GetProperties(BindingFlags.Public | BindingFlags.Static); diff --git a/Source/SVGImage/SVG/SVGRender.cs b/Source/SVGImage/SVG/SVGRender.cs index 7ac432a..814d360 100644 --- a/Source/SVGImage/SVG/SVGRender.cs +++ b/Source/SVGImage/SVG/SVGRender.cs @@ -203,52 +203,13 @@ private GeometryDrawing NewDrawingItem(Shape shape, Geometry geometry) g.Children.Add(geometry); geometry = g; } - //if (shape.Transform != null) geometry.Transform = shape.Transform; - - // for debugging, if neither stroke or fill is set then set default pen - //if (shape.Fill == null && shape.Stroke == null) - // item.Pen = new Pen(Brushes.Blue, 1); item.Geometry = geometry; return item; } - - - private class ControlLine - { - public Point Ctrl { get; private set; } - - public Point Start { get; private set; } - - public ControlLine(Point start, Point ctrl) - { - this.Start = start; - this.Ctrl = ctrl; - } - - public GeometryDrawing Draw() - { - double size = 0.2; - GeometryDrawing item = new GeometryDrawing(); - item.Brush = Brushes.Red; - GeometryGroup g = new GeometryGroup(); - - item.Pen = new Pen(Brushes.LightGray, size / 2); - g.Children.Add(new LineGeometry(this.Start, this.Ctrl)); - - var rect = new Rect(this.Start.X - size / 2, this.Start.Y - size / 2, size, size); - g.Children.Add(new RectangleGeometry(rect)); - g.Children.Add(new EllipseGeometry(this.Ctrl, size, size)); - - item.Geometry = g; - return item; - } - } - internal DrawingGroup LoadGroup(IList elements, Rect? viewBox, bool isSwitch) { - List debugPoints = new List(); DrawingGroup grp = new DrawingGroup(); if (viewBox.HasValue) grp.ClipGeometry = new RectangleGeometry(viewBox.Value); @@ -345,14 +306,14 @@ internal DrawingGroup LoadGroup(IList elements, Rect? viewBox, bool isSwi continue; } - if (shape is UseShape) + if (shape is UseShape useshape) { - UseShape useshape = shape as UseShape; Shape currentUsedShape = this.SVG.GetShape(useshape.hRef); if (currentUsedShape != null) { - currentUsedShape.RealParent = useshape; Shape oldparent = currentUsedShape.Parent; + //currentUsedShape.RealParent = useshape; + currentUsedShape.Parent = useshape; DrawingGroup subgroup; if (currentUsedShape is Group) subgroup = this.LoadGroup(((Group)currentUsedShape).Elements, null, false); @@ -370,9 +331,9 @@ internal DrawingGroup LoadGroup(IList elements, Rect? viewBox, bool isSwi } continue; } - if (shape is Clip) + if (shape is Clip clip) { - var subgroup = this.LoadGroup((shape as Clip).Elements, null, false); + var subgroup = this.LoadGroup(clip.Elements, null, false); if (shape.Transform != null) subgroup.Transform = shape.Transform; grp.Children.Add(subgroup); @@ -384,15 +345,14 @@ internal DrawingGroup LoadGroup(IList elements, Rect? viewBox, bool isSwi AddDrawingToGroup(grp, shape, subgroup); continue; } - if (shape is RectangleShape) + if (shape is RectangleShape rectShape) { - RectangleShape r = shape as RectangleShape; - double dx = r.X; - double dy = r.Y; - double width = r.Width; - double height = r.Height; - double rx = r.RX; - double ry = r.RY; + double dx = rectShape.X; + double dy = rectShape.Y; + double width = rectShape.Width; + double height = rectShape.Height; + double rx = rectShape.RX; + double ry = rectShape.RY; if (width <= 0 || height <= 0) { continue; @@ -411,72 +371,66 @@ internal DrawingGroup LoadGroup(IList elements, Rect? viewBox, bool isSwi AddDrawingToGroup(grp, shape, di); continue; } - if (shape is LineShape) + if (shape is LineShape lineShape) { - LineShape r = shape as LineShape; - LineGeometry line = new LineGeometry(r.P1, r.P2); + LineGeometry line = new LineGeometry(lineShape.P1, lineShape.P2); var di = this.NewDrawingItem(shape, line); AddDrawingToGroup(grp, shape, di); continue; } - if (shape is PolylineShape) + if (shape is PolylineShape polyline) { - PolylineShape r = shape as PolylineShape; PathGeometry path = new PathGeometry(); PathFigure p = new PathFigure(); path.Figures.Add(p); p.IsClosed = false; - p.StartPoint = r.Points[0]; - for (int index = 1; index < r.Points.Length; index++) + p.StartPoint = polyline.Points[0]; + for (int index = 1; index < polyline.Points.Length; index++) { - p.Segments.Add(new LineSegment(r.Points[index], true)); + p.Segments.Add(new LineSegment(polyline.Points[index], true)); } var di = this.NewDrawingItem(shape, path); AddDrawingToGroup(grp, shape, di); continue; } - if (shape is PolygonShape) + if (shape is PolygonShape polygon) { - PolygonShape r = shape as PolygonShape; PathGeometry path = new PathGeometry(); PathFigure p = new PathFigure(); path.Figures.Add(p); p.IsClosed = true; - p.StartPoint = r.Points[0]; - for (int index = 1; index < r.Points.Length; index++) + p.StartPoint = polygon.Points[0]; + for (int index = 1; index < polygon.Points.Length; index++) { - p.Segments.Add(new LineSegment(r.Points[index], true)); + p.Segments.Add(new LineSegment(polygon.Points[index], true)); } var di = this.NewDrawingItem(shape, path); AddDrawingToGroup(grp, shape, di); continue; } - if (shape is CircleShape) + if (shape is CircleShape circle) { - CircleShape r = shape as CircleShape; - EllipseGeometry c = new EllipseGeometry(new Point(r.CX, r.CY), r.R, r.R); + EllipseGeometry c = new EllipseGeometry(new Point(circle.CX, circle.CY), circle.R, circle.R); var di = this.NewDrawingItem(shape, c); AddDrawingToGroup(grp, shape, di); continue; } - if (shape is EllipseShape) + if (shape is EllipseShape ellipse) { - EllipseShape r = shape as EllipseShape; - EllipseGeometry c = new EllipseGeometry(new Point(r.CX, r.CY), r.RX, r.RY); + EllipseGeometry c = new EllipseGeometry(new Point(ellipse.CX, ellipse.CY), ellipse.RX, ellipse.RY); var di = this.NewDrawingItem(shape, c); AddDrawingToGroup(grp, shape, di); continue; } - if (shape is ImageShape) + if (shape is ImageShape image) { - ImageShape image = shape as ImageShape; var i = new ImageDrawing(image.ImageSource, new Rect(image.X, image.Y, image.Width, image.Height)); AddDrawingToGroup(grp, shape, i); continue; } - if (shape is TextShape) + if (shape is TextShape textShape) { - GeometryGroup gp = TextRender.BuildTextGeometry(shape as TextShape); + GeometryGroup gp = TextRender.BuildTextGeometry(textShape); if (gp != null) { foreach (Geometry gm in gp.Children) @@ -496,33 +450,24 @@ internal DrawingGroup LoadGroup(IList elements, Rect? viewBox, bool isSwi } continue; } - if (shape is PathShape) + if (shape is PathShape pathShape) { - PathShape r = shape as PathShape; var svg = this.SVG; - if (r.Fill == null || r.Fill.IsEmpty(svg)) + if (pathShape.Fill == null || pathShape.Fill.IsEmpty(svg)) { - if (r.Stroke == null || r.Stroke.IsEmpty(svg)) + if (pathShape.Stroke == null || pathShape.Stroke.IsEmpty(svg)) { var fill = new Fill(svg); fill.PaintServerKey = this.SVG.PaintServers.Parse("black"); - r.Fill = fill; + pathShape.Fill = fill; } } - PathGeometry path = PathGeometry.CreateFromGeometry(PathGeometry.Parse(r.Data)); + var path = PathGeometry.CreateFromGeometry(PathGeometry.Parse(pathShape.Data)); var di = this.NewDrawingItem(shape, path); AddDrawingToGroup(grp, shape, di); } } - - if (debugPoints != null) - { - foreach (ControlLine line in debugPoints) - { - grp.Children.Add(line.Draw()); - } - } return grp; } diff --git a/Source/SVGImage/SVG/Shapes/CircleShape.cs b/Source/SVGImage/SVG/Shapes/CircleShape.cs index 7149bd5..91ba9c4 100644 --- a/Source/SVGImage/SVG/Shapes/CircleShape.cs +++ b/Source/SVGImage/SVG/Shapes/CircleShape.cs @@ -8,8 +8,15 @@ namespace SVGImage.SVG.Shapes public sealed class CircleShape : Shape { + private static Fill DefaultFill = null; + public CircleShape(SVG svg, XmlNode node) : base(svg, node) { + if (DefaultFill == null) + { + DefaultFill = Fill.CreateDefault(svg, "black"); + } + Rect? box = svg.ViewBox; this.CX = XmlUtil.AttrValue(node, "cx", 0, box.HasValue ? box.Value.Width : svg.Size.Width); @@ -21,6 +28,15 @@ public CircleShape(SVG svg, XmlNode node) : base(svg, node) this.R = XmlUtil.AttrValue(node, "r", 0, diagRef); } + public override Fill Fill + { + get { + Fill f = base.Fill; + if (f == null) f = DefaultFill; + return f; + } + } + public double CX { get; set; } public double CY { get; set; } diff --git a/Source/SVGImage/SVG/Shapes/EllipseShape.cs b/Source/SVGImage/SVG/Shapes/EllipseShape.cs index bd24f37..b72a992 100644 --- a/Source/SVGImage/SVG/Shapes/EllipseShape.cs +++ b/Source/SVGImage/SVG/Shapes/EllipseShape.cs @@ -8,9 +8,16 @@ namespace SVGImage.SVG.Shapes public sealed class EllipseShape : Shape { + private static Fill DefaultFill = null; + public EllipseShape(SVG svg, XmlNode node) : base(svg, node) { + if (DefaultFill == null) + { + DefaultFill = Fill.CreateDefault(svg, "black"); + } + Rect? box = svg.ViewBox; this.CX = XmlUtil.AttrValue(node, "cx", 0, box.HasValue ? box.Value.Width : svg.Size.Width); @@ -23,6 +30,15 @@ public EllipseShape(SVG svg, XmlNode node) this.RY = XmlUtil.AttrValue(node, "ry", 0, diagRef); } + public override Fill Fill + { + get { + Fill f = base.Fill; + if (f == null) f = DefaultFill; + return f; + } + } + public double CX { get; set; } public double CY { get; set; } diff --git a/Source/SVGImage/SVG/Shapes/PathShape.cs b/Source/SVGImage/SVG/Shapes/PathShape.cs index e2a50cf..33ca7c6 100644 --- a/Source/SVGImage/SVG/Shapes/PathShape.cs +++ b/Source/SVGImage/SVG/Shapes/PathShape.cs @@ -14,8 +14,7 @@ public PathShape(SVG svg, XmlNode node, Shape parent) : base(svg, node, parent) { if (DefaultFill == null) { - DefaultFill = new Fill(svg); - DefaultFill.PaintServerKey = svg.PaintServers.Parse("black"); + DefaultFill = Fill.CreateDefault(svg, "black"); } this.ClosePath = false; diff --git a/Source/SVGImage/SVG/Shapes/PolygonShape.cs b/Source/SVGImage/SVG/Shapes/PolygonShape.cs index ae0deee..0e82bb5 100644 --- a/Source/SVGImage/SVG/Shapes/PolygonShape.cs +++ b/Source/SVGImage/SVG/Shapes/PolygonShape.cs @@ -15,8 +15,7 @@ public PolygonShape(SVG svg, XmlNode node) { if (DefaultFill == null) { - DefaultFill = new Fill(svg); - DefaultFill.PaintServerKey = svg.PaintServers.Parse("black"); + DefaultFill = Fill.CreateDefault(svg, "black"); } string points = XmlUtil.AttrValue(node, SVGTags.sPoints, string.Empty); diff --git a/Source/SVGImage/SVG/Shapes/RectangleShape.cs b/Source/SVGImage/SVG/Shapes/RectangleShape.cs index 118b2a6..2144443 100644 --- a/Source/SVGImage/SVG/Shapes/RectangleShape.cs +++ b/Source/SVGImage/SVG/Shapes/RectangleShape.cs @@ -12,8 +12,7 @@ public RectangleShape(SVG svg, XmlNode node) : base(svg, node) { if (DefaultFill == null) { - DefaultFill = new Fill(svg); - DefaultFill.PaintServerKey = svg.PaintServers.Parse("black"); + DefaultFill = Fill.CreateDefault(svg, "black"); } } diff --git a/Source/SVGImage/SVG/Shapes/Text.cs b/Source/SVGImage/SVG/Shapes/Text.cs index f31b3b4..1a3a7c8 100644 --- a/Source/SVGImage/SVG/Shapes/Text.cs +++ b/Source/SVGImage/SVG/Shapes/Text.cs @@ -9,12 +9,34 @@ namespace SVGImage.SVG public sealed class TextShape : Shape { + private static Fill DefaultFill = null; + private static Stroke DefaultStroke = null; + + public TextShape(SVG svg, XmlNode node, Shape parent) + : base(svg, node, parent) + { + this.X = XmlUtil.AttrValue(node, "x", 0); + this.Y = XmlUtil.AttrValue(node, "y", 0); + this.Text = node.InnerText; + this.GetTextStyle(svg); + // check for tSpan tag + if (node.InnerXml.IndexOf("<") >= 0) + this.TextSpan = this.ParseTSpan(svg, node.InnerXml); + if (DefaultFill == null) + { + DefaultFill = Fill.CreateDefault(svg, "black"); + } + if (DefaultStroke == null) + { + DefaultStroke = Stroke.CreateDefault(svg, 0.1); + } + } + public double X { get; set; } public double Y { get; set; } public string Text { get; set; } public TextSpan TextSpan {get; private set;} - static Fill DefaultFill = null; - static Stroke DefaultStroke = null; + public override Fill Fill { get @@ -25,6 +47,7 @@ public override Fill Fill return f; } } + public override Stroke Stroke { get @@ -35,27 +58,6 @@ public override Stroke Stroke return f; } } - public TextShape(SVG svg, XmlNode node, Shape parent) - : base(svg, node, parent) - { - this.X = XmlUtil.AttrValue(node, "x", 0); - this.Y = XmlUtil.AttrValue(node, "y", 0); - this.Text = node.InnerText; - this.GetTextStyle(svg); - // check for tSpan tag - if (node.InnerXml.IndexOf("<") >= 0) - this.TextSpan = this.ParseTSpan(svg, node.InnerXml); - if (DefaultFill == null) - { - DefaultFill = new Fill(svg); - DefaultFill.PaintServerKey = svg.PaintServers.Parse("black"); - } - if (DefaultStroke == null) - { - DefaultStroke = new Stroke(svg); - DefaultStroke.Width = 0.1; - } - } TextSpan ParseTSpan(SVG svg, string tspanText) { diff --git a/Source/SVGImage/SVG/Stroke.cs b/Source/SVGImage/SVG/Stroke.cs index 614d3a3..ec7e282 100644 --- a/Source/SVGImage/SVG/Stroke.cs +++ b/Source/SVGImage/SVG/Stroke.cs @@ -1,4 +1,5 @@ -using System.Windows; +using System.Diagnostics; +using System.Windows; using System.Windows.Media; namespace SVGImage.SVG @@ -22,24 +23,102 @@ public enum eLineJoin bevel, } - public string PaintServerKey { get; set; } + private SVG _svg; - public double Width { get; set; } + private bool _isDefault; - public double Opacity { get; set; } + private string _paintServerKey; - public eLineCap LineCap { get; set; } + private double _opacity; - public eLineJoin LineJoin { get; set; } + private double _width; - public double[] StrokeArray { get; set; } + private eLineCap _lineCap; + + private eLineJoin _lineJoin; + + private double[] _strokeArray; public Stroke(SVG svg) { - this.Width = 1; - this.LineCap = eLineCap.butt; - this.LineJoin = eLineJoin.miter; - this.Opacity = 100; + _svg = svg; + _isDefault = false; + _width = 1; + _lineCap = eLineCap.butt; + _lineJoin = eLineJoin.miter; + _opacity = 100; + } + + public static Stroke CreateDefault(SVG svg, double width) + { + var stroke = new Stroke(svg); + stroke._width = width; + + stroke._isDefault = true; + + return stroke; + } + + public SVG get => _svg; + + public bool IsDefault + { + get => _isDefault; + set => _isDefault = value; + } + + public string PaintServerKey + { + get => _paintServerKey; + set { + Debug.Assert(_isDefault == false); + _paintServerKey = value; + } + } + + public double Opacity + { + get => _opacity; + set { + Debug.Assert(_isDefault == false); + _opacity = value; + } + } + + public double Width + { + get => _width; + set { + Debug.Assert(_isDefault == false); + _width = value; + } + } + + public eLineCap LineCap + { + get => _lineCap; + set { + Debug.Assert(_isDefault == false); + _lineCap = value; + } + } + + public eLineJoin LineJoin + { + get => _lineJoin; + set { + Debug.Assert(_isDefault == false); + _lineJoin = value; + } + } + + public double[] StrokeArray + { + get => _strokeArray; + set { + Debug.Assert(_isDefault == false); + _strokeArray = value; + } } public bool IsEmpty(SVG svg) diff --git a/Tests/SvgTestBox/Properties/AssemblyInfo.cs b/Tests/SvgTestBox/Properties/AssemblyInfo.cs index bd472ce..4beb06e 100644 --- a/Tests/SvgTestBox/Properties/AssemblyInfo.cs +++ b/Tests/SvgTestBox/Properties/AssemblyInfo.cs @@ -4,6 +4,10 @@ using System.Runtime.InteropServices; using System.Windows; +#if NETNEXT +[assembly: System.Runtime.Versioning.SupportedOSPlatform("windows7.0")] +#endif + // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. diff --git a/Tests/SvgTestSuites/Properties/AssemblyInfo.cs b/Tests/SvgTestSuites/Properties/AssemblyInfo.cs index b08e8f8..3a04436 100644 --- a/Tests/SvgTestSuites/Properties/AssemblyInfo.cs +++ b/Tests/SvgTestSuites/Properties/AssemblyInfo.cs @@ -4,6 +4,10 @@ using System.Runtime.InteropServices; using System.Windows; +#if NETNEXT +[assembly: System.Runtime.Versioning.SupportedOSPlatform("windows7.0")] +#endif + // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly.