[librsvg] RsvgNodeEllipse: Use RsvgPathBuilder instead of building/parsing a path string



commit 6fd7493ef2ba7ed9d8e76a3ae5b064c34825422f
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Feb 20 16:24:02 2015 -0600

    RsvgNodeEllipse: Use RsvgPathBuilder instead of building/parsing a path string
    
    Signed-off-by: Federico Mena Quintero <federico gnome org>

 rsvg-shapes.c |   93 ++++++++++++++++++---------------------------------------
 1 files changed, 29 insertions(+), 64 deletions(-)
---
diff --git a/rsvg-shapes.c b/rsvg-shapes.c
index 3b2de3d..df8641f 100644
--- a/rsvg-shapes.c
+++ b/rsvg-shapes.c
@@ -644,10 +644,9 @@ static void
 _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;
+    RsvgPathBuilder builder;
 
     cx = _rsvg_css_normalize_length (&ellipse->cx, ctx, 'h');
     cy = _rsvg_css_normalize_length (&ellipse->cy, ctx, 'v');
@@ -656,74 +655,40 @@ _rsvg_node_ellipse_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
 
     if (rx <= 0 || ry <= 0)
         return;
+
     /* approximate an ellipse using 4 bezier curves */
 
-    d = g_string_new ("M ");
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx + rx));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy));
-
-    g_string_append (d, " C ");
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx + rx));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy - RSVG_ARC_MAGIC * ry));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx + RSVG_ARC_MAGIC * rx));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy - ry));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy - ry));
-
-    g_string_append (d, " C ");
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx - RSVG_ARC_MAGIC * rx));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy - ry));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx - rx));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy - RSVG_ARC_MAGIC * ry));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx - rx));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy));
-
-    g_string_append (d, " C ");
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx - rx));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy + RSVG_ARC_MAGIC * ry));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx - RSVG_ARC_MAGIC * rx));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy + ry));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy + ry));
-
-    g_string_append (d, " C ");
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx + RSVG_ARC_MAGIC * rx));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy + ry));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx + rx));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy + RSVG_ARC_MAGIC * ry));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx + rx));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy));
-
-    g_string_append (d, " Z");
+    rsvg_path_builder_init (&builder, 19);
 
-    rsvg_state_reinherit_top (ctx, self->state, dominate);
+    rsvg_path_builder_move_to (&builder, cx + rx, cy);
+
+    rsvg_path_builder_curve_to (&builder,
+                                cx + rx, cy - RSVG_ARC_MAGIC * ry,
+                                cx + RSVG_ARC_MAGIC * rx, cy - ry,
+                                cx, cy - ry);
+
+    rsvg_path_builder_curve_to (&builder,
+                                cx - RSVG_ARC_MAGIC * rx, cy - ry,
+                                cx - rx, cy - RSVG_ARC_MAGIC * ry,
+                                cx - rx, cy);
+
+    rsvg_path_builder_curve_to (&builder,
+                                cx - rx, cy + RSVG_ARC_MAGIC * ry,
+                                cx - RSVG_ARC_MAGIC * rx, cy + ry,
+                                cx, cy + ry);
+
+    rsvg_path_builder_curve_to (&builder,
+                                cx + RSVG_ARC_MAGIC * rx, cy + ry,
+                                cx + rx, cy + RSVG_ARC_MAGIC * ry,
+                                cx + rx, cy);
+
+    rsvg_path_builder_close_path (&builder);
 
-    path = rsvg_parse_path (d->str);
+    path = rsvg_path_builder_finish (&builder);
+
+    rsvg_state_reinherit_top (ctx, self->state, dominate);
     rsvg_render_path (ctx, path);
     rsvg_cairo_path_destroy (path);
-
-    g_string_free (d, TRUE);
 }
 
 RsvgNode *


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