The R Project SVN R

Rev

Rev 20446 | Rev 30859 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
11507 ripley 1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
4
 *  Copyright (C) 1998--2000  R Development Core Team
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
20
 
21
#ifndef GRAPHICS_H_
22
#define GRAPHICS_H_
23
 
24
#define R_GRAPHICS_INTERNAL 1
25
 
11509 ripley 26
#include <R_ext/Boolean.h>
11507 ripley 27
 
28
#define R_MaxDevices 64
29
 
30
#define	DEG2RAD 0.01745329251994329576
31
 
32
#define COLOR_TABLE_SIZE 1024
33
 
34
#define MAX_LAYOUT_ROWS 15
35
#define MAX_LAYOUT_COLS 15
36
 
37
/* NOTE: during replays, call == R_NilValue;
38
   ----  the following adds readability: */
39
#define GRecording(call)  (call != R_NilValue)
40
 
41
typedef unsigned int rcolor;
42
 
43
typedef struct {
44
	double ax;
45
	double bx;
46
	double ay;
47
	double by;
48
} GTrans;
49
 
50
	/* possible coordinate systems (for specifying locations) */
51
typedef enum {
52
 DEVICE	= 0,	/* native device coordinates (rasters) */
53
 NDC	= 1,	/* normalised device coordinates x=(0,1), y=(0,1) */
54
 INCHES = 13,	/* inches x=(0,width), y=(0,height) */
55
 NIC	= 6,	/* normalised inner region coordinates (0,1) */
56
 OMA1	= 2,	/* outer margin 1 (bottom) x=NIC, y=LINES */
57
 OMA2	= 3,	/* outer margin 2 (left) */
58
 OMA3	= 4,	/* outer margin 3 (top) */
59
 OMA4	= 5,	/* outer margin 4 (right) */
60
 NFC	= 7,	/* normalised figure region coordinates (0,1) */
61
 NPC	= 16,	/* normalised plot region coordinates (0,1) */
11510 ripley 62
 USER	= 12,	/* user/data/world coordinates;
11507 ripley 63
		 * x,=(xmin,xmax), y=(ymin,ymax) */
64
 MAR1	= 8,	/* figure margin 1 (bottom) x=USER(x), y=LINES */
65
 MAR2	= 9,	/* figure margin 2 (left)   x=USER(y), y=LINES */
66
 MAR3	= 10,	/* figure margin 3 (top)    x=USER(x), y=LINES */
67
 MAR4	= 11,	/* figure margin 4 (right)  x=USER(y), y=LINES */
68
 
69
	/* possible, units (for specifying dimensions) */
70
	/* all of the above, plus ... */
71
 
72
 LINES = 14,	/* multiples of a line in the margin (mex) */
73
 CHARS = 15	/* multiples of text height (cex) */
74
} GUnit;
75
 
76
 
77
typedef struct {
78
    /* Basic Device Driver Properties */
79
    /* These MUST be set by device drivers on open */
80
 
81
    /* These parameters cannot be set by the user */
82
    /* although left, right, bottom, and top can be */
83
    /* interrogated indirectly (i.e., par("din")) */
84
    /* and cra can be interrogated directly (i.e., par("cra")) */
85
 
86
    double left;	/* left raster coordinate */
87
    double right;	/* right raster coordinate */
88
    double bottom;	/* bottom raster coordinate */
89
    double top;		/* top raster coordinate */
90
    double xCharOffset;	/* x character addressing offset */
91
    double yCharOffset;	/* y character addressing offset */
92
    double yLineBias;	/* 1/2 interline space as fraction of line height */
93
    Rboolean canResizePlot;	/* can the graphics surface be resized */
94
    Rboolean canChangeFont;	/* device has multiple fonts */
95
    Rboolean canRotateText;	/* text can be rotated */
96
    Rboolean canResizeText;	/* text can be resized */
97
    Rboolean canClip;		/* Hardware clipping */
98
    int canHAdj;	/* Can do at least some horizontal adjustment of text
99
 
100
 
101
    /* a couple of the GRZ-like parameters that have to be */
102
    /* set by the device */
103
 
104
    double ipr[2];	/* Inches per raster; [0]=x, [1]=y */
105
    double asp;		/* Pixel aspect ratio = ipr[1]/ipr[0] */
106
    double cra[2];	/* Character size in rasters; [0]=x, [1]=y */
107
 
108
    /* Plot State */
109
    /* When the device driver is started this is 0 */
110
    /* After the first call to plot.new it is 1 */
111
    /* Every graphics operation except plot.new */
112
    /* should fail if state = 0 */
113
    /* This is checked at the highest internal function */
114
    /* level (e.g., do_lines, do_axis, do_plot_xy, ...) */
115
 
116
    int	state;		/* Plot State */
117
    Rboolean valid;	/* valid layout ? */
118
 
119
    /* GRZ-like Graphics Parameters */
120
    /* ``The horror, the horror ... '' */
121
    /* Marlon Brando - Appocalypse Now */
122
 
123
    /* General Parameters -- set and interrogated directly */
124
 
125
    double adj;		/* String adjustment */
126
    Rboolean ann;	/* Should annotation take place */
127
    Rboolean ask;	/* User confirmation of ``page eject'' */
128
    rcolor bg;		/* **R ONLY** Background color */
129
    int	bty;		/* Box type */
130
    double cex;		/* Character expansion */
131
    rcolor col;		/* Plotting Color */
132
    double crt;		/* Character/string rotation */
133
    double din[2];	/* device size in inches */
134
    int	err;		/* Error repporting level */
135
    rcolor fg;		/* **R ONLY** Foreground Color */
136
    int	font;		/* Text font */
137
    double gamma;	/* Device Gamma Correction */
138
    int	lab[3];		/* Axis labelling */
139
			/* [0] = # ticks on x-axis */
140
			/* [1] = # ticks on y-axis */
141
			/* [2] = length of axis labels */
142
    int	las;		/* Label style (rotation) */
143
    int	lty;		/* Line texture */
144
    double lwd;		/* Line width */
145
    double mgp[3];	/* Annotation location */
146
			/* [0] = location of axis title */
147
			/* [1] = location of axis label */
148
			/* [2] = location of axis line */
149
    double mkh;		/* Mark size in inches */
150
    int	pch;		/* Plotting character */
151
    int	ps;		/* Text & symbol pointsize */
20446 maechler 152
    int	smo;		/* Curve smoothness */
11507 ripley 153
    double srt;		/* String Rotation */
154
    double tck;		/* Tick size as in S */
155
    double tcl;		/* Tick size in "lines" */
156
    double tmag;	/* **R ONLY** Title Magnification */
157
    int	type;		/* type of plot desired */
158
    double xaxp[3];	/* X Axis annotation */
159
			/* [0] = coordinate of lower tick */
160
			/* [1] = coordinate of upper tick */
161
			/* [2] = num tick intervals */
162
			/* almost always used internally */
163
    int	xaxs;		/* X Axis style */
164
    int	xaxt;		/* X Axis type */
165
    int	xpd;		/* Clip to plot region indicator */
166
    int	oldxpd;
167
    double yaxp[3];	/* Y Axis annotation */
168
    int	yaxs;		/* Y Axis style */
169
    int	yaxt;		/* Y Axis type */
170
    Rboolean xlog;	/* Log Axis for X */
171
    Rboolean ylog;	/* Log Axis for Y */
172
 
173
    /* Annotation Parameters */
174
 
175
    float cexbase;	/* Base character size */
176
    float cexmain;	/* Main title size */
177
    float cexlab;	/* xlab and ylab size */
178
    float cexsub;	/* Sub title size */
179
    float cexaxis;	/* Axis label size */
180
 
181
    int	fontmain;	/* Main title font */
182
    int	fontlab;	/* Xlab and ylab font */
183
    int	fontsub;	/* Subtitle font */
184
    int	fontaxis;	/* Axis label fonts */
185
 
186
    int	colmain;	/* Main title color */
187
    int	collab;		/* Xlab and ylab color */
188
    int	colsub;		/* Subtitle color */
189
    int	colaxis;	/* Axis label color */
190
 
191
    /* Layout Parameters */
192
 
193
    Rboolean layout;	/* has a layout been specified */
194
 
195
    int	numrows;
196
    int	numcols;
197
    int	currentFigure;
198
    int	lastFigure;
199
    double heights[MAX_LAYOUT_ROWS];
200
    double widths[MAX_LAYOUT_COLS];
201
    int	cmHeights[MAX_LAYOUT_ROWS];
202
    int	cmWidths[MAX_LAYOUT_COLS];
203
    int	order[MAX_LAYOUT_ROWS][MAX_LAYOUT_COLS];
204
    int	rspct;		/* 0 = none, 1 = full, 2 = see respect */
205
    int	respect[MAX_LAYOUT_ROWS][MAX_LAYOUT_COLS];
206
 
207
    int	mfind;		/* By row/col indicator */
208
 
209
    /* Layout parameters which can be set directly by the */
210
    /* user (e.g., par(fig=c(.5,1,0,1))) or otherwise are */
211
    /* calculated automatically */
212
    /* NOTE that *Units parameters are for internal use only */
213
 
214
    double fig[4];	/* (current) Figure size (proportion) */
215
			/* [0] = left, [1] = right */
216
			/* [2] = bottom, [3] = top */
217
    double fin[2];	/* (current) Figure size (inches) */
218
			/* [0] = width, [1] = height */
219
    GUnit fUnits;	/* (current) figure size units */
220
    double plt[4];	/* (current) Plot size (proportions) */
221
			/* [0] = left, [1] = right */
222
			/* [2] = bottom, [3] = top */
223
    double pin[2];	/* (current) plot size (inches) */
224
			/* [0] = width, [1] = height */
225
    GUnit pUnits;	/* (current) plot size units */
226
    Rboolean defaultFigure;	/* calculate figure from layout ? */
227
    Rboolean defaultPlot;	/* calculate plot from figure - margins ? */
228
 
229
    /* Layout parameters which are set directly by the user */
230
 
231
    double mar[4];	/* Plot margins in lines */
232
    double mai[4];	/* Plot margins in inches */
233
			/* [0] = bottom, [1] = left */
234
			/* [2] = top, [3] = right */
235
    GUnit mUnits;	/* plot margin units */
236
    double mex;		/* Margin expansion factor */
237
    double oma[4];	/* Outer margins in lines */
238
    double omi[4];	/* outer margins in inches */
239
    double omd[4];	/* outer margins in NDC */
240
			/* [0] = bottom, [1] = left */
241
			/* [2] = top, [3] = right */
242
    GUnit oUnits;	/* outer margin units */
243
    int	pty;		/* Plot type */
244
 
245
    /* Layout parameters which can be set by the user, but */
246
    /* almost always get automatically calculated anyway */
247
 
248
    double usr[4];	/* Graphics window */
249
			/* [0] = xmin, [1] = xmax */
250
			/* [2] = ymin, [3] = ymax */
251
 
252
    /* The logged usr parameter;  if xlog, use logusr[0:1] */
253
    /* if ylog, use logusr[2:3] */
254
 
255
    double logusr[4];
256
 
257
    /* Layout parameter: Internal flags */
258
 
259
    Rboolean new;	/* Clean plot ? */
260
    int	devmode;	/* creating new image or adding to existing one */
261
 
262
    /* Coordinate System Mappings */
263
    /* These are only used internally (i.e., cannot be */
264
    /* set directly by the user) */
265
 
266
    /* The reliability of these parameters relies on */
267
    /* the fact that plot.new is the */
268
    /* first graphics operation called in the creation */
269
    /* of a graph */
270
 
271
    /* udpated per plot.new */
272
 
273
    double xNDCPerChar;	/* Nominal character width (NDC) */
274
    double yNDCPerChar;	/* Nominal character height (NDC) */
275
    double xNDCPerLine;	/* Nominal line width (NDC) */
276
    double yNDCPerLine;	/* Nominal line height (NDC) */
277
    double xNDCPerInch;	/* xNDC -> Inches */
278
    double yNDCPerInch;	/* yNDC -> Inches */
279
 
280
    /* updated per plot.new and if inner2dev changes */
281
 
282
    GTrans fig2dev;	/* Figure to device */
283
 
284
    /* udpated per DevNewPlot and if ndc2dev changes */
285
 
286
    GTrans inner2dev;	/* Inner region to device */
287
 
288
    /* udpated per device resize */
289
 
290
    GTrans ndc2dev;	/* NDC to raw device */
291
 
292
    /* updated per plot.new and per plot.window */
293
 
294
    GTrans win2fig;	/* Window to figure mapping */
295
 
296
    /* NOTE: if user has not set fig and/or plt then */
297
    /* they need to be updated per plot.new too */
298
 
299
    /* device operations */
300
    Rboolean (*open)();
301
    void (*close)();
302
    void (*activate)();
303
    void (*deactivate)();
304
    void (*resize)();
305
    void (*newPage)();
306
    void (*clip)();
307
    double (*strWidth)();
308
    void (*line)();
309
    void (*polyline)();
310
    void (*text)();
311
    void (*dot)();
312
    void (*rect)();
313
    void (*circle)();
314
    void (*polygon)();
315
    Rboolean (*locator)();
316
    void (*mode)();
317
    void (*hold)();
318
    void (*metricInfo)();
319
} GPar;
320
 
321
typedef struct {
16880 murrell 322
    /* New flag to indicate that this is an "old" device
323
     * structure.
324
     */
325
    int newDevStruct;
326
    GPar dp;		/* current device default parameters */
327
    GPar gp;		/* current device current parameters */
328
    GPar dpSaved;		/* saved device default parameters */
329
    void *deviceSpecific;	/* pointer to device specific parameters */
330
    Rboolean displayListOn;	/* toggle for display list status */
331
    SEXP displayList;	/* display list */
11507 ripley 332
} DevDesc;
333
 
19934 maechler 334
/* For easy reference: Here are the source files of
11507 ripley 335
 * currently existing device drivers:
336
 * FILE				driver name prefix
337
 * ----------------------	------------------
20446 maechler 338
 * ../main/devPS.c		PS , PDF _and_  XFig
11507 ripley 339
 * ../main/devPicTeX.c		PicTeX
15168 pd 340
 * ../modules/X11/devX11.c	X11
11507 ripley 341
 * ../gnuwin32/devga.c		GA
15168 pd 342
 * ../modules/gnome/devGTK.c	GTK
343
 * ../modules/gnome/devGNOME.c	Gnome
11507 ripley 344
 */
345
 
11510 ripley 346
/* always remap private functions */
11509 ripley 347
#include <Rgraphics.h>
11510 ripley 348
#define char2col		Rf_char2col
349
#define col2name		Rf_col2name
350
#define copyGPar		Rf_copyGPar
16880 murrell 351
#define curDevice               Rf_curDevice
352
#define GetDevice               Rf_GetDevice
11510 ripley 353
#define GInit			Rf_GInit
354
#define name2col		Rf_name2col
16880 murrell 355
#define nextDevice              Rf_nextDevice
11510 ripley 356
#define number2col		Rf_number2col
16880 murrell 357
#define NumDevices              Rf_NumDevices
11510 ripley 358
#define rgb2col			Rf_rgb2col
359
#define RGB2rgb			Rf_RGB2rgb
360
#define ScaleColor		Rf_ScaleColor
361
#define str2col			Rf_str2col
362
#define StrMatch		Rf_StrMatch
11507 ripley 363
 
364
/* Default the settings for general graphical parameters
365
 * (i.e., defaults that do not depend on the device type: */
366
void GInit(GPar*);
367
 
11510 ripley 368
void copyGPar(GPar *, GPar *);
369
 
16880 murrell 370
int curDevice(void);
11510 ripley 371
 
16880 murrell 372
DevDesc* GetDevice(int i);
11510 ripley 373
 
16880 murrell 374
int nextDevice(int from);
375
 
376
int NumDevices(void);
377
 
378
int deviceNumber(DevDesc *dd);
379
 
380
int devNumber(DevDesc *dd);
381
 
11510 ripley 382
		/* Miscellaneous (from graphics.c & colors.c) */
383
 
384
unsigned int rgb2col(char *);
385
unsigned int name2col(char *);
386
unsigned int number2col(char *);
387
unsigned int char2col(char *);/* rgb2col() or name2col() */
388
unsigned int str2col(char *);
389
 
390
char* col2name(unsigned int);
391
 
392
unsigned int ScaleColor(double x);
20446 maechler 393
unsigned int CheckColor(int x);
11510 ripley 394
 
395
char* RGB2rgb(unsigned int, unsigned int, unsigned int);
396
 
397
int StrMatch(char *s, char *t);
398
 
399
double R_Log10(double);
400
 
17204 hornik 401
#include <R_ext/GraphicsDevice.h>
402
#include <R_ext/GraphicsEngine.h>
403
#include <R_ext/GraphicsBase.h>
16880 murrell 404
 
27237 murrell 405
/* 
406
 * Function to generate an R_GE_gcontext from Rf_gpptr info
407
 */
408
void gcontextFromGP(R_GE_gcontext *gc, DevDesc *dd);
409
 
16880 murrell 410
/* FIXME: Make this a macro to avoid function call overhead?
411
 */
17179 murrell 412
GPar* Rf_gpptr(DevDesc *dd);
413
GPar* Rf_dpptr(DevDesc *dd);
414
GPar* Rf_dpSavedptr(DevDesc *dd);
415
SEXP Rf_displayList(DevDesc *dd);
16880 murrell 416
 
11507 ripley 417
#endif /* GRAPHICS_H_ */