Some fixes to follow coding conventions.
[bpt/emacs.git] / lisp / international / fontset.el
CommitLineData
60370d40 1;;; fontset.el --- commands for handling fontset
4ed46869 2
fa526c4a
RS
3;; Copyright (C) 1995, 1997 Electrotechnical Laboratory, JAPAN.
4;; Licensed to the Free Software Foundation.
4ed46869
KH
5
6;; Keywords: mule, multilingual, fontset
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
369314dc
KH
21;; along with GNU Emacs; see the file COPYING. If not, write to the
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
4ed46869 24
60370d40
PJ
25;;; Commentary:
26
4ed46869
KH
27;;; Code:
28
2ad00186
KH
29;; Set standard fontname specification of characters in the default
30;; fontset to find an appropriate font for each charset. This is used
31;; to generate a font name for a fontset if the fontset doesn't
32;; specify a font name for a specific character. The specification
33;; has the form (FAMILY . REGISTRY). FAMILY may be nil, in which
34;; case, the family name of default face is used. If REGISTRY
35;; contains a character `-', the string before that is embedded in
36;; `CHARSET_REGISTRY' field, and the string after that is embedded in
37;; `CHARSET_ENCODING' field. If it does not contain `-', the whole
38;; string is embedded in `CHARSET_REGISTRY' field, and a wild card
39;; character `*' is embedded in `CHARSET_ENCODING' field. The
40;; REGISTRY for ASCII characters are predefined as "ISO8859-1".
41
42(let ((l `((latin-iso8859-1 . (nil . "ISO8859-1"))
43 (latin-iso8859-2 . (nil . "ISO8859-2"))
44 (latin-iso8859-3 . (nil . "ISO8859-3"))
45 (latin-iso8859-4 . (nil . "ISO8859-4"))
46 (thai-tis620 . ("*" . "TIS620"))
47 (greek-iso8859-7 . ("*" . "ISO8859-7"))
48 (arabic-iso8859-6 . ("*" . "ISO8859-6"))
49 (hebrew-iso8859-8 . ("*" . "ISO8859-8"))
50 (katakana-jisx0201 . ("*" . "JISX0201"))
51 (latin-jisx0201 . (nil . "JISX0201"))
52 (cyrillic-iso8859-5 . ("*" . "ISO8859-5"))
53 (latin-iso8859-9 . (nil . "ISO8859-9"))
54 (japanese-jisx0208-1978 . ("*" . "JISX0208.1978"))
9fff53a3
KH
55 (chinese-gb2312 . ("*" . "GB2312.1980"))
56 (japanese-jisx0208 . ("*" . "JISX0208.1990"))
57 (korean-ksc5601 . ("*" . "KSC5601.1989"))
2ad00186
KH
58 (japanese-jisx0212 . ("*" . "JISX0212"))
59 (chinese-cns11643-1 . ("*" . "CNS11643.1992-1"))
60 (chinese-cns11643-2 . ("*" . "CNS11643.1992-2"))
61 (chinese-cns11643-3 . ("*" . "CNS11643.1992-3"))
62 (chinese-cns11643-4 . ("*" . "CNS11643.1992-4"))
63 (chinese-cns11643-5 . ("*" . "CNS11643.1992-5"))
64 (chinese-cns11643-6 . ("*" . "CNS11643.1992-6"))
65 (chinese-cns11643-7 . ("*" . "CNS11643.1992-7"))
66 (chinese-big5-1 . ("*" . "Big5"))
67 (chinese-big5-2 . ("*" . "Big5"))
68 (chinese-sisheng . (nil . "sisheng_cwnn"))
69 (vietnamese-viscii-lower . (nil . "VISCII1.1"))
70 (vietnamese-viscii-upper . (nil . "VISCII1.1"))
71 (arabic-digit . ("*" . "MuleArabic-0"))
72 (arabic-1-column . ("*" . "MuleArabic-1"))
73 (arabic-2-column . ("*" . "MuleArabic-2"))
74 (ipa . (nil . "MuleIPA"))
75 (ethiopic . ("*" . "Ethiopic-Unicode"))
76 (ascii-right-to-left . (nil . "ISO8859-1"))
77 (indian-is13194 . ("*" . "IS13194-Devanagari"))
78 (indian-2-column . ("*" . "MuleIndian-2"))
79 (indian-1-column . ("*" . "MuleIndian-1"))
80 (lao . ("*" . "MuleLao-1"))
12385722 81 (tibetan . ("proportional" . "MuleTibetan-2"))
2ad00186
KH
82 (tibetan-1-column . ("*" . "MuleTibetan-1"))
83 (latin-iso8859-14 . (nil . "ISO8859-14"))
84 (latin-iso8859-15 . (nil . "ISO8859-15"))
85 (mule-unicode-0100-24ff . (nil . "ISO10646-1"))
adbff2a7
KH
86 (mule-unicode-2500-33ff . (nil . "ISO10646-1"))
87 (mule-unicode-e000-ffff . (nil . "ISO10646-1"))
dd7e81b4
KH
88 (japanese-jisx0213-1 . ("*" . "JISX0213.2000-1"))
89 (japanese-jisx0213-2 . ("*" . "JISX0213.2000-2"))
6eca8d93 90 ))
2ad00186 91 charset font-spec arg)
4ed46869 92 (while l
2ad00186 93 (setq charset (car (car l)) font-spec (cdr (car l)) l (cdr l))
6eca8d93
KH
94 (if (symbolp charset)
95 (setq arg (make-char charset))
96 (setq arg charset))
2ad00186 97 (set-fontset-font "fontset-default" arg font-spec)))
4ed46869
KH
98
99;; Set arguments in `font-encoding-alist' (which see).
100(defun set-font-encoding (pattern charset encoding)
101 (let ((slot (assoc pattern font-encoding-alist)))
102 (if slot
103 (let ((place (assq charset (cdr slot))))
104 (if place
105 (setcdr place encoding)
106 (setcdr slot (cons (cons charset encoding) (cdr slot)))))
107 (setq font-encoding-alist
108 (cons (list pattern (cons charset encoding)) font-encoding-alist)))
109 ))
110
111(set-font-encoding "ISO8859-1" 'ascii 0)
112(set-font-encoding "JISX0201" 'latin-jisx0201 0)
113
adbff2a7 114(define-ccl-program ccl-encode-unicode-font
12385722 115 `(0
adbff2a7
KH
116 (if (r0 == ,(charset-id 'ascii))
117 ((r2 = r1)
118 (r1 = 0))
119 (if (r0 == ,(charset-id 'latin-iso8859-1))
120 ((r2 = (r1 + 128))
121 (r1 = 0))
122 (if (r0 == ,(charset-id 'mule-unicode-0100-24ff))
123 ((r1 *= 96)
124 (r1 += r2)
125 (r1 += ,(- #x100 (* 32 96) 32))
126 (r1 >8= 0)
127 (r2 = r7))
128 (if (r0 == ,(charset-id 'mule-unicode-2500-33ff))
129 ((r1 *= 96)
130 (r1 += r2)
131 (r1 += ,(- #x2500 (* 32 96) 32))
132 (r1 >8= 0)
133 (r2 = r7))
134 (if (r0 == ,(charset-id 'mule-unicode-e000-ffff))
135 ((r1 *= 96)
136 (r1 += r2)
137 (r1 += ,(- #xe000 (* 32 96) 32))
138 (r1 >8= 0)
139 (r2 = r7)))))))))
12385722
KH
140
141(setq font-ccl-encoder-alist
adbff2a7 142 (cons '("ISO10646-1" . ccl-encode-unicode-font)
12385722
KH
143 font-ccl-encoder-alist))
144
4ed46869
KH
145;; Setting for suppressing XLoadQueryFont on big fonts.
146(setq x-pixel-size-width-font-regexp
147 "gb2312\\|jisx0208\\|ksc5601\\|cns11643\\|big5")
148
6eca8d93 149;; These fonts require vertical centering.
0c4f97d0 150(setq vertical-centering-font-regexp
6eca8d93 151 "gb2312\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5")
0c4f97d0 152
6fb8f8bd
KH
153(defvar x-font-name-charset-alist
154 '(("iso8859-1" ascii latin-iso8859-1)
155 ("iso8859-2" ascii latin-iso8859-2)
156 ("iso8859-3" ascii latin-iso8859-3)
157 ("iso8859-4" ascii latin-iso8859-4)
158 ("iso8859-5" ascii cyrillic-iso8859-5)
159 ("iso8859-6" ascii arabic-iso8859-6)
160 ("iso8859-7" ascii greek-iso8859-7)
161 ("iso8859-8" ascii hebrew-iso8859-8)
7a860cf2
DL
162 ("iso8859-14" ascii latin-iso8859-14)
163 ("iso8859-15" ascii latin-iso8859-15)
6fb8f8bd
KH
164 ("tis620" ascii thai-tis620)
165 ("koi8" ascii cyrillic-iso8859-5)
166 ("viscii" ascii vietnamese-viscii-upper vietnamese-viscii-lower)
167 ("vscii" ascii vietnamese-viscii-upper vietnamese-viscii-lower)
12385722 168 ("mulelao-1" ascii lao)
adbff2a7
KH
169 ("iso10646-1" ascii latin-iso8859-1 mule-unicode-0100-24ff
170 mule-unicode-2500-33ff mule-unicode-e000-ffff))
6fb8f8bd
KH
171 "Alist of font names vs list of charsets the font can display.
172
173When a font name which matches some element of this alist is given as
174`-fn' command line argument or is specified by X resource, a fontset
175which uses the specified font for the corresponding charsets are
176created and used for the initial frame.")
177
4ed46869
KH
178;;; XLFD (X Logical Font Description) format handler.
179
180;; Define XLFD's field index numbers. ; field name
181(defconst xlfd-regexp-foundry-subnum 0) ; FOUNDRY
182(defconst xlfd-regexp-family-subnum 1) ; FAMILY_NAME
183(defconst xlfd-regexp-weight-subnum 2) ; WEIGHT_NAME
184(defconst xlfd-regexp-slant-subnum 3) ; SLANT
185(defconst xlfd-regexp-swidth-subnum 4) ; SETWIDTH_NAME
186(defconst xlfd-regexp-adstyle-subnum 5) ; ADD_STYLE_NAME
187(defconst xlfd-regexp-pixelsize-subnum 6) ; PIXEL_SIZE
188(defconst xlfd-regexp-pointsize-subnum 7) ; POINT_SIZE
189(defconst xlfd-regexp-resx-subnum 8) ; RESOLUTION_X
190(defconst xlfd-regexp-resy-subnum 9) ; RESOLUTION_Y
191(defconst xlfd-regexp-spacing-subnum 10) ; SPACING
192(defconst xlfd-regexp-avgwidth-subnum 11) ; AVERAGE_WIDTH
193(defconst xlfd-regexp-registry-subnum 12) ; CHARSET_REGISTRY
194(defconst xlfd-regexp-encoding-subnum 13) ; CHARSET_ENCODING
195
196;; Regular expression matching against a fontname which conforms to
197;; XLFD (X Logical Font Description). All fields in XLFD should be
198;; not be omitted (but can be a wild card) to be matched.
199(defconst xlfd-tight-regexp
200 "^\
201-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
202-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)\
203-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)-\\([^-]*\\)$")
204
205;; List of field numbers of XLFD whose values are numeric.
206(defconst xlfd-regexp-numeric-subnums
207 (list xlfd-regexp-pixelsize-subnum ;6
208 xlfd-regexp-pointsize-subnum ;7
209 xlfd-regexp-resx-subnum ;8
210 xlfd-regexp-resy-subnum ;9
211 xlfd-regexp-avgwidth-subnum ;11
212 ))
213
214(defun x-decompose-font-name (pattern)
215 "Decompose PATTERN into XLFD's fields and return vector of the fields.
216The length of the vector is 14.
217
218If PATTERN doesn't conform to XLFD, try to get a full XLFD name from
219X server and use the information of the full name to decompose
220PATTERN. If no full XLFD name is gotten, return nil."
221 (let (xlfd-fields fontname)
222 (if (string-match xlfd-tight-regexp pattern)
223 (let ((i 0))
224 (setq xlfd-fields (make-vector 14 nil))
225 (while (< i 14)
226 (aset xlfd-fields i (match-string (1+ i) pattern))
227 (setq i (1+ i)))
228 xlfd-fields)
229 (setq fontname (condition-case nil
230 (x-resolve-font-name pattern)
231 (error)))
232 (if (and fontname
233 (string-match xlfd-tight-regexp fontname))
190ce634 234 ;; We get a full XLFD name.
4ed46869
KH
235 (let ((len (length pattern))
236 (i 0)
237 l)
190ce634
KH
238 ;; Setup xlfd-fields by the full XLFD name. Each element
239 ;; should be a cons of matched index and matched string.
4ed46869
KH
240 (setq xlfd-fields (make-vector 14 nil))
241 (while (< i 14)
242 (aset xlfd-fields i
243 (cons (match-beginning (1+ i))
244 (match-string (1+ i) fontname)))
245 (setq i (1+ i)))
190ce634
KH
246
247 ;; Replace wild cards in PATTERN by regexp codes.
4ed46869
KH
248 (setq i 0)
249 (while (< i len)
250 (let ((ch (aref pattern i)))
251 (if (= ch ??)
252 (setq pattern (concat (substring pattern 0 i)
253 "\\(.\\)"
254 (substring pattern (1+ i)))
255 len (+ len 4)
256 i (+ i 4))
257 (if (= ch ?*)
258 (setq pattern (concat (substring pattern 0 i)
259 "\\(.*\\)"
260 (substring pattern (1+ i)))
261 len (+ len 5)
262 i (+ i 5))
263 (setq i (1+ i))))))
190ce634
KH
264
265 ;; Set each element of xlfd-fields to proper strings.
266 (if (string-match pattern fontname)
267 ;; The regular expression PATTERN matchs the full XLFD
268 ;; name. Set elements that correspond to a wild card
269 ;; in PATTERN to "*", set the other elements to the
270 ;; exact strings in PATTERN.
271 (let ((l (cdr (cdr (match-data)))))
272 (setq i 0)
273 (while (< i 14)
274 (if (or (null l) (< (car (aref xlfd-fields i)) (car l)))
275 (progn
276 (aset xlfd-fields i (cdr (aref xlfd-fields i)))
277 (setq i (1+ i)))
278 (if (< (car (aref xlfd-fields i)) (car (cdr l)))
279 (progn
280 (aset xlfd-fields i "*")
281 (setq i (1+ i)))
282 (setq l (cdr (cdr l)))))))
283 ;; Set each element of xlfd-fields to the exact string
284 ;; in the corresonding fields in full XLFD name.
285 (setq i 0)
286 (while (< i 14)
287 (aset xlfd-fields i (cdr (aref xlfd-fields i)))
288 (setq i (1+ i))))
4ed46869
KH
289 xlfd-fields)))))
290
441038a6
KH
291;; Replace consecutive wild-cards (`*') in NAME to one.
292;; Ex. (x-reduce-font-name "-*-*-*-iso8859-1") => "-*-iso8859-1"
293(defsubst x-reduce-font-name (name)
294 (while (string-match "-\\*-\\(\\*-\\)+" name)
295 (setq name (replace-match "-*-" t t name)))
296 name)
297
bb98ead9 298(defun x-compose-font-name (fields &optional reduce)
4ed46869 299 "Compose X's fontname from FIELDS.
bb98ead9 300FIELDS is a vector of XLFD fields, the length 14.
441038a6 301If a field is nil, wild-card letter `*' is embedded.
6eca8d93
KH
302Optional argument REDUCE is always ignored. It exists just for
303backward compatibility."
304 (concat "-" (mapconcat (lambda (x) (or x "*")) fields "-")))
bcb68cff 305
4ed46869 306(defun x-complement-fontset-spec (xlfd-fields fontlist)
6eca8d93 307 "Complement FONTLIST for charsets based on XLFD-FIELDS and return it.
4ed46869 308XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
6fb8f8bd 309FONTLIST is an alist of charsets vs the corresponding font names.
4ed46869 310
6eca8d93
KH
311The fonts are complemented as below.
312
313If FONTLIST doesn't specify a font for ASCII charset, generate a font
314name for the charset from XLFD-FIELDS, and add that information to
315FONTLIST.
316
317If a font specifid for ASCII supports the other charsets (see the
318variable `x-font-name-charset-alist'), add that information to FONTLIST."
f6cab6c8 319 (let* ((slot (assq 'ascii fontlist))
6bf84cde
KH
320 (ascii-font (cdr slot))
321 ascii-font-spec)
f6cab6c8
KH
322 (if ascii-font
323 (setcdr slot (setq ascii-font (x-resolve-font-name ascii-font)))
324 ;; If font for ASCII is not specified, add it.
2ad00186
KH
325 (aset xlfd-fields xlfd-regexp-registry-subnum "iso8859")
326 (aset xlfd-fields xlfd-regexp-encoding-subnum "1")
f6cab6c8 327 (setq ascii-font (x-resolve-font-name (x-compose-font-name xlfd-fields)))
2ad00186 328 (setq fontlist (cons (cons 'ascii ascii-font) fontlist)))
6eca8d93
KH
329
330 ;; If the font for ASCII also supports the other charsets, and
331 ;; they are not specified in FONTLIST, add them.
6bf84cde
KH
332 (setq xlfd-fields (x-decompose-font-name ascii-font))
333 (if (not xlfd-fields)
334 (setq ascii-font-spec ascii-font)
335 (setq ascii-font-spec
336 (cons (format "%s-%s"
337 (aref xlfd-fields xlfd-regexp-foundry-subnum)
338 (aref xlfd-fields xlfd-regexp-family-subnum))
339 (format "%s-%s"
340 (aref xlfd-fields xlfd-regexp-registry-subnum)
341 (aref xlfd-fields xlfd-regexp-encoding-subnum)))))
6eca8d93
KH
342 (let ((tail x-font-name-charset-alist)
343 elt)
344 (while tail
345 (setq elt (car tail) tail (cdr tail))
346 (if (string-match (car elt) ascii-font)
347 (let ((charsets (cdr elt))
348 charset)
349 (while charsets
350 (setq charset (car charsets) charsets (cdr charsets))
351 (or (assq charset fontlist)
352 (setq fontlist
6bf84cde 353 (cons (cons charset ascii-font-spec) fontlist))))))))
6eca8d93
KH
354
355 fontlist))
4ed46869 356
35d4066a
KH
357(defun fontset-name-p (fontset)
358 "Return non-nil if FONTSET is valid as fontset name.
359A valid fontset name should conform to XLFD (X Logical Font Description)
360with \"fontset\" in `<CHARSET_REGISTRY> field."
361 (and (string-match xlfd-tight-regexp fontset)
362 (string= (match-string (1+ xlfd-regexp-registry-subnum) fontset)
363 "fontset")))
364
4ed46869
KH
365;; Return a list to be appended to `x-fixed-font-alist' when
366;; `mouse-set-font' is called.
367(defun generate-fontset-menu ()
6eca8d93 368 (let ((fontsets (fontset-list))
4ed46869
KH
369 fontset-name
370 l)
371 (while fontsets
6eca8d93 372 (setq fontset-name (car fontsets) fontsets (cdr fontsets))
494ec9bc 373 (setq l (cons (list (fontset-plain-name fontset-name) fontset-name) l)))
80ae5f3a
KH
374 (cons "Fontset"
375 (sort l (function (lambda (x y) (string< (car x) (car y))))))))
4ed46869
KH
376
377(defun fontset-plain-name (fontset)
378 "Return a plain and descriptive name of FONTSET."
494ec9bc
KH
379 (if (not (setq fontset (query-fontset fontset)))
380 (error "Invalid fontset: %s" fontset))
4ed46869
KH
381 (let ((xlfd-fields (x-decompose-font-name fontset)))
382 (if xlfd-fields
383 (let ((weight (aref xlfd-fields xlfd-regexp-weight-subnum))
384 (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
385 (swidth (aref xlfd-fields xlfd-regexp-swidth-subnum))
386 (size (aref xlfd-fields xlfd-regexp-pixelsize-subnum))
494ec9bc
KH
387 (charset (aref xlfd-fields xlfd-regexp-registry-subnum))
388 (nickname (aref xlfd-fields xlfd-regexp-encoding-subnum))
4ed46869 389 name)
494ec9bc 390 (if (not (string= "fontset" charset))
4ed46869 391 fontset
494ec9bc
KH
392 (if (> (string-to-int size) 0)
393 (setq name (format "%s: %s-dot" nickname size))
394 (setq name nickname))
395 (cond ((string-match "^medium$" weight)
396 (setq name (concat name " " "medium")))
397 ((string-match "^bold$\\|^demibold$" weight)
398 (setq name (concat name " " weight))))
399 (cond ((string-match "^i$" slant)
400 (setq name (concat name " " "italic")))
401 ((string-match "^o$" slant)
402 (setq name (concat name " " "slant")))
403 ((string-match "^ri$" slant)
404 (setq name (concat name " " "reverse italic")))
405 ((string-match "^ro$" slant)
406 (setq name (concat name " " "reverse slant"))))
4ed46869
KH
407 name))
408 fontset)))
409
ca1a6e9d 410;;;###autoload
6fb8f8bd 411(defun create-fontset-from-fontset-spec (fontset-spec
bb98ead9 412 &optional style-variant noerror)
4ed46869
KH
413 "Create a fontset from fontset specification string FONTSET-SPEC.
414FONTSET-SPEC is a string of the format:
415 FONTSET-NAME,CHARSET-NAME0:FONT-NAME0,CHARSET-NAME1:FONT-NAME1, ...
494ec9bc 416Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
bb98ead9 417
6eca8d93
KH
418Optional 2nd argument is ignored. It exists just for backward
419compatibility.
bb98ead9 420
883e21bd 421If this function attempts to create already existing fontset, error is
1f50fef9
KH
422signaled unless the optional 3rd argument NOERROR is non-nil.
423
424It returns a name of the created fontset."
494ec9bc
KH
425 (if (not (string-match "^[^,]+" fontset-spec))
426 (error "Invalid fontset spec: %s" fontset-spec))
6eca8d93 427 (setq fontset-spec (downcase fontset-spec))
494ec9bc
KH
428 (let ((idx (match-end 0))
429 (name (match-string 0 fontset-spec))
6eca8d93 430 xlfd-fields charset fontlist ascii-font)
6fb8f8bd
KH
431 (if (query-fontset name)
432 (or noerror
86e411c9 433 (error "Fontset \"%s\" already exists" name))
6eca8d93
KH
434 (setq xlfd-fields (x-decompose-font-name name))
435 (or xlfd-fields
436 (error "Fontset \"%s\" not conforming to XLFD" name))
437
6fb8f8bd
KH
438 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
439 (while (string-match "[, \t\n]*\\([^:]+\\):\\([^,]+\\)" fontset-spec idx)
440 (setq idx (match-end 0))
441 (setq charset (intern (match-string 1 fontset-spec)))
442 (if (charsetp charset)
443 (setq fontlist (cons (cons charset (match-string 2 fontset-spec))
444 fontlist))))
f6cab6c8 445 (setq ascii-font (cdr (assq 'ascii fontlist)))
6eca8d93
KH
446
447 ;; Complement FONTLIST.
448 (setq fontlist (x-complement-fontset-spec xlfd-fields fontlist))
449
450 (new-fontset name fontlist)
451
452 ;; Define the short name alias.
453 (if (and (string-match "fontset-.*$" name)
454 (not (assoc name fontset-alias-alist)))
455 (let ((alias (match-string 0 name)))
456 (or (rassoc alias fontset-alias-alist)
457 (setq fontset-alias-alist
458 (cons (cons name alias) fontset-alias-alist)))))
459
460 ;; Define the ASCII font name alias.
f6cab6c8
KH
461 (or ascii-font
462 (setq ascii-font (cdr (assq 'ascii fontlist))))
6eca8d93
KH
463 (or (rassoc ascii-font fontset-alias-alist)
464 (setq fontset-alias-alist
465 (cons (cons name ascii-font)
466 fontset-alias-alist))))
6fb8f8bd 467
1f50fef9
KH
468 name))
469
470(defun create-fontset-from-ascii-font (font &optional resolved-font
471 fontset-name)
472 "Create a fontset from an ASCII font FONT.
473
474Optional 1st arg RESOLVED-FONT is a resolved name of FONT. If
475omitted, x-resolve-font-name is called to get the resolved name. At
56d25ff5 476this time, if FONT is not available, error is signaled.
1f50fef9
KH
477
478Optional 2nd arg FONTSET-NAME is a string to be used in
479`<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
480an appropriate name is generated automatically.
481
1f50fef9 482It returns a name of the created fontset."
6eca8d93
KH
483 (setq font (downcase font))
484 (if resolved-font
485 (setq resolved-font (downcase resolved-font))
486 (setq resolved-font (downcase (x-resolve-font-name font))))
487 (let ((xlfd (x-decompose-font-name font))
488 (resolved-xlfd (x-decompose-font-name resolved-font))
489 fontset fontset-spec)
1f50fef9
KH
490 (aset xlfd xlfd-regexp-foundry-subnum nil)
491 (aset xlfd xlfd-regexp-family-subnum nil)
492 (aset xlfd xlfd-regexp-registry-subnum "fontset")
6eca8d93
KH
493 (if fontset-name
494 (setq fontset-name (downcase fontset-name))
495 (setq fontset-name
496 (format "%s_%s_%s"
497 (aref resolved-xlfd xlfd-regexp-registry-subnum)
498 (aref resolved-xlfd xlfd-regexp-encoding-subnum)
499 (aref resolved-xlfd xlfd-regexp-pixelsize-subnum))))
1f50fef9 500 (aset xlfd xlfd-regexp-encoding-subnum fontset-name)
1f50fef9
KH
501 (setq fontset (x-compose-font-name xlfd))
502 (or (query-fontset fontset)
6eca8d93
KH
503 (create-fontset-from-fontset-spec (concat fontset ", ascii:" font)))))
504
4ed46869 505\f
acfb10b8 506;; Create standard fontset from 16 dots fonts which are the most widely
80d4ea92
KH
507;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
508;; specified here because FAMILY of those fonts are not "fixed" in
509;; many cases.
acfb10b8 510(defvar standard-fontset-spec
cdd675ad 511 (purecopy "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard,
4ed46869
KH
512 chinese-gb2312:-*-medium-r-normal-*-16-*-gb2312*-*,
513 korean-ksc5601:-*-medium-r-normal-*-16-*-ksc5601*-*,
514 chinese-cns11643-1:-*-medium-r-normal-*-16-*-cns11643*-1,
515 chinese-cns11643-2:-*-medium-r-normal-*-16-*-cns11643*-2,
516 chinese-cns11643-3:-*-medium-r-normal-*-16-*-cns11643*-3,
517 chinese-cns11643-4:-*-medium-r-normal-*-16-*-cns11643*-4,
518 chinese-cns11643-5:-*-medium-r-normal-*-16-*-cns11643*-5,
519 chinese-cns11643-6:-*-medium-r-normal-*-16-*-cns11643*-6,
cdd675ad 520 chinese-cns11643-7:-*-medium-r-normal-*-16-*-cns11643*-7")
acfb10b8
KH
521 "String of fontset spec of the standard fontset.
522You have the biggest chance to display international characters
523with correct glyphs by using the standard fontset.
4ed46869
KH
524See the documentation of `create-fontset-from-fontset-spec' for the format.")
525
526;; Create fontsets from X resources of the name `fontset-N (class
527;; Fontset-N)' where N is integer 0, 1, ...
528;; The values of the resources the string of the same format as
acfb10b8 529;; `standard-fontset-spec'.
4ed46869
KH
530
531(defun create-fontset-from-x-resource ()
532 (let ((idx 0)
533 fontset-spec)
cdd675ad
DL
534 (while (setq fontset-spec (x-get-resource (format "fontset-%d" idx)
535 (format "Fontset-%d" idx)))
a5695549 536 (create-fontset-from-fontset-spec fontset-spec t 'noerror)
4ed46869
KH
537 (setq idx (1+ idx)))))
538
4ed46869
KH
539;;
540(provide 'fontset)
541
542;;; fontset.el ends here