Update copyright year to 2015
[emacs.git] / lisp / international / fontset.el
blob8eb1c0d3961b621b7f680976979c36b886f6e1c8
1 ;;; fontset.el --- commands for handling fontset
3 ;; Copyright (C) 1997-2015 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
6 ;; National Institute of Advanced Industrial Science and Technology (AIST)
7 ;; Registration Number H14PRO021
8 ;; Copyright (C) 2003, 2006
9 ;; National Institute of Advanced Industrial Science and Technology (AIST)
10 ;; Registration Number H13PRO009
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 (arabic #x628)
157 (syriac #x710)
158 (thaana #x78C)
159 (devanagari #x915)
160 (bengali #x995)
161 (gurmukhi #xA15)
162 (gujarati #xA95)
163 (oriya #xB15)
164 (tamil #xB95)
165 (telugu #xC15)
166 (kannada #xC95)
167 (malayalam #xD15)
168 (sinhala #xD95)
169 (thai #xE17)
170 (lao #xEA5)
171 (tibetan #xF40)
172 (burmese #x1000)
173 (georgian #x10D3)
174 (ethiopic #x1208)
175 (cherokee #x13B6)
176 (canadian-aboriginal #x14C0)
177 (ogham #x168F)
178 (runic #x16A0)
179 (khmer #x1780)
180 (mongolian #x1826)
181 (symbol . [#x201C #x2200 #x2500])
182 (braille #x2800)
183 (ideographic-description #x2FF0)
184 (cjk-misc #x300E)
185 (kana #x304B)
186 (bopomofo #x3105)
187 (kanbun #x319D)
188 (han #x5B57)
189 (yi #xA288)
190 (cham #xAA00)
191 (tai-viet #xAA80)
192 (hangul #xAC00)
193 (linear-b #x10000)
194 (aegean-number #x10100)
195 (ancient-greek-number #x10140)
196 (ancient-symbol #x10190)
197 (phaistos-disc #x101D0)
198 (lycian #x10280)
199 (carian #x102A0)
200 (olt-italic #x10300)
201 (ugaritic #x10380)
202 (old-permic #x10350)
203 (old-persian #x103A0)
204 (deseret #x10400)
205 (shavian #x10450)
206 (osmanya #x10480)
207 (elbasan #x10500)
208 (caucasian-albanian #x10530)
209 (linear-a #x10600)
210 (cypriot-syllabary #x10800)
211 (palmyrene #x10860)
212 (nabataean #x10880)
213 (phoenician #x10900)
214 (lydian #x10920)
215 (kharoshthi #x10A00)
216 (manichaean #x10AC0)
217 (mahajani #x11150)
218 (sinhala-archaic-number #x111E1)
219 (khojki #x11200)
220 (khudawadi #x112B0)
221 (grantha #x11305)
222 (tirhuta #x11481)
223 (siddham #x11580)
224 (modi #x11600)
225 (takri #x11680)
226 (warang-citi #x118A1)
227 (pau-cin-hau #x11AC0)
228 (cuneiform #x12000)
229 (cuneiform-numbers-and-punctuation #x12400)
230 (mro #x16A40)
231 (bassa-vah #x16AD0)
232 (pahawh-hmong #x16B11)
233 (duployan-shorthand #x1BC20)
234 (byzantine-musical-symbol #x1D000)
235 (musical-symbol #x1D100)
236 (ancient-greek-musical-notation #x1D200)
237 (tai-xuan-jing-symbol #x1D300)
238 (counting-rod-numeral #x1D360)
239 (mende-kikakui #x1E810)
240 (mahjong-tile #x1F000)
241 (domino-tile #x1F030)))
243 (defvar otf-script-alist)
245 ;; The below was synchronized with the latest Jan 3, 2013 version of
246 ;; https://www.microsoft.com/typography/otspec/scripttags.htm.
247 (setq otf-script-alist
248 '((arab . arabic)
249 (armi . aramaic)
250 (armn . armenian)
251 (avst . avestan)
252 (bali . balinese)
253 (bamu . bamum)
254 (batk . batak)
255 (bng2 . bengali)
256 (beng . bengali)
257 (bopo . bopomofo)
258 (brai . braille)
259 (brah . brahmi)
260 (bugi . buginese)
261 (buhd . buhid)
262 (byzm . byzantine-musical-symbol)
263 (cans . canadian-aboriginal)
264 (cari . carian)
265 (cakm . chakma)
266 (cham . cham)
267 (cher . cherokee)
268 (copt . coptic)
269 (xsux . cuneiform)
270 (cprt . cypriot)
271 (cyrl . cyrillic)
272 (dsrt . deseret)
273 (deva . devanagari)
274 (dev2 . devanagari)
275 (egyp . egyptian)
276 (ethi . ethiopic)
277 (geor . georgian)
278 (glag . glagolitic)
279 (goth . gothic)
280 (grek . greek)
281 (gujr . gujarati)
282 (gjr2 . gujarati)
283 (guru . gurmukhi)
284 (gur2 . gurmukhi)
285 (hani . han)
286 (hang . hangul)
287 (jamo . hangul)
288 (hano . hanunoo)
289 (hebr . hebrew)
290 (phli . inscriptional-pahlavi)
291 (prti . inscriptional-parthian)
292 (java . javanese)
293 (kthi . kaithi)
294 (kana . kana) ; Hiragana
295 (knda . kannada)
296 (knd2 . kannada)
297 (kali . kayah-li)
298 (khar . kharoshthi)
299 (khmr . khmer)
300 (lao\ . lao)
301 (latn . latin)
302 (lepc . lepcha)
303 (limb . limbu)
304 (linb . linear_b)
305 (mlym . malayalam)
306 (mlm2 . malayalam)
307 (mand . mandaic)
308 (math . mathematical)
309 (mtei . meetei-mayek)
310 (merc . meroitic)
311 (mero . meroitic)
312 (mong . mongolian)
313 (musc . musical-symbol)
314 (mymr . burmese)
315 (nko\ . nko)
316 (ogam . ogham)
317 (olck . ol-chiki)
318 (ital . old_italic)
319 (xpeo . old_persian)
320 (sarb . old-south-arabian)
321 (orkh . old-turkic)
322 (orya . oriya)
323 (ory2 . oriya)
324 (osma . osmanya)
325 (phag . phags-pa)
326 (phnx . phoenician)
327 (rjng . rejang)
328 (runr . runic)
329 (samr . samaritan)
330 (saur . saurashtra)
331 (shrd . sharada)
332 (shaw . shavian)
333 (sinh . sinhala)
334 (sora . sora-sompeng)
335 (sund . sundanese)
336 (sylo . syloti_nagri)
337 (syrc . syriac)
338 (tglg . tagalog)
339 (tagb . tagbanwa)
340 (tale . tai_le)
341 (talu . tai-lue)
342 (lana . tai-tham)
343 (tavt . tai-viet)
344 (takr . takri)
345 (taml . tamil)
346 (tml2 . tamil)
347 (telu . telugu)
348 (thaa . thaana)
349 (thai . thai)
350 (tibt . tibetan)
351 (tfng . tifinagh)
352 (ugar . ugaritic)
353 (vai\ . vai)
354 (yi\ \ . yi)))
356 ;; Set standard fontname specification of characters in the default
357 ;; fontset to find an appropriate font for each script/charset. The
358 ;; specification has the form ((SCRIPT FONT-SPEC ...) ...), where
359 ;; FONT-SPEC is:
360 ;; a cons (FAMILY . REGISTRY),
361 ;; or a string FONT-NAME,
362 ;; or an object created by `font-spec'.
364 ;; FAMILY may be nil, in which case, the corresponding name of
365 ;; default face is used. If REGISTRY contains a character `-', the
366 ;; string before that is embedded in `CHARSET_REGISTRY' field, and the
367 ;; string after that is embedded in `CHARSET_ENCODING' field. If it
368 ;; does not contain `-', the whole string is embedded in
369 ;; `CHARSET_REGISTRY' field, and a wild card character `*' is embedded
370 ;; in `CHARSET_ENCODING' field.
372 ;; SCRIPT is a symbol that appears as an element of the char table
373 ;; `char-script-table'. SCRIPT may be a charset specifying the range
374 ;; of characters.
376 (declare-function new-fontset "fontset.c" (name fontlist))
377 (declare-function set-fontset-font "fontset.c"
378 (name target font-spec &optional frame add))
380 (eval-when-compile
382 ;; Build data to initialize the default fontset at compile time to
383 ;; avoid loading charsets that won't be necessary at runtime.
385 ;; The value is (CJK-REGISTRY-VECTOR TARGET-SPEC ...), where
386 ;; CJK-REGISTRY-VECTOR is ["JISX0208.1983-0" "GB2312.1980-0" ...],
387 ;; TARGET-SPEC is (TARGET . BITMASK) or (TARGET SPEC ...),
388 ;; TARGET is CHAR or (FROM-CHAR . TO-CHAR),
389 ;; BITMASK is a bitmask of indices to CJK-REGISTRY-VECTOR,
390 ;; SPEC is a list of arguments to font-spec.
392 (defmacro build-default-fontset-data ()
393 (let* (;; CHARSET-REGISTRY CHARSET FROM-CODE TO-CODE
394 (cjk '(("JISX0208.1983-0" japanese-jisx0208 #x2121 #x287E)
395 ("GB2312.1980-0" chinese-gb2312 #x2121 #x297E)
396 ("BIG5-0" big5 #xA140 #xA3FE)
397 ("CNS11643.1992-1" chinese-cns11643-1 #x2121 #x427E)
398 ("KSC5601.1987-0" korean-ksc5601 #x2121 #x2C7E)))
399 (scripts '((tibetan
400 (:registry "iso10646-1" :otf (tibt nil (ccmp blws abvs)))
401 (:family "mtib" :registry "iso10646-1")
402 (:registry "muletibetan-2"))
403 (ethiopic
404 (:registry "iso10646-1" :script ethiopic)
405 (:registry "ethiopic-unicode"))
406 (phonetic
407 (:registry "iso10646-1" :script phonetic)
408 (:registry "MuleIPA-1")
409 (:registry "iso10646-1"))))
410 (cjk-table (make-char-table nil))
411 (script-coverage
412 #'(lambda (script)
413 (let ((coverage))
414 (map-char-table
415 #'(lambda (range val)
416 (when (eq val script)
417 (if (consp range)
418 (setq range (cons (car range) (cdr range))))
419 (push range coverage)))
420 char-script-table)
421 coverage)))
422 (data (list (vconcat (mapcar 'car cjk))))
423 (i 0))
424 (dolist (elt cjk)
425 (let ((mask (lsh 1 i)))
426 (map-charset-chars
427 #'(lambda (range _arg)
428 (let ((from (car range)) (to (cdr range)))
429 (if (< to #x110000)
430 (while (<= from to)
431 (or (memq (aref char-script-table from)
432 '(kana hangul han cjk-misc))
433 (aset cjk-table from
434 (logior (or (aref cjk-table from) 0) mask)))
435 (setq from (1+ from))))))
436 (nth 1 elt) nil (nth 2 elt) (nth 3 elt)))
437 (setq i (1+ i)))
438 (map-char-table
439 #'(lambda (range val)
440 (if (consp range)
441 (setq range (cons (car range) (cdr range))))
442 (push (cons range val) data))
443 cjk-table)
444 (dolist (script scripts)
445 (dolist (range (funcall script-coverage (car script)))
446 (push (cons range (cdr script)) data)))
447 `(quote ,(nreverse data))))
450 (defun setup-default-fontset ()
451 "Setup the default fontset."
452 (new-fontset
453 "fontset-default"
454 `(;; for each script
455 (latin (nil . "ISO8859-1")
456 (nil . "ISO8859-2")
457 (nil . "ISO8859-3")
458 (nil . "ISO8859-4")
459 (nil . "ISO8859-9")
460 (nil . "ISO8859-10")
461 (nil . "ISO8859-13")
462 (nil . "ISO8859-14")
463 (nil . "ISO8859-15")
464 (nil . "ISO8859-16")
465 (nil . "VISCII1.1-1")
466 ,(font-spec :registry "iso10646-1" :script 'latin))
468 (thai ,(font-spec :registry "iso10646-1" :otf '(thai nil nil (mark)))
469 ,(font-spec :registry "iso10646-1" :script 'thai)
470 (nil . "TIS620*")
471 (nil . "ISO8859-11"))
473 (devanagari ,(font-spec :registry "iso10646-1" :otf '(deva nil (rphf)))
474 (nil . "iso10646.indian-1"))
475 (bengali ,(font-spec :registry "iso10646-1" :otf '(beng nil (rphf))))
476 (gurmukhi ,(font-spec :registry "iso10646-1" :otf '(guru nil (blwf))))
477 (gujarati ,(font-spec :registry "iso10646-1" :otf '(gujr nil (rphf))))
478 (oriya ,(font-spec :registry "iso10646-1" :otf '(orya nil (rphf))))
479 (tamil ,(font-spec :registry "iso10646-1" :otf '(taml nil (akhn))))
480 (telugu ,(font-spec :registry "iso10646-1" :otf '(telu nil (blwf))))
481 (kannada ,(font-spec :registry "iso10646-1" :otf '(knda nil (rphf))))
482 (sinhala ,(font-spec :registry "iso10646-1" :otf '(sinh nil (akhn))))
483 (malayalam ,(font-spec :registry "iso10646-1" :otf '(mlym nil (akhn))))
485 (burmese ,(font-spec :registry "iso10646-1" :otf '(mymr nil nil))
486 ,(font-spec :registry "iso10646-1" :script 'burmese))
488 (lao ,(font-spec :registry "iso10646-1" :otf '(lao\ nil nil (mark)))
489 ,(font-spec :registry "iso10646-1" :script 'lao)
490 (nil . "MuleLao-1"))
492 (tai-viet ("TaiViet" . "iso10646-1"))
494 (greek ,(font-spec :registry "iso10646-1" :script 'greek)
495 (nil . "ISO8859-7"))
497 (cyrillic ,(font-spec :registry "iso10646-1" :script 'cyrillic)
498 (nil . "ISO8859-5")
499 (nil . "microsoft-cp1251")
500 (nil . "koi8-r"))
502 (arabic ,(font-spec :registry "iso10646-1"
503 :otf '(arab nil (init medi fina liga)))
504 (nil . "MuleArabic-0")
505 (nil . "MuleArabic-1")
506 (nil . "MuleArabic-2")
507 (nil . "ISO8859-6"))
509 (hebrew ,(font-spec :registry "iso10646-1" :script 'hebrew)
510 (nil . "ISO8859-8"))
512 (khmer ,(font-spec :registry "iso10646-1" :otf '(khmr nil (pres))))
514 (kana (nil . "JISX0208*")
515 (nil . "GB2312.1980-0")
516 (nil . "KSC5601.1987*")
517 (nil . "JISX0201*")
518 (nil . "JISX0213.2000-1")
519 (nil . "JISX0213.2004-1")
520 ,(font-spec :registry "iso10646-1" :script 'kana))
522 (bopomofo ,(font-spec :registry "iso10646-1" :script 'bopomofo)
523 (nil . "sisheng_cwnn-0"))
525 (han (nil . "GB2312.1980-0")
526 (nil . "JISX0208*")
527 (nil . "JISX0212*")
528 (nil . "big5*")
529 (nil . "KSC5601.1987*")
530 (nil . "CNS11643.1992-1")
531 (nil . "CNS11643.1992-2")
532 (nil . "CNS11643.1992-3")
533 (nil . "CNS11643.1992-4")
534 (nil . "CNS11643.1992-5")
535 (nil . "CNS11643.1992-6")
536 (nil . "CNS11643.1992-7")
537 (nil . "gbk-0")
538 (nil . "gb18030")
539 (nil . "JISX0213.2000-1")
540 (nil . "JISX0213.2000-2")
541 (nil . "JISX0213.2004-1")
542 ,(font-spec :registry "iso10646-1" :lang 'ja)
543 ,(font-spec :registry "iso10646-1" :lang 'zh))
545 (cjk-misc (nil . "GB2312.1980-0")
546 (nil . "JISX0208*")
547 (nil . "JISX0212*")
548 (nil . "big5*")
549 (nil . "KSC5601.1987*")
550 (nil . "CNS11643.1992-1")
551 (nil . "CNS11643.1992-2")
552 (nil . "CNS11643.1992-3")
553 (nil . "CNS11643.1992-4")
554 (nil . "CNS11643.1992-5")
555 (nil . "CNS11643.1992-6")
556 (nil . "CNS11643.1992-7")
557 (nil . "gbk-0")
558 (nil . "gb18030")
559 (nil . "JISX0213.2000-1")
560 (nil . "JISX0213.2000-2")
561 ,(font-spec :registry "iso10646-1" :lang 'ja)
562 ,(font-spec :registry "iso10646-1" :lang 'zh))
564 (hangul (nil . "KSC5601.1987-0")
565 ,(font-spec :registry "iso10646-1" :lang 'ko))
567 ;; for each charset
568 (ascii (nil . "ISO8859-1"))
569 (arabic-digit ("*" . "MuleArabic-0"))
570 (arabic-1-column ("*" . "MuleArabic-1"))
571 (arabic-2-column ("*" . "MuleArabic-2"))
572 (indian-is13194 (nil . "is13194-devanagari"))
573 (indian-1-column ("*" . "muleindian-2"))
574 ;; Indian CDAC
575 (devanagari-cdac (nil . "Devanagari-CDAC"))
576 (sanskrit-cdac (nil . "Sanskrit-CDAC"))
577 (bengali-cdac (nil . "Bengali-CDAC"))
578 (assamese-cdac (nil . "Assamese-CDAC"))
579 (punjabi-cdac (nil . "Punjabi-CDAC"))
580 (gujarati-cdac (nil . "Gujarati-CDAC"))
581 (oriya-cdac (nil . "Oriya-CDAC"))
582 (tamil-cdac (nil . "Tamil-CDAC"))
583 (telugu-cdac (nil . "Telugu-CDAC"))
584 (kannada-cdac (nil . "Kannada-CDAC"))
585 (malayalam-cdac (nil . "Malayalam-CDAC"))
586 ;; Indian AKRUTI
587 (devanagari-akruti (nil . "Devanagari-Akruti"))
588 (bengali-akruti (nil . "Bengali-Akruti"))
589 (punjabi-akruti (nil . "Punjabi-Akruti"))
590 (gujarati-akruti (nil . "Gujarati-Akruti"))
591 (oriya-akruti (nil . "Oriya-Akruti"))
592 (tamil-akruti (nil . "Tamil-Akruti"))
593 (telugu-akruti (nil . "Telugu-Akruti"))
594 (kannada-akruti (nil . "Kannada-Akruti"))
595 (malayalam-akruti (nil . "Malayalam-Akruti"))
597 ;; Fallback fonts
598 (nil (nil . "gb2312.1980")
599 (nil . "gbk-0")
600 (nil . "gb18030")
601 (nil . "jisx0208")
602 (nil . "ksc5601.1987")
603 (nil . "CNS11643.1992-1")
604 (nil . "CNS11643.1992-2")
605 (nil . "CNS11643.1992-3")
606 (nil . "CNS11643.1992-4")
607 (nil . "CNS11643.1992-5")
608 (nil . "CNS11643.1992-6")
609 (nil . "CNS11643.1992-7")
610 (nil . "big5")
611 (nil . "jisx0213.2000-1")
612 (nil . "jisx0213.2004-1")
613 (nil . "jisx0212"))
616 ;; For simple scripts
617 (dolist (script '(phonetic
618 armenian
619 syriac
620 thaana
621 georgian
622 cherokee
623 canadian-aboriginal
624 ogham
625 runic
626 symbol
627 braille
629 aegean-number
630 ancient-greek-number
631 ancient-symbol
632 phaistos-disc
633 lycian
634 carian
635 olt-italic
636 ugaritic
637 old-persian
638 deseret
639 shavian
640 osmanya
641 cypriot-syllabary
642 phoenician
643 lydian
644 kharoshthi
645 cuneiform
646 cuneiform-numbers-and-punctuation
647 byzantine-musical-symbol
648 musical-symbol
649 ancient-greek-musical-notation
650 tai-xuan-jing-symbol
651 counting-rod-numeral
652 mahjong-tile
653 domino-tile))
654 (set-fontset-font "fontset-default"
655 script (font-spec :registry "iso10646-1" :script script)
656 nil 'append))
658 ;; Special settings for `MATHEMATICAL (U+1D400..U+1D7FF)'.
659 (dolist (math-subgroup '((#x1D400 #x1D433 mathematical-bold)
660 (#x1D434 #x1D467 mathematical-italic)
661 (#x1D468 #x1D49B mathematical-bold-italic)
662 (#x1D49C #x1D4CF mathematical-script)
663 (#x1D4D0 #x1D503 mathematical-bold-script)
664 (#x1D504 #x1D537 mathematical-fraktur)
665 (#x1D538 #x1D56B mathematical-double-struck)
666 (#x1D56C #x1D59F mathematical-bold-fraktur)
667 (#x1D5A0 #x1D5D3 mathematical-sans-serif)
668 (#x1D5D4 #x1D607 mathematical-sans-serif-bold)
669 (#x1D608 #x1D63B mathematical-sans-serif-italic)
670 (#x1D63C #x1D66F mathematical-sans-serif-bold-italic)
671 (#x1D670 #x1D6A3 mathematical-monospace)
672 (#x1D6A4 #x1D6A5 mathematical-italic)
673 (#x1D6A8 #x1D6E1 mathematical-bold)
674 (#x1D6E2 #x1D71B mathematical-italic)
675 (#x1D71C #x1D755 mathematical-bold-italic)
676 (#x1D756 #x1D78F mathematical-sans-serif-bold)
677 (#x1D790 #x1D7C9 mathematical-sans-serif-bold-italic)
678 (#x1D7CA #x1D7D7 mathematical-bold)
679 (#x1D7D8 #x1D7E1 mathematical-double-struck)
680 (#x1D7E2 #x1D7EB mathematical-sans-serif)
681 (#x1D7EC #x1D7F5 mathematical-sans-serif-bold)
682 (#x1D7F6 #x1D7FF mathematical-monospace)))
683 (let ((slot (assq (nth 2 math-subgroup) script-representative-chars)))
684 (if slot
685 (if (vectorp (cdr slot))
686 (setcdr slot (vconcat (cdr slot) (vector (car math-subgroup))))
687 (setcdr slot (vector (cadr slot) (car math-subgroup))))
688 (setq slot (list (nth 2 math-subgroup) (car math-subgroup)))
689 (nconc script-representative-chars (list slot))))
690 (set-fontset-font
691 "fontset-default"
692 (cons (car math-subgroup) (nth 1 math-subgroup))
693 (font-spec :registry "iso10646-1" :script (nth 2 math-subgroup))))
695 ;; Append CJK fonts for characters other than han, kana, cjk-misc.
696 ;; Append fonts for scripts whose name is also a charset name.
697 (let* ((data (build-default-fontset-data))
698 (registries (car data)))
699 (dolist (target-spec (cdr data))
700 (let ((target (car target-spec))
701 (spec (cdr target-spec)))
702 (if (integerp spec)
703 (dotimes (i (length registries))
704 (if (> (logand spec (lsh 1 i)) 0)
705 (set-fontset-font "fontset-default" target
706 (cons nil (aref registries i))
707 nil 'append)))
708 (dolist (args spec)
709 (set-fontset-font "fontset-default" target
710 (apply 'font-spec args) nil 'append))))))
712 ;; Append Unicode fonts.
713 ;; This may find fonts with more variants (bold, italic) but which
714 ;; don't cover many characters.
715 (set-fontset-font "fontset-default" nil
716 '(nil . "iso10646-1") nil 'prepend)
717 ;; These may find fonts that cover many characters but with fewer
718 ;; variants.
719 (set-fontset-font "fontset-default" nil
720 '("gnu-unifont" . "iso10646-1") nil 'prepend)
721 (set-fontset-font "fontset-default" nil
722 '("mutt-clearlyu" . "iso10646-1") nil 'prepend)
723 (set-fontset-font "fontset-default" '(#x20000 . #x2FFFF)
724 '(nil . "unicode-sip"))
726 (set-fontset-font "fontset-default" '(#xE000 . #xF8FF)
727 '(nil . "iso10646-1"))
728 ;; Don't try the fallback fonts even if no suitable font was found
729 ;; by the above font-spec.
730 (set-fontset-font "fontset-default" '(#xE000 . #xF8FF) nil nil 'append))
732 (defun create-default-fontset ()
733 "Create the default fontset.
734 Internal use only. Should be called at startup time."
735 (condition-case err
736 (setup-default-fontset)
737 (error (display-warning
738 'initialization
739 (format "Creation of the default fontsets failed: %s" err)
740 :error))))
742 ;; These are the registered registries/encodings from
743 ;; ftp://ftp.x.org/pub/DOCS/registry 2001/06/01
745 ;; Name Reference
746 ;; ---- ---------
747 ;; "DEC" [27]
748 ;; registry prefix
749 ;; "DEC.CNS11643.1986-2" [53]
750 ;; CNS11643 2-plane using the encoding
751 ;; suggested in that standard
752 ;; "DEC.DTSCS.1990-2" [54]
753 ;; DEC Taiwan Supplemental Character Set
754 ;; "fujitsu.u90x01.1991-0" [87]
755 ;; "fujitsu.u90x03.1991-0" [87]
756 ;; "GB2312.1980-0" [39],[12]
757 ;; China (PRC) Hanzi, GL encoding
758 ;; "GB2312.1980-1" [39]
759 ;; (deprecated)
760 ;; China (PRC) Hanzi, GR encoding
761 ;; "HP-Arabic8" [36]
762 ;; HPARABIC8 8-bit character set
763 ;; "HP-East8" [36]
764 ;; HPEAST8 8-bit character set
765 ;; "HP-Greek8" [36]
766 ;; HPGREEK8 8-bit character set
767 ;; "HP-Hebrew8" [36]
768 ;; HPHEBREW8 8-bit character set
769 ;; "HP-Japanese15" [36]
770 ;; HPJAPAN15 15-bit character set,
771 ;; modified from industry de facto
772 ;; standard Shift-JIS
773 ;; "HP-Kana8" [36]
774 ;; HPKANA8 8-bit character set
775 ;; "HP-Korean15" [36]
776 ;; HPKOREAN15 15-bit character set
777 ;; "HP-Roman8" [36]
778 ;; HPROMAN8 8-bit character set
779 ;; "HP-SChinese15" [36]
780 ;; HPSCHINA15 15-bit character set for
781 ;; support of Simplified Chinese
782 ;; "HP-TChinese15" [36]
783 ;; HPTCHINA15 15-bit character set for
784 ;; support of Traditional Chinese
785 ;; "HP-Turkish8" [36]
786 ;; HPTURKISH8 8-bit character set
787 ;; "IPSYS" [59]
788 ;; registry prefix
789 ;; "IPSYS.IE-1" [59]
790 ;; "ISO2022"<REG>"-"<ENC> [44]
791 ;; "ISO646.1991-IRV" [107]
792 ;; ISO 646 International Reference Version
793 ;; "ISO8859-1" [15],[12]
794 ;; ISO Latin alphabet No. 1
795 ;; "ISO8859-2" [15],[12]
796 ;; ISO Latin alphabet No. 2
797 ;; "ISO8859-3" [15],[12]
798 ;; ISO Latin alphabet No. 3
799 ;; "ISO8859-4" [15],[12]
800 ;; ISO Latin alphabet No. 4
801 ;; "ISO8859-5" [15],[12]
802 ;; ISO Latin/Cyrillic alphabet
803 ;; "ISO8859-6" [15],[12]
804 ;; ISO Latin/Arabic alphabet
805 ;; "ISO8859-7" [15],[12]
806 ;; ISO Latin/Greek alphabet
807 ;; "ISO8859-8" [15],[12]
808 ;; ISO Latin/Hebrew alphabet
809 ;; "ISO8859-9" [15],[12]
810 ;; ISO Latin alphabet No. 5
811 ;; "ISO8859-10" [15],[12]
812 ;; ISO Latin alphabet No. 6
813 ;; "ISO8859-13" [15],[12]
814 ;; ISO Latin alphabet No. 7
815 ;; "ISO8859-14" [15],[12]
816 ;; ISO Latin alphabet No. 8
817 ;; "ISO8859-15" [15],[12]
818 ;; ISO Latin alphabet No. 9
819 ;; "FCD8859-15" [7]
820 ;; (deprecated)
821 ;; ISO Latin alphabet No. 9, Final Committee Draft
822 ;; "ISO10646-1" [133]
823 ;; Unicode Universal Multiple-Octet Coded Character Set
824 ;; "ISO10646-MES" [133]
825 ;; (deprecated)
826 ;; Unicode Minimum European Subset
827 ;; "JISX0201.1976-0" [38],[12]
828 ;; 8-Bit Alphanumeric-Katakana Code
829 ;; "JISX0208.1983-0" [40],[12]
830 ;; Japanese Graphic Character Set,
831 ;; GL encoding
832 ;; "JISX0208.1990-0" [71]
833 ;; Japanese Graphic Character Set,
834 ;; GL encoding
835 ;; "JISX0208.1983-1" [40]
836 ;; (deprecated)
837 ;; Japanese Graphic Character Set,
838 ;; GR encoding
839 ;; "JISX0212.1990-0" [72]
840 ;; Supplementary Japanese Graphic Character Set,
841 ;; GL encoding
842 ;; "KOI8-R" [119]
843 ;; Cyrillic alphabet
844 ;; "KSC5601.1987-0" [41],[12]
845 ;; Korean Graphic Character Set,
846 ;; GL encoding
847 ;; "KSC5601.1987-1" [41]
848 ;; (deprecated)
849 ;; Korean Graphic Character Set,
850 ;; GR encoding
851 ;; "omron_CNS11643-0" [45]
852 ;; "omron_CNS11643-1" [45]
853 ;; "omron_BIG5-0" [45]
854 ;; "omron_BIG5-1" [45]
855 ;; "wn.tamil.1993" [103]
857 (defun set-font-encoding (pattern charset)
858 "Set arguments in `font-encoding-alist' (which see)."
859 (let ((slot (assoc pattern font-encoding-alist)))
860 (if slot
861 (setcdr slot charset)
862 (setq font-encoding-alist
863 (cons (cons pattern charset) font-encoding-alist)))))
865 (defvar x-pixel-size-width-font-regexp)
866 (defvar vertical-centering-font-regexp)
868 ;; Setting for suppressing XLoadQueryFont on big fonts.
869 (setq x-pixel-size-width-font-regexp
870 (purecopy "gb2312\\|gbk\\|gb18030\\|jisx0208\\|ksc5601\\|cns11643\\|big5"))
872 ;; These fonts require vertical centering.
873 (setq vertical-centering-font-regexp
874 (purecopy "gb2312\\|gbk\\|gb18030\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5"))
875 (put 'vertical-centering-font-regexp 'standard-value
876 (list vertical-centering-font-regexp))
878 ;; CDAC fonts are actually smaller than their design sizes.
879 (setq face-font-rescale-alist
880 (list (cons (purecopy "-cdac$") 1.3)))
882 (defvar x-font-name-charset-alist nil
883 "This variable has no meaning now. Just kept for backward compatibility.")
885 ;;; XLFD (X Logical Font Description) format handler.
887 ;; Define XLFD's field index numbers. ; field name
888 (defconst xlfd-regexp-family-subnum 0) ; FOUNDRY and FAMILY
889 (defconst xlfd-regexp-weight-subnum 1) ; WEIGHT_NAME
890 (defconst xlfd-regexp-slant-subnum 2) ; SLANT
891 (defconst xlfd-regexp-swidth-subnum 3) ; SETWIDTH_NAME
892 (defconst xlfd-regexp-adstyle-subnum 4) ; ADD_STYLE_NAME
893 (defconst xlfd-regexp-pixelsize-subnum 5) ; PIXEL_SIZE
894 (defconst xlfd-regexp-pointsize-subnum 6) ; POINT_SIZE
895 (defconst xlfd-regexp-resx-subnum 7) ; RESOLUTION_X
896 (defconst xlfd-regexp-resy-subnum 8) ; RESOLUTION_Y
897 (defconst xlfd-regexp-spacing-subnum 8) ; SPACING
898 (defconst xlfd-regexp-avgwidth-subnum 10) ; AVERAGE_WIDTH
899 (defconst xlfd-regexp-registry-subnum 11) ; REGISTRY and ENCODING
901 ;; Regular expression matching against a fontname which conforms to
902 ;; XLFD (X Logical Font Description). All fields in XLFD should be
903 ;; not be omitted (but can be a wild card) to be matched.
904 (defconst xlfd-tight-regexp
906 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
907 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
908 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*-[^-]*\\)$")
910 ;; Regular expression matching against a fontname which conforms to
911 ;; XLFD (X Logical Font Description). All fields in XLFD from FOUNDRY
912 ;; to ADSTYLE, REGISTRY, and ENCODING should be not be omitted (but
913 ;; can be a wild card) to be matched.
914 (defconst xlfd-style-regexp
916 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-.*\
917 -\\([^-]*-[^-]*\\)$")
919 ;; List of field numbers of XLFD whose values are numeric.
920 (defconst xlfd-regexp-numeric-subnums
921 (list xlfd-regexp-pixelsize-subnum ;5
922 xlfd-regexp-pointsize-subnum ;6
923 xlfd-regexp-resx-subnum ;7
924 xlfd-regexp-resy-subnum ;8
925 xlfd-regexp-avgwidth-subnum ;10
928 (defun x-decompose-font-name (pattern)
929 "Decompose PATTERN into XLFD fields and return a vector of the fields.
930 The length of the vector is 12.
931 The FOUNDRY and FAMILY fields are concatenated and stored in the first
932 element of the vector.
933 The REGISTRY and ENCODING fields are concatenated and stored in the last
934 element of the vector.
936 Return nil if PATTERN doesn't conform to XLFD."
937 (if (string-match xlfd-tight-regexp pattern)
938 (let ((xlfd-fields (make-vector 12 nil)))
939 (dotimes (i 12)
940 (aset xlfd-fields i (match-string (1+ i) pattern)))
941 (dotimes (i 12)
942 (if (string-match "^[*-]+$" (aref xlfd-fields i))
943 (aset xlfd-fields i nil)))
944 xlfd-fields)))
946 (defun x-compose-font-name (fields &optional _reduce)
947 "Compose X fontname from FIELDS.
948 FIELDS is a vector of XLFD fields, of length 12.
949 If a field is nil, wild-card letter `*' is embedded.
950 Optional argument REDUCE exists just for backward compatibility,
951 and is always ignored."
952 (concat "-" (mapconcat (lambda (x) (or x "*")) fields "-")))
955 (defun x-must-resolve-font-name (xlfd-fields)
956 "Like `x-resolve-font-name', but always return a font name.
957 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
958 If no font matching XLFD-FIELDS is available, successively replace
959 parts of the font name pattern with \"*\" until some font is found.
960 Value is name of that font."
961 (let ((ascii-font nil) (index 0))
962 (while (and (null ascii-font) (<= index xlfd-regexp-registry-subnum))
963 (let ((pattern (x-compose-font-name xlfd-fields)))
964 (condition-case nil
965 (setq ascii-font (x-resolve-font-name pattern))
966 (error
967 (message "Warning: no fonts matching `%s' available" pattern)
968 (aset xlfd-fields index "*")
969 (setq index (1+ index))))))
970 (unless ascii-font
971 (error "No fonts found"))
972 ascii-font))
975 (defun x-complement-fontset-spec (default-spec fontlist)
976 "Complement elements of FONTLIST based on DEFAULT-SPEC.
977 DEFAULT-SPEC is a font-spec object providing default font properties.
978 FONTLIST is an alist of script names vs the corresponding font names.
980 The font names are parsed and unspecified font properties are
981 given from DEFAULT-SPEC."
982 (let ((prop-list '(:foundry :family :weight :slant :width :adstyle :size)))
983 (dolist (elt fontlist)
984 (let ((spec (font-spec :name (cadr elt))))
985 (dolist (prop prop-list)
986 (let ((val (font-get spec prop)))
987 (or val
988 (font-put spec prop (font-get default-spec prop)))))
989 (setcar (cdr elt) spec)))
990 fontlist))
992 (defun fontset-name-p (fontset)
993 "Return non-nil if FONTSET is valid as fontset name.
994 A valid fontset name should conform to XLFD (X Logical Font Description)
995 with \"fontset\" in `<CHARSET_REGISTRY>' field."
996 (and (string-match xlfd-tight-regexp fontset)
997 (string= (match-string (1+ xlfd-regexp-registry-subnum) fontset)
998 "fontset")))
1000 (declare-function fontset-list "fontset.c" ())
1002 (defun generate-fontset-menu ()
1003 "Return list to be appended to `x-fixed-font-alist'.
1004 Done when `mouse-set-font' is called."
1005 (let (l)
1006 (dolist (fontset (fontset-list))
1007 (or (string-match "fontset-default$" fontset)
1008 (string-match "fontset-auto[0-9]+$" fontset)
1009 (push (list (fontset-plain-name fontset) fontset) l)))
1010 (cons "Fontset"
1011 (sort l #'(lambda (x y) (string< (car x) (car y)))))))
1013 (declare-function query-fontset "fontset.c" (pattern &optional regexpp))
1015 (defun fontset-plain-name (fontset)
1016 "Return a plain and descriptive name of FONTSET."
1017 (if (not (setq fontset (query-fontset fontset)))
1018 (error "Invalid fontset: %s" fontset))
1019 (let ((xlfd-fields (x-decompose-font-name fontset)))
1020 (if xlfd-fields
1021 (let ((family (aref xlfd-fields xlfd-regexp-family-subnum))
1022 (weight (aref xlfd-fields xlfd-regexp-weight-subnum))
1023 (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
1024 ;(swidth (aref xlfd-fields xlfd-regexp-swidth-subnum))
1025 (size (aref xlfd-fields xlfd-regexp-pixelsize-subnum))
1026 (nickname (aref xlfd-fields xlfd-regexp-registry-subnum))
1027 name)
1028 (if (not (string-match "^fontset-\\(.*\\)$" nickname))
1029 (setq nickname family)
1030 (setq nickname (match-string 1 nickname)))
1031 (if (and size (> (string-to-number size) 0))
1032 (setq name (format "%s: %s-dot" nickname size))
1033 (setq name nickname))
1034 (and weight
1035 (cond ((string-match "^medium$" weight)
1036 (setq name (concat name " " "medium")))
1037 ((string-match "^bold$\\|^demibold$" weight)
1038 (setq name (concat name " " weight)))))
1039 (and slant
1040 (cond ((string-match "^i$" slant)
1041 (setq name (concat name " " "italic")))
1042 ((string-match "^o$" slant)
1043 (setq name (concat name " " "slant")))
1044 ((string-match "^ri$" slant)
1045 (setq name (concat name " " "reverse italic")))
1046 ((string-match "^ro$" slant)
1047 (setq name (concat name " " "reverse slant")))))
1048 name)
1049 fontset)))
1051 (defvar charset-script-alist
1052 '((ascii . latin)
1053 (latin-iso8859-1 . latin)
1054 (latin-iso8859-2 . latin)
1055 (latin-iso8859-3 . latin)
1056 (latin-iso8859-4 . latin)
1057 (latin-iso8859-9 . latin)
1058 (latin-iso8859-10 . latin)
1059 (latin-iso8859-13 . latin)
1060 (latin-iso8859-14 . latin)
1061 (latin-iso8859-15 . latin)
1062 (latin-iso8859-16 . latin)
1063 (latin-jisx0201 . latin)
1064 (thai-tis620 . thai)
1065 (cyrillic-iso8859-5 . cyrillic)
1066 (arabic-iso8859-6 . arabic)
1067 (greek-iso8859-7 . latin)
1068 (hebrew-iso8859-8 . latin)
1069 (katakana-jisx0201 . kana)
1070 (chinese-gb2312 . han)
1071 (chinese-gbk . han)
1072 (gb18030-2-byte . han)
1073 (gb18030-4-byte-bmp . han)
1074 (gb18030-4-byte-ext-1 . han)
1075 (gb18030-4-byte-ext-2 . han)
1076 (gb18030-4-byte-smp . han)
1077 (chinese-big5-1 . han)
1078 (chinese-big5-2 . han)
1079 (chinese-cns11643-1 . han)
1080 (chinese-cns11643-2 . han)
1081 (chinese-cns11643-3 . han)
1082 (chinese-cns11643-4 . han)
1083 (chinese-cns11643-5 . han)
1084 (chinese-cns11643-6 . han)
1085 (chinese-cns11643-7 . han)
1086 (japanese-jisx0208 . han)
1087 (japanese-jisx0208-1978 . han)
1088 (japanese-jisx0212 . han)
1089 (japanese-jisx0213-1 . han)
1090 (japanese-jisx0213-2 . han)
1091 (korean-ksc5601 . hangul)
1092 (chinese-sisheng . bopomofo)
1093 (vietnamese-viscii-lower . latin)
1094 (vietnamese-viscii-upper . latin)
1095 (arabic-digit . arabic)
1096 (arabic-1-column . arabic)
1097 (arabic-2-column . arabic)
1098 (indian-is13194 . devanagari)
1099 (indian-glyph . devanagari)
1100 (indian-1-column . devanagari)
1101 (indian-2-column . devanagari)
1102 (tibetan-1-column . tibetan))
1103 "Alist of charsets vs the corresponding most appropriate scripts.
1105 This alist is used by the function `create-fontset-from-fontset-spec'
1106 to map charsets to scripts.")
1108 (defun create-fontset-from-fontset-spec (fontset-spec
1109 &optional _style-variant _noerror)
1110 "Create a fontset from fontset specification string FONTSET-SPEC.
1111 FONTSET-SPEC is a string of the format:
1112 FONTSET-NAME,SCRIPT-NAME0:FONT-NAME0,SCRIPT-NAME1:FONT-NAME1, ...
1113 Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
1115 When a frame uses the fontset as the `font' parameter, the frame's
1116 default font name is derived from FONTSET-NAME by substituting
1117 \"iso8859-1\" for the tail part \"fontset-XXX\". But, if SCRIPT-NAMEn
1118 is \"ascii\", use the corresponding FONT-NAMEn as the default font
1119 name.
1121 Optional 2nd and 3rd arguments exist just for backward compatibility,
1122 and are ignored.
1124 It returns a name of the created fontset.
1126 For backward compatibility, SCRIPT-NAME may be a charset name, in
1127 which case, the corresponding script is decided by the variable
1128 `charset-script-alist' (which see)."
1129 (or (string-match "^[^,]+" fontset-spec)
1130 (error "Invalid fontset spec: %s" fontset-spec))
1131 (let ((idx (match-end 0))
1132 (name (match-string 0 fontset-spec))
1133 default-spec target script fontlist)
1134 (or (string-match xlfd-tight-regexp name)
1135 (error "Fontset name \"%s\" not conforming to XLFD" name))
1136 (setq default-spec (font-spec :name name))
1137 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
1138 (while (string-match "[, \t\n]*\\([^:]+\\):[ \t]*\\([^,]+\\)"
1139 fontset-spec idx)
1140 (setq idx (match-end 0))
1141 (setq target (intern (match-string 1 fontset-spec)))
1142 (cond ((or (eq target 'ascii)
1143 (memq target (char-table-extra-slot char-script-table 0)))
1144 (push (list target (match-string 2 fontset-spec)) fontlist))
1145 ((setq script (cdr (assq target charset-script-alist)))
1146 (push (list script (match-string 2 fontset-spec)) fontlist))
1147 ((charsetp target)
1148 (push (list target (match-string 2 fontset-spec)) fontlist))))
1150 ;; Complement FONTLIST.
1151 (setq fontlist (x-complement-fontset-spec default-spec fontlist))
1153 ;; Create a fontset.
1154 (new-fontset name (nreverse fontlist))))
1156 (defun create-fontset-from-ascii-font (font &optional resolved-font
1157 fontset-name)
1158 "Create a fontset from an ASCII font FONT.
1160 Optional 2nd arg RESOLVED-FONT is a resolved name of FONT.
1161 If omitted, `x-resolve-font-name' is called to get the resolved name.
1162 At this time, if FONT is not available, an error is signaled.
1164 Optional 3rd arg FONTSET-NAME is a string to be used in
1165 `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
1166 an appropriate name is generated automatically.
1168 It returns a name of the created fontset."
1169 (setq font (downcase font))
1170 (setq resolved-font
1171 (downcase (or resolved-font (x-resolve-font-name font))))
1172 (let ((xlfd (x-decompose-font-name resolved-font))
1173 fontset)
1174 (if fontset-name
1175 (setq fontset-name (downcase fontset-name))
1176 (if (query-fontset "fontset-startup")
1177 (setq fontset-name
1178 (subst-char-in-string
1179 ?- ?_ (aref xlfd xlfd-regexp-registry-subnum) t))
1180 (setq fontset-name "startup")))
1181 (aset xlfd xlfd-regexp-registry-subnum
1182 (format "fontset-%s" fontset-name))
1183 (setq fontset (x-compose-font-name xlfd))
1184 (or (query-fontset fontset)
1185 (create-fontset-from-fontset-spec (concat fontset ", ascii:" font)))))
1188 ;; Create standard fontset from 16 dots fonts which are the most widely
1189 ;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
1190 ;; specified here because FAMILY of those fonts are not "fixed" in
1191 ;; many cases.
1192 (defvar standard-fontset-spec
1193 (purecopy "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard")
1194 "String of fontset spec of the standard fontset.
1195 You have the biggest chance to display international characters
1196 with correct glyphs by using the standard fontset.
1197 See the documentation of `create-fontset-from-fontset-spec' for the format.")
1200 ;; Create fontsets from X resources of the name `fontset-N (class
1201 ;; Fontset-N)' where N is integer 0, 1, ...
1202 ;; The values of the resources the string of the same format as
1203 ;; `standard-fontset-spec'.
1205 (declare-function x-get-resource "frame.c"
1206 (attribute class &optional component subclass))
1208 (defun create-fontset-from-x-resource ()
1209 (let ((idx 0)
1210 fontset-spec)
1211 (while (setq fontset-spec (x-get-resource (format "fontset-%d" idx)
1212 (format "Fontset-%d" idx)))
1213 (condition-case nil
1214 (create-fontset-from-fontset-spec fontset-spec t)
1215 (error (display-warning
1216 'initialization
1217 (format "Fontset-%d: invalid specification in X resource" idx)
1218 :warning)))
1219 (setq idx (1+ idx)))))
1222 (provide 'fontset)
1224 ;;; fontset.el ends here