Document and fix some bugs with side windows
[emacs.git] / lisp / international / fontset.el
blob612c0a08ad7db51d5e656e9e02fbef284f886fb6
1 ;;; fontset.el --- commands for handling fontset
3 ;; Copyright (C) 1997-2016 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 "Symbola" nil 'prepend))
816 ;; Box Drawing and Block Elements
817 (set-fontset-font "fontset-default" '(#x2500 . #x259F)
818 "FreeMono" nil 'prepend)
820 ;; Since standard-fontset-spec on X uses fixed-medium font, which
821 ;; gets mapped to a iso8859-1 variant, we would like to prefer its
822 ;; iso10646-1 variant for symbols, where the coverage is known to be
823 ;; good.
824 (dolist (symbol-subgroup
825 '((#x2000 . #x206F) ;; General Punctuation
826 (#x2070 . #x209F) ;; Superscripts and Subscripts
827 (#x20A0 . #x20CF) ;; Currency Symbols
828 (#x2150 . #x218F) ;; Number Forms
829 (#x2190 . #x21FF) ;; Arrows
830 (#x2200 . #x22FF) ;; Mathematical Operators
831 (#x2300 . #x23FF) ;; Miscellaneous Technical
832 (#x2400 . #x243F) ;; Control Pictures
833 (#x2440 . #x245F) ;; Optical Char Recognition
834 (#x2460 . #x24FF) ;; Enclosed Alphanumerics
835 (#x2500 . #x257F) ;; Box Drawing
836 (#x2580 . #x259F) ;; Block Elements
837 (#x25A0 . #x25FF) ;; Geometric Shapes
838 (#x2600 . #x2689) ;; Miscellaneous Symbols
839 (#x2700 . #x27bF) ;; Dingbats
840 (#x27F5 . #x27FF))) ;; Supplemental Arrows-A
841 (set-fontset-font "fontset-default" symbol-subgroup
842 "-*-fixed-medium-*-*-*-*-*-*-*-*-*-iso10646-1"
843 nil 'prepend))
845 ;; Append CJK fonts for characters other than han, kana, cjk-misc.
846 ;; Append fonts for scripts whose name is also a charset name.
847 (let* ((data (build-default-fontset-data))
848 (registries (car data)))
849 (dolist (target-spec (cdr data))
850 (let ((target (car target-spec))
851 (spec (cdr target-spec)))
852 (if (integerp spec)
853 (dotimes (i (length registries))
854 (if (> (logand spec (lsh 1 i)) 0)
855 (set-fontset-font "fontset-default" target
856 (cons nil (aref registries i))
857 nil 'append)))
858 (dolist (args spec)
859 (set-fontset-font "fontset-default" target
860 (apply 'font-spec args) nil 'append))))))
862 ;; Append Unicode fonts.
863 ;; This may find fonts with more variants (bold, italic) but which
864 ;; don't cover many characters.
865 (set-fontset-font "fontset-default" nil
866 '(nil . "iso10646-1") nil 'prepend)
867 ;; These may find fonts that cover many characters but with fewer
868 ;; variants.
869 (set-fontset-font "fontset-default" nil
870 '("gnu-unifont" . "iso10646-1") nil 'prepend)
871 (set-fontset-font "fontset-default" nil
872 '("mutt-clearlyu" . "iso10646-1") nil 'prepend)
873 (set-fontset-font "fontset-default" '(#x20000 . #x2FFFF)
874 '(nil . "unicode-sip"))
876 (set-fontset-font "fontset-default" '(#xE000 . #xF8FF)
877 '(nil . "iso10646-1"))
878 ;; Don't try the fallback fonts even if no suitable font was found
879 ;; by the above font-spec.
880 (set-fontset-font "fontset-default" '(#xE000 . #xF8FF) nil nil 'append))
882 (defun create-default-fontset ()
883 "Create the default fontset.
884 Internal use only. Should be called at startup time."
885 (condition-case err
886 (setup-default-fontset)
887 (error (display-warning
888 'initialization
889 (format "Creation of the default fontsets failed: %s" err)
890 :error))))
892 ;; These are the registered registries/encodings from
893 ;; ftp://ftp.x.org/pub/DOCS/registry 2001/06/01
895 ;; Name Reference
896 ;; ---- ---------
897 ;; "DEC" [27]
898 ;; registry prefix
899 ;; "DEC.CNS11643.1986-2" [53]
900 ;; CNS11643 2-plane using the encoding
901 ;; suggested in that standard
902 ;; "DEC.DTSCS.1990-2" [54]
903 ;; DEC Taiwan Supplemental Character Set
904 ;; "fujitsu.u90x01.1991-0" [87]
905 ;; "fujitsu.u90x03.1991-0" [87]
906 ;; "GB2312.1980-0" [39],[12]
907 ;; China (PRC) Hanzi, GL encoding
908 ;; "GB2312.1980-1" [39]
909 ;; (deprecated)
910 ;; China (PRC) Hanzi, GR encoding
911 ;; "HP-Arabic8" [36]
912 ;; HPARABIC8 8-bit character set
913 ;; "HP-East8" [36]
914 ;; HPEAST8 8-bit character set
915 ;; "HP-Greek8" [36]
916 ;; HPGREEK8 8-bit character set
917 ;; "HP-Hebrew8" [36]
918 ;; HPHEBREW8 8-bit character set
919 ;; "HP-Japanese15" [36]
920 ;; HPJAPAN15 15-bit character set,
921 ;; modified from industry de facto
922 ;; standard Shift-JIS
923 ;; "HP-Kana8" [36]
924 ;; HPKANA8 8-bit character set
925 ;; "HP-Korean15" [36]
926 ;; HPKOREAN15 15-bit character set
927 ;; "HP-Roman8" [36]
928 ;; HPROMAN8 8-bit character set
929 ;; "HP-SChinese15" [36]
930 ;; HPSCHINA15 15-bit character set for
931 ;; support of Simplified Chinese
932 ;; "HP-TChinese15" [36]
933 ;; HPTCHINA15 15-bit character set for
934 ;; support of Traditional Chinese
935 ;; "HP-Turkish8" [36]
936 ;; HPTURKISH8 8-bit character set
937 ;; "IPSYS" [59]
938 ;; registry prefix
939 ;; "IPSYS.IE-1" [59]
940 ;; "ISO2022"<REG>"-"<ENC> [44]
941 ;; "ISO646.1991-IRV" [107]
942 ;; ISO 646 International Reference Version
943 ;; "ISO8859-1" [15],[12]
944 ;; ISO Latin alphabet No. 1
945 ;; "ISO8859-2" [15],[12]
946 ;; ISO Latin alphabet No. 2
947 ;; "ISO8859-3" [15],[12]
948 ;; ISO Latin alphabet No. 3
949 ;; "ISO8859-4" [15],[12]
950 ;; ISO Latin alphabet No. 4
951 ;; "ISO8859-5" [15],[12]
952 ;; ISO Latin/Cyrillic alphabet
953 ;; "ISO8859-6" [15],[12]
954 ;; ISO Latin/Arabic alphabet
955 ;; "ISO8859-7" [15],[12]
956 ;; ISO Latin/Greek alphabet
957 ;; "ISO8859-8" [15],[12]
958 ;; ISO Latin/Hebrew alphabet
959 ;; "ISO8859-9" [15],[12]
960 ;; ISO Latin alphabet No. 5
961 ;; "ISO8859-10" [15],[12]
962 ;; ISO Latin alphabet No. 6
963 ;; "ISO8859-13" [15],[12]
964 ;; ISO Latin alphabet No. 7
965 ;; "ISO8859-14" [15],[12]
966 ;; ISO Latin alphabet No. 8
967 ;; "ISO8859-15" [15],[12]
968 ;; ISO Latin alphabet No. 9
969 ;; "FCD8859-15" [7]
970 ;; (deprecated)
971 ;; ISO Latin alphabet No. 9, Final Committee Draft
972 ;; "ISO10646-1" [133]
973 ;; Unicode Universal Multiple-Octet Coded Character Set
974 ;; "ISO10646-MES" [133]
975 ;; (deprecated)
976 ;; Unicode Minimum European Subset
977 ;; "JISX0201.1976-0" [38],[12]
978 ;; 8-Bit Alphanumeric-Katakana Code
979 ;; "JISX0208.1983-0" [40],[12]
980 ;; Japanese Graphic Character Set,
981 ;; GL encoding
982 ;; "JISX0208.1990-0" [71]
983 ;; Japanese Graphic Character Set,
984 ;; GL encoding
985 ;; "JISX0208.1983-1" [40]
986 ;; (deprecated)
987 ;; Japanese Graphic Character Set,
988 ;; GR encoding
989 ;; "JISX0212.1990-0" [72]
990 ;; Supplementary Japanese Graphic Character Set,
991 ;; GL encoding
992 ;; "KOI8-R" [119]
993 ;; Cyrillic alphabet
994 ;; "KSC5601.1987-0" [41],[12]
995 ;; Korean Graphic Character Set,
996 ;; GL encoding
997 ;; "KSC5601.1987-1" [41]
998 ;; (deprecated)
999 ;; Korean Graphic Character Set,
1000 ;; GR encoding
1001 ;; "omron_CNS11643-0" [45]
1002 ;; "omron_CNS11643-1" [45]
1003 ;; "omron_BIG5-0" [45]
1004 ;; "omron_BIG5-1" [45]
1005 ;; "wn.tamil.1993" [103]
1007 (defun set-font-encoding (pattern charset)
1008 "Set arguments in `font-encoding-alist' (which see)."
1009 (let ((slot (assoc pattern font-encoding-alist)))
1010 (if slot
1011 (setcdr slot charset)
1012 (setq font-encoding-alist
1013 (cons (cons pattern charset) font-encoding-alist)))))
1015 (defvar x-pixel-size-width-font-regexp)
1016 (defvar vertical-centering-font-regexp)
1018 ;; Setting for suppressing XLoadQueryFont on big fonts.
1019 (setq x-pixel-size-width-font-regexp
1020 (purecopy "gb2312\\|gbk\\|gb18030\\|jisx0208\\|ksc5601\\|cns11643\\|big5"))
1022 ;; These fonts require vertical centering.
1023 (setq vertical-centering-font-regexp
1024 (purecopy "gb2312\\|gbk\\|gb18030\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5"))
1025 (put 'vertical-centering-font-regexp 'standard-value
1026 (list vertical-centering-font-regexp))
1028 ;; CDAC fonts are actually smaller than their design sizes.
1029 (setq face-font-rescale-alist
1030 (list (cons (purecopy "-cdac$") 1.3)))
1032 (defvar x-font-name-charset-alist nil
1033 "This variable has no meaning now. Just kept for backward compatibility.")
1035 ;;; XLFD (X Logical Font Description) format handler.
1037 ;; Define XLFD's field index numbers. ; field name
1038 (defconst xlfd-regexp-family-subnum 0) ; FOUNDRY and FAMILY
1039 (defconst xlfd-regexp-weight-subnum 1) ; WEIGHT_NAME
1040 (defconst xlfd-regexp-slant-subnum 2) ; SLANT
1041 (defconst xlfd-regexp-swidth-subnum 3) ; SETWIDTH_NAME
1042 (defconst xlfd-regexp-adstyle-subnum 4) ; ADD_STYLE_NAME
1043 (defconst xlfd-regexp-pixelsize-subnum 5) ; PIXEL_SIZE
1044 (defconst xlfd-regexp-pointsize-subnum 6) ; POINT_SIZE
1045 (defconst xlfd-regexp-resx-subnum 7) ; RESOLUTION_X
1046 (defconst xlfd-regexp-resy-subnum 8) ; RESOLUTION_Y
1047 (defconst xlfd-regexp-spacing-subnum 8) ; SPACING
1048 (defconst xlfd-regexp-avgwidth-subnum 10) ; AVERAGE_WIDTH
1049 (defconst xlfd-regexp-registry-subnum 11) ; REGISTRY and ENCODING
1051 ;; Regular expression matching against a fontname which conforms to
1052 ;; XLFD (X Logical Font Description). All fields in XLFD should be
1053 ;; not be omitted (but can be a wild card) to be matched.
1054 (defconst xlfd-tight-regexp
1056 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
1057 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
1058 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*-[^-]*\\)$")
1060 ;; Regular expression matching against a fontname which conforms to
1061 ;; XLFD (X Logical Font Description). All fields in XLFD from FOUNDRY
1062 ;; to ADSTYLE, REGISTRY, and ENCODING should be not be omitted (but
1063 ;; can be a wild card) to be matched.
1064 (defconst xlfd-style-regexp
1066 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-.*\
1067 -\\([^-]*-[^-]*\\)$")
1069 ;; List of field numbers of XLFD whose values are numeric.
1070 (defconst xlfd-regexp-numeric-subnums
1071 (list xlfd-regexp-pixelsize-subnum ;5
1072 xlfd-regexp-pointsize-subnum ;6
1073 xlfd-regexp-resx-subnum ;7
1074 xlfd-regexp-resy-subnum ;8
1075 xlfd-regexp-avgwidth-subnum ;10
1078 (defun x-decompose-font-name (pattern)
1079 "Decompose PATTERN into XLFD fields and return a vector of the fields.
1080 The length of the vector is 12.
1081 The FOUNDRY and FAMILY fields are concatenated and stored in the first
1082 element of the vector.
1083 The REGISTRY and ENCODING fields are concatenated and stored in the last
1084 element of the vector.
1086 Return nil if PATTERN doesn't conform to XLFD."
1087 (if (string-match xlfd-tight-regexp pattern)
1088 (let ((xlfd-fields (make-vector 12 nil)))
1089 (dotimes (i 12)
1090 (aset xlfd-fields i (match-string (1+ i) pattern)))
1091 (dotimes (i 12)
1092 (if (string-match "^[*-]+$" (aref xlfd-fields i))
1093 (aset xlfd-fields i nil)))
1094 xlfd-fields)))
1096 (defun x-compose-font-name (fields &optional _reduce)
1097 "Compose X fontname from FIELDS.
1098 FIELDS is a vector of XLFD fields, of length 12.
1099 If a field is nil, wild-card letter `*' is embedded.
1100 Optional argument REDUCE exists just for backward compatibility,
1101 and is always ignored."
1102 (concat "-" (mapconcat (lambda (x) (or x "*")) fields "-")))
1105 (defun x-must-resolve-font-name (xlfd-fields)
1106 "Like `x-resolve-font-name', but always return a font name.
1107 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
1108 If no font matching XLFD-FIELDS is available, successively replace
1109 parts of the font name pattern with \"*\" until some font is found.
1110 Value is name of that font."
1111 (let ((ascii-font nil) (index 0))
1112 (while (and (null ascii-font) (<= index xlfd-regexp-registry-subnum))
1113 (let ((pattern (x-compose-font-name xlfd-fields)))
1114 (condition-case nil
1115 (setq ascii-font (x-resolve-font-name pattern))
1116 (error
1117 (message "Warning: no fonts matching `%s' available" pattern)
1118 (aset xlfd-fields index "*")
1119 (setq index (1+ index))))))
1120 (unless ascii-font
1121 (error "No fonts found"))
1122 ascii-font))
1125 (defun x-complement-fontset-spec (default-spec fontlist)
1126 "Complement elements of FONTLIST based on DEFAULT-SPEC.
1127 DEFAULT-SPEC is a font-spec object providing default font properties.
1128 FONTLIST is an alist of script names vs the corresponding font names.
1130 The font names are parsed and unspecified font properties are
1131 given from DEFAULT-SPEC."
1132 (let ((prop-list '(:foundry :family :weight :slant :width :adstyle :size)))
1133 (dolist (elt fontlist)
1134 (let ((spec (font-spec :name (cadr elt))))
1135 (dolist (prop prop-list)
1136 (let ((val (font-get spec prop)))
1137 (or val
1138 (font-put spec prop (font-get default-spec prop)))))
1139 (setcar (cdr elt) spec)))
1140 fontlist))
1142 (defun fontset-name-p (fontset)
1143 "Return non-nil if FONTSET is valid as fontset name.
1144 A valid fontset name should conform to XLFD (X Logical Font Description)
1145 with \"fontset\" in `<CHARSET_REGISTRY>' field."
1146 (and (string-match xlfd-tight-regexp fontset)
1147 (string= (match-string (1+ xlfd-regexp-registry-subnum) fontset)
1148 "fontset")))
1150 (declare-function fontset-list "fontset.c" ())
1152 (defun generate-fontset-menu ()
1153 "Return list to be appended to `x-fixed-font-alist'.
1154 Done when `mouse-set-font' is called."
1155 (let (l)
1156 (dolist (fontset (fontset-list))
1157 (or (string-match "fontset-default$" fontset)
1158 (string-match "fontset-auto[0-9]+$" fontset)
1159 (push (list (fontset-plain-name fontset) fontset) l)))
1160 (cons "Fontset"
1161 (sort l #'(lambda (x y) (string< (car x) (car y)))))))
1163 (declare-function query-fontset "fontset.c" (pattern &optional regexpp))
1165 (defun fontset-plain-name (fontset)
1166 "Return a plain and descriptive name of FONTSET."
1167 (if (not (setq fontset (query-fontset fontset)))
1168 (error "Invalid fontset: %s" fontset))
1169 (let ((xlfd-fields (x-decompose-font-name fontset)))
1170 (if xlfd-fields
1171 (let ((family (aref xlfd-fields xlfd-regexp-family-subnum))
1172 (weight (aref xlfd-fields xlfd-regexp-weight-subnum))
1173 (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
1174 ;(swidth (aref xlfd-fields xlfd-regexp-swidth-subnum))
1175 (size (aref xlfd-fields xlfd-regexp-pixelsize-subnum))
1176 (nickname (aref xlfd-fields xlfd-regexp-registry-subnum))
1177 name)
1178 (if (not (string-match "^fontset-\\(.*\\)$" nickname))
1179 (setq nickname family)
1180 (setq nickname (match-string 1 nickname)))
1181 (if (and size (> (string-to-number size) 0))
1182 (setq name (format "%s: %s-dot" nickname size))
1183 (setq name nickname))
1184 (and weight
1185 (cond ((string-match "^medium$" weight)
1186 (setq name (concat name " " "medium")))
1187 ((string-match "^bold$\\|^demibold$" weight)
1188 (setq name (concat name " " weight)))))
1189 (and slant
1190 (cond ((string-match "^i$" slant)
1191 (setq name (concat name " " "italic")))
1192 ((string-match "^o$" slant)
1193 (setq name (concat name " " "slant")))
1194 ((string-match "^ri$" slant)
1195 (setq name (concat name " " "reverse italic")))
1196 ((string-match "^ro$" slant)
1197 (setq name (concat name " " "reverse slant")))))
1198 name)
1199 fontset)))
1201 (defvar charset-script-alist
1202 '((ascii . latin)
1203 (latin-iso8859-1 . latin)
1204 (latin-iso8859-2 . latin)
1205 (latin-iso8859-3 . latin)
1206 (latin-iso8859-4 . latin)
1207 (latin-iso8859-9 . latin)
1208 (latin-iso8859-10 . latin)
1209 (latin-iso8859-13 . latin)
1210 (latin-iso8859-14 . latin)
1211 (latin-iso8859-15 . latin)
1212 (latin-iso8859-16 . latin)
1213 (latin-jisx0201 . latin)
1214 (thai-tis620 . thai)
1215 (cyrillic-iso8859-5 . cyrillic)
1216 (arabic-iso8859-6 . arabic)
1217 (greek-iso8859-7 . latin)
1218 (hebrew-iso8859-8 . latin)
1219 (katakana-jisx0201 . kana)
1220 (chinese-gb2312 . han)
1221 (chinese-gbk . han)
1222 (gb18030-2-byte . han)
1223 (gb18030-4-byte-bmp . han)
1224 (gb18030-4-byte-ext-1 . han)
1225 (gb18030-4-byte-ext-2 . han)
1226 (gb18030-4-byte-smp . han)
1227 (chinese-big5-1 . han)
1228 (chinese-big5-2 . han)
1229 (chinese-cns11643-1 . han)
1230 (chinese-cns11643-2 . han)
1231 (chinese-cns11643-3 . han)
1232 (chinese-cns11643-4 . han)
1233 (chinese-cns11643-5 . han)
1234 (chinese-cns11643-6 . han)
1235 (chinese-cns11643-7 . han)
1236 (japanese-jisx0208 . han)
1237 (japanese-jisx0208-1978 . han)
1238 (japanese-jisx0212 . han)
1239 (japanese-jisx0213-1 . han)
1240 (japanese-jisx0213-2 . han)
1241 (korean-ksc5601 . hangul)
1242 (chinese-sisheng . bopomofo)
1243 (vietnamese-viscii-lower . latin)
1244 (vietnamese-viscii-upper . latin)
1245 (arabic-digit . arabic)
1246 (arabic-1-column . arabic)
1247 (arabic-2-column . arabic)
1248 (indian-is13194 . devanagari)
1249 (indian-glyph . devanagari)
1250 (indian-1-column . devanagari)
1251 (indian-2-column . devanagari)
1252 (tibetan-1-column . tibetan))
1253 "Alist of charsets vs the corresponding most appropriate scripts.
1255 This alist is used by the function `create-fontset-from-fontset-spec'
1256 to map charsets to scripts.")
1258 (defun create-fontset-from-fontset-spec (fontset-spec
1259 &optional _style-variant _noerror)
1260 "Create a fontset from fontset specification string FONTSET-SPEC.
1261 FONTSET-SPEC is a string of the format:
1262 FONTSET-NAME[,SCRIPT-NAME0:FONT-NAME0,SCRIPT-NAME1:FONT-NAME1] ...
1263 Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
1265 When a frame uses the fontset as the `font' parameter, the frame's
1266 default font name is derived from FONTSET-NAME by substituting
1267 \"iso8859-1\" for the tail part \"fontset-XXX\". But, if SCRIPT-NAMEn
1268 is \"ascii\", use the corresponding FONT-NAMEn as the default font
1269 name.
1271 Optional 2nd and 3rd arguments exist just for backward compatibility,
1272 and are ignored.
1274 It returns a name of the created fontset.
1276 For backward compatibility, SCRIPT-NAME may be a charset name, in
1277 which case, the corresponding script is decided by the variable
1278 `charset-script-alist' (which see)."
1279 (or (string-match "^[^,]+" fontset-spec)
1280 (error "Invalid fontset spec: %s" fontset-spec))
1281 (let ((idx (match-end 0))
1282 (name (match-string 0 fontset-spec))
1283 default-spec target script fontlist)
1284 (or (string-match xlfd-tight-regexp name)
1285 (error "Fontset name \"%s\" not conforming to XLFD" name))
1286 (setq default-spec (font-spec :name name))
1287 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
1288 (while (string-match "[, \t\n]*\\([^:]+\\):[ \t]*\\([^,]+\\)"
1289 fontset-spec idx)
1290 (setq idx (match-end 0))
1291 (setq target (intern (match-string 1 fontset-spec)))
1292 (cond ((or (eq target 'ascii)
1293 (memq target (char-table-extra-slot char-script-table 0)))
1294 (push (list target (match-string 2 fontset-spec)) fontlist))
1295 ((setq script (cdr (assq target charset-script-alist)))
1296 (push (list script (match-string 2 fontset-spec)) fontlist))
1297 ((charsetp target)
1298 (push (list target (match-string 2 fontset-spec)) fontlist))))
1300 ;; Complement FONTLIST.
1301 (setq fontlist (x-complement-fontset-spec default-spec fontlist))
1303 ;; Create a fontset.
1304 (new-fontset name (nreverse fontlist))))
1306 (defun create-fontset-from-ascii-font (font &optional resolved-font
1307 fontset-name)
1308 "Create a fontset from an ASCII font FONT.
1310 Optional 2nd arg RESOLVED-FONT is a resolved name of FONT.
1311 If omitted, `x-resolve-font-name' is called to get the resolved name.
1312 At this time, if FONT is not available, an error is signaled.
1314 Optional 3rd arg FONTSET-NAME is a string to be used in
1315 `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
1316 an appropriate name is generated automatically.
1318 It returns a name of the created fontset."
1319 (setq font (downcase font))
1320 (setq resolved-font
1321 (downcase (or resolved-font (x-resolve-font-name font))))
1322 (let ((xlfd (x-decompose-font-name resolved-font))
1323 fontset)
1324 (if fontset-name
1325 (setq fontset-name (downcase fontset-name))
1326 (if (query-fontset "fontset-startup")
1327 (setq fontset-name
1328 (subst-char-in-string
1329 ?- ?_ (aref xlfd xlfd-regexp-registry-subnum) t))
1330 (setq fontset-name "startup")))
1331 (aset xlfd xlfd-regexp-registry-subnum
1332 (format "fontset-%s" fontset-name))
1333 (setq fontset (x-compose-font-name xlfd))
1334 (or (query-fontset fontset)
1335 (create-fontset-from-fontset-spec (concat fontset ", ascii:" font)))))
1338 ;; Create standard fontset from 16 dots fonts which are the most widely
1339 ;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
1340 ;; specified here because FAMILY of those fonts are not "fixed" in
1341 ;; many cases.
1342 (defvar standard-fontset-spec
1343 (purecopy "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard")
1344 "String of fontset spec of the standard fontset.
1345 You have the biggest chance to display international characters
1346 with correct glyphs by using the standard fontset.
1347 See the documentation of `create-fontset-from-fontset-spec' for the format.")
1350 ;; Create fontsets from X resources of the name `fontset-N (class
1351 ;; Fontset-N)' where N is integer 0, 1, ...
1352 ;; The values of the resources the string of the same format as
1353 ;; `standard-fontset-spec'.
1355 (declare-function x-get-resource "frame.c"
1356 (attribute class &optional component subclass))
1358 (defun create-fontset-from-x-resource ()
1359 (let ((idx 0)
1360 fontset-spec)
1361 (while (setq fontset-spec (x-get-resource (format "fontset-%d" idx)
1362 (format "Fontset-%d" idx)))
1363 (condition-case nil
1364 (create-fontset-from-fontset-spec fontset-spec t)
1365 (error (display-warning
1366 'initialization
1367 (format "Fontset-%d: invalid specification in X resource" idx)
1368 :warning)))
1369 (setq idx (1+ idx)))))
1372 (provide 'fontset)
1374 ;;; fontset.el ends here