X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fsvgtiny.c;h=aae0b0e1fb0c95ca0062781d07fad2c5bd9f6fec;hb=edf35196f5130c6e6f8430d9af6bb52033a56b79;hp=ab6b6dd5ea30f282320fa33bcccd5fff437a5be3;hpb=15cdb30e3125ce542289fe385f559799e5abf220;p=libsvgtiny.git diff --git a/src/svgtiny.c b/src/svgtiny.c index ab6b6dd..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); } @@ -709,6 +734,8 @@ float svgtiny_parse_length(const char *s, int viewport_size, float n = atof((const char *) s); float font_size = 20; /*css_len2px(&state.style.font_size.value.length, 0);*/ + UNUSED(state); + if (unit[0] == 0) { return n; } else if (unit[0] == '%') { @@ -807,7 +834,7 @@ void svgtiny_parse_color(const char *s, svgtiny_colour *c, } else if (10 <= len && s[0] == 'r' && s[1] == 'g' && s[2] == 'b' && s[3] == '(' && s[len - 1] == ')') { - if (sscanf(s + 4, "%i,%i,%i", &r, &g, &b) == 3) + if (sscanf(s + 4, "%u,%u,%u", &r, &g, &b) == 3) *c = svgtiny_RGB(r, g, b); else if (sscanf(s + 4, "%f%%,%f%%,%f%%", &rf, &gf, &bf) == 3) { b = bf * 255 / 100; @@ -856,6 +883,8 @@ void svgtiny_parse_color(const char *s, svgtiny_colour *c, void svgtiny_parse_font_attributes(const xmlNode *node, struct svgtiny_parse_state *state) { + UNUSED(state); + for (const xmlAttr *attr = node->properties; attr; attr = attr->next) { if (strcmp((const char *) attr->name, "font-size") == 0) { /*if (css_parse_length(