Skip to content

Commit 45813e2

Browse files
committed
Fixes most Example svg renders
1 parent 1cb69c7 commit 45813e2

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

Source/SVGImage/SVG/SVGRender.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Xml;
44
using System.Linq;
55
using System.Collections.Generic;
6+
using SVGImage.SVG.Utils;
67

78
using System.Windows;
89
using System.Windows.Media;

Source/SVGImage/SVG/Shapes/Shape.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ public Stroke Stroke
125125
}
126126

127127
protected virtual Fill DefaultFill()
128+
{
129+
return null;
130+
}
131+
132+
protected virtual Fill GetParentFill()
128133
{
129134
var parent = this.Parent;
130135
while (parent != null)
@@ -141,7 +146,7 @@ protected virtual Fill DefaultFill()
141146

142147
public Fill Fill
143148
{
144-
get => m_fill ?? DefaultFill();
149+
get => m_fill ?? GetParentFill() ?? DefaultFill();
145150
set => m_fill = value;
146151
}
147152

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Windows.Media;
3+
using System.Windows.Markup;
4+
using System.IO;
5+
using System.Xml;
6+
7+
namespace SVGImage.SVG.Utils
8+
{
9+
internal static class DrawingGroupSerializer
10+
{
11+
public static string SerializeToXaml(DrawingGroup drawingGroup)
12+
{
13+
if (drawingGroup is null)
14+
{
15+
throw new ArgumentNullException(nameof(drawingGroup));
16+
}
17+
18+
// Freezing can help ensure serialization works without exceptions
19+
if (drawingGroup.CanFreeze && !drawingGroup.IsFrozen)
20+
{
21+
drawingGroup.Freeze();
22+
}
23+
24+
var settings = new XmlWriterSettings
25+
{
26+
Indent = true,
27+
IndentChars = " ",
28+
OmitXmlDeclaration = true
29+
};
30+
31+
using (var stringWriter = new StringWriter())
32+
using (var xmlWriter = XmlWriter.Create(stringWriter, settings))
33+
{
34+
XamlWriter.Save(drawingGroup, xmlWriter);
35+
return stringWriter.ToString();
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)