annotate lisp/font.el @ 4453:29efd169efe7

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