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