aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1995-07-17 22:57:32 +0000
committerKarl Heuer1995-07-17 22:57:32 +0000
commitef43639253ea115019a854f4ab8b3e0c44f73009 (patch)
tree7c20a01dcf91a9af37011b98745e3c3932555581
parent7b0e1b8f6c43018a777adba8448e14536f88ed70 (diff)
downloademacs-ef43639253ea115019a854f4ab8b3e0c44f73009.tar.gz
emacs-ef43639253ea115019a854f4ab8b3e0c44f73009.zip
(x-create-frame-with-faces): Set background-mode
and display-type frame parameters. (x-frob-font-slant, x-frob-font-weight): Replace the adstyle field with *, if we can find it. (set-face-background): Use face-color-supported-p. (face-color-gray-p): New function. (face-default-stipple): New variable. (set-face-background): Use face-default-stipple for all grays. (set-face-stipple): Change arg name. (face-color-supported-p): Use face-color-gray-p.
-rw-r--r--lisp/faces.el205
1 files changed, 125 insertions, 80 deletions
diff --git a/lisp/faces.el b/lisp/faces.el
index 7c7acc26587..637170cc457 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -125,6 +125,23 @@ in that frame; otherwise change each frame."
125 (interactive (internal-face-interactive "foreground")) 125 (interactive (internal-face-interactive "foreground"))
126 (internal-set-face-1 face 'foreground color 4 frame)) 126 (internal-set-face-1 face 'foreground color 4 frame))
127 127
128(defvar face-default-stipple "gray3"
129 "Default stipple pattern used on monochrome displays.
130This stipple pattern is used on monochrome displays
131instead of shades of gray for a face background color.
132See `set-face-stipple' for possible values for this variable.")
133
134(defun face-color-gray-p (color &optional frame)
135 "Return t if COLOR is a shade of gray (or white or black).
136FRAME specifies the frame and thus the display for interpreting COLOR."
137 (let* ((values (x-color-values color frame))
138 (r (nth 0 values))
139 (g (nth 1 values))
140 (b (nth 2 values)))
141 (and (< (abs (- r g)) (/ (max 1 (abs r) (abs g)) 20))
142 (< (abs (- g b)) (/ (max 1 (abs g) (abs b)) 20))
143 (< (abs (- b r)) (/ (max 1 (abs b) (abs r)) 20)))))
144
128(defun set-face-background (face color &optional frame) 145(defun set-face-background (face color &optional frame)
129 "Change the background color of face FACE to COLOR (a string). 146 "Change the background color of face FACE to COLOR (a string).
130If the optional FRAME argument is provided, change only 147If the optional FRAME argument is provided, change only
@@ -133,10 +150,8 @@ in that frame; otherwise change each frame."
133 ;; For a specific frame, use gray stipple instead of gray color 150 ;; For a specific frame, use gray stipple instead of gray color
134 ;; if the display does not support a gray color. 151 ;; if the display does not support a gray color.
135 (if (and frame (not (eq frame t)) 152 (if (and frame (not (eq frame t))
136 (member color '("gray" "gray1" "gray3")) 153 (not (face-color-supported-p frame color)))
137 (not (x-display-color-p frame)) 154 (set-face-stipple face face-default-stipple frame)
138 (not (x-display-grayscale-p frame)))
139 (set-face-stipple face color frame)
140 (if (null frame) 155 (if (null frame)
141 (let ((frames (frame-list))) 156 (let ((frames (frame-list)))
142 (while frames 157 (while frames
@@ -146,7 +161,7 @@ in that frame; otherwise change each frame."
146 color) 161 color)
147 (internal-set-face-1 face 'background color 5 frame)))) 162 (internal-set-face-1 face 'background color 5 frame))))
148 163
149(defun set-face-stipple (face name &optional frame) 164(defun set-face-stipple (face pixmap &optional frame)
150 "Change the stipple pixmap of face FACE to PIXMAP. 165 "Change the stipple pixmap of face FACE to PIXMAP.
151PIXMAP should be a string, the name of a file of pixmap data. 166PIXMAP should be a string, the name of a file of pixmap data.
152The directories listed in the `x-bitmap-file-path' variable are searched. 167The directories listed in the `x-bitmap-file-path' variable are searched.
@@ -158,7 +173,7 @@ and DATA is a string, containing the raw bits of the bitmap.
158If the optional FRAME argument is provided, change only 173If the optional FRAME argument is provided, change only
159in that frame; otherwise change each frame." 174in that frame; otherwise change each frame."
160 (interactive (internal-face-interactive "stipple")) 175 (interactive (internal-face-interactive "stipple"))
161 (internal-set-face-1 face 'background-pixmap name 6 frame)) 176 (internal-set-face-1 face 'background-pixmap pixmap 6 frame))
162 177
163(defalias 'set-face-background-pixmap 'set-face-stipple) 178(defalias 'set-face-background-pixmap 'set-face-stipple)
164 179
@@ -605,23 +620,36 @@ also the same size as FACE on FRAME, or fail."
605 (cdr (assq 'font (frame-parameters (selected-frame)))))) 620 (cdr (assq 'font (frame-parameters (selected-frame))))))
606 621
607(defun x-frob-font-weight (font which) 622(defun x-frob-font-weight (font which)
608 (if (or (string-match x-font-regexp font) 623 (cond ((string-match x-font-regexp font)
609 (string-match x-font-regexp-head font) 624 (concat (substring font 0 (match-beginning x-font-regexp-weight-subnum))
610 (string-match x-font-regexp-weight font)) 625 which
611 (concat (substring font 0 (match-beginning 1)) which 626 (substring font (match-end x-font-regexp-weight-subnum)
612 (substring font (match-end 1))) 627 (match-beginning x-font-regexp-adstyle-subnum))
613 nil)) 628 ;; Replace the ADD_STYLE_NAME field with *
629 ;; because the info in it may not be the same
630 ;; for related fonts.
631 "*"
632 (substring font (match-end x-font-regexp-adstyle-subnum))))
633 ((or (string-match x-font-regexp-head font)
634 (string-match x-font-regexp-weight font))
635 (concat (substring font 0 (match-beginning 1)) which
636 (substring font (match-end 1))))))
614 637
615(defun x-frob-font-slant (font which) 638(defun x-frob-font-slant (font which)
616 (cond ((or (string-match x-font-regexp font) 639 (cond ((string-match x-font-regexp font)
617 (string-match x-font-regexp-head font)) 640 (concat (substring font 0 (match-beginning x-font-regexp-slant-subnum))
618 (concat (substring font 0 (match-beginning 2)) which 641 which
619 (substring font (match-end 2)))) 642 (substring font (match-end x-font-regexp-slant-subnum)
620 ((string-match x-font-regexp-slant font) 643 (match-beginning x-font-regexp-adstyle-subnum))
644 ;; Replace the ADD_STYLE_NAME field with *
645 ;; because the info in it may not be the same
646 ;; for related fonts.
647 "*"
648 (substring font (match-end x-font-regexp-adstyle-subnum))))
649 ((or (string-match x-font-regexp-head font)
650 (string-match x-font-regexp-slant font))
621 (concat (substring font 0 (match-beginning 1)) which 651 (concat (substring font 0 (match-beginning 1)) which
622 (substring font (match-end 1)))) 652 (substring font (match-end 1))))))
623 (t nil)))
624
625 653
626(defun x-make-font-bold (font) 654(defun x-make-font-bold (font)
627 "Given an X font specification, make a bold version of it. 655 "Given an X font specification, make a bold version of it.
@@ -981,57 +1009,80 @@ selected frame."
981 (setq parameters (append parameters 1009 (setq parameters (append parameters
982 default-frame-alist 1010 default-frame-alist
983 parsed))))) 1011 parsed)))))
984 (if (null global-face-data) 1012 (let (frame)
985 (x-create-frame parameters) 1013 (if (null global-face-data)
986 (let* ((visibility-spec (assq 'visibility parameters)) 1014 (setq frame (x-create-frame parameters))
987 (frame (x-create-frame (cons '(visibility . nil) parameters))) 1015 (let* ((visibility-spec (assq 'visibility parameters))
988 (faces (copy-alist global-face-data)) 1016 (faces (copy-alist global-face-data))
989 success 1017 success
990 (rest faces)) 1018 (rest faces))
991 (unwind-protect 1019 (setq frame (x-create-frame (cons '(visibility . nil) parameters)))
992 (progn 1020 (unwind-protect
993 (set-frame-face-alist frame faces) 1021 (progn
994 1022 (set-frame-face-alist frame faces)
995 (if (cdr (or (assq 'reverse parameters) 1023
996 (assq 'reverse default-frame-alist) 1024 (if (cdr (or (assq 'reverse parameters)
997 (let ((resource (x-get-resource "reverseVideo" 1025 (assq 'reverse default-frame-alist)
998 "ReverseVideo"))) 1026 (let ((resource (x-get-resource "reverseVideo"
999 (if resource 1027 "ReverseVideo")))
1000 (cons nil (member (downcase resource) 1028 (if resource
1001 '("on" "true"))))))) 1029 (cons nil (member (downcase resource)
1002 (let* ((params (frame-parameters frame)) 1030 '("on" "true")))))))
1003 (bg (cdr (assq 'foreground-color params))) 1031 (let* ((params (frame-parameters frame))
1004 (fg (cdr (assq 'background-color params)))) 1032 (bg (cdr (assq 'foreground-color params)))
1005 (modify-frame-parameters frame 1033 (fg (cdr (assq 'background-color params))))
1006 (list (cons 'foreground-color fg) 1034 (modify-frame-parameters frame
1007 (cons 'background-color bg))) 1035 (list (cons 'foreground-color fg)
1008 (if (equal bg (cdr (assq 'border-color params))) 1036 (cons 'background-color bg)))
1009 (modify-frame-parameters frame 1037 (if (equal bg (cdr (assq 'border-color params)))
1010 (list (cons 'border-color fg)))) 1038 (modify-frame-parameters frame
1011 (if (equal bg (cdr (assq 'mouse-color params))) 1039 (list (cons 'border-color fg))))
1012 (modify-frame-parameters frame 1040 (if (equal bg (cdr (assq 'mouse-color params)))
1013 (list (cons 'mouse-color fg)))) 1041 (modify-frame-parameters frame
1014 (if (equal bg (cdr (assq 'cursor-color params))) 1042 (list (cons 'mouse-color fg))))
1015 (modify-frame-parameters frame 1043 (if (equal bg (cdr (assq 'cursor-color params)))
1016 (list (cons 'cursor-color fg)))))) 1044 (modify-frame-parameters frame
1017 ;; Copy the vectors that represent the faces. 1045 (list (cons 'cursor-color fg))))))
1018 ;; Also fill them in from X resources. 1046 ;; Copy the vectors that represent the faces.
1019 (while rest 1047 ;; Also fill them in from X resources.
1020 (let ((global (cdr (car rest)))) 1048 (while rest
1021 (setcdr (car rest) (vector 'face 1049 (let ((global (cdr (car rest))))
1022 (face-name (cdr (car rest))) 1050 (setcdr (car rest) (vector 'face
1023 (face-id (cdr (car rest))) 1051 (face-name (cdr (car rest)))
1024 nil nil nil nil nil)) 1052 (face-id (cdr (car rest)))
1025 (face-fill-in (car (car rest)) global frame)) 1053 nil nil nil nil nil))
1026 (make-face-x-resource-internal (cdr (car rest)) frame t) 1054 (face-fill-in (car (car rest)) global frame))
1027 (setq rest (cdr rest))) 1055 (make-face-x-resource-internal (cdr (car rest)) frame t)
1028 (if (null visibility-spec) 1056 (setq rest (cdr rest)))
1029 (make-frame-visible frame) 1057 (if (null visibility-spec)
1030 (modify-frame-parameters frame (list visibility-spec))) 1058 (make-frame-visible frame)
1031 (setq success t) 1059 (modify-frame-parameters frame (list visibility-spec)))
1032 frame) 1060 (setq success t))
1033 (or success 1061 (or success
1034 (delete-frame frame)))))) 1062 (delete-frame frame)))))
1063 ;; Set up the background-mode frame parameter
1064 ;; so that programs can decide good ways of highlighting
1065 ;; on this frame.
1066 (let ((bg-resource (x-get-resource ".backgroundMode"
1067 "BackgroundMode"))
1068 (params (frame-parameters))
1069 (bg-mode))
1070 (setq bg-mode
1071 (cond (bg-resource (intern (downcase bg-resource)))
1072 ((< (apply '+ (x-color-values
1073 (cdr (assq 'background-color params))))
1074 (/ (apply '+ (x-color-values "white")) 3))
1075 'dark)
1076 (t 'light)))
1077 (modify-frame-parameters frame
1078 (list (cons 'background-mode bg-mode)
1079 (cons 'display-type
1080 (cond ((x-display-color-p frame)
1081 'color)
1082 ((x-display-grayscale-p frame)
1083 'grayscale)
1084 (t 'mono))))))
1085 frame))
1035 1086
1036;; Update a frame's faces when we change its default font. 1087;; Update a frame's faces when we change its default font.
1037(defun frame-update-faces (frame) 1088(defun frame-update-faces (frame)
@@ -1125,18 +1176,12 @@ selected frame."
1125 (or (x-display-color-p frame) 1176 (or (x-display-color-p frame)
1126 ;; A black-and-white display can implement these. 1177 ;; A black-and-white display can implement these.
1127 (member color '("black" "white")) 1178 (member color '("black" "white"))
1128 ;; A black-and-white display can fake these for background. 1179 ;; A black-and-white display can fake gray for background.
1129 (and background-p 1180 (and background-p
1130 (member color '("gray" "gray1" "gray3"))) 1181 (face-color-gray-p color frame))
1131 ;; A grayscale display can implement colors that are gray (more or less). 1182 ;; A grayscale display can implement colors that are gray (more or less).
1132 (and (x-display-grayscale-p frame) 1183 (and (x-display-grayscale-p frame)
1133 (let* ((values (x-color-values color frame)) 1184 (face-color-gray-p color frame))))
1134 (r (nth 0 values))
1135 (g (nth 1 values))
1136 (b (nth 2 values)))
1137 (and (< (abs (- r g)) (/ (abs (+ r g)) 20))
1138 (< (abs (- g b)) (/ (abs (+ g b)) 20))
1139 (< (abs (- b r)) (/ (abs (+ b r)) 20)))))))
1140 1185
1141;; Use FUNCTION to store a color in FACE on FRAME. 1186;; Use FUNCTION to store a color in FACE on FRAME.
1142;; COLORS is either a single color or a list of colors. 1187;; COLORS is either a single color or a list of colors.