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