[cairo-commit] svg2png/src svg2png.c,1.2,1.3

Carl Worth commit at pdx.freedesktop.org
Fri Jun 4 09:10:32 PDT 2004


Committed by: cworth

Update of /cvs/cairo/svg2png/src
In directory pdx:/tmp/cvs-serv657/src

Modified Files:
	svg2png.c 
Log Message:

        * src/svg2png.c (main): Close open files before exiting.
        (render_to_png): Handle the --width and --height options in a more
        intelligent way. They will now automatically trigger scaling as
        necessary (but never distorting the original aspect ratio). If
        both are provided, and with an inconsisent aspect ratio, the
        rendering will be centered in the extra space. It's now possible
        to simply provide one of these options and the other one will be
        computed based on the aspect ratio.


Index: svg2png.c
===================================================================
RCS file: /cvs/cairo/svg2png/src/svg2png.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** a/svg2png.c	4 May 2004 02:02:30 -0000	1.2
--- b/svg2png.c	4 Jun 2004 16:10:30 -0000	1.3
***************
*** 83,86 ****
--- 83,91 ----
      }
  
+     if (svg_file != stdin)
+ 	fclose (svg_file);
+     if (png_file != stdout)
+ 	fclose (png_file);
+ 
      return 0;
  }
***************
*** 89,92 ****
--- 94,99 ----
  render_to_png (FILE *svg_file, FILE *png_file, double scale, int width, int height)
  {
+     int svg_width, svg_height;
+ 
      svg_cairo_status_t status;
      cairo_t *cr;
***************
*** 105,112 ****
  	return status;
  
!     if (width < 0 || height < 0) {
! 	svg_cairo_get_size (svgc, &width, &height);
! 	width = (width * scale + 0.5);
! 	height = (height * scale + 0.5);
      }
  
--- 112,133 ----
  	return status;
  
!     svg_cairo_get_size (svgc, &svg_width, &svg_height);
! 
!     if (width < 0 && height < 0) {
! 	width = (svg_width * scale + 0.5);
! 	height = (svg_height * scale + 0.5);
!     } else if (width < 0) {
! 	scale = (double) height / (double) svg_height;
! 	width = (svg_width * scale + 0.5);
!     } else if (height < 0) {
! 	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);
      }
  





More information about the cairo-commit mailing list