summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunsuChoi <jsuya.choi@samsung.com>2019-04-19 13:56:48 +0900
committerHermet Park <hermetpark@gmail.com>2019-04-19 13:56:49 +0900
commit5403af9629a9cc6805e26ade38ea95c2e0bbdb31 (patch)
tree4180118a397c949b6fc98f320f6643593a22e19e
parent3715faf96566c73f1c985ce4872845963032ee9f (diff)
vg_common_svg: Prevent duplicate operations for percentage value
Summary: x1, y1, x2 and y2 of Svg_Linear_Gradient structure must be a percentage value.(0 ~ 1) but these variables are reused with efl_gfx_gradient_linear_start/end_set/get and duplicate operations occur. Test Plan: N/A Reviewers: Hermet, smohanty Reviewed By: Hermet Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8662
-rw-r--r--src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c49
-rw-r--r--src/static_libs/vg_common/vg_common.h1
-rw-r--r--src/static_libs/vg_common/vg_common_svg.c13
3 files changed, 59 insertions, 4 deletions
diff --git a/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c b/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
index 950db2bea1..97a7215776 100644
--- a/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
+++ b/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
@@ -1519,6 +1519,7 @@ _clone_gradient(Svg_Style_Gradient *from)
1519 grad->id = _copy_id(from->id); 1519 grad->id = _copy_id(from->id);
1520 grad->ref = _copy_id(from->ref); 1520 grad->ref = _copy_id(from->ref);
1521 grad->spread = from->spread; 1521 grad->spread = from->spread;
1522 grad->use_percentage = from->use_percentage;
1522 grad->user_space = from->user_space; 1523 grad->user_space = from->user_space;
1523 grad->stops = _clone_grad_stops(from->stops); 1524 grad->stops = _clone_grad_stops(from->stops);
1524 if (grad->type == SVG_LINEAR_GRADIENT) 1525 if (grad->type == SVG_LINEAR_GRADIENT)
@@ -1874,15 +1875,53 @@ _handle_linear_y2_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, con
1874 linear->y2 = _gradient_to_double(loader->svg_parse, value, SVG_PARSER_LENGTH_VERTICAL); 1875 linear->y2 = _gradient_to_double(loader->svg_parse, value, SVG_PARSER_LENGTH_VERTICAL);
1875} 1876}
1876 1877
1878static void
1879_recalc_linear_x1_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, Eina_Bool user_space)
1880{
1881 if (!user_space)
1882 {
1883 linear->x1 = linear->x1 * loader->svg_parse->global.width;
1884 }
1885}
1886
1887static void
1888_recalc_linear_y1_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, Eina_Bool user_space)
1889{
1890 if (!user_space)
1891 {
1892 linear->y1 = linear->y1 * loader->svg_parse->global.height;
1893 }
1894}
1895
1896static void
1897_recalc_linear_x2_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, Eina_Bool user_space)
1898{
1899 if (!user_space)
1900 {
1901 linear->x2 = linear->x2 * loader->svg_parse->global.width;
1902 }
1903}
1904
1905static void
1906_recalc_linear_y2_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, Eina_Bool user_space)
1907{
1908 if (!user_space)
1909 {
1910 linear->y2 = linear->y2 * loader->svg_parse->global.height;
1911 }
1912}
1913
1877typedef void (*Linear_Method)(Evas_SVG_Loader *loader, Svg_Linear_Gradient *linear, const char *value); 1914typedef void (*Linear_Method)(Evas_SVG_Loader *loader, Svg_Linear_Gradient *linear, const char *value);
1915typedef void (*Linear_Method_Recalc)(Evas_SVG_Loader *loader, Svg_Linear_Gradient *linear, Eina_Bool user_space);
1878 1916
1879#define LINEAR_DEF(Name) \ 1917#define LINEAR_DEF(Name) \
1880 { #Name, sizeof (#Name), _handle_linear_##Name##_attr} 1918 { #Name, sizeof (#Name), _handle_linear_##Name##_attr, _recalc_linear_##Name##_attr}
1881 1919
1882static const struct { 1920static const struct {
1883 const char *tag; 1921 const char *tag;
1884 int sz; 1922 int sz;
1885 Linear_Method tag_handler;; 1923 Linear_Method tag_handler;
1924 Linear_Method_Recalc tag_recalc;
1886} linear_tags[] = { 1925} linear_tags[] = {
1887 LINEAR_DEF(x1), 1926 LINEAR_DEF(x1),
1888 LINEAR_DEF(y1), 1927 LINEAR_DEF(y1),
@@ -1931,6 +1970,7 @@ _create_linearGradient(Evas_SVG_Loader *loader, const char *buf, unsigned buflen
1931{ 1970{
1932 Svg_Style_Gradient *grad = calloc(1, sizeof(Svg_Style_Gradient)); 1971 Svg_Style_Gradient *grad = calloc(1, sizeof(Svg_Style_Gradient));
1933 loader->svg_parse->style_grad = grad; 1972 loader->svg_parse->style_grad = grad;
1973 unsigned int i;
1934 1974
1935 grad->type = SVG_LINEAR_GRADIENT; 1975 grad->type = SVG_LINEAR_GRADIENT;
1936 grad->user_space = EINA_FALSE; 1976 grad->user_space = EINA_FALSE;
@@ -1942,6 +1982,11 @@ _create_linearGradient(Evas_SVG_Loader *loader, const char *buf, unsigned buflen
1942 eina_simple_xml_attributes_parse(buf, buflen, 1982 eina_simple_xml_attributes_parse(buf, buflen,
1943 _attr_parse_linear_gradient_node, loader); 1983 _attr_parse_linear_gradient_node, loader);
1944 1984
1985 for (i = 0; i < sizeof (linear_tags) / sizeof(linear_tags[0]); i++)
1986 linear_tags[i].tag_recalc(loader, grad->linear, grad->user_space);
1987
1988 grad->use_percentage = EINA_TRUE;
1989
1945 return loader->svg_parse->style_grad; 1990 return loader->svg_parse->style_grad;
1946} 1991}
1947 1992
diff --git a/src/static_libs/vg_common/vg_common.h b/src/static_libs/vg_common/vg_common.h
index ab0cb0ded3..b1dfa7d7f9 100644
--- a/src/static_libs/vg_common/vg_common.h
+++ b/src/static_libs/vg_common/vg_common.h
@@ -206,6 +206,7 @@ struct _Svg_Style_Gradient
206 Eina_List *stops; // Efl_Gfx_Gradient_Stop 206 Eina_List *stops; // Efl_Gfx_Gradient_Stop
207 Svg_Radial_Gradient *radial; 207 Svg_Radial_Gradient *radial;
208 Svg_Linear_Gradient *linear; 208 Svg_Linear_Gradient *linear;
209 Eina_Bool use_percentage;
209}; 210};
210 211
211struct _Svg_Paint 212struct _Svg_Paint
diff --git a/src/static_libs/vg_common/vg_common_svg.c b/src/static_libs/vg_common/vg_common_svg.c
index 1c33e6454e..9f26453abc 100644
--- a/src/static_libs/vg_common/vg_common_svg.c
+++ b/src/static_libs/vg_common/vg_common_svg.c
@@ -568,8 +568,16 @@ _apply_gradient_property(Svg_Style_Gradient *g, Efl_VG *vg, Efl_VG *parent, Vg_F
568 if (g->type == SVG_LINEAR_GRADIENT) 568 if (g->type == SVG_LINEAR_GRADIENT)
569 { 569 {
570 grad_obj = efl_add(EFL_CANVAS_VG_GRADIENT_LINEAR_CLASS, parent); 570 grad_obj = efl_add(EFL_CANVAS_VG_GRADIENT_LINEAR_CLASS, parent);
571 efl_gfx_gradient_linear_start_set(grad_obj, g->linear->x1 * r.w + r.x, g->linear->y1 * r.h + r.y); 571
572 efl_gfx_gradient_linear_end_set(grad_obj, g->linear->x2 * r.w + r.x, g->linear->y2 * r.h + r.y); 572 if (g->use_percentage)
573 {
574 g->linear->x1 = g->linear->x1 * r.w + r.x;
575 g->linear->y1 = g->linear->y1 * r.h + r.y;
576 g->linear->x2 = g->linear->x2 * r.w + r.x;
577 g->linear->y2 = g->linear->y2 * r.h + r.y;
578 }
579 efl_gfx_gradient_linear_start_set(grad_obj, g->linear->x1, g->linear->y1);
580 efl_gfx_gradient_linear_end_set(grad_obj, g->linear->x2, g->linear->y2);
573 } 581 }
574 else if (g->type == SVG_RADIAL_GRADIENT) 582 else if (g->type == SVG_RADIAL_GRADIENT)
575 { 583 {
@@ -911,6 +919,7 @@ _create_gradient_node(Efl_VG *vg)
911 if (!grad->linear) goto oom_error; 919 if (!grad->linear) goto oom_error;
912 efl_gfx_gradient_linear_start_get(vg, &grad->linear->x1, &grad->linear->y1); 920 efl_gfx_gradient_linear_start_get(vg, &grad->linear->x1, &grad->linear->y1);
913 efl_gfx_gradient_linear_end_get(vg, &grad->linear->x2, &grad->linear->y2); 921 efl_gfx_gradient_linear_end_get(vg, &grad->linear->x2, &grad->linear->y2);
922 grad->use_percentage = EINA_FALSE;
914 } 923 }
915 else 924 else
916 { 925 {