Mercurial > hg > xemacs-beta
annotate lisp/font.el @ 5881:31dd275fa683
Preserv the current buffer on non-local exit, #'accept-process-output.
2015-03-31 Aidan Kehoe <kehoea@parhasard.net>
* event-stream.c (Faccept_process_output):
Restore the current buffer even on non-local exit in this
function, none of the code that uses #'accept-process-output is
actually prepared to handle the current buffer changing.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Tue, 31 Mar 2015 18:42:21 +0100 |
parents | 23dc211f4d2f |
children |
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) | |
5763
23dc211f4d2f
Make fc-name-parse signal on invalid-argument.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5475
diff
changeset
|
4 ;; Copyright (c) 1996, 1997, 2013 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))) | |
5763
23dc211f4d2f
Make fc-name-parse signal on invalid-argument.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5475
diff
changeset
|
789 ;; names generated by font-instance-truename may contain |
23dc211f4d2f
Make fc-name-parse signal on invalid-argument.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5475
diff
changeset
|
790 ;; unparseable object specifications |
23dc211f4d2f
Make fc-name-parse signal on invalid-argument.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5475
diff
changeset
|
791 (pattern (fc-font-match device (fc-name-parse-harder 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) |