[librsvg/next: 27/31] Render paths from cairo_path_t



commit 2801ef5bd58968ec2d6587a5ed5983bbef4658b8
Author: Christian Persch <chpe gnome org>
Date:   Fri Sep 16 22:23:07 2011 +0200

    Render paths from cairo_path_t
    
    Pass the cairo_path_t to the render funtion, instead of a string.

 rsvg-base.c    |    8 +-------
 rsvg-private.h |    2 +-
 rsvg-shapes.c  |   46 +++++++++++++++++++++++++++++++++++-----------
 rsvg-shapes.h  |    3 ++-
 4 files changed, 39 insertions(+), 20 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index f473d69..56fdef5 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -2060,16 +2060,10 @@ rsvg_push_discrete_layer (RsvgDrawingCtx * ctx)
 }
 
 void
-rsvg_render_path (RsvgDrawingCtx * ctx, const char *d)
+rsvg_render_path (RsvgDrawingCtx * ctx, const cairo_path_t *path)
 {
-    /* todo: store and use the path higher up */
-    cairo_path_t *path;
-
-    path = rsvg_parse_path (d);
-
     ctx->render->render_path (ctx, path);
     rsvg_render_markers (ctx, path);
-    rsvg_cairo_path_destroy (path);
 }
 
 void
diff --git a/rsvg-private.h b/rsvg-private.h
index ce12302..a17aa9f 100644
--- a/rsvg-private.h
+++ b/rsvg-private.h
@@ -375,7 +375,7 @@ GByteArray  *_rsvg_acquire_xlink_href_resource  (const char *href,
 
 void rsvg_pop_discrete_layer    (RsvgDrawingCtx * ctx);
 void rsvg_push_discrete_layer   (RsvgDrawingCtx * ctx);
-void rsvg_render_path           (RsvgDrawingCtx * ctx, const char *d);
+void rsvg_render_path           (RsvgDrawingCtx * ctx, const cairo_path_t *path);
 void rsvg_render_image          (RsvgDrawingCtx * ctx, GdkPixbuf * pb,
                                  double x, double y, double w, double h);
 void rsvg_render_free           (RsvgRender * render);
diff --git a/rsvg-shapes.c b/rsvg-shapes.c
index 07baf24..6e203de 100644
--- a/rsvg-shapes.c
+++ b/rsvg-shapes.c
@@ -35,6 +35,7 @@
 #include "rsvg-shapes.h"
 #include "rsvg-css.h"
 #include "rsvg-defs.h"
+#include "rsvg-path.h"
 
 /* 4/3 * (1-cos 45Â)/sin 45Â = 4/3 * sqrt(2) - 1 */
 #define RSVG_ARC_MAGIC ((double) 0.5522847498)
@@ -42,23 +43,25 @@
 static void
 rsvg_node_path_free (RsvgNode * self)
 {
-    RsvgNodePath *z = (RsvgNodePath *) self;
-    if (z->d)
-        g_free (z->d);
-    _rsvg_node_finalize (&z->super);
-    g_free (z);
+    RsvgNodePath *path = (RsvgNodePath *) self;
+    g_free (path->d);
+    _rsvg_node_finalize (&path->super);
+    g_free (path);
 }
 
 static void
 rsvg_node_path_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
 {
     RsvgNodePath *path = (RsvgNodePath *) self;
+    cairo_path_t *p;
     if (!path->d)
         return;
 
     rsvg_state_reinherit_top (ctx, self->state, dominate);
 
-    rsvg_render_path (ctx, path->d);
+    p = rsvg_parse_path (path->d);
+    rsvg_render_path (ctx, p);
+    rsvg_cairo_path_destroy (p);
 }
 
 static void
@@ -138,6 +141,7 @@ _rsvg_node_poly_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
     RsvgNodePoly *poly = (RsvgNodePoly *) self;
     gsize i;
     GString *d;
+    cairo_path_t *path;
     char buf[G_ASCII_DTOSTR_BUF_SIZE];
 
     /* represent as a "moveto, lineto*, close" path */
@@ -164,7 +168,10 @@ _rsvg_node_poly_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
         g_string_append (d, " Z");
 
     rsvg_state_reinherit_top (ctx, self->state, dominate);
-    rsvg_render_path (ctx, d->str);
+
+    path = rsvg_parse_path (d->str);
+    rsvg_render_path (ctx, path);
+    rsvg_cairo_path_destroy (path);
 
     g_string_free (d, TRUE);
 }
@@ -244,6 +251,7 @@ static void
 _rsvg_node_line_draw (RsvgNode * overself, RsvgDrawingCtx * ctx, int dominate)
 {
     GString *d;
+    cairo_path_t *path;
     char buf[G_ASCII_DTOSTR_BUF_SIZE];
     RsvgNodeLine *self = (RsvgNodeLine *) overself;
 
@@ -264,7 +272,10 @@ _rsvg_node_line_draw (RsvgNode * overself, RsvgDrawingCtx * ctx, int dominate)
                                         _rsvg_css_normalize_length (&self->y2, ctx, 'v')));
 
     rsvg_state_reinherit_top (ctx, overself->state, dominate);
-    rsvg_render_path (ctx, d->str);
+
+    path = rsvg_parse_path (d->str);
+    rsvg_render_path (ctx, path);
+    rsvg_cairo_path_destroy (path);
 
     g_string_free (d, TRUE);
 }
@@ -328,6 +339,7 @@ _rsvg_node_rect_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
 {
     double x, y, w, h, rx, ry;
     GString *d = NULL;
+    cairo_path_t *path;
     RsvgNodeRect *rect = (RsvgNodeRect *) self;
     char buf[G_ASCII_DTOSTR_BUF_SIZE];
 
@@ -441,7 +453,10 @@ _rsvg_node_rect_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
     g_string_append (d, " Z");
 
     rsvg_state_reinherit_top (ctx, self->state, dominate);
-    rsvg_render_path (ctx, d->str);
+
+    path = rsvg_parse_path (d->str);
+    rsvg_render_path (ctx, path);
+    rsvg_cairo_path_destroy (path);
     g_string_free (d, TRUE);
 }
 
@@ -493,6 +508,7 @@ static void
 _rsvg_node_circle_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
 {
     GString *d = NULL;
+    cairo_path_t *path;
     RsvgNodeCircle *circle = (RsvgNodeCircle *) self;
     char buf[G_ASCII_DTOSTR_BUF_SIZE];
     double cx, cy, r;
@@ -566,7 +582,10 @@ _rsvg_node_circle_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
     g_string_append (d, " Z");
 
     rsvg_state_reinherit_top (ctx, self->state, dominate);
-    rsvg_render_path (ctx, d->str);
+
+    path = rsvg_parse_path (d->str);
+    rsvg_render_path (ctx, path);
+    rsvg_cairo_path_destroy (path);
 
     g_string_free (d, TRUE);
 }
@@ -621,6 +640,7 @@ _rsvg_node_ellipse_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
 {
     RsvgNodeEllipse *ellipse = (RsvgNodeEllipse *) self;
     GString *d = NULL;
+    cairo_path_t *path;
     char buf[G_ASCII_DTOSTR_BUF_SIZE];
     double cx, cy, rx, ry;
 
@@ -693,7 +713,11 @@ _rsvg_node_ellipse_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
     g_string_append (d, " Z");
 
     rsvg_state_reinherit_top (ctx, self->state, dominate);
-    rsvg_render_path (ctx, d->str);
+
+    path = rsvg_parse_path (d->str);
+    rsvg_render_path (ctx, path);
+    rsvg_cairo_path_destroy (path);
+
     g_string_free (d, TRUE);
 }
 
diff --git a/rsvg-shapes.h b/rsvg-shapes.h
index baad98f..8a1dee0 100644
--- a/rsvg-shapes.h
+++ b/rsvg-shapes.h
@@ -30,6 +30,8 @@
 #ifndef RSVG_SHAPES_H
 #define RSVG_SHAPES_H
 
+#include <cairo.h>
+
 #include "rsvg-structure.h"
 
 G_BEGIN_DECLS 
@@ -42,7 +44,6 @@ RsvgNode *rsvg_new_rect (void);
 RsvgNode *rsvg_new_circle (void);
 RsvgNode *rsvg_new_ellipse (void);
 
-
 typedef struct _RsvgNodePath RsvgNodePath;
 
 struct _RsvgNodePath {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]