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)
77 ("tis620" . tis620-2533)
78 ("microsoft-cp1251" . windows-1251)
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)
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)))
120 (setq script-representative-chars
121 '((latin ?A ?Z ?a ?z)
147 (canadian-aboriginal #x14C0)
153 (ideographic-description #x2FF0)
162 (setq otf-script-alist
171 (byzm . byzantine-musical-symbol)
172 (cans . canadian_aboliginal)
200 (math . mathematical)
202 (musc . musical-symbol)
215 (sylo . syloti_nagri)
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
233 ;; a cons (FAMILY . REGISTRY),
234 ;; or a string FONT-NAME,
235 ;; or an object created by `font-spec'.
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.
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
249 (defun setup-default-fontset ()
250 "Setup the default fontset."
254 (latin (nil . "ISO8859-1")
263 (nil . "VISCII1.1-1"))
265 (thai (nil . "TIS620*")
266 (nil . "ISO8859-11"))
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))))
273 (lao (nil . "MuleLao-1"))
275 (tai-viet ("TaiViet" . "iso10646-1"))
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"))
283 ;; both for script and charset.
284 (ethiopic (nil . "ethiopic-unicode"))
286 (greek (nil . "ISO8859-7"))
288 (cyrillic (nil . "ISO8859-5")
289 (nil . "microsoft-cp1251")
292 (arabic (nil . "MuleArabic-0")
293 (nil . "MuleArabic-1")
294 (nil . "MuleArabic-2")
297 (hebrew (nil . "ISO8859-8"))
299 (kana (nil . "JISX0208*")
300 (nil . "GB2312.1980-0")
301 (nil . "KSC5601.1987*")
303 (nil . "JISX0213.2000-1")
304 (nil . "JISX0213.2004-1"))
306 (bopomofo (nil . "sisheng_cwnn-0"))
308 (han (nil . "GB2312.1980-0")
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")
322 (nil . "JISX0213.2000-1")
323 (nil . "JISX0213.2000-2")
324 (nil . "JISX0213.2004-1"))
326 (cjk-misc (nil . "GB2312.1980-0")
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")
340 (nil . "JISX0213.2000-1")
341 (nil . "JISX0213.2000-2"))
343 (hangul (nil . "KSC5601.1987-0"))
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"))
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"))
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"))
379 (nil (nil . "gb2312.1980")
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")
392 (nil . "jisx0213.2000-1")
393 (nil . "jisx0213.2004-1")
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
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))
409 ;; These are the registered registries/encodings from
410 ;; ftp://ftp.x.org/pub/DOCS/registry 2001/06/01
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]
427 ;; China (PRC) Hanzi, GR encoding
429 ;; HPARABIC8 8-bit character set
431 ;; HPEAST8 8-bit character set
433 ;; HPGREEK8 8-bit character set
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
441 ;; HPKANA8 8-bit character set
442 ;; "HP-Korean15" [36]
443 ;; HPKOREAN15 15-bit character set
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
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
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]
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,
499 ;; "JISX0208.1990-0" [71]
500 ;; Japanese Graphic Character Set,
502 ;; "JISX0208.1983-1" [40]
504 ;; Japanese Graphic Character Set,
506 ;; "JISX0212.1990-0" [72]
507 ;; Supplementary Japanese Graphic Character Set,
511 ;; "KSC5601.1987-0" [41],[12]
512 ;; Korean Graphic Character Set,
514 ;; "KSC5601.1987-1" [41]
516 ;; Korean Graphic Character Set,
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]
524 (defun set-font-encoding (pattern charset)
525 "Set arguments in `font-encoding-alist' (which see)."
526 (let ((slot (assoc pattern font-encoding-alist)))
528 (setcdr slot charset)
529 (setq font-encoding-alist
530 (cons (cons pattern charset) font-encoding-alist)))))
532 ;; Setting for suppressing XLoadQueryFont on big fonts.
533 (setq x-pixel-size-width-font-regexp
534 "gb2312\\|gbk\\|gb18030\\|jisx0208\\|ksc5601\\|cns11643\\|big5")
536 ;; These fonts require vertical centering.
537 (setq vertical-centering-font-regexp
538 "gb2312\\|gbk\\|gb18030\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5")
540 ;; CDAC fonts are actually smaller than their design sizes.
541 (setq face-font-rescale-alist
544 (defvar x-font-name-charset-alist nil
545 "This variable has no meaning now. Just kept for backward compatibility.")
547 ;;; XLFD (X Logical Font Description) format handler.
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
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
568 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
569 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
570 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*-[^-]*\\)$")
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
578 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-.*\
579 -\\([^-]*-[^-]*\\)$")
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
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.
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)))
602 (aset xlfd-fields i (match-string (1+ i) pattern)))
604 (if (string-match "^[*-]+$" (aref xlfd-fields i))
605 (aset xlfd-fields i nil)))
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 "-")))
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)))
627 (setq ascii-font (x-resolve-font-name pattern))
629 (message "Warning: no fonts matching `%s' available" pattern)
630 (aset xlfd-fields index "*")
631 (setq index (1+ index))))))
633 (error "No fonts found"))
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.
642 The font names are complemented as below.
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))
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))
671 (setq args (list :family (or fam family))))
672 (if (or (and wei (setq wei (if (not (string-match "^[*?]*$" wei))
675 (setq args (cons :weight (cons (or wei weight) args))))
676 (if (or (and sla (setq sla (if (not (string-match "^[*?]*$" sla))
679 (setq args (cons :slant (cons (or sla slant) args))))
680 (if (or (and wid (setq wid (if (not (string-match "^[*?]*$" wid))
683 (setq args (cons :width (cons (or wid width) args))))
684 (if (or (and ads (setq ads (if (not (string-match "^[*?]*$" ads))
687 (setq args (cons :adstyle (cons (or ads adstyle) args))))
688 (if (or (and reg (setq reg (if (not (string-match "^[*?]*$" reg))
691 (setq args (cons :registry (cons (or reg registry) args))))
692 (setcar (cdr elt) (apply 'font-spec args))))))
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)
703 (defun generate-fontset-menu ()
704 "Return list to be appended to `x-fixed-font-alist'.
705 Done when `mouse-set-font' is called."
707 (dolist (fontset (fontset-list))
708 (or (string-match "fontset-default$" fontset)
709 (push (list (fontset-plain-name fontset) fontset) l)))
711 (sort l #'(lambda (x y) (string< (car x) (car y)))))))
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)))
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))
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))
733 (cond ((string-match "^medium$" weight)
734 (setq name (concat name " " "medium")))
735 ((string-match "^bold$\\|^demibold$" weight)
736 (setq name (concat name " " weight)))))
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")))))
749 (defvar charset-script-alist
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)
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)
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.
803 This alist is used by the function `create-fontset-from-fontset-spec'
804 to map charsets to scripts.")
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.
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
819 Optional 2nd and 3rd arguments exist just for backward compatibility,
822 It returns a name of the created fontset.
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))
834 (error "Fontset name \"%s\" not conforming to XLFD" name))
836 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
837 (while (string-match "[, \t\n]*\\([^:]+\\):[ \t]*\\([^,]+\\)"
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))
847 (push (list target (match-string 2 fontset-spec)) fontlist))))
849 ;; Complement FONTLIST.
850 (setq fontlist (x-complement-fontset-spec xlfd-fields fontlist))
853 (new-fontset name (nreverse fontlist))))
855 (defun create-fontset-from-ascii-font (font &optional resolved-font
857 "Create a fontset from an ASCII font FONT.
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.
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.
867 It returns a name of the created fontset."
868 (setq font (downcase font))
870 (downcase (or resolved-font (x-resolve-font-name font))))
871 (let ((xlfd (x-decompose-font-name resolved-font))
874 (setq fontset-name (downcase fontset-name))
875 (if (query-fontset "fontset-startup")
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)))))
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
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.")
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'.
904 (defun create-fontset-from-x-resource ()
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)))))
915 ;;; arch-tag: bb53e629-0234-403c-950e-551e61554849
916 ;;; fontset.el ends here