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