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)
|
|
35 (or (face-font 'default 'global)
|
|
36 (set-face-font 'default "Courier New:Regular:10")
|
|
37 'global)
|
|
38 (or (face-foreground 'default 'global)
|
|
39 (set-face-foreground 'default "black" 'global 'mswindows))
|
|
40 (or (face-background 'default 'global)
|
|
41 (set-face-background 'default "white" 'global 'mswindows))
|
|
42 (or (face-background 'modeline 'global)
|
|
43 (set-face-background 'modeline "grey75" 'global 'mswindows))
|
|
44 )
|
|
45
|
|
46
|
|
47 (defun mswindows-init-frame-faces (frame)
|
|
48 )
|
|
49
|
|
50
|
|
51 ;;; Fill in missing parts of a font spec. This is primarily intended as a
|
|
52 ;;; helper function for the functions below.
|
|
53 ;;; mswindows fonts look like:
|
215
|
54 ;;; fontname[:[weight][ style][:pointsize[:effects[:charset]]]]
|
213
|
55 ;;; A minimal mswindows font spec looks like:
|
|
56 ;;; Courier New
|
|
57 ;;; A maximal mswindows font spec looks like:
|
|
58 ;;; Courier New:Bold Italic:10:underline strikeout:ansi
|
|
59 ;;; Missing parts of the font spec should be filled in with these values:
|
|
60 ;;; Courier New:Normal:10::ansi
|
282
|
61 (defun mswindows-font-canonicalize-name (font)
|
|
62 "Given a mswindows font or font specification, this returns its
|
|
63 specification in canonical form."
|
280
|
64 (if (or (font-instance-p font)
|
|
65 (stringp font))
|
|
66 (let ((name (if (font-instance-p font)
|
|
67 (font-instance-name font)
|
|
68 font)))
|
|
69 (cond ((string-match
|
|
70 "^[a-zA-Z ]+:[a-zA-Z ]*:[0-9]+:[a-zA-Z ]*:[a-zA-Z 0-9]*$"
|
|
71 name) name)
|
|
72 ((string-match "^[a-zA-Z ]+:[a-zA-Z ]*:[0-9]+:[a-zA-Z ]*$"
|
|
73 name) (concat name ":ansi"))
|
|
74 ((string-match "^[a-zA-Z ]+:[a-zA-Z ]*:[0-9]+$" name)
|
|
75 (concat name "::ansi"))
|
|
76 ((string-match "^[a-zA-Z ]+:[a-zA-Z ]*$" name)
|
|
77 (concat name ":10::ansi"))
|
|
78 ((string-match "^[a-zA-Z ]+$" name)
|
|
79 (concat name ":Normal:10::ansi"))
|
|
80 (t "Courier New:Normal:10::ansi")))))
|
213
|
81
|
|
82 (defun mswindows-make-font-bold (font &optional device)
|
|
83 "Given a mswindows font specification, this attempts to make a bold font.
|
|
84 If it fails, it returns nil."
|
215
|
85 (if (font-instance-p font)
|
282
|
86 (let ((name (mswindows-font-canonicalize-name font))
|
221
|
87 (oldwidth (font-instance-width font)))
|
215
|
88 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
221
|
89 (let ((newfont (make-font-instance
|
|
90 (concat (substring name 0 (match-beginning 1))
|
|
91 "Bold" (substring name (match-end 1)))
|
|
92 device t)))
|
|
93 ; Hack! on mswindows, bold fonts (even monospaced) are often wider than the
|
|
94 ; equivalent non-bold font. Making the bold font one point smaller usually
|
|
95 ; makes it the same width (maybe at the expense of making it one pixel shorter)
|
|
96 (if (font-instance-p newfont)
|
|
97 (if (> (font-instance-width newfont) oldwidth)
|
|
98 (mswindows-find-smaller-font newfont)
|
|
99 newfont))))))
|
213
|
100
|
|
101 (defun mswindows-make-font-unbold (font &optional device)
|
|
102 "Given a mswindows font specification, this attempts to make a non-bold font.
|
|
103 If it fails, it returns nil."
|
215
|
104 (if (font-instance-p font)
|
282
|
105 (let ((name (mswindows-font-canonicalize-name font)))
|
215
|
106 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
|
107 (make-font-instance (concat
|
|
108 (substring name 0 (match-beginning 1))
|
|
109 "Normal" (substring name (match-end 1)))
|
|
110 device t))))
|
213
|
111
|
|
112 (defun mswindows-make-font-italic (font &optional device)
|
215
|
113 "Given a mswindows font specification, this attempts to make an `italic'
|
|
114 font. If it fails, it returns nil."
|
|
115 (if (font-instance-p font)
|
282
|
116 (let ((name (mswindows-font-canonicalize-name font)))
|
215
|
117 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
|
118 (make-font-instance (concat
|
|
119 (substring name 0 (match-beginning 1))
|
|
120 "Italic" (substring name (match-end 1)))
|
|
121 device t))))
|
213
|
122
|
|
123 (defun mswindows-make-font-unitalic (font &optional device)
|
215
|
124 "Given a mswindows font specification, this attempts to make a non-italic
|
|
125 font. If it fails, it returns nil."
|
|
126 (if (font-instance-p font)
|
282
|
127 (let ((name (mswindows-font-canonicalize-name font)))
|
215
|
128 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
|
129 (make-font-instance (concat
|
|
130 (substring name 0 (match-beginning 1))
|
|
131 "Normal" (substring name (match-end 1)))
|
|
132 device t))))
|
213
|
133
|
|
134 (defun mswindows-make-font-bold-italic (font &optional device)
|
|
135 "Given a mswindows font specification, this attempts to make a `bold-italic'
|
|
136 font. If it fails, it returns nil."
|
215
|
137 (if (font-instance-p font)
|
282
|
138 (let ((name (mswindows-font-canonicalize-name font))
|
221
|
139 (oldwidth (font-instance-width font)))
|
215
|
140 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
221
|
141 (let ((newfont (make-font-instance
|
|
142 (concat (substring name 0 (match-beginning 1))
|
|
143 "Bold Italic" (substring name (match-end 1)))
|
|
144 device t)))
|
|
145 ; Hack! on mswindows, bold fonts (even monospaced) are often wider than the
|
|
146 ; equivalent non-bold font. Making the bold font one point smaller usually
|
|
147 ; makes it the same width (maybe at the expense of making it one pixel shorter)
|
|
148 (if (font-instance-p newfont)
|
|
149 (if (> (font-instance-width newfont) oldwidth)
|
|
150 (mswindows-find-smaller-font newfont)
|
|
151 newfont))))))
|
213
|
152
|
|
153 (defun mswindows-find-smaller-font (font &optional device)
|
221
|
154 "Loads a new version of the given font (or font name) 1 point smaller.
|
|
155 Returns the font if it succeeds, nil otherwise."
|
215
|
156 (if (font-instance-p font)
|
282
|
157 (let (old-size (name (mswindows-font-canonicalize-name font)))
|
215
|
158 (string-match "^[a-zA-Z ]+:[a-zA-Z ]*:\\([0-9]+\\):" name)
|
|
159 (setq old-size (string-to-int
|
|
160 (substring name (match-beginning 1) (match-end 1))))
|
|
161 (if (> old-size 0)
|
|
162 (make-font-instance (concat
|
|
163 (substring name 0 (match-beginning 1))
|
|
164 (int-to-string (- old-size 1))
|
|
165 (substring name (match-end 1)))
|
|
166 device t)))))
|
213
|
167
|
|
168 (defun mswindows-find-larger-font (font &optional device)
|
221
|
169 "Loads a new version of the given font (or font name) 1 point larger.
|
|
170 Returns the font if it succeeds, nil otherwise."
|
215
|
171 (if (font-instance-p font)
|
282
|
172 (let (old-size (name (mswindows-font-canonicalize-name font)))
|
215
|
173 (string-match "^[a-zA-Z ]+:[a-zA-Z ]*:\\([0-9]+\\):" name)
|
|
174 (setq old-size (string-to-int
|
|
175 (substring name (match-beginning 1) (match-end 1))))
|
|
176 (make-font-instance (concat
|
|
177 (substring name 0 (match-beginning 1))
|
|
178 (int-to-string (+ old-size 1))
|
|
179 (substring name (match-end 1)))
|
|
180 device t))))
|