Exemplo n.º 1
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));
}
Exemplo n.º 2
0
Arquivo: canvas.c Projeto: cran/canvas
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;
}
Exemplo n.º 3
0
Arquivo: par.c Projeto: Vladimir84/rcc
 *	"mai", "mar", "mex",
 *	"mfrow", "mfcol", "mfg",
 *	"new",
 *	"oma", "omd", "omi",
 *	"pin", "plt", "ps", "pty"
 *	"usr",
 *	"xlog", "ylog"
 */
    double x;
    int ix = 0;

#include "par-common.c"
/*	  ------------
 *--- now, these are *different* from  "Specify2() use" : */
    else if (streql(what, "bg")) {
	lengthCheck(what, value, 1, call);	ix = RGBpar(value, 0);
	/*	naIntCheck(ix, what); */
	R_DEV__(bg) = ix;
	R_DEV__(new) = FALSE;
    }
    else if (streql(what, "cex")) {
	lengthCheck(what, value, 1, call);	x = asReal(value);
	posRealCheck(x, what);
	R_DEV__(cex) = 1.0; /* ! (highlevel par, i.e.  Specify2(), set x ! */
	R_DEV__(cexbase) = x;
    }

    else if (streql(what, "fg")) {
	/* par(fg=) sets BOTH "fg" and "col" */
	lengthCheck(what, value, 1, call);	ix = RGBpar(value, 0);
	/*	naIntCheck(ix, what); */
Exemplo n.º 4
0
/*
   cairo(filename, type, width, height, pointsize, bg, res, antialias, 
         quality, family)
*/
SEXP in_Cairo(SEXP args)
{
    pGEDevDesc gdd;
    SEXP sc;
    const char *filename, *family;
    int type, quality, width, height, pointsize, bgcolor, res, antialias;
    const void *vmax = vmaxget();

    args = CDR(args); /* skip entry point name */
    if (!isString(CAR(args)) || LENGTH(CAR(args)) < 1)
	error(_("invalid '%s' argument"), "filename");
    filename = translateChar(STRING_ELT(CAR(args), 0));
    args = CDR(args);
    type = asInteger(CAR(args));
    if(type == NA_INTEGER || type <= 0)
	error(_("invalid '%s' argument"), "type");
    args = CDR(args);
    width = asInteger(CAR(args));
    if(width == NA_INTEGER || width <= 0)
	error(_("invalid '%s' argument"), "width");
    args = CDR(args);
    height = asInteger(CAR(args));
    if(height == NA_INTEGER || height <= 0)
	error(_("invalid '%s' argument"), "height");
    args = CDR(args);
    pointsize = asInteger(CAR(args));
    if(pointsize == NA_INTEGER || pointsize <= 0)
	error(_("invalid '%s' argument"), "pointsize");
    args = CDR(args);
    sc = CAR(args);
    if (!isString(sc) && !isInteger(sc) && !isLogical(sc) && !isReal(sc))
	error(_("invalid '%s' value"), "bg");
    bgcolor = RGBpar(sc, 0);
    args = CDR(args);
    res = asInteger(CAR(args));
    args = CDR(args);
    antialias = asInteger(CAR(args));
    if(antialias == NA_INTEGER)
	error(_("invalid '%s' argument"), "antialias");
    args = CDR(args);
    quality = asInteger(CAR(args));
    if(quality == NA_INTEGER || quality < 0 || quality > 100)
	error(_("invalid '%s' argument"), "quality");
    args = CDR(args);
    if (!isString(CAR(args)) || LENGTH(CAR(args)) < 1)
	error(_("invalid '%s' argument"), "family");
    family = translateChar(STRING_ELT(CAR(args), 0));

    R_GE_checkVersionOrDie(R_GE_version);
    R_CheckDeviceAvailable();
    BEGIN_SUSPEND_INTERRUPTS {
	pDevDesc dev;
	/* Allocate and initialize the device driver data */
	if (!(dev = (pDevDesc) calloc(1, sizeof(DevDesc)))) return 0;
	if (!BMDeviceDriver(dev, devtable[type].gtype, filename, quality,
			    width, height, pointsize,
			    bgcolor, res, antialias, family)) {
	    free(dev);
	    error(_("unable to start device '%s'"), devtable[type].name);
	}
	gdd = GEcreateDevDesc(dev);
	GEaddDevice2f(gdd, devtable[type].name, filename);
    } END_SUSPEND_INTERRUPTS;

    vmaxset(vmax);
    return R_NilValue;
}