[cairo-commit] src/cairo-gstate.c src/cairo-surface.c

Carl Worth cworth at kemper.freedesktop.org
Thu Mar 15 22:39:21 PDT 2007


 src/cairo-gstate.c  |   44 +++++++++++++++++++++++++++++++++-----------
 src/cairo-surface.c |    6 ++++--
 2 files changed, 37 insertions(+), 13 deletions(-)

New commits:
diff-tree 1234064fa4aa20d0875473709d2fa74600af485b (from 133183d858aa632da3cec2a789dcc1e1203d778b)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Mar 15 22:38:42 2007 -0700

    Allow NULL pointers for functions that accept pointers for multiple return values.
    
    When a single function accepts pointers for multiple return values,
    the convention is that it's legal for the user to pass NULL for
    those pointers in case the user is only interested in some subset
    of the values.
    
    This was already properly implemented for functions such as
    cairo_pattern_get_rgba, etc.
    
    Here we fix four functions to follow the same convention:
    
    	cairo_stroke_extents
    	cairo_fill_extents
    	cairo_clip_extents
    	cairo_surface_get_device_offset

diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index bacf516..b75a90b 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -1038,12 +1038,23 @@ _cairo_gstate_traps_extents_to_user_rect
 
     if (extents.p1.x >= extents.p2.x || extents.p1.y >= extents.p2.y) {
         /* no traps, so we actually won't draw anything */
-        *x1 = *y1 = *x2 = *y2 = 0;
+	if (x1)
+	    *x1 = 0.0;
+	if (y1)
+	    *y1 = 0.0;
+	if (x2)
+	    *x2 = 0.0;
+	if (y2)
+	    *y2 = 0.0;
     } else {
-        *x1 = _cairo_fixed_to_double (extents.p1.x);
-        *y1 = _cairo_fixed_to_double (extents.p1.y);
-        *x2 = _cairo_fixed_to_double (extents.p2.x);
-        *y2 = _cairo_fixed_to_double (extents.p2.y);
+	if (x1)
+	    *x1 = _cairo_fixed_to_double (extents.p1.x);
+	if (y1)
+	    *y1 = _cairo_fixed_to_double (extents.p1.y);
+	if (x2)
+	    *x2 = _cairo_fixed_to_double (extents.p2.x);
+	if (y2)
+	    *y2 = _cairo_fixed_to_double (extents.p2.y);
 
         _cairo_gstate_backend_to_user_rectangle (gstate, x1, y1, x2, y2, NULL);
     }
@@ -1059,7 +1070,14 @@ _cairo_gstate_stroke_extents (cairo_gsta
     cairo_traps_t traps;
 
     if (gstate->stroke_style.line_width <= 0.0) {
-        *x1 = *y1 = *x2 = *y2 = 0.0;
+	if (x1)
+	    *x1 = 0.0;
+	if (y1)
+	    *y1 = 0.0;
+	if (x2)
+	    *x2 = 0.0;
+	if (y2)
+	    *y2 = 0.0;
 	return CAIRO_STATUS_SUCCESS;
     }
 
@@ -1135,11 +1153,15 @@ _cairo_gstate_clip_extents (cairo_gstate
     status = _cairo_clip_intersect_to_rectangle (&gstate->clip, &extents);
     if (status)
         return status;
-    
-    *x1 = extents.x;
-    *y1 = extents.y;
-    *x2 = extents.x + extents.width;
-    *y2 = extents.y + extents.height;
+
+    if (x1)
+	*x1 = extents.x;
+    if (y1)
+	*y1 = extents.y;
+    if (x2)
+	*x2 = extents.x + extents.width;
+    if (y2)
+	*y2 = extents.y + extents.height;
 
     _cairo_gstate_backend_to_user_rectangle (gstate, x1, y1, x2, y2, NULL);
 
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 5dbac58..516f30d 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -786,8 +786,10 @@ cairo_surface_get_device_offset (cairo_s
 				 double          *x_offset,
 				 double          *y_offset)
 {
-    *x_offset = surface->device_transform.x0;
-    *y_offset = surface->device_transform.y0;
+    if (x_offset)
+	*x_offset = surface->device_transform.x0;
+    if (y_offset)
+	*y_offset = surface->device_transform.y0;
 }
 slim_hidden_def (cairo_surface_get_device_offset);
 


More information about the cairo-commit mailing list