From b2029f06481f81d151e5c78123df894121808235 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 10 Feb 2011 15:02:26 +0000 Subject: [PATCH] Evas text_utils: fixed a bug with splitting. Cutoff is the position in the string, not in the string object. SVN revision: 56920 --- .../src/lib/engines/common/evas_text_utils.c | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/legacy/evas/src/lib/engines/common/evas_text_utils.c b/legacy/evas/src/lib/engines/common/evas_text_utils.c index 78056ad736..954000d7f8 100644 --- a/legacy/evas/src/lib/engines/common/evas_text_utils.c +++ b/legacy/evas/src/lib/engines/common/evas_text_utils.c @@ -69,8 +69,53 @@ evas_common_text_props_content_unref(Evas_Text_Props *props) /* Won't work in the middle of ligatures, assumes cutoff < len */ EAPI void evas_common_text_props_split(Evas_Text_Props *base, - Evas_Text_Props *ext, int cutoff) + Evas_Text_Props *ext, int _cutoff) { + size_t cutoff; + + /* Translate text cutoff pos to string object cutoff point */ +#ifdef OT_SUPPORT + cutoff = 0; + + { + Evas_Font_OT_Info *itr; + size_t i; + itr = base->info->ot + base->start; + _cutoff += base->text_offset; + /* FIXME: can I binary search? I don't think this is always sorted */ + for (i = 0 ; i < base->len ; i++, itr++) + { + if (itr->source_cluster == (size_t) _cutoff) + { + if (base->bidi.dir == EVAS_BIDI_DIRECTION_RTL) + { + /* Walk to the last one of the same cluster */ + for ( ; i < base->len ; i++, itr++) + { + if (itr->source_cluster != (size_t) _cutoff) + break; + } + cutoff = base->len - i; + } + else + { + cutoff = i; + } + break; + } + } + } + + /* If we didn't find a reasonable cut location, return. */ + if (cutoff == 0) + { + ERR("Couldn't find the cutoff position."); + return; + } +#else + cutoff = (size_t) _cutoff; +#endif + evas_common_text_props_content_copy_and_ref(ext, base); if (base->bidi.dir == EVAS_BIDI_DIRECTION_RTL) {