OSDN Git Service

3446cf79ce42d63da1a6c39a91483095bf64917e
[linuxjm/LDP_man-pages.git] / original / man7 / charsets.7
1 .\" Copyright (c) 1996 Eric S. Raymond <esr@thyrsus.com>
2 .\"                and Andries Brouwer <aeb@cwi.nl>
3 .\"
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
8 .\"
9 .\" This is combined from many sources, including notes by aeb and
10 .\" research by esr.  Portions derive from a writeup by Roman Czyborra.
11 .\"
12 .\" Last changed by David Starner <dstarner98@aasaa.ofe.org>.
13 .TH CHARSETS 7 2008-06-03 "Linux" "Linux Programmer's Manual"
14 .SH NAME
15 charsets \- programmer's view of character sets and internationalization
16 .SH DESCRIPTION
17 Linux is an international operating system.
18 Various of its utilities
19 and device drivers (including the console driver) support multilingual
20 character sets including Latin-alphabet letters with diacritical
21 marks, accents, ligatures, and entire non-Latin alphabets including
22 Greek, Cyrillic, Arabic, and Hebrew.
23 .LP
24 This manual page presents a programmer's-eye view of different
25 character-set standards and how they fit together on Linux.
26 Standards
27 discussed include ASCII, ISO 8859, KOI8-R, Unicode, ISO 2022 and
28 ISO 4873.
29 The primary emphasis is on character sets actually used as
30 locale character sets, not the myriad others that can be found in data
31 from other systems.
32 .LP
33 A complete list of charsets used in an officially supported locale in glibc
34 2.2.3 is: ISO-8859-{1,2,3,5,6,7,8,9,13,15}, CP1251, UTF-8, EUC-{KR,JP,TW},
35 KOI8-{R,U}, GB2312, GB18030, GBK, BIG5, BIG5-HKSCS and TIS-620 (in no
36 particular order.)
37 (Romanian may be switching to ISO-8859-16.)
38 .SS ASCII
39 ASCII (American Standard Code For Information Interchange) is the original
40 7-bit character set, originally designed for American English.
41 It is currently described by the ECMA-6 standard.
42 .LP
43 Various ASCII variants replacing the dollar sign with other currency
44 symbols and replacing punctuation with non-English alphabetic characters
45 to cover German, French, Spanish and others in 7 bits exist.
46 All are
47 deprecated; glibc doesn't support locales whose character sets aren't
48 true supersets of ASCII.
49 (These sets are also known as ISO-646, a close
50 relative of ASCII that permitted replacing these characters.)
51 .LP
52 As Linux was written for hardware designed in the US, it natively
53 supports ASCII.
54 .SS ISO 8859
55 ISO 8859 is a series of 15 8-bit character sets all of which have US
56 ASCII in their low (7-bit) half, invisible control characters in
57 positions 128 to 159, and 96 fixed-width graphics in positions 160-255.
58 .LP
59 Of these, the most important is ISO 8859-1 (Latin-1).
60 It is natively
61 supported in the Linux console driver, fairly well supported in X11R6,
62 and is the base character set of HTML.
63 .LP
64 Console support for the other 8859 character sets is available under
65 Linux through user-mode utilities (such as
66 .BR setfont (8))
67 .\" // some distributions still have the deprecated consolechars
68 that modify keyboard bindings and the EGA graphics
69 table and employ the "user mapping" font table in the console
70 driver.
71 .LP
72 Here are brief descriptions of each set:
73 .TP
74 8859-1 (Latin-1)
75 Latin-1 covers most Western European languages such as Albanian, Catalan,
76 Danish, Dutch, English, Faroese, Finnish, French, German, Galician,
77 Irish, Icelandic, Italian, Norwegian, Portuguese, Spanish, and
78 Swedish.
79 The lack of the ligatures Dutch ij, French oe and old-style
80 ,,German`` quotation marks is considered tolerable.
81 .TP
82 8859-2 (Latin-2)
83 Latin-2 supports most Latin-written Slavic and Central European
84 languages: Croatian, Czech, German, Hungarian, Polish, Rumanian,
85 Slovak, and Slovene.
86 .TP
87 8859-3 (Latin-3)
88 Latin-3 is popular with authors of Esperanto, Galician, and Maltese.
89 (Turkish is now written with 8859-9 instead.)
90 .TP
91 8859-4 (Latin-4)
92 Latin-4 introduced letters for Estonian, Latvian, and Lithuanian.
93 It is essentially obsolete; see 8859-10 (Latin-6) and 8859-13 (Latin-7).
94 .TP
95 8859-5
96 Cyrillic letters supporting Bulgarian, Byelorussian, Macedonian,
97 Russian, Serbian and Ukrainian.
98 Ukrainians read the letter "ghe"
99 with downstroke as "heh" and would need a ghe with upstroke to write a
100 correct ghe.
101 See the discussion of KOI8-R below.
102 .TP
103 8859-6
104 Supports Arabic.
105 The 8859-6 glyph table is a fixed font of separate
106 letter forms, but a proper display engine should combine these
107 using the proper initial, medial, and final forms.
108 .TP
109 8859-7
110 Supports Modern Greek.
111 .TP
112 8859-8
113 Supports modern Hebrew without niqud (punctuation signs).
114 Niqud and full-fledged Biblical Hebrew are outside the scope of this
115 character set; under Linux, UTF-8 is the preferred encoding for
116 these.
117 .TP
118 8859-9 (Latin-5)
119 This is a variant of Latin-1 that replaces Icelandic letters with
120 Turkish ones.
121 .TP
122 8859-10 (Latin-6)
123 Latin 6 adds the last Inuit (Greenlandic) and Sami (Lappish) letters
124 that were missing in Latin 4 to cover the entire Nordic area.
125 RFC 1345 listed a preliminary and different "latin6".
126 Skolt Sami still
127 needs a few more accents than these.
128 .TP
129 8859-11
130 This only exists as a rejected draft standard.
131 The draft standard
132 was identical to TIS-620, which is used under Linux for Thai.
133 .TP
134 8859-12
135 This set does not exist.
136 While Vietnamese has been suggested for this
137 space, it does not fit within the 96 (noncombining) characters ISO
138 8859 offers.
139 UTF-8 is the preferred character set for Vietnamese use
140 under Linux.
141 .TP
142 8859-13 (Latin-7)
143 Supports the Baltic Rim languages; in particular, it includes Latvian
144 characters not found in Latin-4.
145 .TP
146 8859-14 (Latin-8)
147 This is the Celtic character set, covering Gaelic and Welsh.
148 This charset also contains the dotted characters needed for Old Irish.
149 .TP
150 8859-15 (Latin-9)
151 This adds the Euro sign and French and Finnish letters that were missing in
152 Latin-1.
153 .TP
154 8859-16 (Latin-10)
155 This set covers many of the languages covered by 8859-2, and supports
156 Romanian more completely then that set does.
157 .SS KOI8-R
158 KOI8-R is a non-ISO character set popular in Russia.
159 The lower half
160 is US ASCII; the upper is a Cyrillic character set somewhat better
161 designed than ISO 8859-5.
162 KOI8-U is a common character set, based off
163 KOI8-R, that has better support for Ukrainian.
164 Neither of these sets
165 are ISO-2022 compatible, unlike the ISO-8859 series.
166 .LP
167 Console support for KOI8-R is available under Linux through user-mode
168 utilities that modify keyboard bindings and the EGA graphics table,
169 and employ the "user mapping" font table in the console driver.
170 .\" Thanks to Tomohiro KUBOTA for the following sections about
171 .\" national standards.
172 .SS JIS X 0208
173 JIS X 0208 is a Japanese national standard character set.
174 Though there are some more Japanese national standard character sets (like
175 JIS X 0201, JIS X 0212, and JIS X 0213), this is the most important one.
176 Characters are mapped into a 94x94 two-byte matrix,
177 whose each byte is in the range 0x21-0x7e.
178 Note that JIS X 0208 is a character set, not an encoding.
179 This means that JIS X 0208
180 itself is not used for expressing text data.
181 JIS X 0208 is used
182 as a component to construct encodings such as EUC-JP, Shift_JIS,
183 and ISO-2022-JP.
184 EUC-JP is the most important encoding for Linux
185 and includes US ASCII and JIS X 0208.
186 In EUC-JP, JIS X 0208
187 characters are expressed in two bytes, each of which is the
188 JIS X 0208 code plus 0x80.
189 .SS KS X 1001
190 KS X 1001 is a Korean national standard character set.
191 Just as
192 JIS X 0208, characters are mapped into a 94x94 two-byte matrix.
193 KS X 1001 is used like JIS X 0208, as a component
194 to construct encodings such as EUC-KR, Johab, and ISO-2022-KR.
195 EUC-KR is the most important encoding for Linux and includes
196 US ASCII and KS X 1001.
197 KS C 5601 is an older name for KS X 1001.
198 .SS GB 2312
199 GB 2312 is a mainland Chinese national standard character set used
200 to express simplified Chinese.
201 Just like JIS X 0208, characters are
202 mapped into a 94x94 two-byte matrix used to construct EUC-CN.
203 EUC-CN
204 is the most important encoding for Linux and includes US ASCII and
205 GB 2312.
206 Note that EUC-CN is often called as GB, GB 2312, or CN-GB.
207 .SS Big5
208 Big5 is a popular character set in Taiwan to express traditional
209 Chinese.
210 (Big5 is both a character set and an encoding.)
211 It is a superset of US ASCII.
212 Non-ASCII characters are expressed in two bytes.
213 Bytes 0xa1-0xfe are used as leading bytes for two-byte characters.
214 Big5 and its extension is widely used in Taiwan and Hong Kong.
215 It is not ISO 2022-compliant.
216 .SS TIS 620
217 TIS 620 is a Thai national standard character set and a superset
218 of US ASCII.
219 Like ISO 8859 series, Thai characters are mapped into
220 0xa1-0xfe.
221 TIS 620 is the only commonly used character set under
222 Linux besides UTF-8 to have combining characters.
223 .SS UNICODE
224 Unicode (ISO 10646) is a standard which aims to unambiguously represent every
225 character in every human language.
226 Unicode's structure permits 20.1 bits to encode every character.
227 Since most computers don't include 20.1-bit
228 integers, Unicode is usually encoded as 32-bit integers internally and
229 either a series of 16-bit integers (UTF-16) (needing two 16-bit integers
230 only when encoding certain rare characters) or a series of 8-bit bytes
231 (UTF-8).
232 Information on Unicode is available at <http://www.unicode.org>.
233 .LP
234 Linux represents Unicode using the 8-bit Unicode Transformation Format
235 (UTF-8).
236 UTF-8 is a variable length encoding of Unicode.
237 It uses 1
238 byte to code 7 bits, 2 bytes for 11 bits, 3 bytes for 16 bits, 4 bytes
239 for 21 bits, 5 bytes for 26 bits, 6 bytes for 31 bits.
240 .LP
241 Let 0,1,x stand for a zero, one, or arbitrary bit.
242 A byte 0xxxxxxx
243 stands for the Unicode 00000000 0xxxxxxx which codes the same symbol
244 as the ASCII 0xxxxxxx.
245 Thus, ASCII goes unchanged into UTF-8, and
246 people using only ASCII do not notice any change: not in code, and not
247 in file size.
248 .LP
249 A byte 110xxxxx is the start of a 2-byte code, and 110xxxxx 10yyyyyy
250 is assembled into 00000xxx xxyyyyyy.
251 A byte 1110xxxx is the start
252 of a 3-byte code, and 1110xxxx 10yyyyyy 10zzzzzz is assembled
253 into xxxxyyyy yyzzzzzz.
254 (When UTF-8 is used to code the 31-bit ISO 10646
255 then this progression continues up to 6-byte codes.)
256 .LP
257 For most people who use ISO-8859 character sets, this means that the
258 characters outside of ASCII are now coded with two bytes.
259 This tends
260 to expand ordinary text files by only one or two percent.
261 For Russian
262 or Greek users, this expands ordinary text files by 100%, since text in
263 those languages is mostly outside of ASCII.
264 For Japanese users this means
265 that the 16-bit codes now in common use will take three bytes.
266 While there
267 are algorithmic conversions from some character sets (especially ISO-8859-1) to
268 Unicode, general conversion requires carrying around conversion tables,
269 which can be quite large for 16-bit codes.
270 .LP
271 Note that UTF-8 is self-synchronizing: 10xxxxxx is a tail, any other
272 byte is the head of a code.
273 Note that the only way ASCII bytes occur
274 in a UTF-8 stream, is as themselves.
275 In particular, there are no
276 embedded NULs (\(aq\\0\(aq) or \(aq/\(aqs that form part of some larger code.
277 .LP
278 Since ASCII, and, in particular, NUL and \(aq/\(aq, are unchanged, the
279 kernel does not notice that UTF-8 is being used.
280 It does not care at
281 all what the bytes it is handling stand for.
282 .LP
283 Rendering of Unicode data streams is typically handled through
284 "subfont" tables which map a subset of Unicode to glyphs.
285 Internally
286 the kernel uses Unicode to describe the subfont loaded in video RAM.
287 This means that in UTF-8 mode one can use a character set with 512
288 different symbols.
289 This is not enough for Japanese, Chinese and
290 Korean, but it is enough for most other purposes.
291 .LP
292 At the current time, the console driver does not handle combining
293 characters.
294 So Thai, Sioux and any other script needing combining
295 characters can't be handled on the console.
296 .SS "ISO 2022 and ISO 4873"
297 The ISO 2022 and 4873 standards describe a font-control model
298 based on VT100 practice.
299 This model is (partially) supported
300 by the Linux kernel and by
301 .BR xterm (1).
302 It is popular in Japan and Korea.
303 .LP
304 There are 4 graphic character sets, called G0, G1, G2 and G3,
305 and one of them is the current character set for codes with
306 high bit zero (initially G0), and one of them is the current
307 character set for codes with high bit one (initially G1).
308 Each graphic character set has 94 or 96 characters, and is
309 essentially a 7-bit character set.
310 It uses codes either
311 040-0177 (041-0176) or 0240-0377 (0241-0376).
312 G0 always has size 94 and uses codes 041-0176.
313 .LP
314 Switching between character sets is done using the shift functions
315 \fB^N\fP (SO or LS1), \fB^O\fP (SI or LS0), ESC n (LS2), ESC o (LS3),
316 ESC N (SS2), ESC O (SS3), ESC ~ (LS1R), ESC } (LS2R), ESC | (LS3R).
317 The function LS\fIn\fP makes character set G\fIn\fP the current one
318 for codes with high bit zero.
319 The function LS\fIn\fPR makes character set G\fIn\fP the current one
320 for codes with high bit one.
321 The function SS\fIn\fP makes character set G\fIn\fP (\fIn\fP=2 or 3)
322 the current one for the next character only (regardless of the value
323 of its high order bit).
324 .LP
325 A 94-character set is designated as G\fIn\fP character set
326 by an escape sequence ESC ( xx (for G0), ESC ) xx (for G1),
327 ESC * xx (for G2), ESC + xx (for G3), where xx is a symbol
328 or a pair of symbols found in the ISO 2375 International
329 Register of Coded Character Sets.
330 For example, ESC ( @ selects the ISO 646 character set as G0,
331 ESC ( A selects the UK standard character set (with pound
332 instead of number sign), ESC ( B selects ASCII (with dollar
333 instead of currency sign), ESC ( M selects a character set
334 for African languages, ESC ( ! A selects the Cuban character
335 set, and so on.
336 .LP
337 A 96-character set is designated as G\fIn\fP character set
338 by an escape sequence ESC \- xx (for G1), ESC . xx (for G2)
339 or ESC / xx (for G3).
340 For example, ESC \- G selects the Hebrew alphabet as G1.
341 .LP
342 A multibyte character set is designated as G\fIn\fP character set
343 by an escape sequence ESC $ xx or ESC $ ( xx (for G0),
344 ESC $ ) xx (for G1), ESC $ * xx (for G2), ESC $ + xx (for G3).
345 For example, ESC $ ( C selects the Korean character set for G0.
346 The Japanese character set selected by ESC $ B has a more
347 recent version selected by ESC & @ ESC $ B.
348 .LP
349 ISO 4873 stipulates a narrower use of character sets, where G0
350 is fixed (always ASCII), so that G1, G2 and G3
351 can only be invoked for codes with the high order bit set.
352 In particular, \fB^N\fP and \fB^O\fP are not used anymore, ESC ( xx
353 can be used only with xx=B, and ESC ) xx, ESC * xx, ESC + xx
354 are equivalent to ESC \- xx, ESC . xx, ESC / xx, respectively.
355 .SH "SEE ALSO"
356 .BR console (4),
357 .BR console_codes (4),
358 .BR console_ioctl (4),
359 .BR ascii (7),
360 .BR iso_8859-1 (7),
361 .BR unicode (7),
362 .BR utf-8 (7)