The R Project SVN R

Rev

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

Rev Author Line No. Line
11507 ripley 1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
82142 maechler 3
 *  Copyright (C) 1998--2021  R Core Team
11507 ripley 4
 *  Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
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
42308 ripley 17
 *  along with this program; if not, a copy is available at
68949 ripley 18
 *  https://www.R-project.org/Licenses/
11507 ripley 19
 */
20
 
70046 ripley 21
/* Internal header, not installed */
22
 
11507 ripley 23
#ifndef GRAPHICS_H_
24
#define GRAPHICS_H_
25
 
11509 ripley 26
#include <R_ext/Boolean.h>
11507 ripley 27
 
30956 murrell 28
#include <R_ext/GraphicsEngine.h>
44197 ripley 29
/* needed for R_GE_lineend/join, R_GE_gcontext */
44312 ripley 30
 
44348 ripley 31
#define R_GRAPHICS 1
82142 maechler 32
#include <Rgraphics.h> /* RUnit, G<par> functions */
30956 murrell 33
 
44154 ripley 34
/* base.c, graphics.c, par.c */
59084 maechler 35
#define MAX_LAYOUT_ROWS 200
36
#define MAX_LAYOUT_COLS 200
37
#define MAX_LAYOUT_CELLS 10007 /* must be less than 65535,
32449 ripley 38
				3 copies, 3bytes each */
11507 ripley 39
 
40
typedef struct {
41
	double ax;
42
	double bx;
43
	double ay;
44
	double by;
45
} GTrans;
46
 
47
typedef struct {
48
    /* Plot State */
59084 maechler 49
    /*
44342 ripley 50
       When the device driver is started this is 0
51
       After the first call to plot.new/perps it is 1
52
       Every graphics operation except plot.new/persp
59084 maechler 53
       should fail if state = 0
44342 ripley 54
       This is checked at the highest internal function
59084 maechler 55
       level (e.g., do_lines, do_axis, do_plot_xy, ...)
44342 ripley 56
    */
11507 ripley 57
 
59084 maechler 58
    int	state;		/* plot state: 1 if GNewPlot has been called
44343 ripley 59
			   (by plot.new or persp) */
60
    Rboolean valid;	/* valid layout ?  Used in GCheckState & do_playDL */
11507 ripley 61
 
62
    /* GRZ-like Graphics Parameters */
63
    /* ``The horror, the horror ... '' */
84150 maechler 64
    /* Marlon Brando - Apocalypse Now */
11507 ripley 65
 
66
    /* General Parameters -- set and interrogated directly */
67
 
68
    double adj;		/* String adjustment */
69
    Rboolean ann;	/* Should annotation take place */
70
    rcolor bg;		/* **R ONLY** Background color */
59177 ripley 71
    char bty;		/* Box type */
11507 ripley 72
    double cex;		/* Character expansion */
30956 murrell 73
    double lheight;     /* Line height
74
			   The height of a line of text is:
75
			   ps * cex * lheight */
11507 ripley 76
    rcolor col;		/* Plotting Color */
77
    double crt;		/* Character/string rotation */
78
    double din[2];	/* device size in inches */
84150 maechler 79
    int	err;		/* Error reporting level */
11507 ripley 80
    rcolor fg;		/* **R ONLY** Foreground Color */
59084 maechler 81
    char family[201];  /* **R ONLY** Font family
30956 murrell 82
			   Simple name which is mapped by device-specific
83
			   font database to device-specific name.
84
			   Only used if not "".
85
			   Default is "".
86
			   Ignored by some devices. */
11507 ripley 87
    int	font;		/* Text font */
88
    double gamma;	/* Device Gamma Correction */
89
    int	lab[3];		/* Axis labelling */
90
			/* [0] = # ticks on x-axis */
91
			/* [1] = # ticks on y-axis */
92
			/* [2] = length of axis labels */
93
    int	las;		/* Label style (rotation) */
94
    int	lty;		/* Line texture */
95
    double lwd;		/* Line width */
30956 murrell 96
    R_GE_lineend lend;  /* **R ONLY** Line end style */
97
    R_GE_linejoin ljoin;/* **R ONLY** Line join style */
98
    double lmitre;      /* **R ONLY** Line mitre limit */
11507 ripley 99
    double mgp[3];	/* Annotation location */
100
			/* [0] = location of axis title */
101
			/* [1] = location of axis label */
102
			/* [2] = location of axis line */
103
    double mkh;		/* Mark size in inches */
104
    int	pch;		/* Plotting character */
44343 ripley 105
    /* Note that ps is never changed, so always the same as dev->startps.
106
       However, the ps in the graphics context is changed */
44645 ripley 107
    double ps;		/* Text & symbol pointsize */
20446 maechler 108
    int	smo;		/* Curve smoothness */
11507 ripley 109
    double srt;		/* String Rotation */
110
    double tck;		/* Tick size as in S */
111
    double tcl;		/* Tick size in "lines" */
112
    double xaxp[3];	/* X Axis annotation */
113
			/* [0] = coordinate of lower tick */
114
			/* [1] = coordinate of upper tick */
115
			/* [2] = num tick intervals */
116
			/* almost always used internally */
59177 ripley 117
    char xaxs;		/* X Axis style */
118
    char xaxt;		/* X Axis type */
44343 ripley 119
    Rboolean xlog;	/* Log Axis for X */
11507 ripley 120
    int	xpd;		/* Clip to plot region indicator */
121
    int	oldxpd;
122
    double yaxp[3];	/* Y Axis annotation */
59177 ripley 123
    char yaxs;		/* Y Axis style */
124
    char yaxt;		/* Y Axis type */
11507 ripley 125
    Rboolean ylog;	/* Log Axis for Y */
126
 
127
    /* Annotation Parameters */
128
 
59177 ripley 129
    double cexbase;	/* Base character size */
130
    double cexmain;	/* Main title size */
131
    double cexlab;	/* xlab and ylab size */
132
    double cexsub;	/* Sub title size */
133
    double cexaxis;	/* Axis label size */
11507 ripley 134
 
135
    int	fontmain;	/* Main title font */
136
    int	fontlab;	/* Xlab and ylab font */
137
    int	fontsub;	/* Subtitle font */
138
    int	fontaxis;	/* Axis label fonts */
139
 
44369 ripley 140
    rcolor colmain;	/* Main title color */
141
    rcolor collab;	/* Xlab and ylab color */
142
    rcolor colsub;	/* Subtitle color */
143
    rcolor colaxis;	/* Axis label color */
11507 ripley 144
 
145
    /* Layout Parameters */
146
 
147
    Rboolean layout;	/* has a layout been specified */
148
 
149
    int	numrows;
150
    int	numcols;
151
    int	currentFigure;
152
    int	lastFigure;
153
    double heights[MAX_LAYOUT_ROWS];
154
    double widths[MAX_LAYOUT_COLS];
155
    int	cmHeights[MAX_LAYOUT_ROWS];
156
    int	cmWidths[MAX_LAYOUT_COLS];
32449 ripley 157
    unsigned short order[MAX_LAYOUT_CELLS];
11507 ripley 158
    int	rspct;		/* 0 = none, 1 = full, 2 = see respect */
32449 ripley 159
    unsigned char respect[MAX_LAYOUT_CELLS];
11507 ripley 160
 
161
    int	mfind;		/* By row/col indicator */
162
 
163
    /* Layout parameters which can be set directly by the */
164
    /* user (e.g., par(fig=c(.5,1,0,1))) or otherwise are */
165
    /* calculated automatically */
166
    /* NOTE that *Units parameters are for internal use only */
167
 
168
    double fig[4];	/* (current) Figure size (proportion) */
169
			/* [0] = left, [1] = right */
170
			/* [2] = bottom, [3] = top */
171
    double fin[2];	/* (current) Figure size (inches) */
172
			/* [0] = width, [1] = height */
173
    GUnit fUnits;	/* (current) figure size units */
174
    double plt[4];	/* (current) Plot size (proportions) */
175
			/* [0] = left, [1] = right */
176
			/* [2] = bottom, [3] = top */
177
    double pin[2];	/* (current) plot size (inches) */
178
			/* [0] = width, [1] = height */
179
    GUnit pUnits;	/* (current) plot size units */
180
    Rboolean defaultFigure;	/* calculate figure from layout ? */
181
    Rboolean defaultPlot;	/* calculate plot from figure - margins ? */
182
 
183
    /* Layout parameters which are set directly by the user */
184
 
185
    double mar[4];	/* Plot margins in lines */
186
    double mai[4];	/* Plot margins in inches */
187
			/* [0] = bottom, [1] = left */
188
			/* [2] = top, [3] = right */
189
    GUnit mUnits;	/* plot margin units */
190
    double mex;		/* Margin expansion factor */
191
    double oma[4];	/* Outer margins in lines */
192
    double omi[4];	/* outer margins in inches */
193
    double omd[4];	/* outer margins in NDC */
194
			/* [0] = bottom, [1] = left */
195
			/* [2] = top, [3] = right */
196
    GUnit oUnits;	/* outer margin units */
59177 ripley 197
    char pty;		/* Plot type */
11507 ripley 198
 
199
    /* Layout parameters which can be set by the user, but */
200
    /* almost always get automatically calculated anyway */
201
 
202
    double usr[4];	/* Graphics window */
203
			/* [0] = xmin, [1] = xmax */
204
			/* [2] = ymin, [3] = ymax */
205
 
206
    /* The logged usr parameter;  if xlog, use logusr[0:1] */
207
    /* if ylog, use logusr[2:3] */
208
 
209
    double logusr[4];
210
 
211
    /* Layout parameter: Internal flags */
212
 
213
    Rboolean new;	/* Clean plot ? */
214
    int	devmode;	/* creating new image or adding to existing one */
215
 
216
    /* Coordinate System Mappings */
217
    /* These are only used internally (i.e., cannot be */
218
    /* set directly by the user) */
219
 
220
    /* The reliability of these parameters relies on */
221
    /* the fact that plot.new is the */
222
    /* first graphics operation called in the creation */
44343 ripley 223
    /* of a graph  (unless it is a call to persp) */
11507 ripley 224
 
225
    /* udpated per plot.new */
226
 
227
    double xNDCPerChar;	/* Nominal character width (NDC) */
228
    double yNDCPerChar;	/* Nominal character height (NDC) */
229
    double xNDCPerLine;	/* Nominal line width (NDC) */
230
    double yNDCPerLine;	/* Nominal line height (NDC) */
231
    double xNDCPerInch;	/* xNDC -> Inches */
232
    double yNDCPerInch;	/* yNDC -> Inches */
233
 
234
    /* updated per plot.new and if inner2dev changes */
235
 
236
    GTrans fig2dev;	/* Figure to device */
237
 
238
    /* udpated per DevNewPlot and if ndc2dev changes */
239
 
240
    GTrans inner2dev;	/* Inner region to device */
241
 
242
    /* udpated per device resize */
243
 
244
    GTrans ndc2dev;	/* NDC to raw device */
245
 
246
    /* updated per plot.new and per plot.window */
247
 
248
    GTrans win2fig;	/* Window to figure mapping */
249
 
250
    /* NOTE: if user has not set fig and/or plt then */
251
    /* they need to be updated per plot.new too */
252
 
34613 murrell 253
    double scale;       /* An internal "zoom" factor to apply to ps and lwd */
254
                        /* (for fit-to-window resizing in Windows) */
11507 ripley 255
} GPar;
256
 
11510 ripley 257
/* always remap private functions */
258
#define copyGPar		Rf_copyGPar
37012 ripley 259
#define FixupCol		Rf_FixupCol
260
#define FixupLty		Rf_FixupLty
261
#define FixupLwd		Rf_FixupLwd
262
#define FixupVFont		Rf_FixupVFont
11510 ripley 263
#define GInit			Rf_GInit
44154 ripley 264
#define labelformat		Rf_labelformat
37012 ripley 265
#define ProcessInlinePars	Rf_ProcessInlinePars
44154 ripley 266
#define recordGraphicOperation	Rf_recordGraphicOperation
11507 ripley 267
 
31938 murrell 268
/* NOTE: during replays, call == R_NilValue;
269
   ----  the following adds readability: */
44348 ripley 270
Rboolean GRecording(SEXP, pGEDevDesc);
31938 murrell 271
 
11507 ripley 272
/* Default the settings for general graphical parameters
273
 * (i.e., defaults that do not depend on the device type: */
274
void GInit(GPar*);
275
 
11510 ripley 276
void copyGPar(GPar *, GPar *);
277
 
44312 ripley 278
 /* from graphics.c, used in par.c */
279
double R_Log10(double);
11510 ripley 280
 
44312 ripley 281
/* from par.c, called in plot.c, plot3d.c */
59261 ripley 282
void ProcessInlinePars(SEXP, pGEDevDesc);
37012 ripley 283
 
44154 ripley 284
/* from device.c */
44348 ripley 285
void recordGraphicOperation(SEXP, SEXP, pGEDevDesc);
44154 ripley 286
 
287
/* some functions that plot.c needs to share with plot3d.c */
44312 ripley 288
SEXP FixupCol(SEXP, unsigned int);
37012 ripley 289
SEXP FixupLty(SEXP, int);
290
SEXP FixupLwd(SEXP, double);
291
SEXP FixupVFont(SEXP);
44154 ripley 292
SEXP labelformat(SEXP);
37012 ripley 293
 
59084 maechler 294
/*
27237 murrell 295
 * Function to generate an R_GE_gcontext from Rf_gpptr info
44154 ripley 296
 *
297
 * from graphics.c, used in plot.c, plotmath.c
27237 murrell 298
 */
44348 ripley 299
void gcontextFromGP(pGEcontext gc, pGEDevDesc dd);
27237 murrell 300
 
44154 ripley 301
/* From base.c */
44343 ripley 302
#define gpptr Rf_gpptr
303
#define dpptr Rf_dpptr
44348 ripley 304
GPar* Rf_gpptr(pGEDevDesc dd);
305
GPar* Rf_dpptr(pGEDevDesc dd);
16880 murrell 306
 
11507 ripley 307
#endif /* GRAPHICS_H_ */