-;; thai-util.el -- utilities for Thai
+;;; thai-util.el --- utilities for Thai -*- coding: iso-2022-7bit; -*-
-;; Copyright (C) 1995 Free Software Foundation, Inc.
;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
+;; Licensed to the Free Software Foundation.
+;; Copyright (C) 2003
+;; National Institute of Advanced Industrial Science and Technology (AIST)
+;; Registration Number H13PRO009
-;; Keywords: mule, multilingual, thai
+;; Keywords: mule, multilingual, Thai, i18n
;; This file is part of GNU Emacs.
;; 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, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; 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:
;;; Code:
;; Setting information of Thai characters.
+(defconst thai-category-table (make-category-table))
+(define-category ?c "Thai consonant" thai-category-table)
+(define-category ?v "Thai upper/lower vowel" thai-category-table)
+(define-category ?t "Thai tone" thai-category-table)
+
+;; The general composing rules are as follows:
+;;
+;; T
+;; V T V T
+;; CV -> C, CT -> C, CVT -> C, Cv -> C, CvT -> C
+;; v v
+;;
+;; where C: consonant, V: vowel upper, v: vowel lower, T: tone mark.
+
+(defvar thai-composition-pattern "\\cc\\(\\ct\\|\\cv\\ct?\\)"
+ "Regular expression matching a Thai composite sequence.")
+
(let ((l '((?\e,T!\e(B consonant "LETTER KO KAI") ; 0xA1
(?\e,T"\e(B consonant "LETTER KHO KHAI") ; 0xA2
(?\e,T#\e(B consonant "LETTER KHO KHUAT") ; 0xA3
))
elm)
(while l
- (setq elm (car l))
- (put-char-code-property (car elm) 'phonetic-type (car (cdr elm)))
- (put-char-code-property (car elm) 'name (nth 2 elm))
- (setq l (cdr l))))
+ (setq elm (car l) l (cdr l))
+ (let ((char (car elm))
+ (ptype (nth 1 elm)))
+ (put-char-code-property char 'phonetic-type ptype)
+ (cond ((eq ptype 'consonant)
+ (modify-category-entry char ?c thai-category-table))
+ ((memq ptype '(vowel-upper vowel-lower))
+ (modify-category-entry char ?v thai-category-table))
+ ((eq ptype 'tone)
+ (modify-category-entry char ?t thai-category-table)))
+ (put-char-code-property char 'name (nth 2 elm)))))
;;;###autoload
(defun thai-compose-region (beg end)
(interactive "r")
(save-restriction
(narrow-to-region beg end)
- (decompose-region (point-min) (point-max))
(goto-char (point-min))
- (while (re-search-forward "\\c0\\(\\c2\\|\\c3\\|\\c4\\)+" nil t)
- (if (aref (char-category-set (char-after (match-beginning 0))) ?t)
- (compose-region (match-beginning 0) (match-end 0))))))
+ (with-category-table thai-category-table
+ (while (re-search-forward thai-composition-pattern nil t)
+ (compose-region (match-beginning 0) (match-end 0))))))
+
+;;;###autoload
+(defun thai-compose-string (string)
+ "Compose Thai characters in STRING and return the resulting string."
+ (with-category-table thai-category-table
+ (let ((idx 0))
+ (while (setq idx (string-match thai-composition-pattern string idx))
+ (compose-string string idx (match-end 0))
+ (setq idx (match-end 0)))))
+ string)
;;;###autoload
(defun thai-compose-buffer ()
(thai-compose-region (point-min) (point-max)))
;;;###autoload
-(defun thai-post-read-conversion (len)
- (save-excursion
- (save-restriction
- (let ((buffer-modified-p (buffer-modified-p)))
- (narrow-to-region (point) (+ (point) len))
- (thai-compose-region (point-min) (point-max))
- (set-buffer-modified-p buffer-modified-p)
- (point-max)))))
-
-;;;###autoload
-(defun thai-pre-write-conversion (from to)
- (let ((old-buf (current-buffer))
- (work-buf (get-buffer-create " *thai-work*")))
- (set-buffer work-buf)
- (erase-buffer)
- (insert-buffer-substring old-buf from to)
- (decompose-region (point-min) (point-max))))
+(defun thai-composition-function (pos &optional string)
+ (setq pos (1- pos))
+ (let ((pattern "[\e,T!\e(B-\e,TCEG\e(B-\e,TN!\e(B-\e,TCEG\e(B-\e,TN\e(B][\e,TQT\e(B-\e,TWgnX\e(B-\e,TZQT\e(B-\e,TWgnX\e(B-\e,TZ\e(B]?[\e,Th\e(B-\e,Tmh\e(B-\e,Tm\e(B]?"))
+ (if string
+ (if (and (>= pos 0)
+ (eq (string-match pattern string pos) pos))
+ (prog1 (match-end 0)
+ (compose-string string pos (match-end 0))))
+ (if (>= pos (point-min))
+ (progn
+ (goto-char pos)
+ (if (looking-at pattern)
+ (prog1 (match-end 0)
+ (compose-region pos (match-end 0)))))))))
;;
-(provide 'language/thai-util)
+(provide 'thai-util)
-;;; Local Variables:
-;;; generated-autoload-file: "../loaddefs.el"
-;;; End:
+;;; arch-tag: 59425d6a-8cf9-4e06-a6ab-8ab7dc7a7a97
;;; thai-util.el ends here
-