213
|
1 ;;; msw-faces.el --- mswindows-specific face stuff.
|
|
2
|
|
3 ;;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
4 ;;; Copyright (C) 1995, 1996 Ben Wing.
|
|
5
|
|
6 ;; Author: Jamie Zawinski
|
|
7 ;; Modified by: Chuck Thompson
|
|
8 ;; Modified by: Ben Wing
|
|
9 ;; Modified by: Martin Buchholz
|
|
10 ;; Rewritten for mswindows by: Jonathan Harris
|
|
11
|
|
12 ;; This file is part of XEmacs.
|
|
13
|
|
14 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
15 ;; under the terms of the GNU General Public License as published by
|
|
16 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
17 ;; any later version.
|
|
18
|
|
19 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
22 ;; General Public License for more details.
|
|
23
|
|
24 ;; You should have received a copy of the GNU General Public License
|
|
25 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
27 ;; Boston, MA 02111-1307, USA.
|
|
28
|
|
29 ;; This file does the magic to parse mswindows font names, and make sure that the
|
|
30 ;; default and modeline attributes of new frames are specified enough.
|
|
31
|
|
32 ;;; ensure that the default face has some reasonable fallbacks if nothing
|
|
33 ;;; else is specified.
|
|
34 (defun mswindows-init-device-faces (device)
|
288
|
35 (set-face-font 'default
|
|
36 '((mswindows default) . "Courier New:Regular:10") 'global)
|
290
|
37 ;; gui elements
|
|
38 (set-face-foreground 'gui-element '((mswindows default) . "Black") 'global)
|
|
39 (set-face-background 'gui-element '((mswindows default) . "Gray75") 'global)
|
288
|
40 (set-face-foreground 'default '((mswindows default) . "black") 'global)
|
|
41 (set-face-background 'default '((mswindows default) . "white") 'global)
|
213
|
42 )
|
|
43
|
|
44
|
|
45 (defun mswindows-init-frame-faces (frame)
|
|
46 )
|
|
47
|
|
48
|
|
49 ;;; Fill in missing parts of a font spec. This is primarily intended as a
|
|
50 ;;; helper function for the functions below.
|
|
51 ;;; mswindows fonts look like:
|
294
|
52 ;;; fontname[:[weight][ style][:pointsize[:effects]]][:charset]
|
213
|
53 ;;; A minimal mswindows font spec looks like:
|
|
54 ;;; Courier New
|
|
55 ;;; A maximal mswindows font spec looks like:
|
294
|
56 ;;; Courier New:Bold Italic:10:underline strikeout:western
|
213
|
57 ;;; Missing parts of the font spec should be filled in with these values:
|
294
|
58 ;;; Courier New:Normal:10::western
|
282
|
59 (defun mswindows-font-canonicalize-name (font)
|
|
60 "Given a mswindows font or font specification, this returns its
|
|
61 specification in canonical form."
|
280
|
62 (if (or (font-instance-p font)
|
|
63 (stringp font))
|
|
64 (let ((name (if (font-instance-p font)
|
|
65 (font-instance-name font)
|
|
66 font)))
|
|
67 (cond ((string-match
|
|
68 "^[a-zA-Z ]+:[a-zA-Z ]*:[0-9]+:[a-zA-Z ]*:[a-zA-Z 0-9]*$"
|
|
69 name) name)
|
|
70 ((string-match "^[a-zA-Z ]+:[a-zA-Z ]*:[0-9]+:[a-zA-Z ]*$"
|
294
|
71 name) (concat name ":western"))
|
280
|
72 ((string-match "^[a-zA-Z ]+:[a-zA-Z ]*:[0-9]+$" name)
|
294
|
73 (concat name "::western"))
|
280
|
74 ((string-match "^[a-zA-Z ]+:[a-zA-Z ]*$" name)
|
294
|
75 (concat name ":10::western"))
|
280
|
76 ((string-match "^[a-zA-Z ]+$" name)
|
294
|
77 (concat name ":Normal:10::western"))
|
|
78 (t "Courier New:Normal:10::western")))))
|
213
|
79
|
|
80 (defun mswindows-make-font-bold (font &optional device)
|
|
81 "Given a mswindows font specification, this attempts to make a bold font.
|
|
82 If it fails, it returns nil."
|
215
|
83 (if (font-instance-p font)
|
282
|
84 (let ((name (mswindows-font-canonicalize-name font))
|
221
|
85 (oldwidth (font-instance-width font)))
|
215
|
86 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
221
|
87 (let ((newfont (make-font-instance
|
|
88 (concat (substring name 0 (match-beginning 1))
|
|
89 "Bold" (substring name (match-end 1)))
|
|
90 device t)))
|
|
91 ; Hack! on mswindows, bold fonts (even monospaced) are often wider than the
|
|
92 ; equivalent non-bold font. Making the bold font one point smaller usually
|
|
93 ; makes it the same width (maybe at the expense of making it one pixel shorter)
|
|
94 (if (font-instance-p newfont)
|
|
95 (if (> (font-instance-width newfont) oldwidth)
|
|
96 (mswindows-find-smaller-font newfont)
|
|
97 newfont))))))
|
213
|
98
|
|
99 (defun mswindows-make-font-unbold (font &optional device)
|
|
100 "Given a mswindows font specification, this attempts to make a non-bold font.
|
|
101 If it fails, it returns nil."
|
215
|
102 (if (font-instance-p font)
|
282
|
103 (let ((name (mswindows-font-canonicalize-name font)))
|
215
|
104 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
|
105 (make-font-instance (concat
|
|
106 (substring name 0 (match-beginning 1))
|
|
107 "Normal" (substring name (match-end 1)))
|
|
108 device t))))
|
213
|
109
|
|
110 (defun mswindows-make-font-italic (font &optional device)
|
215
|
111 "Given a mswindows font specification, this attempts to make an `italic'
|
|
112 font. If it fails, it returns nil."
|
|
113 (if (font-instance-p font)
|
282
|
114 (let ((name (mswindows-font-canonicalize-name font)))
|
215
|
115 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
|
116 (make-font-instance (concat
|
|
117 (substring name 0 (match-beginning 1))
|
|
118 "Italic" (substring name (match-end 1)))
|
|
119 device t))))
|
213
|
120
|
|
121 (defun mswindows-make-font-unitalic (font &optional device)
|
215
|
122 "Given a mswindows font specification, this attempts to make a non-italic
|
|
123 font. If it fails, it returns nil."
|
|
124 (if (font-instance-p font)
|
282
|
125 (let ((name (mswindows-font-canonicalize-name font)))
|
215
|
126 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
|
127 (make-font-instance (concat
|
|
128 (substring name 0 (match-beginning 1))
|
|
129 "Normal" (substring name (match-end 1)))
|
|
130 device t))))
|
213
|
131
|
|
132 (defun mswindows-make-font-bold-italic (font &optional device)
|
|
133 "Given a mswindows font specification, this attempts to make a `bold-italic'
|
|
134 font. If it fails, it returns nil."
|
215
|
135 (if (font-instance-p font)
|
282
|
136 (let ((name (mswindows-font-canonicalize-name font))
|
221
|
137 (oldwidth (font-instance-width font)))
|
215
|
138 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
221
|
139 (let ((newfont (make-font-instance
|
|
140 (concat (substring name 0 (match-beginning 1))
|
|
141 "Bold Italic" (substring name (match-end 1)))
|
|
142 device t)))
|
|
143 ; Hack! on mswindows, bold fonts (even monospaced) are often wider than the
|
|
144 ; equivalent non-bold font. Making the bold font one point smaller usually
|
|
145 ; makes it the same width (maybe at the expense of making it one pixel shorter)
|
|
146 (if (font-instance-p newfont)
|
|
147 (if (> (font-instance-width newfont) oldwidth)
|
|
148 (mswindows-find-smaller-font newfont)
|
|
149 newfont))))))
|
213
|
150
|
|
151 (defun mswindows-find-smaller-font (font &optional device)
|
221
|
152 "Loads a new version of the given font (or font name) 1 point smaller.
|
|
153 Returns the font if it succeeds, nil otherwise."
|
215
|
154 (if (font-instance-p font)
|
282
|
155 (let (old-size (name (mswindows-font-canonicalize-name font)))
|
215
|
156 (string-match "^[a-zA-Z ]+:[a-zA-Z ]*:\\([0-9]+\\):" name)
|
|
157 (setq old-size (string-to-int
|
|
158 (substring name (match-beginning 1) (match-end 1))))
|
|
159 (if (> old-size 0)
|
|
160 (make-font-instance (concat
|
|
161 (substring name 0 (match-beginning 1))
|
|
162 (int-to-string (- old-size 1))
|
|
163 (substring name (match-end 1)))
|
|
164 device t)))))
|
213
|
165
|
|
166 (defun mswindows-find-larger-font (font &optional device)
|
221
|
167 "Loads a new version of the given font (or font name) 1 point larger.
|
|
168 Returns the font if it succeeds, nil otherwise."
|
215
|
169 (if (font-instance-p font)
|
282
|
170 (let (old-size (name (mswindows-font-canonicalize-name font)))
|
215
|
171 (string-match "^[a-zA-Z ]+:[a-zA-Z ]*:\\([0-9]+\\):" name)
|
|
172 (setq old-size (string-to-int
|
|
173 (substring name (match-beginning 1) (match-end 1))))
|
|
174 (make-font-instance (concat
|
|
175 (substring name 0 (match-beginning 1))
|
|
176 (int-to-string (+ old-size 1))
|
|
177 (substring name (match-end 1)))
|
|
178 device t))))
|