annotate lisp/font.el @ 267:966663fcf606 r20-5b32

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