Mercurial > emacs
annotate lisp/language/mlm-util.el @ 49957:14248792753a
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 24 Feb 2003 16:45:24 +0000 |
parents | 15e3ed34db0a |
children | bd6fa6f622f2 |
rev | line source |
---|---|
49702 | 1 ;;; mlm-util.el --- support for composing malayalam characters -*-coding: iso-2022-7bit;-*- |
2 | |
3 ;; Copyright (C) 2003 Free Software Foundation, Inc. | |
4 | |
5 ;; Maintainer: KAWABATA, Taichi <kawabata@m17n.org> | |
6 ;; Keywords: multilingual, Malayalam | |
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: Feb. 11. 2003 | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; This file provides character(Unicode) to glyph(CDAC) conversion and | |
30 ;; composition of Malayalam script characters. | |
31 | |
32 ;;; Code: | |
33 | |
34 ;; Malayalam Composable Pattern | |
35 ;; C .. Consonants | |
36 ;; V .. Vowel | |
37 ;; H .. Halant | |
38 ;; M .. Matra | |
39 ;; V .. Vowel | |
40 ;; A .. Anuswar | |
41 ;; D .. Chandrabindu | |
42 ;; (N .. Zerowidth Non Joiner) | |
43 ;; (J .. Zerowidth Joiner. ) | |
44 ;; 1. vowel | |
45 ;; V(A|visargam)? | |
46 ;; 2. syllable : maximum of 5 consecutive consonants. (e.g. kartsnya) | |
47 ;; ((CH)?(CH)?(CH)?CH)?C(H|M?(A|D)?)? | |
48 | |
49 (defconst malayalam-consonant | |
50 "[$,1@5(B-$,1@Y(B]") | |
51 | |
52 (defconst malayalam-composable-pattern | |
53 (concat | |
54 "\\([$,1@%(B-$,1@4(B][$,1@"(B]?\\)\\|$,1@#(B" | |
55 "\\|\\(" | |
56 "\\(?:\\(?:[$,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\\)?" | |
57 "[$,1@5(B-$,1@Y(B]\\(?:$,1@m(B\\|[$,1@^(B-$,1@c@f@g@h@j@j@k@l(B]?[$,1@"@m(B]?\\)?" | |
58 "\\)") | |
59 "Regexp matching a composable sequence of Malayalam characters.") | |
60 | |
61 ;;;###autoload | |
62 (defun malayalam-compose-region (from to) | |
63 (interactive "r") | |
64 (save-excursion | |
65 (save-restriction | |
66 (narrow-to-region from to) | |
67 (goto-char (point-min)) | |
68 (while (re-search-forward malayalam-composable-pattern nil t) | |
69 (malayalam-compose-syllable-region (match-beginning 0) | |
70 (match-end 0)))))) | |
71 (defun malayalam-compose-string (string) | |
72 (with-temp-buffer | |
73 (insert (decompose-string string)) | |
74 (malayalam-compose-region (point-min) (point-max)) | |
75 (buffer-string))) | |
76 | |
77 (defun malayalam-post-read-conversion (len) | |
78 (save-excursion | |
79 (save-restriction | |
80 (let ((buffer-modified-p (buffer-modified-p))) | |
81 (narrow-to-region (point) (+ (point) len)) | |
82 (malayalam-compose-region (point-min) (point-max)) | |
83 (set-buffer-modified-p buffer-modified-p) | |
84 (- (point-max) (point-min)))))) | |
85 | |
86 (defun malayalam-range (from to) | |
87 "Make the list of the integers of range FROM to TO." | |
88 (let (result) | |
89 (while (<= from to) (setq result (cons to result) to (1- to))) result)) | |
90 | |
91 (defun malayalam-regexp-of-hashtbl-keys (hashtbl) | |
92 "Return a regular expression that matches all keys in hashtable HASHTBL." | |
93 (let ((max-specpdl-size 1000)) | |
94 (regexp-opt | |
95 (sort | |
96 (let (dummy) | |
97 (maphash (function (lambda (key val) (setq dummy (cons key dummy)))) hashtbl) | |
98 dummy) | |
99 (function (lambda (x y) (> (length x) (length y)))))))) | |
100 | |
101 | |
102 ;;;###autoload | |
103 (defun malayalam-composition-function (from to pattern &optional string) | |
104 "Compose Malayalam characters in REGION, or STRING if specified. | |
105 Assume that the REGION or STRING must fully match the composable | |
106 PATTERN regexp." | |
107 (if string (malayalam-compose-syllable-string string) | |
108 (malayalam-compose-syllable-region from to)) | |
109 (- to from)) | |
110 | |
111 ;; Register a function to compose Malayalam characters. | |
112 (mapc | |
113 (function (lambda (ucs) | |
114 (aset composition-function-table (decode-char 'ucs ucs) | |
115 (list (cons malayalam-composable-pattern | |
116 'malayalam-composition-function))))) | |
117 (nconc '(#x0d02 #x0d03) (malayalam-range #x0d05 #x0d39))) | |
118 | |
119 ;; Notes on conversion steps. | |
120 | |
121 ;; 1. chars to glyphs | |
122 ;; | |
123 ;; Simple replacement of characters to glyphs is done. | |
124 | |
125 ;; 2. glyphs reordering. | |
126 ;; | |
127 ;; Two special reordering rule takes place. | |
128 ;; a. following "$,46[(B" goes to the front. | |
129 ;; b. following "$,46S6S(B", "$,46S(B" or "$,46T(B" goes to the front. | |
130 ;; This reordering occurs only to the last cluster of consonants. | |
131 ;; Preceding consonants with halant characters are not affected. | |
132 | |
133 ;; 3. Composition. | |
134 ;; | |
135 ;; left modifiers will be attached at the left. | |
136 ;; others will be attached right. | |
137 | |
138 (defvar mlm-char-glyph | |
139 '(;; various signs | |
140 ("$,1@"(B" . "$,46W(B") | |
141 ("$,1@#(B" . "$,46X(B") | |
142 ;; Independent Vowels | |
143 ("$,1@%(B" . "$,46!(B") | |
144 ("$,1@&(B" . "$,46"(B") | |
145 ("$,1@'(B" . "$,46#(B") | |
146 ("$,1@((B" . "$,46#6U(B") | |
147 ("$,1@)(B" . "$,46$(B") | |
148 ("$,1@*(B" . "$,46$6U(B") | |
149 ("$,1@+(B" . "$,46%(B") | |
150 ("$,1@,(B" . "nil") ;; not in present use, not supported. | |
151 ("$,1@.(B" . "$,46&(B") | |
152 ("$,1@/(B" . "$,46'(B") | |
153 ("$,1@0(B" . "$,46S6&(B") | |
154 ("$,1@2(B" . "$,46((B") | |
155 ("$,1@3(B" . "$,46(6M(B") | |
156 ("$,1@4(B" . "$,46(6U(B") | |
157 ;; Consonants | |
158 ("$,1@5(B" . "$,46)(B") | |
159 ("$,1@5@m@5(B" . "$,47!(B") | |
49955
15e3ed34db0a
(mlm-char-glyph): Fix several composing rules.
Kenichi Handa <handa@m17n.org>
parents:
49943
diff
changeset
|
160 ("$,1@5@m@S(B" . "$,47"(B") |
49702 | 161 ("$,1@5@m@W(B" . "$,47#(B") |
162 ("$,1@5@m@?(B" . "$,47N(B") ;; ? | |
163 ("$,1@5@m@D(B" . "$,47`(B") | |
49955
15e3ed34db0a
(mlm-char-glyph): Fix several composing rules.
Kenichi Handa <handa@m17n.org>
parents:
49943
diff
changeset
|
164 ("$,1@5@a(B" . "$,47f(B") ;; ? ;; vowel u? |
15e3ed34db0a
(mlm-char-glyph): Fix several composing rules.
Kenichi Handa <handa@m17n.org>
parents:
49943
diff
changeset
|
165 ("$,1@5@m@5@m@a(B" . "$,47g(B") ;; ? ;; vowel u? |
49702 | 166 |
167 ("$,1@6(B" . "$,46*(B") | |
168 | |
169 ("$,1@7(B" . "$,46+(B") | |
170 ("$,1@7@m@7(B" . "$,47$(B") | |
171 ("$,1@7@m@R(B" . "$,47%(B") | |
172 ("$,1@7@m@N(B" . "$,47\(B") | |
173 ("$,1@7@m@H(B" . "$,47a(B") | |
174 | |
175 ("$,1@8(B" . "$,46,(B") | |
176 | |
177 ("$,1@9(B" . "$,46-(B") | |
178 ("$,1@9@m@5(B" . "$,47&(B") | |
179 ("$,1@9@m@9(B" . "$,47'(B") | |
49955
15e3ed34db0a
(mlm-char-glyph): Fix several composing rules.
Kenichi Handa <handa@m17n.org>
parents:
49943
diff
changeset
|
180 ("$,1@9@m@5@a(B" . "$,47h(B") ;; ? ;; vowel u? |
49702 | 181 |
182 ("$,1@:(B" . "$,46.(B") | |
183 ("$,1@:@m@:(B" . "$,47((B") ;; duplicate | |
184 ("$,1@:@m@;(B" . "$,47Q(B") ;; ? | |
185 | |
186 ("$,1@;(B" . "$,46/(B") | |
187 | |
188 ("$,1@<(B" . "$,460(B") | |
189 ("$,1@<@m@<(B" . "$,47V(B") | |
190 ("$,1@<@m@>(B" . "$,47Z(B") | |
191 | |
192 ("$,1@=(B" . "$,461(B") | |
193 | |
194 ("$,1@>(B" . "$,462(B") | |
195 ("$,1@>@m@:(B" . "$,47)(B") | |
196 ("$,1@>@m@>(B" . "$,47*(B") | |
197 | |
198 ("$,1@?(B" . "$,463(B") | |
199 ("$,1@?@m@?(B" . "$,47+(B") | |
200 | |
201 ("$,1@@(B" . "$,464(B") | |
202 ("$,1@A(B" . "$,465(B") | |
203 ("$,1@A@m@A(B" . "$,47M(B") | |
204 ("$,1@B(B" . "$,466(B") | |
205 | |
206 ("$,1@C(B" . "$,467(B") | |
207 ("$,1@C@m(B" . "$,47,(B") ;; half consonant | |
208 ("$,1@C@m@?(B" . "$,47-(B") | |
209 ("$,1@C@m@C(B" . "$,47.(B") | |
210 ("$,1@C@m@N(B" . "$,47W(B") | |
211 ("$,1@C@m@G(B" . "$,47^(B") ;; ? | |
212 ("$,1@C@m@V(B" . "$,47i(B") ;; ? | |
213 | |
214 ("$,1@D(B" . "$,468(B") | |
215 ("$,1@D@m@D(B" . "$,47/(B") | |
216 ("$,1@D@m@E(B" . "$,470(B") | |
217 ("$,1@D@m@X(B" . "$,47U(B") | |
218 ("$,1@D@m@M(B" . "$,47[(B") | |
219 ("$,1@D@m@N(B" . "$,47_(B") | |
49955
15e3ed34db0a
(mlm-char-glyph): Fix several composing rules.
Kenichi Handa <handa@m17n.org>
parents:
49943
diff
changeset
|
220 ("$,1@D@a(B" . "$,47j(B") ;; ? ;; vowel u ? |
49702 | 221 |
222 ("$,1@E(B" . "$,469(B") | |
223 | |
224 ("$,1@F(B" . "$,46:(B") | |
225 ("$,1@F@m@F(B" . "$,471(B") | |
226 ("$,1@F@m@G(B" . "$,472(B") | |
227 | |
228 ("$,1@G(B" . "$,46;(B") | |
229 | |
230 ("$,1@H(B" . "$,46<(B") | |
231 ("$,1@H@m(B" . "$,473(B") ;; half consonant | |
232 ("$,1@H@m@D(B" . "$,474(B") | |
233 ("$,1@H@m@F(B" . "$,475(B") | |
234 ("$,1@H@m@H(B" . "$,476(B") | |
235 ("$,1@H@m@N(B" . "$,477(B") | |
236 ("$,1@H@m@G(B" . "$,47T(B") | |
237 ("$,1@H@m@E(B" . "$,47Y(B") | |
238 ("$,1@H@m@Q(B" . "$,47b(B") | |
239 ("$,1@H@m@V(B" . "$,47k(B") ;; ? | |
240 ("$,1@H@m@H@m@V(B" . "$,47l(B") ;; ? | |
241 | |
242 ("$,1@J(B" . "$,46=(B") | |
243 ("$,1@J@m@J(B" . "$,478(B") ;; duplicate | |
244 ("$,1@J@m@R(B" . "$,479(B") ;; lakar | |
245 | |
246 ("$,1@K(B" . "$,46>(B") | |
247 | |
248 ("$,1@L(B" . "$,46?(B") | |
249 ("$,1@L@m@L(B" . "$,47:(B") ;; duplicate | |
250 ("$,1@L@m@R(B" . "$,47;(B") ;; lakar | |
251 ("$,1@L@m@G(B" . "$,47O(B") ;; ? | |
252 ("$,1@L@m@F(B" . "$,47P(B") ;; ? | |
253 | |
254 ("$,1@M(B" . "$,46@(B") | |
255 | |
256 ("$,1@N(B" . "$,46A(B") | |
257 ("$,1@N@m@J(B" . "$,47<(B") | |
258 ("$,1@N@m@N(B" . "$,47=(B") | |
259 ("$,1@N@m@R(B" . "$,47>(B") ;; lakar | |
260 | |
261 ("$,1@O(B" . "$,46B(B") | |
262 ("$,1@O@m@O(B" . "$,47?(B") ;; duplicate | |
263 ("$,1@O@m@5@m@5(B" . "$,47m(B") ;; ? | |
264 | |
265 ("$,1@P(B" . "$,46C(B") | |
266 ("$,1@P@m(B" . "$,47@(B") | |
267 | |
268 ("$,1@Q(B" . "$,46D(B") | |
269 ("$,1@Q@m(B" . "$,47@(B") ;; same glyph as "$,1@P@m(B" | |
270 ;;("$,1@Q@m@Q(B" . "$,47A(B") | |
271 ("$,1@Q@m@Q(B" . "$,47d(B") | |
272 | |
273 ("$,1@R(B" . "$,46E(B") | |
274 ("$,1@R@m(B" . "$,47B(B") | |
275 ("$,1@R@m@R(B" . "$,47C(B") ;; lakar | |
276 ("$,1@R@m@J(B" . "$,47e(B") ;; ? | |
277 | |
278 ("$,1@S(B" . "$,46F(B") | |
279 ("$,1@S@m(B" . "$,47D(B") | |
280 ("$,1@S@m@S(B" . "$,47E(B") | |
281 | |
282 ("$,1@T(B" . "$,46G(B") | |
283 ("$,1@T@m(B" . "$,47D(B") | |
284 | |
285 ("$,1@U(B" . "$,46H(B") | |
286 ("$,1@U@m@U(B" . "$,47F(B") | |
287 | |
288 ("$,1@V(B" . "$,46I(B") | |
289 ("$,1@V@m@R(B" . "$,47G(B") | |
290 ("$,1@V@m@V(B" . "$,47H(B") | |
291 ("$,1@V@m@:(B" . "$,47](B") | |
292 | |
293 ("$,1@W(B" . "$,46J(B") | |
294 ("$,1@W@m@?(B" . "$,47c(B") | |
295 | |
296 ("$,1@X(B" . "$,46K(B") | |
297 ("$,1@X@m@R(B" . "$,47I(B") | |
298 ("$,1@X@m@X(B" . "$,47J(B") | |
299 ("$,1@X@m@Q@m@Q(B" . "$,47L(B") | |
300 ("$,1@X@m@E(B" . "$,47X(B") | |
301 | |
302 ("$,1@Y(B" . "$,46L(B") | |
303 ("$,1@Y@m@R(B" . "$,47K(B") | |
304 ("$,1@Y@m@N(B" . "$,47R(B") | |
305 ("$,1@Y@m@H(B" . "$,47S(B") | |
306 | |
307 ;; Dependent vowel signs | |
308 ("$,1@^(B" . "$,46M(B") | |
309 ("$,1@_(B" . "$,46N(B") | |
310 ("$,1@`(B" . "$,46O(B") | |
311 ("$,1@a(B" . "$,46P(B") | |
312 ("$,1@b(B" . "$,46Q(B") | |
313 ("$,1@c(B" . "$,46R(B") | |
314 ("$,1@f(B" . "$,46S(B") | |
315 ("$,1@g(B" . "$,46T(B") | |
316 ("$,1@h(B" . "$,46S6S(B") | |
317 ("$,1@j(B" . "$,46S6M(B") | |
318 ("$,1@k(B" . "$,46T6M(B") | |
319 ("$,1@l(B" . "$,46U(B") | |
320 ;; Various signs | |
321 ("$,1@m(B" . "$,46V(B") | |
322 ("$,1@m@O(B" . "$,46Y(B") ;; yakar | |
323 ("$,1@m@O@a(B" . "$,46\(B") ;; yakar + u ;; ? | |
324 ("$,1@m@O@b(B" . "$,46](B") ;; yakar + uu ;; ? | |
325 ("$,1@m@U(B" . "$,46Z(B") ;; vakar modifier | |
326 ("$,1@m@P(B" . "$,46[(B") ;; rakar modifier is the same to rra modifier. | |
49943
f70ce138a267
(mlm-char-glyph): Add entries for "halant +
Kenichi Handa <handa@m17n.org>
parents:
49702
diff
changeset
|
327 ("$,1@m@P@m(B" . "$,46R(B") ;; halant + rakar + halant |
49702 | 328 ("$,1@m@Q(B" . "$,46[(B") ;; rrakar modifier |
49943
f70ce138a267
(mlm-char-glyph): Add entries for "halant +
Kenichi Handa <handa@m17n.org>
parents:
49702
diff
changeset
|
329 ("$,1@m@Q@m(B" . "$,46R(B") ;; halant + rrakar + halant |
49702 | 330 ("$,1@m@m(B" . "$,46V(B") ;; double omission sign to stop forming half consonant. |
331 ("$,1@w(B" . "$,46U(B") ;; not in present use, already at 0D4C. | |
332 )) | |
333 | |
334 (defvar mlm-char-glyph-hash | |
335 (let* ((hash (make-hash-table :test 'equal))) | |
336 (mapc (function (lambda (x) (puthash (car x) (cdr x) hash))) | |
337 mlm-char-glyph) | |
338 hash)) | |
339 | |
340 (defvar mlm-char-glyph-regexp | |
341 (malayalam-regexp-of-hashtbl-keys mlm-char-glyph-hash)) | |
342 | |
343 ;; Malayalam languages needed to be reordered in a complex mannar. | |
344 | |
345 (defvar mlm-consonants | |
346 (concat | |
347 "$,46)6*6+6,6-6.6/606162636465666768696:6;6<6=6>6?6@6A6B6C6D6E6F6G6H6I6J6K6L(B" | |
348 "$,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" | |
349 )) | |
350 | |
351 (defvar mlm-consonants-regexp | |
352 (concat "\\($,46[(B?[" mlm-consonants "][$,46Y6Z(B]?\\)")) | |
353 | |
354 (defvar mlm-glyph-reorder-key-glyphs "[$,46[6S6T(B]") | |
355 | |
356 (defvar mlm-glyph-reordering-regexp-list | |
357 `((,(concat "\\([" mlm-consonants "][$,46Y6Z(B]?\\)$,46[(B") . "$,46[(B\\1") | |
358 (,(concat mlm-consonants-regexp "$,46S6S(B") . "$,46S6S(B\\1") | |
359 (,(concat mlm-consonants-regexp "$,46S(B") . "$,46S(B\\1") | |
360 (,(concat mlm-consonants-regexp "$,46T(B") . "$,46T(B\\1"))) | |
361 | |
362 (defun malayalam-compose-syllable-string (string) | |
363 (with-temp-buffer | |
364 (insert (decompose-string string)) | |
365 (malayalam-compose-syllable-region (point-min) (point-max)) | |
366 (buffer-string))) | |
367 | |
368 (defun malayalam-compose-syllable-region (from to) | |
369 "Compose malayalam syllable in region FROM to TO." | |
370 (let (glyph-str | |
371 match-str | |
372 glyph-reorder-regexps | |
373 glyph-reorder-replace | |
374 glyph-reorder-regexp) | |
375 (save-excursion | |
376 (save-restriction | |
377 (narrow-to-region from to) | |
378 (goto-char (point-min)) | |
379 ;; char-glyph-conversion | |
380 (while (re-search-forward mlm-char-glyph-regexp nil t) | |
381 (setq match-str (match-string 0)) | |
382 (setq glyph-str | |
383 (concat glyph-str (gethash match-str mlm-char-glyph-hash)))) | |
384 (when (string-match mlm-glyph-reorder-key-glyphs glyph-str) | |
385 ;; glyph reordering | |
386 (setq glyph-reorder-regexps mlm-glyph-reordering-regexp-list) | |
387 (while glyph-reorder-regexps | |
388 (setq glyph-reorder-regexp (caar glyph-reorder-regexps)) | |
389 (setq glyph-reorder-replace (cdar glyph-reorder-regexps)) | |
390 (setq glyph-reorder-regexps (cdr glyph-reorder-regexps)) | |
391 (if (string-match glyph-reorder-regexp glyph-str) | |
392 (setq glyph-str | |
393 (replace-match glyph-reorder-replace nil nil | |
394 glyph-str))))) | |
395 ;; concatenate and attach reference-points. | |
396 (setq glyph-str | |
397 (cdr | |
398 (apply | |
399 'nconc | |
400 (mapcar | |
401 (function | |
402 (lambda (x) (list '(5 . 3) x))) ;; default ref. point. | |
403 glyph-str)))) | |
404 (compose-region from to glyph-str))))) | |
405 | |
406 (provide 'mlm-util) | |
407 | |
408 ;;; devan-util.el ends here |