Merge pull request #145 from wcout/issue_139

Fix issue #139: Nano SVG is still locale dependent
This commit is contained in:
Mikko Mononen 2018-12-14 22:22:57 +02:00 committed by GitHub
commit c1f6e209c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1422,8 +1422,7 @@ static unsigned int nsvg__parseColor(const char* str)
static float nsvg__parseOpacity(const char* str) static float nsvg__parseOpacity(const char* str)
{ {
float val = 0; float val = nsvg__atof(str);
sscanf(str, "%f", &val);
if (val < 0.0f) val = 0.0f; if (val < 0.0f) val = 0.0f;
if (val > 1.0f) val = 1.0f; if (val > 1.0f) val = 1.0f;
return val; return val;
@ -1431,8 +1430,7 @@ static float nsvg__parseOpacity(const char* str)
static float nsvg__parseMiterLimit(const char* str) static float nsvg__parseMiterLimit(const char* str)
{ {
float val = 0; float val = nsvg__atof(str);
sscanf(str, "%f", &val);
if (val < 0.0f) val = 0.0f; if (val < 0.0f) val = 0.0f;
return val; return val;
} }
@ -1463,9 +1461,9 @@ static int nsvg__parseUnits(const char* units)
static NSVGcoordinate nsvg__parseCoordinateRaw(const char* str) static NSVGcoordinate nsvg__parseCoordinateRaw(const char* str)
{ {
NSVGcoordinate coord = {0, NSVG_UNITS_USER}; NSVGcoordinate coord = {0, NSVG_UNITS_USER};
char units[32]=""; char buf[64];
sscanf(str, "%f%31s", &coord.value, units); coord.units = nsvg__parseUnits(nsvg__parseNumber(str, buf, 64));
coord.units = nsvg__parseUnits(units); coord.value = nsvg__atof(buf);
return coord; return coord;
} }
@ -2505,7 +2503,22 @@ static void nsvg__parseSVG(NSVGparser* p, const char** attr)
} else if (strcmp(attr[i], "height") == 0) { } else if (strcmp(attr[i], "height") == 0) {
p->image->height = nsvg__parseCoordinate(p, attr[i + 1], 0.0f, 0.0f); p->image->height = nsvg__parseCoordinate(p, attr[i + 1], 0.0f, 0.0f);
} else if (strcmp(attr[i], "viewBox") == 0) { } else if (strcmp(attr[i], "viewBox") == 0) {
sscanf(attr[i + 1], "%f%*[%%, \t]%f%*[%%, \t]%f%*[%%, \t]%f", &p->viewMinx, &p->viewMiny, &p->viewWidth, &p->viewHeight); const char *s = attr[i + 1];
char buf[64];
s = nsvg__parseNumber(s, buf, 64);
p->viewMinx = nsvg__atof(buf);
while (*s && (nsvg__isspace(*s) || *s == '%' || *s == ',')) s++;
if (!*s) return;
s = nsvg__parseNumber(s, buf, 64);
p->viewMiny = nsvg__atof(buf);
while (*s && (nsvg__isspace(*s) || *s == '%' || *s == ',')) s++;
if (!*s) return;
s = nsvg__parseNumber(s, buf, 64);
p->viewWidth = nsvg__atof(buf);
while (*s && (nsvg__isspace(*s) || *s == '%' || *s == ',')) s++;
if (!*s) return;
s = nsvg__parseNumber(s, buf, 64);
p->viewHeight = nsvg__atof(buf);
} else if (strcmp(attr[i], "preserveAspectRatio") == 0) { } else if (strcmp(attr[i], "preserveAspectRatio") == 0) {
if (strstr(attr[i + 1], "none") != 0) { if (strstr(attr[i + 1], "none") != 0) {
// No uniform scaling // No uniform scaling