diff options
| author | Kenichi Handa | 2008-02-21 07:38:40 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2008-02-21 07:38:40 +0000 |
| commit | 3e45ea11c045ac71f42042e30155ff8562b54a0e (patch) | |
| tree | 1bb92020b2816cab0b4ccaa807446631cbe8bcee | |
| parent | b94affd7b0502a30b8175181e06b19de67583bea (diff) | |
| download | emacs-3e45ea11c045ac71f42042e30155ff8562b54a0e.tar.gz emacs-3e45ea11c045ac71f42042e30155ff8562b54a0e.zip | |
*** empty log message ***
| -rw-r--r-- | lisp/language/devan-util.el | 664 |
1 files changed, 0 insertions, 664 deletions
diff --git a/lisp/language/devan-util.el b/lisp/language/devan-util.el deleted file mode 100644 index 85cf1f9a673..00000000000 --- a/lisp/language/devan-util.el +++ /dev/null | |||
| @@ -1,664 +0,0 @@ | |||
| 1 | ;;; devan-util.el --- Support for composing Devanagari characters -*-coding: iso-2022-7bit;-*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 | ||
| 4 | ;; Free Software Foundation, Inc. | ||
| 5 | ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, | ||
| 6 | ;; 2007, 2008 | ||
| 7 | ;; National Institute of Advanced Industrial Science and Technology (AIST) | ||
| 8 | ;; Registration Number H14PRO021 | ||
| 9 | |||
| 10 | ;; Maintainer: KAWABATA, Taichi <kawabata@m17n.org> | ||
| 11 | ;; Keywords: multilingual, Devanagari | ||
| 12 | |||
| 13 | ;; This file is part of GNU Emacs. | ||
| 14 | |||
| 15 | ;; GNU Emacs is free software; you can redistribute it and/or modify | ||
| 16 | ;; it under the terms of the GNU General Public License as published by | ||
| 17 | ;; the Free Software Foundation; either version 3, or (at your option) | ||
| 18 | ;; any later version. | ||
| 19 | |||
| 20 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 21 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 22 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 23 | ;; GNU General Public License for more details. | ||
| 24 | |||
| 25 | ;; You should have received a copy of the GNU General Public License | ||
| 26 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | ||
| 27 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
| 28 | ;; Boston, MA 02110-1301, USA. | ||
| 29 | |||
| 30 | ;; Created: Feb. 17. 2001 | ||
| 31 | |||
| 32 | ;;; Commentary: | ||
| 33 | |||
| 34 | ;; This file provides character(Unicode) to glyph(CDAC) conversion and | ||
| 35 | ;; composition of Devanagari script characters. | ||
| 36 | |||
| 37 | ;;; Code: | ||
| 38 | |||
| 39 | ;; Devanagari Composable Pattern | ||
| 40 | ;; C .. Consonants | ||
| 41 | ;; V .. Vowel | ||
| 42 | ;; H .. Halant | ||
| 43 | ;; M .. Matra | ||
| 44 | ;; V .. Vowel | ||
| 45 | ;; A .. Anuswar | ||
| 46 | ;; D .. Chandrabindu | ||
| 47 | ;; (N .. Zerowidth Non Joiner) | ||
| 48 | ;; (J .. Zerowidth Joiner. ) | ||
| 49 | ;; 1. vowel | ||
| 50 | ;; V(A/D)? | ||
| 51 | ;; 2. syllable : maximum of 5 consecutive consonants. (e.g. kartsnya) | ||
| 52 | ;; ((CH)?(CH)?(CH)?CH)?C(H|M?(A|D)?)? | ||
| 53 | |||
| 54 | (defconst devanagari-consonant | ||
| 55 | "[$,15U(B-$,15y68(B-$,16?(B]") | ||
| 56 | |||
| 57 | ;;("$,16B(B" . nil) | ||
| 58 | ;;("$,16A(B" . nil) | ||
| 59 | ;;("$,16C(B" . nil) | ||
| 60 | |||
| 61 | |||
| 62 | (defconst devanagari-composable-pattern | ||
| 63 | (concat | ||
| 64 | "\\([$,15E(B-$,15T6@6A(B][$,15A5B(B]?\\)\\|[$,15C6D(B]" | ||
| 65 | "\\|\\(" | ||
| 66 | "\\(?:\\(?:[$,15U(B-$,15y68(B-$,16?(B]$,16-(B\\)?\\(?:[$,15U(B-$,15y68(B-$,16?(B]$,16-(B\\)?\\(?:[$,15U(B-$,15y68(B-$,16?(B]$,16-(B\\)?[$,15U(B-$,15y68(B-$,16?(B]$,16-(B\\)?" | ||
| 67 | "[$,15U(B-$,15y68(B-$,16?(B]\\(?:$,16-(B\\|[$,15~(B-$,16-6B6C(B]?[$,15B5A(B]?\\)?" | ||
| 68 | "\\)") | ||
| 69 | "Regexp matching a composable sequence of Devanagari characters.") | ||
| 70 | |||
| 71 | (dolist (range '((#x0903 . #x0903) | ||
| 72 | (#x0905 . #x0939) | ||
| 73 | (#x0958 . #x0961))) | ||
| 74 | (set-char-table-range indian-composable-pattern range | ||
| 75 | devanagari-composable-pattern)) | ||
| 76 | |||
| 77 | ;;;###autoload | ||
| 78 | (defun devanagari-compose-region (from to) | ||
| 79 | (interactive "r") | ||
| 80 | (save-excursion | ||
| 81 | (save-restriction | ||
| 82 | (narrow-to-region from to) | ||
| 83 | (goto-char (point-min)) | ||
| 84 | (while (re-search-forward devanagari-composable-pattern nil t) | ||
| 85 | (devanagari-compose-syllable-region (match-beginning 0) | ||
| 86 | (match-end 0)))))) | ||
| 87 | (defun devanagari-compose-string (string) | ||
| 88 | (with-temp-buffer | ||
| 89 | (insert (decompose-string string)) | ||
| 90 | (devanagari-compose-region (point-min) (point-max)) | ||
| 91 | (buffer-string))) | ||
| 92 | |||
| 93 | ;;;###autoload | ||
| 94 | (defun devanagari-post-read-conversion (len) | ||
| 95 | (save-excursion | ||
| 96 | (save-restriction | ||
| 97 | (let ((buffer-modified-p (buffer-modified-p))) | ||
| 98 | (narrow-to-region (point) (+ (point) len)) | ||
| 99 | (devanagari-compose-region (point-min) (point-max)) | ||
| 100 | (set-buffer-modified-p buffer-modified-p) | ||
| 101 | (- (point-max) (point-min)))))) | ||
| 102 | |||
| 103 | (defun devanagari-regexp-of-hashtbl-keys (hashtbl) | ||
| 104 | "Return a regular expression that matches all keys in hashtable HASHTBL." | ||
| 105 | (let ((max-specpdl-size 1000)) | ||
| 106 | (regexp-opt | ||
| 107 | (sort | ||
| 108 | (let (dummy) | ||
| 109 | (maphash (function (lambda (key val) (setq dummy (cons key dummy)))) hashtbl) | ||
| 110 | dummy) | ||
| 111 | (function (lambda (x y) (> (length x) (length y)))))))) | ||
| 112 | |||
| 113 | ;;;###autoload | ||
| 114 | (defun devanagari-composition-function (pos &optional string) | ||
| 115 | "Compose Devanagari characters after the position POS. | ||
| 116 | If STRING is not nil, it is a string, and POS is an index to the string. | ||
| 117 | In this case, compose characters after POS of the string." | ||
| 118 | (if string | ||
| 119 | (if auto-compose-current-font | ||
| 120 | (if (eq (string-match "[$,15@(B-$,16_(B]+" pos) pos) | ||
| 121 | (or (font-shape-text 0 (match-end 0) auto-compose-current-font | ||
| 122 | string) | ||
| 123 | pos))) | ||
| 124 | (goto-char pos) | ||
| 125 | (if auto-compose-current-font | ||
| 126 | (if (looking-at "[$,15@(B-$,16_(B]+") | ||
| 127 | (or (font-shape-text pos (match-end 0) auto-compose-current-font) | ||
| 128 | pos) | ||
| 129 | (if (looking-at devanagari-composable-pattern) | ||
| 130 | (prog1 (match-end 0) | ||
| 131 | (devanagari-compose-syllable-region pos (match-end 0)))))))) | ||
| 132 | |||
| 133 | ;; Notes on conversion steps. | ||
| 134 | |||
| 135 | ;; 1. chars to glyphs | ||
| 136 | ;; | ||
| 137 | ;; Rules will not be applied to the halant appeared at the end of the | ||
| 138 | ;; text. Also, the preceding/following "r" will be treated as special case. | ||
| 139 | |||
| 140 | ;; 2. glyphs reordering. | ||
| 141 | ;; | ||
| 142 | ;; The glyphs are split by halant, and each glyph groups are | ||
| 143 | ;; re-ordered in the following order. | ||
| 144 | ;; | ||
| 145 | ;; Note that `consonant-glyph' mentioned here does not contain the | ||
| 146 | ;; vertical bar (right modifier) attached at the right of the | ||
| 147 | ;; consonant. | ||
| 148 | ;; | ||
| 149 | ;; If the glyph-group contains right modifier, | ||
| 150 | ;; (1) consonant-glyphs/vowels, with nukta sign | ||
| 151 | ;; (2) spacing | ||
| 152 | ;; (3) right modifier (may be matra) | ||
| 153 | ;; (4) top matra | ||
| 154 | ;; (5) preceding "r" | ||
| 155 | ;; (6) anuswar | ||
| 156 | ;; (7) following "r" | ||
| 157 | ;; (8) bottom matra or halant. | ||
| 158 | ;; | ||
| 159 | ;; Otherwise, | ||
| 160 | ;; (1) consonant-glyph/vowels, with nukta sign | ||
| 161 | ;; (3) left matra | ||
| 162 | ;; (4) top matra | ||
| 163 | ;; (5) preceding "r" | ||
| 164 | ;; (6) anuswar | ||
| 165 | ;; (7) following "r" | ||
| 166 | ;; (8) bottom matra or halant. | ||
| 167 | ;; (2) spacing | ||
| 168 | |||
| 169 | ;; 3. glyph to glyph | ||
| 170 | ;; | ||
| 171 | ;; For better display, some glyph display would be tuned. | ||
| 172 | |||
| 173 | ;; 4. Composition. | ||
| 174 | ;; | ||
| 175 | ;; left modifiers will be attached at the left. | ||
| 176 | ;; others will be attached right. | ||
| 177 | |||
| 178 | ;; Problem:: | ||
| 179 | ;; Can we generalize this methods to other Indian scripts? | ||
| 180 | |||
| 181 | (defvar dev-char-glyph | ||
| 182 | '(("$,15E(B" . "$,4 K(B") | ||
| 183 | ("$,15F(B" . "$,4 K")(B") | ||
| 184 | ("$,15~(B" . "$,4")(B") | ||
| 185 | ("$,15G(B" . "$,4 \(B") | ||
| 186 | ("$,15(B" . "$,4"*(B") | ||
| 187 | ("$,155A(B" . "$,4"*(B\$,4"&(B") | ||
| 188 | ("$,15H(B" . "$,4 \"'(B") | ||
| 189 | ("$,15H5A(B" . "$,4 \"'"&(B") | ||
| 190 | ("$,16 (B" . "$,4"2(B") | ||
| 191 | ("$,16 5A(B" . "$,4"2"&(B") | ||
| 192 | ("$,15I(B" . "$,4 ](B") | ||
| 193 | ("$,16!(B" . "$,4"6(B") | ||
| 194 | ("$,15J(B" . "$,4 ^"P(B") | ||
| 195 | ("$,16"(B" . "$,4":(B") | ||
| 196 | ("$,15K(B" . "$,4 `"Q(B") | ||
| 197 | ("$,16#(B" . "$,4">(B") | ||
| 198 | ;;("$,15L(B" . nil) ; not implemented. | ||
| 199 | ("$,16$(B" . "$,4"?(B") | ||
| 200 | ("$,15M(B" . "$,4 b"L(B") | ||
| 201 | ("$,15M5A(B" . "$,4 b"$(B") | ||
| 202 | ("$,15M5B(B" . "$,4 b"$(B") | ||
| 203 | ("$,16%(B" . "\$,4"L(B") | ||
| 204 | ("$,15N(B" . "$,4 b"@(B") | ||
| 205 | ("$,15N5A(B" . "$,4 b"@"&(B") | ||
| 206 | ("$,16&(B" . "\$,4"@(B") | ||
| 207 | ("$,16&5A(B" . "\$,4"@(B\$,4"&(B") | ||
| 208 | ("$,15O(B" . "$,4 b(B") | ||
| 209 | ("$,16'(B" . "\$,4"D(B") | ||
| 210 | ("$,16'5A(B" . "\$,4"D(B\$,4"&(B") | ||
| 211 | ("$,15P(B" . "$,4 b"D(B") | ||
| 212 | ("$,15P5A(B" . "$,4 b"D"&(B") | ||
| 213 | ("$,16((B" . "\$,4"H(B") | ||
| 214 | ("$,16(5A(B" . "\$,4"H(B\$,4"&(B") | ||
| 215 | ("$,15Q(B" . "$,4 K")"L(B") ;; special rule for reodering. | ||
| 216 | ("$,15Q5A(B" . "$,4 K")"$(B") | ||
| 217 | ("$,15Q5B(B" . "$,4 K")"$(B") | ||
| 218 | ("$,16)(B" . "\$,4")"L(B") | ||
| 219 | ("$,16)5A(B" . "\$,4")"$(B") | ||
| 220 | ("$,16)5B(B" . "\$,4")"$(B") | ||
| 221 | ("$,15R(B" . "$,4 K")"@(B") | ||
| 222 | ("$,15R5A(B" . "$,4 K")"@"&(B") | ||
| 223 | ("$,16*(B" . "\$,4")"@(B") | ||
| 224 | ("$,16*5A(B" . "\$,4")"@"&(B") | ||
| 225 | ("$,15S(B" . "$,4 K")"D(B") | ||
| 226 | ("$,15S5A(B" . "$,4 K")"D"&(B") | ||
| 227 | ("$,16+(B" . "\$,4")"D(B") | ||
| 228 | ("$,16+5A(B" . "\$,4")"D"&(B") | ||
| 229 | ("$,15T(B" . "$,4 K")"H(B") | ||
| 230 | ("$,15T5A(B" . "$,4 K")"H"&(B") | ||
| 231 | ("$,16,(B" . "\$,4")"H(B") | ||
| 232 | ("$,16,5A(B" . "\$,4")"H"&(B") | ||
| 233 | ("$,16@(B" . "$,4 a"Q(B") | ||
| 234 | ;;("$,16B(B" . nil) | ||
| 235 | ;;("$,16A(B" . nil) | ||
| 236 | ;;("$,16C(B" . nil) | ||
| 237 | |||
| 238 | ;; GRUTTALS | ||
| 239 | ("$,15U(B" . "$,4 e"R(B") | ||
| 240 | ("$,15U6-(B" . "$,4 c(B") | ||
| 241 | ("$,15U6-5p(B" . "$,4 g"R(B") | ||
| 242 | ("$,15U6-5d(B" . "$,4 h"R(B") | ||
| 243 | ("$,15U6-5w(B" . "$,4 i")(B") | ||
| 244 | ("$,15U6-5w6-(B" . "$,4 i(B") | ||
| 245 | |||
| 246 | ("$,15V(B" . "$,4 j")(B") | ||
| 247 | ("$,15V6-(B" . "$,4 j(B") | ||
| 248 | ("$,15V6-5p(B" . "$,4 l")(B") | ||
| 249 | ("$,15V6-5p6-(B" . "$,4 l(B") | ||
| 250 | |||
| 251 | ("$,15W(B" . "$,4 m")(B") | ||
| 252 | ("$,15W6-(B" . "$,4 m(B") | ||
| 253 | ("$,15W6-5p(B" . "$,4 o")(B") | ||
| 254 | ("$,15W6-5p6-(B" . "$,4 o(B") | ||
| 255 | |||
| 256 | ("$,15X(B" . "$,4 p")(B") | ||
| 257 | ("$,15X6-(B" . "$,4 p(B") | ||
| 258 | ("$,15X6-5p(B" . "$,4 q")(B") | ||
| 259 | ("$,15X6-5p6-(B" . "$,4 q(B") | ||
| 260 | |||
| 261 | ("$,15Y(B" . "$,4 r"S(B") | ||
| 262 | ;; PALATALS | ||
| 263 | ("$,15Z(B" . "$,4 s")(B") | ||
| 264 | ("$,15Z6-(B" . "$,4 s(B") | ||
| 265 | ("$,15Z6-5p(B" . "$,4 t")(B") | ||
| 266 | ("$,15Z6-5p6-(B" . "$,4 t(B") | ||
| 267 | |||
| 268 | ("$,15[(B" . "$,4 u"T(B") | ||
| 269 | |||
| 270 | ("$,15\(B" . "$,4 v")(B") | ||
| 271 | ("$,15\6-(B" . "$,4 v(B") | ||
| 272 | ("$,15\6-5p(B" . "$,4 x")(B") | ||
| 273 | ("$,15\6-5p6-(B" . "$,4 x(B") | ||
| 274 | ("$,15\6-5^(B" . "$,4 y")(B") | ||
| 275 | ("$,15\6-5^6-(B" . "$,4 y(B") | ||
| 276 | |||
| 277 | ("$,15](B" . "$,4 z")(B") | ||
| 278 | ("$,15]6-(B" . "$,4 z(B") | ||
| 279 | ("$,15]6-5p(B" . "$,4 {")(B") | ||
| 280 | ("$,15]6-5p6-(B" . "$,4 {(B") | ||
| 281 | |||
| 282 | ("$,15^(B" . "$,4 |")(B") | ||
| 283 | ("$,15^6-(B" . "$,4 |(B") | ||
| 284 | ;; CEREBRALS | ||
| 285 | ("$,15_(B" . "$,4 }"U(B") | ||
| 286 | ("$,15_6-5_(B" . "$,4 ~"U(B") | ||
| 287 | ("$,15_6-5`(B" . "$,4 "U(B") | ||
| 288 | |||
| 289 | ("$,15`(B" . "$,4! "V(B") | ||
| 290 | ("$,15`6-5`(B" . "$,4!!"V(B") | ||
| 291 | |||
| 292 | ("$,15a(B" . "$,4!""W(B") | ||
| 293 | ("$,15a6-5a(B" . "$,4!$"W(B") | ||
| 294 | ("$,15a6-5b(B" . "$,4!%"W(B") | ||
| 295 | |||
| 296 | ("$,15b(B" . "$,4!&"X(B") | ||
| 297 | |||
| 298 | ("$,15c(B" . "$,4!(")(B") | ||
| 299 | ("$,15c6-(B" . "$,4!((B") | ||
| 300 | ;; DENTALS | ||
| 301 | ("$,15d(B" . "$,4!)")(B") | ||
| 302 | ("$,15d6-(B" . "$,4!)(B") | ||
| 303 | ("$,15d6-5p(B" . "$,4!*")(B") | ||
| 304 | ("$,15d6-5p6-(B" . "$,4!*(B") | ||
| 305 | ("$,15d6-5d(B" . "$,4!+")(B") | ||
| 306 | ("$,15d6-5d6-(B" . "$,4!+(B") | ||
| 307 | |||
| 308 | ("$,15e(B" . "$,4!,")(B") | ||
| 309 | ("$,15e6-(B" . "$,4!,(B") | ||
| 310 | ("$,15e6-5p(B" . "$,4!-")(B") | ||
| 311 | ("$,15e6-5p6-(B" . "$,4!-(B") | ||
| 312 | |||
| 313 | ("$,15f(B" . "$,4!."Y(B") | ||
| 314 | ("$,15f6#(B" . "$,4!/"Y(B") | ||
| 315 | ("$,15f6-5p(B" . "$,4!0"Y(B") | ||
| 316 | ("$,15f6-5f(B" . "$,4!1"Y(B") | ||
| 317 | ("$,15f6-5g(B" . "$,4!2"Y(B") | ||
| 318 | ("$,15f6-5n(B" . "$,4!3(B") | ||
| 319 | ("$,15f6-5o(B" . "$,4!4(B") | ||
| 320 | ("$,15f6-5u(B" . "$,4!5"Y(B") | ||
| 321 | |||
| 322 | ("$,15g(B" . "$,4!6")(B") | ||
| 323 | ("$,15g6-(B" . "$,4!6(B") | ||
| 324 | ("$,15g6-5p(B" . "$,4!7")(B") | ||
| 325 | ("$,15g6-5p6-(B" . "$,4!7(B") | ||
| 326 | |||
| 327 | ("$,15h(B" . "$,4!8")(B") | ||
| 328 | ("$,15h6-(B" . "$,4!8(B") | ||
| 329 | ("$,15h6-5p(B" . "$,4!9")(B") | ||
| 330 | ("$,15h6-5p6-(B" . "$,4!9")(B") | ||
| 331 | ("$,15h6-5h(B" . "$,4!:")(B") | ||
| 332 | ("$,15h6-5h6-(B" . "$,4!:(B") | ||
| 333 | |||
| 334 | ("$,15i(B" . "$,4!8"#")(B") | ||
| 335 | ;; LABIALS | ||
| 336 | ("$,15j(B" . "$,4!;")(B") | ||
| 337 | ("$,15j6-(B" . "$,4!;(B") | ||
| 338 | ("$,15j6-5p(B" . "$,4!<")(B") | ||
| 339 | ("$,15j6-5p6-(B" . "$,4!<(B") | ||
| 340 | |||
| 341 | ("$,15k(B" . "$,4!a"[(B") | ||
| 342 | ("$,15k6-(B" . "$,4!=(B") | ||
| 343 | ("$,15k6-5p(B" . "$,4!c"[(B") | ||
| 344 | |||
| 345 | ("$,15l(B" . "$,4!d")(B") | ||
| 346 | ("$,15l6-(B" . "$,4!d(B") | ||
| 347 | ("$,15l6-5p(B" . "$,4!e")(B") | ||
| 348 | ("$,15l6-5p6-(B" . "$,4!e(B") | ||
| 349 | |||
| 350 | ("$,15m(B" . "$,4!f")(B") | ||
| 351 | ("$,15m6-(B" . "$,4!f(B") | ||
| 352 | ("$,15m6-5p(B" . "$,4!g")(B") | ||
| 353 | ("$,15m6-5p6-(B" . "$,4!g(B") | ||
| 354 | |||
| 355 | ("$,15n(B" . "$,4!h")(B") | ||
| 356 | ("$,15n6-(B" . "$,4!h(B") | ||
| 357 | ("$,15n6-5p(B" . "$,4!i")(B") | ||
| 358 | ("$,15n6-5p6-(B" . "$,4!i(B") | ||
| 359 | ;; SEMIVOWELS | ||
| 360 | ("$,15o(B" . "$,4!j")(B") | ||
| 361 | ("$,15o6-(B" . "$,4!j(B") | ||
| 362 | ("$,15o6-5p(B" . "$,4!k")(B") | ||
| 363 | ("$,15o6-5p6-(B" . "$,4!k(B") | ||
| 364 | ("$,16-5o(B" . "$,4!l(B") ;; when every ohter lig. fails. | ||
| 365 | |||
| 366 | ("$,15p(B" . "$,4!n"W(B") | ||
| 367 | ;; ("$,15p6-(B" . "\$,4"'(B") ;; special case. only the topmost pos. | ||
| 368 | ("$,15q(B" . "$,4!n"#"W(B") | ||
| 369 | ("$,15q6-(B" . "$,4!m(B") ;; IS 13194 speical rule. | ||
| 370 | ("$,15p6!(B" . "$,4!o"[(B") | ||
| 371 | ("$,15p6"(B" . "$,4!p"\(B") | ||
| 372 | |||
| 373 | ("$,15r(B" . "$,4!q")(B") | ||
| 374 | ("$,15r6-(B" . "$,4!q(B") | ||
| 375 | ("$,15s(B" . "$,4!s(B") | ||
| 376 | ("$,15s6-(B" . "$,4!r(B") | ||
| 377 | ("$,15t(B" . "$,4!s"#(B") | ||
| 378 | ("$,15t6-(B" . "$,4!r"#(B") | ||
| 379 | |||
| 380 | ("$,15u(B" . "$,4!t")(B") | ||
| 381 | ("$,15u6-(B" . "$,4!t(B") | ||
| 382 | ("$,15u6-5p(B" . "$,4!u")(B") | ||
| 383 | ("$,15u6-5p6-(B" . "$,4!u(B") | ||
| 384 | ;; SIBILANTS | ||
| 385 | ("$,15v(B" . "$,4!v")(B") | ||
| 386 | ("$,15v6-(B" . "$,4!v(B") | ||
| 387 | ("$,15v6-5u(B" . "$,4!w")(B") | ||
| 388 | ("$,15v6-5u6-(B" . "$,4!w(B") | ||
| 389 | ("$,15v6-5p(B" . "$,4!x")(B") | ||
| 390 | ("$,15v6-5p6-(B" . "$,4!x(B") | ||
| 391 | |||
| 392 | ("$,15w(B" . "$,4!y")(B") | ||
| 393 | ("$,15w6-(B" . "$,4!y(B") | ||
| 394 | ("$,15x(B" . "$,4!z")(B") | ||
| 395 | ("$,15x6-(B" . "$,4!z(B") | ||
| 396 | ("$,15x6-5p(B" . "$,4!{")(B") | ||
| 397 | ("$,15x6-5p6-(B" . "$,4!{(B") | ||
| 398 | |||
| 399 | ("$,15y(B" . "$,4!}(B") | ||
| 400 | ("$,15y6-(B" . "$,4!|(B") | ||
| 401 | ("$,15y6#(B" . "$,4!~(B") | ||
| 402 | ("$,15y6-5p(B" . "$,4!(B") | ||
| 403 | ("$,15y6-5n(B" . "$,4" (B") | ||
| 404 | ("$,15y6-5o(B" . "$,4"!(B") | ||
| 405 | ;; NUKTAS | ||
| 406 | ("$,168(B" . "$,4 f"R"S(B") | ||
| 407 | ("$,1686-(B" . "$,4 d(B") | ||
| 408 | ("$,169(B" . "$,4 k")(B") | ||
| 409 | ("$,1696-(B" . "$,4 k(B") | ||
| 410 | ("$,16:(B" . "$,4 n")(B") | ||
| 411 | ("$,16:6-(B" . "$,4 n(B") | ||
| 412 | ("$,16;(B" . "$,4 w")(B") | ||
| 413 | ("$,16;6-(B" . "$,4 w(B") | ||
| 414 | ("$,16<(B" . "$,4!#"W(B") | ||
| 415 | ("$,16=(B" . "$,4!'"X(B") | ||
| 416 | ("$,16>(B" . "$,4!b"[(B") | ||
| 417 | ("$,16>6-(B" . "$,4!>(B") | ||
| 418 | ("$,16?(B" . "$,4!j"#")(B") | ||
| 419 | ;; misc modifiers. | ||
| 420 | ("$,15A(B" . "\$,4"$(B") | ||
| 421 | ("$,15B(B" . "\$,4"&(B") | ||
| 422 | ("$,15C(B" . "$,4 F(B") | ||
| 423 | ("$,15|(B" . "$,4"#(B") | ||
| 424 | ("$,15}(B" . "$,4 E(B") | ||
| 425 | ("$,16-(B" . "$,4""(B") | ||
| 426 | ("$,16-5p(B" . "$,4"%(B") ;; following "r" | ||
| 427 | ;; ("$,160(B" . "$,4 D(B") | ||
| 428 | ("$,16D(B" . "$,4 J(B") | ||
| 429 | ;; ("$,16F(B" . "") | ||
| 430 | ;; ("$,16G(B" . "") | ||
| 431 | ;; ("$,16H(B" . "") | ||
| 432 | ;; ("$,16I(B" . "") | ||
| 433 | ;; ("$,16J(B" . "") | ||
| 434 | ;; ("$,16K(B" . "") | ||
| 435 | ;; ("$,16L(B" . "") | ||
| 436 | ;; ("$,16M(B" . "") | ||
| 437 | ;; ("$,16N(B" . "") | ||
| 438 | ;; ("$,16O(B" . "") | ||
| 439 | ) | ||
| 440 | "Devanagari characters to glyphs conversion table. | ||
| 441 | Default value contains only the basic rules. You may add your own | ||
| 442 | preferred rule from the sanskrit fonts." ) | ||
| 443 | |||
| 444 | (defvar dev-char-glyph-hash | ||
| 445 | (let* ((hash (make-hash-table :test 'equal))) | ||
| 446 | (mapc (function (lambda (x) (puthash (car x) (cdr x) hash))) | ||
| 447 | dev-char-glyph) | ||
| 448 | hash)) | ||
| 449 | |||
| 450 | (defvar dev-char-glyph-regexp | ||
| 451 | (devanagari-regexp-of-hashtbl-keys dev-char-glyph-hash)) | ||
| 452 | |||
| 453 | ;; glyph-to-glyph conversion table. | ||
| 454 | ;; it is supposed that glyphs are ordered in | ||
| 455 | ;; [consonant/nukta] - [matra/halant] - [preceding-r] - [anuswar]. | ||
| 456 | |||
| 457 | (defvar dev-glyph-glyph | ||
| 458 | '(("\$,4"'(B\$,4"&(B" . "\$,4"((B") | ||
| 459 | ("\$,4"'(B\$,4"$(B" . "\$,4"((B") | ||
| 460 | ("$,4"*(B\$,4"&(B" . "$,4"+(B") | ||
| 461 | ("$,4"*(B\$,4"'(B" . "$,4",(B") | ||
| 462 | ("$,4"*(B\$,4"'(B\$,4"&(B" . "$,4"-(B") | ||
| 463 | ("$,4"2(B\$,4"&(B" . "$,4"3(B") | ||
| 464 | ("$,4"2(B\$,4"'(B" . "$,4"4(B") | ||
| 465 | ("$,4"2(B\$,4"'(B\$,4"&(B" . "$,4"5(B") | ||
| 466 | ("$,4"#(B\$,4"6(B" . "$,4"7(B") | ||
| 467 | ("$,4"%(B\$,4"6(B" . "$,4"8(B") | ||
| 468 | ;;("$,4"6(B" . "$,4"9(B") | ||
| 469 | ("$,4"#(B\$,4":(B" . "$,4";(B") | ||
| 470 | ("$,4"%(B\$,4":(B" . "$,4"<(B") | ||
| 471 | ;;("$,4":(B" . "$,4"=(B") | ||
| 472 | ("\$,4"@(B\$,4"&(B" . "\$,4"A(B") | ||
| 473 | ("\$,4"@(B\$,4"'(B" . "\$,4"B(B") | ||
| 474 | ("\$,4"@(B\$,4"'(B\$,4"&(B" . "\$,4"C(B") | ||
| 475 | ("\$,4"D(B\$,4"&(B" . "\$,4"E(B") | ||
| 476 | ("\$,4"D(B\$,4"'(B" . "\$,4"F(B") | ||
| 477 | ("\$,4"D(B\$,4"'(B\$,4"&(B" . "\$,4"G(B") | ||
| 478 | ("\$,4"H(B\$,4"&(B" . "\$,4"I(B") | ||
| 479 | ("\$,4"H(B\$,4"'(B" . "\$,4"J(B") | ||
| 480 | ("\$,4"H(B\$,4"'(B\$,4"&(B" . "\$,4"K(B") | ||
| 481 | ("\$,4"L(B\$,4"&(B" . "\$,4"M(B") | ||
| 482 | ("\$,4"L(B\$,4"'(B" . "\$,4"N(B") | ||
| 483 | ("\$,4"L(B\$,4"'(B\$,4"&(B" . "\$,4"O(B") | ||
| 484 | )) | ||
| 485 | (defvar dev-glyph-glyph-hash | ||
| 486 | (let* ((hash (make-hash-table :test 'equal))) | ||
| 487 | (mapc (function (lambda (x) (puthash (car x) (cdr x) hash))) | ||
| 488 | dev-glyph-glyph) | ||
| 489 | hash)) | ||
| 490 | (defvar dev-glyph-glyph-regexp | ||
| 491 | (devanagari-regexp-of-hashtbl-keys dev-glyph-glyph-hash)) | ||
| 492 | |||
| 493 | |||
| 494 | ;; yet another glyph-to-glyph conversions. | ||
| 495 | (defvar dev-glyph-glyph-2 | ||
| 496 | '(("$,4"*(B" . "$,4".(B") | ||
| 497 | ("$,4"+(B" . "$,4"/(B") | ||
| 498 | ("$,4",(B" . "$,4"0(B") | ||
| 499 | ("$,4"-(B" . "$,4"1(B"))) | ||
| 500 | (defvar dev-glyph-glyph-2-hash | ||
| 501 | (let* ((hash (make-hash-table :test 'equal))) | ||
| 502 | (mapc (function (lambda (x) (puthash (car x) (cdr x) hash))) | ||
| 503 | dev-glyph-glyph-2) | ||
| 504 | hash)) | ||
| 505 | (defvar dev-glyph-glyph-2-regexp | ||
| 506 | (devanagari-regexp-of-hashtbl-keys dev-glyph-glyph-2-hash)) | ||
| 507 | |||
| 508 | (defun dev-charseq (from &optional to) | ||
| 509 | (if (null to) (setq to from)) | ||
| 510 | (number-sequence (decode-char 'devanagari-cdac from) | ||
| 511 | (decode-char 'devanagari-cdac to))) | ||
| 512 | |||
| 513 | (defvar dev-glyph-cvn | ||
| 514 | (append | ||
| 515 | (dev-charseq #x2b) | ||
| 516 | (dev-charseq #x3c #xc1) | ||
| 517 | (dev-charseq #xc3)) | ||
| 518 | "Devanagari Consonants/Vowels/Nukta Glyphs") | ||
| 519 | |||
| 520 | (defvar dev-glyph-space | ||
| 521 | (dev-charseq #xf0 #xfe) | ||
| 522 | "Devanagari Spacing Glyphs") | ||
| 523 | |||
| 524 | (defvar dev-glyph-right-modifier | ||
| 525 | (append | ||
| 526 | (dev-charseq #xc9) | ||
| 527 | (dev-charseq #xd2 #xd5)) | ||
| 528 | "Devanagari Modifiers attached at the right side.") | ||
| 529 | |||
| 530 | (defvar dev-glyph-right-modifier-regexp | ||
| 531 | (concat "[" dev-glyph-right-modifier "]")) | ||
| 532 | |||
| 533 | (defvar dev-glyph-left-matra | ||
| 534 | (dev-charseq #xca #xd1) | ||
| 535 | "Devanagari Matras attached at the left side.") | ||
| 536 | |||
| 537 | (defvar dev-glyph-top-matra | ||
| 538 | (dev-charseq #xe0 #xef) | ||
| 539 | "Devanagari Matras attached at the top side.") | ||
| 540 | |||
| 541 | (defvar dev-glyph-bottom-modifier | ||
| 542 | (append | ||
| 543 | (dev-charseq #xd6 #xdf) | ||
| 544 | (dev-charseq #xc2)) | ||
| 545 | "Devanagari Modifiers attached at the bottom.") | ||
| 546 | |||
| 547 | (defvar dev-glyph-order | ||
| 548 | `((,dev-glyph-cvn . 1) | ||
| 549 | (,dev-glyph-space . 2) | ||
| 550 | (,dev-glyph-right-modifier . 3) | ||
| 551 | (,dev-glyph-left-matra . 3) ;; processed by reference point. | ||
| 552 | (,dev-glyph-top-matra . 4) | ||
| 553 | (,(dev-charseq #xc7 #xc8) . 5) | ||
| 554 | (,(dev-charseq #xc4) . 6) | ||
| 555 | (,(dev-charseq #xc6) . 6) | ||
| 556 | (,(dev-charseq #xc5) . 7) | ||
| 557 | (,dev-glyph-bottom-modifier . 8))) | ||
| 558 | |||
| 559 | (mapc | ||
| 560 | (function (lambda (x) | ||
| 561 | (mapc | ||
| 562 | (function (lambda (y) | ||
| 563 | (put-char-code-property y 'composition-order (cdr x)))) | ||
| 564 | (car x)))) | ||
| 565 | dev-glyph-order) | ||
| 566 | |||
| 567 | (mapc | ||
| 568 | (function (lambda (x) | ||
| 569 | (put-char-code-property x 'reference-point '(3 . 5)))) | ||
| 570 | dev-glyph-left-matra) | ||
| 571 | |||
| 572 | (defun devanagari-compose-syllable-string (string) | ||
| 573 | (with-temp-buffer | ||
| 574 | (insert (decompose-string string)) | ||
| 575 | (devanagari-compose-syllable-region (point-min) (point-max)) | ||
| 576 | (buffer-string))) | ||
| 577 | |||
| 578 | (defun devanagari-compose-syllable-region (from to) | ||
| 579 | "Compose devanagari syllable in region FROM to TO." | ||
| 580 | (let ((glyph-str nil) (cons-num 0) glyph-str-list | ||
| 581 | (last-halant nil) (preceding-r nil) (last-modifier nil) | ||
| 582 | (last-char (char-before to)) match-str | ||
| 583 | glyph-block split-pos) | ||
| 584 | (save-excursion | ||
| 585 | (save-restriction | ||
| 586 | ;;; *** char-to-glyph conversion *** | ||
| 587 | ;; Special rule 1. -- Last halant must be preserved. | ||
| 588 | (if (eq last-char ?$,16-(B) | ||
| 589 | (progn | ||
| 590 | (setq last-halant t) | ||
| 591 | (narrow-to-region from (1- to))) | ||
| 592 | (narrow-to-region from to) | ||
| 593 | ;; note if the last char is modifier. | ||
| 594 | (if (or (eq last-char ?$,15A(B) (eq last-char ?$,15B(B)) | ||
| 595 | (setq last-modifier t))) | ||
| 596 | (goto-char (point-min)) | ||
| 597 | ;; Special rule 2. -- preceding "r halant" must be modifier. | ||
| 598 | (when (looking-at "$,15p6-(B.") | ||
| 599 | (setq preceding-r t) | ||
| 600 | (goto-char (+ 2 (point)))) | ||
| 601 | ;; translate the rest characters into glyphs | ||
| 602 | (while (re-search-forward dev-char-glyph-regexp nil t) | ||
| 603 | (setq match-str (match-string 0)) | ||
| 604 | (setq glyph-str | ||
| 605 | (concat glyph-str | ||
| 606 | (gethash match-str dev-char-glyph-hash))) | ||
| 607 | ;; count the number of consonant-glyhs. | ||
| 608 | (if (string-match devanagari-consonant match-str) | ||
| 609 | (setq cons-num (1+ cons-num)))) | ||
| 610 | ;; preceding-r must be attached before the anuswar if exists. | ||
| 611 | (if preceding-r | ||
| 612 | (if last-modifier | ||
| 613 | (setq glyph-str (concat (substring glyph-str 0 -1) | ||
| 614 | "$,4"'(B" (substring glyph-str -1))) | ||
| 615 | (setq glyph-str (concat glyph-str "$,4"'(B")))) | ||
| 616 | (if last-halant (setq glyph-str (concat glyph-str "$,4""(B"))) | ||
| 617 | ;;; *** glyph-to-glyph conversion *** | ||
| 618 | (when (string-match dev-glyph-glyph-regexp glyph-str) | ||
| 619 | (setq glyph-str | ||
| 620 | (replace-match (gethash (match-string 0 glyph-str) | ||
| 621 | dev-glyph-glyph-hash) | ||
| 622 | nil t glyph-str)) | ||
| 623 | (if (and (> cons-num 1) | ||
| 624 | (string-match dev-glyph-glyph-2-regexp glyph-str)) | ||
| 625 | (setq glyph-str | ||
| 626 | (replace-match (gethash (match-string 0 glyph-str) | ||
| 627 | dev-glyph-glyph-2-hash) | ||
| 628 | nil t glyph-str)))) | ||
| 629 | ;;; *** glyph reordering *** | ||
| 630 | (while (setq split-pos (string-match "$,4""(B\\|.$" glyph-str)) | ||
| 631 | (setq glyph-block (substring glyph-str 0 (1+ split-pos))) | ||
| 632 | (setq glyph-str (substring glyph-str (1+ split-pos))) | ||
| 633 | (setq | ||
| 634 | glyph-block | ||
| 635 | (if (string-match dev-glyph-right-modifier-regexp glyph-block) | ||
| 636 | (sort (string-to-list glyph-block) | ||
| 637 | (function (lambda (x y) | ||
| 638 | (< (get-char-code-property x 'composition-order) | ||
| 639 | (get-char-code-property y 'composition-order))))) | ||
| 640 | (sort (string-to-list glyph-block) | ||
| 641 | (function (lambda (x y) | ||
| 642 | (let ((xo (get-char-code-property x 'composition-order)) | ||
| 643 | (yo (get-char-code-property y 'composition-order))) | ||
| 644 | (if (= xo 2) nil (if (= yo 2) t (< xo yo))))))))) | ||
| 645 | (setq glyph-str-list (nconc glyph-str-list glyph-block))) | ||
| 646 | ;; concatenate and attach reference-points. | ||
| 647 | (setq glyph-str | ||
| 648 | (cdr | ||
| 649 | (apply | ||
| 650 | 'nconc | ||
| 651 | (mapcar | ||
| 652 | (function (lambda (x) | ||
| 653 | (list | ||
| 654 | (or (get-char-code-property x 'reference-point) | ||
| 655 | '(5 . 3) ;; default reference point. | ||
| 656 | ) | ||
| 657 | x))) | ||
| 658 | glyph-str-list)))))) | ||
| 659 | (compose-region from to glyph-str))) | ||
| 660 | |||
| 661 | (provide 'devan-util) | ||
| 662 | |||
| 663 | ;;; arch-tag: 9bc4d6e3-f2b9-4110-886e-ff9b66b7eebc | ||
| 664 | ;;; devan-util.el ends here | ||