1 ;;; fontset.el --- commands for handling fontset
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,
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
13 ;; Keywords: mule, i18n, fontset
15 ;; This file is part of GNU Emacs.
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)
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.
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.
36 ;; Setup font-encoding-alist for all known encodings.
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)
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)
76 ("sisheng_cwnn" . chinese-sisheng)
78 ("tis620" . tis620-2533)
79 ("microsoft-cp1251" . windows-1251)
81 ("mulearabic-0" . arabic-digit)
82 ("mulearabic-1" . arabic-1-column)
83 ("mulearabic-2" . arabic-2-column)
85 ("ethiopic-unicode" . (unicode-bmp . ethiopic))
86 ("is13194-devanagari" . indian-is13194)
87 ("Devanagari-CDAC" . devanagari-cdac)
88 ("Sanskrit-CDAC" . sanskrit-cdac)
89 ("Bengali-CDAC" . bengali-cdac)
90 ("Assamese-CDAC" . assamese-cdac)
91 ("Punjabi-CDAC" . punjabi-cdac)
92 ("Gujarati-CDAC" . gujarati-cdac)
93 ("Oriya-CDAC" . oriya-cdac)
94 ("Tamil-CDAC" . tamil-cdac)
95 ("Telugu-CDAC" . telugu-cdac)
96 ("Kannada-CDAC" . kannada-cdac)
97 ("Malayalam-CDAC" . malayalam-cdac)
98 ("Devanagari-Akruti" . devanagari-akruti)
99 ("Bengali-Akruti" . bengali-akruti)
100 ("Punjabi-Akruti" . punjabi-akruti)
101 ("Gujarati-Akruti" . gujarati-akruti)
102 ("Oriya-Akruti" . oriya-akruti)
103 ("Tamil-Akruti" . tamil-akruti)
104 ("Telugu-Akruti" . telugu-akruti)
105 ("Kannada-Akruti" . kannada-akruti)
106 ("Malayalam-Akruti" . malayalam-akruti)
107 ("muleindian-2" . indian-2-column)
108 ("muleindian-1" . indian-1-column)
109 ("mulelao-1" . mule-lao)
110 ("muletibetan-2" . tibetan)
111 ("muletibetan-1" . tibetan-1-column)
112 ("jisx0213.2000-1" . japanese-jisx0213-1)
113 ("jisx0213.2000-2" . japanese-jisx0213-2)
114 ("jisx0213.2004-1" . japanese-jisx0213.2004-1)
115 ("abobe-symbol" . symbol)
116 ("iso10646-1$" . (unicode-bmp . nil))
117 ("iso10646.indian-1" . (unicode-bmp . nil))))
119 (setq script-representative-chars
120 '((latin ?A ?Z ?a ?z)
146 (canadian-aboriginal #x14C0)
152 (ideographic-description #x2FF0)
161 (setq otf-script-alist
170 (byzm . byzantine-musical-symbol)
171 (cans . canadian_aboliginal)
199 (math . mathematical)
201 (musc . musical-symbol)
214 (sylo . syloti_nagri)
228 ;; Set standard fontname specification of characters in the default
229 ;; fontset to find an appropriate font for each script/charset. The
230 ;; specification has the form ((SCRIPT FONT-SPEC ...) ...), where
232 ;; a cons (FAMILY . REGISTRY),
233 ;; or a string FONT-NAME,
234 ;; or an object created by `font-spec'.
236 ;; FAMILY may be nil, in which case, the the corresponding name of
237 ;; default face is used. If REGISTRY contains a character `-', the
238 ;; string before that is embedded in `CHARSET_REGISTRY' field, and the
239 ;; string after that is embedded in `CHARSET_ENCODING' field. If it
240 ;; does not contain `-', the whole string is embedded in
241 ;; `CHARSET_REGISTRY' field, and a wild card character `*' is embedded
242 ;; in `CHARSET_ENCODING' field.
244 ;; SCRIPT is a symbol that appears as an element of the char table
245 ;; `char-script-table'. SCRIPT may be a charset specifying the range
248 (defun setup-default-fontset ()
249 "Setup the default fontset."
253 (latin (nil . "ISO8859-1")
262 (nil . "VISCII1.1-1"))
264 (thai (nil . "TIS620*")
265 (nil . "ISO8859-11"))
267 (devanagari ,(font-spec :registry "iso10646-1" :otf '(deva nil (rphf)))
268 (nil . "iso10646.indian-1"))
269 (malayalam ,(font-spec :registry "iso10646-1" :otf '(mlym nil (akhn))))
270 (tamil ,(font-spec :registry "iso10646-1" :otf '(taml nil (akhn))))
272 (lao (nil . "MuleLao-1"))
274 (tai-viet ("TaiViet" . "iso10646-1"))
276 ;; both for script and charset.
277 (tibetan ,(font-spec :registry "iso10646-1"
278 :otf '(tibt nil (ccmp blws abvs)))
279 ,(font-spec :family "mtib" :registry "iso10646-1")
280 (nil . "muletibetan-2"))
282 ;; both for script and charset.
283 (ethiopic (nil . "ethiopic-unicode"))
285 (greek (nil . "ISO8859-7"))
287 (cyrillic (nil . "ISO8859-5")
288 (nil . "microsoft-cp1251")
291 (arabic (nil . "MuleArabic-0")
292 (nil . "MuleArabic-1")
293 (nil . "MuleArabic-2")
296 (hebrew (nil . "ISO8859-8"))
298 (kana (nil . "JISX0208*")
299 (nil . "GB2312.1980-0")
300 (nil . "KSC5601.1987*")
302 (nil . "JISX0213.2000-1")
303 (nil . "JISX0213.2004-1"))
305 (bopomofo (nil . "sisheng_cwnn-0"))
307 (han (nil . "GB2312.1980-0")
311 (nil . "KSC5601.1987*")
312 (nil . "CNS11643.1992-1")
313 (nil . "CNS11643.1992-2")
314 (nil . "CNS11643.1992-3")
315 (nil . "CNS11643.1992-4")
316 (nil . "CNS11643.1992-5")
317 (nil . "CNS11643.1992-6")
318 (nil . "CNS11643.1992-7")
321 (nil . "JISX0213.2000-1")
322 (nil . "JISX0213.2000-2")
323 (nil . "JISX0213.2004-1"))
325 (cjk-misc (nil . "GB2312.1980-0")
329 (nil . "KSC5601.1987*")
330 (nil . "CNS11643.1992-1")
331 (nil . "CNS11643.1992-2")
332 (nil . "CNS11643.1992-3")
333 (nil . "CNS11643.1992-4")
334 (nil . "CNS11643.1992-5")
335 (nil . "CNS11643.1992-6")
336 (nil . "CNS11643.1992-7")
339 (nil . "JISX0213.2000-1")
340 (nil . "JISX0213.2000-2"))
342 (hangul (nil . "KSC5601.1987-0"))
345 (ascii (nil . "ISO8859-1"))
346 (arabic-digit ("*" . "MuleArabic-0"))
347 (arabic-1-column ("*" . "MuleArabic-1"))
348 (arabic-2-column ("*" . "MuleArabic-2"))
349 (indian-is13194 (nil . "is13194-devanagari"))
350 (indian-1-column ("*" . "muleindian-2"))
352 (devanagari-cdac (nil . "Devanagari-CDAC"))
353 (sanskrit-cdac (nil . "Sanskrit-CDAC"))
354 (bengali-cdac (nil . "Bengali-CDAC"))
355 (assamese-cdac (nil . "Assamese-CDAC"))
356 (punjabi-cdac (nil . "Punjabi-CDAC"))
357 (gujarati-cdac (nil . "Gujarati-CDAC"))
358 (oriya-cdac (nil . "Oriya-CDAC"))
359 (tamil-cdac (nil . "Tamil-CDAC"))
360 (telugu-cdac (nil . "Telugu-CDAC"))
361 (kannada-cdac (nil . "Kannada-CDAC"))
362 (malayalam-cdac (nil . "Malayalam-CDAC"))
364 (devanagari-akruti (nil . "Devanagari-Akruti"))
365 (bengali-akruti (nil . "Bengali-Akruti"))
366 (punjabi-akruti (nil . "Punjabi-Akruti"))
367 (gujarati-akruti (nil . "Gujarati-Akruti"))
368 (oriya-akruti (nil . "Oriya-Akruti"))
369 (tamil-akruti (nil . "Tamil-Akruti"))
370 (telugu-akruti (nil . "Telugu-Akruti"))
371 (kannada-akruti (nil . "Kannada-Akruti"))
372 (malayalam-akruti (nil . "Malayalam-Akruti"))
373 ;;(devanagari-glyph ("altsys-dv_ttsurekh" . "devanagari-cdac"))
374 ;;(malayalam-glyph ("altsys-ml_ttkarthika" . "malayalam-cdac"))
375 (ipa (nil . "MuleIPA-1"))
378 (nil (nil . "gb2312.1980")
382 (nil . "ksc5601.1987")
383 (nil . "CNS11643.1992-1")
384 (nil . "CNS11643.1992-2")
385 (nil . "CNS11643.1992-3")
386 (nil . "CNS11643.1992-4")
387 (nil . "CNS11643.1992-5")
388 (nil . "CNS11643.1992-6")
389 (nil . "CNS11643.1992-7")
391 (nil . "jisx0213.2000-1")
392 (nil . "jisx0213.2004-1")
396 ;; Append Unicode fonts.
397 ;; This may find fonts with more variants (bold, italic) but which
398 ;; don't cover many characters.
399 (set-fontset-font "fontset-default" nil
400 '(nil . "iso10646-1") nil 'append)
401 ;; These may find fonts that cover many characters but with fewer
403 (set-fontset-font "fontset-default" nil
404 '("gnu-unifont" . "iso10646-1") nil 'append)
405 (set-fontset-font "fontset-default" nil
406 '("mutt-clearlyu" . "iso10646-1") nil 'append))
408 ;; These are the registered registries/encodings from
409 ;; ftp://ftp.x.org/pub/DOCS/registry 2001/06/01
415 ;; "DEC.CNS11643.1986-2" [53]
416 ;; CNS11643 2-plane using the encoding
417 ;; suggested in that standard
418 ;; "DEC.DTSCS.1990-2" [54]
419 ;; DEC Taiwan Supplemental Character Set
420 ;; "fujitsu.u90x01.1991-0" [87]
421 ;; "fujitsu.u90x03.1991-0" [87]
422 ;; "GB2312.1980-0" [39],[12]
423 ;; China (PRC) Hanzi, GL encoding
424 ;; "GB2312.1980-1" [39]
426 ;; China (PRC) Hanzi, GR encoding
428 ;; HPARABIC8 8-bit character set
430 ;; HPEAST8 8-bit character set
432 ;; HPGREEK8 8-bit character set
434 ;; HPHEBREW8 8-bit character set
435 ;; "HP-Japanese15" [36]
436 ;; HPJAPAN15 15-bit characer set,
437 ;; modified from industry defacto
438 ;; standard Shift-JIS
440 ;; HPKANA8 8-bit character set
441 ;; "HP-Korean15" [36]
442 ;; HPKOREAN15 15-bit character set
444 ;; HPROMAN8 8-bit character set
445 ;; "HP-SChinese15" [36]
446 ;; HPSCHINA15 15-bit character set for
447 ;; support of Simplified Chinese
448 ;; "HP-TChinese15" [36]
449 ;; HPTCHINA15 15-bit character set for
450 ;; support of Traditional Chinese
451 ;; "HP-Turkish8" [36]
452 ;; HPTURKISH8 8-bit character set
456 ;; "ISO2022"<REG>"-"<ENC> [44]
457 ;; "ISO646.1991-IRV" [107]
458 ;; ISO 646 International Reference Version
459 ;; "ISO8859-1" [15],[12]
460 ;; ISO Latin alphabet No. 1
461 ;; "ISO8859-2" [15],[12]
462 ;; ISO Latin alphabet No. 2
463 ;; "ISO8859-3" [15],[12]
464 ;; ISO Latin alphabet No. 3
465 ;; "ISO8859-4" [15],[12]
466 ;; ISO Latin alphabet No. 4
467 ;; "ISO8859-5" [15],[12]
468 ;; ISO Latin/Cyrillic alphabet
469 ;; "ISO8859-6" [15],[12]
470 ;; ISO Latin/Arabic alphabet
471 ;; "ISO8859-7" [15],[12]
472 ;; ISO Latin/Greek alphabet
473 ;; "ISO8859-8" [15],[12]
474 ;; ISO Latin/Hebrew alphabet
475 ;; "ISO8859-9" [15],[12]
476 ;; ISO Latin alphabet No. 5
477 ;; "ISO8859-10" [15],[12]
478 ;; ISO Latin alphabet No. 6
479 ;; "ISO8859-13" [15],[12]
480 ;; ISO Latin alphabet No. 7
481 ;; "ISO8859-14" [15],[12]
482 ;; ISO Latin alphabet No. 8
483 ;; "ISO8859-15" [15],[12]
484 ;; ISO Latin alphabet No. 9
487 ;; ISO Latin alphabet No. 9, Final Committee Draft
488 ;; "ISO10646-1" [133]
489 ;; Unicode Universal Multiple-Octet Coded Character Set
490 ;; "ISO10646-MES" [133]
492 ;; Unicode Minimum European Subset
493 ;; "JISX0201.1976-0" [38],[12]
494 ;; 8-Bit Alphanumeric-Katakana Code
495 ;; "JISX0208.1983-0" [40],[12]
496 ;; Japanese Graphic Character Set,
498 ;; "JISX0208.1990-0" [71]
499 ;; Japanese Graphic Character Set,
501 ;; "JISX0208.1983-1" [40]
503 ;; Japanese Graphic Character Set,
505 ;; "JISX0212.1990-0" [72]
506 ;; Supplementary Japanese Graphic Character Set,
510 ;; "KSC5601.1987-0" [41],[12]
511 ;; Korean Graphic Character Set,
513 ;; "KSC5601.1987-1" [41]
515 ;; Korean Graphic Character Set,
517 ;; "omron_CNS11643-0" [45]
518 ;; "omron_CNS11643-1" [45]
519 ;; "omron_BIG5-0" [45]
520 ;; "omron_BIG5-1" [45]
521 ;; "wn.tamil.1993" [103]
523 (defun set-font-encoding (pattern charset)
524 "Set arguments in `font-encoding-alist' (which see)."
525 (let ((slot (assoc pattern font-encoding-alist)))
527 (setcdr slot charset)
528 (setq font-encoding-alist
529 (cons (cons pattern charset) font-encoding-alist)))))
531 ;; Setting for suppressing XLoadQueryFont on big fonts.
532 (setq x-pixel-size-width-font-regexp
533 "gb2312\\|gbk\\|gb18030\\|jisx0208\\|ksc5601\\|cns11643\\|big5")
535 ;; These fonts require vertical centering.
536 (setq vertical-centering-font-regexp
537 "gb2312\\|gbk\\|gb18030\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5")
539 ;; CDAC fonts are actually smaller than their design sizes.
540 (setq face-font-rescale-alist
543 (defvar x-font-name-charset-alist nil
544 "This variable has no meaning now. Just kept for backward compatibility.")
546 ;;; XLFD (X Logical Font Description) format handler.
548 ;; Define XLFD's field index numbers. ; field name
549 (defconst xlfd-regexp-family-subnum 0) ; FOUNDRY and FAMILY
550 (defconst xlfd-regexp-weight-subnum 1) ; WEIGHT_NAME
551 (defconst xlfd-regexp-slant-subnum 2) ; SLANT
552 (defconst xlfd-regexp-swidth-subnum 3) ; SETWIDTH_NAME
553 (defconst xlfd-regexp-adstyle-subnum 4) ; ADD_STYLE_NAME
554 (defconst xlfd-regexp-pixelsize-subnum 5) ; PIXEL_SIZE
555 (defconst xlfd-regexp-pointsize-subnum 6) ; POINT_SIZE
556 (defconst xlfd-regexp-resx-subnum 7) ; RESOLUTION_X
557 (defconst xlfd-regexp-resy-subnum 8) ; RESOLUTION_Y
558 (defconst xlfd-regexp-spacing-subnum 8) ; SPACING
559 (defconst xlfd-regexp-avgwidth-subnum 10) ; AVERAGE_WIDTH
560 (defconst xlfd-regexp-registry-subnum 11) ; REGISTRY and ENCODING
562 ;; Regular expression matching against a fontname which conforms to
563 ;; XLFD (X Logical Font Description). All fields in XLFD should be
564 ;; not be omitted (but can be a wild card) to be matched.
565 (defconst xlfd-tight-regexp
567 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
568 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
569 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*-[^-]*\\)$")
571 ;; Regular expression matching against a fontname which conforms to
572 ;; XLFD (X Logical Font Description). All fields in XLFD from FOUNDRY
573 ;; to ADSTYLE, REGISTRY, and ENCODING should be not be omitted (but
574 ;; can be a wild card) to be matched.
575 (defconst xlfd-style-regexp
577 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-.*\
578 -\\([^-]*-[^-]*\\)$")
580 ;; List of field numbers of XLFD whose values are numeric.
581 (defconst xlfd-regexp-numeric-subnums
582 (list xlfd-regexp-pixelsize-subnum ;5
583 xlfd-regexp-pointsize-subnum ;6
584 xlfd-regexp-resx-subnum ;7
585 xlfd-regexp-resy-subnum ;8
586 xlfd-regexp-avgwidth-subnum ;10
589 (defun x-decompose-font-name (pattern)
590 "Decompose PATTERN into XLFD fields and return a vector of the fields.
591 The length of the vector is 12.
592 The FOUNDRY and FAMILY fields are concatinated and stored in the first
593 element of the vector.
594 The REGISTRY and ENCODING fields are concatinated and stored in the last
595 element of the vector.
597 Return nil if PATTERN doesn't conform to XLFD."
598 (if (string-match xlfd-tight-regexp pattern)
599 (let ((xlfd-fields (make-vector 12 nil)))
601 (aset xlfd-fields i (match-string (1+ i) pattern)))
603 (if (string-match "^[*-]+$" (aref xlfd-fields i))
604 (aset xlfd-fields i nil)))
607 (defun x-compose-font-name (fields &optional reduce)
608 "Compose X fontname from FIELDS.
609 FIELDS is a vector of XLFD fields, of length 12.
610 If a field is nil, wild-card letter `*' is embedded.
611 Optional argument REDUCE exists just for backward compatibility,
612 and is always ignored."
613 (concat "-" (mapconcat (lambda (x) (or x "*")) fields "-")))
616 (defun x-must-resolve-font-name (xlfd-fields)
617 "Like `x-resolve-font-name', but always return a font name.
618 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
619 If no font matching XLFD-FIELDS is available, successively replace
620 parts of the font name pattern with \"*\" until some font is found.
621 Value is name of that font."
622 (let ((ascii-font nil) (index 0))
623 (while (and (null ascii-font) (<= index xlfd-regexp-registry-subnum))
624 (let ((pattern (x-compose-font-name xlfd-fields)))
626 (setq ascii-font (x-resolve-font-name pattern))
628 (message "Warning: no fonts matching `%s' available" pattern)
629 (aset xlfd-fields index "*")
630 (setq index (1+ index))))))
632 (error "No fonts found"))
636 (defun x-complement-fontset-spec (xlfd-fields fontlist)
637 "Complement elements of FONTLIST based on XLFD-FIELDS.
638 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
639 FONTLIST is an alist of script names vs the corresponding font names.
641 The font names are complemented as below.
643 If a font name matches `xlfd-style-regexp', each field of wild card is
644 replaced by the corresponding fields in XLFD-FIELDS."
645 (let ((family (aref xlfd-fields xlfd-regexp-family-subnum))
646 (weight (aref xlfd-fields xlfd-regexp-weight-subnum))
647 (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
648 (width (aref xlfd-fields xlfd-regexp-swidth-subnum))
649 (adstyle (aref xlfd-fields xlfd-regexp-adstyle-subnum))
650 (registry (aref xlfd-fields xlfd-regexp-registry-subnum)))
651 (if weight (setq weight (intern weight)))
652 (if slant (setq slant (intern slant)))
653 (if width (setq width (intern width)))
654 (if adstyle (setq adstyle (intern adstyle)))
655 (dolist (elt fontlist)
656 (let ((name (cadr elt))
658 (when (or (string-match xlfd-style-regexp name)
659 (and (setq name (car (x-list-fonts name nil nil 1)))
660 (string-match xlfd-style-regexp name)))
661 (let ((fam (match-string (1+ xlfd-regexp-family-subnum) name))
662 (wei (match-string (1+ xlfd-regexp-weight-subnum) name))
663 (sla (match-string (1+ xlfd-regexp-slant-subnum) name))
664 (wid (match-string (1+ xlfd-regexp-swidth-subnum) name))
665 (ads (match-string (1+ xlfd-regexp-adstyle-subnum) name))
666 (reg (match-string (1+ xlfd-regexp-registry-subnum) name)))
667 (if (or (and fam (setq fam (if (not (string-match "^[*?]*$" fam))
670 (setq args (list :family (or fam family))))
671 (if (or (and wei (setq wei (if (not (string-match "^[*?]*$" wei))
674 (setq args (cons :weight (cons (or wei weight) args))))
675 (if (or (and sla (setq sla (if (not (string-match "^[*?]*$" sla))
678 (setq args (cons :slant (cons (or sla slant) args))))
679 (if (or (and wid (setq wid (if (not (string-match "^[*?]*$" wid))
682 (setq args (cons :width (cons (or wid width) args))))
683 (if (or (and ads (setq ads (if (not (string-match "^[*?]*$" ads))
686 (setq args (cons :adstyle (cons (or ads adstyle) args))))
687 (if (or (and reg (setq reg (if (not (string-match "^[*?]*$" reg))
690 (setq args (cons :registry (cons (or reg registry) args))))
691 (setcar (cdr elt) (apply 'font-spec args))))))
694 (defun fontset-name-p (fontset)
695 "Return non-nil if FONTSET is valid as fontset name.
696 A valid fontset name should conform to XLFD (X Logical Font Description)
697 with \"fontset\" in `<CHARSET_REGISTRY>' field."
698 (and (string-match xlfd-tight-regexp fontset)
699 (string= (match-string (1+ xlfd-regexp-registry-subnum) fontset)
702 (defun generate-fontset-menu ()
703 "Return list to be appended to `x-fixed-font-alist'.
704 Done when `mouse-set-font' is called."
706 (dolist (fontset (fontset-list))
707 (or (string-match "fontset-default$" fontset)
708 (push (list (fontset-plain-name fontset) fontset) l)))
710 (sort l #'(lambda (x y) (string< (car x) (car y)))))))
712 (defun fontset-plain-name (fontset)
713 "Return a plain and descriptive name of FONTSET."
714 (if (not (setq fontset (query-fontset fontset)))
715 (error "Invalid fontset: %s" fontset))
716 (let ((xlfd-fields (x-decompose-font-name fontset)))
718 (let ((family (aref xlfd-fields xlfd-regexp-family-subnum))
719 (weight (aref xlfd-fields xlfd-regexp-weight-subnum))
720 (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
721 (swidth (aref xlfd-fields xlfd-regexp-swidth-subnum))
722 (size (aref xlfd-fields xlfd-regexp-pixelsize-subnum))
723 (nickname (aref xlfd-fields xlfd-regexp-registry-subnum))
725 (if (not (string-match "^fontset-\\(.*\\)$" nickname))
726 (setq nickname family)
727 (setq nickname (match-string 1 nickname)))
728 (if (and size (> (string-to-number size) 0))
729 (setq name (format "%s: %s-dot" nickname size))
730 (setq name nickname))
732 (cond ((string-match "^medium$" weight)
733 (setq name (concat name " " "medium")))
734 ((string-match "^bold$\\|^demibold$" weight)
735 (setq name (concat name " " weight)))))
737 (cond ((string-match "^i$" slant)
738 (setq name (concat name " " "italic")))
739 ((string-match "^o$" slant)
740 (setq name (concat name " " "slant")))
741 ((string-match "^ri$" slant)
742 (setq name (concat name " " "reverse italic")))
743 ((string-match "^ro$" slant)
744 (setq name (concat name " " "reverse slant")))))
748 (defvar charset-script-alist
750 (latin-iso8859-1 . latin)
751 (latin-iso8859-2 . latin)
752 (latin-iso8859-3 . latin)
753 (latin-iso8859-4 . latin)
754 (latin-iso8859-9 . latin)
755 (latin-iso8859-10 . latin)
756 (latin-iso8859-13 . latin)
757 (latin-iso8859-14 . latin)
758 (latin-iso8859-15 . latin)
759 (latin-iso8859-16 . latin)
760 (latin-jisx0201 . latin)
762 (cyrillic-iso8859-5 . cyrillic)
763 (arabic-iso8859-6 . arabic)
764 (greek-iso8859-7 . latin)
765 (hebrew-iso8859-8 . latin)
766 (katakana-jisx0201 . kana)
767 (chinese-gb2312 . han)
769 (gb18030-2-byte . han)
770 (gb18030-4-byte-bmp . han)
771 (gb18030-4-byte-ext-1 . han)
772 (gb18030-4-byte-ext-2 . han)
773 (gb18030-4-byte-smp . han)
774 (chinese-big5-1 . han)
775 (chinese-big5-2 . han)
776 (chinese-cns11643-1 . han)
777 (chinese-cns11643-2 . han)
778 (chinese-cns11643-3 . han)
779 (chinese-cns11643-4 . han)
780 (chinese-cns11643-5 . han)
781 (chinese-cns11643-6 . han)
782 (chinese-cns11643-7 . han)
783 (japanese-jisx0208 . han)
784 (japanese-jisx0208-1978 . han)
785 (japanese-jisx0212 . han)
786 (japanese-jisx0213-1 . han)
787 (japanese-jisx0213-2 . han)
788 (korean-ksc5601 . hangul)
789 (chinese-sisheng . bopomofo)
790 (vietnamese-viscii-lower . latin)
791 (vietnamese-viscii-upper . latin)
792 (arabic-digit . arabic)
793 (arabic-1-column . arabic)
794 (arabic-2-column . arabic)
795 (indian-is13194 . devanagari)
796 (indian-glyph . devanagari)
797 (indian-1-column . devanagari)
798 (indian-2-column . devanagari)
799 (tibetan-1-column . tibetan))
800 "Alist of charsets vs the corresponding most appropriate scripts.
802 This alist is used by the function `create-fontset-from-fontset-spec'
803 to map charsets to scripts.")
805 (defun create-fontset-from-fontset-spec (fontset-spec
806 &optional style-variant noerror)
807 "Create a fontset from fontset specification string FONTSET-SPEC.
808 FONTSET-SPEC is a string of the format:
809 FONTSET-NAME,SCRIPT0:FONT0,SCRIPT1:FONT1, ...
810 Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
812 When a frame uses the fontset as the `font' parameter, the frame's
813 default font name is derived from FONTSET-NAME by substituting
814 \"iso8859-1\" for the tail part \"fontset-XXX\". But, if SCRIPT-NAMEn
815 is \"ascii\", use the corresponding FONT-NAMEn as the default font
818 Optional 2nd and 3rd arguments exist just for backward compatibility,
821 It returns a name of the created fontset.
823 For backward compatibility, SCRIPT-NAME may be a charset name, in
824 which case, the corresponding script is decided by the variable
825 `charset-script-alist' (which see)."
826 (or (string-match "^[^,]+" fontset-spec)
827 (error "Invalid fontset spec: %s" fontset-spec))
828 (let ((idx (match-end 0))
829 (name (match-string 0 fontset-spec))
830 xlfd-fields target script fontlist)
831 (setq xlfd-fields (x-decompose-font-name name))
833 (error "Fontset name \"%s\" not conforming to XLFD" name))
835 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
836 (while (string-match "[, \t\n]*\\([^:]+\\):[ \t]*\\([^,]+\\)"
838 (setq idx (match-end 0))
839 (setq target (intern (match-string 1 fontset-spec)))
840 (cond ((or (eq target 'ascii)
841 (memq target (char-table-extra-slot char-script-table 0)))
842 (push (list target (match-string 2 fontset-spec)) fontlist))
843 ((setq script (cdr (assq target charset-script-alist)))
844 (push (list script (match-string 2 fontset-spec)) fontlist))
846 (push (list target (match-string 2 fontset-spec)) fontlist))))
848 ;; Complement FONTLIST.
849 (setq fontlist (x-complement-fontset-spec xlfd-fields fontlist))
852 (new-fontset name (nreverse fontlist))))
854 (defun create-fontset-from-ascii-font (font &optional resolved-font
856 "Create a fontset from an ASCII font FONT.
858 Optional 2nd arg RESOLVED-FONT is a resolved name of FONT.
859 If omitted, `x-resolve-font-name' is called to get the resolved name.
860 At this time, if FONT is not available, an error is signaled.
862 Optional 3rd arg FONTSET-NAME is a string to be used in
863 `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
864 an appropriate name is generated automatically.
866 It returns a name of the created fontset."
867 (setq font (downcase font))
869 (downcase (or resolved-font (x-resolve-font-name font))))
870 (let ((xlfd (x-decompose-font-name resolved-font))
873 (setq fontset-name (downcase fontset-name))
874 (if (query-fontset "fontset-startup")
876 (subst-char-in-string
877 ?- ?_ (aref xlfd xlfd-regexp-registry-subnum) t))
878 (setq fontset-name "startup")))
879 (aset xlfd xlfd-regexp-registry-subnum
880 (format "fontset-%s" fontset-name))
881 (setq fontset (x-compose-font-name xlfd))
882 (or (query-fontset fontset)
883 (create-fontset-from-fontset-spec (concat fontset ", ascii:" font)))))
886 ;; Create standard fontset from 16 dots fonts which are the most widely
887 ;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
888 ;; specified here because FAMILY of those fonts are not "fixed" in
890 (defvar standard-fontset-spec
891 (purecopy "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard")
892 "String of fontset spec of the standard fontset.
893 You have the biggest chance to display international characters
894 with correct glyphs by using the standard fontset.
895 See the documentation of `create-fontset-from-fontset-spec' for the format.")
898 ;; Create fontsets from X resources of the name `fontset-N (class
899 ;; Fontset-N)' where N is integer 0, 1, ...
900 ;; The values of the resources the string of the same format as
901 ;; `standard-fontset-spec'.
903 (defun create-fontset-from-x-resource ()
906 (while (setq fontset-spec (x-get-resource (format "fontset-%d" idx)
907 (format "Fontset-%d" idx)))
908 (create-fontset-from-fontset-spec fontset-spec t 'noerror)
909 (setq idx (1+ idx)))))
914 ;;; arch-tag: bb53e629-0234-403c-950e-551e61554849
915 ;;; fontset.el ends here