1 /* xfaces.c -- "Face" primitives.
3 Copyright (C) 1993-1994, 1998-2015 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>. */
24 When using Emacs with X, the display style of characters can be
25 changed by defining `faces'. Each face can specify the following
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'.
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
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 corresponding 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
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'.
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.
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 the 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
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.
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.
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,
172 2. Setting face-font-family-alternatives allows the user to
173 specify alternative font families to try if a family specified by a
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
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
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. */
203 #include "sysstdio.h"
204 #include <sys/types.h>
205 #include <sys/stat.h>
208 #include "character.h"
210 #include "keyboard.h"
212 #include "termhooks.h"
216 #include <Xm/XmStrDefs.h>
217 #endif /* USE_MOTIF */
223 #ifdef HAVE_WINDOW_SYSTEM
227 #define x_display_info w32_display_info
228 #define GCGraphicsExposures 0
229 #endif /* HAVE_NTGUI */
232 #define GCGraphicsExposures 0
234 #endif /* HAVE_WINDOW_SYSTEM */
237 #include "dispextern.h"
238 #include "blockinput.h"
240 #include "intervals.h"
241 #include "termchar.h"
245 #ifdef HAVE_X_WINDOWS
247 /* Compensate for a bug in Xos.h on some systems, on which it requires
248 time.h. On some such systems, Xos.h tries to redefine struct
249 timeval and struct timezone if USG is #defined while it is
252 #ifdef XOS_NEEDS_TIME_H
258 #if defined USG || defined __TIMEVAL__ /* Don't warn about unused macros. */
260 #else /* not XOS_NEEDS_TIME_H */
262 #endif /* not XOS_NEEDS_TIME_H */
264 #endif /* HAVE_X_WINDOWS */
268 /* Non-zero if face attribute ATTR is unspecified. */
270 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified)
272 /* Non-zero if face attribute ATTR is `ignore-defface'. */
274 #define IGNORE_DEFFACE_P(ATTR) EQ ((ATTR), QCignore_defface)
276 /* Size of hash table of realized faces in face caches (should be a
279 #define FACE_CACHE_BUCKETS_SIZE 1001
281 char unspecified_fg
[] = "unspecified-fg", unspecified_bg
[] = "unspecified-bg";
283 /* Alist of alternative font families. Each element is of the form
284 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
285 try FAMILY1, then FAMILY2, ... */
287 Lisp_Object Vface_alternative_font_family_alist
;
289 /* Alist of alternative font registries. Each element is of the form
290 (REGISTRY REGISTRY1 REGISTRY2...). If fonts of REGISTRY can't be
291 loaded, try REGISTRY1, then REGISTRY2, ... */
293 Lisp_Object Vface_alternative_font_registry_alist
;
295 /* The next ID to assign to Lisp faces. */
297 static int next_lface_id
;
299 /* A vector mapping Lisp face Id's to face names. */
301 static Lisp_Object
*lface_id_to_name
;
302 static ptrdiff_t lface_id_to_name_size
;
304 #ifdef HAVE_WINDOW_SYSTEM
306 /* Counter for calls to clear_face_cache. If this counter reaches
307 CLEAR_FONT_TABLE_COUNT, and a frame has more than
308 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
310 static int clear_font_table_count
;
311 #define CLEAR_FONT_TABLE_COUNT 100
312 #define CLEAR_FONT_TABLE_NFONTS 10
314 #endif /* HAVE_WINDOW_SYSTEM */
316 /* Non-zero means face attributes have been changed since the last
317 redisplay. Used in redisplay_internal. */
319 int face_change_count
;
321 /* Non-zero means don't display bold text if a face's foreground
322 and background colors are the inverse of the default colors of the
323 display. This is a kluge to suppress `bold black' foreground text
324 which is hard to read on an LCD monitor. */
326 static int tty_suppress_bold_inverse_default_colors_p
;
328 /* A list of the form `((x . y))' used to avoid consing in
329 Finternal_set_lisp_face_attribute. */
331 static Lisp_Object Vparam_value_alist
;
333 /* The total number of colors currently allocated. */
336 static int ncolors_allocated
;
337 static int npixmaps_allocated
;
341 /* Non-zero means the definition of the `menu' face for new frames has
344 static int menu_face_changed_default
;
346 struct named_merge_point
;
348 static struct face
*realize_face (struct face_cache
*, Lisp_Object
*,
350 static struct face
*realize_x_face (struct face_cache
*, Lisp_Object
*);
351 static struct face
*realize_tty_face (struct face_cache
*, Lisp_Object
*);
352 static bool realize_basic_faces (struct frame
*);
353 static bool realize_default_face (struct frame
*);
354 static void realize_named_face (struct frame
*, Lisp_Object
, int);
355 static struct face_cache
*make_face_cache (struct frame
*);
356 static void free_face_cache (struct face_cache
*);
357 static int merge_face_ref (struct frame
*, Lisp_Object
, Lisp_Object
*,
358 int, struct named_merge_point
*);
359 static int color_distance (XColor
*x
, XColor
*y
);
361 #ifdef HAVE_WINDOW_SYSTEM
362 static void set_font_frame_param (Lisp_Object
, Lisp_Object
);
363 static void clear_face_gcs (struct face_cache
*);
364 static struct face
*realize_non_ascii_face (struct frame
*, Lisp_Object
,
366 #endif /* HAVE_WINDOW_SYSTEM */
368 /***********************************************************************
370 ***********************************************************************/
372 #ifdef HAVE_X_WINDOWS
374 #ifdef DEBUG_X_COLORS
376 /* The following is a poor mans infrastructure for debugging X color
377 allocation problems on displays with PseudoColor-8. Some X servers
378 like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement
379 color reference counts completely so that they don't signal an
380 error when a color is freed whose reference count is already 0.
381 Other X servers do. To help me debug this, the following code
382 implements a simple reference counting schema of its own, for a
383 single display/screen. --gerd. */
385 /* Reference counts for pixel colors. */
387 int color_count
[256];
389 /* Register color PIXEL as allocated. */
392 register_color (unsigned long pixel
)
394 eassert (pixel
< 256);
395 ++color_count
[pixel
];
399 /* Register color PIXEL as deallocated. */
402 unregister_color (unsigned long pixel
)
404 eassert (pixel
< 256);
405 if (color_count
[pixel
] > 0)
406 --color_count
[pixel
];
412 /* Register N colors from PIXELS as deallocated. */
415 unregister_colors (unsigned long *pixels
, int n
)
418 for (i
= 0; i
< n
; ++i
)
419 unregister_color (pixels
[i
]);
423 DEFUN ("dump-colors", Fdump_colors
, Sdump_colors
, 0, 0, 0,
424 doc
: /* Dump currently allocated colors to stderr. */)
429 fputc ('\n', stderr
);
431 for (i
= n
= 0; i
< ARRAYELTS (color_count
); ++i
)
434 fprintf (stderr
, "%3d: %5d", i
, color_count
[i
]);
437 fputc ('\n', stderr
);
439 fputc ('\t', stderr
);
443 fputc ('\n', stderr
);
447 #endif /* DEBUG_X_COLORS */
450 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
451 color values. Interrupt input must be blocked when this function
455 x_free_colors (struct frame
*f
, unsigned long *pixels
, int npixels
)
457 int class = FRAME_DISPLAY_INFO (f
)->visual
->class;
459 /* If display has an immutable color map, freeing colors is not
460 necessary and some servers don't allow it. So don't do it. */
461 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
463 #ifdef DEBUG_X_COLORS
464 unregister_colors (pixels
, npixels
);
466 XFreeColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
474 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
475 color values. Interrupt input must be blocked when this function
479 x_free_dpy_colors (Display
*dpy
, Screen
*screen
, Colormap cmap
,
480 unsigned long *pixels
, int npixels
)
482 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
483 int class = dpyinfo
->visual
->class;
485 /* If display has an immutable color map, freeing colors is not
486 necessary and some servers don't allow it. So don't do it. */
487 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
489 #ifdef DEBUG_X_COLORS
490 unregister_colors (pixels
, npixels
);
492 XFreeColors (dpy
, cmap
, pixels
, npixels
, 0);
495 #endif /* USE_X_TOOLKIT */
497 /* Create and return a GC for use on frame F. GC values and mask
498 are given by XGCV and MASK. */
501 x_create_gc (struct frame
*f
, unsigned long mask
, XGCValues
*xgcv
)
505 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
512 /* Free GC which was used on frame F. */
515 x_free_gc (struct frame
*f
, GC gc
)
517 eassert (input_blocked_p ());
518 IF_DEBUG ((--ngcs
, eassert (ngcs
>= 0)));
519 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
522 #endif /* HAVE_X_WINDOWS */
525 /* W32 emulation of GCs */
528 x_create_gc (struct frame
*f
, unsigned long mask
, XGCValues
*xgcv
)
532 gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, xgcv
);
539 /* Free GC which was used on frame F. */
542 x_free_gc (struct frame
*f
, GC gc
)
544 IF_DEBUG ((--ngcs
, eassert (ngcs
>= 0)));
548 #endif /* HAVE_NTGUI */
551 /* NS emulation of GCs */
554 x_create_gc (struct frame
*f
,
558 GC gc
= xmalloc (sizeof *gc
);
564 x_free_gc (struct frame
*f
, GC gc
)
570 /***********************************************************************
572 ***********************************************************************/
574 /* Initialize face cache and basic faces for frame F. */
577 init_frame_faces (struct frame
*f
)
579 /* Make a face cache, if F doesn't have one. */
580 if (FRAME_FACE_CACHE (f
) == NULL
)
581 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
583 #ifdef HAVE_WINDOW_SYSTEM
584 /* Make the image cache. */
585 if (FRAME_WINDOW_P (f
))
587 /* We initialize the image cache when creating the first frame
588 on a terminal, and not during terminal creation. This way,
589 `x-open-connection' on a tty won't create an image cache. */
590 if (FRAME_IMAGE_CACHE (f
) == NULL
)
591 FRAME_IMAGE_CACHE (f
) = make_image_cache ();
592 ++FRAME_IMAGE_CACHE (f
)->refcount
;
594 #endif /* HAVE_WINDOW_SYSTEM */
596 /* Realize faces early (Bug#17889). */
597 if (!realize_basic_faces (f
))
602 /* Free face cache of frame F. Called from frame-dependent
603 resource freeing function, e.g. (x|tty)_free_frame_resources. */
606 free_frame_faces (struct frame
*f
)
608 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
612 free_face_cache (face_cache
);
613 FRAME_FACE_CACHE (f
) = NULL
;
616 #ifdef HAVE_WINDOW_SYSTEM
617 if (FRAME_WINDOW_P (f
))
619 struct image_cache
*image_cache
= FRAME_IMAGE_CACHE (f
);
622 --image_cache
->refcount
;
623 if (image_cache
->refcount
== 0)
624 free_image_cache (f
);
627 #endif /* HAVE_WINDOW_SYSTEM */
631 /* Clear face caches, and recompute basic faces for frame F. Call
632 this after changing frame parameters on which those faces depend,
633 or when realized faces have been freed due to changing attributes
637 recompute_basic_faces (struct frame
*f
)
639 if (FRAME_FACE_CACHE (f
))
641 clear_face_cache (0);
642 if (!realize_basic_faces (f
))
648 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
649 try to free unused fonts, too. */
652 clear_face_cache (bool clear_fonts_p
)
654 #ifdef HAVE_WINDOW_SYSTEM
655 Lisp_Object tail
, frame
;
658 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
660 /* From time to time see if we can unload some fonts. This also
661 frees all realized faces on all frames. Fonts needed by
662 faces will be loaded again when faces are realized again. */
663 clear_font_table_count
= 0;
665 FOR_EACH_FRAME (tail
, frame
)
667 struct frame
*f
= XFRAME (frame
);
668 if (FRAME_WINDOW_P (f
)
669 && FRAME_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
671 clear_font_cache (f
);
672 free_all_realized_faces (frame
);
678 /* Clear GCs of realized faces. */
679 FOR_EACH_FRAME (tail
, frame
)
681 struct frame
*f
= XFRAME (frame
);
682 if (FRAME_WINDOW_P (f
))
683 clear_face_gcs (FRAME_FACE_CACHE (f
));
685 clear_image_caches (Qnil
);
687 #endif /* HAVE_WINDOW_SYSTEM */
691 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
692 doc
: /* Clear face caches on all frames.
693 Optional THOROUGHLY non-nil means try to free unused fonts, too. */)
694 (Lisp_Object thoroughly
)
696 clear_face_cache (!NILP (thoroughly
));
698 windows_or_buffers_changed
= 53;
703 /***********************************************************************
705 ***********************************************************************/
707 #ifdef HAVE_WINDOW_SYSTEM
709 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
710 doc
: /* Value is non-nil if OBJECT is a valid bitmap specification.
711 A bitmap specification is either a string, a file name, or a list
712 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
713 HEIGHT is its height, and DATA is a string containing the bits of
714 the pixmap. Bits are stored row by row, each row occupies
715 \(WIDTH + 7)/8 bytes. */)
720 if (STRINGP (object
))
721 /* If OBJECT is a string, it's a file name. */
723 else if (CONSP (object
))
725 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
726 HEIGHT must be ints > 0, and DATA must be string large
727 enough to hold a bitmap of the specified size. */
728 Lisp_Object width
, height
, data
;
730 height
= width
= data
= Qnil
;
734 width
= XCAR (object
);
735 object
= XCDR (object
);
738 height
= XCAR (object
);
739 object
= XCDR (object
);
741 data
= XCAR (object
);
746 && RANGED_INTEGERP (1, width
, INT_MAX
)
747 && RANGED_INTEGERP (1, height
, INT_MAX
))
749 int bytes_per_row
= ((XINT (width
) + BITS_PER_CHAR
- 1)
751 if (XINT (height
) <= SBYTES (data
) / bytes_per_row
)
756 return pixmap_p
? Qt
: Qnil
;
760 /* Load a bitmap according to NAME (which is either a file name or a
761 pixmap spec) for use on frame F. Value is the bitmap_id (see
762 xfns.c). If NAME is nil, return with a bitmap id of zero. If
763 bitmap cannot be loaded, display a message saying so, and return
767 load_pixmap (struct frame
*f
, Lisp_Object name
)
774 CHECK_TYPE (!NILP (Fbitmap_spec_p (name
)), Qbitmap_spec_p
, name
);
779 /* Decode a bitmap spec into a bitmap. */
784 w
= XINT (Fcar (name
));
785 h
= XINT (Fcar (Fcdr (name
)));
786 bits
= Fcar (Fcdr (Fcdr (name
)));
788 bitmap_id
= x_create_bitmap_from_data (f
, SSDATA (bits
),
793 /* It must be a string -- a file name. */
794 bitmap_id
= x_create_bitmap_from_file (f
, name
);
800 add_to_log ("Invalid or undefined bitmap `%s'", name
, Qnil
);
806 ++npixmaps_allocated
;
813 #endif /* HAVE_WINDOW_SYSTEM */
817 /***********************************************************************
819 ***********************************************************************/
821 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
822 RGB_LIST should contain (at least) 3 lisp integers.
823 Return 0 if there's a problem with RGB_LIST, otherwise return 1. */
826 parse_rgb_list (Lisp_Object rgb_list
, XColor
*color
)
828 #define PARSE_RGB_LIST_FIELD(field) \
829 if (CONSP (rgb_list) && INTEGERP (XCAR (rgb_list))) \
831 color->field = XINT (XCAR (rgb_list)); \
832 rgb_list = XCDR (rgb_list); \
837 PARSE_RGB_LIST_FIELD (red
);
838 PARSE_RGB_LIST_FIELD (green
);
839 PARSE_RGB_LIST_FIELD (blue
);
845 /* Lookup on frame F the color described by the lisp string COLOR.
846 The resulting tty color is returned in TTY_COLOR; if STD_COLOR is
847 non-zero, then the `standard' definition of the same color is
851 tty_lookup_color (struct frame
*f
, Lisp_Object color
, XColor
*tty_color
,
854 Lisp_Object frame
, color_desc
;
856 if (!STRINGP (color
) || NILP (Ffboundp (Qtty_color_desc
)))
859 XSETFRAME (frame
, f
);
861 color_desc
= call2 (Qtty_color_desc
, color
, frame
);
862 if (CONSP (color_desc
) && CONSP (XCDR (color_desc
)))
866 if (! INTEGERP (XCAR (XCDR (color_desc
))))
869 tty_color
->pixel
= XINT (XCAR (XCDR (color_desc
)));
871 rgb
= XCDR (XCDR (color_desc
));
872 if (! parse_rgb_list (rgb
, tty_color
))
875 /* Should we fill in STD_COLOR too? */
878 /* Default STD_COLOR to the same as TTY_COLOR. */
879 *std_color
= *tty_color
;
881 /* Do a quick check to see if the returned descriptor is
882 actually _exactly_ equal to COLOR, otherwise we have to
883 lookup STD_COLOR separately. If it's impossible to lookup
884 a standard color, we just give up and use TTY_COLOR. */
885 if ((!STRINGP (XCAR (color_desc
))
886 || NILP (Fstring_equal (color
, XCAR (color_desc
))))
887 && !NILP (Ffboundp (Qtty_color_standard_values
)))
889 /* Look up STD_COLOR separately. */
890 rgb
= call1 (Qtty_color_standard_values
, color
);
891 if (! parse_rgb_list (rgb
, std_color
))
898 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
899 /* We were called early during startup, and the colors are not
900 yet set up in tty-defined-color-alist. Don't return a failure
901 indication, since this produces the annoying "Unable to
902 load color" messages in the *Messages* buffer. */
905 /* tty-color-desc seems to have returned a bad value. */
909 /* A version of defined_color for non-X frames. */
912 tty_defined_color (struct frame
*f
, const char *color_name
,
913 XColor
*color_def
, bool alloc
)
918 color_def
->pixel
= FACE_TTY_DEFAULT_COLOR
;
921 color_def
->green
= 0;
924 status
= tty_lookup_color (f
, build_string (color_name
), color_def
, NULL
);
926 if (color_def
->pixel
== FACE_TTY_DEFAULT_COLOR
&& *color_name
)
928 if (strcmp (color_name
, "unspecified-fg") == 0)
929 color_def
->pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
930 else if (strcmp (color_name
, "unspecified-bg") == 0)
931 color_def
->pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
934 if (color_def
->pixel
!= FACE_TTY_DEFAULT_COLOR
)
941 /* Decide if color named COLOR_NAME is valid for the display
942 associated with the frame F; if so, return the rgb values in
943 COLOR_DEF. If ALLOC, allocate a new colormap cell.
945 This does the right thing for any type of frame. */
948 defined_color (struct frame
*f
, const char *color_name
, XColor
*color_def
,
951 if (!FRAME_WINDOW_P (f
))
952 return tty_defined_color (f
, color_name
, color_def
, alloc
);
953 #ifdef HAVE_X_WINDOWS
954 else if (FRAME_X_P (f
))
955 return x_defined_color (f
, color_name
, color_def
, alloc
);
958 else if (FRAME_W32_P (f
))
959 return w32_defined_color (f
, color_name
, color_def
, alloc
);
962 else if (FRAME_NS_P (f
))
963 return ns_defined_color (f
, color_name
, color_def
, alloc
, 1);
970 /* Given the index IDX of a tty color on frame F, return its name, a
974 tty_color_name (struct frame
*f
, int idx
)
976 if (idx
>= 0 && !NILP (Ffboundp (Qtty_color_by_index
)))
981 XSETFRAME (frame
, f
);
982 coldesc
= call2 (Qtty_color_by_index
, make_number (idx
), frame
);
985 return XCAR (coldesc
);
988 /* We can have an MS-DOS frame under -nw for a short window of
989 opportunity before internal_terminal_init is called. DTRT. */
990 if (FRAME_MSDOS_P (f
) && !inhibit_window_system
)
991 return msdos_stdcolor_name (idx
);
994 if (idx
== FACE_TTY_DEFAULT_FG_COLOR
)
995 return build_string (unspecified_fg
);
996 if (idx
== FACE_TTY_DEFAULT_BG_COLOR
)
997 return build_string (unspecified_bg
);
1003 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1006 The criterion implemented here is not a terribly sophisticated one. */
1009 face_color_gray_p (struct frame
*f
, const char *color_name
)
1014 if (defined_color (f
, color_name
, &color
, 0))
1015 gray_p
= (/* Any color sufficiently close to black counts as gray. */
1016 (color
.red
< 5000 && color
.green
< 5000 && color
.blue
< 5000)
1018 ((eabs (color
.red
- color
.green
)
1019 < max (color
.red
, color
.green
) / 20)
1020 && (eabs (color
.green
- color
.blue
)
1021 < max (color
.green
, color
.blue
) / 20)
1022 && (eabs (color
.blue
- color
.red
)
1023 < max (color
.blue
, color
.red
) / 20)));
1031 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1032 BACKGROUND_P non-zero means the color will be used as background
1036 face_color_supported_p (struct frame
*f
, const char *color_name
,
1042 XSETFRAME (frame
, f
);
1044 #ifdef HAVE_WINDOW_SYSTEM
1046 ? (!NILP (Fxw_display_color_p (frame
))
1047 || xstrcasecmp (color_name
, "black") == 0
1048 || xstrcasecmp (color_name
, "white") == 0
1050 && face_color_gray_p (f
, color_name
))
1051 || (!NILP (Fx_display_grayscale_p (frame
))
1052 && face_color_gray_p (f
, color_name
)))
1055 tty_defined_color (f
, color_name
, ¬_used
, 0);
1059 DEFUN ("color-gray-p", Fcolor_gray_p
, Scolor_gray_p
, 1, 2, 0,
1060 doc
: /* Return non-nil if COLOR is a shade of gray (or white or black).
1061 FRAME specifies the frame and thus the display for interpreting COLOR.
1062 If FRAME is nil or omitted, use the selected frame. */)
1063 (Lisp_Object color
, Lisp_Object frame
)
1065 CHECK_STRING (color
);
1066 return (face_color_gray_p (decode_any_frame (frame
), SSDATA (color
))
1071 DEFUN ("color-supported-p", Fcolor_supported_p
,
1072 Scolor_supported_p
, 1, 3, 0,
1073 doc
: /* Return non-nil if COLOR can be displayed on FRAME.
1074 BACKGROUND-P non-nil means COLOR is used as a background.
1075 Otherwise, this function tells whether it can be used as a foreground.
1076 If FRAME is nil or omitted, use the selected frame.
1077 COLOR must be a valid color name. */)
1078 (Lisp_Object color
, Lisp_Object frame
, Lisp_Object background_p
)
1080 CHECK_STRING (color
);
1081 return (face_color_supported_p (decode_any_frame (frame
),
1082 SSDATA (color
), !NILP (background_p
))
1087 static unsigned long
1088 load_color2 (struct frame
*f
, struct face
*face
, Lisp_Object name
,
1089 enum lface_attribute_index target_index
, XColor
*color
)
1091 eassert (STRINGP (name
));
1092 eassert (target_index
== LFACE_FOREGROUND_INDEX
1093 || target_index
== LFACE_BACKGROUND_INDEX
1094 || target_index
== LFACE_UNDERLINE_INDEX
1095 || target_index
== LFACE_OVERLINE_INDEX
1096 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1097 || target_index
== LFACE_BOX_INDEX
);
1099 /* if the color map is full, defined_color will return a best match
1100 to the values in an existing cell. */
1101 if (!defined_color (f
, SSDATA (name
), color
, 1))
1103 add_to_log ("Unable to load color \"%s\"", name
, Qnil
);
1105 switch (target_index
)
1107 case LFACE_FOREGROUND_INDEX
:
1108 face
->foreground_defaulted_p
= 1;
1109 color
->pixel
= FRAME_FOREGROUND_PIXEL (f
);
1112 case LFACE_BACKGROUND_INDEX
:
1113 face
->background_defaulted_p
= 1;
1114 color
->pixel
= FRAME_BACKGROUND_PIXEL (f
);
1117 case LFACE_UNDERLINE_INDEX
:
1118 face
->underline_defaulted_p
= 1;
1119 color
->pixel
= FRAME_FOREGROUND_PIXEL (f
);
1122 case LFACE_OVERLINE_INDEX
:
1123 face
->overline_color_defaulted_p
= 1;
1124 color
->pixel
= FRAME_FOREGROUND_PIXEL (f
);
1127 case LFACE_STRIKE_THROUGH_INDEX
:
1128 face
->strike_through_color_defaulted_p
= 1;
1129 color
->pixel
= FRAME_FOREGROUND_PIXEL (f
);
1132 case LFACE_BOX_INDEX
:
1133 face
->box_color_defaulted_p
= 1;
1134 color
->pixel
= FRAME_FOREGROUND_PIXEL (f
);
1143 ++ncolors_allocated
;
1146 return color
->pixel
;
1149 /* Load color with name NAME for use by face FACE on frame F.
1150 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1151 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1152 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1153 pixel color. If color cannot be loaded, display a message, and
1154 return the foreground, background or underline color of F, but
1155 record that fact in flags of the face so that we don't try to free
1159 load_color (struct frame
*f
, struct face
*face
, Lisp_Object name
,
1160 enum lface_attribute_index target_index
)
1163 return load_color2 (f
, face
, name
, target_index
, &color
);
1167 #ifdef HAVE_WINDOW_SYSTEM
1169 #define NEAR_SAME_COLOR_THRESHOLD 30000
1171 /* Load colors for face FACE which is used on frame F. Colors are
1172 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1173 of ATTRS. If the background color specified is not supported on F,
1174 try to emulate gray colors with a stipple from Vface_default_stipple. */
1177 load_face_colors (struct frame
*f
, struct face
*face
,
1178 Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
1180 Lisp_Object fg
, bg
, dfg
;
1183 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1184 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1186 /* Swap colors if face is inverse-video. */
1187 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1195 /* Check for support for foreground, not for background because
1196 face_color_supported_p is smart enough to know that grays are
1197 "supported" as background because we are supposed to use stipple
1199 if (!face_color_supported_p (f
, SSDATA (bg
), 0)
1200 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1202 x_destroy_bitmap (f
, face
->stipple
);
1203 face
->stipple
= load_pixmap (f
, Vface_default_stipple
);
1206 face
->background
= load_color2 (f
, face
, bg
, LFACE_BACKGROUND_INDEX
, &xbg
);
1207 face
->foreground
= load_color2 (f
, face
, fg
, LFACE_FOREGROUND_INDEX
, &xfg
);
1209 dfg
= attrs
[LFACE_DISTANT_FOREGROUND_INDEX
];
1210 if (!NILP (dfg
) && !UNSPECIFIEDP (dfg
)
1211 && color_distance (&xbg
, &xfg
) < NEAR_SAME_COLOR_THRESHOLD
)
1213 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1214 face
->background
= load_color (f
, face
, dfg
, LFACE_BACKGROUND_INDEX
);
1216 face
->foreground
= load_color (f
, face
, dfg
, LFACE_FOREGROUND_INDEX
);
1220 #ifdef HAVE_X_WINDOWS
1222 /* Free color PIXEL on frame F. */
1225 unload_color (struct frame
*f
, unsigned long pixel
)
1230 x_free_colors (f
, &pixel
, 1);
1235 /* Free colors allocated for FACE. */
1238 free_face_colors (struct frame
*f
, struct face
*face
)
1240 /* PENDING(NS): need to do something here? */
1242 if (face
->colors_copied_bitwise_p
)
1247 if (!face
->foreground_defaulted_p
)
1249 x_free_colors (f
, &face
->foreground
, 1);
1250 IF_DEBUG (--ncolors_allocated
);
1253 if (!face
->background_defaulted_p
)
1255 x_free_colors (f
, &face
->background
, 1);
1256 IF_DEBUG (--ncolors_allocated
);
1259 if (face
->underline_p
1260 && !face
->underline_defaulted_p
)
1262 x_free_colors (f
, &face
->underline_color
, 1);
1263 IF_DEBUG (--ncolors_allocated
);
1266 if (face
->overline_p
1267 && !face
->overline_color_defaulted_p
)
1269 x_free_colors (f
, &face
->overline_color
, 1);
1270 IF_DEBUG (--ncolors_allocated
);
1273 if (face
->strike_through_p
1274 && !face
->strike_through_color_defaulted_p
)
1276 x_free_colors (f
, &face
->strike_through_color
, 1);
1277 IF_DEBUG (--ncolors_allocated
);
1280 if (face
->box
!= FACE_NO_BOX
1281 && !face
->box_color_defaulted_p
)
1283 x_free_colors (f
, &face
->box_color
, 1);
1284 IF_DEBUG (--ncolors_allocated
);
1290 #endif /* HAVE_X_WINDOWS */
1292 #endif /* HAVE_WINDOW_SYSTEM */
1296 /***********************************************************************
1298 ***********************************************************************/
1300 /* An enumerator for each field of an XLFD font name. */
1321 /* An enumerator for each possible slant value of a font. Taken from
1322 the XLFD specification. */
1330 XLFD_SLANT_REVERSE_ITALIC
,
1331 XLFD_SLANT_REVERSE_OBLIQUE
,
1335 /* Relative font weight according to XLFD documentation. */
1339 XLFD_WEIGHT_UNKNOWN
,
1340 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1341 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1342 XLFD_WEIGHT_LIGHT
, /* 30 */
1343 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1344 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1345 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1346 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1347 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1348 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1351 /* Relative proportionate width. */
1355 XLFD_SWIDTH_UNKNOWN
,
1356 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1357 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1358 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1359 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1360 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1361 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1362 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1363 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1364 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1367 /* Order by which font selection chooses fonts. The default values
1368 mean `first, find a best match for the font width, then for the
1369 font height, then for weight, then for slant.' This variable can be
1370 set via set-face-font-sort-order. */
1372 static int font_sort_order
[4];
1374 #ifdef HAVE_WINDOW_SYSTEM
1376 static enum font_property_index font_props_for_sorting
[FONT_SIZE_INDEX
];
1379 compare_fonts_by_sort_order (const void *v1
, const void *v2
)
1381 Lisp_Object
const *p1
= v1
;
1382 Lisp_Object
const *p2
= v2
;
1383 Lisp_Object font1
= *p1
;
1384 Lisp_Object font2
= *p2
;
1387 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1389 enum font_property_index idx
= font_props_for_sorting
[i
];
1390 Lisp_Object val1
= AREF (font1
, idx
), val2
= AREF (font2
, idx
);
1393 if (idx
<= FONT_REGISTRY_INDEX
)
1396 result
= STRINGP (val2
) ? strcmp (SSDATA (val1
), SSDATA (val2
)) : -1;
1398 result
= STRINGP (val2
) ? 1 : 0;
1402 if (INTEGERP (val1
))
1403 result
= (INTEGERP (val2
) && XINT (val1
) >= XINT (val2
)
1404 ? XINT (val1
) > XINT (val2
)
1407 result
= INTEGERP (val2
) ? 1 : 0;
1415 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
1416 doc
: /* Return a list of available fonts of family FAMILY on FRAME.
1417 If FAMILY is omitted or nil, list all families.
1418 Otherwise, FAMILY must be a string, possibly containing wildcards
1420 If FRAME is omitted or nil, use the selected frame.
1421 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
1422 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
1423 FAMILY is the font family name. POINT-SIZE is the size of the
1424 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
1425 width, weight and slant of the font. These symbols are the same as for
1426 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
1427 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
1428 giving the registry and encoding of the font.
1429 The result list is sorted according to the current setting of
1430 the face font sort order. */)
1431 (Lisp_Object family
, Lisp_Object frame
)
1433 Lisp_Object font_spec
, list
, *drivers
, vec
;
1434 struct frame
*f
= decode_live_frame (frame
);
1435 ptrdiff_t i
, nfonts
;
1440 font_spec
= Ffont_spec (0, NULL
);
1443 CHECK_STRING (family
);
1444 font_parse_family_registry (family
, Qnil
, font_spec
);
1447 list
= font_list_entities (f
, font_spec
);
1451 /* Sort the font entities. */
1452 for (i
= 0; i
< 4; i
++)
1453 switch (font_sort_order
[i
])
1456 font_props_for_sorting
[i
] = FONT_WIDTH_INDEX
; break;
1457 case XLFD_POINT_SIZE
:
1458 font_props_for_sorting
[i
] = FONT_SIZE_INDEX
; break;
1460 font_props_for_sorting
[i
] = FONT_WEIGHT_INDEX
; break;
1462 font_props_for_sorting
[i
] = FONT_SLANT_INDEX
; break;
1464 font_props_for_sorting
[i
++] = FONT_FAMILY_INDEX
;
1465 font_props_for_sorting
[i
++] = FONT_FOUNDRY_INDEX
;
1466 font_props_for_sorting
[i
++] = FONT_ADSTYLE_INDEX
;
1467 font_props_for_sorting
[i
++] = FONT_REGISTRY_INDEX
;
1469 ndrivers
= XINT (Flength (list
));
1470 SAFE_ALLOCA_LISP (drivers
, ndrivers
);
1471 for (i
= 0; i
< ndrivers
; i
++, list
= XCDR (list
))
1472 drivers
[i
] = XCAR (list
);
1473 vec
= Fvconcat (ndrivers
, drivers
);
1474 nfonts
= ASIZE (vec
);
1476 qsort (XVECTOR (vec
)->contents
, nfonts
, word_size
,
1477 compare_fonts_by_sort_order
);
1480 for (i
= nfonts
- 1; i
>= 0; --i
)
1482 Lisp_Object font
= AREF (vec
, i
);
1483 Lisp_Object v
= make_uninit_vector (8);
1485 Lisp_Object spacing
;
1487 ASET (v
, 0, AREF (font
, FONT_FAMILY_INDEX
));
1488 ASET (v
, 1, FONT_WIDTH_SYMBOLIC (font
));
1489 point
= PIXEL_TO_POINT (XINT (AREF (font
, FONT_SIZE_INDEX
)) * 10,
1491 ASET (v
, 2, make_number (point
));
1492 ASET (v
, 3, FONT_WEIGHT_SYMBOLIC (font
));
1493 ASET (v
, 4, FONT_SLANT_SYMBOLIC (font
));
1494 spacing
= Ffont_get (font
, QCspacing
);
1495 ASET (v
, 5, (NILP (spacing
) || EQ (spacing
, Qp
)) ? Qnil
: Qt
);
1496 ASET (v
, 6, Ffont_xlfd_name (font
, Qnil
));
1497 ASET (v
, 7, AREF (font
, FONT_REGISTRY_INDEX
));
1499 result
= Fcons (v
, result
);
1506 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
1507 doc
: /* Return a list of the names of available fonts matching PATTERN.
1508 If optional arguments FACE and FRAME are specified, return only fonts
1509 the same size as FACE on FRAME.
1511 PATTERN should be a string containing a font name in the XLFD,
1512 Fontconfig, or GTK format. A font name given in the XLFD format may
1513 contain wildcard characters:
1514 the * character matches any substring, and
1515 the ? character matches any single character.
1516 PATTERN is case-insensitive.
1518 The return value is a list of strings, suitable as arguments to
1521 Fonts Emacs can't use may or may not be excluded
1522 even if they match PATTERN and FACE.
1523 The optional fourth argument MAXIMUM sets a limit on how many
1524 fonts to match. The first MAXIMUM fonts are reported.
1525 The optional fifth argument WIDTH, if specified, is a number of columns
1526 occupied by a character of a font. In that case, return only fonts
1527 the WIDTH times as wide as FACE on FRAME. */)
1528 (Lisp_Object pattern
, Lisp_Object face
, Lisp_Object frame
,
1529 Lisp_Object maximum
, Lisp_Object width
)
1532 int size
, avgwidth
IF_LINT (= 0);
1534 check_window_system (NULL
);
1535 CHECK_STRING (pattern
);
1537 if (! NILP (maximum
))
1538 CHECK_NATNUM (maximum
);
1541 CHECK_NUMBER (width
);
1543 /* We can't simply call decode_window_system_frame because
1544 this function may be called before any frame is created. */
1545 f
= decode_live_frame (frame
);
1546 if (! FRAME_WINDOW_P (f
))
1548 /* Perhaps we have not yet created any frame. */
1554 XSETFRAME (frame
, f
);
1556 /* Determine the width standard for comparison with the fonts we find. */
1562 /* This is of limited utility since it works with character
1563 widths. Keep it for compatibility. --gerd. */
1564 int face_id
= lookup_named_face (f
, face
, 0);
1565 struct face
*width_face
= (face_id
< 0
1567 : FACE_FROM_ID (f
, face_id
));
1569 if (width_face
&& width_face
->font
)
1571 size
= width_face
->font
->pixel_size
;
1572 avgwidth
= width_face
->font
->average_width
;
1576 size
= FRAME_FONT (f
)->pixel_size
;
1577 avgwidth
= FRAME_FONT (f
)->average_width
;
1580 avgwidth
*= XINT (width
);
1583 Lisp_Object font_spec
= font_spec_from_name (pattern
);
1584 if (!FONTP (font_spec
))
1585 signal_error ("Invalid font name", pattern
);
1589 Ffont_put (font_spec
, QCsize
, make_number (size
));
1590 Ffont_put (font_spec
, QCavgwidth
, make_number (avgwidth
));
1592 Lisp_Object fonts
= Flist_fonts (font_spec
, frame
, maximum
, font_spec
);
1593 for (Lisp_Object tail
= fonts
; CONSP (tail
); tail
= XCDR (tail
))
1595 Lisp_Object font_entity
;
1597 font_entity
= XCAR (tail
);
1598 if ((NILP (AREF (font_entity
, FONT_SIZE_INDEX
))
1599 || XINT (AREF (font_entity
, FONT_SIZE_INDEX
)) == 0)
1600 && ! NILP (AREF (font_spec
, FONT_SIZE_INDEX
)))
1602 /* This is a scalable font. For backward compatibility,
1603 we set the specified size. */
1604 font_entity
= copy_font_spec (font_entity
);
1605 ASET (font_entity
, FONT_SIZE_INDEX
,
1606 AREF (font_spec
, FONT_SIZE_INDEX
));
1608 XSETCAR (tail
, Ffont_xlfd_name (font_entity
, Qnil
));
1611 /* We don't have to check fontsets. */
1613 Lisp_Object fontsets
= list_fontsets (f
, pattern
, size
);
1614 return CALLN (Fnconc
, fonts
, fontsets
);
1617 #endif /* HAVE_WINDOW_SYSTEM */
1620 /***********************************************************************
1622 ***********************************************************************/
1624 /* Access face attributes of face LFACE, a Lisp vector. */
1626 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
1627 #define LFACE_FOUNDRY(LFACE) AREF ((LFACE), LFACE_FOUNDRY_INDEX)
1628 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
1629 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
1630 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
1631 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
1632 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
1633 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
1634 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
1635 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
1636 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
1637 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
1638 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
1639 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
1640 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
1641 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
1642 #define LFACE_FONTSET(LFACE) AREF ((LFACE), LFACE_FONTSET_INDEX)
1643 #define LFACE_DISTANT_FOREGROUND(LFACE) \
1644 AREF ((LFACE), LFACE_DISTANT_FOREGROUND_INDEX)
1646 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
1647 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
1649 #define LFACEP(LFACE) \
1651 && ASIZE (LFACE) == LFACE_VECTOR_SIZE \
1652 && EQ (AREF (LFACE, 0), Qface))
1657 /* Check consistency of Lisp face attribute vector ATTRS. */
1660 check_lface_attrs (Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
1662 eassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
1663 || IGNORE_DEFFACE_P (attrs
[LFACE_FAMILY_INDEX
])
1664 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
1665 eassert (UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
1666 || IGNORE_DEFFACE_P (attrs
[LFACE_FOUNDRY_INDEX
])
1667 || STRINGP (attrs
[LFACE_FOUNDRY_INDEX
]));
1668 eassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
1669 || IGNORE_DEFFACE_P (attrs
[LFACE_SWIDTH_INDEX
])
1670 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
1671 eassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
1672 || IGNORE_DEFFACE_P (attrs
[LFACE_HEIGHT_INDEX
])
1673 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
])
1674 || FLOATP (attrs
[LFACE_HEIGHT_INDEX
])
1675 || FUNCTIONP (attrs
[LFACE_HEIGHT_INDEX
]));
1676 eassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
1677 || IGNORE_DEFFACE_P (attrs
[LFACE_WEIGHT_INDEX
])
1678 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
1679 eassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
1680 || IGNORE_DEFFACE_P (attrs
[LFACE_SLANT_INDEX
])
1681 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
1682 eassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
1683 || IGNORE_DEFFACE_P (attrs
[LFACE_UNDERLINE_INDEX
])
1684 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
1685 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
])
1686 || CONSP (attrs
[LFACE_UNDERLINE_INDEX
]));
1687 eassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
1688 || IGNORE_DEFFACE_P (attrs
[LFACE_OVERLINE_INDEX
])
1689 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
1690 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
1691 eassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1692 || IGNORE_DEFFACE_P (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1693 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1694 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
1695 eassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
1696 || IGNORE_DEFFACE_P (attrs
[LFACE_BOX_INDEX
])
1697 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
1698 || STRINGP (attrs
[LFACE_BOX_INDEX
])
1699 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
1700 || CONSP (attrs
[LFACE_BOX_INDEX
]));
1701 eassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
1702 || IGNORE_DEFFACE_P (attrs
[LFACE_INVERSE_INDEX
])
1703 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
1704 eassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
1705 || IGNORE_DEFFACE_P (attrs
[LFACE_FOREGROUND_INDEX
])
1706 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
1707 eassert (UNSPECIFIEDP (attrs
[LFACE_DISTANT_FOREGROUND_INDEX
])
1708 || IGNORE_DEFFACE_P (attrs
[LFACE_DISTANT_FOREGROUND_INDEX
])
1709 || STRINGP (attrs
[LFACE_DISTANT_FOREGROUND_INDEX
]));
1710 eassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
1711 || IGNORE_DEFFACE_P (attrs
[LFACE_BACKGROUND_INDEX
])
1712 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
1713 eassert (UNSPECIFIEDP (attrs
[LFACE_INHERIT_INDEX
])
1714 || IGNORE_DEFFACE_P (attrs
[LFACE_INHERIT_INDEX
])
1715 || NILP (attrs
[LFACE_INHERIT_INDEX
])
1716 || SYMBOLP (attrs
[LFACE_INHERIT_INDEX
])
1717 || CONSP (attrs
[LFACE_INHERIT_INDEX
]));
1718 #ifdef HAVE_WINDOW_SYSTEM
1719 eassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
1720 || IGNORE_DEFFACE_P (attrs
[LFACE_STIPPLE_INDEX
])
1721 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
1722 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
1723 eassert (UNSPECIFIEDP (attrs
[LFACE_FONT_INDEX
])
1724 || IGNORE_DEFFACE_P (attrs
[LFACE_FONT_INDEX
])
1725 || FONTP (attrs
[LFACE_FONT_INDEX
]));
1726 eassert (UNSPECIFIEDP (attrs
[LFACE_FONTSET_INDEX
])
1727 || STRINGP (attrs
[LFACE_FONTSET_INDEX
])
1728 || NILP (attrs
[LFACE_FONTSET_INDEX
]));
1733 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
1736 check_lface (Lisp_Object lface
)
1740 eassert (LFACEP (lface
));
1741 check_lface_attrs (XVECTOR (lface
)->contents
);
1745 #else /* not GLYPH_DEBUG */
1747 #define check_lface_attrs(attrs) (void) 0
1748 #define check_lface(lface) (void) 0
1750 #endif /* GLYPH_DEBUG */
1754 /* Face-merge cycle checking. */
1756 enum named_merge_point_kind
1758 NAMED_MERGE_POINT_NORMAL
,
1759 NAMED_MERGE_POINT_REMAP
1762 /* A `named merge point' is simply a point during face-merging where we
1763 look up a face by name. We keep a stack of which named lookups we're
1764 currently processing so that we can easily detect cycles, using a
1765 linked- list of struct named_merge_point structures, typically
1766 allocated on the stack frame of the named lookup functions which are
1767 active (so no consing is required). */
1768 struct named_merge_point
1770 Lisp_Object face_name
;
1771 enum named_merge_point_kind named_merge_point_kind
;
1772 struct named_merge_point
*prev
;
1776 /* If a face merging cycle is detected for FACE_NAME, return 0,
1777 otherwise add NEW_NAMED_MERGE_POINT, which is initialized using
1778 FACE_NAME and NAMED_MERGE_POINT_KIND, as the head of the linked list
1779 pointed to by NAMED_MERGE_POINTS, and return 1. */
1782 push_named_merge_point (struct named_merge_point
*new_named_merge_point
,
1783 Lisp_Object face_name
,
1784 enum named_merge_point_kind named_merge_point_kind
,
1785 struct named_merge_point
**named_merge_points
)
1787 struct named_merge_point
*prev
;
1789 for (prev
= *named_merge_points
; prev
; prev
= prev
->prev
)
1790 if (EQ (face_name
, prev
->face_name
))
1792 if (prev
->named_merge_point_kind
== named_merge_point_kind
)
1793 /* A cycle, so fail. */
1795 else if (prev
->named_merge_point_kind
== NAMED_MERGE_POINT_REMAP
)
1796 /* A remap `hides ' any previous normal merge points
1797 (because the remap means that it's actually different face),
1798 so as we know the current merge point must be normal, we
1799 can just assume it's OK. */
1803 new_named_merge_point
->face_name
= face_name
;
1804 new_named_merge_point
->named_merge_point_kind
= named_merge_point_kind
;
1805 new_named_merge_point
->prev
= *named_merge_points
;
1807 *named_merge_points
= new_named_merge_point
;
1813 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
1814 to make it a symbol. If FACE_NAME is an alias for another face,
1815 return that face's name.
1817 Return default face in case of errors. */
1820 resolve_face_name (Lisp_Object face_name
, int signal_p
)
1822 Lisp_Object orig_face
;
1823 Lisp_Object tortoise
, hare
;
1825 if (STRINGP (face_name
))
1826 face_name
= intern (SSDATA (face_name
));
1828 if (NILP (face_name
) || !SYMBOLP (face_name
))
1831 orig_face
= face_name
;
1832 tortoise
= hare
= face_name
;
1837 hare
= Fget (hare
, Qface_alias
);
1838 if (NILP (hare
) || !SYMBOLP (hare
))
1842 hare
= Fget (hare
, Qface_alias
);
1843 if (NILP (hare
) || !SYMBOLP (hare
))
1846 tortoise
= Fget (tortoise
, Qface_alias
);
1847 if (EQ (hare
, tortoise
))
1850 xsignal1 (Qcircular_list
, orig_face
);
1859 /* Return the face definition of FACE_NAME on frame F. F null means
1860 return the definition for new frames. FACE_NAME may be a string or
1861 a symbol (apparently Emacs 20.2 allowed strings as face names in
1862 face text properties; Ediff uses that). If SIGNAL_P is non-zero,
1863 signal an error if FACE_NAME is not a valid face name. If SIGNAL_P
1864 is zero, value is nil if FACE_NAME is not a valid face name. */
1866 lface_from_face_name_no_resolve (struct frame
*f
, Lisp_Object face_name
,
1872 lface
= assq_no_quit (face_name
, f
->face_alist
);
1874 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
1877 lface
= XCDR (lface
);
1879 signal_error ("Invalid face", face_name
);
1881 check_lface (lface
);
1886 /* Return the face definition of FACE_NAME on frame F. F null means
1887 return the definition for new frames. FACE_NAME may be a string or
1888 a symbol (apparently Emacs 20.2 allowed strings as face names in
1889 face text properties; Ediff uses that). If FACE_NAME is an alias
1890 for another face, return that face's definition. If SIGNAL_P is
1891 non-zero, signal an error if FACE_NAME is not a valid face name.
1892 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
1895 lface_from_face_name (struct frame
*f
, Lisp_Object face_name
, int signal_p
)
1897 face_name
= resolve_face_name (face_name
, signal_p
);
1898 return lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
1902 /* Get face attributes of face FACE_NAME from frame-local faces on
1903 frame F. Store the resulting attributes in ATTRS which must point
1904 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
1905 is non-zero, signal an error if FACE_NAME does not name a face.
1906 Otherwise, value is zero if FACE_NAME is not a face. */
1909 get_lface_attributes_no_remap (struct frame
*f
, Lisp_Object face_name
,
1910 Lisp_Object attrs
[LFACE_VECTOR_SIZE
],
1915 lface
= lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
1918 memcpy (attrs
, XVECTOR (lface
)->contents
,
1919 LFACE_VECTOR_SIZE
* sizeof *attrs
);
1921 return !NILP (lface
);
1924 /* Get face attributes of face FACE_NAME from frame-local faces on frame
1925 F. Store the resulting attributes in ATTRS which must point to a
1926 vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If FACE_NAME is an
1927 alias for another face, use that face's definition. If SIGNAL_P is
1928 non-zero, signal an error if FACE_NAME does not name a face.
1929 Otherwise, value is zero if FACE_NAME is not a face. */
1932 get_lface_attributes (struct frame
*f
, Lisp_Object face_name
,
1933 Lisp_Object attrs
[LFACE_VECTOR_SIZE
], int signal_p
,
1934 struct named_merge_point
*named_merge_points
)
1936 Lisp_Object face_remapping
;
1938 face_name
= resolve_face_name (face_name
, signal_p
);
1940 /* See if SYMBOL has been remapped to some other face (usually this
1941 is done buffer-locally). */
1942 face_remapping
= assq_no_quit (face_name
, Vface_remapping_alist
);
1943 if (CONSP (face_remapping
))
1945 struct named_merge_point named_merge_point
;
1947 if (push_named_merge_point (&named_merge_point
,
1948 face_name
, NAMED_MERGE_POINT_REMAP
,
1949 &named_merge_points
))
1953 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
1954 attrs
[i
] = Qunspecified
;
1956 return merge_face_ref (f
, XCDR (face_remapping
), attrs
,
1957 signal_p
, named_merge_points
);
1961 /* Default case, no remapping. */
1962 return get_lface_attributes_no_remap (f
, face_name
, attrs
, signal_p
);
1966 /* Non-zero if all attributes in face attribute vector ATTRS are
1967 specified, i.e. are non-nil. */
1970 lface_fully_specified_p (Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
1974 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
1975 if (i
!= LFACE_FONT_INDEX
&& i
!= LFACE_INHERIT_INDEX
1976 && i
!= LFACE_DISTANT_FOREGROUND_INDEX
)
1977 if ((UNSPECIFIEDP (attrs
[i
]) || IGNORE_DEFFACE_P (attrs
[i
])))
1980 return i
== LFACE_VECTOR_SIZE
;
1983 #ifdef HAVE_WINDOW_SYSTEM
1985 /* Set font-related attributes of Lisp face LFACE from FONT-OBJECT.
1986 If FORCE_P is zero, set only unspecified attributes of LFACE. The
1987 exception is `font' attribute. It is set to FONT_OBJECT regardless
1991 set_lface_from_font (struct frame
*f
, Lisp_Object lface
,
1992 Lisp_Object font_object
, int force_p
)
1995 struct font
*font
= XFONT_OBJECT (font_object
);
1997 /* Set attributes only if unspecified, otherwise face defaults for
1998 new frames would never take effect. If the font doesn't have a
1999 specific property, set a normal value for that. */
2001 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
2003 Lisp_Object family
= AREF (font_object
, FONT_FAMILY_INDEX
);
2005 ASET (lface
, LFACE_FAMILY_INDEX
, SYMBOL_NAME (family
));
2008 if (force_p
|| UNSPECIFIEDP (LFACE_FOUNDRY (lface
)))
2010 Lisp_Object foundry
= AREF (font_object
, FONT_FOUNDRY_INDEX
);
2012 ASET (lface
, LFACE_FOUNDRY_INDEX
, SYMBOL_NAME (foundry
));
2015 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
2017 int pt
= PIXEL_TO_POINT (font
->pixel_size
* 10, FRAME_RES_Y (f
));
2020 ASET (lface
, LFACE_HEIGHT_INDEX
, make_number (pt
));
2023 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
2025 val
= FONT_WEIGHT_FOR_FACE (font_object
);
2026 ASET (lface
, LFACE_WEIGHT_INDEX
, ! NILP (val
) ? val
:Qnormal
);
2028 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
2030 val
= FONT_SLANT_FOR_FACE (font_object
);
2031 ASET (lface
, LFACE_SLANT_INDEX
, ! NILP (val
) ? val
: Qnormal
);
2033 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
2035 val
= FONT_WIDTH_FOR_FACE (font_object
);
2036 ASET (lface
, LFACE_SWIDTH_INDEX
, ! NILP (val
) ? val
: Qnormal
);
2039 ASET (lface
, LFACE_FONT_INDEX
, font_object
);
2043 #endif /* HAVE_WINDOW_SYSTEM */
2046 /* Merges the face height FROM with the face height TO, and returns the
2047 merged height. If FROM is an invalid height, then INVALID is
2048 returned instead. FROM and TO may be either absolute face heights or
2049 `relative' heights; the returned value is always an absolute height
2050 unless both FROM and TO are relative. */
2053 merge_face_heights (Lisp_Object from
, Lisp_Object to
, Lisp_Object invalid
)
2055 Lisp_Object result
= invalid
;
2057 if (INTEGERP (from
))
2058 /* FROM is absolute, just use it as is. */
2060 else if (FLOATP (from
))
2061 /* FROM is a scale, use it to adjust TO. */
2064 /* relative X absolute => absolute */
2065 result
= make_number (XFLOAT_DATA (from
) * XINT (to
));
2066 else if (FLOATP (to
))
2067 /* relative X relative => relative */
2068 result
= make_float (XFLOAT_DATA (from
) * XFLOAT_DATA (to
));
2069 else if (UNSPECIFIEDP (to
))
2072 else if (FUNCTIONP (from
))
2073 /* FROM is a function, which use to adjust TO. */
2075 /* Call function with current height as argument.
2076 From is the new height. */
2077 result
= safe_call1 (from
, to
);
2079 /* Ensure that if TO was absolute, so is the result. */
2080 if (INTEGERP (to
) && !INTEGERP (result
))
2088 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
2089 store the resulting attributes in TO, which must be already be
2090 completely specified and contain only absolute attributes. Every
2091 specified attribute of FROM overrides the corresponding attribute of
2092 TO; relative attributes in FROM are merged with the absolute value in
2093 TO and replace it. NAMED_MERGE_POINTS is used internally to detect
2094 loops in face inheritance/remapping; it should be 0 when called from
2098 merge_face_vectors (struct frame
*f
, Lisp_Object
*from
, Lisp_Object
*to
,
2099 struct named_merge_point
*named_merge_points
)
2102 Lisp_Object font
= Qnil
;
2104 /* If FROM inherits from some other faces, merge their attributes into
2105 TO before merging FROM's direct attributes. Note that an :inherit
2106 attribute of `unspecified' is the same as one of nil; we never
2107 merge :inherit attributes, so nil is more correct, but lots of
2108 other code uses `unspecified' as a generic value for face attributes. */
2109 if (!UNSPECIFIEDP (from
[LFACE_INHERIT_INDEX
])
2110 && !NILP (from
[LFACE_INHERIT_INDEX
]))
2111 merge_face_ref (f
, from
[LFACE_INHERIT_INDEX
], to
, 0, named_merge_points
);
2113 if (FONT_SPEC_P (from
[LFACE_FONT_INDEX
]))
2115 if (!UNSPECIFIEDP (to
[LFACE_FONT_INDEX
]))
2116 font
= merge_font_spec (from
[LFACE_FONT_INDEX
], to
[LFACE_FONT_INDEX
]);
2118 font
= copy_font_spec (from
[LFACE_FONT_INDEX
]);
2119 to
[LFACE_FONT_INDEX
] = font
;
2122 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2123 if (!UNSPECIFIEDP (from
[i
]))
2125 if (i
== LFACE_HEIGHT_INDEX
&& !INTEGERP (from
[i
]))
2127 to
[i
] = merge_face_heights (from
[i
], to
[i
], to
[i
]);
2128 font_clear_prop (to
, FONT_SIZE_INDEX
);
2130 else if (i
!= LFACE_FONT_INDEX
&& ! EQ (to
[i
], from
[i
]))
2133 if (i
>= LFACE_FAMILY_INDEX
&& i
<=LFACE_SLANT_INDEX
)
2134 font_clear_prop (to
,
2135 (i
== LFACE_FAMILY_INDEX
? FONT_FAMILY_INDEX
2136 : i
== LFACE_FOUNDRY_INDEX
? FONT_FOUNDRY_INDEX
2137 : i
== LFACE_SWIDTH_INDEX
? FONT_WIDTH_INDEX
2138 : i
== LFACE_HEIGHT_INDEX
? FONT_SIZE_INDEX
2139 : i
== LFACE_WEIGHT_INDEX
? FONT_WEIGHT_INDEX
2140 : FONT_SLANT_INDEX
));
2144 /* If FROM specifies a font spec, make its contents take precedence
2145 over :family and other attributes. This is needed for face
2146 remapping using :font to work. */
2150 if (! NILP (AREF (font
, FONT_FOUNDRY_INDEX
)))
2151 to
[LFACE_FOUNDRY_INDEX
] = SYMBOL_NAME (AREF (font
, FONT_FOUNDRY_INDEX
));
2152 if (! NILP (AREF (font
, FONT_FAMILY_INDEX
)))
2153 to
[LFACE_FAMILY_INDEX
] = SYMBOL_NAME (AREF (font
, FONT_FAMILY_INDEX
));
2154 if (! NILP (AREF (font
, FONT_WEIGHT_INDEX
)))
2155 to
[LFACE_WEIGHT_INDEX
] = FONT_WEIGHT_FOR_FACE (font
);
2156 if (! NILP (AREF (font
, FONT_SLANT_INDEX
)))
2157 to
[LFACE_SLANT_INDEX
] = FONT_SLANT_FOR_FACE (font
);
2158 if (! NILP (AREF (font
, FONT_WIDTH_INDEX
)))
2159 to
[LFACE_SWIDTH_INDEX
] = FONT_WIDTH_FOR_FACE (font
);
2160 ASET (font
, FONT_SIZE_INDEX
, Qnil
);
2163 /* TO is always an absolute face, which should inherit from nothing.
2164 We blindly copy the :inherit attribute above and fix it up here. */
2165 to
[LFACE_INHERIT_INDEX
] = Qnil
;
2168 /* Merge the named face FACE_NAME on frame F, into the vector of face
2169 attributes TO. NAMED_MERGE_POINTS is used to detect loops in face
2170 inheritance. Returns true if FACE_NAME is a valid face name and
2171 merging succeeded. */
2174 merge_named_face (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*to
,
2175 struct named_merge_point
*named_merge_points
)
2177 struct named_merge_point named_merge_point
;
2179 if (push_named_merge_point (&named_merge_point
,
2180 face_name
, NAMED_MERGE_POINT_NORMAL
,
2181 &named_merge_points
))
2183 struct gcpro gcpro1
;
2184 Lisp_Object from
[LFACE_VECTOR_SIZE
];
2185 int ok
= get_lface_attributes (f
, face_name
, from
, 0, named_merge_points
);
2189 GCPRO1 (named_merge_point
.face_name
);
2190 merge_face_vectors (f
, from
, to
, named_merge_points
);
2201 /* Merge face attributes from the lisp `face reference' FACE_REF on
2202 frame F into the face attribute vector TO. If ERR_MSGS is non-zero,
2203 problems with FACE_REF cause an error message to be shown. Return
2204 non-zero if no errors occurred (regardless of the value of ERR_MSGS).
2205 NAMED_MERGE_POINTS is used to detect loops in face inheritance or
2206 list structure; it may be 0 for most callers.
2208 FACE_REF may be a single face specification or a list of such
2209 specifications. Each face specification can be:
2211 1. A symbol or string naming a Lisp face.
2213 2. A property list of the form (KEYWORD VALUE ...) where each
2214 KEYWORD is a face attribute name, and value is an appropriate value
2217 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
2218 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
2219 for compatibility with 20.2.
2221 Face specifications earlier in lists take precedence over later
2225 merge_face_ref (struct frame
*f
, Lisp_Object face_ref
, Lisp_Object
*to
,
2226 int err_msgs
, struct named_merge_point
*named_merge_points
)
2228 int ok
= 1; /* Succeed without an error? */
2230 if (CONSP (face_ref
))
2232 Lisp_Object first
= XCAR (face_ref
);
2234 if (EQ (first
, Qforeground_color
)
2235 || EQ (first
, Qbackground_color
))
2237 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
2238 . COLOR). COLOR must be a string. */
2239 Lisp_Object color_name
= XCDR (face_ref
);
2240 Lisp_Object color
= first
;
2242 if (STRINGP (color_name
))
2244 if (EQ (color
, Qforeground_color
))
2245 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
2247 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
2252 add_to_log ("Invalid face color", color_name
, Qnil
);
2256 else if (SYMBOLP (first
)
2257 && *SDATA (SYMBOL_NAME (first
)) == ':')
2259 /* Assume this is the property list form. */
2260 while (CONSP (face_ref
) && CONSP (XCDR (face_ref
)))
2262 Lisp_Object keyword
= XCAR (face_ref
);
2263 Lisp_Object value
= XCAR (XCDR (face_ref
));
2266 /* Specifying `unspecified' is a no-op. */
2267 if (EQ (value
, Qunspecified
))
2269 else if (EQ (keyword
, QCfamily
))
2271 if (STRINGP (value
))
2273 to
[LFACE_FAMILY_INDEX
] = value
;
2274 font_clear_prop (to
, FONT_FAMILY_INDEX
);
2279 else if (EQ (keyword
, QCfoundry
))
2281 if (STRINGP (value
))
2283 to
[LFACE_FOUNDRY_INDEX
] = value
;
2284 font_clear_prop (to
, FONT_FOUNDRY_INDEX
);
2289 else if (EQ (keyword
, QCheight
))
2291 Lisp_Object new_height
=
2292 merge_face_heights (value
, to
[LFACE_HEIGHT_INDEX
], Qnil
);
2294 if (! NILP (new_height
))
2296 to
[LFACE_HEIGHT_INDEX
] = new_height
;
2297 font_clear_prop (to
, FONT_SIZE_INDEX
);
2302 else if (EQ (keyword
, QCweight
))
2304 if (SYMBOLP (value
) && FONT_WEIGHT_NAME_NUMERIC (value
) >= 0)
2306 to
[LFACE_WEIGHT_INDEX
] = value
;
2307 font_clear_prop (to
, FONT_WEIGHT_INDEX
);
2312 else if (EQ (keyword
, QCslant
))
2314 if (SYMBOLP (value
) && FONT_SLANT_NAME_NUMERIC (value
) >= 0)
2316 to
[LFACE_SLANT_INDEX
] = value
;
2317 font_clear_prop (to
, FONT_SLANT_INDEX
);
2322 else if (EQ (keyword
, QCunderline
))
2328 to
[LFACE_UNDERLINE_INDEX
] = value
;
2332 else if (EQ (keyword
, QCoverline
))
2337 to
[LFACE_OVERLINE_INDEX
] = value
;
2341 else if (EQ (keyword
, QCstrike_through
))
2346 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
2350 else if (EQ (keyword
, QCbox
))
2353 value
= make_number (1);
2354 if (INTEGERP (value
)
2358 to
[LFACE_BOX_INDEX
] = value
;
2362 else if (EQ (keyword
, QCinverse_video
)
2363 || EQ (keyword
, QCreverse_video
))
2365 if (EQ (value
, Qt
) || NILP (value
))
2366 to
[LFACE_INVERSE_INDEX
] = value
;
2370 else if (EQ (keyword
, QCforeground
))
2372 if (STRINGP (value
))
2373 to
[LFACE_FOREGROUND_INDEX
] = value
;
2377 else if (EQ (keyword
, QCdistant_foreground
))
2379 if (STRINGP (value
))
2380 to
[LFACE_DISTANT_FOREGROUND_INDEX
] = value
;
2384 else if (EQ (keyword
, QCbackground
))
2386 if (STRINGP (value
))
2387 to
[LFACE_BACKGROUND_INDEX
] = value
;
2391 else if (EQ (keyword
, QCstipple
))
2393 #if defined (HAVE_WINDOW_SYSTEM)
2394 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
2395 if (!NILP (pixmap_p
))
2396 to
[LFACE_STIPPLE_INDEX
] = value
;
2399 #endif /* HAVE_WINDOW_SYSTEM */
2401 else if (EQ (keyword
, QCwidth
))
2403 if (SYMBOLP (value
) && FONT_WIDTH_NAME_NUMERIC (value
) >= 0)
2405 to
[LFACE_SWIDTH_INDEX
] = value
;
2406 font_clear_prop (to
, FONT_WIDTH_INDEX
);
2411 else if (EQ (keyword
, QCfont
))
2414 to
[LFACE_FONT_INDEX
] = value
;
2418 else if (EQ (keyword
, QCinherit
))
2420 /* This is not really very useful; it's just like a
2421 normal face reference. */
2422 if (! merge_face_ref (f
, value
, to
,
2423 err_msgs
, named_merge_points
))
2431 add_to_log ("Invalid face attribute %S %S", keyword
, value
);
2435 face_ref
= XCDR (XCDR (face_ref
));
2440 /* This is a list of face refs. Those at the beginning of the
2441 list take precedence over what follows, so we have to merge
2442 from the end backwards. */
2443 Lisp_Object next
= XCDR (face_ref
);
2446 ok
= merge_face_ref (f
, next
, to
, err_msgs
, named_merge_points
);
2448 if (! merge_face_ref (f
, first
, to
, err_msgs
, named_merge_points
))
2454 /* FACE_REF ought to be a face name. */
2455 ok
= merge_named_face (f
, face_ref
, to
, named_merge_points
);
2456 if (!ok
&& err_msgs
)
2457 add_to_log ("Invalid face reference: %s", face_ref
, Qnil
);
2464 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
2465 Sinternal_make_lisp_face
, 1, 2, 0,
2466 doc
: /* Make FACE, a symbol, a Lisp face with all attributes nil.
2467 If FACE was not known as a face before, create a new one.
2468 If optional argument FRAME is specified, make a frame-local face
2469 for that frame. Otherwise operate on the global face definition.
2470 Value is a vector of face attributes. */)
2471 (Lisp_Object face
, Lisp_Object frame
)
2473 Lisp_Object global_lface
, lface
;
2477 CHECK_SYMBOL (face
);
2478 global_lface
= lface_from_face_name (NULL
, face
, 0);
2482 CHECK_LIVE_FRAME (frame
);
2484 lface
= lface_from_face_name (f
, face
, 0);
2487 f
= NULL
, lface
= Qnil
;
2489 /* Add a global definition if there is none. */
2490 if (NILP (global_lface
))
2492 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2494 ASET (global_lface
, 0, Qface
);
2495 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
2496 Vface_new_frame_defaults
);
2498 /* Assign the new Lisp face a unique ID. The mapping from Lisp
2499 face id to Lisp face is given by the vector lface_id_to_name.
2500 The mapping from Lisp face to Lisp face id is given by the
2501 property `face' of the Lisp face name. */
2502 if (next_lface_id
== lface_id_to_name_size
)
2504 xpalloc (lface_id_to_name
, &lface_id_to_name_size
, 1, MAX_FACE_ID
,
2505 sizeof *lface_id_to_name
);
2507 lface_id_to_name
[next_lface_id
] = face
;
2508 Fput (face
, Qface
, make_number (next_lface_id
));
2512 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2513 ASET (global_lface
, i
, Qunspecified
);
2515 /* Add a frame-local definition. */
2520 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2522 ASET (lface
, 0, Qface
);
2523 fset_face_alist (f
, Fcons (Fcons (face
, lface
), f
->face_alist
));
2526 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2527 ASET (lface
, i
, Qunspecified
);
2530 lface
= global_lface
;
2532 /* Changing a named face means that all realized faces depending on
2533 that face are invalid. Since we cannot tell which realized faces
2534 depend on the face, make sure they are all removed. This is done
2535 by incrementing face_change_count. The next call to
2536 init_iterator will then free realized faces. */
2537 if (NILP (Fget (face
, Qface_no_inherit
)))
2539 ++face_change_count
;
2540 windows_or_buffers_changed
= 54;
2543 eassert (LFACEP (lface
));
2544 check_lface (lface
);
2549 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
2550 Sinternal_lisp_face_p
, 1, 2, 0,
2551 doc
: /* Return non-nil if FACE names a face.
2552 FACE should be a symbol or string.
2553 If optional second argument FRAME is non-nil, check for the
2554 existence of a frame-local face with name FACE on that frame.
2555 Otherwise check for the existence of a global face. */)
2556 (Lisp_Object face
, Lisp_Object frame
)
2560 face
= resolve_face_name (face
, 1);
2564 CHECK_LIVE_FRAME (frame
);
2565 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2568 lface
= lface_from_face_name (NULL
, face
, 0);
2574 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
2575 Sinternal_copy_lisp_face
, 4, 4, 0,
2576 doc
: /* Copy face FROM to TO.
2577 If FRAME is t, copy the global face definition of FROM.
2578 Otherwise, copy the frame-local definition of FROM on FRAME.
2579 If NEW-FRAME is a frame, copy that data into the frame-local
2580 definition of TO on NEW-FRAME. If NEW-FRAME is nil,
2581 FRAME controls where the data is copied to.
2583 The value is TO. */)
2584 (Lisp_Object from
, Lisp_Object to
, Lisp_Object frame
, Lisp_Object new_frame
)
2586 Lisp_Object lface
, copy
;
2588 CHECK_SYMBOL (from
);
2593 /* Copy global definition of FROM. We don't make copies of
2594 strings etc. because 20.2 didn't do it either. */
2595 lface
= lface_from_face_name (NULL
, from
, 1);
2596 copy
= Finternal_make_lisp_face (to
, Qnil
);
2600 /* Copy frame-local definition of FROM. */
2601 if (NILP (new_frame
))
2603 CHECK_LIVE_FRAME (frame
);
2604 CHECK_LIVE_FRAME (new_frame
);
2605 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
2606 copy
= Finternal_make_lisp_face (to
, new_frame
);
2609 vcopy (copy
, 0, XVECTOR (lface
)->contents
, LFACE_VECTOR_SIZE
);
2611 /* Changing a named face means that all realized faces depending on
2612 that face are invalid. Since we cannot tell which realized faces
2613 depend on the face, make sure they are all removed. This is done
2614 by incrementing face_change_count. The next call to
2615 init_iterator will then free realized faces. */
2616 if (NILP (Fget (to
, Qface_no_inherit
)))
2618 ++face_change_count
;
2619 windows_or_buffers_changed
= 55;
2626 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
2627 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
2628 doc
: /* Set attribute ATTR of FACE to VALUE.
2629 FRAME being a frame means change the face on that frame.
2630 FRAME nil means change the face of the selected frame.
2631 FRAME t means change the default for new frames.
2632 FRAME 0 means change the face on all frames, and change the default
2634 (Lisp_Object face
, Lisp_Object attr
, Lisp_Object value
, Lisp_Object frame
)
2637 Lisp_Object old_value
= Qnil
;
2638 /* Set one of enum font_property_index (> 0) if ATTR is one of
2639 font-related attributes other than QCfont and QCfontset. */
2640 enum font_property_index prop_index
= 0;
2642 CHECK_SYMBOL (face
);
2643 CHECK_SYMBOL (attr
);
2645 face
= resolve_face_name (face
, 1);
2647 /* If FRAME is 0, change face on all frames, and change the
2648 default for new frames. */
2649 if (INTEGERP (frame
) && XINT (frame
) == 0)
2652 Finternal_set_lisp_face_attribute (face
, attr
, value
, Qt
);
2653 FOR_EACH_FRAME (tail
, frame
)
2654 Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
2658 /* Set lface to the Lisp attribute vector of FACE. */
2661 lface
= lface_from_face_name (NULL
, face
, 1);
2663 /* When updating face-new-frame-defaults, we put :ignore-defface
2664 where the caller wants `unspecified'. This forces the frame
2665 defaults to ignore the defface value. Otherwise, the defface
2666 will take effect, which is generally not what is intended.
2667 The value of that attribute will be inherited from some other
2668 face during face merging. See internal_merge_in_global_face. */
2669 if (UNSPECIFIEDP (value
))
2670 value
= QCignore_defface
;
2675 frame
= selected_frame
;
2677 CHECK_LIVE_FRAME (frame
);
2678 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2680 /* If a frame-local face doesn't exist yet, create one. */
2682 lface
= Finternal_make_lisp_face (face
, frame
);
2685 if (EQ (attr
, QCfamily
))
2687 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2689 CHECK_STRING (value
);
2690 if (SCHARS (value
) == 0)
2691 signal_error ("Invalid face family", value
);
2693 old_value
= LFACE_FAMILY (lface
);
2694 ASET (lface
, LFACE_FAMILY_INDEX
, value
);
2695 prop_index
= FONT_FAMILY_INDEX
;
2697 else if (EQ (attr
, QCfoundry
))
2699 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2701 CHECK_STRING (value
);
2702 if (SCHARS (value
) == 0)
2703 signal_error ("Invalid face foundry", value
);
2705 old_value
= LFACE_FOUNDRY (lface
);
2706 ASET (lface
, LFACE_FOUNDRY_INDEX
, value
);
2707 prop_index
= FONT_FOUNDRY_INDEX
;
2709 else if (EQ (attr
, QCheight
))
2711 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2713 if (EQ (face
, Qdefault
))
2715 /* The default face must have an absolute size. */
2716 if (!INTEGERP (value
) || XINT (value
) <= 0)
2717 signal_error ("Default face height not absolute and positive",
2722 /* For non-default faces, do a test merge with a random
2723 height to see if VALUE's ok. */
2724 Lisp_Object test
= merge_face_heights (value
,
2727 if (!INTEGERP (test
) || XINT (test
) <= 0)
2728 signal_error ("Face height does not produce a positive integer",
2733 old_value
= LFACE_HEIGHT (lface
);
2734 ASET (lface
, LFACE_HEIGHT_INDEX
, value
);
2735 prop_index
= FONT_SIZE_INDEX
;
2737 else if (EQ (attr
, QCweight
))
2739 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2741 CHECK_SYMBOL (value
);
2742 if (FONT_WEIGHT_NAME_NUMERIC (value
) < 0)
2743 signal_error ("Invalid face weight", value
);
2745 old_value
= LFACE_WEIGHT (lface
);
2746 ASET (lface
, LFACE_WEIGHT_INDEX
, value
);
2747 prop_index
= FONT_WEIGHT_INDEX
;
2749 else if (EQ (attr
, QCslant
))
2751 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2753 CHECK_SYMBOL (value
);
2754 if (FONT_SLANT_NAME_NUMERIC (value
) < 0)
2755 signal_error ("Invalid face slant", value
);
2757 old_value
= LFACE_SLANT (lface
);
2758 ASET (lface
, LFACE_SLANT_INDEX
, value
);
2759 prop_index
= FONT_SLANT_INDEX
;
2761 else if (EQ (attr
, QCunderline
))
2765 if (UNSPECIFIEDP (value
) || IGNORE_DEFFACE_P (value
))
2767 else if (NILP (value
) || EQ (value
, Qt
))
2769 else if (STRINGP (value
) && SCHARS (value
) > 0)
2771 else if (CONSP (value
))
2773 Lisp_Object key
, val
, list
;
2776 /* FIXME? This errs on the side of acceptance. Eg it accepts:
2777 (defface foo '((t :underline 'foo) "doc")
2778 Maybe this is intentional, maybe it isn't.
2779 Non-nil symbols other than t are not documented as being valid.
2780 Eg compare with inverse-video, which explicitly rejects them.
2784 while (!NILP (CAR_SAFE(list
)))
2786 key
= CAR_SAFE (list
);
2787 list
= CDR_SAFE (list
);
2788 val
= CAR_SAFE (list
);
2789 list
= CDR_SAFE (list
);
2791 if (NILP (key
) || NILP (val
))
2797 else if (EQ (key
, QCcolor
)
2798 && !(EQ (val
, Qforeground_color
)
2799 || (STRINGP (val
) && SCHARS (val
) > 0)))
2805 else if (EQ (key
, QCstyle
)
2806 && !(EQ (val
, Qline
) || EQ (val
, Qwave
)))
2815 signal_error ("Invalid face underline", value
);
2817 old_value
= LFACE_UNDERLINE (lface
);
2818 ASET (lface
, LFACE_UNDERLINE_INDEX
, value
);
2820 else if (EQ (attr
, QCoverline
))
2822 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2823 if ((SYMBOLP (value
)
2825 && !EQ (value
, Qnil
))
2826 /* Overline color. */
2828 && SCHARS (value
) == 0))
2829 signal_error ("Invalid face overline", value
);
2831 old_value
= LFACE_OVERLINE (lface
);
2832 ASET (lface
, LFACE_OVERLINE_INDEX
, value
);
2834 else if (EQ (attr
, QCstrike_through
))
2836 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2837 if ((SYMBOLP (value
)
2839 && !EQ (value
, Qnil
))
2840 /* Strike-through color. */
2842 && SCHARS (value
) == 0))
2843 signal_error ("Invalid face strike-through", value
);
2845 old_value
= LFACE_STRIKE_THROUGH (lface
);
2846 ASET (lface
, LFACE_STRIKE_THROUGH_INDEX
, value
);
2848 else if (EQ (attr
, QCbox
))
2852 /* Allow t meaning a simple box of width 1 in foreground color
2855 value
= make_number (1);
2857 if (UNSPECIFIEDP (value
) || IGNORE_DEFFACE_P (value
))
2859 else if (NILP (value
))
2861 else if (INTEGERP (value
))
2862 valid_p
= XINT (value
) != 0;
2863 else if (STRINGP (value
))
2864 valid_p
= SCHARS (value
) > 0;
2865 else if (CONSP (value
))
2881 if (EQ (k
, QCline_width
))
2883 if (!INTEGERP (v
) || XINT (v
) == 0)
2886 else if (EQ (k
, QCcolor
))
2888 if (!NILP (v
) && (!STRINGP (v
) || SCHARS (v
) == 0))
2891 else if (EQ (k
, QCstyle
))
2893 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
2900 valid_p
= NILP (tem
);
2906 signal_error ("Invalid face box", value
);
2908 old_value
= LFACE_BOX (lface
);
2909 ASET (lface
, LFACE_BOX_INDEX
, value
);
2911 else if (EQ (attr
, QCinverse_video
)
2912 || EQ (attr
, QCreverse_video
))
2914 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2916 CHECK_SYMBOL (value
);
2917 if (!EQ (value
, Qt
) && !NILP (value
))
2918 signal_error ("Invalid inverse-video face attribute value", value
);
2920 old_value
= LFACE_INVERSE (lface
);
2921 ASET (lface
, LFACE_INVERSE_INDEX
, value
);
2923 else if (EQ (attr
, QCforeground
))
2925 /* Compatibility with 20.x. */
2927 value
= Qunspecified
;
2928 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2930 /* Don't check for valid color names here because it depends
2931 on the frame (display) whether the color will be valid
2932 when the face is realized. */
2933 CHECK_STRING (value
);
2934 if (SCHARS (value
) == 0)
2935 signal_error ("Empty foreground color value", value
);
2937 old_value
= LFACE_FOREGROUND (lface
);
2938 ASET (lface
, LFACE_FOREGROUND_INDEX
, value
);
2940 else if (EQ (attr
, QCdistant_foreground
))
2942 /* Compatibility with 20.x. */
2944 value
= Qunspecified
;
2945 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2947 /* Don't check for valid color names here because it depends
2948 on the frame (display) whether the color will be valid
2949 when the face is realized. */
2950 CHECK_STRING (value
);
2951 if (SCHARS (value
) == 0)
2952 signal_error ("Empty distant-foreground color value", value
);
2954 old_value
= LFACE_DISTANT_FOREGROUND (lface
);
2955 ASET (lface
, LFACE_DISTANT_FOREGROUND_INDEX
, value
);
2957 else if (EQ (attr
, QCbackground
))
2959 /* Compatibility with 20.x. */
2961 value
= Qunspecified
;
2962 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2964 /* Don't check for valid color names here because it depends
2965 on the frame (display) whether the color will be valid
2966 when the face is realized. */
2967 CHECK_STRING (value
);
2968 if (SCHARS (value
) == 0)
2969 signal_error ("Empty background color value", value
);
2971 old_value
= LFACE_BACKGROUND (lface
);
2972 ASET (lface
, LFACE_BACKGROUND_INDEX
, value
);
2974 else if (EQ (attr
, QCstipple
))
2976 #if defined (HAVE_WINDOW_SYSTEM)
2977 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
2979 && NILP (Fbitmap_spec_p (value
)))
2980 signal_error ("Invalid stipple attribute", value
);
2981 old_value
= LFACE_STIPPLE (lface
);
2982 ASET (lface
, LFACE_STIPPLE_INDEX
, value
);
2983 #endif /* HAVE_WINDOW_SYSTEM */
2985 else if (EQ (attr
, QCwidth
))
2987 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2989 CHECK_SYMBOL (value
);
2990 if (FONT_WIDTH_NAME_NUMERIC (value
) < 0)
2991 signal_error ("Invalid face width", value
);
2993 old_value
= LFACE_SWIDTH (lface
);
2994 ASET (lface
, LFACE_SWIDTH_INDEX
, value
);
2995 prop_index
= FONT_WIDTH_INDEX
;
2997 else if (EQ (attr
, QCfont
))
2999 #ifdef HAVE_WINDOW_SYSTEM
3000 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3002 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3006 old_value
= LFACE_FONT (lface
);
3007 if (! FONTP (value
))
3009 if (STRINGP (value
))
3011 Lisp_Object name
= value
;
3012 int fontset
= fs_query_fontset (name
, 0);
3015 name
= fontset_ascii (fontset
);
3016 value
= font_spec_from_name (name
);
3018 signal_error ("Invalid font name", name
);
3021 signal_error ("Invalid font or font-spec", value
);
3024 f
= XFRAME (selected_frame
);
3029 If frame is t, and selected frame is a tty frame, the font
3030 can't be realized. An improvement would be to loop over frames
3031 for a non-tty frame and use that. See discussion in Bug#18573.
3032 For a daemon, frame may be an initial frame (Bug#18869). */
3033 if (FRAME_WINDOW_P (f
))
3035 if (! FONT_OBJECT_P (value
))
3037 Lisp_Object
*attrs
= XVECTOR (lface
)->contents
;
3038 Lisp_Object font_object
;
3040 font_object
= font_load_for_lface (f
, attrs
, value
);
3041 if (NILP (font_object
))
3042 signal_error ("Font not available", value
);
3043 value
= font_object
;
3045 set_lface_from_font (f
, lface
, value
, 1);
3049 ASET (lface
, LFACE_FONT_INDEX
, value
);
3051 #endif /* HAVE_WINDOW_SYSTEM */
3053 else if (EQ (attr
, QCfontset
))
3055 #ifdef HAVE_WINDOW_SYSTEM
3056 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3060 old_value
= LFACE_FONTSET (lface
);
3061 tmp
= Fquery_fontset (value
, Qnil
);
3063 signal_error ("Invalid fontset name", value
);
3064 ASET (lface
, LFACE_FONTSET_INDEX
, value
= tmp
);
3066 #endif /* HAVE_WINDOW_SYSTEM */
3068 else if (EQ (attr
, QCinherit
))
3071 if (SYMBOLP (value
))
3074 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
3075 if (!SYMBOLP (XCAR (tail
)))
3078 ASET (lface
, LFACE_INHERIT_INDEX
, value
);
3080 signal_error ("Invalid face inheritance", value
);
3082 else if (EQ (attr
, QCbold
))
3084 old_value
= LFACE_WEIGHT (lface
);
3085 ASET (lface
, LFACE_WEIGHT_INDEX
, NILP (value
) ? Qnormal
: Qbold
);
3086 prop_index
= FONT_WEIGHT_INDEX
;
3088 else if (EQ (attr
, QCitalic
))
3091 old_value
= LFACE_SLANT (lface
);
3092 ASET (lface
, LFACE_SLANT_INDEX
, NILP (value
) ? Qnormal
: Qitalic
);
3093 prop_index
= FONT_SLANT_INDEX
;
3096 signal_error ("Invalid face attribute name", attr
);
3100 /* If a font-related attribute other than QCfont and QCfontset
3101 is specified, and if the original QCfont attribute has a font
3102 (font-spec or font-object), set the corresponding property in
3103 the font to nil so that the font selector doesn't think that
3104 the attribute is mandatory. Also, clear the average
3106 font_clear_prop (XVECTOR (lface
)->contents
, prop_index
);
3109 /* Changing a named face means that all realized faces depending on
3110 that face are invalid. Since we cannot tell which realized faces
3111 depend on the face, make sure they are all removed. This is done
3112 by incrementing face_change_count. The next call to
3113 init_iterator will then free realized faces. */
3115 && NILP (Fget (face
, Qface_no_inherit
))
3116 && NILP (Fequal (old_value
, value
)))
3118 ++face_change_count
;
3119 windows_or_buffers_changed
= 56;
3122 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3123 && NILP (Fequal (old_value
, value
)))
3129 if (EQ (face
, Qdefault
))
3131 #ifdef HAVE_WINDOW_SYSTEM
3132 /* Changed font-related attributes of the `default' face are
3133 reflected in changed `font' frame parameters. */
3135 && (prop_index
|| EQ (attr
, QCfont
))
3136 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
3137 set_font_frame_param (frame
, lface
);
3139 #endif /* HAVE_WINDOW_SYSTEM */
3141 if (EQ (attr
, QCforeground
))
3142 param
= Qforeground_color
;
3143 else if (EQ (attr
, QCbackground
))
3144 param
= Qbackground_color
;
3146 #ifdef HAVE_WINDOW_SYSTEM
3148 else if (EQ (face
, Qscroll_bar
))
3150 /* Changing the colors of `scroll-bar' sets frame parameters
3151 `scroll-bar-foreground' and `scroll-bar-background'. */
3152 if (EQ (attr
, QCforeground
))
3153 param
= Qscroll_bar_foreground
;
3154 else if (EQ (attr
, QCbackground
))
3155 param
= Qscroll_bar_background
;
3157 #endif /* not HAVE_NTGUI */
3158 else if (EQ (face
, Qborder
))
3160 /* Changing background color of `border' sets frame parameter
3162 if (EQ (attr
, QCbackground
))
3163 param
= Qborder_color
;
3165 else if (EQ (face
, Qcursor
))
3167 /* Changing background color of `cursor' sets frame parameter
3169 if (EQ (attr
, QCbackground
))
3170 param
= Qcursor_color
;
3172 else if (EQ (face
, Qmouse
))
3174 /* Changing background color of `mouse' sets frame parameter
3176 if (EQ (attr
, QCbackground
))
3177 param
= Qmouse_color
;
3179 #endif /* HAVE_WINDOW_SYSTEM */
3180 else if (EQ (face
, Qmenu
))
3182 /* Indicate that we have to update the menu bar when realizing
3183 faces on FRAME. FRAME t change the default for new frames.
3184 We do this by setting the flag in new face caches. */
3187 struct frame
*f
= XFRAME (frame
);
3188 if (FRAME_FACE_CACHE (f
) == NULL
)
3189 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
3190 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 1;
3193 menu_face_changed_default
= 1;
3199 /* Update `default-frame-alist', which is used for new frames. */
3201 store_in_alist (&Vdefault_frame_alist
, param
, value
);
3204 /* Update the current frame's parameters. */
3207 cons
= XCAR (Vparam_value_alist
);
3208 XSETCAR (cons
, param
);
3209 XSETCDR (cons
, value
);
3210 Fmodify_frame_parameters (frame
, Vparam_value_alist
);
3219 /* Update the corresponding face when frame parameter PARAM on frame F
3220 has been assigned the value NEW_VALUE. */
3223 update_face_from_frame_parameter (struct frame
*f
, Lisp_Object param
,
3224 Lisp_Object new_value
)
3226 Lisp_Object face
= Qnil
;
3229 /* If there are no faces yet, give up. This is the case when called
3230 from Fx_create_frame, and we do the necessary things later in
3231 face-set-after-frame-defaults. */
3232 if (NILP (f
->face_alist
))
3235 if (EQ (param
, Qforeground_color
))
3238 lface
= lface_from_face_name (f
, face
, 1);
3239 ASET (lface
, LFACE_FOREGROUND_INDEX
,
3240 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3241 realize_basic_faces (f
);
3243 else if (EQ (param
, Qbackground_color
))
3247 /* Changing the background color might change the background
3248 mode, so that we have to load new defface specs.
3249 Call frame-set-background-mode to do that. */
3250 XSETFRAME (frame
, f
);
3251 call1 (Qframe_set_background_mode
, frame
);
3254 lface
= lface_from_face_name (f
, face
, 1);
3255 ASET (lface
, LFACE_BACKGROUND_INDEX
,
3256 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3257 realize_basic_faces (f
);
3259 #ifdef HAVE_WINDOW_SYSTEM
3260 else if (EQ (param
, Qborder_color
))
3263 lface
= lface_from_face_name (f
, face
, 1);
3264 ASET (lface
, LFACE_BACKGROUND_INDEX
,
3265 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3267 else if (EQ (param
, Qcursor_color
))
3270 lface
= lface_from_face_name (f
, face
, 1);
3271 ASET (lface
, LFACE_BACKGROUND_INDEX
,
3272 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3274 else if (EQ (param
, Qmouse_color
))
3277 lface
= lface_from_face_name (f
, face
, 1);
3278 ASET (lface
, LFACE_BACKGROUND_INDEX
,
3279 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3283 /* Changing a named face means that all realized faces depending on
3284 that face are invalid. Since we cannot tell which realized faces
3285 depend on the face, make sure they are all removed. This is done
3286 by incrementing face_change_count. The next call to
3287 init_iterator will then free realized faces. */
3289 && NILP (Fget (face
, Qface_no_inherit
)))
3291 ++face_change_count
;
3292 windows_or_buffers_changed
= 57;
3297 #ifdef HAVE_WINDOW_SYSTEM
3299 /* Set the `font' frame parameter of FRAME determined from the
3300 font-object set in `default' face attributes LFACE. */
3303 set_font_frame_param (Lisp_Object frame
, Lisp_Object lface
)
3305 struct frame
*f
= XFRAME (frame
);
3308 if (FRAME_WINDOW_P (f
)
3309 /* Don't do anything if the font is `unspecified'. This can
3310 happen during frame creation. */
3311 && (font
= LFACE_FONT (lface
),
3312 ! UNSPECIFIEDP (font
)))
3314 if (FONT_SPEC_P (font
))
3316 font
= font_load_for_lface (f
, XVECTOR (lface
)->contents
, font
);
3319 ASET (lface
, LFACE_FONT_INDEX
, font
);
3321 f
->default_face_done_p
= 0;
3322 AUTO_FRAME_ARG (arg
, Qfont
, font
);
3323 Fmodify_frame_parameters (frame
, arg
);
3327 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
3328 Sinternal_face_x_get_resource
, 2, 3, 0,
3329 doc
: /* Get the value of X resource RESOURCE, class CLASS.
3330 Returned value is for the display of frame FRAME. If FRAME is not
3331 specified or nil, use selected frame. This function exists because
3332 ordinary `x-get-resource' doesn't take a frame argument. */)
3333 (Lisp_Object resource
, Lisp_Object
class, Lisp_Object frame
)
3335 Lisp_Object value
= Qnil
;
3338 CHECK_STRING (resource
);
3339 CHECK_STRING (class);
3340 f
= decode_live_frame (frame
);
3342 value
= display_x_get_resource (FRAME_DISPLAY_INFO (f
),
3343 resource
, class, Qnil
, Qnil
);
3349 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
3350 If VALUE is "on" or "true", return t. If VALUE is "off" or
3351 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
3352 error; if SIGNAL_P is zero, return 0. */
3355 face_boolean_x_resource_value (Lisp_Object value
, int signal_p
)
3357 Lisp_Object result
= make_number (0);
3359 eassert (STRINGP (value
));
3361 if (xstrcasecmp (SSDATA (value
), "on") == 0
3362 || xstrcasecmp (SSDATA (value
), "true") == 0)
3364 else if (xstrcasecmp (SSDATA (value
), "off") == 0
3365 || xstrcasecmp (SSDATA (value
), "false") == 0)
3367 else if (xstrcasecmp (SSDATA (value
), "unspecified") == 0)
3368 result
= Qunspecified
;
3370 signal_error ("Invalid face attribute value from X resource", value
);
3376 DEFUN ("internal-set-lisp-face-attribute-from-resource",
3377 Finternal_set_lisp_face_attribute_from_resource
,
3378 Sinternal_set_lisp_face_attribute_from_resource
,
3379 3, 4, 0, doc
: /* */)
3380 (Lisp_Object face
, Lisp_Object attr
, Lisp_Object value
, Lisp_Object frame
)
3382 CHECK_SYMBOL (face
);
3383 CHECK_SYMBOL (attr
);
3384 CHECK_STRING (value
);
3386 if (xstrcasecmp (SSDATA (value
), "unspecified") == 0)
3387 value
= Qunspecified
;
3388 else if (EQ (attr
, QCheight
))
3390 value
= Fstring_to_number (value
, make_number (10));
3391 if (XINT (value
) <= 0)
3392 signal_error ("Invalid face height from X resource", value
);
3394 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
3395 value
= face_boolean_x_resource_value (value
, 1);
3396 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
3397 value
= intern (SSDATA (value
));
3398 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
3399 value
= face_boolean_x_resource_value (value
, 1);
3400 else if (EQ (attr
, QCunderline
)
3401 || EQ (attr
, QCoverline
)
3402 || EQ (attr
, QCstrike_through
))
3404 Lisp_Object boolean_value
;
3406 /* If the result of face_boolean_x_resource_value is t or nil,
3407 VALUE does NOT specify a color. */
3408 boolean_value
= face_boolean_x_resource_value (value
, 0);
3409 if (SYMBOLP (boolean_value
))
3410 value
= boolean_value
;
3412 else if (EQ (attr
, QCbox
) || EQ (attr
, QCinherit
))
3413 value
= Fcar (Fread_from_string (value
, Qnil
, Qnil
));
3415 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3418 #endif /* HAVE_WINDOW_SYSTEM */
3421 /***********************************************************************
3423 ***********************************************************************/
3425 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
3427 /* Make menus on frame F appear as specified by the `menu' face. */
3430 x_update_menu_appearance (struct frame
*f
)
3432 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
3436 && (rdb
= XrmGetDatabase (FRAME_X_DISPLAY (f
)),
3441 ptrdiff_t bufsize
= sizeof line
;
3442 Lisp_Object lface
= lface_from_face_name (f
, Qmenu
, 1);
3443 struct face
*face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
3444 const char *myname
= SSDATA (Vx_resource_name
);
3447 const char *popup_path
= "popup_menu";
3449 const char *popup_path
= "menu.popup";
3452 if (STRINGP (LFACE_FOREGROUND (lface
)))
3454 exprintf (&buf
, &bufsize
, line
, -1, "%s.%s*foreground: %s",
3456 SDATA (LFACE_FOREGROUND (lface
)));
3457 XrmPutLineResource (&rdb
, line
);
3458 exprintf (&buf
, &bufsize
, line
, -1, "%s.pane.menubar*foreground: %s",
3459 myname
, SDATA (LFACE_FOREGROUND (lface
)));
3460 XrmPutLineResource (&rdb
, line
);
3464 if (STRINGP (LFACE_BACKGROUND (lface
)))
3466 exprintf (&buf
, &bufsize
, line
, -1, "%s.%s*background: %s",
3468 SDATA (LFACE_BACKGROUND (lface
)));
3469 XrmPutLineResource (&rdb
, line
);
3471 exprintf (&buf
, &bufsize
, line
, -1, "%s.pane.menubar*background: %s",
3472 myname
, SDATA (LFACE_BACKGROUND (lface
)));
3473 XrmPutLineResource (&rdb
, line
);
3478 /* On Solaris 5.8, it's been reported that the `menu' face
3479 can be unspecified here, during startup. Why this
3480 happens remains unknown. -- cyd */
3481 && FONTP (LFACE_FONT (lface
))
3482 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
3483 || !UNSPECIFIEDP (LFACE_FOUNDRY (lface
))
3484 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
3485 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3486 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
3487 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
3489 Lisp_Object xlfd
= Ffont_xlfd_name (LFACE_FONT (lface
), Qnil
);
3491 const char *suffix
= "List";
3494 #if defined HAVE_X_I18N
3496 const char *suffix
= "Set";
3498 const char *suffix
= "";
3505 #if defined HAVE_X_I18N
3506 char *fontsetname
= xic_create_fontsetname (SSDATA (xlfd
), motif
);
3508 char *fontsetname
= SSDATA (xlfd
);
3510 exprintf (&buf
, &bufsize
, line
, -1, "%s.pane.menubar*font%s: %s",
3511 myname
, suffix
, fontsetname
);
3512 XrmPutLineResource (&rdb
, line
);
3514 exprintf (&buf
, &bufsize
, line
, -1, "%s.%s*font%s: %s",
3515 myname
, popup_path
, suffix
, fontsetname
);
3516 XrmPutLineResource (&rdb
, line
);
3518 if (fontsetname
!= SSDATA (xlfd
))
3519 xfree (fontsetname
);
3523 if (changed_p
&& f
->output_data
.x
->menubar_widget
)
3524 free_frame_menubar (f
);
3531 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
3534 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p
,
3535 Sface_attribute_relative_p
,
3537 doc
: /* Check whether a face attribute value is relative.
3538 Specifically, this function returns t if the attribute ATTRIBUTE
3539 with the value VALUE is relative.
3541 A relative value is one that doesn't entirely override whatever is
3542 inherited from another face. For most possible attributes,
3543 the only relative value that users see is `unspecified'.
3544 However, for :height, floating point values are also relative. */
3546 (Lisp_Object attribute
, Lisp_Object value
)
3548 if (EQ (value
, Qunspecified
) || (EQ (value
, QCignore_defface
)))
3550 else if (EQ (attribute
, QCheight
))
3551 return INTEGERP (value
) ? Qnil
: Qt
;
3556 DEFUN ("merge-face-attribute", Fmerge_face_attribute
, Smerge_face_attribute
,
3558 doc
: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
3559 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
3560 the result will be absolute, otherwise it will be relative. */)
3561 (Lisp_Object attribute
, Lisp_Object value1
, Lisp_Object value2
)
3563 if (EQ (value1
, Qunspecified
) || EQ (value1
, QCignore_defface
))
3565 else if (EQ (attribute
, QCheight
))
3566 return merge_face_heights (value1
, value2
, value1
);
3572 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
3573 Sinternal_get_lisp_face_attribute
,
3575 doc
: /* Return face attribute KEYWORD of face SYMBOL.
3576 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
3577 face attribute name, signal an error.
3578 If the optional argument FRAME is given, report on face SYMBOL in that
3579 frame. If FRAME is t, report on the defaults for face SYMBOL (for new
3580 frames). If FRAME is omitted or nil, use the selected frame. */)
3581 (Lisp_Object symbol
, Lisp_Object keyword
, Lisp_Object frame
)
3583 struct frame
*f
= EQ (frame
, Qt
) ? NULL
: decode_live_frame (frame
);
3584 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 1), value
= Qnil
;
3586 CHECK_SYMBOL (symbol
);
3587 CHECK_SYMBOL (keyword
);
3589 if (EQ (keyword
, QCfamily
))
3590 value
= LFACE_FAMILY (lface
);
3591 else if (EQ (keyword
, QCfoundry
))
3592 value
= LFACE_FOUNDRY (lface
);
3593 else if (EQ (keyword
, QCheight
))
3594 value
= LFACE_HEIGHT (lface
);
3595 else if (EQ (keyword
, QCweight
))
3596 value
= LFACE_WEIGHT (lface
);
3597 else if (EQ (keyword
, QCslant
))
3598 value
= LFACE_SLANT (lface
);
3599 else if (EQ (keyword
, QCunderline
))
3600 value
= LFACE_UNDERLINE (lface
);
3601 else if (EQ (keyword
, QCoverline
))
3602 value
= LFACE_OVERLINE (lface
);
3603 else if (EQ (keyword
, QCstrike_through
))
3604 value
= LFACE_STRIKE_THROUGH (lface
);
3605 else if (EQ (keyword
, QCbox
))
3606 value
= LFACE_BOX (lface
);
3607 else if (EQ (keyword
, QCinverse_video
)
3608 || EQ (keyword
, QCreverse_video
))
3609 value
= LFACE_INVERSE (lface
);
3610 else if (EQ (keyword
, QCforeground
))
3611 value
= LFACE_FOREGROUND (lface
);
3612 else if (EQ (keyword
, QCdistant_foreground
))
3613 value
= LFACE_DISTANT_FOREGROUND (lface
);
3614 else if (EQ (keyword
, QCbackground
))
3615 value
= LFACE_BACKGROUND (lface
);
3616 else if (EQ (keyword
, QCstipple
))
3617 value
= LFACE_STIPPLE (lface
);
3618 else if (EQ (keyword
, QCwidth
))
3619 value
= LFACE_SWIDTH (lface
);
3620 else if (EQ (keyword
, QCinherit
))
3621 value
= LFACE_INHERIT (lface
);
3622 else if (EQ (keyword
, QCfont
))
3623 value
= LFACE_FONT (lface
);
3624 else if (EQ (keyword
, QCfontset
))
3625 value
= LFACE_FONTSET (lface
);
3627 signal_error ("Invalid face attribute name", keyword
);
3629 if (IGNORE_DEFFACE_P (value
))
3630 return Qunspecified
;
3636 DEFUN ("internal-lisp-face-attribute-values",
3637 Finternal_lisp_face_attribute_values
,
3638 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
3639 doc
: /* Return a list of valid discrete values for face attribute ATTR.
3640 Value is nil if ATTR doesn't have a discrete set of valid values. */)
3643 Lisp_Object result
= Qnil
;
3645 CHECK_SYMBOL (attr
);
3647 if (EQ (attr
, QCunderline
) || EQ (attr
, QCoverline
)
3648 || EQ (attr
, QCstrike_through
)
3649 || EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
3650 result
= list2 (Qt
, Qnil
);
3656 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
3657 Sinternal_merge_in_global_face
, 2, 2, 0,
3658 doc
: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
3659 Default face attributes override any local face attributes. */)
3660 (Lisp_Object face
, Lisp_Object frame
)
3663 Lisp_Object global_lface
, local_lface
, *gvec
, *lvec
;
3664 struct frame
*f
= XFRAME (frame
);
3666 CHECK_LIVE_FRAME (frame
);
3667 global_lface
= lface_from_face_name (NULL
, face
, 1);
3668 local_lface
= lface_from_face_name (f
, face
, 0);
3669 if (NILP (local_lface
))
3670 local_lface
= Finternal_make_lisp_face (face
, frame
);
3672 /* Make every specified global attribute override the local one.
3673 BEWARE!! This is only used from `face-set-after-frame-default' where
3674 the local frame is defined from default specs in `face-defface-spec'
3675 and those should be overridden by global settings. Hence the strange
3676 "global before local" priority. */
3677 lvec
= XVECTOR (local_lface
)->contents
;
3678 gvec
= XVECTOR (global_lface
)->contents
;
3679 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3680 if (IGNORE_DEFFACE_P (gvec
[i
]))
3681 ASET (local_lface
, i
, Qunspecified
);
3682 else if (! UNSPECIFIEDP (gvec
[i
]))
3683 ASET (local_lface
, i
, AREF (global_lface
, i
));
3685 /* If the default face was changed, update the face cache and the
3686 `font' frame parameter. */
3687 if (EQ (face
, Qdefault
))
3689 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
3690 struct face
*newface
, *oldface
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
3691 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
3693 /* This can be NULL (e.g., in batch mode). */
3696 /* Ensure that the face vector is fully specified by merging
3697 the previously-cached vector. */
3698 memcpy (attrs
, oldface
->lface
, sizeof attrs
);
3699 merge_face_vectors (f
, lvec
, attrs
, 0);
3700 vcopy (local_lface
, 0, attrs
, LFACE_VECTOR_SIZE
);
3701 newface
= realize_face (c
, lvec
, DEFAULT_FACE_ID
);
3703 if ((! UNSPECIFIEDP (gvec
[LFACE_FAMILY_INDEX
])
3704 || ! UNSPECIFIEDP (gvec
[LFACE_FOUNDRY_INDEX
])
3705 || ! UNSPECIFIEDP (gvec
[LFACE_HEIGHT_INDEX
])
3706 || ! UNSPECIFIEDP (gvec
[LFACE_WEIGHT_INDEX
])
3707 || ! UNSPECIFIEDP (gvec
[LFACE_SLANT_INDEX
])
3708 || ! UNSPECIFIEDP (gvec
[LFACE_SWIDTH_INDEX
])
3709 || ! UNSPECIFIEDP (gvec
[LFACE_FONT_INDEX
]))
3712 Lisp_Object name
= newface
->font
->props
[FONT_NAME_INDEX
];
3713 AUTO_FRAME_ARG (arg
, Qfont
, name
);
3714 Fmodify_frame_parameters (frame
, arg
);
3717 if (STRINGP (gvec
[LFACE_FOREGROUND_INDEX
]))
3719 AUTO_FRAME_ARG (arg
, Qforeground_color
,
3720 gvec
[LFACE_FOREGROUND_INDEX
]);
3721 Fmodify_frame_parameters (frame
, arg
);
3724 if (STRINGP (gvec
[LFACE_BACKGROUND_INDEX
]))
3726 AUTO_FRAME_ARG (arg
, Qbackground_color
,
3727 gvec
[LFACE_BACKGROUND_INDEX
]);
3728 Fmodify_frame_parameters (frame
, arg
);
3737 /* The following function is implemented for compatibility with 20.2.
3738 The function is used in x-resolve-fonts when it is asked to
3739 return fonts with the same size as the font of a face. This is
3740 done in fontset.el. */
3742 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 3, 0,
3743 doc
: /* Return the font name of face FACE, or nil if it is unspecified.
3744 The font name is, by default, for ASCII characters.
3745 If the optional argument FRAME is given, report on face FACE in that frame.
3746 If FRAME is t, report on the defaults for face FACE (for new frames).
3747 The font default for a face is either nil, or a list
3748 of the form (bold), (italic) or (bold italic).
3749 If FRAME is omitted or nil, use the selected frame. And, in this case,
3750 if the optional third argument CHARACTER is given,
3751 return the font name used for CHARACTER. */)
3752 (Lisp_Object face
, Lisp_Object frame
, Lisp_Object character
)
3756 Lisp_Object result
= Qnil
;
3757 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
3759 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3760 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
3761 result
= Fcons (Qbold
, result
);
3763 if (!UNSPECIFIEDP (LFACE_SLANT (lface
))
3764 && !EQ (LFACE_SLANT (lface
), Qnormal
))
3765 result
= Fcons (Qitalic
, result
);
3771 struct frame
*f
= decode_live_frame (frame
);
3772 int face_id
= lookup_named_face (f
, face
, 1);
3773 struct face
*fface
= FACE_FROM_ID (f
, face_id
);
3777 #ifdef HAVE_WINDOW_SYSTEM
3778 if (FRAME_WINDOW_P (f
) && !NILP (character
))
3780 CHECK_CHARACTER (character
);
3781 face_id
= FACE_FOR_CHAR (f
, fface
, XINT (character
), -1, Qnil
);
3782 fface
= FACE_FROM_ID (f
, face_id
);
3785 ? fface
->font
->props
[FONT_NAME_INDEX
]
3787 #else /* !HAVE_WINDOW_SYSTEM */
3788 return build_string (FRAME_MSDOS_P (f
)
3790 : FRAME_W32_P (f
) ? "w32term"
3797 /* Compare face-attribute values v1 and v2 for equality. Value is non-zero if
3798 all attributes are `equal'. Tries to be fast because this function
3799 is called quite often. */
3802 face_attr_equal_p (Lisp_Object v1
, Lisp_Object v2
)
3804 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
3805 and the other is specified. */
3806 if (XTYPE (v1
) != XTYPE (v2
))
3815 if (SBYTES (v1
) != SBYTES (v2
))
3818 return memcmp (SDATA (v1
), SDATA (v2
), SBYTES (v1
)) == 0;
3825 return !NILP (Fequal (v1
, v2
));
3830 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
3831 all attributes are `equal'. Tries to be fast because this function
3832 is called quite often. */
3835 lface_equal_p (Lisp_Object
*v1
, Lisp_Object
*v2
)
3840 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
3841 equal_p
= face_attr_equal_p (v1
[i
], v2
[i
]);
3847 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
3848 Sinternal_lisp_face_equal_p
, 2, 3, 0,
3849 doc
: /* True if FACE1 and FACE2 are equal.
3850 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
3851 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
3852 If FRAME is omitted or nil, use the selected frame. */)
3853 (Lisp_Object face1
, Lisp_Object face2
, Lisp_Object frame
)
3857 Lisp_Object lface1
, lface2
;
3859 /* Don't use decode_window_system_frame here because this function
3860 is called before X frames exist. At that time, if FRAME is nil,
3861 selected_frame will be used which is the frame dumped with
3862 Emacs. That frame is not an X frame. */
3863 f
= EQ (frame
, Qt
) ? NULL
: decode_live_frame (frame
);
3865 lface1
= lface_from_face_name (f
, face1
, 1);
3866 lface2
= lface_from_face_name (f
, face2
, 1);
3867 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
3868 XVECTOR (lface2
)->contents
);
3869 return equal_p
? Qt
: Qnil
;
3873 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
3874 Sinternal_lisp_face_empty_p
, 1, 2, 0,
3875 doc
: /* True if FACE has no attribute specified.
3876 If the optional argument FRAME is given, report on face FACE in that frame.
3877 If FRAME is t, report on the defaults for face FACE (for new frames).
3878 If FRAME is omitted or nil, use the selected frame. */)
3879 (Lisp_Object face
, Lisp_Object frame
)
3881 struct frame
*f
= EQ (frame
, Qt
) ? NULL
: decode_live_frame (frame
);
3882 Lisp_Object lface
= lface_from_face_name (f
, face
, 1);
3885 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3886 if (!UNSPECIFIEDP (AREF (lface
, i
)))
3889 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
3893 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
3895 doc
: /* Return an alist of frame-local faces defined on FRAME.
3896 For internal use only. */)
3899 return decode_live_frame (frame
)->face_alist
;
3903 /* Return a hash code for Lisp string STRING with case ignored. Used
3904 below in computing a hash value for a Lisp face. */
3907 hash_string_case_insensitive (Lisp_Object string
)
3909 const unsigned char *s
;
3911 eassert (STRINGP (string
));
3912 for (s
= SDATA (string
); *s
; ++s
)
3913 hash
= (hash
<< 1) ^ c_tolower (*s
);
3918 /* Return a hash code for face attribute vector V. */
3921 lface_hash (Lisp_Object
*v
)
3923 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
3924 ^ hash_string_case_insensitive (v
[LFACE_FOUNDRY_INDEX
])
3925 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
3926 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
3927 ^ XHASH (v
[LFACE_WEIGHT_INDEX
])
3928 ^ XHASH (v
[LFACE_SLANT_INDEX
])
3929 ^ XHASH (v
[LFACE_SWIDTH_INDEX
])
3930 ^ XHASH (v
[LFACE_HEIGHT_INDEX
]));
3933 #ifdef HAVE_WINDOW_SYSTEM
3935 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
3936 considering charsets/registries). They do if they specify the same
3937 family, point size, weight, width, slant, and font. Both
3938 LFACE1 and LFACE2 must be fully-specified. */
3941 lface_same_font_attributes_p (Lisp_Object
*lface1
, Lisp_Object
*lface2
)
3943 eassert (lface_fully_specified_p (lface1
)
3944 && lface_fully_specified_p (lface2
));
3945 return (xstrcasecmp (SSDATA (lface1
[LFACE_FAMILY_INDEX
]),
3946 SSDATA (lface2
[LFACE_FAMILY_INDEX
])) == 0
3947 && xstrcasecmp (SSDATA (lface1
[LFACE_FOUNDRY_INDEX
]),
3948 SSDATA (lface2
[LFACE_FOUNDRY_INDEX
])) == 0
3949 && EQ (lface1
[LFACE_HEIGHT_INDEX
], lface2
[LFACE_HEIGHT_INDEX
])
3950 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
3951 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
3952 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
])
3953 && EQ (lface1
[LFACE_FONT_INDEX
], lface2
[LFACE_FONT_INDEX
])
3954 && (EQ (lface1
[LFACE_FONTSET_INDEX
], lface2
[LFACE_FONTSET_INDEX
])
3955 || (STRINGP (lface1
[LFACE_FONTSET_INDEX
])
3956 && STRINGP (lface2
[LFACE_FONTSET_INDEX
])
3957 && ! xstrcasecmp (SSDATA (lface1
[LFACE_FONTSET_INDEX
]),
3958 SSDATA (lface2
[LFACE_FONTSET_INDEX
]))))
3962 #endif /* HAVE_WINDOW_SYSTEM */
3964 /***********************************************************************
3966 ***********************************************************************/
3968 /* Allocate and return a new realized face for Lisp face attribute
3971 static struct face
*
3972 make_realized_face (Lisp_Object
*attr
)
3974 enum { off
= offsetof (struct face
, id
) };
3975 struct face
*face
= xmalloc (sizeof *face
);
3977 memcpy (face
->lface
, attr
, sizeof face
->lface
);
3978 memset (&face
->id
, 0, sizeof *face
- off
);
3979 face
->ascii_face
= face
;
3985 /* Free realized face FACE, including its X resources. FACE may
3989 free_realized_face (struct frame
*f
, struct face
*face
)
3993 #ifdef HAVE_WINDOW_SYSTEM
3994 if (FRAME_WINDOW_P (f
))
3996 /* Free fontset of FACE if it is ASCII face. */
3997 if (face
->fontset
>= 0 && face
== face
->ascii_face
)
3998 free_face_fontset (f
, face
);
4003 font_done_for_face (f
, face
);
4004 x_free_gc (f
, face
->gc
);
4008 #ifdef HAVE_X_WINDOWS
4009 free_face_colors (f
, face
);
4010 #endif /* HAVE_X_WINDOWS */
4011 x_destroy_bitmap (f
, face
->stipple
);
4013 #endif /* HAVE_WINDOW_SYSTEM */
4019 #ifdef HAVE_WINDOW_SYSTEM
4021 /* Prepare face FACE for subsequent display on frame F. This must be called
4022 before using X resources of FACE to allocate GCs if they haven't been
4023 allocated yet or have been freed by clearing the face cache. */
4026 prepare_face_for_display (struct frame
*f
, struct face
*face
)
4028 eassert (FRAME_WINDOW_P (f
));
4033 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
4035 xgcv
.foreground
= face
->foreground
;
4036 xgcv
.background
= face
->background
;
4037 #ifdef HAVE_X_WINDOWS
4038 xgcv
.graphics_exposures
= False
;
4042 #ifdef HAVE_X_WINDOWS
4045 xgcv
.fill_style
= FillOpaqueStippled
;
4046 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
4047 mask
|= GCFillStyle
| GCStipple
;
4050 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
4052 font_prepare_for_face (f
, face
);
4057 #endif /* HAVE_WINDOW_SYSTEM */
4059 /* Returns the `distance' between the colors X and Y. */
4062 color_distance (XColor
*x
, XColor
*y
)
4064 /* This formula is from a paper titled `Colour metric' by Thiadmer Riemersma.
4065 Quoting from that paper:
4067 This formula has results that are very close to L*u*v* (with the
4068 modified lightness curve) and, more importantly, it is a more even
4069 algorithm: it does not have a range of colors where it suddenly
4070 gives far from optimal results.
4072 See <http://www.compuphase.com/cmetric.htm> for more info. */
4074 long r
= (x
->red
- y
->red
) >> 8;
4075 long g
= (x
->green
- y
->green
) >> 8;
4076 long b
= (x
->blue
- y
->blue
) >> 8;
4077 long r_mean
= (x
->red
+ y
->red
) >> 9;
4080 (((512 + r_mean
) * r
* r
) >> 8)
4082 + (((767 - r_mean
) * b
* b
) >> 8);
4086 DEFUN ("color-distance", Fcolor_distance
, Scolor_distance
, 2, 3, 0,
4087 doc
: /* Return an integer distance between COLOR1 and COLOR2 on FRAME.
4088 COLOR1 and COLOR2 may be either strings containing the color name,
4089 or lists of the form (RED GREEN BLUE).
4090 If FRAME is unspecified or nil, the current frame is used. */)
4091 (Lisp_Object color1
, Lisp_Object color2
, Lisp_Object frame
)
4093 struct frame
*f
= decode_live_frame (frame
);
4094 XColor cdef1
, cdef2
;
4096 if (!(CONSP (color1
) && parse_rgb_list (color1
, &cdef1
))
4097 && !(STRINGP (color1
) && defined_color (f
, SSDATA (color1
), &cdef1
, 0)))
4098 signal_error ("Invalid color", color1
);
4099 if (!(CONSP (color2
) && parse_rgb_list (color2
, &cdef2
))
4100 && !(STRINGP (color2
) && defined_color (f
, SSDATA (color2
), &cdef2
, 0)))
4101 signal_error ("Invalid color", color2
);
4103 return make_number (color_distance (&cdef1
, &cdef2
));
4107 /***********************************************************************
4109 ***********************************************************************/
4111 /* Return a new face cache for frame F. */
4113 static struct face_cache
*
4114 make_face_cache (struct frame
*f
)
4116 struct face_cache
*c
= xmalloc (sizeof *c
);
4118 c
->buckets
= xzalloc (FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
);
4121 c
->faces_by_id
= xmalloc (c
->size
* sizeof *c
->faces_by_id
);
4123 c
->menu_face_changed_p
= menu_face_changed_default
;
4127 #ifdef HAVE_WINDOW_SYSTEM
4129 /* Clear out all graphics contexts for all realized faces, except for
4130 the basic faces. This should be done from time to time just to avoid
4131 keeping too many graphics contexts that are no longer needed. */
4134 clear_face_gcs (struct face_cache
*c
)
4136 if (c
&& FRAME_WINDOW_P (c
->f
))
4139 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
4141 struct face
*face
= c
->faces_by_id
[i
];
4142 if (face
&& face
->gc
)
4146 font_done_for_face (c
->f
, face
);
4147 x_free_gc (c
->f
, face
->gc
);
4155 #endif /* HAVE_WINDOW_SYSTEM */
4157 /* Free all realized faces in face cache C, including basic faces.
4158 C may be null. If faces are freed, make sure the frame's current
4159 matrix is marked invalid, so that a display caused by an expose
4160 event doesn't try to use faces we destroyed. */
4163 free_realized_faces (struct face_cache
*c
)
4168 struct frame
*f
= c
->f
;
4170 /* We must block input here because we can't process X events
4171 safely while only some faces are freed, or when the frame's
4172 current matrix still references freed faces. */
4175 for (i
= 0; i
< c
->used
; ++i
)
4177 free_realized_face (f
, c
->faces_by_id
[i
]);
4178 c
->faces_by_id
[i
] = NULL
;
4182 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4183 memset (c
->buckets
, 0, size
);
4185 /* Must do a thorough redisplay the next time. Mark current
4186 matrices as invalid because they will reference faces freed
4187 above. This function is also called when a frame is
4188 destroyed. In this case, the root window of F is nil. */
4189 if (WINDOWP (f
->root_window
))
4191 clear_current_matrices (f
);
4192 windows_or_buffers_changed
= 58;
4200 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
4201 This is done after attributes of a named face have been changed,
4202 because we can't tell which realized faces depend on that face. */
4205 free_all_realized_faces (Lisp_Object frame
)
4210 FOR_EACH_FRAME (rest
, frame
)
4211 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4214 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4218 /* Free face cache C and faces in it, including their X resources. */
4221 free_face_cache (struct face_cache
*c
)
4225 free_realized_faces (c
);
4227 xfree (c
->faces_by_id
);
4233 /* Cache realized face FACE in face cache C. HASH is the hash value
4234 of FACE. If FACE is for ASCII characters (i.e. FACE->ascii_face ==
4235 FACE), insert the new face to the beginning of the collision list
4236 of the face hash table of C. Otherwise, add the new face to the
4237 end of the collision list. This way, lookup_face can quickly find
4238 that a requested face is not cached. */
4241 cache_face (struct face_cache
*c
, struct face
*face
, unsigned int hash
)
4243 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4247 if (face
->ascii_face
!= face
)
4249 struct face
*last
= c
->buckets
[i
];
4260 c
->buckets
[i
] = face
;
4261 face
->prev
= face
->next
= NULL
;
4267 face
->next
= c
->buckets
[i
];
4269 face
->next
->prev
= face
;
4270 c
->buckets
[i
] = face
;
4273 /* Find a free slot in C->faces_by_id and use the index of the free
4274 slot as FACE->id. */
4275 for (i
= 0; i
< c
->used
; ++i
)
4276 if (c
->faces_by_id
[i
] == NULL
)
4281 /* Check that FACE got a unique id. */
4286 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
4287 for (face1
= c
->buckets
[j
]; face1
; face1
= face1
->next
)
4293 #endif /* GLYPH_DEBUG */
4295 /* Maybe enlarge C->faces_by_id. */
4298 if (c
->used
== c
->size
)
4299 c
->faces_by_id
= xpalloc (c
->faces_by_id
, &c
->size
, 1, MAX_FACE_ID
,
4300 sizeof *c
->faces_by_id
);
4304 c
->faces_by_id
[i
] = face
;
4308 /* Remove face FACE from cache C. */
4311 uncache_face (struct face_cache
*c
, struct face
*face
)
4313 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
4316 face
->prev
->next
= face
->next
;
4318 c
->buckets
[i
] = face
->next
;
4321 face
->next
->prev
= face
->prev
;
4323 c
->faces_by_id
[face
->id
] = NULL
;
4324 if (face
->id
== c
->used
)
4329 /* Look up a realized face with face attributes ATTR in the face cache
4330 of frame F. The face will be used to display ASCII characters.
4331 Value is the ID of the face found. If no suitable face is found,
4332 realize a new one. */
4335 lookup_face (struct frame
*f
, Lisp_Object
*attr
)
4337 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4342 eassert (cache
!= NULL
);
4343 check_lface_attrs (attr
);
4345 /* Look up ATTR in the face cache. */
4346 hash
= lface_hash (attr
);
4347 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4349 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4351 if (face
->ascii_face
!= face
)
4353 /* There's no more ASCII face. */
4357 if (face
->hash
== hash
4358 && lface_equal_p (face
->lface
, attr
))
4362 /* If not found, realize a new face. */
4364 face
= realize_face (cache
, attr
, -1);
4367 eassert (face
== FACE_FROM_ID (f
, face
->id
));
4368 #endif /* GLYPH_DEBUG */
4373 #ifdef HAVE_WINDOW_SYSTEM
4374 /* Look up a realized face that has the same attributes as BASE_FACE
4375 except for the font in the face cache of frame F. If FONT-OBJECT
4376 is not nil, it is an already opened font. If FONT-OBJECT is nil,
4377 the face has no font. Value is the ID of the face found. If no
4378 suitable face is found, realize a new one. */
4381 face_for_font (struct frame
*f
, Lisp_Object font_object
, struct face
*base_face
)
4383 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4388 eassert (cache
!= NULL
);
4389 base_face
= base_face
->ascii_face
;
4390 hash
= lface_hash (base_face
->lface
);
4391 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4393 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4395 if (face
->ascii_face
== face
)
4397 if (face
->ascii_face
== base_face
4398 && face
->font
== (NILP (font_object
) ? NULL
4399 : XFONT_OBJECT (font_object
))
4400 && lface_equal_p (face
->lface
, base_face
->lface
))
4404 /* If not found, realize a new face. */
4405 face
= realize_non_ascii_face (f
, font_object
, base_face
);
4408 #endif /* HAVE_WINDOW_SYSTEM */
4410 /* Return the face id of the realized face for named face SYMBOL on
4411 frame F suitable for displaying ASCII characters. Value is -1 if
4412 the face couldn't be determined, which might happen if the default
4413 face isn't realized and cannot be realized. */
4416 lookup_named_face (struct frame
*f
, Lisp_Object symbol
, int signal_p
)
4418 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4419 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4420 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4422 if (default_face
== NULL
)
4424 if (!realize_basic_faces (f
))
4426 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4427 if (default_face
== NULL
)
4428 emacs_abort (); /* realize_basic_faces must have set it up */
4431 if (! get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4434 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4435 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4437 return lookup_face (f
, attrs
);
4441 /* Return the display face-id of the basic face whose canonical face-id
4442 is FACE_ID. The return value will usually simply be FACE_ID, unless that
4443 basic face has bee remapped via Vface_remapping_alist. This function is
4444 conservative: if something goes wrong, it will simply return FACE_ID
4445 rather than signal an error. */
4448 lookup_basic_face (struct frame
*f
, int face_id
)
4450 Lisp_Object name
, mapping
;
4451 int remapped_face_id
;
4453 if (NILP (Vface_remapping_alist
))
4454 return face_id
; /* Nothing to do. */
4458 case DEFAULT_FACE_ID
: name
= Qdefault
; break;
4459 case MODE_LINE_FACE_ID
: name
= Qmode_line
; break;
4460 case MODE_LINE_INACTIVE_FACE_ID
: name
= Qmode_line_inactive
; break;
4461 case HEADER_LINE_FACE_ID
: name
= Qheader_line
; break;
4462 case TOOL_BAR_FACE_ID
: name
= Qtool_bar
; break;
4463 case FRINGE_FACE_ID
: name
= Qfringe
; break;
4464 case SCROLL_BAR_FACE_ID
: name
= Qscroll_bar
; break;
4465 case BORDER_FACE_ID
: name
= Qborder
; break;
4466 case CURSOR_FACE_ID
: name
= Qcursor
; break;
4467 case MOUSE_FACE_ID
: name
= Qmouse
; break;
4468 case MENU_FACE_ID
: name
= Qmenu
; break;
4471 emacs_abort (); /* the caller is supposed to pass us a basic face id */
4474 /* Do a quick scan through Vface_remapping_alist, and return immediately
4475 if there is no remapping for face NAME. This is just an optimization
4476 for the very common no-remapping case. */
4477 mapping
= assq_no_quit (name
, Vface_remapping_alist
);
4479 return face_id
; /* Give up. */
4481 /* If there is a remapping entry, lookup the face using NAME, which will
4482 handle the remapping too. */
4483 remapped_face_id
= lookup_named_face (f
, name
, 0);
4484 if (remapped_face_id
< 0)
4485 return face_id
; /* Give up. */
4487 return remapped_face_id
;
4491 /* Return a face for charset ASCII that is like the face with id
4492 FACE_ID on frame F, but has a font that is STEPS steps smaller.
4493 STEPS < 0 means larger. Value is the id of the face. */
4496 smaller_face (struct frame
*f
, int face_id
, int steps
)
4498 #ifdef HAVE_WINDOW_SYSTEM
4500 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4501 int pt
, last_pt
, last_height
;
4504 struct face
*new_face
;
4506 /* If not called for an X frame, just return the original face. */
4507 if (FRAME_TERMCAP_P (f
))
4510 /* Try in increments of 1/2 pt. */
4511 delta
= steps
< 0 ? 5 : -5;
4512 steps
= eabs (steps
);
4514 face
= FACE_FROM_ID (f
, face_id
);
4515 memcpy (attrs
, face
->lface
, sizeof attrs
);
4516 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
4517 new_face_id
= face_id
;
4518 last_height
= FONT_HEIGHT (face
->font
);
4522 /* Give up if we cannot find a font within 10pt. */
4523 && eabs (last_pt
- pt
) < 100)
4525 /* Look up a face for a slightly smaller/larger font. */
4527 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
4528 new_face_id
= lookup_face (f
, attrs
);
4529 new_face
= FACE_FROM_ID (f
, new_face_id
);
4531 /* If height changes, count that as one step. */
4532 if ((delta
< 0 && FONT_HEIGHT (new_face
->font
) < last_height
)
4533 || (delta
> 0 && FONT_HEIGHT (new_face
->font
) > last_height
))
4536 last_height
= FONT_HEIGHT (new_face
->font
);
4543 #else /* not HAVE_WINDOW_SYSTEM */
4547 #endif /* not HAVE_WINDOW_SYSTEM */
4551 /* Return a face for charset ASCII that is like the face with id
4552 FACE_ID on frame F, but has height HEIGHT. */
4555 face_with_height (struct frame
*f
, int face_id
, int height
)
4557 #ifdef HAVE_WINDOW_SYSTEM
4559 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4561 if (FRAME_TERMCAP_P (f
)
4565 face
= FACE_FROM_ID (f
, face_id
);
4566 memcpy (attrs
, face
->lface
, sizeof attrs
);
4567 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
4568 font_clear_prop (attrs
, FONT_SIZE_INDEX
);
4569 face_id
= lookup_face (f
, attrs
);
4570 #endif /* HAVE_WINDOW_SYSTEM */
4576 /* Return the face id of the realized face for named face SYMBOL on
4577 frame F suitable for displaying ASCII characters, and use
4578 attributes of the face FACE_ID for attributes that aren't
4579 completely specified by SYMBOL. This is like lookup_named_face,
4580 except that the default attributes come from FACE_ID, not from the
4581 default face. FACE_ID is assumed to be already realized. */
4584 lookup_derived_face (struct frame
*f
, Lisp_Object symbol
, int face_id
,
4587 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4588 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4589 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
4594 if (!get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4597 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4598 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4599 return lookup_face (f
, attrs
);
4602 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector
,
4603 Sface_attributes_as_vector
, 1, 1, 0,
4604 doc
: /* Return a vector of face attributes corresponding to PLIST. */)
4608 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
4610 merge_face_ref (XFRAME (selected_frame
), plist
, XVECTOR (lface
)->contents
,
4617 /***********************************************************************
4618 Face capability testing
4619 ***********************************************************************/
4622 /* If the distance (as returned by color_distance) between two colors is
4623 less than this, then they are considered the same, for determining
4624 whether a color is supported or not. The range of values is 0-65535. */
4626 #define TTY_SAME_COLOR_THRESHOLD 10000
4628 #ifdef HAVE_WINDOW_SYSTEM
4630 /* Return true if all the face attributes in ATTRS are supported
4631 on the window-system frame F.
4633 The definition of `supported' is somewhat heuristic, but basically means
4634 that a face containing all the attributes in ATTRS, when merged with the
4635 default face for display, can be represented in a way that's
4637 \(1) different in appearance than the default face, and
4638 \(2) `close in spirit' to what the attributes specify, if not exact. */
4641 x_supports_face_attributes_p (struct frame
*f
,
4642 Lisp_Object attrs
[LFACE_VECTOR_SIZE
],
4643 struct face
*def_face
)
4645 Lisp_Object
*def_attrs
= def_face
->lface
;
4647 /* Check that other specified attributes are different that the default
4649 if ((!UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
4650 && face_attr_equal_p (attrs
[LFACE_UNDERLINE_INDEX
],
4651 def_attrs
[LFACE_UNDERLINE_INDEX
]))
4652 || (!UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
4653 && face_attr_equal_p (attrs
[LFACE_INVERSE_INDEX
],
4654 def_attrs
[LFACE_INVERSE_INDEX
]))
4655 || (!UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
4656 && face_attr_equal_p (attrs
[LFACE_FOREGROUND_INDEX
],
4657 def_attrs
[LFACE_FOREGROUND_INDEX
]))
4658 || (!UNSPECIFIEDP (attrs
[LFACE_DISTANT_FOREGROUND_INDEX
])
4659 && face_attr_equal_p (attrs
[LFACE_DISTANT_FOREGROUND_INDEX
],
4660 def_attrs
[LFACE_DISTANT_FOREGROUND_INDEX
]))
4661 || (!UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
4662 && face_attr_equal_p (attrs
[LFACE_BACKGROUND_INDEX
],
4663 def_attrs
[LFACE_BACKGROUND_INDEX
]))
4664 || (!UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
4665 && face_attr_equal_p (attrs
[LFACE_STIPPLE_INDEX
],
4666 def_attrs
[LFACE_STIPPLE_INDEX
]))
4667 || (!UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
4668 && face_attr_equal_p (attrs
[LFACE_OVERLINE_INDEX
],
4669 def_attrs
[LFACE_OVERLINE_INDEX
]))
4670 || (!UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
4671 && face_attr_equal_p (attrs
[LFACE_STRIKE_THROUGH_INDEX
],
4672 def_attrs
[LFACE_STRIKE_THROUGH_INDEX
]))
4673 || (!UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
4674 && face_attr_equal_p (attrs
[LFACE_BOX_INDEX
],
4675 def_attrs
[LFACE_BOX_INDEX
])))
4678 /* Check font-related attributes, as those are the most commonly
4679 "unsupported" on a window-system (because of missing fonts). */
4680 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
4681 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
4682 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
4683 || !UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
4684 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
4685 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
]))
4689 Lisp_Object merged_attrs
[LFACE_VECTOR_SIZE
];
4692 memcpy (merged_attrs
, def_attrs
, sizeof merged_attrs
);
4694 merge_face_vectors (f
, attrs
, merged_attrs
, 0);
4696 face_id
= lookup_face (f
, merged_attrs
);
4697 face
= FACE_FROM_ID (f
, face_id
);
4700 error ("Cannot make face");
4702 /* If the font is the same, or no font is found, then not
4704 if (face
->font
== def_face
->font
4707 for (i
= FONT_TYPE_INDEX
; i
<= FONT_SIZE_INDEX
; i
++)
4708 if (! EQ (face
->font
->props
[i
], def_face
->font
->props
[i
]))
4712 if (i
< FONT_FOUNDRY_INDEX
|| i
> FONT_REGISTRY_INDEX
4713 || face
->font
->driver
->case_sensitive
)
4715 s1
= SYMBOL_NAME (face
->font
->props
[i
]);
4716 s2
= SYMBOL_NAME (def_face
->font
->props
[i
]);
4717 if (! EQ (Fcompare_strings (s1
, make_number (0), Qnil
,
4718 s2
, make_number (0), Qnil
, Qt
), Qt
))
4724 /* Everything checks out, this face is supported. */
4728 #endif /* HAVE_WINDOW_SYSTEM */
4730 /* Return true if all the face attributes in ATTRS are supported
4733 The definition of `supported' is somewhat heuristic, but basically means
4734 that a face containing all the attributes in ATTRS, when merged
4735 with the default face for display, can be represented in a way that's
4737 \(1) different in appearance than the default face, and
4738 \(2) `close in spirit' to what the attributes specify, if not exact.
4740 Point (2) implies that a `:weight black' attribute will be satisfied
4741 by any terminal that can display bold, and a `:foreground "yellow"' as
4742 long as the terminal can display a yellowish color, but `:slant italic'
4743 will _not_ be satisfied by the tty display code's automatic
4744 substitution of a `dim' face for italic. */
4747 tty_supports_face_attributes_p (struct frame
*f
,
4748 Lisp_Object attrs
[LFACE_VECTOR_SIZE
],
4749 struct face
*def_face
)
4752 Lisp_Object val
, fg
, bg
;
4753 XColor fg_tty_color
, fg_std_color
;
4754 XColor bg_tty_color
, bg_std_color
;
4755 unsigned test_caps
= 0;
4756 Lisp_Object
*def_attrs
= def_face
->lface
;
4758 /* First check some easy-to-check stuff; ttys support none of the
4759 following attributes, so we can just return false if any are requested
4760 (even if `nominal' values are specified, we should still return false,
4761 as that will be the same value that the default face uses). We
4762 consider :slant unsupportable on ttys, even though the face code
4763 actually `fakes' them using a dim attribute if possible. This is
4764 because the faked result is too different from what the face
4766 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
4767 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
4768 || !UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
4769 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
4770 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
4771 || !UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
4772 || !UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
4773 || !UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
]))
4776 /* Test for terminal `capabilities' (non-color character attributes). */
4778 /* font weight (bold/dim) */
4779 val
= attrs
[LFACE_WEIGHT_INDEX
];
4780 if (!UNSPECIFIEDP (val
)
4781 && (weight
= FONT_WEIGHT_NAME_NUMERIC (val
), weight
>= 0))
4783 int def_weight
= FONT_WEIGHT_NAME_NUMERIC (def_attrs
[LFACE_WEIGHT_INDEX
]);
4787 if (def_weight
> 100)
4788 return 0; /* same as default */
4789 test_caps
= TTY_CAP_BOLD
;
4791 else if (weight
< 100)
4793 if (def_weight
< 100)
4794 return 0; /* same as default */
4795 test_caps
= TTY_CAP_DIM
;
4797 else if (def_weight
== 100)
4798 return 0; /* same as default */
4802 val
= attrs
[LFACE_SLANT_INDEX
];
4803 if (!UNSPECIFIEDP (val
)
4804 && (slant
= FONT_SLANT_NAME_NUMERIC (val
), slant
>= 0))
4806 int def_slant
= FONT_SLANT_NAME_NUMERIC (def_attrs
[LFACE_SLANT_INDEX
]);
4807 if (slant
== 100 || slant
== def_slant
)
4808 return 0; /* same as default */
4810 test_caps
|= TTY_CAP_ITALIC
;
4814 val
= attrs
[LFACE_UNDERLINE_INDEX
];
4815 if (!UNSPECIFIEDP (val
))
4818 return 0; /* ttys can't use colored underlines */
4819 else if (EQ (CAR_SAFE (val
), QCstyle
) && EQ (CAR_SAFE (CDR_SAFE (val
)), Qwave
))
4820 return 0; /* ttys can't use wave underlines */
4821 else if (face_attr_equal_p (val
, def_attrs
[LFACE_UNDERLINE_INDEX
]))
4822 return 0; /* same as default */
4824 test_caps
|= TTY_CAP_UNDERLINE
;
4828 val
= attrs
[LFACE_INVERSE_INDEX
];
4829 if (!UNSPECIFIEDP (val
))
4831 if (face_attr_equal_p (val
, def_attrs
[LFACE_INVERSE_INDEX
]))
4832 return 0; /* same as default */
4834 test_caps
|= TTY_CAP_INVERSE
;
4838 /* Color testing. */
4840 /* Check if foreground color is close enough. */
4841 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
4844 Lisp_Object def_fg
= def_attrs
[LFACE_FOREGROUND_INDEX
];
4846 if (face_attr_equal_p (fg
, def_fg
))
4847 return 0; /* same as default */
4848 else if (! tty_lookup_color (f
, fg
, &fg_tty_color
, &fg_std_color
))
4849 return 0; /* not a valid color */
4850 else if (color_distance (&fg_tty_color
, &fg_std_color
)
4851 > TTY_SAME_COLOR_THRESHOLD
)
4852 return 0; /* displayed color is too different */
4854 /* Make sure the color is really different than the default. */
4856 XColor def_fg_color
;
4857 if (tty_lookup_color (f
, def_fg
, &def_fg_color
, 0)
4858 && (color_distance (&fg_tty_color
, &def_fg_color
)
4859 <= TTY_SAME_COLOR_THRESHOLD
))
4864 /* Check if background color is close enough. */
4865 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
4868 Lisp_Object def_bg
= def_attrs
[LFACE_BACKGROUND_INDEX
];
4870 if (face_attr_equal_p (bg
, def_bg
))
4871 return 0; /* same as default */
4872 else if (! tty_lookup_color (f
, bg
, &bg_tty_color
, &bg_std_color
))
4873 return 0; /* not a valid color */
4874 else if (color_distance (&bg_tty_color
, &bg_std_color
)
4875 > TTY_SAME_COLOR_THRESHOLD
)
4876 return 0; /* displayed color is too different */
4878 /* Make sure the color is really different than the default. */
4880 XColor def_bg_color
;
4881 if (tty_lookup_color (f
, def_bg
, &def_bg_color
, 0)
4882 && (color_distance (&bg_tty_color
, &def_bg_color
)
4883 <= TTY_SAME_COLOR_THRESHOLD
))
4888 /* If both foreground and background are requested, see if the
4889 distance between them is OK. We just check to see if the distance
4890 between the tty's foreground and background is close enough to the
4891 distance between the standard foreground and background. */
4892 if (STRINGP (fg
) && STRINGP (bg
))
4895 = (color_distance (&fg_std_color
, &bg_std_color
)
4896 - color_distance (&fg_tty_color
, &bg_tty_color
));
4897 if (delta_delta
> TTY_SAME_COLOR_THRESHOLD
4898 || delta_delta
< -TTY_SAME_COLOR_THRESHOLD
)
4903 /* See if the capabilities we selected above are supported, with the
4905 return tty_capable_p (FRAME_TTY (f
), test_caps
);
4909 DEFUN ("display-supports-face-attributes-p",
4910 Fdisplay_supports_face_attributes_p
, Sdisplay_supports_face_attributes_p
,
4912 doc
: /* Return non-nil if all the face attributes in ATTRIBUTES are supported.
4913 The optional argument DISPLAY can be a display name, a frame, or
4914 nil (meaning the selected frame's display).
4916 The definition of `supported' is somewhat heuristic, but basically means
4917 that a face containing all the attributes in ATTRIBUTES, when merged
4918 with the default face for display, can be represented in a way that's
4920 \(1) different in appearance than the default face, and
4921 \(2) `close in spirit' to what the attributes specify, if not exact.
4923 Point (2) implies that a `:weight black' attribute will be satisfied by
4924 any display that can display bold, and a `:foreground \"yellow\"' as long
4925 as it can display a yellowish color, but `:slant italic' will _not_ be
4926 satisfied by the tty display code's automatic substitution of a `dim'
4927 face for italic. */)
4928 (Lisp_Object attributes
, Lisp_Object display
)
4934 struct face
*def_face
;
4935 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4937 if (noninteractive
|| !initialized
)
4938 /* We may not be able to access low-level face information in batch
4939 mode, or before being dumped, and this function is not going to
4940 be very useful in those cases anyway, so just give up. */
4944 frame
= selected_frame
;
4945 else if (FRAMEP (display
))
4949 /* Find any frame on DISPLAY. */
4953 FOR_EACH_FRAME (tail
, frame
)
4954 if (!NILP (Fequal (Fcdr (Fassq (Qdisplay
,
4955 XFRAME (frame
)->param_alist
)),
4960 CHECK_LIVE_FRAME (frame
);
4963 for (i
= 0; i
< LFACE_VECTOR_SIZE
; i
++)
4964 attrs
[i
] = Qunspecified
;
4965 merge_face_ref (f
, attributes
, attrs
, 1, 0);
4967 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4968 if (def_face
== NULL
)
4970 if (! realize_basic_faces (f
))
4971 error ("Cannot realize default face");
4972 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4973 if (def_face
== NULL
)
4974 emacs_abort (); /* realize_basic_faces must have set it up */
4977 /* Dispatch to the appropriate handler. */
4978 if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
4979 supports
= tty_supports_face_attributes_p (f
, attrs
, def_face
);
4980 #ifdef HAVE_WINDOW_SYSTEM
4982 supports
= x_supports_face_attributes_p (f
, attrs
, def_face
);
4985 return supports
? Qt
: Qnil
;
4989 /***********************************************************************
4991 ***********************************************************************/
4993 DEFUN ("internal-set-font-selection-order",
4994 Finternal_set_font_selection_order
,
4995 Sinternal_set_font_selection_order
, 1, 1, 0,
4996 doc
: /* Set font selection order for face font selection to ORDER.
4997 ORDER must be a list of length 4 containing the symbols `:width',
4998 `:height', `:weight', and `:slant'. Face attributes appearing
4999 first in ORDER are matched first, e.g. if `:height' appears before
5000 `:weight' in ORDER, font selection first tries to find a font with
5001 a suitable height, and then tries to match the font weight.
5007 int indices
[ARRAYELTS (font_sort_order
)];
5010 memset (indices
, 0, sizeof indices
);
5014 CONSP (list
) && i
< ARRAYELTS (indices
);
5015 list
= XCDR (list
), ++i
)
5017 Lisp_Object attr
= XCAR (list
);
5020 if (EQ (attr
, QCwidth
))
5022 else if (EQ (attr
, QCheight
))
5023 xlfd
= XLFD_POINT_SIZE
;
5024 else if (EQ (attr
, QCweight
))
5026 else if (EQ (attr
, QCslant
))
5031 if (indices
[i
] != 0)
5036 if (!NILP (list
) || i
!= ARRAYELTS (indices
))
5037 signal_error ("Invalid font sort order", order
);
5038 for (i
= 0; i
< ARRAYELTS (font_sort_order
); ++i
)
5039 if (indices
[i
] == 0)
5040 signal_error ("Invalid font sort order", order
);
5042 if (memcmp (indices
, font_sort_order
, sizeof indices
) != 0)
5044 memcpy (font_sort_order
, indices
, sizeof font_sort_order
);
5045 free_all_realized_faces (Qnil
);
5048 font_update_sort_order (font_sort_order
);
5054 DEFUN ("internal-set-alternative-font-family-alist",
5055 Finternal_set_alternative_font_family_alist
,
5056 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
5057 doc
: /* Define alternative font families to try in face font selection.
5058 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5059 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
5060 be found. Value is ALIST. */)
5063 Lisp_Object entry
, tail
, tail2
;
5066 alist
= Fcopy_sequence (alist
);
5067 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5069 entry
= XCAR (tail
);
5071 entry
= Fcopy_sequence (entry
);
5072 XSETCAR (tail
, entry
);
5073 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5074 XSETCAR (tail2
, Fintern (XCAR (tail2
), Qnil
));
5077 Vface_alternative_font_family_alist
= alist
;
5078 free_all_realized_faces (Qnil
);
5083 DEFUN ("internal-set-alternative-font-registry-alist",
5084 Finternal_set_alternative_font_registry_alist
,
5085 Sinternal_set_alternative_font_registry_alist
, 1, 1, 0,
5086 doc
: /* Define alternative font registries to try in face font selection.
5087 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5088 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
5089 be found. Value is ALIST. */)
5092 Lisp_Object entry
, tail
, tail2
;
5095 alist
= Fcopy_sequence (alist
);
5096 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5098 entry
= XCAR (tail
);
5100 entry
= Fcopy_sequence (entry
);
5101 XSETCAR (tail
, entry
);
5102 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5103 XSETCAR (tail2
, Fdowncase (XCAR (tail2
)));
5105 Vface_alternative_font_registry_alist
= alist
;
5106 free_all_realized_faces (Qnil
);
5111 #ifdef HAVE_WINDOW_SYSTEM
5113 /* Return the fontset id of the base fontset name or alias name given
5114 by the fontset attribute of ATTRS. Value is -1 if the fontset
5115 attribute of ATTRS doesn't name a fontset. */
5118 face_fontset (Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
5122 name
= attrs
[LFACE_FONTSET_INDEX
];
5123 if (!STRINGP (name
))
5125 return fs_query_fontset (name
, 0);
5128 #endif /* HAVE_WINDOW_SYSTEM */
5132 /***********************************************************************
5134 ***********************************************************************/
5136 /* Realize basic faces on frame F. Value is zero if frame parameters
5137 of F don't contain enough information needed to realize the default
5141 realize_basic_faces (struct frame
*f
)
5144 ptrdiff_t count
= SPECPDL_INDEX ();
5146 /* Block input here so that we won't be surprised by an X expose
5147 event, for instance, without having the faces set up. */
5149 specbind (Qscalable_fonts_allowed
, Qt
);
5151 if (realize_default_face (f
))
5153 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
5154 realize_named_face (f
, Qmode_line_inactive
, MODE_LINE_INACTIVE_FACE_ID
);
5155 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
5156 realize_named_face (f
, Qfringe
, FRINGE_FACE_ID
);
5157 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
5158 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
5159 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
5160 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
5161 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
5162 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
5163 realize_named_face (f
, Qvertical_border
, VERTICAL_BORDER_FACE_ID
);
5164 realize_named_face (f
, Qwindow_divider
, WINDOW_DIVIDER_FACE_ID
);
5165 realize_named_face (f
, Qwindow_divider_first_pixel
,
5166 WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID
);
5167 realize_named_face (f
, Qwindow_divider_last_pixel
,
5168 WINDOW_DIVIDER_LAST_PIXEL_FACE_ID
);
5170 /* Reflect changes in the `menu' face in menu bars. */
5171 if (FRAME_FACE_CACHE (f
)->menu_face_changed_p
)
5173 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 0;
5174 #ifdef USE_X_TOOLKIT
5175 if (FRAME_WINDOW_P (f
))
5176 x_update_menu_appearance (f
);
5183 unbind_to (count
, Qnil
);
5189 /* Realize the default face on frame F. If the face is not fully
5190 specified, make it fully-specified. Attributes of the default face
5191 that are not explicitly specified are taken from frame parameters. */
5194 realize_default_face (struct frame
*f
)
5196 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5198 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5201 /* If the `default' face is not yet known, create it. */
5202 lface
= lface_from_face_name (f
, Qdefault
, 0);
5206 XSETFRAME (frame
, f
);
5207 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
5210 #ifdef HAVE_WINDOW_SYSTEM
5211 if (FRAME_WINDOW_P (f
))
5213 Lisp_Object font_object
;
5215 XSETFONT (font_object
, FRAME_FONT (f
));
5216 set_lface_from_font (f
, lface
, font_object
, f
->default_face_done_p
);
5217 ASET (lface
, LFACE_FONTSET_INDEX
, fontset_name (FRAME_FONTSET (f
)));
5218 f
->default_face_done_p
= 1;
5220 #endif /* HAVE_WINDOW_SYSTEM */
5222 if (!FRAME_WINDOW_P (f
))
5224 ASET (lface
, LFACE_FAMILY_INDEX
, build_string ("default"));
5225 ASET (lface
, LFACE_FOUNDRY_INDEX
, LFACE_FAMILY (lface
));
5226 ASET (lface
, LFACE_SWIDTH_INDEX
, Qnormal
);
5227 ASET (lface
, LFACE_HEIGHT_INDEX
, make_number (1));
5228 if (UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
5229 ASET (lface
, LFACE_WEIGHT_INDEX
, Qnormal
);
5230 if (UNSPECIFIEDP (LFACE_SLANT (lface
)))
5231 ASET (lface
, LFACE_SLANT_INDEX
, Qnormal
);
5232 if (UNSPECIFIEDP (LFACE_FONTSET (lface
)))
5233 ASET (lface
, LFACE_FONTSET_INDEX
, Qnil
);
5236 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
5237 ASET (lface
, LFACE_UNDERLINE_INDEX
, Qnil
);
5239 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
5240 ASET (lface
, LFACE_OVERLINE_INDEX
, Qnil
);
5242 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
5243 ASET (lface
, LFACE_STRIKE_THROUGH_INDEX
, Qnil
);
5245 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
5246 ASET (lface
, LFACE_BOX_INDEX
, Qnil
);
5248 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
5249 ASET (lface
, LFACE_INVERSE_INDEX
, Qnil
);
5251 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
5253 /* This function is called so early that colors are not yet
5254 set in the frame parameter list. */
5255 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
5257 if (CONSP (color
) && STRINGP (XCDR (color
)))
5258 ASET (lface
, LFACE_FOREGROUND_INDEX
, XCDR (color
));
5259 else if (FRAME_WINDOW_P (f
))
5261 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5262 ASET (lface
, LFACE_FOREGROUND_INDEX
, build_string (unspecified_fg
));
5267 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
5269 /* This function is called so early that colors are not yet
5270 set in the frame parameter list. */
5271 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
5272 if (CONSP (color
) && STRINGP (XCDR (color
)))
5273 ASET (lface
, LFACE_BACKGROUND_INDEX
, XCDR (color
));
5274 else if (FRAME_WINDOW_P (f
))
5276 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5277 ASET (lface
, LFACE_BACKGROUND_INDEX
, build_string (unspecified_bg
));
5282 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
5283 ASET (lface
, LFACE_STIPPLE_INDEX
, Qnil
);
5285 /* Realize the face; it must be fully-specified now. */
5286 eassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
5287 check_lface (lface
);
5288 memcpy (attrs
, XVECTOR (lface
)->contents
, sizeof attrs
);
5289 face
= realize_face (c
, attrs
, DEFAULT_FACE_ID
);
5291 #ifdef HAVE_WINDOW_SYSTEM
5292 #ifdef HAVE_X_WINDOWS
5293 if (FRAME_X_P (f
) && face
->font
!= FRAME_FONT (f
))
5295 /* This can happen when making a frame on a display that does
5296 not support the default font. */
5300 /* Otherwise, the font specified for the frame was not
5301 acceptable as a font for the default face (perhaps because
5302 auto-scaled fonts are rejected), so we must adjust the frame
5304 x_set_font (f
, LFACE_FONT (lface
), Qnil
);
5306 #endif /* HAVE_X_WINDOWS */
5307 #endif /* HAVE_WINDOW_SYSTEM */
5312 /* Realize basic faces other than the default face in face cache C.
5313 SYMBOL is the face name, ID is the face id the realized face must
5314 have. The default face must have been realized already. */
5317 realize_named_face (struct frame
*f
, Lisp_Object symbol
, int id
)
5319 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5320 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
5321 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5322 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5324 /* The default face must exist and be fully specified. */
5325 get_lface_attributes_no_remap (f
, Qdefault
, attrs
, 1);
5326 check_lface_attrs (attrs
);
5327 eassert (lface_fully_specified_p (attrs
));
5329 /* If SYMBOL isn't know as a face, create it. */
5333 XSETFRAME (frame
, f
);
5334 lface
= Finternal_make_lisp_face (symbol
, frame
);
5337 /* Merge SYMBOL's face with the default face. */
5338 get_lface_attributes_no_remap (f
, symbol
, symbol_attrs
, 1);
5339 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
5341 /* Realize the face. */
5342 realize_face (c
, attrs
, id
);
5346 /* Realize the fully-specified face with attributes ATTRS in face
5347 cache CACHE for ASCII characters. If FORMER_FACE_ID is
5348 non-negative, it is an ID of face to remove before caching the new
5349 face. Value is a pointer to the newly created realized face. */
5351 static struct face
*
5352 realize_face (struct face_cache
*cache
, Lisp_Object attrs
[LFACE_VECTOR_SIZE
],
5357 /* LFACE must be fully specified. */
5358 eassert (cache
!= NULL
);
5359 check_lface_attrs (attrs
);
5361 if (former_face_id
>= 0 && cache
->used
> former_face_id
)
5363 /* Remove the former face. */
5364 struct face
*former_face
= cache
->faces_by_id
[former_face_id
];
5365 uncache_face (cache
, former_face
);
5366 free_realized_face (cache
->f
, former_face
);
5367 SET_FRAME_GARBAGED (cache
->f
);
5370 if (FRAME_WINDOW_P (cache
->f
))
5371 face
= realize_x_face (cache
, attrs
);
5372 else if (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
))
5373 face
= realize_tty_face (cache
, attrs
);
5374 else if (FRAME_INITIAL_P (cache
->f
))
5376 /* Create a dummy face. */
5377 face
= make_realized_face (attrs
);
5382 /* Insert the new face. */
5383 cache_face (cache
, face
, lface_hash (attrs
));
5388 #ifdef HAVE_WINDOW_SYSTEM
5389 /* Realize the fully-specified face that uses FONT-OBJECT and has the
5390 same attributes as BASE_FACE except for the font on frame F.
5391 FONT-OBJECT may be nil, in which case, realized a face of
5394 static struct face
*
5395 realize_non_ascii_face (struct frame
*f
, Lisp_Object font_object
,
5396 struct face
*base_face
)
5398 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5401 face
= xmalloc (sizeof *face
);
5405 = (! NILP (font_object
)
5406 && FONT_WEIGHT_NAME_NUMERIC (face
->lface
[LFACE_WEIGHT_INDEX
]) > 100
5407 && FONT_WEIGHT_NUMERIC (font_object
) <= 100);
5409 /* Don't try to free the colors copied bitwise from BASE_FACE. */
5410 face
->colors_copied_bitwise_p
= 1;
5411 face
->font
= NILP (font_object
) ? NULL
: XFONT_OBJECT (font_object
);
5414 cache_face (cache
, face
, face
->hash
);
5418 #endif /* HAVE_WINDOW_SYSTEM */
5421 /* Realize the fully-specified face with attributes ATTRS in face
5422 cache CACHE for ASCII characters. Do it for X frame CACHE->f. If
5423 the new face doesn't share font with the default face, a fontname
5424 is allocated from the heap and set in `font_name' of the new face,
5425 but it is not yet loaded here. Value is a pointer to the newly
5426 created realized face. */
5428 static struct face
*
5429 realize_x_face (struct face_cache
*cache
, Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
5431 struct face
*face
= NULL
;
5432 #ifdef HAVE_WINDOW_SYSTEM
5433 struct face
*default_face
;
5435 Lisp_Object stipple
, underline
, overline
, strike_through
, box
;
5437 eassert (FRAME_WINDOW_P (cache
->f
));
5439 /* Allocate a new realized face. */
5440 face
= make_realized_face (attrs
);
5441 face
->ascii_face
= face
;
5445 /* Determine the font to use. Most of the time, the font will be
5446 the same as the font of the default face, so try that first. */
5447 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5449 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
5451 face
->font
= default_face
->font
;
5453 = make_fontset_for_ascii_face (f
, default_face
->fontset
, face
);
5457 /* If the face attribute ATTRS specifies a fontset, use it as
5458 the base of a new realized fontset. Otherwise, use the same
5459 base fontset as of the default face. The base determines
5460 registry and encoding of a font. It may also determine
5461 foundry and family. The other fields of font name pattern
5462 are constructed from ATTRS. */
5463 int fontset
= face_fontset (attrs
);
5465 /* If we are realizing the default face, ATTRS should specify a
5466 fontset. In other words, if FONTSET is -1, we are not
5467 realizing the default face, thus the default face should have
5468 already been realized. */
5472 fontset
= default_face
->fontset
;
5476 if (! FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5477 attrs
[LFACE_FONT_INDEX
]
5478 = font_load_for_lface (f
, attrs
, Ffont_spec (0, NULL
));
5479 if (FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5481 face
->font
= XFONT_OBJECT (attrs
[LFACE_FONT_INDEX
]);
5482 face
->fontset
= make_fontset_for_ascii_face (f
, fontset
, face
);
5492 && FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]) > 100
5493 && FONT_WEIGHT_NUMERIC (attrs
[LFACE_FONT_INDEX
]) <= 100)
5494 face
->overstrike
= 1;
5496 /* Load colors, and set remaining attributes. */
5498 load_face_colors (f
, face
, attrs
);
5501 box
= attrs
[LFACE_BOX_INDEX
];
5504 /* A simple box of line width 1 drawn in color given by
5506 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
5508 face
->box
= FACE_SIMPLE_BOX
;
5509 face
->box_line_width
= 1;
5511 else if (INTEGERP (box
))
5513 /* Simple box of specified line width in foreground color of the
5515 eassert (XINT (box
) != 0);
5516 face
->box
= FACE_SIMPLE_BOX
;
5517 face
->box_line_width
= XINT (box
);
5518 face
->box_color
= face
->foreground
;
5519 face
->box_color_defaulted_p
= 1;
5521 else if (CONSP (box
))
5523 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
5524 being one of `raised' or `sunken'. */
5525 face
->box
= FACE_SIMPLE_BOX
;
5526 face
->box_color
= face
->foreground
;
5527 face
->box_color_defaulted_p
= 1;
5528 face
->box_line_width
= 1;
5532 Lisp_Object keyword
, value
;
5534 keyword
= XCAR (box
);
5542 if (EQ (keyword
, QCline_width
))
5544 if (INTEGERP (value
) && XINT (value
) != 0)
5545 face
->box_line_width
= XINT (value
);
5547 else if (EQ (keyword
, QCcolor
))
5549 if (STRINGP (value
))
5551 face
->box_color
= load_color (f
, face
, value
,
5553 face
->use_box_color_for_shadows_p
= 1;
5556 else if (EQ (keyword
, QCstyle
))
5558 if (EQ (value
, Qreleased_button
))
5559 face
->box
= FACE_RAISED_BOX
;
5560 else if (EQ (value
, Qpressed_button
))
5561 face
->box
= FACE_SUNKEN_BOX
;
5566 /* Text underline, overline, strike-through. */
5568 underline
= attrs
[LFACE_UNDERLINE_INDEX
];
5569 if (EQ (underline
, Qt
))
5571 /* Use default color (same as foreground color). */
5572 face
->underline_p
= 1;
5573 face
->underline_type
= FACE_UNDER_LINE
;
5574 face
->underline_defaulted_p
= 1;
5575 face
->underline_color
= 0;
5577 else if (STRINGP (underline
))
5579 /* Use specified color. */
5580 face
->underline_p
= 1;
5581 face
->underline_type
= FACE_UNDER_LINE
;
5582 face
->underline_defaulted_p
= 0;
5583 face
->underline_color
5584 = load_color (f
, face
, underline
,
5585 LFACE_UNDERLINE_INDEX
);
5587 else if (NILP (underline
))
5589 face
->underline_p
= 0;
5590 face
->underline_defaulted_p
= 0;
5591 face
->underline_color
= 0;
5593 else if (CONSP (underline
))
5595 /* `(:color COLOR :style STYLE)'.
5596 STYLE being one of `line' or `wave'. */
5597 face
->underline_p
= 1;
5598 face
->underline_color
= 0;
5599 face
->underline_defaulted_p
= 1;
5600 face
->underline_type
= FACE_UNDER_LINE
;
5602 /* FIXME? This is also not robust about checking the precise form.
5603 See comments in Finternal_set_lisp_face_attribute. */
5604 while (CONSP (underline
))
5606 Lisp_Object keyword
, value
;
5608 keyword
= XCAR (underline
);
5609 underline
= XCDR (underline
);
5611 if (!CONSP (underline
))
5613 value
= XCAR (underline
);
5614 underline
= XCDR (underline
);
5616 if (EQ (keyword
, QCcolor
))
5618 if (EQ (value
, Qforeground_color
))
5620 face
->underline_defaulted_p
= 1;
5621 face
->underline_color
= 0;
5623 else if (STRINGP (value
))
5625 face
->underline_defaulted_p
= 0;
5626 face
->underline_color
= load_color (f
, face
, value
,
5627 LFACE_UNDERLINE_INDEX
);
5630 else if (EQ (keyword
, QCstyle
))
5632 if (EQ (value
, Qline
))
5633 face
->underline_type
= FACE_UNDER_LINE
;
5634 else if (EQ (value
, Qwave
))
5635 face
->underline_type
= FACE_UNDER_WAVE
;
5640 overline
= attrs
[LFACE_OVERLINE_INDEX
];
5641 if (STRINGP (overline
))
5643 face
->overline_color
5644 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
5645 LFACE_OVERLINE_INDEX
);
5646 face
->overline_p
= 1;
5648 else if (EQ (overline
, Qt
))
5650 face
->overline_color
= face
->foreground
;
5651 face
->overline_color_defaulted_p
= 1;
5652 face
->overline_p
= 1;
5655 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
5656 if (STRINGP (strike_through
))
5658 face
->strike_through_color
5659 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
5660 LFACE_STRIKE_THROUGH_INDEX
);
5661 face
->strike_through_p
= 1;
5663 else if (EQ (strike_through
, Qt
))
5665 face
->strike_through_color
= face
->foreground
;
5666 face
->strike_through_color_defaulted_p
= 1;
5667 face
->strike_through_p
= 1;
5670 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
5671 if (!NILP (stipple
))
5672 face
->stipple
= load_pixmap (f
, stipple
);
5673 #endif /* HAVE_WINDOW_SYSTEM */
5679 /* Map a specified color of face FACE on frame F to a tty color index.
5680 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
5681 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
5682 default foreground/background colors. */
5685 map_tty_color (struct frame
*f
, struct face
*face
,
5686 enum lface_attribute_index idx
, int *defaulted
)
5688 Lisp_Object frame
, color
, def
;
5689 int foreground_p
= idx
== LFACE_FOREGROUND_INDEX
;
5690 unsigned long default_pixel
=
5691 foreground_p
? FACE_TTY_DEFAULT_FG_COLOR
: FACE_TTY_DEFAULT_BG_COLOR
;
5692 unsigned long pixel
= default_pixel
;
5694 unsigned long default_other_pixel
=
5695 foreground_p
? FACE_TTY_DEFAULT_BG_COLOR
: FACE_TTY_DEFAULT_FG_COLOR
;
5698 eassert (idx
== LFACE_FOREGROUND_INDEX
|| idx
== LFACE_BACKGROUND_INDEX
);
5700 XSETFRAME (frame
, f
);
5701 color
= face
->lface
[idx
];
5705 && CONSP (Vtty_defined_color_alist
)
5706 && (def
= assq_no_quit (color
, call1 (Qtty_color_alist
, frame
)),
5709 /* Associations in tty-defined-color-alist are of the form
5710 (NAME INDEX R G B). We need the INDEX part. */
5711 pixel
= XINT (XCAR (XCDR (def
)));
5714 if (pixel
== default_pixel
&& STRINGP (color
))
5716 pixel
= load_color (f
, face
, color
, idx
);
5719 /* If the foreground of the default face is the default color,
5720 use the foreground color defined by the frame. */
5721 if (FRAME_MSDOS_P (f
))
5723 if (pixel
== default_pixel
5724 || pixel
== FACE_TTY_DEFAULT_COLOR
)
5727 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5729 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5730 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5733 else if (pixel
== default_other_pixel
)
5736 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5738 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5739 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5747 face
->foreground
= pixel
;
5749 face
->background
= pixel
;
5753 /* Realize the fully-specified face with attributes ATTRS in face
5754 cache CACHE for ASCII characters. Do it for TTY frame CACHE->f.
5755 Value is a pointer to the newly created realized face. */
5757 static struct face
*
5758 realize_tty_face (struct face_cache
*cache
,
5759 Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
5763 int face_colors_defaulted
= 0;
5764 struct frame
*f
= cache
->f
;
5766 /* Frame must be a termcap frame. */
5767 eassert (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
));
5769 /* Allocate a new realized face. */
5770 face
= make_realized_face (attrs
);
5772 face
->font_name
= FRAME_MSDOS_P (cache
->f
) ? "ms-dos" : "tty";
5775 /* Map face attributes to TTY appearances. */
5776 weight
= FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]);
5777 slant
= FONT_SLANT_NAME_NUMERIC (attrs
[LFACE_SLANT_INDEX
]);
5779 face
->tty_bold_p
= 1;
5781 face
->tty_italic_p
= 1;
5782 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5783 face
->tty_underline_p
= 1;
5784 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
5785 face
->tty_reverse_p
= 1;
5787 /* Map color names to color indices. */
5788 map_tty_color (f
, face
, LFACE_FOREGROUND_INDEX
, &face_colors_defaulted
);
5789 map_tty_color (f
, face
, LFACE_BACKGROUND_INDEX
, &face_colors_defaulted
);
5791 /* Swap colors if face is inverse-video. If the colors are taken
5792 from the frame colors, they are already inverted, since the
5793 frame-creation function calls x-handle-reverse-video. */
5794 if (face
->tty_reverse_p
&& !face_colors_defaulted
)
5796 unsigned long tem
= face
->foreground
;
5797 face
->foreground
= face
->background
;
5798 face
->background
= tem
;
5801 if (tty_suppress_bold_inverse_default_colors_p
5803 && face
->background
== FACE_TTY_DEFAULT_FG_COLOR
5804 && face
->foreground
== FACE_TTY_DEFAULT_BG_COLOR
)
5805 face
->tty_bold_p
= 0;
5811 DEFUN ("tty-suppress-bold-inverse-default-colors",
5812 Ftty_suppress_bold_inverse_default_colors
,
5813 Stty_suppress_bold_inverse_default_colors
, 1, 1, 0,
5814 doc
: /* Suppress/allow boldness of faces with inverse default colors.
5815 SUPPRESS non-nil means suppress it.
5816 This affects bold faces on TTYs whose foreground is the default background
5817 color of the display and whose background is the default foreground color.
5818 For such faces, the bold face attribute is ignored if this variable
5820 (Lisp_Object suppress
)
5822 tty_suppress_bold_inverse_default_colors_p
= !NILP (suppress
);
5823 ++face_change_count
;
5829 /***********************************************************************
5831 ***********************************************************************/
5833 /* Return the ID of the face to use to display character CH with face
5834 property PROP on frame F in current_buffer. */
5837 compute_char_face (struct frame
*f
, int ch
, Lisp_Object prop
)
5841 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
5846 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5847 face_id
= FACE_FOR_CHAR (f
, face
, ch
, -1, Qnil
);
5851 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5852 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5853 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
5854 merge_face_ref (f
, prop
, attrs
, 1, 0);
5855 face_id
= lookup_face (f
, attrs
);
5861 /* Return the face ID associated with buffer position POS for
5862 displaying ASCII characters. Return in *ENDPTR the position at
5863 which a different face is needed, as far as text properties and
5864 overlays are concerned. W is a window displaying current_buffer.
5866 REGION_BEG, REGION_END delimit the region, so it can be
5869 LIMIT is a position not to scan beyond. That is to limit the time
5870 this function can take.
5872 If MOUSE is non-zero, use the character's mouse-face, not its face.
5874 BASE_FACE_ID, if non-negative, specifies a base face id to use
5875 instead of DEFAULT_FACE_ID.
5877 The face returned is suitable for displaying ASCII characters. */
5880 face_at_buffer_position (struct window
*w
, ptrdiff_t pos
,
5881 ptrdiff_t *endptr
, ptrdiff_t limit
,
5882 int mouse
, int base_face_id
)
5884 struct frame
*f
= XFRAME (w
->frame
);
5885 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5886 Lisp_Object prop
, position
;
5887 ptrdiff_t i
, noverlays
;
5888 Lisp_Object
*overlay_vec
;
5890 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
5891 Lisp_Object limit1
, end
;
5892 struct face
*default_face
;
5894 /* W must display the current buffer. We could write this function
5895 to use the frame and buffer of W, but right now it doesn't. */
5896 /* eassert (XBUFFER (w->contents) == current_buffer); */
5898 XSETFASTINT (position
, pos
);
5902 /* Get the `face' or `mouse_face' text property at POS, and
5903 determine the next position at which the property changes. */
5904 prop
= Fget_text_property (position
, propname
, w
->contents
);
5905 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
5906 end
= Fnext_single_property_change (position
, propname
, w
->contents
, limit1
);
5908 endpos
= XINT (end
);
5910 /* Look at properties from overlays. */
5913 ptrdiff_t next_overlay
;
5915 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, &next_overlay
, 0);
5916 if (next_overlay
< endpos
)
5917 endpos
= next_overlay
;
5925 if (base_face_id
>= 0)
5926 face_id
= base_face_id
;
5927 else if (NILP (Vface_remapping_alist
))
5928 face_id
= DEFAULT_FACE_ID
;
5930 face_id
= lookup_basic_face (f
, DEFAULT_FACE_ID
);
5932 default_face
= FACE_FROM_ID (f
, face_id
);
5935 /* Optimize common cases where we can use the default face. */
5940 return default_face
->id
;
5943 /* Begin with attributes from the default face. */
5944 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
5946 /* Merge in attributes specified via text properties. */
5948 merge_face_ref (f
, prop
, attrs
, 1, 0);
5950 /* Now merge the overlay data. */
5951 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
5952 for (i
= 0; i
< noverlays
; i
++)
5957 prop
= Foverlay_get (overlay_vec
[i
], propname
);
5959 merge_face_ref (f
, prop
, attrs
, 1, 0);
5961 oend
= OVERLAY_END (overlay_vec
[i
]);
5962 oendpos
= OVERLAY_POSITION (oend
);
5963 if (oendpos
< endpos
)
5971 /* Look up a realized face with the given face attributes,
5972 or realize a new one for ASCII characters. */
5973 return lookup_face (f
, attrs
);
5976 /* Return the face ID at buffer position POS for displaying ASCII
5977 characters associated with overlay strings for overlay OVERLAY.
5979 Like face_at_buffer_position except for OVERLAY. Currently it
5980 simply disregards the `face' properties of all overlays. */
5983 face_for_overlay_string (struct window
*w
, ptrdiff_t pos
,
5984 ptrdiff_t *endptr
, ptrdiff_t limit
,
5985 int mouse
, Lisp_Object overlay
)
5987 struct frame
*f
= XFRAME (w
->frame
);
5988 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5989 Lisp_Object prop
, position
;
5991 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
5992 Lisp_Object limit1
, end
;
5993 struct face
*default_face
;
5995 /* W must display the current buffer. We could write this function
5996 to use the frame and buffer of W, but right now it doesn't. */
5997 /* eassert (XBUFFER (w->contents) == current_buffer); */
5999 XSETFASTINT (position
, pos
);
6003 /* Get the `face' or `mouse_face' text property at POS, and
6004 determine the next position at which the property changes. */
6005 prop
= Fget_text_property (position
, propname
, w
->contents
);
6006 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6007 end
= Fnext_single_property_change (position
, propname
, w
->contents
, limit1
);
6009 endpos
= XINT (end
);
6013 /* Optimize common case where we can use the default face. */
6015 && NILP (Vface_remapping_alist
))
6016 return DEFAULT_FACE_ID
;
6018 /* Begin with attributes from the default face. */
6019 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
6020 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6022 /* Merge in attributes specified via text properties. */
6024 merge_face_ref (f
, prop
, attrs
, 1, 0);
6028 /* Look up a realized face with the given face attributes,
6029 or realize a new one for ASCII characters. */
6030 return lookup_face (f
, attrs
);
6034 /* Compute the face at character position POS in Lisp string STRING on
6035 window W, for ASCII characters.
6037 If STRING is an overlay string, it comes from position BUFPOS in
6038 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
6039 not an overlay string. W must display the current buffer.
6040 REGION_BEG and REGION_END give the start and end positions of the
6041 region; both are -1 if no region is visible.
6043 BASE_FACE_ID is the id of a face to merge with. For strings coming
6044 from overlays or the `display' property it is the face at BUFPOS.
6046 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
6048 Set *ENDPTR to the next position where to check for faces in
6049 STRING; -1 if the face is constant from POS to the end of the
6052 Value is the id of the face to use. The face returned is suitable
6053 for displaying ASCII characters. */
6056 face_at_string_position (struct window
*w
, Lisp_Object string
,
6057 ptrdiff_t pos
, ptrdiff_t bufpos
,
6058 ptrdiff_t *endptr
, enum face_id base_face_id
,
6061 Lisp_Object prop
, position
, end
, limit
;
6062 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6063 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6064 struct face
*base_face
;
6065 bool multibyte_p
= STRING_MULTIBYTE (string
);
6066 Lisp_Object prop_name
= mouse_p
? Qmouse_face
: Qface
;
6068 /* Get the value of the face property at the current position within
6069 STRING. Value is nil if there is no face property. */
6070 XSETFASTINT (position
, pos
);
6071 prop
= Fget_text_property (position
, prop_name
, string
);
6073 /* Get the next position at which to check for faces. Value of end
6074 is nil if face is constant all the way to the end of the string.
6075 Otherwise it is a string position where to check faces next.
6076 Limit is the maximum position up to which to check for property
6077 changes in Fnext_single_property_change. Strings are usually
6078 short, so set the limit to the end of the string. */
6079 XSETFASTINT (limit
, SCHARS (string
));
6080 end
= Fnext_single_property_change (position
, prop_name
, string
, limit
);
6082 *endptr
= XFASTINT (end
);
6086 base_face
= FACE_FROM_ID (f
, base_face_id
);
6087 eassert (base_face
);
6089 /* Optimize the default case that there is no face property. */
6092 /* We can't realize faces for different charsets differently
6093 if we don't have fonts, so we can stop here if not working
6094 on a window-system frame. */
6095 || !FRAME_WINDOW_P (f
)
6096 || FACE_SUITABLE_FOR_ASCII_CHAR_P (base_face
, 0)))
6097 return base_face
->id
;
6099 /* Begin with attributes from the base face. */
6100 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6102 /* Merge in attributes specified via text properties. */
6104 merge_face_ref (f
, prop
, attrs
, 1, 0);
6106 /* Look up a realized face with the given face attributes,
6107 or realize a new one for ASCII characters. */
6108 return lookup_face (f
, attrs
);
6112 /* Merge a face into a realized face.
6114 F is frame where faces are (to be) realized.
6116 FACE_NAME is named face to merge.
6118 If FACE_NAME is nil, FACE_ID is face_id of realized face to merge.
6120 If FACE_NAME is t, FACE_ID is lface_id of face to merge.
6122 BASE_FACE_ID is realized face to merge into.
6128 merge_faces (struct frame
*f
, Lisp_Object face_name
, int face_id
,
6131 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6132 struct face
*base_face
;
6134 base_face
= FACE_FROM_ID (f
, base_face_id
);
6136 return base_face_id
;
6138 if (EQ (face_name
, Qt
))
6140 if (face_id
< 0 || face_id
>= lface_id_to_name_size
)
6141 return base_face_id
;
6142 face_name
= lface_id_to_name
[face_id
];
6143 /* When called during make-frame, lookup_derived_face may fail
6144 if the faces are uninitialized. Don't signal an error. */
6145 face_id
= lookup_derived_face (f
, face_name
, base_face_id
, 0);
6146 return (face_id
>= 0 ? face_id
: base_face_id
);
6149 /* Begin with attributes from the base face. */
6150 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6152 if (!NILP (face_name
))
6154 if (!merge_named_face (f
, face_name
, attrs
, 0))
6155 return base_face_id
;
6161 return base_face_id
;
6162 face
= FACE_FROM_ID (f
, face_id
);
6164 return base_face_id
;
6165 merge_face_vectors (f
, face
->lface
, attrs
, 0);
6168 /* Look up a realized face with the given face attributes,
6169 or realize a new one for ASCII characters. */
6170 return lookup_face (f
, attrs
);
6175 #ifndef HAVE_X_WINDOWS
6176 DEFUN ("x-load-color-file", Fx_load_color_file
,
6177 Sx_load_color_file
, 1, 1, 0,
6178 doc
: /* Create an alist of color entries from an external file.
6180 The file should define one named RGB color per line like so:
6182 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6183 (Lisp_Object filename
)
6186 Lisp_Object cmap
= Qnil
;
6187 Lisp_Object abspath
;
6189 CHECK_STRING (filename
);
6190 abspath
= Fexpand_file_name (filename
, Qnil
);
6193 fp
= emacs_fopen (SSDATA (abspath
), "rt");
6197 int red
, green
, blue
;
6200 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
6201 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
6204 int color
= RGB (red
, green
, blue
);
6206 int color
= (red
<< 16) | (green
<< 8) | blue
;
6208 char *name
= buf
+ num
;
6209 ptrdiff_t len
= strlen (name
);
6210 len
-= 0 < len
&& name
[len
- 1] == '\n';
6211 cmap
= Fcons (Fcons (make_string (name
, len
), make_number (color
)),
6223 /***********************************************************************
6225 ***********************************************************************/
6229 /* Print the contents of the realized face FACE to stderr. */
6232 dump_realized_face (struct face
*face
)
6234 fprintf (stderr
, "ID: %d\n", face
->id
);
6235 #ifdef HAVE_X_WINDOWS
6236 fprintf (stderr
, "gc: %p\n", face
->gc
);
6238 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
6240 SDATA (face
->lface
[LFACE_FOREGROUND_INDEX
]));
6241 fprintf (stderr
, "background: 0x%lx (%s)\n",
6243 SDATA (face
->lface
[LFACE_BACKGROUND_INDEX
]));
6245 fprintf (stderr
, "font_name: %s (%s)\n",
6246 SDATA (face
->font
->props
[FONT_NAME_INDEX
]),
6247 SDATA (face
->lface
[LFACE_FAMILY_INDEX
]));
6248 #ifdef HAVE_X_WINDOWS
6249 fprintf (stderr
, "font = %p\n", face
->font
);
6251 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
6252 fprintf (stderr
, "underline: %d (%s)\n",
6254 SDATA (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
])));
6255 fprintf (stderr
, "hash: %d\n", face
->hash
);
6259 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, doc
: /* */)
6266 fprintf (stderr
, "font selection order: ");
6267 for (i
= 0; i
< ARRAYELTS (font_sort_order
); ++i
)
6268 fprintf (stderr
, "%d ", font_sort_order
[i
]);
6269 fprintf (stderr
, "\n");
6271 fprintf (stderr
, "alternative fonts: ");
6272 debug_print (Vface_alternative_font_family_alist
);
6273 fprintf (stderr
, "\n");
6275 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
6276 Fdump_face (make_number (i
));
6282 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
6284 error ("Not a valid face");
6285 dump_realized_face (face
);
6292 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
6293 0, 0, 0, doc
: /* */)
6296 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
6297 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
6298 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
6302 #endif /* GLYPH_DEBUG */
6306 /***********************************************************************
6308 ***********************************************************************/
6311 syms_of_xfaces (void)
6313 /* The symbols `face' and `mouse-face' used as text properties. */
6314 DEFSYM (Qface
, "face");
6316 /* Property for basic faces which other faces cannot inherit. */
6317 DEFSYM (Qface_no_inherit
, "face-no-inherit");
6319 /* Error symbol for wrong_type_argument in load_pixmap. */
6320 DEFSYM (Qbitmap_spec_p
, "bitmap-spec-p");
6322 /* The name of the function to call when the background of the frame
6323 has changed, frame_set_background_mode. */
6324 DEFSYM (Qframe_set_background_mode
, "frame-set-background-mode");
6326 /* Lisp face attribute keywords. */
6327 DEFSYM (QCfamily
, ":family");
6328 DEFSYM (QCheight
, ":height");
6329 DEFSYM (QCweight
, ":weight");
6330 DEFSYM (QCslant
, ":slant");
6331 DEFSYM (QCunderline
, ":underline");
6332 DEFSYM (QCinverse_video
, ":inverse-video");
6333 DEFSYM (QCreverse_video
, ":reverse-video");
6334 DEFSYM (QCforeground
, ":foreground");
6335 DEFSYM (QCbackground
, ":background");
6336 DEFSYM (QCstipple
, ":stipple");
6337 DEFSYM (QCwidth
, ":width");
6338 DEFSYM (QCfont
, ":font");
6339 DEFSYM (QCfontset
, ":fontset");
6340 DEFSYM (QCdistant_foreground
, ":distant-foreground");
6341 DEFSYM (QCbold
, ":bold");
6342 DEFSYM (QCitalic
, ":italic");
6343 DEFSYM (QCoverline
, ":overline");
6344 DEFSYM (QCstrike_through
, ":strike-through");
6345 DEFSYM (QCbox
, ":box");
6346 DEFSYM (QCinherit
, ":inherit");
6348 /* Symbols used for Lisp face attribute values. */
6349 DEFSYM (QCcolor
, ":color");
6350 DEFSYM (QCline_width
, ":line-width");
6351 DEFSYM (QCstyle
, ":style");
6352 DEFSYM (Qline
, "line");
6353 DEFSYM (Qwave
, "wave");
6354 DEFSYM (Qreleased_button
, "released-button");
6355 DEFSYM (Qpressed_button
, "pressed-button");
6356 DEFSYM (Qnormal
, "normal");
6357 DEFSYM (Qextra_light
, "extra-light");
6358 DEFSYM (Qlight
, "light");
6359 DEFSYM (Qsemi_light
, "semi-light");
6360 DEFSYM (Qsemi_bold
, "semi-bold");
6361 DEFSYM (Qbold
, "bold");
6362 DEFSYM (Qextra_bold
, "extra-bold");
6363 DEFSYM (Qultra_bold
, "ultra-bold");
6364 DEFSYM (Qoblique
, "oblique");
6365 DEFSYM (Qitalic
, "italic");
6367 /* The symbols `foreground-color' and `background-color' which can be
6368 used as part of a `face' property. This is for compatibility with
6370 DEFSYM (Qbackground_color
, "background-color");
6371 DEFSYM (Qforeground_color
, "foreground-color");
6373 DEFSYM (Qunspecified
, "unspecified");
6374 DEFSYM (QCignore_defface
, ":ignore-defface");
6376 /* The symbol `face-alias'. A symbol having that property is an
6377 alias for another face. Value of the property is the name of
6378 the aliased face. */
6379 DEFSYM (Qface_alias
, "face-alias");
6381 /* Names of basic faces. */
6382 DEFSYM (Qdefault
, "default");
6383 DEFSYM (Qtool_bar
, "tool-bar");
6384 DEFSYM (Qregion
, "region");
6385 DEFSYM (Qfringe
, "fringe");
6386 DEFSYM (Qheader_line
, "header-line");
6387 DEFSYM (Qscroll_bar
, "scroll-bar");
6388 DEFSYM (Qmenu
, "menu");
6389 DEFSYM (Qcursor
, "cursor");
6390 DEFSYM (Qborder
, "border");
6391 DEFSYM (Qmouse
, "mouse");
6392 DEFSYM (Qmode_line_inactive
, "mode-line-inactive");
6393 DEFSYM (Qvertical_border
, "vertical-border");
6395 /* TTY color-related functions (defined in tty-colors.el). */
6396 DEFSYM (Qwindow_divider
, "window-divider");
6397 DEFSYM (Qwindow_divider_first_pixel
, "window-divider-first-pixel");
6398 DEFSYM (Qwindow_divider_last_pixel
, "window-divider-last-pixel");
6399 DEFSYM (Qtty_color_desc
, "tty-color-desc");
6400 DEFSYM (Qtty_color_standard_values
, "tty-color-standard-values");
6401 DEFSYM (Qtty_color_by_index
, "tty-color-by-index");
6403 /* The name of the function used to compute colors on TTYs. */
6404 DEFSYM (Qtty_color_alist
, "tty-color-alist");
6406 /* Allowed scalable fonts. A value of nil means don't allow any
6407 scalable fonts. A value of t means allow the use of any scalable
6408 font. Otherwise, value must be a list of regular expressions. A
6409 font may be scaled if its name matches a regular expression in the
6411 DEFSYM (Qscalable_fonts_allowed
, "scalable-fonts-allowed");
6413 Vparam_value_alist
= list1 (Fcons (Qnil
, Qnil
));
6414 staticpro (&Vparam_value_alist
);
6415 Vface_alternative_font_family_alist
= Qnil
;
6416 staticpro (&Vface_alternative_font_family_alist
);
6417 Vface_alternative_font_registry_alist
= Qnil
;
6418 staticpro (&Vface_alternative_font_registry_alist
);
6420 defsubr (&Sinternal_make_lisp_face
);
6421 defsubr (&Sinternal_lisp_face_p
);
6422 defsubr (&Sinternal_set_lisp_face_attribute
);
6423 #ifdef HAVE_WINDOW_SYSTEM
6424 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
6426 defsubr (&Scolor_gray_p
);
6427 defsubr (&Scolor_supported_p
);
6428 #ifndef HAVE_X_WINDOWS
6429 defsubr (&Sx_load_color_file
);
6431 defsubr (&Sface_attribute_relative_p
);
6432 defsubr (&Smerge_face_attribute
);
6433 defsubr (&Sinternal_get_lisp_face_attribute
);
6434 defsubr (&Sinternal_lisp_face_attribute_values
);
6435 defsubr (&Sinternal_lisp_face_equal_p
);
6436 defsubr (&Sinternal_lisp_face_empty_p
);
6437 defsubr (&Sinternal_copy_lisp_face
);
6438 defsubr (&Sinternal_merge_in_global_face
);
6439 defsubr (&Sface_font
);
6440 defsubr (&Sframe_face_alist
);
6441 defsubr (&Sdisplay_supports_face_attributes_p
);
6442 defsubr (&Scolor_distance
);
6443 defsubr (&Sinternal_set_font_selection_order
);
6444 defsubr (&Sinternal_set_alternative_font_family_alist
);
6445 defsubr (&Sinternal_set_alternative_font_registry_alist
);
6446 defsubr (&Sface_attributes_as_vector
);
6448 defsubr (&Sdump_face
);
6449 defsubr (&Sshow_face_resources
);
6450 #endif /* GLYPH_DEBUG */
6451 defsubr (&Sclear_face_cache
);
6452 defsubr (&Stty_suppress_bold_inverse_default_colors
);
6454 #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS
6455 defsubr (&Sdump_colors
);
6458 DEFVAR_LISP ("face-new-frame-defaults", Vface_new_frame_defaults
,
6459 doc
: /* List of global face definitions (for internal use only.) */);
6460 Vface_new_frame_defaults
= Qnil
;
6462 DEFVAR_LISP ("face-default-stipple", Vface_default_stipple
,
6463 doc
: /* Default stipple pattern used on monochrome displays.
6464 This stipple pattern is used on monochrome displays
6465 instead of shades of gray for a face background color.
6466 See `set-face-stipple' for possible values for this variable. */);
6467 Vface_default_stipple
= build_pure_c_string ("gray3");
6469 DEFVAR_LISP ("tty-defined-color-alist", Vtty_defined_color_alist
,
6470 doc
: /* An alist of defined terminal colors and their RGB values.
6471 See the docstring of `tty-color-alist' for the details. */);
6472 Vtty_defined_color_alist
= Qnil
;
6474 DEFVAR_LISP ("scalable-fonts-allowed", Vscalable_fonts_allowed
,
6475 doc
: /* Allowed scalable fonts.
6476 A value of nil means don't allow any scalable fonts.
6477 A value of t means allow any scalable font.
6478 Otherwise, value must be a list of regular expressions. A font may be
6479 scaled if its name matches a regular expression in the list.
6480 Note that if value is nil, a scalable font might still be used, if no
6481 other font of the appropriate family and registry is available. */);
6482 Vscalable_fonts_allowed
= Qnil
;
6484 DEFVAR_LISP ("face-ignored-fonts", Vface_ignored_fonts
,
6485 doc
: /* List of ignored fonts.
6486 Each element is a regular expression that matches names of fonts to
6488 Vface_ignored_fonts
= Qnil
;
6490 DEFVAR_LISP ("face-remapping-alist", Vface_remapping_alist
,
6491 doc
: /* Alist of face remappings.
6492 Each element is of the form:
6494 (FACE . REPLACEMENT),
6496 which causes display of the face FACE to use REPLACEMENT instead.
6497 REPLACEMENT is a face specification, i.e. one of the following:
6500 (2) a property list of attribute/value pairs, or
6501 (3) a list in which each element has the form of (1) or (2).
6503 List values for REPLACEMENT are merged to form the final face
6504 specification, with earlier entries taking precedence, in the same as
6505 as in the `face' text property.
6507 Face-name remapping cycles are suppressed; recursive references use
6508 the underlying face instead of the remapped face. So a remapping of
6511 (FACE EXTRA-FACE... FACE)
6515 (FACE (FACE-ATTR VAL ...) FACE)
6517 causes EXTRA-FACE... or (FACE-ATTR VAL ...) to be _merged_ with the
6518 existing definition of FACE. Note that this isn't necessary for the
6519 default face, since every face inherits from the default face.
6521 If this variable is made buffer-local, the face remapping takes effect
6522 only in that buffer. For instance, the mode my-mode could define a
6523 face `my-mode-default', and then in the mode setup function, do:
6525 (set (make-local-variable 'face-remapping-alist)
6526 '((default my-mode-default)))).
6528 Because Emacs normally only redraws screen areas when the underlying
6529 buffer contents change, you may need to call `redraw-display' after
6530 changing this variable for it to take effect. */);
6531 Vface_remapping_alist
= Qnil
;
6533 DEFVAR_LISP ("face-font-rescale-alist", Vface_font_rescale_alist
,
6534 doc
: /* Alist of fonts vs the rescaling factors.
6535 Each element is a cons (FONT-PATTERN . RESCALE-RATIO), where
6536 FONT-PATTERN is a font-spec or a regular expression matching a font name, and
6537 RESCALE-RATIO is a floating point number to specify how much larger
6538 \(or smaller) font we should use. For instance, if a face requests
6539 a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point. */);
6540 Vface_font_rescale_alist
= Qnil
;
6542 #ifdef HAVE_WINDOW_SYSTEM
6543 defsubr (&Sbitmap_spec_p
);
6544 defsubr (&Sx_list_fonts
);
6545 defsubr (&Sinternal_face_x_get_resource
);
6546 defsubr (&Sx_family_fonts
);