annotate lisp/w3/font.el @ 2:ac2d302a0011 r19-15b2

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