The R Project SVN R

Rev

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

Rev 10960 Rev 11067
Line 23... Line 23...
23
#endif
23
#endif
24
 
24
 
25
#include "Defn.h"
25
#include "Defn.h"
26
#include "Graphics.h"
26
#include "Graphics.h"
27
#include "Fileio.h"
27
#include "Fileio.h"
-
 
28
#include "Devices.h"
28
 
29
 
29
	/* device-specific information per picTeX device */
30
	/* device-specific information per picTeX device */
30
 
31
 
-
 
32
#define DOTSperIN	72.27
-
 
33
#define in2dots(x) 	(DOTSperIN * x)
-
 
34
 
31
typedef struct {
35
typedef struct {
32
    FILE *texfp;
36
    FILE *texfp;
33
    char filename[128];
37
    char filename[128];
34
    int pageno;
38
    int pageno;
35
    int landscape;
39
    int landscape;
Line 45... Line 49...
45
    rcolor col;
49
    rcolor col;
46
    rcolor fg;
50
    rcolor fg;
47
    rcolor bg;
51
    rcolor bg;
48
    int fontsize;
52
    int fontsize;
49
    int fontface;
53
    int fontface;
50
    int debug;
54
    Rboolean debug;
51
} picTeXDesc;
55
} picTeXDesc;
52
 
56
 
53
 
57
 
54
	/* Global device information */
58
	/* Global device information */
55
 
59
 
Line 153... Line 157...
153
static void   PicTeX_Clip(double, double, double, double, DevDesc*);
157
static void   PicTeX_Clip(double, double, double, double, DevDesc*);
154
static void   PicTeX_Close(DevDesc*);
158
static void   PicTeX_Close(DevDesc*);
155
static void   PicTeX_Deactivate(DevDesc *);
159
static void   PicTeX_Deactivate(DevDesc *);
156
static void   PicTeX_Hold(DevDesc*);
160
static void   PicTeX_Hold(DevDesc*);
157
static void   PicTeX_Line(double, double, double, double, int, DevDesc*);
161
static void   PicTeX_Line(double, double, double, double, int, DevDesc*);
158
static int    PicTeX_Locator(double*, double*, DevDesc*);
162
static Rboolean PicTeX_Locator(double*, double*, DevDesc*);
159
static void   PicTeX_Mode(int, DevDesc*);
163
static void   PicTeX_Mode(int, DevDesc*);
160
static void   PicTeX_NewPage(DevDesc*);
164
static void   PicTeX_NewPage(DevDesc*);
161
static int    PicTeX_Open(DevDesc*, picTeXDesc*);
165
static Rboolean PicTeX_Open(DevDesc*, picTeXDesc*);
162
static void   PicTeX_Polygon(int, double*, double*, int, int, int, DevDesc*);
166
static void   PicTeX_Polygon(int, double*, double*, int, int, int, DevDesc*);
163
static void   PicTeX_Polyline(int, double*, double*, int, DevDesc*);
167
static void   PicTeX_Polyline(int, double*, double*, int, DevDesc*);
164
static void   PicTeX_Rect(double, double, double, double, int, int, int,
168
static void   PicTeX_Rect(double, double, double, double, int, int, int,
165
			  DevDesc*);
169
			  DevDesc*);
166
static void   PicTeX_Resize(DevDesc*);
170
static void   PicTeX_Resize(DevDesc*);
Line 219... Line 223...
219
    *width = 0.0;
223
    *width = 0.0;
220
}
224
}
221
 
225
 
222
	/* Initialize the device */
226
	/* Initialize the device */
223
 
227
 
224
static int PicTeX_Open(DevDesc *dd, picTeXDesc *ptd)
228
static Rboolean PicTeX_Open(DevDesc *dd, picTeXDesc *ptd)
225
{
229
{
226
    ptd->fontsize = 0;
230
    ptd->fontsize = 0;
227
    ptd->fontface = 0;
231
    ptd->fontface = 0;
228
    ptd->debug = 0;
232
    ptd->debug = FALSE;
229
    if (!(ptd->texfp = R_fopen(R_ExpandFileName(ptd->filename), "w")))
233
    if (!(ptd->texfp = R_fopen(R_ExpandFileName(ptd->filename), "w")))
230
	return 0;
234
	return FALSE;
231
    fprintf(ptd->texfp, "\\hbox{\\beginpicture\n");
235
    fprintf(ptd->texfp, "\\hbox{\\beginpicture\n");
232
    fprintf(ptd->texfp, "\\setcoordinatesystem units <1pt,1pt>\n");
236
    fprintf(ptd->texfp, "\\setcoordinatesystem units <1pt,1pt>\n");
233
    fprintf(ptd->texfp,
237
    fprintf(ptd->texfp,
234
	    "\\setplotarea x from 0 to %.2f, y from 0 to %.2f\n",
238
	    "\\setplotarea x from 0 to %.2f, y from 0 to %.2f\n",
235
	    ptd->width * 72.27, ptd->height * 72.27);
239
	    in2dots(ptd->width), in2dots(ptd->height));
236
    fprintf(ptd->texfp,"\\setlinear\n");
240
    fprintf(ptd->texfp,"\\setlinear\n");
237
    fprintf(ptd->texfp, "\\font\\picfont cmss10\\picfont\n");
241
    fprintf(ptd->texfp, "\\font\\picfont cmss10\\picfont\n");
238
    SetFont(1, 10, ptd);
242
    SetFont(1, 10, ptd);
239
    ptd->pageno += 1;
243
    ptd->pageno++;
240
    return 1;
244
    return TRUE;
241
}
245
}
242
 
246
 
243
 
247
 
244
	/* Interactive Resize */
248
	/* Interactive Resize */
245
 
249
 
Line 272... Line 276...
272
	fprintf(ptd->texfp, "\\endpicture\n}\n\n\n");
276
	fprintf(ptd->texfp, "\\endpicture\n}\n\n\n");
273
	fprintf(ptd->texfp, "\\hbox{\\beginpicture\n");
277
	fprintf(ptd->texfp, "\\hbox{\\beginpicture\n");
274
	fprintf(ptd->texfp, "\\setcoordinatesystem units <1pt,1pt>\n");
278
	fprintf(ptd->texfp, "\\setcoordinatesystem units <1pt,1pt>\n");
275
	fprintf(ptd->texfp,
279
	fprintf(ptd->texfp,
276
		"\\setplotarea x from 0 to %.2f, y from 0 to %.2f\n",
280
		"\\setplotarea x from 0 to %.2f, y from 0 to %.2f\n",
277
		ptd->width * 72.27, ptd->height * 72.27);
281
		in2dots(ptd->width), in2dots(ptd->height));
278
	fprintf(ptd->texfp,"\\setlinear\n");
282
	fprintf(ptd->texfp,"\\setlinear\n");
279
	fprintf(ptd->texfp, "\\font\\picfont cmss10\\picfont\n");
283
	fprintf(ptd->texfp, "\\font\\picfont cmss10\\picfont\n");
280
    }
284
    }
281
    ptd->pageno +=1;
285
    ptd->pageno++;
282
    face = ptd->fontface;
286
    face = ptd->fontface;
283
    size = ptd->fontsize;
287
    size = ptd->fontsize;
284
    ptd->fontface = 0;
288
    ptd->fontface = 0;
285
    ptd->fontsize = 0;
289
    ptd->fontsize = 0;
286
    SetFont(face, size, ptd);
290
    SetFont(face, size, ptd);
Line 409... Line 413...
409
			"%% Drawing line from %.2f, %.2f to %.2f, %.2f\n",
413
			"%% Drawing line from %.2f, %.2f to %.2f, %.2f\n",
410
			x1, y1, x2, y2);
414
			x1, y1, x2, y2);
411
	PicTeX_ClipLine(x1, y1, x2, y2, ptd);
415
	PicTeX_ClipLine(x1, y1, x2, y2, ptd);
412
	if (ptd->debug)
416
	if (ptd->debug)
413
		fprintf(ptd->texfp,
417
		fprintf(ptd->texfp,
414
			"%% Drawing cliped ine from %.2f, %.2f to %.2f, %.2f\n",
418
			"%% Drawing clipped line from %.2f, %.2f to %.2f, %.2f\n",
415
			ptd->clippedx0, ptd->clippedy0,
419
			ptd->clippedx0, ptd->clippedy0,
416
			ptd->clippedx1, ptd->clippedy1);
420
			ptd->clippedx1, ptd->clippedy1);
417
	fprintf(ptd->texfp, "\\plot %.2f %.2f %.2f %.2f /\n",
421
	fprintf(ptd->texfp, "\\plot %.2f %.2f %.2f %.2f /\n",
418
		ptd->clippedx0, ptd->clippedy0,
422
		ptd->clippedx0, ptd->clippedy0,
419
		ptd->clippedx1, ptd->clippedy1);
423
		ptd->clippedx1, ptd->clippedy1);
Line 577... Line 581...
577
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
581
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
578
 
582
 
579
    size = dd->gp.cex * dd->gp.ps + 0.5;
583
    size = dd->gp.cex * dd->gp.ps + 0.5;
580
    SetFont(dd->gp.font, size, ptd);
584
    SetFont(dd->gp.font, size, ptd);
581
    GConvert(&x, &y, coords, DEVICE, dd);
585
    GConvert(&x, &y, coords, DEVICE, dd);
582
    if(ptd->debug) fprintf(ptd->texfp,
586
    if(ptd->debug) 
583
			   "%% Writing string of length %.2f, at %.2f %.2f, xc = %.2f yc = %.2f\n",
-
 
584
			   (double)PicTeX_StrWidth(str, dd), x, y, 0.0, 0.0);
-
 
585
    if (ptd->debug) fprintf(ptd->texfp,
587
	fprintf(ptd->texfp,
586
			    "%% Writing string of length %.2f, at %.2f %.2f, xc = %.2f yc = %.2f\n",
588
		"%% Writing string of length %.2f, at %.2f %.2f, xc = %.2f yc = %.2f\n",
587
			    (double)PicTeX_StrWidth(str, dd), x, y, 0.0, 0.0);
589
		(double)PicTeX_StrWidth(str, dd), x, y, 0.0, 0.0);
588
 
-
 
589
    fprintf(ptd->texfp,"\\put ");
590
    fprintf(ptd->texfp,"\\put ");
590
    textext(str, ptd);
591
    textext(str, ptd);
591
    if (rot == 90 )
592
    if (rot == 90 )
592
	fprintf(ptd->texfp," [rB] <%.2fpt,%.2fpt>", xoff, yoff);
593
	 fprintf(ptd->texfp," [rB] <%.2fpt,%.2fpt>", xoff, yoff);
593
    else fprintf(ptd->texfp," [lB] <%.2fpt,%.2fpt>", xoff, yoff);
594
    else fprintf(ptd->texfp," [lB] <%.2fpt,%.2fpt>", xoff, yoff);
594
    fprintf(ptd->texfp," at %.2f %.2f\n", x, y);
595
    fprintf(ptd->texfp," at %.2f %.2f\n", x, y);
595
}
596
}
596
 
597
 
597
/* Pick */
598
/* Pick */
598
static int PicTeX_Locator(double *x, double *y, DevDesc *dd)
599
static Rboolean PicTeX_Locator(double *x, double *y, DevDesc *dd)
599
{
600
{
600
    return 0;
601
    return FALSE;
601
}
602
}
602
 
603
 
603
 
604
 
604
/* Set Graphics mode - not needed for PS */
605
/* Set Graphics mode - not needed for PS */
605
static void PicTeX_Mode(int mode, DevDesc* dd)
606
static void PicTeX_Mode(int mode, DevDesc* dd)
Line 609... Line 610...
609
/* GraphicsInteraction() for the Mac */
610
/* GraphicsInteraction() for the Mac */
610
static void PicTeX_Hold(DevDesc *dd)
611
static void PicTeX_Hold(DevDesc *dd)
611
{
612
{
612
}
613
}
613
 
614
 
614
int PicTeXDeviceDriver(DevDesc *dd, char *filename, char *bg, char *fg,
615
Rboolean PicTeXDeviceDriver(DevDesc *dd, char *filename, char *bg, char *fg,
615
		       double width, double height, int debug)
616
			    double width, double height, Rboolean debug)
616
{
617
{
617
    picTeXDesc *ptd;
618
    picTeXDesc *ptd;
618
 
619
 
619
    if (!(ptd = (picTeXDesc *) malloc(sizeof(picTeXDesc))))
620
    if (!(ptd = (picTeXDesc *) malloc(sizeof(picTeXDesc))))
620
	return 0;
621
	return FALSE;
621
 
622
 
622
    strcpy(ptd->filename, filename);
623
    strcpy(ptd->filename, filename);
623
 
624
 
624
    dd->dp.bg = dd->gp.bg = str2col(bg);
625
    dd->dp.bg = dd->gp.bg = str2col(bg);
625
    dd->dp.fg = dd->gp.fg = str2col(fg);
626
    dd->dp.fg = dd->gp.fg = str2col(fg);
Line 644... Line 645...
644
    dd->dp.metricInfo = PicTeX_MetricInfo;
645
    dd->dp.metricInfo = PicTeX_MetricInfo;
645
 
646
 
646
    /* Screen Dimensions in Pixels */
647
    /* Screen Dimensions in Pixels */
647
 
648
 
648
    dd->dp.left = 0;		/* left */
649
    dd->dp.left = 0;		/* left */
649
    dd->dp.right = 72.27 * width;	/* right */
650
    dd->dp.right = in2dots(width);/* right */
650
    dd->dp.bottom = 0;		/* bottom */
651
    dd->dp.bottom = 0;		/* bottom */
651
    dd->dp.top = 72.27 * height;	/* top */
652
    dd->dp.top = in2dots(height);/* top */
652
    ptd->width = width;
653
    ptd->width = width;
653
    ptd->height = height;
654
    ptd->height = height;
654
 
655
 
655
    if( ! PicTeX_Open(dd, ptd) ) return 0;
656
    if( ! PicTeX_Open(dd, ptd) ) 
-
 
657
	return FALSE;
656
 
658
 
657
    /* Base Pointsize */
659
    /* Base Pointsize */
658
    /* Nominal Character Sizes in Pixels */
660
    /* Nominal Character Sizes in Pixels */
659
 
661
 
660
    dd->dp.ps = 10;
662
    dd->dp.ps = 10;
661
    dd->dp.cra[0] =	 (6.0/12.0) * 10.0;
663
    dd->dp.cra[0] =	 (6.0/12.0) * 10.0;
662
    dd->dp.cra[1] =	 (10.0/12.0) * 10.0;
664
    dd->dp.cra[1] =	(10.0/12.0) * 10.0;
663
 
665
 
664
    /* Character Addressing Offsets */
666
    /* Character Addressing Offsets */
665
    /* These offsets should center a single */
667
    /* These offsets should center a single */
666
    /* plotting character over the plotting point. */
668
    /* plotting character over the plotting point. */
667
    /* Pure guesswork and eyeballing ... */
669
    /* Pure guesswork and eyeballing ... */
Line 669... Line 671...
669
    dd->dp.xCharOffset =  0; /*0.4900;*/
671
    dd->dp.xCharOffset =  0; /*0.4900;*/
670
    dd->dp.yCharOffset =  0; /*0.3333;*/
672
    dd->dp.yCharOffset =  0; /*0.3333;*/
671
    dd->dp.yLineBias = 0; /*0.1;*/
673
    dd->dp.yLineBias = 0; /*0.1;*/
672
 
674
 
673
    /* Inches per Raster Unit */
675
    /* Inches per Raster Unit */
674
    /* We use printer points */
-
 
675
    /* I.e. 72.27 dots per inch */
676
    /* We use printer points, i.e. 72.27 dots per inch : */
676
 
-
 
677
    dd->dp.ipr[0] = 1.0/72.27;
-
 
678
    dd->dp.ipr[1] = 1.0/72.27;
677
    dd->dp.ipr[0] = dd->dp.ipr[1] = 1./DOTSperIN;
679
 
678
 
680
    dd->dp.canResizePlot = 0;
679
    dd->dp.canResizePlot = FALSE;
681
    dd->dp.canChangeFont = 1;
680
    dd->dp.canChangeFont = TRUE;
682
    dd->dp.canRotateText = 0;
681
    dd->dp.canRotateText = FALSE;
683
    dd->dp.canResizeText = 1;
682
    dd->dp.canResizeText = TRUE;
684
    dd->dp.canClip = 1;
683
    dd->dp.canClip = TRUE;
685
    dd->dp.canHAdj = 0;
684
    dd->dp.canHAdj = 0;
686
 
685
 
687
    ptd->lty = 1;
686
    ptd->lty = 1;
688
    ptd->pageno = 0;
687
    ptd->pageno = 0;
689
    ptd->debug = debug;
688
    ptd->debug = debug;
690
 
689
 
691
    dd->deviceSpecific = (void *) ptd;
690
    dd->deviceSpecific = (void *) ptd;
692
    dd->displayListOn = 0;
691
    dd->displayListOn = FALSE;
693
    return 1;
692
    return TRUE;
694
}
693
}