OSDN Git Service

The character widths list is needed because retrieving the widths from the dict is...
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 8 May 2009 18:40:02 +0000 (03:40 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 8 May 2009 18:40:02 +0000 (03:40 +0900)
src/FukuiNoNamari/ThreadViewBase/element.py

index 61d60d2..bda9475 100644 (file)
@@ -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,