Edje/evas filters: Use EDJ data sections to store filters code
authorJean-Philippe Andre <jp.andre@samsung.com>
Tue, 16 Jun 2015 12:05:06 +0000 (21:05 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Thu, 25 Jun 2015 05:36:09 +0000 (14:36 +0900)
Use the file data {item, file} block to embed filters code.
It can become especially useful to keep the filters as separated
Lua files, that will be embedded in the final edj file.

@feature

src/bin/edje/edje_cc_handlers.c
src/lib/edje/edje_load.c
src/lib/edje/edje_private.h
src/lib/edje/edje_text.c

index 53bf91e..403b210 100644 (file)
@@ -9007,12 +9007,15 @@ st_collections_group_parts_part_description_text_ellipsis(void)
     @property
         filter.code
     @parameters
-        [filter program as a string]
+        [filter program] OR [data name]
     @effect
         Applies a series of image filters to a TEXT or IMAGE part. The argument
         to this field is the source code of a Lua program invoking various
         filter operations. For more information, please refer to the page
         "Evas filters reference".
+        The parameter can also be a parameter name as specified in the
+        data section (item or file property). This means external filter files
+        can be easily embedded in an edje file.
         @see evasfiltersref
     @endproperty
 */
index 9708dd6..b4533e7 100644 (file)
@@ -1505,7 +1505,8 @@ _edje_file_del(Edje *ed)
                   eina_stringshare_del(rp->typedata.text->font);
                   eina_stringshare_del(rp->typedata.text->cache.in_str);
                   eina_stringshare_del(rp->typedata.text->cache.out_str);
-                  eina_stringshare_del(rp->typedata.text->filter.code);
+                  if (!rp->typedata.text->filter.no_free)
+                    eina_stringshare_del(rp->typedata.text->filter.code);
                   free(rp->typedata.text);
                }
              else if ((rp->type == EDJE_RP_TYPE_SWALLOW) &&
@@ -1929,7 +1930,8 @@ _edje_collection_free_part_description_clean(int type, Edje_Part_Description_Com
              eina_stringshare_del(text->text.text_class);
              eina_stringshare_del(text->text.style.str);
              eina_stringshare_del(text->text.font.str);
-             eina_stringshare_del(text->text.filter.code);
+             if (!text->text.filter.no_free)
+               eina_stringshare_del(text->text.filter.code);
           }
         break;
      }
index 8aec84a..7744f08 100644 (file)
@@ -1282,6 +1282,8 @@ struct _Edje_Part_Description_Spec_Filter
 {
    const char    *code;
    Eina_List     *sources; /* "part" or "buffer:part" */
+   Eina_Bool      checked_data : 1; // checked whether this is a data item or embedded string
+   Eina_Bool      no_free : 1;
 };
 
 struct _Edje_Part_Description_Spec_Image
index 8ee579e..5e2743b 100644 (file)
@@ -193,6 +193,24 @@ _edje_text_class_font_get(Edje *ed, Edje_Part_Description_Text *chosen_desc, int
    return font;
 }
 
+static inline const char *
+_edje_filter_get(Edje *ed, Edje_Part_Description_Spec_Filter *filter)
+{
+   if (EINA_UNLIKELY(!filter->checked_data))
+     {
+        Edje_String *st;
+        filter->checked_data = 1;
+        st = eina_hash_find(ed->file->data, filter->code);
+        if (st)
+          {
+             eina_stringshare_del(filter->code);
+             filter->code = st->str;
+             filter->no_free = 1;
+          }
+     }
+   return filter->code;
+}
+
 void
 _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep,
                         Edje_Calc_Params *params,
@@ -228,12 +246,15 @@ _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep,
    if (!text)
      text = edje_string_get(&chosen_desc->text.text);
    font = _edje_text_class_font_get(ed, chosen_desc, &size, &sfont);
-   filter = chosen_desc->text.filter.code;
 
    if (ep->typedata.text->text) text = ep->typedata.text->text;
    if (ep->typedata.text->font) font = ep->typedata.text->font;
    if (ep->typedata.text->size > 0) size = ep->typedata.text->size;
-   if (ep->typedata.text->filter.code) filter = ep->typedata.text->filter.code;
+
+   if (ep->typedata.text->filter.code)
+     filter = _edje_filter_get(ed, &ep->typedata.text->filter);
+   else
+     filter = _edje_filter_get(ed, &chosen_desc->text.filter);
    if (ep->typedata.text->filter.sources != chosen_desc->text.filter.sources)
      {
         prev_sources = ep->typedata.text->filter.sources;