diff --git a/ChangeLog b/ChangeLog index e3fba574fb..e6e743bc62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2013-04-04 Yakov Goldberg + + * Evas font: char position, returned by + evas_common_font_query_char_at_coords(), + depends on left/right half of char and its direction. + 2013-03-04 Cedric Bail * Evas: fix crash with Buffer engine with non alpha output. diff --git a/NEWS b/NEWS index d3605ccabf..5cab2bc092 100644 --- a/NEWS +++ b/NEWS @@ -220,3 +220,4 @@ Fixes: * Fix evas word start/end find in textblock to be consistent with other toolkit logic on the matter * Fix edje entry to respect filters and if input filtered out, don't clear selections * Fix evas buffer engine allocation with non alpha output + * Evas font: click on left/right half of char does matter now. diff --git a/src/lib/evas/common/evas_font_query.c b/src/lib/evas/common/evas_font_query.c index c87aabfba5..c2f68de922 100644 --- a/src/lib/evas/common/evas_font_query.c +++ b/src/lib/evas/common/evas_font_query.c @@ -721,6 +721,7 @@ evas_common_font_query_char_at_coords(RGBA_Font *fn, const Evas_Text_Props *text if (found) { int item_pos; + Evas_Coord cx_it, cw_it, cmid; Evas_Coord cluster_adv; cluster_adv = EVAS_FONT_WALK_PEN_X - cluster_start; @@ -736,12 +737,34 @@ evas_common_font_query_char_at_coords(RGBA_Font *fn, const Evas_Text_Props *text part = cluster_adv / items; item_pos = items - ((int) ((x - cluster_start) / part)) - 1; } - if (cx) *cx = EVAS_FONT_WALK_PEN_X + - ((cluster_adv / items) * (item_pos - 1)); + + cx_it = EVAS_FONT_WALK_PEN_X + ((cluster_adv / items) * (item_pos - 1)); + cw_it = (cluster_adv / items); + + if (cx) *cx = cx_it; if (cy) *cy = -asc; - if (cw) *cw = (cluster_adv / items); + if (cw) *cw = cw_it; if (ch) *ch = asc + desc; ret_val = prev_cluster + item_pos; + + /* Check, if x coord points to RIGHT half part of LTR char + * or to LEFT half char of RTL char. If so, increment found position */ + cmid = cx_it + (cw_it / 2); + if (text_props->bidi_dir == EVAS_BIDI_DIRECTION_LTR) + { + if (x > cmid) + { + ret_val++; + } + } + else + { + if (x < cmid) + { + ret_val++; + } + } + goto end; } end: diff --git a/src/tests/evas/evas_test_text.c b/src/tests/evas/evas_test_text.c index e0a9fad4fc..9db4fcfa0d 100644 --- a/src/tests/evas/evas_test_text.c +++ b/src/tests/evas/evas_test_text.c @@ -117,7 +117,10 @@ START_TEST(evas_text_geometries) fail_if(x <= px); px = x; /* Get back the coords */ - fail_if(i != evas_object_text_char_coords_get(to, x + (w / 2), + fail_if(i != evas_object_text_char_coords_get(to, x + (w / 4), + y + (h / 2), &x, &y, &w, &h)); + /* Get back cursor position, if click on right half of char. */ + fail_if((i + 1) != evas_object_text_char_coords_get(to, x + ((3 * w) / 4), y + (h / 2), &x, &y, &w, &h)); } @@ -427,7 +430,20 @@ START_TEST(evas_text_bidi) fail_if(x >= px); px = x; /* Get back the coords */ - fail_if(i != evas_object_text_char_coords_get(to, x + (w / 2), + fail_if(i != evas_object_text_char_coords_get(to, x + ((3 * w) / 4), + y + (h / 2), &x, &y, &w, &h)); + } + + /* Get back cursor position, if click on left half of char. */ + evas_object_text_text_set(to, "שלום..."); + x = 0; + px = 200; + for (i = 0 ; i < eina_unicode_utf8_get_len("שלום...") ; i++) + { + fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h)); + fail_if(x >= px); + px = x; + fail_if((i + 1) != evas_object_text_char_coords_get(to, x + (w / 4), y + (h / 2), &x, &y, &w, &h)); } @@ -449,7 +465,7 @@ START_TEST(evas_text_bidi) fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h)); fail_if(x <= px); px = x; - fail_if(i != evas_object_text_char_coords_get(to, x + (w / 2), + fail_if(i != evas_object_text_char_coords_get(to, x + ((3 * w) / 4), y + (h / 2), &x, &y, &w, &h)); i++; for ( ; i < eina_unicode_utf8_get_len("Test - נסיון") ; i++) @@ -486,7 +502,13 @@ START_TEST(evas_text_bidi) fail_if(x >= px); px = x; /* Get back the coords */ - fail_if(i != evas_object_text_char_coords_get(to, x + (w / 2), + if (w == 0) + { + int cx; + fail_if(!evas_object_text_char_pos_get(to, i - 1, &cx, NULL, NULL, NULL)); + w = cx - x; + } + fail_if(i != evas_object_text_char_coords_get(to, x + (3 * w /4), y + (h / 2), &x, &y, &w, &h)); }