int main(int argc, char *argv[]) { char* hanja_table_file = NULL; char buf[256] = { '\0', }; if (argc > 1) hanja_table_file = argv[1]; HanjaTable *table; table = hanja_table_load(hanja_table_file); while (fgets(buf, sizeof(buf), stdin) != NULL) { char* p = strchr(buf, '\n'); if (p != NULL) *p = '\0'; HanjaList *list = hanja_table_match_prefix(table, buf); int i, n; n = hanja_list_get_size(list); for (i = 0; i < n; i++) { const char* key = hanja_list_get_nth_key(list, i); const char* value = hanja_list_get_nth_value(list, i); const char* comment = hanja_list_get_nth_comment(list, i); printf("%s:%s:%s\n", key, value, comment); } hanja_list_delete(list); } hanja_table_delete(table); return 0; }
void HangulInstance::update_candidates () { m_lookup_table.clear (); m_candidate_comments.clear (); HanjaList* list = NULL; // search for symbol character // key string for symbol character is like: // 'ㄱ', 'ㄴ', 'ㄷ', etc WideString preeditw = get_preedit_string(); if (preeditw.length() == 1) { String key = utf8_wcstombs(preeditw); list = hanja_table_match_suffix(m_factory->m_symbol_table, key.c_str()); } // search for hanja if (list == NULL) { String str = get_candidate_string(); SCIM_DEBUG_IMENGINE(1) << "candidate string: " << str << "\n"; if (str.length() > 0) { if (is_hanja_mode() || m_factory->m_commit_by_word) { list = hanja_table_match_prefix(m_factory->m_hanja_table, str.c_str()); } else { list = hanja_table_match_suffix(m_factory->m_hanja_table, str.c_str()); } } } if (list != NULL) { int n = hanja_list_get_size(list); for (int i = 0; i < n; ++i) { const char* value = hanja_list_get_nth_value(list, i); const char* comment = hanja_list_get_nth_comment(list, i); WideString candidate = utf8_mbstowcs(value, -1); m_lookup_table.append_candidate(candidate); m_candidate_comments.push_back(String(comment)); } m_lookup_table.set_page_size (9); m_lookup_table.show_cursor (); update_lookup_table (m_lookup_table); show_lookup_table (); hangul_update_aux_string (); hanja_list_delete(list); } if (m_lookup_table.number_of_candidates() <= 0) { delete_candidates(); } }
static void ibus_hangul_engine_hide_lookup_table (IBusHangulEngine *hangul) { gboolean is_visible; is_visible = lookup_table_is_visible (hangul->table); // Sending hide lookup table message when the lookup table // is not visible results wrong behavior. So I have to check // whether the table is visible or not before to hide. if (is_visible) { ibus_engine_hide_lookup_table ((IBusEngine *)hangul); ibus_engine_hide_auxiliary_text ((IBusEngine *)hangul); lookup_table_set_visible (hangul->table, FALSE); } if (hangul->hanja_list != NULL) { hanja_list_delete (hangul->hanja_list); hangul->hanja_list = NULL; } }
static void nimf_libhangul_finalize (GObject *object) { g_debug (G_STRLOC ": %s", G_STRFUNC); NimfLibhangul *hangul = NIMF_LIBHANGUL (object); if (--nimf_libhangul_hanja_table_ref_count == 0) { hanja_table_delete (nimf_libhangul_hanja_table); hanja_table_delete (nimf_libhangul_symbol_table); } hanja_list_delete (hangul->hanja_list); hangul_ic_delete (hangul->context); g_free (hangul->preedit_string); nimf_preedit_attr_freev (hangul->preedit_attrs); g_free (hangul->id); g_free (hangul->method); nimf_key_freev (hangul->hanja_keys); g_object_unref (hangul->settings); G_OBJECT_CLASS (nimf_libhangul_parent_class)->finalize (object); }
static void ibus_hangul_engine_update_hanja_list (IBusHangulEngine *hangul) { gchar* hanja_key; gchar* preedit_utf8; const ucschar* hic_preedit; UString* preedit; int lookup_method; IBusText* ibus_text = NULL; guint cursor_pos = 0; guint anchor_pos = 0; if (hangul->hanja_list != NULL) { hanja_list_delete (hangul->hanja_list); hangul->hanja_list = NULL; } hic_preedit = hangul_ic_get_preedit_string (hangul->context); hanja_key = NULL; lookup_method = LOOKUP_METHOD_PREFIX; preedit = ustring_dup (hangul->preedit); ustring_append_ucs4 (preedit, hic_preedit, -1); if (ustring_length(preedit) > 0) { preedit_utf8 = ustring_to_utf8 (preedit, -1); if (word_commit || hangul->hanja_mode) { hanja_key = preedit_utf8; lookup_method = LOOKUP_METHOD_PREFIX; } else { gchar* substr; ibus_engine_get_surrounding_text ((IBusEngine *)hangul, &ibus_text, &cursor_pos, &anchor_pos); substr = h_ibus_text_get_substring (ibus_text, cursor_pos - 64, cursor_pos); if (substr != NULL) { hanja_key = g_strconcat (substr, preedit_utf8, NULL); g_free (preedit_utf8); } else { hanja_key = preedit_utf8; } lookup_method = LOOKUP_METHOD_SUFFIX; } } else { ibus_engine_get_surrounding_text ((IBusEngine *)hangul, &ibus_text, &cursor_pos, &anchor_pos); if (cursor_pos != anchor_pos) { // If we have selection in surrounding text, we use that. hanja_key = h_ibus_text_get_substring (ibus_text, cursor_pos, anchor_pos); lookup_method = LOOKUP_METHOD_EXACT; } else { hanja_key = h_ibus_text_get_substring (ibus_text, cursor_pos - 64, cursor_pos); lookup_method = LOOKUP_METHOD_SUFFIX; } } if (hanja_key != NULL) { hangul->hanja_list = ibus_hangul_engine_lookup_hanja_table (hanja_key, lookup_method); hangul->last_lookup_method = lookup_method; g_free (hanja_key); } ustring_delete (preedit); if (ibus_text != NULL) g_object_unref (ibus_text); }
gboolean nimf_libhangul_filter_event (NimfEngine *engine, NimfServiceIC *target, NimfEvent *event) { g_debug (G_STRLOC ": %s", G_STRFUNC); guint keyval; gboolean retval = FALSE; NimfLibhangul *hangul = NIMF_LIBHANGUL (engine); if (event->key.type == NIMF_EVENT_KEY_RELEASE || event->key.keyval == NIMF_KEY_Shift_L || event->key.keyval == NIMF_KEY_Shift_R) return FALSE; if (event->key.state & (NIMF_CONTROL_MASK | NIMF_MOD1_MASK)) { nimf_libhangul_reset (engine, target); return FALSE; } if (G_UNLIKELY (nimf_event_matches (event, (const NimfKey **) hangul->hanja_keys))) { if (nimf_candidatable_is_visible (hangul->candidatable) == FALSE) { gchar item[4]; const char *key = hangul->preedit_string; gboolean use_preedit; if (hangul->preedit_string[0] == 0) { gchar *text; gint cursor_pos; nimf_engine_get_surrounding (engine, target, &text, &cursor_pos); if (text && cursor_pos > 0) { gchar *p = g_utf8_offset_to_pointer (text, cursor_pos - 1); g_utf8_strncpy (item, p, 1); if (g_utf8_validate (item, -1, NULL)) key = item; } g_free (text); } hanja_list_delete (hangul->hanja_list); nimf_candidatable_clear (hangul->candidatable, target); hangul->hanja_list = hanja_table_match_exact (nimf_libhangul_hanja_table, key); if (hangul->hanja_list == NULL) hangul->hanja_list = hanja_table_match_exact (nimf_libhangul_symbol_table, key); hangul->n_pages = (hanja_list_get_size (hangul->hanja_list) + 9) / 10; hangul->current_page = 1; nimf_libhangul_update_page (engine, target); use_preedit = nimf_service_ic_get_use_preedit (target); if (!use_preedit) nimf_candidatable_set_auxiliary_text (hangul->candidatable, key, g_utf8_strlen (key, -1)); nimf_candidatable_show (hangul->candidatable, target, !use_preedit); nimf_candidatable_select_first_item_in_page (hangul->candidatable); } else { nimf_candidatable_hide (hangul->candidatable); nimf_candidatable_clear (hangul->candidatable, target); hanja_list_delete (hangul->hanja_list); hangul->hanja_list = NULL; hangul->current_page = 0; hangul->n_pages = 0; } return TRUE; } if (nimf_candidatable_is_visible (hangul->candidatable)) { switch (event->key.keyval) { case NIMF_KEY_Return: case NIMF_KEY_KP_Enter: { gchar *text; text = nimf_candidatable_get_selected_text (hangul->candidatable); on_candidate_clicked (engine, target, text, -1); g_free (text); } break; case NIMF_KEY_Up: case NIMF_KEY_KP_Up: nimf_candidatable_select_previous_item (hangul->candidatable); break; case NIMF_KEY_Down: case NIMF_KEY_KP_Down: nimf_candidatable_select_next_item (hangul->candidatable); break; case NIMF_KEY_Page_Up: case NIMF_KEY_KP_Page_Up: nimf_libhangul_page_up (engine, target); break; case NIMF_KEY_Page_Down: case NIMF_KEY_KP_Page_Down: nimf_libhangul_page_down (engine, target); break; case NIMF_KEY_Home: nimf_libhangul_page_home (engine, target); break; case NIMF_KEY_End: nimf_libhangul_page_end (engine, target); break; case NIMF_KEY_Escape: nimf_candidatable_hide (hangul->candidatable); break; case NIMF_KEY_0: case NIMF_KEY_1: case NIMF_KEY_2: case NIMF_KEY_3: case NIMF_KEY_4: case NIMF_KEY_5: case NIMF_KEY_6: case NIMF_KEY_7: case NIMF_KEY_8: case NIMF_KEY_9: case NIMF_KEY_KP_0: case NIMF_KEY_KP_1: case NIMF_KEY_KP_2: case NIMF_KEY_KP_3: case NIMF_KEY_KP_4: case NIMF_KEY_KP_5: case NIMF_KEY_KP_6: case NIMF_KEY_KP_7: case NIMF_KEY_KP_8: case NIMF_KEY_KP_9: { if (hangul->hanja_list == NULL || hangul->current_page < 1) break; gint i, n; gint list_len = hanja_list_get_size (hangul->hanja_list); if (event->key.keyval >= NIMF_KEY_0 && event->key.keyval <= NIMF_KEY_9) n = (event->key.keyval - NIMF_KEY_0 + 9) % 10; else if (event->key.keyval >= NIMF_KEY_KP_0 && event->key.keyval <= NIMF_KEY_KP_9) n = (event->key.keyval - NIMF_KEY_KP_0 + 9) % 10; else break; i = (hangul->current_page - 1) * 10 + n; if (i < MIN (hangul->current_page * 10, list_len)) { const Hanja *hanja = hanja_list_get_nth (hangul->hanja_list, i); const char *text = hanja_get_value (hanja); on_candidate_clicked (engine, target, (gchar *) text, -1); } } break; default: break; } return TRUE; } const ucschar *ucs_commit; const ucschar *ucs_preedit; if (G_UNLIKELY (event->key.keyval == NIMF_KEY_BackSpace)) { retval = hangul_ic_backspace (hangul->context); if (retval) { ucs_preedit = hangul_ic_get_preedit_string (hangul->context); gchar *new_preedit = g_ucs4_to_utf8 (ucs_preedit, -1, NULL, NULL, NULL); nimf_libhangul_update_preedit (engine, target, new_preedit); } return retval; } if (G_UNLIKELY (g_strcmp0 (hangul->method, "ro") == 0)) keyval = event->key.keyval; else keyval = nimf_event_keycode_to_qwerty_keyval (event); if (!hangul->is_double_consonant_rule && (g_strcmp0 (hangul->method, "2") == 0) && nimf_libhangul_filter_leading_consonant (engine, target, keyval)) return TRUE; retval = hangul_ic_process (hangul->context, keyval); ucs_commit = hangul_ic_get_commit_string (hangul->context); ucs_preedit = hangul_ic_get_preedit_string (hangul->context); gchar *new_commit = g_ucs4_to_utf8 (ucs_commit, -1, NULL, NULL, NULL); if (ucs_commit[0] != 0) nimf_libhangul_emit_commit (engine, target, new_commit); g_free (new_commit); gchar *new_preedit = g_ucs4_to_utf8 (ucs_preedit, -1, NULL, NULL, NULL); nimf_libhangul_update_preedit (engine, target, new_preedit); return retval; }