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