Gpencil: Fix for SVG import arc and float errors
Fix for the Arc commands (A/a) to successfully parse the 4th and 5th arguments.
Fix for floats without a specified integer part, like `.123`
File for testing:
{F10042021}
Reviewed By: filedescriptor
Differential Revision: https://developer.blender.org/D11099
This commit is contained in:
@@ -1289,7 +1289,7 @@ static const char *nsvg__parseNumber(const char *s, char *it, const int size)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *nsvg__getNextPathItem(const char *s, char *it)
|
static const char *nsvg__getNextPathItem(const char *s, char *it, char cmd, int nargs)
|
||||||
{
|
{
|
||||||
it[0] = '\0';
|
it[0] = '\0';
|
||||||
// Skip white spaces and commas
|
// Skip white spaces and commas
|
||||||
@@ -1297,6 +1297,15 @@ static const char *nsvg__getNextPathItem(const char *s, char *it)
|
|||||||
s++;
|
s++;
|
||||||
if (!*s)
|
if (!*s)
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
|
/* Blender: Special case for arc command's 4th and 5th arguments. */
|
||||||
|
if (ELEM(cmd, 'a', 'A') && ELEM(nargs, 3, 4)) {
|
||||||
|
it[0] = s[0];
|
||||||
|
it[1] = '\0';
|
||||||
|
s++;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
if (*s == '-' || *s == '+' || *s == '.' || nsvg__isdigit(*s)) {
|
if (*s == '-' || *s == '+' || *s == '.' || nsvg__isdigit(*s)) {
|
||||||
s = nsvg__parseNumber(s, it, 64);
|
s = nsvg__parseNumber(s, it, 64);
|
||||||
}
|
}
|
||||||
@@ -1576,8 +1585,8 @@ static int nsvg__isCoordinate(const char *s)
|
|||||||
// optional sign
|
// optional sign
|
||||||
if (*s == '-' || *s == '+')
|
if (*s == '-' || *s == '+')
|
||||||
s++;
|
s++;
|
||||||
// must have at least one digit
|
// must have at least one digit, or start by a dot
|
||||||
return nsvg__isdigit(*s);
|
return (nsvg__isdigit(*s) || *s == '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSVGcoordinate nsvg__parseCoordinateRaw(const char *str)
|
static NSVGcoordinate nsvg__parseCoordinateRaw(const char *str)
|
||||||
@@ -2413,7 +2422,7 @@ static void nsvg__parsePath(NSVGparser *p, const char **attr)
|
|||||||
nargs = 0;
|
nargs = 0;
|
||||||
|
|
||||||
while (*s) {
|
while (*s) {
|
||||||
s = nsvg__getNextPathItem(s, item);
|
s = nsvg__getNextPathItem(s, item, cmd, nargs);
|
||||||
if (!*item)
|
if (!*item)
|
||||||
break;
|
break;
|
||||||
if (cmd != '\0' && nsvg__isCoordinate(item)) {
|
if (cmd != '\0' && nsvg__isCoordinate(item)) {
|
||||||
@@ -2740,7 +2749,7 @@ static void nsvg__parsePoly(NSVGparser *p, const char **attr, int closeFlag)
|
|||||||
s = attr[i + 1];
|
s = attr[i + 1];
|
||||||
nargs = 0;
|
nargs = 0;
|
||||||
while (*s) {
|
while (*s) {
|
||||||
s = nsvg__getNextPathItem(s, item);
|
s = nsvg__getNextPathItem(s, item, '\0', nargs);
|
||||||
args[nargs++] = (float)nsvg__atof(item);
|
args[nargs++] = (float)nsvg__atof(item);
|
||||||
if (nargs >= 2) {
|
if (nargs >= 2) {
|
||||||
if (npts == 0)
|
if (npts == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user