Enlightenment CVS committal

Author  : barbieri
Project : e17
Module  : libs/edje

Dir     : e17/libs/edje/src/lib


Modified Files:
        edje_text.c 


Log Message:
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).

===================================================================
RCS file: /cvs/e/e17/libs/edje/src/lib/edje_text.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -3 -r1.67 -r1.68
--- edje_text.c 14 Oct 2007 23:54:27 -0000      1.67
+++ edje_text.c 22 Oct 2007 22:31:13 -0000      1.68
@@ -493,21 +493,48 @@
          }
        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;



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to