1 /* Header for UCS-4 character representation.
2 Copyright (C) 1999 Electrotechnical Laboratory, JAPAN.
3 Licensed to the Free Software Foundation.
5 This file is part of XEmacs.
7 XEmacs is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Rewritten by MORIOKA Tomohiko <tomo@m17n.org>. */
24 #ifndef _XEMACS_CHAR_UCS_H
25 #define _XEMACS_CHAR_UCS_H
27 #define valid_char_p(ch) 1
29 #define CHAR_ASCII_P(ch) ((ch) <= 0x7F)
32 /************************************************************************/
33 /* Definition of leading bytes */
34 /************************************************************************/
36 typedef int Charset_ID;
38 #define MIN_LEADING_BYTE 0x80
40 #define LEADING_BYTE_UCS_BMP 0x80
41 #define LEADING_BYTE_CONTROL_1 0x81 /* represent normal 80-9F */
44 #define CHARSET_ID_OFFSET_94 0x60
46 #define MIN_CHARSET_ID_PRIVATE_94 (CHARSET_ID_OFFSET_94 + '0')
47 #define MAX_CHARSET_ID_PRIVATE_94 (CHARSET_ID_OFFSET_94 + '?')
50 #define LEADING_BYTE_ASCII (CHARSET_ID_OFFSET_94 + 'B')
52 /* Right half of JIS X0201-1976 */
53 #define LEADING_BYTE_KATAKANA_JISX0201 (CHARSET_ID_OFFSET_94 + 'I')
55 /* Left half of JIS X0201-1976 */
56 #define LEADING_BYTE_LATIN_JISX0201 (CHARSET_ID_OFFSET_94 + 'J')
59 #define CHARSET_ID_OFFSET_96 0x70
61 /* Right half of ISO 8859-1 */
62 #define LEADING_BYTE_LATIN_ISO8859_1 (CHARSET_ID_OFFSET_96 + 'A')
64 /* Right half of ISO 8859-2 */
65 #define LEADING_BYTE_LATIN_ISO8859_2 (CHARSET_ID_OFFSET_96 + 'B')
67 /* Right half of ISO 8859-3 */
68 #define LEADING_BYTE_LATIN_ISO8859_3 (CHARSET_ID_OFFSET_96 + 'C')
70 /* Right half of ISO 8859-4 */
71 #define LEADING_BYTE_LATIN_ISO8859_4 (CHARSET_ID_OFFSET_96 + 'D')
73 /* Right half of ISO 8859-7 */
74 #define LEADING_BYTE_GREEK_ISO8859_7 (CHARSET_ID_OFFSET_96 + 'F')
76 /* Right half of ISO 8859-6 */
77 #define LEADING_BYTE_ARABIC_ISO8859_6 (CHARSET_ID_OFFSET_96 + 'G')
79 /* Right half of ISO 8859-8 */
80 #define LEADING_BYTE_HEBREW_ISO8859_8 (CHARSET_ID_OFFSET_96 + 'H')
82 /* Right half of ISO 8859-5 */
83 #define LEADING_BYTE_CYRILLIC_ISO8859_5 (CHARSET_ID_OFFSET_96 + 'L')
85 /* Right half of ISO 8859-9 */
86 #define LEADING_BYTE_LATIN_ISO8859_9 (CHARSET_ID_OFFSET_96 + 'M')
89 #define LEADING_BYTE_THAI_TIS620 (CHARSET_ID_OFFSET_96 + 'T')
92 #define MIN_LEADING_BYTE_PRIVATE_1 0xD0
93 #define MAX_LEADING_BYTE_PRIVATE_1 0xDF
96 #define CHARSET_ID_OFFSET_94x94 0xB0
99 #define LEADING_BYTE_CHINESE_BIG5_1 ('0' + CHARSET_ID_OFFSET_94x94)
102 #define LEADING_BYTE_CHINESE_BIG5_2 ('1' + CHARSET_ID_OFFSET_94x94)
104 #define MIN_LEADING_BYTE_PRIVATE_2 ('0' + CHARSET_ID_OFFSET_94x94)
105 #define MAX_LEADING_BYTE_PRIVATE_2 ('?' + CHARSET_ID_OFFSET_94x94)
107 /* Japanese JIS X0208-1978 */
108 #define LEADING_BYTE_JAPANESE_JISX0208_1978 \
109 ('@' + CHARSET_ID_OFFSET_94x94)
111 /* Chinese Hanzi GB2312-1980 */
112 #define LEADING_BYTE_CHINESE_GB2312 ('A' + CHARSET_ID_OFFSET_94x94)
114 /* Japanese JIS X0208-1983 */
115 #define LEADING_BYTE_JAPANESE_JISX0208 ('B' + CHARSET_ID_OFFSET_94x94)
117 /* Hangul KS C5601-1987 */
118 #define LEADING_BYTE_KOREAN_KSC5601 ('C' + CHARSET_ID_OFFSET_94x94)
120 /* Japanese JIS X0212-1990 */
121 #define LEADING_BYTE_JAPANESE_JISX0212 ('D' + CHARSET_ID_OFFSET_94x94)
123 /* CCITT Extended GB */
124 #define LEADING_BYTE_CHINESE_CCITT_GB ('E' + CHARSET_ID_OFFSET_94x94)
126 /* Chinese CNS11643 Set 1 */
127 #define LEADING_BYTE_CHINESE_CNS11643_1 ('G' + CHARSET_ID_OFFSET_94x94)
129 /* Chinese CNS11643 Set 2 */
130 #define LEADING_BYTE_CHINESE_CNS11643_2 ('H' + CHARSET_ID_OFFSET_94x94)
132 /* Chinese CNS11643 Set 3 */
133 #define LEADING_BYTE_CHINESE_CNS11643_3 ('I' + CHARSET_ID_OFFSET_94x94)
135 /* Chinese CNS11643 Set 4 */
136 #define LEADING_BYTE_CHINESE_CNS11643_4 ('J' + CHARSET_ID_OFFSET_94x94)
138 /* Chinese CNS11643 Set 5 */
139 #define LEADING_BYTE_CHINESE_CNS11643_5 ('K' + CHARSET_ID_OFFSET_94x94)
141 /* Chinese CNS11643 Set 6 */
142 #define LEADING_BYTE_CHINESE_CNS11643_6 ('L' + CHARSET_ID_OFFSET_94x94)
144 /* Chinese CNS11643 Set 7 */
145 #define LEADING_BYTE_CHINESE_CNS11643_7 ('M' + CHARSET_ID_OFFSET_94x94)
147 /* DPRK Hangul KPS 9566-1997 */
148 #define LEADING_BYTE_KOREAN_KPS9566 ('N' + CHARSET_ID_OFFSET_94x94)
150 #define MIN_LEADING_BYTE_OFFICIAL_2 LEADING_BYTE_JAPANESE_JISX0208_1978
151 #define MAX_LEADING_BYTE_OFFICIAL_2 LEADING_BYTE_KOREAN_KPS9566
153 #define NUM_LEADING_BYTES 256
156 /************************************************************************/
157 /* Information about a particular character set */
158 /************************************************************************/
162 struct lcrecord_header header;
166 Lisp_Object doc_string, registry, short_name, long_name;
168 Lisp_Object reverse_direction_charset;
170 Lisp_Object ccl_program;
172 /* Final byte of this character set in ISO2022 designating escape sequence */
175 /* Number of bytes (1 - 4) required in the internal representation
176 for characters in this character set. This is *not* the
177 same as the dimension of the character set). */
178 unsigned int rep_bytes;
180 /* Number of columns a character in this charset takes up, on TTY
181 devices. Not used for X devices. */
182 unsigned int columns;
184 /* Direction of this character set */
185 unsigned int direction;
187 /* Type of this character set (94, 96, 94x94, 96x96) */
190 /* Number of bytes used in encoding of this character set (1 or 2) */
191 unsigned int dimension;
193 /* Number of chars in each dimension (usually 94 or 96) */
196 /* Which half of font to be used to display this character set */
197 unsigned int graphic;
200 DECLARE_LRECORD (charset, struct Lisp_Charset);
201 #define XCHARSET(x) XRECORD (x, charset, struct Lisp_Charset)
202 #define XSETCHARSET(x, p) XSETRECORD (x, p, charset)
203 #define CHARSETP(x) RECORDP (x, charset)
204 #define GC_CHARSETP(x) GC_RECORDP (x, charset)
205 #define CHECK_CHARSET(x) CHECK_RECORD (x, charset)
206 #define CONCHECK_CHARSET(x) CONCHECK_RECORD (x, charset)
208 #define CHARSET_TYPE_94 0 /* This charset includes 94 characters. */
209 #define CHARSET_TYPE_96 1 /* This charset includes 96 characters. */
210 #define CHARSET_TYPE_94X94 2 /* This charset includes 94x94 characters. */
211 #define CHARSET_TYPE_96X96 3 /* This charset includes 96x96 characters. */
212 #define CHARSET_TYPE_128X128 4 /* This charset includes 128x128 characters. */
213 #define CHARSET_TYPE_256X256 5 /* This charset includes 256x256 characters. */
215 #define CHARSET_LEFT_TO_RIGHT 0
216 #define CHARSET_RIGHT_TO_LEFT 1
218 /* Leading byte and id have been regrouped. -- OG */
219 #define CHARSET_ID(cs) ((cs)->id)
220 #define CHARSET_LEADING_BYTE(cs) ((Bufbyte)(CHARSET_ID(cs)))
221 #define CHARSET_NAME(cs) ((cs)->name)
222 #define CHARSET_SHORT_NAME(cs) ((cs)->short_name)
223 #define CHARSET_LONG_NAME(cs) ((cs)->long_name)
224 #define CHARSET_REP_BYTES(cs) ((cs)->rep_bytes)
225 #define CHARSET_COLUMNS(cs) ((cs)->columns)
226 #define CHARSET_GRAPHIC(cs) ((cs)->graphic)
227 #define CHARSET_TYPE(cs) ((cs)->type)
228 #define CHARSET_DIRECTION(cs) ((cs)->direction)
229 #define CHARSET_FINAL(cs) ((cs)->final)
230 #define CHARSET_DOC_STRING(cs) ((cs)->doc_string)
231 #define CHARSET_REGISTRY(cs) ((cs)->registry)
232 #define CHARSET_CCL_PROGRAM(cs) ((cs)->ccl_program)
233 #define CHARSET_DIMENSION(cs) ((cs)->dimension)
234 #define CHARSET_CHARS(cs) ((cs)->chars)
235 #define CHARSET_REVERSE_DIRECTION_CHARSET(cs) ((cs)->reverse_direction_charset)
238 #define XCHARSET_ID(cs) CHARSET_ID (XCHARSET (cs))
239 #define XCHARSET_NAME(cs) CHARSET_NAME (XCHARSET (cs))
240 #define XCHARSET_SHORT_NAME(cs) CHARSET_SHORT_NAME (XCHARSET (cs))
241 #define XCHARSET_LONG_NAME(cs) CHARSET_LONG_NAME (XCHARSET (cs))
242 #define XCHARSET_REP_BYTES(cs) CHARSET_REP_BYTES (XCHARSET (cs))
243 #define XCHARSET_COLUMNS(cs) CHARSET_COLUMNS (XCHARSET (cs))
244 #define XCHARSET_GRAPHIC(cs) CHARSET_GRAPHIC (XCHARSET (cs))
245 #define XCHARSET_TYPE(cs) CHARSET_TYPE (XCHARSET (cs))
246 #define XCHARSET_DIRECTION(cs) CHARSET_DIRECTION (XCHARSET (cs))
247 #define XCHARSET_FINAL(cs) CHARSET_FINAL (XCHARSET (cs))
248 #define XCHARSET_DOC_STRING(cs) CHARSET_DOC_STRING (XCHARSET (cs))
249 #define XCHARSET_REGISTRY(cs) CHARSET_REGISTRY (XCHARSET (cs))
250 #define XCHARSET_LEADING_BYTE(cs) CHARSET_LEADING_BYTE (XCHARSET (cs))
251 #define XCHARSET_CCL_PROGRAM(cs) CHARSET_CCL_PROGRAM (XCHARSET (cs))
252 #define XCHARSET_DIMENSION(cs) CHARSET_DIMENSION (XCHARSET (cs))
253 #define XCHARSET_CHARS(cs) CHARSET_CHARS (XCHARSET (cs))
254 #define XCHARSET_REVERSE_DIRECTION_CHARSET(cs) \
255 CHARSET_REVERSE_DIRECTION_CHARSET (XCHARSET (cs))
257 /* Table of charsets indexed by (leading byte - 128). */
258 extern Lisp_Object charset_by_leading_byte[NUM_LEADING_BYTES];
260 /* Table of charsets indexed by type/final-byte. */
261 extern Lisp_Object charset_by_attributes[4][128];
263 #ifdef ERROR_CHECK_TYPECHECK
264 /* int not Bufbyte even though that is the actual type of a leading byte.
265 This way, out-ot-range values will get caught rather than automatically
267 INLINE Lisp_Object CHARSET_BY_LEADING_BYTE (Charset_ID lb);
269 CHARSET_BY_LEADING_BYTE (Charset_ID lb)
271 assert (lb >= MIN_LEADING_BYTE &&
272 lb < (MIN_LEADING_BYTE + NUM_LEADING_BYTES));
273 return charset_by_leading_byte[lb - MIN_LEADING_BYTE];
278 #define CHARSET_BY_LEADING_BYTE(lb) \
279 (charset_by_leading_byte[(lb) - MIN_LEADING_BYTE])
283 #define CHARSET_BY_ATTRIBUTES(type, final, dir) \
284 (charset_by_attributes[type][final])
287 /************************************************************************/
288 /* Dealing with characters */
289 /************************************************************************/
291 #define MAX_CHAR_BASIC_LATIN 0x007F
293 #define MIN_CHAR_GREEK 0x0370
294 #define MAX_CHAR_GREEK 0x03CF
296 #define MIN_CHAR_CYRILLIC 0x0400
297 #define MAX_CHAR_CYRILLIC 0x045F
299 #define MIN_CHAR_HEBREW 0x0590
300 #define MAX_CHAR_HEBREW 0x05EF
302 #define MIN_CHAR_THAI 0x0E00
303 #define MAX_CHAR_THAI 0x0E5F
305 #define MIN_CHAR_HALFWIDTH_KATAKANA 0xFF60
306 #define MAX_CHAR_HALFWIDTH_KATAKANA 0xFF9F
308 #define MIN_CHAR_94 0xE90940
309 #define MAX_CHAR_94 (MIN_CHAR_94 + 94 * 80 - 1)
310 #define MIN_CHAR_96 (MIN_CHAR_94 + 94 * 80)
311 #define MAX_CHAR_96 (MIN_CHAR_96 + 96 * 80 - 1)
313 #define MIN_CHAR_94x94 0xE9F6C0
314 #define MAX_CHAR_94x94 (MIN_CHAR_94x94 + 94 * 94 * 80 - 1)
315 #define MIN_CHAR_96x96 0xF4C000
316 #define MAX_CHAR_96x96 (MIN_CHAR_96x96 + 96 * 96 * 80 - 1)
319 /* Return a character whose charset is CHARSET and position-codes
320 are C1 and C2. TYPE9N character ignores C2. */
322 INLINE Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2);
324 MAKE_CHAR (Lisp_Object charset, int c1, int c2)
326 if (EQ (charset, Vcharset_ascii))
328 else if (EQ (charset, Vcharset_control_1))
330 else if (EQ (charset, Vcharset_latin_iso8859_1))
332 else if (EQ (charset, Vcharset_greek_iso8859_7))
333 return c1 + MIN_CHAR_GREEK - 0x20;
334 else if (EQ (charset, Vcharset_cyrillic_iso8859_5))
335 return c1 + MIN_CHAR_CYRILLIC - 0x20;
336 else if (EQ (charset, Vcharset_hebrew_iso8859_8))
337 return c1 + MIN_CHAR_HEBREW - 0x20;
338 else if (EQ (charset, Vcharset_thai_tis620))
339 return c1 + MIN_CHAR_THAI - 0x20;
340 else if (EQ (charset, Vcharset_katakana_jisx0201))
342 return c1 + MIN_CHAR_HALFWIDTH_KATAKANA - 0x20;
345 else if (XCHARSET_DIMENSION (charset) == 1)
347 switch (XCHARSET_CHARS (charset))
351 + (XCHARSET_FINAL (charset) - '0') * 94 + (c1 - 33);
354 + (XCHARSET_FINAL (charset) - '0') * 96 + (c1 - 32);
361 switch (XCHARSET_CHARS (charset))
364 return MIN_CHAR_94x94
365 + (XCHARSET_FINAL (charset) - '0') * 94 * 94
366 + (c1 - 33) * 94 + (c2 - 33);
368 return MIN_CHAR_96x96
369 + (XCHARSET_FINAL (charset) - '0') * 96 * 96
370 + (c1 - 32) * 96 + (c2 - 32);
377 extern Charset_ID latin_a_char_to_charset[128];
378 extern unsigned char latin_a_char_to_byte1[128];
379 extern unsigned char latin_a_char_to_byte2[128];
381 INLINE void breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2);
383 breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
385 if (c <= MAX_CHAR_BASIC_LATIN)
387 *charset = Vcharset_ascii;
393 *charset = Vcharset_control_1;
399 *charset = Vcharset_latin_iso8859_1;
406 = CHARSET_BY_LEADING_BYTE (latin_a_char_to_charset[c - 0x100]);
407 *c1 = latin_a_char_to_byte1[c - 0x100];
408 *c2 = latin_a_char_to_byte2[c - 0x100];
410 else if (c < MIN_CHAR_GREEK)
412 printf("not break up u+%x", c);
415 else if (c <= MAX_CHAR_GREEK)
417 *charset = Vcharset_greek_iso8859_7;
418 *c1 = c - MIN_CHAR_GREEK + 0x20;
421 else if (c < MIN_CHAR_CYRILLIC)
423 printf("not break up u+%x", c);
426 else if (c <= MAX_CHAR_CYRILLIC)
428 *charset = Vcharset_cyrillic_iso8859_5;
429 *c1 = c - MIN_CHAR_CYRILLIC + 0x20;
432 else if (c < MIN_CHAR_HEBREW)
434 printf("not break up u+%x", c);
437 else if (c <= MAX_CHAR_HEBREW)
439 *charset = Vcharset_hebrew_iso8859_8;
440 *c1 = c - MIN_CHAR_HEBREW + 0x20;
443 else if (c < MIN_CHAR_THAI)
445 printf("not break up u+%x", c);
448 else if (c <= MAX_CHAR_THAI)
450 *charset = Vcharset_thai_tis620;
451 *c1 = c - MIN_CHAR_THAI + 0x20;
454 else if (c < MIN_CHAR_HALFWIDTH_KATAKANA)
456 printf("not break up u+%x", c);
459 else if (c <= MAX_CHAR_HALFWIDTH_KATAKANA)
461 *charset = Vcharset_katakana_jisx0201;
462 *c1 = c - MIN_CHAR_HALFWIDTH_KATAKANA + 0x20;
465 else if (c <= MAX_CHAR_94)
468 = CHARSET_BY_ATTRIBUTES (CHARSET_TYPE_94,
469 ((c - MIN_CHAR_94) / 94) + '0',
470 CHARSET_LEFT_TO_RIGHT);
471 *c1 = ((c - MIN_CHAR_94) % 94) + 33;
474 else if (c <= MAX_CHAR_96)
477 = CHARSET_BY_ATTRIBUTES (CHARSET_TYPE_96,
478 ((c - MIN_CHAR_96) / 96) + '0',
479 CHARSET_LEFT_TO_RIGHT);
480 *c1 = ((c - MIN_CHAR_96) % 96) + 32;
483 else if (c <= MAX_CHAR_94x94)
486 = CHARSET_BY_ATTRIBUTES (CHARSET_TYPE_94X94,
487 ((c - MIN_CHAR_94x94) / (94 * 94)) + '0',
488 CHARSET_LEFT_TO_RIGHT);
489 *c1 = (((c - MIN_CHAR_94x94) / 94) % 94) + 33;
490 *c2 = ((c - MIN_CHAR_94x94) % 94) + 33;
492 else if (c <= MAX_CHAR_96x96)
495 = CHARSET_BY_ATTRIBUTES (CHARSET_TYPE_96X96,
496 ((c - MIN_CHAR_96x96) / (96 * 96)) + '0',
497 CHARSET_LEFT_TO_RIGHT);
498 *c1 = (((c - MIN_CHAR_96x96) / 96) % 96) + 32;
499 *c2 = ((c - MIN_CHAR_96x96) % 96) + 32;
508 #define BREAKUP_CHAR(ch, charset, b1, b2) \
509 breakup_char_1 (ch, &(charset), &(b1), &(b2))
511 INLINE Lisp_Object CHAR_CHARSET (Emchar ch);
513 CHAR_CHARSET (Emchar ch)
518 BREAKUP_CHAR(ch, charset, b1, b2);
522 #define CHAR_LEADING_BYTE(c) (XCHARSET_LEADING_BYTE(CHAR_CHARSET(c)))
525 #ifdef ENABLE_COMPOSITE_CHARS
526 /************************************************************************/
527 /* Composite characters */
528 /************************************************************************/
530 Emchar lookup_composite_char (Bufbyte *str, int len);
531 Lisp_Object composite_char_string (Emchar ch);
532 #endif /* ENABLE_COMPOSITE_CHARS */
535 /************************************************************************/
536 /* Exported functions */
537 /************************************************************************/
539 EXFUN (Ffind_charset, 1);
540 EXFUN (Fget_charset, 1);
542 extern Lisp_Object Vcharset_chinese_big5_1;
543 extern Lisp_Object Vcharset_chinese_big5_2;
544 extern Lisp_Object Vcharset_japanese_jisx0208;
545 extern Lisp_Object Vcharset_japanese_jisx0212;
547 #endif /* _XEMACS_CHAR_UCS_H */