Fix arg usage of format-decode-run-method (Bug#7488).
[bpt/emacs.git] / lisp / international / fontset.el
CommitLineData
60370d40 1;;; fontset.el --- commands for handling fontset
4ed46869 2
d4877ac1 3;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
114f9c96 4;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
7976eda0 5;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
114f9c96 6;; 2005, 2006, 2007, 2008, 2009, 2010
2fd125a3
KH
7;; National Institute of Advanced Industrial Science and Technology (AIST)
8;; Registration Number H14PRO021
6118a2b8 9;; Copyright (C) 2003, 2006
8f924df7
KH
10;; National Institute of Advanced Industrial Science and Technology (AIST)
11;; Registration Number H13PRO009
4ed46869 12
8135c753 13;; Keywords: mule, i18n, fontset
4ed46869
KH
14
15;; This file is part of GNU Emacs.
16
4936186e 17;; GNU Emacs is free software: you can redistribute it and/or modify
4ed46869 18;; it under the terms of the GNU General Public License as published by
4936186e
GM
19;; the Free Software Foundation, either version 3 of the License, or
20;; (at your option) any later version.
4ed46869
KH
21
22;; GNU Emacs is distributed in the hope that it will be useful,
23;; but WITHOUT ANY WARRANTY; without even the implied warranty of
24;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25;; GNU General Public License for more details.
26
27;; You should have received a copy of the GNU General Public License
4936186e 28;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
4ed46869 29
60370d40
PJ
30;;; Commentary:
31
4ed46869
KH
32;;; Code:
33
37a94e2f
KH
34;; Setup font-encoding-alist for all known encodings.
35
36(setq font-encoding-alist
ca0a881a
DN
37 (mapcar (lambda (arg)
38 (cons (purecopy (car arg)) (cdr arg)))
37a94e2f
KH
39 '(("iso8859-1$" . iso-8859-1)
40 ("iso8859-2$" . iso-8859-2)
41 ("iso8859-3$" . iso-8859-3)
42 ("iso8859-4$" . iso-8859-4)
43 ("iso8859-5$" . iso-8859-5)
44 ("iso8859-6$" . iso-8859-6)
45 ("iso8859-7$" . iso-8859-7)
46 ("iso8859-8$" . iso-8859-8)
47 ("iso8859-9$" . iso-8859-9)
48 ("iso8859-10$" . iso-8859-10)
49 ("iso8859-11$" . iso-8859-11)
50 ("iso8859-13$" . iso-8859-13)
51 ("iso8859-14$" . iso-8859-14)
52 ("iso8859-15$" . iso-8859-15)
cd5315ac 53 ("iso8859-16$" . iso-8859-16)
cd155f72 54 ("ascii-0$" . ascii)
37a94e2f 55 ("gb2312.1980" . chinese-gb2312)
28f2f887 56 ("gbk" . chinese-gbk)
26cdb3ee 57 ("gb18030" . (unicode . nil))
37a94e2f
KH
58 ("jisx0208.1978" . japanese-jisx0208-1978)
59 ("jisx0208" . japanese-jisx0208)
60 ("jisx0201" . jisx0201)
61 ("jisx0212" . japanese-jisx0212)
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"
fe243f8e 436 :otf '(arab nil (init medi fini 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,
8135c753
DL
704;; modified from industry defacto
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"))
0c4f97d0 808
e46947a5
KH
809;; CDAC fonts are actually smaller than their design sizes.
810(setq face-font-rescale-alist
1e8780b1 811 (list (cons (purecopy "-cdac$") 1.3)))
e46947a5 812
06f76f0d
KH
813(defvar x-font-name-charset-alist nil
814 "This variable has no meaning now. Just kept for backward compatibility.")
6fb8f8bd 815
4ed46869
KH
816;;; XLFD (X Logical Font Description) format handler.
817
818;; Define XLFD's field index numbers. ; field name
06f76f0d
KH
819(defconst xlfd-regexp-family-subnum 0) ; FOUNDRY and FAMILY
820(defconst xlfd-regexp-weight-subnum 1) ; WEIGHT_NAME
821(defconst xlfd-regexp-slant-subnum 2) ; SLANT
822(defconst xlfd-regexp-swidth-subnum 3) ; SETWIDTH_NAME
823(defconst xlfd-regexp-adstyle-subnum 4) ; ADD_STYLE_NAME
824(defconst xlfd-regexp-pixelsize-subnum 5) ; PIXEL_SIZE
825(defconst xlfd-regexp-pointsize-subnum 6) ; POINT_SIZE
826(defconst xlfd-regexp-resx-subnum 7) ; RESOLUTION_X
827(defconst xlfd-regexp-resy-subnum 8) ; RESOLUTION_Y
828(defconst xlfd-regexp-spacing-subnum 8) ; SPACING
829(defconst xlfd-regexp-avgwidth-subnum 10) ; AVERAGE_WIDTH
830(defconst xlfd-regexp-registry-subnum 11) ; REGISTRY and ENCODING
4ed46869
KH
831
832;; Regular expression matching against a fontname which conforms to
833;; XLFD (X Logical Font Description). All fields in XLFD should be
834;; not be omitted (but can be a wild card) to be matched.
835(defconst xlfd-tight-regexp
836 "^\
06f76f0d 837-\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
4ed46869 838-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
06f76f0d
KH
839-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*-[^-]*\\)$")
840
841;; Regular expression matching against a fontname which conforms to
842;; XLFD (X Logical Font Description). All fields in XLFD from FOUNDRY
8135c753 843;; to ADSTYLE, REGISTRY, and ENCODING should be not be omitted (but
06f76f0d
KH
844;; can be a wild card) to be matched.
845(defconst xlfd-style-regexp
846 "^\
847-\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-.*\
848-\\([^-]*-[^-]*\\)$")
4ed46869
KH
849
850;; List of field numbers of XLFD whose values are numeric.
851(defconst xlfd-regexp-numeric-subnums
06f76f0d
KH
852 (list xlfd-regexp-pixelsize-subnum ;5
853 xlfd-regexp-pointsize-subnum ;6
854 xlfd-regexp-resx-subnum ;7
855 xlfd-regexp-resy-subnum ;8
856 xlfd-regexp-avgwidth-subnum ;10
4ed46869
KH
857 ))
858
859(defun x-decompose-font-name (pattern)
92438d6e 860 "Decompose PATTERN into XLFD fields and return a vector of the fields.
06f76f0d 861The length of the vector is 12.
92438d6e
KH
862The FOUNDRY and FAMILY fields are concatinated and stored in the first
863element of the vector.
864The REGISTRY and ENCODING fields are concatinated and stored in the last
865element of the vector.
866
867Return nil if PATTERN doesn't conform to XLFD."
868 (if (string-match xlfd-tight-regexp pattern)
869 (let ((xlfd-fields (make-vector 12 nil)))
870 (dotimes (i 12)
871 (aset xlfd-fields i (match-string (1+ i) pattern)))
872 (dotimes (i 12)
873 (if (string-match "^[*-]+$" (aref xlfd-fields i))
874 (aset xlfd-fields i nil)))
875 xlfd-fields)))
441038a6 876
bb98ead9 877(defun x-compose-font-name (fields &optional reduce)
8135c753 878 "Compose X fontname from FIELDS.
a0451a71 879FIELDS is a vector of XLFD fields, of length 12.
441038a6 880If a field is nil, wild-card letter `*' is embedded.
33fac697
JB
881Optional argument REDUCE exists just for backward compatibility,
882and is always ignored."
6eca8d93 883 (concat "-" (mapconcat (lambda (x) (or x "*")) fields "-")))
bcb68cff 884
4fbe2b13
GM
885
886(defun x-must-resolve-font-name (xlfd-fields)
887 "Like `x-resolve-font-name', but always return a font name.
888XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
889If no font matching XLFD-FIELDS is available, successively replace
890parts of the font name pattern with \"*\" until some font is found.
891Value is name of that font."
892 (let ((ascii-font nil) (index 0))
06f76f0d 893 (while (and (null ascii-font) (<= index xlfd-regexp-registry-subnum))
4fbe2b13
GM
894 (let ((pattern (x-compose-font-name xlfd-fields)))
895 (condition-case nil
896 (setq ascii-font (x-resolve-font-name pattern))
897 (error
898 (message "Warning: no fonts matching `%s' available" pattern)
899 (aset xlfd-fields index "*")
900 (setq index (1+ index))))))
901 (unless ascii-font
37aad8f5 902 (error "No fonts found"))
4fbe2b13
GM
903 ascii-font))
904
905
6ce70459
KH
906(defun x-complement-fontset-spec (default-spec fontlist)
907 "Complement elements of FONTLIST based on DEFAULT-SPEC.
908DEFAULT-SPEC is a font-spec object providing default font properties.
92438d6e
KH
909FONTLIST is an alist of script names vs the corresponding font names.
910
6ce70459
KH
911The font names are parsed and unspecified font properties are
912given from DEFAULT-SPEC."
5db50cca 913 (let ((prop-list '(:foundry :family :weight :slant :width :adstyle :size)))
06f76f0d 914 (dolist (elt fontlist)
6ce70459
KH
915 (let ((spec (font-spec :name (cadr elt))))
916 (dolist (prop prop-list)
917 (let ((val (font-get spec prop)))
918 (or val
919 (font-put spec prop (font-get default-spec prop)))))
920 (setcar (cdr elt) spec)))
6eca8d93 921 fontlist))
4ed46869 922
35d4066a
KH
923(defun fontset-name-p (fontset)
924 "Return non-nil if FONTSET is valid as fontset name.
925A valid fontset name should conform to XLFD (X Logical Font Description)
33fac697 926with \"fontset\" in `<CHARSET_REGISTRY>' field."
35d4066a
KH
927 (and (string-match xlfd-tight-regexp fontset)
928 (string= (match-string (1+ xlfd-regexp-registry-subnum) fontset)
929 "fontset")))
930
aa360da1
GM
931(declare-function fontset-list "fontset.c" ())
932
4ed46869 933(defun generate-fontset-menu ()
8135c753
DL
934 "Return list to be appended to `x-fixed-font-alist'.
935Done when `mouse-set-font' is called."
d58b6a31
KH
936 (let (l)
937 (dolist (fontset (fontset-list))
938 (or (string-match "fontset-default$" fontset)
e096e30e 939 (string-match "fontset-auto[0-9]+$" fontset)
d58b6a31 940 (push (list (fontset-plain-name fontset) fontset) l)))
80ae5f3a 941 (cons "Fontset"
d58b6a31 942 (sort l #'(lambda (x y) (string< (car x) (car y)))))))
4ed46869 943
aa360da1
GM
944(declare-function query-fontset "fontset.c" (pattern &optional regexpp))
945
4ed46869
KH
946(defun fontset-plain-name (fontset)
947 "Return a plain and descriptive name of FONTSET."
494ec9bc
KH
948 (if (not (setq fontset (query-fontset fontset)))
949 (error "Invalid fontset: %s" fontset))
4ed46869
KH
950 (let ((xlfd-fields (x-decompose-font-name fontset)))
951 (if xlfd-fields
87997c2c
KH
952 (let ((family (aref xlfd-fields xlfd-regexp-family-subnum))
953 (weight (aref xlfd-fields xlfd-regexp-weight-subnum))
4ed46869
KH
954 (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
955 (swidth (aref xlfd-fields xlfd-regexp-swidth-subnum))
956 (size (aref xlfd-fields xlfd-regexp-pixelsize-subnum))
06f76f0d 957 (nickname (aref xlfd-fields xlfd-regexp-registry-subnum))
4ed46869 958 name)
06f76f0d 959 (if (not (string-match "^fontset-\\(.*\\)$" nickname))
87997c2c
KH
960 (setq nickname family)
961 (setq nickname (match-string 1 nickname)))
09fd851a 962 (if (and size (> (string-to-number size) 0))
87997c2c
KH
963 (setq name (format "%s: %s-dot" nickname size))
964 (setq name nickname))
965 (and weight
966 (cond ((string-match "^medium$" weight)
967 (setq name (concat name " " "medium")))
968 ((string-match "^bold$\\|^demibold$" weight)
969 (setq name (concat name " " weight)))))
970 (and slant
971 (cond ((string-match "^i$" slant)
972 (setq name (concat name " " "italic")))
973 ((string-match "^o$" slant)
974 (setq name (concat name " " "slant")))
975 ((string-match "^ri$" slant)
976 (setq name (concat name " " "reverse italic")))
977 ((string-match "^ro$" slant)
978 (setq name (concat name " " "reverse slant")))))
979 name)
4ed46869
KH
980 fontset)))
981
37a94e2f 982(defvar charset-script-alist
8a020f4c 983 '((ascii . latin)
37a94e2f
KH
984 (latin-iso8859-1 . latin)
985 (latin-iso8859-2 . latin)
986 (latin-iso8859-3 . latin)
987 (latin-iso8859-4 . latin)
988 (latin-iso8859-9 . latin)
989 (latin-iso8859-10 . latin)
990 (latin-iso8859-13 . latin)
991 (latin-iso8859-14 . latin)
992 (latin-iso8859-15 . latin)
993 (latin-iso8859-16 . latin)
994 (latin-jisx0201 . latin)
995 (thai-tis620 . thai)
996 (cyrillic-iso8859-5 . cyrillic)
997 (arabic-iso8859-6 . arabic)
998 (greek-iso8859-7 . latin)
999 (hebrew-iso8859-8 . latin)
8a020f4c 1000 (katakana-jisx0201 . kana)
37a94e2f 1001 (chinese-gb2312 . han)
28f2f887 1002 (chinese-gbk . han)
c7606603
KH
1003 (gb18030-2-byte . han)
1004 (gb18030-4-byte-bmp . han)
1005 (gb18030-4-byte-ext-1 . han)
1006 (gb18030-4-byte-ext-2 . han)
1007 (gb18030-4-byte-smp . han)
37a94e2f
KH
1008 (chinese-big5-1 . han)
1009 (chinese-big5-2 . han)
1010 (chinese-cns11643-1 . han)
1011 (chinese-cns11643-2 . han)
1012 (chinese-cns11643-3 . han)
1013 (chinese-cns11643-4 . han)
1014 (chinese-cns11643-5 . han)
1015 (chinese-cns11643-6 . han)
1016 (chinese-cns11643-7 . han)
1017 (japanese-jisx0208 . han)
1018 (japanese-jisx0208-1978 . han)
1019 (japanese-jisx0212 . han)
1020 (japanese-jisx0213-1 . han)
1021 (japanese-jisx0213-2 . han)
8a020f4c 1022 (korean-ksc5601 . hangul)
37a94e2f
KH
1023 (chinese-sisheng . bopomofo)
1024 (vietnamese-viscii-lower . latin)
1025 (vietnamese-viscii-upper . latin)
1026 (arabic-digit . arabic)
1027 (arabic-1-column . arabic)
1028 (arabic-2-column . arabic)
1029 (indian-is13194 . devanagari)
1030 (indian-glyph . devanagari)
1031 (indian-1-column . devanagari)
1032 (indian-2-column . devanagari)
1033 (tibetan-1-column . tibetan))
1034 "Alist of charsets vs the corresponding most appropriate scripts.
1035
1036This alist is used by the function `create-fontset-from-fontset-spec'
1037to map charsets to scripts.")
c963bbc2 1038
6fb8f8bd 1039(defun create-fontset-from-fontset-spec (fontset-spec
bb98ead9 1040 &optional style-variant noerror)
4ed46869
KH
1041 "Create a fontset from fontset specification string FONTSET-SPEC.
1042FONTSET-SPEC is a string of the format:
6fcec85e 1043 FONTSET-NAME,SCRIPT-NAME0:FONT-NAME0,SCRIPT-NAME1:FONT-NAME1, ...
494ec9bc 1044Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
bb98ead9 1045
92438d6e
KH
1046When a frame uses the fontset as the `font' parameter, the frame's
1047default font name is derived from FONTSET-NAME by substituting
1048\"iso8859-1\" for the tail part \"fontset-XXX\". But, if SCRIPT-NAMEn
1049is \"ascii\", use the corresponding FONT-NAMEn as the default font
1050name.
bb98ead9 1051
a0451a71
MB
1052Optional 2nd and 3rd arguments exist just for backward compatibility,
1053and are ignored.
1f50fef9 1054
37a94e2f
KH
1055It returns a name of the created fontset.
1056
1057For backward compatibility, SCRIPT-NAME may be a charset name, in
1058which case, the corresponding script is decided by the variable
1059`charset-script-alist' (which see)."
92438d6e 1060 (or (string-match "^[^,]+" fontset-spec)
494ec9bc
KH
1061 (error "Invalid fontset spec: %s" fontset-spec))
1062 (let ((idx (match-end 0))
1063 (name (match-string 0 fontset-spec))
6ce70459
KH
1064 default-spec target script fontlist)
1065 (or (string-match xlfd-tight-regexp name)
92438d6e 1066 (error "Fontset name \"%s\" not conforming to XLFD" name))
6ce70459 1067 (setq default-spec (font-spec :name name))
92438d6e 1068 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
6fcec85e 1069 (while (string-match "[, \t\n]*\\([^:]+\\):[ \t]*\\([^,]+\\)"
31f5d05a 1070 fontset-spec idx)
92438d6e 1071 (setq idx (match-end 0))
09fd851a
KH
1072 (setq target (intern (match-string 1 fontset-spec)))
1073 (cond ((or (eq target 'ascii)
4b89b5e2
KH
1074 (memq target (char-table-extra-slot char-script-table 0)))
1075 (push (list target (match-string 2 fontset-spec)) fontlist))
1076 ((setq script (cdr (assq target charset-script-alist)))
09fd851a
KH
1077 (push (list script (match-string 2 fontset-spec)) fontlist))
1078 ((charsetp target)
1079 (push (list target (match-string 2 fontset-spec)) fontlist))))
92438d6e
KH
1080
1081 ;; Complement FONTLIST.
6ce70459 1082 (setq fontlist (x-complement-fontset-spec default-spec fontlist))
92438d6e
KH
1083
1084 ;; Create a fontset.
09fd851a 1085 (new-fontset name (nreverse fontlist))))
1f50fef9
KH
1086
1087(defun create-fontset-from-ascii-font (font &optional resolved-font
1088 fontset-name)
1089 "Create a fontset from an ASCII font FONT.
1090
33fac697
JB
1091Optional 2nd arg RESOLVED-FONT is a resolved name of FONT.
1092If omitted, `x-resolve-font-name' is called to get the resolved name.
1093At this time, if FONT is not available, an error is signaled.
1f50fef9 1094
33fac697 1095Optional 3rd arg FONTSET-NAME is a string to be used in
1f50fef9
KH
1096`<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
1097an appropriate name is generated automatically.
1098
1f50fef9 1099It returns a name of the created fontset."
6eca8d93 1100 (setq font (downcase font))
37a94e2f
KH
1101 (setq resolved-font
1102 (downcase (or resolved-font (x-resolve-font-name font))))
06f76f0d
KH
1103 (let ((xlfd (x-decompose-font-name resolved-font))
1104 fontset)
6eca8d93
KH
1105 (if fontset-name
1106 (setq fontset-name (downcase fontset-name))
87997c2c
KH
1107 (if (query-fontset "fontset-startup")
1108 (setq fontset-name
1109 (subst-char-in-string
1110 ?- ?_ (aref xlfd xlfd-regexp-registry-subnum) t))
1111 (setq fontset-name "startup")))
06f76f0d
KH
1112 (aset xlfd xlfd-regexp-registry-subnum
1113 (format "fontset-%s" fontset-name))
1f50fef9
KH
1114 (setq fontset (x-compose-font-name xlfd))
1115 (or (query-fontset fontset)
6eca8d93
KH
1116 (create-fontset-from-fontset-spec (concat fontset ", ascii:" font)))))
1117
4ed46869 1118\f
acfb10b8 1119;; Create standard fontset from 16 dots fonts which are the most widely
80d4ea92
KH
1120;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
1121;; specified here because FAMILY of those fonts are not "fixed" in
1122;; many cases.
acfb10b8 1123(defvar standard-fontset-spec
06f76f0d 1124 (purecopy "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard")
acfb10b8
KH
1125 "String of fontset spec of the standard fontset.
1126You have the biggest chance to display international characters
1127with correct glyphs by using the standard fontset.
4ed46869
KH
1128See the documentation of `create-fontset-from-fontset-spec' for the format.")
1129
37a94e2f 1130
4ed46869
KH
1131;; Create fontsets from X resources of the name `fontset-N (class
1132;; Fontset-N)' where N is integer 0, 1, ...
1133;; The values of the resources the string of the same format as
acfb10b8 1134;; `standard-fontset-spec'.
4ed46869 1135
aa360da1
GM
1136(declare-function x-get-resource "frame.c"
1137 (attribute class &optional component subclass))
1138
4ed46869
KH
1139(defun create-fontset-from-x-resource ()
1140 (let ((idx 0)
1141 fontset-spec)
cdd675ad
DL
1142 (while (setq fontset-spec (x-get-resource (format "fontset-%d" idx)
1143 (format "Fontset-%d" idx)))
1c9992b7 1144 (condition-case nil
4bd4e5bc
KH
1145 (create-fontset-from-fontset-spec fontset-spec t)
1146 (error (display-warning
1147 'initialization
1148 (format "Fontset-%d: invalid specification in X resource" idx)
1149 :warning)))
4ed46869
KH
1150 (setq idx (1+ idx)))))
1151
4ed46869
KH
1152;;
1153(provide 'fontset)
1154
cbee283d 1155;; arch-tag: bb53e629-0234-403c-950e-551e61554849
4ed46869 1156;;; fontset.el ends here