diff options
| author | Huang Peng <shawn.p.huang@gmail.com> | 2008-06-12 10:00:44 +0800 |
|---|---|---|
| committer | Huang Peng <shawn.p.huang@gmail.com> | 2008-06-12 10:00:44 +0800 |
| commit | fc2c64dcd3a31d620717a40d007a8a056ee01331 (patch) | |
| tree | 35c7b09143cc6717f303f08227b4351e5578cc6a | |
| parent | ac3e3a1cf72611cba09fbccd2faf0c6d0cbf884a (diff) | |
| download | ibus-fc2c64dcd3a31d620717a40d007a8a056ee01331.tar.gz ibus-fc2c64dcd3a31d620717a40d007a8a056ee01331.tar.xz ibus-fc2c64dcd3a31d620717a40d007a8a056ee01331.zip | |
Convert offset in PangoAttrList
| -rw-r--r-- | ibus/gtk.py | 15 | ||||
| -rw-r--r-- | panel/candidatepanel.py | 6 |
2 files changed, 14 insertions, 7 deletions
diff --git a/ibus/gtk.py b/ibus/gtk.py index 21294bb..4d1cb0a 100644 --- a/ibus/gtk.py +++ b/ibus/gtk.py @@ -2,27 +2,34 @@ import pango import ibus class PangoAttrList (pango.AttrList): - def __init__ (self, attrs): + def __init__ (self, attrs, unistr): pango.AttrList.__init__ (self) if attrs == None: return + offsets = [] + offset = 0 + for c in unistr: + offsets.append (offset) + offset += len (c.encode ("utf8")) for attr in attrs: pango_attr = None + start_index = offsets[attr._start_index] + end_index = offsets[attr._end_index] if attr._type == ibus.ATTR_TYPE_FOREGROUND: r = (attr._value & 0x00ff0000) >> 8 g = (attr._value & 0x0000ff00) b = (attr._value & 0x000000ff) << 8 pango_attr = pango.AttrForeground (r, g, b, - attr._start_index, attr._end_index) + start_index, end_index) elif attr._type == ibus.ATTR_TYPE_BACKGROUND: r = (attr._value & 0x00ff0000) >> 8 g = (attr._value & 0x0000ff00) b = (attr._value & 0x000000ff) << 8 pango_attr = pango.AttrBackground (r, g, b, - attr._start_index, attr._end_index) + start_index, end_index) elif attr._type == ibus.ATTR_TYPE_UNDERLINE: pango_attr = pango.AttrUnderline (int (attr._value), - attr._start_index, attr._end_index) + start_index, end_index) if pango_attr != None: self.insert (pango_attr) diff --git a/panel/candidatepanel.py b/panel/candidatepanel.py index 2955b39..dd8480a 100644 --- a/panel/candidatepanel.py +++ b/panel/candidatepanel.py @@ -226,7 +226,7 @@ class CandidatePanel (gtk.VBox): self._check_show_states () def update_preedit (self, text, attrs, cursor_pos, show): - attrs = PangoAttrList (attrs) + attrs = PangoAttrList (attrs, text) if show: self.show_preedit_string () else: @@ -249,7 +249,7 @@ class CandidatePanel (gtk.VBox): self._check_show_states () def update_aux_string (self, text, attrs, show): - attrs = PangoAttrList (attrs) + attrs = PangoAttrList (attrs, text) if show: self.show_aux_string () @@ -286,7 +286,7 @@ class CandidatePanel (gtk.VBox): self._lookup_table = lookup_table candidates = self._lookup_table.get_canidates_in_current_page () - candidates = map (lambda x: (x[0], PangoAttrList (x[1])), candidates) + candidates = map (lambda x: (x[0], PangoAttrList (x[1], x[0])), candidates) self._candidate_area.set_candidates (candidates, self._lookup_table.get_cursor_pos_in_current_page ()) def _check_show_states (self): |
