Initial git import
[sxemacs] / 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 MORIOKA Tomohiko
6
7 ;; Keywords: multilingual, Chinese
8
9 ;; This file is part of SXEmacs.
10
11 ;; SXEmacs 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 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; SXEmacs 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 this program.  If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;; For Chinese, three character sets GB2312, BIG5, and CNS11643 are
27 ;; supported.
28
29 ;;; Code:
30 (eval-when-compile (require 'ccl))
31
32 ;; Syntax of Chinese characters.
33 (modify-syntax-entry 'chinese-gb2312 "w")
34 (loop for row in '(33 34 41)
35       do (modify-syntax-entry `[chinese-gb2312 ,row] "."))
36 ;;(loop for row from 35 to  40
37 ;;      do (modify-syntax-entry `[chinese-gb2312 ,row] "w"))
38 ;;(loop for row from 42 to 126
39 ;;      do (modify-syntax-entry `[chinese-gb2312 ,row] "w"))
40
41 (modify-syntax-entry 'chinese-cns11643-1  "w")
42 (modify-syntax-entry 'chinese-cns11643-2  "w")
43 (modify-syntax-entry 'chinese-big5-1 "w")
44 (modify-syntax-entry 'chinese-big5-2 "w")
45
46 ;; CNS11643 Plane3 thru Plane7
47 ;; These represent more and more obscure Chinese characters.
48 ;; By the time you get to Plane 7, we're talking about characters
49 ;; that appear once in some ancient manuscript and whose meaning
50 ;; is unknown.
51
52 (flet
53     ((make-chinese-cns11643-charset
54       (name plane final)
55       (make-charset
56        name (concat "CNS 11643 Plane " plane " (Chinese traditional)")
57        `(registry 
58          ,(concat "CNS11643[.-]\\(.*[.-]\\)?" plane "$")
59          dimension 2
60          chars 94
61          final ,final
62          graphic 0))
63       (modify-syntax-entry   name "w")
64       (modify-category-entry name ?t)
65       ))
66   (make-chinese-cns11643-charset 'chinese-cns11643-3 "3" ?I)
67   (make-chinese-cns11643-charset 'chinese-cns11643-4 "4" ?J)
68   (make-chinese-cns11643-charset 'chinese-cns11643-5 "5" ?K)
69   (make-chinese-cns11643-charset 'chinese-cns11643-6 "6" ?L)
70   (make-chinese-cns11643-charset 'chinese-cns11643-7 "7" ?M)
71   )
72
73 ;; ISO-IR-165 (CCITT Extended GB)
74 ;;    It is based on CCITT Recommendation T.101, includes GB 2312-80 +
75 ;;    GB 8565-88 table A4 + 293 characters.
76 (make-charset
77  'chinese-isoir165
78  "ISO-IR-165 (CCITT Extended GB; Chinese simplified)"
79  `(registry "isoir165"
80    dimension 2
81    chars 94
82    final ?E
83    graphic 0))
84
85 ;; PinYin-ZhuYin
86 (make-charset 'sisheng "PinYin-ZhuYin"
87               '(registry "sisheng_cwnn\\|OMRON_UDC_ZH"
88                 dimension 1
89                 chars 94
90                 final ?0
91                 graphic 0
92                 ))
93
94 ;; If you prefer QUAIL to EGG, please modify below as you wish.
95 ;;(when (and (featurep 'egg) (featurep 'wnn))
96 ;;  (setq wnn-server-type 'cserver)
97 ;;  (load "pinyin")
98 ;;  (setq its:*standard-modes*
99 ;;        (cons (its:get-mode-map "PinYin") its:*standard-modes*)))
100 \f
101 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
102 ;;; Chinese (general)
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
104
105 ;; (make-coding-system
106 ;;  'iso-2022-cn 2 ?C
107 ;;  "ISO 2022 based 7bit encoding for Chinese GB and CNS (MIME:ISO-2022-CN)"
108 ;;  '(ascii
109 ;;    (nil chinese-gb2312 chinese-cns11643-1)
110 ;;    (nil chinese-cns11643-2)
111 ;;    nil
112 ;;    nil ascii-eol ascii-cntl seven locking-shift single-shift nil nil nil
113 ;;    init-bol)
114 ;;  '((safe-charsets ascii chinese-gb2312 chinese-cns11643-1 chinese-cns11643-2)
115 ;;    (mime-charset . iso-2022-cn)))
116
117 ;; (define-coding-system-alias 'chinese-iso-7bit 'iso-2022-cn)
118
119 ;; (make-coding-system
120 ;;  'iso-2022-cn-ext 2 ?C
121 ;;  "ISO 2022 based 7bit encoding for Chinese GB and CNS (MIME:ISO-2022-CN-EXT)"
122 ;;  '(ascii
123 ;;    (nil chinese-gb2312 chinese-cns11643-1)
124 ;;    (nil chinese-cns11643-2)
125 ;;    (nil chinese-cns11643-3 chinese-cns11643-4 chinese-cns11643-5
126 ;;         chinese-cns11643-6 chinese-cns11643-7)
127 ;;    nil ascii-eol ascii-cntl seven locking-shift single-shift nil nil nil
128 ;;    init-bol)
129 ;;  '((safe-charsets ascii chinese-gb2312 chinese-cns11643-1 chinese-cns11643-2
130 ;;                   chinese-cns11643-3 chinese-cns11643-4 chinese-cns11643-5
131 ;;                   chinese-cns11643-6 chinese-cns11643-7)
132 ;;    (mime-charset . iso-2022-cn-ext)))
133
134 \f
135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136 ;;; Chinese GB2312 (simplified) 
137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
138
139 ;; (make-coding-system
140 ;;  'chinese-iso-8bit 2 ?c
141 ;;  "ISO 2022 based EUC encoding for Chinese GB2312 (MIME:CN-GB-2312)"
142 ;;  '(ascii chinese-gb2312 nil nil
143 ;;    nil ascii-eol ascii-cntl nil nil nil nil)
144 ;;  '((safe-charsets ascii chinese-gb2312)
145 ;;    (mime-charset . cn-gb-2312)))
146
147 (make-coding-system
148  'cn-gb-2312 'iso2022
149  "Coding-system of Chinese EUC (Extended Unix Code)."
150  '(charset-g0 ascii
151    charset-g1 chinese-gb2312
152    charset-g2 sisheng
153    charset-g3 t
154    mnemonic "Zh-GB/EUC"
155    ))
156
157 ;; (define-coding-system-alias 'cn-gb-2312 'chinese-iso-8bit)
158 ;; (define-coding-system-alias 'euc-china 'chinese-iso-8bit)
159 ;; (define-coding-system-alias 'euc-cn 'chinese-iso-8bit)
160
161 (define-coding-system-alias 'gb2312 'cn-gb-2312)
162 (define-coding-system-alias 'chinese-euc 'cn-gb-2312)
163
164 ;; (make-coding-system
165 ;;  'chinese-hz 0 ?z
166 ;;  "Hz/ZW 7-bit encoding for Chinese GB2312 (MIME:HZ-GB-2312)"
167 ;;  nil
168 ;;  '((safe-charsets ascii chinese-gb2312)
169 ;;    (mime-charset . hz-gb-2312)
170 ;;    (post-read-conversion . post-read-decode-hz)
171 ;;    (pre-write-conversion . pre-write-encode-hz)))
172 ;; (put 'chinese-hz 'post-read-conversion 'post-read-decode-hz)
173 ;; (put 'chinese-hz 'pre-write-conversion 'pre-write-encode-hz)
174
175 (make-coding-system
176  'hz-gb-2312 'no-conversion
177  "Coding-system of Hz/ZW used for Chinese."
178  '(mnemonic "Zh-GB/Hz"
179    eol-type lf
180    post-read-conversion post-read-decode-hz
181    pre-write-conversion pre-write-encode-hz))
182
183 ;; (define-coding-system-alias 'hz-gb-2312 'chinese-hz)
184 ;; (define-coding-system-alias 'hz 'chinese-hz)
185
186 (define-coding-system-alias 'hz 'hz-gb-2312)
187
188 (defun post-read-decode-hz (len)
189   (let ((pos (point))
190         (buffer-modified-p (buffer-modified-p)))
191     (prog1
192         (declare-fboundp (decode-hz-region pos (+ pos len)))
193       (set-buffer-modified-p buffer-modified-p))))
194
195 (defun pre-write-encode-hz (from to)
196   (let ((buf (current-buffer)))
197     (set-buffer (generate-new-buffer " *temp*"))
198     (if (stringp from)
199         (insert from)
200       (insert-buffer-substring buf from to))
201     (declare-fboundp (encode-hz-region 1 (point-max)))
202     nil))
203            
204 (set-language-info-alist
205  "Chinese-GB" '((setup-function . setup-chinese-gb-environment-internal)
206                 (charset chinese-gb2312 sisheng)
207                 (coding-system cn-gb-2312 iso-2022-7bit hz-gb-2312)
208                 (coding-priority cn-gb-2312 big5 iso-2022-7bit)
209                 (input-method . "chinese-py-punct")
210                 (features china-util)
211                 (sample-text . "Chinese (\e$AVPND\e(B,\e$AFUM(;0\e(B,\e$A::So\e(B)    \e$ADc:C\e(B")
212                 (documentation . "Support for Chinese GB2312 character set."))
213  '("Chinese"))
214
215 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
216 ;; Chinese BIG5 (traditional)
217 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
218
219 ;; (make-coding-system
220 ;;  'chinese-big5 3 ?B "BIG5 8-bit encoding for Chinese (MIME:CN-BIG5)"
221 ;;  nil
222 ;;  '((safe-charsets ascii chinese-big5-1 chinese-big5-2)
223 ;;    (mime-charset . cn-big5)
224 ;;    (charset-origin-alist (chinese-big5-1  "BIG5" encode-big5-char)
225 ;;                          (chinese-big5-2  "BIG5" encode-big5-char))))
226
227 (make-coding-system
228  'big5 'big5
229  "Coding-system of BIG5."
230  '(mnemonic "Zh/Big5"))
231
232 ;; (define-coding-system-alias 'big5 'chinese-big5)
233 ;; (define-coding-system-alias 'cn-big5 'chinese-big5)
234
235 (define-coding-system-alias 'cn-big5 'big5)
236
237 ;; Big5 font requires special encoding.
238 (define-ccl-program ccl-encode-big5-font
239   `(0
240     ;; In:  R0:chinese-big5-1 or chinese-big5-2
241     ;;      R1:position code 1
242     ;;      R2:position code 2
243     ;; Out: R1:font code point 1
244     ;;      R2:font code point 2
245     ((r2 = ((((r1 - ?\x21) * 94) + r2) - ?\x21))
246      (if (r0 == ,(charset-id 'chinese-big5-2)) (r2 += 6280))
247      (r1 = ((r2 / 157) + ?\xA1))
248      (r2 %= 157)
249      (if (r2 < ?\x3F) (r2 += ?\x40) (r2 += ?\x62))))
250   "CCL program to encode a Big5 code to code point of Big5 font.")
251
252 ;; (setq font-ccl-encoder-alist
253 ;;       (cons (cons "big5" ccl-encode-big5-font) font-ccl-encoder-alist))
254
255 (set-charset-ccl-program 'chinese-big5-1 'ccl-encode-big5-font)
256 (set-charset-ccl-program 'chinese-big5-2 'ccl-encode-big5-font)
257
258 (set-language-info-alist
259  "Chinese-BIG5" '((charset chinese-big5-1 chinese-big5-2)
260                   (coding-system big5 iso-2022-7bit)
261                   (coding-priority big5 cn-gb-2312 iso-2022-7bit)
262                   (input-method . "chinese-py-punct-b5")
263                   (features china-util)
264                   (sample-text . "Cantonese (\e$(0GnM$\e(B,\e$(0N]0*Hd\e(B) \e$(0*/=(\e(B, \e$(0+$)p\e(B")
265                   (documentation . "Support for Chinese Big5 character set."))
266  '("Chinese"))
267
268 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
269 ;; Chinese CNS11643 (traditional)
270 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
271
272 ;; (set-language-info-alist
273 ;;  "Chinese-CNS" '((charset chinese-cns11643-1 chinese-cns11643-2
274 ;;                           chinese-cns11643-3 chinese-cns11643-4
275 ;;                           chinese-cns11643-5 chinese-cns11643-6
276 ;;                           chinese-cns11643-7)
277 ;;                  (coding-system iso-2022-cn)
278 ;;                  (coding-priority iso-2022-cn chinese-big5 chinese-iso-8bit)
279 ;;                  (features china-util)
280 ;;                  (input-method . "chinese-cns-quick")
281 ;;                  (documentation . "Support for Chinese CNS character sets."))
282 ;;  '("Chinese"))
283
284 ;;; chinese.el ends here