[PATCH] Add cairo_ps_surface_restrict_to_level()

Adrian Johnson ajohnson at redneon.com
Mon Sep 17 05:43:32 PDT 2007


---
 doc/public/cairo-sections.txt  |    4 ++
 src/cairo-ps-surface-private.h |    2 +
 src/cairo-ps-surface.c         |   91 ++++++++++++++++++++++++++++++++++++++++
 src/cairo-ps.h                 |   25 +++++++++++
 4 files changed, 122 insertions(+), 0 deletions(-)

diff --git a/doc/public/cairo-sections.txt b/doc/public/cairo-sections.txt
index 3bf8956..bb5e572 100644
--- a/doc/public/cairo-sections.txt
+++ b/doc/public/cairo-sections.txt
@@ -58,6 +58,10 @@ cairo_surface_write_to_png_stream
 <TITLE>PostScript Surfaces</TITLE>
 cairo_ps_surface_create
 cairo_ps_surface_create_for_stream
+cairo_ps_surface_restrict_to_level
+cairo_ps_level_t
+cairo_ps_get_levels
+cairo_ps_level_to_string
 cairo_ps_surface_set_size
 cairo_ps_surface_dsc_begin_setup
 cairo_ps_surface_dsc_begin_page_setup
diff --git a/src/cairo-ps-surface-private.h b/src/cairo-ps-surface-private.h
index 3a23c21..8960e37 100644
--- a/src/cairo-ps-surface-private.h
+++ b/src/cairo-ps-surface-private.h
@@ -76,6 +76,8 @@ typedef struct cairo_ps_surface {
 
     cairo_array_t *dsc_comment_target;
 
+    cairo_ps_level_t ps_level;
+
     cairo_surface_t *paginated_surface;
 } cairo_ps_surface_t;
 
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 83e5bbb..345e9e7 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -54,6 +54,20 @@
 static const cairo_surface_backend_t cairo_ps_surface_backend;
 static const cairo_paginated_surface_backend_t cairo_ps_surface_paginated_backend;
 
+static const cairo_ps_level_t _cairo_ps_levels[] =
+{
+    CAIRO_PS_LEVEL_2,
+    CAIRO_PS_LEVEL_3
+};
+
+#define CAIRO_PS_LEVEL_LAST ARRAY_LENGTH (_cairo_ps_levels)
+
+static const char * _cairo_ps_level_strings[CAIRO_PS_LEVEL_LAST] =
+{
+    "PS Level 2",
+    "PS Level 3"
+};
+
 /* A word wrap stream can be used as a filter to do word wrapping on
  * top of an existing output stream. The word wrapping is quite
  * simple, using isspace to determine characters that separate
@@ -817,6 +831,8 @@ _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream,
 
     surface->dsc_comment_target = &surface->dsc_header_comments;
 
+    surface->ps_level = CAIRO_PS_LEVEL_2;
+
     surface->paginated_surface = _cairo_paginated_surface_create (&surface->base,
 								   CAIRO_CONTENT_COLOR_ALPHA,
 								   width, height,
@@ -957,6 +973,81 @@ _extract_ps_surface (cairo_surface_t	 *surface,
 }
 
 /**
+ * cairo_ps_surface_restrict_to_level:
+ * @surface: a PostScript #cairo_surface_t
+ * @level: PostScript version
+ *
+ * Restricts the generated PostSript file to @level. See
+ * cairo_ps_get_versions() for a list of available version values that
+ * can be used here.
+ *
+ * This function should only be called before any drawing operations
+ * have been performed on the given surface. The simplest way to do
+ * this is to call this function immediately after creating the
+ * surface.
+ *
+ * Since: 1.6
+ **/
+void
+cairo_ps_surface_restrict_to_level (cairo_surface_t  *surface,
+                                    cairo_ps_level_t  level)
+{
+    cairo_ps_surface_t *ps_surface;
+    cairo_status_t status;
+
+    status = _extract_ps_surface (surface, &ps_surface);
+    if (status) {
+	_cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
+	return;
+    }
+
+    if (level < CAIRO_PS_LEVEL_LAST)
+	ps_surface->ps_level = level;
+}
+
+/**
+ * cairo_ps_get_levels:
+ * @versions: supported level list
+ * @num_versions: list length
+ *
+ * Used to retrieve the list of supported levels. See
+ * cairo_ps_surface_restrict_to_version().
+ *
+ * Since: 1.6
+ **/
+void
+cairo_ps_get_levels (cairo_ps_level_t const	**levels,
+                     int                     	 *num_levels)
+{
+    if (levels != NULL)
+	*levels = _cairo_ps_levels;
+
+    if (num_levels != NULL)
+	*num_levels = CAIRO_PS_LEVEL_LAST;
+}
+
+/**
+ * cairo_ps_level_to_string:
+ * @version: a level id
+ *
+ * Get the string representation of the given @level id. This function
+ * will return NULL if @level id isn't valid. See cairo_ps_get_versions()
+ * for a way to get the list of valid level ids.
+ *
+ * Return value: the string associated to given version.
+ *
+ * Since: 1.6
+ **/
+const char *
+cairo_ps_level_to_string (cairo_ps_level_t level)
+{
+    if (level >= CAIRO_PS_LEVEL_LAST)
+	return NULL;
+
+    return _cairo_ps_level_strings[level];
+}
+
+/**
  * cairo_ps_surface_set_size:
  * @surface: a PostScript cairo_surface_t
  * @width_in_points: new surface width, in points (1 point == 1/72.0 inch)
diff --git a/src/cairo-ps.h b/src/cairo-ps.h
index a61d12d..1a1b6ae 100644
--- a/src/cairo-ps.h
+++ b/src/cairo-ps.h
@@ -47,6 +47,20 @@ CAIRO_BEGIN_DECLS
 
 /* PS-surface functions */
 
+/**
+ * cairo_ps_level_t
+ * @CAIRO_PS_LEVEL_2: The language level 2 of the PostScript specification.
+ * @CAIRO_PS_LEVEL_3: The language level 3 of the PostScript specification.
+ *
+ * #cairo_ps_level_t is used to describe the language level of the
+ * PostScript Language Reference that a generated PostScript file will
+ * conform to.
+ */
+typedef enum _cairo_ps_level {
+    CAIRO_PS_LEVEL_2,
+    CAIRO_PS_LEVEL_3
+} cairo_ps_level_t;
+
 cairo_public cairo_surface_t *
 cairo_ps_surface_create (const char		*filename,
 			 double			 width_in_points,
@@ -59,6 +73,17 @@ cairo_ps_surface_create_for_stream (cairo_write_func_t	write_func,
 				    double		height_in_points);
 
 cairo_public void
+cairo_ps_surface_restrict_to_level (cairo_surface_t    *surface,
+                                    cairo_ps_level_t    level);
+
+cairo_public void
+cairo_ps_get_levels (cairo_ps_level_t const  **levels,
+                     int                      *num_levels);
+
+cairo_public const char *
+cairo_ps_level_to_string (cairo_ps_level_t level);
+
+cairo_public void
 cairo_ps_surface_set_size (cairo_surface_t	*surface,
 			   double		 width_in_points,
 			   double		 height_in_points);
-- 
1.5.2.4


--------------090802090204060507030906--


More information about the cairo mailing list