From b542743d9ecb035efe5eaf0c4deb28c6930f1ee0 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Mon, 22 Oct 2007 22:31:13 +0000 Subject: [PATCH] Fix calculation of font size when text.fit_y is set. Before it was using a linear search with initial step proportional to difference bettwen desired and current height, but the way it was implemented it was giving incorrect values, for example: a text in an animation that enlarges height was getting size_{n} < size_{n-1}, where it should be always the oposite (the sequence was like: 31, 32, 33, 34, 31, 33, 34, 35, ...). One way to avoid that was to recalculate "dif" based on new "th", but it quickly drop to 1. The current implementation now uses a binary search to find the first size that matches the desired height and then a linear search to search the largest font doing that (differents sizes may result in the same height). This linear search is often an extra lookup and can be avoided if we want just something that fits (instead of the largest). SVN revision: 32146 --- legacy/edje/src/lib/edje_text.c | 49 +++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/legacy/edje/src/lib/edje_text.c b/legacy/edje/src/lib/edje_text.c index 87f75e8554..7e6bcbe28c 100644 --- a/legacy/edje/src/lib/edje_text.c +++ b/legacy/edje/src/lib/edje_text.c @@ -493,21 +493,48 @@ _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep, } else if (th > sh) { - int dif; + int current; - dif = (th - sh) / 4; - if (dif < 1) dif = 1; - while ((th > sh) && (sw >= 0)) + evas_object_text_font_set(ep->object, font, 10); + part_get_geometry(ep, &tw, &th); + + if (th == sh) + current = 10; + else { - size -= dif; - if (size <= 0) break; - if (inlined_font) evas_object_text_font_source_set(ep->object, ed->path); - else evas_object_text_font_source_set(ep->object, NULL); + int bottom, top; - evas_object_text_font_set(ep->object, font, size); - part_get_geometry(ep, &tw, &th); - if ((size > 0) && (th == 0)) break; + if (th < sh) + bottom = 10; + else if (th > sh) + { + bottom = 1; + top = 10; + } + + top = size; + /* search one that fits (binary search) */ + do + { + current = (top + bottom) / 2; + + evas_object_text_font_set(ep->object, font, current); + part_get_geometry(ep, &tw, &th); + + if (th < sh) bottom = current + 1; + else if (th > sh) top = current - 1; + } while ((bottom < top) && (th != sh)); } + + /* search the larger one that fits (linear search) */ + do + { + current++; + + evas_object_text_font_set(ep->object, font, current); + part_get_geometry(ep, &tw, &th); + } while (th <= sh); + size = current - 1; } } if (size < 1) size = 1;