From f6cd36c6587a8408ca740feb7f7c2297483deae0 Mon Sep 17 00:00:00 2001 From: ali Date: Mon, 29 Jul 2019 20:18:37 +0000 Subject: [PATCH] evas_textblock: change font-size/font-family only using EFL.Text.Font Interface Currently: User cannot change font size only, he needs to set both font and font size with (**efl_text_font_font_set**) To change size only, you need to make two calls, one to get font (**efl_text_font_font_get**) , then pass it again with new size to (**efl_text_font_font_set**). New Behaviour: If user want to change size only, then he passes NULL as font argument to keep same font. If user want to change font only, then he passes 0 as font-size argument, to keep same font-size. Notes: This is not best solution, but it better than current behaviour. I think best solution to have separate function to set font size, but It might break current api or duplicate functions. Reviewed-by: Cedric BAIL Differential Revision: https://phab.enlightenment.org/D9158 --- src/lib/efl/interfaces/efl_text_font.eo | 3 +++ src/lib/evas/canvas/evas_object_text.c | 42 ++++++++++++++++------------- src/lib/evas/canvas/evas_object_textblock.c | 4 +-- src/tests/evas/evas_test_textblock.c | 30 +++++++++++++++++++++ 4 files changed, 58 insertions(+), 21 deletions(-) diff --git a/src/lib/efl/interfaces/efl_text_font.eo b/src/lib/efl/interfaces/efl_text_font.eo index 27d32d6..31ded3e 100644 --- a/src/lib/efl/interfaces/efl_text_font.eo +++ b/src/lib/efl/interfaces/efl_text_font.eo @@ -63,6 +63,9 @@ interface @beta Efl.Text_Font { to get an idea). Alternatively, youe can use the full path to a font file. + To skip changing font family pass null as font family. + To skip changing font size pass 0 as font size. + See also @.font.get, @.font_source.get. ]] } diff --git a/src/lib/evas/canvas/evas_object_text.c b/src/lib/evas/canvas/evas_object_text.c index f9ee58a..0f18f8f 100644 --- a/src/lib/evas/canvas/evas_object_text.c +++ b/src/lib/evas/canvas/evas_object_text.c @@ -476,34 +476,38 @@ _evas_text_efl_text_font_font_set(Eo *eo_obj, Evas_Text_Data *o, const char *fon Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS); Evas_Font_Description *fdesc; - if ((!font) || (size <= 0)) return; + if (!font && size <= 0) return; evas_object_async_block(obj); if ((size == o->cur.size) && (o->cur.font && !strcmp(font, o->cur.font))) return; - /* We can't assume the given font is same with current fdesc by comparing string. - Since Evas starts to supporting "auto" for language, - the given font string should be parsed once before comparing it. */ - fdesc = evas_font_desc_new(); + if (font) + { + /* We can't assume the given font is same with current fdesc by comparing string. + Since Evas starts to supporting "auto" for language, + the given font string should be parsed once before comparing it. */ + fdesc = evas_font_desc_new(); - /* Set default language according to locale. */ - eina_stringshare_replace(&(fdesc->lang), evas_font_lang_normalize("auto")); - evas_font_name_parse(fdesc, font); + /* Set default language according to locale. */ + eina_stringshare_replace(&(fdesc->lang), evas_font_lang_normalize("auto")); + evas_font_name_parse(fdesc, font); - if (o->cur.fdesc && !evas_font_desc_cmp(fdesc, o->cur.fdesc) && - (size == o->cur.size)) - { - evas_font_desc_unref(fdesc); - return; - } + if (o->cur.fdesc && !evas_font_desc_cmp(fdesc, o->cur.fdesc) && + (size == o->cur.size)) + { + evas_font_desc_unref(fdesc); + return; + } - if (o->cur.fdesc) evas_font_desc_unref(o->cur.fdesc); - o->cur.fdesc = fdesc; + if (o->cur.fdesc) evas_font_desc_unref(o->cur.fdesc); + o->cur.fdesc = fdesc; + eina_stringshare_replace(&o->cur.font, font); + o->prev.font = NULL; + } - o->cur.size = size; - eina_stringshare_replace(&o->cur.font, font); - o->prev.font = NULL; + if ( size > 0 ) + o->cur.size = size; _evas_text_font_reload(eo_obj, o); } diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c index ebca342..f1b03b7 100644 --- a/src/lib/evas/canvas/evas_object_textblock.c +++ b/src/lib/evas/canvas/evas_object_textblock.c @@ -16541,13 +16541,13 @@ _efl_canvas_text_efl_text_font_font_set(Eo *obj EINA_UNUSED, Efl_Canvas_Text_Dat Eina_Stringshare *nfont; - if (o->default_format.info.size != size) + if (size > 0 && o->default_format.info.size != size) { o->default_format.info.size = size; changed = EINA_TRUE; } - if (o->default_format.info.font != font) + if (font && o->default_format.info.font != font) { nfont = eina_stringshare_add(font); if (nfont == _FMT_INFO(font)) diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c index dc3f22d..ef81ae3 100644 --- a/src/tests/evas/evas_test_textblock.c +++ b/src/tests/evas/evas_test_textblock.c @@ -4654,6 +4654,35 @@ EFL_START_TEST(efl_canvas_text_markup) } EFL_END_TEST +EFL_START_TEST(efl_text_font) +{ + START_EFL_CANVAS_TEXT_TEST(); + + efl_text_set(txt, "\n\n\n"); + + const char * font; + int font_size; + efl_text_font_set(txt, "Sans", 20); + efl_text_font_set(txt, NULL, 0); + + efl_text_font_get(txt, &font, &font_size); + fail_if(20 != font_size); + fail_if(strcmp(font,"Sans")); + + efl_text_font_set(txt, NULL, 30); + efl_text_font_get(txt, &font, &font_size); + fail_if(30 != font_size); + fail_if(strcmp(font,"Sans")); + + efl_text_font_set(txt, "arial", 0); + efl_text_font_get(txt, &font, &font_size); + fail_if(30 != font_size); + fail_if(strcmp(font,"arial")); + + END_EFL_CANVAS_TEXT_TEST(); +} +EFL_END_TEST + void evas_test_textblock(TCase *tc) { tcase_add_test(tc, evas_textblock_simple); @@ -4686,5 +4715,6 @@ void evas_test_textblock(TCase *tc) tcase_add_test(tc, efl_text); tcase_add_test(tc, efl_canvas_text_cursor); tcase_add_test(tc, efl_canvas_text_markup); + tcase_add_test(tc, efl_text_font); } -- 2.7.4