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