From: <hez...@us...> - 2009-08-02 05:44:56
|
Revision: 10198 http://plplot.svn.sourceforge.net/plplot/?rev=10198&view=rev Author: hezekiahcarty Date: 2009-08-02 05:44:48 +0000 (Sun, 02 Aug 2009) Log Message: ----------- Factor out clipping code to share between text and arc functions Modified Paths: -------------- trunk/drivers/cairo.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2009-08-02 05:29:20 UTC (rev 10197) +++ trunk/drivers/cairo.c 2009-08-02 05:44:48 UTC (rev 10198) @@ -198,6 +198,7 @@ PLCairo *stream_and_font_setup(PLStream *, int); cairo_status_t write_to_stream(void *, unsigned char *, unsigned int); +void set_clip(PLStream *pls); /* String processing */ @@ -601,7 +602,6 @@ PangoLayout *layout; PangoFontDescription *fontDescription; PLCairo *aStream; - PLINT rcx[4], rcy[4]; aStream = (PLCairo *)pls->dev; @@ -628,30 +628,7 @@ /* Set up the clipping region if we are doing text clipping */ if(aStream->text_clipping){ - - /* Use PLplot core routine to get the corners of the clipping rectangle */ - difilt_clip(rcx, rcy); - - /* Layout the bounds of the clipping region */ - /* Should we convert PLINT to short and use the polyline routine? */ - cairo_move_to(aStream->cairoContext, - aStream->downscale * (double) rcx[0], - aStream->downscale * (double) rcy[0]); - cairo_line_to(aStream->cairoContext, - aStream->downscale * (double) rcx[1], - aStream->downscale * (double) rcy[1]); - cairo_line_to(aStream->cairoContext, - aStream->downscale * (double) rcx[2], - aStream->downscale * (double) rcy[2]); - cairo_line_to(aStream->cairoContext, - aStream->downscale * (double) rcx[3], - aStream->downscale * (double) rcy[3]); - cairo_line_to(aStream->cairoContext, - aStream->downscale * (double) rcx[0], - aStream->downscale * (double) rcy[0]); - - /* Set the clipping region */ - cairo_clip(aStream->cairoContext); + set_clip(pls); } /* Move to the string reference point */ @@ -757,8 +734,7 @@ /* Set up the clipping region if we are doing text clipping */ if(aStream->text_clipping){ - cairo_rectangle(aStream->cairoContext, aStream->downscale * pls->clpxmi, aStream->downscale * pls->clpymi, aStream->downscale * (pls->clpxma - pls->clpxmi), aStream->downscale * (pls->clpyma - pls->clpymi)); - cairo_clip(aStream->cairoContext); + set_clip(pls); } /* Move to the string reference point */ @@ -1178,6 +1154,49 @@ } /*--------------------------------------------------------------------- + set_clip() + + Set the clipping region to the plot window. + NOTE: cairo_save() and cairo_restore() should probably be called before + and after this, respectively. + ---------------------------------------------------------------------*/ + +void set_clip(PLStream *pls) +{ + PLINT rcx[4], rcy[4]; + PLCairo *aStream; + aStream = (PLCairo *)pls->dev; + + /* Use PLplot core routine to get the corners of the clipping rectangle */ + difilt_clip(rcx, rcy); + + /* Layout the bounds of the clipping region */ + /* Should we convert PLINT to short and use the polyline routine? */ + cairo_move_to(aStream->cairoContext, + aStream->downscale * (double) rcx[0], + aStream->downscale * (double) rcy[0]); + cairo_line_to(aStream->cairoContext, + aStream->downscale * (double) rcx[1], + aStream->downscale * (double) rcy[1]); + cairo_line_to(aStream->cairoContext, + aStream->downscale * (double) rcx[2], + aStream->downscale * (double) rcy[2]); + cairo_line_to(aStream->cairoContext, + aStream->downscale * (double) rcx[3], + aStream->downscale * (double) rcy[3]); + cairo_line_to(aStream->cairoContext, + aStream->downscale * (double) rcx[0], + aStream->downscale * (double) rcy[0]); + + /* Set the clipping region */ + cairo_clip(aStream->cairoContext); + + /* Apparently, in some older Cairo versions, cairo_clip does not consume + the current path. */ + cairo_new_path(aStream->cairoContext); +} + +/*--------------------------------------------------------------------- arc() Draws an arc, possibly filled. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |