Edje: edc text_class applied without font or font_size in style

Summary:
The issue with `text_class` in Edc styles has to be within a string containing `font` & `font_size` properties to effect style, if font or font_size not presented in the same string text_class will be ignored.

So in the following Edc example, `text_class` will be ignored:
```
collections {
   text_classes {
      text_class {
         name: "tc1";
         font: "Sans";
         size: 20;
      }
   }
   styles {
      style {
         name: "style1";
         base: "color=#00FF00 text_class=tc1";
         tag: "br" "\n";
      }
   }
}
```

To apply text_class `tc1`, font and font_size has to be added to `styles.style.base` value, to be as follows:
```
...
base: "font=Serif font_size=15 color=#00FF00 text_class=tc1";
...
```

NOTE: The produced font will be `Sans` and font_size equal to `20`

Test Plan:
`layout.edc`
```
// compile: edje_cc layout.edc
// play: edje_player layout.edj
collections {
    text_classes {
       text_class {
          name: "tc1";
          font: "Sans";
          size: 20;
       }
    }
    styles {
        style {
            name: "style1";
            base: "color=#FFFFFF text_class=tc1";
        }
    }
    group {
        name : "group1";
        parts {
           part {
              name : "tb1";
              type: TEXTBLOCK;
              scale: 1;
              entry_mode: NONE;
              description {
                  state: "default" 0.0;
                  rel1.relative: 0.0 0.0;
                  rel2.relative: 0.5 0.5;
                  text {
                     style: "style1";
                     align: 0.0 0.0;
                     text: "Hello EFL";
                  }
              }
           }
        }
    }
}

Reviewers: segfaultxavi, smohanty, ali.alzyod, cedric, zmike

Reviewed By: zmike

Subscribers: zmike, segfaultxavi, cedric, #reviewers, #committers

Tags: #efl

Maniphest Tasks: T8477, T8478

Differential Revision: https://phab.enlightenment.org/D10692
This commit is contained in:
a.srour 2019-12-30 11:12:37 -05:00 committed by Mike Blumenkrantz
parent 97ffbe1f12
commit 0164162a48
3 changed files with 85 additions and 5 deletions

View File

@ -193,7 +193,7 @@ _edje_textblock_style_update(Edje *ed, Edje_Style *stl)
eina_strbuf_append(txt, fontsource);
}
}
if (tc && tc->size && !EINA_DBL_EQ(tag->font_size, 0))
if (tc && tc->size)
{
double new_size = _edje_text_size_calc(tag->font_size, tc);
if (!EINA_DBL_EQ(tag->font_size, new_size))
@ -206,7 +206,7 @@ _edje_textblock_style_update(Edje *ed, Edje_Style *stl)
}
}
/* Add font name last to save evas from multiple loads */
if (tc && tc->font && tag->font)
if (tc && tc->font)
{
const char *f;
char *sfont = NULL;

View File

@ -1,8 +1,21 @@
collections {
text_classes {
text_class {
name: "tc1";
font: "Serif";
size: 18;
}
}
styles {
style { name: "tb_style";
base: "font=Sans font_size=20 color=#fff";
}
style { name: "tb_tc_style";
base: "color=#ff0 text_class=tc1";
}
style { name: "tb_tc2_style";
base: "color=#0ff text_class=tc2";
}
}
group { name: "test_textblock";
parts {
@ -18,4 +31,32 @@ collections {
}
}
}
group { name: "test_tc_textblock";
parts {
part { name: "tb";
type: TEXTBLOCK;
description { state: "default" 0.0;
min: 300 300;
text {
text: "Hello World";
style: "tb_tc_style";
}
}
}
}
}
group { name: "test_tc_textblock2";
parts {
part { name: "tb2";
type: TEXTBLOCK;
description { state: "default" 0.0;
min: 300 300;
text {
text: "Hello World";
style: "tb_tc2_style";
}
}
}
}
}
}

View File

@ -102,13 +102,52 @@ EFL_START_TEST(edje_test_textblock)
evas = _setup_evas();
obj = edje_object_add(evas);
fail_unless(edje_object_file_set(obj, test_layout_get("test_textblock.edj"), "test_textblock"));
ck_assert(edje_object_file_set(obj, test_layout_get("test_textblock.edj"), "test_textblock"));
txt = edje_object_part_text_get(obj, "text");
fail_if(!txt || strcmp(txt, "Bye"));
ck_assert(txt || !strcmp(txt, "Bye"));
edje_object_part_text_set(obj, "text", buf);
txt = edje_object_part_text_get(obj, "text");
fail_if(!txt || strcmp(txt, buf));
ck_assert(txt || !strcmp(txt, buf));
Evas_Object *obj2 = edje_object_add(evas);
ck_assert(edje_object_file_set(obj2, test_layout_get("test_textblock.edj"), "test_tc_textblock"));
Evas_Object *tb = (Evas_Object*)edje_object_part_object_get(obj2, "tb");
ck_assert_ptr_ne(tb, NULL);
int w = 0, h = 0;
evas_object_textblock_size_formatted_get(tb, &w, &h);
Evas_Textblock_Style *st = evas_object_textblock_style_get(tb);
txt = evas_textblock_style_get(st);
ck_assert_str_eq(txt, "DEFAULT='color=#ff0 font_size=18.0 font=Serif'");
ck_assert_int_ne(w, 0);
ck_assert_int_ne(h, 0);
edje_object_text_class_set(obj2, "tc1", "Sans", 15);
edje_object_calc_force(obj2);
int w2 = 0, h2 = 0;
evas_object_textblock_size_formatted_get(tb, &w2, &h2);
ck_assert_int_ne(w2, 0);
ck_assert_int_ne(h2, 0);
ck_assert_int_ne(w, w2);
ck_assert_int_ne(h, h2);
ck_assert(edje_object_file_set(obj2, test_layout_get("test_textblock.edj"), "test_tc_textblock2"));
tb = (Evas_Object*)edje_object_part_object_get(obj2, "tb2");
ck_assert_ptr_ne(tb, NULL);
st = evas_object_textblock_style_get(tb);
txt = evas_textblock_style_get(st);
ck_assert_str_eq(txt, "DEFAULT='color=#0ff'");
evas_object_textblock_size_formatted_get(tb, &w, &h);
ck_assert_int_eq(w, 0);
ck_assert_int_eq(h, 0);
edje_object_text_class_set(obj2, "tc2", "Sans", 15);
edje_object_calc_force(obj2);
evas_object_textblock_size_formatted_get(tb, &w, &h);
ck_assert_int_ne(w, 0);
ck_assert_int_ne(h, 0);
st = evas_object_textblock_style_get(tb);
txt = evas_textblock_style_get(st);
ck_assert_str_eq(txt, "DEFAULT='color=#0ff font_size=15.0 font=Sans'");
}
EFL_END_TEST