diff options
| author | Kenichi Handa | 2003-01-10 07:35:06 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2003-01-10 07:35:06 +0000 |
| commit | 92438d6e2d79035566087b6f7c3b5ff225dfd0db (patch) | |
| tree | 627d02f181c8065e4a91f2ec9bc9f78eacd2840d | |
| parent | 143023034c048ac7714ff016c5e332e8ab83a888 (diff) | |
| download | emacs-92438d6e2d79035566087b6f7c3b5ff225dfd0db.tar.gz emacs-92438d6e2d79035566087b6f7c3b5ff225dfd0db.zip | |
Enable the default fontset to use
unicode fonts for ASCII characters.
(x-decompose-font-name): Don't try to resolve PATTERN by
x-resolve-font-name.
(x-complement-fontset-spec): Never prepend an ASCII font.
(create-fontset-from-fontset-spec): If a fontset of the same name
already exists, override it instead of signalling an error. Don't
turn `ascii' into `latin'. Don't update fontset-alias-alist here.
| -rw-r--r-- | lisp/international/fontset.el | 216 |
1 files changed, 59 insertions, 157 deletions
diff --git a/lisp/international/fontset.el b/lisp/international/fontset.el index a48d7db5a56..773f563ddc4 100644 --- a/lisp/international/fontset.el +++ b/lisp/international/fontset.el | |||
| @@ -218,12 +218,12 @@ | |||
| 218 | ;; Append Unicode fonts. | 218 | ;; Append Unicode fonts. |
| 219 | ;; This may find fonts with more variants (bold, italic) but which don't cover | 219 | ;; This may find fonts with more variants (bold, italic) but which don't cover |
| 220 | ;; many characters. | 220 | ;; many characters. |
| 221 | (set-fontset-font "fontset-default" '(#x00A0 . #xFFFF) | 221 | (set-fontset-font "fontset-default" '(0 . #xFFFF) |
| 222 | '(nil . "iso10646-1") nil 'append) | 222 | '(nil . "iso10646-1") nil 'append) |
| 223 | ;; These may find fonts that cover many characters but with fewer variants. | 223 | ;; These may find fonts that cover many characters but with fewer variants. |
| 224 | (set-fontset-font "fontset-default" '(#x00A0 . #xFFFF) | 224 | (set-fontset-font "fontset-default" '(0 . #xFFFF) |
| 225 | '("gnu-unifont" . "iso10646-1") nil 'append) | 225 | '("gnu-unifont" . "iso10646-1") nil 'append) |
| 226 | (set-fontset-font "fontset-default" '(#x00A0 . #xFFFF) | 226 | (set-fontset-font "fontset-default" '(0 . #xFFFF) |
| 227 | '("mutt-clearlyu" . "iso10646-1") nil 'append) | 227 | '("mutt-clearlyu" . "iso10646-1") nil 'append) |
| 228 | 228 | ||
| 229 | ;; These are the registered registries/encodings from | 229 | ;; These are the registered registries/encodings from |
| @@ -408,80 +408,22 @@ | |||
| 408 | )) | 408 | )) |
| 409 | 409 | ||
| 410 | (defun x-decompose-font-name (pattern) | 410 | (defun x-decompose-font-name (pattern) |
| 411 | "Decompose PATTERN into XLFD fields and return vector of the fields. | 411 | "Decompose PATTERN into XLFD fields and return a vector of the fields. |
| 412 | The length of the vector is 12. | 412 | The length of the vector is 12. |
| 413 | 413 | The FOUNDRY and FAMILY fields are concatinated and stored in the first | |
| 414 | If PATTERN doesn't conform to XLFD, try to get a full XLFD name from | 414 | element of the vector. |
| 415 | X server and use the information of the full name to decompose | 415 | The REGISTRY and ENCODING fields are concatinated and stored in the last |
| 416 | PATTERN. If no full XLFD name is gotten, return nil." | 416 | element of the vector. |
| 417 | (let (xlfd-fields fontname) | 417 | |
| 418 | (if (string-match xlfd-tight-regexp pattern) | 418 | Return nil if PATTERN doesn't conform to XLFD." |
| 419 | (progn | 419 | (if (string-match xlfd-tight-regexp pattern) |
| 420 | (setq xlfd-fields (make-vector 12 nil)) | 420 | (let ((xlfd-fields (make-vector 12 nil))) |
| 421 | (dotimes (i 12) | 421 | (dotimes (i 12) |
| 422 | (aset xlfd-fields i (match-string (1+ i) pattern))) | 422 | (aset xlfd-fields i (match-string (1+ i) pattern))) |
| 423 | (dotimes (i 12) | 423 | (dotimes (i 12) |
| 424 | (if (string-match "^[*-]+$" (aref xlfd-fields i)) | 424 | (if (string-match "^[*-]+$" (aref xlfd-fields i)) |
| 425 | (aset xlfd-fields i nil))) | 425 | (aset xlfd-fields i nil))) |
| 426 | xlfd-fields) | 426 | xlfd-fields))) |
| 427 | (setq fontname (condition-case nil | ||
| 428 | (x-resolve-font-name pattern) | ||
| 429 | (error))) | ||
| 430 | (if (and fontname | ||
| 431 | (string-match xlfd-tight-regexp fontname)) | ||
| 432 | ;; We get a full XLFD name. | ||
| 433 | (let ((len (length pattern)) | ||
| 434 | (i 0) | ||
| 435 | l) | ||
| 436 | ;; Setup xlfd-fields by the full XLFD name. Each element | ||
| 437 | ;; should be a cons of matched index and matched string. | ||
| 438 | (setq xlfd-fields (make-vector 12 nil)) | ||
| 439 | (dotimes (i 12) | ||
| 440 | (aset xlfd-fields i | ||
| 441 | (cons (match-beginning (1+ i)) | ||
| 442 | (match-string (1+ i) fontname)))) | ||
| 443 | |||
| 444 | ;; Replace wild cards in PATTERN by regexp codes. | ||
| 445 | (setq i 0) | ||
| 446 | (while (< i len) | ||
| 447 | (let ((ch (aref pattern i))) | ||
| 448 | (if (= ch ??) | ||
| 449 | (setq pattern (concat (substring pattern 0 i) | ||
| 450 | "\\(.\\)" | ||
| 451 | (substring pattern (1+ i))) | ||
| 452 | len (+ len 4) | ||
| 453 | i (+ i 4)) | ||
| 454 | (if (= ch ?*) | ||
| 455 | (setq pattern (concat (substring pattern 0 i) | ||
| 456 | "\\(.*\\)" | ||
| 457 | (substring pattern (1+ i))) | ||
| 458 | len (+ len 5) | ||
| 459 | i (+ i 5)) | ||
| 460 | (setq i (1+ i)))))) | ||
| 461 | |||
| 462 | ;; Set each element of xlfd-fields to proper strings. | ||
| 463 | (if (string-match pattern fontname) | ||
| 464 | ;; The regular expression PATTERN matches the full XLFD | ||
| 465 | ;; name. Set elements that correspond to a wild card | ||
| 466 | ;; in PATTERN to nil, set the other elements to the | ||
| 467 | ;; exact strings in PATTERN. | ||
| 468 | (let ((l (cdr (cdr (match-data))))) | ||
| 469 | (setq i 0) | ||
| 470 | (while (< i 12) | ||
| 471 | (if (or (null l) (< (car (aref xlfd-fields i)) (car l))) | ||
| 472 | (progn | ||
| 473 | (aset xlfd-fields i (cdr (aref xlfd-fields i))) | ||
| 474 | (setq i (1+ i))) | ||
| 475 | (if (< (car (aref xlfd-fields i)) (car (cdr l))) | ||
| 476 | (progn | ||
| 477 | (aset xlfd-fields i nil) | ||
| 478 | (setq i (1+ i))) | ||
| 479 | (setq l (cdr (cdr l))))))) | ||
| 480 | ;; Set each element of xlfd-fields to the exact string | ||
| 481 | ;; in the corresponding fields in full XLFD name. | ||
| 482 | (dotimes (i 12) | ||
| 483 | (aset xlfd-fields i (cdr (aref xlfd-fields i))))) | ||
| 484 | xlfd-fields))))) | ||
| 485 | 427 | ||
| 486 | (defun x-compose-font-name (fields &optional reduce) | 428 | (defun x-compose-font-name (fields &optional reduce) |
| 487 | "Compose X fontname from FIELDS. | 429 | "Compose X fontname from FIELDS. |
| @@ -512,43 +454,20 @@ Value is name of that font." | |||
| 512 | 454 | ||
| 513 | 455 | ||
| 514 | (defun x-complement-fontset-spec (xlfd-fields fontlist) | 456 | (defun x-complement-fontset-spec (xlfd-fields fontlist) |
| 515 | "Complement FONTLIST for charsets based on XLFD-FIELDS and return it. | 457 | "Complement elements of FONTLIST based on XLFD-FIELDS. |
| 516 | XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields. | 458 | XLFD-FIELDS is a vector of XLFD (X Logical Font Description) fields. |
| 517 | FONTLIST is an alist of charsets vs the corresponding font names. | 459 | FONTLIST is an alist of script names vs the corresponding font names. |
| 518 | 460 | ||
| 519 | The fonts are complemented as below. | 461 | The font names are complemented as below. |
| 520 | 462 | ||
| 521 | At first, if FONTLIST doesn't specify a font for ASCII charset, | 463 | If a font name matches `xlfd-style-regexp', each field of wild card is |
| 522 | generate a font name for the charset from XLFD-FIELDS, and add that | 464 | replaced by the corresponding fields in XLFD-FIELDS." |
| 523 | information to FONTLIST. | 465 | (let ((default-spec (vector (aref xlfd-fields xlfd-regexp-family-subnum) |
| 524 | 466 | (aref xlfd-fields xlfd-regexp-weight-subnum) | |
| 525 | Then, replace font names with the corresponding XLFD field vectors | 467 | (aref xlfd-fields xlfd-regexp-slant-subnum) |
| 526 | while substituting default field names for wild cards if they match | 468 | (aref xlfd-fields xlfd-regexp-swidth-subnum) |
| 527 | `xlfd-style-regexp'. The default field names are decided by | 469 | (aref xlfd-fields xlfd-regexp-adstyle-subnum) |
| 528 | XLFD-FIELDS." | 470 | (aref xlfd-fields xlfd-regexp-registry-subnum)))) |
| 529 | (let* ((default-spec (vector (aref xlfd-fields xlfd-regexp-family-subnum) | ||
| 530 | (aref xlfd-fields xlfd-regexp-weight-subnum) | ||
| 531 | (aref xlfd-fields xlfd-regexp-slant-subnum) | ||
| 532 | (aref xlfd-fields xlfd-regexp-swidth-subnum) | ||
| 533 | (aref xlfd-fields xlfd-regexp-adstyle-subnum) | ||
| 534 | (aref xlfd-fields xlfd-regexp-registry-subnum))) | ||
| 535 | (slot (assq 'ascii fontlist)) | ||
| 536 | (ascii-font (cadr slot)) | ||
| 537 | xlfd-ascii) | ||
| 538 | (if ascii-font | ||
| 539 | (progn | ||
| 540 | (setq ascii-font (x-resolve-font-name ascii-font)) | ||
| 541 | (setcar (cdr slot) ascii-font) | ||
| 542 | (setq xlfd-ascii (x-decompose-font-name ascii-font)) | ||
| 543 | (dotimes (i 11) | ||
| 544 | (or (aref xlfd-fields i) | ||
| 545 | (aset xlfd-fields i (aref xlfd-ascii i))))) | ||
| 546 | ;; If font for ASCII is not specified, add it. | ||
| 547 | (setq xlfd-ascii (copy-sequence xlfd-fields)) | ||
| 548 | (aset xlfd-ascii xlfd-regexp-registry-subnum "iso8859-1") | ||
| 549 | (setq ascii-font (x-must-resolve-font-name xlfd-ascii)) | ||
| 550 | (setq fontlist (cons (list 'ascii ascii-font) fontlist))) | ||
| 551 | |||
| 552 | (dolist (elt fontlist) | 471 | (dolist (elt fontlist) |
| 553 | (let ((name (cadr elt)) | 472 | (let ((name (cadr elt)) |
| 554 | font-spec) | 473 | font-spec) |
| @@ -678,61 +597,44 @@ FONTSET-SPEC is a string of the format: | |||
| 678 | FONTSET-NAME,SCRIPT-NAME0:FONT-NAME0,SCRIPT-NAME1:FONT-NAME1, ... | 597 | FONTSET-NAME,SCRIPT-NAME0:FONT-NAME0,SCRIPT-NAME1:FONT-NAME1, ... |
| 679 | Any number of SPACE, TAB, and NEWLINE can be put before and after commas. | 598 | Any number of SPACE, TAB, and NEWLINE can be put before and after commas. |
| 680 | 599 | ||
| 681 | Optional 2nd argument is ignored. It exists just for backward | 600 | When a frame uses the fontset as the `font' parameter, the frame's |
| 682 | compatibility. | 601 | default font name is derived from FONTSET-NAME by substituting |
| 602 | \"iso8859-1\" for the tail part \"fontset-XXX\". But, if SCRIPT-NAMEn | ||
| 603 | is \"ascii\", use the corresponding FONT-NAMEn as the default font | ||
| 604 | name. | ||
| 683 | 605 | ||
| 684 | If this function attempts to create already existing fontset, error is | 606 | Optional 2nd and 3rd arguments are ignored. They exist just for |
| 685 | signaled unless the optional 3rd argument NOERROR is non-nil. | 607 | backward compatibility. |
| 686 | 608 | ||
| 687 | It returns a name of the created fontset. | 609 | It returns a name of the created fontset. |
| 688 | 610 | ||
| 689 | For backward compatibility, SCRIPT-NAME may be a charset name, in | 611 | For backward compatibility, SCRIPT-NAME may be a charset name, in |
| 690 | which case, the corresponding script is decided by the variable | 612 | which case, the corresponding script is decided by the variable |
| 691 | `charset-script-alist' (which see)." | 613 | `charset-script-alist' (which see)." |
| 692 | (if (not (string-match "^[^,]+" fontset-spec)) | 614 | (or (string-match "^[^,]+" fontset-spec) |
| 693 | (error "Invalid fontset spec: %s" fontset-spec)) | 615 | (error "Invalid fontset spec: %s" fontset-spec)) |
| 694 | (let ((idx (match-end 0)) | 616 | (let ((idx (match-end 0)) |
| 695 | (name (match-string 0 fontset-spec)) | 617 | (name (match-string 0 fontset-spec)) |
| 696 | xlfd-fields script fontlist ascii-font) | 618 | xlfd-fields script fontlist) |
| 697 | (if (query-fontset name) | 619 | (setq xlfd-fields (x-decompose-font-name name)) |
| 698 | (or noerror | 620 | (or xlfd-fields |
| 699 | (error "Fontset \"%s\" already exists" name)) | 621 | (error "Fontset name \"%s\" not conforming to XLFD" name)) |
| 700 | (setq xlfd-fields (x-decompose-font-name name)) | 622 | |
| 701 | (or xlfd-fields | 623 | ;; At first, extract pairs of charset and fontname from FONTSET-SPEC. |
| 702 | (error "Fontset \"%s\" not conforming to XLFD" name)) | 624 | (while (string-match "[, \t\n]*\\([^:]+\\):\\([^,]+\\)" fontset-spec idx) |
| 703 | 625 | (setq idx (match-end 0)) | |
| 704 | ;; At first, extract pairs of charset and fontname from FONTSET-SPEC. | 626 | (setq script (intern (match-string 1 fontset-spec))) |
| 705 | (while (string-match "[, \t\n]*\\([^:]+\\):\\([^,]+\\)" fontset-spec idx) | 627 | (if (or (eq script 'ascii) |
| 706 | (setq idx (match-end 0)) | 628 | (memq script (char-table-extra-slot char-script-table 0)) |
| 707 | (setq script (intern (match-string 1 fontset-spec))) | 629 | (setq script (cdr (assq script charset-script-alist)))) |
| 708 | (if (or (memq script (char-table-extra-slot char-script-table 0)) | 630 | (setq fontlist (cons (list script (match-string 2 fontset-spec)) |
| 709 | (setq script (cdr (assq script charset-script-alist)))) | 631 | fontlist)))) |
| 710 | (setq fontlist (cons (list script (match-string 2 fontset-spec)) | 632 | |
| 711 | fontlist)))) | 633 | ;; Complement FONTLIST. |
| 712 | (setq ascii-font (cadr (assq 'ascii fontlist))) | 634 | (setq fontlist (x-complement-fontset-spec xlfd-fields fontlist)) |
| 713 | 635 | ||
| 714 | ;; Complement FONTLIST. | 636 | ;; Create a fontset. |
| 715 | (setq fontlist (x-complement-fontset-spec xlfd-fields fontlist)) | 637 | (new-fontset name fontlist))) |
| 716 | (setq name (x-compose-font-name xlfd-fields)) | ||
| 717 | (new-fontset name fontlist) | ||
| 718 | |||
| 719 | ;; Define the short name alias. | ||
| 720 | (if (and (string-match "fontset-.*$" name) | ||
| 721 | (not (assoc name fontset-alias-alist))) | ||
| 722 | (let ((alias (match-string 0 name))) | ||
| 723 | (or (rassoc alias fontset-alias-alist) | ||
| 724 | (setq fontset-alias-alist | ||
| 725 | (cons (cons name alias) fontset-alias-alist))))) | ||
| 726 | |||
| 727 | ;; Define the ASCII font name alias. | ||
| 728 | (or ascii-font | ||
| 729 | (setq ascii-font (cdr (assq 'ascii fontlist)))) | ||
| 730 | (or (rassoc ascii-font fontset-alias-alist) | ||
| 731 | (setq fontset-alias-alist | ||
| 732 | (cons (cons name ascii-font) | ||
| 733 | fontset-alias-alist)))) | ||
| 734 | |||
| 735 | name)) | ||
| 736 | 638 | ||
| 737 | (defun create-fontset-from-ascii-font (font &optional resolved-font | 639 | (defun create-fontset-from-ascii-font (font &optional resolved-font |
| 738 | fontset-name) | 640 | fontset-name) |