1 ;;; msw-faces.el --- mswindows-specific face stuff.
3 ;;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
4 ;;; Copyright (C) 1995, 1996 Ben Wing.
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
12 ;; This file is part of XEmacs.
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)
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.
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.
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.
32 ;;; Force creation of the default face font so that if it fails we get an
33 ;;; error now instead of a crash at frame creation.
34 (defun mswindows-init-device-faces (device)
35 (unless (face-font-instance 'default device)
36 (error "Can't find a suitable default font")))
39 (defun mswindows-init-frame-faces (frame)
43 ;;; Fill in missing parts of a font spec. This is primarily intended as a
44 ;;; helper function for the functions below.
45 ;;; mswindows fonts look like:
46 ;;; fontname[:[weight][ style][:pointsize[:effects]]][:charset]
47 ;;; A minimal mswindows font spec looks like:
49 ;;; A maximal mswindows font spec looks like:
50 ;;; Courier New:Bold Italic:10:underline strikeout:Western
51 ;;; Missing parts of the font spec should be filled in with these values:
52 ;;; Courier New:Regular:10::Western
53 (defun mswindows-font-canonicalize-name (font)
54 "Given a mswindows font or font name, this returns its name in
56 (if (or (font-instance-p font)
58 (let ((name (if (font-instance-p font)
59 (font-instance-name font)
62 "^[a-zA-Z ]+:[a-zA-Z ]*:[0-9]+:[a-zA-Z ]*:[a-zA-Z 0-9]*$"
64 ((string-match "^[a-zA-Z ]+:[a-zA-Z ]*:[0-9]+:[a-zA-Z ]*$"
65 name) (concat name ":Western"))
66 ((string-match "^[a-zA-Z ]+:[a-zA-Z ]*:[0-9]+$" name)
67 (concat name "::Western"))
68 ((string-match "^[a-zA-Z ]+:[a-zA-Z ]*$" name)
69 (concat name ":10::Western"))
70 ((string-match "^[a-zA-Z ]+$" name)
71 (concat name ":Regular:10::Western"))
72 (t "Courier New:Regular:10::Western")))))
74 (defun mswindows-make-font-bold (font &optional device)
75 "Given a mswindows font specification, this attempts to make a bold font.
76 If it fails, it returns nil."
77 (if (font-instance-p font)
78 (let ((name (mswindows-font-canonicalize-name font))
79 (oldwidth (font-instance-width font)))
80 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
81 (let ((newfont (make-font-instance
82 (concat (substring name 0 (match-beginning 1))
83 "Bold" (substring name (match-end 1)))
85 ; Hack! on mswindows, bold fonts (even monospaced) are often wider than the
86 ; equivalent non-bold font. Making the bold font one point smaller usually
87 ; makes it the same width (maybe at the expense of making it one pixel shorter)
88 (if (font-instance-p newfont)
89 (if (> (font-instance-width newfont) oldwidth)
90 (mswindows-find-smaller-font newfont device)
93 (defun mswindows-make-font-unbold (font &optional device)
94 "Given a mswindows font specification, this attempts to make a non-bold font.
95 If it fails, it returns nil."
96 (if (font-instance-p font)
97 (let ((name (mswindows-font-canonicalize-name font)))
98 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
99 (make-font-instance (concat
100 (substring name 0 (match-beginning 1))
101 "Regular" (substring name (match-end 1)))
104 (defun mswindows-make-font-italic (font &optional device)
105 "Given a mswindows font specification, this attempts to make an `italic'
106 font. If it fails, it returns nil."
107 (if (font-instance-p font)
108 (let ((name (mswindows-font-canonicalize-name font)))
109 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
110 (make-font-instance (concat
111 (substring name 0 (match-beginning 1))
112 "Italic" (substring name (match-end 1)))
115 (defun mswindows-make-font-unitalic (font &optional device)
116 "Given a mswindows font specification, this attempts to make a non-italic
117 font. If it fails, it returns nil."
118 (if (font-instance-p font)
119 (let ((name (mswindows-font-canonicalize-name font)))
120 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
121 (make-font-instance (concat
122 (substring name 0 (match-beginning 1))
123 "Regular" (substring name (match-end 1)))
126 (defun mswindows-make-font-bold-italic (font &optional device)
127 "Given a mswindows font specification, this attempts to make a `bold-italic'
128 font. If it fails, it returns nil."
129 (if (font-instance-p font)
130 (let ((name (mswindows-font-canonicalize-name font))
131 (oldwidth (font-instance-width font)))
132 (string-match "^[a-zA-Z ]+:\\([a-zA-Z ]*\\):" name)
133 (let ((newfont (make-font-instance
134 (concat (substring name 0 (match-beginning 1))
135 "Bold Italic" (substring name (match-end 1)))
137 ; Hack! on mswindows, bold fonts (even monospaced) are often wider than the
138 ; equivalent non-bold font. Making the bold font one point smaller usually
139 ; makes it the same width (maybe at the expense of making it one pixel shorter)
140 (if (font-instance-p newfont)
141 (if (> (font-instance-width newfont) oldwidth)
142 (mswindows-find-smaller-font newfont device)
145 (defun mswindows-find-smaller-font (font &optional device)
146 "Loads a new version of the given font (or font name) 1 point smaller.
147 Returns the font if it succeeds, nil otherwise."
148 (if (stringp font) (setq font (make-font-instance font device)))
149 (if (font-instance-p font) (setq font (font-instance-truename font)))
150 (if (stringp font) (setq font (make-font-instance font device)))
151 (if (font-instance-p font)
152 (let (old-size (name (mswindows-font-canonicalize-name font)))
153 (string-match "^[a-zA-Z ]+:[a-zA-Z ]*:\\([0-9]+\\):" name)
154 (setq old-size (string-to-int
155 (substring name (match-beginning 1) (match-end 1))))
157 (make-font-instance (concat
158 (substring name 0 (match-beginning 1))
159 (int-to-string (- old-size 1))
160 (substring name (match-end 1)))
163 (defun mswindows-find-larger-font (font &optional device)
164 "Loads a new version of the given font (or font name) 1 point larger.
165 Returns the font if it succeeds, nil otherwise."
166 (if (stringp font) (setq font (make-font-instance font device)))
167 (if (font-instance-p font) (setq font (font-instance-truename font)))
168 (if (stringp font) (setq font (make-font-instance font device)))
169 (if (font-instance-p font)
170 (let (old-size (name (mswindows-font-canonicalize-name font)))
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)))