From: <hba...@us...> - 2009-07-20 01:47:49
|
Revision: 10165 http://plplot.svn.sourceforge.net/plplot/?rev=10165&view=rev Author: hbabcock Date: 2009-07-20 01:47:47 +0000 (Mon, 20 Jul 2009) Log Message: ----------- Added the routine difilt_clip to PLplot core which will appropriately transform the coordinates of the text clipping rectangle for the benefit of those drivers that render their own text. Changed the svg driver and the cairo driver to use this new core routine for their text clipping. Modified Paths: -------------- trunk/drivers/cairo.c trunk/drivers/svg.c trunk/include/plplotP.h trunk/src/plcore.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2009-07-20 01:15:20 UTC (rev 10164) +++ trunk/drivers/cairo.c 2009-07-20 01:47:47 UTC (rev 10165) @@ -596,6 +596,7 @@ PangoLayout *layout; PangoFontDescription *fontDescription; PLCairo *aStream; + PLINT rcx[4], rcy[4]; aStream = (PLCairo *)pls->dev; @@ -617,25 +618,37 @@ pango_layout_context_changed(layout); cairo_font_options_destroy(cairoFontOptions); + /* Save current transform matrix & clipping region */ + cairo_save(aStream->cairoContext); + /* Set up the clipping region if we are doing text clipping */ if(aStream->text_clipping){ - cairo_save(aStream->cairoContext); - diorot_rad = pls->diorot * PI/2.0; - rotate_cairo_surface(pls, - cos(diorot_rad), - sin(diorot_rad), - -sin(diorot_rad), - cos(diorot_rad), - 0.5 * pls->xlength, - 0.5 * pls->ylength); - cairo_rectangle(aStream->cairoContext, aStream->downscale * pls->clpxmi, aStream->downscale * pls->clpymi, aStream->downscale * (pls->clpxma - pls->clpxmi), aStream->downscale * (pls->clpyma - pls->clpymi)); + + /* 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); - cairo_restore(aStream->cairoContext); } - /* Save current transform matrix & clipping region */ - cairo_save(aStream->cairoContext); - /* Move to the string reference point */ cairo_move_to(aStream->cairoContext, aStream->downscale * (double) args->x, aStream->downscale * (double) args->y); Modified: trunk/drivers/svg.c =================================================================== --- trunk/drivers/svg.c 2009-07-20 01:15:20 UTC (rev 10164) +++ trunk/drivers/svg.c 2009-07-20 01:47:47 UTC (rev 10165) @@ -465,7 +465,6 @@ short lastOffset; double ftHt; PLUNICODE fci; - PLINT x1c, y1c, x2c, y2c; PLINT rcx[4], rcy[4]; PLFLT rotation, shear, stride, cos_rot, sin_rot, sin_shear, cos_shear; PLFLT t[4]; @@ -495,21 +494,9 @@ svg_attr_values(aStream, "id","text-clipping%d", which_clip); svg_general(aStream, ">\n"); - /* Use PLplot core routine to appropriately transform the - coordinates of the clipping rectangle */ - x1c = pls->clpxmi; - y1c = pls->clpymi; - x2c = pls->clpxma; - y2c = pls->clpyma; - rcx[0] = x1c; - rcx[1] = x1c; - rcx[2] = x2c; - rcx[3] = x2c; - rcy[0] = y1c; - rcy[1] = y2c; - rcy[2] = y2c; - rcy[3] = y1c; - difilt(rcx, rcy, 4, &x1c, &x2c, &y1c, &y2c); + /* Use PLplot core routine difilt_clip to appropriately + transform the coordinates of the clipping rectangle */ + difilt_clip(rcx, rcy); /* Output a polygon to represent the clipping region. */ svg_open(aStream, "polygon"); @@ -536,6 +523,7 @@ /* This draws the clipping region on the screen which can be very helpful for debugging. */ + /* svg_open(aStream, "polygon"); svg_attr_values(aStream, Modified: trunk/include/plplotP.h =================================================================== --- trunk/include/plplotP.h 2009-07-20 01:15:20 UTC (rev 10164) +++ trunk/include/plplotP.h 2009-07-20 01:47:47 UTC (rev 10165) @@ -518,6 +518,12 @@ difilt(PLINT *, PLINT *, PLINT, PLINT *, PLINT *, PLINT *, PLINT *); + /* Transforms the clipping region coordinates as necessary + based on the current plot orientation, etc. */ + +PLDLLIMPEXP void +difilt_clip(PLINT *, PLINT *); + /* Driver draws text */ void Modified: trunk/src/plcore.c =================================================================== --- trunk/src/plcore.c 2009-07-20 01:15:20 UTC (rev 10164) +++ trunk/src/plcore.c 2009-07-20 01:47:47 UTC (rev 10165) @@ -1127,6 +1127,34 @@ } /*--------------------------------------------------------------------------*\ + * void difilt_clip + * + * This provides the transformed text clipping region for the benefit of + * those drivers that render their own text. +\*--------------------------------------------------------------------------*/ + +void +difilt_clip(PLINT *x_coords, PLINT *y_coords) +{ + PLINT x1c, x2c, y1c, y2c; + + x1c = plsc->clpxmi; + y1c = plsc->clpymi; + x2c = plsc->clpxma; + y2c = plsc->clpyma; + x_coords[0] = x1c; + x_coords[1] = x1c; + x_coords[2] = x2c; + x_coords[3] = x2c; + y_coords[0] = y1c; + y_coords[1] = y2c; + y_coords[2] = y2c; + y_coords[3] = y1c; + difilt(x_coords, y_coords, 4, &x1c, &x2c, &y1c, &y2c); +} + + +/*--------------------------------------------------------------------------*\ * void pldi_ini * * Updates driver interface, making sure everything is in order. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |