[cairo-commit] Branch 'ps-surface' - 5 commits - src/cairo-analyze-surface.c src/cairoint.h src/cairo-paginated-surface.c src/cairo-ps-surface.c src/cairo-scaled-font.c

keithp keithp at kemper.freedesktop.org
Tue Feb 28 10:53:38 PST 2006


 src/cairo-analyze-surface.c   |   11 +++
 src/cairo-paginated-surface.c |   11 +++
 src/cairo-ps-surface.c        |  125 ++++++++++++++++++++++++++++++++++--------
 src/cairo-scaled-font.c       |    2 
 src/cairoint.h                |    2 
 5 files changed, 125 insertions(+), 26 deletions(-)

New commits:
diff-tree 2984f60a3a4571a8d4179fdc64a9e67ce9854f21 (from 9ca67992a5816db49e8dca866816481483896814)
Author: Keith Packard <keithp at evo.keithp.com>
Date:   Mon Feb 27 20:09:24 2006 -0800

    Need cairo_analyze_surface_get_extents

diff --git a/src/cairo-analyze-surface.c b/src/cairo-analyze-surface.c
index e2d5e84..a3ea707 100644
--- a/src/cairo-analyze-surface.c
+++ b/src/cairo-analyze-surface.c
@@ -48,6 +48,15 @@ typedef struct {
 } cairo_analyze_surface_t;
 
 static cairo_int_status_t
+_cairo_analyze_surface_get_extents (void	 	*abstract_surface,
+				    cairo_rectangle_t	*rectangle)
+{
+    cairo_analyze_surface_t *surface = abstract_surface;
+
+    return _cairo_surface_get_extents (surface->target, rectangle);
+}
+
+static cairo_int_status_t
 _cairo_analyze_surface_paint (void			*abstract_surface,
 			      cairo_operator_t		op,
 			      cairo_pattern_t		*source)
@@ -181,7 +190,7 @@ static const cairo_surface_backend_t cai
     NULL, /* show_page */
     NULL, /* set_clip_region */
     NULL, /* clip_path */
-    NULL, /* get_extents */
+    _cairo_analyze_surface_get_extents,
     NULL, /* old_show_glyphs */
     NULL, /* get_font_options */
     NULL, /* flush */
diff-tree 9ca67992a5816db49e8dca866816481483896814 (from ad247974ebcfc5ede9fd3856eeaee4860318d118)
Author: Keith Packard <keithp at evo.keithp.com>
Date:   Mon Feb 27 20:05:57 2006 -0800

    Support meta surface patterns

diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c
index a4979c1..17036a4 100644
--- a/src/cairo-paginated-surface.c
+++ b/src/cairo-paginated-surface.c
@@ -155,6 +155,15 @@ _cairo_paginated_surface_get_target (cai
     return paginated_surface->target;
 }
 
+static cairo_surface_t *
+_cairo_paginated_surface_create_similar (void		 *other,
+					 cairo_content_t  content,
+					 int		  width,
+					 int		  height)
+{
+    return _cairo_meta_surface_create (content, width, height);
+}
+
 static cairo_status_t
 _cairo_paginated_surface_finish (void *abstract_surface)
 {
@@ -412,7 +421,7 @@ _cairo_paginated_surface_snapshot (void 
 }
 
 const cairo_surface_backend_t cairo_paginated_surface_backend = {
-    NULL, /* create_similar */
+    _cairo_paginated_surface_create_similar,
     _cairo_paginated_surface_finish,
     _cairo_paginated_surface_acquire_source_image,
     _cairo_paginated_surface_release_source_image,
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index aa5ac89..4245c9b 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -41,6 +41,7 @@
 #include "cairo-ps.h"
 #include "cairo-font-subset-private.h"
 #include "cairo-paginated-surface-private.h"
+#include "cairo-meta-surface-private.h"
 #include "cairo-ft-private.h"
 
 #include <time.h>
@@ -620,9 +621,11 @@ operator_always_translucent (cairo_opera
 static cairo_bool_t
 pattern_surface_supported (const cairo_surface_pattern_t *pattern)
 {
-    if (pattern->surface->backend->acquire_source_image == NULL)
-	return FALSE;
-    return TRUE;
+    if (_cairo_surface_is_meta (pattern->surface))
+	return TRUE;
+    if (pattern->surface->backend->acquire_source_image != NULL)
+	return TRUE;
+    return FALSE;
 }
 
 static cairo_bool_t
@@ -823,20 +826,30 @@ static void
 emit_surface_pattern (cairo_ps_surface_t *surface,
 		      cairo_surface_pattern_t *pattern)
 {
-    cairo_image_surface_t	*image;
-    cairo_status_t		status;
-    void			*image_extra;
     cairo_rectangle_t		extents;
 
-    status = _cairo_surface_acquire_source_image (pattern->surface,
-						  &image,
-						  &image_extra);
-    assert (status == CAIRO_STATUS_SUCCESS);
-    emit_image (surface, image, &pattern->base.matrix, "MyPattern");
-    _cairo_surface_release_source_image (pattern->surface, image, image_extra);
+    if (_cairo_surface_is_meta (pattern->surface)) {
+	_cairo_output_stream_printf (surface->stream, "/MyPattern {\n");
+	_cairo_meta_surface_replay (pattern->surface, &surface->base);
+	extents.width = surface->width;
+	extents.height = surface->height;
+	_cairo_output_stream_printf (surface->stream, "} bind def\n");
+    } else {
+	cairo_image_surface_t	*image;
+	void			*image_extra;
+	cairo_status_t		status;
+
+	status = _cairo_surface_acquire_source_image (pattern->surface,
+						      &image,
+						      &image_extra);
+	_cairo_surface_get_extents (&image->base, &extents);
+	assert (status == CAIRO_STATUS_SUCCESS);
+	emit_image (surface, image, &pattern->base.matrix, "MyPattern");
+	_cairo_surface_release_source_image (pattern->surface, image,
+					     image_extra);
+    }
     _cairo_output_stream_printf (surface->stream,
 				 "<< /PatternType 1 /PaintType 1 /TilingType 1\n");
-    _cairo_surface_get_extents (&image->base, &extents);
     _cairo_output_stream_printf (surface->stream,
 				 "/BBox [0 0 %d %d]\n",
 				 extents.width, extents.height);
diff-tree ad247974ebcfc5ede9fd3856eeaee4860318d118 (from 59e4a32d550d14cfaa0687e716c7df0cadf56adc)
Author: Keith Packard <keithp at evo.keithp.com>
Date:   Mon Feb 27 19:34:32 2006 -0800

    Release pattern source image when done with it

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 119b99e..aa5ac89 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -833,6 +833,7 @@ emit_surface_pattern (cairo_ps_surface_t
 						  &image_extra);
     assert (status == CAIRO_STATUS_SUCCESS);
     emit_image (surface, image, &pattern->base.matrix, "MyPattern");
+    _cairo_surface_release_source_image (pattern->surface, image, image_extra);
     _cairo_output_stream_printf (surface->stream,
 				 "<< /PatternType 1 /PaintType 1 /TilingType 1\n");
     _cairo_surface_get_extents (&image->base, &extents);
diff-tree 59e4a32d550d14cfaa0687e716c7df0cadf56adc (from 06b83b89fc4271060c63b284d7909162b92152f1)
Author: Keith Packard <keithp at evo.keithp.com>
Date:   Mon Feb 27 19:23:47 2006 -0800

    Primitive ps glyph support. Fix ps strokes to not leave path defined

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index c6aeff0..119b99e 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -752,10 +752,18 @@ emit_image (cairo_ps_surface_t    *surfa
     cairo_matrix_init (&d2i, 1, 0, 0, 1, 0, 0);
     cairo_matrix_multiply (&d2i, &d2i, matrix);
 
+#if 1
+    /* Construct a string holding the entire image (!) */
     _cairo_output_stream_printf (surface->stream, "/%sString %d string def\n",
 				 name, (int) rgb_size);
     _cairo_output_stream_printf (surface->stream,
 				 "currentfile %sString readstring\n", name);
+#else
+    /* Construct a reusable stream decoder holding the image */
+    _cairo_output_stream_printf (surface->stream, "/%sString <<\n", name);
+    /* intent = image data */
+    _cairo_output_stream_printf (surface->stream, "\t/Intent 0\n");
+#endif    
     /* Compressed image data */
     _cairo_output_stream_write (surface->stream, rgb, rgb_size);
 
@@ -781,7 +789,7 @@ emit_image (cairo_ps_surface_t    *surfa
 				 d2i.xx, d2i.yx,
 				 d2i.xy, d2i.yy,
 				 d2i.x0, d2i.y0);
-    _cairo_output_stream_printf (surface->stream, "} def\n");
+    _cairo_output_stream_printf (surface->stream, "} bind def\n");
 
     status = CAIRO_STATUS_SUCCESS;
 
@@ -1200,6 +1208,8 @@ _cairo_ps_surface_stroke (void			*abstra
     info.output_stream = stream;
     info.has_current_point = FALSE;
 
+    _cairo_output_stream_printf (stream,
+				 "gsave\n");
     status = _cairo_path_fixed_interpret (path,
 					  CAIRO_DIRECTION_FORWARD,
 					  _cairo_ps_surface_path_move_to,
@@ -1212,8 +1222,6 @@ _cairo_ps_surface_stroke (void			*abstra
      * Switch to user space to set line parameters
      */
     _cairo_output_stream_printf (stream,
-				 "gsave\n");
-    _cairo_output_stream_printf (stream,
 				 "[%f %f %f %f 0 0] concat\n",
 				 ctm->xx, ctm->yx, ctm->xy, ctm->yy);
     /* line width */
@@ -1301,6 +1309,41 @@ _cairo_ps_surface_fill (void		*abstract_
     return status;
 }
 
+static cairo_int_status_t
+_cairo_ps_surface_show_glyphs (void		     *abstract_surface,
+			       cairo_operator_t	      op,
+			       cairo_pattern_t	     *source,
+			       const cairo_glyph_t   *glyphs,
+			       int		      num_glyphs,
+			       cairo_scaled_font_t   *scaled_font)
+{
+    cairo_ps_surface_t *surface = abstract_surface;
+    cairo_output_stream_t *stream = surface->stream;
+    cairo_int_status_t status;
+    cairo_path_fixed_t *path;
+
+    if (surface->mode == CAIRO_PAGINATED_MODE_ANALYZE) {
+	if (!pattern_operation_supported (op, source))
+	    return CAIRO_INT_STATUS_UNSUPPORTED;
+	return CAIRO_STATUS_SUCCESS;
+    }
+
+    if (surface->need_start_page)
+	_cairo_ps_surface_start_page (surface);
+
+    _cairo_output_stream_printf (stream,
+				 "%% _cairo_ps_surface_show_glyphs\n");
+
+    path = _cairo_path_fixed_create ();
+    _cairo_scaled_font_glyph_path (scaled_font, glyphs, num_glyphs, path);
+    status = _cairo_ps_surface_fill (abstract_surface, op, source,
+				     path, CAIRO_FILL_RULE_WINDING,
+				     0.1, scaled_font->options.antialias);
+    _cairo_path_fixed_destroy (path);
+
+    return CAIRO_STATUS_SUCCESS;
+}
+
 static const cairo_surface_backend_t cairo_ps_surface_backend = {
     NULL, /* create_similar */
     _cairo_ps_surface_finish,
@@ -1334,7 +1377,8 @@ static const cairo_surface_backend_t cai
     NULL, /* mask */
     _cairo_ps_surface_stroke,
     _cairo_ps_surface_fill,
-    NULL /* show_glyphs */
+    _cairo_ps_surface_show_glyphs,
+    NULL, /* snapshot */
 };
 
 static void
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 8ebbf45..22d22be 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -1008,7 +1008,7 @@ _scaled_glyph_path_close_path (void *abs
 
 cairo_status_t
 _cairo_scaled_font_glyph_path (cairo_scaled_font_t *scaled_font,
-			       cairo_glyph_t	   *glyphs, 
+			       const cairo_glyph_t *glyphs, 
 			       int		    num_glyphs,
 			       cairo_path_fixed_t  *path)
 {
diff --git a/src/cairoint.h b/src/cairoint.h
index 401114c..3d01e40 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1529,7 +1529,7 @@ _cairo_scaled_font_show_glyphs (cairo_sc
 
 cairo_private cairo_status_t
 _cairo_scaled_font_glyph_path (cairo_scaled_font_t *scaled_font,
-			       cairo_glyph_t       *glyphs, 
+			       const cairo_glyph_t *glyphs, 
 			       int                  num_glyphs,
 			       cairo_path_fixed_t  *path);
 
diff-tree 06b83b89fc4271060c63b284d7909162b92152f1 (from f9d4482137e7f13e634cc578c64d84ffdea16bca)
Author: Keith Packard <keithp at evo.keithp.com>
Date:   Mon Feb 27 17:49:53 2006 -0800

    Support image surface patterns

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index f1ae414..c6aeff0 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -672,7 +672,8 @@ compress_dup (const void *data, unsigned
 static cairo_status_t
 emit_image (cairo_ps_surface_t    *surface,
 	    cairo_image_surface_t *image,
-	    cairo_matrix_t	  *matrix)
+	    cairo_matrix_t	  *matrix,
+	    char		  *name)
 {
     cairo_status_t status;
     unsigned char *rgb, *compressed;
@@ -751,6 +752,17 @@ emit_image (cairo_ps_surface_t    *surfa
     cairo_matrix_init (&d2i, 1, 0, 0, 1, 0, 0);
     cairo_matrix_multiply (&d2i, &d2i, matrix);
 
+    _cairo_output_stream_printf (surface->stream, "/%sString %d string def\n",
+				 name, (int) rgb_size);
+    _cairo_output_stream_printf (surface->stream,
+				 "currentfile %sString readstring\n", name);
+    /* Compressed image data */
+    _cairo_output_stream_write (surface->stream, rgb, rgb_size);
+
+    _cairo_output_stream_printf (surface->stream,
+				 "\n");
+
+    _cairo_output_stream_printf (surface->stream, "/%s {\n", name);
     _cairo_output_stream_printf (surface->stream,
 				 "/DeviceRGB setcolorspace\n"
 				 "<<\n"
@@ -759,23 +771,20 @@ emit_image (cairo_ps_surface_t    *surfa
 				 "	/Height %d\n"
 				 "	/BitsPerComponent 8\n"
 				 "	/Decode [ 0 1 0 1 0 1 ]\n"
-				 "	/DataSource currentfile\n"
+				 "	/DataSource %sString\n"
 				 "	/ImageMatrix [ %f %f %f %f %f %f ]\n"
 				 ">>\n"
 				 "image\n",
 				 opaque_image->width,
 				 opaque_image->height,
+				 name,
 				 d2i.xx, d2i.yx,
 				 d2i.xy, d2i.yy,
 				 d2i.x0, d2i.y0);
+    _cairo_output_stream_printf (surface->stream, "} def\n");
 
-    /* Compressed image data */
-    _cairo_output_stream_write (surface->stream, rgb, rgb_size);
     status = CAIRO_STATUS_SUCCESS;
 
-    _cairo_output_stream_printf (surface->stream,
-				 "\n");
-
     free (compressed);
  bail2:
     free (rgb);
@@ -809,12 +818,26 @@ emit_surface_pattern (cairo_ps_surface_t
     cairo_image_surface_t	*image;
     cairo_status_t		status;
     void			*image_extra;
+    cairo_rectangle_t		extents;
 
     status = _cairo_surface_acquire_source_image (pattern->surface,
 						  &image,
 						  &image_extra);
     assert (status == CAIRO_STATUS_SUCCESS);
-    emit_image (surface, image, &pattern->base.matrix);
+    emit_image (surface, image, &pattern->base.matrix, "MyPattern");
+    _cairo_output_stream_printf (surface->stream,
+				 "<< /PatternType 1 /PaintType 1 /TilingType 1\n");
+    _cairo_surface_get_extents (&image->base, &extents);
+    _cairo_output_stream_printf (surface->stream,
+				 "/BBox [0 0 %d %d]\n",
+				 extents.width, extents.height);
+    _cairo_output_stream_printf (surface->stream,
+				 "/XStep %d /YStep %d\n",
+				 extents.width, extents.height);
+    _cairo_output_stream_printf (surface->stream,
+				 "/PaintProc { begin MyPattern\n");
+    _cairo_output_stream_printf (surface->stream,
+				 " end } bind >> matrix makepattern setpattern\n");
 }
 
 static void


More information about the cairo-commit mailing list