From: <hba...@us...> - 2009-11-07 21:09:24
|
Revision: 10567 http://plplot.svn.sourceforge.net/plplot/?rev=10567&view=rev Author: hbabcock Date: 2009-11-07 21:09:12 +0000 (Sat, 07 Nov 2009) Log Message: ----------- Add a background color handling option to the extcairo driver. The default is still not to set the background color. Modified Paths: -------------- trunk/drivers/cairo.c trunk/examples/c/ext-cairo-test.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2009-11-01 18:15:58 UTC (rev 10566) +++ trunk/drivers/cairo.c 2009-11-07 21:09:12 UTC (rev 10567) @@ -75,11 +75,14 @@ static int graphics_anti_aliasing; static int external_drawable; static int rasterize_image; +static int set_background; + static DrvOpt cairo_options[] = { { "text_clipping", DRV_INT, &text_clipping, "Use text clipping (text_clipping=0|1)" }, { "text_anti_aliasing", DRV_INT, &text_anti_aliasing, "Set desired text anti-aliasing (text_anti_aliasing=0|1|2|3). The numbers are in the same order as the cairo_antialias_t enumeration documented at http://cairographics.org/manual/cairo-cairo-t.html#cairo-antialias-t)" }, { "graphics_anti_aliasing", DRV_INT, &graphics_anti_aliasing, "Set desired graphics anti-aliasing (graphics_anti_aliasing=0|1|2|3). The numbers are in the same order as the cairo_antialias_t enumeration documented at http://cairographics.org/manual/cairo-cairo-t.html#cairo-antialias-t" }, { "external_drawable", DRV_INT, &external_drawable, "Plot to external X drawable" }, { "rasterize_image", DRV_INT, &rasterize_image, "Raster or vector image rendering (rasterize_image=0|1)" }, + { "set_background", DRV_INT, &set_background, "Set the background for the extcairo device (set_background=0|1). If 1 then the plot background will set by PLplot" }, { NULL, DRV_INT, NULL, NULL } }; typedef struct @@ -92,6 +95,7 @@ short text_anti_aliasing; short graphics_anti_aliasing; short rasterize_image; + short set_background; double downscale; char *pangoMarkupString; short upDown; @@ -1117,6 +1121,7 @@ text_anti_aliasing = 0; /* use 'default' text aliasing by default */ graphics_anti_aliasing = 0; /* use 'default' graphics aliasing by default */ rasterize_image = 1; /* Enable rasterization by default */ + set_background = 0; /* Default for extcairo is that PLplot not change the background */ /* Check for cairo specific options */ plParseDrvOpts( cairo_options ); @@ -1131,6 +1136,7 @@ aStream->text_anti_aliasing = text_anti_aliasing; aStream->graphics_anti_aliasing = graphics_anti_aliasing; aStream->rasterize_image = rasterize_image; + aStream->set_background = set_background; return aStream; } @@ -2346,6 +2352,7 @@ #if defined ( PLD_extcairo ) +void extcairo_setbackground( PLStream * ); void plD_dispatch_init_extcairo( PLDispatchTable *pdt ); void plD_init_extcairo( PLStream * ); void plD_bop_extcairo( PLStream * ); @@ -2354,6 +2361,30 @@ void plD_tidy_extcairo( PLStream * ); /*--------------------------------------------------------------------- + * extcairo_setbackground() + * + * Set the background color for the extcairo device + * ----------------------------------------------------------------------*/ + +void extcairo_setbackground( PLStream *pls ) +{ + PLCairo *aStream; + + aStream = (PLCairo *) pls->dev; + + /* Fill the context with the background color if the user so desires. */ + if ( aStream->cairoContext != NULL) { + cairo_rectangle( aStream->cairoContext, 0.0, 0.0, pls->xlength, pls->ylength ); + cairo_set_source_rgba( aStream->cairoContext, + (double) pls->cmap0[0].r / 255.0, + (double) pls->cmap0[0].g / 255.0, + (double) pls->cmap0[0].b / 255.0, + (double) pls->cmap0[0].a ); + cairo_fill( aStream->cairoContext ); + } +} + +/*--------------------------------------------------------------------- * dispatch_init_init() * * Initialize device dispatch table @@ -2403,7 +2434,14 @@ void plD_bop_extcairo( PLStream *pls ) { -/* nothing to do here, we want to preserve the Cairo context as it is. */ + PLCairo *aStream; + + aStream = (PLCairo *) pls->dev; + + /* Set background if desired */ + if ( aStream->set_background ){ + extcairo_setbackground(pls); + } } /*---------------------------------------------------------------------- @@ -2444,6 +2482,10 @@ /* Should adjust plot size to fit in the given cairo context? * Cairo does not provide a way to query the dimensions of a context? */ + /* Set background if desired */ + if ( aStream->set_background ){ + extcairo_setbackground(pls); + } break; default: /* Fall back on default Cairo actions */ plD_esc_cairo( pls, op, ptr ); Modified: trunk/examples/c/ext-cairo-test.c =================================================================== --- trunk/examples/c/ext-cairo-test.c 2009-11-01 18:15:58 UTC (rev 10566) +++ trunk/examples/c/ext-cairo-test.c 2009-11-07 21:09:12 UTC (rev 10567) @@ -5,7 +5,7 @@ #include <plplot.h> -int main( int argc, char *argv[] ) +int main( int argc, const char *argv[] ) { cairo_surface_t *cairoSurface; cairo_t *cairoContext; @@ -13,6 +13,8 @@ cairoSurface = cairo_ps_surface_create( "ext-cairo-test.ps", 720, 540 ); cairoContext = cairo_create( cairoSurface ); + plparseopts( &argc, argv, PL_PARSE_FULL ); + plsdev( "extcairo" ); plinit(); pl_cmd( PLESC_DEVINIT, cairoContext ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |