~ubuntu-branches/ubuntu/jaunty/texlive-bin/jaunty

« back to all changes in this revision

Viewing changes to build/source/texk/windvi/winxutl.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2008-06-26 23:14:59 UTC
  • mfrom: (2.1.30 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080626231459-y02rjsrgtafu83yr
Tags: 2007.dfsg.2-3
add missing source roadmap.fig of roadmap.eps in fontinst documentation
(Closes: #482915) (urgency medium due to RC bug)
(new patch add-missing-fontinst-source)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <windows.h>
 
2
#include <commdlg.h>
 
3
#include "wingui.h"
 
4
#include "xdvi-config.h"
 
5
 
 
6
#include "winxutl.h"
 
7
 
 
8
#define _TRACE 0
 
9
 
 
10
RGBQUAD QuadWhite = { 255, 255, 255, 0};
 
11
RGBQUAD QuadBlack = {   0,   0,   0, 0};
 
12
 
 
13
colormap_t win32_color_map[] = 
 
14
{
 
15
  {"snow"                      , MYRGB (255,250,250)},
 
16
  {"ghost white"               , MYRGB (248,248,255)},
 
17
  {"GhostWhite"                , MYRGB (248,248,255)},
 
18
  {"white smoke"               , MYRGB (245,245,245)},
 
19
  {"WhiteSmoke"                , MYRGB (245,245,245)},
 
20
  {"gainsboro"                 , MYRGB (220,220,220)},
 
21
  {"floral white"              , MYRGB (255,250,240)},
 
22
  {"FloralWhite"               , MYRGB (255,250,240)},
 
23
  {"old lace"                  , MYRGB (253,245,230)},
 
24
  {"OldLace"                   , MYRGB (253,245,230)},
 
25
  {"linen"                     , MYRGB (250,240,230)},
 
26
  {"antique white"             , MYRGB (250,235,215)},
 
27
  {"AntiqueWhite"              , MYRGB (250,235,215)},
 
28
  {"papaya whip"               , MYRGB (255,239,213)},
 
29
  {"PapayaWhip"                , MYRGB (255,239,213)},
 
30
  {"blanched almond"           , MYRGB (255,235,205)},
 
31
  {"BlanchedAlmond"            , MYRGB (255,235,205)},
 
32
  {"bisque"                    , MYRGB (255,228,196)},
 
33
  {"peach puff"                , MYRGB (255,218,185)},
 
34
  {"PeachPuff"                 , MYRGB (255,218,185)},
 
35
  {"navajo white"              , MYRGB (255,222,173)},
 
36
  {"NavajoWhite"               , MYRGB (255,222,173)},
 
37
  {"moccasin"                  , MYRGB (255,228,181)},
 
38
  {"cornsilk"                  , MYRGB (255,248,220)},
 
39
  {"ivory"                     , MYRGB (255,255,240)},
 
40
  {"lemon chiffon"             , MYRGB (255,250,205)},
 
41
  {"LemonChiffon"              , MYRGB (255,250,205)},
 
42
  {"seashell"                  , MYRGB (255,245,238)},
 
43
  {"honeydew"                  , MYRGB (240,255,240)},
 
44
  {"mint cream"                , MYRGB (245,255,250)},
 
45
  {"MintCream"                 , MYRGB (245,255,250)},
 
46
  {"azure"                     , MYRGB (240,255,255)},
 
47
  {"alice blue"                , MYRGB (240,248,255)},
 
48
  {"AliceBlue"                 , MYRGB (240,248,255)},
 
49
  {"lavender"                  , MYRGB (230,230,250)},
 
50
  {"lavender blush"            , MYRGB (255,240,245)},
 
51
  {"LavenderBlush"             , MYRGB (255,240,245)},
 
52
  {"misty rose"                , MYRGB (255,228,225)},
 
53
  {"MistyRose"                 , MYRGB (255,228,225)},
 
54
  {"white"                     , MYRGB (255,255,255)},
 
55
  {"black"                     , MYRGB (  0,  0,  0)},
 
56
  {"dark slate gray"           , MYRGB ( 47, 79, 79)},
 
57
  {"DarkSlateGray"             , MYRGB ( 47, 79, 79)},
 
58
  {"dark slate grey"           , MYRGB ( 47, 79, 79)},
 
59
  {"DarkSlateGrey"             , MYRGB ( 47, 79, 79)},
 
60
  {"dim gray"                  , MYRGB (105,105,105)},
 
61
  {"DimGray"                   , MYRGB (105,105,105)},
 
62
  {"dim grey"                  , MYRGB (105,105,105)},
 
63
  {"DimGrey"                   , MYRGB (105,105,105)},
 
64
  {"slate gray"                , MYRGB (112,128,144)},
 
65
  {"SlateGray"                 , MYRGB (112,128,144)},
 
66
  {"slate grey"                , MYRGB (112,128,144)},
 
67
  {"SlateGrey"                 , MYRGB (112,128,144)},
 
68
  {"light slate gray"          , MYRGB (119,136,153)},
 
69
  {"LightSlateGray"            , MYRGB (119,136,153)},
 
70
  {"light slate grey"          , MYRGB (119,136,153)},
 
71
  {"LightSlateGrey"            , MYRGB (119,136,153)},
 
72
  {"gray"                      , MYRGB (190,190,190)},
 
73
  {"grey"                      , MYRGB (190,190,190)},
 
74
  {"light grey"                , MYRGB (211,211,211)},
 
75
  {"LightGrey"                 , MYRGB (211,211,211)},
 
76
  {"light gray"                , MYRGB (211,211,211)},
 
77
  {"LightGray"                 , MYRGB (211,211,211)},
 
78
  {"midnight blue"             , MYRGB ( 25, 25,112)},
 
79
  {"MidnightBlue"              , MYRGB ( 25, 25,112)},
 
80
  {"navy"                      , MYRGB (  0,  0,128)},
 
81
  {"navy blue"                 , MYRGB (  0,  0,128)},
 
82
  {"NavyBlue"                  , MYRGB (  0,  0,128)},
 
83
  {"cornflower blue"           , MYRGB (100,149,237)},
 
84
  {"CornflowerBlue"            , MYRGB (100,149,237)},
 
85
  {"dark slate blue"           , MYRGB ( 72, 61,139)},
 
86
  {"DarkSlateBlue"             , MYRGB ( 72, 61,139)},
 
87
  {"slate blue"                , MYRGB (106, 90,205)},
 
88
  {"SlateBlue"                 , MYRGB (106, 90,205)},
 
89
  {"medium slate blue"         , MYRGB (123,104,238)},
 
90
  {"MediumSlateBlue"           , MYRGB (123,104,238)},
 
91
  {"light slate blue"          , MYRGB (132,112,255)},
 
92
  {"LightSlateBlue"            , MYRGB (132,112,255)},
 
93
  {"medium blue"               , MYRGB (  0,  0,205)},
 
94
  {"MediumBlue"                , MYRGB (  0,  0,205)},
 
95
  {"royal blue"                , MYRGB ( 65,105,225)},
 
96
  {"RoyalBlue"                 , MYRGB ( 65,105,225)},
 
97
  {"blue"                      , MYRGB (  0,  0,255)},
 
98
  {"dodger blue"               , MYRGB ( 30,144,255)},
 
99
  {"DodgerBlue"                , MYRGB ( 30,144,255)},
 
100
  {"deep sky blue"             , MYRGB (  0,191,255)},
 
101
  {"DeepSkyBlue"               , MYRGB (  0,191,255)},
 
102
  {"sky blue"                  , MYRGB (135,206,235)},
 
103
  {"SkyBlue"                   , MYRGB (135,206,235)},
 
104
  {"light sky blue"            , MYRGB (135,206,250)},
 
105
  {"LightSkyBlue"              , MYRGB (135,206,250)},
 
106
  {"steel blue"                , MYRGB ( 70,130,180)},
 
107
  {"SteelBlue"                 , MYRGB ( 70,130,180)},
 
108
  {"light steel blue"          , MYRGB (176,196,222)},
 
109
  {"LightSteelBlue"            , MYRGB (176,196,222)},
 
110
  {"light blue"                , MYRGB (173,216,230)},
 
111
  {"LightBlue"                 , MYRGB (173,216,230)},
 
112
  {"powder blue"               , MYRGB (176,224,230)},
 
113
  {"PowderBlue"                , MYRGB (176,224,230)},
 
114
  {"pale turquoise"            , MYRGB (175,238,238)},
 
115
  {"PaleTurquoise"             , MYRGB (175,238,238)},
 
116
  {"dark turquoise"            , MYRGB (  0,206,209)},
 
117
  {"DarkTurquoise"             , MYRGB (  0,206,209)},
 
118
  {"medium turquoise"          , MYRGB ( 72,209,204)},
 
119
  {"MediumTurquoise"           , MYRGB ( 72,209,204)},
 
120
  {"turquoise"                 , MYRGB ( 64,224,208)},
 
121
  {"cyan"                      , MYRGB (  0,255,255)},
 
122
  {"light cyan"                , MYRGB (224,255,255)},
 
123
  {"LightCyan"                 , MYRGB (224,255,255)},
 
124
  {"cadet blue"                , MYRGB ( 95,158,160)},
 
125
  {"CadetBlue"                 , MYRGB ( 95,158,160)},
 
126
  {"medium aquamarine"         , MYRGB (102,205,170)},
 
127
  {"MediumAquamarine"          , MYRGB (102,205,170)},
 
128
  {"aquamarine"                , MYRGB (127,255,212)},
 
129
  {"dark green"                , MYRGB (  0,100,  0)},
 
130
  {"DarkGreen"                 , MYRGB (  0,100,  0)},
 
131
  {"dark olive green"          , MYRGB ( 85,107, 47)},
 
132
  {"DarkOliveGreen"            , MYRGB ( 85,107, 47)},
 
133
  {"dark sea green"            , MYRGB (143,188,143)},
 
134
  {"DarkSeaGreen"              , MYRGB (143,188,143)},
 
135
  {"sea green"                 , MYRGB ( 46,139, 87)},
 
136
  {"SeaGreen"                  , MYRGB ( 46,139, 87)},
 
137
  {"medium sea green"          , MYRGB ( 60,179,113)},
 
138
  {"MediumSeaGreen"            , MYRGB ( 60,179,113)},
 
139
  {"light sea green"           , MYRGB ( 32,178,170)},
 
140
  {"LightSeaGreen"             , MYRGB ( 32,178,170)},
 
141
  {"pale green"                , MYRGB (152,251,152)},
 
142
  {"PaleGreen"                 , MYRGB (152,251,152)},
 
143
  {"spring green"              , MYRGB (  0,255,127)},
 
144
  {"SpringGreen"               , MYRGB (  0,255,127)},
 
145
  {"lawn green"                , MYRGB (124,252,  0)},
 
146
  {"LawnGreen"                 , MYRGB (124,252,  0)},
 
147
  {"green"                     , MYRGB (  0,255,  0)},
 
148
  {"chartreuse"                , MYRGB (127,255,  0)},
 
149
  {"medium spring green"       , MYRGB (  0,250,154)},
 
150
  {"MediumSpringGreen"         , MYRGB (  0,250,154)},
 
151
  {"green yellow"              , MYRGB (173,255, 47)},
 
152
  {"GreenYellow"               , MYRGB (173,255, 47)},
 
153
  {"lime green"                , MYRGB ( 50,205, 50)},
 
154
  {"LimeGreen"                 , MYRGB ( 50,205, 50)},
 
155
  {"yellow green"              , MYRGB (154,205, 50)},
 
156
  {"YellowGreen"               , MYRGB (154,205, 50)},
 
157
  {"forest green"              , MYRGB ( 34,139, 34)},
 
158
  {"ForestGreen"               , MYRGB ( 34,139, 34)},
 
159
  {"olive drab"                , MYRGB (107,142, 35)},
 
160
  {"OliveDrab"                 , MYRGB (107,142, 35)},
 
161
  {"dark khaki"                , MYRGB (189,183,107)},
 
162
  {"DarkKhaki"                 , MYRGB (189,183,107)},
 
163
  {"khaki"                     , MYRGB (240,230,140)},
 
164
  {"pale goldenrod"            , MYRGB (238,232,170)},
 
165
  {"PaleGoldenrod"             , MYRGB (238,232,170)},
 
166
  {"light goldenrod yellow"    , MYRGB (250,250,210)},
 
167
  {"LightGoldenrodYellow"      , MYRGB (250,250,210)},
 
168
  {"light yellow"              , MYRGB (255,255,224)},
 
169
  {"LightYellow"               , MYRGB (255,255,224)},
 
170
  {"yellow"                    , MYRGB (255,255,  0)},
 
171
  {"gold"                      , MYRGB (255,215,  0)},
 
172
  {"light goldenrod"           , MYRGB (238,221,130)},
 
173
  {"LightGoldenrod"            , MYRGB (238,221,130)},
 
174
  {"goldenrod"                 , MYRGB (218,165, 32)},
 
175
  {"dark goldenrod"            , MYRGB (184,134, 11)},
 
176
  {"DarkGoldenrod"             , MYRGB (184,134, 11)},
 
177
  {"rosy brown"                , MYRGB (188,143,143)},
 
178
  {"RosyBrown"                 , MYRGB (188,143,143)},
 
179
  {"indian red"                , MYRGB (205, 92, 92)},
 
180
  {"IndianRed"                 , MYRGB (205, 92, 92)},
 
181
  {"saddle brown"              , MYRGB (139, 69, 19)},
 
182
  {"SaddleBrown"               , MYRGB (139, 69, 19)},
 
183
  {"sienna"                    , MYRGB (160, 82, 45)},
 
184
  {"peru"                      , MYRGB (205,133, 63)},
 
185
  {"burlywood"                 , MYRGB (222,184,135)},
 
186
  {"beige"                     , MYRGB (245,245,220)},
 
187
  {"wheat"                     , MYRGB (245,222,179)},
 
188
  {"sandy brown"               , MYRGB (244,164, 96)},
 
189
  {"SandyBrown"                , MYRGB (244,164, 96)},
 
190
  {"tan"                       , MYRGB (210,180,140)},
 
191
  {"chocolate"                 , MYRGB (210,105, 30)},
 
192
  {"firebrick"                 , MYRGB (178,34, 34)},
 
193
  {"brown"                     , MYRGB (165,42, 42)},
 
194
  {"dark salmon"               , MYRGB (233,150,122)},
 
195
  {"DarkSalmon"                , MYRGB (233,150,122)},
 
196
  {"salmon"                    , MYRGB (250,128,114)},
 
197
  {"light salmon"              , MYRGB (255,160,122)},
 
198
  {"LightSalmon"               , MYRGB (255,160,122)},
 
199
  {"orange"                    , MYRGB (255,165,  0)},
 
200
  {"dark orange"               , MYRGB (255,140,  0)},
 
201
  {"DarkOrange"                , MYRGB (255,140,  0)},
 
202
  {"coral"                     , MYRGB (255,127, 80)},
 
203
  {"light coral"               , MYRGB (240,128,128)},
 
204
  {"LightCoral"                , MYRGB (240,128,128)},
 
205
  {"tomato"                    , MYRGB (255, 99, 71)},
 
206
  {"orange red"                , MYRGB (255, 69,  0)},
 
207
  {"OrangeRed"                 , MYRGB (255, 69,  0)},
 
208
  {"red"                       , MYRGB (255,  0,  0)},
 
209
  {"hot pink"                  , MYRGB (255,105,180)},
 
210
  {"HotPink"                   , MYRGB (255,105,180)},
 
211
  {"deep pink"                 , MYRGB (255, 20,147)},
 
212
  {"DeepPink"                  , MYRGB (255, 20,147)},
 
213
  {"pink"                      , MYRGB (255,192,203)},
 
214
  {"light pink"                , MYRGB (255,182,193)},
 
215
  {"LightPink"                 , MYRGB (255,182,193)},
 
216
  {"pale violet red"           , MYRGB (219,112,147)},
 
217
  {"PaleVioletRed"             , MYRGB (219,112,147)},
 
218
  {"maroon"                    , MYRGB (176, 48, 96)},
 
219
  {"medium violet red"         , MYRGB (199, 21,133)},
 
220
  {"MediumVioletRed"           , MYRGB (199, 21,133)},
 
221
  {"violet red"                , MYRGB (208, 32,144)},
 
222
  {"VioletRed"                 , MYRGB (208, 32,144)},
 
223
  {"magenta"                   , MYRGB (255,  0,255)},
 
224
  {"violet"                    , MYRGB (238,130,238)},
 
225
  {"plum"                      , MYRGB (221,160,221)},
 
226
  {"orchid"                    , MYRGB (218,112,214)},
 
227
  {"medium orchid"             , MYRGB (186, 85,211)},
 
228
  {"MediumOrchid"              , MYRGB (186, 85,211)},
 
229
  {"dark orchid"               , MYRGB (153, 50,204)},
 
230
  {"DarkOrchid"                , MYRGB (153, 50,204)},
 
231
  {"dark violet"               , MYRGB (148,  0,211)},
 
232
  {"DarkViolet"                , MYRGB (148,  0,211)},
 
233
  {"blue violet"               , MYRGB (138, 43,226)},
 
234
  {"BlueViolet"                , MYRGB (138, 43,226)},
 
235
  {"purple"                    , MYRGB (160, 32,240)},
 
236
  {"medium purple"             , MYRGB (147,112,219)},
 
237
  {"MediumPurple"              , MYRGB (147,112,219)},
 
238
  {"thistle"                   , MYRGB (216,191,216)},
 
239
  {"gray0"                     , MYRGB (  0,  0,  0)},
 
240
  {"grey0"                     , MYRGB (  0,  0,  0)},
 
241
  {"dark grey"                 , MYRGB (169,169,169)},
 
242
  {"DarkGrey"                  , MYRGB (169,169,169)},
 
243
  {"dark gray"                 , MYRGB (169,169,169)},
 
244
  {"DarkGray"                  , MYRGB (169,169,169)},
 
245
  {"dark blue"                 , MYRGB (  0,  0,139)},
 
246
  {"DarkBlue"                  , MYRGB (  0,  0,139)},
 
247
  {"dark cyan"                 , MYRGB (  0,139,139)},
 
248
  {"DarkCyan"                  , MYRGB (  0,139,139)},
 
249
  {"dark magenta"              , MYRGB (139,  0,139)},
 
250
  {"DarkMagenta"               , MYRGB (139,  0,139)},
 
251
  {"dark red"                  , MYRGB (139,  0,  0)},
 
252
  {"DarkRed"                   , MYRGB (139,  0,  0)},
 
253
  {"light green"               , MYRGB (144,238,144)},
 
254
  {"LightGreen"                , MYRGB (144,238,144)}
 
255
};
 
256
 
 
257
int win32_color_map_size = sizeof(win32_color_map)/sizeof(colormap_t);
 
258
 
 
259
int check_386()
 
260
{
 
261
  OSVERSIONINFO os;
 
262
  SYSTEM_INFO si;
 
263
  int is_nt = 0;
 
264
  os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
 
265
  if (GetVersionEx(&os) == 0)
 
266
    Win32Error("GetVersionEx");
 
267
  is_nt = (os.dwPlatformId == VER_PLATFORM_WIN32_NT);
 
268
  GetSystemInfo(&si);
 
269
  if (is_nt)
 
270
    return si.wProcessorLevel <= 3;
 
271
  else
 
272
    return si.dwProcessorType == PROCESSOR_INTEL_386;
 
273
}
 
274
 
 
275
/*
 
276
  swap count bytes starting at address p
 
277
  */
 
278
 
 
279
void bswap_asm(void *p, unsigned count)
 
280
{
 
281
    __asm {
 
282
      mov       edx, DWORD PTR p;
 
283
      mov       ecx, count;
 
284
      /*        shl     ecx, 2; */
 
285
    $L1:
 
286
      mov     eax, DWORD PTR [edx];
 
287
      bswap   eax;
 
288
      mov     DWORD PTR [edx], eax;
 
289
      inc     edx;
 
290
      inc     edx;
 
291
      inc     edx;
 
292
      inc     edx;
 
293
      loopnz  $L1;
 
294
    }
 
295
}
 
296
 
 
297
void bswap_c(void *p, unsigned count)
 
298
{
 
299
  unsigned char *q;
 
300
  unsigned char temp;
 
301
    for (q = p;
 
302
         q < (unsigned char *)p + 4*count;
 
303
         q += 4) {
 
304
        temp = *(q);   *(q)   = *(q+3); *(q+3) = temp;
 
305
        temp = *(q+1); *(q+1) = *(q+2); *(q+2) = temp;
 
306
    }
 
307
}
 
308
 
 
309
FILE *
 
310
XsraSelFile(Widget toplevel, char *prompt, char *ok, char *cancel, 
 
311
            char *failed, char *init_path, char *mode,
 
312
            int (*show_entry)(), char **name_return)
 
313
{
 
314
  OPENFILENAME ofn;       /* common dialog box structure */
 
315
  char szFile[260];       /* buffer for filename */
 
316
  FILE *fret = NULL;
 
317
  char currentDir[260];
 
318
 
 
319
  *name_return = NULL;
 
320
  GetCurrentDirectory(sizeof(currentDir), currentDir);
 
321
 
 
322
  szFile[0] = '\0';
 
323
  /* Initialize OPENFILENAME */
 
324
  ZeroMemory(&ofn, sizeof(OPENFILENAME));
 
325
  ofn.lStructSize = sizeof(OPENFILENAME);
 
326
  ofn.hwndOwner = toplevel;
 
327
  ofn.lpstrFile = szFile;
 
328
  ofn.nMaxFile = sizeof(szFile);
 
329
  ofn.lpstrFilter = "Dvi Files\0*.dvi\0All Files\0*.*\0\0";
 
330
  ofn.nFilterIndex = 1;
 
331
  ofn.lpstrFileTitle = NULL;
 
332
  ofn.nMaxFileTitle = 0;
 
333
  ofn.lpstrInitialDir = NULL; /* FIXME : we should use init_path */
 
334
  ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
 
335
 
 
336
  /* Display the Open dialog box.  */
 
337
  
 
338
  if (GetOpenFileName(&ofn)==TRUE) {
 
339
    *name_return = xstrdup(szFile);
 
340
    fret = fopen(*name_return, mode);
 
341
  }
 
342
  else {
 
343
    SetCurrentDirectory(currentDir);
 
344
    if (CommDlgExtendedError() != 0)
 
345
      MessageBox(toplevel, failed, NULL, MB_OK|MB_ICONERROR||MB_APPLMODAL);
 
346
  }
 
347
  return fret;
 
348
}
 
349
 
 
350
COLORREF string_to_colorref(char *p)
 
351
{
 
352
  COLORREF c;
 
353
  float cyan, magenta, yellow, black, red, green, blue, gray;
 
354
 
 
355
  while ( *p <= ' ' ) p++ ;
 
356
  if (memicmp(p, "cmyk", 4) == 0) {
 
357
    sscanf(p+4, "%f %f %f %f", &cyan, &magenta, &yellow, &black);
 
358
    cyan += black;
 
359
    magenta += black;
 
360
    yellow += black;
 
361
 
 
362
    red = (float)fabs(magenta-yellow);
 
363
    blue = (float)fabs(magenta - cyan);
 
364
    green = (float)fabs(yellow - cyan);
 
365
 
 
366
    c = MYRGB((unsigned)(red*255), (unsigned)(green*255), (unsigned)(blue*255));
 
367
  }
 
368
  else if (memicmp(p, "gray", 4) == 0) {
 
369
    sscanf(p+4, "%f", &gray);
 
370
    c = MYRGB((unsigned)(255*gray), (unsigned)(255*gray), (unsigned)(255*gray));
 
371
  }
 
372
  else if (memicmp(p, "rgb", 3) == 0) {
 
373
    sscanf(p+3, "%f %f %f", &red, &green, &blue);
 
374
    c = MYRGB((unsigned)(red*255), (unsigned)(green*255), (unsigned)(blue*255));
 
375
  }
 
376
  else
 
377
    c = x_to_win32_color(p);
 
378
 
 
379
  return c;
 
380
}
 
381
 
 
382
#ifdef TRANSFORM
 
383
HRGN hClipRgn = NULL;
 
384
#endif
 
385
 
 
386
/*
 
387
  FP: 22/07/99
 
388
  Time to clean up this routine.
 
389
  Should handle clipping automatically.
 
390
  Should handle transformations.
 
391
  Grey scaling for colors is handled by complex rop code.
 
392
*/
 
393
 
 
394
/* trial version : uses SetDIBits(), no temp DIB */
 
395
void XPutImage(void *scrn, HWND w, HDC hdc, XImage *img, 
 
396
               int src_x, int src_y,
 
397
               int dest_x, int dest_y,
 
398
               unsigned int width, unsigned int height)
 
399
{
 
400
  RGBQUAD c1,c2;
 
401
  COLORREF fc, bc;
 
402
#ifdef TRANSFORM
 
403
  POINT lppt[4];
 
404
  HRGN hNewClipRgn = NULL;
 
405
  XFORM xfrm, xfrm_temp;
 
406
  extern BOOL bTransfInUse;
 
407
#endif
 
408
 
 
409
  if (!allowDrawingChars) {
 
410
#if 0
 
411
    fprintf(stderr, "Not allowing chars drawing\n");
 
412
#endif
 
413
    return;
 
414
  }
 
415
 
 
416
#if 0
 
417
    fprintf(stderr, "Back color is %-8x, mode is %s\n",
 
418
            GetBkColor(hdc),
 
419
            (GetBkMode(hdc) == OPAQUE ? "opaque" :
 
420
             (GetBkMode(hdc) == TRANSPARENT ? "transparent" : "failed")));
 
421
#endif
 
422
 
 
423
#if _TRACE
 
424
  if (isPrinting) {
 
425
    fprintf(stderr, "fore = %x\n", fore_Pixel);
 
426
    fprintf(stderr, "src_x = %d, src_y = %d, dest_x = %d, dest_y = %d\n",
 
427
            src_x, src_y, dest_x, dest_y);
 
428
  }
 
429
#endif
 
430
 
 
431
  if (!img->width || !img->height) {
 
432
    /* Nothing to do ! */
 
433
    return;
 
434
  }
 
435
 
 
436
#ifdef WIN32
 
437
  if (img->endian_permuted !=NULL && *(img->endian_permuted) == 0) {
 
438
    bswap((BMUNIT*)img->data, 
 
439
                (img->bytes_per_line * height)/BMBYTES);
 
440
    *(img->endian_permuted) = 1;
 
441
  }
 
442
#endif
 
443
 
 
444
#if TRANSFORM
 
445
  if (resource.use_xform && bTransfInUse) {
 
446
    RECT rTemp;
 
447
    BOOL bClipped1, bClipped2;
 
448
    extern XFORM current_transf;
 
449
    rTemp.left = dest_x;
 
450
    rTemp.top = dest_y;
 
451
    rTemp.right = dest_x + width;
 
452
    rTemp.bottom = dest_y + height;
 
453
    if (SetWorldTransform(hdc, &current_transf) == 0)
 
454
      Win32Error("XPutImage/SetWorldTransform/current");
 
455
    
 
456
    lppt[0].x = dest_x;
 
457
    lppt[0].y = dest_y;
 
458
    lppt[1].x = dest_x + width;
 
459
    lppt[1].y = dest_y;
 
460
    lppt[2].x = dest_x + width;
 
461
    lppt[2].y = dest_y + height;
 
462
    lppt[3].x = dest_x;
 
463
    lppt[3].y = dest_y + height;
 
464
    LPtoDP(hdc, lppt, 4);
 
465
    if ((hNewClipRgn = CreatePolygonRgn(lppt, 4, ALTERNATE)) == NULL) {
 
466
      Win32Error("XPutImage/CreatePolygonRgn");
 
467
    }
 
468
    if (SelectClipRgn(hdc, hNewClipRgn) == ERROR) {
 
469
      Win32Error("XPutImage/SelectClipRgn");
 
470
    }
 
471
    bClipped2 = RectVisible(hdc, &rTemp);
 
472
    if (!bClipped2)
 
473
      goto nothing;
 
474
  }
 
475
  else
 
476
#endif
 
477
    {
 
478
      RECT rTemp;
 
479
      rTemp.left = dest_x;
 
480
      rTemp.top = dest_y;
 
481
      rTemp.right = dest_x + width;
 
482
      rTemp.bottom = dest_y + height;
 
483
      if (!RectVisible(hdc, &rTemp))
 
484
        goto nothing;
 
485
    }
 
486
 
 
487
#if _TRACE
 
488
    fprintf(stderr, "XPutImage at (%d %d) of (%d, %d, w=%d x h=%d)\n",
 
489
            dest_x, dest_y, src_x, src_y, width, height);
 
490
#endif
 
491
  switch (img->depth) {
 
492
  case 1:
 
493
    bmi1.bmiHeader.biWidth    = img->width;
 
494
    bmi1.bmiHeader.biHeight   = (img->height == 1 ? img->height : -img->height);
 
495
    bmi1.bmiHeader.biSizeImage = 
 
496
      WIDTHBYTES((DWORD)img->width * img->depth) 
 
497
      * (img->height > 0 ? img->height : -img->height);
 
498
#if _TRACE
 
499
    fprintf(stderr, "XPutImage at (%d %d) of (%d, %d, w=%d x h=%d)\n",
 
500
            dest_x, dest_y, src_x, src_y, width, height);
 
501
    fprintf(stderr, "bmiColors: 0 = %x, 1 = %x\n",
 
502
            bmi1.bmiColors[0], bmi1.bmiColors[1]);
 
503
#endif
 
504
 
 
505
    c1 = bmi1.bmiColors[0];
 
506
    c2 = bmi1.bmiColors[1];
 
507
 
 
508
    if (isPrinting && !(bColorPage || psToDisplay)) {
 
509
      HBRUSH oldBrush;
 
510
 
 
511
      bmi1.bmiColors[0] = QuadWhite;
 
512
      bmi1.bmiColors[1] = QuadBlack;
 
513
 
 
514
      oldBrush = SelectObject(hdc, foreBrush);
 
515
 
 
516
      if (StretchDIBits(hdc, dest_x, dest_y, width, height,
 
517
                        src_x, src_y, width, height, 
 
518
                        img->data, (LPBITMAPINFO)&bmi1, 
 
519
                        DIB_RGB_COLORS, SRCAND /* 0x00B8074A  0x00E61CE8 */  ) == GDI_ERROR)
 
520
        Win32Error("XPutImage/SetDIBits");
 
521
      bmi1.bmiColors[0] = c1;
 
522
      bmi1.bmiColors[1] = c2;
 
523
 
 
524
      SelectObject(hdc, oldBrush);
 
525
    }
 
526
#if 1
 
527
        else  {
 
528
            HBRUSH oldBrush;
 
529
            init_pix( MYRGB(255,255,255), MYRGB(0,0,0));
 
530
            oldBrush = SelectObject(hdc, foreBrush);
 
531
            if (StretchDIBits(hdc, dest_x, dest_y, width, height,
 
532
                              src_x, src_y, width, height, 
 
533
                              img->data, (LPBITMAPINFO)&bmi1, DIB_RGB_COLORS, 0x00B8074A ) == GDI_ERROR)
 
534
              Win32Error("XPutImage/SetDIBits");
 
535
            SelectObject(hdc, oldBrush);
 
536
          }
 
537
#else
 
538
    else {
 
539
      /* this is the 2 passes solution, but does not seem to work ok
 
540
         on the printer dc */
 
541
      bmi1.bmiColors[0] = QuadWhite;
 
542
      bmi1.bmiColors[1] = QuadBlack;
 
543
      
 
544
      if (StretchDIBits(hdc, dest_x, dest_y, width, height,
 
545
                        src_x, src_y, width, height, 
 
546
                        img->data, (LPBITMAPINFO)&bmi1, DIB_RGB_COLORS, SRCAND ) == GDI_ERROR)
 
547
        Win32Error("XPutImage/SetDIBits");
 
548
      
 
549
      bmi1.bmiColors[0] = QuadBlack;
 
550
      bmi1.bmiColors[1] = Color2Quad(fore_Pixel);
 
551
      
 
552
      if (StretchDIBits(hdc, dest_x, dest_y, width, height,
 
553
                        src_x, src_y, width, height, 
 
554
                        img->data, (LPBITMAPINFO)&bmi1, DIB_RGB_COLORS, SRCPAINT ) == GDI_ERROR)
 
555
        Win32Error("XPutImage/SetDIBits");
 
556
      bmi1.bmiColors[0] = c1;
 
557
      bmi1.bmiColors[1] = Color2Quad(fore_Pixel);
 
558
    }
 
559
#endif
 
560
    break;
 
561
 
 
562
  case 4: {
 
563
    POINT pt;
 
564
    RECT rcClip, rcGlyph, rcDest;
 
565
 
 
566
    bmi4.bmiHeader.biWidth    = img->width;
 
567
    bmi4.bmiHeader.biHeight   = (img->height == 1 ? img->height : -img->height);
 
568
    bmi4.bmiHeader.biSizeImage = 
 
569
      WIDTHBYTES((DWORD)img->width * img->depth) 
 
570
      * (img->height > 0 ? img->height : -img->height);
 
571
 
 
572
#if 0
 
573
    fprintf(stderr, "XPutImage @ (%d %d) w %d h %d fore %-8x back %-8x\n",
 
574
            dest_x, dest_y, width, height, fore_Pixel, back_Pixel);
 
575
#endif
 
576
 
 
577
#if 0
 
578
        fprintf(stderr, "This is%s a color page!\n", bColorPage ? "" : " not");
 
579
#endif
 
580
    /* If this is a monochrome page, no antialiasing */
 
581
    if (!bColorPage) {
 
582
        /* Don't bother with color antialiasing in this case ! */
 
583
        fc = fore_Pixel;
 
584
        bc = back_Pixel;
 
585
        init_pix(bc, fc);
 
586
#if 0
 
587
        {
 
588
          int pixel;
 
589
          for (pixel = 0; pixel < 16; pixel++)
 
590
            fprintf(stderr, "color %d = %-8x %-8x %-8x\n", pixel, 
 
591
                    pal_rgb[pixel], pal_bw[pixel], pal_mask[pixel]);
 
592
        }
 
593
#endif
 
594
        if (StretchDIBits(hdc, dest_x, dest_y, width, height,
 
595
                          src_x, src_y, width, height, 
 
596
                          img->data, (LPBITMAPINFO)&bmi4, DIB_RGB_COLORS, SRCAND ) == GDI_ERROR) {
 
597
          Win32Error("XPutImage/SetDIBits");
 
598
        }
 
599
      }      
 
600
      else {
 
601
          {
 
602
            HBRUSH oldBrush;
 
603
            init_pix( MYRGB(255,255,255), MYRGB(0,0,0));
 
604
            oldBrush = SelectObject(hdc, foreBrush);
 
605
            if (StretchDIBits(hdc, dest_x, dest_y, width, height,
 
606
                              src_x, src_y, width, height, 
 
607
                              img->data, (LPBITMAPINFO)&bmi4, DIB_RGB_COLORS, 0x00B8074A ) == GDI_ERROR)
 
608
              Win32Error("XPutImage/SetDIBits");
 
609
            SelectObject(hdc, oldBrush);
 
610
          }
 
611
          
 
612
        }
 
613
      }
 
614
 
 
615
    break;
 
616
    
 
617
  case 8:
 
618
    bmi8.bmiHeader.biWidth    = img->width;
 
619
    bmi8.bmiHeader.biHeight   = (img->height == 1 ? img->height : -img->height);
 
620
    bmi8.bmiHeader.biSizeImage = 
 
621
      WIDTHBYTES((DWORD)img->width * img->depth) 
 
622
      * (img->height > 0 ? img->height : -img->height);
 
623
 
 
624
    if (StretchDIBits(hdc, dest_x, dest_y, width, height,
 
625
                      src_x, src_y, width, height, 
 
626
                      img->data, (LPBITMAPINFO)&bmi8, DIB_RGB_COLORS, SRCPAINT ) == GDI_ERROR)
 
627
      Win32Error("XPutImage/SetDIBits");
 
628
    break;
 
629
 
 
630
  default:
 
631
    fprintf(stderr, "XPutImage: image depth is %d, non implemented.\n",
 
632
            img->depth);
 
633
  }
 
634
 nothing:
 
635
#if TRANSFORM
 
636
  if (resource.use_xform && bTransfInUse) {
 
637
    SelectClipRgn(hdc, NULL);
 
638
    if (hNewClipRgn) DeleteObject(hNewClipRgn);
 
639
    ModifyWorldTransform(hdc, &xfrm_temp, MWT_IDENTITY);
 
640
  }
 
641
#endif
 
642
}
 
643
 
 
644
/* Trial version : assumes 16 colors DIBS, computes the nibble to be
 
645
   changed */
 
646
void XPutPixel(XImage *img, int x, int y, COLORREF c)
 
647
{
 
648
  unsigned pixel;
 
649
  unsigned char *pos;
 
650
  if (x < 0 || x > img->width || y < 0 || y > img->height) {
 
651
    fprintf(stderr, 
 
652
            "XPutPixel error : x = %d y = %d width = %d height = %d\n",
 
653
            x, y, img->width, img->height);
 
654
  } else {
 
655
    switch (img->depth) {
 
656
    case 4:
 
657
#if 0
 
658
      for (pixel = 0; pixel < 16; pixel++)
 
659
        fprintf(stderr, "color %d = %-8x\n", pixel, palette[pixel]);
 
660
      fprintf(stderr, "looked for %-8x\n", c);
 
661
#endif
 
662
      for (pixel = 0; (palette[pixel] != c) && (pixel < 16); pixel++);
 
663
      if (pixel == 16)
 
664
        Win32Error("XPutPixel/Color not found");
 
665
#if 0      
 
666
      else
 
667
        fprintf(stderr, "Found pixel = %d color = %-8x\n", pixel, palette[pixel]);
 
668
#endif
 
669
      pos = (unsigned char *)img->data + y * img->bytes_per_line + x / 2;
 
670
#if 0
 
671
      fprintf(stderr, "img w = %d h = %d b/l = %d data = %x\nx = %d y = %d pos = %x\n", img->width , img->height, img->bytes_per_line, img->data, x, y, pos);
 
672
#endif
 
673
      if (x % 2 == 0) {
 
674
        /* msb */
 
675
        *pos = (*pos & 0x0F) | ((pixel & 0x0F) << 4);
 
676
      }
 
677
      else {
 
678
        /* lsb */
 
679
        *pos = (*pos & 0xF0) | (pixel & 0x0F);
 
680
      }
 
681
      break;
 
682
    default:
 
683
      Win32Error("XPutPixel/not a 16 colors DIB");
 
684
    }
 
685
  }
 
686
}
 
687
 
 
688
XImage* XCreateImage(void* d, HDC hdc, unsigned int depth, 
 
689
                     int format, int offset, char* data, 
 
690
                     unsigned int width, unsigned int height, 
 
691
                     int bitmap_pad, int bytes_per_line)
 
692
{
 
693
  XImage *img;
 
694
  img = (XImage *)xmalloc(sizeof(XImage));
 
695
  img->width = width;
 
696
  img->height = height;
 
697
  img->depth = depth;
 
698
  if (! bytes_per_line) {
 
699
    img->bytes_per_line = 
 
700
      WIDTHBYTES((DWORD)img->width * img->depth) ;
 
701
  }
 
702
  else
 
703
    img->bytes_per_line = bytes_per_line;
 
704
  img->data = NULL;
 
705
  return img;
 
706
}
 
707
 
 
708
void XClearWindow(void *disp, HWND win)
 
709
{
 
710
  if (! isPrinting) {
 
711
    if (debug & DBG_EVENT) {
 
712
      fprintf(stderr, "Clearing window %-8x\n", win);
 
713
    }
 
714
    SendMessage(win, WM_ERASEBKGND,  (WPARAM)GetDC(win), 0);
 
715
    UpdateWindow(win);
 
716
  }
 
717
}
 
718
 
 
719
void XClearArea(void *disp, HWND win, int x, int y, int width, int height, 
 
720
                int b)
 
721
{
 
722
  HDC maneGC = GetDC(win);
 
723
  RECT r;
 
724
 
 
725
  r.left = x; r.top = y;
 
726
  r.right = x + width;
 
727
  r.bottom = y + height;
 
728
 
 
729
  /* Blank the bitmap */
 
730
#if 0  
 
731
  if (!PatBlt(maneGC, x, y, x+width, y+height, PATCOPY))
 
732
    Win32Error("XClearArea: PatBlt");
 
733
#else
 
734
  r.right++;
 
735
  r.bottom++;
 
736
  if (!FillRect(maneGC, &r, backBrush))
 
737
    Win32Error("XClearArea: PatBlt");
 
738
#endif
 
739
  ReleaseDC(win, maneGC);
 
740
}
 
741
 
 
742
void XFlush(void *disp)
 
743
{
 
744
  GdiFlush();
 
745
}
 
746
 
 
747
void XDestroyImage(XImage *img)
 
748
{
 
749
  /* An XImage is a DIB basically */
 
750
  if (img) {    
 
751
    if (img->data) free(img->data);
 
752
    free (img);
 
753
  }
 
754
}
 
755
 
 
756
void XDrawLine(void *d, HWND hwnd, HDC hdc, int x1, int y1, int x2, int y2)
 
757
{
 
758
  static int xprev = 0, yprev = 0;
 
759
  if (xprev != x1 || yprev != y1) {
 
760
#if 0
 
761
    fprintf(stderr, "Moving to (%d, %d)\n", x1, y1);
 
762
#endif
 
763
    MoveToEx(hdc, x1, y1, NULL);
 
764
  }
 
765
#if 0
 
766
  fprintf(stderr, "Drawing to (%d, %d)\n", x2, y2);
 
767
#endif
 
768
  LineTo(hdc, x2, y2);
 
769
  xprev = x2;
 
770
  yprev = y2;
 
771
}
 
772
 
 
773
void XDrawPoint(void *w, HWND hwnd, HDC hdc, int x1, int y1)
 
774
{
 
775
#if 0
 
776
  fprintf(stderr, "Drawing point at (%d %d)\n", x1, y1);
 
777
#endif
 
778
  if (MoveToEx(hdc, x1, y1, NULL) == 0) {
 
779
    Win32Error("XDrawPoint/MoveToEx failed!");
 
780
  }
 
781
  if (LineTo(hdc, x1, y1) == 0) {
 
782
    Win32Error("XDrawPoint/LineTo failed!");
 
783
  }
 
784
}
 
785
 
 
786
void XFillRectangle(void *d, HWND w, HDC hdc, int x, int y,
 
787
                    unsigned int width, unsigned int height)
 
788
{
 
789
  RECT r;
 
790
  /* Rectangle(hdc, x, y, x+width, y+height); */
 
791
  r.left = x; r.top = y;
 
792
  r.right = x + width;
 
793
  r.bottom = y + height;
 
794
#if 0
 
795
  fprintf(stderr, "FillRect (%d %d) - (%d %d) hdc %x color %-8x\n",
 
796
          r.left, r.top, r.right, r.bottom, hdc, fore_Pixel);
 
797
#endif
 
798
  FillRect(hdc, &r, foreBrush);
 
799
}
 
800
 
 
801
 
 
802
HBITMAP CreateDIB(HDC hdc, int x, int y, int bitCount, 
 
803
                  BITMAPINFO_256 *header, void **data)
 
804
{
 
805
  int i;
 
806
  HBITMAP hbm;
 
807
  BITMAPINFO_256 bmi;
 
808
  LPBITMAPINFO lpbmi;
 
809
 
 
810
  LPVOID ppvBits;
 
811
 
 
812
  lpbmi = (LPBITMAPINFO)(header ? header : &bmi);
 
813
 
 
814
  lpbmi->bmiHeader.biSize     = sizeof(BITMAPINFOHEADER);
 
815
  lpbmi->bmiHeader.biPlanes   = 1;
 
816
  lpbmi->bmiHeader.biBitCount = bitCount;
 
817
  lpbmi->bmiHeader.biCompression        = BI_RGB;
 
818
  lpbmi->bmiHeader.biWidth    = x;
 
819
  lpbmi->bmiHeader.biHeight   = y;
 
820
  lpbmi->bmiHeader.biSizeImage = 
 
821
    WIDTHBYTES((DWORD)x * bitCount) * (y > 0 ? y : -y);
 
822
  if (lpbmi->bmiHeader.biCompression != BI_RGB)
 
823
    lpbmi->bmiHeader.biSizeImage = (lpbmi->bmiHeader.biSizeImage * 3) / 2;
 
824
  lpbmi->bmiHeader.biXPelsPerMeter      = 0;
 
825
  lpbmi->bmiHeader.biYPelsPerMeter      = 0;
 
826
  lpbmi->bmiHeader.biClrUsed            = 0;
 
827
  lpbmi->bmiHeader.biClrImportant       = 0;
 
828
  
 
829
  /* SelectPalette(hdc,hpal,FALSE); */
 
830
  if (bitCount == 1) {
 
831
    lpbmi->bmiColors[1] = Color2Quad(back_Pixel);
 
832
    lpbmi->bmiColors[0] = Color2Quad(fore_Pixel);
 
833
  }
 
834
#ifdef GREY
 
835
  else if (bitCount <= 8) {
 
836
    for (i = 0; i < (1 << bitCount); i++) {
 
837
      lpbmi->bmiColors[i] = Color2Quad(palette[i]);
 
838
    }
 
839
  }
 
840
#endif
 
841
 
 
842
  hbm = CreateDIBSection(hdc, lpbmi, DIB_RGB_COLORS, &ppvBits, NULL, 0);
 
843
  /*  fprintf(stderr, "Nb DIBS = %d\n", ++nbDIBS); */
 
844
  if (hbm == NULL)
 
845
    Win32Error("CreateDIB/CreateDIBSection");
 
846
  if (data)
 
847
    *data = ppvBits;
 
848
  return hbm;
 
849
}
 
850
 
 
851
/* These ones are taken from NTEmacs */
 
852
 
 
853
/*
 
854
 *    XParseGeometry parses strings of the form
 
855
 *   "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
 
856
 *   width, height, xoffset, and yoffset are unsigned integers.
 
857
 *   Example:  "=80x24+300-49"
 
858
 *   The equal sign is optional.
 
859
 *   It returns a bitmask that indicates which of the four values
 
860
 *   were actually found in the string.  For each value found,
 
861
 *   the corresponding argument is updated;  for each value
 
862
 *   not found, the corresponding argument is left unchanged. 
 
863
 */
 
864
 
 
865
static int
 
866
read_integer (char *s, char **NextString)
 
867
{
 
868
  register int Result = 0;
 
869
  int Sign = 1;
 
870
  
 
871
  if (*s == '+')
 
872
    s++;
 
873
  else if (*s == '-')
 
874
    {
 
875
      s++;
 
876
      Sign = -1;
 
877
    }
 
878
  for (; (*s >= '0') && (*s <= '9'); s++)
 
879
    {
 
880
      Result = (Result * 10) + (*s - '0');
 
881
    }
 
882
  *NextString = s;
 
883
  if (Sign >= 0)
 
884
    return (Result);
 
885
  else
 
886
    return (-Result);
 
887
}
 
888
 
 
889
int 
 
890
XParseGeometry (char *s, int *x, int *y, 
 
891
                unsigned int *width, unsigned int *height)
 
892
{
 
893
  int mask = NoValue;
 
894
  register char *strind;
 
895
  unsigned int tempWidth, tempHeight;
 
896
  int tempX, tempY;
 
897
  char *nextCharacter;
 
898
  
 
899
  if ((s == NULL) || (*s == '\0')) return (mask);
 
900
  if (*s == '=')
 
901
    s++;  /* ignore possible '=' at beg of geometry spec */
 
902
  
 
903
  strind = (char *)s;
 
904
  if (*strind != '+' && *strind != '-' && *strind != 'x') 
 
905
    {
 
906
      tempWidth = read_integer (strind, &nextCharacter);
 
907
      if (strind == nextCharacter) 
 
908
        return (0);
 
909
      strind = nextCharacter;
 
910
      mask |= WidthValue;
 
911
    }
 
912
  
 
913
  if (*strind == 'x' || *strind == 'X') 
 
914
    {   
 
915
      strind++;
 
916
      tempHeight = read_integer (strind, &nextCharacter);
 
917
      if (strind == nextCharacter)
 
918
        return (0);
 
919
      strind = nextCharacter;
 
920
      mask |= HeightValue;
 
921
    }
 
922
  
 
923
  if ((*strind == '+') || (*strind == '-')) 
 
924
    {
 
925
      if (*strind == '-') 
 
926
        {
 
927
          strind++;
 
928
          tempX = -read_integer (strind, &nextCharacter);
 
929
          if (strind == nextCharacter)
 
930
            return (0);
 
931
          strind = nextCharacter;
 
932
          mask |= XNegative;
 
933
 
 
934
        }
 
935
      else
 
936
        {       
 
937
          strind++;
 
938
          tempX = read_integer (strind, &nextCharacter);
 
939
          if (strind == nextCharacter)
 
940
            return (0);
 
941
          strind = nextCharacter;
 
942
        }
 
943
      mask |= XValue;
 
944
      if ((*strind == '+') || (*strind == '-')) 
 
945
        {
 
946
          if (*strind == '-') 
 
947
            {
 
948
              strind++;
 
949
              tempY = -read_integer (strind, &nextCharacter);
 
950
              if (strind == nextCharacter)
 
951
                return (0);
 
952
              strind = nextCharacter;
 
953
              mask |= YNegative;
 
954
 
 
955
            }
 
956
          else
 
957
            {
 
958
              strind++;
 
959
              tempY = read_integer (strind, &nextCharacter);
 
960
              if (strind == nextCharacter)
 
961
                return (0);
 
962
              strind = nextCharacter;
 
963
            }
 
964
          mask |= YValue;
 
965
        }
 
966
    }
 
967
  
 
968
  /* If strind isn't at the end of the string the it's an invalid
 
969
     geometry specification. */
 
970
  
 
971
  if (*strind != '\0') return (0);
 
972
  
 
973
  if (mask & XValue)
 
974
    *x = tempX;
 
975
  if (mask & YValue)
 
976
    *y = tempY;
 
977
  if (mask & WidthValue)
 
978
    *width = tempWidth;
 
979
  if (mask & HeightValue)
 
980
    *height = tempHeight;
 
981
  return (mask);
 
982
}
 
983
 
 
984
COLORREF 
 
985
x_to_win32_color (const char *colorname)
 
986
{
 
987
  colormap_t *tail;
 
988
  int i;
 
989
  COLORREF ret;
 
990
 
 
991
  if (colorname[0] == '#')
 
992
    {
 
993
      /* Could be an old-style RGB Device specification.  */
 
994
      char *color;
 
995
      int size;
 
996
      color = colorname + 1;
 
997
      
 
998
      size = strlen(color);
 
999
      if (size == 3 || size == 6 || size == 9 || size == 12)
 
1000
        {
 
1001
          UINT colorval;
 
1002
          int i, pos;
 
1003
          pos = 0;
 
1004
          size /= 3;
 
1005
          colorval = 0;
 
1006
          
 
1007
          for (i = 0; i < 3; i++)
 
1008
            {
 
1009
              char *end;
 
1010
              char t;
 
1011
              unsigned long value;
 
1012
 
 
1013
              /* The check for 'x' in the following conditional takes into
 
1014
                 account the fact that strtol allows a "0x" in front of
 
1015
                 our numbers, and we don't.  */
 
1016
              if (!isxdigit(color[0]) || color[1] == 'x')
 
1017
                break;
 
1018
              t = color[size];
 
1019
              color[size] = '\0';
 
1020
              value = strtoul(color, &end, 16);
 
1021
              color[size] = t;
 
1022
              if (errno == ERANGE || end - color != size)
 
1023
                break;
 
1024
              switch (size)
 
1025
                {
 
1026
                case 1:
 
1027
                  value = value * 0x10;
 
1028
                  break;
 
1029
                case 2:
 
1030
                  break;
 
1031
                case 3:
 
1032
                  value /= 0x10;
 
1033
                  break;
 
1034
                case 4:
 
1035
                  value /= 0x100;
 
1036
                  break;
 
1037
                }
 
1038
              colorval |= (value << pos);
 
1039
              pos += 0x8;
 
1040
              if (i == 2)
 
1041
                {
 
1042
                  return MYADJUSTRGB(colorval);
 
1043
                }
 
1044
              color = end;
 
1045
            }
 
1046
        }
 
1047
    }
 
1048
  else if (strnicmp(colorname, "rgb:", 4) == 0)
 
1049
    {
 
1050
      char *color;
 
1051
      UINT colorval;
 
1052
      int i, pos;
 
1053
      pos = 0;
 
1054
 
 
1055
      colorval = 0;
 
1056
      color = colorname + 4;
 
1057
      for (i = 0; i < 3; i++)
 
1058
        {
 
1059
          char *end;
 
1060
          unsigned long value;
 
1061
          
 
1062
          /* The check for 'x' in the following conditional takes into
 
1063
             account the fact that strtol allows a "0x" in front of
 
1064
             our numbers, and we don't.  */
 
1065
          if (!isxdigit(color[0]) || color[1] == 'x')
 
1066
            break;
 
1067
          value = strtoul(color, &end, 16);
 
1068
          if (errno == ERANGE)
 
1069
            break;
 
1070
          switch (end - color)
 
1071
            {
 
1072
            case 1:
 
1073
              value = value * 0x10 + value;
 
1074
              break;
 
1075
            case 2:
 
1076
              break;
 
1077
            case 3:
 
1078
              value /= 0x10;
 
1079
              break;
 
1080
            case 4:
 
1081
              value /= 0x100;
 
1082
              break;
 
1083
            default:
 
1084
              value = ULONG_MAX;
 
1085
            }
 
1086
          if (value == ULONG_MAX)
 
1087
            break;
 
1088
          colorval |= (value << pos);
 
1089
          pos += 0x8;
 
1090
          if (i == 2)
 
1091
            {
 
1092
              if (*end != '\0')
 
1093
                break;
 
1094
              return MYADJUSTRGB(colorval);
 
1095
            }
 
1096
          if (*end != '/')
 
1097
            break;
 
1098
          color = end + 1;
 
1099
        }
 
1100
    }
 
1101
  else if (strnicmp(colorname, "rgbi:", 5) == 0)
 
1102
    {
 
1103
      /* This is an RGB Intensity specification.  */
 
1104
      char *color;
 
1105
      UINT colorval;
 
1106
      int i, pos;
 
1107
      pos = 0;
 
1108
 
 
1109
      colorval = 0;
 
1110
      color = colorname + 5;
 
1111
      for (i = 0; i < 3; i++)
 
1112
        {
 
1113
          char *end;
 
1114
          double value;
 
1115
          UINT val;
 
1116
 
 
1117
          value = strtod(color, &end);
 
1118
          if (errno == ERANGE)
 
1119
            break;
 
1120
          if (value < 0.0 || value > 1.0)
 
1121
            break;
 
1122
          val = (UINT)(0x100 * value);
 
1123
          /* We used 0x100 instead of 0xFF to give an continuous
 
1124
             range between 0.0 and 1.0 inclusive.  The next statement
 
1125
             fixes the 1.0 case.  */
 
1126
          if (val == 0x100)
 
1127
            val = 0xFF;
 
1128
          colorval |= (val << pos);
 
1129
          pos += 0x8;
 
1130
          if (i == 2)
 
1131
            {
 
1132
              if (*end != '\0')
 
1133
                break;
 
1134
              return MYADJUSTRGB(colorval);
 
1135
            }
 
1136
          if (*end != '/')
 
1137
            break;
 
1138
          color = end + 1;
 
1139
        }
 
1140
    }
 
1141
  /* I am not going to attempt to handle any of the CIE color schemes
 
1142
     or TekHVC, since I don't know the algorithms for conversion to
 
1143
     RGB.  */
 
1144
  
 
1145
  for (tail = win32_color_map, i = 0; 
 
1146
       i < sizeof(win32_color_map)/sizeof(colormap_t); 
 
1147
       tail++, i++)
 
1148
    {
 
1149
      char *tem = tail->name;
 
1150
 
 
1151
      if (lstrcmpi (tem, colorname) == 0)
 
1152
        {
 
1153
          ret = tail->colorref;
 
1154
          break;
 
1155
        }
 
1156
    }
 
1157
  return ret;
 
1158
}
 
1159