forked from enlightenment/efl
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
This commit is contained in:
parent
3715faf965
commit
5403af9629
|
@ -1519,6 +1519,7 @@ _clone_gradient(Svg_Style_Gradient *from)
|
|||
grad->id = _copy_id(from->id);
|
||||
grad->ref = _copy_id(from->ref);
|
||||
grad->spread = from->spread;
|
||||
grad->use_percentage = from->use_percentage;
|
||||
grad->user_space = from->user_space;
|
||||
grad->stops = _clone_grad_stops(from->stops);
|
||||
if (grad->type == SVG_LINEAR_GRADIENT)
|
||||
|
@ -1874,15 +1875,53 @@ _handle_linear_y2_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, con
|
|||
linear->y2 = _gradient_to_double(loader->svg_parse, value, SVG_PARSER_LENGTH_VERTICAL);
|
||||
}
|
||||
|
||||
static void
|
||||
_recalc_linear_x1_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, Eina_Bool user_space)
|
||||
{
|
||||
if (!user_space)
|
||||
{
|
||||
linear->x1 = linear->x1 * loader->svg_parse->global.width;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_recalc_linear_y1_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, Eina_Bool user_space)
|
||||
{
|
||||
if (!user_space)
|
||||
{
|
||||
linear->y1 = linear->y1 * loader->svg_parse->global.height;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_recalc_linear_x2_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, Eina_Bool user_space)
|
||||
{
|
||||
if (!user_space)
|
||||
{
|
||||
linear->x2 = linear->x2 * loader->svg_parse->global.width;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_recalc_linear_y2_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, Eina_Bool user_space)
|
||||
{
|
||||
if (!user_space)
|
||||
{
|
||||
linear->y2 = linear->y2 * loader->svg_parse->global.height;
|
||||
}
|
||||
}
|
||||
|
||||
typedef void (*Linear_Method)(Evas_SVG_Loader *loader, Svg_Linear_Gradient *linear, const char *value);
|
||||
typedef void (*Linear_Method_Recalc)(Evas_SVG_Loader *loader, Svg_Linear_Gradient *linear, Eina_Bool user_space);
|
||||
|
||||
#define LINEAR_DEF(Name) \
|
||||
{ #Name, sizeof (#Name), _handle_linear_##Name##_attr}
|
||||
{ #Name, sizeof (#Name), _handle_linear_##Name##_attr, _recalc_linear_##Name##_attr}
|
||||
|
||||
static const struct {
|
||||
const char *tag;
|
||||
int sz;
|
||||
Linear_Method tag_handler;;
|
||||
Linear_Method tag_handler;
|
||||
Linear_Method_Recalc tag_recalc;
|
||||
} linear_tags[] = {
|
||||
LINEAR_DEF(x1),
|
||||
LINEAR_DEF(y1),
|
||||
|
@ -1931,6 +1970,7 @@ _create_linearGradient(Evas_SVG_Loader *loader, const char *buf, unsigned buflen
|
|||
{
|
||||
Svg_Style_Gradient *grad = calloc(1, sizeof(Svg_Style_Gradient));
|
||||
loader->svg_parse->style_grad = grad;
|
||||
unsigned int i;
|
||||
|
||||
grad->type = SVG_LINEAR_GRADIENT;
|
||||
grad->user_space = EINA_FALSE;
|
||||
|
@ -1942,6 +1982,11 @@ _create_linearGradient(Evas_SVG_Loader *loader, const char *buf, unsigned buflen
|
|||
eina_simple_xml_attributes_parse(buf, buflen,
|
||||
_attr_parse_linear_gradient_node, loader);
|
||||
|
||||
for (i = 0; i < sizeof (linear_tags) / sizeof(linear_tags[0]); i++)
|
||||
linear_tags[i].tag_recalc(loader, grad->linear, grad->user_space);
|
||||
|
||||
grad->use_percentage = EINA_TRUE;
|
||||
|
||||
return loader->svg_parse->style_grad;
|
||||
}
|
||||
|
||||
|
|
|
@ -206,6 +206,7 @@ struct _Svg_Style_Gradient
|
|||
Eina_List *stops; // Efl_Gfx_Gradient_Stop
|
||||
Svg_Radial_Gradient *radial;
|
||||
Svg_Linear_Gradient *linear;
|
||||
Eina_Bool use_percentage;
|
||||
};
|
||||
|
||||
struct _Svg_Paint
|
||||
|
|
|
@ -568,8 +568,16 @@ _apply_gradient_property(Svg_Style_Gradient *g, Efl_VG *vg, Efl_VG *parent, Vg_F
|
|||
if (g->type == SVG_LINEAR_GRADIENT)
|
||||
{
|
||||
grad_obj = efl_add(EFL_CANVAS_VG_GRADIENT_LINEAR_CLASS, parent);
|
||||
efl_gfx_gradient_linear_start_set(grad_obj, g->linear->x1 * r.w + r.x, g->linear->y1 * r.h + r.y);
|
||||
efl_gfx_gradient_linear_end_set(grad_obj, g->linear->x2 * r.w + r.x, g->linear->y2 * r.h + r.y);
|
||||
|
||||
if (g->use_percentage)
|
||||
{
|
||||
g->linear->x1 = g->linear->x1 * r.w + r.x;
|
||||
g->linear->y1 = g->linear->y1 * r.h + r.y;
|
||||
g->linear->x2 = g->linear->x2 * r.w + r.x;
|
||||
g->linear->y2 = g->linear->y2 * r.h + r.y;
|
||||
}
|
||||
efl_gfx_gradient_linear_start_set(grad_obj, g->linear->x1, g->linear->y1);
|
||||
efl_gfx_gradient_linear_end_set(grad_obj, g->linear->x2, g->linear->y2);
|
||||
}
|
||||
else if (g->type == SVG_RADIAL_GRADIENT)
|
||||
{
|
||||
|
@ -911,6 +919,7 @@ _create_gradient_node(Efl_VG *vg)
|
|||
if (!grad->linear) goto oom_error;
|
||||
efl_gfx_gradient_linear_start_get(vg, &grad->linear->x1, &grad->linear->y1);
|
||||
efl_gfx_gradient_linear_end_get(vg, &grad->linear->x2, &grad->linear->y2);
|
||||
grad->use_percentage = EINA_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue