Git init
[external/pango1.0.git] / modules / hangul / hangul-defs.h
1 /* Pango
2  * hangul-defs.h:
3  *
4  * Copyright (C) 2002-2006 Changwoo Ryu
5  * Author: Changwoo Ryu <cwryu@debian.org>
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 /* See 3.12 "Conjoining Jamo Behavior" in the Unicode Book for more
24  * information
25  */
26
27 /* The start of the Hangul Syllables (U+AC00-U+D7A3) */
28 #define SBASE 0xAC00
29 #define SCOUNT 11172
30
31 /* The starts/ends of the leading consonants (choseong), the vowels
32  * (jungseong) and the trailing consonants (jongseong).
33  */
34 #define LBASE 0x1100
35 #define VBASE 0x1161
36 #define TBASE 0x11A7
37 #define LEND 0x115F
38 #define VEND 0x11A7
39 #define TEND 0x11FF
40
41 /* Number of modern jamos */
42 #define LCOUNT 19
43 #define VCOUNT 21
44 #define TCOUNT 28
45 #define NCOUNT (VCOUNT * TCOUNT) /* number of syllables of a given choseong */
46
47 /* choseong and jungseong filler */
48 #define LFILL 0x115F
49 #define VFILL 0x1160
50
51 /* Old tone marks. */
52 #define HTONE1 0x302E
53 #define HTONE2 0x302F
54
55 /* Useful macros
56  */
57
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))
64
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))
69
70 /* if a syllable has a jongseong */
71 #define S_HAS_T(s) (((s) - SBASE) % TCOUNT)
72
73 /* non hangul */
74 #define IS_HANGUL(wc)   (IS_S(wc) || IS_JAMO(wc) || IS_M(wc))
75
76 /* syllable boundary condition */
77 #define IS_BOUNDARY(prev,next)                                  \
78         ((!IS_L(prev) && IS_S(wc)) ||                           \
79          !IS_HANGUL(next) ||                                    \
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)) ||                          \
84          IS_M(prev))
85
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))