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
|
89909
|
79 ;;;###autoload
|
49702
|
80 (defun tamil-post-read-conversion (len)
|
|
81 (save-excursion
|
|
82 (save-restriction
|
|
83 (let ((buffer-modified-p (buffer-modified-p)))
|
|
84 (narrow-to-region (point) (+ (point) len))
|
|
85 (tamil-compose-region (point-min) (point-max))
|
|
86 (set-buffer-modified-p buffer-modified-p)
|
|
87 (- (point-max) (point-min))))))
|
|
88
|
|
89 (defun tamil-range (from to)
|
|
90 "Make the list of the integers of range FROM to TO."
|
|
91 (let (result)
|
|
92 (while (<= from to) (setq result (cons to result) to (1- to))) result))
|
|
93
|
|
94 (defun tamil-regexp-of-hashtbl-keys (hashtbl)
|
|
95 "Return a regular expression that matches all keys in hashtable HASHTBL."
|
|
96 (let ((max-specpdl-size 1000))
|
|
97 (regexp-opt
|
|
98 (sort
|
|
99 (let (dummy)
|
|
100 (maphash (function (lambda (key val) (setq dummy (cons key dummy)))) hashtbl)
|
|
101 dummy)
|
|
102 (function (lambda (x y) (> (length x) (length y))))))))
|
|
103
|
|
104
|
|
105 ;; Notes on conversion steps.
|
|
106
|
|
107 ;; 1. chars to glyphs
|
|
108 ;; Simple replacement of characters to glyphs is done.
|
|
109
|
|
110 ;; 2. glyphs reordering.
|
|
111 ;; following "$,4)j(B", "$,4)k(B", "$,4)l(B" goes to the front.
|
|
112
|
|
113 ;; 3. glyphs to glyphs
|
|
114 ;; reordered vowels are ligatured to consonants.
|
|
115
|
|
116 ;; 4. Composition.
|
|
117 ;; left modifiers will be attached at the left.
|
|
118 ;; others will be attached right.
|
|
119
|
|
120 (defvar tml-char-glyph
|
|
121 '(;; various signs
|
89483
|
122 ("$,1<"(B" . "$,4)b(B") ;; not good
|
49702
|
123 ("$,1<#(B" . "$,4*G(B")
|
|
124 ;; Independent Vowels
|
|
125 ("$,1<%(B" . "$,4*<(B")
|
|
126 ("$,1<&(B" . "$,4*=(B")
|
|
127 ("$,1<'(B" . "$,4*>(B")
|
|
128 ("$,1<((B" . "$,4*?(B")
|
|
129 ("$,1<)(B" . "$,4*@(B")
|
|
130 ("$,1<*(B" . "$,4*A(B")
|
|
131 ("$,1<.(B" . "$,4*B(B")
|
|
132 ("$,1</(B" . "$,4*C(B")
|
|
133 ("$,1<0(B" . "$,4*D(B")
|
|
134 ("$,1<2(B" . "$,4*E(B")
|
|
135 ("$,1<3(B" . "$,4*F(B")
|
|
136 ("$,1<4(B" . "$,4*E*W(B")
|
|
137 ;; Consonants
|
|
138 ("$,1<5<m<W<m(B" . "$,4):(B") ; ks.
|
|
139 ("$,1<5<m<W(B" . "$,4*^(B") ; ks
|
|
140 ("$,1<5(B" . "$,4*H(B")
|
|
141
|
|
142 ("$,1<9(B" . "$,4*I(B")
|
|
143 ("$,1<:(B" . "$,4*J(B")
|
|
144 ("$,1<<(B" . "$,4*\(B")
|
|
145 ("$,1<<<m(B" . "$,4)8(B")
|
|
146 ("$,1<>(B" . "$,4*K(B")
|
|
147 ("$,1<?(B" . "$,4*L(B")
|
|
148 ("$,1<C(B" . "$,4*M(B")
|
|
149 ("$,1<D(B" . "$,4*N(B")
|
|
150 ("$,1<H(B" . "$,4*O(B")
|
|
151 ("$,1<I(B" . "$,4*Y(B")
|
|
152 ("$,1<I<m(B" . "$,4)a(B")
|
|
153 ("$,1<J(B" . "$,4*P(B")
|
|
154 ("$,1<N(B" . "$,4*Q(B")
|
|
155 ("$,1<O(B" . "$,4*R(B")
|
|
156 ("$,1<P(B" . "$,4*S(B")
|
|
157 ("$,1<Q(B" . "$,4*X(B")
|
|
158 ("$,1<R(B" . "$,4*T(B")
|
|
159 ("$,1<S(B" . "$,4*W(B")
|
|
160 ("$,1<T(B" . "$,4*V(B")
|
|
161 ("$,1<U(B" . "$,4*U(B")
|
|
162 ("$,1<W(B" . "$,4*[(B")
|
|
163 ("$,1<W<m(B" . "$,4)7(B")
|
|
164 ("$,1<W<m<P<`(B" . "$,4*_(B")
|
|
165 ("$,1<X(B" . "$,4*Z(B")
|
|
166 ("$,1<X<m(B" . "$,4)6(B")
|
|
167 ("$,1<Y(B" . "$,4*](B")
|
|
168 ("$,1<Y<m(B" . "$,4)9(B")
|
|
169
|
|
170 ;; Dependent vowel signs
|
|
171 ("$,1<^(B" . "$,4)c(B")
|
|
172 ("$,1<_(B" . "$,4)d(B")
|
|
173 ("$,1<`(B" . "$,4)f(B")
|
|
174 ("$,1<a(B" . "$,4)g(B")
|
|
175 ("$,1<b(B" . "$,4)h(B")
|
|
176 ("$,1<f(B" . "$,4)j(B")
|
|
177 ("$,1<g(B" . "$,4)k(B")
|
|
178 ("$,1<h(B" . "$,4)l(B")
|
|
179 ("$,1<j(B" . "$,4)j)c(B")
|
|
180 ("$,1<k(B" . "$,4)k)c(B")
|
|
181 ("$,1<l(B" . "$,4)j*W(B")
|
|
182
|
|
183 ;; Various signs
|
|
184 ("$,1<m(B" . "$,4)b(B")
|
|
185 ("$,1<w(B" . "nil") ;; not supported?
|
|
186 ))
|
|
187
|
|
188 (defvar tml-char-glyph-hash
|
|
189 (let* ((hash (make-hash-table :test 'equal)))
|
|
190 (mapc (function (lambda (x) (puthash (car x) (cdr x) hash)))
|
|
191 tml-char-glyph)
|
|
192 hash))
|
|
193
|
|
194 (defvar tml-char-glyph-regexp
|
|
195 (tamil-regexp-of-hashtbl-keys tml-char-glyph-hash))
|
|
196
|
|
197 ;; Tamil languages needed to be reordered.
|
|
198
|
|
199 (defvar tml-consonants-regexp
|
|
200 "[$,4*H*^*I*J*\*K*L*M*N*O*Y*P*Q*R*S*X*T*W*V*U*[*Z*](B]")
|
|
201
|
|
202 (defvar tml-glyph-reorder-key-glyphs "[$,4)j)k)l(B]")
|
|
203
|
|
204 (defvar tml-glyph-reordering-regexp-list
|
|
205 (cons
|
|
206 (concat "\\(" tml-consonants-regexp "\\)\\([$,4)j)k)l(B]\\)") "\\2\\1"))
|
|
207
|
|
208 ;; Tamil vowel modifiers to be ligatured.
|
|
209 (defvar tml-glyph-glyph
|
|
210 '(
|
|
211 ("$,4*H)d(B" . "$,4(a(B") ; ki
|
|
212 ("$,4*^)d(B" . "$,4(v(B") ; ksi
|
|
213 ("$,4*^)f(B" . "$,4)2(B") ; ksi~
|
|
214 ("$,4*I)d(B" . "$,4(b(B") ; n^i
|
|
215 ("$,4*J)d(B" . "$,4(c(B") ; ci
|
|
216 ("$,4*K)d(B" . "$,4(d(B") ; n~i
|
|
217 ("$,4*L)d(B" . "$,4)n(B") ; t.i
|
|
218 ("$,4*M)d(B" . "$,4(e(B") ; n.i
|
|
219 ("$,4*N)d(B" . "$,4(f(B") ; ti
|
|
220 ("$,4*O)d(B" . "$,4(g(B") ; ni
|
|
221 ("$,4*P)d(B" . "$,4(h(B") ; pi
|
|
222 ("$,4*Q)d(B" . "$,4(i(B") ; mi
|
|
223 ("$,4*R)d(B" . "$,4(j(B") ; yi
|
|
224 ("$,4*S)d(B" . "$,4(k(B") ; ri
|
|
225 ("$,4*T)d(B" . "$,4(l(B") ; li
|
|
226 ("$,4*U)d(B" . "$,4(m(B") ; vi
|
|
227 ("$,4*V)d(B" . "$,4(n(B") ; l_i
|
|
228 ("$,4*W)d(B" . "$,4(o(B") ; l.i
|
|
229 ("$,4*X)d(B" . "$,4(p(B") ; r_i
|
|
230 ("$,4*Y)d(B" . "$,4(q(B") ; n_i
|
|
231 ("$,4*Z)d(B" . "$,4(r(B") ; si
|
|
232 ("$,4*[)d(B" . "$,4(s(B") ; s'i
|
|
233 ("$,4*\)d(B" . "$,4(t(B") ; ji
|
|
234 ("$,4*])d(B" . "$,4(u(B") ; hi
|
|
235
|
|
236 ("$,4*H)f(B" . "$,4(w(B") ; ki~
|
|
237 ("$,4*I)f(B" . "$,4(x(B") ; n^i~
|
|
238 ("$,4*J)f(B" . "$,4(y(B") ; ci~
|
|
239 ("$,4*K)f(B" . "$,4(z(B") ; n~i~
|
|
240 ("$,4*L)f(B" . "$,4)o(B") ; t.i~
|
|
241 ("$,4*M)f(B" . "$,4)!(B") ; n.i~
|
|
242 ("$,4*N)f(B" . "$,4)"(B") ; ti~
|
|
243 ("$,4*O)f(B" . "$,4)#(B") ; ni~
|
|
244 ("$,4*P)f(B" . "$,4)$(B") ; pi~
|
|
245 ("$,4*Q)f(B" . "$,4)%(B") ; mi~
|
|
246 ("$,4*R)f(B" . "$,4)&(B") ; yi~
|
|
247 ("$,4*S)f(B" . "$,4)'(B") ; ri~
|
|
248 ("$,4*T)f(B" . "$,4)((B") ; li~
|
|
249 ("$,4*U)f(B" . "$,4))(B") ; vi~
|
|
250 ("$,4*V)f(B" . "$,4)*(B") ; l_i~
|
|
251 ("$,4*W)f(B" . "$,4)+(B") ; l.i~
|
|
252 ("$,4*X)f(B" . "$,4),(B") ; r_i~
|
|
253 ("$,4*Y)f(B" . "$,4)-(B") ; n_i~
|
|
254 ("$,4*Z)f(B" . "$,4).(B") ; si~
|
|
255 ("$,4*[)f(B" . "$,4)/(B") ; s'i~
|
|
256 ("$,4*\)f(B" . "$,4)0(B") ; ji~
|
|
257 ("$,4*])f(B" . "$,4)1(B") ; hi~
|
|
258
|
|
259 ("$,4*H)g(B" . "$,4)p(B") ; ku
|
|
260 ("$,4*I)g(B" . "$,4)q(B") ; n^u
|
|
261 ("$,4*J)g(B" . "$,4)r(B") ; cu
|
|
262 ("$,4*K)g(B" . "$,4)s(B") ; n~u
|
|
263 ("$,4*L)g(B" . "$,4)t(B") ; t.u
|
|
264 ("$,4*M)g(B" . "$,4)u(B") ; n.u
|
|
265 ("$,4*N)g(B" . "$,4)v(B") ; tu
|
|
266 ("$,4*O)g(B" . "$,4)x(B") ; nu
|
|
267 ("$,4*P)g(B" . "$,4)y(B") ; pu
|
|
268 ("$,4*Q)g(B" . "$,4)z(B") ; mu
|
|
269 ("$,4*R)g(B" . "$,4){(B") ; yu
|
|
270 ("$,4*S)g(B" . "$,4)|(B") ; ru
|
|
271 ("$,4*T)g(B" . "$,4)}(B") ; lu
|
|
272 ("$,4*U)g(B" . "$,4)~(B") ; vu
|
|
273 ("$,4*V)g(B" . "$,4)(B") ; l_u
|
|
274 ("$,4*W)g(B" . "$,4* (B") ; l.u
|
|
275 ("$,4*X)g(B" . "$,4*!(B") ; r_u
|
|
276 ("$,4*Y)g(B" . "$,4*"(B") ; n_u
|
|
277
|
|
278 ("$,4*H)h(B" . "$,4*#(B") ; ku~
|
|
279 ("$,4*I)h(B" . "$,4*$(B") ; n^u~
|
|
280 ("$,4*J)h(B" . "$,4*%(B") ; cu~
|
|
281 ("$,4*K)h(B" . "$,4*&(B") ; n~u~
|
|
282 ("$,4*L)h(B" . "$,4*'(B") ; t.u~
|
|
283 ("$,4*M)h(B" . "$,4*((B") ; n.u~
|
|
284 ("$,4*N)h(B" . "$,4*)(B") ; tu~
|
|
285 ("$,4*O)h(B" . "$,4*+(B") ; nu~
|
|
286 ("$,4*P)h(B" . "$,4*,(B") ; pu~
|
|
287 ("$,4*Q)h(B" . "$,4*-(B") ; mu~
|
|
288 ("$,4*R)h(B" . "$,4*.(B") ; yu~
|
|
289 ("$,4*S)h(B" . "$,4*/(B") ; ru~
|
|
290 ("$,4*T)h(B" . "$,4*6(B") ; lu~
|
|
291 ("$,4*U)h(B" . "$,4*7(B") ; vu~
|
|
292 ("$,4*V)h(B" . "$,4*8(B") ; l_u~
|
|
293 ("$,4*W)h(B" . "$,4*9(B") ; l.u~
|
|
294 ("$,4*X)h(B" . "$,4*:(B") ; r_u~
|
|
295 ("$,4*Y)h(B" . "$,4*;(B") ; n_u~
|
|
296 ))
|
|
297
|
|
298 (defvar tml-glyph-glyph-hash
|
|
299 (let* ((hash (make-hash-table :test 'equal)))
|
|
300 (mapc (function (lambda (x) (puthash (car x) (cdr x) hash)))
|
|
301 tml-glyph-glyph)
|
|
302 hash))
|
|
303
|
|
304 (defvar tml-glyph-glyph-regexp
|
|
305 (tamil-regexp-of-hashtbl-keys tml-glyph-glyph-hash))
|
|
306
|
|
307 (defun tamil-compose-syllable-string (string)
|
|
308 (with-temp-buffer
|
|
309 (insert (decompose-string string))
|
|
310 (tamil-compose-syllable-region (point-min) (point-max))
|
|
311 (buffer-string)))
|
|
312
|
|
313 (defun tamil-compose-syllable-region (from to)
|
|
314 "Compose tamil syllable in region FROM to TO."
|
|
315 (let (glyph-str match-str glyph-reorder-regexps)
|
|
316 (save-excursion
|
|
317 (save-restriction
|
|
318 (narrow-to-region from to)
|
|
319 (goto-char (point-min))
|
|
320 ;; char-glyph-conversion
|
89483
|
321 (while (not (eobp))
|
|
322 (if (looking-at tml-char-glyph-regexp)
|
|
323 (progn
|
|
324 (setq match-str (match-string 0)
|
|
325 glyph-str
|
|
326 (concat glyph-str
|
|
327 (gethash match-str tml-char-glyph-hash)))
|
|
328 (goto-char (match-end 0)))
|
|
329 (setq glyph-str (concat glyph-str (string (following-char))))
|
|
330 (forward-char 1)))
|
|
331 (or glyph-str
|
|
332 (aset glyph-str 0 (following-char)))
|
49702
|
333 ;; glyph reordering
|
|
334 (when (string-match tml-glyph-reorder-key-glyphs glyph-str)
|
|
335 (if (string-match (car tml-glyph-reordering-regexp-list)
|
|
336 glyph-str)
|
|
337 (setq glyph-str
|
|
338 (replace-match (cdr tml-glyph-reordering-regexp-list)
|
|
339 nil nil glyph-str))))
|
|
340 ;; glyph-glyph-conversion
|
|
341 (when (string-match tml-glyph-glyph-regexp glyph-str)
|
|
342 (setq match-str (match-string 0 glyph-str))
|
|
343 (setq glyph-str
|
|
344 (replace-match (gethash match-str tml-glyph-glyph-hash)
|
|
345 nil nil glyph-str)))
|
|
346 ;; concatenate and attach reference-points.
|
|
347 (setq glyph-str
|
|
348 (cdr
|
|
349 (apply
|
|
350 'nconc
|
|
351 (mapcar
|
|
352 (function
|
|
353 (lambda (x) (list '(5 . 3) x))) ;; default ref. point.
|
|
354 glyph-str))))
|
|
355 (compose-region from to glyph-str)))))
|
|
356
|
89483
|
357 ;;;###autoload
|
|
358 (defun tamil-composition-function (pos &optional string)
|
|
359 "Compose Tamil characters after the position POS.
|
|
360 If STRING is not nil, it is a string, and POS is an index to the string.
|
|
361 In this case, compose characters after POS of the string."
|
|
362 (if string
|
|
363 ;; Not yet implemented.
|
|
364 nil
|
|
365 (goto-char pos)
|
|
366 (if (looking-at tamil-composable-pattern)
|
|
367 (prog1 (match-end 0)
|
|
368 (tamil-compose-syllable-region pos (match-end 0))))))
|
|
369
|
49702
|
370 (provide 'tml-util)
|
|
371
|
89909
|
372 ;;; arch-tag: 4d1c9737-e7b1-44cf-a040-4f64c50e773e
|
49702
|
373 ;;; tml-util.el ends here
|