Commit | Line | Data |
---|---|---|
ee4f8284 KH |
1 | ;;; tv-util.el --- support for Tai Viet -*- coding: utf-8 -*- |
2 | ||
ae940284 | 3 | ;; Copyright (C) 2007, 2008, 2009 |
ee4f8284 KH |
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 | ||
4936186e | 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
ee4f8284 | 12 | ;; it under the terms of the GNU General Public License as published by |
4936186e GM |
13 | ;; the Free Software Foundation, either version 3 of the License, or |
14 | ;; (at your option) any later version. | |
ee4f8284 KH |
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 | |
4936186e | 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
ee4f8284 KH |
23 | |
24 | ;;; Code | |
25 | ||
26 | ;; Regexp matching with a sequence of Tai Viet characters. | |
27 | (defconst tai-viet-re | |
482a9df0 | 28 | (format "[\xaa80-\xaac2\xaadb-\xaadf-]+")) |
ee4f8284 KH |
29 | |
30 | ;; Char-table of information about glyph type of Tai Viet characters. | |
31 | (defconst tai-viet-glyph-info | |
32 | (let ((table (make-char-table nil)) | |
33 | (specials '((right-overhang . "ꪊꪋꪌꪍꪏꪓꪖꪜꪞꪡꪤꪨ") | |
34 | (left-overhang . "ꫂ") | |
35 | (combining-vowel . "ꪴꪰꪲꪳꪷꪸꪾ") | |
482a9df0 KH |
36 | (combining-tone . "꪿꫁") |
37 | (misc . "-")))) | |
ee4f8284 KH |
38 | ;; Set all TaiViet characters to `t'. |
39 | (set-char-table-range table (cons #xaa80 #xaac2) t) | |
40 | (set-char-table-range table (cons #xaadb #xaadf) t) | |
41 | ;; Overwrite it for special characters. | |
42 | (dolist (elt specials) | |
43 | (let ((category (car elt)) | |
44 | (chars (cdr elt))) | |
45 | (dotimes (i (length chars)) | |
46 | (aset table (aref chars i) category)))) | |
47 | table)) | |
48 | ||
49 | (defun tai-viet-compose-string (from to string) | |
50 | "Compose Tai Viet characters in STRING between indices FROM and TO." | |
51 | (let* ((ch (aref string from)) | |
52 | (info (aref tai-viet-glyph-info ch)) | |
53 | prev-info) | |
54 | (if (eq info 'non-spacing) | |
55 | (compose-string string from (1+ from) (string ch ?\t))) | |
56 | (setq from (1+ from) prev-info info) | |
57 | (while (and (< from to) | |
c8e50a73 KH |
58 | (>= #xaa80 (setq ch (aref string from))) |
59 | (<= #xaaDF ch)) | |
ee4f8284 KH |
60 | (setq info (aref tai-viet-glyph-info ch)) |
61 | (if (and (eq info 'non-spacing) | |
62 | (eq prev-info 'non-spacing)) | |
63 | (compose-string from (1+ from) (string ?\t ch))) | |
64 | (setq from (1+ from) prev-info info)) | |
65 | (if (eq info 'right-overhang) | |
66 | (compose-string string (1- from) from (string ch ?\t))) | |
67 | from)) | |
68 | ||
69 | (defun tai-viet-compose-region (from to) | |
70 | "Compose Tai Viet characters in the region between FROM and TO." | |
71 | (decompose-region from to) | |
72 | (let ((normal-rule '(Br . Bl)) | |
73 | (tone-rule '(tr . bl)) | |
74 | (prev-viet nil) | |
75 | ch info pos components overhang) | |
76 | (while (< from to) | |
77 | (or ch | |
78 | (setq ch (char-after from) | |
79 | info (aref tai-viet-glyph-info ch))) | |
80 | (setq from (1+ from)) | |
81 | (if (not info) | |
82 | (setq prev-viet nil | |
83 | ch nil) | |
84 | (if (memq info '(combining-vowel combining-tone)) | |
85 | (progn | |
86 | ;; Display this as a spacing glyph. | |
87 | (compose-region (1- from) from (string ?\t ch)) | |
88 | (setq prev-viet t | |
89 | ch nil)) | |
90 | (setq pos (1- from) | |
91 | components ch | |
92 | overhang (if (eq info 'right-overhang) | |
93 | 'right-overhang | |
94 | (if (and (not prev-viet) (eq info 'left-overhang)) | |
95 | 'left-overhang)) | |
96 | prev-viet t | |
97 | ch nil) | |
98 | (if (and (< from to) | |
99 | (setq ch (char-after from) | |
100 | info (aref tai-viet-glyph-info ch))) | |
101 | (if (memq info '(combining-vowel combining-tone)) | |
102 | (progn | |
103 | (setq components | |
104 | (list components normal-rule ch) | |
105 | from (1+ from) | |
106 | ch nil) | |
107 | (if (and (< from to) | |
108 | (setq ch (char-after from) | |
109 | info (aref tai-viet-glyph-info ch)) | |
110 | (eq info 'combining-tone)) | |
111 | (setq components (nconc components | |
112 | (list tone-rule ch)) | |
113 | from (1+ from))) | |
114 | (if (eq overhang 'left-overhang) | |
115 | (setq components (cons ?\t | |
116 | (cons normal-rule components))) | |
117 | (if (and (eq overhang 'right-overhang) | |
118 | (>= from to)) | |
119 | (setq components (nconc components | |
120 | (list normal-rule ?\t))))) | |
121 | (compose-region pos from components)) | |
122 | (if (eq overhang 'left-overhang) | |
123 | (compose-region pos from (string ?\t components)))) | |
124 | (if (eq overhang 'left-overhang) | |
125 | (compose-region pos from (string ?\t components)) | |
126 | (if (and (eq overhang 'right-overhang) (>= from to)) | |
127 | (compose-region pos from (string components ?\t)))))))) | |
128 | from)) | |
129 | ||
130 | ||
131 | ;;;###autoload | |
268dff94 KH |
132 | (defun tai-viet-composition-function (from to font-object string) |
133 | (if string | |
134 | (if (string-match tai-viet-re string from) | |
135 | (tai-viet-compose-string from (match-end 0) string)) | |
136 | (goto-char from) | |
137 | (if (looking-at tai-viet-re) | |
138 | (tai-viet-compose-region from (match-end 0))))) | |
ee4f8284 KH |
139 | |
140 | ;; | |
141 | (provide 'tai-viet-util) | |
650e2d28 MB |
142 | |
143 | ;; arch-tag: a45ac3fc-07d0-44d5-8841-2ebea7e11f5b |