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