SvgPath: When path end(Z,z), Current point are returned to starting point(M,m)
authorJunsuChoi <jsuya.choi@samsung.com>
Tue, 22 Sep 2020 05:28:51 +0000 (14:28 +0900)
committerHermet Park <chuneon.park@samsung.com>
Wed, 23 Sep 2020 05:44:07 +0000 (14:44 +0900)
When path ends with 'z' or 'Z' command, if 'm' comes as next command,
the current point is incorrectly referenced.
Since 'Z', 'z' means to close the path,
so, Save point and reuse it when 'M' or 'm' is called.

Change-Id: I6b47ec0d424dbc7dfc3bcf1344cf2ae4c15a1081

src/loaders/svg/tvgSvgPath.cpp

index 2e3edab..e3ea03e 100644 (file)
@@ -280,7 +280,7 @@ static int _numberCount(char cmd)
 }
 
 
-static void _processCommand(vector<PathCommand>* cmds, vector<Point>* pts, char cmd, float* arr, int count, Point* cur, Point* curCtl, bool *isQuadratic)
+static void _processCommand(vector<PathCommand>* cmds, vector<Point>* pts, char cmd, float* arr, int count, Point* cur, Point* curCtl, Point* startPoint, bool *isQuadratic)
 {
     int i;
     switch (cmd) {
@@ -321,6 +321,7 @@ static void _processCommand(vector<PathCommand>* cmds, vector<Point>* pts, char
             cmds->push_back(PathCommand::MoveTo);
             pts->push_back(p);
             *cur = {arr[0] ,arr[1]};
+            *startPoint = {arr[0] ,arr[1]};
             break;
         }
         case 'l':
@@ -432,6 +433,7 @@ static void _processCommand(vector<PathCommand>* cmds, vector<Point>* pts, char
         case 'z':
         case 'Z': {
             cmds->push_back(PathCommand::Close);
+            *cur = *startPoint;
             break;
         }
         case 'a':
@@ -503,6 +505,7 @@ tuple<vector<PathCommand>, vector<Point>> svgPathToTvgPath(const char* svgPath)
     int numberCount = 0;
     Point cur = { 0, 0 };
     Point curCtl = { 0, 0 };
+    Point startPoint = { 0, 0 };
     char cmd = 0;
     bool isQuadratic = false;
     char* path = (char*)svgPath;
@@ -515,7 +518,7 @@ tuple<vector<PathCommand>, vector<Point>> svgPathToTvgPath(const char* svgPath)
     while ((path[0] != '\0')) {
         path = _nextCommand(path, &cmd, numberArray, &numberCount);
         if (!path) break;
-        _processCommand(&cmds, &pts, cmd, numberArray, numberCount, &cur, &curCtl, &isQuadratic);
+        _processCommand(&cmds, &pts, cmd, numberArray, numberCount, &cur, &curCtl, &startPoint, &isQuadratic);
     }
 
     setlocale(LC_NUMERIC, curLocale);