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

Carl Worth cworth at kemper.freedesktop.org
Tue Apr 18 23:35:05 PDT 2006


 src/cairo-pdf-surface.c |   81 +++++++++++++++++++++++++++++++++++-------------
 src/cairo-ps-surface.c  |    2 -
 2 files changed, 61 insertions(+), 22 deletions(-)

New commits:
diff-tree ab2546009ff246bd0e7bbc07437330cf307e00f7 (from 241c6480cd9a5f63ea67f8cb1407f22503697ca3)
Author: Carl Worth <cworth at cworth.org>
Date:   Tue Apr 18 23:31:16 2006 -0700

    Use fallbacks in PDF backend for CAIRO_ANTIALIAS_NONE.
    
    Perhaps there's a way to preserve that hint in PDF output, but until
    we have code that actually does that, the correct thing to do is to
    call it unsupported and let the fallbacks do their thing.
    
    With this commit, the two regressions that were recently introduced
    now pass again. Specifically:
    
    	rectangle-rounding-error
    	unantialiased-shapes

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 027e2cb..64b5641 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -2232,8 +2232,14 @@ _cairo_pdf_surface_stroke (void			*abstr
     cairo_pdf_document_t *document = surface->document;
     cairo_status_t status;
 
-    if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE)
+    if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) {
+	/* XXX: Does PDF provide a way we can preserve this hint? For now,
+	 * this will trigger a fallback. */
+	if (antialias == CAIRO_ANTIALIAS_NONE)
+	    return CAIRO_INT_STATUS_UNSUPPORTED;
+
 	return _analyze_operation (surface, op, source);
+    }
 
     assert (_operation_supported (surface, op, source));
 
@@ -2280,8 +2286,14 @@ _cairo_pdf_surface_fill (void			*abstrac
     const char *pdf_operator;
     cairo_status_t status;
 
-    if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE)
+    if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) {
+	/* XXX: Does PDF provide a way we can preserve this hint? For now,
+	 * this will trigger a fallback. */
+	if (antialias == CAIRO_ANTIALIAS_NONE)
+	    return CAIRO_INT_STATUS_UNSUPPORTED;
+
 	return _analyze_operation (surface, op, source);
+    }
 
     assert (_operation_supported (surface, op, source));
 
diff-tree 241c6480cd9a5f63ea67f8cb1407f22503697ca3 (from 8be1697f2bd8026b28f2f24c2fab967ee01b6d8c)
Author: Carl Worth <cworth at cworth.org>
Date:   Tue Apr 18 23:24:14 2006 -0700

    Add implementation of _cairo_pdf_surface_paint (and fix emit_surface_pattern).
    
    Fix general broken-ness in emit_surface_pattern, enough so that a new
    implementation of _cairo_pdf_surface_paint does something useful. With
    this commit, the following tests switch from all-fallback to
    all-native and still pass the test suite with flying colors:
    
    	caps-joins
    	caps-sub-paths
    	clip-fill-rule
    	clip-fill-rule-pixel-aligned
    	clip-nesting
    	clip-twice
    	dash-caps-joins
    	dash-offset-negative
    	leaky-polygon
    	line-width
    	paint
    	path-data
    	transforms
    
    Meanwhile, the following two tests also switch from fallback to
    native, but cause the test suite to complain about failures. These
    both look like a mostly harmless failure to respect the ANTIALIAS_NONE
    hint in the PDF output:
    
    	rectangle-rounding-error-pdf-argb32-out.pdf
    	unantialiased-shapes-pdf-argb32-out.pdf

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index ef08ffc..027e2cb 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -175,7 +175,7 @@ _cairo_pdf_surface_clear (cairo_pdf_surf
 static cairo_pdf_stream_t *
 _cairo_pdf_document_open_stream (cairo_pdf_document_t	*document,
 				 const char		*fmt,
-				 ...);
+				 ...) CAIRO_PRINTF_FORMAT(2, 3);
 static void
 _cairo_pdf_document_close_stream (cairo_pdf_document_t	*document);
 
@@ -930,7 +930,7 @@ emit_surface_pattern (cairo_pdf_surface_
     void *image_extra;
     cairo_status_t status;
     unsigned int id, alpha;
-    cairo_matrix_t pm;
+    cairo_matrix_t i2u;
 
     /* XXX: This is broken. We need new code here to actually emit the
      * PDF surface. */
@@ -947,25 +947,27 @@ emit_surface_pattern (cairo_pdf_surface_
 
     /* BBox must be smaller than XStep by YStep or acroread wont
      * display the pattern. */
-
-    cairo_matrix_init_identity (&pm);
-    cairo_matrix_scale (&pm, image->width, image->height);
-    pm = pattern->base.matrix;
-    cairo_matrix_invert (&pm);
-
     stream = _cairo_pdf_document_open_stream (document,
-					      "   /BBox [ 0 0 256 256 ]\r\n"
-					      "   /XStep 256\r\n"
-					      "   /YStep 256\r\n"
+					      "   /BBox [ 0 0 %d %d ]\r\n"
+					      "   /XStep %d\r\n"
+					      "   /YStep %d\r\n"
 					      "   /PatternType 1\r\n"
 					      "   /TilingType 1\r\n"
 					      "   /PaintType 1\r\n"
 					      "   /Resources << /XObject << /res%d %d 0 R >> >>\r\n",
+					      image->width, image->height,
+					      image->width, image->height,
 					      id, id);
 
+    i2u = pattern->base.matrix;
+    cairo_matrix_invert (&i2u);
+    cairo_matrix_scale (&i2u, image->width, image->height);
 
     _cairo_output_stream_printf (output,
-				 " /res%d Do\r\n",
+				 "q %f %f %f %f %f %f cm /res%d Do Q\r\n",
+				 i2u.xx, i2u.yx,
+				 i2u.xy, i2u.yy,
+				 i2u.x0, i2u.y0,
 				 id);
 
     _cairo_pdf_surface_add_pattern (dst, stream->id);
@@ -2096,17 +2098,42 @@ _cairo_pdf_surface_paint (void			*abstra
 			  cairo_pattern_t	*source)
 {
     cairo_pdf_surface_t *surface = abstract_surface;
+    cairo_pdf_document_t *document = surface->document;
+    cairo_status_t status;
 
     if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE)
-	return CAIRO_INT_STATUS_UNSUPPORTED;
+	return _analyze_operation (surface, op, source);
 
-    /* One would think that since we analyzed this away as unsupported
-     * that it would never be called after analyzing. But in fact,
-     * paint is called to paint the actual fallback surface. So we
-     * must not ASSERT_NOT_REACHED as we do for the other drawing
-     * operations. */
+    /* XXX: It would be nice to be able to assert this condition
+     * here. But, we actually allow one 'cheat' that is used when
+     * painting the final image-based fallbacks. The final fallbacks
+     * do have alpha which we support by blending with white. This is
+     * possible only because there is nothing between the fallback
+     * images and the paper, nor is anything painted above. */
+    /*
+    assert (_operation_supported (op, source));
+    */
+
+#if 0
+    if (source->type == CAIRO_PATTERN_TYPE_SURFACE)
+	return _cairo_pdf_surface_composite_image (surface, (cairo_surface_pattern_t *) source);
+#endif
 
-    return CAIRO_INT_STATUS_UNSUPPORTED;
+    status = emit_pattern (surface, source);
+    if (status)
+	return status;
+
+    /* After emitting the pattern the current stream should belong to
+     * this surface, so no need to _cairo_pdf_surface_ensure_stream()
+     */
+    assert (document->current_stream != NULL &&
+	    document->current_stream == surface->current_stream);
+
+    _cairo_output_stream_printf (document->output_stream,
+				 "0 0 %f %f re f\r\n",
+				 surface->width, surface->height);
+
+    return _cairo_output_stream_get_status (document->output_stream);
 }
 
 static cairo_int_status_t
diff-tree 8be1697f2bd8026b28f2f24c2fab967ee01b6d8c (from a98b44a1deab5fd15607b50df63189a74a269909)
Author: Carl Worth <cworth at cworth.org>
Date:   Tue Apr 18 23:18:39 2006 -0700

    Fix stale code in comment.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 29b6882..1d73495 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -1370,7 +1370,7 @@ _cairo_ps_surface_paint (void			*abstrac
      * possible only because there is nothing between the fallback
      * images and the paper, nor is anything painted above. */
     /*
-    assert (pattern_operation_supported (op, source));
+    assert (_operation_supported (op, source));
     */
     
     _cairo_output_stream_printf (stream,


More information about the cairo-commit mailing list