Remove m17n/Makefile.am
[ibus.git] / ibus / gtk.py
blob87427678e683f29751dd96900500c78f6a5e926e
1 # vim:set noet ts=4:
3 # ibus - The Input Bus
5 # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program; if not, write to the
19 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 # Boston, MA 02111-1307 USA
22 __all__ = (
23 "PangoAttrList",
26 import pango
27 import ibus
29 class PangoAttrList (pango.AttrList):
30 def __init__ (self, attrs, unistr):
31 pango.AttrList.__init__ (self)
32 if attrs == None:
33 return
34 offsets = []
35 offset = 0
36 for c in unistr:
37 offsets.append (offset)
38 offset += len (c.encode ("utf8"))
39 offsets.append (offset)
40 for attr in attrs:
41 pango_attr = None
42 start_index = attr._start_index if attr._start_index >= 0 else 0
43 end_index = attr._end_index if attr._end_index >= 0 else 0
44 start_index = offsets[start_index] if start_index < len (offsets) else offsets[-1]
45 end_index = offsets[end_index] if end_index < len (offsets) else offsets[-1]
46 if attr._type == ibus.ATTR_TYPE_FOREGROUND:
47 r = (attr._value & 0x00ff0000) >> 8
48 g = (attr._value & 0x0000ff00)
49 b = (attr._value & 0x000000ff) << 8
50 pango_attr = pango.AttrForeground (r, g, b,
51 start_index, end_index)
52 elif attr._type == ibus.ATTR_TYPE_BACKGROUND:
53 r = (attr._value & 0x00ff0000) >> 8
54 g = (attr._value & 0x0000ff00)
55 b = (attr._value & 0x000000ff) << 8
56 pango_attr = pango.AttrBackground (r, g, b,
57 start_index, end_index)
58 elif attr._type == ibus.ATTR_TYPE_UNDERLINE:
59 pango_attr = pango.AttrUnderline (int (attr._value),
60 start_index, end_index)
61 if pango_attr != None:
62 self.insert (pango_attr)
65 if __name__ == "__main__":
66 PangoAttrList (None)