annotate lisp/font.el @ 5348:39304a35b6b3

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