;; TML2-OTF.flt -- Font Layout Table for tml2 OpenType fonts
;; Copyright (C) 2010 AIST (H15PRO112)
;; See the end for copying conditions.

(font layouter tml2-otf nil
      (version "1.6.0")
      (font (nil nil unicode-bmp :otf=tml2)))

;;; <li> TML2-OTF.flt
;;;
;;; For tml2 OpenType fonts to draw the Tamil script.

(category
 ;; X: generic
 ;; a: ANUSVARA
 ;; V: independent vowel
 ;; C: consonant
 ;; H: HALANT
 ;; m: vowel sign (pre)
 ;; p: vowel sign (others)
 (0x0B80 0x0BFF	?X)			; generic
 (0x0B82	?a)			; SIGN ANUSVARA
 (0x0B85 0x0B94 ?V)			; LETTER A .. AU
 (0x0B95 0x0BB9 ?C)			; LETTER KA .. HA
 (0x0BBE 0x0BC2	?p)			; VOWEL SIGN AA .. I
 (0x0BC6 0x0BC8	?m)			; VOWEL SIGN E .. AI
 (0x0BCD	?H)			; SIGN VIRAMA
 (0x0BD7	?p)			; AU LENGTH MARK

 (0x200C	?N)			; ZWNJ
 (0x200D	?J)			; ZWJ
 (0x25CC	?X)			; DOTTED CIRCLE
 )

;; Stage 0
;; Preprocessing
(generator
 (0
  (cond
   ;; Decompose two-part vowel signs.
   ((0x0BCA)
    0x0BC6 0x0BBE)
   ((0x0BCB)
    0x0BC7 0x0BBE)
   ((0x0BCC)
    0x0BC6 0x0BD7)

   ;; A variation of AU.
   ((0x0B92 0x0BD7)
    0x0B94)

   ;; The SHRII ligature and its old definition
   ((0x0BB6 0x0BCD 0x0BB0 0x0BC0)
    (0 :otf=tml2=locl,akhn,half,cjct,pres,abvs,blws,psts,haln,calt+))
   ((0x0BB8 0x0BCD 0x0BB0 0x0BC0)
    (0 :otf=tml2=locl,akhn,half,cjct,pres,abvs,blws,psts,haln,calt+))

   ("." =))
  *))

;; Stage 1
;; Syllable identification and basic shaping froms
(generator
 (0
  (cond
   ;; Consonant-based syllables
   ("(CJ?HJ?)*C(H[NJ]?|m?p?)a?"
    < | :otf=tml2=locl,akhn,half,cjct+ | >)

   ;; Syllables with an independent vowel
   ("Vm?p?a?"
    < | = * | >)

   ;; Two-part vowel signs
   ((0x0BC6 0x0BBE)
    (cond
     ((font-facility 0x25CC) < 0x0BC6 0x25CC 0x0BBE >)
     (".+" < 0x0BCA >)))
   ((0x0BC7 0x0BBE)
    (cond
     ((font-facility 0x25CC) < 0x0BC7 0x25CC 0x0BBE >)
     (".+" < 0x0BCB >)))
   ((0x0BC6 0x0BD7)
    (cond
     ((font-facility 0x25CC) < 0x0BC6 0x25CC 0x0BD7 >)
     (".+" < 0x0BCC >)))

   ;; Combining marks are displayed with a DOTTED CIRCLE.
   ("m"
    (cond
     ((font-facility 0x25CC) < = 0x25CC >)
     ("." [ = ])))
   ("[Hpa]"
    (cond
     ((font-facility 0x25CC) < 0x25CC = >)
     ("." [ = ])))

   ("." =))
  *))

;; Stage 2
;; Move pre-base matra after the last halant, or to the beginning
(generator
 (0
  (cond
   ;; 1         2       3  4
   (" ([^ ]+HJ?)([^H ]+)(m)([^ ]*) "
    | (1 = *) (3 =) (2 = *) (4 = *) |)

   ;; 1      2  3
   (" ([^ ]+)(m)([^ ]*) "
    | (2 =) (1 = *) (3 = *) |)

   ("." =))
  *))

;; Stage 3
;; Presentation forms
(generator
 (0
  (cond
   (" ([^ ]+) "
    | (1 :otf=tml2=pres,abvs,blws,psts,haln,calt+) |)

   ("." =))
  *))

;; Stage 4
;; Remove ZWNJ/ZWJ
(generator
 (0
  (cond
   ("[NJ]")

   ("." =))
  *))

;; Stage 5
;; GPOS processing
(generator
 (0
  (cond
   (" ([^ ]+) "
    (1 :otf=tml2=+kern,dist,abvm,blwm))

   ("." =))
  *))

;; Copyright (C) 2010
;;   National Institute of Advanced Industrial Science and Technology (AIST)
;;   Registration Number H15PRO112

;; This file is part of the m17n database; a sub-part of the m17n
;; library.

;; The m17n library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public License
;; as published by the Free Software Foundation; either version 2.1 of
;; the License, or (at your option) any later version.

;; The m17n library is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; Lesser General Public License for more details.

;; You should have received a copy of the GNU Lesser General Public
;; License along with the m17n library; if not, write to the Free
;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;; Local Variables:
;; mode: emacs-lisp
;; End:
