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