Add gardi-1.3 for Devanagari.
[m17n/m17n-db.git] / MLM-OTF.flt
1 ;; MLM-OTF.flt -- Font Layout Table for Malayalam OpenType font
2 ;; Copyright (C) 2003, 2004
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., 59 Temple Place, Suite 330, Boston, MA
22 ;; 02111-1307, USA.
23
24 ;;; <li> MLM-OTF.flt
25 ;;;
26 ;;; For Malayalam OpenType fonts to draw reformed Malayalam script.
27
28 ;; The first stage is to extract a syllable and re-order characters.
29 (category
30  ;; C: consonant (except for BPR)
31  ;; B: consonant that is the subject of "blws" feature
32  ;; P: consonant that is the subject of "pstf" feature
33  ;; R: consonant RA
34  ;; H: HALANT (VIRAMA)
35  ;; m: MATRA (Mpre)
36  ;; p: MATRA (Mpost)
37  ;; t: MATRA (two-part: Mpre+Mpost)
38  ;; A: vowel modifier (post) (ANUSVARA and VISARGA)
39  ;; V: independent vowel
40  ;; N: ZWNJ (ZERO WIDTH NON-JOINER)
41  ;; J: ZWJ (ZERO WIDTH JOINER)
42  ;; E: else (all other independnt characters)
43  (0x0D00 0x0D7F ?E)                     ; else
44  (0x0D02 0x0D03 ?A)                     ; ANUSVARA & VISARGA
45  (0x0D05 0x0D14 ?V)                     ; independent vowel
46  (0x0D15 0x0D39 ?C)                     ; consonant
47
48  ;; Accorind to www.microsoft.com/typography/otfntdev/indicot/appen.htm,
49  ;; these must be classified into 'B' category, but at least, it
50  ;; doesn't work with this font
51  ;; http://www.supersoftweb.com/THOOLIUC.TTF
52  ;;(0x0D1F      ?B)                     ; TTA
53  ;;(0x0D23      ?B)                     ; NNA
54  ;;(0x0D26      ?B)                     ; DA
55  (0x0D2F        ?P)                     ; YA
56  (0x0D30        ?R)                     ; RA
57  (0x0D32        ?B)                     ; LA
58  (0x0D35        ?P)                     ; VA
59  (0x0D3E 0x0D43 ?p)                     ; dependent vowel (Mpost)
60  (0x0D46 0x0D48 ?m)                     ; dependent vowel (Mpre)
61  (0x0D4A 0x0D4C ?t)                     ; dependent vowel (two-part)
62  (0x0D4D        ?H)                     ; VIRAMA (HALANT)
63  (0x0D57        ?p)                     ; dependent vowel (Mpost)
64  (0x0D60        ?V)                     ; VOCALIC RR
65  (0x0D61        ?V)                     ; VOCALIC LL
66  (0x200C        ?N)                     ; ZWNJ
67  (0x200D        ?J)                     ; ZWJ
68  (0x0D7D        ?x)
69  (0x0D7E        ?y)
70  (0x0D7F        ?z)
71  )
72
73 ;; The first step is to extract a syllable while moving a Halant
74 ;; following Cbase to the tail and partitioning two-part matras into
75 ;; parts.
76 (generator
77  (0
78   (cond
79    ;; If [CR]H is followed by ZWNJ/ZWJ, move ZWNJ/ZWJ) to the head so
80    ;; that the later stages find it quickly.
81    ("([CBPR]H)([NJ])"
82     < | (2 =) (1 = =) | >)
83
84    ;; A syllable starting with a consonant and ending with a vowel
85    ;; and/or a vowel modifier.
86    ("(([CBPR]H)*[CBPR])([pmt]A?|A)"
87     < | (1 move-halant) (3 partition = =) | >)
88
89    ;; A syllable starting with a consonant and ending without a vowel
90    ;; nor a vowel modifier.
91    ("(([CBPR]H)*[CBPR])(H)?"
92     < | (1 move-halant) (3 =) | >)
93
94    ;; A syllable starting with an independent vowel.
95    ("(VA?)"
96     < | (1 = *) | >)
97
98    ;; Other independent character.
99    ("." =))
100   *)
101
102  ;; Move Halant to the tail if necessary.  Insert 0x0D7D before Cbase,
103  ;; 0x0D7E after Cbase, 0x0D7F before the tailing RH (if any).  They
104  ;; work as markers in the following stages.
105  (move-halant
106   (cond
107    ;; In the first two cases, we don't have to move Halant.
108    ("[BPR]$"                            ; Single consonant.
109     0x0D7D 0x0D7E =)
110    ("(([CBPR]H)*)(C)$"                  ; Cbase is at tail.
111     (1 = *) 0x0D7D (3 =) 0x0D7E)
112    ;; In the following cases, we must move Halant to the tail.
113    ("(([CBPR]H)*)([C])H(([BR]H)*)(R)$"  ; Cbase is at head or middle.
114     (1 = *) 0x0D7D (3 =) 0x0D7E (4 = *) 0x0D7F 0x0D30 0x0D4D)
115    ("(([CBPR]H)*)([C])H(([BR]H)*[BP])$" ; Cbase is at head or middle.
116     (1 = *) 0x0D7D (3 =) 0x0D7E (4 = *) 0x0D4D)
117    ("(.)H(.*)$"                         ; No Cbase, move the first
118                                         ; Halant to the tail.
119     0x0D7D 0x0D7E (1 = *) (2 = *) 0x0D4D)))
120
121  ;; Partition two-part matras into parts.
122  (partition
123   (cond
124    ((0x0D4A)    0x0D46 0x0D3E)
125    ((0x0D4B)    0x0D47 0x0D3E)
126    ;; Unicode suggests this partitioning:
127    ((0x0D4C)    0x0D46 0x0D57)
128    ;; but it is questionable.  Perhaps, this substitution is better.
129    ;; ((0x0D4C) 0x0D57)
130    )))
131
132 ;; The second stage is to move Mpre to the head.
133 (generator
134  (0
135   (cond
136    (" [NJ]([^ ]*) "
137     = *)
138    (" ([^m ]*)(m)([^ ]*) "
139     | (2 =) (1 = *) (3 = *) |)
140    (" ([^ ]*) "
141     = *)
142    ("." =))
143   *))
144
145 ;; The third stage is to drive OTF tables.
146 (generator
147  (0
148   (cond
149    ;; Originally [CBPR]H is followed by ZWNJ.  Apply only GPOS
150    ;; features (if any).
151    (" N([^ ]*) "
152     (1 otf:mlym=))
153
154    ;; Originally [CBPR]H is followed by ZWJ.  Apply only GSUB haln
155    ;; feature and GPOS features (if any).
156    (" J([^ ]*) "
157     (1 otf:mlym=haln))
158
159    ;; Syllable starting with a consonant should match this pattern.
160    (" ([^ y]*)y([^ z]*)(z..)?([^ ]*) "
161     |
162     (1 otf:mlym=~blwf,~pstf,~blws,~psts,*) ; Prebase part.
163     0x0D7E                                 ; Preserve this marker.
164     (2 otf:mlym=~akhn,~haln,blwf,pstf,vatu,*) ; Postbase part.
165     (3 = otf:mlym=pstf)                    ; Optional tailing RH.
166     (4 otf:mlym=)                          ; Optional Mpost.
167     |)
168
169    ;; A syllable starting with an independent vowel.
170    (" ([^ ]*) "
171     (1 otf:mlym))
172
173    ;; Any other independent character.  Apply no feature (just CMAP).
174    ("."
175     [ otf:mlym=+ ] ))
176   *))
177
178 ;; The last stage is to move Mpre (if any) backward and tailing RH (if
179 ;; any) forward to just before the base consonant.
180 (generator
181  (0
182   (cond
183    (" (m)?([^xy]*)x([^y]*)y([^ z]*)(z(.))?([^ ]*) "
184     (2 = *) (1 =) (5 (6 =)) (3 = *) (4 = *) (7 = *))
185    (" (m)?([^y]*)y([^ z]*)(z(.))?([^ ]*) "
186     (1 =) (4 (5 =)) (2 = *) (3 = *) (6 = *))
187    ("[NJ]")
188    ("."
189     = ))
190   *))
191
192 ;; Local Variables:
193 ;; mode: emacs-lisp
194 ;; End: