Added text truncating to tables and fixed size bug
This commit is contained in:
parent
e1e25e3d2a
commit
37c252dc65
2 changed files with 5 additions and 3 deletions
|
@ -4,7 +4,7 @@ from TextWraper import wrap_text_with_font
|
|||
class TableTextDesign (TextDesign):
|
||||
"""Gets a matrix with text that is than
|
||||
displayed in a table without borders."""
|
||||
def __init__ (self, size, text_matrix, max_col_size = None, max_row_size = None, font = None, fontsize = 12, column_horizontal_alignments = [], mask = True, line_spacing = 0, col_spacing = 0, truncate_rows = True, truncate_cols = True, wrap = False):
|
||||
def __init__ (self, size, text_matrix, max_col_size = None, max_row_size = None, font = None, fontsize = 12, column_horizontal_alignments = [], mask = True, line_spacing = 0, col_spacing = 0, truncate_rows = True, truncate_cols = True, wrap = False, truncate_text=True, truncate_suffix="..."):
|
||||
super(TableTextDesign, self).__init__(size, font=font, fontsize=fontsize, mask=mask)
|
||||
self.matrix = text_matrix
|
||||
self.max_col_size = max_col_size
|
||||
|
@ -17,6 +17,8 @@ class TableTextDesign (TextDesign):
|
|||
self.max_col = None
|
||||
self.column_horizontal_alignments = column_horizontal_alignments
|
||||
self.wrap = wrap
|
||||
self.truncate_text = truncate_text
|
||||
self.truncate_suffix = truncate_suffix
|
||||
|
||||
def __finish_image__ (self):
|
||||
if len(self.matrix) is 0:
|
||||
|
@ -93,7 +95,7 @@ class TableTextDesign (TextDesign):
|
|||
self.__draw_text__(pos, size, r, c)
|
||||
|
||||
def __draw_text__ (self, pos, size, row, col):
|
||||
design = TextDesign(size, text=self.matrix[row][col], font=self.font_family, fontsize=self.font_size, horizontalalignment=self.__get_col_hori_alignment__(col), wrap=self.wrap)
|
||||
design = TextDesign(size, text=self.matrix[row][col], font=self.font_family, fontsize=self.font_size, horizontalalignment=self.__get_col_hori_alignment__(col), wrap=self.wrap, truncate=self.truncate_text, truncate_suffix=self.truncate_suffix)
|
||||
design.pos = pos
|
||||
self.draw_design(design)
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ class TextDesign (DesignEntity):
|
|||
ImageDraw.Draw(self.__image__).text(pos, self.text, fill=self.color, font=self.__font__)
|
||||
|
||||
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
|
||||
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]:
|
||||
|
|
Loading…
Reference in a new issue