]> code.delx.au - gnu-emacs/blob - lisp/international/fontset.el
(font-encoding-alist): Add the entry of "unicode-bmp".
[gnu-emacs] / lisp / international / fontset.el
1 ;;; fontset.el --- commands for handling fontset
2
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
5 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
6 ;; 2005, 2006, 2007
7 ;; National Institute of Advanced Industrial Science and Technology (AIST)
8 ;; Registration Number H14PRO021
9 ;; Copyright (C) 2003, 2006
10 ;; National Institute of Advanced Industrial Science and Technology (AIST)
11 ;; Registration Number H13PRO009
12
13 ;; Keywords: mule, i18n, fontset
14
15 ;; This file is part of GNU Emacs.
16
17 ;; GNU Emacs is free software; you can redistribute it and/or modify
18 ;; it under the terms of the GNU General Public License as published by
19 ;; the Free Software Foundation; either version 3, or (at your option)
20 ;; any later version.
21
22 ;; GNU Emacs is distributed in the hope that it will be useful,
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;; GNU General Public License for more details.
26
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with GNU Emacs; see the file COPYING. If not, write to the
29 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
30 ;; Boston, MA 02110-1301, USA.
31
32 ;;; Commentary:
33
34 ;;; Code:
35
36 ;; Setup font-encoding-alist for all known encodings.
37
38 (setq font-encoding-alist
39 '(("iso8859-1$" . iso-8859-1)
40 ("iso8859-2$" . iso-8859-2)
41 ("iso8859-3$" . iso-8859-3)
42 ("iso8859-4$" . iso-8859-4)
43 ("iso8859-5$" . iso-8859-5)
44 ("iso8859-6$" . iso-8859-6)
45 ("iso8859-7$" . iso-8859-7)
46 ("iso8859-8$" . iso-8859-8)
47 ("iso8859-9$" . iso-8859-9)
48 ("iso8859-10$" . iso-8859-10)
49 ("iso8859-11$" . iso-8859-11)
50 ("iso8859-13$" . iso-8859-13)
51 ("iso8859-14$" . iso-8859-14)
52 ("iso8859-15$" . iso-8859-15)
53 ("gb2312.1980" . chinese-gb2312)
54 ("gbk" . chinese-gbk)
55 ("gb18030" . gb18030)
56 ("jisx0208.1978" . japanese-jisx0208-1978)
57 ("jisx0208" . japanese-jisx0208)
58 ("jisx0201" . jisx0201)
59 ("jisx0212" . japanese-jisx0212)
60 ("ksc5601.1987" . korean-ksc5601)
61 ("cns11643.1992.*1" . chinese-cns11643-1)
62 ("cns11643.1992.*2" . chinese-cns11643-2)
63 ("cns11643.1992.*3" . chinese-cns11643-3)
64 ("cns11643.1992.*4" . chinese-cns11643-4)
65 ("cns11643.1992.*5" . chinese-cns11643-5)
66 ("cns11643.1992.*6" . chinese-cns11643-6)
67 ("cns11643.1992.*7" . chinese-cns11643-7)
68 ("cns11643.92p1-0" . chinese-cns11643-1)
69 ("cns11643.92p2-0" . chinese-cns11643-2)
70 ("cns11643.92p3-0" . chinese-cns11643-3)
71 ("cns11643.92p4-0" . chinese-cns11643-4)
72 ("cns11643.92p5-0" . chinese-cns11643-5)
73 ("cns11643.92p6-0" . chinese-cns11643-6)
74 ("cns11643.92p7-0" . chinese-cns11643-7)
75 ("big5" . big5)
76 ("viscii" . viscii)
77 ("tis620" . tis620-2533)
78 ("microsoft-cp1251" . windows-1251)
79 ("koi8-r" . koi8-r)
80 ("jisx0213.2000-1" . japanese-jisx0213-1)
81 ("jisx0213.2000-2" . japanese-jisx0213-2)
82 ("jisx0213.2004-1" . japanese-jisx0213.2004-1)
83 ("iso10646-1$" . (unicode-bmp . nil))
84 ("iso10646.indian-1" . (unicode-bmp . nil))
85 ("unicode-bmp" . (unicode-bmp . nil))
86 ("abobe-symbol" . symbol)
87 ("sisheng_cwnn" . chinese-sisheng)
88 ("mulearabic-0" . arabic-digit)
89 ("mulearabic-1" . arabic-1-column)
90 ("mulearabic-2" . arabic-2-column)
91 ("muleipa" . ipa)
92 ("ethiopic-unicode" . (unicode-bmp . ethiopic))
93 ("is13194-devanagari" . indian-is13194)
94 ("Devanagari-CDAC" . devanagari-cdac)
95 ("Sanskrit-CDAC" . sanskrit-cdac)
96 ("Bengali-CDAC" . bengali-cdac)
97 ("Assamese-CDAC" . assamese-cdac)
98 ("Punjabi-CDAC" . punjabi-cdac)
99 ("Gujarati-CDAC" . gujarati-cdac)
100 ("Oriya-CDAC" . oriya-cdac)
101 ("Tamil-CDAC" . tamil-cdac)
102 ("Telugu-CDAC" . telugu-cdac)
103 ("Kannada-CDAC" . kannada-cdac)
104 ("Malayalam-CDAC" . malayalam-cdac)
105 ("Devanagari-Akruti" . devanagari-akruti)
106 ("Bengali-Akruti" . bengali-akruti)
107 ("Punjabi-Akruti" . punjabi-akruti)
108 ("Gujarati-Akruti" . gujarati-akruti)
109 ("Oriya-Akruti" . oriya-akruti)
110 ("Tamil-Akruti" . tamil-akruti)
111 ("Telugu-Akruti" . telugu-akruti)
112 ("Kannada-Akruti" . kannada-akruti)
113 ("Malayalam-Akruti" . malayalam-akruti)
114 ("muleindian-2" . indian-2-column)
115 ("muleindian-1" . indian-1-column)
116 ("mulelao-1" . mule-lao)
117 ("muletibetan-2" . tibetan)
118 ("muletibetan-1" . tibetan-1-column)))
119
120 (setq script-representative-chars
121 '((latin ?A ?Z ?a ?z)
122 (greek #x3A9)
123 (coptic #x3E2)
124 (cyrillic #x42F)
125 (armenian #x531)
126 (hebrew #x5D0)
127 (arabic #x628)
128 (syriac #x710)
129 (thaana #x78C)
130 (devanagari #x915)
131 (bengali #x995)
132 (gurmukhi #xA15)
133 (gujarati #xA95)
134 (oriya #xB15)
135 (tamil #xB95)
136 (telugu #xC15)
137 (kannada #xC95)
138 (malayalam #xD15)
139 (sinhala #xD95)
140 (thai #xE17)
141 (lao #xEA5)
142 (tibetan #xF40)
143 (myanmar #x1000)
144 (georgian #x10D3)
145 (ethiopic #x1208)
146 (cherokee #x13B6)
147 (canadian-aboriginal #x14C0)
148 (ogham #x168F)
149 (runic #x16A0)
150 (khmer #x1780)
151 (mongolian #x1826)
152 (braille #x2800)
153 (ideographic-description #x2FF0)
154 (cjk-misc #x300E)
155 (kana #x304B)
156 (bopomofo #x3105)
157 (kanbun #x319D)
158 (han #x5B57)
159 (yi #xA288)
160 (hangul #xAC00)))
161
162 (setq otf-script-alist
163 '((arab . arabic)
164 (armn . armenian)
165 (bali . balinese)
166 (beng . bengali)
167 (bopo . bopomofo)
168 (brai . braille)
169 (bugi . buginese)
170 (buhd . buhid)
171 (byzm . byzantine-musical-symbol)
172 (cans . canadian_aboliginal)
173 (cher . cherokee)
174 (copt . coptic)
175 (xsux . cuneiform)
176 (cyrl . cyrillic)
177 (cprt . cypriot)
178 (dsrt . deseret)
179 (deva . devanagari)
180 (ethi . ethiopic)
181 (geor . georgian)
182 (glag . glagolitic)
183 (goth . gothic)
184 (grek . greek)
185 (gujr . gujarati)
186 (guru . gurmukhi)
187 (hani . han)
188 (hang . hangul)
189 (hano . hanunoo)
190 (hebr . hebrew)
191 (kana . kana)
192 (knda . kannada)
193 (khar . kharoshthi)
194 (khmr . khmer)
195 (lao\ . lao)
196 (latn . latin)
197 (limb . limbu)
198 (linb . linear_b)
199 (mlym . malayalam)
200 (math . mathematical)
201 (mong . mongolian)
202 (musc . musical-symbol)
203 (mymr . myanmar)
204 (nko\ . nko)
205 (ogam . ogham)
206 (ital . old_italic)
207 (xpeo . old_persian)
208 (orya . oriya)
209 (osma . osmanya)
210 (phag . phags-pa)
211 (phnx . phoenician)
212 (runr . runic)
213 (shaw . shavian)
214 (sinh . sinhala)
215 (sylo . syloti_nagri)
216 (syrc . syriac)
217 (tglg . tagalog)
218 (tagb . tagbanwa)
219 (taml . tamil)
220 (tale . tai_le)
221 (telu . telugu)
222 (thaa . thaana)
223 (thai . thai)
224 (tibt . tibetan)
225 (tfng . tifinagh)
226 (ugar . ugaritic)
227 (yi\ \ . yi)))
228
229 ;; Set standard fontname specification of characters in the default
230 ;; fontset to find an appropriate font for each script/charset. The
231 ;; specification has the form ((SCRIPT FONT-SPEC ...) ...), where
232 ;; FONT-SPEC is:
233 ;; a cons (FAMILY . REGISTRY),
234 ;; or a string FONT-NAME,
235 ;; or an object created by `font-spec'.
236 ;;
237 ;; FAMILY may be nil, in which case, the the corresponding name of
238 ;; default face is used. If REGISTRY contains a character `-', the
239 ;; string before that is embedded in `CHARSET_REGISTRY' field, and the
240 ;; string after that is embedded in `CHARSET_ENCODING' field. If it
241 ;; does not contain `-', the whole string is embedded in
242 ;; `CHARSET_REGISTRY' field, and a wild card character `*' is embedded
243 ;; in `CHARSET_ENCODING' field.
244 ;;
245 ;; SCRIPT is a symbol that appears as an element of the char table
246 ;; `char-script-table'. SCRIPT may be a charset specifying the range
247 ;; of characters.
248
249 (defun setup-default-fontset ()
250 "Setup the default fontset."
251 (new-fontset
252 "fontset-default"
253 `(;; for each script
254 (latin (nil . "ISO8859-1")
255 (nil . "ISO8859-2")
256 (nil . "ISO8859-3")
257 (nil . "ISO8859-4")
258 (nil . "ISO8859-9")
259 (nil . "ISO8859-10")
260 (nil . "ISO8859-13")
261 (nil . "ISO8859-14")
262 (nil . "ISO8859-15")
263 (nil . "VISCII1.1-1"))
264
265 (thai (nil . "TIS620*")
266 (nil . "ISO8859-11"))
267
268 (devanagari ,(font-spec :registry "iso10646-1" :otf '(deva nil (rphf)))
269 (nil . "iso10646.indian-1"))
270 (malayalam ,(font-spec :registry "iso10646-1" :otf '(mlym nil (akhn))))
271 (tamil ,(font-spec :registry "iso10646-1" :otf '(taml nil (akhn))))
272
273 (lao (nil . "MuleLao-1"))
274
275 (tai-viet ("TaiViet" . "iso10646-1"))
276
277 ;; both for script and charset.
278 (tibetan ,(font-spec :registry "iso10646-1"
279 :otf '(tibt nil (ccmp blws abvs)))
280 ,(font-spec :family "mtib" :registry "iso10646-1")
281 (nil . "muletibetan-2"))
282
283 ;; both for script and charset.
284 (ethiopic (nil . "ethiopic-unicode"))
285
286 (greek (nil . "ISO8859-7"))
287
288 (cyrillic (nil . "ISO8859-5")
289 (nil . "microsoft-cp1251")
290 (nil . "koi8-r"))
291
292 (arabic (nil . "MuleArabic-0")
293 (nil . "MuleArabic-1")
294 (nil . "MuleArabic-2")
295 (nil . "ISO8859-6"))
296
297 (hebrew (nil . "ISO8859-8"))
298
299 (kana (nil . "JISX0208*")
300 (nil . "GB2312.1980-0")
301 (nil . "KSC5601.1987*")
302 (nil . "JISX0201*")
303 (nil . "JISX0213.2000-1")
304 (nil . "JISX0213.2004-1"))
305
306 (bopomofo (nil . "sisheng_cwnn-0"))
307
308 (han (nil . "GB2312.1980-0")
309 (nil . "JISX0208*")
310 (nil . "JISX0212*")
311 (nil . "big5*")
312 (nil . "KSC5601.1987*")
313 (nil . "CNS11643.1992-1")
314 (nil . "CNS11643.1992-2")
315 (nil . "CNS11643.1992-3")
316 (nil . "CNS11643.1992-4")
317 (nil . "CNS11643.1992-5")
318 (nil . "CNS11643.1992-6")
319 (nil . "CNS11643.1992-7")
320 (nil . "gbk-0")
321 (nil . "gb18030")
322 (nil . "JISX0213.2000-1")
323 (nil . "JISX0213.2000-2")
324 (nil . "JISX0213.2004-1"))
325
326 (cjk-misc (nil . "GB2312.1980-0")
327 (nil . "JISX0208*")
328 (nil . "JISX0212*")
329 (nil . "big5*")
330 (nil . "KSC5601.1987*")
331 (nil . "CNS11643.1992-1")
332 (nil . "CNS11643.1992-2")
333 (nil . "CNS11643.1992-3")
334 (nil . "CNS11643.1992-4")
335 (nil . "CNS11643.1992-5")
336 (nil . "CNS11643.1992-6")
337 (nil . "CNS11643.1992-7")
338 (nil . "gbk-0")
339 (nil . "gb18030")
340 (nil . "JISX0213.2000-1")
341 (nil . "JISX0213.2000-2"))
342
343 (hangul (nil . "KSC5601.1987-0"))
344
345 ;; for each charset
346 (ascii (nil . "ISO8859-1"))
347 (arabic-digit ("*" . "MuleArabic-0"))
348 (arabic-1-column ("*" . "MuleArabic-1"))
349 (arabic-2-column ("*" . "MuleArabic-2"))
350 (indian-is13194 (nil . "is13194-devanagari"))
351 (indian-1-column ("*" . "muleindian-2"))
352 ;; Indian CDAC
353 (devanagari-cdac (nil . "Devanagari-CDAC"))
354 (sanskrit-cdac (nil . "Sanskrit-CDAC"))
355 (bengali-cdac (nil . "Bengali-CDAC"))
356 (assamese-cdac (nil . "Assamese-CDAC"))
357 (punjabi-cdac (nil . "Punjabi-CDAC"))
358 (gujarati-cdac (nil . "Gujarati-CDAC"))
359 (oriya-cdac (nil . "Oriya-CDAC"))
360 (tamil-cdac (nil . "Tamil-CDAC"))
361 (telugu-cdac (nil . "Telugu-CDAC"))
362 (kannada-cdac (nil . "Kannada-CDAC"))
363 (malayalam-cdac (nil . "Malayalam-CDAC"))
364 ;; Indian AKRUTI
365 (devanagari-akruti (nil . "Devanagari-Akruti"))
366 (bengali-akruti (nil . "Bengali-Akruti"))
367 (punjabi-akruti (nil . "Punjabi-Akruti"))
368 (gujarati-akruti (nil . "Gujarati-Akruti"))
369 (oriya-akruti (nil . "Oriya-Akruti"))
370 (tamil-akruti (nil . "Tamil-Akruti"))
371 (telugu-akruti (nil . "Telugu-Akruti"))
372 (kannada-akruti (nil . "Kannada-Akruti"))
373 (malayalam-akruti (nil . "Malayalam-Akruti"))
374 ;;(devanagari-glyph ("altsys-dv_ttsurekh" . "devanagari-cdac"))
375 ;;(malayalam-glyph ("altsys-ml_ttkarthika" . "malayalam-cdac"))
376 (ipa (nil . "MuleIPA-1"))
377
378 ;; Fallback fonts
379 (nil (nil . "gb2312.1980")
380 (nil . "gbk-0")
381 (nil . "gb18030")
382 (nil . "jisx0208")
383 (nil . "ksc5601.1987")
384 (nil . "CNS11643.1992-1")
385 (nil . "CNS11643.1992-2")
386 (nil . "CNS11643.1992-3")
387 (nil . "CNS11643.1992-4")
388 (nil . "CNS11643.1992-5")
389 (nil . "CNS11643.1992-6")
390 (nil . "CNS11643.1992-7")
391 (nil . "big5")
392 (nil . "jisx0213.2000-1")
393 (nil . "jisx0213.2004-1")
394 (nil . "jisx0212"))
395 ))
396
397 ;; Append Unicode fonts.
398 ;; This may find fonts with more variants (bold, italic) but which
399 ;; don't cover many characters.
400 (set-fontset-font "fontset-default" nil
401 '(nil . "iso10646-1") nil 'append)
402 ;; These may find fonts that cover many characters but with fewer
403 ;; variants.
404 (set-fontset-font "fontset-default" nil
405 '("gnu-unifont" . "iso10646-1") nil 'append)
406 (set-fontset-font "fontset-default" nil
407 '("mutt-clearlyu" . "iso10646-1") nil 'append))
408
409 ;; These are the registered registries/encodings from
410 ;; ftp://ftp.x.org/pub/DOCS/registry 2001/06/01
411
412 ;; Name Reference
413 ;; ---- ---------
414 ;; "DEC" [27]
415 ;; registry prefix
416 ;; "DEC.CNS11643.1986-2" [53]
417 ;; CNS11643 2-plane using the encoding
418 ;; suggested in that standard
419 ;; "DEC.DTSCS.1990-2" [54]
420 ;; DEC Taiwan Supplemental Character Set
421 ;; "fujitsu.u90x01.1991-0" [87]
422 ;; "fujitsu.u90x03.1991-0" [87]
423 ;; "GB2312.1980-0" [39],[12]
424 ;; China (PRC) Hanzi, GL encoding
425 ;; "GB2312.1980-1" [39]
426 ;; (deprecated)
427 ;; China (PRC) Hanzi, GR encoding
428 ;; "HP-Arabic8" [36]
429 ;; HPARABIC8 8-bit character set
430 ;; "HP-East8" [36]
431 ;; HPEAST8 8-bit character set
432 ;; "HP-Greek8" [36]
433 ;; HPGREEK8 8-bit character set
434 ;; "HP-Hebrew8" [36]
435 ;; HPHEBREW8 8-bit character set
436 ;; "HP-Japanese15" [36]
437 ;; HPJAPAN15 15-bit characer set,
438 ;; modified from industry defacto
439 ;; standard Shift-JIS
440 ;; "HP-Kana8" [36]
441 ;; HPKANA8 8-bit character set
442 ;; "HP-Korean15" [36]
443 ;; HPKOREAN15 15-bit character set
444 ;; "HP-Roman8" [36]
445 ;; HPROMAN8 8-bit character set
446 ;; "HP-SChinese15" [36]
447 ;; HPSCHINA15 15-bit character set for
448 ;; support of Simplified Chinese
449 ;; "HP-TChinese15" [36]
450 ;; HPTCHINA15 15-bit character set for
451 ;; support of Traditional Chinese
452 ;; "HP-Turkish8" [36]
453 ;; HPTURKISH8 8-bit character set
454 ;; "IPSYS" [59]
455 ;; registry prefix
456 ;; "IPSYS.IE-1" [59]
457 ;; "ISO2022"<REG>"-"<ENC> [44]
458 ;; "ISO646.1991-IRV" [107]
459 ;; ISO 646 International Reference Version
460 ;; "ISO8859-1" [15],[12]
461 ;; ISO Latin alphabet No. 1
462 ;; "ISO8859-2" [15],[12]
463 ;; ISO Latin alphabet No. 2
464 ;; "ISO8859-3" [15],[12]
465 ;; ISO Latin alphabet No. 3
466 ;; "ISO8859-4" [15],[12]
467 ;; ISO Latin alphabet No. 4
468 ;; "ISO8859-5" [15],[12]
469 ;; ISO Latin/Cyrillic alphabet
470 ;; "ISO8859-6" [15],[12]
471 ;; ISO Latin/Arabic alphabet
472 ;; "ISO8859-7" [15],[12]
473 ;; ISO Latin/Greek alphabet
474 ;; "ISO8859-8" [15],[12]
475 ;; ISO Latin/Hebrew alphabet
476 ;; "ISO8859-9" [15],[12]
477 ;; ISO Latin alphabet No. 5
478 ;; "ISO8859-10" [15],[12]
479 ;; ISO Latin alphabet No. 6
480 ;; "ISO8859-13" [15],[12]
481 ;; ISO Latin alphabet No. 7
482 ;; "ISO8859-14" [15],[12]
483 ;; ISO Latin alphabet No. 8
484 ;; "ISO8859-15" [15],[12]
485 ;; ISO Latin alphabet No. 9
486 ;; "FCD8859-15" [7]
487 ;; (deprecated)
488 ;; ISO Latin alphabet No. 9, Final Committee Draft
489 ;; "ISO10646-1" [133]
490 ;; Unicode Universal Multiple-Octet Coded Character Set
491 ;; "ISO10646-MES" [133]
492 ;; (deprecated)
493 ;; Unicode Minimum European Subset
494 ;; "JISX0201.1976-0" [38],[12]
495 ;; 8-Bit Alphanumeric-Katakana Code
496 ;; "JISX0208.1983-0" [40],[12]
497 ;; Japanese Graphic Character Set,
498 ;; GL encoding
499 ;; "JISX0208.1990-0" [71]
500 ;; Japanese Graphic Character Set,
501 ;; GL encoding
502 ;; "JISX0208.1983-1" [40]
503 ;; (deprecated)
504 ;; Japanese Graphic Character Set,
505 ;; GR encoding
506 ;; "JISX0212.1990-0" [72]
507 ;; Supplementary Japanese Graphic Character Set,
508 ;; GL encoding
509 ;; "KOI8-R" [119]
510 ;; Cyrillic alphabet
511 ;; "KSC5601.1987-0" [41],[12]
512 ;; Korean Graphic Character Set,
513 ;; GL encoding
514 ;; "KSC5601.1987-1" [41]
515 ;; (deprecated)
516 ;; Korean Graphic Character Set,
517 ;; GR encoding
518 ;; "omron_CNS11643-0" [45]
519 ;; "omron_CNS11643-1" [45]
520 ;; "omron_BIG5-0" [45]
521 ;; "omron_BIG5-1" [45]
522 ;; "wn.tamil.1993" [103]
523
524 (defun set-font-encoding (pattern charset)
525 "Set arguments in `font-encoding-alist' (which see)."
526 (let ((slot (assoc pattern font-encoding-alist)))
527 (if slot
528 (setcdr slot charset)
529 (setq font-encoding-alist
530 (cons (cons pattern charset) font-encoding-alist)))))
531
532 ;; Setting for suppressing XLoadQueryFont on big fonts.
533 (setq x-pixel-size-width-font-regexp
534 "gb2312\\|gbk\\|gb18030\\|jisx0208\\|ksc5601\\|cns11643\\|big5")
535
536 ;; These fonts require vertical centering.
537 (setq vertical-centering-font-regexp
538 "gb2312\\|gbk\\|gb18030\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5")
539
540 ;; CDAC fonts are actually smaller than their design sizes.
541 (setq face-font-rescale-alist
542 '(("-cdac$" . 1.3)))
543
544 (defvar x-font-name-charset-alist nil
545 "This variable has no meaning now. Just kept for backward compatibility.")
546
547 ;;; XLFD (X Logical Font Description) format handler.
548
549 ;; Define XLFD's field index numbers. ; field name
550 (defconst xlfd-regexp-family-subnum 0) ; FOUNDRY and FAMILY
551 (defconst xlfd-regexp-weight-subnum 1) ; WEIGHT_NAME
552 (defconst xlfd-regexp-slant-subnum 2) ; SLANT
553 (defconst xlfd-regexp-swidth-subnum 3) ; SETWIDTH_NAME
554 (defconst xlfd-regexp-adstyle-subnum 4) ; ADD_STYLE_NAME
555 (defconst xlfd-regexp-pixelsize-subnum 5) ; PIXEL_SIZE
556 (defconst xlfd-regexp-pointsize-subnum 6) ; POINT_SIZE
557 (defconst xlfd-regexp-resx-subnum 7) ; RESOLUTION_X
558 (defconst xlfd-regexp-resy-subnum 8) ; RESOLUTION_Y
559 (defconst xlfd-regexp-spacing-subnum 8) ; SPACING
560 (defconst xlfd-regexp-avgwidth-subnum 10) ; AVERAGE_WIDTH
561 (defconst xlfd-regexp-registry-subnum 11) ; REGISTRY and ENCODING
562
563 ;; Regular expression matching against a fontname which conforms to
564 ;; XLFD (X Logical Font Description). All fields in XLFD should be
565 ;; not be omitted (but can be a wild card) to be matched.
566 (defconst xlfd-tight-regexp
567 "^\
568 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
569 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
570 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*-[^-]*\\)$")
571
572 ;; Regular expression matching against a fontname which conforms to
573 ;; XLFD (X Logical Font Description). All fields in XLFD from FOUNDRY
574 ;; to ADSTYLE, REGISTRY, and ENCODING should be not be omitted (but
575 ;; can be a wild card) to be matched.
576 (defconst xlfd-style-regexp
577 "^\
578 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-.*\
579 -\\([^-]*-[^-]*\\)$")
580
581 ;; List of field numbers of XLFD whose values are numeric.
582 (defconst xlfd-regexp-numeric-subnums
583 (list xlfd-regexp-pixelsize-subnum ;5
584 xlfd-regexp-pointsize-subnum ;6
585 xlfd-regexp-resx-subnum ;7
586 xlfd-regexp-resy-subnum ;8
587 xlfd-regexp-avgwidth-subnum ;10
588 ))
589
590 (defun x-decompose-font-name (pattern)
591 "Decompose PATTERN into XLFD fields and return a vector of the fields.
592 The length of the vector is 12.
593 The FOUNDRY and FAMILY fields are concatinated and stored in the first
594 element of the vector.
595 The REGISTRY and ENCODING fields are concatinated and stored in the last
596 element of the vector.
597
598 Return nil if PATTERN doesn't conform to XLFD."
599 (if (string-match xlfd-tight-regexp pattern)
600 (let ((xlfd-fields (make-vector 12 nil)))
601 (dotimes (i 12)
602 (aset xlfd-fields i (match-string (1+ i) pattern)))
603 (dotimes (i 12)
604 (if (string-match "^[*-]+$" (aref xlfd-fields i))
605 (aset xlfd-fields i nil)))
606 xlfd-fields)))
607
608 (defun x-compose-font-name (fields &optional reduce)
609 "Compose X fontname from FIELDS.
610 FIELDS is a vector of XLFD fields, of length 12.
611 If a field is nil, wild-card letter `*' is embedded.
612 Optional argument REDUCE exists just for backward compatibility,
613 and is always ignored."
614 (concat "-" (mapconcat (lambda (x) (or x "*")) fields "-")))
615
616
617 (defun x-must-resolve-font-name (xlfd-fields)
618 "Like `x-resolve-font-name', but always return a font name.
619 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
620 If no font matching XLFD-FIELDS is available, successively replace
621 parts of the font name pattern with \"*\" until some font is found.
622 Value is name of that font."
623 (let ((ascii-font nil) (index 0))
624 (while (and (null ascii-font) (<= index xlfd-regexp-registry-subnum))
625 (let ((pattern (x-compose-font-name xlfd-fields)))
626 (condition-case nil
627 (setq ascii-font (x-resolve-font-name pattern))
628 (error
629 (message "Warning: no fonts matching `%s' available" pattern)
630 (aset xlfd-fields index "*")
631 (setq index (1+ index))))))
632 (unless ascii-font
633 (error "No fonts found"))
634 ascii-font))
635
636
637 (defun x-complement-fontset-spec (xlfd-fields fontlist)
638 "Complement elements of FONTLIST based on XLFD-FIELDS.
639 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
640 FONTLIST is an alist of script names vs the corresponding font names.
641
642 The font names are complemented as below.
643
644 If a font name matches `xlfd-style-regexp', each field of wild card is
645 replaced by the corresponding fields in XLFD-FIELDS."
646 (let ((family (aref xlfd-fields xlfd-regexp-family-subnum))
647 (weight (aref xlfd-fields xlfd-regexp-weight-subnum))
648 (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
649 (width (aref xlfd-fields xlfd-regexp-swidth-subnum))
650 (adstyle (aref xlfd-fields xlfd-regexp-adstyle-subnum))
651 (registry (aref xlfd-fields xlfd-regexp-registry-subnum)))
652 (if weight (setq weight (intern weight)))
653 (if slant (setq slant (intern slant)))
654 (if width (setq width (intern width)))
655 (if adstyle (setq adstyle (intern adstyle)))
656 (dolist (elt fontlist)
657 (let ((name (cadr elt))
658 args)
659 (when (or (string-match xlfd-style-regexp name)
660 (and (setq name (car (x-list-fonts name nil nil 1)))
661 (string-match xlfd-style-regexp name)))
662 (let ((fam (match-string (1+ xlfd-regexp-family-subnum) name))
663 (wei (match-string (1+ xlfd-regexp-weight-subnum) name))
664 (sla (match-string (1+ xlfd-regexp-slant-subnum) name))
665 (wid (match-string (1+ xlfd-regexp-swidth-subnum) name))
666 (ads (match-string (1+ xlfd-regexp-adstyle-subnum) name))
667 (reg (match-string (1+ xlfd-regexp-registry-subnum) name)))
668 (if (or (and fam (setq fam (if (not (string-match "^[*?]*$" fam))
669 fam)))
670 family)
671 (setq args (list :family (or fam family))))
672 (if (or (and wei (setq wei (if (not (string-match "^[*?]*$" wei))
673 (intern wei))))
674 weight)
675 (setq args (cons :weight (cons (or wei weight) args))))
676 (if (or (and sla (setq sla (if (not (string-match "^[*?]*$" sla))
677 (intern sla))))
678 slant)
679 (setq args (cons :slant (cons (or sla slant) args))))
680 (if (or (and wid (setq wid (if (not (string-match "^[*?]*$" wid))
681 (intern wid))))
682 width)
683 (setq args (cons :width (cons (or wid width) args))))
684 (if (or (and ads (setq ads (if (not (string-match "^[*?]*$" ads))
685 (intern ads))))
686 adstyle)
687 (setq args (cons :adstyle (cons (or ads adstyle) args))))
688 (if (or (and reg (setq reg (if (not (string-match "^[*?]*$" reg))
689 reg)))
690 registry)
691 (setq args (cons :registry (cons (or reg registry) args))))
692 (setcar (cdr elt) (apply 'font-spec args))))))
693 fontlist))
694
695 (defun fontset-name-p (fontset)
696 "Return non-nil if FONTSET is valid as fontset name.
697 A valid fontset name should conform to XLFD (X Logical Font Description)
698 with \"fontset\" in `<CHARSET_REGISTRY>' field."
699 (and (string-match xlfd-tight-regexp fontset)
700 (string= (match-string (1+ xlfd-regexp-registry-subnum) fontset)
701 "fontset")))
702
703 (defun generate-fontset-menu ()
704 "Return list to be appended to `x-fixed-font-alist'.
705 Done when `mouse-set-font' is called."
706 (let (l)
707 (dolist (fontset (fontset-list))
708 (or (string-match "fontset-default$" fontset)
709 (push (list (fontset-plain-name fontset) fontset) l)))
710 (cons "Fontset"
711 (sort l #'(lambda (x y) (string< (car x) (car y)))))))
712
713 (defun fontset-plain-name (fontset)
714 "Return a plain and descriptive name of FONTSET."
715 (if (not (setq fontset (query-fontset fontset)))
716 (error "Invalid fontset: %s" fontset))
717 (let ((xlfd-fields (x-decompose-font-name fontset)))
718 (if xlfd-fields
719 (let ((family (aref xlfd-fields xlfd-regexp-family-subnum))
720 (weight (aref xlfd-fields xlfd-regexp-weight-subnum))
721 (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
722 (swidth (aref xlfd-fields xlfd-regexp-swidth-subnum))
723 (size (aref xlfd-fields xlfd-regexp-pixelsize-subnum))
724 (nickname (aref xlfd-fields xlfd-regexp-registry-subnum))
725 name)
726 (if (not (string-match "^fontset-\\(.*\\)$" nickname))
727 (setq nickname family)
728 (setq nickname (match-string 1 nickname)))
729 (if (and size (> (string-to-number size) 0))
730 (setq name (format "%s: %s-dot" nickname size))
731 (setq name nickname))
732 (and weight
733 (cond ((string-match "^medium$" weight)
734 (setq name (concat name " " "medium")))
735 ((string-match "^bold$\\|^demibold$" weight)
736 (setq name (concat name " " weight)))))
737 (and slant
738 (cond ((string-match "^i$" slant)
739 (setq name (concat name " " "italic")))
740 ((string-match "^o$" slant)
741 (setq name (concat name " " "slant")))
742 ((string-match "^ri$" slant)
743 (setq name (concat name " " "reverse italic")))
744 ((string-match "^ro$" slant)
745 (setq name (concat name " " "reverse slant")))))
746 name)
747 fontset)))
748
749 (defvar charset-script-alist
750 '((ascii . latin)
751 (latin-iso8859-1 . latin)
752 (latin-iso8859-2 . latin)
753 (latin-iso8859-3 . latin)
754 (latin-iso8859-4 . latin)
755 (latin-iso8859-9 . latin)
756 (latin-iso8859-10 . latin)
757 (latin-iso8859-13 . latin)
758 (latin-iso8859-14 . latin)
759 (latin-iso8859-15 . latin)
760 (latin-iso8859-16 . latin)
761 (latin-jisx0201 . latin)
762 (thai-tis620 . thai)
763 (cyrillic-iso8859-5 . cyrillic)
764 (arabic-iso8859-6 . arabic)
765 (greek-iso8859-7 . latin)
766 (hebrew-iso8859-8 . latin)
767 (katakana-jisx0201 . kana)
768 (chinese-gb2312 . han)
769 (chinese-gbk . han)
770 (gb18030-2-byte . han)
771 (gb18030-4-byte-bmp . han)
772 (gb18030-4-byte-ext-1 . han)
773 (gb18030-4-byte-ext-2 . han)
774 (gb18030-4-byte-smp . han)
775 (chinese-big5-1 . han)
776 (chinese-big5-2 . han)
777 (chinese-cns11643-1 . han)
778 (chinese-cns11643-2 . han)
779 (chinese-cns11643-3 . han)
780 (chinese-cns11643-4 . han)
781 (chinese-cns11643-5 . han)
782 (chinese-cns11643-6 . han)
783 (chinese-cns11643-7 . han)
784 (japanese-jisx0208 . han)
785 (japanese-jisx0208-1978 . han)
786 (japanese-jisx0212 . han)
787 (japanese-jisx0213-1 . han)
788 (japanese-jisx0213-2 . han)
789 (korean-ksc5601 . hangul)
790 (chinese-sisheng . bopomofo)
791 (vietnamese-viscii-lower . latin)
792 (vietnamese-viscii-upper . latin)
793 (arabic-digit . arabic)
794 (arabic-1-column . arabic)
795 (arabic-2-column . arabic)
796 (indian-is13194 . devanagari)
797 (indian-glyph . devanagari)
798 (indian-1-column . devanagari)
799 (indian-2-column . devanagari)
800 (tibetan-1-column . tibetan))
801 "Alist of charsets vs the corresponding most appropriate scripts.
802
803 This alist is used by the function `create-fontset-from-fontset-spec'
804 to map charsets to scripts.")
805
806 (defun create-fontset-from-fontset-spec (fontset-spec
807 &optional style-variant noerror)
808 "Create a fontset from fontset specification string FONTSET-SPEC.
809 FONTSET-SPEC is a string of the format:
810 FONTSET-NAME,SCRIPT0:FONT0,SCRIPT1:FONT1, ...
811 Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
812
813 When a frame uses the fontset as the `font' parameter, the frame's
814 default font name is derived from FONTSET-NAME by substituting
815 \"iso8859-1\" for the tail part \"fontset-XXX\". But, if SCRIPT-NAMEn
816 is \"ascii\", use the corresponding FONT-NAMEn as the default font
817 name.
818
819 Optional 2nd and 3rd arguments exist just for backward compatibility,
820 and are ignored.
821
822 It returns a name of the created fontset.
823
824 For backward compatibility, SCRIPT-NAME may be a charset name, in
825 which case, the corresponding script is decided by the variable
826 `charset-script-alist' (which see)."
827 (or (string-match "^[^,]+" fontset-spec)
828 (error "Invalid fontset spec: %s" fontset-spec))
829 (let ((idx (match-end 0))
830 (name (match-string 0 fontset-spec))
831 xlfd-fields target script fontlist)
832 (setq xlfd-fields (x-decompose-font-name name))
833 (or xlfd-fields
834 (error "Fontset name \"%s\" not conforming to XLFD" name))
835
836 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
837 (while (string-match "[, \t\n]*\\([^:]+\\):[ \t]*\\([^,]+\\)"
838 fontset-spec idx)
839 (setq idx (match-end 0))
840 (setq target (intern (match-string 1 fontset-spec)))
841 (cond ((or (eq target 'ascii)
842 (memq target (char-table-extra-slot char-script-table 0)))
843 (push (list target (match-string 2 fontset-spec)) fontlist))
844 ((setq script (cdr (assq target charset-script-alist)))
845 (push (list script (match-string 2 fontset-spec)) fontlist))
846 ((charsetp target)
847 (push (list target (match-string 2 fontset-spec)) fontlist))))
848
849 ;; Complement FONTLIST.
850 (setq fontlist (x-complement-fontset-spec xlfd-fields fontlist))
851
852 ;; Create a fontset.
853 (new-fontset name (nreverse fontlist))))
854
855 (defun create-fontset-from-ascii-font (font &optional resolved-font
856 fontset-name)
857 "Create a fontset from an ASCII font FONT.
858
859 Optional 2nd arg RESOLVED-FONT is a resolved name of FONT.
860 If omitted, `x-resolve-font-name' is called to get the resolved name.
861 At this time, if FONT is not available, an error is signaled.
862
863 Optional 3rd arg FONTSET-NAME is a string to be used in
864 `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
865 an appropriate name is generated automatically.
866
867 It returns a name of the created fontset."
868 (setq font (downcase font))
869 (setq resolved-font
870 (downcase (or resolved-font (x-resolve-font-name font))))
871 (let ((xlfd (x-decompose-font-name resolved-font))
872 fontset)
873 (if fontset-name
874 (setq fontset-name (downcase fontset-name))
875 (if (query-fontset "fontset-startup")
876 (setq fontset-name
877 (subst-char-in-string
878 ?- ?_ (aref xlfd xlfd-regexp-registry-subnum) t))
879 (setq fontset-name "startup")))
880 (aset xlfd xlfd-regexp-registry-subnum
881 (format "fontset-%s" fontset-name))
882 (setq fontset (x-compose-font-name xlfd))
883 (or (query-fontset fontset)
884 (create-fontset-from-fontset-spec (concat fontset ", ascii:" font)))))
885
886 \f
887 ;; Create standard fontset from 16 dots fonts which are the most widely
888 ;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
889 ;; specified here because FAMILY of those fonts are not "fixed" in
890 ;; many cases.
891 (defvar standard-fontset-spec
892 (purecopy "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard")
893 "String of fontset spec of the standard fontset.
894 You have the biggest chance to display international characters
895 with correct glyphs by using the standard fontset.
896 See the documentation of `create-fontset-from-fontset-spec' for the format.")
897
898
899 ;; Create fontsets from X resources of the name `fontset-N (class
900 ;; Fontset-N)' where N is integer 0, 1, ...
901 ;; The values of the resources the string of the same format as
902 ;; `standard-fontset-spec'.
903
904 (defun create-fontset-from-x-resource ()
905 (let ((idx 0)
906 fontset-spec)
907 (while (setq fontset-spec (x-get-resource (format "fontset-%d" idx)
908 (format "Fontset-%d" idx)))
909 (create-fontset-from-fontset-spec fontset-spec t 'noerror)
910 (setq idx (1+ idx)))))
911
912 ;;
913 (provide 'fontset)
914
915 ;;; arch-tag: bb53e629-0234-403c-950e-551e61554849
916 ;;; fontset.el ends here