[cairo-commit] svg2png/src svg2png.c,1.7,1.8

Keith Packard commit at pdx.freedesktop.org
Thu May 12 11:35:01 PDT 2005


Committed by: keithp

Update of /cvs/cairo/svg2png/src
In directory gabe:/tmp/cvs-serv18734/src

Modified Files:
	svg2png.c 
Log Message:
2005-05-12  Keith Packard  <keithp at keithp.com>

	reviewed by: cworth

	* src/svg2png.c: (render_to_png):
	Adapt to  changes in the cairo API.
	Clean up various valgrind-related issues.


Index: svg2png.c
===================================================================
RCS file: /cvs/cairo/svg2png/src/svg2png.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- svg2png.c	26 Apr 2005 20:03:33 -0000	1.7
+++ svg2png.c	12 May 2005 18:34:59 -0000	1.8
@@ -122,8 +122,8 @@
     svg_cairo_status_t status;
     cairo_t *cr;
     svg_cairo_t *svgc;
-
-    cr = cairo_create ();
+    cairo_surface_t *surface;
+    double dx = 0, dy = 0;
 
     status = svg_cairo_create (&svgc);
     if (status) {
@@ -147,30 +147,36 @@
 	scale = (double) width / (double) svg_width;
 	height = (svg_height * scale + 0.5);
     } else {
-	int dx, dy;
 	scale = MIN ((double) width / (double) svg_width, (double) height / (double) svg_height);
 	/* Center the resulting image */
 	dx = (width - (int) (svg_width * scale + 0.5)) / 2;
 	dy = (height - (int) (svg_height * scale + 0.5)) / 2;
-	cairo_translate (cr, dx, dy);
     }
 
-    cairo_scale (cr, scale, scale);
+    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+    cr = cairo_create (surface);
+    
+    cairo_save (cr);
+    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+    cairo_paint (cr);
+    cairo_restore (cr);
 
-    cairo_set_target_image_no_data (cr, CAIRO_FORMAT_ARGB32, width, height);
+    cairo_translate (cr, dx, dy);
+    cairo_scale (cr, scale, scale);
 
     /* XXX: This probably doesn't need to be here (eventually) */
-    cairo_set_rgb_color (cr, 1, 1, 1);
+    cairo_set_source_rgb (cr, 1, 1, 1);
 
     status = svg_cairo_render (svgc, cr);
 
-    status = write_surface_to_png_file (cairo_get_target_surface (cr), png_file);
+    status = write_surface_to_png_file (surface, png_file);
+    cairo_surface_destroy (surface);
+    cairo_destroy (cr);
+    
     if (status)
 	return status;
 
     svg_cairo_destroy (svgc);
 
-    cairo_destroy (cr);
-
     return status;
 }




More information about the cairo-commit mailing list