Do not break a syllable after ZWNJ.
[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 ;; Compose consonant and nukta
77 (generator
78  (0
79   (cond
80    ((0x0928 0x093C) 0x0929)
81    ((0x0930 0x093C) 0x0931)
82    ((0x0933 0x093C) 0x0934)
83    ((0x0915 0x093C) 0x0958)
84    ((0x0916 0x093C) 0x0959)
85    ((0x0917 0x093C) 0x095A)
86    ((0x091C 0x093C) 0x095B)
87    ((0x0921 0x093C) 0x095C)
88    ((0x0922 0x093C) 0x095D)
89    ((0x092B 0x093C) 0x095E)
90    ((0x092F 0x093C) 0x095F)
91    ("." =))
92   *))
93
94 ;; Reordering
95 (generator
96  (0
97   (cond
98    ;; A syllable containing a vowel sign.
99    ;;1      2            34   5   6     7   8   9   10
100    ("([CR]n?(HJ?[CR]n?)*)((m)|(b)|(u|p))(A)?(a)?(S)?(s)?"
101     < | (4 =) (1 move-h) (5 =) (10 =) (6 =) (1 reph) (7 =) (9 =) (8 =) | >)
102
103    ;; A syllable without vowel signs but with a vowel modifier.
104    ;;1      2            34   5   6   7
105    ("([CR]n?(HJ?[CR]n?)*)((A)|(a))(S)?(s)?"
106     < | (1 move-h) (7 =) (1 reph) (4 =) (6 =) (5 =) | >)
107
108    ;; No vowel signs, No vowel modifiers, but with a stress sign or an accent.
109    ;;1      2            34   5
110    ("([CR]n?(HJ?[CR]n?)*)((S)|(s))"
111     < | (1 move-h) (5 =) (1 reph) (4 =) | >)
112
113    ;; No marks at all.  Need further anylysis.
114    ("[CR]n?(HJ?[CR]n?)*(H(N|J)?)?"
115     < | (0 nomarks) | >)
116
117    ;; A syllable starting with an independent vowel.
118    ;;1  2   3   4   5
119    ("(V)(A)?(a)?(S)?(s)?"
120     < | (1 =) (5 =) (2 =) (4 =) (3 =) | >)
121
122    ("." =))
123   *)
124
125  (move-h
126   (cond
127    ;; Starting with an eyelash-RA, which remains there.
128    ("(RHJ.+)(H)(R)$"
129     (1 = *) (3 =) (2 =))
130    ("RHJ.*"
131     = *)
132
133    ;; Starting with a reph, which is removed.
134    ("RH(.+)(H)(R)$"
135     (1 = *) (3 =) (2 =))
136    ("RH(.+)"
137     (1 = *))
138
139    ("(.+)(H)(R)$"
140     (1 = *) (3 =) (2 =))
141    (".+"
142     = *)))
143
144  (reph
145   (cond
146    ("RHJ.*")
147    ("(RH).*"
148     (1 otf:deva=rphf+))))
149
150  (del-reph
151   (cond
152    ("RHJ.*"
153     = *)
154    ("RH(.*)"
155     (1 = *))
156    (".+"
157     = *)))
158
159  (nomarks
160   (cond
161    ;; Ending with a Halant and ZWJ.
162    (".+HJ$"
163     (0 del-reph) (0 reph))
164
165    ;; Ending with a Halant and an optional ZWNJ.  Add ZWNJ explicitly.
166    ("(.+)(H)N?$"
167     (1 move-h) (1 reph) (2 =) 0x200C)
168
169    ;; Ending with a consonant.
170    (".+"
171     (0 move-h) (0 reph))))
172  )
173
174 ;; Apply 'nukt' and 'akhn'.
175 (generator
176  (0
177   (cond
178    (" ([^ ]+) "
179     | (1 otf:deva=nukt,akhn+) |)
180    ("." =))
181   *))
182
183 ;; Apply either 'half' or 'blwf' to consonants.  If a syllable ends
184 ;; with a halant and a ZWNJ, render the final halant explicitly.
185 (generator
186  (0
187   (cond
188    ;; Allow eyelash RA to appear at the beginning.
189    (" (RH)J(.+)(H)N "
190     | (1 otf:deva=half+) (2 gsub) (3 =) |)
191    (" (m)?(RH)J([^ ]*) "
192     | (1 =) (2 otf:deva=half+) (3 gsub) |)
193
194    ;; Avoid applying 'half' and 'blwf' to the initial RA.
195    (" (R)(.*)(H)N "
196     | (1 =) (2 gsub) (3 =) |)
197    (" (m?R)([^ ]*) "
198     | (1 = *) (2 gsub) |)
199
200    (" (.+)(H)N "
201     | (1 gsub) (2 =) |)
202    (" ([^ ]+) "
203     | (1 gsub) |)
204
205    ("." =))
206   *)
207
208  ;; Dispite Rule R5a (p.305), we use the below form to depict the
209  ;; sequence "RHJ" at a non-initial position.  This is to avoid
210  ;; interpreting the sequence "CHRHJ" as "CH" + "RHJ".  It should be
211  ;; parsed as "CHR" + "HJ".
212  (gsub
213   (cond
214    ("(.H)J?(.*)"
215     (1 otf:deva=blwf,half+) (2 gsub))
216    ("(.)(.*)"
217     (1 =) (2 gsub))))
218  )
219
220 ;; Apply other features.
221 (generator
222  (0
223   (cond
224    (" ([^ ]+) "
225     (1 otf:deva=vatu,pres,abvs,blws,psts,haln+abvm,blwm,dist))
226    ("."
227     [ = ]))
228   *))
229
230 ;; Local Variables:
231 ;; mode: emacs-lisp
232 ;; End: