forked from AntdUI/AntdUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cs
More file actions
105 lines (98 loc) · 3.83 KB
/
Main.cs
File metadata and controls
105 lines (98 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// COPYRIGHT (C) Tom. ALL RIGHTS RESERVED.
// THE AntdUI PROJECT IS AN WINFORM LIBRARY LICENSED UNDER THE Apache-2.0 License.
// LICENSED UNDER THE Apache License, VERSION 2.0 (THE "License")
// YOU MAY NOT USE THIS FILE EXCEPT IN COMPLIANCE WITH THE License.
// YOU MAY OBTAIN A COPY OF THE LICENSE AT
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, SOFTWARE
// DISTRIBUTED UNDER THE LICENSE IS DISTRIBUTED ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
// SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING PERMISSIONS AND
// LIMITATIONS UNDER THE License.
// GITEE: https://gitee.com/antdui/AntdUI
// GITHUB: https://github.com/AntdUI/AntdUI
// CSDN: https://blog.csdn.net/v_132
// QQ: 17379620
namespace SVGView
{
public partial class Main : AntdUI.Window
{
public Main()
{
InitializeComponent();
}
private void button1_Click(object sender, MouseEventArgs e)
{
var svg = input1.Text;
if (string.IsNullOrEmpty(svg)) return;
input1.Text = Hand(svg.Trim(), e.Button == MouseButtons.Right);
}
void ReId(ref string svg, params string[] ids)
{
foreach (string id in ids) ReId(ref svg, id);
}
void ReId(ref string svg, string id)
{
if (svg.Contains(" " + id + "=\"") || svg.Contains("<" + id + "=\""))
{
int i = svg.IndexOf(id + "=\"");
while (i != -1)
{
string first = svg.Substring(0, i), last = svg.Substring(i + id.Length + 3);
last = last.Substring(last.IndexOf("\"") + 1).Trim();
svg = first + last;
i = svg.IndexOf(id + "=\"");
}
}
}
void ReNodeOne(ref string svg, string id)
{
int i = svg.IndexOf("<" + id + ">");
if (i > -1)
{
string first = svg.Substring(0, i), last = svg.Substring(i + id.Length + 2);
last = last.Substring(last.IndexOf("</") + id.Length + 3).Trim();
svg = first + last;
}
}
private void input1_TextChanged(object sender, EventArgs e)
{
try
{
var svg = input1.Text;
if (svg == null) return;
button1.ImageSvg = svg;
int size = (int)Math.Floor((pictureBox1.Width > pictureBox1.Height ? pictureBox1.Height : pictureBox1.Width) * 0.8F);
pictureBox1.Image = AntdUI.SvgExtend.SvgToBmp(svg, size, size, Color.Black);
}
catch { }
}
private void button2_Click(object sender, MouseEventArgs e)
{
try
{
var svg = Clipboard.GetText();
if (string.IsNullOrEmpty(svg)) return;
input1.Text = Hand(svg.Trim(), e.Button == MouseButtons.Right);
Clipboard.SetText(input1.Text);
}
catch { }
}
string Hand(string svg, bool more = false)
{
if (svg.StartsWith("<?xml")) svg = svg.Substring(svg.IndexOf(">") + 1).Trim();
int i = svg.IndexOf(">") + 1;
string first = svg.Substring(0, i), last = svg.Substring(i);
ReId(ref first, "class", "version", "xmlns", "width", "height", "t");
ReNodeOne(ref last, "title");
svg = first + last;
if (more) ReId(ref svg, "fill");
ReId(ref svg, "p-id");
string _tmp = svg.Replace(" >", ">").Replace("\t", "").Replace("\r", "").Replace("\n", "");
while (_tmp.Contains(" ")) _tmp = _tmp.Replace(" ", " ");
return _tmp.Replace("> <", "><").Trim();
}
}
}