diff options
author | Federico Mena Quintero <federico@gnome.org> | 2015-02-20 16:24:02 -0600 |
---|---|---|
committer | Federico Mena Quintero <federico@gnome.org> | 2015-02-20 16:24:02 -0600 |
commit | 6fd7493ef2ba7ed9d8e76a3ae5b064c34825422f (patch) | |
tree | 180998c404dc070f8ac4961842e91043aa1ed114 | |
parent | 3f49de8d77f787489bc0f1215ef92e3619a9875a (diff) | |
download | librsvg-6fd7493ef2ba7ed9d8e76a3ae5b064c34825422f.tar.gz |
RsvgNodeEllipse: Use RsvgPathBuilder instead of building/parsing a path string
Signed-off-by: Federico Mena Quintero <federico@gnome.org>
-rw-r--r-- | rsvg-shapes.c | 93 |
1 files changed, 29 insertions, 64 deletions
diff --git a/rsvg-shapes.c b/rsvg-shapes.c index 3b2de3df..df8641f4 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 * |