Initial revision
[chise/xemacs-chise.git.1] / lisp / mule / chinese.el
1 ;;; chinese.el --- Support for Chinese
2
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5 ;; Copyright (C) 1997 MORIOKA Tomohiko
6
7 ;; Keywords: multilingual, Chinese
8
9 ;; This file is part of XEmacs.
10
11 ;; XEmacs is free software; you can redistribute it and/or modify it
12 ;; 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 ;; XEmacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 ;; 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; For Chinese, three character sets GB2312, BIG5, and CNS11643 are
29 ;; supported.
30
31 ;;; Code:
32
33 ;; Syntax of Chinese characters.
34 (modify-syntax-entry 'chinese-gb2312 "w")
35 (loop for row in '(33 34 41)
36       do (modify-syntax-entry `[chinese-gb2312 ,row] "."))
37 ;;(loop for row from 35 to  40
38 ;;      do (modify-syntax-entry `[chinese-gb2312 ,row] "w"))
39 ;;(loop for row from 42 to 126
40 ;;      do (modify-syntax-entry `[chinese-gb2312 ,row] "w"))
41
42 (modify-syntax-entry 'chinese-cns11643-1  "w")
43 (modify-syntax-entry 'chinese-cns11643-2  "w")
44 (modify-syntax-entry 'chinese-big5-1 "w")
45 (modify-syntax-entry 'chinese-big5-2 "w")
46
47 ;; CNS11643 Plane3 thru Plane7
48 ;; These represent more and more obscure Chinese characters.
49 ;; By the time you get to Plane 7, we're talking about characters
50 ;; that appear once in some ancient manuscript and whose meaning
51 ;; is unknown.
52
53 (flet
54     ((make-chinese-cns11643-charset
55       (name plane final)
56       (make-charset
57        name (concat "CNS 11643 Plane " plane " (Chinese traditional)")
58        `(registry 
59          ,(concat "CNS11643[.-]\\(.*[.-]\\)?" plane "$")
60          dimension 2
61          chars 94
62          final ,final
63          graphic 0))
64       (modify-syntax-entry   name "w")
65       (modify-category-entry name ?t)
66       ))
67   (make-chinese-cns11643-charset 'chinese-cns11643-3 "3" ?I)
68   (make-chinese-cns11643-charset 'chinese-cns11643-4 "4" ?J)
69   (make-chinese-cns11643-charset 'chinese-cns11643-5 "5" ?K)
70   (make-chinese-cns11643-charset 'chinese-cns11643-6 "6" ?L)
71   (make-chinese-cns11643-charset 'chinese-cns11643-7 "7" ?M)
72   )
73
74 ;; ISO-IR-165 (CCITT Extended GB)
75 ;;    It is based on CCITT Recommendation T.101, includes GB 2312-80 +
76 ;;    GB 8565-88 table A4 + 293 characters.
77 (make-charset
78  'chinese-isoir165
79  "ISO-IR-165 (CCITT Extended GB; Chinese simplified)"
80  `(registry "isoir165"
81    dimension 2
82    chars 94
83    final ?E
84    graphic 0))
85
86 ;; PinYin-ZhuYin
87 (make-charset 'sisheng "PinYin-ZhuYin"
88               '(registry "sisheng_cwnn\\|OMRON_UDC_ZH"
89                 dimension 1
90                 chars 94
91                 final ?0
92                 graphic 0
93                 ))
94
95 ;; If you prefer QUAIL to EGG, please modify below as you wish.
96 ;;(when (and (featurep 'egg) (featurep 'wnn))
97 ;;  (setq wnn-server-type 'cserver)
98 ;;  (load "pinyin")
99 ;;  (setq its:*standard-modes*
100 ;;        (cons (its:get-mode-map "PinYin") its:*standard-modes*)))
101 \f
102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
103 ;;; Chinese (general)
104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
105
106 ;; (make-coding-system
107 ;;  'chinese-iso-7bit 2 ?C
108 ;;  "ISO 2022 based 7bit encoding for Chinese GB and CNS (MIME:ISO-2022-CN)"
109 ;;  '(ascii
110 ;;    (nil chinese-gb2312 chinese-cns11643-1)
111 ;;    (nil chinese-cns11643-2)
112 ;;    (nil chinese-cns11643-3 chinese-cns11643-4 chinese-cns11643-5
113 ;;         chinese-cns11643-6 chinese-cns11643-7)
114 ;;    nil ascii-eol ascii-cntl seven locking-shift single-shift nil nil nil
115 ;;    init-bol))
116
117 ;; (define-coding-system-alias 'iso-2022-cn 'chinese-iso-7bit)
118 ;; (define-coding-system-alias 'iso-2022-cn-ext 'chinese-iso-7bit)
119
120 ;; (define-prefix-command 'describe-chinese-environment-map)
121 ;; (define-key-after describe-language-environment-map [Chinese]
122 ;;   '("Chinese" . describe-chinese-environment-map)
123 ;;   t)
124
125 ;; (define-prefix-command 'setup-chinese-environment-map)
126 ;; (define-key-after setup-language-environment-map [Chinese]
127 ;;   '("Chinese" . setup-chinese-environment-map)
128 ;;   t)
129 \f
130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
131 ;;; Chinese GB2312 (simplified) 
132 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
133
134 ;; (make-coding-system
135 ;;  'chinese-iso-8bit 2 ?c
136 ;;  "ISO 2022 based EUC encoding for Chinese GB2312 (MIME:CN-GB-2312)"
137 ;;  '((ascii t) chinese-gb2312 chinese-sisheng nil
138 ;;    nil ascii-eol ascii-cntl nil nil single-shift nil))
139
140 (make-coding-system
141  'cn-gb-2312 'iso2022
142  "Coding-system of Chinese EUC (Extended Unix Code)."
143  '(charset-g0 ascii
144    charset-g1 chinese-gb2312
145    charset-g2 sisheng
146    charset-g3 t
147    mnemonic "Zh-GB/EUC"
148    ))
149
150 ;; (define-coding-system-alias 'cn-gb-2312 'chinese-iso-8bit)
151 ;; (define-coding-system-alias 'euc-china 'chinese-iso-8bit)
152
153 (copy-coding-system 'cn-gb-2312 'gb2312)
154 (copy-coding-system 'cn-gb-2312 'chinese-euc)
155
156 ;; (make-coding-system
157 ;;  'chinese-hz 0 ?z
158 ;;  "Hz/ZW 7-bit encoding for Chinese GB2312 (MIME:HZ-GB-2312)"
159 ;;  nil)
160 ;; (put 'chinese-hz 'post-read-conversion 'post-read-decode-hz)
161 ;; (put 'chinese-hz 'pre-write-conversion 'pre-write-encode-hz)
162
163 (make-coding-system
164  'hz-gb-2312 'no-conversion
165  "Coding-system of Hz/ZW used for Chinese."
166  '(mnemonic "Zh-GB/Hz"
167    eol-type lf
168    post-read-conversion post-read-decode-hz
169    pre-write-conversion pre-write-encode-hz))
170
171 ;; (define-coding-system-alias 'hz-gb-2312 'chinese-hz)
172 ;; (define-coding-system-alias 'hz 'chinese-hz)
173
174 (copy-coding-system 'hz-gb-2312 'hz)
175 (copy-coding-system 'hz-gb-2312 'chinese-hz)
176
177 (defun post-read-decode-hz (len)
178   (let ((pos (point)))
179     (decode-hz-region pos (+ pos len))))
180
181 (defun pre-write-encode-hz (from to)
182   (let ((buf (current-buffer))
183         (work (get-buffer-create " *pre-write-encoding-work*")))
184     (set-buffer work)
185     (erase-buffer)
186     (if (stringp from)
187         (insert from)
188       (insert-buffer-substring buf from to))
189     (encode-hz-region 1 (point-max))
190     nil))
191            
192 (set-language-info-alist
193  "Chinese-GB" '((setup-function . (setup-chinese-gb-environment
194                                    . setup-chinese-environment-map))
195                 (charset . (chinese-gb2312 sisheng))
196                 (coding-system
197                  . (cn-gb-2312 iso-2022-7bit hz-gb-2312))
198                 (sample-text . "Chinese (\e$AVPND\e(B,\e$AFUM(;0\e(B,\e$A::So\e(B)    \e$ADc:C\e(B")
199                 (documentation . ("Support for Chinese GB2312 character set."
200                                   . describe-chinese-environment-map))
201                 ))
202
203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
204 ;; Chinese BIG5 (traditional)
205 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
206
207 ;; (make-coding-system
208 ;;  'chinese-big5 3 ?B "BIG5 8-bit encoding for Chinese (MIME:CN-BIG5)")
209
210 (make-coding-system
211  'big5 'big5
212  "Coding-system of BIG5."
213  '(mnemonic "Zh/Big5"))
214
215 ;; (define-coding-system-alias 'big5 'chinese-big5)
216 ;; (define-coding-system-alias 'cn-big5 'chinese-big5)
217
218 (copy-coding-system 'big5 'cn-big5)
219 (copy-coding-system 'big5 'chinese-big5)
220
221 ;; Big5 font requires special encoding.
222 (define-ccl-program ccl-encode-big5-font
223   `(0
224     ;; In:  R0:chinese-big5-1 or chinese-big5-2
225     ;;      R1:position code 1
226     ;;      R2:position code 2
227     ;; Out: R1:font code point 1
228     ;;      R2:font code point 2
229     ((r2 = ((((r1 - ?\x21) * 94) + r2) - ?\x21))
230      (if (r0 == ,(charset-id 'chinese-big5-2)) (r2 += 6280))
231      (r1 = ((r2 / 157) + ?\xA1))
232      (r2 %= 157)
233      (if (r2 < ?\x3F) (r2 += ?\x40) (r2 += ?\x62))))
234   "CCL program to encode a Big5 code to code point of Big5 font.")
235
236 ;; (setq font-ccl-encoder-alist
237 ;;       (cons (cons "big5" ccl-encode-big5-font) font-ccl-encoder-alist))
238
239 (set-charset-ccl-program 'chinese-big5-1 ccl-encode-big5-font)
240 (set-charset-ccl-program 'chinese-big5-2 ccl-encode-big5-font)
241
242 (set-language-info-alist
243  "Chinese-BIG5" '((setup-function . (setup-chinese-big5-environment
244                                      . setup-chinese-environment-map))
245                   (charset . (chinese-big5-1 chinese-big5-2))
246                   (coding-system . (big5 iso-2022-7bit))
247                   (sample-text . "Cantonese (\e$(0GnM$\e(B,\e$(0N]0*Hd\e(B) \e$(0*/=(\e(B, \e$(0+$)p\e(B")
248                   (documentation . ("Support for Chinese Big5 character set."
249                                     . describe-chinese-environment-map))
250                   ))
251
252 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
253 ;; Chinese CNS11643 (traditional)
254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
255
256 ;; (set-language-info-alist
257 ;;  "Chinese-CNS" '((setup-function . (setup-chinese-cns-environment
258 ;;                                     . setup-chinese-environment-map))
259 ;;                  (charset . (chinese-cns11643-1 chinese-cns11643-2
260 ;;                              chinese-cns11643-3 chinese-cns11643-4
261 ;;                              chinese-cns11643-5 chinese-cns11643-6
262 ;;                              chinese-cns11643-7))
263 ;;                  (coding-system . (chinese-iso-7bit))
264 ;;                  (documentation . ("Support for Chinese CNS character sets."
265 ;;                                    . describe-chinese-environment-map))
266 ;;                  ))
267
268 ;;; chinese.el ends here