From: <hba...@us...> - 2007-08-18 00:07:22
|
Revision: 7812 http://plplot.svn.sourceforge.net/plplot/?rev=7812&view=rev Author: hbabcock Date: 2007-08-17 17:07:24 -0700 (Fri, 17 Aug 2007) Log Message: ----------- Added a text clipping option to the Cairo devices. The user can now turn on text clipping by specifying text_clipping=1. Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2007-08-17 07:24:39 UTC (rev 7811) +++ trunk/drivers/cairo.c 2007-08-18 00:07:24 UTC (rev 7812) @@ -58,9 +58,14 @@ #define MAX_STRING_LEN 500 #define MAX_MARKUP_LEN MAX_STRING_LEN * 10 +static int text_clipping; +static DrvOpt cairo_options[] = {{"text_clipping", DRV_INT, &text_clipping, "Use text clipping (text_clipping=0|1)"}, + {NULL, DRV_INT, NULL, NULL}}; + typedef struct { cairo_surface_t *cairoSurface; cairo_t *cairoContext; + short text_clipping; #if defined(PLD_xcairo) Display *XDisplay; Window XWindow; @@ -142,7 +147,7 @@ /* General */ -void stream_and_font_setup(PLStream *, int); +PLCairo *stream_and_font_setup(PLStream *, int); cairo_status_t write_to_stream(void *, unsigned char *, unsigned int); /* String processing */ @@ -343,9 +348,11 @@ // Save current transform matrix & clipping region cairo_save(aStream->cairoContext); - // Setup the clipping region - // cairo_rectangle(aStream->cairoContext, DOWNSCALE * pls->clpxmi, DOWNSCALE * pls->clpymi, DOWNSCALE * (pls->clpxma - pls->clpxmi), DOWNSCALE * (pls->clpyma - pls->clpymi)); - // cairo_clip(aStream->cairoContext); + // Set up the clipping region if we are doing text clipping + if(aStream->text_clipping){ + cairo_rectangle(aStream->cairoContext, DOWNSCALE * pls->clpxmi, DOWNSCALE * pls->clpymi, DOWNSCALE * (pls->clpxma - pls->clpxmi), DOWNSCALE * (pls->clpyma - pls->clpymi)); + cairo_clip(aStream->cairoContext); + } // Move to the string reference point cairo_move_to(aStream->cairoContext, DOWNSCALE * (double) args->x, DOWNSCALE * (double) args->y); @@ -583,12 +590,15 @@ // // Initializes the PLStream structure for the cairo devices. // Initializes the font lookup table. +// Checks for cairo specific user options. +// Returns a new PLCairo structure. //--------------------------------------------------------------------- -void stream_and_font_setup(PLStream *pls, int interactive) +PLCairo *stream_and_font_setup(PLStream *pls, int interactive) { int i; char *a; + PLCairo *aStream; // Stream setup pls->termin = interactive; /* Interactive device */ @@ -619,6 +629,23 @@ } } } + + // Allocate a cairo stream structure + aStream = malloc(sizeof(PLCairo)); + + // Set text clipping off as this makes the driver pretty slow + aStream->text_clipping = 0; + text_clipping = 0; + + // Check for cairo specific options + plParseDrvOpts(cairo_options); + + // Turn on text clipping if the user desires this + if(text_clipping){ + aStream->text_clipping = 1; + } + + return aStream; } //--------------------------------------------------------------------- @@ -746,11 +773,8 @@ PLCairo *aStream; // Setup the PLStream and the font lookup table - stream_and_font_setup(pls, 1); + aStream = stream_and_font_setup(pls, 1); - // Allocate a cairo stream structure - aStream = malloc(sizeof(PLCairo)); - // X Windows setup aStream->XDisplay = NULL; aStream->XDisplay = XOpenDisplay(NULL); @@ -942,11 +966,8 @@ PLCairo *aStream; // Setup the PLStream and the font lookup table - stream_and_font_setup(pls, 0); + aStream = stream_and_font_setup(pls, 0); - // Allocate a cairo stream structure - aStream = malloc(sizeof(PLCairo)); - // Prompt for a file name if not already set. plOpenFile(pls); @@ -1013,11 +1034,8 @@ PLCairo *aStream; // Setup the PLStream and the font lookup table - stream_and_font_setup(pls, 0); + aStream = stream_and_font_setup(pls, 0); - // Allocate a cairo stream structure - aStream = malloc(sizeof(PLCairo)); - // Prompt for a file name if not already set. plOpenFile(pls); @@ -1089,11 +1107,8 @@ PLCairo *aStream; // Setup the PLStream and the font lookup table - stream_and_font_setup(pls, 0); + aStream = stream_and_font_setup(pls, 0); - // Allocate a cairo stream structure - aStream = malloc(sizeof(PLCairo)); - // Prompt for a file name if not already set. plOpenFile(pls); @@ -1161,17 +1176,8 @@ { PLCairo *aStream; - // Setup the PLStream and the font lookup table - stream_and_font_setup(pls, 0); - - // Initialize family file info - plFamInit(pls); - - // Prompt for a file name if not already set, and close the file - // since we just need the name, not an open file. - plOpenFile(pls); - - // Allocate a cairo stream structure. + // Setup the PLStream and the font lookup table and allocate a cairo + // stream structure. // // NOTE: The check below is necessary since, in family mode, this function // will be called multiple times. While you might think that it is @@ -1182,11 +1188,18 @@ // which I infer the existence of said bad stale pointer. // if(pls->dev == NULL){ - aStream = malloc(sizeof(PLCairo)); + aStream = stream_and_font_setup(pls, 0); } else { + stream_and_font_setup(pls, 0); aStream = pls->dev; } + // Initialize family file info + plFamInit(pls); + + // Prompt for a file name if not already set. + plOpenFile(pls); + // Save the pointer to the structure in the PLplot stream pls->dev = aStream; @@ -1296,11 +1309,8 @@ pls->ylength = pls->phyyma; // Setup the PLStream and the font lookup table - stream_and_font_setup(pls, 0); + aStream = stream_and_font_setup(pls, 0); - // Allocate a cairo stream structure - aStream = malloc(sizeof(PLCairo)); - // Check that user supplied us with some memory to draw in if(pls->dev == NULL){ plexit("Must call plsmem first to set user plotting area!"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |