Improved truncating
This commit is contained in:
parent
37c252dc65
commit
50960c7c05
1 changed files with 3 additions and 1 deletions
|
@ -4,6 +4,7 @@ from Assets import path, defaultfont
|
||||||
from TextWraper import wrap_text_with_font
|
from TextWraper import wrap_text_with_font
|
||||||
|
|
||||||
paddingcorrection = -3
|
paddingcorrection = -3
|
||||||
|
truncateerror_fontsize = 0.5
|
||||||
|
|
||||||
class TextDesign (DesignEntity):
|
class TextDesign (DesignEntity):
|
||||||
"""Object that manages all information relevant to text
|
"""Object that manages all information relevant to text
|
||||||
|
@ -41,8 +42,9 @@ class TextDesign (DesignEntity):
|
||||||
def __truncate_text__ (self):
|
def __truncate_text__ (self):
|
||||||
if self.__font__.getsize(self.text)[0] <= self.size[0]: #does not need truncating
|
if self.__font__.getsize(self.text)[0] <= self.size[0]: #does not need truncating
|
||||||
return
|
return
|
||||||
|
error = truncateerror_fontsize * self.__font__.getsize("A")[0]
|
||||||
suffix_length = self.__font__.getsize(self.truncate_suffix)[0]
|
suffix_length = self.__font__.getsize(self.truncate_suffix)[0]
|
||||||
while len(self.text) > 1 and self.__font__.getsize(self.text)[0] + suffix_length >= self.size[0]:
|
while len(self.text) > 1 and self.__font__.getsize(self.text)[0] + suffix_length >= self.size[0] - error:
|
||||||
self.text = self.text[0:-1]
|
self.text = self.text[0:-1]
|
||||||
self.text += self.truncate_suffix
|
self.text += self.truncate_suffix
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue