462
|
1 ;;; gtk-faces.el --- GTK-specific face frobnication, aka black magic.
|
|
2
|
|
3 ;; Copyright (C) 1992-4, 1997 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995, 1996 Ben Wing.
|
|
5 ;; Copyright (c) 2000 William Perry
|
|
6
|
|
7 ;; Author: William M. Perry <wmperry@gnu.org>
|
|
8 ;; Maintainer: XEmacs Development Team
|
|
9 ;; Keywords: extensions, internal, dumped
|
|
10
|
|
11 ;; This file is part of XEmacs.
|
|
12
|
|
13 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
14 ;; under the terms of the GNU General Public License as published by
|
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
|
18 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
21 ;; General Public License for more details.
|
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
|
24 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
26 ;; Boston, MA 02111-1307, USA.
|
|
27
|
|
28 ;;; Synched up with: Not synched.
|
|
29
|
|
30 ;;; Commentary:
|
|
31
|
|
32 ;; This file is dumped with XEmacs (when GTK support is compiled in).
|
|
33
|
502
|
34 (globally-declare-fboundp
|
|
35 '(gtk-init-pointers
|
|
36 gtk-font-selection-dialog-new
|
|
37 gtk-widget-set-sensitive gtk-font-selection-dialog-apply-button
|
|
38 gtk-signal-connect gtk-main-quit
|
|
39 gtk-font-selection-dialog-ok-button
|
|
40 gtk-font-selection-dialog-get-font-name gtk-widget-destroy
|
|
41 font-menu-set-font font-family font-size
|
|
42 gtk-font-selection-dialog-cancel-button gtk-widget-show-all
|
771
|
43 gtk-main gtk-style-info))
|
462
|
44
|
711
|
45 (eval-when-compile
|
|
46 (defmacro gtk-style-munge-face (face attribute value)
|
|
47 (let ((func (intern (format "face-%s" (eval attribute)))))
|
|
48 `(add-spec-to-specifier (,func ,face) ,value nil '(gtk default) 'prepend))))
|
462
|
49
|
|
50 ;;; gtk-init-device-faces is responsible for initializing default
|
|
51 ;;; values for faces on a newly created device.
|
|
52 ;;;
|
|
53 (defun gtk-init-device-faces (device)
|
|
54 ;;
|
|
55 ;; If the "default" face didn't have a font specified, try to pick one.
|
|
56 ;;
|
711
|
57 (when (eq (device-type device) 'gtk)
|
707
|
58 (let* ((style (gtk-style-info device))
|
711
|
59 (normal 0) ; GTK_STATE_NORMAL
|
462
|
60 ;;(active 1) ; GTK_STATE_ACTIVE
|
|
61 (prelight 2) ; GTK_STATE_PRELIGHT
|
|
62 (selected 3) ; GTK_STATE_SELECTED
|
|
63 ;;(insensitive 4) ; GTK_STATE_INSENSITIVE
|
|
64 )
|
711
|
65 (gtk-style-munge-face 'highlight 'foreground
|
|
66 (nth prelight (plist-get style 'text)))
|
|
67 (gtk-style-munge-face 'highlight 'background
|
|
68 (nth prelight (plist-get style 'background)))
|
|
69 (gtk-style-munge-face 'zmacs-region 'foreground
|
|
70 (nth selected (plist-get style 'text)))
|
|
71 (gtk-style-munge-face 'zmacs-region 'background
|
|
72 (nth selected (plist-get style 'background)))
|
|
73 (gtk-style-munge-face 'toolbar 'background
|
|
74 (nth normal (plist-get style 'base)))
|
|
75 (gtk-style-munge-face 'toolbar 'foreground
|
|
76 (nth normal (plist-get style 'text)))
|
|
77 (set-face-background 'modeline [toolbar background] '(gtk default))
|
|
78 (set-face-foreground 'modeline [toolbar foreground] '(gtk default))
|
|
79 )
|
|
80 (gtk-init-pointers)))
|
462
|
81
|
|
82 ;;; This is called from `init-frame-faces', which is called from
|
|
83 ;;; init_frame_faces() which is called from Fmake_frame(), to perform
|
|
84 ;;; any device-specific initialization.
|
|
85 ;;;
|
|
86 (defun gtk-init-frame-faces (frame)
|
|
87 )
|
|
88
|
|
89 (defun gtk-init-global-faces ()
|
872
|
90 )
|
462
|
91
|
|
92
|
|
93 ;;; Lots of this stolen from x-faces.el - I'm not sure if this will
|
|
94 ;;; require a rewrite for win32 or not?
|
|
95 (defconst gtk-font-regexp nil)
|
|
96 (defconst gtk-font-regexp-head nil)
|
|
97 (defconst gtk-font-regexp-head-2 nil)
|
|
98 (defconst gtk-font-regexp-weight nil)
|
|
99 (defconst gtk-font-regexp-slant nil)
|
|
100 (defconst gtk-font-regexp-pixel nil)
|
|
101 (defconst gtk-font-regexp-point nil)
|
|
102 (defconst gtk-font-regexp-foundry-and-family nil)
|
|
103 (defconst gtk-font-regexp-registry-and-encoding nil)
|
|
104 (defconst gtk-font-regexp-spacing nil)
|
|
105
|
|
106 ;;; Regexps matching font names in "Host Portable Character Representation."
|
|
107 ;;;
|
|
108 (let ((- "[-?]")
|
|
109 (foundry "[^-]*")
|
|
110 (family "[^-]*")
|
|
111 (weight "\\(bold\\|demibold\\|medium\\|black\\)") ; 1
|
|
112 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
|
|
113 (weight\? "\\([^-]*\\)") ; 1
|
|
114 (slant "\\([ior]\\)") ; 2
|
|
115 ; (slant\? "\\([ior?*]?\\)") ; 2
|
|
116 (slant\? "\\([^-]?\\)") ; 2
|
|
117 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
|
|
118 (swidth "\\([^-]*\\)") ; 3
|
|
119 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
|
|
120 (adstyle "\\([^-]*\\)") ; 4
|
|
121 (pixelsize "\\(\\*\\|[0-9]+\\)") ; 5
|
|
122 (pointsize "\\(\\*\\|0\\|[0-9][0-9]+\\)") ; 6
|
|
123 ; (resx "\\(\\*\\|[0-9][0-9]+\\)") ; 7
|
|
124 ; (resy "\\(\\*\\|[0-9][0-9]+\\)") ; 8
|
|
125 (resx "\\([*0]\\|[0-9][0-9]+\\)") ; 7
|
|
126 (resy "\\([*0]\\|[0-9][0-9]+\\)") ; 8
|
|
127 (spacing "[cmp?*]")
|
|
128 (avgwidth "\\(\\*\\|[0-9]+\\)") ; 9
|
|
129 (registry "[^-]*") ; some fonts have omitted registries
|
|
130 ; (encoding ".+") ; note that encoding may contain "-"...
|
|
131 (encoding "[^-]+") ; false!
|
|
132 )
|
|
133 (setq gtk-font-regexp
|
|
134 (purecopy
|
|
135 (concat "\\`\\*?[-?*]"
|
|
136 foundry - family - weight\? - slant\? - swidth - adstyle -
|
|
137 pixelsize - pointsize - resx - resy - spacing - avgwidth -
|
|
138 registry - encoding "\\'"
|
|
139 )))
|
|
140 (setq gtk-font-regexp-head
|
|
141 (purecopy
|
|
142 (concat "\\`[-?*]" foundry - family - weight\? - slant\?
|
|
143 "\\([-*?]\\|\\'\\)")))
|
|
144 (setq gtk-font-regexp-head-2
|
|
145 (purecopy
|
|
146 (concat "\\`[-?*]" foundry - family - weight\? - slant\?
|
|
147 - swidth - adstyle - pixelsize - pointsize
|
|
148 "\\([-*?]\\|\\'\\)")))
|
|
149 (setq gtk-font-regexp-slant (purecopy (concat - slant -)))
|
|
150 (setq gtk-font-regexp-weight (purecopy (concat - weight -)))
|
|
151 ;; if we can't match any of the more specific regexps (unfortunate) then
|
|
152 ;; look for digits; assume 2+ digits is 10ths of points, and 1-2 digits
|
|
153 ;; is pixels. Bogus as hell.
|
|
154 (setq gtk-font-regexp-pixel (purecopy "[-?*]\\([0-9][0-9]?\\)[-?*]"))
|
|
155 (setq gtk-font-regexp-point (purecopy "[-?*]\\([0-9][0-9]+\\)[-?*]"))
|
|
156 ;; the following two are used by x-font-menu.el.
|
|
157 (setq gtk-font-regexp-foundry-and-family
|
|
158 (purecopy (concat "\\`[-?*]" foundry - "\\(" family "\\)" -)))
|
|
159 (setq gtk-font-regexp-registry-and-encoding
|
|
160 (purecopy (concat - "\\(" registry "\\)" - "\\(" encoding "\\)\\'")))
|
|
161 (setq gtk-font-regexp-spacing
|
|
162 (purecopy (concat - "\\(" spacing "\\)" - avgwidth
|
|
163 - registry - encoding "\\'")))
|
|
164 )
|
|
165
|
|
166 (defvaralias 'x-font-regexp 'gtk-font-regexp)
|
|
167 (defvaralias 'x-font-regexp-head 'gtk-font-regexp-head)
|
|
168 (defvaralias 'x-font-regexp-head-2 'gtk-font-regexp-head-2)
|
|
169 (defvaralias 'x-font-regexp-weight 'gtk-font-regexp-weight)
|
|
170 (defvaralias 'x-font-regexp-slant 'gtk-font-regexp-slant)
|
|
171 (defvaralias 'x-font-regexp-pixel 'gtk-font-regexp-pixel)
|
|
172 (defvaralias 'x-font-regexp-point 'gtk-font-regexp-point)
|
|
173 (defvaralias 'x-font-regexp-foundry-and-family 'gtk-font-regexp-foundry-and-family)
|
|
174 (defvaralias 'x-font-regexp-registry-and-encoding 'gtk-font-regexp-registry-and-encoding)
|
|
175 (defvaralias 'x-font-regexp-spacing 'gtk-font-regexp-spacing)
|
|
176
|
|
177 (defun gtk-frob-font-weight (font which)
|
|
178 (if (font-instance-p font) (setq font (font-instance-name font)))
|
|
179 (cond ((null font) nil)
|
|
180 ((or (string-match gtk-font-regexp font)
|
|
181 (string-match gtk-font-regexp-head font)
|
|
182 (string-match gtk-font-regexp-weight font))
|
|
183 (concat (substring font 0 (match-beginning 1)) which
|
|
184 (substring font (match-end 1))))
|
|
185 (t nil)))
|
|
186
|
|
187 (defun gtk-frob-font-slant (font which)
|
|
188 (if (font-instance-p font) (setq font (font-instance-name font)))
|
|
189 (cond ((null font) nil)
|
|
190 ((or (string-match gtk-font-regexp font)
|
|
191 (string-match gtk-font-regexp-head font))
|
|
192 (concat (substring font 0 (match-beginning 2)) which
|
|
193 (substring font (match-end 2))))
|
|
194 ((string-match gtk-font-regexp-slant font)
|
|
195 (concat (substring font 0 (match-beginning 1)) which
|
|
196 (substring font (match-end 1))))
|
|
197 (t nil)))
|
|
198
|
|
199 (defun gtk-make-font-bold (font &optional device)
|
|
200 (or (try-font-name (gtk-frob-font-weight font "bold") device)
|
|
201 (try-font-name (gtk-frob-font-weight font "black") device)
|
|
202 (try-font-name (gtk-frob-font-weight font "demibold") device)))
|
|
203
|
|
204 (defun gtk-make-font-unbold (font &optional device)
|
|
205 (try-font-name (gtk-frob-font-weight font "medium") device))
|
|
206
|
776
|
207 (defcustom try-oblique-before-italic-fonts t
|
462
|
208 "*If nil, italic fonts are searched before oblique fonts.
|
|
209 If non-nil, oblique fonts are tried before italic fonts. This is mostly
|
|
210 applicable to adobe-courier fonts"
|
|
211 :type 'boolean
|
|
212 :tag "Try Oblique Before Italic Fonts"
|
|
213 :group 'x)
|
776
|
214 (define-obsolete-variable-alias '*try-oblique-before-italic-fonts*
|
|
215 'try-oblique-before-italic-fonts)
|
462
|
216
|
|
217 (defun gtk-make-font-italic (font &optional device)
|
776
|
218 (if try-oblique-before-italic-fonts
|
462
|
219 (or (try-font-name (gtk-frob-font-slant font "o") device)
|
|
220 (try-font-name (gtk-frob-font-slant font "i") device))
|
|
221 (or (try-font-name (gtk-frob-font-slant font "i") device)
|
|
222 (try-font-name (gtk-frob-font-slant font "o") device))))
|
|
223
|
|
224 (defun gtk-make-font-unitalic (font &optional device)
|
|
225 (try-font-name (gtk-frob-font-slant font "r") device))
|
|
226
|
|
227 (defun gtk-make-font-bold-italic (font &optional device)
|
776
|
228 (if try-oblique-before-italic-fonts
|
462
|
229 (or (try-font-name
|
|
230 (gtk-frob-font-slant (gtk-frob-font-weight font "bold") "o") device)
|
|
231 (try-font-name
|
|
232 (gtk-frob-font-slant (gtk-frob-font-weight font "bold") "i") device)
|
|
233 (try-font-name
|
|
234 (gtk-frob-font-slant (gtk-frob-font-weight font "black") "o") device)
|
|
235 (try-font-name
|
|
236 (gtk-frob-font-slant (gtk-frob-font-weight font "black") "i") device)
|
|
237 (try-font-name
|
|
238 (gtk-frob-font-slant (gtk-frob-font-weight font "demibold") "o") device)
|
|
239 (try-font-name
|
|
240 (gtk-frob-font-slant (gtk-frob-font-weight font "demibold") "i") device))
|
|
241 (or (try-font-name
|
|
242 (gtk-frob-font-slant (gtk-frob-font-weight font "bold") "i") device)
|
|
243 (try-font-name
|
|
244 (gtk-frob-font-slant (gtk-frob-font-weight font "bold") "o") device)
|
|
245 (try-font-name
|
|
246 (gtk-frob-font-slant (gtk-frob-font-weight font "black") "i") device)
|
|
247 (try-font-name
|
|
248 (gtk-frob-font-slant (gtk-frob-font-weight font "black") "o") device)
|
|
249 (try-font-name
|
|
250 (gtk-frob-font-slant (gtk-frob-font-weight font "demibold") "i") device)
|
|
251 (try-font-name
|
|
252 (gtk-frob-font-slant (gtk-frob-font-weight font "demibold") "o") device))))
|
|
253
|
|
254 (defun gtk-choose-font ()
|
|
255 (interactive)
|
|
256 (require 'x-font-menu)
|
|
257 (require 'font)
|
|
258 (let ((locale (if font-menu-this-frame-only-p
|
|
259 (selected-frame)
|
|
260 nil))
|
|
261 (dialog nil))
|
|
262 (setq dialog (gtk-font-selection-dialog-new "Choose default font..."))
|
|
263 (put dialog 'modal t)
|
|
264 (put dialog 'type 'dialog)
|
|
265
|
|
266 (gtk-widget-set-sensitive (gtk-font-selection-dialog-apply-button dialog) nil)
|
|
267 (gtk-signal-connect dialog 'destroy (lambda (&rest ignored) (gtk-main-quit)))
|
|
268 (gtk-signal-connect (gtk-font-selection-dialog-ok-button dialog)
|
|
269 'clicked
|
|
270 (lambda (button data)
|
|
271 (let* ((dialog (car data))
|
|
272 (font (font-create-object
|
|
273 (gtk-font-selection-dialog-get-font-name dialog))))
|
|
274 (gtk-widget-destroy dialog)
|
|
275 (font-menu-set-font (car (font-family font)) nil (* 10 (font-size font)))))
|
|
276 (cons dialog locale))
|
|
277 (gtk-signal-connect (gtk-font-selection-dialog-cancel-button dialog)
|
|
278 'clicked
|
|
279 (lambda (button dialog)
|
|
280 (gtk-widget-destroy dialog)) dialog)
|
|
281
|
|
282 (gtk-widget-show-all dialog)
|
|
283 (gtk-main)))
|