From ee3d7d8c2128672342a29ab9926c1263e39f6e95 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 2 Jul 2014 10:08:12 +0200 Subject: add support for long texts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/__main__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/__main__.py b/src/__main__.py index c545a66..e8120f4 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -154,7 +154,7 @@ class Bar: ''' return self.font.query_text_extents(text).overall_width - def draw_text(self, x, y, descent, text): ## TODO fix support for text longer than 255 symbols + def draw_text(self, x, y, descent, text): ''' Draw a text @@ -171,9 +171,15 @@ class Bar: for c in text + '\0': if c in special: if not buf == '': - draw_text(self.window, self.gc, x, y, buf) - x += self.font_width * len(buf) - buf = '' + if len(buf.encode('utf-8')) > 255: + while not buf == '': + sbuf, buf = buf[:42], buf[42:] + draw_text(self.window, self.gc, x, y, sbuf) + x += self.font_width * len(sbuf) + else: + draw_text(self.window, self.gc, x, y, buf) + x += self.font_width * len(buf) + buf = '' if not c == '\0': segs = [] if c in '─┼┬┴': segs.append((0, 1, 2, 1)) -- cgit v1.2.3-70-g09d2