evas canvas: Fixed svg path command processing. 76/246276/5
authorMichal Szczecinski <m.szczecinsk@partner.samsung.com>
Tue, 27 Oct 2020 07:23:37 +0000 (08:23 +0100)
committerHermet Park <chuneon.park@samsung.com>
Thu, 5 Nov 2020 06:37:39 +0000 (06:37 +0000)
Changes:
1. Added _parse_flag optimization
2. Set current control point properly for set type commands in path
parser.

Change-Id: Ic88180832d2a9e46828819561027eb7db56a9c38

src/lib/evas/canvas/evas_tvg_path_helpers.h

index 36535dc..f27d602 100644 (file)
@@ -51,17 +51,10 @@ static inline Eina_Bool
 _parse_flag(char **content, int *number)
 {
    char *end = NULL;
-   char *end_test = NULL;
-   char content_test[strlen(*content) + 1];
-   int number_test;
 
-   strcpy(content_test,*content);
-   *number = strtol(*content, &end, 10) ? 1 : 0;
-   if ((*content) == end) return EINA_FALSE;
-   number_test = (int)strtof(content_test, &end_test);
-
-   if ((*number != number_test) || (*end != *end_test))
-     return EINA_FALSE;
+   *number = strtol(*content, &end, 10);
+   if ((*content) == end || *end == '.') return EINA_FALSE;
+   if (*number != 0 && *number != 1) return EINA_FALSE;
 
    *content = _skipcomma(end);
    return EINA_TRUE;
@@ -417,17 +410,14 @@ _process_command(Efl_Tvg_Shape_Svg_Path *svg_path, char c, double *pts,
       case 'S':
         {
            double ctrl_x, ctrl_y;
+           ctrl_x = *cur_x;
+           ctrl_y = *cur_y;
            if ((svg_path->cmds_cnt > 1) && (svg_path->cmds[svg_path->cmds_cnt - 1] ==
                 TVG_PATH_COMMAND_CUBIC_TO) && !(*is_quadratic))
              {
                 ctrl_x = *cur_x * 2 - *cur_ctl_x;
                 ctrl_y = *cur_y * 2 - *cur_ctl_y;
              }
-           else
-             {
-                ctrl_x = *cur_x;
-                ctrl_y = *cur_y;
-             }
            if (!_svg_path_grow(svg_path, 3)) break;
            svg_path->pts[svg_path->pts_cnt-3].x = ctrl_x;
            svg_path->pts[svg_path->pts_cnt-3].y = ctrl_y;
@@ -469,17 +459,14 @@ _process_command(Efl_Tvg_Shape_Svg_Path *svg_path, char c, double *pts,
       case 'T':
        {
            double ctrl_x, ctrl_y, ctrl_x0, ctrl_y0, ctrl_x1, ctrl_y1;
+           ctrl_x = *cur_x;
+           ctrl_y = *cur_y;
            if ((svg_path->cmds_cnt > 1) && (svg_path->cmds[svg_path->cmds_cnt - 1] ==
                 TVG_PATH_COMMAND_CUBIC_TO) && *is_quadratic)
              {
                 ctrl_x = *cur_x * 2 - *cur_ctl_x;
                 ctrl_y = *cur_y * 2 - *cur_ctl_y;
              }
-           else
-             {
-                ctrl_x = *cur_x;
-                ctrl_y = *cur_y;
-             }
            ctrl_x0 = (*cur_x + 2 * ctrl_x) * (1.0 / 3.0);
            ctrl_y0 = (*cur_y + 2 * ctrl_y) * (1.0 / 3.0);
            ctrl_x1 = (pts[0] + 2 * ctrl_x) * (1.0 / 3.0);