2297
|
1 ;;; x-font-menu.el --- Managing menus of X fonts.
|
428
|
2
|
|
3 ;; Copyright (C) 1994 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
|
|
5 ;; Copyright (C) 1997 Sun Microsystems
|
|
6
|
|
7 ;; Author: Jamie Zawinski <jwz@jwz.org>
|
|
8 ;; Restructured by: Jonathan Stigelman <Stig@hackvan.com>
|
|
9 ;; Mule-ized by: Martin Buchholz
|
|
10 ;; More restructuring for MS-Windows by Andy Piper <andy@xemacs.org>
|
|
11
|
|
12 ;; This file is part of XEmacs.
|
|
13
|
|
14 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
15 ;; under the terms of the GNU General Public License as published by
|
|
16 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
17 ;; any later version.
|
|
18
|
|
19 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
22 ;; General Public License for more details.
|
|
23
|
|
24 ;; You should have received a copy of the GNU General Public License
|
|
25 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
26 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
|
27 ;; Boston, MA 02111-1307, USA.
|
|
28 ;;; Code:
|
|
29
|
|
30 ;; #### - implement these...
|
|
31 ;;
|
|
32 ;;; (defvar font-menu-ignore-proportional-fonts nil
|
|
33 ;;; "*If non-nil, then the font menu will only show fixed-width fonts.")
|
|
34
|
|
35 (require 'font-menu)
|
|
36
|
502
|
37 (globally-declare-boundp
|
|
38 '(x-font-regexp
|
2297
|
39 x-font-regexp-foundry-and-family
|
|
40 x-font-regexp-spacing))
|
502
|
41
|
|
42 (globally-declare-fboundp
|
|
43 '(charset-registry))
|
|
44
|
428
|
45 (defvar x-font-menu-registry-encoding nil
|
|
46 "Registry and encoding to use with font menu fonts.")
|
|
47
|
|
48 (defvar x-fonts-menu-junk-families
|
444
|
49 (mapconcat
|
|
50 #'identity
|
|
51 '("cursor" "glyph" "symbol" ; Obvious losers.
|
|
52 "\\`Ax...\\'" ; FrameMaker fonts - there are just way too
|
428
|
53 ; many of these, and there is a different
|
|
54 ; font family for each font face! Losers.
|
|
55 ; "Axcor" -> "Applix Courier Roman",
|
|
56 ; "Axcob" -> "Applix Courier Bold", etc.
|
444
|
57 )
|
|
58 "\\|")
|
2297
|
59 "Regexp matching font families which should not be menu-selectable.
|
|
60 E.g. cursor fonts.")
|
428
|
61
|
|
62 (defun hack-font-truename (fn)
|
2297
|
63 ;; #### Are "font sets" XFontSets?
|
|
64 ;; #### Is this useful if not configure'd --with-xfs?
|
|
65 ;; #### This is duplicated in gtk-font-menu.el.
|
|
66 "Filter the output of `font-instance-truename' to deal with font sets."
|
428
|
67 (if (string-match "," (font-instance-truename fn))
|
|
68 (let ((fpnt (nth 8 (split-string (font-instance-name fn) "-")))
|
|
69 (flist (split-string (font-instance-truename fn) ","))
|
|
70 ret)
|
|
71 (while flist
|
|
72 (if (string-equal fpnt (nth 8 (split-string (car flist) "-")))
|
|
73 (progn (setq ret (car flist)) (setq flist nil))
|
|
74 (setq flist (cdr flist))
|
|
75 ))
|
|
76 ret)
|
|
77 (font-instance-truename fn)))
|
|
78
|
|
79 (defvar x-font-regexp-ascii nil
|
|
80 "This is used to filter out font families that can't display ASCII text.
|
|
81 It must be set at run-time.")
|
|
82
|
|
83 ;;;###autoload
|
|
84 (defun x-reset-device-font-menus (device &optional debug)
|
|
85 "Generates the `Font', `Size', and `Weight' submenus for the Options menu.
|
|
86 This is run the first time that a font-menu is needed for each device.
|
|
87 If you don't like the lazy invocation of this function, you can add it to
|
|
88 `create-device-hook' and that will make the font menus respond more quickly
|
|
89 when they are selected for the first time. If you add fonts to your system,
|
|
90 or if you change your font path, you can call this to re-initialize the menus."
|
|
91 ;; by Stig@hackvan.com
|
|
92 ;; #### - this should implement a `menus-only' option, which would
|
2527
|
93 ;; recalculate the menus from the cache w/o having to do font-list again.
|
428
|
94 (unless x-font-regexp-ascii
|
|
95 (setq x-font-regexp-ascii (if (featurep 'mule)
|
|
96 (charset-registry 'ascii)
|
|
97 "iso8859-1")))
|
|
98 (setq x-font-menu-registry-encoding
|
|
99 (if (featurep 'mule) "*-*" "iso8859-1"))
|
|
100 (let ((case-fold-search t)
|
|
101 family size weight entry monospaced-p
|
|
102 dev-cache cache families sizes weights)
|
|
103 (dolist (name (cond ((null debug) ; debugging kludge
|
2527
|
104 (font-list "*-*-*-*-*-*-*-*-*-*-*-*-*-*" device
|
1701
|
105 font-menu-max-number))
|
428
|
106 ((stringp debug) (split-string debug "\n"))
|
|
107 (t debug)))
|
|
108 (when (and (string-match x-font-regexp-ascii name)
|
|
109 (string-match x-font-regexp name))
|
|
110 (setq weight (capitalize (match-string 1 name))
|
|
111 size (string-to-int (match-string 6 name)))
|
|
112 (or (string-match x-font-regexp-foundry-and-family name)
|
|
113 (error "internal error"))
|
|
114 (setq family (capitalize (match-string 1 name)))
|
|
115 (or (string-match x-font-regexp-spacing name)
|
|
116 (error "internal error"))
|
|
117 (setq monospaced-p (string= "m" (match-string 1 name)))
|
|
118 (unless (string-match x-fonts-menu-junk-families family)
|
|
119 (setq entry (or (vassoc family cache)
|
|
120 (car (setq cache
|
|
121 (cons (vector family nil nil t)
|
|
122 cache)))))
|
|
123 (or (member family families) (push family families))
|
|
124 (or (member weight weights) (push weight weights))
|
|
125 (or (member size sizes) (push size sizes))
|
|
126 (or (member weight (aref entry 1)) (push weight (aref entry 1)))
|
|
127 (or (member size (aref entry 2)) (push size (aref entry 2)))
|
|
128 (aset entry 3 (and (aref entry 3) monospaced-p)))))
|
|
129 ;;
|
|
130 ;; Hack scalable fonts.
|
|
131 ;; Some fonts come only in scalable versions (the only size is 0)
|
|
132 ;; and some fonts come in both scalable and non-scalable versions
|
|
133 ;; (one size is 0). If there are any scalable fonts at all, make
|
|
134 ;; sure that the union of all point sizes contains at least some
|
|
135 ;; common sizes - it's possible that some sensible sizes might end
|
|
136 ;; up not getting mentioned explicitly.
|
|
137 ;;
|
|
138 (if (member 0 sizes)
|
|
139 (let ((common '(60 80 100 120 140 160 180 240)))
|
|
140 (while common
|
|
141 (or;;(member (car common) sizes) ; not enough slack
|
|
142 (let ((rest sizes)
|
|
143 (done nil))
|
|
144 (while (and (not done) rest)
|
|
145 (if (and (> (car common) (- (car rest) 5))
|
|
146 (< (car common) (+ (car rest) 5)))
|
|
147 (setq done t))
|
|
148 (setq rest (cdr rest)))
|
|
149 done)
|
|
150 (setq sizes (cons (car common) sizes)))
|
|
151 (setq common (cdr common)))
|
|
152 (setq sizes (delq 0 sizes))))
|
|
153
|
|
154 (setq families (sort families 'string-lessp)
|
|
155 weights (sort weights 'string-lessp)
|
|
156 sizes (sort sizes '<))
|
|
157
|
|
158 (dolist (entry cache)
|
|
159 (aset entry 1 (sort (aref entry 1) 'string-lessp))
|
|
160 (aset entry 2 (sort (aref entry 2) '<)))
|
|
161
|
|
162 (setq dev-cache (assq device device-fonts-cache))
|
|
163 (or dev-cache
|
|
164 (setq dev-cache (car (push (list device) device-fonts-cache))))
|
|
165 (setcdr
|
|
166 dev-cache
|
|
167 (vector
|
|
168 cache
|
|
169 (mapcar (lambda (x)
|
|
170 (vector x
|
|
171 (list 'font-menu-set-font x nil nil)
|
|
172 ':style 'radio ':active nil ':selected nil))
|
|
173 families)
|
|
174 (mapcar (lambda (x)
|
|
175 (vector (if (/= 0 (% x 10))
|
1104
|
176 (number-to-string (/ x 10.0))
|
|
177 (number-to-string (/ x 10)))
|
428
|
178 (list 'font-menu-set-font nil nil x)
|
|
179 ':style 'radio ':active nil ':selected nil))
|
|
180 sizes)
|
|
181 (mapcar (lambda (x)
|
|
182 (vector x
|
|
183 (list 'font-menu-set-font nil x nil)
|
|
184 ':style 'radio ':active nil ':selected nil))
|
|
185 weights)))
|
|
186 (cdr dev-cache)))
|
|
187
|
|
188 ;; Extract font information from a face. We examine both the
|
|
189 ;; user-specified font name and the canonical (`true') font name.
|
|
190 ;; These can appear to have totally different properties.
|
|
191 ;; For examples, see the prolog above.
|
|
192
|
|
193 ;; We use the user-specified one if possible, else use the truename.
|
|
194 ;; If the user didn't specify one (with "-dt-*-*", for example)
|
|
195 ;; get the truename and use the possibly suboptimal data from that.
|
|
196 ;;;###autoload
|
523
|
197 (defun x-font-menu-font-data (face dcache)
|
428
|
198 (let* ((case-fold-search t)
|
|
199 (domain (if font-menu-this-frame-only-p
|
|
200 (selected-frame)
|
|
201 (selected-device)))
|
|
202 (name (font-instance-name (face-font-instance face domain)))
|
|
203 (truename (font-instance-truename
|
|
204 (face-font-instance face domain
|
|
205 (if (featurep 'mule) 'ascii))))
|
|
206 family size weight entry slant)
|
|
207 (when (string-match x-font-regexp-foundry-and-family name)
|
|
208 (setq family (capitalize (match-string 1 name)))
|
|
209 (setq entry (vassoc family (aref dcache 0))))
|
|
210 (when (and (null entry)
|
|
211 (string-match x-font-regexp-foundry-and-family truename))
|
|
212 (setq family (capitalize (match-string 1 truename)))
|
|
213 (setq entry (vassoc family (aref dcache 0))))
|
523
|
214
|
|
215 (if (null entry)
|
|
216 (make-vector 5 nil)
|
|
217
|
|
218 (when (string-match x-font-regexp name)
|
|
219 (setq weight (capitalize (match-string 1 name)))
|
|
220 (setq size (string-to-int (match-string 6 name))))
|
428
|
221
|
523
|
222 (when (string-match x-font-regexp truename)
|
|
223 (when (not (member weight (aref entry 1)))
|
|
224 (setq weight (capitalize (match-string 1 truename))))
|
|
225 (when (not (member size (aref entry 2)))
|
|
226 (setq size (string-to-int (match-string 6 truename))))
|
|
227 (setq slant (capitalize (match-string 2 truename))))
|
428
|
228
|
523
|
229 (vector entry family size weight slant))))
|
428
|
230
|
|
231 (defun x-font-menu-load-font (family weight size slant resolution)
|
|
232 "Try to load a font with the requested properties.
|
|
233 The weight, slant and resolution are only hints."
|
|
234 (when (integerp size) (setq size (int-to-string size)))
|
|
235 (let (font)
|
|
236 (catch 'got-font
|
|
237 (dolist (weight (list weight "*"))
|
|
238 (dolist (slant
|
|
239 (cond ((string-equal slant "O") '("O" "I" "*"))
|
|
240 ((string-equal slant "I") '("I" "O" "*"))
|
|
241 ((string-equal slant "*") '("*"))
|
|
242 (t (list slant "*"))))
|
|
243 (dolist (resolution
|
|
244 (if (string-equal resolution "*-*")
|
|
245 (list resolution)
|
|
246 (list resolution "*-*")))
|
|
247 (when (setq font
|
|
248 (make-font-instance
|
|
249 (concat "-*-" family "-" weight "-" slant "-*-*-*-"
|
|
250 size "-" resolution "-*-*-"
|
|
251 x-font-menu-registry-encoding)
|
|
252 nil t))
|
|
253 (throw 'got-font font))))))))
|
|
254
|
|
255 (provide 'x-font-menu)
|
|
256
|
|
257 ;;; x-font-menu.el ends here
|