209
|
1 ;; x-font-menu.el --- Managing menus of X fonts.
|
|
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
|
412
|
7 ;; Author: Jamie Zawinski <jwz@netscape.com>
|
209
|
8 ;; Restructured by: Jonathan Stigelman <Stig@hackvan.com>
|
|
9 ;; Mule-ized by: Martin Buchholz
|
414
|
10 ;; More restructuring for MS-Windows by Andy Piper <andy@xemacs.org>
|
209
|
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
|
414
|
35 (require 'font-menu)
|
209
|
36
|
414
|
37 (defvar x-font-menu-registry-encoding nil
|
209
|
38 "Registry and encoding to use with font menu fonts.")
|
|
39
|
414
|
40 (defvar x-fonts-menu-junk-families
|
209
|
41 (purecopy
|
|
42 (mapconcat
|
|
43 #'identity
|
|
44 '("cursor" "glyph" "symbol" ; Obvious losers.
|
|
45 "\\`Ax...\\'" ; FrameMaker fonts - there are just way too
|
|
46 ; many of these, and there is a different
|
|
47 ; font family for each font face! Losers.
|
|
48 ; "Axcor" -> "Applix Courier Roman",
|
|
49 ; "Axcob" -> "Applix Courier Bold", etc.
|
|
50 )
|
|
51 "\\|"))
|
|
52 "A regexp matching font families which are uninteresting (e.g. cursor fonts).")
|
|
53
|
|
54 (defun hack-font-truename (fn)
|
|
55 "Filter the output of `font-instance-truename' to deal with Japanese fontsets."
|
|
56 (if (string-match "," (font-instance-truename fn))
|
|
57 (let ((fpnt (nth 8 (split-string (font-instance-name fn) "-")))
|
|
58 (flist (split-string (font-instance-truename fn) ","))
|
|
59 ret)
|
|
60 (while flist
|
|
61 (if (string-equal fpnt (nth 8 (split-string (car flist) "-")))
|
|
62 (progn (setq ret (car flist)) (setq flist nil))
|
|
63 (setq flist (cdr flist))
|
|
64 ))
|
|
65 ret)
|
|
66 (font-instance-truename fn)))
|
|
67
|
|
68 (defvar x-font-regexp-ascii nil
|
|
69 "This is used to filter out font families that can't display ASCII text.
|
|
70 It must be set at run-time.")
|
|
71
|
|
72 ;;;###autoload
|
414
|
73 (defun x-reset-device-font-menus (device &optional debug)
|
209
|
74 "Generates the `Font', `Size', and `Weight' submenus for the Options menu.
|
|
75 This is run the first time that a font-menu is needed for each device.
|
|
76 If you don't like the lazy invocation of this function, you can add it to
|
|
77 `create-device-hook' and that will make the font menus respond more quickly
|
|
78 when they are selected for the first time. If you add fonts to your system,
|
|
79 or if you change your font path, you can call this to re-initialize the menus."
|
|
80 ;; by Stig@hackvan.com
|
|
81 ;; #### - this should implement a `menus-only' option, which would
|
|
82 ;; recalculate the menus from the cache w/o having to do list-fonts again.
|
414
|
83 (unless x-font-regexp-ascii
|
|
84 (setq x-font-regexp-ascii (if (featurep 'mule)
|
|
85 (charset-registry 'ascii)
|
|
86 "iso8859-1")))
|
|
87 (setq x-font-menu-registry-encoding
|
|
88 (if (featurep 'mule) "*-*" "iso8859-1"))
|
|
89 (let ((case-fold-search t)
|
|
90 family size weight entry monospaced-p
|
|
91 dev-cache cache families sizes weights)
|
|
92 (dolist (name (cond ((null debug) ; debugging kludge
|
|
93 (list-fonts "*-*-*-*-*-*-*-*-*-*-*-*-*-*" device))
|
|
94 ((stringp debug) (split-string debug "\n"))
|
|
95 (t debug)))
|
|
96 (when (and (string-match x-font-regexp-ascii name)
|
|
97 (string-match x-font-regexp name))
|
|
98 (setq weight (capitalize (match-string 1 name))
|
|
99 size (string-to-int (match-string 6 name)))
|
|
100 (or (string-match x-font-regexp-foundry-and-family name)
|
|
101 (error "internal error"))
|
|
102 (setq family (capitalize (match-string 1 name)))
|
|
103 (or (string-match x-font-regexp-spacing name)
|
|
104 (error "internal error"))
|
|
105 (setq monospaced-p (string= "m" (match-string 1 name)))
|
|
106 (unless (string-match x-fonts-menu-junk-families family)
|
|
107 (setq entry (or (vassoc family cache)
|
|
108 (car (setq cache
|
|
109 (cons (vector family nil nil t)
|
|
110 cache)))))
|
|
111 (or (member family families) (push family families))
|
|
112 (or (member weight weights) (push weight weights))
|
|
113 (or (member size sizes) (push size sizes))
|
|
114 (or (member weight (aref entry 1)) (push weight (aref entry 1)))
|
|
115 (or (member size (aref entry 2)) (push size (aref entry 2)))
|
|
116 (aset entry 3 (and (aref entry 3) monospaced-p)))))
|
|
117 ;;
|
|
118 ;; Hack scalable fonts.
|
|
119 ;; Some fonts come only in scalable versions (the only size is 0)
|
|
120 ;; and some fonts come in both scalable and non-scalable versions
|
|
121 ;; (one size is 0). If there are any scalable fonts at all, make
|
|
122 ;; sure that the union of all point sizes contains at least some
|
|
123 ;; common sizes - it's possible that some sensible sizes might end
|
|
124 ;; up not getting mentioned explicitly.
|
|
125 ;;
|
|
126 (if (member 0 sizes)
|
|
127 (let ((common '(60 80 100 120 140 160 180 240)))
|
|
128 (while common
|
|
129 (or;;(member (car common) sizes) ; not enough slack
|
|
130 (let ((rest sizes)
|
|
131 (done nil))
|
|
132 (while (and (not done) rest)
|
|
133 (if (and (> (car common) (- (car rest) 5))
|
|
134 (< (car common) (+ (car rest) 5)))
|
|
135 (setq done t))
|
|
136 (setq rest (cdr rest)))
|
|
137 done)
|
|
138 (setq sizes (cons (car common) sizes)))
|
|
139 (setq common (cdr common)))
|
|
140 (setq sizes (delq 0 sizes))))
|
|
141
|
|
142 (setq families (sort families 'string-lessp)
|
|
143 weights (sort weights 'string-lessp)
|
|
144 sizes (sort sizes '<))
|
|
145
|
|
146 (dolist (entry cache)
|
|
147 (aset entry 1 (sort (aref entry 1) 'string-lessp))
|
|
148 (aset entry 2 (sort (aref entry 2) '<)))
|
209
|
149
|
414
|
150 (setq dev-cache (assq device device-fonts-cache))
|
|
151 (or dev-cache
|
|
152 (setq dev-cache (car (push (list device) device-fonts-cache))))
|
|
153 (setcdr
|
|
154 dev-cache
|
|
155 (vector
|
|
156 cache
|
|
157 (mapcar (lambda (x)
|
|
158 (vector x
|
|
159 (list 'font-menu-set-font x nil nil)
|
|
160 ':style 'radio ':active nil ':selected nil))
|
|
161 families)
|
|
162 (mapcar (lambda (x)
|
|
163 (vector (if (/= 0 (% x 10))
|
|
164 ;; works with no LISP_FLOAT_TYPE
|
|
165 (concat (int-to-string (/ x 10)) "."
|
|
166 (int-to-string (% x 10)))
|
|
167 (int-to-string (/ x 10)))
|
|
168 (list 'font-menu-set-font nil nil x)
|
|
169 ':style 'radio ':active nil ':selected nil))
|
|
170 sizes)
|
|
171 (mapcar (lambda (x)
|
|
172 (vector x
|
|
173 (list 'font-menu-set-font nil x nil)
|
|
174 ':style 'radio ':active nil ':selected nil))
|
|
175 weights)))
|
|
176 (cdr dev-cache)))
|
209
|
177
|
|
178 ;; Extract font information from a face. We examine both the
|
|
179 ;; user-specified font name and the canonical (`true') font name.
|
|
180 ;; These can appear to have totally different properties.
|
|
181 ;; For examples, see the prolog above.
|
|
182
|
|
183 ;; We use the user-specified one if possible, else use the truename.
|
|
184 ;; If the user didn't specify one (with "-dt-*-*", for example)
|
|
185 ;; get the truename and use the possibly suboptimal data from that.
|
414
|
186 ;;;###autoload
|
|
187 (defun* x-font-menu-font-data (face dcache)
|
209
|
188 (let* ((case-fold-search t)
|
|
189 (domain (if font-menu-this-frame-only-p
|
|
190 (selected-frame)
|
|
191 (selected-device)))
|
|
192 (name (font-instance-name (face-font-instance face domain)))
|
|
193 (truename (font-instance-truename
|
|
194 (face-font-instance face domain
|
|
195 (if (featurep 'mule) 'ascii))))
|
|
196 family size weight entry slant)
|
|
197 (when (string-match x-font-regexp-foundry-and-family name)
|
|
198 (setq family (capitalize (match-string 1 name)))
|
|
199 (setq entry (vassoc family (aref dcache 0))))
|
|
200 (when (and (null entry)
|
|
201 (string-match x-font-regexp-foundry-and-family truename))
|
|
202 (setq family (capitalize (match-string 1 truename)))
|
|
203 (setq entry (vassoc family (aref dcache 0))))
|
|
204 (when (null entry)
|
414
|
205 (return-from x-font-menu-font-data (make-vector 5 nil)))
|
209
|
206
|
|
207 (when (string-match x-font-regexp name)
|
|
208 (setq weight (capitalize (match-string 1 name)))
|
|
209 (setq size (string-to-int (match-string 6 name))))
|
|
210
|
|
211 (when (string-match x-font-regexp truename)
|
|
212 (when (not (member weight (aref entry 1)))
|
|
213 (setq weight (capitalize (match-string 1 truename))))
|
|
214 (when (not (member size (aref entry 2)))
|
|
215 (setq size (string-to-int (match-string 6 truename))))
|
|
216 (setq slant (capitalize (match-string 2 truename))))
|
|
217
|
|
218 (vector entry family size weight slant)))
|
|
219
|
414
|
220 (defun x-font-menu-load-font (family weight size slant resolution)
|
209
|
221 "Try to load a font with the requested properties.
|
|
222 The weight, slant and resolution are only hints."
|
|
223 (when (integerp size) (setq size (int-to-string size)))
|
|
224 (let (font)
|
|
225 (catch 'got-font
|
|
226 (dolist (weight (list weight "*"))
|
|
227 (dolist (slant
|
|
228 (cond ((string-equal slant "O") '("O" "I" "*"))
|
|
229 ((string-equal slant "I") '("I" "O" "*"))
|
|
230 ((string-equal slant "*") '("*"))
|
|
231 (t (list slant "*"))))
|
|
232 (dolist (resolution
|
|
233 (if (string-equal resolution "*-*")
|
|
234 (list resolution)
|
|
235 (list resolution "*-*")))
|
|
236 (when (setq font
|
|
237 (make-font-instance
|
|
238 (concat "-*-" family "-" weight "-" slant "-*-*-*-"
|
|
239 size "-" resolution "-*-*-"
|
414
|
240 x-font-menu-registry-encoding)
|
209
|
241 nil t))
|
|
242 (throw 'got-font font))))))))
|
|
243
|
|
244 (provide 'x-font-menu)
|
|
245
|
|
246 ;;; x-font-menu.el ends here
|