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