Fix for the case of failed LAM-ALEF ligature. Handle positioning of
[m17n/m17n-db.git] / FLT / DEVA-OTF.flt
1 ;; DEVA-OTF.flt -- Font Layout Table for Devanagari OpenType fonts
2 ;; Copyright (C) 2003, 2004, 2007, 2008, 2010 AIST (H15PRO112)
3 ;; See the end for copying conditions.
4
5 (font layouter deva-otf nil
6       (version "1.6.0")
7       (font (nil nil unicode-bmp :otf=deva)))
8
9 ;;; <li> DEVA-OTF.flt
10 ;;;
11 ;;; For Devanagari OpenType fonts to draw the Devanagari script.
12
13 ;; Accepted modifier sequence:
14 ;; 1. matra (pre, below, above, post)
15 ;; 2. candrabindu (0901) or anusvara (0902)
16 ;; 3. udatta (0951) or anudatta (0952)
17 ;; 4. grave (0953) or acute (0954)
18 ;; 5. visarga (0903)
19
20 ;; Rendering glyph order:
21 ;; 1. below matra
22 ;; 2. anudatta (0952)
23 ;; 3. above- or post matra
24 ;; 4. reph
25 ;; 5. candrabindu (0901) or anusvara (0902)
26 ;; 6. udatta (0951)
27 ;; 7. visarga (0903)
28
29 (category
30  ;; X: generic
31  ;; V: independent vowel
32  ;; C: consonant (except for RA)
33  ;; R: consonant RA
34  ;; n: NUKTA
35  ;; H: HALANT
36  ;; m: vowel sign (pre)
37  ;; u: vowel sign (above)
38  ;; b: vowel sign (below)
39  ;; p: vowel sign (post)
40  ;; a: vowel modifier (above)
41  ;; A: vowel modifier (post)
42  ;; s: stress sign / accent (above)
43  ;; S: stress sign (below)
44  ;; N: ZWNJ
45  ;; J: ZWJ
46  (0x0900 0x097F ?X)                     ; generic
47  (0x0900 0x0902 ?a)                     ; SIGN INVERTED CANDRABINDU .. ANUSVARA
48  (0x0903        ?A)                     ; SIGN VISARGA
49  (0x0904 0x0914 ?V)                     ; LETTER SHORT A .. AU
50  (0x0915 0x0939 ?C)                     ; LETTER KA .. HA
51  (0x0930        ?R)                     ; LETTER RA
52  (0x093C        ?n)                     ; SIGN NUKTA
53  (0x093E        ?p)                     ; VOWEL SIGN AA
54  (0x093F        ?m)                     ; VOWEL SIGN I
55  (0x0940        ?p)                     ; VOWEL SIGN II
56  (0x0941 0x0944 ?b)                     ; VOWEL SIGN UU .. VOCALIC RR
57  (0x0945 0x0948 ?u)                     ; VOWEL SIGN CANDRA E .. AI
58  (0x0949 0x094C ?p)                     ; VOWEL SIGN CANDRA O .. AU
59  (0x094D        ?H)                     ; SIGN VIRAMA
60  (0x094E        ?m)                     ; VOWEL SIGN PRISHTHAMATRA E
61  (0x0951        ?s)                     ; STRESS SIGN UDATTA
62  (0x0952        ?S)                     ; STRESS SIGN ANUDATTA
63  (0x0953 0x0954 ?t)                     ; GRAVE ACCENT .. ACUTE ACCENT
64  (0x0955        ?u)                     ; VOWEL SIGN CHANDRA LONG E
65  (0x0958 0x095F ?C)                     ; LETTER QA .. YYA
66  (0x0960 0x0961 ?V)                     ; LETTER VOCALIC RR  .. VOCALIC LL
67  (0x0962 0x0963 ?b)                     ; VOWEL SIGN VOCALIC L .. VOCALIC LL
68  (0x0972        ?V)                     ; LETTER CANDRA A
69  (0x0979 0x097F ?C)                     ; LETTER ZHA .. BBA
70
71  (0x200C        ?N)                     ; ZWNJ
72  (0x200D        ?J)                     ; ZWJ
73  (0x25CC        ?X)                     ; DOTTED CIRCLE
74
75  (rphf          ?r)
76  )
77
78 ;; Stage 0
79 ;; Preprocessing
80 (generator
81  (0
82   (cond
83    ;; Compose a consonant and a nukta
84    ((0x0928 0x093C) 0x0929)
85    ((0x0930 0x093C) 0x0931)
86    ((0x0933 0x093C) 0x0934)
87    ((0x0915 0x093C) 0x0958)
88    ((0x0916 0x093C) 0x0959)
89    ((0x0917 0x093C) 0x095A)
90    ((0x091C 0x093C) 0x095B)
91    ((0x0921 0x093C) 0x095C)
92    ((0x0922 0x093C) 0x095D)
93    ((0x092B 0x093C) 0x095E)
94    ((0x092F 0x093C) 0x095F)
95
96    ("." =))
97   *))
98
99 ;; Stage 1
100 ;; Syllable identification
101 (generator
102  (0
103   (cond
104    ;; Syllables with an independent vowel
105    ;;
106    ("(RH)?(Vn?)((J?HR)?m?u?b?p?n?a?[sS]?t?A?)"
107     < | (1 = =) (2 :otf=deva=nukt+) (3 = *) | >)
108
109    ;; Consonant-based syllables
110    ;;1      23                 4
111    ("([CR]n?((J?H|HJ?)[CR]n?)*)(H[NJ]?|m?u?b?p?n?a?[sS]?t?A?)"
112     < |
113     (cond
114      (".+HJ$" :otf=deva=nukt,akhn+)
115      ("(.+)(H)N?$" (1 :otf=deva=nukt,akhn+) (2 =) 0x200C)
116      (".+" :otf=deva=nukt,akhn+))
117     | >)
118
119    ;; Combining marks are displayed with a DOTTED CIRCLE.
120    ("m"
121     (cond
122      ((font-facility 0x25CC) < = 0x25CC >)
123      ("." [ = ])))
124    ("[nHubpaSsA]"
125     (cond
126      ((font-facility 0x25CC) < 0x25CC = >)
127      ("." [ = ])))
128
129    ;; Isolated blwf is displayed with a DOTTED CIRCLE in the next stage.
130    ("(J)(H)(R)"
131     < | (1 =) (3 =) (2 =) | >)
132
133    ("." =))
134   *))
135
136 ;; Stage 2
137 ;; Reorder halant for blwf
138 (generator
139  (0
140   (cond
141    ;; Isolated blwf
142    (" J(RH) "
143     (cond
144      ((font-facility 0x25CC) < 0x25CC :otf=deva=blwf+ >)
145      (" J(RH) " [ (1 :otf=deva=blwf+) ])))
146
147    ;; Syllables with an overt halant
148    (" (RHJ?)?([^ ]+)(HN) "
149     | (1 = *) (2 reorder) (3 = =) |)
150
151    ;; Ordinary syllables
152    (" (RHJ?)?([^mubpasStA ]+)(m?u?b?p?n?a?[sS]?t?A?) "
153     | (1 = *) (2 reorder) (3 = *) |)
154
155    ("." =))
156   *)
157
158  ;; In Devanagari and Gujarati, vattu has a half form.  Thus we handle
159  ;; the sequence CHRHC as (CH)half + (RH)blwf + C instead of
160  ;; reordering and interpreting it as C + (RH)blwf + H + C.
161  (reorder
162   (cond
163    ("(.+)(H)(R)$" (1 = *) (3 =) (2 =))
164    (".+" = *)))
165  )
166
167 ;; Stage 3
168 ;; Language forms and matra reordering
169 (generator
170  (0
171   (cond
172    ;; Overt halant forms
173    (" (RHJ?)?([^ ]+)(HN) "
174     |
175     (1 (cond ("RHJ" :otf=deva=half+)
176              ("RH" :otf=deva=rphf+)))
177     (2 (cond ("(.H)J?(.*)" (1 :otf=deva=half+) (2 lang-forms *))
178              (".+" lang-forms *)))
179     (3 = =) |)
180
181    ;; Other syllables
182    ;; 1      2               3     4     5     6       7   8
183    (" (RHJ?)?([^mubpasStA ]*)(mn?)?(un?)?(bn?)?(p?n?a?)(S)?(s?t?A?) "
184     | (3 = *)
185     (1 (cond ("RHJ" :otf=deva=half+)
186              ("RH" :otf=deva=rphf+)))
187     (2 (cond ("(.H)J?(.*)" (1 :otf=deva=half+) (2 lang-forms *))
188              (".+" lang-forms *)))
189     (5 = *) (7 =) (4 = *) (6 = *) (8 = *) |)
190
191    ("." =))
192   *)
193
194  (lang-forms
195   (cond
196    ("(.H)J" (1 :otf=deva=half+))
197    (".H" :otf=deva=blwf,half+)
198    ("." =)))
199  )
200
201 ;; Stage 4
202 ;; Final reordering #1 (Move pre-base matra after the last halant)
203 (generator
204  (0
205   (cond
206    ;; 1    2         3
207    (" (mn?)([^ ]+HJ?)([^H ]+) "
208     | (2 = *) (1 = *) (3 = *) |)
209
210    ("." =))
211   *))
212
213 ;; Stage 5
214 ;; Final reordering #2 (Move reph after the first halant)
215 (generator
216  (0
217   (cond
218    ;; Syllables with a reph and an explicit halant
219    ;; 1     2  3             4
220    (" (mn?)?(r)([^H ]+HJ?)([^ ]*) "
221     | (1 = *) (3 = *) (2 =) (4 = *) |)
222
223    ;; A reph without explicit halant
224    ;; 1     2  3          4
225    (" (mn?)?(r)([^astA ]+)(a?s?t?A?) "
226     | (1 = *) (3 = *) (2 =) (4 = *) |)
227
228    ("." =))
229   *))
230
231 ;; Stage 6
232 ;; Nukta for matra, vattu and presentation forms
233 (generator
234  (0
235   (cond
236    (" ([^ ]+) "
237     | (1 :otf=deva=nukt,vatu,pres,abvs,blws,psts,haln+) |)
238
239    ("." =))
240   *))
241
242 ;; Stage 7
243 ;; Remove ZWNJ/ZWJ
244 (generator
245  (0
246   (cond
247    ("[NJ]")
248
249    ("." =))
250   *))
251
252 ;; Stage 8
253 ;; GPOS processing
254 (generator
255  (0
256   (cond
257    (" ([^ ]+) "
258     (1 :otf=deva=+abvm,blwm,dist))
259
260    ("." =))
261   *))
262
263 ;; Copyright (C) 2003, 2004, 2007, 2008, 2010
264 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
265 ;;   Registration Number H15PRO112
266
267 ;; This file is part of the m17n database; a sub-part of the m17n
268 ;; library.
269
270 ;; The m17n library is free software; you can redistribute it and/or
271 ;; modify it under the terms of the GNU Lesser General Public License
272 ;; as published by the Free Software Foundation; either version 2.1 of
273 ;; the License, or (at your option) any later version.
274
275 ;; The m17n library is distributed in the hope that it will be useful,
276 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
277 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
278 ;; Lesser General Public License for more details.
279
280 ;; You should have received a copy of the GNU Lesser General Public
281 ;; License along with the m17n library; if not, write to the Free
282 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
283 ;; Boston, MA 02110-1301, USA.
284
285 ;; Local Variables:
286 ;; mode: emacs-lisp
287 ;; End: