diff options
author | Federico Mena Quintero <federico@gnome.org> | 2015-02-20 16:10:49 -0600 |
---|---|---|
committer | Federico Mena Quintero <federico@gnome.org> | 2015-02-20 16:23:11 -0600 |
commit | 3f49de8d77f787489bc0f1215ef92e3619a9875a (patch) | |
tree | 3cd7fb481517824e9beeab204fa8f497b7d73c6b | |
parent | 9fe6fadb403de56fedc937f0f72b9378c5dd311f (diff) | |
download | librsvg-3f49de8d77f787489bc0f1215ef92e3619a9875a.tar.gz |
RsvgNodeCircle: Use RsvgPathBuilder instead of building/parsing a path string
Signed-off-by: Federico Mena Quintero <federico@gnome.org>
-rw-r--r-- | rsvg-shapes.c | 82 |
1 files changed, 23 insertions, 59 deletions
diff --git a/rsvg-shapes.c b/rsvg-shapes.c index c466b913..3b2de3df 100644 --- a/rsvg-shapes.c +++ b/rsvg-shapes.c @@ -548,11 +548,10 @@ _rsvg_node_circle_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * 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; + RsvgPathBuilder builder; cx = _rsvg_css_normalize_length (&circle->cx, ctx, 'h'); cy = _rsvg_css_normalize_length (&circle->cy, ctx, 'v'); @@ -563,72 +562,37 @@ _rsvg_node_circle_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate) /* approximate a circle using 4 bezier curves */ - d = g_string_new ("M "); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx + r)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy)); + rsvg_path_builder_init (&builder, 19); - g_string_append (d, " C "); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx + r)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy + r * RSVG_ARC_MAGIC)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx + r * RSVG_ARC_MAGIC)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy + r)); - 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 + r)); + rsvg_path_builder_move_to (&builder, cx + r, cy); - g_string_append (d, " C "); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx - r * RSVG_ARC_MAGIC)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy + r)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx - r)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy + r * RSVG_ARC_MAGIC)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx - r)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy)); + rsvg_path_builder_curve_to (&builder, + cx + r, cy + r * RSVG_ARC_MAGIC, + cx + r * RSVG_ARC_MAGIC, cy + r, + cx, cy + r); - g_string_append (d, " C "); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx - r)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy - r * RSVG_ARC_MAGIC)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx - r * RSVG_ARC_MAGIC)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy - r)); - 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 - r)); + rsvg_path_builder_curve_to (&builder, + cx - r * RSVG_ARC_MAGIC, cy + r, + cx - r, cy + r * RSVG_ARC_MAGIC, + cx - r, cy); - g_string_append (d, " C "); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx + r * RSVG_ARC_MAGIC)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy - r)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx + r)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy - r * RSVG_ARC_MAGIC)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cx + r)); - g_string_append_c (d, ' '); - g_string_append (d, g_ascii_dtostr (buf, sizeof (buf), cy)); + rsvg_path_builder_curve_to (&builder, + cx - r, cy - r * RSVG_ARC_MAGIC, + cx - r * RSVG_ARC_MAGIC, cy - r, + cx, cy - r); - g_string_append (d, " Z"); + rsvg_path_builder_curve_to (&builder, + cx + r * RSVG_ARC_MAGIC, cy - r, + cx + r, cy - r * RSVG_ARC_MAGIC, + cx + r, cy); - rsvg_state_reinherit_top (ctx, self->state, dominate); + 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 * |