2 using System.Collections.Generic;
\r
4 using System.Windows.Media;
\r
6 namespace NT2chCtrl.html
\r
14 HtmlColor(string colorName, int colorValue)
\r
16 mColorName = colorName;
\r
17 mColorValue = colorValue;
\r
20 public static Color getColor(string colorText)
\r
22 colorText = colorText.Trim();
\r
25 idx = colorText.IndexOf("rgb(");
\r
29 return getColorFromRgbString(colorText, 4, out endIdx);
\r
31 idx = colorText.IndexOf('#');
\r
34 return getColorFromHexString(colorText, 1);
\r
36 foreach (HtmlColor c in mColorList)
\r
38 if (colorText.Equals(c.mColorName, StringComparison.OrdinalIgnoreCase))
\r
39 return getColor(c.mColorValue);
\r
41 return Colors.Transparent;
\r
45 private static Color getColorFromRgbString(string rgbString, int startIdx, out int endIdx)
\r
48 int length = rgbString.Length;
\r
52 int r = 0, g = 0;//, b = 0;
\r
56 for (int i = startIdx; i < length; i++)
\r
58 char c = rgbString[i];
\r
59 if (c >= '0' && c <= '9')
\r
63 else if (digits == 1)
\r
64 value = (c - '0') + (value * 10);
\r
65 else if (digits == 2)
\r
66 value = (c - '0') + (value * 10);
\r
68 return Colors.Transparent;
\r
74 return Colors.Transparent;
\r
78 else if (colorIdx == 1)
\r
80 //else if (colorIdx == 2)
\r
83 return Colors.Transparent;
\r
87 else if (c == ' ' || c == '\t' || c == 'r' || c == '\n')
\r
93 return Colors.Transparent;
\r
95 return Color.FromRgb((byte)r, (byte)g, (byte)value);
\r
99 return Colors.Transparent;
\r
102 return Colors.Transparent;
\r
105 private static Color getColorFromHexString(string hexString, int startIdx)
\r
107 int[] by = new int[8];
\r
108 int length = Math.Min(hexString.Length, 8);
\r
110 for (int i = startIdx; i < length; i++)
\r
112 char c = hexString[i];
\r
113 if (c >= '0' && c <= '9')
\r
115 by[idx] = (c - '0');
\r
116 }else if(c >= 'a' && c <= 'f'){
\r
117 by[idx] = (c - 'a' + 10);
\r
119 else if (c >= 'A' && c <= 'F')
\r
121 by[idx] = (c - 'A' + 10);
\r
130 if (idx < 0 || idx > 6)
\r
131 return Colors.Transparent;
\r
133 int r = 0, g = 0, b = 0;
\r
137 for (int i = 0; idx >= 0; i++)
\r
157 for (int i = 0; idx >= 0; i++)
\r
165 b += (by[idx] << 4);
\r
171 g += (by[idx] << 4);
\r
177 r += (by[idx] << 4);
\r
185 return Color.FromRgb((byte)r, (byte)g, (byte)b);
\r
189 private static Color getColor(int value)
\r
191 int r = (value & 0xff0000) >> 16;
\r
192 int g = (value & 0xff00) >> 8;
\r
193 int b = (value & 0xff);
\r
194 return Color.FromRgb((byte)r, (byte)g, (byte)b);
\r
197 static HtmlColor [] mColorList =
\r
199 new HtmlColor("aliceblue", 0xF0F8FF), // 240,248,255
\r
200 new HtmlColor("antiquewhite", 0xFAEBD7), //250,235,215
\r
201 new HtmlColor("aqua", 0x00FFFF), //0,255,255
\r
202 new HtmlColor("aquamarine", 0x7FFFD4), //127,255,212
\r
203 new HtmlColor("azure", 0xF0FFFF), //240,255,255
\r
204 new HtmlColor("beige", 0xF5F5DC), //245,245,220
\r
205 new HtmlColor("bisque", 0xFFE4C4), //255,228,196
\r
206 new HtmlColor("black", 0x000000), //0,0,0
\r
207 new HtmlColor("blanchedalmond", 0xFFEBCD), //255,235,205
\r
208 new HtmlColor("blue", 0x0000FF), //0,0,255
\r
209 new HtmlColor("blueviolet", 0x8A2BE2), //138,43,226
\r
210 new HtmlColor("brown", 0xA52A2A), //165,42,42
\r
211 new HtmlColor("burlywood", 0xDEB887), //222,184,135
\r
212 new HtmlColor("cadetblue", 0x5F9EA0), //95,158,160
\r
213 new HtmlColor("chartreuse", 0x7FFF00), //127,255,0
\r
214 new HtmlColor("chocolate", 0xD2691E), //210,105,30
\r
215 new HtmlColor("coral", 0xFF7F50), //255,127,80
\r
216 new HtmlColor("cornflowerblue", 0x6495ED), //100,149,237
\r
217 new HtmlColor("cornsilk", 0xFFF8DC), //255,248,220
\r
218 new HtmlColor("crimson", 0xDC143C), //220,20,60
\r
219 new HtmlColor("cyan", 0x00FFFF), //0,255,255
\r
220 new HtmlColor("darkblue", 0x00008B), //0,0,139
\r
221 new HtmlColor("darkcyan", 0x008B8B), //0,139,139
\r
222 new HtmlColor("darkgoldenrod", 0xB8860B), //184,134,11
\r
223 new HtmlColor("darkgray", 0xA9A9A9), //169,169,169
\r
224 new HtmlColor("darkgreen", 0x006400), //0,100,0
\r
225 new HtmlColor("darkgrey", 0xA9A9A9), //169,169,169
\r
226 new HtmlColor("darkkhaki", 0xBDB76B), //189,183,107
\r
227 new HtmlColor("darkmagenta", 0x8B008B), //139,0,139
\r
228 new HtmlColor("darkolivegreen", 0x556B2F), //85,107,47
\r
229 new HtmlColor("darkorange", 0xFF8C00), //255,140,0
\r
230 new HtmlColor("darkorchid", 0x9932CC), //153,50,204
\r
231 new HtmlColor("darkred", 0x8B0000), //139,0,0
\r
232 new HtmlColor("darksalmon", 0xE9967A), //233,150,122
\r
233 new HtmlColor("darkseagreen", 0x8FBC8F), //143,188,143
\r
234 new HtmlColor("darkslateblue", 0x483D8B), //72,61,139
\r
235 new HtmlColor("darkslategray", 0x2F4F4F), //47,79,79
\r
236 new HtmlColor("darkslategrey", 0x2F4F4F), //47,79,79
\r
237 new HtmlColor("darkturquoise", 0x00CED1), //0,206,209
\r
238 new HtmlColor("darkviolet", 0x9400D3), //148,0,211
\r
239 new HtmlColor("deeppink", 0xFF1493), //255,20,147
\r
240 new HtmlColor("deepskyblue", 0x00BFFF), //0,191,255
\r
241 new HtmlColor("dimgray", 0x696969), //105,105,105
\r
242 new HtmlColor("dimgrey", 0x696969), //105,105,105
\r
243 new HtmlColor("dodgerblue", 0x1E90FF), //30,144,255
\r
244 new HtmlColor("firebrick", 0xB22222), //178,34,34
\r
245 new HtmlColor("floralwhite", 0xFFFAF0), //255,250,240
\r
246 new HtmlColor("forestgreen", 0x228B22), //34,139,34
\r
247 new HtmlColor("fuchsia", 0xFF00FF), //255,0,255
\r
248 new HtmlColor("gainsboro", 0xDCDCDC), //220,220,220
\r
249 new HtmlColor("ghostwhite", 0xF8F8FF), //248,248,255
\r
250 new HtmlColor("gold", 0xFFD700), //255,215,0
\r
251 new HtmlColor("goldenrod", 0xDAA520), //218,165,32
\r
252 new HtmlColor("gray", 0x808080), //128,128,128
\r
253 new HtmlColor("green", 0x008000), //0,128,0
\r
254 new HtmlColor("greenyellow", 0xADFF2F), //173,255,47
\r
255 new HtmlColor("grey", 0x808080), //128,128,128
\r
256 new HtmlColor("honeydew", 0xF0FFF0), //240,255,240
\r
257 new HtmlColor("hotpink", 0xFF69B4), //255,105,180
\r
258 new HtmlColor("indianred", 0xCD5C5C), //205,92,92
\r
259 new HtmlColor("indigo", 0x4B0082), //75,0,130
\r
260 new HtmlColor("ivory", 0xFFFFF0), //255,255,240
\r
261 new HtmlColor("khaki", 0xF0E68C), //240,230,140
\r
262 new HtmlColor("lavender", 0xE6E6FA), //230,230,250
\r
263 new HtmlColor("lavenderblush", 0xFFF0F5), //255,240,245
\r
264 new HtmlColor("lawngreen", 0x7CFC00), //124,252,0
\r
265 new HtmlColor("lemonchiffon", 0xFFFACD), //255,250,205
\r
266 new HtmlColor("lightblue", 0xADD8E6), //173,216,230
\r
267 new HtmlColor("lightcoral", 0xF08080), //240,128,128
\r
268 new HtmlColor("lightcyan", 0xE0FFFF), //224,255,255
\r
269 new HtmlColor("lightgoldenrodyellow", 0xFAFAD2), //250,250,210
\r
270 new HtmlColor("lightgray", 0xD3D3D3), //211,211,211
\r
271 new HtmlColor("lightgreen", 0x90EE90), //144,238,144
\r
272 new HtmlColor("lightgrey", 0xD3D3D3), //211,211,211
\r
273 new HtmlColor("lightpink", 0xFFB6C1), //255,182,193
\r
274 new HtmlColor("lightsalmon", 0xFFA07A), //255,160,122
\r
275 new HtmlColor("lightseagreen", 0x20B2AA), //32,178,170
\r
276 new HtmlColor("lightskyblue", 0x87CEFA), //135,206,250
\r
277 new HtmlColor("lightslategray", 0x778899), //119,136,153
\r
278 new HtmlColor("lightslategrey", 0x778899), //119,136,153
\r
279 new HtmlColor("lightsteelblue", 0xB0C4DE), //176,196,222
\r
280 new HtmlColor("lightyellow", 0xFFFFE0), //255,255,224
\r
281 new HtmlColor("lime", 0x00FF00), //0,255,0
\r
282 new HtmlColor("limegreen", 0x32CD32), //50,205,50
\r
283 new HtmlColor("linen", 0xFAF0E6), //250,240,230
\r
284 new HtmlColor("magenta", 0xFF00FF), //255,0,255
\r
285 new HtmlColor("maroon", 0x800000), //128,0,0
\r
286 new HtmlColor("mediumaquamarine", 0x66CDAA), //102,205,170
\r
287 new HtmlColor("mediumblue", 0x0000CD), //0,0,205
\r
288 new HtmlColor("mediumorchid", 0xBA55D3), //186,85,211
\r
289 new HtmlColor("mediumpurple", 0x9370DB), //147,112,219
\r
290 new HtmlColor("mediumseagreen", 0x3CB371), //60,179,113
\r
291 new HtmlColor("mediumslateblue", 0x7B68EE), //123,104,238
\r
292 new HtmlColor("mediumspringgreen", 0x00FA9A), //0,250,154
\r
293 new HtmlColor("mediumturquoise", 0x48D1CC), //72,209,204
\r
294 new HtmlColor("mediumvioletred", 0xC71585), //199,21,133
\r
295 new HtmlColor("midnightblue", 0x191970), //25,25,112
\r
296 new HtmlColor("mintcream", 0xF5FFFA), //245,255,250
\r
297 new HtmlColor("mistyrose", 0xFFE4E1), //255,228,225
\r
298 new HtmlColor("moccasin", 0xFFE4B5), //255,228,181
\r
299 new HtmlColor("navajowhite", 0xFFDEAD), //255,222,173
\r
300 new HtmlColor("navy", 0x000080), //0,0,128
\r
301 new HtmlColor("oldlace", 0xFDF5E6), //253,245,230
\r
302 new HtmlColor("olive", 0x808000), //128,128,0
\r
303 new HtmlColor("olivedrab", 0x6B8E23), //107,142,35
\r
304 new HtmlColor("orange", 0xFFA500), //255,165,0
\r
305 new HtmlColor("orangered", 0xFF4500), //255,69,0
\r
306 new HtmlColor("orchid", 0xDA70D6), //218,112,214
\r
307 new HtmlColor("palegoldenrod", 0xEEE8AA), //238,232,170
\r
308 new HtmlColor("palegreen", 0x98FB98), //152,251,152
\r
309 new HtmlColor("paleturquoise", 0xAFEEEE), //175,238,238
\r
310 new HtmlColor("palevioletred", 0xDB7093), //219,112,147
\r
311 new HtmlColor("papayawhip", 0xFFEFD5), //255,239,213
\r
312 new HtmlColor("peachpuff", 0xFFDAB9), //255,218,185
\r
313 new HtmlColor("peru", 0xCD853F), //205,133,63
\r
314 new HtmlColor("pink", 0xFFC0CB), //255,192,203
\r
315 new HtmlColor("plum", 0xDDA0DD), //221,160,221
\r
316 new HtmlColor("powderblue", 0xB0E0E6), //176,224,230
\r
317 new HtmlColor("purple", 0x800080), //128,0,128
\r
318 new HtmlColor("red", 0xFF0000), //255,0,0
\r
319 new HtmlColor("rosybrown", 0xBC8F8F), //188,143,143
\r
320 new HtmlColor("royalblue", 0x4169E1), //65,105,225
\r
321 new HtmlColor("saddlebrown", 0x8B4513), //139,69,19
\r
322 new HtmlColor("salmon", 0xFA8072), //250,128,114
\r
323 new HtmlColor("sandybrown", 0xF4A460), //244,164,96
\r
324 new HtmlColor("seagreen", 0x2E8B57), //46,139,87
\r
325 new HtmlColor("seashell", 0xFFF5EE), //255,245,238
\r
326 new HtmlColor("sienna", 0xA0522D), //160,82,45
\r
327 new HtmlColor("silver", 0xC0C0C0), //192,192,192
\r
328 new HtmlColor("skyblue", 0x87CEEB), //135,206,235
\r
329 new HtmlColor("slateblue", 0x6A5ACD), //106,90,205
\r
330 new HtmlColor("slategray", 0x708090), //112,128,144
\r
331 new HtmlColor("slategrey", 0x708090), //112,128,144
\r
332 new HtmlColor("snow", 0xFFFAFA), //255,250,250
\r
333 new HtmlColor("springgreen", 0x00FF7F), //0,255,127
\r
334 new HtmlColor("steelblue", 0x4682B4), //70,130,180
\r
335 new HtmlColor("tan", 0xD2B48C), //210,180,140
\r
336 new HtmlColor("teal", 0x008080), //0,128,128
\r
337 new HtmlColor("thistle", 0xD8BFD8), //216,191,216
\r
338 new HtmlColor("tomato", 0xFF6347), //255,99,71
\r
339 new HtmlColor("turquoise", 0x40E0D0), //64,224,208
\r
340 new HtmlColor("violet", 0xEE82EE), //238,130,238
\r
341 new HtmlColor("wheat", 0xF5DEB3), //245,222,179
\r
342 new HtmlColor("white", 0xFFFFFF), //255,255,255
\r
343 new HtmlColor("whitesmoke", 0xF5F5F5), //245,245,245
\r
344 new HtmlColor("yellow", 0xFFFF00), //255,255,0
\r
345 new HtmlColor("yellowgreen", 0x9ACD32), //154,205,50
\r