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
29 class PangoAttrList (pango
.AttrList
):
30 def __init__ (self
, attrs
, unistr
):
31 pango
.AttrList
.__init
__ (self
)
37 offsets
.append (offset
)
38 offset
+= len (c
.encode ("utf8"))
39 offsets
.append (offset
)
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__":