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 .
"꪿꫁")
40 ;; Set all TaiViet characters to `t'.
41 (set-char-table-range table
(cons #xaa80
#xaac2
) t
)
42 (set-char-table-range table
(cons #xaadb
#xaadf
) t
)
43 ;; Overwrite it for special characters.
44 (dolist (elt specials
)
45 (let ((category (car elt
))
47 (dotimes (i (length chars
))
48 (aset table
(aref chars i
) category
))))
51 (defun tai-viet-compose-string (from to string
)
52 "Compose Tai Viet characters in STRING between indices FROM and TO."
53 (let* ((ch (aref string from
))
54 (info (aref tai-viet-glyph-info ch
))
56 (if (eq info
'non-spacing
)
57 (compose-string string from
(1+ from
) (string ch ?
\t)))
58 (setq from
(1+ from
) prev-info info
)
59 (while (and (< from to
)
60 (>= #xaa80
(setq ch
(aref string from
)))
62 (setq info
(aref tai-viet-glyph-info ch
))
63 (if (and (eq info
'non-spacing
)
64 (eq prev-info
'non-spacing
))
65 (compose-string from
(1+ from
) (string ?
\t ch
)))
66 (setq from
(1+ from
) prev-info info
))
67 (if (eq info
'right-overhang
)
68 (compose-string string
(1- from
) from
(string ch ?
\t)))
71 (defun tai-viet-compose-region (from to
)
72 "Compose Tai Viet characters in the region between FROM and TO."
73 (decompose-region from to
)
74 (let ((normal-rule '(Br . Bl
))
75 (tone-rule '(tr . bl
))
77 ch info pos components overhang
)
80 (setq ch
(char-after from
)
81 info
(aref tai-viet-glyph-info ch
)))
86 (if (memq info
'(combining-vowel combining-tone
))
88 ;; Display this as a spacing glyph.
89 (compose-region (1- from
) from
(string ?
\t ch
))
94 overhang
(if (eq info
'right-overhang
)
96 (if (and (not prev-viet
) (eq info
'left-overhang
))
101 (setq ch
(char-after from
)
102 info
(aref tai-viet-glyph-info ch
)))
103 (if (memq info
'(combining-vowel combining-tone
))
106 (list components normal-rule ch
)
110 (setq ch
(char-after from
)
111 info
(aref tai-viet-glyph-info ch
))
112 (eq info
'combining-tone
))
113 (setq components
(nconc components
116 (if (eq overhang
'left-overhang
)
117 (setq components
(cons ?
\t
118 (cons normal-rule components
)))
119 (if (and (eq overhang
'right-overhang
)
121 (setq components
(nconc components
122 (list normal-rule ?
\t)))))
123 (compose-region pos from components
))
124 (if (eq overhang
'left-overhang
)
125 (compose-region pos from
(string ?
\t components
))))
126 (if (eq overhang
'left-overhang
)
127 (compose-region pos from
(string ?
\t components
))
128 (if (and (eq overhang
'right-overhang
) (>= from to
))
129 (compose-region pos from
(string components ?
\t))))))))
134 (defun tai-viet-composition-function (from to font-object string
)
136 (if (string-match tai-viet-re string from
)
137 (tai-viet-compose-string from
(match-end 0) string
))
139 (if (looking-at tai-viet-re
)
140 (tai-viet-compose-region from
(match-end 0)))))
143 (provide 'tai-viet-util
)
145 ;; arch-tag: a45ac3fc-07d0-44d5-8841-2ebea7e11f5b