annotate lisp/font.el @ 304:c6de09ad3017 r21-0b50

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