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