evas/font: fix handling querying char at coords (click on gap)
authorYakov Goldberg <yakov.g@samsung.com>
Sun, 7 Apr 2013 13:08:06 +0000 (16:08 +0300)
committerSungho Kwak <sungho1.kwak@samsung.com>
Tue, 11 Jun 2013 12:15:34 +0000 (21:15 +0900)
   If query at x coord, which points to rigth half of LTR char,
   next posiition will be returned. The same for left half of RTL char.

   Merged from upstream:
   d55c3f2bb732b4d730127122c5a00cb8040f7cee
   fb7994e0d95dc61bcfd2670db60da6dc652a1fbc

Change-Id: I169a419e45904a9b366c16fe28dcd335a5341576

ChangeLog
NEWS
src/lib/engines/common/evas_font_query.c
src/tests/evas_test_text.c

index 9008fc3..8872d63 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 
         * Fix Evas_Object_Text when LTR and RTL are used in the same
         paragraph.
+
+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.
diff --git a/NEWS b/NEWS
index 1d550a2..a26b6f4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Fixes:
    * Fix evas textblock tag parser to respect escaped spaces and escaped single quotes
    * Fix the line drawing clipping problem on arm gl driver.
    * Evas: Fix Evas_Object_Text when LTR and RTL are used in the same paragraph.
+   * Evas font: click on left/right half of char does matter now.
 
 Evas 1.7.7
 
index 4c904d9..d866507 100644 (file)
@@ -681,6 +681,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;
 
@@ -696,12 +697,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:
index 99ab405..edf1bbe 100644 (file)
@@ -113,7 +113,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), NULL, NULL, NULL, NULL));
+        /* 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));
      }
 
@@ -362,7 +365,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));
      }
 
@@ -376,7 +392,7 @@ 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 + (w / 4),
                  y + (h / 2), &x, &y, &w, &h));
      }
 
@@ -384,7 +400,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++)
@@ -421,7 +437,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));
      }