]> code.delx.au - gnu-emacs/blob - lisp/international/fontset.el
cdbaade73abb15791db0a6bb6c0705e9b972c8a2
[gnu-emacs] / lisp / international / fontset.el
1 ;;; fontset.el --- commands for handling fontset
2
3 ;; Copyright (C) 1997-2015 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
6 ;; National Institute of Advanced Industrial Science and Technology (AIST)
7 ;; Registration Number H14PRO021
8 ;; Copyright (C) 2003, 2006
9 ;; National Institute of Advanced Industrial Science and Technology (AIST)
10 ;; Registration Number H13PRO009
11
12 ;; Keywords: mule, i18n, fontset
13
14 ;; This file is part of GNU Emacs.
15
16 ;; GNU Emacs is free software: you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation, either version 3 of the License, or
19 ;; (at your option) any later version.
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
27 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28
29 ;;; Commentary:
30
31 ;;; Code:
32
33 ;; Setup font-encoding-alist for all known encodings.
34
35 (setq font-encoding-alist
36 (mapcar (lambda (arg)
37 (cons (purecopy (car arg)) (cdr arg)))
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)
52 ("iso8859-16$" . iso-8859-16)
53 ("ascii-0$" . ascii)
54 ("gb2312.1980" . chinese-gb2312)
55 ("gbk" . chinese-gbk)
56 ("gb18030" . (unicode . nil))
57 ("jisx0208.1978" . japanese-jisx0208-1978)
58 ("jisx0208" . japanese-jisx0208)
59 ("jisx0201" . jisx0201)
60 ("jisx0212" . japanese-jisx0212)
61 ("ksx1001" . korean-ksc5601)
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)
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)
77 ("big5" . big5)
78 ("viscii" . viscii)
79 ("tis620" . tis620-2533)
80 ("microsoft-cp1251" . windows-1251)
81 ("koi8-r" . koi8-r)
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)
90 ("mulearabic-0" . arabic-digit)
91 ("mulearabic-1" . arabic-1-column)
92 ("mulearabic-2" . arabic-2-column)
93 ("muleipa" . ipa)
94 ("ethiopic-unicode" . (unicode-bmp . ethiopic))
95 ("is13194-devanagari" . indian-is13194)
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)
116 ("muleindian-2" . indian-2-column)
117 ("muleindian-1" . indian-1-column)
118 ("mulelao-1" . mule-lao)
119 ("muletibetan-2" . tibetan)
120 ("muletibetan-0" . tibetan)
121 ("muletibetan-1" . tibetan-1-column))))
122
123 (defvar font-encoding-charset-alist)
124
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
148 (setq script-representative-chars
149 '((latin ?A ?Z ?a ?z #x00C0 #x0100 #x0180 #x1e00)
150 (phonetic #x250 #x283)
151 (greek #x3A9)
152 (coptic #x3E2)
153 (cyrillic #x42F)
154 (armenian #x531)
155 (hebrew #x5D0)
156 (vai #xA500)
157 (arabic #x628)
158 (syriac #x710)
159 (thaana #x78C)
160 (devanagari #x915)
161 (bengali #x995)
162 (gurmukhi #xA15)
163 (gujarati #xA95)
164 (oriya #xB15)
165 (tamil #xB95)
166 (telugu #xC15)
167 (kannada #xC95)
168 (malayalam #xD15)
169 (sinhala #xD95)
170 (thai #xE17)
171 (lao #xEA5)
172 (tibetan #xF40)
173 (burmese #x1000)
174 (georgian #x10D3)
175 (ethiopic #x1208)
176 (cherokee #x13B6)
177 (canadian-aboriginal #x14C0)
178 (ogham #x168F)
179 (runic #x16A0)
180 (khmer #x1780)
181 (mongolian #x1826)
182 (symbol . [#x201C #x2200 #x2500])
183 (braille #x2800)
184 (ideographic-description #x2FF0)
185 (cjk-misc #x300E)
186 (kana #x304B)
187 (bopomofo #x3105)
188 (kanbun #x319D)
189 (han #x5B57)
190 (yi #xA288)
191 (cham #xAA00)
192 (tai-viet #xAA80)
193 (hangul #xAC00)
194 (linear-b #x10000)
195 (aegean-number #x10100)
196 (ancient-greek-number #x10140)
197 (ancient-symbol #x10190)
198 (phaistos-disc #x101D0)
199 (lycian #x10280)
200 (carian #x102A0)
201 (old-italic #x10300)
202 (ugaritic #x10380)
203 (old-permic #x10350)
204 (old-persian #x103A0)
205 (deseret #x10400)
206 (shavian #x10450)
207 (osmanya #x10480)
208 (elbasan #x10500)
209 (caucasian-albanian #x10530)
210 (linear-a #x10600)
211 (cypriot-syllabary #x10800)
212 (palmyrene #x10860)
213 (nabataean #x10880)
214 (phoenician #x10900)
215 (lydian #x10920)
216 (kharoshthi #x10A00)
217 (manichaean #x10AC0)
218 (mahajani #x11150)
219 (sinhala-archaic-number #x111E1)
220 (khojki #x11200)
221 (khudawadi #x112B0)
222 (grantha #x11305)
223 (tirhuta #x11481)
224 (siddham #x11580)
225 (modi #x11600)
226 (takri #x11680)
227 (warang-citi #x118A1)
228 (pau-cin-hau #x11AC0)
229 (cuneiform #x12000)
230 (cuneiform-numbers-and-punctuation #x12400)
231 (mro #x16A40)
232 (bassa-vah #x16AD0)
233 (pahawh-hmong #x16B11)
234 (duployan-shorthand #x1BC20)
235 (byzantine-musical-symbol #x1D000)
236 (musical-symbol #x1D100)
237 (ancient-greek-musical-notation #x1D200)
238 (tai-xuan-jing-symbol #x1D300)
239 (counting-rod-numeral #x1D360)
240 (mende-kikakui #x1E810)
241 (mahjong-tile #x1F000)
242 (domino-tile #x1F030)))
243
244 (defvar otf-script-alist)
245
246 ;; The below was synchronized with the latest Jan 3, 2013 version of
247 ;; https://www.microsoft.com/typography/otspec/scripttags.htm.
248 (setq otf-script-alist
249 '((arab . arabic)
250 (armi . aramaic)
251 (armn . armenian)
252 (avst . avestan)
253 (bali . balinese)
254 (bamu . bamum)
255 (batk . batak)
256 (bng2 . bengali)
257 (beng . bengali)
258 (bopo . bopomofo)
259 (brai . braille)
260 (brah . brahmi)
261 (bugi . buginese)
262 (buhd . buhid)
263 (byzm . byzantine-musical-symbol)
264 (cans . canadian-aboriginal)
265 (cari . carian)
266 (cakm . chakma)
267 (cham . cham)
268 (cher . cherokee)
269 (copt . coptic)
270 (xsux . cuneiform)
271 (cprt . cypriot)
272 (cyrl . cyrillic)
273 (dsrt . deseret)
274 (deva . devanagari)
275 (dev2 . devanagari)
276 (egyp . egyptian)
277 (ethi . ethiopic)
278 (geor . georgian)
279 (glag . glagolitic)
280 (goth . gothic)
281 (grek . greek)
282 (gujr . gujarati)
283 (gjr2 . gujarati)
284 (guru . gurmukhi)
285 (gur2 . gurmukhi)
286 (hani . han)
287 (hang . hangul)
288 (jamo . hangul)
289 (hano . hanunoo)
290 (hebr . hebrew)
291 (phli . inscriptional-pahlavi)
292 (prti . inscriptional-parthian)
293 (java . javanese)
294 (kthi . kaithi)
295 (kana . kana) ; Hiragana
296 (knda . kannada)
297 (knd2 . kannada)
298 (kali . kayah-li)
299 (khar . kharoshthi)
300 (khmr . khmer)
301 (lao\ . lao)
302 (latn . latin)
303 (lepc . lepcha)
304 (limb . limbu)
305 (linb . linear_b)
306 (lisu . lisu)
307 (lyci . lycian)
308 (lydi . lydian)
309 (mlym . malayalam)
310 (mlm2 . malayalam)
311 (mand . mandaic)
312 (math . mathematical)
313 (mtei . meetei-mayek)
314 (merc . meroitic)
315 (mero . meroitic)
316 (mong . mongolian)
317 (musc . musical-symbol)
318 (mym2 . burmese)
319 (mymr . burmese)
320 (nko\ . nko)
321 (ogam . ogham)
322 (olck . ol-chiki)
323 (ital . old_italic)
324 (xpeo . old_persian)
325 (sarb . old-south-arabian)
326 (orkh . old-turkic)
327 (orya . oriya)
328 (ory2 . oriya)
329 (osma . osmanya)
330 (phag . phags-pa)
331 (phnx . phoenician)
332 (rjng . rejang)
333 (runr . runic)
334 (samr . samaritan)
335 (saur . saurashtra)
336 (shrd . sharada)
337 (shaw . shavian)
338 (sinh . sinhala)
339 (sora . sora-sompeng)
340 (sund . sundanese)
341 (sylo . syloti_nagri)
342 (syrc . syriac)
343 (tglg . tagalog)
344 (tagb . tagbanwa)
345 (tale . tai_le)
346 (talu . tai-lue)
347 (lana . tai-tham)
348 (tavt . tai-viet)
349 (takr . takri)
350 (taml . tamil)
351 (tml2 . tamil)
352 (telu . telugu)
353 (tel2 . telugu)
354 (thaa . thaana)
355 (thai . thai)
356 (tibt . tibetan)
357 (tfng . tifinagh)
358 (ugar . ugaritic)
359 (vai\ . vai)
360 (yi\ \ . yi)))
361
362 ;; Set standard fontname specification of characters in the default
363 ;; fontset to find an appropriate font for each script/charset. The
364 ;; specification has the form ((SCRIPT FONT-SPEC ...) ...), where
365 ;; FONT-SPEC is:
366 ;; a cons (FAMILY . REGISTRY),
367 ;; or a string FONT-NAME,
368 ;; or an object created by `font-spec'.
369 ;;
370 ;; FAMILY may be nil, in which case, the corresponding name of
371 ;; default face is used. If REGISTRY contains a character `-', the
372 ;; string before that is embedded in `CHARSET_REGISTRY' field, and the
373 ;; string after that is embedded in `CHARSET_ENCODING' field. If it
374 ;; does not contain `-', the whole string is embedded in
375 ;; `CHARSET_REGISTRY' field, and a wild card character `*' is embedded
376 ;; in `CHARSET_ENCODING' field.
377 ;;
378 ;; SCRIPT is a symbol that appears as an element of the char table
379 ;; `char-script-table'. SCRIPT may be a charset specifying the range
380 ;; of characters.
381
382 (declare-function new-fontset "fontset.c" (name fontlist))
383 (declare-function set-fontset-font "fontset.c"
384 (name target font-spec &optional frame add))
385
386 (eval-when-compile
387
388 ;; Build data to initialize the default fontset at compile time to
389 ;; avoid loading charsets that won't be necessary at runtime.
390
391 ;; The value is (CJK-REGISTRY-VECTOR TARGET-SPEC ...), where
392 ;; CJK-REGISTRY-VECTOR is ["JISX0208.1983-0" "GB2312.1980-0" ...],
393 ;; TARGET-SPEC is (TARGET . BITMASK) or (TARGET SPEC ...),
394 ;; TARGET is CHAR or (FROM-CHAR . TO-CHAR),
395 ;; BITMASK is a bitmask of indices to CJK-REGISTRY-VECTOR,
396 ;; SPEC is a list of arguments to font-spec.
397
398 (defmacro build-default-fontset-data ()
399 (let* (;; CHARSET-REGISTRY CHARSET FROM-CODE TO-CODE
400 (cjk '(("JISX0208.1983-0" japanese-jisx0208 #x2121 #x287E)
401 ("GB2312.1980-0" chinese-gb2312 #x2121 #x297E)
402 ("BIG5-0" big5 #xA140 #xA3FE)
403 ("CNS11643.1992-1" chinese-cns11643-1 #x2121 #x427E)
404 ("KSC5601.1987-0" korean-ksc5601 #x2121 #x2C7E)))
405 (scripts '((tibetan
406 (:registry "iso10646-1" :otf (tibt nil (ccmp blws abvs)))
407 (:family "mtib" :registry "iso10646-1")
408 (:registry "muletibetan-2"))
409 (ethiopic
410 (:registry "iso10646-1" :script ethiopic)
411 (:registry "ethiopic-unicode"))
412 (phonetic
413 (:registry "iso10646-1" :script phonetic)
414 (:registry "MuleIPA-1")
415 (:registry "iso10646-1"))))
416 (cjk-table (make-char-table nil))
417 (script-coverage
418 #'(lambda (script)
419 (let ((coverage))
420 (map-char-table
421 #'(lambda (range val)
422 (when (eq val script)
423 (if (consp range)
424 (setq range (cons (car range) (cdr range))))
425 (push range coverage)))
426 char-script-table)
427 coverage)))
428 (data (list (vconcat (mapcar 'car cjk))))
429 (i 0))
430 (dolist (elt cjk)
431 (let ((mask (lsh 1 i)))
432 (map-charset-chars
433 #'(lambda (range _arg)
434 (let ((from (car range)) (to (cdr range)))
435 (if (< to #x110000)
436 (while (<= from to)
437 (or (memq (aref char-script-table from)
438 '(kana hangul han cjk-misc))
439 (aset cjk-table from
440 (logior (or (aref cjk-table from) 0) mask)))
441 (setq from (1+ from))))))
442 (nth 1 elt) nil (nth 2 elt) (nth 3 elt)))
443 (setq i (1+ i)))
444 (map-char-table
445 #'(lambda (range val)
446 (if (consp range)
447 (setq range (cons (car range) (cdr range))))
448 (push (cons range val) data))
449 cjk-table)
450 (dolist (script scripts)
451 (dolist (range (funcall script-coverage (car script)))
452 (push (cons range (cdr script)) data)))
453 `(quote ,(nreverse data))))
454 )
455
456 (defun setup-default-fontset ()
457 "Setup the default fontset."
458 (new-fontset
459 "fontset-default"
460 `(;; for each script
461 (latin (nil . "ISO8859-1")
462 (nil . "ISO8859-2")
463 (nil . "ISO8859-3")
464 (nil . "ISO8859-4")
465 (nil . "ISO8859-9")
466 (nil . "ISO8859-10")
467 (nil . "ISO8859-13")
468 (nil . "ISO8859-14")
469 (nil . "ISO8859-15")
470 (nil . "ISO8859-16")
471 (nil . "VISCII1.1-1")
472 ,(font-spec :registry "iso10646-1" :script 'latin))
473
474 (thai ,(font-spec :registry "iso10646-1" :otf '(thai nil nil (mark)))
475 ,(font-spec :registry "iso10646-1" :script 'thai)
476 (nil . "TIS620*")
477 (nil . "ISO8859-11"))
478
479 (devanagari ,(font-spec :registry "iso10646-1" :otf '(dev2 nil (rphf)))
480 ,(font-spec :registry "iso10646-1" :otf '(deva nil (rphf)))
481 (nil . "iso10646.indian-1"))
482 (bengali ,(font-spec :registry "iso10646-1" :otf '(bng2 nil (rphf)))
483 ,(font-spec :registry "iso10646-1" :otf '(beng nil (rphf))))
484 (gurmukhi ,(font-spec :registry "iso10646-1" :otf '(gur2 nil (blwf)))
485 ,(font-spec :registry "iso10646-1" :otf '(guru nil (blwf))))
486 (gujarati ,(font-spec :registry "iso10646-1" :otf '(gjr2 nil (rphf)))
487 ,(font-spec :registry "iso10646-1" :otf '(gujr nil (rphf))))
488 (oriya ,(font-spec :registry "iso10646-1" :otf '(ory2 nil (rphf)))
489 ,(font-spec :registry "iso10646-1" :otf '(orya nil (rphf))))
490 (tamil ,(font-spec :registry "iso10646-1" :otf '(tml2 nil (akhn)))
491 ,(font-spec :registry "iso10646-1" :otf '(taml nil (akhn))))
492 (telugu ,(font-spec :registry "iso10646-1" :otf '(tel2 nil (blwf)))
493 ,(font-spec :registry "iso10646-1" :otf '(telu nil (blwf))))
494 (kannada ,(font-spec :registry "iso10646-1" :otf '(knd2 nil (rphf)))
495 ,(font-spec :registry "iso10646-1" :otf '(knda nil (rphf))))
496 (sinhala ,(font-spec :registry "iso10646-1" :otf '(sinh nil (akhn))))
497 (malayalam ,(font-spec :registry "iso10646-1" :otf '(mlm2 nil (akhn)))
498 ,(font-spec :registry "iso10646-1" :otf '(mlym nil (akhn))))
499
500 (burmese ,(font-spec :registry "iso10646-1" :otf '(mym2 nil nil))
501 ,(font-spec :registry "iso10646-1" :otf '(mymr nil nil))
502 ,(font-spec :registry "iso10646-1" :script 'burmese))
503
504 (lao ,(font-spec :registry "iso10646-1" :otf '(lao\ nil nil (mark)))
505 ,(font-spec :registry "iso10646-1" :script 'lao)
506 (nil . "MuleLao-1"))
507
508 (tai-viet ("TaiViet" . "iso10646-1"))
509
510 (greek ,(font-spec :registry "iso10646-1" :script 'greek)
511 (nil . "ISO8859-7"))
512
513 (cyrillic ,(font-spec :registry "iso10646-1" :script 'cyrillic)
514 (nil . "ISO8859-5")
515 (nil . "microsoft-cp1251")
516 (nil . "koi8-r"))
517
518 (arabic ,(font-spec :registry "iso10646-1"
519 :otf '(arab nil (init medi fina liga)))
520 (nil . "MuleArabic-0")
521 (nil . "MuleArabic-1")
522 (nil . "MuleArabic-2")
523 (nil . "ISO8859-6"))
524
525 (hebrew ,(font-spec :registry "iso10646-1" :script 'hebrew)
526 (nil . "ISO8859-8"))
527
528 (khmer ,(font-spec :registry "iso10646-1" :otf '(khmr nil (pres))))
529
530 (kana (nil . "JISX0208*")
531 (nil . "GB2312.1980-0")
532 (nil . "KSC5601.1987*")
533 (nil . "JISX0201*")
534 (nil . "JISX0213.2000-1")
535 (nil . "JISX0213.2004-1")
536 ,(font-spec :registry "iso10646-1" :script 'kana))
537
538 (bopomofo ,(font-spec :registry "iso10646-1" :script 'bopomofo)
539 (nil . "sisheng_cwnn-0"))
540
541 (han (nil . "GB2312.1980-0")
542 (nil . "JISX0208*")
543 (nil . "JISX0212*")
544 (nil . "big5*")
545 (nil . "KSC5601.1987*")
546 (nil . "CNS11643.1992-1")
547 (nil . "CNS11643.1992-2")
548 (nil . "CNS11643.1992-3")
549 (nil . "CNS11643.1992-4")
550 (nil . "CNS11643.1992-5")
551 (nil . "CNS11643.1992-6")
552 (nil . "CNS11643.1992-7")
553 (nil . "gbk-0")
554 (nil . "gb18030")
555 (nil . "JISX0213.2000-1")
556 (nil . "JISX0213.2000-2")
557 (nil . "JISX0213.2004-1")
558 ,(font-spec :registry "iso10646-1" :lang 'ja)
559 ,(font-spec :registry "iso10646-1" :lang 'zh))
560
561 (cjk-misc (nil . "GB2312.1980-0")
562 (nil . "JISX0208*")
563 (nil . "JISX0212*")
564 (nil . "big5*")
565 (nil . "KSC5601.1987*")
566 (nil . "CNS11643.1992-1")
567 (nil . "CNS11643.1992-2")
568 (nil . "CNS11643.1992-3")
569 (nil . "CNS11643.1992-4")
570 (nil . "CNS11643.1992-5")
571 (nil . "CNS11643.1992-6")
572 (nil . "CNS11643.1992-7")
573 (nil . "gbk-0")
574 (nil . "gb18030")
575 (nil . "JISX0213.2000-1")
576 (nil . "JISX0213.2000-2")
577 ,(font-spec :registry "iso10646-1" :lang 'ja)
578 ,(font-spec :registry "iso10646-1" :lang 'zh))
579
580 (hangul (nil . "KSC5601.1987-0")
581 ,(font-spec :registry "iso10646-1" :lang 'ko))
582
583 ;; for each charset
584 (ascii (nil . "ISO8859-1"))
585 (arabic-digit ("*" . "MuleArabic-0"))
586 (arabic-1-column ("*" . "MuleArabic-1"))
587 (arabic-2-column ("*" . "MuleArabic-2"))
588 (indian-is13194 (nil . "is13194-devanagari"))
589 (indian-1-column ("*" . "muleindian-2"))
590 ;; Indian CDAC
591 (devanagari-cdac (nil . "Devanagari-CDAC"))
592 (sanskrit-cdac (nil . "Sanskrit-CDAC"))
593 (bengali-cdac (nil . "Bengali-CDAC"))
594 (assamese-cdac (nil . "Assamese-CDAC"))
595 (punjabi-cdac (nil . "Punjabi-CDAC"))
596 (gujarati-cdac (nil . "Gujarati-CDAC"))
597 (oriya-cdac (nil . "Oriya-CDAC"))
598 (tamil-cdac (nil . "Tamil-CDAC"))
599 (telugu-cdac (nil . "Telugu-CDAC"))
600 (kannada-cdac (nil . "Kannada-CDAC"))
601 (malayalam-cdac (nil . "Malayalam-CDAC"))
602 ;; Indian AKRUTI
603 (devanagari-akruti (nil . "Devanagari-Akruti"))
604 (bengali-akruti (nil . "Bengali-Akruti"))
605 (punjabi-akruti (nil . "Punjabi-Akruti"))
606 (gujarati-akruti (nil . "Gujarati-Akruti"))
607 (oriya-akruti (nil . "Oriya-Akruti"))
608 (tamil-akruti (nil . "Tamil-Akruti"))
609 (telugu-akruti (nil . "Telugu-Akruti"))
610 (kannada-akruti (nil . "Kannada-Akruti"))
611 (malayalam-akruti (nil . "Malayalam-Akruti"))
612
613 ;; Fallback fonts
614 (nil (nil . "gb2312.1980")
615 (nil . "gbk-0")
616 (nil . "gb18030")
617 (nil . "jisx0208")
618 (nil . "ksc5601.1987")
619 (nil . "CNS11643.1992-1")
620 (nil . "CNS11643.1992-2")
621 (nil . "CNS11643.1992-3")
622 (nil . "CNS11643.1992-4")
623 (nil . "CNS11643.1992-5")
624 (nil . "CNS11643.1992-6")
625 (nil . "CNS11643.1992-7")
626 (nil . "big5")
627 (nil . "jisx0213.2000-1")
628 (nil . "jisx0213.2004-1")
629 (nil . "jisx0212"))
630 ))
631
632 ;; For simple scripts
633 (dolist (script '(phonetic
634 armenian
635 syriac
636 thaana
637 georgian
638 cherokee
639 canadian-aboriginal
640 ogham
641 runic
642 symbol
643 braille
644 yi
645 aegean-number
646 ancient-greek-number
647 ancient-symbol
648 phaistos-disc
649 lycian
650 carian
651 old-italic
652 ugaritic
653 old-persian
654 deseret
655 shavian
656 osmanya
657 cypriot-syllabary
658 phoenician
659 lydian
660 kharoshthi
661 cuneiform
662 cuneiform-numbers-and-punctuation
663 byzantine-musical-symbol
664 musical-symbol
665 ancient-greek-musical-notation
666 tai-xuan-jing-symbol
667 counting-rod-numeral
668 mahjong-tile
669 domino-tile))
670 (set-fontset-font "fontset-default"
671 script (font-spec :registry "iso10646-1" :script script)
672 nil 'append))
673
674 ;; Special settings for `MATHEMATICAL (U+1D400..U+1D7FF)'.
675 (dolist (math-subgroup '((#x1D400 #x1D433 mathematical-bold)
676 (#x1D434 #x1D467 mathematical-italic)
677 (#x1D468 #x1D49B mathematical-bold-italic)
678 (#x1D49C #x1D4CF mathematical-script)
679 (#x1D4D0 #x1D503 mathematical-bold-script)
680 (#x1D504 #x1D537 mathematical-fraktur)
681 (#x1D538 #x1D56B mathematical-double-struck)
682 (#x1D56C #x1D59F mathematical-bold-fraktur)
683 (#x1D5A0 #x1D5D3 mathematical-sans-serif)
684 (#x1D5D4 #x1D607 mathematical-sans-serif-bold)
685 (#x1D608 #x1D63B mathematical-sans-serif-italic)
686 (#x1D63C #x1D66F mathematical-sans-serif-bold-italic)
687 (#x1D670 #x1D6A3 mathematical-monospace)
688 (#x1D6A4 #x1D6A5 mathematical-italic)
689 (#x1D6A8 #x1D6E1 mathematical-bold)
690 (#x1D6E2 #x1D71B mathematical-italic)
691 (#x1D71C #x1D755 mathematical-bold-italic)
692 (#x1D756 #x1D78F mathematical-sans-serif-bold)
693 (#x1D790 #x1D7C9 mathematical-sans-serif-bold-italic)
694 (#x1D7CA #x1D7D7 mathematical-bold)
695 (#x1D7D8 #x1D7E1 mathematical-double-struck)
696 (#x1D7E2 #x1D7EB mathematical-sans-serif)
697 (#x1D7EC #x1D7F5 mathematical-sans-serif-bold)
698 (#x1D7F6 #x1D7FF mathematical-monospace)))
699 (let ((slot (assq (nth 2 math-subgroup) script-representative-chars)))
700 (if slot
701 (if (vectorp (cdr slot))
702 (setcdr slot (vconcat (cdr slot) (vector (car math-subgroup))))
703 (setcdr slot (vector (cadr slot) (car math-subgroup))))
704 (setq slot (list (nth 2 math-subgroup) (car math-subgroup)))
705 (nconc script-representative-chars (list slot))))
706 (set-fontset-font
707 "fontset-default"
708 (cons (car math-subgroup) (nth 1 math-subgroup))
709 (font-spec :registry "iso10646-1" :script (nth 2 math-subgroup))))
710
711 ;; Special setup for various symbols and punctuation characters
712 ;; covered well by Symbola, excluding those covered well by popular
713 ;; Unicode fonts. We exclude the latter because users don't like us
714 ;; invading on their font setups where they have good support from
715 ;; other fonts.
716 (dolist (symbol-subgroup
717 '((#x2000 . #x2012) ;; General Punctuation
718 (#x2015 . #x2017)
719 #x201F
720 (#x2023 . #x202F)
721 (#x2031 . #x2038)
722 (#x203B . #x206F)
723 (#x2070 . #x209F) ;; Superscripts and Subscripts
724 (#x20B6 . #x20CF) ;; Currency Symbols
725 (#x2100 . #x2121) ;; Letterlike Symbols
726 (#x2123 . #x214F)
727 (#x2150 . #x215A) ;; Number Forms
728 (#x215F . #x218F)
729 (#x2194 . #x21FF) ;; Arrows
730 (#x2200 . #x2211) ;; Mathematical Operators
731 (#x2213 . #x2247)
732 (#x2249 . #x225F)
733 (#x2261 . #x2263)
734 (#x2266 . #x22FF)
735 (#x2300 . #x2301) ;; Miscellaneous Technical
736 (#x2303 . #x230F)
737 (#x2311 . #x231F)
738 (#x2322 . #x23FF)
739 (#x2400 . #x243F) ;; Control Pictures
740 (#x2440 . #x245F) ;; Optical Char Recognition
741 (#x2460 . #x24FF) ;; Enclosed Alphanumerics
742 (#x25A0 . #x25FF) ;; Geometric Shapes
743 (#x2600 . #x265F) ;; Miscellaneous Symbols
744 (#x2661 . #x2662)
745 #x2664
746 (#x2667 . #x2669)
747 (#x266C . #x26FF)
748 (#x2700 . #x27bF) ;; Dingbats
749 (#x27C0 . #x27EF) ;; Misc Mathematical Symbols-A
750 (#x27F0 . #x27FF) ;; Supplemental Arrows-A
751 (#x2900 . #x297F) ;; Supplemental Arrows-B
752 (#x2980 . #x29FF) ;; Misc Mathematical Symbols-B
753 (#x2A00 . #x2AFF) ;; Suppl. Math Operators
754 (#x2B00 . #x2BFF) ;; Misc Symbols and Arrows
755 (#x2E00 . #x2E7F) ;; Supplemental Punctuation
756 (#x4DC0 . #x4DFF) ;; Yijing Hexagram Symbols
757 (#xFE10 . #xFE1F) ;; Vertical Forms
758 (#x10100 . #x1013F) ;; Aegean Numbers
759 (#x102E0 . #x102FF) ;; Coptic Epact Numbers
760 (#x1D000 . #x1D0FF) ;; Byzantine Musical Symbols
761 (#x1D200 . #x1D24F) ;; Ancient Greek Musical Notation
762 (#x1F0A0 . #x1F0FF) ;; Playing Cards
763 (#x1F100 . #x1F1FF) ;; Enclosed Alphanumeric Suppl
764 (#x1F300 . #x1F5FF) ;; Misc Symbols and Pictographs
765 (#x1F600 . #x1F64F) ;; Emoticons
766 (#x1F650 . #x1F67F) ;; Ornamental Dingbats
767 (#x1F680 . #x1F6FF) ;; Transport and Map Symbols
768 (#x1F700 . #x1F77F) ;; Alchemical Symbols
769 (#x1F780 . #x1F7FF) ;; Geometric Shapes Extended
770 (#x1F800 . #x1F8FF))) ;; Supplemental Arrows-C
771 (set-fontset-font "fontset-default" symbol-subgroup "Symbola" nil 'prepend))
772 ;; Box Drawing and Block Elements
773 (set-fontset-font "fontset-default" '(#x2500 . #x259F)
774 "FreeMono" nil 'prepend)
775
776 ;; Since standard-fontset-spec on X uses fixed-medium font, which
777 ;; gets mapped to a iso8859-1 variant, we would like to prefer its
778 ;; iso10646-1 variant for symbols, where the coverage is known to be
779 ;; good.
780 (dolist (symbol-subgroup
781 '((#x2000 . #x206F) ;; General Punctuation
782 (#x2070 . #x209F) ;; Superscripts and Subscripts
783 (#x20A0 . #x20CF) ;; Currency Symbols
784 (#x2150 . #x218F) ;; Number Forms
785 (#x2190 . #x21FF) ;; Arrows
786 (#x2200 . #x22FF) ;; Mathematical Operators
787 (#x2300 . #x23FF) ;; Miscellaneous Technical
788 (#x2400 . #x243F) ;; Control Pictures
789 (#x2440 . #x245F) ;; Optical Char Recognition
790 (#x2460 . #x24FF) ;; Enclosed Alphanumerics
791 (#x2500 . #x257F) ;; Box Drawing
792 (#x2580 . #x259F) ;; Block Elements
793 (#x25A0 . #x25FF) ;; Geometric Shapes
794 (#x2600 . #x2689) ;; Miscellaneous Symbols
795 (#x2700 . #x27bF) ;; Dingbats
796 (#x27F5 . #x27FF))) ;; Supplemental Arrows-A
797 (set-fontset-font "fontset-default" symbol-subgroup
798 "-*-fixed-medium-*-*-*-*-*-*-*-*-*-iso10646-1"
799 nil 'prepend))
800
801 ;; Append CJK fonts for characters other than han, kana, cjk-misc.
802 ;; Append fonts for scripts whose name is also a charset name.
803 (let* ((data (build-default-fontset-data))
804 (registries (car data)))
805 (dolist (target-spec (cdr data))
806 (let ((target (car target-spec))
807 (spec (cdr target-spec)))
808 (if (integerp spec)
809 (dotimes (i (length registries))
810 (if (> (logand spec (lsh 1 i)) 0)
811 (set-fontset-font "fontset-default" target
812 (cons nil (aref registries i))
813 nil 'append)))
814 (dolist (args spec)
815 (set-fontset-font "fontset-default" target
816 (apply 'font-spec args) nil 'append))))))
817
818 ;; Append Unicode fonts.
819 ;; This may find fonts with more variants (bold, italic) but which
820 ;; don't cover many characters.
821 (set-fontset-font "fontset-default" nil
822 '(nil . "iso10646-1") nil 'prepend)
823 ;; These may find fonts that cover many characters but with fewer
824 ;; variants.
825 (set-fontset-font "fontset-default" nil
826 '("gnu-unifont" . "iso10646-1") nil 'prepend)
827 (set-fontset-font "fontset-default" nil
828 '("mutt-clearlyu" . "iso10646-1") nil 'prepend)
829 (set-fontset-font "fontset-default" '(#x20000 . #x2FFFF)
830 '(nil . "unicode-sip"))
831
832 (set-fontset-font "fontset-default" '(#xE000 . #xF8FF)
833 '(nil . "iso10646-1"))
834 ;; Don't try the fallback fonts even if no suitable font was found
835 ;; by the above font-spec.
836 (set-fontset-font "fontset-default" '(#xE000 . #xF8FF) nil nil 'append))
837
838 (defun create-default-fontset ()
839 "Create the default fontset.
840 Internal use only. Should be called at startup time."
841 (condition-case err
842 (setup-default-fontset)
843 (error (display-warning
844 'initialization
845 (format "Creation of the default fontsets failed: %s" err)
846 :error))))
847
848 ;; These are the registered registries/encodings from
849 ;; ftp://ftp.x.org/pub/DOCS/registry 2001/06/01
850
851 ;; Name Reference
852 ;; ---- ---------
853 ;; "DEC" [27]
854 ;; registry prefix
855 ;; "DEC.CNS11643.1986-2" [53]
856 ;; CNS11643 2-plane using the encoding
857 ;; suggested in that standard
858 ;; "DEC.DTSCS.1990-2" [54]
859 ;; DEC Taiwan Supplemental Character Set
860 ;; "fujitsu.u90x01.1991-0" [87]
861 ;; "fujitsu.u90x03.1991-0" [87]
862 ;; "GB2312.1980-0" [39],[12]
863 ;; China (PRC) Hanzi, GL encoding
864 ;; "GB2312.1980-1" [39]
865 ;; (deprecated)
866 ;; China (PRC) Hanzi, GR encoding
867 ;; "HP-Arabic8" [36]
868 ;; HPARABIC8 8-bit character set
869 ;; "HP-East8" [36]
870 ;; HPEAST8 8-bit character set
871 ;; "HP-Greek8" [36]
872 ;; HPGREEK8 8-bit character set
873 ;; "HP-Hebrew8" [36]
874 ;; HPHEBREW8 8-bit character set
875 ;; "HP-Japanese15" [36]
876 ;; HPJAPAN15 15-bit character set,
877 ;; modified from industry de facto
878 ;; standard Shift-JIS
879 ;; "HP-Kana8" [36]
880 ;; HPKANA8 8-bit character set
881 ;; "HP-Korean15" [36]
882 ;; HPKOREAN15 15-bit character set
883 ;; "HP-Roman8" [36]
884 ;; HPROMAN8 8-bit character set
885 ;; "HP-SChinese15" [36]
886 ;; HPSCHINA15 15-bit character set for
887 ;; support of Simplified Chinese
888 ;; "HP-TChinese15" [36]
889 ;; HPTCHINA15 15-bit character set for
890 ;; support of Traditional Chinese
891 ;; "HP-Turkish8" [36]
892 ;; HPTURKISH8 8-bit character set
893 ;; "IPSYS" [59]
894 ;; registry prefix
895 ;; "IPSYS.IE-1" [59]
896 ;; "ISO2022"<REG>"-"<ENC> [44]
897 ;; "ISO646.1991-IRV" [107]
898 ;; ISO 646 International Reference Version
899 ;; "ISO8859-1" [15],[12]
900 ;; ISO Latin alphabet No. 1
901 ;; "ISO8859-2" [15],[12]
902 ;; ISO Latin alphabet No. 2
903 ;; "ISO8859-3" [15],[12]
904 ;; ISO Latin alphabet No. 3
905 ;; "ISO8859-4" [15],[12]
906 ;; ISO Latin alphabet No. 4
907 ;; "ISO8859-5" [15],[12]
908 ;; ISO Latin/Cyrillic alphabet
909 ;; "ISO8859-6" [15],[12]
910 ;; ISO Latin/Arabic alphabet
911 ;; "ISO8859-7" [15],[12]
912 ;; ISO Latin/Greek alphabet
913 ;; "ISO8859-8" [15],[12]
914 ;; ISO Latin/Hebrew alphabet
915 ;; "ISO8859-9" [15],[12]
916 ;; ISO Latin alphabet No. 5
917 ;; "ISO8859-10" [15],[12]
918 ;; ISO Latin alphabet No. 6
919 ;; "ISO8859-13" [15],[12]
920 ;; ISO Latin alphabet No. 7
921 ;; "ISO8859-14" [15],[12]
922 ;; ISO Latin alphabet No. 8
923 ;; "ISO8859-15" [15],[12]
924 ;; ISO Latin alphabet No. 9
925 ;; "FCD8859-15" [7]
926 ;; (deprecated)
927 ;; ISO Latin alphabet No. 9, Final Committee Draft
928 ;; "ISO10646-1" [133]
929 ;; Unicode Universal Multiple-Octet Coded Character Set
930 ;; "ISO10646-MES" [133]
931 ;; (deprecated)
932 ;; Unicode Minimum European Subset
933 ;; "JISX0201.1976-0" [38],[12]
934 ;; 8-Bit Alphanumeric-Katakana Code
935 ;; "JISX0208.1983-0" [40],[12]
936 ;; Japanese Graphic Character Set,
937 ;; GL encoding
938 ;; "JISX0208.1990-0" [71]
939 ;; Japanese Graphic Character Set,
940 ;; GL encoding
941 ;; "JISX0208.1983-1" [40]
942 ;; (deprecated)
943 ;; Japanese Graphic Character Set,
944 ;; GR encoding
945 ;; "JISX0212.1990-0" [72]
946 ;; Supplementary Japanese Graphic Character Set,
947 ;; GL encoding
948 ;; "KOI8-R" [119]
949 ;; Cyrillic alphabet
950 ;; "KSC5601.1987-0" [41],[12]
951 ;; Korean Graphic Character Set,
952 ;; GL encoding
953 ;; "KSC5601.1987-1" [41]
954 ;; (deprecated)
955 ;; Korean Graphic Character Set,
956 ;; GR encoding
957 ;; "omron_CNS11643-0" [45]
958 ;; "omron_CNS11643-1" [45]
959 ;; "omron_BIG5-0" [45]
960 ;; "omron_BIG5-1" [45]
961 ;; "wn.tamil.1993" [103]
962
963 (defun set-font-encoding (pattern charset)
964 "Set arguments in `font-encoding-alist' (which see)."
965 (let ((slot (assoc pattern font-encoding-alist)))
966 (if slot
967 (setcdr slot charset)
968 (setq font-encoding-alist
969 (cons (cons pattern charset) font-encoding-alist)))))
970
971 (defvar x-pixel-size-width-font-regexp)
972 (defvar vertical-centering-font-regexp)
973
974 ;; Setting for suppressing XLoadQueryFont on big fonts.
975 (setq x-pixel-size-width-font-regexp
976 (purecopy "gb2312\\|gbk\\|gb18030\\|jisx0208\\|ksc5601\\|cns11643\\|big5"))
977
978 ;; These fonts require vertical centering.
979 (setq vertical-centering-font-regexp
980 (purecopy "gb2312\\|gbk\\|gb18030\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5"))
981 (put 'vertical-centering-font-regexp 'standard-value
982 (list vertical-centering-font-regexp))
983
984 ;; CDAC fonts are actually smaller than their design sizes.
985 (setq face-font-rescale-alist
986 (list (cons (purecopy "-cdac$") 1.3)))
987
988 (defvar x-font-name-charset-alist nil
989 "This variable has no meaning now. Just kept for backward compatibility.")
990
991 ;;; XLFD (X Logical Font Description) format handler.
992
993 ;; Define XLFD's field index numbers. ; field name
994 (defconst xlfd-regexp-family-subnum 0) ; FOUNDRY and FAMILY
995 (defconst xlfd-regexp-weight-subnum 1) ; WEIGHT_NAME
996 (defconst xlfd-regexp-slant-subnum 2) ; SLANT
997 (defconst xlfd-regexp-swidth-subnum 3) ; SETWIDTH_NAME
998 (defconst xlfd-regexp-adstyle-subnum 4) ; ADD_STYLE_NAME
999 (defconst xlfd-regexp-pixelsize-subnum 5) ; PIXEL_SIZE
1000 (defconst xlfd-regexp-pointsize-subnum 6) ; POINT_SIZE
1001 (defconst xlfd-regexp-resx-subnum 7) ; RESOLUTION_X
1002 (defconst xlfd-regexp-resy-subnum 8) ; RESOLUTION_Y
1003 (defconst xlfd-regexp-spacing-subnum 8) ; SPACING
1004 (defconst xlfd-regexp-avgwidth-subnum 10) ; AVERAGE_WIDTH
1005 (defconst xlfd-regexp-registry-subnum 11) ; REGISTRY and ENCODING
1006
1007 ;; Regular expression matching against a fontname which conforms to
1008 ;; XLFD (X Logical Font Description). All fields in XLFD should be
1009 ;; not be omitted (but can be a wild card) to be matched.
1010 (defconst xlfd-tight-regexp
1011 "^\
1012 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
1013 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
1014 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*-[^-]*\\)$")
1015
1016 ;; Regular expression matching against a fontname which conforms to
1017 ;; XLFD (X Logical Font Description). All fields in XLFD from FOUNDRY
1018 ;; to ADSTYLE, REGISTRY, and ENCODING should be not be omitted (but
1019 ;; can be a wild card) to be matched.
1020 (defconst xlfd-style-regexp
1021 "^\
1022 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-.*\
1023 -\\([^-]*-[^-]*\\)$")
1024
1025 ;; List of field numbers of XLFD whose values are numeric.
1026 (defconst xlfd-regexp-numeric-subnums
1027 (list xlfd-regexp-pixelsize-subnum ;5
1028 xlfd-regexp-pointsize-subnum ;6
1029 xlfd-regexp-resx-subnum ;7
1030 xlfd-regexp-resy-subnum ;8
1031 xlfd-regexp-avgwidth-subnum ;10
1032 ))
1033
1034 (defun x-decompose-font-name (pattern)
1035 "Decompose PATTERN into XLFD fields and return a vector of the fields.
1036 The length of the vector is 12.
1037 The FOUNDRY and FAMILY fields are concatenated and stored in the first
1038 element of the vector.
1039 The REGISTRY and ENCODING fields are concatenated and stored in the last
1040 element of the vector.
1041
1042 Return nil if PATTERN doesn't conform to XLFD."
1043 (if (string-match xlfd-tight-regexp pattern)
1044 (let ((xlfd-fields (make-vector 12 nil)))
1045 (dotimes (i 12)
1046 (aset xlfd-fields i (match-string (1+ i) pattern)))
1047 (dotimes (i 12)
1048 (if (string-match "^[*-]+$" (aref xlfd-fields i))
1049 (aset xlfd-fields i nil)))
1050 xlfd-fields)))
1051
1052 (defun x-compose-font-name (fields &optional _reduce)
1053 "Compose X fontname from FIELDS.
1054 FIELDS is a vector of XLFD fields, of length 12.
1055 If a field is nil, wild-card letter `*' is embedded.
1056 Optional argument REDUCE exists just for backward compatibility,
1057 and is always ignored."
1058 (concat "-" (mapconcat (lambda (x) (or x "*")) fields "-")))
1059
1060
1061 (defun x-must-resolve-font-name (xlfd-fields)
1062 "Like `x-resolve-font-name', but always return a font name.
1063 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
1064 If no font matching XLFD-FIELDS is available, successively replace
1065 parts of the font name pattern with \"*\" until some font is found.
1066 Value is name of that font."
1067 (let ((ascii-font nil) (index 0))
1068 (while (and (null ascii-font) (<= index xlfd-regexp-registry-subnum))
1069 (let ((pattern (x-compose-font-name xlfd-fields)))
1070 (condition-case nil
1071 (setq ascii-font (x-resolve-font-name pattern))
1072 (error
1073 (message "Warning: no fonts matching `%s' available" pattern)
1074 (aset xlfd-fields index "*")
1075 (setq index (1+ index))))))
1076 (unless ascii-font
1077 (error "No fonts found"))
1078 ascii-font))
1079
1080
1081 (defun x-complement-fontset-spec (default-spec fontlist)
1082 "Complement elements of FONTLIST based on DEFAULT-SPEC.
1083 DEFAULT-SPEC is a font-spec object providing default font properties.
1084 FONTLIST is an alist of script names vs the corresponding font names.
1085
1086 The font names are parsed and unspecified font properties are
1087 given from DEFAULT-SPEC."
1088 (let ((prop-list '(:foundry :family :weight :slant :width :adstyle :size)))
1089 (dolist (elt fontlist)
1090 (let ((spec (font-spec :name (cadr elt))))
1091 (dolist (prop prop-list)
1092 (let ((val (font-get spec prop)))
1093 (or val
1094 (font-put spec prop (font-get default-spec prop)))))
1095 (setcar (cdr elt) spec)))
1096 fontlist))
1097
1098 (defun fontset-name-p (fontset)
1099 "Return non-nil if FONTSET is valid as fontset name.
1100 A valid fontset name should conform to XLFD (X Logical Font Description)
1101 with \"fontset\" in `<CHARSET_REGISTRY>' field."
1102 (and (string-match xlfd-tight-regexp fontset)
1103 (string= (match-string (1+ xlfd-regexp-registry-subnum) fontset)
1104 "fontset")))
1105
1106 (declare-function fontset-list "fontset.c" ())
1107
1108 (defun generate-fontset-menu ()
1109 "Return list to be appended to `x-fixed-font-alist'.
1110 Done when `mouse-set-font' is called."
1111 (let (l)
1112 (dolist (fontset (fontset-list))
1113 (or (string-match "fontset-default$" fontset)
1114 (string-match "fontset-auto[0-9]+$" fontset)
1115 (push (list (fontset-plain-name fontset) fontset) l)))
1116 (cons "Fontset"
1117 (sort l #'(lambda (x y) (string< (car x) (car y)))))))
1118
1119 (declare-function query-fontset "fontset.c" (pattern &optional regexpp))
1120
1121 (defun fontset-plain-name (fontset)
1122 "Return a plain and descriptive name of FONTSET."
1123 (if (not (setq fontset (query-fontset fontset)))
1124 (error "Invalid fontset: %s" fontset))
1125 (let ((xlfd-fields (x-decompose-font-name fontset)))
1126 (if xlfd-fields
1127 (let ((family (aref xlfd-fields xlfd-regexp-family-subnum))
1128 (weight (aref xlfd-fields xlfd-regexp-weight-subnum))
1129 (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
1130 ;(swidth (aref xlfd-fields xlfd-regexp-swidth-subnum))
1131 (size (aref xlfd-fields xlfd-regexp-pixelsize-subnum))
1132 (nickname (aref xlfd-fields xlfd-regexp-registry-subnum))
1133 name)
1134 (if (not (string-match "^fontset-\\(.*\\)$" nickname))
1135 (setq nickname family)
1136 (setq nickname (match-string 1 nickname)))
1137 (if (and size (> (string-to-number size) 0))
1138 (setq name (format "%s: %s-dot" nickname size))
1139 (setq name nickname))
1140 (and weight
1141 (cond ((string-match "^medium$" weight)
1142 (setq name (concat name " " "medium")))
1143 ((string-match "^bold$\\|^demibold$" weight)
1144 (setq name (concat name " " weight)))))
1145 (and slant
1146 (cond ((string-match "^i$" slant)
1147 (setq name (concat name " " "italic")))
1148 ((string-match "^o$" slant)
1149 (setq name (concat name " " "slant")))
1150 ((string-match "^ri$" slant)
1151 (setq name (concat name " " "reverse italic")))
1152 ((string-match "^ro$" slant)
1153 (setq name (concat name " " "reverse slant")))))
1154 name)
1155 fontset)))
1156
1157 (defvar charset-script-alist
1158 '((ascii . latin)
1159 (latin-iso8859-1 . latin)
1160 (latin-iso8859-2 . latin)
1161 (latin-iso8859-3 . latin)
1162 (latin-iso8859-4 . latin)
1163 (latin-iso8859-9 . latin)
1164 (latin-iso8859-10 . latin)
1165 (latin-iso8859-13 . latin)
1166 (latin-iso8859-14 . latin)
1167 (latin-iso8859-15 . latin)
1168 (latin-iso8859-16 . latin)
1169 (latin-jisx0201 . latin)
1170 (thai-tis620 . thai)
1171 (cyrillic-iso8859-5 . cyrillic)
1172 (arabic-iso8859-6 . arabic)
1173 (greek-iso8859-7 . latin)
1174 (hebrew-iso8859-8 . latin)
1175 (katakana-jisx0201 . kana)
1176 (chinese-gb2312 . han)
1177 (chinese-gbk . han)
1178 (gb18030-2-byte . han)
1179 (gb18030-4-byte-bmp . han)
1180 (gb18030-4-byte-ext-1 . han)
1181 (gb18030-4-byte-ext-2 . han)
1182 (gb18030-4-byte-smp . han)
1183 (chinese-big5-1 . han)
1184 (chinese-big5-2 . han)
1185 (chinese-cns11643-1 . han)
1186 (chinese-cns11643-2 . han)
1187 (chinese-cns11643-3 . han)
1188 (chinese-cns11643-4 . han)
1189 (chinese-cns11643-5 . han)
1190 (chinese-cns11643-6 . han)
1191 (chinese-cns11643-7 . han)
1192 (japanese-jisx0208 . han)
1193 (japanese-jisx0208-1978 . han)
1194 (japanese-jisx0212 . han)
1195 (japanese-jisx0213-1 . han)
1196 (japanese-jisx0213-2 . han)
1197 (korean-ksc5601 . hangul)
1198 (chinese-sisheng . bopomofo)
1199 (vietnamese-viscii-lower . latin)
1200 (vietnamese-viscii-upper . latin)
1201 (arabic-digit . arabic)
1202 (arabic-1-column . arabic)
1203 (arabic-2-column . arabic)
1204 (indian-is13194 . devanagari)
1205 (indian-glyph . devanagari)
1206 (indian-1-column . devanagari)
1207 (indian-2-column . devanagari)
1208 (tibetan-1-column . tibetan))
1209 "Alist of charsets vs the corresponding most appropriate scripts.
1210
1211 This alist is used by the function `create-fontset-from-fontset-spec'
1212 to map charsets to scripts.")
1213
1214 (defun create-fontset-from-fontset-spec (fontset-spec
1215 &optional _style-variant _noerror)
1216 "Create a fontset from fontset specification string FONTSET-SPEC.
1217 FONTSET-SPEC is a string of the format:
1218 FONTSET-NAME,SCRIPT-NAME0:FONT-NAME0,SCRIPT-NAME1:FONT-NAME1, ...
1219 Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
1220
1221 When a frame uses the fontset as the `font' parameter, the frame's
1222 default font name is derived from FONTSET-NAME by substituting
1223 \"iso8859-1\" for the tail part \"fontset-XXX\". But, if SCRIPT-NAMEn
1224 is \"ascii\", use the corresponding FONT-NAMEn as the default font
1225 name.
1226
1227 Optional 2nd and 3rd arguments exist just for backward compatibility,
1228 and are ignored.
1229
1230 It returns a name of the created fontset.
1231
1232 For backward compatibility, SCRIPT-NAME may be a charset name, in
1233 which case, the corresponding script is decided by the variable
1234 `charset-script-alist' (which see)."
1235 (or (string-match "^[^,]+" fontset-spec)
1236 (error "Invalid fontset spec: %s" fontset-spec))
1237 (let ((idx (match-end 0))
1238 (name (match-string 0 fontset-spec))
1239 default-spec target script fontlist)
1240 (or (string-match xlfd-tight-regexp name)
1241 (error "Fontset name \"%s\" not conforming to XLFD" name))
1242 (setq default-spec (font-spec :name name))
1243 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
1244 (while (string-match "[, \t\n]*\\([^:]+\\):[ \t]*\\([^,]+\\)"
1245 fontset-spec idx)
1246 (setq idx (match-end 0))
1247 (setq target (intern (match-string 1 fontset-spec)))
1248 (cond ((or (eq target 'ascii)
1249 (memq target (char-table-extra-slot char-script-table 0)))
1250 (push (list target (match-string 2 fontset-spec)) fontlist))
1251 ((setq script (cdr (assq target charset-script-alist)))
1252 (push (list script (match-string 2 fontset-spec)) fontlist))
1253 ((charsetp target)
1254 (push (list target (match-string 2 fontset-spec)) fontlist))))
1255
1256 ;; Complement FONTLIST.
1257 (setq fontlist (x-complement-fontset-spec default-spec fontlist))
1258
1259 ;; Create a fontset.
1260 (new-fontset name (nreverse fontlist))))
1261
1262 (defun create-fontset-from-ascii-font (font &optional resolved-font
1263 fontset-name)
1264 "Create a fontset from an ASCII font FONT.
1265
1266 Optional 2nd arg RESOLVED-FONT is a resolved name of FONT.
1267 If omitted, `x-resolve-font-name' is called to get the resolved name.
1268 At this time, if FONT is not available, an error is signaled.
1269
1270 Optional 3rd arg FONTSET-NAME is a string to be used in
1271 `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
1272 an appropriate name is generated automatically.
1273
1274 It returns a name of the created fontset."
1275 (setq font (downcase font))
1276 (setq resolved-font
1277 (downcase (or resolved-font (x-resolve-font-name font))))
1278 (let ((xlfd (x-decompose-font-name resolved-font))
1279 fontset)
1280 (if fontset-name
1281 (setq fontset-name (downcase fontset-name))
1282 (if (query-fontset "fontset-startup")
1283 (setq fontset-name
1284 (subst-char-in-string
1285 ?- ?_ (aref xlfd xlfd-regexp-registry-subnum) t))
1286 (setq fontset-name "startup")))
1287 (aset xlfd xlfd-regexp-registry-subnum
1288 (format "fontset-%s" fontset-name))
1289 (setq fontset (x-compose-font-name xlfd))
1290 (or (query-fontset fontset)
1291 (create-fontset-from-fontset-spec (concat fontset ", ascii:" font)))))
1292
1293 \f
1294 ;; Create standard fontset from 16 dots fonts which are the most widely
1295 ;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
1296 ;; specified here because FAMILY of those fonts are not "fixed" in
1297 ;; many cases.
1298 (defvar standard-fontset-spec
1299 (purecopy "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard")
1300 "String of fontset spec of the standard fontset.
1301 You have the biggest chance to display international characters
1302 with correct glyphs by using the standard fontset.
1303 See the documentation of `create-fontset-from-fontset-spec' for the format.")
1304
1305
1306 ;; Create fontsets from X resources of the name `fontset-N (class
1307 ;; Fontset-N)' where N is integer 0, 1, ...
1308 ;; The values of the resources the string of the same format as
1309 ;; `standard-fontset-spec'.
1310
1311 (declare-function x-get-resource "frame.c"
1312 (attribute class &optional component subclass))
1313
1314 (defun create-fontset-from-x-resource ()
1315 (let ((idx 0)
1316 fontset-spec)
1317 (while (setq fontset-spec (x-get-resource (format "fontset-%d" idx)
1318 (format "Fontset-%d" idx)))
1319 (condition-case nil
1320 (create-fontset-from-fontset-spec fontset-spec t)
1321 (error (display-warning
1322 'initialization
1323 (format "Fontset-%d: invalid specification in X resource" idx)
1324 :warning)))
1325 (setq idx (1+ idx)))))
1326
1327 ;;
1328 (provide 'fontset)
1329
1330 ;;; fontset.el ends here