void Label::alignText() const { Evas_Coord x( 0 ); Evas_Coord y( 0 ); Evas_Coord w( 0 ); Evas_Coord h( 0 ); if( 1 == evas_object_text_char_pos_get( label__ , text__.size() - 1 , &x , &y , &w , &h ) ) { unsigned int offset_y( 0 ); if( h > 0 && height__ > static_cast< unsigned int >( h ) ) offset_y = ( height__ - h ) / 2; unsigned int offset_x( 0 ); if( w > 0 && width__ > static_cast< unsigned int >( w ) ) offset_x = ( width__ - w - x ) / 2; evas_object_move( label__ , x__ + offset_x , y__ + offset_y ); } }
const Rect Text::getCharacterPosition(int pos) const { Evas_Coord cx, cy, cw, ch; if (!evas_object_text_char_pos_get (o, pos, &cx, &cy, &cw, &ch)) { throw FontCharacterPositionException (); } return Rect (cx, cy, cw, ch); }
/* Gets the geometry of the char according to its utf-8 pos */ static int _e_editable_char_geometry_get_from_pos(Evas_Object *editable, int utf_pos, Evas_Coord *cx, Evas_Coord *cy, Evas_Coord *cw, Evas_Coord *ch) { E_Editable_Smart_Data *sd; const Evas_Object *text_obj; const char *text; Evas_Coord x, w; int index = 0, i, last_pos, ret; if (cx) *cx = 0; if (cy) *cy = 0; if (cw) *cw = 0; if (ch) *ch = 0; if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return 0; if (!(text_obj = edje_object_part_object_get(sd->text_object, "e.text.text"))) return 0; text = evas_object_text_text_get(text_obj); if ((!text) || (sd->unicode_length <= 0) || (utf_pos <= 0)) { e_editable_char_size_get(editable, cw, ch); return 1; } else { if (utf_pos >= sd->unicode_length) { utf_pos = sd->unicode_length - 1; last_pos = 1; } else last_pos = 0; for (i = 0; i < utf_pos; i++) index = evas_string_char_next_get(text, index, NULL); ret = evas_object_text_char_pos_get(text_obj, index, &x, cy, &w, ch); if (cx) *cx = x - 1 + (last_pos ? w : 0); if (cw) *cw = last_pos ? 1 : w; return ret; } }
END_TEST /* Various text related geometries */ START_TEST(evas_text_geometries) { START_TEXT_TEST(); const char *buf = "Tests"; const char *font = TEST_FONT_NAME; Evas_Font_Size size = 14; Evas_Coord prev; int i; Evas_Coord x, y, w, h, px; evas_object_text_text_set(to, buf); /* All should be 0 without a font set */ fail_if(evas_object_text_ascent_get(to) != 0); fail_if(evas_object_text_descent_get(to) != 0); fail_if(evas_object_text_max_ascent_get(to) != 0); fail_if(evas_object_text_max_descent_get(to) != 0); fail_if(evas_object_text_horiz_advance_get(to) != 0); fail_if(evas_object_text_vert_advance_get(to) != 0); evas_object_text_font_set(to, font, size); /* Check that they are bigger than 0. */ fail_if(evas_object_text_ascent_get(to) <= 0); fail_if(evas_object_text_descent_get(to) <= 0); fail_if(evas_object_text_max_ascent_get(to) <= 0); fail_if(evas_object_text_max_descent_get(to) <= 0); fail_if(evas_object_text_horiz_advance_get(to) <= 0); fail_if(evas_object_text_vert_advance_get(to) <= 0); /* Check that expanding the text does what we expect it */ evas_object_text_text_set(to, "Test"); prev = evas_object_text_ascent_get(to); evas_object_text_text_set(to, "Testing"); fail_if(evas_object_text_ascent_get(to) != prev); evas_object_text_text_set(to, "Test"); prev = evas_object_text_descent_get(to); evas_object_text_text_set(to, "Testing"); fail_if(evas_object_text_descent_get(to) != prev); evas_object_text_text_set(to, "Test"); prev = evas_object_text_max_ascent_get(to); evas_object_text_text_set(to, "Testing"); fail_if(evas_object_text_max_ascent_get(to) != prev); evas_object_text_text_set(to, "Test"); prev = evas_object_text_max_descent_get(to); evas_object_text_text_set(to, "Testing"); fail_if(evas_object_text_max_descent_get(to) != prev); evas_object_text_text_set(to, "Test"); prev = evas_object_text_horiz_advance_get(to); evas_object_text_text_set(to, "Testing"); fail_if(evas_object_text_horiz_advance_get(to) <= prev); evas_object_text_text_set(to, "Test"); prev = evas_object_text_vert_advance_get(to); evas_object_text_text_set(to, "Testing"); fail_if(evas_object_text_vert_advance_get(to) != prev); /* Go through all the characters, making sure the geometries we get * are in a monotonically increasing order and that all sizes are * bigger than 0. */ evas_object_text_text_set(to, "Testing..."); x = 0; px = -100; for (i = 0 ; i < eina_unicode_utf8_get_len("Testing...") ; i++) { fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h)); fail_if(x <= px); px = x; /* Get back the coords */ 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)); } /* Last up to pos */ Evas_Coord adv; int pos, prev_pos; evas_object_text_text_set(to, "Test - 유니코드"); adv = evas_object_text_horiz_advance_get(to); pos = prev_pos = 0; for (x = 0 ; x <= (adv - 1) ; x++) { pos = evas_object_text_last_up_to_pos(to, x, 0); _ck_assert_int(pos, >=, prev_pos); prev_pos = pos; } pos = evas_object_text_last_up_to_pos(to, x, 0); ck_assert_int_eq(pos, -1); pos = evas_object_text_last_up_to_pos(to, -50, 0); ck_assert_int_eq(pos, -1); END_TEXT_TEST(); }
END_TEST #ifdef HAVE_FRIBIDI START_TEST(evas_text_bidi) { START_TEXT_TEST(); const char *buf = "Test - בדיקה"; int i; Evas_Coord x, y, w, h, px; const char *font = TEST_FONT_NAME; Evas_Font_Size size = 14; evas_object_text_font_set(to, font, size); evas_object_text_text_set(to, buf); fail_if(evas_object_text_direction_get(to) != EVAS_BIDI_DIRECTION_LTR); evas_object_text_text_set(to, "בדיקה"); fail_if(evas_object_text_direction_get(to) != EVAS_BIDI_DIRECTION_RTL); /* With RTL text coords should be monotontically decreasing. */ 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; /* Get back the coords */ 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)); } /* Bidi text is a bit more complex */ evas_object_text_text_set(to, "Test - נסיון..."); x = 0; px = -100; for (i = 0 ; i < eina_unicode_utf8_get_len("Test - ") ; i++) { fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h)); fail_if(x <= px); px = x; /* Get back the coords */ fail_if(i != evas_object_text_char_coords_get(to, x + (w / 4), y + (h / 2), &x, &y, &w, &h)); } /* First rtl char requires more specific handling */ 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 + ((3 * w) / 4), y + (h / 2), &x, &y, &w, &h)); i++; for ( ; i < eina_unicode_utf8_get_len("Test - נסיון") ; i++) { fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h)); fail_if(x >= px); px = x; /* Get back the coords */ fail_if(i != evas_object_text_char_coords_get(to, x + (w / 2), y + (h / 2), &x, &y, &w, &h)); } /* First ltr char requires more specific handling */ fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h)); fail_if(x <= px); px = x; i++; for ( ; i < eina_unicode_utf8_get_len("Test - נסיון...") ; i++) { fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h)); fail_if(x <= px); px = x; /* Get back the coords */ fail_if(i != evas_object_text_char_coords_get(to, x + (w / 2), y + (h / 2), &x, &y, &w, &h)); } /* And with an rtl text */ evas_object_text_text_set(to, "נסיון - test..."); x = 0; px = 100; 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; /* Get back the coords */ 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)); } /* First ltr char requires more specific handling */ 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), y + (h / 2), &x, &y, &w, &h)); i++; for ( ; i < eina_unicode_utf8_get_len("נסיון - test") ; i++) { fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h)); fail_if(x <= px); px = x; /* Get back the coords */ fail_if(i != evas_object_text_char_coords_get(to, x + (w / 2), y + (h / 2), &x, &y, &w, &h)); } /* First rtl char requires more specific handling */ fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h)); fail_if(x >= px); px = x; i++; for ( ; i < eina_unicode_utf8_get_len("נסיון - test...") ; i++) { fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h)); fail_if(x >= px); px = x; /* Get back the coords */ fail_if(i != evas_object_text_char_coords_get(to, x + (w / 2), y + (h / 2), &x, &y, &w, &h)); } /* And some last up to pos tests */ Evas_Coord adv; int pos, prev_pos; evas_object_text_text_set(to, "Test - נסיון..."); adv = evas_object_text_horiz_advance_get(to); pos = prev_pos = 0; for (x = 0 ; x <= (adv - 1) ; x++) { pos = evas_object_text_last_up_to_pos(to, x, 0); _ck_assert_int(pos, >=, prev_pos); prev_pos = pos; } pos = evas_object_text_last_up_to_pos(to, x, 0); fail_if(pos != -1); pos = evas_object_text_last_up_to_pos(to, -50, 0); fail_if(pos != -1); END_TEXT_TEST(); }
static void e_entry_configure(E_Entry *entry) { int p1l, p1r, p1t, p1b; int p2l, p2r, p2t, p2b; if (!entry->evas) return; if (!entry->event_box) return; p1l = p1r = p1t = p1b = 0; if (entry->obj_base) ebits_get_insets(entry->obj_base, &p1l, &p1r, &p1t, &p1b); p2l = p2r = p2t = p2b = 0; if (entry->obj_cursor) ebits_get_insets(entry->obj_cursor, &p2l, &p2r, &p2t, &p2b); if (entry->obj_base) { ebits_move(entry->obj_base, entry->x, entry->y); ebits_resize(entry->obj_base, entry->w, entry->h); } evas_object_move(entry->clip_box, entry->x + p1l, entry->y + p1t); evas_object_resize(entry->clip_box, entry->w - p1l - p1r, entry->h - p1t - p1b); evas_object_move(entry->event_box, entry->x + p1l + p2l, entry->y + p1t + p2t); evas_object_resize(entry->event_box, entry->w - p1l - p1r - p2l - p2r, entry->h - p1t - p1b - p2t - p2b); if ((entry->buffer) && (entry->buffer[0] != 0) && (entry->focused)) { double tx, ty, tw, th; /* kjb - debug */ /*printf("conf:curs: %d\n",entry->cursor_pos);*/ if (entry->cursor_pos < (int)strlen(entry->buffer)) { evas_object_text_char_pos_get(entry->text, entry->cursor_pos, &tx, &ty, &tw, &th); } else { entry->cursor_pos = strlen(entry->buffer); evas_object_text_char_pos_get(entry->text, entry->cursor_pos - 1, &tx, &ty,&tw, &th); tx += tw; tw = entry->end_width; } evas_object_geometry_get(entry->text, NULL, NULL, NULL, &th); if (tx + tw + entry->scroll_pos > entry->w - p1l - p1r) entry->scroll_pos = entry->w - tx - tw - p1l - p1r - p1l - p2l; else if (tx + entry->scroll_pos < p1l) entry->scroll_pos = 0 - tx; if (entry->obj_cursor) { ebits_move(entry->obj_cursor, entry->x + tx + entry->scroll_pos + p1l, entry->y /*+ ty*/ + p1t); ebits_resize(entry->obj_cursor, tw + p2l + p2r, th + p2t + p2b); ebits_show(entry->obj_cursor); } } else if (entry->focused) { int tx, tw; double th; entry->scroll_pos = 0; tw = 4; tx = 0; evas_object_geometry_get(entry->text, NULL, NULL, NULL, &th); if (entry->obj_cursor) { ebits_move(entry->obj_cursor, entry->x + tx + entry->scroll_pos + p1l, entry->y + p1t); ebits_resize(entry->obj_cursor, entry->end_width + p2l + p2r, th + p2t + p2b); ebits_show(entry->obj_cursor); } } else { if (entry->obj_cursor) ebits_hide(entry->obj_cursor); } evas_object_move(entry->text, entry->x + entry->scroll_pos + p1l + p2l, entry->y + p1t + p2t); if (entry->select.start >= 0) { double x1, y1, x2, tw, th; evas_object_text_char_pos_get(entry->text, entry->select.start, &x1, &y1, NULL, NULL); if (entry->select.start + entry->select.length <= (int)strlen(entry->buffer)) { evas_object_text_char_pos_get(entry->text, entry->select.start + entry->select.length - 1, &x2, NULL, &tw, &th); } else { evas_object_text_char_pos_get(entry->text, entry->select.start + entry->select.length - 2, &x2, NULL, &tw, &th); tw += entry->end_width; } evas_object_geometry_get(entry->text, NULL, NULL, NULL, &th); if (entry->obj_selection) { ebits_move(entry->obj_selection, entry->x + x1 + entry->scroll_pos + p1l, entry->y + y1 + p1t); ebits_resize(entry->obj_selection, x2 + tw - x1 + p2l + p2r, th + p2t + p2b); ebits_show(entry->obj_selection); } } else { if (entry->obj_selection) ebits_hide(entry->obj_selection); } }