annotate lisp/font-menu.el @ 646:00c54252fe4f

[xemacs-hg @ 2001-08-08 12:15:04 by didierv] autoload.el: handle the case of `define-derived-mode'.
author didierv
date Wed, 08 Aug 2001 12:15:04 +0000
parents 1ccc32a20af4
children 943eaba38521
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;; font-menu.el --- Managing menus of fonts.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Copyright (C) 1997 Sun Microsystems
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Adapted from x-font-menu.el by Andy Piper <andy@xemacs.org>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; Free Software Foundation, 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;; This file contains the device-nospecific font menu stuff
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;;; Creates three menus, "Font", "Size", and "Weight", and puts them on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;;; "Options" menu. The contents of these menus are the superset of those
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;;; properties available on any fonts, but only the intersection of the three
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;;; sets is selectable at one time.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 ;;; Known Problems:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;;; ===============
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 ;;; Items on the Font menu are selectable if and only if that font exists in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 ;;; the same size and weight as the current font. This means that some fonts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;;; are simply not reachable from some other fonts - if only one font comes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 ;;; in only one point size (like "Nil", which comes only in 2), you will never
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 ;;; be able to select it. It would be better if the items on the Fonts menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 ;;; were always selectable, and selecting them would set the size to be the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 ;;; closest size to the current font's size.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 ;;;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
45 ;;; This attempts to change all other faces in an analogous way to the change
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 ;;; that was made to the default face; if it can't, it will skip over the face.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 ;;; However, this could leave incongruous font sizes around, which may cause
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 ;;; some nonreversibility problems if further changes are made. Perhaps it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 ;;; should remember the initial fonts of all faces, and derive all subsequent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 ;;; fonts from that initial state.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 ;;; xfontsel(1) is a lot more flexible (but probably harder to understand).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 ;;; The code to construct menus from all of the x11 fonts available from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 ;;; server is autoloaded and executed the very first time that one of the Font
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 ;;; menus is selected on each device. That is, if XEmacs has frames on two
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 ;;; different devices, then separate font menu information will be maintained
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 ;;; for each X display. If the font path changes after emacs has already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 ;;; asked the X server on a particular display for its list of fonts, this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 ;;; won't notice. Also, the first time that a font menu is posted on each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 ;;; display will entail a lengthy delay, but that's better than slowing down
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 ;;; XEmacs startup. At any time (i.e.: after a font-path change or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 ;;; immediately after device creation), you can call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 ;;; `reset-device-font-menus' to rebuild the menus from all currently
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 ;;; available fonts.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 ;;; There is knowledge here about the regexp match numbers in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 ;;; `mswindows-font-regexp' and `mswindows-font-regexp-foundry-and-family' defined in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 ;;; mswindows-faces.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 ;;; There are at least three kinds of fonts under X11r5:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 ;;; - bitmap fonts, which can be assumed to look as good as possible;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 ;;; - bitmap fonts which have been (or can be) automatically scaled to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 ;;; a new size, and which almost always look awful;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 ;;; - and true outline fonts, which should look ok at any size, but in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 ;;; practice (on at least some systems) look awful at any size, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 ;;; even in theory are unlikely ever to look as good as non-scaled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 ;;; bitmap fonts.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 ;;; It would be nice to get this code to look for non-scaled bitmap fonts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 ;;; first, then outline fonts, then scaled bitmap fonts as a last resort.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 ;;; But it's not clear to me how to tell them apart based on their truenames
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 ;;; and/or the result of XListFonts(). I welcome any and all explanations
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 ;;; of the subtleties involved...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 ;;; If You Think You'Re Seeing A Bug:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 ;;; =================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 ;;; When reporting problems, send the following information:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 ;;; - Exactly what behavior you're seeing;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 ;;; - The output of the `xlsfonts' program;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 ;;; - The value of the variable `device-fonts-cache';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 ;;; - The values of the following expressions, both before and after
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 ;;; making a selection from any of the fonts-related menus:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 ;;; (face-font 'default)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 ;;; (font-truename (face-font 'default))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 ;;; (font-properties (face-font 'default))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 ;;; - The values of the following variables after making a selection:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 ;;; font-menu-preferred-resolution
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 ;;; font-menu-registry-encoding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 ;;; There is a common misconception that "*-courier-medium-r-*-11-*", also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 ;;; known as "-adobe-courier-medium-r-normal--11-80-100-100-m-60-iso8859-1",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 ;;; is an 11-point font. It is not -- it is an 11-pixel font at 100dpi,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 ;;; which is an 8-point font (the number after -11- is the size in tenths
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 ;;; of points). So if you expect to be seeing an "11" entry in the "Size"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 ;;; menu and are not, this may be why.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 ;;; In the real world (aka Solaris), one has to deal with fonts that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 ;;; appear to be medium-i but are really light-r, and fonts that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 ;;; resolve to different resolutions depending on the charset:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 ;;; (font-instance-truename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 ;;; (make-font-instance "-*-mincho-medium-i-normal-*-*-*-*-*-*-*-jisx0201*-*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 ;;; ==>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 ;;; "-morisawa-ryumin light kl-light-r-normal--10-100-72-72-m-50-jisx0201.1976-0"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 ;;; (list-fonts "-dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 ;;; ==>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 ;;; ("-dt-interface user-medium-r-normal-s sans-12-120-72-72-m-70-iso8859-1"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 ;;; "-dt-interface user-medium-r-normal-s-14-120-75-75-m-120-jisx0208.1983-0"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 ;;; "-dt-interface user-medium-r-normal-s-14-120-75-75-m-60-jisx0201.1976-0")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 (defcustom font-menu-ignore-scaled-fonts nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 "*If non-nil, then the font menu will try to show only bitmap fonts."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 :group 'font-menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 (defcustom font-menu-this-frame-only-p nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 "*If non-nil, then changing the default font from the font menu will only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 affect one frame instead of all frames."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 :group 'font-menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (defcustom font-menu-max-items 25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 "*Maximum number of items in the font menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 If number of entries in a menu is larger than this value, split menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 into submenus of nearly equal length. If nil, never split menu into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 submenus."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 :group 'font-menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 :type '(choice (const :tag "no submenus" nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 (integer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 (defcustom font-menu-submenu-name-format "%-12.12s ... %.12s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 "*Format specification of the submenu name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 Used by `font-menu-split-long-menu' if the number of entries in a menu is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 larger than `font-menu-menu-max-items'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 This string should contain one %s for the name of the first entry and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 one %s for the name of the last entry in the submenu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 If the value is a function, it should return the submenu name. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 function is be called with two arguments, the names of the first and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 the last entry in the menu."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 :group 'font-menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 :type '(choice (string :tag "Format string")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
161 (defvar font-menu-preferred-resolution
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (make-specifier-and-init 'generic '((global ((mswindows) . ":")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 ((x) . "*-*"))) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 "Preferred horizontal and vertical font menu resolution (e.g. \"75:75\").")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (defvar font-menu-size-scaling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 (make-specifier-and-init 'integer '((global ((mswindows) . 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 ((x) . 10))) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 "Scale factor used in defining font sizes.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 ;; only call XListFonts (and parse) once per device.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 ;; ( (device . [parsed-list-fonts family-menu size-menu weight-menu]) ...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (defvar device-fonts-cache nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 (defsubst device-fonts-cache ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 (or (cdr (assq (selected-device) device-fonts-cache))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 (and (reset-device-font-menus (selected-device))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 (cdr (assq (selected-device) device-fonts-cache)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 (fset 'install-font-menus 'reset-device-font-menus)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 (make-obsolete 'install-font-menus 'reset-device-font-menus)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 (defun reset-device-font-menus (&optional device debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 "Generates the `Font', `Size', and `Weight' submenus for the Options menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 This is run the first time that a font-menu is needed for each device.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 If you don't like the lazy invocation of this function, you can add it to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 `create-device-hook' and that will make the font menus respond more quickly
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
190 when they are selected for the first time. If you add fonts to your system,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 or if you change your font path, you can call this to re-initialize the menus."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 (message "Getting list of fonts from server... ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 (if (or noninteractive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 (not (or device (setq device (selected-device)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 (call-device-method 'reset-device-font-menus device device debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 (message "Getting list of fonts from server... done.")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 (defun font-menu-split-long-menu (menu)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
200 "Split MENU according to `font-menu-max-items' and add accelerator specs."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 (let ((len (length menu)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (if (or (null font-menu-max-items)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (null (featurep 'lisp-float-type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (<= len font-menu-max-items))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
205 (submenu-generate-accelerator-spec menu)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 ;; Submenu is max 2 entries longer than menu, never shorter, number of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 ;; entries in submenus differ by at most one (with longer submenus first)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 (let* ((outer (floor (sqrt len)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (inner (/ len outer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 (rest (% len outer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (result nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (setq menu (reverse menu))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 (while menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 (let ((in inner)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 (sub nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (to (car menu)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 (while (> in 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (setq in (1- in)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 sub (cons (car menu) sub)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 menu (cdr menu)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (setq result
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 (cons (cons (if (stringp font-menu-submenu-name-format)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 (format font-menu-submenu-name-format
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
224 (menu-item-strip-accelerator-spec
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
225 (aref (car sub) 0))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
226 (menu-item-strip-accelerator-spec
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
227 (aref to 0)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (funcall font-menu-submenu-name-format
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
229 (menu-item-strip-accelerator-spec
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
230 (aref (car sub) 0))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
231 (menu-item-strip-accelerator-spec
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
232 (aref to 0))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
233 (submenu-generate-accelerator-spec sub))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 result)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 rest (1+ rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (if (= rest outer) (setq inner (1+ inner)))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
237 (submenu-generate-accelerator-spec result)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (defun font-menu-family-constructor (ignored)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (catch 'menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (unless (console-on-window-system-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (throw 'menu '(["Cannot parse current font" ding nil])))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (let* ((dcache (device-fonts-cache))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 (font-data (font-menu-font-data 'default dcache))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (entry (aref font-data 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (family (aref font-data 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (size (aref font-data 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (weight (aref font-data 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 f)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (unless family
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (throw 'menu '(["Cannot parse current font" ding nil])))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 ;; Items on the Font menu are enabled iff that font exists in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 ;; the same size and weight as the current font (scalable fonts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 ;; exist in every size). Only the current font is marked as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 ;; selected.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 (font-menu-split-long-menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (mapcar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (lambda (item)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
260 (setq f (menu-item-strip-accelerator-spec (aref item 0))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 entry (vassoc f (aref dcache 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 (if (and (or (member weight (aref entry 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 ;; mswindows often allows any weight
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 (member "" (aref entry 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (or (member size (aref entry 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (and (not font-menu-ignore-scaled-fonts)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (member 0 (aref entry 2)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (enable-menu-item item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (disable-menu-item item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 (if (string-equal family f)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 (select-toggle-menu-item item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (deselect-toggle-menu-item item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (aref dcache 1))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (define-device-method* font-menu-font-data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (defun font-menu-size-constructor (ignored)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (catch 'menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (unless (console-on-window-system-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (throw 'menu '(["Cannot parse current font" ding nil])))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (let* ((dcache (device-fonts-cache))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (font-data (font-menu-font-data 'default dcache))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 (entry (aref font-data 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (family (aref font-data 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (size (aref font-data 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 ;;(weight (aref font-data 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 (unless family
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 (throw 'menu '(["Cannot parse current font" ding nil])))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 ;; Items on the Size menu are enabled iff current font has
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 ;; that size. Only the size of the current font is selected.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 ;; (If the current font comes in size 0, it is scalable, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 ;; thus has every size.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 (mapcar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 (lambda (item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (setq s (nth 3 (aref item 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (if (or (member s (aref entry 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (and (not font-menu-ignore-scaled-fonts)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 (member 0 (aref entry 2))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 (enable-menu-item item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (disable-menu-item item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 (if (eq size s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (select-toggle-menu-item item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (deselect-toggle-menu-item item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 item)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
308 (submenu-generate-accelerator-spec (aref dcache 2))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 (defun font-menu-weight-constructor (ignored)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 (catch 'menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (unless (console-on-window-system-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 (throw 'menu '(["Cannot parse current font" ding nil])))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (let* ((dcache (device-fonts-cache))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 (font-data (font-menu-font-data 'default dcache))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (entry (aref font-data 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (family (aref font-data 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 ;;(size (aref font-data 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (weight (aref font-data 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 w)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 (unless family
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (throw 'menu '(["Cannot parse current font" ding nil])))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 ;; Items on the Weight menu are enabled iff current font
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 ;; has that weight. Only the weight of the current font
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 ;; is selected.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (mapcar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (lambda (item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (setq w (aref item 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 (if (member w (aref entry 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 (enable-menu-item item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 (disable-menu-item item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (if (string-equal weight w)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 (select-toggle-menu-item item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 (deselect-toggle-menu-item item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 item)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
337 (submenu-generate-accelerator-spec (aref dcache 3))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 ;;; Changing font sizes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (defun font-menu-set-font (family weight size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 ;; This is what gets run when an item is selected from any of the three
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 ;; fonts menus. It needs to be rather clever.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 ;; (size is measured in 10ths of points.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (let* ((dcache (device-fonts-cache))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (font-data (font-menu-font-data 'default dcache))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (from-family (aref font-data 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (from-size (aref font-data 2))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
350 (from-weight (aref font-data 3))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (from-slant (aref font-data 4))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
352 (face-list-to-change (delq 'default (face-list)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
353 new-default-face-font)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 (unless from-family
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 (signal 'error '("couldn't parse font name for default face")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 (when weight
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (signal 'error '("Setting weight currently not supported")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 (setq new-default-face-font
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
359 (font-menu-load-font
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 (or family from-family)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 (or weight from-weight)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (or size from-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 from-slant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (specifier-instance
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 font-menu-preferred-resolution (selected-device))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 ;; This is such a gross hack. The border-glyph face under
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 ;; mswindows is in a symbol font. Thus it will not appear in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 ;; cache - being a junk family. What we should do is change the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 ;; size but not the family, but this is more work than I care to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 ;; invest at the moment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (when (eq (device-type) 'mswindows)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (setq face-list-to-change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 (delq 'border-glyph face-list-to-change)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 (dolist (face face-list-to-change)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 (when (face-font-instance face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (message "Changing font of `%s'..." face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 (condition-case c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 (font-menu-change-face face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 from-family from-weight from-size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 family weight size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 (display-error c nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 (sit-for 1)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 ;; Set the default face's font after hacking the other faces, so that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 ;; the frame size doesn't change until we are all done.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 ;; If we need to be frame local we do the changes ourselves.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 (if font-menu-this-frame-only-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 ;;; WMP - we need to honor font-menu-this-frame-only-p here!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 (set-face-font 'default new-default-face-font
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 (and font-menu-this-frame-only-p (selected-frame)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 ;; OK Let Customize do it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (custom-set-face-update-spec 'default
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
394 (list (list 'type (device-type)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
395 (list :family family
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
396 :size (concat
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
397 (int-to-string
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
398 (/ (or size from-size)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
399 (specifier-instance font-menu-size-scaling
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
400 (selected-device))))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
401 "pt")))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 (message "Font %s" (face-font-name 'default)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (defun font-menu-change-face (face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 from-family from-weight from-size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 to-family to-weight to-size)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
408 (check-type face symbol)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (let* ((dcache (device-fonts-cache))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 (font-data (font-menu-font-data face dcache))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (face-family (aref font-data 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 (face-size (aref font-data 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 (face-weight (aref font-data 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 (face-slant (aref font-data 4)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 (or face-family
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 (signal 'error (list "couldn't parse font name for face" face)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 ;; If this face matches the old default face in the attribute we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 ;; are changing, then change it to the new attribute along that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 ;; dimension. Also, the face must have its own global attribute.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 ;; If its value is inherited, we don't touch it. If any of this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 ;; is not true, we leave it alone.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 (when (and (face-font face 'global)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
425 (cond
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 (to-family (string-equal face-family from-family))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 (to-weight (string-equal face-weight from-weight))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 (to-size (= face-size from-size))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 (set-face-font face
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 (font-menu-load-font (or to-family face-family)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 (or to-weight face-weight)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 (or to-size face-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 face-slant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 (specifier-instance
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
435 font-menu-preferred-resolution
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 (selected-device)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (and font-menu-this-frame-only-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 (selected-frame))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 (define-device-method font-menu-load-font)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 (defun flush-device-fonts-cache (device)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 ;; by Stig@hackvan.com
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 (let ((elt (assq device device-fonts-cache)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 (and elt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 (setq device-fonts-cache (delq elt device-fonts-cache)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 (add-hook 'delete-device-hook 'flush-device-fonts-cache)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 (provide 'font-menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 ;; font-menu ends here