]> code.delx.au - gnu-emacs/blob - lisp/international/fontset.el
Merge from origin/emacs-24
[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 (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 old-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 (#x20B6 . #x20CF) ;; Currency Symbols
710 (#x2100 . #x2121) ;; Letterlike Symbols
711 (#x2123 . #x214F)
712 (#x2150 . #x215A) ;; Number Forms
713 (#x215F . #x218F)
714 (#x2194 . #x21FF) ;; Arrows
715 (#x2200 . #x2211) ;; Mathematical Operators
716 (#x2213 . #x2247)
717 (#x2249 . #x225F)
718 (#x2261 . #x2263)
719 (#x2266 . #x22FF)
720 (#x2300 . #x2301) ;; Miscellaneous Technical
721 (#x2303 . #x230F)
722 (#x2311 . #x231F)
723 (#x2322 . #x23FF)
724 (#x2400 . #x243F) ;; Control Pictures
725 (#x2440 . #x245F) ;; Optical Char Recognition
726 (#x2460 . #x24FF) ;; Enclosed Alphanumerics
727 (#x25A0 . #x25FF) ;; Geometric Shapes
728 (#x2600 . #x265F) ;; Miscellaneous Symbols
729 (#x2661 . #x2662)
730 #x2664
731 (#x2667 . #x2669)
732 (#x266C . #x26FF)
733 (#x2700 . #x27bF) ;; Dingbats
734 (#x27C0 . #x27EF) ;; Misc Mathematical Symbols-A
735 (#x27F0 . #x27FF) ;; Supplemental Arrows-A
736 (#x2900 . #x297F) ;; Supplemental Arrows-B
737 (#x2980 . #x29FF) ;; Misc Mathematical Symbols-B
738 (#x2A00 . #x2AFF) ;; Suppl. Math Operators
739 (#x2B00 . #x2BFF) ;; Misc Symbols and Arrows
740 (#x2E00 . #x2E7F) ;; Supplemental Punctuation
741 (#x4DC0 . #x4DFF) ;; Yijing Hexagram Symbols
742 (#xFE10 . #xFE1F) ;; Vertical Forms
743 (#x10100 . #x1013F) ;; Aegean Numbers
744 (#x102E0 . #x102FF) ;; Coptic Epact Numbers
745 (#x1D000 . #x1D0FF) ;; Byzantine Musical Symbols
746 (#x1D200 . #x1D24F) ;; Ancient Greek Musical Notation
747 (#x1F0A0 . #x1F0FF) ;; Playing Cards
748 (#x1F100 . #x1F1FF) ;; Enclosed Alphanumeric Suppl
749 (#x1F300 . #x1F5FF) ;; Misc Symbols and Pictographs
750 (#x1F600 . #x1F64F) ;; Emoticons
751 (#x1F650 . #x1F67F) ;; Ornamental Dingbats
752 (#x1F680 . #x1F6FF) ;; Transport and Map Symbols
753 (#x1F700 . #x1F77F) ;; Alchemical Symbols
754 (#x1F780 . #x1F7FF) ;; Geometric Shapes Extended
755 (#x1F800 . #x1F8FF))) ;; Supplemental Arrows-C
756 (set-fontset-font "fontset-default" symbol-subgroup "Symbola" nil 'prepend))
757 ;; Box Drawing and Block Elements
758 (set-fontset-font "fontset-default" '(#x2500 . #x259F)
759 "FreeMono" nil 'prepend)
760
761 ;; Since standard-fontset-spec on X uses fixed-medium font, which
762 ;; gets mapped to a iso8859-1 variant, we would like to prefer its
763 ;; iso10646-1 variant for symbols, where the coverage is known to be
764 ;; good.
765 (dolist (symbol-subgroup
766 '((#x2000 . #x206F) ;; General Punctuation
767 (#x2070 . #x209F) ;; Superscripts and Subscripts
768 (#x20A0 . #x20CF) ;; Currency Symbols
769 (#x2150 . #x218F) ;; Number Forms
770 (#x2190 . #x21FF) ;; Arrows
771 (#x2200 . #x22FF) ;; Mathematical Operators
772 (#x2300 . #x23FF) ;; Miscellaneous Technical
773 (#x2400 . #x243F) ;; Control Pictures
774 (#x2440 . #x245F) ;; Optical Char Recognition
775 (#x2460 . #x24FF) ;; Enclosed Alphanumerics
776 (#x2500 . #x257F) ;; Box Drawing
777 (#x2580 . #x259F) ;; Block Elements
778 (#x25A0 . #x25FF) ;; Geometric Shapes
779 (#x2600 . #x2689) ;; Miscellaneous Symbols
780 (#x2700 . #x27bF) ;; Dingbats
781 (#x27F5 . #x27FF))) ;; Supplemental Arrows-A
782 (set-fontset-font "fontset-default" symbol-subgroup
783 "-*-fixed-medium-*-*-*-*-*-*-*-*-*-iso10646-1"
784 nil 'prepend))
785
786 ;; Append CJK fonts for characters other than han, kana, cjk-misc.
787 ;; Append fonts for scripts whose name is also a charset name.
788 (let* ((data (build-default-fontset-data))
789 (registries (car data)))
790 (dolist (target-spec (cdr data))
791 (let ((target (car target-spec))
792 (spec (cdr target-spec)))
793 (if (integerp spec)
794 (dotimes (i (length registries))
795 (if (> (logand spec (lsh 1 i)) 0)
796 (set-fontset-font "fontset-default" target
797 (cons nil (aref registries i))
798 nil 'append)))
799 (dolist (args spec)
800 (set-fontset-font "fontset-default" target
801 (apply 'font-spec args) nil 'append))))))
802
803 ;; Append Unicode fonts.
804 ;; This may find fonts with more variants (bold, italic) but which
805 ;; don't cover many characters.
806 (set-fontset-font "fontset-default" nil
807 '(nil . "iso10646-1") nil 'prepend)
808 ;; These may find fonts that cover many characters but with fewer
809 ;; variants.
810 (set-fontset-font "fontset-default" nil
811 '("gnu-unifont" . "iso10646-1") nil 'prepend)
812 (set-fontset-font "fontset-default" nil
813 '("mutt-clearlyu" . "iso10646-1") nil 'prepend)
814 (set-fontset-font "fontset-default" '(#x20000 . #x2FFFF)
815 '(nil . "unicode-sip"))
816
817 (set-fontset-font "fontset-default" '(#xE000 . #xF8FF)
818 '(nil . "iso10646-1"))
819 ;; Don't try the fallback fonts even if no suitable font was found
820 ;; by the above font-spec.
821 (set-fontset-font "fontset-default" '(#xE000 . #xF8FF) nil nil 'append))
822
823 (defun create-default-fontset ()
824 "Create the default fontset.
825 Internal use only. Should be called at startup time."
826 (condition-case err
827 (setup-default-fontset)
828 (error (display-warning
829 'initialization
830 (format "Creation of the default fontsets failed: %s" err)
831 :error))))
832
833 ;; These are the registered registries/encodings from
834 ;; ftp://ftp.x.org/pub/DOCS/registry 2001/06/01
835
836 ;; Name Reference
837 ;; ---- ---------
838 ;; "DEC" [27]
839 ;; registry prefix
840 ;; "DEC.CNS11643.1986-2" [53]
841 ;; CNS11643 2-plane using the encoding
842 ;; suggested in that standard
843 ;; "DEC.DTSCS.1990-2" [54]
844 ;; DEC Taiwan Supplemental Character Set
845 ;; "fujitsu.u90x01.1991-0" [87]
846 ;; "fujitsu.u90x03.1991-0" [87]
847 ;; "GB2312.1980-0" [39],[12]
848 ;; China (PRC) Hanzi, GL encoding
849 ;; "GB2312.1980-1" [39]
850 ;; (deprecated)
851 ;; China (PRC) Hanzi, GR encoding
852 ;; "HP-Arabic8" [36]
853 ;; HPARABIC8 8-bit character set
854 ;; "HP-East8" [36]
855 ;; HPEAST8 8-bit character set
856 ;; "HP-Greek8" [36]
857 ;; HPGREEK8 8-bit character set
858 ;; "HP-Hebrew8" [36]
859 ;; HPHEBREW8 8-bit character set
860 ;; "HP-Japanese15" [36]
861 ;; HPJAPAN15 15-bit character set,
862 ;; modified from industry de facto
863 ;; standard Shift-JIS
864 ;; "HP-Kana8" [36]
865 ;; HPKANA8 8-bit character set
866 ;; "HP-Korean15" [36]
867 ;; HPKOREAN15 15-bit character set
868 ;; "HP-Roman8" [36]
869 ;; HPROMAN8 8-bit character set
870 ;; "HP-SChinese15" [36]
871 ;; HPSCHINA15 15-bit character set for
872 ;; support of Simplified Chinese
873 ;; "HP-TChinese15" [36]
874 ;; HPTCHINA15 15-bit character set for
875 ;; support of Traditional Chinese
876 ;; "HP-Turkish8" [36]
877 ;; HPTURKISH8 8-bit character set
878 ;; "IPSYS" [59]
879 ;; registry prefix
880 ;; "IPSYS.IE-1" [59]
881 ;; "ISO2022"<REG>"-"<ENC> [44]
882 ;; "ISO646.1991-IRV" [107]
883 ;; ISO 646 International Reference Version
884 ;; "ISO8859-1" [15],[12]
885 ;; ISO Latin alphabet No. 1
886 ;; "ISO8859-2" [15],[12]
887 ;; ISO Latin alphabet No. 2
888 ;; "ISO8859-3" [15],[12]
889 ;; ISO Latin alphabet No. 3
890 ;; "ISO8859-4" [15],[12]
891 ;; ISO Latin alphabet No. 4
892 ;; "ISO8859-5" [15],[12]
893 ;; ISO Latin/Cyrillic alphabet
894 ;; "ISO8859-6" [15],[12]
895 ;; ISO Latin/Arabic alphabet
896 ;; "ISO8859-7" [15],[12]
897 ;; ISO Latin/Greek alphabet
898 ;; "ISO8859-8" [15],[12]
899 ;; ISO Latin/Hebrew alphabet
900 ;; "ISO8859-9" [15],[12]
901 ;; ISO Latin alphabet No. 5
902 ;; "ISO8859-10" [15],[12]
903 ;; ISO Latin alphabet No. 6
904 ;; "ISO8859-13" [15],[12]
905 ;; ISO Latin alphabet No. 7
906 ;; "ISO8859-14" [15],[12]
907 ;; ISO Latin alphabet No. 8
908 ;; "ISO8859-15" [15],[12]
909 ;; ISO Latin alphabet No. 9
910 ;; "FCD8859-15" [7]
911 ;; (deprecated)
912 ;; ISO Latin alphabet No. 9, Final Committee Draft
913 ;; "ISO10646-1" [133]
914 ;; Unicode Universal Multiple-Octet Coded Character Set
915 ;; "ISO10646-MES" [133]
916 ;; (deprecated)
917 ;; Unicode Minimum European Subset
918 ;; "JISX0201.1976-0" [38],[12]
919 ;; 8-Bit Alphanumeric-Katakana Code
920 ;; "JISX0208.1983-0" [40],[12]
921 ;; Japanese Graphic Character Set,
922 ;; GL encoding
923 ;; "JISX0208.1990-0" [71]
924 ;; Japanese Graphic Character Set,
925 ;; GL encoding
926 ;; "JISX0208.1983-1" [40]
927 ;; (deprecated)
928 ;; Japanese Graphic Character Set,
929 ;; GR encoding
930 ;; "JISX0212.1990-0" [72]
931 ;; Supplementary Japanese Graphic Character Set,
932 ;; GL encoding
933 ;; "KOI8-R" [119]
934 ;; Cyrillic alphabet
935 ;; "KSC5601.1987-0" [41],[12]
936 ;; Korean Graphic Character Set,
937 ;; GL encoding
938 ;; "KSC5601.1987-1" [41]
939 ;; (deprecated)
940 ;; Korean Graphic Character Set,
941 ;; GR encoding
942 ;; "omron_CNS11643-0" [45]
943 ;; "omron_CNS11643-1" [45]
944 ;; "omron_BIG5-0" [45]
945 ;; "omron_BIG5-1" [45]
946 ;; "wn.tamil.1993" [103]
947
948 (defun set-font-encoding (pattern charset)
949 "Set arguments in `font-encoding-alist' (which see)."
950 (let ((slot (assoc pattern font-encoding-alist)))
951 (if slot
952 (setcdr slot charset)
953 (setq font-encoding-alist
954 (cons (cons pattern charset) font-encoding-alist)))))
955
956 (defvar x-pixel-size-width-font-regexp)
957 (defvar vertical-centering-font-regexp)
958
959 ;; Setting for suppressing XLoadQueryFont on big fonts.
960 (setq x-pixel-size-width-font-regexp
961 (purecopy "gb2312\\|gbk\\|gb18030\\|jisx0208\\|ksc5601\\|cns11643\\|big5"))
962
963 ;; These fonts require vertical centering.
964 (setq vertical-centering-font-regexp
965 (purecopy "gb2312\\|gbk\\|gb18030\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5"))
966 (put 'vertical-centering-font-regexp 'standard-value
967 (list vertical-centering-font-regexp))
968
969 ;; CDAC fonts are actually smaller than their design sizes.
970 (setq face-font-rescale-alist
971 (list (cons (purecopy "-cdac$") 1.3)))
972
973 (defvar x-font-name-charset-alist nil
974 "This variable has no meaning now. Just kept for backward compatibility.")
975
976 ;;; XLFD (X Logical Font Description) format handler.
977
978 ;; Define XLFD's field index numbers. ; field name
979 (defconst xlfd-regexp-family-subnum 0) ; FOUNDRY and FAMILY
980 (defconst xlfd-regexp-weight-subnum 1) ; WEIGHT_NAME
981 (defconst xlfd-regexp-slant-subnum 2) ; SLANT
982 (defconst xlfd-regexp-swidth-subnum 3) ; SETWIDTH_NAME
983 (defconst xlfd-regexp-adstyle-subnum 4) ; ADD_STYLE_NAME
984 (defconst xlfd-regexp-pixelsize-subnum 5) ; PIXEL_SIZE
985 (defconst xlfd-regexp-pointsize-subnum 6) ; POINT_SIZE
986 (defconst xlfd-regexp-resx-subnum 7) ; RESOLUTION_X
987 (defconst xlfd-regexp-resy-subnum 8) ; RESOLUTION_Y
988 (defconst xlfd-regexp-spacing-subnum 8) ; SPACING
989 (defconst xlfd-regexp-avgwidth-subnum 10) ; AVERAGE_WIDTH
990 (defconst xlfd-regexp-registry-subnum 11) ; REGISTRY and ENCODING
991
992 ;; Regular expression matching against a fontname which conforms to
993 ;; XLFD (X Logical Font Description). All fields in XLFD should be
994 ;; not be omitted (but can be a wild card) to be matched.
995 (defconst xlfd-tight-regexp
996 "^\
997 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
998 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
999 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*-[^-]*\\)$")
1000
1001 ;; Regular expression matching against a fontname which conforms to
1002 ;; XLFD (X Logical Font Description). All fields in XLFD from FOUNDRY
1003 ;; to ADSTYLE, REGISTRY, and ENCODING should be not be omitted (but
1004 ;; can be a wild card) to be matched.
1005 (defconst xlfd-style-regexp
1006 "^\
1007 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-.*\
1008 -\\([^-]*-[^-]*\\)$")
1009
1010 ;; List of field numbers of XLFD whose values are numeric.
1011 (defconst xlfd-regexp-numeric-subnums
1012 (list xlfd-regexp-pixelsize-subnum ;5
1013 xlfd-regexp-pointsize-subnum ;6
1014 xlfd-regexp-resx-subnum ;7
1015 xlfd-regexp-resy-subnum ;8
1016 xlfd-regexp-avgwidth-subnum ;10
1017 ))
1018
1019 (defun x-decompose-font-name (pattern)
1020 "Decompose PATTERN into XLFD fields and return a vector of the fields.
1021 The length of the vector is 12.
1022 The FOUNDRY and FAMILY fields are concatenated and stored in the first
1023 element of the vector.
1024 The REGISTRY and ENCODING fields are concatenated and stored in the last
1025 element of the vector.
1026
1027 Return nil if PATTERN doesn't conform to XLFD."
1028 (if (string-match xlfd-tight-regexp pattern)
1029 (let ((xlfd-fields (make-vector 12 nil)))
1030 (dotimes (i 12)
1031 (aset xlfd-fields i (match-string (1+ i) pattern)))
1032 (dotimes (i 12)
1033 (if (string-match "^[*-]+$" (aref xlfd-fields i))
1034 (aset xlfd-fields i nil)))
1035 xlfd-fields)))
1036
1037 (defun x-compose-font-name (fields &optional _reduce)
1038 "Compose X fontname from FIELDS.
1039 FIELDS is a vector of XLFD fields, of length 12.
1040 If a field is nil, wild-card letter `*' is embedded.
1041 Optional argument REDUCE exists just for backward compatibility,
1042 and is always ignored."
1043 (concat "-" (mapconcat (lambda (x) (or x "*")) fields "-")))
1044
1045
1046 (defun x-must-resolve-font-name (xlfd-fields)
1047 "Like `x-resolve-font-name', but always return a font name.
1048 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
1049 If no font matching XLFD-FIELDS is available, successively replace
1050 parts of the font name pattern with \"*\" until some font is found.
1051 Value is name of that font."
1052 (let ((ascii-font nil) (index 0))
1053 (while (and (null ascii-font) (<= index xlfd-regexp-registry-subnum))
1054 (let ((pattern (x-compose-font-name xlfd-fields)))
1055 (condition-case nil
1056 (setq ascii-font (x-resolve-font-name pattern))
1057 (error
1058 (message "Warning: no fonts matching `%s' available" pattern)
1059 (aset xlfd-fields index "*")
1060 (setq index (1+ index))))))
1061 (unless ascii-font
1062 (error "No fonts found"))
1063 ascii-font))
1064
1065
1066 (defun x-complement-fontset-spec (default-spec fontlist)
1067 "Complement elements of FONTLIST based on DEFAULT-SPEC.
1068 DEFAULT-SPEC is a font-spec object providing default font properties.
1069 FONTLIST is an alist of script names vs the corresponding font names.
1070
1071 The font names are parsed and unspecified font properties are
1072 given from DEFAULT-SPEC."
1073 (let ((prop-list '(:foundry :family :weight :slant :width :adstyle :size)))
1074 (dolist (elt fontlist)
1075 (let ((spec (font-spec :name (cadr elt))))
1076 (dolist (prop prop-list)
1077 (let ((val (font-get spec prop)))
1078 (or val
1079 (font-put spec prop (font-get default-spec prop)))))
1080 (setcar (cdr elt) spec)))
1081 fontlist))
1082
1083 (defun fontset-name-p (fontset)
1084 "Return non-nil if FONTSET is valid as fontset name.
1085 A valid fontset name should conform to XLFD (X Logical Font Description)
1086 with \"fontset\" in `<CHARSET_REGISTRY>' field."
1087 (and (string-match xlfd-tight-regexp fontset)
1088 (string= (match-string (1+ xlfd-regexp-registry-subnum) fontset)
1089 "fontset")))
1090
1091 (declare-function fontset-list "fontset.c" ())
1092
1093 (defun generate-fontset-menu ()
1094 "Return list to be appended to `x-fixed-font-alist'.
1095 Done when `mouse-set-font' is called."
1096 (let (l)
1097 (dolist (fontset (fontset-list))
1098 (or (string-match "fontset-default$" fontset)
1099 (string-match "fontset-auto[0-9]+$" fontset)
1100 (push (list (fontset-plain-name fontset) fontset) l)))
1101 (cons "Fontset"
1102 (sort l #'(lambda (x y) (string< (car x) (car y)))))))
1103
1104 (declare-function query-fontset "fontset.c" (pattern &optional regexpp))
1105
1106 (defun fontset-plain-name (fontset)
1107 "Return a plain and descriptive name of FONTSET."
1108 (if (not (setq fontset (query-fontset fontset)))
1109 (error "Invalid fontset: %s" fontset))
1110 (let ((xlfd-fields (x-decompose-font-name fontset)))
1111 (if xlfd-fields
1112 (let ((family (aref xlfd-fields xlfd-regexp-family-subnum))
1113 (weight (aref xlfd-fields xlfd-regexp-weight-subnum))
1114 (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
1115 ;(swidth (aref xlfd-fields xlfd-regexp-swidth-subnum))
1116 (size (aref xlfd-fields xlfd-regexp-pixelsize-subnum))
1117 (nickname (aref xlfd-fields xlfd-regexp-registry-subnum))
1118 name)
1119 (if (not (string-match "^fontset-\\(.*\\)$" nickname))
1120 (setq nickname family)
1121 (setq nickname (match-string 1 nickname)))
1122 (if (and size (> (string-to-number size) 0))
1123 (setq name (format "%s: %s-dot" nickname size))
1124 (setq name nickname))
1125 (and weight
1126 (cond ((string-match "^medium$" weight)
1127 (setq name (concat name " " "medium")))
1128 ((string-match "^bold$\\|^demibold$" weight)
1129 (setq name (concat name " " weight)))))
1130 (and slant
1131 (cond ((string-match "^i$" slant)
1132 (setq name (concat name " " "italic")))
1133 ((string-match "^o$" slant)
1134 (setq name (concat name " " "slant")))
1135 ((string-match "^ri$" slant)
1136 (setq name (concat name " " "reverse italic")))
1137 ((string-match "^ro$" slant)
1138 (setq name (concat name " " "reverse slant")))))
1139 name)
1140 fontset)))
1141
1142 (defvar charset-script-alist
1143 '((ascii . latin)
1144 (latin-iso8859-1 . latin)
1145 (latin-iso8859-2 . latin)
1146 (latin-iso8859-3 . latin)
1147 (latin-iso8859-4 . latin)
1148 (latin-iso8859-9 . latin)
1149 (latin-iso8859-10 . latin)
1150 (latin-iso8859-13 . latin)
1151 (latin-iso8859-14 . latin)
1152 (latin-iso8859-15 . latin)
1153 (latin-iso8859-16 . latin)
1154 (latin-jisx0201 . latin)
1155 (thai-tis620 . thai)
1156 (cyrillic-iso8859-5 . cyrillic)
1157 (arabic-iso8859-6 . arabic)
1158 (greek-iso8859-7 . latin)
1159 (hebrew-iso8859-8 . latin)
1160 (katakana-jisx0201 . kana)
1161 (chinese-gb2312 . han)
1162 (chinese-gbk . han)
1163 (gb18030-2-byte . han)
1164 (gb18030-4-byte-bmp . han)
1165 (gb18030-4-byte-ext-1 . han)
1166 (gb18030-4-byte-ext-2 . han)
1167 (gb18030-4-byte-smp . han)
1168 (chinese-big5-1 . han)
1169 (chinese-big5-2 . han)
1170 (chinese-cns11643-1 . han)
1171 (chinese-cns11643-2 . han)
1172 (chinese-cns11643-3 . han)
1173 (chinese-cns11643-4 . han)
1174 (chinese-cns11643-5 . han)
1175 (chinese-cns11643-6 . han)
1176 (chinese-cns11643-7 . han)
1177 (japanese-jisx0208 . han)
1178 (japanese-jisx0208-1978 . han)
1179 (japanese-jisx0212 . han)
1180 (japanese-jisx0213-1 . han)
1181 (japanese-jisx0213-2 . han)
1182 (korean-ksc5601 . hangul)
1183 (chinese-sisheng . bopomofo)
1184 (vietnamese-viscii-lower . latin)
1185 (vietnamese-viscii-upper . latin)
1186 (arabic-digit . arabic)
1187 (arabic-1-column . arabic)
1188 (arabic-2-column . arabic)
1189 (indian-is13194 . devanagari)
1190 (indian-glyph . devanagari)
1191 (indian-1-column . devanagari)
1192 (indian-2-column . devanagari)
1193 (tibetan-1-column . tibetan))
1194 "Alist of charsets vs the corresponding most appropriate scripts.
1195
1196 This alist is used by the function `create-fontset-from-fontset-spec'
1197 to map charsets to scripts.")
1198
1199 (defun create-fontset-from-fontset-spec (fontset-spec
1200 &optional _style-variant _noerror)
1201 "Create a fontset from fontset specification string FONTSET-SPEC.
1202 FONTSET-SPEC is a string of the format:
1203 FONTSET-NAME,SCRIPT-NAME0:FONT-NAME0,SCRIPT-NAME1:FONT-NAME1, ...
1204 Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
1205
1206 When a frame uses the fontset as the `font' parameter, the frame's
1207 default font name is derived from FONTSET-NAME by substituting
1208 \"iso8859-1\" for the tail part \"fontset-XXX\". But, if SCRIPT-NAMEn
1209 is \"ascii\", use the corresponding FONT-NAMEn as the default font
1210 name.
1211
1212 Optional 2nd and 3rd arguments exist just for backward compatibility,
1213 and are ignored.
1214
1215 It returns a name of the created fontset.
1216
1217 For backward compatibility, SCRIPT-NAME may be a charset name, in
1218 which case, the corresponding script is decided by the variable
1219 `charset-script-alist' (which see)."
1220 (or (string-match "^[^,]+" fontset-spec)
1221 (error "Invalid fontset spec: %s" fontset-spec))
1222 (let ((idx (match-end 0))
1223 (name (match-string 0 fontset-spec))
1224 default-spec target script fontlist)
1225 (or (string-match xlfd-tight-regexp name)
1226 (error "Fontset name \"%s\" not conforming to XLFD" name))
1227 (setq default-spec (font-spec :name name))
1228 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
1229 (while (string-match "[, \t\n]*\\([^:]+\\):[ \t]*\\([^,]+\\)"
1230 fontset-spec idx)
1231 (setq idx (match-end 0))
1232 (setq target (intern (match-string 1 fontset-spec)))
1233 (cond ((or (eq target 'ascii)
1234 (memq target (char-table-extra-slot char-script-table 0)))
1235 (push (list target (match-string 2 fontset-spec)) fontlist))
1236 ((setq script (cdr (assq target charset-script-alist)))
1237 (push (list script (match-string 2 fontset-spec)) fontlist))
1238 ((charsetp target)
1239 (push (list target (match-string 2 fontset-spec)) fontlist))))
1240
1241 ;; Complement FONTLIST.
1242 (setq fontlist (x-complement-fontset-spec default-spec fontlist))
1243
1244 ;; Create a fontset.
1245 (new-fontset name (nreverse fontlist))))
1246
1247 (defun create-fontset-from-ascii-font (font &optional resolved-font
1248 fontset-name)
1249 "Create a fontset from an ASCII font FONT.
1250
1251 Optional 2nd arg RESOLVED-FONT is a resolved name of FONT.
1252 If omitted, `x-resolve-font-name' is called to get the resolved name.
1253 At this time, if FONT is not available, an error is signaled.
1254
1255 Optional 3rd arg FONTSET-NAME is a string to be used in
1256 `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
1257 an appropriate name is generated automatically.
1258
1259 It returns a name of the created fontset."
1260 (setq font (downcase font))
1261 (setq resolved-font
1262 (downcase (or resolved-font (x-resolve-font-name font))))
1263 (let ((xlfd (x-decompose-font-name resolved-font))
1264 fontset)
1265 (if fontset-name
1266 (setq fontset-name (downcase fontset-name))
1267 (if (query-fontset "fontset-startup")
1268 (setq fontset-name
1269 (subst-char-in-string
1270 ?- ?_ (aref xlfd xlfd-regexp-registry-subnum) t))
1271 (setq fontset-name "startup")))
1272 (aset xlfd xlfd-regexp-registry-subnum
1273 (format "fontset-%s" fontset-name))
1274 (setq fontset (x-compose-font-name xlfd))
1275 (or (query-fontset fontset)
1276 (create-fontset-from-fontset-spec (concat fontset ", ascii:" font)))))
1277
1278 \f
1279 ;; Create standard fontset from 16 dots fonts which are the most widely
1280 ;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
1281 ;; specified here because FAMILY of those fonts are not "fixed" in
1282 ;; many cases.
1283 (defvar standard-fontset-spec
1284 (purecopy "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard")
1285 "String of fontset spec of the standard fontset.
1286 You have the biggest chance to display international characters
1287 with correct glyphs by using the standard fontset.
1288 See the documentation of `create-fontset-from-fontset-spec' for the format.")
1289
1290
1291 ;; Create fontsets from X resources of the name `fontset-N (class
1292 ;; Fontset-N)' where N is integer 0, 1, ...
1293 ;; The values of the resources the string of the same format as
1294 ;; `standard-fontset-spec'.
1295
1296 (declare-function x-get-resource "frame.c"
1297 (attribute class &optional component subclass))
1298
1299 (defun create-fontset-from-x-resource ()
1300 (let ((idx 0)
1301 fontset-spec)
1302 (while (setq fontset-spec (x-get-resource (format "fontset-%d" idx)
1303 (format "Fontset-%d" idx)))
1304 (condition-case nil
1305 (create-fontset-from-fontset-spec fontset-spec t)
1306 (error (display-warning
1307 'initialization
1308 (format "Fontset-%d: invalid specification in X resource" idx)
1309 :warning)))
1310 (setq idx (1+ idx)))))
1311
1312 ;;
1313 (provide 'fontset)
1314
1315 ;;; fontset.el ends here