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