comparison lisp/energize/energize-font-size.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 0293115a14e9
comparison
equal deleted inserted replaced
-1:000000000000 0:376386a54a3c
1 ;; interactive adjust font size and face
2 ;; Copyright (C) 1992-1993 Free Software Foundation, Inc.
3
4 ;; This file is part of XEmacs.
5
6 ;; XEmacs is free software; you can redistribute it and/or modify it
7 ;; under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 2, or (at your option)
9 ;; any later version.
10
11 ;; XEmacs is distributed in the hope that it will be useful, but
12 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;; General Public License for more details.
15
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with XEmacs; see the file COPYING. If not, write to the Free
18 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 (defconst energize-x-modify-font-regexp
21 "-\\([^-]+-[^-]+\\)-\\([^-]+\\)-\\([^-]+\\)-\\([^-]+\\)-\\([^-]+\\)-\\([^-]+\\)-\\([^-]+\\)-\\([^-]+\\)-\\([^-]+\\)-\\([^-]+\\)-\\([^-]+\\)-\\([^-]+\\)-\\([^-]+\\)"
22 "Regexpr to extract or modify font entries")
23
24 (defconst energize-font-families-parameters
25 '(("courier" . ("adobe-courier" "o"))
26 ("lucida" . ("b&h-lucida" "i"))
27 ("openwindows" . energize-make-openwindow-font)
28 ("helvetica" . ("adobe-helvetica" "o"))
29 ("times" . ("adobe-times" "i"))
30 ("clean" . ("shumacher-clean" "i"))))
31
32 (defun energize-x-set-font-name-entry (font-name entry value)
33 (if (and font-name (string-match energize-x-modify-font-regexp font-name))
34 (let ((match (substring font-name (match-beginning entry) (match-end entry))))
35 (concat (substring font-name 0 (match-beginning entry))
36 value
37 (substring font-name (match-end entry))))
38 font-name))
39
40 (defun energize-x-set-font-entry (font entry value)
41 (if font
42 (let* ((font-name (if (stringp font) font (font-name font)))
43 (new-name (energize-x-set-font-name-entry font-name entry value)))
44 (if (stringp font)
45 new-name
46 (make-x-font new-name)))))
47
48 (defun energize-x-set-face-font-entry (face entry value)
49 "Sets the face font to be of the specified point size"
50 (let* ((font (face-font face))
51 (new-font (energize-x-set-font-entry font entry value)))
52 (and new-font
53 (condition-case a
54 (set-face-font face new-font)
55 (error (message (format "%S" a)) (sit-for 0))))))
56
57 (defun energize-set-font-size (size)
58 (interactive "sSet new font size to: ")
59 (mapcar '(lambda (face) (energize-x-set-face-font-entry face 7 size))
60 (list-faces)))
61
62 (defun energize-make-openwindow-font (font-name)
63 (string-match energize-x-modify-font-regexp f-name)
64 (let ((slant (substring f-name (match-beginning 3) (match-end 3))))
65 (if (member slant '("i" "o"))
66 (concat
67 (substring f-name 0 (match-beginning 1))
68 "b&h-lucida"
69 (substring f-name (match-end 1) (match-beginning 3))
70 "i"
71 (substring f-name (match-end 3)))
72 (let ((new-name
73 (concat
74 (substring f-name 0 (match-beginning 1))
75 "b&h-lucidatypewriter"
76 (substring f-name (match-end 1) (match-beginning 3))
77 slant
78 (substring f-name (match-end 3)))))
79 ;; tries the R5 name first and the openwindows name second
80 (if (x-list-fonts new-name)
81 new-name
82 (concat
83 (substring f-name 0 (match-beginning 1))
84 "b&h-lucida sans typewriter"
85 (substring f-name (match-end 1) (match-beginning 3))
86 slant
87 (substring f-name (match-end 3))))))))
88
89 (defun energize-set-font-family (family)
90 (interactive "sSet new font family to: ")
91 (let ((font-desc (cdr (assoc family energize-font-families-parameters)))
92 (faces (list-faces)))
93 (if (null font-desc)
94 (error (format "Unknown font family %s, use one of %s" family
95 (mapcar 'car energize-font-families-parameters))))
96 (while faces
97 (let* ((face (car faces))
98 (font (face-font face))
99 (f-name (and font (font-name font))))
100 (if f-name
101 (progn
102 (if (symbolp font-desc)
103 (setq f-name (funcall font-desc f-name))
104 (string-match energize-x-modify-font-regexp f-name)
105 (let ((slant (substring f-name
106 (match-beginning 3) (match-end 3))))
107 (if (member slant '("i" "o"))
108 (setq slant (nth 1 font-desc)))
109 (setq f-name
110 (concat
111 (substring f-name 0 (match-beginning 1))
112 (car font-desc)
113 (substring f-name (match-end 1) (match-beginning 3))
114 slant
115 (substring f-name (match-end 3))))))))
116 (set-face-font face f-name))
117 (setq faces (cdr faces)))))
118
119 (defun energize-set-font-boldness (bold)
120 (interactive "sEnter boldness:")
121 (let* ((default-name (font-name (face-font 'default)))
122 (default-boldness
123 (and (string-match energize-x-modify-font-regexp default-name)
124 (substring default-name (match-beginning 2) (match-end 2)))))
125 (if (not (equal bold default-boldness))
126 (let ((faces (list-faces)))
127 (while faces
128 (let* ((face (car faces))
129 (font (face-font face))
130 (f-name (and font (font-name font))))
131 (if f-name
132 (progn
133 (string-match energize-x-modify-font-regexp f-name)
134 (let ((font-boldness
135 (substring f-name (match-beginning 2) (match-end 2))))
136 (setq new-boldness
137 (if (equal font-boldness "bold")
138 "medium"
139 "bold"))
140 (setq f-name
141 (concat
142 (substring f-name 0 (match-beginning 2))
143 new-boldness
144 (substring f-name (match-end 2)))))
145 (set-face-font face f-name))))
146 (setq faces (cdr faces)))))))