summaryrefslogtreecommitdiff
path: root/hangul/hangul.h
blob: ea25a5b102bab5cbcab9a80ef0d686b5a53fbf5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* libhangul
 * Copyright (C) 2004 Choe Hwanjin
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 */

#ifndef _HANGUL_H_
#define _HANGUL_H_

#include <wchar.h>
#include <stdbool.h>
#include <inttypes.h>

#ifdef __cplusplus
extern "C" {
#endif

/* hangulctype.c */
enum {
    HANGUL_CHOSEONG_FILLER  = 0x115f,   /* hangul choseong filler */
    HANGUL_JUNGSEONG_FILLER = 0x1160    /* hangul jungseong filler */
};

typedef uint32_t ucschar;

bool hangul_is_choseong(ucschar c);
bool hangul_is_jungseong(ucschar c);
bool hangul_is_jongseong(ucschar c);
bool hangul_is_choseong_conjoinable(ucschar c);
bool hangul_is_jungseong_conjoinable(ucschar c);
bool hangul_is_jongseong_conjoinable(ucschar c);
bool hangul_is_syllable(ucschar c);
bool hangul_is_jaso(ucschar c);
bool hangul_is_jamo(ucschar c);

ucschar hangul_choseong_to_jamo(ucschar ch);
ucschar hangul_jungseong_to_jamo(ucschar ch);
ucschar hangul_jongseong_to_jamo(ucschar ch);

ucschar hangul_choseong_to_jongseong(ucschar ch);
ucschar hangul_jongseong_to_choseong(ucschar ch);
void    hangul_jongseong_dicompose(ucschar ch, ucschar* jong, ucschar* cho);

ucschar hangul_jaso_to_syllable(ucschar choseong,
				ucschar jungseong,
				ucschar jongseong);

/* hangulinputcontext.c */
typedef struct _HangulJamoCombination HangulJamoCombination;
typedef struct _HangulBuffer HangulBuffer;
typedef struct _HangulInputContext HangulInputContext;

typedef enum {
    HANGUL_KEYBOARD_2,
    HANGUL_KEYBOARD_32,
    HANGUL_KEYBOARD_3FINAL,
    HANGUL_KEYBOARD_390,
    HANGUL_KEYBOARD_3NOSHIFT,
    HANGUL_KEYBOARD_3YETGUL
} HangulKeyboardType;

enum {
    HANGUL_OUTPUT_SYLLABLE,
    HANGUL_OUTPUT_JAMO
};

enum {
    HANGUL_INPUT_FILTER_2,
    HANGUL_INPUT_FILTER_3
};

struct _HangulJamoCombination {
    uint32_t key;
    ucschar code;
};

struct _HangulBuffer {
    ucschar choseong;
    ucschar jungseong;
    ucschar jongseong;

    ucschar stack[12];
    int     index;
};

struct _HangulInputContext {
    int type;
    const ucschar *keyboard_table;
    const HangulJamoCombination *combination_table;
    int combination_table_size;
    HangulBuffer buffer;
    int output_mode;

    ucschar preedit_string[64];
    ucschar commit_string[64];
};

HangulInputContext* hangul_ic_new(HangulKeyboardType keyboard);
void hangul_ic_delete(HangulInputContext *hic);
bool hangul_ic_filter(HangulInputContext *hic, int ascii);
void hangul_ic_reset(HangulInputContext *hic);
bool hangul_ic_backspace(HangulInputContext *hic);

void hangul_ic_set_output_mode(HangulInputContext *hic, int mode);
void hangul_ic_set_keyboard(HangulInputContext *hic,
			    HangulKeyboardType keyboard);
const ucschar* hangul_ic_get_preedit_string(HangulInputContext *hic);
const ucschar* hangul_ic_get_commit_string(HangulInputContext *hic);

/* hanja.c */
enum {
    HANJA_MATCH_EXACT,
    HANJA_MATCH_PREFIX
};

typedef struct _Hanja Hanja;
typedef struct _HanjaList HanjaList;
typedef struct _HanjaTable HanjaTable;

struct _Hanja {
    const char *key;
    const char *value;
    const char *comment;
};

struct _HanjaList {
    const char *key;
    int nitems;
    Hanja **items; 
};

struct _HanjaTable {
    int nmember;
    HanjaList **base;
};

HanjaTable* hanja_table_load(const char *filename);
HanjaList*  hanja_table_match(const HanjaTable* table,
			      int option, const char *key);
void hanja_table_destroy(HanjaTable *table);
void hanja_list_destroy(HanjaList *list);

#ifdef __cplusplus
}
#endif

#endif /* _HANGUL_H_ */