49702
|
1 ;;; tml-util.el --- support for composing tamil characters -*-coding: iso-2022-7bit;-*-
|
|
2
|
|
3 ;; Copyright (C) 2001 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Maintainer: KAWABATA, Taichi <kawabata@m17n.org>
|
|
6 ;; Keywords: multilingual, Indian, Tamil
|
|
7
|
|
8 ;; This file is part of GNU Emacs.
|
|
9
|
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
11 ;; it under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 ;; GNU General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 ;; Boston, MA 02111-1307, USA.
|
|
24
|
|
25 ;; Created: Nov. 08. 2002
|
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;; This file provides character(Unicode) to glyph(CDAC) conversion and
|
|
30 ;; composition of Tamil script characters.
|
|
31
|
|
32 ;;; Code:
|
|
33
|
|
34 ;; Tamil Composable Pattern
|
|
35 ;; C .. Consonants
|
|
36 ;; V .. Vowel
|
|
37 ;; H .. Pulli
|
|
38 ;; M .. Matra
|
|
39 ;; V .. Vowel
|
|
40 ;; A .. Anuswar
|
|
41 ;; D .. Chandrabindu
|
|
42 ;; 1. vowel
|
|
43 ;; V
|
|
44 ;; 2. syllable : only ligature-formed pattern forms composition.
|
|
45 ;; (CkHCs|C)(H|M)?
|
|
46 ;; 3. sri special
|
|
47 ;; (CsHCrVi)
|
|
48
|
|
49 ;; oririnal
|
|
50 ;; ((CH)?(CH)?(CH)?CH)?C(H|M?(A|D)?)?
|
|
51
|
|
52 (defconst tamil-consonant
|
|
53 "[$,1<5(B-$,1<Y(B]")
|
|
54
|
|
55 (defconst tamil-composable-pattern
|
|
56 (concat
|
|
57 "\\([$,1<%(B-$,1<4(B]\\)\\|"
|
|
58 "[$,1<"<#(B]\\|" ;; vowel modifier considered independent
|
|
59 "\\(\\(?:\\(?:$,1<5<m<W(B\\)\\|[$,1<5(B-$,1<Y(B]\\)[$,1<m<^(B-$,1<l(B]?\\)\\|"
|
|
60 "\\($,1<W<m<P<`(B\\)")
|
|
61 "Regexp matching a composable sequence of Tamil characters.")
|
|
62
|
|
63 ;;;###autoload
|
|
64 (defun tamil-compose-region (from to)
|
|
65 (interactive "r")
|
|
66 (save-excursion
|
|
67 (save-restriction
|
|
68 (narrow-to-region from to)
|
|
69 (goto-char (point-min))
|
|
70 (while (re-search-forward tamil-composable-pattern nil t)
|
|
71 (tamil-compose-syllable-region (match-beginning 0)
|
|
72 (match-end 0))))))
|
|
73 (defun tamil-compose-string (string)
|
|
74 (with-temp-buffer
|
|
75 (insert (decompose-string string))
|
|
76 (tamil-compose-region (point-min) (point-max))
|
|
77 (buffer-string)))
|
|
78
|
|
79 (defun tamil-post-read-conversion (len)
|
|
80 (save-excursion
|
|
81 (save-restriction
|
|
82 (let ((buffer-modified-p (buffer-modified-p)))
|
|
83 (narrow-to-region (point) (+ (point) len))
|
|
84 (tamil-compose-region (point-min) (point-max))
|
|
85 (set-buffer-modified-p buffer-modified-p)
|
|
86 (- (point-max) (point-min))))))
|
|
87
|
|
88 (defun tamil-range (from to)
|
|
89 "Make the list of the integers of range FROM to TO."
|
|
90 (let (result)
|
|
91 (while (<= from to) (setq result (cons to result) to (1- to))) result))
|
|
92
|
|
93 (defun tamil-regexp-of-hashtbl-keys (hashtbl)
|
|
94 "Return a regular expression that matches all keys in hashtable HASHTBL."
|
|
95 (let ((max-specpdl-size 1000))
|
|
96 (regexp-opt
|
|
97 (sort
|
|
98 (let (dummy)
|
|
99 (maphash (function (lambda (key val) (setq dummy (cons key dummy)))) hashtbl)
|
|
100 dummy)
|
|
101 (function (lambda (x y) (> (length x) (length y))))))))
|
|
102
|
|
103
|
|
104 ;; Notes on conversion steps.
|
|
105
|
|
106 ;; 1. chars to glyphs
|
|
107 ;; Simple replacement of characters to glyphs is done.
|
|
108
|
|
109 ;; 2. glyphs reordering.
|
|
110 ;; following "$,4)j(B", "$,4)k(B", "$,4)l(B" goes to the front.
|
|
111
|
|
112 ;; 3. glyphs to glyphs
|
|
113 ;; reordered vowels are ligatured to consonants.
|
|
114
|
|
115 ;; 4. Composition.
|
|
116 ;; left modifiers will be attached at the left.
|
|
117 ;; others will be attached right.
|
|
118
|
|
119 (defvar tml-char-glyph
|
|
120 '(;; various signs
|
89483
|
121 ("$,1<"(B" . "$,4)b(B") ;; not good
|
49702
|
122 ("$,1<#(B" . "$,4*G(B")
|
|
123 ;; Independent Vowels
|
|
124 ("$,1<%(B" . "$,4*<(B")
|
|
125 ("$,1<&(B" . "$,4*=(B")
|
|
126 ("$,1<'(B" . "$,4*>(B")
|
|
127 ("$,1<((B" . "$,4*?(B")
|
|
128 ("$,1<)(B" . "$,4*@(B")
|
|
129 ("$,1<*(B" . "$,4*A(B")
|
|
130 ("$,1<.(B" . "$,4*B(B")
|
|
131 ("$,1</(B" . "$,4*C(B")
|
|
132 ("$,1<0(B" . "$,4*D(B")
|
|
133 ("$,1<2(B" . "$,4*E(B")
|
|
134 ("$,1<3(B" . "$,4*F(B")
|
|
135 ("$,1<4(B" . "$,4*E*W(B")
|
|
136 ;; Consonants
|
|
137 ("$,1<5<m<W<m(B" . "$,4):(B") ; ks.
|
|
138 ("$,1<5<m<W(B" . "$,4*^(B") ; ks
|
|
139 ("$,1<5(B" . "$,4*H(B")
|
|
140
|
|
141 ("$,1<9(B" . "$,4*I(B")
|
|
142 ("$,1<:(B" . "$,4*J(B")
|
|
143 ("$,1<<(B" . "$,4*\(B")
|
|
144 ("$,1<<<m(B" . "$,4)8(B")
|
|
145 ("$,1<>(B" . "$,4*K(B")
|
|
146 ("$,1<?(B" . "$,4*L(B")
|
|
147 ("$,1<C(B" . "$,4*M(B")
|
|
148 ("$,1<D(B" . "$,4*N(B")
|
|
149 ("$,1<H(B" . "$,4*O(B")
|
|
150 ("$,1<I(B" . "$,4*Y(B")
|
|
151 ("$,1<I<m(B" . "$,4)a(B")
|
|
152 ("$,1<J(B" . "$,4*P(B")
|
|
153 ("$,1<N(B" . "$,4*Q(B")
|
|
154 ("$,1<O(B" . "$,4*R(B")
|
|
155 ("$,1<P(B" . "$,4*S(B")
|
|
156 ("$,1<Q(B" . "$,4*X(B")
|
|
157 ("$,1<R(B" . "$,4*T(B")
|
|
158 ("$,1<S(B" . "$,4*W(B")
|
|
159 ("$,1<T(B" . "$,4*V(B")
|
|
160 ("$,1<U(B" . "$,4*U(B")
|
|
161 ("$,1<W(B" . "$,4*[(B")
|
|
162 ("$,1<W<m(B" . "$,4)7(B")
|
|
163 ("$,1<W<m<P<`(B" . "$,4*_(B")
|
|
164 ("$,1<X(B" . "$,4*Z(B")
|
|
165 ("$,1<X<m(B" . "$,4)6(B")
|
|
166 ("$,1<Y(B" . "$,4*](B")
|
|
167 ("$,1<Y<m(B" . "$,4)9(B")
|
|
168
|
|
169 ;; Dependent vowel signs
|
|
170 ("$,1<^(B" . "$,4)c(B")
|
|
171 ("$,1<_(B" . "$,4)d(B")
|
|
172 ("$,1<`(B" . "$,4)f(B")
|
|
173 ("$,1<a(B" . "$,4)g(B")
|
|
174 ("$,1<b(B" . "$,4)h(B")
|
|
175 ("$,1<f(B" . "$,4)j(B")
|
|
176 ("$,1<g(B" . "$,4)k(B")
|
|
177 ("$,1<h(B" . "$,4)l(B")
|
|
178 ("$,1<j(B" . "$,4)j)c(B")
|
|
179 ("$,1<k(B" . "$,4)k)c(B")
|
|
180 ("$,1<l(B" . "$,4)j*W(B")
|
|
181
|
|
182 ;; Various signs
|
|
183 ("$,1<m(B" . "$,4)b(B")
|
|
184 ("$,1<w(B" . "nil") ;; not supported?
|
|
185 ))
|
|
186
|
|
187 (defvar tml-char-glyph-hash
|
|
188 (let* ((hash (make-hash-table :test 'equal)))
|
|
189 (mapc (function (lambda (x) (puthash (car x) (cdr x) hash)))
|
|
190 tml-char-glyph)
|
|
191 hash))
|
|
192
|
|
193 (defvar tml-char-glyph-regexp
|
|
194 (tamil-regexp-of-hashtbl-keys tml-char-glyph-hash))
|
|
195
|
|
196 ;; Tamil languages needed to be reordered.
|
|
197
|
|
198 (defvar tml-consonants-regexp
|
|
199 "[$,4*H*^*I*J*\*K*L*M*N*O*Y*P*Q*R*S*X*T*W*V*U*[*Z*](B]")
|
|
200
|
|
201 (defvar tml-glyph-reorder-key-glyphs "[$,4)j)k)l(B]")
|
|
202
|
|
203 (defvar tml-glyph-reordering-regexp-list
|
|
204 (cons
|
|
205 (concat "\\(" tml-consonants-regexp "\\)\\([$,4)j)k)l(B]\\)") "\\2\\1"))
|
|
206
|
|
207 ;; Tamil vowel modifiers to be ligatured.
|
|
208 (defvar tml-glyph-glyph
|
|
209 '(
|
|
210 ("$,4*H)d(B" . "$,4(a(B") ; ki
|
|
211 ("$,4*^)d(B" . "$,4(v(B") ; ksi
|
|
212 ("$,4*^)f(B" . "$,4)2(B") ; ksi~
|
|
213 ("$,4*I)d(B" . "$,4(b(B") ; n^i
|
|
214 ("$,4*J)d(B" . "$,4(c(B") ; ci
|
|
215 ("$,4*K)d(B" . "$,4(d(B") ; n~i
|
|
216 ("$,4*L)d(B" . "$,4)n(B") ; t.i
|
|
217 ("$,4*M)d(B" . "$,4(e(B") ; n.i
|
|
218 ("$,4*N)d(B" . "$,4(f(B") ; ti
|
|
219 ("$,4*O)d(B" . "$,4(g(B") ; ni
|
|
220 ("$,4*P)d(B" . "$,4(h(B") ; pi
|
|
221 ("$,4*Q)d(B" . "$,4(i(B") ; mi
|
|
222 ("$,4*R)d(B" . "$,4(j(B") ; yi
|
|
223 ("$,4*S)d(B" . "$,4(k(B") ; ri
|
|
224 ("$,4*T)d(B" . "$,4(l(B") ; li
|
|
225 ("$,4*U)d(B" . "$,4(m(B") ; vi
|
|
226 ("$,4*V)d(B" . "$,4(n(B") ; l_i
|
|
227 ("$,4*W)d(B" . "$,4(o(B") ; l.i
|
|
228 ("$,4*X)d(B" . "$,4(p(B") ; r_i
|
|
229 ("$,4*Y)d(B" . "$,4(q(B") ; n_i
|
|
230 ("$,4*Z)d(B" . "$,4(r(B") ; si
|
|
231 ("$,4*[)d(B" . "$,4(s(B") ; s'i
|
|
232 ("$,4*\)d(B" . "$,4(t(B") ; ji
|
|
233 ("$,4*])d(B" . "$,4(u(B") ; hi
|
|
234
|
|
235 ("$,4*H)f(B" . "$,4(w(B") ; ki~
|
|
236 ("$,4*I)f(B" . "$,4(x(B") ; n^i~
|
|
237 ("$,4*J)f(B" . "$,4(y(B") ; ci~
|
|
238 ("$,4*K)f(B" . "$,4(z(B") ; n~i~
|
|
239 ("$,4*L)f(B" . "$,4)o(B") ; t.i~
|
|
240 ("$,4*M)f(B" . "$,4)!(B") ; n.i~
|
|
241 ("$,4*N)f(B" . "$,4)"(B") ; ti~
|
|
242 ("$,4*O)f(B" . "$,4)#(B") ; ni~
|
|
243 ("$,4*P)f(B" . "$,4)$(B") ; pi~
|
|
244 ("$,4*Q)f(B" . "$,4)%(B") ; mi~
|
|
245 ("$,4*R)f(B" . "$,4)&(B") ; yi~
|
|
246 ("$,4*S)f(B" . "$,4)'(B") ; ri~
|
|
247 ("$,4*T)f(B" . "$,4)((B") ; li~
|
|
248 ("$,4*U)f(B" . "$,4))(B") ; vi~
|
|
249 ("$,4*V)f(B" . "$,4)*(B") ; l_i~
|
|
250 ("$,4*W)f(B" . "$,4)+(B") ; l.i~
|
|
251 ("$,4*X)f(B" . "$,4),(B") ; r_i~
|
|
252 ("$,4*Y)f(B" . "$,4)-(B") ; n_i~
|
|
253 ("$,4*Z)f(B" . "$,4).(B") ; si~
|
|
254 ("$,4*[)f(B" . "$,4)/(B") ; s'i~
|
|
255 ("$,4*\)f(B" . "$,4)0(B") ; ji~
|
|
256 ("$,4*])f(B" . "$,4)1(B") ; hi~
|
|
257
|
|
258 ("$,4*H)g(B" . "$,4)p(B") ; ku
|
|
259 ("$,4*I)g(B" . "$,4)q(B") ; n^u
|
|
260 ("$,4*J)g(B" . "$,4)r(B") ; cu
|
|
261 ("$,4*K)g(B" . "$,4)s(B") ; n~u
|
|
262 ("$,4*L)g(B" . "$,4)t(B") ; t.u
|
|
263 ("$,4*M)g(B" . "$,4)u(B") ; n.u
|
|
264 ("$,4*N)g(B" . "$,4)v(B") ; tu
|
|
265 ("$,4*O)g(B" . "$,4)x(B") ; nu
|
|
266 ("$,4*P)g(B" . "$,4)y(B") ; pu
|
|
267 ("$,4*Q)g(B" . "$,4)z(B") ; mu
|
|
268 ("$,4*R)g(B" . "$,4){(B") ; yu
|
|
269 ("$,4*S)g(B" . "$,4)|(B") ; ru
|
|
270 ("$,4*T)g(B" . "$,4)}(B") ; lu
|
|
271 ("$,4*U)g(B" . "$,4)~(B") ; vu
|
|
272 ("$,4*V)g(B" . "$,4)(B") ; l_u
|
|
273 ("$,4*W)g(B" . "$,4* (B") ; l.u
|
|
274 ("$,4*X)g(B" . "$,4*!(B") ; r_u
|
|
275 ("$,4*Y)g(B" . "$,4*"(B") ; n_u
|
|
276
|
|
277 ("$,4*H)h(B" . "$,4*#(B") ; ku~
|
|
278 ("$,4*I)h(B" . "$,4*$(B") ; n^u~
|
|
279 ("$,4*J)h(B" . "$,4*%(B") ; cu~
|
|
280 ("$,4*K)h(B" . "$,4*&(B") ; n~u~
|
|
281 ("$,4*L)h(B" . "$,4*'(B") ; t.u~
|
|
282 ("$,4*M)h(B" . "$,4*((B") ; n.u~
|
|
283 ("$,4*N)h(B" . "$,4*)(B") ; tu~
|
|
284 ("$,4*O)h(B" . "$,4*+(B") ; nu~
|
|
285 ("$,4*P)h(B" . "$,4*,(B") ; pu~
|
|
286 ("$,4*Q)h(B" . "$,4*-(B") ; mu~
|
|
287 ("$,4*R)h(B" . "$,4*.(B") ; yu~
|
|
288 ("$,4*S)h(B" . "$,4*/(B") ; ru~
|
|
289 ("$,4*T)h(B" . "$,4*6(B") ; lu~
|
|
290 ("$,4*U)h(B" . "$,4*7(B") ; vu~
|
|
291 ("$,4*V)h(B" . "$,4*8(B") ; l_u~
|
|
292 ("$,4*W)h(B" . "$,4*9(B") ; l.u~
|
|
293 ("$,4*X)h(B" . "$,4*:(B") ; r_u~
|
|
294 ("$,4*Y)h(B" . "$,4*;(B") ; n_u~
|
|
295 ))
|
|
296
|
|
297 (defvar tml-glyph-glyph-hash
|
|
298 (let* ((hash (make-hash-table :test 'equal)))
|
|
299 (mapc (function (lambda (x) (puthash (car x) (cdr x) hash)))
|
|
300 tml-glyph-glyph)
|
|
301 hash))
|
|
302
|
|
303 (defvar tml-glyph-glyph-regexp
|
|
304 (tamil-regexp-of-hashtbl-keys tml-glyph-glyph-hash))
|
|
305
|
|
306 (defun tamil-compose-syllable-string (string)
|
|
307 (with-temp-buffer
|
|
308 (insert (decompose-string string))
|
|
309 (tamil-compose-syllable-region (point-min) (point-max))
|
|
310 (buffer-string)))
|
|
311
|
|
312 (defun tamil-compose-syllable-region (from to)
|
|
313 "Compose tamil syllable in region FROM to TO."
|
|
314 (let (glyph-str match-str glyph-reorder-regexps)
|
|
315 (save-excursion
|
|
316 (save-restriction
|
|
317 (narrow-to-region from to)
|
|
318 (goto-char (point-min))
|
|
319 ;; char-glyph-conversion
|
89483
|
320 (while (not (eobp))
|
|
321 (if (looking-at tml-char-glyph-regexp)
|
|
322 (progn
|
|
323 (setq match-str (match-string 0)
|
|
324 glyph-str
|
|
325 (concat glyph-str
|
|
326 (gethash match-str tml-char-glyph-hash)))
|
|
327 (goto-char (match-end 0)))
|
|
328 (setq glyph-str (concat glyph-str (string (following-char))))
|
|
329 (forward-char 1)))
|
|
330 (or glyph-str
|
|
331 (aset glyph-str 0 (following-char)))
|
49702
|
332 ;; glyph reordering
|
|
333 (when (string-match tml-glyph-reorder-key-glyphs glyph-str)
|
|
334 (if (string-match (car tml-glyph-reordering-regexp-list)
|
|
335 glyph-str)
|
|
336 (setq glyph-str
|
|
337 (replace-match (cdr tml-glyph-reordering-regexp-list)
|
|
338 nil nil glyph-str))))
|
|
339 ;; glyph-glyph-conversion
|
|
340 (when (string-match tml-glyph-glyph-regexp glyph-str)
|
|
341 (setq match-str (match-string 0 glyph-str))
|
|
342 (setq glyph-str
|
|
343 (replace-match (gethash match-str tml-glyph-glyph-hash)
|
|
344 nil nil glyph-str)))
|
|
345 ;; concatenate and attach reference-points.
|
|
346 (setq glyph-str
|
|
347 (cdr
|
|
348 (apply
|
|
349 'nconc
|
|
350 (mapcar
|
|
351 (function
|
|
352 (lambda (x) (list '(5 . 3) x))) ;; default ref. point.
|
|
353 glyph-str))))
|
|
354 (compose-region from to glyph-str)))))
|
|
355
|
89483
|
356 ;;;###autoload
|
|
357 (defun tamil-composition-function (pos &optional string)
|
|
358 "Compose Tamil characters after the position POS.
|
|
359 If STRING is not nil, it is a string, and POS is an index to the string.
|
|
360 In this case, compose characters after POS of the string."
|
|
361 (if string
|
|
362 ;; Not yet implemented.
|
|
363 nil
|
|
364 (goto-char pos)
|
|
365 (if (looking-at tamil-composable-pattern)
|
|
366 (prog1 (match-end 0)
|
|
367 (tamil-compose-syllable-region pos (match-end 0))))))
|
|
368
|
49702
|
369 (provide 'tml-util)
|
|
370
|
|
371 ;;; tml-util.el ends here
|