428
|
1 ;;; msw-faces.el --- mswindows-specific face stuff.
|
|
2
|
|
3 ;;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
|
793
|
4 ;;; Copyright (C) 1995, 1996, 2002 Ben Wing.
|
428
|
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
|
|
30 ;; the default and modeline attributes of new frames are specified enough.
|
|
31
|
793
|
32 (set-face-font 'gui-element "MS Sans Serif:Regular:8" nil 'mswindows)
|
|
33
|
428
|
34 (defun mswindows-init-device-faces (device)
|
442
|
35 (let ((color-default (device-system-metric device 'color-default))
|
|
36 (color-3d-face (device-system-metric device 'color-3d-face)))
|
|
37 ; Force creation of the default face font so that if it fails we get
|
|
38 ; an error now instead of a crash at frame creation.
|
|
39 (unless (face-font-instance 'default device)
|
|
40 (error "Can't find a suitable default font"))
|
|
41
|
|
42 (if (car color-default)
|
|
43 (set-face-foreground 'default (car color-default)) device)
|
|
44 (if (cdr color-default)
|
|
45 (set-face-background 'default (cdr color-default)) device)
|
|
46 (if (car color-3d-face)
|
|
47 (set-face-foreground 'gui-element (car color-3d-face)) device)
|
|
48 (if (cdr color-3d-face)
|
|
49 (set-face-background 'gui-element (cdr color-3d-face)) device)
|
793
|
50 ))
|
428
|
51
|
|
52 (defun mswindows-init-frame-faces (frame)
|
|
53 )
|
|
54
|
|
55 ;; Other functions expect these regexps
|
|
56 (defconst mswindows-font-regexp
|
|
57 (let
|
|
58 ((- ":")
|
|
59 (fontname "\\([a-zA-Z ]+\\)")
|
|
60 (weight "\\([a-zA-Z]*\\)?")
|
|
61 (style "\\( [a-zA-Z]*\\)?")
|
|
62 (pointsize "\\([0-9]+\\)?")
|
|
63 (effects "\\([a-zA-Z ]*\\)?")
|
|
64 (charset "\\([a-zA-Z 0-9]*\\)")
|
|
65 )
|
|
66 (concat "^"
|
|
67 fontname - weight style - pointsize - effects - charset "$")))
|
|
68
|
|
69 ;;; Fill in missing parts of a font spec. This is primarily intended as a
|
|
70 ;;; helper function for the functions below.
|
|
71 ;;; mswindows fonts look like:
|
|
72 ;;; fontname[:[weight][ style][:pointsize[:effects]]][:charset]
|
|
73 ;;; A minimal mswindows font spec looks like:
|
|
74 ;;; Courier New
|
|
75 ;;; A maximal mswindows font spec looks like:
|
|
76 ;;; Courier New:Bold Italic:10:underline strikeout:Western
|
|
77 ;;; Missing parts of the font spec should be filled in with these values:
|
|
78 ;;; Courier New:Regular:10::Western
|
|
79 (defun mswindows-font-canonicalize-name (font)
|
|
80 "Given a mswindows font or font name, this returns its name in
|
|
81 canonical form."
|
|
82 (if (or (font-instance-p font)
|
|
83 (stringp font))
|
|
84 (let ((name (if (font-instance-p font)
|
|
85 (font-instance-name font)
|
|
86 font)))
|
|
87 (cond ((string-match
|
|
88 "^[a-zA-Z ]+:[a-zA-Z ]*:[0-9]+:[a-zA-Z ]*:[a-zA-Z 0-9]*$"
|
|
89 name) name)
|
|
90 ((string-match "^[a-zA-Z ]+:[a-zA-Z ]*:[0-9]+:[a-zA-Z ]*$"
|
|
91 name) (concat name ":Western"))
|
|
92 ((string-match "^[a-zA-Z ]+:[a-zA-Z ]*:[0-9]+$" name)
|
|
93 (concat name "::Western"))
|
|
94 ((string-match "^[a-zA-Z ]+:[a-zA-Z ]*$" name)
|
|
95 (concat name ":10::Western"))
|
|
96 ((string-match "^[a-zA-Z ]+$" name)
|
|
97 (concat name ":Regular:10::Western"))
|
|
98 (t "Courier New:Regular:10::Western")))))
|
|
99
|
|
100 (defun mswindows-make-font-bold (font &optional device)
|
|
101 "Given a mswindows font specification, this attempts to make a bold font.
|
|
102 If it fails, it returns nil."
|
|
103 (if (font-instance-p font)
|
|
104 (let ((name (mswindows-font-canonicalize-name font))
|
|
105 (oldwidth (font-instance-width font)))
|
|
106 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
|
107 (let ((newfont (make-font-instance
|
|
108 (concat (substring name 0 (match-beginning 1))
|
|
109 "Bold" (substring name (match-end 1)))
|
|
110 device t)))
|
|
111 ; Hack! on mswindows, bold fonts (even monospaced) are often wider than the
|
|
112 ; equivalent non-bold font. Making the bold font one point smaller usually
|
|
113 ; makes it the same width (maybe at the expense of making it one pixel shorter)
|
|
114 (if (font-instance-p newfont)
|
|
115 (if (> (font-instance-width newfont) oldwidth)
|
|
116 (mswindows-find-smaller-font newfont device)
|
|
117 newfont))))))
|
|
118
|
|
119 (defun mswindows-make-font-unbold (font &optional device)
|
|
120 "Given a mswindows font specification, this attempts to make a non-bold font.
|
|
121 If it fails, it returns nil."
|
|
122 (if (font-instance-p font)
|
|
123 (let ((name (mswindows-font-canonicalize-name font)))
|
|
124 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
|
125 (make-font-instance (concat
|
|
126 (substring name 0 (match-beginning 1))
|
|
127 "Regular" (substring name (match-end 1)))
|
|
128 device t))))
|
|
129
|
|
130 (defun mswindows-make-font-italic (font &optional device)
|
|
131 "Given a mswindows font specification, this attempts to make an `italic'
|
|
132 font. If it fails, it returns nil."
|
|
133 (if (font-instance-p font)
|
|
134 (let ((name (mswindows-font-canonicalize-name font)))
|
|
135 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
|
136 (make-font-instance (concat
|
|
137 (substring name 0 (match-beginning 1))
|
|
138 "Italic" (substring name (match-end 1)))
|
|
139 device t))))
|
|
140
|
|
141 (defun mswindows-make-font-unitalic (font &optional device)
|
|
142 "Given a mswindows font specification, this attempts to make a non-italic
|
|
143 font. If it fails, it returns nil."
|
|
144 (if (font-instance-p font)
|
|
145 (let ((name (mswindows-font-canonicalize-name font)))
|
|
146 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
|
147 (make-font-instance (concat
|
|
148 (substring name 0 (match-beginning 1))
|
|
149 "Regular" (substring name (match-end 1)))
|
|
150 device t))))
|
|
151
|
|
152 (defun mswindows-make-font-bold-italic (font &optional device)
|
|
153 "Given a mswindows font specification, this attempts to make a `bold-italic'
|
|
154 font. If it fails, it returns nil."
|
|
155 (if (font-instance-p font)
|
|
156 (let ((name (mswindows-font-canonicalize-name font))
|
|
157 (oldwidth (font-instance-width font)))
|
|
158 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
|
|
159 (let ((newfont (make-font-instance
|
|
160 (concat (substring name 0 (match-beginning 1))
|
|
161 "Bold Italic" (substring name (match-end 1)))
|
|
162 device t)))
|
|
163 ; Hack! on mswindows, bold fonts (even monospaced) are often wider than the
|
|
164 ; equivalent non-bold font. Making the bold font one point smaller usually
|
|
165 ; makes it the same width (maybe at the expense of making it one pixel shorter)
|
|
166 (if (font-instance-p newfont)
|
|
167 (if (> (font-instance-width newfont) oldwidth)
|
|
168 (mswindows-find-smaller-font newfont device)
|
|
169 newfont))))))
|
|
170
|
|
171 (defun mswindows-find-smaller-font (font &optional device)
|
|
172 "Loads a new version of the given font (or font name) 1 point smaller.
|
|
173 Returns the font if it succeeds, nil otherwise."
|
|
174 (if (stringp font) (setq font (make-font-instance font device)))
|
|
175 (if (font-instance-p font) (setq font (font-instance-truename font)))
|
|
176 (if (stringp font) (setq font (make-font-instance font device)))
|
|
177 (if (font-instance-p font)
|
|
178 (let (old-size (name (mswindows-font-canonicalize-name font)))
|
|
179 (string-match "^[a-zA-Z ]+:[a-zA-Z ]*:\\([0-9]+\\):" name)
|
|
180 (setq old-size (string-to-int
|
|
181 (substring name (match-beginning 1) (match-end 1))))
|
|
182 (if (> old-size 0)
|
|
183 (make-font-instance (concat
|
|
184 (substring name 0 (match-beginning 1))
|
|
185 (int-to-string (- old-size 1))
|
|
186 (substring name (match-end 1)))
|
|
187 device t)))))
|
|
188
|
|
189 (defun mswindows-find-larger-font (font &optional device)
|
|
190 "Loads a new version of the given font (or font name) 1 point larger.
|
|
191 Returns the font if it succeeds, nil otherwise."
|
|
192 (if (stringp font) (setq font (make-font-instance font device)))
|
|
193 (if (font-instance-p font) (setq font (font-instance-truename font)))
|
|
194 (if (stringp font) (setq font (make-font-instance font device)))
|
|
195 (if (font-instance-p font)
|
|
196 (let (old-size (name (mswindows-font-canonicalize-name font)))
|
|
197 (string-match "^[a-zA-Z ]+:[a-zA-Z ]*:\\([0-9]+\\):" name)
|
|
198 (setq old-size (string-to-int
|
|
199 (substring name (match-beginning 1) (match-end 1))))
|
|
200 (make-font-instance (concat
|
|
201 (substring name 0 (match-beginning 1))
|
|
202 (int-to-string (+ old-size 1))
|
|
203 (substring name (match-end 1)))
|
|
204 device t))))
|