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