|
Packit Service |
1d8f1c |
# vim:set et sts=4 sw=4:
|
|
Packit Service |
1d8f1c |
#
|
|
Packit Service |
1d8f1c |
# ibus - The Input Bus
|
|
Packit Service |
1d8f1c |
#
|
|
Packit Service |
1d8f1c |
# Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com>
|
|
Packit Service |
1d8f1c |
# Copyright (c) 2007-2010 Red Hat, Inc.
|
|
Packit Service |
1d8f1c |
#
|
|
Packit Service |
1d8f1c |
# This library is free software; you can redistribute it and/or
|
|
Packit Service |
1d8f1c |
# modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
1d8f1c |
# License as published by the Free Software Foundation; either
|
|
Packit Service |
1d8f1c |
# version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
1d8f1c |
#
|
|
Packit Service |
1d8f1c |
# This library is distributed in the hope that it will be useful,
|
|
Packit Service |
1d8f1c |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
1d8f1c |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
1d8f1c |
# Lesser General Public License for more details.
|
|
Packit Service |
1d8f1c |
#
|
|
Packit Service |
1d8f1c |
# You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
1d8f1c |
# License along with this library; if not, write to the Free Software
|
|
Packit Service |
1d8f1c |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
Packit Service |
1d8f1c |
# USA
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
__all__ = (
|
|
Packit Service |
1d8f1c |
"PangoAttrList",
|
|
Packit Service |
1d8f1c |
)
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
import pango
|
|
Packit Service |
1d8f1c |
import ibus
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
class PangoAttrList(pango.AttrList):
|
|
Packit Service |
1d8f1c |
def __init__(self, attrs, unistr):
|
|
Packit Service |
1d8f1c |
super(PangoAttrList, self).__init__()
|
|
Packit Service |
1d8f1c |
if attrs == None:
|
|
Packit Service |
1d8f1c |
return
|
|
Packit Service |
1d8f1c |
offsets = []
|
|
Packit Service |
1d8f1c |
offset = 0
|
|
Packit Service |
1d8f1c |
for c in unistr:
|
|
Packit Service |
1d8f1c |
offsets.append(offset)
|
|
Packit Service |
1d8f1c |
offset += len(c.encode("utf8"))
|
|
Packit Service |
1d8f1c |
offsets.append(offset)
|
|
Packit Service |
1d8f1c |
for attr in attrs:
|
|
Packit Service |
1d8f1c |
pango_attr = None
|
|
Packit Service |
1d8f1c |
start_index = attr.start_index if attr.start_index >= 0 else 0
|
|
Packit Service |
1d8f1c |
end_index = attr.end_index if attr.end_index >= 0 else 0
|
|
Packit Service |
1d8f1c |
start_index = offsets[start_index] if start_index < len(offsets) else offsets[-1]
|
|
Packit Service |
1d8f1c |
end_index = offsets[end_index] if end_index < len(offsets) else offsets[-1]
|
|
Packit Service |
1d8f1c |
if attr.type == ibus.ATTR_TYPE_FOREGROUND:
|
|
Packit Service |
1d8f1c |
r = (attr.value & 0x00ff0000) >> 8
|
|
Packit Service |
1d8f1c |
g = (attr.value & 0x0000ff00)
|
|
Packit Service |
1d8f1c |
b = (attr.value & 0x000000ff) << 8
|
|
Packit Service |
1d8f1c |
pango_attr = pango.AttrForeground(r, g, b,
|
|
Packit Service |
1d8f1c |
start_index, end_index)
|
|
Packit Service |
1d8f1c |
elif attr.type == ibus.ATTR_TYPE_BACKGROUND:
|
|
Packit Service |
1d8f1c |
r = (attr.value & 0x00ff0000) >> 8
|
|
Packit Service |
1d8f1c |
g = (attr.value & 0x0000ff00)
|
|
Packit Service |
1d8f1c |
b = (attr.value & 0x000000ff) << 8
|
|
Packit Service |
1d8f1c |
pango_attr = pango.AttrBackground(r, g, b,
|
|
Packit Service |
1d8f1c |
start_index, end_index)
|
|
Packit Service |
1d8f1c |
elif attr.type == ibus.ATTR_TYPE_UNDERLINE:
|
|
Packit Service |
1d8f1c |
pango_attr = pango.AttrUnderline(int(attr.value),
|
|
Packit Service |
1d8f1c |
start_index, end_index)
|
|
Packit Service |
1d8f1c |
if pango_attr != None:
|
|
Packit Service |
1d8f1c |
self.insert(pango_attr)
|
|
Packit Service |
1d8f1c |
|