From 11a97b9035651caaabda46430b3098f4356a179e Mon Sep 17 00:00:00 2001 From: Aiwota Programmer Date: Sat, 9 May 2009 03:40:02 +0900 Subject: [PATCH] The character widths list is needed because retrieving the widths from the dict is slow. --- src/FukuiNoNamari/ThreadViewBase/element.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/FukuiNoNamari/ThreadViewBase/element.py b/src/FukuiNoNamari/ThreadViewBase/element.py index 61d60d2..bda9475 100644 --- a/src/FukuiNoNamari/ThreadViewBase/element.py +++ b/src/FukuiNoNamari/ThreadViewBase/element.py @@ -115,7 +115,7 @@ class ElementText: return dict[ch] def recalc_char_widths(self): - pass + self.widths = map(self._get_ch_width, self.text) def _get_ch_width_dict(self): return ElementText.ch_width_dict @@ -137,8 +137,7 @@ class ElementText: if y >= top and y < bottom: sum_of_widths = line.rectangle.x index = line.start_index - subtext = self.text[line.start_index:line.end_index] - for width in itertools.imap(self._get_ch_width, subtext): + for width in self.widths[line.start_index:line.end_index]: if sum_of_widths + width/2 > x: break sum_of_widths += width @@ -155,8 +154,7 @@ class ElementText: ch_h = get_approximate_char_height(self.pango_layout.get_context()) - iterable = itertools.imap(self._get_ch_width, self.text) - for index, ch_w in enumerate(iterable): + for index, ch_w in enumerate(self.widths): if current_line_x + current_line_width + ch_w > width: line = Line( current_line_start_index, index, -- 2.11.0