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