| 30691 |
murdoch |
1 |
/*
|
|
|
2 |
* R : A Computer Language for Statistical Data Analysis
|
|
|
3 |
* Copyright (C) 2001-4 The R Development Core Team.
|
|
|
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
|
|
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
18 |
*/
|
| 17204 |
hornik |
19 |
|
| 30691 |
murdoch |
20 |
/* Used by third-party graphics devices */
|
|
|
21 |
|
| 17204 |
hornik |
22 |
/* The graphics engine will only accept locations and dimensions
|
|
|
23 |
* in native device coordinates, but it provides the following functions
|
|
|
24 |
* for converting between a couple of simple alternative coordinate
|
|
|
25 |
* systems and device coordinates:
|
|
|
26 |
* DEVICE = native units of the device
|
|
|
27 |
* NDC = Normalised device coordinates
|
|
|
28 |
* INCHES = inches (!)
|
|
|
29 |
* CM = centimetres (!!)
|
|
|
30 |
*/
|
|
|
31 |
|
|
|
32 |
typedef enum {
|
|
|
33 |
GE_DEVICE = 0, /* native device coordinates (rasters) */
|
|
|
34 |
GE_NDC = 1, /* normalised device coordinates x=(0,1), y=(0,1) */
|
|
|
35 |
GE_INCHES = 2,
|
|
|
36 |
GE_CM = 3
|
|
|
37 |
} GEUnit;
|
|
|
38 |
|
|
|
39 |
#define MAX_GRAPHICS_SYSTEMS 24
|
|
|
40 |
|
|
|
41 |
typedef enum {
|
|
|
42 |
/* In response to this event, the registered graphics system
|
|
|
43 |
* should allocate and initialise the systemSpecific structure
|
|
|
44 |
*/
|
|
|
45 |
GE_InitState = 0,
|
|
|
46 |
/* This event gives the registered system a chance to undo
|
|
|
47 |
* anything done in the initialisation.
|
|
|
48 |
*/
|
|
|
49 |
GE_FinaliseState = 1,
|
|
|
50 |
/* This is sent by the graphics engine prior to initialising
|
|
|
51 |
* the display list. It give the graphics system the chance
|
|
|
52 |
* to squirrel away information it will need for redrawing the
|
|
|
53 |
* the display list
|
|
|
54 |
*/
|
|
|
55 |
GE_SaveState = 2,
|
|
|
56 |
/* This is sent by the graphics engine prior to replaying the
|
|
|
57 |
* display list. It gives the graphics system the chance to
|
|
|
58 |
* restore any information it saved on the GE_SaveState event
|
|
|
59 |
*/
|
|
|
60 |
GE_RestoreState = 6,
|
|
|
61 |
/* Copy system state information to the current device.
|
|
|
62 |
* This is used when copying graphics from one device to another
|
|
|
63 |
* so all the graphics system needs to do is to copy across
|
|
|
64 |
* the bits required for the display list to draw faithfully
|
|
|
65 |
* on the new device.
|
|
|
66 |
*/
|
|
|
67 |
GE_CopyState = 3,
|
|
|
68 |
/* Create a snapshot of the system state that is sufficient
|
|
|
69 |
* for the current "image" to be reproduced
|
|
|
70 |
*/
|
|
|
71 |
GE_SaveSnapshotState = 4,
|
|
|
72 |
/* Restore the system state that is saved by GE_SaveSnapshotState
|
|
|
73 |
*/
|
|
|
74 |
GE_RestoreSnapshotState = 5,
|
|
|
75 |
/* When replaying the display list, the graphics engine
|
|
|
76 |
* checks, after each replayed action, that the action
|
|
|
77 |
* produced valid output. This is the graphics system's
|
|
|
78 |
* chance to say that the output is crap (in which case the
|
|
|
79 |
* graphics engine will abort the display list replay).
|
|
|
80 |
*/
|
| 17270 |
murrell |
81 |
GE_CheckPlot = 7,
|
|
|
82 |
/* The device wants to scale the current pointsize
|
|
|
83 |
* (for scaling an image)
|
|
|
84 |
* This is not a nice general solution, but a quick fix for
|
|
|
85 |
* the Windows device.
|
|
|
86 |
*/
|
|
|
87 |
GE_ScalePS = 8
|
| 17204 |
hornik |
88 |
} GEevent;
|
|
|
89 |
|
| 19966 |
duncan |
90 |
typedef struct _GEDevDesc GEDevDesc;
|
| 17204 |
hornik |
91 |
|
| 19966 |
duncan |
92 |
typedef SEXP (* GEcallback)(GEevent, GEDevDesc *, SEXP);
|
|
|
93 |
|
|
|
94 |
typedef struct {
|
| 17204 |
hornik |
95 |
/* An array of information about each graphics system that
|
|
|
96 |
* has registered with the graphics engine.
|
|
|
97 |
* This is used to store graphics state for each graphics
|
|
|
98 |
* system on each device.
|
|
|
99 |
*/
|
|
|
100 |
void *systemSpecific;
|
|
|
101 |
/*
|
|
|
102 |
* An array of function pointers, one per graphics system that
|
|
|
103 |
* has registered with the graphics engine.
|
|
|
104 |
*
|
|
|
105 |
* system_Callback is called when the graphics engine wants
|
|
|
106 |
* to give a graphics system the chance to play with its
|
|
|
107 |
* device-specific information (stored in systemSpecific)
|
|
|
108 |
* There are two parameters: an "event" to tell the graphics
|
|
|
109 |
* system why the graphics engine has called this function,
|
|
|
110 |
* and the systemSpecific pointer. The graphics engine
|
|
|
111 |
* has to pass the systemSpecific pointer because only
|
|
|
112 |
* the graphics engine will know what array index to use.
|
|
|
113 |
*/
|
|
|
114 |
GEcallback callback;
|
|
|
115 |
} GESystemDesc;
|
|
|
116 |
|
| 19966 |
duncan |
117 |
struct _GEDevDesc {
|
| 17204 |
hornik |
118 |
int newDevStruct;
|
|
|
119 |
NewDevDesc *dev;
|
|
|
120 |
/* Information about a device which has nothing to do with
|
|
|
121 |
* R's concept of a graphics engine.
|
|
|
122 |
*/
|
|
|
123 |
GESystemDesc *gesd[MAX_GRAPHICS_SYSTEMS];
|
| 19966 |
duncan |
124 |
};
|
| 17204 |
hornik |
125 |
|
| 27236 |
murrell |
126 |
/*
|
|
|
127 |
* A structure containing graphical parameters
|
|
|
128 |
*
|
|
|
129 |
* This is how graphical parameters are passed from graphics systems
|
|
|
130 |
* to the graphics engine AND from the graphics engine to graphics
|
|
|
131 |
* devices.
|
|
|
132 |
*
|
|
|
133 |
* Devices are not *required* to honour graphical parameters
|
|
|
134 |
* (e.g., alpha transparency is going to be tough for some)
|
|
|
135 |
*/
|
|
|
136 |
typedef struct {
|
|
|
137 |
/*
|
|
|
138 |
* Colours
|
|
|
139 |
*
|
|
|
140 |
* NOTE: Alpha transparency included in col & fill
|
|
|
141 |
*/
|
|
|
142 |
int col; /* pen colour (lines, text, borders, ...) */
|
|
|
143 |
int fill; /* fill colour (for polygons, circles, rects, ...) */
|
|
|
144 |
double gamma; /* Gamma correction */
|
|
|
145 |
/*
|
|
|
146 |
* Line characteristics
|
|
|
147 |
*/
|
|
|
148 |
double lwd; /* Line width (roughly number of pixels) */
|
|
|
149 |
int lty; /* Line type (solid, dashed, dotted, ...) */
|
|
|
150 |
/* FIXME: need to add line end/joins */
|
|
|
151 |
/*
|
|
|
152 |
* Text characteristics
|
|
|
153 |
*/
|
|
|
154 |
double cex; /* Character expansion (font size = fontsize*cex) */
|
|
|
155 |
double ps; /* Font size in points */
|
|
|
156 |
double lineheight; /* Line height (multiply by font size) */
|
|
|
157 |
int fontface; /* Font face (plain, italic, bold, ...) */
|
|
|
158 |
char fontfamily[50]; /* Font family */
|
|
|
159 |
} R_GE_gcontext;
|
|
|
160 |
|
| 17204 |
hornik |
161 |
GEDevDesc* GEcreateDevDesc(NewDevDesc* dev);
|
|
|
162 |
void GEdestroyDevDesc(GEDevDesc* dd);
|
|
|
163 |
void* GEsystemState(GEDevDesc *dd, int index);
|
|
|
164 |
void GEregisterWithDevice(GEDevDesc *dd);
|
| 17360 |
murrell |
165 |
void GEregisterSystem(GEcallback callback, int *systemRegisterIndex);
|
| 17204 |
hornik |
166 |
void GEunregisterSystem(int registerIndex);
|
|
|
167 |
|
|
|
168 |
SEXP GEHandleEvent(GEevent event, NewDevDesc *dev, SEXP data);
|
|
|
169 |
|
|
|
170 |
double fromDeviceX(double value, GEUnit to, GEDevDesc *dd);
|
|
|
171 |
double toDeviceX(double value, GEUnit from, GEDevDesc *dd);
|
|
|
172 |
double fromDeviceY(double value, GEUnit to, GEDevDesc *dd);
|
|
|
173 |
double toDeviceY(double value, GEUnit from, GEDevDesc *dd);
|
|
|
174 |
double fromDeviceWidth(double value, GEUnit to, GEDevDesc *dd);
|
|
|
175 |
double toDeviceWidth(double value, GEUnit from, GEDevDesc *dd);
|
|
|
176 |
double fromDeviceHeight(double value, GEUnit to, GEDevDesc *dd);
|
|
|
177 |
double toDeviceHeight(double value, GEUnit from, GEDevDesc *dd);
|
|
|
178 |
|
|
|
179 |
/*
|
|
|
180 |
* Some Notes on Line Textures
|
|
|
181 |
*
|
|
|
182 |
* Line textures are stored as an array of 4-bit integers within
|
|
|
183 |
* a single 32-bit word. These integers contain the lengths of
|
|
|
184 |
* lines to be drawn with the pen alternately down and then up.
|
|
|
185 |
* The device should try to arrange that these values are measured
|
|
|
186 |
* in points if possible, although pixels is ok on most displays.
|
|
|
187 |
*
|
|
|
188 |
* If newlty contains a line texture description it is decoded
|
|
|
189 |
* as follows:
|
|
|
190 |
*
|
|
|
191 |
* ndash = 0;
|
|
|
192 |
* for(i=0 ; i<8 && newlty & 15 ; i++) {
|
|
|
193 |
* dashlist[ndash++] = newlty & 15;
|
|
|
194 |
* newlty = newlty>>4;
|
|
|
195 |
* }
|
|
|
196 |
* dashlist[0] = length of pen-down segment
|
|
|
197 |
* dashlist[1] = length of pen-up segment
|
|
|
198 |
* etc
|
|
|
199 |
*
|
|
|
200 |
* An integer containing a zero terminates the pattern. Hence
|
|
|
201 |
* ndash in this code fragment gives the length of the texture
|
|
|
202 |
* description. If a description contains an odd number of
|
|
|
203 |
* elements it is replicated to create a pattern with an
|
|
|
204 |
* even number of elements. (If this is a pain, do something
|
|
|
205 |
* different its not crucial).
|
|
|
206 |
*
|
|
|
207 |
*/
|
|
|
208 |
|
|
|
209 |
/*--- The basic numbered & names line types; Here device-independent:
|
|
|
210 |
e.g. "dashed" == "44", "dotdash" == "1343"
|
|
|
211 |
*/
|
|
|
212 |
|
|
|
213 |
#define LTY_BLANK -1
|
|
|
214 |
#define LTY_SOLID 0
|
|
|
215 |
#define LTY_DASHED 4 + (4<<4)
|
|
|
216 |
#define LTY_DOTTED 1 + (3<<4)
|
|
|
217 |
#define LTY_DOTDASH 1 + (3<<4) + (4<<8) + (3<<12)
|
|
|
218 |
#define LTY_LONGDASH 7 + (3<<4)
|
|
|
219 |
#define LTY_TWODASH 2 + (2<<4) + (6<<8) + (2<<12)
|
|
|
220 |
|
|
|
221 |
void GESetClip(double x1, double y1, double x2, double y2, GEDevDesc *dd);
|
| 27236 |
murrell |
222 |
void GENewPage(R_GE_gcontext *gc, GEDevDesc *dd);
|
| 17204 |
hornik |
223 |
void GELine(double x1, double y1, double x2, double y2,
|
| 27236 |
murrell |
224 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 17204 |
hornik |
225 |
void GEPolyline(int n, double *x, double *y,
|
| 27236 |
murrell |
226 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 17204 |
hornik |
227 |
void GEPolygon(int n, double *x, double *y,
|
| 27236 |
murrell |
228 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 17204 |
hornik |
229 |
void GECircle(double x, double y, double radius,
|
| 27236 |
murrell |
230 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 17204 |
hornik |
231 |
void GERect(double x0, double y0, double x1, double y1,
|
| 27236 |
murrell |
232 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 17204 |
hornik |
233 |
void GEText(double x, double y, char *str,
|
| 21060 |
murrell |
234 |
double xc, double yc, double rot,
|
| 27236 |
murrell |
235 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 17204 |
hornik |
236 |
void GEMode(int mode, GEDevDesc* dd);
|
|
|
237 |
void GESymbol(double x, double y, int pch, double size,
|
| 27236 |
murrell |
238 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 17204 |
hornik |
239 |
void GEPretty(double *lo, double *up, int *ndiv);
|
| 27236 |
murrell |
240 |
void GEMetricInfo(int c, R_GE_gcontext *gc,
|
| 17204 |
hornik |
241 |
double *ascent, double *descent, double *width,
|
|
|
242 |
GEDevDesc *dd);
|
| 21060 |
murrell |
243 |
double GEStrWidth(char *str,
|
| 27236 |
murrell |
244 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 21060 |
murrell |
245 |
double GEStrHeight(char *str,
|
| 27236 |
murrell |
246 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 17204 |
hornik |
247 |
|
| 21060 |
murrell |
248 |
/*
|
|
|
249 |
* From plotmath.c
|
| 19875 |
murrell |
250 |
*/
|
|
|
251 |
double GEExpressionWidth(SEXP expr,
|
| 27236 |
murrell |
252 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 19875 |
murrell |
253 |
double GEExpressionHeight(SEXP expr,
|
| 27236 |
murrell |
254 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 19875 |
murrell |
255 |
void GEMathText(double x, double y, SEXP expr,
|
|
|
256 |
double xc, double yc, double rot,
|
| 27236 |
murrell |
257 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 21060 |
murrell |
258 |
/*
|
|
|
259 |
* (End from plotmath.c)
|
| 19875 |
murrell |
260 |
*/
|
|
|
261 |
|
| 21060 |
murrell |
262 |
/*
|
|
|
263 |
* From plot3d.c
|
|
|
264 |
*/
|
|
|
265 |
SEXP GEcontourLines(double *x, int nx, double *y, int ny,
|
|
|
266 |
double *z, double *levels, int nl,
|
|
|
267 |
GEDevDesc *dd);
|
|
|
268 |
/*
|
|
|
269 |
* (End from plot3d.c)
|
|
|
270 |
*/
|
|
|
271 |
|
|
|
272 |
/*
|
|
|
273 |
* From vfonts.c
|
|
|
274 |
*/
|
|
|
275 |
typedef void (*R_GE_VTextRoutine)(double x, double y, char *s,
|
| 27236 |
murrell |
276 |
double x_justify, double y_justify,
|
|
|
277 |
double rotation,
|
|
|
278 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 21060 |
murrell |
279 |
|
|
|
280 |
typedef double (*R_GE_VStrWidthRoutine)(const unsigned char *s,
|
| 27236 |
murrell |
281 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 21060 |
murrell |
282 |
|
|
|
283 |
typedef double (*R_GE_VStrHeightRoutine)(const unsigned char *s,
|
| 27236 |
murrell |
284 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 21060 |
murrell |
285 |
|
|
|
286 |
void R_GE_setVFontRoutines(R_GE_VStrWidthRoutine vwidth,
|
|
|
287 |
R_GE_VStrHeightRoutine vheight,
|
|
|
288 |
R_GE_VTextRoutine vtext);
|
|
|
289 |
|
| 27236 |
murrell |
290 |
double R_GE_VStrWidth(const unsigned char *s,
|
|
|
291 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 21060 |
murrell |
292 |
|
| 27236 |
murrell |
293 |
double R_GE_VStrHeight(const unsigned char *s,
|
|
|
294 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 21060 |
murrell |
295 |
|
|
|
296 |
void R_GE_VText(double x, double y, char *s,
|
|
|
297 |
double x_justify, double y_justify, double rotation,
|
| 27236 |
murrell |
298 |
R_GE_gcontext *gc, GEDevDesc *dd);
|
| 21060 |
murrell |
299 |
/*
|
|
|
300 |
* (End from vfonts.c)
|
|
|
301 |
*/
|
|
|
302 |
|
| 17204 |
hornik |
303 |
#define DEG2RAD 0.01745329251994329576
|
|
|
304 |
|
|
|
305 |
GEDevDesc* GEcurrentDevice();
|
|
|
306 |
void GEinitDisplayList(GEDevDesc *dd);
|
|
|
307 |
void GEplayDisplayList(GEDevDesc *dd);
|
|
|
308 |
void GEcopyDisplayList(int fromDevice);
|
|
|
309 |
SEXP GEcreateSnapshot(GEDevDesc *dd);
|
|
|
310 |
void GEplaySnapshot(SEXP snapshot, GEDevDesc* dd);
|