changeset 49702:369dbdebd88a

New file.
author Kenichi Handa <handa@m17n.org>
date Tue, 11 Feb 2003 01:38:31 +0000
parents 77c73732b535
children 664f9896e442
files lisp/language/malayalam.el lisp/language/mlm-util.el lisp/language/tamil.el lisp/language/tml-util.el
diffstat 4 files changed, 862 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lisp/language/malayalam.el	Tue Feb 11 01:38:31 2003 +0000
@@ -0,0 +1,46 @@
+;;; malayalam.el --- Support for Malayalam -*- coding: iso-2022-7bit; no-byte-compile: t -*-
+
+;; Copyright (C) 2003 Free Software Foundation, Inc.
+
+;; Maintainer:  KAWABATA, Taichi <kawabata@m17n.org>
+;; Keywords: multilingual, Indian, Malayalam
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs 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 General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;; This file defines language-info of Malayalam script.
+
+;;; Code:
+
+(set-language-info-alist
+ "Malayalam" '((charset mule-unicode-0100-24ff indian-glyph )
+               ;;          indian-2-column 
+               ;; comment out later
+               ;;          )
+		(coding-system utf-8)
+		(coding-priority utf-8)
+		(input-method . "malayalam-itrans")
+		(features mlm-util)
+		(documentation . "\
+South Indian language Malayalam is supported in this language environment."))
+ '("Indian"))
+
+(provide 'malayalam)
+
+;;; malayalam.el ends here
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lisp/language/mlm-util.el	Tue Feb 11 01:38:31 2003 +0000
@@ -0,0 +1,406 @@
+;;; mlm-util.el --- support for composing malayalam characters  -*-coding: iso-2022-7bit;-*-
+
+;; Copyright (C) 2003 Free Software Foundation, Inc.
+
+;; Maintainer:  KAWABATA, Taichi <kawabata@m17n.org>
+;; Keywords: multilingual, Malayalam
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs 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 General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;; Created: Feb. 11. 2003
+
+;;; Commentary:
+
+;; This file provides character(Unicode) to glyph(CDAC) conversion and
+;; composition of Malayalam script characters.
+
+;;; Code:
+
+;; Malayalam Composable Pattern
+;;    C .. Consonants
+;;    V .. Vowel
+;;    H .. Halant
+;;    M .. Matra
+;;    V .. Vowel
+;;    A .. Anuswar
+;;    D .. Chandrabindu
+;;    (N .. Zerowidth Non Joiner)
+;;    (J .. Zerowidth Joiner.  )
+;; 1. vowel
+;;  V(A|visargam)?
+;; 2. syllable : maximum of 5 consecutive consonants.  (e.g. kartsnya)
+;;  ((CH)?(CH)?(CH)?CH)?C(H|M?(A|D)?)?
+
+(defconst malayalam-consonant
+  "[$,1@5(B-$,1@Y(B]")
+
+(defconst malayalam-composable-pattern
+  (concat
+   "\\([$,1@%(B-$,1@4(B][$,1@"(B]?\\)\\|$,1@#(B"
+   "\\|\\("
+   "\\(?:\\(?:[$,1@5(B-$,1@Y(B]$,1@m(B\\)?\\(?:[$,1@5(B-$,1@Y(B]$,1@m(B\\)?\\(?:[$,1@5(B-$,1@Y(B]$,1@m(B\\)?[$,1@5(B-$,1@Y(B]$,1@m(B\\)?"
+   "[$,1@5(B-$,1@Y(B]\\(?:$,1@m(B\\|[$,1@^(B-$,1@c@f@g@h@j@j@k@l(B]?[$,1@"@m(B]?\\)?"
+   "\\)")
+  "Regexp matching a composable sequence of Malayalam characters.")
+
+;;;###autoload
+(defun malayalam-compose-region (from to)
+  (interactive "r")
+  (save-excursion
+    (save-restriction
+      (narrow-to-region from to)
+      (goto-char (point-min))
+      (while (re-search-forward malayalam-composable-pattern nil t)
+	(malayalam-compose-syllable-region (match-beginning 0)
+					    (match-end 0))))))
+(defun malayalam-compose-string (string)
+  (with-temp-buffer
+    (insert (decompose-string string))
+    (malayalam-compose-region (point-min) (point-max))
+    (buffer-string)))
+
+(defun malayalam-post-read-conversion (len)
+  (save-excursion
+    (save-restriction
+      (let ((buffer-modified-p (buffer-modified-p)))
+	(narrow-to-region (point) (+ (point) len))
+	(malayalam-compose-region (point-min) (point-max))
+	(set-buffer-modified-p buffer-modified-p)
+	(- (point-max) (point-min))))))
+
+(defun malayalam-range (from to)
+  "Make the list of the integers of range FROM to TO."
+  (let (result)
+    (while (<= from to) (setq result (cons to result) to (1- to))) result))
+
+(defun malayalam-regexp-of-hashtbl-keys (hashtbl)
+  "Return a regular expression that matches all keys in hashtable HASHTBL."
+  (let ((max-specpdl-size 1000))
+    (regexp-opt
+     (sort
+      (let (dummy)
+	(maphash (function (lambda (key val) (setq dummy (cons key dummy)))) hashtbl)
+	dummy)
+      (function (lambda (x y) (> (length x) (length y))))))))
+
+
+;;;###autoload
+(defun malayalam-composition-function (from to pattern  &optional string)
+  "Compose Malayalam characters in REGION, or STRING if specified.
+Assume that the REGION or STRING must fully match the composable 
+PATTERN regexp."
+  (if string (malayalam-compose-syllable-string string)
+    (malayalam-compose-syllable-region from to))
+  (- to from))
+
+;; Register a function to compose Malayalam characters.
+(mapc
+ (function (lambda (ucs)
+   (aset composition-function-table (decode-char 'ucs ucs)
+	 (list (cons malayalam-composable-pattern
+                     'malayalam-composition-function)))))
+ (nconc '(#x0d02 #x0d03) (malayalam-range #x0d05 #x0d39)))
+
+;; Notes on conversion steps.
+
+;; 1. chars to glyphs
+;;
+;; Simple replacement of characters to glyphs is done.
+
+;; 2. glyphs reordering.
+;;
+;; Two special reordering rule takes place.
+;; a. following "$,46[(B" goes to the front.
+;; b. following "$,46S6S(B", "$,46S(B" or "$,46T(B" goes to the front.
+;; This reordering occurs only to the last cluster of consonants.
+;; Preceding consonants with halant characters are not affected.
+
+;; 3. Composition.
+;;
+;; left modifiers will be attached at the left.
+;; others will be attached right.
+
+(defvar mlm-char-glyph
+  '(;; various signs
+    ("$,1@"(B" . "$,46W(B")
+    ("$,1@#(B" . "$,46X(B")
+    ;; Independent Vowels
+    ("$,1@%(B" . "$,46!(B")
+    ("$,1@&(B" . "$,46"(B")
+    ("$,1@'(B" . "$,46#(B")
+    ("$,1@((B" . "$,46#6U(B")
+    ("$,1@)(B" . "$,46$(B")
+    ("$,1@*(B" . "$,46$6U(B")
+    ("$,1@+(B" . "$,46%(B")
+    ("$,1@,(B" . "nil") ;; not in present use, not supported.
+    ("$,1@.(B" . "$,46&(B")
+    ("$,1@/(B" . "$,46'(B")
+    ("$,1@0(B" . "$,46S6&(B")
+    ("$,1@2(B" . "$,46((B")
+    ("$,1@3(B" . "$,46(6M(B")
+    ("$,1@4(B" . "$,46(6U(B")
+    ;; Consonants
+    ("$,1@5(B" . "$,46)(B")
+    ("$,1@5@m@5(B" . "$,47!(B")
+    ("$,1@5@m@7(B" . "$,47"(B")
+    ("$,1@5@m@W(B" . "$,47#(B")
+    ("$,1@5@m@?(B" . "$,47N(B") ;; ?
+    ("$,1@5@m@D(B" . "$,47`(B")
+    ("$,1@5@m@F(B" . "$,47f(B") ;; ? ;; vowel u?
+    ("$,1@5@m@5@m@F(B" . "$,47g(B") ;; ? ;; vowel u?
+
+    ("$,1@6(B" . "$,46*(B")
+
+    ("$,1@7(B" . "$,46+(B")
+    ("$,1@7@m@7(B" . "$,47$(B")
+    ("$,1@7@m@R(B" . "$,47%(B")
+    ("$,1@7@m@N(B" . "$,47\(B")
+    ("$,1@7@m@H(B" . "$,47a(B")
+
+    ("$,1@8(B" . "$,46,(B")
+
+    ("$,1@9(B" . "$,46-(B")
+    ("$,1@9@m@5(B" . "$,47&(B")
+    ("$,1@9@m@9(B" . "$,47'(B")
+    ("$,1@9@m@5@m@F(B" . "$,47h(B") ;; ? ;; vowel u?
+
+    ("$,1@:(B" . "$,46.(B")
+    ("$,1@:@m@:(B" . "$,47((B") ;; duplicate
+    ("$,1@:@m@;(B" . "$,47Q(B") ;; ?
+
+    ("$,1@;(B" . "$,46/(B")
+
+    ("$,1@<(B" . "$,460(B")
+    ("$,1@<@m@<(B" . "$,47V(B")
+    ("$,1@<@m@>(B" . "$,47Z(B")
+
+    ("$,1@=(B" . "$,461(B")
+
+    ("$,1@>(B" . "$,462(B")
+    ("$,1@>@m@:(B" . "$,47)(B")
+    ("$,1@>@m@>(B" . "$,47*(B")
+
+    ("$,1@?(B" . "$,463(B")
+    ("$,1@?@m@?(B" . "$,47+(B")
+
+    ("$,1@@(B" . "$,464(B")
+    ("$,1@A(B" . "$,465(B")
+    ("$,1@A@m@A(B" . "$,47M(B")
+    ("$,1@B(B" . "$,466(B")
+
+    ("$,1@C(B" . "$,467(B")
+    ("$,1@C@m(B" . "$,47,(B") ;; half consonant
+    ("$,1@C@m@?(B" . "$,47-(B")
+    ("$,1@C@m@C(B" . "$,47.(B")
+    ("$,1@C@m@N(B" . "$,47W(B")
+    ("$,1@C@m@G(B" . "$,47^(B") ;; ?
+    ("$,1@C@m@V(B" . "$,47i(B") ;; ?
+
+    ("$,1@D(B" . "$,468(B")
+    ("$,1@D@m@D(B" . "$,47/(B")
+    ("$,1@D@m@E(B" . "$,470(B")
+    ("$,1@D@m@X(B" . "$,47U(B")
+    ("$,1@D@m@M(B" . "$,47[(B")
+    ("$,1@D@m@N(B" . "$,47_(B")
+    ("$,1@D@m@F(B" . "$,47j(B") ;; ? ;; vowel u ?
+
+    ("$,1@E(B" . "$,469(B")
+
+    ("$,1@F(B" . "$,46:(B")
+    ("$,1@F@m@F(B" . "$,471(B")
+    ("$,1@F@m@G(B" . "$,472(B")
+
+    ("$,1@G(B" . "$,46;(B")
+
+    ("$,1@H(B" . "$,46<(B")
+    ("$,1@H@m(B" . "$,473(B") ;; half consonant
+    ("$,1@H@m@D(B" . "$,474(B")
+    ("$,1@H@m@F(B" . "$,475(B")
+    ("$,1@H@m@H(B" . "$,476(B")
+    ("$,1@H@m@N(B" . "$,477(B")
+    ("$,1@H@m@G(B" . "$,47T(B")
+    ("$,1@H@m@E(B" . "$,47Y(B")
+    ("$,1@H@m@Q(B" . "$,47b(B")
+    ("$,1@H@m@V(B" . "$,47k(B") ;; ?
+    ("$,1@H@m@H@m@V(B" . "$,47l(B") ;; ?
+
+    ("$,1@J(B" . "$,46=(B")
+    ("$,1@J@m@J(B" . "$,478(B") ;; duplicate
+    ("$,1@J@m@R(B" . "$,479(B") ;; lakar
+
+    ("$,1@K(B" . "$,46>(B")
+
+    ("$,1@L(B" . "$,46?(B")
+    ("$,1@L@m@L(B" . "$,47:(B") ;; duplicate
+    ("$,1@L@m@R(B" . "$,47;(B") ;; lakar
+    ("$,1@L@m@G(B" . "$,47O(B") ;; ?
+    ("$,1@L@m@F(B" . "$,47P(B") ;; ?
+
+    ("$,1@M(B" . "$,46@(B")
+
+    ("$,1@N(B" . "$,46A(B")
+    ("$,1@N@m@J(B" . "$,47<(B")
+    ("$,1@N@m@N(B" . "$,47=(B")
+    ("$,1@N@m@R(B" . "$,47>(B") ;; lakar
+
+    ("$,1@O(B" . "$,46B(B")
+    ("$,1@O@m@O(B" . "$,47?(B") ;; duplicate
+    ("$,1@O@m@5@m@5(B" . "$,47m(B") ;; ?
+
+    ("$,1@P(B" . "$,46C(B")
+    ("$,1@P@m(B" . "$,47@(B")
+
+    ("$,1@Q(B" . "$,46D(B")
+    ("$,1@Q@m(B" . "$,47@(B") ;; same glyph as "$,1@P@m(B"
+    ;;("$,1@Q@m@Q(B" . "$,47A(B")
+    ("$,1@Q@m@Q(B" . "$,47d(B")
+
+    ("$,1@R(B" . "$,46E(B")
+    ("$,1@R@m(B" . "$,47B(B")
+    ("$,1@R@m@R(B" . "$,47C(B") ;; lakar
+    ("$,1@R@m@J(B" . "$,47e(B") ;; ?
+
+    ("$,1@S(B" . "$,46F(B")
+    ("$,1@S@m(B" . "$,47D(B")
+    ("$,1@S@m@S(B" . "$,47E(B")
+
+    ("$,1@T(B" . "$,46G(B")
+    ("$,1@T@m(B" . "$,47D(B")
+
+    ("$,1@U(B" . "$,46H(B")
+    ("$,1@U@m@U(B" . "$,47F(B")
+
+    ("$,1@V(B" . "$,46I(B")
+    ("$,1@V@m@R(B" . "$,47G(B")
+    ("$,1@V@m@V(B" . "$,47H(B")
+    ("$,1@V@m@:(B" . "$,47](B")
+
+    ("$,1@W(B" . "$,46J(B")
+    ("$,1@W@m@?(B" . "$,47c(B")
+
+    ("$,1@X(B" . "$,46K(B")
+    ("$,1@X@m@R(B" . "$,47I(B")
+    ("$,1@X@m@X(B" . "$,47J(B")
+    ("$,1@X@m@Q@m@Q(B" . "$,47L(B")
+    ("$,1@X@m@E(B" . "$,47X(B")
+
+    ("$,1@Y(B" . "$,46L(B")
+    ("$,1@Y@m@R(B" . "$,47K(B")
+    ("$,1@Y@m@N(B" . "$,47R(B")
+    ("$,1@Y@m@H(B" . "$,47S(B")
+
+    ;; Dependent vowel signs
+    ("$,1@^(B" . "$,46M(B")
+    ("$,1@_(B" . "$,46N(B")
+    ("$,1@`(B" . "$,46O(B")
+    ("$,1@a(B" . "$,46P(B")
+    ("$,1@b(B" . "$,46Q(B")
+    ("$,1@c(B" . "$,46R(B")
+    ("$,1@f(B" . "$,46S(B")
+    ("$,1@g(B" . "$,46T(B")
+    ("$,1@h(B" . "$,46S6S(B")
+    ("$,1@j(B" . "$,46S6M(B")
+    ("$,1@k(B" . "$,46T6M(B")
+    ("$,1@l(B" . "$,46U(B")
+    ;; Various signs
+    ("$,1@m(B" . "$,46V(B")
+    ("$,1@m@O(B" . "$,46Y(B") ;; yakar
+    ("$,1@m@O@a(B" . "$,46\(B") ;; yakar + u ;; ?
+    ("$,1@m@O@b(B" . "$,46](B") ;; yakar + uu ;; ?
+    ("$,1@m@U(B" . "$,46Z(B") ;; vakar modifier
+    ("$,1@m@P(B" . "$,46[(B") ;; rakar modifier is the same to rra modifier.
+    ("$,1@m@Q(B" . "$,46[(B") ;; rrakar modifier
+    ("$,1@m@m(B" . "$,46V(B") ;; double omission sign to stop forming half consonant.
+    ("$,1@w(B" . "$,46U(B") ;; not in present use, already at 0D4C.
+    ))
+
+(defvar mlm-char-glyph-hash
+  (let* ((hash (make-hash-table :test 'equal)))
+    (mapc (function (lambda (x) (puthash (car x) (cdr x) hash)))
+	  mlm-char-glyph)
+    hash))
+
+(defvar mlm-char-glyph-regexp
+  (malayalam-regexp-of-hashtbl-keys mlm-char-glyph-hash))
+
+;; Malayalam languages needed to be reordered in a complex mannar.
+
+(defvar mlm-consonants
+  (concat
+  "$,46)6*6+6,6-6.6/606162636465666768696:6;6<6=6>6?6@6A6B6C6D6E6F6G6H6I6J6K6L(B"
+  "$,47!7"7#7$7%7&7'7(7)7*7+7,7-7.7/707172737475767778797:7;7<7=7>7?7@7A7B7C7D7E7F7G7H7I7J7K7L7M7N7O7P7Q7R7S7T7U7V7W7X7Y7Z7[7\7]7^7_7`7a7b7c7d7e(B"
+  ))
+
+(defvar mlm-consonants-regexp
+  (concat "\\($,46[(B?[" mlm-consonants "][$,46Y6Z(B]?\\)"))
+
+(defvar mlm-glyph-reorder-key-glyphs "[$,46[6S6T(B]")
+
+(defvar mlm-glyph-reordering-regexp-list
+  `((,(concat "\\([" mlm-consonants "][$,46Y6Z(B]?\\)$,46[(B") . "$,46[(B\\1")
+    (,(concat mlm-consonants-regexp "$,46S6S(B") . "$,46S6S(B\\1")
+    (,(concat mlm-consonants-regexp "$,46S(B") . "$,46S(B\\1")
+    (,(concat mlm-consonants-regexp "$,46T(B") . "$,46T(B\\1")))
+
+(defun malayalam-compose-syllable-string (string)
+  (with-temp-buffer
+    (insert (decompose-string string))
+    (malayalam-compose-syllable-region (point-min) (point-max))
+    (buffer-string)))
+
+(defun malayalam-compose-syllable-region (from to)
+  "Compose malayalam syllable in region FROM to TO."
+  (let (glyph-str
+	match-str
+	glyph-reorder-regexps
+	glyph-reorder-replace
+	glyph-reorder-regexp)
+    (save-excursion
+      (save-restriction
+        (narrow-to-region from to)
+        (goto-char (point-min))
+        ;; char-glyph-conversion
+        (while (re-search-forward mlm-char-glyph-regexp nil t)
+          (setq match-str (match-string 0))
+          (setq glyph-str
+                (concat glyph-str (gethash match-str mlm-char-glyph-hash))))
+        (when (string-match mlm-glyph-reorder-key-glyphs glyph-str)
+          ;; glyph reordering
+          (setq glyph-reorder-regexps mlm-glyph-reordering-regexp-list)
+          (while glyph-reorder-regexps
+            (setq glyph-reorder-regexp (caar glyph-reorder-regexps))
+            (setq glyph-reorder-replace (cdar glyph-reorder-regexps))
+            (setq glyph-reorder-regexps (cdr glyph-reorder-regexps))
+            (if (string-match glyph-reorder-regexp glyph-str)
+                (setq glyph-str
+                      (replace-match glyph-reorder-replace nil nil
+                                     glyph-str)))))
+        ;; concatenate and attach reference-points.
+        (setq glyph-str
+              (cdr
+               (apply
+                'nconc
+                (mapcar
+                 (function 
+                  (lambda (x) (list '(5 . 3) x))) ;; default ref. point.
+                 glyph-str))))
+        (compose-region from to glyph-str)))))
+
+(provide 'mlm-util)
+
+;;; devan-util.el ends here
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lisp/language/tamil.el	Tue Feb 11 01:38:31 2003 +0000
@@ -0,0 +1,43 @@
+;;; tamil.el --- Support for Tamil -*- coding: iso-2022-7bit; no-byte-compile: t -*-
+
+;; Copyright (C) 2003 Free Software Foundation, Inc.
+
+;; Maintainer: KAWABATA, Taichi <batta@beige.ocn.ne.jp>
+;; Keywords: multilingual, Indian, Tamil
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs 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 General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;; This file defines language-info of Tamil script.
+
+;;; Code:
+
+(set-language-info-alist
+ "Tamil" '((charset mule-unicode-0100-24ff indian-glyph )
+		(coding-system utf-8)
+		(coding-priority utf-8)
+		(input-method . "tamil-itrans")
+		(features tml-util)
+		(documentation . "\
+South Indian Language Tamikl supported in this language environment."))
+ '("Indian"))
+
+(provide 'tamil)
+
+;;; tamil.el ends here
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lisp/language/tml-util.el	Tue Feb 11 01:38:31 2003 +0000
@@ -0,0 +1,367 @@
+;;; tml-util.el --- support for composing tamil characters  -*-coding: iso-2022-7bit;-*-
+
+;; Copyright (C) 2001 Free Software Foundation, Inc.
+
+;; Maintainer: KAWABATA, Taichi <kawabata@m17n.org>
+;; Keywords: multilingual, Indian, Tamil
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs 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 General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;; Created: Nov. 08. 2002
+
+;;; Commentary:
+
+;; This file provides character(Unicode) to glyph(CDAC) conversion and
+;; composition of Tamil script characters.
+
+;;; Code:
+
+;; Tamil Composable Pattern
+;;    C .. Consonants
+;;    V .. Vowel
+;;    H .. Pulli
+;;    M .. Matra
+;;    V .. Vowel
+;;    A .. Anuswar
+;;    D .. Chandrabindu
+;; 1. vowel
+;;  V
+;; 2. syllable : only ligature-formed pattern forms composition.
+;;  (CkHCs|C)(H|M)?
+;; 3. sri special
+;;  (CsHCrVi)
+
+;;  oririnal
+;;  ((CH)?(CH)?(CH)?CH)?C(H|M?(A|D)?)?
+
+(defconst tamil-consonant
+  "[$,1<5(B-$,1<Y(B]")
+
+(defconst tamil-composable-pattern
+  (concat
+   "\\([$,1<%(B-$,1<4(B]\\)\\|"
+   "[$,1<"<#(B]\\|" ;; vowel modifier considered independent
+   "\\(\\(?:\\(?:$,1<5<m<W(B\\)\\|[$,1<5(B-$,1<Y(B]\\)[$,1<m<^(B-$,1<l(B]?\\)\\|"
+   "\\($,1<W<m<P<`(B\\)")
+  "Regexp matching a composable sequence of Tamil characters.")
+
+;;;###autoload
+(defun tamil-compose-region (from to)
+  (interactive "r")
+  (save-excursion
+    (save-restriction
+      (narrow-to-region from to)
+      (goto-char (point-min))
+      (while (re-search-forward tamil-composable-pattern nil t)
+	(tamil-compose-syllable-region (match-beginning 0)
+					    (match-end 0))))))
+(defun tamil-compose-string (string)
+  (with-temp-buffer
+    (insert (decompose-string string))
+    (tamil-compose-region (point-min) (point-max))
+    (buffer-string)))
+
+(defun tamil-post-read-conversion (len)
+  (save-excursion
+    (save-restriction
+      (let ((buffer-modified-p (buffer-modified-p)))
+	(narrow-to-region (point) (+ (point) len))
+	(tamil-compose-region (point-min) (point-max))
+	(set-buffer-modified-p buffer-modified-p)
+	(- (point-max) (point-min))))))
+
+(defun tamil-range (from to)
+  "Make the list of the integers of range FROM to TO."
+  (let (result)
+    (while (<= from to) (setq result (cons to result) to (1- to))) result))
+
+(defun tamil-regexp-of-hashtbl-keys (hashtbl)
+  "Return a regular expression that matches all keys in hashtable HASHTBL."
+  (let ((max-specpdl-size 1000))
+    (regexp-opt
+     (sort
+      (let (dummy)
+	(maphash (function (lambda (key val) (setq dummy (cons key dummy)))) hashtbl)
+	dummy)
+      (function (lambda (x y) (> (length x) (length y))))))))
+
+
+;;;###autoload
+(defun tamil-composition-function (from to pattern  &optional string)
+  "Compose Tamil characters in REGION, or STRING if specified.
+Assume that the REGION or STRING must fully match the composable 
+PATTERN regexp."
+  (if string (tamil-compose-syllable-string string)
+    (tamil-compose-syllable-region from to))
+  (- to from))
+
+;; Register a function to compose Tamil characters.
+(mapc
+ (function (lambda (ucs)
+   (aset composition-function-table (decode-char 'ucs ucs)
+	 (list (cons tamil-composable-pattern
+                     'tamil-composition-function)))))
+ (nconc '(#x0b82 #x0b83) (tamil-range #x0b85 #x0bb9)))
+
+;; Notes on conversion steps.
+
+;; 1. chars to glyphs
+;; Simple replacement of characters to glyphs is done.
+
+;; 2. glyphs reordering.
+;; following "$,4)j(B", "$,4)k(B", "$,4)l(B" goes to the front.
+
+;; 3. glyphs to glyphs
+;; reordered vowels are ligatured to consonants.
+
+;; 4. Composition.
+;; left modifiers will be attached at the left.
+;; others will be attached right.
+
+(defvar tml-char-glyph
+  '(;; various signs
+    ;;("$,1<"(B" . "")
+    ("$,1<#(B" . "$,4*G(B")
+    ;; Independent Vowels
+    ("$,1<%(B" . "$,4*<(B")
+    ("$,1<&(B" . "$,4*=(B")
+    ("$,1<'(B" . "$,4*>(B")
+    ("$,1<((B" . "$,4*?(B")
+    ("$,1<)(B" . "$,4*@(B")
+    ("$,1<*(B" . "$,4*A(B")
+    ("$,1<.(B" . "$,4*B(B")
+    ("$,1</(B" . "$,4*C(B")
+    ("$,1<0(B" . "$,4*D(B")
+    ("$,1<2(B" . "$,4*E(B")
+    ("$,1<3(B" . "$,4*F(B")
+    ("$,1<4(B" . "$,4*E*W(B")
+    ;; Consonants
+    ("$,1<5<m<W<m(B" . "$,4):(B")	; ks.
+    ("$,1<5<m<W(B" . "$,4*^(B")	; ks
+    ("$,1<5(B" . "$,4*H(B")
+
+    ("$,1<9(B" . "$,4*I(B")
+    ("$,1<:(B" . "$,4*J(B")
+    ("$,1<<(B" . "$,4*\(B")
+    ("$,1<<<m(B" . "$,4)8(B")
+    ("$,1<>(B" . "$,4*K(B")
+    ("$,1<?(B" . "$,4*L(B")
+    ("$,1<C(B" . "$,4*M(B")
+    ("$,1<D(B" . "$,4*N(B")
+    ("$,1<H(B" . "$,4*O(B")
+    ("$,1<I(B" . "$,4*Y(B")
+    ("$,1<I<m(B" . "$,4)a(B")
+    ("$,1<J(B" . "$,4*P(B")
+    ("$,1<N(B" . "$,4*Q(B")
+    ("$,1<O(B" . "$,4*R(B")
+    ("$,1<P(B" . "$,4*S(B")
+    ("$,1<Q(B" . "$,4*X(B")
+    ("$,1<R(B" . "$,4*T(B")
+    ("$,1<S(B" . "$,4*W(B")
+    ("$,1<T(B" . "$,4*V(B")
+    ("$,1<U(B" . "$,4*U(B")
+    ("$,1<W(B" . "$,4*[(B")
+    ("$,1<W<m(B" . "$,4)7(B")
+    ("$,1<W<m<P<`(B" . "$,4*_(B")
+    ("$,1<X(B" . "$,4*Z(B")
+    ("$,1<X<m(B" . "$,4)6(B")
+    ("$,1<Y(B" . "$,4*](B")
+    ("$,1<Y<m(B" . "$,4)9(B")
+
+    ;; Dependent vowel signs
+    ("$,1<^(B" . "$,4)c(B")
+    ("$,1<_(B" . "$,4)d(B")
+    ("$,1<`(B" . "$,4)f(B")
+    ("$,1<a(B" . "$,4)g(B")
+    ("$,1<b(B" . "$,4)h(B")
+    ("$,1<f(B" . "$,4)j(B")
+    ("$,1<g(B" . "$,4)k(B")
+    ("$,1<h(B" . "$,4)l(B")
+    ("$,1<j(B" . "$,4)j)c(B")
+    ("$,1<k(B" . "$,4)k)c(B")
+    ("$,1<l(B" . "$,4)j*W(B")
+
+    ;; Various signs
+    ("$,1<m(B" . "$,4)b(B")
+    ("$,1<w(B" . "nil") ;; not supported?
+    ))
+
+(defvar tml-char-glyph-hash
+  (let* ((hash (make-hash-table :test 'equal)))
+    (mapc (function (lambda (x) (puthash (car x) (cdr x) hash)))
+	  tml-char-glyph)
+    hash))
+
+(defvar tml-char-glyph-regexp
+  (tamil-regexp-of-hashtbl-keys tml-char-glyph-hash))
+
+;; Tamil languages needed to be reordered.
+
+(defvar tml-consonants-regexp
+  "[$,4*H*^*I*J*\*K*L*M*N*O*Y*P*Q*R*S*X*T*W*V*U*[*Z*](B]")
+
+(defvar tml-glyph-reorder-key-glyphs "[$,4)j)k)l(B]")
+
+(defvar tml-glyph-reordering-regexp-list
+  (cons
+   (concat "\\(" tml-consonants-regexp "\\)\\([$,4)j)k)l(B]\\)") "\\2\\1"))
+
+;; Tamil vowel modifiers to be ligatured.
+(defvar tml-glyph-glyph
+  '(
+    ("$,4*H)d(B" . "$,4(a(B")	; ki
+    ("$,4*^)d(B" . "$,4(v(B")	; ksi
+    ("$,4*^)f(B" . "$,4)2(B")	; ksi~
+    ("$,4*I)d(B" . "$,4(b(B")	; n^i
+    ("$,4*J)d(B" . "$,4(c(B")	; ci
+    ("$,4*K)d(B" . "$,4(d(B")	; n~i
+    ("$,4*L)d(B" . "$,4)n(B")	; t.i
+    ("$,4*M)d(B" . "$,4(e(B")	; n.i
+    ("$,4*N)d(B" . "$,4(f(B")	; ti
+    ("$,4*O)d(B" . "$,4(g(B")	; ni
+    ("$,4*P)d(B" . "$,4(h(B")	; pi
+    ("$,4*Q)d(B" . "$,4(i(B")	; mi
+    ("$,4*R)d(B" . "$,4(j(B")	; yi
+    ("$,4*S)d(B" . "$,4(k(B")	; ri
+    ("$,4*T)d(B" . "$,4(l(B")	; li
+    ("$,4*U)d(B" . "$,4(m(B")	; vi
+    ("$,4*V)d(B" . "$,4(n(B")	; l_i
+    ("$,4*W)d(B" . "$,4(o(B")	; l.i
+    ("$,4*X)d(B" . "$,4(p(B")	; r_i
+    ("$,4*Y)d(B" . "$,4(q(B")	; n_i
+    ("$,4*Z)d(B" . "$,4(r(B")	; si
+    ("$,4*[)d(B" . "$,4(s(B")	; s'i
+    ("$,4*\)d(B" . "$,4(t(B")	; ji
+    ("$,4*])d(B" . "$,4(u(B")	; hi
+
+    ("$,4*H)f(B" . "$,4(w(B")	; ki~
+    ("$,4*I)f(B" . "$,4(x(B")	; n^i~
+    ("$,4*J)f(B" . "$,4(y(B")	; ci~
+    ("$,4*K)f(B" . "$,4(z(B")	; n~i~
+    ("$,4*L)f(B" . "$,4)o(B")	; t.i~
+    ("$,4*M)f(B" . "$,4)!(B")	; n.i~
+    ("$,4*N)f(B" . "$,4)"(B")	; ti~
+    ("$,4*O)f(B" . "$,4)#(B")	; ni~
+    ("$,4*P)f(B" . "$,4)$(B")	; pi~
+    ("$,4*Q)f(B" . "$,4)%(B")	; mi~
+    ("$,4*R)f(B" . "$,4)&(B")	; yi~
+    ("$,4*S)f(B" . "$,4)'(B")	; ri~
+    ("$,4*T)f(B" . "$,4)((B")	; li~
+    ("$,4*U)f(B" . "$,4))(B")	; vi~
+    ("$,4*V)f(B" . "$,4)*(B")	; l_i~
+    ("$,4*W)f(B" . "$,4)+(B")	; l.i~
+    ("$,4*X)f(B" . "$,4),(B")	; r_i~
+    ("$,4*Y)f(B" . "$,4)-(B")	; n_i~
+    ("$,4*Z)f(B" . "$,4).(B")	; si~
+    ("$,4*[)f(B" . "$,4)/(B")	; s'i~
+    ("$,4*\)f(B" . "$,4)0(B")	; ji~
+    ("$,4*])f(B" . "$,4)1(B")	; hi~
+
+    ("$,4*H)g(B" . "$,4)p(B")	; ku
+    ("$,4*I)g(B" . "$,4)q(B")	; n^u
+    ("$,4*J)g(B" . "$,4)r(B")	; cu
+    ("$,4*K)g(B" . "$,4)s(B")	; n~u
+    ("$,4*L)g(B" . "$,4)t(B")	; t.u
+    ("$,4*M)g(B" . "$,4)u(B")	; n.u
+    ("$,4*N)g(B" . "$,4)v(B")	; tu
+    ("$,4*O)g(B" . "$,4)x(B")	; nu
+    ("$,4*P)g(B" . "$,4)y(B")	; pu
+    ("$,4*Q)g(B" . "$,4)z(B")	; mu
+    ("$,4*R)g(B" . "$,4){(B")	; yu
+    ("$,4*S)g(B" . "$,4)|(B")	; ru
+    ("$,4*T)g(B" . "$,4)}(B")	; lu
+    ("$,4*U)g(B" . "$,4)~(B")	; vu
+    ("$,4*V)g(B" . "$,4)(B")	; l_u
+    ("$,4*W)g(B" . "$,4* (B")	; l.u
+    ("$,4*X)g(B" . "$,4*!(B")	; r_u
+    ("$,4*Y)g(B" . "$,4*"(B")	; n_u
+
+    ("$,4*H)h(B" . "$,4*#(B")	; ku~
+    ("$,4*I)h(B" . "$,4*$(B")	; n^u~
+    ("$,4*J)h(B" . "$,4*%(B")	; cu~
+    ("$,4*K)h(B" . "$,4*&(B")	; n~u~
+    ("$,4*L)h(B" . "$,4*'(B")	; t.u~
+    ("$,4*M)h(B" . "$,4*((B")	; n.u~
+    ("$,4*N)h(B" . "$,4*)(B")	; tu~
+    ("$,4*O)h(B" . "$,4*+(B")	; nu~
+    ("$,4*P)h(B" . "$,4*,(B")	; pu~
+    ("$,4*Q)h(B" . "$,4*-(B")	; mu~
+    ("$,4*R)h(B" . "$,4*.(B")	; yu~
+    ("$,4*S)h(B" . "$,4*/(B")	; ru~
+    ("$,4*T)h(B" . "$,4*6(B")	; lu~
+    ("$,4*U)h(B" . "$,4*7(B")	; vu~
+    ("$,4*V)h(B" . "$,4*8(B")	; l_u~
+    ("$,4*W)h(B" . "$,4*9(B")	; l.u~
+    ("$,4*X)h(B" . "$,4*:(B")	; r_u~
+    ("$,4*Y)h(B" . "$,4*;(B")	; n_u~
+    ))
+
+(defvar tml-glyph-glyph-hash
+  (let* ((hash (make-hash-table :test 'equal)))
+    (mapc (function (lambda (x) (puthash (car x) (cdr x) hash)))
+	  tml-glyph-glyph)
+    hash))
+
+(defvar tml-glyph-glyph-regexp
+  (tamil-regexp-of-hashtbl-keys tml-glyph-glyph-hash))
+
+(defun tamil-compose-syllable-string (string)
+  (with-temp-buffer
+    (insert (decompose-string string))
+    (tamil-compose-syllable-region (point-min) (point-max))
+    (buffer-string)))
+
+(defun tamil-compose-syllable-region (from to)
+  "Compose tamil syllable in region FROM to TO."
+  (let (glyph-str match-str glyph-reorder-regexps)
+    (save-excursion
+      (save-restriction
+        (narrow-to-region from to)
+        (goto-char (point-min))
+        ;; char-glyph-conversion
+        (while (re-search-forward tml-char-glyph-regexp nil t)
+          (setq match-str (match-string 0))
+          (setq glyph-str
+                (concat glyph-str (gethash match-str tml-char-glyph-hash))))
+        ;; glyph reordering
+        (when (string-match tml-glyph-reorder-key-glyphs glyph-str)
+          (if (string-match (car tml-glyph-reordering-regexp-list)
+                            glyph-str)
+              (setq glyph-str
+                    (replace-match (cdr tml-glyph-reordering-regexp-list)
+                                   nil nil glyph-str))))
+        ;; glyph-glyph-conversion
+        (when (string-match tml-glyph-glyph-regexp glyph-str)
+          (setq match-str (match-string 0 glyph-str))
+          (setq glyph-str 
+                (replace-match (gethash match-str tml-glyph-glyph-hash)
+                               nil nil glyph-str)))
+        ;; concatenate and attach reference-points.
+        (setq glyph-str
+              (cdr
+               (apply
+                'nconc
+                (mapcar
+                 (function 
+                  (lambda (x) (list '(5 . 3) x))) ;; default ref. point.
+                 glyph-str))))
+        (compose-region from to glyph-str)))))
+
+(provide 'tml-util)
+
+;;; tml-util.el ends here