462
|
1 ;; gtk-font-menu.el --- Managing menus of GTK 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
|
|
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 ;; GTK-ized by: William Perry <wmperry@xemacs.org>
|
|
12
|
|
13 ;; This file is part of XEmacs.
|
|
14
|
|
15 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
16 ;; under the terms of the GNU General Public License as published by
|
|
17 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
18 ;; any later version.
|
|
19
|
|
20 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
23 ;; General Public License for more details.
|
|
24
|
|
25 ;; You should have received a copy of the GNU General Public License
|
|
26 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
27 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
|
28 ;; Boston, MA 02111-1307, USA.
|
|
29 ;;; Code:
|
|
30
|
2297
|
31 ;; #### - The comment that this file was GTK-ized by Wm Perry is a lie;
|
|
32 ;; nothing was done except to rename everything that was x- to gtk-.
|
|
33 ;; This is harmless, but we should reintegrate so that GTK can take
|
|
34 ;; advantage of fontconfig, too, I think.
|
|
35
|
462
|
36 ;; #### - implement these...
|
|
37 ;;
|
|
38 ;;; (defvar font-menu-ignore-proportional-fonts nil
|
|
39 ;;; "*If non-nil, then the font menu will only show fixed-width fonts.")
|
|
40
|
|
41 (require 'font-menu)
|
|
42
|
502
|
43 (globally-declare-boundp
|
|
44 '(gtk-font-regexp
|
2297
|
45 gtk-font-regexp-foundry-and-family
|
|
46 gtk-font-regexp-spacing))
|
502
|
47
|
462
|
48 (defvar gtk-font-menu-registry-encoding nil
|
|
49 "Registry and encoding to use with font menu fonts.")
|
|
50
|
|
51 (defvar gtk-fonts-menu-junk-families
|
|
52 (mapconcat
|
|
53 #'identity
|
|
54 '("cursor" "glyph" "symbol" ; Obvious losers.
|
|
55 "\\`Ax...\\'" ; FrameMaker fonts - there are just way too
|
|
56 ; many of these, and there is a different
|
|
57 ; font family for each font face! Losers.
|
|
58 ; "Axcor" -> "Applix Courier Roman",
|
|
59 ; "Axcob" -> "Applix Courier Bold", etc.
|
|
60 )
|
|
61 "\\|")
|
|
62 "A regexp matching font families which are uninteresting (e.g. cursor fonts).")
|
|
63
|
|
64 (defun hack-font-truename (fn)
|
2297
|
65 ;; #### This is duplicated from x-font-menu.el.
|
|
66 "Filter the output of `font-instance-truename' to deal with font sets."
|
462
|
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 gtk-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 gtk-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.
|
462
|
94 (unless gtk-font-regexp-ascii
|
|
95 (setq gtk-font-regexp-ascii (if (featurep 'mule)
|
502
|
96 (declare-fboundp
|
|
97 (charset-registry 'ascii))
|
462
|
98 "iso8859-1")))
|
|
99 (setq gtk-font-menu-registry-encoding
|
|
100 (if (featurep 'mule) "*-*" "iso8859-1"))
|
|
101 (let ((case-fold-search t)
|
|
102 family size weight entry monospaced-p
|
|
103 dev-cache cache families sizes weights)
|
|
104 (dolist (name (cond ((null debug) ; debugging kludge
|
2527
|
105 (font-list "*-*-*-*-*-*-*-*-*-*-*-*-*-*" device))
|
462
|
106 ((stringp debug) (split-string debug "\n"))
|
|
107 (t debug)))
|
|
108 (when (and (string-match gtk-font-regexp-ascii name)
|
|
109 (string-match gtk-font-regexp name))
|
|
110 (setq weight (capitalize (match-string 1 name))
|
|
111 size (string-to-int (match-string 6 name)))
|
|
112 (or (string-match gtk-font-regexp-foundry-and-family name)
|
|
113 (error "internal error"))
|
|
114 (setq family (capitalize (match-string 1 name)))
|
|
115 (or (string-match gtk-font-regexp-spacing name)
|
|
116 (error "internal error"))
|
|
117 (setq monospaced-p (string= "m" (match-string 1 name)))
|
|
118 (unless (string-match gtk-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)))
|
462
|
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
|
|
197 (defun* gtk-font-menu-font-data (face dcache)
|
|
198 (defvar gtk-font-regexp)
|
|
199 (defvar gtk-font-regexp-foundry-and-family)
|
|
200 (let* ((case-fold-search t)
|
|
201 (domain (if font-menu-this-frame-only-p
|
|
202 (selected-frame)
|
|
203 (selected-device)))
|
|
204 (name (font-instance-name (face-font-instance face domain)))
|
|
205 (truename (font-instance-truename
|
|
206 (face-font-instance face domain
|
|
207 (if (featurep 'mule) 'ascii))))
|
|
208 family size weight entry slant)
|
|
209 (when (string-match gtk-font-regexp-foundry-and-family name)
|
|
210 (setq family (capitalize (match-string 1 name)))
|
|
211 (setq entry (vassoc family (aref dcache 0))))
|
|
212 (when (and (null entry)
|
|
213 (string-match gtk-font-regexp-foundry-and-family truename))
|
|
214 (setq family (capitalize (match-string 1 truename)))
|
|
215 (setq entry (vassoc family (aref dcache 0))))
|
|
216 (when (null entry)
|
|
217 (return-from gtk-font-menu-font-data (make-vector 5 nil)))
|
|
218
|
|
219 (when (string-match gtk-font-regexp name)
|
|
220 (setq weight (capitalize (match-string 1 name)))
|
|
221 (setq size (string-to-int (match-string 6 name))))
|
|
222
|
|
223 (when (string-match gtk-font-regexp truename)
|
|
224 (when (not (member weight (aref entry 1)))
|
|
225 (setq weight (capitalize (match-string 1 truename))))
|
|
226 (when (not (member size (aref entry 2)))
|
|
227 (setq size (string-to-int (match-string 6 truename))))
|
|
228 (setq slant (capitalize (match-string 2 truename))))
|
|
229
|
|
230 (vector entry family size weight slant)))
|
|
231
|
|
232 (defun gtk-font-menu-load-font (family weight size slant resolution)
|
|
233 "Try to load a font with the requested properties.
|
|
234 The weight, slant and resolution are only hints."
|
|
235 (when (integerp size) (setq size (int-to-string size)))
|
|
236 (let (font)
|
|
237 (catch 'got-font
|
|
238 (dolist (weight (list weight "*"))
|
|
239 (dolist (slant
|
|
240 (cond ((string-equal slant "O") '("O" "I" "*"))
|
|
241 ((string-equal slant "I") '("I" "O" "*"))
|
|
242 ((string-equal slant "*") '("*"))
|
|
243 (t (list slant "*"))))
|
|
244 (dolist (resolution
|
|
245 (if (string-equal resolution "*-*")
|
|
246 (list resolution)
|
|
247 (list resolution "*-*")))
|
|
248 (when (setq font
|
|
249 (make-font-instance
|
|
250 (concat "-*-" family "-" weight "-" slant "-*-*-*-"
|
|
251 size "-" resolution "-*-*-"
|
|
252 gtk-font-menu-registry-encoding)
|
|
253 nil t))
|
|
254 (throw 'got-font font))))))))
|
|
255
|
|
256 (provide 'gtk-font-menu)
|
|
257
|
|
258 ;;; gtk-font-menu.el ends here
|