[cairo-commit] 3 commits - src/cairo-pdf-surface.c src/cairo-ps-surface.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Sun Apr 27 05:41:49 PDT 2008


 src/cairo-pdf-surface.c |   39 ++++++++++++++++++++++++++++++++-------
 src/cairo-ps-surface.c  |   26 ++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 7 deletions(-)

New commits:
commit 5e102b06d1a3c62a1dd0f381fbd1123961bebdf8
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Apr 27 21:51:05 2008 +0930

    PDF: Fix unbalanced save/restore

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index ed22322..42092f4 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -2610,7 +2610,6 @@ _cairo_pdf_surface_select_pattern (cairo_pdf_surface_t *surface,
         _cairo_output_stream_printf (surface->output,
                                      "/a%d gs\n",
                                      alpha);
-	surface->select_pattern_gstate_saved = FALSE;
     } else {
 	status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha);
 	if (status)
commit 3a2a86721096a5efdec25a3ec041d9fc7eec6cf8
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Apr 27 17:49:04 2008 +0930

    PS: Fix gradients with one stop

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index f6940bf..59f07ed 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -2618,6 +2618,19 @@ _cairo_ps_surface_emit_linear_pattern (cairo_ps_surface_t     *surface,
     if (pattern->base.n_stops == 0)
         return CAIRO_INT_STATUS_NOTHING_TO_DO;
 
+    if (pattern->base.n_stops == 1) {
+	cairo_solid_pattern_t solid;
+
+	_cairo_pattern_init_solid (&solid,
+				   &pattern->base.stops[0].color,
+				   CAIRO_CONTENT_COLOR_ALPHA);
+	_cairo_ps_surface_emit_solid_pattern (surface,
+					      &solid);
+	_cairo_pattern_fini (&solid.base);
+
+	return CAIRO_STATUS_SUCCESS;
+    }
+
     extend = cairo_pattern_get_extend (&pattern->base.base);
 
     pat_to_ps = pattern->base.base.matrix;
@@ -2745,6 +2758,19 @@ _cairo_ps_surface_emit_radial_pattern (cairo_ps_surface_t     *surface,
     if (pattern->base.n_stops == 0)
         return CAIRO_INT_STATUS_NOTHING_TO_DO;
 
+    if (pattern->base.n_stops == 1) {
+	cairo_solid_pattern_t solid;
+
+	_cairo_pattern_init_solid (&solid,
+				   &pattern->base.stops[0].color,
+				   CAIRO_CONTENT_COLOR_ALPHA);
+	_cairo_ps_surface_emit_solid_pattern (surface,
+					      &solid);
+	_cairo_pattern_fini (&solid.base);
+
+	return CAIRO_STATUS_SUCCESS;
+    }
+
     extend = cairo_pattern_get_extend (&pattern->base.base);
 
     pat_to_ps = pattern->base.base.matrix;
commit f99d86e7082a59f2c6e53f021f8fd62973a0d1ef
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Apr 27 17:32:41 2008 +0930

    PDF: Fix gradients with one stop

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index f82af83..ed22322 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -771,15 +771,23 @@ _cairo_pdf_surface_add_pdf_pattern (cairo_pdf_surface_t		*surface,
 	return CAIRO_STATUS_SUCCESS;
     }
 
-    /* Gradients with zero stops do not produce any output */
     if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR ||
         pattern->type == CAIRO_PATTERN_TYPE_RADIAL)
     {
 	cairo_gradient_pattern_t *gradient;
 
 	gradient = (cairo_gradient_pattern_t *) pattern;
+
+	/* Gradients with zero stops do not produce any output */
 	if (gradient->n_stops == 0)
 	    return CAIRO_INT_STATUS_NOTHING_TO_DO;
+
+	/* Gradients with one stop are the same as solid colors */
+	if (gradient->n_stops == 1) {
+	    pattern_res->id = 0;
+	    gstate_res->id = 0;
+	    return CAIRO_STATUS_SUCCESS;
+	}
     }
 
     pdf_pattern.pattern = cairo_pattern_reference (pattern);
@@ -2562,19 +2570,37 @@ _cairo_pdf_surface_select_pattern (cairo_pdf_surface_t *surface,
 {
     cairo_status_t status;
     int alpha;
+    cairo_bool_t is_solid_color = FALSE;
+    cairo_color_t *solid_color;
 
     if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) {
-	cairo_solid_pattern_t *solid_pattern = (cairo_solid_pattern_t *) pattern;
+	cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) pattern;
+
+	is_solid_color = TRUE;
+	solid_color = &solid->color;
+    }
+
+    if (pattern->type == CAIRO_PATTERN_TYPE_LINEAR ||
+	pattern->type == CAIRO_PATTERN_TYPE_RADIAL)
+    {
+	cairo_gradient_pattern_t *gradient = (cairo_gradient_pattern_t *) pattern;
+
+	if (gradient->n_stops == 1) {
+	    is_solid_color = TRUE;
+	    solid_color = &gradient->stops[0].color;
+	}
+    }
 
-	status = _cairo_pdf_surface_add_alpha (surface, solid_pattern->color.alpha, &alpha);
+    if (is_solid_color) {
+	status = _cairo_pdf_surface_add_alpha (surface, solid_color->alpha, &alpha);
 	if (status)
 	    return status;
 
 	_cairo_output_stream_printf (surface->output,
 				     "%f %f %f ",
-				     solid_pattern->color.red,
-				     solid_pattern->color.green,
-				     solid_pattern->color.blue);
+				     solid_color->red,
+				     solid_color->green,
+				     solid_color->blue);
 
 	if (is_stroke)
             _cairo_output_stream_printf (surface->output, "RG ");


More information about the cairo-commit mailing list