1 ;;; fontset.el --- commands for handling fontset
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003
5 ;; National Institute of Advanced Industrial Science and Technology (AIST)
6 ;; Registration Number H14PRO021
8 ;; Keywords: mule, multilingual, fontset
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
31 ;; Set standard fontname specification of characters in the default
32 ;; fontset to find an appropriate font for each charset. This is used
33 ;; to generate a font name for a fontset if the fontset doesn't
34 ;; specify a font name for a specific character. The specification
35 ;; has the form (FAMILY . REGISTRY). FAMILY may be nil, in which
36 ;; case, the family name of default face is used. If REGISTRY
37 ;; contains a character `-', the string before that is embedded in
38 ;; `CHARSET_REGISTRY' field, and the string after that is embedded in
39 ;; `CHARSET_ENCODING' field. If it does not contain `-', the whole
40 ;; string is embedded in `CHARSET_REGISTRY' field, and a wild card
41 ;; character `*' is embedded in `CHARSET_ENCODING' field. The
42 ;; REGISTRY for ASCII characters are predefined as "ISO8859-1".
44 (defun setup-default-fontset ()
45 "Setup the default fontset."
47 `((latin-iso8859-1 .
(nil .
"ISO8859-1"))
48 (latin-iso8859-2 .
(nil .
"ISO8859-2"))
49 (latin-iso8859-3 .
(nil .
"ISO8859-3"))
50 (latin-iso8859-4 .
(nil .
"ISO8859-4"))
51 ;; Setting "*" family is for a workaround of the problem
52 ;; that a font of wrong size is preferred if the font
53 ;; family matches with a requested one.
54 (thai-tis620 .
("*" .
"TIS620"))
55 (greek-iso8859-7 .
(nil .
"ISO8859-7"))
56 (arabic-iso8859-6 .
(nil .
"ISO8859-6"))
57 (hebrew-iso8859-8 .
(nil .
"ISO8859-8"))
58 (katakana-jisx0201 .
(nil .
"JISX0201"))
59 (latin-jisx0201 .
(nil .
"JISX0201"))
60 (cyrillic-iso8859-5 .
(nil .
"ISO8859-5"))
61 (latin-iso8859-9 .
(nil .
"ISO8859-9"))
62 (japanese-jisx0208-1978 .
(nil .
"JISX0208.1978"))
63 (chinese-gb2312 .
(nil .
"GB2312.1980"))
64 (japanese-jisx0208 .
(nil .
"JISX0208.1990"))
65 (korean-ksc5601 .
(nil .
"KSC5601.1989"))
66 (japanese-jisx0212 .
(nil .
"JISX0212"))
67 (chinese-cns11643-1 .
(nil .
"CNS11643.1992-1"))
68 (chinese-cns11643-2 .
(nil .
"CNS11643.1992-2"))
69 (chinese-cns11643-3 .
(nil .
"CNS11643.1992-3"))
70 (chinese-cns11643-4 .
(nil .
"CNS11643.1992-4"))
71 (chinese-cns11643-5 .
(nil .
"CNS11643.1992-5"))
72 (chinese-cns11643-6 .
(nil .
"CNS11643.1992-6"))
73 (chinese-cns11643-7 .
(nil .
"CNS11643.1992-7"))
74 (chinese-big5-1 .
(nil .
"Big5"))
75 (chinese-big5-2 .
(nil .
"Big5"))
76 (chinese-sisheng .
(nil .
"sisheng_cwnn"))
77 (vietnamese-viscii-lower .
(nil .
"VISCII1.1"))
78 (vietnamese-viscii-upper .
(nil .
"VISCII1.1"))
79 (arabic-digit .
(nil .
"MuleArabic-0"))
80 (arabic-1-column .
(nil .
"MuleArabic-1"))
81 (arabic-2-column .
(nil .
"MuleArabic-2"))
82 (ipa .
(nil .
"MuleIPA"))
83 (ethiopic .
(nil .
"Ethiopic-Unicode"))
84 (ascii-right-to-left .
(nil .
"ISO8859-1"))
85 (indian-is13194 .
(nil .
"IS13194-Devanagari"))
86 (indian-2-column .
(nil .
"MuleIndian-2"))
87 (lao .
(nil .
"MuleLao-1"))
88 (tibetan .
("proportional" .
"MuleTibetan-2"))
89 (tibetan-1-column .
(nil .
"MuleTibetan-1"))
90 (latin-iso8859-14 .
(nil .
"ISO8859-14"))
91 (latin-iso8859-15 .
(nil .
"ISO8859-15"))
92 (mule-unicode-0100-24ff .
(nil .
"ISO10646-1"))
93 (mule-unicode-2500-33ff .
(nil .
"ISO10646-1"))
94 (mule-unicode-e000-ffff .
(nil .
"ISO10646-1"))
95 (japanese-jisx0213-1 .
(nil .
"JISX0213.2000-1"))
96 (japanese-jisx0213-2 .
(nil .
"JISX0213.2000-2"))
98 ((,(decode-char 'ucs
#x0900
) .
,(decode-char 'ucs
#x097F
))
99 .
(nil .
"ISO10646.indian-1"))
101 (,(indian-font-char-range 'cdac
:dv-ttsurekh
)
102 .
(nil .
"Devanagari-CDAC"))
103 (,(indian-font-char-range 'cdac
:sd-ttsurekh
)
104 .
(nil .
"Sanskrit-CDAC"))
105 (,(indian-font-char-range 'cdac
:bn-ttdurga
)
106 .
(nil .
"Bengali-CDAC"))
107 (,(indian-font-char-range 'cdac
:as-ttdurga
)
108 .
(nil .
"Assamese-CDAC"))
109 (,(indian-font-char-range 'cdac
:pn-ttamar
)
110 .
(nil .
"Punjabi-CDAC"))
111 (,(indian-font-char-range 'cdac
:gj-ttavantika
)
112 .
(nil .
"Gujarati-CDAC"))
113 (,(indian-font-char-range 'cdac
:or-ttsarala
)
114 .
(nil .
"Oriya-CDAC"))
115 (,(indian-font-char-range 'cdac
:tm-ttvalluvar
)
116 .
(nil .
"Tamil-CDAC"))
117 (,(indian-font-char-range 'cdac
:tl-tthemalatha
)
118 .
(nil .
"Telugu-CDAC"))
119 (,(indian-font-char-range 'cdac
:kn-ttuma
)
120 .
(nil .
"Kannada-CDAC"))
121 (,(indian-font-char-range 'cdac
:ml-ttkarthika
)
122 .
(nil .
"Malayalam-CDAC"))
124 (,(indian-font-char-range 'akruti
:dev
)
125 .
(nil .
"Devanagari-Akruti"))
126 (,(indian-font-char-range 'akruti
:bng
)
127 .
(nil .
"Bengali-Akruti"))
128 (,(indian-font-char-range 'akruti
:pnj
)
129 .
(nil .
"Punjabi-Akruti"))
130 (,(indian-font-char-range 'akruti
:guj
)
131 .
(nil .
"Gujarati-Akruti"))
132 (,(indian-font-char-range 'akruti
:ori
)
133 .
(nil .
"Oriay-Akruti"))
134 (,(indian-font-char-range 'akruti
:tml
)
135 .
(nil .
"Tamil-Akruti"))
136 (,(indian-font-char-range 'akruti
:tlg
)
137 .
(nil .
"Telugu-Akruti"))
138 (,(indian-font-char-range 'akruti
:knd
)
139 .
(nil .
"Kannada-Akruti"))
140 (,(indian-font-char-range 'akruti
:mal
)
141 .
(nil .
"Malayalam-Akruti"))
143 (set-fontset-font "fontset-default" (car elt
) (cdr elt
))))
145 ;; Set arguments in `font-encoding-alist' (which see).
146 (defun set-font-encoding (pattern charset encoding
)
147 (let ((slot (assoc pattern font-encoding-alist
)))
149 (let ((place (assq charset
(cdr slot
))))
151 (setcdr place encoding
)
152 (setcdr slot
(cons (cons charset encoding
) (cdr slot
)))))
153 (setq font-encoding-alist
154 (cons (list pattern
(cons charset encoding
)) font-encoding-alist
)))
157 ;; Allow display of arbitrary characters with an iso-10646-encoded
159 (define-translation-table 'ucs-mule-to-mule-unicode
160 ucs-mule-to-mule-unicode
)
161 (define-translation-hash-table 'ucs-mule-cjk-to-unicode
162 ucs-mule-cjk-to-unicode
)
164 (define-ccl-program ccl-encode-unicode-font
167 ;; r1: 1st position code
168 ;; r2: 2nd position code (if r0 is 2D charset)
169 ((if (r0 == ,(charset-id 'ascii
))
172 ;; At first, try to get a Unicode code point directly.
174 ;; This is a 2D charset.
175 (r1 = ((r1 << 7) | r2
)))
176 (lookup-character ucs-mule-cjk-to-unicode r0 r1
)
181 ;; Look for a translation for non-ASCII chars.
182 ((translate-character ucs-mule-to-mule-unicode r0 r1
)
183 (if (r0 == ,(charset-id 'latin-iso8859-1
))
188 (if (r0 == ,(charset-id 'mule-unicode-0100-24ff
))
191 (r1 += ,(- #x100
(* 32 96) 32))
194 (if (r0 == ,(charset-id 'mule-unicode-2500-33ff
))
197 (r1 += ,(- #x2500
(* 32 96) 32))
200 (if (r0 == ,(charset-id 'mule-unicode-e000-ffff
))
203 (r1 += ,(- #xe000
(* 32 96) 32))
206 ;; No way, use the glyph for U+FFFD.
208 (r2 = #xFD
)))))))))))))
209 "Encode characters for display with iso10646 font.
210 Translate through the translation-hash-table named
211 `ucs-mule-cjk-to-unicode' and the translation-table named
212 `ucs-mule-to-mule-unicode' initially.")
214 ;; Use the above CCL encoder for Unicode fonts. Please note that the
215 ;; regexp is not simply "ISO10646-1" because there exists, for
216 ;; instance, the following Devanagari Unicode fonts:
217 ;; -misc-fixed-medium-r-normal--24-240-72-72-c-120-iso10646.indian-1
218 ;; -sibal-devanagari-medium-r-normal--24-240-75-75-P--iso10646-dev
219 (setq font-ccl-encoder-alist
220 (cons '("ISO10646.*-*" . ccl-encode-unicode-font
)
221 font-ccl-encoder-alist
))
223 ;; Setting for suppressing XLoadQueryFont on big fonts.
224 (setq x-pixel-size-width-font-regexp
225 "gb2312\\|jisx0208\\|ksc5601\\|cns11643\\|big5")
227 ;; These fonts require vertical centering.
228 (setq vertical-centering-font-regexp
229 "gb2312\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5")
231 ;; CDAC fonts are actually smaller than their design sizes.
232 (setq face-font-rescale-alist
235 (defvar x-font-name-charset-alist
236 '(("iso8859-1" ascii latin-iso8859-1
)
237 ("iso8859-2" ascii latin-iso8859-2
)
238 ("iso8859-3" ascii latin-iso8859-3
)
239 ("iso8859-4" ascii latin-iso8859-4
)
240 ("iso8859-5" ascii cyrillic-iso8859-5
)
241 ("iso8859-6" ascii arabic-iso8859-6
)
242 ("iso8859-7" ascii greek-iso8859-7
)
243 ("iso8859-8" ascii hebrew-iso8859-8
)
244 ("iso8859-14" ascii latin-iso8859-14
)
245 ("iso8859-15" ascii latin-iso8859-15
)
246 ("tis620" ascii thai-tis620
)
247 ("koi8" ascii cyrillic-iso8859-5
)
248 ("viscii" ascii vietnamese-viscii-upper vietnamese-viscii-lower
)
249 ("vscii" ascii vietnamese-viscii-upper vietnamese-viscii-lower
)
250 ("mulelao-1" ascii lao
)
251 ("iso10646-1" ascii latin-iso8859-1 mule-unicode-0100-24ff
252 mule-unicode-2500-33ff mule-unicode-e000-ffff
))
253 "Alist of font names vs list of charsets the font can display.
255 When a font name which matches some element of this alist is given as
256 `-fn' command line argument or is specified by X resource, a fontset
257 which uses the specified font for the corresponding charsets are
258 created and used for the initial frame.")
260 ;;; XLFD (X Logical Font Description) format handler.
262 ;; Define XLFD's field index numbers. ; field name
263 (defconst xlfd-regexp-foundry-subnum
0) ; FOUNDRY
264 (defconst xlfd-regexp-family-subnum
1) ; FAMILY_NAME
265 (defconst xlfd-regexp-weight-subnum
2) ; WEIGHT_NAME
266 (defconst xlfd-regexp-slant-subnum
3) ; SLANT
267 (defconst xlfd-regexp-swidth-subnum
4) ; SETWIDTH_NAME
268 (defconst xlfd-regexp-adstyle-subnum
5) ; ADD_STYLE_NAME
269 (defconst xlfd-regexp-pixelsize-subnum
6) ; PIXEL_SIZE
270 (defconst xlfd-regexp-pointsize-subnum
7) ; POINT_SIZE
271 (defconst xlfd-regexp-resx-subnum
8) ; RESOLUTION_X
272 (defconst xlfd-regexp-resy-subnum
9) ; RESOLUTION_Y
273 (defconst xlfd-regexp-spacing-subnum
10) ; SPACING
274 (defconst xlfd-regexp-avgwidth-subnum
11) ; AVERAGE_WIDTH
275 (defconst xlfd-regexp-registry-subnum
12) ; CHARSET_REGISTRY
276 (defconst xlfd-regexp-encoding-subnum
13) ; CHARSET_ENCODING
278 ;; Regular expression matching against a fontname which conforms to
279 ;; XLFD (X Logical Font Description). All fields in XLFD should be
280 ;; not be omitted (but can be a wild card) to be matched.
281 (defconst xlfd-tight-regexp
283 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
284 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
285 -\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)$")
287 ;; List of field numbers of XLFD whose values are numeric.
288 (defconst xlfd-regexp-numeric-subnums
289 (list xlfd-regexp-pixelsize-subnum
;6
290 xlfd-regexp-pointsize-subnum
;7
291 xlfd-regexp-resx-subnum
;8
292 xlfd-regexp-resy-subnum
;9
293 xlfd-regexp-avgwidth-subnum
;11
296 (defun x-decompose-font-name (pattern)
297 "Decompose PATTERN into XLFD's fields and return vector of the fields.
298 The length of the vector is 14.
300 If PATTERN doesn't conform to XLFD, try to get a full XLFD name from
301 X server and use the information of the full name to decompose
302 PATTERN. If no full XLFD name is gotten, return nil."
303 (let (xlfd-fields fontname
)
304 (if (string-match xlfd-tight-regexp pattern
)
306 (setq xlfd-fields
(make-vector 14 nil
))
308 (aset xlfd-fields i
(match-string (1+ i
) pattern
))
311 (setq fontname
(condition-case nil
312 (x-resolve-font-name pattern
)
315 (string-match xlfd-tight-regexp fontname
))
316 ;; We get a full XLFD name.
317 (let ((len (length pattern
))
320 ;; Setup xlfd-fields by the full XLFD name. Each element
321 ;; should be a cons of matched index and matched string.
322 (setq xlfd-fields
(make-vector 14 nil
))
325 (cons (match-beginning (1+ i
))
326 (match-string (1+ i
) fontname
)))
329 ;; Replace wild cards in PATTERN by regexp codes.
332 (let ((ch (aref pattern i
)))
334 (setq pattern
(concat (substring pattern
0 i
)
336 (substring pattern
(1+ i
)))
340 (setq pattern
(concat (substring pattern
0 i
)
342 (substring pattern
(1+ i
)))
347 ;; Set each element of xlfd-fields to proper strings.
348 (if (string-match pattern fontname
)
349 ;; The regular expression PATTERN matchs the full XLFD
350 ;; name. Set elements that correspond to a wild card
351 ;; in PATTERN to "*", set the other elements to the
352 ;; exact strings in PATTERN.
353 (let ((l (cdr (cdr (match-data)))))
356 (if (or (null l
) (< (car (aref xlfd-fields i
)) (car l
)))
358 (aset xlfd-fields i
(cdr (aref xlfd-fields i
)))
360 (if (< (car (aref xlfd-fields i
)) (car (cdr l
)))
362 (aset xlfd-fields i
"*")
364 (setq l
(cdr (cdr l
)))))))
365 ;; Set each element of xlfd-fields to the exact string
366 ;; in the corresonding fields in full XLFD name.
369 (aset xlfd-fields i
(cdr (aref xlfd-fields i
)))
373 ;; Replace consecutive wild-cards (`*') in NAME to one.
374 ;; Ex. (x-reduce-font-name "-*-*-*-iso8859-1") => "-*-iso8859-1"
375 (defsubst x-reduce-font-name
(name)
376 (while (string-match "-\\*-\\(\\*-\\)+" name
)
377 (setq name
(replace-match "-*-" t t name
)))
380 (defun x-compose-font-name (fields &optional reduce
)
381 "Compose X's fontname from FIELDS.
382 FIELDS is a vector of XLFD fields, the length 14.
383 If a field is nil, wild-card letter `*' is embedded.
384 Optional argument REDUCE is always ignored. It exists just for
385 backward compatibility."
386 (concat "-" (mapconcat (lambda (x) (or x
"*")) fields
"-")))
389 (defun x-must-resolve-font-name (xlfd-fields)
390 "Like `x-resolve-font-name', but always return a font name.
391 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
392 If no font matching XLFD-FIELDS is available, successively replace
393 parts of the font name pattern with \"*\" until some font is found.
394 Value is name of that font."
395 (let ((ascii-font nil
) (index 0))
396 (while (and (null ascii-font
) (<= index xlfd-regexp-encoding-subnum
))
397 (let ((pattern (x-compose-font-name xlfd-fields
)))
399 (setq ascii-font
(x-resolve-font-name pattern
))
401 (message "Warning: no fonts matching `%s' available" pattern
)
402 (aset xlfd-fields index
"*")
403 (setq index
(1+ index
))))))
405 (error "No fonts found"))
409 (defun x-complement-fontset-spec (xlfd-fields fontlist
)
410 "Complement FONTLIST for charsets based on XLFD-FIELDS and return it.
411 XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
412 FONTLIST is an alist of charsets vs the corresponding font names.
414 The fonts are complemented as below.
416 If FONTLIST doesn't specify a font for ASCII charset, generate a font
417 name for the charset from XLFD-FIELDS, and add that information to
420 If a font specifid for ASCII supports the other charsets (see the
421 variable `x-font-name-charset-alist'), add that information to FONTLIST."
422 (let* ((slot (assq 'ascii fontlist
))
423 (ascii-font (cdr slot
))
426 (setcdr slot
(setq ascii-font
(x-resolve-font-name ascii-font
)))
427 ;; If font for ASCII is not specified, add it.
428 (aset xlfd-fields xlfd-regexp-registry-subnum
"iso8859")
429 (aset xlfd-fields xlfd-regexp-encoding-subnum
"1")
430 (setq ascii-font
(x-must-resolve-font-name xlfd-fields
))
431 (setq fontlist
(cons (cons 'ascii ascii-font
) fontlist
)))
433 ;; If the font for ASCII also supports the other charsets, and
434 ;; they are not specified in FONTLIST, add them.
435 (setq xlfd-fields
(x-decompose-font-name ascii-font
))
436 (if (not xlfd-fields
)
437 (setq ascii-font-spec ascii-font
)
438 (setq ascii-font-spec
439 (cons (format "%s-%s"
440 (aref xlfd-fields xlfd-regexp-foundry-subnum
)
441 (aref xlfd-fields xlfd-regexp-family-subnum
))
443 (aref xlfd-fields xlfd-regexp-registry-subnum
)
444 (aref xlfd-fields xlfd-regexp-encoding-subnum
)))))
445 (let ((tail x-font-name-charset-alist
)
448 (setq elt
(car tail
) tail
(cdr tail
))
449 (if (string-match (car elt
) ascii-font
)
450 (let ((charsets (cdr elt
))
453 (setq charset
(car charsets
) charsets
(cdr charsets
))
454 (or (assq charset fontlist
)
456 (cons (cons charset ascii-font-spec
) fontlist
))))))))
460 (defun fontset-name-p (fontset)
461 "Return non-nil if FONTSET is valid as fontset name.
462 A valid fontset name should conform to XLFD (X Logical Font Description)
463 with \"fontset\" in `<CHARSET_REGISTRY> field."
464 (and (string-match xlfd-tight-regexp fontset
)
465 (string= (match-string (1+ xlfd-regexp-registry-subnum
) fontset
)
468 ;; Return a list to be appended to `x-fixed-font-alist' when
469 ;; `mouse-set-font' is called.
470 (defun generate-fontset-menu ()
471 (let ((fontsets (fontset-list))
475 (setq fontset-name
(car fontsets
) fontsets
(cdr fontsets
))
476 (setq l
(cons (list (fontset-plain-name fontset-name
) fontset-name
) l
)))
478 (sort l
(function (lambda (x y
) (string< (car x
) (car y
))))))))
480 (defun fontset-plain-name (fontset)
481 "Return a plain and descriptive name of FONTSET."
482 (if (not (setq fontset
(query-fontset fontset
)))
483 (error "Invalid fontset: %s" fontset
))
484 (let ((xlfd-fields (x-decompose-font-name fontset
)))
486 (let ((weight (aref xlfd-fields xlfd-regexp-weight-subnum
))
487 (slant (aref xlfd-fields xlfd-regexp-slant-subnum
))
488 (swidth (aref xlfd-fields xlfd-regexp-swidth-subnum
))
489 (size (aref xlfd-fields xlfd-regexp-pixelsize-subnum
))
490 (charset (aref xlfd-fields xlfd-regexp-registry-subnum
))
491 (nickname (aref xlfd-fields xlfd-regexp-encoding-subnum
))
493 (if (not (string= "fontset" charset
))
495 (if (> (string-to-number size
) 0)
496 (setq name
(format "%s: %s-dot" nickname size
))
497 (setq name nickname
))
498 (cond ((string-match "^medium$" weight
)
499 (setq name
(concat name
" " "medium")))
500 ((string-match "^bold$\\|^demibold$" weight
)
501 (setq name
(concat name
" " weight
))))
502 (cond ((string-match "^i$" slant
)
503 (setq name
(concat name
" " "italic")))
504 ((string-match "^o$" slant
)
505 (setq name
(concat name
" " "slant")))
506 ((string-match "^ri$" slant
)
507 (setq name
(concat name
" " "reverse italic")))
508 ((string-match "^ro$" slant
)
509 (setq name
(concat name
" " "reverse slant"))))
514 (defun create-fontset-from-fontset-spec (fontset-spec
515 &optional style-variant noerror
)
516 "Create a fontset from fontset specification string FONTSET-SPEC.
517 FONTSET-SPEC is a string of the format:
518 FONTSET-NAME,CHARSET-NAME0:FONT-NAME0,CHARSET-NAME1:FONT-NAME1, ...
519 Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
521 Optional 2nd argument is ignored. It exists just for backward
524 If this function attempts to create already existing fontset, error is
525 signaled unless the optional 3rd argument NOERROR is non-nil.
527 It returns a name of the created fontset."
528 (if (not (string-match "^[^,]+" fontset-spec
))
529 (error "Invalid fontset spec: %s" fontset-spec
))
530 (setq fontset-spec
(downcase fontset-spec
))
531 (let ((idx (match-end 0))
532 (name (match-string 0 fontset-spec
))
533 xlfd-fields charset fontlist ascii-font
)
534 (if (query-fontset name
)
536 (error "Fontset \"%s\" already exists" name
))
537 (setq xlfd-fields
(x-decompose-font-name name
))
539 (error "Fontset \"%s\" not conforming to XLFD" name
))
541 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
542 (while (string-match "[, \t\n]*\\([^:]+\\):\\([^,]+\\)" fontset-spec idx
)
543 (setq idx
(match-end 0))
544 (setq charset
(intern (match-string 1 fontset-spec
)))
545 (if (charsetp charset
)
546 (setq fontlist
(cons (cons charset
(match-string 2 fontset-spec
))
548 (setq ascii-font
(cdr (assq 'ascii fontlist
)))
550 ;; Complement FONTLIST.
551 (setq fontlist
(x-complement-fontset-spec xlfd-fields fontlist
))
553 (new-fontset name fontlist
)
555 ;; Define the short name alias.
556 (if (and (string-match "fontset-.*$" name
)
557 (not (assoc name fontset-alias-alist
)))
558 (let ((alias (match-string 0 name
)))
559 (or (rassoc alias fontset-alias-alist
)
560 (setq fontset-alias-alist
561 (cons (cons name alias
) fontset-alias-alist
)))))
563 ;; Define the ASCII font name alias.
565 (setq ascii-font
(cdr (assq 'ascii fontlist
))))
566 (or (rassoc ascii-font fontset-alias-alist
)
567 (setq fontset-alias-alist
568 (cons (cons name ascii-font
)
569 fontset-alias-alist
))))
573 (defun create-fontset-from-ascii-font (font &optional resolved-font
575 "Create a fontset from an ASCII font FONT.
577 Optional 1st arg RESOLVED-FONT is a resolved name of FONT. If
578 omitted, `x-resolve-font-name' is called to get the resolved name. At
579 this time, if FONT is not available, error is signaled.
581 Optional 2nd arg FONTSET-NAME is a string to be used in
582 `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
583 an appropriate name is generated automatically.
585 It returns a name of the created fontset."
586 (setq font
(downcase font
))
588 (setq resolved-font
(downcase resolved-font
))
589 (setq resolved-font
(downcase (x-resolve-font-name font
))))
590 (let ((xlfd (x-decompose-font-name font
))
591 (resolved-xlfd (x-decompose-font-name resolved-font
))
592 fontset fontset-spec
)
593 (aset xlfd xlfd-regexp-foundry-subnum nil
)
594 (aset xlfd xlfd-regexp-family-subnum nil
)
595 (aset xlfd xlfd-regexp-registry-subnum
"fontset")
597 (setq fontset-name
(downcase fontset-name
))
600 (aref resolved-xlfd xlfd-regexp-registry-subnum
)
601 (aref resolved-xlfd xlfd-regexp-encoding-subnum
)
602 (aref resolved-xlfd xlfd-regexp-pixelsize-subnum
))))
603 (aset xlfd xlfd-regexp-encoding-subnum fontset-name
)
604 (setq fontset
(x-compose-font-name xlfd
))
605 (or (query-fontset fontset
)
606 (create-fontset-from-fontset-spec (concat fontset
", ascii:" font
)))))
609 ;; Create standard fontset from 16 dots fonts which are the most widely
610 ;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
611 ;; specified here because FAMILY of those fonts are not "fixed" in
613 (defvar standard-fontset-spec
614 (purecopy "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard,
615 chinese-gb2312:-*-medium-r-normal-*-16-*-gb2312*-*,
616 korean-ksc5601:-*-medium-r-normal-*-16-*-ksc5601*-*,
617 chinese-cns11643-1:-*-medium-r-normal-*-16-*-cns11643*-1,
618 chinese-cns11643-2:-*-medium-r-normal-*-16-*-cns11643*-2,
619 chinese-cns11643-3:-*-medium-r-normal-*-16-*-cns11643*-3,
620 chinese-cns11643-4:-*-medium-r-normal-*-16-*-cns11643*-4,
621 chinese-cns11643-5:-*-medium-r-normal-*-16-*-cns11643*-5,
622 chinese-cns11643-6:-*-medium-r-normal-*-16-*-cns11643*-6,
623 chinese-cns11643-7:-*-medium-r-normal-*-16-*-cns11643*-7")
624 "String of fontset spec of the standard fontset.
625 You have the biggest chance to display international characters
626 with correct glyphs by using the standard fontset.
627 See the documentation of `create-fontset-from-fontset-spec' for the format.")
629 ;; Create fontsets from X resources of the name `fontset-N (class
630 ;; Fontset-N)' where N is integer 0, 1, ...
631 ;; The values of the resources the string of the same format as
632 ;; `standard-fontset-spec'.
634 (defun create-fontset-from-x-resource ()
637 (while (setq fontset-spec
(x-get-resource (format "fontset-%d" idx
)
638 (format "Fontset-%d" idx
)))
639 (create-fontset-from-fontset-spec fontset-spec t
'noerror
)
640 (setq idx
(1+ idx
)))))
645 ;;; arch-tag: bb53e629-0234-403c-950e-551e61554849
646 ;;; fontset.el ends here