Rewrite Eshell tests using ERT
[bpt/emacs.git] / lisp / international / fontset.el
CommitLineData
60370d40 1;;; fontset.el --- commands for handling fontset
4ed46869 2
ab422c4d 3;; Copyright (C) 1997-2013 Free Software Foundation, Inc.
7976eda0 4;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5df4f04c 5;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
2fd125a3
KH
6;; National Institute of Advanced Industrial Science and Technology (AIST)
7;; Registration Number H14PRO021
6118a2b8 8;; Copyright (C) 2003, 2006
8f924df7
KH
9;; National Institute of Advanced Industrial Science and Technology (AIST)
10;; Registration Number H13PRO009
4ed46869 11
8135c753 12;; Keywords: mule, i18n, fontset
4ed46869
KH
13
14;; This file is part of GNU Emacs.
15
4936186e 16;; GNU Emacs is free software: you can redistribute it and/or modify
4ed46869 17;; it under the terms of the GNU General Public License as published by
4936186e
GM
18;; the Free Software Foundation, either version 3 of the License, or
19;; (at your option) any later version.
4ed46869
KH
20
21;; GNU Emacs is distributed in the hope that it will be useful,
22;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24;; GNU General Public License for more details.
25
26;; You should have received a copy of the GNU General Public License
4936186e 27;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
4ed46869 28
60370d40
PJ
29;;; Commentary:
30
4ed46869
KH
31;;; Code:
32
37a94e2f
KH
33;; Setup font-encoding-alist for all known encodings.
34
35(setq font-encoding-alist
e8e4d5c8
SS
36 (mapcar (lambda (arg)
37 (cons (purecopy (car arg)) (cdr arg)))
37a94e2f
KH
38 '(("iso8859-1$" . iso-8859-1)
39 ("iso8859-2$" . iso-8859-2)
40 ("iso8859-3$" . iso-8859-3)
41 ("iso8859-4$" . iso-8859-4)
42 ("iso8859-5$" . iso-8859-5)
43 ("iso8859-6$" . iso-8859-6)
44 ("iso8859-7$" . iso-8859-7)
45 ("iso8859-8$" . iso-8859-8)
46 ("iso8859-9$" . iso-8859-9)
47 ("iso8859-10$" . iso-8859-10)
48 ("iso8859-11$" . iso-8859-11)
49 ("iso8859-13$" . iso-8859-13)
50 ("iso8859-14$" . iso-8859-14)
51 ("iso8859-15$" . iso-8859-15)
cd5315ac 52 ("iso8859-16$" . iso-8859-16)
cd155f72 53 ("ascii-0$" . ascii)
37a94e2f 54 ("gb2312.1980" . chinese-gb2312)
28f2f887 55 ("gbk" . chinese-gbk)
26cdb3ee 56 ("gb18030" . (unicode . nil))
37a94e2f
KH
57 ("jisx0208.1978" . japanese-jisx0208-1978)
58 ("jisx0208" . japanese-jisx0208)
59 ("jisx0201" . jisx0201)
60 ("jisx0212" . japanese-jisx0212)
b9e501de 61 ("ksx1001" . korean-ksc5601)
37a94e2f
KH
62 ("ksc5601.1987" . korean-ksc5601)
63 ("cns11643.1992.*1" . chinese-cns11643-1)
64 ("cns11643.1992.*2" . chinese-cns11643-2)
65 ("cns11643.1992.*3" . chinese-cns11643-3)
66 ("cns11643.1992.*4" . chinese-cns11643-4)
67 ("cns11643.1992.*5" . chinese-cns11643-5)
68 ("cns11643.1992.*6" . chinese-cns11643-6)
69 ("cns11643.1992.*7" . chinese-cns11643-7)
eb62213c
KH
70 ("cns11643.92p1-0" . chinese-cns11643-1)
71 ("cns11643.92p2-0" . chinese-cns11643-2)
72 ("cns11643.92p3-0" . chinese-cns11643-3)
73 ("cns11643.92p4-0" . chinese-cns11643-4)
74 ("cns11643.92p5-0" . chinese-cns11643-5)
75 ("cns11643.92p6-0" . chinese-cns11643-6)
76 ("cns11643.92p7-0" . chinese-cns11643-7)
37a94e2f 77 ("big5" . big5)
37a94e2f
KH
78 ("viscii" . viscii)
79 ("tis620" . tis620-2533)
b32f2167 80 ("microsoft-cp1251" . windows-1251)
6118a2b8 81 ("koi8-r" . koi8-r)
ef1d428c
KH
82 ("jisx0213.2000-1" . japanese-jisx0213-1)
83 ("jisx0213.2000-2" . japanese-jisx0213-2)
84 ("jisx0213.2004-1" . japanese-jisx0213.2004-1)
85 ("iso10646-1$" . (unicode-bmp . nil))
86 ("iso10646.indian-1" . (unicode-bmp . nil))
87 ("unicode-bmp" . (unicode-bmp . nil))
88 ("abobe-symbol" . symbol)
89 ("sisheng_cwnn" . chinese-sisheng)
37a94e2f
KH
90 ("mulearabic-0" . arabic-digit)
91 ("mulearabic-1" . arabic-1-column)
92 ("mulearabic-2" . arabic-2-column)
93 ("muleipa" . ipa)
362cd0bf 94 ("ethiopic-unicode" . (unicode-bmp . ethiopic))
37a94e2f 95 ("is13194-devanagari" . indian-is13194)
8f924df7
KH
96 ("Devanagari-CDAC" . devanagari-cdac)
97 ("Sanskrit-CDAC" . sanskrit-cdac)
98 ("Bengali-CDAC" . bengali-cdac)
99 ("Assamese-CDAC" . assamese-cdac)
100 ("Punjabi-CDAC" . punjabi-cdac)
101 ("Gujarati-CDAC" . gujarati-cdac)
102 ("Oriya-CDAC" . oriya-cdac)
103 ("Tamil-CDAC" . tamil-cdac)
104 ("Telugu-CDAC" . telugu-cdac)
105 ("Kannada-CDAC" . kannada-cdac)
106 ("Malayalam-CDAC" . malayalam-cdac)
107 ("Devanagari-Akruti" . devanagari-akruti)
108 ("Bengali-Akruti" . bengali-akruti)
109 ("Punjabi-Akruti" . punjabi-akruti)
110 ("Gujarati-Akruti" . gujarati-akruti)
111 ("Oriya-Akruti" . oriya-akruti)
112 ("Tamil-Akruti" . tamil-akruti)
113 ("Telugu-Akruti" . telugu-akruti)
114 ("Kannada-Akruti" . kannada-akruti)
115 ("Malayalam-Akruti" . malayalam-akruti)
37a94e2f
KH
116 ("muleindian-2" . indian-2-column)
117 ("muleindian-1" . indian-1-column)
118 ("mulelao-1" . mule-lao)
119 ("muletibetan-2" . tibetan)
fd47473c 120 ("muletibetan-0" . tibetan)
ca0a881a 121 ("muletibetan-1" . tibetan-1-column))))
37a94e2f 122
aa360da1
GM
123(defvar font-encoding-charset-alist)
124
6ce70459
KH
125(setq font-encoding-charset-alist
126 '((latin-iso8859-1 . iso-8859-1)
127 (latin-iso8859-2 . iso-8859-2)
128 (latin-iso8859-3 . iso-8859-3)
129 (latin-iso8859-4 . iso-8859-4)
130 (latin-iso8859-9 . iso-8859-9)
131 (latin-iso8859-10 . iso-8859-10)
132 (latin-iso8859-13 . iso-8859-13)
133 (latin-iso8859-14 . iso-8859-14)
134 (latin-iso8859-15 . iso-8859-15)
135 (latin-iso8859-16 . iso-8859-16)
136 (cyrillic-iso8859-5 . iso-8859-5)
137 (greek-iso8859-7 . iso-8859-7)
138 (arabic-iso8859-6 . iso-8859-6)
139 (thai-tis620 . tis620-2533)
140 (latin-jisx0201 . jisx0201)
141 (katakana-jisx0201 . jisx0201)
142 (chinese-big5-1 . big5)
143 (chinese-big5-2 . big5)
144 (vietnamese-viscii-lower . viscii)
145 (vietnamese-viscii-upper . viscii)
146 (tibetan . unicode-bmp)))
147
6118a2b8 148(setq script-representative-chars
1a8dc09b
KH
149 '((latin ?A ?Z ?a ?z #x00C0 #x0100 #x0180 #x1e00)
150 (phonetic #x250 #x283)
f3a9e177 151 (greek #x3A9)
6118a2b8
KH
152 (coptic #x3E2)
153 (cyrillic #x42F)
154 (armenian #x531)
155 (hebrew #x5D0)
156 (arabic #x628)
157 (syriac #x710)
158 (thaana #x78C)
159 (devanagari #x915)
160 (bengali #x995)
161 (gurmukhi #xA15)
162 (gujarati #xA95)
163 (oriya #xB15)
164 (tamil #xB95)
165 (telugu #xC15)
166 (kannada #xC95)
167 (malayalam #xD15)
168 (sinhala #xD95)
169 (thai #xE17)
170 (lao #xEA5)
171 (tibetan #xF40)
d99ea08e 172 (burmese #x1000)
6118a2b8
KH
173 (georgian #x10D3)
174 (ethiopic #x1208)
175 (cherokee #x13B6)
176 (canadian-aboriginal #x14C0)
177 (ogham #x168F)
178 (runic #x16A0)
179 (khmer #x1780)
180 (mongolian #x1826)
fac97bb4 181 (symbol . [#x201C #x2200 #x2500])
6118a2b8
KH
182 (braille #x2800)
183 (ideographic-description #x2FF0)
184 (cjk-misc #x300E)
185 (kana #x304B)
186 (bopomofo #x3105)
187 (kanbun #x319D)
188 (han #x5B57)
189 (yi #xA288)
e585323a
KH
190 (cham #xAA00)
191 (tai-viet #xAA80)
947c7596
KH
192 (hangul #xAC00)
193 (linear-b #x10000)
194 (aegean-number #x10100)
195 (ancient-greek-number #x10140)
196 (ancient-symbol #x10190)
197 (phaistos-disc #x101D0)
198 (lycian #x10280)
199 (carian #x102A0)
200 (olt-italic #x10300)
201 (ugaritic #x10380)
202 (old-persian #x103A0)
203 (deseret #x10400)
204 (shavian #x10450)
205 (osmanya #x10480)
206 (cypriot-syllabary #x10800)
207 (phoenician #x10900)
208 (lydian #x10920)
209 (kharoshthi #x10A00)
210 (cuneiform #x12000)
211 (cuneiform-numbers-and-punctuation #x12400)
212 (byzantine-musical-symbol #x1D000)
213 (musical-symbol #x1D100)
214 (ancient-greek-musical-notation #x1D200)
215 (tai-xuan-jing-symbol #x1D300)
216 (counting-rod-numeral #x1D360)
947c7596
KH
217 (mahjong-tile #x1F000)
218 (domino-tile #x1F030)))
37a94e2f 219
aa360da1
GM
220(defvar otf-script-alist)
221
10853234
KH
222(setq otf-script-alist
223 '((arab . arabic)
224 (armn . armenian)
225 (bali . balinese)
226 (beng . bengali)
227 (bopo . bopomofo)
228 (brai . braille)
229 (bugi . buginese)
230 (buhd . buhid)
27950902 231 (byzm . byzantine-musical-symbol)
6ce70459 232 (cans . canadian-aboriginal)
10853234
KH
233 (cher . cherokee)
234 (copt . coptic)
235 (xsux . cuneiform)
236 (cyrl . cyrillic)
237 (cprt . cypriot)
238 (dsrt . deseret)
239 (deva . devanagari)
240 (ethi . ethiopic)
241 (geor . georgian)
242 (glag . glagolitic)
243 (goth . gothic)
244 (grek . greek)
245 (gujr . gujarati)
246 (guru . gurmukhi)
247 (hani . han)
248 (hang . hangul)
249 (hano . hanunoo)
250 (hebr . hebrew)
251 (kana . kana)
252 (knda . kannada)
253 (khar . kharoshthi)
254 (khmr . khmer)
d9080b86 255 (lao\ . lao)
10853234
KH
256 (latn . latin)
257 (limb . limbu)
258 (linb . linear_b)
259 (mlym . malayalam)
27950902 260 (math . mathematical)
10853234 261 (mong . mongolian)
27950902 262 (musc . musical-symbol)
d99ea08e 263 (mymr . burmese)
d9080b86 264 (nko\ . nko)
10853234
KH
265 (ogam . ogham)
266 (ital . old_italic)
267 (xpeo . old_persian)
268 (orya . oriya)
269 (osma . osmanya)
270 (phag . phags-pa)
271 (phnx . phoenician)
272 (runr . runic)
273 (shaw . shavian)
274 (sinh . sinhala)
275 (sylo . syloti_nagri)
276 (syrc . syriac)
277 (tglg . tagalog)
278 (tagb . tagbanwa)
279 (taml . tamil)
280 (tale . tai_le)
281 (telu . telugu)
282 (thaa . thaana)
283 (thai . thai)
284 (tibt . tibetan)
285 (tfng . tifinagh)
286 (ugar . ugaritic)
d9080b86 287 (yi\ \ . yi)))
10853234 288
2ad00186 289;; Set standard fontname specification of characters in the default
37a94e2f
KH
290;; fontset to find an appropriate font for each script/charset. The
291;; specification has the form ((SCRIPT FONT-SPEC ...) ...), where
292;; FONT-SPEC is:
9841dbc9
KH
293;; a cons (FAMILY . REGISTRY),
294;; or a string FONT-NAME,
295;; or an object created by `font-spec'.
8f924df7 296;;
b4dc7d98 297;; FAMILY may be nil, in which case, the corresponding name of
9841dbc9
KH
298;; default face is used. If REGISTRY contains a character `-', the
299;; string before that is embedded in `CHARSET_REGISTRY' field, and the
300;; string after that is embedded in `CHARSET_ENCODING' field. If it
301;; does not contain `-', the whole string is embedded in
302;; `CHARSET_REGISTRY' field, and a wild card character `*' is embedded
303;; in `CHARSET_ENCODING' field.
37a94e2f
KH
304;;
305;; SCRIPT is a symbol that appears as an element of the char table
306;; `char-script-table'. SCRIPT may be a charset specifying the range
307;; of characters.
2ad00186 308
aa360da1
GM
309(declare-function new-fontset "fontset.c" (name fontlist))
310(declare-function set-fontset-font "fontset.c"
311 (name target font-spec &optional frame add))
312
726e3f1d
KH
313(eval-when-compile
314
315;; Build a data to initialize the default fontset at compile time to
316;; avoid loading charsets that won't be necessary at runtime.
317
318;; The value is (CJK-REGISTRY-VECTOR TARGET-SPEC ...), where
319;; CJK-REGISTRY-VECTOR is ["JISX0208.1983-0" "GB2312.1980-0" ...],
320;; TARGET-SPEC is (TARGET . BITMASK) or (TARGET SPEC ...),
321;; TARGET is CHAR or (FROM-CHAR . TO-CHAR),
322;; BITMASK is a bitmask of indices to CJK-REGISTRY-VECTOR,
323;; SPEC is a list of arguments to font-spec.
324
325(defmacro build-default-fontset-data ()
326 (let* (;; CHARSET-REGISTRY CHARSET FROM-CODE TO-CODE
327 (cjk '(("JISX0208.1983-0" japanese-jisx0208 #x2121 #x287E)
328 ("GB2312.1980-0" chinese-gb2312 #x2121 #x297E)
329 ("BIG5-0" big5 #xA140 #xA3FE)
330 ("CNS11643.1992-1" chinese-cns11643-1 #x2121 #x427E)
331 ("KSC5601.1987-0" korean-ksc5601 #x2121 #x2C7E)))
332 (scripts '((tibetan
333 (:registry "iso10646-1" :otf (tibt nil (ccmp blws abvs)))
334 (:family "mtib" :registry "iso10646-1")
335 (:registry "muletibetan-2"))
336 (ethiopic
337 (:registry "iso10646-1" :script ethiopic)
338 (:registry "ethiopic-unicode"))
339 (phonetic
340 (:registry "iso10646-1" :script phonetic)
341 (:registry "MuleIPA-1")
342 (:registry "iso10646-1"))))
343 (cjk-table (make-char-table nil))
344 (script-coverage
345 #'(lambda (script)
346 (let ((coverage))
347 (map-char-table
348 #'(lambda (range val)
349 (when (eq val script)
350 (if (consp range)
351 (setq range (cons (car range) (cdr range))))
352 (push range coverage)))
353 char-script-table)
354 coverage)))
355 (data (list (vconcat (mapcar 'car cjk))))
356 (i 0))
357 (dolist (elt cjk)
358 (let ((mask (lsh 1 i)))
359 (map-charset-chars
360 #'(lambda (range arg)
361 (let ((from (car range)) (to (cdr range)))
362 (if (< to #x110000)
363 (while (<= from to)
e94be827
KH
364 (or (memq (aref char-script-table from)
365 '(kana hangul han cjk-misc))
366 (aset cjk-table from
367 (logior (or (aref cjk-table from) 0) mask)))
726e3f1d
KH
368 (setq from (1+ from))))))
369 (nth 1 elt) nil (nth 2 elt) (nth 3 elt)))
370 (setq i (1+ i)))
371 (map-char-table
372 #'(lambda (range val)
373 (if (consp range)
374 (setq range (cons (car range) (cdr range))))
375 (push (cons range val) data))
376 cjk-table)
377 (dolist (script scripts)
378 (dolist (range (funcall script-coverage (car script)))
379 (push (cons range (cdr script)) data)))
380 `(quote ,(nreverse data))))
381)
382
c963bbc2
KH
383(defun setup-default-fontset ()
384 "Setup the default fontset."
8f924df7
KH
385 (new-fontset
386 "fontset-default"
d9080b86 387 `(;; for each script
8f924df7
KH
388 (latin (nil . "ISO8859-1")
389 (nil . "ISO8859-2")
390 (nil . "ISO8859-3")
391 (nil . "ISO8859-4")
392 (nil . "ISO8859-9")
393 (nil . "ISO8859-10")
394 (nil . "ISO8859-13")
395 (nil . "ISO8859-14")
396 (nil . "ISO8859-15")
cd5315ac 397 (nil . "ISO8859-16")
e585323a 398 (nil . "VISCII1.1-1")
174ba8c7 399 ,(font-spec :registry "iso10646-1" :script 'latin))
8f924df7 400
ef34da7f
JB
401 (thai ,(font-spec :registry "iso10646-1" :otf '(thai nil nil (mark)))
402 ,(font-spec :registry "iso10646-1" :script 'thai)
6ce70459
KH
403 (nil . "TIS620*")
404 (nil . "ISO8859-11"))
8f924df7 405
d9080b86
KH
406 (devanagari ,(font-spec :registry "iso10646-1" :otf '(deva nil (rphf)))
407 (nil . "iso10646.indian-1"))
6ce70459
KH
408 (bengali ,(font-spec :registry "iso10646-1" :otf '(beng nil (rphf))))
409 (gurmukhi ,(font-spec :registry "iso10646-1" :otf '(guru nil (blwf))))
410 (gujarati ,(font-spec :registry "iso10646-1" :otf '(gujr nil (rphf))))
411 (oriya ,(font-spec :registry "iso10646-1" :otf '(orya nil (rphf))))
d9080b86 412 (tamil ,(font-spec :registry "iso10646-1" :otf '(taml nil (akhn))))
6ce70459
KH
413 (telugu ,(font-spec :registry "iso10646-1" :otf '(telu nil (blwf))))
414 (kannada ,(font-spec :registry "iso10646-1" :otf '(knda nil (rphf))))
415 (sinhala ,(font-spec :registry "iso10646-1" :otf '(sinh nil (akhn))))
416 (malayalam ,(font-spec :registry "iso10646-1" :otf '(mlym nil (akhn))))
8f924df7 417
4aa2c3b2 418 (burmese ,(font-spec :registry "iso10646-1" :otf '(mymr nil nil))
d99ea08e 419 ,(font-spec :registry "iso10646-1" :script 'burmese))
f88cc4d6 420
01308609 421 (lao ,(font-spec :registry "iso10646-1" :otf '(lao\ nil nil (mark)))
a1fe5dfa 422 ,(font-spec :registry "iso10646-1" :script 'lao)
6ce70459 423 (nil . "MuleLao-1"))
8f924df7 424
f6724075
KH
425 (tai-viet ("TaiViet" . "iso10646-1"))
426
6ce70459
KH
427 (greek ,(font-spec :registry "iso10646-1" :script 'greek)
428 (nil . "ISO8859-7"))
8f924df7 429
6ce70459
KH
430 (cyrillic ,(font-spec :registry "iso10646-1" :script 'cyrillic)
431 (nil . "ISO8859-5")
b32f2167
KH
432 (nil . "microsoft-cp1251")
433 (nil . "koi8-r"))
8f924df7 434
6ce70459 435 (arabic ,(font-spec :registry "iso10646-1"
b60f961f 436 :otf '(arab nil (init medi fina liga)))
6ce70459 437 (nil . "MuleArabic-0")
8f924df7
KH
438 (nil . "MuleArabic-1")
439 (nil . "MuleArabic-2")
440 (nil . "ISO8859-6"))
441
6ce70459
KH
442 (hebrew ,(font-spec :registry "iso10646-1" :script 'hebrew)
443 (nil . "ISO8859-8"))
444
6ce70459
KH
445 (khmer ,(font-spec :registry "iso10646-1" :otf '(khmr nil (pres))))
446
e096e30e 447 (kana (nil . "JISX0208*")
8f924df7
KH
448 (nil . "GB2312.1980-0")
449 (nil . "KSC5601.1987*")
d1bd4b12
KH
450 (nil . "JISX0201*")
451 (nil . "JISX0213.2000-1")
e096e30e
KH
452 (nil . "JISX0213.2004-1")
453 ,(font-spec :registry "iso10646-1" :script 'kana))
8f924df7 454
66fb0117
JR
455 (bopomofo ,(font-spec :registry "iso10646-1" :script 'bopomofo)
456 (nil . "sisheng_cwnn-0"))
8f924df7 457
e096e30e 458 (han (nil . "GB2312.1980-0")
8f924df7
KH
459 (nil . "JISX0208*")
460 (nil . "JISX0212*")
461 (nil . "big5*")
462 (nil . "KSC5601.1987*")
463 (nil . "CNS11643.1992-1")
464 (nil . "CNS11643.1992-2")
465 (nil . "CNS11643.1992-3")
466 (nil . "CNS11643.1992-4")
467 (nil . "CNS11643.1992-5")
468 (nil . "CNS11643.1992-6")
469 (nil . "CNS11643.1992-7")
470 (nil . "gbk-0")
c7606603 471 (nil . "gb18030")
8f924df7 472 (nil . "JISX0213.2000-1")
a16abfed 473 (nil . "JISX0213.2000-2")
e096e30e
KH
474 (nil . "JISX0213.2004-1")
475 ,(font-spec :registry "iso10646-1" :lang 'ja)
476 ,(font-spec :registry "iso10646-1" :lang 'zh))
8f924df7 477
e096e30e 478 (cjk-misc (nil . "GB2312.1980-0")
8f924df7
KH
479 (nil . "JISX0208*")
480 (nil . "JISX0212*")
481 (nil . "big5*")
482 (nil . "KSC5601.1987*")
483 (nil . "CNS11643.1992-1")
484 (nil . "CNS11643.1992-2")
485 (nil . "CNS11643.1992-3")
486 (nil . "CNS11643.1992-4")
487 (nil . "CNS11643.1992-5")
488 (nil . "CNS11643.1992-6")
489 (nil . "CNS11643.1992-7")
490 (nil . "gbk-0")
c7606603 491 (nil . "gb18030")
8f924df7 492 (nil . "JISX0213.2000-1")
e096e30e 493 (nil . "JISX0213.2000-2")
174ba8c7
JR
494 ,(font-spec :registry "iso10646-1" :lang 'ja)
495 ,(font-spec :registry "iso10646-1" :lang 'zh))
8f924df7 496
e096e30e 497 (hangul (nil . "KSC5601.1987-0")
174ba8c7 498 ,(font-spec :registry "iso10646-1" :lang 'ko))
8f924df7
KH
499
500 ;; for each charset
501 (ascii (nil . "ISO8859-1"))
502 (arabic-digit ("*" . "MuleArabic-0"))
503 (arabic-1-column ("*" . "MuleArabic-1"))
504 (arabic-2-column ("*" . "MuleArabic-2"))
505 (indian-is13194 (nil . "is13194-devanagari"))
506 (indian-1-column ("*" . "muleindian-2"))
507 ;; Indian CDAC
508 (devanagari-cdac (nil . "Devanagari-CDAC"))
509 (sanskrit-cdac (nil . "Sanskrit-CDAC"))
510 (bengali-cdac (nil . "Bengali-CDAC"))
511 (assamese-cdac (nil . "Assamese-CDAC"))
512 (punjabi-cdac (nil . "Punjabi-CDAC"))
513 (gujarati-cdac (nil . "Gujarati-CDAC"))
514 (oriya-cdac (nil . "Oriya-CDAC"))
515 (tamil-cdac (nil . "Tamil-CDAC"))
516 (telugu-cdac (nil . "Telugu-CDAC"))
517 (kannada-cdac (nil . "Kannada-CDAC"))
518 (malayalam-cdac (nil . "Malayalam-CDAC"))
519 ;; Indian AKRUTI
520 (devanagari-akruti (nil . "Devanagari-Akruti"))
521 (bengali-akruti (nil . "Bengali-Akruti"))
522 (punjabi-akruti (nil . "Punjabi-Akruti"))
523 (gujarati-akruti (nil . "Gujarati-Akruti"))
524 (oriya-akruti (nil . "Oriya-Akruti"))
525 (tamil-akruti (nil . "Tamil-Akruti"))
526 (telugu-akruti (nil . "Telugu-Akruti"))
527 (kannada-akruti (nil . "Kannada-Akruti"))
528 (malayalam-akruti (nil . "Malayalam-Akruti"))
d1bd4b12
KH
529
530 ;; Fallback fonts
531 (nil (nil . "gb2312.1980")
c7606603
KH
532 (nil . "gbk-0")
533 (nil . "gb18030")
d1bd4b12
KH
534 (nil . "jisx0208")
535 (nil . "ksc5601.1987")
eb62213c
KH
536 (nil . "CNS11643.1992-1")
537 (nil . "CNS11643.1992-2")
538 (nil . "CNS11643.1992-3")
539 (nil . "CNS11643.1992-4")
540 (nil . "CNS11643.1992-5")
541 (nil . "CNS11643.1992-6")
542 (nil . "CNS11643.1992-7")
d1bd4b12
KH
543 (nil . "big5")
544 (nil . "jisx0213.2000-1")
545 (nil . "jisx0213.2004-1")
546 (nil . "jisx0212"))
8f924df7
KH
547 ))
548
947c7596
KH
549 ;; For simple scripts
550 (dolist (script '(phonetic
551 armenian
552 syriac
553 thaana
947c7596
KH
554 georgian
555 cherokee
556 canadian-aboriginal
557 ogham
558 runic
559 symbol
560 braille
561 yi
6fcec85e 562 aegean-number
947c7596
KH
563 ancient-greek-number
564 ancient-symbol
565 phaistos-disc
566 lycian
567 carian
568 olt-italic
569 ugaritic
570 old-persian
571 deseret
572 shavian
573 osmanya
574 cypriot-syllabary
575 phoenician
576 lydian
577 kharoshthi
578 cuneiform
579 cuneiform-numbers-and-punctuation
580 byzantine-musical-symbol
581 musical-symbol
582 ancient-greek-musical-notation
583 tai-xuan-jing-symbol
584 counting-rod-numeral
947c7596
KH
585 mahjong-tile
586 domino-tile))
587 (set-fontset-font "fontset-default"
69cb8d82
KH
588 script (font-spec :registry "iso10646-1" :script script)
589 nil 'append))
947c7596 590
c8762666
KH
591 ;; Special settings for `MATHEMATICAL (U+1D400..U+1D7FF)'.
592 (dolist (math-subgroup '((#x1D400 #x1D433 mathematical-bold)
593 (#x1D434 #x1D467 mathematical-italic)
594 (#x1D468 #x1D49B mathematical-bold-italic)
595 (#x1D49C #x1D4CF mathematical-script)
596 (#x1D4D0 #x1D503 mathematical-bold-script)
597 (#x1D504 #x1D537 mathematical-fraktur)
598 (#x1D538 #x1D56B mathematical-double-struck)
599 (#x1D56C #x1D59F mathematical-bold-fraktur)
600 (#x1D5A0 #x1D5D3 mathematical-sans-serif)
601 (#x1D5D4 #x1D607 mathematical-sans-serif-bold)
602 (#x1D608 #x1D63B mathematical-sans-serif-italic)
603 (#x1D63C #x1D66F mathematical-sans-serif-bold-italic)
604 (#x1D670 #x1D6A3 mathematical-monospace)
605 (#x1D6A4 #x1D6A5 mathematical-italic)
606 (#x1D6A8 #x1D6E1 mathematical-bold)
607 (#x1D6E2 #x1D71B mathematical-italic)
608 (#x1D71C #x1D755 mathematical-bold-italic)
609 (#x1D756 #x1D78F mathematical-sans-serif-bold)
610 (#x1D790 #x1D7C9 mathematical-sans-serif-bold-italic)
611 (#x1D7CA #x1D7D7 mathematical-bold)
612 (#x1D7D8 #x1D7E1 mathematical-double-struck)
613 (#x1D7E2 #x1D7EB mathematical-sans-serif)
614 (#x1D7EC #x1D7F5 mathematical-sans-serif-bold)
615 (#x1D7F6 #x1D7FF mathematical-monospace)))
616 (let ((slot (assq (nth 2 math-subgroup) script-representative-chars)))
617 (if slot
618 (if (vectorp (cdr slot))
619 (setcdr slot (vconcat (cdr slot) (vector (car math-subgroup))))
620 (setcdr slot (vector (cadr slot) (car math-subgroup))))
621 (setq slot (list (nth 2 math-subgroup) (car math-subgroup)))
3208a64a 622 (nconc script-representative-chars (list slot))))
c8762666
KH
623 (set-fontset-font
624 "fontset-default"
625 (cons (car math-subgroup) (nth 1 math-subgroup))
626 (font-spec :registry "iso10646-1" :script (nth 2 math-subgroup))))
627
0ad6626b 628 ;; Append CJK fonts for characters other than han, kana, cjk-misc.
726e3f1d
KH
629 ;; Append fonts for scripts whose name is also a charset name.
630 (let* ((data (build-default-fontset-data))
631 (registries (car data)))
632 (dolist (target-spec (cdr data))
633 (let ((target (car target-spec))
634 (spec (cdr target-spec)))
635 (if (integerp spec)
636 (dotimes (i (length registries))
637 (if (> (logand spec (lsh 1 i)) 0)
638 (set-fontset-font "fontset-default" target
639 (cons nil (aref registries i))
640 nil 'append)))
641 (dolist (args spec)
642 (set-fontset-font "fontset-default" target
643 (apply 'font-spec args) nil 'append))))))
0ad6626b 644
8f924df7
KH
645 ;; Append Unicode fonts.
646 ;; This may find fonts with more variants (bold, italic) but which
647 ;; don't cover many characters.
d1bd4b12 648 (set-fontset-font "fontset-default" nil
3fe3d08b 649 '(nil . "iso10646-1") nil 'prepend)
8f924df7
KH
650 ;; These may find fonts that cover many characters but with fewer
651 ;; variants.
d1bd4b12 652 (set-fontset-font "fontset-default" nil
3fe3d08b 653 '("gnu-unifont" . "iso10646-1") nil 'prepend)
d1bd4b12 654 (set-fontset-font "fontset-default" nil
3fe3d08b 655 '("mutt-clearlyu" . "iso10646-1") nil 'prepend)
e54be9a0
KH
656 (set-fontset-font "fontset-default" '(#x20000 . #x2FFFF)
657 '(nil . "unicode-sip"))
e585323a 658
74fcd0b1
KH
659 (set-fontset-font "fontset-default" '(#xE000 . #xF8FF)
660 '(nil . "iso10646-1"))
661 ;; Don't try the fallback fonts even if no suitable font was found
662 ;; by the above font-spec.
663 (set-fontset-font "fontset-default" '(#xE000 . #xF8FF) nil nil 'append))
06f76f0d 664
4bd4e5bc
KH
665(defun create-default-fontset ()
666 "Create the default fontset.
667Internal use only. Should be called at startup time."
668 (condition-case err
669 (setup-default-fontset)
670 (error (display-warning
671 'initialization
672 (format "Creation of the default fontsets failed: %s" err)
673 :error))))
674
8135c753
DL
675;; These are the registered registries/encodings from
676;; ftp://ftp.x.org/pub/DOCS/registry 2001/06/01
677
678;; Name Reference
679;; ---- ---------
680;; "DEC" [27]
681;; registry prefix
682;; "DEC.CNS11643.1986-2" [53]
683;; CNS11643 2-plane using the encoding
684;; suggested in that standard
685;; "DEC.DTSCS.1990-2" [54]
686;; DEC Taiwan Supplemental Character Set
687;; "fujitsu.u90x01.1991-0" [87]
688;; "fujitsu.u90x03.1991-0" [87]
689;; "GB2312.1980-0" [39],[12]
690;; China (PRC) Hanzi, GL encoding
691;; "GB2312.1980-1" [39]
692;; (deprecated)
693;; China (PRC) Hanzi, GR encoding
694;; "HP-Arabic8" [36]
695;; HPARABIC8 8-bit character set
696;; "HP-East8" [36]
697;; HPEAST8 8-bit character set
698;; "HP-Greek8" [36]
699;; HPGREEK8 8-bit character set
700;; "HP-Hebrew8" [36]
701;; HPHEBREW8 8-bit character set
702;; "HP-Japanese15" [36]
51e4f4a8 703;; HPJAPAN15 15-bit character set,
4c36be58 704;; modified from industry de facto
8135c753
DL
705;; standard Shift-JIS
706;; "HP-Kana8" [36]
707;; HPKANA8 8-bit character set
708;; "HP-Korean15" [36]
709;; HPKOREAN15 15-bit character set
710;; "HP-Roman8" [36]
711;; HPROMAN8 8-bit character set
712;; "HP-SChinese15" [36]
713;; HPSCHINA15 15-bit character set for
714;; support of Simplified Chinese
715;; "HP-TChinese15" [36]
716;; HPTCHINA15 15-bit character set for
717;; support of Traditional Chinese
718;; "HP-Turkish8" [36]
719;; HPTURKISH8 8-bit character set
720;; "IPSYS" [59]
721;; registry prefix
722;; "IPSYS.IE-1" [59]
723;; "ISO2022"<REG>"-"<ENC> [44]
724;; "ISO646.1991-IRV" [107]
725;; ISO 646 International Reference Version
726;; "ISO8859-1" [15],[12]
727;; ISO Latin alphabet No. 1
728;; "ISO8859-2" [15],[12]
729;; ISO Latin alphabet No. 2
730;; "ISO8859-3" [15],[12]
731;; ISO Latin alphabet No. 3
732;; "ISO8859-4" [15],[12]
733;; ISO Latin alphabet No. 4
734;; "ISO8859-5" [15],[12]
735;; ISO Latin/Cyrillic alphabet
736;; "ISO8859-6" [15],[12]
737;; ISO Latin/Arabic alphabet
738;; "ISO8859-7" [15],[12]
739;; ISO Latin/Greek alphabet
740;; "ISO8859-8" [15],[12]
741;; ISO Latin/Hebrew alphabet
742;; "ISO8859-9" [15],[12]
743;; ISO Latin alphabet No. 5
744;; "ISO8859-10" [15],[12]
745;; ISO Latin alphabet No. 6
746;; "ISO8859-13" [15],[12]
747;; ISO Latin alphabet No. 7
748;; "ISO8859-14" [15],[12]
749;; ISO Latin alphabet No. 8
750;; "ISO8859-15" [15],[12]
751;; ISO Latin alphabet No. 9
752;; "FCD8859-15" [7]
753;; (deprecated)
754;; ISO Latin alphabet No. 9, Final Committee Draft
755;; "ISO10646-1" [133]
756;; Unicode Universal Multiple-Octet Coded Character Set
757;; "ISO10646-MES" [133]
758;; (deprecated)
759;; Unicode Minimum European Subset
760;; "JISX0201.1976-0" [38],[12]
761;; 8-Bit Alphanumeric-Katakana Code
762;; "JISX0208.1983-0" [40],[12]
763;; Japanese Graphic Character Set,
764;; GL encoding
765;; "JISX0208.1990-0" [71]
766;; Japanese Graphic Character Set,
767;; GL encoding
768;; "JISX0208.1983-1" [40]
769;; (deprecated)
770;; Japanese Graphic Character Set,
771;; GR encoding
772;; "JISX0212.1990-0" [72]
773;; Supplementary Japanese Graphic Character Set,
774;; GL encoding
775;; "KOI8-R" [119]
776;; Cyrillic alphabet
777;; "KSC5601.1987-0" [41],[12]
778;; Korean Graphic Character Set,
779;; GL encoding
780;; "KSC5601.1987-1" [41]
781;; (deprecated)
782;; Korean Graphic Character Set,
783;; GR encoding
784;; "omron_CNS11643-0" [45]
785;; "omron_CNS11643-1" [45]
786;; "omron_BIG5-0" [45]
787;; "omron_BIG5-1" [45]
788;; "wn.tamil.1993" [103]
4ed46869 789
06f76f0d 790(defun set-font-encoding (pattern charset)
8135c753 791 "Set arguments in `font-encoding-alist' (which see)."
4ed46869
KH
792 (let ((slot (assoc pattern font-encoding-alist)))
793 (if slot
06f76f0d 794 (setcdr slot charset)
4ed46869 795 (setq font-encoding-alist
06f76f0d 796 (cons (cons pattern charset) font-encoding-alist)))))
12385722 797
aa360da1
GM
798(defvar x-pixel-size-width-font-regexp)
799(defvar vertical-centering-font-regexp)
800
4ed46869
KH
801;; Setting for suppressing XLoadQueryFont on big fonts.
802(setq x-pixel-size-width-font-regexp
1e8780b1 803 (purecopy "gb2312\\|gbk\\|gb18030\\|jisx0208\\|ksc5601\\|cns11643\\|big5"))
4ed46869 804
6eca8d93 805;; These fonts require vertical centering.
0c4f97d0 806(setq vertical-centering-font-regexp
1e8780b1 807 (purecopy "gb2312\\|gbk\\|gb18030\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5"))
56cd351d
GM
808(put 'vertical-centering-font-regexp 'standard-value
809 (list vertical-centering-font-regexp))
0c4f97d0 810
e46947a5
KH
811;; CDAC fonts are actually smaller than their design sizes.
812(setq face-font-rescale-alist
1e8780b1 813 (list (cons (purecopy "-cdac$") 1.3)))
e46947a5 814
06f76f0d
KH
815(defvar x-font-name-charset-alist nil
816 "This variable has no meaning now. Just kept for backward compatibility.")
6fb8f8bd 817
4ed46869
KH
818;;; XLFD (X Logical Font Description) format handler.
819
820;; Define XLFD's field index numbers. ; field name
06f76f0d
KH
821(defconst xlfd-regexp-family-subnum 0) ; FOUNDRY and FAMILY
822(defconst xlfd-regexp-weight-subnum 1) ; WEIGHT_NAME
823(defconst xlfd-regexp-slant-subnum 2) ; SLANT
824(defconst xlfd-regexp-swidth-subnum 3) ; SETWIDTH_NAME
825(defconst xlfd-regexp-adstyle-subnum 4) ; ADD_STYLE_NAME
826(defconst xlfd-regexp-pixelsize-subnum 5) ; PIXEL_SIZE
827(defconst xlfd-regexp-pointsize-subnum 6) ; POINT_SIZE
828(defconst xlfd-regexp-resx-subnum 7) ; RESOLUTION_X
829(defconst xlfd-regexp-resy-subnum 8) ; RESOLUTION_Y
830(defconst xlfd-regexp-spacing-subnum 8) ; SPACING
831(defconst xlfd-regexp-avgwidth-subnum 10) ; AVERAGE_WIDTH
832(defconst xlfd-regexp-registry-subnum 11) ; REGISTRY and ENCODING
4ed46869
KH
833
834;; Regular expression matching against a fontname which conforms to
835;; XLFD (X Logical Font Description). All fields in XLFD should be
836;; not be omitted (but can be a wild card) to be matched.
837(defconst xlfd-tight-regexp
838 "^\
06f76f0d 839-\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
4ed46869 840-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
06f76f0d
KH
841-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*-[^-]*\\)$")
842
843;; Regular expression matching against a fontname which conforms to
844;; XLFD (X Logical Font Description). All fields in XLFD from FOUNDRY
8135c753 845;; to ADSTYLE, REGISTRY, and ENCODING should be not be omitted (but
06f76f0d
KH
846;; can be a wild card) to be matched.
847(defconst xlfd-style-regexp
848 "^\
849-\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-.*\
850-\\([^-]*-[^-]*\\)$")
4ed46869
KH
851
852;; List of field numbers of XLFD whose values are numeric.
853(defconst xlfd-regexp-numeric-subnums
06f76f0d
KH
854 (list xlfd-regexp-pixelsize-subnum ;5
855 xlfd-regexp-pointsize-subnum ;6
856 xlfd-regexp-resx-subnum ;7
857 xlfd-regexp-resy-subnum ;8
858 xlfd-regexp-avgwidth-subnum ;10
4ed46869
KH
859 ))
860
861(defun x-decompose-font-name (pattern)
92438d6e 862 "Decompose PATTERN into XLFD fields and return a vector of the fields.
06f76f0d 863The length of the vector is 12.
5c32d3f2 864The FOUNDRY and FAMILY fields are concatenated and stored in the first
92438d6e 865element of the vector.
5c32d3f2 866The REGISTRY and ENCODING fields are concatenated and stored in the last
92438d6e
KH
867element of the vector.
868
869Return nil if PATTERN doesn't conform to XLFD."
870 (if (string-match xlfd-tight-regexp pattern)
871 (let ((xlfd-fields (make-vector 12 nil)))
872 (dotimes (i 12)
873 (aset xlfd-fields i (match-string (1+ i) pattern)))
874 (dotimes (i 12)
875 (if (string-match "^[*-]+$" (aref xlfd-fields i))
876 (aset xlfd-fields i nil)))
877 xlfd-fields)))
441038a6 878
bb98ead9 879(defun x-compose-font-name (fields &optional reduce)
8135c753 880 "Compose X fontname from FIELDS.
a0451a71 881FIELDS is a vector of XLFD fields, of length 12.
441038a6 882If a field is nil, wild-card letter `*' is embedded.
33fac697
JB
883Optional argument REDUCE exists just for backward compatibility,
884and is always ignored."
6eca8d93 885 (concat "-" (mapconcat (lambda (x) (or x "*")) fields "-")))
bcb68cff 886
4fbe2b13
GM
887
888(defun x-must-resolve-font-name (xlfd-fields)
889 "Like `x-resolve-font-name', but always return a font name.
890XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
891If no font matching XLFD-FIELDS is available, successively replace
892parts of the font name pattern with \"*\" until some font is found.
893Value is name of that font."
894 (let ((ascii-font nil) (index 0))
06f76f0d 895 (while (and (null ascii-font) (<= index xlfd-regexp-registry-subnum))
4fbe2b13
GM
896 (let ((pattern (x-compose-font-name xlfd-fields)))
897 (condition-case nil
898 (setq ascii-font (x-resolve-font-name pattern))
899 (error
900 (message "Warning: no fonts matching `%s' available" pattern)
901 (aset xlfd-fields index "*")
902 (setq index (1+ index))))))
903 (unless ascii-font
37aad8f5 904 (error "No fonts found"))
4fbe2b13
GM
905 ascii-font))
906
907
6ce70459
KH
908(defun x-complement-fontset-spec (default-spec fontlist)
909 "Complement elements of FONTLIST based on DEFAULT-SPEC.
910DEFAULT-SPEC is a font-spec object providing default font properties.
92438d6e
KH
911FONTLIST is an alist of script names vs the corresponding font names.
912
6ce70459
KH
913The font names are parsed and unspecified font properties are
914given from DEFAULT-SPEC."
5db50cca 915 (let ((prop-list '(:foundry :family :weight :slant :width :adstyle :size)))
06f76f0d 916 (dolist (elt fontlist)
6ce70459
KH
917 (let ((spec (font-spec :name (cadr elt))))
918 (dolist (prop prop-list)
919 (let ((val (font-get spec prop)))
920 (or val
921 (font-put spec prop (font-get default-spec prop)))))
922 (setcar (cdr elt) spec)))
6eca8d93 923 fontlist))
4ed46869 924
35d4066a
KH
925(defun fontset-name-p (fontset)
926 "Return non-nil if FONTSET is valid as fontset name.
927A valid fontset name should conform to XLFD (X Logical Font Description)
33fac697 928with \"fontset\" in `<CHARSET_REGISTRY>' field."
35d4066a
KH
929 (and (string-match xlfd-tight-regexp fontset)
930 (string= (match-string (1+ xlfd-regexp-registry-subnum) fontset)
931 "fontset")))
932
aa360da1
GM
933(declare-function fontset-list "fontset.c" ())
934
4ed46869 935(defun generate-fontset-menu ()
8135c753
DL
936 "Return list to be appended to `x-fixed-font-alist'.
937Done when `mouse-set-font' is called."
d58b6a31
KH
938 (let (l)
939 (dolist (fontset (fontset-list))
940 (or (string-match "fontset-default$" fontset)
e096e30e 941 (string-match "fontset-auto[0-9]+$" fontset)
d58b6a31 942 (push (list (fontset-plain-name fontset) fontset) l)))
80ae5f3a 943 (cons "Fontset"
d58b6a31 944 (sort l #'(lambda (x y) (string< (car x) (car y)))))))
4ed46869 945
aa360da1
GM
946(declare-function query-fontset "fontset.c" (pattern &optional regexpp))
947
4ed46869
KH
948(defun fontset-plain-name (fontset)
949 "Return a plain and descriptive name of FONTSET."
494ec9bc
KH
950 (if (not (setq fontset (query-fontset fontset)))
951 (error "Invalid fontset: %s" fontset))
4ed46869
KH
952 (let ((xlfd-fields (x-decompose-font-name fontset)))
953 (if xlfd-fields
87997c2c
KH
954 (let ((family (aref xlfd-fields xlfd-regexp-family-subnum))
955 (weight (aref xlfd-fields xlfd-regexp-weight-subnum))
4ed46869
KH
956 (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
957 (swidth (aref xlfd-fields xlfd-regexp-swidth-subnum))
958 (size (aref xlfd-fields xlfd-regexp-pixelsize-subnum))
06f76f0d 959 (nickname (aref xlfd-fields xlfd-regexp-registry-subnum))
4ed46869 960 name)
06f76f0d 961 (if (not (string-match "^fontset-\\(.*\\)$" nickname))
87997c2c
KH
962 (setq nickname family)
963 (setq nickname (match-string 1 nickname)))
09fd851a 964 (if (and size (> (string-to-number size) 0))
87997c2c
KH
965 (setq name (format "%s: %s-dot" nickname size))
966 (setq name nickname))
967 (and weight
968 (cond ((string-match "^medium$" weight)
969 (setq name (concat name " " "medium")))
970 ((string-match "^bold$\\|^demibold$" weight)
971 (setq name (concat name " " weight)))))
972 (and slant
973 (cond ((string-match "^i$" slant)
974 (setq name (concat name " " "italic")))
975 ((string-match "^o$" slant)
976 (setq name (concat name " " "slant")))
977 ((string-match "^ri$" slant)
978 (setq name (concat name " " "reverse italic")))
979 ((string-match "^ro$" slant)
980 (setq name (concat name " " "reverse slant")))))
981 name)
4ed46869
KH
982 fontset)))
983
37a94e2f 984(defvar charset-script-alist
8a020f4c 985 '((ascii . latin)
37a94e2f
KH
986 (latin-iso8859-1 . latin)
987 (latin-iso8859-2 . latin)
988 (latin-iso8859-3 . latin)
989 (latin-iso8859-4 . latin)
990 (latin-iso8859-9 . latin)
991 (latin-iso8859-10 . latin)
992 (latin-iso8859-13 . latin)
993 (latin-iso8859-14 . latin)
994 (latin-iso8859-15 . latin)
995 (latin-iso8859-16 . latin)
996 (latin-jisx0201 . latin)
997 (thai-tis620 . thai)
998 (cyrillic-iso8859-5 . cyrillic)
999 (arabic-iso8859-6 . arabic)
1000 (greek-iso8859-7 . latin)
1001 (hebrew-iso8859-8 . latin)
8a020f4c 1002 (katakana-jisx0201 . kana)
37a94e2f 1003 (chinese-gb2312 . han)
28f2f887 1004 (chinese-gbk . han)
c7606603
KH
1005 (gb18030-2-byte . han)
1006 (gb18030-4-byte-bmp . han)
1007 (gb18030-4-byte-ext-1 . han)
1008 (gb18030-4-byte-ext-2 . han)
1009 (gb18030-4-byte-smp . han)
37a94e2f
KH
1010 (chinese-big5-1 . han)
1011 (chinese-big5-2 . han)
1012 (chinese-cns11643-1 . han)
1013 (chinese-cns11643-2 . han)
1014 (chinese-cns11643-3 . han)
1015 (chinese-cns11643-4 . han)
1016 (chinese-cns11643-5 . han)
1017 (chinese-cns11643-6 . han)
1018 (chinese-cns11643-7 . han)
1019 (japanese-jisx0208 . han)
1020 (japanese-jisx0208-1978 . han)
1021 (japanese-jisx0212 . han)
1022 (japanese-jisx0213-1 . han)
1023 (japanese-jisx0213-2 . han)
8a020f4c 1024 (korean-ksc5601 . hangul)
37a94e2f
KH
1025 (chinese-sisheng . bopomofo)
1026 (vietnamese-viscii-lower . latin)
1027 (vietnamese-viscii-upper . latin)
1028 (arabic-digit . arabic)
1029 (arabic-1-column . arabic)
1030 (arabic-2-column . arabic)
1031 (indian-is13194 . devanagari)
1032 (indian-glyph . devanagari)
1033 (indian-1-column . devanagari)
1034 (indian-2-column . devanagari)
1035 (tibetan-1-column . tibetan))
1036 "Alist of charsets vs the corresponding most appropriate scripts.
1037
1038This alist is used by the function `create-fontset-from-fontset-spec'
1039to map charsets to scripts.")
c963bbc2 1040
6fb8f8bd 1041(defun create-fontset-from-fontset-spec (fontset-spec
bb98ead9 1042 &optional style-variant noerror)
4ed46869
KH
1043 "Create a fontset from fontset specification string FONTSET-SPEC.
1044FONTSET-SPEC is a string of the format:
6fcec85e 1045 FONTSET-NAME,SCRIPT-NAME0:FONT-NAME0,SCRIPT-NAME1:FONT-NAME1, ...
494ec9bc 1046Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
bb98ead9 1047
92438d6e
KH
1048When a frame uses the fontset as the `font' parameter, the frame's
1049default font name is derived from FONTSET-NAME by substituting
1050\"iso8859-1\" for the tail part \"fontset-XXX\". But, if SCRIPT-NAMEn
1051is \"ascii\", use the corresponding FONT-NAMEn as the default font
1052name.
bb98ead9 1053
a0451a71
MB
1054Optional 2nd and 3rd arguments exist just for backward compatibility,
1055and are ignored.
1f50fef9 1056
37a94e2f
KH
1057It returns a name of the created fontset.
1058
1059For backward compatibility, SCRIPT-NAME may be a charset name, in
1060which case, the corresponding script is decided by the variable
1061`charset-script-alist' (which see)."
92438d6e 1062 (or (string-match "^[^,]+" fontset-spec)
494ec9bc
KH
1063 (error "Invalid fontset spec: %s" fontset-spec))
1064 (let ((idx (match-end 0))
1065 (name (match-string 0 fontset-spec))
6ce70459
KH
1066 default-spec target script fontlist)
1067 (or (string-match xlfd-tight-regexp name)
92438d6e 1068 (error "Fontset name \"%s\" not conforming to XLFD" name))
6ce70459 1069 (setq default-spec (font-spec :name name))
92438d6e 1070 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
6fcec85e 1071 (while (string-match "[, \t\n]*\\([^:]+\\):[ \t]*\\([^,]+\\)"
31f5d05a 1072 fontset-spec idx)
92438d6e 1073 (setq idx (match-end 0))
09fd851a
KH
1074 (setq target (intern (match-string 1 fontset-spec)))
1075 (cond ((or (eq target 'ascii)
4b89b5e2
KH
1076 (memq target (char-table-extra-slot char-script-table 0)))
1077 (push (list target (match-string 2 fontset-spec)) fontlist))
1078 ((setq script (cdr (assq target charset-script-alist)))
09fd851a
KH
1079 (push (list script (match-string 2 fontset-spec)) fontlist))
1080 ((charsetp target)
1081 (push (list target (match-string 2 fontset-spec)) fontlist))))
92438d6e
KH
1082
1083 ;; Complement FONTLIST.
6ce70459 1084 (setq fontlist (x-complement-fontset-spec default-spec fontlist))
92438d6e
KH
1085
1086 ;; Create a fontset.
09fd851a 1087 (new-fontset name (nreverse fontlist))))
1f50fef9
KH
1088
1089(defun create-fontset-from-ascii-font (font &optional resolved-font
1090 fontset-name)
1091 "Create a fontset from an ASCII font FONT.
1092
33fac697
JB
1093Optional 2nd arg RESOLVED-FONT is a resolved name of FONT.
1094If omitted, `x-resolve-font-name' is called to get the resolved name.
1095At this time, if FONT is not available, an error is signaled.
1f50fef9 1096
33fac697 1097Optional 3rd arg FONTSET-NAME is a string to be used in
1f50fef9
KH
1098`<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
1099an appropriate name is generated automatically.
1100
1f50fef9 1101It returns a name of the created fontset."
6eca8d93 1102 (setq font (downcase font))
37a94e2f
KH
1103 (setq resolved-font
1104 (downcase (or resolved-font (x-resolve-font-name font))))
06f76f0d
KH
1105 (let ((xlfd (x-decompose-font-name resolved-font))
1106 fontset)
6eca8d93
KH
1107 (if fontset-name
1108 (setq fontset-name (downcase fontset-name))
87997c2c
KH
1109 (if (query-fontset "fontset-startup")
1110 (setq fontset-name
1111 (subst-char-in-string
1112 ?- ?_ (aref xlfd xlfd-regexp-registry-subnum) t))
1113 (setq fontset-name "startup")))
06f76f0d
KH
1114 (aset xlfd xlfd-regexp-registry-subnum
1115 (format "fontset-%s" fontset-name))
1f50fef9
KH
1116 (setq fontset (x-compose-font-name xlfd))
1117 (or (query-fontset fontset)
6eca8d93
KH
1118 (create-fontset-from-fontset-spec (concat fontset ", ascii:" font)))))
1119
4ed46869 1120\f
acfb10b8 1121;; Create standard fontset from 16 dots fonts which are the most widely
80d4ea92
KH
1122;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
1123;; specified here because FAMILY of those fonts are not "fixed" in
1124;; many cases.
acfb10b8 1125(defvar standard-fontset-spec
06f76f0d 1126 (purecopy "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard")
acfb10b8
KH
1127 "String of fontset spec of the standard fontset.
1128You have the biggest chance to display international characters
1129with correct glyphs by using the standard fontset.
4ed46869
KH
1130See the documentation of `create-fontset-from-fontset-spec' for the format.")
1131
37a94e2f 1132
4ed46869
KH
1133;; Create fontsets from X resources of the name `fontset-N (class
1134;; Fontset-N)' where N is integer 0, 1, ...
1135;; The values of the resources the string of the same format as
acfb10b8 1136;; `standard-fontset-spec'.
4ed46869 1137
aa360da1
GM
1138(declare-function x-get-resource "frame.c"
1139 (attribute class &optional component subclass))
1140
4ed46869
KH
1141(defun create-fontset-from-x-resource ()
1142 (let ((idx 0)
1143 fontset-spec)
cdd675ad
DL
1144 (while (setq fontset-spec (x-get-resource (format "fontset-%d" idx)
1145 (format "Fontset-%d" idx)))
1c9992b7 1146 (condition-case nil
4bd4e5bc
KH
1147 (create-fontset-from-fontset-spec fontset-spec t)
1148 (error (display-warning
1149 'initialization
1150 (format "Fontset-%d: invalid specification in X resource" idx)
1151 :warning)))
4ed46869
KH
1152 (setq idx (1+ idx)))))
1153
4ed46869
KH
1154;;
1155(provide 'fontset)
1156
1157;;; fontset.el ends here