From 79e5cd6f1a222929d0de84d8e7b1acffe7f16dce Mon Sep 17 00:00:00 2001 From: Shinwoo Kim Date: Fri, 7 Oct 2016 17:31:59 +0900 Subject: [PATCH] Revert "Revert "efl/interface: refactored svg_path() api as well as added arc animation"" This reverts commit 7b1f471fe87455e9f9b673aee9e82cb0edadeb89. Change-Id: I34a121ad2bf346c5fd90b60aaa7beda5d022fee6 --- src/lib/efl/interfaces/efl_gfx_shape.c | 830 ++++++++++++++------------------- 1 file changed, 357 insertions(+), 473 deletions(-) diff --git a/src/lib/efl/interfaces/efl_gfx_shape.c b/src/lib/efl/interfaces/efl_gfx_shape.c index 7ffcda5..a5b7097 100644 --- a/src/lib/efl/interfaces/efl_gfx_shape.c +++ b/src/lib/efl/interfaces/efl_gfx_shape.c @@ -28,6 +28,7 @@ struct _Efl_Gfx_Shape_Data unsigned int commands_count; unsigned int points_count; + char *path_data; Eina_Bool convex; }; @@ -315,6 +316,9 @@ _efl_gfx_property_get(const Eo *obj, Efl_Gfx_Property *property) property->j = efl_gfx_shape_stroke_join_get()); } +static void _path_interpolation(Eo *obj, Efl_Gfx_Shape_Data *pd, char *from, char *to, double pos); +static void _efl_gfx_shape_reset(Eo *obj, Efl_Gfx_Shape_Data *pd); + static Eina_Bool _efl_gfx_shape_interpolate(Eo *obj, Efl_Gfx_Shape_Data *pd, const Eo *from, const Eo *to, double pos_map) @@ -331,61 +335,70 @@ _efl_gfx_shape_interpolate(Eo *obj, Efl_Gfx_Shape_Data *pd, if (!eo_isa(from, EFL_GFX_SHAPE_MIXIN) || !eo_isa(to, EFL_GFX_SHAPE_MIXIN)) return EINA_FALSE; if (pd == from_pd || pd == to_pd) return EINA_FALSE; - if (!_efl_gfx_shape_equal_commands_internal(from_pd, to_pd)) - return EINA_FALSE; + _efl_gfx_property_get(from, &property_from); _efl_gfx_property_get(to, &property_to); if (property_from.dash_length != property_to.dash_length) return EINA_FALSE; - cmds = realloc(pd->commands, - sizeof (Efl_Gfx_Path_Command) * from_pd->commands_count); - if (!cmds && from_pd->commands_count) return EINA_FALSE; - pd->commands = cmds; - - pts = realloc(pd->points, - sizeof (double) * from_pd->points_count); - if (!pts && from_pd->points_count) return EINA_FALSE; - pd->points = pts; - - if (cmds) + if (from_pd->path_data && to_pd->path_data) { - memcpy(cmds, from_pd->commands, - sizeof (Efl_Gfx_Path_Command) * from_pd->commands_count); - - if (pts) + _efl_gfx_shape_reset(obj, pd); + _path_interpolation(obj, pd, from_pd->path_data, to_pd->path_data, pos_map); + } + else + { + if (!_efl_gfx_shape_equal_commands_internal(from_pd, to_pd)) + return EINA_FALSE; + cmds = realloc(pd->commands, + sizeof (Efl_Gfx_Path_Command) * from_pd->commands_count); + if (!cmds && from_pd->commands_count) return EINA_FALSE; + pd->commands = cmds; + + pts = realloc(pd->points, + sizeof (double) * from_pd->points_count); + if (!pts && from_pd->points_count) return EINA_FALSE; + pd->points = pts; + + if (cmds) { - double *to_pts = to_pd->points; - double *from_pts = from_pd->points; - - for (i = 0; cmds[i] != EFL_GFX_PATH_COMMAND_TYPE_END; i++) - for (j = 0; j < _efl_gfx_path_command_length(cmds[i]); j++) - { - *pts = interpolate(*from_pts, *to_pts, pos_map); - - pts++; - from_pts++; - to_pts++; - } + memcpy(cmds, from_pd->commands, + sizeof (Efl_Gfx_Path_Command) * from_pd->commands_count); + + if (pts) + { + double *to_pts = to_pd->points; + double *from_pts = from_pd->points; + + for (i = 0; cmds[i] != EFL_GFX_PATH_COMMAND_TYPE_END; i++) + for (j = 0; j < _efl_gfx_path_command_length(cmds[i]); j++) + { + *pts = interpolate(*from_pts, *to_pts, pos_map); + + pts++; + from_pts++; + to_pts++; + } + } } - } - pd->points_count = from_pd->points_count; - pd->commands_count = from_pd->commands_count; - - pd->current.x = interpolate(from_pd->current.x, - to_pd->current.x, - pos_map); - pd->current.y = interpolate(from_pd->current.y, - to_pd->current.y, - pos_map); - pd->current_ctrl.x = interpolate(from_pd->current_ctrl.x, - to_pd->current_ctrl.x, + pd->points_count = from_pd->points_count; + pd->commands_count = from_pd->commands_count; + + pd->current.x = interpolate(from_pd->current.x, + to_pd->current.x, pos_map); - pd->current_ctrl.y = interpolate(from_pd->current_ctrl.y, - to_pd->current_ctrl.y, + pd->current.y = interpolate(from_pd->current.y, + to_pd->current.y, pos_map); + pd->current_ctrl.x = interpolate(from_pd->current_ctrl.x, + to_pd->current_ctrl.x, + pos_map); + pd->current_ctrl.y = interpolate(from_pd->current_ctrl.y, + to_pd->current_ctrl.y, + pos_map); + } if (property_to.dash_length) { @@ -447,6 +460,8 @@ _efl_gfx_shape_reset(Eo *obj, Efl_Gfx_Shape_Data *pd) free(pd->points); pd->points = NULL; pd->points_count = 0; + free(pd->path_data); + pd->path_data = NULL; pd->current.x = 0; pd->current.y = 0; @@ -1182,15 +1197,6 @@ _skipcomma(const char *content) } static inline Eina_Bool -_next_isnumber(const char *content) -{ - char *tmp = NULL; - - (void) strtod(content, &tmp); - return content != tmp; -} - -static inline Eina_Bool _parse_number(char **content, double *number) { char *end = NULL; @@ -1202,286 +1208,319 @@ _parse_number(char **content, double *number) return EINA_TRUE; } -static Eina_Bool -_efl_gfx_path_parse_pair(const char *content, char **end, double *x, double *y) +static inline Eina_Bool +_parse_long(char **content, int *number) { - char *str = (char *) content; - - if (_parse_number(&str, x)) - if (_parse_number(&str, y)) - { - *end = str; - return EINA_TRUE; - } - return EINA_FALSE; + char *end = NULL; + *number = strtol(*content, &end, 10) ? 1 : 0; + // if the start of string is not number + if ((*content) == end) return EINA_FALSE; + *content = _skipcomma(end); + return EINA_TRUE; } -static Eina_Bool -_efl_gfx_path_parse_pair_to(const char *content, char **end, - Eo *obj, Efl_Gfx_Shape_Data *pd, - double *current_x, double *current_y, - void (*func)(Eo *obj, Efl_Gfx_Shape_Data *pd, double x, double y), - Eina_Bool rel) -{ - double x, y; - *end = (char*) content; - do +static int +_number_count(char cmd) +{ + int count = 0; + switch (cmd) { - Eina_Bool r; - - r = _efl_gfx_path_parse_pair(content, end, &x, &y); - if (!r) return EINA_FALSE; - - if (rel) - { - x += *current_x; - y += *current_y; - } - func(obj, pd, x, y); - content = *end; - - *current_x = x; - *current_y = y; - } - while (_next_isnumber(content)); - - return EINA_TRUE; + case 'M': + case 'm': + case 'L': + case 'l': + { + count = 2; + break; + } + case 'C': + case 'c': + case 'E': + case 'e': + { + count = 6; + break; + } + case 'H': + case 'h': + case 'V': + case 'v': + { + count = 1; + break; + } + case 'S': + case 's': + case 'Q': + case 'q': + case 'T': + case 't': + { + count = 4; + break; + } + case 'A': + case 'a': + { + count = 7; + break; + } + default: + break; + } + return count; +} + +static void +process_command(Eo *obj, Efl_Gfx_Shape_Data *pd, char cmd, double *arr, int count, double *cur_x, double *cur_y) +{ + int i; + switch (cmd) + { + case 'm': + case 'l': + case 'c': + case 's': + case 'q': + case 't': + { + for(i=0; ipath_data) + free(pd->path_data); + pd->path_data = malloc(strlen(svg_path_data) + 1); + strcpy(pd->path_data, svg_path_data); } + // TIZEN_ONLY(20160420): efl/interface: update locale before parsing svg path error: setlocale(LC_NUMERIC, cur_locale); -- 2.7.4