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