The R Project SVN R

Rev

Rev 8813 | Rev 10960 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8813 Rev 9004
Line 26... Line 26...
26
#include "Fileio.h"
26
#include "Fileio.h"
27
 
27
 
28
	/* device-specific information per picTeX device */
28
	/* device-specific information per picTeX device */
29
 
29
 
30
typedef struct {
30
typedef struct {
31
	FILE *texfp;
31
    FILE *texfp;
32
	char filename[128];
32
    char filename[128];
33
	int pageno;
33
    int pageno;
34
	int landscape;
34
    int landscape;
35
	double width;
35
    double width;
36
	double height;
36
    double height;
37
	double pagewidth;
37
    double pagewidth;
38
	double pageheight;
38
    double pageheight;
39
	double xlast;
39
    double xlast;
40
	double ylast;
40
    double ylast;
41
	double clipleft, clipright, cliptop, clipbottom;
41
    double clipleft, clipright, cliptop, clipbottom;
42
	double clippedx0, clippedy0, clippedx1, clippedy1;
42
    double clippedx0, clippedy0, clippedx1, clippedy1;
43
	int lty;
43
    int lty;
44
	rcolor col;
44
    rcolor col;
45
	rcolor fg;
45
    rcolor fg;
46
	rcolor bg;
46
    rcolor bg;
47
	int fontsize;
47
    int fontsize;
48
	int fontface;
48
    int fontface;
49
	int debug;
49
    int debug;
50
} picTeXDesc;
50
} picTeXDesc;
51
 
51
 
52
 
52
 
53
	/* Global device information */
53
	/* Global device information */
54
 
54
 
Line 169... Line 169...
169
 
169
 
170
	/* Support routines */
170
	/* Support routines */
171
 
171
 
172
static void SetLinetype(int newlty, int newlwd, DevDesc *dd)
172
static void SetLinetype(int newlty, int newlwd, DevDesc *dd)
173
{
173
{
174
	picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
174
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
175
 
175
 
176
	int i, templty;
176
    int i, templty;
177
	ptd->lty = newlty;
177
    ptd->lty = newlty;
178
	if (ptd->lty) {
178
    if (ptd->lty) {
179
		fprintf(ptd->texfp,"\\setdashpattern <");
179
	fprintf(ptd->texfp,"\\setdashpattern <");
180
		for(i=0 ; i<8 && newlty&15 ; i++) {
180
	for(i=0 ; i<8 && newlty&15 ; i++) {
181
			fprintf(ptd->texfp,"%dpt", newlwd * newlty&15);
181
	    fprintf(ptd->texfp,"%dpt", newlwd * newlty&15);
182
			templty = newlty>>4;
182
	    templty = newlty>>4;
183
			if ((i+1)<8 && templty&15) fprintf(ptd->texfp,", ");
183
	    if ((i+1)<8 && templty&15) fprintf(ptd->texfp,", ");
184
			newlty = newlty>>4;
184
	    newlty = newlty>>4;
185
		}
185
	}
186
		fprintf(ptd->texfp,">\n");
186
	fprintf(ptd->texfp,">\n");
187
	} else fprintf(ptd->texfp,"\\setsolid\n");
187
    } else fprintf(ptd->texfp,"\\setsolid\n");
188
}
188
}
189
 
189
 
190
 
190
 
191
static void SetFont(int face, int size, picTeXDesc *ptd)
191
static void SetFont(int face, int size, picTeXDesc *ptd)
192
{
192
{
193
	int lface=face, lsize= size;
193
    int lface=face, lsize= size;
194
	if(lface < 1 || lface > 4) lface = 1;
194
    if(lface < 1 || lface > 4) lface = 1;
195
	if(lsize < 1 || lsize > 24) lsize = 10;
195
    if(lsize < 1 || lsize > 24) lsize = 10;
196
	if(lsize != ptd->fontsize || lface != ptd->fontface) {
196
    if(lsize != ptd->fontsize || lface != ptd->fontface) {
197
		fprintf(ptd->texfp, "\\font\\picfont %s at %dpt\\picfont\n",
197
	fprintf(ptd->texfp, "\\font\\picfont %s at %dpt\\picfont\n",
198
			fontname[lface-1], lsize);
198
		fontname[lface-1], lsize);
199
		ptd->fontsize = lsize;
199
	ptd->fontsize = lsize;
200
		ptd->fontface = lface;
200
	ptd->fontface = lface;
201
	}
201
    }
202
}
202
}
203
 
203
 
204
static void PicTeX_Activate(DevDesc *dd)
204
static void PicTeX_Activate(DevDesc *dd)
205
{
205
{
206
}
206
}
Line 247... Line 247...
247
}
247
}
248
 
248
 
249
static void PicTeX_Clip(double x0, double x1, double y0, double y1,
249
static void PicTeX_Clip(double x0, double x1, double y0, double y1,
250
			DevDesc *dd)
250
			DevDesc *dd)
251
{
251
{
252
	picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
252
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
253
 
253
 
254
	if(ptd->debug)
254
    if(ptd->debug)
255
	fprintf(ptd->texfp, "%% Setting Clip Region to %.2f %.2f %.2f %.2f\n",
255
	fprintf(ptd->texfp, "%% Setting Clip Region to %.2f %.2f %.2f %.2f\n",
256
		x0, y0, x1, y1);
256
		x0, y0, x1, y1);
257
	ptd->clipleft = x0;
257
    ptd->clipleft = x0;
258
	ptd->clipright = x1;
258
    ptd->clipright = x1;
259
	ptd->clipbottom = y0;
259
    ptd->clipbottom = y0;
260
	ptd->cliptop = y1;
260
    ptd->cliptop = y1;
261
}
261
}
262
 
262
 
263
	/* Start a new page */
263
	/* Start a new page */
264
 
264
 
265
static void PicTeX_NewPage(DevDesc *dd)
265
static void PicTeX_NewPage(DevDesc *dd)
266
{
266
{
267
	picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
267
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
268
 
268
 
269
	int face, size;
269
    int face, size;
270
	if (ptd->pageno) {
270
    if (ptd->pageno) {
271
		fprintf(ptd->texfp, "\\endpicture\n}\n\n\n");
271
	fprintf(ptd->texfp, "\\endpicture\n}\n\n\n");
272
		fprintf(ptd->texfp, "\\hbox{\\beginpicture\n");
272
	fprintf(ptd->texfp, "\\hbox{\\beginpicture\n");
273
		fprintf(ptd->texfp, "\\setcoordinatesystem units <1pt,1pt>\n");
273
	fprintf(ptd->texfp, "\\setcoordinatesystem units <1pt,1pt>\n");
274
		fprintf(ptd->texfp,
274
	fprintf(ptd->texfp,
275
			"\\setplotarea x from 0 to %.2f, y from 0 to %.2f\n",
275
		"\\setplotarea x from 0 to %.2f, y from 0 to %.2f\n",
276
			ptd->width * 72.27, ptd->height * 72.27);
276
		ptd->width * 72.27, ptd->height * 72.27);
277
		fprintf(ptd->texfp,"\\setlinear\n");
277
	fprintf(ptd->texfp,"\\setlinear\n");
278
		fprintf(ptd->texfp, "\\font\\picfont cmss10\\picfont\n");
278
	fprintf(ptd->texfp, "\\font\\picfont cmss10\\picfont\n");
279
	}
279
    }
280
	ptd->pageno +=1;
280
    ptd->pageno +=1;
281
	face = ptd->fontface;
281
    face = ptd->fontface;
282
	size = ptd->fontsize;
282
    size = ptd->fontsize;
283
	ptd->fontface = 0;
283
    ptd->fontface = 0;
284
	ptd->fontsize = 0;
284
    ptd->fontsize = 0;
285
	SetFont(face, size, ptd);
285
    SetFont(face, size, ptd);
286
}
286
}
287
 
287
 
288
	/* Close down the driver */
288
	/* Close down the driver */
289
 
289
 
290
static void PicTeX_Close(DevDesc *dd)
290
static void PicTeX_Close(DevDesc *dd)
Line 310... Line 310...
310
	/* Draw To */
310
	/* Draw To */
311
 
311
 
312
static void PicTeX_ClipLine(double x0, double y0, double x1, double y1,
312
static void PicTeX_ClipLine(double x0, double y0, double x1, double y1,
313
			    picTeXDesc *ptd)
313
			    picTeXDesc *ptd)
314
{
314
{
315
	ptd->clippedx0 = x0; ptd->clippedx1 = x1;
315
    ptd->clippedx0 = x0; ptd->clippedx1 = x1;
316
	ptd->clippedy0 = y0; ptd->clippedy1 = y1;
316
    ptd->clippedy0 = y0; ptd->clippedy1 = y1;
317
 
-
 
318
	if ((ptd->clippedx0 < ptd->clipleft &&
-
 
319
	     ptd->clippedx1 < ptd->clipleft) ||
-
 
320
	    (ptd->clippedx0 > ptd->clipright &&
-
 
321
	     ptd->clippedx1 > ptd->clipright) ||
-
 
322
	    (ptd->clippedy0 < ptd->clipbottom &&
-
 
323
	     ptd->clippedy1 < ptd->clipbottom) ||
-
 
324
	    (ptd->clippedy0 > ptd->cliptop &&
-
 
325
	     ptd->clippedy1 > ptd->cliptop)) {
-
 
326
		ptd->clippedx0 = ptd->clippedx1;
-
 
327
		ptd->clippedy0 = ptd->clippedy1;
-
 
328
		return;
-
 
329
	}
-
 
330
 
317
 
-
 
318
    if ((ptd->clippedx0 < ptd->clipleft &&
-
 
319
	 ptd->clippedx1 < ptd->clipleft) ||
-
 
320
	(ptd->clippedx0 > ptd->clipright &&
-
 
321
	 ptd->clippedx1 > ptd->clipright) ||
-
 
322
	(ptd->clippedy0 < ptd->clipbottom &&
-
 
323
	 ptd->clippedy1 < ptd->clipbottom) ||
-
 
324
	(ptd->clippedy0 > ptd->cliptop &&
-
 
325
	 ptd->clippedy1 > ptd->cliptop)) {
-
 
326
	ptd->clippedx0 = ptd->clippedx1;
-
 
327
	ptd->clippedy0 = ptd->clippedy1;
-
 
328
	return;
-
 
329
    }
-
 
330
 
331
	/*Clipping Left */
331
    /*Clipping Left */
332
	if (ptd->clippedx1 >= ptd->clipleft && ptd->clippedx0 < ptd->clipleft) {
332
    if (ptd->clippedx1 >= ptd->clipleft && ptd->clippedx0 < ptd->clipleft) {
333
		ptd->clippedy0 = ((ptd->clippedy1-ptd->clippedy0) /
333
	ptd->clippedy0 = ((ptd->clippedy1-ptd->clippedy0) /
334
				  (ptd->clippedx1-ptd->clippedx0) *
334
			  (ptd->clippedx1-ptd->clippedx0) *
335
				  (ptd->clipleft-ptd->clippedx0)) +
335
			  (ptd->clipleft-ptd->clippedx0)) +
336
				 ptd->clippedy0;
336
	    ptd->clippedy0;
337
		ptd->clippedx0 = ptd->clipleft;
337
	ptd->clippedx0 = ptd->clipleft;
338
	}
338
    }
339
	if (ptd->clippedx1 <= ptd->clipleft && ptd->clippedx0 > ptd->clipleft) {
339
    if (ptd->clippedx1 <= ptd->clipleft && ptd->clippedx0 > ptd->clipleft) {
340
		ptd->clippedy1 = ((ptd->clippedy1-ptd->clippedy0) /
340
	ptd->clippedy1 = ((ptd->clippedy1-ptd->clippedy0) /
341
				  (ptd->clippedx1-ptd->clippedx0) *
341
			  (ptd->clippedx1-ptd->clippedx0) *
342
				  (ptd->clipleft-ptd->clippedx0)) +
342
			  (ptd->clipleft-ptd->clippedx0)) +
343
				 ptd->clippedy0;
343
	    ptd->clippedy0;
344
		ptd->clippedx1 = ptd->clipleft;
344
	ptd->clippedx1 = ptd->clipleft;
345
	}
345
    }
346
	/* Clipping Right */
346
    /* Clipping Right */
347
	if (ptd->clippedx1 >= ptd->clipright &&
347
    if (ptd->clippedx1 >= ptd->clipright &&
348
	    ptd->clippedx0 < ptd->clipright) {
348
	ptd->clippedx0 < ptd->clipright) {
349
		ptd->clippedy1 = ((ptd->clippedy1-ptd->clippedy0) /
349
	ptd->clippedy1 = ((ptd->clippedy1-ptd->clippedy0) /
350
				  (ptd->clippedx1-ptd->clippedx0) *
350
			  (ptd->clippedx1-ptd->clippedx0) *
351
				  (ptd->clipright-ptd->clippedx0)) +
351
			  (ptd->clipright-ptd->clippedx0)) +
352
				 ptd->clippedy0;
352
	    ptd->clippedy0;
353
		ptd->clippedx1 = ptd->clipright;
353
	ptd->clippedx1 = ptd->clipright;
354
	}
354
    }
355
	if (ptd->clippedx1 <= ptd->clipright &&
355
    if (ptd->clippedx1 <= ptd->clipright &&
356
	    ptd->clippedx0 > ptd->clipright) {
356
	ptd->clippedx0 > ptd->clipright) {
357
		ptd->clippedy0 = ((ptd->clippedy1-ptd->clippedy0) /
357
	ptd->clippedy0 = ((ptd->clippedy1-ptd->clippedy0) /
358
				  (ptd->clippedx1-ptd->clippedx0) *
358
			  (ptd->clippedx1-ptd->clippedx0) *
359
				  (ptd->clipright-ptd->clippedx0)) +
359
			  (ptd->clipright-ptd->clippedx0)) +
360
				 ptd->clippedy0;
360
	    ptd->clippedy0;
361
		ptd->clippedx0 = ptd->clipright;
361
	ptd->clippedx0 = ptd->clipright;
362
	}
362
    }
363
	/*Clipping Bottom */
363
    /*Clipping Bottom */
364
	if (ptd->clippedy1 >= ptd->clipbottom  &&
364
    if (ptd->clippedy1 >= ptd->clipbottom  &&
365
	    ptd->clippedy0 < ptd->clipbottom ) {
365
	ptd->clippedy0 < ptd->clipbottom ) {
366
		ptd->clippedx0 = ((ptd->clippedx1-ptd->clippedx0) /
366
	ptd->clippedx0 = ((ptd->clippedx1-ptd->clippedx0) /
367
				  (ptd->clippedy1-ptd->clippedy0) *
367
			  (ptd->clippedy1-ptd->clippedy0) *
368
				  (ptd->clipbottom -ptd->clippedy0)) +
368
			  (ptd->clipbottom -ptd->clippedy0)) +
369
				 ptd->clippedx0;
369
	    ptd->clippedx0;
370
		ptd->clippedy0 = ptd->clipbottom ;
370
	ptd->clippedy0 = ptd->clipbottom ;
371
	}
371
    }
372
	if (ptd->clippedy1 <= ptd->clipbottom &&
372
    if (ptd->clippedy1 <= ptd->clipbottom &&
373
	    ptd->clippedy0 > ptd->clipbottom ) {
373
	ptd->clippedy0 > ptd->clipbottom ) {
374
		ptd->clippedx1 = ((ptd->clippedx1-ptd->clippedx0) /
374
	ptd->clippedx1 = ((ptd->clippedx1-ptd->clippedx0) /
375
				  (ptd->clippedy1-ptd->clippedy0) *
375
			  (ptd->clippedy1-ptd->clippedy0) *
376
				  (ptd->clipbottom -ptd->clippedy0)) +
376
			  (ptd->clipbottom -ptd->clippedy0)) +
377
				 ptd->clippedx0;
377
	    ptd->clippedx0;
378
		ptd->clippedy1 = ptd->clipbottom ;
378
	ptd->clippedy1 = ptd->clipbottom ;
379
	}
379
    }
380
	/*Clipping Top */
380
    /*Clipping Top */
381
	if (ptd->clippedy1 >= ptd->cliptop  && ptd->clippedy0 < ptd->cliptop ) {
381
    if (ptd->clippedy1 >= ptd->cliptop  && ptd->clippedy0 < ptd->cliptop ) {
382
		ptd->clippedx1 = ((ptd->clippedx1-ptd->clippedx0) /
382
	ptd->clippedx1 = ((ptd->clippedx1-ptd->clippedx0) /
383
				  (ptd->clippedy1-ptd->clippedy0) *
383
			  (ptd->clippedy1-ptd->clippedy0) *
384
				  (ptd->cliptop -ptd->clippedy0)) +
384
			  (ptd->cliptop -ptd->clippedy0)) +
385
				 ptd->clippedx0;
385
	    ptd->clippedx0;
386
		ptd->clippedy1 = ptd->cliptop ;
386
	ptd->clippedy1 = ptd->cliptop ;
387
	}
387
    }
388
	if (ptd->clippedy1 <= ptd->cliptop && ptd->clippedy0 > ptd->cliptop ) {
388
    if (ptd->clippedy1 <= ptd->cliptop && ptd->clippedy0 > ptd->cliptop ) {
389
		ptd->clippedx0 = ((ptd->clippedx1-ptd->clippedx0) /
389
	ptd->clippedx0 = ((ptd->clippedx1-ptd->clippedx0) /
390
				  (ptd->clippedy1-ptd->clippedy0) *
390
			  (ptd->clippedy1-ptd->clippedy0) *
391
				  (ptd->cliptop -ptd->clippedy0)) +
391
			  (ptd->cliptop -ptd->clippedy0)) +
392
				 ptd->clippedx0;
392
	    ptd->clippedx0;
393
		ptd->clippedy0 = ptd->cliptop ;
393
	ptd->clippedy0 = ptd->cliptop ;
394
	}
394
    }
395
}
395
}
396
 
396
 
397
static void PicTeX_Line(double x1, double y1, double x2, double y2,
397
static void PicTeX_Line(double x1, double y1, double x2, double y2,
398
			int coords, DevDesc *dd)
398
			int coords, DevDesc *dd)
399
{
399
{
Line 420... Line 420...
420
}
420
}
421
 
421
 
422
static void PicTeX_Polyline(int n, double *x, double *y, int coords,
422
static void PicTeX_Polyline(int n, double *x, double *y, int coords,
423
			    DevDesc* dd)
423
			    DevDesc* dd)
424
{
424
{
425
	double x1, y1, x2, y2;
425
    double x1, y1, x2, y2;
426
	int i;
426
    int i;
427
	picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
427
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
428
 
428
 
429
	SetLinetype(dd->gp.lty, dd->gp.lwd, dd);
429
    SetLinetype(dd->gp.lty, dd->gp.lwd, dd);
430
	x1 = x[0];
430
    x1 = x[0];
431
	y1 = y[0];
431
    y1 = y[0];
432
	GConvert(&x1, &y1, coords, DEVICE, dd);
432
    GConvert(&x1, &y1, coords, DEVICE, dd);
433
	for (i=1; i<n; i++) {
433
    for (i=1; i<n; i++) {
434
		x2 = x[i];
434
	x2 = x[i];
435
		y2 = y[i];
435
	y2 = y[i];
436
		GConvert(&x2, &y2, coords, DEVICE, dd);
436
	GConvert(&x2, &y2, coords, DEVICE, dd);
437
		PicTeX_ClipLine(x1, y1, x2, y2, ptd);
437
	PicTeX_ClipLine(x1, y1, x2, y2, ptd);
438
		fprintf(ptd->texfp, "\\plot %.2f %.2f %.2f %.2f /\n",
438
	fprintf(ptd->texfp, "\\plot %.2f %.2f %.2f %.2f /\n",
439
			ptd->clippedx0, ptd->clippedy0,
439
		ptd->clippedx0, ptd->clippedy0,
440
			ptd->clippedx1, ptd->clippedy1);
440
		ptd->clippedx1, ptd->clippedy1);
441
	}
441
    }
442
}
442
}
443
 
443
 
444
	/* String Width in Rasters */
444
	/* String Width in Rasters */
445
	/* For the current font in pointsize fontsize */
445
	/* For the current font in pointsize fontsize */
446
 
446
 
447
static double PicTeX_StrWidth(char *str, DevDesc *dd)
447
static double PicTeX_StrWidth(char *str, DevDesc *dd)
448
{
448
{
449
	picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
449
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
450
 
450
 
451
	char *p;
451
    char *p;
452
	int size;
452
    int size;
453
	double sum;
453
    double sum;
454
	size = dd->gp.cex * dd->gp.ps + 0.5;
454
    size = dd->gp.cex * dd->gp.ps + 0.5;
455
	SetFont(dd->gp.font, size, ptd);
455
    SetFont(dd->gp.font, size, ptd);
456
	sum = 0;
456
    sum = 0;
457
	for(p=str ; *p ; p++)
457
    for(p=str ; *p ; p++)
458
		sum += charwidth[ptd->fontface-1][(int)*p];
458
	sum += charwidth[ptd->fontface-1][(int)*p];
459
	return sum * ptd->fontsize;
459
    return sum * ptd->fontsize;
460
}
460
}
461
 
461
 
462
 
462
 
463
 
463
 
464
 
464
 
Line 479... Line 479...
479
 
479
 
480
/* Possibly Filled Rectangle */
480
/* Possibly Filled Rectangle */
481
static void PicTeX_Rect(double x0, double y0, double x1, double y1,
481
static void PicTeX_Rect(double x0, double y0, double x1, double y1,
482
			int coords, int bg, int fg, DevDesc *dd)
482
			int coords, int bg, int fg, DevDesc *dd)
483
{
483
{
484
	double x[4], y[4];
484
    double x[4], y[4];
485
	x[0] = x0; y[0] = y0;
485
    x[0] = x0; y[0] = y0;
486
	x[1] = x0; y[1] = y1;
486
    x[1] = x0; y[1] = y1;
487
	x[2] = x1; y[2] = y1;
487
    x[2] = x1; y[2] = y1;
488
	x[3] = x1; y[3] = y0;
488
    x[3] = x1; y[3] = y0;
489
	PicTeX_Polygon(4, x, y, coords, bg, fg, dd);
489
    PicTeX_Polygon(4, x, y, coords, bg, fg, dd);
490
}
490
}
491
 
491
 
492
static void PicTeX_Circle(double x, double y, int coords, double r,
492
static void PicTeX_Circle(double x, double y, int coords, double r,
493
			  int col, int border, DevDesc *dd)
493
			  int col, int border, DevDesc *dd)
494
{
494
{
495
	picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
495
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
496
 
496
 
497
	GConvert(&x, &y, coords, DEVICE, dd);
497
    GConvert(&x, &y, coords, DEVICE, dd);
498
	fprintf(ptd->texfp,
498
    fprintf(ptd->texfp,
499
	"\\circulararc 360 degrees from %.2f %.2f center at %.2f %.2f\n",
499
	    "\\circulararc 360 degrees from %.2f %.2f center at %.2f %.2f\n",
500
			x, (y + r), x, y);
500
	    x, (y + r), x, y);
501
 
501
 
502
}
502
}
503
 
503
 
504
static void PicTeX_Polygon(int n, double *x, double *y, int coords,
504
static void PicTeX_Polygon(int n, double *x, double *y, int coords,
505
			   int bg, int fg, DevDesc* dd)
505
			   int bg, int fg, DevDesc* dd)
506
{
506
{
507
	double x1, y1, x2, y2;
507
    double x1, y1, x2, y2;
508
	int i;
508
    int i;
509
	picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
509
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
510
 
510
 
511
	SetLinetype(dd->gp.lty, dd->gp.lwd, dd);
511
    SetLinetype(dd->gp.lty, dd->gp.lwd, dd);
512
	x1 = x[0];
512
    x1 = x[0];
513
	y1 = y[0];
513
    y1 = y[0];
514
	GConvert(&x1, &y1, coords, DEVICE, dd);
514
    GConvert(&x1, &y1, coords, DEVICE, dd);
515
	for (i=1; i<n; i++) {
515
    for (i=1; i<n; i++) {
516
		x2 = x[i];
516
	x2 = x[i];
517
		y2 = y[i];
517
	y2 = y[i];
518
		GConvert(&x2, &y2, coords, DEVICE, dd);
-
 
519
		PicTeX_ClipLine(x1, y1, x2, y2, ptd);
-
 
520
		fprintf(ptd->texfp, "\\plot %.2f %.2f %.2f %.2f /\n",
-
 
521
			ptd->clippedx0, ptd->clippedy0,
-
 
522
			ptd->clippedx1, ptd->clippedy1);
-
 
523
		x1 = x2;
-
 
524
		y1 = y2;
-
 
525
	}
-
 
526
	x2 = x[0];
-
 
527
	y2 = y[0];
-
 
528
	GConvert(&x2, &y2, coords, DEVICE, dd);
518
	GConvert(&x2, &y2, coords, DEVICE, dd);
529
	PicTeX_ClipLine(x1, y1, x2, y2, ptd);
519
	PicTeX_ClipLine(x1, y1, x2, y2, ptd);
530
	fprintf(ptd->texfp, "\\plot %.2f %.2f %.2f %.2f /\n",
520
	fprintf(ptd->texfp, "\\plot %.2f %.2f %.2f %.2f /\n",
531
		ptd->clippedx0, ptd->clippedy0,
521
		ptd->clippedx0, ptd->clippedy0,
532
		ptd->clippedx1, ptd->clippedy1);
522
		ptd->clippedx1, ptd->clippedy1);
-
 
523
	x1 = x2;
-
 
524
	y1 = y2;
-
 
525
    }
-
 
526
    x2 = x[0];
-
 
527
    y2 = y[0];
-
 
528
    GConvert(&x2, &y2, coords, DEVICE, dd);
-
 
529
    PicTeX_ClipLine(x1, y1, x2, y2, ptd);
-
 
530
    fprintf(ptd->texfp, "\\plot %.2f %.2f %.2f %.2f /\n",
-
 
531
	    ptd->clippedx0, ptd->clippedy0,
-
 
532
	    ptd->clippedx1, ptd->clippedy1);
533
}
533
}
534
 
534
 
535
/* TeX Text Translations */
535
/* TeX Text Translations */
536
static void textext(char *str, picTeXDesc *ptd)
536
static void textext(char *str, picTeXDesc *ptd)
537
{
537
{
538
	fputc('{', ptd->texfp);
538
    fputc('{', ptd->texfp);
539
	for( ; *str ; str++)
539
    for( ; *str ; str++)
540
		switch(*str) {
540
	switch(*str) {
541
			case '$':
541
	case '$':
542
				fprintf(ptd->texfp, "\\$");
542
	    fprintf(ptd->texfp, "\\$");
543
				break;
543
	    break;
544
 
544
 
545
			case '%':
545
	case '%':
546
				fprintf(ptd->texfp, "\\%%");
546
	    fprintf(ptd->texfp, "\\%%");
547
				break;
547
	    break;
548
 
548
 
549
			case '{':
549
	case '{':
550
				fprintf(ptd->texfp, "\\{");
550
	    fprintf(ptd->texfp, "\\{");
551
				break;
551
	    break;
552
 
552
 
553
			case '}':
553
	case '}':
554
				fprintf(ptd->texfp, "\\}");
554
	    fprintf(ptd->texfp, "\\}");
555
				break;
555
	    break;
556
 
556
 
557
			case '^':
557
	case '^':
558
				fprintf(ptd->texfp, "\\^{}");
558
	    fprintf(ptd->texfp, "\\^{}");
559
				break;
559
	    break;
560
 
560
 
561
			default:
561
	default:
562
				fputc(*str, ptd->texfp);
562
	    fputc(*str, ptd->texfp);
563
				break;
563
	    break;
564
		}
564
	}
565
	fprintf(ptd->texfp,"} ");
565
    fprintf(ptd->texfp,"} ");
566
}
566
}
567
 
567
 
568
/* Rotated Text */
568
/* Rotated Text */
569
 
569
 
570
static void PicTeX_Text(double x, double y, int coords,
570
static void PicTeX_Text(double x, double y, int coords,
571
			char *str, double rot, double hadj,
571
			char *str, double rot, double hadj,
572
			DevDesc *dd)
572
			DevDesc *dd)
573
{
573
{
574
	int size;
574
    int size;
575
	double xoff = 0.0, yoff = 0.0;
575
    double xoff = 0.0, yoff = 0.0;
576
	picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
576
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
577
 
577
 
578
	size = dd->gp.cex * dd->gp.ps + 0.5;
578
    size = dd->gp.cex * dd->gp.ps + 0.5;
579
	SetFont(dd->gp.font, size, ptd);
579
    SetFont(dd->gp.font, size, ptd);
580
	GConvert(&x, &y, coords, DEVICE, dd);
580
    GConvert(&x, &y, coords, DEVICE, dd);
581
	if(ptd->debug) fprintf(ptd->texfp,
581
    if(ptd->debug) fprintf(ptd->texfp,
582
	"%% Writing string of length %.2f, at %.2f %.2f, xc = %.2f yc = %.2f\n",
582
			   "%% Writing string of length %.2f, at %.2f %.2f, xc = %.2f yc = %.2f\n",
583
	(double)PicTeX_StrWidth(str, dd), x, y, 0.0, 0.0);
583
			   (double)PicTeX_StrWidth(str, dd), x, y, 0.0, 0.0);
584
	if (ptd->debug) fprintf(ptd->texfp,
584
    if (ptd->debug) fprintf(ptd->texfp,
585
	"%% Writing string of length %.2f, at %.2f %.2f, xc = %.2f yc = %.2f\n",
585
			    "%% Writing string of length %.2f, at %.2f %.2f, xc = %.2f yc = %.2f\n",
586
	(double)PicTeX_StrWidth(str, dd), x, y, 0.0, 0.0);
586
			    (double)PicTeX_StrWidth(str, dd), x, y, 0.0, 0.0);
587
 
587
 
588
	fprintf(ptd->texfp,"\\put ");
588
    fprintf(ptd->texfp,"\\put ");
589
	textext(str, ptd);
589
    textext(str, ptd);
590
	if (rot == 90 )
590
    if (rot == 90 )
591
	fprintf(ptd->texfp," [rB] <%.2fpt,%.2fpt>", xoff, yoff);
591
	fprintf(ptd->texfp," [rB] <%.2fpt,%.2fpt>", xoff, yoff);
592
	else fprintf(ptd->texfp," [lB] <%.2fpt,%.2fpt>", xoff, yoff);
592
    else fprintf(ptd->texfp," [lB] <%.2fpt,%.2fpt>", xoff, yoff);
593
	fprintf(ptd->texfp," at %.2f %.2f\n", x, y);
593
    fprintf(ptd->texfp," at %.2f %.2f\n", x, y);
594
}
594
}
595
 
595
 
596
/* Pick */
596
/* Pick */
597
static int PicTeX_Locator(double *x, double *y, DevDesc *dd)
597
static int PicTeX_Locator(double *x, double *y, DevDesc *dd)
598
{
598
{
599
	return 0;
599
    return 0;
600
}
600
}
601
 
601
 
602
 
602
 
603
/* Set Graphics mode - not needed for PS */
603
/* Set Graphics mode - not needed for PS */
604
static void PicTeX_Mode(int mode, DevDesc* dd)
604
static void PicTeX_Mode(int mode, DevDesc* dd)
Line 611... Line 611...
611
}
611
}
612
 
612
 
613
int PicTeXDeviceDriver(DevDesc *dd, char *filename, char *bg, char *fg,
613
int PicTeXDeviceDriver(DevDesc *dd, char *filename, char *bg, char *fg,
614
		       double width, double height, int debug)
614
		       double width, double height, int debug)
615
{
615
{
616
	picTeXDesc *ptd;
616
    picTeXDesc *ptd;
617
 
617
 
618
	if (!(ptd = (picTeXDesc *) malloc(sizeof(picTeXDesc))))
618
    if (!(ptd = (picTeXDesc *) malloc(sizeof(picTeXDesc))))
619
		return 0;
619
	return 0;
620
 
620
 
621
	strcpy(ptd->filename, filename);
621
    strcpy(ptd->filename, filename);
622
 
622
 
623
	dd->dp.bg = dd->gp.bg = str2col(bg);
623
    dd->dp.bg = dd->gp.bg = str2col(bg);
624
	dd->dp.fg = dd->gp.fg = str2col(fg);
624
    dd->dp.fg = dd->gp.fg = str2col(fg);
625
 
-
 
626
	dd->dp.activate = PicTeX_Activate;
-
 
627
	dd->dp.deactivate = PicTeX_Deactivate;
-
 
628
	dd->dp.open = PicTeX_Open;
-
 
629
	dd->dp.close = PicTeX_Close;
-
 
630
	dd->dp.clip = PicTeX_Clip;
-
 
631
	dd->dp.resize = PicTeX_Resize;
-
 
632
	dd->dp.newPage = PicTeX_NewPage;
-
 
633
	dd->dp.line = PicTeX_Line;
-
 
634
	dd->dp.text = PicTeX_Text;
-
 
635
	dd->dp.strWidth = PicTeX_StrWidth;
-
 
636
	dd->dp.rect = PicTeX_Rect;
-
 
637
	dd->dp.circle = PicTeX_Circle;
-
 
638
	dd->dp.polygon = PicTeX_Polygon;
-
 
639
	dd->dp.polyline = PicTeX_Polyline;
-
 
640
	dd->dp.locator = PicTeX_Locator;
-
 
641
	dd->dp.mode = PicTeX_Mode;
-
 
642
	dd->dp.hold = PicTeX_Hold;
-
 
643
	dd->dp.metricInfo = PicTeX_MetricInfo;
-
 
644
 
-
 
645
	/* Screen Dimensions in Pixels */
-
 
646
 
-
 
647
	dd->dp.left = 0;		/* left */
-
 
648
	dd->dp.right = 72.27 * width;	/* right */
-
 
649
	dd->dp.bottom = 0;		/* bottom */
-
 
650
	dd->dp.top = 72.27 * height;	/* top */
-
 
651
	ptd->width = width;
-
 
652
	ptd->height = height;
-
 
653
 
-
 
654
	if( ! PicTeX_Open(dd, ptd) ) return 0;
-
 
655
 
-
 
656
		/* Base Pointsize */
-
 
657
		/* Nominal Character Sizes in Pixels */
-
 
658
 
-
 
659
	dd->dp.ps = 10;
-
 
660
	dd->dp.cra[0] =	 (6.0/12.0) * 10.0;
-
 
661
	dd->dp.cra[1] =	 (10.0/12.0) * 10.0;
-
 
662
 
-
 
663
		/* Character Addressing Offsets */
-
 
664
		/* These offsets should center a single */
-
 
665
		/* plotting character over the plotting point. */
-
 
666
		/* Pure guesswork and eyeballing ... */
-
 
667
 
-
 
668
	dd->dp.xCharOffset =  0; /*0.4900;*/
-
 
669
	dd->dp.yCharOffset =  0; /*0.3333;*/
-
 
670
	dd->dp.yLineBias = 0; /*0.1;*/
-
 
671
 
-
 
672
		/* Inches per Raster Unit */
-
 
673
		/* We use printer points */
-
 
674
		/* I.e. 72.27 dots per inch */
-
 
675
 
-
 
676
	dd->dp.ipr[0] = 1.0/72.27;
-
 
677
	dd->dp.ipr[1] = 1.0/72.27;
-
 
678
 
-
 
679
	dd->dp.canResizePlot = 0;
-
 
680
	dd->dp.canChangeFont = 1;
-
 
681
	dd->dp.canRotateText = 0;
-
 
682
	dd->dp.canResizeText = 1;
-
 
683
	dd->dp.canClip = 1;
-
 
684
	dd->dp.canHAdj = 0;
-
 
685
 
-
 
686
	ptd->lty = 1;
-
 
687
	ptd->pageno = 0;
-
 
688
	ptd->debug = debug;
-
 
689
 
625
 
-
 
626
    dd->dp.activate = PicTeX_Activate;
-
 
627
    dd->dp.deactivate = PicTeX_Deactivate;
-
 
628
    dd->dp.open = PicTeX_Open;
-
 
629
    dd->dp.close = PicTeX_Close;
-
 
630
    dd->dp.clip = PicTeX_Clip;
-
 
631
    dd->dp.resize = PicTeX_Resize;
-
 
632
    dd->dp.newPage = PicTeX_NewPage;
-
 
633
    dd->dp.line = PicTeX_Line;
-
 
634
    dd->dp.text = PicTeX_Text;
-
 
635
    dd->dp.strWidth = PicTeX_StrWidth;
-
 
636
    dd->dp.rect = PicTeX_Rect;
-
 
637
    dd->dp.circle = PicTeX_Circle;
-
 
638
    dd->dp.polygon = PicTeX_Polygon;
-
 
639
    dd->dp.polyline = PicTeX_Polyline;
-
 
640
    dd->dp.locator = PicTeX_Locator;
-
 
641
    dd->dp.mode = PicTeX_Mode;
-
 
642
    dd->dp.hold = PicTeX_Hold;
-
 
643
    dd->dp.metricInfo = PicTeX_MetricInfo;
-
 
644
 
-
 
645
    /* Screen Dimensions in Pixels */
-
 
646
 
-
 
647
    dd->dp.left = 0;		/* left */
-
 
648
    dd->dp.right = 72.27 * width;	/* right */
-
 
649
    dd->dp.bottom = 0;		/* bottom */
-
 
650
    dd->dp.top = 72.27 * height;	/* top */
-
 
651
    ptd->width = width;
-
 
652
    ptd->height = height;
-
 
653
 
-
 
654
    if( ! PicTeX_Open(dd, ptd) ) return 0;
-
 
655
 
-
 
656
    /* Base Pointsize */
-
 
657
    /* Nominal Character Sizes in Pixels */
-
 
658
 
-
 
659
    dd->dp.ps = 10;
-
 
660
    dd->dp.cra[0] =	 (6.0/12.0) * 10.0;
-
 
661
    dd->dp.cra[1] =	 (10.0/12.0) * 10.0;
-
 
662
 
-
 
663
    /* Character Addressing Offsets */
-
 
664
    /* These offsets should center a single */
-
 
665
    /* plotting character over the plotting point. */
-
 
666
    /* Pure guesswork and eyeballing ... */
-
 
667
 
-
 
668
    dd->dp.xCharOffset =  0; /*0.4900;*/
-
 
669
    dd->dp.yCharOffset =  0; /*0.3333;*/
690
	dd->deviceSpecific = (void *) ptd;
670
    dd->dp.yLineBias = 0; /*0.1;*/
-
 
671
 
-
 
672
    /* Inches per Raster Unit */
-
 
673
    /* We use printer points */
-
 
674
    /* I.e. 72.27 dots per inch */
-
 
675
 
-
 
676
    dd->dp.ipr[0] = 1.0/72.27;
-
 
677
    dd->dp.ipr[1] = 1.0/72.27;
-
 
678
 
-
 
679
    dd->dp.canResizePlot = 0;
-
 
680
    dd->dp.canChangeFont = 1;
-
 
681
    dd->dp.canRotateText = 0;
-
 
682
    dd->dp.canResizeText = 1;
-
 
683
    dd->dp.canClip = 1;
-
 
684
    dd->dp.canHAdj = 0;
-
 
685
 
-
 
686
    ptd->lty = 1;
-
 
687
    ptd->pageno = 0;
-
 
688
    ptd->debug = debug;
691
 
689
 
-
 
690
    dd->deviceSpecific = (void *) ptd;
-
 
691
    dd->displayListOn = 0;
692
	return 1;
692
    return 1;
693
}
693
}