1 ;;; tv-util.el --- support for Tai Viet -*- coding: utf-8 -*-
3 ;; Copyright (C) 2007, 2008
4 ;; National Institute of Advanced Industrial Science and Technology (AIST)
5 ;; Registration Number H13PRO009
7 ;; Keywords: multilingual, Tai Viet, i18n
9 ;; This file is part of GNU Emacs.
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
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; Regexp matching with a sequence of Tai Viet characters.
28 (format "[\xaa80-\xaac2\xaadb-\xaadf-]+"))
30 ;; Char-table of information about glyph type of Tai Viet characters.
31 (defconst tai-viet-glyph-info
32 (let ((table (make-char-table nil))
33 (specials '((right-overhang . "ꪊꪋꪌꪍꪏꪓꪖꪜꪞꪡꪤꪨ")
35 (combining-vowel . "ꪴꪰꪲꪳꪷꪸꪾ")
36 (combining-tone . "꪿꫁")
38 ;; Set all TaiViet characters to `t'.
39 (set-char-table-range table (cons #xaa80 #xaac2) t)
40 (set-char-table-range table (cons #xaadb #xaadf) t)
41 ;; Overwrite it for special characters.
42 (dolist (elt specials)
43 (let ((category (car elt))
45 (dotimes (i (length chars))
46 (aset table (aref chars i) category))))
49 (defun tai-viet-compose-string (from to string)
50 "Compose Tai Viet characters in STRING between indices FROM and TO."
51 (let* ((ch (aref string from))
52 (info (aref tai-viet-glyph-info ch))
54 (if (eq info 'non-spacing)
55 (compose-string string from (1+ from) (string ch ?\t)))
56 (setq from (1+ from) prev-info info)
57 (while (and (< from to)
58 (>= #xaa80 (setq ch (aref string from)))
60 (setq info (aref tai-viet-glyph-info ch))
61 (if (and (eq info 'non-spacing)
62 (eq prev-info 'non-spacing))
63 (compose-string from (1+ from) (string ?\t ch)))
64 (setq from (1+ from) prev-info info))
65 (if (eq info 'right-overhang)
66 (compose-string string (1- from) from (string ch ?\t)))
69 (defun tai-viet-compose-region (from to)
70 "Compose Tai Viet characters in the region between FROM and TO."
71 (decompose-region from to)
72 (let ((normal-rule '(Br . Bl))
73 (tone-rule '(tr . bl))
75 ch info pos components overhang)
78 (setq ch (char-after from)
79 info (aref tai-viet-glyph-info ch)))
84 (if (memq info '(combining-vowel combining-tone))
86 ;; Display this as a spacing glyph.
87 (compose-region (1- from) from (string ?\t ch))
92 overhang (if (eq info 'right-overhang)
94 (if (and (not prev-viet) (eq info 'left-overhang))
99 (setq ch (char-after from)
100 info (aref tai-viet-glyph-info ch)))
101 (if (memq info '(combining-vowel combining-tone))
104 (list components normal-rule ch)
108 (setq ch (char-after from)
109 info (aref tai-viet-glyph-info ch))
110 (eq info 'combining-tone))
111 (setq components (nconc components
114 (if (eq overhang 'left-overhang)
115 (setq components (cons ?\t
116 (cons normal-rule components)))
117 (if (and (eq overhang 'right-overhang)
119 (setq components (nconc components
120 (list normal-rule ?\t)))))
121 (compose-region pos from components))
122 (if (eq overhang 'left-overhang)
123 (compose-region pos from (string ?\t components))))
124 (if (eq overhang 'left-overhang)
125 (compose-region pos from (string ?\t components))
126 (if (and (eq overhang 'right-overhang) (>= from to))
127 (compose-region pos from (string components ?\t))))))))
132 (defun tai-viet-composition-function (from to font-object string)
134 (if (string-match tai-viet-re string from)
135 (tai-viet-compose-string from (match-end 0) string))
137 (if (looking-at tai-viet-re)
138 (tai-viet-compose-region from (match-end 0)))))
141 (provide 'tai-viet-util)
143 ;; arch-tag: a45ac3fc-07d0-44d5-8841-2ebea7e11f5b