diff options
author | Huang Peng <shawn.p.huang@gmail.com> | 2008-08-15 15:59:02 +0800 |
---|---|---|
committer | Huang Peng <shawn.p.huang@gmail.com> | 2008-08-15 15:59:02 +0800 |
commit | d73edd3ecd4135151131e63fb510f58a202eb02e (patch) | |
tree | 2a910bc93b285e128d801b9e2358151a5f43ece3 | |
parent | f6ba190711636de62918b2db9a4007dd6dc75674 (diff) | |
download | ibus-hangul-d73edd3ecd4135151131e63fb510f58a202eb02e.tar.gz |
Implement hangul.i
-rw-r--r-- | engine/Makefile.am | 4 | ||||
-rw-r--r-- | engine/hangul.i | 212 | ||||
-rw-r--r-- | po/POTFILES.in | 2 |
3 files changed, 163 insertions, 55 deletions
diff --git a/engine/Makefile.am b/engine/Makefile.am index 751d266..4de2b75 100644 --- a/engine/Makefile.am +++ b/engine/Makefile.am @@ -40,12 +40,12 @@ nodist__hangul_la_SOURCES = \ $(NULL) _hangul_la_CFLAGS = \ - @ANTHY_CFLAGS@ \ + @HANGUL_CFLAGS@ \ @PYTHON_CFLAGS@ \ $(NULL) _hangul_la_LDFLAGS = \ - @ANTHY_LIBS@ \ + @HANGUL_LIBS@ \ -rpath $(hanguldir) \ -avoid-version \ -module \ diff --git a/engine/hangul.i b/engine/hangul.i index c48481c..941d785 100644 --- a/engine/hangul.i +++ b/engine/hangul.i @@ -1,6 +1,6 @@ /* vim:set et ts=4: */ /* - * ibus-anthy - The Anthy engine for IBus + * ibus-hangul - The Hangul engine for IBus * * Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com> * @@ -19,97 +19,207 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -%module anthy +%module hangul %{ /* Put header files here or function declarations like below */ -#include <anthy/anthy.h> +#include <wchar.h> +#include <hangul.h> %} %init %{ - anthy_init (); %} +%typemap (in) ucschar * { + if (PyUnicode_Check ($input)) { + $1 = PyUnicode_AsUnicode ($input); + } + else { + PyErr_SetString (PyExc_TypeError, + "arg msut be unistr"); + return NULL; + } +} + +%typemap (out) ucschar * { + if ($1 != NULL) { + $result = PyUnicode_FromWideChar ($1, wcslen ($1)); + } + else { + Py_INCREF (Py_None); + $result = Py_None; + } +} + +typedef int ucschar; + +/* define struct HangulKeyboard */ +typedef struct {} HangulKeyboard; +%extend HangulKeyboard { + HangulKeyboard () { + return hangul_keyboard_new (); + } + + ~HangulKeyboard () { + hangul_keyboard_delete (self); + } + + void set_value (int key, ucschar value) { + hangul_keyboard_set_value (self, key, value); + } + + void set_type (int type) { + hangul_keyboard_set_type (self, type); + } +}; + +/* define struct HangulCombination */ +typedef struct {} HangulCombination; +%extend HangulCombination { + HangulCombination () { + return hangul_combination_new (); + } + + ~HangulCombination () { + hangul_combination_delete (self); + } + + bool set_data (ucschar *first, ucschar *second, ucschar *result, int n) { + return hangul_combination_set_data (self, first, second, result, n); + } +}; -/* anthy_context_t */ -%include anthy/anthy.h -struct anthy_context {}; -%extend anthy_context { - anthy_context () { - return anthy_create_context (); +/* define struct HangulInputContext */ +typedef struct {} HangulInputContext; +%extend HangulInputContext { + HangulInputContext (char *keyboard) { + return hangul_ic_new (keyboard); + } + + ~HangulInputContext() { + hangul_ic_delete (self); + } + + bool process (int ascii) { + return hangul_ic_process (self, ascii); } void reset () { - anthy_reset_context (self); + hangul_ic_reset (self); } - int set_string (char *str) { - return anthy_set_string (self, str); + bool backspace () { + return hangul_ic_backspace (self); } - void resize_segment (int a1, int a2) { - anthy_resize_segment (self, a1, a2); + bool is_empty () { + return hangul_ic_is_empty (self); } - int get_stat (struct anthy_conv_stat *a1) { - return anthy_get_stat (self, a1); + bool has_choseong () { + return hangul_ic_has_choseong (self); } - int get_segment_stat (int a1, struct anthy_segment_stat *a2) { - return anthy_get_segment_stat (self, a1, a2); + bool has_jungseong () { + return hangul_ic_has_jungseong (self); } - char *get_segment (int a1, int a2) { - int len; - static char temp[512]; + bool has_jongseong () { + return hangul_ic_has_jongseong (self); + } - len = anthy_get_segment (self, a1, a2, temp, sizeof (temp)); - if (len >= 0) - return temp; - else - return NULL; + int dvorak_to_qwerty (int qwerty) { + return hangul_ic_dvorak_to_qwerty (qwerty); } - int commit_segment (int a1, int a2) { - return anthy_commit_segment (self, a1, a2); + void set_output_mode (int mode) { + hangul_ic_set_output_mode (self, mode); } - int set_prediction_string (const char *a1) { - return anthy_set_prediction_string (self, a1); + void set_keyboard (const HangulKeyboard *keyboard) { + hangul_ic_set_keyboard (self, keyboard); } - int get_prediction_stat (struct anthy_prediction_stat *a1) { - return anthy_get_prediction_stat (self, a1); + void select_keyboard (const char *id) { + hangul_ic_select_keyboard (self, id); } - char *get_prediction (int a1) { - int len; - static char temp[512]; + void set_combination (const HangulCombination *combination) { + hangul_ic_set_combination (self, combination); + } - len = anthy_get_prediction (self, a1, temp, sizeof (temp)); + void connect_callback (void *event, void *callback, void *user_data) { + hangul_ic_connect_callback (self, event, callback, user_data); + } - if (len >= 0) - return temp; - else - return NULL; + const ucschar *get_preedit_string () { + return hangul_ic_get_preedit_string (self); } - int commit_prediction (int a1) { - return anthy_commit_prediction(self, a1); + const ucschar *get_commit_string () { + return hangul_ic_get_commit_string (self); } - void _print () { - anthy_print_context (self); + const ucschar *flush () { + return hangul_ic_flush (self); } +}; - int _set_encoding (int encoding) { - return anthy_context_set_encoding (self, encoding); +/* + Translate HanjaList to (key, [(v1, c1), (v2, c2), ...]) + */ +%typemap (out) HanjaList * { + if ($1 != NULL) { + int size = hanja_list_get_size ($1); + PyObject *key = PyString_FromString (hanja_list_get_key ($1)); + PyObject *list = PyList_New (size); + int i; + for (i = 0; i < size; i++) { + const Hanja *hanja = hanja_list_get_nth ($1, i); + PyObject *value = PyString_FromString (hanja_get_value (hanja)); + PyObject *comment = PyString_FromString (hanja_get_comment (hanja)); + PyList_SetItem (list, i, PyTuple_Pack (2, value, comment)); + } + hanja_list_delete ($1); + $result = PyTuple_Pack (2, key, list); + } + else { + Py_INCREF (Py_None); + $result = Py_None; } +} - int set_reconversion_mode (int mode) { - return anthy_set_reconversion_mode (self, mode); +/* define HanjaTable */ +typedef struct {} HanjaTable; +%extend HanjaTable { + HanjaTable (const char *name) { + return hanja_table_load (name); } - ~anthy_context () { - anthy_release_context (self); + ~HanjaTable () { + hanja_table_delete (self); } + + HanjaList *match_prefix (const char *key) { + return hanja_table_match_prefix (self, key); + } + + HanjaList *match_suffix (const char *key) { + return hanja_table_match_suffix (self, key); + } +} + +enum { + HANGUL_CHOSEONG_FILLER = 0x115f, /* hangul choseong filler */ + HANGUL_JUNGSEONG_FILLER = 0x1160 /* hangul jungseong filler */ }; +enum { + HANGUL_OUTPUT_SYLLABLE, + HANGUL_OUTPUT_JAMO +}; + +enum { + HANGUL_KEYBOARD_TYPE_JAMO, + HANGUL_KEYBOARD_TYPE_JASO +}; + + diff --git a/po/POTFILES.in b/po/POTFILES.in index 8b0fdd0..2cab87c 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,5 +1,3 @@ -./python-config.py ./engine/main.py -./engine/tables.py ./engine/engine.py ./engine/factory.py |