Mercurial > emacs
annotate src/xfaces.c @ 25270:7c4983be66e4
(Vfont_list_limit): New.
(syms_of_xfaces): Make it a user-variable.
(DEFAULT_FONT_LIST_LIMIT): New.
(sorted_font_list): If Vfont_list_limit is an integer > 0, list
maximally that number of fonts, otherwise use
DEFAULT_FONT_LIST_LIMIT.
(Fx_font_family_list): Bind `font-list-limit' to higher values
until we have all fonts.
(Fxfont_list): Additionally return the full names of fonts and
their registry and encoding.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Sun, 15 Aug 1999 22:29:45 +0000 |
parents | 11d01c90da6d |
children | 2042c4a224ad |
rev | line source |
---|---|
24995 | 1 /* xfaces.c -- "Face" primitives. |
2 Copyright (C) 1993, 1994, 1998, 1999 Free Software Foundation. | |
2342 | 3 |
2336 | 4 This file is part of GNU Emacs. |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
2342 | 8 the Free Software Foundation; either version 2, or (at your option) |
2336 | 9 any later version. |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14090
diff
changeset
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14090
diff
changeset
|
19 Boston, MA 02111-1307, USA. */ |
2336 | 20 |
24995 | 21 /* New face implementation by Gerd Moellmann <gerd@gnu.org>. */ |
22 | |
23 /* Faces. | |
24 | |
25 When using Emacs with X, the display style of characters can be | |
26 changed by defining `faces'. Each face can specify the following | |
27 display attributes: | |
28 | |
29 1. Font family or fontset alias name. | |
30 | |
31 2. Relative proportionate width, aka character set width or set | |
32 width (swidth), e.g. `semi-compressed'. | |
33 | |
34 3. Font height in 1/10pt | |
35 | |
36 4. Font weight, e.g. `bold'. | |
37 | |
38 5. Font slant, e.g. `italic'. | |
39 | |
40 6. Foreground color. | |
41 | |
42 7. Background color. | |
43 | |
44 8. Whether or not characters should be underlined, and in what color. | |
45 | |
46 9. Whether or not characters should be displayed in inverse video. | |
47 | |
48 10. A background stipple, a bitmap. | |
49 | |
50 11. Whether or not characters should be overlined, and in what color. | |
51 | |
52 12. Whether or not characters should be strike-through, and in what | |
53 color. | |
54 | |
55 13. Whether or not a box should be drawn around characters, the box | |
56 type, and, for simple boxes, in what color. | |
57 | |
58 Faces are frame-local by nature because Emacs allows to define the | |
59 same named face (face names are symbols) differently for different | |
60 frames. Each frame has an alist of face definitions for all named | |
61 faces. The value of a named face in such an alist is a Lisp vector | |
62 with the symbol `face' in slot 0, and a slot for each each of the | |
63 face attributes mentioned above. | |
64 | |
65 There is also a global face alist `Vface_new_frame_defaults'. Face | |
66 definitions from this list are used to initialize faces of newly | |
67 created frames. | |
68 | |
69 A face doesn't have to specify all attributes. Those not specified | |
70 have a value of `unspecified'. Faces specifying all attributes are | |
71 called `fully-specified'. | |
72 | |
73 | |
74 Face merging. | |
75 | |
76 The display style of a given character in the text is determined by | |
77 combining several faces. This process is called `face merging'. | |
78 Any aspect of the display style that isn't specified by overlays or | |
79 text properties is taken from the `default' face. Since it is made | |
80 sure that the default face is always fully-specified, face merging | |
81 always results in a fully-specified face. | |
82 | |
83 | |
84 Face realization. | |
85 | |
86 After all face attributes for a character have been determined by | |
87 merging faces of that character, that face is `realized'. The | |
88 realization process maps face attributes to what is physically | |
89 available on the system where Emacs runs. The result is a | |
90 `realized face' in form of a struct face which is stored in the | |
91 face cache of the frame on which it was realized. | |
92 | |
93 Face realization is done in the context of the charset of the | |
94 character to display because different fonts and encodings are used | |
95 for different charsets. In other words, for characters of | |
96 different charsets, different realized faces are needed to display | |
97 them. | |
98 | |
99 Except for composite characters (CHARSET_COMPOSITION), faces are | |
100 always realized for a specific character set and contain a specific | |
101 font, even if the face being realized specifies a fontset (see | |
102 `font selection' below). The reason is that the result of the new | |
103 font selection stage is better than what can be done with | |
104 statically defined font name patterns in fontsets. | |
105 | |
106 | |
107 Unibyte text. | |
108 | |
109 In unibyte text, Emacs' charsets aren't applicable; function | |
110 `char-charset' reports CHARSET_ASCII for all characters, including | |
111 those > 0x7f. The X registry and encoding of fonts to use is | |
112 determined from the variable `x-unibyte-registry-and-encoding' in | |
113 this case. The variable is initialized at Emacs startup time from | |
114 the font the user specified for Emacs. | |
115 | |
116 Currently all unibyte text, i.e. all buffers with | |
117 enable_multibyte_characters nil are displayed with fonts of the | |
118 same registry and encoding `x-unibyte-registry-and-encoding'. This | |
119 is consistent with the fact that languages can also be set | |
120 globally, only. | |
121 | |
122 | |
123 Font selection. | |
124 | |
125 Font selection tries to find the best available matching font for a | |
126 given (charset, face) combination. This is done slightly | |
127 differently for faces specifying a fontset, or a font family name. | |
128 | |
129 If the face specifies a fontset alias name, that fontset determines | |
130 a pattern for fonts of the given charset. If the face specifies a | |
131 font family, a font pattern is constructed. Charset symbols have a | |
132 property `x-charset-registry' for that purpose that maps a charset | |
133 to an XLFD registry and encoding in the font pattern constructed. | |
134 | |
135 Available fonts on the system on which Emacs runs are then matched | |
136 against the font pattern. The result of font selection is the best | |
137 match for the given face attributes in this font list. | |
138 | |
139 Font selection can be influenced by the user. | |
140 | |
141 1. The user can specify the relative importance he gives the face | |
142 attributes width, height, weight, and slant by setting | |
143 face-font-selection-order (faces.el) to a list of face attribute | |
144 names. The default is '(:width :height :weight :slant), and means | |
145 that font selection first tries to find a good match for the font | |
146 width specified by a face, then---within fonts with that | |
147 width---tries to find a best match for the specified font height, | |
148 etc. | |
149 | |
150 2. Setting face-alternative-font-family-alist allows the user to | |
151 specify alternative font families to try if a family specified by a | |
152 face doesn't exist. | |
153 | |
154 | |
155 Composite characters. | |
156 | |
157 Realized faces for composite characters are the only ones having a | |
158 fontset id >= 0. When a composite character is encoded into a | |
159 sequence of non-composite characters (in xterm.c), a suitable font | |
160 for the non-composite characters is then selected and realized, | |
161 i.e. the realization process is delayed but in principle the same. | |
162 | |
163 | |
164 Initialization of basic faces. | |
165 | |
166 The faces `default', `modeline' are considered `basic faces'. | |
167 When redisplay happens the first time for a newly created frame, | |
168 basic faces are realized for CHARSET_ASCII. Frame parameters are | |
169 used to fill in unspecified attributes of the default face. */ | |
170 | |
171 /* Define SCALABLE_FONTS to a non-zero value to enable scalable | |
172 font use. Define it to zero to disable scalable font use. | |
173 | |
174 Use of too many or too large scalable fonts can crash XFree86 | |
175 servers. That's why I've put the code dealing with scalable fonts | |
176 in #if's. */ | |
177 | |
178 #define SCALABLE_FONTS 1 | |
2342 | 179 |
2336 | 180 #include <sys/types.h> |
181 #include <sys/stat.h> | |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
4258
diff
changeset
|
182 #include <config.h> |
2336 | 183 #include "lisp.h" |
17047 | 184 #include "charset.h" |
18083
c361afa561c5
Include frame.h unconditionally.
Richard M. Stallman <rms@gnu.org>
parents:
17047
diff
changeset
|
185 #include "frame.h" |
c361afa561c5
Include frame.h unconditionally.
Richard M. Stallman <rms@gnu.org>
parents:
17047
diff
changeset
|
186 |
9572 | 187 #ifdef HAVE_X_WINDOWS |
2336 | 188 #include "xterm.h" |
17047 | 189 #include "fontset.h" |
9572 | 190 #endif |
24995 | 191 |
9572 | 192 #ifdef MSDOS |
193 #include "dosfns.h" | |
194 #endif | |
24995 | 195 |
2336 | 196 #include "buffer.h" |
2391 | 197 #include "dispextern.h" |
2438 | 198 #include "blockinput.h" |
2767
482fa0725db6
* xfaces.c (intern_frame_face): Exchange order of arguments, to
Jim Blandy <jimb@redhat.com>
parents:
2743
diff
changeset
|
199 #include "window.h" |
8848 | 200 #include "intervals.h" |
2336 | 201 |
9572 | 202 #ifdef HAVE_X_WINDOWS |
24995 | 203 |
204 /* Compensate for a bug in Xos.h on some systems, on which it requires | |
3997
d968bcba16af
* xfaces.c [XOS_NEEDS_TIME_H]: #undef USG while #including
Jim Blandy <jimb@redhat.com>
parents:
3882
diff
changeset
|
205 time.h. On some such systems, Xos.h tries to redefine struct |
d968bcba16af
* xfaces.c [XOS_NEEDS_TIME_H]: #undef USG while #including
Jim Blandy <jimb@redhat.com>
parents:
3882
diff
changeset
|
206 timeval and struct timezone if USG is #defined while it is |
d968bcba16af
* xfaces.c [XOS_NEEDS_TIME_H]: #undef USG while #including
Jim Blandy <jimb@redhat.com>
parents:
3882
diff
changeset
|
207 #included. */ |
24995 | 208 |
3436
291f28da7ea1
Test XOS_NEEDS_TIME_H, not HPUX, for including time.hj.
Richard M. Stallman <rms@gnu.org>
parents:
3401
diff
changeset
|
209 #ifdef XOS_NEEDS_TIME_H |
3997
d968bcba16af
* xfaces.c [XOS_NEEDS_TIME_H]: #undef USG while #including
Jim Blandy <jimb@redhat.com>
parents:
3882
diff
changeset
|
210 #include <time.h> |
d968bcba16af
* xfaces.c [XOS_NEEDS_TIME_H]: #undef USG while #including
Jim Blandy <jimb@redhat.com>
parents:
3882
diff
changeset
|
211 #undef USG |
d968bcba16af
* xfaces.c [XOS_NEEDS_TIME_H]: #undef USG while #including
Jim Blandy <jimb@redhat.com>
parents:
3882
diff
changeset
|
212 #include <X11/Xos.h> |
d968bcba16af
* xfaces.c [XOS_NEEDS_TIME_H]: #undef USG while #including
Jim Blandy <jimb@redhat.com>
parents:
3882
diff
changeset
|
213 #define USG |
d968bcba16af
* xfaces.c [XOS_NEEDS_TIME_H]: #undef USG while #including
Jim Blandy <jimb@redhat.com>
parents:
3882
diff
changeset
|
214 #define __TIMEVAL__ |
24995 | 215 #else /* not XOS_NEEDS_TIME_H */ |
2336 | 216 #include <X11/Xos.h> |
24995 | 217 #endif /* not XOS_NEEDS_TIME_H */ |
218 | |
9572 | 219 #endif /* HAVE_X_WINDOWS */ |
24995 | 220 |
221 #include <stdio.h> | |
222 #include <stdlib.h> | |
223 #include <ctype.h> | |
224 #include "keyboard.h" | |
225 | |
226 #ifndef max | |
227 #define max(A, B) ((A) > (B) ? (A) : (B)) | |
228 #define min(A, B) ((A) < (B) ? (A) : (B)) | |
229 #define abs(X) ((X) < 0 ? -(X) : (X)) | |
230 #endif | |
231 | |
232 /* Non-zero if face attribute ATTR is unspecified. */ | |
233 | |
234 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified) | |
235 | |
236 /* Value is the number of elements of VECTOR. */ | |
237 | |
238 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR)) | |
239 | |
240 /* Make a copy of string S on the stack using alloca. Value is a pointer | |
241 to the copy. */ | |
242 | |
243 #define STRDUPA(S) strcpy ((char *) alloca (strlen ((S)) + 1), (S)) | |
244 | |
245 /* Make a copy of the contents of Lisp string S on the stack using | |
246 alloca. Value is a pointer to the copy. */ | |
247 | |
248 #define LSTRDUPA(S) STRDUPA (XSTRING ((S))->data) | |
249 | |
250 /* Size of hash table of realized faces in face caches (should be a | |
251 prime number). */ | |
252 | |
253 #define FACE_CACHE_BUCKETS_SIZE 1001 | |
254 | |
255 /* Keyword symbols used for face attribute names. */ | |
256 | |
257 Lisp_Object QCfamily, QCheight, QCweight, QCslant, QCunderline; | |
258 Lisp_Object QCinverse_video, QCforeground, QCbackground, QCstipple; | |
259 Lisp_Object QCwidth, QCfont, QCbold, QCitalic; | |
260 Lisp_Object QCreverse_video; | |
261 Lisp_Object QCoverline, QCstrike_through, QCbox; | |
262 | |
263 /* Symbols used for attribute values. */ | |
264 | |
265 Lisp_Object Qnormal, Qbold, Qultra_light, Qextra_light, Qlight; | |
266 Lisp_Object Qsemi_light, Qsemi_bold, Qextra_bold, Qultra_bold; | |
267 Lisp_Object Qoblique, Qitalic, Qreverse_oblique, Qreverse_italic; | |
268 Lisp_Object Qultra_condensed, Qextra_condensed, Qcondensed; | |
269 Lisp_Object Qsemi_condensed, Qsemi_expanded, Qexpanded, Qextra_expanded; | |
270 Lisp_Object Qultra_expanded; | |
271 Lisp_Object Qreleased_button, Qpressed_button; | |
272 Lisp_Object QCstyle, QCcolor, QCline_width; | |
273 Lisp_Object Qunspecified; | |
274 | |
275 /* The symbol `x-charset-registry'. This property of charsets defines | |
276 the X registry and encoding that fonts should have that are used to | |
277 display characters of that charset. */ | |
278 | |
279 Lisp_Object Qx_charset_registry; | |
280 | |
281 /* Names of basic faces. */ | |
282 | |
283 Lisp_Object Qdefault, Qmodeline, Qtoolbar, Qregion, Qbitmap_area; | |
284 Lisp_Object Qtop_line; | |
285 | |
286 /* Default stipple pattern used on monochrome displays. This stipple | |
287 pattern is used on monochrome displays instead of shades of gray | |
288 for a face background color. See `set-face-stipple' for possible | |
289 values for this variable. */ | |
290 | |
291 Lisp_Object Vface_default_stipple; | |
292 | |
293 /* Default registry and encoding to use for charsets whose charset | |
294 symbols don't specify one. */ | |
295 | |
296 Lisp_Object Vface_default_registry; | |
297 | |
298 /* Alist of alternative font families. Each element is of the form | |
299 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded, | |
300 try FAMILY1, then FAMILY2, ... */ | |
301 | |
302 Lisp_Object Vface_alternative_font_family_alist; | |
303 | |
304 /* Allowed scalable fonts. A value of nil means don't allow any | |
305 scalable fonts. A value of t means allow the use of any scalable | |
306 font. Otherwise, value must be a list of regular expressions. A | |
307 font may be scaled if its name matches a regular expression in the | |
308 list. */ | |
309 | |
310 #if SCALABLE_FONTS | |
311 Lisp_Object Vscalable_fonts_allowed; | |
312 #endif | |
313 | |
25270 | 314 /* Maximum number of fonts to consider in font_list. If not an |
315 integer > 0, DEFAULT_FONT_LIST_LIMIT is used instead. */ | |
316 | |
317 Lisp_Object Vfont_list_limit; | |
318 #define DEFAULT_FONT_LIST_LIMIT 100 | |
319 | |
24995 | 320 /* The symbols `foreground-color' and `background-color' which can be |
321 used as part of a `face' property. This is for compatibility with | |
322 Emacs 20.2. */ | |
323 | |
324 Lisp_Object Qforeground_color, Qbackground_color; | |
325 | |
326 /* The symbols `face' and `mouse-face' used as text properties. */ | |
2342 | 327 |
23730
c71c3ac4b80a
(Qmouse_face): Replace definition with extern decl.
Richard M. Stallman <rms@gnu.org>
parents:
21766
diff
changeset
|
328 Lisp_Object Qface; |
24995 | 329 extern Lisp_Object Qmouse_face; |
330 | |
331 /* Error symbol for wrong_type_argument in load_pixmap. */ | |
332 | |
9564
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
333 Lisp_Object Qpixmap_spec_p; |
2391 | 334 |
24995 | 335 /* Alist of global face definitions. Each element is of the form |
336 (FACE . LFACE) where FACE is a symbol naming a face and LFACE | |
337 is a Lisp vector of face attributes. These faces are used | |
338 to initialize faces for new frames. */ | |
339 | |
340 Lisp_Object Vface_new_frame_defaults; | |
341 | |
342 /* The next ID to assign to Lisp faces. */ | |
343 | |
344 static int next_lface_id; | |
345 | |
346 /* A vector mapping Lisp face Id's to face names. */ | |
347 | |
348 static Lisp_Object *lface_id_to_name; | |
349 static int lface_id_to_name_size; | |
350 | |
351 /* An alist of elements (COLOR-NAME . INDEX) mapping color names | |
352 to color indices for tty frames. */ | |
353 | |
354 Lisp_Object Vface_tty_color_alist; | |
355 | |
356 /* Counter for calls to clear_face_cache. If this counter reaches | |
357 CLEAR_FONT_TABLE_COUNT, and a frame has more than | |
358 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */ | |
359 | |
360 static int clear_font_table_count; | |
361 #define CLEAR_FONT_TABLE_COUNT 100 | |
362 #define CLEAR_FONT_TABLE_NFONTS 10 | |
363 | |
364 /* Non-zero means face attributes have been changed since the last | |
365 redisplay. Used in redisplay_internal. */ | |
366 | |
367 int face_change_count; | |
368 | |
369 /* The total number of colors currently allocated. */ | |
370 | |
371 #if GLYPH_DEBUG | |
372 static int ncolors_allocated; | |
373 static int npixmaps_allocated; | |
374 static int ngcs; | |
375 #endif | |
376 | |
377 | |
2336 | 378 |
24995 | 379 /* Function prototypes. */ |
380 | |
381 struct font_name; | |
382 struct table_entry; | |
383 | |
384 static int may_use_scalable_font_p P_ ((struct font_name *, char *)); | |
385 static void set_font_frame_param P_ ((Lisp_Object, Lisp_Object)); | |
386 static int better_font_p P_ ((int *, struct font_name *, struct font_name *, | |
387 int)); | |
388 static int first_font_matching P_ ((struct frame *f, char *, | |
389 struct font_name *)); | |
390 static int x_face_list_fonts P_ ((struct frame *, char *, | |
391 struct font_name *, int, int, int)); | |
392 static int font_scalable_p P_ ((struct font_name *)); | |
393 static Lisp_Object deduce_unibyte_registry P_ ((struct frame *, char *)); | |
394 static int get_lface_attributes P_ ((struct frame *, Lisp_Object, Lisp_Object *, int)); | |
395 static int load_pixmap P_ ((struct frame *, Lisp_Object, unsigned *, unsigned *)); | |
396 static char *xstrdup P_ ((char *)); | |
397 static unsigned char *xstrlwr P_ ((unsigned char *)); | |
398 static void signal_error P_ ((char *, Lisp_Object)); | |
399 static void display_message P_ ((struct frame *, char *, Lisp_Object, Lisp_Object)); | |
400 static struct frame *frame_or_selected_frame P_ ((Lisp_Object, int)); | |
401 static void load_face_font_or_fontset P_ ((struct frame *, struct face *, char *, int)); | |
402 static void load_face_colors P_ ((struct frame *, struct face *, Lisp_Object *)); | |
403 static void free_face_colors P_ ((struct frame *, struct face *)); | |
404 static int face_color_gray_p P_ ((struct frame *, char *)); | |
405 static char *build_font_name P_ ((struct font_name *)); | |
406 static void free_font_names P_ ((struct font_name *, int)); | |
407 static int sorted_font_list P_ ((struct frame *, char *, | |
408 int (*cmpfn) P_ ((const void *, const void *)), | |
409 struct font_name **)); | |
410 static int font_list P_ ((struct frame *, char *, char *, char *, struct font_name **)); | |
411 static int try_font_list P_ ((struct frame *, Lisp_Object *, char *, char *, char *, | |
412 struct font_name **)); | |
413 static int cmp_font_names P_ ((const void *, const void *)); | |
414 static struct face *realize_face P_ ((struct face_cache *, | |
415 Lisp_Object *, int)); | |
416 static struct face *realize_x_face P_ ((struct face_cache *, | |
417 Lisp_Object *, int)); | |
418 static struct face *realize_tty_face P_ ((struct face_cache *, | |
419 Lisp_Object *, int)); | |
420 static int realize_basic_faces P_ ((struct frame *)); | |
421 static int realize_default_face P_ ((struct frame *)); | |
422 static void realize_named_face P_ ((struct frame *, Lisp_Object, int)); | |
423 static int lface_fully_specified_p P_ ((Lisp_Object *)); | |
424 static int lface_equal_p P_ ((Lisp_Object *, Lisp_Object *)); | |
425 static unsigned hash_string_case_insensitive P_ ((Lisp_Object)); | |
426 static unsigned lface_hash P_ ((Lisp_Object *)); | |
427 static int lface_same_font_attributes_p P_ ((Lisp_Object *, Lisp_Object *)); | |
428 static struct face_cache *make_face_cache P_ ((struct frame *)); | |
429 static void free_realized_face P_ ((struct frame *, struct face *)); | |
430 static void clear_face_gcs P_ ((struct face_cache *)); | |
431 static void free_face_cache P_ ((struct face_cache *)); | |
432 static int face_numeric_weight P_ ((Lisp_Object)); | |
433 static int face_numeric_slant P_ ((Lisp_Object)); | |
434 static int face_numeric_swidth P_ ((Lisp_Object)); | |
435 static int face_fontset P_ ((struct frame *, Lisp_Object *)); | |
436 static char *choose_face_font P_ ((struct frame *, Lisp_Object *, int, | |
437 Lisp_Object)); | |
438 static char *choose_face_fontset_font P_ ((struct frame *, Lisp_Object *, | |
439 int, int)); | |
440 static void merge_face_vectors P_ ((Lisp_Object *from, Lisp_Object *)); | |
441 static void merge_face_vector_with_property P_ ((struct frame *, Lisp_Object *, | |
442 Lisp_Object)); | |
443 static int set_lface_from_font_name P_ ((struct frame *, Lisp_Object, char *, | |
444 int)); | |
445 static Lisp_Object lface_from_face_name P_ ((struct frame *, Lisp_Object, int)); | |
446 static struct face *make_realized_face P_ ((Lisp_Object *, int, Lisp_Object)); | |
447 static void free_realized_faces P_ ((struct face_cache *)); | |
448 static char *best_matching_font P_ ((struct frame *, Lisp_Object *, | |
449 struct font_name *, int)); | |
450 static void cache_face P_ ((struct face_cache *, struct face *, unsigned)); | |
451 static void uncache_face P_ ((struct face_cache *, struct face *)); | |
452 static int xlfd_numeric_slant P_ ((struct font_name *)); | |
453 static int xlfd_numeric_weight P_ ((struct font_name *)); | |
454 static int xlfd_numeric_swidth P_ ((struct font_name *)); | |
455 static Lisp_Object xlfd_symbolic_slant P_ ((struct font_name *)); | |
456 static Lisp_Object xlfd_symbolic_weight P_ ((struct font_name *)); | |
457 static Lisp_Object xlfd_symbolic_swidth P_ ((struct font_name *)); | |
458 static int xlfd_fixed_p P_ ((struct font_name *)); | |
459 static int xlfd_numeric_value P_ ((struct table_entry *, int, struct font_name *, | |
460 int, int)); | |
461 static Lisp_Object xlfd_symbolic_value P_ ((struct table_entry *, int, | |
462 struct font_name *, int, int)); | |
463 static struct table_entry *xlfd_lookup_field_contents P_ ((struct table_entry *, int, | |
464 struct font_name *, int)); | |
2730
139740855fa6
* xfaces.c (Fmake_face_internal): Do nothing for non-X frames.
Jim Blandy <jimb@redhat.com>
parents:
2538
diff
changeset
|
465 |
9572 | 466 #ifdef HAVE_X_WINDOWS |
24995 | 467 |
468 static int split_font_name P_ ((struct frame *, struct font_name *, int)); | |
469 static int xlfd_point_size P_ ((struct frame *, struct font_name *)); | |
470 static void sort_fonts P_ ((struct frame *, struct font_name *, int, | |
471 int (*cmpfn) P_ ((const void *, const void *)))); | |
472 static GC x_create_gc P_ ((struct frame *, unsigned long, XGCValues *)); | |
473 static void x_free_gc P_ ((struct frame *, GC)); | |
474 static void clear_font_table P_ ((struct frame *)); | |
475 | |
476 #endif /* HAVE_X_WINDOWS */ | |
477 | |
478 | |
479 /*********************************************************************** | |
480 Utilities | |
481 ***********************************************************************/ | |
482 | |
483 #ifdef HAVE_X_WINDOWS | |
484 | |
485 /* Create and return a GC for use on frame F. GC values and mask | |
486 are given by XGCV and MASK. */ | |
487 | |
488 static INLINE GC | |
489 x_create_gc (f, mask, xgcv) | |
2730
139740855fa6
* xfaces.c (Fmake_face_internal): Do nothing for non-X frames.
Jim Blandy <jimb@redhat.com>
parents:
2538
diff
changeset
|
490 struct frame *f; |
24995 | 491 unsigned long mask; |
492 XGCValues *xgcv; | |
2730
139740855fa6
* xfaces.c (Fmake_face_internal): Do nothing for non-X frames.
Jim Blandy <jimb@redhat.com>
parents:
2538
diff
changeset
|
493 { |
2336 | 494 GC gc; |
24995 | 495 BLOCK_INPUT; |
496 gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), mask, xgcv); | |
497 UNBLOCK_INPUT; | |
498 IF_DEBUG (++ngcs); | |
499 return gc; | |
500 } | |
501 | |
502 | |
503 /* Free GC which was used on frame F. */ | |
504 | |
505 static INLINE void | |
506 x_free_gc (f, gc) | |
507 struct frame *f; | |
508 GC gc; | |
509 { | |
3074
96b4623fdeb3
* xterm.h: New section for declarations for xfaces.c.
Jim Blandy <jimb@redhat.com>
parents:
3065
diff
changeset
|
510 BLOCK_INPUT; |
24995 | 511 xassert (--ngcs >= 0); |
512 XFreeGC (FRAME_X_DISPLAY (f), gc); | |
513 UNBLOCK_INPUT; | |
514 } | |
515 | |
516 #endif /* HAVE_X_WINDOWS */ | |
517 | |
518 | |
519 /* Like strdup, but uses xmalloc. */ | |
520 | |
521 static char * | |
522 xstrdup (s) | |
523 char *s; | |
524 { | |
525 int len = strlen (s) + 1; | |
526 char *p = (char *) xmalloc (len); | |
527 bcopy (s, p, len); | |
528 return p; | |
529 } | |
530 | |
531 | |
532 /* Like stricmp. Used to compare parts of font names which are in | |
533 ISO8859-1. */ | |
534 | |
535 int | |
536 xstricmp (s1, s2) | |
537 unsigned char *s1, *s2; | |
538 { | |
539 while (*s1 && *s2) | |
540 { | |
541 unsigned char c1 = tolower (*s1); | |
542 unsigned char c2 = tolower (*s2); | |
543 if (c1 != c2) | |
544 return c1 < c2 ? -1 : 1; | |
545 ++s1, ++s2; | |
546 } | |
547 | |
548 if (*s1 == 0) | |
549 return *s2 == 0 ? 0 : -1; | |
550 return 1; | |
551 } | |
552 | |
553 | |
554 /* Like strlwr, which might not always be available. */ | |
555 | |
556 static unsigned char * | |
557 xstrlwr (s) | |
558 unsigned char *s; | |
559 { | |
560 unsigned char *p = s; | |
561 | |
562 for (p = s; *p; ++p) | |
563 *p = tolower (*p); | |
564 | |
565 return s; | |
566 } | |
567 | |
568 | |
569 /* Signal `error' with message S, and additional argument ARG. */ | |
570 | |
571 static void | |
572 signal_error (s, arg) | |
573 char *s; | |
574 Lisp_Object arg; | |
575 { | |
576 Fsignal (Qerror, Fcons (build_string (s), Fcons (arg, Qnil))); | |
577 } | |
578 | |
579 | |
580 /* Display a message with format string FORMAT and arguments ARG1 and | |
581 ARG2 on frame F. Used to display errors if fonts, bitmaps, colors | |
582 etc. for a realized face on frame F cannot be loaded. (If we would | |
583 signal an error in these cases, we would end up in an infinite | |
584 recursion because this would stop realization, and the redisplay | |
585 triggered by the signal would try to realize that same face again.) | |
586 | |
587 If basic faces of F are not realized, just add the message to the | |
588 messages buffer "*Messages*". Because Fmessage calls | |
589 echo_area_display which tries to realize basic faces again, we would | |
590 otherwise also end in an infinite recursion. */ | |
591 | |
592 static void | |
593 display_message (f, format, arg1, arg2) | |
594 struct frame *f; | |
595 char *format; | |
596 Lisp_Object arg1, arg2; | |
597 { | |
598 Lisp_Object args[3]; | |
599 Lisp_Object nargs; | |
600 extern int waiting_for_input; | |
601 | |
602 /* Function note_mouse_highlight calls face_at_buffer_position which | |
603 may realize a face. If some attribute of that face is invalid, | |
604 say an invalid color, don't display an error to avoid calling | |
605 Lisp from XTread_socket. */ | |
606 if (waiting_for_input) | |
607 return; | |
608 | |
609 nargs = make_number (DIM (args)); | |
610 args[0] = build_string (format); | |
611 args[1] = arg1; | |
612 args[2] = arg2; | |
613 | |
614 if (f->face_cache->used >= BASIC_FACE_ID_SENTINEL) | |
615 Fmessage (nargs, args); | |
2391 | 616 else |
9566
fef2cfcbbe37
(intern_face): Update mask properly to set stipple
Richard M. Stallman <rms@gnu.org>
parents:
9564
diff
changeset
|
617 { |
24995 | 618 Lisp_Object msg = Fformat (nargs, args); |
619 char *buffer = LSTRDUPA (msg); | |
620 message_dolog (buffer, strlen (buffer), 1, 0); | |
9566
fef2cfcbbe37
(intern_face): Update mask properly to set stipple
Richard M. Stallman <rms@gnu.org>
parents:
9564
diff
changeset
|
621 } |
2336 | 622 } |
2730
139740855fa6
* xfaces.c (Fmake_face_internal): Do nothing for non-X frames.
Jim Blandy <jimb@redhat.com>
parents:
2538
diff
changeset
|
623 |
24995 | 624 |
625 /* If FRAME is nil, return selected_frame. Otherwise, check that | |
626 FRAME is a live frame, and return a pointer to it. NPARAM | |
627 is the parameter number of FRAME, for CHECK_LIVE_FRAME. This is | |
628 here because it's a frequent pattern in Lisp function definitions. */ | |
629 | |
630 static INLINE struct frame * | |
631 frame_or_selected_frame (frame, nparam) | |
632 Lisp_Object frame; | |
633 int nparam; | |
634 { | |
635 struct frame *f; | |
636 | |
637 if (NILP (frame)) | |
638 f = selected_frame; | |
639 else | |
640 { | |
641 CHECK_LIVE_FRAME (frame, nparam); | |
642 f = XFRAME (frame); | |
643 } | |
644 | |
645 return f; | |
646 } | |
647 | |
648 | |
649 /*********************************************************************** | |
650 Frames and faces | |
651 ***********************************************************************/ | |
652 | |
653 /* Initialize face cache and basic faces for frame F. */ | |
9529
8e610355cb29
Eliminate the "display faces"; store GCs in the "computed faces".
Richard M. Stallman <rms@gnu.org>
parents:
9326
diff
changeset
|
654 |
8e610355cb29
Eliminate the "display faces"; store GCs in the "computed faces".
Richard M. Stallman <rms@gnu.org>
parents:
9326
diff
changeset
|
655 void |
24995 | 656 init_frame_faces (f) |
657 struct frame *f; | |
9529
8e610355cb29
Eliminate the "display faces"; store GCs in the "computed faces".
Richard M. Stallman <rms@gnu.org>
parents:
9326
diff
changeset
|
658 { |
24995 | 659 /* Make a face cache, if F doesn't have one. */ |
660 if (FRAME_FACE_CACHE (f) == NULL) | |
661 FRAME_FACE_CACHE (f) = make_face_cache (f); | |
662 | |
663 #ifdef HAVE_X_WINDOWS | |
664 /* Make the image cache. */ | |
665 if (FRAME_X_P (f)) | |
9529
8e610355cb29
Eliminate the "display faces"; store GCs in the "computed faces".
Richard M. Stallman <rms@gnu.org>
parents:
9326
diff
changeset
|
666 { |
24995 | 667 if (FRAME_X_IMAGE_CACHE (f) == NULL) |
668 FRAME_X_IMAGE_CACHE (f) = make_image_cache (); | |
669 ++FRAME_X_IMAGE_CACHE (f)->refcount; | |
670 } | |
671 #endif /* HAVE_X_WINDOWS */ | |
672 | |
673 /* Realize basic faces. Must have enough information in frame | |
674 parameters to realize basic faces at this point. */ | |
675 #ifdef HAVE_X_WINDOWS | |
676 if (!FRAME_X_P (f) || FRAME_X_WINDOW (f)) | |
677 #endif | |
678 if (!realize_basic_faces (f)) | |
679 abort (); | |
680 } | |
681 | |
682 | |
683 /* Free face cache of frame F. Called from Fdelete_frame. */ | |
684 | |
685 void | |
686 free_frame_faces (f) | |
687 struct frame *f; | |
688 { | |
689 struct face_cache *face_cache = FRAME_FACE_CACHE (f); | |
690 | |
691 if (face_cache) | |
692 { | |
693 free_face_cache (face_cache); | |
694 FRAME_FACE_CACHE (f) = NULL; | |
695 } | |
696 | |
697 #ifdef HAVE_X_WINDOWS | |
698 if (FRAME_X_P (f)) | |
699 { | |
700 struct image_cache *image_cache = FRAME_X_IMAGE_CACHE (f); | |
701 if (image_cache) | |
9529
8e610355cb29
Eliminate the "display faces"; store GCs in the "computed faces".
Richard M. Stallman <rms@gnu.org>
parents:
9326
diff
changeset
|
702 { |
24995 | 703 --image_cache->refcount; |
704 if (image_cache->refcount == 0) | |
705 free_image_cache (f); | |
706 } | |
707 } | |
708 #endif /* HAVE_X_WINDOWS */ | |
709 } | |
710 | |
711 | |
712 /* Recompute basic faces for frame F. Call this after changing frame | |
713 parameters on which those faces depend, or when realized faces have | |
714 been freed due to changing attributes of named faces. */ | |
715 | |
716 void | |
717 recompute_basic_faces (f) | |
718 struct frame *f; | |
719 { | |
720 if (FRAME_FACE_CACHE (f)) | |
721 { | |
722 int realized_p = realize_basic_faces (f); | |
723 xassert (realized_p); | |
724 } | |
725 } | |
726 | |
727 | |
728 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means | |
729 try to free unused fonts, too. */ | |
730 | |
731 void | |
732 clear_face_cache (clear_fonts_p) | |
733 int clear_fonts_p; | |
734 { | |
735 #ifdef HAVE_X_WINDOWS | |
736 Lisp_Object tail, frame; | |
737 struct frame *f; | |
738 | |
739 if (clear_fonts_p | |
740 || ++clear_font_table_count == CLEAR_FONT_TABLE_COUNT) | |
741 { | |
742 /* From time to time see if we can unload some fonts. This also | |
743 frees all realized faces on all frames. Fonts needed by | |
744 faces will be loaded again when faces are realized again. */ | |
745 clear_font_table_count = 0; | |
746 | |
747 FOR_EACH_FRAME (tail, frame) | |
748 { | |
749 f = XFRAME (frame); | |
750 if (FRAME_X_P (f) | |
751 && FRAME_X_DISPLAY_INFO (f)->n_fonts > CLEAR_FONT_TABLE_NFONTS) | |
9529
8e610355cb29
Eliminate the "display faces"; store GCs in the "computed faces".
Richard M. Stallman <rms@gnu.org>
parents:
9326
diff
changeset
|
752 { |
24995 | 753 free_all_realized_faces (frame); |
754 clear_font_table (f); | |
9529
8e610355cb29
Eliminate the "display faces"; store GCs in the "computed faces".
Richard M. Stallman <rms@gnu.org>
parents:
9326
diff
changeset
|
755 } |
8e610355cb29
Eliminate the "display faces"; store GCs in the "computed faces".
Richard M. Stallman <rms@gnu.org>
parents:
9326
diff
changeset
|
756 } |
8e610355cb29
Eliminate the "display faces"; store GCs in the "computed faces".
Richard M. Stallman <rms@gnu.org>
parents:
9326
diff
changeset
|
757 } |
24995 | 758 else |
13460
5513606156bc
(unload_font): Invalidate computed faces.
Richard M. Stallman <rms@gnu.org>
parents:
13363
diff
changeset
|
759 { |
24995 | 760 /* Clear GCs of realized faces. */ |
761 FOR_EACH_FRAME (tail, frame) | |
13460
5513606156bc
(unload_font): Invalidate computed faces.
Richard M. Stallman <rms@gnu.org>
parents:
13363
diff
changeset
|
762 { |
24995 | 763 f = XFRAME (frame); |
764 if (FRAME_X_P (f)) | |
765 { | |
766 clear_face_gcs (FRAME_FACE_CACHE (f)); | |
767 clear_image_cache (f, 0); | |
768 } | |
13460
5513606156bc
(unload_font): Invalidate computed faces.
Richard M. Stallman <rms@gnu.org>
parents:
13363
diff
changeset
|
769 } |
5513606156bc
(unload_font): Invalidate computed faces.
Richard M. Stallman <rms@gnu.org>
parents:
13363
diff
changeset
|
770 } |
24995 | 771 #endif /* HAVE_X_WINDOWS */ |
2730
139740855fa6
* xfaces.c (Fmake_face_internal): Do nothing for non-X frames.
Jim Blandy <jimb@redhat.com>
parents:
2538
diff
changeset
|
772 } |
139740855fa6
* xfaces.c (Fmake_face_internal): Do nothing for non-X frames.
Jim Blandy <jimb@redhat.com>
parents:
2538
diff
changeset
|
773 |
24995 | 774 |
775 DEFUN ("clear-face-cache", Fclear_face_cache, Sclear_face_cache, 0, 1, 0, | |
776 "Clear face caches on all frames.\n\ | |
777 Optional THOROUGHLY non-nil means try to free unused fonts, too.") | |
778 (thorougly) | |
779 Lisp_Object thorougly; | |
2730
139740855fa6
* xfaces.c (Fmake_face_internal): Do nothing for non-X frames.
Jim Blandy <jimb@redhat.com>
parents:
2538
diff
changeset
|
780 { |
24995 | 781 clear_face_cache (!NILP (thorougly)); |
782 return Qnil; | |
2730
139740855fa6
* xfaces.c (Fmake_face_internal): Do nothing for non-X frames.
Jim Blandy <jimb@redhat.com>
parents:
2538
diff
changeset
|
783 } |
139740855fa6
* xfaces.c (Fmake_face_internal): Do nothing for non-X frames.
Jim Blandy <jimb@redhat.com>
parents:
2538
diff
changeset
|
784 |
24995 | 785 |
786 | |
787 #ifdef HAVE_X_WINDOWS | |
788 | |
789 | |
790 /* Remove those fonts from the font table of frame F that are not used | |
791 by fontsets. Called from clear_face_cache from time to time. */ | |
792 | |
793 static void | |
794 clear_font_table (f) | |
2730
139740855fa6
* xfaces.c (Fmake_face_internal): Do nothing for non-X frames.
Jim Blandy <jimb@redhat.com>
parents:
2538
diff
changeset
|
795 struct frame *f; |
139740855fa6
* xfaces.c (Fmake_face_internal): Do nothing for non-X frames.
Jim Blandy <jimb@redhat.com>
parents:
2538
diff
changeset
|
796 { |
24995 | 797 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
798 char *used; | |
799 Lisp_Object rest, frame; | |
800 int i; | |
801 | |
802 xassert (FRAME_X_P (f)); | |
803 | |
804 used = (char *) alloca (dpyinfo->n_fonts * sizeof *used); | |
805 bzero (used, dpyinfo->n_fonts * sizeof *used); | |
806 | |
807 /* For all frames with the same x_display_info as F, record | |
808 in `used' those fonts that are in use by fontsets. */ | |
809 FOR_EACH_FRAME (rest, frame) | |
810 if (FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo) | |
811 { | |
812 struct frame *f = XFRAME (frame); | |
813 struct fontset_data *fontset_data = FRAME_FONTSET_DATA (f); | |
814 | |
815 for (i = 0; i < fontset_data->n_fontsets; ++i) | |
816 { | |
817 struct fontset_info *info = fontset_data->fontset_table[i]; | |
818 int j; | |
819 | |
820 for (j = 0; j <= MAX_CHARSET; ++j) | |
821 { | |
822 int idx = info->font_indexes[j]; | |
823 if (idx >= 0) | |
824 used[idx] = 1; | |
825 } | |
826 } | |
827 } | |
828 | |
829 /* Free those fonts that are not used by fontsets. */ | |
830 for (i = 0; i < dpyinfo->n_fonts; ++i) | |
831 if (used[i] == 0 && dpyinfo->font_table[i].name) | |
832 { | |
833 struct font_info *font_info = dpyinfo->font_table + i; | |
834 | |
835 /* Free names. In xfns.c there is a comment that full_name | |
836 should never be freed because it is always shared with | |
837 something else. I don't think this is true anymore---see | |
838 x_load_font. It's either equal to font_info->name or | |
839 allocated via xmalloc, and there seems to be no place in | |
840 the source files where full_name is transferred to another | |
841 data structure. */ | |
842 if (font_info->full_name != font_info->name) | |
843 xfree (font_info->full_name); | |
844 xfree (font_info->name); | |
845 | |
846 /* Free the font. */ | |
847 BLOCK_INPUT; | |
848 XFreeFont (dpyinfo->display, font_info->font); | |
849 UNBLOCK_INPUT; | |
850 | |
851 /* Mark font table slot free. */ | |
852 font_info->font = NULL; | |
853 font_info->name = font_info->full_name = NULL; | |
854 } | |
9564
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
855 } |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
856 |
24995 | 857 |
858 #endif /* HAVE_X_WINDOWS */ | |
859 | |
860 | |
861 | |
862 /*********************************************************************** | |
863 X Pixmaps | |
864 ***********************************************************************/ | |
865 | |
866 #ifdef HAVE_X_WINDOWS | |
867 | |
9564
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
868 DEFUN ("pixmap-spec-p", Fpixmap_spec_p, Spixmap_spec_p, 1, 1, 0, |
24995 | 869 "Non-nil if OBJECT is a valid pixmap specification.\n\ |
870 A pixmap specification is either a string, or a list (WIDTH HEIGHT DATA)\n\ | |
871 where WIDTH is the pixel width of the pixmap, HEIGHT is its height,\n\ | |
872 and DATA contains the bits of the pixmap.") | |
14090
24b93860d392
(Fpixmap_spec_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
873 (object) |
24b93860d392
(Fpixmap_spec_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
874 Lisp_Object object; |
9564
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
875 { |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
876 Lisp_Object height, width; |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
877 |
14090
24b93860d392
(Fpixmap_spec_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
878 return ((STRINGP (object) |
24b93860d392
(Fpixmap_spec_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
879 || (CONSP (object) |
24b93860d392
(Fpixmap_spec_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
880 && CONSP (XCONS (object)->cdr) |
24b93860d392
(Fpixmap_spec_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
881 && CONSP (XCONS (XCONS (object)->cdr)->cdr) |
24b93860d392
(Fpixmap_spec_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
882 && NILP (XCONS (XCONS (XCONS (object)->cdr)->cdr)->cdr) |
24b93860d392
(Fpixmap_spec_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
883 && (width = XCONS (object)->car, INTEGERP (width)) |
24995 | 884 && (height = XCONS (XCONS (object)->cdr)->car, |
885 INTEGERP (height)) | |
14090
24b93860d392
(Fpixmap_spec_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
886 && STRINGP (XCONS (XCONS (XCONS (object)->cdr)->cdr)->car) |
9564
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
887 && XINT (width) > 0 |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
888 && XINT (height) > 0 |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
889 /* The string must have enough bits for width * height. */ |
14090
24b93860d392
(Fpixmap_spec_p): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
890 && ((XSTRING (XCONS (XCONS (XCONS (object)->cdr)->cdr)->car)->size |
13363
941c37982f37
(BITS_PER_SHORT, BITS_PER_INT, BITS_PER_LONG):
Karl Heuer <kwzh@gnu.org>
parents:
12667
diff
changeset
|
891 * (BITS_PER_INT / sizeof (int))) |
9944
dd9afae74baf
(Fpixmap_spec_p): Avoid function calls and assignments as arguments to a
Karl Heuer <kwzh@gnu.org>
parents:
9902
diff
changeset
|
892 >= XFASTINT (width) * XFASTINT (height)))) |
9564
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
893 ? Qt : Qnil); |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
894 } |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
895 |
24995 | 896 |
897 /* Load a bitmap according to NAME (which is either a file name or a | |
898 pixmap spec) for use on frame F. Value is the bitmap_id (see | |
899 xfns.c). If NAME is nil, return with a bitmap id of zero. If | |
900 bitmap cannot be loaded, display a message saying so, and return | |
901 zero. Store the bitmap width in *W_PTR and its height in *H_PTR, | |
902 if these pointers are not null. */ | |
903 | |
904 static int | |
9564
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
905 load_pixmap (f, name, w_ptr, h_ptr) |
9902
32ed712a45a3
(load_pixmap): Handle bitmap_id < 0. F is a FRAME_PTR.
Richard M. Stallman <rms@gnu.org>
parents:
9671
diff
changeset
|
906 FRAME_PTR f; |
9564
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
907 Lisp_Object name; |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
908 unsigned int *w_ptr, *h_ptr; |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
909 { |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
910 int bitmap_id; |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
911 Lisp_Object tem; |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
912 |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
913 if (NILP (name)) |
24995 | 914 return 0; |
9564
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
915 |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
916 tem = Fpixmap_spec_p (name); |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
917 if (NILP (tem)) |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
918 wrong_type_argument (Qpixmap_spec_p, name); |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
919 |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
920 BLOCK_INPUT; |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
921 if (CONSP (name)) |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
922 { |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
923 /* Decode a bitmap spec into a bitmap. */ |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
924 |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
925 int h, w; |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
926 Lisp_Object bits; |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
927 |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
928 w = XINT (Fcar (name)); |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
929 h = XINT (Fcar (Fcdr (name))); |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
930 bits = Fcar (Fcdr (Fcdr (name))); |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
931 |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
932 bitmap_id = x_create_bitmap_from_data (f, XSTRING (bits)->data, |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
933 w, h); |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
934 } |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
935 else |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
936 { |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
937 /* It must be a string -- a file name. */ |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
938 bitmap_id = x_create_bitmap_from_file (f, name); |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
939 } |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
940 UNBLOCK_INPUT; |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
941 |
9902
32ed712a45a3
(load_pixmap): Handle bitmap_id < 0. F is a FRAME_PTR.
Richard M. Stallman <rms@gnu.org>
parents:
9671
diff
changeset
|
942 if (bitmap_id < 0) |
24995 | 943 { |
944 display_message (f, "Invalid or undefined bitmap %s", name, Qnil); | |
945 bitmap_id = 0; | |
946 | |
947 if (w_ptr) | |
948 *w_ptr = 0; | |
949 if (h_ptr) | |
950 *h_ptr = 0; | |
951 } | |
952 else | |
953 { | |
954 #if GLYPH_DEBUG | |
955 ++npixmaps_allocated; | |
956 #endif | |
957 if (w_ptr) | |
958 *w_ptr = x_bitmap_width (f, bitmap_id); | |
959 | |
960 if (h_ptr) | |
961 *h_ptr = x_bitmap_height (f, bitmap_id); | |
962 } | |
9564
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
963 |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
964 return bitmap_id; |
2730
139740855fa6
* xfaces.c (Fmake_face_internal): Do nothing for non-X frames.
Jim Blandy <jimb@redhat.com>
parents:
2538
diff
changeset
|
965 } |
9572 | 966 |
24995 | 967 #endif /* HAVE_X_WINDOWS */ |
968 | |
9572 | 969 |
2336 | 970 |
24995 | 971 /*********************************************************************** |
972 Minimum font bounds | |
973 ***********************************************************************/ | |
974 | |
9572 | 975 #ifdef HAVE_X_WINDOWS |
3074
96b4623fdeb3
* xterm.h: New section for declarations for xfaces.c.
Jim Blandy <jimb@redhat.com>
parents:
3065
diff
changeset
|
976 |
25062
050561b336aa
(load_face_colors): Load background color if setting
Gerd Moellmann <gerd@gnu.org>
parents:
24995
diff
changeset
|
977 /* Update the line_height of frame F. Return non-zero if line height |
050561b336aa
(load_face_colors): Load background color if setting
Gerd Moellmann <gerd@gnu.org>
parents:
24995
diff
changeset
|
978 changes. */ |
6768
0b61d2b74e64
(frame_update_line_height): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6615
diff
changeset
|
979 |
6879
471aebc1b151
(frame_update_line_height): Don't call x_set_window_size.
Richard M. Stallman <rms@gnu.org>
parents:
6784
diff
changeset
|
980 int |
6768
0b61d2b74e64
(frame_update_line_height): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6615
diff
changeset
|
981 frame_update_line_height (f) |
24995 | 982 struct frame *f; |
6768
0b61d2b74e64
(frame_update_line_height): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6615
diff
changeset
|
983 { |
25062
050561b336aa
(load_face_colors): Load background color if setting
Gerd Moellmann <gerd@gnu.org>
parents:
24995
diff
changeset
|
984 int fontset, line_height, changed_p; |
050561b336aa
(load_face_colors): Load background color if setting
Gerd Moellmann <gerd@gnu.org>
parents:
24995
diff
changeset
|
985 |
050561b336aa
(load_face_colors): Load background color if setting
Gerd Moellmann <gerd@gnu.org>
parents:
24995
diff
changeset
|
986 fontset = f->output_data.x->fontset; |
050561b336aa
(load_face_colors): Load background color if setting
Gerd Moellmann <gerd@gnu.org>
parents:
24995
diff
changeset
|
987 if (fontset > 0) |
050561b336aa
(load_face_colors): Load background color if setting
Gerd Moellmann <gerd@gnu.org>
parents:
24995
diff
changeset
|
988 line_height = FRAME_FONTSET_DATA (f)->fontset_table[fontset]->height; |
050561b336aa
(load_face_colors): Load background color if setting
Gerd Moellmann <gerd@gnu.org>
parents:
24995
diff
changeset
|
989 else |
050561b336aa
(load_face_colors): Load background color if setting
Gerd Moellmann <gerd@gnu.org>
parents:
24995
diff
changeset
|
990 line_height = FONT_HEIGHT (f->output_data.x->font); |
050561b336aa
(load_face_colors): Load background color if setting
Gerd Moellmann <gerd@gnu.org>
parents:
24995
diff
changeset
|
991 |
050561b336aa
(load_face_colors): Load background color if setting
Gerd Moellmann <gerd@gnu.org>
parents:
24995
diff
changeset
|
992 changed_p = line_height != f->output_data.x->line_height; |
050561b336aa
(load_face_colors): Load background color if setting
Gerd Moellmann <gerd@gnu.org>
parents:
24995
diff
changeset
|
993 f->output_data.x->line_height = line_height; |
24995 | 994 return changed_p; |
6768
0b61d2b74e64
(frame_update_line_height): New function.
Richard M. Stallman <rms@gnu.org>
parents:
6615
diff
changeset
|
995 } |
24995 | 996 |
997 #endif /* HAVE_X_WINDOWS */ | |
998 | |
6784
d41c216ccd27
(frame_update_line_height): Check param_faces[i] not null.
Richard M. Stallman <rms@gnu.org>
parents:
6768
diff
changeset
|
999 |
24995 | 1000 /*********************************************************************** |
1001 Fonts | |
1002 ***********************************************************************/ | |
1003 | |
1004 #ifdef HAVE_X_WINDOWS | |
1005 | |
1006 /* Load font or fontset of face FACE which is used on frame F. | |
1007 FONTSET is the fontset FACE should use or -1, if FACE doesn't use a | |
1008 fontset. FONT_NAME is the name of the font to load, if no fontset | |
1009 is used. It is null if no suitable font name could be determined | |
1010 for the face. */ | |
6784
d41c216ccd27
(frame_update_line_height): Check param_faces[i] not null.
Richard M. Stallman <rms@gnu.org>
parents:
6768
diff
changeset
|
1011 |
3074
96b4623fdeb3
* xterm.h: New section for declarations for xfaces.c.
Jim Blandy <jimb@redhat.com>
parents:
3065
diff
changeset
|
1012 static void |
24995 | 1013 load_face_font_or_fontset (f, face, font_name, fontset) |
1014 struct frame *f; | |
1015 struct face *face; | |
1016 char *font_name; | |
1017 int fontset; | |
1018 { | |
1019 struct font_info *font_info = NULL; | |
1020 | |
1021 face->font_info_id = -1; | |
1022 face->fontset = fontset; | |
1023 face->font = NULL; | |
1024 | |
1025 BLOCK_INPUT; | |
1026 if (fontset >= 0) | |
1027 font_info = FS_LOAD_FONT (f, FRAME_X_FONT_TABLE (f), CHARSET_ASCII, | |
1028 NULL, fontset); | |
1029 else if (font_name) | |
1030 font_info = FS_LOAD_FONT (f, FRAME_X_FONT_TABLE (f), face->charset, | |
1031 font_name, -1); | |
1032 UNBLOCK_INPUT; | |
1033 | |
1034 if (font_info) | |
1035 { | |
1036 char *s; | |
1037 int i; | |
1038 | |
1039 face->font_info_id = FONT_INFO_ID (f, font_info); | |
1040 face->font = font_info->font; | |
1041 face->font_name = font_info->full_name; | |
1042 | |
1043 /* Make the registry part of the font name readily accessible. | |
1044 The registry is used to find suitable faces for unibyte text. */ | |
1045 s = font_info->full_name + strlen (font_info->full_name); | |
1046 i = 0; | |
1047 while (i < 2 && --s >= font_info->full_name) | |
1048 if (*s == '-') | |
1049 ++i; | |
1050 | |
1051 if (!STRINGP (face->registry) | |
1052 || xstricmp (XSTRING (face->registry)->data, s + 1) != 0) | |
1053 { | |
1054 if (STRINGP (Vface_default_registry) | |
1055 && !xstricmp (XSTRING (Vface_default_registry)->data, s + 1)) | |
1056 face->registry = Vface_default_registry; | |
1057 else | |
1058 face->registry = build_string (s + 1); | |
1059 } | |
1060 } | |
1061 else if (fontset >= 0) | |
1062 display_message (f, "Unable to load ASCII font of fontset %d", | |
1063 make_number (fontset), Qnil); | |
1064 else if (font_name) | |
1065 display_message (f, "Unable to load font %s", | |
1066 build_string (font_name), Qnil); | |
1067 } | |
1068 | |
1069 #endif /* HAVE_X_WINDOWS */ | |
1070 | |
1071 | |
1072 | |
1073 /*********************************************************************** | |
1074 X Colors | |
1075 ***********************************************************************/ | |
1076 | |
1077 #ifdef HAVE_X_WINDOWS | |
1078 | |
1079 /* Return non-zero if COLOR_NAME is a shade of gray (or white or | |
1080 black) on frame F. The algorithm is taken from 20.2 faces.el. */ | |
1081 | |
1082 static int | |
1083 face_color_gray_p (f, color_name) | |
1084 struct frame *f; | |
1085 char *color_name; | |
1086 { | |
1087 XColor color; | |
1088 int gray_p; | |
1089 | |
1090 if (defined_color (f, color_name, &color, 0)) | |
1091 gray_p = ((abs (color.red - color.green) | |
1092 < max (color.red, color.green) / 20) | |
1093 && (abs (color.green - color.blue) | |
1094 < max (color.green, color.blue) / 20) | |
1095 && (abs (color.blue - color.red) | |
1096 < max (color.blue, color.red) / 20)); | |
1097 else | |
1098 gray_p = 0; | |
1099 | |
1100 return gray_p; | |
1101 } | |
1102 | |
1103 | |
1104 /* Return non-zero if color COLOR_NAME can be displayed on frame F. | |
1105 BACKGROUND_P non-zero means the color will be used as background | |
1106 color. */ | |
1107 | |
1108 static int | |
1109 face_color_supported_p (f, color_name, background_p) | |
1110 struct frame *f; | |
1111 char *color_name; | |
1112 int background_p; | |
1113 { | |
1114 Lisp_Object frame; | |
1115 | |
1116 XSETFRAME (frame, f); | |
1117 return (!NILP (Vwindow_system) | |
1118 && (!NILP (Fx_display_color_p (frame)) | |
1119 || xstricmp (color_name, "black") == 0 | |
1120 || xstricmp (color_name, "white") == 0 | |
1121 || (background_p | |
1122 && face_color_gray_p (f, color_name)) | |
1123 || (!NILP (Fx_display_grayscale_p (frame)) | |
1124 && face_color_gray_p (f, color_name)))); | |
1125 } | |
1126 | |
1127 | |
1128 DEFUN ("face-color-gray-p", Fface_color_gray_p, Sface_color_gray_p, 1, 2, 0, | |
1129 "Return non-nil if COLOR is a shade of gray (or white or black).\n\ | |
1130 FRAME specifies the frame and thus the display for interpreting COLOR.\n\ | |
1131 If FRAME is nil or omitted, use the selected frame.") | |
1132 (color, frame) | |
1133 Lisp_Object color, frame; | |
1134 { | |
1135 struct frame *f = check_x_frame (frame); | |
1136 CHECK_STRING (color, 0); | |
1137 return face_color_gray_p (f, XSTRING (color)->data) ? Qt : Qnil; | |
1138 } | |
1139 | |
1140 | |
1141 DEFUN ("face-color-supported-p", Fface_color_supported_p, | |
1142 Sface_color_supported_p, 2, 3, 0, | |
1143 "Return non-nil if COLOR can be displayed on FRAME.\n\ | |
1144 BACKGROUND-P non-nil means COLOR is used as a background.\n\ | |
1145 If FRAME is nil or omitted, use the selected frame.\n\ | |
1146 COLOR must be a valid color name.") | |
1147 (frame, color, background_p) | |
1148 Lisp_Object frame, color, background_p; | |
1149 { | |
1150 struct frame *f = check_x_frame (frame); | |
1151 CHECK_STRING (color, 0); | |
1152 if (face_color_supported_p (f, XSTRING (color)->data, !NILP (background_p))) | |
1153 return Qt; | |
1154 return Qnil; | |
1155 } | |
1156 | |
1157 /* Load color with name NAME for use by face FACE on frame F. | |
1158 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX, | |
1159 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX, | |
1160 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the | |
1161 pixel color. If color cannot be loaded, display a message, and | |
1162 return the foreground, background or underline color of F, but | |
1163 record that fact in flags of the face so that we don't try to free | |
1164 these colors. */ | |
1165 | |
25114
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1166 unsigned long |
24995 | 1167 load_color (f, face, name, target_index) |
1168 struct frame *f; | |
1169 struct face *face; | |
1170 Lisp_Object name; | |
1171 enum lface_attribute_index target_index; | |
1172 { | |
1173 XColor color; | |
1174 | |
1175 xassert (STRINGP (name)); | |
1176 xassert (target_index == LFACE_FOREGROUND_INDEX | |
1177 || target_index == LFACE_BACKGROUND_INDEX | |
1178 || target_index == LFACE_UNDERLINE_INDEX | |
1179 || target_index == LFACE_OVERLINE_INDEX | |
1180 || target_index == LFACE_STRIKE_THROUGH_INDEX | |
1181 || target_index == LFACE_BOX_INDEX); | |
1182 | |
1183 /* if the color map is full, defined_color will return a best match | |
1184 to the values in an existing cell. */ | |
1185 if (!defined_color (f, XSTRING (name)->data, &color, 1)) | |
1186 { | |
1187 display_message (f, "Unable to load color %s", name, Qnil); | |
1188 | |
1189 switch (target_index) | |
1190 { | |
1191 case LFACE_FOREGROUND_INDEX: | |
1192 face->foreground_defaulted_p = 1; | |
1193 color.pixel = FRAME_FOREGROUND_PIXEL (f); | |
1194 break; | |
1195 | |
1196 case LFACE_BACKGROUND_INDEX: | |
1197 face->background_defaulted_p = 1; | |
1198 color.pixel = FRAME_BACKGROUND_PIXEL (f); | |
1199 break; | |
1200 | |
1201 case LFACE_UNDERLINE_INDEX: | |
1202 face->underline_defaulted_p = 1; | |
1203 color.pixel = FRAME_FOREGROUND_PIXEL (f); | |
1204 break; | |
1205 | |
1206 case LFACE_OVERLINE_INDEX: | |
1207 face->overline_color_defaulted_p = 1; | |
1208 color.pixel = FRAME_FOREGROUND_PIXEL (f); | |
1209 break; | |
1210 | |
1211 case LFACE_STRIKE_THROUGH_INDEX: | |
1212 face->strike_through_color_defaulted_p = 1; | |
1213 color.pixel = FRAME_FOREGROUND_PIXEL (f); | |
1214 break; | |
1215 | |
1216 case LFACE_BOX_INDEX: | |
1217 face->box_color_defaulted_p = 1; | |
1218 color.pixel = FRAME_FOREGROUND_PIXEL (f); | |
1219 break; | |
1220 | |
1221 default: | |
1222 abort (); | |
1223 } | |
1224 } | |
1225 #if GLYPH_DEBUG | |
1226 else | |
1227 ++ncolors_allocated; | |
1228 #endif | |
1229 | |
1230 return color.pixel; | |
1231 } | |
1232 | |
1233 | |
1234 /* Load colors for face FACE which is used on frame F. Colors are | |
1235 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX | |
1236 of ATTRS. If the background color specified is not supported on F, | |
1237 try to emulate gray colors with a stipple from Vface_default_stipple. */ | |
1238 | |
1239 static void | |
1240 load_face_colors (f, face, attrs) | |
1241 struct frame *f; | |
1242 struct face *face; | |
1243 Lisp_Object *attrs; | |
1244 { | |
1245 Lisp_Object fg, bg; | |
1246 | |
1247 bg = attrs[LFACE_BACKGROUND_INDEX]; | |
1248 fg = attrs[LFACE_FOREGROUND_INDEX]; | |
1249 | |
1250 /* Swap colors if face is inverse-video. */ | |
1251 if (EQ (attrs[LFACE_INVERSE_INDEX], Qt)) | |
1252 { | |
1253 Lisp_Object tmp; | |
1254 tmp = fg; | |
1255 fg = bg; | |
1256 bg = tmp; | |
1257 } | |
1258 | |
1259 /* Check for support for foreground, not for background because | |
1260 face_color_supported_p is smart enough to know that grays are | |
1261 "supported" as background because we are supposed to use stipple | |
1262 for them. */ | |
1263 if (!face_color_supported_p (f, XSTRING (bg)->data, 0) | |
1264 && !NILP (Fpixmap_spec_p (Vface_default_stipple))) | |
1265 { | |
1266 x_destroy_bitmap (f, face->stipple); | |
1267 face->stipple = load_pixmap (f, Vface_default_stipple, | |
1268 &face->pixmap_w, &face->pixmap_h); | |
1269 } | |
25092
79a5a567bdb0
(prepare_face_for_display): Use FillOpaqueStippled instead of
Gerd Moellmann <gerd@gnu.org>
parents:
25062
diff
changeset
|
1270 |
79a5a567bdb0
(prepare_face_for_display): Use FillOpaqueStippled instead of
Gerd Moellmann <gerd@gnu.org>
parents:
25062
diff
changeset
|
1271 face->background = load_color (f, face, bg, LFACE_BACKGROUND_INDEX); |
24995 | 1272 face->foreground = load_color (f, face, fg, LFACE_FOREGROUND_INDEX); |
1273 } | |
1274 | |
1275 | |
1276 /* Free color PIXEL on frame F. */ | |
1277 | |
1278 void | |
1279 unload_color (f, pixel) | |
1280 struct frame *f; | |
1281 unsigned long pixel; | |
1282 { | |
1283 Display *dpy = FRAME_X_DISPLAY (f); | |
1284 int class = FRAME_X_DISPLAY_INFO (f)->visual->class; | |
1285 | |
1286 if (pixel == BLACK_PIX_DEFAULT (f) | |
1287 || pixel == WHITE_PIX_DEFAULT (f)) | |
1288 return; | |
1289 | |
1290 BLOCK_INPUT; | |
1291 | |
1292 /* If display has an immutable color map, freeing colors is not | |
1293 necessary and some servers don't allow it. So don't do it. */ | |
1294 if (! (class == StaticColor || class == StaticGray || class == TrueColor)) | |
1295 { | |
1296 Colormap cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f)); | |
1297 XFreeColors (dpy, cmap, &pixel, 1, 0); | |
1298 } | |
1299 | |
1300 UNBLOCK_INPUT; | |
1301 } | |
1302 | |
1303 | |
1304 /* Free colors allocated for FACE. */ | |
1305 | |
1306 static void | |
1307 free_face_colors (f, face) | |
1308 struct frame *f; | |
3074
96b4623fdeb3
* xterm.h: New section for declarations for xfaces.c.
Jim Blandy <jimb@redhat.com>
parents:
3065
diff
changeset
|
1309 struct face *face; |
96b4623fdeb3
* xterm.h: New section for declarations for xfaces.c.
Jim Blandy <jimb@redhat.com>
parents:
3065
diff
changeset
|
1310 { |
24995 | 1311 int class = FRAME_X_DISPLAY_INFO (f)->visual->class; |
1312 | |
1313 /* If display has an immutable color map, freeing colors is not | |
1314 necessary and some servers don't allow it. So don't do it. */ | |
1315 if (class != StaticColor | |
1316 && class != StaticGray | |
1317 && class != TrueColor) | |
1318 { | |
1319 Display *dpy; | |
1320 Colormap cmap; | |
1321 | |
1322 BLOCK_INPUT; | |
1323 dpy = FRAME_X_DISPLAY (f); | |
1324 cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f)); | |
1325 | |
1326 if (face->foreground != BLACK_PIX_DEFAULT (f) | |
1327 && face->foreground != WHITE_PIX_DEFAULT (f) | |
1328 && !face->foreground_defaulted_p) | |
1329 { | |
1330 XFreeColors (dpy, cmap, &face->foreground, 1, 0); | |
1331 IF_DEBUG (--ncolors_allocated); | |
1332 } | |
1333 | |
1334 if (face->background != BLACK_PIX_DEFAULT (f) | |
1335 && face->background != WHITE_PIX_DEFAULT (f) | |
1336 && !face->background_defaulted_p) | |
1337 { | |
1338 XFreeColors (dpy, cmap, &face->background, 1, 0); | |
1339 IF_DEBUG (--ncolors_allocated); | |
1340 } | |
1341 | |
1342 if (face->underline_p | |
1343 && !face->underline_defaulted_p | |
1344 && face->underline_color != BLACK_PIX_DEFAULT (f) | |
1345 && face->underline_color != WHITE_PIX_DEFAULT (f)) | |
1346 { | |
1347 XFreeColors (dpy, cmap, &face->underline_color, 1, 0); | |
1348 IF_DEBUG (--ncolors_allocated); | |
1349 } | |
1350 | |
1351 if (face->overline_p | |
1352 && !face->overline_color_defaulted_p | |
1353 && face->overline_color != BLACK_PIX_DEFAULT (f) | |
1354 && face->overline_color != WHITE_PIX_DEFAULT (f)) | |
1355 { | |
1356 XFreeColors (dpy, cmap, &face->overline_color, 1, 0); | |
1357 IF_DEBUG (--ncolors_allocated); | |
1358 } | |
1359 | |
1360 if (face->strike_through_p | |
1361 && !face->strike_through_color_defaulted_p | |
1362 && face->strike_through_color != BLACK_PIX_DEFAULT (f) | |
1363 && face->strike_through_color != WHITE_PIX_DEFAULT (f)) | |
1364 { | |
1365 XFreeColors (dpy, cmap, &face->strike_through_color, 1, 0); | |
1366 IF_DEBUG (--ncolors_allocated); | |
1367 } | |
1368 | |
1369 if (face->box != FACE_NO_BOX | |
1370 && !face->box_color_defaulted_p | |
1371 && face->box_color != BLACK_PIX_DEFAULT (f) | |
1372 && face->box_color != WHITE_PIX_DEFAULT (f)) | |
1373 { | |
1374 XFreeColors (dpy, cmap, &face->box_color, 1, 0); | |
1375 IF_DEBUG (--ncolors_allocated); | |
1376 } | |
1377 | |
1378 UNBLOCK_INPUT; | |
1379 } | |
1380 } | |
1381 | |
25114
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1382 #else /* ! HAVE_X_WINDOWS */ |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1383 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1384 #ifdef MSDOS |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1385 unsigned long |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1386 load_color (f, face, name, target_index) |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1387 struct frame *f; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1388 struct face *face; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1389 Lisp_Object name; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1390 enum lface_attribute_index target_index; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1391 { |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1392 Lisp_Object color; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1393 int color_idx = FACE_TTY_DEFAULT_COLOR; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1394 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1395 if (NILP (name)) |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1396 return (unsigned long)FACE_TTY_DEFAULT_COLOR; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1397 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1398 CHECK_STRING (name, 0); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1399 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1400 color = Qnil; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1401 if (XSTRING (name)->size && !NILP (Ffboundp (Qmsdos_color_translate))) |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1402 { |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1403 color = call1 (Qmsdos_color_translate, name); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1404 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1405 if (INTEGERP (color)) |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1406 return (unsigned long)XINT (color); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1407 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1408 display_message (f, "Unable to load color %s", name, Qnil); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1409 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1410 switch (target_index) |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1411 { |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1412 case LFACE_FOREGROUND_INDEX: |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1413 face->foreground_defaulted_p = 1; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1414 color_idx = FRAME_FOREGROUND_PIXEL (f); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1415 break; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1416 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1417 case LFACE_BACKGROUND_INDEX: |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1418 face->background_defaulted_p = 1; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1419 color_idx = FRAME_BACKGROUND_PIXEL (f); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1420 break; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1421 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1422 case LFACE_UNDERLINE_INDEX: |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1423 face->underline_defaulted_p = 1; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1424 color_idx = FRAME_FOREGROUND_PIXEL (f); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1425 break; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1426 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1427 case LFACE_OVERLINE_INDEX: |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1428 face->overline_color_defaulted_p = 1; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1429 color_idx = FRAME_FOREGROUND_PIXEL (f); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1430 break; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1431 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1432 case LFACE_STRIKE_THROUGH_INDEX: |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1433 face->strike_through_color_defaulted_p = 1; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1434 color_idx = FRAME_FOREGROUND_PIXEL (f); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1435 break; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1436 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1437 case LFACE_BOX_INDEX: |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1438 face->box_color_defaulted_p = 1; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1439 color_idx = FRAME_FOREGROUND_PIXEL (f); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1440 break; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1441 } |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1442 } |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1443 else |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1444 color_idx = msdos_stdcolor_idx (XSTRING (name)->data); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1445 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1446 return (unsigned long)color_idx; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1447 } |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1448 #endif /* MSDOS */ |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
1449 #endif /* ! HAVE_X_WINDOWS */ |
24995 | 1450 |
1451 | |
1452 | |
1453 /*********************************************************************** | |
1454 XLFD Font Names | |
1455 ***********************************************************************/ | |
1456 | |
1457 /* An enumerator for each field of an XLFD font name. */ | |
1458 | |
1459 enum xlfd_field | |
1460 { | |
1461 XLFD_FOUNDRY, | |
1462 XLFD_FAMILY, | |
1463 XLFD_WEIGHT, | |
1464 XLFD_SLANT, | |
1465 XLFD_SWIDTH, | |
1466 XLFD_ADSTYLE, | |
1467 XLFD_PIXEL_SIZE, | |
1468 XLFD_POINT_SIZE, | |
1469 XLFD_RESX, | |
1470 XLFD_RESY, | |
1471 XLFD_SPACING, | |
1472 XLFD_AVGWIDTH, | |
1473 XLFD_REGISTRY, | |
1474 XLFD_ENCODING, | |
1475 XLFD_LAST | |
1476 }; | |
1477 | |
1478 /* An enumerator for each possible slant value of a font. Taken from | |
1479 the XLFD specification. */ | |
1480 | |
1481 enum xlfd_slant | |
1482 { | |
1483 XLFD_SLANT_UNKNOWN, | |
1484 XLFD_SLANT_ROMAN, | |
1485 XLFD_SLANT_ITALIC, | |
1486 XLFD_SLANT_OBLIQUE, | |
1487 XLFD_SLANT_REVERSE_ITALIC, | |
1488 XLFD_SLANT_REVERSE_OBLIQUE, | |
1489 XLFD_SLANT_OTHER | |
1490 }; | |
1491 | |
1492 /* Relative font weight according to XLFD documentation. */ | |
1493 | |
1494 enum xlfd_weight | |
1495 { | |
1496 XLFD_WEIGHT_UNKNOWN, | |
1497 XLFD_WEIGHT_ULTRA_LIGHT, /* 10 */ | |
1498 XLFD_WEIGHT_EXTRA_LIGHT, /* 20 */ | |
1499 XLFD_WEIGHT_LIGHT, /* 30 */ | |
1500 XLFD_WEIGHT_SEMI_LIGHT, /* 40: SemiLight, Book, ... */ | |
1501 XLFD_WEIGHT_MEDIUM, /* 50: Medium, Normal, Regular, ... */ | |
1502 XLFD_WEIGHT_SEMI_BOLD, /* 60: SemiBold, DemiBold, ... */ | |
1503 XLFD_WEIGHT_BOLD, /* 70: Bold, ... */ | |
1504 XLFD_WEIGHT_EXTRA_BOLD, /* 80: ExtraBold, Heavy, ... */ | |
1505 XLFD_WEIGHT_ULTRA_BOLD /* 90: UltraBold, Black, ... */ | |
1506 }; | |
1507 | |
1508 /* Relative proportionate width. */ | |
1509 | |
1510 enum xlfd_swidth | |
1511 { | |
1512 XLFD_SWIDTH_UNKNOWN, | |
1513 XLFD_SWIDTH_ULTRA_CONDENSED, /* 10 */ | |
1514 XLFD_SWIDTH_EXTRA_CONDENSED, /* 20 */ | |
1515 XLFD_SWIDTH_CONDENSED, /* 30: Condensed, Narrow, Compressed, ... */ | |
1516 XLFD_SWIDTH_SEMI_CONDENSED, /* 40: semicondensed */ | |
1517 XLFD_SWIDTH_MEDIUM, /* 50: Medium, Normal, Regular, ... */ | |
1518 XLFD_SWIDTH_SEMI_EXPANDED, /* 60: SemiExpanded, DemiExpanded, ... */ | |
1519 XLFD_SWIDTH_EXPANDED, /* 70: Expanded... */ | |
1520 XLFD_SWIDTH_EXTRA_EXPANDED, /* 80: ExtraExpanded, Wide... */ | |
1521 XLFD_SWIDTH_ULTRA_EXPANDED /* 90: UltraExpanded... */ | |
1522 }; | |
1523 | |
1524 /* Structure used for tables mapping XLFD weight, slant, and width | |
1525 names to numeric and symbolic values. */ | |
1526 | |
1527 struct table_entry | |
1528 { | |
1529 char *name; | |
1530 int numeric; | |
1531 Lisp_Object *symbol; | |
1532 }; | |
1533 | |
1534 /* Table of XLFD slant names and their numeric and symbolic | |
1535 representations. This table must be sorted by slant names in | |
1536 ascending order. */ | |
1537 | |
1538 static struct table_entry slant_table[] = | |
1539 { | |
1540 {"i", XLFD_SLANT_ITALIC, &Qitalic}, | |
1541 {"o", XLFD_SLANT_OBLIQUE, &Qoblique}, | |
1542 {"ot", XLFD_SLANT_OTHER, &Qitalic}, | |
1543 {"r", XLFD_SLANT_ROMAN, &Qnormal}, | |
1544 {"ri", XLFD_SLANT_REVERSE_ITALIC, &Qreverse_italic}, | |
1545 {"ro", XLFD_SLANT_REVERSE_OBLIQUE, &Qreverse_oblique} | |
1546 }; | |
1547 | |
1548 /* Table of XLFD weight names. This table must be sorted by weight | |
1549 names in ascending order. */ | |
1550 | |
1551 static struct table_entry weight_table[] = | |
1552 { | |
1553 {"black", XLFD_WEIGHT_ULTRA_BOLD, &Qultra_bold}, | |
1554 {"bold", XLFD_WEIGHT_BOLD, &Qbold}, | |
1555 {"book", XLFD_WEIGHT_SEMI_LIGHT, &Qsemi_light}, | |
1556 {"demibold", XLFD_WEIGHT_SEMI_BOLD, &Qsemi_bold}, | |
1557 {"extralight", XLFD_WEIGHT_EXTRA_LIGHT, &Qextra_light}, | |
1558 {"extrabold", XLFD_WEIGHT_EXTRA_BOLD, &Qextra_bold}, | |
1559 {"heavy", XLFD_WEIGHT_EXTRA_BOLD, &Qextra_bold}, | |
1560 {"light", XLFD_WEIGHT_LIGHT, &Qlight}, | |
1561 {"medium", XLFD_WEIGHT_MEDIUM, &Qnormal}, | |
1562 {"normal", XLFD_WEIGHT_MEDIUM, &Qnormal}, | |
1563 {"regular", XLFD_WEIGHT_MEDIUM, &Qnormal}, | |
1564 {"semibold", XLFD_WEIGHT_SEMI_BOLD, &Qsemi_bold}, | |
1565 {"semilight", XLFD_WEIGHT_SEMI_LIGHT, &Qsemi_light}, | |
1566 {"ultralight", XLFD_WEIGHT_ULTRA_LIGHT, &Qultra_light}, | |
1567 {"ultrabold", XLFD_WEIGHT_ULTRA_BOLD, &Qultra_bold} | |
1568 }; | |
1569 | |
1570 /* Table of XLFD width names. This table must be sorted by width | |
1571 names in ascending order. */ | |
1572 | |
1573 static struct table_entry swidth_table[] = | |
1574 { | |
1575 {"compressed", XLFD_SWIDTH_CONDENSED, &Qcondensed}, | |
1576 {"condensed", XLFD_SWIDTH_CONDENSED, &Qcondensed}, | |
1577 {"demiexpanded", XLFD_SWIDTH_SEMI_EXPANDED, &Qsemi_expanded}, | |
1578 {"expanded", XLFD_SWIDTH_EXPANDED, &Qexpanded}, | |
1579 {"extracondensed", XLFD_SWIDTH_EXTRA_CONDENSED, &Qextra_condensed}, | |
1580 {"extraexpanded", XLFD_SWIDTH_EXTRA_EXPANDED, &Qextra_expanded}, | |
1581 {"medium", XLFD_SWIDTH_MEDIUM, &Qnormal}, | |
1582 {"narrow", XLFD_SWIDTH_CONDENSED, &Qcondensed}, | |
1583 {"normal", XLFD_SWIDTH_MEDIUM, &Qnormal}, | |
1584 {"regular", XLFD_SWIDTH_MEDIUM, &Qnormal}, | |
1585 {"semicondensed", XLFD_SWIDTH_SEMI_CONDENSED, &Qsemi_condensed}, | |
1586 {"semiexpanded", XLFD_SWIDTH_SEMI_EXPANDED, &Qsemi_expanded}, | |
1587 {"ultracondensed", XLFD_SWIDTH_ULTRA_CONDENSED, &Qultra_condensed}, | |
1588 {"ultraexpanded", XLFD_SWIDTH_ULTRA_EXPANDED, &Qultra_expanded}, | |
1589 {"wide", XLFD_SWIDTH_EXTRA_EXPANDED, &Qextra_expanded} | |
1590 }; | |
1591 | |
1592 /* Structure used to hold the result of splitting font names in XLFD | |
1593 format into their fields. */ | |
1594 | |
1595 struct font_name | |
1596 { | |
1597 /* The original name which is modified destructively by | |
1598 split_font_name. The pointer is kept here to be able to free it | |
1599 if it was allocated from the heap. */ | |
1600 char *name; | |
1601 | |
1602 /* Font name fields. Each vector element points into `name' above. | |
1603 Fields are NUL-terminated. */ | |
1604 char *fields[XLFD_LAST]; | |
1605 | |
1606 /* Numeric values for those fields that interest us. See | |
1607 split_font_name for which these are. */ | |
1608 int numeric[XLFD_LAST]; | |
1609 }; | |
1610 | |
1611 /* The frame in effect when sorting font names. Set temporarily in | |
1612 sort_fonts so that it is available in font comparison functions. */ | |
1613 | |
1614 static struct frame *font_frame; | |
1615 | |
1616 /* Order by which font selection chooses fonts. The default values | |
1617 mean `first, find a best match for the font width, then for the | |
1618 font height, then for weight, then for slant.' This variable can be | |
1619 set via set-face-font-sort-order. */ | |
1620 | |
1621 static int font_sort_order[4]; | |
1622 | |
1623 | |
1624 /* Look up FONT.fields[FIELD_INDEX] in TABLE which has DIM entries. | |
1625 TABLE must be sorted by TABLE[i]->name in ascending order. Value | |
1626 is a pointer to the matching table entry or null if no table entry | |
1627 matches. */ | |
1628 | |
1629 static struct table_entry * | |
1630 xlfd_lookup_field_contents (table, dim, font, field_index) | |
1631 struct table_entry *table; | |
1632 int dim; | |
1633 struct font_name *font; | |
1634 int field_index; | |
1635 { | |
1636 /* Function split_font_name converts fields to lower-case, so there | |
1637 is no need to use xstrlwr or xstricmp here. */ | |
1638 char *s = font->fields[field_index]; | |
1639 int low, mid, high, cmp; | |
1640 | |
1641 low = 0; | |
1642 high = dim - 1; | |
1643 | |
1644 while (low <= high) | |
1645 { | |
1646 mid = (low + high) / 2; | |
1647 cmp = strcmp (table[mid].name, s); | |
1648 | |
1649 if (cmp < 0) | |
1650 low = mid + 1; | |
1651 else if (cmp > 0) | |
1652 high = mid - 1; | |
1653 else | |
1654 return table + mid; | |
1655 } | |
1656 | |
1657 return NULL; | |
1658 } | |
1659 | |
1660 | |
1661 /* Return a numeric representation for font name field | |
1662 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which | |
1663 has DIM entries. Value is the numeric value found or DFLT if no | |
1664 table entry matches. This function is used to translate weight, | |
1665 slant, and swidth names of XLFD font names to numeric values. */ | |
1666 | |
1667 static INLINE int | |
1668 xlfd_numeric_value (table, dim, font, field_index, dflt) | |
1669 struct table_entry *table; | |
1670 int dim; | |
1671 struct font_name *font; | |
1672 int field_index; | |
1673 int dflt; | |
1674 { | |
1675 struct table_entry *p; | |
1676 p = xlfd_lookup_field_contents (table, dim, font, field_index); | |
1677 return p ? p->numeric : dflt; | |
1678 } | |
1679 | |
1680 | |
1681 /* Return a symbolic representation for font name field | |
1682 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which | |
1683 has DIM entries. Value is the symbolic value found or DFLT if no | |
1684 table entry matches. This function is used to translate weight, | |
1685 slant, and swidth names of XLFD font names to symbols. */ | |
1686 | |
1687 static INLINE Lisp_Object | |
1688 xlfd_symbolic_value (table, dim, font, field_index, dflt) | |
1689 struct table_entry *table; | |
1690 int dim; | |
1691 struct font_name *font; | |
1692 int field_index; | |
1693 int dflt; | |
1694 { | |
1695 struct table_entry *p; | |
1696 p = xlfd_lookup_field_contents (table, dim, font, field_index); | |
1697 return p ? *p->symbol : dflt; | |
1698 } | |
1699 | |
1700 | |
1701 /* Return a numeric value for the slant of the font given by FONT. */ | |
1702 | |
1703 static INLINE int | |
1704 xlfd_numeric_slant (font) | |
1705 struct font_name *font; | |
1706 { | |
1707 return xlfd_numeric_value (slant_table, DIM (slant_table), | |
1708 font, XLFD_SLANT, XLFD_SLANT_ROMAN); | |
1709 } | |
1710 | |
1711 | |
1712 /* Return a symbol representing the weight of the font given by FONT. */ | |
1713 | |
1714 static INLINE Lisp_Object | |
1715 xlfd_symbolic_slant (font) | |
1716 struct font_name *font; | |
1717 { | |
1718 return xlfd_symbolic_value (slant_table, DIM (slant_table), | |
1719 font, XLFD_SLANT, Qnormal); | |
1720 } | |
1721 | |
1722 | |
1723 /* Return a numeric value for the weight of the font given by FONT. */ | |
1724 | |
1725 static INLINE int | |
1726 xlfd_numeric_weight (font) | |
1727 struct font_name *font; | |
1728 { | |
1729 return xlfd_numeric_value (weight_table, DIM (weight_table), | |
1730 font, XLFD_WEIGHT, XLFD_WEIGHT_MEDIUM); | |
1731 } | |
1732 | |
1733 | |
1734 /* Return a symbol representing the slant of the font given by FONT. */ | |
1735 | |
1736 static INLINE Lisp_Object | |
1737 xlfd_symbolic_weight (font) | |
1738 struct font_name *font; | |
1739 { | |
1740 return xlfd_symbolic_value (weight_table, DIM (weight_table), | |
1741 font, XLFD_WEIGHT, Qnormal); | |
1742 } | |
1743 | |
1744 | |
1745 /* Return a numeric value for the swidth of the font whose XLFD font | |
1746 name fields are found in FONT. */ | |
1747 | |
1748 static INLINE int | |
1749 xlfd_numeric_swidth (font) | |
1750 struct font_name *font; | |
1751 { | |
1752 return xlfd_numeric_value (swidth_table, DIM (swidth_table), | |
1753 font, XLFD_SWIDTH, XLFD_SWIDTH_MEDIUM); | |
1754 } | |
1755 | |
1756 | |
1757 /* Return a symbolic value for the swidth of FONT. */ | |
1758 | |
1759 static INLINE Lisp_Object | |
1760 xlfd_symbolic_swidth (font) | |
1761 struct font_name *font; | |
1762 { | |
1763 return xlfd_symbolic_value (swidth_table, DIM (swidth_table), | |
1764 font, XLFD_SWIDTH, Qnormal); | |
1765 } | |
1766 | |
1767 | |
1768 /* Look up the entry of SYMBOL in the vector TABLE which has DIM | |
1769 entries. Value is a pointer to the matching table entry or null if | |
1770 no element of TABLE contains SYMBOL. */ | |
1771 | |
1772 static struct table_entry * | |
1773 face_value (table, dim, symbol) | |
1774 struct table_entry *table; | |
1775 int dim; | |
1776 Lisp_Object symbol; | |
1777 { | |
1778 int i; | |
1779 | |
1780 xassert (SYMBOLP (symbol)); | |
1781 | |
1782 for (i = 0; i < dim; ++i) | |
1783 if (EQ (*table[i].symbol, symbol)) | |
1784 break; | |
1785 | |
1786 return i < dim ? table + i : NULL; | |
1787 } | |
1788 | |
1789 | |
1790 /* Return a numeric value for SYMBOL in the vector TABLE which has DIM | |
1791 entries. Value is -1 if SYMBOL is not found in TABLE. */ | |
1792 | |
1793 static INLINE int | |
1794 face_numeric_value (table, dim, symbol) | |
1795 struct table_entry *table; | |
1796 int dim; | |
1797 Lisp_Object symbol; | |
1798 { | |
1799 struct table_entry *p = face_value (table, dim, symbol); | |
1800 return p ? p->numeric : -1; | |
1801 } | |
1802 | |
1803 | |
1804 /* Return a numeric value representing the weight specified by Lisp | |
1805 symbol WEIGHT. Value is one of the enumerators of enum | |
1806 xlfd_weight. */ | |
1807 | |
1808 static INLINE int | |
1809 face_numeric_weight (weight) | |
1810 Lisp_Object weight; | |
1811 { | |
1812 return face_numeric_value (weight_table, DIM (weight_table), weight); | |
1813 } | |
1814 | |
1815 | |
1816 /* Return a numeric value representing the slant specified by Lisp | |
1817 symbol SLANT. Value is one of the enumerators of enum xlfd_slant. */ | |
1818 | |
1819 static INLINE int | |
1820 face_numeric_slant (slant) | |
1821 Lisp_Object slant; | |
1822 { | |
1823 return face_numeric_value (slant_table, DIM (slant_table), slant); | |
1824 } | |
1825 | |
1826 | |
1827 /* Return a numeric value representing the swidth specified by Lisp | |
1828 symbol WIDTH. Value is one of the enumerators of enum xlfd_swidth. */ | |
1829 | |
1830 static int | |
1831 face_numeric_swidth (width) | |
1832 Lisp_Object width; | |
1833 { | |
1834 return face_numeric_value (swidth_table, DIM (swidth_table), width); | |
1835 } | |
1836 | |
1837 | |
1838 #ifdef HAVE_X_WINDOWS | |
1839 | |
1840 /* Return non-zero if FONT is the name of a fixed-pitch font. */ | |
1841 | |
1842 static INLINE int | |
1843 xlfd_fixed_p (font) | |
1844 struct font_name *font; | |
1845 { | |
1846 /* Function split_font_name converts fields to lower-case, so there | |
1847 is no need to use tolower here. */ | |
1848 return *font->fields[XLFD_SPACING] != 'p'; | |
1849 } | |
1850 | |
1851 | |
1852 /* Return the point size of FONT on frame F, measured in 1/10 pt. | |
1853 | |
1854 The actual height of the font when displayed on F depends on the | |
1855 resolution of both the font and frame. For example, a 10pt font | |
1856 designed for a 100dpi display will display larger than 10pt on a | |
1857 75dpi display. (It's not unusual to use fonts not designed for the | |
1858 display one is using. For example, some intlfonts are available in | |
1859 72dpi versions, only.) | |
1860 | |
1861 Value is the real point size of FONT on frame F, or 0 if it cannot | |
1862 be determined. */ | |
1863 | |
1864 static INLINE int | |
1865 xlfd_point_size (f, font) | |
1866 struct frame *f; | |
1867 struct font_name *font; | |
1868 { | |
1869 double resy = FRAME_X_DISPLAY_INFO (f)->resy; | |
1870 double font_resy = atoi (font->fields[XLFD_RESY]); | |
1871 double font_pt = atoi (font->fields[XLFD_POINT_SIZE]); | |
1872 int real_pt; | |
1873 | |
1874 if (font_resy == 0 || font_pt == 0) | |
1875 real_pt = 0; | |
1876 else | |
1877 real_pt = (font_resy / resy) * font_pt + 0.5; | |
1878 | |
1879 return real_pt; | |
1880 } | |
1881 | |
1882 | |
1883 /* Split XLFD font name FONT->name destructively into NUL-terminated, | |
1884 lower-case fields in FONT->fields. NUMERIC_P non-zero means | |
1885 compute numeric values for fields XLFD_POINT_SIZE, XLFD_SWIDTH, | |
1886 XLFD_RESY, XLFD_SLANT, and XLFD_WEIGHT in FONT->numeric. Value is | |
1887 zero if the font name doesn't have the format we expect. The | |
1888 expected format is a font name that starts with a `-' and has | |
1889 XLFD_LAST fields separated by `-'. (The XLFD specification allows | |
1890 forms of font names where certain field contents are enclosed in | |
1891 square brackets. We don't support that, for now. */ | |
1892 | |
1893 static int | |
1894 split_font_name (f, font, numeric_p) | |
1895 struct frame *f; | |
1896 struct font_name *font; | |
1897 int numeric_p; | |
1898 { | |
1899 int i = 0; | |
1900 int success_p; | |
1901 | |
1902 if (*font->name == '-') | |
1903 { | |
1904 char *p = xstrlwr (font->name) + 1; | |
1905 | |
1906 while (i < XLFD_LAST) | |
1907 { | |
1908 font->fields[i] = p; | |
1909 ++i; | |
1910 | |
1911 while (*p && *p != '-') | |
1912 ++p; | |
1913 | |
1914 if (*p != '-') | |
1915 break; | |
1916 | |
1917 *p++ = 0; | |
1918 } | |
1919 } | |
1920 | |
1921 success_p = i == XLFD_LAST; | |
1922 | |
1923 /* If requested, and font name was in the expected format, | |
1924 compute numeric values for some fields. */ | |
1925 if (numeric_p && success_p) | |
1926 { | |
1927 font->numeric[XLFD_POINT_SIZE] = xlfd_point_size (f, font); | |
1928 font->numeric[XLFD_RESY] = atoi (font->fields[XLFD_RESY]); | |
1929 font->numeric[XLFD_SLANT] = xlfd_numeric_slant (font); | |
1930 font->numeric[XLFD_WEIGHT] = xlfd_numeric_weight (font); | |
1931 font->numeric[XLFD_SWIDTH] = xlfd_numeric_swidth (font); | |
1932 } | |
1933 | |
1934 return success_p; | |
1935 } | |
1936 | |
1937 | |
1938 /* Build an XLFD font name from font name fields in FONT. Value is a | |
1939 pointer to the font name, which is allocated via xmalloc. */ | |
1940 | |
1941 static char * | |
1942 build_font_name (font) | |
1943 struct font_name *font; | |
1944 { | |
1945 int i; | |
1946 int size = 100; | |
1947 char *font_name = (char *) xmalloc (size); | |
1948 int total_length = 0; | |
1949 | |
1950 for (i = 0; i < XLFD_LAST; ++i) | |
1951 { | |
1952 /* Add 1 because of the leading `-'. */ | |
1953 int len = strlen (font->fields[i]) + 1; | |
1954 | |
1955 /* Reallocate font_name if necessary. Add 1 for the final | |
1956 NUL-byte. */ | |
1957 if (total_length + len + 1 >= size) | |
1958 { | |
1959 int new_size = max (2 * size, size + len + 1); | |
1960 int sz = new_size * sizeof *font_name; | |
1961 font_name = (char *) xrealloc (font_name, sz); | |
1962 size = new_size; | |
1963 } | |
1964 | |
1965 font_name[total_length] = '-'; | |
1966 bcopy (font->fields[i], font_name + total_length + 1, len - 1); | |
1967 total_length += len; | |
1968 } | |
1969 | |
1970 font_name[total_length] = 0; | |
1971 return font_name; | |
1972 } | |
1973 | |
1974 | |
1975 /* Free an array FONTS of N font_name structures. This frees FONTS | |
1976 itself and all `name' fields in its elements. */ | |
1977 | |
1978 static INLINE void | |
1979 free_font_names (fonts, n) | |
1980 struct font_name *fonts; | |
1981 int n; | |
1982 { | |
1983 while (n) | |
1984 xfree (fonts[--n].name); | |
1985 xfree (fonts); | |
1986 } | |
1987 | |
1988 | |
1989 /* Sort vector FONTS of font_name structures which contains NFONTS | |
1990 elements using qsort and comparison function CMPFN. F is the frame | |
1991 on which the fonts will be used. The global variable font_frame | |
1992 is temporarily set to F to make it available in CMPFN. */ | |
1993 | |
1994 static INLINE void | |
1995 sort_fonts (f, fonts, nfonts, cmpfn) | |
1996 struct frame *f; | |
1997 struct font_name *fonts; | |
1998 int nfonts; | |
1999 int (*cmpfn) P_ ((const void *, const void *)); | |
2000 { | |
2001 font_frame = f; | |
2002 qsort (fonts, nfonts, sizeof *fonts, cmpfn); | |
2003 font_frame = NULL; | |
3074
96b4623fdeb3
* xterm.h: New section for declarations for xfaces.c.
Jim Blandy <jimb@redhat.com>
parents:
3065
diff
changeset
|
2004 } |
96b4623fdeb3
* xterm.h: New section for declarations for xfaces.c.
Jim Blandy <jimb@redhat.com>
parents:
3065
diff
changeset
|
2005 |
24995 | 2006 |
2007 /* Get fonts matching PATTERN on frame F. If F is null, use the first | |
2008 display in x_display_list. FONTS is a pointer to a vector of | |
2009 NFONTS font_name structures. TRY_ALTERNATIVES_P non-zero means try | |
2010 alternative patterns from Valternate_fontname_alist if no fonts are | |
2011 found matching PATTERN. SCALABLE_FONTS_P non-zero means include | |
2012 scalable fonts. | |
2013 | |
2014 For all fonts found, set FONTS[i].name to the name of the font, | |
2015 allocated via xmalloc, and split font names into fields. Ignore | |
2016 fonts that we can't parse. Value is the number of fonts found. | |
2017 | |
2018 This is similar to x_list_fonts. The differences are: | |
2019 | |
2020 1. It avoids consing. | |
2021 2. It never calls XLoadQueryFont. */ | |
2022 | |
2023 static int | |
2024 x_face_list_fonts (f, pattern, fonts, nfonts, try_alternatives_p, | |
2025 scalable_fonts_p) | |
2026 struct frame *f; | |
2027 char *pattern; | |
2028 struct font_name *fonts; | |
2029 int nfonts, try_alternatives_p; | |
2030 int scalable_fonts_p; | |
2031 { | |
2032 Display *dpy = f ? FRAME_X_DISPLAY (f) : x_display_list->display; | |
2033 int n, i, j; | |
2034 char **names; | |
2035 | |
2036 /* Get the list of fonts matching PATTERN from the X server. */ | |
2037 BLOCK_INPUT; | |
2038 names = XListFonts (dpy, pattern, nfonts, &n); | |
2039 UNBLOCK_INPUT; | |
2040 | |
2041 if (names) | |
2042 { | |
2043 /* Make a copy of the font names we got from X, and | |
2044 split them into fields. */ | |
2045 for (i = j = 0; i < n; ++i) | |
2046 { | |
2047 /* Make a copy of the font name. */ | |
2048 fonts[j].name = xstrdup (names[i]); | |
2049 | |
2050 /* Ignore fonts having a name that we can't parse. */ | |
2051 if (!split_font_name (f, fonts + j, 1)) | |
2052 xfree (fonts[j].name); | |
2053 else if (font_scalable_p (fonts + j)) | |
2054 { | |
2055 #if SCALABLE_FONTS | |
2056 if (!scalable_fonts_p | |
2057 || !may_use_scalable_font_p (fonts + j, names[i])) | |
2058 xfree (fonts[j].name); | |
2059 else | |
2060 ++j; | |
2061 #else /* !SCALABLE_FONTS */ | |
2062 /* Always ignore scalable fonts. */ | |
2063 xfree (fonts[j].name); | |
2064 #endif /* !SCALABLE_FONTS */ | |
2065 } | |
2066 else | |
2067 ++j; | |
2068 } | |
2069 | |
2070 n = j; | |
2071 | |
2072 /* Free font names. */ | |
2073 BLOCK_INPUT; | |
2074 XFreeFontNames (names); | |
2075 UNBLOCK_INPUT; | |
2076 } | |
2077 | |
2078 | |
2079 /* If no fonts found, try patterns from Valternate_fontname_alist. */ | |
2080 if (n == 0 && try_alternatives_p) | |
2081 { | |
2082 Lisp_Object list = Valternate_fontname_alist; | |
2083 | |
2084 while (CONSP (list)) | |
2085 { | |
2086 Lisp_Object entry = XCAR (list); | |
2087 if (CONSP (entry) | |
2088 && STRINGP (XCAR (entry)) | |
2089 && strcmp (XSTRING (XCAR (entry))->data, pattern) == 0) | |
2090 break; | |
2091 list = XCDR (list); | |
2092 } | |
2093 | |
2094 if (CONSP (list)) | |
2095 { | |
2096 Lisp_Object patterns = XCAR (list); | |
2097 Lisp_Object name; | |
2098 | |
2099 while (CONSP (patterns) | |
2100 /* If list is screwed up, give up. */ | |
2101 && (name = XCAR (patterns), | |
2102 STRINGP (name)) | |
2103 /* Ignore patterns equal to PATTERN because we tried that | |
2104 already with no success. */ | |
2105 && (strcmp (XSTRING (name)->data, pattern) == 0 | |
2106 || (n = x_face_list_fonts (f, XSTRING (name)->data, | |
2107 fonts, nfonts, 0, | |
2108 scalable_fonts_p), | |
2109 n == 0))) | |
2110 patterns = XCDR (patterns); | |
2111 } | |
2112 } | |
2113 | |
2114 return n; | |
2115 } | |
2116 | |
2117 | |
2118 /* Determine the first font matching PATTERN on frame F. Return in | |
2119 *FONT the matching font name, split into fields. Value is non-zero | |
2120 if a match was found. */ | |
2121 | |
2122 static int | |
2123 first_font_matching (f, pattern, font) | |
2124 struct frame *f; | |
2125 char *pattern; | |
2126 struct font_name *font; | |
2127 { | |
2128 int nfonts = 100; | |
2129 struct font_name *fonts; | |
2130 | |
2131 fonts = (struct font_name *) xmalloc (nfonts * sizeof *fonts); | |
2132 nfonts = x_face_list_fonts (f, pattern, fonts, nfonts, 1, 0); | |
2133 | |
2134 if (nfonts > 0) | |
2135 { | |
2136 bcopy (&fonts[0], font, sizeof *font); | |
2137 | |
2138 fonts[0].name = NULL; | |
2139 free_font_names (fonts, nfonts); | |
2140 } | |
2141 | |
2142 return nfonts > 0; | |
2143 } | |
2144 | |
2145 | |
2146 /* Determine fonts matching PATTERN on frame F. Sort resulting fonts | |
2147 using comparison function CMPFN. Value is the number of fonts | |
2148 found. If value is non-zero, *FONTS is set to a vector of | |
2149 font_name structures allocated from the heap containing matching | |
2150 fonts. Each element of *FONTS contains a name member that is also | |
2151 allocated from the heap. Font names in these structures are split | |
2152 into fields. Use free_font_names to free such an array. */ | |
2153 | |
2154 static int | |
2155 sorted_font_list (f, pattern, cmpfn, fonts) | |
2156 struct frame *f; | |
2157 char *pattern; | |
2158 int (*cmpfn) P_ ((const void *, const void *)); | |
2159 struct font_name **fonts; | |
2160 { | |
2161 int nfonts; | |
2162 | |
2163 /* Get the list of fonts matching pattern. 100 should suffice. */ | |
25270 | 2164 nfonts = DEFAULT_FONT_LIST_LIMIT; |
2165 if (INTEGERP (Vfont_list_limit) && XINT (Vfont_list_limit) > 0) | |
2166 nfonts = XFASTINT (Vfont_list_limit); | |
2167 | |
24995 | 2168 *fonts = (struct font_name *) xmalloc (nfonts * sizeof **fonts); |
2169 #if SCALABLE_FONTS | |
2170 nfonts = x_face_list_fonts (f, pattern, *fonts, nfonts, 1, 1); | |
2171 #else | |
2172 nfonts = x_face_list_fonts (f, pattern, *fonts, nfonts, 1, 0); | |
2173 #endif | |
2174 | |
2175 /* Sort the resulting array and return it in *FONTS. If no | |
2176 fonts were found, make sure to set *FONTS to null. */ | |
2177 if (nfonts) | |
2178 sort_fonts (f, *fonts, nfonts, cmpfn); | |
2179 else | |
2180 { | |
2181 xfree (*fonts); | |
2182 *fonts = NULL; | |
2183 } | |
2184 | |
2185 return nfonts; | |
2186 } | |
2187 | |
2188 | |
2189 /* Compare two font_name structures *A and *B. Value is analogous to | |
2190 strcmp. Sort order is given by the global variable | |
2191 font_sort_order. Font names are sorted so that, everything else | |
2192 being equal, fonts with a resolution closer to that of the frame on | |
2193 which they are used are listed first. The global variable | |
2194 font_frame is the frame on which we operate. */ | |
2195 | |
2196 static int | |
2197 cmp_font_names (a, b) | |
2198 const void *a, *b; | |
2199 { | |
2200 struct font_name *x = (struct font_name *) a; | |
2201 struct font_name *y = (struct font_name *) b; | |
2202 int cmp; | |
2203 | |
2204 /* All strings have been converted to lower-case by split_font_name, | |
2205 so we can use strcmp here. */ | |
2206 cmp = strcmp (x->fields[XLFD_FAMILY], y->fields[XLFD_FAMILY]); | |
2207 if (cmp == 0) | |
2208 { | |
2209 int i; | |
2210 | |
2211 for (i = 0; i < DIM (font_sort_order) && cmp == 0; ++i) | |
2212 { | |
2213 int j = font_sort_order[i]; | |
2214 cmp = x->numeric[j] - y->numeric[j]; | |
2215 } | |
2216 | |
2217 if (cmp == 0) | |
2218 { | |
2219 /* Everything else being equal, we prefer fonts with an | |
2220 y-resolution closer to that of the frame. */ | |
2221 int resy = FRAME_X_DISPLAY_INFO (font_frame)->resy; | |
2222 int x_resy = x->numeric[XLFD_RESY]; | |
2223 int y_resy = y->numeric[XLFD_RESY]; | |
2224 cmp = abs (resy - x_resy) - abs (resy - y_resy); | |
2225 } | |
2226 } | |
2227 | |
2228 return cmp; | |
2229 } | |
2230 | |
2231 | |
2232 /* Get a sorted list of fonts of family FAMILY on frame F. If PATTERN | |
2233 is non-null list fonts matching that pattern. Otherwise, if | |
2234 REGISTRY_AND_ENCODING is non-null return only fonts with that | |
2235 registry and encoding, otherwise return fonts of any registry and | |
2236 encoding. Set *FONTS to a vector of font_name structures allocated | |
2237 from the heap containing the fonts found. Value is the number of | |
2238 fonts found. */ | |
2239 | |
2240 static int | |
2241 font_list (f, pattern, family, registry_and_encoding, fonts) | |
2242 struct frame *f; | |
2243 char *pattern; | |
2244 char *family; | |
2245 char *registry_and_encoding; | |
2246 struct font_name **fonts; | |
2247 { | |
2248 if (pattern == NULL) | |
2249 { | |
2250 if (family == NULL) | |
2251 family = "*"; | |
2252 | |
2253 if (registry_and_encoding == NULL) | |
2254 registry_and_encoding = "*"; | |
2255 | |
2256 pattern = (char *) alloca (strlen (family) | |
2257 + strlen (registry_and_encoding) | |
2258 + 10); | |
2259 if (index (family, '-')) | |
2260 sprintf (pattern, "-%s-*-%s", family, registry_and_encoding); | |
2261 else | |
2262 sprintf (pattern, "-*-%s-*-%s", family, registry_and_encoding); | |
2263 } | |
2264 | |
2265 return sorted_font_list (f, pattern, cmp_font_names, fonts); | |
2266 } | |
2267 | |
2268 | |
2269 /* Remove elements from LIST whose cars are `equal'. Called from | |
2270 x-font-list and x-font-family-list to remove duplicate font | |
2271 entries. */ | |
2272 | |
2273 static void | |
2274 remove_duplicates (list) | |
2275 Lisp_Object list; | |
2276 { | |
2277 Lisp_Object tail = list; | |
2278 | |
2279 while (!NILP (tail) && !NILP (XCDR (tail))) | |
2280 { | |
2281 Lisp_Object next = XCDR (tail); | |
2282 if (!NILP (Fequal (XCAR (next), XCAR (tail)))) | |
2283 XCDR (tail) = XCDR (next); | |
2284 else | |
2285 tail = XCDR (tail); | |
2286 } | |
2287 } | |
2288 | |
2289 | |
2290 DEFUN ("x-font-list", Fxfont_list, Sx_font_list, 0, 2, 0, | |
2291 "Return a list of available fonts of family FAMILY on FRAME.\n\ | |
2292 If FAMILY is omitted or nil, list all families.\n\ | |
2293 Otherwise, FAMILY must be a string, possibly containing wildcards\n\ | |
2294 `?' and `*'.\n\ | |
2295 If FRAME is omitted or nil, use the selected frame.\n\ | |
2296 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT\n\ | |
25270 | 2297 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].\n\ |
24995 | 2298 FAMILY is the font family name. POINT-SIZE is the size of the\n\ |
2299 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the\n\ | |
2300 width, weight and slant of the font. These symbols are the same as for\n\ | |
2301 face attributes. FIXED-P is non-nil if the font is fixed-pitch.\n\ | |
25270 | 2302 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string\n\ |
2303 giving the registry and encoding of the font.\n\ | |
24995 | 2304 The result list is sorted according to the current setting of\n\ |
2305 the face font sort order.") | |
2306 (family, frame) | |
2307 Lisp_Object family, frame; | |
2308 { | |
2309 struct frame *f = check_x_frame (frame); | |
2310 struct font_name *fonts; | |
2311 int i, nfonts; | |
2312 Lisp_Object result; | |
2313 struct gcpro gcpro1; | |
2314 char *family_pattern; | |
2315 | |
2316 if (NILP (family)) | |
2317 family_pattern = "*"; | |
2318 else | |
2319 { | |
2320 CHECK_STRING (family, 1); | |
2321 family_pattern = LSTRDUPA (family); | |
2322 } | |
2323 | |
2324 result = Qnil; | |
2325 GCPRO1 (result); | |
2326 nfonts = font_list (f, NULL, family_pattern, NULL, &fonts); | |
2327 for (i = nfonts - 1; i >= 0; --i) | |
2328 { | |
25270 | 2329 Lisp_Object v = Fmake_vector (make_number (8), Qnil); |
2330 char *tem; | |
24995 | 2331 |
2332 #define ASET(VECTOR, IDX, VAL) (XVECTOR (VECTOR)->contents[IDX] = (VAL)) | |
2333 | |
2334 ASET (v, 0, build_string (fonts[i].fields[XLFD_FAMILY])); | |
2335 ASET (v, 1, xlfd_symbolic_swidth (fonts + i)); | |
2336 ASET (v, 2, make_number (xlfd_point_size (f, fonts + i))); | |
2337 ASET (v, 3, xlfd_symbolic_weight (fonts + i)); | |
2338 ASET (v, 4, xlfd_symbolic_slant (fonts + i)); | |
2339 ASET (v, 5, xlfd_fixed_p (fonts + i) ? Qt : Qnil); | |
25270 | 2340 tem = build_font_name (fonts + i); |
2341 ASET (v, 6, build_string (tem)); | |
2342 sprintf (tem, "%s-%s", fonts[i].fields[XLFD_REGISTRY], | |
2343 fonts[i].fields[XLFD_ENCODING]); | |
2344 ASET (v, 7, build_string (tem)); | |
2345 xfree (tem); | |
2346 | |
24995 | 2347 result = Fcons (v, result); |
2348 | |
2349 #undef ASET | |
2350 } | |
2351 | |
2352 remove_duplicates (result); | |
2353 free_font_names (fonts, nfonts); | |
2354 UNGCPRO; | |
2355 return result; | |
2356 } | |
2357 | |
2358 | |
2359 DEFUN ("x-font-family-list", Fx_font_family_list, Sx_font_family_list, | |
2360 0, 1, 0, | |
2361 "Return a list of available font families on FRAME.\n\ | |
2362 If FRAME is omitted or nil, use the selected frame.\n\ | |
2363 Value is a list of conses (FAMILY . FIXED-P) where FAMILY\n\ | |
2364 is a font family, and FIXED-P is non-nil if fonts of that family\n\ | |
2365 are fixed-pitch.") | |
2366 (frame) | |
2367 Lisp_Object frame; | |
2368 { | |
2369 struct frame *f = check_x_frame (frame); | |
2370 int nfonts, i; | |
2371 struct font_name *fonts; | |
2372 Lisp_Object result; | |
2373 struct gcpro gcpro1; | |
25270 | 2374 int count = specpdl_ptr - specpdl; |
2375 int limit; | |
2376 | |
2377 /* Let's consider all fonts. Increase the limit for matching | |
2378 fonts until we have them all. */ | |
2379 for (limit = 500;;) | |
2380 { | |
2381 specbind (intern ("font-list-limit"), make_number (limit)); | |
2382 nfonts = font_list (f, NULL, "*", NULL, &fonts); | |
2383 | |
2384 if (nfonts == limit) | |
2385 { | |
2386 free_font_names (fonts, nfonts); | |
2387 limit *= 2; | |
2388 } | |
2389 else | |
2390 break; | |
2391 } | |
24995 | 2392 |
2393 result = Qnil; | |
2394 GCPRO1 (result); | |
2395 for (i = nfonts - 1; i >= 0; --i) | |
2396 result = Fcons (Fcons (build_string (fonts[i].fields[XLFD_FAMILY]), | |
2397 xlfd_fixed_p (fonts + i) ? Qt : Qnil), | |
2398 result); | |
2399 | |
2400 remove_duplicates (result); | |
2401 free_font_names (fonts, nfonts); | |
2402 UNGCPRO; | |
25270 | 2403 return unbind_to (count, result); |
24995 | 2404 } |
2405 | |
2406 | |
2407 DEFUN ("x-list-fonts", Fx_list_fonts, Sx_list_fonts, 1, 5, 0, | |
2408 "Return a list of the names of available fonts matching PATTERN.\n\ | |
2409 If optional arguments FACE and FRAME are specified, return only fonts\n\ | |
2410 the same size as FACE on FRAME.\n\ | |
2411 PATTERN is a string, perhaps with wildcard characters;\n\ | |
2412 the * character matches any substring, and\n\ | |
2413 the ? character matches any single character.\n\ | |
2414 PATTERN is case-insensitive.\n\ | |
2415 FACE is a face name--a symbol.\n\ | |
2416 \n\ | |
2417 The return value is a list of strings, suitable as arguments to\n\ | |
2418 set-face-font.\n\ | |
2419 \n\ | |
2420 Fonts Emacs can't use may or may not be excluded\n\ | |
2421 even if they match PATTERN and FACE.\n\ | |
2422 The optional fourth argument MAXIMUM sets a limit on how many\n\ | |
2423 fonts to match. The first MAXIMUM fonts are reported.\n\ | |
2424 The optional fifth argument WIDTH, if specified, is a number of columns\n\ | |
2425 occupied by a character of a font. In that case, return only fonts\n\ | |
2426 the WIDTH times as wide as FACE on FRAME.") | |
2427 (pattern, face, frame, maximum, width) | |
2428 Lisp_Object pattern, face, frame, maximum, width; | |
2429 { | |
2430 struct frame *f; | |
2431 int size; | |
2432 int maxnames; | |
2433 | |
2434 check_x (); | |
2435 CHECK_STRING (pattern, 0); | |
2436 | |
2437 if (NILP (maximum)) | |
2438 maxnames = 2000; | |
2439 else | |
2440 { | |
2441 CHECK_NATNUM (maximum, 0); | |
2442 maxnames = XINT (maximum); | |
2443 } | |
2444 | |
2445 if (!NILP (width)) | |
2446 CHECK_NUMBER (width, 4); | |
2447 | |
2448 /* We can't simply call check_x_frame because this function may be | |
2449 called before any frame is created. */ | |
2450 f = frame_or_selected_frame (frame, 2); | |
2451 if (!FRAME_X_P (f)) | |
2452 { | |
2453 /* Perhaps we have not yet created any frame. */ | |
2454 f = NULL; | |
2455 face = Qnil; | |
2456 } | |
2457 | |
2458 /* Determine the width standard for comparison with the fonts we find. */ | |
2459 | |
2460 if (NILP (face)) | |
2461 size = 0; | |
2462 else | |
2463 { | |
2464 /* This is of limited utility since it works with character | |
2465 widths. Keep it for compatibility. --gerd. */ | |
2466 int face_id = lookup_named_face (f, face, CHARSET_ASCII); | |
2467 struct face *face = FACE_FROM_ID (f, face_id); | |
2468 | |
2469 if (face->font) | |
2470 size = face->font->max_bounds.width; | |
2471 else | |
2472 size = FRAME_FONT (f)->max_bounds.width; | |
2473 | |
2474 if (!NILP (width)) | |
2475 size *= XINT (width); | |
2476 } | |
2477 | |
2478 { | |
2479 Lisp_Object args[2]; | |
2480 | |
2481 args[0] = x_list_fonts (f, pattern, size, maxnames); | |
2482 if (f == NULL) | |
2483 /* We don't have to check fontsets. */ | |
2484 return args[0]; | |
2485 args[1] = list_fontsets (f, pattern, size); | |
2486 return Fnconc (2, args); | |
2487 } | |
2488 } | |
2489 | |
2490 #endif /* HAVE_X_WINDOWS */ | |
2491 | |
2492 | |
2493 | |
2494 /*********************************************************************** | |
2495 Lisp Faces | |
2496 ***********************************************************************/ | |
2497 | |
2498 /* Access face attributes of face FACE, a Lisp vector. */ | |
2499 | |
2500 #define LFACE_FAMILY(LFACE) \ | |
2501 XVECTOR (LFACE)->contents[LFACE_FAMILY_INDEX] | |
2502 #define LFACE_HEIGHT(LFACE) \ | |
2503 XVECTOR (LFACE)->contents[LFACE_HEIGHT_INDEX] | |
2504 #define LFACE_WEIGHT(LFACE) \ | |
2505 XVECTOR (LFACE)->contents[LFACE_WEIGHT_INDEX] | |
2506 #define LFACE_SLANT(LFACE) \ | |
2507 XVECTOR (LFACE)->contents[LFACE_SLANT_INDEX] | |
2508 #define LFACE_UNDERLINE(LFACE) \ | |
2509 XVECTOR (LFACE)->contents[LFACE_UNDERLINE_INDEX] | |
2510 #define LFACE_INVERSE(LFACE) \ | |
2511 XVECTOR (LFACE)->contents[LFACE_INVERSE_INDEX] | |
2512 #define LFACE_FOREGROUND(LFACE) \ | |
2513 XVECTOR (LFACE)->contents[LFACE_FOREGROUND_INDEX] | |
2514 #define LFACE_BACKGROUND(LFACE) \ | |
2515 XVECTOR (LFACE)->contents[LFACE_BACKGROUND_INDEX] | |
2516 #define LFACE_STIPPLE(LFACE) \ | |
2517 XVECTOR (LFACE)->contents[LFACE_STIPPLE_INDEX] | |
2518 #define LFACE_SWIDTH(LFACE) \ | |
2519 XVECTOR (LFACE)->contents[LFACE_SWIDTH_INDEX] | |
2520 #define LFACE_OVERLINE(LFACE) \ | |
2521 XVECTOR (LFACE)->contents[LFACE_OVERLINE_INDEX] | |
2522 #define LFACE_STRIKE_THROUGH(LFACE) \ | |
2523 XVECTOR (LFACE)->contents[LFACE_STRIKE_THROUGH_INDEX] | |
2524 #define LFACE_BOX(LFACE) \ | |
2525 XVECTOR (LFACE)->contents[LFACE_BOX_INDEX] | |
2526 | |
2527 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size | |
2528 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */ | |
2529 | |
2530 #define LFACEP(LFACE) \ | |
2531 (VECTORP (LFACE) \ | |
2532 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \ | |
2533 && EQ (XVECTOR (LFACE)->contents[0], Qface)) | |
2534 | |
2535 | |
2536 #if GLYPH_DEBUG | |
2537 | |
2538 /* Check consistency of Lisp face attribute vector ATTRS. */ | |
2539 | |
2540 static void | |
2541 check_lface_attrs (attrs) | |
2542 Lisp_Object *attrs; | |
2543 { | |
2544 xassert (UNSPECIFIEDP (attrs[LFACE_FAMILY_INDEX]) | |
2545 || STRINGP (attrs[LFACE_FAMILY_INDEX])); | |
2546 xassert (UNSPECIFIEDP (attrs[LFACE_SWIDTH_INDEX]) | |
2547 || SYMBOLP (attrs[LFACE_SWIDTH_INDEX])); | |
2548 xassert (UNSPECIFIEDP (attrs[LFACE_HEIGHT_INDEX]) | |
2549 || INTEGERP (attrs[LFACE_HEIGHT_INDEX])); | |
2550 xassert (UNSPECIFIEDP (attrs[LFACE_WEIGHT_INDEX]) | |
2551 || SYMBOLP (attrs[LFACE_WEIGHT_INDEX])); | |
2552 xassert (UNSPECIFIEDP (attrs[LFACE_SLANT_INDEX]) | |
2553 || SYMBOLP (attrs[LFACE_SLANT_INDEX])); | |
2554 xassert (UNSPECIFIEDP (attrs[LFACE_UNDERLINE_INDEX]) | |
2555 || SYMBOLP (attrs[LFACE_UNDERLINE_INDEX]) | |
2556 || STRINGP (attrs[LFACE_UNDERLINE_INDEX])); | |
2557 xassert (UNSPECIFIEDP (attrs[LFACE_OVERLINE_INDEX]) | |
2558 || SYMBOLP (attrs[LFACE_OVERLINE_INDEX]) | |
2559 || STRINGP (attrs[LFACE_OVERLINE_INDEX])); | |
2560 xassert (UNSPECIFIEDP (attrs[LFACE_STRIKE_THROUGH_INDEX]) | |
2561 || SYMBOLP (attrs[LFACE_STRIKE_THROUGH_INDEX]) | |
2562 || STRINGP (attrs[LFACE_STRIKE_THROUGH_INDEX])); | |
2563 xassert (UNSPECIFIEDP (attrs[LFACE_BOX_INDEX]) | |
2564 || SYMBOLP (attrs[LFACE_BOX_INDEX]) | |
2565 || STRINGP (attrs[LFACE_BOX_INDEX]) | |
2566 || INTEGERP (attrs[LFACE_BOX_INDEX]) | |
2567 || CONSP (attrs[LFACE_BOX_INDEX])); | |
2568 xassert (UNSPECIFIEDP (attrs[LFACE_INVERSE_INDEX]) | |
2569 || SYMBOLP (attrs[LFACE_INVERSE_INDEX])); | |
2570 xassert (UNSPECIFIEDP (attrs[LFACE_FOREGROUND_INDEX]) | |
2571 || STRINGP (attrs[LFACE_FOREGROUND_INDEX])); | |
2572 xassert (UNSPECIFIEDP (attrs[LFACE_BACKGROUND_INDEX]) | |
2573 || STRINGP (attrs[LFACE_BACKGROUND_INDEX])); | |
2574 #ifdef HAVE_WINDOW_SYSTEM | |
2575 xassert (UNSPECIFIEDP (attrs[LFACE_STIPPLE_INDEX]) | |
2576 || SYMBOLP (attrs[LFACE_STIPPLE_INDEX]) | |
2577 || !NILP (Fpixmap_spec_p (attrs[LFACE_STIPPLE_INDEX]))); | |
2578 #endif | |
2579 } | |
2580 | |
2581 | |
2582 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */ | |
2583 | |
2584 static void | |
2585 check_lface (lface) | |
2586 Lisp_Object lface; | |
2587 { | |
2588 if (!NILP (lface)) | |
2589 { | |
2590 xassert (LFACEP (lface)); | |
2591 check_lface_attrs (XVECTOR (lface)->contents); | |
2592 } | |
2593 } | |
2594 | |
2595 #else /* GLYPH_DEBUG == 0 */ | |
2596 | |
2597 #define check_lface_attrs(attrs) (void) 0 | |
2598 #define check_lface(lface) (void) 0 | |
2599 | |
2600 #endif /* GLYPH_DEBUG == 0 */ | |
2601 | |
2602 | |
2603 /* Return the face definition of FACE_NAME on frame F. F null means | |
2604 return the global definition. FACE_NAME may be a string or a | |
2605 symbol (apparently Emacs 20.2 allows strings as face names in face | |
2606 text properties; ediff uses that). If SIGNAL_P is non-zero, signal | |
2607 an error if FACE_NAME is not a valid face name. If SIGNAL_P is | |
2608 zero, value is nil if FACE_NAME is not a valid face name. */ | |
2609 | |
2610 static INLINE Lisp_Object | |
2611 lface_from_face_name (f, face_name, signal_p) | |
2612 struct frame *f; | |
2613 Lisp_Object face_name; | |
2614 int signal_p; | |
2615 { | |
2616 Lisp_Object lface; | |
2617 | |
2618 if (STRINGP (face_name)) | |
2619 face_name = intern (XSTRING (face_name)->data); | |
2620 | |
2621 if (f) | |
2622 lface = assq_no_quit (face_name, f->face_alist); | |
2623 else | |
2624 lface = assq_no_quit (face_name, Vface_new_frame_defaults); | |
2625 | |
2626 if (CONSP (lface)) | |
2627 lface = XCDR (lface); | |
2628 else if (signal_p) | |
2629 signal_error ("Invalid face", face_name); | |
2630 | |
2631 check_lface (lface); | |
2632 return lface; | |
2633 } | |
2634 | |
2635 | |
2636 /* Get face attributes of face FACE_NAME from frame-local faces on | |
2637 frame F. Store the resulting attributes in ATTRS which must point | |
2638 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P | |
2639 is non-zero, signal an error if FACE_NAME does not name a face. | |
2640 Otherwise, value is zero if FACE_NAME is not a face. */ | |
2641 | |
2642 static INLINE int | |
2643 get_lface_attributes (f, face_name, attrs, signal_p) | |
2644 struct frame *f; | |
2645 Lisp_Object face_name; | |
2646 Lisp_Object *attrs; | |
2647 int signal_p; | |
2648 { | |
2649 Lisp_Object lface; | |
2650 int success_p; | |
2651 | |
2652 lface = lface_from_face_name (f, face_name, signal_p); | |
2653 if (!NILP (lface)) | |
2654 { | |
2655 bcopy (XVECTOR (lface)->contents, attrs, | |
2656 LFACE_VECTOR_SIZE * sizeof *attrs); | |
2657 success_p = 1; | |
2658 } | |
2659 else | |
2660 success_p = 0; | |
2661 | |
2662 return success_p; | |
2663 } | |
2664 | |
2665 | |
2666 /* Non-zero if all attributes in face attribute vector ATTRS are | |
2667 specified, i.e. are non-nil. */ | |
2668 | |
2669 static int | |
2670 lface_fully_specified_p (attrs) | |
2671 Lisp_Object *attrs; | |
2672 { | |
2673 int i; | |
2674 | |
2675 for (i = 1; i < LFACE_VECTOR_SIZE; ++i) | |
2676 if (UNSPECIFIEDP (attrs[i])) | |
2677 break; | |
2678 | |
2679 return i == LFACE_VECTOR_SIZE; | |
2680 } | |
2681 | |
2682 | |
2683 #ifdef HAVE_X_WINDOWS | |
2684 | |
2685 /* Set font-related attributes of Lisp face LFACE from XLFD font name | |
2686 FONT_NAME. If FORCE_P is zero, set only unspecified attributes of | |
2687 LFACE. Ignore fields of FONT_NAME containing wildcards. Value is | |
2688 zero if not successful because FONT_NAME was not in a valid format. | |
2689 A valid format is one that is suitable for split_font_name, see the | |
2690 comment there. */ | |
2691 | |
2692 static int | |
2693 set_lface_from_font_name (f, lface, font_name, force_p) | |
6784
d41c216ccd27
(frame_update_line_height): Check param_faces[i] not null.
Richard M. Stallman <rms@gnu.org>
parents:
6768
diff
changeset
|
2694 struct frame *f; |
24995 | 2695 Lisp_Object lface; |
2696 char *font_name; | |
2697 int force_p; | |
2698 { | |
2699 struct font_name font; | |
2700 char *buffer; | |
2701 int pt; | |
2702 int free_font_name_p = 0; | |
2703 | |
2704 /* If FONT_NAME contains wildcards, use the first matching font. */ | |
2705 if (index (font_name, '*') || index (font_name, '?')) | |
2706 { | |
2707 if (!first_font_matching (f, font_name, &font)) | |
2708 return 0; | |
2709 free_font_name_p = 1; | |
2710 } | |
2711 else | |
2712 { | |
2713 font.name = STRDUPA (font_name); | |
2714 if (!split_font_name (f, &font, 1)) | |
2715 { | |
2716 /* The font name may be something like `6x13'. Make | |
2717 sure we use the full name. */ | |
2718 struct font_info *font_info; | |
2719 | |
2720 BLOCK_INPUT; | |
2721 font_info = fs_load_font (f, FRAME_X_FONT_TABLE (f), | |
2722 CHARSET_ASCII, font_name, -1); | |
2723 UNBLOCK_INPUT; | |
2724 | |
2725 if (!font_info) | |
2726 return 0; | |
2727 | |
2728 font.name = STRDUPA (font_info->full_name); | |
2729 split_font_name (f, &font, 1); | |
2730 } | |
2731 | |
2732 /* FONT_NAME should not be a fontset name, here. */ | |
2733 xassert (xstricmp (font.fields[XLFD_REGISTRY], "fontset") != 0); | |
2734 } | |
2735 | |
2736 /* Set attributes only if unspecified, otherwise face defaults for | |
2737 new frames would never take effect. */ | |
2738 | |
2739 if (force_p || UNSPECIFIEDP (LFACE_FAMILY (lface))) | |
2740 { | |
2741 buffer = (char *) alloca (strlen (font.fields[XLFD_FAMILY]) | |
2742 + strlen (font.fields[XLFD_FOUNDRY]) | |
2743 + 2); | |
2744 sprintf (buffer, "%s-%s", font.fields[XLFD_FOUNDRY], | |
2745 font.fields[XLFD_FAMILY]); | |
2746 LFACE_FAMILY (lface) = build_string (buffer); | |
2747 } | |
2748 | |
2749 if (force_p || UNSPECIFIEDP (LFACE_HEIGHT (lface))) | |
2750 { | |
2751 pt = xlfd_point_size (f, &font); | |
2752 xassert (pt > 0); | |
2753 LFACE_HEIGHT (lface) = make_number (pt); | |
2754 } | |
2755 | |
2756 if (force_p || UNSPECIFIEDP (LFACE_SWIDTH (lface))) | |
2757 LFACE_SWIDTH (lface) = xlfd_symbolic_swidth (&font); | |
2758 | |
2759 if (force_p || UNSPECIFIEDP (LFACE_WEIGHT (lface))) | |
2760 LFACE_WEIGHT (lface) = xlfd_symbolic_weight (&font); | |
2761 | |
2762 if (force_p || UNSPECIFIEDP (LFACE_SLANT (lface))) | |
2763 LFACE_SLANT (lface) = xlfd_symbolic_slant (&font); | |
2764 | |
2765 if (free_font_name_p) | |
2766 xfree (font.name); | |
2767 | |
2768 return 1; | |
2769 } | |
2770 | |
2771 #endif /* HAVE_X_WINDOWS */ | |
2772 | |
2773 | |
2774 /* Merge two Lisp face attribute vectors FROM and TO and store the | |
2775 resulting attributes in TO. Every non-nil attribute of FROM | |
2776 overrides the corresponding attribute of TO. */ | |
2777 | |
2778 static INLINE void | |
2779 merge_face_vectors (from, to) | |
2780 Lisp_Object *from, *to; | |
2781 { | |
2782 int i; | |
2783 for (i = 1; i < LFACE_VECTOR_SIZE; ++i) | |
2784 if (!UNSPECIFIEDP (from[i])) | |
2785 to[i] = from[i]; | |
2786 } | |
2787 | |
2788 | |
2789 /* Given a Lisp face attribute vector TO and a Lisp object PROP that | |
2790 is a face property, determine the resulting face attributes on | |
2791 frame F, and store them in TO. PROP may be a single face | |
2792 specification or a list of such specifications. Each face | |
2793 specification can be | |
2794 | |
2795 1. A symbol or string naming a Lisp face. | |
2796 | |
2797 2. A property list of the form (KEYWORD VALUE ...) where each | |
2798 KEYWORD is a face attribute name, and value is an appropriate value | |
2799 for that attribute. | |
2800 | |
2801 3. Conses or the form (FOREGROUND-COLOR . COLOR) or | |
2802 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is | |
2803 for compatibility with 20.2. | |
2804 | |
2805 Face specifications earlier in lists take precedence over later | |
2806 specifications. */ | |
2807 | |
2808 static void | |
2809 merge_face_vector_with_property (f, to, prop) | |
2810 struct frame *f; | |
2811 Lisp_Object *to; | |
2812 Lisp_Object prop; | |
2813 { | |
2814 if (CONSP (prop)) | |
2815 { | |
2816 Lisp_Object first = XCAR (prop); | |
2817 | |
2818 if (EQ (first, Qforeground_color) | |
2819 || EQ (first, Qbackground_color)) | |
2820 { | |
2821 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR | |
2822 . COLOR). COLOR must be a string. */ | |
2823 Lisp_Object color_name = XCDR (prop); | |
2824 Lisp_Object color = first; | |
2825 | |
2826 if (STRINGP (color_name)) | |
2827 { | |
2828 if (EQ (color, Qforeground_color)) | |
2829 to[LFACE_FOREGROUND_INDEX] = color_name; | |
2830 else | |
2831 to[LFACE_BACKGROUND_INDEX] = color_name; | |
2832 } | |
2833 else | |
2834 display_message (f, "Invalid face color", color_name, Qnil); | |
2835 } | |
2836 else if (SYMBOLP (first) | |
2837 && *XSYMBOL (first)->name->data == ':') | |
2838 { | |
2839 /* Assume this is the property list form. */ | |
2840 while (CONSP (prop) && CONSP (XCDR (prop))) | |
2841 { | |
2842 Lisp_Object keyword = XCAR (prop); | |
2843 Lisp_Object value = XCAR (XCDR (prop)); | |
2844 | |
2845 if (EQ (keyword, QCfamily)) | |
2846 { | |
2847 if (STRINGP (value)) | |
2848 to[LFACE_FAMILY_INDEX] = value; | |
2849 else | |
2850 display_message (f, "Illegal face font family", | |
2851 value, Qnil); | |
2852 } | |
2853 else if (EQ (keyword, QCheight)) | |
2854 { | |
2855 if (INTEGERP (value)) | |
2856 to[LFACE_HEIGHT_INDEX] = value; | |
2857 else | |
2858 display_message (f, "Illegal face font height", | |
2859 value, Qnil); | |
2860 } | |
2861 else if (EQ (keyword, QCweight)) | |
2862 { | |
2863 if (SYMBOLP (value) | |
2864 && face_numeric_weight (value) >= 0) | |
2865 to[LFACE_WEIGHT_INDEX] = value; | |
2866 else | |
2867 display_message (f, "Illegal face weight", value, Qnil); | |
2868 } | |
2869 else if (EQ (keyword, QCslant)) | |
2870 { | |
2871 if (SYMBOLP (value) | |
2872 && face_numeric_slant (value) >= 0) | |
2873 to[LFACE_SLANT_INDEX] = value; | |
2874 else | |
2875 display_message (f, "Illegal face slant", value, Qnil); | |
2876 } | |
2877 else if (EQ (keyword, QCunderline)) | |
2878 { | |
2879 if (EQ (value, Qt) | |
2880 || NILP (value) | |
2881 || STRINGP (value)) | |
2882 to[LFACE_UNDERLINE_INDEX] = value; | |
2883 else | |
2884 display_message (f, "Illegal face underline", value, Qnil); | |
2885 } | |
2886 else if (EQ (keyword, QCoverline)) | |
2887 { | |
2888 if (EQ (value, Qt) | |
2889 || NILP (value) | |
2890 || STRINGP (value)) | |
2891 to[LFACE_OVERLINE_INDEX] = value; | |
2892 else | |
2893 display_message (f, "Illegal face overline", value, Qnil); | |
2894 } | |
2895 else if (EQ (keyword, QCstrike_through)) | |
2896 { | |
2897 if (EQ (value, Qt) | |
2898 || NILP (value) | |
2899 || STRINGP (value)) | |
2900 to[LFACE_STRIKE_THROUGH_INDEX] = value; | |
2901 else | |
2902 display_message (f, "Illegal face strike-through", | |
2903 value, Qnil); | |
2904 } | |
2905 else if (EQ (keyword, QCbox)) | |
2906 { | |
2907 if (EQ (value, Qt)) | |
2908 value = make_number (1); | |
2909 if (INTEGERP (value) | |
2910 || STRINGP (value) | |
2911 || CONSP (value) | |
2912 || NILP (value)) | |
2913 to[LFACE_BOX_INDEX] = value; | |
2914 else | |
2915 display_message (f, "Illegal face box", value, Qnil); | |
2916 } | |
2917 else if (EQ (keyword, QCinverse_video) | |
2918 || EQ (keyword, QCreverse_video)) | |
2919 { | |
2920 if (EQ (value, Qt) || NILP (value)) | |
2921 to[LFACE_INVERSE_INDEX] = value; | |
2922 else | |
2923 display_message (f, "Illegal face inverse-video", | |
2924 value, Qnil); | |
2925 } | |
2926 else if (EQ (keyword, QCforeground)) | |
2927 { | |
2928 if (STRINGP (value)) | |
2929 to[LFACE_FOREGROUND_INDEX] = value; | |
2930 else | |
2931 display_message (f, "Illegal face foreground", | |
2932 value, Qnil); | |
2933 } | |
2934 else if (EQ (keyword, QCbackground)) | |
2935 { | |
2936 if (STRINGP (value)) | |
2937 to[LFACE_BACKGROUND_INDEX] = value; | |
2938 else | |
2939 display_message (f, "Illegal face background", | |
2940 value, Qnil); | |
2941 } | |
2942 else if (EQ (keyword, QCstipple)) | |
2943 { | |
2944 #ifdef HAVE_X_WINDOWS | |
2945 Lisp_Object pixmap_p = Fpixmap_spec_p (value); | |
2946 if (!NILP (pixmap_p)) | |
2947 to[LFACE_STIPPLE_INDEX] = value; | |
2948 else | |
2949 display_message (f, "Illegal face stipple", value, Qnil); | |
2950 #endif | |
2951 } | |
2952 else if (EQ (keyword, QCwidth)) | |
2953 { | |
2954 if (SYMBOLP (value) | |
2955 && face_numeric_swidth (value) >= 0) | |
2956 to[LFACE_SWIDTH_INDEX] = value; | |
2957 else | |
2958 display_message (f, "Illegal face width", value, Qnil); | |
2959 } | |
2960 else | |
2961 display_message (f, "Invalid attribute %s in face property", | |
2962 keyword, Qnil); | |
2963 | |
2964 prop = XCDR (XCDR (prop)); | |
2965 } | |
2966 } | |
2967 else | |
2968 { | |
2969 /* This is a list of face specs. Specifications at the | |
2970 beginning of the list take precedence over later | |
2971 specifications, so we have to merge starting with the | |
2972 last specification. */ | |
2973 Lisp_Object next = XCDR (prop); | |
2974 if (!NILP (next)) | |
2975 merge_face_vector_with_property (f, to, next); | |
2976 merge_face_vector_with_property (f, to, first); | |
2977 } | |
2978 } | |
2979 else | |
2980 { | |
2981 /* PROP ought to be a face name. */ | |
2982 Lisp_Object lface = lface_from_face_name (f, prop, 0); | |
2983 if (NILP (lface)) | |
2984 display_message (f, "Invalid face text property value: %s", | |
2985 prop, Qnil); | |
2986 else | |
2987 merge_face_vectors (XVECTOR (lface)->contents, to); | |
2988 } | |
2989 } | |
2990 | |
2991 | |
2992 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face, | |
2993 Sinternal_make_lisp_face, 1, 2, 0, | |
2994 "Make FACE, a symbol, a Lisp face with all attributes nil.\n\ | |
2995 If FACE was not known as a face before, create a new one.\n\ | |
2996 If optional argument FRAME is specified, make a frame-local face\n\ | |
2997 for that frame. Otherwise operate on the global face definition.\n\ | |
2998 Value is a vector of face attributes.") | |
2999 (face, frame) | |
3000 Lisp_Object face, frame; | |
3001 { | |
3002 Lisp_Object global_lface, lface; | |
3003 struct frame *f; | |
3004 int i; | |
3005 | |
3006 CHECK_SYMBOL (face, 0); | |
3007 global_lface = lface_from_face_name (NULL, face, 0); | |
3008 | |
3009 if (!NILP (frame)) | |
3010 { | |
3011 CHECK_LIVE_FRAME (frame, 1); | |
3012 f = XFRAME (frame); | |
3013 lface = lface_from_face_name (f, face, 0); | |
3014 } | |
3015 else | |
3016 f = NULL, lface = Qnil; | |
3017 | |
3018 /* Add a global definition if there is none. */ | |
3019 if (NILP (global_lface)) | |
3020 { | |
3021 global_lface = Fmake_vector (make_number (LFACE_VECTOR_SIZE), | |
3022 Qunspecified); | |
3023 XVECTOR (global_lface)->contents[0] = Qface; | |
3024 Vface_new_frame_defaults = Fcons (Fcons (face, global_lface), | |
3025 Vface_new_frame_defaults); | |
3026 | |
3027 /* Assign the new Lisp face a unique ID. The mapping from Lisp | |
3028 face id to Lisp face is given by the vector lface_id_to_name. | |
3029 The mapping from Lisp face to Lisp face id is given by the | |
3030 property `face' of the Lisp face name. */ | |
3031 if (next_lface_id == lface_id_to_name_size) | |
3032 { | |
3033 int new_size = max (50, 2 * lface_id_to_name_size); | |
3034 int sz = new_size * sizeof *lface_id_to_name; | |
3035 lface_id_to_name = (Lisp_Object *) xrealloc (lface_id_to_name, sz); | |
3036 lface_id_to_name_size = new_size; | |
3037 } | |
3038 | |
3039 lface_id_to_name[next_lface_id] = face; | |
3040 Fput (face, Qface, make_number (next_lface_id)); | |
3041 ++next_lface_id; | |
3042 } | |
3043 else if (f == NULL) | |
3044 for (i = 1; i < LFACE_VECTOR_SIZE; ++i) | |
3045 XVECTOR (global_lface)->contents[i] = Qunspecified; | |
3046 | |
3047 /* Add a frame-local definition. */ | |
3048 if (f) | |
3049 { | |
3050 if (NILP (lface)) | |
3051 { | |
3052 lface = Fmake_vector (make_number (LFACE_VECTOR_SIZE), | |
3053 Qunspecified); | |
3054 XVECTOR (lface)->contents[0] = Qface; | |
3055 f->face_alist = Fcons (Fcons (face, lface), f->face_alist); | |
3056 } | |
3057 else | |
3058 for (i = 1; i < LFACE_VECTOR_SIZE; ++i) | |
3059 XVECTOR (lface)->contents[i] = Qunspecified; | |
3060 } | |
3061 else | |
3062 lface = global_lface; | |
3063 | |
3064 xassert (LFACEP (lface)); | |
3065 check_lface (lface); | |
3066 return lface; | |
3067 } | |
3068 | |
3069 | |
3070 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p, | |
3071 Sinternal_lisp_face_p, 1, 2, 0, | |
3072 "Return non-nil if FACE names a face.\n\ | |
3073 If optional second parameter FRAME is non-nil, check for the\n\ | |
3074 existence of a frame-local face with name FACE on that frame.\n\ | |
3075 Otherwise check for the existence of a global face.") | |
3076 (face, frame) | |
3077 Lisp_Object face, frame; | |
3078 { | |
3079 Lisp_Object lface; | |
3080 | |
3081 if (!NILP (frame)) | |
3082 { | |
3083 CHECK_LIVE_FRAME (frame, 1); | |
3084 lface = lface_from_face_name (XFRAME (frame), face, 0); | |
3085 } | |
3086 else | |
3087 lface = lface_from_face_name (NULL, face, 0); | |
3088 | |
3089 return lface; | |
3090 } | |
3091 | |
3092 | |
3093 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face, | |
3094 Sinternal_copy_lisp_face, 4, 4, 0, | |
3095 "Copy face FROM to TO.\n\ | |
3096 If FRAME it t, copy the global face definition of FROM to the\n\ | |
3097 global face definition of TO. Otherwise, copy the frame-local\n\ | |
3098 definition of FROM on FRAME to the frame-local definition of TO\n\ | |
3099 on NEW-FRAME, or FRAME if NEW-FRAME is nil.\n\ | |
3100 \n\ | |
3101 Value is TO.") | |
3102 (from, to, frame, new_frame) | |
3103 Lisp_Object from, to, frame, new_frame; | |
3104 { | |
3105 Lisp_Object lface, copy; | |
3106 | |
3107 CHECK_SYMBOL (from, 0); | |
3108 CHECK_SYMBOL (to, 1); | |
3109 if (NILP (new_frame)) | |
3110 new_frame = frame; | |
3111 | |
3112 if (EQ (frame, Qt)) | |
3113 { | |
3114 /* Copy global definition of FROM. We don't make copies of | |
3115 strings etc. because 20.2 didn't do it either. */ | |
3116 lface = lface_from_face_name (NULL, from, 1); | |
3117 copy = Finternal_make_lisp_face (to, Qnil); | |
3118 } | |
3119 else | |
3120 { | |
3121 /* Copy frame-local definition of FROM. */ | |
3122 CHECK_LIVE_FRAME (frame, 2); | |
3123 CHECK_LIVE_FRAME (new_frame, 3); | |
3124 lface = lface_from_face_name (XFRAME (frame), from, 1); | |
3125 copy = Finternal_make_lisp_face (to, new_frame); | |
3126 } | |
3127 | |
3128 bcopy (XVECTOR (lface)->contents, XVECTOR (copy)->contents, | |
3129 LFACE_VECTOR_SIZE * sizeof (Lisp_Object)); | |
3130 | |
3131 return to; | |
3132 } | |
3133 | |
3134 | |
3135 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute, | |
3136 Sinternal_set_lisp_face_attribute, 3, 4, 0, | |
3137 "Set attribute ATTR of FACE to VALUE.\n\ | |
3138 If optional argument FRAME is given, set the face attribute of face FACE\n\ | |
3139 on that frame. If FRAME is t, set the attribute of the default for face\n\ | |
3140 FACE (for new frames). If FRAME is omitted or nil, use the selected\n\ | |
3141 frame.") | |
3142 (face, attr, value, frame) | |
3143 Lisp_Object face, attr, value, frame; | |
6784
d41c216ccd27
(frame_update_line_height): Check param_faces[i] not null.
Richard M. Stallman <rms@gnu.org>
parents:
6768
diff
changeset
|
3144 { |
24995 | 3145 Lisp_Object lface; |
3146 Lisp_Object old_value = Qnil; | |
3147 int font_related_attr_p = 0; | |
3148 | |
3149 CHECK_SYMBOL (face, 0); | |
3150 CHECK_SYMBOL (attr, 1); | |
3151 | |
3152 /* Set lface to the Lisp attribute vector of FACE. */ | |
3153 if (EQ (frame, Qt)) | |
3154 lface = lface_from_face_name (NULL, face, 1); | |
3155 else | |
3156 { | |
3157 if (NILP (frame)) | |
3158 XSETFRAME (frame, selected_frame); | |
3159 | |
3160 CHECK_LIVE_FRAME (frame, 3); | |
3161 lface = lface_from_face_name (XFRAME (frame), face, 0); | |
3162 | |
3163 /* If a frame-local face doesn't exist yet, create one. */ | |
3164 if (NILP (lface)) | |
3165 lface = Finternal_make_lisp_face (face, frame); | |
3166 } | |
3167 | |
3168 if (EQ (attr, QCfamily)) | |
3169 { | |
3170 if (!UNSPECIFIEDP (value)) | |
3171 { | |
3172 CHECK_STRING (value, 3); | |
3173 if (XSTRING (value)->size == 0) | |
3174 signal_error ("Invalid face family", value); | |
3175 } | |
3176 old_value = LFACE_FAMILY (lface); | |
3177 LFACE_FAMILY (lface) = value; | |
3178 font_related_attr_p = 1; | |
3179 } | |
3180 else if (EQ (attr, QCheight)) | |
3181 { | |
3182 if (!UNSPECIFIEDP (value)) | |
3183 { | |
3184 CHECK_NUMBER (value, 3); | |
3185 if (XINT (value) <= 0) | |
3186 signal_error ("Invalid face height", value); | |
3187 } | |
3188 old_value = LFACE_HEIGHT (lface); | |
3189 LFACE_HEIGHT (lface) = value; | |
3190 font_related_attr_p = 1; | |
3191 } | |
3192 else if (EQ (attr, QCweight)) | |
3193 { | |
3194 if (!UNSPECIFIEDP (value)) | |
3195 { | |
3196 CHECK_SYMBOL (value, 3); | |
3197 if (face_numeric_weight (value) < 0) | |
3198 signal_error ("Invalid face weight", value); | |
3199 } | |
3200 old_value = LFACE_WEIGHT (lface); | |
3201 LFACE_WEIGHT (lface) = value; | |
3202 font_related_attr_p = 1; | |
3203 } | |
3204 else if (EQ (attr, QCslant)) | |
3205 { | |
3206 if (!UNSPECIFIEDP (value)) | |
3207 { | |
3208 CHECK_SYMBOL (value, 3); | |
3209 if (face_numeric_slant (value) < 0) | |
3210 signal_error ("Invalid face slant", value); | |
3211 } | |
3212 old_value = LFACE_SLANT (lface); | |
3213 LFACE_SLANT (lface) = value; | |
3214 font_related_attr_p = 1; | |
3215 } | |
3216 else if (EQ (attr, QCunderline)) | |
3217 { | |
3218 if (!UNSPECIFIEDP (value)) | |
3219 if ((SYMBOLP (value) | |
3220 && !EQ (value, Qt) | |
3221 && !EQ (value, Qnil)) | |
3222 /* Underline color. */ | |
3223 || (STRINGP (value) | |
3224 && XSTRING (value)->size == 0)) | |
3225 signal_error ("Invalid face underline", value); | |
3226 | |
3227 old_value = LFACE_UNDERLINE (lface); | |
3228 LFACE_UNDERLINE (lface) = value; | |
3229 } | |
3230 else if (EQ (attr, QCoverline)) | |
3231 { | |
3232 if (!UNSPECIFIEDP (value)) | |
3233 if ((SYMBOLP (value) | |
3234 && !EQ (value, Qt) | |
3235 && !EQ (value, Qnil)) | |
3236 /* Overline color. */ | |
3237 || (STRINGP (value) | |
3238 && XSTRING (value)->size == 0)) | |
3239 signal_error ("Invalid face overline", value); | |
3240 | |
3241 old_value = LFACE_OVERLINE (lface); | |
3242 LFACE_OVERLINE (lface) = value; | |
3243 } | |
3244 else if (EQ (attr, QCstrike_through)) | |
3245 { | |
3246 if (!UNSPECIFIEDP (value)) | |
3247 if ((SYMBOLP (value) | |
3248 && !EQ (value, Qt) | |
3249 && !EQ (value, Qnil)) | |
3250 /* Strike-through color. */ | |
3251 || (STRINGP (value) | |
3252 && XSTRING (value)->size == 0)) | |
3253 signal_error ("Invalid face strike-through", value); | |
3254 | |
3255 old_value = LFACE_STRIKE_THROUGH (lface); | |
3256 LFACE_STRIKE_THROUGH (lface) = value; | |
3257 } | |
3258 else if (EQ (attr, QCbox)) | |
3259 { | |
3260 int valid_p; | |
3261 | |
3262 /* Allow t meaning a simple box of width 1 in foreground color | |
3263 of the face. */ | |
3264 if (EQ (value, Qt)) | |
3265 value = make_number (1); | |
3266 | |
3267 if (UNSPECIFIEDP (value)) | |
3268 valid_p = 1; | |
3269 else if (NILP (value)) | |
3270 valid_p = 1; | |
3271 else if (INTEGERP (value)) | |
3272 valid_p = XINT (value) > 0; | |
3273 else if (STRINGP (value)) | |
3274 valid_p = XSTRING (value)->size > 0; | |
3275 else if (CONSP (value)) | |
3276 { | |
3277 Lisp_Object tem; | |
3278 | |
3279 tem = value; | |
3280 while (CONSP (tem)) | |
3281 { | |
3282 Lisp_Object k, v; | |
3283 | |
3284 k = XCAR (tem); | |
3285 tem = XCDR (tem); | |
3286 if (!CONSP (tem)) | |
3287 break; | |
3288 v = XCAR (tem); | |
3289 tem = XCDR (tem); | |
3290 | |
3291 if (EQ (k, QCline_width)) | |
3292 { | |
3293 if (!INTEGERP (v) || XINT (v) <= 0) | |
3294 break; | |
3295 } | |
3296 else if (EQ (k, QCcolor)) | |
3297 { | |
3298 if (!STRINGP (v) || XSTRING (v)->size == 0) | |
3299 break; | |
3300 } | |
3301 else if (EQ (k, QCstyle)) | |
3302 { | |
3303 if (!EQ (v, Qpressed_button) && !EQ (v, Qreleased_button)) | |
3304 break; | |
3305 } | |
3306 else | |
3307 break; | |
3308 } | |
3309 | |
3310 valid_p = NILP (tem); | |
3311 } | |
3312 else | |
3313 valid_p = 0; | |
3314 | |
3315 if (!valid_p) | |
3316 signal_error ("Invalid face box", value); | |
3317 | |
3318 old_value = LFACE_BOX (lface); | |
3319 LFACE_BOX (lface) = value; | |
3320 } | |
3321 else if (EQ (attr, QCinverse_video) | |
3322 || EQ (attr, QCreverse_video)) | |
3323 { | |
3324 if (!UNSPECIFIEDP (value)) | |
3325 { | |
3326 CHECK_SYMBOL (value, 3); | |
3327 if (!EQ (value, Qt) && !NILP (value)) | |
3328 signal_error ("Invalid inverse-video face attribute value", value); | |
3329 } | |
3330 old_value = LFACE_INVERSE (lface); | |
3331 LFACE_INVERSE (lface) = value; | |
3332 } | |
3333 else if (EQ (attr, QCforeground)) | |
3334 { | |
3335 if (!UNSPECIFIEDP (value)) | |
3336 { | |
3337 /* Don't check for valid color names here because it depends | |
3338 on the frame (display) whether the color will be valid | |
3339 when the face is realized. */ | |
3340 CHECK_STRING (value, 3); | |
3341 if (XSTRING (value)->size == 0) | |
3342 signal_error ("Empty foreground color value", value); | |
3343 } | |
3344 old_value = LFACE_FOREGROUND (lface); | |
3345 LFACE_FOREGROUND (lface) = value; | |
3346 } | |
3347 else if (EQ (attr, QCbackground)) | |
3348 { | |
3349 if (!UNSPECIFIEDP (value)) | |
3350 { | |
3351 /* Don't check for valid color names here because it depends | |
3352 on the frame (display) whether the color will be valid | |
3353 when the face is realized. */ | |
3354 CHECK_STRING (value, 3); | |
3355 if (XSTRING (value)->size == 0) | |
3356 signal_error ("Empty background color value", value); | |
3357 } | |
3358 old_value = LFACE_BACKGROUND (lface); | |
3359 LFACE_BACKGROUND (lface) = value; | |
3360 } | |
3361 else if (EQ (attr, QCstipple)) | |
3362 { | |
3363 #ifdef HAVE_X_WINDOWS | |
3364 if (!UNSPECIFIEDP (value) | |
3365 && !NILP (value) | |
3366 && NILP (Fpixmap_spec_p (value))) | |
3367 signal_error ("Invalid stipple attribute", value); | |
3368 old_value = LFACE_STIPPLE (lface); | |
3369 LFACE_STIPPLE (lface) = value; | |
3370 #endif /* HAVE_X_WINDOWS */ | |
3371 } | |
3372 else if (EQ (attr, QCwidth)) | |
3373 { | |
3374 if (!UNSPECIFIEDP (value)) | |
3375 { | |
3376 CHECK_SYMBOL (value, 3); | |
3377 if (face_numeric_swidth (value) < 0) | |
3378 signal_error ("Invalid face width", value); | |
3379 } | |
3380 old_value = LFACE_SWIDTH (lface); | |
3381 LFACE_SWIDTH (lface) = value; | |
3382 font_related_attr_p = 1; | |
3383 } | |
3384 else if (EQ (attr, QCfont)) | |
3385 { | |
3386 #ifdef HAVE_X_WINDOWS | |
3387 /* Set font-related attributes of the Lisp face from an | |
3388 XLFD font name. */ | |
3389 struct frame *f; | |
3390 | |
3391 CHECK_STRING (value, 3); | |
3392 if (EQ (frame, Qt)) | |
3393 f = selected_frame; | |
3394 else | |
3395 f = check_x_frame (frame); | |
3396 | |
3397 if (!set_lface_from_font_name (f, lface, XSTRING (value)->data, 1)) | |
3398 signal_error ("Invalid font name", value); | |
3399 | |
3400 font_related_attr_p = 1; | |
3401 #endif /* HAVE_X_WINDOWS */ | |
3402 } | |
3403 else if (EQ (attr, QCbold)) | |
3404 { | |
3405 old_value = LFACE_WEIGHT (lface); | |
3406 LFACE_WEIGHT (lface) = NILP (value) ? Qnormal : Qbold; | |
3407 font_related_attr_p = 1; | |
3408 } | |
3409 else if (EQ (attr, QCitalic)) | |
3410 { | |
3411 old_value = LFACE_SLANT (lface); | |
3412 LFACE_SLANT (lface) = NILP (value) ? Qnormal : Qitalic; | |
3413 font_related_attr_p = 1; | |
3414 } | |
3415 else | |
3416 signal_error ("Invalid face attribute name", attr); | |
3417 | |
3418 /* Changing a named face means that all realized faces depending on | |
3419 that face are invalid. Since we cannot tell which realized faces | |
3420 depend on the face, make sure they are all removed. This is done | |
3421 by incrementing face_change_count. The next call to | |
3422 init_iterator will then free realized faces. */ | |
3423 if (!EQ (frame, Qt) | |
3424 && (EQ (attr, QCfont) | |
3425 || NILP (Fequal (old_value, value)))) | |
3426 { | |
3427 ++face_change_count; | |
3428 ++windows_or_buffers_changed; | |
3429 } | |
3430 | |
3431 #ifdef HAVE_X_WINDOWS | |
3432 /* Changed font-related attributes of the `default' face are | |
3433 reflected in changed `font' frame parameters. */ | |
3434 if (EQ (face, Qdefault) | |
3435 && !EQ (frame, Qt) | |
3436 && font_related_attr_p | |
3437 && lface_fully_specified_p (XVECTOR (lface)->contents) | |
3438 && NILP (Fequal (old_value, value))) | |
3439 set_font_frame_param (frame, lface); | |
3440 | |
3441 #endif /* HAVE_X_WINDOWS */ | |
3442 | |
3443 return face; | |
3444 } | |
3445 | |
3446 | |
3447 #ifdef HAVE_X_WINDOWS | |
3448 | |
3449 /* Set the `font' frame parameter of FRAME according to `default' face | |
3450 attributes LFACE. */ | |
3451 | |
3452 static void | |
3453 set_font_frame_param (frame, lface) | |
3454 Lisp_Object frame, lface; | |
3455 { | |
3456 struct frame *f = XFRAME (frame); | |
3457 Lisp_Object frame_font; | |
3458 int fontset; | |
3459 char *font; | |
3460 | |
3461 /* Get FRAME's font parameter. */ | |
3462 frame_font = Fassq (Qfont, f->param_alist); | |
3463 xassert (CONSP (frame_font) && STRINGP (XCDR (frame_font))); | |
3464 frame_font = XCDR (frame_font); | |
3465 | |
3466 fontset = fs_query_fontset (f, XSTRING (frame_font)->data); | |
3467 if (fontset >= 0) | |
3468 { | |
3469 /* Frame parameter is a fontset name. Modify the fontset so | |
3470 that all its fonts reflect face attributes LFACE. */ | |
3471 int charset; | |
3472 struct fontset_info *fontset_info; | |
3473 | |
3474 fontset_info = FRAME_FONTSET_DATA (f)->fontset_table[fontset]; | |
3475 | |
3476 for (charset = 0; charset < MAX_CHARSET; ++charset) | |
3477 if (fontset_info->fontname[charset]) | |
3478 { | |
3479 font = choose_face_fontset_font (f, XVECTOR (lface)->contents, | |
3480 fontset, charset); | |
3481 Fset_fontset_font (frame_font, CHARSET_SYMBOL (charset), | |
3482 build_string (font), frame); | |
3483 xfree (font); | |
3484 } | |
3485 } | |
3486 else | |
3487 { | |
3488 /* Frame parameter is an X font name. I believe this can | |
3489 only happen in unibyte mode. */ | |
3490 font = choose_face_font (f, XVECTOR (lface)->contents, | |
3491 -1, Vface_default_registry); | |
3492 if (font) | |
3493 { | |
3494 store_frame_param (f, Qfont, build_string (font)); | |
3495 xfree (font); | |
3496 } | |
3497 } | |
3498 } | |
3499 | |
3500 | |
3501 /* Get the value of X resource RESOURCE, class CLASS for the display | |
3502 of frame FRAME. This is here because ordinary `x-get-resource' | |
3503 doesn't take a frame argument. */ | |
3504 | |
3505 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource, | |
3506 Sinternal_face_x_get_resource, 3, 3, 0, "") | |
3507 (resource, class, frame) | |
3508 Lisp_Object resource, class, frame; | |
3509 { | |
3510 Lisp_Object value; | |
3511 CHECK_STRING (resource, 0); | |
3512 CHECK_STRING (class, 1); | |
3513 CHECK_LIVE_FRAME (frame, 2); | |
3514 BLOCK_INPUT; | |
3515 value = display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame)), | |
3516 resource, class, Qnil, Qnil); | |
3517 UNBLOCK_INPUT; | |
3518 return value; | |
3519 } | |
3520 | |
3521 | |
3522 /* Return resource string VALUE as a boolean value, i.e. nil, or t. | |
3523 If VALUE is "on" or "true", return t. If VALUE is "off" or | |
3524 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an | |
3525 error; if SIGNAL_P is zero, return 0. */ | |
3526 | |
3527 static Lisp_Object | |
3528 face_boolean_x_resource_value (value, signal_p) | |
3529 Lisp_Object value; | |
3530 int signal_p; | |
3531 { | |
3532 Lisp_Object result = make_number (0); | |
3533 | |
3534 xassert (STRINGP (value)); | |
3535 | |
3536 if (xstricmp (XSTRING (value)->data, "on") == 0 | |
3537 || xstricmp (XSTRING (value)->data, "true") == 0) | |
3538 result = Qt; | |
3539 else if (xstricmp (XSTRING (value)->data, "off") == 0 | |
3540 || xstricmp (XSTRING (value)->data, "false") == 0) | |
3541 result = Qnil; | |
3542 else if (xstricmp (XSTRING (value)->data, "unspecified") == 0) | |
3543 result = Qunspecified; | |
3544 else if (signal_p) | |
3545 signal_error ("Invalid face attribute value from X resource", value); | |
3546 | |
3547 return result; | |
3548 } | |
3549 | |
3550 | |
3551 DEFUN ("internal-set-lisp-face-attribute-from-resource", | |
3552 Finternal_set_lisp_face_attribute_from_resource, | |
3553 Sinternal_set_lisp_face_attribute_from_resource, | |
3554 3, 4, 0, "") | |
3555 (face, attr, value, frame) | |
3556 Lisp_Object face, attr, value, frame; | |
3557 { | |
3558 CHECK_SYMBOL (face, 0); | |
3559 CHECK_SYMBOL (attr, 1); | |
3560 CHECK_STRING (value, 2); | |
3561 | |
3562 if (xstricmp (XSTRING (value)->data, "unspecified") == 0) | |
3563 value = Qunspecified; | |
3564 else if (EQ (attr, QCheight)) | |
3565 { | |
3566 value = Fstring_to_number (value, make_number (10)); | |
3567 if (XINT (value) <= 0) | |
3568 signal_error ("Invalid face height from X resource", value); | |
3569 } | |
3570 else if (EQ (attr, QCbold) || EQ (attr, QCitalic)) | |
3571 value = face_boolean_x_resource_value (value, 1); | |
3572 else if (EQ (attr, QCweight) || EQ (attr, QCslant) || EQ (attr, QCwidth)) | |
3573 value = intern (XSTRING (value)->data); | |
3574 else if (EQ (attr, QCreverse_video) || EQ (attr, QCinverse_video)) | |
3575 value = face_boolean_x_resource_value (value, 1); | |
3576 else if (EQ (attr, QCunderline) | |
3577 || EQ (attr, QCoverline) | |
3578 || EQ (attr, QCstrike_through) | |
3579 || EQ (attr, QCbox)) | |
3580 { | |
3581 Lisp_Object boolean_value; | |
3582 | |
3583 /* If the result of face_boolean_x_resource_value is t or nil, | |
3584 VALUE does NOT specify a color. */ | |
3585 boolean_value = face_boolean_x_resource_value (value, 0); | |
3586 if (SYMBOLP (boolean_value)) | |
3587 value = boolean_value; | |
3588 } | |
3589 | |
3590 return Finternal_set_lisp_face_attribute (face, attr, value, frame); | |
6784
d41c216ccd27
(frame_update_line_height): Check param_faces[i] not null.
Richard M. Stallman <rms@gnu.org>
parents:
6768
diff
changeset
|
3591 } |
8472
0d0b32e78a5b
(compute_glyph_face_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8119
diff
changeset
|
3592 |
24995 | 3593 |
3594 #endif /* HAVE_X_WINDOWS */ | |
3595 | |
3596 | |
3597 | |
3598 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute, | |
3599 Sinternal_get_lisp_face_attribute, | |
3600 2, 3, 0, | |
3601 "Return face attribute KEYWORD of face SYMBOL.\n\ | |
3602 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid\n\ | |
3603 face attribute name, signal an error.\n\ | |
3604 If the optional argument FRAME is given, report on face FACE in that\n\ | |
3605 frame. If FRAME is t, report on the defaults for face FACE (for new\n\ | |
3606 frames). If FRAME is omitted or nil, use the selected frame.") | |
3607 (symbol, keyword, frame) | |
3608 Lisp_Object symbol, keyword, frame; | |
3609 { | |
3610 Lisp_Object lface, value = Qnil; | |
3611 | |
3612 CHECK_SYMBOL (symbol, 0); | |
3613 CHECK_SYMBOL (keyword, 1); | |
3614 | |
3615 if (EQ (frame, Qt)) | |
3616 lface = lface_from_face_name (NULL, symbol, 1); | |
3617 else | |
3618 { | |
3619 if (NILP (frame)) | |
3620 XSETFRAME (frame, selected_frame); | |
3621 CHECK_LIVE_FRAME (frame, 2); | |
3622 lface = lface_from_face_name (XFRAME (frame), symbol, 1); | |
3623 } | |
3624 | |
3625 if (EQ (keyword, QCfamily)) | |
3626 value = LFACE_FAMILY (lface); | |
3627 else if (EQ (keyword, QCheight)) | |
3628 value = LFACE_HEIGHT (lface); | |
3629 else if (EQ (keyword, QCweight)) | |
3630 value = LFACE_WEIGHT (lface); | |
3631 else if (EQ (keyword, QCslant)) | |
3632 value = LFACE_SLANT (lface); | |
3633 else if (EQ (keyword, QCunderline)) | |
3634 value = LFACE_UNDERLINE (lface); | |
3635 else if (EQ (keyword, QCoverline)) | |
3636 value = LFACE_OVERLINE (lface); | |
3637 else if (EQ (keyword, QCstrike_through)) | |
3638 value = LFACE_STRIKE_THROUGH (lface); | |
3639 else if (EQ (keyword, QCbox)) | |
3640 value = LFACE_BOX (lface); | |
3641 else if (EQ (keyword, QCinverse_video) | |
3642 || EQ (keyword, QCreverse_video)) | |
3643 value = LFACE_INVERSE (lface); | |
3644 else if (EQ (keyword, QCforeground)) | |
3645 value = LFACE_FOREGROUND (lface); | |
3646 else if (EQ (keyword, QCbackground)) | |
3647 value = LFACE_BACKGROUND (lface); | |
3648 else if (EQ (keyword, QCstipple)) | |
3649 value = LFACE_STIPPLE (lface); | |
3650 else if (EQ (keyword, QCwidth)) | |
3651 value = LFACE_SWIDTH (lface); | |
3652 else | |
3653 signal_error ("Invalid face attribute name", keyword); | |
3654 | |
3655 return value; | |
3656 } | |
3657 | |
3658 | |
3659 DEFUN ("internal-lisp-face-attribute-values", | |
3660 Finternal_lisp_face_attribute_values, | |
3661 Sinternal_lisp_face_attribute_values, 1, 1, 0, | |
3662 "Return a list of valid discrete values for face attribute ATTR.\n\ | |
3663 Value is nil if ATTR doesn't have a discrete set of valid values.") | |
3664 (attr) | |
3665 Lisp_Object attr; | |
3666 { | |
3667 Lisp_Object result = Qnil; | |
3668 | |
3669 CHECK_SYMBOL (attr, 0); | |
3670 | |
3671 if (EQ (attr, QCweight) | |
3672 || EQ (attr, QCslant) | |
3673 || EQ (attr, QCwidth)) | |
3674 { | |
3675 /* Extract permissible symbols from tables. */ | |
3676 struct table_entry *table; | |
3677 int i, dim; | |
3678 | |
3679 if (EQ (attr, QCweight)) | |
3680 table = weight_table, dim = DIM (weight_table); | |
3681 else if (EQ (attr, QCslant)) | |
3682 table = slant_table, dim = DIM (slant_table); | |
3683 else | |
3684 table = swidth_table, dim = DIM (swidth_table); | |
3685 | |
3686 for (i = 0; i < dim; ++i) | |
3687 { | |
3688 Lisp_Object symbol = *table[i].symbol; | |
3689 Lisp_Object tail = result; | |
3690 | |
3691 while (!NILP (tail) | |
3692 && !EQ (XCAR (tail), symbol)) | |
3693 tail = XCDR (tail); | |
3694 | |
3695 if (NILP (tail)) | |
3696 result = Fcons (symbol, result); | |
3697 } | |
3698 } | |
3699 else if (EQ (attr, QCunderline)) | |
3700 result = Fcons (Qt, Fcons (Qnil, Qnil)); | |
3701 else if (EQ (attr, QCoverline)) | |
3702 result = Fcons (Qt, Fcons (Qnil, Qnil)); | |
3703 else if (EQ (attr, QCstrike_through)) | |
3704 result = Fcons (Qt, Fcons (Qnil, Qnil)); | |
3705 else if (EQ (attr, QCinverse_video) || EQ (attr, QCreverse_video)) | |
3706 result = Fcons (Qt, Fcons (Qnil, Qnil)); | |
3707 | |
3708 return result; | |
3709 } | |
3710 | |
3711 | |
3712 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face, | |
3713 Sinternal_merge_in_global_face, 2, 2, 0, | |
3714 "Add attributes from frame-default definition of FACE to FACE on FRAME.") | |
3715 (face, frame) | |
3716 Lisp_Object face, frame; | |
3717 { | |
3718 Lisp_Object global_lface, local_lface; | |
3719 CHECK_LIVE_FRAME (frame, 1); | |
3720 global_lface = lface_from_face_name (NULL, face, 1); | |
3721 local_lface = lface_from_face_name (XFRAME (frame), face, 0); | |
3722 if (NILP (local_lface)) | |
3723 local_lface = Finternal_make_lisp_face (face, frame); | |
3724 merge_face_vectors (XVECTOR (global_lface)->contents, | |
3725 XVECTOR (local_lface)->contents); | |
3726 return face; | |
3727 } | |
3728 | |
3729 | |
3730 /* The following function is implemented for compatibility with 20.2. | |
3731 The function is used in x-resolve-fonts when it is asked to | |
3732 return fonts with the same size as the font of a face. This is | |
3733 done in fontset.el. */ | |
3734 | |
3735 DEFUN ("face-font", Fface_font, Sface_font, 1, 2, 0, | |
3736 "Return the font name of face FACE, or nil if it is unspecified.\n\ | |
3737 If the optional argument FRAME is given, report on face FACE in that frame.\n\ | |
3738 If FRAME is t, report on the defaults for face FACE (for new frames).\n\ | |
3739 The font default for a face is either nil, or a list\n\ | |
3740 of the form (bold), (italic) or (bold italic).\n\ | |
3741 If FRAME is omitted or nil, use the selected frame.") | |
3742 (face, frame) | |
3743 Lisp_Object face, frame; | |
3744 { | |
3745 if (EQ (frame, Qt)) | |
3746 { | |
3747 Lisp_Object result = Qnil; | |
3748 Lisp_Object lface = lface_from_face_name (NULL, face, 1); | |
3749 | |
3750 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface)) | |
3751 && !EQ (LFACE_WEIGHT (lface), Qnormal)) | |
3752 result = Fcons (Qbold, result); | |
3753 | |
3754 if (!NILP (LFACE_SLANT (lface)) | |
3755 && !EQ (LFACE_SLANT (lface), Qnormal)) | |
3756 result = Fcons (Qitalic, result); | |
3757 | |
3758 return result; | |
3759 } | |
3760 else | |
3761 { | |
3762 struct frame *f = frame_or_selected_frame (frame, 1); | |
3763 int face_id = lookup_named_face (f, face, CHARSET_ASCII); | |
3764 struct face *face = FACE_FROM_ID (f, face_id); | |
3765 return build_string (face->font_name); | |
3766 } | |
3767 } | |
3768 | |
3769 | |
3770 /* Compare face vectors V1 and V2 for equality. Value is non-zero if | |
3771 all attributes are `equal'. Tries to be fast because this function | |
3772 is called quite often. */ | |
3773 | |
3774 static INLINE int | |
3775 lface_equal_p (v1, v2) | |
3776 Lisp_Object *v1, *v2; | |
3777 { | |
3778 int i, equal_p = 1; | |
3779 | |
3780 for (i = 1; i < LFACE_VECTOR_SIZE && equal_p; ++i) | |
3781 { | |
3782 Lisp_Object a = v1[i]; | |
3783 Lisp_Object b = v2[i]; | |
3784 | |
3785 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil, | |
3786 and the other is specified. */ | |
3787 equal_p = XTYPE (a) == XTYPE (b); | |
3788 if (!equal_p) | |
3789 break; | |
3790 | |
3791 if (!EQ (a, b)) | |
3792 { | |
3793 switch (XTYPE (a)) | |
3794 { | |
3795 case Lisp_String: | |
3796 equal_p = (XSTRING (a)->size == XSTRING (b)->size | |
3797 && bcmp (XSTRING (a)->data, XSTRING (b)->data, | |
3798 XSTRING (a)->size) == 0); | |
3799 break; | |
3800 | |
3801 case Lisp_Int: | |
3802 case Lisp_Symbol: | |
3803 equal_p = 0; | |
3804 break; | |
3805 | |
3806 default: | |
3807 equal_p = !NILP (Fequal (a, b)); | |
3808 break; | |
3809 } | |
3810 } | |
3811 } | |
3812 | |
3813 return equal_p; | |
3814 } | |
3815 | |
3816 | |
3817 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p, | |
3818 Sinternal_lisp_face_equal_p, 2, 3, 0, | |
3819 "True if FACE1 and FACE2 are equal.\n\ | |
3820 If the optional argument FRAME is given, report on face FACE in that frame.\n\ | |
3821 If FRAME is t, report on the defaults for face FACE (for new frames).\n\ | |
3822 If FRAME is omitted or nil, use the selected frame.") | |
3823 (face1, face2, frame) | |
3824 Lisp_Object face1, face2, frame; | |
3825 { | |
3826 int equal_p; | |
3827 struct frame *f; | |
3828 Lisp_Object lface1, lface2; | |
3829 | |
3830 if (EQ (frame, Qt)) | |
3831 f = NULL; | |
3832 else | |
3833 /* Don't use check_x_frame here because this function is called | |
3834 before X frames exist. At that time, if FRAME is nil, | |
3835 selected_frame will be used which is the frame dumped with | |
3836 Emacs. That frame is not an X frame. */ | |
3837 f = frame_or_selected_frame (frame, 2); | |
3838 | |
3839 lface1 = lface_from_face_name (NULL, face1, 1); | |
3840 lface2 = lface_from_face_name (NULL, face2, 1); | |
3841 equal_p = lface_equal_p (XVECTOR (lface1)->contents, | |
3842 XVECTOR (lface2)->contents); | |
3843 return equal_p ? Qt : Qnil; | |
3844 } | |
3845 | |
3846 | |
3847 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p, | |
3848 Sinternal_lisp_face_empty_p, 1, 2, 0, | |
3849 "True if FACE has no attribute specified.\n\ | |
3850 If the optional argument FRAME is given, report on face FACE in that frame.\n\ | |
3851 If FRAME is t, report on the defaults for face FACE (for new frames).\n\ | |
3852 If FRAME is omitted or nil, use the selected frame.") | |
3853 (face, frame) | |
3854 Lisp_Object face, frame; | |
3855 { | |
3856 struct frame *f; | |
3857 Lisp_Object lface; | |
3858 int i; | |
3859 | |
3860 if (NILP (frame)) | |
3861 f = selected_frame; | |
3862 else | |
3863 { | |
3864 CHECK_LIVE_FRAME (frame, 0); | |
3865 f = XFRAME (frame); | |
3866 } | |
3867 | |
3868 if (EQ (frame, Qt)) | |
3869 lface = lface_from_face_name (NULL, face, 1); | |
3870 else | |
3871 lface = lface_from_face_name (f, face, 1); | |
3872 | |
3873 for (i = 1; i < LFACE_VECTOR_SIZE; ++i) | |
3874 if (!UNSPECIFIEDP (XVECTOR (lface)->contents[i])) | |
3875 break; | |
3876 | |
3877 return i == LFACE_VECTOR_SIZE ? Qt : Qnil; | |
3878 } | |
3879 | |
3880 | |
3881 DEFUN ("frame-face-alist", Fframe_face_alist, Sframe_face_alist, | |
3882 0, 1, 0, | |
3883 "Return an alist of frame-local faces defined on FRAME.\n\ | |
3884 For internal use only.") | |
3885 (frame) | |
3886 Lisp_Object frame; | |
3887 { | |
3888 struct frame *f = frame_or_selected_frame (frame, 0); | |
3889 return f->face_alist; | |
3890 } | |
3891 | |
3892 | |
3893 /* Return a hash code for Lisp string STRING with case ignored. Used | |
3894 below in computing a hash value for a Lisp face. */ | |
3895 | |
3896 static INLINE unsigned | |
3897 hash_string_case_insensitive (string) | |
3898 Lisp_Object string; | |
3899 { | |
3900 unsigned char *s; | |
3901 unsigned hash = 0; | |
3902 xassert (STRINGP (string)); | |
3903 for (s = XSTRING (string)->data; *s; ++s) | |
3904 hash = (hash << 1) ^ tolower (*s); | |
3905 return hash; | |
3906 } | |
3907 | |
3908 | |
3909 /* Return a hash code for face attribute vector V. */ | |
3910 | |
3911 static INLINE unsigned | |
3912 lface_hash (v) | |
3913 Lisp_Object *v; | |
3914 { | |
3915 return (hash_string_case_insensitive (v[LFACE_FAMILY_INDEX]) | |
3916 ^ hash_string_case_insensitive (v[LFACE_FOREGROUND_INDEX]) | |
3917 ^ hash_string_case_insensitive (v[LFACE_BACKGROUND_INDEX]) | |
3918 ^ (unsigned) v[LFACE_WEIGHT_INDEX] | |
3919 ^ (unsigned) v[LFACE_SLANT_INDEX] | |
3920 ^ (unsigned) v[LFACE_SWIDTH_INDEX] | |
3921 ^ XFASTINT (v[LFACE_HEIGHT_INDEX])); | |
3922 } | |
3923 | |
3924 | |
3925 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without | |
3926 considering charsets/registries). They do if they specify the same | |
3927 family, point size, weight, width and slant. Both LFACE1 and | |
3928 LFACE2 must be fully-specified. */ | |
3929 | |
3930 static INLINE int | |
3931 lface_same_font_attributes_p (lface1, lface2) | |
3932 Lisp_Object *lface1, *lface2; | |
3933 { | |
3934 xassert (lface_fully_specified_p (lface1) | |
3935 && lface_fully_specified_p (lface2)); | |
3936 return (xstricmp (XSTRING (lface1[LFACE_FAMILY_INDEX])->data, | |
3937 XSTRING (lface2[LFACE_FAMILY_INDEX])->data) == 0 | |
3938 && (XFASTINT (lface1[LFACE_HEIGHT_INDEX]) | |
3939 == XFASTINT (lface2[LFACE_HEIGHT_INDEX])) | |
3940 && EQ (lface1[LFACE_SWIDTH_INDEX], lface2[LFACE_SWIDTH_INDEX]) | |
3941 && EQ (lface1[LFACE_WEIGHT_INDEX], lface2[LFACE_WEIGHT_INDEX]) | |
3942 && EQ (lface1[LFACE_SLANT_INDEX], lface2[LFACE_SLANT_INDEX])); | |
3943 } | |
3944 | |
3945 | |
3946 | |
3947 /*********************************************************************** | |
3948 Realized Faces | |
3949 ***********************************************************************/ | |
3950 | |
3951 /* Allocate and return a new realized face for Lisp face attribute | |
3952 vector ATTR, charset CHARSET, and registry REGISTRY. */ | |
3953 | |
3954 static struct face * | |
3955 make_realized_face (attr, charset, registry) | |
3956 Lisp_Object *attr; | |
3957 int charset; | |
3958 Lisp_Object registry; | |
3959 { | |
3960 struct face *face = (struct face *) xmalloc (sizeof *face); | |
3961 bzero (face, sizeof *face); | |
3962 face->charset = charset; | |
3963 face->registry = registry; | |
3964 bcopy (attr, face->lface, sizeof face->lface); | |
3965 return face; | |
3966 } | |
3967 | |
3968 | |
3969 /* Free realized face FACE, including its X resources. FACE may | |
3970 be null. */ | |
3971 | |
3972 static void | |
3973 free_realized_face (f, face) | |
3974 struct frame *f; | |
3975 struct face *face; | |
3976 { | |
3977 if (face) | |
3978 { | |
3979 #ifdef HAVE_X_WINDOWS | |
3980 if (FRAME_X_P (f)) | |
3981 { | |
3982 if (face->gc) | |
3983 { | |
3984 x_free_gc (f, face->gc); | |
3985 face->gc = 0; | |
3986 } | |
3987 | |
3988 free_face_colors (f, face); | |
3989 x_destroy_bitmap (f, face->stipple); | |
3990 } | |
3991 #endif /* HAVE_X_WINDOWS */ | |
3992 | |
3993 xfree (face); | |
3994 } | |
3995 } | |
3996 | |
3997 | |
3998 /* Prepare face FACE for subsequent display on frame F. This | |
3999 allocated GCs if they haven't been allocated yet or have been freed | |
4000 by clearing the face cache. */ | |
4001 | |
4002 void | |
4003 prepare_face_for_display (f, face) | |
4004 struct frame *f; | |
4005 struct face *face; | |
4006 { | |
4007 #ifdef HAVE_X_WINDOWS | |
4008 xassert (FRAME_X_P (f)); | |
4009 | |
4010 if (face->gc == 0) | |
4011 { | |
4012 XGCValues xgcv; | |
4013 unsigned long mask = GCForeground | GCBackground | GCGraphicsExposures; | |
4014 | |
4015 xgcv.foreground = face->foreground; | |
4016 xgcv.background = face->background; | |
4017 xgcv.graphics_exposures = False; | |
4018 | |
4019 /* The font of FACE may be null if we couldn't load it. */ | |
4020 if (face->font) | |
4021 { | |
4022 xgcv.font = face->font->fid; | |
4023 mask |= GCFont; | |
4024 } | |
4025 | |
4026 BLOCK_INPUT; | |
4027 if (face->stipple) | |
4028 { | |
25092
79a5a567bdb0
(prepare_face_for_display): Use FillOpaqueStippled instead of
Gerd Moellmann <gerd@gnu.org>
parents:
25062
diff
changeset
|
4029 xgcv.fill_style = FillOpaqueStippled; |
24995 | 4030 xgcv.stipple = x_bitmap_pixmap (f, face->stipple); |
4031 mask |= GCFillStyle | GCStipple; | |
4032 } | |
4033 | |
4034 face->gc = x_create_gc (f, mask, &xgcv); | |
4035 UNBLOCK_INPUT; | |
4036 } | |
4037 #endif | |
4038 } | |
4039 | |
4040 | |
4041 /* Non-zero if FACE is suitable for displaying ISO8859-1. Used in | |
4042 macro FACE_SUITABLE_FOR_CHARSET_P to avoid realizing a new face for | |
4043 ISO8859-1 if the ASCII face suffices. */ | |
8472
0d0b32e78a5b
(compute_glyph_face_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8119
diff
changeset
|
4044 |
0d0b32e78a5b
(compute_glyph_face_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8119
diff
changeset
|
4045 int |
24995 | 4046 face_suitable_for_iso8859_1_p (face) |
4047 struct face *face; | |
4048 { | |
4049 int len = strlen (face->font_name); | |
4050 return len >= 9 && xstricmp (face->font_name + len - 9, "iso8859-1") == 0; | |
4051 } | |
4052 | |
4053 | |
4054 /* Value is non-zero if FACE is suitable for displaying characters | |
4055 of CHARSET. CHARSET < 0 means unibyte text. */ | |
4056 | |
4057 INLINE int | |
4058 face_suitable_for_charset_p (face, charset) | |
4059 struct face *face; | |
4060 int charset; | |
4061 { | |
4062 int suitable_p = 0; | |
4063 | |
4064 if (charset < 0) | |
4065 { | |
4066 if (EQ (face->registry, Vface_default_registry) | |
4067 || !NILP (Fequal (face->registry, Vface_default_registry))) | |
4068 suitable_p = 1; | |
4069 } | |
4070 else if (face->charset == charset) | |
4071 suitable_p = 1; | |
4072 else if (face->charset == CHARSET_ASCII | |
4073 && charset == charset_latin_iso8859_1) | |
4074 suitable_p = face_suitable_for_iso8859_1_p (face); | |
4075 else if (face->charset == charset_latin_iso8859_1 | |
4076 && charset == CHARSET_ASCII) | |
4077 suitable_p = 1; | |
4078 | |
4079 return suitable_p; | |
4080 } | |
4081 | |
4082 | |
4083 | |
4084 /*********************************************************************** | |
4085 Face Cache | |
4086 ***********************************************************************/ | |
4087 | |
4088 /* Return a new face cache for frame F. */ | |
4089 | |
4090 static struct face_cache * | |
4091 make_face_cache (f) | |
8472
0d0b32e78a5b
(compute_glyph_face_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8119
diff
changeset
|
4092 struct frame *f; |
24995 | 4093 { |
4094 struct face_cache *c; | |
4095 int size; | |
4096 | |
4097 c = (struct face_cache *) xmalloc (sizeof *c); | |
4098 bzero (c, sizeof *c); | |
4099 size = FACE_CACHE_BUCKETS_SIZE * sizeof *c->buckets; | |
4100 c->buckets = (struct face **) xmalloc (size); | |
4101 bzero (c->buckets, size); | |
4102 c->size = 50; | |
4103 c->faces_by_id = (struct face **) xmalloc (c->size * sizeof *c->faces_by_id); | |
4104 c->f = f; | |
4105 return c; | |
4106 } | |
4107 | |
4108 | |
4109 /* Clear out all graphics contexts for all realized faces, except for | |
4110 the basic faces. This should be done from time to time just to avoid | |
4111 keeping too many graphics contexts that are no longer needed. */ | |
4112 | |
4113 static void | |
4114 clear_face_gcs (c) | |
4115 struct face_cache *c; | |
4116 { | |
4117 if (c && FRAME_X_P (c->f)) | |
4118 { | |
4119 #ifdef HAVE_X_WINDOWS | |
4120 int i; | |
4121 for (i = BASIC_FACE_ID_SENTINEL; i < c->used; ++i) | |
4122 { | |
4123 struct face *face = c->faces_by_id[i]; | |
4124 if (face && face->gc) | |
4125 { | |
4126 x_free_gc (c->f, face->gc); | |
4127 face->gc = 0; | |
4128 } | |
4129 } | |
4130 #endif /* HAVE_X_WINDOWS */ | |
4131 } | |
4132 } | |
4133 | |
4134 | |
4135 /* Free all realized faces in face cache C, including basic faces. C | |
4136 may be null. If faces are freed, make sure the frame's current | |
4137 matrix is marked invalid, so that a display caused by an expose | |
4138 event doesn't try to use faces we destroyed. */ | |
4139 | |
4140 static void | |
4141 free_realized_faces (c) | |
4142 struct face_cache *c; | |
8472
0d0b32e78a5b
(compute_glyph_face_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8119
diff
changeset
|
4143 { |
24995 | 4144 if (c && c->used) |
4145 { | |
4146 int i, size; | |
4147 struct frame *f = c->f; | |
4148 | |
4149 for (i = 0; i < c->used; ++i) | |
4150 { | |
4151 free_realized_face (f, c->faces_by_id[i]); | |
4152 c->faces_by_id[i] = NULL; | |
4153 } | |
4154 | |
4155 c->used = 0; | |
4156 size = FACE_CACHE_BUCKETS_SIZE * sizeof *c->buckets; | |
4157 bzero (c->buckets, size); | |
4158 | |
4159 /* Must do a thorough redisplay the next time. Mark current | |
4160 matrices as invalid because they will reference faces freed | |
4161 above. This function is also called when a frame is | |
4162 destroyed. In this case, the root window of F is nil. */ | |
4163 if (WINDOWP (f->root_window)) | |
4164 { | |
4165 clear_current_matrices (f); | |
4166 ++windows_or_buffers_changed; | |
4167 } | |
4168 } | |
4169 } | |
4170 | |
4171 | |
4172 /* Free all realized faces on FRAME or on all frames if FRAME is nil. | |
4173 This is done after attributes of a named face have been changed, | |
4174 because we can't tell which realized faces depend on that face. */ | |
4175 | |
4176 void | |
4177 free_all_realized_faces (frame) | |
4178 Lisp_Object frame; | |
4179 { | |
4180 if (NILP (frame)) | |
8472
0d0b32e78a5b
(compute_glyph_face_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8119
diff
changeset
|
4181 { |
24995 | 4182 Lisp_Object rest; |
4183 FOR_EACH_FRAME (rest, frame) | |
4184 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame))); | |
4185 } | |
4186 else | |
4187 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame))); | |
4188 } | |
4189 | |
4190 | |
4191 /* Free face cache C and faces in it, including their X resources. */ | |
4192 | |
4193 static void | |
4194 free_face_cache (c) | |
4195 struct face_cache *c; | |
4196 { | |
4197 if (c) | |
4198 { | |
4199 free_realized_faces (c); | |
4200 xfree (c->buckets); | |
4201 xfree (c->faces_by_id); | |
4202 xfree (c); | |
4203 } | |
4204 } | |
4205 | |
4206 | |
4207 /* Cache realized face FACE in face cache C. HASH is the hash value | |
4208 of FACE. If FACE->fontset >= 0, add the new face to the end of the | |
4209 collision list of the face hash table of C. This is done because | |
4210 otherwise lookup_face would find FACE for every charset, even if | |
4211 faces with the same attributes but for specific charsets exist. */ | |
4212 | |
4213 static void | |
4214 cache_face (c, face, hash) | |
4215 struct face_cache *c; | |
4216 struct face *face; | |
4217 unsigned hash; | |
4218 { | |
4219 int i = hash % FACE_CACHE_BUCKETS_SIZE; | |
4220 | |
4221 face->hash = hash; | |
4222 | |
4223 if (face->fontset >= 0) | |
4224 { | |
4225 struct face *last = c->buckets[i]; | |
4226 if (last) | |
4227 { | |
4228 while (last->next) | |
4229 last = last->next; | |
4230 last->next = face; | |
4231 face->prev = last; | |
4232 face->next = NULL; | |
4233 } | |
4234 else | |
4235 { | |
4236 c->buckets[i] = face; | |
4237 face->prev = face->next = NULL; | |
4238 } | |
4239 } | |
4240 else | |
4241 { | |
4242 face->prev = NULL; | |
4243 face->next = c->buckets[i]; | |
4244 if (face->next) | |
4245 face->next->prev = face; | |
4246 c->buckets[i] = face; | |
8472
0d0b32e78a5b
(compute_glyph_face_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8119
diff
changeset
|
4247 } |
0d0b32e78a5b
(compute_glyph_face_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8119
diff
changeset
|
4248 |
24995 | 4249 /* Find a free slot in C->faces_by_id and use the index of the free |
4250 slot as FACE->id. */ | |
4251 for (i = 0; i < c->used; ++i) | |
4252 if (c->faces_by_id[i] == NULL) | |
4253 break; | |
4254 face->id = i; | |
4255 | |
4256 /* Maybe enlarge C->faces_by_id. */ | |
4257 if (i == c->used && c->used == c->size) | |
4258 { | |
4259 int new_size = 2 * c->size; | |
4260 int sz = new_size * sizeof *c->faces_by_id; | |
4261 c->faces_by_id = (struct face **) xrealloc (c->faces_by_id, sz); | |
4262 c->size = new_size; | |
4263 } | |
4264 | |
4265 #if GLYPH_DEBUG | |
4266 /* Check that FACE got a unique id. */ | |
4267 { | |
4268 int j, n; | |
4269 struct face *face; | |
4270 | |
4271 for (j = n = 0; j < FACE_CACHE_BUCKETS_SIZE; ++j) | |
4272 for (face = c->buckets[j]; face; face = face->next) | |
4273 if (face->id == i) | |
4274 ++n; | |
4275 | |
4276 xassert (n == 1); | |
4277 } | |
4278 #endif /* GLYPH_DEBUG */ | |
4279 | |
4280 c->faces_by_id[i] = face; | |
4281 if (i == c->used) | |
4282 ++c->used; | |
4283 } | |
4284 | |
4285 | |
4286 /* Remove face FACE from cache C. */ | |
4287 | |
4288 static void | |
4289 uncache_face (c, face) | |
4290 struct face_cache *c; | |
4291 struct face *face; | |
4292 { | |
4293 int i = face->hash % FACE_CACHE_BUCKETS_SIZE; | |
4294 | |
4295 if (face->prev) | |
4296 face->prev->next = face->next; | |
4297 else | |
4298 c->buckets[i] = face->next; | |
4299 | |
4300 if (face->next) | |
4301 face->next->prev = face->prev; | |
4302 | |
4303 c->faces_by_id[face->id] = NULL; | |
4304 if (face->id == c->used) | |
4305 --c->used; | |
4306 } | |
4307 | |
4308 | |
4309 /* Look up a realized face with face attributes ATTR in the face cache | |
4310 of frame F. The face will be used to display characters of | |
4311 CHARSET. CHARSET < 0 means the face will be used to display | |
4312 unibyte text. The value of face-default-registry is used to choose | |
4313 a font for the face in that case. Value is the ID of the face | |
4314 found. If no suitable face is found, realize a new one. */ | |
4315 | |
4316 INLINE int | |
4317 lookup_face (f, attr, charset) | |
4318 struct frame *f; | |
4319 Lisp_Object *attr; | |
4320 int charset; | |
4321 { | |
4322 struct face_cache *c = FRAME_FACE_CACHE (f); | |
4323 unsigned hash; | |
4324 int i; | |
4325 struct face *face; | |
4326 | |
4327 xassert (c != NULL); | |
4328 check_lface_attrs (attr); | |
4329 | |
4330 /* Look up ATTR in the face cache. */ | |
4331 hash = lface_hash (attr); | |
4332 i = hash % FACE_CACHE_BUCKETS_SIZE; | |
4333 | |
4334 for (face = c->buckets[i]; face; face = face->next) | |
4335 if (face->hash == hash | |
25114
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4336 && (!FRAME_WINDOW_P (f) |
24995 | 4337 || FACE_SUITABLE_FOR_CHARSET_P (face, charset)) |
4338 && lface_equal_p (face->lface, attr)) | |
4339 break; | |
4340 | |
4341 /* If not found, realize a new face. */ | |
4342 if (face == NULL) | |
4343 { | |
4344 face = realize_face (c, attr, charset); | |
4345 cache_face (c, face, hash); | |
4346 } | |
4347 | |
4348 #if GLYPH_DEBUG | |
4349 xassert (face == FACE_FROM_ID (f, face->id)); | |
4350 if (FRAME_X_P (f)) | |
4351 xassert (charset < 0 || FACE_SUITABLE_FOR_CHARSET_P (face, charset)); | |
4352 #endif /* GLYPH_DEBUG */ | |
4353 | |
4354 return face->id; | |
8472
0d0b32e78a5b
(compute_glyph_face_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8119
diff
changeset
|
4355 } |
24995 | 4356 |
4357 | |
4358 /* Return the face id of the realized face for named face SYMBOL on | |
4359 frame F suitable for displaying characters from CHARSET. CHARSET < | |
4360 0 means unibyte text. */ | |
4361 | |
4362 int | |
4363 lookup_named_face (f, symbol, charset) | |
4364 struct frame *f; | |
4365 Lisp_Object symbol; | |
4366 int charset; | |
4367 { | |
4368 Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
4369 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE]; | |
4370 struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); | |
4371 | |
4372 get_lface_attributes (f, symbol, symbol_attrs, 1); | |
4373 bcopy (default_face->lface, attrs, sizeof attrs); | |
4374 merge_face_vectors (symbol_attrs, attrs); | |
4375 return lookup_face (f, attrs, charset); | |
4376 } | |
4377 | |
4378 | |
4379 /* Return the ID of the realized ASCII face of Lisp face with ID | |
4380 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */ | |
4381 | |
4382 int | |
4383 ascii_face_of_lisp_face (f, lface_id) | |
4384 struct frame *f; | |
4385 int lface_id; | |
4386 { | |
4387 int face_id; | |
4388 | |
4389 if (lface_id >= 0 && lface_id < lface_id_to_name_size) | |
4390 { | |
4391 Lisp_Object face_name = lface_id_to_name[lface_id]; | |
4392 face_id = lookup_named_face (f, face_name, CHARSET_ASCII); | |
4393 } | |
4394 else | |
4395 face_id = -1; | |
4396 | |
4397 return face_id; | |
4398 } | |
4399 | |
4400 | |
4401 /* Return a face for charset ASCII that is like the face with id | |
4402 FACE_ID on frame F, but has a font that is STEPS steps smaller. | |
4403 STEPS < 0 means larger. Value is the id of the face. */ | |
4404 | |
4405 int | |
4406 smaller_face (f, face_id, steps) | |
4407 struct frame *f; | |
4408 int face_id, steps; | |
4409 { | |
4410 #ifdef HAVE_X_WINDOWS | |
4411 struct face *face; | |
4412 Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
4413 int pt, last_pt, last_height; | |
4414 int delta; | |
4415 int new_face_id; | |
4416 struct face *new_face; | |
4417 | |
4418 /* If not called for an X frame, just return the original face. */ | |
4419 if (FRAME_TERMCAP_P (f)) | |
4420 return face_id; | |
4421 | |
4422 /* Try in increments of 1/2 pt. */ | |
4423 delta = steps < 0 ? 5 : -5; | |
4424 steps = abs (steps); | |
4425 | |
4426 face = FACE_FROM_ID (f, face_id); | |
4427 bcopy (face->lface, attrs, sizeof attrs); | |
4428 pt = last_pt = XFASTINT (attrs[LFACE_HEIGHT_INDEX]); | |
4429 new_face_id = face_id; | |
4430 last_height = FONT_HEIGHT (face->font); | |
4431 | |
4432 while (steps | |
4433 && pt + delta > 0 | |
4434 /* Give up if we cannot find a font within 10pt. */ | |
4435 && abs (last_pt - pt) < 100) | |
4436 { | |
4437 /* Look up a face for a slightly smaller/larger font. */ | |
4438 pt += delta; | |
4439 attrs[LFACE_HEIGHT_INDEX] = make_number (pt); | |
4440 new_face_id = lookup_face (f, attrs, CHARSET_ASCII); | |
4441 new_face = FACE_FROM_ID (f, new_face_id); | |
4442 | |
4443 /* If height changes, count that as one step. */ | |
4444 if (FONT_HEIGHT (new_face->font) != last_height) | |
4445 { | |
4446 --steps; | |
4447 last_height = FONT_HEIGHT (new_face->font); | |
4448 last_pt = pt; | |
4449 } | |
4450 } | |
4451 | |
4452 return new_face_id; | |
4453 | |
4454 #else /* not HAVE_X_WINDOWS */ | |
4455 | |
4456 return face_id; | |
4457 | |
4458 #endif /* not HAVE_X_WINDOWS */ | |
4459 } | |
4460 | |
4461 | |
4462 /* Return a face for charset ASCII that is like the face with id | |
4463 FACE_ID on frame F, but has height HEIGHT. */ | |
2795
e97e96fb0cb8
(compute_char_face): New args REGION_BEG, REGION_END.
Richard M. Stallman <rms@gnu.org>
parents:
2784
diff
changeset
|
4464 |
2730
139740855fa6
* xfaces.c (Fmake_face_internal): Do nothing for non-X frames.
Jim Blandy <jimb@redhat.com>
parents:
2538
diff
changeset
|
4465 int |
24995 | 4466 face_with_height (f, face_id, height) |
4467 struct frame *f; | |
4468 int face_id; | |
4469 int height; | |
4470 { | |
4471 #ifdef HAVE_X_WINDOWS | |
4472 struct face *face; | |
4473 Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
4474 | |
4475 if (FRAME_TERMCAP_P (f) | |
4476 || height <= 0) | |
4477 return face_id; | |
4478 | |
4479 face = FACE_FROM_ID (f, face_id); | |
4480 bcopy (face->lface, attrs, sizeof attrs); | |
4481 attrs[LFACE_HEIGHT_INDEX] = make_number (height); | |
4482 face_id = lookup_face (f, attrs, CHARSET_ASCII); | |
4483 #endif /* HAVE_X_WINDOWS */ | |
4484 | |
4485 return face_id; | |
4486 } | |
4487 | |
25114
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4488 /* Return the face id of the realized face for named face SYMBOL on |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4489 frame F suitable for displaying characters from CHARSET (CHARSET < |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4490 0 means unibyte text), and use attributes of the face FACE_ID for |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4491 attributes that aren't completely specified by SYMBOL. This is |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4492 like lookup_named_face, except that the default attributes come |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4493 from FACE_ID, not from the default face. FACE_ID is assumed to |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4494 be already realized. */ |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4495 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4496 int |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4497 lookup_derived_face (f, symbol, charset, face_id) |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4498 struct frame *f; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4499 Lisp_Object symbol; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4500 int charset; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4501 int face_id; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4502 { |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4503 Lisp_Object attrs[LFACE_VECTOR_SIZE]; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4504 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE]; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4505 struct face *default_face = FACE_FROM_ID (f, face_id); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4506 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4507 if (!default_face) |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4508 abort (); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4509 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4510 get_lface_attributes (f, symbol, symbol_attrs, 1); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4511 bcopy (default_face->lface, attrs, sizeof attrs); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4512 merge_face_vectors (symbol_attrs, attrs); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4513 return lookup_face (f, attrs, charset); |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4514 } |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
4515 |
24995 | 4516 |
4517 | |
4518 /*********************************************************************** | |
4519 Font selection | |
4520 ***********************************************************************/ | |
4521 | |
4522 DEFUN ("internal-set-font-selection-order", | |
4523 Finternal_set_font_selection_order, | |
4524 Sinternal_set_font_selection_order, 1, 1, 0, | |
4525 "Set font selection order for face font selection to ORDER.\n\ | |
4526 ORDER must be a list of length 4 containing the symbols `:width',\n\ | |
4527 `:height', `:weight', and `:slant'. Face attributes appearing\n\ | |
4528 first in ORDER are matched first, e.g. if `:height' appears before\n\ | |
4529 `:weight' in ORDER, font selection first tries to find a font with\n\ | |
4530 a suitable height, and then tries to match the font weight.\n\ | |
4531 Value is ORDER.") | |
4532 (order) | |
4533 Lisp_Object order; | |
4534 { | |
4535 Lisp_Object list; | |
4536 int i; | |
4537 int indices[4]; | |
4538 | |
4539 CHECK_LIST (order, 0); | |
4540 bzero (indices, sizeof indices); | |
4541 i = 0; | |
4542 | |
4543 for (list = order; | |
4544 CONSP (list) && i < DIM (indices); | |
4545 list = XCDR (list), ++i) | |
4546 { | |
4547 Lisp_Object attr = XCAR (list); | |
4548 int xlfd; | |
4549 | |
4550 if (EQ (attr, QCwidth)) | |
4551 xlfd = XLFD_SWIDTH; | |
4552 else if (EQ (attr, QCheight)) | |
4553 xlfd = XLFD_POINT_SIZE; | |
4554 else if (EQ (attr, QCweight)) | |
4555 xlfd = XLFD_WEIGHT; | |
4556 else if (EQ (attr, QCslant)) | |
4557 xlfd = XLFD_SLANT; | |
4558 else | |
4559 break; | |
4560 | |
4561 if (indices[i] != 0) | |
4562 break; | |
4563 indices[i] = xlfd; | |
4564 } | |
4565 | |
4566 if (!NILP (list) | |
4567 || i != DIM (indices) | |
4568 || indices[0] == 0 | |
4569 || indices[1] == 0 | |
4570 || indices[2] == 0 | |
4571 || indices[3] == 0) | |
4572 signal_error ("Invalid font sort order", order); | |
4573 | |
4574 if (bcmp (indices, font_sort_order, sizeof indices) != 0) | |
4575 { | |
4576 bcopy (indices, font_sort_order, sizeof font_sort_order); | |
4577 free_all_realized_faces (Qnil); | |
4578 } | |
4579 | |
4580 return Qnil; | |
4581 } | |
4582 | |
4583 | |
4584 DEFUN ("internal-set-alternative-font-family-alist", | |
4585 Finternal_set_alternative_font_family_alist, | |
4586 Sinternal_set_alternative_font_family_alist, 1, 1, 0, | |
4587 "Define alternative font families to try in face font selection.\n\ | |
4588 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.\n\ | |
4589 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can\n\ | |
4590 be found. Value is ALIST.") | |
4591 (alist) | |
4592 Lisp_Object alist; | |
4593 { | |
4594 CHECK_LIST (alist, 0); | |
4595 Vface_alternative_font_family_alist = alist; | |
4596 free_all_realized_faces (Qnil); | |
4597 return alist; | |
4598 } | |
4599 | |
4600 | |
4601 #ifdef HAVE_X_WINDOWS | |
4602 | |
4603 /* Return the X registry and encoding of font name FONT_NAME on frame F. | |
4604 Value is nil if not successful. */ | |
4605 | |
4606 static Lisp_Object | |
4607 deduce_unibyte_registry (f, font_name) | |
4608 struct frame *f; | |
4609 char *font_name; | |
4610 { | |
4611 struct font_name font; | |
4612 Lisp_Object registry = Qnil; | |
4613 | |
4614 font.name = STRDUPA (font_name); | |
4615 if (split_font_name (f, &font, 0)) | |
4616 { | |
4617 char *buffer; | |
4618 | |
4619 /* Extract registry and encoding. */ | |
4620 buffer = (char *) alloca (strlen (font.fields[XLFD_REGISTRY]) | |
4621 + strlen (font.fields[XLFD_ENCODING]) | |
4622 + 10); | |
4623 strcpy (buffer, font.fields[XLFD_REGISTRY]); | |
4624 strcat (buffer, "-"); | |
4625 strcat (buffer, font.fields[XLFD_ENCODING]); | |
4626 registry = build_string (buffer); | |
4627 } | |
4628 | |
4629 return registry; | |
4630 } | |
4631 | |
4632 | |
4633 /* Value is non-zero if FONT is the name of a scalable font. The | |
4634 X11R6 XLFD spec says that point size, pixel size, and average width | |
4635 are zero for scalable fonts. Intlfonts contain at least one | |
4636 scalable font ("*-muleindian-1") for which this isn't true, so we | |
4637 just test average width. */ | |
4638 | |
4639 static int | |
4640 font_scalable_p (font) | |
4641 struct font_name *font; | |
4642 { | |
4643 char *s = font->fields[XLFD_AVGWIDTH]; | |
4644 return *s == '0' && *(s + 1) == '\0'; | |
4645 } | |
4646 | |
4647 | |
4648 /* Value is non-zero if FONT1 is a better match for font attributes | |
4649 VALUES than FONT2. VALUES is an array of face attribute values in | |
4650 font sort order. COMPARE_PT_P zero means don't compare point | |
4651 sizes. */ | |
4652 | |
4653 static int | |
4654 better_font_p (values, font1, font2, compare_pt_p) | |
4655 int *values; | |
4656 struct font_name *font1, *font2; | |
4657 int compare_pt_p; | |
4658 { | |
4659 int i; | |
4660 | |
4661 for (i = 0; i < 4; ++i) | |
4662 { | |
4663 int xlfd_idx = font_sort_order[i]; | |
4664 | |
4665 if (compare_pt_p || xlfd_idx != XLFD_POINT_SIZE) | |
4666 { | |
4667 int delta1 = abs (values[i] - font1->numeric[xlfd_idx]); | |
4668 int delta2 = abs (values[i] - font2->numeric[xlfd_idx]); | |
4669 | |
4670 if (delta1 > delta2) | |
4671 return 0; | |
4672 else if (delta1 < delta2) | |
4673 return 1; | |
4674 else | |
4675 { | |
4676 /* The difference may be equal because, e.g., the face | |
4677 specifies `italic' but we have only `regular' and | |
4678 `oblique'. Prefer `oblique' in this case. */ | |
4679 if ((xlfd_idx == XLFD_WEIGHT || xlfd_idx == XLFD_SLANT) | |
4680 && font1->numeric[xlfd_idx] > values[i] | |
4681 && font2->numeric[xlfd_idx] < values[i]) | |
4682 return 1; | |
4683 } | |
4684 } | |
4685 } | |
4686 | |
4687 return 0; | |
4688 } | |
4689 | |
4690 | |
4691 #if SCALABLE_FONTS | |
4692 | |
4693 /* Value is non-zero if FONT is an exact match for face attributes in | |
4694 SPECIFIED. SPECIFIED is an array of face attribute values in font | |
4695 sort order. */ | |
4696 | |
4697 static int | |
4698 exact_face_match_p (specified, font) | |
4699 int *specified; | |
4700 struct font_name *font; | |
4701 { | |
4702 int i; | |
4703 | |
4704 for (i = 0; i < 4; ++i) | |
4705 if (specified[i] != font->numeric[font_sort_order[i]]) | |
4706 break; | |
4707 | |
4708 return i == 4; | |
4709 } | |
4710 | |
4711 | |
4712 /* Value is the name of a scaled font, generated from scalable font | |
4713 FONT on frame F. SPECIFIED_PT is the point-size to scale FONT to. | |
4714 Value is allocated from heap. */ | |
4715 | |
4716 static char * | |
4717 build_scalable_font_name (f, font, specified_pt) | |
4718 struct frame *f; | |
4719 struct font_name *font; | |
4720 int specified_pt; | |
4721 { | |
4722 char point_size[20], pixel_size[20]; | |
4723 int pixel_value; | |
4724 double resy = FRAME_X_DISPLAY_INFO (f)->resy; | |
4725 double pt; | |
4726 | |
4727 /* If scalable font is for a specific resolution, compute | |
4728 the point size we must specify from the resolution of | |
4729 the display and the specified resolution of the font. */ | |
4730 if (font->numeric[XLFD_RESY] != 0) | |
4731 { | |
4732 pt = resy / font->numeric[XLFD_RESY] * specified_pt + 0.5; | |
4733 pixel_value = font->numeric[XLFD_RESY] / 720.0 * pt; | |
4734 } | |
4735 else | |
4736 { | |
4737 pt = specified_pt; | |
4738 pixel_value = resy / 720.0 * pt; | |
4739 } | |
4740 | |
4741 /* Set point size of the font. */ | |
4742 sprintf (point_size, "%d", (int) pt); | |
4743 font->fields[XLFD_POINT_SIZE] = point_size; | |
4744 font->numeric[XLFD_POINT_SIZE] = pt; | |
4745 | |
4746 /* Set pixel size. */ | |
4747 sprintf (pixel_size, "%d", pixel_value); | |
4748 font->fields[XLFD_PIXEL_SIZE] = pixel_size; | |
4749 font->numeric[XLFD_PIXEL_SIZE] = pixel_value; | |
4750 | |
4751 /* If font doesn't specify its resolution, use the | |
4752 resolution of the display. */ | |
4753 if (font->numeric[XLFD_RESY] == 0) | |
4754 { | |
4755 char buffer[20]; | |
4756 sprintf (buffer, "%d", (int) resy); | |
4757 font->fields[XLFD_RESY] = buffer; | |
4758 font->numeric[XLFD_RESY] = resy; | |
4759 } | |
4760 | |
4761 if (strcmp (font->fields[XLFD_RESX], "0") == 0) | |
4762 { | |
4763 char buffer[20]; | |
4764 int resx = FRAME_X_DISPLAY_INFO (f)->resx; | |
4765 sprintf (buffer, "%d", resx); | |
4766 font->fields[XLFD_RESX] = buffer; | |
4767 font->numeric[XLFD_RESX] = resx; | |
4768 } | |
4769 | |
4770 return build_font_name (font); | |
4771 } | |
4772 | |
4773 | |
4774 /* Value is non-zero if we are allowed to use scalable font FONT. We | |
4775 can't run a Lisp function here since this function may be called | |
4776 with input blocked. */ | |
4777 | |
4778 static int | |
4779 may_use_scalable_font_p (font, name) | |
4780 struct font_name *font; | |
4781 char *name; | |
4782 { | |
4783 if (EQ (Vscalable_fonts_allowed, Qt)) | |
4784 return 1; | |
4785 else if (CONSP (Vscalable_fonts_allowed)) | |
4786 { | |
4787 Lisp_Object tail, regexp; | |
4788 | |
4789 for (tail = Vscalable_fonts_allowed; CONSP (tail); tail = XCDR (tail)) | |
4790 { | |
4791 regexp = XCAR (tail); | |
4792 if (STRINGP (regexp) | |
4793 && fast_c_string_match_ignore_case (regexp, name) >= 0) | |
4794 return 1; | |
4795 } | |
4796 } | |
4797 | |
4798 return 0; | |
4799 } | |
4800 | |
4801 #endif /* SCALABLE_FONTS != 0 */ | |
4802 | |
4803 | |
4804 /* Return the name of the best matching font for face attributes | |
4805 ATTRS in the array of font_name structures FONTS which contains | |
4806 NFONTS elements. Value is a font name which is allocated from | |
4807 the heap. FONTS is freed by this function. */ | |
4808 | |
4809 static char * | |
4810 best_matching_font (f, attrs, fonts, nfonts) | |
4811 struct frame *f; | |
4812 Lisp_Object *attrs; | |
4813 struct font_name *fonts; | |
4814 int nfonts; | |
4815 { | |
4816 char *font_name; | |
4817 struct font_name *best; | |
4818 int i, pt; | |
4819 int specified[4]; | |
4820 int exact_p; | |
4821 | |
4822 if (nfonts == 0) | |
4823 return NULL; | |
4824 | |
4825 /* Make specified font attributes available in `specified', | |
4826 indexed by sort order. */ | |
4827 for (i = 0; i < DIM (font_sort_order); ++i) | |
4828 { | |
4829 int xlfd_idx = font_sort_order[i]; | |
4830 | |
4831 if (xlfd_idx == XLFD_SWIDTH) | |
4832 specified[i] = face_numeric_swidth (attrs[LFACE_SWIDTH_INDEX]); | |
4833 else if (xlfd_idx == XLFD_POINT_SIZE) | |
4834 specified[i] = pt = XFASTINT (attrs[LFACE_HEIGHT_INDEX]); | |
4835 else if (xlfd_idx == XLFD_WEIGHT) | |
4836 specified[i] = face_numeric_weight (attrs[LFACE_WEIGHT_INDEX]); | |
4837 else if (xlfd_idx == XLFD_SLANT) | |
4838 specified[i] = face_numeric_slant (attrs[LFACE_SLANT_INDEX]); | |
4839 else | |
4840 abort (); | |
4841 } | |
4842 | |
4843 #if SCALABLE_FONTS | |
4844 | |
4845 /* Set to 1 */ | |
4846 exact_p = 0; | |
4847 | |
4848 /* Start with the first non-scalable font in the list. */ | |
4849 for (i = 0; i < nfonts; ++i) | |
4850 if (!font_scalable_p (fonts + i)) | |
4851 break; | |
4852 | |
4853 /* Find the best match among the non-scalable fonts. */ | |
4854 if (i < nfonts) | |
4855 { | |
4856 best = fonts + i; | |
4857 | |
4858 for (i = 1; i < nfonts; ++i) | |
4859 if (!font_scalable_p (fonts + i) | |
4860 && better_font_p (specified, fonts + i, best, 1)) | |
4861 { | |
4862 best = fonts + i; | |
4863 | |
4864 exact_p = exact_face_match_p (specified, best); | |
4865 if (exact_p) | |
4866 break; | |
4867 } | |
4868 | |
4869 } | |
4870 else | |
4871 best = NULL; | |
4872 | |
4873 /* Unless we found an exact match among non-scalable fonts, see if | |
4874 we can find a better match among scalable fonts. */ | |
4875 if (!exact_p) | |
4876 { | |
4877 /* A scalable font is better if | |
4878 | |
4879 1. its weight, slant, swidth attributes are better, or. | |
4880 | |
4881 2. the best non-scalable font doesn't have the required | |
4882 point size, and the scalable fonts weight, slant, swidth | |
4883 isn't worse. */ | |
4884 | |
4885 int non_scalable_has_exact_height_p; | |
4886 | |
4887 if (best && best->numeric[XLFD_POINT_SIZE] == pt) | |
4888 non_scalable_has_exact_height_p = 1; | |
4889 else | |
4890 non_scalable_has_exact_height_p = 0; | |
4891 | |
4892 for (i = 0; i < nfonts; ++i) | |
4893 if (font_scalable_p (fonts + i)) | |
4894 { | |
4895 if (best == NULL | |
4896 || better_font_p (specified, fonts + i, best, 0) | |
4897 || (!non_scalable_has_exact_height_p | |
4898 && !better_font_p (specified, best, fonts + i, 0))) | |
4899 best = fonts + i; | |
4900 } | |
4901 } | |
4902 | |
4903 if (font_scalable_p (best)) | |
4904 font_name = build_scalable_font_name (f, best, pt); | |
4905 else | |
4906 font_name = build_font_name (best); | |
4907 | |
4908 #else /* !SCALABLE_FONTS */ | |
4909 | |
4910 /* Find the best non-scalable font. */ | |
4911 best = fonts; | |
4912 | |
4913 for (i = 1; i < nfonts; ++i) | |
4914 { | |
4915 xassert (!font_scalable_p (fonts + i)); | |
4916 if (better_font_p (specified, fonts + i, best, 1)) | |
4917 best = fonts + i; | |
4918 } | |
4919 | |
4920 font_name = build_font_name (best); | |
4921 | |
4922 #endif /* !SCALABLE_FONTS */ | |
4923 | |
4924 /* Free font_name structures. */ | |
4925 free_font_names (fonts, nfonts); | |
4926 | |
4927 return font_name; | |
4928 } | |
4929 | |
4930 | |
4931 /* Try to get a list of fonts on frame F with font family FAMILY and | |
4932 registry/encoding REGISTRY. Return in *FONTS a pointer to a vector | |
4933 of font_name structures for the fonts matched. Value is the number | |
4934 of fonts found. */ | |
4935 | |
4936 static int | |
4937 try_font_list (f, attrs, pattern, family, registry, fonts) | |
4938 struct frame *f; | |
4939 Lisp_Object *attrs; | |
4940 char *pattern, *family, *registry; | |
4941 struct font_name **fonts; | |
4942 { | |
4943 int nfonts; | |
4944 | |
4945 if (family == NULL) | |
4946 family = LSTRDUPA (attrs[LFACE_FAMILY_INDEX]); | |
4947 | |
4948 nfonts = font_list (f, pattern, family, registry, fonts); | |
4949 | |
4950 if (nfonts == 0) | |
4951 { | |
4952 Lisp_Object alter; | |
4953 | |
4954 /* Try alternative font families from | |
4955 Vface_alternative_font_family_alist. */ | |
4956 alter = Fassoc (build_string (family), | |
4957 Vface_alternative_font_family_alist); | |
4958 if (CONSP (alter)) | |
4959 for (alter = XCDR (alter); | |
4960 CONSP (alter) && nfonts == 0; | |
4961 alter = XCDR (alter)) | |
4962 { | |
4963 if (STRINGP (XCAR (alter))) | |
4964 { | |
4965 family = LSTRDUPA (XCAR (alter)); | |
4966 nfonts = font_list (f, NULL, family, registry, fonts); | |
4967 } | |
4968 } | |
4969 | |
4970 /* Try font family of the default face or "fixed". */ | |
4971 if (nfonts == 0) | |
4972 { | |
4973 struct face *dflt = FACE_FROM_ID (f, DEFAULT_FACE_ID); | |
4974 if (dflt) | |
4975 family = LSTRDUPA (dflt->lface[LFACE_FAMILY_INDEX]); | |
4976 else | |
4977 family = "fixed"; | |
4978 nfonts = font_list (f, NULL, family, registry, fonts); | |
4979 } | |
4980 | |
4981 /* Try any family with the given registry. */ | |
4982 if (nfonts == 0) | |
4983 nfonts = font_list (f, NULL, "*", registry, fonts); | |
4984 } | |
4985 | |
4986 return nfonts; | |
4987 } | |
4988 | |
4989 | |
4990 /* Return the registry and encoding pattern that fonts for CHARSET | |
4991 should match. Value is allocated from the heap. */ | |
4992 | |
4993 char * | |
4994 x_charset_registry (charset) | |
4995 int charset; | |
4996 { | |
4997 Lisp_Object prop, charset_plist; | |
4998 char *registry; | |
4999 | |
5000 /* Get registry and encoding from the charset's plist. */ | |
5001 charset_plist = CHARSET_TABLE_INFO (charset, CHARSET_PLIST_IDX); | |
5002 prop = Fplist_get (charset_plist, Qx_charset_registry); | |
5003 | |
5004 if (STRINGP (prop)) | |
5005 { | |
5006 if (index (XSTRING (prop)->data, '-')) | |
5007 registry = xstrdup (XSTRING (prop)->data); | |
5008 else | |
5009 { | |
5010 /* If registry doesn't contain a `-', make it a pattern. */ | |
5011 registry = (char *) xmalloc (STRING_BYTES (XSTRING (prop)) + 5); | |
5012 strcpy (registry, XSTRING (prop)->data); | |
5013 strcat (registry, "*-*"); | |
5014 } | |
5015 } | |
5016 else if (STRINGP (Vface_default_registry)) | |
5017 registry = xstrdup (XSTRING (Vface_default_registry)->data); | |
5018 else | |
5019 registry = xstrdup ("iso8859-1"); | |
5020 | |
5021 return registry; | |
5022 } | |
5023 | |
5024 | |
5025 /* Return the fontset id of the fontset name or alias name given by | |
5026 the family attribute of ATTRS on frame F. Value is -1 if the | |
5027 family attribute of ATTRS doesn't name a fontset. */ | |
5028 | |
5029 static int | |
5030 face_fontset (f, attrs) | |
5031 struct frame *f; | |
5032 Lisp_Object *attrs; | |
5033 { | |
5034 Lisp_Object name = attrs[LFACE_FAMILY_INDEX]; | |
5035 int fontset; | |
5036 | |
5037 name = Fquery_fontset (name, Qnil); | |
5038 if (NILP (name)) | |
5039 fontset = -1; | |
5040 else | |
5041 fontset = fs_query_fontset (f, XSTRING (name)->data); | |
5042 | |
5043 return fontset; | |
5044 } | |
5045 | |
5046 | |
5047 /* Get the font to use for the face realizing the fully-specified Lisp | |
5048 face ATTRS for charset CHARSET on frame F. CHARSET < 0 means | |
5049 unibyte text; UNIBYTE_REGISTRY is the registry and encoding to use | |
5050 in this case. Value is the font name which is allocated from the | |
5051 heap (which means that it must be freed eventually). */ | |
5052 | |
5053 static char * | |
5054 choose_face_font (f, attrs, charset, unibyte_registry) | |
5055 struct frame *f; | |
5056 Lisp_Object *attrs; | |
5057 int charset; | |
5058 Lisp_Object unibyte_registry; | |
5059 { | |
5060 struct font_name *fonts; | |
5061 int nfonts; | |
5062 char *registry; | |
5063 | |
5064 /* ATTRS must be fully-specified. */ | |
5065 xassert (lface_fully_specified_p (attrs)); | |
5066 | |
5067 if (STRINGP (unibyte_registry)) | |
5068 registry = xstrdup (XSTRING (unibyte_registry)->data); | |
5069 else | |
5070 registry = x_charset_registry (charset); | |
5071 | |
5072 nfonts = try_font_list (f, attrs, NULL, NULL, registry, &fonts); | |
5073 xfree (registry); | |
5074 return best_matching_font (f, attrs, fonts, nfonts); | |
5075 } | |
5076 | |
5077 | |
5078 /* Choose a font to use on frame F to display CHARSET using FONTSET | |
5079 with Lisp face attributes specified by ATTRS. CHARSET may be any | |
5080 valid charset except CHARSET_COMPOSITION. CHARSET < 0 means | |
5081 unibyte text. If the fontset doesn't contain a font pattern for | |
5082 charset, use the pattern for CHARSET_ASCII. Value is the font name | |
5083 which is allocated from the heap and must be freed by the caller. */ | |
5084 | |
5085 static char * | |
5086 choose_face_fontset_font (f, attrs, fontset, charset) | |
5087 struct frame *f; | |
5088 Lisp_Object *attrs; | |
5089 int fontset, charset; | |
5090 { | |
5091 char *pattern; | |
5092 char *font_name = NULL; | |
5093 struct fontset_info *fontset_info; | |
5094 struct font_name *fonts; | |
5095 int nfonts; | |
5096 | |
5097 xassert (charset != CHARSET_COMPOSITION); | |
5098 xassert (fontset >= 0 && fontset < FRAME_FONTSET_DATA (f)->n_fontsets); | |
5099 | |
5100 /* For unibyte text, use the ASCII font of the fontset. Using the | |
5101 ASCII font seems to be the most reasonable thing we can do in | |
5102 this case. */ | |
5103 if (charset < 0) | |
5104 charset = CHARSET_ASCII; | |
5105 | |
5106 /* Get the font name pattern to use for CHARSET from the fontset. */ | |
5107 fontset_info = FRAME_FONTSET_DATA (f)->fontset_table[fontset]; | |
5108 pattern = fontset_info->fontname[charset]; | |
5109 if (!pattern) | |
5110 pattern = fontset_info->fontname[CHARSET_ASCII]; | |
5111 xassert (pattern); | |
5112 | |
5113 /* Get a list of fonts matching that pattern and choose the | |
5114 best match for the specified face attributes from it. */ | |
5115 nfonts = try_font_list (f, attrs, pattern, NULL, NULL, &fonts); | |
5116 font_name = best_matching_font (f, attrs, fonts, nfonts); | |
5117 return font_name; | |
5118 } | |
5119 | |
5120 #endif /* HAVE_X_WINDOWS */ | |
5121 | |
5122 | |
5123 | |
5124 /*********************************************************************** | |
5125 Face Realization | |
5126 ***********************************************************************/ | |
5127 | |
5128 /* Realize basic faces on frame F. Value is zero if frame parameters | |
5129 of F don't contain enough information needed to realize the default | |
5130 face. */ | |
5131 | |
5132 static int | |
5133 realize_basic_faces (f) | |
2342 | 5134 struct frame *f; |
24995 | 5135 { |
5136 int success_p = 0; | |
5137 | |
5138 if (realize_default_face (f)) | |
5139 { | |
5140 realize_named_face (f, Qmodeline, MODE_LINE_FACE_ID); | |
5141 realize_named_face (f, Qtoolbar, TOOLBAR_FACE_ID); | |
5142 realize_named_face (f, Qbitmap_area, BITMAP_AREA_FACE_ID); | |
5143 realize_named_face (f, Qtop_line, TOP_LINE_FACE_ID); | |
5144 success_p = 1; | |
5145 } | |
5146 | |
5147 return success_p; | |
5148 } | |
5149 | |
5150 | |
5151 /* Realize the default face on frame F. If the face is not fully | |
5152 specified, make it fully-specified. Attributes of the default face | |
5153 that are not explicitly specified are taken from frame parameters. */ | |
5154 | |
5155 static int | |
5156 realize_default_face (f) | |
5157 struct frame *f; | |
5158 { | |
5159 struct face_cache *c = FRAME_FACE_CACHE (f); | |
5160 Lisp_Object lface; | |
5161 Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
5162 Lisp_Object unibyte_registry; | |
5163 Lisp_Object frame_font; | |
5164 struct face *face; | |
5165 int fontset; | |
5166 | |
5167 /* If the `default' face is not yet known, create it. */ | |
5168 lface = lface_from_face_name (f, Qdefault, 0); | |
5169 if (NILP (lface)) | |
5170 { | |
5171 Lisp_Object frame; | |
5172 XSETFRAME (frame, f); | |
5173 lface = Finternal_make_lisp_face (Qdefault, frame); | |
5174 } | |
5175 | |
5176 #ifdef HAVE_X_WINDOWS | |
5177 if (FRAME_X_P (f)) | |
5178 { | |
5179 /* Set frame_font to the value of the `font' frame parameter. */ | |
5180 frame_font = Fassq (Qfont, f->param_alist); | |
5181 xassert (CONSP (frame_font) && STRINGP (XCDR (frame_font))); | |
5182 frame_font = XCDR (frame_font); | |
5183 | |
5184 fontset = fs_query_fontset (f, XSTRING (frame_font)->data); | |
5185 if (fontset >= 0) | |
5186 { | |
5187 /* If frame_font is a fontset name, don't use that for | |
5188 determining font-related attributes of the default face | |
5189 because it is just an artificial name. Use the ASCII font of | |
5190 the fontset, instead. */ | |
5191 struct font_info *font_info; | |
5192 struct font_name font; | |
5193 | |
5194 BLOCK_INPUT; | |
5195 font_info = FS_LOAD_FONT (f, FRAME_X_FONT_TABLE (f), CHARSET_ASCII, | |
5196 NULL, fontset); | |
5197 UNBLOCK_INPUT; | |
5198 | |
5199 /* Set weight etc. from the ASCII font. */ | |
5200 if (!set_lface_from_font_name (f, lface, font_info->full_name, 0)) | |
5201 return 0; | |
5202 | |
5203 /* Remember registry and encoding of the frame font. */ | |
5204 unibyte_registry = deduce_unibyte_registry (f, font_info->full_name); | |
5205 if (STRINGP (unibyte_registry)) | |
5206 Vface_default_registry = unibyte_registry; | |
5207 else | |
5208 Vface_default_registry = build_string ("iso8859-1"); | |
5209 | |
5210 /* But set the family to the fontset alias name. Implementation | |
5211 note: When a font is passed to Emacs via `-fn FONT', a | |
5212 fontset is created in `x-win.el' whose name ends in | |
5213 `fontset-startup'. This fontset has an alias name that is | |
5214 equal to frame_font. */ | |
5215 xassert (STRINGP (frame_font)); | |
5216 font.name = LSTRDUPA (frame_font); | |
5217 | |
5218 if (!split_font_name (f, &font, 1) | |
5219 || xstricmp (font.fields[XLFD_REGISTRY], "fontset") != 0 | |
5220 || xstricmp (font.fields[XLFD_ENCODING], "startup") != 0) | |
5221 LFACE_FAMILY (lface) = frame_font; | |
5222 } | |
5223 else | |
5224 { | |
5225 /* Frame parameters contain a real font. Fill default face | |
5226 attributes from that font. */ | |
5227 if (!set_lface_from_font_name (f, lface, | |
5228 XSTRING (frame_font)->data, 0)) | |
5229 return 0; | |
5230 | |
5231 /* Remember registry and encoding of the frame font. */ | |
5232 unibyte_registry | |
5233 = deduce_unibyte_registry (f, XSTRING (frame_font)->data); | |
5234 if (STRINGP (unibyte_registry)) | |
5235 Vface_default_registry = unibyte_registry; | |
5236 else | |
5237 Vface_default_registry = build_string ("iso8859-1"); | |
5238 } | |
5239 } | |
5240 #endif /* HAVE_X_WINDOWS */ | |
5241 | |
25114
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5242 if (!FRAME_WINDOW_P (f)) |
24995 | 5243 { |
5244 LFACE_FAMILY (lface) = build_string ("default"); | |
5245 LFACE_SWIDTH (lface) = Qnormal; | |
5246 LFACE_HEIGHT (lface) = make_number (1); | |
5247 LFACE_WEIGHT (lface) = Qnormal; | |
5248 LFACE_SLANT (lface) = Qnormal; | |
5249 } | |
5250 | |
5251 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface))) | |
5252 LFACE_UNDERLINE (lface) = Qnil; | |
5253 | |
5254 if (UNSPECIFIEDP (LFACE_OVERLINE (lface))) | |
5255 LFACE_OVERLINE (lface) = Qnil; | |
5256 | |
5257 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface))) | |
5258 LFACE_STRIKE_THROUGH (lface) = Qnil; | |
5259 | |
5260 if (UNSPECIFIEDP (LFACE_BOX (lface))) | |
5261 LFACE_BOX (lface) = Qnil; | |
5262 | |
5263 if (UNSPECIFIEDP (LFACE_INVERSE (lface))) | |
5264 LFACE_INVERSE (lface) = Qnil; | |
5265 | |
5266 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface))) | |
5267 { | |
5268 /* This function is called so early that colors are not yet | |
5269 set in the frame parameter list. */ | |
5270 Lisp_Object color = Fassq (Qforeground_color, f->param_alist); | |
5271 | |
5272 if (CONSP (color) && STRINGP (XCDR (color))) | |
5273 LFACE_FOREGROUND (lface) = XCDR (color); | |
5274 else if (FRAME_X_P (f)) | |
5275 return 0; | |
25114
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5276 else if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) |
24995 | 5277 /* Frame parameters for terminal frames usually don't contain |
5278 a color. Use an empty string to indicate that the face | |
5279 should use the (unknown) default color of the terminal. */ | |
5280 LFACE_FOREGROUND (lface) = build_string (""); | |
5281 else | |
5282 abort (); | |
5283 } | |
5284 | |
5285 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface))) | |
5286 { | |
5287 /* This function is called so early that colors are not yet | |
5288 set in the frame parameter list. */ | |
5289 Lisp_Object color = Fassq (Qbackground_color, f->param_alist); | |
5290 if (CONSP (color) && STRINGP (XCDR (color))) | |
5291 LFACE_BACKGROUND (lface) = XCDR (color); | |
5292 else if (FRAME_X_P (f)) | |
5293 return 0; | |
25114
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5294 else if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) |
24995 | 5295 /* Frame parameters for terminal frames usually don't contain |
5296 a color. Use an empty string to indicate that the face | |
5297 should use the (unknown) default color of the terminal. */ | |
5298 LFACE_BACKGROUND (lface) = build_string (""); | |
5299 else | |
5300 abort (); | |
5301 } | |
5302 | |
5303 if (UNSPECIFIEDP (LFACE_STIPPLE (lface))) | |
5304 LFACE_STIPPLE (lface) = Qnil; | |
5305 | |
5306 /* Realize the face; it must be fully-specified now. */ | |
5307 xassert (lface_fully_specified_p (XVECTOR (lface)->contents)); | |
5308 check_lface (lface); | |
5309 bcopy (XVECTOR (lface)->contents, attrs, sizeof attrs); | |
5310 face = realize_face (c, attrs, CHARSET_ASCII); | |
5311 | |
5312 /* Remove the former default face. */ | |
5313 if (c->used > DEFAULT_FACE_ID) | |
5314 { | |
5315 struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); | |
5316 uncache_face (c, default_face); | |
5317 free_realized_face (f, default_face); | |
5318 } | |
5319 | |
5320 /* Insert the new default face. */ | |
5321 cache_face (c, face, lface_hash (attrs)); | |
5322 xassert (face->id == DEFAULT_FACE_ID); | |
5323 return 1; | |
5324 } | |
5325 | |
5326 | |
5327 /* Realize basic faces other than the default face in face cache C. | |
5328 SYMBOL is the face name, ID is the face id the realized face must | |
5329 have. The default face must have been realized already. */ | |
5330 | |
5331 static void | |
5332 realize_named_face (f, symbol, id) | |
5333 struct frame *f; | |
5334 Lisp_Object symbol; | |
5335 int id; | |
5336 { | |
5337 struct face_cache *c = FRAME_FACE_CACHE (f); | |
5338 Lisp_Object lface = lface_from_face_name (f, symbol, 0); | |
5339 Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
5340 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE]; | |
5341 struct face *new_face; | |
5342 | |
5343 /* The default face must exist and be fully specified. */ | |
5344 get_lface_attributes (f, Qdefault, attrs, 1); | |
5345 check_lface_attrs (attrs); | |
5346 xassert (lface_fully_specified_p (attrs)); | |
5347 | |
5348 /* If SYMBOL isn't know as a face, create it. */ | |
5349 if (NILP (lface)) | |
5350 { | |
5351 Lisp_Object frame; | |
5352 XSETFRAME (frame, f); | |
5353 lface = Finternal_make_lisp_face (symbol, frame); | |
5354 } | |
5355 | |
5356 /* Merge SYMBOL's face with the default face. */ | |
5357 get_lface_attributes (f, symbol, symbol_attrs, 1); | |
5358 merge_face_vectors (symbol_attrs, attrs); | |
5359 | |
5360 /* Realize the face. */ | |
5361 new_face = realize_face (c, attrs, CHARSET_ASCII); | |
5362 | |
5363 /* Remove the former face. */ | |
5364 if (c->used > id) | |
5365 { | |
5366 struct face *old_face = c->faces_by_id[id]; | |
5367 uncache_face (c, old_face); | |
5368 free_realized_face (f, old_face); | |
5369 } | |
5370 | |
5371 /* Insert the new face. */ | |
5372 cache_face (c, new_face, lface_hash (attrs)); | |
5373 xassert (new_face->id == id); | |
5374 } | |
5375 | |
5376 | |
5377 /* Realize the fully-specified face with attributes ATTRS in face | |
5378 cache C for character set CHARSET or for unibyte text if CHARSET < | |
5379 0. Value is a pointer to the newly created realized face. */ | |
5380 | |
5381 static struct face * | |
5382 realize_face (c, attrs, charset) | |
5383 struct face_cache *c; | |
5384 Lisp_Object *attrs; | |
5385 int charset; | |
5386 { | |
5387 struct face *face; | |
5388 | |
5389 /* LFACE must be fully specified. */ | |
5390 xassert (c != NULL); | |
5391 check_lface_attrs (attrs); | |
5392 | |
5393 if (FRAME_X_P (c->f)) | |
5394 face = realize_x_face (c, attrs, charset); | |
25114
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5395 else if (FRAME_TERMCAP_P (c->f) || FRAME_MSDOS_P (c->f)) |
24995 | 5396 face = realize_tty_face (c, attrs, charset); |
5397 else | |
5398 abort (); | |
5399 | |
5400 return face; | |
5401 } | |
5402 | |
5403 | |
5404 /* Realize the fully-specified face with attributes ATTRS in face | |
5405 cache C for character set CHARSET or for unibyte text if CHARSET < | |
5406 0. Do it for X frame C->f. Value is a pointer to the newly | |
5407 created realized face. */ | |
5408 | |
5409 static struct face * | |
5410 realize_x_face (c, attrs, charset) | |
5411 struct face_cache *c; | |
5412 Lisp_Object *attrs; | |
5413 int charset; | |
5414 { | |
5415 #ifdef HAVE_X_WINDOWS | |
5416 struct face *face, *default_face; | |
5417 struct frame *f = c->f; | |
5418 Lisp_Object stipple, overline, strike_through, box; | |
5419 Lisp_Object unibyte_registry; | |
5420 struct gcpro gcpro1; | |
5421 | |
5422 xassert (FRAME_X_P (f)); | |
5423 | |
5424 /* If realizing a face for use in unibyte text, get the X registry | |
5425 and encoding to use from Vface_default_registry. */ | |
5426 if (charset < 0) | |
5427 unibyte_registry = (STRINGP (Vface_default_registry) | |
5428 ? Vface_default_registry | |
5429 : build_string ("iso8859-1")); | |
5430 else | |
5431 unibyte_registry = Qnil; | |
5432 GCPRO1 (unibyte_registry); | |
5433 | |
5434 /* Allocate a new realized face. */ | |
5435 face = make_realized_face (attrs, charset, unibyte_registry); | |
5436 | |
5437 /* Determine the font to use. Most of the time, the font will be | |
5438 the same as the font of the default face, so try that first. */ | |
5439 default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); | |
5440 if (default_face | |
5441 && FACE_SUITABLE_FOR_CHARSET_P (default_face, charset) | |
5442 && lface_same_font_attributes_p (default_face->lface, attrs)) | |
5443 { | |
5444 face->font = default_face->font; | |
5445 face->fontset = default_face->fontset; | |
5446 face->font_info_id = default_face->font_info_id; | |
5447 face->font_name = default_face->font_name; | |
5448 face->registry = default_face->registry; | |
5449 } | |
5450 else if (charset >= 0) | |
5451 { | |
5452 /* For all charsets except CHARSET_COMPOSITION, we use our own | |
5453 font selection functions to choose a best matching font for | |
5454 the specified face attributes. If the face specifies a | |
5455 fontset alias name, the fontset determines the font name | |
5456 pattern, otherwise we construct a font pattern from face | |
5457 attributes and charset. | |
5458 | |
5459 If charset is CHARSET_COMPOSITION, we always construct a face | |
5460 with a fontset, even if the face doesn't specify a fontset alias | |
5461 (we use fontset-standard in that case). When the composite | |
5462 character is displayed in xterm.c, a suitable concrete font is | |
5463 loaded in x_get_char_font_and_encoding. */ | |
5464 | |
5465 char *font_name = NULL; | |
5466 int fontset = face_fontset (f, attrs); | |
5467 | |
5468 if (charset == CHARSET_COMPOSITION) | |
5469 fontset = max (0, fontset); | |
5470 else if (fontset < 0) | |
5471 font_name = choose_face_font (f, attrs, charset, Qnil); | |
5472 else | |
5473 { | |
5474 font_name = choose_face_fontset_font (f, attrs, fontset, charset); | |
5475 fontset = -1; | |
5476 } | |
5477 | |
5478 load_face_font_or_fontset (f, face, font_name, fontset); | |
5479 xfree (font_name); | |
5480 } | |
5481 else | |
5482 { | |
5483 /* Unibyte case, and font is not equal to that of the default | |
5484 face. UNIBYTE_REGISTRY is the X registry and encoding the | |
5485 font should have. What is a reasonable thing to do if the | |
5486 user specified a fontset alias name for the face in this | |
5487 case? We choose a font by taking the ASCII font of the | |
5488 fontset, but using UNIBYTE_REGISTRY for its registry and | |
5489 encoding. */ | |
5490 | |
5491 char *font_name = NULL; | |
5492 int fontset = face_fontset (f, attrs); | |
5493 | |
5494 if (fontset < 0) | |
5495 font_name = choose_face_font (f, attrs, charset, unibyte_registry); | |
5496 else | |
5497 font_name = choose_face_fontset_font (f, attrs, fontset, charset); | |
5498 | |
5499 load_face_font_or_fontset (f, face, font_name, -1); | |
5500 xfree (font_name); | |
5501 } | |
5502 | |
5503 /* Load colors, and set remaining attributes. */ | |
5504 | |
5505 load_face_colors (f, face, attrs); | |
5506 | |
5507 /* Set up box. */ | |
5508 box = attrs[LFACE_BOX_INDEX]; | |
5509 if (STRINGP (box)) | |
5510 { | |
5511 /* A simple box of line width 1 drawn in color given by | |
5512 the string. */ | |
5513 face->box_color = load_color (f, face, attrs[LFACE_BOX_INDEX], | |
5514 LFACE_BOX_INDEX); | |
5515 face->box = FACE_SIMPLE_BOX; | |
5516 face->box_line_width = 1; | |
5517 } | |
5518 else if (INTEGERP (box)) | |
5519 { | |
5520 /* Simple box of specified line width in foreground color of the | |
5521 face. */ | |
5522 xassert (XINT (box) > 0); | |
5523 face->box = FACE_SIMPLE_BOX; | |
5524 face->box_line_width = XFASTINT (box); | |
5525 face->box_color = face->foreground; | |
5526 face->box_color_defaulted_p = 1; | |
5527 } | |
5528 else if (CONSP (box)) | |
5529 { | |
5530 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW | |
5531 being one of `raised' or `sunken'. */ | |
5532 face->box = FACE_SIMPLE_BOX; | |
5533 face->box_color = face->foreground; | |
5534 face->box_color_defaulted_p = 1; | |
5535 face->box_line_width = 1; | |
5536 | |
5537 while (CONSP (box)) | |
5538 { | |
5539 Lisp_Object keyword, value; | |
5540 | |
5541 keyword = XCAR (box); | |
5542 box = XCDR (box); | |
5543 | |
5544 if (!CONSP (box)) | |
5545 break; | |
5546 value = XCAR (box); | |
5547 box = XCDR (box); | |
5548 | |
5549 if (EQ (keyword, QCline_width)) | |
5550 { | |
5551 if (INTEGERP (value) && XINT (value) > 0) | |
5552 face->box_line_width = XFASTINT (value); | |
5553 } | |
5554 else if (EQ (keyword, QCcolor)) | |
5555 { | |
5556 if (STRINGP (value)) | |
5557 { | |
5558 face->box_color = load_color (f, face, value, | |
5559 LFACE_BOX_INDEX); | |
5560 face->use_box_color_for_shadows_p = 1; | |
5561 } | |
5562 } | |
5563 else if (EQ (keyword, QCstyle)) | |
5564 { | |
5565 if (EQ (value, Qreleased_button)) | |
5566 face->box = FACE_RAISED_BOX; | |
5567 else if (EQ (value, Qpressed_button)) | |
5568 face->box = FACE_SUNKEN_BOX; | |
5569 } | |
5570 } | |
5571 } | |
5572 | |
5573 /* Text underline, overline, strike-through. */ | |
5574 | |
5575 if (EQ (attrs[LFACE_UNDERLINE_INDEX], Qt)) | |
5576 { | |
5577 /* Use default color (same as foreground color). */ | |
5578 face->underline_p = 1; | |
5579 face->underline_defaulted_p = 1; | |
5580 face->underline_color = 0; | |
5581 } | |
5582 else if (STRINGP (attrs[LFACE_UNDERLINE_INDEX])) | |
5583 { | |
5584 /* Use specified color. */ | |
5585 face->underline_p = 1; | |
5586 face->underline_defaulted_p = 0; | |
5587 face->underline_color | |
5588 = load_color (f, face, attrs[LFACE_UNDERLINE_INDEX], | |
5589 LFACE_UNDERLINE_INDEX); | |
5590 } | |
5591 else if (NILP (attrs[LFACE_UNDERLINE_INDEX])) | |
5592 { | |
5593 face->underline_p = 0; | |
5594 face->underline_defaulted_p = 0; | |
5595 face->underline_color = 0; | |
5596 } | |
5597 | |
5598 overline = attrs[LFACE_OVERLINE_INDEX]; | |
5599 if (STRINGP (overline)) | |
5600 { | |
5601 face->overline_color | |
5602 = load_color (f, face, attrs[LFACE_OVERLINE_INDEX], | |
5603 LFACE_OVERLINE_INDEX); | |
5604 face->overline_p = 1; | |
5605 } | |
5606 else if (EQ (overline, Qt)) | |
5607 { | |
5608 face->overline_color = face->foreground; | |
5609 face->overline_color_defaulted_p = 1; | |
5610 face->overline_p = 1; | |
5611 } | |
5612 | |
5613 strike_through = attrs[LFACE_STRIKE_THROUGH_INDEX]; | |
5614 if (STRINGP (strike_through)) | |
5615 { | |
5616 face->strike_through_color | |
5617 = load_color (f, face, attrs[LFACE_STRIKE_THROUGH_INDEX], | |
5618 LFACE_STRIKE_THROUGH_INDEX); | |
5619 face->strike_through_p = 1; | |
5620 } | |
5621 else if (EQ (strike_through, Qt)) | |
5622 { | |
5623 face->strike_through_color = face->foreground; | |
5624 face->strike_through_color_defaulted_p = 1; | |
5625 face->strike_through_p = 1; | |
5626 } | |
5627 | |
5628 stipple = attrs[LFACE_STIPPLE_INDEX]; | |
5629 if (!NILP (stipple)) | |
5630 face->stipple = load_pixmap (f, stipple, &face->pixmap_w, &face->pixmap_h); | |
5631 | |
5632 UNGCPRO; | |
5633 xassert (face->fontset < 0 || face->charset == CHARSET_COMPOSITION); | |
5634 xassert (FACE_SUITABLE_FOR_CHARSET_P (face, charset)); | |
5635 return face; | |
5636 #endif /* HAVE_X_WINDOWS */ | |
5637 } | |
5638 | |
5639 | |
5640 /* Realize the fully-specified face with attributes ATTRS in face | |
5641 cache C for character set CHARSET or for unibyte text if CHARSET < | |
5642 0. Do it for TTY frame C->f. Value is a pointer to the newly | |
5643 created realized face. */ | |
5644 | |
5645 static struct face * | |
5646 realize_tty_face (c, attrs, charset) | |
5647 struct face_cache *c; | |
5648 Lisp_Object *attrs; | |
5649 int charset; | |
5650 { | |
5651 struct face *face; | |
5652 int weight, slant; | |
5653 Lisp_Object color; | |
5654 | |
5655 /* Frame must be a termcap frame. */ | |
25114
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5656 xassert (FRAME_TERMCAP_P (c->f) || FRAME_MSDOS_P (c->f)); |
24995 | 5657 |
5658 /* Allocate a new realized face. */ | |
5659 face = make_realized_face (attrs, charset, Qnil); | |
25114
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5660 face->font_name = FRAME_MSDOS_P (c->f) ? "ms-dos" : "tty"; |
24995 | 5661 |
5662 /* Map face attributes to TTY appearances. We map slant to | |
5663 dimmed text because we want italic text to appear differently | |
5664 and because dimmed text is probably used infrequently. */ | |
5665 weight = face_numeric_weight (attrs[LFACE_WEIGHT_INDEX]); | |
5666 slant = face_numeric_slant (attrs[LFACE_SLANT_INDEX]); | |
5667 | |
5668 if (weight > XLFD_WEIGHT_MEDIUM) | |
5669 face->tty_bold_p = 1; | |
5670 if (weight < XLFD_WEIGHT_MEDIUM || slant != XLFD_SLANT_ROMAN) | |
5671 face->tty_dim_p = 1; | |
5672 if (!NILP (attrs[LFACE_UNDERLINE_INDEX])) | |
5673 face->tty_underline_p = 1; | |
5674 if (!NILP (attrs[LFACE_INVERSE_INDEX])) | |
5675 face->tty_reverse_p = 1; | |
5676 | |
5677 /* Map color names to color indices. */ | |
5678 face->foreground = face->background = FACE_TTY_DEFAULT_COLOR; | |
5679 | |
5680 color = attrs[LFACE_FOREGROUND_INDEX]; | |
5681 if (XSTRING (color)->size | |
5682 && (color = Fassoc (color, Vface_tty_color_alist), | |
5683 CONSP (color))) | |
5684 face->foreground = XINT (XCDR (color)); | |
5685 | |
25114
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5686 #ifdef MSDOS |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5687 if (FRAME_MSDOS_P (c->f) && face->foreground == FACE_TTY_DEFAULT_COLOR) |
25213
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5688 { |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5689 face->foreground = load_color (c->f, face, |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5690 attrs[LFACE_FOREGROUND_INDEX], |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5691 LFACE_FOREGROUND_INDEX); |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5692 /* If the foreground of the default face is the default color, |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5693 use the foreground color defined by the frame. */ |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5694 if (face->foreground == FACE_TTY_DEFAULT_COLOR) |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5695 { |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5696 face->foreground = FRAME_FOREGROUND_PIXEL (f); |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5697 attrs[LFACE_FOREGROUND_INDEX] = |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5698 build_string (msdos_stdcolor_name (face->foreground)); |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5699 } |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5700 } |
25114
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5701 #endif |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5702 |
24995 | 5703 color = attrs[LFACE_BACKGROUND_INDEX]; |
5704 if (XSTRING (color)->size | |
5705 && (color = Fassoc (color, Vface_tty_color_alist), | |
5706 CONSP (color))) | |
5707 face->background = XINT (XCDR (color)); | |
5708 | |
25114
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5709 #ifdef MSDOS |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5710 if (FRAME_MSDOS_P (c->f) && face->background == FACE_TTY_DEFAULT_COLOR) |
25213
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5711 { |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5712 face->background = load_color (c->f, face, |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5713 attrs[LFACE_BACKGROUND_INDEX], |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5714 LFACE_BACKGROUND_INDEX); |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5715 /* If the background of the default face is the default color, |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5716 use the background color defined by the frame. */ |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5717 if (face->background == FACE_TTY_DEFAULT_COLOR) |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5718 { |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5719 face->background = FRAME_BACKGROUND_PIXEL (f); |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5720 attrs[LFACE_BACKGROUND_INDEX] = |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5721 build_string (msdos_stdcolor_name (face->background)); |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5722 } |
11d01c90da6d
(realize_default_face) [MSDOS]: Don't take default
Eli Zaretskii <eliz@gnu.org>
parents:
25114
diff
changeset
|
5723 } |
25114
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5724 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5725 /* Swap colors if face is inverse-video. */ |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5726 if (face->tty_reverse_p) |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5727 { |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5728 unsigned long tem = face->foreground; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5729 |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5730 face->foreground = face->background; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5731 face->background = tem; |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5732 } |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5733 #endif |
be5d3e21fbd7
(load_color): Remove static from definition and remove
Eli Zaretskii <eliz@gnu.org>
parents:
25092
diff
changeset
|
5734 |
24995 | 5735 return face; |
5736 } | |
5737 | |
5738 | |
5739 DEFUN ("face-register-tty-color", Fface_register_tty_color, | |
5740 Sface_register_tty_color, 2, 2, 0, | |
5741 "Say that COLOR is color number NUMBER on the terminal.\n\ | |
5742 COLOR is a string, the color name. Value is COLOR.") | |
5743 (color, number) | |
5744 Lisp_Object color, number; | |
5745 { | |
5746 Lisp_Object entry; | |
5747 | |
5748 CHECK_STRING (color, 0); | |
5749 CHECK_NUMBER (number, 1); | |
5750 entry = Fassoc (color, Vface_tty_color_alist); | |
5751 if (NILP (entry)) | |
5752 Vface_tty_color_alist = Fcons (Fcons (color, number), | |
5753 Vface_tty_color_alist); | |
5754 else | |
5755 Fsetcdr (entry, number); | |
5756 return color; | |
5757 } | |
5758 | |
5759 | |
5760 DEFUN ("face-clear-tty-colors", Fface_clear_tty_colors, | |
5761 Sface_clear_tty_colors, 0, 0, 0, | |
5762 "Unregister all registered tty colors.") | |
5763 () | |
5764 { | |
5765 return Vface_tty_color_alist = Qnil; | |
5766 } | |
5767 | |
5768 | |
5769 DEFUN ("tty-defined-colors", Ftty_defined_colors, | |
5770 Stty_defined_colors, 0, 0, 0, | |
5771 "Return a list of registered tty colors.") | |
5772 () | |
5773 { | |
5774 Lisp_Object list, colors; | |
5775 | |
5776 colors = Qnil; | |
5777 for (list = Vface_tty_color_alist; CONSP (list); list = XCDR (list)) | |
5778 colors = Fcons (XCAR (XCAR (list)), colors); | |
5779 | |
5780 return colors; | |
5781 } | |
5782 | |
5783 | |
5784 | |
5785 /*********************************************************************** | |
5786 Computing Faces | |
5787 ***********************************************************************/ | |
5788 | |
5789 /* Return the ID of the face to use to display character CH with face | |
5790 property PROP on frame F in current_buffer. */ | |
5791 | |
5792 int | |
5793 compute_char_face (f, ch, prop) | |
5794 struct frame *f; | |
5795 int ch; | |
5796 Lisp_Object prop; | |
5797 { | |
5798 int face_id; | |
5799 int charset = (NILP (current_buffer->enable_multibyte_characters) | |
5800 ? -1 | |
5801 : CHAR_CHARSET (ch)); | |
5802 | |
5803 if (NILP (prop)) | |
5804 face_id = FACE_FOR_CHARSET (f, DEFAULT_FACE_ID, charset); | |
5805 else | |
5806 { | |
5807 Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
5808 struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); | |
5809 bcopy (default_face->lface, attrs, sizeof attrs); | |
5810 merge_face_vector_with_property (f, attrs, prop); | |
5811 face_id = lookup_face (f, attrs, charset); | |
5812 } | |
5813 | |
5814 return face_id; | |
5815 } | |
5816 | |
5817 | |
5818 /* Return the face ID associated with buffer position POS for | |
5819 displaying ASCII characters. Return in *ENDPTR the position at | |
5820 which a different face is needed, as far as text properties and | |
5821 overlays are concerned. W is a window displaying current_buffer. | |
5822 | |
5823 REGION_BEG, REGION_END delimit the region, so it can be | |
5824 highlighted. | |
5825 | |
5826 LIMIT is a position not to scan beyond. That is to limit the time | |
5827 this function can take. | |
5828 | |
5829 If MOUSE is non-zero, use the character's mouse-face, not its face. | |
5830 | |
5831 The face returned is suitable for displaying CHARSET_ASCII if | |
5832 current_buffer->enable_multibyte_characters is non-nil. Otherwise, | |
5833 the face is suitable for displaying unibyte text. */ | |
5834 | |
5835 int | |
5836 face_at_buffer_position (w, pos, region_beg, region_end, | |
5837 endptr, limit, mouse) | |
2391 | 5838 struct window *w; |
2342 | 5839 int pos; |
2795
e97e96fb0cb8
(compute_char_face): New args REGION_BEG, REGION_END.
Richard M. Stallman <rms@gnu.org>
parents:
2784
diff
changeset
|
5840 int region_beg, region_end; |
2342 | 5841 int *endptr; |
5084
863e092a5891
(compute_char_face): Accept new arg LIMIT.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
5842 int limit; |
6615
96ddf85642d1
(compute_char_face): New arg MOUSE.
Richard M. Stallman <rms@gnu.org>
parents:
5858
diff
changeset
|
5843 int mouse; |
2342 | 5844 { |
24995 | 5845 struct frame *f = XFRAME (w->frame); |
5846 Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
2767
482fa0725db6
* xfaces.c (intern_frame_face): Exchange order of arguments, to
Jim Blandy <jimb@redhat.com>
parents:
2743
diff
changeset
|
5847 Lisp_Object prop, position; |
24995 | 5848 int i, noverlays; |
2342 | 5849 Lisp_Object *overlay_vec; |
2391 | 5850 Lisp_Object frame; |
2784
f8c6796b7777
* xfaces.c (compute_char_face): When merging the overlays,
Jim Blandy <jimb@redhat.com>
parents:
2767
diff
changeset
|
5851 int endpos; |
24995 | 5852 Lisp_Object propname = mouse ? Qmouse_face : Qface; |
5853 Lisp_Object limit1, end; | |
5854 struct face *default_face; | |
5855 int multibyte_p = !NILP (current_buffer->enable_multibyte_characters); | |
2784
f8c6796b7777
* xfaces.c (compute_char_face): When merging the overlays,
Jim Blandy <jimb@redhat.com>
parents:
2767
diff
changeset
|
5856 |
f8c6796b7777
* xfaces.c (compute_char_face): When merging the overlays,
Jim Blandy <jimb@redhat.com>
parents:
2767
diff
changeset
|
5857 /* W must display the current buffer. We could write this function |
f8c6796b7777
* xfaces.c (compute_char_face): When merging the overlays,
Jim Blandy <jimb@redhat.com>
parents:
2767
diff
changeset
|
5858 to use the frame and buffer of W, but right now it doesn't. */ |
24995 | 5859 xassert (XBUFFER (w->buffer) == current_buffer); |
2391 | 5860 |
9284
a969e0eefaf5
(compute_char_face): Use new accessor macros instead of calling XSET directly.
Karl Heuer <kwzh@gnu.org>
parents:
9186
diff
changeset
|
5861 XSETFRAME (frame, f); |
24995 | 5862 XSETFASTINT (position, pos); |
2342 | 5863 |
2784
f8c6796b7777
* xfaces.c (compute_char_face): When merging the overlays,
Jim Blandy <jimb@redhat.com>
parents:
2767
diff
changeset
|
5864 endpos = ZV; |
2795
e97e96fb0cb8
(compute_char_face): New args REGION_BEG, REGION_END.
Richard M. Stallman <rms@gnu.org>
parents:
2784
diff
changeset
|
5865 if (pos < region_beg && region_beg < endpos) |
e97e96fb0cb8
(compute_char_face): New args REGION_BEG, REGION_END.
Richard M. Stallman <rms@gnu.org>
parents:
2784
diff
changeset
|
5866 endpos = region_beg; |
2784
f8c6796b7777
* xfaces.c (compute_char_face): When merging the overlays,
Jim Blandy <jimb@redhat.com>
parents:
2767
diff
changeset
|
5867 |
24995 | 5868 /* Get the `face' or `mouse_face' text property at POS, and |
5869 determine the next position at which the property changes. */ | |
6615
96ddf85642d1
(compute_char_face): New arg MOUSE.
Richard M. Stallman <rms@gnu.org>
parents:
5858
diff
changeset
|
5870 prop = Fget_text_property (position, propname, w->buffer); |
24995 | 5871 XSETFASTINT (limit1, (limit < endpos ? limit : endpos)); |
5872 end = Fnext_single_property_change (position, propname, w->buffer, limit1); | |
5873 if (INTEGERP (end)) | |
5874 endpos = XINT (end); | |
5875 | |
5876 /* Look at properties from overlays. */ | |
2767
482fa0725db6
* xfaces.c (intern_frame_face): Exchange order of arguments, to
Jim Blandy <jimb@redhat.com>
parents:
2743
diff
changeset
|
5877 { |
2784
f8c6796b7777
* xfaces.c (compute_char_face): When merging the overlays,
Jim Blandy <jimb@redhat.com>
parents:
2767
diff
changeset
|
5878 int next_overlay; |
2838
5f6a2d52d2ef
(compute_char_face): Pass 0 as EXTEND arg to overlays_at.
Richard M. Stallman <rms@gnu.org>
parents:
2821
diff
changeset
|
5879 int len; |
2767
482fa0725db6
* xfaces.c (intern_frame_face): Exchange order of arguments, to
Jim Blandy <jimb@redhat.com>
parents:
2743
diff
changeset
|
5880 |
2838
5f6a2d52d2ef
(compute_char_face): Pass 0 as EXTEND arg to overlays_at.
Richard M. Stallman <rms@gnu.org>
parents:
2821
diff
changeset
|
5881 /* First try with room for 40 overlays. */ |
5f6a2d52d2ef
(compute_char_face): Pass 0 as EXTEND arg to overlays_at.
Richard M. Stallman <rms@gnu.org>
parents:
2821
diff
changeset
|
5882 len = 40; |
5f6a2d52d2ef
(compute_char_face): Pass 0 as EXTEND arg to overlays_at.
Richard M. Stallman <rms@gnu.org>
parents:
2821
diff
changeset
|
5883 overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); |
11420
8ab99c3646a7
(compute_char_face): Don't use NULL.
Richard M. Stallman <rms@gnu.org>
parents:
11416
diff
changeset
|
5884 noverlays = overlays_at (pos, 0, &overlay_vec, &len, |
24995 | 5885 &next_overlay, NULL); |
5886 | |
5887 /* If there are more than 40, make enough space for all, and try | |
5888 again. */ | |
2838
5f6a2d52d2ef
(compute_char_face): Pass 0 as EXTEND arg to overlays_at.
Richard M. Stallman <rms@gnu.org>
parents:
2821
diff
changeset
|
5889 if (noverlays > len) |
5f6a2d52d2ef
(compute_char_face): Pass 0 as EXTEND arg to overlays_at.
Richard M. Stallman <rms@gnu.org>
parents:
2821
diff
changeset
|
5890 { |
5f6a2d52d2ef
(compute_char_face): Pass 0 as EXTEND arg to overlays_at.
Richard M. Stallman <rms@gnu.org>
parents:
2821
diff
changeset
|
5891 len = noverlays; |
5f6a2d52d2ef
(compute_char_face): Pass 0 as EXTEND arg to overlays_at.
Richard M. Stallman <rms@gnu.org>
parents:
2821
diff
changeset
|
5892 overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); |
8965
a7947f88d558
(compute_char_face): Pass new arg to overlays_at.
Richard M. Stallman <rms@gnu.org>
parents:
8848
diff
changeset
|
5893 noverlays = overlays_at (pos, 0, &overlay_vec, &len, |
24995 | 5894 &next_overlay, NULL); |
2838
5f6a2d52d2ef
(compute_char_face): Pass 0 as EXTEND arg to overlays_at.
Richard M. Stallman <rms@gnu.org>
parents:
2821
diff
changeset
|
5895 } |
5f6a2d52d2ef
(compute_char_face): Pass 0 as EXTEND arg to overlays_at.
Richard M. Stallman <rms@gnu.org>
parents:
2821
diff
changeset
|
5896 |
2784
f8c6796b7777
* xfaces.c (compute_char_face): When merging the overlays,
Jim Blandy <jimb@redhat.com>
parents:
2767
diff
changeset
|
5897 if (next_overlay < endpos) |
f8c6796b7777
* xfaces.c (compute_char_face): When merging the overlays,
Jim Blandy <jimb@redhat.com>
parents:
2767
diff
changeset
|
5898 endpos = next_overlay; |
2767
482fa0725db6
* xfaces.c (intern_frame_face): Exchange order of arguments, to
Jim Blandy <jimb@redhat.com>
parents:
2743
diff
changeset
|
5899 } |
482fa0725db6
* xfaces.c (intern_frame_face): Exchange order of arguments, to
Jim Blandy <jimb@redhat.com>
parents:
2743
diff
changeset
|
5900 |
482fa0725db6
* xfaces.c (intern_frame_face): Exchange order of arguments, to
Jim Blandy <jimb@redhat.com>
parents:
2743
diff
changeset
|
5901 *endptr = endpos; |
2342 | 5902 |
24995 | 5903 default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); |
5904 | |
5905 /* Optimize common cases where we can use the default face. */ | |
5906 if (noverlays == 0 | |
5907 && NILP (prop) | |
5908 && !(pos >= region_beg && pos < region_end) | |
5909 && (multibyte_p | |
5910 || !FRAME_WINDOW_P (f) | |
5911 || FACE_SUITABLE_FOR_CHARSET_P (default_face, -1))) | |
5912 return DEFAULT_FACE_ID; | |
5913 | |
5914 /* Begin with attributes from the default face. */ | |
5915 bcopy (default_face->lface, attrs, sizeof attrs); | |
5916 | |
5917 /* Merge in attributes specified via text properties. */ | |
5918 if (!NILP (prop)) | |
5919 merge_face_vector_with_property (f, attrs, prop); | |
5920 | |
5921 /* Now merge the overlay data. */ | |
5858
021e58905963
(compute_char_face): Extract overlay-sorting code as a separate function,
Karl Heuer <kwzh@gnu.org>
parents:
5801
diff
changeset
|
5922 noverlays = sort_overlays (overlay_vec, noverlays, w); |
2342 | 5923 for (i = 0; i < noverlays; i++) |
5924 { | |
19128
e789b647f15b
(merge_face_list): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18723
diff
changeset
|
5925 Lisp_Object oend; |
e789b647f15b
(merge_face_list): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18723
diff
changeset
|
5926 int oendpos; |
9186
45bac5feb065
(compute_char_face): Handle list as overlay face property.
Richard M. Stallman <rms@gnu.org>
parents:
9184
diff
changeset
|
5927 |
19128
e789b647f15b
(merge_face_list): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18723
diff
changeset
|
5928 prop = Foverlay_get (overlay_vec[i], propname); |
24995 | 5929 if (!NILP (prop)) |
5930 merge_face_vector_with_property (f, attrs, prop); | |
2342 | 5931 |
19128
e789b647f15b
(merge_face_list): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18723
diff
changeset
|
5932 oend = OVERLAY_END (overlay_vec[i]); |
e789b647f15b
(merge_face_list): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18723
diff
changeset
|
5933 oendpos = OVERLAY_POSITION (oend); |
e789b647f15b
(merge_face_list): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18723
diff
changeset
|
5934 if (oendpos < endpos) |
e789b647f15b
(merge_face_list): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18723
diff
changeset
|
5935 endpos = oendpos; |
2342 | 5936 } |
5937 | |
24995 | 5938 /* If in the region, merge in the region face. */ |
2795
e97e96fb0cb8
(compute_char_face): New args REGION_BEG, REGION_END.
Richard M. Stallman <rms@gnu.org>
parents:
2784
diff
changeset
|
5939 if (pos >= region_beg && pos < region_end) |
e97e96fb0cb8
(compute_char_face): New args REGION_BEG, REGION_END.
Richard M. Stallman <rms@gnu.org>
parents:
2784
diff
changeset
|
5940 { |
24995 | 5941 Lisp_Object region_face = lface_from_face_name (f, Qregion, 0); |
5942 merge_face_vectors (XVECTOR (region_face)->contents, attrs); | |
5943 | |
2795
e97e96fb0cb8
(compute_char_face): New args REGION_BEG, REGION_END.
Richard M. Stallman <rms@gnu.org>
parents:
2784
diff
changeset
|
5944 if (region_end < endpos) |
e97e96fb0cb8
(compute_char_face): New args REGION_BEG, REGION_END.
Richard M. Stallman <rms@gnu.org>
parents:
2784
diff
changeset
|
5945 endpos = region_end; |
e97e96fb0cb8
(compute_char_face): New args REGION_BEG, REGION_END.
Richard M. Stallman <rms@gnu.org>
parents:
2784
diff
changeset
|
5946 } |
e97e96fb0cb8
(compute_char_face): New args REGION_BEG, REGION_END.
Richard M. Stallman <rms@gnu.org>
parents:
2784
diff
changeset
|
5947 |
2342 | 5948 *endptr = endpos; |
5949 | |
24995 | 5950 /* Look up a realized face with the given face attributes, |
5951 or realize a new one. Charset is ignored for tty frames. */ | |
5952 return lookup_face (f, attrs, multibyte_p ? CHARSET_ASCII : -1); | |
2342 | 5953 } |
19128
e789b647f15b
(merge_face_list): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18723
diff
changeset
|
5954 |
24995 | 5955 |
5956 /* Compute the face at character position POS in Lisp string STRING on | |
5957 window W, for charset CHARSET_ASCII. | |
5958 | |
5959 If STRING is an overlay string, it comes from position BUFPOS in | |
5960 current_buffer, otherwise BUFPOS is zero to indicate that STRING is | |
5961 not an overlay string. W must display the current buffer. | |
5962 REGION_BEG and REGION_END give the start and end positions of the | |
5963 region; both are -1 if no region is visible. BASE_FACE_ID is the | |
5964 id of the basic face to merge with. It is usually equal to | |
5965 DEFAULT_FACE_ID but can be MODE_LINE_FACE_ID or TOP_LINE_FACE_ID | |
5966 for strings displayed in the mode or top line. | |
5967 | |
5968 Set *ENDPTR to the next position where to check for faces in | |
5969 STRING; -1 if the face is constant from POS to the end of the | |
5970 string. | |
5971 | |
5972 Value is the id of the face to use. The face returned is suitable | |
5973 for displaying CHARSET_ASCII if STRING is multibyte. Otherwise, | |
5974 the face is suitable for displaying unibyte text. */ | |
5975 | |
5976 int | |
5977 face_at_string_position (w, string, pos, bufpos, region_beg, | |
5978 region_end, endptr, base_face_id) | |
5979 struct window *w; | |
5980 Lisp_Object string; | |
5981 int pos, bufpos; | |
5982 int region_beg, region_end; | |
5983 int *endptr; | |
5984 enum face_id base_face_id; | |
19128
e789b647f15b
(merge_face_list): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18723
diff
changeset
|
5985 { |
24995 | 5986 Lisp_Object prop, position, end, limit; |
5987 struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
5988 Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
5989 struct face *base_face; | |
5990 int multibyte_p = STRING_MULTIBYTE (string); | |
5991 | |
5992 /* Get the value of the face property at the current position within | |
5993 STRING. Value is nil if there is no face property. */ | |
5994 XSETFASTINT (position, pos); | |
5995 prop = Fget_text_property (position, Qface, string); | |
5996 | |
5997 /* Get the next position at which to check for faces. Value of end | |
5998 is nil if face is constant all the way to the end of the string. | |
5999 Otherwise it is a string position where to check faces next. | |
6000 Limit is the maximum position up to which to check for property | |
6001 changes in Fnext_single_property_change. Strings are usually | |
6002 short, so set the limit to the end of the string. */ | |
6003 XSETFASTINT (limit, XSTRING (string)->size); | |
6004 end = Fnext_single_property_change (position, Qface, string, limit); | |
6005 if (INTEGERP (end)) | |
6006 *endptr = XFASTINT (end); | |
19128
e789b647f15b
(merge_face_list): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18723
diff
changeset
|
6007 else |
24995 | 6008 *endptr = -1; |
6009 | |
6010 base_face = FACE_FROM_ID (f, base_face_id); | |
6011 xassert (base_face); | |
6012 | |
6013 /* Optimize the default case that there is no face property and we | |
6014 are not in the region. */ | |
6015 if (NILP (prop) | |
6016 && (base_face_id != DEFAULT_FACE_ID | |
6017 /* BUFPOS <= 0 means STRING is not an overlay string, so | |
6018 that the region doesn't have to be taken into account. */ | |
6019 || bufpos <= 0 | |
6020 || bufpos < region_beg | |
6021 || bufpos >= region_end) | |
6022 && (multibyte_p | |
6023 /* We can't realize faces for different charsets differently | |
6024 if we don't have fonts, so we can stop here if not working | |
6025 on a window-system frame. */ | |
6026 || !FRAME_WINDOW_P (f) | |
6027 || FACE_SUITABLE_FOR_CHARSET_P (base_face, -1))) | |
6028 return base_face->id; | |
6029 | |
6030 /* Begin with attributes from the base face. */ | |
6031 bcopy (base_face->lface, attrs, sizeof attrs); | |
6032 | |
6033 /* Merge in attributes specified via text properties. */ | |
6034 if (!NILP (prop)) | |
6035 merge_face_vector_with_property (f, attrs, prop); | |
6036 | |
6037 /* If in the region, merge in the region face. */ | |
6038 if (bufpos | |
6039 && bufpos >= region_beg | |
6040 && bufpos < region_end) | |
19128
e789b647f15b
(merge_face_list): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18723
diff
changeset
|
6041 { |
24995 | 6042 Lisp_Object region_face = lface_from_face_name (f, Qregion, 0); |
6043 merge_face_vectors (XVECTOR (region_face)->contents, attrs); | |
19128
e789b647f15b
(merge_face_list): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18723
diff
changeset
|
6044 } |
24995 | 6045 |
6046 /* Look up a realized face with the given face attributes, | |
6047 or realize a new one. */ | |
6048 return lookup_face (f, attrs, multibyte_p ? CHARSET_ASCII : -1); | |
3074
96b4623fdeb3
* xterm.h: New section for declarations for xfaces.c.
Jim Blandy <jimb@redhat.com>
parents:
3065
diff
changeset
|
6049 } |
96b4623fdeb3
* xterm.h: New section for declarations for xfaces.c.
Jim Blandy <jimb@redhat.com>
parents:
3065
diff
changeset
|
6050 |
96b4623fdeb3
* xterm.h: New section for declarations for xfaces.c.
Jim Blandy <jimb@redhat.com>
parents:
3065
diff
changeset
|
6051 |
2336 | 6052 |
24995 | 6053 /*********************************************************************** |
6054 Tests | |
6055 ***********************************************************************/ | |
6056 | |
6057 #if GLYPH_DEBUG | |
6058 | |
6059 /* Print the contents of the realized face FACE to stderr. */ | |
6060 | |
6061 static void | |
6062 dump_realized_face (face) | |
6063 struct face *face; | |
2336 | 6064 { |
24995 | 6065 fprintf (stderr, "ID: %d\n", face->id); |
6066 #ifdef HAVE_X_WINDOWS | |
6067 fprintf (stderr, "gc: %d\n", (int) face->gc); | |
6068 #endif | |
6069 fprintf (stderr, "foreground: 0x%lx (%s)\n", | |
6070 face->foreground, | |
6071 XSTRING (face->lface[LFACE_FOREGROUND_INDEX])->data); | |
6072 fprintf (stderr, "background: 0x%lx (%s)\n", | |
6073 face->background, | |
6074 XSTRING (face->lface[LFACE_BACKGROUND_INDEX])->data); | |
6075 fprintf (stderr, "font_name: %s (%s)\n", | |
6076 face->font_name, | |
6077 XSTRING (face->lface[LFACE_FAMILY_INDEX])->data); | |
6078 #ifdef HAVE_X_WINDOWS | |
6079 fprintf (stderr, "font = %p\n", face->font); | |
6080 #endif | |
6081 fprintf (stderr, "font_info_id = %d\n", face->font_info_id); | |
6082 fprintf (stderr, "fontset: %d\n", face->fontset); | |
6083 fprintf (stderr, "underline: %d (%s)\n", | |
6084 face->underline_p, | |
6085 XSTRING (Fsymbol_name (face->lface[LFACE_UNDERLINE_INDEX]))->data); | |
6086 fprintf (stderr, "hash: %d\n", face->hash); | |
6087 fprintf (stderr, "charset: %d\n", face->charset); | |
6088 } | |
6089 | |
6090 | |
6091 DEFUN ("dump-face", Fdump_face, Sdump_face, 0, 1, 0, "") | |
6092 (n) | |
6093 Lisp_Object n; | |
6094 { | |
6095 if (NILP (n)) | |
2336 | 6096 { |
24995 | 6097 int i; |
6098 | |
6099 fprintf (stderr, "font selection order: "); | |
6100 for (i = 0; i < DIM (font_sort_order); ++i) | |
6101 fprintf (stderr, "%d ", font_sort_order[i]); | |
6102 fprintf (stderr, "\n"); | |
6103 | |
6104 fprintf (stderr, "alternative fonts: "); | |
6105 debug_print (Vface_alternative_font_family_alist); | |
6106 fprintf (stderr, "\n"); | |
6107 | |
6108 for (i = 0; i < FRAME_FACE_CACHE (selected_frame)->used; ++i) | |
6109 Fdump_face (make_number (i)); | |
2336 | 6110 } |
24995 | 6111 else |
6112 { | |
6113 struct face *face; | |
6114 CHECK_NUMBER (n, 0); | |
6115 face = FACE_FROM_ID (selected_frame, XINT (n)); | |
6116 if (face == NULL) | |
6117 error ("Not a valid face"); | |
6118 dump_realized_face (face); | |
6119 } | |
6120 | |
2336 | 6121 return Qnil; |
6122 } | |
6123 | |
6124 | |
24995 | 6125 DEFUN ("show-face-resources", Fshow_face_resources, Sshow_face_resources, |
6126 0, 0, 0, "") | |
6127 () | |
2336 | 6128 { |
24995 | 6129 fprintf (stderr, "number of colors = %d\n", ncolors_allocated); |
6130 fprintf (stderr, "number of pixmaps = %d\n", npixmaps_allocated); | |
6131 fprintf (stderr, "number of GCs = %d\n", ngcs); | |
2336 | 6132 return Qnil; |
6133 } | |
24995 | 6134 |
6135 #endif /* GLYPH_DEBUG != 0 */ | |
6136 | |
18083
c361afa561c5
Include frame.h unconditionally.
Richard M. Stallman <rms@gnu.org>
parents:
17047
diff
changeset
|
6137 |
c361afa561c5
Include frame.h unconditionally.
Richard M. Stallman <rms@gnu.org>
parents:
17047
diff
changeset
|
6138 |
24995 | 6139 /*********************************************************************** |
6140 Initialization | |
6141 ***********************************************************************/ | |
2730
139740855fa6
* xfaces.c (Fmake_face_internal): Do nothing for non-X frames.
Jim Blandy <jimb@redhat.com>
parents:
2538
diff
changeset
|
6142 |
2336 | 6143 void |
2391 | 6144 syms_of_xfaces () |
2336 | 6145 { |
2391 | 6146 Qface = intern ("face"); |
6147 staticpro (&Qface); | |
9564
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
6148 Qpixmap_spec_p = intern ("pixmap-spec-p"); |
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
6149 staticpro (&Qpixmap_spec_p); |
2391 | 6150 |
24995 | 6151 /* Lisp face attribute keywords. */ |
6152 QCfamily = intern (":family"); | |
6153 staticpro (&QCfamily); | |
6154 QCheight = intern (":height"); | |
6155 staticpro (&QCheight); | |
6156 QCweight = intern (":weight"); | |
6157 staticpro (&QCweight); | |
6158 QCslant = intern (":slant"); | |
6159 staticpro (&QCslant); | |
6160 QCunderline = intern (":underline"); | |
6161 staticpro (&QCunderline); | |
6162 QCinverse_video = intern (":inverse-video"); | |
6163 staticpro (&QCinverse_video); | |
6164 QCreverse_video = intern (":reverse-video"); | |
6165 staticpro (&QCreverse_video); | |
6166 QCforeground = intern (":foreground"); | |
6167 staticpro (&QCforeground); | |
6168 QCbackground = intern (":background"); | |
6169 staticpro (&QCbackground); | |
6170 QCstipple = intern (":stipple");; | |
6171 staticpro (&QCstipple); | |
6172 QCwidth = intern (":width"); | |
6173 staticpro (&QCwidth); | |
6174 QCfont = intern (":font"); | |
6175 staticpro (&QCfont); | |
6176 QCbold = intern (":bold"); | |
6177 staticpro (&QCbold); | |
6178 QCitalic = intern (":italic"); | |
6179 staticpro (&QCitalic); | |
6180 QCoverline = intern (":overline"); | |
6181 staticpro (&QCoverline); | |
6182 QCstrike_through = intern (":strike-through"); | |
6183 staticpro (&QCstrike_through); | |
6184 QCbox = intern (":box"); | |
6185 staticpro (&QCbox); | |
6186 | |
6187 /* Symbols used for Lisp face attribute values. */ | |
6188 QCcolor = intern (":color"); | |
6189 staticpro (&QCcolor); | |
6190 QCline_width = intern (":line-width"); | |
6191 staticpro (&QCline_width); | |
6192 QCstyle = intern (":style"); | |
6193 staticpro (&QCstyle); | |
6194 Qreleased_button = intern ("released-button"); | |
6195 staticpro (&Qreleased_button); | |
6196 Qpressed_button = intern ("pressed-button"); | |
6197 staticpro (&Qpressed_button); | |
6198 Qnormal = intern ("normal"); | |
6199 staticpro (&Qnormal); | |
6200 Qultra_light = intern ("ultra-light"); | |
6201 staticpro (&Qultra_light); | |
6202 Qextra_light = intern ("extra-light"); | |
6203 staticpro (&Qextra_light); | |
6204 Qlight = intern ("light"); | |
6205 staticpro (&Qlight); | |
6206 Qsemi_light = intern ("semi-light"); | |
6207 staticpro (&Qsemi_light); | |
6208 Qsemi_bold = intern ("semi-bold"); | |
6209 staticpro (&Qsemi_bold); | |
6210 Qbold = intern ("bold"); | |
6211 staticpro (&Qbold); | |
6212 Qextra_bold = intern ("extra-bold"); | |
6213 staticpro (&Qextra_bold); | |
6214 Qultra_bold = intern ("ultra-bold"); | |
6215 staticpro (&Qultra_bold); | |
6216 Qoblique = intern ("oblique"); | |
6217 staticpro (&Qoblique); | |
6218 Qitalic = intern ("italic"); | |
6219 staticpro (&Qitalic); | |
6220 Qreverse_oblique = intern ("reverse-oblique"); | |
6221 staticpro (&Qreverse_oblique); | |
6222 Qreverse_italic = intern ("reverse-italic"); | |
6223 staticpro (&Qreverse_italic); | |
6224 Qultra_condensed = intern ("ultra-condensed"); | |
6225 staticpro (&Qultra_condensed); | |
6226 Qextra_condensed = intern ("extra-condensed"); | |
6227 staticpro (&Qextra_condensed); | |
6228 Qcondensed = intern ("condensed"); | |
6229 staticpro (&Qcondensed); | |
6230 Qsemi_condensed = intern ("semi-condensed"); | |
6231 staticpro (&Qsemi_condensed); | |
6232 Qsemi_expanded = intern ("semi-expanded"); | |
6233 staticpro (&Qsemi_expanded); | |
6234 Qexpanded = intern ("expanded"); | |
6235 staticpro (&Qexpanded); | |
6236 Qextra_expanded = intern ("extra-expanded"); | |
6237 staticpro (&Qextra_expanded); | |
6238 Qultra_expanded = intern ("ultra-expanded"); | |
6239 staticpro (&Qultra_expanded); | |
6240 Qbackground_color = intern ("background-color"); | |
6241 staticpro (&Qbackground_color); | |
6242 Qforeground_color = intern ("foreground-color"); | |
6243 staticpro (&Qforeground_color); | |
6244 Qunspecified = intern ("unspecified"); | |
6245 staticpro (&Qunspecified); | |
6246 | |
6247 Qx_charset_registry = intern ("x-charset-registry"); | |
6248 staticpro (&Qx_charset_registry); | |
6249 Qdefault = intern ("default"); | |
6250 staticpro (&Qdefault); | |
6251 Qmodeline = intern ("modeline"); | |
6252 staticpro (&Qmodeline); | |
6253 Qtoolbar = intern ("toolbar"); | |
6254 staticpro (&Qtoolbar); | |
6255 Qregion = intern ("region"); | |
6256 staticpro (&Qregion); | |
6257 Qbitmap_area = intern ("bitmap-area"); | |
6258 staticpro (&Qbitmap_area); | |
6259 Qtop_line = intern ("top-line"); | |
6260 staticpro (&Qtop_line); | |
6261 | |
6262 defsubr (&Sinternal_make_lisp_face); | |
6263 defsubr (&Sinternal_lisp_face_p); | |
6264 defsubr (&Sinternal_set_lisp_face_attribute); | |
6265 #ifdef HAVE_X_WINDOWS | |
6266 defsubr (&Sinternal_set_lisp_face_attribute_from_resource); | |
6267 defsubr (&Sface_color_gray_p); | |
6268 defsubr (&Sface_color_supported_p); | |
6269 #endif | |
6270 defsubr (&Sinternal_get_lisp_face_attribute); | |
6271 defsubr (&Sinternal_lisp_face_attribute_values); | |
6272 defsubr (&Sinternal_lisp_face_equal_p); | |
6273 defsubr (&Sinternal_lisp_face_empty_p); | |
6274 defsubr (&Sinternal_copy_lisp_face); | |
6275 defsubr (&Sinternal_merge_in_global_face); | |
6276 defsubr (&Sface_font); | |
6277 defsubr (&Sframe_face_alist); | |
6278 defsubr (&Sinternal_set_font_selection_order); | |
6279 defsubr (&Sinternal_set_alternative_font_family_alist); | |
6280 #if GLYPH_DEBUG | |
6281 defsubr (&Sdump_face); | |
6282 defsubr (&Sshow_face_resources); | |
6283 #endif /* GLYPH_DEBUG */ | |
6284 defsubr (&Sclear_face_cache); | |
6285 | |
25270 | 6286 DEFVAR_LISP ("font-list-limit", &Vfont_list_limit, |
6287 "*Limit for font matching.\n\ | |
6288 If an integer > 0, font matching functions won't load more than\n\ | |
6289 that number of fonts when searching for a matching font."); | |
6290 Vfont_list_limit = make_number (DEFAULT_FONT_LIST_LIMIT); | |
6291 | |
24995 | 6292 DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults, |
6293 "List of global face definitions (for internal use only.)"); | |
6294 Vface_new_frame_defaults = Qnil; | |
6295 | |
6296 DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple, | |
6297 "*Default stipple pattern used on monochrome displays.\n\ | |
6298 This stipple pattern is used on monochrome displays\n\ | |
6299 instead of shades of gray for a face background color.\n\ | |
6300 See `set-face-stipple' for possible values for this variable."); | |
6301 Vface_default_stipple = build_string ("gray3"); | |
6302 | |
6303 DEFVAR_LISP ("face-default-registry", &Vface_default_registry, | |
6304 "Default registry and encoding to use.\n\ | |
6305 This registry and encoding is used for unibyte text. It is set up\n\ | |
6306 from the specified frame font when Emacs starts. (For internal use only.)"); | |
6307 Vface_default_registry = Qnil; | |
6308 | |
6309 DEFVAR_LISP ("face-alternative-font-family-alist", | |
6310 &Vface_alternative_font_family_alist, ""); | |
6311 Vface_alternative_font_family_alist = Qnil; | |
6312 | |
6313 #if SCALABLE_FONTS | |
6314 | |
6315 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed, | |
6316 "Allowed scalable fonts.\n\ | |
6317 A value of nil means don't allow any scalable fonts.\n\ | |
6318 A value of t means allow any scalable font.\n\ | |
6319 Otherwise, value must be a list of regular expressions. A font may be\n\ | |
6320 scaled if its name matches a regular expression in the list."); | |
6321 Vscalable_fonts_allowed = Qnil; | |
6322 | |
6323 #endif /* SCALABLE_FONTS */ | |
18083
c361afa561c5
Include frame.h unconditionally.
Richard M. Stallman <rms@gnu.org>
parents:
17047
diff
changeset
|
6324 |
9572 | 6325 #ifdef HAVE_X_WINDOWS |
9564
1bfb920ab23e
(intern_face): Set the fill_style.
Richard M. Stallman <rms@gnu.org>
parents:
9529
diff
changeset
|
6326 defsubr (&Spixmap_spec_p); |
24995 | 6327 defsubr (&Sx_list_fonts); |
6328 defsubr (&Sinternal_face_x_get_resource); | |
6329 defsubr (&Sx_font_list); | |
6330 defsubr (&Sx_font_family_list); | |
6331 #endif /* HAVE_X_WINDOWS */ | |
6332 | |
6333 /* TTY face support. */ | |
6334 defsubr (&Sface_register_tty_color); | |
6335 defsubr (&Sface_clear_tty_colors); | |
6336 defsubr (&Stty_defined_colors); | |
6337 Vface_tty_color_alist = Qnil; | |
6338 staticpro (&Vface_tty_color_alist); | |
2336 | 6339 } |