[cairo-commit] libsvg-cairo/src svg-cairo-internal.h, 1.16, 1.17 svg_cairo.c, 1.33, 1.34

Carl Worth commit at pdx.freedesktop.org
Mon Apr 18 16:32:20 PDT 2005


Committed by: cworth

Update of /cvs/cairo/libsvg-cairo/src
In directory gabe:/tmp/cvs-serv25077/src

Modified Files:
	svg-cairo-internal.h svg_cairo.c 
Log Message:

        * src/svg-cairo-internal.h:
        * src/svg_cairo.c: (_svg_cairo_end_group), (_svg_cairo_set_color),
        (_svg_cairo_set_color_and_alpha), (_svg_cairo_set_gradient),
        (_svg_cairo_set_paint_and_opacity), (_svg_cairo_render_image):
        Track changes in cairo API (removal of cairo_set_alpha).


Index: svg-cairo-internal.h
===================================================================
RCS file: /cvs/cairo/libsvg-cairo/src/svg-cairo-internal.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- svg-cairo-internal.h	27 Jan 2005 11:54:23 -0000	1.16
+++ svg-cairo-internal.h	18 Apr 2005 23:32:18 -0000	1.17
@@ -43,6 +43,8 @@
 typedef struct svg_cairo_state {
     cairo_surface_t *child_surface;
 
+    svg_color_t color;
+
     svg_paint_t fill_paint;
     svg_paint_t stroke_paint;
     double fill_opacity;

Index: svg_cairo.c
===================================================================
RCS file: /cvs/cairo/libsvg-cairo/src/svg_cairo.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- svg_cairo.c	11 Apr 2005 19:22:40 -0000	1.33
+++ svg_cairo.c	18 Apr 2005 23:32:18 -0000	1.34
@@ -437,13 +437,9 @@
 
     if (opacity != 1.0) {
 	cairo_save (svg_cairo->cr);
-	/* Put the DefaultMatrix in place, (XXX: do we want
-           IdentityMatrix here?), or else the current transformation
-           will have been applied twice. I'm still a bit fuzzy on
-           whether this is the correct approach or if it's masking
-           some other problem. */
+	/* XXX: Need to use opacity here, but cairo doesn't provide
+	 * the right API right now. */
 	cairo_identity_matrix (svg_cairo->cr);
-	cairo_set_alpha (svg_cairo->cr, opacity);
 	cairo_move_to (svg_cairo->cr, 0, 0);
 	cairo_show_surface (svg_cairo->cr, svg_cairo->state->child_surface,
 		       svg_cairo->state->viewport_width, svg_cairo->state->viewport_height);
@@ -524,21 +520,24 @@
 {
     svg_cairo_t *svg_cairo = closure;
 
-    if (color->is_current_color)
-	return SVG_STATUS_SUCCESS;
-
-    cairo_set_rgb_color (svg_cairo->cr,
-			 svg_color_get_red   (color) / 255.0,
-			 svg_color_get_green (color) / 255.0,
-			 svg_color_get_blue  (color) / 255.0);
+    svg_cairo->state->color = *color;
 
     return _cairo_status_to_svg_status (cairo_status (svg_cairo->cr));
 }
 
 static svg_status_t
-_svg_cairo_set_alpha (svg_cairo_t *svg_cairo, double alpha)
+_svg_cairo_set_color_and_alpha (svg_cairo_t *svg_cairo,
+				svg_color_t *color,
+				double alpha)
 {
-    cairo_set_alpha (svg_cairo->cr, alpha);
+    if (color->is_current_color)
+	color = &svg_cairo->state->color;
+
+    cairo_set_source_rgba (svg_cairo->cr,
+			   svg_color_get_red   (color) / 255.0,
+			   svg_color_get_green (color) / 255.0,
+			   svg_color_get_blue  (color) / 255.0,
+			   alpha);
 
     return _cairo_status_to_svg_status (cairo_status (svg_cairo->cr));
 }
@@ -602,11 +601,11 @@
     
     for (i = 0; i < gradient->num_stops; i++) {
 	stop = &gradient->stops[i];
-	cairo_pattern_add_color_stop (pattern, stop->offset,
-				      svg_color_get_red (&stop->color) / 255.0,
-				      svg_color_get_green (&stop->color) / 255.0,
-				      svg_color_get_blue (&stop->color) / 255.0,
-				      stop->opacity);
+	cairo_pattern_add_color_stop_rgba (pattern, stop->offset,
+					   svg_color_get_red (&stop->color) / 255.0,
+					   svg_color_get_green (&stop->color) / 255.0,
+					   svg_color_get_blue (&stop->color) / 255.0,
+					   stop->opacity);
     }
 	    
     switch (gradient->spread) {
@@ -694,11 +693,15 @@
 {
     svg_status_t status;
 
+    opacity *= svg_cairo->state->opacity;
+    
     switch (paint->type) {
     case SVG_PAINT_TYPE_NONE:
 	break;
     case SVG_PAINT_TYPE_COLOR:
-	status = _svg_cairo_set_color (svg_cairo, &paint->p.color);
+	status = _svg_cairo_set_color_and_alpha (svg_cairo,
+						 &paint->p.color,
+						 opacity);
 	if (status)
 	    return status;
 	break;
@@ -714,10 +717,6 @@
 	break;
     }
     
-    status = _svg_cairo_set_alpha (svg_cairo, opacity * svg_cairo->state->opacity);
-    if (status)
-        return status;
-
     return SVG_STATUS_SUCCESS;
 }
 
@@ -1219,6 +1218,8 @@
     cairo_surface_t *surface;
     double x, y, width, height;
 
+    cairo_save (svg_cairo->cr);
+
     _svg_cairo_length_to_pixel (svg_cairo, x_len, &x);
     _svg_cairo_length_to_pixel (svg_cairo, y_len, &y);
     _svg_cairo_length_to_pixel (svg_cairo, width_len, &width);
@@ -1228,7 +1229,11 @@
 					      data_width, data_height, data_width *4);
     cairo_move_to (svg_cairo->cr, x, y);
     cairo_scale (svg_cairo->cr, width / data_width, height / data_height);
+    /* XXX: Cairo is currently lacking the API we need here to paint
+     * an image with some translucence. */
+#if 0
     cairo_set_alpha (svg_cairo->cr, svg_cairo->state->opacity);
+#endif
 
     cairo_show_surface (svg_cairo->cr,
 			surface,
@@ -1236,6 +1241,8 @@
 
     cairo_surface_destroy (surface);
 
+    cairo_restore (svg_cairo->cr);
+
     return _cairo_status_to_svg_status (cairo_status (svg_cairo->cr));
 }
 




More information about the cairo-commit mailing list