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