1 ;;; fontset.el --- commands for handling fontset
3 ;; Copyright (C) 1995, 1997 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5 ;; Copyright (C) 2001 Free Software Foundation, Inc.
7 ;; National Institute of Advanced Industrial Science and Technology (AIST)
8 ;; Registration Number H13PRO009
10 ;; Keywords: mule, i18n, fontset
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
33 ;; Setup font-encoding-alist for all known encodings.
35 (setq font-encoding-alist
36 '(("iso8859-1$" . iso-8859-1
)
37 ("iso8859-2$" . iso-8859-2
)
38 ("iso8859-3$" . iso-8859-3
)
39 ("iso8859-4$" . iso-8859-4
)
40 ("iso8859-5$" . iso-8859-5
)
41 ("iso8859-6$" . iso-8859-6
)
42 ("iso8859-7$" . iso-8859-7
)
43 ("iso8859-8$" . iso-8859-8
)
44 ("iso8859-9$" . iso-8859-9
)
45 ("iso8859-10$" . iso-8859-10
)
46 ("iso8859-11$" . iso-8859-11
)
47 ("iso8859-13$" . iso-8859-13
)
48 ("iso8859-14$" . iso-8859-14
)
49 ("iso8859-15$" . iso-8859-15
)
50 ("gb2312.1980" . chinese-gb2312
)
51 ("jisx0208.1978" . japanese-jisx0208-1978
)
52 ("jisx0208" . japanese-jisx0208
)
53 ("jisx0201" . jisx0201
)
54 ("jisx0212" . japanese-jisx0212
)
55 ("ksc5601.1987" . korean-ksc5601
)
56 ("cns11643.1992.*1" . chinese-cns11643-1
)
57 ("cns11643.1992.*2" . chinese-cns11643-2
)
58 ("cns11643.1992.*3" . chinese-cns11643-3
)
59 ("cns11643.1992.*4" . chinese-cns11643-4
)
60 ("cns11643.1992.*5" . chinese-cns11643-5
)
61 ("cns11643.1992.*6" . chinese-cns11643-6
)
62 ("cns11643.1992.*7" . chinese-cns11643-7
)
63 ("cns11643.92p1-0" . chinese-cns11643-1
)
64 ("cns11643.92p2-0" . chinese-cns11643-2
)
65 ("cns11643.92p3-0" . chinese-cns11643-3
)
66 ("cns11643.92p4-0" . chinese-cns11643-4
)
67 ("cns11643.92p5-0" . chinese-cns11643-5
)
68 ("cns11643.92p6-0" . chinese-cns11643-6
)
69 ("cns11643.92p7-0" . chinese-cns11643-7
)
71 ("sisheng_cwnn" . chinese-sisheng
)
73 ("tis620" . tis620-2533
)
74 ("mulearabic-0" . arabic-digit
)
75 ("mulearabic-1" . arabic-1-column
)
76 ("mulearabic-2" . arabic-2-column
)
78 ("ethiopic-unicode" . ethiopic
)
79 ("is13194-devanagari" . indian-is13194
)
80 ("Devanagari-CDAC" . devanagari-cdac
)
81 ("Sanskrit-CDAC" . sanskrit-cdac
)
82 ("Bengali-CDAC" . bengali-cdac
)
83 ("Assamese-CDAC" . assamese-cdac
)
84 ("Punjabi-CDAC" . punjabi-cdac
)
85 ("Gujarati-CDAC" . gujarati-cdac
)
86 ("Oriya-CDAC" . oriya-cdac
)
87 ("Tamil-CDAC" . tamil-cdac
)
88 ("Telugu-CDAC" . telugu-cdac
)
89 ("Kannada-CDAC" . kannada-cdac
)
90 ("Malayalam-CDAC" . malayalam-cdac
)
91 ("Devanagari-Akruti" . devanagari-akruti
)
92 ("Bengali-Akruti" . bengali-akruti
)
93 ("Punjabi-Akruti" . punjabi-akruti
)
94 ("Gujarati-Akruti" . gujarati-akruti
)
95 ("Oriya-Akruti" . oriya-akruti
)
96 ("Tamil-Akruti" . tamil-akruti
)
97 ("Telugu-Akruti" . telugu-akruti
)
98 ("Kannada-Akruti" . kannada-akruti
)
99 ("Malayalam-Akruti" . malayalam-akruti
)
100 ("muleindian-2" . indian-2-column
)
101 ("muleindian-1" . indian-1-column
)
102 ("mulelao-1" . mule-lao
)
103 ("muletibetan-2" . tibetan
)
104 ("muletibetan-1" . tibetan-1-column
)
105 ("jisx0213.2000-1" . japanese-jisx0213-1
)
106 ("jisx0213.2000-2" . japanese-jisx0213-2
)
107 ("jisx0213.2004-1" . japanese-jisx0213.2004-
1)
108 ("abobe-symbol" . symbol
)
109 ("iso10646-1$" .
(unicode-bmp . nil
))
110 ("iso10646.indian-1" .
(unicode-bmp . nil
))))
113 ;; Set standard fontname specification of characters in the default
114 ;; fontset to find an appropriate font for each script/charset. The
115 ;; specification has the form ((SCRIPT FONT-SPEC ...) ...), where
117 ;; a vector [ FAMILY WEIGHT SLANT ADSTYLE REGISTRY ],
118 ;; or a cons (FAMILY . REGISTRY),
119 ;; or a string FONT-NAME.
121 ;; FAMILY, WEIGHT, SLANT, and ADSTYLE may be nil, in which case, the
122 ;; the corresponding name of default face is used. If REGISTRY
123 ;; contains a character `-', the string before that is embedded in
124 ;; `CHARSET_REGISTRY' field, and the string after that is embedded in
125 ;; `CHARSET_ENCODING' field. If it does not contain `-', the whole
126 ;; string is embedded in `CHARSET_REGISTRY' field, and a wild card
127 ;; character `*' is embedded in `CHARSET_ENCODING' field.
129 ;; SCRIPT is a symbol that appears as an element of the char table
130 ;; `char-script-table'. SCRIPT may be a charset specifying the range
133 (defun setup-default-fontset ()
134 "Setup the default fontset."
138 (latin (nil .
"ISO8859-1")
147 (nil .
"VISCII1.1-1"))
149 (thai (nil .
"TIS620*")
150 (nil .
"ISO8859-11"))
152 (devanagari (nil .
"iso10646.indian-1"))
154 (lao (nil .
"MuleLao-1"))
156 ;; both for script and charset.
157 (tibetan (nil .
"muletibetan-2"))
159 ;; both for script and charset.
160 (ethiopic (nil .
"ethiopic-unicode"))
162 (greek (nil .
"ISO8859-7"))
164 (cyrillic (nil .
"ISO8859-5"))
166 (arabic (nil .
"MuleArabic-0")
167 (nil .
"MuleArabic-1")
168 (nil .
"MuleArabic-2")
171 (hebrew (nil .
"ISO8859-8"))
173 (kana (nil .
"JISX0208*")
174 (nil .
"GB2312.1980-0")
175 (nil .
"KSC5601.1987*")
177 (nil .
"JISX0213.2000-1")
178 (nil .
"JISX0213.2004-1"))
180 (bopomofo (nil .
"sisheng_cwnn-0"))
182 (han (nil .
"GB2312.1980-0")
186 (nil .
"KSC5601.1987*")
187 (nil .
"CNS11643.1992-1")
188 (nil .
"CNS11643.1992-2")
189 (nil .
"CNS11643.1992-3")
190 (nil .
"CNS11643.1992-4")
191 (nil .
"CNS11643.1992-5")
192 (nil .
"CNS11643.1992-6")
193 (nil .
"CNS11643.1992-7")
195 (nil .
"JISX0213.2000-1")
196 (nil .
"JISX0213.2000-2")
197 (nil .
"JISX0213.2004-1"))
199 (cjk-misc (nil .
"GB2312.1980-0")
203 (nil .
"KSC5601.1987*")
204 (nil .
"CNS11643.1992-1")
205 (nil .
"CNS11643.1992-2")
206 (nil .
"CNS11643.1992-3")
207 (nil .
"CNS11643.1992-4")
208 (nil .
"CNS11643.1992-5")
209 (nil .
"CNS11643.1992-6")
210 (nil .
"CNS11643.1992-7")
212 (nil .
"JISX0213.2000-1")
213 (nil .
"JISX0213.2000-2"))
215 (hangul (nil .
"KSC5601.1987-0"))
218 (ascii (nil .
"ISO8859-1"))
219 (arabic-digit ("*" .
"MuleArabic-0"))
220 (arabic-1-column ("*" .
"MuleArabic-1"))
221 (arabic-2-column ("*" .
"MuleArabic-2"))
222 (indian-is13194 (nil .
"is13194-devanagari"))
223 (indian-1-column ("*" .
"muleindian-2"))
225 (devanagari-cdac (nil .
"Devanagari-CDAC"))
226 (sanskrit-cdac (nil .
"Sanskrit-CDAC"))
227 (bengali-cdac (nil .
"Bengali-CDAC"))
228 (assamese-cdac (nil .
"Assamese-CDAC"))
229 (punjabi-cdac (nil .
"Punjabi-CDAC"))
230 (gujarati-cdac (nil .
"Gujarati-CDAC"))
231 (oriya-cdac (nil .
"Oriya-CDAC"))
232 (tamil-cdac (nil .
"Tamil-CDAC"))
233 (telugu-cdac (nil .
"Telugu-CDAC"))
234 (kannada-cdac (nil .
"Kannada-CDAC"))
235 (malayalam-cdac (nil .
"Malayalam-CDAC"))
237 (devanagari-akruti (nil .
"Devanagari-Akruti"))
238 (bengali-akruti (nil .
"Bengali-Akruti"))
239 (punjabi-akruti (nil .
"Punjabi-Akruti"))
240 (gujarati-akruti (nil .
"Gujarati-Akruti"))
241 (oriya-akruti (nil .
"Oriya-Akruti"))
242 (tamil-akruti (nil .
"Tamil-Akruti"))
243 (telugu-akruti (nil .
"Telugu-Akruti"))
244 (kannada-akruti (nil .
"Kannada-Akruti"))
245 (malayalam-akruti (nil .
"Malayalam-Akruti"))
246 ;;(devanagari-glyph ("altsys-dv_ttsurekh" . "devanagari-cdac"))
247 ;;(malayalam-glyph ("altsys-ml_ttkarthika" . "malayalam-cdac"))
248 (ipa (nil .
"MuleIPA-1"))
251 (nil (nil .
"gb2312.1980")
253 (nil .
"ksc5601.1987")
254 (nil .
"CNS11643.1992-1")
255 (nil .
"CNS11643.1992-2")
256 (nil .
"CNS11643.1992-3")
257 (nil .
"CNS11643.1992-4")
258 (nil .
"CNS11643.1992-5")
259 (nil .
"CNS11643.1992-6")
260 (nil .
"CNS11643.1992-7")
262 (nil .
"jisx0213.2000-1")
263 (nil .
"jisx0213.2004-1")
267 ;; Append Unicode fonts.
268 ;; This may find fonts with more variants (bold, italic) but which
269 ;; don't cover many characters.
270 (set-fontset-font "fontset-default" nil
271 '(nil .
"iso10646-1") nil
'append
)
272 ;; These may find fonts that cover many characters but with fewer
274 (set-fontset-font "fontset-default" nil
275 '("gnu-unifont" .
"iso10646-1") nil
'append
)
276 (set-fontset-font "fontset-default" nil
277 '("mutt-clearlyu" .
"iso10646-1") nil
'append
))
279 ;; These are the registered registries/encodings from
280 ;; ftp://ftp.x.org/pub/DOCS/registry 2001/06/01
286 ;; "DEC.CNS11643.1986-2" [53]
287 ;; CNS11643 2-plane using the encoding
288 ;; suggested in that standard
289 ;; "DEC.DTSCS.1990-2" [54]
290 ;; DEC Taiwan Supplemental Character Set
291 ;; "fujitsu.u90x01.1991-0" [87]
292 ;; "fujitsu.u90x03.1991-0" [87]
293 ;; "GB2312.1980-0" [39],[12]
294 ;; China (PRC) Hanzi, GL encoding
295 ;; "GB2312.1980-1" [39]
297 ;; China (PRC) Hanzi, GR encoding
299 ;; HPARABIC8 8-bit character set
301 ;; HPEAST8 8-bit character set
303 ;; HPGREEK8 8-bit character set
305 ;; HPHEBREW8 8-bit character set
306 ;; "HP-Japanese15" [36]
307 ;; HPJAPAN15 15-bit characer set,
308 ;; modified from industry defacto
309 ;; standard Shift-JIS
311 ;; HPKANA8 8-bit character set
312 ;; "HP-Korean15" [36]
313 ;; HPKOREAN15 15-bit character set
315 ;; HPROMAN8 8-bit character set
316 ;; "HP-SChinese15" [36]
317 ;; HPSCHINA15 15-bit character set for
318 ;; support of Simplified Chinese
319 ;; "HP-TChinese15" [36]
320 ;; HPTCHINA15 15-bit character set for
321 ;; support of Traditional Chinese
322 ;; "HP-Turkish8" [36]
323 ;; HPTURKISH8 8-bit character set
327 ;; "ISO2022"<REG>"-"<ENC> [44]
328 ;; "ISO646.1991-IRV" [107]
329 ;; ISO 646 International Reference Version
330 ;; "ISO8859-1" [15],[12]
331 ;; ISO Latin alphabet No. 1
332 ;; "ISO8859-2" [15],[12]
333 ;; ISO Latin alphabet No. 2
334 ;; "ISO8859-3" [15],[12]
335 ;; ISO Latin alphabet No. 3
336 ;; "ISO8859-4" [15],[12]
337 ;; ISO Latin alphabet No. 4
338 ;; "ISO8859-5" [15],[12]
339 ;; ISO Latin/Cyrillic alphabet
340 ;; "ISO8859-6" [15],[12]
341 ;; ISO Latin/Arabic alphabet
342 ;; "ISO8859-7" [15],[12]
343 ;; ISO Latin/Greek alphabet
344 ;; "ISO8859-8" [15],[12]
345 ;; ISO Latin/Hebrew alphabet
346 ;; "ISO8859-9" [15],[12]
347 ;; ISO Latin alphabet No. 5
348 ;; "ISO8859-10" [15],[12]
349 ;; ISO Latin alphabet No. 6
350 ;; "ISO8859-13" [15],[12]
351 ;; ISO Latin alphabet No. 7
352 ;; "ISO8859-14" [15],[12]
353 ;; ISO Latin alphabet No. 8
354 ;; "ISO8859-15" [15],[12]
355 ;; ISO Latin alphabet No. 9
358 ;; ISO Latin alphabet No. 9, Final Committee Draft
359 ;; "ISO10646-1" [133]
360 ;; Unicode Universal Multiple-Octet Coded Character Set
361 ;; "ISO10646-MES" [133]
363 ;; Unicode Minimum European Subset
364 ;; "JISX0201.1976-0" [38],[12]
365 ;; 8-Bit Alphanumeric-Katakana Code
366 ;; "JISX0208.1983-0" [40],[12]
367 ;; Japanese Graphic Character Set,
369 ;; "JISX0208.1990-0" [71]
370 ;; Japanese Graphic Character Set,
372 ;; "JISX0208.1983-1" [40]
374 ;; Japanese Graphic Character Set,
376 ;; "JISX0212.1990-0" [72]
377 ;; Supplementary Japanese Graphic Character Set,
381 ;; "KSC5601.1987-0" [41],[12]
382 ;; Korean Graphic Character Set,
384 ;; "KSC5601.1987-1" [41]
386 ;; Korean Graphic Character Set,
388 ;; "omron_CNS11643-0" [45]
389 ;; "omron_CNS11643-1" [45]
390 ;; "omron_BIG5-0" [45]
391 ;; "omron_BIG5-1" [45]
392 ;; "wn.tamil.1993" [103]
394 (defun set-font-encoding (pattern charset
)
395 "Set arguments in `font-encoding-alist' (which see)."
396 (let ((slot (assoc pattern font-encoding-alist
)))
398 (setcdr slot charset
)
399 (setq font-encoding-alist
400 (cons (cons pattern charset
) font-encoding-alist
)))))
402 ;; Setting for suppressing XLoadQueryFont on big fonts.
403 (setq x-pixel-size-width-font-regexp
404 "gb2312\\|jisx0208\\|ksc5601\\|cns11643\\|big5")
406 ;; These fonts require vertical centering.
407 (setq vertical-centering-font-regexp
408 "gb2312\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5")
410 ;; CDAC fonts are actually smaller than their design sizes.
411 (setq face-font-rescale-alist
414 (defvar x-font-name-charset-alist nil
415 "This variable has no meaning now. Just kept for backward compatibility.")
417 ;;; XLFD (X Logical Font Description) format handler.
419 ;; Define XLFD's field index numbers. ; field name
420 (defconst xlfd-regexp-family-subnum
0) ; FOUNDRY and FAMILY
421 (defconst xlfd-regexp-weight-subnum
1) ; WEIGHT_NAME
422 (defconst xlfd-regexp-slant-subnum
2) ; SLANT
423 (defconst xlfd-regexp-swidth-subnum
3) ; SETWIDTH_NAME
424 (defconst xlfd-regexp-adstyle-subnum
4) ; ADD_STYLE_NAME
425 (defconst xlfd-regexp-pixelsize-subnum
5) ; PIXEL_SIZE
426 (defconst xlfd-regexp-pointsize-subnum
6) ; POINT_SIZE
427 (defconst xlfd-regexp-resx-subnum
7) ; RESOLUTION_X
428 (defconst xlfd-regexp-resy-subnum
8) ; RESOLUTION_Y
429 (defconst xlfd-regexp-spacing-subnum
8) ; SPACING
430 (defconst xlfd-regexp-avgwidth-subnum
10) ; AVERAGE_WIDTH
431 (defconst xlfd-regexp-registry-subnum
11) ; REGISTRY and ENCODING
433 ;; Regular expression matching against a fontname which conforms to
434 ;; XLFD (X Logical Font Description). All fields in XLFD should be
435 ;; not be omitted (but can be a wild card) to be matched.
436 (defconst xlfd-tight-regexp
438 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
439 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
440 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*-[^-]*\\)$")
442 ;; Regular expression matching against a fontname which conforms to
443 ;; XLFD (X Logical Font Description). All fields in XLFD from FOUNDRY
444 ;; to ADSTYLE, REGISTRY, and ENCODING should be not be omitted (but
445 ;; can be a wild card) to be matched.
446 (defconst xlfd-style-regexp
448 -\\([^-]*-[^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-.*\
449 -\\([^-]*-[^-]*\\)$")
451 ;; List of field numbers of XLFD whose values are numeric.
452 (defconst xlfd-regexp-numeric-subnums
453 (list xlfd-regexp-pixelsize-subnum
;5
454 xlfd-regexp-pointsize-subnum
;6
455 xlfd-regexp-resx-subnum
;7
456 xlfd-regexp-resy-subnum
;8
457 xlfd-regexp-avgwidth-subnum
;10
460 (defun x-decompose-font-name (pattern)
461 "Decompose PATTERN into XLFD fields and return a vector of the fields.
462 The length of the vector is 12.
463 The FOUNDRY and FAMILY fields are concatinated and stored in the first
464 element of the vector.
465 The REGISTRY and ENCODING fields are concatinated and stored in the last
466 element of the vector.
468 Return nil if PATTERN doesn't conform to XLFD."
469 (if (string-match xlfd-tight-regexp pattern
)
470 (let ((xlfd-fields (make-vector 12 nil
)))
472 (aset xlfd-fields i
(match-string (1+ i
) pattern
)))
474 (if (string-match "^[*-]+$" (aref xlfd-fields i
))
475 (aset xlfd-fields i nil
)))
478 (defun x-compose-font-name (fields &optional reduce
)
479 "Compose X fontname from FIELDS.
480 FIELDS is a vector of XLFD fields, the length 12.
481 If a field is nil, wild-card letter `*' is embedded.
482 Optional argument REDUCE is always ignored. It exists just for
483 backward compatibility."
484 (concat "-" (mapconcat (lambda (x) (or x
"*")) fields
"-")))
486 (defun x-must-resolve-font-name (xlfd-fields)
487 "Like `x-resolve-font-name', but always return a font name.
488 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
489 If no font matching XLFD-FIELDS is available, successively replace
490 parts of the font name pattern with \"*\" until some font is found.
491 Value is name of that font."
492 (let ((ascii-font nil
) (index 0))
493 (while (and (null ascii-font
) (<= index xlfd-regexp-registry-subnum
))
494 (let ((pattern (x-compose-font-name xlfd-fields
)))
496 (setq ascii-font
(x-resolve-font-name pattern
))
498 (message "Warning: no fonts matching `%s' available" pattern
)
499 (aset xlfd-fields index
"*")
500 (setq index
(1+ index
))))))
502 (error "No fonts found"))
506 (defun x-complement-fontset-spec (xlfd-fields fontlist
)
507 "Complement elements of FONTLIST based on XLFD-FIELDS.
508 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
509 FONTLIST is an alist of script names vs the corresponding font names.
511 The font names are complemented as below.
513 If a font name matches `xlfd-style-regexp', each field of wild card is
514 replaced by the corresponding fields in XLFD-FIELDS."
515 (let ((default-spec (vector (aref xlfd-fields xlfd-regexp-family-subnum
)
516 (aref xlfd-fields xlfd-regexp-weight-subnum
)
517 (aref xlfd-fields xlfd-regexp-slant-subnum
)
518 (aref xlfd-fields xlfd-regexp-swidth-subnum
)
519 (aref xlfd-fields xlfd-regexp-adstyle-subnum
)
520 (aref xlfd-fields xlfd-regexp-registry-subnum
))))
521 (dolist (elt fontlist
)
522 (let ((name (cadr elt
))
524 (when (or (string-match xlfd-style-regexp name
)
525 (and (setq name
(car (x-list-fonts name nil nil
1)))
526 (string-match xlfd-style-regexp name
)))
527 (setq font-spec
(make-vector 6 nil
))
529 (aset font-spec i
(match-string (1+ i
) name
)))
531 (if (string-match "^[*-]+$" (aref font-spec i
))
532 (aset font-spec i
(aref default-spec i
))))
533 (setcar (cdr elt
) font-spec
))))
537 (defun fontset-name-p (fontset)
538 "Return non-nil if FONTSET is valid as fontset name.
539 A valid fontset name should conform to XLFD (X Logical Font Description)
540 with \"fontset\" in `<CHARSET_REGISTRY> field."
541 (and (string-match xlfd-tight-regexp fontset
)
542 (string= (match-string (1+ xlfd-regexp-registry-subnum
) fontset
)
545 (defun generate-fontset-menu ()
546 "Return list to be appended to `x-fixed-font-alist'.
547 Done when `mouse-set-font' is called."
549 (dolist (fontset (fontset-list))
550 (or (string-match "fontset-default$" fontset
)
551 (push (list (fontset-plain-name fontset
) fontset
) l
)))
553 (sort l
#'(lambda (x y
) (string< (car x
) (car y
)))))))
555 (defun fontset-plain-name (fontset)
556 "Return a plain and descriptive name of FONTSET."
557 (if (not (setq fontset
(query-fontset fontset
)))
558 (error "Invalid fontset: %s" fontset
))
559 (let ((xlfd-fields (x-decompose-font-name fontset
)))
561 (let ((family (aref xlfd-fields xlfd-regexp-family-subnum
))
562 (weight (aref xlfd-fields xlfd-regexp-weight-subnum
))
563 (slant (aref xlfd-fields xlfd-regexp-slant-subnum
))
564 (swidth (aref xlfd-fields xlfd-regexp-swidth-subnum
))
565 (size (aref xlfd-fields xlfd-regexp-pixelsize-subnum
))
566 (nickname (aref xlfd-fields xlfd-regexp-registry-subnum
))
568 (if (not (string-match "^fontset-\\(.*\\)$" nickname
))
569 (setq nickname family
)
570 (setq nickname
(match-string 1 nickname
)))
571 (if (and size
(> (string-to-int size
) 0))
572 (setq name
(format "%s: %s-dot" nickname size
))
573 (setq name nickname
))
575 (cond ((string-match "^medium$" weight
)
576 (setq name
(concat name
" " "medium")))
577 ((string-match "^bold$\\|^demibold$" weight
)
578 (setq name
(concat name
" " weight
)))))
580 (cond ((string-match "^i$" slant
)
581 (setq name
(concat name
" " "italic")))
582 ((string-match "^o$" slant
)
583 (setq name
(concat name
" " "slant")))
584 ((string-match "^ri$" slant
)
585 (setq name
(concat name
" " "reverse italic")))
586 ((string-match "^ro$" slant
)
587 (setq name
(concat name
" " "reverse slant")))))
591 (defvar charset-script-alist
593 (latin-iso8859-1 . latin
)
594 (latin-iso8859-2 . latin
)
595 (latin-iso8859-3 . latin
)
596 (latin-iso8859-4 . latin
)
597 (latin-iso8859-9 . latin
)
598 (latin-iso8859-10 . latin
)
599 (latin-iso8859-13 . latin
)
600 (latin-iso8859-14 . latin
)
601 (latin-iso8859-15 . latin
)
602 (latin-iso8859-16 . latin
)
603 (latin-jisx0201 . latin
)
605 (cyrillic-iso8859-5 . cyrillic
)
606 (arabic-iso8859-6 . arabic
)
607 (greek-iso8859-7 . latin
)
608 (hebrew-iso8859-8 . latin
)
609 (katakana-jisx0201 . kana
)
610 (chinese-gb2312 . han
)
611 (chinese-big5-1 . han
)
612 (chinese-big5-2 . han
)
613 (chinese-cns11643-1 . han
)
614 (chinese-cns11643-2 . han
)
615 (chinese-cns11643-3 . han
)
616 (chinese-cns11643-4 . han
)
617 (chinese-cns11643-5 . han
)
618 (chinese-cns11643-6 . han
)
619 (chinese-cns11643-7 . han
)
620 (japanese-jisx0208 . han
)
621 (japanese-jisx0208-1978 . han
)
622 (japanese-jisx0212 . han
)
623 (japanese-jisx0213-1 . han
)
624 (japanese-jisx0213-2 . han
)
625 (korean-ksc5601 . hangul
)
626 (chinese-sisheng . bopomofo
)
627 (vietnamese-viscii-lower . latin
)
628 (vietnamese-viscii-upper . latin
)
629 (arabic-digit . arabic
)
630 (arabic-1-column . arabic
)
631 (arabic-2-column . arabic
)
632 (indian-is13194 . devanagari
)
633 (indian-glyph . devanagari
)
634 (indian-1-column . devanagari
)
635 (indian-2-column . devanagari
)
636 (tibetan-1-column . tibetan
))
637 "Alist of charsets vs the corresponding most appropriate scripts.
639 This alist is used by the function `create-fontset-from-fontset-spec'
640 to map charsets to scripts.")
642 (defun create-fontset-from-fontset-spec (fontset-spec
643 &optional style-variant noerror
)
644 "Create a fontset from fontset specification string FONTSET-SPEC.
645 FONTSET-SPEC is a string of the format:
646 FONTSET-NAME,SCRIPT-NAME0:FONT-NAME0,SCRIPT-NAME1:FONT-NAME1, ...
647 Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
649 When a frame uses the fontset as the `font' parameter, the frame's
650 default font name is derived from FONTSET-NAME by substituting
651 \"iso8859-1\" for the tail part \"fontset-XXX\". But, if SCRIPT-NAMEn
652 is \"ascii\", use the corresponding FONT-NAMEn as the default font
655 Optional 2nd and 3rd arguments are ignored. They exist just for
656 backward compatibility.
658 It returns a name of the created fontset.
660 For backward compatibility, SCRIPT-NAME may be a charset name, in
661 which case, the corresponding script is decided by the variable
662 `charset-script-alist' (which see)."
663 (or (string-match "^[^,]+" fontset-spec
)
664 (error "Invalid fontset spec: %s" fontset-spec
))
665 (let ((idx (match-end 0))
666 (name (match-string 0 fontset-spec
))
667 xlfd-fields script fontlist
)
668 (setq xlfd-fields
(x-decompose-font-name name
))
670 (error "Fontset name \"%s\" not conforming to XLFD" name
))
672 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
673 (while (string-match "[, \t\n]*\\([^:]+\\):\\([^,]+\\)" fontset-spec idx
)
674 (setq idx
(match-end 0))
675 (setq script
(intern (match-string 1 fontset-spec
)))
676 (if (or (eq script
'ascii
)
677 (memq script
(char-table-extra-slot char-script-table
0))
678 (setq script
(cdr (assq script charset-script-alist
))))
679 (setq fontlist
(cons (list script
(match-string 2 fontset-spec
))
682 ;; Complement FONTLIST.
683 (setq fontlist
(x-complement-fontset-spec xlfd-fields fontlist
))
686 (new-fontset name fontlist
)))
688 (defun create-fontset-from-ascii-font (font &optional resolved-font
690 "Create a fontset from an ASCII font FONT.
692 Optional 1st arg RESOLVED-FONT is a resolved name of FONT. If
693 omitted, `x-resolve-font-name' is called to get the resolved name. At
694 this time, if FONT is not available, an error is signaled.
696 Optional 2nd arg FONTSET-NAME is a string to be used in
697 `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
698 an appropriate name is generated automatically.
700 It returns a name of the created fontset."
701 (setq font
(downcase font
))
703 (downcase (or resolved-font
(x-resolve-font-name font
))))
704 (let ((xlfd (x-decompose-font-name resolved-font
))
707 (setq fontset-name
(downcase fontset-name
))
708 (if (query-fontset "fontset-startup")
710 (subst-char-in-string
711 ?- ?_
(aref xlfd xlfd-regexp-registry-subnum
) t
))
712 (setq fontset-name
"startup")))
713 (aset xlfd xlfd-regexp-registry-subnum
714 (format "fontset-%s" fontset-name
))
715 (setq fontset
(x-compose-font-name xlfd
))
716 (or (query-fontset fontset
)
717 (create-fontset-from-fontset-spec (concat fontset
", ascii:" font
)))))
720 ;; Create standard fontset from 16 dots fonts which are the most widely
721 ;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
722 ;; specified here because FAMILY of those fonts are not "fixed" in
724 (defvar standard-fontset-spec
725 (purecopy "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard")
726 "String of fontset spec of the standard fontset.
727 You have the biggest chance to display international characters
728 with correct glyphs by using the standard fontset.
729 See the documentation of `create-fontset-from-fontset-spec' for the format.")
732 ;; Create fontsets from X resources of the name `fontset-N (class
733 ;; Fontset-N)' where N is integer 0, 1, ...
734 ;; The values of the resources the string of the same format as
735 ;; `standard-fontset-spec'.
737 (defun create-fontset-from-x-resource ()
740 (while (setq fontset-spec
(x-get-resource (format "fontset-%d" idx
)
741 (format "Fontset-%d" idx
)))
742 (create-fontset-from-fontset-spec fontset-spec t
'noerror
)
743 (setq idx
(1+ idx
)))))
748 ;;; arch-tag: bb53e629-0234-403c-950e-551e61554849
749 ;;; fontset.el ends here