Evas filters: Add support for proxies in Edje
authorJean-Philippe Andre <jp.andre@samsung.com>
Wed, 5 Feb 2014 10:40:24 +0000 (19:40 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Fri, 7 Feb 2014 08:33:18 +0000 (17:33 +0900)
They will be defined with the following syntax:
buffer:buf(src=part);

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

index cf82202..f3b706b 100644 (file)
@@ -7314,6 +7314,13 @@ static void
 st_collections_group_parts_part_description_text_filter(void)
 {
    Edje_Part_Description_Text *ed;
+   Eina_List *sources = NULL;
+   Eina_Stringshare *name;
+   char *token, *code;
+   Eina_Bool valid = EINA_TRUE;
+
+   static const char *allowed_name_chars =
+         "abcdefghijklmnopqrstuvwxyzABCDEFGHJIKLMNOPQRSTUVWXYZ0123456789_";
 
    check_arg_count(1);
 
@@ -7325,8 +7332,62 @@ st_collections_group_parts_part_description_text_filter(void)
      }
 
    ed = (Edje_Part_Description_Text*) current_desc;
+   ed->text.filter_sources = NULL;
 
    ed->text.filter.str = parse_str(0);
+   if (!ed->text.filter.str) return;
+
+   // Parse list of buffers that have a source
+   // note: does not support comments
+   code = strdup(ed->text.filter.str);
+   for (token = strtok(code, ";"); token; token = strtok(NULL, ";"))
+     {
+        size_t len;
+
+        len = strspn(token, " \n\t");
+        token += len;
+
+        if (!strncasecmp("buffer", token, 6))
+          {
+             // note: a valid string won't necessary compile at runtime
+
+             token = strchr(token, ':');
+             if (!token)
+               {
+                  valid = EINA_FALSE;
+                  break;
+               }
+             token = strchr(token, '(');
+             if (!token)
+               {
+                  valid = EINA_FALSE;
+                  break;
+               }
+             token = strcasestr(token, "src");
+             if (!token) continue;
+             token += 3;
+             len = strspn(token, " =\n\t");
+             if (!len || !token[len])
+               {
+                  valid = EINA_FALSE;
+                  break;
+               }
+             token += len;
+             len = strspn(token, allowed_name_chars);
+             if (!len || !token[len])
+               {
+                  valid = EINA_FALSE;
+                  break;
+               }
+             token[len] = '\0';
+             name = eina_stringshare_add(token);
+
+             sources = eina_list_append(sources, name);
+          }
+     }
+   free(code);
+
+   if (valid) ed->text.filter_sources = sources;
 }
 
 
index d48f807..3a11cff 100644 (file)
@@ -806,6 +806,7 @@ _edje_edd_init(void)
    EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_text, Edje_Part_Description_Text, "text.id_text_source", text.id_text_source, EET_T_INT);
    EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_text, Edje_Part_Description_Text, "text.elipsis", text.elipsis, EET_T_DOUBLE);
    EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_text, Edje_Part_Description_Text, "text.filter", text.filter, EET_T_STRING);
+   EET_DATA_DESCRIPTOR_ADD_LIST_STRING(_edje_edd_edje_part_description_text, Edje_Part_Description_Text, "text.filter_sources", text.filter_sources);
 
    EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Edje_Part_Description_Text);
    eddc.func.mem_free = mem_free_textblock;
index c4b9df1..a057d8e 100644 (file)
@@ -1176,6 +1176,7 @@ struct _Edje_Part_Description_Spec_Text
    Edje_String    font; /* if a specific font is asked for */
    Edje_String    repch; /* replacement char for password mode entry */
    Edje_String    filter; /* special effects */
+   Eina_List     *filter_sources; /* proxy sources for special effects */
 
    Edje_Alignment align; /* text alignment within bounds */
    Edje_Color     color3;
@@ -1532,6 +1533,7 @@ struct _Edje_Real_Part_Text
    const char            *font; // 4
    const char            *style; // 4
    const char            *filter; // 4
+   Eina_List             *filter_sources; // 4
    Edje_Position          offset; // 8
    short                  size; // 2
    struct {
@@ -1544,7 +1546,7 @@ struct _Edje_Real_Part_Text
       const char         *out_str; // 4
       FLOAT_T             align_x, align_y; // 16
    } cache;
-}; // 76
+}; // 84
 // FIXME make text a potiner to struct and alloc at end
 // if part type is TEXT move common members textblock +
 // text to front and have smaller struct for textblock
index dd9f80b..2d3a38d 100644 (file)
@@ -169,7 +169,8 @@ _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep,
    char                *font2 = NULL;
    char         *sfont = NULL;
    int          size;
-   const char   *filter;
+   const char   *filter, *source_name;
+   Eina_List    *filter_sources = NULL, *prev_sources = NULL, *li;
    Evas_Coord   tw, th;
    Evas_Coord   sw, sh;
    int          inlined_font = 0, free_text = 0;
@@ -188,6 +189,12 @@ _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep,
    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) filter = ep->typedata.text->filter;
+   if (ep->typedata.text->filter_sources != chosen_desc->text.filter_sources)
+     {
+        prev_sources = ep->typedata.text->filter_sources;
+        filter_sources = chosen_desc->text.filter_sources;
+        ep->typedata.text->filter_sources = chosen_desc->text.filter_sources;
+     }
 
    if (ep->typedata.text->text_source)
      {
@@ -421,9 +428,19 @@ arrange_text:
    if (ep->part->scale) evas_object_scale_set(ep->object, TO_DOUBLE(sc));
    eo_do(ep->object,
          evas_obj_text_font_set(font, size),
-         evas_obj_text_filter_program_set(filter),
          evas_obj_text_text_set(text));
    part_get_geometry(ep, &tw, &th);
+
+   /* filters */
+   EINA_LIST_FOREACH(prev_sources, li, source_name)
+     eo_do(ep->object, evas_obj_text_filter_source_set(source_name, NULL));
+   EINA_LIST_FOREACH(filter_sources, li, source_name)
+     {
+        Edje_Real_Part *rp = _edje_real_part_get(ed, source_name);
+        eo_do(ep->object, evas_obj_text_filter_source_set(source_name, rp ? rp->object : NULL));
+     }
+   eo_do(ep->object, evas_obj_text_filter_program_set(filter));
+
    /* Handle alignment */
      {
         FLOAT_T align_x;