vg_common_svg : Implement gradientTransform property of linearGradient

Summary:
Svg parser gets transformation matrix information from svg.
If there is a matrix, calculate matrix operations
on the start and end points of the gradient.

TODO: We should implement gradientTransform of radialGradient.

Test Plan: N/A

Reviewers: Hermet, smohanty

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D8663
This commit is contained in:
junsu choi 2019-04-19 15:07:11 +09:00 committed by Hermet Park
parent 5403af9629
commit 41152dc29e
3 changed files with 38 additions and 0 deletions

View File

@ -1521,6 +1521,11 @@ _clone_gradient(Svg_Style_Gradient *from)
grad->spread = from->spread;
grad->use_percentage = from->use_percentage;
grad->user_space = from->user_space;
if (from->transform)
{
grad->transform = calloc(1, sizeof(Eina_Matrix3));
eina_matrix3_copy(grad->transform, from->transform);
}
grad->stops = _clone_grad_stops(from->stops);
if (grad->type == SVG_LINEAR_GRADIENT)
{
@ -1961,6 +1966,10 @@ _attr_parse_linear_gradient_node(void *data, const char *key, const char *value)
{
grad->user_space = EINA_TRUE;
}
else if (!strcmp(key, "gradientTransform"))
{
grad->transform = _parse_transformation_matrix(value);
}
return EINA_TRUE;
}

View File

@ -206,6 +206,7 @@ struct _Svg_Style_Gradient
Eina_List *stops; // Efl_Gfx_Gradient_Stop
Svg_Radial_Gradient *radial;
Svg_Linear_Gradient *linear;
Eina_Matrix3 *transform;
Eina_Bool use_percentage;
};

View File

@ -481,6 +481,7 @@ _svg_style_gradient_free(Svg_Style_Gradient *grad)
eina_stringshare_del(grad->ref);
free(grad->radial);
free(grad->linear);
if (grad->transform) free(grad->transform);
EINA_LIST_FREE(grad->stops, stop)
{
@ -576,6 +577,33 @@ _apply_gradient_property(Svg_Style_Gradient *g, Efl_VG *vg, Efl_VG *parent, Vg_F
g->linear->x2 = g->linear->x2 * r.w + r.x;
g->linear->y2 = g->linear->y2 * r.h + r.y;
}
if (g->transform)
{
double cy = ((double) r.h) * 0.5 + r.y;
double cx = ((double) r.w) * 0.5 + r.x;
//Calc start point
eina_matrix3_identity(&m);
eina_matrix3_translate(&m, g->linear->x1 - cx, g->linear->y1 - cy);
eina_matrix3_multiply_copy(&m, g->transform , &m);
eina_matrix3_translate(&m, cx, cy);
eina_matrix3_values_get(&m, NULL, NULL, &g->linear->x1,
NULL, NULL, &g->linear->y1,
NULL, NULL, NULL);
//Calc end point
eina_matrix3_identity(&m);
eina_matrix3_translate(&m, g->linear->x2 - cx, g->linear->y2 - cy);
eina_matrix3_multiply_copy(&m, g->transform , &m);
eina_matrix3_translate(&m, cx, cy);
eina_matrix3_values_get(&m, NULL, NULL, &g->linear->x2,
NULL, NULL, &g->linear->y2,
NULL, NULL, NULL);
}
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);
}