Remove ZWJ's _after_ 'vatu' and 'pres' are applied.
[m17n/m17n-db.git] / FLT / DEVA-OTF.flt
1 ;; DEVA-OTF.flt -- Font Layout Table for Devanagari OpenType font
2 ;; Copyright (C) 2003, 2004, 2007
3 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
4 ;;   Registration Number H15PRO112
5
6 ;; This file is part of the m17n database; a sub-part of the m17n
7 ;; library.
8
9 ;; The m17n library is free software; you can redistribute it and/or
10 ;; modify it under the terms of the GNU Lesser General Public License
11 ;; as published by the Free Software Foundation; either version 2.1 of
12 ;; the License, or (at your option) any later version.
13
14 ;; The m17n library is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 ;; Lesser General Public License for more details.
18
19 ;; You should have received a copy of the GNU Lesser General Public
20 ;; License along with the m17n library; if not, write to the Free
21 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
23
24 ;;; <li> DEVA-OTF.flt
25 ;;;
26 ;;; For Devanagari OpenType fonts to draw the Devanagari script.
27
28 (font layouter deva-otf nil
29       (font (nil nil unicode-bmp :otf=deva=rphf)))
30
31 (category
32  ;; X: generic
33  ;; C: consonant (except for RA)
34  ;; R: consonant RA
35  ;; n: NUKTA
36  ;; H: HALANT
37  ;; m: vowel sign (pre)
38  ;; u: vowel sign (above)
39  ;; b: vowel sign (below)
40  ;; p: vowel sign (post)
41  ;; A: vowel modifier (above)
42  ;; a: vowel modifier (post)
43  ;; S: stress sign / accent (above)
44  ;; s: stress sign / accent (below)
45  ;; V: independent vowel
46  ;; Z: internal use
47  ;; N: ZWNJ
48  ;; J: ZWJ
49  (0x0900 0x097F ?X)                     ; generic
50  (0x0900        ?Z)                     ; internal use
51  (0x0901 0x0902 ?A)                     ; SIGN CANDRABINDU .. ANUSVARA
52  (0x0903        ?a)                     ; SIGN VISARGA
53  (0x0904 0x0914 ?V)                     ; LETTER SHORT A .. AU
54  (0x0915 0x0939 ?C)                     ; LETTER KA .. HA
55  (0x0930        ?R)                     ; LETTER RA
56  (0x093C        ?n)                     ; SIGN NUKTA
57  (0x093E        ?p)                     ; VOWEL SIGN AA
58  (0x093F        ?m)                     ; VOWEL SIGN I
59  (0x0940        ?p)                     ; VOWEL SIGN II
60  (0x0941 0x0944 ?b)                     ; VOWEL SIGN UU .. VOCALIC RR
61  (0x0945 0x0948 ?u)                     ; VOWEL SIGN CANDRA E .. AI
62  (0x0949 0x094C ?p)                     ; VOWEL SIGN CANDRA O .. AU
63  (0x094D        ?H)                     ; SIGN VIRAMA
64  (0x0951        ?S)                     ; STRESS SIGN UDATTA
65  (0x0952        ?s)                     ; STRESS SIGN ANUDATTA
66  (0x0953 0x0954 ?S)                     ; GRAVE ACCENT .. ACUTE ACCENT
67  (0x0958 0x095F ?C)                     ; LETTER QA .. YYA
68  (0x0960 0x0961 ?V)                     ; LETTER VOCALIC RR  .. VOCALIC LL
69  (0x0962 0x0963 ?b)                     ; VOWEL SIGN VOCALIC L .. VOCALIC LL
70  (0x097B 0x097C ?C)                     ; LETTER GGA .. JJA
71  (0x097E 0x097F ?C)                     ; LETTER DDDA .. BBA
72  (0x200C        ?N)                     ; ZWNJ
73  (0x200D        ?J)                     ; ZWJ
74  )
75
76 ;; Stage 0
77 ;; Compose consonant and nukta
78 (generator
79  (0
80   (cond
81    ((0x0928 0x093C) 0x0929)
82    ((0x0930 0x093C) 0x0931)
83    ((0x0933 0x093C) 0x0934)
84    ((0x0915 0x093C) 0x0958)
85    ((0x0916 0x093C) 0x0959)
86    ((0x0917 0x093C) 0x095A)
87    ((0x091C 0x093C) 0x095B)
88    ((0x0921 0x093C) 0x095C)
89    ((0x0922 0x093C) 0x095D)
90    ((0x092B 0x093C) 0x095E)
91    ((0x092F 0x093C) 0x095F)
92    ("." =))
93   *))
94
95 ;; Stage 1
96 ;; Syllable identification and eordering.
97 (generator
98  (0
99   (cond
100    ;; A syllable containing a vowel sign.
101    ;;1      2            34   5   6     7   8   9   10
102    ("([CR]n?(HJ?[CR]n?)*)((m)|(b)|(u|p))(A)?(a)?(S)?(s)?"
103     < | (4 =) (1 move-h) (5 =) (10 =) (6 =) (1 reph) (7 =) (9 =) (8 =) | >)
104
105    ;; A syllable without vowel signs but with a vowel modifier.
106    ;;1      2            34   5   6   7
107    ("([CR]n?(HJ?[CR]n?)*)((A)|(a))(S)?(s)?"
108     < | (1 move-h) (7 =) (1 reph) (4 =) (6 =) (5 =) | >)
109
110    ;; No vowel signs, No vowel modifiers, but with a stress sign or an accent.
111    ;;1      2            34   5
112    ("([CR]n?(HJ?[CR]n?)*)((S)|(s))"
113     < | (1 move-h) (5 =) (1 reph) (4 =) | >)
114
115    ;; No marks at all.  Need further anylysis.
116    ("[CR]n?(HJ?[CR]n?)*(H(N|J)?)?"
117     < | (0 nomarks) | >)
118
119    ;; A syllable starting with an independent vowel.
120    ;;1  2   3   4   5
121    ("(V)(A)?(a)?(S)?(s)?"
122     < | (1 =) (5 =) (2 =) (4 =) (3 =) | >)
123
124    ("." =))
125   *)
126
127  (move-h
128   (cond
129    ;; Starting with an eyelash-RA, which remains there.
130    ("(RHJ.+)(H)(R)$"
131     (1 = *) (3 =) (2 =))
132    ("RHJ.*"
133     = *)
134
135    ;; Starting with a reph, which is removed.
136    ("RH(.+)(H)(R)$"
137     (1 = *) (3 =) (2 =))
138    ("RH(.+)"
139     (1 = *))
140
141    ("(.+)(H)(R)$"
142     (1 = *) (3 =) (2 =))
143    (".+"
144     = *)))
145
146  (reph
147   (cond
148    ("RHJ.*")
149    ("(RH).*"
150     (1 otf:deva=rphf+))))
151
152  (del-reph
153   (cond
154    ("RHJ.*"
155     = *)
156    ("RH(.*)"
157     (1 = *))
158    (".+"
159     = *)))
160
161  (nomarks
162   (cond
163    ;; Ending with a Halant and a ZWJ.
164    (".+HJ$"
165     (0 del-reph) (0 reph))
166
167    ;; Ending with a Halant and an optional ZWNJ.  Add ZWNJ explicitly.
168    ("(.+)(H)N?$"
169     (1 move-h) (1 reph) (2 =) 0x200C)
170
171    ;; Ending with a consonant.
172    (".+"
173     (0 move-h) (0 reph))))
174  )
175
176 ;; Stage 2
177 ;; Apply GSUB features.  If a syllable ends with a halant and a ZWNJ,
178 ;; render the final halant explicitly.
179 (generator
180  (0
181   (cond
182    ;; Allow eyelash RA to appear at the beginning.
183    (" (RH)J(.+)(H)N "
184     | (1 otf:deva=half+) (2 gsub) (3 =) |)
185    (" (m)?(RH)J([^ ]*) "
186     | (1 =) (2 otf:deva=half+) (3 gsub) |)
187
188    ;; Avoid applying 'blwf' and 'half' to the "RH" at the beginning;
189    (" (R)(.*)(H)N "
190     | (1 =) (2 gsub) (3 =) |)
191    (" (m?R)([^ ]*) "
192     | (1 otf:deva=pres+) (2 gsub) |)
193
194    (" (.+)(H)N "
195     | (1 gsub) (2 =) |)
196    (" ([^ ]+) "
197     | (1 gsub) |)
198
199    ("." =))
200   *)
201
202  ;; Dispite Rule R5a (The Unicode Standard 5.0, p.305), we use the
203  ;; below form to depict the sequence "RHJ" at a non-initial position.
204  ;; This is to avoid interpreting the sequence "CHRHJ" as "CH" +
205  ;; "RHJ".  It should be parsed as "CHR" + "HJ".
206  (gsub
207   otf:deva=nukt,akhn,blwf,half,vatu,pres+)
208  )
209
210 ;; Stage 3
211 ;; ZWJ's are used to prevent consonant conjuncts, so they are removed
212 ;; only after 'vatu' and 'pres' have been applied.
213 (generator
214  (0
215   (cond
216    ("J")
217    ("." =))
218   *))
219
220 ;; Stage 4
221 ;; Apply other features.
222 (generator
223  (0
224   (cond
225    (" ([^ ]+) "
226     (1 otf:deva=abvs,blws,psts,haln+abvm,blwm,dist))
227    ("."
228     [ = ]))
229   *))
230
231 ;; Local Variables:
232 ;; mode: emacs-lisp
233 ;; End: