/* pango.c generated by valac 0.40.8, the Vala compiler
* generated from pango.vala, do not modify */
/* vim:set et sts=4 sw=4:
*
* ibus - The Input Bus
*
* Copyright(c) 2011 Peng Huang <shawn.p.huang@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#include <glib.h>
#include <glib-object.h>
#include <ibus.h>
#include <pango/pango.h>
#include <stdlib.h>
#include <string.h>
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _pango_attribute_destroy0(var) ((var == NULL) ? NULL : (var = (pango_attribute_destroy (var), NULL)))
#define _pango_attr_list_unref0(var) ((var == NULL) ? NULL : (var = (pango_attr_list_unref (var), NULL)))
PangoAttrList* get_pango_attr_list_from_ibus_text (IBusText* text);
static gint
string_index_of_nth_char (const gchar* self,
glong c)
{
gint result = 0;
gchar* _tmp0_;
g_return_val_if_fail (self != NULL, 0);
_tmp0_ = g_utf8_offset_to_pointer (self, c);
result = (gint) (_tmp0_ - ((gchar*) self));
return result;
}
static gpointer
_g_object_ref0 (gpointer self)
{
return self ? g_object_ref (self) : NULL;
}
PangoAttrList*
get_pango_attr_list_from_ibus_text (IBusText* text)
{
PangoAttrList* result = NULL;
PangoAttrList* pango_attrs = NULL;
PangoAttrList* _tmp0_;
IBusAttrList* attrs = NULL;
IBusAttrList* _tmp1_;
IBusAttrList* _tmp2_;
const gchar* str = NULL;
const gchar* _tmp3_;
glong nchars = 0L;
const gchar* _tmp4_;
glong* offsets = NULL;
glong _tmp5_;
glong* _tmp6_;
gint offsets_length1;
gint _offsets_size_;
IBusAttribute* attr = NULL;
gint i = 0;
g_return_val_if_fail (text != NULL, NULL);
_tmp0_ = pango_attr_list_new ();
pango_attrs = _tmp0_;
_tmp1_ = ibus_text_get_attributes (text);
attrs = _tmp1_;
_tmp2_ = attrs;
if (_tmp2_ == NULL) {
result = pango_attrs;
return result;
}
_tmp3_ = ibus_text_get_text (text);
str = _tmp3_;
_tmp4_ = str;
nchars = (glong) g_utf8_strlen (_tmp4_, (gssize) -1);
_tmp5_ = nchars;
_tmp6_ = g_new0 (glong, _tmp5_ + 1);
offsets = _tmp6_;
offsets_length1 = _tmp5_ + 1;
_offsets_size_ = offsets_length1;
{
gint i = 0;
i = 0;
{
gboolean _tmp7_ = FALSE;
_tmp7_ = TRUE;
while (TRUE) {
gint _tmp9_;
glong _tmp10_;
glong* _tmp11_;
gint _tmp11__length1;
gint _tmp12_;
const gchar* _tmp13_;
gint _tmp14_;
glong _tmp15_;
if (!_tmp7_) {
gint _tmp8_;
_tmp8_ = i;
i = _tmp8_ + 1;
}
_tmp7_ = FALSE;
_tmp9_ = i;
_tmp10_ = nchars;
if (!(((glong) _tmp9_) <= _tmp10_)) {
break;
}
_tmp11_ = offsets;
_tmp11__length1 = offsets_length1;
_tmp12_ = i;
_tmp13_ = str;
_tmp14_ = i;
_tmp11_[_tmp12_] = (glong) string_index_of_nth_char (_tmp13_, (glong) _tmp14_);
_tmp15_ = _tmp11_[_tmp12_];
}
}
}
i = 0;
while (TRUE) {
IBusAttrList* _tmp16_;
gint _tmp17_;
IBusAttribute* _tmp18_;
IBusAttribute* _tmp19_;
IBusAttribute* _tmp20_;
glong start_index = 0L;
IBusAttribute* _tmp21_;
guint _tmp22_;
glong _tmp23_;
glong _tmp24_ = 0L;
glong _tmp25_;
glong _tmp26_;
glong end_index = 0L;
IBusAttribute* _tmp32_;
guint _tmp33_;
glong _tmp34_;
glong _tmp35_ = 0L;
glong _tmp36_;
glong _tmp37_;
PangoAttribute* pango_attr = NULL;
IBusAttribute* _tmp43_;
guint _tmp44_;
PangoAttribute* _tmp68_;
glong _tmp69_;
PangoAttribute* _tmp70_;
glong _tmp71_;
PangoAttrList* _tmp72_;
PangoAttribute* _tmp73_;
_tmp16_ = attrs;
_tmp17_ = i;
i = _tmp17_ + 1;
_tmp18_ = ibus_attr_list_get (_tmp16_, (guint) _tmp17_);
_tmp19_ = _g_object_ref0 (_tmp18_);
_g_object_unref0 (attr);
attr = _tmp19_;
_tmp20_ = attr;
if (_tmp20_ == NULL) {
break;
}
_tmp21_ = attr;
_tmp22_ = _tmp21_->start_index;
start_index = (glong) _tmp22_;
_tmp23_ = start_index;
if (_tmp23_ <= ((glong) 0)) {
start_index = (glong) 0;
}
_tmp25_ = start_index;
_tmp26_ = nchars;
if (_tmp25_ <= _tmp26_) {
glong* _tmp27_;
gint _tmp27__length1;
glong _tmp28_;
glong _tmp29_;
_tmp27_ = offsets;
_tmp27__length1 = offsets_length1;
_tmp28_ = start_index;
_tmp29_ = _tmp27_[_tmp28_];
_tmp24_ = _tmp29_;
} else {
glong* _tmp30_;
gint _tmp30__length1;
glong _tmp31_;
_tmp30_ = offsets;
_tmp30__length1 = offsets_length1;
_tmp31_ = _tmp30_[-1];
_tmp24_ = _tmp31_;
}
start_index = _tmp24_;
_tmp32_ = attr;
_tmp33_ = _tmp32_->end_index;
end_index = (glong) _tmp33_;
_tmp34_ = end_index;
if (_tmp34_ <= ((glong) 0)) {
end_index = (glong) 0;
}
_tmp36_ = end_index;
_tmp37_ = nchars;
if (_tmp36_ <= _tmp37_) {
glong* _tmp38_;
gint _tmp38__length1;
glong _tmp39_;
glong _tmp40_;
_tmp38_ = offsets;
_tmp38__length1 = offsets_length1;
_tmp39_ = end_index;
_tmp40_ = _tmp38_[_tmp39_];
_tmp35_ = _tmp40_;
} else {
glong* _tmp41_;
gint _tmp41__length1;
glong _tmp42_;
_tmp41_ = offsets;
_tmp41__length1 = offsets_length1;
_tmp42_ = _tmp41_[-1];
_tmp35_ = _tmp42_;
}
end_index = _tmp35_;
pango_attr = NULL;
_tmp43_ = attr;
_tmp44_ = _tmp43_->type;
switch (_tmp44_) {
case IBUS_ATTR_TYPE_FOREGROUND:
{
{
guint16 r = 0U;
IBusAttribute* _tmp45_;
guint _tmp46_;
guint16 g = 0U;
IBusAttribute* _tmp47_;
guint _tmp48_;
guint16 b = 0U;
IBusAttribute* _tmp49_;
guint _tmp50_;
guint16 _tmp51_;
guint16 _tmp52_;
guint16 _tmp53_;
PangoAttribute* _tmp54_;
_tmp45_ = attr;
_tmp46_ = _tmp45_->value;
r = (guint16) ((_tmp46_ & 0x00ff0000) >> 8);
_tmp47_ = attr;
_tmp48_ = _tmp47_->value;
g = (guint16) (_tmp48_ & 0x0000ff00);
_tmp49_ = attr;
_tmp50_ = _tmp49_->value;
b = (guint16) ((_tmp50_ & 0x000000ff) << 8);
_tmp51_ = r;
_tmp52_ = g;
_tmp53_ = b;
_tmp54_ = pango_attr_foreground_new (_tmp51_, _tmp52_, _tmp53_);
_pango_attribute_destroy0 (pango_attr);
pango_attr = _tmp54_;
break;
}
}
case IBUS_ATTR_TYPE_BACKGROUND:
{
{
guint16 r = 0U;
IBusAttribute* _tmp55_;
guint _tmp56_;
guint16 g = 0U;
IBusAttribute* _tmp57_;
guint _tmp58_;
guint16 b = 0U;
IBusAttribute* _tmp59_;
guint _tmp60_;
guint16 _tmp61_;
guint16 _tmp62_;
guint16 _tmp63_;
PangoAttribute* _tmp64_;
_tmp55_ = attr;
_tmp56_ = _tmp55_->value;
r = (guint16) ((_tmp56_ & 0x00ff0000) >> 8);
_tmp57_ = attr;
_tmp58_ = _tmp57_->value;
g = (guint16) (_tmp58_ & 0x0000ff00);
_tmp59_ = attr;
_tmp60_ = _tmp59_->value;
b = (guint16) ((_tmp60_ & 0x000000ff) << 8);
_tmp61_ = r;
_tmp62_ = g;
_tmp63_ = b;
_tmp64_ = pango_attr_background_new (_tmp61_, _tmp62_, _tmp63_);
_pango_attribute_destroy0 (pango_attr);
pango_attr = _tmp64_;
break;
}
}
case IBUS_ATTR_TYPE_UNDERLINE:
{
{
IBusAttribute* _tmp65_;
guint _tmp66_;
PangoAttribute* _tmp67_;
_tmp65_ = attr;
_tmp66_ = _tmp65_->value;
_tmp67_ = pango_attr_underline_new ((PangoUnderline) _tmp66_);
_pango_attribute_destroy0 (pango_attr);
pango_attr = _tmp67_;
break;
}
}
default:
{
continue;
}
}
_tmp68_ = pango_attr;
_tmp69_ = start_index;
_tmp68_->start_index = (guint) _tmp69_;
_tmp70_ = pango_attr;
_tmp71_ = end_index;
_tmp70_->end_index = (guint) _tmp71_;
_tmp72_ = pango_attrs;
_tmp73_ = pango_attr;
pango_attr = NULL;
pango_attr_list_insert (_tmp72_, _tmp73_);
_pango_attribute_destroy0 (pango_attr);
}
result = pango_attrs;
_g_object_unref0 (attr);
offsets = (g_free (offsets), NULL);
return result;
}