static MText * mtext_from_utf8 (TableContext *context, const unsigned char *buf, size_t size) { mconv_reset_converter (context->converter); mconv_rebind_buffer (context->converter, buf, size); return mconv_decode (context->converter, mtext ()); }
static gboolean ibus_m17n_engine_process_key (IBusM17NEngine *m17n, MSymbol key) { gchar *buf; MText *produced; gint retval; retval = minput_filter (m17n->context, key, NULL); if (retval) { return TRUE; } produced = mtext (); retval = minput_lookup (m17n->context, key, NULL, produced); if (retval) { // g_debug ("minput_lookup returns %d", retval); } buf = ibus_m17n_mtext_to_utf8 (produced); m17n_object_unref (produced); if (buf && strlen (buf)) { ibus_m17n_engine_commit_string (m17n, buf); } g_free (buf); return retval == 0; }
int m17n_ccx_filter(M17nCCX *m17n,FILE *in,FILE *out){ int rcode = -1; int ecode; m17n->m_mtext = 0; m17n->m_dec = mconv_stream_converter(m17n->m_icode,in); if( m17n->m_dec == 0 ){ m17n_ccx_freeconv(m17n); return -1; } m17n->m_enc = mconv_stream_converter(m17n->m_ocode,out); if( m17n->m_enc == 0 ){ m17n_ccx_freeconv(m17n); return -2; } LAP("converter-set"); m17n->m_mtext = mtext(); m17n->m_dec->lenient = 1; mconv_decode(m17n->m_dec,m17n->m_mtext); LAP("decoded"); m17n->m_enc->lenient = 1; m17n->m_enc->last_block = 1; ecode = mconv_encode(m17n->m_enc,m17n->m_mtext); rcode = 0; LAP("encoded"); m17n_ccx_freeconv(m17n); LAP("filter-done"); return rcode; }
static void on_get_surrounding_text (MInputContext *context, MSymbol command) { g_debug (G_STRLOC ": %s", G_STRFUNC); NimfM17n *m17n = context->arg; if (!NIMF_IS_M17N (m17n) || !nimf_service_im_target) return; gchar *text; gint cursor_pos, nchars, nbytes; MText *mt, *surround = NULL; int len, pos; nimf_engine_get_surrounding (NIMF_ENGINE (m17n), nimf_service_im_target, &text, &cursor_pos); if (text == NULL) return; nchars = g_utf8_strlen (text, -1); nbytes = strlen (text); mt = mconv_decode_buffer (Mcoding_utf_8, (const unsigned char *) text, nbytes); g_free (text); len = (long) mplist_value (m17n->ic->plist); if (len < 0) { pos = cursor_pos + len; if (pos < 0) pos = 0; surround = mtext_duplicate (mt, pos, cursor_pos); } else if (len > 0) { pos = cursor_pos + len; if (pos > nchars) pos = nchars; surround = mtext_duplicate (mt, cursor_pos, pos); } if (!surround) surround = mtext (); m17n_object_unref (mt); mplist_set (m17n->ic->plist, Mtext, surround); m17n_object_unref (surround); }
int m17n_ccx_string(M17nCCX *m17n,const char *istr,int len,char *ostr,int siz){ const unsigned char *uistr = (const unsigned char*)istr; const unsigned char *uostr = (const unsigned char*)ostr; int rcode = -1; int ecode; int oleng = 1; m17n->m_mtext = 0; m17n->m_dec = mconv_buffer_converter(m17n->m_icode,uistr,len); if( m17n->m_dec == 0 ){ m17n_ccx_freeconv(m17n); return -1; } m17n->m_enc = mconv_buffer_converter(m17n->m_ocode,uostr,siz-1); if( m17n->m_enc == 0 ){ m17n_ccx_freeconv(m17n); return -2; } LAP("converter-set"); m17n->m_mtext = mtext(); m17n->m_dec->lenient = 1; mconv_decode(m17n->m_dec,m17n->m_mtext); LAP("decoded"); m17n->m_enc->lenient = 1; m17n->m_enc->last_block = 1; ecode = mconv_encode(m17n->m_enc,m17n->m_mtext); oleng = m17n->m_enc->nbytes; ostr[oleng] = 0; rcode = oleng; LAP("encoded"); m17n_ccx_freeconv(m17n); LAP("filter-done"); return rcode; }
gboolean nimf_m17n_filter_event (NimfEngine *engine, NimfServiceIC *target, NimfEvent *event) { g_debug (G_STRLOC ": %s", G_STRFUNC); NimfM17n *m17n = NIMF_M17N (engine); g_return_val_if_fail (m17n->im != NULL, FALSE); if (event->key.type == NIMF_EVENT_KEY_RELEASE || event->key.keyval == NIMF_KEY_Shift_L || event->key.keyval == NIMF_KEY_Shift_R) return FALSE; nimf_service_im_target = target; guint keyval = event->key.keyval; gboolean move = FALSE; if (nimf_candidatable_is_visible (m17n->candidatable)) { switch (keyval) { case NIMF_KEY_Up: case NIMF_KEY_KP_Up: keyval = NIMF_KEY_Left; break; case NIMF_KEY_Down: case NIMF_KEY_KP_Down: keyval = NIMF_KEY_Right; break; case NIMF_KEY_Left: case NIMF_KEY_KP_Left: case NIMF_KEY_Page_Up: case NIMF_KEY_KP_Page_Up: keyval = NIMF_KEY_Up; nimf_m17n_page_up (m17n); break; case NIMF_KEY_Right: case NIMF_KEY_KP_Right: case NIMF_KEY_Page_Down: case NIMF_KEY_KP_Page_Down: keyval = NIMF_KEY_Down; nimf_m17n_page_down (m17n); break; case NIMF_KEY_KP_0: keyval = NIMF_KEY_0; break; case NIMF_KEY_KP_1: keyval = NIMF_KEY_1; break; case NIMF_KEY_KP_2: keyval = NIMF_KEY_2; break; case NIMF_KEY_KP_3: keyval = NIMF_KEY_3; break; case NIMF_KEY_KP_4: keyval = NIMF_KEY_4; break; case NIMF_KEY_KP_5: keyval = NIMF_KEY_5; break; case NIMF_KEY_KP_6: keyval = NIMF_KEY_6; break; case NIMF_KEY_KP_7: keyval = NIMF_KEY_7; break; case NIMF_KEY_KP_8: keyval = NIMF_KEY_8; break; case NIMF_KEY_KP_9: keyval = NIMF_KEY_9; break; default: move = TRUE; break; } } const gchar *keysym_name; gboolean retval; keysym_name = nimf_keyval_to_keysym_name (keyval); MSymbol symbol; if (keysym_name) { GString *string; string = g_string_new (""); if (event->key.state & NIMF_HYPER_MASK) g_string_append (string, "H-"); if (event->key.state & NIMF_SUPER_MASK) g_string_append (string, "s-"); if (event->key.state & NIMF_MOD5_MASK) g_string_append (string, "G-"); if (event->key.state & NIMF_MOD1_MASK) g_string_append (string, "A-"); if (event->key.state & NIMF_META_MASK) g_string_append (string, "M-"); if (event->key.state & NIMF_CONTROL_MASK) g_string_append (string, "C-"); if (event->key.state & NIMF_SHIFT_MASK) g_string_append (string, "S-"); g_string_append (string, keysym_name); symbol = msymbol (string->str); g_string_free (string, TRUE); } else { g_warning (G_STRLOC ": %s: keysym name not found", G_STRFUNC); symbol = Mnil; } retval = minput_filter (m17n->ic, symbol, NULL); if (!retval) { MText *produced; produced = mtext (); retval = !minput_lookup (m17n->ic, symbol, NULL, produced); if (mtext_len (produced) > 0) { gchar *buf; buf = nimf_m17n_mtext_to_utf8 (m17n, produced); if (m17n->converter->nbytes > 0) nimf_engine_emit_commit (engine, target, (const gchar *) buf); g_free (buf); } m17n_object_unref (produced); } if (m17n->ic->preedit_changed) { gchar *new_preedit = nimf_m17n_mtext_to_utf8 (m17n, m17n->ic->preedit); nimf_m17n_update_preedit (engine, target, new_preedit); } if (m17n->ic->status_changed) { gchar *status; status = nimf_m17n_mtext_to_utf8 (m17n, m17n->ic->status); if (status && strlen (status)) g_debug ("Minput_status_draw: %s", status); g_free (status); } if (m17n->ic->candidate_list && m17n->ic->candidate_show) { nimf_m17n_update_candidate (engine, target); if (!nimf_candidatable_is_visible (m17n->candidatable)) nimf_candidatable_show (m17n->candidatable, target, FALSE); else if (move) nimf_candidatable_show (m17n->candidatable, target, FALSE); } else { nimf_candidatable_hide (m17n->candidatable); } nimf_service_im_target = NULL; return retval; }
static void ibus_m17n_engine_callback (MInputContext *context, MSymbol command) { IBusM17NEngine *m17n = NULL; m17n = context->arg; g_return_if_fail (m17n != NULL); /* the callback may be called in minput_create_ic, in the time * m17n->context has not be assigned, so need assign it. */ if (m17n->context == NULL) { m17n->context = context; } if (command == Minput_preedit_start) { ibus_engine_hide_preedit_text ((IBusEngine *)m17n); } else if (command == Minput_preedit_draw) { ibus_m17n_engine_update_preedit (m17n); } else if (command == Minput_preedit_done) { ibus_engine_hide_preedit_text ((IBusEngine *)m17n); } else if (command == Minput_status_start) { ibus_engine_hide_preedit_text ((IBusEngine *)m17n); } else if (command == Minput_status_draw) { gchar *status; status = ibus_m17n_mtext_to_utf8 (m17n->context->status); if (status && strlen (status)) { IBusText *text; text = ibus_text_new_from_string (status); ibus_property_set_label (m17n->status_prop, text); ibus_property_set_visible (m17n->status_prop, TRUE); } else { ibus_property_set_label (m17n->status_prop, NULL); ibus_property_set_visible (m17n->status_prop, FALSE); } ibus_engine_update_property ((IBusEngine *)m17n, m17n->status_prop); g_free (status); } else if (command == Minput_status_done) { } else if (command == Minput_candidates_start) { ibus_engine_hide_lookup_table ((IBusEngine *) m17n); ibus_engine_hide_auxiliary_text ((IBusEngine *) m17n); } else if (command == Minput_candidates_draw) { ibus_m17n_engine_update_lookup_table (m17n); } else if (command == Minput_candidates_done) { ibus_engine_hide_lookup_table ((IBusEngine *) m17n); ibus_engine_hide_auxiliary_text ((IBusEngine *) m17n); } else if (command == Minput_set_spot) { } else if (command == Minput_toggle) { } else if (command == Minput_reset) { } /* ibus_engine_get_surrounding_text is only available in the current git master (1.3.99+) */ #ifdef HAVE_IBUS_ENGINE_GET_SURROUNDING_TEXT else if (command == Minput_get_surrounding_text && (((IBusEngine *) m17n)->client_capabilities & IBUS_CAP_SURROUNDING_TEXT) != 0) { IBusText *text; guint cursor_pos, nchars, nbytes; MText *mt, *surround; int len, pos; ibus_engine_get_surrounding_text ((IBusEngine *) m17n, &text, &cursor_pos); nchars = ibus_text_get_length (text); nbytes = g_utf8_offset_to_pointer (text->text, nchars) - text->text; mt = mconv_decode_buffer (Mcoding_utf_8, text->text, nbytes); g_object_unref (text); len = (long) mplist_value (m17n->context->plist); if (len < 0) { pos = cursor_pos + len; if (pos < 0) pos = 0; surround = mtext_duplicate (mt, pos, cursor_pos); } else if (len > 0) { pos = cursor_pos + len; if (pos > nchars) pos = nchars; surround = mtext_duplicate (mt, cursor_pos, pos); } else { surround = mtext (); } m17n_object_unref (mt); mplist_set (m17n->context->plist, Mtext, surround); m17n_object_unref (surround); } #endif /* !HAVE_IBUS_ENGINE_GET_SURROUNDING_TEXT */ else if (command == Minput_delete_surrounding_text && (((IBusEngine *) m17n)->client_capabilities & IBUS_CAP_SURROUNDING_TEXT) != 0) { int len; len = (long) mplist_value (m17n->context->plist); if (len < 0) ibus_engine_delete_surrounding_text ((IBusEngine *) m17n, len, -len); else if (len > 0) ibus_engine_delete_surrounding_text ((IBusEngine *) m17n, 0, len); } }
static gchar * transliterator_m17n_real_transliterate (TranslitTransliterator *self, const gchar *input, guint *endpos, GError **error) { TransliteratorM17n *m17n = TRANSLITERATOR_M17N (self); const gchar *p; GString *string; gchar *output; gint n_filtered = 0; string = g_string_sized_new (strlen (input)); minput_reset_ic (m17n->ic); for (p = input; ; p = g_utf8_next_char (p)) { gunichar uc = g_utf8_get_char (p); MSymbol symbol; gint retval; if (*p == '\0') symbol = Mnil; else { gint length; gchar *utf8; length = g_unichar_to_utf8 (uc, NULL); utf8 = g_slice_alloc0 (length + 1); g_unichar_to_utf8 (uc, utf8); symbol = msymbol (utf8); g_slice_free1 (length, utf8); } retval = minput_filter (m17n->ic, symbol, NULL); if (retval == 0) { MText *mt = mtext (); retval = minput_lookup (m17n->ic, symbol, NULL, mt); if (mtext_len (mt) > 0) { output = mtext_to_utf8 (mt); g_string_append (string, output); g_free (output); } if (retval) g_string_append_unichar (string, uc); m17n_object_unref (mt); n_filtered = 0; } else n_filtered++; if (symbol == Mnil) break; } if (endpos) *endpos = g_utf8_strlen (input, -1) - n_filtered; return g_string_free (string, FALSE); }