The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
34906 murdoch 1
/*******************************************************************************
13365 ripley 2
 *  RProxy: Connector implementation between application and R language
34906 murdoch 3
 *  Copyright (C) 2000--2005 Thomas Baier
13365 ripley 4
 *
5
 *  This library is free software; you can redistribute it and/or
6
 *  modify it under the terms of the GNU Library General Public
7
 *  License as published by the Free Software Foundation; either
8
 *  version 2 of the License, or (at your option) any later version.
26207 murdoch 9
 *
13365 ripley 10
 *  This library is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 *  Library General Public License for more details.
26207 murdoch 14
 *
13365 ripley 15
 *  You should have received a copy of the GNU Library General Public
16
 *  License along with this library; if not, write to the Free
36821 ripley 17
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 *  MA 02110-1301, USA.
13365 ripley 19
 *
34906 murdoch 20
 ******************************************************************************/
13365 ripley 21
 
26207 murdoch 22
/* virtual device size */
13365 ripley 23
#define DEV_X 500
24
#define DEV_Y 500
25
 
36873 ripley 26
#include <config.h>
31242 murdoch 27
#include <Defn.h>
28
#include <Graphics.h>
29
#include <Rdevices.h>
13365 ripley 30
#include <stdio.h>
31
#include <windows.h>
32
 
33
#include "SC_proxy.h"
34
 
35
extern SC_GraphicsDevice* __graphics_device;
36
 
17227 murrell 37
static void R_Proxy_Graphics_Activate (NewDevDesc* pDD)
13365 ripley 38
{
39
  if (__graphics_device)
40
    {
41
      __graphics_device->vtbl->activate (__graphics_device);
42
      return;
43
    }
44
}
45
 
46
#ifdef MessageBox
47
#undef MessageBox
48
#endif
49
#define MessageBox(a,b,c,d)
50
 
17227 murrell 51
static void R_Proxy_Graphics_Activate(NewDevDesc *dd);
52
static void R_Proxy_Graphics_Circle(double x, double y, double r,
27236 murrell 53
				    R_GE_gcontext *gc,
54
				    NewDevDesc *dd);
26207 murdoch 55
static void R_Proxy_Graphics_Clip(double x0, double x1, double y0, double y1,
17227 murrell 56
		     NewDevDesc *dd);
57
static void R_Proxy_Graphics_Close(NewDevDesc *dd);
58
static void R_Proxy_Graphics_Deactivate(NewDevDesc *dd);
59
static void R_Proxy_Graphics_Hold(NewDevDesc *dd);
60
static Rboolean R_Proxy_Graphics_Locator(double *x, double *y, NewDevDesc *dd);
61
static void R_Proxy_Graphics_Line(double x1, double y1, double x2, double y2,
27236 murrell 62
				  R_GE_gcontext *gc,
63
				  NewDevDesc *dd);
64
static void R_Proxy_Graphics_MetricInfo(int c, 
65
					R_GE_gcontext *gc,
66
					double* ascent, double* descent,
67
					double* width, NewDevDesc *dd);
17227 murrell 68
static void R_Proxy_Graphics_Mode(int mode, NewDevDesc *dd);
27236 murrell 69
static void R_Proxy_Graphics_NewPage(R_GE_gcontext *gc,
70
				     NewDevDesc *dd);
26207 murdoch 71
static void R_Proxy_Graphics_Polygon(int n, double *x, double *y,
27236 murrell 72
				     R_GE_gcontext *gc,
73
				     NewDevDesc *dd);
26207 murdoch 74
static void R_Proxy_Graphics_Polyline(int n, double *x, double *y,
27236 murrell 75
				      R_GE_gcontext *gc,
76
				      NewDevDesc *dd);
17227 murrell 77
static void R_Proxy_Graphics_Rect(double x0, double y0, double x1, double y1,
27236 murrell 78
				  R_GE_gcontext *gc,
79
				  NewDevDesc *dd);
17227 murrell 80
static void R_Proxy_Graphics_Size(double *left, double *right,
27236 murrell 81
				  double *bottom, double *top,
82
				  NewDevDesc *dd);
17511 ripley 83
#ifdef UNUSED
17227 murrell 84
static void R_Proxy_Graphics_Resize(NewDevDesc *dd);
17511 ripley 85
#endif
27236 murrell 86
static double R_Proxy_Graphics_StrWidth(char *str, 
87
					R_GE_gcontext *gc,
88
					NewDevDesc *dd);
26207 murdoch 89
static void R_Proxy_Graphics_Text(double x, double y, char *str,
27236 murrell 90
				  double rot, double hadj,
91
				  R_GE_gcontext *gc,
92
				  NewDevDesc *dd);
17227 murrell 93
static Rboolean R_Proxy_Graphics_Open (NewDevDesc* pDD,
94
				       void* pAXD,
95
				       char* pDisplay,
96
				       double pWidth,
97
				       double pHeight,
98
				       Rboolean pRecording,
99
				       int pResize);
100
 
26207 murdoch 101
/* 00-06-22 | baier | added line type and width */
13365 ripley 102
static void R_Proxy_Graphics_Circle (double pX,
103
				     double pY,
104
				     double pRad,
27236 murrell 105
				     R_GE_gcontext *gc,
17227 murrell 106
				     NewDevDesc* pDD)
13365 ripley 107
{
31242 murdoch 108
/*  OutputDebugString("R_Proxy_Graphics_Circle()\n"); */
13365 ripley 109
  if (__graphics_device)
110
    {
111
      __graphics_device->vtbl->circle (__graphics_device,
112
				       pX,
113
				       pY,
114
				       pRad,
27236 murrell 115
				       gc->fill,
116
				       gc->col,
117
				       gc->lty,
118
				       gc->lwd);
13365 ripley 119
      return;
120
    }
121
 
122
  MessageBox (GetDesktopWindow (),"Circle()","R_Proxy_Graphics",MB_OK);
123
}
124
static void R_Proxy_Graphics_Clip (double pX0,
125
				   double pX1,
126
				   double pY0,
127
				   double pY1,
17227 murrell 128
				   NewDevDesc* pDD)
13365 ripley 129
{
130
  if (__graphics_device)
131
    {
132
      __graphics_device->vtbl->clip (__graphics_device,
133
				     pX0,pX1,pY0,pY1);
134
      return;
135
    }
136
 
137
  MessageBox (GetDesktopWindow (),"Clip()","R_Proxy_Graphics",MB_OK);
138
}
17227 murrell 139
static void R_Proxy_Graphics_Close (NewDevDesc* pDD)
13365 ripley 140
{
141
  if (__graphics_device)
142
    {
143
      __graphics_device->vtbl->close (__graphics_device);
144
      return;
145
    }
146
 
147
  MessageBox (GetDesktopWindow (),"Close()","R_Proxy_Graphics",MB_OK);
148
}
17227 murrell 149
static void R_Proxy_Graphics_Deactivate (NewDevDesc* pDD)
13365 ripley 150
{
151
  if (__graphics_device)
152
    {
153
      __graphics_device->vtbl->deactivate (__graphics_device);
154
      return;
155
    }
156
 
157
  MessageBox (GetDesktopWindow (),"Deactivate()","R_Proxy_Graphics",MB_OK);
158
}
17227 murrell 159
static void R_Proxy_Graphics_Hold (NewDevDesc* pDD)
13365 ripley 160
{
161
  if (__graphics_device)
162
    {
163
      __graphics_device->vtbl->hold (__graphics_device);
164
      return;
165
    }
166
 
167
  MessageBox (GetDesktopWindow (),"Hold()","R_Proxy_Graphics",MB_OK);
168
}
26207 murdoch 169
/* 00-06-22 | baier | added color, line type and width */
13365 ripley 170
static void R_Proxy_Graphics_Line (double pX0,
171
				   double pY0,
172
				   double pX1,
173
				   double pY1,
27236 murrell 174
				   R_GE_gcontext *gc,
17227 murrell 175
				   NewDevDesc* pDD)
13365 ripley 176
{
177
  if (__graphics_device)
178
    {
179
 
180
      __graphics_device->vtbl->line (__graphics_device,
27236 murrell 181
				     pX0,pY0,pX1,pY1,gc->col,
182
				     gc->lty,gc->lwd);
13365 ripley 183
      return;
184
    }
185
 
186
  MessageBox (GetDesktopWindow (),"Line()","R_Proxy_Graphics",MB_OK);
187
}
26207 murdoch 188
/* 01-01-25 | changed return type */
13365 ripley 189
static Rboolean R_Proxy_Graphics_Locator (double* pX,
190
					  double* pY,
17227 murrell 191
					  NewDevDesc* pDD)
13365 ripley 192
{
193
  if (__graphics_device)
194
    {
195
      return __graphics_device->vtbl->locator (__graphics_device,pX,pY);
196
    }
197
 
198
  MessageBox (GetDesktopWindow (),"Locator()","R_Proxy_Graphics",MB_OK);
199
  return 0;
200
}
17227 murrell 201
static void R_Proxy_Graphics_Mode (int pMode, NewDevDesc *dd)
13365 ripley 202
{
203
  if (__graphics_device)
204
    {
205
      __graphics_device->vtbl->mode (__graphics_device,pMode);
206
      return;
207
    }
208
 
209
  MessageBox (GetDesktopWindow (),"Mode()","R_Proxy_Graphics",MB_OK);
210
}
27236 murrell 211
static void R_Proxy_Graphics_NewPage (R_GE_gcontext *gc,
17227 murrell 212
				      NewDevDesc* pDD)
13365 ripley 213
{
214
  if (__graphics_device)
215
    {
216
      __graphics_device->vtbl->newpage (__graphics_device);
217
      return;
218
    }
219
 
220
  MessageBox (GetDesktopWindow (),"NewPage()","R_Proxy_Graphics",MB_OK);
221
}
26207 murdoch 222
/* 01-01-25 | baier | added new parameters "recording", "resize" */
17227 murrell 223
static Rboolean R_Proxy_Graphics_Open (NewDevDesc* pDD,
13365 ripley 224
				       void* pAXD,
225
				       char* pDisplay,
226
				       double pWidth,
227
				       double pHeight,
228
				       Rboolean pRecording,
229
				       int pResize)
230
{
231
  if (__graphics_device)
232
    {
233
      return __graphics_device->vtbl->open (__graphics_device,
234
					    pDisplay,pWidth,pHeight,0.0,0,0);
235
    }
236
 
237
  MessageBox (GetDesktopWindow (),"Open()","R_Proxy_Graphics",MB_OK);
238
  return 1;
239
}
17227 murrell 240
 
13365 ripley 241
static void R_Proxy_Graphics_Polygon (int pCount,
242
				      double* pX,
243
				      double* pY,
27236 murrell 244
				      R_GE_gcontext *gc,
17227 murrell 245
				      NewDevDesc* pDD)
13365 ripley 246
{
247
  if (__graphics_device)
248
    {
26207 murdoch 249
      /* convert coordinates here: don't use alloca() -> overflow? */
13365 ripley 250
      double* lX = (double*) malloc (pCount * sizeof (double));
251
      double* lY = (double*) malloc (pCount * sizeof (double));
252
      int i = 0;
253
 
26207 murdoch 254
      /* could use memcpy() for speed */
13365 ripley 255
      for (i = 0;i < pCount;i++)
256
	{
257
	  lX[i] = pX[i];
258
	  lY[i] = pY[i];
259
 
260
	}
261
 
27236 murrell 262
      /*      sprintf (x,"device::Polygon: bg is %08x, fg is %08x\n",fill,col); */
26207 murdoch 263
      /*      OutputDebugString (x); */
13365 ripley 264
      __graphics_device->vtbl->polygon (__graphics_device,
27236 murrell 265
					pCount,lX,lY,gc->fill,gc->col);
13365 ripley 266
 
267
      free (lX);
268
      free (lY);
269
 
270
      return;
271
    }
272
 
273
  MessageBox (GetDesktopWindow (),"Polygon()","R_Proxy_Graphics",MB_OK);
274
}
26207 murdoch 275
/* 01-01-23 | baier | added "col" parameter */
13365 ripley 276
static void R_Proxy_Graphics_Polyline (int pCount,
277
				       double* pX,
278
				       double* pY,
27236 murrell 279
				       R_GE_gcontext *gc,
17227 murrell 280
				       NewDevDesc* pDD)
13365 ripley 281
{
282
  if (__graphics_device)
283
    {
26207 murdoch 284
      /* convert coordinates here: don't use alloca() -> overflow? */
13365 ripley 285
      double* lX = (double*) malloc (pCount * sizeof (double));
286
      double* lY = (double*) malloc (pCount * sizeof (double));
287
      int i = 0;
288
 
26207 murdoch 289
      /* could use memcpy() for speed */
13365 ripley 290
      for (i = 0;i < pCount;i++)
291
	{
292
	  char x[1000];
293
	  lX[i] = pX[i];
294
	  lY[i] = pY[i];
295
 
296
	  sprintf (x,"Polyline: coord %d is %f/%f (was %f/%f)\n",
297
		   i,lX[i],lY[i],pX[i],pY[i]);
26207 murdoch 298
	  /*	  OutputDebugString (x); */
13365 ripley 299
 
300
	}
301
 
302
      __graphics_device->vtbl->polyline (__graphics_device,
27236 murrell 303
					 pCount,lX,lY,gc->col);
13365 ripley 304
 
305
      free (lX);
306
      free (lY);
307
 
308
      return;
309
    }
310
 
311
  MessageBox (GetDesktopWindow (),"Polyline()","R_Proxy_Graphics",MB_OK);
312
}
26207 murdoch 313
/* 00-06-22 | baier | added line type and width */
13365 ripley 314
static void R_Proxy_Graphics_Rect (double pX0,
315
				   double pY0,
316
				   double pX1,
317
				   double pY1,
27236 murrell 318
				   R_GE_gcontext *gc,
17227 murrell 319
				   NewDevDesc* pDD)
13365 ripley 320
{
321
  if (__graphics_device)
322
    {
323
 
324
      __graphics_device->vtbl->rect (__graphics_device,
27236 murrell 325
				     pX0,pY0,pX1,pY1,gc->fill,gc->col,
326
				     gc->lty,gc->lwd);
13365 ripley 327
      return;
328
    }
329
 
330
  MessageBox (GetDesktopWindow (),"Rect()","R_Proxy_Graphics",MB_OK);
331
}
17227 murrell 332
static void R_Proxy_Graphics_Size(double *left, double *right,
333
				  double *bottom, double *top,
334
				  NewDevDesc *pDD)
13365 ripley 335
{
17227 murrell 336
    *left = pDD->left;
337
    *right = pDD->right;
338
    *bottom = pDD->bottom;
339
    *top = pDD->top;
340
}
17511 ripley 341
 
342
#ifdef UNUSED
17227 murrell 343
static void R_Proxy_Graphics_Resize (NewDevDesc* pDD)
344
{
13365 ripley 345
  if (__graphics_device)
346
    {
347
      __graphics_device->vtbl->resize (__graphics_device);
348
      return;
349
    }
350
 
351
  MessageBox (GetDesktopWindow (),"Resize()","R_Proxy_Graphics",MB_OK);
352
}
17511 ripley 353
#endif
354
 
26207 murdoch 355
/* 00-06-22 | baier | added font and size parameters */
17227 murrell 356
static double R_Proxy_Graphics_StrWidth (char* pString,
27236 murrell 357
					 R_GE_gcontext *gc,
17227 murrell 358
					 NewDevDesc* pDD)
13365 ripley 359
{
360
  if (__graphics_device)
361
    {
27236 murrell 362
      int lSize = gc->cex * gc->ps + 0.5;
13365 ripley 363
      return __graphics_device->vtbl->strwidth (__graphics_device,
364
						pString,
27236 murrell 365
						gc->fontface,
13365 ripley 366
						lSize);
367
    }
368
 
369
  MessageBox (GetDesktopWindow (),"StrWidth()","R_Proxy_Graphics",MB_OK);
370
  return 0.0;
371
}
372
 
26207 murdoch 373
/* 00-06-22 | baier | added color, font and size */
13365 ripley 374
static void R_Proxy_Graphics_Text (double pX,
375
				   double pY,
376
				   char* pString,
377
				   double pRot,
378
				   double pHadj,
27236 murrell 379
				   R_GE_gcontext *gc,
17227 murrell 380
				   NewDevDesc* pDD)
13365 ripley 381
{
382
  if (__graphics_device)
383
    {
27236 murrell 384
      int lSize = gc->cex * gc->ps + 0.5;
13365 ripley 385
 
386
      __graphics_device->vtbl->text (__graphics_device,
387
				     pX,pY,pString,pRot,pHadj,
27236 murrell 388
				     gc->col,gc->fontface,lSize);
13365 ripley 389
      return;
390
    }
391
 
392
  MessageBox (GetDesktopWindow (),"Text()","R_Proxy_Graphics",MB_OK);
393
}
394
 
26207 murdoch 395
/* 00-06-22 | baier | added font and size parameters */
27236 murrell 396
static void R_Proxy_Graphics_MetricInfo(int c, 
397
					R_GE_gcontext *gc,
398
					double* ascent, double* descent,
399
					double* width, NewDevDesc *dd);
13365 ripley 400
static void R_Proxy_Graphics_MetricInfo (int pC,
27236 murrell 401
					 R_GE_gcontext *gc,
13365 ripley 402
					 double* pAscent,
403
					 double* pDescent,
404
					 double* pWidth,
17227 murrell 405
					 NewDevDesc* pDD)
13365 ripley 406
{
407
  if (__graphics_device)
408
    {
27236 murrell 409
      int lSize = gc->cex * gc->ps + 0.5;
13365 ripley 410
      __graphics_device->vtbl->metricinfo (__graphics_device,
411
					   pC,
412
					   pAscent,
413
					   pDescent,
414
					   pWidth,
27236 murrell 415
					   gc->fontface,
13365 ripley 416
					   lSize);
417
      return;
418
    }
419
 
420
  MessageBox (GetDesktopWindow (),"MetricInfo()","R_Proxy_Graphics",MB_OK);
421
}
422
 
26207 murdoch 423
/* 01-01-25 | baier | new paramters */
31242 murdoch 424
/* 04-09-27 | baier | startcol, startfill */
17227 murrell 425
int R_Proxy_Graphics_Driver (NewDevDesc* pDD,
13365 ripley 426
			     char* pDisplay,
427
			     double pWidth,
428
			     double pHeight,
429
			     double pPointSize,
430
			     Rboolean pRecording,
431
			     int pResize,
432
			     struct _SC_GraphicsDevice* pDevice)
433
{
17227 murrell 434
  pDD->startfont = 1;
435
  pDD->startps = pPointSize;
31242 murdoch 436
  pDD->startcol = R_RGB(0, 0, 0);
437
  pDD->startfill = R_TRANWHITE;
17227 murrell 438
  pDD->startlty = LTY_SOLID;
439
  pDD->startgamma = 1;
13365 ripley 440
 
441
  /* init the device-specific functionality here */
442
  pDD->deviceSpecific = (void *) NULL;
443
 
444
  /* Start the Device Driver and Hardcopy.  */
445
  if (!R_Proxy_Graphics_Open (pDD,
446
			      NULL,
447
			      pDisplay,
448
			      pWidth,
449
			      pHeight,
450
			      pRecording,
451
			      pResize)) {
452
    return 0;
453
  }
454
  /* Set up Data Structures  */
455
 
17227 murrell 456
  pDD->newDevStruct = 1;
13365 ripley 457
 
17227 murrell 458
  pDD->open = R_Proxy_Graphics_Open;
459
  pDD->close = R_Proxy_Graphics_Close;
460
  pDD->activate = R_Proxy_Graphics_Activate;
461
  pDD->deactivate = R_Proxy_Graphics_Deactivate;
462
  pDD->size = R_Proxy_Graphics_Size;
463
  pDD->newPage = R_Proxy_Graphics_NewPage;
464
  pDD->clip = R_Proxy_Graphics_Clip;
465
  pDD->strWidth = R_Proxy_Graphics_StrWidth;
466
  pDD->text = R_Proxy_Graphics_Text;
467
  pDD->rect = R_Proxy_Graphics_Rect;
468
  pDD->circle = R_Proxy_Graphics_Circle;
469
  pDD->line = R_Proxy_Graphics_Line;
470
  pDD->polyline = R_Proxy_Graphics_Polyline;
471
  pDD->polygon = R_Proxy_Graphics_Polygon;
472
  pDD->locator = R_Proxy_Graphics_Locator;
473
  pDD->mode = R_Proxy_Graphics_Mode;
474
  pDD->hold = R_Proxy_Graphics_Hold;
475
  pDD->metricInfo = R_Proxy_Graphics_MetricInfo;
476
 
13365 ripley 477
    /* set graphics parameters that must be set by device driver */
478
    /* Window Dimensions in Pixels */
17227 murrell 479
  pDD->left = 0;	/* left */
480
  pDD->right = DEV_X;	/* right */
481
  pDD->top = 0;	/* top */
482
  pDD->bottom = DEV_Y;	/* bottom */
13365 ripley 483
 
484
 
485
  /* Nominal Character Sizes in Pixels */
17227 murrell 486
  pDD->cra[0] = 10;
487
  pDD->cra[1] = 10;
13365 ripley 488
  /* Character Addressing Offsets */
489
  /* These are used to plot a single plotting character */
490
  /* so that it is exactly over the plotting point */
491
 
17227 murrell 492
  pDD->xCharOffset = 0.50;
493
  pDD->yCharOffset = 0.40;
494
  pDD->yLineBias = 0.1;
13365 ripley 495
 
496
  /* Inches per raster unit */
497
 
17227 murrell 498
  pDD->ipr[0] = 1.0 / 72.0;
499
  pDD->ipr[1] = 1.0 / 72.0;
13365 ripley 500
 
501
    /* Device capabilities */
502
    /* Clipping is problematic for X11 */
503
    /* Graphics is clipped, text is not */
504
 
17227 murrell 505
  pDD->canResizePlot = 1;
34906 murdoch 506
  pDD->canChangeFont = 1;
17227 murrell 507
  pDD->canRotateText = 1;
508
  pDD->canResizeText = 1;
509
  pDD->canClip = 1;
31242 murdoch 510
  pDD->displayListOn = 1;
34906 murdoch 511
  pDD->canChangeGamma = 1;
13365 ripley 512
 
513
  /* initialise x11 device description (most of the work */
514
  /* has been done in X11_Open) */
515
 
516
  return 1;
517
}