The R Project SVN R

Rev

Rev 19874 | Rev 31643 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19874 Rev 27236
Line 1... Line -...
1
/**************************
-
 
2
 * A first hack at a possible new device API
-
 
3
 **************************
-
 
4
 */
-
 
5
 
1
 
6
/* New device driver structure
2
/* New device driver structure
7
 * NOTES:
3
 * NOTES:
8
 * 1. All locations and dimensions are in device coordinates.
4
 * 1. All locations and dimensions are in device coordinates.
9
 * 2. I found this comment in the doc for dev_Open -- looks nasty
5
 * 2. I found this comment in the doc for dev_Open -- looks nasty
Line 23... Line 19...
23
 *    what dev_StrWidth would give if font metric information is
19
 *    what dev_StrWidth would give if font metric information is
24
 *    not available.  I guess having both allows the developer
20
 *    not available.  I guess having both allows the developer
25
 *    to decide when to ask for which sort of value, and to decide
21
 *    to decide when to ask for which sort of value, and to decide
26
 *    what to do when font metric information is not available.
22
 *    what to do when font metric information is not available.
27
 *    And why not a dev_StrHeight?
23
 *    And why not a dev_StrHeight?
28
 * 4. Replaced dev_Resize with dev_Size
-
 
29
 * 5. Do I make "cex" and "ps" part of the graphics engine or
-
 
30
 *    part of R base graphics?  If not part of the graphics engine,
-
 
31
 *    then how should the graphics engine specify text size?
-
 
32
 *    For now, they are part of the graphics engine.
-
 
33
 *    Similar comments apply for "font".
-
 
34
 * 6. Should "ipr", "asp", and "cra" be in the device description?
24
 * 4. Should "ipr", "asp", and "cra" be in the device description?
35
 *    If not, then where?
25
 *    If not, then where?
36
 *    I guess they don't need to be if no device makes use of them.
26
 *    I guess they don't need to be if no device makes use of them.
37
 *    On the other hand, they would need to be replaced by a device
27
 *    On the other hand, they would need to be replaced by a device
38
 *    call that R base graphics could use to get enough information
28
 *    call that R base graphics could use to get enough information
39
 *    to figure them out.  (e.g., some sort of dpi() function to
29
 *    to figure them out.  (e.g., some sort of dpi() function to
40
 *    complement the size() function.)
30
 *    complement the size() function.)
41
 * 7. Is dev_Dot used anywhere?
-
 
42
 */
31
 */
-
 
32
 
43
typedef struct {
33
typedef struct {
44
    /* The first element is a boolean indicating whether this is 
34
    /* The first element is a boolean indicating whether this is 
45
     * a new device driver (always 1) -- the old device driver structure
35
     * a new device driver (always 1) -- the old device driver structure
46
     * has had a similar element added (which will always be 0)
36
     * has had a similar element added (which will always be 0)
47
     *
37
     *
Line 119... Line 109...
119
				 * was last initialised
109
				 * was last initialised
120
				 */
110
				 */
121
    /********************************************************
111
    /********************************************************
122
     * Device procedures.
112
     * Device procedures.
123
     ********************************************************/
113
     ********************************************************/
-
 
114
 
-
 
115
    /*
-
 
116
     * ---------------------------------------
-
 
117
     * GENERAL COMMENT ON GRAPHICS PARAMETERS:
-
 
118
     * ---------------------------------------
-
 
119
     * Graphical parameters are now passed in a graphics context
-
 
120
     * structure (R_GE_gcontext*) rather than individually.
-
 
121
     * Each device action should extract the parameters it needs
-
 
122
     * and ignore the others.  Thought should be given to which 
-
 
123
     * parameters are relevant in each case -- the graphics engine
-
 
124
     * does not REQUIRE that each parameter is honoured, but if
-
 
125
     * a parameter is NOT honoured, it might be a good idea to
-
 
126
     * issue a warning when a parameter is not honoured (or at
-
 
127
     * the very least document which parameters are not honoured
-
 
128
     * in the user-level documentation for the device).  [An example
-
 
129
     * of a parameter that may not be honoured by many devices is
-
 
130
     * transparency.]
-
 
131
     */
-
 
132
 
124
    /*
133
    /*
125
     * device_Activate is called when a device becomes the	
134
     * device_Activate is called when a device becomes the	
126
     * active device.  For example, it can be used to change the
135
     * active device.  For example, it can be used to change the
127
     * title of a window to indicate the active status of	
136
     * title of a window to indicate the active status of	
128
     * the device to the user.  Not all device types will	
137
     * the device to the user.  Not all device types will	
Line 144... Line 153...
144
     * If "fill" is NA_INTEGER then the circle should not 
153
     * If "fill" is NA_INTEGER then the circle should not 
145
     * be filled.
154
     * be filled.
146
     * An example is ...
155
     * An example is ...
147
     *
156
     *
148
     * static void X11_Circle(double x, double y, double r,
157
     * static void X11_Circle(double x, double y, double r,
149
     *		              int col, int fill, double gamma,
-
 
150
     *                        int lty, double lwd,
158
     *                        R_GE_gcontext *gc,
151
     *                        NewDevDesc *dd);
159
     *                        NewDevDesc *dd);
152
     *
160
     *
-
 
161
     * R_GE_gcontext parameters that should be honoured (if possible):
-
 
162
     *   col, fill, gamma, lty, lwd
153
     */
163
     */
154
    void (*circle)();
164
    void (*circle)();
155
    /*
165
    /*
156
     * device_Clip is given the left, right, bottom, and	
166
     * device_Clip is given the left, right, bottom, and	
157
     * top of a rectangle (in DEVICE coordinates).	
167
     * top of a rectangle (in DEVICE coordinates).	
Line 216... Line 226...
216
     * device_Line should have the side-effect that a single
226
     * device_Line should have the side-effect that a single
217
     * line is drawn (from x1,y1 to x2,y2)			
227
     * line is drawn (from x1,y1 to x2,y2)			
218
     * An example is ...
228
     * An example is ...
219
     *
229
     *
220
     * static void X11_Line(double x1, double y1, double x2, double y2,
230
     * static void X11_Line(double x1, double y1, double x2, double y2,
221
     *		            int col, double gamma, int lty, double lwd,
231
     *                      R_GE_gcontext *gc,
222
     *                      NewDevDesc *dd);
232
     *                      NewDevDesc *dd);
223
     *
233
     *
-
 
234
     * R_GE_gcontext parameters that should be honoured (if possible):
-
 
235
     *   col, gamma, lty, lwd
224
     */
236
     */
225
    void (*line)();
237
    void (*line)();
226
    /*
238
    /*
227
     * device_MetricInfo should return height, depth, and	
239
     * device_MetricInfo should return height, depth, and	
228
     * width information for the given character in DEVICE	
240
     * width information for the given character in DEVICE	
Line 231... Line 243...
231
     * and for exact centering of text (see GText)		
243
     * and for exact centering of text (see GText)		
232
     * If the device cannot provide metric information then 
244
     * If the device cannot provide metric information then 
233
     * it MUST return 0.0 for ascent, descent, and width.
245
     * it MUST return 0.0 for ascent, descent, and width.
234
     * An example is ...
246
     * An example is ...
235
     *
247
     *
236
     * static void X11_MetricInfo(int c, int font, double cex, double ps,
248
     * static void X11_MetricInfo(int c,
-
 
249
     *                            R_GE_gcontext *gc,
237
     *                            double* ascent, double* descent,
250
     *                            double* ascent, double* descent,
238
     *                            double* width, NewDevDesc *dd);
251
     *                            double* width, NewDevDesc *dd);
-
 
252
     *
-
 
253
     * R_GE_gcontext parameters that should be honoured (if possible):
-
 
254
     *   font, cex, ps
239
     */
255
     */
240
    void (*metricInfo)();
256
    void (*metricInfo)();
241
    /*
257
    /*
242
     * device_Mode is called whenever the graphics engine	
258
     * device_Mode is called whenever the graphics engine	
243
     * starts drawing (mode=1) or stops drawing (mode=0)	
259
     * starts drawing (mode=1) or stops drawing (mode=0)	
Line 255... Line 271...
255
     * device (e.g., X11) or moving to a new page	
271
     * device (e.g., X11) or moving to a new page	
256
     * (e.g., postscript)					
272
     * (e.g., postscript)					
257
     * An example is ...
273
     * An example is ...
258
     *
274
     *
259
     *
275
     *
260
     * static void X11_NewPage(int fill, double gamma, NewDevDesc *dd);
276
     * static void X11_NewPage(R_GE_gcontext *gc,
-
 
277
     *                         NewDevDesc *dd);
261
     *
278
     *
262
     */
279
     */
263
    void (*newPage)();
280
    void (*newPage)();
264
    /*
281
    /*
265
     * device_Open is not usually called directly by the	
282
     * device_Open is not usually called directly by the	
Line 287... Line 304...
287
     * If "col" is NA_INTEGER don't draw the border		
304
     * If "col" is NA_INTEGER don't draw the border		
288
     * If "fill" is NA_INTEGER don't fill the polygon		
305
     * If "fill" is NA_INTEGER don't fill the polygon		
289
     * An example is ...
306
     * An example is ...
290
     *
307
     *
291
     * static void X11_Polygon(int n, double *x, double *y, 
308
     * static void X11_Polygon(int n, double *x, double *y, 
292
     *		               int col, int fill, double gamma,
-
 
293
     *                         int lty, double lwd,
309
     *                         R_GE_gcontext *gc,
294
     *                         NewDevDesc *dd);
310
     *                         NewDevDesc *dd);
295
     *
311
     *
-
 
312
     * R_GE_gcontext parameters that should be honoured (if possible):
-
 
313
     *   col, fill, gamma, lty, lwd
296
     */
314
     */
297
    void (*polygon)();
315
    void (*polygon)();
298
    /*
316
    /*
299
     * device_Polyline should have the side-effect that a	
317
     * device_Polyline should have the side-effect that a	
300
     * series of line segments are drawn using the given x	
318
     * series of line segments are drawn using the given x	
301
     * and y values.
319
     * and y values.
302
     * An example is ...
320
     * An example is ...
303
     *
321
     *
304
     * static void X11_Polyline(int n, double *x, double *y, 
322
     * static void X11_Polyline(int n, double *x, double *y, 
305
     *		               int col, double gamma,
-
 
306
     *                         int lty, double lwd,
323
     *                          R_GE_gcontext *gc,
307
     *                          NewDevDesc *dd);
324
     *                          NewDevDesc *dd);
308
     *
325
     *
-
 
326
     * R_GE_gcontext parameters that should be honoured (if possible):
-
 
327
     *   col, gamma, lty, lwd
309
     */
328
     */
310
    void (*polyline)();
329
    void (*polyline)();
311
    /*
330
    /*
312
     * device_Rect should have the side-effect that a	
331
     * device_Rect should have the side-effect that a	
313
     * rectangle is drawn with the given locations for its	
332
     * rectangle is drawn with the given locations for its	
Line 318... Line 337...
318
     * If "fill" is NA_INTEGER then the rectangle should not	
337
     * If "fill" is NA_INTEGER then the rectangle should not	
319
     * be filled.						
338
     * be filled.						
320
     * An example is ...
339
     * An example is ...
321
     *
340
     *
322
     * static void X11_Rect(double x0, double y0, double x1, double y1,
341
     * static void X11_Rect(double x0, double y0, double x1, double y1,
323
     *		            int col, int fill, double gamma,
-
 
324
     *                      int lty, double lwd,
342
     *                      R_GE_gcontext *gc,
325
     *                      NewDevDesc *dd);
343
     *                      NewDevDesc *dd);
326
     *
344
     *
327
     */
345
     */
328
    void (*rect)();
346
    void (*rect)();
329
    /*
347
    /*
Line 339... Line 357...
339
     *
357
     *
340
     * static void X11_Size(double *left, double *right,
358
     * static void X11_Size(double *left, double *right,
341
     *                      double *bottom, double *top,
359
     *                      double *bottom, double *top,
342
     *                      NewDevDesc *dd);
360
     *                      NewDevDesc *dd);
343
     *
361
     *
-
 
362
     * R_GE_gcontext parameters that should be honoured (if possible):
-
 
363
     *   col, fill, gamma, lty, lwd
344
     */
364
     */
345
    void (*size)();
365
    void (*size)();
346
    /*
366
    /*
347
     * device_StrWidth should return the width of the given 
367
     * device_StrWidth should return the width of the given 
348
     * string in DEVICE units.				
368
     * string in DEVICE units.				
349
     * An example is ...
369
     * An example is ...
350
     *
370
     *
351
     * static double X11_StrWidth(char *str, int font, double cex, double ps,
371
     * static double X11_StrWidth(char *str, 
-
 
372
     *                            R_GE_gcontext *gc,
352
     *                            NewDevDesc *dd)
373
     *                            NewDevDesc *dd)
353
     *
374
     *
-
 
375
     * R_GE_gcontext parameters that should be honoured (if possible):
-
 
376
     *   font, cex, ps
354
     */
377
     */
355
    double (*strWidth)();
378
    double (*strWidth)();
356
    /*
379
    /*
357
     * device_Text should have the side-effect that the	
380
     * device_Text should have the side-effect that the	
358
     * given text is drawn at the given location.
381
     * given text is drawn at the given location.
359
     * The text should be rotated according to rot (degrees)
382
     * The text should be rotated according to rot (degrees)
360
     * An example is ...
383
     * An example is ...
361
     *
384
     *
362
     * static void X11_Text(double x, double y, char *str, 
385
     * static void X11_Text(double x, double y, char *str, 
363
     *                      double rot, double hadj, 
386
     *                      double rot, double hadj, 
364
     *		            int col, double gamma,
-
 
365
     *                      int font, double cex, double ps,
387
     *                      R_GE_gcontext *gc,
366
     * 	                    NewDevDesc *dd);
388
     * 	                    NewDevDesc *dd);
367
     *
389
     *
-
 
390
     * R_GE_gcontext parameters that should be honoured (if possible):
-
 
391
     *   font, cex, ps, col, gamma
368
     */
392
     */
369
    void (*text)();
393
    void (*text)();
370
} NewDevDesc;
394
} NewDevDesc;
371
 
395
 
372
	/********************************************************/
396
	/********************************************************/