// [[Rcpp::export]] bool XLSX_(std::string file, std::string bg_, double width, double height, double offx, double offy, int pointsize, Rcpp::List aliases, bool editable, int id, std::string raster_prefix, int last_rel_id, int standalone) { int bg = R_GE_str2col(bg_.c_str()); R_GE_checkVersionOrDie(R_GE_version); R_CheckDeviceAvailable(); BEGIN_SUSPEND_INTERRUPTS { pDevDesc dev = xlsx_driver_new(file, bg, width, height, offx, offy, pointsize, aliases, editable, id, raster_prefix, last_rel_id, standalone); if (dev == NULL) Rcpp::stop("Failed to start xlsx device"); pGEDevDesc dd = GEcreateDevDesc(dev); GEaddDevice2(dd, "xlsx_device"); GEinitDisplayList(dd); } END_SUSPEND_INTERRUPTS; return true; }
SEXP devcontrol(SEXP args) { int listFlag; pGEDevDesc gdd = GEcurrentDevice(); args = CDR(args); listFlag = asLogical(CAR(args)); if(listFlag == NA_LOGICAL) error(_("invalid argument")); GEinitDisplayList(gdd); gdd->displayListOn = listFlag ? TRUE: FALSE; return ScalarLogical(listFlag); }
// [[Rcpp::export]] bool devSVG_(std::string file, std::string bg_, int width, int height, int pointsize, bool standalone) { int bg = R_GE_str2col(bg_.c_str()); R_GE_checkVersionOrDie(R_GE_version); R_CheckDeviceAvailable(); BEGIN_SUSPEND_INTERRUPTS { pDevDesc dev = svg_driver_new(file, bg, width, height, pointsize, standalone); if (dev == NULL) Rcpp::stop("Failed to start SVG device"); pGEDevDesc dd = GEcreateDevDesc(dev); GEaddDevice2(dd, "devSVG"); GEinitDisplayList(dd); } END_SUSPEND_INTERRUPTS; return true; }
static int GrDev_init(PyObject *self, PyObject *args, PyObject *kwds) { #ifdef RPY_DEBUG_GRDEV printf("FIXME: Initializing GrDev\n"); #endif if (!rpy2_isinitialized()) { PyErr_Format(PyExc_RuntimeError, "R must be initialized before instances of GraphicalDevice can be created."); return -1; } if (R_CheckDeviceAvailableBool() != TRUE) { PyErr_Format(PyExc_RuntimeError, "Too many open R devices."); return -1; } pDevDesc dev = ((PyGrDevObject *)self)->grdev; configureDevice(dev, self); pGEDevDesc gdd = GEcreateDevDesc(dev); #if (PY_VERSION_HEX < 0x03010000) GEaddDevice2(gdd, self->ob_type->tp_name); #else GEaddDevice2(gdd, Py_TYPE(self)->tp_name); #endif GEinitDisplayList(gdd); /* FIXME: protect device number ? */ /* allocate memory for the pDevDesc structure ? */ /* pDevDesc grdev = malloc(); */ /* FIXME: handle allocation error */ /* self->grdev = grdev; */ return 0; }
SEXP MingSWFNew(SEXP file, SEXP height, SEXP width, SEXP scale, SEXP version, SEXP bg, SEXP fonts, SEXP initAS, SEXP labelMethod){ int bgcolor = RGBpar(bg,0); /* R Graphics Device: in GraphicsDevice.h */ pDevDesc RGD; /* R Graphics Engine: in GraphicsEngine.h */ pGEDevDesc RGE; /* Ming Graphics Device */ MingSWFDesc *MGD; if (!(RGD = (pDevDesc)calloc(1, sizeof(NewDevDesc)))) return R_NilValue; if (!(MGD = (MingSWFDesc *)calloc(1, sizeof(MingSWFDesc)))){ free(RGD); error("unable to start device mingswf"); return R_NilValue; } MGD->version = asInteger(version); Ming_setScale(asInteger(scale));/* default for library is 20 */ MGD->movie = newSWFMovieWithVersion(MGD->version); MGD->file=(char *)CHAR(STRING_ELT(file,0)); /* Initialize SWF file */ SWFMovie_setDimension(MGD->movie,asReal(width),asReal(height)); SWFMovie_setBackground(MGD->movie, REDC(bgcolor), GREENC(bgcolor), BLUEC(bgcolor)); SWFMovie_setRate(MGD->movie, 1.0); SWFMovie_setNumberOfFrames(MGD->movie, 1); SWFMovie_add(MGD->movie,newSWFInitAction(newSWFAction( "_root.createEmptyMovieClip('popup',65534);" "_root.popup._visible = false;" "_root.popup.createTextField('Label',65535,0,0,0,0);" "_root.popup.Label.multiline = true;" "_root.popup.Label.html = true;" "_root.movePopUp = function (){" " if (_root._xmouse <= _root.popup.Label._width+20){" " _root.popup._x = _root._xmouse+20;" " } else {" " _root.popup._x = _root._xmouse-_root.popup.Label._width-10;" " }" " if (_root._ymouse <= _root.popup.Label._height+20){" " _root.popup._y = _root._ymouse+15;" " } else {" " _root.popup._y = _root._ymouse-_root.popup.Label._height-10;" " }" " updateAfterEvent();" "};" "_root.showPopUp = function(obj){" " _root.popup.Label.htmlText = obj.Label;" " obj.oldAlpha = obj._alpha;" " obj._alpha = 50;" " _root.popup.Label.autoSize = true;" " _root.popup.lineStyle(20,0xc2c2c2);" " _root.popup.beginFill(0xc2c2c2);" " _root.popup.moveTo(0,0);" " _root.popup.lineTo(_root.popup.Label._width-5,0);" " _root.popup.lineTo(_root.popup.Label._width-5,_root.popup.Label._height-5);" " _root.popup.lineTo(0,_root.popup.Label._height-5);" " _root.popup.lineTo(0,0);" " _root.popup._visible = true;" " obj.onMouseMove = _root.movePopUp;" " _root.movePopUp();" "};" "_root.hidePopUp = function(obj){" " obj._alpha = obj.oldAlpha;" " delete obj.onMouseMove;" " _root.popup.clear();" " _root.popup._visible = false;" "};" ))); RGD->deviceSpecific = (void *) MGD; /* Callbacks */ RGD->close = MingSWFClose; RGD->activate = MingSWFActivate; RGD->deactivate = MingSWFDeactivate; RGD->size = MingSWFSize; RGD->newPage = MingSWFNewPage; RGD->clip = MingSWFClip; RGD->strWidth = MingSWFStrWidth; RGD->text = MingSWFText; RGD->rect = MingSWFRect; RGD->circle = MingSWFCircle; RGD->line = MingSWFLine; RGD->polyline = MingSWFPolyline; RGD->polygon = MingSWFPolygon; RGD->locator = MingSWFLocator; RGD->mode = MingSWFMode; RGD->metricInfo = MingSWFMetricInfo; RGD->hasTextUTF8 = TRUE; RGD->strWidthUTF8 = MingSWFStrWidth; RGD->textUTF8 = MingSWFText; RGD->wantSymbolUTF8 = TRUE; /* Initialise RGD */ RGD->left = RGD->clipLeft = 0; RGD->top = RGD->clipTop = 0; RGD->right = RGD->clipRight = asReal(width); RGD->bottom = RGD->clipBottom = asReal(height); RGD->xCharOffset = 0.4900; RGD->yCharOffset = 0.3333; RGD->yLineBias = 0.1; RGD->ipr[0] = 1.0/72.0; RGD->ipr[1] = 1.0/72.0; RGD->cra[0] = 0.9 * 12; RGD->cra[1] = 1.2 * 12; RGD->gamma = 1.0; RGD->canClip = FALSE; RGD->canChangeGamma = FALSE; RGD->canHAdj = 2; RGD->startps = 12.0; RGD->startcol = R_RGB(0,0,0); RGD->startfill = 0xffffffff; RGD->startlty = LTY_SOLID; RGD->startfont = 1; RGD->startgamma = RGD->gamma; RGD->displayListOn = TRUE; /* Add to the device list */ RGE = GEcreateDevDesc(RGD); MGD->RGE = RGE; GEaddDevice(RGE); GEinitDisplayList(RGE); return ScalarInteger(1 + GEdeviceNumber(RGE)); }
/* convenience wrapper */ void GEaddDevice2(pGEDevDesc gdd, const char *name) { gsetVar(R_DeviceSymbol, mkString(name), R_BaseEnv); GEaddDevice(gdd); GEinitDisplayList(gdd); }
SEXP canvas_new_device(SEXP args) { /* R Graphics Device: in GraphicsDevice.h */ pDevDesc RGD; /* R Graphics Engine: in GraphicsEngine.h */ pGEDevDesc RGE; /* canvas Graphics Device */ canvasDesc *cGD; FILE *fp = NULL; int width, height, bgcolor; SEXP v; args=CDR(args); v=CAR(args); args=CDR(args); if (isString(v)){ PROTECT(v); fp = fopen(CHAR(STRING_ELT(v,0)),"w"); UNPROTECT(1); if (fp == NULL) error("could not open file"); } else { error("file must be a filename"); } v=CAR(args); args=CDR(args); if (!isNumeric(v)) {fclose(fp); error("`width' must be a number");} width=asInteger(v); v=CAR(args); args=CDR(args); if (!isNumeric(v)) {fclose(fp); error("`height' must be a number");} height=asInteger(v); v=CAR(args); args=CDR(args); if (!isString(v) && !isInteger(v) && !isLogical(v) && !isReal(v)) error("invalid color specification for `bg'"); bgcolor = RGBpar(v, 0); #ifdef CANVASDEBUG Rprintf("canvas_new_device(width=%d,height=%d,fd=%x)\n", width, height, fp); #endif R_CheckDeviceAvailable(); if (!(RGD = (pDevDesc)calloc(1, sizeof(NewDevDesc)))){ fclose(fp); error("calloc failed for canvas device"); } if (!(cGD = (canvasDesc *)calloc(1, sizeof(canvasDesc)))){ free(RGD); fclose(fp); error("calloc failed for canvas device"); } cGD->fp = fp; RGD->deviceSpecific = (void *) cGD; /* Callbacks */ RGD->close = canvasClose; RGD->activate = canvasActivate; RGD->deactivate = canvasDeactivate; RGD->size = canvasSize; RGD->newPage = canvasNewPage; RGD->clip = canvasClip; RGD->strWidth = canvasStrWidth; RGD->text = canvasText; RGD->rect = canvasRect; RGD->circle = canvasCircle; RGD->line = canvasLine; RGD->polyline = canvasPolyline; RGD->polygon = canvasPolygon; RGD->locator = canvasLocator; RGD->mode = canvasMode; RGD->metricInfo = canvasMetricInfo; RGD->hasTextUTF8 = TRUE; RGD->strWidthUTF8 = canvasStrWidth; RGD->textUTF8 = canvasText; RGD->wantSymbolUTF8 = TRUE; /* Initialise RGD */ RGD->left = RGD->clipLeft = 0; RGD->top = RGD->clipTop = 0; RGD->right = RGD->clipRight = width; RGD->bottom = RGD->clipBottom = height; RGD->xCharOffset = 0.4900; RGD->yCharOffset = 0.3333; RGD->yLineBias = 0.1; RGD->ipr[0] = 1.0/72.0; RGD->ipr[1] = 1.0/72.0; RGD->cra[0] = 0.9 * 10; RGD->cra[1] = 1.2 * 10; RGD->gamma = 1.0; RGD->canClip = FALSE; RGD->canChangeGamma = FALSE; RGD->canHAdj = 2; RGD->startps = 10.0; RGD->startcol = R_RGB(0,0,0); RGD->startfill = bgcolor; RGD->startlty = LTY_SOLID; RGD->startfont = 1; RGD->startgamma = RGD->gamma; RGD->displayListOn = FALSE; /* Add to the device list */ RGE = GEcreateDevDesc(RGD); cGD->RGE = RGE; GEaddDevice(RGE); GEinitDisplayList(RGE); /*return ScalarInteger(1 + GEdeviceNumber(RGE));*/ return R_NilValue; }
SEXP Quartz(SEXP args) { NewDevDesc *dev = NULL; GEDevDesc *dd; char *display, *vmax, *family=NULL; char fontfamily[255]; double height, width, ps; Rboolean antialias, autorefresh; SInt32 macVer; int quartzpos = 1; vmax = vmaxget(); args = CDR(args); /* skip entry point name */ display = CHAR(asChar(CAR(args))); args = CDR(args); width = asReal(CAR(args)); args = CDR(args); height = asReal(CAR(args)); args = CDR(args); if (width <= 0 || height <= 0) error(_("invalid width or height in quartz")); ps = asReal(CAR(args)); args = CDR(args); family = CHAR(asChar(CAR(args))); args = CDR(args); antialias = asLogical(CAR(args)); args = CDR(args); autorefresh = asLogical(CAR(args)); if(Gestalt(gestaltSystemVersion, &macVer) == noErr) if (macVer >= 0x1030) WeAreOnPanther = true; else WeAreOnPanther = false; R_CheckDeviceAvailable(); /* Allocate and initialize the device driver data */ BEGIN_SUSPEND_INTERRUPTS { if (!(dev = (NewDevDesc *) calloc(1, sizeof(NewDevDesc)))) return 0; /* Do this for early redraw attempts */ dev->displayList = R_NilValue; /* Make sure that this is initialised before a GC can occur. * This (and displayList) get protected during GC */ dev->savedSnapshot = R_NilValue; strcpy(fontfamily, family); #ifdef HAVE_AQUA if(useaqua) GetQuartzParameters(&width, &height, &ps, fontfamily, &antialias, &autorefresh, &quartzpos); #endif if (!QuartzDeviceDriver((DevDesc *)dev, display, width, height, ps, fontfamily, antialias, autorefresh, quartzpos, 0xffffffff)) { free(dev); error(_("unable to start device Quartz")); } gsetVar(install(".Device"), mkString("quartz"), R_NilValue); dd = GEcreateDevDesc(dev); addDevice((DevDesc*)dd); GEinitDisplayList(dd); } END_SUSPEND_INTERRUPTS; vmaxset(vmax); return R_NilValue; }