(stage 0): Use font-facility to check KHANDA-TA's availability.
[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     < | (1 :otf=beng=nukt,akhn+)
115     (4 (cond ("HJ" = =)
116              ("(H)N?" (1 =) 0x200C)
117              (".+" = *))) | >)
118
119    ;; Two-part vowel signs
120    ((0x09C7 0x09BE)
121     (cond
122      ((font-facility 0x25CC) < = 0x25CC = >)
123      (".+" < 0x09CB >)))
124    ((0x09C7 0x09D7)
125     (cond
126      ((font-facility 0x25CC) < = 0x25CC = >)
127      (".+" < 0x09CC >)))
128
129    ;; Combining marks are displayed with a DOTTED CIRCLE.
130    ("m"
131     (cond
132      ((font-facility 0x25CC) < = 0x25CC >)
133      ("." [ = ])))
134    ("[nHbpaA]"
135     (cond
136      ((font-facility 0x25CC) < 0x25CC = >)
137      ("." [ = ])))
138
139    ;; Isolated blwf and pstf are displayed with a DOTTED CIRCLE in the
140    ;; next stage.
141    ("(J)(H)([BYR])"
142     < | (1 =) (3 =) (2 =) | >)
143
144    ("." =))
145   *))
146
147 ;; Stage 2
148 ;; Reorder halant for blwf and pstf
149 (generator
150  (0
151   (cond
152    ;; Isolated blwf and pstf
153    (" J([BYR]H) "
154     (cond
155      ((font-facility 0x25CC) < 0x25CC (1 :otf=beng=blwf,pstf+) >)
156      (" J([BYR]H) " [ (1 :otf=beng=blwf,pstf+) ])))
157
158    ;; Syllables with an overt halant
159    (" (RHJ?)?([^ ]+)(HN) "
160     | (1 = *) (2 reorder) (3 = =) |)
161
162    ;; Syllables with a below matra
163    (" (RHJ?)?([^mbpaA ]*[^mbpaANJ ])(m?[NJ]?bp?n?a?A?) "
164     | (1 = *) (2 reorder) (3 = *) |)
165
166    ;; Other syllables
167    (" (RHJ?)?([^mbpaA ]+)(m?p?n?a?A?) "
168     | (1 = *) (2 reorder) (3 = *) |)
169
170    ("." =))
171   *)
172
173  (reorder
174   ("(.|.+([^YJ]|JY|HJ))((J?HY)*)$"
175    (1 reorder-BR *) (3 reorder-Y *)))
176  
177  ;; Unlike Devanagari and Gujarati, vattu in Bengali does not have a
178  ;; half form.  Therefore the sequence CHRHC can be safely reordered
179  ;; to CRHHC.  Same for CHBHC.
180  (reorder-BR
181   (cond
182    ("J?(H)([BR])"
183     (2 =) (1 =))
184    ("." =)))
185
186  (reorder-Y
187   ("J?(H)(Y)"
188    (2 =) (1 =)))
189  )
190
191 ;; Stage 3
192 ;; Language forms and matra reordering
193 (generator
194  (0
195   (cond
196    ;; Overt halant forms
197    (" (RHJ?)?([^ ]+)(HN) "
198     |
199     (1 (cond ("RHJ" :otf=beng=half+)
200              ("RH" :otf=beng=rphf+)))
201     (2 b4post) (2 post) (3 = =) |)
202
203    ;; Syllables with a below matra
204    ;; 1      2              3     4         5
205    (" (RHJ?)?([^mb]*[^mbNJ])(mn?)?([NJ]?bn?)(p?n?a?A?) "
206     | (3 = *)
207     (1 (cond ("RHJ" :otf=beng=half+)
208              ("RH" :otf=beng=rphf+)))
209     (2 b4post) (4 = *) (2 post) (5 = *) |)
210
211    ;; Other syllables
212    ;; 1      2          3     4
213    (" (RHJ?)?([^mpaA ]*)(mn?)?(p?n?a?A?) "
214     | (3 = *)
215     (1 (cond ("RHJ" :otf=beng=half+)
216              ("RH" :otf=beng=rphf+)))
217     (2 b4post) (2 post) (4 = *) |)
218
219    ("." =))
220   *)
221
222  (b4post
223   (cond
224    ("(.H)J?(.*)"
225     (1 :otf=beng=half+)
226     (2 ("(.|.+([^YH]|JY|[BR]H))((YH)*)$" (1 lang-forms *))))
227    ("(.|.+([^YH]|JY|[BR]H))((YH)*)"
228     (1 lang-forms *))))
229
230  (lang-forms
231   (cond
232    ("(.H)J" (1 :otf=beng=half+))
233    (".H" :otf=beng=blwf,half,vatu+)
234    ("." =)))
235
236  (post
237   ("(.|.+([^YH]|JY|[BR]H))((YH)+)$"
238    (3 :otf=beng=pstf+)))
239  )
240
241 ;; Stage 4
242 ;; Final reordering #1 (Move pre-base matra after the last halant)
243 (generator
244  (0
245   (cond
246    ;; 1    2         3
247    (" (mn?)([^ ]+HJ?)([^H ]+) "
248     | (2 = *) (1 = *) (3 = *) |)
249
250    ("." =))
251   *))
252
253 ;; Stage 5
254 ;; Final reordering #2 (Move reph after the first halant)
255 (generator
256  (0
257   (cond
258    ;; Syllables with a reph and an explicit halant
259    ;; 1     2  3           4
260    (" (mn?)?(r)([^HP ]+HJ?)([^ ]*) "
261     | (1 = *) (3 = *) (2 =) (4 = *) |)
262
263    ;; A reph without explicit halant
264    ;; 1     2  3          4
265    (" (mn?)?(r)([^PpaA ]+)(P*(HN)?p?n?a?A?) "
266     | (1 = *) (3 = *) (2 =) (4 = *) |)
267
268    ("." =))
269   *))
270
271 ;; Stage 6
272 ;; Nukta for matra and Presentation forms
273 (generator
274  (0
275   (cond
276    (" (mn?)?([^ ]+) "
277     | (1 :otf=beng=nukt,init+) (2 :otf=beng=nukt,pres,abvs,blws,psts,haln+) |)
278
279    ("." =))
280   *))
281
282 ;; Stage 7
283 ;; Remove ZWNJ/ZWJ
284 (generator
285  (0
286   (cond
287    ("[NJ]")
288
289    ("." =))
290   *))
291
292 ;; Stage 8
293 ;; GPOS processing
294 (generator
295  (0
296   (cond
297    (" ([^ ]+) "
298     (1 :otf=beng=+abvm,blwm,dist))
299
300    ("." =))
301   *))
302
303 ;; Copyright (C) 2004, 2007, 2010
304 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
305 ;;   Registration Number H15PRO112
306
307 ;; This file is part of the m17n database; a sub-part of the m17n
308 ;; library.
309
310 ;; The m17n library is free software; you can redistribute it and/or
311 ;; modify it under the terms of the GNU Lesser General Public License
312 ;; as published by the Free Software Foundation; either version 2.1 of
313 ;; the License, or (at your option) any later version.
314
315 ;; The m17n library is distributed in the hope that it will be useful,
316 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
317 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
318 ;; Lesser General Public License for more details.
319
320 ;; You should have received a copy of the GNU Lesser General Public
321 ;; License along with the m17n library; if not, write to the Free
322 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
323 ;; Boston, MA 02110-1301, USA.
324
325 ;; Local Variables:
326 ;; mode: emacs-lisp
327 ;; End: