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