evas svg: fix missing node opacity attribute. 48/208648/1
authorHermet Park <hermetpark@gmail.com>
Thu, 27 Jun 2019 04:16:36 +0000 (13:16 +0900)
committerHermet Park <hermetpark@gmail.com>
Thu, 27 Jun 2019 04:19:51 +0000 (13:19 +0900)
Any svg node could have its opacity value, we missed implementing it.

If a node have a opacity, it's opacity could be multiply with fill and stroke colors.

@fix

Change-Id: Iac1caed073c5bf012fc7789e6d3e77e56c59550a

src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
src/static_libs/vg_common/vg_common.h
src/static_libs/vg_common/vg_common_svg.c

index 9c63d0b..7a616f4 100644 (file)
@@ -888,6 +888,12 @@ _handle_fill_rule_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node* node, cons
 }
 
 static void
+_handle_opacity_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node* node, const char *value)
+{
+   node->style->opacity = _to_opacity(value);
+}
+
+static void
 _handle_fill_opacity_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node* node, const char *value)
 {
    node->style->fill.flags |= SVG_FILL_FLAGS_OPACITY;
@@ -915,6 +921,7 @@ static const struct {
   STYLE_DEF(fill, fill),
   STYLE_DEF(fill-rule, fill_rule),
   STYLE_DEF(fill-opacity, fill_opacity),
+  STYLE_DEF(opacity, opacity),
   STYLE_DEF(stroke, stroke),
   STYLE_DEF(stroke-width, stroke_width),
   STYLE_DEF(stroke-linejoin, stroke_linejoin),
@@ -1001,6 +1008,7 @@ _create_node(Svg_Node *parent, Svg_Node_Type type)
    node->style->fill.paint.none = EINA_FALSE;
    // default fill opacity is 1
    node->style->fill.opacity = 255;
+   node->style->opacity = 255;
 
    // default fill rule is nonzero
    node->style->fill.fill_rule = EFL_GFX_FILL_RULE_WINDING;
index fc8d566..731a8d2 100644 (file)
@@ -272,6 +272,7 @@ struct _Svg_Style_Property
    int                r;
    int                g;
    int                b;
+   int                opacity;
 };
 
 struct _Svg_Node
index d14d9dd..e753e22 100644 (file)
@@ -183,6 +183,8 @@ _eet_for_style_property(void)
    EET_DATA_DESCRIPTOR_ADD_BASIC(eet, Svg_Style_Property, "r", r, EET_T_INT);
    EET_DATA_DESCRIPTOR_ADD_BASIC(eet, Svg_Style_Property, "g", g, EET_T_INT);
    EET_DATA_DESCRIPTOR_ADD_BASIC(eet, Svg_Style_Property, "b", b, EET_T_INT);
+   EET_DATA_DESCRIPTOR_ADD_BASIC(eet, Svg_Style_Property, "opacity", opacity, EET_T_INT);
+
    // for fill
    EET_DATA_DESCRIPTOR_ADD_BASIC(eet, Svg_Style_Property, "fill.flags", fill.flags, EET_T_INT);
    EET_DATA_DESCRIPTOR_ADD_BASIC(eet, Svg_Style_Property, "fill.paint.r", fill.paint.r, EET_T_INT);
@@ -731,6 +733,15 @@ _apply_vg_property(Svg_Node *node, Efl_VG *vg, Efl_VG *parent, Vg_File_Data *vg_
                           style->fill.paint.b, style->fill.opacity);
      }
 
+   //apply node opacity
+   if (style->opacity < 255)
+     {
+        int r, g, b, a;
+        efl_gfx_color_get(vg, &r, &g, &b, &a);
+        float fa = ((float) style->opacity / 255);
+        efl_gfx_color_set(vg, ((float) r) * fa, ((float) g) * fa, ((float) b) * fa, ((float) a) * fa);
+     }
+
    efl_gfx_shape_stroke_width_set(vg, style->stroke.width);
    efl_gfx_shape_stroke_cap_set(vg, style->stroke.cap);
    efl_gfx_shape_stroke_join_set(vg, style->stroke.join);
@@ -906,6 +917,7 @@ _create_node(Svg_Node *parent, Svg_Node_Type type)
    // default line join is miter
    node->style->stroke.join = EFL_GFX_JOIN_MITER;
    node->style->stroke.scale = 1.0;
+   node->style->opacity = 255;
 
    node->parent = parent;
    node->type = type;