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