(state:state-LVT-or-LVTL): Add backspace branch.
[m17n/m17n-db.git] / FLT / BENG-OTF.flt
1 ;; BENG-OTF.flt -- Font Layout Table for Bengali OpenType fonts
2 ;; Copyright (C) 2004, 2007, 2010 AIST (H15PRO112)
3 ;; See the end for copying conditions.
4
5 (font layouter beng-otf nil
6       (version "1.6.0")
7       (font (nil nil unicode-bmp :otf=beng)))
8
9 ;;; <li> BENG-OTF.flt
10 ;;;
11 ;;; For Bengali OpenType fonts to draw the Bengali script.  
12
13 ;; After-base glyph order for rendering:
14 ;; 1. below form consonants
15 ;; 2. below matra
16 ;; 3. reph
17 ;; 4. candrabindu (0981)
18 ;; 5. post form consonants
19 ;; 6. post matra
20 ;; 7. anusvara (0982) and visarga (0983)
21
22 (category
23  ;; X: generic
24  ;; V: independent vowel
25  ;; C: consonant
26  ;; B: BA
27  ;; Y: YA
28  ;; R: RA
29  ;; T: KHANDA TA
30  ;; n: NUKTA
31  ;; H: HALANT
32  ;; m: vowel sign (pre)
33  ;; b: vowel sign (below)
34  ;; p: vowel sign (post)
35  ;; a: vowel modifier (above)
36  ;; A: vowel modifier (post)
37  ;; N: ZWNJ
38  ;; J: ZWJ
39  (0x0980 0x09FF ?X)                     ; generic
40  (0x0981        ?a)                     ; SIGN CANDRABINDU
41  (0x0982 0x0983 ?A)                     ; SIGN ANUSVARA .. VISARGA
42  (0x0985 0x0994 ?V)                     ; LETTER A .. AU
43  (0x0995 0x09B9 ?C)                     ; LETTER KA .. HA
44  (0x09AC        ?B)                     ; LETTER BA
45  (0x09AF        ?Y)                     ; LETTER YA
46  (0x09B0        ?R)                     ; LETTER RA
47  (0x09BC        ?n)                     ; SIGN NUKTA
48  (0x09BE        ?p)                     ; VOWEL SIGN AA
49  (0x09BF        ?m)                     ; VOWEL SIGN I
50  (0x09C0        ?p)                     ; VOWEL SIGN II
51  (0x09C1 0x09C4 ?b)                     ; VOWEL SIGN U .. RR
52  (0x09C7 0x09C8 ?m)                     ; VOWEL SIGN E .. AI
53  (0x09CD        ?H)                     ; SIGN VIRAMA
54  (0x09CE        ?T)                     ; LETTER KHANDA TA
55  (0x09D7        ?p)                     ; AU LENGTH MARK
56  (0x09DC 0x09DF ?C)                     ; LETTER RRA .. YYA
57  (0x09E0 0x09E1 ?V)                     ; LETTER VOCALIC RR, LL
58  (0x09E2 0x09E3 ?b)                     ; VOWEL SIGN L .. LL
59  (0x09F0        ?R)                     ; LETTER RA WITH MIDDLE DIAGONAL
60  (0x09F1        ?C)                     ; LETTER RA WITH LOWER DIAGONAL
61
62  (0x200C        ?N)                     ; ZWNJ
63  (0x200D        ?J)                     ; ZWJ
64  (0x25CC        ?X)                     ; DOTTED CIRCLE
65
66  (rphf          ?r)
67  (pstf          ?P)
68  )
69
70 ;; Stage 0
71 ;; Preprocessing
72 (generator
73  (0
74   (cond
75    ;; Decompose two-part vowel signs.
76    ((0x09CB)
77     0x09C7 0x09BE)
78    ((0x09CC)
79     0x09C7 0x09D7)
80
81    ;; Many fonts still do not have KHANDA-TA.
82    ((0x09CE)
83     (cond
84      ((font-facility 0x09CE) =)
85      (".+" 0x09A4 0x09CD 0x200D)))
86
87    ;; consonant + NUKTA
88    ((0x09A1 0x09BC)
89     0x09DC)
90    ((0x09A2 0x09BC)
91     0x09DD)
92    ((0x09AF 0x09BC)
93     0x09DF)
94
95    ("." =))
96   *))
97
98 ;; Stage 1
99 ;; Syllable identification
100 (generator
101  (0
102   (cond
103    ;; Syllables with an independent vowel
104    ("(RH)?(Vn?)((J?H[BYR])?m?b?p?n?a?A?)"
105     < | (1 = =) (2 :otf=beng=nukt+) (3 = *) | >)
106
107    ;; KHANDA-TA combines only with reph.
108    ("(RH)?(T)"
109     < (2 =) (1 :otf=beng=rphf+) >)
110
111    ;; Consonant-based syllables
112    ;;1        23                   4
113    ("([CBYR]n?((J?H|HJ?)[CBYR]n?)*)(H[NJ]?|m?([NJ]?b)?p?n?a?A?)"
114     < |
115     (cond
116      (".+HJ$" :otf=beng=nukt,akhn+)
117      ("(.+)(H)N?$" (1 :otf=beng=nukt,akhn+) (2 =) 0x200C)
118      (".+" :otf=beng=nukt,akhn+))
119     | >)
120
121    ;; Two-part vowel signs
122    ((0x09C7 0x09BE)
123     (cond
124      ((font-facility 0x25CC) < = 0x25CC = >)
125      (".+" [ 0x09CB ])))
126    ((0x09C7 0x09D7)
127     (cond
128      ((font-facility 0x25CC) < = 0x25CC = >)
129      (".+" [ 0x09CC ])))
130
131    ;; Combining marks are displayed with a DOTTED CIRCLE.
132    ("m"
133     (cond
134      ((font-facility 0x25CC) < = 0x25CC >)
135      ("." [ = ])))
136    ("[nHbpaA]"
137     (cond
138      ((font-facility 0x25CC) < 0x25CC = >)
139      ("." [ = ])))
140
141    ;; Isolated blwf and pstf are displayed with a DOTTED CIRCLE in the
142    ;; next stage.
143    ("(J)(H)([BYR])"
144     < | (1 =) (3 =) (2 =) | >)
145
146    ("." =))
147   *))
148
149 ;; Stage 2
150 ;; Reorder halant for blwf and pstf
151 (generator
152  (0
153   (cond
154    ;; Isolated blwf and pstf
155    (" J([BYR]H) "
156     (cond
157      ((font-facility 0x25CC) < 0x25CC (1 :otf=beng=blwf,pstf+) >)
158      (" J([BYR]H) " [ (1 :otf=beng=blwf,pstf+) ])))
159
160    ;; Syllables with an overt halant
161    (" (RHJ?)?([^ ]+)(HN) "
162     | (1 = *) (2 reorder) (3 = =) |)
163
164    ;; Syllables with a below matra
165    (" (RHJ?)?([^mbpaA ]*[^mbpaANJ ])(m?[NJ]?bp?n?a?A?) "
166     | (1 = *) (2 reorder) (3 = *) |)
167
168    ;; Other syllables
169    (" (RHJ?)?([^mbpaA ]+)(m?p?n?a?A?) "
170     | (1 = *) (2 reorder) (3 = *) |)
171
172    ("." =))
173   *)
174
175  (reorder
176   ("(.|.+([^YJ]|JY|HJ))((J?HY)*)$"
177    (1 reorder-BR *) (3 reorder-Y *)))
178  
179  ;; Unlike Devanagari and Gujarati, vattu in Bengali does not have a
180  ;; half form.  Therefore the sequence CHRHC can be safely reordered
181  ;; to CRHHC.  Same for CHBHC.
182  (reorder-BR
183   (cond
184    ("J?(H)([BR])"
185     (2 =) (1 =))
186    ("." =)))
187
188  (reorder-Y
189   ("J?(H)(Y)"
190    (2 =) (1 =)))
191  )
192
193 ;; Stage 3
194 ;; Language forms and matra reordering
195 (generator
196  (0
197   (cond
198    ;; Overt halant forms
199    (" (RHJ?)?([^ ]+)(HN) "
200     |
201     (1 (cond ("RHJ" :otf=beng=half+)
202              ("RH" :otf=beng=rphf+)))
203     (2 b4post) (2 post) (3 = =) |)
204
205    ;; Syllables with a below matra
206    ;; 1      2              3     4         5
207    (" (RHJ?)?([^mb]*[^mbNJ])(mn?)?([NJ]?bn?)(p?n?a?A?) "
208     | (3 = *)
209     (1 (cond ("RHJ" :otf=beng=half+)
210              ("RH" :otf=beng=rphf+)))
211     (2 b4post) (4 = *) (2 post) (5 = *) |)
212
213    ;; Other syllables
214    ;; 1      2          3     4
215    (" (RHJ?)?([^mpaA ]*)(mn?)?(p?n?a?A?) "
216     | (3 = *)
217     (1 (cond ("RHJ" :otf=beng=half+)
218              ("RH" :otf=beng=rphf+)))
219     (2 b4post) (2 post) (4 = *) |)
220
221    ("." =))
222   *)
223
224  (b4post
225   (cond
226    ("(.H)J?(.*)"
227     (1 :otf=beng=half+)
228     (2 ("(.|.+([^YH]|JY|[BR]H))((YH)*)$" (1 lang-forms *))))
229    ("(.|.+([^YH]|JY|[BR]H))((YH)*)"
230     (1 lang-forms *))))
231
232  (lang-forms
233   (cond
234    ("(.H)J" (1 :otf=beng=half+))
235    (".H" :otf=beng=blwf,half,vatu+)
236    ("." =)))
237
238  (post
239   ("(.|.+([^YH]|JY|[BR]H))((YH)+)$"
240    (3 :otf=beng=pstf+)))
241  )
242
243 ;; Stage 4
244 ;; Final reordering #1 (Move pre-base matra after the last halant)
245 (generator
246  (0
247   (cond
248    ;; 1    2         3
249    (" (mn?)([^ ]+HJ?)([^H ]+) "
250     | (2 = *) (1 = *) (3 = *) |)
251
252    ("." =))
253   *))
254
255 ;; Stage 5
256 ;; Final reordering #2 (Move reph after the first halant)
257 (generator
258  (0
259   (cond
260    ;; Syllables with a reph and an explicit halant
261    ;; 1     2  3           4
262    (" (mn?)?(r)([^HP ]+HJ?)([^ ]*) "
263     | (1 = *) (3 = *) (2 =) (4 = *) |)
264
265    ;; A reph without explicit halant
266    ;; 1     2  3          4
267    (" (mn?)?(r)([^PpaA ]+)(P*(HN)?p?n?a?A?) "
268     | (1 = *) (3 = *) (2 =) (4 = *) |)
269
270    ("." =))
271   *))
272
273 ;; Stage 6
274 ;; Nukta for matra and Presentation forms
275 (generator
276  (0
277   (cond
278    (" (mn?)?([^ ]+) "
279     | (1 :otf=beng=nukt,init+) (2 :otf=beng=nukt,pres,abvs,blws,psts,haln+) |)
280
281    ("." =))
282   *))
283
284 ;; Stage 7
285 ;; Remove ZWNJ/ZWJ
286 (generator
287  (0
288   (cond
289    ("[NJ]")
290
291    ("." =))
292   *))
293
294 ;; Stage 8
295 ;; GPOS processing
296 (generator
297  (0
298   (cond
299    (" ([^ ]+) "
300     (1 :otf=beng=+abvm,blwm,dist))
301
302    ("." =))
303   *))
304
305 ;; Copyright (C) 2004, 2007, 2010
306 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
307 ;;   Registration Number H15PRO112
308
309 ;; This file is part of the m17n database; a sub-part of the m17n
310 ;; library.
311
312 ;; The m17n library is free software; you can redistribute it and/or
313 ;; modify it under the terms of the GNU Lesser General Public License
314 ;; as published by the Free Software Foundation; either version 2.1 of
315 ;; the License, or (at your option) any later version.
316
317 ;; The m17n library is distributed in the hope that it will be useful,
318 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
319 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
320 ;; Lesser General Public License for more details.
321
322 ;; You should have received a copy of the GNU Lesser General Public
323 ;; License along with the m17n library; if not, write to the Free
324 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
325 ;; Boston, MA 02110-1301, USA.
326
327 ;; Local Variables:
328 ;; mode: emacs-lisp
329 ;; End: