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 2, 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 vector [ FAMILY WEIGHT SLANT ADSTYLE REGISTRY ],
233 ;; or a cons (FAMILY . REGISTRY),
234 ;; or a string FONT-NAME.
236 ;; FAMILY, WEIGHT, SLANT, and ADSTYLE may be nil, in which case, the
237 ;; the corresponding name of default face is used. If REGISTRY
238 ;; contains a character `-', the string before that is embedded in
239 ;; `CHARSET_REGISTRY' field, and the string after that is embedded in
240 ;; `CHARSET_ENCODING' field. If it does not contain `-', the whole
241 ;; string is embedded in `CHARSET_REGISTRY' field, and a wild card
242 ;; character `*' is embedded 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 (nil . "iso10646.indian-1"))
269 (lao (nil . "MuleLao-1"))
271 ;; both for script and charset.
272 (tibetan (nil . "muletibetan-2"))
274 ;; both for script and charset.
275 (ethiopic (nil . "ethiopic-unicode"))
277 (greek (nil . "ISO8859-7"))
279 (cyrillic (nil . "ISO8859-5")
280 (nil . "microsoft-cp1251")
283 (arabic (nil . "MuleArabic-0")
284 (nil . "MuleArabic-1")
285 (nil . "MuleArabic-2")
288 (hebrew (nil . "ISO8859-8"))
290 (kana (nil . "JISX0208*")
291 (nil . "GB2312.1980-0")
292 (nil . "KSC5601.1987*")
294 (nil . "JISX0213.2000-1")
295 (nil . "JISX0213.2004-1"))
297 (bopomofo (nil . "sisheng_cwnn-0"))
299 (han (nil . "GB2312.1980-0")
303 (nil . "KSC5601.1987*")
304 (nil . "CNS11643.1992-1")
305 (nil . "CNS11643.1992-2")
306 (nil . "CNS11643.1992-3")
307 (nil . "CNS11643.1992-4")
308 (nil . "CNS11643.1992-5")
309 (nil . "CNS11643.1992-6")
310 (nil . "CNS11643.1992-7")
313 (nil . "JISX0213.2000-1")
314 (nil . "JISX0213.2000-2")
315 (nil . "JISX0213.2004-1"))
317 (cjk-misc (nil . "GB2312.1980-0")
321 (nil . "KSC5601.1987*")
322 (nil . "CNS11643.1992-1")
323 (nil . "CNS11643.1992-2")
324 (nil . "CNS11643.1992-3")
325 (nil . "CNS11643.1992-4")
326 (nil . "CNS11643.1992-5")
327 (nil . "CNS11643.1992-6")
328 (nil . "CNS11643.1992-7")
331 (nil . "JISX0213.2000-1")
332 (nil . "JISX0213.2000-2"))
334 (hangul (nil . "KSC5601.1987-0"))
337 (ascii (nil . "ISO8859-1"))
338 (arabic-digit ("*" . "MuleArabic-0"))
339 (arabic-1-column ("*" . "MuleArabic-1"))
340 (arabic-2-column ("*" . "MuleArabic-2"))
341 (indian-is13194 (nil . "is13194-devanagari"))
342 (indian-1-column ("*" . "muleindian-2"))
344 (devanagari-cdac (nil . "Devanagari-CDAC"))
345 (sanskrit-cdac (nil . "Sanskrit-CDAC"))
346 (bengali-cdac (nil . "Bengali-CDAC"))
347 (assamese-cdac (nil . "Assamese-CDAC"))
348 (punjabi-cdac (nil . "Punjabi-CDAC"))
349 (gujarati-cdac (nil . "Gujarati-CDAC"))
350 (oriya-cdac (nil . "Oriya-CDAC"))
351 (tamil-cdac (nil . "Tamil-CDAC"))
352 (telugu-cdac (nil . "Telugu-CDAC"))
353 (kannada-cdac (nil . "Kannada-CDAC"))
354 (malayalam-cdac (nil . "Malayalam-CDAC"))
356 (devanagari-akruti (nil . "Devanagari-Akruti"))
357 (bengali-akruti (nil . "Bengali-Akruti"))
358 (punjabi-akruti (nil . "Punjabi-Akruti"))
359 (gujarati-akruti (nil . "Gujarati-Akruti"))
360 (oriya-akruti (nil . "Oriya-Akruti"))
361 (tamil-akruti (nil . "Tamil-Akruti"))
362 (telugu-akruti (nil . "Telugu-Akruti"))
363 (kannada-akruti (nil . "Kannada-Akruti"))
364 (malayalam-akruti (nil . "Malayalam-Akruti"))
365 ;;(devanagari-glyph ("altsys-dv_ttsurekh" . "devanagari-cdac"))
366 ;;(malayalam-glyph ("altsys-ml_ttkarthika" . "malayalam-cdac"))
367 (ipa (nil . "MuleIPA-1"))
370 (nil (nil . "gb2312.1980")
374 (nil . "ksc5601.1987")
375 (nil . "CNS11643.1992-1")
376 (nil . "CNS11643.1992-2")
377 (nil . "CNS11643.1992-3")
378 (nil . "CNS11643.1992-4")
379 (nil . "CNS11643.1992-5")
380 (nil . "CNS11643.1992-6")
381 (nil . "CNS11643.1992-7")
383 (nil . "jisx0213.2000-1")
384 (nil . "jisx0213.2004-1")
388 ;; Append Unicode fonts.
389 ;; This may find fonts with more variants (bold, italic) but which
390 ;; don't cover many characters.
391 (set-fontset-font "fontset-default" nil
392 '(nil . "iso10646-1") nil 'append)
393 ;; These may find fonts that cover many characters but with fewer
395 (set-fontset-font "fontset-default" nil
396 '("gnu-unifont" . "iso10646-1") nil 'append)
397 (set-fontset-font "fontset-default" nil
398 '("mutt-clearlyu" . "iso10646-1") nil 'append))
400 ;; These are the registered registries/encodings from
401 ;; ftp://ftp.x.org/pub/DOCS/registry 2001/06/01
407 ;; "DEC.CNS11643.1986-2" [53]
408 ;; CNS11643 2-plane using the encoding
409 ;; suggested in that standard
410 ;; "DEC.DTSCS.1990-2" [54]
411 ;; DEC Taiwan Supplemental Character Set
412 ;; "fujitsu.u90x01.1991-0" [87]
413 ;; "fujitsu.u90x03.1991-0" [87]
414 ;; "GB2312.1980-0" [39],[12]
415 ;; China (PRC) Hanzi, GL encoding
416 ;; "GB2312.1980-1" [39]
418 ;; China (PRC) Hanzi, GR encoding
420 ;; HPARABIC8 8-bit character set
422 ;; HPEAST8 8-bit character set
424 ;; HPGREEK8 8-bit character set
426 ;; HPHEBREW8 8-bit character set
427 ;; "HP-Japanese15" [36]
428 ;; HPJAPAN15 15-bit characer set,
429 ;; modified from industry defacto
430 ;; standard Shift-JIS
432 ;; HPKANA8 8-bit character set
433 ;; "HP-Korean15" [36]
434 ;; HPKOREAN15 15-bit character set
436 ;; HPROMAN8 8-bit character set
437 ;; "HP-SChinese15" [36]
438 ;; HPSCHINA15 15-bit character set for
439 ;; support of Simplified Chinese
440 ;; "HP-TChinese15" [36]
441 ;; HPTCHINA15 15-bit character set for
442 ;; support of Traditional Chinese
443 ;; "HP-Turkish8" [36]
444 ;; HPTURKISH8 8-bit character set
448 ;; "ISO2022"<REG>"-"<ENC> [44]
449 ;; "ISO646.1991-IRV" [107]
450 ;; ISO 646 International Reference Version
451 ;; "ISO8859-1" [15],[12]
452 ;; ISO Latin alphabet No. 1
453 ;; "ISO8859-2" [15],[12]
454 ;; ISO Latin alphabet No. 2
455 ;; "ISO8859-3" [15],[12]
456 ;; ISO Latin alphabet No. 3
457 ;; "ISO8859-4" [15],[12]
458 ;; ISO Latin alphabet No. 4
459 ;; "ISO8859-5" [15],[12]
460 ;; ISO Latin/Cyrillic alphabet
461 ;; "ISO8859-6" [15],[12]
462 ;; ISO Latin/Arabic alphabet
463 ;; "ISO8859-7" [15],[12]
464 ;; ISO Latin/Greek alphabet
465 ;; "ISO8859-8" [15],[12]
466 ;; ISO Latin/Hebrew alphabet
467 ;; "ISO8859-9" [15],[12]
468 ;; ISO Latin alphabet No. 5
469 ;; "ISO8859-10" [15],[12]
470 ;; ISO Latin alphabet No. 6
471 ;; "ISO8859-13" [15],[12]
472 ;; ISO Latin alphabet No. 7
473 ;; "ISO8859-14" [15],[12]
474 ;; ISO Latin alphabet No. 8
475 ;; "ISO8859-15" [15],[12]
476 ;; ISO Latin alphabet No. 9
479 ;; ISO Latin alphabet No. 9, Final Committee Draft
480 ;; "ISO10646-1" [133]
481 ;; Unicode Universal Multiple-Octet Coded Character Set
482 ;; "ISO10646-MES" [133]
484 ;; Unicode Minimum European Subset
485 ;; "JISX0201.1976-0" [38],[12]
486 ;; 8-Bit Alphanumeric-Katakana Code
487 ;; "JISX0208.1983-0" [40],[12]
488 ;; Japanese Graphic Character Set,
490 ;; "JISX0208.1990-0" [71]
491 ;; Japanese Graphic Character Set,
493 ;; "JISX0208.1983-1" [40]
495 ;; Japanese Graphic Character Set,
497 ;; "JISX0212.1990-0" [72]
498 ;; Supplementary Japanese Graphic Character Set,
502 ;; "KSC5601.1987-0" [41],[12]
503 ;; Korean Graphic Character Set,
505 ;; "KSC5601.1987-1" [41]
507 ;; Korean Graphic Character Set,
509 ;; "omron_CNS11643-0" [45]
510 ;; "omron_CNS11643-1" [45]
511 ;; "omron_BIG5-0" [45]
512 ;; "omron_BIG5-1" [45]
513 ;; "wn.tamil.1993" [103]
515 (defun set-font-encoding (pattern charset)
516 "Set arguments in `font-encoding-alist' (which see)."
517 (let ((slot (assoc pattern font-encoding-alist)))
519 (setcdr slot charset)
520 (setq font-encoding-alist
521 (cons (cons pattern charset) font-encoding-alist)))))
523 ;; Setting for suppressing XLoadQueryFont on big fonts.
524 (setq x-pixel-size-width-font-regexp
525 "gb2312\\|gbk\\|gb18030\\|jisx0208\\|ksc5601\\|cns11643\\|big5")
527 ;; These fonts require vertical centering.
528 (setq vertical-centering-font-regexp
529 "gb2312\\|gbk\\|gb18030\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5")
531 ;; CDAC fonts are actually smaller than their design sizes.
532 (setq face-font-rescale-alist
535 (defvar x-font-name-charset-alist nil
536 "This variable has no meaning now. Just kept for backward compatibility.")
538 ;;; XLFD (X Logical Font Description) format handler.
540 ;; Define XLFD's field index numbers. ; field name
541 (defconst xlfd-regexp-family-subnum 0) ; FOUNDRY and FAMILY
542 (defconst xlfd-regexp-weight-subnum 1) ; WEIGHT_NAME
543 (defconst xlfd-regexp-slant-subnum 2) ; SLANT
544 (defconst xlfd-regexp-swidth-subnum 3) ; SETWIDTH_NAME
545 (defconst xlfd-regexp-adstyle-subnum 4) ; ADD_STYLE_NAME
546 (defconst xlfd-regexp-pixelsize-subnum 5) ; PIXEL_SIZE
547 (defconst xlfd-regexp-pointsize-subnum 6) ; POINT_SIZE
548 (defconst xlfd-regexp-resx-subnum 7) ; RESOLUTION_X
549 (defconst xlfd-regexp-resy-subnum 8) ; RESOLUTION_Y
550 (defconst xlfd-regexp-spacing-subnum 8) ; SPACING
551 (defconst xlfd-regexp-avgwidth-subnum 10) ; AVERAGE_WIDTH
552 (defconst xlfd-regexp-registry-subnum 11) ; REGISTRY and ENCODING
554 ;; Regular expression matching against a fontname which conforms to
555 ;; XLFD (X Logical Font Description). All fields in XLFD should be
556 ;; not be omitted (but can be a wild card) to be matched.
557 (defconst xlfd-tight-regexp
559 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
560 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
561 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*-[^-]*\\)$")
563 ;; Regular expression matching against a fontname which conforms to
564 ;; XLFD (X Logical Font Description). All fields in XLFD from FOUNDRY
565 ;; to ADSTYLE, REGISTRY, and ENCODING should be not be omitted (but
566 ;; can be a wild card) to be matched.
567 (defconst xlfd-style-regexp
569 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-.*\
570 -\\([^-]*-[^-]*\\)$")
572 ;; List of field numbers of XLFD whose values are numeric.
573 (defconst xlfd-regexp-numeric-subnums
574 (list xlfd-regexp-pixelsize-subnum ;5
575 xlfd-regexp-pointsize-subnum ;6
576 xlfd-regexp-resx-subnum ;7
577 xlfd-regexp-resy-subnum ;8
578 xlfd-regexp-avgwidth-subnum ;10
581 (defun x-decompose-font-name (pattern)
582 "Decompose PATTERN into XLFD fields and return a vector of the fields.
583 The length of the vector is 12.
584 The FOUNDRY and FAMILY fields are concatinated and stored in the first
585 element of the vector.
586 The REGISTRY and ENCODING fields are concatinated and stored in the last
587 element of the vector.
589 Return nil if PATTERN doesn't conform to XLFD."
590 (if (string-match xlfd-tight-regexp pattern)
591 (let ((xlfd-fields (make-vector 12 nil)))
593 (aset xlfd-fields i (match-string (1+ i) pattern)))
595 (if (string-match "^[*-]+$" (aref xlfd-fields i))
596 (aset xlfd-fields i nil)))
599 (defun x-compose-font-name (fields &optional reduce)
600 "Compose X fontname from FIELDS.
601 FIELDS is a vector of XLFD fields, of length 12.
602 If a field is nil, wild-card letter `*' is embedded.
603 Optional argument REDUCE exists just for backward compatibility,
604 and is always ignored."
605 (concat "-" (mapconcat (lambda (x) (or x "*")) fields "-")))
608 (defun x-must-resolve-font-name (xlfd-fields)
609 "Like `x-resolve-font-name', but always return a font name.
610 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
611 If no font matching XLFD-FIELDS is available, successively replace
612 parts of the font name pattern with \"*\" until some font is found.
613 Value is name of that font."
614 (let ((ascii-font nil) (index 0))
615 (while (and (null ascii-font) (<= index xlfd-regexp-registry-subnum))
616 (let ((pattern (x-compose-font-name xlfd-fields)))
618 (setq ascii-font (x-resolve-font-name pattern))
620 (message "Warning: no fonts matching `%s' available" pattern)
621 (aset xlfd-fields index "*")
622 (setq index (1+ index))))))
624 (error "No fonts found"))
628 (defun x-complement-fontset-spec (xlfd-fields fontlist)
629 "Complement elements of FONTLIST based on XLFD-FIELDS.
630 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
631 FONTLIST is an alist of script names vs the corresponding font names.
633 The font names are complemented as below.
635 If a font name matches `xlfd-style-regexp', each field of wild card is
636 replaced by the corresponding fields in XLFD-FIELDS."
637 (let ((default-spec (vector (aref xlfd-fields xlfd-regexp-family-subnum)
638 (aref xlfd-fields xlfd-regexp-weight-subnum)
639 (aref xlfd-fields xlfd-regexp-slant-subnum)
640 (aref xlfd-fields xlfd-regexp-swidth-subnum)
641 (aref xlfd-fields xlfd-regexp-adstyle-subnum)
642 (aref xlfd-fields xlfd-regexp-registry-subnum))))
643 (dolist (elt fontlist)
644 (let ((name (cadr elt))
646 (when (or (string-match xlfd-style-regexp name)
647 (and (setq name (car (x-list-fonts name nil nil 1)))
648 (string-match xlfd-style-regexp name)))
649 (setq font-spec (make-vector 6 nil))
651 (aset font-spec i (match-string (1+ i) name)))
653 (if (string-match "^[*-]+$" (aref font-spec i))
654 (aset font-spec i (aref default-spec i))))
655 (setcar (cdr elt) font-spec))))
659 (defun fontset-name-p (fontset)
660 "Return non-nil if FONTSET is valid as fontset name.
661 A valid fontset name should conform to XLFD (X Logical Font Description)
662 with \"fontset\" in `<CHARSET_REGISTRY>' field."
663 (and (string-match xlfd-tight-regexp fontset)
664 (string= (match-string (1+ xlfd-regexp-registry-subnum) fontset)
667 (defun generate-fontset-menu ()
668 "Return list to be appended to `x-fixed-font-alist'.
669 Done when `mouse-set-font' is called."
671 (dolist (fontset (fontset-list))
672 (or (string-match "fontset-default$" fontset)
673 (push (list (fontset-plain-name fontset) fontset) l)))
675 (sort l #'(lambda (x y) (string< (car x) (car y)))))))
677 (defun fontset-plain-name (fontset)
678 "Return a plain and descriptive name of FONTSET."
679 (if (not (setq fontset (query-fontset fontset)))
680 (error "Invalid fontset: %s" fontset))
681 (let ((xlfd-fields (x-decompose-font-name fontset)))
683 (let ((family (aref xlfd-fields xlfd-regexp-family-subnum))
684 (weight (aref xlfd-fields xlfd-regexp-weight-subnum))
685 (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
686 (swidth (aref xlfd-fields xlfd-regexp-swidth-subnum))
687 (size (aref xlfd-fields xlfd-regexp-pixelsize-subnum))
688 (nickname (aref xlfd-fields xlfd-regexp-registry-subnum))
690 (if (not (string-match "^fontset-\\(.*\\)$" nickname))
691 (setq nickname family)
692 (setq nickname (match-string 1 nickname)))
693 (if (and size (> (string-to-number size) 0))
694 (setq name (format "%s: %s-dot" nickname size))
695 (setq name nickname))
697 (cond ((string-match "^medium$" weight)
698 (setq name (concat name " " "medium")))
699 ((string-match "^bold$\\|^demibold$" weight)
700 (setq name (concat name " " weight)))))
702 (cond ((string-match "^i$" slant)
703 (setq name (concat name " " "italic")))
704 ((string-match "^o$" slant)
705 (setq name (concat name " " "slant")))
706 ((string-match "^ri$" slant)
707 (setq name (concat name " " "reverse italic")))
708 ((string-match "^ro$" slant)
709 (setq name (concat name " " "reverse slant")))))
713 (defvar charset-script-alist
715 (latin-iso8859-1 . latin)
716 (latin-iso8859-2 . latin)
717 (latin-iso8859-3 . latin)
718 (latin-iso8859-4 . latin)
719 (latin-iso8859-9 . latin)
720 (latin-iso8859-10 . latin)
721 (latin-iso8859-13 . latin)
722 (latin-iso8859-14 . latin)
723 (latin-iso8859-15 . latin)
724 (latin-iso8859-16 . latin)
725 (latin-jisx0201 . latin)
727 (cyrillic-iso8859-5 . cyrillic)
728 (arabic-iso8859-6 . arabic)
729 (greek-iso8859-7 . latin)
730 (hebrew-iso8859-8 . latin)
731 (katakana-jisx0201 . kana)
732 (chinese-gb2312 . han)
734 (gb18030-2-byte . han)
735 (gb18030-4-byte-bmp . han)
736 (gb18030-4-byte-ext-1 . han)
737 (gb18030-4-byte-ext-2 . han)
738 (gb18030-4-byte-smp . han)
739 (chinese-big5-1 . han)
740 (chinese-big5-2 . han)
741 (chinese-cns11643-1 . han)
742 (chinese-cns11643-2 . han)
743 (chinese-cns11643-3 . han)
744 (chinese-cns11643-4 . han)
745 (chinese-cns11643-5 . han)
746 (chinese-cns11643-6 . han)
747 (chinese-cns11643-7 . han)
748 (japanese-jisx0208 . han)
749 (japanese-jisx0208-1978 . han)
750 (japanese-jisx0212 . han)
751 (japanese-jisx0213-1 . han)
752 (japanese-jisx0213-2 . han)
753 (korean-ksc5601 . hangul)
754 (chinese-sisheng . bopomofo)
755 (vietnamese-viscii-lower . latin)
756 (vietnamese-viscii-upper . latin)
757 (arabic-digit . arabic)
758 (arabic-1-column . arabic)
759 (arabic-2-column . arabic)
760 (indian-is13194 . devanagari)
761 (indian-glyph . devanagari)
762 (indian-1-column . devanagari)
763 (indian-2-column . devanagari)
764 (tibetan-1-column . tibetan))
765 "Alist of charsets vs the corresponding most appropriate scripts.
767 This alist is used by the function `create-fontset-from-fontset-spec'
768 to map charsets to scripts.")
770 (defun create-fontset-from-fontset-spec (fontset-spec
771 &optional style-variant noerror)
772 "Create a fontset from fontset specification string FONTSET-SPEC.
773 FONTSET-SPEC is a string of the format:
774 FONTSET-NAME,SCRIPT0:FONT0,SCRIPT1:FONT1, ...
775 Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
777 When a frame uses the fontset as the `font' parameter, the frame's
778 default font name is derived from FONTSET-NAME by substituting
779 \"iso8859-1\" for the tail part \"fontset-XXX\". But, if SCRIPT-NAMEn
780 is \"ascii\", use the corresponding FONT-NAMEn as the default font
783 Optional 2nd and 3rd arguments exist just for backward compatibility,
786 It returns a name of the created fontset.
788 For backward compatibility, SCRIPT-NAME may be a charset name, in
789 which case, the corresponding script is decided by the variable
790 `charset-script-alist' (which see)."
791 (or (string-match "^[^,]+" fontset-spec)
792 (error "Invalid fontset spec: %s" fontset-spec))
793 (let ((idx (match-end 0))
794 (name (match-string 0 fontset-spec))
795 xlfd-fields target script fontlist)
796 (setq xlfd-fields (x-decompose-font-name name))
798 (error "Fontset name \"%s\" not conforming to XLFD" name))
800 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
801 (while (string-match "[, \t\n]*\\([^:]+\\):[ \t]*\\([^,]+\\)"
803 (setq idx (match-end 0))
804 (setq target (intern (match-string 1 fontset-spec)))
805 (cond ((or (eq target 'ascii)
806 (memq target (char-table-extra-slot char-script-table 0)))
807 (push (list target (match-string 2 fontset-spec)) fontlist))
808 ((setq script (cdr (assq target charset-script-alist)))
809 (push (list script (match-string 2 fontset-spec)) fontlist))
811 (push (list target (match-string 2 fontset-spec)) fontlist))))
813 ;; Complement FONTLIST.
814 (setq fontlist (x-complement-fontset-spec xlfd-fields fontlist))
817 (new-fontset name (nreverse fontlist))))
819 (defun create-fontset-from-ascii-font (font &optional resolved-font
821 "Create a fontset from an ASCII font FONT.
823 Optional 2nd arg RESOLVED-FONT is a resolved name of FONT.
824 If omitted, `x-resolve-font-name' is called to get the resolved name.
825 At this time, if FONT is not available, an error is signaled.
827 Optional 3rd arg FONTSET-NAME is a string to be used in
828 `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
829 an appropriate name is generated automatically.
831 It returns a name of the created fontset."
832 (setq font (downcase font))
834 (downcase (or resolved-font (x-resolve-font-name font))))
835 (let ((xlfd (x-decompose-font-name resolved-font))
838 (setq fontset-name (downcase fontset-name))
839 (if (query-fontset "fontset-startup")
841 (subst-char-in-string
842 ?- ?_ (aref xlfd xlfd-regexp-registry-subnum) t))
843 (setq fontset-name "startup")))
844 (aset xlfd xlfd-regexp-registry-subnum
845 (format "fontset-%s" fontset-name))
846 (setq fontset (x-compose-font-name xlfd))
847 (or (query-fontset fontset)
848 (create-fontset-from-fontset-spec (concat fontset ", ascii:" font)))))
851 ;; Create standard fontset from 16 dots fonts which are the most widely
852 ;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
853 ;; specified here because FAMILY of those fonts are not "fixed" in
855 (defvar standard-fontset-spec
856 (purecopy "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard")
857 "String of fontset spec of the standard fontset.
858 You have the biggest chance to display international characters
859 with correct glyphs by using the standard fontset.
860 See the documentation of `create-fontset-from-fontset-spec' for the format.")
863 ;; Create fontsets from X resources of the name `fontset-N (class
864 ;; Fontset-N)' where N is integer 0, 1, ...
865 ;; The values of the resources the string of the same format as
866 ;; `standard-fontset-spec'.
868 (defun create-fontset-from-x-resource ()
871 (while (setq fontset-spec (x-get-resource (format "fontset-%d" idx)
872 (format "Fontset-%d" idx)))
873 (create-fontset-from-fontset-spec fontset-spec t 'noerror)
874 (setq idx (1+ idx)))))
879 ;;; arch-tag: bb53e629-0234-403c-950e-551e61554849
880 ;;; fontset.el ends here