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