Commit | Line | Data |
---|---|---|
82641697 | 1 | /* xfaces.c -- "Face" primitives. |
d26d6fd9 GM |
2 | Copyright (C) 1993, 1994, 1998, 1999, 2000, 2001 |
3 | Free Software Foundation. | |
7b7739b1 | 4 | |
c115973b JB |
5 | This file is part of GNU Emacs. |
6 | ||
7 | GNU Emacs is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
7b7739b1 | 9 | the Free Software Foundation; either version 2, or (at your option) |
c115973b JB |
10 | any later version. |
11 | ||
12 | GNU Emacs is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU Emacs; see the file COPYING. If not, write to | |
3b7ad313 EN |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
c115973b | 21 | |
82641697 GM |
22 | /* New face implementation by Gerd Moellmann <gerd@gnu.org>. */ |
23 | ||
24 | /* Faces. | |
25 | ||
26 | When using Emacs with X, the display style of characters can be | |
27 | changed by defining `faces'. Each face can specify the following | |
28 | display attributes: | |
29 | ||
39506348 | 30 | 1. Font family name. |
178c5d9c | 31 | |
82641697 GM |
32 | 2. Relative proportionate width, aka character set width or set |
33 | width (swidth), e.g. `semi-compressed'. | |
178c5d9c | 34 | |
39506348 | 35 | 3. Font height in 1/10pt. |
178c5d9c | 36 | |
82641697 | 37 | 4. Font weight, e.g. `bold'. |
178c5d9c | 38 | |
82641697 | 39 | 5. Font slant, e.g. `italic'. |
178c5d9c | 40 | |
82641697 | 41 | 6. Foreground color. |
178c5d9c | 42 | |
82641697 GM |
43 | 7. Background color. |
44 | ||
45 | 8. Whether or not characters should be underlined, and in what color. | |
46 | ||
47 | 9. Whether or not characters should be displayed in inverse video. | |
48 | ||
49 | 10. A background stipple, a bitmap. | |
50 | ||
51 | 11. Whether or not characters should be overlined, and in what color. | |
52 | ||
53 | 12. Whether or not characters should be strike-through, and in what | |
54 | color. | |
55 | ||
56 | 13. Whether or not a box should be drawn around characters, the box | |
57 | type, and, for simple boxes, in what color. | |
58 | ||
39506348 | 59 | 14. Font or fontset pattern, or nil. This is a special attribute. |
ec7a10e3 | 60 | When this attribute is specified, the face uses a font opened by |
39506348 KH |
61 | that pattern as is. In addition, all the other font-related |
62 | attributes (1st thru 5th) are generated from the opened font name. | |
63 | On the other hand, if one of the other font-related attributes are | |
64 | specified, this attribute is set to nil. In that case, the face | |
65 | doesn't inherit this attribute from the `default' face, and uses a | |
66 | font determined by the other attributes (those may be inherited | |
67 | from the `default' face). | |
68 | ||
2c20458f MB |
69 | 15. A face name or list of face names from which to inherit attributes. |
70 | ||
a08332c0 GM |
71 | 16. A specified average font width, which is invisible from Lisp, |
72 | and is used to ensure that a font specified on the command line, | |
73 | for example, can be matched exactly. | |
74 | ||
82641697 GM |
75 | Faces are frame-local by nature because Emacs allows to define the |
76 | same named face (face names are symbols) differently for different | |
77 | frames. Each frame has an alist of face definitions for all named | |
78 | faces. The value of a named face in such an alist is a Lisp vector | |
39506348 KH |
79 | with the symbol `face' in slot 0, and a slot for each of the face |
80 | attributes mentioned above. | |
82641697 GM |
81 | |
82 | There is also a global face alist `Vface_new_frame_defaults'. Face | |
83 | definitions from this list are used to initialize faces of newly | |
84 | created frames. | |
178c5d9c | 85 | |
82641697 | 86 | A face doesn't have to specify all attributes. Those not specified |
39506348 KH |
87 | have a value of `unspecified'. Faces specifying all attributes but |
88 | the 14th are called `fully-specified'. | |
82641697 GM |
89 | |
90 | ||
91 | Face merging. | |
92 | ||
93 | The display style of a given character in the text is determined by | |
94 | combining several faces. This process is called `face merging'. | |
95 | Any aspect of the display style that isn't specified by overlays or | |
96 | text properties is taken from the `default' face. Since it is made | |
97 | sure that the default face is always fully-specified, face merging | |
98 | always results in a fully-specified face. | |
99 | ||
100 | ||
101 | Face realization. | |
178c5d9c | 102 | |
82641697 GM |
103 | After all face attributes for a character have been determined by |
104 | merging faces of that character, that face is `realized'. The | |
105 | realization process maps face attributes to what is physically | |
106 | available on the system where Emacs runs. The result is a | |
107 | `realized face' in form of a struct face which is stored in the | |
108 | face cache of the frame on which it was realized. | |
109 | ||
39506348 KH |
110 | Face realization is done in the context of the character to display |
111 | because different fonts may be used for different characters. In | |
112 | other words, for characters that have different font | |
113 | specifications, different realized faces are needed to display | |
82641697 GM |
114 | them. |
115 | ||
39506348 KH |
116 | Font specification is done by fontsets. See the comment in |
117 | fontset.c for the details. In the current implementation, all ASCII | |
118 | characters share the same font in a fontset. | |
119 | ||
120 | Faces are at first realized for ASCII characters, and, at that | |
121 | time, assigned a specific realized fontset. Hereafter, we call | |
122 | such a face as `ASCII face'. When a face for a multibyte character | |
123 | is realized, it inherits (thus shares) a fontset of an ASCII face | |
124 | that has the same attributes other than font-related ones. | |
125 | ||
ec7a10e3 | 126 | Thus, all realized face have a realized fontset. |
82641697 GM |
127 | |
128 | ||
129 | Unibyte text. | |
130 | ||
39506348 KH |
131 | Unibyte text (i.e. raw 8-bit characters) is displayed with the same |
132 | font as ASCII characters. That is because it is expected that | |
133 | unibyte text users specify a font that is suitable both for ASCII | |
134 | and raw 8-bit characters. | |
135 | ||
82641697 GM |
136 | |
137 | Font selection. | |
138 | ||
139 | Font selection tries to find the best available matching font for a | |
39506348 | 140 | given (character, face) combination. |
82641697 | 141 | |
39506348 KH |
142 | If the face specifies a fontset name, that fontset determines a |
143 | pattern for fonts of the given character. If the face specifies a | |
144 | font name or the other font-related attributes, a fontset is | |
145 | realized from the default fontset. In that case, that | |
146 | specification determines a pattern for ASCII characters and the | |
147 | default fontset determines a pattern for multibyte characters. | |
82641697 GM |
148 | |
149 | Available fonts on the system on which Emacs runs are then matched | |
150 | against the font pattern. The result of font selection is the best | |
151 | match for the given face attributes in this font list. | |
152 | ||
153 | Font selection can be influenced by the user. | |
154 | ||
155 | 1. The user can specify the relative importance he gives the face | |
156 | attributes width, height, weight, and slant by setting | |
157 | face-font-selection-order (faces.el) to a list of face attribute | |
158 | names. The default is '(:width :height :weight :slant), and means | |
159 | that font selection first tries to find a good match for the font | |
160 | width specified by a face, then---within fonts with that | |
161 | width---tries to find a best match for the specified font height, | |
162 | etc. | |
163 | ||
c824bfbc | 164 | 2. Setting face-font-family-alternatives allows the user to |
82641697 GM |
165 | specify alternative font families to try if a family specified by a |
166 | face doesn't exist. | |
167 | ||
c824bfbc KH |
168 | 3. Setting face-font-registry-alternatives allows the user to |
169 | specify all alternative font registries to try for a face | |
170 | specifying a registry. | |
171 | ||
172 | 4. Setting face-ignored-fonts allows the user to ignore specific | |
173 | fonts. | |
174 | ||
82641697 | 175 | |
ec7a10e3 | 176 | Character composition. |
39506348 KH |
177 | |
178 | Usually, the realization process is already finished when Emacs | |
179 | actually reflects the desired glyph matrix on the screen. However, | |
180 | on displaying a composition (sequence of characters to be composed | |
181 | on the screen), a suitable font for the components of the | |
182 | composition is selected and realized while drawing them on the | |
183 | screen, i.e. the realization process is delayed but in principle | |
184 | the same. | |
82641697 | 185 | |
178c5d9c | 186 | |
82641697 GM |
187 | Initialization of basic faces. |
188 | ||
189 | The faces `default', `modeline' are considered `basic faces'. | |
190 | When redisplay happens the first time for a newly created frame, | |
191 | basic faces are realized for CHARSET_ASCII. Frame parameters are | |
192 | used to fill in unspecified attributes of the default face. */ | |
193 | ||
68c45bf0 | 194 | #include <config.h> |
c115973b JB |
195 | #include <sys/types.h> |
196 | #include <sys/stat.h> | |
7ee72033 | 197 | |
c115973b | 198 | #include "lisp.h" |
a8517066 | 199 | #include "charset.h" |
9763806e | 200 | #include "keyboard.h" |
b5c53576 RS |
201 | #include "frame.h" |
202 | ||
f7cc6849 DL |
203 | #ifdef HAVE_WINDOW_SYSTEM |
204 | #include "fontset.h" | |
d12d0a9b GM |
205 | #endif /* HAVE_WINDOW_SYSTEM */ |
206 | ||
87485d6f | 207 | #ifdef HAVE_X_WINDOWS |
c115973b | 208 | #include "xterm.h" |
c7ae3284 GM |
209 | #ifdef USE_MOTIF |
210 | #include <Xm/Xm.h> | |
211 | #include <Xm/XmStrDefs.h> | |
212 | #endif /* USE_MOTIF */ | |
d12d0a9b | 213 | #endif /* HAVE_X_WINDOWS */ |
82641697 | 214 | |
87485d6f MW |
215 | #ifdef MSDOS |
216 | #include "dosfns.h" | |
217 | #endif | |
82641697 | 218 | |
c3cee013 JR |
219 | #ifdef WINDOWSNT |
220 | #include "w32term.h" | |
221 | #include "fontset.h" | |
222 | /* Redefine X specifics to W32 equivalents to avoid cluttering the | |
223 | code with #ifdef blocks. */ | |
9763806e | 224 | #undef FRAME_X_DISPLAY_INFO |
c3cee013 JR |
225 | #define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO |
226 | #define x_display_info w32_display_info | |
227 | #define FRAME_X_FONT_TABLE FRAME_W32_FONT_TABLE | |
228 | #define check_x check_w32 | |
229 | #define x_list_fonts w32_list_fonts | |
230 | #define GCGraphicsExposures 0 | |
231 | /* For historic reasons, FONT_WIDTH refers to average width on W32, | |
232 | not maximum as on X. Redefine here. */ | |
9763806e | 233 | #undef FONT_WIDTH |
c3cee013 | 234 | #define FONT_WIDTH FONT_MAX_WIDTH |
d12d0a9b | 235 | #endif /* WINDOWSNT */ |
c3cee013 | 236 | |
e0f712ba | 237 | #ifdef MAC_OS |
1a578e9b AC |
238 | #include "macterm.h" |
239 | #define x_display_info mac_display_info | |
240 | #define check_x check_mac | |
e0f712ba | 241 | #endif /* MAC_OS */ |
1a578e9b | 242 | |
c115973b | 243 | #include "buffer.h" |
f211082d | 244 | #include "dispextern.h" |
357f32fc | 245 | #include "blockinput.h" |
b6d40e46 | 246 | #include "window.h" |
bde7c500 | 247 | #include "intervals.h" |
c115973b | 248 | |
87485d6f | 249 | #ifdef HAVE_X_WINDOWS |
82641697 GM |
250 | |
251 | /* Compensate for a bug in Xos.h on some systems, on which it requires | |
657070ac JB |
252 | time.h. On some such systems, Xos.h tries to redefine struct |
253 | timeval and struct timezone if USG is #defined while it is | |
254 | #included. */ | |
657070ac | 255 | |
82641697 | 256 | #ifdef XOS_NEEDS_TIME_H |
e11d186d | 257 | #include <time.h> |
657070ac JB |
258 | #undef USG |
259 | #include <X11/Xos.h> | |
260 | #define USG | |
e11d186d | 261 | #define __TIMEVAL__ |
82641697 GM |
262 | #else /* not XOS_NEEDS_TIME_H */ |
263 | #include <X11/Xos.h> | |
264 | #endif /* not XOS_NEEDS_TIME_H */ | |
e11d186d | 265 | |
82641697 | 266 | #endif /* HAVE_X_WINDOWS */ |
7a4d2269 | 267 | |
82641697 | 268 | #include <stdio.h> |
82641697 | 269 | #include <ctype.h> |
c115973b | 270 | |
82641697 | 271 | #define abs(X) ((X) < 0 ? -(X) : (X)) |
cb637678 | 272 | |
c660ce4e GM |
273 | /* Number of pt per inch (from the TeXbook). */ |
274 | ||
275 | #define PT_PER_INCH 72.27 | |
276 | ||
82641697 GM |
277 | /* Non-zero if face attribute ATTR is unspecified. */ |
278 | ||
279 | #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified) | |
280 | ||
281 | /* Value is the number of elements of VECTOR. */ | |
282 | ||
283 | #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR)) | |
284 | ||
178c5d9c | 285 | /* Make a copy of string S on the stack using alloca. Value is a pointer |
82641697 GM |
286 | to the copy. */ |
287 | ||
288 | #define STRDUPA(S) strcpy ((char *) alloca (strlen ((S)) + 1), (S)) | |
bc0db68d | 289 | |
82641697 GM |
290 | /* Make a copy of the contents of Lisp string S on the stack using |
291 | alloca. Value is a pointer to the copy. */ | |
292 | ||
293 | #define LSTRDUPA(S) STRDUPA (XSTRING ((S))->data) | |
294 | ||
178c5d9c | 295 | /* Size of hash table of realized faces in face caches (should be a |
82641697 GM |
296 | prime number). */ |
297 | ||
298 | #define FACE_CACHE_BUCKETS_SIZE 1001 | |
299 | ||
2d764c78 | 300 | /* A definition of XColor for non-X frames. */ |
ae4b4ba5 | 301 | |
2d764c78 | 302 | #ifndef HAVE_X_WINDOWS |
ae4b4ba5 GM |
303 | |
304 | typedef struct | |
305 | { | |
2d764c78 EZ |
306 | unsigned long pixel; |
307 | unsigned short red, green, blue; | |
308 | char flags; | |
309 | char pad; | |
ae4b4ba5 GM |
310 | } |
311 | XColor; | |
312 | ||
313 | #endif /* not HAVE_X_WINDOWS */ | |
2d764c78 | 314 | |
82641697 GM |
315 | /* Keyword symbols used for face attribute names. */ |
316 | ||
317 | Lisp_Object QCfamily, QCheight, QCweight, QCslant, QCunderline; | |
318 | Lisp_Object QCinverse_video, QCforeground, QCbackground, QCstipple; | |
319 | Lisp_Object QCwidth, QCfont, QCbold, QCitalic; | |
320 | Lisp_Object QCreverse_video; | |
2c20458f | 321 | Lisp_Object QCoverline, QCstrike_through, QCbox, QCinherit; |
82641697 GM |
322 | |
323 | /* Symbols used for attribute values. */ | |
324 | ||
325 | Lisp_Object Qnormal, Qbold, Qultra_light, Qextra_light, Qlight; | |
326 | Lisp_Object Qsemi_light, Qsemi_bold, Qextra_bold, Qultra_bold; | |
327 | Lisp_Object Qoblique, Qitalic, Qreverse_oblique, Qreverse_italic; | |
328 | Lisp_Object Qultra_condensed, Qextra_condensed, Qcondensed; | |
329 | Lisp_Object Qsemi_condensed, Qsemi_expanded, Qexpanded, Qextra_expanded; | |
330 | Lisp_Object Qultra_expanded; | |
331 | Lisp_Object Qreleased_button, Qpressed_button; | |
332 | Lisp_Object QCstyle, QCcolor, QCline_width; | |
ef917393 EZ |
333 | Lisp_Object Qunspecified; |
334 | ||
335 | char unspecified_fg[] = "unspecified-fg", unspecified_bg[] = "unspecified-bg"; | |
82641697 | 336 | |
92610620 GM |
337 | /* The name of the function to call when the background of the frame |
338 | has changed, frame_update_face_colors. */ | |
339 | ||
340 | Lisp_Object Qframe_update_face_colors; | |
341 | ||
82641697 GM |
342 | /* Names of basic faces. */ |
343 | ||
fb4927c4 | 344 | Lisp_Object Qdefault, Qtool_bar, Qregion, Qfringe; |
c7ae3284 | 345 | Lisp_Object Qheader_line, Qscroll_bar, Qcursor, Qborder, Qmouse, Qmenu; |
039b6394 | 346 | Lisp_Object Qmode_line_inactive; |
fb4927c4 | 347 | extern Lisp_Object Qmode_line; |
8bd201d6 | 348 | |
92610620 GM |
349 | /* The symbol `face-alias'. A symbols having that property is an |
350 | alias for another face. Value of the property is the name of | |
351 | the aliased face. */ | |
352 | ||
353 | Lisp_Object Qface_alias; | |
354 | ||
8bd201d6 GM |
355 | /* Names of frame parameters related to faces. */ |
356 | ||
357 | extern Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background; | |
358 | extern Lisp_Object Qborder_color, Qcursor_color, Qmouse_color; | |
82641697 GM |
359 | |
360 | /* Default stipple pattern used on monochrome displays. This stipple | |
361 | pattern is used on monochrome displays instead of shades of gray | |
362 | for a face background color. See `set-face-stipple' for possible | |
363 | values for this variable. */ | |
364 | ||
365 | Lisp_Object Vface_default_stipple; | |
366 | ||
82641697 GM |
367 | /* Alist of alternative font families. Each element is of the form |
368 | (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded, | |
369 | try FAMILY1, then FAMILY2, ... */ | |
370 | ||
371 | Lisp_Object Vface_alternative_font_family_alist; | |
372 | ||
32fcc231 GM |
373 | /* Alist of alternative font registries. Each element is of the form |
374 | (REGISTRY REGISTRY1 REGISTRY2...). If fonts of REGISTRY can't be | |
375 | loaded, try REGISTRY1, then REGISTRY2, ... */ | |
376 | ||
377 | Lisp_Object Vface_alternative_font_registry_alist; | |
378 | ||
82641697 GM |
379 | /* Allowed scalable fonts. A value of nil means don't allow any |
380 | scalable fonts. A value of t means allow the use of any scalable | |
381 | font. Otherwise, value must be a list of regular expressions. A | |
382 | font may be scaled if its name matches a regular expression in the | |
383 | list. */ | |
384 | ||
eeffb293 | 385 | Lisp_Object Vscalable_fonts_allowed, Qscalable_fonts_allowed; |
82641697 | 386 | |
c824bfbc KH |
387 | /* List of regular expressions that matches names of fonts to ignore. */ |
388 | ||
389 | Lisp_Object Vface_ignored_fonts; | |
390 | ||
057df17c GM |
391 | /* Maximum number of fonts to consider in font_list. If not an |
392 | integer > 0, DEFAULT_FONT_LIST_LIMIT is used instead. */ | |
393 | ||
394 | Lisp_Object Vfont_list_limit; | |
395 | #define DEFAULT_FONT_LIST_LIMIT 100 | |
396 | ||
82641697 GM |
397 | /* The symbols `foreground-color' and `background-color' which can be |
398 | used as part of a `face' property. This is for compatibility with | |
399 | Emacs 20.2. */ | |
400 | ||
401 | Lisp_Object Qforeground_color, Qbackground_color; | |
402 | ||
403 | /* The symbols `face' and `mouse-face' used as text properties. */ | |
7b7739b1 | 404 | |
ff83dbb1 | 405 | Lisp_Object Qface; |
82641697 GM |
406 | extern Lisp_Object Qmouse_face; |
407 | ||
408 | /* Error symbol for wrong_type_argument in load_pixmap. */ | |
409 | ||
fef04523 | 410 | Lisp_Object Qbitmap_spec_p; |
f211082d | 411 | |
82641697 GM |
412 | /* Alist of global face definitions. Each element is of the form |
413 | (FACE . LFACE) where FACE is a symbol naming a face and LFACE | |
414 | is a Lisp vector of face attributes. These faces are used | |
415 | to initialize faces for new frames. */ | |
cb637678 | 416 | |
82641697 | 417 | Lisp_Object Vface_new_frame_defaults; |
18195655 | 418 | |
82641697 | 419 | /* The next ID to assign to Lisp faces. */ |
cb637678 | 420 | |
82641697 | 421 | static int next_lface_id; |
c115973b | 422 | |
82641697 | 423 | /* A vector mapping Lisp face Id's to face names. */ |
c115973b | 424 | |
82641697 GM |
425 | static Lisp_Object *lface_id_to_name; |
426 | static int lface_id_to_name_size; | |
c115973b | 427 | |
ae4b4ba5 GM |
428 | /* TTY color-related functions (defined in tty-colors.el). */ |
429 | ||
2d764c78 | 430 | Lisp_Object Qtty_color_desc, Qtty_color_by_index; |
82641697 | 431 | |
ae4b4ba5 GM |
432 | /* The name of the function used to compute colors on TTYs. */ |
433 | ||
434 | Lisp_Object Qtty_color_alist; | |
435 | ||
436 | /* An alist of defined terminal colors and their RGB values. */ | |
437 | ||
438 | Lisp_Object Vtty_defined_color_alist; | |
439 | ||
82641697 GM |
440 | /* Counter for calls to clear_face_cache. If this counter reaches |
441 | CLEAR_FONT_TABLE_COUNT, and a frame has more than | |
442 | CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */ | |
443 | ||
444 | static int clear_font_table_count; | |
445 | #define CLEAR_FONT_TABLE_COUNT 100 | |
446 | #define CLEAR_FONT_TABLE_NFONTS 10 | |
447 | ||
448 | /* Non-zero means face attributes have been changed since the last | |
449 | redisplay. Used in redisplay_internal. */ | |
450 | ||
451 | int face_change_count; | |
452 | ||
a4a76b61 GM |
453 | /* Non-zero means don't display bold text if a face's foreground |
454 | and background colors are the inverse of the default colors of the | |
455 | display. This is a kluge to suppress `bold black' foreground text | |
456 | which is hard to read on an LCD monitor. */ | |
457 | ||
458 | int tty_suppress_bold_inverse_default_colors_p; | |
459 | ||
dbc968b8 GM |
460 | /* A list of the form `((x . y))' used to avoid consing in |
461 | Finternal_set_lisp_face_attribute. */ | |
462 | ||
463 | static Lisp_Object Vparam_value_alist; | |
464 | ||
82641697 GM |
465 | /* The total number of colors currently allocated. */ |
466 | ||
467 | #if GLYPH_DEBUG | |
468 | static int ncolors_allocated; | |
469 | static int npixmaps_allocated; | |
470 | static int ngcs; | |
471 | #endif | |
472 | ||
ceeda019 GM |
473 | /* Non-zero means the definition of the `menu' face for new frames has |
474 | been changed. */ | |
475 | ||
476 | int menu_face_changed_default; | |
82641697 GM |
477 | |
478 | \f | |
479 | /* Function prototypes. */ | |
480 | ||
481 | struct font_name; | |
482 | struct table_entry; | |
483 | ||
ae4b4ba5 GM |
484 | static void map_tty_color P_ ((struct frame *, struct face *, |
485 | enum lface_attribute_index, int *)); | |
c7ae3284 | 486 | static Lisp_Object resolve_face_name P_ ((Lisp_Object)); |
702a1e8e | 487 | static int may_use_scalable_font_p P_ ((char *)); |
82641697 GM |
488 | static void set_font_frame_param P_ ((Lisp_Object, Lisp_Object)); |
489 | static int better_font_p P_ ((int *, struct font_name *, struct font_name *, | |
a08332c0 | 490 | int, int)); |
82641697 | 491 | static int x_face_list_fonts P_ ((struct frame *, char *, |
702a1e8e | 492 | struct font_name *, int, int)); |
82641697 | 493 | static int font_scalable_p P_ ((struct font_name *)); |
82641697 GM |
494 | static int get_lface_attributes P_ ((struct frame *, Lisp_Object, Lisp_Object *, int)); |
495 | static int load_pixmap P_ ((struct frame *, Lisp_Object, unsigned *, unsigned *)); | |
82641697 GM |
496 | static unsigned char *xstrlwr P_ ((unsigned char *)); |
497 | static void signal_error P_ ((char *, Lisp_Object)); | |
82641697 | 498 | static struct frame *frame_or_selected_frame P_ ((Lisp_Object, int)); |
39506348 | 499 | static void load_face_font P_ ((struct frame *, struct face *, int)); |
82641697 GM |
500 | static void load_face_colors P_ ((struct frame *, struct face *, Lisp_Object *)); |
501 | static void free_face_colors P_ ((struct frame *, struct face *)); | |
502 | static int face_color_gray_p P_ ((struct frame *, char *)); | |
503 | static char *build_font_name P_ ((struct font_name *)); | |
504 | static void free_font_names P_ ((struct font_name *, int)); | |
505 | static int sorted_font_list P_ ((struct frame *, char *, | |
506 | int (*cmpfn) P_ ((const void *, const void *)), | |
507 | struct font_name **)); | |
32fcc231 GM |
508 | static int font_list_1 P_ ((struct frame *, Lisp_Object, Lisp_Object, |
509 | Lisp_Object, struct font_name **)); | |
39506348 KH |
510 | static int font_list P_ ((struct frame *, Lisp_Object, Lisp_Object, |
511 | Lisp_Object, struct font_name **)); | |
702a1e8e | 512 | static int try_font_list P_ ((struct frame *, Lisp_Object *, |
39506348 | 513 | Lisp_Object, Lisp_Object, struct font_name **)); |
4a529c42 GM |
514 | static int try_alternative_families P_ ((struct frame *f, Lisp_Object, |
515 | Lisp_Object, struct font_name **)); | |
82641697 | 516 | static int cmp_font_names P_ ((const void *, const void *)); |
39506348 KH |
517 | static struct face *realize_face P_ ((struct face_cache *, Lisp_Object *, int, |
518 | struct face *, int)); | |
82641697 | 519 | static struct face *realize_x_face P_ ((struct face_cache *, |
39506348 | 520 | Lisp_Object *, int, struct face *)); |
82641697 GM |
521 | static struct face *realize_tty_face P_ ((struct face_cache *, |
522 | Lisp_Object *, int)); | |
523 | static int realize_basic_faces P_ ((struct frame *)); | |
524 | static int realize_default_face P_ ((struct frame *)); | |
525 | static void realize_named_face P_ ((struct frame *, Lisp_Object, int)); | |
526 | static int lface_fully_specified_p P_ ((Lisp_Object *)); | |
527 | static int lface_equal_p P_ ((Lisp_Object *, Lisp_Object *)); | |
528 | static unsigned hash_string_case_insensitive P_ ((Lisp_Object)); | |
529 | static unsigned lface_hash P_ ((Lisp_Object *)); | |
530 | static int lface_same_font_attributes_p P_ ((Lisp_Object *, Lisp_Object *)); | |
531 | static struct face_cache *make_face_cache P_ ((struct frame *)); | |
532 | static void free_realized_face P_ ((struct frame *, struct face *)); | |
533 | static void clear_face_gcs P_ ((struct face_cache *)); | |
534 | static void free_face_cache P_ ((struct face_cache *)); | |
535 | static int face_numeric_weight P_ ((Lisp_Object)); | |
536 | static int face_numeric_slant P_ ((Lisp_Object)); | |
537 | static int face_numeric_swidth P_ ((Lisp_Object)); | |
39506348 KH |
538 | static int face_fontset P_ ((Lisp_Object *)); |
539 | static char *choose_face_font P_ ((struct frame *, Lisp_Object *, int, int)); | |
2c20458f MB |
540 | static void merge_face_vectors P_ ((struct frame *, Lisp_Object *, Lisp_Object*, Lisp_Object)); |
541 | static void merge_face_inheritance P_ ((struct frame *f, Lisp_Object, | |
542 | Lisp_Object *, Lisp_Object)); | |
82641697 GM |
543 | static void merge_face_vector_with_property P_ ((struct frame *, Lisp_Object *, |
544 | Lisp_Object)); | |
39506348 KH |
545 | static int set_lface_from_font_name P_ ((struct frame *, Lisp_Object, |
546 | Lisp_Object, int, int)); | |
82641697 | 547 | static Lisp_Object lface_from_face_name P_ ((struct frame *, Lisp_Object, int)); |
39506348 | 548 | static struct face *make_realized_face P_ ((Lisp_Object *)); |
82641697 GM |
549 | static void free_realized_faces P_ ((struct face_cache *)); |
550 | static char *best_matching_font P_ ((struct frame *, Lisp_Object *, | |
2e6621ca | 551 | struct font_name *, int, int)); |
82641697 GM |
552 | static void cache_face P_ ((struct face_cache *, struct face *, unsigned)); |
553 | static void uncache_face P_ ((struct face_cache *, struct face *)); | |
554 | static int xlfd_numeric_slant P_ ((struct font_name *)); | |
555 | static int xlfd_numeric_weight P_ ((struct font_name *)); | |
556 | static int xlfd_numeric_swidth P_ ((struct font_name *)); | |
557 | static Lisp_Object xlfd_symbolic_slant P_ ((struct font_name *)); | |
558 | static Lisp_Object xlfd_symbolic_weight P_ ((struct font_name *)); | |
559 | static Lisp_Object xlfd_symbolic_swidth P_ ((struct font_name *)); | |
560 | static int xlfd_fixed_p P_ ((struct font_name *)); | |
561 | static int xlfd_numeric_value P_ ((struct table_entry *, int, struct font_name *, | |
562 | int, int)); | |
563 | static Lisp_Object xlfd_symbolic_value P_ ((struct table_entry *, int, | |
6fc556fd KR |
564 | struct font_name *, int, |
565 | Lisp_Object)); | |
82641697 GM |
566 | static struct table_entry *xlfd_lookup_field_contents P_ ((struct table_entry *, int, |
567 | struct font_name *, int)); | |
568 | ||
c3cee013 | 569 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 GM |
570 | |
571 | static int split_font_name P_ ((struct frame *, struct font_name *, int)); | |
572 | static int xlfd_point_size P_ ((struct frame *, struct font_name *)); | |
573 | static void sort_fonts P_ ((struct frame *, struct font_name *, int, | |
574 | int (*cmpfn) P_ ((const void *, const void *)))); | |
575 | static GC x_create_gc P_ ((struct frame *, unsigned long, XGCValues *)); | |
576 | static void x_free_gc P_ ((struct frame *, GC)); | |
d5641fc5 | 577 | static void clear_font_table P_ ((struct x_display_info *)); |
82641697 | 578 | |
c3cee013 JR |
579 | #ifdef WINDOWSNT |
580 | extern Lisp_Object w32_list_fonts P_ ((struct frame *, Lisp_Object, int, int)); | |
581 | #endif /* WINDOWSNT */ | |
582 | ||
bce72079 GM |
583 | #ifdef USE_X_TOOLKIT |
584 | static void x_update_menu_appearance P_ ((struct frame *)); | |
9180dc8c PJ |
585 | |
586 | extern void free_frame_menubar P_ ((struct frame *)); | |
bce72079 GM |
587 | #endif /* USE_X_TOOLKIT */ |
588 | ||
c3cee013 | 589 | #endif /* HAVE_WINDOW_SYSTEM */ |
c115973b | 590 | |
cb637678 | 591 | \f |
82641697 GM |
592 | /*********************************************************************** |
593 | Utilities | |
594 | ***********************************************************************/ | |
c115973b | 595 | |
87485d6f | 596 | #ifdef HAVE_X_WINDOWS |
cb637678 | 597 | |
a435fc2a GM |
598 | #ifdef DEBUG_X_COLORS |
599 | ||
600 | /* The following is a poor mans infrastructure for debugging X color | |
601 | allocation problems on displays with PseudoColor-8. Some X servers | |
602 | like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement | |
603 | color reference counts completely so that they don't signal an | |
604 | error when a color is freed whose reference count is already 0. | |
605 | Other X servers do. To help me debug this, the following code | |
606 | implements a simple reference counting schema of its own, for a | |
607 | single display/screen. --gerd. */ | |
608 | ||
609 | /* Reference counts for pixel colors. */ | |
610 | ||
611 | int color_count[256]; | |
612 | ||
613 | /* Register color PIXEL as allocated. */ | |
614 | ||
615 | void | |
616 | register_color (pixel) | |
617 | unsigned long pixel; | |
618 | { | |
619 | xassert (pixel < 256); | |
620 | ++color_count[pixel]; | |
621 | } | |
622 | ||
623 | ||
624 | /* Register color PIXEL as deallocated. */ | |
625 | ||
626 | void | |
627 | unregister_color (pixel) | |
628 | unsigned long pixel; | |
629 | { | |
630 | xassert (pixel < 256); | |
631 | if (color_count[pixel] > 0) | |
632 | --color_count[pixel]; | |
633 | else | |
634 | abort (); | |
635 | } | |
636 | ||
637 | ||
638 | /* Register N colors from PIXELS as deallocated. */ | |
639 | ||
640 | void | |
641 | unregister_colors (pixels, n) | |
642 | unsigned long *pixels; | |
643 | int n; | |
644 | { | |
645 | int i; | |
646 | for (i = 0; i < n; ++i) | |
647 | unregister_color (pixels[i]); | |
648 | } | |
649 | ||
08dc08dc GM |
650 | |
651 | DEFUN ("dump-colors", Fdump_colors, Sdump_colors, 0, 0, 0, | |
7ee72033 MB |
652 | doc: /* Dump currently allocated colors to stderr. */) |
653 | () | |
08dc08dc GM |
654 | { |
655 | int i, n; | |
656 | ||
657 | fputc ('\n', stderr); | |
178c5d9c | 658 | |
08dc08dc GM |
659 | for (i = n = 0; i < sizeof color_count / sizeof color_count[0]; ++i) |
660 | if (color_count[i]) | |
661 | { | |
662 | fprintf (stderr, "%3d: %5d", i, color_count[i]); | |
663 | ++n; | |
664 | if (n % 5 == 0) | |
665 | fputc ('\n', stderr); | |
666 | else | |
667 | fputc ('\t', stderr); | |
668 | } | |
669 | ||
670 | if (n % 5 != 0) | |
671 | fputc ('\n', stderr); | |
672 | return Qnil; | |
673 | } | |
674 | ||
a435fc2a GM |
675 | #endif /* DEBUG_X_COLORS */ |
676 | ||
d12d0a9b | 677 | |
1f847cf8 GM |
678 | /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel |
679 | color values. Interrupt input must be blocked when this function | |
680 | is called. */ | |
681 | ||
682 | void | |
683 | x_free_colors (f, pixels, npixels) | |
684 | struct frame *f; | |
685 | unsigned long *pixels; | |
686 | int npixels; | |
687 | { | |
688 | int class = FRAME_X_DISPLAY_INFO (f)->visual->class; | |
689 | ||
690 | /* If display has an immutable color map, freeing colors is not | |
691 | necessary and some servers don't allow it. So don't do it. */ | |
692 | if (class != StaticColor && class != StaticGray && class != TrueColor) | |
693 | { | |
a435fc2a | 694 | #ifdef DEBUG_X_COLORS |
08dc08dc | 695 | unregister_colors (pixels, npixels); |
a435fc2a | 696 | #endif |
513c5806 GM |
697 | XFreeColors (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), |
698 | pixels, npixels, 0); | |
08dc08dc GM |
699 | } |
700 | } | |
701 | ||
702 | ||
703 | /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel | |
704 | color values. Interrupt input must be blocked when this function | |
705 | is called. */ | |
706 | ||
707 | void | |
708 | x_free_dpy_colors (dpy, screen, cmap, pixels, npixels) | |
709 | Display *dpy; | |
710 | Screen *screen; | |
711 | Colormap cmap; | |
712 | unsigned long *pixels; | |
713 | int npixels; | |
714 | { | |
715 | struct x_display_info *dpyinfo = x_display_info_for_display (dpy); | |
716 | int class = dpyinfo->visual->class; | |
717 | ||
718 | /* If display has an immutable color map, freeing colors is not | |
719 | necessary and some servers don't allow it. So don't do it. */ | |
720 | if (class != StaticColor && class != StaticGray && class != TrueColor) | |
721 | { | |
a435fc2a | 722 | #ifdef DEBUG_X_COLORS |
08dc08dc | 723 | unregister_colors (pixels, npixels); |
a435fc2a | 724 | #endif |
513c5806 | 725 | XFreeColors (dpy, cmap, pixels, npixels, 0); |
1f847cf8 GM |
726 | } |
727 | } | |
728 | ||
08dc08dc | 729 | |
82641697 GM |
730 | /* Create and return a GC for use on frame F. GC values and mask |
731 | are given by XGCV and MASK. */ | |
732 | ||
733 | static INLINE GC | |
734 | x_create_gc (f, mask, xgcv) | |
cb637678 | 735 | struct frame *f; |
82641697 GM |
736 | unsigned long mask; |
737 | XGCValues *xgcv; | |
c115973b JB |
738 | { |
739 | GC gc; | |
82641697 GM |
740 | BLOCK_INPUT; |
741 | gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), mask, xgcv); | |
742 | UNBLOCK_INPUT; | |
743 | IF_DEBUG (++ngcs); | |
744 | return gc; | |
745 | } | |
c115973b | 746 | |
42120bc7 | 747 | |
82641697 GM |
748 | /* Free GC which was used on frame F. */ |
749 | ||
750 | static INLINE void | |
751 | x_free_gc (f, gc) | |
752 | struct frame *f; | |
753 | GC gc; | |
754 | { | |
660ed669 | 755 | BLOCK_INPUT; |
82641697 GM |
756 | xassert (--ngcs >= 0); |
757 | XFreeGC (FRAME_X_DISPLAY (f), gc); | |
758 | UNBLOCK_INPUT; | |
759 | } | |
660ed669 | 760 | |
82641697 | 761 | #endif /* HAVE_X_WINDOWS */ |
660ed669 | 762 | |
c3cee013 JR |
763 | #ifdef WINDOWSNT |
764 | /* W32 emulation of GCs */ | |
765 | ||
766 | static INLINE GC | |
767 | x_create_gc (f, mask, xgcv) | |
768 | struct frame *f; | |
769 | unsigned long mask; | |
770 | XGCValues *xgcv; | |
771 | { | |
772 | GC gc; | |
773 | BLOCK_INPUT; | |
774 | gc = XCreateGC (NULL, FRAME_W32_WINDOW (f), mask, xgcv); | |
775 | UNBLOCK_INPUT; | |
776 | IF_DEBUG (++ngcs); | |
777 | return gc; | |
778 | } | |
779 | ||
780 | ||
781 | /* Free GC which was used on frame F. */ | |
782 | ||
783 | static INLINE void | |
784 | x_free_gc (f, gc) | |
785 | struct frame *f; | |
786 | GC gc; | |
787 | { | |
788 | BLOCK_INPUT; | |
789 | xassert (--ngcs >= 0); | |
790 | xfree (gc); | |
791 | UNBLOCK_INPUT; | |
792 | } | |
793 | ||
794 | #endif /* WINDOWSNT */ | |
660ed669 | 795 | |
e0f712ba AC |
796 | #ifdef MAC_OS |
797 | /* Mac OS emulation of GCs */ | |
798 | ||
799 | extern XGCValues *XCreateGC (void *, Window, unsigned long, XGCValues *); | |
800 | ||
801 | static INLINE GC | |
802 | x_create_gc (f, mask, xgcv) | |
803 | struct frame *f; | |
804 | unsigned long mask; | |
805 | XGCValues *xgcv; | |
806 | { | |
807 | GC gc; | |
808 | gc = XCreateGC (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f), mask, xgcv); | |
809 | return gc; | |
810 | } | |
811 | ||
812 | static INLINE void | |
813 | x_free_gc (f, gc) | |
814 | struct frame *f; | |
815 | GC gc; | |
816 | { | |
817 | XFreeGC (FRAME_MAC_DISPLAY (f), gc); | |
818 | } | |
819 | ||
820 | #endif /* MAC_OS */ | |
821 | ||
82641697 GM |
822 | /* Like stricmp. Used to compare parts of font names which are in |
823 | ISO8859-1. */ | |
824 | ||
825 | int | |
826 | xstricmp (s1, s2) | |
827 | unsigned char *s1, *s2; | |
828 | { | |
829 | while (*s1 && *s2) | |
95887807 | 830 | { |
82641697 GM |
831 | unsigned char c1 = tolower (*s1); |
832 | unsigned char c2 = tolower (*s2); | |
833 | if (c1 != c2) | |
834 | return c1 < c2 ? -1 : 1; | |
835 | ++s1, ++s2; | |
95887807 | 836 | } |
cd0bb842 | 837 | |
82641697 GM |
838 | if (*s1 == 0) |
839 | return *s2 == 0 ? 0 : -1; | |
840 | return 1; | |
841 | } | |
660ed669 | 842 | |
660ed669 | 843 | |
82641697 | 844 | /* Like strlwr, which might not always be available. */ |
42120bc7 | 845 | |
82641697 GM |
846 | static unsigned char * |
847 | xstrlwr (s) | |
848 | unsigned char *s; | |
849 | { | |
850 | unsigned char *p = s; | |
851 | ||
852 | for (p = s; *p; ++p) | |
853 | *p = tolower (*p); | |
854 | ||
855 | return s; | |
c115973b | 856 | } |
cb637678 | 857 | |
42120bc7 | 858 | |
82641697 GM |
859 | /* Signal `error' with message S, and additional argument ARG. */ |
860 | ||
861 | static void | |
862 | signal_error (s, arg) | |
863 | char *s; | |
864 | Lisp_Object arg; | |
42120bc7 | 865 | { |
82641697 GM |
866 | Fsignal (Qerror, Fcons (build_string (s), Fcons (arg, Qnil))); |
867 | } | |
42120bc7 | 868 | |
82641697 | 869 | |
c0617987 GM |
870 | /* If FRAME is nil, return a pointer to the selected frame. |
871 | Otherwise, check that FRAME is a live frame, and return a pointer | |
872 | to it. NPARAM is the parameter number of FRAME, for | |
873 | CHECK_LIVE_FRAME. This is here because it's a frequent pattern in | |
874 | Lisp function definitions. */ | |
82641697 GM |
875 | |
876 | static INLINE struct frame * | |
877 | frame_or_selected_frame (frame, nparam) | |
878 | Lisp_Object frame; | |
879 | int nparam; | |
880 | { | |
82641697 | 881 | if (NILP (frame)) |
c0617987 | 882 | frame = selected_frame; |
178c5d9c | 883 | |
b7826503 | 884 | CHECK_LIVE_FRAME (frame); |
c0617987 | 885 | return XFRAME (frame); |
42120bc7 | 886 | } |
82641697 | 887 | |
42120bc7 | 888 | \f |
82641697 GM |
889 | /*********************************************************************** |
890 | Frames and faces | |
891 | ***********************************************************************/ | |
cd0bb842 | 892 | |
82641697 | 893 | /* Initialize face cache and basic faces for frame F. */ |
cb637678 | 894 | |
82641697 GM |
895 | void |
896 | init_frame_faces (f) | |
cb637678 | 897 | struct frame *f; |
cb637678 | 898 | { |
82641697 GM |
899 | /* Make a face cache, if F doesn't have one. */ |
900 | if (FRAME_FACE_CACHE (f) == NULL) | |
901 | FRAME_FACE_CACHE (f) = make_face_cache (f); | |
178c5d9c | 902 | |
c3cee013 | 903 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 | 904 | /* Make the image cache. */ |
c3cee013 | 905 | if (FRAME_WINDOW_P (f)) |
82641697 GM |
906 | { |
907 | if (FRAME_X_IMAGE_CACHE (f) == NULL) | |
908 | FRAME_X_IMAGE_CACHE (f) = make_image_cache (); | |
909 | ++FRAME_X_IMAGE_CACHE (f)->refcount; | |
910 | } | |
c3cee013 | 911 | #endif /* HAVE_WINDOW_SYSTEM */ |
cb637678 | 912 | |
178c5d9c | 913 | /* Realize basic faces. Must have enough information in frame |
82641697 GM |
914 | parameters to realize basic faces at this point. */ |
915 | #ifdef HAVE_X_WINDOWS | |
916 | if (!FRAME_X_P (f) || FRAME_X_WINDOW (f)) | |
c3cee013 JR |
917 | #endif |
918 | #ifdef WINDOWSNT | |
919 | if (!FRAME_WINDOW_P (f) || FRAME_W32_WINDOW (f)) | |
82641697 GM |
920 | #endif |
921 | if (!realize_basic_faces (f)) | |
922 | abort (); | |
923 | } | |
cb637678 | 924 | |
cb637678 | 925 | |
82641697 | 926 | /* Free face cache of frame F. Called from Fdelete_frame. */ |
cb637678 | 927 | |
82641697 GM |
928 | void |
929 | free_frame_faces (f) | |
cb637678 | 930 | struct frame *f; |
cb637678 | 931 | { |
82641697 | 932 | struct face_cache *face_cache = FRAME_FACE_CACHE (f); |
178c5d9c | 933 | |
82641697 GM |
934 | if (face_cache) |
935 | { | |
936 | free_face_cache (face_cache); | |
937 | FRAME_FACE_CACHE (f) = NULL; | |
938 | } | |
660ed669 | 939 | |
c3cee013 JR |
940 | #ifdef HAVE_WINDOW_SYSTEM |
941 | if (FRAME_WINDOW_P (f)) | |
195f798e | 942 | { |
82641697 GM |
943 | struct image_cache *image_cache = FRAME_X_IMAGE_CACHE (f); |
944 | if (image_cache) | |
195f798e | 945 | { |
82641697 GM |
946 | --image_cache->refcount; |
947 | if (image_cache->refcount == 0) | |
948 | free_image_cache (f); | |
195f798e RS |
949 | } |
950 | } | |
c3cee013 | 951 | #endif /* HAVE_WINDOW_SYSTEM */ |
cb637678 JB |
952 | } |
953 | ||
82641697 | 954 | |
8bd201d6 GM |
955 | /* Clear face caches, and recompute basic faces for frame F. Call |
956 | this after changing frame parameters on which those faces depend, | |
957 | or when realized faces have been freed due to changing attributes | |
958 | of named faces. */ | |
82641697 GM |
959 | |
960 | void | |
961 | recompute_basic_faces (f) | |
cb637678 | 962 | struct frame *f; |
cb637678 | 963 | { |
82641697 GM |
964 | if (FRAME_FACE_CACHE (f)) |
965 | { | |
8bd201d6 | 966 | clear_face_cache (0); |
18df9369 GM |
967 | if (!realize_basic_faces (f)) |
968 | abort (); | |
82641697 GM |
969 | } |
970 | } | |
cb637678 | 971 | |
cb637678 | 972 | |
82641697 GM |
973 | /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means |
974 | try to free unused fonts, too. */ | |
cb637678 | 975 | |
adfea139 | 976 | void |
82641697 GM |
977 | clear_face_cache (clear_fonts_p) |
978 | int clear_fonts_p; | |
cb637678 | 979 | { |
c3cee013 | 980 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 GM |
981 | Lisp_Object tail, frame; |
982 | struct frame *f; | |
828e66d1 | 983 | |
82641697 GM |
984 | if (clear_fonts_p |
985 | || ++clear_font_table_count == CLEAR_FONT_TABLE_COUNT) | |
828e66d1 | 986 | { |
d5641fc5 GM |
987 | struct x_display_info *dpyinfo; |
988 | ||
989 | /* Fonts are common for frames on one display, i.e. on | |
990 | one X screen. */ | |
991 | for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) | |
992 | if (dpyinfo->n_fonts > CLEAR_FONT_TABLE_NFONTS) | |
993 | clear_font_table (dpyinfo); | |
994 | ||
82641697 GM |
995 | /* From time to time see if we can unload some fonts. This also |
996 | frees all realized faces on all frames. Fonts needed by | |
997 | faces will be loaded again when faces are realized again. */ | |
998 | clear_font_table_count = 0; | |
195f798e | 999 | |
82641697 | 1000 | FOR_EACH_FRAME (tail, frame) |
195f798e | 1001 | { |
d5641fc5 | 1002 | struct frame *f = XFRAME (frame); |
c3cee013 | 1003 | if (FRAME_WINDOW_P (f) |
82641697 | 1004 | && FRAME_X_DISPLAY_INFO (f)->n_fonts > CLEAR_FONT_TABLE_NFONTS) |
d5641fc5 | 1005 | free_all_realized_faces (frame); |
82641697 GM |
1006 | } |
1007 | } | |
1008 | else | |
1009 | { | |
1010 | /* Clear GCs of realized faces. */ | |
1011 | FOR_EACH_FRAME (tail, frame) | |
1012 | { | |
1013 | f = XFRAME (frame); | |
c3cee013 | 1014 | if (FRAME_WINDOW_P (f)) |
82641697 GM |
1015 | { |
1016 | clear_face_gcs (FRAME_FACE_CACHE (f)); | |
1017 | clear_image_cache (f, 0); | |
195f798e RS |
1018 | } |
1019 | } | |
828e66d1 | 1020 | } |
c3cee013 | 1021 | #endif /* HAVE_WINDOW_SYSTEM */ |
cd0bb842 RS |
1022 | } |
1023 | ||
82641697 GM |
1024 | |
1025 | DEFUN ("clear-face-cache", Fclear_face_cache, Sclear_face_cache, 0, 1, 0, | |
7ee72033 MB |
1026 | doc: /* Clear face caches on all frames. |
1027 | Optional THOROUGHLY non-nil means try to free unused fonts, too. */) | |
1028 | (thoroughly) | |
6a3f48c7 | 1029 | Lisp_Object thoroughly; |
cd0bb842 | 1030 | { |
6a3f48c7 | 1031 | clear_face_cache (!NILP (thoroughly)); |
ae4b4ba5 GM |
1032 | ++face_change_count; |
1033 | ++windows_or_buffers_changed; | |
82641697 GM |
1034 | return Qnil; |
1035 | } | |
1036 | ||
1037 | ||
1038 | ||
c3cee013 | 1039 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 GM |
1040 | |
1041 | ||
4cba8c0b GM |
1042 | /* Remove fonts from the font table of DPYINFO except for the default |
1043 | ASCII fonts of frames on that display. Called from clear_face_cache | |
39506348 | 1044 | from time to time. */ |
82641697 GM |
1045 | |
1046 | static void | |
d5641fc5 GM |
1047 | clear_font_table (dpyinfo) |
1048 | struct x_display_info *dpyinfo; | |
82641697 | 1049 | { |
82641697 GM |
1050 | int i; |
1051 | ||
d5641fc5 | 1052 | /* Free those fonts that are not used by frames on DPYINFO. */ |
39506348 KH |
1053 | for (i = 0; i < dpyinfo->n_fonts; ++i) |
1054 | { | |
1055 | struct font_info *font_info = dpyinfo->font_table + i; | |
d5641fc5 GM |
1056 | Lisp_Object tail, frame; |
1057 | ||
1058 | /* Check if slot is already free. */ | |
1059 | if (font_info->name == NULL) | |
1060 | continue; | |
1061 | ||
3d90c96c | 1062 | /* Don't free a default font of some frame. */ |
d5641fc5 GM |
1063 | FOR_EACH_FRAME (tail, frame) |
1064 | { | |
1065 | struct frame *f = XFRAME (frame); | |
1066 | if (FRAME_WINDOW_P (f) | |
d5641fc5 GM |
1067 | && font_info->font == FRAME_FONT (f)) |
1068 | break; | |
1069 | } | |
82641697 | 1070 | |
d5641fc5 | 1071 | if (!NILP (tail)) |
39506348 | 1072 | continue; |
82641697 | 1073 | |
39506348 KH |
1074 | /* Free names. */ |
1075 | if (font_info->full_name != font_info->name) | |
1076 | xfree (font_info->full_name); | |
1077 | xfree (font_info->name); | |
82641697 | 1078 | |
39506348 KH |
1079 | /* Free the font. */ |
1080 | BLOCK_INPUT; | |
c3cee013 | 1081 | #ifdef HAVE_X_WINDOWS |
39506348 | 1082 | XFreeFont (dpyinfo->display, font_info->font); |
c3cee013 JR |
1083 | #endif |
1084 | #ifdef WINDOWSNT | |
39506348 | 1085 | w32_unload_font (dpyinfo, font_info->font); |
c3cee013 | 1086 | #endif |
39506348 | 1087 | UNBLOCK_INPUT; |
82641697 | 1088 | |
39506348 KH |
1089 | /* Mark font table slot free. */ |
1090 | font_info->font = NULL; | |
1091 | font_info->name = font_info->full_name = NULL; | |
1092 | } | |
82641697 GM |
1093 | } |
1094 | ||
c3cee013 | 1095 | #endif /* HAVE_WINDOW_SYSTEM */ |
82641697 GM |
1096 | |
1097 | ||
1098 | \f | |
1099 | /*********************************************************************** | |
1100 | X Pixmaps | |
1101 | ***********************************************************************/ | |
1102 | ||
c3cee013 | 1103 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 | 1104 | |
fef04523 | 1105 | DEFUN ("bitmap-spec-p", Fbitmap_spec_p, Sbitmap_spec_p, 1, 1, 0, |
7ee72033 | 1106 | doc: /* Value is non-nil if OBJECT is a valid bitmap specification. |
228299fa GM |
1107 | A bitmap specification is either a string, a file name, or a list |
1108 | \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap, | |
1109 | HEIGHT is its height, and DATA is a string containing the bits of | |
1110 | the pixmap. Bits are stored row by row, each row occupies | |
7ee72033 MB |
1111 | \(WIDTH + 7)/8 bytes. */) |
1112 | (object) | |
82641697 GM |
1113 | Lisp_Object object; |
1114 | { | |
c7ae3284 | 1115 | int pixmap_p = 0; |
178c5d9c | 1116 | |
c7ae3284 GM |
1117 | if (STRINGP (object)) |
1118 | /* If OBJECT is a string, it's a file name. */ | |
1119 | pixmap_p = 1; | |
1120 | else if (CONSP (object)) | |
1121 | { | |
1122 | /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and | |
1123 | HEIGHT must be integers > 0, and DATA must be string large | |
1124 | enough to hold a bitmap of the specified size. */ | |
1125 | Lisp_Object width, height, data; | |
1126 | ||
1127 | height = width = data = Qnil; | |
178c5d9c | 1128 | |
c7ae3284 GM |
1129 | if (CONSP (object)) |
1130 | { | |
1131 | width = XCAR (object); | |
1132 | object = XCDR (object); | |
1133 | if (CONSP (object)) | |
1134 | { | |
1135 | height = XCAR (object); | |
1136 | object = XCDR (object); | |
1137 | if (CONSP (object)) | |
1138 | data = XCAR (object); | |
1139 | } | |
1140 | } | |
cd0bb842 | 1141 | |
c7ae3284 GM |
1142 | if (NATNUMP (width) && NATNUMP (height) && STRINGP (data)) |
1143 | { | |
1144 | int bytes_per_row = ((XFASTINT (width) + BITS_PER_CHAR - 1) | |
1145 | / BITS_PER_CHAR); | |
6fc556fd | 1146 | if (STRING_BYTES (XSTRING (data)) >= bytes_per_row * XINT (height)) |
c7ae3284 GM |
1147 | pixmap_p = 1; |
1148 | } | |
1149 | } | |
1150 | ||
1151 | return pixmap_p ? Qt : Qnil; | |
cd0bb842 RS |
1152 | } |
1153 | ||
cd0bb842 | 1154 | |
82641697 GM |
1155 | /* Load a bitmap according to NAME (which is either a file name or a |
1156 | pixmap spec) for use on frame F. Value is the bitmap_id (see | |
1157 | xfns.c). If NAME is nil, return with a bitmap id of zero. If | |
1158 | bitmap cannot be loaded, display a message saying so, and return | |
1159 | zero. Store the bitmap width in *W_PTR and its height in *H_PTR, | |
1160 | if these pointers are not null. */ | |
cd0bb842 | 1161 | |
82641697 | 1162 | static int |
cd0bb842 | 1163 | load_pixmap (f, name, w_ptr, h_ptr) |
7812a96f | 1164 | FRAME_PTR f; |
cd0bb842 RS |
1165 | Lisp_Object name; |
1166 | unsigned int *w_ptr, *h_ptr; | |
1167 | { | |
1168 | int bitmap_id; | |
1169 | Lisp_Object tem; | |
1170 | ||
1171 | if (NILP (name)) | |
82641697 | 1172 | return 0; |
cd0bb842 | 1173 | |
fef04523 | 1174 | tem = Fbitmap_spec_p (name); |
cd0bb842 | 1175 | if (NILP (tem)) |
fef04523 | 1176 | wrong_type_argument (Qbitmap_spec_p, name); |
cd0bb842 RS |
1177 | |
1178 | BLOCK_INPUT; | |
cd0bb842 RS |
1179 | if (CONSP (name)) |
1180 | { | |
1181 | /* Decode a bitmap spec into a bitmap. */ | |
1182 | ||
1183 | int h, w; | |
1184 | Lisp_Object bits; | |
1185 | ||
1186 | w = XINT (Fcar (name)); | |
1187 | h = XINT (Fcar (Fcdr (name))); | |
1188 | bits = Fcar (Fcdr (Fcdr (name))); | |
1189 | ||
1190 | bitmap_id = x_create_bitmap_from_data (f, XSTRING (bits)->data, | |
1191 | w, h); | |
1192 | } | |
1193 | else | |
1194 | { | |
1195 | /* It must be a string -- a file name. */ | |
1196 | bitmap_id = x_create_bitmap_from_file (f, name); | |
1197 | } | |
1198 | UNBLOCK_INPUT; | |
1199 | ||
7812a96f | 1200 | if (bitmap_id < 0) |
82641697 | 1201 | { |
1b8f7fbc | 1202 | add_to_log ("Invalid or undefined bitmap %s", name, Qnil); |
82641697 | 1203 | bitmap_id = 0; |
cd0bb842 | 1204 | |
82641697 GM |
1205 | if (w_ptr) |
1206 | *w_ptr = 0; | |
1207 | if (h_ptr) | |
1208 | *h_ptr = 0; | |
1209 | } | |
1210 | else | |
1211 | { | |
1212 | #if GLYPH_DEBUG | |
1213 | ++npixmaps_allocated; | |
1214 | #endif | |
1215 | if (w_ptr) | |
1216 | *w_ptr = x_bitmap_width (f, bitmap_id); | |
1217 | ||
1218 | if (h_ptr) | |
1219 | *h_ptr = x_bitmap_height (f, bitmap_id); | |
1220 | } | |
cd0bb842 RS |
1221 | |
1222 | return bitmap_id; | |
cb637678 | 1223 | } |
87485d6f | 1224 | |
c3cee013 | 1225 | #endif /* HAVE_WINDOW_SYSTEM */ |
82641697 | 1226 | |
87485d6f | 1227 | |
82641697 GM |
1228 | \f |
1229 | /*********************************************************************** | |
1230 | Minimum font bounds | |
1231 | ***********************************************************************/ | |
1232 | ||
c3cee013 | 1233 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 | 1234 | |
d6fc0a22 GM |
1235 | /* Update the line_height of frame F. Return non-zero if line height |
1236 | changes. */ | |
87485d6f | 1237 | |
82641697 GM |
1238 | int |
1239 | frame_update_line_height (f) | |
87485d6f | 1240 | struct frame *f; |
87485d6f | 1241 | { |
39506348 | 1242 | int line_height, changed_p; |
178c5d9c | 1243 | |
39506348 | 1244 | line_height = FONT_HEIGHT (FRAME_FONT (f)); |
c3cee013 JR |
1245 | changed_p = line_height != FRAME_LINE_HEIGHT (f); |
1246 | FRAME_LINE_HEIGHT (f) = line_height; | |
82641697 | 1247 | return changed_p; |
87485d6f MW |
1248 | } |
1249 | ||
c3cee013 | 1250 | #endif /* HAVE_WINDOW_SYSTEM */ |
82641697 GM |
1251 | |
1252 | \f | |
1253 | /*********************************************************************** | |
1254 | Fonts | |
1255 | ***********************************************************************/ | |
1256 | ||
c3cee013 | 1257 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 | 1258 | |
39506348 KH |
1259 | /* Load font of face FACE which is used on frame F to display |
1260 | character C. The name of the font to load is determined by lface | |
1261 | and fontset of FACE. */ | |
82641697 GM |
1262 | |
1263 | static void | |
39506348 | 1264 | load_face_font (f, face, c) |
82641697 GM |
1265 | struct frame *f; |
1266 | struct face *face; | |
39506348 | 1267 | int c; |
87485d6f | 1268 | { |
82641697 | 1269 | struct font_info *font_info = NULL; |
39506348 | 1270 | char *font_name; |
178c5d9c | 1271 | |
82641697 | 1272 | face->font_info_id = -1; |
82641697 | 1273 | face->font = NULL; |
39506348 KH |
1274 | |
1275 | font_name = choose_face_font (f, face->lface, face->fontset, c); | |
1276 | if (!font_name) | |
1277 | return; | |
1278 | ||
82641697 | 1279 | BLOCK_INPUT; |
39506348 | 1280 | font_info = FS_LOAD_FACE_FONT (f, c, font_name, face); |
82641697 GM |
1281 | UNBLOCK_INPUT; |
1282 | ||
1283 | if (font_info) | |
1284 | { | |
39506348 | 1285 | face->font_info_id = font_info->font_idx; |
82641697 GM |
1286 | face->font = font_info->font; |
1287 | face->font_name = font_info->full_name; | |
39506348 | 1288 | if (face->gc) |
82641697 | 1289 | { |
39506348 KH |
1290 | x_free_gc (f, face->gc); |
1291 | face->gc = 0; | |
82641697 GM |
1292 | } |
1293 | } | |
39506348 | 1294 | else |
1b8f7fbc | 1295 | add_to_log ("Unable to load font %s", |
7dbdfcf8 | 1296 | build_string (font_name), Qnil); |
39506348 | 1297 | xfree (font_name); |
87485d6f MW |
1298 | } |
1299 | ||
c3cee013 | 1300 | #endif /* HAVE_WINDOW_SYSTEM */ |
87485d6f | 1301 | |
87485d6f | 1302 | |
82641697 GM |
1303 | \f |
1304 | /*********************************************************************** | |
1305 | X Colors | |
1306 | ***********************************************************************/ | |
1307 | ||
2d764c78 | 1308 | /* A version of defined_color for non-X frames. */ |
08dc08dc | 1309 | |
2d764c78 EZ |
1310 | int |
1311 | tty_defined_color (f, color_name, color_def, alloc) | |
1312 | struct frame *f; | |
1313 | char *color_name; | |
1314 | XColor *color_def; | |
1315 | int alloc; | |
1316 | { | |
1317 | Lisp_Object color_desc; | |
ae4b4ba5 GM |
1318 | unsigned long color_idx = FACE_TTY_DEFAULT_COLOR; |
1319 | unsigned long red = 0, green = 0, blue = 0; | |
2d764c78 EZ |
1320 | int status = 1; |
1321 | ||
1322 | if (*color_name && !NILP (Ffboundp (Qtty_color_desc))) | |
1323 | { | |
a61c12d5 EZ |
1324 | Lisp_Object frame; |
1325 | ||
1326 | XSETFRAME (frame, f); | |
2d764c78 | 1327 | status = 0; |
a61c12d5 | 1328 | color_desc = call2 (Qtty_color_desc, build_string (color_name), frame); |
363e4e42 | 1329 | if (CONSP (color_desc) && CONSP (XCDR (color_desc))) |
2d764c78 EZ |
1330 | { |
1331 | color_idx = XINT (XCAR (XCDR (color_desc))); | |
1332 | if (CONSP (XCDR (XCDR (color_desc)))) | |
1333 | { | |
1334 | red = XINT (XCAR (XCDR (XCDR (color_desc)))); | |
1335 | green = XINT (XCAR (XCDR (XCDR (XCDR (color_desc))))); | |
1336 | blue = XINT (XCAR (XCDR (XCDR (XCDR (XCDR (color_desc)))))); | |
1337 | } | |
1338 | status = 1; | |
1339 | } | |
a61c12d5 | 1340 | else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist")))) |
2d764c78 | 1341 | /* We were called early during startup, and the colors are not |
a61c12d5 | 1342 | yet set up in tty-defined-color-alist. Don't return a failure |
2d764c78 EZ |
1343 | indication, since this produces the annoying "Unable to |
1344 | load color" messages in the *Messages* buffer. */ | |
1345 | status = 1; | |
1346 | } | |
f9d2fdc4 EZ |
1347 | if (color_idx == FACE_TTY_DEFAULT_COLOR && *color_name) |
1348 | { | |
1349 | if (strcmp (color_name, "unspecified-fg") == 0) | |
1350 | color_idx = FACE_TTY_DEFAULT_FG_COLOR; | |
1351 | else if (strcmp (color_name, "unspecified-bg") == 0) | |
1352 | color_idx = FACE_TTY_DEFAULT_BG_COLOR; | |
1353 | } | |
1354 | ||
3b451f74 EZ |
1355 | if (color_idx != FACE_TTY_DEFAULT_COLOR) |
1356 | status = 1; | |
1357 | ||
3a28db80 | 1358 | color_def->pixel = color_idx; |
2d764c78 EZ |
1359 | color_def->red = red; |
1360 | color_def->green = green; | |
1361 | color_def->blue = blue; | |
1362 | ||
1363 | return status; | |
1364 | } | |
1365 | ||
08dc08dc GM |
1366 | |
1367 | /* Decide if color named COLOR_NAME is valid for the display | |
1368 | associated with the frame F; if so, return the rgb values in | |
1369 | COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell. | |
2d764c78 EZ |
1370 | |
1371 | This does the right thing for any type of frame. */ | |
08dc08dc | 1372 | |
2d764c78 EZ |
1373 | int |
1374 | defined_color (f, color_name, color_def, alloc) | |
1375 | struct frame *f; | |
1376 | char *color_name; | |
1377 | XColor *color_def; | |
1378 | int alloc; | |
1379 | { | |
1380 | if (!FRAME_WINDOW_P (f)) | |
1381 | return tty_defined_color (f, color_name, color_def, alloc); | |
82641697 | 1382 | #ifdef HAVE_X_WINDOWS |
2d764c78 EZ |
1383 | else if (FRAME_X_P (f)) |
1384 | return x_defined_color (f, color_name, color_def, alloc); | |
1385 | #endif | |
1386 | #ifdef WINDOWSNT | |
1387 | else if (FRAME_W32_P (f)) | |
2d764c78 EZ |
1388 | return w32_defined_color (f, color_name, color_def, alloc); |
1389 | #endif | |
e0f712ba | 1390 | #ifdef MAC_OS |
2d764c78 | 1391 | else if (FRAME_MAC_P (f)) |
2d764c78 EZ |
1392 | return mac_defined_color (f, color_name, color_def, alloc); |
1393 | #endif | |
1394 | else | |
1395 | abort (); | |
1396 | } | |
1397 | ||
08dc08dc GM |
1398 | |
1399 | /* Given the index IDX of a tty color on frame F, return its name, a | |
1400 | Lisp string. */ | |
2d764c78 EZ |
1401 | |
1402 | Lisp_Object | |
1403 | tty_color_name (f, idx) | |
1404 | struct frame *f; | |
1405 | int idx; | |
1406 | { | |
2d764c78 EZ |
1407 | if (idx >= 0 && !NILP (Ffboundp (Qtty_color_by_index))) |
1408 | { | |
a61c12d5 EZ |
1409 | Lisp_Object frame; |
1410 | Lisp_Object coldesc; | |
1411 | ||
1412 | XSETFRAME (frame, f); | |
1413 | coldesc = call2 (Qtty_color_by_index, make_number (idx), frame); | |
2d764c78 EZ |
1414 | |
1415 | if (!NILP (coldesc)) | |
1416 | return XCAR (coldesc); | |
1417 | } | |
1418 | #ifdef MSDOS | |
1419 | /* We can have an MSDOG frame under -nw for a short window of | |
1420 | opportunity before internal_terminal_init is called. DTRT. */ | |
1421 | if (FRAME_MSDOS_P (f) && !inhibit_window_system) | |
1422 | return msdos_stdcolor_name (idx); | |
1423 | #endif | |
1424 | ||
ef917393 EZ |
1425 | if (idx == FACE_TTY_DEFAULT_FG_COLOR) |
1426 | return build_string (unspecified_fg); | |
1427 | if (idx == FACE_TTY_DEFAULT_BG_COLOR) | |
1428 | return build_string (unspecified_bg); | |
c3cee013 JR |
1429 | |
1430 | #ifdef WINDOWSNT | |
1431 | return vga_stdcolor_name (idx); | |
1432 | #endif | |
1433 | ||
ef917393 | 1434 | return Qunspecified; |
2d764c78 | 1435 | } |
82641697 | 1436 | |
08dc08dc | 1437 | |
82641697 GM |
1438 | /* Return non-zero if COLOR_NAME is a shade of gray (or white or |
1439 | black) on frame F. The algorithm is taken from 20.2 faces.el. */ | |
1440 | ||
1441 | static int | |
1442 | face_color_gray_p (f, color_name) | |
1443 | struct frame *f; | |
1444 | char *color_name; | |
1445 | { | |
1446 | XColor color; | |
1447 | int gray_p; | |
1448 | ||
1449 | if (defined_color (f, color_name, &color, 0)) | |
1450 | gray_p = ((abs (color.red - color.green) | |
1451 | < max (color.red, color.green) / 20) | |
1452 | && (abs (color.green - color.blue) | |
1453 | < max (color.green, color.blue) / 20) | |
1454 | && (abs (color.blue - color.red) | |
1455 | < max (color.blue, color.red) / 20)); | |
87485d6f | 1456 | else |
82641697 | 1457 | gray_p = 0; |
178c5d9c | 1458 | |
82641697 | 1459 | return gray_p; |
87485d6f | 1460 | } |
87485d6f | 1461 | |
cb637678 | 1462 | |
82641697 GM |
1463 | /* Return non-zero if color COLOR_NAME can be displayed on frame F. |
1464 | BACKGROUND_P non-zero means the color will be used as background | |
1465 | color. */ | |
1466 | ||
1467 | static int | |
1468 | face_color_supported_p (f, color_name, background_p) | |
1469 | struct frame *f; | |
1470 | char *color_name; | |
1471 | int background_p; | |
1472 | { | |
1473 | Lisp_Object frame; | |
2d764c78 | 1474 | XColor not_used; |
82641697 GM |
1475 | |
1476 | XSETFRAME (frame, f); | |
8affcced KH |
1477 | return (FRAME_WINDOW_P (f) |
1478 | ? (!NILP (Fxw_display_color_p (frame)) | |
1479 | || xstricmp (color_name, "black") == 0 | |
1480 | || xstricmp (color_name, "white") == 0 | |
1481 | || (background_p | |
1482 | && face_color_gray_p (f, color_name)) | |
1483 | || (!NILP (Fx_display_grayscale_p (frame)) | |
1484 | && face_color_gray_p (f, color_name))) | |
1485 | : tty_defined_color (f, color_name, ¬_used, 0)); | |
2d764c78 | 1486 | } |
82641697 GM |
1487 | |
1488 | ||
da47150d | 1489 | DEFUN ("color-gray-p", Fcolor_gray_p, Scolor_gray_p, 1, 2, 0, |
7ee72033 | 1490 | doc: /* Return non-nil if COLOR is a shade of gray (or white or black). |
228299fa | 1491 | FRAME specifies the frame and thus the display for interpreting COLOR. |
7ee72033 MB |
1492 | If FRAME is nil or omitted, use the selected frame. */) |
1493 | (color, frame) | |
82641697 | 1494 | Lisp_Object color, frame; |
cb637678 | 1495 | { |
2d764c78 EZ |
1496 | struct frame *f; |
1497 | ||
b7826503 PJ |
1498 | CHECK_FRAME (frame); |
1499 | CHECK_STRING (color); | |
2d764c78 | 1500 | f = XFRAME (frame); |
82641697 GM |
1501 | return face_color_gray_p (f, XSTRING (color)->data) ? Qt : Qnil; |
1502 | } | |
660ed669 | 1503 | |
fffc2367 | 1504 | |
da47150d EZ |
1505 | DEFUN ("color-supported-p", Fcolor_supported_p, |
1506 | Scolor_supported_p, 2, 3, 0, | |
7ee72033 | 1507 | doc: /* Return non-nil if COLOR can be displayed on FRAME. |
228299fa GM |
1508 | BACKGROUND-P non-nil means COLOR is used as a background. |
1509 | If FRAME is nil or omitted, use the selected frame. | |
7ee72033 MB |
1510 | COLOR must be a valid color name. */) |
1511 | (color, frame, background_p) | |
82641697 GM |
1512 | Lisp_Object frame, color, background_p; |
1513 | { | |
2d764c78 EZ |
1514 | struct frame *f; |
1515 | ||
b7826503 PJ |
1516 | CHECK_FRAME (frame); |
1517 | CHECK_STRING (color); | |
2d764c78 | 1518 | f = XFRAME (frame); |
82641697 GM |
1519 | if (face_color_supported_p (f, XSTRING (color)->data, !NILP (background_p))) |
1520 | return Qt; | |
1521 | return Qnil; | |
1522 | } | |
7b37f67b | 1523 | |
08dc08dc | 1524 | |
82641697 GM |
1525 | /* Load color with name NAME for use by face FACE on frame F. |
1526 | TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX, | |
1527 | LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX, | |
1528 | LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the | |
1529 | pixel color. If color cannot be loaded, display a message, and | |
1530 | return the foreground, background or underline color of F, but | |
1531 | record that fact in flags of the face so that we don't try to free | |
1532 | these colors. */ | |
1533 | ||
44747bd0 | 1534 | unsigned long |
82641697 GM |
1535 | load_color (f, face, name, target_index) |
1536 | struct frame *f; | |
1537 | struct face *face; | |
1538 | Lisp_Object name; | |
1539 | enum lface_attribute_index target_index; | |
1540 | { | |
1541 | XColor color; | |
178c5d9c | 1542 | |
82641697 GM |
1543 | xassert (STRINGP (name)); |
1544 | xassert (target_index == LFACE_FOREGROUND_INDEX | |
1545 | || target_index == LFACE_BACKGROUND_INDEX | |
1546 | || target_index == LFACE_UNDERLINE_INDEX | |
1547 | || target_index == LFACE_OVERLINE_INDEX | |
1548 | || target_index == LFACE_STRIKE_THROUGH_INDEX | |
1549 | || target_index == LFACE_BOX_INDEX); | |
178c5d9c | 1550 | |
82641697 GM |
1551 | /* if the color map is full, defined_color will return a best match |
1552 | to the values in an existing cell. */ | |
1553 | if (!defined_color (f, XSTRING (name)->data, &color, 1)) | |
1554 | { | |
2d764c78 | 1555 | add_to_log ("Unable to load color \"%s\"", name, Qnil); |
178c5d9c | 1556 | |
82641697 | 1557 | switch (target_index) |
1120eb5e | 1558 | { |
82641697 GM |
1559 | case LFACE_FOREGROUND_INDEX: |
1560 | face->foreground_defaulted_p = 1; | |
1561 | color.pixel = FRAME_FOREGROUND_PIXEL (f); | |
1562 | break; | |
178c5d9c | 1563 | |
82641697 GM |
1564 | case LFACE_BACKGROUND_INDEX: |
1565 | face->background_defaulted_p = 1; | |
1566 | color.pixel = FRAME_BACKGROUND_PIXEL (f); | |
1567 | break; | |
178c5d9c | 1568 | |
82641697 GM |
1569 | case LFACE_UNDERLINE_INDEX: |
1570 | face->underline_defaulted_p = 1; | |
1571 | color.pixel = FRAME_FOREGROUND_PIXEL (f); | |
1572 | break; | |
178c5d9c | 1573 | |
82641697 GM |
1574 | case LFACE_OVERLINE_INDEX: |
1575 | face->overline_color_defaulted_p = 1; | |
1576 | color.pixel = FRAME_FOREGROUND_PIXEL (f); | |
1120eb5e | 1577 | break; |
178c5d9c | 1578 | |
82641697 GM |
1579 | case LFACE_STRIKE_THROUGH_INDEX: |
1580 | face->strike_through_color_defaulted_p = 1; | |
1581 | color.pixel = FRAME_FOREGROUND_PIXEL (f); | |
1582 | break; | |
178c5d9c | 1583 | |
82641697 GM |
1584 | case LFACE_BOX_INDEX: |
1585 | face->box_color_defaulted_p = 1; | |
1586 | color.pixel = FRAME_FOREGROUND_PIXEL (f); | |
1587 | break; | |
1588 | ||
1589 | default: | |
1590 | abort (); | |
1120eb5e | 1591 | } |
82641697 GM |
1592 | } |
1593 | #if GLYPH_DEBUG | |
1594 | else | |
1595 | ++ncolors_allocated; | |
1596 | #endif | |
178c5d9c | 1597 | |
82641697 GM |
1598 | return color.pixel; |
1599 | } | |
1120eb5e | 1600 | |
08dc08dc | 1601 | |
c3cee013 | 1602 | #ifdef HAVE_WINDOW_SYSTEM |
1120eb5e | 1603 | |
82641697 GM |
1604 | /* Load colors for face FACE which is used on frame F. Colors are |
1605 | specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX | |
1606 | of ATTRS. If the background color specified is not supported on F, | |
1607 | try to emulate gray colors with a stipple from Vface_default_stipple. */ | |
1608 | ||
1609 | static void | |
1610 | load_face_colors (f, face, attrs) | |
1611 | struct frame *f; | |
1612 | struct face *face; | |
1613 | Lisp_Object *attrs; | |
1614 | { | |
1615 | Lisp_Object fg, bg; | |
1616 | ||
1617 | bg = attrs[LFACE_BACKGROUND_INDEX]; | |
1618 | fg = attrs[LFACE_FOREGROUND_INDEX]; | |
1619 | ||
1620 | /* Swap colors if face is inverse-video. */ | |
1621 | if (EQ (attrs[LFACE_INVERSE_INDEX], Qt)) | |
1622 | { | |
1623 | Lisp_Object tmp; | |
1624 | tmp = fg; | |
1625 | fg = bg; | |
1626 | bg = tmp; | |
1627 | } | |
1628 | ||
1629 | /* Check for support for foreground, not for background because | |
1630 | face_color_supported_p is smart enough to know that grays are | |
1631 | "supported" as background because we are supposed to use stipple | |
1632 | for them. */ | |
1633 | if (!face_color_supported_p (f, XSTRING (bg)->data, 0) | |
fef04523 | 1634 | && !NILP (Fbitmap_spec_p (Vface_default_stipple))) |
82641697 GM |
1635 | { |
1636 | x_destroy_bitmap (f, face->stipple); | |
1637 | face->stipple = load_pixmap (f, Vface_default_stipple, | |
1638 | &face->pixmap_w, &face->pixmap_h); | |
1639 | } | |
82641697 | 1640 | |
be8a72f4 | 1641 | face->background = load_color (f, face, bg, LFACE_BACKGROUND_INDEX); |
82641697 | 1642 | face->foreground = load_color (f, face, fg, LFACE_FOREGROUND_INDEX); |
cb637678 JB |
1643 | } |
1644 | ||
660ed669 | 1645 | |
82641697 | 1646 | /* Free color PIXEL on frame F. */ |
cd0bb842 | 1647 | |
cb637678 | 1648 | void |
82641697 | 1649 | unload_color (f, pixel) |
cb637678 | 1650 | struct frame *f; |
82641697 | 1651 | unsigned long pixel; |
cb637678 | 1652 | { |
c3cee013 | 1653 | #ifdef HAVE_X_WINDOWS |
30a7ac22 GM |
1654 | if (pixel != -1) |
1655 | { | |
1656 | BLOCK_INPUT; | |
1657 | x_free_colors (f, &pixel, 1); | |
1658 | UNBLOCK_INPUT; | |
1659 | } | |
c3cee013 | 1660 | #endif |
82641697 GM |
1661 | } |
1662 | ||
1663 | ||
1664 | /* Free colors allocated for FACE. */ | |
1665 | ||
1666 | static void | |
1667 | free_face_colors (f, face) | |
1668 | struct frame *f; | |
1669 | struct face *face; | |
1670 | { | |
c3cee013 | 1671 | #ifdef HAVE_X_WINDOWS |
28a072fe GM |
1672 | if (face->colors_copied_bitwise_p) |
1673 | return; | |
1674 | ||
08dc08dc | 1675 | BLOCK_INPUT; |
178c5d9c | 1676 | |
08dc08dc GM |
1677 | if (!face->foreground_defaulted_p) |
1678 | { | |
1679 | x_free_colors (f, &face->foreground, 1); | |
1680 | IF_DEBUG (--ncolors_allocated); | |
1681 | } | |
178c5d9c | 1682 | |
08dc08dc GM |
1683 | if (!face->background_defaulted_p) |
1684 | { | |
1685 | x_free_colors (f, &face->background, 1); | |
1686 | IF_DEBUG (--ncolors_allocated); | |
1687 | } | |
82641697 | 1688 | |
08dc08dc GM |
1689 | if (face->underline_p |
1690 | && !face->underline_defaulted_p) | |
1691 | { | |
1692 | x_free_colors (f, &face->underline_color, 1); | |
1693 | IF_DEBUG (--ncolors_allocated); | |
1694 | } | |
82641697 | 1695 | |
08dc08dc GM |
1696 | if (face->overline_p |
1697 | && !face->overline_color_defaulted_p) | |
1698 | { | |
1699 | x_free_colors (f, &face->overline_color, 1); | |
1700 | IF_DEBUG (--ncolors_allocated); | |
1701 | } | |
82641697 | 1702 | |
08dc08dc GM |
1703 | if (face->strike_through_p |
1704 | && !face->strike_through_color_defaulted_p) | |
1705 | { | |
1706 | x_free_colors (f, &face->strike_through_color, 1); | |
1707 | IF_DEBUG (--ncolors_allocated); | |
1708 | } | |
82641697 | 1709 | |
08dc08dc GM |
1710 | if (face->box != FACE_NO_BOX |
1711 | && !face->box_color_defaulted_p) | |
1712 | { | |
1713 | x_free_colors (f, &face->box_color, 1); | |
1714 | IF_DEBUG (--ncolors_allocated); | |
82641697 | 1715 | } |
08dc08dc GM |
1716 | |
1717 | UNBLOCK_INPUT; | |
2d764c78 | 1718 | #endif /* HAVE_X_WINDOWS */ |
c3cee013 | 1719 | } |
08dc08dc | 1720 | |
c3cee013 | 1721 | #endif /* HAVE_WINDOW_SYSTEM */ |
82641697 GM |
1722 | |
1723 | ||
1724 | \f | |
1725 | /*********************************************************************** | |
1726 | XLFD Font Names | |
1727 | ***********************************************************************/ | |
1728 | ||
1729 | /* An enumerator for each field of an XLFD font name. */ | |
1730 | ||
1731 | enum xlfd_field | |
1732 | { | |
1733 | XLFD_FOUNDRY, | |
1734 | XLFD_FAMILY, | |
1735 | XLFD_WEIGHT, | |
1736 | XLFD_SLANT, | |
1737 | XLFD_SWIDTH, | |
1738 | XLFD_ADSTYLE, | |
1739 | XLFD_PIXEL_SIZE, | |
1740 | XLFD_POINT_SIZE, | |
1741 | XLFD_RESX, | |
1742 | XLFD_RESY, | |
1743 | XLFD_SPACING, | |
1744 | XLFD_AVGWIDTH, | |
1745 | XLFD_REGISTRY, | |
1746 | XLFD_ENCODING, | |
1747 | XLFD_LAST | |
1748 | }; | |
1749 | ||
178c5d9c | 1750 | /* An enumerator for each possible slant value of a font. Taken from |
82641697 GM |
1751 | the XLFD specification. */ |
1752 | ||
1753 | enum xlfd_slant | |
1754 | { | |
1755 | XLFD_SLANT_UNKNOWN, | |
1756 | XLFD_SLANT_ROMAN, | |
1757 | XLFD_SLANT_ITALIC, | |
1758 | XLFD_SLANT_OBLIQUE, | |
1759 | XLFD_SLANT_REVERSE_ITALIC, | |
1760 | XLFD_SLANT_REVERSE_OBLIQUE, | |
1761 | XLFD_SLANT_OTHER | |
1762 | }; | |
1763 | ||
1764 | /* Relative font weight according to XLFD documentation. */ | |
1765 | ||
1766 | enum xlfd_weight | |
1767 | { | |
1768 | XLFD_WEIGHT_UNKNOWN, | |
1769 | XLFD_WEIGHT_ULTRA_LIGHT, /* 10 */ | |
1770 | XLFD_WEIGHT_EXTRA_LIGHT, /* 20 */ | |
1771 | XLFD_WEIGHT_LIGHT, /* 30 */ | |
1772 | XLFD_WEIGHT_SEMI_LIGHT, /* 40: SemiLight, Book, ... */ | |
1773 | XLFD_WEIGHT_MEDIUM, /* 50: Medium, Normal, Regular, ... */ | |
1774 | XLFD_WEIGHT_SEMI_BOLD, /* 60: SemiBold, DemiBold, ... */ | |
1775 | XLFD_WEIGHT_BOLD, /* 70: Bold, ... */ | |
1776 | XLFD_WEIGHT_EXTRA_BOLD, /* 80: ExtraBold, Heavy, ... */ | |
1777 | XLFD_WEIGHT_ULTRA_BOLD /* 90: UltraBold, Black, ... */ | |
1778 | }; | |
1779 | ||
1780 | /* Relative proportionate width. */ | |
1781 | ||
1782 | enum xlfd_swidth | |
1783 | { | |
1784 | XLFD_SWIDTH_UNKNOWN, | |
1785 | XLFD_SWIDTH_ULTRA_CONDENSED, /* 10 */ | |
1786 | XLFD_SWIDTH_EXTRA_CONDENSED, /* 20 */ | |
1787 | XLFD_SWIDTH_CONDENSED, /* 30: Condensed, Narrow, Compressed, ... */ | |
1788 | XLFD_SWIDTH_SEMI_CONDENSED, /* 40: semicondensed */ | |
1789 | XLFD_SWIDTH_MEDIUM, /* 50: Medium, Normal, Regular, ... */ | |
1790 | XLFD_SWIDTH_SEMI_EXPANDED, /* 60: SemiExpanded, DemiExpanded, ... */ | |
1791 | XLFD_SWIDTH_EXPANDED, /* 70: Expanded... */ | |
1792 | XLFD_SWIDTH_EXTRA_EXPANDED, /* 80: ExtraExpanded, Wide... */ | |
1793 | XLFD_SWIDTH_ULTRA_EXPANDED /* 90: UltraExpanded... */ | |
1794 | }; | |
1795 | ||
1796 | /* Structure used for tables mapping XLFD weight, slant, and width | |
1797 | names to numeric and symbolic values. */ | |
1798 | ||
1799 | struct table_entry | |
1800 | { | |
1801 | char *name; | |
1802 | int numeric; | |
1803 | Lisp_Object *symbol; | |
1804 | }; | |
1805 | ||
1806 | /* Table of XLFD slant names and their numeric and symbolic | |
1807 | representations. This table must be sorted by slant names in | |
1808 | ascending order. */ | |
1809 | ||
1810 | static struct table_entry slant_table[] = | |
1811 | { | |
1812 | {"i", XLFD_SLANT_ITALIC, &Qitalic}, | |
1813 | {"o", XLFD_SLANT_OBLIQUE, &Qoblique}, | |
1814 | {"ot", XLFD_SLANT_OTHER, &Qitalic}, | |
1815 | {"r", XLFD_SLANT_ROMAN, &Qnormal}, | |
1816 | {"ri", XLFD_SLANT_REVERSE_ITALIC, &Qreverse_italic}, | |
1817 | {"ro", XLFD_SLANT_REVERSE_OBLIQUE, &Qreverse_oblique} | |
1818 | }; | |
1819 | ||
1820 | /* Table of XLFD weight names. This table must be sorted by weight | |
1821 | names in ascending order. */ | |
1822 | ||
1823 | static struct table_entry weight_table[] = | |
1824 | { | |
1825 | {"black", XLFD_WEIGHT_ULTRA_BOLD, &Qultra_bold}, | |
1826 | {"bold", XLFD_WEIGHT_BOLD, &Qbold}, | |
1827 | {"book", XLFD_WEIGHT_SEMI_LIGHT, &Qsemi_light}, | |
a288d0d1 | 1828 | {"demi", XLFD_WEIGHT_SEMI_BOLD, &Qsemi_bold}, |
82641697 GM |
1829 | {"demibold", XLFD_WEIGHT_SEMI_BOLD, &Qsemi_bold}, |
1830 | {"extralight", XLFD_WEIGHT_EXTRA_LIGHT, &Qextra_light}, | |
1831 | {"extrabold", XLFD_WEIGHT_EXTRA_BOLD, &Qextra_bold}, | |
1832 | {"heavy", XLFD_WEIGHT_EXTRA_BOLD, &Qextra_bold}, | |
1833 | {"light", XLFD_WEIGHT_LIGHT, &Qlight}, | |
1834 | {"medium", XLFD_WEIGHT_MEDIUM, &Qnormal}, | |
1835 | {"normal", XLFD_WEIGHT_MEDIUM, &Qnormal}, | |
1836 | {"regular", XLFD_WEIGHT_MEDIUM, &Qnormal}, | |
1837 | {"semibold", XLFD_WEIGHT_SEMI_BOLD, &Qsemi_bold}, | |
1838 | {"semilight", XLFD_WEIGHT_SEMI_LIGHT, &Qsemi_light}, | |
1839 | {"ultralight", XLFD_WEIGHT_ULTRA_LIGHT, &Qultra_light}, | |
1840 | {"ultrabold", XLFD_WEIGHT_ULTRA_BOLD, &Qultra_bold} | |
1841 | }; | |
1842 | ||
1843 | /* Table of XLFD width names. This table must be sorted by width | |
1844 | names in ascending order. */ | |
1845 | ||
1846 | static struct table_entry swidth_table[] = | |
1847 | { | |
1848 | {"compressed", XLFD_SWIDTH_CONDENSED, &Qcondensed}, | |
1849 | {"condensed", XLFD_SWIDTH_CONDENSED, &Qcondensed}, | |
1850 | {"demiexpanded", XLFD_SWIDTH_SEMI_EXPANDED, &Qsemi_expanded}, | |
1851 | {"expanded", XLFD_SWIDTH_EXPANDED, &Qexpanded}, | |
1852 | {"extracondensed", XLFD_SWIDTH_EXTRA_CONDENSED, &Qextra_condensed}, | |
1853 | {"extraexpanded", XLFD_SWIDTH_EXTRA_EXPANDED, &Qextra_expanded}, | |
1854 | {"medium", XLFD_SWIDTH_MEDIUM, &Qnormal}, | |
1855 | {"narrow", XLFD_SWIDTH_CONDENSED, &Qcondensed}, | |
1856 | {"normal", XLFD_SWIDTH_MEDIUM, &Qnormal}, | |
1857 | {"regular", XLFD_SWIDTH_MEDIUM, &Qnormal}, | |
1858 | {"semicondensed", XLFD_SWIDTH_SEMI_CONDENSED, &Qsemi_condensed}, | |
1859 | {"semiexpanded", XLFD_SWIDTH_SEMI_EXPANDED, &Qsemi_expanded}, | |
1860 | {"ultracondensed", XLFD_SWIDTH_ULTRA_CONDENSED, &Qultra_condensed}, | |
1861 | {"ultraexpanded", XLFD_SWIDTH_ULTRA_EXPANDED, &Qultra_expanded}, | |
1862 | {"wide", XLFD_SWIDTH_EXTRA_EXPANDED, &Qextra_expanded} | |
1863 | }; | |
1864 | ||
1865 | /* Structure used to hold the result of splitting font names in XLFD | |
1866 | format into their fields. */ | |
1867 | ||
1868 | struct font_name | |
1869 | { | |
1870 | /* The original name which is modified destructively by | |
1871 | split_font_name. The pointer is kept here to be able to free it | |
1872 | if it was allocated from the heap. */ | |
1873 | char *name; | |
1874 | ||
1875 | /* Font name fields. Each vector element points into `name' above. | |
1876 | Fields are NUL-terminated. */ | |
1877 | char *fields[XLFD_LAST]; | |
1878 | ||
1879 | /* Numeric values for those fields that interest us. See | |
1880 | split_font_name for which these are. */ | |
1881 | int numeric[XLFD_LAST]; | |
8e1b21a7 KH |
1882 | |
1883 | /* Lower value mean higher priority. */ | |
1884 | int registry_priority; | |
82641697 GM |
1885 | }; |
1886 | ||
1887 | /* The frame in effect when sorting font names. Set temporarily in | |
1888 | sort_fonts so that it is available in font comparison functions. */ | |
1889 | ||
1890 | static struct frame *font_frame; | |
1891 | ||
1892 | /* Order by which font selection chooses fonts. The default values | |
1893 | mean `first, find a best match for the font width, then for the | |
1894 | font height, then for weight, then for slant.' This variable can be | |
1895 | set via set-face-font-sort-order. */ | |
1896 | ||
e0f712ba | 1897 | #ifdef MAC_OS |
a08332c0 GM |
1898 | static int font_sort_order[4] = { |
1899 | XLFD_SWIDTH, XLFD_POINT_SIZE, XLFD_WEIGHT, XLFD_SLANT | |
1900 | }; | |
1a578e9b | 1901 | #else |
82641697 | 1902 | static int font_sort_order[4]; |
1a578e9b | 1903 | #endif |
82641697 GM |
1904 | |
1905 | /* Look up FONT.fields[FIELD_INDEX] in TABLE which has DIM entries. | |
1906 | TABLE must be sorted by TABLE[i]->name in ascending order. Value | |
1907 | is a pointer to the matching table entry or null if no table entry | |
1908 | matches. */ | |
1909 | ||
1910 | static struct table_entry * | |
1911 | xlfd_lookup_field_contents (table, dim, font, field_index) | |
1912 | struct table_entry *table; | |
1913 | int dim; | |
1914 | struct font_name *font; | |
1915 | int field_index; | |
1916 | { | |
1917 | /* Function split_font_name converts fields to lower-case, so there | |
1918 | is no need to use xstrlwr or xstricmp here. */ | |
1919 | char *s = font->fields[field_index]; | |
1920 | int low, mid, high, cmp; | |
1921 | ||
1922 | low = 0; | |
1923 | high = dim - 1; | |
1924 | ||
1925 | while (low <= high) | |
1926 | { | |
1927 | mid = (low + high) / 2; | |
1928 | cmp = strcmp (table[mid].name, s); | |
178c5d9c | 1929 | |
82641697 GM |
1930 | if (cmp < 0) |
1931 | low = mid + 1; | |
1932 | else if (cmp > 0) | |
1933 | high = mid - 1; | |
1934 | else | |
1935 | return table + mid; | |
1936 | } | |
1937 | ||
1938 | return NULL; | |
1939 | } | |
1940 | ||
1941 | ||
1942 | /* Return a numeric representation for font name field | |
1943 | FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which | |
1944 | has DIM entries. Value is the numeric value found or DFLT if no | |
1945 | table entry matches. This function is used to translate weight, | |
1946 | slant, and swidth names of XLFD font names to numeric values. */ | |
1947 | ||
1948 | static INLINE int | |
1949 | xlfd_numeric_value (table, dim, font, field_index, dflt) | |
1950 | struct table_entry *table; | |
1951 | int dim; | |
1952 | struct font_name *font; | |
1953 | int field_index; | |
1954 | int dflt; | |
1955 | { | |
1956 | struct table_entry *p; | |
1957 | p = xlfd_lookup_field_contents (table, dim, font, field_index); | |
1958 | return p ? p->numeric : dflt; | |
1959 | } | |
1960 | ||
1961 | ||
1962 | /* Return a symbolic representation for font name field | |
1963 | FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which | |
1964 | has DIM entries. Value is the symbolic value found or DFLT if no | |
1965 | table entry matches. This function is used to translate weight, | |
1966 | slant, and swidth names of XLFD font names to symbols. */ | |
1967 | ||
1968 | static INLINE Lisp_Object | |
1969 | xlfd_symbolic_value (table, dim, font, field_index, dflt) | |
1970 | struct table_entry *table; | |
1971 | int dim; | |
1972 | struct font_name *font; | |
1973 | int field_index; | |
6fc556fd | 1974 | Lisp_Object dflt; |
82641697 GM |
1975 | { |
1976 | struct table_entry *p; | |
1977 | p = xlfd_lookup_field_contents (table, dim, font, field_index); | |
1978 | return p ? *p->symbol : dflt; | |
1979 | } | |
1980 | ||
1981 | ||
1982 | /* Return a numeric value for the slant of the font given by FONT. */ | |
1983 | ||
1984 | static INLINE int | |
1985 | xlfd_numeric_slant (font) | |
1986 | struct font_name *font; | |
1987 | { | |
1988 | return xlfd_numeric_value (slant_table, DIM (slant_table), | |
1989 | font, XLFD_SLANT, XLFD_SLANT_ROMAN); | |
1990 | } | |
1991 | ||
1992 | ||
1993 | /* Return a symbol representing the weight of the font given by FONT. */ | |
1994 | ||
1995 | static INLINE Lisp_Object | |
1996 | xlfd_symbolic_slant (font) | |
1997 | struct font_name *font; | |
1998 | { | |
1999 | return xlfd_symbolic_value (slant_table, DIM (slant_table), | |
2000 | font, XLFD_SLANT, Qnormal); | |
2001 | } | |
2002 | ||
2003 | ||
2004 | /* Return a numeric value for the weight of the font given by FONT. */ | |
2005 | ||
2006 | static INLINE int | |
2007 | xlfd_numeric_weight (font) | |
2008 | struct font_name *font; | |
2009 | { | |
2010 | return xlfd_numeric_value (weight_table, DIM (weight_table), | |
2011 | font, XLFD_WEIGHT, XLFD_WEIGHT_MEDIUM); | |
2012 | } | |
2013 | ||
2014 | ||
2015 | /* Return a symbol representing the slant of the font given by FONT. */ | |
2016 | ||
2017 | static INLINE Lisp_Object | |
2018 | xlfd_symbolic_weight (font) | |
2019 | struct font_name *font; | |
2020 | { | |
2021 | return xlfd_symbolic_value (weight_table, DIM (weight_table), | |
2022 | font, XLFD_WEIGHT, Qnormal); | |
2023 | } | |
2024 | ||
2025 | ||
2026 | /* Return a numeric value for the swidth of the font whose XLFD font | |
2027 | name fields are found in FONT. */ | |
2028 | ||
2029 | static INLINE int | |
2030 | xlfd_numeric_swidth (font) | |
2031 | struct font_name *font; | |
2032 | { | |
2033 | return xlfd_numeric_value (swidth_table, DIM (swidth_table), | |
2034 | font, XLFD_SWIDTH, XLFD_SWIDTH_MEDIUM); | |
2035 | } | |
2036 | ||
2037 | ||
2038 | /* Return a symbolic value for the swidth of FONT. */ | |
2039 | ||
2040 | static INLINE Lisp_Object | |
2041 | xlfd_symbolic_swidth (font) | |
2042 | struct font_name *font; | |
2043 | { | |
2044 | return xlfd_symbolic_value (swidth_table, DIM (swidth_table), | |
2045 | font, XLFD_SWIDTH, Qnormal); | |
2046 | } | |
178c5d9c | 2047 | |
82641697 GM |
2048 | |
2049 | /* Look up the entry of SYMBOL in the vector TABLE which has DIM | |
2050 | entries. Value is a pointer to the matching table entry or null if | |
2051 | no element of TABLE contains SYMBOL. */ | |
2052 | ||
2053 | static struct table_entry * | |
2054 | face_value (table, dim, symbol) | |
2055 | struct table_entry *table; | |
2056 | int dim; | |
2057 | Lisp_Object symbol; | |
2058 | { | |
2059 | int i; | |
2060 | ||
2061 | xassert (SYMBOLP (symbol)); | |
178c5d9c | 2062 | |
82641697 GM |
2063 | for (i = 0; i < dim; ++i) |
2064 | if (EQ (*table[i].symbol, symbol)) | |
2065 | break; | |
2066 | ||
2067 | return i < dim ? table + i : NULL; | |
2068 | } | |
2069 | ||
2070 | ||
2071 | /* Return a numeric value for SYMBOL in the vector TABLE which has DIM | |
2072 | entries. Value is -1 if SYMBOL is not found in TABLE. */ | |
2073 | ||
2074 | static INLINE int | |
2075 | face_numeric_value (table, dim, symbol) | |
2076 | struct table_entry *table; | |
2077 | int dim; | |
2078 | Lisp_Object symbol; | |
2079 | { | |
2080 | struct table_entry *p = face_value (table, dim, symbol); | |
2081 | return p ? p->numeric : -1; | |
2082 | } | |
2083 | ||
2084 | ||
2085 | /* Return a numeric value representing the weight specified by Lisp | |
2086 | symbol WEIGHT. Value is one of the enumerators of enum | |
2087 | xlfd_weight. */ | |
2088 | ||
2089 | static INLINE int | |
2090 | face_numeric_weight (weight) | |
2091 | Lisp_Object weight; | |
2092 | { | |
2093 | return face_numeric_value (weight_table, DIM (weight_table), weight); | |
2094 | } | |
2095 | ||
2096 | ||
2097 | /* Return a numeric value representing the slant specified by Lisp | |
2098 | symbol SLANT. Value is one of the enumerators of enum xlfd_slant. */ | |
2099 | ||
2100 | static INLINE int | |
2101 | face_numeric_slant (slant) | |
2102 | Lisp_Object slant; | |
2103 | { | |
2104 | return face_numeric_value (slant_table, DIM (slant_table), slant); | |
2105 | } | |
2106 | ||
2107 | ||
2108 | /* Return a numeric value representing the swidth specified by Lisp | |
2109 | symbol WIDTH. Value is one of the enumerators of enum xlfd_swidth. */ | |
2110 | ||
2111 | static int | |
2112 | face_numeric_swidth (width) | |
2113 | Lisp_Object width; | |
2114 | { | |
2115 | return face_numeric_value (swidth_table, DIM (swidth_table), width); | |
2116 | } | |
2117 | ||
2118 | ||
c3cee013 | 2119 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 GM |
2120 | |
2121 | /* Return non-zero if FONT is the name of a fixed-pitch font. */ | |
2122 | ||
2123 | static INLINE int | |
2124 | xlfd_fixed_p (font) | |
2125 | struct font_name *font; | |
2126 | { | |
2127 | /* Function split_font_name converts fields to lower-case, so there | |
2128 | is no need to use tolower here. */ | |
2129 | return *font->fields[XLFD_SPACING] != 'p'; | |
2130 | } | |
2131 | ||
2132 | ||
2133 | /* Return the point size of FONT on frame F, measured in 1/10 pt. | |
2134 | ||
2135 | The actual height of the font when displayed on F depends on the | |
2136 | resolution of both the font and frame. For example, a 10pt font | |
2137 | designed for a 100dpi display will display larger than 10pt on a | |
2138 | 75dpi display. (It's not unusual to use fonts not designed for the | |
2139 | display one is using. For example, some intlfonts are available in | |
2140 | 72dpi versions, only.) | |
2141 | ||
2142 | Value is the real point size of FONT on frame F, or 0 if it cannot | |
2143 | be determined. */ | |
2144 | ||
2145 | static INLINE int | |
2146 | xlfd_point_size (f, font) | |
2147 | struct frame *f; | |
2148 | struct font_name *font; | |
2149 | { | |
2150 | double resy = FRAME_X_DISPLAY_INFO (f)->resy; | |
933b0249 GM |
2151 | char *pixel_field = font->fields[XLFD_PIXEL_SIZE]; |
2152 | double pixel; | |
82641697 GM |
2153 | int real_pt; |
2154 | ||
933b0249 GM |
2155 | if (*pixel_field == '[') |
2156 | { | |
2157 | /* The pixel size field is `[A B C D]' which specifies | |
2158 | a transformation matrix. | |
2159 | ||
2160 | A B 0 | |
2161 | C D 0 | |
2162 | 0 0 1 | |
2163 | ||
2164 | by which all glyphs of the font are transformed. The spec | |
2165 | says that s scalar value N for the pixel size is equivalent | |
2166 | to A = N * resx/resy, B = C = 0, D = N. */ | |
2167 | char *start = pixel_field + 1, *end; | |
2168 | double matrix[4]; | |
2169 | int i; | |
2170 | ||
2171 | for (i = 0; i < 4; ++i) | |
2172 | { | |
2173 | matrix[i] = strtod (start, &end); | |
2174 | start = end; | |
2175 | } | |
2176 | ||
7eb4b061 | 2177 | pixel = matrix[3]; |
933b0249 GM |
2178 | } |
2179 | else | |
2180 | pixel = atoi (pixel_field); | |
2181 | ||
2182 | if (pixel == 0) | |
82641697 GM |
2183 | real_pt = 0; |
2184 | else | |
933b0249 | 2185 | real_pt = PT_PER_INCH * 10.0 * pixel / resy + 0.5; |
82641697 GM |
2186 | |
2187 | return real_pt; | |
2188 | } | |
2189 | ||
2190 | ||
39506348 KH |
2191 | /* Return point size of PIXEL dots while considering Y-resultion (DPI) |
2192 | of frame F. This function is used to guess a point size of font | |
2193 | when only the pixel height of the font is available. */ | |
2194 | ||
2195 | static INLINE int | |
2196 | pixel_point_size (f, pixel) | |
2197 | struct frame *f; | |
2198 | int pixel; | |
2199 | { | |
2200 | double resy = FRAME_X_DISPLAY_INFO (f)->resy; | |
2201 | double real_pt; | |
2202 | int int_pt; | |
2203 | ||
c660ce4e GM |
2204 | /* As one inch is PT_PER_INCH points, PT_PER_INCH/RESY gives the |
2205 | point size of one dot. */ | |
2206 | real_pt = pixel * PT_PER_INCH / resy; | |
39506348 KH |
2207 | int_pt = real_pt + 0.5; |
2208 | ||
2209 | return int_pt; | |
2210 | } | |
2211 | ||
2212 | ||
82641697 GM |
2213 | /* Split XLFD font name FONT->name destructively into NUL-terminated, |
2214 | lower-case fields in FONT->fields. NUMERIC_P non-zero means | |
2215 | compute numeric values for fields XLFD_POINT_SIZE, XLFD_SWIDTH, | |
2216 | XLFD_RESY, XLFD_SLANT, and XLFD_WEIGHT in FONT->numeric. Value is | |
2217 | zero if the font name doesn't have the format we expect. The | |
2218 | expected format is a font name that starts with a `-' and has | |
933b0249 | 2219 | XLFD_LAST fields separated by `-'. */ |
82641697 GM |
2220 | |
2221 | static int | |
2222 | split_font_name (f, font, numeric_p) | |
2223 | struct frame *f; | |
2224 | struct font_name *font; | |
2225 | int numeric_p; | |
2226 | { | |
2227 | int i = 0; | |
2228 | int success_p; | |
2229 | ||
2230 | if (*font->name == '-') | |
2231 | { | |
2232 | char *p = xstrlwr (font->name) + 1; | |
2233 | ||
7b16a6bf | 2234 | while (i < XLFD_LAST) |
82641697 GM |
2235 | { |
2236 | font->fields[i] = p; | |
7b16a6bf | 2237 | ++i; |
933b0249 GM |
2238 | |
2239 | /* Pixel and point size may be of the form `[....]'. For | |
2240 | BNF, see XLFD spec, chapter 4. Negative values are | |
2241 | indicated by tilde characters which we replace with | |
2242 | `-' characters, here. */ | |
2243 | if (*p == '[' | |
d5188d8c GM |
2244 | && (i - 1 == XLFD_PIXEL_SIZE |
2245 | || i - 1 == XLFD_POINT_SIZE)) | |
933b0249 GM |
2246 | { |
2247 | char *start, *end; | |
2248 | int j; | |
2249 | ||
2250 | for (++p; *p && *p != ']'; ++p) | |
2251 | if (*p == '~') | |
2252 | *p = '-'; | |
2253 | ||
2254 | /* Check that the matrix contains 4 floating point | |
2255 | numbers. */ | |
3849cbf4 | 2256 | for (j = 0, start = font->fields[i - 1] + 1; |
933b0249 GM |
2257 | j < 4; |
2258 | ++j, start = end) | |
2259 | if (strtod (start, &end) == 0 && start == end) | |
2260 | break; | |
2261 | ||
2262 | if (j < 4) | |
2263 | break; | |
2264 | } | |
178c5d9c | 2265 | |
82641697 GM |
2266 | while (*p && *p != '-') |
2267 | ++p; | |
178c5d9c | 2268 | |
82641697 GM |
2269 | if (*p != '-') |
2270 | break; | |
178c5d9c | 2271 | |
82641697 GM |
2272 | *p++ = 0; |
2273 | } | |
2274 | } | |
2275 | ||
2276 | success_p = i == XLFD_LAST; | |
2277 | ||
2278 | /* If requested, and font name was in the expected format, | |
2279 | compute numeric values for some fields. */ | |
2280 | if (numeric_p && success_p) | |
2281 | { | |
2282 | font->numeric[XLFD_POINT_SIZE] = xlfd_point_size (f, font); | |
2283 | font->numeric[XLFD_RESY] = atoi (font->fields[XLFD_RESY]); | |
2284 | font->numeric[XLFD_SLANT] = xlfd_numeric_slant (font); | |
2285 | font->numeric[XLFD_WEIGHT] = xlfd_numeric_weight (font); | |
2286 | font->numeric[XLFD_SWIDTH] = xlfd_numeric_swidth (font); | |
a08332c0 | 2287 | font->numeric[XLFD_AVGWIDTH] = atoi (font->fields[XLFD_AVGWIDTH]); |
82641697 GM |
2288 | } |
2289 | ||
8e1b21a7 KH |
2290 | /* Initialize it to zero. It will be overridden by font_list while |
2291 | trying alternate registries. */ | |
2292 | font->registry_priority = 0; | |
2293 | ||
82641697 GM |
2294 | return success_p; |
2295 | } | |
2296 | ||
2297 | ||
2298 | /* Build an XLFD font name from font name fields in FONT. Value is a | |
2299 | pointer to the font name, which is allocated via xmalloc. */ | |
178c5d9c | 2300 | |
82641697 GM |
2301 | static char * |
2302 | build_font_name (font) | |
2303 | struct font_name *font; | |
2304 | { | |
2305 | int i; | |
2306 | int size = 100; | |
2307 | char *font_name = (char *) xmalloc (size); | |
2308 | int total_length = 0; | |
2309 | ||
2310 | for (i = 0; i < XLFD_LAST; ++i) | |
2311 | { | |
2312 | /* Add 1 because of the leading `-'. */ | |
2313 | int len = strlen (font->fields[i]) + 1; | |
2314 | ||
2315 | /* Reallocate font_name if necessary. Add 1 for the final | |
2316 | NUL-byte. */ | |
2317 | if (total_length + len + 1 >= size) | |
2318 | { | |
2319 | int new_size = max (2 * size, size + len + 1); | |
2320 | int sz = new_size * sizeof *font_name; | |
2321 | font_name = (char *) xrealloc (font_name, sz); | |
2322 | size = new_size; | |
2323 | } | |
2324 | ||
2325 | font_name[total_length] = '-'; | |
2326 | bcopy (font->fields[i], font_name + total_length + 1, len - 1); | |
2327 | total_length += len; | |
2328 | } | |
2329 | ||
2330 | font_name[total_length] = 0; | |
2331 | return font_name; | |
2332 | } | |
2333 | ||
2334 | ||
2335 | /* Free an array FONTS of N font_name structures. This frees FONTS | |
2336 | itself and all `name' fields in its elements. */ | |
2337 | ||
2338 | static INLINE void | |
2339 | free_font_names (fonts, n) | |
2340 | struct font_name *fonts; | |
2341 | int n; | |
2342 | { | |
2343 | while (n) | |
2344 | xfree (fonts[--n].name); | |
2345 | xfree (fonts); | |
2346 | } | |
2347 | ||
2348 | ||
2349 | /* Sort vector FONTS of font_name structures which contains NFONTS | |
2350 | elements using qsort and comparison function CMPFN. F is the frame | |
2351 | on which the fonts will be used. The global variable font_frame | |
2352 | is temporarily set to F to make it available in CMPFN. */ | |
2353 | ||
2354 | static INLINE void | |
2355 | sort_fonts (f, fonts, nfonts, cmpfn) | |
2356 | struct frame *f; | |
2357 | struct font_name *fonts; | |
2358 | int nfonts; | |
2359 | int (*cmpfn) P_ ((const void *, const void *)); | |
2360 | { | |
2361 | font_frame = f; | |
2362 | qsort (fonts, nfonts, sizeof *fonts, cmpfn); | |
2363 | font_frame = NULL; | |
2364 | } | |
2365 | ||
2366 | ||
2367 | /* Get fonts matching PATTERN on frame F. If F is null, use the first | |
2368 | display in x_display_list. FONTS is a pointer to a vector of | |
2369 | NFONTS font_name structures. TRY_ALTERNATIVES_P non-zero means try | |
2370 | alternative patterns from Valternate_fontname_alist if no fonts are | |
702a1e8e | 2371 | found matching PATTERN. |
82641697 GM |
2372 | |
2373 | For all fonts found, set FONTS[i].name to the name of the font, | |
2374 | allocated via xmalloc, and split font names into fields. Ignore | |
a86110a8 | 2375 | fonts that we can't parse. Value is the number of fonts found. */ |
82641697 GM |
2376 | |
2377 | static int | |
702a1e8e | 2378 | x_face_list_fonts (f, pattern, fonts, nfonts, try_alternatives_p) |
82641697 GM |
2379 | struct frame *f; |
2380 | char *pattern; | |
2381 | struct font_name *fonts; | |
2382 | int nfonts, try_alternatives_p; | |
82641697 | 2383 | { |
702a1e8e | 2384 | int n, nignored; |
82641697 | 2385 | |
c3cee013 JR |
2386 | /* NTEMACS_TODO : currently this uses w32_list_fonts, but it may be |
2387 | better to do it the other way around. */ | |
2388 | Lisp_Object lfonts; | |
2389 | Lisp_Object lpattern, tem; | |
2390 | ||
c3cee013 JR |
2391 | lpattern = build_string (pattern); |
2392 | ||
2393 | /* Get the list of fonts matching PATTERN. */ | |
1a578e9b | 2394 | #ifdef WINDOWSNT |
a86110a8 | 2395 | BLOCK_INPUT; |
c3cee013 | 2396 | lfonts = w32_list_fonts (f, lpattern, 0, nfonts); |
a86110a8 | 2397 | UNBLOCK_INPUT; |
d26d6fd9 | 2398 | #else |
702a1e8e | 2399 | lfonts = x_list_fonts (f, lpattern, -1, nfonts); |
1a578e9b | 2400 | #endif |
c3cee013 | 2401 | |
d26d6fd9 GM |
2402 | /* Make a copy of the font names we got from X, and |
2403 | split them into fields. */ | |
702a1e8e GM |
2404 | n = nignored = 0; |
2405 | for (tem = lfonts; CONSP (tem) && n < nfonts; tem = XCDR (tem)) | |
c3cee013 | 2406 | { |
d26d6fd9 GM |
2407 | Lisp_Object elt, tail; |
2408 | char *name = XSTRING (XCAR (tem))->data; | |
82641697 | 2409 | |
702a1e8e | 2410 | /* Ignore fonts matching a pattern from face-ignored-fonts. */ |
d26d6fd9 | 2411 | for (tail = Vface_ignored_fonts; CONSP (tail); tail = XCDR (tail)) |
82641697 | 2412 | { |
d26d6fd9 GM |
2413 | elt = XCAR (tail); |
2414 | if (STRINGP (elt) | |
2415 | && fast_c_string_match_ignore_case (elt, name) >= 0) | |
2416 | break; | |
2417 | } | |
2418 | if (!NILP (tail)) | |
702a1e8e GM |
2419 | { |
2420 | ++nignored; | |
2421 | continue; | |
2422 | } | |
c824bfbc | 2423 | |
d26d6fd9 GM |
2424 | /* Make a copy of the font name. */ |
2425 | fonts[n].name = xstrdup (name); | |
82641697 | 2426 | |
702a1e8e | 2427 | if (split_font_name (f, fonts + n, 1)) |
d26d6fd9 | 2428 | { |
702a1e8e GM |
2429 | if (font_scalable_p (fonts + n) |
2430 | && !may_use_scalable_font_p (name)) | |
2431 | { | |
2432 | ++nignored; | |
2433 | xfree (fonts[n].name); | |
2434 | } | |
82641697 | 2435 | else |
d26d6fd9 | 2436 | ++n; |
82641697 | 2437 | } |
d26d6fd9 | 2438 | else |
702a1e8e GM |
2439 | xfree (fonts[n].name); |
2440 | } | |
2441 | ||
82641697 GM |
2442 | /* If no fonts found, try patterns from Valternate_fontname_alist. */ |
2443 | if (n == 0 && try_alternatives_p) | |
2444 | { | |
2445 | Lisp_Object list = Valternate_fontname_alist; | |
2446 | ||
2447 | while (CONSP (list)) | |
2448 | { | |
2449 | Lisp_Object entry = XCAR (list); | |
2450 | if (CONSP (entry) | |
2451 | && STRINGP (XCAR (entry)) | |
2452 | && strcmp (XSTRING (XCAR (entry))->data, pattern) == 0) | |
2453 | break; | |
2454 | list = XCDR (list); | |
2455 | } | |
2456 | ||
2457 | if (CONSP (list)) | |
2458 | { | |
2459 | Lisp_Object patterns = XCAR (list); | |
2460 | Lisp_Object name; | |
178c5d9c | 2461 | |
82641697 GM |
2462 | while (CONSP (patterns) |
2463 | /* If list is screwed up, give up. */ | |
2464 | && (name = XCAR (patterns), | |
2465 | STRINGP (name)) | |
2466 | /* Ignore patterns equal to PATTERN because we tried that | |
2467 | already with no success. */ | |
2468 | && (strcmp (XSTRING (name)->data, pattern) == 0 | |
2469 | || (n = x_face_list_fonts (f, XSTRING (name)->data, | |
702a1e8e | 2470 | fonts, nfonts, 0), |
82641697 GM |
2471 | n == 0))) |
2472 | patterns = XCDR (patterns); | |
2473 | } | |
2474 | } | |
178c5d9c | 2475 | |
82641697 GM |
2476 | return n; |
2477 | } | |
178c5d9c | 2478 | |
82641697 | 2479 | |
82641697 GM |
2480 | /* Determine fonts matching PATTERN on frame F. Sort resulting fonts |
2481 | using comparison function CMPFN. Value is the number of fonts | |
2482 | found. If value is non-zero, *FONTS is set to a vector of | |
2483 | font_name structures allocated from the heap containing matching | |
2484 | fonts. Each element of *FONTS contains a name member that is also | |
2485 | allocated from the heap. Font names in these structures are split | |
2486 | into fields. Use free_font_names to free such an array. */ | |
2487 | ||
2488 | static int | |
2489 | sorted_font_list (f, pattern, cmpfn, fonts) | |
2490 | struct frame *f; | |
2491 | char *pattern; | |
2492 | int (*cmpfn) P_ ((const void *, const void *)); | |
2493 | struct font_name **fonts; | |
2494 | { | |
2495 | int nfonts; | |
178c5d9c | 2496 | |
82641697 | 2497 | /* Get the list of fonts matching pattern. 100 should suffice. */ |
057df17c GM |
2498 | nfonts = DEFAULT_FONT_LIST_LIMIT; |
2499 | if (INTEGERP (Vfont_list_limit) && XINT (Vfont_list_limit) > 0) | |
2500 | nfonts = XFASTINT (Vfont_list_limit); | |
178c5d9c | 2501 | |
82641697 | 2502 | *fonts = (struct font_name *) xmalloc (nfonts * sizeof **fonts); |
702a1e8e | 2503 | nfonts = x_face_list_fonts (f, pattern, *fonts, nfonts, 1); |
178c5d9c SS |
2504 | |
2505 | /* Sort the resulting array and return it in *FONTS. If no | |
82641697 GM |
2506 | fonts were found, make sure to set *FONTS to null. */ |
2507 | if (nfonts) | |
2508 | sort_fonts (f, *fonts, nfonts, cmpfn); | |
2509 | else | |
2510 | { | |
2511 | xfree (*fonts); | |
2512 | *fonts = NULL; | |
2513 | } | |
2514 | ||
2515 | return nfonts; | |
2516 | } | |
2517 | ||
2518 | ||
2519 | /* Compare two font_name structures *A and *B. Value is analogous to | |
2520 | strcmp. Sort order is given by the global variable | |
2521 | font_sort_order. Font names are sorted so that, everything else | |
2522 | being equal, fonts with a resolution closer to that of the frame on | |
2523 | which they are used are listed first. The global variable | |
2524 | font_frame is the frame on which we operate. */ | |
2525 | ||
2526 | static int | |
2527 | cmp_font_names (a, b) | |
2528 | const void *a, *b; | |
2529 | { | |
2530 | struct font_name *x = (struct font_name *) a; | |
2531 | struct font_name *y = (struct font_name *) b; | |
2532 | int cmp; | |
2533 | ||
2534 | /* All strings have been converted to lower-case by split_font_name, | |
2535 | so we can use strcmp here. */ | |
2536 | cmp = strcmp (x->fields[XLFD_FAMILY], y->fields[XLFD_FAMILY]); | |
2537 | if (cmp == 0) | |
2538 | { | |
2539 | int i; | |
178c5d9c | 2540 | |
82641697 GM |
2541 | for (i = 0; i < DIM (font_sort_order) && cmp == 0; ++i) |
2542 | { | |
2543 | int j = font_sort_order[i]; | |
2544 | cmp = x->numeric[j] - y->numeric[j]; | |
2545 | } | |
2546 | ||
2547 | if (cmp == 0) | |
2548 | { | |
2549 | /* Everything else being equal, we prefer fonts with an | |
2550 | y-resolution closer to that of the frame. */ | |
2551 | int resy = FRAME_X_DISPLAY_INFO (font_frame)->resy; | |
2552 | int x_resy = x->numeric[XLFD_RESY]; | |
2553 | int y_resy = y->numeric[XLFD_RESY]; | |
2554 | cmp = abs (resy - x_resy) - abs (resy - y_resy); | |
2555 | } | |
2556 | } | |
2557 | ||
2558 | return cmp; | |
2559 | } | |
2560 | ||
2561 | ||
2562 | /* Get a sorted list of fonts of family FAMILY on frame F. If PATTERN | |
39506348 KH |
2563 | is non-nil list fonts matching that pattern. Otherwise, if |
2564 | REGISTRY is non-nil return only fonts with that registry, otherwise | |
2565 | return fonts of any registry. Set *FONTS to a vector of font_name | |
2566 | structures allocated from the heap containing the fonts found. | |
2567 | Value is the number of fonts found. */ | |
82641697 GM |
2568 | |
2569 | static int | |
32fcc231 | 2570 | font_list_1 (f, pattern, family, registry, fonts) |
82641697 | 2571 | struct frame *f; |
39506348 | 2572 | Lisp_Object pattern, family, registry; |
82641697 GM |
2573 | struct font_name **fonts; |
2574 | { | |
39506348 KH |
2575 | char *pattern_str, *family_str, *registry_str; |
2576 | ||
2577 | if (NILP (pattern)) | |
82641697 | 2578 | { |
39506348 KH |
2579 | family_str = (NILP (family) ? "*" : (char *) XSTRING (family)->data); |
2580 | registry_str = (NILP (registry) ? "*" : (char *) XSTRING (registry)->data); | |
178c5d9c | 2581 | |
39506348 | 2582 | pattern_str = (char *) alloca (strlen (family_str) |
0d1f7c08 KH |
2583 | + strlen (registry_str) |
2584 | + 10); | |
2585 | strcpy (pattern_str, index (family_str, '-') ? "-" : "-*-"); | |
2586 | strcat (pattern_str, family_str); | |
2587 | strcat (pattern_str, "-*-"); | |
2588 | strcat (pattern_str, registry_str); | |
2589 | if (!index (registry_str, '-')) | |
2590 | { | |
2591 | if (registry_str[strlen (registry_str) - 1] == '*') | |
2592 | strcat (pattern_str, "-*"); | |
2593 | else | |
2594 | strcat (pattern_str, "*-*"); | |
2595 | } | |
82641697 | 2596 | } |
39506348 KH |
2597 | else |
2598 | pattern_str = (char *) XSTRING (pattern)->data; | |
178c5d9c | 2599 | |
39506348 | 2600 | return sorted_font_list (f, pattern_str, cmp_font_names, fonts); |
82641697 GM |
2601 | } |
2602 | ||
2603 | ||
8e1b21a7 KH |
2604 | /* Concatenate font list FONTS1 and FONTS2. FONTS1 and FONTS2 |
2605 | contains NFONTS1 fonts and NFONTS2 fonts respectively. Return a | |
2606 | pointer to a newly allocated font list. FONTS1 and FONTS2 are | |
2607 | freed. */ | |
2608 | ||
2609 | static struct font_name * | |
2610 | concat_font_list (fonts1, nfonts1, fonts2, nfonts2) | |
2611 | struct font_name *fonts1, *fonts2; | |
2612 | int nfonts1, nfonts2; | |
2613 | { | |
2614 | int new_nfonts = nfonts1 + nfonts2; | |
2615 | struct font_name *new_fonts; | |
2616 | ||
2617 | new_fonts = (struct font_name *) xmalloc (sizeof *new_fonts * new_nfonts); | |
2618 | bcopy (fonts1, new_fonts, sizeof *new_fonts * nfonts1); | |
2619 | bcopy (fonts2, new_fonts + nfonts1, sizeof *new_fonts * nfonts2); | |
2620 | xfree (fonts1); | |
2621 | xfree (fonts2); | |
2622 | return new_fonts; | |
2623 | } | |
2624 | ||
2625 | ||
32fcc231 GM |
2626 | /* Get a sorted list of fonts of family FAMILY on frame F. |
2627 | ||
2628 | If PATTERN is non-nil list fonts matching that pattern. | |
2629 | ||
8e1b21a7 KH |
2630 | If REGISTRY is non-nil, return fonts with that registry and the |
2631 | alternative registries from Vface_alternative_font_registry_alist. | |
32fcc231 GM |
2632 | |
2633 | If REGISTRY is nil return fonts of any registry. | |
2634 | ||
2635 | Set *FONTS to a vector of font_name structures allocated from the | |
2636 | heap containing the fonts found. Value is the number of fonts | |
2637 | found. */ | |
2638 | ||
2639 | static int | |
2640 | font_list (f, pattern, family, registry, fonts) | |
2641 | struct frame *f; | |
2642 | Lisp_Object pattern, family, registry; | |
2643 | struct font_name **fonts; | |
2644 | { | |
2645 | int nfonts = font_list_1 (f, pattern, family, registry, fonts); | |
2646 | ||
8e1b21a7 | 2647 | if (!NILP (registry) |
32fcc231 GM |
2648 | && CONSP (Vface_alternative_font_registry_alist)) |
2649 | { | |
2650 | Lisp_Object alter; | |
2651 | ||
2652 | alter = Fassoc (registry, Vface_alternative_font_registry_alist); | |
2653 | if (CONSP (alter)) | |
2654 | { | |
8e1b21a7 KH |
2655 | int reg_prio, i; |
2656 | ||
2657 | for (alter = XCDR (alter), reg_prio = 1; | |
2658 | CONSP (alter); | |
2659 | alter = XCDR (alter), reg_prio++) | |
32fcc231 | 2660 | if (STRINGP (XCAR (alter))) |
8e1b21a7 KH |
2661 | { |
2662 | int nfonts2; | |
2663 | struct font_name *fonts2; | |
2664 | ||
2665 | nfonts2 = font_list_1 (f, pattern, family, XCAR (alter), | |
2666 | &fonts2); | |
2667 | for (i = 0; i < nfonts2; i++) | |
2668 | fonts2[i].registry_priority = reg_prio; | |
2669 | *fonts = (nfonts > 0 | |
2670 | ? concat_font_list (*fonts, nfonts, fonts2, nfonts2) | |
2671 | : fonts2); | |
2672 | nfonts += nfonts2; | |
2673 | } | |
32fcc231 GM |
2674 | } |
2675 | } | |
2676 | ||
2677 | return nfonts; | |
2678 | } | |
2679 | ||
2680 | ||
82641697 | 2681 | /* Remove elements from LIST whose cars are `equal'. Called from |
92610620 | 2682 | x-family-fonts and x-font-family-list to remove duplicate font |
82641697 GM |
2683 | entries. */ |
2684 | ||
2685 | static void | |
2686 | remove_duplicates (list) | |
2687 | Lisp_Object list; | |
2688 | { | |
2689 | Lisp_Object tail = list; | |
178c5d9c | 2690 | |
82641697 GM |
2691 | while (!NILP (tail) && !NILP (XCDR (tail))) |
2692 | { | |
2693 | Lisp_Object next = XCDR (tail); | |
2694 | if (!NILP (Fequal (XCAR (next), XCAR (tail)))) | |
f3fbd155 | 2695 | XSETCDR (tail, XCDR (next)); |
82641697 GM |
2696 | else |
2697 | tail = XCDR (tail); | |
2698 | } | |
2699 | } | |
2700 | ||
2701 | ||
92610620 | 2702 | DEFUN ("x-family-fonts", Fx_family_fonts, Sx_family_fonts, 0, 2, 0, |
7ee72033 | 2703 | doc: /* Return a list of available fonts of family FAMILY on FRAME. |
228299fa GM |
2704 | If FAMILY is omitted or nil, list all families. |
2705 | Otherwise, FAMILY must be a string, possibly containing wildcards | |
2706 | `?' and `*'. | |
2707 | If FRAME is omitted or nil, use the selected frame. | |
2708 | Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT | |
2709 | SLANT FIXED-P FULL REGISTRY-AND-ENCODING]. | |
2710 | FAMILY is the font family name. POINT-SIZE is the size of the | |
2711 | font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the | |
2712 | width, weight and slant of the font. These symbols are the same as for | |
2713 | face attributes. FIXED-P is non-nil if the font is fixed-pitch. | |
2714 | FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string | |
2715 | giving the registry and encoding of the font. | |
2716 | The result list is sorted according to the current setting of | |
7ee72033 MB |
2717 | the face font sort order. */) |
2718 | (family, frame) | |
82641697 GM |
2719 | Lisp_Object family, frame; |
2720 | { | |
2721 | struct frame *f = check_x_frame (frame); | |
2722 | struct font_name *fonts; | |
2723 | int i, nfonts; | |
2724 | Lisp_Object result; | |
2725 | struct gcpro gcpro1; | |
82641697 | 2726 | |
39506348 | 2727 | if (!NILP (family)) |
b7826503 | 2728 | CHECK_STRING (family); |
178c5d9c | 2729 | |
82641697 GM |
2730 | result = Qnil; |
2731 | GCPRO1 (result); | |
39506348 | 2732 | nfonts = font_list (f, Qnil, family, Qnil, &fonts); |
82641697 GM |
2733 | for (i = nfonts - 1; i >= 0; --i) |
2734 | { | |
057df17c GM |
2735 | Lisp_Object v = Fmake_vector (make_number (8), Qnil); |
2736 | char *tem; | |
82641697 | 2737 | |
82641697 GM |
2738 | ASET (v, 0, build_string (fonts[i].fields[XLFD_FAMILY])); |
2739 | ASET (v, 1, xlfd_symbolic_swidth (fonts + i)); | |
2740 | ASET (v, 2, make_number (xlfd_point_size (f, fonts + i))); | |
2741 | ASET (v, 3, xlfd_symbolic_weight (fonts + i)); | |
2742 | ASET (v, 4, xlfd_symbolic_slant (fonts + i)); | |
2743 | ASET (v, 5, xlfd_fixed_p (fonts + i) ? Qt : Qnil); | |
057df17c GM |
2744 | tem = build_font_name (fonts + i); |
2745 | ASET (v, 6, build_string (tem)); | |
2746 | sprintf (tem, "%s-%s", fonts[i].fields[XLFD_REGISTRY], | |
2747 | fonts[i].fields[XLFD_ENCODING]); | |
2748 | ASET (v, 7, build_string (tem)); | |
2749 | xfree (tem); | |
178c5d9c | 2750 | |
82641697 | 2751 | result = Fcons (v, result); |
82641697 GM |
2752 | } |
2753 | ||
2754 | remove_duplicates (result); | |
2755 | free_font_names (fonts, nfonts); | |
2756 | UNGCPRO; | |
2757 | return result; | |
2758 | } | |
2759 | ||
2760 | ||
2761 | DEFUN ("x-font-family-list", Fx_font_family_list, Sx_font_family_list, | |
2762 | 0, 1, 0, | |
7ee72033 | 2763 | doc: /* Return a list of available font families on FRAME. |
228299fa GM |
2764 | If FRAME is omitted or nil, use the selected frame. |
2765 | Value is a list of conses (FAMILY . FIXED-P) where FAMILY | |
2766 | is a font family, and FIXED-P is non-nil if fonts of that family | |
7ee72033 MB |
2767 | are fixed-pitch. */) |
2768 | (frame) | |
82641697 GM |
2769 | Lisp_Object frame; |
2770 | { | |
2771 | struct frame *f = check_x_frame (frame); | |
2772 | int nfonts, i; | |
2773 | struct font_name *fonts; | |
2774 | Lisp_Object result; | |
2775 | struct gcpro gcpro1; | |
057df17c GM |
2776 | int count = specpdl_ptr - specpdl; |
2777 | int limit; | |
2778 | ||
2779 | /* Let's consider all fonts. Increase the limit for matching | |
2780 | fonts until we have them all. */ | |
2781 | for (limit = 500;;) | |
2782 | { | |
2783 | specbind (intern ("font-list-limit"), make_number (limit)); | |
39506348 | 2784 | nfonts = font_list (f, Qnil, Qnil, Qnil, &fonts); |
178c5d9c | 2785 | |
057df17c GM |
2786 | if (nfonts == limit) |
2787 | { | |
2788 | free_font_names (fonts, nfonts); | |
2789 | limit *= 2; | |
2790 | } | |
2791 | else | |
2792 | break; | |
2793 | } | |
178c5d9c | 2794 | |
82641697 GM |
2795 | result = Qnil; |
2796 | GCPRO1 (result); | |
2797 | for (i = nfonts - 1; i >= 0; --i) | |
2798 | result = Fcons (Fcons (build_string (fonts[i].fields[XLFD_FAMILY]), | |
2799 | xlfd_fixed_p (fonts + i) ? Qt : Qnil), | |
2800 | result); | |
2801 | ||
2802 | remove_duplicates (result); | |
2803 | free_font_names (fonts, nfonts); | |
2804 | UNGCPRO; | |
057df17c | 2805 | return unbind_to (count, result); |
82641697 GM |
2806 | } |
2807 | ||
2808 | ||
2809 | DEFUN ("x-list-fonts", Fx_list_fonts, Sx_list_fonts, 1, 5, 0, | |
7ee72033 | 2810 | doc: /* Return a list of the names of available fonts matching PATTERN. |
228299fa GM |
2811 | If optional arguments FACE and FRAME are specified, return only fonts |
2812 | the same size as FACE on FRAME. | |
2813 | PATTERN is a string, perhaps with wildcard characters; | |
2814 | the * character matches any substring, and | |
2815 | the ? character matches any single character. | |
2816 | PATTERN is case-insensitive. | |
2817 | FACE is a face name--a symbol. | |
2818 | ||
2819 | The return value is a list of strings, suitable as arguments to | |
2820 | set-face-font. | |
2821 | ||
2822 | Fonts Emacs can't use may or may not be excluded | |
2823 | even if they match PATTERN and FACE. | |
2824 | The optional fourth argument MAXIMUM sets a limit on how many | |
2825 | fonts to match. The first MAXIMUM fonts are reported. | |
2826 | The optional fifth argument WIDTH, if specified, is a number of columns | |
2827 | occupied by a character of a font. In that case, return only fonts | |
7ee72033 MB |
2828 | the WIDTH times as wide as FACE on FRAME. */) |
2829 | (pattern, face, frame, maximum, width) | |
82641697 GM |
2830 | Lisp_Object pattern, face, frame, maximum, width; |
2831 | { | |
2832 | struct frame *f; | |
2833 | int size; | |
2834 | int maxnames; | |
2835 | ||
2836 | check_x (); | |
b7826503 | 2837 | CHECK_STRING (pattern); |
178c5d9c | 2838 | |
82641697 GM |
2839 | if (NILP (maximum)) |
2840 | maxnames = 2000; | |
2841 | else | |
2842 | { | |
b7826503 | 2843 | CHECK_NATNUM (maximum); |
82641697 GM |
2844 | maxnames = XINT (maximum); |
2845 | } | |
2846 | ||
2847 | if (!NILP (width)) | |
b7826503 | 2848 | CHECK_NUMBER (width); |
82641697 GM |
2849 | |
2850 | /* We can't simply call check_x_frame because this function may be | |
2851 | called before any frame is created. */ | |
2852 | f = frame_or_selected_frame (frame, 2); | |
c3cee013 | 2853 | if (!FRAME_WINDOW_P (f)) |
82641697 GM |
2854 | { |
2855 | /* Perhaps we have not yet created any frame. */ | |
2856 | f = NULL; | |
2857 | face = Qnil; | |
2858 | } | |
2859 | ||
2860 | /* Determine the width standard for comparison with the fonts we find. */ | |
2861 | ||
2862 | if (NILP (face)) | |
2863 | size = 0; | |
2864 | else | |
2865 | { | |
2866 | /* This is of limited utility since it works with character | |
2867 | widths. Keep it for compatibility. --gerd. */ | |
39506348 | 2868 | int face_id = lookup_named_face (f, face, 0); |
b5de343d GM |
2869 | struct face *face = (face_id < 0 |
2870 | ? NULL | |
2871 | : FACE_FROM_ID (f, face_id)); | |
82641697 | 2872 | |
b5de343d | 2873 | if (face && face->font) |
c3cee013 | 2874 | size = FONT_WIDTH (face->font); |
82641697 | 2875 | else |
c3cee013 | 2876 | size = FONT_WIDTH (FRAME_FONT (f)); |
82641697 GM |
2877 | |
2878 | if (!NILP (width)) | |
2879 | size *= XINT (width); | |
2880 | } | |
2881 | ||
2882 | { | |
2883 | Lisp_Object args[2]; | |
2884 | ||
2885 | args[0] = x_list_fonts (f, pattern, size, maxnames); | |
2886 | if (f == NULL) | |
2887 | /* We don't have to check fontsets. */ | |
2888 | return args[0]; | |
2889 | args[1] = list_fontsets (f, pattern, size); | |
2890 | return Fnconc (2, args); | |
2891 | } | |
2892 | } | |
2893 | ||
c3cee013 | 2894 | #endif /* HAVE_WINDOW_SYSTEM */ |
82641697 GM |
2895 | |
2896 | ||
2897 | \f | |
2898 | /*********************************************************************** | |
2899 | Lisp Faces | |
2900 | ***********************************************************************/ | |
2901 | ||
a08332c0 GM |
2902 | /* Access face attributes of face LFACE, a Lisp vector. */ |
2903 | ||
2904 | #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX) | |
2905 | #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX) | |
2906 | #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX) | |
2907 | #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX) | |
2908 | #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX) | |
2909 | #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX) | |
2910 | #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX) | |
2911 | #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX) | |
2912 | #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX) | |
2913 | #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX) | |
2914 | #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX) | |
2915 | #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX) | |
2916 | #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX) | |
2917 | #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX) | |
2918 | #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX) | |
2919 | #define LFACE_AVGWIDTH(LFACE) AREF ((LFACE), LFACE_AVGWIDTH_INDEX) | |
82641697 GM |
2920 | |
2921 | /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size | |
2922 | LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */ | |
2923 | ||
2924 | #define LFACEP(LFACE) \ | |
2925 | (VECTORP (LFACE) \ | |
2926 | && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \ | |
a08332c0 | 2927 | && EQ (AREF (LFACE, 0), Qface)) |
82641697 | 2928 | |
178c5d9c | 2929 | |
82641697 GM |
2930 | #if GLYPH_DEBUG |
2931 | ||
2932 | /* Check consistency of Lisp face attribute vector ATTRS. */ | |
2933 | ||
2934 | static void | |
2935 | check_lface_attrs (attrs) | |
2936 | Lisp_Object *attrs; | |
2937 | { | |
2938 | xassert (UNSPECIFIEDP (attrs[LFACE_FAMILY_INDEX]) | |
2939 | || STRINGP (attrs[LFACE_FAMILY_INDEX])); | |
2940 | xassert (UNSPECIFIEDP (attrs[LFACE_SWIDTH_INDEX]) | |
2941 | || SYMBOLP (attrs[LFACE_SWIDTH_INDEX])); | |
a08332c0 GM |
2942 | xassert (UNSPECIFIEDP (attrs[LFACE_AVGWIDTH_INDEX]) |
2943 | || INTEGERP (attrs[LFACE_AVGWIDTH_INDEX])); | |
82641697 | 2944 | xassert (UNSPECIFIEDP (attrs[LFACE_HEIGHT_INDEX]) |
2c20458f MB |
2945 | || INTEGERP (attrs[LFACE_HEIGHT_INDEX]) |
2946 | || FLOATP (attrs[LFACE_HEIGHT_INDEX]) | |
2947 | || FUNCTIONP (attrs[LFACE_HEIGHT_INDEX])); | |
82641697 GM |
2948 | xassert (UNSPECIFIEDP (attrs[LFACE_WEIGHT_INDEX]) |
2949 | || SYMBOLP (attrs[LFACE_WEIGHT_INDEX])); | |
2950 | xassert (UNSPECIFIEDP (attrs[LFACE_SLANT_INDEX]) | |
2951 | || SYMBOLP (attrs[LFACE_SLANT_INDEX])); | |
2952 | xassert (UNSPECIFIEDP (attrs[LFACE_UNDERLINE_INDEX]) | |
2953 | || SYMBOLP (attrs[LFACE_UNDERLINE_INDEX]) | |
2954 | || STRINGP (attrs[LFACE_UNDERLINE_INDEX])); | |
2955 | xassert (UNSPECIFIEDP (attrs[LFACE_OVERLINE_INDEX]) | |
2956 | || SYMBOLP (attrs[LFACE_OVERLINE_INDEX]) | |
2957 | || STRINGP (attrs[LFACE_OVERLINE_INDEX])); | |
2958 | xassert (UNSPECIFIEDP (attrs[LFACE_STRIKE_THROUGH_INDEX]) | |
2959 | || SYMBOLP (attrs[LFACE_STRIKE_THROUGH_INDEX]) | |
2960 | || STRINGP (attrs[LFACE_STRIKE_THROUGH_INDEX])); | |
2961 | xassert (UNSPECIFIEDP (attrs[LFACE_BOX_INDEX]) | |
2962 | || SYMBOLP (attrs[LFACE_BOX_INDEX]) | |
2963 | || STRINGP (attrs[LFACE_BOX_INDEX]) | |
2964 | || INTEGERP (attrs[LFACE_BOX_INDEX]) | |
2965 | || CONSP (attrs[LFACE_BOX_INDEX])); | |
2966 | xassert (UNSPECIFIEDP (attrs[LFACE_INVERSE_INDEX]) | |
2967 | || SYMBOLP (attrs[LFACE_INVERSE_INDEX])); | |
2968 | xassert (UNSPECIFIEDP (attrs[LFACE_FOREGROUND_INDEX]) | |
2969 | || STRINGP (attrs[LFACE_FOREGROUND_INDEX])); | |
2970 | xassert (UNSPECIFIEDP (attrs[LFACE_BACKGROUND_INDEX]) | |
2971 | || STRINGP (attrs[LFACE_BACKGROUND_INDEX])); | |
2c20458f MB |
2972 | xassert (UNSPECIFIEDP (attrs[LFACE_INHERIT_INDEX]) |
2973 | || NILP (attrs[LFACE_INHERIT_INDEX]) | |
2974 | || SYMBOLP (attrs[LFACE_INHERIT_INDEX]) | |
2975 | || CONSP (attrs[LFACE_INHERIT_INDEX])); | |
82641697 GM |
2976 | #ifdef HAVE_WINDOW_SYSTEM |
2977 | xassert (UNSPECIFIEDP (attrs[LFACE_STIPPLE_INDEX]) | |
2978 | || SYMBOLP (attrs[LFACE_STIPPLE_INDEX]) | |
fef04523 | 2979 | || !NILP (Fbitmap_spec_p (attrs[LFACE_STIPPLE_INDEX]))); |
39506348 | 2980 | xassert (UNSPECIFIEDP (attrs[LFACE_FONT_INDEX]) |
d2cafc8c GM |
2981 | || NILP (attrs[LFACE_FONT_INDEX]) |
2982 | || STRINGP (attrs[LFACE_FONT_INDEX])); | |
82641697 GM |
2983 | #endif |
2984 | } | |
2985 | ||
2986 | ||
2987 | /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */ | |
2988 | ||
2989 | static void | |
2990 | check_lface (lface) | |
2991 | Lisp_Object lface; | |
2992 | { | |
2993 | if (!NILP (lface)) | |
2994 | { | |
2995 | xassert (LFACEP (lface)); | |
2996 | check_lface_attrs (XVECTOR (lface)->contents); | |
2997 | } | |
2998 | } | |
2999 | ||
3000 | #else /* GLYPH_DEBUG == 0 */ | |
3001 | ||
3002 | #define check_lface_attrs(attrs) (void) 0 | |
3003 | #define check_lface(lface) (void) 0 | |
3004 | ||
3005 | #endif /* GLYPH_DEBUG == 0 */ | |
3006 | ||
3007 | ||
39506348 | 3008 | /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it |
c7ae3284 GM |
3009 | to make it a symvol. If FACE_NAME is an alias for another face, |
3010 | return that face's name. */ | |
3011 | ||
3012 | static Lisp_Object | |
3013 | resolve_face_name (face_name) | |
3014 | Lisp_Object face_name; | |
3015 | { | |
3016 | Lisp_Object aliased; | |
178c5d9c | 3017 | |
c7ae3284 GM |
3018 | if (STRINGP (face_name)) |
3019 | face_name = intern (XSTRING (face_name)->data); | |
3020 | ||
906b3b14 | 3021 | while (SYMBOLP (face_name)) |
c7ae3284 GM |
3022 | { |
3023 | aliased = Fget (face_name, Qface_alias); | |
3024 | if (NILP (aliased)) | |
3025 | break; | |
3026 | else | |
3027 | face_name = aliased; | |
3028 | } | |
3029 | ||
3030 | return face_name; | |
3031 | } | |
3032 | ||
3033 | ||
82641697 | 3034 | /* Return the face definition of FACE_NAME on frame F. F null means |
45d9f1ef GM |
3035 | return the definition for new frames. FACE_NAME may be a string or |
3036 | a symbol (apparently Emacs 20.2 allowed strings as face names in | |
3037 | face text properties; Ediff uses that). If FACE_NAME is an alias | |
3038 | for another face, return that face's definition. If SIGNAL_P is | |
92610620 GM |
3039 | non-zero, signal an error if FACE_NAME is not a valid face name. |
3040 | If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face | |
3041 | name. */ | |
82641697 GM |
3042 | |
3043 | static INLINE Lisp_Object | |
3044 | lface_from_face_name (f, face_name, signal_p) | |
3045 | struct frame *f; | |
3046 | Lisp_Object face_name; | |
3047 | int signal_p; | |
3048 | { | |
c7ae3284 | 3049 | Lisp_Object lface; |
82641697 | 3050 | |
c7ae3284 | 3051 | face_name = resolve_face_name (face_name); |
92610620 | 3052 | |
82641697 GM |
3053 | if (f) |
3054 | lface = assq_no_quit (face_name, f->face_alist); | |
3055 | else | |
3056 | lface = assq_no_quit (face_name, Vface_new_frame_defaults); | |
3057 | ||
3058 | if (CONSP (lface)) | |
3059 | lface = XCDR (lface); | |
3060 | else if (signal_p) | |
3061 | signal_error ("Invalid face", face_name); | |
3062 | ||
3063 | check_lface (lface); | |
3064 | return lface; | |
3065 | } | |
3066 | ||
3067 | ||
3068 | /* Get face attributes of face FACE_NAME from frame-local faces on | |
3069 | frame F. Store the resulting attributes in ATTRS which must point | |
3070 | to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P | |
3071 | is non-zero, signal an error if FACE_NAME does not name a face. | |
3072 | Otherwise, value is zero if FACE_NAME is not a face. */ | |
3073 | ||
3074 | static INLINE int | |
3075 | get_lface_attributes (f, face_name, attrs, signal_p) | |
3076 | struct frame *f; | |
3077 | Lisp_Object face_name; | |
3078 | Lisp_Object *attrs; | |
3079 | int signal_p; | |
3080 | { | |
3081 | Lisp_Object lface; | |
3082 | int success_p; | |
3083 | ||
3084 | lface = lface_from_face_name (f, face_name, signal_p); | |
3085 | if (!NILP (lface)) | |
3086 | { | |
3087 | bcopy (XVECTOR (lface)->contents, attrs, | |
3088 | LFACE_VECTOR_SIZE * sizeof *attrs); | |
3089 | success_p = 1; | |
3090 | } | |
3091 | else | |
3092 | success_p = 0; | |
3093 | ||
3094 | return success_p; | |
3095 | } | |
3096 | ||
3097 | ||
3098 | /* Non-zero if all attributes in face attribute vector ATTRS are | |
3099 | specified, i.e. are non-nil. */ | |
3100 | ||
3101 | static int | |
3102 | lface_fully_specified_p (attrs) | |
3103 | Lisp_Object *attrs; | |
3104 | { | |
3105 | int i; | |
3106 | ||
3107 | for (i = 1; i < LFACE_VECTOR_SIZE; ++i) | |
a08332c0 GM |
3108 | if (i != LFACE_FONT_INDEX && i != LFACE_INHERIT_INDEX |
3109 | && i != LFACE_AVGWIDTH_INDEX) | |
6288c62f GM |
3110 | if (UNSPECIFIEDP (attrs[i])) |
3111 | break; | |
82641697 GM |
3112 | |
3113 | return i == LFACE_VECTOR_SIZE; | |
3114 | } | |
3115 | ||
c3cee013 | 3116 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 | 3117 | |
39506348 KH |
3118 | /* Set font-related attributes of Lisp face LFACE from the fullname of |
3119 | the font opened by FONTNAME. If FORCE_P is zero, set only | |
3120 | unspecified attributes of LFACE. The exception is `font' | |
3121 | attribute. It is set to FONTNAME as is regardless of FORCE_P. | |
3122 | ||
3123 | If FONTNAME is not available on frame F, | |
3124 | return 0 if MAY_FAIL_P is non-zero, otherwise abort. | |
3125 | If the fullname is not in a valid XLFD format, | |
3126 | return 0 if MAY_FAIL_P is non-zero, otherwise set normal values | |
3127 | in LFACE and return 1. | |
3128 | Otherwise, return 1. */ | |
178c5d9c | 3129 | |
82641697 | 3130 | static int |
39506348 | 3131 | set_lface_from_font_name (f, lface, fontname, force_p, may_fail_p) |
82641697 GM |
3132 | struct frame *f; |
3133 | Lisp_Object lface; | |
39506348 | 3134 | Lisp_Object fontname; |
3221576b | 3135 | int force_p, may_fail_p; |
82641697 GM |
3136 | { |
3137 | struct font_name font; | |
3138 | char *buffer; | |
3139 | int pt; | |
39506348 KH |
3140 | int have_xlfd_p; |
3141 | int fontset; | |
3142 | char *font_name = XSTRING (fontname)->data; | |
3143 | struct font_info *font_info; | |
82641697 | 3144 | |
39506348 KH |
3145 | /* If FONTNAME is actually a fontset name, get ASCII font name of it. */ |
3146 | fontset = fs_query_fontset (fontname, 0); | |
3147 | if (fontset >= 0) | |
3148 | font_name = XSTRING (fontset_ascii (fontset))->data; | |
3149 | ||
3150 | /* Check if FONT_NAME is surely available on the system. Usually | |
3151 | FONT_NAME is already cached for the frame F and FS_LOAD_FONT | |
3152 | returns quickly. But, even if FONT_NAME is not yet cached, | |
3153 | caching it now is not futail because we anyway load the font | |
3154 | later. */ | |
3155 | BLOCK_INPUT; | |
3156 | font_info = FS_LOAD_FONT (f, 0, font_name, -1); | |
3157 | UNBLOCK_INPUT; | |
82641697 | 3158 | |
39506348 | 3159 | if (!font_info) |
3221576b GM |
3160 | { |
3161 | if (may_fail_p) | |
3162 | return 0; | |
39506348 | 3163 | abort (); |
3221576b | 3164 | } |
39506348 KH |
3165 | |
3166 | font.name = STRDUPA (font_info->full_name); | |
3167 | have_xlfd_p = split_font_name (f, &font, 1); | |
3221576b | 3168 | |
82641697 | 3169 | /* Set attributes only if unspecified, otherwise face defaults for |
39506348 KH |
3170 | new frames would never take effect. If we couldn't get a font |
3171 | name conforming to XLFD, set normal values. */ | |
178c5d9c | 3172 | |
82641697 GM |
3173 | if (force_p || UNSPECIFIEDP (LFACE_FAMILY (lface))) |
3174 | { | |
39506348 KH |
3175 | Lisp_Object val; |
3176 | if (have_xlfd_p) | |
3177 | { | |
3178 | buffer = (char *) alloca (strlen (font.fields[XLFD_FAMILY]) | |
3179 | + strlen (font.fields[XLFD_FOUNDRY]) | |
3180 | + 2); | |
3181 | sprintf (buffer, "%s-%s", font.fields[XLFD_FOUNDRY], | |
3182 | font.fields[XLFD_FAMILY]); | |
3183 | val = build_string (buffer); | |
3184 | } | |
3185 | else | |
3186 | val = build_string ("*"); | |
3187 | LFACE_FAMILY (lface) = val; | |
82641697 GM |
3188 | } |
3189 | ||
3190 | if (force_p || UNSPECIFIEDP (LFACE_HEIGHT (lface))) | |
3191 | { | |
39506348 KH |
3192 | if (have_xlfd_p) |
3193 | pt = xlfd_point_size (f, &font); | |
3194 | else | |
3195 | pt = pixel_point_size (f, font_info->height * 10); | |
82641697 GM |
3196 | xassert (pt > 0); |
3197 | LFACE_HEIGHT (lface) = make_number (pt); | |
3198 | } | |
3199 | ||
3200 | if (force_p || UNSPECIFIEDP (LFACE_SWIDTH (lface))) | |
39506348 KH |
3201 | LFACE_SWIDTH (lface) |
3202 | = have_xlfd_p ? xlfd_symbolic_swidth (&font) : Qnormal; | |
82641697 | 3203 | |
a08332c0 GM |
3204 | if (force_p || UNSPECIFIEDP (LFACE_AVGWIDTH (lface))) |
3205 | LFACE_AVGWIDTH (lface) | |
3206 | = (have_xlfd_p | |
3207 | ? make_number (font.numeric[XLFD_AVGWIDTH]) | |
3208 | : Qunspecified); | |
3209 | ||
82641697 | 3210 | if (force_p || UNSPECIFIEDP (LFACE_WEIGHT (lface))) |
39506348 KH |
3211 | LFACE_WEIGHT (lface) |
3212 | = have_xlfd_p ? xlfd_symbolic_weight (&font) : Qnormal; | |
82641697 GM |
3213 | |
3214 | if (force_p || UNSPECIFIEDP (LFACE_SLANT (lface))) | |
39506348 KH |
3215 | LFACE_SLANT (lface) |
3216 | = have_xlfd_p ? xlfd_symbolic_slant (&font) : Qnormal; | |
82641697 | 3217 | |
39506348 | 3218 | LFACE_FONT (lface) = fontname; |
178c5d9c | 3219 | |
82641697 GM |
3220 | return 1; |
3221 | } | |
d12d0a9b | 3222 | |
c3cee013 | 3223 | #endif /* HAVE_WINDOW_SYSTEM */ |
82641697 GM |
3224 | |
3225 | ||
2c20458f MB |
3226 | /* Merges the face height FROM with the face height TO, and returns the |
3227 | merged height. If FROM is an invalid height, then INVALID is | |
cdfaafa9 MB |
3228 | returned instead. FROM and TO may be either absolute face heights or |
3229 | `relative' heights; the returned value is always an absolute height | |
3230 | unless both FROM and TO are relative. GCPRO is a lisp value that | |
3231 | will be protected from garbage-collection if this function makes a | |
3232 | call into lisp. */ | |
2c20458f MB |
3233 | |
3234 | Lisp_Object | |
3235 | merge_face_heights (from, to, invalid, gcpro) | |
3236 | Lisp_Object from, to, invalid, gcpro; | |
3237 | { | |
cdfaafa9 | 3238 | Lisp_Object result = invalid; |
2c20458f MB |
3239 | |
3240 | if (INTEGERP (from)) | |
cdfaafa9 MB |
3241 | /* FROM is absolute, just use it as is. */ |
3242 | result = from; | |
3243 | else if (FLOATP (from)) | |
3244 | /* FROM is a scale, use it to adjust TO. */ | |
3245 | { | |
3246 | if (INTEGERP (to)) | |
3247 | /* relative X absolute => absolute */ | |
c319cf24 | 3248 | result = make_number ((EMACS_INT)(XFLOAT_DATA (from) * XINT (to))); |
cdfaafa9 MB |
3249 | else if (FLOATP (to)) |
3250 | /* relative X relative => relative */ | |
3251 | result = make_float (XFLOAT_DATA (from) * XFLOAT_DATA (to)); | |
2c20458f | 3252 | } |
2c20458f | 3253 | else if (FUNCTIONP (from)) |
cdfaafa9 | 3254 | /* FROM is a function, which use to adjust TO. */ |
2c20458f MB |
3255 | { |
3256 | /* Call function with current height as argument. | |
3257 | From is the new height. */ | |
cdfaafa9 | 3258 | Lisp_Object args[2]; |
2c20458f MB |
3259 | struct gcpro gcpro1; |
3260 | ||
3261 | GCPRO1 (gcpro); | |
3262 | ||
3263 | args[0] = from; | |
3264 | args[1] = to; | |
cdfaafa9 | 3265 | result = safe_call (2, args); |
2c20458f MB |
3266 | |
3267 | UNGCPRO; | |
3268 | ||
cdfaafa9 MB |
3269 | /* Ensure that if TO was absolute, so is the result. */ |
3270 | if (INTEGERP (to) && !INTEGERP (result)) | |
3271 | result = invalid; | |
2c20458f MB |
3272 | } |
3273 | ||
cdfaafa9 | 3274 | return result; |
2c20458f MB |
3275 | } |
3276 | ||
3277 | ||
3278 | /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and | |
613fa7f2 MB |
3279 | store the resulting attributes in TO, which must be already be |
3280 | completely specified and contain only absolute attributes. Every | |
3281 | specified attribute of FROM overrides the corresponding attribute of | |
3282 | TO; relative attributes in FROM are merged with the absolute value in | |
3283 | TO and replace it. CYCLE_CHECK is used internally to detect loops in | |
3284 | face inheritance; it should be Qnil when called from other places. */ | |
82641697 GM |
3285 | |
3286 | static INLINE void | |
2c20458f MB |
3287 | merge_face_vectors (f, from, to, cycle_check) |
3288 | struct frame *f; | |
82641697 | 3289 | Lisp_Object *from, *to; |
2c20458f | 3290 | Lisp_Object cycle_check; |
82641697 GM |
3291 | { |
3292 | int i; | |
2c20458f MB |
3293 | |
3294 | /* If FROM inherits from some other faces, merge their attributes into | |
3295 | TO before merging FROM's direct attributes. Note that an :inherit | |
3296 | attribute of `unspecified' is the same as one of nil; we never | |
3297 | merge :inherit attributes, so nil is more correct, but lots of | |
3298 | other code uses `unspecified' as a generic value for face attributes. */ | |
3299 | if (!UNSPECIFIEDP (from[LFACE_INHERIT_INDEX]) | |
3300 | && !NILP (from[LFACE_INHERIT_INDEX])) | |
3301 | merge_face_inheritance (f, from[LFACE_INHERIT_INDEX], to, cycle_check); | |
3302 | ||
87188200 MB |
3303 | /* If TO specifies a :font attribute, and FROM specifies some |
3304 | font-related attribute, we need to clear TO's :font attribute | |
3305 | (because it will be inconsistent with whatever FROM specifies, and | |
3306 | FROM takes precedence). */ | |
3307 | if (!NILP (to[LFACE_FONT_INDEX]) | |
3308 | && (!UNSPECIFIEDP (from[LFACE_FAMILY_INDEX]) | |
3309 | || !UNSPECIFIEDP (from[LFACE_HEIGHT_INDEX]) | |
3310 | || !UNSPECIFIEDP (from[LFACE_WEIGHT_INDEX]) | |
3311 | || !UNSPECIFIEDP (from[LFACE_SLANT_INDEX]) | |
a08332c0 GM |
3312 | || !UNSPECIFIEDP (from[LFACE_SWIDTH_INDEX]) |
3313 | || !UNSPECIFIEDP (from[LFACE_AVGWIDTH_INDEX]))) | |
87188200 MB |
3314 | to[LFACE_FONT_INDEX] = Qnil; |
3315 | ||
82641697 GM |
3316 | for (i = 1; i < LFACE_VECTOR_SIZE; ++i) |
3317 | if (!UNSPECIFIEDP (from[i])) | |
ab8469eb PJ |
3318 | { |
3319 | if (i == LFACE_HEIGHT_INDEX && !INTEGERP (from[i])) | |
3320 | to[i] = merge_face_heights (from[i], to[i], to[i], cycle_check); | |
3321 | else | |
3322 | to[i] = from[i]; | |
3323 | } | |
2c20458f MB |
3324 | |
3325 | /* TO is always an absolute face, which should inherit from nothing. | |
3326 | We blindly copy the :inherit attribute above and fix it up here. */ | |
3327 | to[LFACE_INHERIT_INDEX] = Qnil; | |
3328 | } | |
3329 | ||
6288c62f | 3330 | |
2c20458f MB |
3331 | /* Checks the `cycle check' variable CHECK to see if it indicates that |
3332 | EL is part of a cycle; CHECK must be either Qnil or a value returned | |
3333 | by an earlier use of CYCLE_CHECK. SUSPICIOUS is the number of | |
3334 | elements after which a cycle might be suspected; after that many | |
3335 | elements, this macro begins consing in order to keep more precise | |
3336 | track of elements. | |
3337 | ||
f0529b5b | 3338 | Returns nil if a cycle was detected, otherwise a new value for CHECK |
2c20458f MB |
3339 | that includes EL. |
3340 | ||
3341 | CHECK is evaluated multiple times, EL and SUSPICIOUS 0 or 1 times, so | |
3342 | the caller should make sure that's ok. */ | |
6288c62f | 3343 | |
28e6fb66 GM |
3344 | #define CYCLE_CHECK(check, el, suspicious) \ |
3345 | (NILP (check) \ | |
3346 | ? make_number (0) \ | |
3347 | : (INTEGERP (check) \ | |
3348 | ? (XFASTINT (check) < (suspicious) \ | |
3349 | ? make_number (XFASTINT (check) + 1) \ | |
3350 | : Fcons (el, Qnil)) \ | |
3351 | : (!NILP (Fmemq ((el), (check))) \ | |
3352 | ? Qnil \ | |
3353 | : Fcons ((el), (check))))) | |
2c20458f | 3354 | |
87188200 MB |
3355 | |
3356 | /* Merge face attributes from the face on frame F whose name is | |
3357 | INHERITS, into the vector of face attributes TO; INHERITS may also be | |
3358 | a list of face names, in which case they are applied in order. | |
3359 | CYCLE_CHECK is used to detect loops in face inheritance. | |
3360 | Returns true if any of the inherited attributes are `font-related'. */ | |
3361 | ||
2c20458f MB |
3362 | static void |
3363 | merge_face_inheritance (f, inherit, to, cycle_check) | |
3364 | struct frame *f; | |
3365 | Lisp_Object inherit; | |
3366 | Lisp_Object *to; | |
3367 | Lisp_Object cycle_check; | |
3368 | { | |
3369 | if (SYMBOLP (inherit) && !EQ (inherit, Qunspecified)) | |
3370 | /* Inherit from the named face INHERIT. */ | |
3371 | { | |
3372 | Lisp_Object lface; | |
3373 | ||
3374 | /* Make sure we're not in an inheritance loop. */ | |
3375 | cycle_check = CYCLE_CHECK (cycle_check, inherit, 15); | |
3376 | if (NILP (cycle_check)) | |
3377 | /* Cycle detected, ignore any further inheritance. */ | |
3378 | return; | |
3379 | ||
3380 | lface = lface_from_face_name (f, inherit, 0); | |
3381 | if (!NILP (lface)) | |
3382 | merge_face_vectors (f, XVECTOR (lface)->contents, to, cycle_check); | |
3383 | } | |
3384 | else if (CONSP (inherit)) | |
3385 | /* Handle a list of inherited faces by calling ourselves recursively | |
3386 | on each element. Note that we only do so for symbol elements, so | |
3387 | it's not possible to infinitely recurse. */ | |
3388 | { | |
3389 | while (CONSP (inherit)) | |
3390 | { | |
3391 | if (SYMBOLP (XCAR (inherit))) | |
3392 | merge_face_inheritance (f, XCAR (inherit), to, cycle_check); | |
3393 | ||
3394 | /* Check for a circular inheritance list. */ | |
3395 | cycle_check = CYCLE_CHECK (cycle_check, inherit, 15); | |
3396 | if (NILP (cycle_check)) | |
3397 | /* Cycle detected. */ | |
3398 | break; | |
3399 | ||
3400 | inherit = XCDR (inherit); | |
3401 | } | |
3402 | } | |
82641697 GM |
3403 | } |
3404 | ||
3405 | ||
3406 | /* Given a Lisp face attribute vector TO and a Lisp object PROP that | |
3407 | is a face property, determine the resulting face attributes on | |
3408 | frame F, and store them in TO. PROP may be a single face | |
3409 | specification or a list of such specifications. Each face | |
3410 | specification can be | |
3411 | ||
3412 | 1. A symbol or string naming a Lisp face. | |
3413 | ||
3414 | 2. A property list of the form (KEYWORD VALUE ...) where each | |
3415 | KEYWORD is a face attribute name, and value is an appropriate value | |
3416 | for that attribute. | |
3417 | ||
3418 | 3. Conses or the form (FOREGROUND-COLOR . COLOR) or | |
3419 | (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is | |
3420 | for compatibility with 20.2. | |
3421 | ||
3422 | Face specifications earlier in lists take precedence over later | |
3423 | specifications. */ | |
178c5d9c | 3424 | |
82641697 GM |
3425 | static void |
3426 | merge_face_vector_with_property (f, to, prop) | |
3427 | struct frame *f; | |
3428 | Lisp_Object *to; | |
3429 | Lisp_Object prop; | |
3430 | { | |
3431 | if (CONSP (prop)) | |
3432 | { | |
3433 | Lisp_Object first = XCAR (prop); | |
178c5d9c | 3434 | |
82641697 GM |
3435 | if (EQ (first, Qforeground_color) |
3436 | || EQ (first, Qbackground_color)) | |
3437 | { | |
3438 | /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR | |
3439 | . COLOR). COLOR must be a string. */ | |
3440 | Lisp_Object color_name = XCDR (prop); | |
3441 | Lisp_Object color = first; | |
3442 | ||
3443 | if (STRINGP (color_name)) | |
3444 | { | |
3445 | if (EQ (color, Qforeground_color)) | |
3446 | to[LFACE_FOREGROUND_INDEX] = color_name; | |
3447 | else | |
3448 | to[LFACE_BACKGROUND_INDEX] = color_name; | |
3449 | } | |
3450 | else | |
1b8f7fbc | 3451 | add_to_log ("Invalid face color", color_name, Qnil); |
82641697 GM |
3452 | } |
3453 | else if (SYMBOLP (first) | |
3454 | && *XSYMBOL (first)->name->data == ':') | |
3455 | { | |
3456 | /* Assume this is the property list form. */ | |
3457 | while (CONSP (prop) && CONSP (XCDR (prop))) | |
3458 | { | |
3459 | Lisp_Object keyword = XCAR (prop); | |
3460 | Lisp_Object value = XCAR (XCDR (prop)); | |
3461 | ||
3462 | if (EQ (keyword, QCfamily)) | |
3463 | { | |
3464 | if (STRINGP (value)) | |
3465 | to[LFACE_FAMILY_INDEX] = value; | |
3466 | else | |
1a948b17 | 3467 | add_to_log ("Invalid face font family", value, Qnil); |
82641697 GM |
3468 | } |
3469 | else if (EQ (keyword, QCheight)) | |
3470 | { | |
2c20458f MB |
3471 | Lisp_Object new_height = |
3472 | merge_face_heights (value, to[LFACE_HEIGHT_INDEX], | |
3473 | Qnil, Qnil); | |
3474 | ||
3475 | if (NILP (new_height)) | |
1a948b17 | 3476 | add_to_log ("Invalid face font height", value, Qnil); |
2c20458f MB |
3477 | else |
3478 | to[LFACE_HEIGHT_INDEX] = new_height; | |
82641697 GM |
3479 | } |
3480 | else if (EQ (keyword, QCweight)) | |
3481 | { | |
3482 | if (SYMBOLP (value) | |
3483 | && face_numeric_weight (value) >= 0) | |
3484 | to[LFACE_WEIGHT_INDEX] = value; | |
3485 | else | |
1a948b17 | 3486 | add_to_log ("Invalid face weight", value, Qnil); |
82641697 GM |
3487 | } |
3488 | else if (EQ (keyword, QCslant)) | |
3489 | { | |
3490 | if (SYMBOLP (value) | |
3491 | && face_numeric_slant (value) >= 0) | |
3492 | to[LFACE_SLANT_INDEX] = value; | |
3493 | else | |
1a948b17 | 3494 | add_to_log ("Invalid face slant", value, Qnil); |
82641697 GM |
3495 | } |
3496 | else if (EQ (keyword, QCunderline)) | |
3497 | { | |
3498 | if (EQ (value, Qt) | |
3499 | || NILP (value) | |
3500 | || STRINGP (value)) | |
3501 | to[LFACE_UNDERLINE_INDEX] = value; | |
3502 | else | |
1a948b17 | 3503 | add_to_log ("Invalid face underline", value, Qnil); |
82641697 GM |
3504 | } |
3505 | else if (EQ (keyword, QCoverline)) | |
3506 | { | |
3507 | if (EQ (value, Qt) | |
3508 | || NILP (value) | |
3509 | || STRINGP (value)) | |
3510 | to[LFACE_OVERLINE_INDEX] = value; | |
3511 | else | |
1a948b17 | 3512 | add_to_log ("Invalid face overline", value, Qnil); |
82641697 GM |
3513 | } |
3514 | else if (EQ (keyword, QCstrike_through)) | |
3515 | { | |
3516 | if (EQ (value, Qt) | |
3517 | || NILP (value) | |
3518 | || STRINGP (value)) | |
3519 | to[LFACE_STRIKE_THROUGH_INDEX] = value; | |
3520 | else | |
1a948b17 | 3521 | add_to_log ("Invalid face strike-through", value, Qnil); |
82641697 GM |
3522 | } |
3523 | else if (EQ (keyword, QCbox)) | |
3524 | { | |
3525 | if (EQ (value, Qt)) | |
3526 | value = make_number (1); | |
3527 | if (INTEGERP (value) | |
3528 | || STRINGP (value) | |
3529 | || CONSP (value) | |
3530 | || NILP (value)) | |
3531 | to[LFACE_BOX_INDEX] = value; | |
3532 | else | |
1a948b17 | 3533 | add_to_log ("Invalid face box", value, Qnil); |
82641697 GM |
3534 | } |
3535 | else if (EQ (keyword, QCinverse_video) | |
3536 | || EQ (keyword, QCreverse_video)) | |
3537 | { | |
3538 | if (EQ (value, Qt) || NILP (value)) | |
3539 | to[LFACE_INVERSE_INDEX] = value; | |
3540 | else | |
1a948b17 | 3541 | add_to_log ("Invalid face inverse-video", value, Qnil); |
82641697 GM |
3542 | } |
3543 | else if (EQ (keyword, QCforeground)) | |
3544 | { | |
3545 | if (STRINGP (value)) | |
3546 | to[LFACE_FOREGROUND_INDEX] = value; | |
3547 | else | |
1a948b17 | 3548 | add_to_log ("Invalid face foreground", value, Qnil); |
82641697 GM |
3549 | } |
3550 | else if (EQ (keyword, QCbackground)) | |
3551 | { | |
3552 | if (STRINGP (value)) | |
3553 | to[LFACE_BACKGROUND_INDEX] = value; | |
3554 | else | |
1a948b17 | 3555 | add_to_log ("Invalid face background", value, Qnil); |
82641697 GM |
3556 | } |
3557 | else if (EQ (keyword, QCstipple)) | |
3558 | { | |
3559 | #ifdef HAVE_X_WINDOWS | |
fef04523 | 3560 | Lisp_Object pixmap_p = Fbitmap_spec_p (value); |
82641697 GM |
3561 | if (!NILP (pixmap_p)) |
3562 | to[LFACE_STIPPLE_INDEX] = value; | |
3563 | else | |
1a948b17 | 3564 | add_to_log ("Invalid face stipple", value, Qnil); |
82641697 GM |
3565 | #endif |
3566 | } | |
3567 | else if (EQ (keyword, QCwidth)) | |
3568 | { | |
3569 | if (SYMBOLP (value) | |
3570 | && face_numeric_swidth (value) >= 0) | |
3571 | to[LFACE_SWIDTH_INDEX] = value; | |
3572 | else | |
1a948b17 | 3573 | add_to_log ("Invalid face width", value, Qnil); |
82641697 | 3574 | } |
2c20458f MB |
3575 | else if (EQ (keyword, QCinherit)) |
3576 | { | |
3577 | if (SYMBOLP (value)) | |
3578 | to[LFACE_INHERIT_INDEX] = value; | |
3579 | else | |
3580 | { | |
3581 | Lisp_Object tail; | |
3582 | for (tail = value; CONSP (tail); tail = XCDR (tail)) | |
3583 | if (!SYMBOLP (XCAR (tail))) | |
3584 | break; | |
3585 | if (NILP (tail)) | |
3586 | to[LFACE_INHERIT_INDEX] = value; | |
3587 | else | |
3588 | add_to_log ("Invalid face inherit", value, Qnil); | |
3589 | } | |
3590 | } | |
82641697 | 3591 | else |
1b8f7fbc | 3592 | add_to_log ("Invalid attribute %s in face property", |
7dbdfcf8 | 3593 | keyword, Qnil); |
82641697 GM |
3594 | |
3595 | prop = XCDR (XCDR (prop)); | |
3596 | } | |
3597 | } | |
3598 | else | |
3599 | { | |
3600 | /* This is a list of face specs. Specifications at the | |
3601 | beginning of the list take precedence over later | |
3602 | specifications, so we have to merge starting with the | |
3603 | last specification. */ | |
3604 | Lisp_Object next = XCDR (prop); | |
3605 | if (!NILP (next)) | |
3606 | merge_face_vector_with_property (f, to, next); | |
3607 | merge_face_vector_with_property (f, to, first); | |
3608 | } | |
3609 | } | |
3610 | else | |
3611 | { | |
3612 | /* PROP ought to be a face name. */ | |
3613 | Lisp_Object lface = lface_from_face_name (f, prop, 0); | |
3614 | if (NILP (lface)) | |
1b8f7fbc | 3615 | add_to_log ("Invalid face text property value: %s", prop, Qnil); |
82641697 | 3616 | else |
2c20458f | 3617 | merge_face_vectors (f, XVECTOR (lface)->contents, to, Qnil); |
82641697 GM |
3618 | } |
3619 | } | |
3620 | ||
3621 | ||
3622 | DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face, | |
3623 | Sinternal_make_lisp_face, 1, 2, 0, | |
7ee72033 | 3624 | doc: /* Make FACE, a symbol, a Lisp face with all attributes nil. |
228299fa GM |
3625 | If FACE was not known as a face before, create a new one. |
3626 | If optional argument FRAME is specified, make a frame-local face | |
3627 | for that frame. Otherwise operate on the global face definition. | |
7ee72033 MB |
3628 | Value is a vector of face attributes. */) |
3629 | (face, frame) | |
82641697 GM |
3630 | Lisp_Object face, frame; |
3631 | { | |
3632 | Lisp_Object global_lface, lface; | |
3633 | struct frame *f; | |
3634 | int i; | |
3635 | ||
b7826503 | 3636 | CHECK_SYMBOL (face); |
82641697 | 3637 | global_lface = lface_from_face_name (NULL, face, 0); |
178c5d9c | 3638 | |
82641697 GM |
3639 | if (!NILP (frame)) |
3640 | { | |
b7826503 | 3641 | CHECK_LIVE_FRAME (frame); |
82641697 GM |
3642 | f = XFRAME (frame); |
3643 | lface = lface_from_face_name (f, face, 0); | |
3644 | } | |
3645 | else | |
3646 | f = NULL, lface = Qnil; | |
3647 | ||
3648 | /* Add a global definition if there is none. */ | |
3649 | if (NILP (global_lface)) | |
3650 | { | |
3651 | global_lface = Fmake_vector (make_number (LFACE_VECTOR_SIZE), | |
3652 | Qunspecified); | |
a08332c0 | 3653 | AREF (global_lface, 0) = Qface; |
178c5d9c | 3654 | Vface_new_frame_defaults = Fcons (Fcons (face, global_lface), |
82641697 | 3655 | Vface_new_frame_defaults); |
178c5d9c | 3656 | |
82641697 GM |
3657 | /* Assign the new Lisp face a unique ID. The mapping from Lisp |
3658 | face id to Lisp face is given by the vector lface_id_to_name. | |
3659 | The mapping from Lisp face to Lisp face id is given by the | |
3660 | property `face' of the Lisp face name. */ | |
3661 | if (next_lface_id == lface_id_to_name_size) | |
3662 | { | |
3663 | int new_size = max (50, 2 * lface_id_to_name_size); | |
3664 | int sz = new_size * sizeof *lface_id_to_name; | |
3665 | lface_id_to_name = (Lisp_Object *) xrealloc (lface_id_to_name, sz); | |
3666 | lface_id_to_name_size = new_size; | |
3667 | } | |
178c5d9c | 3668 | |
82641697 GM |
3669 | lface_id_to_name[next_lface_id] = face; |
3670 | Fput (face, Qface, make_number (next_lface_id)); | |
3671 | ++next_lface_id; | |
3672 | } | |
3673 | else if (f == NULL) | |
3674 | for (i = 1; i < LFACE_VECTOR_SIZE; ++i) | |
a08332c0 | 3675 | AREF (global_lface, i) = Qunspecified; |
178c5d9c | 3676 | |
82641697 GM |
3677 | /* Add a frame-local definition. */ |
3678 | if (f) | |
3679 | { | |
3680 | if (NILP (lface)) | |
3681 | { | |
3682 | lface = Fmake_vector (make_number (LFACE_VECTOR_SIZE), | |
3683 | Qunspecified); | |
a08332c0 | 3684 | AREF (lface, 0) = Qface; |
82641697 GM |
3685 | f->face_alist = Fcons (Fcons (face, lface), f->face_alist); |
3686 | } | |
3687 | else | |
3688 | for (i = 1; i < LFACE_VECTOR_SIZE; ++i) | |
a08332c0 | 3689 | AREF (lface, i) = Qunspecified; |
82641697 GM |
3690 | } |
3691 | else | |
3692 | lface = global_lface; | |
3693 | ||
33565969 RS |
3694 | /* Changing a named face means that all realized faces depending on |
3695 | that face are invalid. Since we cannot tell which realized faces | |
3696 | depend on the face, make sure they are all removed. This is done | |
3697 | by incrementing face_change_count. The next call to | |
3698 | init_iterator will then free realized faces. */ | |
3699 | ++face_change_count; | |
3700 | ++windows_or_buffers_changed; | |
3701 | ||
82641697 GM |
3702 | xassert (LFACEP (lface)); |
3703 | check_lface (lface); | |
3704 | return lface; | |
3705 | } | |
3706 | ||
3707 | ||
3708 | DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p, | |
3709 | Sinternal_lisp_face_p, 1, 2, 0, | |
7ee72033 | 3710 | doc: /* Return non-nil if FACE names a face. |
228299fa GM |
3711 | If optional second parameter FRAME is non-nil, check for the |
3712 | existence of a frame-local face with name FACE on that frame. | |
7ee72033 MB |
3713 | Otherwise check for the existence of a global face. */) |
3714 | (face, frame) | |
82641697 GM |
3715 | Lisp_Object face, frame; |
3716 | { | |
3717 | Lisp_Object lface; | |
178c5d9c | 3718 | |
82641697 GM |
3719 | if (!NILP (frame)) |
3720 | { | |
b7826503 | 3721 | CHECK_LIVE_FRAME (frame); |
82641697 GM |
3722 | lface = lface_from_face_name (XFRAME (frame), face, 0); |
3723 | } | |
3724 | else | |
3725 | lface = lface_from_face_name (NULL, face, 0); | |
3726 | ||
3727 | return lface; | |
3728 | } | |
3729 | ||
3730 | ||
3731 | DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face, | |
3732 | Sinternal_copy_lisp_face, 4, 4, 0, | |
7ee72033 | 3733 | doc: /* Copy face FROM to TO. |
228299fa GM |
3734 | If FRAME it t, copy the global face definition of FROM to the |
3735 | global face definition of TO. Otherwise, copy the frame-local | |
3736 | definition of FROM on FRAME to the frame-local definition of TO | |
3737 | on NEW-FRAME, or FRAME if NEW-FRAME is nil. | |
3738 | ||
7ee72033 MB |
3739 | Value is TO. */) |
3740 | (from, to, frame, new_frame) | |
82641697 GM |
3741 | Lisp_Object from, to, frame, new_frame; |
3742 | { | |
3743 | Lisp_Object lface, copy; | |
178c5d9c | 3744 | |
b7826503 PJ |
3745 | CHECK_SYMBOL (from); |
3746 | CHECK_SYMBOL (to); | |
82641697 GM |
3747 | if (NILP (new_frame)) |
3748 | new_frame = frame; | |
3749 | ||
3750 | if (EQ (frame, Qt)) | |
3751 | { | |
3752 | /* Copy global definition of FROM. We don't make copies of | |
3753 | strings etc. because 20.2 didn't do it either. */ | |
3754 | lface = lface_from_face_name (NULL, from, 1); | |
3755 | copy = Finternal_make_lisp_face (to, Qnil); | |
3756 | } | |
3757 | else | |
3758 | { | |
3759 | /* Copy frame-local definition of FROM. */ | |
b7826503 PJ |
3760 | CHECK_LIVE_FRAME (frame); |
3761 | CHECK_LIVE_FRAME (new_frame); | |
82641697 GM |
3762 | lface = lface_from_face_name (XFRAME (frame), from, 1); |
3763 | copy = Finternal_make_lisp_face (to, new_frame); | |
3764 | } | |
178c5d9c | 3765 | |
82641697 GM |
3766 | bcopy (XVECTOR (lface)->contents, XVECTOR (copy)->contents, |
3767 | LFACE_VECTOR_SIZE * sizeof (Lisp_Object)); | |
178c5d9c | 3768 | |
33565969 RS |
3769 | /* Changing a named face means that all realized faces depending on |
3770 | that face are invalid. Since we cannot tell which realized faces | |
3771 | depend on the face, make sure they are all removed. This is done | |
3772 | by incrementing face_change_count. The next call to | |
3773 | init_iterator will then free realized faces. */ | |
3774 | ++face_change_count; | |
3775 | ++windows_or_buffers_changed; | |
3776 | ||
82641697 GM |
3777 | return to; |
3778 | } | |
3779 | ||
3780 | ||
3781 | DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute, | |
3782 | Sinternal_set_lisp_face_attribute, 3, 4, 0, | |
7ee72033 | 3783 | doc: /* Set attribute ATTR of FACE to VALUE. |
228299fa GM |
3784 | FRAME being a frame means change the face on that frame. |
3785 | FRAME nil means change the face of the selected frame. | |
3786 | FRAME t means change the default for new frames. | |
3787 | FRAME 0 means change the face on all frames, and change the default | |
7ee72033 MB |
3788 | for new frames. */) |
3789 | (face, attr, value, frame) | |
82641697 GM |
3790 | Lisp_Object face, attr, value, frame; |
3791 | { | |
3792 | Lisp_Object lface; | |
3793 | Lisp_Object old_value = Qnil; | |
39506348 KH |
3794 | /* Set 1 if ATTR is QCfont. */ |
3795 | int font_attr_p = 0; | |
3796 | /* Set 1 if ATTR is one of font-related attributes other than QCfont. */ | |
82641697 | 3797 | int font_related_attr_p = 0; |
178c5d9c | 3798 | |
b7826503 PJ |
3799 | CHECK_SYMBOL (face); |
3800 | CHECK_SYMBOL (attr); | |
82641697 | 3801 | |
c7ae3284 GM |
3802 | face = resolve_face_name (face); |
3803 | ||
628436fb GM |
3804 | /* If FRAME is 0, change face on all frames, and change the |
3805 | default for new frames. */ | |
3806 | if (INTEGERP (frame) && XINT (frame) == 0) | |
3807 | { | |
3808 | Lisp_Object tail; | |
d12d0a9b | 3809 | Finternal_set_lisp_face_attribute (face, attr, value, Qt); |
628436fb GM |
3810 | FOR_EACH_FRAME (tail, frame) |
3811 | Finternal_set_lisp_face_attribute (face, attr, value, frame); | |
d12d0a9b | 3812 | return face; |
628436fb GM |
3813 | } |
3814 | ||
82641697 GM |
3815 | /* Set lface to the Lisp attribute vector of FACE. */ |
3816 | if (EQ (frame, Qt)) | |
3817 | lface = lface_from_face_name (NULL, face, 1); | |
3818 | else | |
3819 | { | |
3820 | if (NILP (frame)) | |
c0617987 | 3821 | frame = selected_frame; |
178c5d9c | 3822 | |
b7826503 | 3823 | CHECK_LIVE_FRAME (frame); |
82641697 | 3824 | lface = lface_from_face_name (XFRAME (frame), face, 0); |
178c5d9c | 3825 | |
82641697 GM |
3826 | /* If a frame-local face doesn't exist yet, create one. */ |
3827 | if (NILP (lface)) | |
3828 | lface = Finternal_make_lisp_face (face, frame); | |
3829 | } | |
3830 | ||
3831 | if (EQ (attr, QCfamily)) | |
3832 | { | |
3833 | if (!UNSPECIFIEDP (value)) | |
3834 | { | |
b7826503 | 3835 | CHECK_STRING (value); |
82641697 GM |
3836 | if (XSTRING (value)->size == 0) |
3837 | signal_error ("Invalid face family", value); | |
3838 | } | |
3839 | old_value = LFACE_FAMILY (lface); | |
3840 | LFACE_FAMILY (lface) = value; | |
3841 | font_related_attr_p = 1; | |
3842 | } | |
3843 | else if (EQ (attr, QCheight)) | |
3844 | { | |
3845 | if (!UNSPECIFIEDP (value)) | |
3846 | { | |
d8055bfc | 3847 | Lisp_Object test; |
2c20458f | 3848 | |
d8055bfc GM |
3849 | test = (EQ (face, Qdefault) |
3850 | ? value | |
3851 | /* The default face must have an absolute size, | |
3852 | otherwise, we do a test merge with a random | |
3853 | height to see if VALUE's ok. */ | |
3854 | : merge_face_heights (value, make_number (10), Qnil, Qnil)); | |
3855 | ||
3856 | if (!INTEGERP (test) || XINT (test) <= 0) | |
82641697 GM |
3857 | signal_error ("Invalid face height", value); |
3858 | } | |
2c20458f | 3859 | |
82641697 GM |
3860 | old_value = LFACE_HEIGHT (lface); |
3861 | LFACE_HEIGHT (lface) = value; | |
3862 | font_related_attr_p = 1; | |
3863 | } | |
3864 | else if (EQ (attr, QCweight)) | |
3865 | { | |
3866 | if (!UNSPECIFIEDP (value)) | |
3867 | { | |
b7826503 | 3868 | CHECK_SYMBOL (value); |
82641697 GM |
3869 | if (face_numeric_weight (value) < 0) |
3870 | signal_error ("Invalid face weight", value); | |
3871 | } | |
3872 | old_value = LFACE_WEIGHT (lface); | |
3873 | LFACE_WEIGHT (lface) = value; | |
3874 | font_related_attr_p = 1; | |
3875 | } | |
3876 | else if (EQ (attr, QCslant)) | |
3877 | { | |
3878 | if (!UNSPECIFIEDP (value)) | |
3879 | { | |
b7826503 | 3880 | CHECK_SYMBOL (value); |
82641697 GM |
3881 | if (face_numeric_slant (value) < 0) |
3882 | signal_error ("Invalid face slant", value); | |
3883 | } | |
3884 | old_value = LFACE_SLANT (lface); | |
3885 | LFACE_SLANT (lface) = value; | |
3886 | font_related_attr_p = 1; | |
3887 | } | |
3888 | else if (EQ (attr, QCunderline)) | |
3889 | { | |
3890 | if (!UNSPECIFIEDP (value)) | |
3891 | if ((SYMBOLP (value) | |
3892 | && !EQ (value, Qt) | |
3893 | && !EQ (value, Qnil)) | |
3894 | /* Underline color. */ | |
3895 | || (STRINGP (value) | |
3896 | && XSTRING (value)->size == 0)) | |
3897 | signal_error ("Invalid face underline", value); | |
178c5d9c | 3898 | |
82641697 GM |
3899 | old_value = LFACE_UNDERLINE (lface); |
3900 | LFACE_UNDERLINE (lface) = value; | |
3901 | } | |
3902 | else if (EQ (attr, QCoverline)) | |
3903 | { | |
3904 | if (!UNSPECIFIEDP (value)) | |
3905 | if ((SYMBOLP (value) | |
3906 | && !EQ (value, Qt) | |
3907 | && !EQ (value, Qnil)) | |
3908 | /* Overline color. */ | |
3909 | || (STRINGP (value) | |
3910 | && XSTRING (value)->size == 0)) | |
3911 | signal_error ("Invalid face overline", value); | |
178c5d9c | 3912 | |
82641697 GM |
3913 | old_value = LFACE_OVERLINE (lface); |
3914 | LFACE_OVERLINE (lface) = value; | |
3915 | } | |
3916 | else if (EQ (attr, QCstrike_through)) | |
3917 | { | |
3918 | if (!UNSPECIFIEDP (value)) | |
3919 | if ((SYMBOLP (value) | |
3920 | && !EQ (value, Qt) | |
3921 | && !EQ (value, Qnil)) | |
3922 | /* Strike-through color. */ | |
3923 | || (STRINGP (value) | |
3924 | && XSTRING (value)->size == 0)) | |
3925 | signal_error ("Invalid face strike-through", value); | |
178c5d9c | 3926 | |
82641697 GM |
3927 | old_value = LFACE_STRIKE_THROUGH (lface); |
3928 | LFACE_STRIKE_THROUGH (lface) = value; | |
3929 | } | |
3930 | else if (EQ (attr, QCbox)) | |
3931 | { | |
3932 | int valid_p; | |
178c5d9c | 3933 | |
82641697 GM |
3934 | /* Allow t meaning a simple box of width 1 in foreground color |
3935 | of the face. */ | |
3936 | if (EQ (value, Qt)) | |
3937 | value = make_number (1); | |
3938 | ||
3939 | if (UNSPECIFIEDP (value)) | |
3940 | valid_p = 1; | |
3941 | else if (NILP (value)) | |
3942 | valid_p = 1; | |
3943 | else if (INTEGERP (value)) | |
89624b8b | 3944 | valid_p = XINT (value) != 0; |
82641697 GM |
3945 | else if (STRINGP (value)) |
3946 | valid_p = XSTRING (value)->size > 0; | |
3947 | else if (CONSP (value)) | |
3948 | { | |
3949 | Lisp_Object tem; | |
178c5d9c | 3950 | |
82641697 GM |
3951 | tem = value; |
3952 | while (CONSP (tem)) | |
3953 | { | |
3954 | Lisp_Object k, v; | |
3955 | ||
3956 | k = XCAR (tem); | |
3957 | tem = XCDR (tem); | |
3958 | if (!CONSP (tem)) | |
3959 | break; | |
3960 | v = XCAR (tem); | |
3961 | tem = XCDR (tem); | |
178c5d9c | 3962 | |
82641697 GM |
3963 | if (EQ (k, QCline_width)) |
3964 | { | |
89624b8b | 3965 | if (!INTEGERP (v) || XINT (v) == 0) |
82641697 GM |
3966 | break; |
3967 | } | |
3968 | else if (EQ (k, QCcolor)) | |
3969 | { | |
3970 | if (!STRINGP (v) || XSTRING (v)->size == 0) | |
3971 | break; | |
3972 | } | |
3973 | else if (EQ (k, QCstyle)) | |
3974 | { | |
3975 | if (!EQ (v, Qpressed_button) && !EQ (v, Qreleased_button)) | |
3976 | break; | |
3977 | } | |
3978 | else | |
3979 | break; | |
3980 | } | |
3981 | ||
3982 | valid_p = NILP (tem); | |
3983 | } | |
3984 | else | |
3985 | valid_p = 0; | |
3986 | ||
3987 | if (!valid_p) | |
3988 | signal_error ("Invalid face box", value); | |
178c5d9c | 3989 | |
82641697 GM |
3990 | old_value = LFACE_BOX (lface); |
3991 | LFACE_BOX (lface) = value; | |
3992 | } | |
3993 | else if (EQ (attr, QCinverse_video) | |
3994 | || EQ (attr, QCreverse_video)) | |
3995 | { | |
3996 | if (!UNSPECIFIEDP (value)) | |
3997 | { | |
b7826503 | 3998 | CHECK_SYMBOL (value); |
82641697 GM |
3999 | if (!EQ (value, Qt) && !NILP (value)) |
4000 | signal_error ("Invalid inverse-video face attribute value", value); | |
4001 | } | |
4002 | old_value = LFACE_INVERSE (lface); | |
4003 | LFACE_INVERSE (lface) = value; | |
4004 | } | |
4005 | else if (EQ (attr, QCforeground)) | |
4006 | { | |
ef917393 | 4007 | if (!UNSPECIFIEDP (value)) |
82641697 GM |
4008 | { |
4009 | /* Don't check for valid color names here because it depends | |
4010 | on the frame (display) whether the color will be valid | |
4011 | when the face is realized. */ | |
b7826503 | 4012 | CHECK_STRING (value); |
82641697 GM |
4013 | if (XSTRING (value)->size == 0) |
4014 | signal_error ("Empty foreground color value", value); | |
4015 | } | |
4016 | old_value = LFACE_FOREGROUND (lface); | |
4017 | LFACE_FOREGROUND (lface) = value; | |
4018 | } | |
4019 | else if (EQ (attr, QCbackground)) | |
4020 | { | |
ef917393 | 4021 | if (!UNSPECIFIEDP (value)) |
82641697 GM |
4022 | { |
4023 | /* Don't check for valid color names here because it depends | |
4024 | on the frame (display) whether the color will be valid | |
4025 | when the face is realized. */ | |
b7826503 | 4026 | CHECK_STRING (value); |
82641697 GM |
4027 | if (XSTRING (value)->size == 0) |
4028 | signal_error ("Empty background color value", value); | |
4029 | } | |
4030 | old_value = LFACE_BACKGROUND (lface); | |
4031 | LFACE_BACKGROUND (lface) = value; | |
4032 | } | |
4033 | else if (EQ (attr, QCstipple)) | |
4034 | { | |
4035 | #ifdef HAVE_X_WINDOWS | |
4036 | if (!UNSPECIFIEDP (value) | |
4037 | && !NILP (value) | |
fef04523 | 4038 | && NILP (Fbitmap_spec_p (value))) |
82641697 GM |
4039 | signal_error ("Invalid stipple attribute", value); |
4040 | old_value = LFACE_STIPPLE (lface); | |
4041 | LFACE_STIPPLE (lface) = value; | |
4042 | #endif /* HAVE_X_WINDOWS */ | |
4043 | } | |
4044 | else if (EQ (attr, QCwidth)) | |
4045 | { | |
4046 | if (!UNSPECIFIEDP (value)) | |
4047 | { | |
b7826503 | 4048 | CHECK_SYMBOL (value); |
82641697 GM |
4049 | if (face_numeric_swidth (value) < 0) |
4050 | signal_error ("Invalid face width", value); | |
4051 | } | |
4052 | old_value = LFACE_SWIDTH (lface); | |
4053 | LFACE_SWIDTH (lface) = value; | |
4054 | font_related_attr_p = 1; | |
4055 | } | |
4056 | else if (EQ (attr, QCfont)) | |
4057 | { | |
c3cee013 | 4058 | #ifdef HAVE_WINDOW_SYSTEM |
3d90c96c | 4059 | if (EQ (frame, Qt) || FRAME_WINDOW_P (XFRAME (frame))) |
96fbd2c6 EZ |
4060 | { |
4061 | /* Set font-related attributes of the Lisp face from an XLFD | |
4062 | font name. */ | |
4063 | struct frame *f; | |
4064 | Lisp_Object tmp; | |
82641697 | 4065 | |
b7826503 | 4066 | CHECK_STRING (value); |
96fbd2c6 EZ |
4067 | if (EQ (frame, Qt)) |
4068 | f = SELECTED_FRAME (); | |
4069 | else | |
4070 | f = check_x_frame (frame); | |
178c5d9c | 4071 | |
96fbd2c6 EZ |
4072 | /* VALUE may be a fontset name or an alias of fontset. In |
4073 | such a case, use the base fontset name. */ | |
4074 | tmp = Fquery_fontset (value, Qnil); | |
4075 | if (!NILP (tmp)) | |
4076 | value = tmp; | |
39506348 | 4077 | |
96fbd2c6 EZ |
4078 | if (!set_lface_from_font_name (f, lface, value, 1, 1)) |
4079 | signal_error ("Invalid font or fontset name", value); | |
39506348 | 4080 | |
96fbd2c6 EZ |
4081 | font_attr_p = 1; |
4082 | } | |
c3cee013 | 4083 | #endif /* HAVE_WINDOW_SYSTEM */ |
82641697 | 4084 | } |
2c20458f MB |
4085 | else if (EQ (attr, QCinherit)) |
4086 | { | |
4087 | Lisp_Object tail; | |
4088 | if (SYMBOLP (value)) | |
4089 | tail = Qnil; | |
4090 | else | |
4091 | for (tail = value; CONSP (tail); tail = XCDR (tail)) | |
4092 | if (!SYMBOLP (XCAR (tail))) | |
4093 | break; | |
4094 | if (NILP (tail)) | |
4095 | LFACE_INHERIT (lface) = value; | |
4096 | else | |
6288c62f | 4097 | signal_error ("Invalid face inheritance", value); |
2c20458f | 4098 | } |
82641697 GM |
4099 | else if (EQ (attr, QCbold)) |
4100 | { | |
4101 | old_value = LFACE_WEIGHT (lface); | |
4102 | LFACE_WEIGHT (lface) = NILP (value) ? Qnormal : Qbold; | |
4103 | font_related_attr_p = 1; | |
4104 | } | |
4105 | else if (EQ (attr, QCitalic)) | |
4106 | { | |
4107 | old_value = LFACE_SLANT (lface); | |
4108 | LFACE_SLANT (lface) = NILP (value) ? Qnormal : Qitalic; | |
4109 | font_related_attr_p = 1; | |
4110 | } | |
4111 | else | |
4112 | signal_error ("Invalid face attribute name", attr); | |
4113 | ||
39506348 KH |
4114 | if (font_related_attr_p |
4115 | && !UNSPECIFIEDP (value)) | |
4116 | /* If a font-related attribute other than QCfont is specified, the | |
4117 | original `font' attribute nor that of default face is useless | |
4118 | to determine a new font. Thus, we set it to nil so that font | |
4119 | selection mechanism doesn't use it. */ | |
4120 | LFACE_FONT (lface) = Qnil; | |
4121 | ||
82641697 GM |
4122 | /* Changing a named face means that all realized faces depending on |
4123 | that face are invalid. Since we cannot tell which realized faces | |
4124 | depend on the face, make sure they are all removed. This is done | |
4125 | by incrementing face_change_count. The next call to | |
4126 | init_iterator will then free realized faces. */ | |
4127 | if (!EQ (frame, Qt) | |
4128 | && (EQ (attr, QCfont) | |
4129 | || NILP (Fequal (old_value, value)))) | |
4130 | { | |
4131 | ++face_change_count; | |
4132 | ++windows_or_buffers_changed; | |
4133 | } | |
4134 | ||
0eb2ecde | 4135 | if (!UNSPECIFIEDP (value) |
82641697 | 4136 | && NILP (Fequal (old_value, value))) |
8bd201d6 GM |
4137 | { |
4138 | Lisp_Object param; | |
4139 | ||
4140 | param = Qnil; | |
178c5d9c | 4141 | |
8bd201d6 GM |
4142 | if (EQ (face, Qdefault)) |
4143 | { | |
b9c769f8 | 4144 | #ifdef HAVE_WINDOW_SYSTEM |
8bd201d6 GM |
4145 | /* Changed font-related attributes of the `default' face are |
4146 | reflected in changed `font' frame parameters. */ | |
ceeda019 GM |
4147 | if (FRAMEP (frame) |
4148 | && (font_related_attr_p || font_attr_p) | |
8bd201d6 GM |
4149 | && lface_fully_specified_p (XVECTOR (lface)->contents)) |
4150 | set_font_frame_param (frame, lface); | |
b9c769f8 EZ |
4151 | else |
4152 | #endif /* HAVE_WINDOW_SYSTEM */ | |
4153 | ||
4154 | if (EQ (attr, QCforeground)) | |
8bd201d6 GM |
4155 | param = Qforeground_color; |
4156 | else if (EQ (attr, QCbackground)) | |
4157 | param = Qbackground_color; | |
4158 | } | |
b9c769f8 | 4159 | #ifdef HAVE_WINDOW_SYSTEM |
c3cee013 | 4160 | #ifndef WINDOWSNT |
8bd201d6 GM |
4161 | else if (EQ (face, Qscroll_bar)) |
4162 | { | |
4163 | /* Changing the colors of `scroll-bar' sets frame parameters | |
4164 | `scroll-bar-foreground' and `scroll-bar-background'. */ | |
4165 | if (EQ (attr, QCforeground)) | |
4166 | param = Qscroll_bar_foreground; | |
4167 | else if (EQ (attr, QCbackground)) | |
4168 | param = Qscroll_bar_background; | |
4169 | } | |
d12d0a9b | 4170 | #endif /* not WINDOWSNT */ |
8bd201d6 GM |
4171 | else if (EQ (face, Qborder)) |
4172 | { | |
4173 | /* Changing background color of `border' sets frame parameter | |
4174 | `border-color'. */ | |
4175 | if (EQ (attr, QCbackground)) | |
4176 | param = Qborder_color; | |
4177 | } | |
4178 | else if (EQ (face, Qcursor)) | |
4179 | { | |
4180 | /* Changing background color of `cursor' sets frame parameter | |
4181 | `cursor-color'. */ | |
4182 | if (EQ (attr, QCbackground)) | |
4183 | param = Qcursor_color; | |
4184 | } | |
4185 | else if (EQ (face, Qmouse)) | |
4186 | { | |
4187 | /* Changing background color of `mouse' sets frame parameter | |
4188 | `mouse-color'. */ | |
4189 | if (EQ (attr, QCbackground)) | |
4190 | param = Qmouse_color; | |
4191 | } | |
b9c769f8 | 4192 | #endif /* HAVE_WINDOW_SYSTEM */ |
563f68f1 | 4193 | else if (EQ (face, Qmenu)) |
ceeda019 GM |
4194 | { |
4195 | /* Indicate that we have to update the menu bar when | |
4196 | realizing faces on FRAME. FRAME t change the | |
4197 | default for new frames. We do this by setting | |
4198 | setting the flag in new face caches */ | |
4199 | if (FRAMEP (frame)) | |
4200 | { | |
4201 | struct frame *f = XFRAME (frame); | |
4202 | if (FRAME_FACE_CACHE (f) == NULL) | |
4203 | FRAME_FACE_CACHE (f) = make_face_cache (f); | |
4204 | FRAME_FACE_CACHE (f)->menu_face_changed_p = 1; | |
4205 | } | |
4206 | else | |
4207 | menu_face_changed_default = 1; | |
4208 | } | |
8bd201d6 | 4209 | |
39506348 | 4210 | if (!NILP (param)) |
ab8469eb PJ |
4211 | { |
4212 | if (EQ (frame, Qt)) | |
4213 | /* Update `default-frame-alist', which is used for new frames. */ | |
4214 | { | |
4215 | store_in_alist (&Vdefault_frame_alist, param, value); | |
4216 | } | |
4217 | else | |
4218 | /* Update the current frame's parameters. */ | |
4219 | { | |
4220 | Lisp_Object cons; | |
4221 | cons = XCAR (Vparam_value_alist); | |
4222 | XSETCAR (cons, param); | |
4223 | XSETCDR (cons, value); | |
4224 | Fmodify_frame_parameters (frame, Vparam_value_alist); | |
4225 | } | |
4226 | } | |
8bd201d6 | 4227 | } |
82641697 | 4228 | |
82641697 GM |
4229 | return face; |
4230 | } | |
4231 | ||
4232 | ||
c3cee013 | 4233 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 | 4234 | |
39506348 KH |
4235 | /* Set the `font' frame parameter of FRAME determined from `default' |
4236 | face attributes LFACE. If a face or fontset name is explicitely | |
4237 | specfied in LFACE, use it as is. Otherwise, determine a font name | |
4238 | from the other font-related atrributes of LFACE. In that case, if | |
4239 | there's no matching font, signals an error. */ | |
82641697 GM |
4240 | |
4241 | static void | |
4242 | set_font_frame_param (frame, lface) | |
4243 | Lisp_Object frame, lface; | |
4244 | { | |
4245 | struct frame *f = XFRAME (frame); | |
82641697 | 4246 | |
482cca61 | 4247 | if (FRAME_WINDOW_P (f)) |
82641697 | 4248 | { |
482cca61 GM |
4249 | Lisp_Object font_name; |
4250 | char *font; | |
4251 | ||
4252 | if (STRINGP (LFACE_FONT (lface))) | |
4253 | font_name = LFACE_FONT (lface); | |
4254 | else | |
4255 | { | |
4256 | /* Choose a font name that reflects LFACE's attributes and has | |
4257 | the registry and encoding pattern specified in the default | |
4258 | fontset (3rd arg: -1) for ASCII characters (4th arg: 0). */ | |
4259 | font = choose_face_font (f, XVECTOR (lface)->contents, -1, 0); | |
4260 | if (!font) | |
4261 | error ("No font matches the specified attribute"); | |
4262 | font_name = build_string (font); | |
4263 | xfree (font); | |
4264 | } | |
5226a931 | 4265 | |
482cca61 GM |
4266 | Fmodify_frame_parameters (frame, Fcons (Fcons (Qfont, font_name), Qnil)); |
4267 | } | |
82641697 GM |
4268 | } |
4269 | ||
4270 | ||
8bd201d6 GM |
4271 | /* Update the corresponding face when frame parameter PARAM on frame F |
4272 | has been assigned the value NEW_VALUE. */ | |
4273 | ||
4274 | void | |
4275 | update_face_from_frame_parameter (f, param, new_value) | |
4276 | struct frame *f; | |
4277 | Lisp_Object param, new_value; | |
4278 | { | |
4279 | Lisp_Object lface; | |
4280 | ||
4281 | /* If there are no faces yet, give up. This is the case when called | |
4282 | from Fx_create_frame, and we do the necessary things later in | |
92610620 | 4283 | face-set-after-frame-defaults. */ |
8bd201d6 GM |
4284 | if (NILP (f->face_alist)) |
4285 | return; | |
178c5d9c | 4286 | |
33565969 RS |
4287 | /* Changing a named face means that all realized faces depending on |
4288 | that face are invalid. Since we cannot tell which realized faces | |
4289 | depend on the face, make sure they are all removed. This is done | |
4290 | by incrementing face_change_count. The next call to | |
4291 | init_iterator will then free realized faces. */ | |
4292 | ++face_change_count; | |
4293 | ++windows_or_buffers_changed; | |
4294 | ||
8bd201d6 GM |
4295 | if (EQ (param, Qforeground_color)) |
4296 | { | |
4297 | lface = lface_from_face_name (f, Qdefault, 1); | |
4298 | LFACE_FOREGROUND (lface) = (STRINGP (new_value) | |
4299 | ? new_value : Qunspecified); | |
4300 | realize_basic_faces (f); | |
4301 | } | |
4302 | else if (EQ (param, Qbackground_color)) | |
4303 | { | |
92610620 GM |
4304 | Lisp_Object frame; |
4305 | ||
4306 | /* Changing the background color might change the background | |
4307 | mode, so that we have to load new defface specs. Call | |
4308 | frame-update-face-colors to do that. */ | |
4309 | XSETFRAME (frame, f); | |
4310 | call1 (Qframe_update_face_colors, frame); | |
178c5d9c | 4311 | |
8bd201d6 GM |
4312 | lface = lface_from_face_name (f, Qdefault, 1); |
4313 | LFACE_BACKGROUND (lface) = (STRINGP (new_value) | |
4314 | ? new_value : Qunspecified); | |
4315 | realize_basic_faces (f); | |
4316 | } | |
4317 | if (EQ (param, Qborder_color)) | |
4318 | { | |
4319 | lface = lface_from_face_name (f, Qborder, 1); | |
4320 | LFACE_BACKGROUND (lface) = (STRINGP (new_value) | |
4321 | ? new_value : Qunspecified); | |
4322 | } | |
4323 | else if (EQ (param, Qcursor_color)) | |
4324 | { | |
4325 | lface = lface_from_face_name (f, Qcursor, 1); | |
4326 | LFACE_BACKGROUND (lface) = (STRINGP (new_value) | |
4327 | ? new_value : Qunspecified); | |
4328 | } | |
4329 | else if (EQ (param, Qmouse_color)) | |
4330 | { | |
4331 | lface = lface_from_face_name (f, Qmouse, 1); | |
4332 | LFACE_BACKGROUND (lface) = (STRINGP (new_value) | |
4333 | ? new_value : Qunspecified); | |
4334 | } | |
4335 | } | |
4336 | ||
4337 | ||
82641697 GM |
4338 | /* Get the value of X resource RESOURCE, class CLASS for the display |
4339 | of frame FRAME. This is here because ordinary `x-get-resource' | |
4340 | doesn't take a frame argument. */ | |
4341 | ||
4342 | DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource, | |
7ee72033 MB |
4343 | Sinternal_face_x_get_resource, 3, 3, 0, doc: /* */) |
4344 | (resource, class, frame) | |
82641697 GM |
4345 | Lisp_Object resource, class, frame; |
4346 | { | |
c3cee013 JR |
4347 | Lisp_Object value = Qnil; |
4348 | #ifndef WINDOWSNT | |
e0f712ba | 4349 | #ifndef MAC_OS |
b7826503 PJ |
4350 | CHECK_STRING (resource); |
4351 | CHECK_STRING (class); | |
4352 | CHECK_LIVE_FRAME (frame); | |
82641697 GM |
4353 | BLOCK_INPUT; |
4354 | value = display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame)), | |
4355 | resource, class, Qnil, Qnil); | |
4356 | UNBLOCK_INPUT; | |
e0f712ba | 4357 | #endif /* not MAC_OS */ |
d12d0a9b | 4358 | #endif /* not WINDOWSNT */ |
82641697 GM |
4359 | return value; |
4360 | } | |
4361 | ||
4362 | ||
4363 | /* Return resource string VALUE as a boolean value, i.e. nil, or t. | |
4364 | If VALUE is "on" or "true", return t. If VALUE is "off" or | |
4365 | "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an | |
4366 | error; if SIGNAL_P is zero, return 0. */ | |
178c5d9c | 4367 | |
82641697 GM |
4368 | static Lisp_Object |
4369 | face_boolean_x_resource_value (value, signal_p) | |
4370 | Lisp_Object value; | |
4371 | int signal_p; | |
4372 | { | |
4373 | Lisp_Object result = make_number (0); | |
4374 | ||
4375 | xassert (STRINGP (value)); | |
178c5d9c | 4376 | |
82641697 GM |
4377 | if (xstricmp (XSTRING (value)->data, "on") == 0 |
4378 | || xstricmp (XSTRING (value)->data, "true") == 0) | |
4379 | result = Qt; | |
4380 | else if (xstricmp (XSTRING (value)->data, "off") == 0 | |
4381 | || xstricmp (XSTRING (value)->data, "false") == 0) | |
4382 | result = Qnil; | |
4383 | else if (xstricmp (XSTRING (value)->data, "unspecified") == 0) | |
4384 | result = Qunspecified; | |
4385 | else if (signal_p) | |
4386 | signal_error ("Invalid face attribute value from X resource", value); | |
4387 | ||
4388 | return result; | |
4389 | } | |
4390 | ||
4391 | ||
4392 | DEFUN ("internal-set-lisp-face-attribute-from-resource", | |
4393 | Finternal_set_lisp_face_attribute_from_resource, | |
4394 | Sinternal_set_lisp_face_attribute_from_resource, | |
7ee72033 MB |
4395 | 3, 4, 0, doc: /* */) |
4396 | (face, attr, value, frame) | |
82641697 GM |
4397 | Lisp_Object face, attr, value, frame; |
4398 | { | |
b7826503 PJ |
4399 | CHECK_SYMBOL (face); |
4400 | CHECK_SYMBOL (attr); | |
4401 | CHECK_STRING (value); | |
82641697 GM |
4402 | |
4403 | if (xstricmp (XSTRING (value)->data, "unspecified") == 0) | |
4404 | value = Qunspecified; | |
4405 | else if (EQ (attr, QCheight)) | |
4406 | { | |
4407 | value = Fstring_to_number (value, make_number (10)); | |
4408 | if (XINT (value) <= 0) | |
4409 | signal_error ("Invalid face height from X resource", value); | |
4410 | } | |
4411 | else if (EQ (attr, QCbold) || EQ (attr, QCitalic)) | |
4412 | value = face_boolean_x_resource_value (value, 1); | |
4413 | else if (EQ (attr, QCweight) || EQ (attr, QCslant) || EQ (attr, QCwidth)) | |
4414 | value = intern (XSTRING (value)->data); | |
4415 | else if (EQ (attr, QCreverse_video) || EQ (attr, QCinverse_video)) | |
4416 | value = face_boolean_x_resource_value (value, 1); | |
4417 | else if (EQ (attr, QCunderline) | |
4418 | || EQ (attr, QCoverline) | |
27188d11 | 4419 | || EQ (attr, QCstrike_through)) |
82641697 GM |
4420 | { |
4421 | Lisp_Object boolean_value; | |
4422 | ||
4423 | /* If the result of face_boolean_x_resource_value is t or nil, | |
4424 | VALUE does NOT specify a color. */ | |
4425 | boolean_value = face_boolean_x_resource_value (value, 0); | |
4426 | if (SYMBOLP (boolean_value)) | |
4427 | value = boolean_value; | |
4428 | } | |
27188d11 GM |
4429 | else if (EQ (attr, QCbox)) |
4430 | value = Fcar (Fread_from_string (value, Qnil, Qnil)); | |
82641697 GM |
4431 | |
4432 | return Finternal_set_lisp_face_attribute (face, attr, value, frame); | |
4433 | } | |
4434 | ||
c3cee013 | 4435 | #endif /* HAVE_WINDOW_SYSTEM */ |
82641697 | 4436 | |
c7ae3284 GM |
4437 | \f |
4438 | /*********************************************************************** | |
4439 | Menu face | |
4440 | ***********************************************************************/ | |
4441 | ||
bce72079 | 4442 | #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT |
c7ae3284 | 4443 | |
bce72079 GM |
4444 | /* Make menus on frame F appear as specified by the `menu' face. */ |
4445 | ||
4446 | static void | |
4447 | x_update_menu_appearance (f) | |
c7ae3284 | 4448 | struct frame *f; |
c7ae3284 | 4449 | { |
a03ad468 | 4450 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
bce72079 | 4451 | XrmDatabase rdb; |
178c5d9c | 4452 | |
bce72079 GM |
4453 | if (dpyinfo |
4454 | && (rdb = XrmGetDatabase (FRAME_X_DISPLAY (f)), | |
4455 | rdb != NULL)) | |
c7ae3284 | 4456 | { |
bce72079 GM |
4457 | char line[512]; |
4458 | Lisp_Object lface = lface_from_face_name (f, Qmenu, 1); | |
4459 | struct face *face = FACE_FROM_ID (f, MENU_FACE_ID); | |
4460 | char *myname = XSTRING (Vx_resource_name)->data; | |
4461 | int changed_p = 0; | |
8ad582ac GM |
4462 | #ifdef USE_MOTIF |
4463 | const char *popup_path = "popup_menu"; | |
4464 | #else | |
4465 | const char *popup_path = "menu.popup"; | |
4466 | #endif | |
823ba8d8 | 4467 | |
bce72079 GM |
4468 | if (STRINGP (LFACE_FOREGROUND (lface))) |
4469 | { | |
8ad582ac GM |
4470 | sprintf (line, "%s.%s*foreground: %s", |
4471 | myname, popup_path, | |
4472 | XSTRING (LFACE_FOREGROUND (lface))->data); | |
bce72079 GM |
4473 | XrmPutLineResource (&rdb, line); |
4474 | sprintf (line, "%s.pane.menubar*foreground: %s", | |
4475 | myname, XSTRING (LFACE_FOREGROUND (lface))->data); | |
4476 | XrmPutLineResource (&rdb, line); | |
4477 | changed_p = 1; | |
4478 | } | |
178c5d9c | 4479 | |
bce72079 GM |
4480 | if (STRINGP (LFACE_BACKGROUND (lface))) |
4481 | { | |
8ad582ac GM |
4482 | sprintf (line, "%s.%s*background: %s", |
4483 | myname, popup_path, | |
4484 | XSTRING (LFACE_BACKGROUND (lface))->data); | |
bce72079 GM |
4485 | XrmPutLineResource (&rdb, line); |
4486 | sprintf (line, "%s.pane.menubar*background: %s", | |
4487 | myname, XSTRING (LFACE_BACKGROUND (lface))->data); | |
4488 | XrmPutLineResource (&rdb, line); | |
4489 | changed_p = 1; | |
4490 | } | |
a03ad468 | 4491 | |
bce72079 GM |
4492 | if (face->font_name |
4493 | && (!UNSPECIFIEDP (LFACE_FAMILY (lface)) | |
4494 | || !UNSPECIFIEDP (LFACE_SWIDTH (lface)) | |
4495 | || !UNSPECIFIEDP (LFACE_AVGWIDTH (lface)) | |
4496 | || !UNSPECIFIEDP (LFACE_WEIGHT (lface)) | |
4497 | || !UNSPECIFIEDP (LFACE_SLANT (lface)) | |
4498 | || !UNSPECIFIEDP (LFACE_HEIGHT (lface)))) | |
4499 | { | |
a03ad468 | 4500 | #ifdef USE_MOTIF |
bce72079 | 4501 | const char *suffix = "List"; |
a03ad468 | 4502 | #else |
bce72079 GM |
4503 | const char *suffix = ""; |
4504 | #endif | |
4505 | sprintf (line, "%s.pane.menubar*font%s: %s", | |
4506 | myname, suffix, face->font_name); | |
4507 | XrmPutLineResource (&rdb, line); | |
2eddf899 GM |
4508 | sprintf (line, "%s.%s*font%s: %s", |
4509 | myname, popup_path, suffix, face->font_name); | |
bce72079 GM |
4510 | XrmPutLineResource (&rdb, line); |
4511 | changed_p = 1; | |
4512 | } | |
c7ae3284 | 4513 | |
bce72079 | 4514 | if (changed_p && f->output_data.x->menubar_widget) |
ac17f0bf | 4515 | free_frame_menubar (f); |
c7ae3284 GM |
4516 | } |
4517 | } | |
4518 | ||
bce72079 | 4519 | #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */ |
82641697 GM |
4520 | |
4521 | ||
cdfaafa9 MB |
4522 | DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p, |
4523 | Sface_attribute_relative_p, | |
4524 | 2, 2, 0, | |
4525 | doc: /* Return non-nil if face ATTRIBUTE VALUE is relative. */) | |
4526 | (attribute, value) | |
d0930289 | 4527 | Lisp_Object attribute, value; |
cdfaafa9 MB |
4528 | { |
4529 | if (EQ (value, Qunspecified)) | |
4530 | return Qt; | |
4531 | else if (EQ (attribute, QCheight)) | |
4532 | return INTEGERP (value) ? Qnil : Qt; | |
4533 | else | |
4534 | return Qnil; | |
4535 | } | |
4536 | ||
4537 | DEFUN ("merge-face-attribute", Fmerge_face_attribute, Smerge_face_attribute, | |
4538 | 3, 3, 0, | |
4539 | doc: /* Return face ATTRIBUTE VALUE1 merged with VALUE2. | |
4540 | If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then | |
4541 | the result will be absolute, otherwise it will be relative. */) | |
4542 | (attribute, value1, value2) | |
4543 | Lisp_Object attribute, value1, value2; | |
4544 | { | |
4545 | if (EQ (value1, Qunspecified)) | |
4546 | return value2; | |
4547 | else if (EQ (attribute, QCheight)) | |
4548 | return merge_face_heights (value1, value2, value1, Qnil); | |
4549 | else | |
4550 | return value1; | |
4551 | } | |
4552 | ||
82641697 GM |
4553 | |
4554 | DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute, | |
4555 | Sinternal_get_lisp_face_attribute, | |
4556 | 2, 3, 0, | |
7ee72033 | 4557 | doc: /* Return face attribute KEYWORD of face SYMBOL. |
228299fa GM |
4558 | If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid |
4559 | face attribute name, signal an error. | |
4560 | If the optional argument FRAME is given, report on face FACE in that | |
4561 | frame. If FRAME is t, report on the defaults for face FACE (for new | |
7ee72033 MB |
4562 | frames). If FRAME is omitted or nil, use the selected frame. */) |
4563 | (symbol, keyword, frame) | |
82641697 GM |
4564 | Lisp_Object symbol, keyword, frame; |
4565 | { | |
4566 | Lisp_Object lface, value = Qnil; | |
178c5d9c | 4567 | |
b7826503 PJ |
4568 | CHECK_SYMBOL (symbol); |
4569 | CHECK_SYMBOL (keyword); | |
82641697 GM |
4570 | |
4571 | if (EQ (frame, Qt)) | |
4572 | lface = lface_from_face_name (NULL, symbol, 1); | |
4573 | else | |
4574 | { | |
4575 | if (NILP (frame)) | |
c0617987 | 4576 | frame = selected_frame; |
b7826503 | 4577 | CHECK_LIVE_FRAME (frame); |
82641697 GM |
4578 | lface = lface_from_face_name (XFRAME (frame), symbol, 1); |
4579 | } | |
4580 | ||
4581 | if (EQ (keyword, QCfamily)) | |
4582 | value = LFACE_FAMILY (lface); | |
4583 | else if (EQ (keyword, QCheight)) | |
4584 | value = LFACE_HEIGHT (lface); | |
4585 | else if (EQ (keyword, QCweight)) | |
4586 | value = LFACE_WEIGHT (lface); | |
4587 | else if (EQ (keyword, QCslant)) | |
4588 | value = LFACE_SLANT (lface); | |
4589 | else if (EQ (keyword, QCunderline)) | |
4590 | value = LFACE_UNDERLINE (lface); | |
4591 | else if (EQ (keyword, QCoverline)) | |
4592 | value = LFACE_OVERLINE (lface); | |
4593 | else if (EQ (keyword, QCstrike_through)) | |
4594 | value = LFACE_STRIKE_THROUGH (lface); | |
4595 | else if (EQ (keyword, QCbox)) | |
4596 | value = LFACE_BOX (lface); | |
4597 | else if (EQ (keyword, QCinverse_video) | |
4598 | || EQ (keyword, QCreverse_video)) | |
4599 | value = LFACE_INVERSE (lface); | |
4600 | else if (EQ (keyword, QCforeground)) | |
4601 | value = LFACE_FOREGROUND (lface); | |
4602 | else if (EQ (keyword, QCbackground)) | |
4603 | value = LFACE_BACKGROUND (lface); | |
4604 | else if (EQ (keyword, QCstipple)) | |
4605 | value = LFACE_STIPPLE (lface); | |
4606 | else if (EQ (keyword, QCwidth)) | |
4607 | value = LFACE_SWIDTH (lface); | |
2c20458f MB |
4608 | else if (EQ (keyword, QCinherit)) |
4609 | value = LFACE_INHERIT (lface); | |
39506348 KH |
4610 | else if (EQ (keyword, QCfont)) |
4611 | value = LFACE_FONT (lface); | |
82641697 GM |
4612 | else |
4613 | signal_error ("Invalid face attribute name", keyword); | |
4614 | ||
4615 | return value; | |
4616 | } | |
4617 | ||
4618 | ||
4619 | DEFUN ("internal-lisp-face-attribute-values", | |
4620 | Finternal_lisp_face_attribute_values, | |
4621 | Sinternal_lisp_face_attribute_values, 1, 1, 0, | |
7ee72033 MB |
4622 | doc: /* Return a list of valid discrete values for face attribute ATTR. |
4623 | Value is nil if ATTR doesn't have a discrete set of valid values. */) | |
4624 | (attr) | |
82641697 GM |
4625 | Lisp_Object attr; |
4626 | { | |
4627 | Lisp_Object result = Qnil; | |
178c5d9c | 4628 | |
b7826503 | 4629 | CHECK_SYMBOL (attr); |
178c5d9c | 4630 | |
82641697 GM |
4631 | if (EQ (attr, QCweight) |
4632 | || EQ (attr, QCslant) | |
4633 | || EQ (attr, QCwidth)) | |
4634 | { | |
4635 | /* Extract permissible symbols from tables. */ | |
4636 | struct table_entry *table; | |
4637 | int i, dim; | |
178c5d9c | 4638 | |
82641697 GM |
4639 | if (EQ (attr, QCweight)) |
4640 | table = weight_table, dim = DIM (weight_table); | |
4641 | else if (EQ (attr, QCslant)) | |
4642 | table = slant_table, dim = DIM (slant_table); | |
4643 | else | |
4644 | table = swidth_table, dim = DIM (swidth_table); | |
4645 | ||
4646 | for (i = 0; i < dim; ++i) | |
4647 | { | |
4648 | Lisp_Object symbol = *table[i].symbol; | |
4649 | Lisp_Object tail = result; | |
4650 | ||
4651 | while (!NILP (tail) | |
4652 | && !EQ (XCAR (tail), symbol)) | |
4653 | tail = XCDR (tail); | |
4654 | ||
4655 | if (NILP (tail)) | |
4656 | result = Fcons (symbol, result); | |
4657 | } | |
4658 | } | |
4659 | else if (EQ (attr, QCunderline)) | |
4660 | result = Fcons (Qt, Fcons (Qnil, Qnil)); | |
4661 | else if (EQ (attr, QCoverline)) | |
4662 | result = Fcons (Qt, Fcons (Qnil, Qnil)); | |
4663 | else if (EQ (attr, QCstrike_through)) | |
4664 | result = Fcons (Qt, Fcons (Qnil, Qnil)); | |
4665 | else if (EQ (attr, QCinverse_video) || EQ (attr, QCreverse_video)) | |
4666 | result = Fcons (Qt, Fcons (Qnil, Qnil)); | |
4667 | ||
4668 | return result; | |
4669 | } | |
178c5d9c | 4670 | |
82641697 GM |
4671 | |
4672 | DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face, | |
178c5d9c | 4673 | Sinternal_merge_in_global_face, 2, 2, 0, |
e3cd9e7f | 4674 | doc: /* Add attributes from frame-default definition of FACE to FACE on FRAME. |
7ee72033 MB |
4675 | Default face attributes override any local face attributes. */) |
4676 | (face, frame) | |
82641697 GM |
4677 | Lisp_Object face, frame; |
4678 | { | |
aad40737 MB |
4679 | int i; |
4680 | Lisp_Object global_lface, local_lface, *gvec, *lvec; | |
4681 | ||
b7826503 | 4682 | CHECK_LIVE_FRAME (frame); |
82641697 GM |
4683 | global_lface = lface_from_face_name (NULL, face, 1); |
4684 | local_lface = lface_from_face_name (XFRAME (frame), face, 0); | |
4685 | if (NILP (local_lface)) | |
4686 | local_lface = Finternal_make_lisp_face (face, frame); | |
aad40737 | 4687 | |
cec33c90 SM |
4688 | /* Make every specified global attribute override the local one. |
4689 | BEWARE!! This is only used from `face-set-after-frame-default' where | |
4690 | the local frame is defined from default specs in `face-defface-spec' | |
4691 | and those should be overridden by global settings. Hence the strange | |
4692 | "global before local" priority. */ | |
aad40737 MB |
4693 | lvec = XVECTOR (local_lface)->contents; |
4694 | gvec = XVECTOR (global_lface)->contents; | |
4695 | for (i = 1; i < LFACE_VECTOR_SIZE; ++i) | |
4696 | if (! UNSPECIFIEDP (gvec[i])) | |
4697 | lvec[i] = gvec[i]; | |
334a2e2a GM |
4698 | |
4699 | return Qnil; | |
82641697 GM |
4700 | } |
4701 | ||
4702 | ||
4703 | /* The following function is implemented for compatibility with 20.2. | |
4704 | The function is used in x-resolve-fonts when it is asked to | |
4705 | return fonts with the same size as the font of a face. This is | |
4706 | done in fontset.el. */ | |
4707 | ||
178c5d9c | 4708 | DEFUN ("face-font", Fface_font, Sface_font, 1, 2, 0, |
e3cd9e7f | 4709 | doc: /* Return the font name of face FACE, or nil if it is unspecified. |
228299fa GM |
4710 | If the optional argument FRAME is given, report on face FACE in that frame. |
4711 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
4712 | The font default for a face is either nil, or a list | |
4713 | of the form (bold), (italic) or (bold italic). | |
7ee72033 MB |
4714 | If FRAME is omitted or nil, use the selected frame. */) |
4715 | (face, frame) | |
82641697 GM |
4716 | Lisp_Object face, frame; |
4717 | { | |
4718 | if (EQ (frame, Qt)) | |
4719 | { | |
4720 | Lisp_Object result = Qnil; | |
4721 | Lisp_Object lface = lface_from_face_name (NULL, face, 1); | |
4722 | ||
4723 | if (!UNSPECIFIEDP (LFACE_WEIGHT (lface)) | |
4724 | && !EQ (LFACE_WEIGHT (lface), Qnormal)) | |
4725 | result = Fcons (Qbold, result); | |
178c5d9c | 4726 | |
0f2c6573 | 4727 | if (!UNSPECIFIEDP (LFACE_SLANT (lface)) |
82641697 GM |
4728 | && !EQ (LFACE_SLANT (lface), Qnormal)) |
4729 | result = Fcons (Qitalic, result); | |
178c5d9c | 4730 | |
82641697 GM |
4731 | return result; |
4732 | } | |
4733 | else | |
4734 | { | |
4735 | struct frame *f = frame_or_selected_frame (frame, 1); | |
39506348 | 4736 | int face_id = lookup_named_face (f, face, 0); |
82641697 | 4737 | struct face *face = FACE_FROM_ID (f, face_id); |
b5de343d | 4738 | return face ? build_string (face->font_name) : Qnil; |
82641697 GM |
4739 | } |
4740 | } | |
4741 | ||
4742 | ||
4743 | /* Compare face vectors V1 and V2 for equality. Value is non-zero if | |
4744 | all attributes are `equal'. Tries to be fast because this function | |
4745 | is called quite often. */ | |
4746 | ||
4747 | static INLINE int | |
4748 | lface_equal_p (v1, v2) | |
4749 | Lisp_Object *v1, *v2; | |
4750 | { | |
4751 | int i, equal_p = 1; | |
4752 | ||
4753 | for (i = 1; i < LFACE_VECTOR_SIZE && equal_p; ++i) | |
4754 | { | |
4755 | Lisp_Object a = v1[i]; | |
4756 | Lisp_Object b = v2[i]; | |
4757 | ||
4758 | /* Type can differ, e.g. when one attribute is unspecified, i.e. nil, | |
4759 | and the other is specified. */ | |
4760 | equal_p = XTYPE (a) == XTYPE (b); | |
4761 | if (!equal_p) | |
4762 | break; | |
4763 | ||
4764 | if (!EQ (a, b)) | |
4765 | { | |
4766 | switch (XTYPE (a)) | |
4767 | { | |
4768 | case Lisp_String: | |
ae4b4ba5 GM |
4769 | equal_p = ((STRING_BYTES (XSTRING (a)) |
4770 | == STRING_BYTES (XSTRING (b))) | |
82641697 | 4771 | && bcmp (XSTRING (a)->data, XSTRING (b)->data, |
ae4b4ba5 | 4772 | STRING_BYTES (XSTRING (a))) == 0); |
82641697 | 4773 | break; |
178c5d9c | 4774 | |
82641697 GM |
4775 | case Lisp_Int: |
4776 | case Lisp_Symbol: | |
4777 | equal_p = 0; | |
4778 | break; | |
178c5d9c | 4779 | |
82641697 GM |
4780 | default: |
4781 | equal_p = !NILP (Fequal (a, b)); | |
4782 | break; | |
4783 | } | |
4784 | } | |
4785 | } | |
178c5d9c | 4786 | |
82641697 GM |
4787 | return equal_p; |
4788 | } | |
4789 | ||
4790 | ||
4791 | DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p, | |
4792 | Sinternal_lisp_face_equal_p, 2, 3, 0, | |
7ee72033 | 4793 | doc: /* True if FACE1 and FACE2 are equal. |
228299fa GM |
4794 | If the optional argument FRAME is given, report on face FACE in that frame. |
4795 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
7ee72033 MB |
4796 | If FRAME is omitted or nil, use the selected frame. */) |
4797 | (face1, face2, frame) | |
82641697 GM |
4798 | Lisp_Object face1, face2, frame; |
4799 | { | |
4800 | int equal_p; | |
4801 | struct frame *f; | |
4802 | Lisp_Object lface1, lface2; | |
178c5d9c | 4803 | |
82641697 GM |
4804 | if (EQ (frame, Qt)) |
4805 | f = NULL; | |
4806 | else | |
4807 | /* Don't use check_x_frame here because this function is called | |
4808 | before X frames exist. At that time, if FRAME is nil, | |
4809 | selected_frame will be used which is the frame dumped with | |
4810 | Emacs. That frame is not an X frame. */ | |
4811 | f = frame_or_selected_frame (frame, 2); | |
4812 | ||
4813 | lface1 = lface_from_face_name (NULL, face1, 1); | |
4814 | lface2 = lface_from_face_name (NULL, face2, 1); | |
4815 | equal_p = lface_equal_p (XVECTOR (lface1)->contents, | |
4816 | XVECTOR (lface2)->contents); | |
4817 | return equal_p ? Qt : Qnil; | |
4818 | } | |
4819 | ||
178c5d9c | 4820 | |
82641697 GM |
4821 | DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p, |
4822 | Sinternal_lisp_face_empty_p, 1, 2, 0, | |
7ee72033 | 4823 | doc: /* True if FACE has no attribute specified. |
228299fa GM |
4824 | If the optional argument FRAME is given, report on face FACE in that frame. |
4825 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
7ee72033 MB |
4826 | If FRAME is omitted or nil, use the selected frame. */) |
4827 | (face, frame) | |
82641697 GM |
4828 | Lisp_Object face, frame; |
4829 | { | |
4830 | struct frame *f; | |
4831 | Lisp_Object lface; | |
4832 | int i; | |
4833 | ||
4834 | if (NILP (frame)) | |
c0617987 | 4835 | frame = selected_frame; |
b7826503 | 4836 | CHECK_LIVE_FRAME (frame); |
c0617987 | 4837 | f = XFRAME (frame); |
178c5d9c | 4838 | |
82641697 GM |
4839 | if (EQ (frame, Qt)) |
4840 | lface = lface_from_face_name (NULL, face, 1); | |
4841 | else | |
4842 | lface = lface_from_face_name (f, face, 1); | |
4843 | ||
4844 | for (i = 1; i < LFACE_VECTOR_SIZE; ++i) | |
a08332c0 | 4845 | if (!UNSPECIFIEDP (AREF (lface, i))) |
82641697 | 4846 | break; |
178c5d9c | 4847 | |
82641697 GM |
4848 | return i == LFACE_VECTOR_SIZE ? Qt : Qnil; |
4849 | } | |
4850 | ||
4851 | ||
4852 | DEFUN ("frame-face-alist", Fframe_face_alist, Sframe_face_alist, | |
178c5d9c | 4853 | 0, 1, 0, |
7ee72033 MB |
4854 | doc: /* Return an alist of frame-local faces defined on FRAME. |
4855 | For internal use only. */) | |
4856 | (frame) | |
82641697 GM |
4857 | Lisp_Object frame; |
4858 | { | |
4859 | struct frame *f = frame_or_selected_frame (frame, 0); | |
4860 | return f->face_alist; | |
4861 | } | |
4862 | ||
4863 | ||
4864 | /* Return a hash code for Lisp string STRING with case ignored. Used | |
4865 | below in computing a hash value for a Lisp face. */ | |
4866 | ||
4867 | static INLINE unsigned | |
4868 | hash_string_case_insensitive (string) | |
4869 | Lisp_Object string; | |
4870 | { | |
4871 | unsigned char *s; | |
4872 | unsigned hash = 0; | |
4873 | xassert (STRINGP (string)); | |
4874 | for (s = XSTRING (string)->data; *s; ++s) | |
4875 | hash = (hash << 1) ^ tolower (*s); | |
4876 | return hash; | |
4877 | } | |
4878 | ||
4879 | ||
4880 | /* Return a hash code for face attribute vector V. */ | |
4881 | ||
4882 | static INLINE unsigned | |
4883 | lface_hash (v) | |
4884 | Lisp_Object *v; | |
4885 | { | |
4886 | return (hash_string_case_insensitive (v[LFACE_FAMILY_INDEX]) | |
4887 | ^ hash_string_case_insensitive (v[LFACE_FOREGROUND_INDEX]) | |
4888 | ^ hash_string_case_insensitive (v[LFACE_BACKGROUND_INDEX]) | |
6fc556fd KR |
4889 | ^ XFASTINT (v[LFACE_WEIGHT_INDEX]) |
4890 | ^ XFASTINT (v[LFACE_SLANT_INDEX]) | |
4891 | ^ XFASTINT (v[LFACE_SWIDTH_INDEX]) | |
82641697 GM |
4892 | ^ XFASTINT (v[LFACE_HEIGHT_INDEX])); |
4893 | } | |
4894 | ||
4895 | ||
4896 | /* Return non-zero if LFACE1 and LFACE2 specify the same font (without | |
4897 | considering charsets/registries). They do if they specify the same | |
39506348 KH |
4898 | family, point size, weight, width, slant, and fontset. Both LFACE1 |
4899 | and LFACE2 must be fully-specified. */ | |
82641697 GM |
4900 | |
4901 | static INLINE int | |
4902 | lface_same_font_attributes_p (lface1, lface2) | |
4903 | Lisp_Object *lface1, *lface2; | |
4904 | { | |
4905 | xassert (lface_fully_specified_p (lface1) | |
4906 | && lface_fully_specified_p (lface2)); | |
4907 | return (xstricmp (XSTRING (lface1[LFACE_FAMILY_INDEX])->data, | |
4908 | XSTRING (lface2[LFACE_FAMILY_INDEX])->data) == 0 | |
2c20458f | 4909 | && EQ (lface1[LFACE_HEIGHT_INDEX], lface2[LFACE_HEIGHT_INDEX]) |
82641697 | 4910 | && EQ (lface1[LFACE_SWIDTH_INDEX], lface2[LFACE_SWIDTH_INDEX]) |
a08332c0 | 4911 | && EQ (lface1[LFACE_AVGWIDTH_INDEX], lface2[LFACE_AVGWIDTH_INDEX]) |
82641697 | 4912 | && EQ (lface1[LFACE_WEIGHT_INDEX], lface2[LFACE_WEIGHT_INDEX]) |
39506348 KH |
4913 | && EQ (lface1[LFACE_SLANT_INDEX], lface2[LFACE_SLANT_INDEX]) |
4914 | && (EQ (lface1[LFACE_FONT_INDEX], lface2[LFACE_FONT_INDEX]) | |
4915 | || (STRINGP (lface1[LFACE_FONT_INDEX]) | |
d00b1b63 | 4916 | && STRINGP (lface2[LFACE_FONT_INDEX]) |
39506348 KH |
4917 | && xstricmp (XSTRING (lface1[LFACE_FONT_INDEX])->data, |
4918 | XSTRING (lface2[LFACE_FONT_INDEX])->data)))); | |
82641697 GM |
4919 | } |
4920 | ||
4921 | ||
4922 | \f | |
4923 | /*********************************************************************** | |
4924 | Realized Faces | |
4925 | ***********************************************************************/ | |
4926 | ||
4927 | /* Allocate and return a new realized face for Lisp face attribute | |
39506348 | 4928 | vector ATTR. */ |
82641697 GM |
4929 | |
4930 | static struct face * | |
39506348 | 4931 | make_realized_face (attr) |
82641697 | 4932 | Lisp_Object *attr; |
82641697 GM |
4933 | { |
4934 | struct face *face = (struct face *) xmalloc (sizeof *face); | |
4935 | bzero (face, sizeof *face); | |
39506348 | 4936 | face->ascii_face = face; |
82641697 GM |
4937 | bcopy (attr, face->lface, sizeof face->lface); |
4938 | return face; | |
4939 | } | |
4940 | ||
4941 | ||
4942 | /* Free realized face FACE, including its X resources. FACE may | |
4943 | be null. */ | |
4944 | ||
4945 | static void | |
4946 | free_realized_face (f, face) | |
4947 | struct frame *f; | |
4948 | struct face *face; | |
4949 | { | |
4950 | if (face) | |
4951 | { | |
c3cee013 JR |
4952 | #ifdef HAVE_WINDOW_SYSTEM |
4953 | if (FRAME_WINDOW_P (f)) | |
82641697 | 4954 | { |
39506348 KH |
4955 | /* Free fontset of FACE if it is ASCII face. */ |
4956 | if (face->fontset >= 0 && face == face->ascii_face) | |
4957 | free_face_fontset (f, face); | |
82641697 GM |
4958 | if (face->gc) |
4959 | { | |
4960 | x_free_gc (f, face->gc); | |
4961 | face->gc = 0; | |
4962 | } | |
178c5d9c | 4963 | |
82641697 GM |
4964 | free_face_colors (f, face); |
4965 | x_destroy_bitmap (f, face->stipple); | |
4966 | } | |
c3cee013 | 4967 | #endif /* HAVE_WINDOW_SYSTEM */ |
82641697 GM |
4968 | |
4969 | xfree (face); | |
4970 | } | |
4971 | } | |
4972 | ||
4973 | ||
4974 | /* Prepare face FACE for subsequent display on frame F. This | |
4975 | allocated GCs if they haven't been allocated yet or have been freed | |
4976 | by clearing the face cache. */ | |
4977 | ||
4978 | void | |
4979 | prepare_face_for_display (f, face) | |
4980 | struct frame *f; | |
4981 | struct face *face; | |
4982 | { | |
c3cee013 JR |
4983 | #ifdef HAVE_WINDOW_SYSTEM |
4984 | xassert (FRAME_WINDOW_P (f)); | |
178c5d9c | 4985 | |
82641697 GM |
4986 | if (face->gc == 0) |
4987 | { | |
4988 | XGCValues xgcv; | |
4989 | unsigned long mask = GCForeground | GCBackground | GCGraphicsExposures; | |
4990 | ||
4991 | xgcv.foreground = face->foreground; | |
4992 | xgcv.background = face->background; | |
c3cee013 | 4993 | #ifdef HAVE_X_WINDOWS |
82641697 | 4994 | xgcv.graphics_exposures = False; |
c3cee013 | 4995 | #endif |
82641697 GM |
4996 | /* The font of FACE may be null if we couldn't load it. */ |
4997 | if (face->font) | |
4998 | { | |
c3cee013 | 4999 | #ifdef HAVE_X_WINDOWS |
82641697 | 5000 | xgcv.font = face->font->fid; |
c3cee013 JR |
5001 | #endif |
5002 | #ifdef WINDOWSNT | |
5003 | xgcv.font = face->font; | |
1a578e9b | 5004 | #endif |
e0f712ba | 5005 | #ifdef MAC_OS |
1a578e9b | 5006 | xgcv.font = face->font; |
c3cee013 | 5007 | #endif |
82641697 GM |
5008 | mask |= GCFont; |
5009 | } | |
5010 | ||
5011 | BLOCK_INPUT; | |
c3cee013 | 5012 | #ifdef HAVE_X_WINDOWS |
82641697 GM |
5013 | if (face->stipple) |
5014 | { | |
be8a72f4 | 5015 | xgcv.fill_style = FillOpaqueStippled; |
82641697 GM |
5016 | xgcv.stipple = x_bitmap_pixmap (f, face->stipple); |
5017 | mask |= GCFillStyle | GCStipple; | |
5018 | } | |
c3cee013 | 5019 | #endif |
82641697 GM |
5020 | face->gc = x_create_gc (f, mask, &xgcv); |
5021 | UNBLOCK_INPUT; | |
5022 | } | |
c3cee013 | 5023 | #endif /* HAVE_WINDOW_SYSTEM */ |
82641697 GM |
5024 | } |
5025 | ||
82641697 GM |
5026 | \f |
5027 | /*********************************************************************** | |
5028 | Face Cache | |
5029 | ***********************************************************************/ | |
5030 | ||
5031 | /* Return a new face cache for frame F. */ | |
5032 | ||
5033 | static struct face_cache * | |
5034 | make_face_cache (f) | |
5035 | struct frame *f; | |
5036 | { | |
5037 | struct face_cache *c; | |
5038 | int size; | |
5039 | ||
5040 | c = (struct face_cache *) xmalloc (sizeof *c); | |
5041 | bzero (c, sizeof *c); | |
5042 | size = FACE_CACHE_BUCKETS_SIZE * sizeof *c->buckets; | |
5043 | c->buckets = (struct face **) xmalloc (size); | |
5044 | bzero (c->buckets, size); | |
5045 | c->size = 50; | |
5046 | c->faces_by_id = (struct face **) xmalloc (c->size * sizeof *c->faces_by_id); | |
5047 | c->f = f; | |
ceeda019 | 5048 | c->menu_face_changed_p = menu_face_changed_default; |
82641697 GM |
5049 | return c; |
5050 | } | |
5051 | ||
5052 | ||
5053 | /* Clear out all graphics contexts for all realized faces, except for | |
5054 | the basic faces. This should be done from time to time just to avoid | |
5055 | keeping too many graphics contexts that are no longer needed. */ | |
5056 | ||
5057 | static void | |
5058 | clear_face_gcs (c) | |
5059 | struct face_cache *c; | |
5060 | { | |
c3cee013 | 5061 | if (c && FRAME_WINDOW_P (c->f)) |
82641697 | 5062 | { |
c3cee013 | 5063 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 GM |
5064 | int i; |
5065 | for (i = BASIC_FACE_ID_SENTINEL; i < c->used; ++i) | |
5066 | { | |
5067 | struct face *face = c->faces_by_id[i]; | |
5068 | if (face && face->gc) | |
5069 | { | |
5070 | x_free_gc (c->f, face->gc); | |
5071 | face->gc = 0; | |
5072 | } | |
5073 | } | |
c3cee013 | 5074 | #endif /* HAVE_WINDOW_SYSTEM */ |
82641697 GM |
5075 | } |
5076 | } | |
5077 | ||
5078 | ||
5079 | /* Free all realized faces in face cache C, including basic faces. C | |
5080 | may be null. If faces are freed, make sure the frame's current | |
5081 | matrix is marked invalid, so that a display caused by an expose | |
5082 | event doesn't try to use faces we destroyed. */ | |
5083 | ||
5084 | static void | |
5085 | free_realized_faces (c) | |
5086 | struct face_cache *c; | |
5087 | { | |
5088 | if (c && c->used) | |
5089 | { | |
5090 | int i, size; | |
5091 | struct frame *f = c->f; | |
5092 | ||
84ec3b4b GM |
5093 | /* We must block input here because we can't process X events |
5094 | safely while only some faces are freed, or when the frame's | |
5095 | current matrix still references freed faces. */ | |
5096 | BLOCK_INPUT; | |
5097 | ||
82641697 GM |
5098 | for (i = 0; i < c->used; ++i) |
5099 | { | |
5100 | free_realized_face (f, c->faces_by_id[i]); | |
5101 | c->faces_by_id[i] = NULL; | |
5102 | } | |
178c5d9c | 5103 | |
82641697 GM |
5104 | c->used = 0; |
5105 | size = FACE_CACHE_BUCKETS_SIZE * sizeof *c->buckets; | |
5106 | bzero (c->buckets, size); | |
5107 | ||
5108 | /* Must do a thorough redisplay the next time. Mark current | |
5109 | matrices as invalid because they will reference faces freed | |
5110 | above. This function is also called when a frame is | |
5111 | destroyed. In this case, the root window of F is nil. */ | |
5112 | if (WINDOWP (f->root_window)) | |
5113 | { | |
5114 | clear_current_matrices (f); | |
5115 | ++windows_or_buffers_changed; | |
5116 | } | |
84ec3b4b GM |
5117 | |
5118 | UNBLOCK_INPUT; | |
82641697 GM |
5119 | } |
5120 | } | |
5121 | ||
5122 | ||
39506348 KH |
5123 | /* Free all faces realized for multibyte characters on frame F that |
5124 | has FONTSET. */ | |
5125 | ||
5126 | void | |
5127 | free_realized_multibyte_face (f, fontset) | |
5128 | struct frame *f; | |
5129 | int fontset; | |
5130 | { | |
5131 | struct face_cache *cache = FRAME_FACE_CACHE (f); | |
5132 | struct face *face; | |
5133 | int i; | |
5134 | ||
84ec3b4b GM |
5135 | /* We must block input here because we can't process X events safely |
5136 | while only some faces are freed, or when the frame's current | |
5137 | matrix still references freed faces. */ | |
5138 | BLOCK_INPUT; | |
178c5d9c | 5139 | |
39506348 KH |
5140 | for (i = 0; i < cache->used; i++) |
5141 | { | |
5142 | face = cache->faces_by_id[i]; | |
5143 | if (face | |
5144 | && face != face->ascii_face | |
5145 | && face->fontset == fontset) | |
5146 | { | |
5147 | uncache_face (cache, face); | |
5148 | free_realized_face (f, face); | |
5149 | } | |
5150 | } | |
178c5d9c | 5151 | |
84ec3b4b GM |
5152 | /* Must do a thorough redisplay the next time. Mark current |
5153 | matrices as invalid because they will reference faces freed | |
5154 | above. This function is also called when a frame is destroyed. | |
5155 | In this case, the root window of F is nil. */ | |
39506348 KH |
5156 | if (WINDOWP (f->root_window)) |
5157 | { | |
5158 | clear_current_matrices (f); | |
5159 | ++windows_or_buffers_changed; | |
5160 | } | |
178c5d9c | 5161 | |
84ec3b4b | 5162 | UNBLOCK_INPUT; |
39506348 KH |
5163 | } |
5164 | ||
5165 | ||
82641697 GM |
5166 | /* Free all realized faces on FRAME or on all frames if FRAME is nil. |
5167 | This is done after attributes of a named face have been changed, | |
5168 | because we can't tell which realized faces depend on that face. */ | |
5169 | ||
5170 | void | |
5171 | free_all_realized_faces (frame) | |
5172 | Lisp_Object frame; | |
5173 | { | |
5174 | if (NILP (frame)) | |
5175 | { | |
5176 | Lisp_Object rest; | |
5177 | FOR_EACH_FRAME (rest, frame) | |
5178 | free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame))); | |
5179 | } | |
5180 | else | |
5181 | free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame))); | |
5182 | } | |
5183 | ||
5184 | ||
5185 | /* Free face cache C and faces in it, including their X resources. */ | |
5186 | ||
5187 | static void | |
5188 | free_face_cache (c) | |
5189 | struct face_cache *c; | |
5190 | { | |
5191 | if (c) | |
5192 | { | |
5193 | free_realized_faces (c); | |
5194 | xfree (c->buckets); | |
5195 | xfree (c->faces_by_id); | |
5196 | xfree (c); | |
5197 | } | |
5198 | } | |
5199 | ||
5200 | ||
5201 | /* Cache realized face FACE in face cache C. HASH is the hash value | |
5202 | of FACE. If FACE->fontset >= 0, add the new face to the end of the | |
5203 | collision list of the face hash table of C. This is done because | |
39506348 KH |
5204 | otherwise lookup_face would find FACE for every character, even if |
5205 | faces with the same attributes but for specific characters exist. */ | |
82641697 GM |
5206 | |
5207 | static void | |
5208 | cache_face (c, face, hash) | |
5209 | struct face_cache *c; | |
5210 | struct face *face; | |
5211 | unsigned hash; | |
5212 | { | |
5213 | int i = hash % FACE_CACHE_BUCKETS_SIZE; | |
5214 | ||
5215 | face->hash = hash; | |
5216 | ||
5217 | if (face->fontset >= 0) | |
5218 | { | |
5219 | struct face *last = c->buckets[i]; | |
5220 | if (last) | |
5221 | { | |
5222 | while (last->next) | |
5223 | last = last->next; | |
5224 | last->next = face; | |
5225 | face->prev = last; | |
5226 | face->next = NULL; | |
5227 | } | |
5228 | else | |
5229 | { | |
5230 | c->buckets[i] = face; | |
5231 | face->prev = face->next = NULL; | |
5232 | } | |
5233 | } | |
5234 | else | |
5235 | { | |
5236 | face->prev = NULL; | |
5237 | face->next = c->buckets[i]; | |
5238 | if (face->next) | |
5239 | face->next->prev = face; | |
5240 | c->buckets[i] = face; | |
5241 | } | |
5242 | ||
5243 | /* Find a free slot in C->faces_by_id and use the index of the free | |
5244 | slot as FACE->id. */ | |
5245 | for (i = 0; i < c->used; ++i) | |
5246 | if (c->faces_by_id[i] == NULL) | |
5247 | break; | |
5248 | face->id = i; | |
178c5d9c | 5249 | |
82641697 GM |
5250 | /* Maybe enlarge C->faces_by_id. */ |
5251 | if (i == c->used && c->used == c->size) | |
5252 | { | |
5253 | int new_size = 2 * c->size; | |
5254 | int sz = new_size * sizeof *c->faces_by_id; | |
5255 | c->faces_by_id = (struct face **) xrealloc (c->faces_by_id, sz); | |
5256 | c->size = new_size; | |
5257 | } | |
5258 | ||
5259 | #if GLYPH_DEBUG | |
5260 | /* Check that FACE got a unique id. */ | |
5261 | { | |
5262 | int j, n; | |
5263 | struct face *face; | |
5264 | ||
5265 | for (j = n = 0; j < FACE_CACHE_BUCKETS_SIZE; ++j) | |
5266 | for (face = c->buckets[j]; face; face = face->next) | |
5267 | if (face->id == i) | |
5268 | ++n; | |
5269 | ||
5270 | xassert (n == 1); | |
5271 | } | |
5272 | #endif /* GLYPH_DEBUG */ | |
178c5d9c | 5273 | |
82641697 GM |
5274 | c->faces_by_id[i] = face; |
5275 | if (i == c->used) | |
5276 | ++c->used; | |
5277 | } | |
5278 | ||
5279 | ||
5280 | /* Remove face FACE from cache C. */ | |
5281 | ||
5282 | static void | |
5283 | uncache_face (c, face) | |
5284 | struct face_cache *c; | |
5285 | struct face *face; | |
5286 | { | |
5287 | int i = face->hash % FACE_CACHE_BUCKETS_SIZE; | |
178c5d9c | 5288 | |
82641697 GM |
5289 | if (face->prev) |
5290 | face->prev->next = face->next; | |
5291 | else | |
5292 | c->buckets[i] = face->next; | |
178c5d9c | 5293 | |
82641697 GM |
5294 | if (face->next) |
5295 | face->next->prev = face->prev; | |
178c5d9c | 5296 | |
82641697 GM |
5297 | c->faces_by_id[face->id] = NULL; |
5298 | if (face->id == c->used) | |
5299 | --c->used; | |
5300 | } | |
5301 | ||
5302 | ||
5303 | /* Look up a realized face with face attributes ATTR in the face cache | |
39506348 KH |
5304 | of frame F. The face will be used to display character C. Value |
5305 | is the ID of the face found. If no suitable face is found, realize | |
5306 | a new one. In that case, if C is a multibyte character, BASE_FACE | |
0badc114 | 5307 | is a face that has the same attributes. */ |
82641697 GM |
5308 | |
5309 | INLINE int | |
39506348 | 5310 | lookup_face (f, attr, c, base_face) |
82641697 GM |
5311 | struct frame *f; |
5312 | Lisp_Object *attr; | |
39506348 KH |
5313 | int c; |
5314 | struct face *base_face; | |
82641697 | 5315 | { |
39506348 | 5316 | struct face_cache *cache = FRAME_FACE_CACHE (f); |
82641697 GM |
5317 | unsigned hash; |
5318 | int i; | |
5319 | struct face *face; | |
5320 | ||
39506348 | 5321 | xassert (cache != NULL); |
82641697 GM |
5322 | check_lface_attrs (attr); |
5323 | ||
5324 | /* Look up ATTR in the face cache. */ | |
5325 | hash = lface_hash (attr); | |
5326 | i = hash % FACE_CACHE_BUCKETS_SIZE; | |
178c5d9c | 5327 | |
39506348 | 5328 | for (face = cache->buckets[i]; face; face = face->next) |
82641697 | 5329 | if (face->hash == hash |
44747bd0 | 5330 | && (!FRAME_WINDOW_P (f) |
39506348 | 5331 | || FACE_SUITABLE_FOR_CHAR_P (face, c)) |
82641697 GM |
5332 | && lface_equal_p (face->lface, attr)) |
5333 | break; | |
5334 | ||
5335 | /* If not found, realize a new face. */ | |
5336 | if (face == NULL) | |
39506348 | 5337 | face = realize_face (cache, attr, c, base_face, -1); |
82641697 GM |
5338 | |
5339 | #if GLYPH_DEBUG | |
5340 | xassert (face == FACE_FROM_ID (f, face->id)); | |
d2ff77da KH |
5341 | |
5342 | /* When this function is called from face_for_char (in this case, C is | |
5343 | a multibyte character), a fontset of a face returned by | |
5344 | realize_face is not yet set, i.e. FACE_SUITABLE_FOR_CHAR_P (FACE, | |
5345 | C) is not sutisfied. The fontset is set for this face by | |
5346 | face_for_char later. */ | |
c87a1fda | 5347 | #if 0 |
c3cee013 | 5348 | if (FRAME_WINDOW_P (f)) |
39506348 | 5349 | xassert (FACE_SUITABLE_FOR_CHAR_P (face, c)); |
c87a1fda | 5350 | #endif |
82641697 | 5351 | #endif /* GLYPH_DEBUG */ |
178c5d9c | 5352 | |
82641697 GM |
5353 | return face->id; |
5354 | } | |
5355 | ||
5356 | ||
5357 | /* Return the face id of the realized face for named face SYMBOL on | |
b5de343d GM |
5358 | frame F suitable for displaying character C. Value is -1 if the |
5359 | face couldn't be determined, which might happen if the default face | |
5360 | isn't realized and cannot be realized. */ | |
82641697 GM |
5361 | |
5362 | int | |
39506348 | 5363 | lookup_named_face (f, symbol, c) |
82641697 GM |
5364 | struct frame *f; |
5365 | Lisp_Object symbol; | |
39506348 | 5366 | int c; |
82641697 GM |
5367 | { |
5368 | Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
5369 | Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE]; | |
5370 | struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); | |
5371 | ||
b5de343d GM |
5372 | if (default_face == NULL) |
5373 | { | |
5374 | if (!realize_basic_faces (f)) | |
5375 | return -1; | |
5376 | default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); | |
5377 | } | |
5378 | ||
82641697 GM |
5379 | get_lface_attributes (f, symbol, symbol_attrs, 1); |
5380 | bcopy (default_face->lface, attrs, sizeof attrs); | |
2c20458f | 5381 | merge_face_vectors (f, symbol_attrs, attrs, Qnil); |
39506348 | 5382 | return lookup_face (f, attrs, c, NULL); |
82641697 GM |
5383 | } |
5384 | ||
5385 | ||
5386 | /* Return the ID of the realized ASCII face of Lisp face with ID | |
5387 | LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */ | |
5388 | ||
5389 | int | |
5390 | ascii_face_of_lisp_face (f, lface_id) | |
5391 | struct frame *f; | |
5392 | int lface_id; | |
5393 | { | |
5394 | int face_id; | |
178c5d9c | 5395 | |
82641697 GM |
5396 | if (lface_id >= 0 && lface_id < lface_id_to_name_size) |
5397 | { | |
5398 | Lisp_Object face_name = lface_id_to_name[lface_id]; | |
39506348 | 5399 | face_id = lookup_named_face (f, face_name, 0); |
82641697 GM |
5400 | } |
5401 | else | |
5402 | face_id = -1; | |
5403 | ||
5404 | return face_id; | |
5405 | } | |
5406 | ||
5407 | ||
5408 | /* Return a face for charset ASCII that is like the face with id | |
5409 | FACE_ID on frame F, but has a font that is STEPS steps smaller. | |
5410 | STEPS < 0 means larger. Value is the id of the face. */ | |
5411 | ||
5412 | int | |
5413 | smaller_face (f, face_id, steps) | |
5414 | struct frame *f; | |
5415 | int face_id, steps; | |
39506348 | 5416 | { |
c3cee013 | 5417 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 GM |
5418 | struct face *face; |
5419 | Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
5420 | int pt, last_pt, last_height; | |
5421 | int delta; | |
5422 | int new_face_id; | |
5423 | struct face *new_face; | |
5424 | ||
5425 | /* If not called for an X frame, just return the original face. */ | |
5426 | if (FRAME_TERMCAP_P (f)) | |
5427 | return face_id; | |
5428 | ||
5429 | /* Try in increments of 1/2 pt. */ | |
5430 | delta = steps < 0 ? 5 : -5; | |
5431 | steps = abs (steps); | |
178c5d9c | 5432 | |
82641697 GM |
5433 | face = FACE_FROM_ID (f, face_id); |
5434 | bcopy (face->lface, attrs, sizeof attrs); | |
5435 | pt = last_pt = XFASTINT (attrs[LFACE_HEIGHT_INDEX]); | |
5436 | new_face_id = face_id; | |
5437 | last_height = FONT_HEIGHT (face->font); | |
5438 | ||
5439 | while (steps | |
5440 | && pt + delta > 0 | |
5441 | /* Give up if we cannot find a font within 10pt. */ | |
5442 | && abs (last_pt - pt) < 100) | |
5443 | { | |
5444 | /* Look up a face for a slightly smaller/larger font. */ | |
5445 | pt += delta; | |
5446 | attrs[LFACE_HEIGHT_INDEX] = make_number (pt); | |
39506348 | 5447 | new_face_id = lookup_face (f, attrs, 0, NULL); |
82641697 GM |
5448 | new_face = FACE_FROM_ID (f, new_face_id); |
5449 | ||
5450 | /* If height changes, count that as one step. */ | |
b4c3ca09 GM |
5451 | if ((delta < 0 && FONT_HEIGHT (new_face->font) < last_height) |
5452 | || (delta > 0 && FONT_HEIGHT (new_face->font) > last_height)) | |
82641697 GM |
5453 | { |
5454 | --steps; | |
5455 | last_height = FONT_HEIGHT (new_face->font); | |
5456 | last_pt = pt; | |
5457 | } | |
5458 | } | |
5459 | ||
5460 | return new_face_id; | |
5461 | ||
c3cee013 | 5462 | #else /* not HAVE_WINDOW_SYSTEM */ |
82641697 GM |
5463 | |
5464 | return face_id; | |
178c5d9c | 5465 | |
c3cee013 | 5466 | #endif /* not HAVE_WINDOW_SYSTEM */ |
82641697 GM |
5467 | } |
5468 | ||
5469 | ||
5470 | /* Return a face for charset ASCII that is like the face with id | |
5471 | FACE_ID on frame F, but has height HEIGHT. */ | |
5472 | ||
5473 | int | |
5474 | face_with_height (f, face_id, height) | |
5475 | struct frame *f; | |
5476 | int face_id; | |
5477 | int height; | |
5478 | { | |
c3cee013 | 5479 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 GM |
5480 | struct face *face; |
5481 | Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
5482 | ||
5483 | if (FRAME_TERMCAP_P (f) | |
5484 | || height <= 0) | |
5485 | return face_id; | |
5486 | ||
5487 | face = FACE_FROM_ID (f, face_id); | |
5488 | bcopy (face->lface, attrs, sizeof attrs); | |
5489 | attrs[LFACE_HEIGHT_INDEX] = make_number (height); | |
39506348 | 5490 | face_id = lookup_face (f, attrs, 0, NULL); |
c3cee013 | 5491 | #endif /* HAVE_WINDOW_SYSTEM */ |
178c5d9c | 5492 | |
82641697 GM |
5493 | return face_id; |
5494 | } | |
5495 | ||
b5de343d | 5496 | |
44747bd0 | 5497 | /* Return the face id of the realized face for named face SYMBOL on |
39506348 KH |
5498 | frame F suitable for displaying character C, and use attributes of |
5499 | the face FACE_ID for attributes that aren't completely specified by | |
5500 | SYMBOL. This is like lookup_named_face, except that the default | |
5501 | attributes come from FACE_ID, not from the default face. FACE_ID | |
5502 | is assumed to be already realized. */ | |
44747bd0 EZ |
5503 | |
5504 | int | |
39506348 | 5505 | lookup_derived_face (f, symbol, c, face_id) |
44747bd0 EZ |
5506 | struct frame *f; |
5507 | Lisp_Object symbol; | |
39506348 | 5508 | int c; |
44747bd0 EZ |
5509 | int face_id; |
5510 | { | |
5511 | Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
5512 | Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE]; | |
5513 | struct face *default_face = FACE_FROM_ID (f, face_id); | |
5514 | ||
5515 | if (!default_face) | |
5516 | abort (); | |
5517 | ||
5518 | get_lface_attributes (f, symbol, symbol_attrs, 1); | |
5519 | bcopy (default_face->lface, attrs, sizeof attrs); | |
2c20458f | 5520 | merge_face_vectors (f, symbol_attrs, attrs, Qnil); |
39506348 | 5521 | return lookup_face (f, attrs, c, default_face); |
44747bd0 EZ |
5522 | } |
5523 | ||
f6608d5c RS |
5524 | DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector, |
5525 | Sface_attributes_as_vector, 1, 1, 0, | |
4bb962be | 5526 | doc: /* Return a vector of face attributes corresponding to PLIST. */) |
f6608d5c RS |
5527 | (plist) |
5528 | Lisp_Object plist; | |
5529 | { | |
5530 | Lisp_Object lface; | |
5531 | lface = Fmake_vector (make_number (LFACE_VECTOR_SIZE), | |
5532 | Qunspecified); | |
5533 | merge_face_vector_with_property (XFRAME (selected_frame), | |
5534 | XVECTOR (lface)->contents, | |
5535 | plist); | |
5536 | return lface; | |
5537 | } | |
5538 | ||
82641697 GM |
5539 | |
5540 | \f | |
5541 | /*********************************************************************** | |
5542 | Font selection | |
5543 | ***********************************************************************/ | |
5544 | ||
5545 | DEFUN ("internal-set-font-selection-order", | |
5546 | Finternal_set_font_selection_order, | |
5547 | Sinternal_set_font_selection_order, 1, 1, 0, | |
7ee72033 | 5548 | doc: /* Set font selection order for face font selection to ORDER. |
228299fa GM |
5549 | ORDER must be a list of length 4 containing the symbols `:width', |
5550 | `:height', `:weight', and `:slant'. Face attributes appearing | |
5551 | first in ORDER are matched first, e.g. if `:height' appears before | |
5552 | `:weight' in ORDER, font selection first tries to find a font with | |
5553 | a suitable height, and then tries to match the font weight. | |
7ee72033 MB |
5554 | Value is ORDER. */) |
5555 | (order) | |
228299fa | 5556 | Lisp_Object order; |
82641697 GM |
5557 | { |
5558 | Lisp_Object list; | |
5559 | int i; | |
a08332c0 | 5560 | int indices[DIM (font_sort_order)]; |
178c5d9c | 5561 | |
b7826503 | 5562 | CHECK_LIST (order); |
82641697 GM |
5563 | bzero (indices, sizeof indices); |
5564 | i = 0; | |
5565 | ||
5566 | for (list = order; | |
5567 | CONSP (list) && i < DIM (indices); | |
5568 | list = XCDR (list), ++i) | |
5569 | { | |
5570 | Lisp_Object attr = XCAR (list); | |
5571 | int xlfd; | |
5572 | ||
5573 | if (EQ (attr, QCwidth)) | |
5574 | xlfd = XLFD_SWIDTH; | |
5575 | else if (EQ (attr, QCheight)) | |
5576 | xlfd = XLFD_POINT_SIZE; | |
5577 | else if (EQ (attr, QCweight)) | |
5578 | xlfd = XLFD_WEIGHT; | |
5579 | else if (EQ (attr, QCslant)) | |
5580 | xlfd = XLFD_SLANT; | |
5581 | else | |
5582 | break; | |
5583 | ||
5584 | if (indices[i] != 0) | |
5585 | break; | |
5586 | indices[i] = xlfd; | |
5587 | } | |
5588 | ||
a08332c0 | 5589 | if (!NILP (list) || i != DIM (indices)) |
82641697 | 5590 | signal_error ("Invalid font sort order", order); |
a08332c0 GM |
5591 | for (i = 0; i < DIM (font_sort_order); ++i) |
5592 | if (indices[i] == 0) | |
5593 | signal_error ("Invalid font sort order", order); | |
82641697 GM |
5594 | |
5595 | if (bcmp (indices, font_sort_order, sizeof indices) != 0) | |
5596 | { | |
5597 | bcopy (indices, font_sort_order, sizeof font_sort_order); | |
5598 | free_all_realized_faces (Qnil); | |
5599 | } | |
178c5d9c | 5600 | |
82641697 GM |
5601 | return Qnil; |
5602 | } | |
5603 | ||
5604 | ||
5605 | DEFUN ("internal-set-alternative-font-family-alist", | |
5606 | Finternal_set_alternative_font_family_alist, | |
5607 | Sinternal_set_alternative_font_family_alist, 1, 1, 0, | |
c71f3632 | 5608 | doc: /* Define alternative font families to try in face font selection. |
228299fa GM |
5609 | ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries. |
5610 | Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can | |
7ee72033 MB |
5611 | be found. Value is ALIST. */) |
5612 | (alist) | |
82641697 GM |
5613 | Lisp_Object alist; |
5614 | { | |
b7826503 | 5615 | CHECK_LIST (alist); |
82641697 GM |
5616 | Vface_alternative_font_family_alist = alist; |
5617 | free_all_realized_faces (Qnil); | |
5618 | return alist; | |
5619 | } | |
5620 | ||
5621 | ||
32fcc231 GM |
5622 | DEFUN ("internal-set-alternative-font-registry-alist", |
5623 | Finternal_set_alternative_font_registry_alist, | |
5624 | Sinternal_set_alternative_font_registry_alist, 1, 1, 0, | |
e3cd9e7f | 5625 | doc: /* Define alternative font registries to try in face font selection. |
228299fa GM |
5626 | ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries. |
5627 | Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can | |
7ee72033 MB |
5628 | be found. Value is ALIST. */) |
5629 | (alist) | |
32fcc231 GM |
5630 | Lisp_Object alist; |
5631 | { | |
b7826503 | 5632 | CHECK_LIST (alist); |
32fcc231 GM |
5633 | Vface_alternative_font_registry_alist = alist; |
5634 | free_all_realized_faces (Qnil); | |
5635 | return alist; | |
5636 | } | |
5637 | ||
5638 | ||
c3cee013 | 5639 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 | 5640 | |
82641697 GM |
5641 | /* Value is non-zero if FONT is the name of a scalable font. The |
5642 | X11R6 XLFD spec says that point size, pixel size, and average width | |
5643 | are zero for scalable fonts. Intlfonts contain at least one | |
5644 | scalable font ("*-muleindian-1") for which this isn't true, so we | |
5645 | just test average width. */ | |
5646 | ||
5647 | static int | |
5648 | font_scalable_p (font) | |
5649 | struct font_name *font; | |
5650 | { | |
5651 | char *s = font->fields[XLFD_AVGWIDTH]; | |
c3cee013 JR |
5652 | return (*s == '0' && *(s + 1) == '\0') |
5653 | #ifdef WINDOWSNT | |
5654 | /* Windows implementation of XLFD is slightly broken for backward | |
5655 | compatibility with previous broken versions, so test for | |
5656 | wildcards as well as 0. */ | |
5657 | || *s == '*' | |
5658 | #endif | |
5659 | ; | |
82641697 GM |
5660 | } |
5661 | ||
5662 | ||
8e1b21a7 KH |
5663 | /* Ignore the difference of font point size less than this value. */ |
5664 | ||
5665 | #define FONT_POINT_SIZE_QUANTUM 5 | |
5666 | ||
82641697 GM |
5667 | /* Value is non-zero if FONT1 is a better match for font attributes |
5668 | VALUES than FONT2. VALUES is an array of face attribute values in | |
5669 | font sort order. COMPARE_PT_P zero means don't compare point | |
a08332c0 GM |
5670 | sizes. AVGWIDTH, if not zero, is a specified font average width |
5671 | to compare with. */ | |
82641697 GM |
5672 | |
5673 | static int | |
a08332c0 | 5674 | better_font_p (values, font1, font2, compare_pt_p, avgwidth) |
82641697 GM |
5675 | int *values; |
5676 | struct font_name *font1, *font2; | |
a08332c0 | 5677 | int compare_pt_p, avgwidth; |
82641697 GM |
5678 | { |
5679 | int i; | |
178c5d9c | 5680 | |
a08332c0 | 5681 | for (i = 0; i < DIM (font_sort_order); ++i) |
82641697 GM |
5682 | { |
5683 | int xlfd_idx = font_sort_order[i]; | |
5684 | ||
5685 | if (compare_pt_p || xlfd_idx != XLFD_POINT_SIZE) | |
5686 | { | |
5687 | int delta1 = abs (values[i] - font1->numeric[xlfd_idx]); | |
5688 | int delta2 = abs (values[i] - font2->numeric[xlfd_idx]); | |
178c5d9c | 5689 | |
8e1b21a7 KH |
5690 | if (xlfd_idx == XLFD_POINT_SIZE |
5691 | && abs (delta1 - delta2) < FONT_POINT_SIZE_QUANTUM) | |
5692 | continue; | |
82641697 GM |
5693 | if (delta1 > delta2) |
5694 | return 0; | |
5695 | else if (delta1 < delta2) | |
5696 | return 1; | |
5697 | else | |
5698 | { | |
5699 | /* The difference may be equal because, e.g., the face | |
5700 | specifies `italic' but we have only `regular' and | |
5701 | `oblique'. Prefer `oblique' in this case. */ | |
5702 | if ((xlfd_idx == XLFD_WEIGHT || xlfd_idx == XLFD_SLANT) | |
5703 | && font1->numeric[xlfd_idx] > values[i] | |
5704 | && font2->numeric[xlfd_idx] < values[i]) | |
5705 | return 1; | |
5706 | } | |
5707 | } | |
5708 | } | |
178c5d9c | 5709 | |
a08332c0 GM |
5710 | if (avgwidth) |
5711 | { | |
5712 | int delta1 = abs (avgwidth - font1->numeric[XLFD_AVGWIDTH]); | |
5713 | int delta2 = abs (avgwidth - font2->numeric[XLFD_AVGWIDTH]); | |
5714 | if (delta1 > delta2) | |
5715 | return 0; | |
5716 | else if (delta1 < delta2) | |
5717 | return 1; | |
5718 | } | |
5719 | ||
5720 | return font1->registry_priority < font2->registry_priority; | |
82641697 GM |
5721 | } |
5722 | ||
5723 | ||
82641697 GM |
5724 | /* Value is non-zero if FONT is an exact match for face attributes in |
5725 | SPECIFIED. SPECIFIED is an array of face attribute values in font | |
a08332c0 GM |
5726 | sort order. AVGWIDTH, if non-zero, is an average width to compare |
5727 | with. */ | |
82641697 GM |
5728 | |
5729 | static int | |
a08332c0 | 5730 | exact_face_match_p (specified, font, avgwidth) |
82641697 GM |
5731 | int *specified; |
5732 | struct font_name *font; | |
a08332c0 | 5733 | int avgwidth; |
82641697 GM |
5734 | { |
5735 | int i; | |
178c5d9c | 5736 | |
a08332c0 | 5737 | for (i = 0; i < DIM (font_sort_order); ++i) |
82641697 GM |
5738 | if (specified[i] != font->numeric[font_sort_order[i]]) |
5739 | break; | |
5740 | ||
a08332c0 GM |
5741 | return (i == DIM (font_sort_order) |
5742 | && (avgwidth <= 0 | |
5743 | || avgwidth == font->numeric[XLFD_AVGWIDTH])); | |
82641697 GM |
5744 | } |
5745 | ||
5746 | ||
5747 | /* Value is the name of a scaled font, generated from scalable font | |
5748 | FONT on frame F. SPECIFIED_PT is the point-size to scale FONT to. | |
5749 | Value is allocated from heap. */ | |
5750 | ||
5751 | static char * | |
5752 | build_scalable_font_name (f, font, specified_pt) | |
5753 | struct frame *f; | |
5754 | struct font_name *font; | |
5755 | int specified_pt; | |
5756 | { | |
5757 | char point_size[20], pixel_size[20]; | |
5758 | int pixel_value; | |
5759 | double resy = FRAME_X_DISPLAY_INFO (f)->resy; | |
5760 | double pt; | |
5761 | ||
5762 | /* If scalable font is for a specific resolution, compute | |
5763 | the point size we must specify from the resolution of | |
5764 | the display and the specified resolution of the font. */ | |
5765 | if (font->numeric[XLFD_RESY] != 0) | |
5766 | { | |
5767 | pt = resy / font->numeric[XLFD_RESY] * specified_pt + 0.5; | |
c660ce4e | 5768 | pixel_value = font->numeric[XLFD_RESY] / (PT_PER_INCH * 10.0) * pt; |
82641697 GM |
5769 | } |
5770 | else | |
5771 | { | |
5772 | pt = specified_pt; | |
c660ce4e | 5773 | pixel_value = resy / (PT_PER_INCH * 10.0) * pt; |
82641697 | 5774 | } |
178c5d9c | 5775 | |
82641697 GM |
5776 | /* Set point size of the font. */ |
5777 | sprintf (point_size, "%d", (int) pt); | |
5778 | font->fields[XLFD_POINT_SIZE] = point_size; | |
5779 | font->numeric[XLFD_POINT_SIZE] = pt; | |
178c5d9c | 5780 | |
82641697 GM |
5781 | /* Set pixel size. */ |
5782 | sprintf (pixel_size, "%d", pixel_value); | |
5783 | font->fields[XLFD_PIXEL_SIZE] = pixel_size; | |
5784 | font->numeric[XLFD_PIXEL_SIZE] = pixel_value; | |
178c5d9c | 5785 | |
82641697 GM |
5786 | /* If font doesn't specify its resolution, use the |
5787 | resolution of the display. */ | |
5788 | if (font->numeric[XLFD_RESY] == 0) | |
5789 | { | |
5790 | char buffer[20]; | |
5791 | sprintf (buffer, "%d", (int) resy); | |
5792 | font->fields[XLFD_RESY] = buffer; | |
5793 | font->numeric[XLFD_RESY] = resy; | |
5794 | } | |
178c5d9c | 5795 | |
82641697 GM |
5796 | if (strcmp (font->fields[XLFD_RESX], "0") == 0) |
5797 | { | |
5798 | char buffer[20]; | |
5799 | int resx = FRAME_X_DISPLAY_INFO (f)->resx; | |
5800 | sprintf (buffer, "%d", resx); | |
5801 | font->fields[XLFD_RESX] = buffer; | |
5802 | font->numeric[XLFD_RESX] = resx; | |
5803 | } | |
5804 | ||
5805 | return build_font_name (font); | |
5806 | } | |
5807 | ||
5808 | ||
5809 | /* Value is non-zero if we are allowed to use scalable font FONT. We | |
5810 | can't run a Lisp function here since this function may be called | |
5811 | with input blocked. */ | |
5812 | ||
5813 | static int | |
702a1e8e GM |
5814 | may_use_scalable_font_p (font) |
5815 | char *font; | |
82641697 GM |
5816 | { |
5817 | if (EQ (Vscalable_fonts_allowed, Qt)) | |
5818 | return 1; | |
5819 | else if (CONSP (Vscalable_fonts_allowed)) | |
5820 | { | |
5821 | Lisp_Object tail, regexp; | |
178c5d9c | 5822 | |
82641697 GM |
5823 | for (tail = Vscalable_fonts_allowed; CONSP (tail); tail = XCDR (tail)) |
5824 | { | |
5825 | regexp = XCAR (tail); | |
5826 | if (STRINGP (regexp) | |
702a1e8e | 5827 | && fast_c_string_match_ignore_case (regexp, font) >= 0) |
82641697 GM |
5828 | return 1; |
5829 | } | |
5830 | } | |
178c5d9c | 5831 | |
82641697 GM |
5832 | return 0; |
5833 | } | |
5834 | ||
82641697 GM |
5835 | |
5836 | ||
2e6621ca GM |
5837 | /* Return the name of the best matching font for face attributes ATTRS |
5838 | in the array of font_name structures FONTS which contains NFONTS | |
5839 | elements. WIDTH_RATIO is a factor with which to multiply average | |
5840 | widths if ATTRS specifies such a width. | |
5841 | ||
5842 | Value is a font name which is allocated from the heap. FONTS is | |
5843 | freed by this function. */ | |
82641697 GM |
5844 | |
5845 | static char * | |
2e6621ca | 5846 | best_matching_font (f, attrs, fonts, nfonts, width_ratio) |
82641697 GM |
5847 | struct frame *f; |
5848 | Lisp_Object *attrs; | |
5849 | struct font_name *fonts; | |
5850 | int nfonts; | |
2e6621ca | 5851 | int width_ratio; |
82641697 GM |
5852 | { |
5853 | char *font_name; | |
5854 | struct font_name *best; | |
334a2e2a | 5855 | int i, pt = 0; |
a08332c0 GM |
5856 | int specified[5]; |
5857 | int exact_p, avgwidth; | |
82641697 GM |
5858 | |
5859 | if (nfonts == 0) | |
5860 | return NULL; | |
5861 | ||
5862 | /* Make specified font attributes available in `specified', | |
5863 | indexed by sort order. */ | |
5864 | for (i = 0; i < DIM (font_sort_order); ++i) | |
5865 | { | |
5866 | int xlfd_idx = font_sort_order[i]; | |
178c5d9c | 5867 | |
82641697 GM |
5868 | if (xlfd_idx == XLFD_SWIDTH) |
5869 | specified[i] = face_numeric_swidth (attrs[LFACE_SWIDTH_INDEX]); | |
5870 | else if (xlfd_idx == XLFD_POINT_SIZE) | |
5871 | specified[i] = pt = XFASTINT (attrs[LFACE_HEIGHT_INDEX]); | |
5872 | else if (xlfd_idx == XLFD_WEIGHT) | |
5873 | specified[i] = face_numeric_weight (attrs[LFACE_WEIGHT_INDEX]); | |
5874 | else if (xlfd_idx == XLFD_SLANT) | |
5875 | specified[i] = face_numeric_slant (attrs[LFACE_SLANT_INDEX]); | |
5876 | else | |
5877 | abort (); | |
5878 | } | |
5879 | ||
a08332c0 GM |
5880 | avgwidth = (UNSPECIFIEDP (attrs[LFACE_AVGWIDTH_INDEX]) |
5881 | ? 0 | |
2e6621ca | 5882 | : XFASTINT (attrs[LFACE_AVGWIDTH_INDEX]) * width_ratio); |
a08332c0 | 5883 | |
82641697 | 5884 | exact_p = 0; |
178c5d9c | 5885 | |
82641697 GM |
5886 | /* Start with the first non-scalable font in the list. */ |
5887 | for (i = 0; i < nfonts; ++i) | |
5888 | if (!font_scalable_p (fonts + i)) | |
5889 | break; | |
5890 | ||
5891 | /* Find the best match among the non-scalable fonts. */ | |
5892 | if (i < nfonts) | |
5893 | { | |
5894 | best = fonts + i; | |
178c5d9c | 5895 | |
82641697 GM |
5896 | for (i = 1; i < nfonts; ++i) |
5897 | if (!font_scalable_p (fonts + i) | |
a08332c0 | 5898 | && better_font_p (specified, fonts + i, best, 1, avgwidth)) |
82641697 GM |
5899 | { |
5900 | best = fonts + i; | |
5901 | ||
a08332c0 | 5902 | exact_p = exact_face_match_p (specified, best, avgwidth); |
82641697 GM |
5903 | if (exact_p) |
5904 | break; | |
5905 | } | |
178c5d9c | 5906 | |
82641697 GM |
5907 | } |
5908 | else | |
5909 | best = NULL; | |
5910 | ||
5911 | /* Unless we found an exact match among non-scalable fonts, see if | |
5912 | we can find a better match among scalable fonts. */ | |
5913 | if (!exact_p) | |
5914 | { | |
5915 | /* A scalable font is better if | |
5916 | ||
5917 | 1. its weight, slant, swidth attributes are better, or. | |
178c5d9c | 5918 | |
82641697 GM |
5919 | 2. the best non-scalable font doesn't have the required |
5920 | point size, and the scalable fonts weight, slant, swidth | |
5921 | isn't worse. */ | |
5922 | ||
5923 | int non_scalable_has_exact_height_p; | |
5924 | ||
5925 | if (best && best->numeric[XLFD_POINT_SIZE] == pt) | |
5926 | non_scalable_has_exact_height_p = 1; | |
5927 | else | |
5928 | non_scalable_has_exact_height_p = 0; | |
178c5d9c | 5929 | |
82641697 GM |
5930 | for (i = 0; i < nfonts; ++i) |
5931 | if (font_scalable_p (fonts + i)) | |
5932 | { | |
5933 | if (best == NULL | |
a08332c0 | 5934 | || better_font_p (specified, fonts + i, best, 0, 0) |
82641697 | 5935 | || (!non_scalable_has_exact_height_p |
a08332c0 | 5936 | && !better_font_p (specified, best, fonts + i, 0, 0))) |
82641697 GM |
5937 | best = fonts + i; |
5938 | } | |
5939 | } | |
5940 | ||
5941 | if (font_scalable_p (best)) | |
5942 | font_name = build_scalable_font_name (f, best, pt); | |
5943 | else | |
5944 | font_name = build_font_name (best); | |
178c5d9c | 5945 | |
82641697 GM |
5946 | /* Free font_name structures. */ |
5947 | free_font_names (fonts, nfonts); | |
178c5d9c | 5948 | |
82641697 GM |
5949 | return font_name; |
5950 | } | |
5951 | ||
5952 | ||
3cf80731 SM |
5953 | /* Get a list of matching fonts on frame F, considering FAMILY |
5954 | and alternative font families from Vface_alternative_font_registry_alist. | |
4a529c42 GM |
5955 | |
5956 | FAMILY is the font family whose alternatives are considered. | |
5957 | ||
5958 | REGISTRY, if a string, specifies a font registry and encoding to | |
5959 | match. A value of nil means include fonts of any registry and | |
5960 | encoding. | |
5961 | ||
5962 | Return in *FONTS a pointer to a vector of font_name structures for | |
5963 | the fonts matched. Value is the number of fonts found. */ | |
5964 | ||
5965 | static int | |
5966 | try_alternative_families (f, family, registry, fonts) | |
5967 | struct frame *f; | |
5968 | Lisp_Object family, registry; | |
5969 | struct font_name **fonts; | |
5970 | { | |
5971 | Lisp_Object alter; | |
5972 | int nfonts = 0; | |
5973 | ||
3cf80731 SM |
5974 | nfonts = font_list (f, Qnil, family, registry, fonts); |
5975 | if (nfonts == 0) | |
4a529c42 | 5976 | { |
3cf80731 SM |
5977 | /* Try alternative font families. */ |
5978 | alter = Fassoc (family, Vface_alternative_font_family_alist); | |
5979 | if (CONSP (alter)) | |
5980 | { | |
5981 | for (alter = XCDR (alter); | |
5982 | CONSP (alter) && nfonts == 0; | |
5983 | alter = XCDR (alter)) | |
5984 | { | |
5985 | if (STRINGP (XCAR (alter))) | |
5986 | nfonts = font_list (f, Qnil, XCAR (alter), registry, fonts); | |
5987 | } | |
5988 | } | |
5989 | ||
5990 | /* Try scalable fonts before giving up. */ | |
5991 | if (nfonts == 0 && NILP (Vscalable_fonts_allowed)) | |
4a529c42 | 5992 | { |
3cf80731 SM |
5993 | int count = BINDING_STACK_SIZE (); |
5994 | specbind (Qscalable_fonts_allowed, Qt); | |
5995 | nfonts = try_alternative_families (f, family, registry, fonts); | |
5996 | unbind_to (count, Qnil); | |
4a529c42 GM |
5997 | } |
5998 | } | |
4a529c42 GM |
5999 | return nfonts; |
6000 | } | |
6001 | ||
6002 | ||
702a1e8e GM |
6003 | /* Get a list of matching fonts on frame F. |
6004 | ||
3cf80731 SM |
6005 | FAMILY, if a string, specifies a font family derived from the fontset. |
6006 | It is only used if the face does not specify any family in ATTRS or | |
6007 | if we cannot find any font of the face's family. | |
702a1e8e GM |
6008 | |
6009 | REGISTRY, if a string, specifies a font registry and encoding to | |
6010 | match. A value of nil means include fonts of any registry and | |
6011 | encoding. | |
6012 | ||
6013 | Return in *FONTS a pointer to a vector of font_name structures for | |
6014 | the fonts matched. Value is the number of fonts found. */ | |
82641697 GM |
6015 | |
6016 | static int | |
702a1e8e | 6017 | try_font_list (f, attrs, family, registry, fonts) |
82641697 GM |
6018 | struct frame *f; |
6019 | Lisp_Object *attrs; | |
702a1e8e | 6020 | Lisp_Object family, registry; |
82641697 GM |
6021 | struct font_name **fonts; |
6022 | { | |
4a529c42 | 6023 | int nfonts = 0; |
3cf80731 | 6024 | Lisp_Object face_family = attrs[LFACE_FAMILY_INDEX]; |
82641697 | 6025 | |
3cf80731 SM |
6026 | if (STRINGP (face_family)) |
6027 | nfonts = try_alternative_families (f, face_family, registry, fonts); | |
6028 | ||
6029 | if (nfonts == 0 && !NILP (family)) | |
6030 | nfonts = try_alternative_families (f, family, registry, fonts); | |
178c5d9c | 6031 | |
3cf80731 | 6032 | /* Try font family of the default face or "fixed". */ |
4a529c42 | 6033 | if (nfonts == 0) |
82641697 | 6034 | { |
3cf80731 SM |
6035 | struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); |
6036 | if (default_face) | |
6037 | family = default_face->lface[LFACE_FAMILY_INDEX]; | |
6038 | else | |
6039 | family = build_string ("fixed"); | |
4a529c42 | 6040 | nfonts = font_list (f, Qnil, family, registry, fonts); |
82641697 | 6041 | } |
3cf80731 SM |
6042 | |
6043 | /* Try any family with the given registry. */ | |
6044 | if (nfonts == 0) | |
6045 | nfonts = font_list (f, Qnil, Qnil, registry, fonts); | |
82641697 GM |
6046 | |
6047 | return nfonts; | |
6048 | } | |
6049 | ||
82641697 | 6050 | |
39506348 KH |
6051 | /* Return the fontset id of the base fontset name or alias name given |
6052 | by the fontset attribute of ATTRS. Value is -1 if the fontset | |
6053 | attribute of ATTRS doesn't name a fontset. */ | |
82641697 GM |
6054 | |
6055 | static int | |
39506348 | 6056 | face_fontset (attrs) |
82641697 GM |
6057 | Lisp_Object *attrs; |
6058 | { | |
39506348 | 6059 | Lisp_Object name; |
178c5d9c | 6060 | |
39506348 KH |
6061 | name = attrs[LFACE_FONT_INDEX]; |
6062 | if (!STRINGP (name)) | |
6063 | return -1; | |
6064 | return fs_query_fontset (name, 0); | |
82641697 GM |
6065 | } |
6066 | ||
6067 | ||
39506348 KH |
6068 | /* Choose a name of font to use on frame F to display character C with |
6069 | Lisp face attributes specified by ATTRS. The font name is | |
6070 | determined by the font-related attributes in ATTRS and the name | |
6071 | pattern for C in FONTSET. Value is the font name which is | |
6072 | allocated from the heap and must be freed by the caller, or NULL if | |
6073 | we can get no information about the font name of C. It is assured | |
6074 | that we always get some information for a single byte | |
6075 | character. */ | |
82641697 GM |
6076 | |
6077 | static char * | |
39506348 | 6078 | choose_face_font (f, attrs, fontset, c) |
82641697 GM |
6079 | struct frame *f; |
6080 | Lisp_Object *attrs; | |
39506348 | 6081 | int fontset, c; |
82641697 | 6082 | { |
39506348 | 6083 | Lisp_Object pattern; |
82641697 | 6084 | char *font_name = NULL; |
82641697 | 6085 | struct font_name *fonts; |
2e6621ca | 6086 | int nfonts, width_ratio; |
178c5d9c | 6087 | |
39506348 KH |
6088 | /* Get (foundry and) family name and registry (and encoding) name of |
6089 | a font for C. */ | |
6090 | pattern = fontset_font_pattern (f, fontset, c); | |
6091 | if (NILP (pattern)) | |
6092 | { | |
6093 | xassert (!SINGLE_BYTE_CHAR_P (c)); | |
6094 | return NULL; | |
6095 | } | |
4a529c42 | 6096 | |
39506348 KH |
6097 | /* If what we got is a name pattern, return it. */ |
6098 | if (STRINGP (pattern)) | |
6099 | return xstrdup (XSTRING (pattern)->data); | |
82641697 | 6100 | |
178c5d9c | 6101 | /* Get a list of fonts matching that pattern and choose the |
82641697 | 6102 | best match for the specified face attributes from it. */ |
702a1e8e | 6103 | nfonts = try_font_list (f, attrs, XCAR (pattern), XCDR (pattern), &fonts); |
2e6621ca GM |
6104 | width_ratio = (SINGLE_BYTE_CHAR_P (c) |
6105 | ? 1 | |
6106 | : CHARSET_WIDTH (CHAR_CHARSET (c))); | |
6107 | font_name = best_matching_font (f, attrs, fonts, nfonts, width_ratio); | |
82641697 GM |
6108 | return font_name; |
6109 | } | |
6110 | ||
c3cee013 | 6111 | #endif /* HAVE_WINDOW_SYSTEM */ |
82641697 GM |
6112 | |
6113 | ||
6114 | \f | |
6115 | /*********************************************************************** | |
6116 | Face Realization | |
6117 | ***********************************************************************/ | |
6118 | ||
6119 | /* Realize basic faces on frame F. Value is zero if frame parameters | |
6120 | of F don't contain enough information needed to realize the default | |
6121 | face. */ | |
6122 | ||
6123 | static int | |
6124 | realize_basic_faces (f) | |
6125 | struct frame *f; | |
6126 | { | |
6127 | int success_p = 0; | |
eeffb293 | 6128 | int count = BINDING_STACK_SIZE (); |
17e8204b | 6129 | |
04386463 GM |
6130 | /* Block input here so that we won't be surprised by an X expose |
6131 | event, for instance, without having the faces set up. */ | |
17e8204b | 6132 | BLOCK_INPUT; |
eeffb293 | 6133 | specbind (Qscalable_fonts_allowed, Qt); |
178c5d9c | 6134 | |
82641697 GM |
6135 | if (realize_default_face (f)) |
6136 | { | |
92610620 | 6137 | realize_named_face (f, Qmode_line, MODE_LINE_FACE_ID); |
039b6394 | 6138 | realize_named_face (f, Qmode_line_inactive, MODE_LINE_INACTIVE_FACE_ID); |
9ea173e8 | 6139 | realize_named_face (f, Qtool_bar, TOOL_BAR_FACE_ID); |
4e50fa8b | 6140 | realize_named_face (f, Qfringe, FRINGE_FACE_ID); |
045dee35 | 6141 | realize_named_face (f, Qheader_line, HEADER_LINE_FACE_ID); |
8bd201d6 GM |
6142 | realize_named_face (f, Qscroll_bar, SCROLL_BAR_FACE_ID); |
6143 | realize_named_face (f, Qborder, BORDER_FACE_ID); | |
6144 | realize_named_face (f, Qcursor, CURSOR_FACE_ID); | |
6145 | realize_named_face (f, Qmouse, MOUSE_FACE_ID); | |
c7ae3284 | 6146 | realize_named_face (f, Qmenu, MENU_FACE_ID); |
563f68f1 | 6147 | |
b5de343d | 6148 | /* Reflect changes in the `menu' face in menu bars. */ |
ceeda019 | 6149 | if (FRAME_FACE_CACHE (f)->menu_face_changed_p) |
563f68f1 | 6150 | { |
ceeda019 | 6151 | FRAME_FACE_CACHE (f)->menu_face_changed_p = 0; |
563f68f1 | 6152 | #ifdef USE_X_TOOLKIT |
bce72079 | 6153 | x_update_menu_appearance (f); |
a03ad468 | 6154 | #endif |
563f68f1 GM |
6155 | } |
6156 | ||
82641697 GM |
6157 | success_p = 1; |
6158 | } | |
6159 | ||
eeffb293 | 6160 | unbind_to (count, Qnil); |
17e8204b | 6161 | UNBLOCK_INPUT; |
82641697 GM |
6162 | return success_p; |
6163 | } | |
6164 | ||
6165 | ||
6166 | /* Realize the default face on frame F. If the face is not fully | |
6167 | specified, make it fully-specified. Attributes of the default face | |
6168 | that are not explicitly specified are taken from frame parameters. */ | |
6169 | ||
6170 | static int | |
6171 | realize_default_face (f) | |
6172 | struct frame *f; | |
6173 | { | |
6174 | struct face_cache *c = FRAME_FACE_CACHE (f); | |
6175 | Lisp_Object lface; | |
6176 | Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
82641697 GM |
6177 | Lisp_Object frame_font; |
6178 | struct face *face; | |
82641697 GM |
6179 | |
6180 | /* If the `default' face is not yet known, create it. */ | |
6181 | lface = lface_from_face_name (f, Qdefault, 0); | |
6182 | if (NILP (lface)) | |
6183 | { | |
6184 | Lisp_Object frame; | |
6185 | XSETFRAME (frame, f); | |
6186 | lface = Finternal_make_lisp_face (Qdefault, frame); | |
6187 | } | |
6188 | ||
c3cee013 JR |
6189 | #ifdef HAVE_WINDOW_SYSTEM |
6190 | if (FRAME_WINDOW_P (f)) | |
82641697 GM |
6191 | { |
6192 | /* Set frame_font to the value of the `font' frame parameter. */ | |
6193 | frame_font = Fassq (Qfont, f->param_alist); | |
6194 | xassert (CONSP (frame_font) && STRINGP (XCDR (frame_font))); | |
6195 | frame_font = XCDR (frame_font); | |
8cdeb3f2 | 6196 | set_lface_from_font_name (f, lface, frame_font, 1, 1); |
82641697 | 6197 | } |
c3cee013 | 6198 | #endif /* HAVE_WINDOW_SYSTEM */ |
82641697 | 6199 | |
44747bd0 | 6200 | if (!FRAME_WINDOW_P (f)) |
82641697 GM |
6201 | { |
6202 | LFACE_FAMILY (lface) = build_string ("default"); | |
6203 | LFACE_SWIDTH (lface) = Qnormal; | |
6204 | LFACE_HEIGHT (lface) = make_number (1); | |
c1e7532d EZ |
6205 | if (UNSPECIFIEDP (LFACE_WEIGHT (lface))) |
6206 | LFACE_WEIGHT (lface) = Qnormal; | |
6207 | if (UNSPECIFIEDP (LFACE_SLANT (lface))) | |
6208 | LFACE_SLANT (lface) = Qnormal; | |
a08332c0 | 6209 | LFACE_AVGWIDTH (lface) = Qunspecified; |
82641697 | 6210 | } |
178c5d9c | 6211 | |
82641697 GM |
6212 | if (UNSPECIFIEDP (LFACE_UNDERLINE (lface))) |
6213 | LFACE_UNDERLINE (lface) = Qnil; | |
178c5d9c | 6214 | |
82641697 GM |
6215 | if (UNSPECIFIEDP (LFACE_OVERLINE (lface))) |
6216 | LFACE_OVERLINE (lface) = Qnil; | |
178c5d9c | 6217 | |
82641697 GM |
6218 | if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface))) |
6219 | LFACE_STRIKE_THROUGH (lface) = Qnil; | |
178c5d9c | 6220 | |
82641697 GM |
6221 | if (UNSPECIFIEDP (LFACE_BOX (lface))) |
6222 | LFACE_BOX (lface) = Qnil; | |
178c5d9c | 6223 | |
82641697 GM |
6224 | if (UNSPECIFIEDP (LFACE_INVERSE (lface))) |
6225 | LFACE_INVERSE (lface) = Qnil; | |
178c5d9c | 6226 | |
82641697 GM |
6227 | if (UNSPECIFIEDP (LFACE_FOREGROUND (lface))) |
6228 | { | |
6229 | /* This function is called so early that colors are not yet | |
6230 | set in the frame parameter list. */ | |
6231 | Lisp_Object color = Fassq (Qforeground_color, f->param_alist); | |
178c5d9c | 6232 | |
82641697 GM |
6233 | if (CONSP (color) && STRINGP (XCDR (color))) |
6234 | LFACE_FOREGROUND (lface) = XCDR (color); | |
c3cee013 | 6235 | else if (FRAME_WINDOW_P (f)) |
82641697 | 6236 | return 0; |
e689ec06 | 6237 | else if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) |
ef917393 | 6238 | LFACE_FOREGROUND (lface) = build_string (unspecified_fg); |
f9d2fdc4 | 6239 | else |
82641697 GM |
6240 | abort (); |
6241 | } | |
178c5d9c | 6242 | |
82641697 GM |
6243 | if (UNSPECIFIEDP (LFACE_BACKGROUND (lface))) |
6244 | { | |
6245 | /* This function is called so early that colors are not yet | |
6246 | set in the frame parameter list. */ | |
6247 | Lisp_Object color = Fassq (Qbackground_color, f->param_alist); | |
6248 | if (CONSP (color) && STRINGP (XCDR (color))) | |
6249 | LFACE_BACKGROUND (lface) = XCDR (color); | |
c3cee013 | 6250 | else if (FRAME_WINDOW_P (f)) |
82641697 | 6251 | return 0; |
e689ec06 | 6252 | else if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) |
ef917393 | 6253 | LFACE_BACKGROUND (lface) = build_string (unspecified_bg); |
f9d2fdc4 | 6254 | else |
82641697 GM |
6255 | abort (); |
6256 | } | |
178c5d9c | 6257 | |
82641697 GM |
6258 | if (UNSPECIFIEDP (LFACE_STIPPLE (lface))) |
6259 | LFACE_STIPPLE (lface) = Qnil; | |
6260 | ||
6261 | /* Realize the face; it must be fully-specified now. */ | |
6262 | xassert (lface_fully_specified_p (XVECTOR (lface)->contents)); | |
6263 | check_lface (lface); | |
6264 | bcopy (XVECTOR (lface)->contents, attrs, sizeof attrs); | |
39506348 | 6265 | face = realize_face (c, attrs, 0, NULL, DEFAULT_FACE_ID); |
82641697 GM |
6266 | return 1; |
6267 | } | |
6268 | ||
6269 | ||
6270 | /* Realize basic faces other than the default face in face cache C. | |
6271 | SYMBOL is the face name, ID is the face id the realized face must | |
6272 | have. The default face must have been realized already. */ | |
6273 | ||
6274 | static void | |
6275 | realize_named_face (f, symbol, id) | |
6276 | struct frame *f; | |
6277 | Lisp_Object symbol; | |
6278 | int id; | |
6279 | { | |
6280 | struct face_cache *c = FRAME_FACE_CACHE (f); | |
6281 | Lisp_Object lface = lface_from_face_name (f, symbol, 0); | |
6282 | Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
6283 | Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE]; | |
6284 | struct face *new_face; | |
6285 | ||
6286 | /* The default face must exist and be fully specified. */ | |
6287 | get_lface_attributes (f, Qdefault, attrs, 1); | |
6288 | check_lface_attrs (attrs); | |
6289 | xassert (lface_fully_specified_p (attrs)); | |
6290 | ||
6291 | /* If SYMBOL isn't know as a face, create it. */ | |
6292 | if (NILP (lface)) | |
6293 | { | |
6294 | Lisp_Object frame; | |
6295 | XSETFRAME (frame, f); | |
6296 | lface = Finternal_make_lisp_face (symbol, frame); | |
6297 | } | |
6298 | ||
6299 | /* Merge SYMBOL's face with the default face. */ | |
6300 | get_lface_attributes (f, symbol, symbol_attrs, 1); | |
2c20458f | 6301 | merge_face_vectors (f, symbol_attrs, attrs, Qnil); |
82641697 GM |
6302 | |
6303 | /* Realize the face. */ | |
39506348 | 6304 | new_face = realize_face (c, attrs, 0, NULL, id); |
82641697 GM |
6305 | } |
6306 | ||
6307 | ||
6308 | /* Realize the fully-specified face with attributes ATTRS in face | |
39506348 | 6309 | cache CACHE for character C. If C is a multibyte character, |
0badc114 KH |
6310 | BASE_FACE is a face that has the same attributes. Otherwise, |
6311 | BASE_FACE is ignored. If FORMER_FACE_ID is non-negative, it is an | |
6312 | ID of face to remove before caching the new face. Value is a | |
6313 | pointer to the newly created realized face. */ | |
82641697 GM |
6314 | |
6315 | static struct face * | |
39506348 KH |
6316 | realize_face (cache, attrs, c, base_face, former_face_id) |
6317 | struct face_cache *cache; | |
82641697 | 6318 | Lisp_Object *attrs; |
39506348 KH |
6319 | int c; |
6320 | struct face *base_face; | |
6321 | int former_face_id; | |
82641697 GM |
6322 | { |
6323 | struct face *face; | |
178c5d9c | 6324 | |
82641697 | 6325 | /* LFACE must be fully specified. */ |
39506348 | 6326 | xassert (cache != NULL); |
82641697 GM |
6327 | check_lface_attrs (attrs); |
6328 | ||
39506348 KH |
6329 | if (former_face_id >= 0 && cache->used > former_face_id) |
6330 | { | |
6331 | /* Remove the former face. */ | |
6332 | struct face *former_face = cache->faces_by_id[former_face_id]; | |
6333 | uncache_face (cache, former_face); | |
6334 | free_realized_face (cache->f, former_face); | |
6335 | } | |
6336 | ||
6337 | if (FRAME_WINDOW_P (cache->f)) | |
6338 | face = realize_x_face (cache, attrs, c, base_face); | |
e689ec06 | 6339 | else if (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f)) |
39506348 | 6340 | face = realize_tty_face (cache, attrs, c); |
82641697 GM |
6341 | else |
6342 | abort (); | |
6343 | ||
39506348 KH |
6344 | /* Insert the new face. */ |
6345 | cache_face (cache, face, lface_hash (attrs)); | |
6346 | #ifdef HAVE_WINDOW_SYSTEM | |
192cb6cf | 6347 | if (FRAME_WINDOW_P (cache->f) && face->font == NULL) |
39506348 KH |
6348 | load_face_font (cache->f, face, c); |
6349 | #endif /* HAVE_WINDOW_SYSTEM */ | |
82641697 GM |
6350 | return face; |
6351 | } | |
6352 | ||
6353 | ||
6354 | /* Realize the fully-specified face with attributes ATTRS in face | |
39506348 | 6355 | cache CACHE for character C. Do it for X frame CACHE->f. If C is |
0badc114 KH |
6356 | a multibyte character, BASE_FACE is a face that has the same |
6357 | attributes. Otherwise, BASE_FACE is ignored. If the new face | |
6358 | doesn't share font with the default face, a fontname is allocated | |
6359 | from the heap and set in `font_name' of the new face, but it is not | |
6360 | yet loaded here. Value is a pointer to the newly created realized | |
6361 | face. */ | |
82641697 GM |
6362 | |
6363 | static struct face * | |
39506348 KH |
6364 | realize_x_face (cache, attrs, c, base_face) |
6365 | struct face_cache *cache; | |
82641697 | 6366 | Lisp_Object *attrs; |
39506348 KH |
6367 | int c; |
6368 | struct face *base_face; | |
82641697 | 6369 | { |
c3cee013 | 6370 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 | 6371 | struct face *face, *default_face; |
78d2079c | 6372 | struct frame *f; |
82641697 | 6373 | Lisp_Object stipple, overline, strike_through, box; |
82641697 | 6374 | |
39506348 KH |
6375 | xassert (FRAME_WINDOW_P (cache->f)); |
6376 | xassert (SINGLE_BYTE_CHAR_P (c) | |
0badc114 | 6377 | || base_face); |
82641697 GM |
6378 | |
6379 | /* Allocate a new realized face. */ | |
39506348 KH |
6380 | face = make_realized_face (attrs); |
6381 | ||
6382 | f = cache->f; | |
6383 | ||
6384 | /* If C is a multibyte character, we share all face attirbutes with | |
6385 | BASE_FACE including the realized fontset. But, we must load a | |
6386 | different font. */ | |
6387 | if (!SINGLE_BYTE_CHAR_P (c)) | |
6388 | { | |
6389 | bcopy (base_face, face, sizeof *face); | |
6390 | face->gc = 0; | |
e911049b GM |
6391 | |
6392 | /* Don't try to free the colors copied bitwise from BASE_FACE. */ | |
28a072fe | 6393 | face->colors_copied_bitwise_p = 1; |
178c5d9c | 6394 | |
e911049b GM |
6395 | /* to force realize_face to load font */ |
6396 | face->font = NULL; | |
39506348 KH |
6397 | return face; |
6398 | } | |
6399 | ||
6400 | /* Now we are realizing a face for ASCII (and unibyte) characters. */ | |
82641697 GM |
6401 | |
6402 | /* Determine the font to use. Most of the time, the font will be | |
6403 | the same as the font of the default face, so try that first. */ | |
6404 | default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); | |
6405 | if (default_face | |
39506348 | 6406 | && FACE_SUITABLE_FOR_CHAR_P (default_face, c) |
82641697 GM |
6407 | && lface_same_font_attributes_p (default_face->lface, attrs)) |
6408 | { | |
6409 | face->font = default_face->font; | |
6410 | face->fontset = default_face->fontset; | |
6411 | face->font_info_id = default_face->font_info_id; | |
6412 | face->font_name = default_face->font_name; | |
39506348 | 6413 | face->ascii_face = face; |
82641697 | 6414 | |
39506348 KH |
6415 | /* But, as we can't share the fontset, make a new realized |
6416 | fontset that has the same base fontset as of the default | |
6417 | face. */ | |
6418 | face->fontset | |
6419 | = make_fontset_for_ascii_face (f, default_face->fontset); | |
82641697 GM |
6420 | } |
6421 | else | |
6422 | { | |
39506348 | 6423 | /* If the face attribute ATTRS specifies a fontset, use it as |
fc8c4797 KH |
6424 | the base of a new realized fontset. Otherwise, use the same |
6425 | base fontset as of the default face. The base determines | |
6426 | registry and encoding of a font. It may also determine | |
6427 | foundry and family. The other fields of font name pattern | |
6428 | are constructed from ATTRS. */ | |
6429 | int fontset = face_fontset (attrs); | |
6430 | ||
178c5d9c | 6431 | if ((fontset == -1) && default_face) |
fc8c4797 KH |
6432 | fontset = default_face->fontset; |
6433 | face->fontset = make_fontset_for_ascii_face (f, fontset); | |
39506348 | 6434 | face->font = NULL; /* to force realize_face to load font */ |
1a578e9b | 6435 | |
e0f712ba | 6436 | #ifdef MAC_OS |
1a578e9b AC |
6437 | /* Load the font if it is specified in ATTRS. This fixes |
6438 | changing frame font on the Mac. */ | |
6439 | if (STRINGP (attrs[LFACE_FONT_INDEX])) | |
6440 | { | |
6441 | struct font_info *font_info = | |
6442 | FS_LOAD_FONT (f, 0, XSTRING (attrs[LFACE_FONT_INDEX])->data, -1); | |
6443 | if (font_info) | |
6444 | face->font = font_info->font; | |
6445 | } | |
6446 | #endif | |
82641697 GM |
6447 | } |
6448 | ||
6449 | /* Load colors, and set remaining attributes. */ | |
178c5d9c | 6450 | |
82641697 | 6451 | load_face_colors (f, face, attrs); |
660ed669 | 6452 | |
82641697 GM |
6453 | /* Set up box. */ |
6454 | box = attrs[LFACE_BOX_INDEX]; | |
6455 | if (STRINGP (box)) | |
cb637678 | 6456 | { |
82641697 GM |
6457 | /* A simple box of line width 1 drawn in color given by |
6458 | the string. */ | |
6459 | face->box_color = load_color (f, face, attrs[LFACE_BOX_INDEX], | |
6460 | LFACE_BOX_INDEX); | |
6461 | face->box = FACE_SIMPLE_BOX; | |
6462 | face->box_line_width = 1; | |
cb637678 | 6463 | } |
82641697 | 6464 | else if (INTEGERP (box)) |
42120bc7 | 6465 | { |
82641697 GM |
6466 | /* Simple box of specified line width in foreground color of the |
6467 | face. */ | |
89624b8b | 6468 | xassert (XINT (box) != 0); |
82641697 | 6469 | face->box = FACE_SIMPLE_BOX; |
89624b8b | 6470 | face->box_line_width = XINT (box); |
82641697 GM |
6471 | face->box_color = face->foreground; |
6472 | face->box_color_defaulted_p = 1; | |
6473 | } | |
6474 | else if (CONSP (box)) | |
6475 | { | |
6476 | /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW | |
6477 | being one of `raised' or `sunken'. */ | |
6478 | face->box = FACE_SIMPLE_BOX; | |
6479 | face->box_color = face->foreground; | |
6480 | face->box_color_defaulted_p = 1; | |
6481 | face->box_line_width = 1; | |
6482 | ||
6483 | while (CONSP (box)) | |
42120bc7 | 6484 | { |
82641697 GM |
6485 | Lisp_Object keyword, value; |
6486 | ||
6487 | keyword = XCAR (box); | |
6488 | box = XCDR (box); | |
6489 | ||
6490 | if (!CONSP (box)) | |
6491 | break; | |
6492 | value = XCAR (box); | |
6493 | box = XCDR (box); | |
6494 | ||
6495 | if (EQ (keyword, QCline_width)) | |
6496 | { | |
89624b8b KH |
6497 | if (INTEGERP (value) && XINT (value) != 0) |
6498 | face->box_line_width = XINT (value); | |
82641697 GM |
6499 | } |
6500 | else if (EQ (keyword, QCcolor)) | |
6501 | { | |
6502 | if (STRINGP (value)) | |
6503 | { | |
6504 | face->box_color = load_color (f, face, value, | |
6505 | LFACE_BOX_INDEX); | |
6506 | face->use_box_color_for_shadows_p = 1; | |
6507 | } | |
6508 | } | |
6509 | else if (EQ (keyword, QCstyle)) | |
a8517066 | 6510 | { |
82641697 GM |
6511 | if (EQ (value, Qreleased_button)) |
6512 | face->box = FACE_RAISED_BOX; | |
6513 | else if (EQ (value, Qpressed_button)) | |
6514 | face->box = FACE_SUNKEN_BOX; | |
a8517066 | 6515 | } |
42120bc7 RS |
6516 | } |
6517 | } | |
195f798e | 6518 | |
82641697 | 6519 | /* Text underline, overline, strike-through. */ |
178c5d9c | 6520 | |
82641697 | 6521 | if (EQ (attrs[LFACE_UNDERLINE_INDEX], Qt)) |
178c5d9c | 6522 | { |
82641697 GM |
6523 | /* Use default color (same as foreground color). */ |
6524 | face->underline_p = 1; | |
6525 | face->underline_defaulted_p = 1; | |
6526 | face->underline_color = 0; | |
6527 | } | |
6528 | else if (STRINGP (attrs[LFACE_UNDERLINE_INDEX])) | |
195f798e | 6529 | { |
82641697 GM |
6530 | /* Use specified color. */ |
6531 | face->underline_p = 1; | |
6532 | face->underline_defaulted_p = 0; | |
6533 | face->underline_color | |
6534 | = load_color (f, face, attrs[LFACE_UNDERLINE_INDEX], | |
6535 | LFACE_UNDERLINE_INDEX); | |
195f798e | 6536 | } |
82641697 | 6537 | else if (NILP (attrs[LFACE_UNDERLINE_INDEX])) |
7b00de84 | 6538 | { |
82641697 GM |
6539 | face->underline_p = 0; |
6540 | face->underline_defaulted_p = 0; | |
6541 | face->underline_color = 0; | |
7b00de84 JB |
6542 | } |
6543 | ||
82641697 GM |
6544 | overline = attrs[LFACE_OVERLINE_INDEX]; |
6545 | if (STRINGP (overline)) | |
cb637678 | 6546 | { |
82641697 GM |
6547 | face->overline_color |
6548 | = load_color (f, face, attrs[LFACE_OVERLINE_INDEX], | |
6549 | LFACE_OVERLINE_INDEX); | |
6550 | face->overline_p = 1; | |
cb637678 | 6551 | } |
82641697 | 6552 | else if (EQ (overline, Qt)) |
cb637678 | 6553 | { |
82641697 GM |
6554 | face->overline_color = face->foreground; |
6555 | face->overline_color_defaulted_p = 1; | |
6556 | face->overline_p = 1; | |
cb637678 JB |
6557 | } |
6558 | ||
82641697 GM |
6559 | strike_through = attrs[LFACE_STRIKE_THROUGH_INDEX]; |
6560 | if (STRINGP (strike_through)) | |
6561 | { | |
6562 | face->strike_through_color | |
6563 | = load_color (f, face, attrs[LFACE_STRIKE_THROUGH_INDEX], | |
6564 | LFACE_STRIKE_THROUGH_INDEX); | |
6565 | face->strike_through_p = 1; | |
6566 | } | |
6567 | else if (EQ (strike_through, Qt)) | |
6568 | { | |
6569 | face->strike_through_color = face->foreground; | |
6570 | face->strike_through_color_defaulted_p = 1; | |
6571 | face->strike_through_p = 1; | |
6572 | } | |
867dd159 | 6573 | |
82641697 GM |
6574 | stipple = attrs[LFACE_STIPPLE_INDEX]; |
6575 | if (!NILP (stipple)) | |
6576 | face->stipple = load_pixmap (f, stipple, &face->pixmap_w, &face->pixmap_h); | |
660ed669 | 6577 | |
39506348 | 6578 | xassert (FACE_SUITABLE_FOR_CHAR_P (face, c)); |
82641697 | 6579 | return face; |
c3cee013 | 6580 | #endif /* HAVE_WINDOW_SYSTEM */ |
660ed669 JB |
6581 | } |
6582 | ||
729425b1 | 6583 | |
ae4b4ba5 GM |
6584 | /* Map a specified color of face FACE on frame F to a tty color index. |
6585 | IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and | |
6586 | specifies which color to map. Set *DEFAULTED to 1 if mapping to the | |
6587 | default foreground/background colors. */ | |
6588 | ||
6589 | static void | |
6590 | map_tty_color (f, face, idx, defaulted) | |
6591 | struct frame *f; | |
6592 | struct face *face; | |
6593 | enum lface_attribute_index idx; | |
6594 | int *defaulted; | |
6595 | { | |
6596 | Lisp_Object frame, color, def; | |
6597 | int foreground_p = idx == LFACE_FOREGROUND_INDEX; | |
6598 | unsigned long default_pixel, default_other_pixel, pixel; | |
6599 | ||
6600 | xassert (idx == LFACE_FOREGROUND_INDEX || idx == LFACE_BACKGROUND_INDEX); | |
6601 | ||
6602 | if (foreground_p) | |
6603 | { | |
6604 | pixel = default_pixel = FACE_TTY_DEFAULT_FG_COLOR; | |
6605 | default_other_pixel = FACE_TTY_DEFAULT_BG_COLOR; | |
6606 | } | |
6607 | else | |
6608 | { | |
6609 | pixel = default_pixel = FACE_TTY_DEFAULT_BG_COLOR; | |
6610 | default_other_pixel = FACE_TTY_DEFAULT_FG_COLOR; | |
6611 | } | |
6612 | ||
6613 | XSETFRAME (frame, f); | |
6614 | color = face->lface[idx]; | |
6615 | ||
6616 | if (STRINGP (color) | |
6617 | && XSTRING (color)->size | |
6618 | && CONSP (Vtty_defined_color_alist) | |
6619 | && (def = assq_no_quit (color, call1 (Qtty_color_alist, frame)), | |
6620 | CONSP (def))) | |
6621 | { | |
6622 | /* Associations in tty-defined-color-alist are of the form | |
6623 | (NAME INDEX R G B). We need the INDEX part. */ | |
6624 | pixel = XINT (XCAR (XCDR (def))); | |
6625 | } | |
6626 | ||
6627 | if (pixel == default_pixel && STRINGP (color)) | |
6628 | { | |
6629 | pixel = load_color (f, face, color, idx); | |
6630 | ||
6631 | #if defined (MSDOS) || defined (WINDOWSNT) | |
6632 | /* If the foreground of the default face is the default color, | |
6633 | use the foreground color defined by the frame. */ | |
6634 | #ifdef MSDOS | |
6635 | if (FRAME_MSDOS_P (f)) | |
6636 | { | |
6637 | #endif /* MSDOS */ | |
6638 | if (pixel == default_pixel | |
6639 | || pixel == FACE_TTY_DEFAULT_COLOR) | |
6640 | { | |
6641 | if (foreground_p) | |
6642 | pixel = FRAME_FOREGROUND_PIXEL (f); | |
6643 | else | |
6644 | pixel = FRAME_BACKGROUND_PIXEL (f); | |
6645 | face->lface[idx] = tty_color_name (f, pixel); | |
6646 | *defaulted = 1; | |
6647 | } | |
6648 | else if (pixel == default_other_pixel) | |
6649 | { | |
6650 | if (foreground_p) | |
6651 | pixel = FRAME_BACKGROUND_PIXEL (f); | |
6652 | else | |
6653 | pixel = FRAME_FOREGROUND_PIXEL (f); | |
6654 | face->lface[idx] = tty_color_name (f, pixel); | |
6655 | *defaulted = 1; | |
6656 | } | |
6657 | #ifdef MSDOS | |
6658 | } | |
6659 | #endif | |
6660 | #endif /* MSDOS or WINDOWSNT */ | |
6661 | } | |
6662 | ||
6663 | if (foreground_p) | |
6664 | face->foreground = pixel; | |
6665 | else | |
6666 | face->background = pixel; | |
6667 | } | |
6668 | ||
6669 | ||
82641697 | 6670 | /* Realize the fully-specified face with attributes ATTRS in face |
39506348 KH |
6671 | cache CACHE for character C. Do it for TTY frame CACHE->f. Value is a |
6672 | pointer to the newly created realized face. */ | |
a8517066 | 6673 | |
82641697 | 6674 | static struct face * |
39506348 KH |
6675 | realize_tty_face (cache, attrs, c) |
6676 | struct face_cache *cache; | |
82641697 | 6677 | Lisp_Object *attrs; |
39506348 | 6678 | int c; |
82641697 GM |
6679 | { |
6680 | struct face *face; | |
6681 | int weight, slant; | |
2d764c78 | 6682 | int face_colors_defaulted = 0; |
ae4b4ba5 | 6683 | struct frame *f = cache->f; |
729425b1 | 6684 | |
82641697 | 6685 | /* Frame must be a termcap frame. */ |
e689ec06 | 6686 | xassert (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f)); |
178c5d9c | 6687 | |
82641697 | 6688 | /* Allocate a new realized face. */ |
39506348 | 6689 | face = make_realized_face (attrs); |
e689ec06 | 6690 | face->font_name = FRAME_MSDOS_P (cache->f) ? "ms-dos" : "tty"; |
82641697 | 6691 | |
178c5d9c | 6692 | /* Map face attributes to TTY appearances. We map slant to |
82641697 GM |
6693 | dimmed text because we want italic text to appear differently |
6694 | and because dimmed text is probably used infrequently. */ | |
6695 | weight = face_numeric_weight (attrs[LFACE_WEIGHT_INDEX]); | |
6696 | slant = face_numeric_slant (attrs[LFACE_SLANT_INDEX]); | |
6697 | ||
6698 | if (weight > XLFD_WEIGHT_MEDIUM) | |
6699 | face->tty_bold_p = 1; | |
6700 | if (weight < XLFD_WEIGHT_MEDIUM || slant != XLFD_SLANT_ROMAN) | |
6701 | face->tty_dim_p = 1; | |
6702 | if (!NILP (attrs[LFACE_UNDERLINE_INDEX])) | |
6703 | face->tty_underline_p = 1; | |
6704 | if (!NILP (attrs[LFACE_INVERSE_INDEX])) | |
6705 | face->tty_reverse_p = 1; | |
6706 | ||
6707 | /* Map color names to color indices. */ | |
ae4b4ba5 GM |
6708 | map_tty_color (f, face, LFACE_FOREGROUND_INDEX, &face_colors_defaulted); |
6709 | map_tty_color (f, face, LFACE_BACKGROUND_INDEX, &face_colors_defaulted); | |
6710 | ||
2d764c78 EZ |
6711 | /* Swap colors if face is inverse-video. If the colors are taken |
6712 | from the frame colors, they are already inverted, since the | |
6713 | frame-creation function calls x-handle-reverse-video. */ | |
6714 | if (face->tty_reverse_p && !face_colors_defaulted) | |
44747bd0 EZ |
6715 | { |
6716 | unsigned long tem = face->foreground; | |
44747bd0 EZ |
6717 | face->foreground = face->background; |
6718 | face->background = tem; | |
6719 | } | |
44747bd0 | 6720 | |
a4a76b61 GM |
6721 | if (tty_suppress_bold_inverse_default_colors_p |
6722 | && face->tty_bold_p | |
6723 | && face->background == FACE_TTY_DEFAULT_FG_COLOR | |
6724 | && face->foreground == FACE_TTY_DEFAULT_BG_COLOR) | |
6725 | face->tty_bold_p = 0; | |
6726 | ||
82641697 | 6727 | return face; |
729425b1 | 6728 | } |
867dd159 | 6729 | |
82641697 | 6730 | |
a4a76b61 GM |
6731 | DEFUN ("tty-suppress-bold-inverse-default-colors", |
6732 | Ftty_suppress_bold_inverse_default_colors, | |
6733 | Stty_suppress_bold_inverse_default_colors, 1, 1, 0, | |
e3cd9e7f | 6734 | doc: /* Suppress/allow boldness of faces with inverse default colors. |
228299fa GM |
6735 | SUPPRESS non-nil means suppress it. |
6736 | This affects bold faces on TTYs whose foreground is the default background | |
6737 | color of the display and whose background is the default foreground color. | |
6738 | For such faces, the bold face attribute is ignored if this variable | |
7ee72033 MB |
6739 | is non-nil. */) |
6740 | (suppress) | |
a4a76b61 GM |
6741 | Lisp_Object suppress; |
6742 | { | |
6743 | tty_suppress_bold_inverse_default_colors_p = !NILP (suppress); | |
6744 | ++face_change_count; | |
6745 | return suppress; | |
6746 | } | |
6747 | ||
6748 | ||
82641697 GM |
6749 | \f |
6750 | /*********************************************************************** | |
6751 | Computing Faces | |
6752 | ***********************************************************************/ | |
6753 | ||
6754 | /* Return the ID of the face to use to display character CH with face | |
6755 | property PROP on frame F in current_buffer. */ | |
2e16580f RS |
6756 | |
6757 | int | |
82641697 | 6758 | compute_char_face (f, ch, prop) |
2e16580f | 6759 | struct frame *f; |
82641697 GM |
6760 | int ch; |
6761 | Lisp_Object prop; | |
2e16580f | 6762 | { |
82641697 | 6763 | int face_id; |
39506348 KH |
6764 | |
6765 | if (NILP (current_buffer->enable_multibyte_characters)) | |
522d42f7 | 6766 | ch = 0; |
178c5d9c | 6767 | |
82641697 | 6768 | if (NILP (prop)) |
39506348 KH |
6769 | { |
6770 | struct face *face = FACE_FROM_ID (f, DEFAULT_FACE_ID); | |
6771 | face_id = FACE_FOR_CHAR (f, face, ch); | |
6772 | } | |
82641697 | 6773 | else |
2e16580f | 6774 | { |
82641697 GM |
6775 | Lisp_Object attrs[LFACE_VECTOR_SIZE]; |
6776 | struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); | |
6777 | bcopy (default_face->lface, attrs, sizeof attrs); | |
6778 | merge_face_vector_with_property (f, attrs, prop); | |
39506348 | 6779 | face_id = lookup_face (f, attrs, ch, NULL); |
2e16580f RS |
6780 | } |
6781 | ||
82641697 | 6782 | return face_id; |
2e16580f | 6783 | } |
bc0db68d | 6784 | |
82641697 GM |
6785 | /* Return the face ID associated with buffer position POS for |
6786 | displaying ASCII characters. Return in *ENDPTR the position at | |
6787 | which a different face is needed, as far as text properties and | |
6788 | overlays are concerned. W is a window displaying current_buffer. | |
6789 | ||
6790 | REGION_BEG, REGION_END delimit the region, so it can be | |
6791 | highlighted. | |
6f134486 | 6792 | |
82641697 GM |
6793 | LIMIT is a position not to scan beyond. That is to limit the time |
6794 | this function can take. | |
6795 | ||
6796 | If MOUSE is non-zero, use the character's mouse-face, not its face. | |
6797 | ||
39506348 | 6798 | The face returned is suitable for displaying ASCII characters. */ |
bc0db68d | 6799 | |
cb637678 | 6800 | int |
82641697 GM |
6801 | face_at_buffer_position (w, pos, region_beg, region_end, |
6802 | endptr, limit, mouse) | |
f211082d | 6803 | struct window *w; |
7b7739b1 | 6804 | int pos; |
bc0db68d | 6805 | int region_beg, region_end; |
7b7739b1 | 6806 | int *endptr; |
b349f4fb | 6807 | int limit; |
6f134486 | 6808 | int mouse; |
7b7739b1 | 6809 | { |
82641697 GM |
6810 | struct frame *f = XFRAME (w->frame); |
6811 | Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
b6d40e46 | 6812 | Lisp_Object prop, position; |
82641697 | 6813 | int i, noverlays; |
7b7739b1 | 6814 | Lisp_Object *overlay_vec; |
f211082d | 6815 | Lisp_Object frame; |
f6b98e0b | 6816 | int endpos; |
82641697 GM |
6817 | Lisp_Object propname = mouse ? Qmouse_face : Qface; |
6818 | Lisp_Object limit1, end; | |
6819 | struct face *default_face; | |
f6b98e0b JB |
6820 | |
6821 | /* W must display the current buffer. We could write this function | |
6822 | to use the frame and buffer of W, but right now it doesn't. */ | |
060fb5c1 | 6823 | /* xassert (XBUFFER (w->buffer) == current_buffer); */ |
f211082d | 6824 | |
ac22a6c4 | 6825 | XSETFRAME (frame, f); |
82641697 | 6826 | XSETFASTINT (position, pos); |
7b7739b1 | 6827 | |
f6b98e0b | 6828 | endpos = ZV; |
bc0db68d RS |
6829 | if (pos < region_beg && region_beg < endpos) |
6830 | endpos = region_beg; | |
f6b98e0b | 6831 | |
82641697 GM |
6832 | /* Get the `face' or `mouse_face' text property at POS, and |
6833 | determine the next position at which the property changes. */ | |
6f134486 | 6834 | prop = Fget_text_property (position, propname, w->buffer); |
82641697 GM |
6835 | XSETFASTINT (limit1, (limit < endpos ? limit : endpos)); |
6836 | end = Fnext_single_property_change (position, propname, w->buffer, limit1); | |
6837 | if (INTEGERP (end)) | |
6838 | endpos = XINT (end); | |
6f134486 | 6839 | |
82641697 | 6840 | /* Look at properties from overlays. */ |
b6d40e46 | 6841 | { |
f6b98e0b | 6842 | int next_overlay; |
9516fe94 RS |
6843 | int len; |
6844 | ||
6845 | /* First try with room for 40 overlays. */ | |
6846 | len = 40; | |
6847 | overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
7af31819 | 6848 | noverlays = overlays_at (pos, 0, &overlay_vec, &len, |
565c8641 | 6849 | &next_overlay, NULL, 0); |
9516fe94 | 6850 | |
82641697 GM |
6851 | /* If there are more than 40, make enough space for all, and try |
6852 | again. */ | |
9516fe94 RS |
6853 | if (noverlays > len) |
6854 | { | |
6855 | len = noverlays; | |
6856 | overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
82277c2f | 6857 | noverlays = overlays_at (pos, 0, &overlay_vec, &len, |
565c8641 | 6858 | &next_overlay, NULL, 0); |
9516fe94 | 6859 | } |
b6d40e46 | 6860 | |
f6b98e0b JB |
6861 | if (next_overlay < endpos) |
6862 | endpos = next_overlay; | |
b6d40e46 JB |
6863 | } |
6864 | ||
6865 | *endptr = endpos; | |
7b7739b1 | 6866 | |
82641697 | 6867 | default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); |
178c5d9c | 6868 | |
82641697 GM |
6869 | /* Optimize common cases where we can use the default face. */ |
6870 | if (noverlays == 0 | |
6871 | && NILP (prop) | |
39506348 | 6872 | && !(pos >= region_beg && pos < region_end)) |
82641697 GM |
6873 | return DEFAULT_FACE_ID; |
6874 | ||
6875 | /* Begin with attributes from the default face. */ | |
6876 | bcopy (default_face->lface, attrs, sizeof attrs); | |
6877 | ||
6878 | /* Merge in attributes specified via text properties. */ | |
6879 | if (!NILP (prop)) | |
6880 | merge_face_vector_with_property (f, attrs, prop); | |
6881 | ||
6882 | /* Now merge the overlay data. */ | |
18195655 | 6883 | noverlays = sort_overlays (overlay_vec, noverlays, w); |
18195655 | 6884 | for (i = 0; i < noverlays; i++) |
4699e6d2 | 6885 | { |
18195655 RS |
6886 | Lisp_Object oend; |
6887 | int oendpos; | |
6888 | ||
6889 | prop = Foverlay_get (overlay_vec[i], propname); | |
82641697 GM |
6890 | if (!NILP (prop)) |
6891 | merge_face_vector_with_property (f, attrs, prop); | |
18195655 RS |
6892 | |
6893 | oend = OVERLAY_END (overlay_vec[i]); | |
6894 | oendpos = OVERLAY_POSITION (oend); | |
6895 | if (oendpos < endpos) | |
6896 | endpos = oendpos; | |
6897 | } | |
6898 | ||
82641697 | 6899 | /* If in the region, merge in the region face. */ |
18195655 RS |
6900 | if (pos >= region_beg && pos < region_end) |
6901 | { | |
82641697 | 6902 | Lisp_Object region_face = lface_from_face_name (f, Qregion, 0); |
2c20458f | 6903 | merge_face_vectors (f, XVECTOR (region_face)->contents, attrs, Qnil); |
178c5d9c | 6904 | |
18195655 RS |
6905 | if (region_end < endpos) |
6906 | endpos = region_end; | |
18195655 RS |
6907 | } |
6908 | ||
6909 | *endptr = endpos; | |
6910 | ||
82641697 | 6911 | /* Look up a realized face with the given face attributes, |
39506348 KH |
6912 | or realize a new one for ASCII characters. */ |
6913 | return lookup_face (f, attrs, 0, NULL); | |
18195655 RS |
6914 | } |
6915 | ||
60573a90 | 6916 | |
82641697 | 6917 | /* Compute the face at character position POS in Lisp string STRING on |
39506348 | 6918 | window W, for ASCII characters. |
7b7739b1 | 6919 | |
82641697 GM |
6920 | If STRING is an overlay string, it comes from position BUFPOS in |
6921 | current_buffer, otherwise BUFPOS is zero to indicate that STRING is | |
6922 | not an overlay string. W must display the current buffer. | |
6923 | REGION_BEG and REGION_END give the start and end positions of the | |
8714a182 GM |
6924 | region; both are -1 if no region is visible. |
6925 | ||
6926 | BASE_FACE_ID is the id of a face to merge with. For strings coming | |
6927 | from overlays or the `display' property it is the face at BUFPOS. | |
178c5d9c | 6928 | |
48a4ca99 GM |
6929 | If MOUSE_P is non-zero, use the character's mouse-face, not its face. |
6930 | ||
82641697 GM |
6931 | Set *ENDPTR to the next position where to check for faces in |
6932 | STRING; -1 if the face is constant from POS to the end of the | |
6933 | string. | |
18195655 | 6934 | |
82641697 | 6935 | Value is the id of the face to use. The face returned is suitable |
39506348 | 6936 | for displaying ASCII characters. */ |
fffc2367 | 6937 | |
82641697 GM |
6938 | int |
6939 | face_at_string_position (w, string, pos, bufpos, region_beg, | |
48a4ca99 | 6940 | region_end, endptr, base_face_id, mouse_p) |
82641697 GM |
6941 | struct window *w; |
6942 | Lisp_Object string; | |
6943 | int pos, bufpos; | |
6944 | int region_beg, region_end; | |
6945 | int *endptr; | |
6946 | enum face_id base_face_id; | |
48a4ca99 | 6947 | int mouse_p; |
660ed669 | 6948 | { |
82641697 GM |
6949 | Lisp_Object prop, position, end, limit; |
6950 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
6951 | Lisp_Object attrs[LFACE_VECTOR_SIZE]; | |
6952 | struct face *base_face; | |
6953 | int multibyte_p = STRING_MULTIBYTE (string); | |
48a4ca99 | 6954 | Lisp_Object prop_name = mouse_p ? Qmouse_face : Qface; |
82641697 GM |
6955 | |
6956 | /* Get the value of the face property at the current position within | |
6957 | STRING. Value is nil if there is no face property. */ | |
6958 | XSETFASTINT (position, pos); | |
48a4ca99 | 6959 | prop = Fget_text_property (position, prop_name, string); |
82641697 GM |
6960 | |
6961 | /* Get the next position at which to check for faces. Value of end | |
6962 | is nil if face is constant all the way to the end of the string. | |
6963 | Otherwise it is a string position where to check faces next. | |
6964 | Limit is the maximum position up to which to check for property | |
6965 | changes in Fnext_single_property_change. Strings are usually | |
6966 | short, so set the limit to the end of the string. */ | |
6967 | XSETFASTINT (limit, XSTRING (string)->size); | |
48a4ca99 | 6968 | end = Fnext_single_property_change (position, prop_name, string, limit); |
82641697 GM |
6969 | if (INTEGERP (end)) |
6970 | *endptr = XFASTINT (end); | |
6971 | else | |
6972 | *endptr = -1; | |
6973 | ||
6974 | base_face = FACE_FROM_ID (f, base_face_id); | |
6975 | xassert (base_face); | |
6976 | ||
6977 | /* Optimize the default case that there is no face property and we | |
6978 | are not in the region. */ | |
6979 | if (NILP (prop) | |
6980 | && (base_face_id != DEFAULT_FACE_ID | |
6981 | /* BUFPOS <= 0 means STRING is not an overlay string, so | |
6982 | that the region doesn't have to be taken into account. */ | |
6983 | || bufpos <= 0 | |
6984 | || bufpos < region_beg | |
6985 | || bufpos >= region_end) | |
6986 | && (multibyte_p | |
6987 | /* We can't realize faces for different charsets differently | |
6988 | if we don't have fonts, so we can stop here if not working | |
6989 | on a window-system frame. */ | |
6990 | || !FRAME_WINDOW_P (f) | |
39506348 | 6991 | || FACE_SUITABLE_FOR_CHAR_P (base_face, 0))) |
82641697 GM |
6992 | return base_face->id; |
6993 | ||
6994 | /* Begin with attributes from the base face. */ | |
6995 | bcopy (base_face->lface, attrs, sizeof attrs); | |
6996 | ||
6997 | /* Merge in attributes specified via text properties. */ | |
6998 | if (!NILP (prop)) | |
6999 | merge_face_vector_with_property (f, attrs, prop); | |
7000 | ||
7001 | /* If in the region, merge in the region face. */ | |
7002 | if (bufpos | |
7003 | && bufpos >= region_beg | |
7004 | && bufpos < region_end) | |
a8517066 | 7005 | { |
82641697 | 7006 | Lisp_Object region_face = lface_from_face_name (f, Qregion, 0); |
2c20458f | 7007 | merge_face_vectors (f, XVECTOR (region_face)->contents, attrs, Qnil); |
a8517066 | 7008 | } |
660ed669 | 7009 | |
82641697 | 7010 | /* Look up a realized face with the given face attributes, |
39506348 KH |
7011 | or realize a new one for ASCII characters. */ |
7012 | return lookup_face (f, attrs, 0, NULL); | |
660ed669 JB |
7013 | } |
7014 | ||
7015 | ||
c115973b | 7016 | \f |
82641697 GM |
7017 | /*********************************************************************** |
7018 | Tests | |
7019 | ***********************************************************************/ | |
c115973b | 7020 | |
82641697 | 7021 | #if GLYPH_DEBUG |
c115973b | 7022 | |
82641697 | 7023 | /* Print the contents of the realized face FACE to stderr. */ |
c115973b | 7024 | |
82641697 GM |
7025 | static void |
7026 | dump_realized_face (face) | |
7027 | struct face *face; | |
7028 | { | |
7029 | fprintf (stderr, "ID: %d\n", face->id); | |
7030 | #ifdef HAVE_X_WINDOWS | |
7031 | fprintf (stderr, "gc: %d\n", (int) face->gc); | |
7032 | #endif | |
7033 | fprintf (stderr, "foreground: 0x%lx (%s)\n", | |
7034 | face->foreground, | |
7035 | XSTRING (face->lface[LFACE_FOREGROUND_INDEX])->data); | |
7036 | fprintf (stderr, "background: 0x%lx (%s)\n", | |
7037 | face->background, | |
7038 | XSTRING (face->lface[LFACE_BACKGROUND_INDEX])->data); | |
7039 | fprintf (stderr, "font_name: %s (%s)\n", | |
7040 | face->font_name, | |
7041 | XSTRING (face->lface[LFACE_FAMILY_INDEX])->data); | |
7042 | #ifdef HAVE_X_WINDOWS | |
7043 | fprintf (stderr, "font = %p\n", face->font); | |
7044 | #endif | |
7045 | fprintf (stderr, "font_info_id = %d\n", face->font_info_id); | |
7046 | fprintf (stderr, "fontset: %d\n", face->fontset); | |
7047 | fprintf (stderr, "underline: %d (%s)\n", | |
7048 | face->underline_p, | |
7049 | XSTRING (Fsymbol_name (face->lface[LFACE_UNDERLINE_INDEX]))->data); | |
7050 | fprintf (stderr, "hash: %d\n", face->hash); | |
7051 | fprintf (stderr, "charset: %d\n", face->charset); | |
c115973b JB |
7052 | } |
7053 | ||
7054 | ||
7ee72033 MB |
7055 | DEFUN ("dump-face", Fdump_face, Sdump_face, 0, 1, 0, doc: /* */) |
7056 | (n) | |
82641697 | 7057 | Lisp_Object n; |
c115973b | 7058 | { |
82641697 | 7059 | if (NILP (n)) |
c115973b | 7060 | { |
82641697 | 7061 | int i; |
178c5d9c | 7062 | |
82641697 GM |
7063 | fprintf (stderr, "font selection order: "); |
7064 | for (i = 0; i < DIM (font_sort_order); ++i) | |
7065 | fprintf (stderr, "%d ", font_sort_order[i]); | |
7066 | fprintf (stderr, "\n"); | |
7067 | ||
7068 | fprintf (stderr, "alternative fonts: "); | |
7069 | debug_print (Vface_alternative_font_family_alist); | |
7070 | fprintf (stderr, "\n"); | |
178c5d9c | 7071 | |
c0617987 | 7072 | for (i = 0; i < FRAME_FACE_CACHE (SELECTED_FRAME ())->used; ++i) |
82641697 | 7073 | Fdump_face (make_number (i)); |
c115973b JB |
7074 | } |
7075 | else | |
f5e278c7 | 7076 | { |
82641697 | 7077 | struct face *face; |
b7826503 | 7078 | CHECK_NUMBER (n); |
c0617987 | 7079 | face = FACE_FROM_ID (SELECTED_FRAME (), XINT (n)); |
82641697 GM |
7080 | if (face == NULL) |
7081 | error ("Not a valid face"); | |
7082 | dump_realized_face (face); | |
f5e278c7 | 7083 | } |
178c5d9c | 7084 | |
c115973b JB |
7085 | return Qnil; |
7086 | } | |
b5c53576 | 7087 | |
b5c53576 | 7088 | |
82641697 | 7089 | DEFUN ("show-face-resources", Fshow_face_resources, Sshow_face_resources, |
7ee72033 MB |
7090 | 0, 0, 0, doc: /* */) |
7091 | () | |
b5c53576 | 7092 | { |
82641697 GM |
7093 | fprintf (stderr, "number of colors = %d\n", ncolors_allocated); |
7094 | fprintf (stderr, "number of pixmaps = %d\n", npixmaps_allocated); | |
7095 | fprintf (stderr, "number of GCs = %d\n", ngcs); | |
7096 | return Qnil; | |
b5c53576 RS |
7097 | } |
7098 | ||
82641697 GM |
7099 | #endif /* GLYPH_DEBUG != 0 */ |
7100 | ||
b5c53576 | 7101 | |
c115973b | 7102 | \f |
82641697 GM |
7103 | /*********************************************************************** |
7104 | Initialization | |
7105 | ***********************************************************************/ | |
cb637678 | 7106 | |
c115973b | 7107 | void |
f211082d | 7108 | syms_of_xfaces () |
c115973b | 7109 | { |
f211082d JB |
7110 | Qface = intern ("face"); |
7111 | staticpro (&Qface); | |
fef04523 GM |
7112 | Qbitmap_spec_p = intern ("bitmap-spec-p"); |
7113 | staticpro (&Qbitmap_spec_p); | |
92610620 GM |
7114 | Qframe_update_face_colors = intern ("frame-update-face-colors"); |
7115 | staticpro (&Qframe_update_face_colors); | |
178c5d9c | 7116 | |
82641697 GM |
7117 | /* Lisp face attribute keywords. */ |
7118 | QCfamily = intern (":family"); | |
7119 | staticpro (&QCfamily); | |
7120 | QCheight = intern (":height"); | |
7121 | staticpro (&QCheight); | |
7122 | QCweight = intern (":weight"); | |
7123 | staticpro (&QCweight); | |
7124 | QCslant = intern (":slant"); | |
7125 | staticpro (&QCslant); | |
7126 | QCunderline = intern (":underline"); | |
7127 | staticpro (&QCunderline); | |
7128 | QCinverse_video = intern (":inverse-video"); | |
178c5d9c | 7129 | staticpro (&QCinverse_video); |
82641697 GM |
7130 | QCreverse_video = intern (":reverse-video"); |
7131 | staticpro (&QCreverse_video); | |
7132 | QCforeground = intern (":foreground"); | |
7133 | staticpro (&QCforeground); | |
7134 | QCbackground = intern (":background"); | |
7135 | staticpro (&QCbackground); | |
7136 | QCstipple = intern (":stipple");; | |
7137 | staticpro (&QCstipple); | |
7138 | QCwidth = intern (":width"); | |
7139 | staticpro (&QCwidth); | |
7140 | QCfont = intern (":font"); | |
7141 | staticpro (&QCfont); | |
7142 | QCbold = intern (":bold"); | |
7143 | staticpro (&QCbold); | |
7144 | QCitalic = intern (":italic"); | |
7145 | staticpro (&QCitalic); | |
7146 | QCoverline = intern (":overline"); | |
7147 | staticpro (&QCoverline); | |
7148 | QCstrike_through = intern (":strike-through"); | |
7149 | staticpro (&QCstrike_through); | |
7150 | QCbox = intern (":box"); | |
7151 | staticpro (&QCbox); | |
2c20458f MB |
7152 | QCinherit = intern (":inherit"); |
7153 | staticpro (&QCinherit); | |
82641697 GM |
7154 | |
7155 | /* Symbols used for Lisp face attribute values. */ | |
7156 | QCcolor = intern (":color"); | |
7157 | staticpro (&QCcolor); | |
7158 | QCline_width = intern (":line-width"); | |
7159 | staticpro (&QCline_width); | |
7160 | QCstyle = intern (":style"); | |
7161 | staticpro (&QCstyle); | |
7162 | Qreleased_button = intern ("released-button"); | |
7163 | staticpro (&Qreleased_button); | |
7164 | Qpressed_button = intern ("pressed-button"); | |
7165 | staticpro (&Qpressed_button); | |
7166 | Qnormal = intern ("normal"); | |
7167 | staticpro (&Qnormal); | |
7168 | Qultra_light = intern ("ultra-light"); | |
7169 | staticpro (&Qultra_light); | |
7170 | Qextra_light = intern ("extra-light"); | |
7171 | staticpro (&Qextra_light); | |
7172 | Qlight = intern ("light"); | |
7173 | staticpro (&Qlight); | |
7174 | Qsemi_light = intern ("semi-light"); | |
7175 | staticpro (&Qsemi_light); | |
7176 | Qsemi_bold = intern ("semi-bold"); | |
7177 | staticpro (&Qsemi_bold); | |
7178 | Qbold = intern ("bold"); | |
7179 | staticpro (&Qbold); | |
7180 | Qextra_bold = intern ("extra-bold"); | |
7181 | staticpro (&Qextra_bold); | |
7182 | Qultra_bold = intern ("ultra-bold"); | |
7183 | staticpro (&Qultra_bold); | |
7184 | Qoblique = intern ("oblique"); | |
7185 | staticpro (&Qoblique); | |
7186 | Qitalic = intern ("italic"); | |
7187 | staticpro (&Qitalic); | |
7188 | Qreverse_oblique = intern ("reverse-oblique"); | |
7189 | staticpro (&Qreverse_oblique); | |
7190 | Qreverse_italic = intern ("reverse-italic"); | |
7191 | staticpro (&Qreverse_italic); | |
7192 | Qultra_condensed = intern ("ultra-condensed"); | |
7193 | staticpro (&Qultra_condensed); | |
7194 | Qextra_condensed = intern ("extra-condensed"); | |
7195 | staticpro (&Qextra_condensed); | |
7196 | Qcondensed = intern ("condensed"); | |
7197 | staticpro (&Qcondensed); | |
7198 | Qsemi_condensed = intern ("semi-condensed"); | |
7199 | staticpro (&Qsemi_condensed); | |
7200 | Qsemi_expanded = intern ("semi-expanded"); | |
7201 | staticpro (&Qsemi_expanded); | |
7202 | Qexpanded = intern ("expanded"); | |
7203 | staticpro (&Qexpanded); | |
7204 | Qextra_expanded = intern ("extra-expanded"); | |
7205 | staticpro (&Qextra_expanded); | |
7206 | Qultra_expanded = intern ("ultra-expanded"); | |
7207 | staticpro (&Qultra_expanded); | |
7208 | Qbackground_color = intern ("background-color"); | |
7209 | staticpro (&Qbackground_color); | |
7210 | Qforeground_color = intern ("foreground-color"); | |
7211 | staticpro (&Qforeground_color); | |
7212 | Qunspecified = intern ("unspecified"); | |
7213 | staticpro (&Qunspecified); | |
7214 | ||
92610620 GM |
7215 | Qface_alias = intern ("face-alias"); |
7216 | staticpro (&Qface_alias); | |
82641697 GM |
7217 | Qdefault = intern ("default"); |
7218 | staticpro (&Qdefault); | |
9ea173e8 GM |
7219 | Qtool_bar = intern ("tool-bar"); |
7220 | staticpro (&Qtool_bar); | |
82641697 GM |
7221 | Qregion = intern ("region"); |
7222 | staticpro (&Qregion); | |
8bd201d6 GM |
7223 | Qfringe = intern ("fringe"); |
7224 | staticpro (&Qfringe); | |
045dee35 GM |
7225 | Qheader_line = intern ("header-line"); |
7226 | staticpro (&Qheader_line); | |
8bd201d6 GM |
7227 | Qscroll_bar = intern ("scroll-bar"); |
7228 | staticpro (&Qscroll_bar); | |
c7ae3284 GM |
7229 | Qmenu = intern ("menu"); |
7230 | staticpro (&Qmenu); | |
8bd201d6 GM |
7231 | Qcursor = intern ("cursor"); |
7232 | staticpro (&Qcursor); | |
7233 | Qborder = intern ("border"); | |
7234 | staticpro (&Qborder); | |
7235 | Qmouse = intern ("mouse"); | |
7236 | staticpro (&Qmouse); | |
039b6394 KS |
7237 | Qmode_line_inactive = intern ("mode-line-inactive"); |
7238 | staticpro (&Qmode_line_inactive); | |
2d764c78 EZ |
7239 | Qtty_color_desc = intern ("tty-color-desc"); |
7240 | staticpro (&Qtty_color_desc); | |
7241 | Qtty_color_by_index = intern ("tty-color-by-index"); | |
7242 | staticpro (&Qtty_color_by_index); | |
ae4b4ba5 GM |
7243 | Qtty_color_alist = intern ("tty-color-alist"); |
7244 | staticpro (&Qtty_color_alist); | |
eeffb293 GM |
7245 | Qscalable_fonts_allowed = intern ("scalable-fonts-allowed"); |
7246 | staticpro (&Qscalable_fonts_allowed); | |
82641697 | 7247 | |
dbc968b8 GM |
7248 | Vparam_value_alist = Fcons (Fcons (Qnil, Qnil), Qnil); |
7249 | staticpro (&Vparam_value_alist); | |
434b9cc5 GM |
7250 | Vface_alternative_font_family_alist = Qnil; |
7251 | staticpro (&Vface_alternative_font_family_alist); | |
32fcc231 GM |
7252 | Vface_alternative_font_registry_alist = Qnil; |
7253 | staticpro (&Vface_alternative_font_registry_alist); | |
434b9cc5 | 7254 | |
82641697 GM |
7255 | defsubr (&Sinternal_make_lisp_face); |
7256 | defsubr (&Sinternal_lisp_face_p); | |
7257 | defsubr (&Sinternal_set_lisp_face_attribute); | |
c3cee013 | 7258 | #ifdef HAVE_WINDOW_SYSTEM |
82641697 | 7259 | defsubr (&Sinternal_set_lisp_face_attribute_from_resource); |
42608ba8 | 7260 | #endif |
ea4fa0af GM |
7261 | defsubr (&Scolor_gray_p); |
7262 | defsubr (&Scolor_supported_p); | |
cdfaafa9 MB |
7263 | defsubr (&Sface_attribute_relative_p); |
7264 | defsubr (&Smerge_face_attribute); | |
82641697 GM |
7265 | defsubr (&Sinternal_get_lisp_face_attribute); |
7266 | defsubr (&Sinternal_lisp_face_attribute_values); | |
7267 | defsubr (&Sinternal_lisp_face_equal_p); | |
7268 | defsubr (&Sinternal_lisp_face_empty_p); | |
7269 | defsubr (&Sinternal_copy_lisp_face); | |
7270 | defsubr (&Sinternal_merge_in_global_face); | |
7271 | defsubr (&Sface_font); | |
7272 | defsubr (&Sframe_face_alist); | |
7273 | defsubr (&Sinternal_set_font_selection_order); | |
7274 | defsubr (&Sinternal_set_alternative_font_family_alist); | |
32fcc231 | 7275 | defsubr (&Sinternal_set_alternative_font_registry_alist); |
f6608d5c | 7276 | defsubr (&Sface_attributes_as_vector); |
82641697 GM |
7277 | #if GLYPH_DEBUG |
7278 | defsubr (&Sdump_face); | |
7279 | defsubr (&Sshow_face_resources); | |
7280 | #endif /* GLYPH_DEBUG */ | |
7281 | defsubr (&Sclear_face_cache); | |
a4a76b61 | 7282 | defsubr (&Stty_suppress_bold_inverse_default_colors); |
82641697 | 7283 | |
38426dee | 7284 | #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS |
08dc08dc GM |
7285 | defsubr (&Sdump_colors); |
7286 | #endif | |
7287 | ||
7ee72033 MB |
7288 | DEFVAR_LISP ("font-list-limit", &Vfont_list_limit, |
7289 | doc: /* *Limit for font matching. | |
228299fa GM |
7290 | If an integer > 0, font matching functions won't load more than |
7291 | that number of fonts when searching for a matching font. */); | |
057df17c GM |
7292 | Vfont_list_limit = make_number (DEFAULT_FONT_LIST_LIMIT); |
7293 | ||
7ee72033 MB |
7294 | DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults, |
7295 | doc: /* List of global face definitions (for internal use only.) */); | |
82641697 | 7296 | Vface_new_frame_defaults = Qnil; |
178c5d9c | 7297 | |
7ee72033 MB |
7298 | DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple, |
7299 | doc: /* *Default stipple pattern used on monochrome displays. | |
228299fa GM |
7300 | This stipple pattern is used on monochrome displays |
7301 | instead of shades of gray for a face background color. | |
7302 | See `set-face-stipple' for possible values for this variable. */); | |
82641697 GM |
7303 | Vface_default_stipple = build_string ("gray3"); |
7304 | ||
7ee72033 MB |
7305 | DEFVAR_LISP ("tty-defined-color-alist", &Vtty_defined_color_alist, |
7306 | doc: /* An alist of defined terminal colors and their RGB values. */); | |
ae4b4ba5 GM |
7307 | Vtty_defined_color_alist = Qnil; |
7308 | ||
7ee72033 MB |
7309 | DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed, |
7310 | doc: /* Allowed scalable fonts. | |
228299fa GM |
7311 | A value of nil means don't allow any scalable fonts. |
7312 | A value of t means allow any scalable font. | |
7313 | Otherwise, value must be a list of regular expressions. A font may be | |
7314 | scaled if its name matches a regular expression in the list. | |
7315 | Note that if value is nil, a scalable font might still be used, if no | |
7316 | other font of the appropriate family and registry is available. */); | |
3cf80731 | 7317 | Vscalable_fonts_allowed = Qnil; |
b5c53576 | 7318 | |
7ee72033 MB |
7319 | DEFVAR_LISP ("face-ignored-fonts", &Vface_ignored_fonts, |
7320 | doc: /* List of ignored fonts. | |
228299fa GM |
7321 | Each element is a regular expression that matches names of fonts to |
7322 | ignore. */); | |
c824bfbc KH |
7323 | Vface_ignored_fonts = Qnil; |
7324 | ||
c3cee013 | 7325 | #ifdef HAVE_WINDOW_SYSTEM |
fef04523 | 7326 | defsubr (&Sbitmap_spec_p); |
82641697 GM |
7327 | defsubr (&Sx_list_fonts); |
7328 | defsubr (&Sinternal_face_x_get_resource); | |
92610620 | 7329 | defsubr (&Sx_family_fonts); |
82641697 | 7330 | defsubr (&Sx_font_family_list); |
c3cee013 | 7331 | #endif /* HAVE_WINDOW_SYSTEM */ |
c115973b | 7332 | } |