The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 r 1
/*
990 maechler 2
 *  R : A Computer Language for Statistical Data Analysis
2 r 3
 *  Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
4562 pd 4
 *  Copyright (C) 1998--1999  R Development Core Team
2 r 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
5458 ripley 18
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2 r 19
 */
20
 
21
#ifndef GRAPHICS_H_
22
#define GRAPHICS_H_
23
 
258 paul 24
#include "Defn.h"
2 r 25
 
26
#ifndef NA_REAL
27
#define NA_REAL R_NaReal
28
#endif
29
 
30
#ifndef NA_INTEGER
31
#define NA_INTEGER R_NaInt
32
#endif
33
 
34
#include <math.h>
35
 
36
#ifdef Windows
2428 maechler 37
#include <windows.h>
2 r 38
#endif
39
 
40
#include <float.h>
41
#include <stdlib.h>
42
#include <stdio.h>
43
 
44
/*
45
 *	Some Notes on Color
46
 *
47
 *	R uses a 24-bit color model.  Colors are specified in 32-bit
48
 *	integers which are partitioned into 4 bytes as follows.
49
 *
2566 maechler 50
 *		<-- most sig	    least sig -->
2 r 51
 *		+-------------------------------+
2566 maechler 52
 *		|   0	| blue	| green |  red	|
2 r 53
 *		+-------------------------------+
54
 *
55
 *	The red, green and blue bytes can be extracted as follows.
56
 *
2566 maechler 57
 *		red   = ((color	     ) & 255)
2 r 58
 *		green = ((color >>  8) & 255)
59
 *		blue  = ((color >> 16) & 255)
60
 */
61
#define R_RGB(r,g,b)	((r)|((g)<<8)|((b)<<16))
2566 maechler 62
#define R_RED(col)	(((col)	   )&255)
2 r 63
#define R_GREEN(col)	(((col)>> 8)&255)
64
#define R_BLUE(col)	(((col)>>16)&255)
581 paul 65
#define COLOR_TABLE_SIZE 256
2 r 66
 
6098 pd 67
/*
68
 *	Some Notes on Line Textures
69
 *
70
 *	Line textures are stored as an array of 4-bit integers within
71
 *	a single 32-bit word.  These integers contain the lengths of
72
 *	lines to be drawn with the pen alternately down and then up.
73
 *	The device should try to arrange that these values are measured
74
 *	in points if possible, although pixels is ok on most displays.
75
 *
76
 *	If newlty contains a line texture description it is decoded
77
 *	as follows:
78
 *
79
 *		ndash = 0;
80
 *		for(i=0 ; i<8 && newlty & 15 ; i++) {
81
 *			dashlist[ndash++] = newlty & 15;
82
 *			newlty = newlty>>4;
83
 *		}
84
 *		dashlist[0] = length of pen-down segment
85
 *		dashlist[1] = length of pen-up segment
86
 *		etc
87
 *
88
 *	An integer containing a zero terminates the pattern.  Hence
89
 *	ndash in this code fragment gives the length of the texture
90
 *	description.  If a description contains an odd number of
91
 *	elements it is replicated to create a pattern with an
92
 *	even number of elements.  (If this is a pain, do something
93
 *	different its not crucial).
94
 *
95
 */
3979 ripley 96
 
6098 pd 97
/*--- The basic numbered & names line types; Here device-independent:
98
  e.g. "dashed" == "44",  "dotdash" == "1343"
99
*/
6418 maechler 100
 
6177 pd 101
#define LTY_BLANK	-1
3244 ihaka 102
#define LTY_SOLID	0
103
#define LTY_DASHED	4 + (4<<4)
104
#define LTY_DOTTED	1 + (3<<4)
105
#define LTY_DOTDASH	1 + (3<<4) + (4<<8) + (3<<12)
6098 pd 106
#define LTY_LONGDASH	7 + (3<<4)
107
#define LTY_TWODASH	2 + (2<<4) + (6<<8) + (2<<12)
3244 ihaka 108
 
581 paul 109
#define MAX_LAYOUT_ROWS 15
110
#define MAX_LAYOUT_COLS 15
111
 
112
	/* possible coordinate systems (for specifying locations) */
113
 
114
#define DEVICE	0	/* native device coordinates (rasters) */
115
#define NDC	1	/* normalised device coordinates x=(0,1), y=(0,1) */
2566 maechler 116
#define INCHES 13	/* inches x=(0,width), y=(0,height) */
581 paul 117
#define NIC	6	/* normalised inner region coordinates (0,1) */
118
#define OMA1	2	/* outer margin 1 (bottom) x=NIC, y=LINES */
119
#define OMA2	3	/* outer margin 2 (left) */
120
#define OMA3	4	/* outer margin 3 (top) */
121
#define OMA4	5	/* outer margin 4 (right) */
122
#define NFC	7	/* normalised figure region coordinates (0,1) */
2566 maechler 123
#define NPC	16	/* normalised plot region coordinates (0,1) */
581 paul 124
#define USER	12	/* user/data/world corrdinates */
125
			/* x=(xmin,xmax), y=(ymin,ymax) */
126
#define MAR1	8	/* figure margin 1 (bottom) x=USER(x), y=LINES */
127
#define MAR2	9	/* figure margin 2 (left) x=USER(y) y=LINES */
128
#define MAR3	10	/* figure margin 3 (top) x=USER(x), y=LINES */
129
#define MAR4	11	/* figure margin 4 (right) x=USER(y) y=LINES */
130
 
131
	/* possible units (for specifying dimensions) */
132
	/* all of the above, plus ... */
133
 
134
#define LINES 14	/* multiples of a line in the margin (mex) */
135
#define CHARS 15	/* multiples of text height (cex) */
136
 
137
#define R_MaxDevices 64
138
 
6098 pd 139
#define	DEG2RAD 0.01745329251994329576
140
 
2 r 141
typedef unsigned int rcolor;
142
 
143
typedef struct {
144
	double ax;
145
	double bx;
146
	double ay;
147
	double by;
148
} GTrans;
149
 
581 paul 150
struct colorDataBaseEntry {
2566 maechler 151
	char *name;	/* X11 Color Name */
152
	char *rgb;	/* #RRGGBB String */
2505 maechler 153
	unsigned int code;  /* Internal R Color Code */
581 paul 154
};
155
 
990 maechler 156
typedef struct colorDataBaseEntry ColorDataBaseEntry;
581 paul 157
 
3244 ihaka 158
extern int R_ColorTableSize;
159
extern unsigned int R_ColorTable[];
581 paul 160
extern ColorDataBaseEntry ColorDataBase[];
161
extern char *DefaultPalette[];
162
 
2 r 163
/* Graphics State:
164
 *
165
 * The following structure defines state for a graphics device driver.
166
 * Two copies are kept; the ``default'' set of values, and a set which
167
 * can be modified during calls to an application program.  When a
168
 * new graphics frame is started, the values revert to the defaults
581 paul 169
 *
2 r 170
 */
171
 
172
typedef struct {
4022 r 173
    /* Basic Device Driver Properties */
174
    /* These MUST be set by device drivers on open */
2 r 175
 
4022 r 176
    /* These parameters cannot be set by the user */
177
    /* although left, right, bottom, and top can be */
178
    /* interrogated indirectly (i.e., par("din")) */
179
    /* and cra can be interrogated directly (i.e., par("cra")) */
581 paul 180
 
4022 r 181
    double left;	/* left raster coordinate */
182
    double right;	/* right raster coordinate */
183
    double bottom;	/* bottom raster coordinate */
184
    double top;		/* top raster coordinate */
185
    double xCharOffset;	/* x character addressing offset */
186
    double yCharOffset;	/* y character addressing offset */
187
    double yLineBias;	/* 1/2 interline space as fraction of line height */
188
    int canResizePlot;	/* can the graphics surface be resized */
189
    int canChangeFont;	/* device has multiple fonts */
190
    int canRotateText;	/* text can be rotated */
191
    int canResizeText;	/* text can be resized */
192
    int canClip;	/* Hardware clipping */
2 r 193
 
4022 r 194
    /* a couple of the GRZ-like parameters that have to be */
195
    /* set by the device */
581 paul 196
 
4022 r 197
    double ipr[2];	/* Inches per raster; [0]=x, [1]=y */
198
    double asp;		/* Pixel aspect ratio = ipr[1]/ipr[0] */
199
    double cra[2];	/* Character size in rasters; [0]=x, [1]=y */
581 paul 200
 
4022 r 201
    /* Plot State */
202
    /* When the device driver is started this is 0 */
203
    /* After the first call to plot.new it is 1 */
204
    /* Every graphics operation except plot.new */
205
    /* should fail if state = 0 */
206
    /* This is checked at the highest internal function */
207
    /* level (e.g., do_lines, do_axis, do_plot_xy, ...) */
2 r 208
 
4022 r 209
    int	state;		/* Plot State */
210
    int	valid;		/* valid layout ? */
2 r 211
 
4022 r 212
    /* GRZ-like Graphics Parameters */
213
    /* ``The horror, the horror ... '' */
214
    /* Marlon Brando - Appocalypse Now */
2 r 215
 
4022 r 216
    /* General Parameters -- set and interrogated directly */
2 r 217
 
4022 r 218
    double adj;		/* String adjustment */
219
    int	ann;		/* Should annotation take place */
220
    int	ask;		/* User confirmation of ``page eject'' */
221
    rcolor bg;		/* **R ONLY** Background color */
222
    int	bty;		/* Box type */
223
    double cex;		/* Character expansion */
224
    rcolor col;		/* Plotting Color */
225
    double crt;		/* Character/string rotation */
226
    double din[2];	/* device size in inches */
227
    int	err;		/* Error repporting level */
228
    rcolor fg;		/* **R ONLY** Foreground Color */
229
    int	font;		/* Text font */
230
    double gamma;	/* Device Gamma Correction */
231
    int	lab[3];		/* Axis labelling */
232
			/* [0] = # ticks on x-axis */
233
			/* [1] = # ticks on y-axis */
234
			/* [2] = length of axis labels */
235
    int	las;		/* Label style (rotation) */
236
    int	lty;		/* Line texture */
237
    double lwd;		/* Line width */
238
    double mgp[3];	/* Annotation location */
239
			/* [0] = location of axis title */
240
			/* [1] = location of axis label */
241
			/* [2] = location of axis line */
242
    double mkh;		/* Mark size in inches */
243
    int	pch;		/* Plotting character */
244
    int	ps;		/* Text & symbol pointsize */
245
    int	smo;		/* Curve smoothness */
246
    double srt;		/* String Rotation */
247
    double tck;		/* Tick size as in S */
248
    double tcl;		/* Tick size in "lines" */
249
    double tmag;	/* **R ONLY** Title Magnification */
250
    int	type;		/* type of plot desired */
251
    double xaxp[3];	/* X Axis annotation */
252
			/* [0] = coordinate of lower tick */
253
			/* [1] = coordinate of upper tick */
254
			/* [2] = num tick intervals */
255
			/* almost always used internally */
256
    int	xaxs;		/* X Axis style */
257
    int	xaxt;		/* X Axis type */
258
    int	xpd;		/* Clip to plot region indicator */
259
    int	oldxpd;
260
    double yaxp[3];	/* Y Axis annotation */
261
    int	yaxs;		/* Y Axis style */
262
    int	yaxt;		/* Y Axis type */
263
    int	xlog;		/* Log Axis for X */
264
    int	ylog;		/* Log Axis for Y */
1255 maechler 265
 
4022 r 266
    /* Annotation Parameters */
2 r 267
 
4022 r 268
    float cexbase;	/* Base character size */
269
    float cexmain;	/* Main title size */
270
    float cexlab;	/* xlab and ylab size */
271
    float cexsub;	/* Sub title size */
272
    float cexaxis;	/* Axis label size */
2 r 273
 
4022 r 274
    int	fontmain;	/* Main title font */
275
    int	fontlab;	/* Xlab and ylab font */
276
    int	fontsub;	/* Subtitle font */
277
    int	fontaxis;	/* Axis label fonts */
2 r 278
 
4022 r 279
    int	colmain;	/* Main title color */
280
    int	collab;		/* Xlab and ylab color */
281
    int	colsub;		/* Subtitle color */
282
    int	colaxis;	/* Axis label color */
2 r 283
 
4022 r 284
    /* Layout Parameters */
2 r 285
 
4022 r 286
    int	layout;		/* has a layout been specified */
2 r 287
 
4022 r 288
    int	numrows;
289
    int	numcols;
290
    int	currentFigure;
291
    int	lastFigure;
292
    double heights[MAX_LAYOUT_ROWS];
293
    double widths[MAX_LAYOUT_COLS];
294
    int	cmHeights[MAX_LAYOUT_ROWS];
295
    int	cmWidths[MAX_LAYOUT_COLS];
296
    int	order[MAX_LAYOUT_ROWS][MAX_LAYOUT_COLS];
297
    int	rspct;	        /* 0 = none, 1 = full, 2 = see respect */
298
    int	respect[MAX_LAYOUT_ROWS][MAX_LAYOUT_COLS];
671 paul 299
 
4022 r 300
    int	mfind;		/* By row/col indicator */
581 paul 301
 
4022 r 302
    /* Layout parameters which can be set directly by the */
303
    /* user (e.g., par(fig=c(.5,1,0,1))) or otherwise are */
304
    /* calculated automatically */
305
    /* NOTE that *Units parameters are for internal use only */
581 paul 306
 
4022 r 307
    double fig[4];	/* (current) Figure size (proportion) */
308
			/* [0] = left, [1] = right */
309
			/* [2] = bottom, [3] = top */
310
    double fin[2];	/* (current) Figure size (inches) */
311
			/* [0] = width, [1] = height */
312
    int	fUnits;		/* (current) figure size units */
313
    int	defaultFigure;	/* calculate figure from layout ? */
314
    double plt[4];	/* (current) Plot size (proportions) */
315
			/* [0] = left, [1] = right */
316
			/* [2] = bottom, [3] = top */
317
    double pin[2];	/* (current) plot size (inches) */
318
			/* [0] = width, [1] = height */
319
    int	pUnits;		/* (current) plot size units */
320
    int	defaultPlot;	/* calculate plot from figure - margins ? */
581 paul 321
 
4022 r 322
    /* Layout parameters which are set directly by the user */
581 paul 323
 
4022 r 324
    double mar[4];	/* Plot margins in lines */
325
    double mai[4];	/* Plot margins in inches */
326
			/* [0] = bottom, [1] = left */
327
			/* [2] = top, [3] = right */
328
    int	mUnits;		/* plot margin units */
329
    double mex;		/* Margin expansion factor */
330
    double oma[4];	/* Outer margins in lines */
331
    double omi[4];	/* outer margins in inches */
332
    double omd[4];	/* outer margins in NDC */
333
			/* [0] = bottom, [1] = left */
334
			/* [2] = top, [3] = right */
335
    int	oUnits;		/* outer margin units */
336
    int	pty;		/* Plot type */
581 paul 337
 
4022 r 338
    /* Layout parameters which can be set by the user, but */
339
    /* almost always get automatically calculated anyway */
581 paul 340
 
4022 r 341
    double usr[4];	/* Graphics window */
342
			/* [0] = xmin, [1] = xmax */
343
			/* [2] = ymin, [3] = ymax */
581 paul 344
 
4022 r 345
    /* The logged usr parameter;  if xlog, use logusr[0:1] */
346
    /* if ylog, use logusr[2:3] */
990 maechler 347
 
4022 r 348
    double logusr[4];
2 r 349
 
4022 r 350
    /* Layout parameter: Internal flags */
2 r 351
 
4022 r 352
    int	new;		/* Clean plot ? */
353
    int	devmode;	/* creating new image or adding to existing one */
2 r 354
 
4022 r 355
    /* Coordinate System Mappings */
356
    /* These are only used internally (i.e., cannot be */
357
    /* set directly by the user) */
2 r 358
 
4022 r 359
    /* The reliability of these parameters relies on */
360
    /* the fact that plot.new is the */
361
    /* first graphics operation called in the creation */
362
    /* of a graph */
581 paul 363
 
4022 r 364
    /* udpated per plot.new */
581 paul 365
 
4022 r 366
    double xNDCPerChar;	/* Nominal character width (NDC) */
367
    double yNDCPerChar;	/* Nominal character height (NDC) */
368
    double xNDCPerLine;	/* Nominal line width (NDC) */
369
    double yNDCPerLine;	/* Nominal line height (NDC) */
370
    double xNDCPerInch;	/* xNDC -> Inches */
371
    double yNDCPerInch;	/* yNDC -> Inches */
581 paul 372
 
4022 r 373
    /* updated per plot.new and if inner2dev changes */
581 paul 374
 
4022 r 375
    GTrans fig2dev;	/* Figure to device */
581 paul 376
 
4022 r 377
    /* udpated per DevNewPlot and if ndc2dev changes */
581 paul 378
 
4022 r 379
    GTrans inner2dev;	/* Inner region to device */
581 paul 380
 
4022 r 381
    /* udpated per device resize */
581 paul 382
 
4022 r 383
    GTrans ndc2dev;	/* NDC to raw device */
990 maechler 384
 
4022 r 385
    /* updated per plot.new and per plot.window */
2 r 386
 
4022 r 387
    GTrans win2fig;	/* Window to figure mapping */
581 paul 388
 
4022 r 389
    /* NOTE: if user has not set fig and/or plt then */
390
    /* they need to be updated per plot.new too */
581 paul 391
 
4022 r 392
    /* device operations */
393
    int (*open)();
394
    void (*close)();
395
    void (*activate)();
396
    void (*deactivate)();
397
    void (*resize)();
398
    void (*newPage)();
399
    void (*clip)();
400
    double (*strWidth)();
401
    void (*line)();
402
    void (*polyline)();
403
    void (*text)();
404
    void (*dot)();
405
    void (*rect)();
406
    void (*circle)();
407
    void (*polygon)();
408
    int (*locator)();
409
    void (*mode)();
410
    void (*hold)();
411
    void (*metricInfo)();
2 r 412
} GPar;
413
 
581 paul 414
typedef struct {
2566 maechler 415
	GPar dp;		/* current device default parameters */
581 paul 416
	GPar gp;		/* current device current parameters */
2566 maechler 417
	GPar dpSaved;		/* saved device default parameters */
418
	void *deviceSpecific;	/* pointer to device specific parameters */
419
	int displayListOn;	/* toggle for display list status */
420
	SEXP displayList;	/* display list */
581 paul 421
} DevDesc;
422
 
6098 pd 423
		/* Drivers from ../main/dev....c , description there: */
2540 maechler 424
 
425
int PSDeviceDriver(DevDesc*, char*, char*, char*,
6098 pd 426
		   char*, char*, double, double, double, double, int, int);
2540 maechler 427
 
428
int PicTeXDeviceDriver(DevDesc*, char*, char*, char*, double, double, int);
429
 
2566 maechler 430
/*ifdef Unix : ../unix/devX11.h	 only in few places*/
431
 
432
#ifdef Win32
433
int WinDeviceDriver(char**, int, double*, int);
434
#endif
435
 
3244 ihaka 436
#ifdef OLD_Macintosh
2566 maechler 437
int MacDeviceDriver(char**, int, double*, int);
438
#endif
439
 
440
 
7758 ripley 441
#ifndef R_NO_REMAP
7751 ripley 442
#define addDevice		Rf_addDevice
443
#define char2col		Rf_char2col
444
#define col2name		Rf_col2name
445
#define copyDisplayList		Rf_copyDisplayList
7824 ripley 446
#define copyGPar		Rf_copyGPar
447
#define CreateAtVector		Rf_CreateAtVector
7751 ripley 448
#define curDevice		Rf_curDevice
449
#define CurrentDevice		Rf_CurrentDevice
450
#define currentFigureLocation	Rf_currentFigureLocation
451
#define deviceNumber		Rf_deviceNumber
452
#define DevNull			Rf_DevNull
453
#define FixupCex		Rf_FixupCex
454
#define FixupCol		Rf_FixupCol
455
#define FixupFont		Rf_FixupFont
456
#define FixupLty		Rf_FixupLty
457
#define FixupLwd		Rf_FixupLwd
458
#define FixupPch		Rf_FixupPch
7824 ripley 459
#define FixupVFont		Rf_FixupVFont
7751 ripley 460
#define GArrow			Rf_GArrow
461
#define GBox			Rf_GBox
462
#define GCheckState		Rf_GCheckState
463
#define GCircle			Rf_GCircle
464
#define GClip			Rf_GClip
465
#define GClipPolygon		Rf_GClipPolygon
466
#define GConvert		Rf_GConvert
467
#define GConvertX		Rf_GConvertX
468
#define GConvertXUnits		Rf_GConvertXUnits
469
#define GConvertY		Rf_GConvertY
470
#define GConvertYUnits		Rf_GConvertYUnits
471
#define GEndPath		Rf_GEndPath
7824 ripley 472
#define GetAxisLimits		Rf_GetAxisLimits
7751 ripley 473
#define GetDevice		Rf_GetDevice
474
#define GExpressionHeight	Rf_GExpressionHeight
475
#define GExpressionWidth	Rf_GExpressionWidth
476
#define GForceClip		Rf_GForceClip
477
#define GInit			Rf_GInit
478
#define GLine			Rf_GLine
479
#define GLocator		Rf_GLocator
480
#define GLPretty		Rf_GLPretty
481
#define GMapUnits		Rf_GMapUnits
482
#define GMapWin2Fig		Rf_GMapWin2Fig
483
#define GMathText		Rf_GMathText
484
#define GMetricInfo		Rf_GMetricInfo
485
#define GMMathText		Rf_GMMathText
486
#define GMode			Rf_GMode
487
#define GMtext			Rf_GMtext
488
#define GNewPlot		Rf_GNewPlot
489
#define GPolygon		Rf_GPolygon
490
#define GPolyline		Rf_GPolyline
491
#define GPretty			Rf_GPretty
492
#define GRect			Rf_GRect
493
#define GReset			Rf_GReset
494
#define GRestore		Rf_GRestore
495
#define GRestorePars		Rf_GRestorePars
496
#define GSavePars		Rf_GSavePars
497
#define GScale			Rf_GScale
498
#define GSetState		Rf_GSetState
499
#define GSetupAxis		Rf_GSetupAxis
500
#define GStartPath		Rf_GStartPath
501
#define GStrHeight		Rf_GStrHeight
502
#define GStrWidth		Rf_GStrWidth
503
#define GSymbol			Rf_GSymbol
504
#define GText			Rf_GText
7824 ripley 505
#define GVStrHeight		Rf_GVStrHeight
506
#define GVStrWidth		Rf_GVStrWidth
507
#define GVText			Rf_GVText
7751 ripley 508
#define inhibitDisplayList	Rf_inhibitDisplayList
509
#define initDisplayList		Rf_initDisplayList
510
#define InitGraphics		Rf_InitGraphics
511
#define KillAllDevices		Rf_KillAllDevices
7824 ripley 512
#define KillDevice		Rf_KillDevice
7761 ripley 513
#define killDevice		Rf_killDevice
7824 ripley 514
#define labelformat		Rf_labelformat
7751 ripley 515
#define LTYget			Rf_LTYget
516
#define LTYpar			Rf_LTYpar
517
#define name2col		Rf_name2col
518
#define NewFrameConfirm		Rf_NewFrameConfirm
519
#define nextDevice		Rf_nextDevice
520
#define NoDevices		Rf_NoDevices
521
#define NumDevices		Rf_NumDevices
522
#define playDisplayList		Rf_playDisplayList
523
#define prevDevice		Rf_prevDevice
524
#define ProcessInlinePars	Rf_ProcessInlinePars
525
#define recordGraphicOperation	Rf_recordGraphicOperation
526
#define rgb2col			Rf_rgb2col
527
#define RGB2rgb			Rf_RGB2rgb
528
#define RGBpar			Rf_RGBpar
529
#define ScaleColor		Rf_ScaleColor
530
#define selectDevice		Rf_selectDevice
531
#define Specify2		Rf_Specify2
532
#define StartDevice		Rf_StartDevice
533
#define str2col			Rf_str2col
534
#define StrMatch		Rf_StrMatch
535
#define xDevtoNDC		Rf_xDevtoNDC
536
#define xDevtoNFC		Rf_xDevtoNFC
537
#define xNPCtoUsr		Rf_xNPCtoUsr
538
#define yDevtoNDC		Rf_yDevtoNDC
539
#define yDevtoNFC		Rf_yDevtoNFC
540
#define yNPCtoUsr		Rf_yNPCtoUsr
541
#endif
542
 
581 paul 543
		/* User Callable Functions */
2 r 544
 
2505 maechler 545
/*-------------------------------------------------------------------
546
 *
547
 *  DEVICE FUNCTIONS are concerned with the creation and destruction
548
 *  of devices.
549
 *
550
 */
2 r 551
 
2505 maechler 552
/* Return a pointer to the current device. */
581 paul 553
DevDesc* CurrentDevice();
2505 maechler 554
/* Return a pointer to a device which is identified by number */
581 paul 555
DevDesc* GetDevice(int);
2505 maechler 556
/* Initialise internal device structures. */
990 maechler 557
void InitGraphics(void);
2505 maechler 558
/* Kill device which is identified by number. */
604 paul 559
void KillDevice(DevDesc*);
2505 maechler 560
/* Kill all active devices (used at shutdown). */
581 paul 561
void KillAllDevices();
2505 maechler 562
/* Is the null device the current device? */
581 paul 563
int NoDevices();
2505 maechler 564
/* How many devices exist ? (>= 1) */
581 paul 565
int NumDevices();
2505 maechler 566
/* Get the index of the specified device. */
990 maechler 567
int deviceNumber(DevDesc*);
2505 maechler 568
/* Create a new device. */
581 paul 569
int StartDevice(SEXP, SEXP, int, SEXP, int);
2505 maechler 570
 
571
void DevNull(void);
572
 
3279 pd 573
/* Miscellaneous */
574
void NewFrameConfirm();
990 maechler 575
void recordGraphicOperation(SEXP, SEXP, DevDesc*);
1016 maechler 576
void initDisplayList();
990 maechler 577
void copyDisplayList(int);
578
void playDisplayList(DevDesc*);
579
void inhibitDisplayList(DevDesc*);
2 r 580
 
2505 maechler 581
/*-------------------------------------------------------------------
582
 *
583
 *  DEVICE UTILITIES are concerned with providing information
584
 *  for R interpreted functions.
585
 *
586
 */
2 r 587
 
2505 maechler 588
/* Return the number of the current device. */
581 paul 589
int curDevice();
2505 maechler 590
/* Return the number of the next device. */
581 paul 591
int nextDevice(int);
2505 maechler 592
/* Return the number of the previous device. */
581 paul 593
int prevDevice(int);
2505 maechler 594
/* Make the specified device (specified by number) the current device */
581 paul 595
int selectDevice(int);
2505 maechler 596
/* Kill device which is identified by number. */
604 paul 597
void killDevice(int);
2505 maechler 598
/* ...NO DOC... */
599
void addDevice(DevDesc *);
2 r 600
 
601
 
2505 maechler 602
/*-------------------------------------------------------------------
603
 *
604
 *  GPAR FUNCTIONS are concerned with operations on the
605
 *  entire set of graphics parameters for a device
606
 *  (e.g., initialisation, saving, and restoring)
607
 */
608
 
609
/* Default the settings for general graphical parameters
610
 * (i.e., defaults that do not depend on the device type: */
581 paul 611
void GInit(GPar*);
2505 maechler 612
/* Reset the current graphical parameters from the default ones: */
581 paul 613
void GRestore(DevDesc*);
2505 maechler 614
/* Make a temporary copy of the current parameters */
581 paul 615
void GSavePars(DevDesc*);
2505 maechler 616
/* Restore the temporary copy saved by GSavePars */
581 paul 617
void GRestorePars(DevDesc*);
2505 maechler 618
 
619
		/* More Programmer GPar functions */
620
 
2342 maechler 621
void ProcessInlinePars(SEXP, DevDesc*);
2690 maechler 622
void Specify2(char*, SEXP, DevDesc*);
8285 pd 623
void RecordGraphicsCall(SEXP);
2 r 624
 
5507 ihaka 625
SEXP FixupPch(SEXP, int);
626
SEXP FixupLty(SEXP, int);
627
SEXP FixupFont(SEXP, int);
5508 ihaka 628
SEXP FixupCol(SEXP, unsigned int);
5507 ihaka 629
SEXP FixupCex(SEXP, double);
630
SEXP FixupLwd(SEXP, double);
7817 murrell 631
SEXP FixupVFont(SEXP);
1282 ihaka 632
 
633
 
581 paul 634
 
2505 maechler 635
/*-------------------------------------------------------------------
636
 *
637
 *  DEVICE STATE FUNCTIONS are concerned with getting and setting
638
 *  the current state of the device;  is it ready to be drawn into?
639
 */
640
 
641
/* has plot.new been called yet? */
581 paul 642
void GCheckState(DevDesc*);
2505 maechler 643
/* Set to 1 when plot.new succeeds
644
 * Set to 0 when don't want drawing to go ahead */
581 paul 645
void GSetState(int, DevDesc*);
646
 
647
 
2505 maechler 648
 
649
/*-------------------------------------------------------------------
650
 *
651
 *  GRAPHICAL PRIMITIVES are the generic front-end for the functions
652
 *  that every device driver must provide.
653
 *
654
 *  NOTE that locations supplied to these functions may be in any
655
 *  of the valid coordinate systems (each function takes a "coords"
656
 *  parameter to indicate the coordinate system);  the device-specific
657
 *  version of the function is responsible for calling GConvert to get
658
 *  the location into device coordinates.
659
 *
660
 */
661
 
662
 
663
/* Draw a circle, centred on (x,y) with radius r (in inches). */
581 paul 664
void GCircle(double, double, int, double, int, int, DevDesc*);
2505 maechler 665
/* Set clipping region (based on current setting of dd->gp.xpd).
666
 * Only clip if new clipping region is different from the current one */
581 paul 667
void GClip(DevDesc*);
3942 maechler 668
/* Polygon clipping: */
6098 pd 669
int GClipPolygon(double *, double *, int, int, int,
3942 maechler 670
		 double *, double *, DevDesc *);
2505 maechler 671
/* Always clips */
581 paul 672
void GForceClip(DevDesc*);
2505 maechler 673
/* Draw a line from (x1,y1) to (x2,y2): */
581 paul 674
void GLine(double, double, double, double, int, DevDesc*);
2505 maechler 675
/* Return the location of the next mouse click: */
581 paul 676
int  GLocator(double*, double*, int, DevDesc*);
2505 maechler 677
/* Return the height, depth, and width of the specified
678
 * character in the specified units: */
581 paul 679
void GMetricInfo(int, double*, double*, double*, int, DevDesc*);
2505 maechler 680
/* Set device "mode" (drawing or not drawing) here for windows and mac drivers.
681
 */
3367 ihaka 682
void GMode(int, DevDesc*);
2505 maechler 683
/* Draw a polygon using the specified lists of x and y values: */
581 paul 684
void GPolygon(int, double*, double*, int, int, int, DevDesc*);
2505 maechler 685
/* Draw series of straight lines using the specified lists of x and y values: */
581 paul 686
void GPolyline(int, double*, double*, int, DevDesc*);
2505 maechler 687
/* Draw a rectangle given two opposite corners: */
581 paul 688
void GRect(double, double, double, double, int, int, int, DevDesc*);
2505 maechler 689
/* Return the height of the specified string in the specified units: */
581 paul 690
double GStrHeight(char*, int, DevDesc*);
2505 maechler 691
/* Return the width of the specified string in the specified units */
581 paul 692
double GStrWidth(char*, int, DevDesc*);
2505 maechler 693
/* Draw the specified text at location (x,y) with the specified
694
 * rotation and justification: */
581 paul 695
void GText(double, double, int, char*, double, double, double, DevDesc*);
696
 
2505 maechler 697
 
698
void GStartPath(DevDesc*);
699
void GEndPath(DevDesc*);
700
 
990 maechler 701
void GMathText(double, double, int, SEXP, double, double, double, DevDesc*);
702
void GMMathText(SEXP, int, double, int, double, int, DevDesc*);
703
 
7817 murrell 704
void GVText(double x, double y, int unit, char* s, int typeface, int fontindex,
705
	    double xadj, double yadj, double rot, DevDesc *dd);
706
double GVStrWidth(const unsigned char *s, int typeface, int fontindex,
707
		  int unit, DevDesc *dd);
708
double GVStrHeight(const unsigned char *s, int typeface, int fontindex,
709
		   int unit, DevDesc *dd);
581 paul 710
 
2505 maechler 711
/*-------------------------------------------------------------------
712
 *
713
 *  GRAPHICAL UTILITIES are functions that produce graphical output
714
 *  using the graphical primitives (i.e., they are generic - NOT
715
 *  device-specific).
716
 *
717
 */
718
 
719
/* Draw a line from (x1,y1) to (x2,y2) with an arrow head
720
 * at either or both ends. */
581 paul 721
void GArrow(double, double, double, double, int, double, double, int, DevDesc*);
2505 maechler 722
/* Draw a box around specified region:
723
 *  1=plot region, 2=figure region, 3=inner region, 4=device. */
581 paul 724
void GBox(int, DevDesc*);
2505 maechler 725
/* Return a "nice" min, max and number of intervals for a given
726
 * range on a linear or _log_ scale, respectively: */
727
void GPretty(double*, double*, int*);
2 r 728
void GLPretty(double*, double*, int*);
2505 maechler 729
/* Draw text in margins. */
581 paul 730
void GMtext(char*, int, double, int, double, int, DevDesc*);
2505 maechler 731
/* Draw one of the predefined symbols (circle, square, diamond, ...) */
581 paul 732
void GSymbol(double, double, int, int, DevDesc*);
2 r 733
 
2505 maechler 734
double GExpressionHeight(SEXP, int, DevDesc*);
735
double GExpressionWidth(SEXP, int, DevDesc*);
581 paul 736
 
2505 maechler 737
 
738
 
739
/*-------------------------------------------------------------------
740
 *
741
 *  COLOUR CODE is concerned with the internals of R colour representation
742
 *
743
 */
744
 
745
/* Convert an R colour specification (which might be a number or */
746
/* a string) into an internal colour specification. */
5507 ihaka 747
unsigned int RGBpar(SEXP, int);
2505 maechler 748
 
749
 
750
/*-------------------------------------------------------------------
751
 *
752
 *  LINE TEXTURE CODE is concerned with the internals of R
753
 *  line texture representation.
754
 */
755
unsigned int LTYpar(SEXP, int);
2690 maechler 756
SEXP LTYget(unsigned int);
2505 maechler 757
 
758
 
759
/*----------------------------------------------------------------------
760
 *
761
 *  TRANSFORMATIONS are concerned with converting locations between
762
 *  coordinate systems and dimensions between different units.
763
 */
764
 
765
/* Convert an R unit (e.g., "user") into an internal unit (e.g., USER)> */
766
int GMapUnits(int);
3279 pd 767
/* Convert a LOCATION from one coordinate system to another: */
581 paul 768
void GConvert(double*, double*, int, int, DevDesc*);
3279 pd 769
double GConvertX(double, int, int, DevDesc*);
770
double GConvertY(double, int, int, DevDesc*);
2505 maechler 771
/* Convert an x/y-dimension from one set of units to another: */
581 paul 772
double GConvertXUnits(double, int, int, DevDesc*);
773
double GConvertYUnits(double, int, int, DevDesc*);
2505 maechler 774
 
775
/* Set up the different regions on a device (i.e., inner region,
776
 * figure region, plot region) and transformations for associated
777
 * coordinate systems (called whenever anything that affects the
778
 * coordinate transformations changes):
779
 */
780
void GReset(DevDesc*);
781
 
782
/* Set up the user coordinate transformations: */
783
void GMapWin2Fig(DevDesc*);
784
/* Set up the device for a new plot by Resetting graphics parameters
785
 * and Resetting the regions and coordinate Systems */
786
DevDesc *GNewPlot(int, int);
787
/* Set up the user coordinates based on the axis limits */
581 paul 788
void GScale(double, double, int, DevDesc*);
2505 maechler 789
/* Set up the axis limits based on the user coordinates */
581 paul 790
void GSetupAxis(int, DevDesc*);
2505 maechler 791
/* Return row and column of current figure in the layout matrix */
792
void currentFigureLocation(int*, int*, DevDesc*);
581 paul 793
 
7751 ripley 794
double R_Log10(double);
2505 maechler 795
 
796
double xDevtoNDC(double x, DevDesc *dd);
797
double yDevtoNDC(double y, DevDesc *dd);
798
double xDevtoNFC(double x, DevDesc *dd);
799
double yDevtoNFC(double y, DevDesc *dd);
581 paul 800
double xNPCtoUsr(double, DevDesc*);
801
double yNPCtoUsr(double, DevDesc*);
802
 
990 maechler 803
 
2505 maechler 804
		/* Miscellaneous (from graphics.c & colors.c) */
805
 
990 maechler 806
unsigned int rgb2col(char *);
807
unsigned int name2col(char *);
2505 maechler 808
unsigned int char2col(char *s);/* rgb2col() or name2col() */
809
char* col2name(unsigned int);
5507 ihaka 810
unsigned int str2col(char *s);
990 maechler 811
 
2505 maechler 812
unsigned int ScaleColor(double x);
813
 
814
char* RGB2rgb(unsigned int, unsigned int, unsigned int);
815
 
816
int StrMatch(char *s, char *t);
7824 ripley 817
void copyGPar(GPar *, GPar *);
2505 maechler 818
 
7817 murrell 819
/* some functions that plot.c needs to share with plot3d.c */
820
SEXP CreateAtVector(double*, double*, int, int);
821
void GetAxisLimits(double, double, double*, double*);
822
SEXP labelformat(SEXP);
823
 
7824 ripley 824
/* Vector fonts */
825
 
826
double GVStrWidth (const unsigned char *, int, int, int, DevDesc *);
827
double GVStrHeight (const unsigned char *, int, int, int, DevDesc *);
828
void GVText (double, double, int, char *, int, int, 
829
	     double, double, double, DevDesc *);
830
 
2 r 831
#endif