* autogen/update_autogen: Add a separate -L option for ldefs-boot.el.
[emacs.git] / src / xfaces.c
blob0fc5dd6f8a32cad798a590bce58dda2f7771a819
1 /* xfaces.c -- "Face" primitives.
3 Copyright (C) 1993-1994, 1998-2011 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
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.
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.
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/>. */
20 /* New face implementation by Gerd Moellmann <gerd@gnu.org>. */
22 /* Faces.
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:
28 1. Font family name.
30 2. Font foundary name.
32 3. Relative proportionate width, aka character set width or set
33 width (swidth), e.g. `semi-compressed'.
35 4. Font height in 1/10pt.
37 5. Font weight, e.g. `bold'.
39 6. Font slant, e.g. `italic'.
41 7. Foreground color.
43 8. Background color.
45 9. Whether or not characters should be underlined, and in what color.
47 10. Whether or not characters should be displayed in inverse video.
49 11. A background stipple, a bitmap.
51 12. Whether or not characters should be overlined, and in what color.
53 13. Whether or not characters should be strike-through, and in what
54 color.
56 14. Whether or not a box should be drawn around characters, the box
57 type, and, for simple boxes, in what color.
59 15. Font-spec, or nil. This is a special attribute.
61 A font-spec is a collection of font attributes (specs).
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.
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.
71 15. A face name or list of face names from which to inherit attributes.
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.
77 17. A fontset name. This is another special attribute.
79 A fontset is a mappings from characters to font-specs, and the
80 specs overwrite the font-spec in the 14th attribute.
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.
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.
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'.
99 Face merging.
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.
109 Face realization.
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.
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.
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.
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.
134 Thus, all realized faces have a realized fontset.
137 Unibyte text.
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.
145 Font selection.
147 Font selection tries to find the best available matching font for a
148 given (character, face) combination.
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.
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.
161 Font selection can be influenced by the user.
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.
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.
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.
180 4. Setting face-ignored-fonts allows the user to ignore specific
181 fonts.
184 Character composition.
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.
195 Initialization of basic faces.
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. */
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 #include <setjmp.h>
209 #include "lisp.h"
210 #include "character.h"
211 #include "charset.h"
212 #include "keyboard.h"
213 #include "frame.h"
214 #include "termhooks.h"
216 #ifdef HAVE_X_WINDOWS
217 #include "xterm.h"
218 #ifdef USE_MOTIF
219 #include <Xm/Xm.h>
220 #include <Xm/XmStrDefs.h>
221 #endif /* USE_MOTIF */
222 #endif /* HAVE_X_WINDOWS */
224 #ifdef MSDOS
225 #include "dosfns.h"
226 #endif
228 #ifdef WINDOWSNT
229 #include "w32term.h"
230 #include "fontset.h"
231 /* Redefine X specifics to W32 equivalents to avoid cluttering the
232 code with #ifdef blocks. */
233 #undef FRAME_X_DISPLAY_INFO
234 #define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO
235 #define x_display_info w32_display_info
236 #define FRAME_X_FONT_TABLE FRAME_W32_FONT_TABLE
237 #define check_x check_w32
238 #define GCGraphicsExposures 0
239 #endif /* WINDOWSNT */
241 #ifdef HAVE_NS
242 #include "nsterm.h"
243 #undef FRAME_X_DISPLAY_INFO
244 #define FRAME_X_DISPLAY_INFO FRAME_NS_DISPLAY_INFO
245 #define x_display_info ns_display_info
246 #define FRAME_X_FONT_TABLE FRAME_NS_FONT_TABLE
247 #define check_x check_ns
248 #define GCGraphicsExposures 0
249 #endif /* HAVE_NS */
251 #include "buffer.h"
252 #include "dispextern.h"
253 #include "blockinput.h"
254 #include "window.h"
255 #include "intervals.h"
256 #include "termchar.h"
258 #include "font.h"
259 #ifdef HAVE_WINDOW_SYSTEM
260 #include "fontset.h"
261 #endif /* HAVE_WINDOW_SYSTEM */
263 #ifdef HAVE_X_WINDOWS
265 /* Compensate for a bug in Xos.h on some systems, on which it requires
266 time.h. On some such systems, Xos.h tries to redefine struct
267 timeval and struct timezone if USG is #defined while it is
268 #included. */
270 #ifdef XOS_NEEDS_TIME_H
271 #include <time.h>
272 #undef USG
273 #include <X11/Xos.h>
274 #define USG
275 #define __TIMEVAL__
276 #else /* not XOS_NEEDS_TIME_H */
277 #include <X11/Xos.h>
278 #endif /* not XOS_NEEDS_TIME_H */
280 #endif /* HAVE_X_WINDOWS */
282 #include <ctype.h>
284 /* Number of pt per inch (from the TeXbook). */
286 #define PT_PER_INCH 72.27
288 /* Non-zero if face attribute ATTR is unspecified. */
290 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified)
292 /* Non-zero if face attribute ATTR is `ignore-defface'. */
294 #define IGNORE_DEFFACE_P(ATTR) EQ ((ATTR), Qignore_defface)
296 /* Value is the number of elements of VECTOR. */
298 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
300 /* Size of hash table of realized faces in face caches (should be a
301 prime number). */
303 #define FACE_CACHE_BUCKETS_SIZE 1001
305 /* Keyword symbols used for face attribute names. */
307 Lisp_Object QCfamily, QCheight, QCweight, QCslant, QCunderline;
308 Lisp_Object QCinverse_video, QCforeground, QCbackground, QCstipple;
309 Lisp_Object QCwidth, QCfont, QCbold, QCitalic;
310 Lisp_Object QCreverse_video;
311 Lisp_Object QCoverline, QCstrike_through, QCbox, QCinherit;
312 Lisp_Object QCfontset;
314 /* Symbols used for attribute values. */
316 Lisp_Object Qnormal, Qbold, Qultra_light, Qextra_light, Qlight;
317 Lisp_Object Qsemi_light, Qsemi_bold, Qextra_bold, Qultra_bold;
318 Lisp_Object Qoblique, Qitalic, Qreverse_oblique, Qreverse_italic;
319 Lisp_Object Qultra_condensed, Qextra_condensed, Qcondensed;
320 Lisp_Object Qsemi_condensed, Qsemi_expanded, Qexpanded, Qextra_expanded;
321 Lisp_Object Qultra_expanded;
322 Lisp_Object Qreleased_button, Qpressed_button;
323 Lisp_Object QCstyle, QCcolor, QCline_width;
324 Lisp_Object Qunspecified;
325 Lisp_Object Qignore_defface;
327 char unspecified_fg[] = "unspecified-fg", unspecified_bg[] = "unspecified-bg";
329 /* The name of the function to call when the background of the frame
330 has changed, frame_set_background_mode. */
332 Lisp_Object Qframe_set_background_mode;
334 /* Names of basic faces. */
336 Lisp_Object Qdefault, Qtool_bar, Qregion, Qfringe;
337 Lisp_Object Qheader_line, Qscroll_bar, Qcursor, Qborder, Qmouse, Qmenu;
338 Lisp_Object Qmode_line_inactive, Qvertical_border;
340 /* The symbol `face-alias'. A symbols having that property is an
341 alias for another face. Value of the property is the name of
342 the aliased face. */
344 Lisp_Object Qface_alias;
346 /* Alist of alternative font families. Each element is of the form
347 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
348 try FAMILY1, then FAMILY2, ... */
350 Lisp_Object Vface_alternative_font_family_alist;
352 /* Alist of alternative font registries. Each element is of the form
353 (REGISTRY REGISTRY1 REGISTRY2...). If fonts of REGISTRY can't be
354 loaded, try REGISTRY1, then REGISTRY2, ... */
356 Lisp_Object Vface_alternative_font_registry_alist;
358 /* Allowed scalable fonts. A value of nil means don't allow any
359 scalable fonts. A value of t means allow the use of any scalable
360 font. Otherwise, value must be a list of regular expressions. A
361 font may be scaled if its name matches a regular expression in the
362 list. */
364 Lisp_Object Qscalable_fonts_allowed;
366 #define DEFAULT_FONT_LIST_LIMIT 100
368 /* The symbols `foreground-color' and `background-color' which can be
369 used as part of a `face' property. This is for compatibility with
370 Emacs 20.2. */
372 Lisp_Object Qforeground_color, Qbackground_color;
374 /* The symbols `face' and `mouse-face' used as text properties. */
376 Lisp_Object Qface;
378 /* Property for basic faces which other faces cannot inherit. */
380 Lisp_Object Qface_no_inherit;
382 /* Error symbol for wrong_type_argument in load_pixmap. */
384 Lisp_Object Qbitmap_spec_p;
386 /* The next ID to assign to Lisp faces. */
388 static int next_lface_id;
390 /* A vector mapping Lisp face Id's to face names. */
392 static Lisp_Object *lface_id_to_name;
393 static int lface_id_to_name_size;
395 /* TTY color-related functions (defined in tty-colors.el). */
397 Lisp_Object Qtty_color_desc, Qtty_color_by_index, Qtty_color_standard_values;
399 /* The name of the function used to compute colors on TTYs. */
401 Lisp_Object Qtty_color_alist;
403 /* Counter for calls to clear_face_cache. If this counter reaches
404 CLEAR_FONT_TABLE_COUNT, and a frame has more than
405 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
407 static int clear_font_table_count;
408 #define CLEAR_FONT_TABLE_COUNT 100
409 #define CLEAR_FONT_TABLE_NFONTS 10
411 /* Non-zero means face attributes have been changed since the last
412 redisplay. Used in redisplay_internal. */
414 int face_change_count;
416 /* Non-zero means don't display bold text if a face's foreground
417 and background colors are the inverse of the default colors of the
418 display. This is a kluge to suppress `bold black' foreground text
419 which is hard to read on an LCD monitor. */
421 int tty_suppress_bold_inverse_default_colors_p;
423 /* A list of the form `((x . y))' used to avoid consing in
424 Finternal_set_lisp_face_attribute. */
426 static Lisp_Object Vparam_value_alist;
428 /* The total number of colors currently allocated. */
430 #if GLYPH_DEBUG
431 static int ncolors_allocated;
432 static int npixmaps_allocated;
433 static int ngcs;
434 #endif
436 /* Non-zero means the definition of the `menu' face for new frames has
437 been changed. */
439 int menu_face_changed_default;
442 /* Function prototypes. */
444 struct table_entry;
445 struct named_merge_point;
447 static void map_tty_color (struct frame *, struct face *,
448 enum lface_attribute_index, int *);
449 static Lisp_Object resolve_face_name (Lisp_Object, int);
450 static void set_font_frame_param (Lisp_Object, Lisp_Object);
451 static int get_lface_attributes (struct frame *, Lisp_Object, Lisp_Object *,
452 int, struct named_merge_point *);
453 static int load_pixmap (struct frame *, Lisp_Object, unsigned *, unsigned *);
454 static struct frame *frame_or_selected_frame (Lisp_Object, int);
455 static void load_face_colors (struct frame *, struct face *, Lisp_Object *);
456 static void free_face_colors (struct frame *, struct face *);
457 static int face_color_gray_p (struct frame *, const char *);
458 static struct face *realize_face (struct face_cache *, Lisp_Object *,
459 int);
460 static struct face *realize_non_ascii_face (struct frame *, Lisp_Object,
461 struct face *);
462 static struct face *realize_x_face (struct face_cache *, Lisp_Object *);
463 static struct face *realize_tty_face (struct face_cache *, Lisp_Object *);
464 static int realize_basic_faces (struct frame *);
465 static int realize_default_face (struct frame *);
466 static void realize_named_face (struct frame *, Lisp_Object, int);
467 static int lface_fully_specified_p (Lisp_Object *);
468 static int lface_equal_p (Lisp_Object *, Lisp_Object *);
469 static unsigned hash_string_case_insensitive (Lisp_Object);
470 static unsigned lface_hash (Lisp_Object *);
471 static int lface_same_font_attributes_p (Lisp_Object *, Lisp_Object *);
472 static struct face_cache *make_face_cache (struct frame *);
473 static void clear_face_gcs (struct face_cache *);
474 static void free_face_cache (struct face_cache *);
475 static int face_fontset (Lisp_Object *);
476 static void merge_face_vectors (struct frame *, Lisp_Object *, Lisp_Object*,
477 struct named_merge_point *);
478 static int merge_face_ref (struct frame *, Lisp_Object, Lisp_Object *,
479 int, struct named_merge_point *);
480 static int set_lface_from_font (struct frame *, Lisp_Object, Lisp_Object,
481 int);
482 static Lisp_Object lface_from_face_name (struct frame *, Lisp_Object, int);
483 static struct face *make_realized_face (Lisp_Object *);
484 static void cache_face (struct face_cache *, struct face *, unsigned);
485 static void uncache_face (struct face_cache *, struct face *);
487 #ifdef HAVE_WINDOW_SYSTEM
489 static GC x_create_gc (struct frame *, unsigned long, XGCValues *);
490 static void x_free_gc (struct frame *, GC);
492 #ifdef USE_X_TOOLKIT
493 static void x_update_menu_appearance (struct frame *);
495 extern void free_frame_menubar (struct frame *);
496 #endif /* USE_X_TOOLKIT */
498 #endif /* HAVE_WINDOW_SYSTEM */
501 /***********************************************************************
502 Utilities
503 ***********************************************************************/
505 #ifdef HAVE_X_WINDOWS
507 #ifdef DEBUG_X_COLORS
509 /* The following is a poor mans infrastructure for debugging X color
510 allocation problems on displays with PseudoColor-8. Some X servers
511 like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement
512 color reference counts completely so that they don't signal an
513 error when a color is freed whose reference count is already 0.
514 Other X servers do. To help me debug this, the following code
515 implements a simple reference counting schema of its own, for a
516 single display/screen. --gerd. */
518 /* Reference counts for pixel colors. */
520 int color_count[256];
522 /* Register color PIXEL as allocated. */
524 void
525 register_color (pixel)
526 unsigned long pixel;
528 xassert (pixel < 256);
529 ++color_count[pixel];
533 /* Register color PIXEL as deallocated. */
535 void
536 unregister_color (pixel)
537 unsigned long pixel;
539 xassert (pixel < 256);
540 if (color_count[pixel] > 0)
541 --color_count[pixel];
542 else
543 abort ();
547 /* Register N colors from PIXELS as deallocated. */
549 void
550 unregister_colors (pixels, n)
551 unsigned long *pixels;
552 int n;
554 int i;
555 for (i = 0; i < n; ++i)
556 unregister_color (pixels[i]);
560 DEFUN ("dump-colors", Fdump_colors, Sdump_colors, 0, 0, 0,
561 doc: /* Dump currently allocated colors to stderr. */)
562 (void)
564 int i, n;
566 fputc ('\n', stderr);
568 for (i = n = 0; i < sizeof color_count / sizeof color_count[0]; ++i)
569 if (color_count[i])
571 fprintf (stderr, "%3d: %5d", i, color_count[i]);
572 ++n;
573 if (n % 5 == 0)
574 fputc ('\n', stderr);
575 else
576 fputc ('\t', stderr);
579 if (n % 5 != 0)
580 fputc ('\n', stderr);
581 return Qnil;
584 #endif /* DEBUG_X_COLORS */
587 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
588 color values. Interrupt input must be blocked when this function
589 is called. */
591 void
592 x_free_colors (struct frame *f, long unsigned int *pixels, int npixels)
594 int class = FRAME_X_DISPLAY_INFO (f)->visual->class;
596 /* If display has an immutable color map, freeing colors is not
597 necessary and some servers don't allow it. So don't do it. */
598 if (class != StaticColor && class != StaticGray && class != TrueColor)
600 #ifdef DEBUG_X_COLORS
601 unregister_colors (pixels, npixels);
602 #endif
603 XFreeColors (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f),
604 pixels, npixels, 0);
609 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
610 color values. Interrupt input must be blocked when this function
611 is called. */
613 void
614 x_free_dpy_colors (Display *dpy, Screen *screen, Colormap cmap, long unsigned int *pixels, int npixels)
616 struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
617 int class = dpyinfo->visual->class;
619 /* If display has an immutable color map, freeing colors is not
620 necessary and some servers don't allow it. So don't do it. */
621 if (class != StaticColor && class != StaticGray && class != TrueColor)
623 #ifdef DEBUG_X_COLORS
624 unregister_colors (pixels, npixels);
625 #endif
626 XFreeColors (dpy, cmap, pixels, npixels, 0);
631 /* Create and return a GC for use on frame F. GC values and mask
632 are given by XGCV and MASK. */
634 static INLINE GC
635 x_create_gc (struct frame *f, long unsigned int mask, XGCValues *xgcv)
637 GC gc;
638 BLOCK_INPUT;
639 gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), mask, xgcv);
640 UNBLOCK_INPUT;
641 IF_DEBUG (++ngcs);
642 return gc;
646 /* Free GC which was used on frame F. */
648 static INLINE void
649 x_free_gc (struct frame *f, GC gc)
651 eassert (interrupt_input_blocked);
652 IF_DEBUG (xassert (--ngcs >= 0));
653 XFreeGC (FRAME_X_DISPLAY (f), gc);
656 #endif /* HAVE_X_WINDOWS */
658 #ifdef WINDOWSNT
659 /* W32 emulation of GCs */
661 static INLINE GC
662 x_create_gc (struct frame *f, unsigned long mask, XGCValues *xgcv)
664 GC gc;
665 BLOCK_INPUT;
666 gc = XCreateGC (NULL, FRAME_W32_WINDOW (f), mask, xgcv);
667 UNBLOCK_INPUT;
668 IF_DEBUG (++ngcs);
669 return gc;
673 /* Free GC which was used on frame F. */
675 static INLINE void
676 x_free_gc (struct frame *f, GC gc)
678 IF_DEBUG (xassert (--ngcs >= 0));
679 xfree (gc);
682 #endif /* WINDOWSNT */
684 #ifdef HAVE_NS
685 /* NS emulation of GCs */
687 static INLINE GC
688 x_create_gc (struct frame *f,
689 unsigned long mask,
690 XGCValues *xgcv)
692 GC gc = xmalloc (sizeof (*gc));
693 if (gc)
694 memcpy (gc, xgcv, sizeof (XGCValues));
695 return gc;
698 static INLINE void
699 x_free_gc (struct frame *f, GC gc)
701 xfree (gc);
703 #endif /* HAVE_NS */
705 /* Like strcasecmp/stricmp. Used to compare parts of font names which
706 are in ISO8859-1. */
709 xstrcasecmp (const char *s1, const char *s2)
711 while (*s1 && *s2)
713 unsigned char b1 = *s1;
714 unsigned char b2 = *s2;
715 unsigned char c1 = tolower (b1);
716 unsigned char c2 = tolower (b2);
717 if (c1 != c2)
718 return c1 < c2 ? -1 : 1;
719 ++s1, ++s2;
722 if (*s1 == 0)
723 return *s2 == 0 ? 0 : -1;
724 return 1;
728 /* If FRAME is nil, return a pointer to the selected frame.
729 Otherwise, check that FRAME is a live frame, and return a pointer
730 to it. NPARAM is the parameter number of FRAME, for
731 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
732 Lisp function definitions. */
734 static INLINE struct frame *
735 frame_or_selected_frame (Lisp_Object frame, int nparam)
737 if (NILP (frame))
738 frame = selected_frame;
740 CHECK_LIVE_FRAME (frame);
741 return XFRAME (frame);
745 /***********************************************************************
746 Frames and faces
747 ***********************************************************************/
749 /* Initialize face cache and basic faces for frame F. */
751 void
752 init_frame_faces (struct frame *f)
754 /* Make a face cache, if F doesn't have one. */
755 if (FRAME_FACE_CACHE (f) == NULL)
756 FRAME_FACE_CACHE (f) = make_face_cache (f);
758 #ifdef HAVE_WINDOW_SYSTEM
759 /* Make the image cache. */
760 if (FRAME_WINDOW_P (f))
762 /* We initialize the image cache when creating the first frame
763 on a terminal, and not during terminal creation. This way,
764 `x-open-connection' on a tty won't create an image cache. */
765 if (FRAME_IMAGE_CACHE (f) == NULL)
766 FRAME_IMAGE_CACHE (f) = make_image_cache ();
767 ++FRAME_IMAGE_CACHE (f)->refcount;
769 #endif /* HAVE_WINDOW_SYSTEM */
771 /* Realize basic faces. Must have enough information in frame
772 parameters to realize basic faces at this point. */
773 #ifdef HAVE_X_WINDOWS
774 if (!FRAME_X_P (f) || FRAME_X_WINDOW (f))
775 #endif
776 #ifdef WINDOWSNT
777 if (!FRAME_WINDOW_P (f) || FRAME_W32_WINDOW (f))
778 #endif
779 #ifdef HAVE_NS
780 if (!FRAME_NS_P (f) || FRAME_NS_WINDOW (f))
781 #endif
782 if (!realize_basic_faces (f))
783 abort ();
787 /* Free face cache of frame F. Called from delete_frame. */
789 void
790 free_frame_faces (struct frame *f)
792 struct face_cache *face_cache = FRAME_FACE_CACHE (f);
794 if (face_cache)
796 free_face_cache (face_cache);
797 FRAME_FACE_CACHE (f) = NULL;
800 #ifdef HAVE_WINDOW_SYSTEM
801 if (FRAME_WINDOW_P (f))
803 struct image_cache *image_cache = FRAME_IMAGE_CACHE (f);
804 if (image_cache)
806 --image_cache->refcount;
807 if (image_cache->refcount == 0)
808 free_image_cache (f);
811 #endif /* HAVE_WINDOW_SYSTEM */
815 /* Clear face caches, and recompute basic faces for frame F. Call
816 this after changing frame parameters on which those faces depend,
817 or when realized faces have been freed due to changing attributes
818 of named faces. */
820 void
821 recompute_basic_faces (struct frame *f)
823 if (FRAME_FACE_CACHE (f))
825 clear_face_cache (0);
826 if (!realize_basic_faces (f))
827 abort ();
832 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
833 try to free unused fonts, too. */
835 void
836 clear_face_cache (int clear_fonts_p)
838 #ifdef HAVE_WINDOW_SYSTEM
839 Lisp_Object tail, frame;
841 if (clear_fonts_p
842 || ++clear_font_table_count == CLEAR_FONT_TABLE_COUNT)
844 #if 0
845 /* Not yet implemented. */
846 clear_font_cache (frame);
847 #endif
849 /* From time to time see if we can unload some fonts. This also
850 frees all realized faces on all frames. Fonts needed by
851 faces will be loaded again when faces are realized again. */
852 clear_font_table_count = 0;
854 FOR_EACH_FRAME (tail, frame)
856 struct frame *f = XFRAME (frame);
857 if (FRAME_WINDOW_P (f)
858 && FRAME_X_DISPLAY_INFO (f)->n_fonts > CLEAR_FONT_TABLE_NFONTS)
859 free_all_realized_faces (frame);
862 else
864 /* Clear GCs of realized faces. */
865 FOR_EACH_FRAME (tail, frame)
867 struct frame *f = XFRAME (frame);
868 if (FRAME_WINDOW_P (f))
869 clear_face_gcs (FRAME_FACE_CACHE (f));
871 clear_image_caches (Qnil);
873 #endif /* HAVE_WINDOW_SYSTEM */
877 DEFUN ("clear-face-cache", Fclear_face_cache, Sclear_face_cache, 0, 1, 0,
878 doc: /* Clear face caches on all frames.
879 Optional THOROUGHLY non-nil means try to free unused fonts, too. */)
880 (Lisp_Object thoroughly)
882 clear_face_cache (!NILP (thoroughly));
883 ++face_change_count;
884 ++windows_or_buffers_changed;
885 return Qnil;
889 /***********************************************************************
890 X Pixmaps
891 ***********************************************************************/
893 #ifdef HAVE_WINDOW_SYSTEM
895 DEFUN ("bitmap-spec-p", Fbitmap_spec_p, Sbitmap_spec_p, 1, 1, 0,
896 doc: /* Value is non-nil if OBJECT is a valid bitmap specification.
897 A bitmap specification is either a string, a file name, or a list
898 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
899 HEIGHT is its height, and DATA is a string containing the bits of
900 the pixmap. Bits are stored row by row, each row occupies
901 \(WIDTH + 7)/8 bytes. */)
902 (Lisp_Object object)
904 int pixmap_p = 0;
906 if (STRINGP (object))
907 /* If OBJECT is a string, it's a file name. */
908 pixmap_p = 1;
909 else if (CONSP (object))
911 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
912 HEIGHT must be integers > 0, and DATA must be string large
913 enough to hold a bitmap of the specified size. */
914 Lisp_Object width, height, data;
916 height = width = data = Qnil;
918 if (CONSP (object))
920 width = XCAR (object);
921 object = XCDR (object);
922 if (CONSP (object))
924 height = XCAR (object);
925 object = XCDR (object);
926 if (CONSP (object))
927 data = XCAR (object);
931 if (NATNUMP (width) && NATNUMP (height) && STRINGP (data))
933 int bytes_per_row = ((XFASTINT (width) + BITS_PER_CHAR - 1)
934 / BITS_PER_CHAR);
935 if (SBYTES (data) >= bytes_per_row * XINT (height))
936 pixmap_p = 1;
940 return pixmap_p ? Qt : Qnil;
944 /* Load a bitmap according to NAME (which is either a file name or a
945 pixmap spec) for use on frame F. Value is the bitmap_id (see
946 xfns.c). If NAME is nil, return with a bitmap id of zero. If
947 bitmap cannot be loaded, display a message saying so, and return
948 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
949 if these pointers are not null. */
951 static int
952 load_pixmap (FRAME_PTR f, Lisp_Object name, unsigned int *w_ptr, unsigned int *h_ptr)
954 int bitmap_id;
956 if (NILP (name))
957 return 0;
959 CHECK_TYPE (!NILP (Fbitmap_spec_p (name)), Qbitmap_spec_p, name);
961 BLOCK_INPUT;
962 if (CONSP (name))
964 /* Decode a bitmap spec into a bitmap. */
966 int h, w;
967 Lisp_Object bits;
969 w = XINT (Fcar (name));
970 h = XINT (Fcar (Fcdr (name)));
971 bits = Fcar (Fcdr (Fcdr (name)));
973 bitmap_id = x_create_bitmap_from_data (f, SSDATA (bits),
974 w, h);
976 else
978 /* It must be a string -- a file name. */
979 bitmap_id = x_create_bitmap_from_file (f, name);
981 UNBLOCK_INPUT;
983 if (bitmap_id < 0)
985 add_to_log ("Invalid or undefined bitmap `%s'", name, Qnil);
986 bitmap_id = 0;
988 if (w_ptr)
989 *w_ptr = 0;
990 if (h_ptr)
991 *h_ptr = 0;
993 else
995 #if GLYPH_DEBUG
996 ++npixmaps_allocated;
997 #endif
998 if (w_ptr)
999 *w_ptr = x_bitmap_width (f, bitmap_id);
1001 if (h_ptr)
1002 *h_ptr = x_bitmap_height (f, bitmap_id);
1005 return bitmap_id;
1008 #endif /* HAVE_WINDOW_SYSTEM */
1012 /***********************************************************************
1013 X Colors
1014 ***********************************************************************/
1016 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
1017 RGB_LIST should contain (at least) 3 lisp integers.
1018 Return 0 if there's a problem with RGB_LIST, otherwise return 1. */
1020 static int
1021 parse_rgb_list (Lisp_Object rgb_list, XColor *color)
1023 #define PARSE_RGB_LIST_FIELD(field) \
1024 if (CONSP (rgb_list) && INTEGERP (XCAR (rgb_list))) \
1026 color->field = XINT (XCAR (rgb_list)); \
1027 rgb_list = XCDR (rgb_list); \
1029 else \
1030 return 0;
1032 PARSE_RGB_LIST_FIELD (red);
1033 PARSE_RGB_LIST_FIELD (green);
1034 PARSE_RGB_LIST_FIELD (blue);
1036 return 1;
1040 /* Lookup on frame F the color described by the lisp string COLOR.
1041 The resulting tty color is returned in TTY_COLOR; if STD_COLOR is
1042 non-zero, then the `standard' definition of the same color is
1043 returned in it. */
1045 static int
1046 tty_lookup_color (struct frame *f, Lisp_Object color, XColor *tty_color, XColor *std_color)
1048 Lisp_Object frame, color_desc;
1050 if (!STRINGP (color) || NILP (Ffboundp (Qtty_color_desc)))
1051 return 0;
1053 XSETFRAME (frame, f);
1055 color_desc = call2 (Qtty_color_desc, color, frame);
1056 if (CONSP (color_desc) && CONSP (XCDR (color_desc)))
1058 Lisp_Object rgb;
1060 if (! INTEGERP (XCAR (XCDR (color_desc))))
1061 return 0;
1063 tty_color->pixel = XINT (XCAR (XCDR (color_desc)));
1065 rgb = XCDR (XCDR (color_desc));
1066 if (! parse_rgb_list (rgb, tty_color))
1067 return 0;
1069 /* Should we fill in STD_COLOR too? */
1070 if (std_color)
1072 /* Default STD_COLOR to the same as TTY_COLOR. */
1073 *std_color = *tty_color;
1075 /* Do a quick check to see if the returned descriptor is
1076 actually _exactly_ equal to COLOR, otherwise we have to
1077 lookup STD_COLOR separately. If it's impossible to lookup
1078 a standard color, we just give up and use TTY_COLOR. */
1079 if ((!STRINGP (XCAR (color_desc))
1080 || NILP (Fstring_equal (color, XCAR (color_desc))))
1081 && !NILP (Ffboundp (Qtty_color_standard_values)))
1083 /* Look up STD_COLOR separately. */
1084 rgb = call1 (Qtty_color_standard_values, color);
1085 if (! parse_rgb_list (rgb, std_color))
1086 return 0;
1090 return 1;
1092 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
1093 /* We were called early during startup, and the colors are not
1094 yet set up in tty-defined-color-alist. Don't return a failure
1095 indication, since this produces the annoying "Unable to
1096 load color" messages in the *Messages* buffer. */
1097 return 1;
1098 else
1099 /* tty-color-desc seems to have returned a bad value. */
1100 return 0;
1103 /* A version of defined_color for non-X frames. */
1105 static int
1106 tty_defined_color (struct frame *f, const char *color_name,
1107 XColor *color_def, int alloc)
1109 int status = 1;
1111 /* Defaults. */
1112 color_def->pixel = FACE_TTY_DEFAULT_COLOR;
1113 color_def->red = 0;
1114 color_def->blue = 0;
1115 color_def->green = 0;
1117 if (*color_name)
1118 status = tty_lookup_color (f, build_string (color_name), color_def, NULL);
1120 if (color_def->pixel == FACE_TTY_DEFAULT_COLOR && *color_name)
1122 if (strcmp (color_name, "unspecified-fg") == 0)
1123 color_def->pixel = FACE_TTY_DEFAULT_FG_COLOR;
1124 else if (strcmp (color_name, "unspecified-bg") == 0)
1125 color_def->pixel = FACE_TTY_DEFAULT_BG_COLOR;
1128 if (color_def->pixel != FACE_TTY_DEFAULT_COLOR)
1129 status = 1;
1131 return status;
1135 /* Decide if color named COLOR_NAME is valid for the display
1136 associated with the frame F; if so, return the rgb values in
1137 COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell.
1139 This does the right thing for any type of frame. */
1142 defined_color (struct frame *f, const char *color_name, XColor *color_def, int alloc)
1144 if (!FRAME_WINDOW_P (f))
1145 return tty_defined_color (f, color_name, color_def, alloc);
1146 #ifdef HAVE_X_WINDOWS
1147 else if (FRAME_X_P (f))
1148 return x_defined_color (f, color_name, color_def, alloc);
1149 #endif
1150 #ifdef WINDOWSNT
1151 else if (FRAME_W32_P (f))
1152 return w32_defined_color (f, color_name, color_def, alloc);
1153 #endif
1154 #ifdef HAVE_NS
1155 else if (FRAME_NS_P (f))
1156 return ns_defined_color (f, color_name, color_def, alloc, 1);
1157 #endif
1158 else
1159 abort ();
1163 /* Given the index IDX of a tty color on frame F, return its name, a
1164 Lisp string. */
1166 Lisp_Object
1167 tty_color_name (struct frame *f, int idx)
1169 if (idx >= 0 && !NILP (Ffboundp (Qtty_color_by_index)))
1171 Lisp_Object frame;
1172 Lisp_Object coldesc;
1174 XSETFRAME (frame, f);
1175 coldesc = call2 (Qtty_color_by_index, make_number (idx), frame);
1177 if (!NILP (coldesc))
1178 return XCAR (coldesc);
1180 #ifdef MSDOS
1181 /* We can have an MSDOG frame under -nw for a short window of
1182 opportunity before internal_terminal_init is called. DTRT. */
1183 if (FRAME_MSDOS_P (f) && !inhibit_window_system)
1184 return msdos_stdcolor_name (idx);
1185 #endif
1187 if (idx == FACE_TTY_DEFAULT_FG_COLOR)
1188 return build_string (unspecified_fg);
1189 if (idx == FACE_TTY_DEFAULT_BG_COLOR)
1190 return build_string (unspecified_bg);
1192 return Qunspecified;
1196 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1197 black) on frame F.
1199 The criterion implemented here is not a terribly sophisticated one. */
1201 static int
1202 face_color_gray_p (struct frame *f, const char *color_name)
1204 XColor color;
1205 int gray_p;
1207 if (defined_color (f, color_name, &color, 0))
1208 gray_p = (/* Any color sufficiently close to black counts as grey. */
1209 (color.red < 5000 && color.green < 5000 && color.blue < 5000)
1211 ((eabs (color.red - color.green)
1212 < max (color.red, color.green) / 20)
1213 && (eabs (color.green - color.blue)
1214 < max (color.green, color.blue) / 20)
1215 && (eabs (color.blue - color.red)
1216 < max (color.blue, color.red) / 20)));
1217 else
1218 gray_p = 0;
1220 return gray_p;
1224 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1225 BACKGROUND_P non-zero means the color will be used as background
1226 color. */
1228 static int
1229 face_color_supported_p (struct frame *f, const char *color_name, int background_p)
1231 Lisp_Object frame;
1232 XColor not_used;
1234 XSETFRAME (frame, f);
1235 return
1236 #ifdef HAVE_WINDOW_SYSTEM
1237 FRAME_WINDOW_P (f)
1238 ? (!NILP (Fxw_display_color_p (frame))
1239 || xstrcasecmp (color_name, "black") == 0
1240 || xstrcasecmp (color_name, "white") == 0
1241 || (background_p
1242 && face_color_gray_p (f, color_name))
1243 || (!NILP (Fx_display_grayscale_p (frame))
1244 && face_color_gray_p (f, color_name)))
1246 #endif
1247 tty_defined_color (f, color_name, &not_used, 0);
1251 DEFUN ("color-gray-p", Fcolor_gray_p, Scolor_gray_p, 1, 2, 0,
1252 doc: /* Return non-nil if COLOR is a shade of gray (or white or black).
1253 FRAME specifies the frame and thus the display for interpreting COLOR.
1254 If FRAME is nil or omitted, use the selected frame. */)
1255 (Lisp_Object color, Lisp_Object frame)
1257 struct frame *f;
1259 CHECK_STRING (color);
1260 if (NILP (frame))
1261 frame = selected_frame;
1262 else
1263 CHECK_FRAME (frame);
1264 f = XFRAME (frame);
1265 return face_color_gray_p (f, SSDATA (color)) ? Qt : Qnil;
1269 DEFUN ("color-supported-p", Fcolor_supported_p,
1270 Scolor_supported_p, 1, 3, 0,
1271 doc: /* Return non-nil if COLOR can be displayed on FRAME.
1272 BACKGROUND-P non-nil means COLOR is used as a background.
1273 Otherwise, this function tells whether it can be used as a foreground.
1274 If FRAME is nil or omitted, use the selected frame.
1275 COLOR must be a valid color name. */)
1276 (Lisp_Object color, Lisp_Object frame, Lisp_Object background_p)
1278 struct frame *f;
1280 CHECK_STRING (color);
1281 if (NILP (frame))
1282 frame = selected_frame;
1283 else
1284 CHECK_FRAME (frame);
1285 f = XFRAME (frame);
1286 if (face_color_supported_p (f, SSDATA (color), !NILP (background_p)))
1287 return Qt;
1288 return Qnil;
1292 /* Load color with name NAME for use by face FACE on frame F.
1293 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1294 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1295 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1296 pixel color. If color cannot be loaded, display a message, and
1297 return the foreground, background or underline color of F, but
1298 record that fact in flags of the face so that we don't try to free
1299 these colors. */
1301 unsigned long
1302 load_color (struct frame *f, struct face *face, Lisp_Object name, enum lface_attribute_index target_index)
1304 XColor color;
1306 xassert (STRINGP (name));
1307 xassert (target_index == LFACE_FOREGROUND_INDEX
1308 || target_index == LFACE_BACKGROUND_INDEX
1309 || target_index == LFACE_UNDERLINE_INDEX
1310 || target_index == LFACE_OVERLINE_INDEX
1311 || target_index == LFACE_STRIKE_THROUGH_INDEX
1312 || target_index == LFACE_BOX_INDEX);
1314 /* if the color map is full, defined_color will return a best match
1315 to the values in an existing cell. */
1316 if (!defined_color (f, SSDATA (name), &color, 1))
1318 add_to_log ("Unable to load color \"%s\"", name, Qnil);
1320 switch (target_index)
1322 case LFACE_FOREGROUND_INDEX:
1323 face->foreground_defaulted_p = 1;
1324 color.pixel = FRAME_FOREGROUND_PIXEL (f);
1325 break;
1327 case LFACE_BACKGROUND_INDEX:
1328 face->background_defaulted_p = 1;
1329 color.pixel = FRAME_BACKGROUND_PIXEL (f);
1330 break;
1332 case LFACE_UNDERLINE_INDEX:
1333 face->underline_defaulted_p = 1;
1334 color.pixel = FRAME_FOREGROUND_PIXEL (f);
1335 break;
1337 case LFACE_OVERLINE_INDEX:
1338 face->overline_color_defaulted_p = 1;
1339 color.pixel = FRAME_FOREGROUND_PIXEL (f);
1340 break;
1342 case LFACE_STRIKE_THROUGH_INDEX:
1343 face->strike_through_color_defaulted_p = 1;
1344 color.pixel = FRAME_FOREGROUND_PIXEL (f);
1345 break;
1347 case LFACE_BOX_INDEX:
1348 face->box_color_defaulted_p = 1;
1349 color.pixel = FRAME_FOREGROUND_PIXEL (f);
1350 break;
1352 default:
1353 abort ();
1356 #if GLYPH_DEBUG
1357 else
1358 ++ncolors_allocated;
1359 #endif
1361 return color.pixel;
1365 #ifdef HAVE_WINDOW_SYSTEM
1367 /* Load colors for face FACE which is used on frame F. Colors are
1368 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1369 of ATTRS. If the background color specified is not supported on F,
1370 try to emulate gray colors with a stipple from Vface_default_stipple. */
1372 static void
1373 load_face_colors (struct frame *f, struct face *face, Lisp_Object *attrs)
1375 Lisp_Object fg, bg;
1377 bg = attrs[LFACE_BACKGROUND_INDEX];
1378 fg = attrs[LFACE_FOREGROUND_INDEX];
1380 /* Swap colors if face is inverse-video. */
1381 if (EQ (attrs[LFACE_INVERSE_INDEX], Qt))
1383 Lisp_Object tmp;
1384 tmp = fg;
1385 fg = bg;
1386 bg = tmp;
1389 /* Check for support for foreground, not for background because
1390 face_color_supported_p is smart enough to know that grays are
1391 "supported" as background because we are supposed to use stipple
1392 for them. */
1393 if (!face_color_supported_p (f, SSDATA (bg), 0)
1394 && !NILP (Fbitmap_spec_p (Vface_default_stipple)))
1396 x_destroy_bitmap (f, face->stipple);
1397 face->stipple = load_pixmap (f, Vface_default_stipple,
1398 &face->pixmap_w, &face->pixmap_h);
1401 face->background = load_color (f, face, bg, LFACE_BACKGROUND_INDEX);
1402 face->foreground = load_color (f, face, fg, LFACE_FOREGROUND_INDEX);
1406 /* Free color PIXEL on frame F. */
1408 void
1409 unload_color (struct frame *f, long unsigned int pixel)
1411 #ifdef HAVE_X_WINDOWS
1412 if (pixel != -1)
1414 BLOCK_INPUT;
1415 x_free_colors (f, &pixel, 1);
1416 UNBLOCK_INPUT;
1418 #endif
1422 /* Free colors allocated for FACE. */
1424 static void
1425 free_face_colors (struct frame *f, struct face *face)
1427 /* PENDING(NS): need to do something here? */
1428 #ifdef HAVE_X_WINDOWS
1429 if (face->colors_copied_bitwise_p)
1430 return;
1432 BLOCK_INPUT;
1434 if (!face->foreground_defaulted_p)
1436 x_free_colors (f, &face->foreground, 1);
1437 IF_DEBUG (--ncolors_allocated);
1440 if (!face->background_defaulted_p)
1442 x_free_colors (f, &face->background, 1);
1443 IF_DEBUG (--ncolors_allocated);
1446 if (face->underline_p
1447 && !face->underline_defaulted_p)
1449 x_free_colors (f, &face->underline_color, 1);
1450 IF_DEBUG (--ncolors_allocated);
1453 if (face->overline_p
1454 && !face->overline_color_defaulted_p)
1456 x_free_colors (f, &face->overline_color, 1);
1457 IF_DEBUG (--ncolors_allocated);
1460 if (face->strike_through_p
1461 && !face->strike_through_color_defaulted_p)
1463 x_free_colors (f, &face->strike_through_color, 1);
1464 IF_DEBUG (--ncolors_allocated);
1467 if (face->box != FACE_NO_BOX
1468 && !face->box_color_defaulted_p)
1470 x_free_colors (f, &face->box_color, 1);
1471 IF_DEBUG (--ncolors_allocated);
1474 UNBLOCK_INPUT;
1475 #endif /* HAVE_X_WINDOWS */
1478 #endif /* HAVE_WINDOW_SYSTEM */
1482 /***********************************************************************
1483 XLFD Font Names
1484 ***********************************************************************/
1486 /* An enumerator for each field of an XLFD font name. */
1488 enum xlfd_field
1490 XLFD_FOUNDRY,
1491 XLFD_FAMILY,
1492 XLFD_WEIGHT,
1493 XLFD_SLANT,
1494 XLFD_SWIDTH,
1495 XLFD_ADSTYLE,
1496 XLFD_PIXEL_SIZE,
1497 XLFD_POINT_SIZE,
1498 XLFD_RESX,
1499 XLFD_RESY,
1500 XLFD_SPACING,
1501 XLFD_AVGWIDTH,
1502 XLFD_REGISTRY,
1503 XLFD_ENCODING,
1504 XLFD_LAST
1507 /* An enumerator for each possible slant value of a font. Taken from
1508 the XLFD specification. */
1510 enum xlfd_slant
1512 XLFD_SLANT_UNKNOWN,
1513 XLFD_SLANT_ROMAN,
1514 XLFD_SLANT_ITALIC,
1515 XLFD_SLANT_OBLIQUE,
1516 XLFD_SLANT_REVERSE_ITALIC,
1517 XLFD_SLANT_REVERSE_OBLIQUE,
1518 XLFD_SLANT_OTHER
1521 /* Relative font weight according to XLFD documentation. */
1523 enum xlfd_weight
1525 XLFD_WEIGHT_UNKNOWN,
1526 XLFD_WEIGHT_ULTRA_LIGHT, /* 10 */
1527 XLFD_WEIGHT_EXTRA_LIGHT, /* 20 */
1528 XLFD_WEIGHT_LIGHT, /* 30 */
1529 XLFD_WEIGHT_SEMI_LIGHT, /* 40: SemiLight, Book, ... */
1530 XLFD_WEIGHT_MEDIUM, /* 50: Medium, Normal, Regular, ... */
1531 XLFD_WEIGHT_SEMI_BOLD, /* 60: SemiBold, DemiBold, ... */
1532 XLFD_WEIGHT_BOLD, /* 70: Bold, ... */
1533 XLFD_WEIGHT_EXTRA_BOLD, /* 80: ExtraBold, Heavy, ... */
1534 XLFD_WEIGHT_ULTRA_BOLD /* 90: UltraBold, Black, ... */
1537 /* Relative proportionate width. */
1539 enum xlfd_swidth
1541 XLFD_SWIDTH_UNKNOWN,
1542 XLFD_SWIDTH_ULTRA_CONDENSED, /* 10 */
1543 XLFD_SWIDTH_EXTRA_CONDENSED, /* 20 */
1544 XLFD_SWIDTH_CONDENSED, /* 30: Condensed, Narrow, Compressed, ... */
1545 XLFD_SWIDTH_SEMI_CONDENSED, /* 40: semicondensed */
1546 XLFD_SWIDTH_MEDIUM, /* 50: Medium, Normal, Regular, ... */
1547 XLFD_SWIDTH_SEMI_EXPANDED, /* 60: SemiExpanded, DemiExpanded, ... */
1548 XLFD_SWIDTH_EXPANDED, /* 70: Expanded... */
1549 XLFD_SWIDTH_EXTRA_EXPANDED, /* 80: ExtraExpanded, Wide... */
1550 XLFD_SWIDTH_ULTRA_EXPANDED /* 90: UltraExpanded... */
1553 /* Order by which font selection chooses fonts. The default values
1554 mean `first, find a best match for the font width, then for the
1555 font height, then for weight, then for slant.' This variable can be
1556 set via set-face-font-sort-order. */
1558 static int font_sort_order[4];
1560 #ifdef HAVE_WINDOW_SYSTEM
1562 static enum font_property_index font_props_for_sorting[FONT_SIZE_INDEX];
1564 static int
1565 compare_fonts_by_sort_order (const void *v1, const void *v2)
1567 Lisp_Object font1 = *(Lisp_Object *) v1;
1568 Lisp_Object font2 = *(Lisp_Object *) v2;
1569 int i;
1571 for (i = 0; i < FONT_SIZE_INDEX; i++)
1573 enum font_property_index idx = font_props_for_sorting[i];
1574 Lisp_Object val1 = AREF (font1, idx), val2 = AREF (font2, idx);
1575 int result;
1577 if (idx <= FONT_REGISTRY_INDEX)
1579 if (STRINGP (val1))
1580 result = STRINGP (val2) ? strcmp (SSDATA (val1), SSDATA (val2)) : -1;
1581 else
1582 result = STRINGP (val2) ? 1 : 0;
1584 else
1586 if (INTEGERP (val1))
1587 result = INTEGERP (val2) ? XINT (val1) - XINT (val2) : -1;
1588 else
1589 result = INTEGERP (val2) ? 1 : 0;
1591 if (result)
1592 return result;
1594 return 0;
1597 DEFUN ("x-family-fonts", Fx_family_fonts, Sx_family_fonts, 0, 2, 0,
1598 doc: /* Return a list of available fonts of family FAMILY on FRAME.
1599 If FAMILY is omitted or nil, list all families.
1600 Otherwise, FAMILY must be a string, possibly containing wildcards
1601 `?' and `*'.
1602 If FRAME is omitted or nil, use the selected frame.
1603 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
1604 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
1605 FAMILY is the font family name. POINT-SIZE is the size of the
1606 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
1607 width, weight and slant of the font. These symbols are the same as for
1608 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
1609 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
1610 giving the registry and encoding of the font.
1611 The result list is sorted according to the current setting of
1612 the face font sort order. */)
1613 (Lisp_Object family, Lisp_Object frame)
1615 Lisp_Object font_spec, list, *drivers, vec;
1616 int i, nfonts, ndrivers;
1617 Lisp_Object result;
1619 if (NILP (frame))
1620 frame = selected_frame;
1621 CHECK_LIVE_FRAME (frame);
1623 font_spec = Ffont_spec (0, NULL);
1624 if (!NILP (family))
1626 CHECK_STRING (family);
1627 font_parse_family_registry (family, Qnil, font_spec);
1630 list = font_list_entities (frame, font_spec);
1631 if (NILP (list))
1632 return Qnil;
1634 /* Sort the font entities. */
1635 for (i = 0; i < 4; i++)
1636 switch (font_sort_order[i])
1638 case XLFD_SWIDTH:
1639 font_props_for_sorting[i] = FONT_WIDTH_INDEX; break;
1640 case XLFD_POINT_SIZE:
1641 font_props_for_sorting[i] = FONT_SIZE_INDEX; break;
1642 case XLFD_WEIGHT:
1643 font_props_for_sorting[i] = FONT_WEIGHT_INDEX; break;
1644 default:
1645 font_props_for_sorting[i] = FONT_SLANT_INDEX; break;
1647 font_props_for_sorting[i++] = FONT_FAMILY_INDEX;
1648 font_props_for_sorting[i++] = FONT_FOUNDRY_INDEX;
1649 font_props_for_sorting[i++] = FONT_ADSTYLE_INDEX;
1650 font_props_for_sorting[i++] = FONT_REGISTRY_INDEX;
1652 ndrivers = XINT (Flength (list));
1653 drivers = alloca (sizeof (Lisp_Object) * ndrivers);
1654 for (i = 0; i < ndrivers; i++, list = XCDR (list))
1655 drivers[i] = XCAR (list);
1656 vec = Fvconcat (ndrivers, drivers);
1657 nfonts = ASIZE (vec);
1659 qsort (XVECTOR (vec)->contents, nfonts, sizeof (Lisp_Object),
1660 compare_fonts_by_sort_order);
1662 result = Qnil;
1663 for (i = nfonts - 1; i >= 0; --i)
1665 Lisp_Object font = AREF (vec, i);
1666 Lisp_Object v = Fmake_vector (make_number (8), Qnil);
1667 int point;
1668 Lisp_Object spacing;
1670 ASET (v, 0, AREF (font, FONT_FAMILY_INDEX));
1671 ASET (v, 1, FONT_WIDTH_SYMBOLIC (font));
1672 point = PIXEL_TO_POINT (XINT (AREF (font, FONT_SIZE_INDEX)) * 10,
1673 XFRAME (frame)->resy);
1674 ASET (v, 2, make_number (point));
1675 ASET (v, 3, FONT_WEIGHT_SYMBOLIC (font));
1676 ASET (v, 4, FONT_SLANT_SYMBOLIC (font));
1677 spacing = Ffont_get (font, QCspacing);
1678 ASET (v, 5, (NILP (spacing) || EQ (spacing, Qp)) ? Qnil : Qt);
1679 ASET (v, 6, Ffont_xlfd_name (font, Qnil));
1680 ASET (v, 7, AREF (font, FONT_REGISTRY_INDEX));
1682 result = Fcons (v, result);
1685 return result;
1688 DEFUN ("x-list-fonts", Fx_list_fonts, Sx_list_fonts, 1, 5, 0,
1689 doc: /* Return a list of the names of available fonts matching PATTERN.
1690 If optional arguments FACE and FRAME are specified, return only fonts
1691 the same size as FACE on FRAME.
1693 PATTERN should be a string containing a font name in the XLFD,
1694 Fontconfig, or GTK format. A font name given in the XLFD format may
1695 contain wildcard characters:
1696 the * character matches any substring, and
1697 the ? character matches any single character.
1698 PATTERN is case-insensitive.
1700 The return value is a list of strings, suitable as arguments to
1701 `set-face-font'.
1703 Fonts Emacs can't use may or may not be excluded
1704 even if they match PATTERN and FACE.
1705 The optional fourth argument MAXIMUM sets a limit on how many
1706 fonts to match. The first MAXIMUM fonts are reported.
1707 The optional fifth argument WIDTH, if specified, is a number of columns
1708 occupied by a character of a font. In that case, return only fonts
1709 the WIDTH times as wide as FACE on FRAME. */)
1710 (Lisp_Object pattern, Lisp_Object face, Lisp_Object frame, Lisp_Object maximum, Lisp_Object width)
1712 struct frame *f;
1713 int size, avgwidth IF_LINT (= 0);
1715 check_x ();
1716 CHECK_STRING (pattern);
1718 if (! NILP (maximum))
1719 CHECK_NATNUM (maximum);
1721 if (!NILP (width))
1722 CHECK_NUMBER (width);
1724 /* We can't simply call check_x_frame because this function may be
1725 called before any frame is created. */
1726 if (NILP (frame))
1727 frame = selected_frame;
1728 f = frame_or_selected_frame (frame, 2);
1729 if (! FRAME_WINDOW_P (f))
1731 /* Perhaps we have not yet created any frame. */
1732 f = NULL;
1733 frame = Qnil;
1734 face = Qnil;
1737 /* Determine the width standard for comparison with the fonts we find. */
1739 if (NILP (face))
1740 size = 0;
1741 else
1743 /* This is of limited utility since it works with character
1744 widths. Keep it for compatibility. --gerd. */
1745 int face_id = lookup_named_face (f, face, 0);
1746 struct face *width_face = (face_id < 0
1747 ? NULL
1748 : FACE_FROM_ID (f, face_id));
1750 if (width_face && width_face->font)
1752 size = width_face->font->pixel_size;
1753 avgwidth = width_face->font->average_width;
1755 else
1757 size = FRAME_FONT (f)->pixel_size;
1758 avgwidth = FRAME_FONT (f)->average_width;
1760 if (!NILP (width))
1761 avgwidth *= XINT (width);
1765 Lisp_Object font_spec;
1766 Lisp_Object args[2], tail;
1768 font_spec = font_spec_from_name (pattern);
1769 if (!FONTP (font_spec))
1770 signal_error ("Invalid font name", pattern);
1772 if (size)
1774 Ffont_put (font_spec, QCsize, make_number (size));
1775 Ffont_put (font_spec, QCavgwidth, make_number (avgwidth));
1777 args[0] = Flist_fonts (font_spec, frame, maximum, font_spec);
1778 for (tail = args[0]; CONSP (tail); tail = XCDR (tail))
1780 Lisp_Object font_entity;
1782 font_entity = XCAR (tail);
1783 if ((NILP (AREF (font_entity, FONT_SIZE_INDEX))
1784 || XINT (AREF (font_entity, FONT_SIZE_INDEX)) == 0)
1785 && ! NILP (AREF (font_spec, FONT_SIZE_INDEX)))
1787 /* This is a scalable font. For backward compatibility,
1788 we set the specified size. */
1789 font_entity = Fcopy_font_spec (font_entity);
1790 ASET (font_entity, FONT_SIZE_INDEX,
1791 AREF (font_spec, FONT_SIZE_INDEX));
1793 XSETCAR (tail, Ffont_xlfd_name (font_entity, Qnil));
1795 if (NILP (frame))
1796 /* We don't have to check fontsets. */
1797 return args[0];
1798 args[1] = list_fontsets (f, pattern, size);
1799 return Fnconc (2, args);
1803 #endif /* HAVE_WINDOW_SYSTEM */
1806 /***********************************************************************
1807 Lisp Faces
1808 ***********************************************************************/
1810 /* Access face attributes of face LFACE, a Lisp vector. */
1812 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
1813 #define LFACE_FOUNDRY(LFACE) AREF ((LFACE), LFACE_FOUNDRY_INDEX)
1814 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
1815 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
1816 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
1817 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
1818 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
1819 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
1820 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
1821 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
1822 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
1823 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
1824 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
1825 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
1826 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
1827 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
1828 #define LFACE_FONTSET(LFACE) AREF ((LFACE), LFACE_FONTSET_INDEX)
1830 #if XASSERTS
1831 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
1832 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
1834 #define LFACEP(LFACE) \
1835 (VECTORP (LFACE) \
1836 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \
1837 && EQ (AREF (LFACE, 0), Qface))
1838 #endif
1841 #if GLYPH_DEBUG
1843 /* Check consistency of Lisp face attribute vector ATTRS. */
1845 static void
1846 check_lface_attrs (attrs)
1847 Lisp_Object *attrs;
1849 xassert (UNSPECIFIEDP (attrs[LFACE_FAMILY_INDEX])
1850 || IGNORE_DEFFACE_P (attrs[LFACE_FAMILY_INDEX])
1851 || STRINGP (attrs[LFACE_FAMILY_INDEX]));
1852 xassert (UNSPECIFIEDP (attrs[LFACE_FOUNDRY_INDEX])
1853 || IGNORE_DEFFACE_P (attrs[LFACE_FOUNDRY_INDEX])
1854 || STRINGP (attrs[LFACE_FOUNDRY_INDEX]));
1855 xassert (UNSPECIFIEDP (attrs[LFACE_SWIDTH_INDEX])
1856 || IGNORE_DEFFACE_P (attrs[LFACE_SWIDTH_INDEX])
1857 || SYMBOLP (attrs[LFACE_SWIDTH_INDEX]));
1858 xassert (UNSPECIFIEDP (attrs[LFACE_HEIGHT_INDEX])
1859 || IGNORE_DEFFACE_P (attrs[LFACE_HEIGHT_INDEX])
1860 || INTEGERP (attrs[LFACE_HEIGHT_INDEX])
1861 || FLOATP (attrs[LFACE_HEIGHT_INDEX])
1862 || FUNCTIONP (attrs[LFACE_HEIGHT_INDEX]));
1863 xassert (UNSPECIFIEDP (attrs[LFACE_WEIGHT_INDEX])
1864 || IGNORE_DEFFACE_P (attrs[LFACE_WEIGHT_INDEX])
1865 || SYMBOLP (attrs[LFACE_WEIGHT_INDEX]));
1866 xassert (UNSPECIFIEDP (attrs[LFACE_SLANT_INDEX])
1867 || IGNORE_DEFFACE_P (attrs[LFACE_SLANT_INDEX])
1868 || SYMBOLP (attrs[LFACE_SLANT_INDEX]));
1869 xassert (UNSPECIFIEDP (attrs[LFACE_UNDERLINE_INDEX])
1870 || IGNORE_DEFFACE_P (attrs[LFACE_UNDERLINE_INDEX])
1871 || SYMBOLP (attrs[LFACE_UNDERLINE_INDEX])
1872 || STRINGP (attrs[LFACE_UNDERLINE_INDEX]));
1873 xassert (UNSPECIFIEDP (attrs[LFACE_OVERLINE_INDEX])
1874 || IGNORE_DEFFACE_P (attrs[LFACE_OVERLINE_INDEX])
1875 || SYMBOLP (attrs[LFACE_OVERLINE_INDEX])
1876 || STRINGP (attrs[LFACE_OVERLINE_INDEX]));
1877 xassert (UNSPECIFIEDP (attrs[LFACE_STRIKE_THROUGH_INDEX])
1878 || IGNORE_DEFFACE_P (attrs[LFACE_STRIKE_THROUGH_INDEX])
1879 || SYMBOLP (attrs[LFACE_STRIKE_THROUGH_INDEX])
1880 || STRINGP (attrs[LFACE_STRIKE_THROUGH_INDEX]));
1881 xassert (UNSPECIFIEDP (attrs[LFACE_BOX_INDEX])
1882 || IGNORE_DEFFACE_P (attrs[LFACE_BOX_INDEX])
1883 || SYMBOLP (attrs[LFACE_BOX_INDEX])
1884 || STRINGP (attrs[LFACE_BOX_INDEX])
1885 || INTEGERP (attrs[LFACE_BOX_INDEX])
1886 || CONSP (attrs[LFACE_BOX_INDEX]));
1887 xassert (UNSPECIFIEDP (attrs[LFACE_INVERSE_INDEX])
1888 || IGNORE_DEFFACE_P (attrs[LFACE_INVERSE_INDEX])
1889 || SYMBOLP (attrs[LFACE_INVERSE_INDEX]));
1890 xassert (UNSPECIFIEDP (attrs[LFACE_FOREGROUND_INDEX])
1891 || IGNORE_DEFFACE_P (attrs[LFACE_FOREGROUND_INDEX])
1892 || STRINGP (attrs[LFACE_FOREGROUND_INDEX]));
1893 xassert (UNSPECIFIEDP (attrs[LFACE_BACKGROUND_INDEX])
1894 || IGNORE_DEFFACE_P (attrs[LFACE_BACKGROUND_INDEX])
1895 || STRINGP (attrs[LFACE_BACKGROUND_INDEX]));
1896 xassert (UNSPECIFIEDP (attrs[LFACE_INHERIT_INDEX])
1897 || IGNORE_DEFFACE_P (attrs[LFACE_INHERIT_INDEX])
1898 || NILP (attrs[LFACE_INHERIT_INDEX])
1899 || SYMBOLP (attrs[LFACE_INHERIT_INDEX])
1900 || CONSP (attrs[LFACE_INHERIT_INDEX]));
1901 #ifdef HAVE_WINDOW_SYSTEM
1902 xassert (UNSPECIFIEDP (attrs[LFACE_STIPPLE_INDEX])
1903 || IGNORE_DEFFACE_P (attrs[LFACE_STIPPLE_INDEX])
1904 || SYMBOLP (attrs[LFACE_STIPPLE_INDEX])
1905 || !NILP (Fbitmap_spec_p (attrs[LFACE_STIPPLE_INDEX])));
1906 xassert (UNSPECIFIEDP (attrs[LFACE_FONT_INDEX])
1907 || IGNORE_DEFFACE_P (attrs[LFACE_FONT_INDEX])
1908 || FONTP (attrs[LFACE_FONT_INDEX]));
1909 xassert (UNSPECIFIEDP (attrs[LFACE_FONTSET_INDEX])
1910 || STRINGP (attrs[LFACE_FONTSET_INDEX]));
1911 #endif
1915 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
1917 static void
1918 check_lface (lface)
1919 Lisp_Object lface;
1921 if (!NILP (lface))
1923 xassert (LFACEP (lface));
1924 check_lface_attrs (XVECTOR (lface)->contents);
1928 #else /* GLYPH_DEBUG == 0 */
1930 #define check_lface_attrs(attrs) (void) 0
1931 #define check_lface(lface) (void) 0
1933 #endif /* GLYPH_DEBUG == 0 */
1937 /* Face-merge cycle checking. */
1939 enum named_merge_point_kind
1941 NAMED_MERGE_POINT_NORMAL,
1942 NAMED_MERGE_POINT_REMAP
1945 /* A `named merge point' is simply a point during face-merging where we
1946 look up a face by name. We keep a stack of which named lookups we're
1947 currently processing so that we can easily detect cycles, using a
1948 linked- list of struct named_merge_point structures, typically
1949 allocated on the stack frame of the named lookup functions which are
1950 active (so no consing is required). */
1951 struct named_merge_point
1953 Lisp_Object face_name;
1954 enum named_merge_point_kind named_merge_point_kind;
1955 struct named_merge_point *prev;
1959 /* If a face merging cycle is detected for FACE_NAME, return 0,
1960 otherwise add NEW_NAMED_MERGE_POINT, which is initialized using
1961 FACE_NAME and NAMED_MERGE_POINT_KIND, as the head of the linked list
1962 pointed to by NAMED_MERGE_POINTS, and return 1. */
1964 static INLINE int
1965 push_named_merge_point (struct named_merge_point *new_named_merge_point,
1966 Lisp_Object face_name,
1967 enum named_merge_point_kind named_merge_point_kind,
1968 struct named_merge_point **named_merge_points)
1970 struct named_merge_point *prev;
1972 for (prev = *named_merge_points; prev; prev = prev->prev)
1973 if (EQ (face_name, prev->face_name))
1975 if (prev->named_merge_point_kind == named_merge_point_kind)
1976 /* A cycle, so fail. */
1977 return 0;
1978 else if (prev->named_merge_point_kind == NAMED_MERGE_POINT_REMAP)
1979 /* A remap `hides ' any previous normal merge points
1980 (because the remap means that it's actually different face),
1981 so as we know the current merge point must be normal, we
1982 can just assume it's OK. */
1983 break;
1986 new_named_merge_point->face_name = face_name;
1987 new_named_merge_point->named_merge_point_kind = named_merge_point_kind;
1988 new_named_merge_point->prev = *named_merge_points;
1990 *named_merge_points = new_named_merge_point;
1992 return 1;
1997 #if 0 /* Seems to be unused. */
1998 static Lisp_Object
1999 internal_resolve_face_name (nargs, args)
2000 int nargs;
2001 Lisp_Object *args;
2003 return Fget (args[0], args[1]);
2006 static Lisp_Object
2007 resolve_face_name_error (ignore)
2008 Lisp_Object ignore;
2010 return Qnil;
2012 #endif
2014 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
2015 to make it a symbol. If FACE_NAME is an alias for another face,
2016 return that face's name.
2018 Return default face in case of errors. */
2020 static Lisp_Object
2021 resolve_face_name (Lisp_Object face_name, int signal_p)
2023 Lisp_Object orig_face;
2024 Lisp_Object tortoise, hare;
2026 if (STRINGP (face_name))
2027 face_name = intern (SSDATA (face_name));
2029 if (NILP (face_name) || !SYMBOLP (face_name))
2030 return face_name;
2032 orig_face = face_name;
2033 tortoise = hare = face_name;
2035 while (1)
2037 face_name = hare;
2038 hare = Fget (hare, Qface_alias);
2039 if (NILP (hare) || !SYMBOLP (hare))
2040 break;
2042 face_name = hare;
2043 hare = Fget (hare, Qface_alias);
2044 if (NILP (hare) || !SYMBOLP (hare))
2045 break;
2047 tortoise = Fget (tortoise, Qface_alias);
2048 if (EQ (hare, tortoise))
2050 if (signal_p)
2051 xsignal1 (Qcircular_list, orig_face);
2052 return Qdefault;
2056 return face_name;
2060 /* Return the face definition of FACE_NAME on frame F. F null means
2061 return the definition for new frames. FACE_NAME may be a string or
2062 a symbol (apparently Emacs 20.2 allowed strings as face names in
2063 face text properties; Ediff uses that). If SIGNAL_P is non-zero,
2064 signal an error if FACE_NAME is not a valid face name. If SIGNAL_P
2065 is zero, value is nil if FACE_NAME is not a valid face name. */
2066 static INLINE Lisp_Object
2067 lface_from_face_name_no_resolve (struct frame *f, Lisp_Object face_name, int signal_p)
2069 Lisp_Object lface;
2071 if (f)
2072 lface = assq_no_quit (face_name, f->face_alist);
2073 else
2074 lface = assq_no_quit (face_name, Vface_new_frame_defaults);
2076 if (CONSP (lface))
2077 lface = XCDR (lface);
2078 else if (signal_p)
2079 signal_error ("Invalid face", face_name);
2081 check_lface (lface);
2083 return lface;
2086 /* Return the face definition of FACE_NAME on frame F. F null means
2087 return the definition for new frames. FACE_NAME may be a string or
2088 a symbol (apparently Emacs 20.2 allowed strings as face names in
2089 face text properties; Ediff uses that). If FACE_NAME is an alias
2090 for another face, return that face's definition. If SIGNAL_P is
2091 non-zero, signal an error if FACE_NAME is not a valid face name.
2092 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
2093 name. */
2094 static INLINE Lisp_Object
2095 lface_from_face_name (struct frame *f, Lisp_Object face_name, int signal_p)
2097 face_name = resolve_face_name (face_name, signal_p);
2098 return lface_from_face_name_no_resolve (f, face_name, signal_p);
2102 /* Get face attributes of face FACE_NAME from frame-local faces on
2103 frame F. Store the resulting attributes in ATTRS which must point
2104 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
2105 is non-zero, signal an error if FACE_NAME does not name a face.
2106 Otherwise, value is zero if FACE_NAME is not a face. */
2108 static INLINE int
2109 get_lface_attributes_no_remap (struct frame *f, Lisp_Object face_name, Lisp_Object *attrs, int signal_p)
2111 Lisp_Object lface;
2113 lface = lface_from_face_name_no_resolve (f, face_name, signal_p);
2115 if (! NILP (lface))
2116 memcpy (attrs, XVECTOR (lface)->contents,
2117 LFACE_VECTOR_SIZE * sizeof *attrs);
2119 return !NILP (lface);
2122 /* Get face attributes of face FACE_NAME from frame-local faces on frame
2123 F. Store the resulting attributes in ATTRS which must point to a
2124 vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If FACE_NAME is an
2125 alias for another face, use that face's definition. If SIGNAL_P is
2126 non-zero, signal an error if FACE_NAME does not name a face.
2127 Otherwise, value is zero if FACE_NAME is not a face. */
2129 static INLINE int
2130 get_lface_attributes (struct frame *f, Lisp_Object face_name, Lisp_Object *attrs, int signal_p, struct named_merge_point *named_merge_points)
2132 Lisp_Object face_remapping;
2134 face_name = resolve_face_name (face_name, signal_p);
2136 /* See if SYMBOL has been remapped to some other face (usually this
2137 is done buffer-locally). */
2138 face_remapping = assq_no_quit (face_name, Vface_remapping_alist);
2139 if (CONSP (face_remapping))
2141 struct named_merge_point named_merge_point;
2143 if (push_named_merge_point (&named_merge_point,
2144 face_name, NAMED_MERGE_POINT_REMAP,
2145 &named_merge_points))
2147 int i;
2149 for (i = 1; i < LFACE_VECTOR_SIZE; ++i)
2150 attrs[i] = Qunspecified;
2152 return merge_face_ref (f, XCDR (face_remapping), attrs,
2153 signal_p, named_merge_points);
2157 /* Default case, no remapping. */
2158 return get_lface_attributes_no_remap (f, face_name, attrs, signal_p);
2162 /* Non-zero if all attributes in face attribute vector ATTRS are
2163 specified, i.e. are non-nil. */
2165 static int
2166 lface_fully_specified_p (Lisp_Object *attrs)
2168 int i;
2170 for (i = 1; i < LFACE_VECTOR_SIZE; ++i)
2171 if (i != LFACE_FONT_INDEX && i != LFACE_INHERIT_INDEX)
2172 if ((UNSPECIFIEDP (attrs[i]) || IGNORE_DEFFACE_P (attrs[i])))
2173 break;
2175 return i == LFACE_VECTOR_SIZE;
2178 #ifdef HAVE_WINDOW_SYSTEM
2180 /* Set font-related attributes of Lisp face LFACE from FONT-OBJECT.
2181 If FORCE_P is zero, set only unspecified attributes of LFACE. The
2182 exception is `font' attribute. It is set to FONT_OBJECT regardless
2183 of FORCE_P. */
2185 static int
2186 set_lface_from_font (struct frame *f, Lisp_Object lface, Lisp_Object font_object, int force_p)
2188 Lisp_Object val;
2189 struct font *font = XFONT_OBJECT (font_object);
2191 /* Set attributes only if unspecified, otherwise face defaults for
2192 new frames would never take effect. If the font doesn't have a
2193 specific property, set a normal value for that. */
2195 if (force_p || UNSPECIFIEDP (LFACE_FAMILY (lface)))
2197 Lisp_Object family = AREF (font_object, FONT_FAMILY_INDEX);
2199 LFACE_FAMILY (lface) = SYMBOL_NAME (family);
2202 if (force_p || UNSPECIFIEDP (LFACE_FOUNDRY (lface)))
2204 Lisp_Object foundry = AREF (font_object, FONT_FOUNDRY_INDEX);
2206 LFACE_FOUNDRY (lface) = SYMBOL_NAME (foundry);
2209 if (force_p || UNSPECIFIEDP (LFACE_HEIGHT (lface)))
2211 int pt = PIXEL_TO_POINT (font->pixel_size * 10, f->resy);
2213 xassert (pt > 0);
2214 LFACE_HEIGHT (lface) = make_number (pt);
2217 if (force_p || UNSPECIFIEDP (LFACE_WEIGHT (lface)))
2219 val = FONT_WEIGHT_FOR_FACE (font_object);
2220 LFACE_WEIGHT (lface) = ! NILP (val) ? val :Qnormal;
2222 if (force_p || UNSPECIFIEDP (LFACE_SLANT (lface)))
2224 val = FONT_SLANT_FOR_FACE (font_object);
2225 LFACE_SLANT (lface) = ! NILP (val) ? val : Qnormal;
2227 if (force_p || UNSPECIFIEDP (LFACE_SWIDTH (lface)))
2229 val = FONT_WIDTH_FOR_FACE (font_object);
2230 LFACE_SWIDTH (lface) = ! NILP (val) ? val : Qnormal;
2233 LFACE_FONT (lface) = font_object;
2234 return 1;
2237 #endif /* HAVE_WINDOW_SYSTEM */
2240 /* Merges the face height FROM with the face height TO, and returns the
2241 merged height. If FROM is an invalid height, then INVALID is
2242 returned instead. FROM and TO may be either absolute face heights or
2243 `relative' heights; the returned value is always an absolute height
2244 unless both FROM and TO are relative. */
2246 static Lisp_Object
2247 merge_face_heights (Lisp_Object from, Lisp_Object to, Lisp_Object invalid)
2249 Lisp_Object result = invalid;
2251 if (INTEGERP (from))
2252 /* FROM is absolute, just use it as is. */
2253 result = from;
2254 else if (FLOATP (from))
2255 /* FROM is a scale, use it to adjust TO. */
2257 if (INTEGERP (to))
2258 /* relative X absolute => absolute */
2259 result = make_number ((EMACS_INT)(XFLOAT_DATA (from) * XINT (to)));
2260 else if (FLOATP (to))
2261 /* relative X relative => relative */
2262 result = make_float (XFLOAT_DATA (from) * XFLOAT_DATA (to));
2263 else if (UNSPECIFIEDP (to))
2264 result = from;
2266 else if (FUNCTIONP (from))
2267 /* FROM is a function, which use to adjust TO. */
2269 /* Call function with current height as argument.
2270 From is the new height. */
2271 Lisp_Object args[2];
2273 args[0] = from;
2274 args[1] = to;
2275 result = safe_call (2, args);
2277 /* Ensure that if TO was absolute, so is the result. */
2278 if (INTEGERP (to) && !INTEGERP (result))
2279 result = invalid;
2282 return result;
2286 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
2287 store the resulting attributes in TO, which must be already be
2288 completely specified and contain only absolute attributes. Every
2289 specified attribute of FROM overrides the corresponding attribute of
2290 TO; relative attributes in FROM are merged with the absolute value in
2291 TO and replace it. NAMED_MERGE_POINTS is used internally to detect
2292 loops in face inheritance/remapping; it should be 0 when called from
2293 other places. */
2295 static INLINE void
2296 merge_face_vectors (struct frame *f, Lisp_Object *from, Lisp_Object *to, struct named_merge_point *named_merge_points)
2298 int i;
2300 /* If FROM inherits from some other faces, merge their attributes into
2301 TO before merging FROM's direct attributes. Note that an :inherit
2302 attribute of `unspecified' is the same as one of nil; we never
2303 merge :inherit attributes, so nil is more correct, but lots of
2304 other code uses `unspecified' as a generic value for face attributes. */
2305 if (!UNSPECIFIEDP (from[LFACE_INHERIT_INDEX])
2306 && !NILP (from[LFACE_INHERIT_INDEX]))
2307 merge_face_ref (f, from[LFACE_INHERIT_INDEX], to, 0, named_merge_points);
2309 i = LFACE_FONT_INDEX;
2310 if (!UNSPECIFIEDP (from[i]))
2312 if (!UNSPECIFIEDP (to[i]))
2313 to[i] = Fmerge_font_spec (from[i], to[i]);
2314 else
2315 to[i] = Fcopy_font_spec (from[i]);
2316 if (! NILP (AREF (to[i], FONT_FOUNDRY_INDEX)))
2317 to[LFACE_FOUNDRY_INDEX] = SYMBOL_NAME (AREF (to[i], FONT_FOUNDRY_INDEX));
2318 if (! NILP (AREF (to[i], FONT_FAMILY_INDEX)))
2319 to[LFACE_FAMILY_INDEX] = SYMBOL_NAME (AREF (to[i], FONT_FAMILY_INDEX));
2320 if (! NILP (AREF (to[i], FONT_WEIGHT_INDEX)))
2321 to[LFACE_WEIGHT_INDEX] = FONT_WEIGHT_FOR_FACE (to[i]);
2322 if (! NILP (AREF (to[i], FONT_SLANT_INDEX)))
2323 to[LFACE_SLANT_INDEX] = FONT_SLANT_FOR_FACE (to[i]);
2324 if (! NILP (AREF (to[i], FONT_WIDTH_INDEX)))
2325 to[LFACE_SWIDTH_INDEX] = FONT_WIDTH_FOR_FACE (to[i]);
2326 ASET (to[i], FONT_SIZE_INDEX, Qnil);
2329 for (i = 1; i < LFACE_VECTOR_SIZE; ++i)
2330 if (!UNSPECIFIEDP (from[i]))
2332 if (i == LFACE_HEIGHT_INDEX && !INTEGERP (from[i]))
2334 to[i] = merge_face_heights (from[i], to[i], to[i]);
2335 font_clear_prop (to, FONT_SIZE_INDEX);
2337 else if (i != LFACE_FONT_INDEX
2338 && ! EQ (to[i], from[i]))
2340 to[i] = from[i];
2341 if (i >= LFACE_FAMILY_INDEX && i <=LFACE_SLANT_INDEX)
2342 font_clear_prop (to,
2343 (i == LFACE_FAMILY_INDEX ? FONT_FAMILY_INDEX
2344 : i == LFACE_FOUNDRY_INDEX ? FONT_FOUNDRY_INDEX
2345 : i == LFACE_SWIDTH_INDEX ? FONT_WIDTH_INDEX
2346 : i == LFACE_HEIGHT_INDEX ? FONT_SIZE_INDEX
2347 : i == LFACE_WEIGHT_INDEX ? FONT_WEIGHT_INDEX
2348 : FONT_SLANT_INDEX));
2352 /* TO is always an absolute face, which should inherit from nothing.
2353 We blindly copy the :inherit attribute above and fix it up here. */
2354 to[LFACE_INHERIT_INDEX] = Qnil;
2357 /* Merge the named face FACE_NAME on frame F, into the vector of face
2358 attributes TO. NAMED_MERGE_POINTS is used to detect loops in face
2359 inheritance. Returns true if FACE_NAME is a valid face name and
2360 merging succeeded. */
2362 static int
2363 merge_named_face (struct frame *f, Lisp_Object face_name, Lisp_Object *to, struct named_merge_point *named_merge_points)
2365 struct named_merge_point named_merge_point;
2367 if (push_named_merge_point (&named_merge_point,
2368 face_name, NAMED_MERGE_POINT_NORMAL,
2369 &named_merge_points))
2371 struct gcpro gcpro1;
2372 Lisp_Object from[LFACE_VECTOR_SIZE];
2373 int ok = get_lface_attributes (f, face_name, from, 0, named_merge_points);
2375 if (ok)
2377 GCPRO1 (named_merge_point.face_name);
2378 merge_face_vectors (f, from, to, named_merge_points);
2379 UNGCPRO;
2382 return ok;
2384 else
2385 return 0;
2389 /* Merge face attributes from the lisp `face reference' FACE_REF on
2390 frame F into the face attribute vector TO. If ERR_MSGS is non-zero,
2391 problems with FACE_REF cause an error message to be shown. Return
2392 non-zero if no errors occurred (regardless of the value of ERR_MSGS).
2393 NAMED_MERGE_POINTS is used to detect loops in face inheritance or
2394 list structure; it may be 0 for most callers.
2396 FACE_REF may be a single face specification or a list of such
2397 specifications. Each face specification can be:
2399 1. A symbol or string naming a Lisp face.
2401 2. A property list of the form (KEYWORD VALUE ...) where each
2402 KEYWORD is a face attribute name, and value is an appropriate value
2403 for that attribute.
2405 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
2406 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
2407 for compatibility with 20.2.
2409 Face specifications earlier in lists take precedence over later
2410 specifications. */
2412 static int
2413 merge_face_ref (struct frame *f, Lisp_Object face_ref, Lisp_Object *to, int err_msgs, struct named_merge_point *named_merge_points)
2415 int ok = 1; /* Succeed without an error? */
2417 if (CONSP (face_ref))
2419 Lisp_Object first = XCAR (face_ref);
2421 if (EQ (first, Qforeground_color)
2422 || EQ (first, Qbackground_color))
2424 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
2425 . COLOR). COLOR must be a string. */
2426 Lisp_Object color_name = XCDR (face_ref);
2427 Lisp_Object color = first;
2429 if (STRINGP (color_name))
2431 if (EQ (color, Qforeground_color))
2432 to[LFACE_FOREGROUND_INDEX] = color_name;
2433 else
2434 to[LFACE_BACKGROUND_INDEX] = color_name;
2436 else
2438 if (err_msgs)
2439 add_to_log ("Invalid face color", color_name, Qnil);
2440 ok = 0;
2443 else if (SYMBOLP (first)
2444 && *SDATA (SYMBOL_NAME (first)) == ':')
2446 /* Assume this is the property list form. */
2447 while (CONSP (face_ref) && CONSP (XCDR (face_ref)))
2449 Lisp_Object keyword = XCAR (face_ref);
2450 Lisp_Object value = XCAR (XCDR (face_ref));
2451 int err = 0;
2453 /* Specifying `unspecified' is a no-op. */
2454 if (EQ (value, Qunspecified))
2456 else if (EQ (keyword, QCfamily))
2458 if (STRINGP (value))
2460 to[LFACE_FAMILY_INDEX] = value;
2461 font_clear_prop (to, FONT_FAMILY_INDEX);
2463 else
2464 err = 1;
2466 else if (EQ (keyword, QCfoundry))
2468 if (STRINGP (value))
2470 to[LFACE_FOUNDRY_INDEX] = value;
2471 font_clear_prop (to, FONT_FOUNDRY_INDEX);
2473 else
2474 err = 1;
2476 else if (EQ (keyword, QCheight))
2478 Lisp_Object new_height =
2479 merge_face_heights (value, to[LFACE_HEIGHT_INDEX], Qnil);
2481 if (! NILP (new_height))
2483 to[LFACE_HEIGHT_INDEX] = new_height;
2484 font_clear_prop (to, FONT_SIZE_INDEX);
2486 else
2487 err = 1;
2489 else if (EQ (keyword, QCweight))
2491 if (SYMBOLP (value) && FONT_WEIGHT_NAME_NUMERIC (value) >= 0)
2493 to[LFACE_WEIGHT_INDEX] = value;
2494 font_clear_prop (to, FONT_WEIGHT_INDEX);
2496 else
2497 err = 1;
2499 else if (EQ (keyword, QCslant))
2501 if (SYMBOLP (value) && FONT_SLANT_NAME_NUMERIC (value) >= 0)
2503 to[LFACE_SLANT_INDEX] = value;
2504 font_clear_prop (to, FONT_SLANT_INDEX);
2506 else
2507 err = 1;
2509 else if (EQ (keyword, QCunderline))
2511 if (EQ (value, Qt)
2512 || NILP (value)
2513 || STRINGP (value))
2514 to[LFACE_UNDERLINE_INDEX] = value;
2515 else
2516 err = 1;
2518 else if (EQ (keyword, QCoverline))
2520 if (EQ (value, Qt)
2521 || NILP (value)
2522 || STRINGP (value))
2523 to[LFACE_OVERLINE_INDEX] = value;
2524 else
2525 err = 1;
2527 else if (EQ (keyword, QCstrike_through))
2529 if (EQ (value, Qt)
2530 || NILP (value)
2531 || STRINGP (value))
2532 to[LFACE_STRIKE_THROUGH_INDEX] = value;
2533 else
2534 err = 1;
2536 else if (EQ (keyword, QCbox))
2538 if (EQ (value, Qt))
2539 value = make_number (1);
2540 if (INTEGERP (value)
2541 || STRINGP (value)
2542 || CONSP (value)
2543 || NILP (value))
2544 to[LFACE_BOX_INDEX] = value;
2545 else
2546 err = 1;
2548 else if (EQ (keyword, QCinverse_video)
2549 || EQ (keyword, QCreverse_video))
2551 if (EQ (value, Qt) || NILP (value))
2552 to[LFACE_INVERSE_INDEX] = value;
2553 else
2554 err = 1;
2556 else if (EQ (keyword, QCforeground))
2558 if (STRINGP (value))
2559 to[LFACE_FOREGROUND_INDEX] = value;
2560 else
2561 err = 1;
2563 else if (EQ (keyword, QCbackground))
2565 if (STRINGP (value))
2566 to[LFACE_BACKGROUND_INDEX] = value;
2567 else
2568 err = 1;
2570 else if (EQ (keyword, QCstipple))
2572 #if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
2573 Lisp_Object pixmap_p = Fbitmap_spec_p (value);
2574 if (!NILP (pixmap_p))
2575 to[LFACE_STIPPLE_INDEX] = value;
2576 else
2577 err = 1;
2578 #endif
2580 else if (EQ (keyword, QCwidth))
2582 if (SYMBOLP (value) && FONT_WIDTH_NAME_NUMERIC (value) >= 0)
2584 to[LFACE_SWIDTH_INDEX] = value;
2585 font_clear_prop (to, FONT_WIDTH_INDEX);
2587 else
2588 err = 1;
2590 else if (EQ (keyword, QCinherit))
2592 /* This is not really very useful; it's just like a
2593 normal face reference. */
2594 if (! merge_face_ref (f, value, to,
2595 err_msgs, named_merge_points))
2596 err = 1;
2598 else
2599 err = 1;
2601 if (err)
2603 add_to_log ("Invalid face attribute %S %S", keyword, value);
2604 ok = 0;
2607 face_ref = XCDR (XCDR (face_ref));
2610 else
2612 /* This is a list of face refs. Those at the beginning of the
2613 list take precedence over what follows, so we have to merge
2614 from the end backwards. */
2615 Lisp_Object next = XCDR (face_ref);
2617 if (! NILP (next))
2618 ok = merge_face_ref (f, next, to, err_msgs, named_merge_points);
2620 if (! merge_face_ref (f, first, to, err_msgs, named_merge_points))
2621 ok = 0;
2624 else
2626 /* FACE_REF ought to be a face name. */
2627 ok = merge_named_face (f, face_ref, to, named_merge_points);
2628 if (!ok && err_msgs)
2629 add_to_log ("Invalid face reference: %s", face_ref, Qnil);
2632 return ok;
2636 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face,
2637 Sinternal_make_lisp_face, 1, 2, 0,
2638 doc: /* Make FACE, a symbol, a Lisp face with all attributes nil.
2639 If FACE was not known as a face before, create a new one.
2640 If optional argument FRAME is specified, make a frame-local face
2641 for that frame. Otherwise operate on the global face definition.
2642 Value is a vector of face attributes. */)
2643 (Lisp_Object face, Lisp_Object frame)
2645 Lisp_Object global_lface, lface;
2646 struct frame *f;
2647 int i;
2649 CHECK_SYMBOL (face);
2650 global_lface = lface_from_face_name (NULL, face, 0);
2652 if (!NILP (frame))
2654 CHECK_LIVE_FRAME (frame);
2655 f = XFRAME (frame);
2656 lface = lface_from_face_name (f, face, 0);
2658 else
2659 f = NULL, lface = Qnil;
2661 /* Add a global definition if there is none. */
2662 if (NILP (global_lface))
2664 global_lface = Fmake_vector (make_number (LFACE_VECTOR_SIZE),
2665 Qunspecified);
2666 ASET (global_lface, 0, Qface);
2667 Vface_new_frame_defaults = Fcons (Fcons (face, global_lface),
2668 Vface_new_frame_defaults);
2670 /* Assign the new Lisp face a unique ID. The mapping from Lisp
2671 face id to Lisp face is given by the vector lface_id_to_name.
2672 The mapping from Lisp face to Lisp face id is given by the
2673 property `face' of the Lisp face name. */
2674 if (next_lface_id == lface_id_to_name_size)
2676 int new_size = max (50, 2 * lface_id_to_name_size);
2677 int sz = new_size * sizeof *lface_id_to_name;
2678 lface_id_to_name = (Lisp_Object *) xrealloc (lface_id_to_name, sz);
2679 lface_id_to_name_size = new_size;
2682 lface_id_to_name[next_lface_id] = face;
2683 Fput (face, Qface, make_number (next_lface_id));
2684 ++next_lface_id;
2686 else if (f == NULL)
2687 for (i = 1; i < LFACE_VECTOR_SIZE; ++i)
2688 ASET (global_lface, i, Qunspecified);
2690 /* Add a frame-local definition. */
2691 if (f)
2693 if (NILP (lface))
2695 lface = Fmake_vector (make_number (LFACE_VECTOR_SIZE),
2696 Qunspecified);
2697 ASET (lface, 0, Qface);
2698 f->face_alist = Fcons (Fcons (face, lface), f->face_alist);
2700 else
2701 for (i = 1; i < LFACE_VECTOR_SIZE; ++i)
2702 ASET (lface, i, Qunspecified);
2704 else
2705 lface = global_lface;
2707 /* Changing a named face means that all realized faces depending on
2708 that face are invalid. Since we cannot tell which realized faces
2709 depend on the face, make sure they are all removed. This is done
2710 by incrementing face_change_count. The next call to
2711 init_iterator will then free realized faces. */
2712 if (NILP (Fget (face, Qface_no_inherit)))
2714 ++face_change_count;
2715 ++windows_or_buffers_changed;
2718 xassert (LFACEP (lface));
2719 check_lface (lface);
2720 return lface;
2724 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p,
2725 Sinternal_lisp_face_p, 1, 2, 0,
2726 doc: /* Return non-nil if FACE names a face.
2727 FACE should be a symbol or string.
2728 If optional second argument FRAME is non-nil, check for the
2729 existence of a frame-local face with name FACE on that frame.
2730 Otherwise check for the existence of a global face. */)
2731 (Lisp_Object face, Lisp_Object frame)
2733 Lisp_Object lface;
2735 face = resolve_face_name (face, 1);
2737 if (!NILP (frame))
2739 CHECK_LIVE_FRAME (frame);
2740 lface = lface_from_face_name (XFRAME (frame), face, 0);
2742 else
2743 lface = lface_from_face_name (NULL, face, 0);
2745 return lface;
2749 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face,
2750 Sinternal_copy_lisp_face, 4, 4, 0,
2751 doc: /* Copy face FROM to TO.
2752 If FRAME is t, copy the global face definition of FROM.
2753 Otherwise, copy the frame-local definition of FROM on FRAME.
2754 If NEW-FRAME is a frame, copy that data into the frame-local
2755 definition of TO on NEW-FRAME. If NEW-FRAME is nil,
2756 FRAME controls where the data is copied to.
2758 The value is TO. */)
2759 (Lisp_Object from, Lisp_Object to, Lisp_Object frame, Lisp_Object new_frame)
2761 Lisp_Object lface, copy;
2763 CHECK_SYMBOL (from);
2764 CHECK_SYMBOL (to);
2766 if (EQ (frame, Qt))
2768 /* Copy global definition of FROM. We don't make copies of
2769 strings etc. because 20.2 didn't do it either. */
2770 lface = lface_from_face_name (NULL, from, 1);
2771 copy = Finternal_make_lisp_face (to, Qnil);
2773 else
2775 /* Copy frame-local definition of FROM. */
2776 if (NILP (new_frame))
2777 new_frame = frame;
2778 CHECK_LIVE_FRAME (frame);
2779 CHECK_LIVE_FRAME (new_frame);
2780 lface = lface_from_face_name (XFRAME (frame), from, 1);
2781 copy = Finternal_make_lisp_face (to, new_frame);
2784 memcpy (XVECTOR (copy)->contents, XVECTOR (lface)->contents,
2785 LFACE_VECTOR_SIZE * sizeof (Lisp_Object));
2787 /* Changing a named face means that all realized faces depending on
2788 that face are invalid. Since we cannot tell which realized faces
2789 depend on the face, make sure they are all removed. This is done
2790 by incrementing face_change_count. The next call to
2791 init_iterator will then free realized faces. */
2792 if (NILP (Fget (to, Qface_no_inherit)))
2794 ++face_change_count;
2795 ++windows_or_buffers_changed;
2798 return to;
2802 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute,
2803 Sinternal_set_lisp_face_attribute, 3, 4, 0,
2804 doc: /* Set attribute ATTR of FACE to VALUE.
2805 FRAME being a frame means change the face on that frame.
2806 FRAME nil means change the face of the selected frame.
2807 FRAME t means change the default for new frames.
2808 FRAME 0 means change the face on all frames, and change the default
2809 for new frames. */)
2810 (Lisp_Object face, Lisp_Object attr, Lisp_Object value, Lisp_Object frame)
2812 Lisp_Object lface;
2813 Lisp_Object old_value = Qnil;
2814 /* Set one of enum font_property_index (> 0) if ATTR is one of
2815 font-related attributes other than QCfont and QCfontset. */
2816 enum font_property_index prop_index = 0;
2818 CHECK_SYMBOL (face);
2819 CHECK_SYMBOL (attr);
2821 face = resolve_face_name (face, 1);
2823 /* If FRAME is 0, change face on all frames, and change the
2824 default for new frames. */
2825 if (INTEGERP (frame) && XINT (frame) == 0)
2827 Lisp_Object tail;
2828 Finternal_set_lisp_face_attribute (face, attr, value, Qt);
2829 FOR_EACH_FRAME (tail, frame)
2830 Finternal_set_lisp_face_attribute (face, attr, value, frame);
2831 return face;
2834 /* Set lface to the Lisp attribute vector of FACE. */
2835 if (EQ (frame, Qt))
2837 lface = lface_from_face_name (NULL, face, 1);
2839 /* When updating face-new-frame-defaults, we put :ignore-defface
2840 where the caller wants `unspecified'. This forces the frame
2841 defaults to ignore the defface value. Otherwise, the defface
2842 will take effect, which is generally not what is intended.
2843 The value of that attribute will be inherited from some other
2844 face during face merging. See internal_merge_in_global_face. */
2845 if (UNSPECIFIEDP (value))
2846 value = Qignore_defface;
2848 else
2850 if (NILP (frame))
2851 frame = selected_frame;
2853 CHECK_LIVE_FRAME (frame);
2854 lface = lface_from_face_name (XFRAME (frame), face, 0);
2856 /* If a frame-local face doesn't exist yet, create one. */
2857 if (NILP (lface))
2858 lface = Finternal_make_lisp_face (face, frame);
2861 if (EQ (attr, QCfamily))
2863 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
2865 CHECK_STRING (value);
2866 if (SCHARS (value) == 0)
2867 signal_error ("Invalid face family", value);
2869 old_value = LFACE_FAMILY (lface);
2870 LFACE_FAMILY (lface) = value;
2871 prop_index = FONT_FAMILY_INDEX;
2873 else if (EQ (attr, QCfoundry))
2875 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
2877 CHECK_STRING (value);
2878 if (SCHARS (value) == 0)
2879 signal_error ("Invalid face foundry", value);
2881 old_value = LFACE_FOUNDRY (lface);
2882 LFACE_FOUNDRY (lface) = value;
2883 prop_index = FONT_FOUNDRY_INDEX;
2885 else if (EQ (attr, QCheight))
2887 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
2889 if (EQ (face, Qdefault))
2891 /* The default face must have an absolute size. */
2892 if (!INTEGERP (value) || XINT (value) <= 0)
2893 signal_error ("Default face height not absolute and positive", value);
2895 else
2897 /* For non-default faces, do a test merge with a random
2898 height to see if VALUE's ok. */
2899 Lisp_Object test = merge_face_heights (value,
2900 make_number (10),
2901 Qnil);
2902 if (!INTEGERP (test) || XINT (test) <= 0)
2903 signal_error ("Face height does not produce a positive integer", value);
2907 old_value = LFACE_HEIGHT (lface);
2908 LFACE_HEIGHT (lface) = value;
2909 prop_index = FONT_SIZE_INDEX;
2911 else if (EQ (attr, QCweight))
2913 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
2915 CHECK_SYMBOL (value);
2916 if (FONT_WEIGHT_NAME_NUMERIC (value) < 0)
2917 signal_error ("Invalid face weight", value);
2919 old_value = LFACE_WEIGHT (lface);
2920 LFACE_WEIGHT (lface) = value;
2921 prop_index = FONT_WEIGHT_INDEX;
2923 else if (EQ (attr, QCslant))
2925 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
2927 CHECK_SYMBOL (value);
2928 if (FONT_SLANT_NAME_NUMERIC (value) < 0)
2929 signal_error ("Invalid face slant", value);
2931 old_value = LFACE_SLANT (lface);
2932 LFACE_SLANT (lface) = value;
2933 prop_index = FONT_SLANT_INDEX;
2935 else if (EQ (attr, QCunderline))
2937 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
2938 if ((SYMBOLP (value)
2939 && !EQ (value, Qt)
2940 && !EQ (value, Qnil))
2941 /* Underline color. */
2942 || (STRINGP (value)
2943 && SCHARS (value) == 0))
2944 signal_error ("Invalid face underline", value);
2946 old_value = LFACE_UNDERLINE (lface);
2947 LFACE_UNDERLINE (lface) = value;
2949 else if (EQ (attr, QCoverline))
2951 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
2952 if ((SYMBOLP (value)
2953 && !EQ (value, Qt)
2954 && !EQ (value, Qnil))
2955 /* Overline color. */
2956 || (STRINGP (value)
2957 && SCHARS (value) == 0))
2958 signal_error ("Invalid face overline", value);
2960 old_value = LFACE_OVERLINE (lface);
2961 LFACE_OVERLINE (lface) = value;
2963 else if (EQ (attr, QCstrike_through))
2965 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
2966 if ((SYMBOLP (value)
2967 && !EQ (value, Qt)
2968 && !EQ (value, Qnil))
2969 /* Strike-through color. */
2970 || (STRINGP (value)
2971 && SCHARS (value) == 0))
2972 signal_error ("Invalid face strike-through", value);
2974 old_value = LFACE_STRIKE_THROUGH (lface);
2975 LFACE_STRIKE_THROUGH (lface) = value;
2977 else if (EQ (attr, QCbox))
2979 int valid_p;
2981 /* Allow t meaning a simple box of width 1 in foreground color
2982 of the face. */
2983 if (EQ (value, Qt))
2984 value = make_number (1);
2986 if (UNSPECIFIEDP (value) || IGNORE_DEFFACE_P (value))
2987 valid_p = 1;
2988 else if (NILP (value))
2989 valid_p = 1;
2990 else if (INTEGERP (value))
2991 valid_p = XINT (value) != 0;
2992 else if (STRINGP (value))
2993 valid_p = SCHARS (value) > 0;
2994 else if (CONSP (value))
2996 Lisp_Object tem;
2998 tem = value;
2999 while (CONSP (tem))
3001 Lisp_Object k, v;
3003 k = XCAR (tem);
3004 tem = XCDR (tem);
3005 if (!CONSP (tem))
3006 break;
3007 v = XCAR (tem);
3008 tem = XCDR (tem);
3010 if (EQ (k, QCline_width))
3012 if (!INTEGERP (v) || XINT (v) == 0)
3013 break;
3015 else if (EQ (k, QCcolor))
3017 if (!NILP (v) && (!STRINGP (v) || SCHARS (v) == 0))
3018 break;
3020 else if (EQ (k, QCstyle))
3022 if (!EQ (v, Qpressed_button) && !EQ (v, Qreleased_button))
3023 break;
3025 else
3026 break;
3029 valid_p = NILP (tem);
3031 else
3032 valid_p = 0;
3034 if (!valid_p)
3035 signal_error ("Invalid face box", value);
3037 old_value = LFACE_BOX (lface);
3038 LFACE_BOX (lface) = value;
3040 else if (EQ (attr, QCinverse_video)
3041 || EQ (attr, QCreverse_video))
3043 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
3045 CHECK_SYMBOL (value);
3046 if (!EQ (value, Qt) && !NILP (value))
3047 signal_error ("Invalid inverse-video face attribute value", value);
3049 old_value = LFACE_INVERSE (lface);
3050 LFACE_INVERSE (lface) = value;
3052 else if (EQ (attr, QCforeground))
3054 /* Compatibility with 20.x. */
3055 if (NILP (value))
3056 value = Qunspecified;
3057 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
3059 /* Don't check for valid color names here because it depends
3060 on the frame (display) whether the color will be valid
3061 when the face is realized. */
3062 CHECK_STRING (value);
3063 if (SCHARS (value) == 0)
3064 signal_error ("Empty foreground color value", value);
3066 old_value = LFACE_FOREGROUND (lface);
3067 LFACE_FOREGROUND (lface) = value;
3069 else if (EQ (attr, QCbackground))
3071 /* Compatibility with 20.x. */
3072 if (NILP (value))
3073 value = Qunspecified;
3074 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
3076 /* Don't check for valid color names here because it depends
3077 on the frame (display) whether the color will be valid
3078 when the face is realized. */
3079 CHECK_STRING (value);
3080 if (SCHARS (value) == 0)
3081 signal_error ("Empty background color value", value);
3083 old_value = LFACE_BACKGROUND (lface);
3084 LFACE_BACKGROUND (lface) = value;
3086 else if (EQ (attr, QCstipple))
3088 #if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
3089 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value)
3090 && !NILP (value)
3091 && NILP (Fbitmap_spec_p (value)))
3092 signal_error ("Invalid stipple attribute", value);
3093 old_value = LFACE_STIPPLE (lface);
3094 LFACE_STIPPLE (lface) = value;
3095 #endif /* HAVE_X_WINDOWS || HAVE_NS */
3097 else if (EQ (attr, QCwidth))
3099 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
3101 CHECK_SYMBOL (value);
3102 if (FONT_WIDTH_NAME_NUMERIC (value) < 0)
3103 signal_error ("Invalid face width", value);
3105 old_value = LFACE_SWIDTH (lface);
3106 LFACE_SWIDTH (lface) = value;
3107 prop_index = FONT_WIDTH_INDEX;
3109 else if (EQ (attr, QCfont))
3111 #ifdef HAVE_WINDOW_SYSTEM
3112 if (EQ (frame, Qt) || FRAME_WINDOW_P (XFRAME (frame)))
3114 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
3116 FRAME_PTR f;
3118 old_value = LFACE_FONT (lface);
3119 if (! FONTP (value))
3121 if (STRINGP (value))
3123 Lisp_Object name = value;
3124 int fontset = fs_query_fontset (name, 0);
3126 if (fontset >= 0)
3127 name = fontset_ascii (fontset);
3128 value = font_spec_from_name (name);
3129 if (!FONTP (value))
3130 signal_error ("Invalid font name", name);
3132 else
3133 signal_error ("Invalid font or font-spec", value);
3135 if (EQ (frame, Qt))
3136 f = XFRAME (selected_frame);
3137 else
3138 f = XFRAME (frame);
3139 if (! FONT_OBJECT_P (value))
3141 Lisp_Object *attrs = XVECTOR (lface)->contents;
3142 Lisp_Object font_object;
3144 font_object = font_load_for_lface (f, attrs, value);
3145 if (NILP (font_object))
3146 signal_error ("Font not available", value);
3147 value = font_object;
3149 set_lface_from_font (f, lface, value, 1);
3151 else
3152 LFACE_FONT (lface) = value;
3154 #endif /* HAVE_WINDOW_SYSTEM */
3156 else if (EQ (attr, QCfontset))
3158 #ifdef HAVE_WINDOW_SYSTEM
3159 if (EQ (frame, Qt) || FRAME_WINDOW_P (XFRAME (frame)))
3161 Lisp_Object tmp;
3163 old_value = LFACE_FONTSET (lface);
3164 tmp = Fquery_fontset (value, Qnil);
3165 if (NILP (tmp))
3166 signal_error ("Invalid fontset name", value);
3167 LFACE_FONTSET (lface) = value = tmp;
3169 #endif /* HAVE_WINDOW_SYSTEM */
3171 else if (EQ (attr, QCinherit))
3173 Lisp_Object tail;
3174 if (SYMBOLP (value))
3175 tail = Qnil;
3176 else
3177 for (tail = value; CONSP (tail); tail = XCDR (tail))
3178 if (!SYMBOLP (XCAR (tail)))
3179 break;
3180 if (NILP (tail))
3181 LFACE_INHERIT (lface) = value;
3182 else
3183 signal_error ("Invalid face inheritance", value);
3185 else if (EQ (attr, QCbold))
3187 old_value = LFACE_WEIGHT (lface);
3188 LFACE_WEIGHT (lface) = NILP (value) ? Qnormal : Qbold;
3189 prop_index = FONT_WEIGHT_INDEX;
3191 else if (EQ (attr, QCitalic))
3193 attr = QCslant;
3194 old_value = LFACE_SLANT (lface);
3195 LFACE_SLANT (lface) = NILP (value) ? Qnormal : Qitalic;
3196 prop_index = FONT_SLANT_INDEX;
3198 else
3199 signal_error ("Invalid face attribute name", attr);
3201 if (prop_index)
3203 /* If a font-related attribute other than QCfont and QCfontset
3204 is specified, and if the original QCfont attribute has a font
3205 (font-spec or font-object), set the corresponding property in
3206 the font to nil so that the font selector doesn't think that
3207 the attribute is mandatory. Also, clear the average
3208 width. */
3209 font_clear_prop (XVECTOR (lface)->contents, prop_index);
3212 /* Changing a named face means that all realized faces depending on
3213 that face are invalid. Since we cannot tell which realized faces
3214 depend on the face, make sure they are all removed. This is done
3215 by incrementing face_change_count. The next call to
3216 init_iterator will then free realized faces. */
3217 if (!EQ (frame, Qt)
3218 && NILP (Fget (face, Qface_no_inherit))
3219 && NILP (Fequal (old_value, value)))
3221 ++face_change_count;
3222 ++windows_or_buffers_changed;
3225 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value)
3226 && NILP (Fequal (old_value, value)))
3228 Lisp_Object param;
3230 param = Qnil;
3232 if (EQ (face, Qdefault))
3234 #ifdef HAVE_WINDOW_SYSTEM
3235 /* Changed font-related attributes of the `default' face are
3236 reflected in changed `font' frame parameters. */
3237 if (FRAMEP (frame)
3238 && (prop_index || EQ (attr, QCfont))
3239 && lface_fully_specified_p (XVECTOR (lface)->contents))
3240 set_font_frame_param (frame, lface);
3241 else
3242 #endif /* HAVE_WINDOW_SYSTEM */
3244 if (EQ (attr, QCforeground))
3245 param = Qforeground_color;
3246 else if (EQ (attr, QCbackground))
3247 param = Qbackground_color;
3249 #ifdef HAVE_WINDOW_SYSTEM
3250 #ifndef WINDOWSNT
3251 else if (EQ (face, Qscroll_bar))
3253 /* Changing the colors of `scroll-bar' sets frame parameters
3254 `scroll-bar-foreground' and `scroll-bar-background'. */
3255 if (EQ (attr, QCforeground))
3256 param = Qscroll_bar_foreground;
3257 else if (EQ (attr, QCbackground))
3258 param = Qscroll_bar_background;
3260 #endif /* not WINDOWSNT */
3261 else if (EQ (face, Qborder))
3263 /* Changing background color of `border' sets frame parameter
3264 `border-color'. */
3265 if (EQ (attr, QCbackground))
3266 param = Qborder_color;
3268 else if (EQ (face, Qcursor))
3270 /* Changing background color of `cursor' sets frame parameter
3271 `cursor-color'. */
3272 if (EQ (attr, QCbackground))
3273 param = Qcursor_color;
3275 else if (EQ (face, Qmouse))
3277 /* Changing background color of `mouse' sets frame parameter
3278 `mouse-color'. */
3279 if (EQ (attr, QCbackground))
3280 param = Qmouse_color;
3282 #endif /* HAVE_WINDOW_SYSTEM */
3283 else if (EQ (face, Qmenu))
3285 /* Indicate that we have to update the menu bar when
3286 realizing faces on FRAME. FRAME t change the
3287 default for new frames. We do this by setting
3288 setting the flag in new face caches */
3289 if (FRAMEP (frame))
3291 struct frame *f = XFRAME (frame);
3292 if (FRAME_FACE_CACHE (f) == NULL)
3293 FRAME_FACE_CACHE (f) = make_face_cache (f);
3294 FRAME_FACE_CACHE (f)->menu_face_changed_p = 1;
3296 else
3297 menu_face_changed_default = 1;
3300 if (!NILP (param))
3302 if (EQ (frame, Qt))
3303 /* Update `default-frame-alist', which is used for new frames. */
3305 store_in_alist (&Vdefault_frame_alist, param, value);
3307 else
3308 /* Update the current frame's parameters. */
3310 Lisp_Object cons;
3311 cons = XCAR (Vparam_value_alist);
3312 XSETCAR (cons, param);
3313 XSETCDR (cons, value);
3314 Fmodify_frame_parameters (frame, Vparam_value_alist);
3319 return face;
3323 /* Update the corresponding face when frame parameter PARAM on frame F
3324 has been assigned the value NEW_VALUE. */
3326 void
3327 update_face_from_frame_parameter (struct frame *f, Lisp_Object param, Lisp_Object new_value)
3329 Lisp_Object face = Qnil;
3330 Lisp_Object lface;
3332 /* If there are no faces yet, give up. This is the case when called
3333 from Fx_create_frame, and we do the necessary things later in
3334 face-set-after-frame-defaults. */
3335 if (NILP (f->face_alist))
3336 return;
3338 if (EQ (param, Qforeground_color))
3340 face = Qdefault;
3341 lface = lface_from_face_name (f, face, 1);
3342 LFACE_FOREGROUND (lface) = (STRINGP (new_value)
3343 ? new_value : Qunspecified);
3344 realize_basic_faces (f);
3346 else if (EQ (param, Qbackground_color))
3348 Lisp_Object frame;
3350 /* Changing the background color might change the background
3351 mode, so that we have to load new defface specs.
3352 Call frame-update-face-colors to do that. */
3353 XSETFRAME (frame, f);
3354 call1 (Qframe_set_background_mode, frame);
3356 face = Qdefault;
3357 lface = lface_from_face_name (f, face, 1);
3358 LFACE_BACKGROUND (lface) = (STRINGP (new_value)
3359 ? new_value : Qunspecified);
3360 realize_basic_faces (f);
3362 #ifdef HAVE_WINDOW_SYSTEM
3363 else if (EQ (param, Qborder_color))
3365 face = Qborder;
3366 lface = lface_from_face_name (f, face, 1);
3367 LFACE_BACKGROUND (lface) = (STRINGP (new_value)
3368 ? new_value : Qunspecified);
3370 else if (EQ (param, Qcursor_color))
3372 face = Qcursor;
3373 lface = lface_from_face_name (f, face, 1);
3374 LFACE_BACKGROUND (lface) = (STRINGP (new_value)
3375 ? new_value : Qunspecified);
3377 else if (EQ (param, Qmouse_color))
3379 face = Qmouse;
3380 lface = lface_from_face_name (f, face, 1);
3381 LFACE_BACKGROUND (lface) = (STRINGP (new_value)
3382 ? new_value : Qunspecified);
3384 #endif
3386 /* Changing a named face means that all realized faces depending on
3387 that face are invalid. Since we cannot tell which realized faces
3388 depend on the face, make sure they are all removed. This is done
3389 by incrementing face_change_count. The next call to
3390 init_iterator will then free realized faces. */
3391 if (!NILP (face)
3392 && NILP (Fget (face, Qface_no_inherit)))
3394 ++face_change_count;
3395 ++windows_or_buffers_changed;
3400 #ifdef HAVE_WINDOW_SYSTEM
3402 /* Set the `font' frame parameter of FRAME determined from the
3403 font-object set in `default' face attributes LFACE. */
3405 static void
3406 set_font_frame_param (Lisp_Object frame, Lisp_Object lface)
3408 struct frame *f = XFRAME (frame);
3409 Lisp_Object font;
3411 if (FRAME_WINDOW_P (f)
3412 /* Don't do anything if the font is `unspecified'. This can
3413 happen during frame creation. */
3414 && (font = LFACE_FONT (lface),
3415 ! UNSPECIFIEDP (font)))
3417 if (FONT_SPEC_P (font))
3419 font = font_load_for_lface (f, XVECTOR (lface)->contents, font);
3420 if (NILP (font))
3421 return;
3422 LFACE_FONT (lface) = font;
3424 f->default_face_done_p = 0;
3425 Fmodify_frame_parameters (frame, Fcons (Fcons (Qfont, font), Qnil));
3430 /* Get the value of X resource RESOURCE, class CLASS for the display
3431 of frame FRAME. This is here because ordinary `x-get-resource'
3432 doesn't take a frame argument. */
3434 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource,
3435 Sinternal_face_x_get_resource, 3, 3, 0, doc: /* */)
3436 (Lisp_Object resource, Lisp_Object class, Lisp_Object frame)
3438 Lisp_Object value = Qnil;
3439 CHECK_STRING (resource);
3440 CHECK_STRING (class);
3441 CHECK_LIVE_FRAME (frame);
3442 BLOCK_INPUT;
3443 value = display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame)),
3444 resource, class, Qnil, Qnil);
3445 UNBLOCK_INPUT;
3446 return value;
3450 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
3451 If VALUE is "on" or "true", return t. If VALUE is "off" or
3452 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
3453 error; if SIGNAL_P is zero, return 0. */
3455 static Lisp_Object
3456 face_boolean_x_resource_value (Lisp_Object value, int signal_p)
3458 Lisp_Object result = make_number (0);
3460 xassert (STRINGP (value));
3462 if (xstrcasecmp (SSDATA (value), "on") == 0
3463 || xstrcasecmp (SSDATA (value), "true") == 0)
3464 result = Qt;
3465 else if (xstrcasecmp (SSDATA (value), "off") == 0
3466 || xstrcasecmp (SSDATA (value), "false") == 0)
3467 result = Qnil;
3468 else if (xstrcasecmp (SSDATA (value), "unspecified") == 0)
3469 result = Qunspecified;
3470 else if (signal_p)
3471 signal_error ("Invalid face attribute value from X resource", value);
3473 return result;
3477 DEFUN ("internal-set-lisp-face-attribute-from-resource",
3478 Finternal_set_lisp_face_attribute_from_resource,
3479 Sinternal_set_lisp_face_attribute_from_resource,
3480 3, 4, 0, doc: /* */)
3481 (Lisp_Object face, Lisp_Object attr, Lisp_Object value, Lisp_Object frame)
3483 CHECK_SYMBOL (face);
3484 CHECK_SYMBOL (attr);
3485 CHECK_STRING (value);
3487 if (xstrcasecmp (SSDATA (value), "unspecified") == 0)
3488 value = Qunspecified;
3489 else if (EQ (attr, QCheight))
3491 value = Fstring_to_number (value, make_number (10));
3492 if (XINT (value) <= 0)
3493 signal_error ("Invalid face height from X resource", value);
3495 else if (EQ (attr, QCbold) || EQ (attr, QCitalic))
3496 value = face_boolean_x_resource_value (value, 1);
3497 else if (EQ (attr, QCweight) || EQ (attr, QCslant) || EQ (attr, QCwidth))
3498 value = intern (SSDATA (value));
3499 else if (EQ (attr, QCreverse_video) || EQ (attr, QCinverse_video))
3500 value = face_boolean_x_resource_value (value, 1);
3501 else if (EQ (attr, QCunderline)
3502 || EQ (attr, QCoverline)
3503 || EQ (attr, QCstrike_through))
3505 Lisp_Object boolean_value;
3507 /* If the result of face_boolean_x_resource_value is t or nil,
3508 VALUE does NOT specify a color. */
3509 boolean_value = face_boolean_x_resource_value (value, 0);
3510 if (SYMBOLP (boolean_value))
3511 value = boolean_value;
3513 else if (EQ (attr, QCbox) || EQ (attr, QCinherit))
3514 value = Fcar (Fread_from_string (value, Qnil, Qnil));
3516 return Finternal_set_lisp_face_attribute (face, attr, value, frame);
3519 #endif /* HAVE_WINDOW_SYSTEM */
3522 /***********************************************************************
3523 Menu face
3524 ***********************************************************************/
3526 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
3528 /* Make menus on frame F appear as specified by the `menu' face. */
3530 static void
3531 x_update_menu_appearance (struct frame *f)
3533 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3534 XrmDatabase rdb;
3536 if (dpyinfo
3537 && (rdb = XrmGetDatabase (FRAME_X_DISPLAY (f)),
3538 rdb != NULL))
3540 char line[512];
3541 Lisp_Object lface = lface_from_face_name (f, Qmenu, 1);
3542 struct face *face = FACE_FROM_ID (f, MENU_FACE_ID);
3543 const char *myname = SSDATA (Vx_resource_name);
3544 int changed_p = 0;
3545 #ifdef USE_MOTIF
3546 const char *popup_path = "popup_menu";
3547 #else
3548 const char *popup_path = "menu.popup";
3549 #endif
3551 if (STRINGP (LFACE_FOREGROUND (lface)))
3553 sprintf (line, "%s.%s*foreground: %s",
3554 myname, popup_path,
3555 SDATA (LFACE_FOREGROUND (lface)));
3556 XrmPutLineResource (&rdb, line);
3557 sprintf (line, "%s.pane.menubar*foreground: %s",
3558 myname, SDATA (LFACE_FOREGROUND (lface)));
3559 XrmPutLineResource (&rdb, line);
3560 changed_p = 1;
3563 if (STRINGP (LFACE_BACKGROUND (lface)))
3565 sprintf (line, "%s.%s*background: %s",
3566 myname, popup_path,
3567 SDATA (LFACE_BACKGROUND (lface)));
3568 XrmPutLineResource (&rdb, line);
3569 sprintf (line, "%s.pane.menubar*background: %s",
3570 myname, SDATA (LFACE_BACKGROUND (lface)));
3571 XrmPutLineResource (&rdb, line);
3572 changed_p = 1;
3575 if (face->font
3576 /* On Solaris 5.8, it's been reported that the `menu' face
3577 can be unspecified here, during startup. Why this
3578 happens remains unknown. -- cyd */
3579 && FONTP (LFACE_FONT (lface))
3580 && (!UNSPECIFIEDP (LFACE_FAMILY (lface))
3581 || !UNSPECIFIEDP (LFACE_FOUNDRY (lface))
3582 || !UNSPECIFIEDP (LFACE_SWIDTH (lface))
3583 || !UNSPECIFIEDP (LFACE_WEIGHT (lface))
3584 || !UNSPECIFIEDP (LFACE_SLANT (lface))
3585 || !UNSPECIFIEDP (LFACE_HEIGHT (lface))))
3587 Lisp_Object xlfd = Ffont_xlfd_name (LFACE_FONT (lface), Qnil);
3588 #ifdef USE_MOTIF
3589 const char *suffix = "List";
3590 Bool motif = True;
3591 #else
3592 #if defined HAVE_X_I18N
3594 const char *suffix = "Set";
3595 #else
3596 const char *suffix = "";
3597 #endif
3598 Bool motif = False;
3599 #endif
3601 if (! NILP (xlfd))
3603 #if defined HAVE_X_I18N
3604 char *fontsetname = xic_create_fontsetname (SSDATA (xlfd), motif);
3605 #else
3606 char *fontsetname = SSDATA (xlfd);
3607 #endif
3608 sprintf (line, "%s.pane.menubar*font%s: %s",
3609 myname, suffix, fontsetname);
3610 XrmPutLineResource (&rdb, line);
3611 sprintf (line, "%s.%s*font%s: %s",
3612 myname, popup_path, suffix, fontsetname);
3613 XrmPutLineResource (&rdb, line);
3614 changed_p = 1;
3615 if (fontsetname != SSDATA (xlfd))
3616 xfree (fontsetname);
3620 if (changed_p && f->output_data.x->menubar_widget)
3621 free_frame_menubar (f);
3625 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
3628 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p,
3629 Sface_attribute_relative_p,
3630 2, 2, 0,
3631 doc: /* Check whether a face attribute value is relative.
3632 Specifically, this function returns t if the attribute ATTRIBUTE
3633 with the value VALUE is relative.
3635 A relative value is one that doesn't entirely override whatever is
3636 inherited from another face. For most possible attributes,
3637 the only relative value that users see is `unspecified'.
3638 However, for :height, floating point values are also relative. */)
3639 (Lisp_Object attribute, Lisp_Object value)
3641 if (EQ (value, Qunspecified) || (EQ (value, Qignore_defface)))
3642 return Qt;
3643 else if (EQ (attribute, QCheight))
3644 return INTEGERP (value) ? Qnil : Qt;
3645 else
3646 return Qnil;
3649 DEFUN ("merge-face-attribute", Fmerge_face_attribute, Smerge_face_attribute,
3650 3, 3, 0,
3651 doc: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
3652 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
3653 the result will be absolute, otherwise it will be relative. */)
3654 (Lisp_Object attribute, Lisp_Object value1, Lisp_Object value2)
3656 if (EQ (value1, Qunspecified) || EQ (value1, Qignore_defface))
3657 return value2;
3658 else if (EQ (attribute, QCheight))
3659 return merge_face_heights (value1, value2, value1);
3660 else
3661 return value1;
3665 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute,
3666 Sinternal_get_lisp_face_attribute,
3667 2, 3, 0,
3668 doc: /* Return face attribute KEYWORD of face SYMBOL.
3669 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
3670 face attribute name, signal an error.
3671 If the optional argument FRAME is given, report on face SYMBOL in that
3672 frame. If FRAME is t, report on the defaults for face SYMBOL (for new
3673 frames). If FRAME is omitted or nil, use the selected frame. */)
3674 (Lisp_Object symbol, Lisp_Object keyword, Lisp_Object frame)
3676 Lisp_Object lface, value = Qnil;
3678 CHECK_SYMBOL (symbol);
3679 CHECK_SYMBOL (keyword);
3681 if (EQ (frame, Qt))
3682 lface = lface_from_face_name (NULL, symbol, 1);
3683 else
3685 if (NILP (frame))
3686 frame = selected_frame;
3687 CHECK_LIVE_FRAME (frame);
3688 lface = lface_from_face_name (XFRAME (frame), symbol, 1);
3691 if (EQ (keyword, QCfamily))
3692 value = LFACE_FAMILY (lface);
3693 else if (EQ (keyword, QCfoundry))
3694 value = LFACE_FOUNDRY (lface);
3695 else if (EQ (keyword, QCheight))
3696 value = LFACE_HEIGHT (lface);
3697 else if (EQ (keyword, QCweight))
3698 value = LFACE_WEIGHT (lface);
3699 else if (EQ (keyword, QCslant))
3700 value = LFACE_SLANT (lface);
3701 else if (EQ (keyword, QCunderline))
3702 value = LFACE_UNDERLINE (lface);
3703 else if (EQ (keyword, QCoverline))
3704 value = LFACE_OVERLINE (lface);
3705 else if (EQ (keyword, QCstrike_through))
3706 value = LFACE_STRIKE_THROUGH (lface);
3707 else if (EQ (keyword, QCbox))
3708 value = LFACE_BOX (lface);
3709 else if (EQ (keyword, QCinverse_video)
3710 || EQ (keyword, QCreverse_video))
3711 value = LFACE_INVERSE (lface);
3712 else if (EQ (keyword, QCforeground))
3713 value = LFACE_FOREGROUND (lface);
3714 else if (EQ (keyword, QCbackground))
3715 value = LFACE_BACKGROUND (lface);
3716 else if (EQ (keyword, QCstipple))
3717 value = LFACE_STIPPLE (lface);
3718 else if (EQ (keyword, QCwidth))
3719 value = LFACE_SWIDTH (lface);
3720 else if (EQ (keyword, QCinherit))
3721 value = LFACE_INHERIT (lface);
3722 else if (EQ (keyword, QCfont))
3723 value = LFACE_FONT (lface);
3724 else if (EQ (keyword, QCfontset))
3725 value = LFACE_FONTSET (lface);
3726 else
3727 signal_error ("Invalid face attribute name", keyword);
3729 if (IGNORE_DEFFACE_P (value))
3730 return Qunspecified;
3732 return value;
3736 DEFUN ("internal-lisp-face-attribute-values",
3737 Finternal_lisp_face_attribute_values,
3738 Sinternal_lisp_face_attribute_values, 1, 1, 0,
3739 doc: /* Return a list of valid discrete values for face attribute ATTR.
3740 Value is nil if ATTR doesn't have a discrete set of valid values. */)
3741 (Lisp_Object attr)
3743 Lisp_Object result = Qnil;
3745 CHECK_SYMBOL (attr);
3747 if (EQ (attr, QCunderline))
3748 result = Fcons (Qt, Fcons (Qnil, Qnil));
3749 else if (EQ (attr, QCoverline))
3750 result = Fcons (Qt, Fcons (Qnil, Qnil));
3751 else if (EQ (attr, QCstrike_through))
3752 result = Fcons (Qt, Fcons (Qnil, Qnil));
3753 else if (EQ (attr, QCinverse_video) || EQ (attr, QCreverse_video))
3754 result = Fcons (Qt, Fcons (Qnil, Qnil));
3756 return result;
3760 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face,
3761 Sinternal_merge_in_global_face, 2, 2, 0,
3762 doc: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
3763 Default face attributes override any local face attributes. */)
3764 (Lisp_Object face, Lisp_Object frame)
3766 int i;
3767 Lisp_Object global_lface, local_lface, *gvec, *lvec;
3768 struct frame *f = XFRAME (frame);
3770 CHECK_LIVE_FRAME (frame);
3771 global_lface = lface_from_face_name (NULL, face, 1);
3772 local_lface = lface_from_face_name (f, face, 0);
3773 if (NILP (local_lface))
3774 local_lface = Finternal_make_lisp_face (face, frame);
3776 /* Make every specified global attribute override the local one.
3777 BEWARE!! This is only used from `face-set-after-frame-default' where
3778 the local frame is defined from default specs in `face-defface-spec'
3779 and those should be overridden by global settings. Hence the strange
3780 "global before local" priority. */
3781 lvec = XVECTOR (local_lface)->contents;
3782 gvec = XVECTOR (global_lface)->contents;
3783 for (i = 1; i < LFACE_VECTOR_SIZE; ++i)
3784 if (IGNORE_DEFFACE_P (gvec[i]))
3785 lvec[i] = Qunspecified;
3786 else if (! UNSPECIFIEDP (gvec[i]))
3787 lvec[i] = gvec[i];
3789 /* If the default face was changed, update the face cache and the
3790 `font' frame parameter. */
3791 if (EQ (face, Qdefault))
3793 struct face_cache *c = FRAME_FACE_CACHE (f);
3794 struct face *newface, *oldface = FACE_FROM_ID (f, DEFAULT_FACE_ID);
3795 Lisp_Object attrs[LFACE_VECTOR_SIZE];
3797 /* This can be NULL (e.g., in batch mode). */
3798 if (oldface)
3800 /* Ensure that the face vector is fully specified by merging
3801 the previously-cached vector. */
3802 memcpy (attrs, oldface->lface, sizeof attrs);
3803 merge_face_vectors (f, lvec, attrs, 0);
3804 memcpy (lvec, attrs, sizeof attrs);
3805 newface = realize_face (c, lvec, DEFAULT_FACE_ID);
3807 if ((! UNSPECIFIEDP (gvec[LFACE_FAMILY_INDEX])
3808 || ! UNSPECIFIEDP (gvec[LFACE_FOUNDRY_INDEX])
3809 || ! UNSPECIFIEDP (gvec[LFACE_HEIGHT_INDEX])
3810 || ! UNSPECIFIEDP (gvec[LFACE_WEIGHT_INDEX])
3811 || ! UNSPECIFIEDP (gvec[LFACE_SLANT_INDEX])
3812 || ! UNSPECIFIEDP (gvec[LFACE_SWIDTH_INDEX])
3813 || ! UNSPECIFIEDP (gvec[LFACE_FONT_INDEX]))
3814 && newface->font)
3816 Lisp_Object name = newface->font->props[FONT_NAME_INDEX];
3817 Fmodify_frame_parameters (frame, Fcons (Fcons (Qfont, name),
3818 Qnil));
3823 return Qnil;
3827 /* The following function is implemented for compatibility with 20.2.
3828 The function is used in x-resolve-fonts when it is asked to
3829 return fonts with the same size as the font of a face. This is
3830 done in fontset.el. */
3832 DEFUN ("face-font", Fface_font, Sface_font, 1, 3, 0,
3833 doc: /* Return the font name of face FACE, or nil if it is unspecified.
3834 The font name is, by default, for ASCII characters.
3835 If the optional argument FRAME is given, report on face FACE in that frame.
3836 If FRAME is t, report on the defaults for face FACE (for new frames).
3837 The font default for a face is either nil, or a list
3838 of the form (bold), (italic) or (bold italic).
3839 If FRAME is omitted or nil, use the selected frame. And, in this case,
3840 if the optional third argument CHARACTER is given,
3841 return the font name used for CHARACTER. */)
3842 (Lisp_Object face, Lisp_Object frame, Lisp_Object character)
3844 if (EQ (frame, Qt))
3846 Lisp_Object result = Qnil;
3847 Lisp_Object lface = lface_from_face_name (NULL, face, 1);
3849 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface))
3850 && !EQ (LFACE_WEIGHT (lface), Qnormal))
3851 result = Fcons (Qbold, result);
3853 if (!UNSPECIFIEDP (LFACE_SLANT (lface))
3854 && !EQ (LFACE_SLANT (lface), Qnormal))
3855 result = Fcons (Qitalic, result);
3857 return result;
3859 else
3861 struct frame *f = frame_or_selected_frame (frame, 1);
3862 int face_id = lookup_named_face (f, face, 1);
3863 struct face *fface = FACE_FROM_ID (f, face_id);
3865 if (! fface)
3866 return Qnil;
3867 #ifdef HAVE_WINDOW_SYSTEM
3868 if (FRAME_WINDOW_P (f) && !NILP (character))
3870 CHECK_CHARACTER (character);
3871 face_id = FACE_FOR_CHAR (f, fface, XINT (character), -1, Qnil);
3872 fface = FACE_FROM_ID (f, face_id);
3874 return (fface->font
3875 ? fface->font->props[FONT_NAME_INDEX]
3876 : Qnil);
3877 #else /* !HAVE_WINDOW_SYSTEM */
3878 return build_string (FRAME_MSDOS_P (f)
3879 ? "ms-dos"
3880 : FRAME_W32_P (f) ? "w32term"
3881 :"tty");
3882 #endif
3887 /* Compare face-attribute values v1 and v2 for equality. Value is non-zero if
3888 all attributes are `equal'. Tries to be fast because this function
3889 is called quite often. */
3891 static INLINE int
3892 face_attr_equal_p (Lisp_Object v1, Lisp_Object v2)
3894 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
3895 and the other is specified. */
3896 if (XTYPE (v1) != XTYPE (v2))
3897 return 0;
3899 if (EQ (v1, v2))
3900 return 1;
3902 switch (XTYPE (v1))
3904 case Lisp_String:
3905 if (SBYTES (v1) != SBYTES (v2))
3906 return 0;
3908 return memcmp (SDATA (v1), SDATA (v2), SBYTES (v1)) == 0;
3910 case_Lisp_Int:
3911 case Lisp_Symbol:
3912 return 0;
3914 default:
3915 return !NILP (Fequal (v1, v2));
3920 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
3921 all attributes are `equal'. Tries to be fast because this function
3922 is called quite often. */
3924 static INLINE int
3925 lface_equal_p (Lisp_Object *v1, Lisp_Object *v2)
3927 int i, equal_p = 1;
3929 for (i = 1; i < LFACE_VECTOR_SIZE && equal_p; ++i)
3930 equal_p = face_attr_equal_p (v1[i], v2[i]);
3932 return equal_p;
3936 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p,
3937 Sinternal_lisp_face_equal_p, 2, 3, 0,
3938 doc: /* True if FACE1 and FACE2 are equal.
3939 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
3940 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
3941 If FRAME is omitted or nil, use the selected frame. */)
3942 (Lisp_Object face1, Lisp_Object face2, Lisp_Object frame)
3944 int equal_p;
3945 struct frame *f;
3946 Lisp_Object lface1, lface2;
3948 if (EQ (frame, Qt))
3949 f = NULL;
3950 else
3951 /* Don't use check_x_frame here because this function is called
3952 before X frames exist. At that time, if FRAME is nil,
3953 selected_frame will be used which is the frame dumped with
3954 Emacs. That frame is not an X frame. */
3955 f = frame_or_selected_frame (frame, 2);
3957 lface1 = lface_from_face_name (f, face1, 1);
3958 lface2 = lface_from_face_name (f, face2, 1);
3959 equal_p = lface_equal_p (XVECTOR (lface1)->contents,
3960 XVECTOR (lface2)->contents);
3961 return equal_p ? Qt : Qnil;
3965 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p,
3966 Sinternal_lisp_face_empty_p, 1, 2, 0,
3967 doc: /* True if FACE has no attribute specified.
3968 If the optional argument FRAME is given, report on face FACE in that frame.
3969 If FRAME is t, report on the defaults for face FACE (for new frames).
3970 If FRAME is omitted or nil, use the selected frame. */)
3971 (Lisp_Object face, Lisp_Object frame)
3973 struct frame *f;
3974 Lisp_Object lface;
3975 int i;
3977 if (NILP (frame))
3978 frame = selected_frame;
3979 CHECK_LIVE_FRAME (frame);
3980 f = XFRAME (frame);
3982 if (EQ (frame, Qt))
3983 lface = lface_from_face_name (NULL, face, 1);
3984 else
3985 lface = lface_from_face_name (f, face, 1);
3987 for (i = 1; i < LFACE_VECTOR_SIZE; ++i)
3988 if (!UNSPECIFIEDP (AREF (lface, i)))
3989 break;
3991 return i == LFACE_VECTOR_SIZE ? Qt : Qnil;
3995 DEFUN ("frame-face-alist", Fframe_face_alist, Sframe_face_alist,
3996 0, 1, 0,
3997 doc: /* Return an alist of frame-local faces defined on FRAME.
3998 For internal use only. */)
3999 (Lisp_Object frame)
4001 struct frame *f = frame_or_selected_frame (frame, 0);
4002 return f->face_alist;
4006 /* Return a hash code for Lisp string STRING with case ignored. Used
4007 below in computing a hash value for a Lisp face. */
4009 static INLINE unsigned
4010 hash_string_case_insensitive (Lisp_Object string)
4012 const unsigned char *s;
4013 unsigned hash = 0;
4014 xassert (STRINGP (string));
4015 for (s = SDATA (string); *s; ++s)
4016 hash = (hash << 1) ^ tolower (*s);
4017 return hash;
4021 /* Return a hash code for face attribute vector V. */
4023 static INLINE unsigned
4024 lface_hash (Lisp_Object *v)
4026 return (hash_string_case_insensitive (v[LFACE_FAMILY_INDEX])
4027 ^ hash_string_case_insensitive (v[LFACE_FOUNDRY_INDEX])
4028 ^ hash_string_case_insensitive (v[LFACE_FOREGROUND_INDEX])
4029 ^ hash_string_case_insensitive (v[LFACE_BACKGROUND_INDEX])
4030 ^ XHASH (v[LFACE_WEIGHT_INDEX])
4031 ^ XHASH (v[LFACE_SLANT_INDEX])
4032 ^ XHASH (v[LFACE_SWIDTH_INDEX])
4033 ^ XHASH (v[LFACE_HEIGHT_INDEX]));
4037 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
4038 considering charsets/registries). They do if they specify the same
4039 family, point size, weight, width, slant, and font. Both
4040 LFACE1 and LFACE2 must be fully-specified. */
4042 static INLINE int
4043 lface_same_font_attributes_p (Lisp_Object *lface1, Lisp_Object *lface2)
4045 xassert (lface_fully_specified_p (lface1)
4046 && lface_fully_specified_p (lface2));
4047 return (xstrcasecmp (SSDATA (lface1[LFACE_FAMILY_INDEX]),
4048 SSDATA (lface2[LFACE_FAMILY_INDEX])) == 0
4049 && xstrcasecmp (SSDATA (lface1[LFACE_FOUNDRY_INDEX]),
4050 SSDATA (lface2[LFACE_FOUNDRY_INDEX])) == 0
4051 && EQ (lface1[LFACE_HEIGHT_INDEX], lface2[LFACE_HEIGHT_INDEX])
4052 && EQ (lface1[LFACE_SWIDTH_INDEX], lface2[LFACE_SWIDTH_INDEX])
4053 && EQ (lface1[LFACE_WEIGHT_INDEX], lface2[LFACE_WEIGHT_INDEX])
4054 && EQ (lface1[LFACE_SLANT_INDEX], lface2[LFACE_SLANT_INDEX])
4055 && EQ (lface1[LFACE_FONT_INDEX], lface2[LFACE_FONT_INDEX])
4056 && (EQ (lface1[LFACE_FONTSET_INDEX], lface2[LFACE_FONTSET_INDEX])
4057 || (STRINGP (lface1[LFACE_FONTSET_INDEX])
4058 && STRINGP (lface2[LFACE_FONTSET_INDEX])
4059 && ! xstrcasecmp (SSDATA (lface1[LFACE_FONTSET_INDEX]),
4060 SSDATA (lface2[LFACE_FONTSET_INDEX]))))
4066 /***********************************************************************
4067 Realized Faces
4068 ***********************************************************************/
4070 /* Allocate and return a new realized face for Lisp face attribute
4071 vector ATTR. */
4073 static struct face *
4074 make_realized_face (Lisp_Object *attr)
4076 struct face *face = (struct face *) xmalloc (sizeof *face);
4077 memset (face, 0, sizeof *face);
4078 face->ascii_face = face;
4079 memcpy (face->lface, attr, sizeof face->lface);
4080 return face;
4084 /* Free realized face FACE, including its X resources. FACE may
4085 be null. */
4087 void
4088 free_realized_face (struct frame *f, struct face *face)
4090 if (face)
4092 #ifdef HAVE_WINDOW_SYSTEM
4093 if (FRAME_WINDOW_P (f))
4095 /* Free fontset of FACE if it is ASCII face. */
4096 if (face->fontset >= 0 && face == face->ascii_face)
4097 free_face_fontset (f, face);
4098 if (face->gc)
4100 BLOCK_INPUT;
4101 if (face->font)
4102 font_done_for_face (f, face);
4103 x_free_gc (f, face->gc);
4104 face->gc = 0;
4105 UNBLOCK_INPUT;
4108 free_face_colors (f, face);
4109 x_destroy_bitmap (f, face->stipple);
4111 #endif /* HAVE_WINDOW_SYSTEM */
4113 xfree (face);
4118 /* Prepare face FACE for subsequent display on frame F. This
4119 allocated GCs if they haven't been allocated yet or have been freed
4120 by clearing the face cache. */
4122 void
4123 prepare_face_for_display (struct frame *f, struct face *face)
4125 #ifdef HAVE_WINDOW_SYSTEM
4126 xassert (FRAME_WINDOW_P (f));
4128 if (face->gc == 0)
4130 XGCValues xgcv;
4131 unsigned long mask = GCForeground | GCBackground | GCGraphicsExposures;
4133 xgcv.foreground = face->foreground;
4134 xgcv.background = face->background;
4135 #ifdef HAVE_X_WINDOWS
4136 xgcv.graphics_exposures = False;
4137 #endif
4139 BLOCK_INPUT;
4140 #ifdef HAVE_X_WINDOWS
4141 if (face->stipple)
4143 xgcv.fill_style = FillOpaqueStippled;
4144 xgcv.stipple = x_bitmap_pixmap (f, face->stipple);
4145 mask |= GCFillStyle | GCStipple;
4147 #endif
4148 face->gc = x_create_gc (f, mask, &xgcv);
4149 if (face->font)
4150 font_prepare_for_face (f, face);
4151 UNBLOCK_INPUT;
4153 #endif /* HAVE_WINDOW_SYSTEM */
4157 /* Returns the `distance' between the colors X and Y. */
4159 static int
4160 color_distance (XColor *x, XColor *y)
4162 /* This formula is from a paper title `Colour metric' by Thiadmer Riemersma.
4163 Quoting from that paper:
4165 This formula has results that are very close to L*u*v* (with the
4166 modified lightness curve) and, more importantly, it is a more even
4167 algorithm: it does not have a range of colours where it suddenly
4168 gives far from optimal results.
4170 See <http://www.compuphase.com/cmetric.htm> for more info. */
4172 long r = (x->red - y->red) >> 8;
4173 long g = (x->green - y->green) >> 8;
4174 long b = (x->blue - y->blue) >> 8;
4175 long r_mean = (x->red + y->red) >> 9;
4177 return
4178 (((512 + r_mean) * r * r) >> 8)
4179 + 4 * g * g
4180 + (((767 - r_mean) * b * b) >> 8);
4184 DEFUN ("color-distance", Fcolor_distance, Scolor_distance, 2, 3, 0,
4185 doc: /* Return an integer distance between COLOR1 and COLOR2 on FRAME.
4186 COLOR1 and COLOR2 may be either strings containing the color name,
4187 or lists of the form (RED GREEN BLUE).
4188 If FRAME is unspecified or nil, the current frame is used. */)
4189 (Lisp_Object color1, Lisp_Object color2, Lisp_Object frame)
4191 struct frame *f;
4192 XColor cdef1, cdef2;
4194 if (NILP (frame))
4195 frame = selected_frame;
4196 CHECK_LIVE_FRAME (frame);
4197 f = XFRAME (frame);
4199 if (!(CONSP (color1) && parse_rgb_list (color1, &cdef1))
4200 && !(STRINGP (color1) && defined_color (f, SSDATA (color1), &cdef1, 0)))
4201 signal_error ("Invalid color", color1);
4202 if (!(CONSP (color2) && parse_rgb_list (color2, &cdef2))
4203 && !(STRINGP (color2) && defined_color (f, SSDATA (color2), &cdef2, 0)))
4204 signal_error ("Invalid color", color2);
4206 return make_number (color_distance (&cdef1, &cdef2));
4210 /***********************************************************************
4211 Face Cache
4212 ***********************************************************************/
4214 /* Return a new face cache for frame F. */
4216 static struct face_cache *
4217 make_face_cache (struct frame *f)
4219 struct face_cache *c;
4220 int size;
4222 c = (struct face_cache *) xmalloc (sizeof *c);
4223 memset (c, 0, sizeof *c);
4224 size = FACE_CACHE_BUCKETS_SIZE * sizeof *c->buckets;
4225 c->buckets = (struct face **) xmalloc (size);
4226 memset (c->buckets, 0, size);
4227 c->size = 50;
4228 c->faces_by_id = (struct face **) xmalloc (c->size * sizeof *c->faces_by_id);
4229 c->f = f;
4230 c->menu_face_changed_p = menu_face_changed_default;
4231 return c;
4235 /* Clear out all graphics contexts for all realized faces, except for
4236 the basic faces. This should be done from time to time just to avoid
4237 keeping too many graphics contexts that are no longer needed. */
4239 static void
4240 clear_face_gcs (struct face_cache *c)
4242 if (c && FRAME_WINDOW_P (c->f))
4244 #ifdef HAVE_WINDOW_SYSTEM
4245 int i;
4246 for (i = BASIC_FACE_ID_SENTINEL; i < c->used; ++i)
4248 struct face *face = c->faces_by_id[i];
4249 if (face && face->gc)
4251 BLOCK_INPUT;
4252 if (face->font)
4253 font_done_for_face (c->f, face);
4254 x_free_gc (c->f, face->gc);
4255 face->gc = 0;
4256 UNBLOCK_INPUT;
4259 #endif /* HAVE_WINDOW_SYSTEM */
4264 /* Free all realized faces in face cache C, including basic faces.
4265 C may be null. If faces are freed, make sure the frame's current
4266 matrix is marked invalid, so that a display caused by an expose
4267 event doesn't try to use faces we destroyed. */
4269 static void
4270 free_realized_faces (struct face_cache *c)
4272 if (c && c->used)
4274 int i, size;
4275 struct frame *f = c->f;
4277 /* We must block input here because we can't process X events
4278 safely while only some faces are freed, or when the frame's
4279 current matrix still references freed faces. */
4280 BLOCK_INPUT;
4282 for (i = 0; i < c->used; ++i)
4284 free_realized_face (f, c->faces_by_id[i]);
4285 c->faces_by_id[i] = NULL;
4288 c->used = 0;
4289 size = FACE_CACHE_BUCKETS_SIZE * sizeof *c->buckets;
4290 memset (c->buckets, 0, size);
4292 /* Must do a thorough redisplay the next time. Mark current
4293 matrices as invalid because they will reference faces freed
4294 above. This function is also called when a frame is
4295 destroyed. In this case, the root window of F is nil. */
4296 if (WINDOWP (f->root_window))
4298 clear_current_matrices (f);
4299 ++windows_or_buffers_changed;
4302 UNBLOCK_INPUT;
4307 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
4308 This is done after attributes of a named face have been changed,
4309 because we can't tell which realized faces depend on that face. */
4311 void
4312 free_all_realized_faces (Lisp_Object frame)
4314 if (NILP (frame))
4316 Lisp_Object rest;
4317 FOR_EACH_FRAME (rest, frame)
4318 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame)));
4320 else
4321 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame)));
4325 /* Free face cache C and faces in it, including their X resources. */
4327 static void
4328 free_face_cache (struct face_cache *c)
4330 if (c)
4332 free_realized_faces (c);
4333 xfree (c->buckets);
4334 xfree (c->faces_by_id);
4335 xfree (c);
4340 /* Cache realized face FACE in face cache C. HASH is the hash value
4341 of FACE. If FACE is for ASCII characters (i.e. FACE->ascii_face ==
4342 FACE), insert the new face to the beginning of the collision list
4343 of the face hash table of C. Otherwise, add the new face to the
4344 end of the collision list. This way, lookup_face can quickly find
4345 that a requested face is not cached. */
4347 static void
4348 cache_face (struct face_cache *c, struct face *face, unsigned int hash)
4350 int i = hash % FACE_CACHE_BUCKETS_SIZE;
4352 face->hash = hash;
4354 if (face->ascii_face != face)
4356 struct face *last = c->buckets[i];
4357 if (last)
4359 while (last->next)
4360 last = last->next;
4361 last->next = face;
4362 face->prev = last;
4363 face->next = NULL;
4365 else
4367 c->buckets[i] = face;
4368 face->prev = face->next = NULL;
4371 else
4373 face->prev = NULL;
4374 face->next = c->buckets[i];
4375 if (face->next)
4376 face->next->prev = face;
4377 c->buckets[i] = face;
4380 /* Find a free slot in C->faces_by_id and use the index of the free
4381 slot as FACE->id. */
4382 for (i = 0; i < c->used; ++i)
4383 if (c->faces_by_id[i] == NULL)
4384 break;
4385 face->id = i;
4387 /* Maybe enlarge C->faces_by_id. */
4388 if (i == c->used)
4390 if (c->used == c->size)
4392 int new_size, sz;
4393 new_size = min (2 * c->size, MAX_FACE_ID);
4394 if (new_size == c->size)
4395 abort (); /* Alternatives? ++kfs */
4396 sz = new_size * sizeof *c->faces_by_id;
4397 c->faces_by_id = (struct face **) xrealloc (c->faces_by_id, sz);
4398 c->size = new_size;
4400 c->used++;
4403 #if GLYPH_DEBUG
4404 /* Check that FACE got a unique id. */
4406 int j, n;
4407 struct face *face;
4409 for (j = n = 0; j < FACE_CACHE_BUCKETS_SIZE; ++j)
4410 for (face = c->buckets[j]; face; face = face->next)
4411 if (face->id == i)
4412 ++n;
4414 xassert (n == 1);
4416 #endif /* GLYPH_DEBUG */
4418 c->faces_by_id[i] = face;
4422 /* Remove face FACE from cache C. */
4424 static void
4425 uncache_face (struct face_cache *c, struct face *face)
4427 int i = face->hash % FACE_CACHE_BUCKETS_SIZE;
4429 if (face->prev)
4430 face->prev->next = face->next;
4431 else
4432 c->buckets[i] = face->next;
4434 if (face->next)
4435 face->next->prev = face->prev;
4437 c->faces_by_id[face->id] = NULL;
4438 if (face->id == c->used)
4439 --c->used;
4443 /* Look up a realized face with face attributes ATTR in the face cache
4444 of frame F. The face will be used to display ASCII characters.
4445 Value is the ID of the face found. If no suitable face is found,
4446 realize a new one. */
4448 static INLINE int
4449 lookup_face (struct frame *f, Lisp_Object *attr)
4451 struct face_cache *cache = FRAME_FACE_CACHE (f);
4452 unsigned hash;
4453 int i;
4454 struct face *face;
4456 xassert (cache != NULL);
4457 check_lface_attrs (attr);
4459 /* Look up ATTR in the face cache. */
4460 hash = lface_hash (attr);
4461 i = hash % FACE_CACHE_BUCKETS_SIZE;
4463 for (face = cache->buckets[i]; face; face = face->next)
4465 if (face->ascii_face != face)
4467 /* There's no more ASCII face. */
4468 face = NULL;
4469 break;
4471 if (face->hash == hash
4472 && lface_equal_p (face->lface, attr))
4473 break;
4476 /* If not found, realize a new face. */
4477 if (face == NULL)
4478 face = realize_face (cache, attr, -1);
4480 #if GLYPH_DEBUG
4481 xassert (face == FACE_FROM_ID (f, face->id));
4482 #endif /* GLYPH_DEBUG */
4484 return face->id;
4487 #ifdef HAVE_WINDOW_SYSTEM
4488 /* Look up a realized face that has the same attributes as BASE_FACE
4489 except for the font in the face cache of frame F. If FONT-OBJECT
4490 is not nil, it is an already opened font. If FONT-OBJECT is nil,
4491 the face has no font. Value is the ID of the face found. If no
4492 suitable face is found, realize a new one. */
4495 face_for_font (struct frame *f, Lisp_Object font_object, struct face *base_face)
4497 struct face_cache *cache = FRAME_FACE_CACHE (f);
4498 unsigned hash;
4499 int i;
4500 struct face *face;
4502 xassert (cache != NULL);
4503 base_face = base_face->ascii_face;
4504 hash = lface_hash (base_face->lface);
4505 i = hash % FACE_CACHE_BUCKETS_SIZE;
4507 for (face = cache->buckets[i]; face; face = face->next)
4509 if (face->ascii_face == face)
4510 continue;
4511 if (face->ascii_face == base_face
4512 && face->font == (NILP (font_object) ? NULL
4513 : XFONT_OBJECT (font_object))
4514 && lface_equal_p (face->lface, base_face->lface))
4515 return face->id;
4518 /* If not found, realize a new face. */
4519 face = realize_non_ascii_face (f, font_object, base_face);
4520 return face->id;
4522 #endif /* HAVE_WINDOW_SYSTEM */
4524 /* Return the face id of the realized face for named face SYMBOL on
4525 frame F suitable for displaying ASCII characters. Value is -1 if
4526 the face couldn't be determined, which might happen if the default
4527 face isn't realized and cannot be realized. */
4530 lookup_named_face (struct frame *f, Lisp_Object symbol, int signal_p)
4532 Lisp_Object attrs[LFACE_VECTOR_SIZE];
4533 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE];
4534 struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
4536 if (default_face == NULL)
4538 if (!realize_basic_faces (f))
4539 return -1;
4540 default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
4541 if (default_face == NULL)
4542 abort (); /* realize_basic_faces must have set it up */
4545 if (! get_lface_attributes (f, symbol, symbol_attrs, signal_p, 0))
4546 return -1;
4548 memcpy (attrs, default_face->lface, sizeof attrs);
4549 merge_face_vectors (f, symbol_attrs, attrs, 0);
4551 return lookup_face (f, attrs);
4555 /* Return the display face-id of the basic face who's canonical face-id
4556 is FACE_ID. The return value will usually simply be FACE_ID, unless that
4557 basic face has bee remapped via Vface_remapping_alist. This function is
4558 conservative: if something goes wrong, it will simply return FACE_ID
4559 rather than signal an error. */
4562 lookup_basic_face (struct frame *f, int face_id)
4564 Lisp_Object name, mapping;
4565 int remapped_face_id;
4567 if (NILP (Vface_remapping_alist))
4568 return face_id; /* Nothing to do. */
4570 switch (face_id)
4572 case DEFAULT_FACE_ID: name = Qdefault; break;
4573 case MODE_LINE_FACE_ID: name = Qmode_line; break;
4574 case MODE_LINE_INACTIVE_FACE_ID: name = Qmode_line_inactive; break;
4575 case HEADER_LINE_FACE_ID: name = Qheader_line; break;
4576 case TOOL_BAR_FACE_ID: name = Qtool_bar; break;
4577 case FRINGE_FACE_ID: name = Qfringe; break;
4578 case SCROLL_BAR_FACE_ID: name = Qscroll_bar; break;
4579 case BORDER_FACE_ID: name = Qborder; break;
4580 case CURSOR_FACE_ID: name = Qcursor; break;
4581 case MOUSE_FACE_ID: name = Qmouse; break;
4582 case MENU_FACE_ID: name = Qmenu; break;
4584 default:
4585 abort (); /* the caller is supposed to pass us a basic face id */
4588 /* Do a quick scan through Vface_remapping_alist, and return immediately
4589 if there is no remapping for face NAME. This is just an optimization
4590 for the very common no-remapping case. */
4591 mapping = assq_no_quit (name, Vface_remapping_alist);
4592 if (NILP (mapping))
4593 return face_id; /* Give up. */
4595 /* If there is a remapping entry, lookup the face using NAME, which will
4596 handle the remapping too. */
4597 remapped_face_id = lookup_named_face (f, name, 0);
4598 if (remapped_face_id < 0)
4599 return face_id; /* Give up. */
4601 return remapped_face_id;
4605 /* Return the ID of the realized ASCII face of Lisp face with ID
4606 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
4609 ascii_face_of_lisp_face (struct frame *f, int lface_id)
4611 int face_id;
4613 if (lface_id >= 0 && lface_id < lface_id_to_name_size)
4615 Lisp_Object face_name = lface_id_to_name[lface_id];
4616 face_id = lookup_named_face (f, face_name, 1);
4618 else
4619 face_id = -1;
4621 return face_id;
4625 /* Return a face for charset ASCII that is like the face with id
4626 FACE_ID on frame F, but has a font that is STEPS steps smaller.
4627 STEPS < 0 means larger. Value is the id of the face. */
4630 smaller_face (struct frame *f, int face_id, int steps)
4632 #ifdef HAVE_WINDOW_SYSTEM
4633 struct face *face;
4634 Lisp_Object attrs[LFACE_VECTOR_SIZE];
4635 int pt, last_pt, last_height;
4636 int delta;
4637 int new_face_id;
4638 struct face *new_face;
4640 /* If not called for an X frame, just return the original face. */
4641 if (FRAME_TERMCAP_P (f))
4642 return face_id;
4644 /* Try in increments of 1/2 pt. */
4645 delta = steps < 0 ? 5 : -5;
4646 steps = eabs (steps);
4648 face = FACE_FROM_ID (f, face_id);
4649 memcpy (attrs, face->lface, sizeof attrs);
4650 pt = last_pt = XFASTINT (attrs[LFACE_HEIGHT_INDEX]);
4651 new_face_id = face_id;
4652 last_height = FONT_HEIGHT (face->font);
4654 while (steps
4655 && pt + delta > 0
4656 /* Give up if we cannot find a font within 10pt. */
4657 && eabs (last_pt - pt) < 100)
4659 /* Look up a face for a slightly smaller/larger font. */
4660 pt += delta;
4661 attrs[LFACE_HEIGHT_INDEX] = make_number (pt);
4662 new_face_id = lookup_face (f, attrs);
4663 new_face = FACE_FROM_ID (f, new_face_id);
4665 /* If height changes, count that as one step. */
4666 if ((delta < 0 && FONT_HEIGHT (new_face->font) < last_height)
4667 || (delta > 0 && FONT_HEIGHT (new_face->font) > last_height))
4669 --steps;
4670 last_height = FONT_HEIGHT (new_face->font);
4671 last_pt = pt;
4675 return new_face_id;
4677 #else /* not HAVE_WINDOW_SYSTEM */
4679 return face_id;
4681 #endif /* not HAVE_WINDOW_SYSTEM */
4685 /* Return a face for charset ASCII that is like the face with id
4686 FACE_ID on frame F, but has height HEIGHT. */
4689 face_with_height (struct frame *f, int face_id, int height)
4691 #ifdef HAVE_WINDOW_SYSTEM
4692 struct face *face;
4693 Lisp_Object attrs[LFACE_VECTOR_SIZE];
4695 if (FRAME_TERMCAP_P (f)
4696 || height <= 0)
4697 return face_id;
4699 face = FACE_FROM_ID (f, face_id);
4700 memcpy (attrs, face->lface, sizeof attrs);
4701 attrs[LFACE_HEIGHT_INDEX] = make_number (height);
4702 font_clear_prop (attrs, FONT_SIZE_INDEX);
4703 face_id = lookup_face (f, attrs);
4704 #endif /* HAVE_WINDOW_SYSTEM */
4706 return face_id;
4710 /* Return the face id of the realized face for named face SYMBOL on
4711 frame F suitable for displaying ASCII characters, and use
4712 attributes of the face FACE_ID for attributes that aren't
4713 completely specified by SYMBOL. This is like lookup_named_face,
4714 except that the default attributes come from FACE_ID, not from the
4715 default face. FACE_ID is assumed to be already realized. */
4718 lookup_derived_face (struct frame *f, Lisp_Object symbol, int face_id, int signal_p)
4720 Lisp_Object attrs[LFACE_VECTOR_SIZE];
4721 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE];
4722 struct face *default_face = FACE_FROM_ID (f, face_id);
4724 if (!default_face)
4725 abort ();
4727 if (!get_lface_attributes (f, symbol, symbol_attrs, signal_p, 0))
4728 return -1;
4730 memcpy (attrs, default_face->lface, sizeof attrs);
4731 merge_face_vectors (f, symbol_attrs, attrs, 0);
4732 return lookup_face (f, attrs);
4735 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector,
4736 Sface_attributes_as_vector, 1, 1, 0,
4737 doc: /* Return a vector of face attributes corresponding to PLIST. */)
4738 (Lisp_Object plist)
4740 Lisp_Object lface;
4741 lface = Fmake_vector (make_number (LFACE_VECTOR_SIZE),
4742 Qunspecified);
4743 merge_face_ref (XFRAME (selected_frame), plist, XVECTOR (lface)->contents,
4744 1, 0);
4745 return lface;
4750 /***********************************************************************
4751 Face capability testing
4752 ***********************************************************************/
4755 /* If the distance (as returned by color_distance) between two colors is
4756 less than this, then they are considered the same, for determining
4757 whether a color is supported or not. The range of values is 0-65535. */
4759 #define TTY_SAME_COLOR_THRESHOLD 10000
4761 #ifdef HAVE_WINDOW_SYSTEM
4763 /* Return non-zero if all the face attributes in ATTRS are supported
4764 on the window-system frame F.
4766 The definition of `supported' is somewhat heuristic, but basically means
4767 that a face containing all the attributes in ATTRS, when merged with the
4768 default face for display, can be represented in a way that's
4770 \(1) different in appearance than the default face, and
4771 \(2) `close in spirit' to what the attributes specify, if not exact. */
4773 static int
4774 x_supports_face_attributes_p (struct frame *f, Lisp_Object *attrs, struct face *def_face)
4776 Lisp_Object *def_attrs = def_face->lface;
4778 /* Check that other specified attributes are different that the default
4779 face. */
4780 if ((!UNSPECIFIEDP (attrs[LFACE_UNDERLINE_INDEX])
4781 && face_attr_equal_p (attrs[LFACE_UNDERLINE_INDEX],
4782 def_attrs[LFACE_UNDERLINE_INDEX]))
4783 || (!UNSPECIFIEDP (attrs[LFACE_INVERSE_INDEX])
4784 && face_attr_equal_p (attrs[LFACE_INVERSE_INDEX],
4785 def_attrs[LFACE_INVERSE_INDEX]))
4786 || (!UNSPECIFIEDP (attrs[LFACE_FOREGROUND_INDEX])
4787 && face_attr_equal_p (attrs[LFACE_FOREGROUND_INDEX],
4788 def_attrs[LFACE_FOREGROUND_INDEX]))
4789 || (!UNSPECIFIEDP (attrs[LFACE_BACKGROUND_INDEX])
4790 && face_attr_equal_p (attrs[LFACE_BACKGROUND_INDEX],
4791 def_attrs[LFACE_BACKGROUND_INDEX]))
4792 || (!UNSPECIFIEDP (attrs[LFACE_STIPPLE_INDEX])
4793 && face_attr_equal_p (attrs[LFACE_STIPPLE_INDEX],
4794 def_attrs[LFACE_STIPPLE_INDEX]))
4795 || (!UNSPECIFIEDP (attrs[LFACE_OVERLINE_INDEX])
4796 && face_attr_equal_p (attrs[LFACE_OVERLINE_INDEX],
4797 def_attrs[LFACE_OVERLINE_INDEX]))
4798 || (!UNSPECIFIEDP (attrs[LFACE_STRIKE_THROUGH_INDEX])
4799 && face_attr_equal_p (attrs[LFACE_STRIKE_THROUGH_INDEX],
4800 def_attrs[LFACE_STRIKE_THROUGH_INDEX]))
4801 || (!UNSPECIFIEDP (attrs[LFACE_BOX_INDEX])
4802 && face_attr_equal_p (attrs[LFACE_BOX_INDEX],
4803 def_attrs[LFACE_BOX_INDEX])))
4804 return 0;
4806 /* Check font-related attributes, as those are the most commonly
4807 "unsupported" on a window-system (because of missing fonts). */
4808 if (!UNSPECIFIEDP (attrs[LFACE_FAMILY_INDEX])
4809 || !UNSPECIFIEDP (attrs[LFACE_FOUNDRY_INDEX])
4810 || !UNSPECIFIEDP (attrs[LFACE_HEIGHT_INDEX])
4811 || !UNSPECIFIEDP (attrs[LFACE_WEIGHT_INDEX])
4812 || !UNSPECIFIEDP (attrs[LFACE_SLANT_INDEX])
4813 || !UNSPECIFIEDP (attrs[LFACE_SWIDTH_INDEX]))
4815 int face_id;
4816 struct face *face;
4817 Lisp_Object merged_attrs[LFACE_VECTOR_SIZE];
4818 int i;
4820 memcpy (merged_attrs, def_attrs, sizeof merged_attrs);
4822 merge_face_vectors (f, attrs, merged_attrs, 0);
4824 face_id = lookup_face (f, merged_attrs);
4825 face = FACE_FROM_ID (f, face_id);
4827 if (! face)
4828 error ("Cannot make face");
4830 /* If the font is the same, or no font is found, then not
4831 supported. */
4832 if (face->font == def_face->font
4833 || ! face->font)
4834 return 0;
4835 for (i = FONT_TYPE_INDEX; i <= FONT_SIZE_INDEX; i++)
4836 if (! EQ (face->font->props[i], def_face->font->props[i]))
4838 Lisp_Object s1, s2;
4840 if (i < FONT_FOUNDRY_INDEX || i > FONT_REGISTRY_INDEX
4841 || face->font->driver->case_sensitive)
4842 return 1;
4843 s1 = SYMBOL_NAME (face->font->props[i]);
4844 s2 = SYMBOL_NAME (def_face->font->props[i]);
4845 if (! EQ (Fcompare_strings (s1, make_number (0), Qnil,
4846 s2, make_number (0), Qnil, Qt), Qt))
4847 return 1;
4849 return 0;
4852 /* Everything checks out, this face is supported. */
4853 return 1;
4856 #endif /* HAVE_WINDOW_SYSTEM */
4858 /* Return non-zero if all the face attributes in ATTRS are supported
4859 on the tty frame F.
4861 The definition of `supported' is somewhat heuristic, but basically means
4862 that a face containing all the attributes in ATTRS, when merged
4863 with the default face for display, can be represented in a way that's
4865 \(1) different in appearance than the default face, and
4866 \(2) `close in spirit' to what the attributes specify, if not exact.
4868 Point (2) implies that a `:weight black' attribute will be satisfied
4869 by any terminal that can display bold, and a `:foreground "yellow"' as
4870 long as the terminal can display a yellowish color, but `:slant italic'
4871 will _not_ be satisfied by the tty display code's automatic
4872 substitution of a `dim' face for italic. */
4874 static int
4875 tty_supports_face_attributes_p (struct frame *f, Lisp_Object *attrs, struct face *def_face)
4877 int weight;
4878 Lisp_Object val, fg, bg;
4879 XColor fg_tty_color, fg_std_color;
4880 XColor bg_tty_color, bg_std_color;
4881 unsigned test_caps = 0;
4882 Lisp_Object *def_attrs = def_face->lface;
4885 /* First check some easy-to-check stuff; ttys support none of the
4886 following attributes, so we can just return false if any are requested
4887 (even if `nominal' values are specified, we should still return false,
4888 as that will be the same value that the default face uses). We
4889 consider :slant unsupportable on ttys, even though the face code
4890 actually `fakes' them using a dim attribute if possible. This is
4891 because the faked result is too different from what the face
4892 specifies. */
4893 if (!UNSPECIFIEDP (attrs[LFACE_FAMILY_INDEX])
4894 || !UNSPECIFIEDP (attrs[LFACE_FOUNDRY_INDEX])
4895 || !UNSPECIFIEDP (attrs[LFACE_STIPPLE_INDEX])
4896 || !UNSPECIFIEDP (attrs[LFACE_HEIGHT_INDEX])
4897 || !UNSPECIFIEDP (attrs[LFACE_SWIDTH_INDEX])
4898 || !UNSPECIFIEDP (attrs[LFACE_OVERLINE_INDEX])
4899 || !UNSPECIFIEDP (attrs[LFACE_STRIKE_THROUGH_INDEX])
4900 || !UNSPECIFIEDP (attrs[LFACE_BOX_INDEX])
4901 || !UNSPECIFIEDP (attrs[LFACE_SLANT_INDEX]))
4902 return 0;
4905 /* Test for terminal `capabilities' (non-color character attributes). */
4907 /* font weight (bold/dim) */
4908 val = attrs[LFACE_WEIGHT_INDEX];
4909 if (!UNSPECIFIEDP (val)
4910 && (weight = FONT_WEIGHT_NAME_NUMERIC (val), weight >= 0))
4912 int def_weight = FONT_WEIGHT_NAME_NUMERIC (def_attrs[LFACE_WEIGHT_INDEX]);
4914 if (weight > 100)
4916 if (def_weight > 100)
4917 return 0; /* same as default */
4918 test_caps = TTY_CAP_BOLD;
4920 else if (weight < 100)
4922 if (def_weight < 100)
4923 return 0; /* same as default */
4924 test_caps = TTY_CAP_DIM;
4926 else if (def_weight == 100)
4927 return 0; /* same as default */
4930 /* underlining */
4931 val = attrs[LFACE_UNDERLINE_INDEX];
4932 if (!UNSPECIFIEDP (val))
4934 if (STRINGP (val))
4935 return 0; /* ttys can't use colored underlines */
4936 else if (face_attr_equal_p (val, def_attrs[LFACE_UNDERLINE_INDEX]))
4937 return 0; /* same as default */
4938 else
4939 test_caps |= TTY_CAP_UNDERLINE;
4942 /* inverse video */
4943 val = attrs[LFACE_INVERSE_INDEX];
4944 if (!UNSPECIFIEDP (val))
4946 if (face_attr_equal_p (val, def_attrs[LFACE_INVERSE_INDEX]))
4947 return 0; /* same as default */
4948 else
4949 test_caps |= TTY_CAP_INVERSE;
4953 /* Color testing. */
4955 /* Default the color indices in FG_TTY_COLOR and BG_TTY_COLOR, since
4956 we use them when calling `tty_capable_p' below, even if the face
4957 specifies no colors. */
4958 fg_tty_color.pixel = FACE_TTY_DEFAULT_FG_COLOR;
4959 bg_tty_color.pixel = FACE_TTY_DEFAULT_BG_COLOR;
4961 /* Check if foreground color is close enough. */
4962 fg = attrs[LFACE_FOREGROUND_INDEX];
4963 if (STRINGP (fg))
4965 Lisp_Object def_fg = def_attrs[LFACE_FOREGROUND_INDEX];
4967 if (face_attr_equal_p (fg, def_fg))
4968 return 0; /* same as default */
4969 else if (! tty_lookup_color (f, fg, &fg_tty_color, &fg_std_color))
4970 return 0; /* not a valid color */
4971 else if (color_distance (&fg_tty_color, &fg_std_color)
4972 > TTY_SAME_COLOR_THRESHOLD)
4973 return 0; /* displayed color is too different */
4974 else
4975 /* Make sure the color is really different than the default. */
4977 XColor def_fg_color;
4978 if (tty_lookup_color (f, def_fg, &def_fg_color, 0)
4979 && (color_distance (&fg_tty_color, &def_fg_color)
4980 <= TTY_SAME_COLOR_THRESHOLD))
4981 return 0;
4985 /* Check if background color is close enough. */
4986 bg = attrs[LFACE_BACKGROUND_INDEX];
4987 if (STRINGP (bg))
4989 Lisp_Object def_bg = def_attrs[LFACE_BACKGROUND_INDEX];
4991 if (face_attr_equal_p (bg, def_bg))
4992 return 0; /* same as default */
4993 else if (! tty_lookup_color (f, bg, &bg_tty_color, &bg_std_color))
4994 return 0; /* not a valid color */
4995 else if (color_distance (&bg_tty_color, &bg_std_color)
4996 > TTY_SAME_COLOR_THRESHOLD)
4997 return 0; /* displayed color is too different */
4998 else
4999 /* Make sure the color is really different than the default. */
5001 XColor def_bg_color;
5002 if (tty_lookup_color (f, def_bg, &def_bg_color, 0)
5003 && (color_distance (&bg_tty_color, &def_bg_color)
5004 <= TTY_SAME_COLOR_THRESHOLD))
5005 return 0;
5009 /* If both foreground and background are requested, see if the
5010 distance between them is OK. We just check to see if the distance
5011 between the tty's foreground and background is close enough to the
5012 distance between the standard foreground and background. */
5013 if (STRINGP (fg) && STRINGP (bg))
5015 int delta_delta
5016 = (color_distance (&fg_std_color, &bg_std_color)
5017 - color_distance (&fg_tty_color, &bg_tty_color));
5018 if (delta_delta > TTY_SAME_COLOR_THRESHOLD
5019 || delta_delta < -TTY_SAME_COLOR_THRESHOLD)
5020 return 0;
5024 /* See if the capabilities we selected above are supported, with the
5025 given colors. */
5026 if (test_caps != 0 &&
5027 ! tty_capable_p (FRAME_TTY (f), test_caps, fg_tty_color.pixel, bg_tty_color.pixel))
5028 return 0;
5031 /* Hmmm, everything checks out, this terminal must support this face. */
5032 return 1;
5036 DEFUN ("display-supports-face-attributes-p",
5037 Fdisplay_supports_face_attributes_p, Sdisplay_supports_face_attributes_p,
5038 1, 2, 0,
5039 doc: /* Return non-nil if all the face attributes in ATTRIBUTES are supported.
5040 The optional argument DISPLAY can be a display name, a frame, or
5041 nil (meaning the selected frame's display).
5043 The definition of `supported' is somewhat heuristic, but basically means
5044 that a face containing all the attributes in ATTRIBUTES, when merged
5045 with the default face for display, can be represented in a way that's
5047 \(1) different in appearance than the default face, and
5048 \(2) `close in spirit' to what the attributes specify, if not exact.
5050 Point (2) implies that a `:weight black' attribute will be satisfied by
5051 any display that can display bold, and a `:foreground \"yellow\"' as long
5052 as it can display a yellowish color, but `:slant italic' will _not_ be
5053 satisfied by the tty display code's automatic substitution of a `dim'
5054 face for italic. */)
5055 (Lisp_Object attributes, Lisp_Object display)
5057 int supports = 0, i;
5058 Lisp_Object frame;
5059 struct frame *f;
5060 struct face *def_face;
5061 Lisp_Object attrs[LFACE_VECTOR_SIZE];
5063 if (noninteractive || !initialized)
5064 /* We may not be able to access low-level face information in batch
5065 mode, or before being dumped, and this function is not going to
5066 be very useful in those cases anyway, so just give up. */
5067 return Qnil;
5069 if (NILP (display))
5070 frame = selected_frame;
5071 else if (FRAMEP (display))
5072 frame = display;
5073 else
5075 /* Find any frame on DISPLAY. */
5076 Lisp_Object fl_tail;
5078 frame = Qnil;
5079 for (fl_tail = Vframe_list; CONSP (fl_tail); fl_tail = XCDR (fl_tail))
5081 frame = XCAR (fl_tail);
5082 if (!NILP (Fequal (Fcdr (Fassq (Qdisplay,
5083 XFRAME (frame)->param_alist)),
5084 display)))
5085 break;
5089 CHECK_LIVE_FRAME (frame);
5090 f = XFRAME (frame);
5092 for (i = 0; i < LFACE_VECTOR_SIZE; i++)
5093 attrs[i] = Qunspecified;
5094 merge_face_ref (f, attributes, attrs, 1, 0);
5096 def_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
5097 if (def_face == NULL)
5099 if (! realize_basic_faces (f))
5100 error ("Cannot realize default face");
5101 def_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
5102 if (def_face == NULL)
5103 abort (); /* realize_basic_faces must have set it up */
5106 /* Dispatch to the appropriate handler. */
5107 if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
5108 supports = tty_supports_face_attributes_p (f, attrs, def_face);
5109 #ifdef HAVE_WINDOW_SYSTEM
5110 else
5111 supports = x_supports_face_attributes_p (f, attrs, def_face);
5112 #endif
5114 return supports ? Qt : Qnil;
5118 /***********************************************************************
5119 Font selection
5120 ***********************************************************************/
5122 DEFUN ("internal-set-font-selection-order",
5123 Finternal_set_font_selection_order,
5124 Sinternal_set_font_selection_order, 1, 1, 0,
5125 doc: /* Set font selection order for face font selection to ORDER.
5126 ORDER must be a list of length 4 containing the symbols `:width',
5127 `:height', `:weight', and `:slant'. Face attributes appearing
5128 first in ORDER are matched first, e.g. if `:height' appears before
5129 `:weight' in ORDER, font selection first tries to find a font with
5130 a suitable height, and then tries to match the font weight.
5131 Value is ORDER. */)
5132 (Lisp_Object order)
5134 Lisp_Object list;
5135 int i;
5136 int indices[DIM (font_sort_order)];
5138 CHECK_LIST (order);
5139 memset (indices, 0, sizeof indices);
5140 i = 0;
5142 for (list = order;
5143 CONSP (list) && i < DIM (indices);
5144 list = XCDR (list), ++i)
5146 Lisp_Object attr = XCAR (list);
5147 int xlfd;
5149 if (EQ (attr, QCwidth))
5150 xlfd = XLFD_SWIDTH;
5151 else if (EQ (attr, QCheight))
5152 xlfd = XLFD_POINT_SIZE;
5153 else if (EQ (attr, QCweight))
5154 xlfd = XLFD_WEIGHT;
5155 else if (EQ (attr, QCslant))
5156 xlfd = XLFD_SLANT;
5157 else
5158 break;
5160 if (indices[i] != 0)
5161 break;
5162 indices[i] = xlfd;
5165 if (!NILP (list) || i != DIM (indices))
5166 signal_error ("Invalid font sort order", order);
5167 for (i = 0; i < DIM (font_sort_order); ++i)
5168 if (indices[i] == 0)
5169 signal_error ("Invalid font sort order", order);
5171 if (memcmp (indices, font_sort_order, sizeof indices) != 0)
5173 memcpy (font_sort_order, indices, sizeof font_sort_order);
5174 free_all_realized_faces (Qnil);
5177 font_update_sort_order (font_sort_order);
5179 return Qnil;
5183 DEFUN ("internal-set-alternative-font-family-alist",
5184 Finternal_set_alternative_font_family_alist,
5185 Sinternal_set_alternative_font_family_alist, 1, 1, 0,
5186 doc: /* Define alternative font families to try in face font selection.
5187 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5188 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
5189 be found. Value is ALIST. */)
5190 (Lisp_Object alist)
5192 Lisp_Object entry, tail, tail2;
5194 CHECK_LIST (alist);
5195 alist = Fcopy_sequence (alist);
5196 for (tail = alist; CONSP (tail); tail = XCDR (tail))
5198 entry = XCAR (tail);
5199 CHECK_LIST (entry);
5200 entry = Fcopy_sequence (entry);
5201 XSETCAR (tail, entry);
5202 for (tail2 = entry; CONSP (tail2); tail2 = XCDR (tail2))
5203 XSETCAR (tail2, Fintern (XCAR (tail2), Qnil));
5206 Vface_alternative_font_family_alist = alist;
5207 free_all_realized_faces (Qnil);
5208 return alist;
5212 DEFUN ("internal-set-alternative-font-registry-alist",
5213 Finternal_set_alternative_font_registry_alist,
5214 Sinternal_set_alternative_font_registry_alist, 1, 1, 0,
5215 doc: /* Define alternative font registries to try in face font selection.
5216 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5217 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
5218 be found. Value is ALIST. */)
5219 (Lisp_Object alist)
5221 Lisp_Object entry, tail, tail2;
5223 CHECK_LIST (alist);
5224 alist = Fcopy_sequence (alist);
5225 for (tail = alist; CONSP (tail); tail = XCDR (tail))
5227 entry = XCAR (tail);
5228 CHECK_LIST (entry);
5229 entry = Fcopy_sequence (entry);
5230 XSETCAR (tail, entry);
5231 for (tail2 = entry; CONSP (tail2); tail2 = XCDR (tail2))
5232 XSETCAR (tail2, Fdowncase (XCAR (tail2)));
5234 Vface_alternative_font_registry_alist = alist;
5235 free_all_realized_faces (Qnil);
5236 return alist;
5240 #ifdef HAVE_WINDOW_SYSTEM
5242 /* Return the fontset id of the base fontset name or alias name given
5243 by the fontset attribute of ATTRS. Value is -1 if the fontset
5244 attribute of ATTRS doesn't name a fontset. */
5246 static int
5247 face_fontset (Lisp_Object *attrs)
5249 Lisp_Object name;
5251 name = attrs[LFACE_FONTSET_INDEX];
5252 if (!STRINGP (name))
5253 return -1;
5254 return fs_query_fontset (name, 0);
5257 #endif /* HAVE_WINDOW_SYSTEM */
5261 /***********************************************************************
5262 Face Realization
5263 ***********************************************************************/
5265 /* Realize basic faces on frame F. Value is zero if frame parameters
5266 of F don't contain enough information needed to realize the default
5267 face. */
5269 static int
5270 realize_basic_faces (struct frame *f)
5272 int success_p = 0;
5273 int count = SPECPDL_INDEX ();
5275 /* Block input here so that we won't be surprised by an X expose
5276 event, for instance, without having the faces set up. */
5277 BLOCK_INPUT;
5278 specbind (Qscalable_fonts_allowed, Qt);
5280 if (realize_default_face (f))
5282 realize_named_face (f, Qmode_line, MODE_LINE_FACE_ID);
5283 realize_named_face (f, Qmode_line_inactive, MODE_LINE_INACTIVE_FACE_ID);
5284 realize_named_face (f, Qtool_bar, TOOL_BAR_FACE_ID);
5285 realize_named_face (f, Qfringe, FRINGE_FACE_ID);
5286 realize_named_face (f, Qheader_line, HEADER_LINE_FACE_ID);
5287 realize_named_face (f, Qscroll_bar, SCROLL_BAR_FACE_ID);
5288 realize_named_face (f, Qborder, BORDER_FACE_ID);
5289 realize_named_face (f, Qcursor, CURSOR_FACE_ID);
5290 realize_named_face (f, Qmouse, MOUSE_FACE_ID);
5291 realize_named_face (f, Qmenu, MENU_FACE_ID);
5292 realize_named_face (f, Qvertical_border, VERTICAL_BORDER_FACE_ID);
5294 /* Reflect changes in the `menu' face in menu bars. */
5295 if (FRAME_FACE_CACHE (f)->menu_face_changed_p)
5297 FRAME_FACE_CACHE (f)->menu_face_changed_p = 0;
5298 #ifdef USE_X_TOOLKIT
5299 if (FRAME_WINDOW_P (f))
5300 x_update_menu_appearance (f);
5301 #endif
5304 success_p = 1;
5307 unbind_to (count, Qnil);
5308 UNBLOCK_INPUT;
5309 return success_p;
5313 /* Realize the default face on frame F. If the face is not fully
5314 specified, make it fully-specified. Attributes of the default face
5315 that are not explicitly specified are taken from frame parameters. */
5317 static int
5318 realize_default_face (struct frame *f)
5320 struct face_cache *c = FRAME_FACE_CACHE (f);
5321 Lisp_Object lface;
5322 Lisp_Object attrs[LFACE_VECTOR_SIZE];
5323 struct face *face;
5325 /* If the `default' face is not yet known, create it. */
5326 lface = lface_from_face_name (f, Qdefault, 0);
5327 if (NILP (lface))
5329 Lisp_Object frame;
5330 XSETFRAME (frame, f);
5331 lface = Finternal_make_lisp_face (Qdefault, frame);
5334 #ifdef HAVE_WINDOW_SYSTEM
5335 if (FRAME_WINDOW_P (f))
5337 Lisp_Object font_object;
5339 XSETFONT (font_object, FRAME_FONT (f));
5340 set_lface_from_font (f, lface, font_object, f->default_face_done_p);
5341 LFACE_FONTSET (lface) = fontset_name (FRAME_FONTSET (f));
5342 f->default_face_done_p = 1;
5344 #endif /* HAVE_WINDOW_SYSTEM */
5346 if (!FRAME_WINDOW_P (f))
5348 LFACE_FAMILY (lface) = build_string ("default");
5349 LFACE_FOUNDRY (lface) = LFACE_FAMILY (lface);
5350 LFACE_SWIDTH (lface) = Qnormal;
5351 LFACE_HEIGHT (lface) = make_number (1);
5352 if (UNSPECIFIEDP (LFACE_WEIGHT (lface)))
5353 LFACE_WEIGHT (lface) = Qnormal;
5354 if (UNSPECIFIEDP (LFACE_SLANT (lface)))
5355 LFACE_SLANT (lface) = Qnormal;
5356 if (UNSPECIFIEDP (LFACE_FONTSET (lface)))
5357 LFACE_FONTSET (lface) = Qnil;
5360 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface)))
5361 LFACE_UNDERLINE (lface) = Qnil;
5363 if (UNSPECIFIEDP (LFACE_OVERLINE (lface)))
5364 LFACE_OVERLINE (lface) = Qnil;
5366 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface)))
5367 LFACE_STRIKE_THROUGH (lface) = Qnil;
5369 if (UNSPECIFIEDP (LFACE_BOX (lface)))
5370 LFACE_BOX (lface) = Qnil;
5372 if (UNSPECIFIEDP (LFACE_INVERSE (lface)))
5373 LFACE_INVERSE (lface) = Qnil;
5375 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface)))
5377 /* This function is called so early that colors are not yet
5378 set in the frame parameter list. */
5379 Lisp_Object color = Fassq (Qforeground_color, f->param_alist);
5381 if (CONSP (color) && STRINGP (XCDR (color)))
5382 LFACE_FOREGROUND (lface) = XCDR (color);
5383 else if (FRAME_WINDOW_P (f))
5384 return 0;
5385 else if (FRAME_INITIAL_P (f) || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
5386 LFACE_FOREGROUND (lface) = build_string (unspecified_fg);
5387 else
5388 abort ();
5391 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface)))
5393 /* This function is called so early that colors are not yet
5394 set in the frame parameter list. */
5395 Lisp_Object color = Fassq (Qbackground_color, f->param_alist);
5396 if (CONSP (color) && STRINGP (XCDR (color)))
5397 LFACE_BACKGROUND (lface) = XCDR (color);
5398 else if (FRAME_WINDOW_P (f))
5399 return 0;
5400 else if (FRAME_INITIAL_P (f) || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
5401 LFACE_BACKGROUND (lface) = build_string (unspecified_bg);
5402 else
5403 abort ();
5406 if (UNSPECIFIEDP (LFACE_STIPPLE (lface)))
5407 LFACE_STIPPLE (lface) = Qnil;
5409 /* Realize the face; it must be fully-specified now. */
5410 xassert (lface_fully_specified_p (XVECTOR (lface)->contents));
5411 check_lface (lface);
5412 memcpy (attrs, XVECTOR (lface)->contents, sizeof attrs);
5413 face = realize_face (c, attrs, DEFAULT_FACE_ID);
5415 #ifdef HAVE_WINDOW_SYSTEM
5416 #ifdef HAVE_X_WINDOWS
5417 if (FRAME_X_P (f) && face->font != FRAME_FONT (f))
5419 /* This can happen when making a frame on a display that does
5420 not support the default font. */
5421 if (!face->font)
5422 return 0;
5424 /* Otherwise, the font specified for the frame was not
5425 acceptable as a font for the default face (perhaps because
5426 auto-scaled fonts are rejected), so we must adjust the frame
5427 font. */
5428 x_set_font (f, LFACE_FONT (lface), Qnil);
5430 #endif /* HAVE_X_WINDOWS */
5431 #endif /* HAVE_WINDOW_SYSTEM */
5432 return 1;
5436 /* Realize basic faces other than the default face in face cache C.
5437 SYMBOL is the face name, ID is the face id the realized face must
5438 have. The default face must have been realized already. */
5440 static void
5441 realize_named_face (struct frame *f, Lisp_Object symbol, int id)
5443 struct face_cache *c = FRAME_FACE_CACHE (f);
5444 Lisp_Object lface = lface_from_face_name (f, symbol, 0);
5445 Lisp_Object attrs[LFACE_VECTOR_SIZE];
5446 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE];
5447 struct face *new_face;
5449 /* The default face must exist and be fully specified. */
5450 get_lface_attributes_no_remap (f, Qdefault, attrs, 1);
5451 check_lface_attrs (attrs);
5452 xassert (lface_fully_specified_p (attrs));
5454 /* If SYMBOL isn't know as a face, create it. */
5455 if (NILP (lface))
5457 Lisp_Object frame;
5458 XSETFRAME (frame, f);
5459 lface = Finternal_make_lisp_face (symbol, frame);
5462 /* Merge SYMBOL's face with the default face. */
5463 get_lface_attributes_no_remap (f, symbol, symbol_attrs, 1);
5464 merge_face_vectors (f, symbol_attrs, attrs, 0);
5466 /* Realize the face. */
5467 new_face = realize_face (c, attrs, id);
5471 /* Realize the fully-specified face with attributes ATTRS in face
5472 cache CACHE for ASCII characters. If FORMER_FACE_ID is
5473 non-negative, it is an ID of face to remove before caching the new
5474 face. Value is a pointer to the newly created realized face. */
5476 static struct face *
5477 realize_face (struct face_cache *cache, Lisp_Object *attrs, int former_face_id)
5479 struct face *face;
5481 /* LFACE must be fully specified. */
5482 xassert (cache != NULL);
5483 check_lface_attrs (attrs);
5485 if (former_face_id >= 0 && cache->used > former_face_id)
5487 /* Remove the former face. */
5488 struct face *former_face = cache->faces_by_id[former_face_id];
5489 uncache_face (cache, former_face);
5490 free_realized_face (cache->f, former_face);
5491 SET_FRAME_GARBAGED (cache->f);
5494 if (FRAME_WINDOW_P (cache->f))
5495 face = realize_x_face (cache, attrs);
5496 else if (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f))
5497 face = realize_tty_face (cache, attrs);
5498 else if (FRAME_INITIAL_P (cache->f))
5500 /* Create a dummy face. */
5501 face = make_realized_face (attrs);
5503 else
5504 abort ();
5506 /* Insert the new face. */
5507 cache_face (cache, face, lface_hash (attrs));
5508 return face;
5512 #ifdef HAVE_WINDOW_SYSTEM
5513 /* Realize the fully-specified face that uses FONT-OBJECT and has the
5514 same attributes as BASE_FACE except for the font on frame F.
5515 FONT-OBJECT may be nil, in which case, realized a face of
5516 no-font. */
5518 static struct face *
5519 realize_non_ascii_face (struct frame *f, Lisp_Object font_object, struct face *base_face)
5521 struct face_cache *cache = FRAME_FACE_CACHE (f);
5522 struct face *face;
5524 face = (struct face *) xmalloc (sizeof *face);
5525 *face = *base_face;
5526 face->gc = 0;
5527 face->extra = NULL;
5528 face->overstrike
5529 = (! NILP (font_object)
5530 && FONT_WEIGHT_NAME_NUMERIC (face->lface[LFACE_WEIGHT_INDEX]) > 100
5531 && FONT_WEIGHT_NUMERIC (font_object) <= 100);
5533 /* Don't try to free the colors copied bitwise from BASE_FACE. */
5534 face->colors_copied_bitwise_p = 1;
5535 face->font = NILP (font_object) ? NULL : XFONT_OBJECT (font_object);
5536 face->gc = 0;
5538 cache_face (cache, face, face->hash);
5540 return face;
5542 #endif /* HAVE_WINDOW_SYSTEM */
5545 /* Realize the fully-specified face with attributes ATTRS in face
5546 cache CACHE for ASCII characters. Do it for X frame CACHE->f. If
5547 the new face doesn't share font with the default face, a fontname
5548 is allocated from the heap and set in `font_name' of the new face,
5549 but it is not yet loaded here. Value is a pointer to the newly
5550 created realized face. */
5552 static struct face *
5553 realize_x_face (struct face_cache *cache, Lisp_Object *attrs)
5555 struct face *face = NULL;
5556 #ifdef HAVE_WINDOW_SYSTEM
5557 struct face *default_face;
5558 struct frame *f;
5559 Lisp_Object stipple, overline, strike_through, box;
5561 xassert (FRAME_WINDOW_P (cache->f));
5563 /* Allocate a new realized face. */
5564 face = make_realized_face (attrs);
5565 face->ascii_face = face;
5567 f = cache->f;
5569 /* Determine the font to use. Most of the time, the font will be
5570 the same as the font of the default face, so try that first. */
5571 default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
5572 if (default_face
5573 && lface_same_font_attributes_p (default_face->lface, attrs))
5575 face->font = default_face->font;
5576 face->fontset
5577 = make_fontset_for_ascii_face (f, default_face->fontset, face);
5579 else
5581 /* If the face attribute ATTRS specifies a fontset, use it as
5582 the base of a new realized fontset. Otherwise, use the same
5583 base fontset as of the default face. The base determines
5584 registry and encoding of a font. It may also determine
5585 foundry and family. The other fields of font name pattern
5586 are constructed from ATTRS. */
5587 int fontset = face_fontset (attrs);
5589 /* If we are realizing the default face, ATTRS should specify a
5590 fontset. In other words, if FONTSET is -1, we are not
5591 realizing the default face, thus the default face should have
5592 already been realized. */
5593 if (fontset == -1)
5595 if (default_face)
5596 fontset = default_face->fontset;
5597 if (fontset == -1)
5598 abort ();
5600 if (! FONT_OBJECT_P (attrs[LFACE_FONT_INDEX]))
5601 attrs[LFACE_FONT_INDEX]
5602 = font_load_for_lface (f, attrs, attrs[LFACE_FONT_INDEX]);
5603 if (FONT_OBJECT_P (attrs[LFACE_FONT_INDEX]))
5605 face->font = XFONT_OBJECT (attrs[LFACE_FONT_INDEX]);
5606 face->fontset = make_fontset_for_ascii_face (f, fontset, face);
5608 else
5610 face->font = NULL;
5611 face->fontset = -1;
5615 if (face->font
5616 && FONT_WEIGHT_NAME_NUMERIC (attrs[LFACE_WEIGHT_INDEX]) > 100
5617 && FONT_WEIGHT_NUMERIC (attrs[LFACE_FONT_INDEX]) <= 100)
5618 face->overstrike = 1;
5620 /* Load colors, and set remaining attributes. */
5622 load_face_colors (f, face, attrs);
5624 /* Set up box. */
5625 box = attrs[LFACE_BOX_INDEX];
5626 if (STRINGP (box))
5628 /* A simple box of line width 1 drawn in color given by
5629 the string. */
5630 face->box_color = load_color (f, face, attrs[LFACE_BOX_INDEX],
5631 LFACE_BOX_INDEX);
5632 face->box = FACE_SIMPLE_BOX;
5633 face->box_line_width = 1;
5635 else if (INTEGERP (box))
5637 /* Simple box of specified line width in foreground color of the
5638 face. */
5639 xassert (XINT (box) != 0);
5640 face->box = FACE_SIMPLE_BOX;
5641 face->box_line_width = XINT (box);
5642 face->box_color = face->foreground;
5643 face->box_color_defaulted_p = 1;
5645 else if (CONSP (box))
5647 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
5648 being one of `raised' or `sunken'. */
5649 face->box = FACE_SIMPLE_BOX;
5650 face->box_color = face->foreground;
5651 face->box_color_defaulted_p = 1;
5652 face->box_line_width = 1;
5654 while (CONSP (box))
5656 Lisp_Object keyword, value;
5658 keyword = XCAR (box);
5659 box = XCDR (box);
5661 if (!CONSP (box))
5662 break;
5663 value = XCAR (box);
5664 box = XCDR (box);
5666 if (EQ (keyword, QCline_width))
5668 if (INTEGERP (value) && XINT (value) != 0)
5669 face->box_line_width = XINT (value);
5671 else if (EQ (keyword, QCcolor))
5673 if (STRINGP (value))
5675 face->box_color = load_color (f, face, value,
5676 LFACE_BOX_INDEX);
5677 face->use_box_color_for_shadows_p = 1;
5680 else if (EQ (keyword, QCstyle))
5682 if (EQ (value, Qreleased_button))
5683 face->box = FACE_RAISED_BOX;
5684 else if (EQ (value, Qpressed_button))
5685 face->box = FACE_SUNKEN_BOX;
5690 /* Text underline, overline, strike-through. */
5692 if (EQ (attrs[LFACE_UNDERLINE_INDEX], Qt))
5694 /* Use default color (same as foreground color). */
5695 face->underline_p = 1;
5696 face->underline_defaulted_p = 1;
5697 face->underline_color = 0;
5699 else if (STRINGP (attrs[LFACE_UNDERLINE_INDEX]))
5701 /* Use specified color. */
5702 face->underline_p = 1;
5703 face->underline_defaulted_p = 0;
5704 face->underline_color
5705 = load_color (f, face, attrs[LFACE_UNDERLINE_INDEX],
5706 LFACE_UNDERLINE_INDEX);
5708 else if (NILP (attrs[LFACE_UNDERLINE_INDEX]))
5710 face->underline_p = 0;
5711 face->underline_defaulted_p = 0;
5712 face->underline_color = 0;
5715 overline = attrs[LFACE_OVERLINE_INDEX];
5716 if (STRINGP (overline))
5718 face->overline_color
5719 = load_color (f, face, attrs[LFACE_OVERLINE_INDEX],
5720 LFACE_OVERLINE_INDEX);
5721 face->overline_p = 1;
5723 else if (EQ (overline, Qt))
5725 face->overline_color = face->foreground;
5726 face->overline_color_defaulted_p = 1;
5727 face->overline_p = 1;
5730 strike_through = attrs[LFACE_STRIKE_THROUGH_INDEX];
5731 if (STRINGP (strike_through))
5733 face->strike_through_color
5734 = load_color (f, face, attrs[LFACE_STRIKE_THROUGH_INDEX],
5735 LFACE_STRIKE_THROUGH_INDEX);
5736 face->strike_through_p = 1;
5738 else if (EQ (strike_through, Qt))
5740 face->strike_through_color = face->foreground;
5741 face->strike_through_color_defaulted_p = 1;
5742 face->strike_through_p = 1;
5745 stipple = attrs[LFACE_STIPPLE_INDEX];
5746 if (!NILP (stipple))
5747 face->stipple = load_pixmap (f, stipple, &face->pixmap_w, &face->pixmap_h);
5748 #endif /* HAVE_WINDOW_SYSTEM */
5750 return face;
5754 /* Map a specified color of face FACE on frame F to a tty color index.
5755 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
5756 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
5757 default foreground/background colors. */
5759 static void
5760 map_tty_color (struct frame *f, struct face *face, enum lface_attribute_index idx, int *defaulted)
5762 Lisp_Object frame, color, def;
5763 int foreground_p = idx == LFACE_FOREGROUND_INDEX;
5764 unsigned long default_pixel, default_other_pixel, pixel;
5766 xassert (idx == LFACE_FOREGROUND_INDEX || idx == LFACE_BACKGROUND_INDEX);
5768 if (foreground_p)
5770 pixel = default_pixel = FACE_TTY_DEFAULT_FG_COLOR;
5771 default_other_pixel = FACE_TTY_DEFAULT_BG_COLOR;
5773 else
5775 pixel = default_pixel = FACE_TTY_DEFAULT_BG_COLOR;
5776 default_other_pixel = FACE_TTY_DEFAULT_FG_COLOR;
5779 XSETFRAME (frame, f);
5780 color = face->lface[idx];
5782 if (STRINGP (color)
5783 && SCHARS (color)
5784 && CONSP (Vtty_defined_color_alist)
5785 && (def = assq_no_quit (color, call1 (Qtty_color_alist, frame)),
5786 CONSP (def)))
5788 /* Associations in tty-defined-color-alist are of the form
5789 (NAME INDEX R G B). We need the INDEX part. */
5790 pixel = XINT (XCAR (XCDR (def)));
5793 if (pixel == default_pixel && STRINGP (color))
5795 pixel = load_color (f, face, color, idx);
5797 #ifdef MSDOS
5798 /* If the foreground of the default face is the default color,
5799 use the foreground color defined by the frame. */
5800 if (FRAME_MSDOS_P (f))
5802 if (pixel == default_pixel
5803 || pixel == FACE_TTY_DEFAULT_COLOR)
5805 if (foreground_p)
5806 pixel = FRAME_FOREGROUND_PIXEL (f);
5807 else
5808 pixel = FRAME_BACKGROUND_PIXEL (f);
5809 face->lface[idx] = tty_color_name (f, pixel);
5810 *defaulted = 1;
5812 else if (pixel == default_other_pixel)
5814 if (foreground_p)
5815 pixel = FRAME_BACKGROUND_PIXEL (f);
5816 else
5817 pixel = FRAME_FOREGROUND_PIXEL (f);
5818 face->lface[idx] = tty_color_name (f, pixel);
5819 *defaulted = 1;
5822 #endif /* MSDOS */
5825 if (foreground_p)
5826 face->foreground = pixel;
5827 else
5828 face->background = pixel;
5832 /* Realize the fully-specified face with attributes ATTRS in face
5833 cache CACHE for ASCII characters. Do it for TTY frame CACHE->f.
5834 Value is a pointer to the newly created realized face. */
5836 static struct face *
5837 realize_tty_face (struct face_cache *cache, Lisp_Object *attrs)
5839 struct face *face;
5840 int weight, slant;
5841 int face_colors_defaulted = 0;
5842 struct frame *f = cache->f;
5844 /* Frame must be a termcap frame. */
5845 xassert (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f));
5847 /* Allocate a new realized face. */
5848 face = make_realized_face (attrs);
5849 #if 0
5850 face->font_name = FRAME_MSDOS_P (cache->f) ? "ms-dos" : "tty";
5851 #endif
5853 /* Map face attributes to TTY appearances. We map slant to
5854 dimmed text because we want italic text to appear differently
5855 and because dimmed text is probably used infrequently. */
5856 weight = FONT_WEIGHT_NAME_NUMERIC (attrs[LFACE_WEIGHT_INDEX]);
5857 slant = FONT_SLANT_NAME_NUMERIC (attrs[LFACE_SLANT_INDEX]);
5858 if (weight > 100)
5859 face->tty_bold_p = 1;
5860 if (weight < 100 || slant != 100)
5861 face->tty_dim_p = 1;
5862 if (!NILP (attrs[LFACE_UNDERLINE_INDEX]))
5863 face->tty_underline_p = 1;
5864 if (!NILP (attrs[LFACE_INVERSE_INDEX]))
5865 face->tty_reverse_p = 1;
5867 /* Map color names to color indices. */
5868 map_tty_color (f, face, LFACE_FOREGROUND_INDEX, &face_colors_defaulted);
5869 map_tty_color (f, face, LFACE_BACKGROUND_INDEX, &face_colors_defaulted);
5871 /* Swap colors if face is inverse-video. If the colors are taken
5872 from the frame colors, they are already inverted, since the
5873 frame-creation function calls x-handle-reverse-video. */
5874 if (face->tty_reverse_p && !face_colors_defaulted)
5876 unsigned long tem = face->foreground;
5877 face->foreground = face->background;
5878 face->background = tem;
5881 if (tty_suppress_bold_inverse_default_colors_p
5882 && face->tty_bold_p
5883 && face->background == FACE_TTY_DEFAULT_FG_COLOR
5884 && face->foreground == FACE_TTY_DEFAULT_BG_COLOR)
5885 face->tty_bold_p = 0;
5887 return face;
5891 DEFUN ("tty-suppress-bold-inverse-default-colors",
5892 Ftty_suppress_bold_inverse_default_colors,
5893 Stty_suppress_bold_inverse_default_colors, 1, 1, 0,
5894 doc: /* Suppress/allow boldness of faces with inverse default colors.
5895 SUPPRESS non-nil means suppress it.
5896 This affects bold faces on TTYs whose foreground is the default background
5897 color of the display and whose background is the default foreground color.
5898 For such faces, the bold face attribute is ignored if this variable
5899 is non-nil. */)
5900 (Lisp_Object suppress)
5902 tty_suppress_bold_inverse_default_colors_p = !NILP (suppress);
5903 ++face_change_count;
5904 return suppress;
5909 /***********************************************************************
5910 Computing Faces
5911 ***********************************************************************/
5913 /* Return the ID of the face to use to display character CH with face
5914 property PROP on frame F in current_buffer. */
5917 compute_char_face (struct frame *f, int ch, Lisp_Object prop)
5919 int face_id;
5921 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
5922 ch = 0;
5924 if (NILP (prop))
5926 struct face *face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
5927 face_id = FACE_FOR_CHAR (f, face, ch, -1, Qnil);
5929 else
5931 Lisp_Object attrs[LFACE_VECTOR_SIZE];
5932 struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
5933 memcpy (attrs, default_face->lface, sizeof attrs);
5934 merge_face_ref (f, prop, attrs, 1, 0);
5935 face_id = lookup_face (f, attrs);
5938 return face_id;
5941 /* Return the face ID associated with buffer position POS for
5942 displaying ASCII characters. Return in *ENDPTR the position at
5943 which a different face is needed, as far as text properties and
5944 overlays are concerned. W is a window displaying current_buffer.
5946 REGION_BEG, REGION_END delimit the region, so it can be
5947 highlighted.
5949 LIMIT is a position not to scan beyond. That is to limit the time
5950 this function can take.
5952 If MOUSE is non-zero, use the character's mouse-face, not its face.
5954 BASE_FACE_ID, if non-negative, specifies a base face id to use
5955 instead of DEFAULT_FACE_ID.
5957 The face returned is suitable for displaying ASCII characters. */
5960 face_at_buffer_position (struct window *w, EMACS_INT pos,
5961 EMACS_INT region_beg, EMACS_INT region_end,
5962 EMACS_INT *endptr, EMACS_INT limit,
5963 int mouse, int base_face_id)
5965 struct frame *f = XFRAME (w->frame);
5966 Lisp_Object attrs[LFACE_VECTOR_SIZE];
5967 Lisp_Object prop, position;
5968 int i, noverlays;
5969 Lisp_Object *overlay_vec;
5970 Lisp_Object frame;
5971 EMACS_INT endpos;
5972 Lisp_Object propname = mouse ? Qmouse_face : Qface;
5973 Lisp_Object limit1, end;
5974 struct face *default_face;
5976 /* W must display the current buffer. We could write this function
5977 to use the frame and buffer of W, but right now it doesn't. */
5978 /* xassert (XBUFFER (w->buffer) == current_buffer); */
5980 XSETFRAME (frame, f);
5981 XSETFASTINT (position, pos);
5983 endpos = ZV;
5984 if (pos < region_beg && region_beg < endpos)
5985 endpos = region_beg;
5987 /* Get the `face' or `mouse_face' text property at POS, and
5988 determine the next position at which the property changes. */
5989 prop = Fget_text_property (position, propname, w->buffer);
5990 XSETFASTINT (limit1, (limit < endpos ? limit : endpos));
5991 end = Fnext_single_property_change (position, propname, w->buffer, limit1);
5992 if (INTEGERP (end))
5993 endpos = XINT (end);
5995 /* Look at properties from overlays. */
5997 EMACS_INT next_overlay;
5999 GET_OVERLAYS_AT (pos, overlay_vec, noverlays, &next_overlay, 0);
6000 if (next_overlay < endpos)
6001 endpos = next_overlay;
6004 *endptr = endpos;
6006 default_face = FACE_FROM_ID (f, base_face_id >= 0 ? base_face_id
6007 : NILP (Vface_remapping_alist) ? DEFAULT_FACE_ID
6008 : lookup_basic_face (f, DEFAULT_FACE_ID));
6010 /* Optimize common cases where we can use the default face. */
6011 if (noverlays == 0
6012 && NILP (prop)
6013 && !(pos >= region_beg && pos < region_end))
6014 return default_face->id;
6016 /* Begin with attributes from the default face. */
6017 memcpy (attrs, default_face->lface, sizeof attrs);
6019 /* Merge in attributes specified via text properties. */
6020 if (!NILP (prop))
6021 merge_face_ref (f, prop, attrs, 1, 0);
6023 /* Now merge the overlay data. */
6024 noverlays = sort_overlays (overlay_vec, noverlays, w);
6025 for (i = 0; i < noverlays; i++)
6027 Lisp_Object oend;
6028 int oendpos;
6030 prop = Foverlay_get (overlay_vec[i], propname);
6031 if (!NILP (prop))
6032 merge_face_ref (f, prop, attrs, 1, 0);
6034 oend = OVERLAY_END (overlay_vec[i]);
6035 oendpos = OVERLAY_POSITION (oend);
6036 if (oendpos < endpos)
6037 endpos = oendpos;
6040 /* If in the region, merge in the region face. */
6041 if (pos >= region_beg && pos < region_end)
6043 merge_named_face (f, Qregion, attrs, 0);
6045 if (region_end < endpos)
6046 endpos = region_end;
6049 *endptr = endpos;
6051 /* Look up a realized face with the given face attributes,
6052 or realize a new one for ASCII characters. */
6053 return lookup_face (f, attrs);
6056 /* Return the face ID at buffer position POS for displaying ASCII
6057 characters associated with overlay strings for overlay OVERLAY.
6059 Like face_at_buffer_position except for OVERLAY. Currently it
6060 simply disregards the `face' properties of all overlays. */
6063 face_for_overlay_string (struct window *w, EMACS_INT pos,
6064 EMACS_INT region_beg, EMACS_INT region_end,
6065 EMACS_INT *endptr, EMACS_INT limit,
6066 int mouse, Lisp_Object overlay)
6068 struct frame *f = XFRAME (w->frame);
6069 Lisp_Object attrs[LFACE_VECTOR_SIZE];
6070 Lisp_Object prop, position;
6071 Lisp_Object frame;
6072 int endpos;
6073 Lisp_Object propname = mouse ? Qmouse_face : Qface;
6074 Lisp_Object limit1, end;
6075 struct face *default_face;
6077 /* W must display the current buffer. We could write this function
6078 to use the frame and buffer of W, but right now it doesn't. */
6079 /* xassert (XBUFFER (w->buffer) == current_buffer); */
6081 XSETFRAME (frame, f);
6082 XSETFASTINT (position, pos);
6084 endpos = ZV;
6085 if (pos < region_beg && region_beg < endpos)
6086 endpos = region_beg;
6088 /* Get the `face' or `mouse_face' text property at POS, and
6089 determine the next position at which the property changes. */
6090 prop = Fget_text_property (position, propname, w->buffer);
6091 XSETFASTINT (limit1, (limit < endpos ? limit : endpos));
6092 end = Fnext_single_property_change (position, propname, w->buffer, limit1);
6093 if (INTEGERP (end))
6094 endpos = XINT (end);
6096 *endptr = endpos;
6098 default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
6100 /* Optimize common cases where we can use the default face. */
6101 if (NILP (prop)
6102 && !(pos >= region_beg && pos < region_end))
6103 return DEFAULT_FACE_ID;
6105 /* Begin with attributes from the default face. */
6106 memcpy (attrs, default_face->lface, sizeof attrs);
6108 /* Merge in attributes specified via text properties. */
6109 if (!NILP (prop))
6110 merge_face_ref (f, prop, attrs, 1, 0);
6112 /* If in the region, merge in the region face. */
6113 if (pos >= region_beg && pos < region_end)
6115 merge_named_face (f, Qregion, attrs, 0);
6117 if (region_end < endpos)
6118 endpos = region_end;
6121 *endptr = endpos;
6123 /* Look up a realized face with the given face attributes,
6124 or realize a new one for ASCII characters. */
6125 return lookup_face (f, attrs);
6129 /* Compute the face at character position POS in Lisp string STRING on
6130 window W, for ASCII characters.
6132 If STRING is an overlay string, it comes from position BUFPOS in
6133 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
6134 not an overlay string. W must display the current buffer.
6135 REGION_BEG and REGION_END give the start and end positions of the
6136 region; both are -1 if no region is visible.
6138 BASE_FACE_ID is the id of a face to merge with. For strings coming
6139 from overlays or the `display' property it is the face at BUFPOS.
6141 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
6143 Set *ENDPTR to the next position where to check for faces in
6144 STRING; -1 if the face is constant from POS to the end of the
6145 string.
6147 Value is the id of the face to use. The face returned is suitable
6148 for displaying ASCII characters. */
6151 face_at_string_position (struct window *w, Lisp_Object string,
6152 EMACS_INT pos, EMACS_INT bufpos,
6153 EMACS_INT region_beg, EMACS_INT region_end,
6154 EMACS_INT *endptr, enum face_id base_face_id,
6155 int mouse_p)
6157 Lisp_Object prop, position, end, limit;
6158 struct frame *f = XFRAME (WINDOW_FRAME (w));
6159 Lisp_Object attrs[LFACE_VECTOR_SIZE];
6160 struct face *base_face;
6161 int multibyte_p = STRING_MULTIBYTE (string);
6162 Lisp_Object prop_name = mouse_p ? Qmouse_face : Qface;
6164 /* Get the value of the face property at the current position within
6165 STRING. Value is nil if there is no face property. */
6166 XSETFASTINT (position, pos);
6167 prop = Fget_text_property (position, prop_name, string);
6169 /* Get the next position at which to check for faces. Value of end
6170 is nil if face is constant all the way to the end of the string.
6171 Otherwise it is a string position where to check faces next.
6172 Limit is the maximum position up to which to check for property
6173 changes in Fnext_single_property_change. Strings are usually
6174 short, so set the limit to the end of the string. */
6175 XSETFASTINT (limit, SCHARS (string));
6176 end = Fnext_single_property_change (position, prop_name, string, limit);
6177 if (INTEGERP (end))
6178 *endptr = XFASTINT (end);
6179 else
6180 *endptr = -1;
6182 base_face = FACE_FROM_ID (f, base_face_id);
6183 xassert (base_face);
6185 /* Optimize the default case that there is no face property and we
6186 are not in the region. */
6187 if (NILP (prop)
6188 && (base_face_id != DEFAULT_FACE_ID
6189 /* BUFPOS <= 0 means STRING is not an overlay string, so
6190 that the region doesn't have to be taken into account. */
6191 || bufpos <= 0
6192 || bufpos < region_beg
6193 || bufpos >= region_end)
6194 && (multibyte_p
6195 /* We can't realize faces for different charsets differently
6196 if we don't have fonts, so we can stop here if not working
6197 on a window-system frame. */
6198 || !FRAME_WINDOW_P (f)
6199 || FACE_SUITABLE_FOR_CHAR_P (base_face, 0)))
6200 return base_face->id;
6202 /* Begin with attributes from the base face. */
6203 memcpy (attrs, base_face->lface, sizeof attrs);
6205 /* Merge in attributes specified via text properties. */
6206 if (!NILP (prop))
6207 merge_face_ref (f, prop, attrs, 1, 0);
6209 /* If in the region, merge in the region face. */
6210 if (bufpos
6211 && bufpos >= region_beg
6212 && bufpos < region_end)
6213 merge_named_face (f, Qregion, attrs, 0);
6215 /* Look up a realized face with the given face attributes,
6216 or realize a new one for ASCII characters. */
6217 return lookup_face (f, attrs);
6221 /* Merge a face into a realized face.
6223 F is frame where faces are (to be) realized.
6225 FACE_NAME is named face to merge.
6227 If FACE_NAME is nil, FACE_ID is face_id of realized face to merge.
6229 If FACE_NAME is t, FACE_ID is lface_id of face to merge.
6231 BASE_FACE_ID is realized face to merge into.
6233 Return new face id.
6237 merge_faces (struct frame *f, Lisp_Object face_name, int face_id, int base_face_id)
6239 Lisp_Object attrs[LFACE_VECTOR_SIZE];
6240 struct face *base_face;
6242 base_face = FACE_FROM_ID (f, base_face_id);
6243 if (!base_face)
6244 return base_face_id;
6246 if (EQ (face_name, Qt))
6248 if (face_id < 0 || face_id >= lface_id_to_name_size)
6249 return base_face_id;
6250 face_name = lface_id_to_name[face_id];
6251 /* When called during make-frame, lookup_derived_face may fail
6252 if the faces are uninitialized. Don't signal an error. */
6253 face_id = lookup_derived_face (f, face_name, base_face_id, 0);
6254 return (face_id >= 0 ? face_id : base_face_id);
6257 /* Begin with attributes from the base face. */
6258 memcpy (attrs, base_face->lface, sizeof attrs);
6260 if (!NILP (face_name))
6262 if (!merge_named_face (f, face_name, attrs, 0))
6263 return base_face_id;
6265 else
6267 struct face *face;
6268 if (face_id < 0)
6269 return base_face_id;
6270 face = FACE_FROM_ID (f, face_id);
6271 if (!face)
6272 return base_face_id;
6273 merge_face_vectors (f, face->lface, attrs, 0);
6276 /* Look up a realized face with the given face attributes,
6277 or realize a new one for ASCII characters. */
6278 return lookup_face (f, attrs);
6283 #ifndef HAVE_X_WINDOWS
6284 DEFUN ("x-load-color-file", Fx_load_color_file,
6285 Sx_load_color_file, 1, 1, 0,
6286 doc: /* Create an alist of color entries from an external file.
6288 The file should define one named RGB color per line like so:
6289 R G B name
6290 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6291 (Lisp_Object filename)
6293 FILE *fp;
6294 Lisp_Object cmap = Qnil;
6295 Lisp_Object abspath;
6297 CHECK_STRING (filename);
6298 abspath = Fexpand_file_name (filename, Qnil);
6300 fp = fopen (SDATA (abspath), "rt");
6301 if (fp)
6303 char buf[512];
6304 int red, green, blue;
6305 int num;
6307 BLOCK_INPUT;
6309 while (fgets (buf, sizeof (buf), fp) != NULL) {
6310 if (sscanf (buf, "%u %u %u %n", &red, &green, &blue, &num) == 3)
6312 char *name = buf + num;
6313 num = strlen (name) - 1;
6314 if (num >= 0 && name[num] == '\n')
6315 name[num] = 0;
6316 cmap = Fcons (Fcons (build_string (name),
6317 #ifdef WINDOWSNT
6318 make_number (RGB (red, green, blue))),
6319 #else
6320 make_number ((red << 16) | (green << 8) | blue)),
6321 #endif
6322 cmap);
6325 fclose (fp);
6327 UNBLOCK_INPUT;
6330 return cmap;
6332 #endif
6335 /***********************************************************************
6336 Tests
6337 ***********************************************************************/
6339 #if GLYPH_DEBUG
6341 /* Print the contents of the realized face FACE to stderr. */
6343 static void
6344 dump_realized_face (face)
6345 struct face *face;
6347 fprintf (stderr, "ID: %d\n", face->id);
6348 #ifdef HAVE_X_WINDOWS
6349 fprintf (stderr, "gc: %ld\n", (long) face->gc);
6350 #endif
6351 fprintf (stderr, "foreground: 0x%lx (%s)\n",
6352 face->foreground,
6353 SDATA (face->lface[LFACE_FOREGROUND_INDEX]));
6354 fprintf (stderr, "background: 0x%lx (%s)\n",
6355 face->background,
6356 SDATA (face->lface[LFACE_BACKGROUND_INDEX]));
6357 if (face->font)
6358 fprintf (stderr, "font_name: %s (%s)\n",
6359 SDATA (face->font->props[FONT_NAME_INDEX]),
6360 SDATA (face->lface[LFACE_FAMILY_INDEX]));
6361 #ifdef HAVE_X_WINDOWS
6362 fprintf (stderr, "font = %p\n", face->font);
6363 #endif
6364 fprintf (stderr, "fontset: %d\n", face->fontset);
6365 fprintf (stderr, "underline: %d (%s)\n",
6366 face->underline_p,
6367 SDATA (Fsymbol_name (face->lface[LFACE_UNDERLINE_INDEX])));
6368 fprintf (stderr, "hash: %d\n", face->hash);
6372 DEFUN ("dump-face", Fdump_face, Sdump_face, 0, 1, 0, doc: /* */)
6373 (Lisp_Object n)
6375 if (NILP (n))
6377 int i;
6379 fprintf (stderr, "font selection order: ");
6380 for (i = 0; i < DIM (font_sort_order); ++i)
6381 fprintf (stderr, "%d ", font_sort_order[i]);
6382 fprintf (stderr, "\n");
6384 fprintf (stderr, "alternative fonts: ");
6385 debug_print (Vface_alternative_font_family_alist);
6386 fprintf (stderr, "\n");
6388 for (i = 0; i < FRAME_FACE_CACHE (SELECTED_FRAME ())->used; ++i)
6389 Fdump_face (make_number (i));
6391 else
6393 struct face *face;
6394 CHECK_NUMBER (n);
6395 face = FACE_FROM_ID (SELECTED_FRAME (), XINT (n));
6396 if (face == NULL)
6397 error ("Not a valid face");
6398 dump_realized_face (face);
6401 return Qnil;
6405 DEFUN ("show-face-resources", Fshow_face_resources, Sshow_face_resources,
6406 0, 0, 0, doc: /* */)
6407 (void)
6409 fprintf (stderr, "number of colors = %d\n", ncolors_allocated);
6410 fprintf (stderr, "number of pixmaps = %d\n", npixmaps_allocated);
6411 fprintf (stderr, "number of GCs = %d\n", ngcs);
6412 return Qnil;
6415 #endif /* GLYPH_DEBUG != 0 */
6419 /***********************************************************************
6420 Initialization
6421 ***********************************************************************/
6423 void
6424 syms_of_xfaces (void)
6426 Qface = intern_c_string ("face");
6427 staticpro (&Qface);
6428 Qface_no_inherit = intern_c_string ("face-no-inherit");
6429 staticpro (&Qface_no_inherit);
6430 Qbitmap_spec_p = intern_c_string ("bitmap-spec-p");
6431 staticpro (&Qbitmap_spec_p);
6432 Qframe_set_background_mode = intern_c_string ("frame-set-background-mode");
6433 staticpro (&Qframe_set_background_mode);
6435 /* Lisp face attribute keywords. */
6436 QCfamily = intern_c_string (":family");
6437 staticpro (&QCfamily);
6438 QCheight = intern_c_string (":height");
6439 staticpro (&QCheight);
6440 QCweight = intern_c_string (":weight");
6441 staticpro (&QCweight);
6442 QCslant = intern_c_string (":slant");
6443 staticpro (&QCslant);
6444 QCunderline = intern_c_string (":underline");
6445 staticpro (&QCunderline);
6446 QCinverse_video = intern_c_string (":inverse-video");
6447 staticpro (&QCinverse_video);
6448 QCreverse_video = intern_c_string (":reverse-video");
6449 staticpro (&QCreverse_video);
6450 QCforeground = intern_c_string (":foreground");
6451 staticpro (&QCforeground);
6452 QCbackground = intern_c_string (":background");
6453 staticpro (&QCbackground);
6454 QCstipple = intern_c_string (":stipple");
6455 staticpro (&QCstipple);
6456 QCwidth = intern_c_string (":width");
6457 staticpro (&QCwidth);
6458 QCfont = intern_c_string (":font");
6459 staticpro (&QCfont);
6460 QCfontset = intern_c_string (":fontset");
6461 staticpro (&QCfontset);
6462 QCbold = intern_c_string (":bold");
6463 staticpro (&QCbold);
6464 QCitalic = intern_c_string (":italic");
6465 staticpro (&QCitalic);
6466 QCoverline = intern_c_string (":overline");
6467 staticpro (&QCoverline);
6468 QCstrike_through = intern_c_string (":strike-through");
6469 staticpro (&QCstrike_through);
6470 QCbox = intern_c_string (":box");
6471 staticpro (&QCbox);
6472 QCinherit = intern_c_string (":inherit");
6473 staticpro (&QCinherit);
6475 /* Symbols used for Lisp face attribute values. */
6476 QCcolor = intern_c_string (":color");
6477 staticpro (&QCcolor);
6478 QCline_width = intern_c_string (":line-width");
6479 staticpro (&QCline_width);
6480 QCstyle = intern_c_string (":style");
6481 staticpro (&QCstyle);
6482 Qreleased_button = intern_c_string ("released-button");
6483 staticpro (&Qreleased_button);
6484 Qpressed_button = intern_c_string ("pressed-button");
6485 staticpro (&Qpressed_button);
6486 Qnormal = intern_c_string ("normal");
6487 staticpro (&Qnormal);
6488 Qultra_light = intern_c_string ("ultra-light");
6489 staticpro (&Qultra_light);
6490 Qextra_light = intern_c_string ("extra-light");
6491 staticpro (&Qextra_light);
6492 Qlight = intern_c_string ("light");
6493 staticpro (&Qlight);
6494 Qsemi_light = intern_c_string ("semi-light");
6495 staticpro (&Qsemi_light);
6496 Qsemi_bold = intern_c_string ("semi-bold");
6497 staticpro (&Qsemi_bold);
6498 Qbold = intern_c_string ("bold");
6499 staticpro (&Qbold);
6500 Qextra_bold = intern_c_string ("extra-bold");
6501 staticpro (&Qextra_bold);
6502 Qultra_bold = intern_c_string ("ultra-bold");
6503 staticpro (&Qultra_bold);
6504 Qoblique = intern_c_string ("oblique");
6505 staticpro (&Qoblique);
6506 Qitalic = intern_c_string ("italic");
6507 staticpro (&Qitalic);
6508 Qreverse_oblique = intern_c_string ("reverse-oblique");
6509 staticpro (&Qreverse_oblique);
6510 Qreverse_italic = intern_c_string ("reverse-italic");
6511 staticpro (&Qreverse_italic);
6512 Qultra_condensed = intern_c_string ("ultra-condensed");
6513 staticpro (&Qultra_condensed);
6514 Qextra_condensed = intern_c_string ("extra-condensed");
6515 staticpro (&Qextra_condensed);
6516 Qcondensed = intern_c_string ("condensed");
6517 staticpro (&Qcondensed);
6518 Qsemi_condensed = intern_c_string ("semi-condensed");
6519 staticpro (&Qsemi_condensed);
6520 Qsemi_expanded = intern_c_string ("semi-expanded");
6521 staticpro (&Qsemi_expanded);
6522 Qexpanded = intern_c_string ("expanded");
6523 staticpro (&Qexpanded);
6524 Qextra_expanded = intern_c_string ("extra-expanded");
6525 staticpro (&Qextra_expanded);
6526 Qultra_expanded = intern_c_string ("ultra-expanded");
6527 staticpro (&Qultra_expanded);
6528 Qbackground_color = intern_c_string ("background-color");
6529 staticpro (&Qbackground_color);
6530 Qforeground_color = intern_c_string ("foreground-color");
6531 staticpro (&Qforeground_color);
6532 Qunspecified = intern_c_string ("unspecified");
6533 staticpro (&Qunspecified);
6534 Qignore_defface = intern_c_string (":ignore-defface");
6535 staticpro (&Qignore_defface);
6537 Qface_alias = intern_c_string ("face-alias");
6538 staticpro (&Qface_alias);
6539 Qdefault = intern_c_string ("default");
6540 staticpro (&Qdefault);
6541 Qtool_bar = intern_c_string ("tool-bar");
6542 staticpro (&Qtool_bar);
6543 Qregion = intern_c_string ("region");
6544 staticpro (&Qregion);
6545 Qfringe = intern_c_string ("fringe");
6546 staticpro (&Qfringe);
6547 Qheader_line = intern_c_string ("header-line");
6548 staticpro (&Qheader_line);
6549 Qscroll_bar = intern_c_string ("scroll-bar");
6550 staticpro (&Qscroll_bar);
6551 Qmenu = intern_c_string ("menu");
6552 staticpro (&Qmenu);
6553 Qcursor = intern_c_string ("cursor");
6554 staticpro (&Qcursor);
6555 Qborder = intern_c_string ("border");
6556 staticpro (&Qborder);
6557 Qmouse = intern_c_string ("mouse");
6558 staticpro (&Qmouse);
6559 Qmode_line_inactive = intern_c_string ("mode-line-inactive");
6560 staticpro (&Qmode_line_inactive);
6561 Qvertical_border = intern_c_string ("vertical-border");
6562 staticpro (&Qvertical_border);
6563 Qtty_color_desc = intern_c_string ("tty-color-desc");
6564 staticpro (&Qtty_color_desc);
6565 Qtty_color_standard_values = intern_c_string ("tty-color-standard-values");
6566 staticpro (&Qtty_color_standard_values);
6567 Qtty_color_by_index = intern_c_string ("tty-color-by-index");
6568 staticpro (&Qtty_color_by_index);
6569 Qtty_color_alist = intern_c_string ("tty-color-alist");
6570 staticpro (&Qtty_color_alist);
6571 Qscalable_fonts_allowed = intern_c_string ("scalable-fonts-allowed");
6572 staticpro (&Qscalable_fonts_allowed);
6574 Vparam_value_alist = Fcons (Fcons (Qnil, Qnil), Qnil);
6575 staticpro (&Vparam_value_alist);
6576 Vface_alternative_font_family_alist = Qnil;
6577 staticpro (&Vface_alternative_font_family_alist);
6578 Vface_alternative_font_registry_alist = Qnil;
6579 staticpro (&Vface_alternative_font_registry_alist);
6581 defsubr (&Sinternal_make_lisp_face);
6582 defsubr (&Sinternal_lisp_face_p);
6583 defsubr (&Sinternal_set_lisp_face_attribute);
6584 #ifdef HAVE_WINDOW_SYSTEM
6585 defsubr (&Sinternal_set_lisp_face_attribute_from_resource);
6586 #endif
6587 defsubr (&Scolor_gray_p);
6588 defsubr (&Scolor_supported_p);
6589 #ifndef HAVE_X_WINDOWS
6590 defsubr (&Sx_load_color_file);
6591 #endif
6592 defsubr (&Sface_attribute_relative_p);
6593 defsubr (&Smerge_face_attribute);
6594 defsubr (&Sinternal_get_lisp_face_attribute);
6595 defsubr (&Sinternal_lisp_face_attribute_values);
6596 defsubr (&Sinternal_lisp_face_equal_p);
6597 defsubr (&Sinternal_lisp_face_empty_p);
6598 defsubr (&Sinternal_copy_lisp_face);
6599 defsubr (&Sinternal_merge_in_global_face);
6600 defsubr (&Sface_font);
6601 defsubr (&Sframe_face_alist);
6602 defsubr (&Sdisplay_supports_face_attributes_p);
6603 defsubr (&Scolor_distance);
6604 defsubr (&Sinternal_set_font_selection_order);
6605 defsubr (&Sinternal_set_alternative_font_family_alist);
6606 defsubr (&Sinternal_set_alternative_font_registry_alist);
6607 defsubr (&Sface_attributes_as_vector);
6608 #if GLYPH_DEBUG
6609 defsubr (&Sdump_face);
6610 defsubr (&Sshow_face_resources);
6611 #endif /* GLYPH_DEBUG */
6612 defsubr (&Sclear_face_cache);
6613 defsubr (&Stty_suppress_bold_inverse_default_colors);
6615 #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS
6616 defsubr (&Sdump_colors);
6617 #endif
6619 DEFVAR_LISP ("font-list-limit", Vfont_list_limit,
6620 doc: /* *Limit for font matching.
6621 If an integer > 0, font matching functions won't load more than
6622 that number of fonts when searching for a matching font. */);
6623 Vfont_list_limit = make_number (DEFAULT_FONT_LIST_LIMIT);
6625 DEFVAR_LISP ("face-new-frame-defaults", Vface_new_frame_defaults,
6626 doc: /* List of global face definitions (for internal use only.) */);
6627 Vface_new_frame_defaults = Qnil;
6629 DEFVAR_LISP ("face-default-stipple", Vface_default_stipple,
6630 doc: /* *Default stipple pattern used on monochrome displays.
6631 This stipple pattern is used on monochrome displays
6632 instead of shades of gray for a face background color.
6633 See `set-face-stipple' for possible values for this variable. */);
6634 Vface_default_stipple = make_pure_c_string ("gray3");
6636 DEFVAR_LISP ("tty-defined-color-alist", Vtty_defined_color_alist,
6637 doc: /* An alist of defined terminal colors and their RGB values.
6638 See the docstring of `tty-color-alist' for the details. */);
6639 Vtty_defined_color_alist = Qnil;
6641 DEFVAR_LISP ("scalable-fonts-allowed", Vscalable_fonts_allowed,
6642 doc: /* Allowed scalable fonts.
6643 A value of nil means don't allow any scalable fonts.
6644 A value of t means allow any scalable font.
6645 Otherwise, value must be a list of regular expressions. A font may be
6646 scaled if its name matches a regular expression in the list.
6647 Note that if value is nil, a scalable font might still be used, if no
6648 other font of the appropriate family and registry is available. */);
6649 Vscalable_fonts_allowed = Qnil;
6651 DEFVAR_LISP ("face-ignored-fonts", Vface_ignored_fonts,
6652 doc: /* List of ignored fonts.
6653 Each element is a regular expression that matches names of fonts to
6654 ignore. */);
6655 Vface_ignored_fonts = Qnil;
6657 DEFVAR_LISP ("face-remapping-alist", Vface_remapping_alist,
6658 doc: /* Alist of face remappings.
6659 Each element is of the form:
6661 (FACE REPLACEMENT...),
6663 which causes display of the face FACE to use REPLACEMENT... instead.
6664 REPLACEMENT... is interpreted the same way as the value of a `face'
6665 text property: it may be (1) A face name, (2) A list of face names,
6666 (3) A property-list of face attribute/value pairs, or (4) A list of
6667 face names or lists containing face attribute/value pairs.
6669 Multiple entries in REPLACEMENT... are merged together to form the final
6670 result, with faces or attributes earlier in the list taking precedence
6671 over those that are later.
6673 Face-name remapping cycles are suppressed; recursive references use the
6674 underlying face instead of the remapped face. So a remapping of the form:
6676 (FACE EXTRA-FACE... FACE)
6680 (FACE (FACE-ATTR VAL ...) FACE)
6682 will cause EXTRA-FACE... or (FACE-ATTR VAL ...) to be _merged_ with the
6683 existing definition of FACE. Note that for the default face, this isn't
6684 necessary, as every face inherits from the default face.
6686 Making this variable buffer-local is a good way to allow buffer-specific
6687 face definitions. For instance, the mode my-mode could define a face
6688 `my-mode-default', and then in the mode setup function, do:
6690 (set (make-local-variable 'face-remapping-alist)
6691 '((default my-mode-default)))).
6693 Because Emacs normally only redraws screen areas when the underlying
6694 buffer contents change, you may need to call `redraw-display' after
6695 changing this variable for it to take effect. */);
6696 Vface_remapping_alist = Qnil;
6698 DEFVAR_LISP ("face-font-rescale-alist", Vface_font_rescale_alist,
6699 doc: /* Alist of fonts vs the rescaling factors.
6700 Each element is a cons (FONT-PATTERN . RESCALE-RATIO), where
6701 FONT-PATTERN is a font-spec or a regular expression matching a font name, and
6702 RESCALE-RATIO is a floating point number to specify how much larger
6703 \(or smaller) font we should use. For instance, if a face requests
6704 a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point. */);
6705 Vface_font_rescale_alist = Qnil;
6707 #ifdef HAVE_WINDOW_SYSTEM
6708 defsubr (&Sbitmap_spec_p);
6709 defsubr (&Sx_list_fonts);
6710 defsubr (&Sinternal_face_x_get_resource);
6711 defsubr (&Sx_family_fonts);
6712 #endif