annotate lisp/gtk-font-menu.el @ 5504:d3e0482c7899

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