1 ;;; tv-util.el --- support for Tai Viet -*- coding: utf-8 -*-
3 ;; Copyright (C) 2007, 2008, 2009, 2010, 2011
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.
27 (defconst tai-viet-re
"[\xaa80-\xaac2\xaadb-\xaadf]+")
29 ;; Char-table of information about glyph type of Tai Viet characters.
30 (defconst tai-viet-glyph-info
31 (let ((table (make-char-table nil
))
32 (specials '((right-overhang .
"ꪊꪋꪌꪍꪏꪓꪖꪜꪞꪡꪤꪨ")
34 (combining-vowel .
"ꪴꪰꪲꪳꪷꪸꪾ")
35 (combining-tone .
"꪿꫁")
37 ;; Set all TaiViet characters to t.
38 (set-char-table-range table
(cons #xaa80
#xaac2
) t
)
39 (set-char-table-range table
(cons #xaadb
#xaadf
) t
)
40 ;; Overwrite it for special characters.
41 (dolist (elt specials
)
42 (let ((category (car elt
))
44 (dotimes (i (length chars
))
45 (aset table
(aref chars i
) category
))))
48 (defun tai-viet-compose-string (from to string
)
49 "Compose Tai Viet characters in STRING between indices FROM and TO."
50 (let* ((ch (aref string from
))
51 (info (aref tai-viet-glyph-info ch
))
53 (if (eq info
'non-spacing
)
54 (compose-string string from
(1+ from
) (string ch ?
\t)))
55 (setq from
(1+ from
) prev-info info
)
56 (while (and (< from to
)
57 (>= #xaa80
(setq ch
(aref string from
)))
59 (setq info
(aref tai-viet-glyph-info ch
))
60 (if (and (eq info
'non-spacing
)
61 (eq prev-info
'non-spacing
))
62 (compose-string from
(1+ from
) (string ?
\t ch
)))
63 (setq from
(1+ from
) prev-info info
))
64 (if (eq info
'right-overhang
)
65 (compose-string string
(1- from
) from
(string ch ?
\t)))
68 (defun tai-viet-compose-region (from to
)
69 "Compose Tai Viet characters in the region between FROM and TO."
70 (decompose-region from to
)
71 (let ((normal-rule '(Br . Bl
))
72 (tone-rule '(tr . bl
))
74 ch info pos components overhang
)
77 (setq ch
(char-after from
)
78 info
(aref tai-viet-glyph-info ch
)))
83 (if (memq info
'(combining-vowel combining-tone
))
85 ;; Display this as a spacing glyph.
86 (compose-region (1- from
) from
(string ?
\t ch
))
91 overhang
(if (eq info
'right-overhang
)
93 (if (and (not prev-viet
) (eq info
'left-overhang
))
98 (setq ch
(char-after from
)
99 info
(aref tai-viet-glyph-info ch
)))
100 (if (memq info
'(combining-vowel combining-tone
))
103 (list components normal-rule ch
)
107 (setq ch
(char-after from
)
108 info
(aref tai-viet-glyph-info ch
))
109 (eq info
'combining-tone
))
110 (setq components
(nconc components
113 (if (eq overhang
'left-overhang
)
114 (setq components
(cons ?
\t
115 (cons normal-rule components
)))
116 (if (and (eq overhang
'right-overhang
)
118 (setq components
(nconc components
119 (list normal-rule ?
\t)))))
120 (compose-region pos from components
))
121 (if (eq overhang
'left-overhang
)
122 (compose-region pos from
(string ?
\t components
))))
123 (if (eq overhang
'left-overhang
)
124 (compose-region pos from
(string ?
\t components
))
125 (if (and (eq overhang
'right-overhang
) (>= from to
))
126 (compose-region pos from
(string components ?
\t))))))))
131 (defun tai-viet-composition-function (from to font-object string
)
133 (if (string-match tai-viet-re string from
)
134 (tai-viet-compose-string from
(match-end 0) string
))
136 (if (looking-at tai-viet-re
)
137 (tai-viet-compose-region from
(match-end 0)))))
140 (provide 'tai-viet-util
)