Skip to content

Commit e59c836

Browse files
committed
v2.2.0 - Support for .NET 6 (requires .NET 6 SDK for build)
1 parent 421c448 commit e59c836

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+7743
-7741
lines changed

SvgNet/.editorconfig renamed to .editorconfig

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
[*]
2-
end_of_line = crlf
2+
end_of_line =lf
3+
indent_style=tab
4+
dotnet_style_predefined_type_for_locals_parameters_members=true:error
5+
dotnet_style_predefined_type_for_member_access=true:warning
6+
dotnet_diagnostic.CA1021.severity=silent
7+
dotnet_diagnostic.CA1310.severity=suggestion
8+
dotnet_style_allow_multiple_blank_lines_experimental=false:silent
39

410
[*.xml]
511
indent_style = space
@@ -12,7 +18,7 @@ dotnet_sort_system_directives_first=true
1218
csharp_new_line_before_else=false
1319
csharp_new_line_before_catch=false
1420
csharp_new_line_before_finally=false
15-
csharp_prefer_braces=false:silent
21+
csharp_prefer_braces=false:suggestion
1622
csharp_prefer_simple_default_expression=true:suggestion
1723
csharp_new_line_before_open_brace=none
1824
csharp_style_expression_bodied_accessors=true:silent
@@ -25,4 +31,7 @@ csharp_style_var_when_type_is_apparent=true:silent
2531
csharp_style_deconstructed_variable_declaration=true:suggestion
2632

2733
# IDE0056: Use index operator
28-
csharp_style_prefer_index_operator = true:none
34+
csharp_style_prefer_index_operator =false:suggestion
35+
csharp_style_namespace_declarations=block_scoped:warning
36+
csharp_style_prefer_pattern_matching=true:suggestion
37+
csharp_style_allow_blank_lines_between_consecutive_braces_experimental=false:silent

.github/workflows/dotnetcore.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v1
1212

13-
- name: Setup .NET 5.0
13+
- name: Setup .NET 6.0
1414
uses: actions/[email protected]
1515
with:
16-
dotnet-version: 5.0.202
16+
dotnet-version: 6.0.100
1717

1818
- name: Build and Test with dotnet
1919
run: NONET461=true dotnet test --configuration Release -v:m | grep -v 'NAME_UNKNOWN:Package'

SvgDocTest/Assert.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,16 @@
88

99
using System;
1010

11-
namespace SvgDocTest
12-
{
13-
public static class Assert
14-
{
15-
public static void Equals(float a, float b)
16-
{
17-
if (a != b)
18-
{
11+
namespace SvgDocTest {
12+
public static class Assert {
13+
public static void Equals(float a, float b) {
14+
if (a != b) {
1915
throw new Exception("Assert.Equals");
2016
}
2117
}
2218

23-
public static void Equals(bool a, bool b)
24-
{
25-
if (a != b)
26-
{
19+
public static void Equals(bool a, bool b) {
20+
if (a != b) {
2721
throw new Exception("Assert.Equals");
2822
}
2923
}

SvgDocTest/DocForm.Designer.cs

Lines changed: 149 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SvgDocTest/DocForm.cs

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
using System;
2+
using System.IO;
3+
using System.Windows.Forms;
4+
using SvgNet;
5+
using SvgNet.SvgElements;
6+
using SvgNet.SvgTypes;
7+
8+
namespace SvgDocTest {
9+
public partial class DocForm : Form {
10+
public DocForm() => InitializeComponent();
11+
12+
private static readonly string _tempFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "foo.svg");
13+
14+
15+
/// <summary>
16+
/// The main entry point for the application.
17+
/// </summary>
18+
[STAThread]
19+
private static void Main() => Application.Run(new DocForm());
20+
21+
private static void RefreshBrowserFrom(WebBrowser browser, string filename) {
22+
browser.Navigate(new Uri(filename));
23+
browser.Refresh(WebBrowserRefreshOption.Completely);
24+
}
25+
26+
private void Button1_Click(object sender, EventArgs e) {
27+
using (var dlg = new OpenFileDialog {
28+
AutoUpgradeEnabled = true,
29+
CheckFileExists = true,
30+
DefaultExt = ".svg",
31+
Filter = "Scalable Vector Graphics|*.svg",
32+
Multiselect = false,
33+
Title = "Choose one Scalable Vector Graphics file"
34+
}) {
35+
if (dlg.ShowDialog() == DialogResult.OK) {
36+
ProcessSvgFile(dlg.FileName);
37+
}
38+
}
39+
}
40+
41+
private void Button2_Click(object sender, EventArgs e) {
42+
var root = new SvgSvgElement("4in", "4in", "-10,-10 250,250");
43+
44+
//adding multiple children
45+
46+
root.AddChildren(
47+
new SvgRectElement(5, 5, 5, 5),
48+
new SvgEllipseElement(20, 20, 8, 12) {
49+
Style = "fill:yellow;stroke:red"
50+
},
51+
52+
new SvgAElement("https://github.com/managed-commons/SvgNet").AddChildren(
53+
new SvgTextElement("Textastic!", 30, 20) {
54+
Style = "fill:midnightblue;stroke:navy;stroke-width:1px;font-size:30px;font-family:Calibri"
55+
})
56+
);
57+
58+
//group and path
59+
60+
var grp = new SvgGroupElement("green_group") {
61+
Style = "fill:green;stroke:black;"
62+
};
63+
64+
grp.AddChild(new SvgRectElement(30, 30, 5, 20));
65+
66+
var ell = new SvgEllipseElement {
67+
CX = 50,
68+
CY = 50,
69+
RX = 10,
70+
RY = 20
71+
};
72+
73+
var pathy = new SvgPathElement {
74+
D = "M 20,80 C 20,90 30,80 70,100 C 70,100 40,60 50,60 z",
75+
Style = ell.Style
76+
};
77+
78+
root.AddChild(grp);
79+
80+
//cloning and style arithmetic
81+
82+
grp.AddChildren(ell, pathy);
83+
84+
grp.Style.Set("fill", "blue");
85+
86+
var grp2 = (SvgGroupElement)SvgFactory.CloneElement(grp);
87+
88+
grp2.Id = "cloned_red_group";
89+
90+
grp2.Style.Set("fill", "red");
91+
92+
grp2.Style += "opacity:0.5";
93+
94+
grp2.Transform = "scale (1.2, 1.2) translate(10)";
95+
96+
root.AddChild(grp2);
97+
98+
//output
99+
100+
string s = root.WriteSVGString(true);
101+
102+
tbOut.Text = s;
103+
104+
string tempFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "foo.svg");
105+
106+
using (var tw = new StreamWriter(tempFile, false))
107+
tw.Write(s);
108+
109+
svgOut.Navigate(new Uri(tempFile));
110+
svgOut.Refresh(WebBrowserRefreshOption.Completely);
111+
}
112+
113+
private void Button3_Click(object sender, EventArgs e) {
114+
SvgNumList a = "3, 5.6 901 -7 ";
115+
Assert.Equals(a[3], -7f);
116+
117+
SvgTransformList b = "rotate ( 45 ), translate (11, 10)skewX(3)";
118+
Assert.Equals(b[1].Matrix.OffsetX, 11f);
119+
120+
SvgColor c = "rgb( 100%, 100%, 50%)";
121+
Assert.Equals(c.Color.B, 0x7f);
122+
123+
SvgColor d = "#abc";
124+
Assert.Equals(d.Color.G, 0xbb);
125+
126+
SvgPath f = "M 5,5 L 1.1 -6 , Q 1,3 9,10 z";
127+
Assert.Equals(f.Count, 4f);
128+
Assert.Equals(f[1].Abs, true);
129+
Assert.Equals(f[2].Data[3], 10f);
130+
131+
MessageBox.Show("Tests completed Ok");
132+
}
133+
private void ProcessSvgFile(string svgFileName) {
134+
tbIn.Text = svgFileName.LoadText();
135+
RefreshBrowserFrom(svgIn, svgFileName);
136+
tbOut.Text = SvgFactory.LoadFromXML(svgFileName.LoadXml(), null).WriteSVGString(true);
137+
File.WriteAllText(_tempFileName, tbOut.Text);
138+
RefreshBrowserFrom(svgOut, _tempFileName);
139+
}
140+
141+
}
142+
}

0 commit comments

Comments
 (0)