diff options
-rw-r--r-- | ChangeLog | 29 | ||||
-rw-r--r-- | src/cairo-pdf-surface.c | 27 | ||||
-rw-r--r-- | src/cairo-pdf.h | 2 | ||||
-rw-r--r-- | src/cairo-ps-surface.c | 24 | ||||
-rw-r--r-- | src/cairo-ps.h | 2 | ||||
-rw-r--r-- | test/cairo-test.c | 71 | ||||
-rw-r--r-- | test/multi-page.c | 4 |
7 files changed, 98 insertions, 61 deletions
@@ -1,3 +1,32 @@ +2006-01-19 Carl Worth <cworth@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. + 2005-01-19 Emmanuel Pacaud <emmanuel.pacaud@free.fr> * test/svg2png.c: add missing header. Fix #5544. diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c index b33db42a3..ee5c482cf 100644 --- a/src/cairo-pdf-surface.c +++ b/src/cairo-pdf-surface.c @@ -287,7 +287,6 @@ _cairo_pdf_surface_add_font (cairo_pdf_surface_t *surface, unsigned int id) static cairo_surface_t * _cairo_pdf_surface_create_for_stream_internal (cairo_output_stream_t *stream, - cairo_content_t content, double width, double height) { @@ -305,27 +304,21 @@ _cairo_pdf_surface_create_for_stream_internal (cairo_output_stream_t *stream, document->owner = target; _cairo_pdf_document_destroy (document); - return _cairo_paginated_surface_create (target, content, width, height); + return _cairo_paginated_surface_create (target, + CAIRO_CONTENT_COLOR_ALPHA, + width, height); } /** * cairo_pdf_surface_create_for_stream: * @write: a #cairo_write_func_t to accept the output data * @closure: the closure argument for @write - * @content: CAIRO_CONTENT_COLOR_ALPHA or CAIRO_CONTENT_COLOR * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) * * Creates a PDF surface of the specified size in points to be written * incrementally to the stream represented by @write and @closure. * - * The @content argument is used to specify whether the rendering - * semantics should behave as if destination alpha is available. The - * expectation is that the value for @content will be selected to - * achieve consistent results with a display surface that either has - * or does not have destination alpha (for example, - * CAIRO_FORMAT_ARGB32 vs. CAIRO_FORMAT_RGB24). - * * Return value: a pointer to the newly created surface. The caller * owns the surface and should call cairo_surface_destroy when done * with it. @@ -337,7 +330,6 @@ _cairo_pdf_surface_create_for_stream_internal (cairo_output_stream_t *stream, cairo_surface_t * cairo_pdf_surface_create_for_stream (cairo_write_func_t write, void *closure, - cairo_content_t content, double width_in_points, double height_in_points) { @@ -349,7 +341,7 @@ cairo_pdf_surface_create_for_stream (cairo_write_func_t write, return (cairo_surface_t*) &_cairo_surface_nil; } - return _cairo_pdf_surface_create_for_stream_internal (stream, content, + return _cairo_pdf_surface_create_for_stream_internal (stream, width_in_points, height_in_points); } @@ -357,19 +349,11 @@ cairo_pdf_surface_create_for_stream (cairo_write_func_t write, /** * cairo_pdf_surface_create: * @filename: a filename for the PDF output (must be writable) - * @content: CAIRO_CONTENT_COLOR_ALPHA or CAIRO_CONTENT_COLOR * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) * * Creates a PDF surface of the specified size in points to be written * to @filename. - * - * The @content argument is used to specify whether the rendering - * semantics should behave as if destination alpha is available. The - * expectation is that the value for @content will be selected to - * achieve consistent results with a display surface that either has - * or does not have destination alpha (for example, - * CAIRO_FORMAT_ARGB32 vs. CAIRO_FORMAT_RGB24). * * Return value: a pointer to the newly created surface. The caller * owns the surface and should call cairo_surface_destroy when done @@ -381,7 +365,6 @@ cairo_pdf_surface_create_for_stream (cairo_write_func_t write, **/ cairo_surface_t * cairo_pdf_surface_create (const char *filename, - cairo_content_t content, double width_in_points, double height_in_points) { @@ -393,7 +376,7 @@ cairo_pdf_surface_create (const char *filename, return (cairo_surface_t*) &_cairo_surface_nil; } - return _cairo_pdf_surface_create_for_stream_internal (stream, content, + return _cairo_pdf_surface_create_for_stream_internal (stream, width_in_points, height_in_points); } diff --git a/src/cairo-pdf.h b/src/cairo-pdf.h index 1740a4700..abcab0f3f 100644 --- a/src/cairo-pdf.h +++ b/src/cairo-pdf.h @@ -45,14 +45,12 @@ CAIRO_BEGIN_DECLS cairo_public cairo_surface_t * cairo_pdf_surface_create (const char *filename, - cairo_content_t content, double width_in_points, double height_in_points); cairo_public cairo_surface_t * cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func, void *closure, - cairo_content_t content, double width_in_points, double height_in_points); diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c index 78e0aee01..6cf862170 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -122,7 +122,6 @@ _cairo_ps_surface_emit_footer (cairo_ps_surface_t *surface) static cairo_surface_t * _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream, - cairo_content_t content, double width, double height) { @@ -157,26 +156,19 @@ _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream, _cairo_ps_surface_emit_header (surface); return _cairo_paginated_surface_create (&surface->base, - content, width, height); + CAIRO_CONTENT_COLOR_ALPHA, + width, height); } /** * cairo_ps_surface_create: * @filename: a filename for the PS output (must be writable) - * @content: CAIRO_CONTENT_COLOR_ALPHA or CAIRO_CONTENT_COLOR * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) * * Creates a PostScript surface of the specified size in points to be * written to @filename. * - * The @content argument is used to specify whether the rendering - * semantics should behave as if destination alpha is available. The - * expectation is that the value for @content will be selected to - * achieve consistent results with a display surface that either has - * or does not have destination alpha (for example, - * CAIRO_FORMAT_ARGB32 vs. CAIRO_FORMAT_RGB24). - * * Return value: a pointer to the newly created surface. The caller * owns the surface and should call cairo_surface_destroy when done * with it. @@ -187,7 +179,6 @@ _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream, **/ cairo_surface_t * cairo_ps_surface_create (const char *filename, - cairo_content_t content, double width_in_points, double height_in_points) { @@ -200,7 +191,6 @@ cairo_ps_surface_create (const char *filename, } return _cairo_ps_surface_create_for_stream_internal (stream, - content, width_in_points, height_in_points); } @@ -209,7 +199,6 @@ cairo_ps_surface_create (const char *filename, * cairo_ps_surface_create_for_stream: * @write: a #cairo_write_func_t to accept the output data * @closure: the closure argument for @write - * @content: CAIRO_CONTENT_COLOR_ALPHA or CAIRO_CONTENT_COLOR * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch) * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch) * @@ -217,13 +206,6 @@ cairo_ps_surface_create (const char *filename, * written incrementally to the stream represented by @write and * @closure. * - * The @content argument is used to specify whether the rendering - * semantics should behave as if destination alpha is available. The - * expectation is that the value for @content will be selected to - * achieve consistent results with a display surface that either has - * or does not have destination alpha (for example, - * CAIRO_FORMAT_ARGB32 vs. CAIRO_FORMAT_RGB24). - * * Return value: a pointer to the newly created surface. The caller * owns the surface and should call cairo_surface_destroy when done * with it. @@ -235,7 +217,6 @@ cairo_ps_surface_create (const char *filename, cairo_surface_t * cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, void *closure, - cairo_content_t content, double width_in_points, double height_in_points) { @@ -248,7 +229,6 @@ cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, } return _cairo_ps_surface_create_for_stream_internal (stream, - content, width_in_points, height_in_points); } diff --git a/src/cairo-ps.h b/src/cairo-ps.h index b37c99656..0db0c0220 100644 --- a/src/cairo-ps.h +++ b/src/cairo-ps.h @@ -49,14 +49,12 @@ CAIRO_BEGIN_DECLS cairo_public cairo_surface_t * cairo_ps_surface_create (const char *filename, - cairo_content_t content, double width_in_points, double height_in_points); cairo_public cairo_surface_t * cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, void *closure, - cairo_content_t content, double width_in_points, double height_in_points); diff --git a/test/cairo-test.c b/test/cairo-test.c index 0f4a1b0a4..58ec000c5 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -1100,8 +1100,10 @@ cairo_user_data_key_t ps_closure_key; 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 @@ create_ps_surface (cairo_test_t *test, /* 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_surface_write_to_png (cairo_surface_t *surface, const char *filename) 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 @@ cairo_user_data_key_t pdf_closure_key; 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 @@ create_pdf_surface (cairo_test_t *test, 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_surface_write_to_png (cairo_surface_t *surface, const char *filename) 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); diff --git a/test/multi-page.c b/test/multi-page.c index 9e28c3247..f6780b493 100644 --- a/test/multi-page.c +++ b/test/multi-page.c @@ -139,7 +139,7 @@ main (void) #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 @@ main (void) #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) { |