annotate lisp/x11/x-font-menu.el @ 149:538048ae2ab8 r20-3b1

Import from CVS: tag r20-3b1
author cvs
date Mon, 13 Aug 2007 09:36:16 +0200
parents 821dec489c24
children a2f645c6b9f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; x-font-menu.el --- Managing menus of X fonts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
5 ;; Copyright (C) 1997 Sun Microsystems
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 88
diff changeset
7 ;; Author: Jamie Zawinski <jwz@netscape.com>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Restructured by: Jonathan Stigelman <Stig@hackvan.com>
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
9 ;; Mule-ized by: Martin Buchholz
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
25 ;; Free Software Foundation, 59 Temple Place - Suite 330,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
26 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Creates three menus, "Font", "Size", and "Weight", and puts them on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; "Options" menu. The contents of these menus are the superset of those
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; properties available on any fonts, but only the intersection of the three
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; sets is selectable at one time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; Known Problems:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; ===============
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; Items on the Font menu are selectable if and only if that font exists in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; the same size and weight as the current font. This means that some fonts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; are simply not reachable from some other fonts - if only one font comes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; in only one point size (like "Nil", which comes only in 2), you will never
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; be able to select it. It would be better if the items on the Fonts menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; were always selectable, and selecting them would set the size to be the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; closest size to the current font's size.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; This attempts to change all other faces in an analagous way to the change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; that was made to the default face; if it can't, it will skip over the face.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; However, this could leave incongruous font sizes around, which may cause
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; some nonreversibility problems if further changes are made. Perhaps it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; should remember the initial fonts of all faces, and derive all subsequent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; fonts from that initial state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; xfontsel(1) is a lot more flexible (but probably harder to understand).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; The code to construct menus from all of the x11 fonts available from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; server is autoloaded and executed the very first time that one of the Font
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; menus is selected on each device. That is, if XEmacs has frames on two
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;; different devices, then separate font menu information will be maintained
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; for each X display. If the font path changes after emacs has already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;; asked the X server on a particular display for its list of fonts, this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; won't notice. Also, the first time that a font menu is posted on each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; display will entail a lengthy delay, but that's better than slowing down
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; XEmacs startup. At any time (i.e.: after a font-path change or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; immediately after device creation), you can call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;; `reset-device-font-menus' to rebuild the menus from all currently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;; available fonts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;;
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
67 ;;; There is knowledge here about the regexp match numbers in
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
68 ;;; `x-font-regexp' and `x-font-regexp-foundry-and-family' defined in
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
69 ;;; x-faces.el.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; There are at least three kinds of fonts under X11r5:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;; - bitmap fonts, which can be assumed to look as good as possible;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;; - bitmap fonts which have been (or can be) automatically scaled to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;; a new size, and which almost always look awful;
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
76 ;;; - and true outline fonts, which should look ok at any size, but in
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;; practice (on at least some systems) look awful at any size, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;; even in theory are unlikely ever to look as good as non-scaled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;; bitmap fonts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;; It would be nice to get this code to look for non-scaled bitmap fonts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;; first, then outline fonts, then scaled bitmap fonts as a last resort.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;; But it's not clear to me how to tell them apart based on their truenames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;; and/or the result of XListFonts(). I welcome any and all explanations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;; of the subtleties involved...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;; If You Think You'Re Seeing A Bug:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;; =================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;; When reporting problems, send the following information:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;;; - Exactly what behavior you're seeing;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;;; - The output of the `xlsfonts' program;
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
94 ;;; - The value of the variable `device-fonts-cache';
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;;; - The values of the following expressions, both before and after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;;; making a selection from any of the fonts-related menus:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;;; (face-font 'default)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
98 ;;; (font-truename (face-font 'default))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
99 ;;; (font-properties (face-font 'default))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;;; - The values of the following variables after making a selection:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;;; font-menu-preferred-resolution
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
102 ;;; font-menu-registry-encoding
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;;; There is a common misconception that "*-courier-medium-r-*-11-*", also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;; known as "-adobe-courier-medium-r-normal--11-80-100-100-m-60-iso8859-1",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;;; is an 11-point font. It is not -- it is an 11-pixel font at 100dpi,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;;; which is an 8-point font (the number after -11- is the size in tenths
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;;; of points). So if you expect to be seeing an "11" entry in the "Size"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;;; menu and are not, this may be why.
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
110 ;;;
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
111 ;;; In the real world (aka Solaris), one has to deal with fonts that
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
112 ;;; appear to be medium-i but are really light-r, and fonts that
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
113 ;;; resolve to different resolutions depending on the charset:
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
114 ;;;
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
115 ;;; (font-instance-truename
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
116 ;;; (make-font-instance "-*-mincho-medium-i-normal-*-*-*-*-*-*-*-jisx0201*-*"))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
117 ;;; ==>
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
118 ;;; "-morisawa-ryumin light kl-light-r-normal--10-100-72-72-m-50-jisx0201.1976-0"
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
119 ;;;
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
120 ;;; (list-fonts "-dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*")
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
121 ;;; ==>
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
122 ;;; ("-dt-interface user-medium-r-normal-s sans-12-120-72-72-m-70-iso8859-1"
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
123 ;;; "-dt-interface user-medium-r-normal-s-14-120-75-75-m-120-jisx0208.1983-0"
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
124 ;;; "-dt-interface user-medium-r-normal-s-14-120-75-75-m-60-jisx0201.1976-0")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;; #### - implement these...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;;; (defvar font-menu-ignore-proportional-fonts nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;;; "*If non-nil, then the font menu will only show fixed-width fonts.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (defvar font-menu-ignore-scaled-fonts t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 "*If non-nil, then the font menu will try to show only bitmap fonts.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;;;###autoload
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 70
diff changeset
138 (defvar font-menu-this-frame-only-p nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 "*If non-nil, then changing the default font from the font menu will only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 affect one frame instead of all frames.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;; only call XListFonts (and parse) once per device.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;; ( (device . [parsed-list-fonts family-menu size-menu weight-menu]) ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (defvar device-fonts-cache nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
146 (defvar font-menu-registry-encoding nil
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
147 "Registry and encoding to use with font menu fonts.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
149 (defvar font-menu-preferred-resolution "*-*"
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
150 "Preferred horizontal and vertical font menu resolution (e.g. \"75-75\").")
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
151
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
152 (defvar fonts-menu-junk-families
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (purecopy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (mapconcat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 #'identity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 '("cursor" "glyph" "symbol" ; Obvious losers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 "\\`Ax...\\'" ; FrameMaker fonts - there are just way too
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ; many of these, and there is a different
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ; font family for each font face! Losers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ; "Axcor" -> "Applix Courier Roman",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ; "Axcob" -> "Applix Courier Bold", etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 "\\|"))
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
164 "A regexp matching font families which are uninteresting (e.g. cursor fonts).")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
166 (eval-when-compile
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
167 (defsubst device-fonts-cache ()
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
168 (or (cdr (assq (selected-device) device-fonts-cache))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
169 (reset-device-font-menus (selected-device)))))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
170
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (defun hack-font-truename (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 "Filter the output of `font-instance-truename' to deal with Japanese fontsets."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (if (string-match "," (font-instance-truename fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (let ((fpnt (nth 8 (split-string (font-instance-name fn) "-")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (flist (split-string (font-instance-truename fn) ","))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ret)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (while flist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (if (string-equal fpnt (nth 8 (split-string (car flist) "-")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (progn (setq ret (car flist)) (setq flist nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (setq flist (cdr flist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ret)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (font-instance-truename fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (fset 'install-font-menus 'reset-device-font-menus)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (make-obsolete 'install-font-menus 'reset-device-font-menus)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
189 (defvar x-font-regexp-ascii nil
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
190 "This is used to filter out font families that can't display ASCII text.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 It must be set at run-time.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (defun vassoc (key valist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 "Search VALIST for a vector whose first element is equal to KEY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 See also `assoc'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;; by Stig@hackvan.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (let (el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (catch 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (while (setq el (pop valist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (and (equal key (aref el 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (throw 'done el))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (defun reset-device-font-menus (&optional device debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 "Generates the `Font', `Size', and `Weight' submenus for the Options menu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 This is run the first time that a font-menu is needed for each device.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 If you don't like the lazy invocation of this function, you can add it to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 `create-device-hook' and that will make the font menus respond more quickly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 when they are selected for the first time. If you add fonts to your system,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 or if you change your font path, you can call this to re-initialize the menus."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;; by Stig@hackvan.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ;; #### - this should implement a `menus-only' option, which would
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;; recalculate the menus from the cache w/o having to do list-fonts again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (message "Getting list of fonts from server... ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (if (or noninteractive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (not (or device (setq device (selected-device))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (not (eq (device-type device) 'x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 nil
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
219 (unless x-font-regexp-ascii
88
821dec489c24 Import from CVS: tag r20-0
cvs
parents: 86
diff changeset
220 (setq x-font-regexp-ascii (if (featurep 'mule)
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
221 (charset-registry 'ascii)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
222 "iso8859-1")))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
223 (setq font-menu-registry-encoding
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
224 (if (featurep 'mule) "*-*" "iso8859-1"))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
225 (let ((case-fold-search t)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
226 family size weight entry monospaced-p
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
227 dev-cache cache families sizes weights)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
228 (dolist (name (cond ((null debug) ; debugging kludge
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
229 (list-fonts "*-*-*-*-*-*-*-*-*-*-*-*-*-*" device))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
230 ((stringp debug) (split-string debug "\n"))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
231 (t debug)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
232 (when (and (string-match x-font-regexp-ascii name)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
233 (string-match x-font-regexp name))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
234 (setq weight (capitalize (match-string 1 name))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
235 size (string-to-int (match-string 6 name)))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
236 (or (string-match x-font-regexp-foundry-and-family name)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
237 (error "internal error"))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
238 (setq family (capitalize (match-string 1 name)))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
239 (or (string-match x-font-regexp-spacing name)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
240 (error "internal error"))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
241 (setq monospaced-p (string= "m" (match-string 1 name)))
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
242 (unless (string-match fonts-menu-junk-families family)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
243 (setq entry (or (vassoc family cache)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
244 (car (setq cache
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
245 (cons (vector family nil nil t)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
246 cache)))))
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
247 (or (member family families) (push family families))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
248 (or (member weight weights) (push weight weights))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
249 (or (member size sizes) (push size sizes))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
250 (or (member weight (aref entry 1)) (push weight (aref entry 1)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
251 (or (member size (aref entry 2)) (push size (aref entry 2)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
252 (aset entry 3 (and (aref entry 3) monospaced-p)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ;; Hack scalable fonts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 ;; Some fonts come only in scalable versions (the only size is 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;; and some fonts come in both scalable and non-scalable versions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ;; (one size is 0). If there are any scalable fonts at all, make
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ;; sure that the union of all point sizes contains at least some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ;; common sizes - it's possible that some sensible sizes might end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; up not getting mentioned explicitly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (if (member 0 sizes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (let ((common '(60 80 100 120 140 160 180 240)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (while common
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (or;;(member (car common) sizes) ; not enough slack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (let ((rest sizes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (while (and (not done) rest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (if (and (> (car common) (- (car rest) 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (< (car common) (+ (car rest) 5)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (setq done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (setq rest (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (setq sizes (cons (car common) sizes)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (setq common (cdr common)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (setq sizes (delq 0 sizes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (setq families (sort families 'string-lessp)
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
279 weights (sort weights 'string-lessp)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
280 sizes (sort sizes '<))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
282 (dolist (entry cache)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
283 (aset entry 1 (sort (aref entry 1) 'string-lessp))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
284 (aset entry 2 (sort (aref entry 2) '<)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (message "Getting list of fonts from server... done.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (setq dev-cache (assq device device-fonts-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (or dev-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (setq dev-cache (car (push (list device) device-fonts-cache))))
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
291 (setcdr
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
292 dev-cache
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
293 (vector
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
294 cache
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
295 (mapcar (lambda (x)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
296 (vector x
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
297 (list 'font-menu-set-font x nil nil)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
298 ':style 'radio ':active nil ':selected nil))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
299 families)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
300 (mapcar (lambda (x)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
301 (vector (if (/= 0 (% x 10))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
302 ;; works with no LISP_FLOAT_TYPE
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
303 (concat (int-to-string (/ x 10)) "."
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
304 (int-to-string (% x 10)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
305 (int-to-string (/ x 10)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
306 (list 'font-menu-set-font nil nil x)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
307 ':style 'radio ':active nil ':selected nil))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
308 sizes)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
309 (mapcar (lambda (x)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
310 (vector x
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
311 (list 'font-menu-set-font nil x nil)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
312 ':style 'radio ':active nil ':selected nil))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
313 weights)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (cdr dev-cache))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
316 ;; Extract font information from a face. We examine both the
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
317 ;; user-specified font name and the canonical (`true') font name.
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
318 ;; These can appear to have totally different properties.
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
319 ;; For examples, see the prolog above.
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
320
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
321 ;; We use the user-specified one if possible, else use the truename.
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
322 ;; If the user didn't specify one (with "-dt-*-*", for example)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
323 ;; get the truename and use the possibly suboptimal data from that.
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
324 (defun* font-menu-font-data (face dcache)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
325 (let* ((case-fold-search t)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
326 (domain (if font-menu-this-frame-only-p
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
327 (selected-frame)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
328 (selected-device)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
329 (name (font-instance-name (face-font-instance face domain)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
330 (truename (font-instance-truename
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
331 (face-font-instance face domain
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
332 (if (featurep 'mule) 'ascii))))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
333 family size weight entry slant)
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
334 (when (string-match x-font-regexp-foundry-and-family name)
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
335 (setq family (capitalize (match-string 1 name)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
336 (setq entry (vassoc family (aref dcache 0))))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
337 (when (and (null entry)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
338 (string-match x-font-regexp-foundry-and-family truename))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
339 (setq family (capitalize (match-string 1 truename)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
340 (setq entry (vassoc family (aref dcache 0))))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
341 (when (null entry)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
342 (return-from font-menu-font-data (make-vector 5 nil)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
343
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
344 (when (string-match x-font-regexp name)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
345 (setq weight (capitalize (match-string 1 name)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
346 (setq size (string-to-int (match-string 6 name))))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
347
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
348 (when (string-match x-font-regexp truename)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
349 (when (not (member weight (aref entry 1)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
350 (setq weight (capitalize (match-string 1 truename))))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
351 (when (not (member size (aref entry 2)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
352 (setq size (string-to-int (match-string 6 truename))))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
353 (setq slant (capitalize (match-string 2 truename))))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
354
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
355 (vector entry family size weight slant)))
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
356
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (defun font-menu-family-constructor (ignored)
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
359 (catch 'menu
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
360 (unless (eq 'x (device-type (selected-device)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
361 (throw 'menu '(["Cannot parse current font" ding nil])))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
362 (let* ((dcache (device-fonts-cache))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
363 (font-data (font-menu-font-data 'default dcache))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
364 (entry (aref font-data 0))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
365 (family (aref font-data 1))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
366 (size (aref font-data 2))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
367 (weight (aref font-data 3))
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 76
diff changeset
368 f)
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
369 (unless family
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
370 (throw 'menu '(["Cannot parse current font" ding nil])))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
371 ;; Items on the Font menu are enabled iff that font exists in
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
372 ;; the same size and weight as the current font (scalable fonts
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
373 ;; exist in every size). Only the current font is marked as
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
374 ;; selected.
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
375 (mapcar
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
376 (lambda (item)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
377 (setq f (aref item 0)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
378 entry (vassoc f (aref dcache 0)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
379 (if (and (member weight (aref entry 1))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
380 (or (member size (aref entry 2))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
381 (and (not font-menu-ignore-scaled-fonts)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
382 (member 0 (aref entry 2)))))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
383 (enable-menu-item item)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
384 (disable-menu-item item))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
385 (if (string-equal family f)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
386 (select-toggle-menu-item item)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
387 (deselect-toggle-menu-item item))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
388 item)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
389 (aref dcache 1)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (defun font-menu-size-constructor (ignored)
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
393 (catch 'menu
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
394 (unless (eq 'x (device-type (selected-device)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
395 (throw 'menu '(["Cannot parse current font" ding nil])))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
396 (let* ((dcache (device-fonts-cache))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
397 (font-data (font-menu-font-data 'default dcache))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
398 (entry (aref font-data 0))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
399 (family (aref font-data 1))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
400 (size (aref font-data 2))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
401 ;;(weight (aref font-data 3))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
402 s)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
403 (unless family
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
404 (throw 'menu '(["Cannot parse current font" ding nil])))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
405 ;; Items on the Size menu are enabled iff current font has
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
406 ;; that size. Only the size of the current font is selected.
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
407 ;; (If the current font comes in size 0, it is scalable, and
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
408 ;; thus has every size.)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
409 (mapcar
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
410 (lambda (item)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
411 (setq s (nth 3 (aref item 1)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
412 (if (or (member s (aref entry 2))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
413 (and (not font-menu-ignore-scaled-fonts)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
414 (member 0 (aref entry 2))))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
415 (enable-menu-item item)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
416 (disable-menu-item item))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
417 (if (eq size s)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
418 (select-toggle-menu-item item)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
419 (deselect-toggle-menu-item item))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
420 item)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
421 (aref dcache 2)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (defun font-menu-weight-constructor (ignored)
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
425 (catch 'menu
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
426 (unless (eq 'x (device-type (selected-device)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
427 (throw 'menu '(["Cannot parse current font" ding nil])))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
428 (let* ((dcache (device-fonts-cache))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
429 (font-data (font-menu-font-data 'default dcache))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
430 (entry (aref font-data 0))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
431 (family (aref font-data 1))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
432 ;;(size (aref font-data 2))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
433 (weight (aref font-data 3))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
434 w)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
435 (unless family
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
436 (throw 'menu '(["Cannot parse current font" ding nil])))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
437 ;; Items on the Weight menu are enabled iff current font
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
438 ;; has that weight. Only the weight of the current font
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
439 ;; is selected.
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
440 (mapcar
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
441 (lambda (item)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
442 (setq w (aref item 0))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
443 (if (member w (aref entry 1))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
444 (enable-menu-item item)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
445 (disable-menu-item item))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
446 (if (string-equal weight w)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
447 (select-toggle-menu-item item)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
448 (deselect-toggle-menu-item item))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
449 item)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
450 (aref dcache 3)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 ;;; Changing font sizes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (defun font-menu-set-font (family weight size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ;; This is what gets run when an item is selected from any of the three
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 ;; fonts menus. It needs to be rather clever.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ;; (size is measured in 10ths of points.)
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
459 (let* ((dcache (device-fonts-cache))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
460 (font-data (font-menu-font-data 'default dcache))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
461 (from-family (aref font-data 1))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
462 (from-size (aref font-data 2))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
463 (from-weight (aref font-data 3))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
464 (from-slant (aref font-data 4))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
465 new-default-face-font)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
466 (unless from-family
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
467 (signal 'error '("couldn't parse font name for default face")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (setq new-default-face-font
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (font-menu-load-font (or family from-family)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (or weight from-weight)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (or size from-size)
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
472 from-slant
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
473 font-menu-preferred-resolution))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
474 (dolist (face (delq 'default (face-list)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
475 (when (face-font-instance face)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
476 (message "Changing font of `%s'..." face)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
477 (condition-case c
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
478 (font-menu-change-face face
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
479 from-family from-weight from-size
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
480 family weight size)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
481 (error
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
482 (display-error c nil)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
483 (sit-for 1)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ;; Set the default face's font after hacking the other faces, so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 ;; the frame size doesn't change until we are all done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ;;; WMP - we need to honor font-menu-this-frame-only-p here!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (set-face-font 'default new-default-face-font
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (and font-menu-this-frame-only-p (selected-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (message "Font %s" (face-font-name 'default))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (defun font-menu-change-face (face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 from-family from-weight from-size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 to-family to-weight to-size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (or (symbolp face) (signal 'wrong-type-argument (list 'symbolp face)))
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
497 (let* ((dcache (device-fonts-cache))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
498 (font-data (font-menu-font-data face dcache))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
499 (face-family (aref font-data 1))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
500 (face-size (aref font-data 2))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
501 (face-weight (aref font-data 3))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
502 (face-slant (aref font-data 4)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
503
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
504 (or face-family
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
505 (signal 'error (list "couldn't parse font name for face" face)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 ;; If this face matches the old default face in the attribute we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ;; are changing, then change it to the new attribute along that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 ;; dimension. Also, the face must have its own global attribute.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 ;; If its value is inherited, we don't touch it. If any of this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 ;; is not true, we leave it alone.
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
512 (when (and (face-font face 'global)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
513 (cond
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
514 (to-family (string-equal face-family from-family))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
515 (to-weight (string-equal face-weight from-weight))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
516 (to-size (= face-size from-size))))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
517 (set-face-font face
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
518 (font-menu-load-font (or to-family face-family)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
519 (or to-weight face-weight)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
520 (or to-size face-size)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
521 face-slant
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
522 font-menu-preferred-resolution)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
523 (and font-menu-this-frame-only-p
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
524 (selected-frame))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525
86
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
526 (defun font-menu-load-font (family weight size slant resolution)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
527 "Try to load a font with the requested properties.
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
528 The weight, slant and resolution are only hints."
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
529 (when (integerp size) (setq size (int-to-string size)))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
530 (let (font)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
531 (catch 'got-font
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
532 (dolist (weight (list weight "*"))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
533 (dolist (slant
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
534 (cond ((string-equal slant "O") '("O" "I" "*"))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
535 ((string-equal slant "I") '("I" "O" "*"))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
536 ((string-equal slant "*") '("*"))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
537 (t (list slant "*"))))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
538 (dolist (resolution
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
539 (if (string-equal resolution "*-*")
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
540 (list resolution)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
541 (list resolution "*-*")))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
542 (when (setq font
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
543 (make-font-instance
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
544 (concat "-*-" family "-" weight "-" slant "-*-*-*-"
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
545 size "-" resolution "-*-*-"
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
546 font-menu-registry-encoding)
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
547 nil t))
364816949b59 Import from CVS: tag r20-0b93
cvs
parents: 82
diff changeset
548 (throw 'got-font font))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (defun flush-device-fonts-cache (device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 ;; by Stig@hackvan.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (let ((elt (assq device device-fonts-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (and elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (setq device-fonts-cache (delq elt device-fonts-cache)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (add-hook 'delete-device-hook 'flush-device-fonts-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (provide 'x-font-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 ;;; x-font-menu.el ends here