ibus-m17n/ibus-m17n-HEAD.patch

154 lines
5.1 KiB
Diff

diff --git a/src/engine.c b/src/engine.c
index dcfbe48..21fae67 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -254,12 +254,31 @@ ibus_m17n_engine_destroy (IBusM17NEngine *m17n)
}
static void
+ibus_m17n_engine_update_preedit (IBusM17NEngine *m17n)
+{
+ IBusText *text;
+ gchar *buf;
+
+ buf = ibus_m17n_mtext_to_utf8 (m17n->context->preedit);
+ if (buf) {
+ text = ibus_text_new_from_static_string (buf);
+ ibus_text_append_attribute (text, IBUS_ATTR_TYPE_FOREGROUND, 0x00ffffff, 0, -1);
+ ibus_text_append_attribute (text, IBUS_ATTR_TYPE_BACKGROUND, 0x00000000, 0, -1);
+ ibus_engine_update_preedit_text ((IBusEngine *) m17n,
+ text,
+ m17n->context->cursor_pos,
+ mtext_len (m17n->context->preedit) > 0);
+ }
+}
+
+static void
ibus_m17n_engine_commit_string (IBusM17NEngine *m17n,
const gchar *string)
{
IBusText *text;
text = ibus_text_new_from_static_string (string);
ibus_engine_commit_text ((IBusEngine *)m17n, text);
+ ibus_m17n_engine_update_preedit (m17n);
}
MSymbol
@@ -503,14 +522,15 @@ ibus_m17n_engine_update_lookup_table (IBusM17NEngine *m17n)
if (mplist_key (group) == Mtext) {
MText *mt;
- gunichar *buf, *p;
+ gunichar *buf;
+ glong nchars, i;
mt = (MText *) mplist_value (group);
ibus_lookup_table_set_page_size (m17n->table, mtext_len (mt));
- buf = ibus_m17n_mtext_to_ucs4 (mt);
- for (p = buf + 1; *p != 0; p++) {
- ibus_lookup_table_append_candidate (m17n->table, ibus_text_new_from_unichar (*p));
+ buf = ibus_m17n_mtext_to_ucs4 (mt, &nchars);
+ for (i = 0; i < nchars; i++) {
+ ibus_lookup_table_append_candidate (m17n->table, ibus_text_new_from_unichar (buf[i]));
}
g_free (buf);
}
@@ -565,19 +585,7 @@ ibus_m17n_engine_callback (MInputContext *context,
ibus_engine_hide_preedit_text ((IBusEngine *)m17n);
}
else if (command == Minput_preedit_draw) {
- IBusText *text;
- gchar *buf;
-
- buf = ibus_m17n_mtext_to_utf8 (m17n->context->preedit);
- if (buf) {
- text = ibus_text_new_from_static_string (buf);
- ibus_text_append_attribute (text, IBUS_ATTR_TYPE_FOREGROUND, 0x00ffffff, 0, -1);
- ibus_text_append_attribute (text, IBUS_ATTR_TYPE_BACKGROUND, 0x00000000, 0, -1);
- ibus_engine_update_preedit_text ((IBusEngine *) m17n,
- text,
- m17n->context->cursor_pos,
- mtext_len (m17n->context->preedit) > 0);
- }
+ ibus_m17n_engine_update_preedit (m17n);
}
else if (command == Minput_preedit_done) {
ibus_engine_hide_preedit_text ((IBusEngine *)m17n);
diff --git a/src/m17nutil.c b/src/m17nutil.c
index 257f68e..dc2626e 100644
--- a/src/m17nutil.c
+++ b/src/m17nutil.c
@@ -5,7 +5,6 @@
#define N_(text) text
static MConverter *utf8_converter = NULL;
-static MConverter *utf32_converter = NULL;
static const gchar *keymap[] = {
"m17n:as:phonetic",
@@ -35,10 +34,6 @@ ibus_m17n_init (void)
if (utf8_converter == NULL) {
utf8_converter = mconv_buffer_converter (Mcoding_utf_8, NULL, 0);
}
-
- if (utf32_converter == NULL) {
- utf32_converter = mconv_buffer_converter (Mcoding_utf_32, NULL, 0);
- }
}
gchar *
@@ -64,25 +59,28 @@ ibus_m17n_mtext_to_utf8 (MText *text)
}
gunichar *
-ibus_m17n_mtext_to_ucs4 (MText *text)
+ibus_m17n_mtext_to_ucs4 (MText *text, glong *nchars)
{
- gint bufsize;
- gunichar *buf;
+ glong bufsize;
+ gchar *buf;
+ gunichar *ucs;
if (text == NULL)
return NULL;
- mconv_reset_converter (utf32_converter);
-
- bufsize = (mtext_len (text) + 2) * sizeof (gunichar);
- buf = (gunichar *) g_malloc (bufsize);
-
- mconv_rebind_buffer (utf32_converter, (gchar *)buf, bufsize);
- mconv_encode (utf32_converter, text);
+ mconv_reset_converter (utf8_converter);
- buf [utf32_converter->nchars] = 0;
+ bufsize = (mtext_len (text) + 1) * 6;
+ buf = (gchar *) g_malloc (bufsize);
- return buf;
+ mconv_rebind_buffer (utf8_converter, buf, bufsize);
+ if (mconv_encode (utf8_converter, text) < 0) {
+ g_free (buf);
+ return NULL;
+ }
+ ucs = g_utf8_to_ucs4_fast (buf, bufsize, nchars);
+ g_free (buf);
+ return ucs;
}
static IBusEngineDesc *
diff --git a/src/m17nutil.h b/src/m17nutil.h
index 82e7e59..707c5cc 100644
--- a/src/m17nutil.h
+++ b/src/m17nutil.h
@@ -9,5 +9,6 @@ void ibus_m17n_init (void);
GList *ibus_m17n_list_engines (void);
IBusComponent *ibus_m17n_get_component (void);
gchar *ibus_m17n_mtext_to_utf8 (MText *text);
-gunichar *ibus_m17n_mtext_to_ucs4 (MText *text);
+gunichar *ibus_m17n_mtext_to_ucs4 (MText *text,
+ glong *nchars);
#endif