abe2a0e702139708260ca0628e0515b4cb66ae3d
[chise/xemacs-chise.git] / src / objects-msw.c
1 /* mswindows-specific Lisp objects.
2    Copyright (C) 1993, 1994 Free Software Foundation, Inc.
3    Copyright (C) 1995 Board of Trustees, University of Illinois.
4    Copyright (C) 1995 Tinker Systems.
5    Copyright (C) 1995, 1996 Ben Wing.
6    Copyright (C) 1995 Sun Microsystems, Inc.
7    Copyright (C) 1997 Jonathan Harris.
8
9 This file is part of XEmacs.
10
11 XEmacs is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2, or (at your option) any
14 later version.
15
16 XEmacs is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19 for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with XEmacs; see the file COPYING.  If not, write to
23 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA.  */
25
26 /* Synched up with: Not in FSF. */
27
28 /* Authorship:
29
30    Jamie Zawinski, Chuck Thompson, Ben Wing
31    Rewritten for mswindows by Jonathan Harris, November 1997 for 21.0.
32  */
33
34
35 /* TODO: palette handling */
36
37 #include <config.h>
38 #include "lisp.h"
39 #include "hash.h"
40
41 #include "console-msw.h"
42 #include "objects-msw.h"
43
44 #ifdef CHAR_IS_UCS4
45 #include "character.h"
46 #else
47 #ifdef MULE
48 #include "mule-charset.h"
49 #endif
50 #endif
51
52 #include "buffer.h"
53 #include "device.h"
54 #include "insdel.h"
55
56 #if defined(__CYGWIN32__) || defined(__MINGW32__)
57 #define stricmp strcasecmp
58 #define FONTENUMPROC FONTENUMEXPROC
59 #define ntmTm ntmentm
60 #endif
61
62 typedef struct colormap_t 
63 {
64   CONST char *name;
65   CONST COLORREF colorref;
66 } colormap_t;
67
68 /* Colors from X11R6 "XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp" */
69 static CONST colormap_t mswindows_X_color_map[] = 
70 {
71   {"snow"                       , PALETTERGB (255, 250, 250) },
72   {"GhostWhite"                 , PALETTERGB (248, 248, 255) },
73   {"WhiteSmoke"                 , PALETTERGB (245, 245, 245) },
74   {"gainsboro"                  , PALETTERGB (220, 220, 220) },
75   {"FloralWhite"                , PALETTERGB (255, 250, 240) },
76   {"OldLace"                    , PALETTERGB (253, 245, 230) },
77   {"linen"                      , PALETTERGB (250, 240, 230) },
78   {"AntiqueWhite"               , PALETTERGB (250, 235, 215) },
79   {"PapayaWhip"                 , PALETTERGB (255, 239, 213) },
80   {"BlanchedAlmond"             , PALETTERGB (255, 235, 205) },
81   {"bisque"                     , PALETTERGB (255, 228, 196) },
82   {"PeachPuff"                  , PALETTERGB (255, 218, 185) },
83   {"NavajoWhite"                , PALETTERGB (255, 222, 173) },
84   {"moccasin"                   , PALETTERGB (255, 228, 181) },
85   {"cornsilk"                   , PALETTERGB (255, 248, 220) },
86   {"ivory"                      , PALETTERGB (255, 255, 240) },
87   {"LemonChiffon"               , PALETTERGB (255, 250, 205) },
88   {"seashell"                   , PALETTERGB (255, 245, 238) },
89   {"honeydew"                   , PALETTERGB (240, 255, 240) },
90   {"MintCream"                  , PALETTERGB (245, 255, 250) },
91   {"azure"                      , PALETTERGB (240, 255, 255) },
92   {"AliceBlue"                  , PALETTERGB (240, 248, 255) },
93   {"lavender"                   , PALETTERGB (230, 230, 250) },
94   {"LavenderBlush"              , PALETTERGB (255, 240, 245) },
95   {"MistyRose"                  , PALETTERGB (255, 228, 225) },
96   {"white"                      , PALETTERGB (255, 255, 255) },
97   {"black"                      , PALETTERGB (0, 0, 0) },
98   {"DarkSlateGray"              , PALETTERGB (47, 79, 79) },
99   {"DarkSlateGrey"              , PALETTERGB (47, 79, 79) },
100   {"DimGray"                    , PALETTERGB (105, 105, 105) },
101   {"DimGrey"                    , PALETTERGB (105, 105, 105) },
102   {"SlateGray"                  , PALETTERGB (112, 128, 144) },
103   {"SlateGrey"                  , PALETTERGB (112, 128, 144) },
104   {"LightSlateGray"             , PALETTERGB (119, 136, 153) },
105   {"LightSlateGrey"             , PALETTERGB (119, 136, 153) },
106   {"gray"                       , PALETTERGB (190, 190, 190) },
107   {"grey"                       , PALETTERGB (190, 190, 190) },
108   {"LightGrey"                  , PALETTERGB (211, 211, 211) },
109   {"LightGray"                  , PALETTERGB (211, 211, 211) },
110   {"MidnightBlue"               , PALETTERGB (25, 25, 112) },
111   {"navy"                       , PALETTERGB (0, 0, 128) },
112   {"NavyBlue"                   , PALETTERGB (0, 0, 128) },
113   {"CornflowerBlue"             , PALETTERGB (100, 149, 237) },
114   {"DarkSlateBlue"              , PALETTERGB (72, 61, 139) },
115   {"SlateBlue"                  , PALETTERGB (106, 90, 205) },
116   {"MediumSlateBlue"            , PALETTERGB (123, 104, 238) },
117   {"LightSlateBlue"             , PALETTERGB (132, 112, 255) },
118   {"MediumBlue"                 , PALETTERGB (0, 0, 205) },
119   {"RoyalBlue"                  , PALETTERGB (65, 105, 225) },
120   {"blue"                       , PALETTERGB (0, 0, 255) },
121   {"DodgerBlue"                 , PALETTERGB (30, 144, 255) },
122   {"DeepSkyBlue"                , PALETTERGB (0, 191, 255) },
123   {"SkyBlue"                    , PALETTERGB (135, 206, 235) },
124   {"LightSkyBlue"               , PALETTERGB (135, 206, 250) },
125   {"SteelBlue"                  , PALETTERGB (70, 130, 180) },
126   {"LightSteelBlue"             , PALETTERGB (176, 196, 222) },
127   {"LightBlue"                  , PALETTERGB (173, 216, 230) },
128   {"PowderBlue"                 , PALETTERGB (176, 224, 230) },
129   {"PaleTurquoise"              , PALETTERGB (175, 238, 238) },
130   {"DarkTurquoise"              , PALETTERGB (0, 206, 209) },
131   {"MediumTurquoise"            , PALETTERGB (72, 209, 204) },
132   {"turquoise"                  , PALETTERGB (64, 224, 208) },
133   {"cyan"                       , PALETTERGB (0, 255, 255) },
134   {"LightCyan"                  , PALETTERGB (224, 255, 255) },
135   {"CadetBlue"                  , PALETTERGB (95, 158, 160) },
136   {"MediumAquamarine"           , PALETTERGB (102, 205, 170) },
137   {"aquamarine"                 , PALETTERGB (127, 255, 212) },
138   {"DarkGreen"                  , PALETTERGB (0, 100, 0) },
139   {"DarkOliveGreen"             , PALETTERGB (85, 107, 47) },
140   {"DarkSeaGreen"               , PALETTERGB (143, 188, 143) },
141   {"SeaGreen"                   , PALETTERGB (46, 139, 87) },
142   {"MediumSeaGreen"             , PALETTERGB (60, 179, 113) },
143   {"LightSeaGreen"              , PALETTERGB (32, 178, 170) },
144   {"PaleGreen"                  , PALETTERGB (152, 251, 152) },
145   {"SpringGreen"                , PALETTERGB (0, 255, 127) },
146   {"LawnGreen"                  , PALETTERGB (124, 252, 0) },
147   {"green"                      , PALETTERGB (0, 255, 0) },
148   {"chartreuse"                 , PALETTERGB (127, 255, 0) },
149   {"MediumSpringGreen"          , PALETTERGB (0, 250, 154) },
150   {"GreenYellow"                , PALETTERGB (173, 255, 47) },
151   {"LimeGreen"                  , PALETTERGB (50, 205, 50) },
152   {"YellowGreen"                , PALETTERGB (154, 205, 50) },
153   {"ForestGreen"                , PALETTERGB (34, 139, 34) },
154   {"OliveDrab"                  , PALETTERGB (107, 142, 35) },
155   {"DarkKhaki"                  , PALETTERGB (189, 183, 107) },
156   {"khaki"                      , PALETTERGB (240, 230, 140) },
157   {"PaleGoldenrod"              , PALETTERGB (238, 232, 170) },
158   {"LightGoldenrodYellow"       , PALETTERGB (250, 250, 210) },
159   {"LightYellow"                , PALETTERGB (255, 255, 224) },
160   {"yellow"                     , PALETTERGB (255, 255, 0) },
161   {"gold"                       , PALETTERGB (255, 215, 0) },
162   {"LightGoldenrod"             , PALETTERGB (238, 221, 130) },
163   {"goldenrod"                  , PALETTERGB (218, 165, 32) },
164   {"DarkGoldenrod"              , PALETTERGB (184, 134, 11) },
165   {"RosyBrown"                  , PALETTERGB (188, 143, 143) },
166   {"IndianRed"                  , PALETTERGB (205, 92, 92) },
167   {"SaddleBrown"                , PALETTERGB (139, 69, 19) },
168   {"sienna"                     , PALETTERGB (160, 82, 45) },
169   {"peru"                       , PALETTERGB (205, 133, 63) },
170   {"burlywood"                  , PALETTERGB (222, 184, 135) },
171   {"beige"                      , PALETTERGB (245, 245, 220) },
172   {"wheat"                      , PALETTERGB (245, 222, 179) },
173   {"SandyBrown"                 , PALETTERGB (244, 164, 96) },
174   {"tan"                        , PALETTERGB (210, 180, 140) },
175   {"chocolate"                  , PALETTERGB (210, 105, 30) },
176   {"firebrick"                  , PALETTERGB (178, 34, 34) },
177   {"brown"                      , PALETTERGB (165, 42, 42) },
178   {"DarkSalmon"                 , PALETTERGB (233, 150, 122) },
179   {"salmon"                     , PALETTERGB (250, 128, 114) },
180   {"LightSalmon"                , PALETTERGB (255, 160, 122) },
181   {"orange"                     , PALETTERGB (255, 165, 0) },
182   {"DarkOrange"                 , PALETTERGB (255, 140, 0) },
183   {"coral"                      , PALETTERGB (255, 127, 80) },
184   {"LightCoral"                 , PALETTERGB (240, 128, 128) },
185   {"tomato"                     , PALETTERGB (255, 99, 71) },
186   {"OrangeRed"                  , PALETTERGB (255, 69, 0) },
187   {"red"                        , PALETTERGB (255, 0, 0) },
188   {"HotPink"                    , PALETTERGB (255, 105, 180) },
189   {"DeepPink"                   , PALETTERGB (255, 20, 147) },
190   {"pink"                       , PALETTERGB (255, 192, 203) },
191   {"LightPink"                  , PALETTERGB (255, 182, 193) },
192   {"PaleVioletRed"              , PALETTERGB (219, 112, 147) },
193   {"maroon"                     , PALETTERGB (176, 48, 96) },
194   {"MediumVioletRed"            , PALETTERGB (199, 21, 133) },
195   {"VioletRed"                  , PALETTERGB (208, 32, 144) },
196   {"magenta"                    , PALETTERGB (255, 0, 255) },
197   {"violet"                     , PALETTERGB (238, 130, 238) },
198   {"plum"                       , PALETTERGB (221, 160, 221) },
199   {"orchid"                     , PALETTERGB (218, 112, 214) },
200   {"MediumOrchid"               , PALETTERGB (186, 85, 211) },
201   {"DarkOrchid"                 , PALETTERGB (153, 50, 204) },
202   {"DarkViolet"                 , PALETTERGB (148, 0, 211) },
203   {"BlueViolet"                 , PALETTERGB (138, 43, 226) },
204   {"purple"                     , PALETTERGB (160, 32, 240) },
205   {"MediumPurple"               , PALETTERGB (147, 112, 219) },
206   {"thistle"                    , PALETTERGB (216, 191, 216) },
207   {"snow1"                      , PALETTERGB (255, 250, 250) },
208   {"snow2"                      , PALETTERGB (238, 233, 233) },
209   {"snow3"                      , PALETTERGB (205, 201, 201) },
210   {"snow4"                      , PALETTERGB (139, 137, 137) },
211   {"seashell1"                  , PALETTERGB (255, 245, 238) },
212   {"seashell2"                  , PALETTERGB (238, 229, 222) },
213   {"seashell3"                  , PALETTERGB (205, 197, 191) },
214   {"seashell4"                  , PALETTERGB (139, 134, 130) },
215   {"AntiqueWhite1"              , PALETTERGB (255, 239, 219) },
216   {"AntiqueWhite2"              , PALETTERGB (238, 223, 204) },
217   {"AntiqueWhite3"              , PALETTERGB (205, 192, 176) },
218   {"AntiqueWhite4"              , PALETTERGB (139, 131, 120) },
219   {"bisque1"                    , PALETTERGB (255, 228, 196) },
220   {"bisque2"                    , PALETTERGB (238, 213, 183) },
221   {"bisque3"                    , PALETTERGB (205, 183, 158) },
222   {"bisque4"                    , PALETTERGB (139, 125, 107) },
223   {"PeachPuff1"                 , PALETTERGB (255, 218, 185) },
224   {"PeachPuff2"                 , PALETTERGB (238, 203, 173) },
225   {"PeachPuff3"                 , PALETTERGB (205, 175, 149) },
226   {"PeachPuff4"                 , PALETTERGB (139, 119, 101) },
227   {"NavajoWhite1"               , PALETTERGB (255, 222, 173) },
228   {"NavajoWhite2"               , PALETTERGB (238, 207, 161) },
229   {"NavajoWhite3"               , PALETTERGB (205, 179, 139) },
230   {"NavajoWhite4"               , PALETTERGB (139, 121, 94) },
231   {"LemonChiffon1"              , PALETTERGB (255, 250, 205) },
232   {"LemonChiffon2"              , PALETTERGB (238, 233, 191) },
233   {"LemonChiffon3"              , PALETTERGB (205, 201, 165) },
234   {"LemonChiffon4"              , PALETTERGB (139, 137, 112) },
235   {"cornsilk1"                  , PALETTERGB (255, 248, 220) },
236   {"cornsilk2"                  , PALETTERGB (238, 232, 205) },
237   {"cornsilk3"                  , PALETTERGB (205, 200, 177) },
238   {"cornsilk4"                  , PALETTERGB (139, 136, 120) },
239   {"ivory1"                     , PALETTERGB (255, 255, 240) },
240   {"ivory2"                     , PALETTERGB (238, 238, 224) },
241   {"ivory3"                     , PALETTERGB (205, 205, 193) },
242   {"ivory4"                     , PALETTERGB (139, 139, 131) },
243   {"honeydew1"                  , PALETTERGB (240, 255, 240) },
244   {"honeydew2"                  , PALETTERGB (224, 238, 224) },
245   {"honeydew3"                  , PALETTERGB (193, 205, 193) },
246   {"honeydew4"                  , PALETTERGB (131, 139, 131) },
247   {"LavenderBlush1"             , PALETTERGB (255, 240, 245) },
248   {"LavenderBlush2"             , PALETTERGB (238, 224, 229) },
249   {"LavenderBlush3"             , PALETTERGB (205, 193, 197) },
250   {"LavenderBlush4"             , PALETTERGB (139, 131, 134) },
251   {"MistyRose1"                 , PALETTERGB (255, 228, 225) },
252   {"MistyRose2"                 , PALETTERGB (238, 213, 210) },
253   {"MistyRose3"                 , PALETTERGB (205, 183, 181) },
254   {"MistyRose4"                 , PALETTERGB (139, 125, 123) },
255   {"azure1"                     , PALETTERGB (240, 255, 255) },
256   {"azure2"                     , PALETTERGB (224, 238, 238) },
257   {"azure3"                     , PALETTERGB (193, 205, 205) },
258   {"azure4"                     , PALETTERGB (131, 139, 139) },
259   {"SlateBlue1"                 , PALETTERGB (131, 111, 255) },
260   {"SlateBlue2"                 , PALETTERGB (122, 103, 238) },
261   {"SlateBlue3"                 , PALETTERGB (105, 89, 205) },
262   {"SlateBlue4"                 , PALETTERGB (71, 60, 139) },
263   {"RoyalBlue1"                 , PALETTERGB (72, 118, 255) },
264   {"RoyalBlue2"                 , PALETTERGB (67, 110, 238) },
265   {"RoyalBlue3"                 , PALETTERGB (58, 95, 205) },
266   {"RoyalBlue4"                 , PALETTERGB (39, 64, 139) },
267   {"blue1"                      , PALETTERGB (0, 0, 255) },
268   {"blue2"                      , PALETTERGB (0, 0, 238) },
269   {"blue3"                      , PALETTERGB (0, 0, 205) },
270   {"blue4"                      , PALETTERGB (0, 0, 139) },
271   {"DodgerBlue1"                , PALETTERGB (30, 144, 255) },
272   {"DodgerBlue2"                , PALETTERGB (28, 134, 238) },
273   {"DodgerBlue3"                , PALETTERGB (24, 116, 205) },
274   {"DodgerBlue4"                , PALETTERGB (16, 78, 139) },
275   {"SteelBlue1"                 , PALETTERGB (99, 184, 255) },
276   {"SteelBlue2"                 , PALETTERGB (92, 172, 238) },
277   {"SteelBlue3"                 , PALETTERGB (79, 148, 205) },
278   {"SteelBlue4"                 , PALETTERGB (54, 100, 139) },
279   {"DeepSkyBlue1"               , PALETTERGB (0, 191, 255) },
280   {"DeepSkyBlue2"               , PALETTERGB (0, 178, 238) },
281   {"DeepSkyBlue3"               , PALETTERGB (0, 154, 205) },
282   {"DeepSkyBlue4"               , PALETTERGB (0, 104, 139) },
283   {"SkyBlue1"                   , PALETTERGB (135, 206, 255) },
284   {"SkyBlue2"                   , PALETTERGB (126, 192, 238) },
285   {"SkyBlue3"                   , PALETTERGB (108, 166, 205) },
286   {"SkyBlue4"                   , PALETTERGB (74, 112, 139) },
287   {"LightSkyBlue1"              , PALETTERGB (176, 226, 255) },
288   {"LightSkyBlue2"              , PALETTERGB (164, 211, 238) },
289   {"LightSkyBlue3"              , PALETTERGB (141, 182, 205) },
290   {"LightSkyBlue4"              , PALETTERGB (96, 123, 139) },
291   {"SlateGray1"                 , PALETTERGB (198, 226, 255) },
292   {"SlateGray2"                 , PALETTERGB (185, 211, 238) },
293   {"SlateGray3"                 , PALETTERGB (159, 182, 205) },
294   {"SlateGray4"                 , PALETTERGB (108, 123, 139) },
295   {"LightSteelBlue1"            , PALETTERGB (202, 225, 255) },
296   {"LightSteelBlue2"            , PALETTERGB (188, 210, 238) },
297   {"LightSteelBlue3"            , PALETTERGB (162, 181, 205) },
298   {"LightSteelBlue4"            , PALETTERGB (110, 123, 139) },
299   {"LightBlue1"                 , PALETTERGB (191, 239, 255) },
300   {"LightBlue2"                 , PALETTERGB (178, 223, 238) },
301   {"LightBlue3"                 , PALETTERGB (154, 192, 205) },
302   {"LightBlue4"                 , PALETTERGB (104, 131, 139) },
303   {"LightCyan1"                 , PALETTERGB (224, 255, 255) },
304   {"LightCyan2"                 , PALETTERGB (209, 238, 238) },
305   {"LightCyan3"                 , PALETTERGB (180, 205, 205) },
306   {"LightCyan4"                 , PALETTERGB (122, 139, 139) },
307   {"PaleTurquoise1"             , PALETTERGB (187, 255, 255) },
308   {"PaleTurquoise2"             , PALETTERGB (174, 238, 238) },
309   {"PaleTurquoise3"             , PALETTERGB (150, 205, 205) },
310   {"PaleTurquoise4"             , PALETTERGB (102, 139, 139) },
311   {"CadetBlue1"                 , PALETTERGB (152, 245, 255) },
312   {"CadetBlue2"                 , PALETTERGB (142, 229, 238) },
313   {"CadetBlue3"                 , PALETTERGB (122, 197, 205) },
314   {"CadetBlue4"                 , PALETTERGB (83, 134, 139) },
315   {"turquoise1"                 , PALETTERGB (0, 245, 255) },
316   {"turquoise2"                 , PALETTERGB (0, 229, 238) },
317   {"turquoise3"                 , PALETTERGB (0, 197, 205) },
318   {"turquoise4"                 , PALETTERGB (0, 134, 139) },
319   {"cyan1"                      , PALETTERGB (0, 255, 255) },
320   {"cyan2"                      , PALETTERGB (0, 238, 238) },
321   {"cyan3"                      , PALETTERGB (0, 205, 205) },
322   {"cyan4"                      , PALETTERGB (0, 139, 139) },
323   {"DarkSlateGray1"             , PALETTERGB (151, 255, 255) },
324   {"DarkSlateGray2"             , PALETTERGB (141, 238, 238) },
325   {"DarkSlateGray3"             , PALETTERGB (121, 205, 205) },
326   {"DarkSlateGray4"             , PALETTERGB (82, 139, 139) },
327   {"aquamarine1"                , PALETTERGB (127, 255, 212) },
328   {"aquamarine2"                , PALETTERGB (118, 238, 198) },
329   {"aquamarine3"                , PALETTERGB (102, 205, 170) },
330   {"aquamarine4"                , PALETTERGB (69, 139, 116) },
331   {"DarkSeaGreen1"              , PALETTERGB (193, 255, 193) },
332   {"DarkSeaGreen2"              , PALETTERGB (180, 238, 180) },
333   {"DarkSeaGreen3"              , PALETTERGB (155, 205, 155) },
334   {"DarkSeaGreen4"              , PALETTERGB (105, 139, 105) },
335   {"SeaGreen1"                  , PALETTERGB (84, 255, 159) },
336   {"SeaGreen2"                  , PALETTERGB (78, 238, 148) },
337   {"SeaGreen3"                  , PALETTERGB (67, 205, 128) },
338   {"SeaGreen4"                  , PALETTERGB (46, 139, 87) },
339   {"PaleGreen1"                 , PALETTERGB (154, 255, 154) },
340   {"PaleGreen2"                 , PALETTERGB (144, 238, 144) },
341   {"PaleGreen3"                 , PALETTERGB (124, 205, 124) },
342   {"PaleGreen4"                 , PALETTERGB (84, 139, 84) },
343   {"SpringGreen1"               , PALETTERGB (0, 255, 127) },
344   {"SpringGreen2"               , PALETTERGB (0, 238, 118) },
345   {"SpringGreen3"               , PALETTERGB (0, 205, 102) },
346   {"SpringGreen4"               , PALETTERGB (0, 139, 69) },
347   {"green1"                     , PALETTERGB (0, 255, 0) },
348   {"green2"                     , PALETTERGB (0, 238, 0) },
349   {"green3"                     , PALETTERGB (0, 205, 0) },
350   {"green4"                     , PALETTERGB (0, 139, 0) },
351   {"chartreuse1"                , PALETTERGB (127, 255, 0) },
352   {"chartreuse2"                , PALETTERGB (118, 238, 0) },
353   {"chartreuse3"                , PALETTERGB (102, 205, 0) },
354   {"chartreuse4"                , PALETTERGB (69, 139, 0) },
355   {"OliveDrab1"                 , PALETTERGB (192, 255, 62) },
356   {"OliveDrab2"                 , PALETTERGB (179, 238, 58) },
357   {"OliveDrab3"                 , PALETTERGB (154, 205, 50) },
358   {"OliveDrab4"                 , PALETTERGB (105, 139, 34) },
359   {"DarkOliveGreen1"            , PALETTERGB (202, 255, 112) },
360   {"DarkOliveGreen2"            , PALETTERGB (188, 238, 104) },
361   {"DarkOliveGreen3"            , PALETTERGB (162, 205, 90) },
362   {"DarkOliveGreen4"            , PALETTERGB (110, 139, 61) },
363   {"khaki1"                     , PALETTERGB (255, 246, 143) },
364   {"khaki2"                     , PALETTERGB (238, 230, 133) },
365   {"khaki3"                     , PALETTERGB (205, 198, 115) },
366   {"khaki4"                     , PALETTERGB (139, 134, 78) },
367   {"LightGoldenrod1"            , PALETTERGB (255, 236, 139) },
368   {"LightGoldenrod2"            , PALETTERGB (238, 220, 130) },
369   {"LightGoldenrod3"            , PALETTERGB (205, 190, 112) },
370   {"LightGoldenrod4"            , PALETTERGB (139, 129, 76) },
371   {"LightYellow1"               , PALETTERGB (255, 255, 224) },
372   {"LightYellow2"               , PALETTERGB (238, 238, 209) },
373   {"LightYellow3"               , PALETTERGB (205, 205, 180) },
374   {"LightYellow4"               , PALETTERGB (139, 139, 122) },
375   {"yellow1"                    , PALETTERGB (255, 255, 0) },
376   {"yellow2"                    , PALETTERGB (238, 238, 0) },
377   {"yellow3"                    , PALETTERGB (205, 205, 0) },
378   {"yellow4"                    , PALETTERGB (139, 139, 0) },
379   {"gold1"                      , PALETTERGB (255, 215, 0) },
380   {"gold2"                      , PALETTERGB (238, 201, 0) },
381   {"gold3"                      , PALETTERGB (205, 173, 0) },
382   {"gold4"                      , PALETTERGB (139, 117, 0) },
383   {"goldenrod1"                 , PALETTERGB (255, 193, 37) },
384   {"goldenrod2"                 , PALETTERGB (238, 180, 34) },
385   {"goldenrod3"                 , PALETTERGB (205, 155, 29) },
386   {"goldenrod4"                 , PALETTERGB (139, 105, 20) },
387   {"DarkGoldenrod1"             , PALETTERGB (255, 185, 15) },
388   {"DarkGoldenrod2"             , PALETTERGB (238, 173, 14) },
389   {"DarkGoldenrod3"             , PALETTERGB (205, 149, 12) },
390   {"DarkGoldenrod4"             , PALETTERGB (139, 101, 8) },
391   {"RosyBrown1"                 , PALETTERGB (255, 193, 193) },
392   {"RosyBrown2"                 , PALETTERGB (238, 180, 180) },
393   {"RosyBrown3"                 , PALETTERGB (205, 155, 155) },
394   {"RosyBrown4"                 , PALETTERGB (139, 105, 105) },
395   {"IndianRed1"                 , PALETTERGB (255, 106, 106) },
396   {"IndianRed2"                 , PALETTERGB (238, 99, 99) },
397   {"IndianRed3"                 , PALETTERGB (205, 85, 85) },
398   {"IndianRed4"                 , PALETTERGB (139, 58, 58) },
399   {"sienna1"                    , PALETTERGB (255, 130, 71) },
400   {"sienna2"                    , PALETTERGB (238, 121, 66) },
401   {"sienna3"                    , PALETTERGB (205, 104, 57) },
402   {"sienna4"                    , PALETTERGB (139, 71, 38) },
403   {"burlywood1"                 , PALETTERGB (255, 211, 155) },
404   {"burlywood2"                 , PALETTERGB (238, 197, 145) },
405   {"burlywood3"                 , PALETTERGB (205, 170, 125) },
406   {"burlywood4"                 , PALETTERGB (139, 115, 85) },
407   {"wheat1"                     , PALETTERGB (255, 231, 186) },
408   {"wheat2"                     , PALETTERGB (238, 216, 174) },
409   {"wheat3"                     , PALETTERGB (205, 186, 150) },
410   {"wheat4"                     , PALETTERGB (139, 126, 102) },
411   {"tan1"                       , PALETTERGB (255, 165, 79) },
412   {"tan2"                       , PALETTERGB (238, 154, 73) },
413   {"tan3"                       , PALETTERGB (205, 133, 63) },
414   {"tan4"                       , PALETTERGB (139, 90, 43) },
415   {"chocolate1"                 , PALETTERGB (255, 127, 36) },
416   {"chocolate2"                 , PALETTERGB (238, 118, 33) },
417   {"chocolate3"                 , PALETTERGB (205, 102, 29) },
418   {"chocolate4"                 , PALETTERGB (139, 69, 19) },
419   {"firebrick1"                 , PALETTERGB (255, 48, 48) },
420   {"firebrick2"                 , PALETTERGB (238, 44, 44) },
421   {"firebrick3"                 , PALETTERGB (205, 38, 38) },
422   {"firebrick4"                 , PALETTERGB (139, 26, 26) },
423   {"brown1"                     , PALETTERGB (255, 64, 64) },
424   {"brown2"                     , PALETTERGB (238, 59, 59) },
425   {"brown3"                     , PALETTERGB (205, 51, 51) },
426   {"brown4"                     , PALETTERGB (139, 35, 35) },
427   {"salmon1"                    , PALETTERGB (255, 140, 105) },
428   {"salmon2"                    , PALETTERGB (238, 130, 98) },
429   {"salmon3"                    , PALETTERGB (205, 112, 84) },
430   {"salmon4"                    , PALETTERGB (139, 76, 57) },
431   {"LightSalmon1"               , PALETTERGB (255, 160, 122) },
432   {"LightSalmon2"               , PALETTERGB (238, 149, 114) },
433   {"LightSalmon3"               , PALETTERGB (205, 129, 98) },
434   {"LightSalmon4"               , PALETTERGB (139, 87, 66) },
435   {"orange1"                    , PALETTERGB (255, 165, 0) },
436   {"orange2"                    , PALETTERGB (238, 154, 0) },
437   {"orange3"                    , PALETTERGB (205, 133, 0) },
438   {"orange4"                    , PALETTERGB (139, 90, 0) },
439   {"DarkOrange1"                , PALETTERGB (255, 127, 0) },
440   {"DarkOrange2"                , PALETTERGB (238, 118, 0) },
441   {"DarkOrange3"                , PALETTERGB (205, 102, 0) },
442   {"DarkOrange4"                , PALETTERGB (139, 69, 0) },
443   {"coral1"                     , PALETTERGB (255, 114, 86) },
444   {"coral2"                     , PALETTERGB (238, 106, 80) },
445   {"coral3"                     , PALETTERGB (205, 91, 69) },
446   {"coral4"                     , PALETTERGB (139, 62, 47) },
447   {"tomato1"                    , PALETTERGB (255, 99, 71) },
448   {"tomato2"                    , PALETTERGB (238, 92, 66) },
449   {"tomato3"                    , PALETTERGB (205, 79, 57) },
450   {"tomato4"                    , PALETTERGB (139, 54, 38) },
451   {"OrangeRed1"                 , PALETTERGB (255, 69, 0) },
452   {"OrangeRed2"                 , PALETTERGB (238, 64, 0) },
453   {"OrangeRed3"                 , PALETTERGB (205, 55, 0) },
454   {"OrangeRed4"                 , PALETTERGB (139, 37, 0) },
455   {"red1"                       , PALETTERGB (255, 0, 0) },
456   {"red2"                       , PALETTERGB (238, 0, 0) },
457   {"red3"                       , PALETTERGB (205, 0, 0) },
458   {"red4"                       , PALETTERGB (139, 0, 0) },
459   {"DeepPink1"                  , PALETTERGB (255, 20, 147) },
460   {"DeepPink2"                  , PALETTERGB (238, 18, 137) },
461   {"DeepPink3"                  , PALETTERGB (205, 16, 118) },
462   {"DeepPink4"                  , PALETTERGB (139, 10, 80) },
463   {"HotPink1"                   , PALETTERGB (255, 110, 180) },
464   {"HotPink2"                   , PALETTERGB (238, 106, 167) },
465   {"HotPink3"                   , PALETTERGB (205, 96, 144) },
466   {"HotPink4"                   , PALETTERGB (139, 58, 98) },
467   {"pink1"                      , PALETTERGB (255, 181, 197) },
468   {"pink2"                      , PALETTERGB (238, 169, 184) },
469   {"pink3"                      , PALETTERGB (205, 145, 158) },
470   {"pink4"                      , PALETTERGB (139, 99, 108) },
471   {"LightPink1"                 , PALETTERGB (255, 174, 185) },
472   {"LightPink2"                 , PALETTERGB (238, 162, 173) },
473   {"LightPink3"                 , PALETTERGB (205, 140, 149) },
474   {"LightPink4"                 , PALETTERGB (139, 95, 101) },
475   {"PaleVioletRed1"             , PALETTERGB (255, 130, 171) },
476   {"PaleVioletRed2"             , PALETTERGB (238, 121, 159) },
477   {"PaleVioletRed3"             , PALETTERGB (205, 104, 137) },
478   {"PaleVioletRed4"             , PALETTERGB (139, 71, 93) },
479   {"maroon1"                    , PALETTERGB (255, 52, 179) },
480   {"maroon2"                    , PALETTERGB (238, 48, 167) },
481   {"maroon3"                    , PALETTERGB (205, 41, 144) },
482   {"maroon4"                    , PALETTERGB (139, 28, 98) },
483   {"VioletRed1"                 , PALETTERGB (255, 62, 150) },
484   {"VioletRed2"                 , PALETTERGB (238, 58, 140) },
485   {"VioletRed3"                 , PALETTERGB (205, 50, 120) },
486   {"VioletRed4"                 , PALETTERGB (139, 34, 82) },
487   {"magenta1"                   , PALETTERGB (255, 0, 255) },
488   {"magenta2"                   , PALETTERGB (238, 0, 238) },
489   {"magenta3"                   , PALETTERGB (205, 0, 205) },
490   {"magenta4"                   , PALETTERGB (139, 0, 139) },
491   {"orchid1"                    , PALETTERGB (255, 131, 250) },
492   {"orchid2"                    , PALETTERGB (238, 122, 233) },
493   {"orchid3"                    , PALETTERGB (205, 105, 201) },
494   {"orchid4"                    , PALETTERGB (139, 71, 137) },
495   {"plum1"                      , PALETTERGB (255, 187, 255) },
496   {"plum2"                      , PALETTERGB (238, 174, 238) },
497   {"plum3"                      , PALETTERGB (205, 150, 205) },
498   {"plum4"                      , PALETTERGB (139, 102, 139) },
499   {"MediumOrchid1"              , PALETTERGB (224, 102, 255) },
500   {"MediumOrchid2"              , PALETTERGB (209, 95, 238) },
501   {"MediumOrchid3"              , PALETTERGB (180, 82, 205) },
502   {"MediumOrchid4"              , PALETTERGB (122, 55, 139) },
503   {"DarkOrchid1"                , PALETTERGB (191, 62, 255) },
504   {"DarkOrchid2"                , PALETTERGB (178, 58, 238) },
505   {"DarkOrchid3"                , PALETTERGB (154, 50, 205) },
506   {"DarkOrchid4"                , PALETTERGB (104, 34, 139) },
507   {"purple1"                    , PALETTERGB (155, 48, 255) },
508   {"purple2"                    , PALETTERGB (145, 44, 238) },
509   {"purple3"                    , PALETTERGB (125, 38, 205) },
510   {"purple4"                    , PALETTERGB (85, 26, 139) },
511   {"MediumPurple1"              , PALETTERGB (171, 130, 255) },
512   {"MediumPurple2"              , PALETTERGB (159, 121, 238) },
513   {"MediumPurple3"              , PALETTERGB (137, 104, 205) },
514   {"MediumPurple4"              , PALETTERGB (93, 71, 139) },
515   {"thistle1"                   , PALETTERGB (255, 225, 255) },
516   {"thistle2"                   , PALETTERGB (238, 210, 238) },
517   {"thistle3"                   , PALETTERGB (205, 181, 205) },
518   {"thistle4"                   , PALETTERGB (139, 123, 139) },
519   {"gray0"                      , PALETTERGB (0, 0, 0) },
520   {"grey0"                      , PALETTERGB (0, 0, 0) },
521   {"gray1"                      , PALETTERGB (3, 3, 3) },
522   {"grey1"                      , PALETTERGB (3, 3, 3) },
523   {"gray2"                      , PALETTERGB (5, 5, 5) },
524   {"grey2"                      , PALETTERGB (5, 5, 5) },
525   {"gray3"                      , PALETTERGB (8, 8, 8) },
526   {"grey3"                      , PALETTERGB (8, 8, 8) },
527   {"gray4"                      , PALETTERGB (10, 10, 10) },
528   {"grey4"                      , PALETTERGB (10, 10, 10) },
529   {"gray5"                      , PALETTERGB (13, 13, 13) },
530   {"grey5"                      , PALETTERGB (13, 13, 13) },
531   {"gray6"                      , PALETTERGB (15, 15, 15) },
532   {"grey6"                      , PALETTERGB (15, 15, 15) },
533   {"gray7"                      , PALETTERGB (18, 18, 18) },
534   {"grey7"                      , PALETTERGB (18, 18, 18) },
535   {"gray8"                      , PALETTERGB (20, 20, 20) },
536   {"grey8"                      , PALETTERGB (20, 20, 20) },
537   {"gray9"                      , PALETTERGB (23, 23, 23) },
538   {"grey9"                      , PALETTERGB (23, 23, 23) },
539   {"gray10"                     , PALETTERGB (26, 26, 26) },
540   {"grey10"                     , PALETTERGB (26, 26, 26) },
541   {"gray11"                     , PALETTERGB (28, 28, 28) },
542   {"grey11"                     , PALETTERGB (28, 28, 28) },
543   {"gray12"                     , PALETTERGB (31, 31, 31) },
544   {"grey12"                     , PALETTERGB (31, 31, 31) },
545   {"gray13"                     , PALETTERGB (33, 33, 33) },
546   {"grey13"                     , PALETTERGB (33, 33, 33) },
547   {"gray14"                     , PALETTERGB (36, 36, 36) },
548   {"grey14"                     , PALETTERGB (36, 36, 36) },
549   {"gray15"                     , PALETTERGB (38, 38, 38) },
550   {"grey15"                     , PALETTERGB (38, 38, 38) },
551   {"gray16"                     , PALETTERGB (41, 41, 41) },
552   {"grey16"                     , PALETTERGB (41, 41, 41) },
553   {"gray17"                     , PALETTERGB (43, 43, 43) },
554   {"grey17"                     , PALETTERGB (43, 43, 43) },
555   {"gray18"                     , PALETTERGB (46, 46, 46) },
556   {"grey18"                     , PALETTERGB (46, 46, 46) },
557   {"gray19"                     , PALETTERGB (48, 48, 48) },
558   {"grey19"                     , PALETTERGB (48, 48, 48) },
559   {"gray20"                     , PALETTERGB (51, 51, 51) },
560   {"grey20"                     , PALETTERGB (51, 51, 51) },
561   {"gray21"                     , PALETTERGB (54, 54, 54) },
562   {"grey21"                     , PALETTERGB (54, 54, 54) },
563   {"gray22"                     , PALETTERGB (56, 56, 56) },
564   {"grey22"                     , PALETTERGB (56, 56, 56) },
565   {"gray23"                     , PALETTERGB (59, 59, 59) },
566   {"grey23"                     , PALETTERGB (59, 59, 59) },
567   {"gray24"                     , PALETTERGB (61, 61, 61) },
568   {"grey24"                     , PALETTERGB (61, 61, 61) },
569   {"gray25"                     , PALETTERGB (64, 64, 64) },
570   {"grey25"                     , PALETTERGB (64, 64, 64) },
571   {"gray26"                     , PALETTERGB (66, 66, 66) },
572   {"grey26"                     , PALETTERGB (66, 66, 66) },
573   {"gray27"                     , PALETTERGB (69, 69, 69) },
574   {"grey27"                     , PALETTERGB (69, 69, 69) },
575   {"gray28"                     , PALETTERGB (71, 71, 71) },
576   {"grey28"                     , PALETTERGB (71, 71, 71) },
577   {"gray29"                     , PALETTERGB (74, 74, 74) },
578   {"grey29"                     , PALETTERGB (74, 74, 74) },
579   {"gray30"                     , PALETTERGB (77, 77, 77) },
580   {"grey30"                     , PALETTERGB (77, 77, 77) },
581   {"gray31"                     , PALETTERGB (79, 79, 79) },
582   {"grey31"                     , PALETTERGB (79, 79, 79) },
583   {"gray32"                     , PALETTERGB (82, 82, 82) },
584   {"grey32"                     , PALETTERGB (82, 82, 82) },
585   {"gray33"                     , PALETTERGB (84, 84, 84) },
586   {"grey33"                     , PALETTERGB (84, 84, 84) },
587   {"gray34"                     , PALETTERGB (87, 87, 87) },
588   {"grey34"                     , PALETTERGB (87, 87, 87) },
589   {"gray35"                     , PALETTERGB (89, 89, 89) },
590   {"grey35"                     , PALETTERGB (89, 89, 89) },
591   {"gray36"                     , PALETTERGB (92, 92, 92) },
592   {"grey36"                     , PALETTERGB (92, 92, 92) },
593   {"gray37"                     , PALETTERGB (94, 94, 94) },
594   {"grey37"                     , PALETTERGB (94, 94, 94) },
595   {"gray38"                     , PALETTERGB (97, 97, 97) },
596   {"grey38"                     , PALETTERGB (97, 97, 97) },
597   {"gray39"                     , PALETTERGB (99, 99, 99) },
598   {"grey39"                     , PALETTERGB (99, 99, 99) },
599   {"gray40"                     , PALETTERGB (102, 102, 102) },
600   {"grey40"                     , PALETTERGB (102, 102, 102) },
601   {"gray41"                     , PALETTERGB (105, 105, 105) },
602   {"grey41"                     , PALETTERGB (105, 105, 105) },
603   {"gray42"                     , PALETTERGB (107, 107, 107) },
604   {"grey42"                     , PALETTERGB (107, 107, 107) },
605   {"gray43"                     , PALETTERGB (110, 110, 110) },
606   {"grey43"                     , PALETTERGB (110, 110, 110) },
607   {"gray44"                     , PALETTERGB (112, 112, 112) },
608   {"grey44"                     , PALETTERGB (112, 112, 112) },
609   {"gray45"                     , PALETTERGB (115, 115, 115) },
610   {"grey45"                     , PALETTERGB (115, 115, 115) },
611   {"gray46"                     , PALETTERGB (117, 117, 117) },
612   {"grey46"                     , PALETTERGB (117, 117, 117) },
613   {"gray47"                     , PALETTERGB (120, 120, 120) },
614   {"grey47"                     , PALETTERGB (120, 120, 120) },
615   {"gray48"                     , PALETTERGB (122, 122, 122) },
616   {"grey48"                     , PALETTERGB (122, 122, 122) },
617   {"gray49"                     , PALETTERGB (125, 125, 125) },
618   {"grey49"                     , PALETTERGB (125, 125, 125) },
619   {"gray50"                     , PALETTERGB (127, 127, 127) },
620   {"grey50"                     , PALETTERGB (127, 127, 127) },
621   {"gray51"                     , PALETTERGB (130, 130, 130) },
622   {"grey51"                     , PALETTERGB (130, 130, 130) },
623   {"gray52"                     , PALETTERGB (133, 133, 133) },
624   {"grey52"                     , PALETTERGB (133, 133, 133) },
625   {"gray53"                     , PALETTERGB (135, 135, 135) },
626   {"grey53"                     , PALETTERGB (135, 135, 135) },
627   {"gray54"                     , PALETTERGB (138, 138, 138) },
628   {"grey54"                     , PALETTERGB (138, 138, 138) },
629   {"gray55"                     , PALETTERGB (140, 140, 140) },
630   {"grey55"                     , PALETTERGB (140, 140, 140) },
631   {"gray56"                     , PALETTERGB (143, 143, 143) },
632   {"grey56"                     , PALETTERGB (143, 143, 143) },
633   {"gray57"                     , PALETTERGB (145, 145, 145) },
634   {"grey57"                     , PALETTERGB (145, 145, 145) },
635   {"gray58"                     , PALETTERGB (148, 148, 148) },
636   {"grey58"                     , PALETTERGB (148, 148, 148) },
637   {"gray59"                     , PALETTERGB (150, 150, 150) },
638   {"grey59"                     , PALETTERGB (150, 150, 150) },
639   {"gray60"                     , PALETTERGB (153, 153, 153) },
640   {"grey60"                     , PALETTERGB (153, 153, 153) },
641   {"gray61"                     , PALETTERGB (156, 156, 156) },
642   {"grey61"                     , PALETTERGB (156, 156, 156) },
643   {"gray62"                     , PALETTERGB (158, 158, 158) },
644   {"grey62"                     , PALETTERGB (158, 158, 158) },
645   {"gray63"                     , PALETTERGB (161, 161, 161) },
646   {"grey63"                     , PALETTERGB (161, 161, 161) },
647   {"gray64"                     , PALETTERGB (163, 163, 163) },
648   {"grey64"                     , PALETTERGB (163, 163, 163) },
649   {"gray65"                     , PALETTERGB (166, 166, 166) },
650   {"grey65"                     , PALETTERGB (166, 166, 166) },
651   {"gray66"                     , PALETTERGB (168, 168, 168) },
652   {"grey66"                     , PALETTERGB (168, 168, 168) },
653   {"gray67"                     , PALETTERGB (171, 171, 171) },
654   {"grey67"                     , PALETTERGB (171, 171, 171) },
655   {"gray68"                     , PALETTERGB (173, 173, 173) },
656   {"grey68"                     , PALETTERGB (173, 173, 173) },
657   {"gray69"                     , PALETTERGB (176, 176, 176) },
658   {"grey69"                     , PALETTERGB (176, 176, 176) },
659   {"gray70"                     , PALETTERGB (179, 179, 179) },
660   {"grey70"                     , PALETTERGB (179, 179, 179) },
661   {"gray71"                     , PALETTERGB (181, 181, 181) },
662   {"grey71"                     , PALETTERGB (181, 181, 181) },
663   {"gray72"                     , PALETTERGB (184, 184, 184) },
664   {"grey72"                     , PALETTERGB (184, 184, 184) },
665   {"gray73"                     , PALETTERGB (186, 186, 186) },
666   {"grey73"                     , PALETTERGB (186, 186, 186) },
667   {"gray74"                     , PALETTERGB (189, 189, 189) },
668   {"grey74"                     , PALETTERGB (189, 189, 189) },
669   {"gray75"                     , PALETTERGB (191, 191, 191) },
670   {"grey75"                     , PALETTERGB (191, 191, 191) },
671   {"gray76"                     , PALETTERGB (194, 194, 194) },
672   {"grey76"                     , PALETTERGB (194, 194, 194) },
673   {"gray77"                     , PALETTERGB (196, 196, 196) },
674   {"grey77"                     , PALETTERGB (196, 196, 196) },
675   {"gray78"                     , PALETTERGB (199, 199, 199) },
676   {"grey78"                     , PALETTERGB (199, 199, 199) },
677   {"gray79"                     , PALETTERGB (201, 201, 201) },
678   {"grey79"                     , PALETTERGB (201, 201, 201) },
679   {"gray80"                     , PALETTERGB (204, 204, 204) },
680   {"grey80"                     , PALETTERGB (204, 204, 204) },
681   {"gray81"                     , PALETTERGB (207, 207, 207) },
682   {"grey81"                     , PALETTERGB (207, 207, 207) },
683   {"gray82"                     , PALETTERGB (209, 209, 209) },
684   {"grey82"                     , PALETTERGB (209, 209, 209) },
685   {"gray83"                     , PALETTERGB (212, 212, 212) },
686   {"grey83"                     , PALETTERGB (212, 212, 212) },
687   {"gray84"                     , PALETTERGB (214, 214, 214) },
688   {"grey84"                     , PALETTERGB (214, 214, 214) },
689   {"gray85"                     , PALETTERGB (217, 217, 217) },
690   {"grey85"                     , PALETTERGB (217, 217, 217) },
691   {"gray86"                     , PALETTERGB (219, 219, 219) },
692   {"grey86"                     , PALETTERGB (219, 219, 219) },
693   {"gray87"                     , PALETTERGB (222, 222, 222) },
694   {"grey87"                     , PALETTERGB (222, 222, 222) },
695   {"gray88"                     , PALETTERGB (224, 224, 224) },
696   {"grey88"                     , PALETTERGB (224, 224, 224) },
697   {"gray89"                     , PALETTERGB (227, 227, 227) },
698   {"grey89"                     , PALETTERGB (227, 227, 227) },
699   {"gray90"                     , PALETTERGB (229, 229, 229) },
700   {"grey90"                     , PALETTERGB (229, 229, 229) },
701   {"gray91"                     , PALETTERGB (232, 232, 232) },
702   {"grey91"                     , PALETTERGB (232, 232, 232) },
703   {"gray92"                     , PALETTERGB (235, 235, 235) },
704   {"grey92"                     , PALETTERGB (235, 235, 235) },
705   {"gray93"                     , PALETTERGB (237, 237, 237) },
706   {"grey93"                     , PALETTERGB (237, 237, 237) },
707   {"gray94"                     , PALETTERGB (240, 240, 240) },
708   {"grey94"                     , PALETTERGB (240, 240, 240) },
709   {"gray95"                     , PALETTERGB (242, 242, 242) },
710   {"grey95"                     , PALETTERGB (242, 242, 242) },
711   {"gray96"                     , PALETTERGB (245, 245, 245) },
712   {"grey96"                     , PALETTERGB (245, 245, 245) },
713   {"gray97"                     , PALETTERGB (247, 247, 247) },
714   {"grey97"                     , PALETTERGB (247, 247, 247) },
715   {"gray98"                     , PALETTERGB (250, 250, 250) },
716   {"grey98"                     , PALETTERGB (250, 250, 250) },
717   {"gray99"                     , PALETTERGB (252, 252, 252) },
718   {"grey99"                     , PALETTERGB (252, 252, 252) },
719   {"gray100"                    , PALETTERGB (255, 255, 255) },
720   {"grey100"                    , PALETTERGB (255, 255, 255) },
721   {"DarkGrey"                   , PALETTERGB (169, 169, 169) },
722   {"DarkGray"                   , PALETTERGB (169, 169, 169) },
723   {"DarkBlue"                   , PALETTERGB (0, 0, 139) },
724   {"DarkCyan"                   , PALETTERGB (0, 139, 139) },
725   {"DarkMagenta"                , PALETTERGB (139, 0, 139) },
726   {"DarkRed"                    , PALETTERGB (139, 0, 0) },
727   {"LightGreen"                 , PALETTERGB (144, 238, 144) }
728 };
729
730
731 typedef struct fontmap_t 
732 {
733   CONST char *name;
734   CONST int value;
735 } fontmap_t;
736
737 /* Default weight first, preferred names listed before synonyms */
738 static CONST fontmap_t fontweight_map[] = 
739 {
740   {"Regular"            , FW_REGULAR},  /* The standard font weight */
741   {"Thin"               , FW_THIN},
742   {"Extra Light"        , FW_EXTRALIGHT},
743   {"Ultra Light"        , FW_ULTRALIGHT},
744   {"Light"              , FW_LIGHT},
745   {"Normal"             , FW_NORMAL},
746   {"Medium"             , FW_MEDIUM},
747   {"Semi Bold"          , FW_SEMIBOLD},
748   {"Demi Bold"          , FW_DEMIBOLD},
749   {"Bold"               , FW_BOLD},     /* The standard bold font weight */
750   {"Extra Bold"         , FW_EXTRABOLD},
751   {"Ultra Bold"         , FW_ULTRABOLD},
752   {"Heavy"              , FW_HEAVY},
753   {"Black"              , FW_BLACK}
754 };
755
756 /* Default charset first, no synonyms allowed because these names are 
757  * matched against the names reported by win32 by match_font() */
758 static CONST fontmap_t charset_map[] = 
759 {
760   {"Western"            , ANSI_CHARSET},
761   {"Symbol"             , SYMBOL_CHARSET},
762   {"Shift JIS"          , SHIFTJIS_CHARSET},    /* #### Name to be verified */
763   {"GB2312"             , GB2312_CHARSET},      /* #### Name to be verified */
764   {"Hanguel"            , HANGEUL_CHARSET},
765   {"Chinese Big 5"      , CHINESEBIG5_CHARSET}, /* #### Name to be verified */
766 #if (WINVER >= 0x0400)
767   {"Johab"              , JOHAB_CHARSET},       /* #### Name to be verified */
768   {"Hebrew"             , HEBREW_CHARSET},      /* #### Name to be verified */
769   {"Arabic"             , ARABIC_CHARSET},      /* #### Name to be verified */
770   {"Greek"              , GREEK_CHARSET},
771   {"Turkish"            , TURKISH_CHARSET},
772   {"Vietnamese"         , VIETNAMESE_CHARSET},  /* #### Name to be verified */
773   {"Thai"               , THAI_CHARSET},        /* #### Name to be verified */
774   {"Central European"   , EASTEUROPE_CHARSET},
775   {"Cyrillic"           , RUSSIAN_CHARSET},
776   {"Mac"                , MAC_CHARSET},
777   {"Baltic"             , BALTIC_CHARSET},
778 #endif
779   {"OEM/DOS"            , OEM_CHARSET}
780 };
781
782 \f
783 /************************************************************************/
784 /*                               helpers                                */
785 /************************************************************************/
786
787 static int
788 hexval (char c) 
789 {
790   /* assumes ASCII and isxdigit(c) */
791   if (c >= 'a')
792     return c-'a' + 10;
793   else if (c >= 'A')
794     return c-'A' + 10;
795   else
796     return c-'0';
797 }
798
799 COLORREF
800 mswindows_string_to_color(CONST char *name)
801 {
802   int i;
803
804   if (*name == '#')
805     {
806       /* numeric names look like "#RRGGBB", "#RRRGGGBBB" or "#RRRRGGGGBBBB"
807          or "rgb:rrrr/gggg/bbbb" */
808       unsigned int r, g, b;
809   
810       for (i=1; i<strlen(name); i++)
811         {
812           if (!isxdigit ((int)name[i]))
813             return (COLORREF) -1;
814         }
815       if (strlen(name)==7)
816         {
817           r = hexval (name[1]) * 16 + hexval (name[2]);
818           g = hexval (name[3]) * 16 + hexval (name[4]);
819           b = hexval (name[5]) * 16 + hexval (name[6]);
820           return (PALETTERGB (r, g, b));
821         }
822       else if (strlen(name)==10)
823         {
824           r = hexval (name[1]) * 16 + hexval (name[2]);
825           g = hexval (name[4]) * 16 + hexval (name[5]);
826           b = hexval (name[7]) * 16 + hexval (name[8]);
827           return (PALETTERGB (r, g, b));
828         }
829       else if (strlen(name)==13)
830         {
831           r = hexval (name[1]) * 16 + hexval (name[2]);
832           g = hexval (name[5]) * 16 + hexval (name[6]);
833           b = hexval (name[9]) * 16 + hexval (name[10]);
834           return (PALETTERGB (r, g, b));
835         }
836     }
837   else if (!strncmp(name, "rgb:", 4))
838     {
839       unsigned int r,g,b;
840
841       if (sscanf(name, "rgb:%04x/%04x/%04x", &r, &g, &b) == 3)
842         {
843           int len = strlen (name);
844           if (len == 18)
845             {
846               r /= 257;
847               g /= 257;
848               b /= 257;
849             }
850           else if (len == 15)
851             {
852               r /= 17;
853               g /= 17;
854               b /= 17;
855             }
856           return (PALETTERGB (r, g, b));
857         }
858       else 
859         return (COLORREF) -1;
860     }
861   else if (*name)       /* Can't be an empty string */
862     {
863       char *nospaces = alloca (strlen (name)+1);
864       char *c=nospaces;
865       while (*name)
866         if (*name != ' ')
867           *(c++) = *(name++);
868         else
869           name++;
870       *c = '\0';
871
872       for (i=0; i< countof (mswindows_X_color_map); i++)
873         if (!stricmp (nospaces, mswindows_X_color_map[i].name))
874           return (mswindows_X_color_map[i].colorref);
875     }
876   return (COLORREF) -1;
877 }
878
879 /*
880  * Returns non-zero if the two supplied font patterns match.
881  * If they match and fontname is not NULL, copies the logical OR of the
882  * patterns to fontname (which is assumed to be at least MSW_FONTSIZE in size).
883  *
884  * The patterns 'match' iff for each field that is not blank in either pattern,
885  * the corresponding field in the other pattern is either identical or blank.
886  */
887 static int
888 match_font (char *pattern1, char *pattern2, char *fontname)
889 {
890   char *c1=pattern1, *c2=pattern2, *e1=0, *e2=0;
891   int i;
892
893   if (fontname)
894     fontname[0] = '\0';
895
896   for (i=0; i<5; i++)
897     {
898       if (c1 && (e1 = strchr (c1, ':')))
899         *(e1) = '\0';
900       if (c2 && (e2 = strchr (c2, ':')))
901         *(e2) = '\0';
902
903       if (c1 && c1[0]!='\0')
904         {
905           if (c2 && c2[0]!='\0' && stricmp(c1, c2))
906             {
907               if (e1) *e1 = ':';
908               if (e2) *e2 = ':';
909               return 0;
910             }
911           else if (fontname)
912             strcat (strcat (fontname, c1), ":");
913         }
914       else if (fontname)
915         {
916           if (c2 && c2[0]!='\0')
917             strcat (strcat (fontname, c2), ":");
918           else
919             strcat (fontname, ":");
920         }
921
922       if (e1) *(e1++) = ':';
923       if (e2) *(e2++) = ':';
924       c1=e1;
925       c2=e2;
926     }
927
928   if (fontname)
929     fontname[strlen (fontname) - 1] = '\0';     /* Trim trailing ':' */
930   return 1;
931 }
932
933
934
935
936 \f
937 /************************************************************************/
938 /*                                 exports                              */
939 /************************************************************************/
940
941 struct font_enum_t
942 {
943   HDC hdc;
944   struct device *d;
945 };
946
947 static int CALLBACK
948 font_enum_callback_2 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, 
949                       int FontType, struct font_enum_t *font_enum)
950 {
951   struct mswindows_font_enum *fontlist, **fonthead;
952   char fontname[MSW_FONTSIZE];
953   int i;
954
955   /*
956    * The enumerated font weights are not to be trusted because:
957    *  a) lpelfe->elfStyle is only filled in for TrueType fonts.
958    *  b) Not all Bold and Italic styles of all fonts (inluding some Vector,
959    *     Truetype and Raster fonts) are enumerated.
960    * I guess that fonts for which Bold and Italic styles are generated
961    * 'on-the-fly' are not enumerated. It would be overly restrictive to
962    * disallow Bold And Italic weights for these fonts, so we just leave
963    * weights unspecified. This means that we have to weed out duplicates of
964    * those fonts that do get enumerated with different weights.
965    */
966   if (FontType == 0 /*vector*/ || FontType == TRUETYPE_FONTTYPE)
967     /* Scalable, so leave pointsize blank */
968     sprintf (fontname, "%s::::", lpelfe->elfLogFont.lfFaceName);
969   else
970     /* Formula for pointsize->height from LOGFONT docs in Platform SDK */
971     sprintf (fontname, "%s::%d::", lpelfe->elfLogFont.lfFaceName,
972              MulDiv (lpntme->ntmTm.tmHeight - lpntme->ntmTm.tmInternalLeading,
973                      72, DEVICE_MSWINDOWS_LOGPIXELSY (font_enum->d)));
974
975   /*
976    * The enumerated font character set strings are not to be trusted because
977    * lpelfe->elfScript is returned in the host language and not in English.
978    * We can't know a priori the translations of "Western", "Central European"
979    * etc into the host language, so we must use English. The same argument
980    * applies to the font weight string when matching fonts.
981    */
982   for (i=0; i<countof (charset_map); i++)
983     if (lpelfe->elfLogFont.lfCharSet == charset_map[i].value)
984       {
985         strcat (fontname, charset_map[i].name);
986         break;
987       }
988   if (i==countof (charset_map))
989     strcpy (fontname, charset_map[0].name);
990
991   /* Check that the new font is not a duplicate */
992   fonthead = &DEVICE_MSWINDOWS_FONTLIST (font_enum->d);
993   fontlist = *fonthead;
994   while (fontlist)
995     if (!strcmp (fontname, fontlist->fontname))
996       return 1;         /* found a duplicate */
997     else
998       fontlist = fontlist->next;
999
1000   /* Insert entry at head */
1001   fontlist = *fonthead;
1002   *fonthead = xmalloc (sizeof (struct mswindows_font_enum));
1003   if (*fonthead == NULL)
1004     {
1005       *fonthead = fontlist;
1006       return 0;
1007     }
1008   strcpy ((*fonthead)->fontname, fontname);
1009   (*fonthead)->next = fontlist;
1010   return 1;
1011 }
1012
1013 static int CALLBACK
1014 font_enum_callback_1 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, 
1015                       int FontType, struct font_enum_t *font_enum)
1016 {
1017   /* This function gets called once per facename per character set.
1018    * We call a second callback to enumerate the fonts in each facename */
1019   return EnumFontFamiliesEx (font_enum->hdc, &lpelfe->elfLogFont,
1020                              (FONTENUMPROC) font_enum_callback_2,
1021                              (LPARAM) font_enum, 0);
1022 }
1023
1024 /*
1025  * Enumerate the available fonts. Called by mswindows_init_device().
1026  * Fills in the device's device-type-specfic fontlist.
1027  */
1028 void
1029 mswindows_enumerate_fonts (struct device *d)
1030 {
1031   HDC hdc = CreateCompatibleDC (NULL);
1032   LOGFONT logfont;
1033   struct font_enum_t font_enum;
1034
1035   assert (hdc!=NULL);
1036   logfont.lfCharSet = DEFAULT_CHARSET;
1037   logfont.lfFaceName[0] = '\0';
1038   logfont.lfPitchAndFamily = DEFAULT_PITCH;
1039   font_enum.hdc = hdc;
1040   font_enum.d = d;
1041   DEVICE_MSWINDOWS_FONTLIST (d) = NULL;
1042   EnumFontFamiliesEx (hdc, &logfont, (FONTENUMPROC) font_enum_callback_1,
1043                       (LPARAM) (&font_enum), 0);
1044   DeleteDC (hdc);
1045 }
1046
1047 \f
1048 /************************************************************************/
1049 /*                               methods                                */
1050 /************************************************************************/
1051
1052 static int
1053 mswindows_initialize_color_instance (struct Lisp_Color_Instance *c, Lisp_Object name,
1054                                Lisp_Object device, Error_behavior errb)
1055 {
1056   CONST char *extname;
1057   COLORREF color;
1058
1059   GET_C_STRING_CTEXT_DATA_ALLOCA (name, extname);
1060   color = mswindows_string_to_color(extname);
1061   if (color != -1)
1062     {
1063       c->data = xnew (struct mswindows_color_instance_data);
1064       COLOR_INSTANCE_MSWINDOWS_COLOR (c) = color;
1065       return 1;
1066     }
1067   maybe_signal_simple_error ("Unrecognized color", name, Qcolor, errb);
1068   return(0);
1069 }
1070
1071 #if 0
1072 static void
1073 mswindows_mark_color_instance (struct Lisp_Color_Instance *c,
1074                          void (*markobj) (Lisp_Object))
1075 {
1076 }
1077 #endif
1078
1079 static void
1080 mswindows_print_color_instance (struct Lisp_Color_Instance *c,
1081                           Lisp_Object printcharfun,
1082                           int escapeflag)
1083 {
1084   char buf[32];
1085   COLORREF color = COLOR_INSTANCE_MSWINDOWS_COLOR (c);
1086   sprintf (buf, " %06ld=(%04X,%04X,%04X)", color & 0xffffff,
1087            GetRValue(color)*257, GetGValue(color)*257, GetBValue(color)*257);
1088   write_c_string (buf, printcharfun);
1089 }
1090
1091 static void
1092 mswindows_finalize_color_instance (struct Lisp_Color_Instance *c)
1093 {
1094   if (c->data)
1095     {
1096       xfree (c->data);
1097       c->data = 0;
1098     }
1099 }
1100
1101 static int
1102 mswindows_color_instance_equal (struct Lisp_Color_Instance *c1,
1103                           struct Lisp_Color_Instance *c2,
1104                           int depth)
1105 {
1106   return (COLOR_INSTANCE_MSWINDOWS_COLOR(c1) == COLOR_INSTANCE_MSWINDOWS_COLOR(c2));
1107 }
1108
1109 static unsigned long
1110 mswindows_color_instance_hash (struct Lisp_Color_Instance *c, int depth)
1111 {
1112   return (unsigned long)(COLOR_INSTANCE_MSWINDOWS_COLOR(c));
1113 }
1114
1115 static Lisp_Object
1116 mswindows_color_instance_rgb_components (struct Lisp_Color_Instance *c)
1117 {
1118   COLORREF color = COLOR_INSTANCE_MSWINDOWS_COLOR (c);
1119   return list3 (make_int (GetRValue (color) * 257),
1120                 make_int (GetGValue (color) * 257),
1121                 make_int (GetBValue (color) * 257));
1122 }
1123
1124 static int
1125 mswindows_valid_color_name_p (struct device *d, Lisp_Object color)
1126 {
1127   CONST char *extname;
1128
1129   GET_C_STRING_CTEXT_DATA_ALLOCA (color, extname);
1130   return (mswindows_string_to_color(extname)!=-1);
1131 }
1132
1133
1134 \f
1135 static void
1136 mswindows_finalize_font_instance (struct Lisp_Font_Instance *f)
1137 {
1138   if (f->data)
1139     {
1140       DeleteObject(f->data);
1141       f->data=0;
1142     }
1143 }
1144
1145
1146 static int
1147 mswindows_initialize_font_instance (struct Lisp_Font_Instance *f, Lisp_Object name,
1148                                     Lisp_Object device, Error_behavior errb)
1149 {
1150   CONST char *extname;
1151   LOGFONT logfont;
1152   int fields, i;
1153   int pt;
1154   char fontname[LF_FACESIZE], weight[LF_FACESIZE], *style, points[8];
1155   char effects[LF_FACESIZE], charset[LF_FACESIZE];
1156   char *c;
1157   HDC hdc;
1158   HFONT holdfont;
1159   TEXTMETRIC metrics;
1160
1161   extname = XSTRING_DATA (name);
1162
1163   /*
1164    * mswindows fonts look like:
1165    *    fontname[:[weight ][style][:pointsize[:effects]]][:charset]
1166    * The font name field shouldn't be empty.
1167    *
1168    * ie:
1169    *    Lucida Console:Regular:10
1170    * minimal:
1171    *    Courier New
1172    * maximal:
1173    *    Courier New:Bold Italic:10:underline strikeout:western
1174    */
1175
1176   fields = sscanf (extname, "%31[^:]:%31[^:]:%7[^:]:%31[^:]:%31s",
1177                    fontname, weight, points, effects, charset);
1178
1179   /* This function is implemented in a fairly ad-hoc manner.
1180    * The general idea is to validate and canonicalize each of the above fields
1181    * at the same time as we build up the win32 LOGFONT structure. This enables
1182    * us to use match_font() on a canonicalized font string to check the
1183    * availability of the requested font */
1184
1185   if (fields < 0)
1186   {
1187     maybe_signal_simple_error ("Invalid font", name, Qfont, errb);
1188     return (0);
1189   }
1190
1191   if (fields>0 && strlen(fontname))
1192   {
1193     strncpy (logfont.lfFaceName, fontname, LF_FACESIZE);
1194     logfont.lfFaceName[LF_FACESIZE-1] = 0;
1195   }
1196   else
1197   {
1198     maybe_signal_simple_error ("Must specify a font name", name, Qfont, errb);
1199     return (0);
1200   }
1201
1202   /* weight */
1203   if (fields < 2)
1204     strcpy (weight, fontweight_map[0].name);
1205
1206   /* Maybe split weight into weight and style */
1207   if ((c=strchr(weight, ' ')))
1208   {
1209     *c = '\0';
1210     style = c+1;
1211   }
1212   else
1213     style = NULL;
1214
1215   for (i=0; i<countof (fontweight_map); i++)
1216     if (!stricmp (weight, fontweight_map[i].name))
1217       { 
1218         logfont.lfWeight = fontweight_map[i].value;
1219         break;
1220       }
1221   if (i == countof (fontweight_map))    /* No matching weight */
1222     {
1223       if (!style)
1224         {
1225           logfont.lfWeight = FW_REGULAR;
1226           style = weight;       /* May have specified style without weight */
1227         }
1228       else
1229         {
1230           maybe_signal_simple_error ("Invalid font weight", name, Qfont, errb);
1231           return (0);
1232         }
1233     }
1234
1235   if (style)
1236     {
1237       /* #### what about oblique? */
1238       if (stricmp (style,"italic") == 0)
1239         logfont.lfItalic = TRUE;
1240       else
1241       {
1242         maybe_signal_simple_error ("Invalid font weight or style", name, Qfont, errb);
1243         return (0);
1244       }
1245
1246       /* Glue weight and style together again */
1247       if (weight != style)
1248         *c = ' ';
1249     }
1250   else
1251     logfont.lfItalic = FALSE;
1252
1253   if (fields < 3)
1254     pt = 10;    /* #### Should we reject strings that don't specify a size? */
1255   else if ((pt=atoi(points)) == 0)
1256     {
1257       maybe_signal_simple_error ("Invalid font pointsize", name, Qfont, errb);
1258       return (0);
1259     }
1260
1261   /* Formula for pointsize->height from LOGFONT docs in MSVC5 Platform SDK */
1262   logfont.lfHeight = -MulDiv(pt, DEVICE_MSWINDOWS_LOGPIXELSY (XDEVICE (device)), 72);
1263   logfont.lfWidth = 0;
1264
1265   /* Effects */
1266   logfont.lfUnderline = FALSE;
1267   logfont.lfStrikeOut = FALSE;
1268   if (fields >= 4 && effects[0] != '\0')
1269     {
1270       char *effects2;
1271
1272       /* Maybe split effects into effects and effects2 */
1273       if ((c=strchr (effects, ' ')))
1274         {
1275           *c = '\0';
1276           effects2 = c+1;
1277         }
1278       else
1279         effects2 = NULL;
1280
1281       if (stricmp (effects, "underline") == 0)
1282         logfont.lfUnderline = TRUE;
1283       else if (stricmp (effects, "strikeout") == 0)
1284         logfont.lfStrikeOut = TRUE;
1285       else
1286         {
1287           maybe_signal_simple_error ("Invalid font effect", name, Qfont, errb);
1288           return (0);
1289         }
1290
1291       if (effects2 && effects2[0] != '\0')
1292         {
1293           if (stricmp (effects2, "underline") == 0)
1294             logfont.lfUnderline = TRUE;
1295           else if (stricmp (effects2, "strikeout") == 0)
1296             logfont.lfStrikeOut = TRUE;
1297           else
1298             {
1299               maybe_signal_simple_error ("Invalid font effect", name,
1300                                          Qfont, errb);
1301               return (0);
1302             }
1303         }
1304
1305       /* Regenerate sanitised effects string */
1306       if (logfont.lfUnderline)
1307         {
1308           if (logfont.lfStrikeOut)
1309             strcpy (effects, "underline strikeout");
1310           else
1311             strcpy (effects, "underline");
1312         }
1313       else if (logfont.lfStrikeOut)
1314         strcpy (effects, "strikeout");
1315     }
1316   else
1317     effects[0] = '\0';
1318
1319   /* Charset */
1320   /* charset can be specified even if earlier fields havn't been */
1321   if (fields < 5)
1322     {
1323       if ((c=strchr (extname, ':')) && (c=strchr (c+1, ':')) &&
1324           (c=strchr (c+1, ':')) && (c=strchr (c+1, ':')))
1325         {
1326           strncpy (charset, c+1, LF_FACESIZE);
1327           charset[LF_FACESIZE-1] = '\0';
1328         }
1329       else
1330         strcpy (charset, charset_map[0].name);
1331     }
1332
1333   for (i=0; i<countof (charset_map); i++)
1334     if (!stricmp (charset, charset_map[i].name))
1335       {
1336         logfont.lfCharSet = charset_map[i].value;
1337         break;
1338       }
1339
1340   if (i == countof (charset_map))       /* No matching charset */
1341     {
1342       maybe_signal_simple_error ("Invalid charset", name, Qfont, errb);
1343       return 0;
1344     }
1345
1346   /* Misc crud */
1347   logfont.lfEscapement = logfont.lfOrientation = 0;
1348 #if 1
1349   logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
1350   logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1351   logfont.lfQuality = DEFAULT_QUALITY;
1352 #else
1353   logfont.lfOutPrecision = OUT_STROKE_PRECIS;
1354   logfont.lfClipPrecision = CLIP_STROKE_PRECIS;
1355   logfont.lfQuality = PROOF_QUALITY;
1356 #endif
1357   /* Default to monospaced if the specified fontname doesn't exist. */
1358   logfont.lfPitchAndFamily = FF_MODERN;
1359
1360   /* Windows will silently substitute a default font if the fontname 
1361    * specifies a non-existent font. So we check the font against the device's
1362    * list of font patterns to make sure that at least one of them matches. */
1363   {
1364     struct mswindows_font_enum *fontlist;
1365     char truename[MSW_FONTSIZE];
1366     int done = 0;
1367     
1368     sprintf (truename, "%s:%s:%d:%s:%s", fontname, weight, pt, effects, charset);
1369     fontlist = DEVICE_MSWINDOWS_FONTLIST (XDEVICE (device));
1370     while (fontlist && !done)
1371       {
1372         done = match_font (fontlist->fontname, truename, NULL);
1373         fontlist = fontlist->next;
1374       }
1375     if (!done)
1376       {
1377         maybe_signal_simple_error ("No matching font", name, Qfont, errb);
1378         return 0;
1379       }
1380   }
1381
1382   if ((f->data = CreateFontIndirect(&logfont)) == NULL)
1383   {
1384     maybe_signal_simple_error ("Couldn't create font", name, Qfont, errb);
1385     return 0;
1386   }
1387
1388   hdc = CreateCompatibleDC (NULL);
1389   if (hdc)
1390     {
1391       holdfont = SelectObject(hdc, f->data);
1392       if (holdfont)
1393         {
1394           GetTextMetrics (hdc, &metrics);
1395           SelectObject(hdc, holdfont);
1396           DeleteDC (hdc);
1397           f->width = (unsigned short) metrics.tmAveCharWidth;
1398           f->height = (unsigned short) metrics.tmHeight;
1399           f->ascent = (unsigned short) metrics.tmAscent;
1400           f->descent = (unsigned short) metrics.tmDescent;
1401           f->proportional_p = (metrics.tmPitchAndFamily & TMPF_FIXED_PITCH);
1402           return 1;
1403         }
1404       DeleteDC (hdc);
1405     }
1406   mswindows_finalize_font_instance (f);
1407   maybe_signal_simple_error ("Couldn't map font", name, Qfont, errb);
1408   return 0;
1409 }
1410
1411 #if 0
1412 static void
1413 mswindows_mark_font_instance (struct Lisp_Font_Instance *f,
1414                         void (*markobj) (Lisp_Object))
1415 {
1416 }
1417 #endif
1418
1419 static void
1420 mswindows_print_font_instance (struct Lisp_Font_Instance *f,
1421                          Lisp_Object printcharfun,
1422                          int escapeflag)
1423 {
1424 }
1425
1426 static Lisp_Object
1427 mswindows_list_fonts (Lisp_Object pattern, Lisp_Object device)
1428 {
1429   Lisp_Object result = Qnil;
1430   struct mswindows_font_enum *fontlist;
1431   char fontname[MSW_FONTSIZE], *extpattern;
1432
1433   GET_C_STRING_CTEXT_DATA_ALLOCA (pattern, extpattern);
1434   fontlist = DEVICE_MSWINDOWS_FONTLIST (XDEVICE (device));
1435   while (fontlist)
1436     {
1437       if (match_font (fontlist->fontname, extpattern, fontname))
1438          result = Fcons (build_string (fontname), result);
1439       fontlist = fontlist->next;
1440     }
1441
1442   return Fnreverse (result);
1443 }
1444
1445 /* Fill in missing parts of a font spec. This is primarily intended as a
1446  * helper function for the functions below.
1447  * mswindows fonts look like:
1448  *      fontname[:[weight][ style][:pointsize[:effects]]][:charset]
1449  * A minimal mswindows font spec looks like:
1450  *      Courier New
1451  * A maximal mswindows font spec looks like:
1452  *      Courier New:Bold Italic:10:underline strikeout:Western
1453  * Missing parts of the font spec should be filled in with these values:
1454  *      Courier New:Regular:10::Western */
1455 static Lisp_Object
1456 mswindows_font_instance_truename (struct Lisp_Font_Instance *f, Error_behavior errb)
1457 {
1458   int nsep=0;
1459   char *name = (char *) XSTRING_DATA (f->name);
1460   char* ptr = name;
1461   char* extname = alloca (strlen (name) + 19);
1462   strcpy (extname, name);
1463
1464   while ((ptr = strchr (ptr, ':')) != 0)
1465     {
1466       ptr++;
1467       nsep++;
1468     }
1469
1470   switch (nsep)
1471     {
1472     case 0:
1473       strcat (extname, ":Regular:10::Western");
1474       break;
1475     case 1:
1476       strcat (extname, ":10::Western");
1477       break;
1478     case 2:
1479       strcat (extname, "::Western");
1480       break;
1481     case 3:
1482       strcat (extname, ":Western");
1483       break;
1484     default:;
1485     }
1486   
1487   return build_ext_string (extname, FORMAT_OS);
1488 }
1489
1490 #ifdef MULE
1491
1492 static int
1493 mswindows_font_spec_matches_charset (struct device *d, Lisp_Object charset,
1494                              CONST Bufbyte *nonreloc, Lisp_Object reloc,
1495                              Bytecount offset, Bytecount length)
1496 {
1497   /* #### Implement me */
1498   if (UNBOUNDP (charset))
1499     return 1;
1500   
1501   return 1;
1502 }
1503
1504 /* find a font spec that matches font spec FONT and also matches
1505    (the registry of) CHARSET. */
1506 static Lisp_Object
1507 mswindows_find_charset_font (Lisp_Object device, Lisp_Object font,
1508                      Lisp_Object charset)
1509 {
1510   /* #### Implement me */
1511   return build_string ("Courier New:Regular:10");
1512 }
1513
1514 #endif /* MULE */
1515
1516 \f
1517 /************************************************************************/
1518 /*                             non-methods                              */
1519 /************************************************************************/
1520
1521 DEFUN ("mswindows-color-list", Fmswindows_color_list, 0, 0, 0, /*
1522 Return a list of the colors available on mswindows devices.
1523 */
1524        ())
1525 {
1526   Lisp_Object result = Qnil;
1527   int i;
1528
1529   for (i=0; i<countof (mswindows_X_color_map); i++)
1530     result = Fcons (build_string (mswindows_X_color_map[i].name), result);
1531
1532   return Fnreverse (result);
1533 }
1534
1535
1536 \f
1537 /************************************************************************/
1538 /*                            initialization                            */
1539 /************************************************************************/
1540
1541 void
1542 syms_of_objects_mswindows (void)
1543 {
1544   DEFSUBR (Fmswindows_color_list);
1545 }
1546
1547 void
1548 console_type_create_objects_mswindows (void)
1549 {
1550   /* object methods */
1551   CONSOLE_HAS_METHOD (mswindows, initialize_color_instance);
1552 /*  CONSOLE_HAS_METHOD (mswindows, mark_color_instance); */
1553   CONSOLE_HAS_METHOD (mswindows, print_color_instance);
1554   CONSOLE_HAS_METHOD (mswindows, finalize_color_instance);
1555   CONSOLE_HAS_METHOD (mswindows, color_instance_equal);
1556   CONSOLE_HAS_METHOD (mswindows, color_instance_hash);
1557   CONSOLE_HAS_METHOD (mswindows, color_instance_rgb_components);
1558   CONSOLE_HAS_METHOD (mswindows, valid_color_name_p);
1559
1560   CONSOLE_HAS_METHOD (mswindows, initialize_font_instance);
1561 /*  CONSOLE_HAS_METHOD (mswindows, mark_font_instance); */
1562   CONSOLE_HAS_METHOD (mswindows, print_font_instance);
1563   CONSOLE_HAS_METHOD (mswindows, finalize_font_instance);
1564   CONSOLE_HAS_METHOD (mswindows, font_instance_truename); 
1565   CONSOLE_HAS_METHOD (mswindows, list_fonts);
1566 #ifdef MULE
1567   CONSOLE_HAS_METHOD (mswindows, font_spec_matches_charset);
1568   CONSOLE_HAS_METHOD (mswindows, find_charset_font);
1569 #endif
1570 }
1571
1572 void
1573 vars_of_objects_mswindows (void)
1574 {
1575 }