4 * Copyright (C) 2002-2006 Changwoo Ryu
5 * Author: Changwoo Ryu <cwryu@debian.org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 /* See 3.12 "Conjoining Jamo Behavior" in the Unicode Book for more
27 /* The start of the Hangul Syllables (U+AC00-U+D7A3) */
31 /* The starts/ends of the leading consonants (choseong), the vowels
32 * (jungseong) and the trailing consonants (jongseong).
41 /* Number of modern jamos */
45 #define NCOUNT (VCOUNT * TCOUNT) /* number of syllables of a given choseong */
47 /* choseong and jungseong filler */
58 #define IS_JAMO(wc) ((wc) >= LBASE && (wc) <= TEND)
59 #define IS_L(wc) ((wc) >= LBASE && (wc) <= LEND)
60 #define IS_V(wc) ((wc) >= VFILL && (wc) <= VEND)
61 #define IS_T(wc) ((wc) > TBASE && (wc) <= TEND)
62 #define IS_M(wc) ((wc) == HTONE1 || (wc) == HTONE2)
63 #define IS_S(wc) (SBASE <= (wc) && (wc) < (SBASE + SCOUNT))
65 /* jamo which can be composited as a precomposed syllable */
66 #define IS_L_S(wc) ((wc) >= LBASE && (wc) < (LBASE + LCOUNT))
67 #define IS_V_S(wc) ((wc) >= VBASE && (wc) < (VBASE + VCOUNT))
68 #define IS_T_S(wc) ((wc) > TBASE && (wc) < (TBASE + TCOUNT))
70 /* if a syllable has a jongseong */
71 #define S_HAS_T(s) (((s) - SBASE) % TCOUNT)
74 #define IS_HANGUL(wc) (IS_S(wc) || IS_JAMO(wc) || IS_M(wc))
76 /* syllable boundary condition */
77 #define IS_BOUNDARY(prev,next) \
78 ((!IS_L(prev) && IS_S(wc)) || \
80 (IS_S(prev) && S_HAS_T(prev) && IS_L(next)) || \
81 (IS_T(prev) && (IS_L(next) || IS_V(next))) || \
82 (IS_S(prev) && !S_HAS_T(prev) && IS_L(next)) || \
83 (IS_V(prev) && IS_L(next)) || \
86 /* composing/decomposing */
87 #define S_FROM_LVT(l,v,t) (SBASE + (((l) - LBASE) * VCOUNT + ((v) - VBASE)) * TCOUNT + ((t) - TBASE))
88 #define S_FROM_LV(l,v) (SBASE + (((l) - LBASE) * VCOUNT + ((v) - VBASE)) * TCOUNT)
89 #define L_FROM_S(s) (LBASE + (((s) - SBASE) / NCOUNT))
90 #define V_FROM_S(s) (VBASE + (((s) - SBASE) % NCOUNT) / TCOUNT)
91 #define T_FROM_S(s) (TBASE + (((s) - SBASE) % TCOUNT))