From fd3d01047c69b633d0dfc2f079791c3302971004 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 23 Oct 2014 22:18:16 +0100 Subject: [PATCH] fix parsing of whitespace in transform operators The SVG spec for the transform attribute allows whitespace in places that were causing the %n specifier in the ssanf to return 0 as the match failed before it completed the parse. http://www.w3.org/TR/SVG/coords.html#TransformAttribute --- src/svgtiny.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/svgtiny.c b/src/svgtiny.c index 413697c..f02f3d6 100644 --- a/src/svgtiny.c +++ b/src/svgtiny.c @@ -1501,23 +1501,23 @@ void svgtiny_parse_transform(char *s, float *ma, float *mb, a = d = 1; b = c = 0; e = f = 0; - if (sscanf(s, "matrix (%f %f %f %f %f %f) %n", - &a, &b, &c, &d, &e, &f, &n) == 6) + if ((sscanf(s, " matrix (%f %f %f %f %f %f ) %n", + &a, &b, &c, &d, &e, &f, &n) == 6) && (n > 0)) ; - else if (sscanf(s, "translate (%f %f) %n", - &e, &f, &n) == 2) + else if ((sscanf(s, " translate (%f %f ) %n", + &e, &f, &n) == 2) && (n > 0)) ; - else if (sscanf(s, "translate (%f) %n", - &e, &n) == 1) + else if ((sscanf(s, " translate (%f ) %n", + &e, &n) == 1) && (n > 0)) ; - else if (sscanf(s, "scale (%f %f) %n", - &a, &d, &n) == 2) + else if ((sscanf(s, " scale (%f %f ) %n", + &a, &d, &n) == 2) && (n > 0)) ; - else if (sscanf(s, "scale (%f) %n", - &a, &n) == 1) + else if ((sscanf(s, " scale (%f ) %n", + &a, &n) == 1) && (n > 0)) d = a; - else if (sscanf(s, "rotate (%f %f %f) %n", - &angle, &x, &y, &n) == 3) { + else if ((sscanf(s, " rotate (%f %f %f ) %n", + &angle, &x, &y, &n) == 3) && (n > 0)) { angle = angle / 180 * M_PI; a = cos(angle); b = sin(angle); @@ -1525,19 +1525,19 @@ void svgtiny_parse_transform(char *s, float *ma, float *mb, d = cos(angle); e = -x * cos(angle) + y * sin(angle) + x; f = -x * sin(angle) - y * cos(angle) + y; - } else if (sscanf(s, "rotate (%f) %n", - &angle, &n) == 1) { + } else if ((sscanf(s, " rotate (%f ) %n", + &angle, &n) == 1) && (n > 0)) { angle = angle / 180 * M_PI; a = cos(angle); b = sin(angle); c = -sin(angle); d = cos(angle); - } else if (sscanf(s, "skewX (%f) %n", - &angle, &n) == 1) { + } else if ((sscanf(s, " skewX (%f ) %n", + &angle, &n) == 1) && (n > 0)) { angle = angle / 180 * M_PI; c = tan(angle); - } else if (sscanf(s, "skewY (%f) %n", - &angle, &n) == 1) { + } else if ((sscanf(s, " skewY (%f ) %n", + &angle, &n) == 1) && (n > 0)) { angle = angle / 180 * M_PI; b = tan(angle); } else -- 2.44.2