[cairo-commit] src/cairo-svg.h src/cairo-svg-surface.c
Emmanuel Pacaud
emmanuel at kemper.freedesktop.org
Fri May 5 07:30:55 PDT 2006
src/cairo-svg-surface.c | 62 +++++++++++++++++++++++++++++++-----------------
src/cairo-svg.h | 2 -
2 files changed, 42 insertions(+), 22 deletions(-)
New commits:
diff-tree 36fcaa76d66c16fcedddf3c3e967afa3f4a96615 (from 6b40ba283b6d09a7bf3bd0ec795a19b05b9bfec4)
Author: Emmanuel Pacaud <emmanuel.pacaud at free.fr>
Date: Fri May 5 16:02:04 2006 +0200
SVG: Fix cairo_svg_surface_restrict_to_version.
surface parameter is actually a paginated surface.
Use the same logic as pdf backend.
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 96ed461..2c5066b 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -258,6 +258,29 @@ _cairo_surface_is_svg (cairo_surface_t *
return surface->backend == &cairo_svg_surface_backend;
}
+/* If the abstract_surface is a paginated surface, and that paginated
+ * surface's target is a svg_surface, then set svg_surface to that
+ * target. Otherwise return CAIRO_STATUS_SURFACE_TYPE_MISMATCH.
+ */
+static cairo_status_t
+_extract_svg_surface (cairo_surface_t *surface,
+ cairo_svg_surface_t **svg_surface)
+{
+ cairo_surface_t *target;
+
+ if (! _cairo_surface_is_paginated (surface))
+ return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
+
+ target = _cairo_paginated_surface_get_target (surface);
+
+ if (! _cairo_surface_is_svg (target))
+ return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
+
+ *svg_surface = (cairo_svg_surface_t *) target;
+
+ return CAIRO_STATUS_SUCCESS;
+}
+
/**
* cairo_svg_surface_set_dpi:
* @surface: a svg cairo_surface_t
@@ -272,29 +295,22 @@ _cairo_surface_is_svg (cairo_surface_t *
**/
void
-cairo_svg_surface_set_dpi (cairo_surface_t *surface,
+cairo_svg_surface_set_dpi (cairo_surface_t *abstract_surface,
double x_dpi,
double y_dpi)
{
- cairo_surface_t *target;
- cairo_svg_surface_t *svg_surface;
-
- if (!_cairo_surface_is_paginated (surface)) {
- _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
- return;
- }
-
- target = _cairo_paginated_surface_get_target (surface);
+ cairo_svg_surface_t *surface;
+ cairo_status_t status;
- if (!_cairo_surface_is_svg (target)) {
- _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
+ status = _extract_svg_surface (abstract_surface, &surface);
+ if (status) {
+ _cairo_surface_set_error (abstract_surface,
+ CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
return;
}
- svg_surface = (cairo_svg_surface_t *) target;
-
- svg_surface->document->x_dpi = x_dpi;
- svg_surface->document->y_dpi = y_dpi;
+ surface->document->x_dpi = x_dpi;
+ surface->document->y_dpi = y_dpi;
}
/**
@@ -316,13 +332,17 @@ cairo_svg_surface_restrict_to_version (c
cairo_svg_version_t version)
{
cairo_svg_surface_t *surface;
-
- if (!_cairo_surface_is_svg (abstract_surface) ||
- version < 0 || version >= CAIRO_SVG_VERSION_LAST)
+ cairo_status_t status;
+
+ status = _extract_svg_surface (abstract_surface, &surface);
+ if (status) {
+ _cairo_surface_set_error (abstract_surface,
+ CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
return;
+ }
- surface = (cairo_svg_surface_t *) abstract_surface;
- surface->document->svg_version = version;
+ if (version >= 0 && version < CAIRO_SVG_VERSION_LAST)
+ surface->document->svg_version = version;
}
/**
diff --git a/src/cairo-svg.h b/src/cairo-svg.h
index cac6c0e..9053ff0 100644
--- a/src/cairo-svg.h
+++ b/src/cairo-svg.h
@@ -39,7 +39,7 @@
CAIRO_BEGIN_DECLS
typedef enum {
- CAIRO_SVG_VERSION_1_1,
+ CAIRO_SVG_VERSION_1_1 = 0,
CAIRO_SVG_VERSION_1_2,
CAIRO_SVG_VERSION_LAST
} cairo_svg_version_t;
More information about the cairo-commit
mailing list