From 2d35f3325216927539a026c2e74c0f874e04a137 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Sun, 22 Nov 2009 13:32:37 +0000 Subject: Start implementing arcs in paths. Fix crash when an empty path has a gradient fill. svn path=/trunk/libsvgtiny/; revision=9682 --- src/svgtiny.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/svgtiny.c b/src/svgtiny.c index 56f0028..aae0b0e 100644 --- a/src/svgtiny.c +++ b/src/svgtiny.c @@ -240,7 +240,7 @@ svgtiny_code svgtiny_parse_path(xmlNode *path, while (*s) { char command[2]; int plot_command; - float x, y, x1, y1, x2, y2; + float x, y, x1, y1, x2, y2, rx, ry, rotation, large_arc, sweep; int n; /* moveto (M, m), lineto (L, l) (2 arguments) */ @@ -395,14 +395,39 @@ svgtiny_code svgtiny_parse_path(xmlNode *path, } while (sscanf(s, "%f %f %n", &x, &y, &n) == 2); + /* elliptical arc (A, a) (7 arguments) */ + } else if (sscanf(s, " %1[Aa] %f %f %f %f %f %f %f %n", command, + &rx, &ry, &rotation, &large_arc, &sweep, + &x, &y, &n) == 8) { + do { + p[i++] = svgtiny_PATH_LINE; + if (*command == 'a') { + x += last_x; + y += last_y; + } + p[i++] = last_cubic_x = last_quad_x = last_x + = x; + p[i++] = last_cubic_y = last_quad_y = last_y + = y; + s += n; + } while (sscanf(s, "%f %f %f %f %f %f %f %n", + &rx, &ry, &rotation, &large_arc, &sweep, + &x, &y, &n) == 7); + } else { - /*LOG(("parse failed at \"%s\"", s));*/ + fprintf(stderr, "parse failed at \"%s\"\n", s); break; } } xmlFree(path_d); + if (i <= 4) { + /* no real segments in path */ + free(p); + return svgtiny_OK; + } + return svgtiny_add_path(p, i, &state); } -- cgit v1.2.3