-
Notifications
You must be signed in to change notification settings - Fork 0
/
PathFont.cs
232 lines (232 loc) · 6.66 KB
/
PathFont.cs
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
namespace Wholemy {
#region #class# PathFont
public abstract class PathFont {
public Chr GetChr(char Char) {
var P = Map.GetV(ref ChrMap, Char);
if (P == null) {
P = new UnknownChr(Char);
Map.Add(ref ChrMap, Char, P);
}
return P;
}
private Map.Int<Chr> ChrMap;
private Map.Chars<Chr> StrMap;
public System.Windows.Media.Geometry GetGeometry(string Value, double Height, double Weight, out double Width) {
var Count = Value.Length;
Width = 0.0;
var PathSource = new PathSource();
for (int Index = 0; Index < Count; Index++) {
var Char = Value[Index];
var Chr = GetChr(Char);
var Mul = Height / Chr.Height;
PathSource.AddResizeMovA(WH: Mul, X: Width);
PathSource.Begin();
PathSource.Parse(Chr.GetWeight(Weight));
PathSource.CutResize();
Width += (Chr.Width * Mul);
}
return PathSource.CombineToGeometry();
}
public System.Windows.Media.Geometry GetGeometry(string Value, double Height, double Weight) {
var Count = Value.Length;
var Width = 0.0;
var PathSource = new PathSource();
for (int Index = 0; Index < Count; Index++) {
var Char = Value[Index];
var Chr = GetChr(Char);
var Mul = Height / Chr.Height;
PathSource.AddResizeMovA(WH: Mul, X: Width);
PathSource.Begin();
PathSource.Parse(Chr.GetWeight(Weight));
PathSource.CutResize();
Width += (Chr.Width * Mul);
}
return PathSource.CombineToGeometry();
}
public void ToPath(PathSource P,double X,double Y, string Value, double Height, double Weight) {
var Count = Value.Length;
var Width = X;
var PathSource = P;
for (int Index = 0; Index < Count; Index++) {
var Char = Value[Index];
var Chr = GetChr(Char);
var Mul = Height / Chr.Height;
PathSource.AddResizeMovA(WH: Mul, X: Width, Y:Y);
PathSource.Begin();
PathSource.Parse(Chr.GetWeight(Weight));
PathSource.CutResize();
Width += (Chr.Width * Mul);
}
}
public double GetWidth(string Value, double Height) {
var Count = Value.Length;
var Width = 0.0;
for (int Index = 0; Index < Count; Index++) {
var Char = Value[Index];
var Chr = GetChr(Char);
var Mul = Height / Chr.Height;
Width += (Chr.Width * Mul);
}
return Width;
}
#region #new#
public PathFont() {
StrMap = new Map.Chars<Chr>();
var LastType = this.GetType();
while (LastType != null) {
var NestedTypes = LastType.GetNestedTypes(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);
foreach (var NestedType in NestedTypes) {
if (NestedType.IsClass && !NestedType.IsAbstract) {
if (NestedType.IsSubclassOf(typeof(Chr))) {
var Chr = (Chr)NestedType.GetConstructor(System.Type.EmptyTypes)?.Invoke(new object[0]);
if (Chr != null) {
var Str = Chr.Str;
if (Str != null) {
if (Str.Length == 1) {
var C = Chr.Str[0];
if (!Map.Add(ref ChrMap, C, Chr))
throw new System.InvalidOperationException();
} else if (Str.Length > 1) {
var S = Chr.Str;
if (!StrMap.Add(Chr, S))
throw new System.InvalidOperationException();
}
}
Chr.Font = this;
}
}
}
}
LastType = LastType.BaseType;
}
}
#endregion
#region #class# Chr
public abstract class Chr {
public PathFont Font;
public string Str;
public string Name;
public double Width;
public double Height;
private Map.Double<string> CacheMap;
public Chr(char Str) { this.Str = Str.ToString(); }
public Chr(string Str) { this.Str = Str; }
public Chr() { }
public string GetWeight(double Weight) {
var S = Map.GetV(ref CacheMap, Weight);
if (S == null) {
var L = Get(D: Weight / 4).Geometry;
if (L != null) {
S = Get(D: Weight / 4).Geometry.ToString();
} else { S = ""; }
Map.Add(ref CacheMap, Weight, S);
}
return S;
}
public abstract PathSource Get(double D = 0, PathSource Source = null);
public override string ToString() => this.Str;
}
#endregion
#region #class# UnknownChr
protected class UnknownChr : Chr {
public UnknownChr(char chr) : base(chr) { Width = 1000; Height = 1000; }
public override PathSource Get(double D = 0, PathSource Source = null) {
var S = Source ?? new PathSource();
if (D > 0) {
D /= 2;
S.Thickness = D;
S.BeginFz();
//S.AddRotate(45, 500, 500);
//S.AddResizeMovA(XY: 100);
S.AddArc00(50, 200, 200, 50);
S.BeginFz();
S.AddArc00(600, 50, 750, 200);
S.BeginFz();
S.AddArc00(750, 600, 600, 750);
S.BeginFz();
S.AddArc00(200, 750, 50, 600);
S.BeginFz();
S.AddLin00(200, 50, 600, 50);
S.BeginFz();
S.AddLin00(750, 200, 750, 600);
S.BeginFz();
S.AddLin00(600, 750, 200, 750);
S.BeginFz();
S.AddLin00(50, 600, 50, 200);
//S.Thickness = 150 - D;
var chr = (int)(ushort)this.Str[0];
if (((chr >> 15) & 1) == 1) {
S.BeginFz();
S.AddOrc(200, 200, 25);
}
if (((chr >> 14) & 1) == 1) {
S.BeginFz();
S.AddOrc(200 + (400.0 / 3 * 1), 200, 25);
}
if (((chr >> 13) & 1) == 1) {
S.BeginFz();
S.AddOrc(600 - (400.0 / 3 * 1), 200, 25);
}
if (((chr >> 12) & 1) == 1) {
S.BeginFz();
S.AddOrc(600, 200, 25);
}
if (((chr >> 11) & 1) == 1) {
S.BeginFz();
S.AddOrc(200, 200 + (400.0 / 3 * 1), 25);
}
if (((chr >> 10) & 1) == 1) {
S.BeginFz();
S.AddOrc(200 + (400.0 / 3 * 1), 200 + (400.0 / 3 * 1), 25);
}
if (((chr >> 9) & 1) == 1) {
S.BeginFz();
S.AddOrc(600 - (400.0 / 3 * 1), 200 + (400.0 / 3 * 1), 25);
}
if (((chr >> 8) & 1) == 1) {
S.BeginFz();
S.AddOrc(600, 200 + (400.0 / 3 * 1), 25);
}
if (((chr >> 7) & 1) == 1) {
S.BeginFz();
S.AddOrc(200, 600 - (400.0 / 3 * 1), 25);
}
if (((chr >> 6) & 1) == 1) {
S.BeginFz();
S.AddOrc(200 + (400.0 / 3 * 1), 600 - (400.0 / 3 * 1), 25);
}
if (((chr >> 5) & 1) == 1) {
S.BeginFz();
S.AddOrc(600 - (400.0 / 3 * 1), 600 - (400.0 / 3 * 1), 25);
}
if (((chr >> 4) & 1) == 1) {
S.BeginFz();
S.AddOrc(600, 600 - (400.0 / 3 * 1), 25);
}
if (((chr >> 3) & 1) == 1) {
S.BeginFz();
S.AddOrc(200, 600, 25);
}
if (((chr >> 4) & 1) == 1) {
S.BeginFz();
S.AddOrc(200 + (400.0 / 3 * 1), 600, 25);
}
if (((chr >> 1) & 1) == 1) {
S.BeginFz();
S.AddOrc(600 - (400.0 / 3 * 1), 600, 25);
}
if (((chr) & 1) == 1) {
S.BeginFz();
S.AddOrc(600, 600, 25);
}
//S.CutResize();
//S.CutRotate();
return S.Combine();
}
return S;
}
}
#endregion
}
#endregion
}