The R Project SVN R

Rev

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

Rev 19912 Rev 27236
Line 152... Line 152...
152
 
152
 
153
	/* Device driver actions */
153
	/* Device driver actions */
154
 
154
 
155
static void PicTeX_Activate(NewDevDesc *dd);
155
static void PicTeX_Activate(NewDevDesc *dd);
156
static void PicTeX_Circle(double x, double y, double r,
156
static void PicTeX_Circle(double x, double y, double r,
157
		       int col, int fill, double gamma, int lty, double lwd,
157
			  R_GE_gcontext *gc,
158
		       NewDevDesc *dd);
158
			  NewDevDesc *dd);
159
static void PicTeX_Clip(double x0, double x1, double y0, double y1, 
159
static void PicTeX_Clip(double x0, double x1, double y0, double y1, 
160
		     NewDevDesc *dd);
160
			NewDevDesc *dd);
161
static void PicTeX_Close(NewDevDesc *dd);
161
static void PicTeX_Close(NewDevDesc *dd);
162
static void PicTeX_Deactivate(NewDevDesc *dd);
162
static void PicTeX_Deactivate(NewDevDesc *dd);
163
static void PicTeX_Hold(NewDevDesc *dd);
163
static void PicTeX_Hold(NewDevDesc *dd);
164
static Rboolean PicTeX_Locator(double *x, double *y, NewDevDesc *dd);
164
static Rboolean PicTeX_Locator(double *x, double *y, NewDevDesc *dd);
165
static void PicTeX_Line(double x1, double y1, double x2, double y2,
165
static void PicTeX_Line(double x1, double y1, double x2, double y2,
166
		     int col, double gamma, int lty, double lwd,
166
			R_GE_gcontext *gc,
167
		     NewDevDesc *dd);
167
			NewDevDesc *dd);
168
static void PicTeX_MetricInfo(int c, int font, double cex, double ps,
168
static void PicTeX_MetricInfo(int c,
-
 
169
			      R_GE_gcontext *gc,
169
			      double* ascent, double* descent,
170
			      double* ascent, double* descent,
170
			      double* width, NewDevDesc *dd);
171
			      double* width, NewDevDesc *dd);
171
static void PicTeX_Mode(int mode, NewDevDesc *dd);
172
static void PicTeX_Mode(int mode, NewDevDesc *dd);
172
static void PicTeX_NewPage(int fill, double gamma, NewDevDesc *dd);
173
static void PicTeX_NewPage(R_GE_gcontext *gc, NewDevDesc *dd);
173
static void PicTeX_Polygon(int n, double *x, double *y, 
174
static void PicTeX_Polygon(int n, double *x, double *y, 
174
			int col, int fill, double gamma, int lty, double lwd,
175
			   R_GE_gcontext *gc,
175
			NewDevDesc *dd);
176
			   NewDevDesc *dd);
176
static void PicTeX_Rect(double x0, double y0, double x1, double y1,
177
static void PicTeX_Rect(double x0, double y0, double x1, double y1,
177
		     int col, int fill, double gamma, int lty, double lwd,
178
			R_GE_gcontext *gc,
178
		     NewDevDesc *dd);
179
			NewDevDesc *dd);
179
static void PicTeX_Size(double *left, double *right,
180
static void PicTeX_Size(double *left, double *right,
180
		     double *bottom, double *top,
181
			double *bottom, double *top,
181
		     NewDevDesc *dd);
182
			NewDevDesc *dd);
182
static double PicTeX_StrWidth(char *str, int font,
183
static double PicTeX_StrWidth(char *str, 
-
 
184
			      R_GE_gcontext *gc,
183
			      double cex, double ps, NewDevDesc *dd);
185
			      NewDevDesc *dd);
184
static void PicTeX_Text(double x, double y, char *str, 
186
static void PicTeX_Text(double x, double y, char *str, 
185
		     double rot, double hadj, 
187
			double rot, double hadj, 
186
		     int col, double gamma, int font, double cex, double ps,
188
			R_GE_gcontext *gc,
187
		     NewDevDesc *dd);
189
			NewDevDesc *dd);
188
static Rboolean PicTeX_Open(NewDevDesc*, picTeXDesc*);
190
static Rboolean PicTeX_Open(NewDevDesc*, picTeXDesc*);
189
 
191
 
190
	/* Support routines */
192
	/* Support routines */
191
 
193
 
192
static void SetLinetype(int newlty, int newlwd, NewDevDesc *dd)
194
static void SetLinetype(int newlty, int newlwd, NewDevDesc *dd)
Line 209... Line 211...
209
 
211
 
210
 
212
 
211
static void SetFont(int face, int size, picTeXDesc *ptd)
213
static void SetFont(int face, int size, picTeXDesc *ptd)
212
{
214
{
213
    int lface=face, lsize= size;
215
    int lface=face, lsize= size;
214
    if(lface < 1 || lface > 4) lface = 1;
216
    if(lface < 1 || lface > 4 ) lface = 1;
215
    if(lsize < 1 || lsize > 24) lsize = 10;
217
    if(lsize < 1 || lsize > 24) lsize = 10;
216
    if(lsize != ptd->fontsize || lface != ptd->fontface) {
218
    if(lsize != ptd->fontsize || lface != ptd->fontface) {
217
	fprintf(ptd->texfp, "\\font\\picfont %s at %dpt\\picfont\n",
219
	fprintf(ptd->texfp, "\\font\\picfont %s at %dpt\\picfont\n",
218
		fontname[lface-1], lsize);
220
		fontname[lface-1], lsize);
219
	ptd->fontsize = lsize;
221
	ptd->fontsize = lsize;
Line 227... Line 229...
227
 
229
 
228
static void PicTeX_Deactivate(NewDevDesc *dd)
230
static void PicTeX_Deactivate(NewDevDesc *dd)
229
{
231
{
230
}
232
}
231
 
233
 
232
static void PicTeX_MetricInfo(int c, int font, double cex, double ps,
234
static void PicTeX_MetricInfo(int c, 
-
 
235
			      R_GE_gcontext *gc,
233
			      double* ascent, double* descent,
236
			      double* ascent, double* descent,
234
			      double* width, NewDevDesc *dd)
237
			      double* width, NewDevDesc *dd)
235
{
238
{
236
    /* metric information not available => return 0,0,0 */
239
    /* metric information not available => return 0,0,0 */
237
    *ascent = 0.0;
240
    *ascent = 0.0;
Line 287... Line 290...
287
    ptd->cliptop = y1;
290
    ptd->cliptop = y1;
288
}
291
}
289
 
292
 
290
	/* Start a new page */
293
	/* Start a new page */
291
 
294
 
292
static void PicTeX_NewPage(int fill, double gamma, NewDevDesc *dd)
295
static void PicTeX_NewPage(R_GE_gcontext *gc,
-
 
296
			   NewDevDesc *dd)
293
{
297
{
294
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
298
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
295
 
299
 
296
    int face, size;
300
    int face, size;
297
    if (ptd->pageno) {
301
    if (ptd->pageno) {
Line 410... Line 414...
410
	ptd->clippedy0 = ptd->cliptop ;
414
	ptd->clippedy0 = ptd->cliptop ;
411
    }
415
    }
412
}
416
}
413
 
417
 
414
static void PicTeX_Line(double x1, double y1, double x2, double y2,
418
static void PicTeX_Line(double x1, double y1, double x2, double y2,
415
		     int col, double gamma, int lty, double lwd,
419
			R_GE_gcontext *gc,
416
		     NewDevDesc *dd)
420
			NewDevDesc *dd)
417
{
421
{
418
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
422
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
419
 
423
 
420
    if (x1 != x2 || y1 != y2) {
424
    if (x1 != x2 || y1 != y2) {
421
	SetLinetype(lty, lwd, dd);
425
	SetLinetype(gc->lty, gc->lwd, dd);
422
	if(ptd->debug)
426
	if(ptd->debug)
423
	    fprintf(ptd->texfp,
427
	    fprintf(ptd->texfp,
424
		    "%% Drawing line from %.2f, %.2f to %.2f, %.2f\n",
428
		    "%% Drawing line from %.2f, %.2f to %.2f, %.2f\n",
425
		    x1, y1, x2, y2);
429
		    x1, y1, x2, y2);
426
	PicTeX_ClipLine(x1, y1, x2, y2, ptd);
430
	PicTeX_ClipLine(x1, y1, x2, y2, ptd);
Line 434... Line 438...
434
		ptd->clippedx1, ptd->clippedy1);
438
		ptd->clippedx1, ptd->clippedy1);
435
    }
439
    }
436
}
440
}
437
 
441
 
438
static void PicTeX_Polyline(int n, double *x, double *y, 
442
static void PicTeX_Polyline(int n, double *x, double *y, 
439
			    int col, double gamma, int lty, double lwd,
443
			    R_GE_gcontext *gc,
440
			    NewDevDesc *dd)
444
			    NewDevDesc *dd)
441
{
445
{
442
    double x1, y1, x2, y2;
446
    double x1, y1, x2, y2;
443
    int i;
447
    int i;
444
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
448
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
445
 
449
 
446
    SetLinetype(lty, lwd, dd);
450
    SetLinetype(gc->lty, gc->lwd, dd);
447
    x1 = x[0];
451
    x1 = x[0];
448
    y1 = y[0];
452
    y1 = y[0];
449
    for (i = 1; i < n; i++) {
453
    for (i = 1; i < n; i++) {
450
	x2 = x[i];
454
	x2 = x[i];
451
	y2 = y[i];
455
	y2 = y[i];
Line 459... Line 463...
459
}
463
}
460
 
464
 
461
	/* String Width in Rasters */
465
	/* String Width in Rasters */
462
	/* For the current font in pointsize fontsize */
466
	/* For the current font in pointsize fontsize */
463
 
467
 
464
static double PicTeX_StrWidth(char *str, int font,
468
static double PicTeX_StrWidth(char *str, 
-
 
469
			      R_GE_gcontext *gc,
465
			      double cex, double ps, NewDevDesc *dd)
470
			      NewDevDesc *dd)
466
{
471
{
467
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
472
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
468
 
473
 
469
    char *p;
474
    char *p;
470
    int size;
475
    int size;
471
    double sum;
476
    double sum;
472
    size = cex * ps + 0.5;
477
    size = gc->cex * gc->ps + 0.5;
473
    SetFont(font, size, ptd);
478
    SetFont(gc->fontface, size, ptd);
474
    sum = 0;
479
    sum = 0;
475
    for(p=str ; *p ; p++)
480
    for(p=str ; *p ; p++)
476
	sum += charwidth[ptd->fontface-1][(int)*p];
481
	sum += charwidth[ptd->fontface-1][(int)*p];
477
    return sum * ptd->fontsize;
482
    return sum * ptd->fontsize;
478
}
483
}
479
 
484
 
480
 
485
 
481
/* Possibly Filled Rectangle */
486
/* Possibly Filled Rectangle */
482
static void PicTeX_Rect(double x0, double y0, double x1, double y1,
487
static void PicTeX_Rect(double x0, double y0, double x1, double y1,
483
		     int col, int fill, double gamma, int lty, double lwd,
488
			R_GE_gcontext *gc,
484
		     NewDevDesc *dd)
489
			NewDevDesc *dd)
485
{
490
{
486
    double x[4], y[4];
491
    double x[4], y[4];
487
 
492
 
488
    x[0] = x0; y[0] = y0;
493
    x[0] = x0; y[0] = y0;
489
    x[1] = x0; y[1] = y1;
494
    x[1] = x0; y[1] = y1;
490
    x[2] = x1; y[2] = y1;
495
    x[2] = x1; y[2] = y1;
491
    x[3] = x1; y[3] = y0;
496
    x[3] = x1; y[3] = y0;
492
    PicTeX_Polygon(4, x, y, col, fill, gamma, lty, lwd, dd);
497
    PicTeX_Polygon(4, x, y, gc, dd);
493
}
498
}
494
 
499
 
495
static void PicTeX_Circle(double x, double y, double r,
500
static void PicTeX_Circle(double x, double y, double r,
496
		       int col, int fill, double gamma, int lty, double lwd,
501
			  R_GE_gcontext *gc,
497
		       NewDevDesc *dd)
502
			  NewDevDesc *dd)
498
{
503
{
499
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
504
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
500
 
505
 
501
    fprintf(ptd->texfp,
506
    fprintf(ptd->texfp,
502
	    "\\circulararc 360 degrees from %.2f %.2f center at %.2f %.2f\n",
507
	    "\\circulararc 360 degrees from %.2f %.2f center at %.2f %.2f\n",
503
	    x, (y + r), x, y);
508
	    x, (y + r), x, y);
504
}
509
}
505
 
510
 
506
static void PicTeX_Polygon(int n, double *x, double *y, 
511
static void PicTeX_Polygon(int n, double *x, double *y, 
507
			int col, int fill, double gamma, int lty, double lwd,
512
			   R_GE_gcontext *gc,
508
			NewDevDesc *dd)
513
			   NewDevDesc *dd)
509
{
514
{
510
    double x1, y1, x2, y2;
515
    double x1, y1, x2, y2;
511
    int i;
516
    int i;
512
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
517
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
513
 
518
 
514
    SetLinetype(lty, lwd, dd);
519
    SetLinetype(gc->lty, gc->lwd, dd);
515
    x1 = x[0];
520
    x1 = x[0];
516
    y1 = y[0];
521
    y1 = y[0];
517
    for (i=1; i<n; i++) {
522
    for (i=1; i<n; i++) {
518
	x2 = x[i];
523
	x2 = x[i];
519
	y2 = y[i];
524
	y2 = y[i];
Line 566... Line 571...
566
}
571
}
567
 
572
 
568
/* Rotated Text */
573
/* Rotated Text */
569
 
574
 
570
static void PicTeX_Text(double x, double y, char *str, 
575
static void PicTeX_Text(double x, double y, char *str, 
571
		     double rot, double hadj, 
576
			double rot, double hadj, 
572
		     int col, double gamma, int font, double cex, double ps,
577
			R_GE_gcontext *gc,
573
		     NewDevDesc *dd)
578
			NewDevDesc *dd)
574
{
579
{
575
    int size;
580
    int size;
576
    double xoff = 0.0, yoff = 0.0;
581
    double xoff = 0.0, yoff = 0.0;
577
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
582
    picTeXDesc *ptd = (picTeXDesc *) dd->deviceSpecific;
578
 
583
 
579
    size = cex * ps + 0.5;
584
    size = gc->cex * gc->ps + 0.5;
580
    SetFont(font, size, ptd);
585
    SetFont(gc->fontface, size, ptd);
581
    if(ptd->debug) 
586
    if(ptd->debug) 
582
	fprintf(ptd->texfp,
587
	fprintf(ptd->texfp,
583
		"%% 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",
584
		(double)PicTeX_StrWidth(str, font, cex, ps, dd), 
589
		(double)PicTeX_StrWidth(str, gc, dd), 
585
		x, y, 0.0, 0.0);
590
		x, y, 0.0, 0.0);
586
    fprintf(ptd->texfp,"\\put ");
591
    fprintf(ptd->texfp,"\\put ");
587
    textext(str, ptd);
592
    textext(str, ptd);
588
    if (rot == 90 )
593
    if (rot == 90 )
589
	fprintf(ptd->texfp," [rB] <%.2fpt,%.2fpt>", xoff, yoff);
594
	fprintf(ptd->texfp," [rB] <%.2fpt,%.2fpt>", xoff, yoff);