[cairo-commit] doc/public src/cairo-svg.h src/cairo-svg-surface.c

Emmanuel Pacaud emmanuel at kemper.freedesktop.org
Tue May 2 06:00:18 PDT 2006


 doc/public/cairo-sections.txt  |    7 -
 doc/public/tmpl/cairo-svg.sgml |   79 ---------------
 src/cairo-svg-surface.c        |  209 ++++++++++++++++-------------------------
 src/cairo-svg.h                |   41 +++-----
 4 files changed, 109 insertions(+), 227 deletions(-)

New commits:
diff-tree 0e4527c67e623801544be05de32f21a0c10e5b5d (from 32f120e4888fd9344f699fd47c1aea6a5ec3df8e)
Author: Emmanuel Pacaud <emmanuel.pacaud at free.fr>
Date:   Tue May 2 14:50:40 2006 +0200

    SVG: Rework of API for SVG selection.
    
    I've removed cairo_svg_surface_create_xxx functions, and instead implemented
    the following ones:
    
    cairo_svg_surface_restrict_to_version
    cairo_svg_get_versions
    cairo_svg_version_to_string

diff --git a/doc/public/cairo-sections.txt b/doc/public/cairo-sections.txt
index de1feb3..575aa67 100644
--- a/doc/public/cairo-sections.txt
+++ b/doc/public/cairo-sections.txt
@@ -112,12 +112,11 @@ cairo_xlib_surface_create_with_xrender_f
 <FILE>cairo-svg</FILE>
 <TITLE>SVG Surfaces</TITLE>
 cairo_svg_surface_create
-cairo_svg_surface_create_1_1
-cairo_svg_surface_create_1_2
 cairo_svg_surface_create_for_stream
-cairo_svg_surface_create_for_stream_1_1
-cairo_svg_surface_create_for_stream_1_2
 cairo_svg_surface_set_dpi
+cairo_svg_surface_restrict_to_version
+cairo_svg_get_versions
+cairo_svg_version_to_string 
 </SECTION>
 
 <SECTION>
diff --git a/doc/public/tmpl/cairo-svg.sgml b/doc/public/tmpl/cairo-svg.sgml
index fdf167a..1099d61 100644
--- a/doc/public/tmpl/cairo-svg.sgml
+++ b/doc/public/tmpl/cairo-svg.sgml
@@ -17,82 +17,3 @@ Rendering SVG documents
 <!-- ##### SECTION Stability_Level ##### -->
 
 
-<!-- ##### FUNCTION cairo_svg_surface_create ##### -->
-<para>
-
-</para>
-
- at filename: 
- at width_in_points: 
- at height_in_points: 
- at Returns: 
-
-
-<!-- ##### FUNCTION cairo_svg_surface_create_1_1 ##### -->
-<para>
-
-</para>
-
- at filename: 
- at width_in_points: 
- at height_in_points: 
- at Returns: 
-
-
-<!-- ##### FUNCTION cairo_svg_surface_create_1_2 ##### -->
-<para>
-
-</para>
-
- at filename: 
- at width_in_points: 
- at height_in_points: 
- at Returns: 
-
-
-<!-- ##### FUNCTION cairo_svg_surface_create_for_stream ##### -->
-<para>
-
-</para>
-
- at write_func: 
- at closure: 
- at width_in_points: 
- at height_in_points: 
- at Returns: 
-
-
-<!-- ##### FUNCTION cairo_svg_surface_create_for_stream_1_1 ##### -->
-<para>
-
-</para>
-
- at write_func: 
- at closure: 
- at width_in_points: 
- at height_in_points: 
- at Returns: 
-
-
-<!-- ##### FUNCTION cairo_svg_surface_create_for_stream_1_2 ##### -->
-<para>
-
-</para>
-
- at write_func: 
- at closure: 
- at width_in_points: 
- at height_in_points: 
- at Returns: 
-
-
-<!-- ##### FUNCTION cairo_svg_surface_set_dpi ##### -->
-<para>
-
-</para>
-
- at surface: 
- at x_dpi: 
- at y_dpi: 
-
-
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 27ade28..485fc70 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -52,13 +52,20 @@
 
 #define CAIRO_SVG_DEFAULT_DPI 300
 
-typedef enum {
+typedef struct cairo_svg_document cairo_svg_document_t;
+typedef struct cairo_svg_surface cairo_svg_surface_t;
+
+static const cairo_svg_version_t _cairo_svg_versions[CAIRO_SVG_VERSION_LAST] = 
+{
     CAIRO_SVG_VERSION_1_1,
     CAIRO_SVG_VERSION_1_2
-} cairo_svg_version_t;
+};
 
-typedef struct cairo_svg_document cairo_svg_document_t;
-typedef struct cairo_svg_surface cairo_svg_surface_t;
+static const char * _cairo_svg_version_strings[CAIRO_SVG_VERSION_LAST] = 
+{
+    "SVG 1.1",
+    "SVG 1.2"
+};
 
 struct cairo_svg_document {
     cairo_output_stream_t *output_stream;
@@ -166,26 +173,6 @@ _cairo_svg_surface_create_for_stream_int
 					    &cairo_svg_surface_paginated_backend);
 }
 
-static cairo_surface_t *
-_cairo_svg_surface_create_for_stream (cairo_write_func_t     write,
-				      void		    *closure,
-				      double		     width,
-				      double		     height, 
-				      cairo_svg_version_t    version)
-{
-    cairo_status_t status;
-    cairo_output_stream_t *stream;
-
-    stream = _cairo_output_stream_create (write, NULL, closure);
-    status = _cairo_output_stream_get_status (stream);
-    if (status) {
-	_cairo_error (status);
-	return (cairo_surface_t *) &_cairo_surface_nil;
-    }
-
-    return _cairo_svg_surface_create_for_stream_internal (stream, width, height, version);
-}
-
 /**
  * cairo_svg_surface_create_for_stream:
  * @write: a #cairo_write_func_t to accept the output data
@@ -210,75 +197,17 @@ cairo_svg_surface_create_for_stream (cai
 				     double			 width,
 				     double			 height)
 {
-    return _cairo_svg_surface_create_for_stream (write, closure, width, height, 
-						 CAIRO_SVG_VERSION_1_1);
-}
-
-/**
- * cairo_svg_surface_create_for_stream_1_1:
- * @write: a #cairo_write_func_t to accept the output data
- * @closure: the closure argument for @write
- * @width_in_points: width of the surface
- * @height_in_points: height of the surface
- * 
- * Creates a SVG 1.1 surface of the specified size in points to be written
- * incrementally to the stream represented by @write and @closure
- * (see @cairo_svg_surface_create_for_stream and @cairo_svg_surface_create_1_1).
- *
- * Return value: a pointer to the newly created surface. 
- */
-
-cairo_surface_t *
-cairo_svg_surface_create_for_stream_1_1 (cairo_write_func_t  write,
-					 void		    *closure,
-					 double		     width,
-					 double		     height)
-{
-    return _cairo_svg_surface_create_for_stream (write, closure, width, height, 
-						 CAIRO_SVG_VERSION_1_1);
-}
-
-/**
- * cairo_svg_surface_create_for_stream_1_2:
- * @write: a #cairo_write_func_t to accept the output data
- * @closure: the closure argument for @write
- * @width_in_points: width of the surface
- * @height_in_points: height of the surface
- * 
- * Creates a SVG 1.2 surface of the specified size in points to be written
- * incrementally to the stream represented by @write and @closure
- * (see @cairo_svg_surface_create_for_stream and @cairo_svg_surface_create_1_2).
- *
- * Return value: a pointer to the newly created surface. 
- */
-
-cairo_surface_t *
-cairo_svg_surface_create_for_stream_1_2 (cairo_write_func_t  write,
-					 void		    *closure,
-					 double		     width,
-					 double		     height)
-{
-    return _cairo_svg_surface_create_for_stream (write, closure, width, height, 
-						 CAIRO_SVG_VERSION_1_2);
-}
-
-static cairo_surface_t *
-_cairo_svg_surface_create (const char		*filename,
-			   double		 width,
-			   double		 height,
-			   cairo_svg_version_t   version)
-{
     cairo_status_t status;
     cairo_output_stream_t *stream;
 
-    stream = _cairo_output_stream_create_for_filename (filename);
+    stream = _cairo_output_stream_create (write, NULL, closure);
     status = _cairo_output_stream_get_status (stream);
     if (status) {
 	_cairo_error (status);
 	return (cairo_surface_t *) &_cairo_surface_nil;
     }
 
-    return _cairo_svg_surface_create_for_stream_internal (stream, width, height, version);
+    return _cairo_svg_surface_create_for_stream_internal (stream, width, height, CAIRO_SVG_VERSION_1_1);
 }
 
 /**
@@ -304,47 +233,17 @@ cairo_svg_surface_create (const char	*fi
 			  double	 width,
 			  double	 height)
 {
-    return _cairo_svg_surface_create (filename, width, height, CAIRO_SVG_VERSION_1_1);
-}
-
-/**
- * cairo_svg_surface_create_1_1:
- * @filename: a filename for the SVG output.
- * @width_in_points: width of the surface, in points. 
- * @height_in_points: height of the surface, in points.
- * 
- * Creates a SVG 1.1 surface (see @cairo_svg_surface_create). 
- * Compositing operations not supported by SVG 1.1 are emulated via
- * image fallbacks, except for unclipped CLEAR and SOURCE operators.
- * 
- * Return value: a pointer to the newly created surface.
- **/
-
-cairo_surface_t *
-cairo_svg_surface_create_1_1 (const char    *filename,
-			      double	     width,
-			      double	     height)
-{
-    return _cairo_svg_surface_create (filename, width, height, CAIRO_SVG_VERSION_1_1);
-}
+    cairo_status_t status;
+    cairo_output_stream_t *stream;
 
-/**
- * cairo_svg_surface_create_1_2:
- * @filename: a filename for the SVG output.
- * @width_in_points: width of the surface, in points. 
- * @height_in_points: height of the surface, in points.
- * 
- * Creates a SVG 1.2 surface (see @cairo_svg_surface_create). 
- * 
- * Return value: a pointer to the newly created surface.
- **/
+    stream = _cairo_output_stream_create_for_filename (filename);
+    status = _cairo_output_stream_get_status (stream);
+    if (status) {
+	_cairo_error (status);
+	return (cairo_surface_t *) &_cairo_surface_nil;
+    }
 
-cairo_surface_t *
-cairo_svg_surface_create_1_2 (const char    *filename,
-			      double	     width,
-			      double	     height)
-{
-    return _cairo_svg_surface_create (filename, width, height, CAIRO_SVG_VERSION_1_2);
+    return _cairo_svg_surface_create_for_stream_internal (stream, width, height, CAIRO_SVG_VERSION_1_1);
 }
 
 static cairo_bool_t
@@ -392,6 +291,70 @@ cairo_svg_surface_set_dpi (cairo_surface
     svg_surface->document->y_dpi = y_dpi;    
 }
 
+/**
+ * cairo_svg_surface_restrict_to_version:
+ * @surface: a SVG #cairo_surface_t
+ * @version: SVG version
+ *
+ * Restricts the generated SVG file to @version.
+ *
+ * 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.
+ **/
+
+cairo_public void
+cairo_svg_surface_restrict_to_version (cairo_surface_t 		*abstract_surface,
+				       cairo_svg_version_t  	 version)
+{
+    cairo_svg_surface_t *surface;
+    
+    if (!_cairo_surface_is_svg (abstract_surface) || 
+	version < 0 || version >= CAIRO_SVG_VERSION_LAST) 
+	return;
+
+    surface = (cairo_svg_surface_t *) abstract_surface;
+    surface->document->svg_version = version;
+}
+
+/**
+ * cairo_svg_get_versions:
+ * @version: supported version list
+ * @num_versions: list length
+ *
+ * Returns the list of supported versions.
+ **/
+
+cairo_public void
+cairo_svg_get_versions (cairo_svg_version_t const	**versions,
+                        int                     	 *num_versions)
+{
+    if (versions != NULL)
+	*versions = _cairo_svg_versions;
+
+    if (num_versions != NULL)
+	*num_versions = CAIRO_SVG_VERSION_LAST;
+}
+
+/** 
+ * cairo_svg_version_to_string:
+ * @version: a version id
+ *
+ * Returns the string associated to given @version. This function
+ * will return NULL if @version isn't valid. See @cairo_svg_get_versions
+ * for a way to get the list of valid version ids.
+ **/
+
+cairo_public const char *
+cairo_svg_version_to_string (cairo_svg_version_t version)
+{
+    if (version < 0 || version >= CAIRO_SVG_VERSION_LAST)
+	return NULL;
+
+    return _cairo_svg_version_strings[version];
+}
+
 static cairo_surface_t *
 _cairo_svg_surface_create_for_document (cairo_svg_document_t	*document,
 					cairo_content_t		 content,
diff --git a/src/cairo-svg.h b/src/cairo-svg.h
index d428fe3..cac6c0e 100644
--- a/src/cairo-svg.h
+++ b/src/cairo-svg.h
@@ -38,40 +38,39 @@
 
 CAIRO_BEGIN_DECLS
 
-cairo_surface_t *
+typedef enum {
+    CAIRO_SVG_VERSION_1_1,
+    CAIRO_SVG_VERSION_1_2,
+    CAIRO_SVG_VERSION_LAST
+} cairo_svg_version_t;
+
+cairo_public cairo_surface_t *
 cairo_svg_surface_create (const char   *filename,
 			  double	width_in_points,
 			  double	height_in_points);
-cairo_surface_t *
-cairo_svg_surface_create_1_1 (const char   *filename,
-			      double	    width_in_points,
-			      double	    height_in_points);
-cairo_surface_t *
-cairo_svg_surface_create_1_2 (const char   *filename,
-			     double	    width_in_points,
-			     double	    height_in_points);
 
-cairo_surface_t *
+cairo_public cairo_surface_t *
 cairo_svg_surface_create_for_stream (cairo_write_func_t	write_func,
 				     void	       *closure,
 				     double		width_in_points,
 				     double		height_in_points);
-cairo_surface_t *
-cairo_svg_surface_create_for_stream_1_1 (cairo_write_func_t  write_func,
-					 void		    *closure,
-					 double		     width_in_points,
-					 double		     height_in_points);
-cairo_surface_t *
-cairo_svg_surface_create_for_stream_1_2 (cairo_write_func_t  write_func,
-					 void		    *closure,
-					 double		     width_in_points,
-					 double		     height_in_points);
 
-void
+cairo_public void
 cairo_svg_surface_set_dpi (cairo_surface_t     *surface,
 			   double		x_dpi,
 			   double		y_dpi);
 
+cairo_public void
+cairo_svg_surface_restrict_to_version (cairo_surface_t 		*surface,
+				       cairo_svg_version_t  	 version);
+
+cairo_public void
+cairo_svg_get_versions (cairo_svg_version_t const	**versions,
+                        int                      	 *num_versions);
+
+cairo_public const char *
+cairo_svg_version_to_string (cairo_svg_version_t version);
+
 CAIRO_END_DECLS
 
 #else  /* CAIRO_HAS_SVG_SURFACE */


More information about the cairo-commit mailing list