From 11d50af138db162e16d0aee23ff4c80187a6158b Mon Sep 17 00:00:00 2001 From: qua-non Date: Sun, 9 Dec 2012 02:57:33 +0530 Subject: [PATCH] Core:text fix `shorten` routine (was assuming constant letter width) --- kivy/core/text/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kivy/core/text/__init__.py b/kivy/core/text/__init__.py index a97641374..9c205ed7e 100644 --- a/kivy/core/text/__init__.py +++ b/kivy/core/text/__init__.py @@ -204,9 +204,11 @@ class LabelBase(object): else: width = int(self.text_size[0]) - letters = text + '...' - letter_width = textwidth(letters) // len(letters) - max_letters = width // letter_width + letters = ' ... ' + text + while textwidth(letters) > width: + letters = letters[: letters.rfind(' ')] + + max_letters = len(letters) - 2 segment = (max_letters // 2) if segment - margin > 5: @@ -279,7 +281,9 @@ class LabelBase(object): # Shorten the text that we actually display text = self.text - if options['shorten'] and get_extents(text)[0] > uw: + last_word_width = get_extents(text[text.rstrip().rfind(' '):])[0] + if (options['shorten'] and get_extents(text)[0] > + uw - last_word_width): text = self.shorten(text) # first, split lines