annotate lisp/w3/font.el @ 38:1a767b41a199 r19-15b102

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