annotate lisp/language/tv-util.el @ 98285:9794ceb530d3

*** empty log message ***
author Glenn Morris <rgm@gnu.org>
date Sat, 20 Sep 2008 23:37:47 +0000
parents 55b7f25d920a
children a9dc0e7c3f2b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
90938
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1 ;;; tv-util.el --- support for Tai Viet -*- coding: utf-8 -*-
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2
91437
0c76c1616cf9 Update copyright years and GPL version.
Glenn Morris <rgm@gnu.org>
parents: 91277
diff changeset
3 ;; Copyright (C) 2007, 2008
90938
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
4 ;; National Institute of Advanced Industrial Science and Technology (AIST)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
5 ;; Registration Number H13PRO009
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
6
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
7 ;; Keywords: multilingual, Tai Viet, i18n
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
8
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
10
94665
55b7f25d920a Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 91437
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
90938
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94665
55b7f25d920a Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 91437
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
55b7f25d920a Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 91437
diff changeset
14 ;; (at your option) any later version.
90938
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
15
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
20
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94665
55b7f25d920a Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 91437
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
90938
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
23
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
24 ;;; Code
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
25
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
26 ;; Regexp matching with a sequence of Tai Viet characters.
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
27 (defconst tai-viet-re
91217
9cf3b1c148b9 (tai-viet-re): Include '-'.
Kenichi Handa <handa@m17n.org>
parents: 90950
diff changeset
28 (format "[\xaa80-\xaac2\xaadb-\xaadf-]+"))
90938
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
29
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
30 ;; Char-table of information about glyph type of Tai Viet characters.
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
31 (defconst tai-viet-glyph-info
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
32 (let ((table (make-char-table nil))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
33 (specials '((right-overhang . "ꪊꪋꪌꪍꪏꪓꪖꪜꪞꪡꪤꪨ")
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
34 (left-overhang . "ꫂ")
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
35 (combining-vowel . "ꪴꪰꪲꪳꪷꪸꪾ")
91217
9cf3b1c148b9 (tai-viet-re): Include '-'.
Kenichi Handa <handa@m17n.org>
parents: 90950
diff changeset
36 (combining-tone . "꪿꫁")
9cf3b1c148b9 (tai-viet-re): Include '-'.
Kenichi Handa <handa@m17n.org>
parents: 90950
diff changeset
37 (misc . "-"))))
90938
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
38 ;; Set all TaiViet characters to `t'.
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
39 (set-char-table-range table (cons #xaa80 #xaac2) t)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
40 (set-char-table-range table (cons #xaadb #xaadf) t)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
41 ;; Overwrite it for special characters.
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
42 (dolist (elt specials)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
43 (let ((category (car elt))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
44 (chars (cdr elt)))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
45 (dotimes (i (length chars))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
46 (aset table (aref chars i) category))))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
47 table))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
48
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
49 (defun tai-viet-compose-string (from to string)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
50 "Compose Tai Viet characters in STRING between indices FROM and TO."
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
51 (let* ((ch (aref string from))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
52 (info (aref tai-viet-glyph-info ch))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
53 prev-info)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
54 (if (eq info 'non-spacing)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
55 (compose-string string from (1+ from) (string ch ?\t)))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
56 (setq from (1+ from) prev-info info)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
57 (while (and (< from to)
90949
bba587c2b334 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 90938
diff changeset
58 (>= #xaa80 (setq ch (aref string from)))
bba587c2b334 *** empty log message ***
Kenichi Handa <handa@m17n.org>
parents: 90938
diff changeset
59 (<= #xaaDF ch))
90938
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
60 (setq info (aref tai-viet-glyph-info ch))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
61 (if (and (eq info 'non-spacing)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
62 (eq prev-info 'non-spacing))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
63 (compose-string from (1+ from) (string ?\t ch)))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
64 (setq from (1+ from) prev-info info))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
65 (if (eq info 'right-overhang)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
66 (compose-string string (1- from) from (string ch ?\t)))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
67 from))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
68
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
69 (defun tai-viet-compose-region (from to)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
70 "Compose Tai Viet characters in the region between FROM and TO."
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
71 (decompose-region from to)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
72 (let ((normal-rule '(Br . Bl))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
73 (tone-rule '(tr . bl))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
74 (prev-viet nil)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
75 ch info pos components overhang)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
76 (while (< from to)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
77 (or ch
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
78 (setq ch (char-after from)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
79 info (aref tai-viet-glyph-info ch)))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
80 (setq from (1+ from))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
81 (if (not info)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
82 (setq prev-viet nil
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
83 ch nil)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
84 (if (memq info '(combining-vowel combining-tone))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
85 (progn
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
86 ;; Display this as a spacing glyph.
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
87 (compose-region (1- from) from (string ?\t ch))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
88 (setq prev-viet t
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
89 ch nil))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
90 (setq pos (1- from)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
91 components ch
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
92 overhang (if (eq info 'right-overhang)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
93 'right-overhang
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
94 (if (and (not prev-viet) (eq info 'left-overhang))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
95 'left-overhang))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
96 prev-viet t
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
97 ch nil)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
98 (if (and (< from to)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
99 (setq ch (char-after from)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
100 info (aref tai-viet-glyph-info ch)))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
101 (if (memq info '(combining-vowel combining-tone))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
102 (progn
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
103 (setq components
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
104 (list components normal-rule ch)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
105 from (1+ from)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
106 ch nil)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
107 (if (and (< from to)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
108 (setq ch (char-after from)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
109 info (aref tai-viet-glyph-info ch))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
110 (eq info 'combining-tone))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
111 (setq components (nconc components
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
112 (list tone-rule ch))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
113 from (1+ from)))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
114 (if (eq overhang 'left-overhang)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
115 (setq components (cons ?\t
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
116 (cons normal-rule components)))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
117 (if (and (eq overhang 'right-overhang)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
118 (>= from to))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
119 (setq components (nconc components
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
120 (list normal-rule ?\t)))))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
121 (compose-region pos from components))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
122 (if (eq overhang 'left-overhang)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
123 (compose-region pos from (string ?\t components))))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
124 (if (eq overhang 'left-overhang)
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
125 (compose-region pos from (string ?\t components))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
126 (if (and (eq overhang 'right-overhang) (>= from to))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
127 (compose-region pos from (string components ?\t))))))))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
128 from))
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
129
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
130
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
131 ;;;###autoload
91277
0dfd79b5e5c5 (tai-viet-composition-function): Fix
Kenichi Handa <handa@m17n.org>
parents: 91217
diff changeset
132 (defun tai-viet-composition-function (from to font-object string)
0dfd79b5e5c5 (tai-viet-composition-function): Fix
Kenichi Handa <handa@m17n.org>
parents: 91217
diff changeset
133 (if string
0dfd79b5e5c5 (tai-viet-composition-function): Fix
Kenichi Handa <handa@m17n.org>
parents: 91217
diff changeset
134 (if (string-match tai-viet-re string from)
0dfd79b5e5c5 (tai-viet-composition-function): Fix
Kenichi Handa <handa@m17n.org>
parents: 91217
diff changeset
135 (tai-viet-compose-string from (match-end 0) string))
0dfd79b5e5c5 (tai-viet-composition-function): Fix
Kenichi Handa <handa@m17n.org>
parents: 91217
diff changeset
136 (goto-char from)
0dfd79b5e5c5 (tai-viet-composition-function): Fix
Kenichi Handa <handa@m17n.org>
parents: 91217
diff changeset
137 (if (looking-at tai-viet-re)
0dfd79b5e5c5 (tai-viet-composition-function): Fix
Kenichi Handa <handa@m17n.org>
parents: 91217
diff changeset
138 (tai-viet-compose-region from (match-end 0)))))
90938
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
139
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
140 ;;
ab2b53b01252 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
141 (provide 'tai-viet-util)
90950
8568c29985a3 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 90949
diff changeset
142
8568c29985a3 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 90949
diff changeset
143 ;; arch-tag: a45ac3fc-07d0-44d5-8841-2ebea7e11f5b