ibus-fwnnをaonotoがいじってみる(予定)
リビジョン | efe9a0d83a72233b7834deb9cb32ec1f68138029 (tree) |
---|---|
日時 | 2015-08-07 03:26:20 |
作者 | Hashimoto Masahiko <hashimom@X201...> |
コミッター | Hashimoto Masahiko |
equip real-time-convert
@@ -2,6 +2,7 @@ | ||
2 | 2 | |
3 | 3 | #include <string.h> |
4 | 4 | #include <syslog.h> |
5 | +#include <stdlib.h> | |
5 | 6 | #include "convert.h" |
6 | 7 | |
7 | 8 | typedef struct { |
@@ -16,6 +16,7 @@ struct _IBusFwnnEngine { | ||
16 | 16 | |
17 | 17 | /* members */ |
18 | 18 | GString *preedit; |
19 | + GString *convedit; | |
19 | 20 | gint cursor_pos; |
20 | 21 | |
21 | 22 | IBusLookupTable *table; |
@@ -35,6 +36,7 @@ static gboolean | ||
35 | 36 | guint keyval, |
36 | 37 | guint keycode, |
37 | 38 | guint modifiers); |
39 | +#if 0 | |
38 | 40 | static void ibus_fwnn_engine_focus_in (IBusEngine *engine); |
39 | 41 | static void ibus_fwnn_engine_focus_out (IBusEngine *engine); |
40 | 42 | static void ibus_fwnn_engine_reset (IBusEngine *engine); |
@@ -61,6 +63,7 @@ static void ibus_fwnn_engine_property_show | ||
61 | 63 | static void ibus_fwnn_engine_property_hide |
62 | 64 | (IBusEngine *engine, |
63 | 65 | const gchar *prop_name); |
66 | +#endif | |
64 | 67 | |
65 | 68 | static void ibus_fwnn_engine_update (IBusFwnnEngine *fwnn); |
66 | 69 |
@@ -93,6 +96,7 @@ ibus_fwnn_engine_init (IBusFwnnEngine *fwnn) | ||
93 | 96 | printf("ibus_fwnn_engine init FAILED\n"); |
94 | 97 | } |
95 | 98 | fwnn->preedit = g_string_new (""); |
99 | + fwnn->convedit = g_string_new (""); | |
96 | 100 | fwnn->cursor_pos = 0; |
97 | 101 | |
98 | 102 | fwnn->table = ibus_lookup_table_new (9, 0, TRUE, TRUE); |
@@ -113,6 +117,7 @@ ibus_fwnn_engine_destroy (IBusFwnnEngine *fwnn) | ||
113 | 117 | |
114 | 118 | if (fwnn->preedit) { |
115 | 119 | g_string_free (fwnn->preedit, TRUE); |
120 | + g_string_free (fwnn->convedit, TRUE); | |
116 | 121 | fwnn->preedit = NULL; |
117 | 122 | } |
118 | 123 |
@@ -124,6 +129,7 @@ ibus_fwnn_engine_destroy (IBusFwnnEngine *fwnn) | ||
124 | 129 | ((IBusObjectClass *) ibus_fwnn_engine_parent_class)->destroy ((IBusObject *)fwnn); |
125 | 130 | } |
126 | 131 | |
132 | +#if 0 | |
127 | 133 | static void |
128 | 134 | ibus_fwnn_engine_update_lookup_table (IBusFwnnEngine *fwnn) |
129 | 135 | { |
@@ -157,25 +163,29 @@ ibus_fwnn_engine_update_lookup_table (IBusFwnnEngine *fwnn) | ||
157 | 163 | // if (sugs) |
158 | 164 | // fwnn_dict_free_suggestions (dict, sugs); |
159 | 165 | } |
166 | +#endif | |
160 | 167 | |
161 | 168 | static gboolean |
162 | 169 | ibus_fwnn_engine_kanren (IBusFwnnEngine *fwnn) |
163 | 170 | { |
164 | 171 | IBusText *text; |
165 | - char *kanren_p = NULL; | |
172 | + unsigned char *kanren_p = NULL; | |
166 | 173 | gint retval; |
167 | 174 | |
168 | 175 | kanren_p = fwnnserver_kanren(fwnn->preedit->str); |
169 | 176 | text = ibus_text_new_from_static_string (kanren_p); |
170 | - g_string_assign (fwnn->preedit, text->text); | |
171 | - ibus_text_append_attribute(text, IBUS_ATTR_TYPE_FOREGROUND, 0x00FFFF, 0, fwnn->preedit->len); | |
177 | + g_string_assign (fwnn->convedit, text->text); | |
178 | + | |
179 | + text->attrs = ibus_attr_list_new (); | |
180 | + ibus_attr_list_append (text->attrs, | |
181 | + ibus_attr_underline_new (IBUS_ATTR_UNDERLINE_SINGLE, 0, fwnn->convedit->len)); | |
182 | + | |
172 | 183 | ibus_engine_update_preedit_text ((IBusEngine *)fwnn, |
173 | 184 | text, |
174 | 185 | fwnn->cursor_pos, |
175 | 186 | TRUE); |
176 | 187 | |
177 | 188 | ibus_engine_hide_lookup_table ((IBusEngine *)fwnn); |
178 | - | |
179 | 189 | return TRUE; |
180 | 190 | } |
181 | 191 |
@@ -188,9 +198,10 @@ ibus_fwnn_engine_commit (IBusFwnnEngine *fwnn) | ||
188 | 198 | if (fwnn->preedit->len == 0) |
189 | 199 | return FALSE; |
190 | 200 | |
191 | - text = ibus_text_new_from_static_string (fwnn->preedit->str); | |
201 | + text = ibus_text_new_from_static_string (fwnn->convedit->str); | |
192 | 202 | ibus_engine_commit_text ((IBusEngine *)fwnn, text); |
193 | 203 | g_string_assign (fwnn->preedit, ""); |
204 | + g_string_assign (fwnn->convedit, ""); | |
194 | 205 | fwnn->cursor_pos = 0; |
195 | 206 | |
196 | 207 | ibus_fwnn_engine_update (fwnn); |
@@ -337,7 +348,7 @@ ibus_fwnn_engine_process_key_event (IBusEngine *engine, | ||
337 | 348 | fwnn->cursor_pos, |
338 | 349 | keyval); |
339 | 350 | fwnn->cursor_pos = conv_run_romajiconv(fwnn->preedit, fwnn->cursor_pos); |
340 | - ibus_fwnn_engine_update (fwnn); | |
351 | + ibus_fwnn_engine_kanren(fwnn); | |
341 | 352 | |
342 | 353 | return TRUE; |
343 | 354 | } |
@@ -18,7 +18,7 @@ | ||
18 | 18 | #define PC_DIC "pubdic/computer.dic" |
19 | 19 | #define SYMBOL_DIC "pubdic/symbol.dic" |
20 | 20 | |
21 | -#define MAX_CONV_STRLEN (4096) | |
21 | +#define MAX_CONV_STRLEN (1024) | |
22 | 22 | #define CONV_UTF82EUC (0) |
23 | 23 | #define CONV_EUC2UTF8 (1) |
24 | 24 |
@@ -27,7 +27,9 @@ static WNN_ENV *wnnenv; | ||
27 | 27 | static struct wnn_ret_buf wnnbuf= {0, NULL}; |
28 | 28 | |
29 | 29 | /* もちろん仮。malloc して返すように変更する予定 */ |
30 | -static char wnn_out_kanstr[MAX_CONV_STRLEN]; | |
30 | +static unsigned char wnn_yomi_buf[MAX_CONV_STRLEN]; | |
31 | +static unsigned char wnn_out_kanstr[MAX_CONV_STRLEN]; | |
32 | + | |
31 | 33 | |
32 | 34 | static void set_wnn_env_pram() |
33 | 35 | { |
@@ -76,7 +78,7 @@ static void strtows(w_char *u, unsigned char *e) | ||
76 | 78 | *u=0; |
77 | 79 | } |
78 | 80 | |
79 | -static int putws(unsigned short *s, char *outstr) | |
81 | +static int putws(unsigned short *s, unsigned char *outstr) | |
80 | 82 | { |
81 | 83 | int ret = 0; |
82 | 84 |
@@ -93,8 +95,8 @@ static void output_js2char(struct wnn_dai_bunsetsu *dlist, int cnt) | ||
93 | 95 | { |
94 | 96 | int i, tmpbuf_len; |
95 | 97 | struct wnn_sho_bunsetsu *sbn; |
96 | - char kanstr_tmp[MAX_CONV_STRLEN]; | |
97 | - char kanstr_utf8[MAX_CONV_STRLEN]; | |
98 | + unsigned char kanstr_tmp[MAX_CONV_STRLEN]; | |
99 | + unsigned char kanstr_utf8[MAX_CONV_STRLEN]; | |
98 | 100 | |
99 | 101 | for ( ; cnt > 0; dlist++, cnt --) { |
100 | 102 | sbn = dlist->sbn; |
@@ -169,12 +171,20 @@ int fwnnserver_adddic(char *dicfilename) | ||
169 | 171 | return dicno; |
170 | 172 | } |
171 | 173 | |
172 | -char *fwnnserver_kanren(char *yomi) | |
174 | +unsigned char *fwnnserver_kanren(unsigned char *yomi) | |
173 | 175 | { |
174 | 176 | // とりあえずサイズ決め打ち |
175 | - char yomi_euc[MAX_CONV_STRLEN]; | |
177 | + unsigned char yomi_euc[MAX_CONV_STRLEN]; | |
176 | 178 | w_char upstrings[MAX_CONV_STRLEN]; |
177 | 179 | int count = 0; |
180 | + int i=0, yomilen = strlen(yomi); | |
181 | + | |
182 | + // 未確定文字ポインタ(暫定実装で削除予定) | |
183 | + for (i = 0; i < yomilen;) { | |
184 | + if (yomi[i] < 0x7F) | |
185 | + break; | |
186 | + i += 3; | |
187 | + } | |
178 | 188 | |
179 | 189 | memset(yomi_euc, 0, MAX_CONV_STRLEN); |
180 | 190 | memset(upstrings, 0, MAX_CONV_STRLEN); |
@@ -183,9 +193,13 @@ char *fwnnserver_kanren(char *yomi) | ||
183 | 193 | exec_iconv(yomi, yomi_euc, CONV_UTF82EUC); |
184 | 194 | strtows(upstrings, yomi_euc); |
185 | 195 | |
186 | - count = js_kanren(wnnenv, upstrings, WNN_ALL_HINSI, NULL, WNN_VECT_KANREN, WNN_VECT_NO, WNN_VECT_BUNSETSU,&wnnbuf); | |
196 | + count = js_kanren(wnnenv, upstrings, WNN_ALL_HINSI, NULL, | |
197 | + WNN_VECT_KANREN, WNN_VECT_NO, WNN_VECT_BUNSETSU,&wnnbuf); | |
187 | 198 | output_js2char((struct wnn_dai_bunsetsu *)wnnbuf.buf, count); |
188 | 199 | |
200 | + if (i < yomilen) | |
201 | + strcat(wnn_out_kanstr, yomi+i); | |
202 | + | |
189 | 203 | return wnn_out_kanstr; |
190 | 204 | } |
191 | 205 |
@@ -2,9 +2,10 @@ | ||
2 | 2 | #ifndef __FWNN_H__ |
3 | 3 | #define __FWNN_H |
4 | 4 | |
5 | + | |
5 | 6 | int fwnnserver_open(); |
6 | 7 | int fwnnserver_close(); |
7 | 8 | int fwnnserver_adddic(char *dicfilename); |
8 | -char *fwnnserver_kanren(char *yomi); | |
9 | +unsigned char *fwnnserver_kanren(unsigned char *yomi); | |
9 | 10 | |
10 | 11 | #endif |