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