]> code.delx.au - gnu-emacs/blob - lisp/language/thai-util.el
*** empty log message ***
[gnu-emacs] / lisp / language / thai-util.el
1 ;;; thai-util.el --- utilities for Thai -*- coding: iso-2022-7bit; -*-
2
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5 ;; Copyright (C) 2003
6 ;; National Institute of Advanced Industrial Science and Technology (AIST)
7 ;; Registration Number H13PRO009
8
9 ;; Keywords: mule, multilingual, Thai, i18n
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
27
28 ;;; Commentary:
29
30 ;;; Code:
31
32 ;; Setting information of Thai characters.
33
34 (defconst thai-category-table (make-category-table))
35 (define-category ?c "Thai consonant" thai-category-table)
36 (define-category ?v "Thai upper/lower vowel" thai-category-table)
37 (define-category ?t "Thai tone" thai-category-table)
38
39 ;; The general composing rules are as follows:
40 ;;
41 ;; T
42 ;; V T V T
43 ;; CV -> C, CT -> C, CVT -> C, Cv -> C, CvT -> C
44 ;; v v
45 ;;
46 ;; where C: consonant, V: vowel upper, v: vowel lower, T: tone mark.
47
48 (defvar thai-composition-pattern "\\cc\\(\\ct\\|\\cv\\ct?\\)"
49 "Regular expression matching a Thai composite sequence.")
50
51 (let ((l '((?\e,T!\e(B consonant "LETTER KO KAI") ; 0xA1
52 (?\e,T"\e(B consonant "LETTER KHO KHAI") ; 0xA2
53 (?\e,T#\e(B consonant "LETTER KHO KHUAT") ; 0xA3
54 (?\e,T$\e(B consonant "LETTER KHO KHWAI") ; 0xA4
55 (?\e,T%\e(B consonant "LETTER KHO KHON") ; 0xA5
56 (?\e,T&\e(B consonant "LETTER KHO RAKHANG") ; 0xA6
57 (?\e,T'\e(B consonant "LETTER NGO NGU") ; 0xA7
58 (?\e,T(\e(B consonant "LETTER CHO CHAN") ; 0xA8
59 (?\e,T)\e(B consonant "LETTER CHO CHING") ; 0xA9
60 (?\e,T*\e(B consonant "LETTER CHO CHANG") ; 0xAA
61 (?\e,T+\e(B consonant "LETTER SO SO") ; 0xAB
62 (?\e,T,\e(B consonant "LETTER CHO CHOE") ; 0xAC
63 (?\e,T-\e(B consonant "LETTER YO YING") ; 0xAD
64 (?\e,T.\e(B consonant "LETTER DO CHADA") ; 0xAE
65 (?\e,T/\e(B consonant "LETTER TO PATAK") ; 0xAF
66 (?\e,T0\e(B consonant "LETTER THO THAN") ; 0xB0
67 (?\e,T1\e(B consonant "LETTER THO NANGMONTHO") ; 0xB1
68 (?\e,T2\e(B consonant "LETTER THO PHUTHAO") ; 0xB2
69 (?\e,T3\e(B consonant "LETTER NO NEN") ; 0xB3
70 (?\e,T4\e(B consonant "LETTER DO DEK") ; 0xB4
71 (?\e,T5\e(B consonant "LETTER TO TAO") ; 0xB5
72 (?\e,T6\e(B consonant "LETTER THO THUNG") ; 0xB6
73 (?\e,T7\e(B consonant "LETTER THO THAHAN") ; 0xB7
74 (?\e,T8\e(B consonant "LETTER THO THONG") ; 0xB8
75 (?\e,T9\e(B consonant "LETTER NO NU") ; 0xB9
76 (?\e,T:\e(B consonant "LETTER BO BAIMAI") ; 0xBA
77 (?\e,T;\e(B consonant "LETTER PO PLA") ; 0xBB
78 (?\e,T<\e(B consonant "LETTER PHO PHUNG") ; 0xBC
79 (?\e,T=\e(B consonant "LETTER FO FA") ; 0xBD
80 (?\e,T>\e(B consonant "LETTER PHO PHAN") ; 0xBE
81 (?\e,T?\e(B consonant "LETTER FO FAN") ; 0xBF
82 (?\e,T@\e(B consonant "LETTER PHO SAMPHAO") ; 0xC0
83 (?\e,TA\e(B consonant "LETTER MO MA") ; 0xC1
84 (?\e,TB\e(B consonant "LETTER YO YAK") ; 0xC2
85 (?\e,TC\e(B consonant "LETTER RO RUA") ; 0xC3
86 (?\e,TD\e(B vowel-base "LETTER RU (Pali vowel letter)") ; 0xC4
87 (?\e,TE\e(B consonant "LETTER LO LING") ; 0xC5
88 (?\e,TF\e(B vowel-base "LETTER LU (Pali vowel letter)") ; 0xC6
89 (?\e,TG\e(B consonant "LETTER WO WAEN") ; 0xC7
90 (?\e,TH\e(B consonant "LETTER SO SALA") ; 0xC8
91 (?\e,TI\e(B consonant "LETTER SO RUSI") ; 0xC9
92 (?\e,TJ\e(B consonant "LETTER SO SUA") ; 0xCA
93 (?\e,TK\e(B consonant "LETTER HO HIP") ; 0xCB
94 (?\e,TL\e(B consonant "LETTER LO CHULA") ; 0xCC
95 (?\e,TM\e(B consonant "LETTER O ANG") ; 0xCD
96 (?\e,TN\e(B consonant "LETTER HO NOK HUK") ; 0xCE
97 (?\e,TO\e(B special "PAI YAN NOI (abbreviation)") ; 0xCF
98 (?\e,TP\e(B vowel-base "VOWEL SIGN SARA A") ; 0xD0
99 (?\e,TQ\e(B vowel-upper "VOWEL SIGN MAI HAN-AKAT N/S-T") ; 0xD1
100 (?\e,TR\e(B vowel-base "VOWEL SIGN SARA AA") ; 0xD2
101 (?\e,TS\e(B vowel-base "VOWEL SIGN SARA AM") ; 0xD3
102 (?\e,TT\e(B vowel-upper "VOWEL SIGN SARA I N/S-T") ; 0xD4
103 (?\e,TU\e(B vowel-upper "VOWEL SIGN SARA II N/S-T") ; 0xD5
104 (?\e,TV\e(B vowel-upper "VOWEL SIGN SARA UE N/S-T") ; 0xD6
105 (?\e,TW\e(B vowel-upper "VOWEL SIGN SARA UEE N/S-T") ; 0xD7
106 (?\e,TX\e(B vowel-lower "VOWEL SIGN SARA U N/S-B") ; 0xD8
107 (?\e,TY\e(B vowel-lower "VOWEL SIGN SARA UU N/S-B") ; 0xD9
108 (?\e,TZ\e(B vowel-lower "VOWEL SIGN PHINTHU N/S-B (Pali virama)") ; 0xDA
109 (?\e,T[\e(B invalid nil) ; 0xDA
110 (?\e,T\\e(B invalid nil) ; 0xDC
111 (?\e,T]\e(B invalid nil) ; 0xDC
112 (?\e,T^\e(B invalid nil) ; 0xDC
113 (?\e,T_\e(B special "BAHT SIGN (currency symbol)") ; 0xDF
114 (?\e,T`\e(B vowel-base "VOWEL SIGN SARA E") ; 0xE0
115 (?\e,Ta\e(B vowel-base "VOWEL SIGN SARA AE") ; 0xE1
116 (?\e,Tb\e(B vowel-base "VOWEL SIGN SARA O") ; 0xE2
117 (?\e,Tc\e(B vowel-base "VOWEL SIGN SARA MAI MUAN") ; 0xE3
118 (?\e,Td\e(B vowel-base "VOWEL SIGN SARA MAI MALAI") ; 0xE4
119 (?\e,Te\e(B vowel-base "LAK KHANG YAO") ; 0xE5
120 (?\e,Tf\e(B special "MAI YAMOK (repetion)") ; 0xE6
121 (?\e,Tg\e(B vowel-upper "VOWEL SIGN MAI TAI KHU N/S-T") ; 0xE7
122 (?\e,Th\e(B tone "TONE MAI EK N/S-T") ; 0xE8
123 (?\e,Ti\e(B tone "TONE MAI THO N/S-T") ; 0xE9
124 (?\e,Tj\e(B tone "TONE MAI TRI N/S-T") ; 0xEA
125 (?\e,Tk\e(B tone "TONE MAI CHATTAWA N/S-T") ; 0xEB
126 (?\e,Tl\e(B tone "THANTHAKHAT N/S-T (cancellation mark)") ; 0xEC
127 (?\e,Tm\e(B tone "NIKKHAHIT N/S-T (final nasal)") ; 0xED
128 (?\e,Tn\e(B vowel-upper "YAMAKKAN N/S-T") ; 0xEE
129 (?\e,To\e(B special "FONRMAN") ; 0xEF
130 (?\e,Tp\e(B special "DIGIT ZERO") ; 0xF0
131 (?\e,Tq\e(B special "DIGIT ONE") ; 0xF1
132 (?\e,Tr\e(B special "DIGIT TWO") ; 0xF2
133 (?\e,Ts\e(B special "DIGIT THREE") ; 0xF3
134 (?\e,Tt\e(B special "DIGIT FOUR") ; 0xF4
135 (?\e,Tu\e(B special "DIGIT FIVE") ; 0xF5
136 (?\e,Tv\e(B special "DIGIT SIX") ; 0xF6
137 (?\e,Tw\e(B special "DIGIT SEVEN") ; 0xF7
138 (?\e,Tx\e(B special "DIGIT EIGHT") ; 0xF8
139 (?\e,Ty\e(B special "DIGIT NINE") ; 0xF9
140 (?\e,Tz\e(B special "ANGKHANKHU (ellipsis)") ; 0xFA
141 (?\e,T{\e(B special "KHOMUT (beginning of religious texts)") ; 0xFB
142 (?\e,T|\e(B invalid nil) ; 0xFC
143 (?\e,T}\e(B invalid nil) ; 0xFD
144 (?\e,T~\e(B invalid nil) ; 0xFE
145 ))
146 elm)
147 (while l
148 (setq elm (car l) l (cdr l))
149 (let ((char (car elm))
150 (ptype (nth 1 elm)))
151 (put-char-code-property char 'phonetic-type ptype)
152 (cond ((eq ptype 'consonant)
153 (modify-category-entry char ?c thai-category-table))
154 ((memq ptype '(vowel-upper vowel-lower))
155 (modify-category-entry char ?v thai-category-table))
156 ((eq ptype 'tone)
157 (modify-category-entry char ?t thai-category-table)))
158 (put-char-code-property char 'name (nth 2 elm)))))
159
160 ;;;###autoload
161 (defun thai-compose-region (beg end)
162 "Compose Thai characters in the region.
163 When called from a program, expects two arguments,
164 positions (integers or markers) specifying the region."
165 (interactive "r")
166 (save-restriction
167 (narrow-to-region beg end)
168 (goto-char (point-min))
169 (with-category-table thai-category-table
170 (while (re-search-forward thai-composition-pattern nil t)
171 (compose-region (match-beginning 0) (match-end 0))))))
172
173 ;;;###autoload
174 (defun thai-compose-string (string)
175 "Compose Thai characters in STRING and return the resulting string."
176 (with-category-table thai-category-table
177 (let ((idx 0))
178 (while (setq idx (string-match thai-composition-pattern string idx))
179 (compose-string string idx (match-end 0))
180 (setq idx (match-end 0)))))
181 string)
182
183 ;;;###autoload
184 (defun thai-compose-buffer ()
185 "Compose Thai characters in the current buffer."
186 (interactive)
187 (thai-compose-region (point-min) (point-max)))
188
189 ;;;###autoload
190 (defun thai-composition-function (pos &optional string)
191 (setq pos (1- pos))
192 (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]?"))
193 (if string
194 (if (and (>= pos 0)
195 (eq (string-match pattern string pos) pos))
196 (prog1 (match-end 0)
197 (compose-string string pos (match-end 0))))
198 (if (>= pos (point-min))
199 (progn
200 (goto-char pos)
201 (if (looking-at pattern)
202 (prog1 (match-end 0)
203 (compose-region pos (match-end 0)))))))))
204
205 ;;
206 (provide 'thai-util)
207
208 ;;; thai-util.el ends here