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



commit ac5564493f13ff905c9d29d4fc6088da06e61a9e
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Feb 20 13:34:40 2015 -0600

    RsvgNodeLine: Use RsvgPathBuilder instead of building/parsing a path string
    
    Again; no need to go through the production process for Luwak coffee just to
    paint a line.
    
    Signed-off-by: Federico Mena Quintero <federico gnome org>

 rsvg-shapes.c |   33 +++++++++++++--------------------
 1 files changed, 13 insertions(+), 20 deletions(-)
---
diff --git a/rsvg-shapes.c b/rsvg-shapes.c
index 4275436..2ee4388 100644
--- a/rsvg-shapes.c
+++ b/rsvg-shapes.c
@@ -281,34 +281,27 @@ _rsvg_node_line_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * a
 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];
+    RsvgPathBuilder builder;
     RsvgNodeLine *self = (RsvgNodeLine *) overself;
+    double x1, y1, x2, y2;
 
-    /* emulate a line using a path */
-    /* ("M %f %f L %f %f", x1, y1, x2, y2) */
-    d = g_string_new ("M ");
+    rsvg_path_builder_init (&builder, 4);
 
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf),
-                                        _rsvg_css_normalize_length (&self->x1, ctx, 'h')));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf),
-                                        _rsvg_css_normalize_length (&self->y1, ctx, 'v')));
-    g_string_append (d, " L ");
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf),
-                                        _rsvg_css_normalize_length (&self->x2, ctx, 'h')));
-    g_string_append_c (d, ' ');
-    g_string_append (d, g_ascii_dtostr (buf, sizeof (buf),
-                                        _rsvg_css_normalize_length (&self->y2, ctx, 'v')));
+    x1 = _rsvg_css_normalize_length (&self->x1, ctx, 'h');
+    y1 = _rsvg_css_normalize_length (&self->y1, ctx, 'v');
+    x2 = _rsvg_css_normalize_length (&self->x2, ctx, 'h');
+    y2 = _rsvg_css_normalize_length (&self->y2, ctx, 'v');
+
+    rsvg_path_builder_move_to (&builder, x1, y1);
+    rsvg_path_builder_line_to (&builder, x2, y2);
+
+    path = rsvg_path_builder_finish (&builder);
 
     rsvg_state_reinherit_top (ctx, overself->state, dominate);
 
-    path = rsvg_parse_path (d->str);
     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]