[cairo-commit] cairo/test cairo-test.c, 1.76, 1.77 multi-page.c, 1.4, 1.5

Carl Worth commit at pdx.freedesktop.org
Thu Jan 19 17:48:25 PST 2006


Committed by: cworth

Update of /cvs/cairo/cairo/test
In directory gabe:/tmp/cvs-serv5604/test

Modified Files:
	cairo-test.c multi-page.c 
Log Message:
2006-01-19  Carl Worth  <cworth at cworth.org>

        * src/cairo-pdf.h:
        * src/cairo-pdf-surface.c:
        (_cairo_pdf_surface_create_for_stream_internal),
        (cairo_pdf_surface_create_for_stream), (cairo_pdf_surface_create):
        * src/cairo-ps.h:
        * src/cairo-ps-surface.c:
        (_cairo_ps_surface_create_for_stream_internal),
        (cairo_ps_surface_create), (cairo_ps_surface_create_for_stream):

        Rip the cairo_content_t argument out of ps/pdf_surface_create as
        per discussion on cairo mailing list. Instead these surface will
        behave as if CONTENT_COLOR_ALPHA had been passed (that is,
        compositing operators will behave as if destination alpha were
        available).

        This also has the benefit of preserving the API that has been in
        place for PS/PDF surface since the (experimental) stuff in 1.0.0.

        * test/cairo-test.c: (create_ps_surface), (create_pdf_surface):
        * test/multi-page.c: (main): Track API change.

        * test/cairo-test.c: (ps_surface_write_to_png),
        (pdf_surface_write_to_png): Continue testing PS/PDF surfaces in
        the CAIRO_CONTENT_COLOR mode but do it by rendering to an
        intermediate similar surface rather than constructing the target
        surface differently.


Index: cairo-test.c
===================================================================
RCS file: /cvs/cairo/cairo/test/cairo-test.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- cairo-test.c	19 Jan 2006 00:40:17 -0000	1.76
+++ cairo-test.c	20 Jan 2006 01:48:23 -0000	1.77
@@ -1100,8 +1100,10 @@
 
 typedef struct _ps_target_closure
 {
-    char    *filename;
-    int	    width, height;
+    char		*filename;
+    int			 width;
+    int			 height;
+    cairo_surface_t	*target;
 } ps_target_closure_t;
 
 static cairo_surface_t *
@@ -1116,24 +1118,35 @@
 
     /* Sanitize back to a real cairo_content_t value. */
     if (content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED)
-	content = CAIRO_CONTENT_COLOR_ALPHA;
+	content = CAIRO_CONTENT_COLOR_ALPHA; 
 
     *closure = ptc = xmalloc (sizeof (ps_target_closure_t));
 
-    ptc->width = width;
-    ptc->height = height;
-    
     xasprintf (&ptc->filename, "%s-ps-%s-out.ps",
 	       test->name, _cairo_test_content_name (content));
 
-    surface = cairo_ps_surface_create (ptc->filename, content, width, height);
+    ptc->width = width;
+    ptc->height = height;
+
+    surface = cairo_ps_surface_create (ptc->filename, width, height);
     if (cairo_surface_status (surface)) {
 	free (ptc->filename);
 	free (ptc);
 	return NULL;
     }
     cairo_ps_surface_set_dpi (surface, 72., 72.);
+
+    if (content == CAIRO_CONTENT_COLOR) {
+	ptc->target = surface;
+	surface = cairo_surface_create_similar (ptc->target,
+						CAIRO_CONTENT_COLOR,
+						width, height);
+    } else {
+	ptc->target = NULL;
+    }
+
     cairo_surface_set_user_data (surface, &ps_closure_key, ptc, NULL);
+
     return surface;
 }
 
@@ -1143,6 +1156,18 @@
     ps_target_closure_t *ptc = cairo_surface_get_user_data (surface, &ps_closure_key);
     char    command[4096];
 
+    if (ptc->target) {
+	cairo_t *cr;
+	cr = cairo_create (ptc->target);
+	cairo_set_source_surface (cr, surface, 0, 0);
+	cairo_paint (cr);
+	cairo_show_page (cr);
+	cairo_destroy (cr);
+
+	cairo_surface_finish (surface);
+	surface = ptc->target;
+    }
+
     cairo_surface_finish (surface);
     sprintf (command, "gs -q -r72 -g%dx%d -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -sOutputFile=%s %s",
 	     ptc->width, ptc->height, filename, ptc->filename);
@@ -1167,9 +1192,10 @@
 
 typedef struct _pdf_target_closure
 {
-    char *filename;
-    int   width;
-    int   height;
+    char		*filename;
+    int			 width;
+    int			 height;
+    cairo_surface_t	*target;
 } pdf_target_closure_t;
 
 static cairo_surface_t *
@@ -1194,14 +1220,25 @@
     xasprintf (&ptc->filename, "%s-pdf-%s-out.pdf",
 	       test->name, _cairo_test_content_name (content));
 
-    surface = cairo_pdf_surface_create (ptc->filename, content, width, height);
+    surface = cairo_pdf_surface_create (ptc->filename, width, height);
     if (cairo_surface_status (surface)) {
 	free (ptc->filename);
 	free (ptc);
 	return NULL;
     }
     cairo_pdf_surface_set_dpi (surface, 72., 72.);
+
+    if (content == CAIRO_CONTENT_COLOR) {
+	ptc->target = surface;
+	surface = cairo_surface_create_similar (ptc->target,
+						CAIRO_CONTENT_COLOR,
+						width, height);
+    } else {
+	ptc->target = NULL;
+    }
+
     cairo_surface_set_user_data (surface, &pdf_closure_key, ptc, NULL);
+
     return surface;
 }
 
@@ -1211,6 +1248,18 @@
     pdf_target_closure_t *ptc = cairo_surface_get_user_data (surface, &pdf_closure_key);
     char    command[4096];
 
+    if (ptc->target) {
+	cairo_t *cr;
+	cr = cairo_create (ptc->target);
+	cairo_set_source_surface (cr, surface, 0, 0);
+	cairo_paint (cr);
+	cairo_show_page (cr);
+	cairo_destroy (cr);
+
+	cairo_surface_finish (surface);
+	surface = ptc->target;
+    }
+
     cairo_surface_finish (surface);
     sprintf (command, "./pdf2png %s %s 1",
 	     ptc->filename, filename);

Index: multi-page.c
===================================================================
RCS file: /cvs/cairo/cairo/test/multi-page.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- multi-page.c	19 Jan 2006 00:40:17 -0000	1.4
+++ multi-page.c	20 Jan 2006 01:48:23 -0000	1.5
@@ -139,7 +139,7 @@
 #if CAIRO_HAS_PS_SURFACE
     filename = "multi-page.ps";
 
-    surface = cairo_ps_surface_create (filename, CAIRO_CONTENT_COLOR,
+    surface = cairo_ps_surface_create (filename,
 				       WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
     status = cairo_surface_status (surface);
     if (status) {
@@ -158,7 +158,7 @@
 #if CAIRO_HAS_PDF_SURFACE
     filename = "multi-page.pdf";
 
-    surface = cairo_pdf_surface_create (filename, CAIRO_CONTENT_COLOR,
+    surface = cairo_pdf_surface_create (filename,
 					WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
     status = cairo_surface_status (surface);
     if (status) {



More information about the cairo-commit mailing list