1 /* Header for leading-byte character representation.
2 Copyright (C) 1999,2000 MORIOKA Tomohiko
4 This file is part of XEmacs.
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #ifndef _XEMACS_CHAR_LB_H
22 #define _XEMACS_CHAR_LB_H
24 #include "mule-charset.h"
26 int non_ascii_valid_char_p (Emchar ch);
28 INLINE_HEADER int valid_char_p (Emchar ch);
30 valid_char_p (Emchar ch)
32 return ((unsigned int) (ch) <= 0xff) || non_ascii_valid_char_p (ch);
35 #define CHAR_COLUMNS(c) (XCHARSET_COLUMNS(CHAR_CHARSET(c)))
38 INLINE_HEADER Emchar DECODE_CHAR (Lisp_Object charset, int code_point);
40 DECODE_CHAR (Lisp_Object charset, int code_point)
42 if (EQ (charset, Vcharset_ascii))
44 else if (EQ (charset, Vcharset_control_1))
45 return code_point | 0x80;
46 else if (XCHARSET_DIMENSION (charset) == 1)
47 return ((XCHARSET_LEADING_BYTE (charset) -
48 FIELD2_TO_OFFICIAL_LEADING_BYTE) << 7) | code_point;
49 else if (!XCHARSET_PRIVATE_P (charset))
50 return ((XCHARSET_LEADING_BYTE (charset) -
51 FIELD1_TO_OFFICIAL_LEADING_BYTE) << 14)
52 | ((code_point >> 1) & 0x3F80) | (code_point & 0x7F);
54 return ((XCHARSET_LEADING_BYTE (charset) -
55 FIELD1_TO_PRIVATE_LEADING_BYTE) << 14)
56 | ((code_point >> 1) & 0x3F80) | (code_point & 0x7F);
59 INLINE_HEADER int encode_char_1 (Emchar ch, Lisp_Object* charset);
61 encode_char_1 (Emchar ch, Lisp_Object* charset)
63 *charset = CHAR_CHARSET (ch);
64 return XCHARSET_DIMENSION (*charset) == 1
66 : (CHAR_FIELD2 (ch) << 8) | CHAR_FIELD3 (ch);
69 #define ENCODE_CHAR(ch, charset) encode_char_1 (ch, &(charset))
75 unsigned short code_point;
78 INLINE_HEADER Charc CHAR_TO_CHARC (Emchar ch);
80 CHAR_TO_CHARC (Emchar ch)
84 cc.code_point = encode_char_1 (ch, &cc.charset);
88 #endif /* _XEMACS_CHAR_LB_H */