;; GURU-OTF.flt -- Font Layout Table for Gurmukhi OpenType fonts
;; Copyright (C) 2004, 2007  AIST (H15PRO112)
;; See the end for copying conditions.

(font layouter guru-otf nil
      (font (nil nil unicode-bmp :otf=guru=blwf)))

;;; <li> GURU-OTF.flt
;;;
;;; For Gurmukhi OpenType fonts to draw the Gurmukhi script.

(category
 ;; C: general consonant (except for R and Y)
 ;; R: consonant (below)
 ;; Y: consonant YA
 ;; n: NUKTA
 ;; H: HALANT
 ;; m: vowel sign (pre)
 ;; u: vowel sign (above)
 ;; b: vowel sign (below)
 ;; p: vowel sign (post)
 ;; A: vowel modifier (above)
 ;; a: vowel modifier (post)
 ;; V: independent vowel
 ;; d: ADDAK
 ;; N: ZWNJ (ZERO WIDTH NON-JOINER)
 ;; J: ZWJ (ZERO WIDTH JOINER)
 ;; X: generic
 ;; Z: internal use
 (0x0A00 0x0A7F	?X)			; generic
 (0x0A00	?Z)			; internal use
 (0x0A01 0x0A02	?A)			; SIGN ADAK BINDI .. BINDI
 (0x0A03	?a)			; SIGN VISARGA
 (0x0A05 0x0A14	?V)			; LETTER A .. AU
 (0x0A15 0x0A38 ?C)			; LETTER KA .. SA
 (0x0A2F	?Y)			; LETTER YA
 (0x0A30	?R)			; LETTER RA
 (0x0A35	?R)			; LETTER VA
 (0x0A39	?R)			; LETTER HA
 (0x0A3C	?n)			; SIGN NUKTA
 (0x0A3E	?p)			; VOWEL SIGN AA
 (0x0A3F	?m)			; VOWEL SIGN I
 (0x0A40	?p)			; VOWEL SIGN II
 (0x0A41 0x0A42	?b)			; VOWEL SIGN U .. UU
 (0x0A47 0x0A4C	?u)			; VOWEL SIGN EE .. AU
 (0x0A4D	?H)			; SIGN VIRAMA
 (0x0A59 0x0A5E	?C)			; LETTER KHHA .. FA
 (0x0A70	?A)			; TIPPI
 (0x0A71	?d)			; ADDAK
 (0x0964 0x0965	?X)			; DANDA .. DOUBLE DANDA
 (0x200C	?N)			; ZWNJ
 (0x200D	?J)			; ZWJ
 )

;; Compose consonant and nukta
(generator
 (0
  (cond
   ((0x0A32 0x0A3C) 0x0A33)
   ((0x0A38 0x0A3C) 0x0A36)
   ((0x0A16 0x0A3C) 0x0A59)
   ((0x0A17 0x0A3C) 0x0A5A)
   ((0x0A1C 0x0A3C) 0x0A5B)
   ((0x0A2B 0x0A3C) 0x0A5E)
   ("." =))
  *))

;; Reordering
(generator
 (0
  (cond
   ;; A syllable with vowel signs.
   ;;1       2           34   5       6   7
   ("([CRY]n?(H[CRY]n?)*)((m)|(ub?|b)|(p))(A?a?d?)"
    < | (4 =) (1 pre-below) (5 = *) (1 post) (6 =) (7 = *) | >)

   ;; A syllable with vowel modifiers or an Addak.
   ;;1       2           3
   ("([CRY]n?(H[CRY]n?)*)(Aa?d?|ad?|d)"
    < | (1 pre-below) (1 post) (3 = *) | >)

   ;; Add a ZWNJ explicitly when a syllable ends with a halant.
   ;;1       2           3
   ("([CRY]n?(H[CRY]n?)*)(HN?)?"
    < | (1 pre-below) (3 = 0x200C) (1 post) | >)

   ;; A syllable starting with an independent vowel.
   ;; In older texts, LETTER OO may followed by VOWEL SIGN U.
   ("Vb?A?a?d?"
    < | = * | >)

   ("." =))
  *)

 ;; Move the halant after the base consonant to the end.
 ;; Fill the resulting gap with a special mark.
 ;; Remove post-base parts.
 (pre-below
  (cond
   ("(.+)(H)(R)(HY)?$"
    (1 = *) 0x0A00 (3 =) (2 =))
   ("(.+)HY$"
    (1 = *) 0x0A00)
   (".+"
    = * 0x0A00)))

 ;; Extract post-base parts and add a halant at the end.
 ;; Produce nothing if there are no post-base parts.
 (post
  (cond
   (".*(H)(Y)$"
    (2 =) (1 =))
   (".+"
    ))))

;; Apply language forms to concerning segments.  Note that the Saab
;; font generates below form with 'vatu' instead of 'blwf'.
(generator
 (0
  (cond
   ;; Explicit Halant.
   ;; 1       2    3   4
   (" ([^Z]+)Z(RH)?(H)N(YH)? "
    | (1 otf:guru=nukt+) (2 otf:guru=blwf,vatu+) (3 =) (4 otf:guru=pstf+) |)

   ;; Vowel signs and vowel modifiers.
   ;; 1   2       3    4     5    6
   (" (m)?([^Z]+)Z(RH)?(u?b?)(YH)?(p?A?a?d?) "
    | (1 =) (2 otf:guru=nukt+) (3 otf:guru=blwf,vatu+) (4 = *)
    (5 otf:guru=pstf+) (6 = *) |)

   ("." =))
  *))

;; Other features
(generator
 (0
  (cond
   (" ([^ ]+) "
    (1 otf:guru=vatu,pres,abvs,blws,psts,haln+abvm,blwm,dist))

   ("."
    [ = ]))
  *))

;; Copyright (C) 2004, 2007
;;   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:
