Skip to content

Commit 1b438ae

Browse files
committed
hangul ic: HANGUL_IC_OPTION_COMBI_ON_DOUBLE_STROKE 옵션 추가
두벌식에서 자음을 연속 입력해서 된소리로 조합해주는 기능을 설정으로 조정할 수 있게 한다. (예를 들어 ㄱ+ㄱ을 ㄲ으로 변환해 주는 기능) 이에 따라서 관련 유닛 테스트 코드를 변경하고 이 옵션을 테스트할 코드를 추가한다. 기본값은 MS IME 호환을 위해서 false로 설정한다. 세벌식의 경우에는 이 기능이 자판의 기본적인 동작 방식이므로 이 옵션으로 조정되지 않는다. 두벌식 옛한글 자판의 경우에는 현대 한글 자모의 경우만 조합이 제한되고 옛한글 자모들은 그대로 조합된다. 구현에 필요한 hangul_is_jamo_conjoinable 함수도 추가.
1 parent 3cc9998 commit 1b438ae

File tree

4 files changed

+163
-64
lines changed

4 files changed

+163
-64
lines changed

hangul/hangul.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ bool hangul_is_jongseong(ucschar c);
4646
bool hangul_is_choseong_conjoinable(ucschar c);
4747
bool hangul_is_jungseong_conjoinable(ucschar c);
4848
bool hangul_is_jongseong_conjoinable(ucschar c);
49+
bool hangul_is_jamo_conjoinable(ucschar c);
4950
bool hangul_is_syllable(ucschar c);
5051
bool hangul_is_jamo(ucschar c);
5152
bool hangul_is_cjamo(ucschar c);
@@ -88,6 +89,7 @@ enum {
8889

8990
enum {
9091
HANGUL_IC_OPTION_AUTO_REORDER,
92+
HANGUL_IC_OPTION_COMBI_ON_DOUBLE_STROKE,
9193
};
9294

9395
/* keyboard */

hangul/hangulctype.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ hangul_is_jongseong_conjoinable(ucschar c)
144144
return c >= 0x11a7 && c <= 0x11c2;
145145
}
146146

147+
/**
148+
* @ingroup hangulctype
149+
* @brief 자모가 조합 가능한지 확인
150+
*/
151+
bool
152+
hangul_is_jamo_conjoinable(ucschar c)
153+
{
154+
return hangul_is_choseong_conjoinable(c) ||
155+
hangul_is_jungseong_conjoinable(c) ||
156+
hangul_is_jongseong_conjoinable(c);
157+
}
158+
147159
/**
148160
* @ingroup hangulctype
149161
* @brief 한글 음절 인지 확

hangul/hangulinputcontext.c

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ struct _HangulInputContext {
235235

236236
unsigned int use_jamo_mode_only : 1;
237237
unsigned int option_auto_reorder : 1;
238+
unsigned int option_combi_on_double_stroke : 1;
238239
};
239240

240241
#include "hangulkeyboard.h"
@@ -851,6 +852,27 @@ hangul_ic_choseong_to_jongseong(HangulInputContext* hic, ucschar cho)
851852
return 0;
852853
}
853854

855+
static ucschar
856+
hangul_ic_combine(HangulInputContext* hic, ucschar first, ucschar second)
857+
{
858+
if (!hic->option_combi_on_double_stroke) {
859+
if (hangul_keyboard_get_type(hic->keyboard) == HANGUL_KEYBOARD_TYPE_JAMO) {
860+
/* 옛한글은 아래 규칙을 적용하지 않아야 입력가능한 글자가 있으므로
861+
* 적용하지 않는다. */
862+
if (first == second &&
863+
hangul_is_jamo_conjoinable(first)) {
864+
return 0;
865+
}
866+
}
867+
}
868+
869+
ucschar combined = 0;
870+
combined = hangul_combination_combine(hic->keyboard->combination,
871+
first, second);
872+
873+
return combined;
874+
}
875+
854876
static bool
855877
hangul_ic_process_jamo(HangulInputContext *hic, ucschar ch)
856878
{
@@ -866,8 +888,7 @@ hangul_ic_process_jamo(HangulInputContext *hic, ucschar ch)
866888
if (hic->buffer.jongseong) {
867889
if (hangul_is_choseong(ch)) {
868890
jong = hangul_ic_choseong_to_jongseong(hic, ch);
869-
combined = hangul_combination_combine(hic->keyboard->combination,
870-
hic->buffer.jongseong, jong);
891+
combined = hangul_ic_combine(hic, hic->buffer.jongseong, jong);
871892
if (hangul_is_jongseong(combined)) {
872893
if (!hangul_ic_push(hic, combined)) {
873894
if (!hangul_ic_push(hic, ch)) {
@@ -944,8 +965,7 @@ hangul_ic_process_jamo(HangulInputContext *hic, ucschar ch)
944965
}
945966
}
946967
} else if (hangul_is_jungseong(ch)) {
947-
combined = hangul_combination_combine(hic->keyboard->combination,
948-
hic->buffer.jungseong, ch);
968+
combined = hangul_ic_combine(hic, hic->buffer.jungseong, ch);
949969
if (hangul_is_jungseong(combined)) {
950970
if (!hangul_ic_push(hic, combined)) {
951971
return false;
@@ -961,8 +981,7 @@ hangul_ic_process_jamo(HangulInputContext *hic, ucschar ch)
961981
}
962982
} else if (hic->buffer.choseong) {
963983
if (hangul_is_choseong(ch)) {
964-
combined = hangul_combination_combine(hic->keyboard->combination,
965-
hic->buffer.choseong, ch);
984+
combined = hangul_ic_combine(hic, hic->buffer.choseong, ch);
966985
/* 초성을 입력한 combine 함수에서 종성이 나오게 된다면
967986
* 이전 초성도 종성으로 바꿔 주는 편이 나머지 처리에 편리하다.
968987
* 이 기능은 MS IME 호환기능으로 ㄳ을 입력하는데 사용한다. */
@@ -1027,8 +1046,7 @@ hangul_ic_process_jaso(HangulInputContext *hic, ucschar ch)
10271046
} else {
10281047
ucschar choseong = 0;
10291048
if (hangul_is_choseong(hangul_ic_peek(hic))) {
1030-
choseong = hangul_combination_combine(hic->keyboard->combination,
1031-
hic->buffer.choseong, ch);
1049+
choseong = hangul_ic_combine(hic, hic->buffer.choseong, ch);
10321050
}
10331051
if (choseong) {
10341052
if (!hangul_ic_push(hic, choseong)) {
@@ -1068,8 +1086,7 @@ hangul_ic_process_jaso(HangulInputContext *hic, ucschar ch)
10681086
} else {
10691087
ucschar jungseong = 0;
10701088
if (hangul_is_jungseong(hangul_ic_peek(hic))) {
1071-
jungseong = hangul_combination_combine(hic->keyboard->combination,
1072-
hic->buffer.jungseong, ch);
1089+
jungseong = hangul_ic_combine(hic, hic->buffer.jungseong, ch);
10731090
}
10741091
if (jungseong) {
10751092
if (!hangul_ic_push(hic, jungseong)) {
@@ -1096,8 +1113,7 @@ hangul_ic_process_jaso(HangulInputContext *hic, ucschar ch)
10961113
} else {
10971114
ucschar jongseong = 0;
10981115
if (hangul_is_jongseong(hangul_ic_peek(hic))) {
1099-
jongseong = hangul_combination_combine(hic->keyboard->combination,
1100-
hic->buffer.jongseong, ch);
1116+
jongseong = hangul_ic_combine(hic, hic->buffer.jongseong, ch);
11011117
}
11021118
if (jongseong) {
11031119
if (!hangul_ic_push(hic, jongseong)) {
@@ -1154,8 +1170,7 @@ hangul_ic_process_romaja(HangulInputContext *hic, int ascii, ucschar ch)
11541170
jong = ch;
11551171
else
11561172
jong = hangul_ic_choseong_to_jongseong(hic, ch);
1157-
combined = hangul_combination_combine(hic->keyboard->combination,
1158-
hic->buffer.jongseong, jong);
1173+
combined = hangul_ic_combine(hic, hic->buffer.jongseong, jong);
11591174
if (hangul_is_jongseong(combined)) {
11601175
if (!hangul_ic_push(hic, combined)) {
11611176
if (!hangul_ic_push(hic, ch)) {
@@ -1229,8 +1244,7 @@ hangul_ic_process_romaja(HangulInputContext *hic, int ascii, ucschar ch)
12291244
}
12301245
}
12311246
} else if (hangul_is_jungseong(ch)) {
1232-
combined = hangul_combination_combine(hic->keyboard->combination,
1233-
hic->buffer.jungseong, ch);
1247+
combined = hangul_ic_combine(hic, hic->buffer.jungseong, ch);
12341248
if (hangul_is_jungseong(combined)) {
12351249
if (!hangul_ic_push(hic, combined)) {
12361250
return false;
@@ -1253,8 +1267,7 @@ hangul_ic_process_romaja(HangulInputContext *hic, int ascii, ucschar ch)
12531267
}
12541268
} else if (hic->buffer.choseong) {
12551269
if (hangul_is_choseong(ch)) {
1256-
combined = hangul_combination_combine(hic->keyboard->combination,
1257-
hic->buffer.choseong, ch);
1270+
combined = hangul_ic_combine(hic, hic->buffer.choseong, ch);
12581271
if (combined == 0) {
12591272
hic->buffer.jungseong = 0x1173;
12601273
hangul_ic_flush_internal(hic);
@@ -1574,6 +1587,8 @@ hangul_ic_get_option(HangulInputContext* hic, int option)
15741587
switch (option) {
15751588
case HANGUL_IC_OPTION_AUTO_REORDER:
15761589
return hic->option_auto_reorder;
1590+
case HANGUL_IC_OPTION_COMBI_ON_DOUBLE_STROKE:
1591+
return hic->option_combi_on_double_stroke;
15771592
}
15781593

15791594
return false;
@@ -1586,6 +1601,9 @@ hangul_ic_set_option(HangulInputContext* hic, int option, bool value)
15861601
case HANGUL_IC_OPTION_AUTO_REORDER:
15871602
hic->option_auto_reorder = value;
15881603
break;
1604+
case HANGUL_IC_OPTION_COMBI_ON_DOUBLE_STROKE:
1605+
hic->option_combi_on_double_stroke = value;
1606+
break;
15891607
}
15901608
}
15911609

@@ -1746,6 +1764,7 @@ hangul_ic_new(const char* keyboard)
17461764
hic->use_jamo_mode_only = FALSE;
17471765

17481766
hic->option_auto_reorder = false;
1767+
hic->option_combi_on_double_stroke = false;
17491768

17501769
hangul_ic_set_output_mode(hic, HANGUL_OUTPUT_SYLLABLE);
17511770
hangul_ic_select_keyboard(hic, keyboard);

0 commit comments

Comments
 (0)