Пример #1
0
Rboolean newJavaGD_Open(NewDevDesc *dd, newJavaGDDesc *xd, const char *dsp, double w, double h)
{   
    if (initJavaGD(xd)) return FALSE;
    
    xd->fill = 0xffffffff; /* transparent, was R_RGB(255, 255, 255); */
    xd->col = R_RGB(0, 0, 0);
    xd->canvas = R_RGB(255, 255, 255);
    xd->windowWidth = w;
    xd->windowHeight = h;
    xd->holdlevel = 0;
        
    {
        JNIEnv *env = getJNIEnv();
        jmethodID mid;
        
        if(!env || !xd || !xd->talk) {
            gdWarning("gdOpen: env, xd or talk is null");
            return FALSE;
        }
        
        /* we're not using dsp atm! */
        mid = (*env)->GetMethodID(env, xd->talkClass, "gdOpen", "(DD)V");
        if (mid)
            (*env)->CallVoidMethod(env, xd->talk, mid, w, h);
        else {
            gdWarning("gdOpen: can't get mid");
			chkX(env);
            return FALSE;
        }
		chkX(env);
    }
    
    return TRUE;
}
Пример #2
0
void LayerDevice::ConfigureDevice()
{
    dd->deviceSpecific = (void *) lDesc;
    // Device functions
    dd->close = LayerClose;
    dd->activate = LayerActivate;
    dd->deactivate = LayerDeactivate;
    dd->size = LayerSize;
    dd->newPage = LayerNewPage;
    dd->clip = LayerClip;
    dd->strWidth = LayerStrWidth;
    dd->text = LayerText;
    dd->rect = LayerRect;
    dd->circle = LayerCircle;
    dd->line = LayerLine;
    dd->polyline = LayerPolyline;
    dd->polygon = LayerPolygon;
    dd->locator = LayerLocator;
    dd->mode = LayerMode;
    dd->metricInfo = LayerMetricInfo;
    // Initial graphical settings
    dd->startfont = 1;
    dd->startps = 10;
    dd->startcol = R_RGB(0, 0, 0);
    dd->startfill = R_TRANWHITE;
    dd->startlty = LTY_SOLID;
    dd->startgamma = 1;
    // Device physical characteristics
    dd->left = 0;
    dd->right = lDesc->GetWidthInPoints();
    dd->bottom = lDesc->GetHeightInPoints();
    dd->top = 0;
    dd->cra[0] = 10;
    dd->cra[1] = 12;
    dd->xCharOffset = 0.4900;
    dd->yCharOffset = 0.3333;
    dd->yLineBias = 0.1;
    dd->ipr[0] = 1.0 / pointsPerInch;
    dd->ipr[1] = 1.0 / pointsPerInch;
    // Device capabilities
    dd->canClip = TRUE;
    dd->canHAdj = 2;
    dd->canChangeGamma = FALSE;
    dd->displayListOn = TRUE;
}
Пример #3
0
static void 	Quartz_NewPage(R_GE_gcontext *gc,
			       NewDevDesc *dd)
{
    QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
    CGPoint origin = {0.0, 0.0};
    CGSize  size;
    CGRect area;

    size.width = xd->windowWidth;
    size.height = xd->windowHeight;

    area.origin = origin;
    area.size = size;

    Quartz_Clip(0,size.width, 0, size.height, dd);
    
    /*
     * Paul to Stefano:
     * Not sure what is intended here:  looks like you are
     * making sure that on a "new page" operation you clear 
     * the window -- filling the window with a "missing"
     * colour wouldn't do the job so you use "white".
     * We no longer deal with NA as a colour internally so
     * I have changed this as follows:
     * (i)  if gc->fill is not opaque, then fill with white 
     *      (to clear the window)
     * (ii) fill with gc->fill
     *      (to produce the specified "background" which may or
     *       may not be transparent)
     */
    if (!R_OPAQUE(gc->fill)) {
	unsigned int tempcol = gc->fill;
	gc->fill = R_RGB(255, 255, 255);
	Quartz_SetFill(gc->fill, gc->gamma, dd);
	CGContextFillRect( GetContext(xd), area);
	gc->fill = tempcol;
    }
      
    Quartz_SetFill(gc->fill, gc->gamma, dd);

    CGContextFillRect( GetContext(xd), area);
    CGContextFlush( GetContext(xd) );   /* we need to flash it just now */

}
Пример #4
0
/* #RRGGBB[AA] String to Internal Color Code */
static unsigned int rgb2col(const char *rgb)
{
    unsigned int r=0, g=0, b=0, a=0; /* -Wall */
    if(rgb[0] != '#')
	error(_("invalid RGB specification"));
    switch (strlen(rgb)) {
    case 9:
	a = 16 * hexdigit(rgb[7]) + hexdigit(rgb[8]);
    case 7:
	r = 16 * hexdigit(rgb[1]) + hexdigit(rgb[2]);
	g = 16 * hexdigit(rgb[3]) + hexdigit(rgb[4]);
	b = 16 * hexdigit(rgb[5]) + hexdigit(rgb[6]);
	break;
    default:
	error(_("invalid RGB specification"));
    }
    if (strlen(rgb) == 7)
	return R_RGB(r, g, b);
    else
	return R_RGBA(r, g, b, a);
}
Пример #5
0
static Rboolean newJavaGDDeviceDriver(NewDevDesc *dd, char *display,
		double width, double height, int sizeUnit,
		double xpi, double ypi, int canvas,
		double pointsize, double gamma)
{
	newJavaGDDesc *xd;
	
#ifdef JGD_DEBUG
  printf("TD: newJavaGDDeviceDriver(\"%s\", %f, %f, %f)\n", disp_name, width, height, pointsize);
#endif
	
	// allocate new device description
	if (!(xd = (newJavaGDDesc*) calloc(1, sizeof(newJavaGDDesc)))) {
		return FALSE;
	}
	// from here on, if we need to bail out with "error", then we must also free(xd).
	if (!createJavaGD(xd)) {
		free(xd);
		return FALSE;
	}
	
	initJavaGD(xd, &width, &height, &sizeUnit, &xpi, &ypi);
	
	xd->fill = 0xffffffff; /* transparent */
	xd->col = R_RGB(0, 0, 0);
	xd->canvas = canvas;
	
	/* Font will load at first use. */
	if (pointsize < 6 || pointsize > 24) pointsize = 12;
	xd->fontface = -1;
	xd->fontsize = -1;
	xd->basefontface = 1;
	xd->basefontsize = pointsize;
	
	setNewJavaGDDeviceData((NewDevDesc*)(dd), xd,
			width, height, gamma);
	
	return TRUE;
}
Пример #6
0
/* Function to setup device description data,
   like physical characteristics and plotting functions */
Rboolean swfSetup(pDevDesc dev, const char *filename,
    double width, double height,
    const int *bg, float frameRate, SEXP env)
{
    /* Create object to store swf device specific data  */
    pswfDesc swfInfo;
    if(!(swfInfo = (pswfDesc) calloc(1, sizeof(swfDesc))))
        return FALSE;
    
    /* Setup swfInfo data */
    swfSetupSWFInfo(swfInfo, filename, width, height, bg, frameRate, env);
    
    /* Comments coming form R_ext/GraphicsDevice.h */
    /********************************************************
     * Device physical characteristics
     ********************************************************/
    /*
     (0, 0) --------------> x   (width, 0)
       |
       |
       |
       |
       |
       v
       
       y
     
     (0, height)
    */
    /* width and height are specified by inches.
       Here we convert them to points. */
    dev->left = 0;                   /* left raster coordinate */
    dev->right = width * 72.0;       /* right raster coordinate */
    dev->bottom = height * 72.0;     /* bottom raster coordinate */
    dev->top = 0;                    /* top raster coordinate */
    
    /*
    dev->clipLeft;
    dev->clipRight;
    dev->clipBottom;
    dev->clipTop;
    */
    
    dev->xCharOffset = 0.4900;            /* x character addressing offset - unused */
    dev->yCharOffset = 0.3333;            /* y character addressing offset */
    dev->yLineBias = 0.2;                 /* 1/2 interline space as frac of line height */
    dev->ipr[0] = dev->ipr[1] = 1.0 / 72; /* Inches per raster; [0]=x, [1]=y */
    
    dev->cra[0] = 12 * 0.9;               /* Character size in rasters; [0]=x, [1]=y */
    dev->cra[1] = 12 * 1.2;
    
    /*
    dev->gamma;
    */

    /********************************************************
     * Device capabilities
     ********************************************************/
    dev->canClip = TRUE;             /* Device-level clipping */
    dev->canChangeGamma = FALSE;     /* can the gamma factor be modified? */
    dev->canHAdj = 0;                /* Can do at least some horiz adjust of text
                                        0 = none, 1 = {0,0.5,1}, 2 = [0,1] */
    
    /********************************************************
     * Device initial settings
     ********************************************************/
    dev->startps = 12;               /* initial pointsize for text */
    dev->startcol = R_RGB(0, 0, 0);  /* sets par("fg"), par("col") and gpar("col") */
    dev->startfill = R_RGB(bg[0], bg[1], bg[2]);
                                     /* sets par("bg") and gpar("fill") */
    dev->startlty = LTY_SOLID;       /* solid line */
    dev->startfont = 1;              /* plain text */
    dev->startgamma = 1;
    
    /********************************************************
     * Device specific information
     ********************************************************/
    dev->deviceSpecific = (void *) swfInfo;    /* pointer to device specific parameters */
    
    /********************************************************
     * Device display list
     ********************************************************/
    dev->displayListOn = FALSE;      /* toggle for initial display list status */
    
    /********************************************************
     * Event handling entries
     ********************************************************/
    dev->canGenMouseDown = FALSE;    /* can the device generate mousedown events */
    dev->canGenMouseMove = FALSE;    /* can the device generate mousemove events */
    dev->canGenMouseUp = FALSE;      /* can the device generate mouseup events */
    dev->canGenKeybd = FALSE;        /* can the device generate keyboard events */
    dev->gettingEvent = FALSE;       /* This is set while getGraphicsEvent
                                        is actively looking for events */
    
    /********************************************************
     * Device procedures.
     ********************************************************/
    dev->activate = swfActivate;
    dev->circle = swfCircle;
    dev->clip = swfClip;
    dev->close = swfClose;
    dev->deactivate = swfDeactivate;
    dev->locator = NULL;
    dev->line = swfLine;
    dev->metricInfo = swfMetricInfo;
    dev->mode = swfMode;
    dev->newPage = swfNewPage;
    dev->polygon = swfPolygon;
    dev->polyline = swfPolyline;
    dev->rect = swfRect;
    dev->path = NULL;
    dev->raster = NULL;
    dev->cap = NULL;
    dev->size = swfSize;
    dev->strWidth = swfStrWidth;
    dev->text = swfText;
    dev->onExit = NULL;
    dev->getEvent = NULL;
    dev->newFrameConfirm = NULL;
    dev->hasTextUTF8 = TRUE;
    dev->textUTF8 = swfTextUTF8;
    dev->strWidthUTF8 = swfStrWidthUTF8;
    dev->wantSymbolUTF8 = TRUE;
    dev->useRotatedTextInContour = TRUE;
    dev->eventEnv = NULL;
    dev->eventHelper = NULL;
    dev->holdflush = NULL;
    dev->haveTransparency = 2;       /* 1 = no, 2 = yes */
    dev->haveTransparentBg = 1;      /* 1 = no, 2 = fully, 3 = semi */
    dev->haveRaster = 1;             /* 1 = no, 2 = yes, 3 = except for missing values */
    dev->haveCapture = 1;            /* 1 = no, 2 = yes */
    dev->haveLocator = 1;            /* 1 = no, 2 = yes */
    
    return TRUE;
}
Пример #7
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));
}
Пример #8
0
static Rboolean RAPHAELDeviceDriver(pDevDesc dev, const char* filename, double* width,
		double* height, double* offx, double* offy, double ps, int nbplots,
		const char* fontname, int canvas_id, SEXP env) {

	DOCDesc *rd;
	rd = (DOCDesc *) malloc(sizeof(DOCDesc));

	FontInfo *fi = (FontInfo *) malloc(sizeof(FontInfo));
	fi->isinit=0;
	fi->fontsize=(int)ps;
	rd->fi = fi;

	ElementTracer *elt_tracer = (ElementTracer *) malloc(sizeof(ElementTracer));
	elt_tracer->on = 0;
	elt_tracer->isinit = 0;
	rd->elt_tracer = elt_tracer;

	rd->canvas_id = canvas_id;

	rd->filename = strdup(filename);
	rd->fontname = strdup(fontname);
	rd->id = 0;
	rd->pageNumber = 0;
	rd->offx = offx[0];
	rd->offy = offy[0];
	rd->extx = width[0];
	rd->exty = height[0];
	rd->maxplot = nbplots;
	rd->x = offx;
	rd->y = offy;
	rd->width = width;
	rd->height = height;
	rd->fontface = 1;
	rd->fontsize = (int) ps;
	rd->env=env;
	//
	//  Device functions
	//
	dev->deviceSpecific = rd;
	dev->activate = RAPHAEL_activate;
	dev->close = RAPHAEL_Close;
	dev->size = RAPHAEL_Size;
	dev->newPage = RAPHAEL_NewPage;
	dev->clip = RAPHAEL_Clip;
	dev->strWidth = RAPHAEL_StrWidth;
	dev->text = RAPHAEL_Text;
	dev->rect = RAPHAEL_Rect;
	dev->circle = RAPHAEL_Circle;
	dev->line = RAPHAEL_Line;
	dev->polyline = RAPHAEL_Polyline;
	dev->polygon = RAPHAEL_Polygon;
	dev->metricInfo = RAPHAEL_MetricInfo;
	dev->hasTextUTF8 = (Rboolean) FALSE;
	dev->wantSymbolUTF8 = (Rboolean) FALSE;
	dev->useRotatedTextInContour = (Rboolean) FALSE;
	/*
	 * Initial graphical settings
	 */
	dev->startfont = 1;
	dev->startps = ps;
	dev->startcol = R_RGB(0, 0, 0);
	dev->startfill = R_TRANWHITE;
	dev->startlty = LTY_SOLID;
	dev->startgamma = 1;


	/*
	 * Device physical characteristics
	 */

	dev->left = 0;
	dev->right = width[0];
	dev->bottom = height[0];
	dev->top = 0;

	dev->clipLeft = 0;
	dev->clipRight = width[0];
	dev->clipBottom = height[0];
	dev->clipTop = 0;

	rd->clippedx0 = dev->clipLeft;
	rd->clippedy0 = dev->clipTop;
	rd->clippedx1 = dev->clipRight;
	rd->clippedy1 = dev->clipBottom;

	dev->cra[0] = 0.9 * ps;
	dev->cra[1] = 1.2 * ps;
	dev->xCharOffset = 0.4900;
	dev->yCharOffset = 0.3333;
	//dev->yLineBias = 0.2;
	dev->ipr[0] = 1.0 / 72.2;
	dev->ipr[1] = 1.0 / 72.2;
	/*
	 * Device capabilities
	 */
	dev->canClip = (Rboolean) TRUE;
	dev->canHAdj = 2;//canHadj – integer: can the device do horizontal adjustment of text via the text callback, and if so, how precisely? 0 = no adjustment, 1 = {0, 0.5, 1} (left, centre, right justification) or 2 = continuously variable (in [0,1]) between left and right justification.
	dev->canChangeGamma = (Rboolean) FALSE;	//canChangeGamma – Rboolean: can the display gamma be adjusted? This is now ignored, as gamma support has been removed.
	dev->displayListOn = (Rboolean) FALSE;

	dev->haveTransparency = 2;
	dev->haveTransparentBg = 3;

	return (Rboolean) TRUE;
}
Пример #9
0
pDevDesc xlsx_driver_new(std::string filename, int bg, double width, double height,
                         double offx, double offy,
                        int pointsize,
                        Rcpp::List aliases,
                        bool editable, int id,
                        std::string raster_prefix,
                        int next_rels_id,
                        int standalone) {

  pDevDesc dd = (DevDesc*) calloc(1, sizeof(DevDesc));
  if (dd == NULL)
    return dd;

  dd->startfill = bg;
  dd->startcol = R_RGB(0, 0, 0);
  dd->startps = pointsize;
  dd->startlty = 0;
  dd->startfont = 1;
  dd->startgamma = 1;

  // Callbacks
  dd->activate = NULL;
  dd->deactivate = NULL;
  dd->close = xlsx_close;
  dd->clip = xlsx_clip;
  dd->size = xlsx_size;
  dd->newPage = xlsx_new_page;
  dd->line = xlsx_line;
  dd->text = xlsx_text;
  dd->strWidth = xlsx_strwidth;
  dd->rect = xlsx_rect;
  dd->circle = xlsx_circle;
  dd->polygon = xlsx_polygon;
  dd->polyline = xlsx_polyline;
  dd->path = NULL;
  dd->mode = NULL;
  dd->metricInfo = xlsx_metric_info;
  dd->cap = NULL;
  dd->raster = xlsx_raster;

  // UTF-8 support
  dd->wantSymbolUTF8 = (Rboolean) 1;
  dd->hasTextUTF8 = (Rboolean) 1;
  dd->textUTF8 = xlsx_text;
  dd->strWidthUTF8 = xlsx_strwidth;

  // Screen Dimensions in pts
  dd->left = 0;
  dd->top = 0;
  dd->right = width * 72;
  dd->bottom = height * 72;

  // Magic constants copied from other graphics devices
  // nominal character sizes in pts
  dd->cra[0] = 0.9 * pointsize;
  dd->cra[1] = 1.2 * pointsize;
  // character alignment offsets
  dd->xCharOffset = 0.4900;
  dd->yCharOffset = 0.3333;
  dd->yLineBias = 0.2;
  // inches per pt
  dd->ipr[0] = 1.0 / 72.0;
  dd->ipr[1] = 1.0 / 72.0;

  // Capabilities
  dd->canClip = TRUE;
  dd->canHAdj = 0;
  dd->canChangeGamma = FALSE;
  dd->displayListOn = FALSE;
  dd->haveTransparency = 2;
  dd->haveTransparentBg = 2;

  dd->deviceSpecific = new XLSX_dev(filename,
                                    aliases,
                                    editable, offx*72, offy*72, id,
    raster_prefix,
    next_rels_id, standalone,
    width * 72,
    height * 72
    );
  return dd;
}
Пример #10
0
static Rboolean nullDeviceDriver(pDevDesc dev) {
    dev->deviceSpecific = NULL;
    /*
     * Device functions
     */
    dev->close = NULL_Close;
    dev->activate = NULL_Activate;
    dev->deactivate = NULL_Deactivate;
    dev->size = NULL_Size;
    dev->newPage = NULL_NewPage;
    dev->clip = NULL_Clip;
    dev->strWidth = NULL_StrWidth;
    dev->text = NULL_Text;
    dev->rect = NULL_Rect;
    dev->circle = NULL_Circle;
    dev->line = NULL_Line;
    dev->polyline = NULL_Polyline;
    dev->polygon = NULL_Polygon;
    dev->locator = NULL_Locator;
    dev->mode = NULL_Mode;
    dev->metricInfo = NULL_MetricInfo;
    dev->hasTextUTF8 = FALSE;
    dev->useRotatedTextInContour = FALSE;
    /*
     * Initial graphical settings
     */
    dev->startfont = 1;
    dev->startps = 10;
    dev->startcol = R_RGB(0, 0, 0);
    dev->startfill = R_TRANWHITE;
    dev->startlty = LTY_SOLID;
    dev->startgamma = 1;
    /*
     * Start device
     */
    if(!NULL_Open(dev)) {
        return FALSE;
    }
    /*
     * Device physical characteristics
     */
    dev->left = 0;
    dev->right = 1000;
    dev->bottom = 0;
    dev->top = 1000;
    dev->cra[0] = 9;
    dev->cra[1] = 12;
    dev->xCharOffset = 0.4900;
    dev->yCharOffset = 0.3333;
    dev->yLineBias = 0.1;
    dev->ipr[0] = 1.0/72;
    dev->ipr[1] = 1.0/72;
    /*
     * Device capabilities
     */
    dev->canClip = TRUE;
    dev->canHAdj = 2;
    dev->canChangeGamma = FALSE;
    dev->displayListOn = FALSE;

    return TRUE;
}
Пример #11
0
static Rboolean	Quartz_Open(NewDevDesc *dd, QuartzDesc *xd, char *dsp,
		    double wid, double hgt, int bg)
{

	OSStatus	err;
	WindowRef 	devWindow =  NULL;
	Rect		devBounds, mainRect;
	Str255		Title;
	char		buffer[250];
	int 		devnum = devNumber((DevDesc *)dd);


    xd->windowWidth = wid*72;
    xd->windowHeight = hgt*72;
    xd->window = NULL;
    xd->context = NULL;
    xd->auxcontext = NULL;
	
	xd->bg = dd->startfill = bg; /* 0xffffffff; transparent */
    dd->startcol = R_RGB(0, 0, 0);
    /* Create a new window with the specified size */

	SetRect(&devBounds, 0, 0,  xd->windowWidth, xd->windowHeight ) ;
	
	err = CreateNewWindow( kDocumentWindowClass, kWindowStandardHandlerAttribute|kWindowVerticalZoomAttribute | kWindowCollapseBoxAttribute|kWindowResizableAttribute | kWindowCloseBoxAttribute ,
		& devBounds, & devWindow);
	SetWindowBounds(devWindow,  kWindowContentRgn, &devBounds); 
	mainRect = (*GetMainDevice()) -> gdRect;
    switch(xd->QuartzPos){
		case kQuartzTopRight: /* Top Right */
			RepositionWindow (devWindow,  NULL, kWindowCascadeOnMainScreen);
			GetWindowBounds(devWindow, kWindowStructureRgn, &devBounds);
			devBounds.left = mainRect.right - devBounds.right + 1;
			devBounds.right = mainRect.right;
			SetWindowBounds(devWindow, kWindowStructureRgn, &devBounds); 
		break;
	
		case kQuartzBottomRight: /* Bottom Right */
			GetWindowBounds(devWindow, kWindowStructureRgn, &devBounds);
			devBounds.left = mainRect.right - devBounds.right + 1;
			devBounds.right = mainRect.right;
			devBounds.top = mainRect.bottom - devBounds.bottom + 1;			
			devBounds.bottom = mainRect.bottom;
			SetWindowBounds(devWindow, kWindowStructureRgn, &devBounds); 
		break;
	
		case kQuartzBottomLeft: /* Bottom Left */
			GetWindowBounds(devWindow, kWindowStructureRgn, &devBounds);
			devBounds.top = mainRect.bottom - devBounds.bottom + 1;			
			devBounds.bottom = mainRect.bottom;
			SetWindowBounds(devWindow, kWindowStructureRgn, &devBounds); 
		break;
	
		case kQuartzCenter: /* Center */
			RepositionWindow (devWindow,  NULL, kWindowCenterOnMainScreen);
		break;
	
		case kQuartzTopLeft: /* TopLeft */
			RepositionWindow (devWindow,  NULL, kWindowCascadeOnMainScreen);
		break;
	
		default:
		break; 
	}

	
	
	sprintf(buffer,"Quartz (%d) - Active",devnum+1);
	CopyCStringToPascal(buffer,Title);
        SetWTitle(devWindow, Title);

	ShowWindow(devWindow);

	err = InstallWindowEventHandler( devWindow, NewEventHandlerUPP(QuartzEventHandler),
                                          GetEventTypeCount(QuartzEvents),
                                          QuartzEvents, (void *)devWindow, NULL);
                                          
    if(err != noErr)
     return(0);

    xd->window = devWindow;
    xd->color = xd->fill = R_TRANWHITE;
    xd->resize = false;
    xd->lineType = 0;
    xd->lineWidth = 1;
    return TRUE;
}
Пример #12
0
/* Device driver entry point */
Rboolean
RSceneDeviceDriver(pDevDesc dev,
		   double width, double height,
		   double ps,
		   RSceneDevice *qdev)
{
    // store a pointer to the device object (in Qt)
    dev->deviceSpecific = (void *) qdev;

    // pointsize?

    /*
     * Initial graphical settings
     */
    dev->startfont = 1;
    dev->startps = ps;
    dev->startcol = R_RGB(0, 0, 0);
    dev->startfill = R_TRANWHITE;
    dev->startlty = LTY_SOLID;
    dev->startgamma = 1;
    /*
     * Device physical characteristics
     */
    double DPI = 72;

    dev->left   = dev->clipLeft   = 0;
    dev->right  = dev->clipRight  = qdev->width();
    dev->bottom = dev->clipBottom = qdev->height();
    dev->top    = dev->clipTop    = 0;
    dev->cra[0] = 0.9 * ps;
    dev->cra[1] = 1.2 * ps;
    dev->xCharOffset = 0.4900;
    dev->yCharOffset = 0.3333;
    dev->yLineBias = 0.1;
    dev->ipr[0] = 1.0 / DPI;
    dev->ipr[1] = 1.0 / DPI;
    /*
     * Device capabilities
     */
    dev->canClip = FALSE; // can clip, but then selection becomes weird
    dev->canHAdj = 2;
    dev->canChangeGamma = FALSE;
    dev->displayListOn = TRUE;

    dev->hasTextUTF8 = TRUE;
    dev->textUTF8 = (void (*)()) QT_TextUTF8;
    dev->strWidthUTF8 = (double (*)()) QT_StrWidthUTF8;
    dev->wantSymbolUTF8 = TRUE;
    dev->useRotatedTextInContour = TRUE;

    /*
     * Mouse events
     */
//     dev->canGenMouseDown = TRUE;
//     dev->canGenMouseMove = TRUE;
//     dev->canGenMouseUp = TRUE; 
//     dev->canGenKeybd = TRUE;

    // gettingEvent; This is set while getGraphicsEvent is actively
    // looking for events

    /*
     * Device functions
     */
    dev->activate =    (void (*)()) QT_Activate;
    dev->circle =      (void (*)()) QT_Circle;
    dev->clip =        (void (*)()) QT_Clip;
    dev->close =       (void (*)()) QT_Close;
    dev->deactivate =  (void (*)()) QT_Deactivate;
    dev->locator = (Rboolean (*)()) QT_Locator;
    dev->line =        (void (*)()) QT_Line;
    dev->metricInfo =  (void (*)()) QT_MetricInfo;
    dev->mode =        (void (*)()) QT_Mode;
    dev->newPage =     (void (*)()) QT_NewPage;
    dev->polygon =     (void (*)()) QT_Polygon;
    dev->polyline =    (void (*)()) QT_Polyline;
    dev->rect =        (void (*)()) QT_Rect;
    dev->size =        (void (*)()) QT_Size;
    // dev->strWidth =  (double (*)()) QT_StrWidth;
    // dev->text =        (void (*)()) QT_Text;
    // dev->onexit =      (void (*)()) QT_OnExit; NULL is OK
    // dev->getEvent = SEXP (*getEvent)(SEXP, const char *);
    // dev->newFrameConfirm
    // dev->
    return TRUE;
}
Пример #13
0
SEXP read_png(SEXP sFn, SEXP sNative, SEXP sInfo) {
    SEXP res = R_NilValue, info_list = R_NilValue, info_tail = R_NilValue;
    const char *fn;
    char header[8];
    int native = asInteger(sNative), info = (asInteger(sInfo) == 1);
    FILE *f;
    read_job_t rj;
    png_structp png_ptr;
    png_infop info_ptr;
    
    if (TYPEOF(sFn) == RAWSXP) {
	rj.data = (char*) RAW(sFn);
	rj.len = LENGTH(sFn);
	rj.ptr = 0;
	rj.f = f = 0;
    } else {
	if (TYPEOF(sFn) != STRSXP || LENGTH(sFn) < 1) Rf_error("invalid filename");
	fn = CHAR(STRING_ELT(sFn, 0));
	f = fopen(fn, "rb");
	if (!f) Rf_error("unable to open %s", fn);
	if (fread(header, 1, 8, f) < 1 || png_sig_cmp((png_bytep) header, 0, 8)) {
	    fclose(f);
	    Rf_error("file is not in PNG format");
	}
	rj.f = f;
    }

    /* use our own error hanlding code and pass the fp so it can be closed on error */
    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)&rj, user_error_fn, user_warning_fn);
    if (!png_ptr) {
	if (f) fclose(f);
	Rf_error("unable to initialize libpng");
    }
    
    info_ptr = png_create_info_struct(png_ptr);
    if (!info_ptr) {
	if (f) fclose(f);
	png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
	Rf_error("unable to initialize libpng");
    }
    
    if (f) {
	png_init_io(png_ptr, f);
	png_set_sig_bytes(png_ptr, 8);
    } else
	png_set_read_fn(png_ptr, (png_voidp) &rj, user_read_data);

#define add_info(K, V) { info_tail = SETCDR(info_tail, CONS(V, R_NilValue)); SET_TAG(info_tail, install(K)); }

    /* png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_EXPAND, NULL); */
    png_read_info(png_ptr, info_ptr);
    {
	png_uint_32 width, height;
	png_bytepp row_pointers;
	char *img_memory;
	SEXP dim;
	int bit_depth, color_type, interlace_type, compression_type, filter_method, rowbytes;
	int need_swap = 0;
	png_get_IHDR(png_ptr, info_ptr, &width, &height,
		     &bit_depth, &color_type, &interlace_type,
		     &compression_type, &filter_method);
	rowbytes = png_get_rowbytes(png_ptr, info_ptr);
#if VERBOSE_INFO
	Rprintf("png: %d x %d [%d], %d bytes, 0x%x, %d, %d\n", (int) width, (int) height, bit_depth, rowbytes,
		color_type, interlace_type, compression_type, filter_method);
#endif

	if (info) {
	    SEXP dv;
	    double d;
	    png_uint_32 rx, ry;
	    int ut, num_text = 0;
	    png_textp text_ptr;

	    info_tail = info_list = PROTECT(CONS((dv = allocVector(INTSXP, 2)), R_NilValue));
	    INTEGER(dv)[0] = (int) width;
	    INTEGER(dv)[1] = (int) height;
	    SET_TAG(info_list, install("dim"));
	    add_info("bit.depth", ScalarInteger(bit_depth));
	    switch(color_type) {
	    case PNG_COLOR_TYPE_GRAY: add_info("color.type", mkString("gray")); break;
	    case PNG_COLOR_TYPE_GRAY_ALPHA: add_info("color.type", mkString("gray + alpha")); break;
	    case PNG_COLOR_TYPE_PALETTE: add_info("color.type", mkString("palette")); break;
	    case PNG_COLOR_TYPE_RGB: add_info("color.type", mkString("RGB")); break;
	    case PNG_COLOR_TYPE_RGB_ALPHA: add_info("color.type", mkString("RGBA")); break;
	    default: add_info("color.type", ScalarInteger(color_type));
	    }
	    if (png_get_gAMA(png_ptr, info_ptr, &d)) add_info("gamma", ScalarReal(d));
#ifdef PNG_pHYs_SUPPORTED
	    if (png_get_pHYs(png_ptr, info_ptr, &rx, &ry, &ut)) {
		if (ut == PNG_RESOLUTION_METER) {
		    dv = allocVector(REALSXP, 2);
		    REAL(dv)[0] = ((double)rx) / 39.37008;
		    REAL(dv)[1] = ((double)ry) / 39.37008;
		    add_info("dpi", dv);
		} else if (ut == PNG_RESOLUTION_UNKNOWN)
		    add_info("asp", ScalarReal(rx / ry));
	    }
	    if (png_get_text(png_ptr, info_ptr, &text_ptr, &num_text)) {
		SEXP txt_key, txt_val = PROTECT(allocVector(STRSXP, num_text));
		if (num_text) {
		    int i;
		    setAttrib(txt_val, R_NamesSymbol, txt_key = allocVector(STRSXP, num_text));
		    for (i = 0; i < num_text; i++) {
			SET_STRING_ELT(txt_val, i, text_ptr[i].text ? mkChar(text_ptr[i].text) : NA_STRING);
			SET_STRING_ELT(txt_key, i, text_ptr[i].key ? mkChar(text_ptr[i].key) : NA_STRING);
		    }
		}
		add_info("text", txt_val);
		UNPROTECT(1);
	    }
#endif
	}

	/* on little-endian machines it's all well, but on big-endian ones we'll have to swap */
#if ! defined (__BIG_ENDIAN__) && ! defined (__LITTLE_ENDIAN__)   /* old compiler so have to use run-time check */
	{
	    char bo[4] = { 1, 0, 0, 0 };
	    int bi;
	    memcpy(&bi, bo, 4);
	    if (bi != 1)
		need_swap = 1;
	}
#endif
#ifdef __BIG_ENDIAN__
	need_swap = 1;
#endif

	/*==== set any transforms that we desire: ====*/
	/* palette->RGB - no discussion there */
	if (color_type == PNG_COLOR_TYPE_PALETTE)
	    png_set_palette_to_rgb(png_ptr);
	/* expand gray scale to 8 bits */
	if (color_type == PNG_COLOR_TYPE_GRAY &&
	    bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
	/* this should not be necessary but it's in the docs to guarantee 8-bit */
	if (bit_depth < 8)
	    png_set_packing(png_ptr);
	/* convert tRNS chunk into alpha */
	if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
	    png_set_tRNS_to_alpha(png_ptr);
	/* native format doesn't allow for 16-bit so it needs to be truncated */
	if (bit_depth == 16 && native) {
	    Rf_warning("Image uses 16-bit channels but R native format only supports 8-bit, truncating LSB."); 
	    png_set_strip_16(png_ptr);
	}
	/* for native output we need to a) convert gray to RGB, b) add alpha */
	if (native) {
	    if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
		png_set_gray_to_rgb(png_ptr);
	    if (!(color_type & PNG_COLOR_MASK_ALPHA)) /* if there is no alpha, add it */
		png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER);
	}
#if 0 /* we use native (network) endianness since we read each byte anyway */
	/* on little-endian machines we need to swap 16-bit values - this is the inverse of need_swap as used for R! */
	if (!need_swap && bit_depth == 16)
	    png_set_swap(png_ptr);
#endif

	/* PNG wants up to call png_set_interlace_handling so it can get ready to de-interlace images */
	png_set_interlace_handling(png_ptr);

	/* all transformations are in place, so it's time to update the info structure so we can allocate stuff */
	png_read_update_info(png_ptr, info_ptr);

	/* re-read some important bits from the updated structure */
	rowbytes = png_get_rowbytes(png_ptr, info_ptr);
	bit_depth = png_get_bit_depth(png_ptr, info_ptr);
	color_type = png_get_color_type(png_ptr, info_ptr);

#if VERBOSE_INFO
	Rprintf("   -filter-> %d-bits, %d bytes, 0x%x\n", bit_depth, rowbytes, color_type);
#endif

	/* allocate data fro row pointers and the image using R's allocation */
	row_pointers = (png_bytepp) R_alloc(height, sizeof(png_bytep));
	img_memory = R_alloc(height, rowbytes);
	{ /* populate the row pointers */
	    char *i_ptr = img_memory;
	    int i;
	    for (i = 0; i < height; i++, i_ptr += rowbytes)
	      row_pointers[i] = (png_bytep) i_ptr;
	}
	
	/* do the reading work */
	png_read_image(png_ptr, row_pointers);
	
	if (f) {
	    rj.f = 0;
	    fclose(f);
	}

	/* native output - vector of integers */
	if (native) {
	    int pln = rowbytes / width;
	    if (pln < 1 || pln > 4) {
		png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
		Rf_error("native output for %d planes is not possible.", pln);
	    }

	    res = PROTECT(allocVector(INTSXP, width * height));
	    if (pln == 4) { /* 4 planes - efficient - just copy it all */
		int y, *idata = INTEGER(res);
		for (y = 0; y < height; idata += width, y++)
		    memcpy(idata, row_pointers[y], width * sizeof(int));

		if (need_swap) {
		    int *ide = idata;
		    idata = INTEGER(res);
		    for (; idata < ide; idata++)
			RX_swap32(*idata);
		}
	    } else if (pln == 3) { /* RGB */
		int x, y, *idata = INTEGER(res);
		for (y = 0; y < height; y++)
		    for (x = 0; x < rowbytes; x += 3)
			*(idata++) = R_RGB((unsigned int) row_pointers[y][x],
					   (unsigned int) row_pointers[y][x + 1],
					   (unsigned int) row_pointers[y][x + 2]);
	    } else if (pln == 2) { /* GA */
		int x, y, *idata = INTEGER(res);
		for (y = 0; y < height; y++)
		    for (x = 0; x < rowbytes; x += 2)
			*(idata++) = R_RGBA((unsigned int) row_pointers[y][x],
					    (unsigned int) row_pointers[y][x],
					    (unsigned int) row_pointers[y][x],
					    (unsigned int) row_pointers[y][x + 1]);
	    } else { /* gray */
		int x, y, *idata = INTEGER(res);
		for (y = 0; y < height; y++)
		    for (x = 0; x < rowbytes; x++)
			*(idata++) = R_RGB((unsigned int) row_pointers[y][x],
					   (unsigned int) row_pointers[y][x],
					   (unsigned int) row_pointers[y][x]);
	    }
	    dim = allocVector(INTSXP, 2);
	    INTEGER(dim)[0] = height;
	    INTEGER(dim)[1] = width;
	    setAttrib(res, R_DimSymbol, dim);
	    setAttrib(res, R_ClassSymbol, mkString("nativeRaster"));
	    setAttrib(res, install("channels"), ScalarInteger(pln));
	    UNPROTECT(1);
	} else {
	    int x, y, p, pln = rowbytes / width, pls = width * height;
	    double * data;
	    if (bit_depth == 16) {
		res = PROTECT(allocVector(REALSXP, (rowbytes * height) / 2));
		pln /= 2;
	    } else
		res = PROTECT(allocVector(REALSXP, rowbytes * height));

	    data = REAL(res);
	    if (bit_depth == 16)
		for(y = 0; y < height; y++)
		    for (x = 0; x < width; x++)
			for (p = 0; p < pln; p++)
			    data[y + x * height + p * pls] = ((double)(
								       (((unsigned int)(((unsigned char *)row_pointers[y])[2 * (x * pln + p)])) << 8) |
								        ((unsigned int)(((unsigned char *)row_pointers[y])[2 * (x * pln + p) + 1]))
								       )) / 65535.0;
	    else 
		for(y = 0; y < height; y++)
		    for (x = 0; x < width; x++)
			for (p = 0; p < pln; p++)
			    data[y + x * height + p * pls] = ((double)row_pointers[y][x * pln + p]) / 255.0;
	    dim = allocVector(INTSXP, (pln > 1) ? 3 : 2);
	    INTEGER(dim)[0] = height;
	    INTEGER(dim)[1] = width;
	    if (pln > 1)
		INTEGER(dim)[2] = pln;
	    setAttrib(res, R_DimSymbol, dim);
	    UNPROTECT(1);
	}
    }

    if (info) {
	PROTECT(res);
	setAttrib(res, install("info"), info_list);
	UNPROTECT(2);
    }
    
    png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);

    return res;
}
Пример #14
0
static Rboolean PPTXDeviceDriver(pDevDesc dev, const char* filename, double* width,
		double* height, double* offx, double* offy, double ps, int nbplots,
		const char* fontname, int id_init_value, int editable) {

	DOCDesc *rd;
	rd = (DOCDesc *) malloc(sizeof(DOCDesc));

	FontInfo *fi = (FontInfo *) malloc(sizeof(FontInfo));
	fi->isinit=0;
	fi->fontsize=(int) ps;
	rd->fi = fi;
	rd->filename = strdup(filename);
	rd->fontname = strdup(fontname);

	rd->id = id_init_value;
	rd->pageNumber = 0;
	rd->offx = offx[0];
	rd->offy = offy[0];
	rd->extx = width[0];
	rd->exty = height[0];
	rd->maxplot = nbplots;
	rd->x = offx;
	rd->y = offy;
	rd->width = width;
	rd->height = height;
	rd->fontface = 1;
	rd->fontsize = (int) ps;



//	rd->env=env;
	//
	//  Device functions
	//
	dev->deviceSpecific = rd;
	dev->activate = PPTX_activate;
	dev->close = PPTX_Close;
	dev->size = PPTX_Size;
	dev->newPage = PPTX_NewPage;
	dev->clip = PPTX_Clip;
	dev->strWidth = PPTX_StrWidth;
	dev->strWidthUTF8 = PPTX_StrWidthUTF8;
	dev->text = PPTX_Text;
	dev->textUTF8 = PPTX_TextUTF8;
	dev->rect = PPTX_Rect;
	dev->circle = PPTX_Circle;
	dev->line = PPTX_Line;
	dev->polyline = PPTX_Polyline;
	dev->polygon = PPTX_Polygon;
	dev->metricInfo = PPTX_MetricInfo;
	dev->hasTextUTF8 = (Rboolean) TRUE;
	dev->wantSymbolUTF8 = (Rboolean) TRUE;
	dev->useRotatedTextInContour = (Rboolean) FALSE;
	/*
	 * Initial graphical settings
	 */
	dev->startfont = 1;
	dev->startps = ps;
	dev->startcol = R_RGB(0, 0, 0);
	dev->startfill = R_TRANWHITE;
	dev->startlty = LTY_SOLID;
	dev->startgamma = 1;


	/*
	 * Device physical characteristics
	 */

	dev->left = 0;
	dev->right = width[0];
	dev->bottom = height[0];
	dev->top = 0;

	dev->clipLeft = 0;
	dev->clipRight = width[0];
	dev->clipBottom = height[0];
	dev->clipTop = 0;

	rd->clippedx0 = dev->clipLeft;
	rd->clippedy0 = dev->clipTop;
	rd->clippedx1 = dev->clipRight;
	rd->clippedy1 = dev->clipBottom;

	dev->cra[0] = 0.9 * ps;
	dev->cra[1] = 1.2 * ps;
	dev->xCharOffset = 0.4900;
	dev->yCharOffset = 0.3333;
	//dev->yLineBias = 0.2;
	dev->ipr[0] = 1.0 / 72.2;
	dev->ipr[1] = 1.0 / 72.2;
	/*
	 * Device capabilities
	 */
	dev->canClip = (Rboolean) TRUE;
	dev->canHAdj = 2;
	dev->canChangeGamma = (Rboolean) FALSE;
	dev->displayListOn = (Rboolean) FALSE;

	dev->haveTransparency = 2;
	dev->haveTransparentBg = 3;

	rd->editable = editable;


	return (Rboolean) TRUE;
}
Пример #15
0
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;
}
Пример #16
0
void configureDevice(pDevDesc dd, PyObject *self)
{
  /* setup structure */
  dd->deviceSpecific = (void *) self;
  dd->close = rpy_Close;
  dd->activate = rpy_Activate;
  dd->deactivate = rpy_Deactivate;
  dd->size = rpy_Size;
  dd->newPage = rpy_NewPage;
  dd->clip = rpy_Clip;
  /* Next two are unused */
  dd->strWidth = rpy_StrWidth;
  dd->text = rpy_Text;
  dd->rect = rpy_Rect;
  dd->circle = rpy_Circle;
  dd->line = rpy_Line;
  dd->polyline = rpy_PolyLine;
  dd->polygon = rpy_Polygon;
  dd->locator = rpy_Locator;
  dd->mode = rpy_Mode;
  dd->metricInfo = rpy_MetricInfo;
  dd->getEvent = rpy_GetEvent;
  /* FIXME: initialization from self.attribute */
  dd->hasTextUTF8 = TRUE; /*PyObject_GetAttrString(self, ); */
  dd->wantSymbolUTF8 = TRUE;   /* FIXME: initialization from self.attribute */
  dd->strWidthUTF8 = rpy_StrWidth;
  dd->textUTF8 = rpy_Text;

  dd->left = 0;   /* FIXME: initialization from self.attribute */
  dd->right = 100;   /* FIXME: initialization from self.attribute */
  dd->bottom = 100;   /* FIXME: initialization from self.attribute */
  dd->top = 0;   /* FIXME: initialization from self.attribute */

  /* starting parameters */
  dd->startfont = 1; 
  dd->startps = 12.0; /* ps *  */
  dd->startcol = R_RGB(0, 0, 0);
  dd->startfill = R_TRANWHITE;
  dd->startlty = LTY_SOLID; 
  dd->startgamma = 1;
        
  /* dd->cra[0] = 0.9 * 12; */
  /* dd->cra[1] = 1.2 * 12; */
        
  /* character addressing offsets */
  dd->xCharOffset = 0.4900;
  dd->yCharOffset = 0.3333;
  dd->yLineBias = 0.1;

  /* inches per raster unit */
  dd->ipr[0] = 1;
  dd->ipr[1] = 1;

  /* device capabilities */
  dd->canClip = FALSE;
  dd->canHAdj = 0; /* text adjustment 0, 1, or 2 */
  dd->canChangeGamma = FALSE; /* FIXME: what is this ? */

  dd->canGenMouseDown = TRUE; /* can the device generate mousedown events */
  dd->canGenMouseMove = TRUE; /* can the device generate mousemove events */
  dd->canGenMouseUp = TRUE;   /* can the device generate mouseup events */
  
  dd->canGenKeybd = TRUE;     /* can the device generate keyboard events */
    
  dd->displayListOn = TRUE;
        
  /* finish */
}
Пример #17
0
static Rboolean
BMDeviceDriver(pDevDesc dd, int kind, const char *filename,
	       int quality, int width, int height, int ps,
	       int bg, int res, int antialias, const char *family)
{
    pX11Desc xd;
    int res0 = (res > 0) ? res : 72;
    double dps = ps;

    /* allocate new device description */
    if (!(xd = (pX11Desc) calloc(1, sizeof(X11Desc)))) return FALSE;
    strcpy(xd->filename, filename);
    xd->quality = quality;
    xd->windowWidth = width;
    xd->windowHeight = height;
    strncpy(xd->basefontfamily, family, 500);
#ifdef HAVE_PANGOCAIRO
    /* Pango's default resolution is 96 dpi */
    dps *= res0/96.0;
#else
    dps *= res0/72.0;
#endif
    xd->pointsize = dps;
    xd->bg = bg;
    xd->res_dpi = res;
    switch(antialias){
    case 1: xd->antialias = CAIRO_ANTIALIAS_DEFAULT; break;
    case 2: xd->antialias = CAIRO_ANTIALIAS_NONE; break;
    case 3: xd->antialias = CAIRO_ANTIALIAS_GRAY; break;
    case 4: xd->antialias = CAIRO_ANTIALIAS_SUBPIXEL; break;
    default: xd->antialias = CAIRO_ANTIALIAS_DEFAULT;
    }
    xd->npages = 0;
    xd->col = R_RGB(0, 0, 0);
    xd->fill = xd->canvas = bg;
    xd->type = kind;
    xd->fp = NULL;
    xd->lty = -1;
    xd->lwd = -1;
    xd->lend = 0;
    xd->ljoin = 0;

    if (!BM_Open(dd, xd, width, height)) {
	free(xd);
	return FALSE;
    }
    if (xd->type == SVG || xd->type == PDF || xd->type == PS)
	xd->onefile = quality != 0;

    /* Set up Data Structures  */
    dd->size = cbm_Size;
    dd->clip = Cairo_Clip;
    dd->rect = Cairo_Rect;
    dd->circle = Cairo_Circle;
    dd->line = Cairo_Line;
    dd->polyline = Cairo_Polyline;
    dd->polygon = Cairo_Polygon;
    dd->path = Cairo_Path;
    dd->raster = Cairo_Raster;
#ifdef HAVE_PANGOCAIRO
    dd->metricInfo = PangoCairo_MetricInfo;
    dd->strWidth = dd->strWidthUTF8 = PangoCairo_StrWidth;
    dd->text = dd->textUTF8 = PangoCairo_Text;
#else
    dd->metricInfo = Cairo_MetricInfo;
    dd->strWidth = dd->strWidthUTF8 = Cairo_StrWidth;
    dd->text = dd->textUTF8 = Cairo_Text;
#endif
    dd->hasTextUTF8 = TRUE;
#if defined(Win32) && !defined(USE_FC)
    dd->wantSymbolUTF8 = NA_LOGICAL;
#else
    dd->wantSymbolUTF8 = TRUE;
#endif
    dd->useRotatedTextInContour = FALSE;

    dd->haveTransparency = 2;
    dd->haveRaster = 2;
    switch(xd->type) {
    case PDF:
    case SVG:
    case PNG:
    case PNGdirect:
	dd->haveTransparentBg = 3;
	break;
    case PS:
	dd->haveTransparentBg = 2;
	dd->haveRaster = 3; /* ?? */
	break;
    default: /* TIFF, BMP */
	dd->haveTransparency = 1;
    }

    dd->newPage = BM_NewPage;
    dd->close = BM_Close;

    dd->left = 0;
    dd->right = width;
    dd->top = 0;
    dd->bottom = height;
    /* rescale points to pixels */
    dd->cra[0] = 0.9 * ps * res0/72.0;
    dd->cra[1] = 1.2 * ps * res0/72.0;
    dd->startps = ps;
    xd->fontscale = dps/ps;
    dd->ipr[0] = dd->ipr[1] = 1.0/res0;
    xd->lwdscale = res0/96.0;
    dd->xCharOffset = 0.4900;
    dd->yCharOffset = 0.3333;
    dd->yLineBias = 0.2;
    dd->canClip= TRUE;
    dd->canHAdj = 2;
    dd->canChangeGamma = FALSE;
    dd->startcol = xd->col;
    dd->startfill = xd->fill;
    dd->startlty = LTY_SOLID;
    dd->startfont = 1;
    dd->displayListOn = FALSE;
    dd->deviceSpecific = (void *) xd;

    return TRUE;
}