aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa1998-06-12 07:10:59 +0000
committerKenichi Handa1998-06-12 07:10:59 +0000
commitbb98ead95142201215c5226ff1f18260813d8cf4 (patch)
tree1b4dfa171502f2429de304049b21cf87d4578405
parent12755bafbfaadc09c4bf000dd157410fad7cb588 (diff)
downloademacs-bb98ead95142201215c5226ff1f18260813d8cf4.tar.gz
emacs-bb98ead95142201215c5226ff1f18260813d8cf4.zip
(instantiate-fontset): Delete
duplicated call of x-complement-fontset-spec. Call new-fontset with a correct argument. (x-compose-font-name): Argument name adjusted for the doc-string. (x-complement-fontset-spec): Don't alter the contents of the arguments XLFD-FIELDS and FONTLIST. (x-style-funcs-alist): The format changed. (x-modify-font-name): New function. (create-fontset-from-fontset-spec): The arg STYLE-VARIANT-P is changed to STYLE-VARIANT, the format also changed. Use x-modify-font-name instead of calling functions in x-style-funcs-alist directly. (instantiate-fontset): Use x-modify-font-name instead of calling functions in x-style-funcs-alist directly. (resolve-fontset-name): New function.
-rw-r--r--lisp/international/fontset.el266
1 files changed, 160 insertions, 106 deletions
diff --git a/lisp/international/fontset.el b/lisp/international/fontset.el
index 8074a942a54..3944e481d94 100644
--- a/lisp/international/fontset.el
+++ b/lisp/international/fontset.el
@@ -228,14 +228,14 @@ PATTERN. If no full XLFD name is gotten, return nil."
228 (setq name (replace-match "-*-" t t name))) 228 (setq name (replace-match "-*-" t t name)))
229 name) 229 name)
230 230
231(defun x-compose-font-name (xlfd-fields &optional reduce) 231(defun x-compose-font-name (fields &optional reduce)
232 "Compose X's fontname from FIELDS. 232 "Compose X's fontname from FIELDS.
233FIELDS is a vector of XLFD fields. 233FIELDS is a vector of XLFD fields, the length 14.
234If a field is nil, wild-card letter `*' is embedded. 234If a field is nil, wild-card letter `*' is embedded.
235Optional argument REDUCE non-nil means consecutive wild-cards are 235Optional argument REDUCE non-nil means consecutive wild-cards are
236reduced to be one." 236reduced to be one."
237 (let ((name 237 (let ((name
238 (concat "-" (mapconcat (lambda (x) (or x "*")) xlfd-fields "-")))) 238 (concat "-" (mapconcat (lambda (x) (or x "*")) fields "-"))))
239 (if reduce 239 (if reduce
240 (x-reduce-font-name name) 240 (x-reduce-font-name name)
241 name))) 241 name)))
@@ -290,12 +290,17 @@ FONTLIST is an alist of charsets vs the corresponding font names.
290Font names for charsets not listed in FONTLIST are generated from 290Font names for charsets not listed in FONTLIST are generated from
291XLFD-FIELDS and a property of x-charset-registry of each charset 291XLFD-FIELDS and a property of x-charset-registry of each charset
292automatically." 292automatically."
293 (let ((charsets charset-list)) 293 (let ((charsets charset-list)
294 (xlfd-fields-non-ascii (copy-sequence xlfd-fields))
295 (new-fontlist nil))
296 (aset xlfd-fields-non-ascii xlfd-regexp-foundry-subnum nil)
297 (aset xlfd-fields-non-ascii xlfd-regexp-family-subnum nil)
298 (aset xlfd-fields-non-ascii xlfd-regexp-adstyle-subnum nil)
299 (aset xlfd-fields-non-ascii xlfd-regexp-avgwidth-subnum nil)
294 (while charsets 300 (while charsets
295 (let ((charset (car charsets))) 301 (let ((charset (car charsets)))
296 (unless (assq charset fontlist) 302 (unless (assq charset fontlist)
297 (let ((registry (get-charset-property charset 303 (let ((registry (get-charset-property charset 'x-charset-registry))
298 'x-charset-registry))
299 registry-val encoding-val fontname) 304 registry-val encoding-val fontname)
300 (if (string-match "-" registry) 305 (if (string-match "-" registry)
301 ;; REGISTRY contains `CHARSET_ENCODING' field. 306 ;; REGISTRY contains `CHARSET_ENCODING' field.
@@ -303,29 +308,38 @@ automatically."
303 encoding-val (substring registry (match-end 0))) 308 encoding-val (substring registry (match-end 0)))
304 (setq registry-val (concat registry "*") 309 (setq registry-val (concat registry "*")
305 encoding-val "*")) 310 encoding-val "*"))
306 (aset xlfd-fields xlfd-regexp-registry-subnum registry-val) 311 (let ((xlfd (if (eq charset 'ascii) xlfd-fields
307 (aset xlfd-fields xlfd-regexp-encoding-subnum encoding-val) 312 xlfd-fields-non-ascii)))
308 (setq fontname (downcase (x-compose-font-name xlfd-fields))) 313 (aset xlfd xlfd-regexp-registry-subnum registry-val)
309 (setq fontlist (cons (cons charset fontname) fontlist)) 314 (aset xlfd xlfd-regexp-encoding-subnum encoding-val)
315 (setq fontname (downcase (x-compose-font-name xlfd))))
316 (setq new-fontlist (cons (cons charset fontname) new-fontlist))
310 (register-alternate-fontnames fontname)))) 317 (register-alternate-fontnames fontname))))
311 (setq charsets (cdr charsets)))) 318 (setq charsets (cdr charsets)))
312 319
313 ;; If the font for ASCII can also be used for another charsets, use 320 ;; Be sure that ASCII font is avairable.
314 ;; that font instead of what generated based on x-charset-registery 321 (let ((slot (or (assq 'ascii fontlist) (assq 'ascii new-fontlist)))
315 ;; in the previous code. 322 ascii-font)
316 (let ((ascii-font (cdr (assq 'ascii fontlist))) 323 (if (setq ascii-font (condition-case nil
317 (l x-font-name-charset-alist)) 324 (x-resolve-font-name (cdr slot))
318 (while l 325 (error nil)))
319 (if (string-match (car (car l)) ascii-font) 326 (setcdr slot ascii-font))
320 (let ((charsets (cdr (car l)))) 327 (if ascii-font
321 (while charsets 328 (let ((l x-font-name-charset-alist))
322 (if (not (eq (car charsets) 'ascii)) 329 ;; If the ASCII font can also be used for another
323 (setcdr (assq (car charsets) fontlist) ascii-font)) 330 ;; charsets, use that font instead of what generated based
324 (setq charsets (cdr charsets))) 331 ;; on x-charset-registery in the previous code.
325 (setq l nil)) 332 (while l
326 (setq l (cdr l))))) 333 (if (string-match (car (car l)) ascii-font)
327 334 (let ((charsets (cdr (car l))))
328 fontlist) 335 (while charsets
336 (if (and (not (eq (car charsets) 'ascii))
337 (setq slot (assq (car charsets) new-fontlist)))
338 (setcdr slot ascii-font))
339 (setq charsets (cdr charsets)))
340 (setq l nil))
341 (setq l (cdr l))))
342 (append fontlist new-fontlist))))))
329 343
330(defun fontset-name-p (fontset) 344(defun fontset-name-p (fontset)
331 "Return non-nil if FONTSET is valid as fontset name. 345 "Return non-nil if FONTSET is valid as fontset name.
@@ -389,32 +403,49 @@ STYLE is a style of FONTSET, one of the followings:
389FONTLIST is an alist of charsets vs font names to be used in FONSET.") 403FONTLIST is an alist of charsets vs font names to be used in FONSET.")
390 404
391(defconst x-style-funcs-alist 405(defconst x-style-funcs-alist
392 '((bold x-make-font-bold) 406 `((bold . x-make-font-bold)
393 (demibold x-make-font-demibold) 407 (demibold . x-make-font-demibold)
394 (italic x-make-font-italic) 408 (italic . x-make-font-italic)
395 (oblique x-make-font-oblique) 409 (oblique . x-make-font-oblique)
396 (bold-italic x-make-font-bold x-make-font-italic) 410 (bold-italic . x-make-font-bold-italic)
397 (demibold-italic x-make-font-demibold x-make-font-italic) 411 (demibold-italic
398 (demibold-oblique x-make-font-demibold x-make-font-oblique) 412 . ,(function (lambda (x) (x-make-font-italic (x-make-font-demibold x)))))
399 (bold-oblique x-make-font-bold x-make-font-oblique)) 413 (demibold-oblique
400 "Alist of font style vs functions to generate a X font name of the style.") 414 . ,(function (lambda (x) (x-make-font-oblique (x-make-font-demibold x)))))
415 (bold-oblique
416 . ,(function (lambda (x) (x-make-font-oblique (x-make-font-bold x))))))
417 "Alist of font style vs function to generate a X font name of the style.
418The function is called with one argument, a font name.")
419
420(defun x-modify-font-name (fontname style)
421 "Substitute style specification part of FONTNAME for STYLE.
422STYLE should be listed in the variable `x-style-funcs-alist'."
423 (let ((func (cdr (assq style x-style-funcs-alist))))
424 (if func
425 (funcall func fontname))))
401 426
402;;;###autoload 427;;;###autoload
403(defun create-fontset-from-fontset-spec (fontset-spec 428(defun create-fontset-from-fontset-spec (fontset-spec
404 &optional style-variant-p noerror) 429 &optional style-variant noerror)
405 "Create a fontset from fontset specification string FONTSET-SPEC. 430 "Create a fontset from fontset specification string FONTSET-SPEC.
406FONTSET-SPEC is a string of the format: 431FONTSET-SPEC is a string of the format:
407 FONTSET-NAME,CHARSET-NAME0:FONT-NAME0,CHARSET-NAME1:FONT-NAME1, ... 432 FONTSET-NAME,CHARSET-NAME0:FONT-NAME0,CHARSET-NAME1:FONT-NAME1, ...
408Any number of SPACE, TAB, and NEWLINE can be put before and after commas. 433Any number of SPACE, TAB, and NEWLINE can be put before and after commas.
409If optional argument STYLE-VARIANT-P is specified, it also creates 434
410fontsets which differs from FONTSET-NAME in styles (e.g. bold, italic). 435Optional 2nd argument STYLE-VARIANT is a list of font styles
436\(e.g. bold, italic) or the symbol t to specify all available styles.
437If this argument is specified, fontsets which differs from
438FONTSET-NAME in styles are also created. An element of STYLE-VARIANT
439may be cons of style and a font name. In this case, the style variant
440fontset uses the font for ASCII character set.
441
411If this function attempts to create already existing fontset, error is 442If this function attempts to create already existing fontset, error is
412signaled unless the optional 3rd argument NOERROR is non-nil." 443signaled unless the optional 3rd argument NOERROR is non-nil."
413 (if (not (string-match "^[^,]+" fontset-spec)) 444 (if (not (string-match "^[^,]+" fontset-spec))
414 (error "Invalid fontset spec: %s" fontset-spec)) 445 (error "Invalid fontset spec: %s" fontset-spec))
415 (let ((idx (match-end 0)) 446 (let ((idx (match-end 0))
416 (name (match-string 0 fontset-spec)) 447 (name (match-string 0 fontset-spec))
417 fontlist charset) 448 fontlist full-fontlist ascii-font charset)
418 (if (query-fontset name) 449 (if (query-fontset name)
419 (or noerror 450 (or noerror
420 (error "Fontset \"%s\" already exists")) 451 (error "Fontset \"%s\" already exists"))
@@ -425,88 +456,111 @@ signaled unless the optional 3rd argument NOERROR is non-nil."
425 (if (charsetp charset) 456 (if (charsetp charset)
426 (setq fontlist (cons (cons charset (match-string 2 fontset-spec)) 457 (setq fontlist (cons (cons charset (match-string 2 fontset-spec))
427 fontlist)))) 458 fontlist))))
428 459 ;; Remember the specified ASCII font name now because it will be
429 (if style-variant-p 460 ;; replaced by resolved font name by x-complement-fontset-spec.
430 ;; Generate fontset names of style variants and set them in 461 (setq ascii-font (cdr (assq 'ascii fontlist)))
431 ;; uninstantiated-fontset-alist.
432 (let ((style-funcs-alist x-style-funcs-alist)
433 new-name style funcs)
434 (while style-funcs-alist
435 (setq style (car (car style-funcs-alist))
436 funcs (cdr (car style-funcs-alist)))
437 (setq new-name name)
438 (while funcs
439 (setq new-name (funcall (car funcs) new-name))
440 (setq funcs (cdr funcs)))
441 (setq uninstantiated-fontset-alist
442 (cons (list new-name style fontlist)
443 uninstantiated-fontset-alist))
444 (setq style-funcs-alist (cdr style-funcs-alist)))))
445 462
446 ;; If NAME conforms to XLFD, complement FONTLIST for charsets 463 ;; If NAME conforms to XLFD, complement FONTLIST for charsets
447 ;; which are not specified in FONTSET-SPEC. 464 ;; which are not specified in FONTSET-SPEC.
448 (let ((xlfd-fields (x-decompose-font-name name))) 465 (let ((fields (x-decompose-font-name name)))
449 (if xlfd-fields 466 (if fields
450 (setq fontlist 467 (setq full-fontlist (x-complement-fontset-spec fields fontlist))))
451 (x-complement-fontset-spec xlfd-fields fontlist))))
452 468
453 ;; Create the fontset. 469 (when full-fontlist
454 (new-fontset name fontlist) 470 ;; Create the fontset.
455 471 (new-fontset name full-fontlist)
456 ;; Define the alias (short name) if appropriate. 472
457 (if (and (not (assoc name fontset-alias-alist)) 473 ;; Define aliases: short name (if appropriate) and ASCII font name.
458 (string-match "fontset-.*$" name)) 474 (if (and (string-match "fontset-.*$" name)
459 (let ((alias (match-string 0 name))) 475 (not (assoc name fontset-alias-alist)))
460 (or (rassoc alias fontset-alias-alist) 476 (let ((alias (match-string 0 name)))
461 (setq fontset-alias-alist 477 (or (rassoc alias fontset-alias-alist)
462 (cons (cons name alias) fontset-alias-alist)))))))) 478 (setq fontset-alias-alist
479 (cons (cons name alias) fontset-alias-alist)))))
480 (let ((resolved-ascii-font (cdr (assq 'ascii full-fontlist))))
481 (setq fontset-alias-alist
482 (cons (cons name resolved-ascii-font)
483 fontset-alias-alist))
484 (or (equal ascii-font resolved-ascii-font)
485 (setq fontset-alias-alist
486 (cons (cons name ascii-font)
487 fontset-alias-alist))))
488
489 ;; At last, handle style variants.
490 (if (eq style-variant t)
491 (setq style-variant (mapcar 'car x-style-funcs-alist)))
492
493 (if style-variant
494 ;; Generate fontset names of style variants and set them
495 ;; in uninstantiated-fontset-alist.
496 (let* (nonascii-fontlist
497 new-name new-ascii-font style font)
498 (if ascii-font
499 (setq nonascii-fontlist (delete (cons 'ascii ascii-font)
500 (copy-sequence fontlist)))
501 (setq ascii-font (cdr (assq 'ascii full-fontlist))
502 nonascii-fontlist fontlist))
503 (while style-variant
504 (setq style (car style-variant))
505 (if (symbolp style)
506 (setq font nil)
507 (setq font (cdr style)
508 style (car style)))
509 (setq new-name (x-modify-font-name name style))
510 (when new-name
511 ;; Modify ASCII font name for the style...
512 (setq new-ascii-font
513 (or font (x-modify-font-name ascii-font style)))
514 ;; but leave fonts for the other charsets unmodified
515 ;; for the momemnt. They are modified for the style
516 ;; in instantiate-fontset.
517 (setq uninstantiated-fontset-alist
518 (cons (list new-name
519 style
520 (cons (cons 'ascii new-ascii-font)
521 nonascii-fontlist))
522 uninstantiated-fontset-alist))
523 (setq fontset-alias-alist
524 (cons (cons new-name new-ascii-font)
525 fontset-alias-alist)))
526 (setq style-variant (cdr style-variant)))))))))
463 527
464(defun instantiate-fontset (fontset) 528(defun instantiate-fontset (fontset)
465 "Make FONTSET be readly to use. 529 "Make FONTSET be readly to use.
466FONTSET should be in the variable `uninstantiated-fontset-alist' in advance. 530FONTSET should be in the variable `uninstantiated-fontset-alist' in advance.
467Return FONTSET if it is created successfully, else return nil." 531Return FONTSET if it is created successfully, else return nil."
468 (let ((fontset-data (assoc fontset uninstantiated-fontset-alist))) 532 (let ((fontset-data (assoc fontset uninstantiated-fontset-alist)))
469 (if (null fontset-data) 533 (when fontset-data
470 nil 534 (setq uninstantiated-fontset-alist
471 (let* ((xlfd-fields (x-decompose-font-name fontset)) 535 (delete fontset-data uninstantiated-fontset-alist))
472 (fontlist (x-complement-fontset-spec xlfd-fields 536
473 (nth 2 fontset-data))) 537 (let* ((fields (x-decompose-font-name fontset))
474 (funcs (cdr (assq (nth 1 fontset-data) x-style-funcs-alist))) 538 (style (nth 1 fontset-data))
475 ascii-font font font2) 539 (fontlist (x-complement-fontset-spec fields (nth 2 fontset-data)))
476 (setq uninstantiated-fontset-alist 540 (font (cdr (assq 'ascii fontlist))))
477 (delete fontset-data uninstantiated-fontset-alist)) 541 ;; If ASCII font is available, instantiate this fontset.
478 (setq fontlist (x-complement-fontset-spec xlfd-fields fontlist))
479
480 ;; At first, check if ASCII font of this style is surely available.
481 (setq ascii-font (cdr (assq 'ascii fontlist)))
482 (if (= (length funcs) 1)
483 (and (setq font (funcall (car funcs) ascii-font))
484 (setq font (x-resolve-font-name font 'default)))
485 (and (setq font (funcall (car funcs) ascii-font))
486 (not (equal font ascii-font))
487 (setq font2 (funcall (nth 1 funcs) font))
488 (not (equal font2 font))
489 (setq font (x-resolve-font-name font2 'default))))
490
491 ;; If ASCII font is available, instantiate the fontset.
492 (when font 542 (when font
493 (let ((new-fontlist (list (cons 'ascii font)))) 543 (let ((new-fontlist (list (cons 'ascii font))))
544 ;; Fonts for non-ascii charsets should be modified for
545 ;; this style now.
494 (while fontlist 546 (while fontlist
495 (setq font (cdr (car fontlist))) 547 (setq font (cdr (car fontlist)))
496 (or (eq (car (car fontlist)) 'ascii) 548 (or (eq (car (car fontlist)) 'ascii)
497 (if (if (= (length funcs) 1) 549 (setq new-fontlist
498 (setq font (funcall (car funcs) font)) 550 (cons (cons (car (car fontlist))
499 (and (setq font (funcall (car funcs) font)) 551 (x-modify-font-name font style))
500 (not (equal font (cdr (car fontlist)))) 552 new-fontlist)))
501 (setq font2 (funcall (nth 1 funcs) font))
502 (not (equal font2 font))
503 (setq font font2)))
504 (setq new-fontlist
505 (cons (cons (car fontlist) font) new-fontlist))))
506 (setq fontlist (cdr fontlist))) 553 (setq fontlist (cdr fontlist)))
507 (new-fontset fontset (x-complement-fontset-spec xlfd-fields 554 (new-fontset fontset new-fontlist)
508 fontlist))
509 fontset)))))) 555 fontset))))))
556
557(defun resolve-fontset-name (pattern)
558 "Return a fontset name matching PATTERN."
559 (let ((fontset (car (rassoc pattern fontset-alias-alist))))
560 (or fontset (setq fontset pattern))
561 (if (assoc fontset uninstantiated-fontset-alist)
562 (instantiate-fontset fontset)
563 (query-fontset fontset))))
510 564
511;; Create standard fontset from 16 dots fonts which are the most widely 565;; Create standard fontset from 16 dots fonts which are the most widely
512;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are 566;; installed fonts. Fonts for Chinese-GB, Korean, and Chinese-CNS are