class ElementText:
+ ch_width_dict = {} # key: char, value: width
+
def __init__(self, text, pango_layout):
self.text = text
self.pango_layout = pango_layout
- attrlist = self._get_attrs()
- self.widths = thread_view_extend.get_char_width(
- pango_layout.get_context(), text, attrlist)
+ self.recalc_char_widths()
self.line_list = []
def recalc_char_widths(self):
- attrlist = self._get_attrs()
- self.widths = thread_view_extend.get_char_width(
- self.pango_layout.get_context(), self.text, attrlist)
+ self.widths = [i for i in itertools.repeat(0, len(self.text))]
+
+ dict = self._get_ch_width_dict()
+ need_to_get = False
+ for index, ch in enumerate(self.text):
+ if ch not in dict:
+ need_to_get = True
+ break
+ else:
+ width = dict[ch]
+ self.widths[index] = width
+
+ if need_to_get:
+ attrlist = self._get_attrs()
+ self.widths = thread_view_extend.get_char_width(
+ self.pango_layout.get_context(), self.text, attrlist)
+ for index, width in enumerate(self.widths):
+ dict[self.text[index]] = self.widths[index]
+
+ def _get_ch_width_dict(self):
+ return ElementText.ch_width_dict
def _get_attrs(self):
attrs = pango.AttrList()
attrlist.insert(attr)
return attrlist
+ def recalc_char_widths(self):
+ attrlist = self._get_attrs()
+ self.widths = thread_view_extend.get_char_width(
+ self.pango_layout.get_context(), self.text, attrlist)
+
class ElementLink(ElementText):
self.layout = self.threadview.create_res_layout(
self.left_margin, self.resnum)
+ gtk.gdk.threads_enter()
self.layout.add_text(data, bold, href)
+ gtk.gdk.threads_leave()
def to_thread_view(self):
if self.layout is not None: