forked from pat-al/Online-HanGeul-IME
/
ohi.js
4296 lines (3902 loc) · 178 KB
/
ohi.js
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** Modified Version (http://ohi.pat.im)
* Modifier : Pat-al <pat@pat.im> (https://pat.im/910)
* Last Update : 2017/07/01
* Added support for more keyboard basic_layouts by custom keyboard layout tables.
* Added support for Dvorak and Colemak keyboard basic_layouts.
* Added support for Firefox 12 and higher version.
* Added the on-screen keyboard function.
* Added support for old Hangeul combination by Syllable-Initial-Peak-Final Encoding Approach.
* Added support for simultaneous input(moachigi) of some Hangeul keyboards.
**/
/** Original Version (copy - http://ohi.pat.im/org)
* Author : Ho-Seok Ee <hsee@korea.ac.kr>
* Release: 2006/07/18
* Update : 2011/01/22
Copyright (C) Ho-Seok Ee <hsee@korea.ac.kr>. All rights reserved.
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.
The license can be found at http://www.gnu.org/licenses/gpl.txt.
**/
var default_En_type = 'QWERTY';
var default_Ko_type = 'Sin3-P2';
var default_ohi_KBD_type = 'QWERTY';
var default_ohi_KE = 'Ko';
var default_enable_double_final_ext = 0;
var default_enable_diphthong_ext = 0;
var default_enable_sign_ext = 1;
var default_force_normal_typing = 0;
var default_only_CGG_encoding = 0;
var default_enable_Sin3_yeshangeul_combination = 0;
var default_enable_Sin3_diphthong_key = 1;
var default_phonemic_writing = 0;
var default_abbreviation = 0;
var default_convenience_combination = 0;
var default_sunalae = 0;
var default_square_layout = 1;
var En_type; // 영문 자판 종류 (ohiChange 함수로 바꿈)
var Ko_type; // 한글 자판 종류 (ohiChange 함수로 바꿈)
var ohi_KBD_type; // 기준 자판 종류 (QWERTY/QWERTZ/AZERTY, ohiChange_KBD_type 함수로 바꿈)
var ohi_KE; // 한글·영문 상태 (Ko: 한글, En: 영문) (ohiChange_KE 함수로 바꿈)
// En_type, Ko_type 등이 미리 지정되어 있으면 지정된 것으로 초기값을 바꿈
if(typeof En_type != 'undefined') default_En_type = En_type; else En_type = default_En_type;
if(typeof Ko_type != 'undefined') default_Ko_type = Ko_type; else Ko_type = default_Ko_type;
if(typeof ohi_KBD_type != 'undefined') default_ohi_KBD_type = ohi_KBD_type; else ohi_KBD_type = default_ohi_KBD_type;
if(typeof ohi_KE != 'undefined') default_ohi_KE = ohi_KE; else ohi_KE = default_ohi_KE;
if(typeof enable_sign_ext != 'undefined') default_enable_sign_ext = enable_sign_ext;
if(typeof force_normal_typing != 'undefined') default_force_normal_typing = force_normal_typing;
if(typeof phonemic_writing != 'undefined') default_phonemic_writing = phonemic_writing;
if(typeof square_layout != 'undefined') default_square_layout = square_layout;
function basic_layouts() {
var KE; // 한글·영문 상태 (Ko:한글, En:영문)
var type_name; // 자판 배열 이름 (OHI에서 쓰는 로마자 이름)
var full_name; // 자판 배열 이름
var layout; // 기본 배열
var sublayout; // 덧붙여 쓰는 보조 배열
var extended_sign_layout; // 기호 확장 배열
var extended_hangeul_layout; // 한글 확장 배열
var hangeul_combination_table; // 한글 낱자 조합 규칙 (이어치기)
var hangeul_convenience_combination_table; // 입력 편의를 높이려고 더해 쓰는 한글 낱자 조합 규칙 (이어치기)
var extended_hangeul_combination_table; // 옛한글 낱자 조합 규칙 (이어치기)
var moachigi_hangeul_combination_table; // 모아치기 자판의 한글 조합 규칙 (낱자 차례를 따지지 않음)
var ieochigi_abbreviation_table; // 낱자로 조합하는 줄임말 규칙 (이어치기)
var moachigi_abbreviation_table; // 낱자로 조합하는 줄임말 규칙 (모아치기)
var multikey_abbreviation_table; // 글쇠로 조합하는 줄임말 규칙 (모아치기) (다른 조합 규칙보다 가장 먼저 적용됨)
var link; // 자판 배열의 정보가 있는 웹 주소
}
function basic_layout_list() {
basic_layouts.push({KE: 'En', type_name: 'QWERTY', full_name: 'QWERTY'});
basic_layouts.push({KE: 'En', type_name: 'Dvorak', full_name: 'Dvorak', layout: En_Dvorak_layout});
basic_layouts.push({KE: 'En', type_name: 'Colemak', full_name: 'Colemak', layout: En_Colemak_layout});
basic_layouts.push({KE: 'Ko', type_name: '2-KSX5002', full_name: '한국 표준 (KS X 5002)'});
basic_layouts.push({KE: 'Ko', type_name: '2-KPS9256', full_name: '조선 국규 (KPS 9256)'});
basic_layouts.push({KE: 'Ko', type_name: '2-sun-KSX5002', full_name: '순아래 두벌식 (KS X 5002) (꼬마집오리)', link: 'https://sites.google.com/site/tinyduckn/dubeolsig-sun-alae'});
basic_layouts.push({KE: 'Ko', type_name: '3-90', full_name: '3-90 (IBM 세벌식)', layout: K3_90_layout, link: ''});
basic_layouts.push({KE: 'Ko', type_name: '3-91', full_name: '3-91 (공병우 최종 자판) (매킨토시 세벌식)', layout: K3_91_layout, link: ''});
basic_layouts.push({KE: 'Ko', type_name: '3-93-y', full_name: '3-93 옛한글', layout: K3_93y_layout, link: 'http://asadal.busan.ac.kr/~gimgs0/hangeul/kbd/'});
basic_layouts.push({KE: 'Ko', type_name: '3-2012', full_name: '3-2012', layout: K3_2012_layout, extended_sign_layout: typeof K3_2012_extended_sign_layout != 'undefined' ? K3_2012_extended_sign_layout : null, link: 'https://pat.im/938'});
if(typeof K3_Sin3_extended_sign_layout == 'undefined') K3_Sin3_extended_sign_layout = null;
basic_layouts.push({KE: 'Ko', type_name: 'Sin3-P2', full_name: '신세벌식 P2', layout: K3_Sin3_P2_layout, sublayout: K3_Sin3_P2_sublayout, extended_hangeul_layout: K3_Sin3_P2_y_layout, extended_sign_layout: K3_Sin3_extended_sign_layout, extended_hangeul_combination_table: K3_Sin3_P2_extended_combination_table, link: 'https://pat.im/1136'});
}
function option() {
var enable_double_final_ext; // 겹받침 확장 배열 쓰기 --> ohiChange_enable_double_final_ext() 함수로 값을 바꿈
var enable_diphthong_ext; // 겹홀소리 확장 배열 쓰기 --> ohiChange_enable_diphthong_ext() 함수로 값을 바꿈
var enable_sign_ext; // 세벌식 자판의 기호 확장 배열 쓰기 --> ohiChange_enable_sign_ext() 함수로 값을 바꿈
var force_normal_typing; // 모아치기 자판을 이어치기(일반 타자법)로 치게 하기
var only_CGG_encoding; // 옛한글 자판에서 첫가끝 부호 체계만 쓰기
var enable_Sin3_yeshangeul_combination; // 신세벌식 자판에서 옛한글 조합하기
var enable_Sin3_diphthong_key; // 0이면 신세벌식 자판에서 오른쪽 글쇠로 홀소리를 넣을 수 없음
var phonemic_writing; // 풀어쓰기
var abbreviation; // 이어치기 자판에서 줄임말 기능 쓰기
var convenience_combination; // 입력 편의를 높이는 추가 낱자 조합 쓰기
var sunalae; // 두벌식 자판 순아래 조합
var show_layout; // 1: 자판 배열표 보이기 0: 자판 배열표 감추기 --> show_keyboard_layout() 함수로 값을 바꿈
var turn_off_OHI; // OHI 입력 기능 멈추기 (화상 자판은 그대로 씀)
var squred_layout; // 화상 배열표를 네모지게 나타내기
}
function NCR_option() {
var enable_NCR; // HTML 문자 참조 보기
var convert_only_CGG_encoding; // 첫가끝 조합형으로 들어간 한글만 바꾸기
}
var option=new option();
option.enable_double_final_ext = default_enable_double_final_ext;
option.enable_diphthong_ext = default_enable_diphthong_ext;
option.enable_sign_ext = default_enable_sign_ext;
option.force_normal_typing = default_force_normal_typing;
option.only_CGG_encoding = default_only_CGG_encoding;
option.enable_Sin3_yeshangeul_combination = default_enable_Sin3_yeshangeul_combination;
option.enable_Sin3_diphthong_key = default_enable_Sin3_diphthong_key;
option.phonemic_writing = default_phonemic_writing;
option.abbreviation = default_abbreviation;
option.convenience_combination = default_convenience_combination;
option.sunalae = default_sunalae;
option.turn_off_OHI = 0;
option.show_layout = 1;
option.square_layout = default_square_layout;
var NCR_option = new NCR_option();
NCR_option.enable_NCR = 0;
NCR_option.convert_only_CGG_encoding = 0;
var ohiQ = [0,0,0,0,0,0,0,0,0]; // 조합하고 있는 요즘한글 낱자를 담는 배열 [첫,첫,첫,가,가,가,끝,끝,끝]
var ohiRQ = [0,0,0,0,0,0,0,0,0]; // 조합하고 있는 요즘한글 낱자의 추가 정보를 담는 배열 (보기: 겹홀소리 조합용 홀소리인지, 받침 붙는 홀소리인지)
var backup_ohiQ = []; // 요즘한글에서 옛한글 상태로 바뀔 때에 복사해 두는 배열
var backup_ohiRQ = [];
var backspaces_for_restoring_prev_state = 0; // 모아치기 자판이나 줄임말 기능을 쓸 때 바로 앞선 상태로 돌아가는 데에 필요한 되걸음쇠 타수
var abbriviation_processing_state = 0; // 줄임말 처리를 하고 있는지
var ohiStatus = document.createElement('div');
var ohiTimeout = 0;
var Hangeul_SignExtKey1 = 0; // 공병우 세벌식 자판의 첫째 기호 확장 글쇠 누른 횟수, 신세벌 확장 기호 상태
var Hangeul_SignExtKey2 = 0; // 공병우 세벌식 자판의 두째 기호 확장 글쇠 누른 횟수
var onkeypress_skip = 0; // 오른쪽 숫자판을 눌렀을 때 ohiKeypress() 처리를 건너뛰기
var onkeyup_skip = 0; // ohiKeypress() 처리를 건너뛰기
var shift_lock = 0; // 한글 타자기 받침 글쇠 눌린 상태
var shift_click = 0; // 배열표에서 윗글쇠 누른 상태
var shiftlock_click = 0; // 배열표에서 Shift Lock을 누른 상태
var browser = '', browser_ver = 0, nu = navigator.userAgent;
var dkey, ukey;
var pressed_keys = []; // 함께 눌려 있는 글쇠들의 값
var pressing_keys = 0; // 함께 눌려 있는 글쇠 수
var prev_phoneme = []; // 조합하고 있는 한글 낱내에 들어간 낱자들을 담는 배열 (글쇠 기준)
var prev_combined_phoneme = []; // 조합하고 있는 한글 낱내의 조합된 낱자들을 담는 배열
var prev_phoneme_R = []; // 조합하고 있는 낱자의 추가 정보를 담는 배열 (보기: 겹홀소리 조합용 홀소리인지, 받침 붙는 홀소리인지)
var hangeul_combination_table_default, hangeul_combination_table_full;
var ohiHangeul3_HanExtKey=0; // 한글 확장 글쇠가 눌린 상태
var ohi_cheos, ohi_ga, ohi_ggeut, ohi_hotbatchim; // OHI에서 쓰는 요즘한글 첫·가·끝 낱자
var unicode_CGG_hangeul_phoneme = [], unicode_cheos = [], unicode_ga = [], unicode_ggeut=[]; // 유니코드 한글 낱자, 유니코드 한글 첫·가·끝 낱자
var unicode_modern_cheos = [], unicode_modern_ga = [], unicode_modern_ggeut = []; // 유니코드 요즘한글 첫·가·끝 낱자
var compatibility_hangeul_phoneme = [], compatibility_cheos = [], compatibility_ga = [], compatibility_ggeut = []; // 유니코드 호환 자모
var basic_layouts=[], current_layout=[];
function browser_detect() {
var trident=navigator.userAgent.match(/Trident\/(\d\.\d)/i);
var trident_ver = trident===undefined || !trident ? 0 : parseFloat(trident[1]);
if(nu.indexOf('MSIE')>=0 || trident_ver>=7) {
browser = "MSIE";
if(trident_ver<7) {
browser_ver = parseFloat(nu.substring(nu.indexOf("MSIE ")+5));
}
else if(trident_ver==7) {
browser_ver=11;
}
}
else if(nu.indexOf('Firefox') != -1) {
browser = "Firefox";
browser_ver = parseFloat(nu.substring(nu.indexOf('Firefox/')+8));
}
else if(nu.indexOf('Chrome') != -1) {
browser = "Chrome";
browser_ver = parseFloat(nu.substring(nu.indexOf('Chrome/')+7));
}
}
function ohiBackspace(f,opt) { // backspace 글쇠를 누르지 않았을 때에 backspace 동작을 하게 함
if(document.selection && browser=='MSIE' && browser_ver<9) {
var s=document.selection.createRange();
s.moveStart('character', -f.value.length);
var pos = s.text.length;
if(f.setSelectionRange) {
f.setSelectionRange(pos-1,pos);
f.text='';
}
else if(f.createTextRange) {
var range = f.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos-1);
range.select();
range.text = '';
}
}
else {
var bs_start = f.selectionStart;
var bs_end = f.selectionEnd;
if(bs_start == bs_end) {
f.value = f.value.substr(0,bs_start-1)+f.value.substr(bs_end);
f.selectionStart=f.selectionEnd=bs_start-1;
}
else {
f.value = f.value.substr(0,bs_start)+f.value.substr(bs_end);
f.selectionStart=f.selectionEnd=bs_start;
}
}
if(typeof opt == 'undefined' || !opt) ohiInsert(f,0,0);
}
function ohiHangeul_moa_backspace(f,e) {
var i;
if(!backspaces_for_restoring_prev_state) {
if(ohiHangeul_backspace(f,e)) ohiBackspace(f);
}
else {
while(backspaces_for_restoring_prev_state--) {
if(ohiHangeul_backspace(f,e)) ohiBackspace(f);
}
backspaces_for_restoring_prev_state=0;
}
esc_ext_layout();
return 0;
}
function ohiHangeul_backspace(f,e) {
var i,j;
var KE=ohi_KE;
// Backspace (세벌식 기호 확장 배열 상태일 때)
if(option.enable_sign_ext && Hangeul_SignExtKey1+Hangeul_SignExtKey2) {
if(e.preventDefault) e.preventDefault();
if(Ko_type.substr(0,4)=='Sin3') ohiBackspace(f);
esc_ext_layout();
return false;
}
if(ohiQ[1] || ohiQ[4] || ohiQ[0]&&ohiQ[3]) { // Backspace (요즘한글 조합 상태)
if(e.preventDefault) e.preventDefault();
for(i=8; !ohiQ[i];) i--;
ohiInsert(f,ohiQ[i]=0,ohiQ);
ohiRQ[i]=0;
esc_ext_layout();
return false;
}
if(KE=='Ko' && prev_phoneme.length) { // 첫가끝 조합 상태
if(!ohiHangeul3_HanExtKey) {
if(e.preventDefault) e.preventDefault();
ohiBackspace(f);
if(browser=="MSIE" && browser_ver<9 ) { // IE ~8
i=prev_combined_phoneme.length-1; while(i--) ohiBackspace(f);
}
var temp_prev_phoneme = prev_phoneme.slice(0);
var temp_prev_phoneme_R = prev_phoneme_R.slice(0);
prev_phoneme.splice(0);
prev_phoneme_R.splice(0);
prev_combined_phoneme.splice(0);
for(i=temp_prev_phoneme.length-1; i>=1; --i) {
CGG_yesHangeul(f,0,(temp_prev_phoneme_R[i] ? -1:1)*temp_prev_phoneme[i]);
}
}
if(!(Ko_type.substr(0,5)=='Sin3-' && option.enable_Sin3_yeshangeul_combination && typeof current_layout.extended_hangeul_combination_table != 'undefined') && Ko_type.substr(-2)!='-y') {
// 아래아 등이 지워졌을 때 첫가끝 코드 조합 상태에서 요즘한글(완성형) 코드로 바꾸기
for(i=0;i<prev_combined_phoneme.length;++i) {
if(unicode_cheos.indexOf(prev_combined_phoneme[i]) > ohi_cheos.length-1 || unicode_ga.indexOf(prev_combined_phoneme[i]) > ohi_ga.length-1 || unicode_ggeut.indexOf(prev_combined_phoneme[i]) > ohi_ggeut.length-1) break;
}
if(i==prev_combined_phoneme.length) { // 첫가끝 방식으로 조합하던 낱자들을 지우고 요즘한글 방식으로 첫소리만 넣기
if(e.preventDefault) e.preventDefault();
ohiBackspace(f);
if(browser=="MSIE" && browser_ver<9 ) {
i=prev_combined_phoneme.length-1; while(i--) ohiBackspace(f);
}
for(i=prev_combined_phoneme.length;i>=0;--i) {
if(unicode_cheos.indexOf(prev_combined_phoneme[i])>=0) {
ohiQ = backup_ohiQ.slice(0);
ohiRQ = backup_ohiRQ.slice(0);
ohiInsert(f,0,ohiQ);
break;
}
}
prev_phoneme.splice(0);
prev_phoneme_R.splice(0);
prev_combined_phoneme.splice(0);
}
}
else {
if(e.preventDefault) e.preventDefault();
}
esc_ext_layout();
return false;
}
return true;
}
function ohiDoubleJamo(a,c,d) {
var i, j=[ // Double Jamos
[ [1,7,18,21,24],1,7,18,21,24 ], // Cho
[ [39,44,49],[31,32,51],[35,36,51],51 ], // Jung
[ [1,4,9,18,21],[1,21],[24,30],[1,17,18,21,28,29,30],[0,21],21 ] // Jong
];
a=j[a];
for(i=a[0].length; c!=a[0][i-1]; i--) if(!i) return i;
for(a=a[i], i=a.length||1; 1; i--) if(!i || d==a || d==a[i-1]) return i;
}
function ohiInsert(f,m,c) { // Insert
if(!c) {
ohiQ = ohiRQ = [0,0,0,0,0,0,0,0,0];
return true;
}
if(c.length!=9) ohiQ = ohiRQ = [0,0,0,0,0,0,0,0,0];
else {
var m=m||'0,0,0,0,0,0,0,0,0', i=c[0]+c[1]+c[2], j=c[3]+c[4]+c[5], k=c[6]+c[7]+c[8];
c=i&&j?0xac00+(i-(i<3?1:i<5?2:i<10?4:i<20?11:12))*588+(j-31)*28+k-(k<8?0:k<19?1:k<25?2:3):0x3130+(i||j||k);
if(option.phonemic_writing && current_layout.type_name.substr(0,4)!='Sin3') {
// 풀어쓰기로 낱자 넣기
ohiInsert(f,0,32);
ohiBackspace(f);
c=0x3130+(i||j||k);
}
}
if(document.selection && browser=="MSIE" && browser_ver<10 ) { // IE ~9
var s=document.selection.createRange(), t=s.text;
if(t && document.selection.clear) document.selection.clear();
s.text=(m=='0,0,0,0,0,0,0,0,0'||c&&t.length>1?'':t.substr(0,t.length))+String.fromCharCode(c);
if(!c || !m || s.moveStart('character',-1)) {
s.select();
}
}
else if(f.selectionEnd+1) {
if(m!='0,0,0,0,0,0,0,0,0' && f.selectionEnd-f.selectionStart==1) f.selectionStart++;
var e=document.createEvent('KeyboardEvent');
if(e.initKeyEvent && !(browser=="Firefox" && browser_ver>=12 ) && browser!="Chrome") { // Gecko
e.initKeyEvent('keypress',0,0,null,0,0,0,0,127,c);
if(c && f.dispatchEvent(e) && m) f.selectionStart--;
} else { // Firefox 12~, Chrome
var scrollTop = f.scrollTop, scrollLeft = f.scrollLeft, selectionStart = f.selectionStart;
var endText = f.value.substr(f.selectionEnd,f.value.length);
f.value = f.value.substr(0,selectionStart)+String.fromCharCode(c);
var scrollHeight = f.scrollHeight, scrollWidth = f.scrollWidth;
f.value += endText;
if(c==13 && browser=='MSIE' && browser_ver==11 && !endText.length) {
// IE 11에서 뒤에 아무 문자 없을 때 줄을 바꾸면 한글 조합이 안 됨
f.value += String.fromCharCode(32);
}
f.scrollTop = (scrollTop > scrollHeight-f.clientHeight) ? scrollTop : scrollHeight-f.clientHeight;
f.scrollLeft = (scrollLeft > scrollWidth-f.clientWidth) ? scrollLeft : scrollWidth-f.clientWidth;
f.setSelectionRange(m || c<32 ? selectionStart:selectionStart+1, selectionStart+1);
}
}
}
function ohiSelection(f,length) {
if(document.selection && browser=="MSIE" && browser_ver<9) { // IE ~8
}
else if(f.selectionEnd+1) {
var e=document.createEvent('KeyboardEvent');
if(e.initKeyEvent && !(browser=="Firefox" && browser_ver>=12 ) && browser!="Chrome") { // Gecko
f.selectionStart-=length;
} else { // Firefox 12~, Chrome
f.selectionStart=f.selectionEnd-length;
}
}
}
function esc_ext_layout() {
var KE = ohi_KE;
if(ohiHangeul3_HanExtKey || Hangeul_SignExtKey1+Hangeul_SignExtKey2) {
if(KE=='Ko') {
Hangeul_SignExtKey1=Hangeul_SignExtKey2=0;
ohiHangeul3_HanExtKey=0;
show_keyboard_layout(Ko_type);
}
}
Hangeul_SignExtKey1=Hangeul_SignExtKey2=0;
ohiHangeul3_HanExtKey=0;
}
function combine_unicode_hangeul_phoneme(c1,c2) { // 유니코드 한글 낱자 조합하기
var i;
var combination_table;
var combined_phoneme;
if(typeof current_layout.moachigi_hangeul_combination_table != 'undefined' && typeof current_layout.hangeul_combination_table == 'undefined') {
// 모아치기 자판을 이어치기 방식으로 쓸 때
combination_table = current_layout.moachigi_hangeul_combination_table;
for(i=0; i<combination_table.length; ++i) {
if(combination_table[i].phonemes.length!=2) continue;
if(combination_table[i].phonemes.indexOf(c1)<0 || combination_table[i].phonemes.indexOf(c2)<0) continue;
if(c1==c2 && combination_table[i].phonemes[0]!=combination_table[i].phonemes[1]) continue;
combined_phoneme=combination_table[i].char;
break;
}
if(i==combination_table.length) return 0;
return combined_phoneme;
}
else {
// 이어치기 자판
combination_table=hangeul_combination_table_default;
if(current_layout.type_name.substr(-1)=='y') combination_table=hangeul_combination_table_full;
if(typeof current_layout.hangeul_combination_table != 'undefined' && typeof current_layout.hangeul_combination_table.length != 'undefined' && current_layout.hangeul_combination_table.length) {
// 일반 낱자 조합
combination_table = current_layout.hangeul_combination_table;
}
if(typeof current_layout.hangeul_convenience_combination_table != 'undefined' && option.convenience_combination) {
// 편의를 높이기 위한 낱자 조합을 더함
combination_table = combination_table.concat(current_layout.hangeul_convenience_combination_table);
}
if(option.enable_Sin3_yeshangeul_combination && Ko_type.substr(0,5)=='Sin3-') {
if(typeof current_layout.extended_hangeul_combination_table != 'undefined') {
// 신세벌식 옛한글 낱자 조합
combination_table = current_layout.extended_hangeul_combination_table;
}
}
var combined_phoneme=0x10000*c1+c2;
for(i=0; i<combination_table.length; ++i) {
if(combined_phoneme==combination_table[i][0]) {
combined_phoneme=combination_table[i][1];
break;
}
}
if(i==combination_table.length) return 0;
return combined_phoneme;
}
}
function complete_hangeul_syllable(f) { // 첫가끝 조합형 낱내를 유니코드 완성형 낱내로 바꿈
if(!prev_phoneme.length) return;
ohiSelection(f,0);
var i;
if(!option.only_CGG_encoding) {
if(unicode_modern_cheos.indexOf(prev_combined_phoneme[1])>=0 && unicode_modern_ga.indexOf(prev_combined_phoneme[0])>=0
|| unicode_modern_cheos.indexOf(prev_combined_phoneme[2])>=0 && unicode_modern_ga.indexOf(prev_combined_phoneme[1])>=0 && unicode_modern_ggeut.indexOf(prev_combined_phoneme[0])>=0) {
// 첫+가 또는 첫+가+끝
if(unicode_modern_cheos.indexOf(prev_combined_phoneme[1])>=0) {
i=2; while(i--) ohiBackspace(f);
ohiQ = [prev_combined_phoneme[1]-0x1100+11+(prev_combined_phoneme[1]>0x1108 ? 1:0),0,0,prev_combined_phoneme[0]-0x1161+31,0,0,0,0,0];
} else {
i=3; while(i--) ohiBackspace(f);
ohiQ = [prev_combined_phoneme[2]-0x1100+11+(prev_combined_phoneme[2]>0x1108 ? 1:0),0,0,prev_combined_phoneme[1]-0x1161+31,0,0,prev_combined_phoneme[0]-0x11A8+1+(prev_combined_phoneme[0]>0x11AE ? 1:0)+(prev_combined_phoneme[0]>0x11B8 ? 1:0)+(prev_combined_phoneme[0]>0x11BD ? 1:0),0,0];
}
ohiInsert(f,0,ohiQ);
}
}
prev_phoneme.splice(0);
prev_phoneme_R.splice(0);
prev_combined_phoneme.splice(0);
}
function convert_into_ohi_hangeul_phoneme(c) {
// 유니코드의 요즘한글 낱자 코드와 홀소리 호환 낱자 코드를 ohi에서 쓰는 코드로 바꾸기 (옛한글 낱자는 바꾸지 않음)
if(unicode_modern_cheos.indexOf(c)>=0) c=ohi_cheos[unicode_modern_cheos.indexOf(c)];
else if(unicode_modern_ga.indexOf(c)>=0) c=ohi_ga[unicode_modern_ga.indexOf(c)];
else if(unicode_modern_ggeut.indexOf(c)>=0) c=ohi_ggeut[unicode_modern_ggeut.indexOf(c)];
else if(compatibility_ga.indexOf(c)>=0) c=ohi_ga[compatibility_ga.indexOf(c)];
return c;
}
function convert_into_unicode_hangeul_phoneme(c) {
// ohi에서 쓰는 한글 낱자 코드를 유니코드로 바꾸기
if(ohi_cheos.indexOf(c)>=0) c=unicode_cheos[ohi_cheos.indexOf(c)];
else if(ohi_ga.indexOf(c)>=0) c=unicode_ga[ohi_ga.indexOf(c)];
else if(ohi_ggeut.indexOf(c)>=0) c=unicode_ggeut[ohi_ggeut.indexOf(c)];
return c;
}
function convert_into_compatibility_hangeul_phoneme(c) {
c=convert_into_unicode_hangeul_phoneme(c);
yeshangeul_cheos = [0x1140,0x114C,0x1159];
yeshangeul_ga = [0x119E];
yeshangeul_ggeut = [0x11EB,0x11F0,0x11F9];
compatibility_yeshangeul_dah = [0x317F,0x3181,0x3186]; // ㅿ,ㆁ,ㆆ
compatibility_yeshangeul_hol = [0x318D]; // ㆍ
if(unicode_modern_cheos.indexOf(c)>=0) {
c=compatibility_cheos[unicode_modern_cheos.indexOf(c)];
}
else if(unicode_modern_ga.indexOf(c)>=0) {
c=compatibility_ga[unicode_modern_ga.indexOf(c)];
}
else if(unicode_modern_ggeut.indexOf(c)>=0) {
c=compatibility_ggeut[unicode_modern_ggeut.indexOf(c)];
}
else if(yeshangeul_cheos.indexOf(c)>=0) {
c=compatibility_yeshangeul_dah[yeshangeul_cheos.indexOf(c)]
}
else if(yeshangeul_ga.indexOf(c)>=0) {
c=compatibility_yeshangeul_hol[yeshangeul_ga.indexOf(c)]
}
else if(yeshangeul_ggeut.indexOf(c)>=0) {
c=compatibility_yeshangeul_dah[yeshangeul_ggeut.indexOf(c)]
}
return c;
}
function no_shift(c) { // 윗글쇠를 누르지 않고 치는 글쇠인지
if(c==0x27) return 1;
else if(c<=0x2B) return 0;
else if(c<=0x39) return 1;
else if(c==0x3b || c==0x3d) return 1;
else if(c<=0x5a) return 0;
else if(c<=0x5d) return 1;
else if(c<=0x5f) return 0;
else if(c<=0x7a) return 1;
else if(c<=0x7e) return 0;
return 0;
}
function ohiRoman(f,e,c) { // Roman keyboard basic_layouts (Dvorak, Colemak)
if(En_type!='QWERTY') c=current_layout.layout[c-33];
ohiInsert(f,0,c);
}
function ohiHangeul2(f,e,c) { // 2-Beolsik
if((Ko_type.indexOf('KSX5002')>=0 || Ko_type=='KPS9256') && (c<65 || (c-1)%32>25)) {
ohiInsert(f,0,c);
return;
}
var cc;
if(typeof current_layout.layout != 'undefined') {
cc = convert_into_ohi_hangeul_phoneme(current_layout.layout[c-33]);
if(cc==current_layout.layout[c-33]) {
ohiInsert(f,0,cc);
return;
}
if(ohi_cheos.indexOf(cc)>=0) cc-=127;
else if(ohi_ga.indexOf(cc)>=0) cc-=35;
else if(ohi_ggeut.indexOf(cc)>=0) cc-=127;
}
else {
if(Ko_type.indexOf('KSX5002')>=0)
cc=[17,48,26,23,7,9,30,39,33,35,
31,51,49,44,32,36,18,1,4,
21,37,29,24,28,43,27][c%32-1];
else if(Ko_type=='2-KPS9256')
cc=[/*a*/24,/*b*/48,/*c*/26,/*d*/23,/*e*/7,/*f*/4,/*g*/21,/*h*/39,
/*i*/35,/*j*/31,/*k*/51,/*l*/49,/*m*/33,/*n*/43,/*o*/32,/*p*/36,
/*q*/18,/*r*/9,/*s*/1,/*t*/30,/*u*/44,/*v*/29,/*w*/17,/*x*/28,
/*y*/37,/*z*/27][c%32-1];
if(c>64 && c<91) {
// 한글 낱자가 든 글쇠를 윗글쇠와 함께 눌렀을 때
cc += cc==32||cc==36?2:cc==18||cc==7||cc==24||cc==1||cc==21?1:0;
}
}
if(cc<31) { // Jaum
if((!ohiQ[7] || !(ohiQ[0]=-1)) && ohiQ[3]) ohiQ[7]=ohiDoubleJamo(2,ohiQ[6],cc);
if(!ohiQ[3] || ohiQ[0]<0 || ohiQ[0] && (!ohiQ[6] || !ohiQ[7]) && (ohiQ[6] || cc==8 || cc==19 || cc==25))
ohiInsert(f,(ohiQ=ohiQ[1]||ohiQ[3]||!ohiDoubleJamo(0,ohiQ[0],cc)?ohiQ:0),ohiQ=[cc,ohiQ?0:1,0,0,0,0,0,0,0]);
else if(!ohiQ[0] && ohiQ[3]) {
// 닿소리 없이 홀소리가 들어왔고 닿소리가 눌렸을 때 새 낱내로 조합하기
ohiInsert(f,ohiQ,ohiQ);
ohiInsert(f,0,ohiQ=[cc,0,0,0,0,0,0,0,0]);
}
else if(!ohiQ[0] && (ohiQ[0]=cc) || (ohiQ[6]=ohiQ[6]||cc)) ohiInsert(f,0,ohiQ);
if(ohiQ[7]) ohiQ[7]=cc;
}
else { // Moum
if(option.sunalae || Ko_type.substr(0,5)=='2-sun') {
if(ohiQ[3]==cc && !ohiQ[1] && !ohiQ[6] && (ohiQ[0]==1 || ohiQ[0]==7 || ohiQ[0]==18 || ohiQ[0]==21 || ohiQ[0]==24)) {
// 홀소리 글쇠를 거듭 눌러 된소리 만들기
ohiQ[1]=1;
ohiInsert(f,0,ohiQ);
return;
}
}
if(option.sunalae || Ko_type.substr(0,5)=='2-sun' || Ko_type=='2-Gaon26KM') {
if((ohiQ[3]==37 || ohiQ[3]==33) && cc==51) {
// ㅕ+ㅣ→ㅖ, ㅑ+ㅣ→ㅒ
ohiQ[4]=1;
ohiInsert(f,0,ohiQ);
return;
}
}
if((!ohiQ[4] || ohiQ[6] || !(ohiQ[3]=-1)) && !ohiQ[6]) ohiQ[4]=ohiDoubleJamo(1,ohiQ[3],cc);
if((ohiQ[0] && ohiQ[3]>0 && ohiQ[6]) && (ohiQ[7] || !(ohiQ[7]=ohiQ[6]) || !(ohiQ[6]=0))) {
ohiInsert(f,0,[ohiQ[0],ohiQ[1],0,ohiQ[3],ohiQ[4],0,ohiQ[6],0,0]);
ohiInsert(f,ohiQ,ohiQ=[ohiQ[7],0,0,cc,0,0,0,0,0]);
}
else if((!ohiQ[0] || ohiQ[3]) && (!ohiQ[4] || ohiQ[6]) || ohiQ[3]<0) ohiInsert(f,ohiQ,ohiQ=[0,0,0,cc,0,0,0,0,0]);
else if(ohiQ[3]=ohiQ[3]||cc) ohiInsert(f,0,ohiQ);
}
}
function seek_abbreviation(ieochigi_abbreviation_table, c1, c2) { // 줄임말 조합을 찾기 (이어치기 자판)
var i;
var chars=null;
for(i=0; i<ieochigi_abbreviation_table.length; ++i) {
if(abbreviation_table[i].phonemes[0]==convert_into_unicode_hangeul_phoneme(c1) && ieochigi_abbreviation_table[i].phonemes[1]==convert_into_unicode_hangeul_phoneme(c2)) {
return ieochigi_abbreviation_table[i].chars;
}
}
return null;
}
function ohiHangeul3_abbreviation(f,e,c) { // 이어치기 세벌식 자판에서 줄임말 처리
if(!option.abbreviation || typeof current_layout.ieochigi_abbreviation_table == 'undefined') return 0;
var i,j;
var cc=current_layout.layout[c-33];
var ch, chars;
var ieochigi_abbreviation_table=null;
abbreviation_table = current_layout.ieochigi_abbreviation_table;
if(!abbreviation_table || !abbreviation_table.length) return 0;
if(!prev_phoneme.length) {
if(ohiQ[6]) ch=ohiQ[6]+ohiQ[7];
else if(ohiQ[3]) ch=ohiQ[3]+ohiQ[4]+35;
else if(ohiQ[0]) ch=ohiQ[0]+ohiQ[1]+127;
chars=seek_abbreviation(abbreviation_table, convert_into_unicode_hangeul_phoneme(ch), convert_into_unicode_hangeul_phoneme(cc));
if(chars) {
ohiBackspace(f);
insert_chars(f,chars);
return 1;
}
}
return 0;
}
function ohiHangeul3(f,e,c) { // 세벌식 자판 - 낱자 단위 처리
var i,j,cc=0,cc2=0;
var layout=current_layout.layout;
var sublayout=null;
var extended_sign_layout=null;
if(!abbriviation_processing_state) {
if(typeof current_layout.sublayout != 'undefined') sublayout = current_layout.sublayout;
if(typeof current_layout.extended_sign_layout != 'undefined') extended_sign_layout = current_layout.extended_sign_layout;
}
if(unicode_cheos.indexOf(c)>=0 || unicode_ga.indexOf(c)>=0 || unicode_ggeut.indexOf(c)>=0) {
// c가 유니코드 한글 낱자일 때
cc=c;
}
else if(layout) {
cc=layout[c-33];
cc2=layout[c-33-32]; // 윗글 자리
}
if(!cc) {
ohiInsert(f,0,0);
return 0;
}
if(cc>0 && cc<158 && !(option.enable_sign_ext && Hangeul_SignExtKey1+Hangeul_SignExtKey2 && extended_sign_layout)) {
// 아스키 영역의 영문자들을 한글 낱자로 처리하지 않고 그대로 넣기 위함 (기호 확장 배열을 쓰지 않을 때)
ohiInsert(f,0,cc);
return cc;
}
if(Ko_type.substr(-2)!='-y') {
// 요즘한글 자판일 때에 첫가끝 방식으로 처리하지 않게 함
cc=convert_into_ohi_hangeul_phoneme(cc);
cc2=convert_into_ohi_hangeul_phoneme(cc2);
}
if(!abbriviation_processing_state || Ko_type.substr(0,3)=='3m-') {
if(Ko_type.substr(0,1)=='3') {
if(Hangeul3_sign_ext(f,e,c)) return 0; // 기호 확장 배열
if(cc<0) return 0;
}
if(Ko_type.indexOf('Sin3')==0) { // 신세벌식 자판
if(Ko_type.substr(0,5)=='Sin3-') {
if(option.enable_Sin3_yeshangeul_combination && typeof current_layout.extended_hangeul_combination_table != 'undefined') {
cc=CGG_Hangeul_Sin3(f,e,c);
if(cc==-1) return 0;
CGG_yesHangeul(f,c,cc); // 첫가끝 조합형으로 옛한글 낱자 처리하기
return 0;
}
}
cc=Hangeul_Sin3(f,e,c);
if(cc==-1) return 0;
}
else if(Ko_type.substr(1,2)=='t-') { // 타자기 자판
cc=hangeul_typewriter(f,c);
if(cc<0) return 0;
}
if(Ko_type.substr(-1)!='y' && (ohiQ[3]==86-35) && !ohiQ[4] && !ohiQ[6] && no_shift(c) && cc==67 && cc2==69) {
// 요즘한글 배열에서 ㅣ가 들어간 뒤에 ㅐ가 눌렸을 때 ㅣ+ㅐ→ㅒ (ㅒ가 ㅐ의 윗글 자리에 있을 때만)
ohiQ[4]=ohiQ[3]-68;
ohiInsert(f,0,ohiQ);
return 1;
}
if(Ko_type.indexOf('_gm')>=0 || Ko_type.substr(0,3)=='3-P' || (Ko_type.substr(-2)!='-y' && Ko_type.substr(0,2)=='3-' && Number(Ko_type.substr(2,4))>=2014)) {
// 갈마들이 공세벌식 배열들을 위한 처리
cc=Hangeul_Gong3_gm(f,c);
if(cc<0) return 0;
}
if(Ko_type.substr(-2)!='-y' && !prev_phoneme.length && Ko_type.substr(1,2)!='t-' &&
(typeof current_layout.hangeul_combination_table != 'undefined' || typeof current_layout.moachigi_hangeul_combination_table != 'undefined' || typeof current_layout.hangeul_convenience_combination_table != 'undefined')
) {
// 옛한글 자판이 아니고 타자기 자판이 아닐 때 낱자 결합 규칙 적용하기
var ch;
if(ohiQ[6]) ch=ohiQ[6]+ohiQ[7];
else if(ohiQ[3]) ch=ohiQ[3]+ohiQ[4]+35;
else if(ohiQ[0]) ch=ohiQ[0]+ohiQ[1]+127;
ch=combine_unicode_hangeul_phoneme(convert_into_unicode_hangeul_phoneme(ch),convert_into_unicode_hangeul_phoneme(cc));
if(ch) {
if(ohiQ[6]) {
if(!ohiQ[7]) ohiQ[7]=convert_into_ohi_hangeul_phoneme(ch)-ohiQ[6];
else { // 3타로 넣는 받침이 들어갔을 때(순아래 2014 자판의 ㄹ+ㅁ+ㅁ→ㄿ, 이어치기 방식으로 쓰는 모아치기 자판)
ohiQ[8]=convert_into_ohi_hangeul_phoneme(ch)-(ohiQ[6]+ohiQ[7]);
}
}
else if(ohiQ[3]) {
if(!ohiQ[4]) ohiQ[4]=convert_into_ohi_hangeul_phoneme(ch)-ohiQ[3]-35;
else { // 3타로 넣는 홀소리가 들어갔을 때 (이어치기 방식으로 쓰는 모아치기 자판 ㅗ+ㅏ+ㅣ→ㅙ)
ohiQ[5]=convert_into_ohi_hangeul_phoneme(ch)-(ohiQ[3]+ohiQ[4])-35;
}
}
else {
if(!ohiQ[1]) ohiQ[1]=convert_into_ohi_hangeul_phoneme(ch)-ohiQ[0]-127;
else { // 3타로 넣는 첫소리가 들어갔을 때
ohiQ[2]=convert_into_ohi_hangeul_phoneme(ch)-(ohiQ[0]+ohiQ[1])-127;
}
}
ohiInsert(f,0,ohiQ);
return ch;
}
}
// 몇몇 공병우 세벌식 자판에서 첫소리만 들어간 채로 [ 자리 글쇠가 눌렸을 때 아래아를 넣음
if(Ko_type.substr(0,2)=='3-' && Ko_type!='3-sun1990' && Ko_type!='3-91_noshift') {
if(c==0x5B && ( (ohiQ[0]&&!ohiQ[3]&&!ohiQ[6] || unicode_cheos.indexOf(prev_combined_phoneme[0])>=0 ) || prev_combined_phoneme[0]==0x119E)) {
cc=0x119E;
}
}
// 3-91 조합 순아래 자판
if(Ko_type=='3-91_noshift') {
if(c==0x5B && ( (ohiQ[0]&&ohiQ[3]&&!ohiQ[6] || unicode_ga.indexOf(prev_combined_phoneme[0])>=0) )) {
// 첫소리와 가운뎃소리까지 들어간 채로 [ 자리 글쇠가 눌렸을 때
cc=0x11ff;
}
}
}
// 요즘한글 자판에 옛한글 낱자를 쓰는 변칙 낱자 조합
if(Ko_type.substr(-2)!='-y') {
if(unicode_ggeut.indexOf(cc)>=0 && unicode_modern_ggeut.indexOf(cc)<0) {
if(!ohiQ[6]) {
ohiQ[6]=cc;
return 1;
}
}
}
if(Ko_type.substr(0,4)=='Sin3' && option.phonemic_writing && !prev_phoneme.length) {
// 신세벌식 자판으로 풀어쓰기 처리
if( (ohiQ[3] || ohiQ[6]) && (cc>127 && cc<158 && cc!=147 || ohi_hangeul_phoneme.indexOf(cc)<0) ) {
convert_syllable_into_phoneme(f);
}
}
// 요즘한글 자판에서 옛한글 홀소리가 들어갔을 때
if(!prev_phoneme.length && Ko_type.substr(-1)!='y' && ohi_ga.indexOf(cc)<0 && unicode_ga.indexOf(cc)>=0) {
backup_ohiQ = ohiQ.slice(0);
backup_ohiRQ = ohiRQ.slice(0);
if(!ohiQ[0] && !ohiQ[3] && !ohiQ[6]) {
// 한글 조합 상태가 아니면 첫소리 채움 문자 넣음
prev_combined_phoneme.push(cc,0x115F);
ohiInsert(f,0,0x115F);
ohiInsert(f,0,prev_phoneme[0]);
ohiSelection(f,prev_combined_phoneme.length);
return 1;
}
if(ohiQ[0] && !ohiQ[3] && !ohiQ[6]) {
// 첫소리만 들어 있을 때
prev_phoneme.unshift(cc,unicode_cheos[ohi_cheos.indexOf(ohiQ[0]+ohiQ[1]+127)]);
prev_combined_phoneme.unshift(cc,unicode_cheos[ohi_cheos.indexOf(ohiQ[0]+ohiQ[1]+127)]);
ohiBackspace(f);
ohiInsert(f,0,prev_combined_phoneme[1]);
ohiInsert(f,0,prev_combined_phoneme[0]);
ohiSelection(f,prev_combined_phoneme.length);
return 1;
}
if(ohiQ[3] || ohiQ[6]) {
// 가운뎃소리나 끝소리가 들어 있을 때
prev_phoneme.push(cc);
prev_combined_phoneme.push(cc,0x115F);
ohiInsert(f,0,0x115F); // 첫소리 채움 문자 넣음
ohiInsert(f,0,cc);
ohiSelection(f,prev_combined_phoneme.length);
return 1;
}
}
// 요즘한글 자판으로 요즘한글 넣기
else if(cc>127 && cc<158 && cc!=147) { // Cho
if(prev_phoneme.length) {
ohiSelection(f,0);
prev_phoneme.splice(0);
prev_combined_phoneme.splice(0);
prev_phoneme_R.splice(0);
}
i=ohiQ[1]||ohiQ[3]||!ohiDoubleJamo(0,ohiQ[0],cc-127);
if(!i) ohiQ=0;
ohiInsert(f,i,ohiQ=[cc-127,ohiQ?0:1,0,0,0,0,0,0,0]);
return i;
}
else if(!prev_phoneme.length && cc>65 && cc<87) { // Jung
if((!ohiQ[4] || !(ohiQ[3]=-1)) && !(Ko_type.substr(1,2)=='t-' && ohiRQ[3]+ohiRQ[4]>1)) {
ohiQ[4]=ohiDoubleJamo(1,ohiQ[3],cc-35);
i=1;
}
else i=0;
if((!ohiQ[0] || ohiQ[3]) && (!ohiQ[4] || ohiQ[6]) || ohiQ[3]<0) {
ohiInsert(f,ohiQ,ohiQ=[0,0,0,cc-35,0,0,0,0,0]);
i=0;
}
else if(ohiQ[3]=ohiQ[3]||cc-35) {
ohiInsert(f,0,ohiQ);
i=1;
}
return i;
}
else if(!prev_phoneme.length && cc<31) { // Jong
i=0;
if(!current_layout.hangeul_combination_table && (!ohiQ[7] || !(ohiQ[6]=-1))) {
ohiQ[7]=ohiDoubleJamo(2,ohiQ[6],cc);
if(ohiQ[7]) i=1;
}
if(!ohiQ[0] || !ohiQ[3] || ohiQ[6] && !ohiQ[7] || ohiQ[6]<0 || (Ko_type.substr(0,3)=='4t-' && ohiRQ[3]+ohiRQ[4]>0)) {
ohiInsert(f,ohiQ,ohiQ=[0,0,0,0,0,0,cc,0,0]);
i=0;
}
else if(ohiQ[6]=ohiQ[6]||cc) {
ohiInsert(f,0,ohiQ);
i=1;
}
return i;
}
if(Ko_type.substr(-1)=='y' || prev_phoneme.length) {
CGG_yesHangeul(f,c,cc); // 옛한글 자판
}
else {
ohiInsert(f,0,cc);
}
return 0;
}
function convert_syllable_into_phoneme(f) {
backup_ohiQ = ohiQ.slice(0);
ohiInsert(f,0,0);
ohiBackspace(f);
if(backup_ohiQ[0]) ohiInsert(f,0,0x3130+backup_ohiQ[0]+backup_ohiQ[1]+backup_ohiQ[2]);
if(backup_ohiQ[3]) ohiInsert(f,0,0x3130+backup_ohiQ[3]+backup_ohiQ[4]+backup_ohiQ[5]);
if(backup_ohiQ[6]) ohiInsert(f,0,0x3130+backup_ohiQ[6]+backup_ohiQ[7]+backup_ohiQ[8]);
}
function ohiHangeul3_moa(f,e) { // 모아치기 세벌식 자판 처리
var i,j,k,l,m;
var c;
var layout=current_layout.layout;
var extended_sign_layout;
var combination_table;
var pressed_chars = [];
var temp_pressed_chars = [];
var special_keys = [32,13,8]; // 사이띄개, 줄바꾸개, 뒷걸음쇠
var chars=[];
var cheos = [], ga = [], ggeut = [];
var front_etc = [], rear_etc = [];
var front_special = [], rear_special = [];
var necessary_backspaces_cheos=0;
var necessary_backspaces_ga=0;
var necessary_backspaces_ggeut=0;
var necessary_backspaces_sign=0;
for(i=0;i<pressed_keys.length;++i) {
if(special_keys.indexOf(pressed_keys[i])>=0) {
if(!i) front_special.push(pressed_keys[0]);
else rear_special.push(pressed_keys[i]);
pressed_keys.splice(i,1);
}
else pressed_chars.push(convert_into_unicode_hangeul_phoneme(layout[pressed_keys[i]-33]));
}
if(option.enable_sign_ext && typeof current_layout.extended_sign_layout != 'undefined' && Hangeul_SignExtKey1) {
// 기호 확장 배열에서 기호를 넣음
if(pressed_keys.length==1 && Hangeul3_sign_ext(f,e,pressed_keys[0])) return;
if(pressed_keys.length>1) esc_ext_layout();
}
if(typeof current_layout.multikey_abbreviation_table != 'undefined') {
// 여러 글쇠를 누르는 줄여넣기, 예외 조합
combination_table = current_layout.multikey_abbreviation_table;
for(i=0;i<combination_table.length;++i) {
if(pressed_keys.length != combination_table[i].keys.length ) continue;
for(j=0;j<combination_table[i].keys.length;++j) {
if(pressed_keys.indexOf(combination_table[i].keys[j].charCodeAt(0))<0) break;
}
if(j!=combination_table[i].keys.length) continue;
insert_chars(f,combination_table[i].chars);
return;
}
}
if(typeof current_layout.moachigi_abbreviation_table != 'undefined') {
// 모아치기 한글 낱자 줄여넣기 규칙
combination_table = current_layout.moachigi_abbreviation_table;
for(i=0;i<combination_table.length;++i) {
if(pressed_chars.length != combination_table[i].phonemes.length) continue;
for(j=0;j<combination_table[i].phonemes.length;++j) {
if(pressed_chars.indexOf(combination_table[i].phonemes[j])<0) break;
}
if(j!=combination_table[i].phonemes.length) continue;
insert_chars(f,combination_table[i].chars);
return;
}
}
if(typeof current_layout.moachigi_hangeul_combination_table != 'undefined') {
// 모아치기 한글 낱자 조합 규칙 (낱자 차례를 따지지 않음)
combination_table = current_layout.moachigi_hangeul_combination_table;
for(i=0;i<combination_table.length;++i) {
temp_pressed_chars = pressed_chars.slice(0);
for(j=0;j<combination_table[i].phonemes.length;++j) {
k=temp_pressed_chars.indexOf(combination_table[i].phonemes[j]);
if(k<0) break;
temp_pressed_chars.splice(k,1);
}
if(j!=combination_table[i].phonemes.length) continue;
chars.push(combination_table[i].char);