From 3e102ddf615fe293838a9b1f222b670b8f199aec Mon Sep 17 00:00:00 2001 From: tasn Date: Tue, 2 Aug 2011 16:28:37 +0000 Subject: [PATCH] Evas textblock: Fixed range_text_get with TEXT_PLAIN. Until now, it only supported MARKUP, now it also supports plain. Haven't tested it much, but it seems to be working. It can help a lot to people who want to analyse the text, for example when implementing a spell checker, or "search", as now the text maps exactly like the cursors map. Still have to decide if that's the wanted API and set it in stone, or not promise this and expose a different API for these kind of tasks. git-svn-id: http://svn.enlightenment.org/svn/e/trunk/evas@62011 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/canvas/evas_object_textblock.c | 77 +++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/src/lib/canvas/evas_object_textblock.c b/src/lib/canvas/evas_object_textblock.c index 1764ec4..85ca34f 100644 --- a/src/lib/canvas/evas_object_textblock.c +++ b/src/lib/canvas/evas_object_textblock.c @@ -7287,8 +7287,8 @@ evas_textblock_cursor_content_get(const Evas_Textblock_Cursor *cur) return s; } -EAPI char * -evas_textblock_cursor_range_text_get(const Evas_Textblock_Cursor *cur1, const Evas_Textblock_Cursor *_cur2, Evas_Textblock_Text_Type format __UNUSED__) +static char * +_evas_textblock_cursor_range_text_markup_get(const Evas_Textblock_Cursor *cur1, const Evas_Textblock_Cursor *_cur2) { Evas_Object_Textblock *o; Evas_Object_Textblock_Node_Text *n1, *n2, *tnode; @@ -7409,6 +7409,79 @@ evas_textblock_cursor_range_text_get(const Evas_Textblock_Cursor *cur1, const Ev } } +static char * +_evas_textblock_cursor_range_text_plain_get(const Evas_Textblock_Cursor *cur1, const Evas_Textblock_Cursor *_cur2) +{ + Evas_Object_Textblock *o; + Eina_UStrbuf *buf; + Evas_Object_Textblock_Node_Text *n1, *n2; + Evas_Textblock_Cursor *cur2; + + buf = eina_ustrbuf_new(); + + if (!cur1 || !cur1->node) return NULL; + if (!_cur2 || !_cur2->node) return NULL; + if (cur1->obj != _cur2->obj) return NULL; + o = (Evas_Object_Textblock *)(cur1->obj->object_data); + if (evas_textblock_cursor_compare(cur1, _cur2) > 0) + { + const Evas_Textblock_Cursor *tc; + + tc = cur1; + cur1 = _cur2; + _cur2 = tc; + } + n1 = cur1->node; + n2 = _cur2->node; + /* Work on a local copy of the cur */ + cur2 = alloca(sizeof(Evas_Textblock_Cursor)); + cur2->obj = _cur2->obj; + evas_textblock_cursor_copy(_cur2, cur2); + + + if (n1 == n2) + { + const Eina_Unicode *tmp; + tmp = eina_ustrbuf_string_get(n1->unicode); + eina_ustrbuf_append_length(buf, tmp + cur1->pos, cur2->pos - cur1->pos); + } + else + { + const Eina_Unicode *tmp; + tmp = eina_ustrbuf_string_get(n1->unicode); + eina_ustrbuf_append(buf, tmp + cur1->pos); + n1 = _NODE_TEXT(EINA_INLIST_GET(n1)->next); + while (n1 != n2) + { + tmp = eina_ustrbuf_string_get(n1->unicode); + eina_ustrbuf_append_length(buf, tmp, + eina_ustrbuf_length_get(n1->unicode)); + n1 = _NODE_TEXT(EINA_INLIST_GET(n1)->next); + } + tmp = eina_ustrbuf_string_get(n2->unicode); + eina_ustrbuf_append_length(buf, tmp, cur2->pos); + } + + /* Free and return */ + { + char *ret; + ret = eina_unicode_unicode_to_utf8(eina_ustrbuf_string_get(buf), NULL); + eina_ustrbuf_free(buf); + return ret; + } +} + +EAPI char * +evas_textblock_cursor_range_text_get(const Evas_Textblock_Cursor *cur1, const Evas_Textblock_Cursor *cur2, Evas_Textblock_Text_Type format) +{ + if (format == EVAS_TEXTBLOCK_TEXT_MARKUP) + return _evas_textblock_cursor_range_text_markup_get(cur1, cur2); + else if (format == EVAS_TEXTBLOCK_TEXT_PLAIN) + return _evas_textblock_cursor_range_text_plain_get(cur1, cur2); + else + return NULL; /* Not yet supported */ +} + EAPI const char * evas_textblock_cursor_paragraph_text_get(const Evas_Textblock_Cursor *cur) { -- 2.7.4