annotate lisp/w3/font.el @ 152:4c132ee2d62b

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