Mercurial > hg > xemacs-beta
annotate lisp/font.el @ 5673:900a0a8796c3 r21-5-32
XEmacs 21.5.32 "habanero" is released.
author | Stephen J. Turnbull <stephen@xemacs.org> |
---|---|
date | Fri, 03 Aug 2012 02:43:45 +0900 |
parents | 248176c74e6b |
children | 23dc211f4d2f |
rev | line source |
---|---|
428 | 1 ;;; font.el --- New font model |
502 | 2 |
3 ;; Copyright (c) 1995, 1996 by William M. Perry (wmperry@cs.indiana.edu) | |
4 ;; Copyright (c) 1996, 1997 Free Software Foundation, Inc. | |
2527 | 5 ;; Copyright (C) 2002, 2004 Ben Wing. |
502 | 6 |
428 | 7 ;; Author: wmperry |
502 | 8 ;; Maintainer: XEmacs Development Team |
428 | 9 ;; Created: 1997/09/05 15:44:37 |
502 | 10 ;; Keywords: faces |
428 | 11 ;; Version: 1.52 |
502 | 12 |
5287
cd167465bf69
More permission consistency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5178
diff
changeset
|
13 ;; This file is part of XEmacs. |
cd167465bf69
More permission consistency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5178
diff
changeset
|
14 |
5404
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
5178
diff
changeset
|
15 ;; XEmacs is free software: you can redistribute it and/or modify it |
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
5178
diff
changeset
|
16 ;; under the terms of the GNU General Public License as published by the |
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
5178
diff
changeset
|
17 ;; Free Software Foundation, either version 3 of the License, or (at your |
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
5178
diff
changeset
|
18 ;; option) any later version. |
502 | 19 |
5404
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
5178
diff
changeset
|
20 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
5178
diff
changeset
|
21 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
5178
diff
changeset
|
22 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
5178
diff
changeset
|
23 ;; for more details. |
428 | 24 |
502 | 25 ;; You should have received a copy of the GNU General Public License |
5404
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
5178
diff
changeset
|
26 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
502 | 27 |
28 ;;; Synched up with: Not in FSF | |
29 | |
30 ;;; Commentary: | |
428 | 31 |
3094 | 32 ;; This file is totally bogus in the context of Emacs. Much of what it does |
33 ;; is really in the provice of faces (for example all the style parameters), | |
34 ;; and that's the way it is in GNU Emacs. | |
35 ;; | |
36 ;; What is needed for fonts at the Lisp level is a consistent way to access | |
37 ;; face properties that are actually associated with fonts for some rendering | |
38 ;; engine, in other words, the kinds of facilities provided by fontconfig | |
39 ;; patterns. We just need to provide an interface to looking up, storing, | |
40 ;; and manipulating font specifications with certain properties. There will | |
41 ;; be some engine-specific stuff, like the bogosity of X11's character set | |
42 ;; registries. | |
43 | |
502 | 44 ;;; Code: |
45 | |
46 (globally-declare-fboundp | |
2527 | 47 '(internal-facep fontsetp get-font-info |
523 | 48 get-fontset-info mswindows-define-rgb-color cancel-function-timers |
872 | 49 mswindows-font-regexp mswindows-canonicalize-font-name |
50 mswindows-parse-font-style mswindows-construct-font-style | |
4103 | 51 fc-pattern-get-family fc-pattern-get-size fc-pattern-get-weight |
52 fc-font-weight-translate-from-constant make-fc-pattern | |
53 fc-pattern-add-family fc-pattern-add-size)) | |
502 | 54 |
55 (globally-declare-boundp | |
56 '(global-face-data | |
1346 | 57 x-font-regexp x-font-regexp-foundry-and-family |
3094 | 58 fc-font-regexp |
1346 | 59 mswindows-font-regexp)) |
502 | 60 |
428 | 61 (require 'cl) |
62 | |
63 (eval-and-compile | |
64 (defvar device-fonts-cache) | |
65 (condition-case () | |
66 (require 'custom) | |
67 (error nil)) | |
68 (if (and (featurep 'custom) (fboundp 'custom-declare-variable)) | |
69 nil ;; We've got what we needed | |
70 ;; We have the old custom-library, hack around it! | |
71 (defmacro defgroup (&rest args) | |
72 nil) | |
73 (defmacro defcustom (var value doc &rest args) | |
74 `(defvar ,var ,value ,doc)))) | |
75 | |
2527 | 76 ; delete alternate defn of try-font-name |
428 | 77 |
78 (if (not (fboundp 'facep)) | |
79 (defun facep (face) | |
80 "Return t if X is a face name or an internal face vector." | |
81 (if (not window-system) | |
82 nil ; FIXME if FSF ever does TTY faces | |
83 (and (or (internal-facep face) | |
84 (and (symbolp face) (assq face global-face-data))) | |
85 t)))) | |
86 | |
87 (if (not (fboundp 'set-face-property)) | |
88 (defun set-face-property (face property value &optional locale | |
89 tag-set how-to-add) | |
90 "Change a property of FACE." | |
91 (and (symbolp face) | |
92 (put face property value)))) | |
93 | |
94 (if (not (fboundp 'face-property)) | |
95 (defun face-property (face property &optional locale tag-set exact-p) | |
96 "Return FACE's value of the given PROPERTY." | |
97 (and (symbolp face) (get face property)))) | |
98 | |
99 (require 'disp-table) | |
100 | |
101 | |
102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
103 ;;; Lots of variables / keywords for use later in the program | |
104 ;;; Not much should need to be modified | |
105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
3094 | 106 ;; #### These aren't window system mappings |
428 | 107 (defconst font-window-system-mappings |
108 '((x . (x-font-create-name x-font-create-object)) | |
608 | 109 (gtk . (x-font-create-name x-font-create-object)) |
3094 | 110 ;; #### FIXME should this handle fontconfig font objects? |
111 (fc . (fc-font-create-name fc-font-create-object)) | |
428 | 112 (mswindows . (mswindows-font-create-name mswindows-font-create-object)) |
113 (pm . (x-font-create-name x-font-create-object)) ; Change? FIXME | |
3094 | 114 ;; #### what is this bogosity? |
428 | 115 (tty . (tty-font-create-plist tty-font-create-object))) |
707 | 116 "An assoc list mapping device types to a list of translations. |
117 | |
118 The first function creates a font name from a font descriptor object. | |
119 The second performs the reverse translation.") | |
428 | 120 |
121 (defconst x-font-weight-mappings | |
122 '((:extra-light . "extralight") | |
123 (:light . "light") | |
124 (:demi-light . "demilight") | |
125 (:demi . "demi") | |
126 (:book . "book") | |
127 (:medium . "medium") | |
128 (:normal . "medium") | |
129 (:demi-bold . "demibold") | |
130 (:bold . "bold") | |
131 (:extra-bold . "extrabold")) | |
132 "An assoc list mapping keywords to actual Xwindow specific strings | |
133 for use in the 'weight' field of an X font string.") | |
134 | |
135 (defconst font-possible-weights | |
136 (mapcar 'car x-font-weight-mappings)) | |
137 | |
138 (defvar font-rgb-file nil | |
139 "Where the RGB file was found.") | |
140 | |
141 (defvar font-maximum-slippage "1pt" | |
142 "How much a font is allowed to vary from the desired size.") | |
143 | |
707 | 144 ;; Canonical (internal) sizes are in points. |
428 | 145 |
3094 | 146 ;; Property keywords: :family :style :size :registry :encoding :weight |
147 ;; Weight keywords: :extra-light :light :demi-light :medium | |
148 ;; :normal :demi-bold :bold :extra-bold | |
149 ;; See GNU Emacs 21.4 for more properties and keywords we should support | |
428 | 150 |
151 (defvar font-style-keywords nil) | |
152 | |
502 | 153 (defun set-font-family (fontobj family) |
428 | 154 (aset fontobj 1 family)) |
155 | |
502 | 156 (defun set-font-weight (fontobj weight) |
428 | 157 (aset fontobj 3 weight)) |
158 | |
502 | 159 (defun set-font-style (fontobj style) |
428 | 160 (aset fontobj 5 style)) |
161 | |
502 | 162 (defun set-font-size (fontobj size) |
428 | 163 (aset fontobj 7 size)) |
164 | |
502 | 165 (defun set-font-registry (fontobj reg) |
428 | 166 (aset fontobj 9 reg)) |
167 | |
502 | 168 (defun set-font-encoding (fontobj enc) |
428 | 169 (aset fontobj 11 enc)) |
170 | |
502 | 171 (defun font-family (fontobj) |
428 | 172 (aref fontobj 1)) |
173 | |
502 | 174 (defun font-weight (fontobj) |
428 | 175 (aref fontobj 3)) |
176 | |
502 | 177 (defun font-style (fontobj) |
428 | 178 (aref fontobj 5)) |
179 | |
502 | 180 (defun font-size (fontobj) |
428 | 181 (aref fontobj 7)) |
182 | |
502 | 183 (defun font-registry (fontobj) |
428 | 184 (aref fontobj 9)) |
185 | |
502 | 186 (defun font-encoding (fontobj) |
428 | 187 (aref fontobj 11)) |
188 | |
189 (eval-when-compile | |
190 (defmacro define-new-mask (attr mask) | |
191 `(progn | |
192 (setq font-style-keywords | |
193 (cons (cons (quote ,attr) | |
194 (cons | |
195 (quote ,(intern (format "set-font-%s-p" attr))) | |
196 (quote ,(intern (format "font-%s-p" attr))))) | |
197 font-style-keywords)) | |
502 | 198 (defconst ,(intern (format "font-%s-mask" attr)) (lsh 1 ,mask) |
428 | 199 ,(format |
200 "Bitmask for whether a font is to be rendered in %s or not." | |
201 attr)) | |
202 (defun ,(intern (format "font-%s-p" attr)) (fontobj) | |
4577
de0228446b18
Docstring spelling fixes.
"Ville Skyttä <scop@xemacs.org>"
parents:
4453
diff
changeset
|
203 ,(format "Whether FONTOBJ will be rendered in `%s' or not." attr) |
502 | 204 (if (/= 0 (logand (font-style fontobj) |
428 | 205 ,(intern (format "font-%s-mask" attr)))) |
206 t | |
207 nil)) | |
208 (defun ,(intern (format "set-font-%s-p" attr)) (fontobj val) | |
4577
de0228446b18
Docstring spelling fixes.
"Ville Skyttä <scop@xemacs.org>"
parents:
4453
diff
changeset
|
209 ,(format "Set whether FONTOBJ will be rendered in `%s' or not." |
428 | 210 attr) |
211 (cond | |
212 (val | |
502 | 213 (set-font-style fontobj (logior (font-style fontobj) |
214 ,(intern | |
215 (format "font-%s-mask" attr))))) | |
428 | 216 ((,(intern (format "font-%s-p" attr)) fontobj) |
217 (set-font-style fontobj (- (font-style fontobj) | |
218 ,(intern | |
219 (format "font-%s-mask" attr))))))) | |
220 ))) | |
221 | |
523 | 222 (define-new-mask bold 1) |
223 (define-new-mask italic 2) | |
224 (define-new-mask oblique 3) | |
225 (define-new-mask dim 4) | |
226 (define-new-mask underline 5) | |
227 (define-new-mask overline 6) | |
228 (define-new-mask linethrough 7) | |
229 (define-new-mask strikethru 8) | |
230 (define-new-mask reverse 9) | |
231 (define-new-mask blink 10) | |
232 (define-new-mask smallcaps 11) | |
233 (define-new-mask bigcaps 12) | |
234 (define-new-mask dropcaps 13) | |
428 | 235 |
236 (defvar font-caps-display-table | |
237 (let ((table (make-display-table)) | |
238 (i 0)) | |
239 ;; Standard ASCII characters | |
240 (while (< i 26) | |
4451
e214ff9f9507
Use char-tables, not vectors, to instantiate the display table specifiers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
241 (put-display-table (+ i ?a) (+ i ?A) table) |
428 | 242 (setq i (1+ i))) |
243 ;; Now ISO translations | |
3094 | 244 ;; #### FIXME what's this for?? |
428 | 245 (setq i 224) |
246 (while (< i 247) ;; Agrave - Ouml | |
4451
e214ff9f9507
Use char-tables, not vectors, to instantiate the display table specifiers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
247 (put-display-table i (- i 32) table) |
428 | 248 (setq i (1+ i))) |
249 (setq i 248) | |
250 (while (< i 255) ;; Oslash - Thorn | |
4451
e214ff9f9507
Use char-tables, not vectors, to instantiate the display table specifiers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4103
diff
changeset
|
251 (put-display-table i (- i 32) table) |
428 | 252 (setq i (1+ i))) |
253 table)) | |
254 | |
255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
256 ;;; Utility functions | |
257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
3094 | 258 ;; #### unused? |
259 ; (defun set-font-style-by-keywords (fontobj styles) | |
260 ; (make-local-variable 'font-func) | |
261 ; (declare (special font-func)) | |
262 ; (if (listp styles) | |
263 ; (while styles | |
264 ; (setq font-func (car-safe (cdr-safe (assq (car styles) | |
265 ; font-style-keywords))) | |
266 ; styles (cdr styles)) | |
267 ; (and (fboundp font-func) (funcall font-func fontobj t))) | |
268 ; (setq font-func (car-safe (cdr-safe (assq styles font-style-keywords)))) | |
269 ; (and (fboundp font-func) (funcall font-func fontobj t)))) | |
428 | 270 |
3094 | 271 ;; #### unused? |
272 ; (defun font-properties-from-style (fontobj) | |
273 ; (let ((todo font-style-keywords) | |
274 ; type func retval) | |
275 ; (while todo | |
276 ; (setq func (cdr (cdr (car todo))) | |
277 ; type (car (pop todo))) | |
278 ; (if (funcall func fontobj) | |
279 ; (setq retval (cons type retval)))) | |
280 ; retval)) | |
428 | 281 |
282 (defun font-higher-weight (w1 w2) | |
283 (let ((index1 (length (memq w1 font-possible-weights))) | |
284 (index2 (length (memq w2 font-possible-weights)))) | |
285 (cond | |
286 ((<= index1 index2) | |
287 (or w1 w2)) | |
288 ((not w2) | |
289 w1) | |
290 (t | |
291 w2)))) | |
292 | |
293 (defun font-spatial-to-canonical (spec &optional device) | |
707 | 294 "Convert SPEC (in inches, millimeters, points, picas, or pixels) into points. |
295 | |
296 Canonical sizes are in points. If SPEC is null, nil is returned. If SPEC is | |
297 a number, it is interpreted as the desired point size and returned unchanged. | |
298 Otherwise SPEC must be a string consisting of a number and an optional type. | |
299 The type may be the strings \"px\", \"pix\", or \"pixel\" (pixels), \"pt\" or | |
2685 | 300 \"point\" (points), \"pa\" or \"pica\" (picas), \"in\" or \"inch\" (inches), |
301 \"cm\" (centimeters), or \"mm\" (millimeters). | |
707 | 302 |
303 1 in = 2.54 cm = 6 pa = 25.4 mm = 72 pt. Pixel size is device-dependent." | |
428 | 304 (cond |
305 ((numberp spec) | |
306 spec) | |
307 ((null spec) | |
308 nil) | |
309 (t | |
310 (let ((num nil) | |
311 (type nil) | |
312 ;; If for any reason we get null for any of this, default | |
313 ;; to 1024x768 resolution on a 17" screen | |
314 (pix-width (float (or (device-pixel-width device) 1024))) | |
315 (mm-width (float (or (device-mm-width device) 293))) | |
316 (retval nil)) | |
317 (cond | |
3094 | 318 ;; #### this is pretty bogus and should probably be made gone |
319 ;; or supported at a higher level | |
428 | 320 ((string-match "^ *\\([-+*/]\\) *" spec) ; math! whee! |
321 (let ((math-func (intern (match-string 1 spec))) | |
322 (other (font-spatial-to-canonical | |
323 (substring spec (match-end 0) nil))) | |
324 (default (font-spatial-to-canonical | |
325 (font-default-size-for-device device)))) | |
326 (if (fboundp math-func) | |
327 (setq type "px" | |
328 spec (int-to-string (funcall math-func default other))) | |
329 (setq type "px" | |
330 spec (int-to-string other))))) | |
331 ((string-match "[^0-9.]+$" spec) | |
332 (setq type (substring spec (match-beginning 0)) | |
333 spec (substring spec 0 (match-beginning 0)))) | |
334 (t | |
335 (setq type "px" | |
336 spec spec))) | |
337 (setq num (string-to-number spec)) | |
338 (cond | |
339 ((member type '("pixel" "px" "pix")) | |
2685 | 340 (setq retval (* num (/ mm-width pix-width) (/ 72.0 25.4)))) |
428 | 341 ((member type '("point" "pt")) |
342 (setq retval num)) | |
343 ((member type '("pica" "pa")) | |
344 (setq retval (* num 12.0))) | |
345 ((member type '("inch" "in")) | |
346 (setq retval (* num 72.0))) | |
347 ((string= type "mm") | |
348 (setq retval (* num (/ 72.0 25.4)))) | |
349 ((string= type "cm") | |
3094 | 350 (setq retval (* num (/ 72.0 2.54)))) |
428 | 351 (t |
352 (setq retval num)) | |
353 ) | |
354 retval)))) | |
355 | |
356 | |
357 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
358 ;;; The main interface routines - constructors and accessor functions | |
359 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
360 (defun make-font (&rest args) | |
361 (vector :family | |
362 (if (stringp (plist-get args :family)) | |
363 (list (plist-get args :family)) | |
364 (plist-get args :family)) | |
365 :weight | |
366 (plist-get args :weight) | |
367 :style | |
368 (if (numberp (plist-get args :style)) | |
369 (plist-get args :style) | |
370 0) | |
371 :size | |
372 (plist-get args :size) | |
373 :registry | |
374 (plist-get args :registry) | |
375 :encoding | |
376 (plist-get args :encoding))) | |
377 | |
378 (defun font-create-name (fontobj &optional device) | |
707 | 379 "Return a font name constructed from FONTOBJ, appropriate for DEVICE." |
428 | 380 (let* ((type (device-type device)) |
381 (func (car (cdr-safe (assq type font-window-system-mappings))))) | |
382 (and func (fboundp func) (funcall func fontobj device)))) | |
383 | |
384 ;;;###autoload | |
385 (defun font-create-object (fontname &optional device) | |
707 | 386 "Return a font descriptor object for FONTNAME, appropriate for DEVICE." |
428 | 387 (let* ((type (device-type device)) |
388 (func (car (cdr (cdr-safe (assq type font-window-system-mappings)))))) | |
389 (and func (fboundp func) (funcall func fontname device)))) | |
390 | |
391 (defun font-combine-fonts-internal (fontobj-1 fontobj-2) | |
392 (let ((retval (make-font)) | |
393 (size-1 (and (font-size fontobj-1) | |
394 (font-spatial-to-canonical (font-size fontobj-1)))) | |
395 (size-2 (and (font-size fontobj-2) | |
396 (font-spatial-to-canonical (font-size fontobj-2))))) | |
397 (set-font-weight retval (font-higher-weight (font-weight fontobj-1) | |
398 (font-weight fontobj-2))) | |
4607
517f6887fbc0
Remove duplicate functions, chiefly #'delete-duplicates reimplementations.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4577
diff
changeset
|
399 (set-font-family retval |
517f6887fbc0
Remove duplicate functions, chiefly #'delete-duplicates reimplementations.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4577
diff
changeset
|
400 (delete-duplicates (append (font-family fontobj-1) |
4727
90dbf8e772b6
Fix typo in font-combine-fonts-internal.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4607
diff
changeset
|
401 (font-family fontobj-2)) |
90dbf8e772b6
Fix typo in font-combine-fonts-internal.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4607
diff
changeset
|
402 :test #'equal)) |
502 | 403 (set-font-style retval (logior (font-style fontobj-1) |
404 (font-style fontobj-2))) | |
428 | 405 (set-font-registry retval (or (font-registry fontobj-1) |
406 (font-registry fontobj-2))) | |
407 (set-font-encoding retval (or (font-encoding fontobj-1) | |
408 (font-encoding fontobj-2))) | |
409 (set-font-size retval (cond | |
410 ((and size-1 size-2 (>= size-2 size-1)) | |
411 (font-size fontobj-2)) | |
412 ((and size-1 size-2) | |
413 (font-size fontobj-1)) | |
414 (size-1 | |
415 (font-size fontobj-1)) | |
416 (size-2 | |
417 (font-size fontobj-2)) | |
418 (t nil))) | |
419 | |
420 retval)) | |
421 | |
422 (defun font-combine-fonts (&rest args) | |
423 (cond | |
424 ((null args) | |
425 (error "Wrong number of arguments to font-combine-fonts")) | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5287
diff
changeset
|
426 ((eql (length args) 1) |
428 | 427 (car args)) |
428 (t | |
429 (let ((retval (font-combine-fonts-internal (nth 0 args) (nth 1 args)))) | |
430 (setq args (cdr (cdr args))) | |
431 (while args | |
432 (setq retval (font-combine-fonts-internal retval (car args)) | |
433 args (cdr args))) | |
434 retval)))) | |
435 | |
3094 | 436 (defvar font-default-cache nil) |
437 | |
438 ;;;###autoload | |
439 (defun font-default-font-for-device (&optional device) | |
440 (or device (setq device (selected-device))) | |
441 (font-truename | |
442 (make-font-specifier | |
443 (face-font-name 'default device)))) | |
444 | |
445 ;;;###autoload | |
446 (defun font-default-object-for-device (&optional device) | |
447 (let ((font (font-default-font-for-device device))) | |
448 (or (cdr-safe (assoc font font-default-cache)) | |
449 (let ((object (font-create-object font))) | |
450 (push (cons font object) font-default-cache) | |
451 object)))) | |
452 | |
453 ;;;###autoload | |
454 (defun font-default-family-for-device (&optional device) | |
455 (font-family (font-default-object-for-device (or device (selected-device))))) | |
456 | |
457 ;;;###autoload | |
458 (defun font-default-registry-for-device (&optional device) | |
459 (font-registry (font-default-object-for-device (or device (selected-device))))) | |
460 | |
461 ;;;###autoload | |
462 (defun font-default-encoding-for-device (&optional device) | |
463 (font-encoding (font-default-object-for-device (or device (selected-device))))) | |
464 | |
465 ;;;###autoload | |
466 (defun font-default-size-for-device (&optional device) | |
467 ;; face-height isn't the right thing (always 1 pixel too high?) | |
468 ;; (if font-running-xemacs | |
469 ;; (format "%dpx" (face-height 'default device)) | |
470 (font-size (font-default-object-for-device (or device (selected-device))))) | |
471 | |
428 | 472 |
473 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
474 ;;; The window-system dependent code (TTY-style) | |
475 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
476 (defun tty-font-create-object (fontname &optional device) | |
707 | 477 "Return a font descriptor object for FONTNAME, appropriate for TTY devices." |
428 | 478 (make-font :size "12pt")) |
479 | |
480 (defun tty-font-create-plist (fontobj &optional device) | |
707 | 481 "Return a font name constructed from FONTOBJ, appropriate for TTY devices." |
428 | 482 (list |
483 (cons 'underline (font-underline-p fontobj)) | |
484 (cons 'highlight (if (or (font-bold-p fontobj) | |
485 (memq (font-weight fontobj) '(:bold :demi-bold))) | |
486 t)) | |
487 (cons 'dim (font-dim-p fontobj)) | |
488 (cons 'blinking (font-blink-p fontobj)) | |
489 (cons 'reverse (font-reverse-p fontobj)))) | |
490 | |
491 | |
492 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
493 ;;; The window-system dependent code (X-style) | |
494 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
3094 | 495 (defvar font-x-font-regexp (when (and (boundp 'x-font-regexp) |
496 x-font-regexp) | |
428 | 497 (let |
498 ((- "[-?]") | |
499 (foundry "[^-]*") | |
500 (family "[^-]*") | |
502 | 501 ;(weight "\\(bold\\|demibold\\|medium\\|black\\)") |
428 | 502 (weight\? "\\([^-]*\\)") |
502 | 503 ;(slant "\\([ior]\\)") |
428 | 504 (slant\? "\\([^-]?\\)") |
505 (swidth "\\([^-]*\\)") | |
506 (adstyle "\\([^-]*\\)") | |
507 (pixelsize "\\(\\*\\|[0-9]+\\)") | |
508 (pointsize "\\(\\*\\|0\\|[0-9][0-9]+\\)") | |
509 (resx "\\([*0]\\|[0-9][0-9]+\\)") | |
510 (resy "\\([*0]\\|[0-9][0-9]+\\)") | |
511 (spacing "[cmp?*]") | |
512 (avgwidth "\\(\\*\\|[0-9]+\\)") | |
513 (registry "[^-]*") | |
514 (encoding "[^-]+") | |
515 ) | |
516 (concat "\\`\\*?[-?*]" | |
517 foundry - family - weight\? - slant\? - swidth - adstyle - | |
518 pixelsize - pointsize - resx - resy - spacing - avgwidth - | |
519 registry - encoding "\\'" | |
520 )))) | |
521 | |
522 (defvar font-x-registry-and-encoding-regexp | |
3094 | 523 (when (and (boundp 'x-font-regexp-registry-and-encoding) |
524 (symbol-value 'x-font-regexp-registry-and-encoding)) | |
525 (let ((- "[-?]") | |
526 (registry "[^-]*") | |
527 (encoding "[^-]+")) | |
528 (concat - "\\(" registry "\\)" - "\\(" encoding "\\)\\'")))) | |
428 | 529 |
530 (defvar font-x-family-mappings | |
531 '( | |
532 ("serif" . ("new century schoolbook" | |
533 "utopia" | |
534 "charter" | |
535 "times" | |
536 "lucidabright" | |
537 "garamond" | |
538 "palatino" | |
539 "times new roman" | |
540 "baskerville" | |
541 "bookman" | |
542 "bodoni" | |
543 "computer modern" | |
544 "rockwell" | |
545 )) | |
546 ("sans-serif" . ("lucida" | |
547 "helvetica" | |
548 "gills-sans" | |
549 "avant-garde" | |
550 "univers" | |
551 "optima")) | |
552 ("elfin" . ("tymes")) | |
553 ("monospace" . ("courier" | |
554 "fixed" | |
555 "lucidatypewriter" | |
556 "clean" | |
557 "terminal")) | |
558 ("cursive" . ("sirene" | |
559 "zapf chancery")) | |
560 ) | |
561 "A list of font family mappings on X devices.") | |
562 | |
563 (defun x-font-create-object (fontname &optional device) | |
707 | 564 "Return a font descriptor object for FONTNAME, appropriate for X devices." |
428 | 565 (let ((case-fold-search t)) |
566 (if (or (not (stringp fontname)) | |
567 (not (string-match font-x-font-regexp fontname))) | |
4099 | 568 (if (and (stringp fontname) |
4766
32b358a240b0
Avoid calling Xft if not built in.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4759
diff
changeset
|
569 (featurep 'xft-fonts) |
4099 | 570 (string-match font-xft-font-regexp fontname)) |
571 ;; Return an XFT font. | |
572 (xft-font-create-object fontname) | |
573 ;; It's unclear how to parse the font; return an unspecified | |
574 ;; one. | |
575 (make-font)) | |
428 | 576 (let ((family nil) |
577 (size nil) | |
578 (weight (match-string 1 fontname)) | |
579 (slant (match-string 2 fontname)) | |
580 (swidth (match-string 3 fontname)) | |
581 (adstyle (match-string 4 fontname)) | |
582 (pxsize (match-string 5 fontname)) | |
583 (ptsize (match-string 6 fontname)) | |
584 (retval nil) | |
585 (case-fold-search t) | |
586 ) | |
587 (if (not (string-match x-font-regexp-foundry-and-family fontname)) | |
588 nil | |
589 (setq family (list (downcase (match-string 1 fontname))))) | |
590 (if (string= "*" weight) (setq weight nil)) | |
591 (if (string= "*" slant) (setq slant nil)) | |
592 (if (string= "*" swidth) (setq swidth nil)) | |
593 (if (string= "*" adstyle) (setq adstyle nil)) | |
594 (if (string= "*" pxsize) (setq pxsize nil)) | |
595 (if (string= "*" ptsize) (setq ptsize nil)) | |
596 (if ptsize (setq size (/ (string-to-int ptsize) 10))) | |
597 (if (and (not size) pxsize) (setq size (concat pxsize "px"))) | |
598 (if weight (setq weight (intern-soft (concat ":" (downcase weight))))) | |
599 (if (and adstyle (not (equal adstyle ""))) | |
600 (setq family (append family (list (downcase adstyle))))) | |
601 (setq retval (make-font :family family | |
602 :weight weight | |
603 :size size)) | |
604 (set-font-bold-p retval (eq :bold weight)) | |
605 (cond | |
606 ((null slant) nil) | |
607 ((member slant '("i" "I")) | |
608 (set-font-italic-p retval t)) | |
609 ((member slant '("o" "O")) | |
610 (set-font-oblique-p retval t))) | |
611 (when (string-match font-x-registry-and-encoding-regexp fontname) | |
612 (set-font-registry retval (match-string 1 fontname)) | |
613 (set-font-encoding retval (match-string 2 fontname))) | |
614 retval)))) | |
615 | |
616 (defun x-font-families-for-device (&optional device no-resetp) | |
617 (ignore-errors (require 'x-font-menu)) | |
618 (or device (setq device (selected-device))) | |
619 (if (boundp 'device-fonts-cache) | |
620 (let ((menu (or (cdr-safe (assq device device-fonts-cache))))) | |
621 (if (and (not menu) (not no-resetp)) | |
622 (progn | |
623 (reset-device-font-menus device) | |
624 (x-font-families-for-device device t)) | |
625 (let ((scaled (mapcar #'(lambda (x) (if x (aref x 0))) | |
626 (aref menu 0))) | |
627 (normal (mapcar #'(lambda (x) (if x (aref x 0))) | |
628 (aref menu 1)))) | |
4607
517f6887fbc0
Remove duplicate functions, chiefly #'delete-duplicates reimplementations.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4577
diff
changeset
|
629 (sort (delete-duplicates (nconc scaled normal) :test 'equal) |
517f6887fbc0
Remove duplicate functions, chiefly #'delete-duplicates reimplementations.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4577
diff
changeset
|
630 'string-lessp)))) |
428 | 631 (cons "monospace" (mapcar 'car font-x-family-mappings)))) |
632 | |
633 (defun x-font-create-name (fontobj &optional device) | |
707 | 634 "Return a font name constructed from FONTOBJ, appropriate for X devices." |
428 | 635 (if (and (not (or (font-family fontobj) |
636 (font-weight fontobj) | |
637 (font-size fontobj) | |
638 (font-registry fontobj) | |
639 (font-encoding fontobj))) | |
640 (= (font-style fontobj) 0)) | |
641 (face-font 'default) | |
642 (or device (setq device (selected-device))) | |
643 (let* ((default (font-default-object-for-device device)) | |
644 (family (or (font-family fontobj) | |
645 (font-family default) | |
646 (x-font-families-for-device device))) | |
647 (weight (or (font-weight fontobj) :medium)) | |
3094 | 648 (size (or (font-size fontobj) |
428 | 649 (font-size default))) |
650 (registry (or (font-registry fontobj) | |
651 (font-registry default) | |
652 "*")) | |
653 (encoding (or (font-encoding fontobj) | |
654 (font-encoding default) | |
655 "*"))) | |
656 (if (stringp family) | |
657 (setq family (list family))) | |
658 (setq weight (font-higher-weight weight | |
659 (and (font-bold-p fontobj) :bold))) | |
660 (if (stringp size) | |
661 (setq size (truncate (font-spatial-to-canonical size device)))) | |
662 (setq weight (or (cdr-safe (assq weight x-font-weight-mappings)) "*")) | |
663 (let ((done nil) ; Did we find a good font yet? | |
664 (font-name nil) ; font name we are currently checking | |
665 (cur-family nil) ; current family we are checking | |
666 ) | |
667 (while (and family (not done)) | |
668 (setq cur-family (car family) | |
669 family (cdr family)) | |
670 (if (assoc cur-family font-x-family-mappings) | |
671 ;; If the family name is an alias as defined by | |
672 ;; font-x-family-mappings, then append those families | |
673 ;; to the front of 'family' and continue in the loop. | |
674 (setq family (append | |
675 (cdr-safe (assoc cur-family | |
676 font-x-family-mappings)) | |
677 family)) | |
678 ;; Not an alias for a list of fonts, so we just check it. | |
679 ;; First, convert all '-' to spaces so that we don't screw up | |
680 ;; the oh-so wonderful X font model. Wheee. | |
681 (let ((x (length cur-family))) | |
682 (while (> x 0) | |
683 (if (= ?- (aref cur-family (1- x))) | |
684 (aset cur-family (1- x) ? )) | |
685 (setq x (1- x)))) | |
686 ;; We treat oblique and italic as equivalent. Don't ask. | |
687 (let ((slants '("o" "i"))) | |
688 (while (and slants (not done)) | |
689 (setq font-name (format "-*-%s-%s-%s-*-*-*-%s-*-*-*-*-%s-%s" | |
690 cur-family weight | |
691 (if (or (font-italic-p fontobj) | |
692 (font-oblique-p fontobj)) | |
693 (car slants) | |
694 "r") | |
695 (if size | |
696 (int-to-string (* 10 size)) "*") | |
697 registry | |
698 encoding | |
699 ) | |
700 slants (cdr slants) | |
701 done (try-font-name font-name device)))))) | |
702 (if done font-name))))) | |
703 | |
704 | |
3094 | 705 ;;; Cache building code |
706 ;;;###autoload | |
707 (defun x-font-build-cache (&optional device) | |
708 (let ((hash-table (make-hash-table :test 'equal :size 15)) | |
709 (fonts (mapcar 'x-font-create-object | |
710 (font-list "-*-*-*-*-*-*-*-*-*-*-*-*-*-*"))) | |
711 (plist nil) | |
712 (cur nil)) | |
713 (while fonts | |
714 (setq cur (car fonts) | |
715 fonts (cdr fonts) | |
716 plist (cl-gethash (car (font-family cur)) hash-table)) | |
717 (if (not (memq (font-weight cur) (plist-get plist 'weights))) | |
718 (setq plist (plist-put plist 'weights (cons (font-weight cur) | |
719 (plist-get plist 'weights))))) | |
720 (if (not (member (font-size cur) (plist-get plist 'sizes))) | |
721 (setq plist (plist-put plist 'sizes (cons (font-size cur) | |
722 (plist-get plist 'sizes))))) | |
723 (if (and (font-oblique-p cur) | |
724 (not (memq 'oblique (plist-get plist 'styles)))) | |
725 (setq plist (plist-put plist 'styles (cons 'oblique (plist-get plist 'styles))))) | |
726 (if (and (font-italic-p cur) | |
727 (not (memq 'italic (plist-get plist 'styles)))) | |
728 (setq plist (plist-put plist 'styles (cons 'italic (plist-get plist 'styles))))) | |
729 (cl-puthash (car (font-family cur)) plist hash-table)) | |
730 hash-table)) | |
731 | |
732 | |
733 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
734 ;;; The rendering engine-dependent code (Xft-style) | |
735 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
736 | |
737 ;;; #### FIXME actually, this section should be fc-*, right? | |
738 | |
739 (defvar font-xft-font-regexp | |
4099 | 740 (concat "\\`" |
741 #r"\(\\-\|\\:\|\\,\|[^:-]\)*" ; optional foundry and family | |
742 ; (allows for escaped colons, | |
743 ; dashes, commas) | |
744 "\\(-[0-9]*\\(\\.[0-9]*\\)?\\)?" ; optional size (points) | |
745 "\\(:[^:]*\\)*" ; optional properties | |
3094 | 746 ; not necessarily key=value!! |
747 "\\'" | |
4099 | 748 )) |
3094 | 749 |
750 (defvar font-xft-family-mappings | |
751 ;; #### FIXME this shouldn't be needed or used for Xft | |
752 '(("serif" . ("new century schoolbook" | |
753 "utopia" | |
754 "charter" | |
755 "times" | |
756 "lucidabright" | |
757 "garamond" | |
758 "palatino" | |
759 "times new roman" | |
760 "baskerville" | |
761 "bookman" | |
762 "bodoni" | |
763 "computer modern" | |
764 "rockwell" | |
765 )) | |
766 ("sans-serif" . ("lucida" | |
767 "helvetica" | |
768 "gills-sans" | |
769 "avant-garde" | |
770 "univers" | |
771 "optima")) | |
772 ("elfin" . ("tymes")) | |
773 ("monospace" . ("courier" | |
774 "fixed" | |
775 "lucidatypewriter" | |
776 "clean" | |
777 "terminal")) | |
778 ("cursive" . ("sirene" | |
779 "zapf chancery")) | |
780 ) | |
781 "A list of font family mappings on Xft devices.") | |
782 | |
783 (defun xft-font-create-object (fontname &optional device) | |
3360 | 784 "Return a font descriptor object for FONTNAME, appropriate for Xft. |
785 | |
786 Optional DEVICE defaults to `default-x-device'." | |
3094 | 787 (let* ((name fontname) |
788 (device (or device (default-x-device))) | |
3360 | 789 (pattern (fc-font-match device (fc-name-parse name))) |
3094 | 790 (font-obj (make-font)) |
791 (family (fc-pattern-get-family pattern 0)) | |
4362
f5693b5f7f2d
Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents:
4103
diff
changeset
|
792 (size (fc-pattern-get-or-compute-size pattern 0)) |
3094 | 793 (weight (fc-pattern-get-weight pattern 0))) |
794 (set-font-family font-obj | |
795 (and (not (equal family 'fc-result-no-match)) | |
796 family)) | |
797 (set-font-size font-obj | |
798 (and (not (equal size 'fc-result-no-match)) | |
799 size)) | |
800 (set-font-weight font-obj | |
801 (and (not (equal weight 'fc-result-no-match)) | |
802 (fc-font-weight-translate-from-constant weight))) | |
803 font-obj)) | |
804 | |
805 ;; #### FIXME Xft fonts are not defined by the device. | |
806 ;; ... Does that mean the whole model here is bogus? | |
807 (defun xft-font-families-for-device (&optional device no-resetp) | |
808 (ignore-errors (require 'x-font-menu)) ; #### FIXME xft-font-menu? | |
809 (or device (setq device (selected-device))) | |
810 (if (boundp 'device-fonts-cache) ; #### FIXME does this make sense? | |
811 (let ((menu (or (cdr-safe (assq device device-fonts-cache))))) | |
812 (if (and (not menu) (not no-resetp)) | |
813 (progn | |
814 (reset-device-font-menus device) | |
815 (xft-font-families-for-device device t)) | |
816 ;; #### FIXME clearly bogus for Xft | |
817 (let ((scaled (mapcar #'(lambda (x) (if x (aref x 0))) | |
818 (aref menu 0))) | |
819 (normal (mapcar #'(lambda (x) (if x (aref x 0))) | |
820 (aref menu 1)))) | |
4607
517f6887fbc0
Remove duplicate functions, chiefly #'delete-duplicates reimplementations.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4577
diff
changeset
|
821 (sort (delete-duplicates (nconc scaled normal) :test #'equal) |
517f6887fbc0
Remove duplicate functions, chiefly #'delete-duplicates reimplementations.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4577
diff
changeset
|
822 'string-lessp)))) |
3094 | 823 ;; #### FIXME clearly bogus for Xft |
824 (cons "monospace" (mapcar 'car font-xft-family-mappings)))) | |
825 | |
826 (defun xft-font-create-name (fontobj &optional device) | |
827 (let* ((pattern (make-fc-pattern))) | |
828 (if (font-family fontobj) | |
829 (fc-pattern-add-family pattern (font-family fontobj))) | |
830 (if (font-size fontobj) | |
831 (fc-pattern-add-size pattern (font-size fontobj))) | |
832 (fc-name-unparse pattern))) | |
833 | |
834 | |
428 | 835 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
836 ;;; The window-system dependent code (mswindows-style) | |
837 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
838 | |
839 (defconst mswindows-font-weight-mappings | |
872 | 840 '((:thin . "Thin") |
841 (:extra-light . "Extra Light") | |
428 | 842 (:light . "Light") |
872 | 843 (:demi-light . "Light") |
844 (:demi . "Light") | |
845 (:book . "Medium") | |
428 | 846 (:medium . "Medium") |
847 (:normal . "Normal") | |
872 | 848 (:demi-bold . "Demi Bold") |
428 | 849 (:bold . "Bold") |
850 (:regular . "Regular") | |
872 | 851 (:extra-bold . "Extra Bold") |
852 (:heavy . "Heavy")) | |
428 | 853 "An assoc list mapping keywords to actual mswindows specific strings |
854 for use in the 'weight' field of an mswindows font string.") | |
855 | |
856 (defvar font-mswindows-family-mappings | |
857 '( | |
858 ("serif" . ("times new roman" | |
859 "century schoolbook" | |
860 "book antiqua" | |
861 "bookman old style")) | |
862 ("sans-serif" . ("arial" | |
863 "verdana" | |
864 "lucida sans unicode")) | |
865 ("monospace" . ("courier new" | |
866 "lucida console" | |
867 "courier" | |
868 "terminal")) | |
869 ("cursive" . ("roman" | |
870 "script")) | |
871 ) | |
872 "A list of font family mappings on mswindows devices.") | |
873 | |
874 (defun mswindows-font-create-object (fontname &optional device) | |
707 | 875 "Return a font descriptor object for FONTNAME, appropriate for MS Windows devices." |
428 | 876 (let ((case-fold-search t) |
872 | 877 (font (declare-fboundp (mswindows-canonicalize-font-name fontname)))) |
428 | 878 (if (or (not (stringp font)) |
872 | 879 (not (string-match mswindows-font-regexp font))) |
428 | 880 (make-font) |
881 (let ((family (match-string 1 font)) | |
872 | 882 (style (match-string 2 font)) |
883 (pointsize (match-string 3 font)) | |
884 (effects (match-string 4 font)) | |
885 (charset (match-string 5 font)) | |
428 | 886 (retval nil) |
887 (size nil) | |
888 (case-fold-search t) | |
889 ) | |
872 | 890 (destructuring-bind (weight . slant) |
891 (mswindows-parse-font-style style) | |
892 (if (equal pointsize "") (setq pointsize nil)) | |
893 (if pointsize (setq size (concat pointsize "pt"))) | |
894 (if weight (setq weight | |
895 (intern-soft | |
896 (concat ":" (downcase (replace-in-string | |
897 weight " " "-")))))) | |
898 (setq retval (make-font :family family | |
899 :weight weight | |
900 :size size | |
901 :encoding charset)) | |
902 (set-font-bold-p retval (eq :bold weight)) | |
903 (cond | |
904 ((null slant) nil) | |
905 ((string-match "[iI]talic" slant) | |
906 (set-font-italic-p retval t))) | |
907 (cond | |
908 ((null effects) nil) | |
909 ((string-match "^[uU]nderline [sS]trikeout" effects) | |
910 (set-font-underline-p retval t) | |
911 (set-font-strikethru-p retval t)) | |
912 ((string-match "[uU]nderline" effects) | |
913 (set-font-underline-p retval t)) | |
914 ((string-match "[sS]trikeout" effects) | |
915 (set-font-strikethru-p retval t))) | |
916 retval))))) | |
428 | 917 |
918 (defun mswindows-font-create-name (fontobj &optional device) | |
707 | 919 "Return a font name constructed from FONTOBJ, appropriate for MS Windows devices." |
428 | 920 (if (and (not (or (font-family fontobj) |
921 (font-weight fontobj) | |
922 (font-size fontobj) | |
923 (font-registry fontobj) | |
924 (font-encoding fontobj))) | |
925 (= (font-style fontobj) 0)) | |
926 (face-font 'default) | |
927 (or device (setq device (selected-device))) | |
928 (let* ((default (font-default-object-for-device device)) | |
929 (family (or (font-family fontobj) | |
930 (font-family default))) | |
931 (weight (or (font-weight fontobj) :regular)) | |
3094 | 932 (size (or (font-size fontobj) |
428 | 933 (font-size default))) |
934 (underline-p (font-underline-p fontobj)) | |
935 (strikeout-p (font-strikethru-p fontobj)) | |
872 | 936 (encoding (font-encoding fontobj))) |
428 | 937 (if (stringp family) |
938 (setq family (list family))) | |
939 (setq weight (font-higher-weight weight | |
940 (and (font-bold-p fontobj) :bold))) | |
941 (if (stringp size) | |
942 (setq size (truncate (font-spatial-to-canonical size device)))) | |
943 (setq weight (or (cdr-safe | |
944 (assq weight mswindows-font-weight-mappings)) "")) | |
945 (let ((done nil) ; Did we find a good font yet? | |
946 (font-name nil) ; font name we are currently checking | |
947 (cur-family nil) ; current family we are checking | |
948 ) | |
949 (while (and family (not done)) | |
950 (setq cur-family (car family) | |
951 family (cdr family)) | |
952 (if (assoc cur-family font-mswindows-family-mappings) | |
953 ;; If the family name is an alias as defined by | |
954 ;; font-mswindows-family-mappings, then append those families | |
955 ;; to the front of 'family' and continue in the loop. | |
956 (setq family (append | |
957 (cdr-safe (assoc cur-family | |
958 font-mswindows-family-mappings)) | |
959 family)) | |
960 ;; We treat oblique and italic as equivalent. Don't ask. | |
961 ;; Courier New:Bold Italic:10:underline strikeout:western | |
872 | 962 (setq font-name (format "%s:%s:%s:%s:%s" |
963 cur-family | |
964 (mswindows-construct-font-style | |
965 weight | |
966 (if (font-italic-p fontobj) | |
967 "Italic" "")) | |
428 | 968 (if size |
969 (int-to-string size) "10") | |
970 (if underline-p | |
971 (if strikeout-p | |
972 "underline strikeout" | |
973 "underline") | |
974 (if strikeout-p "strikeout" "")) | |
975 (if encoding | |
976 encoding "")) | |
977 done (try-font-name font-name device)))) | |
978 (if done font-name))))) | |
979 | |
980 | |
981 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
982 ;;; Now overwrite the original copy of set-face-font with our own copy that | |
983 ;;; can deal with either syntax. | |
984 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
985 ;;; ###autoload | |
986 (defun font-set-face-font (&optional face font &rest args) | |
987 (cond | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5287
diff
changeset
|
988 ((and (vectorp font) (eql (length font) 12)) |
428 | 989 (let ((font-name (font-create-name font))) |
990 (set-face-property face 'font-specification font) | |
991 (cond | |
992 ((null font-name) ; No matching font! | |
993 nil) | |
994 ((listp font-name) ; For TTYs | |
995 (let (cur) | |
996 (while font-name | |
997 (setq cur (car font-name) | |
998 font-name (cdr font-name)) | |
999 (apply 'set-face-property face (car cur) (cdr cur) args)))) | |
3094 | 1000 (t |
428 | 1001 (apply 'set-face-font face font-name args) |
1002 (apply 'set-face-underline-p face (font-underline-p font) args) | |
1003 (if (and (or (font-smallcaps-p font) (font-bigcaps-p font)) | |
1004 (fboundp 'set-face-display-table)) | |
1005 (apply 'set-face-display-table | |
1006 face font-caps-display-table args)) | |
1007 (apply 'set-face-property face 'strikethru (or | |
1008 (font-linethrough-p font) | |
1009 (font-strikethru-p font)) | |
1010 args)) | |
3094 | 1011 ;;; this used to be default with preceding conditioned on font-running-xemacs |
1012 ; (t | |
1013 ; (condition-case nil | |
1014 ; (apply 'set-face-font face font-name args) | |
1015 ; (error | |
1016 ; (let ((args (car-safe args))) | |
1017 ; (and (or (font-bold-p font) | |
1018 ; (memq (font-weight font) '(:bold :demi-bold))) | |
1019 ; (make-face-bold face args t)) | |
1020 ; (and (font-italic-p font) (make-face-italic face args t))))) | |
1021 ; (apply 'set-face-underline-p face (font-underline-p font) args)) | |
1022 ))) | |
428 | 1023 (t |
1024 ;; Let the original set-face-font signal any errors | |
1025 (set-face-property face 'font-specification nil) | |
1026 (apply 'set-face-font face font args)))) | |
1027 | |
1028 | |
1029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1030 ;;; Now for emacsen specific stuff | |
1031 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1032 (defun font-update-device-fonts (device) | |
1033 ;; Update all faces that were created with the 'font' package | |
1034 ;; to appear correctly on the new device. This should be in the | |
1035 ;; create-device-hook. This is XEmacs 19.12+ specific | |
1036 (let ((faces (face-list 2)) | |
1037 (cur nil) | |
1038 (font-spec nil)) | |
1039 (while faces | |
1040 (setq cur (car faces) | |
1041 faces (cdr faces) | |
1042 font-spec (face-property cur 'font-specification)) | |
1043 (if font-spec | |
1044 (set-face-font cur font-spec device))))) | |
1045 | |
1046 (defun font-update-one-face (face &optional device-list) | |
1047 ;; Update FACE on all devices in DEVICE-LIST | |
1048 ;; DEVICE_LIST defaults to a list of all active devices | |
1049 (setq device-list (or device-list (device-list))) | |
1050 (if (devicep device-list) | |
1051 (setq device-list (list device-list))) | |
1052 (let* ((cur-device nil) | |
502 | 1053 (font-spec (face-property face 'font-specification))) |
428 | 1054 (if (not font-spec) |
1055 ;; Hey! Don't mess with fonts we didn't create in the | |
1056 ;; first place. | |
1057 nil | |
1058 (while device-list | |
1059 (setq cur-device (car device-list) | |
1060 device-list (cdr device-list)) | |
1061 (if (not (device-live-p cur-device)) | |
1062 ;; Whoah! | |
1063 nil | |
1064 (if font-spec | |
1065 (set-face-font face font-spec cur-device))))))) | |
1066 | |
1067 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1068 ;;; Various color related things | |
1069 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1070 | |
1071 (defun font-lookup-rgb-components (color) | |
1072 "Lookup COLOR (a color name) in rgb.txt and return a list of RGB values. | |
1073 The list (R G B) is returned, or an error is signaled if the lookup fails." | |
2527 | 1074 (let ((lib-list (if-boundp 'x-library-search-path |
428 | 1075 x-library-search-path |
1076 (list "/usr/X11R6/lib/X11/" | |
1077 "/usr/X11R5/lib/X11/" | |
1078 "/usr/lib/X11R6/X11/" | |
1079 "/usr/lib/X11R5/X11/" | |
1080 "/usr/local/X11R6/lib/X11/" | |
1081 "/usr/local/X11R5/lib/X11/" | |
1082 "/usr/local/lib/X11R6/X11/" | |
1083 "/usr/local/lib/X11R5/X11/" | |
1084 "/usr/X11/lib/X11/" | |
1085 "/usr/lib/X11/" | |
3125 | 1086 "/usr/share/X11/" |
428 | 1087 "/usr/local/lib/X11/" |
3125 | 1088 "/usr/local/share/X11/" |
428 | 1089 "/usr/X386/lib/X11/" |
1090 "/usr/x386/lib/X11/" | |
1091 "/usr/XFree86/lib/X11/" | |
1092 "/usr/unsupported/lib/X11/" | |
1093 "/usr/athena/lib/X11/" | |
1094 "/usr/local/x11r5/lib/X11/" | |
1095 "/usr/lpp/Xamples/lib/X11/" | |
1096 "/usr/openwin/lib/X11/" | |
1097 "/usr/openwin/share/lib/X11/"))) | |
1098 (file font-rgb-file) | |
1099 r g b) | |
1100 (if (not file) | |
1101 (while lib-list | |
1102 (setq file (expand-file-name "rgb.txt" (car lib-list))) | |
1103 (if (file-readable-p file) | |
1104 (setq lib-list nil | |
1105 font-rgb-file file) | |
1106 (setq lib-list (cdr lib-list) | |
1107 file nil)))) | |
1108 (if (null file) | |
1109 (list 0 0 0) | |
1110 (save-excursion | |
1111 (set-buffer (find-file-noselect file)) | |
1112 (if (not (= (aref (buffer-name) 0) ? )) | |
1113 (rename-buffer (generate-new-buffer-name " *rgb-tmp-buffer*"))) | |
1114 (save-excursion | |
1115 (save-restriction | |
1116 (widen) | |
1117 (goto-char (point-min)) | |
1118 (if (re-search-forward (format "\t%s$" (regexp-quote color)) nil t) | |
1119 (progn | |
1120 (beginning-of-line) | |
1121 (setq r (* (read (current-buffer)) 256) | |
1122 g (* (read (current-buffer)) 256) | |
1123 b (* (read (current-buffer)) 256))) | |
5458
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1124 (display-warning 'color (format "No such color: %s" color)) |
428 | 1125 (setq r 0 |
1126 g 0 | |
1127 b 0)) | |
1128 (list r g b) )))))) | |
1129 | |
1130 (defun font-parse-rgb-components (color) | |
1131 "Parse RGB color specification and return a list of integers (R G B). | |
1132 #FEFEFE and rgb:fe/fe/fe style specifications are parsed." | |
1133 (let ((case-fold-search t) | |
1134 r g b str) | |
1135 (cond ((string-match "^#[0-9a-f]+$" color) | |
1136 (cond | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5287
diff
changeset
|
1137 ((eql (length color) 4) |
5458
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1138 (setq r (string-to-number (substring color 1 2) 16) |
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1139 g (string-to-number (substring color 2 3) 16) |
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1140 b (string-to-number (substring color 3 4) 16) |
428 | 1141 r (* r 4096) |
1142 g (* g 4096) | |
1143 b (* b 4096))) | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5287
diff
changeset
|
1144 ((eql (length color) 7) |
5458
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1145 (setq r (string-to-number (substring color 1 3) 16) |
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1146 g (string-to-number (substring color 3 5) 16) |
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1147 b (string-to-number (substring color 5 7) 16) |
428 | 1148 r (* r 256) |
1149 g (* g 256) | |
1150 b (* b 256))) | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5287
diff
changeset
|
1151 ((eql (length color) 10) |
5458
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1152 (setq r (string-to-number (substring color 1 4) 16) |
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1153 g (string-to-number (substring color 4 7) 16) |
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1154 b (string-to-number (substring color 7 10) 16) |
428 | 1155 r (* r 16) |
1156 g (* g 16) | |
1157 b (* b 16))) | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5287
diff
changeset
|
1158 ((eql (length color) 13) |
5458
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1159 (setq r (string-to-number (substring color 1 5) 16) |
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1160 g (string-to-number (substring color 5 9) 16) |
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1161 b (string-to-number (substring color 9 13) 16))) |
428 | 1162 (t |
5458
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1163 (display-warning 'color |
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1164 (format "Invalid RGB color specification: %s" color)) |
428 | 1165 (setq r 0 |
1166 g 0 | |
1167 b 0)))) | |
1168 ((string-match "rgb:\\([0-9a-f]+\\)/\\([0-9a-f]+\\)/\\([0-9a-f]+\\)" | |
1169 color) | |
1170 (if (or (> (- (match-end 1) (match-beginning 1)) 4) | |
1171 (> (- (match-end 2) (match-beginning 2)) 4) | |
1172 (> (- (match-end 3) (match-beginning 3)) 4)) | |
1173 (error "Invalid RGB color specification: %s" color) | |
1174 (setq str (match-string 1 color) | |
5458
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1175 r (* (string-to-number str 16) |
428 | 1176 (expt 16 (- 4 (length str)))) |
1177 str (match-string 2 color) | |
5458
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1178 g (* (string-to-number str 16) |
428 | 1179 (expt 16 (- 4 (length str)))) |
1180 str (match-string 3 color) | |
5458
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1181 b (* (string-to-number str 16) |
428 | 1182 (expt 16 (- 4 (length str))))))) |
1183 (t | |
5458
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1184 (display-warning 'color (format "Invalid RGB color specification: %s" |
97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1185 color)) |
428 | 1186 (setq r 0 |
1187 g 0 | |
1188 b 0))) | |
1189 (list r g b) )) | |
1190 | |
502 | 1191 (defun font-rgb-color-p (obj) |
428 | 1192 (or (and (vectorp obj) |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5287
diff
changeset
|
1193 (eql (length obj) 4) |
428 | 1194 (eq (aref obj 0) 'rgb)))) |
1195 | |
502 | 1196 (defun font-rgb-color-red (obj) (aref obj 1)) |
1197 (defun font-rgb-color-green (obj) (aref obj 2)) | |
1198 (defun font-rgb-color-blue (obj) (aref obj 3)) | |
428 | 1199 |
1200 (defun font-color-rgb-components (color) | |
1201 "Return the RGB components of COLOR as a list of integers (R G B). | |
1202 16-bit values are always returned. | |
1203 #FEFEFE and rgb:fe/fe/fe style color specifications are parsed directly | |
1204 into their components. | |
1205 RGB values for color names are looked up in the rgb.txt file. | |
1206 The variable x-library-search-path is use to locate the rgb.txt file." | |
1207 (let ((case-fold-search t)) | |
1208 (cond | |
1209 ((and (font-rgb-color-p color) (floatp (aref color 1))) | |
1210 (list (* 65535 (aref color 0)) | |
1211 (* 65535 (aref color 1)) | |
1212 (* 65535 (aref color 2)))) | |
1213 ((font-rgb-color-p color) | |
1214 (list (font-rgb-color-red color) | |
1215 (font-rgb-color-green color) | |
1216 (font-rgb-color-blue color))) | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5287
diff
changeset
|
1217 ((and (vectorp color) (eql 3 (length color))) |
428 | 1218 (list (aref color 0) (aref color 1) (aref color 2))) |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5287
diff
changeset
|
1219 ((and (listp color) (eql 3 (length color)) (floatp (car color))) |
428 | 1220 (mapcar #'(lambda (x) (* x 65535)) color)) |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5287
diff
changeset
|
1221 ((and (listp color) (eql 3 (length color))) |
428 | 1222 color) |
1223 ((or (string-match "^#" color) | |
1224 (string-match "^rgb:" color)) | |
1225 (font-parse-rgb-components color)) | |
1226 ((string-match "\\([0-9.]+\\)[ \t]\\([0-9.]+\\)[ \t]\\([0-9.]+\\)" | |
1227 color) | |
1228 (let ((r (string-to-number (match-string 1 color))) | |
1229 (g (string-to-number (match-string 2 color))) | |
1230 (b (string-to-number (match-string 3 color)))) | |
1231 (if (floatp r) | |
1232 (setq r (round (* 255 r)) | |
1233 g (round (* 255 g)) | |
1234 b (round (* 255 b)))) | |
1235 (font-parse-rgb-components (format "#%02x%02x%02x" r g b)))) | |
1236 (t | |
1237 (font-lookup-rgb-components color))))) | |
1238 | |
502 | 1239 (defun font-tty-compute-color-delta (col1 col2) |
428 | 1240 (+ |
1241 (* (- (aref col1 0) (aref col2 0)) | |
1242 (- (aref col1 0) (aref col2 0))) | |
1243 (* (- (aref col1 1) (aref col2 1)) | |
1244 (- (aref col1 1) (aref col2 1))) | |
1245 (* (- (aref col1 2) (aref col2 2)) | |
1246 (- (aref col1 2) (aref col2 2))))) | |
1247 | |
1248 (defun font-tty-find-closest-color (r g b) | |
1249 ;; This is basically just a lisp copy of allocate_nearest_color | |
5176
8b2f75cecb89
rename objects* (.c, .h and .el files) to fontcolor*
Ben Wing <ben@xemacs.org>
parents:
4766
diff
changeset
|
1250 ;; from fontcolor-x.c from Emacs 19 |
428 | 1251 ;; We really should just check tty-color-list, but unfortunately |
1252 ;; that does not include any RGB information at all. | |
1253 ;; So for now we just hardwire in the default list and call it | |
1254 ;; good for now. | |
1255 (setq r (/ r 65535.0) | |
1256 g (/ g 65535.0) | |
1257 b (/ b 65535.0)) | |
1258 (let* ((color_def (vector r g b)) | |
1259 (colors [([1.0 1.0 1.0] . "white") | |
1260 ([0.0 1.0 1.0] . "cyan") | |
1261 ([1.0 0.0 1.0] . "magenta") | |
1262 ([0.0 0.0 1.0] . "blue") | |
1263 ([1.0 1.0 0.0] . "yellow") | |
1264 ([0.0 1.0 0.0] . "green") | |
1265 ([1.0 0.0 0.0] . "red") | |
1266 ([0.0 0.0 0.0] . "black")]) | |
1267 (no_cells (length colors)) | |
1268 (x 1) | |
1269 (nearest 0) | |
1270 (nearest_delta 0) | |
1271 (trial_delta 0)) | |
1272 (setq nearest_delta (font-tty-compute-color-delta (car (aref colors 0)) | |
1273 color_def)) | |
1274 (while (/= no_cells x) | |
1275 (setq trial_delta (font-tty-compute-color-delta (car (aref colors x)) | |
1276 color_def)) | |
1277 (if (< trial_delta nearest_delta) | |
1278 (setq nearest x | |
1279 nearest_delta trial_delta)) | |
1280 (setq x (1+ x))) | |
1281 (cdr-safe (aref colors nearest)))) | |
1282 | |
1283 (defun font-normalize-color (color &optional device) | |
1284 "Return an RGB tuple, given any form of input. If an error occurs, black | |
1285 is returned." | |
1286 (case (device-type device) | |
1287 ((x pm) | |
1288 (apply 'format "#%02x%02x%02x" (font-color-rgb-components color))) | |
1289 (mswindows | |
1290 (let* ((rgb (font-color-rgb-components color)) | |
1291 (color (apply 'format "#%02x%02x%02x" rgb))) | |
1292 (mswindows-define-rgb-color (nth 0 rgb) (nth 1 rgb) (nth 2 rgb) color) | |
1293 color)) | |
1294 (tty | |
1295 (apply 'font-tty-find-closest-color (font-color-rgb-components color))) | |
1296 (ns | |
502 | 1297 (let ((vals (mapcar #'(lambda (x) (lsh x -8)) |
428 | 1298 (font-color-rgb-components color)))) |
1299 (apply 'format "RGB%02x%02x%02xff" vals))) | |
1300 (otherwise | |
1301 color))) | |
1302 | |
1303 (defun font-set-face-background (&optional face color &rest args) | |
1304 (interactive) | |
1305 (condition-case nil | |
1306 (cond | |
1307 ((or (font-rgb-color-p color) | |
1308 (string-match "^#[0-9a-fA-F]+$" color)) | |
1309 (apply 'set-face-background face | |
1310 (font-normalize-color color) args)) | |
1311 (t | |
1312 (apply 'set-face-background face color args))) | |
1313 (error nil))) | |
1314 | |
1315 (defun font-set-face-foreground (&optional face color &rest args) | |
1316 (interactive) | |
1317 (condition-case nil | |
1318 (cond | |
1319 ((or (font-rgb-color-p color) | |
1320 (string-match "^#[0-9a-fA-F]+$" color)) | |
1321 (apply 'set-face-foreground face (font-normalize-color color) args)) | |
1322 (t | |
1323 (apply 'set-face-foreground face color args))) | |
1324 (error nil))) | |
1325 | |
1326 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1327 ;;; Support for 'blinking' fonts | |
1328 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1329 (defun font-map-windows (func &optional arg frame) | |
1330 (let* ((start (selected-window)) | |
1331 (cur start) | |
1332 (result nil)) | |
1333 (push (funcall func start arg) result) | |
1334 (while (not (eq start (setq cur (next-window cur)))) | |
1335 (push (funcall func cur arg) result)) | |
1336 result)) | |
1337 | |
1338 (defun font-face-visible-in-window-p (window face) | |
1339 (let ((st (window-start window)) | |
1340 (nd (window-end window)) | |
1341 (found nil) | |
1342 (face-at nil)) | |
1343 (setq face-at (get-text-property st 'face (window-buffer window))) | |
1344 (if (or (eq face face-at) (and (listp face-at) (memq face face-at))) | |
1345 (setq found t)) | |
1346 (while (and (not found) | |
1347 (/= nd | |
1348 (setq st (next-single-property-change | |
1349 st 'face | |
1350 (window-buffer window) nd)))) | |
1351 (setq face-at (get-text-property st 'face (window-buffer window))) | |
1352 (if (or (eq face face-at) (and (listp face-at) (memq face face-at))) | |
1353 (setq found t))) | |
1354 found)) | |
1355 | |
1356 (defun font-blink-callback () | |
1357 ;; Optimized to never invert the face unless one of the visible windows | |
1358 ;; is showing it. | |
3094 | 1359 (let ((faces (face-list t)) |
428 | 1360 (obj nil)) |
1361 (while faces | |
1362 (if (and (setq obj (face-property (car faces) 'font-specification)) | |
1363 (font-blink-p obj) | |
1364 (memq t | |
3094 | 1365 (font-map-windows 'font-face-visible-in-window-p |
1366 (car faces)))) | |
428 | 1367 (invert-face (car faces))) |
1368 (pop faces)))) | |
1369 | |
1370 (defcustom font-blink-interval 0.5 | |
1371 "How often to blink faces" | |
1372 :type 'number | |
1373 :group 'faces) | |
1374 | |
1375 (defun font-blink-initialize () | |
1376 (cond | |
1377 ((featurep 'itimer) | |
1378 (if (get-itimer "font-blinker") | |
1379 (delete-itimer (get-itimer "font-blinker"))) | |
1380 (start-itimer "font-blinker" 'font-blink-callback | |
1381 font-blink-interval | |
1382 font-blink-interval)) | |
1383 ((fboundp 'run-at-time) | |
1384 (cancel-function-timers 'font-blink-callback) | |
776 | 1385 (declare-fboundp (run-at-time font-blink-interval |
1386 font-blink-interval | |
1387 'font-blink-callback))) | |
428 | 1388 (t nil))) |
1389 | |
1390 (provide 'font) |