aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa2000-03-21 00:32:06 +0000
committerKenichi Handa2000-03-21 00:32:06 +0000
commit6eca8d93cf82bc7e22f4dd12ca4b891249aec2e3 (patch)
tree7b60ad4d0297623258fc17d32177ee28b96d312b
parentb32631c868235afa96bd3c25a7c3dfde75edbdf5 (diff)
downloademacs-6eca8d93cf82bc7e22f4dd12ca4b891249aec2e3.tar.gz
emacs-6eca8d93cf82bc7e22f4dd12ca4b891249aec2e3.zip
(x-charset-registries): Variable
removed, instead the corresponding data is stored in the default fontset. (register-alternate-fontnames): Function removed. (resolved-ascii-font): Variable removed. (x-compose-font-name): Ignore the second argument REDOCE. (x-complement-fontset-spec): Complement only an ASCII font and element for those charsets than can use that ASCII font. (generate-fontset-menu): Don't refer to global-fontset-alist, instead call fontset-list. (uninstantiated-fontset-alist): Variable removed. (x-style-funcs-alist): Likewise. (fontset-default-styles): Likewise. (x-modify-font-name): Function removed. (create-fontset-from-fontset-spec): Ignore the argument STYLE-VARIANT. (create-fontset-from-ascii-font): Docsting adjusted for the above change. (instantiate-fontset, resolve-fontset-name): Functions removed. (fontset-list): Now implemented by C code.
-rw-r--r--lisp/international/fontset.el528
1 files changed, 152 insertions, 376 deletions
diff --git a/lisp/international/fontset.el b/lisp/international/fontset.el
index ec9474a7179..4c436d6701c 100644
--- a/lisp/international/fontset.el
+++ b/lisp/international/fontset.el
@@ -24,68 +24,70 @@
24 24
25;;; Code: 25;;; Code:
26 26
27;; Set standard REGISTRY property of charset to find an appropriate 27;; Set standard REGISTRY of characters in the default fontset to find
28;; font for each charset. This is used to generate a font name in a 28;; an appropriate font for each charset. This is used to generate a
29;; fontset. If the value contains a character `-', the string before 29;; font name for a fontset if the fontset doesn't specify a font name
30;; that is embedded in `CHARSET_REGISTRY' field, and the string after 30;; for a specific character. If the value contains a character `-',
31;; that is embedded in `CHARSET_ENCODING' field. If the value does not 31;; the string before that is embedded in `CHARSET_REGISTRY' field, and
32;; contain `-', the whole string is embedded in `CHARSET_REGISTRY' 32;; the string after that is embedded in `CHARSET_ENCODING' field. If
33;; field, and a wild card character `*' is embedded in 33;; the value does not contain `-', the whole string is embedded in
34;; `CHARSET_ENCODING' field. 34;; `CHARSET_REGISTRY' field, and a wild card character `*' is embedded
35 35;; in `CHARSET_ENCODING' field.
36(defvar x-charset-registries 36;; The REGISTRY for ASCII characters are predefined as "ISO8859-1".
37 '((ascii . "ISO8859-1") 37
38 (latin-iso8859-1 . "ISO8859-1") 38(let ((l `((latin-iso8859-1 . "ISO8859-1")
39 (latin-iso8859-2 . "ISO8859-2") 39 (latin-iso8859-2 . "ISO8859-2")
40 (latin-iso8859-3 . "ISO8859-3") 40 (latin-iso8859-3 . "ISO8859-3")
41 (latin-iso8859-4 . "ISO8859-4") 41 (latin-iso8859-4 . "ISO8859-4")
42 (thai-tis620 . "TIS620") 42 (thai-tis620 . "TIS620")
43 (greek-iso8859-7 . "ISO8859-7") 43 (greek-iso8859-7 . "ISO8859-7")
44 (arabic-iso8859-6 . "ISO8859-6") 44 (arabic-iso8859-6 . "ISO8859-6")
45 (hebrew-iso8859-8 . "ISO8859-8") 45 (hebrew-iso8859-8 . "ISO8859-8")
46 (katakana-jisx0201 . "JISX0201") 46 (katakana-jisx0201 . "JISX0201")
47 (latin-jisx0201 . "JISX0201") 47 (latin-jisx0201 . "JISX0201")
48 (cyrillic-iso8859-5 . "ISO8859-5") 48 (cyrillic-iso8859-5 . "ISO8859-5")
49 (latin-iso8859-9 . "ISO8859-9") 49 (latin-iso8859-9 . "ISO8859-9")
50 (japanese-jisx0208-1978 . "JISX0208.1978") 50 (japanese-jisx0208-1978 . "JISX0208.1978")
51 (chinese-gb2312 . "GB2312") 51 (chinese-gb2312 . "GB2312")
52 (japanese-jisx0208 . "JISX0208.1983") 52 (japanese-jisx0208 . "JISX0208.1983")
53 (korean-ksc5601 . "KSC5601") 53 (korean-ksc5601 . "KSC5601")
54 (japanese-jisx0212 . "JISX0212") 54 (japanese-jisx0212 . "JISX0212")
55 (chinese-cns11643-1 . "CNS11643.1992-1") 55 (chinese-cns11643-1 . "CNS11643.1992-1")
56 (chinese-cns11643-2 . "CNS11643.1992-2") 56 (chinese-cns11643-2 . "CNS11643.1992-2")
57 (chinese-cns11643-3 . "CNS11643.1992-3") 57 (chinese-cns11643-3 . "CNS11643.1992-3")
58 (chinese-cns11643-4 . "CNS11643.1992-4") 58 (chinese-cns11643-4 . "CNS11643.1992-4")
59 (chinese-cns11643-5 . "CNS11643.1992-5") 59 (chinese-cns11643-5 . "CNS11643.1992-5")
60 (chinese-cns11643-6 . "CNS11643.1992-6") 60 (chinese-cns11643-6 . "CNS11643.1992-6")
61 (chinese-cns11643-7 . "CNS11643.1992-7") 61 (chinese-cns11643-7 . "CNS11643.1992-7")
62 (chinese-big5-1 . "Big5") 62 (chinese-big5-1 . "Big5")
63 (chinese-big5-2 . "Big5") 63 (chinese-big5-2 . "Big5")
64 (chinese-sisheng . "sisheng_cwnn") 64 (chinese-sisheng . "sisheng_cwnn")
65 (vietnamese-viscii-lower . "VISCII1.1") 65 (vietnamese-viscii-lower . "VISCII1.1")
66 (vietnamese-viscii-upper . "VISCII1.1") 66 (vietnamese-viscii-upper . "VISCII1.1")
67 (arabic-digit . "MuleArabic-0") 67 (arabic-digit . "MuleArabic-0")
68 (arabic-1-column . "MuleArabic-1") 68 (arabic-1-column . "MuleArabic-1")
69 (arabic-2-column . "MuleArabic-2") 69 (arabic-2-column . "MuleArabic-2")
70 (ipa . "MuleIPA") 70 (ipa . "MuleIPA")
71 (ethiopic . "Ethiopic-Unicode") 71 (ethiopic . "Ethiopic-Unicode")
72 (ascii-right-to-left . "ISO8859-1") 72 (ascii-right-to-left . "ISO8859-1")
73 (indian-is13194 . "IS13194-Devanagari") 73 (indian-is13194 . "IS13194-Devanagari")
74 (indian-2-column . "MuleIndian-2") 74 (indian-2-column . "MuleIndian-2")
75 (indian-1-column . "MuleIndian-1") 75 (indian-1-column . "MuleIndian-1")
76 (lao . "MuleLao-1") 76 (lao . "MuleLao-1")
77 (tibetan . "MuleTibetan-0") 77 (tibetan . "MuleTibetan-0")
78 (tibetan-1-column . "MuleTibetan-1") 78 (tibetan-1-column . "MuleTibetan-1")
79 (latin-iso8859-14 . "ISO8859-14") 79 (latin-iso8859-14 . "ISO8859-14")
80 (latin-iso8859-15 . "ISO8859-15") 80 (latin-iso8859-15 . "ISO8859-15")
81 )) 81 ))
82 82 charset registry arg)
83(let ((l x-charset-registries))
84 (while l 83 (while l
85 (condition-case nil 84 (setq charset (car (car l)) registry (cdr (car l)) l (cdr l))
86 (put-charset-property (car (car l)) 'x-charset-registry (cdr (car l))) 85 (or (string-match "-" registry)
87 (error nil)) 86 (setq registry (concat registry "*")))
88 (setq l (cdr l)))) 87 (if (symbolp charset)
88 (setq arg (make-char charset))
89 (setq arg charset))
90 (set-fontset-font t arg registry)))
89 91
90;; Set arguments in `font-encoding-alist' (which see). 92;; Set arguments in `font-encoding-alist' (which see).
91(defun set-font-encoding (pattern charset encoding) 93(defun set-font-encoding (pattern charset encoding)
@@ -106,9 +108,9 @@
106(setq x-pixel-size-width-font-regexp 108(setq x-pixel-size-width-font-regexp
107 "gb2312\\|jisx0208\\|ksc5601\\|cns11643\\|big5") 109 "gb2312\\|jisx0208\\|ksc5601\\|cns11643\\|big5")
108 110
109;; There fonts require vertical centering. 111;; These fonts require vertical centering.
110(setq vertical-centering-font-regexp 112(setq vertical-centering-font-regexp
111 "gb2312\\|jisx0208\\|ksc5601\\|cns11643\\|big5") 113 "gb2312\\|jisx0208\\|jisx0212\\|ksc5601\\|cns11643\\|big5")
112 114
113(defvar x-font-name-charset-alist 115(defvar x-font-name-charset-alist
114 '(("iso8859-1" ascii latin-iso8859-1) 116 '(("iso8859-1" ascii latin-iso8859-1)
@@ -257,121 +259,53 @@ PATTERN. If no full XLFD name is gotten, return nil."
257 "Compose X's fontname from FIELDS. 259 "Compose X's fontname from FIELDS.
258FIELDS is a vector of XLFD fields, the length 14. 260FIELDS is a vector of XLFD fields, the length 14.
259If a field is nil, wild-card letter `*' is embedded. 261If a field is nil, wild-card letter `*' is embedded.
260Optional argument REDUCE non-nil means consecutive wild-cards are 262Optional argument REDUCE is always ignored. It exists just for
261reduced to be one." 263backward compatibility."
262 (let ((name 264 (concat "-" (mapconcat (lambda (x) (or x "*")) fields "-")))
263 (concat "-" (mapconcat (lambda (x) (or x "*")) fields "-"))))
264 (if reduce
265 (x-reduce-font-name name)
266 name)))
267
268(defun register-alternate-fontnames (fontname)
269 "Register alternate fontnames for FONTNAME in `alternate-fontname-alist'.
270When Emacs fails to open FONTNAME, it tries to open an alternate font
271registered in the variable `alternate-fontname-alist' (which see).
272
273For FONTNAME, the following three alternate fontnames are registered:
274 fontname which ignores style specification of FONTNAME,
275 fontname which ignores size specification of FONTNAME,
276 fontname which ignores both style and size specification of FONTNAME.
277Emacs tries to open fonts in this order."
278 (unless (assoc fontname alternate-fontname-alist)
279 (let ((xlfd-fields (x-decompose-font-name fontname))
280 style-ignored size-ignored both-ignored)
281 (when xlfd-fields
282 (aset xlfd-fields xlfd-regexp-foundry-subnum nil)
283 (aset xlfd-fields xlfd-regexp-family-subnum nil)
284
285 (let ((temp (copy-sequence xlfd-fields)))
286 (aset temp xlfd-regexp-weight-subnum nil)
287 (aset temp xlfd-regexp-slant-subnum nil)
288 (aset temp xlfd-regexp-swidth-subnum nil)
289 (aset temp xlfd-regexp-adstyle-subnum nil)
290 (setq style-ignored (x-compose-font-name temp t)))
291
292 (aset xlfd-fields xlfd-regexp-pixelsize-subnum nil)
293 (aset xlfd-fields xlfd-regexp-pointsize-subnum nil)
294 (aset xlfd-fields xlfd-regexp-resx-subnum nil)
295 (aset xlfd-fields xlfd-regexp-resy-subnum nil)
296 (aset xlfd-fields xlfd-regexp-spacing-subnum nil)
297 (aset xlfd-fields xlfd-regexp-avgwidth-subnum nil)
298 (setq size-ignored (x-compose-font-name xlfd-fields t))
299
300 (aset xlfd-fields xlfd-regexp-weight-subnum nil)
301 (aset xlfd-fields xlfd-regexp-slant-subnum nil)
302 (aset xlfd-fields xlfd-regexp-swidth-subnum nil)
303 (aset xlfd-fields xlfd-regexp-adstyle-subnum nil)
304 (setq both-ignored (x-compose-font-name xlfd-fields t))
305
306 (setq alternate-fontname-alist
307 (cons (list fontname style-ignored size-ignored both-ignored)
308 alternate-fontname-alist))))))
309
310;; Just to avoid compiler waring. The gloval value is never used.
311(defvar resolved-ascii-font nil)
312 265
313(defun x-complement-fontset-spec (xlfd-fields fontlist) 266(defun x-complement-fontset-spec (xlfd-fields fontlist)
314 "Complement FONTLIST for all charsets based on XLFD-FIELDS and return it. 267 "Complement FONTLIST for charsets based on XLFD-FIELDS and return it.
315XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields. 268XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields.
316FONTLIST is an alist of charsets vs the corresponding font names. 269FONTLIST is an alist of charsets vs the corresponding font names.
317 270
318Font names for charsets not listed in FONTLIST are generated from 271The fonts are complemented as below.
319XLFD-FIELDS and a property of x-charset-registry of each charset 272
320automatically. 273If FONTLIST doesn't specify a font for ASCII charset, generate a font
321 274name for the charset from XLFD-FIELDS, and add that information to
322By side effect, this sets `resolved-ascii-font' to the resolved name 275FONTLIST.
323of ASCII font." 276
324 (let ((charsets charset-list) 277If a font specifid for ASCII supports the other charsets (see the
325 (xlfd-fields-non-ascii (copy-sequence xlfd-fields)) 278variable `x-font-name-charset-alist'), add that information to FONTLIST."
326 (new-fontlist nil)) 279 (let ((ascii-font (cdr (assq 'ascii fontlist))))
327 (aset xlfd-fields-non-ascii xlfd-regexp-foundry-subnum nil) 280
328 (aset xlfd-fields-non-ascii xlfd-regexp-family-subnum nil) 281 ;; If font for ASCII is not specified, add it.
329 (aset xlfd-fields-non-ascii xlfd-regexp-adstyle-subnum nil) 282 (unless ascii-font
330 (aset xlfd-fields-non-ascii xlfd-regexp-avgwidth-subnum nil) 283 (let ((registry (cdr (fontset-font t 0)))
331 (while charsets 284 (encoding nil))
332 (let ((charset (car charsets))) 285 (if (string-match "-" registry)
333 (unless (assq charset fontlist) 286 (setq encoding (substring registry (match-end 0))
334 (let ((registry (get-charset-property charset 'x-charset-registry)) 287 registry (substring registry 0 (match-beginning 0))))
335 registry-val encoding-val fontname) 288 (aset xlfd-fields xlfd-regexp-registry-subnum registry)
336 (if (string-match "-" registry) 289 (aset xlfd-fields xlfd-regexp-encoding-subnum encoding)
337 ;; REGISTRY contains `CHARSET_ENCODING' field. 290 (setq ascii-font (x-compose-font-name xlfd-fields))
338 (setq registry-val (substring registry 0 (match-beginning 0)) 291 (setq fontlist (cons (cons 'ascii ascii-font) fontlist))))
339 encoding-val (substring registry (match-end 0))) 292
340 (setq registry-val (concat registry "*") 293 ;; If the font for ASCII also supports the other charsets, and
341 encoding-val "*")) 294 ;; they are not specified in FONTLIST, add them.
342 (let ((xlfd (if (eq charset 'ascii) xlfd-fields 295 (let ((tail x-font-name-charset-alist)
343 xlfd-fields-non-ascii))) 296 elt)
344 (aset xlfd xlfd-regexp-registry-subnum registry-val) 297 (while tail
345 (aset xlfd xlfd-regexp-encoding-subnum encoding-val) 298 (setq elt (car tail) tail (cdr tail))
346 (setq fontname (downcase (x-compose-font-name xlfd)))) 299 (if (string-match (car elt) ascii-font)
347 (setq new-fontlist (cons (cons charset fontname) new-fontlist)) 300 (let ((charsets (cdr elt))
348 (register-alternate-fontnames fontname)))) 301 charset)
349 (setq charsets (cdr charsets))) 302 (while charsets
350 303 (setq charset (car charsets) charsets (cdr charsets))
351 ;; Be sure that ASCII font is available. 304 (or (assq charset fontlist)
352 (let ((slot (or (assq 'ascii fontlist) (assq 'ascii new-fontlist))) 305 (setq fontlist
353 ascii-font) 306 (cons (cons charset ascii-font) fontlist))))))))
354 (setq ascii-font (condition-case nil 307
355 (x-resolve-font-name (cdr slot)) 308 fontlist))
356 (error nil)))
357 (if ascii-font
358 (let ((l x-font-name-charset-alist))
359 ;; If the ASCII font can also be used for another
360 ;; charsets, use that font instead of what generated based
361 ;; on x-charset-registry in the previous code.
362 (while l
363 (if (string-match (car (car l)) ascii-font)
364 (let ((charsets (cdr (car l)))
365 slot2)
366 (while charsets
367 (if (and (not (eq (car charsets) 'ascii))
368 (setq slot2 (assq (car charsets) new-fontlist)))
369 (setcdr slot2 (cdr slot)))
370 (setq charsets (cdr charsets)))
371 (setq l nil))
372 (setq l (cdr l))))
373 (setq resolved-ascii-font ascii-font)
374 (append fontlist new-fontlist))))))
375 309
376(defun fontset-name-p (fontset) 310(defun fontset-name-p (fontset)
377 "Return non-nil if FONTSET is valid as fontset name. 311 "Return non-nil if FONTSET is valid as fontset name.
@@ -384,11 +318,11 @@ with \"fontset\" in `<CHARSET_REGISTRY> field."
384;; Return a list to be appended to `x-fixed-font-alist' when 318;; Return a list to be appended to `x-fixed-font-alist' when
385;; `mouse-set-font' is called. 319;; `mouse-set-font' is called.
386(defun generate-fontset-menu () 320(defun generate-fontset-menu ()
387 (let ((fontsets global-fontset-alist) 321 (let ((fontsets (fontset-list))
388 fontset-name 322 fontset-name
389 l) 323 l)
390 (while fontsets 324 (while fontsets
391 (setq fontset-name (car (car fontsets)) fontsets (cdr fontsets)) 325 (setq fontset-name (car fontsets) fontsets (cdr fontsets))
392 (setq l (cons (list (fontset-plain-name fontset-name) fontset-name) l))) 326 (setq l (cons (list (fontset-plain-name fontset-name) fontset-name) l)))
393 (cons "Fontset" 327 (cons "Fontset"
394 (sort l (function (lambda (x y) (string< (car x) (car y)))))))) 328 (sort l (function (lambda (x y) (string< (car x) (car y))))))))
@@ -426,53 +360,6 @@ with \"fontset\" in `<CHARSET_REGISTRY> field."
426 name)) 360 name))
427 fontset))) 361 fontset)))
428 362
429(defvar uninstantiated-fontset-alist nil
430 "Alist of fontset names vs. information for instantiating them.
431Each element has the form (FONTSET STYLE FONTLIST), where
432FONTSET is a name of fontset not yet instantiated.
433STYLE is a style of FONTSET, one of the followings:
434 bold, demobold, italic, oblique,
435 bold-italic, demibold-italic, bold-oblique, demibold-oblique.
436FONTLIST is an alist of charsets vs font names to be used in FONSET.")
437
438(defconst x-style-funcs-alist
439 `((bold . x-make-font-bold)
440 (demibold . x-make-font-demibold)
441 (italic . x-make-font-italic)
442 (oblique . x-make-font-oblique)
443 (bold-italic . x-make-font-bold-italic)
444 (demibold-italic
445 . ,(function (lambda (x)
446 (let ((y (x-make-font-demibold x)))
447 (and y (x-make-font-italic y))))))
448 (demibold-oblique
449 . ,(function (lambda (x)
450 (let ((y (x-make-font-demibold x)))
451 (and y (x-make-font-oblique y))))))
452 (bold-oblique
453 . ,(function (lambda (x)
454 (let ((y (x-make-font-bold x)))
455 (and y (x-make-font-oblique y)))))))
456 "Alist of font style vs function to generate a X font name of the style.
457The function is called with one argument, a font name.")
458
459(defcustom fontset-default-styles '(bold italic bold-italic)
460 "List of alternative styles to create for a fontset.
461Valid elements include `bold', `demibold'; `italic', `oblique';
462and combinations of one from each group,
463such as `bold-italic' and `demibold-oblique'."
464 :group 'faces
465 :type '(set (const bold) (const demibold) (const italic) (const oblique)
466 (const bold-italic) (const bold-oblique) (const demibold-italic)
467 (const demibold-oblique)))
468
469(defun x-modify-font-name (fontname style)
470 "Substitute style specification part of FONTNAME for STYLE.
471STYLE should be listed in the variable `x-style-funcs-alist'."
472 (let ((func (cdr (assq style x-style-funcs-alist))))
473 (if func
474 (funcall func fontname))))
475
476;;;###autoload 363;;;###autoload
477(defun create-fontset-from-fontset-spec (fontset-spec 364(defun create-fontset-from-fontset-spec (fontset-spec
478 &optional style-variant noerror) 365 &optional style-variant noerror)
@@ -481,12 +368,8 @@ FONTSET-SPEC is a string of the format:
481 FONTSET-NAME,CHARSET-NAME0:FONT-NAME0,CHARSET-NAME1:FONT-NAME1, ... 368 FONTSET-NAME,CHARSET-NAME0:FONT-NAME0,CHARSET-NAME1:FONT-NAME1, ...
482Any number of SPACE, TAB, and NEWLINE can be put before and after commas. 369Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
483 370
484Optional 2nd argument STYLE-VARIANT is a list of font styles 371Optional 2nd argument is ignored. It exists just for backward
485\(e.g. bold, italic) or the symbol t to specify all available styles. 372compatibility.
486If this argument is specified, fontsets which differs from
487FONTSET-NAME in styles are also created. An element of STYLE-VARIANT
488may be cons of style and a font name. In this case, the style variant
489fontset uses the font for ASCII character set.
490 373
491If this function attempts to create already existing fontset, error is 374If this function attempts to create already existing fontset, error is
492signaled unless the optional 3rd argument NOERROR is non-nil. 375signaled unless the optional 3rd argument NOERROR is non-nil.
@@ -494,12 +377,17 @@ signaled unless the optional 3rd argument NOERROR is non-nil.
494It returns a name of the created fontset." 377It returns a name of the created fontset."
495 (if (not (string-match "^[^,]+" fontset-spec)) 378 (if (not (string-match "^[^,]+" fontset-spec))
496 (error "Invalid fontset spec: %s" fontset-spec)) 379 (error "Invalid fontset spec: %s" fontset-spec))
380 (setq fontset-spec (downcase fontset-spec))
497 (let ((idx (match-end 0)) 381 (let ((idx (match-end 0))
498 (name (match-string 0 fontset-spec)) 382 (name (match-string 0 fontset-spec))
499 fontlist full-fontlist ascii-font resolved-ascii-font charset) 383 xlfd-fields charset fontlist ascii-font)
500 (if (query-fontset name) 384 (if (query-fontset name)
501 (or noerror 385 (or noerror
502 (error "Fontset \"%s\" already exists" name)) 386 (error "Fontset \"%s\" already exists" name))
387 (setq xlfd-fields (x-decompose-font-name name))
388 (or xlfd-fields
389 (error "Fontset \"%s\" not conforming to XLFD" name))
390
503 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC. 391 ;; At first, extract pairs of charset and fontname from FONTSET-SPEC.
504 (while (string-match "[, \t\n]*\\([^:]+\\):\\([^,]+\\)" fontset-spec idx) 392 (while (string-match "[, \t\n]*\\([^:]+\\):\\([^,]+\\)" fontset-spec idx)
505 (setq idx (match-end 0)) 393 (setq idx (match-end 0))
@@ -507,77 +395,27 @@ It returns a name of the created fontset."
507 (if (charsetp charset) 395 (if (charsetp charset)
508 (setq fontlist (cons (cons charset (match-string 2 fontset-spec)) 396 (setq fontlist (cons (cons charset (match-string 2 fontset-spec))
509 fontlist)))) 397 fontlist))))
510 ;; Remember the specified ASCII font name now because it will be 398
511 ;; replaced by resolved font name by x-complement-fontset-spec. 399 ;; Complement FONTLIST.
400 (setq fontlist (x-complement-fontset-spec xlfd-fields fontlist))
401
402 (new-fontset name fontlist)
403
404 ;; Define the short name alias.
405 (if (and (string-match "fontset-.*$" name)
406 (not (assoc name fontset-alias-alist)))
407 (let ((alias (match-string 0 name)))
408 (or (rassoc alias fontset-alias-alist)
409 (setq fontset-alias-alist
410 (cons (cons name alias) fontset-alias-alist)))))
411
412 ;; Define the ASCII font name alias.
512 (setq ascii-font (cdr (assq 'ascii fontlist))) 413 (setq ascii-font (cdr (assq 'ascii fontlist)))
414 (or (rassoc ascii-font fontset-alias-alist)
415 (setq fontset-alias-alist
416 (cons (cons name ascii-font)
417 fontset-alias-alist))))
513 418
514 ;; If NAME conforms to XLFD, complement FONTLIST for charsets
515 ;; which are not specified in FONTSET-SPEC.
516 (let ((fields (x-decompose-font-name name)))
517 (if fields
518 (setq full-fontlist (x-complement-fontset-spec fields fontlist))))
519
520 (when full-fontlist
521 ;; Create the fontset.
522 (new-fontset name full-fontlist)
523
524 ;; Define aliases: short name (if appropriate) and ASCII font name.
525 (if (and (string-match "fontset-.*$" name)
526 (not (assoc name fontset-alias-alist)))
527 (let ((alias (match-string 0 name)))
528 (or (rassoc alias fontset-alias-alist)
529 (setq fontset-alias-alist
530 (cons (cons name alias) fontset-alias-alist)))))
531 (or (rassoc resolved-ascii-font fontset-alias-alist)
532 (setq fontset-alias-alist
533 (cons (cons name resolved-ascii-font)
534 fontset-alias-alist)))
535 (or (equal ascii-font resolved-ascii-font)
536 (rassoc ascii-font fontset-alias-alist)
537 (setq fontset-alias-alist
538 (cons (cons name ascii-font)
539 fontset-alias-alist)))
540
541 ;; At last, handle style variants.
542 (if (eq style-variant t)
543 (setq style-variant fontset-default-styles))
544
545 (if style-variant
546 ;; Generate fontset names of style variants and set them
547 ;; in uninstantiated-fontset-alist.
548 (let* (nonascii-fontlist
549 new-name new-ascii-font style font)
550 (if ascii-font
551 (setq nonascii-fontlist (delete (cons 'ascii ascii-font)
552 (copy-sequence fontlist)))
553 (setq ascii-font (cdr (assq 'ascii full-fontlist))
554 nonascii-fontlist fontlist))
555 (while style-variant
556 (setq style (car style-variant))
557 (if (symbolp style)
558 (setq font nil)
559 (setq font (cdr style)
560 style (car style)))
561 (setq new-name (x-modify-font-name name style))
562 (when new-name
563 ;; Modify ASCII font name for the style...
564 (setq new-ascii-font
565 (or font
566 (x-modify-font-name resolved-ascii-font style)))
567 ;; but leave fonts for the other charsets unmodified
568 ;; for the moment. They are modified for the style
569 ;; in instantiate-fontset.
570 (setq uninstantiated-fontset-alist
571 (cons (list new-name
572 style
573 (cons (cons 'ascii new-ascii-font)
574 nonascii-fontlist))
575 uninstantiated-fontset-alist))
576 (or (rassoc new-ascii-font fontset-alias-alist)
577 (setq fontset-alias-alist
578 (cons (cons new-name new-ascii-font)
579 fontset-alias-alist))))
580 (setq style-variant (cdr style-variant)))))))
581 name)) 419 name))
582 420
583(defun create-fontset-from-ascii-font (font &optional resolved-font 421(defun create-fontset-from-ascii-font (font &optional resolved-font
@@ -592,87 +430,29 @@ Optional 2nd arg FONTSET-NAME is a string to be used in
592`<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted, 430`<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
593an appropriate name is generated automatically. 431an appropriate name is generated automatically.
594 432
595Style variants of the fontset is created too. Font names in the
596variants are generated automatically from FONT unless X resources
597XXX.attributeFont explicitly specify them.
598
599It returns a name of the created fontset." 433It returns a name of the created fontset."
600 (or resolved-font 434 (setq font (downcase font))
601 (setq resolved-font (x-resolve-font-name font))) 435 (if resolved-font
602 (let* ((faces (copy-sequence fontset-default-styles)) 436 (setq resolved-font (downcase resolved-font))
603 (styles faces) 437 (setq resolved-font (downcase (x-resolve-font-name font))))
604 (xlfd (x-decompose-font-name font)) 438 (let ((xlfd (x-decompose-font-name font))
605 (resolved-xlfd (x-decompose-font-name resolved-font)) 439 (resolved-xlfd (x-decompose-font-name resolved-font))
606 face face-font fontset fontset-spec) 440 fontset fontset-spec)
607 (while faces
608 (setq face (car faces))
609 (setq face-font (x-get-resource (concat (symbol-name face)
610 ".attributeFont")
611 "Face.AttributeFont"))
612 (if face-font
613 (setcar faces (cons face face-font)))
614 (setq faces (cdr faces)))
615 (aset xlfd xlfd-regexp-foundry-subnum nil) 441 (aset xlfd xlfd-regexp-foundry-subnum nil)
616 (aset xlfd xlfd-regexp-family-subnum nil) 442 (aset xlfd xlfd-regexp-family-subnum nil)
617 (aset xlfd xlfd-regexp-registry-subnum "fontset") 443 (aset xlfd xlfd-regexp-registry-subnum "fontset")
618 (or fontset-name 444 (if fontset-name
619 (setq fontset-name 445 (setq fontset-name (downcase fontset-name))
620 (format "%s_%s_%s" 446 (setq fontset-name
621 (aref resolved-xlfd xlfd-regexp-registry-subnum) 447 (format "%s_%s_%s"
622 (aref resolved-xlfd xlfd-regexp-encoding-subnum) 448 (aref resolved-xlfd xlfd-regexp-registry-subnum)
623 (aref resolved-xlfd xlfd-regexp-pixelsize-subnum)))) 449 (aref resolved-xlfd xlfd-regexp-encoding-subnum)
450 (aref resolved-xlfd xlfd-regexp-pixelsize-subnum))))
624 (aset xlfd xlfd-regexp-encoding-subnum fontset-name) 451 (aset xlfd xlfd-regexp-encoding-subnum fontset-name)
625 ;; The fontset name should have concrete values in weight and
626 ;; slant field.
627 (let ((weight (aref xlfd xlfd-regexp-weight-subnum))
628 (slant (aref xlfd xlfd-regexp-slant-subnum)))
629 (if (or (not weight) (string-match "[*?]*" weight))
630 (aset xlfd xlfd-regexp-weight-subnum
631 (aref resolved-xlfd xlfd-regexp-weight-subnum)))
632 (if (or (not slant) (string-match "[*?]*" slant))
633 (aset xlfd xlfd-regexp-slant-subnum
634 (aref resolved-xlfd xlfd-regexp-slant-subnum))))
635 (setq fontset (x-compose-font-name xlfd)) 452 (setq fontset (x-compose-font-name xlfd))
636 (or (query-fontset fontset) 453 (or (query-fontset fontset)
637 (create-fontset-from-fontset-spec (concat fontset ", ascii:" font) 454 (create-fontset-from-fontset-spec (concat fontset ", ascii:" font)))))
638 styles)))) 455
639
640(defun instantiate-fontset (fontset)
641 "Make FONTSET be ready to use.
642FONTSET should be in the variable `uninstantiated-fontset-alist' in advance.
643Return FONTSET if it is created successfully, else return nil."
644 (let ((fontset-data (assoc fontset uninstantiated-fontset-alist)))
645 (when fontset-data
646 (setq uninstantiated-fontset-alist
647 (delete fontset-data uninstantiated-fontset-alist))
648
649 (let* ((fields (x-decompose-font-name fontset))
650 (style (nth 1 fontset-data))
651 (fontlist (x-complement-fontset-spec fields (nth 2 fontset-data)))
652 (font (cdr (assq 'ascii fontlist))))
653 ;; If ASCII font is available, instantiate this fontset.
654 (when font
655 (let ((new-fontlist (list (cons 'ascii font))))
656 ;; Fonts for non-ascii charsets should be modified for
657 ;; this style now.
658 (while fontlist
659 (setq font (cdr (car fontlist)))
660 (or (eq (car (car fontlist)) 'ascii)
661 (setq new-fontlist
662 (cons (cons (car (car fontlist))
663 (x-modify-font-name font style))
664 new-fontlist)))
665 (setq fontlist (cdr fontlist)))
666 (new-fontset fontset new-fontlist)
667 fontset))))))
668
669(defun resolve-fontset-name (pattern)
670 "Return a fontset name matching PATTERN."
671 (let ((fontset (car (rassoc pattern fontset-alias-alist))))
672 (or fontset (setq fontset pattern))
673 (if (assoc fontset uninstantiated-fontset-alist)
674 (instantiate-fontset fontset)
675 (query-fontset fontset))))
676 456
677;; Create standard fontset from 16 dots fonts which are the most widely 457;; Create standard fontset from 16 dots fonts which are the most widely
678;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are 458;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are
@@ -707,10 +487,6 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.")
707 (create-fontset-from-fontset-spec fontset-spec t 'noerror) 487 (create-fontset-from-fontset-spec fontset-spec t 'noerror)
708 (setq idx (1+ idx))))) 488 (setq idx (1+ idx)))))
709 489
710(defsubst fontset-list ()
711 "Returns a list of all defined fontset names."
712 (mapcar 'car global-fontset-alist))
713
714;; 490;;
715(provide 'fontset) 491(provide 'fontset)
716 492