summaryrefslogtreecommitdiff
path: root/src/static_libs
diff options
context:
space:
mode:
authorJunsuChoi <jsuya.choi@samsung.com>2020-10-14 19:16:53 +0900
committerHermet Park <chuneon.park@samsung.com>2020-10-14 19:16:53 +0900
commit3274390f7324b561739bdf2b620c939b6e0508fd (patch)
tree0ae5f3d12a09854c7dc00aa59459b2b5c132909c /src/static_libs
parent25e64a9a4e3adc259e81093a223c12996e424bf1 (diff)
vg_load_svg: Implement ClipPath feature
Summary: Supports case of using style attribute for defined <clipPath> and node. In SVG, <clipPath> can be used as a "clipPath" attribute or a style "clip-path". If there is a clip-path node, save it as a composition node and use composition method(matte_alpha) to compose it. Below node types support clip-path. <circle> <ellipse> <g> <path> <polygon> <polyline> <rect> Test Plan: Please see attached svg files {F4026162} Reviewers: Hermet, smohanty Reviewed By: Hermet Subscribers: #reviewers, #committers, cedric, herb, kimcinoo Tags: #efl Differential Revision: https://phab.enlightenment.org/D12179
Diffstat (limited to 'src/static_libs')
-rw-r--r--src/static_libs/vg_common/vg_common.h17
-rw-r--r--src/static_libs/vg_common/vg_common_svg.c41
2 files changed, 57 insertions, 1 deletions
diff --git a/src/static_libs/vg_common/vg_common.h b/src/static_libs/vg_common/vg_common.h
index 43e36df4d8..e9cbb4f475 100644
--- a/src/static_libs/vg_common/vg_common.h
+++ b/src/static_libs/vg_common/vg_common.h
@@ -25,12 +25,14 @@ typedef struct _Svg_Ellipse_Node Svg_Ellipse_Node;
25typedef struct _Svg_Polygon_Node Svg_Polygon_Node; 25typedef struct _Svg_Polygon_Node Svg_Polygon_Node;
26typedef struct _Svg_Rect_Node Svg_Rect_Node; 26typedef struct _Svg_Rect_Node Svg_Rect_Node;
27typedef struct _Svg_Path_Node Svg_Path_Node; 27typedef struct _Svg_Path_Node Svg_Path_Node;
28typedef struct _Svg_Composite Svg_Composite;
28typedef struct _Svg_Style_Property Svg_Style_Property; 29typedef struct _Svg_Style_Property Svg_Style_Property;
29typedef struct _Svg_Line_Node Svg_Line_Node; 30typedef struct _Svg_Line_Node Svg_Line_Node;
30typedef struct _Svg_Custom_Command_Node Svg_Custom_Command_Node; 31typedef struct _Svg_Custom_Command_Node Svg_Custom_Command_Node;
31 32
32typedef struct _Svg_Style_Stroke Svg_Style_Stroke; 33typedef struct _Svg_Style_Stroke Svg_Style_Stroke;
33typedef struct _Svg_Style_Fill Svg_Style_Fill; 34typedef struct _Svg_Style_Fill Svg_Style_Fill;
35typedef enum _Svg_Composite_Flags Svg_Composite_Flags;
34typedef enum _Svg_Fill_Flags Svg_Fill_Flags; 36typedef enum _Svg_Fill_Flags Svg_Fill_Flags;
35typedef enum _Svg_Stroke_Flags Svg_Stroke_Flags; 37typedef enum _Svg_Stroke_Flags Svg_Stroke_Flags;
36 38
@@ -62,6 +64,7 @@ enum _Svg_Node_Type
62 SVG_NODE_USE, 64 SVG_NODE_USE,
63 SVG_NODE_VIDEO, 65 SVG_NODE_VIDEO,
64 SVG_NODE_CUSTOME_COMMAND, 66 SVG_NODE_CUSTOME_COMMAND,
67 SVG_NODE_CLIP_PATH,
65 SVG_NODE_UNKNOWN 68 SVG_NODE_UNKNOWN
66}; 69};
67 70
@@ -224,6 +227,12 @@ struct _Svg_Paint
224 Eina_Stringshare *url; 227 Eina_Stringshare *url;
225}; 228};
226 229
230enum _Svg_Composite_Flags
231{
232 SVG_COMPOSITE_FLAGS_CLIP_PATH = 0x01,
233};
234
235
227enum _Svg_Fill_Flags 236enum _Svg_Fill_Flags
228{ 237{
229 SVG_FILL_FLAGS_PAINT = 0x1, 238 SVG_FILL_FLAGS_PAINT = 0x1,
@@ -266,10 +275,18 @@ struct _Svg_Style_Stroke
266 int dash_count; 275 int dash_count;
267}; 276};
268 277
278struct _Svg_Composite
279{
280 Svg_Composite_Flags flags;
281 const char *url;
282 Svg_Node* node;
283};
284
269struct _Svg_Style_Property 285struct _Svg_Style_Property
270{ 286{
271 Svg_Style_Fill fill; 287 Svg_Style_Fill fill;
272 Svg_Style_Stroke stroke; 288 Svg_Style_Stroke stroke;
289 Svg_Composite comp;
273 // the color property indirectly 290 // the color property indirectly
274 // used by fill and stroke 291 // used by fill and stroke
275 int r; 292 int r;
diff --git a/src/static_libs/vg_common/vg_common_svg.c b/src/static_libs/vg_common/vg_common_svg.c
index 38e203b205..30fc0c0eb5 100644
--- a/src/static_libs/vg_common/vg_common_svg.c
+++ b/src/static_libs/vg_common/vg_common_svg.c
@@ -763,7 +763,7 @@ _apply_vg_property(Svg_Node *node, Efl_VG *vg, Efl_VG *parent, Vg_File_Data *vg_
763 efl_gfx_color_set(vg, ((float) r) * fa, ((float) g) * fa, ((float) b) * fa, ((float) a) * fa); 763 efl_gfx_color_set(vg, ((float) r) * fa, ((float) g) * fa, ((float) b) * fa, ((float) a) * fa);
764 } 764 }
765 765
766 if (node->type == SVG_NODE_G) return; 766 if (node->type == SVG_NODE_G || node->type == SVG_NODE_CLIP_PATH) return;
767 767
768 // apply the fill style property 768 // apply the fill style property
769 efl_gfx_shape_fill_rule_set(vg, style->fill.fill_rule); 769 efl_gfx_shape_fill_rule_set(vg, style->fill.fill_rule);
@@ -829,12 +829,51 @@ _add_polyline(Efl_VG *vg, double *array, int size, Eina_Bool polygon)
829} 829}
830 830
831static Efl_VG * 831static Efl_VG *
832_create_vg_container(Efl_VG *parent)
833{
834 if (!parent)
835 return efl_add_ref(EFL_CANVAS_VG_CONTAINER_CLASS, NULL);
836 else
837 return efl_add(EFL_CANVAS_VG_CONTAINER_CLASS, parent);
838}
839
840static Efl_VG *
832vg_common_create_vg_node_helper(Svg_Node *node, Efl_VG *parent, Vg_File_Data *vg_data) 841vg_common_create_vg_node_helper(Svg_Node *node, Efl_VG *parent, Vg_File_Data *vg_data)
833{ 842{
834 Efl_VG *vg = NULL; 843 Efl_VG *vg = NULL;
835 Svg_Node *child; 844 Svg_Node *child;
836 Eina_List *l; 845 Eina_List *l;
837 846
847 // apply composite node
848 if (node->style->comp.node)
849 {
850 // composite ClipPath
851 if (node->style->comp.flags & SVG_COMPOSITE_FLAGS_CLIP_PATH)
852 {
853 Svg_Node *comp_node = node->style->comp.node;
854 Efl_VG *comp_parent = NULL ,*comp_vg_container = NULL;
855
856 //NOTE:: If node has a composition node, add a container to use VG_COMPOSITION_METHOD.
857 // The composition method is applied to the newly added container.
858 comp_parent = _create_vg_container(parent);
859 comp_vg_container = _create_vg_container(parent);
860
861 // apply the transformation
862 if (comp_node->transform) efl_canvas_vg_node_transformation_set(comp_vg_container, comp_node->transform);
863
864 EINA_LIST_FOREACH(comp_node->child, l, child)
865 {
866 Efl_VG *vg = vg_common_create_vg_node_helper(child, comp_vg_container, vg_data);
867 // clippath does not require color blending. That's why we keep 255 opacity.
868 efl_gfx_color_set(vg, 255, 255, 255, 255);
869 }
870
871 // Composition matte alpha
872 efl_canvas_vg_node_comp_method_set(comp_parent, comp_vg_container, EFL_GFX_VG_COMPOSITE_METHOD_MATTE_ALPHA);
873
874 parent = comp_parent; // replace parent
875 }
876 }
838 switch (node->type) 877 switch (node->type)
839 { 878 {
840 case SVG_NODE_DOC: 879 case SVG_NODE_DOC: