summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Alzyod <ali198724@gmail.com>2020-04-17 12:28:41 +0900
committerWooHyun Jung <wh0705.jung@samsung.com>2020-04-17 12:28:42 +0900
commit9b987c67e1e38602ba2e4c9c990798e99d938bbe (patch)
treefc006f3a4496bdbe0b6971073e25f10341a4662e
parent208c1938bc0dec8c8cdd4b3b19c163ffb746c191 (diff)
evas_textblock: pick textrun fonts
Summary: Picking font on textrun, will now give priority into font picked by the user, regardless of script type. picking font due script can cause many inconvenient results Example of wrong results: (User font is **NotoColorEmoji**) {F3847118} -> add 'a' at the end (notice how text render is wrong) {F3847119} -> add tab before 'a' (text rendering now is right) {F3847120} After Change results: (User font is **NotoColorEmoji**) {F3847118} -> add 'a' at the end -> {F3847122}-> add tab before 'a' -> {F3847123} Also now the following lines will be shown exactly the same, regardless of characters order ``` "가123A321" "A321가123" "123가A321" "A가123321" ``` Test Plan: ``` #include <Elementary.h> /* gcc -o example test.c `pkg-config --cflags --libs elementary` */ EAPI_MAIN int elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) { Evas_Object *win, *en; elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); win = elm_win_util_standard_add("", ""); elm_win_autodel_set(win, EINA_TRUE); en = elm_entry_add(win); elm_entry_scrollable_set(en, EINA_TRUE); evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_entry_text_style_user_push(en,"DEFAULT='font=NotoColorEmoji font_size=30 color=red'"); elm_object_text_set(en, "&#x262a;123456a"); evas_object_show(en); elm_object_content_set(win, en); evas_object_resize(win, 400, 200); evas_object_show(win); elm_run(); return 0; } ELM_MAIN() ``` Reviewers: woohyun, bowonryu, tasn, raster, cedric Reviewed By: tasn Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T8556 Differential Revision: https://phab.enlightenment.org/D11302
-rw-r--r--src/lib/evas/common/evas_font_query.c35
-rw-r--r--src/tests/evas/evas_test_textblock.c22
2 files changed, 24 insertions, 33 deletions
diff --git a/src/lib/evas/common/evas_font_query.c b/src/lib/evas/common/evas_font_query.c
index 640fc65b4c..1464d7f9db 100644
--- a/src/lib/evas/common/evas_font_query.c
+++ b/src/lib/evas/common/evas_font_query.c
@@ -17,7 +17,7 @@
17 * @return length of the run found. 17 * @return length of the run found.
18 */ 18 */
19EAPI int 19EAPI int
20evas_common_font_query_run_font_end_get(RGBA_Font *fn, RGBA_Font_Int **script_fi, RGBA_Font_Int **cur_fi, Evas_Script_Type script, const Eina_Unicode *text, int run_len) 20evas_common_font_query_run_font_end_get(RGBA_Font *fn, RGBA_Font_Int **script_fi, RGBA_Font_Int **cur_fi, Evas_Script_Type script EINA_UNUSED, const Eina_Unicode *text, int run_len)
21{ 21{
22 RGBA_Font_Int *fi = NULL; 22 RGBA_Font_Int *fi = NULL;
23 const Eina_Unicode *run_end = text + run_len; 23 const Eina_Unicode *run_end = text + run_len;
@@ -26,38 +26,7 @@ evas_common_font_query_run_font_end_get(RGBA_Font *fn, RGBA_Font_Int **script_fi
26 /* If there's no current script_fi, find it first */ 26 /* If there's no current script_fi, find it first */
27 if (!*script_fi) 27 if (!*script_fi)
28 { 28 {
29 const Eina_Unicode *base_char = NULL; 29 fi = fn->fonts->data;
30 /* Skip common chars */
31 for (base_char = text ;
32 (base_char < run_end) &&
33 (evas_common_language_char_script_get(*base_char) != script) ;
34 base_char++)
35 ;
36 /* If counter reach variation sequence it is safe to pick default font */
37 if(VAR_SEQ_SAFE(base_char) || (base_char != run_end && VAR_SEQ_SAFE((base_char+1)))) goto get_top_font;
38
39 if (base_char == run_end) base_char = text;
40
41 /* Find the first renderable char */
42 while (base_char < run_end)
43 {
44 /* 0x1F is the last ASCII contral char, just a hack in
45 * the meanwhile. */
46 if ((*base_char > 0x1F) &&
47 evas_common_font_glyph_search(fn, &fi, *base_char, 0, EVAS_FONT_SEARCH_OPTION_NONE))
48 break;
49 base_char++;
50 }
51
52
53 /* If everything else fails, at least try to find a font for the
54 * replacement char */
55 if (base_char == run_end)
56 evas_common_font_glyph_search(fn, &fi, REPLACEMENT_CHAR, 0, EVAS_FONT_SEARCH_OPTION_NONE);
57get_top_font:
58
59 if (!fi)
60 fi = fn->fonts->data;
61 30
62 *script_fi = fi; 31 *script_fi = fi;
63 } 32 }
diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c
index dab090ff00..d3c575039d 100644
--- a/src/tests/evas/evas_test_textblock.c
+++ b/src/tests/evas/evas_test_textblock.c
@@ -4168,6 +4168,27 @@ EFL_START_TEST(evas_textblock_fit)
4168} 4168}
4169EFL_END_TEST; 4169EFL_END_TEST;
4170 4170
4171EFL_START_TEST(evas_textblock_textrun_font)
4172{
4173 START_TB_TEST();
4174 int w1, h1, w2, h2;
4175
4176 evas_object_resize(tb, 300, 300);
4177 evas_object_textblock_text_markup_set(tb, "가123A321");
4178 evas_object_textblock_size_native_get(tb, &w1, &h1);
4179 evas_object_textblock_text_markup_set(tb, "A321가123");
4180 evas_object_textblock_size_native_get(tb, &w2, &h2);
4181 ck_assert(w1==w2 && h1==h2);
4182 evas_object_textblock_text_markup_set(tb, "123가A321");
4183 evas_object_textblock_size_native_get(tb, &w2, &h2);
4184 ck_assert(w1==w2 && h1==h2);
4185 evas_object_textblock_text_markup_set(tb, "A가123321");
4186 evas_object_textblock_size_native_get(tb, &w2, &h2);
4187 ck_assert(w1==w2 && h1==h2);
4188 END_TB_TEST();
4189}
4190EFL_END_TEST;
4191
4171#ifdef HAVE_HYPHEN 4192#ifdef HAVE_HYPHEN
4172static void 4193static void
4173_hyphenation_width_stress(Evas_Object *tb, Evas_Textblock_Cursor *cur) 4194_hyphenation_width_stress(Evas_Object *tb, Evas_Textblock_Cursor *cur)
@@ -5038,6 +5059,7 @@ void evas_test_textblock(TCase *tc)
5038 tcase_add_test(tc, evas_textblock_delete); 5059 tcase_add_test(tc, evas_textblock_delete);
5039 tcase_add_test(tc, evas_textblock_obstacle); 5060 tcase_add_test(tc, evas_textblock_obstacle);
5040 tcase_add_test(tc, evas_textblock_fit); 5061 tcase_add_test(tc, evas_textblock_fit);
5062 tcase_add_test(tc, evas_textblock_textrun_font);
5041#ifdef HAVE_HYPHEN 5063#ifdef HAVE_HYPHEN
5042 tcase_add_test(tc, evas_textblock_hyphenation); 5064 tcase_add_test(tc, evas_textblock_hyphenation);
5043#endif 5065#endif