[cairo-commit] cairo/src cairo-output-stream.c, 1.4, 1.5 cairo-pdf-surface.c, 1.35, 1.36 cairo-pdf.h, 1.10, 1.11 cairo-ps-surface.c, 1.34, 1.35 cairo-ps.h, 1.6, 1.7 cairoint.h, 1.142, 1.143

Carl Worth commit at pdx.freedesktop.org
Tue May 17 05:58:04 PDT 2005


Committed by: cworth

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

Modified Files:
	cairo-output-stream.c cairo-pdf-surface.c cairo-pdf.h 
	cairo-ps-surface.c cairo-ps.h cairoint.h 
Log Message:

        * src/cairoint.h:
        * src/cairo-output-stream.c: Remove destroy_closure from
        cairo_output_stream_t interface.

        * src/cairo-pdf.h:
        * src/cairo-pdf-surface.c: Remove destroy_closure argument from
        cairo_pdf_surface_create_for_stream. Rename width,height to
        width_in_points, height_in_points for better clarity.

        * src/cairo-ps.h:
        * src/cairo-ps-surface.c: Brush a bunch of dust off of the PS
        backend and bring it up to date with the latest API conventions
        from the PDF backend. These include: accepting a filename rather
        than a FILE in the primary constructor, providing a stream-based
        interface for more flexibility, and accepting a surface size in
        device-space units (points) rather than inches.

        * test/pdf-surface.c: (main): Make it a little more clear that the
        width and height being passed around are in units of points.

        * test/ps-surface.c: (main): Update to the latest cairo-ps.h
        changes as described above. Notice how much more sane things
        become now that the surface size is described in device-space
        units.


Index: cairo-output-stream.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-output-stream.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cairo-output-stream.c	16 May 2005 18:41:42 -0000	1.4
+++ cairo-output-stream.c	17 May 2005 12:58:02 -0000	1.5
@@ -49,7 +49,6 @@
 
 cairo_output_stream_t *
 _cairo_output_stream_create (cairo_write_func_t		write_data,
-			     cairo_destroy_func_t	destroy_closure,
 			     void			*closure)
 {
     cairo_output_stream_t *stream;
@@ -59,7 +58,6 @@
 	return NULL;
 
     stream->write_data = write_data;
-    stream->destroy_closure = destroy_closure;
     stream->closure = closure;
     stream->position = 0;
     stream->status = CAIRO_STATUS_SUCCESS;
@@ -70,7 +68,6 @@
 void
 _cairo_output_stream_destroy (cairo_output_stream_t *stream)
 {
-    stream->destroy_closure (stream->closure);
     free (stream);
 }
 
@@ -255,20 +252,12 @@
 static cairo_status_t
 stdio_write (void *closure, const unsigned char *data, unsigned int length)
 {
-	FILE *fp = closure;
-
-	if (fwrite (data, 1, length, fp) == length)
-		return CAIRO_STATUS_SUCCESS;
-
-	return CAIRO_STATUS_WRITE_ERROR;
-}
+    FILE *fp = closure;
 
-static void
-stdio_destroy_closure (void *closure)
-{
-	FILE *fp = closure;
+    if (fwrite (data, 1, length, fp) == length)
+	return CAIRO_STATUS_SUCCESS;
 
-	fclose (fp);
+    return CAIRO_STATUS_WRITE_ERROR;
 }
 
 cairo_output_stream_t *
@@ -281,11 +270,9 @@
     if (fp == NULL)
 	return NULL;
     
-    stream = _cairo_output_stream_create (stdio_write,
-					  stdio_destroy_closure, fp);
+    stream = _cairo_output_stream_create (stdio_write, fp);
     if (stream == NULL)
 	fclose (fp);
 
     return stream;
 }
-

Index: cairo-pdf-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-pdf-surface.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- cairo-pdf-surface.c	16 May 2005 18:41:42 -0000	1.35
+++ cairo-pdf-surface.c	17 May 2005 12:58:02 -0000	1.36
@@ -903,9 +903,9 @@
 }
 
 static cairo_surface_t *
-_cairo_pdf_surface_create_for_stream (cairo_output_stream_t	*stream,
-				      double			width,
-				      double			height)
+_cairo_pdf_surface_create_for_stream_internal (cairo_output_stream_t	*stream,
+					       double			width,
+					       double			height)
 {
     cairo_pdf_document_t *document;
     cairo_surface_t *surface;
@@ -924,18 +924,17 @@
 
 cairo_surface_t *
 cairo_pdf_surface_create_for_stream (cairo_write_func_t		write,
-				     cairo_destroy_func_t	destroy_closure,
 				     void			*closure,
 				     double			width,
 				     double			height)
 {
     cairo_output_stream_t *stream;
 
-    stream = _cairo_output_stream_create (write, destroy_closure, closure);
+    stream = _cairo_output_stream_create (write, closure);
     if (stream == NULL)
 	return NULL;
 
-    return _cairo_pdf_surface_create_for_stream (stream, width, height);
+    return _cairo_pdf_surface_create_for_stream_internal (stream, width, height);
 }
 
 cairo_surface_t *
@@ -949,7 +948,7 @@
     if (stream == NULL)
 	return NULL;
 
-    return _cairo_pdf_surface_create_for_stream (stream, width, height);
+    return _cairo_pdf_surface_create_for_stream_internal (stream, width, height);
 }
 
 void

Index: cairo-pdf.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-pdf.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- cairo-pdf.h	16 May 2005 18:41:42 -0000	1.10
+++ cairo-pdf.h	17 May 2005 12:58:02 -0000	1.11
@@ -44,19 +44,18 @@
 CAIRO_BEGIN_DECLS
 
 cairo_surface_t *
-cairo_pdf_surface_create (const char	*filename,
-			  double	width,
-			  double	height);
+cairo_pdf_surface_create (const char   *filename,
+			  double	width_in_points,
+			  double	height_in_points);
 
 cairo_surface_t *
-cairo_pdf_surface_create_for_stream (cairo_write_func_t		write_func,
-				     cairo_destroy_func_t	destroy_closure_func,
-				     void			*closure,
-				     double			width,
-				     double			height);
+cairo_pdf_surface_create_for_stream (cairo_write_func_t	write_func,
+				     void	       *closure,
+				     double		width_in_points,
+				     double		height_in_points);
 
 void
-cairo_pdf_surface_set_dpi (cairo_surface_t	*surface,
+cairo_pdf_surface_set_dpi (cairo_surface_t     *surface,
 			   double		x_dpi,
 			   double		y_dpi);
 

Index: cairo-ps-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-ps-surface.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- cairo-ps-surface.c	6 May 2005 20:26:16 -0000	1.34
+++ cairo-ps-surface.c	17 May 2005 12:58:02 -0000	1.35
@@ -46,30 +46,30 @@
     cairo_surface_t base;
 
     /* PS-specific fields */
-    FILE *file;
+    cairo_output_stream_t *stream;
 
-    double width_inches;
-    double height_inches;
-    double x_ppi;
-    double y_ppi;
+    double width_in_points;
+    double height_in_points;
+    double x_dpi;
+    double y_dpi;
 
     int pages;
 
     cairo_image_surface_t *image;
 } cairo_ps_surface_t;
 
+#define PS_SURFACE_DPI_DEFAULT 300.0
+
 static void
 _cairo_ps_surface_erase (cairo_ps_surface_t *surface);
 
-cairo_surface_t *
-cairo_ps_surface_create (FILE	*file,
-			 double	width_inches,
-			 double height_inches,
-			 double	x_pixels_per_inch,
-			 double	y_pixels_per_inch)
+static cairo_surface_t *
+_cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream,
+					      double	    width_in_points,
+					      double	   height_in_points)
 {
     cairo_ps_surface_t *surface;
-    int width, height;
+    int width_in_pixels, height_in_pixels;
     time_t now = time (0);
 
     surface = malloc (sizeof (cairo_ps_surface_t));
@@ -78,20 +78,21 @@
 
     _cairo_surface_init (&surface->base, &cairo_ps_surface_backend);
 
-    surface->file = file;
+    surface->stream = stream;
 
-    surface->width_inches = width_inches;
-    surface->height_inches = height_inches;
-    surface->x_ppi = x_pixels_per_inch;
-    surface->y_ppi = x_pixels_per_inch;
+    surface->width_in_points  = width_in_points;
+    surface->height_in_points = height_in_points;
+    surface->x_dpi = PS_SURFACE_DPI_DEFAULT;
+    surface->y_dpi = PS_SURFACE_DPI_DEFAULT;
 
     surface->pages = 0;
 
-    width = (int) (x_pixels_per_inch * width_inches + 1.0);
-    height = (int) (y_pixels_per_inch * height_inches + 1.0);
+    width_in_pixels = (int) (surface->x_dpi * width_in_points / 72.0 + 1.0);
+    height_in_pixels = (int) (surface->y_dpi * height_in_points / 72.0 + 1.0);
 
     surface->image = (cairo_image_surface_t *)
-	cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+	cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+				    width_in_pixels, height_in_pixels);
     if (surface->image == NULL) {
 	free (surface);
 	return NULL;
@@ -100,26 +101,61 @@
     _cairo_ps_surface_erase (surface);
 
     /* Document header */
-    fprintf (file,
-	     "%%!PS-Adobe-3.0\n"
-	     "%%%%Creator: Cairo (http://cairographics.org)\n");
-    fprintf (file,
-	     "%%%%CreationDate: %s",
-	     ctime (&now));
-    fprintf (file,
-	     "%%%%BoundingBox: %d %d %d %d\n",
-	     0, 0, (int) (surface->width_inches * 72.0), (int) (surface->height_inches * 72.0));
+    _cairo_output_stream_printf (surface->stream,
+				 "%%!PS-Adobe-3.0\n"
+				 "%%%%Creator: Cairo (http://cairographics.org)\n");
+    _cairo_output_stream_printf (surface->stream,
+				 "%%%%CreationDate: %s",
+				 ctime (&now));
+    _cairo_output_stream_printf (surface->stream,
+				 "%%%%BoundingBox: %f %f %f %f\n",
+				 0.0, 0.0,
+				 surface->width_in_points,
+				 surface->height_in_points);
     /* The "/FlateDecode filter" currently used is a feature of LanguageLevel 3 */
-    fprintf (file,
-	     "%%%%DocumentData: Clean7Bit\n"
-	     "%%%%LanguageLevel: 3\n");
-    fprintf (file,
-	     "%%%%Orientation: Portrait\n"
-	     "%%%%EndComments\n");
+    _cairo_output_stream_printf (surface->stream,
+				 "%%%%DocumentData: Clean7Bit\n"
+				 "%%%%LanguageLevel: 3\n");
+    _cairo_output_stream_printf (surface->stream,
+				 "%%%%Orientation: Portrait\n"
+				 "%%%%EndComments\n");
 
     return &surface->base;
 }
 
+cairo_surface_t *
+cairo_ps_surface_create (const char    *filename,
+			 double		width_in_points,
+			 double		height_in_points)
+{
+    cairo_output_stream_t *stream;
+
+    stream = _cairo_output_stream_create_for_file (filename);
+    if (stream == NULL)
+	return NULL;
+
+    return _cairo_ps_surface_create_for_stream_internal (stream,
+							 width_in_points,
+							 height_in_points);
+}
+
+cairo_surface_t *
+cairo_ps_surface_create_for_stream (cairo_write_func_t	write_func,
+				    void	       *closure,
+				    double		width_in_points,
+				    double		height_in_points)
+{
+    cairo_output_stream_t *stream;
+
+    stream = _cairo_output_stream_create (write_func, closure);
+    if (stream == NULL)
+	return NULL;
+
+    return _cairo_ps_surface_create_for_stream_internal (stream,
+							 width_in_points,
+							 height_in_points);
+}
+
 static cairo_surface_t *
 _cairo_ps_surface_create_similar (void		*abstract_src,
 				 cairo_format_t	format,
@@ -136,7 +172,8 @@
     cairo_ps_surface_t *surface = abstract_surface;
 
     /* Document footer */
-    fprintf (surface->file, "%%%%EOF\n");
+    _cairo_output_stream_printf (surface->stream,
+				 "%%%%EOF\n");
 
     cairo_surface_destroy (&surface->image->base);
 
@@ -192,7 +229,7 @@
     cairo_ps_surface_t *surface = abstract_surface;
     int width = surface->image->width;
     int height = surface->image->height;
-    FILE *file = surface->file;
+    cairo_output_stream_t *stream = surface->stream;
 
     int i, x, y;
 
@@ -243,34 +280,34 @@
     compress (compressed, &compressed_size, rgb, rgb_size);
 
     /* Page header */
-    fprintf (file, "%%%%Page: %d\n", ++surface->pages);
+    _cairo_output_stream_printf (stream, "%%%%Page: %d\n", ++surface->pages);
 
-    fprintf (file, "gsave\n");
+    _cairo_output_stream_printf (stream, "gsave\n");
 
     /* Image header goop */
-    fprintf (file, "%g %g translate\n", 0.0, surface->height_inches * 72.0);
-    fprintf (file, "%g %g scale\n", 72.0 / surface->x_ppi, 72.0 / surface->y_ppi);
-    fprintf (file, "/DeviceRGB setcolorspace\n");
-    fprintf (file, "<<\n");
-    fprintf (file, "	/ImageType 1\n");
-    fprintf (file, "	/Width %d\n", width);
-    fprintf (file, "	/Height %d\n", height);
-    fprintf (file, "	/BitsPerComponent 8\n");
-    fprintf (file, "	/Decode [ 0 1 0 1 0 1 ]\n");
-    fprintf (file, "	/DataSource currentfile /FlateDecode filter\n");
-    fprintf (file, "	/ImageMatrix [ 1 0 0 -1 0 1 ]\n");
-    fprintf (file, ">>\n");
-    fprintf (file, "image\n");
+    _cairo_output_stream_printf (stream, "%f %f translate\n",
+				 0.0, surface->height_in_points);
+    _cairo_output_stream_printf (stream, "/DeviceRGB setcolorspace\n");
+    _cairo_output_stream_printf (stream, "<<\n");
+    _cairo_output_stream_printf (stream, "	/ImageType 1\n");
+    _cairo_output_stream_printf (stream, "	/Width %d\n", width);
+    _cairo_output_stream_printf (stream, "	/Height %d\n", height);
+    _cairo_output_stream_printf (stream, "	/BitsPerComponent 8\n");
+    _cairo_output_stream_printf (stream, "	/Decode [ 0 1 0 1 0 1 ]\n");
+    _cairo_output_stream_printf (stream, "	/DataSource currentfile /FlateDecode filter\n");
+    _cairo_output_stream_printf (stream, "	/ImageMatrix [ 1 0 0 -1 0 1 ]\n");
+    _cairo_output_stream_printf (stream, ">>\n");
+    _cairo_output_stream_printf (stream, "image\n");
 
     /* Compressed image data */
-    fwrite (compressed, 1, compressed_size, file);
+    _cairo_output_stream_write (stream, compressed, compressed_size);
 
-    fprintf (file, "showpage\n");
+    _cairo_output_stream_printf (stream, "showpage\n");
 
-    fprintf (file, "grestore\n");
+    _cairo_output_stream_printf (stream, "grestore\n");
 
     /* Page footer */
-    fprintf (file, "%%%%EndPage\n");
+    _cairo_output_stream_printf (stream, "%%%%EndPage\n");
 
     free (compressed);
     BAIL1:
@@ -316,8 +353,8 @@
      * mention the aribitray limitation of width to a short(!). We
      * may need to come up with a better interface for get_size.
      */
-    rectangle->width  = (surface->width_inches  * 72.0 + 0.5);
-    rectangle->height = (surface->height_inches * 72.0 + 0.5);
+    rectangle->width  = (surface->width_in_points + 0.5);
+    rectangle->height = (surface->height_in_points + 0.5);
 
     return CAIRO_STATUS_SUCCESS;
 }

Index: cairo-ps.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-ps.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- cairo-ps.h	14 May 2005 17:03:56 -0000	1.6
+++ cairo-ps.h	17 May 2005 12:58:02 -0000	1.7
@@ -48,11 +48,20 @@
 /* PS-surface functions */
 
 cairo_surface_t *
-cairo_ps_surface_create (FILE	*file,
-			 double	width_inches,
-			 double height_inches,
-			 double	x_pixels_per_inch,
-			 double	y_pixels_per_inch);
+cairo_ps_surface_create (const char *filename,
+			 double	     width_in_points,
+			 double	     height_in_points);
+
+cairo_surface_t *
+cairo_ps_surface_create_for_stream (cairo_write_func_t	write_func,
+				    void	       *closure,
+				    double		width_in_points,
+				    double		height_in_points);
+
+void
+cairo_ps_surface_set_dpi (cairo_surface_t      *surface,
+			  double		x_dpi,
+			  double		y_dpi);
 
 CAIRO_END_DECLS
 

Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.142
retrieving revision 1.143
diff -u -d -r1.142 -r1.143
--- cairoint.h	16 May 2005 18:41:42 -0000	1.142
+++ cairoint.h	17 May 2005 12:58:02 -0000	1.143
@@ -1773,7 +1773,6 @@
 
 cairo_private cairo_output_stream_t *
 _cairo_output_stream_create (cairo_write_func_t		write_func,
-			     cairo_destroy_func_t	destroy_closure_func,
 			     void			*closure);
 
 cairo_private void




More information about the cairo-commit mailing list