The R Project SVN R

Rev

Rev 41909 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
29921 ripley 1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
41909 ripley 3
 *  Copyright (C) 2001-7 The R Development Core Team.
29921 ripley 4
 *
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU Lesser General Public License as published by
7
 *  the Free Software Foundation; either version 2.1 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program 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
13
 *  GNU Lesser General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Lesser General Public License
16
 *  along with this program; if not, write to the Free Software
36820 ripley 17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
29921 ripley 18
 */
17204 hornik 19
 
29921 ripley 20
/* Used by third-party graphics devices */
21
 
34747 ripley 22
#ifndef R_GRAPHICSENGINE_H_
23
#define R_GRAPHICSENGINE_H_
24
 
41909 ripley 25
#include <R_ext/GraphicsDevice.h> /* needed for NewDevDesc */
26
 
34747 ripley 27
#ifdef __cplusplus
28
extern "C" {
29
#endif
30
 
32815 murrell 31
/*
32
 * The current graphics engine (including graphics device) API version
33
 * MUST be integer
34
 * 
35
 * This number should be bumped whenever there are changes to 
36
 * GraphicsEngine.h or GraphicsDevice.h so that add-on packages
37
 * that compile against these headers (graphics systems such as
38
 * graphics and grid;  graphics devices such as gtkDevice, RSvgDevice)
39
 * can detect any version mismatch.
40
 *
41
 * Version 1:  Introduction of the version number.
34785 murrell 42
 * Version 2:  GEDevDesc *dd dropped from GEcontourLines().
41887 murrell 43
 * Version 3:  R_GE_str2col() added to API.
32815 murrell 44
 */
45
 
41887 murrell 46
#define R_GE_version 3
32815 murrell 47
 
48
int R_GE_getVersion();
49
 
50
void R_GE_checkVersionOrDie(int version);
51
 
17204 hornik 52
/* The graphics engine will only accept locations and dimensions 
53
 * in native device coordinates, but it provides the following functions
54
 * for converting between a couple of simple alternative coordinate 
55
 * systems and device coordinates:
56
 *    DEVICE = native units of the device
57
 *    NDC = Normalised device coordinates 
58
 *    INCHES = inches (!)
59
 *    CM = centimetres (!!)
60
 */
61
 
62
typedef enum {
63
 GE_DEVICE	= 0,	/* native device coordinates (rasters) */
64
 GE_NDC	= 1,	/* normalised device coordinates x=(0,1), y=(0,1) */
65
 GE_INCHES = 2,
66
 GE_CM     = 3
67
} GEUnit;
68
 
69
#define MAX_GRAPHICS_SYSTEMS 24
70
 
71
typedef enum {
72
    /* In response to this event, the registered graphics system
73
     * should allocate and initialise the systemSpecific structure
74
     */
75
    GE_InitState = 0,
76
    /* This event gives the registered system a chance to undo
77
     * anything done in the initialisation.
78
     */
79
    GE_FinaliseState = 1,
80
    /* This is sent by the graphics engine prior to initialising
81
     * the display list.  It give the graphics system the chance
82
     * to squirrel away information it will need for redrawing the
83
     * the display list
84
     */
85
    GE_SaveState = 2,
86
    /* This is sent by the graphics engine prior to replaying the
87
     * display list.  It gives the graphics system the chance to
88
     * restore any information it saved on the GE_SaveState event
89
     */
90
    GE_RestoreState = 6,
91
    /* Copy system state information to the current device.
92
     * This is used when copying graphics from one device to another
93
     * so all the graphics system needs to do is to copy across
94
     * the bits required for the display list to draw faithfully
95
     * on the new device.
96
     */
97
    GE_CopyState = 3,
98
    /* Create a snapshot of the system state that is sufficient
99
     * for the current "image" to be reproduced
100
     */
101
    GE_SaveSnapshotState = 4,
102
    /* Restore the system state that is saved by GE_SaveSnapshotState
103
     */
104
    GE_RestoreSnapshotState = 5,
105
    /* When replaying the display list, the graphics engine 
106
     * checks, after each replayed action, that the action 
107
     * produced valid output.  This is the graphics system's
108
     * chance to say that the output is crap (in which case the
109
     * graphics engine will abort the display list replay).
110
     */
17270 murrell 111
    GE_CheckPlot = 7,
112
    /* The device wants to scale the current pointsize
113
     * (for scaling an image)
114
     * This is not a nice general solution, but a quick fix for 
115
     * the Windows device.
116
     */
117
    GE_ScalePS = 8
17204 hornik 118
} GEevent;
119
 
19966 duncan 120
typedef struct _GEDevDesc GEDevDesc;
17204 hornik 121
 
19966 duncan 122
typedef SEXP (* GEcallback)(GEevent, GEDevDesc *, SEXP);
123
 
124
typedef struct { 
17204 hornik 125
    /* An array of information about each graphics system that
126
     * has registered with the graphics engine.
127
     * This is used to store graphics state for each graphics
128
     * system on each device.
129
     */
130
    void *systemSpecific;
131
    /* 
132
     * An array of function pointers, one per graphics system that
133
     * has registered with the graphics engine.
134
     *
135
     * system_Callback is called when the graphics engine wants
136
     * to give a graphics system the chance to play with its
137
     * device-specific information (stored in systemSpecific)
138
     * There are two parameters:  an "event" to tell the graphics
139
     * system why the graphics engine has called this function,
140
     * and the systemSpecific pointer.  The graphics engine
141
     * has to pass the systemSpecific pointer because only
142
     * the graphics engine will know what array index to use.
143
     */
144
    GEcallback callback;
145
} GESystemDesc;
146
 
19966 duncan 147
struct _GEDevDesc {
17204 hornik 148
    int newDevStruct;
30832 murrell 149
    /* 
150
     * Stuff that the devices can see (and modify).
151
     * All detailed in GraphicsDevice.h
152
     */
17204 hornik 153
    NewDevDesc *dev;
30832 murrell 154
    /*
155
     * Stuff about the device that only the graphics engine sees
156
     * (the devices don't see it).
157
     * Display list stuff should come here from NewDevDesc struct.
17204 hornik 158
     */
30832 murrell 159
    Rboolean dirty;  /* Has the device received any output? */
31938 murrell 160
    Rboolean recordGraphics; /* Should a graphics call be stored
161
			      * on the display list?
162
			      * Set to FALSE by do_recordGraphics,
163
			      * do_dotcallgr, and do_Externalgr 
164
			      * so that nested calls are not
165
			      * recorded on the display list
166
			      */
30832 murrell 167
    /* 
168
     * Stuff about the device that only graphics systems see.
169
     * The graphics engine has no idea what is in here.
170
     * Used by graphics systems to store system state per device.
171
     */
17204 hornik 172
    GESystemDesc *gesd[MAX_GRAPHICS_SYSTEMS];
19966 duncan 173
};
17204 hornik 174
 
30925 murrell 175
/*
176
 *  Some line end/join constants
177
 */
178
typedef enum {
179
  GE_ROUND_CAP  = 1,
180
  GE_BUTT_CAP   = 2,
181
  GE_SQUARE_CAP = 3
182
} R_GE_lineend;
183
 
184
typedef enum {
185
  GE_ROUND_JOIN = 1,
186
  GE_MITRE_JOIN = 2,
187
  GE_BEVEL_JOIN = 3
188
} R_GE_linejoin;
189
 
27236 murrell 190
/* 
191
 * A structure containing graphical parameters 
192
 *
193
 * This is how graphical parameters are passed from graphics systems
194
 * to the graphics engine AND from the graphics engine to graphics
195
 * devices.
196
 *
197
 * Devices are not *required* to honour graphical parameters
198
 * (e.g., alpha transparency is going to be tough for some)
199
 */
200
typedef struct {
201
    /*
202
     * Colours
203
     *
204
     * NOTE:  Alpha transparency included in col & fill
205
     */
206
    int col;             /* pen colour (lines, text, borders, ...) */
207
    int fill;            /* fill colour (for polygons, circles, rects, ...) */
208
    double gamma;        /* Gamma correction */
209
    /* 
210
     * Line characteristics
211
     */
212
    double lwd;          /* Line width (roughly number of pixels) */
213
    int lty;             /* Line type (solid, dashed, dotted, ...) */
30925 murrell 214
    R_GE_lineend lend;   /* Line end */
215
    R_GE_linejoin ljoin; /* line join */
216
    double lmitre;       /* line mitre */
27236 murrell 217
    /*
218
     * Text characteristics
219
     */
220
    double cex;          /* Character expansion (font size = fontsize*cex) */
221
    double ps;           /* Font size in points */
222
    double lineheight;   /* Line height (multiply by font size) */
223
    int fontface;        /* Font face (plain, italic, bold, ...) */
36203 ripley 224
    char fontfamily[201]; /* Font family */
27236 murrell 225
} R_GE_gcontext;
226
 
17204 hornik 227
GEDevDesc* GEcreateDevDesc(NewDevDesc* dev);
228
void GEdestroyDevDesc(GEDevDesc* dd);
229
void* GEsystemState(GEDevDesc *dd, int index);
230
void GEregisterWithDevice(GEDevDesc *dd);
17360 murrell 231
void GEregisterSystem(GEcallback callback, int *systemRegisterIndex);
17204 hornik 232
void GEunregisterSystem(int registerIndex);
233
 
234
SEXP GEHandleEvent(GEevent event, NewDevDesc *dev, SEXP data);
235
 
38705 ripley 236
#define fromDeviceX		GEfromDeviceX
237
#define toDeviceX		GEtoDeviceX
238
#define fromDeviceY		GEfromDeviceY
239
#define toDeviceY		GEtoDeviceY
240
#define fromDeviceWidth		GEfromDeviceWidth
241
#define toDeviceWidth		GEtoDeviceWidth
242
#define fromDeviceHeight	GEfromDeviceHeight
243
#define toDeviceHeight		GEtoDeviceHeight
244
 
17204 hornik 245
double fromDeviceX(double value, GEUnit to, GEDevDesc *dd); 
246
double toDeviceX(double value, GEUnit from, GEDevDesc *dd);
247
double fromDeviceY(double value, GEUnit to, GEDevDesc *dd); 
248
double toDeviceY(double value, GEUnit from, GEDevDesc *dd);
249
double fromDeviceWidth(double value, GEUnit to, GEDevDesc *dd); 
250
double toDeviceWidth(double value, GEUnit from, GEDevDesc *dd);
251
double fromDeviceHeight(double value, GEUnit to, GEDevDesc *dd); 
252
double toDeviceHeight(double value, GEUnit from, GEDevDesc *dd);
253
 
254
/*
255
 *	Some Notes on Line Textures
256
 *
257
 *	Line textures are stored as an array of 4-bit integers within
258
 *	a single 32-bit word.  These integers contain the lengths of
259
 *	lines to be drawn with the pen alternately down and then up.
260
 *	The device should try to arrange that these values are measured
261
 *	in points if possible, although pixels is ok on most displays.
262
 *
263
 *	If newlty contains a line texture description it is decoded
264
 *	as follows:
265
 *
266
 *		ndash = 0;
267
 *		for(i=0 ; i<8 && newlty & 15 ; i++) {
268
 *			dashlist[ndash++] = newlty & 15;
269
 *			newlty = newlty>>4;
270
 *		}
271
 *		dashlist[0] = length of pen-down segment
272
 *		dashlist[1] = length of pen-up segment
273
 *		etc
274
 *
275
 *	An integer containing a zero terminates the pattern.  Hence
276
 *	ndash in this code fragment gives the length of the texture
277
 *	description.  If a description contains an odd number of
278
 *	elements it is replicated to create a pattern with an
279
 *	even number of elements.  (If this is a pain, do something
280
 *	different its not crucial).
281
 *
282
 */
283
 
284
/*--- The basic numbered & names line types; Here device-independent:
285
  e.g. "dashed" == "44",  "dotdash" == "1343"
286
*/
287
 
288
#define LTY_BLANK	-1
289
#define LTY_SOLID	0
290
#define LTY_DASHED	4 + (4<<4)
291
#define LTY_DOTTED	1 + (3<<4)
292
#define LTY_DOTDASH	1 + (3<<4) + (4<<8) + (3<<12)
293
#define LTY_LONGDASH	7 + (3<<4)
294
#define LTY_TWODASH	2 + (2<<4) + (6<<8) + (2<<12)
295
 
30925 murrell 296
R_GE_lineend LENDpar(SEXP value, int ind);
30956 murrell 297
SEXP LENDget(R_GE_lineend lend);
30925 murrell 298
R_GE_linejoin LJOINpar(SEXP value, int ind);
30956 murrell 299
SEXP LJOINget(R_GE_linejoin ljoin);
30925 murrell 300
 
41887 murrell 301
unsigned int R_GE_str2col(const char *s);
302
 
17204 hornik 303
void GESetClip(double x1, double y1, double x2, double y2, GEDevDesc *dd);
27236 murrell 304
void GENewPage(R_GE_gcontext *gc, GEDevDesc *dd);
17204 hornik 305
void GELine(double x1, double y1, double x2, double y2, 
27236 murrell 306
	    R_GE_gcontext *gc, GEDevDesc *dd);
17204 hornik 307
void GEPolyline(int n, double *x, double *y, 
27236 murrell 308
		R_GE_gcontext *gc, GEDevDesc *dd);
17204 hornik 309
void GEPolygon(int n, double *x, double *y, 
27236 murrell 310
	       R_GE_gcontext *gc, GEDevDesc *dd);
36362 murrell 311
SEXP GEXspline(int n, double *x, double *y, double *s, Rboolean open, 
36748 murrell 312
	       Rboolean repEnds, Rboolean draw,
36362 murrell 313
	       R_GE_gcontext *gc, GEDevDesc *dd);
17204 hornik 314
void GECircle(double x, double y, double radius,
27236 murrell 315
	      R_GE_gcontext *gc, GEDevDesc *dd);
17204 hornik 316
void GERect(double x0, double y0, double x1, double y1,
27236 murrell 317
	    R_GE_gcontext *gc, GEDevDesc *dd);
39880 duncan 318
void GEText(double x, double y, const char * const str,
21060 murrell 319
	    double xc, double yc, double rot,
27236 murrell 320
	    R_GE_gcontext *gc, GEDevDesc *dd);
17204 hornik 321
void GEMode(int mode, GEDevDesc* dd);
322
void GESymbol(double x, double y, int pch, double size,
27236 murrell 323
	      R_GE_gcontext *gc, GEDevDesc *dd);
17204 hornik 324
void GEPretty(double *lo, double *up, int *ndiv);
27236 murrell 325
void GEMetricInfo(int c, R_GE_gcontext *gc, 
17204 hornik 326
		  double *ascent, double *descent, double *width,
327
		  GEDevDesc *dd);
41771 ripley 328
double GEStrWidth(const char *str, 
27236 murrell 329
		  R_GE_gcontext *gc, GEDevDesc *dd);
41771 ripley 330
double GEStrHeight(const char *str, 
27236 murrell 331
		  R_GE_gcontext *gc, GEDevDesc *dd);
17204 hornik 332
 
21060 murrell 333
/* 
334
 * From plotmath.c 
19875 murrell 335
 */
336
double GEExpressionWidth(SEXP expr, 
27236 murrell 337
			 R_GE_gcontext *gc, GEDevDesc *dd);
19875 murrell 338
double GEExpressionHeight(SEXP expr, 
27236 murrell 339
			  R_GE_gcontext *gc, GEDevDesc *dd);
19875 murrell 340
void GEMathText(double x, double y, SEXP expr,
341
		double xc, double yc, double rot, 
27236 murrell 342
		R_GE_gcontext *gc, GEDevDesc *dd);
21060 murrell 343
/* 
344
 * (End from plotmath.c)
19875 murrell 345
 */
346
 
21060 murrell 347
/* 
348
 * From plot3d.c 
349
 */
350
SEXP GEcontourLines(double *x, int nx, double *y, int ny,
34785 murrell 351
		    double *z, double *levels, int nl);
21060 murrell 352
/* 
353
 * (End from plot3d.c)
354
 */
355
 
356
/* 
357
 * From vfonts.c
358
 */
41875 ripley 359
double R_GE_VStrWidth(const char *s, R_GE_gcontext *gc, GEDevDesc *dd);
21060 murrell 360
 
41875 ripley 361
double R_GE_VStrHeight(const char *s, R_GE_gcontext *gc, GEDevDesc *dd);
21060 murrell 362
 
39866 duncan 363
void R_GE_VText(double x, double y, const char * const s, 
21060 murrell 364
		double x_justify, double y_justify, double rotation,
27236 murrell 365
		R_GE_gcontext *gc, GEDevDesc *dd);
21060 murrell 366
/* 
367
 * (End from vfonts.c)
368
 */
369
 
17204 hornik 370
#define	DEG2RAD 0.01745329251994329576
371
 
372
GEDevDesc* GEcurrentDevice();
30832 murrell 373
Rboolean GEdeviceDirty(GEDevDesc *dd);
374
void GEdirtyDevice(GEDevDesc *dd);
375
Rboolean GEcheckState(GEDevDesc *dd);
31938 murrell 376
Rboolean GErecording(SEXP call, GEDevDesc *dd);
30832 murrell 377
void GErecordGraphicOperation(SEXP op, SEXP args, GEDevDesc *dd);
17204 hornik 378
void GEinitDisplayList(GEDevDesc *dd);
379
void GEplayDisplayList(GEDevDesc *dd);
380
void GEcopyDisplayList(int fromDevice);
381
SEXP GEcreateSnapshot(GEDevDesc *dd);
382
void GEplaySnapshot(SEXP snapshot, GEDevDesc* dd);
31938 murrell 383
void GEonExit();
31994 murrell 384
void GEnullDevice();
34747 ripley 385
 
386
 
387
#ifdef __cplusplus
388
}
389
#endif
390
 
391
#endif /* R_GRAPHICSENGINE_ */