Mercurial > hg > xemacs-beta
comparison lisp/font.el @ 280:7df0dd720c89 r21-0b38
Import from CVS: tag r21-0b38
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:32:22 +0200 |
parents | 727739f917cb |
children | c42ec1d1cded |
comparison
equal
deleted
inserted
replaced
279:c20b2fb5bb0a | 280:7df0dd720c89 |
---|---|
98 (setq keywords (cdr keywords))))))) | 98 (setq keywords (cdr keywords))))))) |
99 | 99 |
100 (defconst font-window-system-mappings | 100 (defconst font-window-system-mappings |
101 '((x . (x-font-create-name x-font-create-object)) | 101 '((x . (x-font-create-name x-font-create-object)) |
102 (ns . (ns-font-create-name ns-font-create-object)) | 102 (ns . (ns-font-create-name ns-font-create-object)) |
103 (mswindows . (x-font-create-name x-font-create-object)) ; XXX FIXME | 103 (mswindows . (mswindows-font-create-name mswindows-font-create-object)) |
104 (pm . (x-font-create-name x-font-create-object)) ; Change? FIXME | 104 (pm . (x-font-create-name x-font-create-object)) ; Change? FIXME |
105 (tty . (tty-font-create-plist tty-font-create-object))) | 105 (tty . (tty-font-create-plist tty-font-create-object))) |
106 "An assoc list mapping device types to the function used to create | 106 "An assoc list mapping device types to the function used to create |
107 a font name from a font structure.") | 107 a font name from a font structure.") |
108 | 108 |
763 (setq font-name "UNKNOWN FORMULA GOES HERE" | 763 (setq font-name "UNKNOWN FORMULA GOES HERE" |
764 done (try-font-name font-name device)))) | 764 done (try-font-name font-name device)))) |
765 (if done font-name)))) | 765 (if done font-name)))) |
766 | 766 |
767 | 767 |
768 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
769 ;;; The window-system dependent code (mswindows-style) | |
770 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
771 | |
772 ;;; mswindows fonts look like: | |
773 ;;; fontname[:[weight][ style][:pointsize[:effects[:charset]]]] | |
774 ;;; A minimal mswindows font spec looks like: | |
775 ;;; Courier New | |
776 ;;; A maximal mswindows font spec looks like: | |
777 ;;; Courier New:Bold Italic:10:underline strikeout:ansi | |
778 ;;; Missing parts of the font spec should be filled in with these values: | |
779 ;;; Courier New:Normal:10::ansi | |
780 ;; "^[a-zA-Z ]+:[a-zA-Z ]*:[0-9]+:[a-zA-Z ]*:[a-zA-Z 0-9]*$" | |
781 (defvar font-mswindows-font-regexp | |
782 (let | |
783 ((- ":") | |
784 (fontname "\\([a-zA-Z ]+\\)") | |
785 (weight "\\([a-zA-Z]*\\)") | |
786 (style "\\( [a-zA-Z]*\\)?") | |
787 (pointsize "\\([0-9]+\\)") | |
788 (effects "\\([a-zA-Z ]*\\)")q | |
789 (charset "\\([a-zA-Z 0-9]*\\)") | |
790 ) | |
791 (concat "^" | |
792 fontname - weight style - pointsize - effects - charset "$"))) | |
793 | |
794 (defconst mswindows-font-weight-mappings | |
795 '((:extra-light . "Extralight") | |
796 (:light . "Light") | |
797 (:demi-light . "Demilight") | |
798 (:demi . "Demi") | |
799 (:book . "Book") | |
800 (:medium . "Medium") | |
801 (:normal . "Medium") | |
802 (:demi-bold . "Demibold") | |
803 (:bold . "Bold") | |
804 (:regular . "Regular") | |
805 (:extra-bold . "Extrabold")) | |
806 "An assoc list mapping keywords to actual mswindows specific strings | |
807 for use in the 'weight' field of an mswindows font string.") | |
808 | |
809 | |
810 (defun mswindows-font-create-object (fontname &optional device) | |
811 (let ((case-fold-search t) | |
812 (font (mswindows-font-canicolize-name fontname))) | |
813 (if (or (not (stringp font)) | |
814 (not (string-match font-mswindows-font-regexp font))) | |
815 (make-font) | |
816 (let ((name (match-string 1 font)) | |
817 (weight (match-string 2 font)) | |
818 (style (match-string 3 font)) | |
819 (pointsize (match-string 4 font)) | |
820 (effects (match-string 5 font)) | |
821 (charset (match-string 6 font)) | |
822 (retval nil) | |
823 (size nil) | |
824 (case-fold-search t) | |
825 ) | |
826 (if pointsize (setq size (/ (string-to-int pointsize) 10))) | |
827 (if weight (setq weight (intern-soft (concat ":" (downcase weight))))) | |
828 (setq retval (make-font :family name | |
829 :weight weight | |
830 :size size)) | |
831 (set-font-bold-p retval (eq :bold weight)) | |
832 (cond | |
833 ((null style) nil) | |
834 ((string-match "^[iI]talic" style) | |
835 (set-font-italic-p retval t))) | |
836 retval)))) | |
837 | |
838 (defun mswindows-font-create-name (fontobj &optional device) | |
839 (if (and (not (or (font-family fontobj) | |
840 (font-weight fontobj) | |
841 (font-size fontobj) | |
842 (font-registry fontobj) | |
843 (font-encoding fontobj))) | |
844 (= (font-style fontobj) 0)) | |
845 (face-font 'default) | |
846 (or device (setq device (selected-device))) | |
847 (let* ((default (font-default-object-for-device device)) | |
848 (family (or (font-family fontobj) | |
849 (font-family default))) | |
850 (weight (or (font-weight fontobj) :medium)) | |
851 (style (font-style fontobj)) | |
852 (size (or (if font-running-xemacs | |
853 (font-size fontobj)) | |
854 (font-size default))) | |
855 (registry (or (font-registry fontobj) | |
856 (font-registry default))) | |
857 (encoding (or (font-encoding fontobj) | |
858 (font-encoding default)))) | |
859 (if (stringp family) | |
860 (setq family (list family))) | |
861 (setq weight (font-higher-weight weight | |
862 (and (font-bold-p fontobj) :bold))) | |
863 (if (stringp size) | |
864 (setq size (truncate (font-spatial-to-canonical size device)))) | |
865 (setq weight (or (cdr-safe | |
866 (assq weight mswindows-font-weight-mappings)) "")) | |
867 (let ((done nil) ; Did we find a good font yet? | |
868 (font-name nil) ; font name we are currently checking | |
869 (cur-family nil) ; current family we are checking | |
870 ) | |
871 (while (and family (not done)) | |
872 (setq cur-family (car family) | |
873 family (cdr family)) | |
874 (if (assoc cur-family font-family-mappings) | |
875 ;; If the family name is an alias as defined by | |
876 ;; font-family-mappings, then append those families | |
877 ;; to the front of 'family' and continue in the loop. | |
878 (setq family (append | |
879 (cdr-safe (assoc cur-family | |
880 font-family-mappings)) | |
881 family)) | |
882 ;; We treat oblique and italic as equivalent. Don't ask. | |
883 ;; Courier New:Bold Italic:10:underline strikeout:ansi | |
884 (setq font-name (format "%s:%s%s:%s:%s:%s" | |
885 cur-family weight | |
886 (if (font-italic-p fontobj) | |
887 " Italic" "") | |
888 (if size | |
889 (int-to-string (* 10 size)) "10") | |
890 "" | |
891 "") | |
892 done (try-font-name font-name device)))) | |
893 (if done font-name))))) | |
894 | |
895 | |
768 ;;; Cache building code | 896 ;;; Cache building code |
769 ;;;###autoload | 897 ;;;###autoload |
770 (defun x-font-build-cache (&optional device) | 898 (defun x-font-build-cache (&optional device) |
771 (let ((hashtable (make-hash-table :test 'equal :size 15)) | 899 (let ((hashtable (make-hash-table :test 'equal :size 15)) |
772 (fonts (mapcar 'x-font-create-object | 900 (fonts (mapcar 'x-font-create-object |