forked from DebugST/STTextBox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSvgAttributes.cs
More file actions
120 lines (109 loc) · 4.04 KB
/
SvgAttributes.cs
File metadata and controls
120 lines (109 loc) · 4.04 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Collections;
using System.Drawing.Drawing2D;
namespace ST.Library.Drawing.SvgRender
{
public partial class SvgAttributes : IEnumerable
{
private Dictionary<string, string> m_dic_attr_has_set = new Dictionary<string, string>();
private Dictionary<string, string> m_dic_attr_default = new Dictionary<string, string>();
public string this[string strKey] {
get {
if (m_dic_attr_has_set.ContainsKey(strKey)) {
return m_dic_attr_has_set[strKey];
}
return null;
}
}
public bool Set(string strKey, string strValue) {
if (m_dic_attr_has_set.ContainsKey(strKey)) {
if (string.IsNullOrEmpty(strValue)) {
m_dic_attr_has_set.Remove(strValue);
} else {
if (m_dic_value_check.ContainsKey(strKey)) {
if (!m_dic_value_check[strKey](strValue)) {
return false;
}
}
m_dic_attr_has_set[strKey] = strValue;
}
} else {
if (m_dic_value_check.ContainsKey(strKey)) {
if (!m_dic_value_check[strKey](strValue)) {
return false;
}
}
m_dic_attr_has_set.Add(strKey, strValue);
}
return true;
}
public bool SetDefault(string strKey, string strValue) {
if (m_dic_attr_default.ContainsKey(strKey)) {
if (string.IsNullOrEmpty(strValue)) {
m_dic_attr_default.Remove(strValue);
} else {
if (m_dic_value_check.ContainsKey(strKey)) {
if (!m_dic_value_check[strKey](strValue)) {
return false;
}
}
m_dic_attr_default[strKey] = strValue;
}
} else {
if (m_dic_value_check.ContainsKey(strKey)) {
if (!m_dic_value_check[strKey](strValue)) {
return false;
}
}
m_dic_attr_default.Add(strKey, strValue);
}
return true;
}
public string Get(string strKey) {
string str = this[strKey];
if (str != null) {
return str;
}
return this.GetDefault(strKey);
}
public string GetDefault(string strKey) {
if (m_dic_attr_default.ContainsKey(strKey)) {
return m_dic_attr_default[strKey];
}
return SvgAttributes.GetStaticDefault(strKey);
}
public static bool SetCheckCallBack(string strName, SvgAttributeValueCheckCallBack cb) {
return SvgAttributes.AddCheckCallBack(strName, cb, true);
}
public static bool AddCheckCallBack(string strName, SvgAttributeValueCheckCallBack cb, bool isOverrid) {
if (!m_dic_value_check.ContainsKey(strName)) {
m_dic_value_check.Add(strName, cb);
return true;
}
if (isOverrid) {
m_dic_value_check[strName] = cb;
return true;
}
return false;
}
public string[] GetHasSetKeys() {
return m_dic_attr_has_set.Keys.ToArray();
}
// [interface] ========================================================
public IEnumerator<KeyValuePair<string, string>> GetEnumerator() {
foreach (var v in m_dic_attr_has_set) {
yield return v;
}
//foreach (var v in m_dic_attr_inherit) {
// yield return v;
//}
}
IEnumerator IEnumerable.GetEnumerator() {
return this.GetEnumerator();
}
}
}