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