On Fri, May 1, 2009 at 3:47 PM, Hezekiah M. Carty <hca...@atmos.umd.edu> wrote:
> One fix for the Cairo driver's sawtooth effect suggested on the Cairo
> list is to change the line caps and/or joints.  The attached patch
> does just that and produces, from what I can tell, output which is
> quite nice and without any of those teeth along the edges of the
> plotted surfaces in example 8.

In the spirit of cleaning up line rendering on the Cairo driver, I
have attached another patch which I think makes Cairo lines render a
little more cleanly.  The patch adds a few convenience functions to
the Cairo driver for getting/setting line drawing styles and sets the
style of line ends and joints when rendering both individual line
segments and polylines.

The contours on page 4 of example 16 provide a good example of the
effect this patch has.  As-is, the contours have small dents or gaps
between each line segment.  With the attached patch these gaps are no
longer there.  One downside is that the contour line ends protrude
more noticeably past the plot boundaries, similar to the Qt output.

This patch would apply on top of the previous Cairo sawtooth patch.

Comments?  This is a slightly more invasive patch, so it is probably
better as a post-5.9.3 addition, regardless of the status of the
sawtooth fix patch.

Hez

-- 
Hezekiah M. Carty
Graduate Research Assistant
University of Maryland
Department of Atmospheric and Oceanic Science
diff --git a/drivers/cairo.c b/drivers/cairo.c
index 3a70921..77f1a91 100644
--- a/drivers/cairo.c
+++ b/drivers/cairo.c
@@ -255,17 +255,41 @@ void plD_bop_cairo(PLStream *pls)
   Draw a line in the current color from (x1,y1) to (x2,y2).
   ----------------------------------------------------------------------*/
 
+/*---------------------------------------------------------------------
+  (get|set)_line_properties
+
+  (Get|Set) the current Cairo line drawing properties.
+  ---------------------------------------------------------------------*/
+void get_line_properties(PLCairo *aStream, cairo_line_join_t *join, cairo_line_cap_t *cap)
+{
+  *join = cairo_get_line_join(aStream->cairoContext);
+  *cap = cairo_get_line_cap(aStream->cairoContext);
+}
+
+void set_line_properties(PLCairo *aStream, cairo_line_join_t join, cairo_line_cap_t cap)
+{
+    cairo_set_line_join(aStream->cairoContext, join);
+    cairo_set_line_cap(aStream->cairoContext, cap);
+}
+
 void plD_line_cairo(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
 {
   PLCairo *aStream;
+  cairo_line_join_t old_join;
+  cairo_line_cap_t old_cap;
 
   aStream = (PLCairo *)pls->dev;
 
   set_current_context(pls);
 
+  get_line_properties(aStream, &old_join, &old_cap);
+  set_line_properties(aStream, old_join, CAIRO_LINE_CAP_ROUND);
+
   cairo_move_to(aStream->cairoContext, aStream->downscale * (double) x1a, aStream->downscale * (double) y1a);
   cairo_line_to(aStream->cairoContext, aStream->downscale * (double) x2a, aStream->downscale * (double) y2a);
   cairo_stroke(aStream->cairoContext);
+
+  set_line_properties(aStream, old_join, old_cap);
 }
 
 /*---------------------------------------------------------------------
@@ -277,11 +301,18 @@ void plD_line_cairo(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
 void plD_polyline_cairo(PLStream *pls, short *xa, short *ya, PLINT npts)
 {
   PLCairo *aStream;
+  cairo_line_join_t old_join;
+  cairo_line_cap_t old_cap;
 
   aStream = (PLCairo *)pls->dev;
 
+  get_line_properties(aStream, &old_join, &old_cap);
+  set_line_properties(aStream, CAIRO_LINE_JOIN_BEVEL, CAIRO_LINE_CAP_BUTT);
+
   poly_line(pls, xa, ya, npts);
   cairo_stroke(aStream->cairoContext);
+
+  set_line_properties(aStream, old_join, old_cap);
 }
 
 /*---------------------------------------------------------------------
@@ -994,11 +1025,10 @@ void filled_polygon(PLStream *pls, short *xa, short *ya, PLINT npts)
   aStream = (PLCairo *)pls->dev;
 
   /* Save the previous line drawing style */
-  old_line_cap = cairo_get_line_cap(aStream->cairoContext);
-  old_line_join = cairo_get_line_join(aStream->cairoContext);
+  get_line_properties(aStream, &old_line_join, &old_line_cap);
 
-  cairo_set_line_cap(aStream->cairoContext, CAIRO_LINE_CAP_BUTT);
-  cairo_set_line_join(aStream->cairoContext, CAIRO_LINE_JOIN_BEVEL);
+  /* These line properties make for a nicer looking polygon mesh */
+  set_line_properties(aStream, CAIRO_LINE_JOIN_BEVEL, CAIRO_LINE_CAP_BUTT);
 
   cairo_move_to(aStream->cairoContext, aStream->downscale * (double) xa[0], aStream->downscale * (double) ya[0]);
   for(i=1;i<npts;i++)
@@ -1016,8 +1046,7 @@ void filled_polygon(PLStream *pls, short *xa, short *ya, PLINT npts)
     cairo_fill(aStream->cairoContext);
 
   /* Restor the previous line drawing style */
-  cairo_set_line_cap(aStream->cairoContext, old_line_cap);
-  cairo_set_line_join(aStream->cairoContext, old_line_join);
+  set_line_properties(aStream, old_line_join, old_line_cap);
 }
 
 /*---------------------------------------------------------------------
------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations 
Conference from O'Reilly Media. Velocity features a full day of 
expert-led, hands-on workshops and two days of sessions from industry 
leaders in dedicated Performance & Operations tracks. Use code vel09scf 
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel

Reply via email to