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