Fix for the case of failed LAM-ALEF ligature. Handle positioning of
[m17n/m17n-db.git] / FLT / ARAB-OTF-NO-GPOS.flt
1 ;; ARAB-OTF-NO-GPOS.flt -- Font Layout Table for Arabic OpenType font sans GPOS
2 ;; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010  AIST (H15PRO112)
3 ;; See the end for copying conditions.
4
5 (font layouter arab-otf-no-gpos nil
6       (font (nil nil unicode-bmp :otf=arab=init,medi,fina,liga+~mark)))
7
8 ;;; <li> ARAB-OTF-NO-GPOS.flt
9 ;;;
10 ;;; For Arabic OpenType fonts that don't have GPOS table to draw the
11 ;;; Arabic script.
12
13 ;; Step 0: Move Kazakh high hamza.
14
15 (category
16  ;; p: high hamza carrier (p for positive)
17  ;; n: high hamza suppressor (n for negative)
18  ;; x: don't care
19  ;; X: presentation form
20  (0x0600 0x06FF         ?x)
21  (0x0674 0x0678         ?p)
22  (0x0643                ?n)
23  (0x06AF                ?n)
24  (0x06D5                ?n)
25  (0x0750 0x077F         ?x)             ; Arabic Supplement
26  (0x200C                ?x)
27  (0x200D                ?x)
28  (0x25CC                ?x)
29  (0xFB50 0xFDFF         ?X)             ; Arabic Presentation Forms-A
30  (0xFE70 0xFEFC         ?X)             ; Arabic Presentation Forms-B
31  )
32
33 (generator
34  (0
35   (cond
36    ;; If a presentation form is found, draw the whole sequence as is.
37    (".*X.*" = *)
38
39    (".*p.*"                             ; If a high hamza is found,
40     (cond
41      (".*n.*"                           ;   and a suppressor exists,
42       rmhamza *)                        ;   then remove the high hamza.
43      (0                                 ;   Otherwise, move the high
44       0x674 rmhamza *)))                ;   hamza to the beginning.
45    (0 = *)))                            ; If no high hamza, do nothing.
46
47  (rmhamza
48   (cond
49    ((0x0674)            )
50    ((0x0675)            0x0627)
51    ((0x0676)            0x0648)
52    ((0x0677)            0x06C7)
53    ((0x0678)            0x0649)
54    ("."                 =))))
55
56 ;; Step 1: Initial, medial, or final.  Surround diacritics by
57 ;; separators (|).
58
59 (category
60  ;; D: Dual-joining (beh, teh, etc. & zwj) except for LAMs
61  ;; L: LAMs
62  ;; R: Right-joining (alef, dal, thal, reh, zain) except for ALEFs
63  ;; A: ALEFs
64  ;; U: Non-joining (Hamza, etc. & zwnj)
65  ;; T: Transparent (combining marks)
66  (0x060B 0x060F         ?U)
67  (0x0610 0x0615         ?T)
68  (0x061B                ?U)
69  (0x061E 0x061F         ?U)
70  (0x0621                ?U)
71  (0x0622 0x0627         ?A)
72  (0x0624                ?R)
73  (0x0626                ?D)
74  (0x0628                ?D)
75  (0x0629                ?R)
76  (0x062A 0x062E         ?D)
77  (0x062F 0x0632         ?R)
78  (0x0633 0x0647         ?D)
79  (0x0644                ?L)
80  (0x0648                ?R)
81  (0x0649 0x064A         ?D)
82  (0x064B 0x065E         ?T)
83  (0x0660 0x066D         ?U)
84  (0x066E 0x066F         ?D)
85  (0x0670                ?T)
86  (0x0671 0x0673         ?A)
87  (0x0674 0x0678         ?U)
88  (0x0679 0x0687         ?D)
89  (0x0688 0x0699         ?R)
90  (0x069A 0x06C3         ?D)
91  (0x06B5 0x06B8         ?L)
92  (0x06C4 0x06CB         ?R)
93  (0x06CC 0x06CE         ?D)
94  (0x06CF                ?R)
95  (0x06D0 0x06D3         ?D)
96  (0x06D4                ?U)
97  (0x06D5                ?R)
98  (0x06D6 0x06E4         ?T)
99  (0x06E5 0x06E6         ?U)
100  (0x06E7 0x06E8         ?T)
101  (0x06E9                ?U)
102  (0x06EA 0x06ED         ?T)
103  (0x06EE 0x06EF         ?R)
104  (0x06F0 0x06F9         ?U)
105  (0x06FA 0x06FC         ?D)
106  (0x06FD 0x06FE         ?U)
107  (0x06FF                ?D)
108  (0x0750 0x0758         ?D)
109  (0x0759 0x075B         ?R)
110  (0x075C 0x076A         ?D)
111  (0x076B 0x076C         ?R)
112  (0x076D 0x0770         ?D)
113  (0x0771                ?R)
114  (0x0772                ?D)
115  (0x0773 0x0774         ?R)
116  (0x0775 0x0777         ?D)
117  (0x0778 0x0779         ?R)
118  (0x077A 0x077F         ?D)
119  (0x200C                ?U)
120  (0x200D                ?D)
121  (0x25CC                ?U)
122  (0xE800                ?C)             ; dummy dotted-circle
123  (0xFB50 0xFDFF         ?X)             ; Arabic Presentation Forms-A
124  (0xFE70 0xFEFC         ?X)             ; Arabic Presentation Forms-B
125  )
126
127 (generator
128  (0
129   (cond
130    (".*X.*" (cond ("[DLRAUX]T*" < = * >) ("." =)) *)
131
132    ;; LAM-ALEF pattern.  Move diacritcs on LAM after ALEF.  This is to
133    ;; avoid loosing surrounding separators by OTF's liga or rlig
134    ;; features in the next step.
135    ("L(T*)A.*"
136     (cond
137      ("(.)(T*)(A)(T*)([DLRA].*)"
138       (1 otf:arab=init)
139       (3 otf:arab=fina)
140       (2 | = * |)
141       (4 | = * |)
142       (5 join))
143      ("(.)(T*)(A)(T*)(.*)"                      ; == (D)(T*)(U.*)
144       (1 otf:arab=init)
145       (3 otf:arab=fina)
146       (2 | = * |)
147       (4 | = * |)
148       (5 disjoin))))
149
150    ("[DL].*"
151     (cond
152      ("(.)(T*)([DLRA].*)"
153       (1 otf:arab=init)
154       (2 | = * |)
155       (3 join))
156      ("(.)(T*)(.*)"                     ; == (D)(T*)(U.*)
157       (1 otf:arab=isol)
158       (2 | = * |)
159       (3 disjoin))))
160
161    ("([RAU])(T*)(.*)"
162     (1 otf:arab=isol)
163     (2 | = * | )
164     (3 disjoin))
165
166    ;; Incorrect leading diacritcs.
167    ("(T+)(.*)"
168     (1 (cond ((font-facility 0x25CC)
169               (cond ("." 0x25CC | = |)) *)
170              ("." 0xE800 | = |)) *)
171     (2 disjoin))))
172
173  (join
174   (cond
175    ;; LAM-ALEF pattern.  See the above comment.
176    ("L(T*)A.*"
177     (cond
178      ("(.)(T*)(A)(T*)([DLRA].*)"
179       (1 otf:arab=medi)
180       (3 otf:arab=fina)
181       (2 | = * |)
182       (4 | = * |)
183       (5 join))
184      ("(.)(T*)(A)(T*)(.*)"                      ; == (D)(T*)(U.*)
185       (1 otf:arab=medi)
186       (3 otf:arab=fina)
187       (2 | = * |)
188       (4 | = * |)
189       (5 disjoin))))
190
191    ("[DL].*"
192     (cond
193      ("(.)(T*)([DLRA].*)"
194       (1 otf:arab=medi)
195       (2 | = * |)
196       (3 join))
197      ("(.)(T*)(.*)"                     ; == (D)(T*)(U.*)
198       (1 otf:arab=fina)
199       (2 | = * |)
200       (3 disjoin))))
201
202    ("(.)(T*)(.*)"
203     (1 otf:arab=fina)
204     (2 | = * |)
205     (3 disjoin))))
206
207  (disjoin
208   (cond
209    ;; LAM-ALEF pattern.  See the above comment.
210    ("L(T*)A.*"
211     (cond
212      ("(.)(T*)(A)(T*)([DLRA].*)"
213       (1 otf:arab=init)
214       (3 otf:arab=fina)
215       (2 | = * |)
216       (4 | = * |)
217       (5 join))
218      ("(.)(T*)(A)(T*)(.*)"                      ; == (D)(T*)(U.*)
219       (1 otf:arab=init)
220       (3 otf:arab=fina)
221       (2 | = * |)
222       (4 | = * |)
223       (5 disjoin))))
224
225    ("[DL].*"
226     (cond
227      ("(.)(T*)([DLRA].*)"
228       (1 otf:arab=init)
229       (2 | = * |)
230       (3 join))
231      ("(.)(T*)(.*)"                     ; == (D)(T*)(U.*)
232       (1 otf:arab=isol)
233       (2 | = * |)
234       (3 disjoin))))
235
236    ("(.)(T*)(.*)"                       ; == ([RU])(T*)(.*)
237     (1 otf:arab=isol)
238     (2 | = * |)
239     (3 disjoin)))))
240
241 ;; Step 2: Remaining GSUB features (ligature, etc.).
242
243 (generator
244  (0
245   otf:arab=rlig,calt,liga,dlig,cswh,mset+))
246
247 ;; Step 3: Simulate missing GPOS features.
248
249 (generator
250  (0
251   (cond
252    ("C ([^ ]) "                         ; dummy dotted-circle
253     [ (1 =) ])
254    ("([^ ]) ([^ ]+)?  ([^ ]+)? "        ; LAM-ALEF ligature
255     < (1 =) (2 right-combining) (3 left-combining) >)
256    ("([^ ]) ([^ ]+)? "
257     < (1 =) (2 center-combining) >)
258    ("([^ ])([^ ]) ([^ ]+)?  ([^ ]+)? "  ; failed LAM-ALEF ligature
259     (1 < =) (3 right-combining = *) > (2 < = ) (4 left-combining = *) >)
260    ("[^ ]" =)
261    (" "))
262   *)
263
264  (right-combining
265   (cond ("." Br.Br =)) *)
266
267  (left-combining
268   (cond ("." Bl.Bl =)) *)
269
270  (center-combining
271   (cond ("." Bc.Bc =)) *))
272
273 ;; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
274 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
275 ;;   Registration Number H15PRO112
276
277 ;; This file is part of the m17n database; a sub-part of the m17n
278 ;; library.
279
280 ;; The m17n library is free software; you can redistribute it and/or
281 ;; modify it under the terms of the GNU Lesser General Public License
282 ;; as published by the Free Software Foundation; either version 2.1 of
283 ;; the License, or (at your option) any later version.
284
285 ;; The m17n library is distributed in the hope that it will be useful,
286 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
287 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
288 ;; Lesser General Public License for more details.
289
290 ;; You should have received a copy of the GNU Lesser General Public
291 ;; License along with the m17n library; if not, write to the Free
292 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
293 ;; Boston, MA 02110-1301, USA.
294
295 ;; Local Variables:
296 ;; mode: emacs-lisp
297 ;; End: