svg_loader: fixing issue with parsing an svg path (A/a cmd)

The large_arc and sweep flags should be type checked and
whether their value is 1 or 0.
This commit is contained in:
Mira Grudzinska 2020-09-09 23:31:30 +02:00 committed by JunsuChoi
parent c055682724
commit fa26aa7e7b

View file

@ -44,12 +44,14 @@ static bool _parseNumber(char** content, float* number)
} }
static bool _parseLong(char** content, int* number) static bool _parseFlag(char** content, int* number)
{ {
char* end = NULL; char* end = NULL;
*number = strtol(*content, &end, 10) ? 1 : 0; *number = strtol(*content, &end, 10);
//If the start of string is not number //If the start of string is not number or a number was a float
if ((*content) == end) return false; if ((*content) == end || *end == '.') return false;
//If a flag has a different value than 0 or 1
if (*number != 0 && *number != 1) return false;
*content = _skipComma(end); *content = _skipComma(end);
return true; return true;
} }
@ -463,8 +465,8 @@ static char* _nextCommand(char* path, char* cmd, float* arr, int* count)
if (_parseNumber(&path, &arr[0])) { if (_parseNumber(&path, &arr[0])) {
if (_parseNumber(&path, &arr[1])) { if (_parseNumber(&path, &arr[1])) {
if (_parseNumber(&path, &arr[2])) { if (_parseNumber(&path, &arr[2])) {
if (_parseLong(&path, &large)) { if (_parseFlag(&path, &large)) {
if (_parseLong(&path, &sweep)) { if (_parseFlag(&path, &sweep)) {
if (_parseNumber(&path, &arr[5])) { if (_parseNumber(&path, &arr[5])) {
if (_parseNumber(&path, &arr[6])) { if (_parseNumber(&path, &arr[6])) {
arr[3] = large; arr[3] = large;
@ -519,4 +521,4 @@ tuple<vector<PathCommand>, vector<Point>> svgPathToTvgPath(const char* svgPath)
if (curLocale) free(curLocale); if (curLocale) free(curLocale);
return make_tuple(cmds, pts); return make_tuple(cmds, pts);
} }