90938
|
1 ;;; tv-util.el --- support for Tai Viet -*- coding: utf-8 -*-
|
|
2
|
|
3 ;; Copyright (C) 2007
|
|
4 ;; National Institute of Advanced Industrial Science and Technology (AIST)
|
|
5 ;; Registration Number H13PRO009
|
|
6
|
|
7 ;; Keywords: multilingual, Tai Viet, i18n
|
|
8
|
|
9 ;; This file is part of GNU Emacs.
|
|
10
|
|
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)
|
|
14 ;; any later version.
|
|
15
|
|
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.
|
|
20
|
|
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.
|
|
25
|
|
26 ;;; Code
|
|
27
|
|
28 ;; Regexp matching with a sequence of Tai Viet characters.
|
|
29 (defconst tai-viet-re
|
|
30 (format "[\xaa80-\xaac2\xaadb-\xaadf]+"))
|
|
31
|
|
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 . "ꪊꪋꪌꪍꪏꪓꪖꪜꪞꪡꪤꪨ")
|
|
36 (left-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))
|
|
45 (chars (cdr elt)))
|
|
46 (dotimes (i (length chars))
|
|
47 (aset table (aref chars i) category))))
|
|
48 table))
|
|
49
|
|
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))
|
|
54 prev-info)
|
|
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)
|
90949
|
59 (>= #xaa80 (setq ch (aref string from)))
|
|
60 (<= #xaaDF ch))
|
90938
|
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)))
|
|
68 from))
|
|
69
|
|
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))
|
|
75 (prev-viet nil)
|
|
76 ch info pos components overhang)
|
|
77 (while (< from to)
|
|
78 (or ch
|
|
79 (setq ch (char-after from)
|
|
80 info (aref tai-viet-glyph-info ch)))
|
|
81 (setq from (1+ from))
|
|
82 (if (not info)
|
|
83 (setq prev-viet nil
|
|
84 ch nil)
|
|
85 (if (memq info '(combining-vowel combining-tone))
|
|
86 (progn
|
|
87 ;; Display this as a spacing glyph.
|
|
88 (compose-region (1- from) from (string ?\t ch))
|
|
89 (setq prev-viet t
|
|
90 ch nil))
|
|
91 (setq pos (1- from)
|
|
92 components ch
|
|
93 overhang (if (eq info 'right-overhang)
|
|
94 'right-overhang
|
|
95 (if (and (not prev-viet) (eq info 'left-overhang))
|
|
96 'left-overhang))
|
|
97 prev-viet t
|
|
98 ch nil)
|
|
99 (if (and (< from to)
|
|
100 (setq ch (char-after from)
|
|
101 info (aref tai-viet-glyph-info ch)))
|
|
102 (if (memq info '(combining-vowel combining-tone))
|
|
103 (progn
|
|
104 (setq components
|
|
105 (list components normal-rule ch)
|
|
106 from (1+ from)
|
|
107 ch nil)
|
|
108 (if (and (< from to)
|
|
109 (setq ch (char-after from)
|
|
110 info (aref tai-viet-glyph-info ch))
|
|
111 (eq info 'combining-tone))
|
|
112 (setq components (nconc components
|
|
113 (list tone-rule ch))
|
|
114 from (1+ from)))
|
|
115 (if (eq overhang 'left-overhang)
|
|
116 (setq components (cons ?\t
|
|
117 (cons normal-rule components)))
|
|
118 (if (and (eq overhang 'right-overhang)
|
|
119 (>= from to))
|
|
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))))))))
|
|
129 from))
|
|
130
|
|
131
|
|
132 ;;;###autoload
|
|
133 (defun tai-viet-composition-function (pos &optional string)
|
|
134 (let (to)
|
|
135 (if string
|
|
136 (progn
|
|
137 (if (string-match tai-viet-re string pos)
|
|
138 (tai-viet-compose-string pos (match-end 0) string)
|
|
139 (1+ pos)))
|
|
140 (goto-char pos)
|
|
141 (if (looking-at tai-viet-re)
|
|
142 (tai-viet-compose-region pos (match-end 0))
|
|
143 (1+ pos)))))
|
|
144
|
|
145 ;;
|
|
146 (provide 'tai-viet-util)
|
90950
|
147
|
|
148 ;; arch-tag: a45ac3fc-07d0-44d5-8841-2ebea7e11f5b
|