Mercurial > hg > xemacs-beta
annotate lisp/x-font-menu.el @ 5344:2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
2011-01-22 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-setq, byte-compile-set):
Remove kludge allowing keywords' values to be set, all the code
that does that is gone.
* cl-compat.el (elt-satisfies-test-p):
* faces.el (set-face-parent):
* faces.el (face-doc-string):
* gtk-font-menu.el:
* gtk-font-menu.el (gtk-reset-device-font-menus):
* msw-font-menu.el:
* msw-font-menu.el (mswindows-reset-device-font-menus):
* package-get.el (package-get-installedp):
* select.el (select-convert-from-image-data):
* sound.el:
* sound.el (load-sound-file):
* x-font-menu.el (x-reset-device-font-menus-core):
Don't quote keywords, they're self-quoting, and the
win from backward-compatibility is sufficiently small now that the
style problem overrides it.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 22 Jan 2011 23:29:25 +0000 |
parents | e29fcfd8df5f |
children | 0af042a0c116 |
rev | line source |
---|---|
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 | |
3094 | 37 (when (featurep 'xft-fonts) |
38 (require 'fontconfig)) | |
39 | |
502 | 40 (globally-declare-boundp |
41 '(x-font-regexp | |
2297 | 42 x-font-regexp-foundry-and-family |
43 x-font-regexp-spacing)) | |
502 | 44 |
4103 | 45 (globally-declare-boundp |
46 '(charset-registries | |
47 fc-find-available-font-families | |
48 fc-find-available-weights-for-family | |
49 fc-font-match | |
50 fc-font-slant-translate-from-string | |
51 fc-font-slant-translate-to-string | |
52 fc-font-weight-translate-from-string | |
53 fc-font-weight-translate-to-string | |
54 fc-name-parse | |
55 fc-name-unparse | |
56 fc-pattern-add-family | |
57 fc-pattern-add-size | |
58 fc-pattern-add-slant | |
59 fc-pattern-add-weight | |
60 fc-pattern-get-family | |
61 fc-pattern-get-size | |
62 fc-pattern-get-slant | |
63 fc-pattern-get-successp | |
64 fc-pattern-get-weight | |
65 make-fc-pattern | |
66 xlfd-font-name-p)) | |
502 | 67 |
428 | 68 (defvar x-font-menu-registry-encoding nil |
69 "Registry and encoding to use with font menu fonts.") | |
70 | |
71 (defvar x-fonts-menu-junk-families | |
444 | 72 (mapconcat |
73 #'identity | |
74 '("cursor" "glyph" "symbol" ; Obvious losers. | |
75 "\\`Ax...\\'" ; FrameMaker fonts - there are just way too | |
428 | 76 ; many of these, and there is a different |
77 ; font family for each font face! Losers. | |
78 ; "Axcor" -> "Applix Courier Roman", | |
79 ; "Axcob" -> "Applix Courier Bold", etc. | |
444 | 80 ) |
81 "\\|") | |
2297 | 82 "Regexp matching font families which should not be menu-selectable. |
83 E.g. cursor fonts.") | |
428 | 84 |
85 (defun hack-font-truename (fn) | |
2297 | 86 ;; #### Are "font sets" XFontSets? |
87 ;; #### Is this useful if not configure'd --with-xfs? | |
88 ;; #### This is duplicated in gtk-font-menu.el. | |
89 "Filter the output of `font-instance-truename' to deal with font sets." | |
428 | 90 (if (string-match "," (font-instance-truename fn)) |
91 (let ((fpnt (nth 8 (split-string (font-instance-name fn) "-"))) | |
92 (flist (split-string (font-instance-truename fn) ",")) | |
93 ret) | |
94 (while flist | |
95 (if (string-equal fpnt (nth 8 (split-string (car flist) "-"))) | |
96 (progn (setq ret (car flist)) (setq flist nil)) | |
97 (setq flist (cdr flist)) | |
98 )) | |
99 ret) | |
100 (font-instance-truename fn))) | |
101 | |
102 (defvar x-font-regexp-ascii nil | |
103 "This is used to filter out font families that can't display ASCII text. | |
104 It must be set at run-time.") | |
105 | |
3094 | 106 ;; #### move these to font-menu.el, and maybe make them defcustoms |
107 (defvar font-menu-common-sizes | |
108 '(60 80 100 110 120 130 140 150 160 170 180 200 220 240 300 360) | |
109 "List of commonly desired font sizes in decipoints.") | |
110 | |
428 | 111 ;;;###autoload |
112 (defun x-reset-device-font-menus (device &optional debug) | |
3094 | 113 (if (featurep 'xft-fonts) |
114 (x-reset-device-font-menus-xft device debug) | |
115 (x-reset-device-font-menus-core device debug))) | |
116 | |
117 (defun fc-make-font-menu-entry (family) | |
118 (let ((weights (fc-find-available-weights-for-family family))) | |
119 (vector | |
120 family | |
121 (mapcar | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
122 (lambda (weight-symbol) |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
123 (let ((pair (assoc weight-symbol |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
124 '((:light "Light") |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
125 (:medium "Medium") |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
126 (:demibold "Demibold") |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
127 (:bold "Bold") |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
128 (:black "Black"))))) |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
129 (if pair (cadr pair)))) |
3094 | 130 weights) |
131 '(0) | |
132 nil))) | |
133 | |
134 (defun x-reset-device-font-menus-xft (device &optional debug) | |
135 (let* ((families-1 (fc-find-available-font-families device)) | |
136 (families (delete-if (lambda (x) | |
137 (string-match x-fonts-menu-junk-families x)) | |
138 (sort families-1 'string-lessp))) | |
139 (data | |
140 (vector | |
141 (mapcar 'fc-make-font-menu-entry families) | |
142 (mapcar | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
143 (lambda (family) |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
144 (vector family `(font-menu-set-font ,family nil nil) |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
145 :style 'radio :active nil :selected nil)) |
3094 | 146 families) |
147 (mapcar | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
148 (lambda (size) |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
149 (vector |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
150 (number-to-string size) |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
151 `(font-menu-set-font nil nil ,size) |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
152 :style 'radio :active nil :selected nil)) |
3094 | 153 ;; common size list in decipoints, fontconfig wants points |
154 (mapcar (lambda (x) (/ x 10)) font-menu-common-sizes)) | |
155 (mapcar | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
156 (lambda (weight) |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
157 (vector |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
158 weight |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
159 `(font-menu-set-font nil ,weight nil) |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
160 :style 'radio :active nil :selected nil)) |
3094 | 161 '("Light" "Medium" "Demibold" "Bold" "Black")))) |
162 ;; get or initialize the entry for device | |
163 (dev-cache (or (assq device device-fonts-cache) | |
164 (car (push (list device) device-fonts-cache))))) | |
165 ;; update the device-fonts-cache entry for device in place | |
166 (setcdr dev-cache data) | |
167 data)) | |
168 | |
169 (defun x-reset-device-font-menus-core (device &optional debug) | |
428 | 170 "Generates the `Font', `Size', and `Weight' submenus for the Options menu. |
171 This is run the first time that a font-menu is needed for each device. | |
172 If you don't like the lazy invocation of this function, you can add it to | |
173 `create-device-hook' and that will make the font menus respond more quickly | |
174 when they are selected for the first time. If you add fonts to your system, | |
175 or if you change your font path, you can call this to re-initialize the menus." | |
176 ;; by Stig@hackvan.com | |
177 ;; #### - this should implement a `menus-only' option, which would | |
2527 | 178 ;; recalculate the menus from the cache w/o having to do font-list again. |
428 | 179 (unless x-font-regexp-ascii |
3917 | 180 (setq x-font-regexp-ascii |
181 (if (fboundp 'charset-registries) | |
182 (elt (charset-registries 'ascii) 0) | |
183 "iso8859-1"))) | |
428 | 184 (setq x-font-menu-registry-encoding |
185 (if (featurep 'mule) "*-*" "iso8859-1")) | |
186 (let ((case-fold-search t) | |
187 family size weight entry monospaced-p | |
188 dev-cache cache families sizes weights) | |
189 (dolist (name (cond ((null debug) ; debugging kludge | |
2527 | 190 (font-list "*-*-*-*-*-*-*-*-*-*-*-*-*-*" device |
1701 | 191 font-menu-max-number)) |
428 | 192 ((stringp debug) (split-string debug "\n")) |
193 (t debug))) | |
194 (when (and (string-match x-font-regexp-ascii name) | |
195 (string-match x-font-regexp name)) | |
196 (setq weight (capitalize (match-string 1 name)) | |
197 size (string-to-int (match-string 6 name))) | |
198 (or (string-match x-font-regexp-foundry-and-family name) | |
199 (error "internal error")) | |
200 (setq family (capitalize (match-string 1 name))) | |
201 (or (string-match x-font-regexp-spacing name) | |
202 (error "internal error")) | |
203 (setq monospaced-p (string= "m" (match-string 1 name))) | |
204 (unless (string-match x-fonts-menu-junk-families family) | |
205 (setq entry (or (vassoc family cache) | |
206 (car (setq cache | |
207 (cons (vector family nil nil t) | |
208 cache))))) | |
209 (or (member family families) (push family families)) | |
210 (or (member weight weights) (push weight weights)) | |
211 (or (member size sizes) (push size sizes)) | |
212 (or (member weight (aref entry 1)) (push weight (aref entry 1))) | |
213 (or (member size (aref entry 2)) (push size (aref entry 2))) | |
214 (aset entry 3 (and (aref entry 3) monospaced-p))))) | |
215 ;; | |
216 ;; Hack scalable fonts. | |
217 ;; Some fonts come only in scalable versions (the only size is 0) | |
218 ;; and some fonts come in both scalable and non-scalable versions | |
219 ;; (one size is 0). If there are any scalable fonts at all, make | |
220 ;; sure that the union of all point sizes contains at least some | |
221 ;; common sizes - it's possible that some sensible sizes might end | |
222 ;; up not getting mentioned explicitly. | |
223 ;; | |
224 (if (member 0 sizes) | |
3094 | 225 (let ((common font-menu-common-sizes)) |
428 | 226 (while common |
227 (or;;(member (car common) sizes) ; not enough slack | |
228 (let ((rest sizes) | |
229 (done nil)) | |
230 (while (and (not done) rest) | |
231 (if (and (> (car common) (- (car rest) 5)) | |
232 (< (car common) (+ (car rest) 5))) | |
233 (setq done t)) | |
234 (setq rest (cdr rest))) | |
235 done) | |
236 (setq sizes (cons (car common) sizes))) | |
237 (setq common (cdr common))) | |
238 (setq sizes (delq 0 sizes)))) | |
239 | |
240 (setq families (sort families 'string-lessp) | |
241 weights (sort weights 'string-lessp) | |
242 sizes (sort sizes '<)) | |
243 | |
244 (dolist (entry cache) | |
245 (aset entry 1 (sort (aref entry 1) 'string-lessp)) | |
246 (aset entry 2 (sort (aref entry 2) '<))) | |
247 | |
248 (setq dev-cache (assq device device-fonts-cache)) | |
249 (or dev-cache | |
250 (setq dev-cache (car (push (list device) device-fonts-cache)))) | |
251 (setcdr | |
252 dev-cache | |
253 (vector | |
254 cache | |
255 (mapcar (lambda (x) | |
5344
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
256 (vector x |
428 | 257 (list 'font-menu-set-font x nil nil) |
5344
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
258 :style 'radio :active nil :selected nil)) |
428 | 259 families) |
260 (mapcar (lambda (x) | |
261 (vector (if (/= 0 (% x 10)) | |
1104 | 262 (number-to-string (/ x 10.0)) |
263 (number-to-string (/ x 10))) | |
428 | 264 (list 'font-menu-set-font nil nil x) |
5344
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
265 :style 'radio :active nil :selected nil)) |
428 | 266 sizes) |
267 (mapcar (lambda (x) | |
268 (vector x | |
269 (list 'font-menu-set-font nil x nil) | |
5344
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
270 :style 'radio :active nil :selected nil)) |
428 | 271 weights))) |
272 (cdr dev-cache))) | |
273 | |
274 ;; Extract font information from a face. We examine both the | |
275 ;; user-specified font name and the canonical (`true') font name. | |
276 ;; These can appear to have totally different properties. | |
277 ;; For examples, see the prolog above. | |
278 | |
279 ;; We use the user-specified one if possible, else use the truename. | |
280 ;; If the user didn't specify one (with "-dt-*-*", for example) | |
281 ;; get the truename and use the possibly suboptimal data from that. | |
282 ;;;###autoload | |
523 | 283 (defun x-font-menu-font-data (face dcache) |
3094 | 284 (let* ((case-fold-search t) |
285 (domain (if font-menu-this-frame-only-p | |
286 (selected-frame) | |
287 (selected-device))) | |
288 (name (font-instance-name (face-font-instance face domain)))) | |
289 (if (featurep 'xft-fonts) | |
290 (if (xlfd-font-name-p name) | |
291 ;; #### this call to x-font-menu-font-data-core originally | |
292 ;; had 4 args, and that's probably the right way to go | |
293 (x-font-menu-font-data-core face dcache) | |
3394 | 294 (x-font-menu-font-data-xft face dcache name (selected-device))) |
3094 | 295 ;; #### this one, too |
296 (x-font-menu-font-data-core face dcache)))) | |
297 | |
298 (defun x-font-menu-font-data-xft (face dcache name domain) | |
3360 | 299 ;; DOMAIN is expected to be a device. |
3094 | 300 (let* ((truename (font-instance-truename |
301 (face-font-instance face domain | |
302 (if (featurep 'mule) 'ascii)))) | |
303 entry) | |
304 (if (xlfd-font-name-p truename) | |
305 (progn | |
306 nil) | |
307 (progn | |
3360 | 308 (let* ((pattern (fc-font-match domain (fc-name-parse name))) |
3094 | 309 (family (and pattern |
310 (fc-pattern-get-family pattern 0)))) | |
311 (if (fc-pattern-get-successp family) | |
312 (setq entry (vassoc family (aref dcache 0)))) | |
313 (if (null entry) | |
314 (make-vector 5 nil) | |
315 (let ((weight (fc-pattern-get-weight pattern 0)) | |
316 (size (fc-pattern-get-size pattern 0)) | |
317 (slant (fc-pattern-get-slant pattern 0))) | |
318 (vector | |
319 entry | |
320 (if (fc-pattern-get-successp family) | |
321 family) | |
322 (if (fc-pattern-get-successp size) | |
323 size) | |
324 (if (fc-pattern-get-successp weight) | |
325 (fc-font-weight-translate-to-string weight)) | |
326 (if (fc-pattern-get-successp slant) | |
327 (fc-font-slant-translate-to-string slant)))))))))) | |
328 | |
329 (defun x-font-menu-font-data-core (face dcache) | |
428 | 330 (let* ((case-fold-search t) |
331 (domain (if font-menu-this-frame-only-p | |
332 (selected-frame) | |
333 (selected-device))) | |
334 (name (font-instance-name (face-font-instance face domain))) | |
335 (truename (font-instance-truename | |
336 (face-font-instance face domain | |
337 (if (featurep 'mule) 'ascii)))) | |
338 family size weight entry slant) | |
339 (when (string-match x-font-regexp-foundry-and-family name) | |
340 (setq family (capitalize (match-string 1 name))) | |
341 (setq entry (vassoc family (aref dcache 0)))) | |
342 (when (and (null entry) | |
343 (string-match x-font-regexp-foundry-and-family truename)) | |
344 (setq family (capitalize (match-string 1 truename))) | |
345 (setq entry (vassoc family (aref dcache 0)))) | |
523 | 346 |
347 (if (null entry) | |
348 (make-vector 5 nil) | |
349 | |
350 (when (string-match x-font-regexp name) | |
351 (setq weight (capitalize (match-string 1 name))) | |
352 (setq size (string-to-int (match-string 6 name)))) | |
428 | 353 |
523 | 354 (when (string-match x-font-regexp truename) |
355 (when (not (member weight (aref entry 1))) | |
356 (setq weight (capitalize (match-string 1 truename)))) | |
357 (when (not (member size (aref entry 2))) | |
358 (setq size (string-to-int (match-string 6 truename)))) | |
359 (setq slant (capitalize (match-string 2 truename)))) | |
428 | 360 |
523 | 361 (vector entry family size weight slant)))) |
428 | 362 |
363 (defun x-font-menu-load-font (family weight size slant resolution) | |
3094 | 364 (if (featurep 'xft-fonts) |
365 (x-font-menu-load-font-xft family weight size slant resolution) | |
366 (x-font-menu-load-font-core family weight size slant resolution))) | |
367 | |
368 (defun x-font-menu-load-font-xft (family weight size slant resolution) | |
369 (let ((pattern (make-fc-pattern))) | |
3354 | 370 (fc-pattern-add-family pattern family) |
3094 | 371 (if weight |
3354 | 372 (fc-pattern-add-weight pattern |
373 (fc-font-weight-translate-from-string weight))) | |
3094 | 374 (if size |
3354 | 375 (fc-pattern-add-size pattern size)) |
3094 | 376 (if slant |
3354 | 377 (fc-pattern-add-slant pattern |
378 (fc-font-slant-translate-from-string slant))) | |
3094 | 379 (make-font-instance (fc-name-unparse pattern)))) |
380 | |
381 (defun x-font-menu-load-font-core (family weight size slant resolution) | |
428 | 382 "Try to load a font with the requested properties. |
383 The weight, slant and resolution are only hints." | |
384 (when (integerp size) (setq size (int-to-string size))) | |
385 (let (font) | |
386 (catch 'got-font | |
387 (dolist (weight (list weight "*")) | |
388 (dolist (slant | |
389 (cond ((string-equal slant "O") '("O" "I" "*")) | |
390 ((string-equal slant "I") '("I" "O" "*")) | |
391 ((string-equal slant "*") '("*")) | |
392 (t (list slant "*")))) | |
393 (dolist (resolution | |
394 (if (string-equal resolution "*-*") | |
395 (list resolution) | |
396 (list resolution "*-*"))) | |
397 (when (setq font | |
398 (make-font-instance | |
399 (concat "-*-" family "-" weight "-" slant "-*-*-*-" | |
400 size "-" resolution "-*-*-" | |
401 x-font-menu-registry-encoding) | |
402 nil t)) | |
403 (throw 'got-font font)))))))) | |
404 | |
405 (provide 'x-font-menu) | |
406 | |
407 ;;; x-font-menu.el ends here |