RAPI
R_ext/GraphicsDevice.h
Go to the documentation of this file.
00001 /*
00002  *  R : A Computer Language for Statistical Data Analysis
00003  *  Copyright (C) 2001-11 The R Core Team.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU Lesser General Public License as published by
00007  *  the Free Software Foundation; either version 2.1 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU Lesser General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Lesser General Public License
00016  *  along with this program; if not, a copy is available at
00017  *  https://www.R-project.org/Licenses/
00018  */
00019 
00020 /* Used by third-party graphics devices.
00021  *
00022  * This defines DevDesc, whereas GraphicsEngine.h defines GEDevDesc.
00023  * Also contains entry points from gevents.c
00024  */
00025 
00026 #ifndef R_GRAPHICSDEVICE_H_
00027 #define R_GRAPHICSDEVICE_H_
00028 
00029 
00030 /* ideally we would use prototypes in DevDesc.  
00031    Some devices have taken to passing pointers to their own structure
00032    instead of DevDesc* , defining R_USE_PROTOTYPES 0 allows them to
00033    opt out.
00034 */
00035 
00036 #ifndef  R_USE_PROTOTYPES
00037 # define R_USE_PROTOTYPES 1
00038 # ifndef R_GRAPHICSENGINE_H_
00039 #  error R_ext/GraphicsEngine.h must be included first, and includes this header
00040 # endif
00041 #endif
00042 
00043 #include <R_ext/Boolean.h>
00044 
00045 #ifdef __cplusplus
00046 extern "C" {
00047 #endif
00048 
00049 /* --------- New (in 1.4.0) device driver structure ---------
00050  * NOTES:
00051  * 1. All locations and dimensions are in device coordinates.
00052  * 2. I found this comment in the doc for dev_Open -- looks nasty
00053  *    Any known instances of such a thing happening?  Should be
00054  *    replaced by a function to query the device for preferred gpars
00055  *    settings? (to be called when the device is initialised)
00056          *
00057          * NOTE that it is perfectly acceptable for this
00058          * function to set generic graphics parameters too
00059          * (i.e., override the generic parameter settings
00060          * which GInit sets up) all at the author's own risk
00061          * of course :)
00062      *
00063  * 3. Do we really need dev_StrWidth as well as dev_MetricInfo?
00064  *    I can see the difference between the two -- its just a
00065  *    question of whether dev_MetricInfo should just return
00066  *    what dev_StrWidth would give if font metric information is
00067  *    not available.  I guess having both allows the developer
00068  *    to decide when to ask for which sort of value, and to decide
00069  *    what to do when font metric information is not available.
00070  *    And why not a dev_StrHeight?
00071  * 4. Should "ipr", "asp", and "cra" be in the device description?
00072  *    If not, then where?
00073  *    I guess they don't need to be if no device makes use of them.
00074  *    On the other hand, they would need to be replaced by a device
00075  *    call that R base graphics could use to get enough information
00076  *    to figure them out.  (e.g., some sort of dpi() function to
00077  *    complement the size() function.)
00078  */
00079 
00080 typedef struct _DevDesc DevDesc;
00081 typedef DevDesc* pDevDesc;
00082 
00083 struct _DevDesc {
00084     /********************************************************
00085      * Device physical characteristics
00086      ********************************************************/
00087     double left;            /* left raster coordinate */
00088     double right;           /* right raster coordinate */
00089     double bottom;          /* bottom raster coordinate */
00090     double top;             /* top raster coordinate */
00091     /* R only has the notion of a rectangular clipping region
00092      */
00093     double clipLeft;
00094     double clipRight;
00095     double clipBottom;
00096     double clipTop;
00097     /* I hate these next three -- they seem like a real fudge
00098      * BUT I'm not sure what to replace them with so they stay for now.
00099      */
00100     double xCharOffset;         /* x character addressing offset - unused */
00101     double yCharOffset;         /* y character addressing offset */
00102     double yLineBias;           /* 1/2 interline space as frac of line height */
00103     double ipr[2];          /* Inches per raster; [0]=x, [1]=y */
00104     /* I hate this guy too -- seems to assume that a device can only
00105      * have one font size during its lifetime
00106      * BUT removing/replacing it would take quite a lot of work
00107      * to design and insert a good replacement so it stays for now.
00108      */
00109     double cra[2];          /* Character size in rasters; [0]=x, [1]=y */
00110     double gamma;           /* (initial) Device Gamma Correction */
00111     /********************************************************
00112      * Device capabilities
00113      ********************************************************/
00114     Rboolean canClip;       /* Device-level clipping */
00115     Rboolean canChangeGamma;    /* can the gamma factor be modified? */
00116     int canHAdj;            /* Can do at least some horiz adjust of text
00117                        0 = none, 1 = {0,0.5,1}, 2 = [0,1] */
00118     /********************************************************
00119      * Device initial settings
00120      ********************************************************/
00121     /* These are things that the device must set up when it is created.
00122      * The graphics system can modify them and track current values,
00123      */
00124     double startps;
00125     int startcol;  /* sets par("fg"), par("col") and gpar("col") */
00126     int startfill; /* sets par("bg") and gpar("fill") */
00127     int startlty;
00128     int startfont;
00129     double startgamma;
00130     /********************************************************
00131      * Device specific information
00132      ********************************************************/
00133     void *deviceSpecific;   /* pointer to device specific parameters */
00134     /********************************************************
00135      * Device display list
00136      ********************************************************/
00137     Rboolean displayListOn;     /* toggle for initial display list status */
00138 
00139 
00140     /********************************************************
00141      * Event handling entries
00142      ********************************************************/
00143 
00144     /* Used in do_setGraphicsEventEnv */
00145 
00146     Rboolean canGenMouseDown; /* can the device generate mousedown events */
00147     Rboolean canGenMouseMove; /* can the device generate mousemove events */
00148     Rboolean canGenMouseUp;   /* can the device generate mouseup events */
00149     Rboolean canGenKeybd;     /* can the device generate keyboard events */
00150 
00151     Rboolean gettingEvent;    /* This is set while getGraphicsEvent
00152                  is actively looking for events */
00153     
00154     /********************************************************
00155      * Device procedures.
00156      ********************************************************/
00157 
00158     /*
00159      * ---------------------------------------
00160      * GENERAL COMMENT ON GRAPHICS PARAMETERS:
00161      * ---------------------------------------
00162      * Graphical parameters are now passed in a pointer to a 
00163      * graphics context structure (pGEcontext) rather than individually.
00164      * Each device action should extract the parameters it needs
00165      * and ignore the others.  Thought should be given to which
00166      * parameters are relevant in each case -- the graphics engine
00167      * does not REQUIRE that each parameter is honoured, but if
00168      * a parameter is NOT honoured, it might be a good idea to
00169      * issue a warning when a parameter is not honoured (or at
00170      * the very least document which parameters are not honoured
00171      * in the user-level documentation for the device).  [An example
00172      * of a parameter that may not be honoured by many devices is
00173      * transparency.]
00174      */
00175 
00176     /*
00177      * device_Activate is called when a device becomes the
00178      * active device.  For example, it can be used to change the
00179      * title of a window to indicate the active status of
00180      * the device to the user.  Not all device types will
00181      * do anything.
00182      * The only parameter is a device driver structure.
00183      * An example is ...
00184      *
00185      * static void   X11_Activate(pDevDesc dd);
00186      *
00187      * As from R 2.14.0 this can be omitted or set to NULL.
00188      */
00189 #if R_USE_PROTOTYPES
00190     void (*activate)(const pDevDesc );
00191 #else
00192     void (*activate)();
00193 #endif
00194     /*
00195      * device_Circle should have the side-effect that a
00196      * circle is drawn, centred at the given location, with
00197      * the given radius.
00198      * (If the device has non-square pixels, 'radius' should
00199      * be interpreted in the units of the x direction.)
00200      * The border of the circle should be
00201      * drawn in the given "col", and the circle should be
00202      * filled with the given "fill" colour.
00203      * If "col" is NA_INTEGER then no border should be drawn
00204      * If "fill" is NA_INTEGER then the circle should not
00205      * be filled.
00206      * An example is ...
00207      *
00208      * static void X11_Circle(double x, double y, double r,
00209      *                        pGEcontext gc,
00210      *                        pDevDesc dd);
00211      *
00212      * R_GE_gcontext parameters that should be honoured (if possible):
00213      *   col, fill, gamma, lty, lwd
00214      */
00215 #if R_USE_PROTOTYPES
00216     void (*circle)(double x, double y, double r, const pGEcontext gc, pDevDesc dd);
00217 #else
00218     void (*circle)();
00219 #endif
00220     /*
00221      * device_Clip is given the left, right, bottom, and
00222      * top of a rectangle (in DEVICE coordinates).
00223      * It should have the side-effect that subsequent output
00224      * is clipped to the given rectangle.
00225      * NOTE that R's graphics engine already clips to the
00226      * extent of the device.
00227      * NOTE also that this will probably only be called if
00228      * the flag canClip is true.
00229      * An example is ...
00230      *
00231      * static void X11_Clip(double x0, double x1, double y0, double y1,
00232      *                      pDevDesc dd)
00233      */
00234 #if R_USE_PROTOTYPES
00235     void (*clip)(double x0, double x1, double y0, double y1, pDevDesc dd);
00236 #else
00237     void (*clip)();
00238 #endif
00239     /*
00240      * device_Close is called when the device is killed.
00241      * This function is responsible for destroying any
00242      * device-specific resources that were created in
00243      * device_Open and for FREEing the device-specific
00244      * parameters structure.
00245      * An example is ...
00246      *
00247      * static void X11_Close(pDevDesc dd)
00248      *
00249      */
00250 #if R_USE_PROTOTYPES
00251     void (*close)(pDevDesc dd);
00252 #else
00253     void (*close)();
00254 #endif
00255     /*
00256      * device_Deactivate is called when a device becomes
00257      * inactive.
00258      * This allows the device to undo anything it did in
00259      * dev_Activate.
00260      * Not all device types will do anything.
00261      * An example is ...
00262      *
00263      * static void X11_Deactivate(pDevDesc dd)
00264      *
00265      * As from R 2.14.0 this can be omitted or set to NULL.
00266      */
00267 #if R_USE_PROTOTYPES
00268     void (*deactivate)(pDevDesc );
00269 #else
00270     void (*deactivate)();
00271 #endif
00272 
00273 
00274     /*
00275      * device_Locator should return the location of the next
00276      * mouse click (in DEVICE coordinates)
00277      * Not all devices will do anything (e.g., postscript)
00278      * An example is ...
00279      *
00280      * static Rboolean X11_Locator(double *x, double *y, pDevDesc dd)
00281      *
00282      * As from R 2.14.0 this can be omitted or set to NULL.
00283      */
00284 #if R_USE_PROTOTYPES
00285     Rboolean (*locator)(double *x, double *y, pDevDesc dd);
00286 #else
00287     Rboolean (*locator)();
00288 #endif
00289     /*
00290      * device_Line should have the side-effect that a single
00291      * line is drawn (from x1,y1 to x2,y2)
00292      * An example is ...
00293      *
00294      * static void X11_Line(double x1, double y1, double x2, double y2,
00295      *                      const pGEcontext gc,
00296      *                      pDevDesc dd);
00297      *
00298      * R_GE_gcontext parameters that should be honoured (if possible):
00299      *   col, gamma, lty, lwd
00300      */
00301 #if R_USE_PROTOTYPES
00302     void (*line)(double x1, double y1, double x2, double y2,
00303          const pGEcontext gc, pDevDesc dd);
00304 #else
00305     void (*line)();
00306 #endif
00307     /*
00308      * device_MetricInfo should return height, depth, and
00309      * width information for the given character in DEVICE
00310      * units.
00311      * Note: in an 8-bit locale, c is 'char'.
00312      * In an mbcslocale, it is wchar_t, and at least some
00313      * of code assumes that is UCS-2 (Windows, true) or UCS-4.
00314      * This is used for formatting mathematical expressions
00315      * and for exact centering of text (see GText)
00316      * If the device cannot provide metric information then
00317      * it MUST return 0.0 for ascent, descent, and width.
00318      * An example is ...
00319      *
00320      * static void X11_MetricInfo(int c,
00321      *                            const pGEcontext gc,
00322      *                            double* ascent, double* descent,
00323      *                            double* width, pDevDesc dd);
00324      *
00325      * R_GE_gcontext parameters that should be honoured (if possible):
00326      *   font, cex, ps
00327      */
00328 #if R_USE_PROTOTYPES
00329     void (*metricInfo)(int c, const pGEcontext gc,
00330                double* ascent, double* descent, double* width,
00331                pDevDesc dd);
00332 #else
00333     void (*metricInfo)();
00334 #endif
00335     /*
00336      * device_Mode is called whenever the graphics engine
00337      * starts drawing (mode=1) or stops drawing (mode=0)
00338      * GMode (in graphics.c) also says that 
00339      * mode = 2 (graphical input on) exists.
00340      * The device is not required to do anything
00341      * An example is ...
00342      *
00343      * static void X11_Mode(int mode, pDevDesc dd);
00344      *
00345      * As from R 2.14.0 this can be omitted or set to NULL.
00346      */
00347 #if R_USE_PROTOTYPES
00348     void (*mode)(int mode, pDevDesc dd);
00349 #else
00350     void (*mode)();
00351 #endif
00352     /*
00353      * device_NewPage is called whenever a new plot requires
00354      * a new page.
00355      * A new page might mean just clearing the
00356      * device (e.g., X11) or moving to a new page
00357      * (e.g., postscript)
00358      * An example is ...
00359      *
00360      *
00361      * static void X11_NewPage(const pGEcontext gc,
00362      *                         pDevDesc dd);
00363      *
00364      */
00365 #if R_USE_PROTOTYPES
00366     void (*newPage)(const pGEcontext gc, pDevDesc dd);
00367 #else
00368     void (*newPage)();
00369 #endif
00370     /*
00371      * device_Polygon should have the side-effect that a
00372      * polygon is drawn using the given x and y values
00373      * the polygon border should be drawn in the "col"
00374      * colour and filled with the "fill" colour.
00375      * If "col" is NA_INTEGER don't draw the border
00376      * If "fill" is NA_INTEGER don't fill the polygon
00377      * An example is ...
00378      *
00379      * static void X11_Polygon(int n, double *x, double *y,
00380      *                         const pGEcontext gc,
00381      *                         pDevDesc dd);
00382      *
00383      * R_GE_gcontext parameters that should be honoured (if possible):
00384      *   col, fill, gamma, lty, lwd
00385      */
00386 #if R_USE_PROTOTYPES
00387     void (*polygon)(int n, double *x, double *y, const pGEcontext gc, pDevDesc dd);
00388 #else
00389     void (*polygon)();
00390 #endif
00391     /*
00392      * device_Polyline should have the side-effect that a
00393      * series of line segments are drawn using the given x
00394      * and y values.
00395      * An example is ...
00396      *
00397      * static void X11_Polyline(int n, double *x, double *y,
00398      *                          const pGEcontext gc,
00399      *                          pDevDesc dd);
00400      *
00401      * R_GE_gcontext parameters that should be honoured (if possible):
00402      *   col, gamma, lty, lwd
00403      */
00404 #if R_USE_PROTOTYPES
00405     void (*polyline)(int n, double *x, double *y, const pGEcontext gc, pDevDesc dd);
00406 #else
00407     void (*polyline)();
00408 #endif
00409     /*
00410      * device_Rect should have the side-effect that a
00411      * rectangle is drawn with the given locations for its
00412      * opposite corners.  The border of the rectangle
00413      * should be in the given "col" colour and the rectangle
00414      * should be filled with the given "fill" colour.
00415      * If "col" is NA_INTEGER then no border should be drawn
00416      * If "fill" is NA_INTEGER then the rectangle should not
00417      * be filled.
00418      * An example is ...
00419      *
00420      * static void X11_Rect(double x0, double y0, double x1, double y1,
00421      *                      const pGEcontext gc,
00422      *                      pDevDesc dd);
00423      *
00424      */
00425 #if R_USE_PROTOTYPES
00426     void (*rect)(double x0, double y0, double x1, double y1,
00427          const pGEcontext gc, pDevDesc dd);
00428 #else
00429     void (*rect)();
00430 #endif
00431     /* 
00432      * device_Path should draw one or more sets of points 
00433      * as a single path
00434      * 
00435      * 'x' and 'y' give the points
00436      *
00437      * 'npoly' gives the number of polygons in the path
00438      * MUST be at least 1
00439      *
00440      * 'nper' gives the number of points in each polygon
00441      * each value MUST be at least 2
00442      *
00443      * 'winding' says whether to fill using the nonzero 
00444      * winding rule or the even-odd rule
00445      *
00446      * Added 2010-06-27
00447      *
00448      * As from R 2.13.2 this can be left unimplemented as NULL.
00449      */
00450 #if R_USE_PROTOTYPES
00451     void (*path)(double *x, double *y, 
00452                  int npoly, int *nper,
00453                  Rboolean winding,
00454                  const pGEcontext gc, pDevDesc dd);
00455 #else
00456     void (*path)();
00457 #endif
00458     /* 
00459      * device_Raster should draw a raster image justified 
00460      * at the given location,
00461      * size, and rotation (not all devices may be able to rotate?)
00462      * 
00463      * 'raster' gives the image data BY ROW, with every four bytes
00464      * giving one R colour (ABGR).
00465      *
00466      * 'x and 'y' give the bottom-left corner.
00467      *
00468      * 'rot' is in degrees (as per device_Text), with positive
00469      * rotation anticlockwise from the positive x-axis.
00470      *
00471      * As from R 2.13.2 this can be left unimplemented as NULL.
00472      */
00473 #if R_USE_PROTOTYPES
00474     void (*raster)(unsigned int *raster, int w, int h,
00475                    double x, double y, 
00476                    double width, double height,
00477                    double rot, 
00478                    Rboolean interpolate,
00479                    const pGEcontext gc, pDevDesc dd);
00480 #else
00481     void (*raster)();
00482 #endif
00483     /* 
00484      * device_Cap should return an integer matrix (R colors)
00485      * representing the current contents of the device display.
00486      * 
00487      * The result is expected to be ROW FIRST.
00488      *
00489      * This will only make sense for raster devices and can 
00490      * probably only be implemented for screen devices.
00491      *
00492      * added 2010-06-27
00493      *
00494      * As from R 2.13.2 this can be left unimplemented as NULL.
00495      * For earlier versions of R it should return R_NilValue.
00496      */
00497 #if R_USE_PROTOTYPES
00498     SEXP (*cap)(pDevDesc dd);
00499 #else
00500     SEXP (*cap)();
00501 #endif
00502     /*
00503      * device_Size is called whenever the device is
00504      * resized.
00505      * The function returns (left, right, bottom, and top) for the
00506      * new device size.
00507      * This is not usually called directly by the graphics
00508      * engine because the detection of device resizes
00509      * (e.g., a window resize) are usually detected by
00510      * device-specific code.
00511      * An example is ...
00512      *
00513      * static void X11_Size(double *left, double *right,
00514      *                      double *bottom, double *top,
00515      *                      pDevDesc dd);
00516      *
00517      * R_GE_gcontext parameters that should be honoured (if possible):
00518      *   col, fill, gamma, lty, lwd
00519      *
00520      * As from R 2.13.2 this can be left unimplemented as NULL.
00521      */
00522 #if R_USE_PROTOTYPES
00523     void (*size)(double *left, double *right, double *bottom, double *top,
00524          pDevDesc dd);
00525 #else
00526     void (*size)();
00527 #endif
00528     /*
00529      * device_StrWidth should return the width of the given
00530      * string in DEVICE units.
00531      * An example is ...
00532      *
00533      * static double X11_StrWidth(const char *str,
00534      *                            const pGEcontext gc,
00535      *                            pDevDesc dd)
00536      *
00537      * R_GE_gcontext parameters that should be honoured (if possible):
00538      *   font, cex, ps
00539      */
00540 #if R_USE_PROTOTYPES
00541     double (*strWidth)(const char *str, const pGEcontext gc, pDevDesc dd);
00542 #else
00543     double (*strWidth)();
00544 #endif
00545     /*
00546      * device_Text should have the side-effect that the
00547      * given text is drawn at the given location.
00548      * The text should be rotated according to rot (degrees)
00549      * An example is ...
00550      *
00551      * static void X11_Text(double x, double y, const char *str,
00552      *                      double rot, double hadj,
00553      *                      const pGEcontext gc,
00554      *                      pDevDesc dd);
00555      *
00556      * R_GE_gcontext parameters that should be honoured (if possible):
00557      *   font, cex, ps, col, gamma
00558      */
00559 #if R_USE_PROTOTYPES
00560     void (*text)(double x, double y, const char *str, double rot,
00561          double hadj, const pGEcontext gc, pDevDesc dd);
00562 #else
00563     void (*text)();
00564 #endif
00565     /*
00566      * device_onExit is called by GEonExit when the user has aborted
00567      * some operation, and so an R_ProcessEvents call may not return normally.
00568      * It need not be set to any value; if null, it will not be called.
00569      *
00570      * An example is ...
00571      *
00572      * static void GA_onExit(pDevDesc dd);
00573     */
00574 #if R_USE_PROTOTYPES
00575     void (*onExit)(pDevDesc dd);
00576 #else
00577     void (*onExit)();
00578 #endif
00579     /*
00580      * device_getEvent is no longer used, but the slot is kept for back
00581      * compatibility of the structure.
00582      */
00583     SEXP (*getEvent)(SEXP, const char *);
00584 
00585     /* --------- Optional features introduced in 2.7.0 --------- */
00586 
00587     /* Does the device have a device-specific way to confirm a 
00588        new frame (for e.g. par(ask=TRUE))?
00589        This should be NULL if it does not.
00590        If it does, it returns TRUE if the device handled this, and
00591        FALSE if it wants the engine to do so. 
00592 
00593        There is an example in the windows() device.
00594 
00595        Can be left unimplemented as NULL.
00596     */
00597 #if R_USE_PROTOTYPES
00598     Rboolean (*newFrameConfirm)(pDevDesc dd);
00599 #else
00600     Rboolean (*newFrameConfirm)();
00601 #endif
00602 
00603     /* Some devices can plot UTF-8 text directly without converting
00604        to the native encoding, e.g. windows(), quartz() ....
00605 
00606        If this flag is true, all text *not in the symbol font* is sent
00607        in UTF8 to the textUTF8/strWidthUTF8 entry points.
00608 
00609        If the flag is TRUE, the metricInfo entry point should
00610        accept negative values for 'c' and treat them as indicating
00611        Unicode points (as well as positive values in a MBCS locale).
00612     */
00613     Rboolean hasTextUTF8; /* and strWidthUTF8 */
00614 #if R_USE_PROTOTYPES
00615     void (*textUTF8)(double x, double y, const char *str, double rot,
00616              double hadj, const pGEcontext gc, pDevDesc dd);
00617     double (*strWidthUTF8)(const char *str, const pGEcontext gc, pDevDesc dd);
00618 #else
00619     void (*textUTF8)();
00620     double (*strWidthUTF8)();
00621 #endif
00622     Rboolean wantSymbolUTF8;
00623 
00624     /* Is rotated text good enough to be preferable to Hershey in
00625        contour labels?  Old default was FALSE.
00626     */
00627     Rboolean useRotatedTextInContour;
00628 
00629     /* --------- Post-2.7.0 features --------- */
00630 
00631     /* Added in 2.12.0:  Changed graphics event handling. */
00632     
00633     SEXP eventEnv;   /* This is an environment holding event handlers. */
00634     /*
00635      * eventHelper(dd, 1) is called by do_getGraphicsEvent before looking for a 
00636      * graphics event.  It will then call R_ProcessEvents() and eventHelper(dd, 2)
00637      * until this or another device returns sets a non-null result value in eventEnv,
00638      * at which time eventHelper(dd, 0) will be called.
00639      * 
00640      * An example is ...
00641      *
00642      * static SEXP GA_eventHelper(pDevDesc dd, int code);
00643 
00644      * Can be left unimplemented as NULL
00645      */
00646 #if R_USE_PROTOTYPES
00647     void (*eventHelper)(pDevDesc dd, int code);
00648 #else
00649     void (*eventHelper)();
00650 #endif
00651 
00652     /* added in 2.14.0, only used by screen devices.
00653 
00654        Allows graphics devices to have multiple levels of suspension: 
00655        when this reaches zero output is flushed.
00656 
00657        Can be left unimplemented as NULL.
00658      */
00659 #if R_USE_PROTOTYPES
00660     int (*holdflush)(pDevDesc dd, int level);
00661 #else
00662     int (*holdflush)();
00663 #endif
00664 
00665     /* added in 2.14.0, for dev.capabilities.
00666        In all cases 0 means NA (unset).
00667     */
00668     int haveTransparency; /* 1 = no, 2 = yes */
00669     int haveTransparentBg; /* 1 = no, 2 = fully, 3 = semi */
00670     int haveRaster; /* 1 = no, 2 = yes, 3 = except for missing values */
00671     int haveCapture, haveLocator;  /* 1 = no, 2 = yes */
00672 
00673 
00674     /* Area for future expansion.
00675        By zeroing this, devices are more likely to work if loaded
00676        into a later version of R than that they were compiled under.
00677     */
00678     char reserved[64];
00679 };
00680 
00681 
00682     /********************************************************/
00683     /* the device-driver entry point is given a device  */
00684     /* description structure that it must set up.  this */
00685     /* involves several important jobs ...          */
00686     /* (1) it must ALLOCATE a new device-specific parameters*/
00687     /* structure and FREE that structure if anything goes   */
00688     /* wrong (i.e., it won't report a successful setup to   */
00689     /* the graphics engine (the graphics engine is NOT  */
00690     /* responsible for allocating or freeing device-specific*/
00691     /* resources or parameters)             */
00692     /* (2) it must initialise the device-specific resources */
00693     /* and parameters (mostly done by calling device_Open)  */
00694     /* (3) it must initialise the generic graphical     */
00695     /* parameters that are not initialised by GInit (because*/
00696     /* only the device knows what values they should have)  */
00697     /* see Graphics.h for the official list of these    */
00698     /* (4) it may reset generic graphics parameters that    */
00699     /* have already been initialised by GInit (although you */
00700     /* should know what you are doing if you do this)   */
00701     /* (5) it must attach the device-specific parameters    */
00702     /* structure to the device description structure    */
00703     /* e.g., dd->deviceSpecfic = (void *) xd;       */
00704     /* (6) it must FREE the overall device description if   */
00705     /* it wants to bail out to the top-level        */
00706     /* the graphics engine is responsible for allocating    */
00707     /* the device description and freeing it in most cases  */
00708     /* but if the device driver freaks out it needs to do   */
00709     /* the clean-up itself                  */
00710     /********************************************************/
00711 
00712 /* moved from Rgraphics.h */
00713 
00714 /*
00715  *  Some Notes on Color
00716  *
00717  *  R uses a 24-bit color model.  Colors are specified in 32-bit
00718  *  integers which are partitioned into 4 bytes as follows.
00719  *
00720  *      <-- most sig        least sig -->
00721  *      +-------------------------------+
00722  *      |   0   | blue  | green |  red  |
00723  *      +-------------------------------+
00724  *
00725  *  The red, green and blue bytes can be extracted as follows.
00726  *
00727  *      red   = ((color      ) & 255)
00728  *      green = ((color >>  8) & 255)
00729  *      blue  = ((color >> 16) & 255)
00730  */
00731 /*
00732  *  Changes as from 1.4.0: use top 8 bits as an alpha channel.
00733  *  0 = opaque, 255 = transparent.
00734  */
00735 /*
00736  * Changes as from 2.0.0:  use top 8 bits as full alpha channel
00737  *      255 = opaque, 0 = transparent
00738  *      [to conform with SVG, PDF and others]
00739  *      and everything in between is used
00740  *      [which means that NA is not stored as an internal colour;
00741  *       it is converted to R_RGBA(255, 255, 255, 0)]
00742  */
00743 
00744 #define R_RGB(r,g,b)    ((r)|((g)<<8)|((b)<<16)|0xFF000000)
00745 #define R_RGBA(r,g,b,a) ((r)|((g)<<8)|((b)<<16)|((a)<<24))
00746 #define R_RED(col)  (((col)    )&255)
00747 #define R_GREEN(col)    (((col)>> 8)&255)
00748 #define R_BLUE(col) (((col)>>16)&255)
00749 #define R_ALPHA(col)    (((col)>>24)&255)
00750 #define R_OPAQUE(col)   (R_ALPHA(col) == 255)
00751 #define R_TRANSPARENT(col) (R_ALPHA(col) == 0)
00752     /*
00753      * A transparent white
00754      */
00755 #define R_TRANWHITE     (R_RGBA(255, 255, 255, 0))
00756 
00757 
00758 /* used in various devices */
00759 
00760 #define curDevice       Rf_curDevice
00761 #define killDevice      Rf_killDevice
00762 #define ndevNumber      Rf_ndevNumber
00763 #define NewFrameConfirm     Rf_NewFrameConfirm
00764 #define nextDevice      Rf_nextDevice
00765 #define NoDevices       Rf_NoDevices
00766 #define NumDevices      Rf_NumDevices
00767 #define prevDevice      Rf_prevDevice
00768 #define selectDevice        Rf_selectDevice
00769 #define AdobeSymbol2utf8    Rf_AdobeSymbol2utf8
00770 
00771 /* Properly declared version of devNumber */
00772 int ndevNumber(pDevDesc  dd);
00773 
00774 /* How many devices exist ? (>= 1) */
00775 int NumDevices(void);
00776 
00777 /* Check for an available device slot */
00778 void R_CheckDeviceAvailable(void);
00779 Rboolean R_CheckDeviceAvailableBool(void);
00780 
00781 /* Return the number of the current device. */
00782 int curDevice(void);
00783 
00784 /* Return the number of the next device. */
00785 int nextDevice(int from);
00786 
00787 /* Return the number of the previous device. */
00788 int prevDevice(int from);
00789 
00790 /* Make the specified device (specified by number) the current device */
00791 int selectDevice(int devNum);
00792 
00793 /* Kill device which is identified by number. */
00794 void killDevice(int devNum);
00795 
00796 int NoDevices(void); /* used in engine, graphics, plot, grid */
00797 
00798 void NewFrameConfirm(pDevDesc dd); /* used in graphics.c, grid */
00799 
00800 
00801 /* Graphics events: defined in gevents.c */
00802 
00803 /* These give the indices of some known keys */
00804 
00805 typedef enum {knUNKNOWN = -1,
00806               knLEFT = 0, knUP, knRIGHT, knDOWN,
00807               knF1, knF2, knF3, knF4, knF5, knF6, knF7, knF8, knF9, knF10,
00808               knF11, knF12,
00809               knPGUP, knPGDN, knEND, knHOME, knINS, knDEL} R_KeyName;
00810 
00811 /* These are the three possible mouse events */
00812 
00813 typedef enum {meMouseDown = 0,
00814           meMouseUp,
00815           meMouseMove} R_MouseEvent;
00816 
00817 #define leftButton   1
00818 #define middleButton 2
00819 #define rightButton  4
00820 
00821 #define doKeybd         Rf_doKeybd
00822 #define doMouseEvent        Rf_doMouseEvent
00823 
00824 void doMouseEvent(pDevDesc dd, R_MouseEvent event,
00825                   int buttons, double x, double y);
00826 void doKeybd(pDevDesc dd, R_KeyName rkey,
00827          const char *keyname);
00828 
00829 
00830 /* For use in third-party devices when setting up a device:
00831  * duplicates Defn.h which is used internally.
00832  * (Tested in devNull.c)
00833  */
00834 
00835 #ifndef BEGIN_SUSPEND_INTERRUPTS
00836 /* Macros for suspending interrupts */
00837 #define BEGIN_SUSPEND_INTERRUPTS do { \
00838     Rboolean __oldsusp__ = R_interrupts_suspended; \
00839     R_interrupts_suspended = TRUE;
00840 #define END_SUSPEND_INTERRUPTS R_interrupts_suspended = __oldsusp__; \
00841     if (R_interrupts_pending && ! R_interrupts_suspended) \
00842         Rf_onintr(); \
00843 } while(0)
00844     
00845 #include <R_ext/libextern.h>
00846 LibExtern Rboolean R_interrupts_suspended;    
00847 LibExtern int R_interrupts_pending;
00848 extern void Rf_onintr(void);
00849 LibExtern Rboolean mbcslocale;
00850 #endif
00851 
00852 /* Useful for devices: translates Adobe symbol encoding to UTF-8 */
00853 extern void *AdobeSymbol2utf8(char*out, const char *in, size_t nwork);
00854 /* Translates Unicode point to UTF-8 */
00855 extern size_t Rf_ucstoutf8(char *s, const unsigned int c);
00856 
00857 #ifdef __cplusplus
00858 }
00859 #endif
00860 
00861 #endif /* R_GRAPHICSDEVICE_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines