示例#1
0
void RAPHAEL_SetFontSpec(pDevDesc dev, R_GE_gcontext *gc, int idx) {
	DOCDesc *pd = (DOCDesc *) dev->deviceSpecific;
	char *saved_locale;
	saved_locale = setlocale(LC_NUMERIC, "C");

	float alpha =  R_ALPHA(gc->col)/255.0;
	double fontsize = getFontSize(gc->cex, gc->ps, gc->lineheight);


	if ( gc->cex > 0.0 && alpha > 0 ) {
		fprintf(pd->dmlFilePointer, "elt_%d.attr({", idx);
		fprintf(pd->dmlFilePointer, "'fill': \"#%s\"", RGBHexValue(gc->col) );
		fprintf(pd->dmlFilePointer, ", 'fill-opacity': \"%.3f\"", alpha );
		fprintf(pd->dmlFilePointer, ", 'font-family': \"%s\"", pd->fi->fontname );
		fprintf(pd->dmlFilePointer, ", 'font-size': \"%.0f\"", fontsize );
		if (gc->fontface == 2) {
			fputs(", 'font-weight': \"bold\"", pd->dmlFilePointer );
		} else if (gc->fontface == 3) {
			fputs(", 'font-style':\"italic\"", pd->dmlFilePointer );
		} else if (gc->fontface == 4) {
			fputs(", 'font-weight': \"bold\", 'font-style':\"italic\"", pd->dmlFilePointer );
		}
		fputs("});\n", pd->dmlFilePointer );


	}

	setlocale(LC_NUMERIC, saved_locale);

}
示例#2
0
void RAPHAEL_SetLineSpec(pDevDesc dev, R_GE_gcontext *gc, int idx) {
	DOCDesc *pd = (DOCDesc *) dev->deviceSpecific;
	char *saved_locale;
	saved_locale = setlocale(LC_NUMERIC, "C");

	float alpha =  R_ALPHA(gc->col)/255.0;

	fprintf(pd->dmlFilePointer, "elt_%d.attr({", idx);

	if (gc->lty > -1 && gc->lwd > 0.0 && alpha > 0) {
		fprintf(pd->dmlFilePointer, "'stroke': \"#%s\"", RGBHexValue(gc->col) );
		fprintf(pd->dmlFilePointer, ", 'stroke-opacity': \"%.3f\"", alpha );

		fprintf(pd->dmlFilePointer, ", 'stroke-width': %.3f", gc->lwd );

		switch (gc->lty) {
		case LTY_BLANK:
			break;
		case LTY_SOLID:
			break;
		case LTY_DOTTED:
			fputs(", 'stroke-dasharray': \".\"", pd->dmlFilePointer );
			break;
		case LTY_DASHED:
			fputs(", 'stroke-dasharray': \"-\"", pd->dmlFilePointer );
			break;
		case LTY_LONGDASH:
			fputs(", 'stroke-dasharray': \"--\"", pd->dmlFilePointer );
			break;
		case LTY_DOTDASH:
			fputs(", 'stroke-dasharray': \"-.\"", pd->dmlFilePointer );
			break;
		case LTY_TWODASH:
			fputs(", 'stroke-dasharray': \"--\"", pd->dmlFilePointer );
			break;
		default:
			break;
		}

		switch (gc->ljoin) {
		case GE_ROUND_JOIN: //round
			fputs(", 'stroke-linejoin': \"round\"", pd->dmlFilePointer );
			break;
		case GE_MITRE_JOIN: //mitre
			fputs(", 'stroke-linejoin': \"miter\"", pd->dmlFilePointer );
			break;
		case GE_BEVEL_JOIN: //bevel
			fputs(", 'stroke-linejoin': \"bevel\"", pd->dmlFilePointer );
			break;
		default:
			fputs(", 'stroke-linejoin': \"round\"", pd->dmlFilePointer );
			break;
		}
	} else {
		fputs("'stroke-width': 0", pd->dmlFilePointer );
	}
	fputs("});\n", pd->dmlFilePointer );
	setlocale(LC_NUMERIC, saved_locale);

}
示例#3
0
文件: colors.c 项目: Vladimir84/rcc
SEXP do_col2RGB(SEXP call, SEXP op, SEXP args, SEXP env)
{
/* colorname, "#rrggbb" or "col.number" to (r,g,b) conversion */
    SEXP colors, ans, names, dmns;
    unsigned int col;
    int n, i, i4;

    checkArity(op, args);

    PROTECT(colors = coerceVector(CAR(args),STRSXP));
    n = LENGTH(colors);
    PROTECT(ans = allocMatrix(INTSXP, 4, n));
    PROTECT(dmns = allocVector(VECSXP, 2));

    PROTECT(names = allocVector(STRSXP, 4));
    SET_STRING_ELT(names, 0, mkChar("red"));
    SET_STRING_ELT(names, 1, mkChar("green"));
    SET_STRING_ELT(names, 2, mkChar("blue"));
    SET_STRING_ELT(names, 3, mkChar("alpha"));
    SET_VECTOR_ELT(dmns, 0, names);
    UNPROTECT(1);/*names*/
    if ((names = getAttrib(colors, R_NamesSymbol)) != R_NilValue)
	SET_VECTOR_ELT(dmns, 1, names);
    setAttrib(ans, R_DimNamesSymbol, dmns);
    for(i = i4 = 0; i < n; i++, i4 += 4) {
	col = str2col(CHAR(STRING_ELT(colors, i)));
	INTEGER(ans)[i4 +0] = R_RED(col);
	INTEGER(ans)[i4 +1] = R_GREEN(col);
	INTEGER(ans)[i4 +2] = R_BLUE(col);
	INTEGER(ans)[i4 +3] = R_ALPHA(col);
    }
    UNPROTECT(3);
    return ans;
}
示例#4
0
static void SWF_SetLineStyle(SWFShape shape, const pGEcontext plotParams, 
	swfDevDesc *swfInfo ){
	
	byte red = R_RED(plotParams->col);
	byte green = R_GREEN(plotParams->col);
	byte blue = R_BLUE(plotParams->col);
	byte alpha =  R_ALPHA(plotParams->col);
	if( swfInfo->debug == TRUE ){
		fprintf(swfInfo->logFile,"\tLineStyle: Red=%d, ",red);
		fprintf(swfInfo->logFile,"Green=%d, ",green);
		fprintf(swfInfo->logFile,"Blue=%d, ",blue);
		fprintf(swfInfo->logFile,"Alpha=%d\n",alpha);
		fflush(swfInfo->logFile);
	}
	
	//FIXME: Honor all the line parameters such as 
	//lty, lend, ljoin 
	SWFShape_setLine(shape,
		(unsigned short) plotParams->lwd,
		red, green, blue, alpha);
		
	/* does not play nicely with setRightFill
	SWFShape_setLine2Filled(shape,
		(unsigned short) plotParams->lwd,
		newSWFSolidFillStyle( red, green, blue, alpha ),
		SWF_LINESTYLE_CAP_ROUND,
		plotParams->lmitre);
	*/
		
		
}
示例#5
0
文件: DOCX.cpp 项目: glutz/ReporteRs
void DOCX_setRunProperties(pDevDesc dev, R_GE_gcontext *gc, double fontsize){
	DOCDesc *pd = (DOCDesc *) dev->deviceSpecific;
	int alpha =  (int) ((255-R_ALPHA(gc->col))/255.0 * 100000);//n importe quoi
	int fontface = gc->fontface;
	fprintf(pd->dmlFilePointer, "<w:rPr>" );
	fprintf(pd->dmlFilePointer, "<w:rFonts w:ascii=\"%s\" w:hAnsi=\"%s\" w:cs=\"%s\" />", pd->fi->fontname, pd->fi->fontname, pd->fi->fontname );
	if ( fontface == 2 || fontface == 4 ) {
		fprintf(pd->dmlFilePointer, "<w:b />");
	}
	if (fontface == 3 || fontface == 4) {
		fprintf(pd->dmlFilePointer, "<w:i />");
	}
	fprintf(pd->dmlFilePointer, "<w:color w:val=\"%s\" />", RGBHexValue(gc->col) );
	fprintf(pd->dmlFilePointer, "<w:sz w:val=\"%.0f\" />", fontsize * 2 );
	fprintf(pd->dmlFilePointer, "<w:szCs w:val=\"%.0f\" />", fontsize * 2 );

	if (alpha > 0) {
		fprintf(pd->dmlFilePointer, "<w14:textFill>" );
		fprintf(pd->dmlFilePointer, "<w14:solidFill>" );
		fprintf(pd->dmlFilePointer, "<w14:srgbClr w14:val=\"%s\">", RGBHexValue(gc->col) );
		fprintf(pd->dmlFilePointer, "<w14:alpha w14:val=\"%d\" />", alpha);
		fprintf(pd->dmlFilePointer, "</w14:srgbClr>");
		fprintf(pd->dmlFilePointer, "</w14:solidFill>" );
		fprintf(pd->dmlFilePointer, "</w14:textFill>" );
	}


	fprintf(pd->dmlFilePointer, "</w:rPr>" );

}
示例#6
0
static void Quartz_SetFill(int fill, double gamma, NewDevDesc *dd)
{
    QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
    xd->fill = fill;
    CGContextSetRGBFillColor( GetContext(xd), 
			      (float)R_RED(fill)/255.0, 
			      (float)R_GREEN(fill)/255.0, 
			      (float)R_BLUE(fill)/255.0, 
			      (float)R_ALPHA(fill)/255.0);
}
示例#7
0
static void Quartz_SetStroke(int color, double gamma, NewDevDesc *dd)
{
    QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
    xd->color = color;
    CGContextSetRGBStrokeColor( GetContext(xd), 
				(float)R_RED(color)/255.0, 
				(float)R_GREEN(color)/255.0, 
				(float)R_BLUE(color)/255.0, 
				(float)R_ALPHA(color)/255.0);
}
示例#8
0
/* R uses gc->col for text color, but actually we need to "fill" the outlines */
void swfSetTextColor(SWFShape shape, const pGEcontext gc, pswfDesc swfInfo)
{
    SWFFillStyle fill;
    fill = newSWFSolidFillStyle(R_RED(gc->col),
                                R_GREEN(gc->col),
                                R_BLUE(gc->col),
                                R_ALPHA(gc->col));
    SWFShape_setRightFillStyle(shape, fill);
    
    SWFArray_append(swfInfo->array, (SWFObject) fill);
}
示例#9
0
void write_attr_col(FILE* f, const char* attr, unsigned int col) {
    int alpha = R_ALPHA(col);

    if (col == NA_INTEGER || alpha == 0) {
        fprintf(f, " %s='none'", attr);
        return;
    } else {
        fprintf(f, " %s='#%02X%02X%02X'", attr, R_RED(col), R_GREEN(col), R_BLUE(col));
        if (alpha != 255)
            fprintf(f, " %s-opacity='%0.2f'", attr, alpha / 255.0);
    }
}
示例#10
0
static SDL_Surface *com2alphasurface(agsurface_t *src, int cl, SDL_Surface **opaque) {
	SDL_Surface *s;
	int x,y;
	BYTE *sp, *dp, *op = NULL;
	SDL_Rect r_src;
	Uint32 pixel;
	
	if (sdl_dib->format->BitsPerPixel == 8) {
		s = SDL_AllocSurface(SDL_SWSURFACE, src->width, src->height,
							 32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000);
		*opaque = SDL_AllocSurface(SDL_SWSURFACE, src->width, src->height, 8, 0, 0, 0, 0);
		pixel = sdl_col[cl].r << 16 | sdl_col[cl].g << 8 | sdl_col[cl].b;
	} else {
		s = SDL_AllocSurface(SDL_SWSURFACE, src->width, src->height,
							 sdl_dib->format->BitsPerPixel <= 24 ? sdl_dib->format->BitsPerPixel+8:32,
							 sdl_dib->format->Rmask,sdl_dib->format->Gmask,
							 sdl_dib->format->Bmask,
							 sdl_dib->format->BitsPerPixel<24?0xFF0000:0xFF000000);
		pixel = SDL_MapRGB(sdl_dib->format, sdl_col[cl].r, sdl_col[cl].g, sdl_col[cl].b);
	}
	
	setRect(r_src, 0, 0, src->width, src->height);
	SDL_FillRect(s, &r_src, pixel);

	SDL_LockSurface(s);
	if (*opaque)
		SDL_LockSurface(*opaque);
	
	for (y = 0; y < src->height; y++) {
		sp = src->pixel + y * src->bytes_per_line;
		dp = s->pixels + y * s->pitch;
#ifndef WORDS_BIGENDIAN
		dp += s->format->BytesPerPixel -1;
#endif
		if (*opaque)
			op = (*opaque)->pixels + y * (*opaque)->pitch;
		
		for (x = 0; x < src->width; x++) {
			*dp =  R_ALPHA(*sp);
			if (op)
				*op++ = (*dp >= (256-64)) ? cl : 0;
			sp++;
			dp += s->format->BytesPerPixel;
		}
	}
	
	if (*opaque)
		SDL_UnlockSurface(*opaque);
	SDL_UnlockSurface(s);
	return s;
}
示例#11
0
    /*
     * device_Text should have the side-effect that the
     * given text is drawn at the given location.
     * The text should be rotated according to rot (degrees)
     *
     * R_GE_gcontext parameters that should be honoured (if possible):
     *   font, cex, ps, col, gamma
     */
static void SWF_Text( double x, double y, const char *str,
		double rot, double hadj, const pGEcontext plotParams, 
		pDevDesc deviceInfo)
{
	/* Shortcut pointers to variables of interest. */
	swfDevDesc *swfInfo = (swfDevDesc *) deviceInfo->deviceSpecific;
	
	if( swfInfo->debug == TRUE ){
		fprintf(swfInfo->logFile,
			"SWF_Text: Writing Text \"%s\"\n", str);
		fflush(swfInfo->logFile);
	}
	
	/* It is possible that this will be very expensive and storing 
	 * a single text object in swfInfo may be better.
	 */
	SWFText text_object = newSWFText();
	SWFDisplayItem text_display;
	/*Ming (0,0) is the top left, convert to R (0,0) at bottom left*/
	y = deviceInfo->top - y;
	
	//found = !strcmp(name, fontlist->family->fxname);
	
	// Tell the text object to use the font previously loaded
	SWFText_setFont(text_object, 
		selectFont(plotParams->fontface, plotParams->fontfamily, swfInfo));
	
	// Set the height of the text
	SWFText_setHeight(text_object, plotParams->ps * plotParams->cex);
	
	// Set the color of the text
	byte red = R_RED(plotParams->col);
	byte green = R_GREEN(plotParams->col);
	byte blue = R_BLUE(plotParams->col);
	byte alpha =  R_ALPHA(plotParams->col);
	SWFText_setColor(text_object, red, green, blue, alpha);
	
	// Add a string to the text object
	SWFText_addString(text_object, str, NULL);
	
	// Add the text object to the movie (at 0,0)
	text_display = SWFMovie_add(swfInfo->m, (SWFBlock) text_object);
	
	addToDisplayList( text_display );
	
	// Move to correct coordinate and rotate
	SWFDisplayItem_moveTo(text_display, x, y);
	SWFDisplayItem_rotate(text_display, rot);
	
			
}
示例#12
0
void RAPHAEL_SetFillColor(pDevDesc dev, R_GE_gcontext *gc, int idx) {
	DOCDesc *pd = (DOCDesc *) dev->deviceSpecific;
	char *saved_locale;
	saved_locale = setlocale(LC_NUMERIC, "C");
	fprintf(pd->dmlFilePointer, "elt_%d.attr({", idx);

	float alpha =  R_ALPHA(gc->fill)/255.0;
	if (alpha > 0) {
		fprintf(pd->dmlFilePointer, "'fill': \"#%s\"", RGBHexValue(gc->fill) );
		fprintf(pd->dmlFilePointer, ",'fill-opacity': \"%.3f\"", alpha );
	}
	fputs("});\n", pd->dmlFilePointer );
	setlocale(LC_NUMERIC, saved_locale);

}
示例#13
0
static void SWF_SetFill(SWFShape shape, const pGEcontext plotParams, 
	swfDevDesc *swfInfo  ){
	
	/*
	 *	Some Notes on Color
	 *
	 *	R uses a 24-bit color model.  Colors are specified in 32-bit
	 *	integers which are partitioned into 4 bytes as follows.
	 *
	 *		<-- most sig	    least sig -->
	 *		+-------------------------------+
	 *		|   0	| blue	| green |  red	|
	 *		+-------------------------------+
	 *
	 *	The red, green and blue bytes can be extracted as follows.
	 *
	 *		red   = ((color	     ) & 255)
	 *		green = ((color >>  8) & 255)
	 *		blue  = ((color >> 16) & 255)
	 */
	
	byte red = R_RED(plotParams->fill);
	byte green = R_GREEN(plotParams->fill);
	byte blue = R_BLUE(plotParams->fill);
	
	//Top 8 bits: 255 = opaque, 0 = transparent
	byte alpha = R_ALPHA(plotParams->fill);
	
	if( swfInfo->debug == TRUE ){
		fprintf(swfInfo->logFile,"\tFill: Red=%d, ",red);
		fprintf(swfInfo->logFile,"Green=%d, ",green);
		fprintf(swfInfo->logFile,"Blue=%d, ",blue);
		fprintf(swfInfo->logFile,"Alpha=%d\n",alpha);
		fflush(swfInfo->logFile);
	}
		
		
		
	
	SWFFillStyle fill_style;
	fill_style = newSWFSolidFillStyle( red, green, blue, alpha );
	if(fill_style == NULL)
		error("Failed to allocate memory for fill object!");
	SWFShape_setRightFillStyle(shape, fill_style);
}
示例#14
0
/**********************************
 * Below are supporting functions *
 **********************************/
void swfSetLineStyle(SWFShape shape, const pGEcontext gc, pswfDesc swfInfo)
{
    int cap = SWF_LINESTYLE_CAP_ROUND;
    int endcap = SWF_LINESTYLE_FLAG_ENDCAP_ROUND;
    int join = SWF_LINESTYLE_JOIN_ROUND;
    switch(gc->lend)
    {
        case GE_ROUND_CAP:
            cap = SWF_LINESTYLE_CAP_ROUND;
            endcap = SWF_LINESTYLE_FLAG_ENDCAP_ROUND;
            break;
        case GE_BUTT_CAP:
            cap = SWF_LINESTYLE_CAP_NONE;
            endcap = SWF_LINESTYLE_FLAG_ENDCAP_NONE;
            break;
        case GE_SQUARE_CAP:
            cap = SWF_LINESTYLE_CAP_SQUARE;
            endcap = SWF_LINESTYLE_FLAG_ENDCAP_SQUARE;
            break;
    }
    switch(gc->ljoin)
    {
        case GE_ROUND_JOIN:
            join = SWF_LINESTYLE_JOIN_ROUND;
            break;
        case GE_MITRE_JOIN:
            join = SWF_LINESTYLE_JOIN_MITER;
            break;
        case GE_BEVEL_JOIN:
            join = SWF_LINESTYLE_JOIN_BEVEL;
            break;
    }
    SWFShape_setLine2(shape, (unsigned short) gc->lwd,
                             R_RED(gc->col),
                             R_GREEN(gc->col),
                             R_BLUE(gc->col),
                             R_ALPHA(gc->col),
                             cap | endcap | join,
                             (float) gc->lmitre);
}
示例#15
0
/*
 * 指定範囲にパレット col を rate の割合で重ねる CK1
 */
void sdl_wrapColor(int sx, int sy, int w, int h, int cl, int rate) {
	SDL_Surface *s;
	SDL_Rect r_src,r_dst;

	s = SDL_AllocSurface(SDL_SWSURFACE, w, h,
			     sdl_dib->format->BitsPerPixel, 0, 0, 0, 0);
	
	if (s->format->BitsPerPixel == 8) {
		memcpy(s->format->palette->colors, sdl_dib->format->palette->colors,
		       sizeof(SDL_Color)*256);
	} else {
		cl = (cl < 256) ? SDL_MapRGB(sdl_dib->format, sdl_col[cl].r, sdl_col[cl].g, sdl_col[cl].b) : cl;
	}
	
	setRect(r_src, 0, 0, w, h);
	SDL_FillRect(s, &r_src, cl);
	
	SDL_SetAlpha(s, RLEFLAG(SDL_SRCALPHA), R_ALPHA(rate));
	setRect(r_dst, sx, sy, w, h);
	SDL_BlitSurface(s, &r_src, sdl_dib, &r_dst);
	SDL_FreeSurface(s);
}
示例#16
0
文件: colors.c 项目: SensePlatform/R
SEXP attribute_hidden do_col2RGB(SEXP call, SEXP op, SEXP args, SEXP env)
{
/* colorname, "#rrggbb" or "col.number" to (r,g,b) conversion */

    SEXP colors, ans, names, dmns;
    double col, bg;
    unsigned int icol;
    int n, i, i4;

    checkArity(op, args);
    colors = CAR(args);
    if(isString(colors)) PROTECT(colors);
    else {
	PROTECT(colors = coerceVector(colors, INTSXP));
	if (TYPEOF(colors) != INTSXP)
	    error(_("invalid '%s' value"), "col");
    }
    n = LENGTH(colors);

    /* First set up the output matrix */
    PROTECT(ans = allocMatrix(INTSXP, 4, n));
    PROTECT(dmns = allocVector(VECSXP, 2));
    PROTECT(names = allocVector(STRSXP, 4));
    SET_STRING_ELT(names, 0, mkChar("red"));
    SET_STRING_ELT(names, 1, mkChar("green"));
    SET_STRING_ELT(names, 2, mkChar("blue"));
    SET_STRING_ELT(names, 3, mkChar("alpha"));
    SET_VECTOR_ELT(dmns, 0, names);
    UNPROTECT(1); /*names*/
    if ((names = getAttrib(colors, R_NamesSymbol)) != R_NilValue)
	SET_VECTOR_ELT(dmns, 1, names);
    setAttrib(ans, R_DimNamesSymbol, dmns);

    /* avoid looking up the background unless we will need it;
       this may avoid opening a new window.  Unfortunately, there is no
       unavailable colour, so we work with doubles and convert at the 
       last minute */

#define BG_NEEDED -1.0

    bg = BG_NEEDED;

    if(isString(colors)) {
	for(i = i4 = 0; i < n; i++, i4 += 4) {
	    col = str2col(CHAR(STRING_ELT(colors, i)), bg);
	    if (col == BG_NEEDED)
	    	col = bg = dpptr(GEcurrentDevice())->bg;
	    icol = (unsigned int)col;
	    INTEGER(ans)[i4 +0] = R_RED(icol);
	    INTEGER(ans)[i4 +1] = R_GREEN(icol);
	    INTEGER(ans)[i4 +2] = R_BLUE(icol);
	    INTEGER(ans)[i4 +3] = R_ALPHA(icol);
	}
    } else {
	for(i = i4 = 0; i < n; i++, i4 += 4) {
	    col = INTEGER(colors)[i];
	    if      (col == NA_INTEGER) col = R_TRANWHITE;
	    else if (col == 0)          col = bg;
	    else 		        col = R_ColorTable[(unsigned int)(col-1) % R_ColorTableSize];
	    if (col == BG_NEEDED)
	    	col = bg = dpptr(GEcurrentDevice())->bg;
	    icol = (unsigned int)col;
	    INTEGER(ans)[i4 +0] = R_RED(icol);
	    INTEGER(ans)[i4 +1] = R_GREEN(icol);
	    INTEGER(ans)[i4 +2] = R_BLUE(icol);
	    INTEGER(ans)[i4 +3] = R_ALPHA(icol);
	}
    }
    UNPROTECT(3);
    return ans;
}