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;
*number = strtol(*content, &end, 10) ? 1 : 0;
//If the start of string is not number
if ((*content) == end) return false;
*number = strtol(*content, &end, 10);
//If the start of string is not number or a number was a float
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);
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[1])) {
if (_parseNumber(&path, &arr[2])) {
if (_parseLong(&path, &large)) {
if (_parseLong(&path, &sweep)) {
if (_parseFlag(&path, &large)) {
if (_parseFlag(&path, &sweep)) {
if (_parseNumber(&path, &arr[5])) {
if (_parseNumber(&path, &arr[6])) {
arr[3] = large;
@ -519,4 +521,4 @@ tuple<vector<PathCommand>, vector<Point>> svgPathToTvgPath(const char* svgPath)
if (curLocale) free(curLocale);
return make_tuple(cmds, pts);
}
}