Improved truncating

This commit is contained in:
Maximilian Giller 2019-04-08 16:23:59 +02:00
parent 0b665f4976
commit f0d8507818

View file

@ -42,10 +42,10 @@ class TextDesign (DesignEntity):
def __truncate_text__ (self): def __truncate_text__ (self):
if self.__font__.getsize_multiline(self.text)[0] <= self.size[0]: #does not need truncating if self.__font__.getsize_multiline(self.text)[0] <= self.size[0]: #does not need truncating
return return
error = truncateerror_fontsize * self.__font__.getsize_multiline("A")[0]
suffix_length = self.__font__.getsize_multiline(self.truncate_suffix)[0] suffix_length = self.__font__.getsize_multiline(self.truncate_suffix)[0]
while len(self.text) > 1 and self.__font__.getsize_multiline(self.text)[0] + suffix_length >= self.size[0] - error: while len(self.text) > 1 and self.__font__.getsize_multiline(self.text)[0] + suffix_length >= self.size[0]:
self.text = self.text[0:-1] self.text = self.text[0:-1]
self.text = self.text.rstrip(' ')
self.text += self.truncate_suffix self.text += self.truncate_suffix
def __pos_from_alignment__ (self): def __pos_from_alignment__ (self):