[cairo-commit] 7 commits - src/cairo-pdf-surface.c test/meta-surface-pattern.pdf.argb32.ref.png test/meta-surface-pattern.pdf.rgb24.ref.png test/rotate-image-surface-paint.pdf.xfail.png test/scale-offset-image.pdf.argb32.ref.png test/scale-offset-image.pdf.ref.png test/scale-offset-image.pdf.rgb24.ref.png test/scale-offset-similar.pdf.argb32.ref.png test/scale-offset-similar.pdf.ref.png test/scale-offset-similar.pdf.rgb24.ref.png test/surface-pattern-scale-down.pdf.ref.png test/surface-pattern-scale-up.pdf.ref.png

Adrian Johnson ajohnson at kemper.freedesktop.org
Mon Aug 31 06:46:10 PDT 2009


 dev/null                                      |binary
 src/cairo-pdf-surface.c                       |  106 +++++++++++++++++++++++---
 test/meta-surface-pattern.pdf.argb32.ref.png  |binary
 test/meta-surface-pattern.pdf.rgb24.ref.png   |binary
 test/rotate-image-surface-paint.pdf.xfail.png |binary
 test/scale-offset-image.pdf.argb32.ref.png    |binary
 test/scale-offset-image.pdf.rgb24.ref.png     |binary
 test/scale-offset-similar.pdf.argb32.ref.png  |binary
 test/scale-offset-similar.pdf.rgb24.ref.png   |binary
 test/surface-pattern-scale-down.pdf.ref.png   |binary
 test/surface-pattern-scale-up.pdf.ref.png     |binary
 11 files changed, 97 insertions(+), 9 deletions(-)

New commits:
commit aca1dff25967940c36caee26977512484f1720ac
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Mon Aug 31 22:28:26 2009 +0930

    PDF: Ensure operator is selected before painting surface

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 2b8dceb..6fa6133 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -5329,6 +5329,10 @@ _cairo_pdf_surface_paint (void			*abstract_surface,
     if (unlikely (status))
 	return status;
 
+    status = _cairo_pdf_surface_select_operator (surface, op);
+    if (unlikely (status))
+	return status;
+
     if (source->type == CAIRO_PATTERN_TYPE_SURFACE &&
 	  source->extend == CAIRO_EXTEND_NONE) {
 
@@ -5351,10 +5355,6 @@ _cairo_pdf_surface_paint (void			*abstract_surface,
     if (unlikely (status))
 	return status;
 
-    status = _cairo_pdf_surface_select_operator (surface, op);
-    if (unlikely (status))
-	return status;
-
     if (gstate_res.id != 0) {
 	group = _cairo_pdf_surface_create_smask_group (surface);
 	if (unlikely (group == NULL))
@@ -5627,6 +5627,10 @@ _cairo_pdf_surface_fill (void			*abstract_surface,
     if (unlikely (status))
 	return status;
 
+    status = _cairo_pdf_surface_select_operator (surface, op);
+    if (unlikely (status))
+	return status;
+
     if (source->type == CAIRO_PATTERN_TYPE_SURFACE &&
 	  source->extend == CAIRO_EXTEND_NONE) {
 
@@ -5655,10 +5659,6 @@ _cairo_pdf_surface_fill (void			*abstract_surface,
     if (unlikely (status))
 	return status;
 
-    status = _cairo_pdf_surface_select_operator (surface, op);
-    if (unlikely (status))
-	return status;
-
     if (gstate_res.id != 0) {
 	group = _cairo_pdf_surface_create_smask_group (surface);
 	if (unlikely (group == NULL))
commit a402bdbd32d3ffe4b564318e6dd83831328257b1
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Mon Aug 31 22:15:57 2009 +0930

    PDF: Flush operators before writing to the PDF stream

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 577d7e5..2b8dceb 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -3295,6 +3295,10 @@ _cairo_pdf_surface_paint_surface_pattern (cairo_pdf_surface_t     *surface,
     if (! _cairo_surface_is_meta (source->surface))
 	cairo_matrix_scale (&pdf_p2d, width, height);
 
+    status = _cairo_pdf_operators_flush (&surface->pdf_operators);
+    if (unlikely (status))
+	return status;
+
     if (! _cairo_matrix_is_identity (&pdf_p2d)) {
 	_cairo_output_stream_printf (surface->output,
 				     "%f %f %f %f %f %f cm\n",
commit 119355b2a4d81c903720484adaeb7dea3929ca1f
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Mon Aug 31 22:14:15 2009 +0930

    PDF: Reset alpha to 1.0 before painting a surface
    
    Fixes a test suite regression.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 8a6a83f..577d7e5 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -3272,6 +3272,7 @@ _cairo_pdf_surface_paint_surface_pattern (cairo_pdf_surface_t     *surface,
     int width, height;
     cairo_matrix_t cairo_p2d, pdf_p2d;
     cairo_status_t status;
+    int alpha;
 
     status = _cairo_pdf_surface_add_source_surface (surface,
 						    source->surface,
@@ -3302,8 +3303,13 @@ _cairo_pdf_surface_paint_surface_pattern (cairo_pdf_surface_t     *surface,
 				     pdf_p2d.x0, pdf_p2d.y0);
     }
 
+    status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha);
+    if (unlikely (status))
+	return status;
+
     _cairo_output_stream_printf (surface->output,
-				 "/x%d Do\n",
+				 "/a%d gs /x%d Do\n",
+				 alpha,
 				 surface_res.id);
 
     return _cairo_pdf_surface_add_xobject (surface, surface_res);
commit 20bd7d0edbb01a52bcc88bddcba4cc5237f3a673
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Mon Aug 31 22:03:34 2009 +0930

    Update ref images

diff --git a/test/meta-surface-pattern.pdf.argb32.ref.png b/test/meta-surface-pattern.pdf.argb32.ref.png
index 015f744..a06386b 100644
Binary files a/test/meta-surface-pattern.pdf.argb32.ref.png and b/test/meta-surface-pattern.pdf.argb32.ref.png differ
diff --git a/test/meta-surface-pattern.pdf.rgb24.ref.png b/test/meta-surface-pattern.pdf.rgb24.ref.png
index 1762e8a..bf69f9e 100644
Binary files a/test/meta-surface-pattern.pdf.rgb24.ref.png and b/test/meta-surface-pattern.pdf.rgb24.ref.png differ
diff --git a/test/rotate-image-surface-paint.pdf.xfail.png b/test/rotate-image-surface-paint.pdf.xfail.png
index 043732d..bf0bb0b 100644
Binary files a/test/rotate-image-surface-paint.pdf.xfail.png and b/test/rotate-image-surface-paint.pdf.xfail.png differ
diff --git a/test/scale-offset-image.pdf.argb32.ref.png b/test/scale-offset-image.pdf.argb32.ref.png
new file mode 100644
index 0000000..f7b5175
Binary files /dev/null and b/test/scale-offset-image.pdf.argb32.ref.png differ
diff --git a/test/scale-offset-image.pdf.ref.png b/test/scale-offset-image.pdf.ref.png
deleted file mode 100644
index 2de2d34..0000000
Binary files a/test/scale-offset-image.pdf.ref.png and /dev/null differ
diff --git a/test/scale-offset-image.pdf.rgb24.ref.png b/test/scale-offset-image.pdf.rgb24.ref.png
new file mode 100644
index 0000000..f7b5175
Binary files /dev/null and b/test/scale-offset-image.pdf.rgb24.ref.png differ
diff --git a/test/scale-offset-similar.pdf.argb32.ref.png b/test/scale-offset-similar.pdf.argb32.ref.png
new file mode 100644
index 0000000..f19b647
Binary files /dev/null and b/test/scale-offset-similar.pdf.argb32.ref.png differ
diff --git a/test/scale-offset-similar.pdf.ref.png b/test/scale-offset-similar.pdf.ref.png
deleted file mode 100644
index 94f1b68..0000000
Binary files a/test/scale-offset-similar.pdf.ref.png and /dev/null differ
diff --git a/test/scale-offset-similar.pdf.rgb24.ref.png b/test/scale-offset-similar.pdf.rgb24.ref.png
new file mode 100644
index 0000000..f19b647
Binary files /dev/null and b/test/scale-offset-similar.pdf.rgb24.ref.png differ
diff --git a/test/surface-pattern-scale-down.pdf.ref.png b/test/surface-pattern-scale-down.pdf.ref.png
index 7874243..5657b5c 100644
Binary files a/test/surface-pattern-scale-down.pdf.ref.png and b/test/surface-pattern-scale-down.pdf.ref.png differ
diff --git a/test/surface-pattern-scale-up.pdf.ref.png b/test/surface-pattern-scale-up.pdf.ref.png
index e7e7a81..97472fa 100644
Binary files a/test/surface-pattern-scale-up.pdf.ref.png and b/test/surface-pattern-scale-up.pdf.ref.png differ
commit 135912721f5791ad8eac773fd042c751122c8760
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Aug 30 23:58:53 2009 +0930

    PDF: Avoid using patterns when filling a surface with EXTEND_NONE
    
    The fill equivilant of the previous optimization.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 0ada8c0..8a6a83f 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -5617,6 +5617,25 @@ _cairo_pdf_surface_fill (void			*abstract_surface,
     if (unlikely (status))
 	return status;
 
+    if (source->type == CAIRO_PATTERN_TYPE_SURFACE &&
+	  source->extend == CAIRO_EXTEND_NONE) {
+
+	_cairo_output_stream_printf (surface->output, "q\n");
+	status =  _cairo_pdf_operators_clip (&surface->pdf_operators,
+					     path,
+					     fill_rule);
+	if (unlikely (status))
+	    return status;
+
+	status = _cairo_pdf_surface_paint_surface_pattern (surface,
+							   (cairo_surface_pattern_t *) source);
+	if (unlikely (status))
+	    return status;
+
+	_cairo_output_stream_printf (surface->output, "Q\n");
+	return _cairo_output_stream_get_status (surface->output);
+    }
+
     pattern_res.id = 0;
     gstate_res.id = 0;
     status = _cairo_pdf_surface_add_pdf_pattern (surface, source, clip,
commit 6512faeb9487dcc2d577b5fb3628cf7f13a25c0a
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Aug 30 23:38:17 2009 +0930

    PDF: Avoid using patterns when painting surfaces with EXTEND_NONE
    
    This is an optimization the PS surface has been using to improve
    printing speed and prevent printers from choking on large
    images. Applying this optimzation to PDF prevents the same problem
    occuring when the PDF is converted to PS.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index f7a6738..0ada8c0 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -3265,6 +3265,51 @@ _cairo_pdf_surface_emit_pattern (cairo_pdf_surface_t *surface, cairo_pdf_pattern
 }
 
 static cairo_status_t
+_cairo_pdf_surface_paint_surface_pattern (cairo_pdf_surface_t     *surface,
+					  cairo_surface_pattern_t *source)
+{
+    cairo_pdf_resource_t surface_res;
+    int width, height;
+    cairo_matrix_t cairo_p2d, pdf_p2d;
+    cairo_status_t status;
+
+    status = _cairo_pdf_surface_add_source_surface (surface,
+						    source->surface,
+						    source->base.filter,
+						    &surface_res,
+						    &width,
+						    &height);
+    if (unlikely (status))
+	return status;
+
+    cairo_p2d = source->base.matrix;
+    status = cairo_matrix_invert (&cairo_p2d);
+    /* cairo_pattern_set_matrix ensures the matrix is invertible */
+    assert (status == CAIRO_STATUS_SUCCESS);
+
+    pdf_p2d = surface->cairo_to_pdf;
+    cairo_matrix_multiply (&pdf_p2d, &cairo_p2d, &pdf_p2d);
+    cairo_matrix_translate (&pdf_p2d, 0.0, height);
+    cairo_matrix_scale (&pdf_p2d, 1.0, -1.0);
+    if (! _cairo_surface_is_meta (source->surface))
+	cairo_matrix_scale (&pdf_p2d, width, height);
+
+    if (! _cairo_matrix_is_identity (&pdf_p2d)) {
+	_cairo_output_stream_printf (surface->output,
+				     "%f %f %f %f %f %f cm\n",
+				     pdf_p2d.xx, pdf_p2d.yx,
+				     pdf_p2d.xy, pdf_p2d.yy,
+				     pdf_p2d.x0, pdf_p2d.y0);
+    }
+
+    _cairo_output_stream_printf (surface->output,
+				 "/x%d Do\n",
+				 surface_res.id);
+
+    return _cairo_pdf_surface_add_xobject (surface, surface_res);
+}
+
+static cairo_status_t
 _cairo_pdf_surface_select_operator (cairo_pdf_surface_t *surface,
 				    cairo_operator_t     op)
 {
@@ -5274,6 +5319,19 @@ _cairo_pdf_surface_paint (void			*abstract_surface,
     if (unlikely (status))
 	return status;
 
+    if (source->type == CAIRO_PATTERN_TYPE_SURFACE &&
+	  source->extend == CAIRO_EXTEND_NONE) {
+
+	_cairo_output_stream_printf (surface->output, "q\n");
+	status = _cairo_pdf_surface_paint_surface_pattern (surface,
+							   (cairo_surface_pattern_t *) source);
+	if (unlikely (status))
+	    return status;
+
+	_cairo_output_stream_printf (surface->output, "Q\n");
+	return _cairo_output_stream_get_status (surface->output);
+    }
+
     pattern_res.id = 0;
     gstate_res.id = 0;
     status = _cairo_pdf_surface_add_pdf_pattern (surface, source, clip,
commit 26d568a9ada523793b2e5855678922894e438ef4
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Aug 30 23:50:53 2009 +0930

    PDF: Fix bug when when embedding surfaces

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 83e9b6e..f7a6738 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -4886,7 +4886,8 @@ _cairo_pdf_surface_write_patterns_and_smask_groups (cairo_pdf_surface_t *surface
     group_index = 0;
     surface_index = 0;
     while ((pattern_index < _cairo_array_num_elements (&surface->page_patterns)) ||
-	   (group_index < _cairo_array_num_elements (&surface->smask_groups)))
+	   (group_index < _cairo_array_num_elements (&surface->smask_groups)) ||
+	   (surface_index < _cairo_array_num_elements (&surface->page_surfaces)))
     {
 	for (; group_index < _cairo_array_num_elements (&surface->smask_groups); group_index++) {
 	    _cairo_array_copy_element (&surface->smask_groups, group_index, &group);


More information about the cairo-commit mailing list