1 ;;; tv-util.el --- support for Tai Viet -*- coding: utf-8 -*-
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 2, or (at your option)
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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; Regexp matching with a sequence of Tai Viet characters.
30 (format "[\xaa80-\xaac2\xaadb-\xaadf]+"))
32 ;; Char-table of information about glyph type of Tai Viet characters.
33 (defconst tai-viet-glyph-info
34 (let ((table (make-char-table nil
))
35 (specials '((right-overhang .
"ꪊꪋꪌꪍꪏꪓꪖꪜꪞꪡꪤꪨ")
37 (combining-vowel .
"ꪴꪰꪲꪳꪷꪸꪾ")
38 (combining-tone .
"꪿꫁"))))
39 ;; Set all TaiViet characters to `t'.
40 (set-char-table-range table
(cons #xaa80
#xaac2
) t
)
41 (set-char-table-range table
(cons #xaadb
#xaadf
) t
)
42 ;; Overwrite it for special characters.
43 (dolist (elt specials
)
44 (let ((category (car elt
))
46 (dotimes (i (length chars
))
47 (aset table
(aref chars i
) category
))))
50 (defun tai-viet-compose-string (from to string
)
51 "Compose Tai Viet characters in STRING between indices FROM and TO."
52 (let* ((ch (aref string from
))
53 (info (aref tai-viet-glyph-info ch
))
55 (if (eq info
'non-spacing
)
56 (compose-string string from
(1+ from
) (string ch ?
\t)))
57 (setq from
(1+ from
) prev-info info
)
58 (while (and (< from to
)
59 (>= #xaa80
(setq ch
(aref string from
)))
61 (setq info
(aref tai-viet-glyph-info ch
))
62 (if (and (eq info
'non-spacing
)
63 (eq prev-info
'non-spacing
))
64 (compose-string from
(1+ from
) (string ?
\t ch
)))
65 (setq from
(1+ from
) prev-info info
))
66 (if (eq info
'right-overhang
)
67 (compose-string string
(1- from
) from
(string ch ?
\t)))
70 (defun tai-viet-compose-region (from to
)
71 "Compose Tai Viet characters in the region between FROM and TO."
72 (decompose-region from to
)
73 (let ((normal-rule '(Br . Bl
))
74 (tone-rule '(tr . bl
))
76 ch info pos components overhang
)
79 (setq ch
(char-after from
)
80 info
(aref tai-viet-glyph-info ch
)))
85 (if (memq info
'(combining-vowel combining-tone
))
87 ;; Display this as a spacing glyph.
88 (compose-region (1- from
) from
(string ?
\t ch
))
93 overhang
(if (eq info
'right-overhang
)
95 (if (and (not prev-viet
) (eq info
'left-overhang
))
100 (setq ch
(char-after from
)
101 info
(aref tai-viet-glyph-info ch
)))
102 (if (memq info
'(combining-vowel combining-tone
))
105 (list components normal-rule ch
)
109 (setq ch
(char-after from
)
110 info
(aref tai-viet-glyph-info ch
))
111 (eq info
'combining-tone
))
112 (setq components
(nconc components
115 (if (eq overhang
'left-overhang
)
116 (setq components
(cons ?
\t
117 (cons normal-rule components
)))
118 (if (and (eq overhang
'right-overhang
)
120 (setq components
(nconc components
121 (list normal-rule ?
\t)))))
122 (compose-region pos from components
))
123 (if (eq overhang
'left-overhang
)
124 (compose-region pos from
(string ?
\t components
))))
125 (if (eq overhang
'left-overhang
)
126 (compose-region pos from
(string ?
\t components
))
127 (if (and (eq overhang
'right-overhang
) (>= from to
))
128 (compose-region pos from
(string components ?
\t))))))))
133 (defun tai-viet-composition-function (pos &optional string
)
137 (if (string-match tai-viet-re string pos
)
138 (tai-viet-compose-string pos
(match-end 0) string
)
141 (if (looking-at tai-viet-re
)
142 (tai-viet-compose-region pos
(match-end 0))
146 (provide 'tai-viet-util
)
148 ;; arch-tag: a45ac3fc-07d0-44d5-8841-2ebea7e11f5b