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 <cedric.bail@free.fr> Differential Revision: https://phab.enlightenment.org/D9158
This commit is contained in:
parent
6d0f514126
commit
32cffb4494
|
@ -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.
|
||||
]]
|
||||
}
|
||||
|
|
|
@ -455,34 +455,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();
|
||||
|
||||
/* 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))
|
||||
if (font)
|
||||
{
|
||||
evas_font_desc_unref(fdesc);
|
||||
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();
|
||||
|
||||
/* 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_unref(o->cur.fdesc);
|
||||
o->cur.fdesc = fdesc;
|
||||
eina_stringshare_replace(&o->cur.font, font);
|
||||
o->prev.font = NULL;
|
||||
}
|
||||
|
||||
if (o->cur.fdesc) evas_font_desc_unref(o->cur.fdesc);
|
||||
o->cur.fdesc = fdesc;
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -15808,13 +15808,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))
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue