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