Move 'pres' from Stage 6 to Stage 4.
[m17n/m17n-db.git] / FLT / MLYM-OTF.flt
1 ;; MLYM-OTF.flt -- Font Layout Table for Malayalam OpenType font
2 ;; Copyright (C) 2003, 2004, 2005, 2007, 2008  AIST (H15PRO112)
3 ;; See the end for copying conditions.
4
5 (font layouter mlym-otf nil
6       (font (nil nil unicode-bmp :otf=mlym=akhn)))
7
8 ;;; <li> MLYM-OTF.flt
9 ;;;
10 ;;; For Malayalam OpenType fonts to draw the reformed Malayalam script.
11
12 ;; Tested with the following fonts.  All of these fonts require Halant
13 ;; movement for syllable-final YA, LA and VA, but not for RA.
14
15 ;; AnjaliOldLipi.ttf
16 ;; Dyuthi3.ttf
17 ;; Kalyani121.ttf
18 ;; Meera_04.ttf
19 ;; Rachana_04.ttf
20 ;; RaghuMalayalamSans2.ttf
21 ;; suruma2.ttf
22
23 (category
24  ;; C: ordinary consonants (except P)
25  ;; P: consonants that have a post- or below-form
26  ;; H: HALANT
27  ;; m: vowel sign (pre)
28  ;; b: vowel sign (below)
29  ;; p: vowel sign (post)
30  ;; A: vowel modifier (post)
31  ;; V: independent vowel
32  ;; N: ZWNJ (ZERO WIDTH NON-JOINER)
33  ;; J: ZWJ (ZERO WIDTH JOINER)
34  ;; Z: internal use
35  ;; X: generic
36  (0x0D00 0x0D7F ?X)                     ; generic
37  (0x0D00        ?Z)                     ; internal use
38  (0x0D02 0x0D03 ?A)                     ; SIGN ANUSVARA .. VISARGA
39  (0x0D05 0x0D14 ?V)                     ; LETTER A .. AU
40  (0x0D15 0x0D39 ?C)                     ; LETTER KA .. HA
41  (0x0D2F        ?P)                     ; LETTER YA
42  (0x0D32        ?P)                     ; LETTER LA
43  (0x0D35        ?P)                     ; LETTER VA
44  (0x0D3E 0x0D44 ?p)                     ; VOWEL SIGN AA .. VOCALIC RR
45  (0x0D46 0x0D48 ?m)                     ; VOWEL SIGN E .. AI
46  (0x0D4D        ?H)                     ; SIGN VIRAMA
47  (0x0D57        ?p)                     ; AU LENGTH MARK
48  (0x0D60 0x0D61 ?V)                     ; LETTER VOCALIC RR .. VOCALIC LL
49  (0x0D62 0x0D63 ?b)                     ; VOWEL SIGN VOCALIC L .. LL
50  (0x0D7A 0x0D7F ?C)                     ; LETTER CHILLU NN .. K
51  (0x0964 0x0965 ?X)                     ; DANDA .. DOUBLE DANDA
52  (0x200C        ?N)                     ; ZWNJ
53  (0x200D        ?J)                     ; ZWJ
54  )
55
56 ;; Stage 0
57 ;; Decompose two-part vowels.
58 (generator
59  (0
60   (cond
61    ((0x0D4A)
62     0x0D46 0x0D3E)
63    ((0x0D4B)
64     0x0D47 0x0D3E)
65    ((0x0D4C)
66     0x0D46 0x0D57)
67    ("." =))
68   *))
69
70 ;; Stage 1
71 ;; Syllable identification and reordering.  
72 ;; Put the mark Z after the base consonant.
73 (generator
74  (0
75   (cond
76    ;; A syllable with a left vowel sign.
77    ;;1    2        3  4
78    ("([CP](H[CP])*)(m)(p?A?)"
79     < | (3 =) (1 move-h) (4 = *) | >)
80
81    ;; A syllable with a right vowel sign, a below vowel sign
82    ;; and/or a vowel modifier.
83    ;;1    2        3
84    ("([CP](H[CP])*)(bA?|pA?|A)"
85     < | (1 move-h) (3 = *) | >)
86
87    ;; Explicit Halant / forced chillu form is separated from the
88    ;; preceding characters.
89    ;;12        3
90    ("(([CP]H)*)([CP]H[NJ])"
91     (1 < | cut-off | >) (3 < | = * | >))
92
93    ;; A syllable with no vowel signs/modifiers.
94    ("[CP](H[CP])*H?"
95     < | (0 move-h) | >)
96
97    ;; Starting with an independent vowel.
98    ("VA?"
99     < | (0 = *) | >)
100
101    ("." =))
102   *)
103
104
105  ;; Move the halant that follows the base consonant to the end.
106  (move-h
107   (cond
108    ;; All consonants are P's.
109    ("(P)(H)([PH]*)$"
110     (1 =) 0x0D00 (3 = *) (2 =))
111
112    ;; One or more Non-P consonants.
113    ("([CPH]*C)(H)([PH]+)$"
114     (1 = *) 0x0D00 (3 = *) (2 =))
115
116    ;; Otherwise, final consonant is not P.  No need to move H.
117    (".+"
118     = * 0x0D00)))
119
120  ;; If there are some letters, make them a separate syllable.
121  (cut-off
122   (cond
123    ("[CP](H[CP])*H?"
124     (0 move-h))))
125  )
126
127 ;; Stage 2
128 ;; Apply 'akhn' feature.
129 (generator
130  (0
131   (cond
132    ;; Ordinary syllable.  We must avoid applying 'blwf' and 'pstf' to
133    ;; the first consonant if it is a P, but 'akhn' must be applied
134    ;; always.  Other GSUB features are applied in the following
135    ;; satges.
136
137    ;; 1   2       3  4
138    (" (m)?([CPH]*)(Z)([PHbpA]*) "
139     | (1 =) (2 otf:mlym=akhn+) (3 =) (4 otf:mlym=blwf,pstf+) |)
140
141    ("." =))
142   *))
143
144 ;; Stage 3
145 ;; Apply 'blwf' to non-initial glyphs.
146 (generator
147  (0
148   (cond
149    ;; 1       2       3
150    (" (m?[^Z])([^Z ]*)(Z[^ ]*) "
151     | (1 = *) (2 otf:mlym=blwf+) (3 = *) |)
152
153    ("." =))
154   *))
155
156 ;; Stage 4
157 ;; Apply other language forms and 'pres'.
158 (generator
159  (0
160   (cond
161    ;; All characters should have the 'half' form glyph, and 'pstf' is
162    ;; always applied after 'half'.  Thus we do not need to worry about
163    ;; applying 'pstf' to the first glyph.  Also 'pres' is applied here
164    ;; to form pre-base conjuncts.
165    ;; 1   2       3
166    (" (m)?([^Z ]*)(Z[^ ]*) "
167     | (1 = *) (2 otf:mlym=half,pstf,pres+) (3 = *) |)
168
169    ;; Explicit Halant.
170    (" ([CP]H)N "
171     | (1 = *) |)
172
173    ;; Forced chillu form.  According to Microsoft Typography
174    ;; <http://www.microsoft.com/typography/otfntdev/malayot/features.htm>
175    ;; 'chillu' glyphs are generated with the 'haln' feature.  However,
176    ;; some fonts generate them with 'half'.
177    (" ([CP]HJ) "
178     | (1 otf:mlym=haln,half+) |)
179
180    ("." =))
181   *))
182
183 ;; Stage 5
184 ;; Second reordering.  If there are glyphs before the base, move left
185 ;; vowel sign to the left of the base.
186 (generator
187  (0
188   (cond
189    ;; 1   2       3      4
190    (" (m)?([^Z ]*)([^Z])Z([^ ]*) "
191     | (2 = *) (1 =) (3 =) (4 = *) |)
192
193    ("." =))
194   *))
195
196 ;; Stage 6
197 ;; Apply remaining typographical forms, 'haln' and GPOS features.
198 (generator
199  (0
200   (cond
201    (" ([^ ]+) "
202     (1 otf:mlym=abvs,blws,psts,haln+abvm,blwm,dist))
203    ("."
204     [ = ]))
205   *))
206
207 ;; Copyright (C) 2003, 2004, 2005, 2007, 2008
208 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
209 ;;   Registration Number H15PRO112
210
211 ;; This file is part of the m17n database; a sub-part of the m17n
212 ;; library.
213
214 ;; The m17n library is free software; you can redistribute it and/or
215 ;; modify it under the terms of the GNU Lesser General Public License
216 ;; as published by the Free Software Foundation; either version 2.1 of
217 ;; the License, or (at your option) any later version.
218
219 ;; The m17n library is distributed in the hope that it will be useful,
220 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
221 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
222 ;; Lesser General Public License for more details.
223
224 ;; You should have received a copy of the GNU Lesser General Public
225 ;; License along with the m17n library; if not, write to the Free
226 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
227 ;; Boston, MA 02110-1301, USA.
228
229 ;; Local Variables:
230 ;; mode: emacs-lisp
231 ;; End: