Merge r21-4-11-chise-0_20-=ucs.
[chise/xemacs-chise.git.1] / lisp / mule / chinese.el
1 ;;; chinese.el --- Support for Chinese -*- coding: iso-2022-7bit; -*-
2
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5 ;; Copyright (C) 1997,1999,2001,2002 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-cns11643-3 "w")
45 (modify-syntax-entry 'chinese-cns11643-4 "w")
46 (modify-syntax-entry 'chinese-cns11643-5 "w")
47 (modify-syntax-entry 'chinese-cns11643-6 "w")
48 (modify-syntax-entry 'chinese-cns11643-7 "w")
49 (if (featurep 'utf-2000)
50     (modify-syntax-entry 'chinese-big5 "w")
51   (modify-syntax-entry 'chinese-big5-1 "w")
52   (modify-syntax-entry 'chinese-big5-2 "w"))
53
54 (modify-category-entry 'chinese-cns11643-3 ?t)
55 (modify-category-entry 'chinese-cns11643-4 ?t)
56 (modify-category-entry 'chinese-cns11643-5 ?t)
57 (modify-category-entry 'chinese-cns11643-6 ?t)
58 (modify-category-entry 'chinese-cns11643-7 ?t)
59
60 ;; If you prefer QUAIL to EGG, please modify below as you wish.
61 ;;(when (and (featurep 'egg) (featurep 'wnn))
62 ;;  (setq wnn-server-type 'cserver)
63 ;;  (load "pinyin")
64 ;;  (setq its:*standard-modes*
65 ;;        (cons (its:get-mode-map "PinYin") its:*standard-modes*)))
66 \f
67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68 ;;; Chinese (general)
69 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70
71 ;; (make-coding-system
72 ;;  'iso-2022-cn 2 ?C
73 ;;  "ISO 2022 based 7bit encoding for Chinese GB and CNS (MIME:ISO-2022-CN)"
74 ;;  '(ascii
75 ;;    (nil chinese-gb2312 chinese-cns11643-1)
76 ;;    (nil chinese-cns11643-2)
77 ;;    nil
78 ;;    nil ascii-eol ascii-cntl seven locking-shift single-shift nil nil nil
79 ;;    init-bol)
80 ;;  '((safe-charsets ascii chinese-gb2312 chinese-cns11643-1 chinese-cns11643-2)
81 ;;    (mime-charset . iso-2022-cn)))
82
83 ;; (define-coding-system-alias 'chinese-iso-7bit 'iso-2022-cn)
84
85 ;; (make-coding-system
86 ;;  'iso-2022-cn-ext 2 ?C
87 ;;  "ISO 2022 based 7bit encoding for Chinese GB and CNS (MIME:ISO-2022-CN-EXT)"
88 ;;  '(ascii
89 ;;    (nil chinese-gb2312 chinese-cns11643-1)
90 ;;    (nil chinese-cns11643-2)
91 ;;    (nil chinese-cns11643-3 chinese-cns11643-4 chinese-cns11643-5
92 ;;         chinese-cns11643-6 chinese-cns11643-7)
93 ;;    nil ascii-eol ascii-cntl seven locking-shift single-shift nil nil nil
94 ;;    init-bol)
95 ;;  '((safe-charsets ascii chinese-gb2312 chinese-cns11643-1 chinese-cns11643-2
96 ;;                   chinese-cns11643-3 chinese-cns11643-4 chinese-cns11643-5
97 ;;                   chinese-cns11643-6 chinese-cns11643-7)
98 ;;    (mime-charset . iso-2022-cn-ext)))
99
100 \f
101 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
102 ;;; Chinese GB2312 (simplified) 
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
104
105 ;; (make-coding-system
106 ;;  'chinese-iso-8bit 2 ?c
107 ;;  "ISO 2022 based EUC encoding for Chinese GB2312 (MIME:CN-GB-2312)"
108 ;;  '(ascii chinese-gb2312 nil nil
109 ;;    nil ascii-eol ascii-cntl nil nil nil nil)
110 ;;  '((safe-charsets ascii chinese-gb2312)
111 ;;    (mime-charset . cn-gb-2312)))
112
113 (make-coding-system
114  'cn-gb-2312 'iso2022
115  "Coding-system of Chinese EUC (Extended Unix Code)."
116  '(charset-g0 ascii
117    charset-g1 chinese-gb2312
118    charset-g2 sisheng
119    charset-g3 t
120    mnemonic "Zh-GB/EUC"
121    ))
122
123 ;; (define-coding-system-alias 'cn-gb-2312 'chinese-iso-8bit)
124 ;; (define-coding-system-alias 'euc-china 'chinese-iso-8bit)
125 ;; (define-coding-system-alias 'euc-cn 'chinese-iso-8bit)
126
127 (define-coding-system-alias 'gb2312 'cn-gb-2312)
128 (define-coding-system-alias 'chinese-euc 'cn-gb-2312)
129
130 ;; (make-coding-system
131 ;;  'chinese-hz 0 ?z
132 ;;  "Hz/ZW 7-bit encoding for Chinese GB2312 (MIME:HZ-GB-2312)"
133 ;;  nil
134 ;;  '((safe-charsets ascii chinese-gb2312)
135 ;;    (mime-charset . hz-gb-2312)
136 ;;    (post-read-conversion . post-read-decode-hz)
137 ;;    (pre-write-conversion . pre-write-encode-hz)))
138 ;; (put 'chinese-hz 'post-read-conversion 'post-read-decode-hz)
139 ;; (put 'chinese-hz 'pre-write-conversion 'pre-write-encode-hz)
140
141 (make-coding-system
142  'hz-gb-2312 'no-conversion
143  "Coding-system of Hz/ZW used for Chinese."
144  '(mnemonic "Zh-GB/Hz"
145    eol-type lf
146    post-read-conversion post-read-decode-hz
147    pre-write-conversion pre-write-encode-hz))
148
149 ;; (define-coding-system-alias 'hz-gb-2312 'chinese-hz)
150 ;; (define-coding-system-alias 'hz 'chinese-hz)
151
152 (define-coding-system-alias 'hz 'hz-gb-2312)
153
154 (defun post-read-decode-hz (len)
155   (let ((pos (point))
156         (buffer-modified-p (buffer-modified-p))
157         last-coding-system-used)
158     (prog1
159         (decode-hz-region pos (+ pos len))
160       (set-buffer-modified-p buffer-modified-p))))
161
162 (defun pre-write-encode-hz (from to)
163   (let ((buf (current-buffer)))
164     (set-buffer (generate-new-buffer " *temp*"))
165     (if (stringp from)
166         (insert from)
167       (insert-buffer-substring buf from to))
168     (let (last-coding-system-used)
169       (encode-hz-region 1 (point-max)))
170     nil))
171            
172 (set-language-info-alist
173  "Chinese-GB" '((setup-function . setup-chinese-gb-environment-internal)
174                 (charset chinese-gb2312 sisheng)
175                 (coding-system cn-gb-2312 iso-2022-7bit hz-gb-2312)
176                 (coding-priority cn-gb-2312 big5 iso-2022-7bit)
177                 (input-method . "chinese-py-punct")
178                 (features china-util)
179                 (sample-text . "Chinese (\e$AVPND\e(B,\e$AFUM(;0\e(B,\e$A::So\e(B)    \e$ADc:C\e(B")
180                 (documentation . "Support for Chinese GB2312 character set."))
181  '("Chinese"))
182
183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
184 ;; Chinese BIG5 (traditional)
185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
186
187 ;; (make-coding-system
188 ;;  'chinese-big5 3 ?B "BIG5 8-bit encoding for Chinese (MIME:CN-BIG5)"
189 ;;  nil
190 ;;  '((safe-charsets ascii chinese-big5-1 chinese-big5-2)
191 ;;    (mime-charset . cn-big5)
192 ;;    (charset-origin-alist (chinese-big5-1  "BIG5" encode-big5-char)
193 ;;                          (chinese-big5-2  "BIG5" encode-big5-char))))
194
195 (make-coding-system
196  'big5 'big5
197  "Coding-system of BIG5."
198  '(mnemonic "Zh/Big5"))
199
200 (when (featurep 'utf-2000)
201   (make-coding-system
202    'big5-er 'big5 "Coding-system of BIG5 with entity-reference."
203    '(mnemonic "Big5r"
204               charset-g0 ascii
205               charset-g1 chinese-big5
206               use-entity-reference t))
207
208   (make-coding-system
209    'big5-eten 'big5 "Coding-system of BIG5-ETEN."
210    '(mnemonic "Big5E"
211               charset-g0 ascii
212               charset-g1 chinese-big5-eten))
213   (make-coding-system
214    'big5-eten-er 'big5 "Coding-system of BIG5-ETEN with entity-reference."
215    '(mnemonic "Big5Er"
216               charset-g0 ascii
217               charset-g1 chinese-big5-eten
218               use-entity-reference t))
219
220   (make-coding-system
221    'big5-cdp 'big5 "Coding-system of BIG5 with CDP-extension."
222    '(mnemonic "Big5C"
223               charset-g0 ascii
224               charset-g1 chinese-big5-cdp))
225   )
226
227 ;; (define-coding-system-alias 'big5 'chinese-big5)
228 ;; (define-coding-system-alias 'cn-big5 'chinese-big5)
229
230 (define-coding-system-alias 'cn-big5 'big5)
231
232 ;; Big5 font requires special encoding.
233 (define-ccl-program ccl-encode-big5-font
234   `(0
235     ;; In:  R0:chinese-big5-1 or chinese-big5-2
236     ;;      R1:position code 1
237     ;;      R2:position code 2
238     ;; Out: R1:font code point 1
239     ;;      R2:font code point 2
240     ((r2 = ((((r1 - ?\x21) * 94) + r2) - ?\x21))
241      (if (r0 == ,(charset-id 'chinese-big5-2)) (r2 += 6280))
242      (r1 = ((r2 / 157) + ?\xA1))
243      (r2 %= 157)
244      (if (r2 < ?\x3F) (r2 += ?\x40) (r2 += ?\x62))))
245   "CCL program to encode a Big5 code to code point of Big5 font.")
246
247 ;; (setq font-ccl-encoder-alist
248 ;;       (cons (cons "big5" ccl-encode-big5-font) font-ccl-encoder-alist))
249
250 (set-charset-ccl-program 'chinese-big5-1 'ccl-encode-big5-font)
251 (set-charset-ccl-program 'chinese-big5-2 'ccl-encode-big5-font)
252
253 (set-language-info-alist
254  "Chinese-BIG5" '((charset chinese-big5-1 chinese-big5-2)
255                   (coding-system big5 iso-2022-7bit)
256                   (coding-priority big5 cn-gb-2312 iso-2022-7bit)
257                   (input-method . "chinese-py-punct-b5")
258                   (features china-util)
259                   (sample-text . "Cantonese (\e$(0GnM$\e(B,\e$(0N]0*Hd\e(B) \e$(0*/=(\e(B, \e$(0+$)p\e(B")
260                   (documentation . "Support for Chinese Big5 character set."))
261  '("Chinese"))
262
263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
264 ;; Chinese CNS11643 (traditional)
265 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
266
267 ;; (set-language-info-alist
268 ;;  "Chinese-CNS" '((charset chinese-cns11643-1 chinese-cns11643-2
269 ;;                           chinese-cns11643-3 chinese-cns11643-4
270 ;;                           chinese-cns11643-5 chinese-cns11643-6
271 ;;                           chinese-cns11643-7)
272 ;;                  (coding-system iso-2022-cn)
273 ;;                  (coding-priority iso-2022-cn chinese-big5 chinese-iso-8bit)
274 ;;                  (features china-util)
275 ;;                  (input-method . "chinese-cns-quick")
276 ;;                  (documentation . "Support for Chinese CNS character sets."))
277 ;;  '("Chinese"))
278
279 ;;; chinese.el ends here