summaryrefslogtreecommitdiff
path: root/src/static_libs/vg_common
diff options
context:
space:
mode:
authorVitalii Vorobiov <vi.vorobiov@samsung.com>2017-03-16 14:53:49 +0200
committerJean-Philippe Andre <jp.andre@samsung.com>2017-11-07 11:54:09 +0900
commitd98e2323ad93e66b13841d60cbfdd17cdf8fdff2 (patch)
tree14d5b3c30cf2c09a532b3968572ae87eb9d6631a /src/static_libs/vg_common
parent6bf5d9d96ef07dcd12f5c9e7ceaa1dbcca046206 (diff)
vg_common: property apply "objectBoundingBox" morphings to radial gradient
When objectBoundingBox flag is set up, all gradients should morphed into multiple gradients for every entity that has gradient to be applied on
Diffstat (limited to 'src/static_libs/vg_common')
-rw-r--r--src/static_libs/vg_common/vg_common.c63
1 files changed, 56 insertions, 7 deletions
diff --git a/src/static_libs/vg_common/vg_common.c b/src/static_libs/vg_common/vg_common.c
index 7b33053ed0..21b9201b70 100644
--- a/src/static_libs/vg_common/vg_common.c
+++ b/src/static_libs/vg_common/vg_common.c
@@ -553,7 +553,10 @@ _apply_gradient_property(Svg_Style_Gradient *g, Efl_VG *vg, Vg_File_Data *vg_dat
553 Efl_Gfx_Gradient_Stop *stops, *stop; 553 Efl_Gfx_Gradient_Stop *stops, *stop;
554 int stop_count = 0, i = 0; 554 int stop_count = 0, i = 0;
555 Eina_List *l; 555 Eina_List *l;
556 Eina_Rect r = { 0, 0, 1, 1 }; 556 Eina_Matrix3 m; //for bbox translation
557 Eina_Rect r = EINA_RECT( 0, 0, 1, 1 );
558 Eina_Rect grad_geom = EINA_RECT(0, 0, 0, 0);
559 int radius;
557 560
558 //TODO: apply actual sizes (imporve bounds_get function?)... 561 //TODO: apply actual sizes (imporve bounds_get function?)...
559 //for example with figures and paths 562 //for example with figures and paths
@@ -573,16 +576,62 @@ _apply_gradient_property(Svg_Style_Gradient *g, Efl_VG *vg, Vg_File_Data *vg_dat
573 } 576 }
574 else if (g->type == SVG_RADIAL_GRADIENT) 577 else if (g->type == SVG_RADIAL_GRADIENT)
575 { 578 {
576 /** 579 radius = sqrt(pow(r.w, 2) + pow(r.h, 2)) / sqrt(2.0);
577 * That is according to Units in here 580 if (!g->user_space)
578 * 581 {
579 * https://www.w3.org/TR/2015/WD-SVG2-20150915/coords.html 582 /**
580 */ 583 * That is according to Units in here
581 int radius = sqrt(pow(r.h, 2) + pow(r.w, 2)) / sqrt(2.0); 584 *
585 * https://www.w3.org/TR/2015/WD-SVG2-20150915/coords.html
586 */
587 int min = (r.h > r.w) ? r.w : r.h;
588 radius = sqrt(pow(min, 2) + pow(min, 2)) / sqrt(2.0);
589 }
582 grad_obj = evas_vg_gradient_radial_add(NULL); 590 grad_obj = evas_vg_gradient_radial_add(NULL);
583 evas_vg_gradient_radial_center_set(grad_obj, g->radial->cx * r.w + r.x, g->radial->cy * r.h + r.y); 591 evas_vg_gradient_radial_center_set(grad_obj, g->radial->cx * r.w + r.x, g->radial->cy * r.h + r.y);
584 evas_vg_gradient_radial_radius_set(grad_obj, g->radial->r * radius); 592 evas_vg_gradient_radial_radius_set(grad_obj, g->radial->r * radius);
585 evas_vg_gradient_radial_focal_set(grad_obj, g->radial->fx * r.w + r.x, g->radial->fy * r.h + r.y); 593 evas_vg_gradient_radial_focal_set(grad_obj, g->radial->fx * r.w + r.x, g->radial->fy * r.h + r.y);
594
595 /* in case of objectBoundingBox it need proper scaling */
596 if (!g->user_space)
597 {
598 double scale_X = 1.0, scale_reversed_X = 1.0;
599 double scale_Y = 1.0, scale_reversed_Y = 1.0;
600
601 /* check the smallest size, find the scale value */
602 if (r.h > r.w)
603 {
604 scale_Y = ((double) r.w) / r.h;
605 scale_reversed_Y = ((double) r.h) / r.w;
606 }
607 else
608 {
609 scale_X = ((double) r.h) / r.w;
610 scale_reversed_X = ((double) r.w) / r.h;
611 }
612
613 evas_vg_node_bounds_get(grad_obj, &grad_geom);
614
615 double cy = grad_geom.h / 2 + grad_geom.y;
616 double cy_scaled = (grad_geom.h / 2) * scale_reversed_Y;
617 double cx = grad_geom.w / 2 + grad_geom.x;
618 double cx_scaled = (grad_geom.w / 2) * scale_reversed_X;
619
620 /* matrix tranformation of gradient figure:
621 * 0. we remember size of gradient and it's center point
622 * 1. move all gradients to point {0;0}
623 * (so scale wont increase starting point)
624 * 2. scale properly only according to the bigger size of entity
625 * 3. move back so new center point would stay on position
626 * it had previously
627 */
628 eina_matrix3_identity(&m);
629 eina_matrix3_translate(&m, grad_geom.x, grad_geom.y);
630 eina_matrix3_scale(&m, scale_X, scale_Y);
631 eina_matrix3_translate(&m, cx_scaled - cx, cy_scaled - cy);
632
633 efl_vg_transformation_set(grad_obj, &m);
634 }
586 } 635 }
587 else 636 else
588 { 637 {