[cairo-commit] src/cairo-paginated-surface.c src/cairo-paginated-surface-private.h src/cairo-pdf-surface.c src/cairo-ps-surface.c src/test-paginated-surface.c

Carl Worth cworth at kemper.freedesktop.org
Fri Apr 14 11:39:16 PDT 2006


 src/cairo-paginated-surface-private.h |   17 ++++++++++-------
 src/cairo-paginated-surface.c         |   29 +++++++++++++++--------------
 src/cairo-pdf-surface.c               |   17 +++++++++--------
 src/cairo-ps-surface.c                |   27 ++++++++++++++-------------
 src/test-paginated-surface.c          |   25 +++++++++++++++----------
 5 files changed, 63 insertions(+), 52 deletions(-)

New commits:
diff-tree 8f3c60096d88b3c0368970273828e7a011c5e9dd (from 5461f25df9888aa5fd79e1e371cd1af2cf8964ab)
Author: Carl Worth <cworth at cworth.org>
Date:   Fri Apr 14 11:33:48 2006 -0700

    Add a new cairo_paginated_surface_backend_t rather than just a single function pointer.

diff --git a/src/cairo-paginated-surface-private.h b/src/cairo-paginated-surface-private.h
index cb32596..42cb9ef 100644
--- a/src/cairo-paginated-surface-private.h
+++ b/src/cairo-paginated-surface-private.h
@@ -43,15 +43,18 @@ typedef enum {
     CAIRO_PAGINATED_MODE_RENDER		/* render page contents */
 } cairo_paginated_mode_t;
 
-typedef void (*cairo_set_paginated_mode_func_t) (cairo_surface_t	*target,
-						 cairo_paginated_mode_t	 mode);
+typedef struct _cairo_paginated_surface_backend {
+    void
+    (*set_paginated_mode)	 (void				*surface,
+				  cairo_paginated_mode_t	 mode);
+} cairo_paginated_surface_backend_t;
 
 cairo_private cairo_surface_t *
-_cairo_paginated_surface_create (cairo_surface_t	*target,
-				 cairo_content_t	 content,
-				 int			 width,
-				 int			 height,
-				 cairo_set_paginated_mode_func_t set_paginated_mode);
+_cairo_paginated_surface_create (cairo_surface_t				*target,
+				 cairo_content_t				 content,
+				 int						 width,
+				 int						 height,
+				 const cairo_paginated_surface_backend_t	*backend);
 
 cairo_private cairo_surface_t *
 _cairo_paginated_surface_get_target (cairo_surface_t *surface);
diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c
index 001edf3..26be219 100644
--- a/src/cairo-paginated-surface.c
+++ b/src/cairo-paginated-surface.c
@@ -74,6 +74,9 @@
 typedef struct _cairo_paginated_surface {
     cairo_surface_t base;
 
+    /* The target surface to hold the final result. */
+    cairo_surface_t *target;
+
     cairo_content_t content;
 
     /* XXX: These shouldn't actually exist. We inherit this ugliness
@@ -84,11 +87,8 @@ typedef struct _cairo_paginated_surface 
     int width;
     int height;
 
-    /* The target surface to hold the final result. */
-    cairo_surface_t *target;
-
-    /* Paginated-surface specific function for the target */
-    cairo_set_paginated_mode_func_t set_paginated_mode;
+    /* Paginated-surface specific functions for the target */
+    const cairo_paginated_surface_backend_t *backend;
 
     /* A cairo_meta_surface to record all operations. To be replayed
      * against target, and also against image surface as necessary for
@@ -121,11 +121,11 @@ _cairo_paginated_surface_create_similar 
 #endif
 
 cairo_surface_t *
-_cairo_paginated_surface_create (cairo_surface_t	*target,
-				 cairo_content_t	 content,
-				 int			 width,
-				 int			 height,
-				 cairo_set_paginated_mode_func_t set_paginated_mode)
+_cairo_paginated_surface_create (cairo_surface_t				*target,
+				 cairo_content_t				 content,
+				 int						 width,
+				 int						 height,
+				 const cairo_paginated_surface_backend_t	*backend)
 {
     cairo_paginated_surface_t *surface;
 
@@ -139,12 +139,13 @@ _cairo_paginated_surface_create (cairo_s
      * evidence of the paginated wrapper out to the user. */
     surface->base.type = cairo_surface_get_type (target);
 
+    surface->target = target;
+
     surface->content = content;
     surface->width = width;
     surface->height = height;
 
-    surface->target = target;
-    surface->set_paginated_mode = set_paginated_mode;
+    surface->backend = backend;
 
     surface->meta = _cairo_meta_surface_create (content, width, height);
     if (cairo_surface_status (surface->meta))
@@ -231,9 +232,9 @@ _paint_page (cairo_paginated_surface_t *
     analysis = _cairo_analysis_surface_create (surface->target,
 					       surface->width, surface->height);
 
-    surface->set_paginated_mode (surface->target, CAIRO_PAGINATED_MODE_ANALYZE);
+    surface->backend->set_paginated_mode (surface->target, CAIRO_PAGINATED_MODE_ANALYZE);
     _cairo_meta_surface_replay (surface->meta, analysis);
-    surface->set_paginated_mode (surface->target, CAIRO_PAGINATED_MODE_RENDER);
+    surface->backend->set_paginated_mode (surface->target, CAIRO_PAGINATED_MODE_RENDER);
 
     if (analysis->status) {
 	status = analysis->status;
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 7ab8856..adf29d0 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -187,11 +187,8 @@ _cairo_pdf_surface_add_stream (cairo_pdf
 static void
 _cairo_pdf_surface_ensure_stream (cairo_pdf_surface_t	*surface);
 
-static void
-_cairo_pdf_set_paginated_mode (cairo_surface_t *target,
-			       cairo_paginated_mode_t mode);
-
 static const cairo_surface_backend_t cairo_pdf_surface_backend;
+static const cairo_paginated_surface_backend_t cairo_pdf_surface_paginated_backend;
 
 static unsigned int
 _cairo_pdf_document_new_object (cairo_pdf_document_t *document)
@@ -313,7 +310,7 @@ _cairo_pdf_surface_create_for_stream_int
     return _cairo_paginated_surface_create (target,
 					    CAIRO_CONTENT_COLOR_ALPHA,
 					    width, height,
-					    _cairo_pdf_set_paginated_mode);
+					    &cairo_pdf_surface_paginated_backend);
 }
 
 /**
@@ -2095,10 +2092,10 @@ _cairo_pdf_document_add_page (cairo_pdf_
 }
 
 static void
-_cairo_pdf_set_paginated_mode (cairo_surface_t *target,
-			       cairo_paginated_mode_t paginated_mode)
+_cairo_pdf_surface_set_paginated_mode (void			*abstract_surface,
+				       cairo_paginated_mode_t	 paginated_mode)
 {
-    cairo_pdf_surface_t *surface = (cairo_pdf_surface_t *) target;
+    cairo_pdf_surface_t *surface = abstract_surface;
 
     surface->paginated_mode = paginated_mode;
 }
@@ -2135,3 +2132,7 @@ static const cairo_surface_backend_t cai
     _cairo_pdf_surface_fill,
     NULL  /* show_glyphs */
 };
+
+static const cairo_paginated_surface_backend_t cairo_pdf_surface_paginated_backend = {
+    _cairo_pdf_surface_set_paginated_mode
+};
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index b5062d4..f398176 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -55,10 +55,7 @@
  */
 
 static const cairo_surface_backend_t cairo_ps_surface_backend;
-
-static void
-_cairo_ps_set_paginated_mode (cairo_surface_t *target,
-			      cairo_paginated_mode_t mode);
+static const cairo_paginated_surface_backend_t cairo_ps_surface_paginated_backend;
 
 /*
  * Type1 and Type3 PS fonts can hold only 256 glyphs.
@@ -583,7 +580,7 @@ _cairo_ps_surface_create_for_stream_inte
     return _cairo_paginated_surface_create (&surface->base,
 					    CAIRO_CONTENT_COLOR_ALPHA,
 					    width, height,
-					    _cairo_ps_set_paginated_mode);
+					    &cairo_ps_surface_paginated_backend);
 }
 
 /**
@@ -1824,6 +1821,15 @@ fallback:
     return CAIRO_STATUS_SUCCESS;
 }
 
+static void
+_cairo_ps_surface_set_paginated_mode (void			*abstract_surface,
+				      cairo_paginated_mode_t	 paginated_mode)
+{
+    cairo_ps_surface_t *surface = abstract_surface;
+
+    surface->paginated_mode = paginated_mode;
+}
+
 static const cairo_surface_backend_t cairo_ps_surface_backend = {
     CAIRO_SURFACE_TYPE_PS,
     NULL, /* create_similar */
@@ -1858,11 +1864,6 @@ static const cairo_surface_backend_t cai
     NULL, /* snapshot */
 };
 
-static void
-_cairo_ps_set_paginated_mode (cairo_surface_t *target,
-			      cairo_paginated_mode_t paginated_mode)
-{
-    cairo_ps_surface_t *surface = (cairo_ps_surface_t *) target;
-
-    surface->paginated_mode = paginated_mode;
-}
+static const cairo_paginated_surface_backend_t cairo_ps_surface_paginated_backend = {
+    _cairo_ps_surface_set_paginated_mode
+};
diff --git a/src/test-paginated-surface.c b/src/test-paginated-surface.c
index e42f6a7..6190432 100644
--- a/src/test-paginated-surface.c
+++ b/src/test-paginated-surface.c
@@ -58,15 +58,7 @@ typedef struct _test_paginated_surface {
 } test_paginated_surface_t;
 
 static const cairo_surface_backend_t test_paginated_surface_backend;
-
-static void
-_test_paginated_surface_set_paginated_mode (cairo_surface_t *abstract_surface,
-					    cairo_paginated_mode_t mode)
-{
-    test_paginated_surface_t *surface = (test_paginated_surface_t *) abstract_surface;
-
-    surface->paginated_mode = mode;
-}
+static const cairo_paginated_surface_backend_t test_paginated_surface_paginated_backend;
 
 cairo_surface_t *
 _test_paginated_surface_create_for_data (unsigned char		*data,
@@ -99,7 +91,7 @@ _test_paginated_surface_create_for_data 
     surface->target = target;
 
     return _cairo_paginated_surface_create (&surface->base, content, width, height,
-					    _test_paginated_surface_set_paginated_mode);
+					    &test_paginated_surface_paginated_backend);
 }
 
 static cairo_int_status_t
@@ -238,6 +230,15 @@ _test_paginated_surface_show_glyphs (voi
 				       glyphs, num_glyphs, scaled_font);
 }
 
+static void
+_test_paginated_surface_set_paginated_mode (void			*abstract_surface,
+					    cairo_paginated_mode_t	 mode)
+{
+    test_paginated_surface_t *surface = abstract_surface;
+
+    surface->paginated_mode = mode;
+}
+
 static const cairo_surface_backend_t test_paginated_surface_backend = {
     CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED,
 
@@ -276,3 +277,7 @@ static const cairo_surface_backend_t tes
     _test_paginated_surface_show_glyphs,
     NULL /* snapshot */
 };
+
+static const cairo_paginated_surface_backend_t test_paginated_surface_paginated_backend = {
+    _test_paginated_surface_set_paginated_mode
+};


More information about the cairo-commit mailing list