Mercurial > emacs
annotate src/charset.h @ 18553:62e17ab4e33e
Use true coding system names instead of
aliases. Adjusted for the change of an input method name.
(decode-hz-region): Fix comments.
(encode-hz-region): Fix a coding system name.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Wed, 02 Jul 1997 12:58:30 +0000 |
parents | 33e78cc7f058 |
children | 9ea3c87ea61d |
rev | line source |
---|---|
17052 | 1 /* Header for multilingual character handler. |
18341
33e78cc7f058
Change copyright notices.
Richard M. Stallman <rms@gnu.org>
parents:
17833
diff
changeset
|
2 Copyright (C) 1995, 1997 Electrotechnical Laboratory, JAPAN. |
33e78cc7f058
Change copyright notices.
Richard M. Stallman <rms@gnu.org>
parents:
17833
diff
changeset
|
3 Licensed to the Free Software Foundation. |
17052 | 4 |
17071 | 5 This file is part of GNU Emacs. |
6 | |
7 GNU Emacs is free software; you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
9 the Free Software Foundation; either version 2, or (at your option) | |
10 any later version. | |
17052 | 11 |
17071 | 12 GNU Emacs is distributed in the hope that it will be useful, |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
17052 | 16 |
17071 | 17 You should have received a copy of the GNU General Public License |
18 along with GNU Emacs; 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. */ | |
17052 | 21 |
22 #ifndef _CHARSET_H | |
23 #define _CHARSET_H | |
24 | |
25 /*** GENERAL NOTE on CHARACTER SET (CHARSET) *** | |
26 | |
27 A character set ("charset" hereafter) is a meaningful collection | |
28 (i.e. language, culture, functionality, etc) of characters. Emacs | |
29 handles multiple charsets at once. Each charset corresponds to one | |
30 of ISO charsets (except for a special charset for composition | |
31 characters). Emacs identifies a charset by a unique identification | |
32 number, whereas ISO identifies a charset by a triplet of DIMENSION, | |
33 CHARS and FINAL-CHAR. So, hereafter, just saying "charset" means an | |
34 identification number (integer value). | |
35 | |
36 The value range of charset is 0x00, 0x80..0xFE. There are four | |
37 kinds of charset depending on DIMENSION (1 or 2) and CHARS (94 or | |
38 96). For instance, a charset of DIMENSION2_CHARS94 contains 94x94 | |
39 | |
40 | |
41 Within Emacs Lisp, a charset is treated as a symbol which has a | |
42 property `charset'. The property value is a vector containing | |
43 various information about the charset. For readability of C codes, | |
44 we use the following convention on C variable names: | |
45 charset_symbol: Emacs Lisp symbol of a charset | |
46 charset_id: Emacs Lisp integer of an identification number of a charset | |
47 charset: C integer of an identification number of a charset | |
48 | |
49 Each charset (except for ASCII) is assigned a base leading-code | |
50 (range 0x80..0x9D). In addition, a charset of greater than 0xA0 | |
51 (whose base leading-code is 0x9A..0x9D) is assigned an extended | |
52 leading-code (range 0xA0..0xFE). In this case, each base | |
53 leading-code specify the allowable range of extended leading-code as | |
54 shown in the table below. A leading-code is used to represent a | |
55 character in Emacs' buffer and string. | |
56 | |
57 We call a charset which has extended leading-code as "private | |
58 charset" because those are mainly for a charset which is not | |
59 registered by ISO. On the contrary, we call a charset which does | |
60 not have extended leading-code as "official charset". | |
61 | |
62 --------------------------------------------------------------------------- | |
63 charset dimension base leading-code extended leading-code | |
64 --------------------------------------------------------------------------- | |
65 0x00 official dim1 -- none -- -- none -- | |
66 (ASCII) | |
67 0x01..0x7F --never used-- | |
68 0x80 COMPOSITION same as charset -- none -- | |
69 0x81..0x8F official dim1 same as charset -- none -- | |
70 0x90..0x99 official dim2 same as charset -- none -- | |
71 0x9A..0x9F --never used-- | |
72 0xA0..0xDF private dim1 0x9A same as charset | |
73 of 1-column width | |
74 0xE0..0xEF private dim1 0x9B same as charset | |
75 of 2-column width | |
76 0xF0..0xF4 private dim2 0x9C same as charset | |
77 of 1-column width | |
78 0xF5..0xFE private dim2 0x9D same as charset | |
79 of 2-column width | |
80 0xFF --never used-- | |
81 --------------------------------------------------------------------------- | |
82 | |
83 In the table, "COMPOSITION" means a charset for a composite | |
84 character which is a character composed from several (up to 16) | |
85 non-composite characters (components). Although a composite | |
86 character can contain components of many charsets, a composite | |
87 character itself belongs to the charset CHARSET-COMPOSITION. See | |
88 the document "GENERAL NOTE on COMPOSITE CHARACTER" below for more | |
89 detail. | |
90 | |
91 */ | |
92 | |
93 /* Definition of special leading-codes. */ | |
94 /* Base leading-code. */ | |
95 /* Special leading-code followed by components of a composite character. */ | |
96 #define LEADING_CODE_COMPOSITION 0x80 | |
97 /* Leading-code followed by extended leading-code. */ | |
98 #define LEADING_CODE_PRIVATE_11 0x9A /* for private DIMENSION1 of 1-column */ | |
99 #define LEADING_CODE_PRIVATE_12 0x9B /* for private DIMENSION1 of 2-column */ | |
100 #define LEADING_CODE_PRIVATE_21 0x9C /* for private DIMENSION2 of 1-column */ | |
101 #define LEADING_CODE_PRIVATE_22 0x9D /* for private DIMENSION2o f 2-column */ | |
102 | |
103 /* Extended leading-code. */ | |
104 /* Start of each extended leading-codes. */ | |
105 #define LEADING_CODE_EXT_11 0xA0 /* follows LEADING_CODE_PRIVATE_11 */ | |
106 #define LEADING_CODE_EXT_12 0xE0 /* follows LEADING_CODE_PRIVATE_12 */ | |
107 #define LEADING_CODE_EXT_21 0xF0 /* follows LEADING_CODE_PRIVATE_21 */ | |
108 #define LEADING_CODE_EXT_22 0xF5 /* follows LEADING_CODE_PRIVATE_22 */ | |
109 /* Maximum value of extended leading-codes. */ | |
110 #define LEADING_CODE_EXT_MAX 0xFE | |
111 | |
112 /* Definition of minimum/maximum charset of each DIMENSION. */ | |
113 #define MIN_CHARSET_OFFICIAL_DIMENSION1 0x81 | |
114 #define MAX_CHARSET_OFFICIAL_DIMENSION1 0x8F | |
115 #define MIN_CHARSET_OFFICIAL_DIMENSION2 0x90 | |
116 #define MAX_CHARSET_OFFICIAL_DIMENSION2 0x99 | |
117 #define MIN_CHARSET_PRIVATE_DIMENSION1 LEADING_CODE_EXT_11 | |
118 #define MIN_CHARSET_PRIVATE_DIMENSION2 LEADING_CODE_EXT_21 | |
119 | |
17185
0d5a1bae9d73
(MAX_CHARSET): Definition changed to the actual
Kenichi Handa <handa@m17n.org>
parents:
17120
diff
changeset
|
120 /* Maximum value of overall charset identification number. */ |
0d5a1bae9d73
(MAX_CHARSET): Definition changed to the actual
Kenichi Handa <handa@m17n.org>
parents:
17120
diff
changeset
|
121 #define MAX_CHARSET 0xFE |
0d5a1bae9d73
(MAX_CHARSET): Definition changed to the actual
Kenichi Handa <handa@m17n.org>
parents:
17120
diff
changeset
|
122 |
17052 | 123 /* Definition of special charsets. */ |
124 #define CHARSET_ASCII 0 | |
125 #define CHARSET_COMPOSITION 0x80 | |
126 | |
127 extern int charset_ascii; /* ASCII */ | |
128 extern int charset_composition; /* for a composite character */ | |
129 extern int charset_latin_iso8859_1; /* ISO8859-1 (Latin-1) */ | |
130 extern int charset_jisx0208_1978; /* JISX0208.1978 (Japanese Kanji old set) */ | |
131 extern int charset_jisx0208; /* JISX0208.1983 (Japanese Kanji) */ | |
132 extern int charset_katakana_jisx0201; /* JISX0201.Kana (Japanese Katakana) */ | |
133 extern int charset_latin_jisx0201; /* JISX0201.Roman (Japanese Roman) */ | |
134 extern int charset_big5_1; /* Big5 Level 1 (Chinese Traditional) */ | |
135 extern int charset_big5_2; /* Big5 Level 2 (Chinese Traditional) */ | |
136 | |
137 /* Check if STR points the head of multi-byte form, i.e. *STR is an | |
138 ASCII character or a base leading-code. */ | |
139 #define CHAR_HEAD_P(str) ((unsigned char) *(str) < 0xA0) | |
140 | |
141 /*** GENERAL NOTE on CHARACTER REPRESENTATION *** | |
142 | |
143 At first, the term "character" or "char" is used for a multilingual | |
144 character (of course, including ASCII character), not for a byte in | |
145 computer memory. We use the term "code" or "byte" for the latter | |
146 case. | |
147 | |
148 A character is identified by charset and one or two POSITION-CODEs. | |
149 POSITION-CODE is the position of the character in the charset. A | |
150 character of DIMENSION1 charset has one POSITION-CODE: POSITION-CODE-1. | |
151 A character of DIMENSION2 charset has two POSITION-CODE: | |
152 POSITION-CODE-1 and POSITION-CODE-2. The code range of | |
153 POSITION-CODE is 0x20..0x7F. | |
154 | |
155 Emacs has two kinds of representation of a character: multi-byte | |
156 form (for buffer and string) and single-word form (for character | |
157 object in Emacs Lisp). The latter is called "character code" here | |
158 after. Both representation encode the information of charset and | |
159 POSITION-CODE but in a different way (for instance, MSB of | |
160 POSITION-CODE is set in multi-byte form). | |
161 | |
162 For details of multi-byte form, see the section "2. Emacs internal | |
163 format handlers" of `coding.c'. | |
164 | |
165 Emacs uses 19 bits for a character code. The bits are divided into | |
166 3 fields: FIELD1(5bits):FIELD2(7bits):FIELD3(7bits). | |
167 | |
168 A character code of DIMENSION1 character uses FIELD2 to hold charset | |
169 and FIELD3 to hold POSITION-CODE-1. A character code of DIMENSION2 | |
170 character uses FIELD1 to hold charset, FIELD2 and FIELD3 to hold | |
171 POSITION-CODE-1 and POSITION-CODE-2 respectively. | |
172 | |
173 More precisely... | |
174 | |
175 FIELD2 of DIMENSION1 character (except for ASCII) is "charset - 0x70". | |
176 This is to make all character codes except for ASCII greater than | |
177 256 (ASCII's FIELD2 is 0). So, the range of FIELD2 of DIMENSION1 | |
178 character is 0 or 0x11..0x7F. | |
179 | |
180 FIELD1 of DIMENSION2 character is "charset - 0x8F" for official | |
181 charset and "charset - 0xE0" for private charset. So, the range of | |
182 FIELD1 of DIMENSION2 character is 0x01..0x1E. | |
183 | |
184 ----------------------------------------------------------------------- | |
185 charset FIELD1 (5-bit) FIELD2 (7-bit) FIELD3 (7-bit) | |
186 ----------------------------------------------------------------------- | |
187 ASCII 0 0 POSITION-CODE-1 | |
188 DIMENSION1 0 charset - 0x70 POSITION-CODE-1 | |
189 DIMENSION2(o) charset - 0x8F POSITION-CODE-1 POSITION-CODE-2 | |
190 DIMENSION2(p) charset - 0xE0 POSITION-CODE-1 POSITION-CODE-2 | |
191 ----------------------------------------------------------------------- | |
192 "(o)": official, "(p)": private | |
193 ----------------------------------------------------------------------- | |
194 | |
195 */ | |
196 | |
197 /*** GENERAL NOTE on COMPOSITE CHARACTER *** | |
198 | |
199 A composite character is a character composed from several (up to | |
200 16) non-composite characters (components). Although each components | |
201 can belong to any charset, a composite character itself belongs to | |
202 the charset `charset-composition' and is assigned a special | |
203 leading-code `LEADING_CODE_COMPOSITION' for multi-byte form. See | |
204 the document "2. Emacs internal format handlers" in `coding.c' for | |
205 more detail about multi-byte form. | |
206 | |
207 A character code of composite character has special format. In the | |
208 above document, FIELD1 of a composite character is 0x1F. Each | |
209 composite character is assigned a sequential number CMPCHAR-ID. | |
210 FIELD2 and FIELD3 are combined to make 14bits field for holding | |
211 CMPCHAR-ID, which means that Emacs can handle at most 2^14 (= 16384) | |
212 composite characters at once. | |
213 | |
214 ----------------------------------------------------------------------- | |
215 charset FIELD1 (5-bit) FIELD2&3 (14-bit) | |
216 ----------------------------------------------------------------------- | |
217 CHARSET-COMPOSITION 0x1F CMPCHAR-ID | |
218 ----------------------------------------------------------------------- | |
219 | |
220 Emacs assigns CMPCHAR-ID to a composite character only when it | |
221 requires the character code of the composite character (e.g. while | |
222 displaying the composite character). | |
223 | |
224 */ | |
225 | |
226 /* Masks of each field of character code. */ | |
227 #define CHAR_FIELD1_MASK (0x1F << 14) | |
228 #define CHAR_FIELD2_MASK (0x7F << 7) | |
229 #define CHAR_FIELD3_MASK 0x7F | |
230 | |
231 /* Macros to access each field of character C. */ | |
232 #define CHAR_FIELD1(c) (((c) & CHAR_FIELD1_MASK) >> 14) | |
233 #define CHAR_FIELD2(c) (((c) & CHAR_FIELD2_MASK) >> 7) | |
234 #define CHAR_FIELD3(c) ((c) & CHAR_FIELD3_MASK) | |
235 | |
236 /* Minimum character code of character of each DIMENSION. */ | |
237 #define MIN_CHAR_OFFICIAL_DIMENSION1 \ | |
238 ((MIN_CHARSET_OFFICIAL_DIMENSION1 - 0x70) << 7) | |
239 #define MIN_CHAR_PRIVATE_DIMENSION1 \ | |
240 ((MIN_CHARSET_PRIVATE_DIMENSION1 - 0x70) << 7) | |
241 #define MIN_CHAR_OFFICIAL_DIMENSION2 \ | |
242 ((MIN_CHARSET_OFFICIAL_DIMENSION2 - 0x8F) << 14) | |
243 #define MIN_CHAR_PRIVATE_DIMENSION2 \ | |
244 ((MIN_CHARSET_PRIVATE_DIMENSION2 - 0xE0) << 14) | |
245 #define MIN_CHAR_COMPOSITION \ | |
246 (0x1F << 14) | |
247 | |
248 /* 1 if C is an ASCII character, else 0. */ | |
249 #define SINGLE_BYTE_CHAR_P(c) ((c) < 0x100) | |
250 /* 1 if C is an composite character, else 0. */ | |
251 #define COMPOSITE_CHAR_P(c) ((c) >= MIN_CHAR_COMPOSITION) | |
252 | |
253 /* A char-table containing information of each character set. | |
254 | |
255 Unlike ordinary char-tables, this doesn't contain any nested table. | |
256 Only the top level elements are used. Each element is a vector of | |
257 the following information: | |
258 CHARSET-ID, BYTES, DIMENSION, CHARS, WIDTH, DIRECTION, | |
259 LEADING-CODE-BASE, LEADING-CODE-EXT, | |
260 ISO-FINAL-CHAR, ISO-GRAPHIC-PLANE, | |
261 REVERSE-CHARSET, SHORT-NAME, LONG-NAME, DESCRIPTION, | |
262 PLIST. | |
263 | |
264 CHARSET-ID (integer) is the identification number of the charset. | |
265 | |
266 BYTE (integer) is the length of multi-byte form of a character in | |
267 the charset: one of 1, 2, 3, and 4. | |
268 | |
269 DIMENSION (integer) is the number of bytes to represent a character: 1 or 2. | |
270 | |
271 CHARS (integer) is the number of characters in a dimension: 94 or 96. | |
272 | |
273 WIDTH (integer) is the number of columns a character in the charset | |
274 occupies on the screen: one of 0, 1, and 2. | |
275 | |
276 DIRECTION (integer) is the rendering direction of characters in the | |
277 charset when rendering. If 0, render from right to left, else | |
278 render from left to right. | |
279 | |
280 LEADING-CODE-BASE (integer) is the base leading-code for the | |
281 charset. | |
282 | |
283 LEADING-CODE-EXT (integer) is the extended leading-code for the | |
284 charset. All charsets of less than 0xA0 has the value 0. | |
285 | |
286 ISO-FINAL-CHAR (character) is the final character of the | |
287 corresponding ISO 2022 charset. | |
288 | |
289 ISO-GRAPHIC-PLANE (integer) is the graphic plane to be invoked | |
290 while encoding to variants of ISO 2022 coding system, one of the | |
291 following: 0/graphic-plane-left(GL), 1/graphic-plane-right(GR). | |
292 | |
293 REVERSE-CHARSET (integer) is the charset which differs only in | |
294 LEFT-TO-RIGHT value from the charset. If there's no such a | |
295 charset, the value is -1. | |
296 | |
297 SHORT-NAME (string) is the short name to refer to the charset. | |
298 | |
299 LONG-NAME (string) is the long name to refer to the charset. | |
300 | |
301 DESCRIPTION (string) is the description string of the charset. | |
302 | |
303 PLIST (property list) may contain any type of information a user | |
304 want to put and get by functions `put-charset-property' and | |
305 `get-charset-property' respectively. */ | |
306 extern Lisp_Object Vcharset_table; | |
307 | |
308 /* Macros to access various information of CHARSET in Vcharset_table. | |
309 We provide these macros for efficiency. No range check of CHARSET. */ | |
310 | |
311 /* Return entry of CHARSET (lisp integer) in Vcharset_table. */ | |
17321
9f837bea89e3
(CHARSET_TABLE_ENTRY): Handle ASCII charset correctly.
Kenichi Handa <handa@m17n.org>
parents:
17185
diff
changeset
|
312 #define CHARSET_TABLE_ENTRY(charset) \ |
9f837bea89e3
(CHARSET_TABLE_ENTRY): Handle ASCII charset correctly.
Kenichi Handa <handa@m17n.org>
parents:
17185
diff
changeset
|
313 XCHAR_TABLE (Vcharset_table)->contents[((charset) == CHARSET_ASCII \ |
9f837bea89e3
(CHARSET_TABLE_ENTRY): Handle ASCII charset correctly.
Kenichi Handa <handa@m17n.org>
parents:
17185
diff
changeset
|
314 ? 0 : (charset) + 128)] |
17052 | 315 |
316 /* Return information INFO-IDX of CHARSET. */ | |
317 #define CHARSET_TABLE_INFO(charset, info_idx) \ | |
318 XVECTOR (CHARSET_TABLE_ENTRY (charset))->contents[info_idx] | |
319 | |
320 #define CHARSET_ID_IDX (0) | |
321 #define CHARSET_BYTES_IDX (1) | |
322 #define CHARSET_DIMENSION_IDX (2) | |
323 #define CHARSET_CHARS_IDX (3) | |
324 #define CHARSET_WIDTH_IDX (4) | |
325 #define CHARSET_DIRECTION_IDX (5) | |
326 #define CHARSET_LEADING_CODE_BASE_IDX (6) | |
327 #define CHARSET_LEADING_CODE_EXT_IDX (7) | |
328 #define CHARSET_ISO_FINAL_CHAR_IDX (8) | |
329 #define CHARSET_ISO_GRAPHIC_PLANE_IDX (9) | |
330 #define CHARSET_REVERSE_CHARSET_IDX (10) | |
331 #define CHARSET_SHORT_NAME_IDX (11) | |
332 #define CHARSET_LONG_NAME_IDX (12) | |
333 #define CHARSET_DESCRIPTION_IDX (13) | |
334 #define CHARSET_PLIST_IDX (14) | |
335 /* Size of a vector of each entry of Vcharset_table. */ | |
336 #define CHARSET_MAX_IDX (15) | |
337 | |
338 /* And several more macros to be used frequently. */ | |
339 #define CHARSET_BYTES(charset) \ | |
340 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_BYTES_IDX)) | |
341 #define CHARSET_DIMENSION(charset) \ | |
342 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_DIMENSION_IDX)) | |
343 #define CHARSET_CHARS(charset) \ | |
344 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_CHARS_IDX)) | |
345 #define CHARSET_WIDTH(charset) \ | |
346 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_WIDTH_IDX)) | |
347 #define CHARSET_DIRECTION(charset) \ | |
348 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_DIRECTION_IDX)) | |
349 #define CHARSET_LEADING_CODE_BASE(charset) \ | |
350 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_LEADING_CODE_BASE_IDX)) | |
351 #define CHARSET_LEADING_CODE_EXT(charset) \ | |
352 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_LEADING_CODE_EXT_IDX)) | |
353 #define CHARSET_ISO_FINAL_CHAR(charset) \ | |
354 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_ISO_FINAL_CHAR_IDX)) | |
355 #define CHARSET_ISO_GRAPHIC_PLANE(charset) \ | |
356 XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_ISO_GRAPHIC_PLANE_IDX)) | |
357 #define CHARSET_REVERSE_CHARSET(charset) \ | |
358 XINT (CHARSET_TABLE_INFO (charset, CHARSET_REVERSE_CHARSET_IDX)) | |
359 | |
360 /* Macros to specify direction of a charset. */ | |
361 #define CHARSET_DIRECTION_LEFT_TO_RIGHT 0 | |
362 #define CHARSET_DIRECTION_RIGHT_TO_LEFT 1 | |
363 | |
364 /* A vector of charset symbol indexed by charset-id. This is used | |
365 only for returning charset symbol from C functions. */ | |
366 extern Lisp_Object Vcharset_symbol_table; | |
367 | |
368 /* Return symbol of CHARSET. */ | |
369 #define CHARSET_SYMBOL(charset) \ | |
370 XVECTOR (Vcharset_symbol_table)->contents[charset] | |
371 | |
372 /* 1 if CHARSET is valid, else 0. */ | |
373 #define CHARSET_VALID_P(charset) \ | |
374 ((charset) == 0 \ | |
375 || ((charset) >= 0x80 && (charset) <= MAX_CHARSET_OFFICIAL_DIMENSION2) \ | |
17185
0d5a1bae9d73
(MAX_CHARSET): Definition changed to the actual
Kenichi Handa <handa@m17n.org>
parents:
17120
diff
changeset
|
376 || ((charset) >= MIN_CHARSET_PRIVATE_DIMENSION1 && (charset) <= MAX_CHARSET)) |
17052 | 377 |
378 /* 1 if CHARSET is already defined, else 0. */ | |
379 #define CHARSET_DEFINED_P(charset) \ | |
17185
0d5a1bae9d73
(MAX_CHARSET): Definition changed to the actual
Kenichi Handa <handa@m17n.org>
parents:
17120
diff
changeset
|
380 (((charset) >= 0) && ((charset) <= MAX_CHARSET) \ |
17052 | 381 && !NILP (CHARSET_TABLE_ENTRY (charset))) |
382 | |
383 /* Since the information CHARSET-BYTES and CHARSET-WIDTH of | |
384 Vcharset_table can be retrieved only from the first byte of | |
385 multi-byte form (an ASCII code or a base leading-code), we provide | |
386 here tables to be used by macros BYTES_BY_CHAR_HEAD and | |
387 WIDTH_BY_CHAR_HEAD for faster information retrieval. */ | |
388 extern int bytes_by_char_head[256]; | |
389 extern int width_by_char_head[256]; | |
390 | |
391 #define BYTES_BY_CHAR_HEAD(char_head) bytes_by_char_head[char_head] | |
392 #define WIDTH_BY_CHAR_HEAD(char_head) width_by_char_head[char_head] | |
393 | |
394 /* Charset of the character C. */ | |
395 #define CHAR_CHARSET(c) \ | |
396 (SINGLE_BYTE_CHAR_P (c) \ | |
397 ? CHARSET_ASCII \ | |
398 : ((c) < MIN_CHAR_OFFICIAL_DIMENSION2 \ | |
399 ? CHAR_FIELD2 (c) + 0x70 \ | |
400 : ((c) < MIN_CHAR_PRIVATE_DIMENSION2 \ | |
401 ? CHAR_FIELD1 (c) + 0x8F \ | |
402 : ((c) < MIN_CHAR_COMPOSITION \ | |
403 ? CHAR_FIELD1 (c) + 0xE0 \ | |
404 : CHARSET_COMPOSITION)))) | |
405 | |
406 /* Return charset at the place pointed by P. */ | |
407 #define CHARSET_AT(p) \ | |
408 (*(p) < 0x80 \ | |
409 ? CHARSET_ASCII \ | |
410 : (*(p) == LEADING_CODE_COMPOSITION \ | |
411 ? CHARSET_COMPOSITION \ | |
412 : (*(p) < LEADING_CODE_PRIVATE_11 \ | |
413 ? (int)*(p) \ | |
414 : (*(p) <= LEADING_CODE_PRIVATE_22 \ | |
415 ? (int)*((p) + 1) \ | |
416 : -1)))) | |
417 | |
418 /* Same as `CHARSET_AT ()' but perhaps runs faster because of an | |
419 additional argument C which is the code (byte) at P. */ | |
420 #define FIRST_CHARSET_AT(p, c) \ | |
421 ((c) < 0x80 \ | |
422 ? CHARSET_ASCII \ | |
423 : ((c) == LEADING_CODE_COMPOSITION \ | |
424 ? CHARSET_COMPOSITION \ | |
425 : ((c) < LEADING_CODE_PRIVATE_11 \ | |
426 ? (int)(c) \ | |
427 : ((c) <= LEADING_CODE_PRIVATE_22 \ | |
428 ? (int)*((p) + 1) \ | |
429 : -1)))) | |
430 | |
431 /* Check if two characters C1 and C2 belong to the same charset. | |
432 Always return 0 for composite characters. */ | |
433 #define SAME_CHARSET_P(c1, c2) \ | |
434 (c1 < MIN_CHAR_COMPOSITION \ | |
435 && (SINGLE_BYTE_CHAR_P (c1) \ | |
436 ? SINGLE_BYTE_CHAR_P (c2) \ | |
437 : (c1 < MIN_CHAR_OFFICIAL_DIMENSION2 \ | |
438 ? (c1 & CHAR_FIELD2_MASK) == (c2 & CHAR_FIELD2_MASK) \ | |
439 : (c1 & CHAR_FIELD1_MASK) == (c2 & CHAR_FIELD1_MASK)))) | |
440 | |
441 /* Return a non-ASCII character of which charset is CHARSET and | |
442 position-codes are C1 and C2. DIMENSION1 character ignores C2. */ | |
443 #define MAKE_NON_ASCII_CHAR(charset, c1, c2) \ | |
444 ((charset) == CHARSET_COMPOSITION \ | |
445 ? MAKE_COMPOSITE_CHAR (((c1) << 7) + (c2)) \ | |
446 : (CHARSET_DIMENSION (charset) == 1 \ | |
447 ? (((charset) - 0x70) << 7) | (c1) \ | |
448 : ((charset) < MIN_CHARSET_PRIVATE_DIMENSION2 \ | |
449 ? (((charset) - 0x8F) << 14) | ((c1) << 7) | (c2) \ | |
450 : (((charset) - 0xE0) << 14) | ((c1) << 7) | (c2)))) | |
451 | |
452 /* Return a composite character of which CMPCHAR-ID is ID. */ | |
453 #define MAKE_COMPOSITE_CHAR(id) (MIN_CHAR_COMPOSITION + (id)) | |
454 | |
455 /* Return CMPCHAR-ID of a composite character C. */ | |
456 #define COMPOSITE_CHAR_ID(c) ((c) - MIN_CHAR_COMPOSITION) | |
457 | |
458 /* Return a character of which charset is CHARSET and position-codes | |
459 are C1 and C2. DIMENSION1 character ignores C2. */ | |
460 #define MAKE_CHAR(charset, c1, c2) \ | |
461 ((charset) == CHARSET_ASCII \ | |
462 ? (c1) \ | |
463 : MAKE_NON_ASCII_CHAR ((charset), (c1) & 0x7F, (c2) & 0x7F)) | |
464 | |
17833
59aa4a0772f6
(VALID_CHAR_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
17726
diff
changeset
|
465 /* 1 if C is in the range of possible character code Emacs can have. */ |
59aa4a0772f6
(VALID_CHAR_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
17726
diff
changeset
|
466 #define VALID_CHAR_P(c) \ |
59aa4a0772f6
(VALID_CHAR_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
17726
diff
changeset
|
467 ((c) >= 0 \ |
59aa4a0772f6
(VALID_CHAR_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
17726
diff
changeset
|
468 && (SINGLE_BYTE_CHAR_P (c) \ |
59aa4a0772f6
(VALID_CHAR_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
17726
diff
changeset
|
469 || ((c) < MIN_CHAR_COMPOSITION \ |
59aa4a0772f6
(VALID_CHAR_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
17726
diff
changeset
|
470 ? ((c) & CHAR_FIELD1_MASK \ |
59aa4a0772f6
(VALID_CHAR_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
17726
diff
changeset
|
471 ? (CHAR_FIELD2 (c) >= 32 && CHAR_FIELD3 (c) >= 32) \ |
59aa4a0772f6
(VALID_CHAR_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
17726
diff
changeset
|
472 : (CHAR_FIELD2 (c) >= 16 && CHAR_FIELD3 (c) >= 32)) \ |
59aa4a0772f6
(VALID_CHAR_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
17726
diff
changeset
|
473 : (c) < MIN_CHAR_COMPOSITION + n_cmpchars))) |
59aa4a0772f6
(VALID_CHAR_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
17726
diff
changeset
|
474 |
17052 | 475 /* The charset of non-ASCII character C is set to CHARSET, and the |
476 position-codes of C are set to C1 and C2. C2 of DIMENSION1 character | |
17321
9f837bea89e3
(CHARSET_TABLE_ENTRY): Handle ASCII charset correctly.
Kenichi Handa <handa@m17n.org>
parents:
17185
diff
changeset
|
477 is -1. */ |
17052 | 478 #define SPLIT_NON_ASCII_CHAR(c, charset, c1, c2) \ |
479 ((c) < MIN_CHAR_OFFICIAL_DIMENSION2 \ | |
480 ? (charset = CHAR_FIELD2 (c) + 0x70, \ | |
481 c1 = CHAR_FIELD3 (c), \ | |
17321
9f837bea89e3
(CHARSET_TABLE_ENTRY): Handle ASCII charset correctly.
Kenichi Handa <handa@m17n.org>
parents:
17185
diff
changeset
|
482 c2 = -1) \ |
17052 | 483 : (charset = ((c) < MIN_CHAR_COMPOSITION \ |
484 ? (CHAR_FIELD1 (c) \ | |
485 + ((c) < MIN_CHAR_PRIVATE_DIMENSION2 ? 0x8F : 0xE0)) \ | |
486 : CHARSET_COMPOSITION), \ | |
487 c1 = CHAR_FIELD2 (c), \ | |
488 c2 = CHAR_FIELD3 (c))) | |
489 | |
490 /* The charset of character C is set to CHARSET, and the | |
491 position-codes of C are set to C1 and C2. C2 of DIMENSION1 character | |
17321
9f837bea89e3
(CHARSET_TABLE_ENTRY): Handle ASCII charset correctly.
Kenichi Handa <handa@m17n.org>
parents:
17185
diff
changeset
|
492 is -1. */ |
17052 | 493 #define SPLIT_CHAR(c, charset, c1, c2) \ |
494 (SINGLE_BYTE_CHAR_P (c) \ | |
17321
9f837bea89e3
(CHARSET_TABLE_ENTRY): Handle ASCII charset correctly.
Kenichi Handa <handa@m17n.org>
parents:
17185
diff
changeset
|
495 ? charset = CHARSET_ASCII, c1 = (c), c2 = -1 \ |
17052 | 496 : SPLIT_NON_ASCII_CHAR (c, charset, c1, c2)) |
497 | |
498 /* The charset of the character at STR is set to CHARSET, and the | |
17321
9f837bea89e3
(CHARSET_TABLE_ENTRY): Handle ASCII charset correctly.
Kenichi Handa <handa@m17n.org>
parents:
17185
diff
changeset
|
499 position-codes are set to C1 and C2. C2 of DIMENSION1 character is -1. |
17052 | 500 If the character is a composite character, the upper 7-bit and |
501 lower 7-bit of CMPCHAR-ID are set in C1 and C2 respectively. No | |
502 range checking. */ | |
503 #define SPLIT_STRING(str, len, charset, c1, c2) \ | |
504 ((BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) < 2 \ | |
505 || BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) > len \ | |
506 || split_non_ascii_string (str, len, &charset, &c1, &c2, 0) < 0) \ | |
507 ? c1 = *(str), charset = CHARSET_ASCII \ | |
508 : charset) | |
509 | |
510 /* Mapping table from ISO2022's charset (specified by DIMENSION, | |
511 CHARS, and FINAL_CHAR) to Emacs' charset. Should be accessed by | |
512 macro ISO_CHARSET_TABLE (DIMENSION, CHARS, FINAL_CHAR). */ | |
513 extern int iso_charset_table[2][2][128]; | |
514 | |
515 #define ISO_CHARSET_TABLE(dimension, chars, final_char) \ | |
516 iso_charset_table[XINT (dimension) - 1][XINT (chars) > 94][XINT (final_char)] | |
517 | |
518 #define BASE_LEADING_CODE_P(c) (BYTES_BY_CHAR_HEAD ((unsigned char) (c)) > 1) | |
519 | |
520 /* The following two macros CHAR_STRING and STRING_CHAR are the main | |
521 entry points to convert between Emacs two types of character | |
522 representations: multi-byte form and single-word form (character | |
523 code). */ | |
524 | |
525 /* Set STR a pointer to the multi-byte form of the character C. If C | |
526 is not a composite character, the multi-byte form is set in WORKBUF | |
527 and STR points WORKBUF. The caller should allocate at least 4-byte | |
528 area at WORKBUF in advance. Returns the length of the multi-byte | |
17833
59aa4a0772f6
(VALID_CHAR_P): New macro.
Kenichi Handa <handa@m17n.org>
parents:
17726
diff
changeset
|
529 form. If C is an invalid character code, signal an error. */ |
17052 | 530 |
531 #define CHAR_STRING(c, workbuf, str) \ | |
532 (SINGLE_BYTE_CHAR_P (c) \ | |
533 ? *(str = workbuf) = (unsigned char)(c), 1 \ | |
534 : non_ascii_char_to_string (c, workbuf, &str)) | |
535 | |
536 /* Return a character code of the character of which multi-byte form | |
537 is at STR and the length is LEN. If STR doesn't contain valid | |
538 multi-byte form, only the first byte in STR is returned. */ | |
539 | |
540 #define STRING_CHAR(str, len) \ | |
541 ((BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) == 1 \ | |
542 || BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) > (len)) \ | |
543 ? (unsigned char) *(str) \ | |
544 : string_to_non_ascii_char (str, len, 0)) | |
545 | |
546 /* This is like STRING_CHAR but the third arg ACTUAL_LEN is set to | |
547 the length of the multi-byte form. Just to know the length, use | |
548 MULTIBYTE_FORM_LENGTH. */ | |
549 | |
550 #define STRING_CHAR_AND_LENGTH(str, len, actual_len) \ | |
551 ((BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) == 1 \ | |
552 || BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) > (len)) \ | |
553 ? (actual_len = 1), (unsigned char) *(str) \ | |
554 : string_to_non_ascii_char (str, len, &actual_len)) | |
555 | |
556 /* Return the length of the multi-byte form at string STR of length LEN. */ | |
557 | |
558 #define MULTIBYTE_FORM_LENGTH(str, len) \ | |
559 ((BYTES_BY_CHAR_HEAD (*(unsigned char *)(str)) == 1 \ | |
560 || BYTES_BY_CHAR_HEAD (*(unsigned char *)(str)) > (len)) \ | |
561 ? 1 \ | |
562 : multibyte_form_length (str, len)) | |
563 | |
564 /* Set C a (possibly multibyte) character at P. P points into a | |
565 string which is the virtual concatenation of STR1 (which ends at | |
566 END1) or STR2 (which ends at END2). */ | |
567 | |
568 #define GET_CHAR_AFTER_2(c, p, str1, end1, str2, end2) \ | |
569 do { \ | |
570 const char *dtemp = (p) == (end1) ? (str2) : (p); \ | |
571 const char *dlimit = ((p) >= (str1) && (p) < (end1)) ? (end1) : (end2); \ | |
572 c = STRING_CHAR (dtemp, dlimit - dtemp); \ | |
573 } while (0) | |
574 | |
575 /* Set C a (possibly multibyte) character before P. P points into a | |
576 string which is the virtual concatenation of STR1 (which ends at | |
577 END1) or STR2 (which ends at END2). */ | |
578 | |
579 #define GET_CHAR_BEFORE_2(c, p, str1, end1, str2, end2) \ | |
580 do { \ | |
581 const char *dtemp = (p); \ | |
582 const char *dlimit = ((p) > (str2) && (p) <= (end2)) ? (str2) : (str1); \ | |
583 while (dtemp-- > dlimit && (unsigned char) *dtemp >= 0xA0); \ | |
584 c = STRING_CHAR (dtemp, p - dtemp); \ | |
585 } while (0) | |
586 | |
587 #ifdef emacs | |
588 | |
589 /* Increase the buffer point POS of the current buffer to the next | |
590 character boundary. This macro relies on the fact that *GPT_ADDR | |
591 and *Z_ADDR are always accessible and the values are '\0'. No | |
592 range checking of POS. */ | |
17120
c9c1bc92b8f8
(INC_POS, DEC_POS): Don't increase or decrease too
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
593 #define INC_POS(pos) \ |
c9c1bc92b8f8
(INC_POS, DEC_POS): Don't increase or decrease too
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
594 do { \ |
c9c1bc92b8f8
(INC_POS, DEC_POS): Don't increase or decrease too
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
595 unsigned char *p = POS_ADDR (pos); \ |
c9c1bc92b8f8
(INC_POS, DEC_POS): Don't increase or decrease too
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
596 pos++; \ |
c9c1bc92b8f8
(INC_POS, DEC_POS): Don't increase or decrease too
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
597 if (*p++ >= 0x80) \ |
c9c1bc92b8f8
(INC_POS, DEC_POS): Don't increase or decrease too
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
598 while (!CHAR_HEAD_P (p)) p++, pos++; \ |
17052 | 599 } while (0) |
600 | |
601 /* Decrease the buffer point POS of the current buffer to the previous | |
602 character boundary. No range checking of POS. */ | |
603 #define DEC_POS(pos) \ | |
604 do { \ | |
605 unsigned char *p, *p_min; \ | |
17120
c9c1bc92b8f8
(INC_POS, DEC_POS): Don't increase or decrease too
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
606 int pos_saved = --pos; \ |
c9c1bc92b8f8
(INC_POS, DEC_POS): Don't increase or decrease too
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
607 if (pos < GPT) \ |
17052 | 608 p = BEG_ADDR + pos - 1, p_min = BEG_ADDR; \ |
609 else \ | |
610 p = BEG_ADDR + GAP_SIZE + pos - 1, p_min = GAP_END_ADDR; \ | |
611 while (p > p_min && !CHAR_HEAD_P (p)) p--, pos--; \ | |
17120
c9c1bc92b8f8
(INC_POS, DEC_POS): Don't increase or decrease too
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
612 if (*p < 0x80 && pos != pos_saved) pos = pos_saved; \ |
17052 | 613 } while (0) |
614 | |
615 #endif /* emacs */ | |
616 | |
617 /* Maximum counts of components in one composite character. */ | |
618 #define MAX_COMPONENT_COUNT 16 | |
619 | |
620 /* Structure to hold information of a composite character. */ | |
621 struct cmpchar_info { | |
622 /* Byte length of the composite character. */ | |
623 int len; | |
624 | |
625 /* Multi-byte form of the composite character. */ | |
626 unsigned char *data; | |
627 | |
628 /* Length of glyph codes. */ | |
629 int glyph_len; | |
630 | |
631 /* Width of the overall glyph of the composite character. */ | |
632 int width; | |
633 | |
634 /* Pointer to an array of glyph codes of the composite character. | |
635 This actually contains only character code, no face. */ | |
636 GLYPH *glyph; | |
637 | |
638 /* Pointer to an array of composition rules. The value has the form: | |
639 (0xA0 + ((GLOBAL-REF-POINT << 2) | NEW-REF-POINT)) | |
640 where each XXX-REF-POINT is 0..8. */ | |
641 unsigned char *cmp_rule; | |
642 | |
643 /* Pointer to an array of x-axis offset of left edge of glyphs | |
644 relative to the left of of glyph[0] except for the first element | |
645 which is the absolute offset from the left edge of overall glyph. | |
646 The actual pixel offset should be calculated by multiplying each | |
647 frame's one column width by this value: | |
648 (i.e. FONT_WIDTH (f->output_data.x->font) * col_offset[N]). */ | |
649 float *col_offset; | |
650 | |
651 /* Work slot used by `dumpglyphs' (xterm.c). */ | |
652 int face_work; | |
653 }; | |
654 | |
655 /* Table of pointers to the structure `cmpchar_info' indexed by | |
656 CMPCHAR-ID. */ | |
657 extern struct cmpchar_info **cmpchar_table; | |
658 /* Number of the current composite characters. */ | |
659 extern int n_cmpchars; | |
660 | |
661 /* This is the maximum length of multi-byte form. */ | |
662 #define MAX_LENGTH_OF_MULTI_BYTE_FORM (MAX_COMPONENT_COUNT * 6) | |
663 | |
17185
0d5a1bae9d73
(MAX_CHARSET): Definition changed to the actual
Kenichi Handa <handa@m17n.org>
parents:
17120
diff
changeset
|
664 /* Maximum character code currently used. */ |
0d5a1bae9d73
(MAX_CHARSET): Definition changed to the actual
Kenichi Handa <handa@m17n.org>
parents:
17120
diff
changeset
|
665 #define MAX_CHAR (MIN_CHAR_COMPOSITION + n_cmpchars) |
0d5a1bae9d73
(MAX_CHARSET): Definition changed to the actual
Kenichi Handa <handa@m17n.org>
parents:
17120
diff
changeset
|
666 |
17726 | 667 extern int unify_char (); |
668 | |
17052 | 669 #endif /* _CHARSET_H */ |