diff options
author | Daniel Hirt <daniel.hirt@samsung.com> | 2016-05-23 15:19:38 +0300 |
---|---|---|
committer | Daniel Hirt <daniel.hirt@samsung.com> | 2016-05-23 15:19:38 +0300 |
commit | a2a24f342f74423837b300b11fae8a575ceff5a1 (patch) | |
tree | 15f9e19e657a7a127c19ade8f5a48d7b11add14d | |
parent | eecf8000ded23c60783785f339da41d9ac96349a (diff) | |
download | efl-devs/herdsman/tb2_next.tar.gz |
Canvas text: modify annotation's span in APIdevs/herdsman/tb2_next
Having the annotation spanning from given 'start' to ('end' - 1) is more
intuitive with how cursors are used.
Updated the API description and the test suite.
-rw-r--r-- | src/lib/evas/canvas/efl_canvas_text.eo | 3 | ||||
-rw-r--r-- | src/lib/evas/canvas/evas_object_textblock.c | 12 | ||||
-rw-r--r-- | src/tests/evas/evas_test_textblock.c | 46 |
3 files changed, 32 insertions, 29 deletions
diff --git a/src/lib/evas/canvas/efl_canvas_text.eo b/src/lib/evas/canvas/efl_canvas_text.eo index 629d5c53e2..036ea320cc 100644 --- a/src/lib/evas/canvas/efl_canvas_text.eo +++ b/src/lib/evas/canvas/efl_canvas_text.eo @@ -680,8 +680,7 @@ class Efl.Canvas.Text (Evas.Object, Efl.Text) ]] } annotation_insert { - [[Inserts an annotation format in a specified range [$start, $end] - in the text. + [[Inserts an annotation format in a specified range [$start, $end - 1]. This will add both opening and closing formats for the given $format. diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c index 956dc28942..56592cf2d6 100644 --- a/src/lib/evas/canvas/evas_object_textblock.c +++ b/src/lib/evas/canvas/evas_object_textblock.c @@ -13412,11 +13412,10 @@ _textblock_annotation_set(Eo *eo_obj, Evas_Textblock_Data *o, an->start_node = fnode; fnode->annotation = an; - /* Add closing format at end + 1 */ + /* Add a closing format at end (i.e. format does not apply at end) */ len = strlen(format); buf = malloc(len + 4); sprintf(buf, "</%s>", format); - efl_canvas_text_cursor_char_next(eo_obj, end); _evas_textblock_cursor_format_append(end, buf, &fnode); free(buf); an->end_node = fnode; @@ -13462,7 +13461,6 @@ _efl_canvas_text_annotation_set(Eo *eo_obj, /* XXX: Not efficient but works and saves code */ _textblock_cursor_pos_at_fnode_set(eo_obj, start, annotation->start_node); _textblock_cursor_pos_at_fnode_set(eo_obj, end, annotation->end_node); - efl_canvas_text_cursor_char_prev(eo_obj, end); _evas_textblock_node_format_remove(o, annotation->start_node, 0); _evas_textblock_node_format_remove(o, annotation->end_node, 0); @@ -13638,8 +13636,14 @@ _efl_canvas_text_object_item_insert(Eo *eo_obj EINA_UNUSED, Evas_Textblock_Data *o EINA_UNUSED, Efl_Canvas_Text_Cursor *cur, const char *format) { + Evas_Textblock_Annotation *ret; + Efl_Canvas_Text_Cursor *cur2 = efl_canvas_text_cursor_new(eo_obj); + efl_canvas_text_cursor_copy(eo_obj, cur2, cur); eina_ustrbuf_insert_char(cur->node->unicode, _REPLACEMENT_CHAR, cur->pos); - return _textblock_annotation_insert(eo_obj, o, cur, cur, format, EINA_TRUE); + efl_canvas_text_cursor_char_next(eo_obj, cur2); + ret = _textblock_annotation_insert(eo_obj, o, cur, cur2, format, EINA_TRUE); + efl_canvas_text_cursor_free(eo_obj, cur2); + return ret; } EOLIAN static void diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c index cc9da69b4c..6adb9fb077 100644 --- a/src/tests/evas/evas_test_textblock.c +++ b/src/tests/evas/evas_test_textblock.c @@ -4036,13 +4036,13 @@ START_TEST(evas_textblock_annotation) /* Check some trivial cases */ efl_canvas_text_cursor_pos_set(tb, start, 0); efl_canvas_text_cursor_pos_set(tb, end, 3); - efl_canvas_text_annotation_insert(tb, start, end, NULL); + ck_assert(!efl_canvas_text_annotation_insert(tb, start, end, NULL)); efl_canvas_text_cursor_pos_set(tb, start, 0); efl_canvas_text_cursor_pos_set(tb, end, 3); - efl_canvas_text_annotation_insert(tb, start, end, ""); + ck_assert(!efl_canvas_text_annotation_insert(tb, start, end, "")); efl_canvas_text_cursor_pos_set(tb, start, 1); efl_canvas_text_cursor_pos_set(tb, end, 0); - efl_canvas_text_annotation_insert(tb, start, end, "color=#fff"); + ck_assert(!efl_canvas_text_annotation_insert(tb, start, end, "color=#fff")); /* Insert and check correct positions */ _test_check_annotation(tb, 0, 10, _COMP_PARAMS()); @@ -4050,42 +4050,42 @@ START_TEST(evas_textblock_annotation) efl_canvas_text_cursor_pos_set(tb, start, 0); efl_canvas_text_cursor_pos_set(tb, end, 3); efl_canvas_text_annotation_insert(tb, start, end, "font_weight=bold"); - _test_check_annotation(tb, 0, 3, _COMP_PARAMS("font_weight=bold")); - _test_check_annotation(tb, 0, 3, _COMP_PARAMS("font_weight=bold")); + _test_check_annotation(tb, 0, 2, _COMP_PARAMS("font_weight=bold")); + _test_check_annotation(tb, 0, 2, _COMP_PARAMS("font_weight=bold")); _test_check_annotation(tb, 4, 10, _COMP_PARAMS()); efl_canvas_text_cursor_pos_set(tb, start, 50); efl_canvas_text_cursor_pos_set(tb, end, 60); efl_canvas_text_annotation_insert(tb, start, end, "color=#0ff"); _test_check_annotation(tb, 0, 49, _COMP_PARAMS("font_weight=bold")); - _test_check_annotation(tb, 0, 51, _COMP_PARAMS("font_weight=bold", "color=#0ff")); + _test_check_annotation(tb, 0, 50, _COMP_PARAMS("font_weight=bold", "color=#0ff")); + _test_check_annotation(tb, 0, 55, _COMP_PARAMS("font_weight=bold", "color=#0ff")); _test_check_annotation(tb, 0, 59, _COMP_PARAMS("font_weight=bold", "color=#0ff")); - _test_check_annotation(tb, 0, 60, _COMP_PARAMS("font_weight=bold", "color=#0ff")); _test_check_annotation(tb, 40, 50, _COMP_PARAMS("color=#0ff")); _test_check_annotation(tb, 40, 51, _COMP_PARAMS("color=#0ff")); _test_check_annotation(tb, 40, 61, _COMP_PARAMS("color=#0ff")); - _test_check_annotation(tb, 60, 61, _COMP_PARAMS("color=#0ff")); - _test_check_annotation(tb, 61, 62, _COMP_PARAMS()); + _test_check_annotation(tb, 59, 60, _COMP_PARAMS("color=#0ff")); + _test_check_annotation(tb, 60, 61, _COMP_PARAMS()); /* See that annotation's positions are updated as text is inserted */ evas_object_textblock_text_markup_set(tb, "hello"); efl_canvas_text_cursor_pos_set(tb, start, 0); efl_canvas_text_cursor_pos_set(tb, end, 2); an = efl_canvas_text_annotation_insert(tb, start, end, "color=#fff"); - _test_check_annotation(tb, 3, 3, _COMP_PARAMS()); + _test_check_annotation(tb, 2, 3, _COMP_PARAMS()); evas_textblock_cursor_pos_set(cur, 0); evas_textblock_cursor_text_append(cur, "a"); - _test_check_annotation(tb, 3, 3, _COMP_PARAMS("color=#fff")); - _test_check_annotation(tb, 4, 4, _COMP_PARAMS()); + _test_check_annotation(tb, 2, 3, _COMP_PARAMS("color=#fff")); + _test_check_annotation(tb, 3, 4, _COMP_PARAMS()); /* Replace annotations's format */ evas_object_textblock_annotation_set(tb, an, "font_size=14"); - _test_check_annotation(tb, 3, 3, _COMP_PARAMS("font_size=14")); - _test_check_annotation(tb, 4, 4, _COMP_PARAMS()); + _test_check_annotation(tb, 2, 3, _COMP_PARAMS("font_size=14")); + _test_check_annotation(tb, 3, 4, _COMP_PARAMS()); evas_object_textblock_text_markup_set(tb, "hello world"); efl_canvas_text_cursor_pos_set(tb, start, 0); - efl_canvas_text_cursor_pos_set(tb, end, 1); + efl_canvas_text_cursor_pos_set(tb, end, 2); an = efl_canvas_text_annotation_insert(tb, start, end, "color=#fff"); efl_canvas_text_cursor_pos_set(tb, start, 2); efl_canvas_text_cursor_pos_set(tb, end, 3); @@ -4102,10 +4102,10 @@ START_TEST(evas_textblock_annotation) /* Delete annotations directly */ evas_object_textblock_text_markup_set(tb, "hello world"); efl_canvas_text_cursor_pos_set(tb, start, 0); - efl_canvas_text_cursor_pos_set(tb, end, 1); + efl_canvas_text_cursor_pos_set(tb, end, 2); an = efl_canvas_text_annotation_insert(tb, start, end, "color=#fff"); - efl_canvas_text_cursor_pos_set(tb, start, 2); - efl_canvas_text_cursor_pos_set(tb, end, 3); + efl_canvas_text_cursor_pos_set(tb, start, 3); + efl_canvas_text_cursor_pos_set(tb, end, 4); an2 = efl_canvas_text_annotation_insert(tb, start, end, "font_size=14"); evas_object_textblock_annotation_del(tb, an); _test_check_annotation(tb, 0, 3, _COMP_PARAMS("font_size=14")); @@ -4114,10 +4114,10 @@ START_TEST(evas_textblock_annotation) efl_canvas_text_cursor_pos_set(tb, start, 0); efl_canvas_text_cursor_pos_set(tb, end, 1); an = efl_canvas_text_annotation_insert(tb, start, end, "color=#fff"); - _test_check_annotation(tb, 2, 3, _COMP_PARAMS()); - _test_check_annotation(tb, 1, 1, _COMP_PARAMS("color=#fff")); + _test_check_annotation(tb, 1, 3, _COMP_PARAMS()); + _test_check_annotation(tb, 0, 0, _COMP_PARAMS("color=#fff")); evas_object_textblock_annotation_del(tb, an); - _test_check_annotation(tb, 1, 1, _COMP_PARAMS()); + _test_check_annotation(tb, 0, 0, _COMP_PARAMS()); /* Check blocking of "item formats" */ evas_object_textblock_text_markup_set(tb, "hello world"); @@ -4163,7 +4163,7 @@ START_TEST(evas_textblock_annotation) /* Using annotations with new text API */ efl_text_set(tb, "hello"); efl_canvas_text_cursor_pos_set(tb, start, 0); - efl_canvas_text_cursor_pos_set(tb, end, 4); + efl_canvas_text_cursor_pos_set(tb, end, 5); efl_canvas_text_annotation_insert(tb, start, end, "color=#fff"); _test_check_annotation(tb, 3, 3, _COMP_PARAMS("color=#fff")); evas_textblock_cursor_pos_set(cur, 5); @@ -4179,7 +4179,7 @@ START_TEST(evas_textblock_annotation) /* Specific case with PS */ efl_text_set(tb, "hello\nworld"); efl_canvas_text_cursor_pos_set(tb, start, 0); - efl_canvas_text_cursor_pos_set(tb, end, 4); + efl_canvas_text_cursor_pos_set(tb, end, 5); efl_canvas_text_annotation_insert(tb, start, end, "color=#fff"); _test_check_annotation(tb, 4, 4, _COMP_PARAMS("color=#fff")); evas_textblock_cursor_pos_set(cur, 5); |