*** empty log message ***
[m17n/m17n-db.git] / FLT / KHMR-OTF.flt
1 ;; KHMR-OTF.flt -- Font Layout Table for Khmer OpenType fonts
2 ;; Copyright (C) 2005, 2007
3 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
4 ;;   Registration Number H15PRO112
5
6 ;; This file is part of the m17n database; a sub-part of the m17n
7 ;; library.
8
9 ;; The m17n library is free software; you can redistribute it and/or
10 ;; modify it under the terms of the GNU Lesser General Public License
11 ;; as published by the Free Software Foundation; either version 2.1 of
12 ;; the License, or (at your option) any later version.
13
14 ;; The m17n library is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 ;; Lesser General Public License for more details.
18
19 ;; You should have received a copy of the GNU Lesser General Public
20 ;; License along with the m17n library; if not, write to the Free
21 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
23
24 ;;; <li> KHMR-OTF.flt
25 ;;;
26 ;;; For Khmer OpenType fonts to draw Khmer.
27 ;;; A Font is available from 
28 ;;; <http://www.khmeros.info/drupal/?q=en/download/fonts>.
29
30 (font layouter khmr-otf nil
31       (font (nil nil unicode-bmp :otf=khmr=pres)))
32
33 (category
34  (0x1780 0x17FF ?E)                     ; E: else
35  (0x19E0 0x19FF ?E)
36  (0x1780 0x17B3 ?C)                     ; C: consonant & independent vowel
37  (0x179A        ?R)                     ; R: RO
38  (0x17B6        ?p)                     ; p: vowel sign (post)
39  (0x17B7 0x17BA ?a)                     ; a: vowel sign (above)
40  (0x17BB 0x17BD ?b)                     ; b: vowel sign (below)
41  (0x17BE        ?A)                     ; A: vowel sign (two-part, above)
42  (0x17BF 0x17C0 ?P)                     ; P: vowel sign (two-part, post)
43  (0x17C1 0x17C3 ?m)                     ; m: vowel sign (pre)
44  (0x17C4 0x17C5 ?P)
45  (0x17C6        ?s)                     ; s: sign (above)
46  (0x17C7 0x17C8 ?S)                     ; S: sign (post)
47  (0x17C9 0x17CA ?c)                     ; c: consonant shifter
48  (0x17CB 0x17D1 ?s)
49  (0x17CC        ?r)                     ; r: ROBAT
50  (0x17D2        ?H)                     ; H: COENG
51  (0x17D3        ?s)
52  (0x17DD        ?s)
53  (0x200C        ?N)                     ; N: ZERO WIDTH NON-JOINER
54  (0x200D        ?J)                     ; J: ZERO WIDTH JOINER
55  )
56
57 ;; Generic syllable pattern is as follows.
58 ;; [CR](r|N?c)?(HCr?)*(HR)?(HCr?)*[NJ]?(m|b|a|A|p|P)?s*S?(H[CR])?
59
60 ;; Step 0.
61 ;; Move m to the beginning.
62 ;; Split A and P.
63 ;; Exchange the order of pP and s.
64 ;; Move HR before the base.
65
66 (generator
67  (0
68   (cond
69
70    ;; pre vowel sign
71    ;;1    2       3       4  5     67            8  9    10
72    ("([CR](r|N?c)?(HCr?)*)(HR(r)?)?((HCr?)*[NJ]?)(m)(s*S?(H[CR])?)"
73     < | (8 =) (4 = =) (1 = *) (5 =) (6 = *) (9 = *) | > )
74
75    ;; two-part above vowel sign
76    ;;1    2       3       4  5     67                8
77    ("([CR](r|N?c)?(HCr?)*)(HR(r)?)?((HCr?)*[NJ]?As*S?(H[CR])?)"
78     < | 0x17C1 (4 = =) (1 = *) (5 =) (6 = *) | > )
79
80    ;; post vowel sign
81    ;;1    2       3       4  5     67            8  9   10 11
82    ("([CR](r|N?c)?(HCr?)*)(HR(r)?)?((HCr?)*[NJ]?)(p)(s*)(S?(H[CR])?)"
83     < | (4 = =) (1 = *) (5 =) (6 = *) (9 = *) (8 =) (10 = *) | > )
84
85    ;; two-part post vowel sign
86    ;;1    2       3       4  5     67            8  9   10 11
87    ("([CR](r|N?c)?(HCr?)*)(HR(r)?)?((HCr?)*[NJ]?)(P)(s*)(S?(H[CR])?)"
88     < | 0x17C1 (4 = =) (1 = *) (5 =) (6 = *) (9 = *) (8 =) (10 = *) | > )
89
90    ;; other vowel signs or no vowel sign
91    ;;1    2       3       4  5     67                     8
92    ("([CR](r|N?c)?(HCr?)*)(HR(r)?)?((HCr?)*[NJ]?[b|a]?s*S?(H[CR])?)"
93     < | (4 = =) (1 = *) (5 =) (6 = *) | > )
94
95    ("." =))
96   *))
97
98 ;; Now a syllable looks like below.
99 ;; m?(HR)?[CR](r|N?c)?(HCr?)*[NJ]?(b|a|A)?s*(p|P)?S?(H[CR])?
100
101 ;; Step 1.
102 ;; Set the form of consonant shifter.
103
104 (generator
105  (0
106   (cond
107    ;; shifter + above vowel sign without ZWNJ
108    ;; Shifter take blwf.  HR takes pref.  HC's take blwf or pstf.
109    ;; 1   2    3     4      5     6     7     8
110    (" (m)?(HR)?([CR]c(HCr?)*(N|J)?(a|A))(s*S?)(H[CR])? "
111     |
112     (1 =)
113     (2 otf:khmr=pref+)
114     (3 otf:khmr=blwf,abvf,pstf+)
115     (7 = *)
116     (8 otf:khmr=blwf,pstf+)
117     | )
118
119    ;; shifter + ZWNJ + above vowel sign, or, shifter without above vowel sign
120    ;; Shifter stays above.  HR takes pref.  HC's take blwf or pstf.
121    ;; 1   2    3        45       6           7   8     9   10  11
122    (" (m)?(HR)?([CR]N?c)((HCr?)*)([NJ]?[ba]?)(A)?(s*p?)(P)?(S)?(H[CR])? "
123     |
124     (1 =)
125     (2 otf:khmr=pref+)
126     (3 = *)
127     (4 otf:khmr=blwf,pstf+)
128     (6 = *)
129     (7 otf:khmr=abvf+)
130     (8 = *)
131     (9 otf:khmr=pstf+)
132     (10 =)
133     (11 otf:khmr=blwf,pstf+)
134     | )
135
136    ;; no shifter
137    ;; 1   2    3       45       6           7   8     9   10  11
138    (" (m)?(HR)?([CR]r?)((HCr?)*)([NJ]?[ba]?)(A)?(s*p?)(P)?(S)?(H[CR])? "
139     |
140     (1 =)
141     (2 otf:khmr=pref+)
142     (3 = *)
143     (4 otf:khmr=blwf,pstf+)
144     (6 = *)
145     (7 otf:khmr=abvf+)
146     (8 = *)
147     (9 otf:khmr=pstf+)
148     (10 =)
149     (11 otf:khmr=blwf,pstf+)
150     | )
151
152    ("." =))
153   *))
154
155 ;; Now a syllable looks like below.  ~ characters are OTF feature applied.
156 ;; m?(HR)?[CR](r|c)?(HCr?)*[NJ]?(b|a|A)?s*(p|P)?S?(H[CR])?
157 ;;    ~~   ~~    ~   ~~~~            ~       ~     ~~~~~
158
159 ;; Step 2.
160 ;; Concatenate adjacent Khmer syllables.
161 ;; Remove J.  Retain N to prevent ligature.
162
163 (generator
164  (0
165   (cond
166    ("  ")
167    ("J")
168    ("." =))
169   *))
170
171 ;; Step 3.
172 ;; Apply other OTF features.
173
174 (generator
175  (0
176   (cond
177    (" ([^ ]*) "
178     (1 otf:khmr=pres,blws,abvs,psts,clig))
179    ("."
180     [ otf:khmr=+ ]))
181   *))
182
183 ;; Step 4.
184 ;; Remove N to clean up.
185 (generator
186  (0
187   (cond
188    ("N")
189    ("." =))
190   *))
191
192 ;; Local Variables:
193 ;; mode: emacs-lisp
194 ;; End: