Specify GPOS order explicitly.
[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
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> MLYM-OTF.flt
25 ;;;
26 ;;; For Malayalam OpenType fonts to draw the reformed Malayalam script.
27
28 (font layouter mlym-otf nil
29       (font (nil nil unicode-bmp :otf=mlym=blwf)))
30
31 (category
32  ;; C: consonant (except for R, B, and P)
33  ;; R: consonant RA
34  ;; B: consonant (below)
35  ;; P: consonant (post)
36  ;; H: HALANT
37  ;; m: vowel sign (pre)
38  ;; p: vowel sign (post)
39  ;; A: vowel modifier (post)
40  ;; V: independent vowel
41  ;; N: ZWNJ (ZERO WIDTH NON-JOINER)
42  ;; J: ZWJ (ZERO WIDTH JOINER)
43  ;; X: generic
44  ;; Z: internal use
45  (0x0D00 0x0D7F ?X)                     ; generic
46  (0x0D00        ?Z)                     ; internal use
47  (0x0D02 0x0D03 ?A)                     ; SIGN ANUSVARA .. VISARGA
48  (0x0D05 0x0D14 ?V)                     ; LETTER A .. LETTER AU
49  (0x0D15 0x0D39 ?C)                     ; LETTER KA .. LETTER HA
50  (0x0D2F        ?P)                     ; LETTER YA
51  (0x0D30        ?R)                     ; LETTER RA
52  (0x0D32        ?B)                     ; LETTER LA
53  (0x0D35        ?P)                     ; LETTER VA
54  (0x0D3E 0x0D43 ?p)                     ; VOWEL SIGN AA .. VOCALIC R
55  (0x0D46 0x0D48 ?m)                     ; VOWEL SIGN E .. AI
56  (0x0D4D        ?H)                     ; SIGN VIRAMA
57  (0x0D57        ?p)                     ; AU LENGTH MARK
58  (0x0D60 0x0D61 ?V)                     ; LETTER VOCALIC RR .. VOCALIC LL
59  (0x0964 0x0965 ?X)                     ; DANDA .. DOUBLE DANDA
60  (0x200C        ?N)                     ; ZWNJ
61  (0x200D        ?J)                     ; ZWJ
62  )
63
64 ;; Decompose two-part vowels.
65 (generator
66  (0
67   (cond
68    ((0x0D4A)
69     0x0D46 0x0D3E)
70    ((0x0D4B)
71     0x0D47 0x0D3E)
72    ((0x0D4C)
73     0x0D46 0x0D57)
74    ("." =))
75   *))
76
77 ;; Syllable identification and reordering.  
78 ;; Put the mark 0x0D00 before the first pre-base consonant and after
79 ;; the base consonant.
80 (generator
81  (0
82   (cond
83    ;; A syllable with a left vowel sign.
84    ;;1      2          3  4
85    ("([CRBP](H[CRBP])*)(m)(p?A?)"
86     < | (3 =) (1 get-rh) 0x0D00 (1 move-h) (4 = *) | >)
87
88    ;; A syllable with a right vowel sign and/or a vowel modifier.
89    ;;1      2          3
90    ("([CRBP](H[CRBP])*)(pA?|A)"
91     < | (1 get-rh) 0x0D00 (1 move-h) (3 = *) | >)
92
93    ;; Explicit Halant / forced chillu form is cut off from the preceders.
94    ("(([CRBP]H)*)([CRBP]H[NJ])"
95     (1 cut-off) (3 < | = * | >))
96
97    ;; A syllable with no vowel signs/modifiers.
98    ("([CRBP](H[CRBP])*H?)"
99     < | (1 get-rh) 0x0D00 (1 move-h) | >)
100
101    ;; Starting with an independent vowel.
102    ("(VA?)"
103     < | (1 = *) | >)
104
105    ("." =))
106   *)
107
108  ;; Extract RH that will be moved to the left.
109  (get-rh
110   (cond
111    (".+HR$"
112     0x0D30 0x0D4D)))
113
114  ;; Move the halant after the base consonant to the end.
115  ;; Fill the resulting gap with 0x0D00.
116  ;; Remove final RH if any.
117  (move-h
118   (cond
119    ;; There is a C and the syllable ends with an R.  Remove final RH.
120    ("([CRBPH]*C)H([RBPH]*)R$"
121     (1 = *) 0x0D00 (2 = *))
122
123    ;; The syllable ends other than R.  Move H.
124    ("([CRBPH]*C)(H)([RBPH]+)$"
125     (1 = *) 0x0D00 (3 = *) (2 =))
126
127    ;; No C and end with R.  The first consonant will be the base.  Remove RH.
128    ("([RBP])H([RBPH]*)R$"
129     (1 =) 0x0D00 (2 = *))
130
131    ;; No C and not end with R.  Move H.
132    ("([RBP])(H)([RBPH]+)$"
133     (1 =) 0x0D00 (3 = *) (2 =))
134
135    ;; Otherwise, no need to move H.
136    (".+"
137     = * 0x0D00)))
138
139  ;; If there are some letters make them a separate syllable.
140  (cut-off
141   (cond
142    (".+"
143     < | = * | >)))
144  )
145
146 ;; Apply GSUB features.
147 ;; According to Microsoft Typography
148 ;; <http://www.microsoft.com/typography/otfntdev/malayot/features.htm>
149 ;; 'chillu' are generated with the 'haln' feature.  However, some
150 ;; fonts generate them with 'half'.
151 (generator
152  (0
153   (cond
154    ;; Ordinary syllable.  We must avoid applying 'blwf' and 'pstf' to
155    ;; the first consonant.  Also 'haln' and 'half' must be avoided
156    ;; because chillu does not appear at the beginning of a word.  Thus
157    ;; we apply only 'akhn' here and postpone applying other features
158    ;; to the next stage.
159    ;; 1  2      3         4  5
160    (" (m?(RH)?Z)([CRBPH]+)(Z)([RBPHpA]*) "
161     | (1 = *) (3 otf:mlym=akhn+) (4 =)
162     (5 otf:mlym=blwf,pstf+) |)
163
164    ;; Explicit Halant.
165    (" [CRBP]HN "
166     = *)
167
168    ;; Forced chillu form.
169    (" ([CRBP]H)(J) "
170     | (1 otf:mlym=haln,half+) (2 =) |)
171
172    ;; Sequence that was cut off from a forced form.  Again we apply
173    ;; only 'akhn' here.
174    (" ([CRBPH]+) "
175     | (1 otf:mlym=akhn+) |)
176
177    ("." =))
178   *))
179
180 ;; Apply postoponed GSUB features to ordinary syllables.
181 (generator
182  (0
183   (cond
184    ;; Ordinary syllable.
185    ;; 1  2          3      4 
186    (" (m?(RH)?Z[^Z])([^Z]*)(Z[^ ]*) "
187     | (1 = *) (3 otf:mlym=blwf,half,pstf,haln+) (4 = *) |)
188
189    ;; Explicit Halant / Forced chillu must not change to others.
190    (" (.+)[NJ] "
191     | (1 = *) |)
192
193    ;; Cut off sequence.
194    (" ([^ ])([^ ]*) "
195     | (1 =) (2 otf:mlym=blwf,half,pstf,haln+) |)
196
197    ("." =))
198   *))
199
200 ;; Second reordering.  If there are glyphs before the base, move left
201 ;; vowel sign and RH to the left of the base.
202 (generator
203  (0
204   (cond
205    ;; 1   2     3      4      5
206    (" (m)?(RH)?Z([^Z]*)([^Z])Z([^ ]*) "
207     | (3 = *) (1 =) (2 otf:mlym=pstf+) (4 =) (5 = *) |)
208
209    ("." =))
210   *))
211
212 ;; Apply substitutions and GPOS features.
213 (generator
214  (0
215   (cond
216    (" ([^ ]+) "
217     (1 otf:mlym=pres,abvs,blws,psts+abvm,blwm,dist))
218    ("."
219     [ = ]))
220   *))
221
222 ;; Local Variables:
223 ;; mode: emacs-lisp
224 ;; End: