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