aboutsummaryrefslogtreecommitdiffstats
path: root/math/xplot/files/patch-ab
blob: f0c6b9a760457e2a6c6a15f954bebec4376489db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
--- xplot.c.orig    Wed Nov 19 18:35:43 2003
+++ xplot.c Wed Nov 19 18:35:42 2003
@@ -46,7 +46,7 @@
 #include <X11/cursorfont.h>
 #include <math.h>
 #include <ctype.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include "xplot.h"
 #include "coord.h"
 
@@ -813,9 +813,7 @@
     static struct dpy_info {
       unsigned long line_plane_mask;
       Colormap clr_map;
-      XColor clr;
-      unsigned long pixel[NCOLORS];
-      int Colors[NCOLORS];
+      unsigned long Colors[NCOLORS];
       int virgin;
       Atom xplot_nagle_atom;
       Display *saved_dpy;
@@ -842,38 +840,37 @@
     /* Allocate some color cells */
       
     if (d_i[d].virgin ) {
+      int usewhite;
+
       d_i[d].virgin = 0;
       
       d_i[d].xplot_nagle_atom = XInternAtom(pl->dpy, "XPLOT_NAGLE", False);
 
       d_i[d].clr_map = DefaultColormap(pl->dpy, DefaultScreen(pl->dpy));
       
-      if ( option_mono ||
+      if ( option_mono ) {
+   usewhite = 1;
+      } else {
+   usewhite = 0;
 
-      ! XAllocColorCells(pl->dpy, 
-                 d_i[d].clr_map, 0,
-                 &d_i[d].line_plane_mask, 1,
-                 d_i[d].pixel, NColors) )
-   {
-     /* probably only one bit plane, or all the color cells are taken */
-#if 1
-     if (! option_mono)
-       fputs("XAllocColorCells failed, will only have one plot color\n",
-         stderr);
-#endif
-     for ( i = 0; i < NColors; i++) {
-       d_i[d].Colors[i] = WhitePixelOfScreen(pl->screen);
-     }
-   } else {
-     for (i = 0; i < NColors; i++)  {
-       XParseColor(pl->dpy, d_i[d].clr_map, ColorNames[i], &d_i[d].clr);
-       d_i[d].clr.pixel = d_i[d].pixel[i];
-       XStoreColor (pl->dpy, d_i[d].clr_map, &d_i[d].clr);
-       d_i[d].clr.pixel |= d_i[d].line_plane_mask;
-       XStoreColor (pl->dpy, d_i[d].clr_map, &d_i[d].clr);
-       d_i[d].Colors[i] = d_i[d].clr.pixel;
+   for (i = 0; i < NColors; i++)  {
+     XColor alloc, exact;
+
+     if (XAllocNamedColor(pl->dpy, d_i[d].clr_map, ColorNames[i],
+             &alloc, &exact) == 0) {
+       XFreeColors(pl->dpy, d_i[d].clr_map, d_i[d].Colors, i, NULL);
+       usewhite = 1;
+       fprintf(stderr, "unable to allocate color \"%s\", falling back to only one plot color\n", ColorNames[i]);
+       break;
      }
+     d_i[d].Colors[i] = alloc.pixel;
    }
+      }
+      if ( usewhite ) {
+   for ( i = 0; i < NColors; i++) {
+     d_i[d].Colors[i] = WhitePixelOfScreen(pl->screen);
+   }
+      }
     }
     
     for (i = 0; i < NColors; i++) {
@@ -3154,11 +3151,7 @@
    * GDT: 950310: put dot font hack in.
    */
 
-#ifdef SDO
   fputs("%!PS\n", fp);
-#else
-  fputs("%!PostScript\n", fp);
-#endif
   /* Bracket the PS program with gsave/grestore so these page descriptions
      can be concatenated, then printed. */
   fputs("%%BoundingBox: ", fp);
@@ -3168,146 +3161,146 @@
   fputs("gsave\n", fp);
 
   /* Set up scale */
-  fputs("
-%/sign { dup 0 gt { pop 1 } { 0 lt { -1 } { 0 } ifelse } ifelse } def
-
-%matrix currentmatrix
-%aload pop
-%6 2 roll sign
-%6 1 roll sign
-%6 1 roll sign
-%6 1 roll sign
-%6 1 roll
-%matrix astore setmatrix
-
-0.12 dup scale
-
+  fputs("\n\
+%/sign { dup 0 gt { pop 1 } { 0 lt { -1 } { 0 } ifelse } ifelse } def\n\
+\n\
+%matrix currentmatrix\n\
+%aload pop\n\
+%6 2 roll sign\n\
+%6 1 roll sign\n\
+%6 1 roll sign\n\
+%6 1 roll sign\n\
+%6 1 roll\n\
+%matrix astore setmatrix\n\
+\n\
+0.12 dup scale\n\
+\n\
 ", fp);
 
   fprintf(fp, "/theta {%d mul} def\n", ( (state == PRINTING) ? 4 : 2));
 
   /* Set up units of measurement. */
   fprintf(fp, "/inch {%d mul} def\n", PER_INCH);
-  fputs("/pt {inch 72 div} def
-%
-%
-/tfont /Times-Bold findfont 12 pt scalefont def
-%
-/lfont /Times-Roman findfont 10 pt scalefont def
-%
-%tfont /FontBBox get
-%  aload pop 
-%  tfont /FontMatrix get dtransform pop /tascent exch def
-%  tfont /FontMatrix get dtransform pop neg /tdescent exch def
-lfont /FontBBox get
-  aload pop 
-  lfont /FontMatrix get dtransform pop 0.65 mul /lascent exch def
-  lfont /FontMatrix get dtransform pop neg /ldescent exch def
-% begin gdt mod
-% define font for xplot characters
-/BuildCharDict 10 dict def
-/Xplotfontdict 7 dict def
-Xplotfontdict begin
-  /FontType 3 def
-  /FontMatrix [1 0 0 1 0 0] def
-  /FontBBox [-1 -1 1 1]def
-  /Encoding 256 array def
-  0 1 255 {Encoding exch /.notdef put} for
-  Encoding (.) 0 get /xplotfontdot put
-  /CharacterDefs 3 dict def
-  CharacterDefs /.notdef {} put
-  CharacterDefs /xplotfontdot
-    { newpath
-   0 0 1 0 360 arc fill
-    } put
-  /BuildChar
-    { BuildCharDict begin
-   /char exch def
-   /fontdict exch def
-   /charname fontdict /Encoding get
-   char get def
-   /charproc fontdict /CharacterDefs
-        get charname get def
-   1 0 -1 -1 1 1 setcachedevice
-   gsave charproc grestore
-      end
-    } def
-end
-/XplotFont Xplotfontdict definefont pop
-% scale font according to theta
-/dotsetup { /dotfont /XplotFont findfont 4 theta scalefont def } def
-% DONE gdt mod
-%define procedures for each xplot primitive.
-% x y x --
-/x {moveto 8 8 rlineto -16 -16 rlineto
-    8 8 rmoveto
-    -8 8 rlineto 16 -16 rlineto} def
-% x y + --
-/+ {moveto 0 8 rlineto 0 -16 rlineto
-    0 8 rmoveto
-    -8 0 rlineto 16 0 rlineto} def
-% x y ?arrow --
-/darrow {moveto 8 theta 8 theta rmoveto -8 theta -8 theta rlineto
-         -8 theta 8 theta rlineto } def
-/uarrow {moveto -8 theta -8 theta rmoveto 8 theta 8 theta rlineto
-         8 theta -8 theta rlineto } def
-/rarrow {moveto -8 theta 8 theta rmoveto 8 theta -8 theta rlineto
-         -8 theta -8 theta rlineto } def
-/larrow {moveto 8 theta 8 theta rmoveto -8 theta -8 theta rlineto
-         8 theta -8 theta rlineto } def
-%x y x y line --
-/line {moveto lineto} def
-%x y dot --
-% begin gdt mod
-/dot { moveto dotfont setfont (.) show } def
-%/dot {stroke 8 theta 0 360 arc fill} def
-% end gdt mod
-%x y plus --
-/plus {moveto -16 theta 0 rmoveto 16 theta 0 rlineto 
-       -16 theta -16 theta rmoveto 0 16 theta rlineto} def
-%x y box --
-/box {moveto -8 theta -8 theta rmoveto
-      16 theta 0 rlineto 
-      0 16 theta rlineto
-      -16 theta 0 rlineto
-      0 -16 theta rlineto} def
-%x y diamond --
-/diamond { moveto 0 theta 24 theta rmoveto
-           -24 theta -24 theta rlineto
-            24 theta -24 theta rlineto
-            24 theta  24 theta rlineto
-           -24 theta  24 theta rlineto} def
-%x y ?tick --
-/utick {moveto 0 6 theta rlineto} def
-/dtick {moveto 0 -6 theta rlineto} def
-/ltick {moveto -6 theta 0 rlineto} def
-/rtick {moveto 6 theta 0 rlineto} def
-/htick {moveto -6 theta 0 rmoveto 12 theta 0 rlineto} def
-/vtick {moveto 0 -6 theta rmoveto 0 12 theta rlineto} def
-%Separate functions for each text position.
-%x y string ?text --
-/space 6 pt def
-% Set the font, figure out the width.
-% x y string tsetup string x width y
-/tsetup {lfont setfont dup stringwidth pop exch
-         4 1 roll exch} def
-%CENTER
-/ctext {tsetup lascent 2 div sub
-        3 1 roll 2 div sub exch
-% stack should now be string x y
-        moveto show} def
-%ABOVE
-/atext {tsetup space ldescent add add
-        3 1 roll 2 div sub exch moveto show} def
-%BELOW
-/btext {tsetup space lascent add sub
-        3 1 roll 2 div sub exch moveto show} def
-%TO_THE_LEFT
-/ltext {tsetup lascent 2 div sub
-        3 1 roll space add sub exch moveto show} def
-%TO_THE_RIGHT
-/rtext {tsetup lascent 2 div sub
-        3 1 roll pop space add exch moveto show} def
+  fputs("/pt {inch 72 div} def\n\
+%\n\
+%\n\
+/tfont /Times-Bold findfont 12 pt scalefont def\n\
+%\n\
+/lfont /Times-Roman findfont 10 pt scalefont def\n\
+%\n\
+%tfont /FontBBox get\n\
+%  aload pop\n\
+%  tfont /FontMatrix get dtransform pop /tascent exch def\n\
+%  tfont /FontMatrix get dtransform pop neg /tdescent exch def\n\
+lfont /FontBBox get\n\
+  aload pop\n\
+  lfont /FontMatrix get dtransform pop 0.65 mul /lascent exch def\n\
+  lfont /FontMatrix get dtransform pop neg /ldescent exch def\n\
+% begin gdt mod\n\
+% define font for xplot characters\n\
+/BuildCharDict 10 dict def\n\
+/Xplotfontdict 7 dict def\n\
+Xplotfontdict begin\n\
+  /FontType 3 def\n\
+  /FontMatrix [1 0 0 1 0 0] def\n\
+  /FontBBox [-1 -1 1 1]def\n\
+  /Encoding 256 array def\n\
+  0 1 255 {Encoding exch /.notdef put} for\n\
+  Encoding (.) 0 get /xplotfontdot put\n\
+  /CharacterDefs 3 dict def\n\
+  CharacterDefs /.notdef {} put\n\
+  CharacterDefs /xplotfontdot\n\
+    { newpath\n\
+   0 0 1 0 360 arc fill\n\
+    } put\n\
+  /BuildChar\n\
+    { BuildCharDict begin\n\
+   /char exch def\n\
+   /fontdict exch def\n\
+   /charname fontdict /Encoding get\n\
+   char get def\n\
+   /charproc fontdict /CharacterDefs\n\
+        get charname get def\n\
+   1 0 -1 -1 1 1 setcachedevice\n\
+   gsave charproc grestore\n\
+      end\n\
+    } defn\n\
+end\n\
+/XplotFont Xplotfontdict definefont pop\n\
+% scale font according to theta\n\
+/dotsetup { /dotfont /XplotFont findfont 4 theta scalefont def } def\n\
+% DONE gdt mod\n\
+%define procedures for each xplot primitive.\n\
+% x y x --\n\
+/x {moveto 8 8 rlineto -16 -16 rlineto\n\
+    8 8 rmoveto\n\
+    -8 8 rlineto 16 -16 rlineto} def\n\
+% x y + --\n\
+/+ {moveto 0 8 rlineto 0 -16 rlineto\n\
+    0 8 rmoveto\n\
+    -8 0 rlineto 16 0 rlineto} def\n\
+% x y ?arrow --\n\
+/darrow {moveto 8 theta 8 theta rmoveto -8 theta -8 theta rlineto\n\
+         -8 theta 8 theta rlineto } def\n\
+/uarrow {moveto -8 theta -8 theta rmoveto 8 theta 8 theta rlineto\n\
+         8 theta -8 theta rlineto } def\n\
+/rarrow {moveto -8 theta 8 theta rmoveto 8 theta -8 theta rlineto\n\
+         -8 theta -8 theta rlineto } def\n\
+/larrow {moveto 8 theta 8 theta rmoveto -8 theta -8 theta rlineto\n\
+         8 theta -8 theta rlineto } def\n\
+%x y x y line --\n\
+/line {moveto lineto} def\n\
+%x y dot --\n\
+% begin gdt mod\n\
+/dot { moveto dotfont setfont (.) show } def\n\
+%/dot {stroke 8 theta 0 360 arc fill} def\n\
+% end gdt mod\n\
+%x y plus --\n\
+/plus {moveto -16 theta 0 rmoveto 16 theta 0 rlineto\n\
+       -16 theta -16 theta rmoveto 0 16 theta rlineto} def\n\
+%x y box --\n\
+/box {moveto -8 theta -8 theta rmoveto\n\
+      16 theta 0 rlineto\n\
+      0 16 theta rlineto\n\
+      -16 theta 0 rlineto\n\
+      0 -16 theta rlineto} def\n\
+%x y diamond --\n\
+/diamond { moveto 0 theta 24 theta rmoveto\n\
+           -24 theta -24 theta rlineto\n\
+            24 theta -24 theta rlineto\n\
+            24 theta  24 theta rlineto\n\
+           -24 theta  24 theta rlineto} def\n\
+%x y ?tick --\n\
+/utick {moveto 0 6 theta rlineto} def\n\
+/dtick {moveto 0 -6 theta rlineto} def\n\
+/ltick {moveto -6 theta 0 rlineto} def\n\
+/rtick {moveto 6 theta 0 rlineto} def\n\
+/htick {moveto -6 theta 0 rmoveto 12 theta 0 rlineto} def\n\
+/vtick {moveto 0 -6 theta rmoveto 0 12 theta rlineto} def\n\
+%Separate functions for each text position.\n\
+%x y string ?text --\n\
+/space 6 pt def\n\
+% Set the font, figure out the width.\n\
+% x y string tsetup string x width y\n\
+/tsetup {lfont setfont dup stringwidth pop exch\n\
+         4 1 roll exch} def\n\
+%CENTER\n\
+/ctext {tsetup lascent 2 div sub\n\
+        3 1 roll 2 div sub exch\n\
+% stack should now be string x y\n\
+        moveto show} def\n\
+%ABOVE\n\
+/atext {tsetup space ldescent add add\n\
+        3 1 roll 2 div sub exch moveto show} def\n\
+%BELOW\n\
+/btext {tsetup space lascent add sub\n\
+        3 1 roll 2 div sub exch moveto show} def\n\
+%TO_THE_LEFT\n\
+/ltext {tsetup lascent 2 div sub\n\
+        3 1 roll space add sub exch moveto show} def\n\
+%TO_THE_RIGHT\n\
+/rtext {tsetup lascent 2 div sub\n\
+        3 1 roll pop space add exch moveto show} def\n\
 ", fp);
 
   {
@@ -3354,9 +3347,9 @@
   if (state == PRINTING) {
     fputs("-90 rotate -11 inch 0 inch translate\n", fp);
   } else {
-    fputs("
-/notintex { currentdict userdict eq } def
-notintex { 1.5 inch 5.0 inch translate } if
+    fputs("\n\
+/notintex { currentdict userdict eq } def\n\
+notintex { 1.5 inch 5.0 inch translate } if\n\
 ", fp);
   }
   /* Move origin to create left & bottom margins. */