1
/*===========================================================================
2
Copyright (C) 1995-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
29
* HEADER : pscrdrv.c - Vers 3.6.010 - Jul 1994 - L. Fini, OAA
37
/*****************************************************************************/
38
/* AGL PostScript driver - L. Fini Jun 1987 */
39
/* - L. Fini Oct 1991 (Color support added) */
41
/* This driver is based on a FORTRAN version provided by Alco Blom for */
44
/* This driver allows selection of landscape(default) and Portrait mode by */
45
/* means of the USRAUX portion of the device definition string. */
47
/* Output orientation and size default to landscape A4. Different selection */
48
/* can be made when the first viewport is opened onto the device by means of */
49
/* format specifications characters with the following meanings: */
58
/* The selection characters are to be appendend to the device name, separa- */
59
/* ted by a point as in the following examples: */
61
/* iv=AG_VDEF("ps.p:",.......) selects portrait A4 */
63
/* iv=AG_VDEF("ps.p4:",.......) selects portrait A4 */
65
/* iv=AG_VDEF("ps.pu:",.......) selects portrait US-legal */
67
/* iv=AG_VDEF("ps.3:",.......) selects portrait A3 */
69
/* iv=AG_VDEF("ps.l3:",.......) selects landscape A3 */
71
/* (the characters: p,l,3,4,u can be put in any number and sequence. The */
72
/* last encountered only will take effect) */
83
/* The following entry points have been defined: */
85
/* Function Entry point */
87
/* Initialize AGLINPS0 */
88
/* Cursor en. AGLCUPS0 */
91
/* Polyline AGLPLPS0 */
93
/* Flush buff. AGLSEPS0 */
97
/* device parameters definition */
99
#define VERSCODE 36 /* Declare driver version */
105
#define PSFLAGS SEPALPHA | EXECOMMND | SETBACKGR
106
#define PSMAXLWIDTH 4
108
#define PSBLACK 0 /* Bot index and grayscale value */
109
#define PSWHITE 1 /* Bot index and grayscale value */
120
#define CVTX(x) ((int)((x)*xfact))+1
121
#define CVTY(y) ((int)((y)*yfact))+1
124
/* To allow for good resolution with small file length the driver uses */
125
/* an arbitrary set of coordinates so that numbers are never greater than */
126
/* 10000 for A4 format. The PostScript scale factor is then used to adjust */
127
/* for standard PostScript coordinates (1/72 of an inch). The following */
128
/* values are the required conversion factors. */
131
/* US Legal Landscape mode --------------------------+ */
132
/* US Legal Portrait mode ---------------------+ | */
133
/* A3 Landscape mode -------------------+ | | */
134
/* A3 Portrait mode --------------+ | | | */
135
/* A4 Landscape mode -------+ | | | | */
136
/* A4 Portrait mode --+ | | | | | */
138
static float FACTC[6] = { 6908, 9999, 9999, 14908,7453, 9817 };
139
static float PSCMAXL[6]= { 19.0, 27.5, 27.5, 41.0, 20.5, 27.0 };
140
static float PSCLENG[6]= { 19.0, 27.5, 27.5, 41.0, 21.0, 27.0 };
141
static float PIXCM[6] = { 363.6364,
147
static float CHARF[6] = { 13.889, /* Char. multip. */
156
static int Size,Sptx,Spty;
158
static double xfact,yfact,xofst,yofst;
159
static double xdim,ydim;
160
static int page_touch; /* TRUE when current page has something into */
161
static int file_touch; /* TRUE when current file has something into */
162
static int cur_color;
163
static int cur_backg;
171
/* PSBLACK */ { 0.0, 0.0, 0.0 },
172
/* PSWHITE */ { 1.0, 1.0, 1.0 },
173
/* PSRED */ { 1.0, 0.0, 0.0 },
174
/* PSGREEN */ { 0.0, 1.0, 0.0 },
175
/* PSBLUE */ { 0.0, 0.0, 1.0 },
176
/* PSYELLOW */ { 1.0, 1.0, 0.0 },
177
/* PSMAGENTA */ { 1.0, 0.0, 1.0 },
178
/* PSCYAN */ { 0.0, 1.0, 1.0 } };
180
static char *hd0 = "%% Page: 1 1\n";
181
static char *hd1 = "/cm { 28.34646 mul } def\n";
182
static char *hd2 = "1.0 cm 1.0 cm translate\n";
183
static char *hd3_us = "20.5 cm 0 cm translate\n90 rotate\n";
184
static char *hd3_a4 = "19.0 cm 0 cm translate\n90 rotate\n";
185
static char *hd3_a3 = "27.5 cm 0 cm translate\n90 rotate\n";
186
static char *hd4 = "0.077960552 0.077960552 scale\n";
187
static char *hd5 = "[] 0 setdash\n";
188
static char hd6[] = "1 6 mul setlinewidth\n";
189
static char *hd7 = "/m { moveto } def\n";
190
static char *hd8 = "/r { rlineto } def\n";
191
static char *hd9 = "/l { 8 { rlineto } repeat } def \n";
192
static char *hd10 = "/c { { rlineto } repeat } def\n";
193
static char *hd11 = "/s { stroke } def\n";
194
static char *hd12 = "/n { newpath } def\n";
195
static char *hd13 = "2 setlinejoin\n";
196
static char *hd14 = "% BEGINNING OF PLOT\n";
200
static void showpage(filpt)
204
static char *show = "showpage % END OF PAGE\n";
206
static char *trail1 = "showpage\n";
207
static char *trail2 = "% END OF PAGE\n";
208
static char *trail3 = "%% Trailer\n";
209
static char *trail4 = "%% EOF\n";
224
void set_pscolor(color) /* set up a given color */
227
fprintf(filpt,"%f %f %f setrgbcolor\n",CTAB[color].red,
236
static void fill_area(xmin,xmax,ymin,ymax,color)
243
fprintf(filpt,"n %d %d moveto\n",xmin,ymin);
244
fprintf(filpt,"%d %d lineto\n",xmax,ymin);
245
fprintf(filpt,"%d %d lineto\n",xmax,ymax);
246
fprintf(filpt,"%d %d lineto\n",xmin,ymax);
248
fprintf(filpt,"closepath fill\n");
250
set_pscolor(cur_color);
254
/*---------------------------------------------------------------------------*/
255
void AGLINPS0 (AGLDVCOM)
256
struct bufcom *AGLDVCOM;
258
/* static char *in00 = "%!PS-Adobe-3.0 EPSF-3.0\n";
259
static char *in01 = "%%BoundingBox: 28 28 ";
260
static char *in01_a4 = "570 810\n";
261
static char *in01_a3 = "810 1208\n";
262
static char *in01_us = "604 795\n";
263
static char *in02 = "%! AGL PostScript driver file header - V 3.61\n";
264
static char *in03 = "%%EndComments\n";
267
static char *in00 = "%!PS-Adobe-3.0 EPSF-3.0\n";
268
static char *in01 = "%%BoundingBox: 28 28 ";
269
static char *in01_a4 = "570 810\n";
270
static char *in01_a3 = "810 1208\n";
271
static char *in01_us = "604 795\n";
272
static char *in02 = "%% Creator: ESO-MIDAS/AGL AGL version 3.61\n";
273
static char *in03 = "%% DocumentNeededResources: font Helvetica\n";
274
static char *in04 = "%% LanguageLevel: 1\n";
275
static char *in05 = "%% Pages: 1\n";
276
static char *in06 = "%% EndComments\n";
278
extern void AG_DMSG();
280
char auxbuf[PHNAMLNG];
281
static char *filnam = "pscrplot";
287
switch((int)IBUFFR(0)) { /* Select function */
288
case 0: /* Hardware initialization */
292
strcpy(auxbuf,filnam);
295
if(*auxbuf == '\0') {
300
filpt=fopen(auxbuf,"w");
303
AG_DMSG("Open error:",auxbuf);
312
rot = TRUE; /* Select default orientation */
313
Size=A4; /* Select default size */
316
while(*pt++); /* Skip device name */
317
while(*pt++); /* Skip SYSAUX info */
318
/* to Get USRAUX string */
319
while(*pt) { /* Scan selection string */
320
switch(TOUPPER(*pt)) {
321
case 'P': /* select portrait mode */
324
case 'L': /* select landscape mode */
339
if(rot) { /* Select rotation */
340
AG_DMSG("Mode:","Landscape");
344
AG_DMSG("Mode:","Portrait");
349
strcpy(CHARBUF,auxbuf); /* Copy filename to buffer */
350
AG_DMSG("Out to:",auxbuf);
355
switch(Size) { /* Select size */
359
AG_DMSG("Size:","A4");
360
fputs(in01_a4,filpt);
365
AG_DMSG("Size:","A3");
366
fputs(in01_a3,filpt);
371
AG_DMSG("Size:","US-legal");
372
fputs(in01_us,filpt);
392
switch(Size) { /* Select size */
417
xdim = (RBUFFR(id0)<PSCMAXL[Sptx]) ? RBUFFR(id0) : PSCMAXL[Sptx];
418
xdim = (xdim<=0.0) ? PSCLENG[Sptx] : xdim;
419
ydim = (RBUFFR(id1)<PSCMAXL[Spty]) ? RBUFFR(id1) : PSCMAXL[Spty];
420
ydim = (ydim<=0.0) ? PSCLENG[Spty] : ydim;
421
xofst = ((PSCMAXL[Sptx]-xdim)*0.5) * FACTC[Sptx];
422
yofst = ((PSCMAXL[Spty]-ydim)*0.5) * FACTC[Spty];
423
xfact = (xdim/PSCMAXL[Sptx]) * FACTC[Sptx];
424
yfact = (ydim/PSCMAXL[Spty]) * FACTC[Spty];
425
xofst *= FACTC[Sptx];
426
yofst *= FACTC[Spty];
429
case 1: /* Pass back device characteristics */
438
IBUFFR(2) = n_colors;
440
IBUFFR(3) = xdim*PIXCM[Sptx];
441
IBUFFR(4) = ydim*PIXCM[Spty];
442
IBUFFR(5) = VERSCODE;
443
IBUFFR(6) = PSMAXLWIDTH;
448
IBUFFR(7) = cur_backg; /* Default Background */
449
IBUFFR(8) = cur_color; /* Default foreground */
452
IBUFFR(11) = PSGREEN;
454
IBUFFR(13) = PSYELLOW;
455
IBUFFR(14) = PSMAGENTA;
457
IBUFFR(16) = PSWHITE;
459
RBUFFR(2) = CHARF[Sptx];
463
RBUFFR(6) = PSCLENG[Sptx];
464
RBUFFR(7) = PSCLENG[Spty];
465
RBUFFR(8) = PSCMAXL[Sptx];
466
RBUFFR(9) = PSCMAXL[Spty];
469
case 2: /* set color */
472
if((cur_color<0)||(cur_color>n_colors))
474
set_pscolor(cur_color);
477
case 3: /* set line style */
478
ERRCODE=AGLNOERR; /* Not used since vers. 3.3 */
481
case 4: /* set line width */
484
switch((int)IBUFFR(1)) {
506
case 6: /* Coordinate roundoff */
507
break; /* Unnecessary for high resol. devices */
512
static int xv[8], yv[8];
514
static void trace(filpt,xx,yy)
524
fprintf(filpt,"%d %d ", xv[cnt], yv[cnt]);
526
fprintf(filpt,"l\n");
531
static void trace_flush(filpt)
536
fprintf(filpt,"%d %d r ",xv[0],yv[0]);
541
fprintf(filpt,"%d %d ", xv[cnt], yv[cnt]);
543
fprintf(filpt,"%d c ",cnts);
546
fprintf(filpt,"s\n");
550
/*---------------------------------------------------------------------------*/
551
void AGLPLPS0(AGLDVCOM)
552
struct bufcom *AGLDVCOM;
555
float *vectx, *vecty;
569
if(cur_color != cur_backg)
575
fprintf(filpt,"n %d %d m\n", /* Move to first point */
577
(y0=CVTY(*vecty++)));
579
xx=CVTX(*vectx++)-x0;
580
yy=CVTY(*vecty++)-y0;
582
/* the usual trace_flush doesn't draw anything
583
=> missing point on the `i' char.
584
so we make a 1x1 `filled' square */
586
if ((n == 2) && (xx == 0) && (yy == 0))
589
fprintf(filpt,"%d %d ", xx,yy);
591
fprintf(filpt,"%d %d ", xx,yy);
593
fprintf(filpt,"%d %d ", xx,yy);
595
fprintf(filpt,"%d %d ", xx,yy);
597
fprintf(filpt,"%d %d ", xx,yy);
599
fprintf(filpt,"%d %d ", xx,yy);
601
fprintf(filpt,"%d %d ", xx,yy);
602
fprintf(filpt,"7 c "); /* 7 line segments */
603
fprintf(filpt,"s\n");
608
trace(filpt,xx,yy); /* Trace to second point */
610
x0 += xx; y0 += yy; n--;
635
/*---------------------------------------------------------------------------*/
636
void AGLCUPS0(AGLDVCOM)
637
struct bufcom *AGLDVCOM;
642
/*---------------------------------------------------------------------------*/
643
void AGLERPS0(AGLDVCOM)
644
struct bufcom *AGLDVCOM;
646
int xmin,xmax,ymin,ymax;
650
xmin = CVTX(RBUFFR(0)); xmax = CVTX(RBUFFR(1));
651
ymin = CVTY(RBUFFR(2)); ymax = CVTY(RBUFFR(3));
653
if((xmin==CVTX(0.0))&&(xmax==CVTX(1.0))&& /* Eject page, if the entire */
654
(ymin==CVTY(0.0))&&(ymax==CVTY(1.0)) ){ /* page is erased */
661
cur_backg = IBUFFR(0);
663
if((cur_backg<0)||(cur_backg>n_colors))
666
fill_area(xmin,xmax,ymin,ymax,cur_backg);
669
/*---------------------------------------------------------------------------*/
670
void AGLESPS0(AGLDVCOM)
671
struct bufcom *AGLDVCOM;
676
/*---------------------------------------------------------------------------*/
677
void AGLSEPS0(AGLDVCOM)
678
struct bufcom *AGLDVCOM;
683
/*---------------------------------------------------------------------------*/
684
void AGLTEPS0(AGLDVCOM)
685
struct bufcom *AGLDVCOM;
687
extern void AG_DMSG();
690
fclose(filpt); filpt=NULL;
692
AG_DMSG("Out file","closed");
695
IBUFFR(0)= !file_touch;