1 /* xfaces.c -- "Face" primitives.
3 Copyright (C) 1993-1994, 1998-2011 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New face implementation by Gerd Moellmann <gerd@gnu.org>. */
24 When using Emacs with X, the display style of characters can be
25 changed by defining `faces'. Each face can specify the following
30 2. Font foundary name.
32 3. Relative proportionate width, aka character set width or set
33 width (swidth), e.g. `semi-compressed'.
35 4. Font height in 1/10pt.
37 5. Font weight, e.g. `bold'.
39 6. Font slant, e.g. `italic'.
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 correspoinding specs in this attribute is set to nil.
71 15. A face name or list of face names from which to inherit attributes.
73 16. A specified average font width, which is invisible from Lisp,
74 and is used to ensure that a font specified on the command line,
75 for example, can be matched exactly.
77 17. A fontset name. This is another special attribute.
79 A fontset is a mappings from characters to font-specs, and the
80 specs overwrite the font-spec in the 14th attribute.
83 Faces are frame-local by nature because Emacs allows to define the
84 same named face (face names are symbols) differently for different
85 frames. Each frame has an alist of face definitions for all named
86 faces. The value of a named face in such an alist is a Lisp vector
87 with the symbol `face' in slot 0, and a slot for each of the face
88 attributes mentioned above.
90 There is also a global face alist `Vface_new_frame_defaults'. Face
91 definitions from this list are used to initialize faces of newly
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 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. */
204 #include <sys/types.h>
205 #include <sys/stat.h>
206 #include <stdio.h> /* This needs to be before termchar.h */
210 #include "character.h"
212 #include "keyboard.h"
214 #include "termhooks.h"
216 #ifdef HAVE_X_WINDOWS
220 #include <Xm/XmStrDefs.h>
221 #endif /* USE_MOTIF */
222 #endif /* HAVE_X_WINDOWS */
231 /* Redefine X specifics to W32 equivalents to avoid cluttering the
232 code with #ifdef blocks. */
233 #undef FRAME_X_DISPLAY_INFO
234 #define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO
235 #define x_display_info w32_display_info
236 #define FRAME_X_FONT_TABLE FRAME_W32_FONT_TABLE
237 #define check_x check_w32
238 #define GCGraphicsExposures 0
239 #endif /* WINDOWSNT */
243 #undef FRAME_X_DISPLAY_INFO
244 #define FRAME_X_DISPLAY_INFO FRAME_NS_DISPLAY_INFO
245 #define x_display_info ns_display_info
246 #define FRAME_X_FONT_TABLE FRAME_NS_FONT_TABLE
247 #define check_x check_ns
248 #define GCGraphicsExposures 0
252 #include "dispextern.h"
253 #include "blockinput.h"
255 #include "intervals.h"
256 #include "termchar.h"
259 #ifdef HAVE_WINDOW_SYSTEM
261 #endif /* HAVE_WINDOW_SYSTEM */
263 #ifdef HAVE_X_WINDOWS
265 /* Compensate for a bug in Xos.h on some systems, on which it requires
266 time.h. On some such systems, Xos.h tries to redefine struct
267 timeval and struct timezone if USG is #defined while it is
270 #ifdef XOS_NEEDS_TIME_H
276 #else /* not XOS_NEEDS_TIME_H */
278 #endif /* not XOS_NEEDS_TIME_H */
280 #endif /* HAVE_X_WINDOWS */
284 /* Number of pt per inch (from the TeXbook). */
286 #define PT_PER_INCH 72.27
288 /* Non-zero if face attribute ATTR is unspecified. */
290 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified)
292 /* Non-zero if face attribute ATTR is `ignore-defface'. */
294 #define IGNORE_DEFFACE_P(ATTR) EQ ((ATTR), Qignore_defface)
296 /* Value is the number of elements of VECTOR. */
298 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
300 /* Make a copy of string S on the stack using alloca. Value is a pointer
303 #define STRDUPA(S) strcpy ((char *) alloca (strlen ((S)) + 1), (S))
305 /* Make a copy of the contents of Lisp string S on the stack using
306 alloca. Value is a pointer to the copy. */
308 #define LSTRDUPA(S) STRDUPA (SDATA ((S)))
310 /* Size of hash table of realized faces in face caches (should be a
313 #define FACE_CACHE_BUCKETS_SIZE 1001
315 /* Keyword symbols used for face attribute names. */
317 Lisp_Object QCfamily
, QCheight
, QCweight
, QCslant
, QCunderline
;
318 Lisp_Object QCinverse_video
, QCforeground
, QCbackground
, QCstipple
;
319 Lisp_Object QCwidth
, QCfont
, QCbold
, QCitalic
;
320 Lisp_Object QCreverse_video
;
321 Lisp_Object QCoverline
, QCstrike_through
, QCbox
, QCinherit
;
322 Lisp_Object QCfontset
;
324 /* Symbols used for attribute values. */
326 Lisp_Object Qnormal
, Qbold
, Qultra_light
, Qextra_light
, Qlight
;
327 Lisp_Object Qsemi_light
, Qsemi_bold
, Qextra_bold
, Qultra_bold
;
328 Lisp_Object Qoblique
, Qitalic
, Qreverse_oblique
, Qreverse_italic
;
329 Lisp_Object Qultra_condensed
, Qextra_condensed
, Qcondensed
;
330 Lisp_Object Qsemi_condensed
, Qsemi_expanded
, Qexpanded
, Qextra_expanded
;
331 Lisp_Object Qultra_expanded
;
332 Lisp_Object Qreleased_button
, Qpressed_button
;
333 Lisp_Object QCstyle
, QCcolor
, QCline_width
;
334 Lisp_Object Qunspecified
;
335 Lisp_Object Qignore_defface
;
337 char unspecified_fg
[] = "unspecified-fg", unspecified_bg
[] = "unspecified-bg";
339 /* The name of the function to call when the background of the frame
340 has changed, frame_set_background_mode. */
342 Lisp_Object Qframe_set_background_mode
;
344 /* Names of basic faces. */
346 Lisp_Object Qdefault
, Qtool_bar
, Qregion
, Qfringe
;
347 Lisp_Object Qheader_line
, Qscroll_bar
, Qcursor
, Qborder
, Qmouse
, Qmenu
;
348 Lisp_Object Qmode_line_inactive
, Qvertical_border
;
350 /* The symbol `face-alias'. A symbols having that property is an
351 alias for another face. Value of the property is the name of
354 Lisp_Object Qface_alias
;
356 /* Alist of alternative font families. Each element is of the form
357 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
358 try FAMILY1, then FAMILY2, ... */
360 Lisp_Object Vface_alternative_font_family_alist
;
362 /* Alist of alternative font registries. Each element is of the form
363 (REGISTRY REGISTRY1 REGISTRY2...). If fonts of REGISTRY can't be
364 loaded, try REGISTRY1, then REGISTRY2, ... */
366 Lisp_Object Vface_alternative_font_registry_alist
;
368 /* Allowed scalable fonts. A value of nil means don't allow any
369 scalable fonts. A value of t means allow the use of any scalable
370 font. Otherwise, value must be a list of regular expressions. A
371 font may be scaled if its name matches a regular expression in the
374 Lisp_Object Qscalable_fonts_allowed
;
376 #define DEFAULT_FONT_LIST_LIMIT 100
378 /* The symbols `foreground-color' and `background-color' which can be
379 used as part of a `face' property. This is for compatibility with
382 Lisp_Object Qforeground_color
, Qbackground_color
;
384 /* The symbols `face' and `mouse-face' used as text properties. */
388 /* Property for basic faces which other faces cannot inherit. */
390 Lisp_Object Qface_no_inherit
;
392 /* Error symbol for wrong_type_argument in load_pixmap. */
394 Lisp_Object Qbitmap_spec_p
;
396 /* The next ID to assign to Lisp faces. */
398 static int next_lface_id
;
400 /* A vector mapping Lisp face Id's to face names. */
402 static Lisp_Object
*lface_id_to_name
;
403 static int lface_id_to_name_size
;
405 /* TTY color-related functions (defined in tty-colors.el). */
407 Lisp_Object Qtty_color_desc
, Qtty_color_by_index
, Qtty_color_standard_values
;
409 /* The name of the function used to compute colors on TTYs. */
411 Lisp_Object Qtty_color_alist
;
413 /* Counter for calls to clear_face_cache. If this counter reaches
414 CLEAR_FONT_TABLE_COUNT, and a frame has more than
415 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
417 static int clear_font_table_count
;
418 #define CLEAR_FONT_TABLE_COUNT 100
419 #define CLEAR_FONT_TABLE_NFONTS 10
421 /* Non-zero means face attributes have been changed since the last
422 redisplay. Used in redisplay_internal. */
424 int face_change_count
;
426 /* Non-zero means don't display bold text if a face's foreground
427 and background colors are the inverse of the default colors of the
428 display. This is a kluge to suppress `bold black' foreground text
429 which is hard to read on an LCD monitor. */
431 int tty_suppress_bold_inverse_default_colors_p
;
433 /* A list of the form `((x . y))' used to avoid consing in
434 Finternal_set_lisp_face_attribute. */
436 static Lisp_Object Vparam_value_alist
;
438 /* The total number of colors currently allocated. */
441 static int ncolors_allocated
;
442 static int npixmaps_allocated
;
446 /* Non-zero means the definition of the `menu' face for new frames has
449 int menu_face_changed_default
;
452 /* Function prototypes. */
455 struct named_merge_point
;
457 static void map_tty_color (struct frame
*, struct face
*,
458 enum lface_attribute_index
, int *);
459 static Lisp_Object
resolve_face_name (Lisp_Object
, int);
460 static void set_font_frame_param (Lisp_Object
, Lisp_Object
);
461 static int get_lface_attributes (struct frame
*, Lisp_Object
, Lisp_Object
*,
462 int, struct named_merge_point
*);
463 static int load_pixmap (struct frame
*, Lisp_Object
, unsigned *, unsigned *);
464 static struct frame
*frame_or_selected_frame (Lisp_Object
, int);
465 static void load_face_colors (struct frame
*, struct face
*, Lisp_Object
*);
466 static void free_face_colors (struct frame
*, struct face
*);
467 static int face_color_gray_p (struct frame
*, const char *);
468 static struct face
*realize_face (struct face_cache
*, Lisp_Object
*,
470 static struct face
*realize_non_ascii_face (struct frame
*, Lisp_Object
,
472 static struct face
*realize_x_face (struct face_cache
*, Lisp_Object
*);
473 static struct face
*realize_tty_face (struct face_cache
*, Lisp_Object
*);
474 static int realize_basic_faces (struct frame
*);
475 static int realize_default_face (struct frame
*);
476 static void realize_named_face (struct frame
*, Lisp_Object
, int);
477 static int lface_fully_specified_p (Lisp_Object
*);
478 static int lface_equal_p (Lisp_Object
*, Lisp_Object
*);
479 static unsigned hash_string_case_insensitive (Lisp_Object
);
480 static unsigned lface_hash (Lisp_Object
*);
481 static int lface_same_font_attributes_p (Lisp_Object
*, Lisp_Object
*);
482 static struct face_cache
*make_face_cache (struct frame
*);
483 static void clear_face_gcs (struct face_cache
*);
484 static void free_face_cache (struct face_cache
*);
485 static int face_fontset (Lisp_Object
*);
486 static void merge_face_vectors (struct frame
*, Lisp_Object
*, Lisp_Object
*,
487 struct named_merge_point
*);
488 static int merge_face_ref (struct frame
*, Lisp_Object
, Lisp_Object
*,
489 int, struct named_merge_point
*);
490 static int set_lface_from_font (struct frame
*, Lisp_Object
, Lisp_Object
,
492 static Lisp_Object
lface_from_face_name (struct frame
*, Lisp_Object
, int);
493 static struct face
*make_realized_face (Lisp_Object
*);
494 static void cache_face (struct face_cache
*, struct face
*, unsigned);
495 static void uncache_face (struct face_cache
*, struct face
*);
497 #ifdef HAVE_WINDOW_SYSTEM
499 static GC
x_create_gc (struct frame
*, unsigned long, XGCValues
*);
500 static void x_free_gc (struct frame
*, GC
);
503 static void x_update_menu_appearance (struct frame
*);
505 extern void free_frame_menubar (struct frame
*);
506 #endif /* USE_X_TOOLKIT */
508 #endif /* HAVE_WINDOW_SYSTEM */
511 /***********************************************************************
513 ***********************************************************************/
515 #ifdef HAVE_X_WINDOWS
517 #ifdef DEBUG_X_COLORS
519 /* The following is a poor mans infrastructure for debugging X color
520 allocation problems on displays with PseudoColor-8. Some X servers
521 like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement
522 color reference counts completely so that they don't signal an
523 error when a color is freed whose reference count is already 0.
524 Other X servers do. To help me debug this, the following code
525 implements a simple reference counting schema of its own, for a
526 single display/screen. --gerd. */
528 /* Reference counts for pixel colors. */
530 int color_count
[256];
532 /* Register color PIXEL as allocated. */
535 register_color (pixel
)
538 xassert (pixel
< 256);
539 ++color_count
[pixel
];
543 /* Register color PIXEL as deallocated. */
546 unregister_color (pixel
)
549 xassert (pixel
< 256);
550 if (color_count
[pixel
] > 0)
551 --color_count
[pixel
];
557 /* Register N colors from PIXELS as deallocated. */
560 unregister_colors (pixels
, n
)
561 unsigned long *pixels
;
565 for (i
= 0; i
< n
; ++i
)
566 unregister_color (pixels
[i
]);
570 DEFUN ("dump-colors", Fdump_colors
, Sdump_colors
, 0, 0, 0,
571 doc
: /* Dump currently allocated colors to stderr. */)
576 fputc ('\n', stderr
);
578 for (i
= n
= 0; i
< sizeof color_count
/ sizeof color_count
[0]; ++i
)
581 fprintf (stderr
, "%3d: %5d", i
, color_count
[i
]);
584 fputc ('\n', stderr
);
586 fputc ('\t', stderr
);
590 fputc ('\n', stderr
);
594 #endif /* DEBUG_X_COLORS */
597 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
598 color values. Interrupt input must be blocked when this function
602 x_free_colors (struct frame
*f
, long unsigned int *pixels
, int npixels
)
604 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
606 /* If display has an immutable color map, freeing colors is not
607 necessary and some servers don't allow it. So don't do it. */
608 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
610 #ifdef DEBUG_X_COLORS
611 unregister_colors (pixels
, npixels
);
613 XFreeColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
619 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
620 color values. Interrupt input must be blocked when this function
624 x_free_dpy_colors (Display
*dpy
, Screen
*screen
, Colormap cmap
, long unsigned int *pixels
, int npixels
)
626 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
627 int class = dpyinfo
->visual
->class;
629 /* If display has an immutable color map, freeing colors is not
630 necessary and some servers don't allow it. So don't do it. */
631 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
633 #ifdef DEBUG_X_COLORS
634 unregister_colors (pixels
, npixels
);
636 XFreeColors (dpy
, cmap
, pixels
, npixels
, 0);
641 /* Create and return a GC for use on frame F. GC values and mask
642 are given by XGCV and MASK. */
645 x_create_gc (struct frame
*f
, long unsigned int mask
, XGCValues
*xgcv
)
649 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
656 /* Free GC which was used on frame F. */
659 x_free_gc (struct frame
*f
, GC gc
)
661 eassert (interrupt_input_blocked
);
662 IF_DEBUG (xassert (--ngcs
>= 0));
663 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
666 #endif /* HAVE_X_WINDOWS */
669 /* W32 emulation of GCs */
672 x_create_gc (struct frame
*f
, unsigned long mask
, XGCValues
*xgcv
)
676 gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, xgcv
);
683 /* Free GC which was used on frame F. */
686 x_free_gc (struct frame
*f
, GC gc
)
688 IF_DEBUG (xassert (--ngcs
>= 0));
692 #endif /* WINDOWSNT */
695 /* NS emulation of GCs */
698 x_create_gc (struct frame
*f
,
702 GC gc
= xmalloc (sizeof (*gc
));
704 memcpy (gc
, xgcv
, sizeof (XGCValues
));
709 x_free_gc (struct frame
*f
, GC gc
)
715 /* Like strcasecmp/stricmp. Used to compare parts of font names which
719 xstrcasecmp (const char *s1
, const char *s2
)
723 unsigned char b1
= *s1
;
724 unsigned char b2
= *s2
;
725 unsigned char c1
= tolower (b1
);
726 unsigned char c2
= tolower (b2
);
728 return c1
< c2
? -1 : 1;
733 return *s2
== 0 ? 0 : -1;
738 /* If FRAME is nil, return a pointer to the selected frame.
739 Otherwise, check that FRAME is a live frame, and return a pointer
740 to it. NPARAM is the parameter number of FRAME, for
741 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
742 Lisp function definitions. */
744 static INLINE
struct frame
*
745 frame_or_selected_frame (Lisp_Object frame
, int nparam
)
748 frame
= selected_frame
;
750 CHECK_LIVE_FRAME (frame
);
751 return XFRAME (frame
);
755 /***********************************************************************
757 ***********************************************************************/
759 /* Initialize face cache and basic faces for frame F. */
762 init_frame_faces (struct frame
*f
)
764 /* Make a face cache, if F doesn't have one. */
765 if (FRAME_FACE_CACHE (f
) == NULL
)
766 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
768 #ifdef HAVE_WINDOW_SYSTEM
769 /* Make the image cache. */
770 if (FRAME_WINDOW_P (f
))
772 /* We initialize the image cache when creating the first frame
773 on a terminal, and not during terminal creation. This way,
774 `x-open-connection' on a tty won't create an image cache. */
775 if (FRAME_IMAGE_CACHE (f
) == NULL
)
776 FRAME_IMAGE_CACHE (f
) = make_image_cache ();
777 ++FRAME_IMAGE_CACHE (f
)->refcount
;
779 #endif /* HAVE_WINDOW_SYSTEM */
781 /* Realize basic faces. Must have enough information in frame
782 parameters to realize basic faces at this point. */
783 #ifdef HAVE_X_WINDOWS
784 if (!FRAME_X_P (f
) || FRAME_X_WINDOW (f
))
787 if (!FRAME_WINDOW_P (f
) || FRAME_W32_WINDOW (f
))
790 if (!FRAME_NS_P (f
) || FRAME_NS_WINDOW (f
))
792 if (!realize_basic_faces (f
))
797 /* Free face cache of frame F. Called from delete_frame. */
800 free_frame_faces (struct frame
*f
)
802 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
806 free_face_cache (face_cache
);
807 FRAME_FACE_CACHE (f
) = NULL
;
810 #ifdef HAVE_WINDOW_SYSTEM
811 if (FRAME_WINDOW_P (f
))
813 struct image_cache
*image_cache
= FRAME_IMAGE_CACHE (f
);
816 --image_cache
->refcount
;
817 if (image_cache
->refcount
== 0)
818 free_image_cache (f
);
821 #endif /* HAVE_WINDOW_SYSTEM */
825 /* Clear face caches, and recompute basic faces for frame F. Call
826 this after changing frame parameters on which those faces depend,
827 or when realized faces have been freed due to changing attributes
831 recompute_basic_faces (struct frame
*f
)
833 if (FRAME_FACE_CACHE (f
))
835 clear_face_cache (0);
836 if (!realize_basic_faces (f
))
842 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
843 try to free unused fonts, too. */
846 clear_face_cache (int clear_fonts_p
)
848 #ifdef HAVE_WINDOW_SYSTEM
849 Lisp_Object tail
, frame
;
852 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
855 /* Not yet implemented. */
856 clear_font_cache (frame
);
859 /* From time to time see if we can unload some fonts. This also
860 frees all realized faces on all frames. Fonts needed by
861 faces will be loaded again when faces are realized again. */
862 clear_font_table_count
= 0;
864 FOR_EACH_FRAME (tail
, frame
)
866 struct frame
*f
= XFRAME (frame
);
867 if (FRAME_WINDOW_P (f
)
868 && FRAME_X_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
869 free_all_realized_faces (frame
);
874 /* Clear GCs of realized faces. */
875 FOR_EACH_FRAME (tail
, frame
)
877 struct frame
*f
= XFRAME (frame
);
878 if (FRAME_WINDOW_P (f
))
879 clear_face_gcs (FRAME_FACE_CACHE (f
));
881 clear_image_caches (Qnil
);
883 #endif /* HAVE_WINDOW_SYSTEM */
887 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
888 doc
: /* Clear face caches on all frames.
889 Optional THOROUGHLY non-nil means try to free unused fonts, too. */)
890 (Lisp_Object thoroughly
)
892 clear_face_cache (!NILP (thoroughly
));
894 ++windows_or_buffers_changed
;
899 /***********************************************************************
901 ***********************************************************************/
903 #ifdef HAVE_WINDOW_SYSTEM
905 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
906 doc
: /* Value is non-nil if OBJECT is a valid bitmap specification.
907 A bitmap specification is either a string, a file name, or a list
908 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
909 HEIGHT is its height, and DATA is a string containing the bits of
910 the pixmap. Bits are stored row by row, each row occupies
911 \(WIDTH + 7)/8 bytes. */)
916 if (STRINGP (object
))
917 /* If OBJECT is a string, it's a file name. */
919 else if (CONSP (object
))
921 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
922 HEIGHT must be integers > 0, and DATA must be string large
923 enough to hold a bitmap of the specified size. */
924 Lisp_Object width
, height
, data
;
926 height
= width
= data
= Qnil
;
930 width
= XCAR (object
);
931 object
= XCDR (object
);
934 height
= XCAR (object
);
935 object
= XCDR (object
);
937 data
= XCAR (object
);
941 if (NATNUMP (width
) && NATNUMP (height
) && STRINGP (data
))
943 int bytes_per_row
= ((XFASTINT (width
) + BITS_PER_CHAR
- 1)
945 if (SBYTES (data
) >= bytes_per_row
* XINT (height
))
950 return pixmap_p
? Qt
: Qnil
;
954 /* Load a bitmap according to NAME (which is either a file name or a
955 pixmap spec) for use on frame F. Value is the bitmap_id (see
956 xfns.c). If NAME is nil, return with a bitmap id of zero. If
957 bitmap cannot be loaded, display a message saying so, and return
958 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
959 if these pointers are not null. */
962 load_pixmap (FRAME_PTR f
, Lisp_Object name
, unsigned int *w_ptr
, unsigned int *h_ptr
)
969 CHECK_TYPE (!NILP (Fbitmap_spec_p (name
)), Qbitmap_spec_p
, name
);
974 /* Decode a bitmap spec into a bitmap. */
979 w
= XINT (Fcar (name
));
980 h
= XINT (Fcar (Fcdr (name
)));
981 bits
= Fcar (Fcdr (Fcdr (name
)));
983 bitmap_id
= x_create_bitmap_from_data (f
, SSDATA (bits
),
988 /* It must be a string -- a file name. */
989 bitmap_id
= x_create_bitmap_from_file (f
, name
);
995 add_to_log ("Invalid or undefined bitmap `%s'", name
, Qnil
);
1006 ++npixmaps_allocated
;
1009 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
1012 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
1018 #endif /* HAVE_WINDOW_SYSTEM */
1022 /***********************************************************************
1024 ***********************************************************************/
1026 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
1027 RGB_LIST should contain (at least) 3 lisp integers.
1028 Return 0 if there's a problem with RGB_LIST, otherwise return 1. */
1031 parse_rgb_list (Lisp_Object rgb_list
, XColor
*color
)
1033 #define PARSE_RGB_LIST_FIELD(field) \
1034 if (CONSP (rgb_list) && INTEGERP (XCAR (rgb_list))) \
1036 color->field = XINT (XCAR (rgb_list)); \
1037 rgb_list = XCDR (rgb_list); \
1042 PARSE_RGB_LIST_FIELD (red
);
1043 PARSE_RGB_LIST_FIELD (green
);
1044 PARSE_RGB_LIST_FIELD (blue
);
1050 /* Lookup on frame F the color described by the lisp string COLOR.
1051 The resulting tty color is returned in TTY_COLOR; if STD_COLOR is
1052 non-zero, then the `standard' definition of the same color is
1056 tty_lookup_color (struct frame
*f
, Lisp_Object color
, XColor
*tty_color
, XColor
*std_color
)
1058 Lisp_Object frame
, color_desc
;
1060 if (!STRINGP (color
) || NILP (Ffboundp (Qtty_color_desc
)))
1063 XSETFRAME (frame
, f
);
1065 color_desc
= call2 (Qtty_color_desc
, color
, frame
);
1066 if (CONSP (color_desc
) && CONSP (XCDR (color_desc
)))
1070 if (! INTEGERP (XCAR (XCDR (color_desc
))))
1073 tty_color
->pixel
= XINT (XCAR (XCDR (color_desc
)));
1075 rgb
= XCDR (XCDR (color_desc
));
1076 if (! parse_rgb_list (rgb
, tty_color
))
1079 /* Should we fill in STD_COLOR too? */
1082 /* Default STD_COLOR to the same as TTY_COLOR. */
1083 *std_color
= *tty_color
;
1085 /* Do a quick check to see if the returned descriptor is
1086 actually _exactly_ equal to COLOR, otherwise we have to
1087 lookup STD_COLOR separately. If it's impossible to lookup
1088 a standard color, we just give up and use TTY_COLOR. */
1089 if ((!STRINGP (XCAR (color_desc
))
1090 || NILP (Fstring_equal (color
, XCAR (color_desc
))))
1091 && !NILP (Ffboundp (Qtty_color_standard_values
)))
1093 /* Look up STD_COLOR separately. */
1094 rgb
= call1 (Qtty_color_standard_values
, color
);
1095 if (! parse_rgb_list (rgb
, std_color
))
1102 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
1103 /* We were called early during startup, and the colors are not
1104 yet set up in tty-defined-color-alist. Don't return a failure
1105 indication, since this produces the annoying "Unable to
1106 load color" messages in the *Messages* buffer. */
1109 /* tty-color-desc seems to have returned a bad value. */
1113 /* A version of defined_color for non-X frames. */
1116 tty_defined_color (struct frame
*f
, const char *color_name
,
1117 XColor
*color_def
, int alloc
)
1122 color_def
->pixel
= FACE_TTY_DEFAULT_COLOR
;
1124 color_def
->blue
= 0;
1125 color_def
->green
= 0;
1128 status
= tty_lookup_color (f
, build_string (color_name
), color_def
, NULL
);
1130 if (color_def
->pixel
== FACE_TTY_DEFAULT_COLOR
&& *color_name
)
1132 if (strcmp (color_name
, "unspecified-fg") == 0)
1133 color_def
->pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
1134 else if (strcmp (color_name
, "unspecified-bg") == 0)
1135 color_def
->pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
1138 if (color_def
->pixel
!= FACE_TTY_DEFAULT_COLOR
)
1145 /* Decide if color named COLOR_NAME is valid for the display
1146 associated with the frame F; if so, return the rgb values in
1147 COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell.
1149 This does the right thing for any type of frame. */
1152 defined_color (struct frame
*f
, const char *color_name
, XColor
*color_def
, int alloc
)
1154 if (!FRAME_WINDOW_P (f
))
1155 return tty_defined_color (f
, color_name
, color_def
, alloc
);
1156 #ifdef HAVE_X_WINDOWS
1157 else if (FRAME_X_P (f
))
1158 return x_defined_color (f
, color_name
, color_def
, alloc
);
1161 else if (FRAME_W32_P (f
))
1162 return w32_defined_color (f
, color_name
, color_def
, alloc
);
1165 else if (FRAME_NS_P (f
))
1166 return ns_defined_color (f
, color_name
, color_def
, alloc
, 1);
1173 /* Given the index IDX of a tty color on frame F, return its name, a
1177 tty_color_name (struct frame
*f
, int idx
)
1179 if (idx
>= 0 && !NILP (Ffboundp (Qtty_color_by_index
)))
1182 Lisp_Object coldesc
;
1184 XSETFRAME (frame
, f
);
1185 coldesc
= call2 (Qtty_color_by_index
, make_number (idx
), frame
);
1187 if (!NILP (coldesc
))
1188 return XCAR (coldesc
);
1191 /* We can have an MSDOG frame under -nw for a short window of
1192 opportunity before internal_terminal_init is called. DTRT. */
1193 if (FRAME_MSDOS_P (f
) && !inhibit_window_system
)
1194 return msdos_stdcolor_name (idx
);
1197 if (idx
== FACE_TTY_DEFAULT_FG_COLOR
)
1198 return build_string (unspecified_fg
);
1199 if (idx
== FACE_TTY_DEFAULT_BG_COLOR
)
1200 return build_string (unspecified_bg
);
1202 return Qunspecified
;
1206 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1209 The criterion implemented here is not a terribly sophisticated one. */
1212 face_color_gray_p (struct frame
*f
, const char *color_name
)
1217 if (defined_color (f
, color_name
, &color
, 0))
1218 gray_p
= (/* Any color sufficiently close to black counts as grey. */
1219 (color
.red
< 5000 && color
.green
< 5000 && color
.blue
< 5000)
1221 ((eabs (color
.red
- color
.green
)
1222 < max (color
.red
, color
.green
) / 20)
1223 && (eabs (color
.green
- color
.blue
)
1224 < max (color
.green
, color
.blue
) / 20)
1225 && (eabs (color
.blue
- color
.red
)
1226 < max (color
.blue
, color
.red
) / 20)));
1234 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1235 BACKGROUND_P non-zero means the color will be used as background
1239 face_color_supported_p (struct frame
*f
, const char *color_name
, int background_p
)
1244 XSETFRAME (frame
, f
);
1246 #ifdef HAVE_WINDOW_SYSTEM
1248 ? (!NILP (Fxw_display_color_p (frame
))
1249 || xstrcasecmp (color_name
, "black") == 0
1250 || xstrcasecmp (color_name
, "white") == 0
1252 && face_color_gray_p (f
, color_name
))
1253 || (!NILP (Fx_display_grayscale_p (frame
))
1254 && face_color_gray_p (f
, color_name
)))
1257 tty_defined_color (f
, color_name
, ¬_used
, 0);
1261 DEFUN ("color-gray-p", Fcolor_gray_p
, Scolor_gray_p
, 1, 2, 0,
1262 doc
: /* Return non-nil if COLOR is a shade of gray (or white or black).
1263 FRAME specifies the frame and thus the display for interpreting COLOR.
1264 If FRAME is nil or omitted, use the selected frame. */)
1265 (Lisp_Object color
, Lisp_Object frame
)
1269 CHECK_STRING (color
);
1271 frame
= selected_frame
;
1273 CHECK_FRAME (frame
);
1275 return face_color_gray_p (f
, SSDATA (color
)) ? Qt
: Qnil
;
1279 DEFUN ("color-supported-p", Fcolor_supported_p
,
1280 Scolor_supported_p
, 1, 3, 0,
1281 doc
: /* Return non-nil if COLOR can be displayed on FRAME.
1282 BACKGROUND-P non-nil means COLOR is used as a background.
1283 Otherwise, this function tells whether it can be used as a foreground.
1284 If FRAME is nil or omitted, use the selected frame.
1285 COLOR must be a valid color name. */)
1286 (Lisp_Object color
, Lisp_Object frame
, Lisp_Object background_p
)
1290 CHECK_STRING (color
);
1292 frame
= selected_frame
;
1294 CHECK_FRAME (frame
);
1296 if (face_color_supported_p (f
, SSDATA (color
), !NILP (background_p
)))
1302 /* Load color with name NAME for use by face FACE on frame F.
1303 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1304 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1305 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1306 pixel color. If color cannot be loaded, display a message, and
1307 return the foreground, background or underline color of F, but
1308 record that fact in flags of the face so that we don't try to free
1312 load_color (struct frame
*f
, struct face
*face
, Lisp_Object name
, enum lface_attribute_index target_index
)
1316 xassert (STRINGP (name
));
1317 xassert (target_index
== LFACE_FOREGROUND_INDEX
1318 || target_index
== LFACE_BACKGROUND_INDEX
1319 || target_index
== LFACE_UNDERLINE_INDEX
1320 || target_index
== LFACE_OVERLINE_INDEX
1321 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1322 || target_index
== LFACE_BOX_INDEX
);
1324 /* if the color map is full, defined_color will return a best match
1325 to the values in an existing cell. */
1326 if (!defined_color (f
, SSDATA (name
), &color
, 1))
1328 add_to_log ("Unable to load color \"%s\"", name
, Qnil
);
1330 switch (target_index
)
1332 case LFACE_FOREGROUND_INDEX
:
1333 face
->foreground_defaulted_p
= 1;
1334 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1337 case LFACE_BACKGROUND_INDEX
:
1338 face
->background_defaulted_p
= 1;
1339 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1342 case LFACE_UNDERLINE_INDEX
:
1343 face
->underline_defaulted_p
= 1;
1344 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1347 case LFACE_OVERLINE_INDEX
:
1348 face
->overline_color_defaulted_p
= 1;
1349 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1352 case LFACE_STRIKE_THROUGH_INDEX
:
1353 face
->strike_through_color_defaulted_p
= 1;
1354 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1357 case LFACE_BOX_INDEX
:
1358 face
->box_color_defaulted_p
= 1;
1359 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1368 ++ncolors_allocated
;
1375 #ifdef HAVE_WINDOW_SYSTEM
1377 /* Load colors for face FACE which is used on frame F. Colors are
1378 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1379 of ATTRS. If the background color specified is not supported on F,
1380 try to emulate gray colors with a stipple from Vface_default_stipple. */
1383 load_face_colors (struct frame
*f
, struct face
*face
, Lisp_Object
*attrs
)
1387 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1388 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1390 /* Swap colors if face is inverse-video. */
1391 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1399 /* Check for support for foreground, not for background because
1400 face_color_supported_p is smart enough to know that grays are
1401 "supported" as background because we are supposed to use stipple
1403 if (!face_color_supported_p (f
, SSDATA (bg
), 0)
1404 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1406 x_destroy_bitmap (f
, face
->stipple
);
1407 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1408 &face
->pixmap_w
, &face
->pixmap_h
);
1411 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1412 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1416 /* Free color PIXEL on frame F. */
1419 unload_color (struct frame
*f
, long unsigned int pixel
)
1421 #ifdef HAVE_X_WINDOWS
1425 x_free_colors (f
, &pixel
, 1);
1432 /* Free colors allocated for FACE. */
1435 free_face_colors (struct frame
*f
, struct face
*face
)
1437 /* PENDING(NS): need to do something here? */
1438 #ifdef HAVE_X_WINDOWS
1439 if (face
->colors_copied_bitwise_p
)
1444 if (!face
->foreground_defaulted_p
)
1446 x_free_colors (f
, &face
->foreground
, 1);
1447 IF_DEBUG (--ncolors_allocated
);
1450 if (!face
->background_defaulted_p
)
1452 x_free_colors (f
, &face
->background
, 1);
1453 IF_DEBUG (--ncolors_allocated
);
1456 if (face
->underline_p
1457 && !face
->underline_defaulted_p
)
1459 x_free_colors (f
, &face
->underline_color
, 1);
1460 IF_DEBUG (--ncolors_allocated
);
1463 if (face
->overline_p
1464 && !face
->overline_color_defaulted_p
)
1466 x_free_colors (f
, &face
->overline_color
, 1);
1467 IF_DEBUG (--ncolors_allocated
);
1470 if (face
->strike_through_p
1471 && !face
->strike_through_color_defaulted_p
)
1473 x_free_colors (f
, &face
->strike_through_color
, 1);
1474 IF_DEBUG (--ncolors_allocated
);
1477 if (face
->box
!= FACE_NO_BOX
1478 && !face
->box_color_defaulted_p
)
1480 x_free_colors (f
, &face
->box_color
, 1);
1481 IF_DEBUG (--ncolors_allocated
);
1485 #endif /* HAVE_X_WINDOWS */
1488 #endif /* HAVE_WINDOW_SYSTEM */
1492 /***********************************************************************
1494 ***********************************************************************/
1496 /* An enumerator for each field of an XLFD font name. */
1517 /* An enumerator for each possible slant value of a font. Taken from
1518 the XLFD specification. */
1526 XLFD_SLANT_REVERSE_ITALIC
,
1527 XLFD_SLANT_REVERSE_OBLIQUE
,
1531 /* Relative font weight according to XLFD documentation. */
1535 XLFD_WEIGHT_UNKNOWN
,
1536 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1537 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1538 XLFD_WEIGHT_LIGHT
, /* 30 */
1539 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1540 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1541 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1542 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1543 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1544 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1547 /* Relative proportionate width. */
1551 XLFD_SWIDTH_UNKNOWN
,
1552 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1553 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1554 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1555 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1556 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1557 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1558 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1559 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1560 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1563 /* Order by which font selection chooses fonts. The default values
1564 mean `first, find a best match for the font width, then for the
1565 font height, then for weight, then for slant.' This variable can be
1566 set via set-face-font-sort-order. */
1568 static int font_sort_order
[4];
1570 #ifdef HAVE_WINDOW_SYSTEM
1572 static enum font_property_index font_props_for_sorting
[FONT_SIZE_INDEX
];
1575 compare_fonts_by_sort_order (const void *v1
, const void *v2
)
1577 Lisp_Object font1
= *(Lisp_Object
*) v1
;
1578 Lisp_Object font2
= *(Lisp_Object
*) v2
;
1581 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1583 enum font_property_index idx
= font_props_for_sorting
[i
];
1584 Lisp_Object val1
= AREF (font1
, idx
), val2
= AREF (font2
, idx
);
1587 if (idx
<= FONT_REGISTRY_INDEX
)
1590 result
= STRINGP (val2
) ? strcmp (SSDATA (val1
), SSDATA (val2
)) : -1;
1592 result
= STRINGP (val2
) ? 1 : 0;
1596 if (INTEGERP (val1
))
1597 result
= INTEGERP (val2
) ? XINT (val1
) - XINT (val2
) : -1;
1599 result
= INTEGERP (val2
) ? 1 : 0;
1607 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
1608 doc
: /* Return a list of available fonts of family FAMILY on FRAME.
1609 If FAMILY is omitted or nil, list all families.
1610 Otherwise, FAMILY must be a string, possibly containing wildcards
1612 If FRAME is omitted or nil, use the selected frame.
1613 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
1614 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
1615 FAMILY is the font family name. POINT-SIZE is the size of the
1616 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
1617 width, weight and slant of the font. These symbols are the same as for
1618 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
1619 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
1620 giving the registry and encoding of the font.
1621 The result list is sorted according to the current setting of
1622 the face font sort order. */)
1623 (Lisp_Object family
, Lisp_Object frame
)
1625 Lisp_Object font_spec
, list
, *drivers
, vec
;
1626 int i
, nfonts
, ndrivers
;
1630 frame
= selected_frame
;
1631 CHECK_LIVE_FRAME (frame
);
1633 font_spec
= Ffont_spec (0, NULL
);
1636 CHECK_STRING (family
);
1637 font_parse_family_registry (family
, Qnil
, font_spec
);
1640 list
= font_list_entities (frame
, font_spec
);
1644 /* Sort the font entities. */
1645 for (i
= 0; i
< 4; i
++)
1646 switch (font_sort_order
[i
])
1649 font_props_for_sorting
[i
] = FONT_WIDTH_INDEX
; break;
1650 case XLFD_POINT_SIZE
:
1651 font_props_for_sorting
[i
] = FONT_SIZE_INDEX
; break;
1653 font_props_for_sorting
[i
] = FONT_WEIGHT_INDEX
; break;
1655 font_props_for_sorting
[i
] = FONT_SLANT_INDEX
; break;
1657 font_props_for_sorting
[i
++] = FONT_FAMILY_INDEX
;
1658 font_props_for_sorting
[i
++] = FONT_FOUNDRY_INDEX
;
1659 font_props_for_sorting
[i
++] = FONT_ADSTYLE_INDEX
;
1660 font_props_for_sorting
[i
++] = FONT_REGISTRY_INDEX
;
1662 ndrivers
= XINT (Flength (list
));
1663 drivers
= alloca (sizeof (Lisp_Object
) * ndrivers
);
1664 for (i
= 0; i
< ndrivers
; i
++, list
= XCDR (list
))
1665 drivers
[i
] = XCAR (list
);
1666 vec
= Fvconcat (ndrivers
, drivers
);
1667 nfonts
= ASIZE (vec
);
1669 qsort (XVECTOR (vec
)->contents
, nfonts
, sizeof (Lisp_Object
),
1670 compare_fonts_by_sort_order
);
1673 for (i
= nfonts
- 1; i
>= 0; --i
)
1675 Lisp_Object font
= AREF (vec
, i
);
1676 Lisp_Object v
= Fmake_vector (make_number (8), Qnil
);
1678 Lisp_Object spacing
;
1680 ASET (v
, 0, AREF (font
, FONT_FAMILY_INDEX
));
1681 ASET (v
, 1, FONT_WIDTH_SYMBOLIC (font
));
1682 point
= PIXEL_TO_POINT (XINT (AREF (font
, FONT_SIZE_INDEX
)) * 10,
1683 XFRAME (frame
)->resy
);
1684 ASET (v
, 2, make_number (point
));
1685 ASET (v
, 3, FONT_WEIGHT_SYMBOLIC (font
));
1686 ASET (v
, 4, FONT_SLANT_SYMBOLIC (font
));
1687 spacing
= Ffont_get (font
, QCspacing
);
1688 ASET (v
, 5, (NILP (spacing
) || EQ (spacing
, Qp
)) ? Qnil
: Qt
);
1689 ASET (v
, 6, Ffont_xlfd_name (font
, Qnil
));
1690 ASET (v
, 7, AREF (font
, FONT_REGISTRY_INDEX
));
1692 result
= Fcons (v
, result
);
1698 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
1699 doc
: /* Return a list of the names of available fonts matching PATTERN.
1700 If optional arguments FACE and FRAME are specified, return only fonts
1701 the same size as FACE on FRAME.
1703 PATTERN should be a string containing a font name in the XLFD,
1704 Fontconfig, or GTK format. A font name given in the XLFD format may
1705 contain wildcard characters:
1706 the * character matches any substring, and
1707 the ? character matches any single character.
1708 PATTERN is case-insensitive.
1710 The return value is a list of strings, suitable as arguments to
1713 Fonts Emacs can't use may or may not be excluded
1714 even if they match PATTERN and FACE.
1715 The optional fourth argument MAXIMUM sets a limit on how many
1716 fonts to match. The first MAXIMUM fonts are reported.
1717 The optional fifth argument WIDTH, if specified, is a number of columns
1718 occupied by a character of a font. In that case, return only fonts
1719 the WIDTH times as wide as FACE on FRAME. */)
1720 (Lisp_Object pattern
, Lisp_Object face
, Lisp_Object frame
, Lisp_Object maximum
, Lisp_Object width
)
1723 int size
, avgwidth
IF_LINT (= 0);
1726 CHECK_STRING (pattern
);
1728 if (! NILP (maximum
))
1729 CHECK_NATNUM (maximum
);
1732 CHECK_NUMBER (width
);
1734 /* We can't simply call check_x_frame because this function may be
1735 called before any frame is created. */
1737 frame
= selected_frame
;
1738 f
= frame_or_selected_frame (frame
, 2);
1739 if (! FRAME_WINDOW_P (f
))
1741 /* Perhaps we have not yet created any frame. */
1747 /* Determine the width standard for comparison with the fonts we find. */
1753 /* This is of limited utility since it works with character
1754 widths. Keep it for compatibility. --gerd. */
1755 int face_id
= lookup_named_face (f
, face
, 0);
1756 struct face
*width_face
= (face_id
< 0
1758 : FACE_FROM_ID (f
, face_id
));
1760 if (width_face
&& width_face
->font
)
1762 size
= width_face
->font
->pixel_size
;
1763 avgwidth
= width_face
->font
->average_width
;
1767 size
= FRAME_FONT (f
)->pixel_size
;
1768 avgwidth
= FRAME_FONT (f
)->average_width
;
1771 avgwidth
*= XINT (width
);
1775 Lisp_Object font_spec
;
1776 Lisp_Object args
[2], tail
;
1778 font_spec
= font_spec_from_name (pattern
);
1779 if (!FONTP (font_spec
))
1780 signal_error ("Invalid font name", pattern
);
1784 Ffont_put (font_spec
, QCsize
, make_number (size
));
1785 Ffont_put (font_spec
, QCavgwidth
, make_number (avgwidth
));
1787 args
[0] = Flist_fonts (font_spec
, frame
, maximum
, font_spec
);
1788 for (tail
= args
[0]; CONSP (tail
); tail
= XCDR (tail
))
1790 Lisp_Object font_entity
;
1792 font_entity
= XCAR (tail
);
1793 if ((NILP (AREF (font_entity
, FONT_SIZE_INDEX
))
1794 || XINT (AREF (font_entity
, FONT_SIZE_INDEX
)) == 0)
1795 && ! NILP (AREF (font_spec
, FONT_SIZE_INDEX
)))
1797 /* This is a scalable font. For backward compatibility,
1798 we set the specified size. */
1799 font_entity
= Fcopy_font_spec (font_entity
);
1800 ASET (font_entity
, FONT_SIZE_INDEX
,
1801 AREF (font_spec
, FONT_SIZE_INDEX
));
1803 XSETCAR (tail
, Ffont_xlfd_name (font_entity
, Qnil
));
1806 /* We don't have to check fontsets. */
1808 args
[1] = list_fontsets (f
, pattern
, size
);
1809 return Fnconc (2, args
);
1813 #endif /* HAVE_WINDOW_SYSTEM */
1816 /***********************************************************************
1818 ***********************************************************************/
1820 /* Access face attributes of face LFACE, a Lisp vector. */
1822 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
1823 #define LFACE_FOUNDRY(LFACE) AREF ((LFACE), LFACE_FOUNDRY_INDEX)
1824 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
1825 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
1826 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
1827 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
1828 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
1829 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
1830 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
1831 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
1832 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
1833 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
1834 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
1835 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
1836 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
1837 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
1838 #define LFACE_FONTSET(LFACE) AREF ((LFACE), LFACE_FONTSET_INDEX)
1840 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
1841 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
1843 #define LFACEP(LFACE) \
1845 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \
1846 && EQ (AREF (LFACE, 0), Qface))
1851 /* Check consistency of Lisp face attribute vector ATTRS. */
1854 check_lface_attrs (attrs
)
1857 xassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
1858 || IGNORE_DEFFACE_P (attrs
[LFACE_FAMILY_INDEX
])
1859 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
1860 xassert (UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
1861 || IGNORE_DEFFACE_P (attrs
[LFACE_FOUNDRY_INDEX
])
1862 || STRINGP (attrs
[LFACE_FOUNDRY_INDEX
]));
1863 xassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
1864 || IGNORE_DEFFACE_P (attrs
[LFACE_SWIDTH_INDEX
])
1865 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
1866 xassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
1867 || IGNORE_DEFFACE_P (attrs
[LFACE_HEIGHT_INDEX
])
1868 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
])
1869 || FLOATP (attrs
[LFACE_HEIGHT_INDEX
])
1870 || FUNCTIONP (attrs
[LFACE_HEIGHT_INDEX
]));
1871 xassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
1872 || IGNORE_DEFFACE_P (attrs
[LFACE_WEIGHT_INDEX
])
1873 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
1874 xassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
1875 || IGNORE_DEFFACE_P (attrs
[LFACE_SLANT_INDEX
])
1876 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
1877 xassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
1878 || IGNORE_DEFFACE_P (attrs
[LFACE_UNDERLINE_INDEX
])
1879 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
1880 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]));
1881 xassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
1882 || IGNORE_DEFFACE_P (attrs
[LFACE_OVERLINE_INDEX
])
1883 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
1884 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
1885 xassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1886 || IGNORE_DEFFACE_P (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1887 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1888 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
1889 xassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
1890 || IGNORE_DEFFACE_P (attrs
[LFACE_BOX_INDEX
])
1891 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
1892 || STRINGP (attrs
[LFACE_BOX_INDEX
])
1893 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
1894 || CONSP (attrs
[LFACE_BOX_INDEX
]));
1895 xassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
1896 || IGNORE_DEFFACE_P (attrs
[LFACE_INVERSE_INDEX
])
1897 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
1898 xassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
1899 || IGNORE_DEFFACE_P (attrs
[LFACE_FOREGROUND_INDEX
])
1900 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
1901 xassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
1902 || IGNORE_DEFFACE_P (attrs
[LFACE_BACKGROUND_INDEX
])
1903 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
1904 xassert (UNSPECIFIEDP (attrs
[LFACE_INHERIT_INDEX
])
1905 || IGNORE_DEFFACE_P (attrs
[LFACE_INHERIT_INDEX
])
1906 || NILP (attrs
[LFACE_INHERIT_INDEX
])
1907 || SYMBOLP (attrs
[LFACE_INHERIT_INDEX
])
1908 || CONSP (attrs
[LFACE_INHERIT_INDEX
]));
1909 #ifdef HAVE_WINDOW_SYSTEM
1910 xassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
1911 || IGNORE_DEFFACE_P (attrs
[LFACE_STIPPLE_INDEX
])
1912 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
1913 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
1914 xassert (UNSPECIFIEDP (attrs
[LFACE_FONT_INDEX
])
1915 || IGNORE_DEFFACE_P (attrs
[LFACE_FONT_INDEX
])
1916 || FONTP (attrs
[LFACE_FONT_INDEX
]));
1917 xassert (UNSPECIFIEDP (attrs
[LFACE_FONTSET_INDEX
])
1918 || STRINGP (attrs
[LFACE_FONTSET_INDEX
]));
1923 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
1931 xassert (LFACEP (lface
));
1932 check_lface_attrs (XVECTOR (lface
)->contents
);
1936 #else /* GLYPH_DEBUG == 0 */
1938 #define check_lface_attrs(attrs) (void) 0
1939 #define check_lface(lface) (void) 0
1941 #endif /* GLYPH_DEBUG == 0 */
1945 /* Face-merge cycle checking. */
1947 enum named_merge_point_kind
1949 NAMED_MERGE_POINT_NORMAL
,
1950 NAMED_MERGE_POINT_REMAP
1953 /* A `named merge point' is simply a point during face-merging where we
1954 look up a face by name. We keep a stack of which named lookups we're
1955 currently processing so that we can easily detect cycles, using a
1956 linked- list of struct named_merge_point structures, typically
1957 allocated on the stack frame of the named lookup functions which are
1958 active (so no consing is required). */
1959 struct named_merge_point
1961 Lisp_Object face_name
;
1962 enum named_merge_point_kind named_merge_point_kind
;
1963 struct named_merge_point
*prev
;
1967 /* If a face merging cycle is detected for FACE_NAME, return 0,
1968 otherwise add NEW_NAMED_MERGE_POINT, which is initialized using
1969 FACE_NAME and NAMED_MERGE_POINT_KIND, as the head of the linked list
1970 pointed to by NAMED_MERGE_POINTS, and return 1. */
1973 push_named_merge_point (struct named_merge_point
*new_named_merge_point
,
1974 Lisp_Object face_name
,
1975 enum named_merge_point_kind named_merge_point_kind
,
1976 struct named_merge_point
**named_merge_points
)
1978 struct named_merge_point
*prev
;
1980 for (prev
= *named_merge_points
; prev
; prev
= prev
->prev
)
1981 if (EQ (face_name
, prev
->face_name
))
1983 if (prev
->named_merge_point_kind
== named_merge_point_kind
)
1984 /* A cycle, so fail. */
1986 else if (prev
->named_merge_point_kind
== NAMED_MERGE_POINT_REMAP
)
1987 /* A remap `hides ' any previous normal merge points
1988 (because the remap means that it's actually different face),
1989 so as we know the current merge point must be normal, we
1990 can just assume it's OK. */
1994 new_named_merge_point
->face_name
= face_name
;
1995 new_named_merge_point
->named_merge_point_kind
= named_merge_point_kind
;
1996 new_named_merge_point
->prev
= *named_merge_points
;
1998 *named_merge_points
= new_named_merge_point
;
2005 #if 0 /* Seems to be unused. */
2007 internal_resolve_face_name (nargs
, args
)
2011 return Fget (args
[0], args
[1]);
2015 resolve_face_name_error (ignore
)
2022 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
2023 to make it a symbol. If FACE_NAME is an alias for another face,
2024 return that face's name.
2026 Return default face in case of errors. */
2029 resolve_face_name (Lisp_Object face_name
, int signal_p
)
2031 Lisp_Object orig_face
;
2032 Lisp_Object tortoise
, hare
;
2034 if (STRINGP (face_name
))
2035 face_name
= intern (SSDATA (face_name
));
2037 if (NILP (face_name
) || !SYMBOLP (face_name
))
2040 orig_face
= face_name
;
2041 tortoise
= hare
= face_name
;
2046 hare
= Fget (hare
, Qface_alias
);
2047 if (NILP (hare
) || !SYMBOLP (hare
))
2051 hare
= Fget (hare
, Qface_alias
);
2052 if (NILP (hare
) || !SYMBOLP (hare
))
2055 tortoise
= Fget (tortoise
, Qface_alias
);
2056 if (EQ (hare
, tortoise
))
2059 xsignal1 (Qcircular_list
, orig_face
);
2068 /* Return the face definition of FACE_NAME on frame F. F null means
2069 return the definition for new frames. FACE_NAME may be a string or
2070 a symbol (apparently Emacs 20.2 allowed strings as face names in
2071 face text properties; Ediff uses that). If SIGNAL_P is non-zero,
2072 signal an error if FACE_NAME is not a valid face name. If SIGNAL_P
2073 is zero, value is nil if FACE_NAME is not a valid face name. */
2074 static INLINE Lisp_Object
2075 lface_from_face_name_no_resolve (struct frame
*f
, Lisp_Object face_name
, int signal_p
)
2080 lface
= assq_no_quit (face_name
, f
->face_alist
);
2082 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
2085 lface
= XCDR (lface
);
2087 signal_error ("Invalid face", face_name
);
2089 check_lface (lface
);
2094 /* Return the face definition of FACE_NAME on frame F. F null means
2095 return the definition for new frames. FACE_NAME may be a string or
2096 a symbol (apparently Emacs 20.2 allowed strings as face names in
2097 face text properties; Ediff uses that). If FACE_NAME is an alias
2098 for another face, return that face's definition. If SIGNAL_P is
2099 non-zero, signal an error if FACE_NAME is not a valid face name.
2100 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
2102 static INLINE Lisp_Object
2103 lface_from_face_name (struct frame
*f
, Lisp_Object face_name
, int signal_p
)
2105 face_name
= resolve_face_name (face_name
, signal_p
);
2106 return lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2110 /* Get face attributes of face FACE_NAME from frame-local faces on
2111 frame F. Store the resulting attributes in ATTRS which must point
2112 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
2113 is non-zero, signal an error if FACE_NAME does not name a face.
2114 Otherwise, value is zero if FACE_NAME is not a face. */
2117 get_lface_attributes_no_remap (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*attrs
, int signal_p
)
2121 lface
= lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2124 memcpy (attrs
, XVECTOR (lface
)->contents
,
2125 LFACE_VECTOR_SIZE
* sizeof *attrs
);
2127 return !NILP (lface
);
2130 /* Get face attributes of face FACE_NAME from frame-local faces on frame
2131 F. Store the resulting attributes in ATTRS which must point to a
2132 vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If FACE_NAME is an
2133 alias for another face, use that face's definition. If SIGNAL_P is
2134 non-zero, signal an error if FACE_NAME does not name a face.
2135 Otherwise, value is zero if FACE_NAME is not a face. */
2138 get_lface_attributes (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*attrs
, int signal_p
, struct named_merge_point
*named_merge_points
)
2140 Lisp_Object face_remapping
;
2142 face_name
= resolve_face_name (face_name
, signal_p
);
2144 /* See if SYMBOL has been remapped to some other face (usually this
2145 is done buffer-locally). */
2146 face_remapping
= assq_no_quit (face_name
, Vface_remapping_alist
);
2147 if (CONSP (face_remapping
))
2149 struct named_merge_point named_merge_point
;
2151 if (push_named_merge_point (&named_merge_point
,
2152 face_name
, NAMED_MERGE_POINT_REMAP
,
2153 &named_merge_points
))
2157 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2158 attrs
[i
] = Qunspecified
;
2160 return merge_face_ref (f
, XCDR (face_remapping
), attrs
,
2161 signal_p
, named_merge_points
);
2165 /* Default case, no remapping. */
2166 return get_lface_attributes_no_remap (f
, face_name
, attrs
, signal_p
);
2170 /* Non-zero if all attributes in face attribute vector ATTRS are
2171 specified, i.e. are non-nil. */
2174 lface_fully_specified_p (Lisp_Object
*attrs
)
2178 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2179 if (i
!= LFACE_FONT_INDEX
&& i
!= LFACE_INHERIT_INDEX
)
2180 if ((UNSPECIFIEDP (attrs
[i
]) || IGNORE_DEFFACE_P (attrs
[i
])))
2183 return i
== LFACE_VECTOR_SIZE
;
2186 #ifdef HAVE_WINDOW_SYSTEM
2188 /* Set font-related attributes of Lisp face LFACE from FONT-OBJECT.
2189 If FORCE_P is zero, set only unspecified attributes of LFACE. The
2190 exception is `font' attribute. It is set to FONT_OBJECT regardless
2194 set_lface_from_font (struct frame
*f
, Lisp_Object lface
, Lisp_Object font_object
, int force_p
)
2197 struct font
*font
= XFONT_OBJECT (font_object
);
2199 /* Set attributes only if unspecified, otherwise face defaults for
2200 new frames would never take effect. If the font doesn't have a
2201 specific property, set a normal value for that. */
2203 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
2205 Lisp_Object family
= AREF (font_object
, FONT_FAMILY_INDEX
);
2207 LFACE_FAMILY (lface
) = SYMBOL_NAME (family
);
2210 if (force_p
|| UNSPECIFIEDP (LFACE_FOUNDRY (lface
)))
2212 Lisp_Object foundry
= AREF (font_object
, FONT_FOUNDRY_INDEX
);
2214 LFACE_FOUNDRY (lface
) = SYMBOL_NAME (foundry
);
2217 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
2219 int pt
= PIXEL_TO_POINT (font
->pixel_size
* 10, f
->resy
);
2222 LFACE_HEIGHT (lface
) = make_number (pt
);
2225 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
2227 val
= FONT_WEIGHT_FOR_FACE (font_object
);
2228 LFACE_WEIGHT (lface
) = ! NILP (val
) ? val
:Qnormal
;
2230 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
2232 val
= FONT_SLANT_FOR_FACE (font_object
);
2233 LFACE_SLANT (lface
) = ! NILP (val
) ? val
: Qnormal
;
2235 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
2237 val
= FONT_WIDTH_FOR_FACE (font_object
);
2238 LFACE_SWIDTH (lface
) = ! NILP (val
) ? val
: Qnormal
;
2241 LFACE_FONT (lface
) = font_object
;
2245 #endif /* HAVE_WINDOW_SYSTEM */
2248 /* Merges the face height FROM with the face height TO, and returns the
2249 merged height. If FROM is an invalid height, then INVALID is
2250 returned instead. FROM and TO may be either absolute face heights or
2251 `relative' heights; the returned value is always an absolute height
2252 unless both FROM and TO are relative. */
2255 merge_face_heights (Lisp_Object from
, Lisp_Object to
, Lisp_Object invalid
)
2257 Lisp_Object result
= invalid
;
2259 if (INTEGERP (from
))
2260 /* FROM is absolute, just use it as is. */
2262 else if (FLOATP (from
))
2263 /* FROM is a scale, use it to adjust TO. */
2266 /* relative X absolute => absolute */
2267 result
= make_number ((EMACS_INT
)(XFLOAT_DATA (from
) * XINT (to
)));
2268 else if (FLOATP (to
))
2269 /* relative X relative => relative */
2270 result
= make_float (XFLOAT_DATA (from
) * XFLOAT_DATA (to
));
2271 else if (UNSPECIFIEDP (to
))
2274 else if (FUNCTIONP (from
))
2275 /* FROM is a function, which use to adjust TO. */
2277 /* Call function with current height as argument.
2278 From is the new height. */
2279 Lisp_Object args
[2];
2283 result
= safe_call (2, args
);
2285 /* Ensure that if TO was absolute, so is the result. */
2286 if (INTEGERP (to
) && !INTEGERP (result
))
2294 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
2295 store the resulting attributes in TO, which must be already be
2296 completely specified and contain only absolute attributes. Every
2297 specified attribute of FROM overrides the corresponding attribute of
2298 TO; relative attributes in FROM are merged with the absolute value in
2299 TO and replace it. NAMED_MERGE_POINTS is used internally to detect
2300 loops in face inheritance/remapping; it should be 0 when called from
2304 merge_face_vectors (struct frame
*f
, Lisp_Object
*from
, Lisp_Object
*to
, struct named_merge_point
*named_merge_points
)
2308 /* If FROM inherits from some other faces, merge their attributes into
2309 TO before merging FROM's direct attributes. Note that an :inherit
2310 attribute of `unspecified' is the same as one of nil; we never
2311 merge :inherit attributes, so nil is more correct, but lots of
2312 other code uses `unspecified' as a generic value for face attributes. */
2313 if (!UNSPECIFIEDP (from
[LFACE_INHERIT_INDEX
])
2314 && !NILP (from
[LFACE_INHERIT_INDEX
]))
2315 merge_face_ref (f
, from
[LFACE_INHERIT_INDEX
], to
, 0, named_merge_points
);
2317 i
= LFACE_FONT_INDEX
;
2318 if (!UNSPECIFIEDP (from
[i
]))
2320 if (!UNSPECIFIEDP (to
[i
]))
2321 to
[i
] = Fmerge_font_spec (from
[i
], to
[i
]);
2323 to
[i
] = Fcopy_font_spec (from
[i
]);
2324 if (! NILP (AREF (to
[i
], FONT_FOUNDRY_INDEX
)))
2325 to
[LFACE_FOUNDRY_INDEX
] = SYMBOL_NAME (AREF (to
[i
], FONT_FOUNDRY_INDEX
));
2326 if (! NILP (AREF (to
[i
], FONT_FAMILY_INDEX
)))
2327 to
[LFACE_FAMILY_INDEX
] = SYMBOL_NAME (AREF (to
[i
], FONT_FAMILY_INDEX
));
2328 if (! NILP (AREF (to
[i
], FONT_WEIGHT_INDEX
)))
2329 to
[LFACE_WEIGHT_INDEX
] = FONT_WEIGHT_FOR_FACE (to
[i
]);
2330 if (! NILP (AREF (to
[i
], FONT_SLANT_INDEX
)))
2331 to
[LFACE_SLANT_INDEX
] = FONT_SLANT_FOR_FACE (to
[i
]);
2332 if (! NILP (AREF (to
[i
], FONT_WIDTH_INDEX
)))
2333 to
[LFACE_SWIDTH_INDEX
] = FONT_WIDTH_FOR_FACE (to
[i
]);
2334 ASET (to
[i
], FONT_SIZE_INDEX
, Qnil
);
2337 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2338 if (!UNSPECIFIEDP (from
[i
]))
2340 if (i
== LFACE_HEIGHT_INDEX
&& !INTEGERP (from
[i
]))
2342 to
[i
] = merge_face_heights (from
[i
], to
[i
], to
[i
]);
2343 font_clear_prop (to
, FONT_SIZE_INDEX
);
2345 else if (i
!= LFACE_FONT_INDEX
2346 && ! EQ (to
[i
], from
[i
]))
2349 if (i
>= LFACE_FAMILY_INDEX
&& i
<=LFACE_SLANT_INDEX
)
2350 font_clear_prop (to
,
2351 (i
== LFACE_FAMILY_INDEX
? FONT_FAMILY_INDEX
2352 : i
== LFACE_FOUNDRY_INDEX
? FONT_FOUNDRY_INDEX
2353 : i
== LFACE_SWIDTH_INDEX
? FONT_WIDTH_INDEX
2354 : i
== LFACE_HEIGHT_INDEX
? FONT_SIZE_INDEX
2355 : i
== LFACE_WEIGHT_INDEX
? FONT_WEIGHT_INDEX
2356 : FONT_SLANT_INDEX
));
2360 /* TO is always an absolute face, which should inherit from nothing.
2361 We blindly copy the :inherit attribute above and fix it up here. */
2362 to
[LFACE_INHERIT_INDEX
] = Qnil
;
2365 /* Merge the named face FACE_NAME on frame F, into the vector of face
2366 attributes TO. NAMED_MERGE_POINTS is used to detect loops in face
2367 inheritance. Returns true if FACE_NAME is a valid face name and
2368 merging succeeded. */
2371 merge_named_face (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*to
, struct named_merge_point
*named_merge_points
)
2373 struct named_merge_point named_merge_point
;
2375 if (push_named_merge_point (&named_merge_point
,
2376 face_name
, NAMED_MERGE_POINT_NORMAL
,
2377 &named_merge_points
))
2379 struct gcpro gcpro1
;
2380 Lisp_Object from
[LFACE_VECTOR_SIZE
];
2381 int ok
= get_lface_attributes (f
, face_name
, from
, 0, named_merge_points
);
2385 GCPRO1 (named_merge_point
.face_name
);
2386 merge_face_vectors (f
, from
, to
, named_merge_points
);
2397 /* Merge face attributes from the lisp `face reference' FACE_REF on
2398 frame F into the face attribute vector TO. If ERR_MSGS is non-zero,
2399 problems with FACE_REF cause an error message to be shown. Return
2400 non-zero if no errors occurred (regardless of the value of ERR_MSGS).
2401 NAMED_MERGE_POINTS is used to detect loops in face inheritance or
2402 list structure; it may be 0 for most callers.
2404 FACE_REF may be a single face specification or a list of such
2405 specifications. Each face specification can be:
2407 1. A symbol or string naming a Lisp face.
2409 2. A property list of the form (KEYWORD VALUE ...) where each
2410 KEYWORD is a face attribute name, and value is an appropriate value
2413 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
2414 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
2415 for compatibility with 20.2.
2417 Face specifications earlier in lists take precedence over later
2421 merge_face_ref (struct frame
*f
, Lisp_Object face_ref
, Lisp_Object
*to
, int err_msgs
, struct named_merge_point
*named_merge_points
)
2423 int ok
= 1; /* Succeed without an error? */
2425 if (CONSP (face_ref
))
2427 Lisp_Object first
= XCAR (face_ref
);
2429 if (EQ (first
, Qforeground_color
)
2430 || EQ (first
, Qbackground_color
))
2432 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
2433 . COLOR). COLOR must be a string. */
2434 Lisp_Object color_name
= XCDR (face_ref
);
2435 Lisp_Object color
= first
;
2437 if (STRINGP (color_name
))
2439 if (EQ (color
, Qforeground_color
))
2440 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
2442 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
2447 add_to_log ("Invalid face color", color_name
, Qnil
);
2451 else if (SYMBOLP (first
)
2452 && *SDATA (SYMBOL_NAME (first
)) == ':')
2454 /* Assume this is the property list form. */
2455 while (CONSP (face_ref
) && CONSP (XCDR (face_ref
)))
2457 Lisp_Object keyword
= XCAR (face_ref
);
2458 Lisp_Object value
= XCAR (XCDR (face_ref
));
2461 /* Specifying `unspecified' is a no-op. */
2462 if (EQ (value
, Qunspecified
))
2464 else if (EQ (keyword
, QCfamily
))
2466 if (STRINGP (value
))
2468 to
[LFACE_FAMILY_INDEX
] = value
;
2469 font_clear_prop (to
, FONT_FAMILY_INDEX
);
2474 else if (EQ (keyword
, QCfoundry
))
2476 if (STRINGP (value
))
2478 to
[LFACE_FOUNDRY_INDEX
] = value
;
2479 font_clear_prop (to
, FONT_FOUNDRY_INDEX
);
2484 else if (EQ (keyword
, QCheight
))
2486 Lisp_Object new_height
=
2487 merge_face_heights (value
, to
[LFACE_HEIGHT_INDEX
], Qnil
);
2489 if (! NILP (new_height
))
2491 to
[LFACE_HEIGHT_INDEX
] = new_height
;
2492 font_clear_prop (to
, FONT_SIZE_INDEX
);
2497 else if (EQ (keyword
, QCweight
))
2499 if (SYMBOLP (value
) && FONT_WEIGHT_NAME_NUMERIC (value
) >= 0)
2501 to
[LFACE_WEIGHT_INDEX
] = value
;
2502 font_clear_prop (to
, FONT_WEIGHT_INDEX
);
2507 else if (EQ (keyword
, QCslant
))
2509 if (SYMBOLP (value
) && FONT_SLANT_NAME_NUMERIC (value
) >= 0)
2511 to
[LFACE_SLANT_INDEX
] = value
;
2512 font_clear_prop (to
, FONT_SLANT_INDEX
);
2517 else if (EQ (keyword
, QCunderline
))
2522 to
[LFACE_UNDERLINE_INDEX
] = value
;
2526 else if (EQ (keyword
, QCoverline
))
2531 to
[LFACE_OVERLINE_INDEX
] = value
;
2535 else if (EQ (keyword
, QCstrike_through
))
2540 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
2544 else if (EQ (keyword
, QCbox
))
2547 value
= make_number (1);
2548 if (INTEGERP (value
)
2552 to
[LFACE_BOX_INDEX
] = value
;
2556 else if (EQ (keyword
, QCinverse_video
)
2557 || EQ (keyword
, QCreverse_video
))
2559 if (EQ (value
, Qt
) || NILP (value
))
2560 to
[LFACE_INVERSE_INDEX
] = value
;
2564 else if (EQ (keyword
, QCforeground
))
2566 if (STRINGP (value
))
2567 to
[LFACE_FOREGROUND_INDEX
] = value
;
2571 else if (EQ (keyword
, QCbackground
))
2573 if (STRINGP (value
))
2574 to
[LFACE_BACKGROUND_INDEX
] = value
;
2578 else if (EQ (keyword
, QCstipple
))
2580 #if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
2581 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
2582 if (!NILP (pixmap_p
))
2583 to
[LFACE_STIPPLE_INDEX
] = value
;
2588 else if (EQ (keyword
, QCwidth
))
2590 if (SYMBOLP (value
) && FONT_WIDTH_NAME_NUMERIC (value
) >= 0)
2592 to
[LFACE_SWIDTH_INDEX
] = value
;
2593 font_clear_prop (to
, FONT_WIDTH_INDEX
);
2598 else if (EQ (keyword
, QCinherit
))
2600 /* This is not really very useful; it's just like a
2601 normal face reference. */
2602 if (! merge_face_ref (f
, value
, to
,
2603 err_msgs
, named_merge_points
))
2611 add_to_log ("Invalid face attribute %S %S", keyword
, value
);
2615 face_ref
= XCDR (XCDR (face_ref
));
2620 /* This is a list of face refs. Those at the beginning of the
2621 list take precedence over what follows, so we have to merge
2622 from the end backwards. */
2623 Lisp_Object next
= XCDR (face_ref
);
2626 ok
= merge_face_ref (f
, next
, to
, err_msgs
, named_merge_points
);
2628 if (! merge_face_ref (f
, first
, to
, err_msgs
, named_merge_points
))
2634 /* FACE_REF ought to be a face name. */
2635 ok
= merge_named_face (f
, face_ref
, to
, named_merge_points
);
2636 if (!ok
&& err_msgs
)
2637 add_to_log ("Invalid face reference: %s", face_ref
, Qnil
);
2644 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
2645 Sinternal_make_lisp_face
, 1, 2, 0,
2646 doc
: /* Make FACE, a symbol, a Lisp face with all attributes nil.
2647 If FACE was not known as a face before, create a new one.
2648 If optional argument FRAME is specified, make a frame-local face
2649 for that frame. Otherwise operate on the global face definition.
2650 Value is a vector of face attributes. */)
2651 (Lisp_Object face
, Lisp_Object frame
)
2653 Lisp_Object global_lface
, lface
;
2657 CHECK_SYMBOL (face
);
2658 global_lface
= lface_from_face_name (NULL
, face
, 0);
2662 CHECK_LIVE_FRAME (frame
);
2664 lface
= lface_from_face_name (f
, face
, 0);
2667 f
= NULL
, lface
= Qnil
;
2669 /* Add a global definition if there is none. */
2670 if (NILP (global_lface
))
2672 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2674 ASET (global_lface
, 0, Qface
);
2675 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
2676 Vface_new_frame_defaults
);
2678 /* Assign the new Lisp face a unique ID. The mapping from Lisp
2679 face id to Lisp face is given by the vector lface_id_to_name.
2680 The mapping from Lisp face to Lisp face id is given by the
2681 property `face' of the Lisp face name. */
2682 if (next_lface_id
== lface_id_to_name_size
)
2684 int new_size
= max (50, 2 * lface_id_to_name_size
);
2685 int sz
= new_size
* sizeof *lface_id_to_name
;
2686 lface_id_to_name
= (Lisp_Object
*) xrealloc (lface_id_to_name
, sz
);
2687 lface_id_to_name_size
= new_size
;
2690 lface_id_to_name
[next_lface_id
] = face
;
2691 Fput (face
, Qface
, make_number (next_lface_id
));
2695 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2696 ASET (global_lface
, i
, Qunspecified
);
2698 /* Add a frame-local definition. */
2703 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2705 ASET (lface
, 0, Qface
);
2706 f
->face_alist
= Fcons (Fcons (face
, lface
), f
->face_alist
);
2709 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2710 ASET (lface
, i
, Qunspecified
);
2713 lface
= global_lface
;
2715 /* Changing a named face means that all realized faces depending on
2716 that face are invalid. Since we cannot tell which realized faces
2717 depend on the face, make sure they are all removed. This is done
2718 by incrementing face_change_count. The next call to
2719 init_iterator will then free realized faces. */
2720 if (NILP (Fget (face
, Qface_no_inherit
)))
2722 ++face_change_count
;
2723 ++windows_or_buffers_changed
;
2726 xassert (LFACEP (lface
));
2727 check_lface (lface
);
2732 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
2733 Sinternal_lisp_face_p
, 1, 2, 0,
2734 doc
: /* Return non-nil if FACE names a face.
2735 FACE should be a symbol or string.
2736 If optional second argument FRAME is non-nil, check for the
2737 existence of a frame-local face with name FACE on that frame.
2738 Otherwise check for the existence of a global face. */)
2739 (Lisp_Object face
, Lisp_Object frame
)
2743 face
= resolve_face_name (face
, 1);
2747 CHECK_LIVE_FRAME (frame
);
2748 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2751 lface
= lface_from_face_name (NULL
, face
, 0);
2757 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
2758 Sinternal_copy_lisp_face
, 4, 4, 0,
2759 doc
: /* Copy face FROM to TO.
2760 If FRAME is t, copy the global face definition of FROM.
2761 Otherwise, copy the frame-local definition of FROM on FRAME.
2762 If NEW-FRAME is a frame, copy that data into the frame-local
2763 definition of TO on NEW-FRAME. If NEW-FRAME is nil,
2764 FRAME controls where the data is copied to.
2766 The value is TO. */)
2767 (Lisp_Object from
, Lisp_Object to
, Lisp_Object frame
, Lisp_Object new_frame
)
2769 Lisp_Object lface
, copy
;
2771 CHECK_SYMBOL (from
);
2776 /* Copy global definition of FROM. We don't make copies of
2777 strings etc. because 20.2 didn't do it either. */
2778 lface
= lface_from_face_name (NULL
, from
, 1);
2779 copy
= Finternal_make_lisp_face (to
, Qnil
);
2783 /* Copy frame-local definition of FROM. */
2784 if (NILP (new_frame
))
2786 CHECK_LIVE_FRAME (frame
);
2787 CHECK_LIVE_FRAME (new_frame
);
2788 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
2789 copy
= Finternal_make_lisp_face (to
, new_frame
);
2792 memcpy (XVECTOR (copy
)->contents
, XVECTOR (lface
)->contents
,
2793 LFACE_VECTOR_SIZE
* sizeof (Lisp_Object
));
2795 /* Changing a named face means that all realized faces depending on
2796 that face are invalid. Since we cannot tell which realized faces
2797 depend on the face, make sure they are all removed. This is done
2798 by incrementing face_change_count. The next call to
2799 init_iterator will then free realized faces. */
2800 if (NILP (Fget (to
, Qface_no_inherit
)))
2802 ++face_change_count
;
2803 ++windows_or_buffers_changed
;
2810 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
2811 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
2812 doc
: /* Set attribute ATTR of FACE to VALUE.
2813 FRAME being a frame means change the face on that frame.
2814 FRAME nil means change the face of the selected frame.
2815 FRAME t means change the default for new frames.
2816 FRAME 0 means change the face on all frames, and change the default
2818 (Lisp_Object face
, Lisp_Object attr
, Lisp_Object value
, Lisp_Object frame
)
2821 Lisp_Object old_value
= Qnil
;
2822 /* Set one of enum font_property_index (> 0) if ATTR is one of
2823 font-related attributes other than QCfont and QCfontset. */
2824 enum font_property_index prop_index
= 0;
2826 CHECK_SYMBOL (face
);
2827 CHECK_SYMBOL (attr
);
2829 face
= resolve_face_name (face
, 1);
2831 /* If FRAME is 0, change face on all frames, and change the
2832 default for new frames. */
2833 if (INTEGERP (frame
) && XINT (frame
) == 0)
2836 Finternal_set_lisp_face_attribute (face
, attr
, value
, Qt
);
2837 FOR_EACH_FRAME (tail
, frame
)
2838 Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
2842 /* Set lface to the Lisp attribute vector of FACE. */
2845 lface
= lface_from_face_name (NULL
, face
, 1);
2847 /* When updating face-new-frame-defaults, we put :ignore-defface
2848 where the caller wants `unspecified'. This forces the frame
2849 defaults to ignore the defface value. Otherwise, the defface
2850 will take effect, which is generally not what is intended.
2851 The value of that attribute will be inherited from some other
2852 face during face merging. See internal_merge_in_global_face. */
2853 if (UNSPECIFIEDP (value
))
2854 value
= Qignore_defface
;
2859 frame
= selected_frame
;
2861 CHECK_LIVE_FRAME (frame
);
2862 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2864 /* If a frame-local face doesn't exist yet, create one. */
2866 lface
= Finternal_make_lisp_face (face
, frame
);
2869 if (EQ (attr
, QCfamily
))
2871 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2873 CHECK_STRING (value
);
2874 if (SCHARS (value
) == 0)
2875 signal_error ("Invalid face family", value
);
2877 old_value
= LFACE_FAMILY (lface
);
2878 LFACE_FAMILY (lface
) = value
;
2879 prop_index
= FONT_FAMILY_INDEX
;
2881 else if (EQ (attr
, QCfoundry
))
2883 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2885 CHECK_STRING (value
);
2886 if (SCHARS (value
) == 0)
2887 signal_error ("Invalid face foundry", value
);
2889 old_value
= LFACE_FOUNDRY (lface
);
2890 LFACE_FOUNDRY (lface
) = value
;
2891 prop_index
= FONT_FOUNDRY_INDEX
;
2893 else if (EQ (attr
, QCheight
))
2895 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2897 if (EQ (face
, Qdefault
))
2899 /* The default face must have an absolute size. */
2900 if (!INTEGERP (value
) || XINT (value
) <= 0)
2901 signal_error ("Default face height not absolute and positive", value
);
2905 /* For non-default faces, do a test merge with a random
2906 height to see if VALUE's ok. */
2907 Lisp_Object test
= merge_face_heights (value
,
2910 if (!INTEGERP (test
) || XINT (test
) <= 0)
2911 signal_error ("Face height does not produce a positive integer", value
);
2915 old_value
= LFACE_HEIGHT (lface
);
2916 LFACE_HEIGHT (lface
) = value
;
2917 prop_index
= FONT_SIZE_INDEX
;
2919 else if (EQ (attr
, QCweight
))
2921 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2923 CHECK_SYMBOL (value
);
2924 if (FONT_WEIGHT_NAME_NUMERIC (value
) < 0)
2925 signal_error ("Invalid face weight", value
);
2927 old_value
= LFACE_WEIGHT (lface
);
2928 LFACE_WEIGHT (lface
) = value
;
2929 prop_index
= FONT_WEIGHT_INDEX
;
2931 else if (EQ (attr
, QCslant
))
2933 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2935 CHECK_SYMBOL (value
);
2936 if (FONT_SLANT_NAME_NUMERIC (value
) < 0)
2937 signal_error ("Invalid face slant", value
);
2939 old_value
= LFACE_SLANT (lface
);
2940 LFACE_SLANT (lface
) = value
;
2941 prop_index
= FONT_SLANT_INDEX
;
2943 else if (EQ (attr
, QCunderline
))
2945 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2946 if ((SYMBOLP (value
)
2948 && !EQ (value
, Qnil
))
2949 /* Underline color. */
2951 && SCHARS (value
) == 0))
2952 signal_error ("Invalid face underline", value
);
2954 old_value
= LFACE_UNDERLINE (lface
);
2955 LFACE_UNDERLINE (lface
) = value
;
2957 else if (EQ (attr
, QCoverline
))
2959 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2960 if ((SYMBOLP (value
)
2962 && !EQ (value
, Qnil
))
2963 /* Overline color. */
2965 && SCHARS (value
) == 0))
2966 signal_error ("Invalid face overline", value
);
2968 old_value
= LFACE_OVERLINE (lface
);
2969 LFACE_OVERLINE (lface
) = value
;
2971 else if (EQ (attr
, QCstrike_through
))
2973 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2974 if ((SYMBOLP (value
)
2976 && !EQ (value
, Qnil
))
2977 /* Strike-through color. */
2979 && SCHARS (value
) == 0))
2980 signal_error ("Invalid face strike-through", value
);
2982 old_value
= LFACE_STRIKE_THROUGH (lface
);
2983 LFACE_STRIKE_THROUGH (lface
) = value
;
2985 else if (EQ (attr
, QCbox
))
2989 /* Allow t meaning a simple box of width 1 in foreground color
2992 value
= make_number (1);
2994 if (UNSPECIFIEDP (value
) || IGNORE_DEFFACE_P (value
))
2996 else if (NILP (value
))
2998 else if (INTEGERP (value
))
2999 valid_p
= XINT (value
) != 0;
3000 else if (STRINGP (value
))
3001 valid_p
= SCHARS (value
) > 0;
3002 else if (CONSP (value
))
3018 if (EQ (k
, QCline_width
))
3020 if (!INTEGERP (v
) || XINT (v
) == 0)
3023 else if (EQ (k
, QCcolor
))
3025 if (!NILP (v
) && (!STRINGP (v
) || SCHARS (v
) == 0))
3028 else if (EQ (k
, QCstyle
))
3030 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
3037 valid_p
= NILP (tem
);
3043 signal_error ("Invalid face box", value
);
3045 old_value
= LFACE_BOX (lface
);
3046 LFACE_BOX (lface
) = value
;
3048 else if (EQ (attr
, QCinverse_video
)
3049 || EQ (attr
, QCreverse_video
))
3051 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3053 CHECK_SYMBOL (value
);
3054 if (!EQ (value
, Qt
) && !NILP (value
))
3055 signal_error ("Invalid inverse-video face attribute value", value
);
3057 old_value
= LFACE_INVERSE (lface
);
3058 LFACE_INVERSE (lface
) = value
;
3060 else if (EQ (attr
, QCforeground
))
3062 /* Compatibility with 20.x. */
3064 value
= Qunspecified
;
3065 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3067 /* Don't check for valid color names here because it depends
3068 on the frame (display) whether the color will be valid
3069 when the face is realized. */
3070 CHECK_STRING (value
);
3071 if (SCHARS (value
) == 0)
3072 signal_error ("Empty foreground color value", value
);
3074 old_value
= LFACE_FOREGROUND (lface
);
3075 LFACE_FOREGROUND (lface
) = value
;
3077 else if (EQ (attr
, QCbackground
))
3079 /* Compatibility with 20.x. */
3081 value
= Qunspecified
;
3082 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3084 /* Don't check for valid color names here because it depends
3085 on the frame (display) whether the color will be valid
3086 when the face is realized. */
3087 CHECK_STRING (value
);
3088 if (SCHARS (value
) == 0)
3089 signal_error ("Empty background color value", value
);
3091 old_value
= LFACE_BACKGROUND (lface
);
3092 LFACE_BACKGROUND (lface
) = value
;
3094 else if (EQ (attr
, QCstipple
))
3096 #if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
3097 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3099 && NILP (Fbitmap_spec_p (value
)))
3100 signal_error ("Invalid stipple attribute", value
);
3101 old_value
= LFACE_STIPPLE (lface
);
3102 LFACE_STIPPLE (lface
) = value
;
3103 #endif /* HAVE_X_WINDOWS || HAVE_NS */
3105 else if (EQ (attr
, QCwidth
))
3107 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3109 CHECK_SYMBOL (value
);
3110 if (FONT_WIDTH_NAME_NUMERIC (value
) < 0)
3111 signal_error ("Invalid face width", value
);
3113 old_value
= LFACE_SWIDTH (lface
);
3114 LFACE_SWIDTH (lface
) = value
;
3115 prop_index
= FONT_WIDTH_INDEX
;
3117 else if (EQ (attr
, QCfont
))
3119 #ifdef HAVE_WINDOW_SYSTEM
3120 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3122 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3126 old_value
= LFACE_FONT (lface
);
3127 if (! FONTP (value
))
3129 if (STRINGP (value
))
3131 Lisp_Object name
= value
;
3132 int fontset
= fs_query_fontset (name
, 0);
3135 name
= fontset_ascii (fontset
);
3136 value
= font_spec_from_name (name
);
3138 signal_error ("Invalid font name", name
);
3141 signal_error ("Invalid font or font-spec", value
);
3144 f
= XFRAME (selected_frame
);
3147 if (! FONT_OBJECT_P (value
))
3149 Lisp_Object
*attrs
= XVECTOR (lface
)->contents
;
3150 Lisp_Object font_object
;
3152 font_object
= font_load_for_lface (f
, attrs
, value
);
3153 if (NILP (font_object
))
3154 signal_error ("Font not available", value
);
3155 value
= font_object
;
3157 set_lface_from_font (f
, lface
, value
, 1);
3160 LFACE_FONT (lface
) = value
;
3162 #endif /* HAVE_WINDOW_SYSTEM */
3164 else if (EQ (attr
, QCfontset
))
3166 #ifdef HAVE_WINDOW_SYSTEM
3167 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3171 old_value
= LFACE_FONTSET (lface
);
3172 tmp
= Fquery_fontset (value
, Qnil
);
3174 signal_error ("Invalid fontset name", value
);
3175 LFACE_FONTSET (lface
) = value
= tmp
;
3177 #endif /* HAVE_WINDOW_SYSTEM */
3179 else if (EQ (attr
, QCinherit
))
3182 if (SYMBOLP (value
))
3185 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
3186 if (!SYMBOLP (XCAR (tail
)))
3189 LFACE_INHERIT (lface
) = value
;
3191 signal_error ("Invalid face inheritance", value
);
3193 else if (EQ (attr
, QCbold
))
3195 old_value
= LFACE_WEIGHT (lface
);
3196 LFACE_WEIGHT (lface
) = NILP (value
) ? Qnormal
: Qbold
;
3197 prop_index
= FONT_WEIGHT_INDEX
;
3199 else if (EQ (attr
, QCitalic
))
3202 old_value
= LFACE_SLANT (lface
);
3203 LFACE_SLANT (lface
) = NILP (value
) ? Qnormal
: Qitalic
;
3204 prop_index
= FONT_SLANT_INDEX
;
3207 signal_error ("Invalid face attribute name", attr
);
3211 /* If a font-related attribute other than QCfont and QCfontset
3212 is specified, and if the original QCfont attribute has a font
3213 (font-spec or font-object), set the corresponding property in
3214 the font to nil so that the font selector doesn't think that
3215 the attribute is mandatory. Also, clear the average
3217 font_clear_prop (XVECTOR (lface
)->contents
, prop_index
);
3220 /* Changing a named face means that all realized faces depending on
3221 that face are invalid. Since we cannot tell which realized faces
3222 depend on the face, make sure they are all removed. This is done
3223 by incrementing face_change_count. The next call to
3224 init_iterator will then free realized faces. */
3226 && NILP (Fget (face
, Qface_no_inherit
))
3227 && NILP (Fequal (old_value
, value
)))
3229 ++face_change_count
;
3230 ++windows_or_buffers_changed
;
3233 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3234 && NILP (Fequal (old_value
, value
)))
3240 if (EQ (face
, Qdefault
))
3242 #ifdef HAVE_WINDOW_SYSTEM
3243 /* Changed font-related attributes of the `default' face are
3244 reflected in changed `font' frame parameters. */
3246 && (prop_index
|| EQ (attr
, QCfont
))
3247 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
3248 set_font_frame_param (frame
, lface
);
3250 #endif /* HAVE_WINDOW_SYSTEM */
3252 if (EQ (attr
, QCforeground
))
3253 param
= Qforeground_color
;
3254 else if (EQ (attr
, QCbackground
))
3255 param
= Qbackground_color
;
3257 #ifdef HAVE_WINDOW_SYSTEM
3259 else if (EQ (face
, Qscroll_bar
))
3261 /* Changing the colors of `scroll-bar' sets frame parameters
3262 `scroll-bar-foreground' and `scroll-bar-background'. */
3263 if (EQ (attr
, QCforeground
))
3264 param
= Qscroll_bar_foreground
;
3265 else if (EQ (attr
, QCbackground
))
3266 param
= Qscroll_bar_background
;
3268 #endif /* not WINDOWSNT */
3269 else if (EQ (face
, Qborder
))
3271 /* Changing background color of `border' sets frame parameter
3273 if (EQ (attr
, QCbackground
))
3274 param
= Qborder_color
;
3276 else if (EQ (face
, Qcursor
))
3278 /* Changing background color of `cursor' sets frame parameter
3280 if (EQ (attr
, QCbackground
))
3281 param
= Qcursor_color
;
3283 else if (EQ (face
, Qmouse
))
3285 /* Changing background color of `mouse' sets frame parameter
3287 if (EQ (attr
, QCbackground
))
3288 param
= Qmouse_color
;
3290 #endif /* HAVE_WINDOW_SYSTEM */
3291 else if (EQ (face
, Qmenu
))
3293 /* Indicate that we have to update the menu bar when
3294 realizing faces on FRAME. FRAME t change the
3295 default for new frames. We do this by setting
3296 setting the flag in new face caches */
3299 struct frame
*f
= XFRAME (frame
);
3300 if (FRAME_FACE_CACHE (f
) == NULL
)
3301 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
3302 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 1;
3305 menu_face_changed_default
= 1;
3311 /* Update `default-frame-alist', which is used for new frames. */
3313 store_in_alist (&Vdefault_frame_alist
, param
, value
);
3316 /* Update the current frame's parameters. */
3319 cons
= XCAR (Vparam_value_alist
);
3320 XSETCAR (cons
, param
);
3321 XSETCDR (cons
, value
);
3322 Fmodify_frame_parameters (frame
, Vparam_value_alist
);
3331 /* Update the corresponding face when frame parameter PARAM on frame F
3332 has been assigned the value NEW_VALUE. */
3335 update_face_from_frame_parameter (struct frame
*f
, Lisp_Object param
, Lisp_Object new_value
)
3337 Lisp_Object face
= Qnil
;
3340 /* If there are no faces yet, give up. This is the case when called
3341 from Fx_create_frame, and we do the necessary things later in
3342 face-set-after-frame-defaults. */
3343 if (NILP (f
->face_alist
))
3346 if (EQ (param
, Qforeground_color
))
3349 lface
= lface_from_face_name (f
, face
, 1);
3350 LFACE_FOREGROUND (lface
) = (STRINGP (new_value
)
3351 ? new_value
: Qunspecified
);
3352 realize_basic_faces (f
);
3354 else if (EQ (param
, Qbackground_color
))
3358 /* Changing the background color might change the background
3359 mode, so that we have to load new defface specs.
3360 Call frame-update-face-colors to do that. */
3361 XSETFRAME (frame
, f
);
3362 call1 (Qframe_set_background_mode
, frame
);
3365 lface
= lface_from_face_name (f
, face
, 1);
3366 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3367 ? new_value
: Qunspecified
);
3368 realize_basic_faces (f
);
3370 #ifdef HAVE_WINDOW_SYSTEM
3371 else if (EQ (param
, Qborder_color
))
3374 lface
= lface_from_face_name (f
, face
, 1);
3375 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3376 ? new_value
: Qunspecified
);
3378 else if (EQ (param
, Qcursor_color
))
3381 lface
= lface_from_face_name (f
, face
, 1);
3382 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3383 ? new_value
: Qunspecified
);
3385 else if (EQ (param
, Qmouse_color
))
3388 lface
= lface_from_face_name (f
, face
, 1);
3389 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3390 ? new_value
: Qunspecified
);
3394 /* Changing a named face means that all realized faces depending on
3395 that face are invalid. Since we cannot tell which realized faces
3396 depend on the face, make sure they are all removed. This is done
3397 by incrementing face_change_count. The next call to
3398 init_iterator will then free realized faces. */
3400 && NILP (Fget (face
, Qface_no_inherit
)))
3402 ++face_change_count
;
3403 ++windows_or_buffers_changed
;
3408 #ifdef HAVE_WINDOW_SYSTEM
3410 /* Set the `font' frame parameter of FRAME determined from the
3411 font-object set in `default' face attributes LFACE. */
3414 set_font_frame_param (Lisp_Object frame
, Lisp_Object lface
)
3416 struct frame
*f
= XFRAME (frame
);
3419 if (FRAME_WINDOW_P (f
)
3420 /* Don't do anything if the font is `unspecified'. This can
3421 happen during frame creation. */
3422 && (font
= LFACE_FONT (lface
),
3423 ! UNSPECIFIEDP (font
)))
3425 if (FONT_SPEC_P (font
))
3427 font
= font_load_for_lface (f
, XVECTOR (lface
)->contents
, font
);
3430 LFACE_FONT (lface
) = font
;
3432 f
->default_face_done_p
= 0;
3433 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, font
), Qnil
));
3438 /* Get the value of X resource RESOURCE, class CLASS for the display
3439 of frame FRAME. This is here because ordinary `x-get-resource'
3440 doesn't take a frame argument. */
3442 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
3443 Sinternal_face_x_get_resource
, 3, 3, 0, doc
: /* */)
3444 (Lisp_Object resource
, Lisp_Object
class, Lisp_Object frame
)
3446 Lisp_Object value
= Qnil
;
3447 CHECK_STRING (resource
);
3448 CHECK_STRING (class);
3449 CHECK_LIVE_FRAME (frame
);
3451 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame
)),
3452 resource
, class, Qnil
, Qnil
);
3458 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
3459 If VALUE is "on" or "true", return t. If VALUE is "off" or
3460 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
3461 error; if SIGNAL_P is zero, return 0. */
3464 face_boolean_x_resource_value (Lisp_Object value
, int signal_p
)
3466 Lisp_Object result
= make_number (0);
3468 xassert (STRINGP (value
));
3470 if (xstrcasecmp (SSDATA (value
), "on") == 0
3471 || xstrcasecmp (SSDATA (value
), "true") == 0)
3473 else if (xstrcasecmp (SSDATA (value
), "off") == 0
3474 || xstrcasecmp (SSDATA (value
), "false") == 0)
3476 else if (xstrcasecmp (SSDATA (value
), "unspecified") == 0)
3477 result
= Qunspecified
;
3479 signal_error ("Invalid face attribute value from X resource", value
);
3485 DEFUN ("internal-set-lisp-face-attribute-from-resource",
3486 Finternal_set_lisp_face_attribute_from_resource
,
3487 Sinternal_set_lisp_face_attribute_from_resource
,
3488 3, 4, 0, doc
: /* */)
3489 (Lisp_Object face
, Lisp_Object attr
, Lisp_Object value
, Lisp_Object frame
)
3491 CHECK_SYMBOL (face
);
3492 CHECK_SYMBOL (attr
);
3493 CHECK_STRING (value
);
3495 if (xstrcasecmp (SSDATA (value
), "unspecified") == 0)
3496 value
= Qunspecified
;
3497 else if (EQ (attr
, QCheight
))
3499 value
= Fstring_to_number (value
, make_number (10));
3500 if (XINT (value
) <= 0)
3501 signal_error ("Invalid face height from X resource", value
);
3503 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
3504 value
= face_boolean_x_resource_value (value
, 1);
3505 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
3506 value
= intern (SSDATA (value
));
3507 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
3508 value
= face_boolean_x_resource_value (value
, 1);
3509 else if (EQ (attr
, QCunderline
)
3510 || EQ (attr
, QCoverline
)
3511 || EQ (attr
, QCstrike_through
))
3513 Lisp_Object boolean_value
;
3515 /* If the result of face_boolean_x_resource_value is t or nil,
3516 VALUE does NOT specify a color. */
3517 boolean_value
= face_boolean_x_resource_value (value
, 0);
3518 if (SYMBOLP (boolean_value
))
3519 value
= boolean_value
;
3521 else if (EQ (attr
, QCbox
) || EQ (attr
, QCinherit
))
3522 value
= Fcar (Fread_from_string (value
, Qnil
, Qnil
));
3524 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3527 #endif /* HAVE_WINDOW_SYSTEM */
3530 /***********************************************************************
3532 ***********************************************************************/
3534 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
3536 /* Make menus on frame F appear as specified by the `menu' face. */
3539 x_update_menu_appearance (struct frame
*f
)
3541 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3545 && (rdb
= XrmGetDatabase (FRAME_X_DISPLAY (f
)),
3549 Lisp_Object lface
= lface_from_face_name (f
, Qmenu
, 1);
3550 struct face
*face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
3551 const char *myname
= SSDATA (Vx_resource_name
);
3554 const char *popup_path
= "popup_menu";
3556 const char *popup_path
= "menu.popup";
3559 if (STRINGP (LFACE_FOREGROUND (lface
)))
3561 sprintf (line
, "%s.%s*foreground: %s",
3563 SDATA (LFACE_FOREGROUND (lface
)));
3564 XrmPutLineResource (&rdb
, line
);
3565 sprintf (line
, "%s.pane.menubar*foreground: %s",
3566 myname
, SDATA (LFACE_FOREGROUND (lface
)));
3567 XrmPutLineResource (&rdb
, line
);
3571 if (STRINGP (LFACE_BACKGROUND (lface
)))
3573 sprintf (line
, "%s.%s*background: %s",
3575 SDATA (LFACE_BACKGROUND (lface
)));
3576 XrmPutLineResource (&rdb
, line
);
3577 sprintf (line
, "%s.pane.menubar*background: %s",
3578 myname
, SDATA (LFACE_BACKGROUND (lface
)));
3579 XrmPutLineResource (&rdb
, line
);
3584 /* On Solaris 5.8, it's been reported that the `menu' face
3585 can be unspecified here, during startup. Why this
3586 happens remains unknown. -- cyd */
3587 && FONTP (LFACE_FONT (lface
))
3588 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
3589 || !UNSPECIFIEDP (LFACE_FOUNDRY (lface
))
3590 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
3591 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3592 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
3593 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
3595 Lisp_Object xlfd
= Ffont_xlfd_name (LFACE_FONT (lface
), Qnil
);
3597 const char *suffix
= "List";
3600 #if defined HAVE_X_I18N
3602 const char *suffix
= "Set";
3604 const char *suffix
= "";
3611 #if defined HAVE_X_I18N
3612 char *fontsetname
= xic_create_fontsetname (SSDATA (xlfd
), motif
);
3614 char *fontsetname
= SSDATA (xlfd
);
3616 sprintf (line
, "%s.pane.menubar*font%s: %s",
3617 myname
, suffix
, fontsetname
);
3618 XrmPutLineResource (&rdb
, line
);
3619 sprintf (line
, "%s.%s*font%s: %s",
3620 myname
, popup_path
, suffix
, fontsetname
);
3621 XrmPutLineResource (&rdb
, line
);
3623 if (fontsetname
!= SSDATA (xlfd
))
3624 xfree (fontsetname
);
3628 if (changed_p
&& f
->output_data
.x
->menubar_widget
)
3629 free_frame_menubar (f
);
3633 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
3636 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p
,
3637 Sface_attribute_relative_p
,
3639 doc
: /* Check whether a face attribute value is relative.
3640 Specifically, this function returns t if the attribute ATTRIBUTE
3641 with the value VALUE is relative.
3643 A relative value is one that doesn't entirely override whatever is
3644 inherited from another face. For most possible attributes,
3645 the only relative value that users see is `unspecified'.
3646 However, for :height, floating point values are also relative. */)
3647 (Lisp_Object attribute
, Lisp_Object value
)
3649 if (EQ (value
, Qunspecified
) || (EQ (value
, Qignore_defface
)))
3651 else if (EQ (attribute
, QCheight
))
3652 return INTEGERP (value
) ? Qnil
: Qt
;
3657 DEFUN ("merge-face-attribute", Fmerge_face_attribute
, Smerge_face_attribute
,
3659 doc
: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
3660 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
3661 the result will be absolute, otherwise it will be relative. */)
3662 (Lisp_Object attribute
, Lisp_Object value1
, Lisp_Object value2
)
3664 if (EQ (value1
, Qunspecified
) || EQ (value1
, Qignore_defface
))
3666 else if (EQ (attribute
, QCheight
))
3667 return merge_face_heights (value1
, value2
, value1
);
3673 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
3674 Sinternal_get_lisp_face_attribute
,
3676 doc
: /* Return face attribute KEYWORD of face SYMBOL.
3677 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
3678 face attribute name, signal an error.
3679 If the optional argument FRAME is given, report on face SYMBOL in that
3680 frame. If FRAME is t, report on the defaults for face SYMBOL (for new
3681 frames). If FRAME is omitted or nil, use the selected frame. */)
3682 (Lisp_Object symbol
, Lisp_Object keyword
, Lisp_Object frame
)
3684 Lisp_Object lface
, value
= Qnil
;
3686 CHECK_SYMBOL (symbol
);
3687 CHECK_SYMBOL (keyword
);
3690 lface
= lface_from_face_name (NULL
, symbol
, 1);
3694 frame
= selected_frame
;
3695 CHECK_LIVE_FRAME (frame
);
3696 lface
= lface_from_face_name (XFRAME (frame
), symbol
, 1);
3699 if (EQ (keyword
, QCfamily
))
3700 value
= LFACE_FAMILY (lface
);
3701 else if (EQ (keyword
, QCfoundry
))
3702 value
= LFACE_FOUNDRY (lface
);
3703 else if (EQ (keyword
, QCheight
))
3704 value
= LFACE_HEIGHT (lface
);
3705 else if (EQ (keyword
, QCweight
))
3706 value
= LFACE_WEIGHT (lface
);
3707 else if (EQ (keyword
, QCslant
))
3708 value
= LFACE_SLANT (lface
);
3709 else if (EQ (keyword
, QCunderline
))
3710 value
= LFACE_UNDERLINE (lface
);
3711 else if (EQ (keyword
, QCoverline
))
3712 value
= LFACE_OVERLINE (lface
);
3713 else if (EQ (keyword
, QCstrike_through
))
3714 value
= LFACE_STRIKE_THROUGH (lface
);
3715 else if (EQ (keyword
, QCbox
))
3716 value
= LFACE_BOX (lface
);
3717 else if (EQ (keyword
, QCinverse_video
)
3718 || EQ (keyword
, QCreverse_video
))
3719 value
= LFACE_INVERSE (lface
);
3720 else if (EQ (keyword
, QCforeground
))
3721 value
= LFACE_FOREGROUND (lface
);
3722 else if (EQ (keyword
, QCbackground
))
3723 value
= LFACE_BACKGROUND (lface
);
3724 else if (EQ (keyword
, QCstipple
))
3725 value
= LFACE_STIPPLE (lface
);
3726 else if (EQ (keyword
, QCwidth
))
3727 value
= LFACE_SWIDTH (lface
);
3728 else if (EQ (keyword
, QCinherit
))
3729 value
= LFACE_INHERIT (lface
);
3730 else if (EQ (keyword
, QCfont
))
3731 value
= LFACE_FONT (lface
);
3732 else if (EQ (keyword
, QCfontset
))
3733 value
= LFACE_FONTSET (lface
);
3735 signal_error ("Invalid face attribute name", keyword
);
3737 if (IGNORE_DEFFACE_P (value
))
3738 return Qunspecified
;
3744 DEFUN ("internal-lisp-face-attribute-values",
3745 Finternal_lisp_face_attribute_values
,
3746 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
3747 doc
: /* Return a list of valid discrete values for face attribute ATTR.
3748 Value is nil if ATTR doesn't have a discrete set of valid values. */)
3751 Lisp_Object result
= Qnil
;
3753 CHECK_SYMBOL (attr
);
3755 if (EQ (attr
, QCunderline
))
3756 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3757 else if (EQ (attr
, QCoverline
))
3758 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3759 else if (EQ (attr
, QCstrike_through
))
3760 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3761 else if (EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
3762 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3768 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
3769 Sinternal_merge_in_global_face
, 2, 2, 0,
3770 doc
: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
3771 Default face attributes override any local face attributes. */)
3772 (Lisp_Object face
, Lisp_Object frame
)
3775 Lisp_Object global_lface
, local_lface
, *gvec
, *lvec
;
3776 struct frame
*f
= XFRAME (frame
);
3778 CHECK_LIVE_FRAME (frame
);
3779 global_lface
= lface_from_face_name (NULL
, face
, 1);
3780 local_lface
= lface_from_face_name (f
, face
, 0);
3781 if (NILP (local_lface
))
3782 local_lface
= Finternal_make_lisp_face (face
, frame
);
3784 /* Make every specified global attribute override the local one.
3785 BEWARE!! This is only used from `face-set-after-frame-default' where
3786 the local frame is defined from default specs in `face-defface-spec'
3787 and those should be overridden by global settings. Hence the strange
3788 "global before local" priority. */
3789 lvec
= XVECTOR (local_lface
)->contents
;
3790 gvec
= XVECTOR (global_lface
)->contents
;
3791 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3792 if (IGNORE_DEFFACE_P (gvec
[i
]))
3793 lvec
[i
] = Qunspecified
;
3794 else if (! UNSPECIFIEDP (gvec
[i
]))
3797 /* If the default face was changed, update the face cache and the
3798 `font' frame parameter. */
3799 if (EQ (face
, Qdefault
))
3801 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
3802 struct face
*newface
, *oldface
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
3803 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
3805 /* This can be NULL (e.g., in batch mode). */
3808 /* Ensure that the face vector is fully specified by merging
3809 the previously-cached vector. */
3810 memcpy (attrs
, oldface
->lface
, sizeof attrs
);
3811 merge_face_vectors (f
, lvec
, attrs
, 0);
3812 memcpy (lvec
, attrs
, sizeof attrs
);
3813 newface
= realize_face (c
, lvec
, DEFAULT_FACE_ID
);
3815 if ((! UNSPECIFIEDP (gvec
[LFACE_FAMILY_INDEX
])
3816 || ! UNSPECIFIEDP (gvec
[LFACE_FOUNDRY_INDEX
])
3817 || ! UNSPECIFIEDP (gvec
[LFACE_HEIGHT_INDEX
])
3818 || ! UNSPECIFIEDP (gvec
[LFACE_WEIGHT_INDEX
])
3819 || ! UNSPECIFIEDP (gvec
[LFACE_SLANT_INDEX
])
3820 || ! UNSPECIFIEDP (gvec
[LFACE_SWIDTH_INDEX
])
3821 || ! UNSPECIFIEDP (gvec
[LFACE_FONT_INDEX
]))
3824 Lisp_Object name
= newface
->font
->props
[FONT_NAME_INDEX
];
3825 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, name
),
3835 /* The following function is implemented for compatibility with 20.2.
3836 The function is used in x-resolve-fonts when it is asked to
3837 return fonts with the same size as the font of a face. This is
3838 done in fontset.el. */
3840 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 3, 0,
3841 doc
: /* Return the font name of face FACE, or nil if it is unspecified.
3842 The font name is, by default, for ASCII characters.
3843 If the optional argument FRAME is given, report on face FACE in that frame.
3844 If FRAME is t, report on the defaults for face FACE (for new frames).
3845 The font default for a face is either nil, or a list
3846 of the form (bold), (italic) or (bold italic).
3847 If FRAME is omitted or nil, use the selected frame. And, in this case,
3848 if the optional third argument CHARACTER is given,
3849 return the font name used for CHARACTER. */)
3850 (Lisp_Object face
, Lisp_Object frame
, Lisp_Object character
)
3854 Lisp_Object result
= Qnil
;
3855 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
3857 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3858 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
3859 result
= Fcons (Qbold
, result
);
3861 if (!UNSPECIFIEDP (LFACE_SLANT (lface
))
3862 && !EQ (LFACE_SLANT (lface
), Qnormal
))
3863 result
= Fcons (Qitalic
, result
);
3869 struct frame
*f
= frame_or_selected_frame (frame
, 1);
3870 int face_id
= lookup_named_face (f
, face
, 1);
3871 struct face
*fface
= FACE_FROM_ID (f
, face_id
);
3875 #ifdef HAVE_WINDOW_SYSTEM
3876 if (FRAME_WINDOW_P (f
) && !NILP (character
))
3878 CHECK_CHARACTER (character
);
3879 face_id
= FACE_FOR_CHAR (f
, fface
, XINT (character
), -1, Qnil
);
3880 fface
= FACE_FROM_ID (f
, face_id
);
3883 ? fface
->font
->props
[FONT_NAME_INDEX
]
3885 #else /* !HAVE_WINDOW_SYSTEM */
3886 return build_string (FRAME_MSDOS_P (f
)
3888 : FRAME_W32_P (f
) ? "w32term"
3895 /* Compare face-attribute values v1 and v2 for equality. Value is non-zero if
3896 all attributes are `equal'. Tries to be fast because this function
3897 is called quite often. */
3900 face_attr_equal_p (Lisp_Object v1
, Lisp_Object v2
)
3902 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
3903 and the other is specified. */
3904 if (XTYPE (v1
) != XTYPE (v2
))
3913 if (SBYTES (v1
) != SBYTES (v2
))
3916 return memcmp (SDATA (v1
), SDATA (v2
), SBYTES (v1
)) == 0;
3923 return !NILP (Fequal (v1
, v2
));
3928 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
3929 all attributes are `equal'. Tries to be fast because this function
3930 is called quite often. */
3933 lface_equal_p (Lisp_Object
*v1
, Lisp_Object
*v2
)
3937 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
3938 equal_p
= face_attr_equal_p (v1
[i
], v2
[i
]);
3944 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
3945 Sinternal_lisp_face_equal_p
, 2, 3, 0,
3946 doc
: /* True if FACE1 and FACE2 are equal.
3947 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
3948 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
3949 If FRAME is omitted or nil, use the selected frame. */)
3950 (Lisp_Object face1
, Lisp_Object face2
, Lisp_Object frame
)
3954 Lisp_Object lface1
, lface2
;
3959 /* Don't use check_x_frame here because this function is called
3960 before X frames exist. At that time, if FRAME is nil,
3961 selected_frame will be used which is the frame dumped with
3962 Emacs. That frame is not an X frame. */
3963 f
= frame_or_selected_frame (frame
, 2);
3965 lface1
= lface_from_face_name (f
, face1
, 1);
3966 lface2
= lface_from_face_name (f
, face2
, 1);
3967 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
3968 XVECTOR (lface2
)->contents
);
3969 return equal_p
? Qt
: Qnil
;
3973 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
3974 Sinternal_lisp_face_empty_p
, 1, 2, 0,
3975 doc
: /* True if FACE has no attribute specified.
3976 If the optional argument FRAME is given, report on face FACE in that frame.
3977 If FRAME is t, report on the defaults for face FACE (for new frames).
3978 If FRAME is omitted or nil, use the selected frame. */)
3979 (Lisp_Object face
, Lisp_Object frame
)
3986 frame
= selected_frame
;
3987 CHECK_LIVE_FRAME (frame
);
3991 lface
= lface_from_face_name (NULL
, face
, 1);
3993 lface
= lface_from_face_name (f
, face
, 1);
3995 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3996 if (!UNSPECIFIEDP (AREF (lface
, i
)))
3999 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
4003 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
4005 doc
: /* Return an alist of frame-local faces defined on FRAME.
4006 For internal use only. */)
4009 struct frame
*f
= frame_or_selected_frame (frame
, 0);
4010 return f
->face_alist
;
4014 /* Return a hash code for Lisp string STRING with case ignored. Used
4015 below in computing a hash value for a Lisp face. */
4017 static INLINE
unsigned
4018 hash_string_case_insensitive (Lisp_Object string
)
4020 const unsigned char *s
;
4022 xassert (STRINGP (string
));
4023 for (s
= SDATA (string
); *s
; ++s
)
4024 hash
= (hash
<< 1) ^ tolower (*s
);
4029 /* Return a hash code for face attribute vector V. */
4031 static INLINE
unsigned
4032 lface_hash (Lisp_Object
*v
)
4034 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
4035 ^ hash_string_case_insensitive (v
[LFACE_FOUNDRY_INDEX
])
4036 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
4037 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
4038 ^ XHASH (v
[LFACE_WEIGHT_INDEX
])
4039 ^ XHASH (v
[LFACE_SLANT_INDEX
])
4040 ^ XHASH (v
[LFACE_SWIDTH_INDEX
])
4041 ^ XHASH (v
[LFACE_HEIGHT_INDEX
]));
4045 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
4046 considering charsets/registries). They do if they specify the same
4047 family, point size, weight, width, slant, and font. Both
4048 LFACE1 and LFACE2 must be fully-specified. */
4051 lface_same_font_attributes_p (Lisp_Object
*lface1
, Lisp_Object
*lface2
)
4053 xassert (lface_fully_specified_p (lface1
)
4054 && lface_fully_specified_p (lface2
));
4055 return (xstrcasecmp (SSDATA (lface1
[LFACE_FAMILY_INDEX
]),
4056 SSDATA (lface2
[LFACE_FAMILY_INDEX
])) == 0
4057 && xstrcasecmp (SSDATA (lface1
[LFACE_FOUNDRY_INDEX
]),
4058 SSDATA (lface2
[LFACE_FOUNDRY_INDEX
])) == 0
4059 && EQ (lface1
[LFACE_HEIGHT_INDEX
], lface2
[LFACE_HEIGHT_INDEX
])
4060 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
4061 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
4062 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
])
4063 && EQ (lface1
[LFACE_FONT_INDEX
], lface2
[LFACE_FONT_INDEX
])
4064 && (EQ (lface1
[LFACE_FONTSET_INDEX
], lface2
[LFACE_FONTSET_INDEX
])
4065 || (STRINGP (lface1
[LFACE_FONTSET_INDEX
])
4066 && STRINGP (lface2
[LFACE_FONTSET_INDEX
])
4067 && ! xstrcasecmp (SSDATA (lface1
[LFACE_FONTSET_INDEX
]),
4068 SSDATA (lface2
[LFACE_FONTSET_INDEX
]))))
4074 /***********************************************************************
4076 ***********************************************************************/
4078 /* Allocate and return a new realized face for Lisp face attribute
4081 static struct face
*
4082 make_realized_face (Lisp_Object
*attr
)
4084 struct face
*face
= (struct face
*) xmalloc (sizeof *face
);
4085 memset (face
, 0, sizeof *face
);
4086 face
->ascii_face
= face
;
4087 memcpy (face
->lface
, attr
, sizeof face
->lface
);
4092 /* Free realized face FACE, including its X resources. FACE may
4096 free_realized_face (struct frame
*f
, struct face
*face
)
4100 #ifdef HAVE_WINDOW_SYSTEM
4101 if (FRAME_WINDOW_P (f
))
4103 /* Free fontset of FACE if it is ASCII face. */
4104 if (face
->fontset
>= 0 && face
== face
->ascii_face
)
4105 free_face_fontset (f
, face
);
4110 font_done_for_face (f
, face
);
4111 x_free_gc (f
, face
->gc
);
4116 free_face_colors (f
, face
);
4117 x_destroy_bitmap (f
, face
->stipple
);
4119 #endif /* HAVE_WINDOW_SYSTEM */
4126 /* Prepare face FACE for subsequent display on frame F. This
4127 allocated GCs if they haven't been allocated yet or have been freed
4128 by clearing the face cache. */
4131 prepare_face_for_display (struct frame
*f
, struct face
*face
)
4133 #ifdef HAVE_WINDOW_SYSTEM
4134 xassert (FRAME_WINDOW_P (f
));
4139 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
4141 xgcv
.foreground
= face
->foreground
;
4142 xgcv
.background
= face
->background
;
4143 #ifdef HAVE_X_WINDOWS
4144 xgcv
.graphics_exposures
= False
;
4148 #ifdef HAVE_X_WINDOWS
4151 xgcv
.fill_style
= FillOpaqueStippled
;
4152 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
4153 mask
|= GCFillStyle
| GCStipple
;
4156 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
4158 font_prepare_for_face (f
, face
);
4161 #endif /* HAVE_WINDOW_SYSTEM */
4165 /* Returns the `distance' between the colors X and Y. */
4168 color_distance (XColor
*x
, XColor
*y
)
4170 /* This formula is from a paper title `Colour metric' by Thiadmer Riemersma.
4171 Quoting from that paper:
4173 This formula has results that are very close to L*u*v* (with the
4174 modified lightness curve) and, more importantly, it is a more even
4175 algorithm: it does not have a range of colours where it suddenly
4176 gives far from optimal results.
4178 See <http://www.compuphase.com/cmetric.htm> for more info. */
4180 long r
= (x
->red
- y
->red
) >> 8;
4181 long g
= (x
->green
- y
->green
) >> 8;
4182 long b
= (x
->blue
- y
->blue
) >> 8;
4183 long r_mean
= (x
->red
+ y
->red
) >> 9;
4186 (((512 + r_mean
) * r
* r
) >> 8)
4188 + (((767 - r_mean
) * b
* b
) >> 8);
4192 DEFUN ("color-distance", Fcolor_distance
, Scolor_distance
, 2, 3, 0,
4193 doc
: /* Return an integer distance between COLOR1 and COLOR2 on FRAME.
4194 COLOR1 and COLOR2 may be either strings containing the color name,
4195 or lists of the form (RED GREEN BLUE).
4196 If FRAME is unspecified or nil, the current frame is used. */)
4197 (Lisp_Object color1
, Lisp_Object color2
, Lisp_Object frame
)
4200 XColor cdef1
, cdef2
;
4203 frame
= selected_frame
;
4204 CHECK_LIVE_FRAME (frame
);
4207 if (!(CONSP (color1
) && parse_rgb_list (color1
, &cdef1
))
4208 && !(STRINGP (color1
) && defined_color (f
, SSDATA (color1
), &cdef1
, 0)))
4209 signal_error ("Invalid color", color1
);
4210 if (!(CONSP (color2
) && parse_rgb_list (color2
, &cdef2
))
4211 && !(STRINGP (color2
) && defined_color (f
, SSDATA (color2
), &cdef2
, 0)))
4212 signal_error ("Invalid color", color2
);
4214 return make_number (color_distance (&cdef1
, &cdef2
));
4218 /***********************************************************************
4220 ***********************************************************************/
4222 /* Return a new face cache for frame F. */
4224 static struct face_cache
*
4225 make_face_cache (struct frame
*f
)
4227 struct face_cache
*c
;
4230 c
= (struct face_cache
*) xmalloc (sizeof *c
);
4231 memset (c
, 0, sizeof *c
);
4232 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4233 c
->buckets
= (struct face
**) xmalloc (size
);
4234 memset (c
->buckets
, 0, size
);
4236 c
->faces_by_id
= (struct face
**) xmalloc (c
->size
* sizeof *c
->faces_by_id
);
4238 c
->menu_face_changed_p
= menu_face_changed_default
;
4243 /* Clear out all graphics contexts for all realized faces, except for
4244 the basic faces. This should be done from time to time just to avoid
4245 keeping too many graphics contexts that are no longer needed. */
4248 clear_face_gcs (struct face_cache
*c
)
4250 if (c
&& FRAME_WINDOW_P (c
->f
))
4252 #ifdef HAVE_WINDOW_SYSTEM
4254 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
4256 struct face
*face
= c
->faces_by_id
[i
];
4257 if (face
&& face
->gc
)
4261 font_done_for_face (c
->f
, face
);
4262 x_free_gc (c
->f
, face
->gc
);
4267 #endif /* HAVE_WINDOW_SYSTEM */
4272 /* Free all realized faces in face cache C, including basic faces.
4273 C may be null. If faces are freed, make sure the frame's current
4274 matrix is marked invalid, so that a display caused by an expose
4275 event doesn't try to use faces we destroyed. */
4278 free_realized_faces (struct face_cache
*c
)
4283 struct frame
*f
= c
->f
;
4285 /* We must block input here because we can't process X events
4286 safely while only some faces are freed, or when the frame's
4287 current matrix still references freed faces. */
4290 for (i
= 0; i
< c
->used
; ++i
)
4292 free_realized_face (f
, c
->faces_by_id
[i
]);
4293 c
->faces_by_id
[i
] = NULL
;
4297 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4298 memset (c
->buckets
, 0, size
);
4300 /* Must do a thorough redisplay the next time. Mark current
4301 matrices as invalid because they will reference faces freed
4302 above. This function is also called when a frame is
4303 destroyed. In this case, the root window of F is nil. */
4304 if (WINDOWP (f
->root_window
))
4306 clear_current_matrices (f
);
4307 ++windows_or_buffers_changed
;
4315 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
4316 This is done after attributes of a named face have been changed,
4317 because we can't tell which realized faces depend on that face. */
4320 free_all_realized_faces (Lisp_Object frame
)
4325 FOR_EACH_FRAME (rest
, frame
)
4326 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4329 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4333 /* Free face cache C and faces in it, including their X resources. */
4336 free_face_cache (struct face_cache
*c
)
4340 free_realized_faces (c
);
4342 xfree (c
->faces_by_id
);
4348 /* Cache realized face FACE in face cache C. HASH is the hash value
4349 of FACE. If FACE is for ASCII characters (i.e. FACE->ascii_face ==
4350 FACE), insert the new face to the beginning of the collision list
4351 of the face hash table of C. Otherwise, add the new face to the
4352 end of the collision list. This way, lookup_face can quickly find
4353 that a requested face is not cached. */
4356 cache_face (struct face_cache
*c
, struct face
*face
, unsigned int hash
)
4358 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4362 if (face
->ascii_face
!= face
)
4364 struct face
*last
= c
->buckets
[i
];
4375 c
->buckets
[i
] = face
;
4376 face
->prev
= face
->next
= NULL
;
4382 face
->next
= c
->buckets
[i
];
4384 face
->next
->prev
= face
;
4385 c
->buckets
[i
] = face
;
4388 /* Find a free slot in C->faces_by_id and use the index of the free
4389 slot as FACE->id. */
4390 for (i
= 0; i
< c
->used
; ++i
)
4391 if (c
->faces_by_id
[i
] == NULL
)
4395 /* Maybe enlarge C->faces_by_id. */
4398 if (c
->used
== c
->size
)
4401 new_size
= min (2 * c
->size
, MAX_FACE_ID
);
4402 if (new_size
== c
->size
)
4403 abort (); /* Alternatives? ++kfs */
4404 sz
= new_size
* sizeof *c
->faces_by_id
;
4405 c
->faces_by_id
= (struct face
**) xrealloc (c
->faces_by_id
, sz
);
4412 /* Check that FACE got a unique id. */
4417 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
4418 for (face
= c
->buckets
[j
]; face
; face
= face
->next
)
4424 #endif /* GLYPH_DEBUG */
4426 c
->faces_by_id
[i
] = face
;
4430 /* Remove face FACE from cache C. */
4433 uncache_face (struct face_cache
*c
, struct face
*face
)
4435 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
4438 face
->prev
->next
= face
->next
;
4440 c
->buckets
[i
] = face
->next
;
4443 face
->next
->prev
= face
->prev
;
4445 c
->faces_by_id
[face
->id
] = NULL
;
4446 if (face
->id
== c
->used
)
4451 /* Look up a realized face with face attributes ATTR in the face cache
4452 of frame F. The face will be used to display ASCII characters.
4453 Value is the ID of the face found. If no suitable face is found,
4454 realize a new one. */
4457 lookup_face (struct frame
*f
, Lisp_Object
*attr
)
4459 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4464 xassert (cache
!= NULL
);
4465 check_lface_attrs (attr
);
4467 /* Look up ATTR in the face cache. */
4468 hash
= lface_hash (attr
);
4469 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4471 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4473 if (face
->ascii_face
!= face
)
4475 /* There's no more ASCII face. */
4479 if (face
->hash
== hash
4480 && lface_equal_p (face
->lface
, attr
))
4484 /* If not found, realize a new face. */
4486 face
= realize_face (cache
, attr
, -1);
4489 xassert (face
== FACE_FROM_ID (f
, face
->id
));
4490 #endif /* GLYPH_DEBUG */
4495 #ifdef HAVE_WINDOW_SYSTEM
4496 /* Look up a realized face that has the same attributes as BASE_FACE
4497 except for the font in the face cache of frame F. If FONT-OBJECT
4498 is not nil, it is an already opened font. If FONT-OBJECT is nil,
4499 the face has no font. Value is the ID of the face found. If no
4500 suitable face is found, realize a new one. */
4503 face_for_font (struct frame
*f
, Lisp_Object font_object
, struct face
*base_face
)
4505 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4510 xassert (cache
!= NULL
);
4511 base_face
= base_face
->ascii_face
;
4512 hash
= lface_hash (base_face
->lface
);
4513 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4515 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4517 if (face
->ascii_face
== face
)
4519 if (face
->ascii_face
== base_face
4520 && face
->font
== (NILP (font_object
) ? NULL
4521 : XFONT_OBJECT (font_object
))
4522 && lface_equal_p (face
->lface
, base_face
->lface
))
4526 /* If not found, realize a new face. */
4527 face
= realize_non_ascii_face (f
, font_object
, base_face
);
4530 #endif /* HAVE_WINDOW_SYSTEM */
4532 /* Return the face id of the realized face for named face SYMBOL on
4533 frame F suitable for displaying ASCII characters. Value is -1 if
4534 the face couldn't be determined, which might happen if the default
4535 face isn't realized and cannot be realized. */
4538 lookup_named_face (struct frame
*f
, Lisp_Object symbol
, int signal_p
)
4540 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4541 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4542 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4544 if (default_face
== NULL
)
4546 if (!realize_basic_faces (f
))
4548 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4549 if (default_face
== NULL
)
4550 abort (); /* realize_basic_faces must have set it up */
4553 if (! get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4556 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4557 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4559 return lookup_face (f
, attrs
);
4563 /* Return the display face-id of the basic face who's canonical face-id
4564 is FACE_ID. The return value will usually simply be FACE_ID, unless that
4565 basic face has bee remapped via Vface_remapping_alist. This function is
4566 conservative: if something goes wrong, it will simply return FACE_ID
4567 rather than signal an error. */
4570 lookup_basic_face (struct frame
*f
, int face_id
)
4572 Lisp_Object name
, mapping
;
4573 int remapped_face_id
;
4575 if (NILP (Vface_remapping_alist
))
4576 return face_id
; /* Nothing to do. */
4580 case DEFAULT_FACE_ID
: name
= Qdefault
; break;
4581 case MODE_LINE_FACE_ID
: name
= Qmode_line
; break;
4582 case MODE_LINE_INACTIVE_FACE_ID
: name
= Qmode_line_inactive
; break;
4583 case HEADER_LINE_FACE_ID
: name
= Qheader_line
; break;
4584 case TOOL_BAR_FACE_ID
: name
= Qtool_bar
; break;
4585 case FRINGE_FACE_ID
: name
= Qfringe
; break;
4586 case SCROLL_BAR_FACE_ID
: name
= Qscroll_bar
; break;
4587 case BORDER_FACE_ID
: name
= Qborder
; break;
4588 case CURSOR_FACE_ID
: name
= Qcursor
; break;
4589 case MOUSE_FACE_ID
: name
= Qmouse
; break;
4590 case MENU_FACE_ID
: name
= Qmenu
; break;
4593 abort (); /* the caller is supposed to pass us a basic face id */
4596 /* Do a quick scan through Vface_remapping_alist, and return immediately
4597 if there is no remapping for face NAME. This is just an optimization
4598 for the very common no-remapping case. */
4599 mapping
= assq_no_quit (name
, Vface_remapping_alist
);
4601 return face_id
; /* Give up. */
4603 /* If there is a remapping entry, lookup the face using NAME, which will
4604 handle the remapping too. */
4605 remapped_face_id
= lookup_named_face (f
, name
, 0);
4606 if (remapped_face_id
< 0)
4607 return face_id
; /* Give up. */
4609 return remapped_face_id
;
4613 /* Return the ID of the realized ASCII face of Lisp face with ID
4614 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
4617 ascii_face_of_lisp_face (struct frame
*f
, int lface_id
)
4621 if (lface_id
>= 0 && lface_id
< lface_id_to_name_size
)
4623 Lisp_Object face_name
= lface_id_to_name
[lface_id
];
4624 face_id
= lookup_named_face (f
, face_name
, 1);
4633 /* Return a face for charset ASCII that is like the face with id
4634 FACE_ID on frame F, but has a font that is STEPS steps smaller.
4635 STEPS < 0 means larger. Value is the id of the face. */
4638 smaller_face (struct frame
*f
, int face_id
, int steps
)
4640 #ifdef HAVE_WINDOW_SYSTEM
4642 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4643 int pt
, last_pt
, last_height
;
4646 struct face
*new_face
;
4648 /* If not called for an X frame, just return the original face. */
4649 if (FRAME_TERMCAP_P (f
))
4652 /* Try in increments of 1/2 pt. */
4653 delta
= steps
< 0 ? 5 : -5;
4654 steps
= eabs (steps
);
4656 face
= FACE_FROM_ID (f
, face_id
);
4657 memcpy (attrs
, face
->lface
, sizeof attrs
);
4658 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
4659 new_face_id
= face_id
;
4660 last_height
= FONT_HEIGHT (face
->font
);
4664 /* Give up if we cannot find a font within 10pt. */
4665 && eabs (last_pt
- pt
) < 100)
4667 /* Look up a face for a slightly smaller/larger font. */
4669 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
4670 new_face_id
= lookup_face (f
, attrs
);
4671 new_face
= FACE_FROM_ID (f
, new_face_id
);
4673 /* If height changes, count that as one step. */
4674 if ((delta
< 0 && FONT_HEIGHT (new_face
->font
) < last_height
)
4675 || (delta
> 0 && FONT_HEIGHT (new_face
->font
) > last_height
))
4678 last_height
= FONT_HEIGHT (new_face
->font
);
4685 #else /* not HAVE_WINDOW_SYSTEM */
4689 #endif /* not HAVE_WINDOW_SYSTEM */
4693 /* Return a face for charset ASCII that is like the face with id
4694 FACE_ID on frame F, but has height HEIGHT. */
4697 face_with_height (struct frame
*f
, int face_id
, int height
)
4699 #ifdef HAVE_WINDOW_SYSTEM
4701 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4703 if (FRAME_TERMCAP_P (f
)
4707 face
= FACE_FROM_ID (f
, face_id
);
4708 memcpy (attrs
, face
->lface
, sizeof attrs
);
4709 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
4710 font_clear_prop (attrs
, FONT_SIZE_INDEX
);
4711 face_id
= lookup_face (f
, attrs
);
4712 #endif /* HAVE_WINDOW_SYSTEM */
4718 /* Return the face id of the realized face for named face SYMBOL on
4719 frame F suitable for displaying ASCII characters, and use
4720 attributes of the face FACE_ID for attributes that aren't
4721 completely specified by SYMBOL. This is like lookup_named_face,
4722 except that the default attributes come from FACE_ID, not from the
4723 default face. FACE_ID is assumed to be already realized. */
4726 lookup_derived_face (struct frame
*f
, Lisp_Object symbol
, int face_id
, int signal_p
)
4728 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4729 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4730 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
4735 if (!get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4738 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4739 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4740 return lookup_face (f
, attrs
);
4743 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector
,
4744 Sface_attributes_as_vector
, 1, 1, 0,
4745 doc
: /* Return a vector of face attributes corresponding to PLIST. */)
4749 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
4751 merge_face_ref (XFRAME (selected_frame
), plist
, XVECTOR (lface
)->contents
,
4758 /***********************************************************************
4759 Face capability testing
4760 ***********************************************************************/
4763 /* If the distance (as returned by color_distance) between two colors is
4764 less than this, then they are considered the same, for determining
4765 whether a color is supported or not. The range of values is 0-65535. */
4767 #define TTY_SAME_COLOR_THRESHOLD 10000
4769 #ifdef HAVE_WINDOW_SYSTEM
4771 /* Return non-zero if all the face attributes in ATTRS are supported
4772 on the window-system frame F.
4774 The definition of `supported' is somewhat heuristic, but basically means
4775 that a face containing all the attributes in ATTRS, when merged with the
4776 default face for display, can be represented in a way that's
4778 \(1) different in appearance than the default face, and
4779 \(2) `close in spirit' to what the attributes specify, if not exact. */
4782 x_supports_face_attributes_p (struct frame
*f
, Lisp_Object
*attrs
, struct face
*def_face
)
4784 Lisp_Object
*def_attrs
= def_face
->lface
;
4786 /* Check that other specified attributes are different that the default
4788 if ((!UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
4789 && face_attr_equal_p (attrs
[LFACE_UNDERLINE_INDEX
],
4790 def_attrs
[LFACE_UNDERLINE_INDEX
]))
4791 || (!UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
4792 && face_attr_equal_p (attrs
[LFACE_INVERSE_INDEX
],
4793 def_attrs
[LFACE_INVERSE_INDEX
]))
4794 || (!UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
4795 && face_attr_equal_p (attrs
[LFACE_FOREGROUND_INDEX
],
4796 def_attrs
[LFACE_FOREGROUND_INDEX
]))
4797 || (!UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
4798 && face_attr_equal_p (attrs
[LFACE_BACKGROUND_INDEX
],
4799 def_attrs
[LFACE_BACKGROUND_INDEX
]))
4800 || (!UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
4801 && face_attr_equal_p (attrs
[LFACE_STIPPLE_INDEX
],
4802 def_attrs
[LFACE_STIPPLE_INDEX
]))
4803 || (!UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
4804 && face_attr_equal_p (attrs
[LFACE_OVERLINE_INDEX
],
4805 def_attrs
[LFACE_OVERLINE_INDEX
]))
4806 || (!UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
4807 && face_attr_equal_p (attrs
[LFACE_STRIKE_THROUGH_INDEX
],
4808 def_attrs
[LFACE_STRIKE_THROUGH_INDEX
]))
4809 || (!UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
4810 && face_attr_equal_p (attrs
[LFACE_BOX_INDEX
],
4811 def_attrs
[LFACE_BOX_INDEX
])))
4814 /* Check font-related attributes, as those are the most commonly
4815 "unsupported" on a window-system (because of missing fonts). */
4816 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
4817 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
4818 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
4819 || !UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
4820 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
4821 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
]))
4825 Lisp_Object merged_attrs
[LFACE_VECTOR_SIZE
];
4828 memcpy (merged_attrs
, def_attrs
, sizeof merged_attrs
);
4830 merge_face_vectors (f
, attrs
, merged_attrs
, 0);
4832 face_id
= lookup_face (f
, merged_attrs
);
4833 face
= FACE_FROM_ID (f
, face_id
);
4836 error ("Cannot make face");
4838 /* If the font is the same, or no font is found, then not
4840 if (face
->font
== def_face
->font
4843 for (i
= FONT_TYPE_INDEX
; i
<= FONT_SIZE_INDEX
; i
++)
4844 if (! EQ (face
->font
->props
[i
], def_face
->font
->props
[i
]))
4848 if (i
< FONT_FOUNDRY_INDEX
|| i
> FONT_REGISTRY_INDEX
4849 || face
->font
->driver
->case_sensitive
)
4851 s1
= SYMBOL_NAME (face
->font
->props
[i
]);
4852 s2
= SYMBOL_NAME (def_face
->font
->props
[i
]);
4853 if (! EQ (Fcompare_strings (s1
, make_number (0), Qnil
,
4854 s2
, make_number (0), Qnil
, Qt
), Qt
))
4860 /* Everything checks out, this face is supported. */
4864 #endif /* HAVE_WINDOW_SYSTEM */
4866 /* Return non-zero if all the face attributes in ATTRS are supported
4869 The definition of `supported' is somewhat heuristic, but basically means
4870 that a face containing all the attributes in ATTRS, when merged
4871 with the default face for display, can be represented in a way that's
4873 \(1) different in appearance than the default face, and
4874 \(2) `close in spirit' to what the attributes specify, if not exact.
4876 Point (2) implies that a `:weight black' attribute will be satisfied
4877 by any terminal that can display bold, and a `:foreground "yellow"' as
4878 long as the terminal can display a yellowish color, but `:slant italic'
4879 will _not_ be satisfied by the tty display code's automatic
4880 substitution of a `dim' face for italic. */
4883 tty_supports_face_attributes_p (struct frame
*f
, Lisp_Object
*attrs
, struct face
*def_face
)
4886 Lisp_Object val
, fg
, bg
;
4887 XColor fg_tty_color
, fg_std_color
;
4888 XColor bg_tty_color
, bg_std_color
;
4889 unsigned test_caps
= 0;
4890 Lisp_Object
*def_attrs
= def_face
->lface
;
4893 /* First check some easy-to-check stuff; ttys support none of the
4894 following attributes, so we can just return false if any are requested
4895 (even if `nominal' values are specified, we should still return false,
4896 as that will be the same value that the default face uses). We
4897 consider :slant unsupportable on ttys, even though the face code
4898 actually `fakes' them using a dim attribute if possible. This is
4899 because the faked result is too different from what the face
4901 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
4902 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
4903 || !UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
4904 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
4905 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
4906 || !UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
4907 || !UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
4908 || !UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
4909 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
]))
4913 /* Test for terminal `capabilities' (non-color character attributes). */
4915 /* font weight (bold/dim) */
4916 val
= attrs
[LFACE_WEIGHT_INDEX
];
4917 if (!UNSPECIFIEDP (val
)
4918 && (weight
= FONT_WEIGHT_NAME_NUMERIC (val
), weight
>= 0))
4920 int def_weight
= FONT_WEIGHT_NAME_NUMERIC (def_attrs
[LFACE_WEIGHT_INDEX
]);
4924 if (def_weight
> 100)
4925 return 0; /* same as default */
4926 test_caps
= TTY_CAP_BOLD
;
4928 else if (weight
< 100)
4930 if (def_weight
< 100)
4931 return 0; /* same as default */
4932 test_caps
= TTY_CAP_DIM
;
4934 else if (def_weight
== 100)
4935 return 0; /* same as default */
4939 val
= attrs
[LFACE_UNDERLINE_INDEX
];
4940 if (!UNSPECIFIEDP (val
))
4943 return 0; /* ttys can't use colored underlines */
4944 else if (face_attr_equal_p (val
, def_attrs
[LFACE_UNDERLINE_INDEX
]))
4945 return 0; /* same as default */
4947 test_caps
|= TTY_CAP_UNDERLINE
;
4951 val
= attrs
[LFACE_INVERSE_INDEX
];
4952 if (!UNSPECIFIEDP (val
))
4954 if (face_attr_equal_p (val
, def_attrs
[LFACE_INVERSE_INDEX
]))
4955 return 0; /* same as default */
4957 test_caps
|= TTY_CAP_INVERSE
;
4961 /* Color testing. */
4963 /* Default the color indices in FG_TTY_COLOR and BG_TTY_COLOR, since
4964 we use them when calling `tty_capable_p' below, even if the face
4965 specifies no colors. */
4966 fg_tty_color
.pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
4967 bg_tty_color
.pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
4969 /* Check if foreground color is close enough. */
4970 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
4973 Lisp_Object def_fg
= def_attrs
[LFACE_FOREGROUND_INDEX
];
4975 if (face_attr_equal_p (fg
, def_fg
))
4976 return 0; /* same as default */
4977 else if (! tty_lookup_color (f
, fg
, &fg_tty_color
, &fg_std_color
))
4978 return 0; /* not a valid color */
4979 else if (color_distance (&fg_tty_color
, &fg_std_color
)
4980 > TTY_SAME_COLOR_THRESHOLD
)
4981 return 0; /* displayed color is too different */
4983 /* Make sure the color is really different than the default. */
4985 XColor def_fg_color
;
4986 if (tty_lookup_color (f
, def_fg
, &def_fg_color
, 0)
4987 && (color_distance (&fg_tty_color
, &def_fg_color
)
4988 <= TTY_SAME_COLOR_THRESHOLD
))
4993 /* Check if background color is close enough. */
4994 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
4997 Lisp_Object def_bg
= def_attrs
[LFACE_BACKGROUND_INDEX
];
4999 if (face_attr_equal_p (bg
, def_bg
))
5000 return 0; /* same as default */
5001 else if (! tty_lookup_color (f
, bg
, &bg_tty_color
, &bg_std_color
))
5002 return 0; /* not a valid color */
5003 else if (color_distance (&bg_tty_color
, &bg_std_color
)
5004 > TTY_SAME_COLOR_THRESHOLD
)
5005 return 0; /* displayed color is too different */
5007 /* Make sure the color is really different than the default. */
5009 XColor def_bg_color
;
5010 if (tty_lookup_color (f
, def_bg
, &def_bg_color
, 0)
5011 && (color_distance (&bg_tty_color
, &def_bg_color
)
5012 <= TTY_SAME_COLOR_THRESHOLD
))
5017 /* If both foreground and background are requested, see if the
5018 distance between them is OK. We just check to see if the distance
5019 between the tty's foreground and background is close enough to the
5020 distance between the standard foreground and background. */
5021 if (STRINGP (fg
) && STRINGP (bg
))
5024 = (color_distance (&fg_std_color
, &bg_std_color
)
5025 - color_distance (&fg_tty_color
, &bg_tty_color
));
5026 if (delta_delta
> TTY_SAME_COLOR_THRESHOLD
5027 || delta_delta
< -TTY_SAME_COLOR_THRESHOLD
)
5032 /* See if the capabilities we selected above are supported, with the
5034 if (test_caps
!= 0 &&
5035 ! tty_capable_p (FRAME_TTY (f
), test_caps
, fg_tty_color
.pixel
, bg_tty_color
.pixel
))
5039 /* Hmmm, everything checks out, this terminal must support this face. */
5044 DEFUN ("display-supports-face-attributes-p",
5045 Fdisplay_supports_face_attributes_p
, Sdisplay_supports_face_attributes_p
,
5047 doc
: /* Return non-nil if all the face attributes in ATTRIBUTES are supported.
5048 The optional argument DISPLAY can be a display name, a frame, or
5049 nil (meaning the selected frame's display).
5051 The definition of `supported' is somewhat heuristic, but basically means
5052 that a face containing all the attributes in ATTRIBUTES, when merged
5053 with the default face for display, can be represented in a way that's
5055 \(1) different in appearance than the default face, and
5056 \(2) `close in spirit' to what the attributes specify, if not exact.
5058 Point (2) implies that a `:weight black' attribute will be satisfied by
5059 any display that can display bold, and a `:foreground \"yellow\"' as long
5060 as it can display a yellowish color, but `:slant italic' will _not_ be
5061 satisfied by the tty display code's automatic substitution of a `dim'
5062 face for italic. */)
5063 (Lisp_Object attributes
, Lisp_Object display
)
5065 int supports
= 0, i
;
5068 struct face
*def_face
;
5069 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5071 if (noninteractive
|| !initialized
)
5072 /* We may not be able to access low-level face information in batch
5073 mode, or before being dumped, and this function is not going to
5074 be very useful in those cases anyway, so just give up. */
5078 frame
= selected_frame
;
5079 else if (FRAMEP (display
))
5083 /* Find any frame on DISPLAY. */
5084 Lisp_Object fl_tail
;
5087 for (fl_tail
= Vframe_list
; CONSP (fl_tail
); fl_tail
= XCDR (fl_tail
))
5089 frame
= XCAR (fl_tail
);
5090 if (!NILP (Fequal (Fcdr (Fassq (Qdisplay
,
5091 XFRAME (frame
)->param_alist
)),
5097 CHECK_LIVE_FRAME (frame
);
5100 for (i
= 0; i
< LFACE_VECTOR_SIZE
; i
++)
5101 attrs
[i
] = Qunspecified
;
5102 merge_face_ref (f
, attributes
, attrs
, 1, 0);
5104 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5105 if (def_face
== NULL
)
5107 if (! realize_basic_faces (f
))
5108 error ("Cannot realize default face");
5109 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5110 if (def_face
== NULL
)
5111 abort (); /* realize_basic_faces must have set it up */
5114 /* Dispatch to the appropriate handler. */
5115 if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5116 supports
= tty_supports_face_attributes_p (f
, attrs
, def_face
);
5117 #ifdef HAVE_WINDOW_SYSTEM
5119 supports
= x_supports_face_attributes_p (f
, attrs
, def_face
);
5122 return supports
? Qt
: Qnil
;
5126 /***********************************************************************
5128 ***********************************************************************/
5130 DEFUN ("internal-set-font-selection-order",
5131 Finternal_set_font_selection_order
,
5132 Sinternal_set_font_selection_order
, 1, 1, 0,
5133 doc
: /* Set font selection order for face font selection to ORDER.
5134 ORDER must be a list of length 4 containing the symbols `:width',
5135 `:height', `:weight', and `:slant'. Face attributes appearing
5136 first in ORDER are matched first, e.g. if `:height' appears before
5137 `:weight' in ORDER, font selection first tries to find a font with
5138 a suitable height, and then tries to match the font weight.
5144 int indices
[DIM (font_sort_order
)];
5147 memset (indices
, 0, sizeof indices
);
5151 CONSP (list
) && i
< DIM (indices
);
5152 list
= XCDR (list
), ++i
)
5154 Lisp_Object attr
= XCAR (list
);
5157 if (EQ (attr
, QCwidth
))
5159 else if (EQ (attr
, QCheight
))
5160 xlfd
= XLFD_POINT_SIZE
;
5161 else if (EQ (attr
, QCweight
))
5163 else if (EQ (attr
, QCslant
))
5168 if (indices
[i
] != 0)
5173 if (!NILP (list
) || i
!= DIM (indices
))
5174 signal_error ("Invalid font sort order", order
);
5175 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5176 if (indices
[i
] == 0)
5177 signal_error ("Invalid font sort order", order
);
5179 if (memcmp (indices
, font_sort_order
, sizeof indices
) != 0)
5181 memcpy (font_sort_order
, indices
, sizeof font_sort_order
);
5182 free_all_realized_faces (Qnil
);
5185 font_update_sort_order (font_sort_order
);
5191 DEFUN ("internal-set-alternative-font-family-alist",
5192 Finternal_set_alternative_font_family_alist
,
5193 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
5194 doc
: /* Define alternative font families to try in face font selection.
5195 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5196 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
5197 be found. Value is ALIST. */)
5200 Lisp_Object entry
, tail
, tail2
;
5203 alist
= Fcopy_sequence (alist
);
5204 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5206 entry
= XCAR (tail
);
5208 entry
= Fcopy_sequence (entry
);
5209 XSETCAR (tail
, entry
);
5210 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5211 XSETCAR (tail2
, Fintern (XCAR (tail2
), Qnil
));
5214 Vface_alternative_font_family_alist
= alist
;
5215 free_all_realized_faces (Qnil
);
5220 DEFUN ("internal-set-alternative-font-registry-alist",
5221 Finternal_set_alternative_font_registry_alist
,
5222 Sinternal_set_alternative_font_registry_alist
, 1, 1, 0,
5223 doc
: /* Define alternative font registries to try in face font selection.
5224 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5225 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
5226 be found. Value is ALIST. */)
5229 Lisp_Object entry
, tail
, tail2
;
5232 alist
= Fcopy_sequence (alist
);
5233 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5235 entry
= XCAR (tail
);
5237 entry
= Fcopy_sequence (entry
);
5238 XSETCAR (tail
, entry
);
5239 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5240 XSETCAR (tail2
, Fdowncase (XCAR (tail2
)));
5242 Vface_alternative_font_registry_alist
= alist
;
5243 free_all_realized_faces (Qnil
);
5248 #ifdef HAVE_WINDOW_SYSTEM
5250 /* Ignore the difference of font point size less than this value. */
5252 #define FONT_POINT_SIZE_QUANTUM 5
5254 /* Return the fontset id of the base fontset name or alias name given
5255 by the fontset attribute of ATTRS. Value is -1 if the fontset
5256 attribute of ATTRS doesn't name a fontset. */
5259 face_fontset (Lisp_Object
*attrs
)
5263 name
= attrs
[LFACE_FONTSET_INDEX
];
5264 if (!STRINGP (name
))
5266 return fs_query_fontset (name
, 0);
5269 #endif /* HAVE_WINDOW_SYSTEM */
5273 /***********************************************************************
5275 ***********************************************************************/
5277 /* Realize basic faces on frame F. Value is zero if frame parameters
5278 of F don't contain enough information needed to realize the default
5282 realize_basic_faces (struct frame
*f
)
5285 int count
= SPECPDL_INDEX ();
5287 /* Block input here so that we won't be surprised by an X expose
5288 event, for instance, without having the faces set up. */
5290 specbind (Qscalable_fonts_allowed
, Qt
);
5292 if (realize_default_face (f
))
5294 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
5295 realize_named_face (f
, Qmode_line_inactive
, MODE_LINE_INACTIVE_FACE_ID
);
5296 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
5297 realize_named_face (f
, Qfringe
, FRINGE_FACE_ID
);
5298 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
5299 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
5300 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
5301 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
5302 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
5303 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
5304 realize_named_face (f
, Qvertical_border
, VERTICAL_BORDER_FACE_ID
);
5306 /* Reflect changes in the `menu' face in menu bars. */
5307 if (FRAME_FACE_CACHE (f
)->menu_face_changed_p
)
5309 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 0;
5310 #ifdef USE_X_TOOLKIT
5311 if (FRAME_WINDOW_P (f
))
5312 x_update_menu_appearance (f
);
5319 unbind_to (count
, Qnil
);
5325 /* Realize the default face on frame F. If the face is not fully
5326 specified, make it fully-specified. Attributes of the default face
5327 that are not explicitly specified are taken from frame parameters. */
5330 realize_default_face (struct frame
*f
)
5332 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5334 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5337 /* If the `default' face is not yet known, create it. */
5338 lface
= lface_from_face_name (f
, Qdefault
, 0);
5342 XSETFRAME (frame
, f
);
5343 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
5346 #ifdef HAVE_WINDOW_SYSTEM
5347 if (FRAME_WINDOW_P (f
))
5349 Lisp_Object font_object
;
5351 XSETFONT (font_object
, FRAME_FONT (f
));
5352 set_lface_from_font (f
, lface
, font_object
, f
->default_face_done_p
);
5353 LFACE_FONTSET (lface
) = fontset_name (FRAME_FONTSET (f
));
5354 f
->default_face_done_p
= 1;
5356 #endif /* HAVE_WINDOW_SYSTEM */
5358 if (!FRAME_WINDOW_P (f
))
5360 LFACE_FAMILY (lface
) = build_string ("default");
5361 LFACE_FOUNDRY (lface
) = LFACE_FAMILY (lface
);
5362 LFACE_SWIDTH (lface
) = Qnormal
;
5363 LFACE_HEIGHT (lface
) = make_number (1);
5364 if (UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
5365 LFACE_WEIGHT (lface
) = Qnormal
;
5366 if (UNSPECIFIEDP (LFACE_SLANT (lface
)))
5367 LFACE_SLANT (lface
) = Qnormal
;
5368 if (UNSPECIFIEDP (LFACE_FONTSET (lface
)))
5369 LFACE_FONTSET (lface
) = Qnil
;
5372 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
5373 LFACE_UNDERLINE (lface
) = Qnil
;
5375 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
5376 LFACE_OVERLINE (lface
) = Qnil
;
5378 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
5379 LFACE_STRIKE_THROUGH (lface
) = Qnil
;
5381 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
5382 LFACE_BOX (lface
) = Qnil
;
5384 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
5385 LFACE_INVERSE (lface
) = Qnil
;
5387 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
5389 /* This function is called so early that colors are not yet
5390 set in the frame parameter list. */
5391 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
5393 if (CONSP (color
) && STRINGP (XCDR (color
)))
5394 LFACE_FOREGROUND (lface
) = XCDR (color
);
5395 else if (FRAME_WINDOW_P (f
))
5397 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5398 LFACE_FOREGROUND (lface
) = build_string (unspecified_fg
);
5403 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
5405 /* This function is called so early that colors are not yet
5406 set in the frame parameter list. */
5407 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
5408 if (CONSP (color
) && STRINGP (XCDR (color
)))
5409 LFACE_BACKGROUND (lface
) = XCDR (color
);
5410 else if (FRAME_WINDOW_P (f
))
5412 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5413 LFACE_BACKGROUND (lface
) = build_string (unspecified_bg
);
5418 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
5419 LFACE_STIPPLE (lface
) = Qnil
;
5421 /* Realize the face; it must be fully-specified now. */
5422 xassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
5423 check_lface (lface
);
5424 memcpy (attrs
, XVECTOR (lface
)->contents
, sizeof attrs
);
5425 face
= realize_face (c
, attrs
, DEFAULT_FACE_ID
);
5427 #ifdef HAVE_WINDOW_SYSTEM
5428 #ifdef HAVE_X_WINDOWS
5429 if (FRAME_X_P (f
) && face
->font
!= FRAME_FONT (f
))
5431 /* This can happen when making a frame on a display that does
5432 not support the default font. */
5436 /* Otherwise, the font specified for the frame was not
5437 acceptable as a font for the default face (perhaps because
5438 auto-scaled fonts are rejected), so we must adjust the frame
5440 x_set_font (f
, LFACE_FONT (lface
), Qnil
);
5442 #endif /* HAVE_X_WINDOWS */
5443 #endif /* HAVE_WINDOW_SYSTEM */
5448 /* Realize basic faces other than the default face in face cache C.
5449 SYMBOL is the face name, ID is the face id the realized face must
5450 have. The default face must have been realized already. */
5453 realize_named_face (struct frame
*f
, Lisp_Object symbol
, int id
)
5455 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5456 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
5457 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5458 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5459 struct face
*new_face
;
5461 /* The default face must exist and be fully specified. */
5462 get_lface_attributes_no_remap (f
, Qdefault
, attrs
, 1);
5463 check_lface_attrs (attrs
);
5464 xassert (lface_fully_specified_p (attrs
));
5466 /* If SYMBOL isn't know as a face, create it. */
5470 XSETFRAME (frame
, f
);
5471 lface
= Finternal_make_lisp_face (symbol
, frame
);
5474 /* Merge SYMBOL's face with the default face. */
5475 get_lface_attributes_no_remap (f
, symbol
, symbol_attrs
, 1);
5476 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
5478 /* Realize the face. */
5479 new_face
= realize_face (c
, attrs
, id
);
5483 /* Realize the fully-specified face with attributes ATTRS in face
5484 cache CACHE for ASCII characters. If FORMER_FACE_ID is
5485 non-negative, it is an ID of face to remove before caching the new
5486 face. Value is a pointer to the newly created realized face. */
5488 static struct face
*
5489 realize_face (struct face_cache
*cache
, Lisp_Object
*attrs
, int former_face_id
)
5493 /* LFACE must be fully specified. */
5494 xassert (cache
!= NULL
);
5495 check_lface_attrs (attrs
);
5497 if (former_face_id
>= 0 && cache
->used
> former_face_id
)
5499 /* Remove the former face. */
5500 struct face
*former_face
= cache
->faces_by_id
[former_face_id
];
5501 uncache_face (cache
, former_face
);
5502 free_realized_face (cache
->f
, former_face
);
5503 SET_FRAME_GARBAGED (cache
->f
);
5506 if (FRAME_WINDOW_P (cache
->f
))
5507 face
= realize_x_face (cache
, attrs
);
5508 else if (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
))
5509 face
= realize_tty_face (cache
, attrs
);
5510 else if (FRAME_INITIAL_P (cache
->f
))
5512 /* Create a dummy face. */
5513 face
= make_realized_face (attrs
);
5518 /* Insert the new face. */
5519 cache_face (cache
, face
, lface_hash (attrs
));
5524 #ifdef HAVE_WINDOW_SYSTEM
5525 /* Realize the fully-specified face that uses FONT-OBJECT and has the
5526 same attributes as BASE_FACE except for the font on frame F.
5527 FONT-OBJECT may be nil, in which case, realized a face of
5530 static struct face
*
5531 realize_non_ascii_face (struct frame
*f
, Lisp_Object font_object
, struct face
*base_face
)
5533 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5536 face
= (struct face
*) xmalloc (sizeof *face
);
5541 = (! NILP (font_object
)
5542 && FONT_WEIGHT_NAME_NUMERIC (face
->lface
[LFACE_WEIGHT_INDEX
]) > 100
5543 && FONT_WEIGHT_NUMERIC (font_object
) <= 100);
5545 /* Don't try to free the colors copied bitwise from BASE_FACE. */
5546 face
->colors_copied_bitwise_p
= 1;
5547 face
->font
= NILP (font_object
) ? NULL
: XFONT_OBJECT (font_object
);
5550 cache_face (cache
, face
, face
->hash
);
5554 #endif /* HAVE_WINDOW_SYSTEM */
5557 /* Realize the fully-specified face with attributes ATTRS in face
5558 cache CACHE for ASCII characters. Do it for X frame CACHE->f. If
5559 the new face doesn't share font with the default face, a fontname
5560 is allocated from the heap and set in `font_name' of the new face,
5561 but it is not yet loaded here. Value is a pointer to the newly
5562 created realized face. */
5564 static struct face
*
5565 realize_x_face (struct face_cache
*cache
, Lisp_Object
*attrs
)
5567 struct face
*face
= NULL
;
5568 #ifdef HAVE_WINDOW_SYSTEM
5569 struct face
*default_face
;
5571 Lisp_Object stipple
, overline
, strike_through
, box
;
5573 xassert (FRAME_WINDOW_P (cache
->f
));
5575 /* Allocate a new realized face. */
5576 face
= make_realized_face (attrs
);
5577 face
->ascii_face
= face
;
5581 /* Determine the font to use. Most of the time, the font will be
5582 the same as the font of the default face, so try that first. */
5583 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5585 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
5587 face
->font
= default_face
->font
;
5589 = make_fontset_for_ascii_face (f
, default_face
->fontset
, face
);
5593 /* If the face attribute ATTRS specifies a fontset, use it as
5594 the base of a new realized fontset. Otherwise, use the same
5595 base fontset as of the default face. The base determines
5596 registry and encoding of a font. It may also determine
5597 foundry and family. The other fields of font name pattern
5598 are constructed from ATTRS. */
5599 int fontset
= face_fontset (attrs
);
5601 /* If we are realizing the default face, ATTRS should specify a
5602 fontset. In other words, if FONTSET is -1, we are not
5603 realizing the default face, thus the default face should have
5604 already been realized. */
5608 fontset
= default_face
->fontset
;
5612 if (! FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5613 attrs
[LFACE_FONT_INDEX
]
5614 = font_load_for_lface (f
, attrs
, attrs
[LFACE_FONT_INDEX
]);
5615 if (FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5617 face
->font
= XFONT_OBJECT (attrs
[LFACE_FONT_INDEX
]);
5618 face
->fontset
= make_fontset_for_ascii_face (f
, fontset
, face
);
5628 && FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]) > 100
5629 && FONT_WEIGHT_NUMERIC (attrs
[LFACE_FONT_INDEX
]) <= 100)
5630 face
->overstrike
= 1;
5632 /* Load colors, and set remaining attributes. */
5634 load_face_colors (f
, face
, attrs
);
5637 box
= attrs
[LFACE_BOX_INDEX
];
5640 /* A simple box of line width 1 drawn in color given by
5642 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
5644 face
->box
= FACE_SIMPLE_BOX
;
5645 face
->box_line_width
= 1;
5647 else if (INTEGERP (box
))
5649 /* Simple box of specified line width in foreground color of the
5651 xassert (XINT (box
) != 0);
5652 face
->box
= FACE_SIMPLE_BOX
;
5653 face
->box_line_width
= XINT (box
);
5654 face
->box_color
= face
->foreground
;
5655 face
->box_color_defaulted_p
= 1;
5657 else if (CONSP (box
))
5659 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
5660 being one of `raised' or `sunken'. */
5661 face
->box
= FACE_SIMPLE_BOX
;
5662 face
->box_color
= face
->foreground
;
5663 face
->box_color_defaulted_p
= 1;
5664 face
->box_line_width
= 1;
5668 Lisp_Object keyword
, value
;
5670 keyword
= XCAR (box
);
5678 if (EQ (keyword
, QCline_width
))
5680 if (INTEGERP (value
) && XINT (value
) != 0)
5681 face
->box_line_width
= XINT (value
);
5683 else if (EQ (keyword
, QCcolor
))
5685 if (STRINGP (value
))
5687 face
->box_color
= load_color (f
, face
, value
,
5689 face
->use_box_color_for_shadows_p
= 1;
5692 else if (EQ (keyword
, QCstyle
))
5694 if (EQ (value
, Qreleased_button
))
5695 face
->box
= FACE_RAISED_BOX
;
5696 else if (EQ (value
, Qpressed_button
))
5697 face
->box
= FACE_SUNKEN_BOX
;
5702 /* Text underline, overline, strike-through. */
5704 if (EQ (attrs
[LFACE_UNDERLINE_INDEX
], Qt
))
5706 /* Use default color (same as foreground color). */
5707 face
->underline_p
= 1;
5708 face
->underline_defaulted_p
= 1;
5709 face
->underline_color
= 0;
5711 else if (STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]))
5713 /* Use specified color. */
5714 face
->underline_p
= 1;
5715 face
->underline_defaulted_p
= 0;
5716 face
->underline_color
5717 = load_color (f
, face
, attrs
[LFACE_UNDERLINE_INDEX
],
5718 LFACE_UNDERLINE_INDEX
);
5720 else if (NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5722 face
->underline_p
= 0;
5723 face
->underline_defaulted_p
= 0;
5724 face
->underline_color
= 0;
5727 overline
= attrs
[LFACE_OVERLINE_INDEX
];
5728 if (STRINGP (overline
))
5730 face
->overline_color
5731 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
5732 LFACE_OVERLINE_INDEX
);
5733 face
->overline_p
= 1;
5735 else if (EQ (overline
, Qt
))
5737 face
->overline_color
= face
->foreground
;
5738 face
->overline_color_defaulted_p
= 1;
5739 face
->overline_p
= 1;
5742 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
5743 if (STRINGP (strike_through
))
5745 face
->strike_through_color
5746 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
5747 LFACE_STRIKE_THROUGH_INDEX
);
5748 face
->strike_through_p
= 1;
5750 else if (EQ (strike_through
, Qt
))
5752 face
->strike_through_color
= face
->foreground
;
5753 face
->strike_through_color_defaulted_p
= 1;
5754 face
->strike_through_p
= 1;
5757 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
5758 if (!NILP (stipple
))
5759 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
5760 #endif /* HAVE_WINDOW_SYSTEM */
5766 /* Map a specified color of face FACE on frame F to a tty color index.
5767 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
5768 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
5769 default foreground/background colors. */
5772 map_tty_color (struct frame
*f
, struct face
*face
, enum lface_attribute_index idx
, int *defaulted
)
5774 Lisp_Object frame
, color
, def
;
5775 int foreground_p
= idx
== LFACE_FOREGROUND_INDEX
;
5776 unsigned long default_pixel
, default_other_pixel
, pixel
;
5778 xassert (idx
== LFACE_FOREGROUND_INDEX
|| idx
== LFACE_BACKGROUND_INDEX
);
5782 pixel
= default_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5783 default_other_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5787 pixel
= default_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5788 default_other_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5791 XSETFRAME (frame
, f
);
5792 color
= face
->lface
[idx
];
5796 && CONSP (Vtty_defined_color_alist
)
5797 && (def
= assq_no_quit (color
, call1 (Qtty_color_alist
, frame
)),
5800 /* Associations in tty-defined-color-alist are of the form
5801 (NAME INDEX R G B). We need the INDEX part. */
5802 pixel
= XINT (XCAR (XCDR (def
)));
5805 if (pixel
== default_pixel
&& STRINGP (color
))
5807 pixel
= load_color (f
, face
, color
, idx
);
5810 /* If the foreground of the default face is the default color,
5811 use the foreground color defined by the frame. */
5812 if (FRAME_MSDOS_P (f
))
5814 if (pixel
== default_pixel
5815 || pixel
== FACE_TTY_DEFAULT_COLOR
)
5818 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5820 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5821 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5824 else if (pixel
== default_other_pixel
)
5827 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5829 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5830 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5838 face
->foreground
= pixel
;
5840 face
->background
= pixel
;
5844 /* Realize the fully-specified face with attributes ATTRS in face
5845 cache CACHE for ASCII characters. Do it for TTY frame CACHE->f.
5846 Value is a pointer to the newly created realized face. */
5848 static struct face
*
5849 realize_tty_face (struct face_cache
*cache
, Lisp_Object
*attrs
)
5853 int face_colors_defaulted
= 0;
5854 struct frame
*f
= cache
->f
;
5856 /* Frame must be a termcap frame. */
5857 xassert (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
));
5859 /* Allocate a new realized face. */
5860 face
= make_realized_face (attrs
);
5862 face
->font_name
= FRAME_MSDOS_P (cache
->f
) ? "ms-dos" : "tty";
5865 /* Map face attributes to TTY appearances. We map slant to
5866 dimmed text because we want italic text to appear differently
5867 and because dimmed text is probably used infrequently. */
5868 weight
= FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]);
5869 slant
= FONT_SLANT_NAME_NUMERIC (attrs
[LFACE_SLANT_INDEX
]);
5871 face
->tty_bold_p
= 1;
5872 if (weight
< 100 || slant
!= 100)
5873 face
->tty_dim_p
= 1;
5874 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5875 face
->tty_underline_p
= 1;
5876 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
5877 face
->tty_reverse_p
= 1;
5879 /* Map color names to color indices. */
5880 map_tty_color (f
, face
, LFACE_FOREGROUND_INDEX
, &face_colors_defaulted
);
5881 map_tty_color (f
, face
, LFACE_BACKGROUND_INDEX
, &face_colors_defaulted
);
5883 /* Swap colors if face is inverse-video. If the colors are taken
5884 from the frame colors, they are already inverted, since the
5885 frame-creation function calls x-handle-reverse-video. */
5886 if (face
->tty_reverse_p
&& !face_colors_defaulted
)
5888 unsigned long tem
= face
->foreground
;
5889 face
->foreground
= face
->background
;
5890 face
->background
= tem
;
5893 if (tty_suppress_bold_inverse_default_colors_p
5895 && face
->background
== FACE_TTY_DEFAULT_FG_COLOR
5896 && face
->foreground
== FACE_TTY_DEFAULT_BG_COLOR
)
5897 face
->tty_bold_p
= 0;
5903 DEFUN ("tty-suppress-bold-inverse-default-colors",
5904 Ftty_suppress_bold_inverse_default_colors
,
5905 Stty_suppress_bold_inverse_default_colors
, 1, 1, 0,
5906 doc
: /* Suppress/allow boldness of faces with inverse default colors.
5907 SUPPRESS non-nil means suppress it.
5908 This affects bold faces on TTYs whose foreground is the default background
5909 color of the display and whose background is the default foreground color.
5910 For such faces, the bold face attribute is ignored if this variable
5912 (Lisp_Object suppress
)
5914 tty_suppress_bold_inverse_default_colors_p
= !NILP (suppress
);
5915 ++face_change_count
;
5921 /***********************************************************************
5923 ***********************************************************************/
5925 /* Return the ID of the face to use to display character CH with face
5926 property PROP on frame F in current_buffer. */
5929 compute_char_face (struct frame
*f
, int ch
, Lisp_Object prop
)
5933 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
5938 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5939 face_id
= FACE_FOR_CHAR (f
, face
, ch
, -1, Qnil
);
5943 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5944 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5945 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
5946 merge_face_ref (f
, prop
, attrs
, 1, 0);
5947 face_id
= lookup_face (f
, attrs
);
5953 /* Return the face ID associated with buffer position POS for
5954 displaying ASCII characters. Return in *ENDPTR the position at
5955 which a different face is needed, as far as text properties and
5956 overlays are concerned. W is a window displaying current_buffer.
5958 REGION_BEG, REGION_END delimit the region, so it can be
5961 LIMIT is a position not to scan beyond. That is to limit the time
5962 this function can take.
5964 If MOUSE is non-zero, use the character's mouse-face, not its face.
5966 BASE_FACE_ID, if non-negative, specifies a base face id to use
5967 instead of DEFAULT_FACE_ID.
5969 The face returned is suitable for displaying ASCII characters. */
5972 face_at_buffer_position (struct window
*w
, EMACS_INT pos
,
5973 EMACS_INT region_beg
, EMACS_INT region_end
,
5974 EMACS_INT
*endptr
, EMACS_INT limit
,
5975 int mouse
, int base_face_id
)
5977 struct frame
*f
= XFRAME (w
->frame
);
5978 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5979 Lisp_Object prop
, position
;
5981 Lisp_Object
*overlay_vec
;
5984 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
5985 Lisp_Object limit1
, end
;
5986 struct face
*default_face
;
5988 /* W must display the current buffer. We could write this function
5989 to use the frame and buffer of W, but right now it doesn't. */
5990 /* xassert (XBUFFER (w->buffer) == current_buffer); */
5992 XSETFRAME (frame
, f
);
5993 XSETFASTINT (position
, pos
);
5996 if (pos
< region_beg
&& region_beg
< endpos
)
5997 endpos
= region_beg
;
5999 /* Get the `face' or `mouse_face' text property at POS, and
6000 determine the next position at which the property changes. */
6001 prop
= Fget_text_property (position
, propname
, w
->buffer
);
6002 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6003 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
6005 endpos
= XINT (end
);
6007 /* Look at properties from overlays. */
6009 EMACS_INT next_overlay
;
6011 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, &next_overlay
, 0);
6012 if (next_overlay
< endpos
)
6013 endpos
= next_overlay
;
6018 default_face
= FACE_FROM_ID (f
, base_face_id
>= 0 ? base_face_id
6019 : NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
6020 : lookup_basic_face (f
, DEFAULT_FACE_ID
));
6022 /* Optimize common cases where we can use the default face. */
6025 && !(pos
>= region_beg
&& pos
< region_end
))
6026 return default_face
->id
;
6028 /* Begin with attributes from the default face. */
6029 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6031 /* Merge in attributes specified via text properties. */
6033 merge_face_ref (f
, prop
, attrs
, 1, 0);
6035 /* Now merge the overlay data. */
6036 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6037 for (i
= 0; i
< noverlays
; i
++)
6042 prop
= Foverlay_get (overlay_vec
[i
], propname
);
6044 merge_face_ref (f
, prop
, attrs
, 1, 0);
6046 oend
= OVERLAY_END (overlay_vec
[i
]);
6047 oendpos
= OVERLAY_POSITION (oend
);
6048 if (oendpos
< endpos
)
6052 /* If in the region, merge in the region face. */
6053 if (pos
>= region_beg
&& pos
< region_end
)
6055 merge_named_face (f
, Qregion
, attrs
, 0);
6057 if (region_end
< endpos
)
6058 endpos
= region_end
;
6063 /* Look up a realized face with the given face attributes,
6064 or realize a new one for ASCII characters. */
6065 return lookup_face (f
, attrs
);
6068 /* Return the face ID at buffer position POS for displaying ASCII
6069 characters associated with overlay strings for overlay OVERLAY.
6071 Like face_at_buffer_position except for OVERLAY. Currently it
6072 simply disregards the `face' properties of all overlays. */
6075 face_for_overlay_string (struct window
*w
, EMACS_INT pos
,
6076 EMACS_INT region_beg
, EMACS_INT region_end
,
6077 EMACS_INT
*endptr
, EMACS_INT limit
,
6078 int mouse
, Lisp_Object overlay
)
6080 struct frame
*f
= XFRAME (w
->frame
);
6081 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6082 Lisp_Object prop
, position
;
6085 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
6086 Lisp_Object limit1
, end
;
6087 struct face
*default_face
;
6089 /* W must display the current buffer. We could write this function
6090 to use the frame and buffer of W, but right now it doesn't. */
6091 /* xassert (XBUFFER (w->buffer) == current_buffer); */
6093 XSETFRAME (frame
, f
);
6094 XSETFASTINT (position
, pos
);
6097 if (pos
< region_beg
&& region_beg
< endpos
)
6098 endpos
= region_beg
;
6100 /* Get the `face' or `mouse_face' text property at POS, and
6101 determine the next position at which the property changes. */
6102 prop
= Fget_text_property (position
, propname
, w
->buffer
);
6103 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6104 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
6106 endpos
= XINT (end
);
6110 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6112 /* Optimize common cases where we can use the default face. */
6114 && !(pos
>= region_beg
&& pos
< region_end
))
6115 return DEFAULT_FACE_ID
;
6117 /* Begin with attributes from the default face. */
6118 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6120 /* Merge in attributes specified via text properties. */
6122 merge_face_ref (f
, prop
, attrs
, 1, 0);
6124 /* If in the region, merge in the region face. */
6125 if (pos
>= region_beg
&& pos
< region_end
)
6127 merge_named_face (f
, Qregion
, attrs
, 0);
6129 if (region_end
< endpos
)
6130 endpos
= region_end
;
6135 /* Look up a realized face with the given face attributes,
6136 or realize a new one for ASCII characters. */
6137 return lookup_face (f
, attrs
);
6141 /* Compute the face at character position POS in Lisp string STRING on
6142 window W, for ASCII characters.
6144 If STRING is an overlay string, it comes from position BUFPOS in
6145 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
6146 not an overlay string. W must display the current buffer.
6147 REGION_BEG and REGION_END give the start and end positions of the
6148 region; both are -1 if no region is visible.
6150 BASE_FACE_ID is the id of a face to merge with. For strings coming
6151 from overlays or the `display' property it is the face at BUFPOS.
6153 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
6155 Set *ENDPTR to the next position where to check for faces in
6156 STRING; -1 if the face is constant from POS to the end of the
6159 Value is the id of the face to use. The face returned is suitable
6160 for displaying ASCII characters. */
6163 face_at_string_position (struct window
*w
, Lisp_Object string
,
6164 EMACS_INT pos
, EMACS_INT bufpos
,
6165 EMACS_INT region_beg
, EMACS_INT region_end
,
6166 EMACS_INT
*endptr
, enum face_id base_face_id
,
6169 Lisp_Object prop
, position
, end
, limit
;
6170 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6171 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6172 struct face
*base_face
;
6173 int multibyte_p
= STRING_MULTIBYTE (string
);
6174 Lisp_Object prop_name
= mouse_p
? Qmouse_face
: Qface
;
6176 /* Get the value of the face property at the current position within
6177 STRING. Value is nil if there is no face property. */
6178 XSETFASTINT (position
, pos
);
6179 prop
= Fget_text_property (position
, prop_name
, string
);
6181 /* Get the next position at which to check for faces. Value of end
6182 is nil if face is constant all the way to the end of the string.
6183 Otherwise it is a string position where to check faces next.
6184 Limit is the maximum position up to which to check for property
6185 changes in Fnext_single_property_change. Strings are usually
6186 short, so set the limit to the end of the string. */
6187 XSETFASTINT (limit
, SCHARS (string
));
6188 end
= Fnext_single_property_change (position
, prop_name
, string
, limit
);
6190 *endptr
= XFASTINT (end
);
6194 base_face
= FACE_FROM_ID (f
, base_face_id
);
6195 xassert (base_face
);
6197 /* Optimize the default case that there is no face property and we
6198 are not in the region. */
6200 && (base_face_id
!= DEFAULT_FACE_ID
6201 /* BUFPOS <= 0 means STRING is not an overlay string, so
6202 that the region doesn't have to be taken into account. */
6204 || bufpos
< region_beg
6205 || bufpos
>= region_end
)
6207 /* We can't realize faces for different charsets differently
6208 if we don't have fonts, so we can stop here if not working
6209 on a window-system frame. */
6210 || !FRAME_WINDOW_P (f
)
6211 || FACE_SUITABLE_FOR_CHAR_P (base_face
, 0)))
6212 return base_face
->id
;
6214 /* Begin with attributes from the base face. */
6215 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6217 /* Merge in attributes specified via text properties. */
6219 merge_face_ref (f
, prop
, attrs
, 1, 0);
6221 /* If in the region, merge in the region face. */
6223 && bufpos
>= region_beg
6224 && bufpos
< region_end
)
6225 merge_named_face (f
, Qregion
, attrs
, 0);
6227 /* Look up a realized face with the given face attributes,
6228 or realize a new one for ASCII characters. */
6229 return lookup_face (f
, attrs
);
6233 /* Merge a face into a realized face.
6235 F is frame where faces are (to be) realized.
6237 FACE_NAME is named face to merge.
6239 If FACE_NAME is nil, FACE_ID is face_id of realized face to merge.
6241 If FACE_NAME is t, FACE_ID is lface_id of face to merge.
6243 BASE_FACE_ID is realized face to merge into.
6249 merge_faces (struct frame
*f
, Lisp_Object face_name
, int face_id
, int base_face_id
)
6251 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6252 struct face
*base_face
;
6254 base_face
= FACE_FROM_ID (f
, base_face_id
);
6256 return base_face_id
;
6258 if (EQ (face_name
, Qt
))
6260 if (face_id
< 0 || face_id
>= lface_id_to_name_size
)
6261 return base_face_id
;
6262 face_name
= lface_id_to_name
[face_id
];
6263 /* When called during make-frame, lookup_derived_face may fail
6264 if the faces are uninitialized. Don't signal an error. */
6265 face_id
= lookup_derived_face (f
, face_name
, base_face_id
, 0);
6266 return (face_id
>= 0 ? face_id
: base_face_id
);
6269 /* Begin with attributes from the base face. */
6270 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6272 if (!NILP (face_name
))
6274 if (!merge_named_face (f
, face_name
, attrs
, 0))
6275 return base_face_id
;
6281 return base_face_id
;
6282 face
= FACE_FROM_ID (f
, face_id
);
6284 return base_face_id
;
6285 merge_face_vectors (f
, face
->lface
, attrs
, 0);
6288 /* Look up a realized face with the given face attributes,
6289 or realize a new one for ASCII characters. */
6290 return lookup_face (f
, attrs
);
6295 #ifndef HAVE_X_WINDOWS
6296 DEFUN ("x-load-color-file", Fx_load_color_file
,
6297 Sx_load_color_file
, 1, 1, 0,
6298 doc
: /* Create an alist of color entries from an external file.
6300 The file should define one named RGB color per line like so:
6302 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6303 (Lisp_Object filename
)
6306 Lisp_Object cmap
= Qnil
;
6307 Lisp_Object abspath
;
6309 CHECK_STRING (filename
);
6310 abspath
= Fexpand_file_name (filename
, Qnil
);
6312 fp
= fopen (SDATA (filename
), "rt");
6316 int red
, green
, blue
;
6321 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
6322 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
6324 char *name
= buf
+ num
;
6325 num
= strlen (name
) - 1;
6326 if (num
>= 0 && name
[num
] == '\n')
6328 cmap
= Fcons (Fcons (build_string (name
),
6330 make_number (RGB (red
, green
, blue
))),
6332 make_number ((red
<< 16) | (green
<< 8) | blue
)),
6347 /***********************************************************************
6349 ***********************************************************************/
6353 /* Print the contents of the realized face FACE to stderr. */
6356 dump_realized_face (face
)
6359 fprintf (stderr
, "ID: %d\n", face
->id
);
6360 #ifdef HAVE_X_WINDOWS
6361 fprintf (stderr
, "gc: %ld\n", (long) face
->gc
);
6363 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
6365 SDATA (face
->lface
[LFACE_FOREGROUND_INDEX
]));
6366 fprintf (stderr
, "background: 0x%lx (%s)\n",
6368 SDATA (face
->lface
[LFACE_BACKGROUND_INDEX
]));
6370 fprintf (stderr
, "font_name: %s (%s)\n",
6371 SDATA (face
->font
->props
[FONT_NAME_INDEX
]),
6372 SDATA (face
->lface
[LFACE_FAMILY_INDEX
]));
6373 #ifdef HAVE_X_WINDOWS
6374 fprintf (stderr
, "font = %p\n", face
->font
);
6376 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
6377 fprintf (stderr
, "underline: %d (%s)\n",
6379 SDATA (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
])));
6380 fprintf (stderr
, "hash: %d\n", face
->hash
);
6384 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, doc
: /* */)
6391 fprintf (stderr
, "font selection order: ");
6392 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6393 fprintf (stderr
, "%d ", font_sort_order
[i
]);
6394 fprintf (stderr
, "\n");
6396 fprintf (stderr
, "alternative fonts: ");
6397 debug_print (Vface_alternative_font_family_alist
);
6398 fprintf (stderr
, "\n");
6400 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
6401 Fdump_face (make_number (i
));
6407 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
6409 error ("Not a valid face");
6410 dump_realized_face (face
);
6417 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
6418 0, 0, 0, doc
: /* */)
6421 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
6422 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
6423 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
6427 #endif /* GLYPH_DEBUG != 0 */
6431 /***********************************************************************
6433 ***********************************************************************/
6436 syms_of_xfaces (void)
6438 Qface
= intern_c_string ("face");
6440 Qface_no_inherit
= intern_c_string ("face-no-inherit");
6441 staticpro (&Qface_no_inherit
);
6442 Qbitmap_spec_p
= intern_c_string ("bitmap-spec-p");
6443 staticpro (&Qbitmap_spec_p
);
6444 Qframe_set_background_mode
= intern_c_string ("frame-set-background-mode");
6445 staticpro (&Qframe_set_background_mode
);
6447 /* Lisp face attribute keywords. */
6448 QCfamily
= intern_c_string (":family");
6449 staticpro (&QCfamily
);
6450 QCheight
= intern_c_string (":height");
6451 staticpro (&QCheight
);
6452 QCweight
= intern_c_string (":weight");
6453 staticpro (&QCweight
);
6454 QCslant
= intern_c_string (":slant");
6455 staticpro (&QCslant
);
6456 QCunderline
= intern_c_string (":underline");
6457 staticpro (&QCunderline
);
6458 QCinverse_video
= intern_c_string (":inverse-video");
6459 staticpro (&QCinverse_video
);
6460 QCreverse_video
= intern_c_string (":reverse-video");
6461 staticpro (&QCreverse_video
);
6462 QCforeground
= intern_c_string (":foreground");
6463 staticpro (&QCforeground
);
6464 QCbackground
= intern_c_string (":background");
6465 staticpro (&QCbackground
);
6466 QCstipple
= intern_c_string (":stipple");
6467 staticpro (&QCstipple
);
6468 QCwidth
= intern_c_string (":width");
6469 staticpro (&QCwidth
);
6470 QCfont
= intern_c_string (":font");
6471 staticpro (&QCfont
);
6472 QCfontset
= intern_c_string (":fontset");
6473 staticpro (&QCfontset
);
6474 QCbold
= intern_c_string (":bold");
6475 staticpro (&QCbold
);
6476 QCitalic
= intern_c_string (":italic");
6477 staticpro (&QCitalic
);
6478 QCoverline
= intern_c_string (":overline");
6479 staticpro (&QCoverline
);
6480 QCstrike_through
= intern_c_string (":strike-through");
6481 staticpro (&QCstrike_through
);
6482 QCbox
= intern_c_string (":box");
6484 QCinherit
= intern_c_string (":inherit");
6485 staticpro (&QCinherit
);
6487 /* Symbols used for Lisp face attribute values. */
6488 QCcolor
= intern_c_string (":color");
6489 staticpro (&QCcolor
);
6490 QCline_width
= intern_c_string (":line-width");
6491 staticpro (&QCline_width
);
6492 QCstyle
= intern_c_string (":style");
6493 staticpro (&QCstyle
);
6494 Qreleased_button
= intern_c_string ("released-button");
6495 staticpro (&Qreleased_button
);
6496 Qpressed_button
= intern_c_string ("pressed-button");
6497 staticpro (&Qpressed_button
);
6498 Qnormal
= intern_c_string ("normal");
6499 staticpro (&Qnormal
);
6500 Qultra_light
= intern_c_string ("ultra-light");
6501 staticpro (&Qultra_light
);
6502 Qextra_light
= intern_c_string ("extra-light");
6503 staticpro (&Qextra_light
);
6504 Qlight
= intern_c_string ("light");
6505 staticpro (&Qlight
);
6506 Qsemi_light
= intern_c_string ("semi-light");
6507 staticpro (&Qsemi_light
);
6508 Qsemi_bold
= intern_c_string ("semi-bold");
6509 staticpro (&Qsemi_bold
);
6510 Qbold
= intern_c_string ("bold");
6512 Qextra_bold
= intern_c_string ("extra-bold");
6513 staticpro (&Qextra_bold
);
6514 Qultra_bold
= intern_c_string ("ultra-bold");
6515 staticpro (&Qultra_bold
);
6516 Qoblique
= intern_c_string ("oblique");
6517 staticpro (&Qoblique
);
6518 Qitalic
= intern_c_string ("italic");
6519 staticpro (&Qitalic
);
6520 Qreverse_oblique
= intern_c_string ("reverse-oblique");
6521 staticpro (&Qreverse_oblique
);
6522 Qreverse_italic
= intern_c_string ("reverse-italic");
6523 staticpro (&Qreverse_italic
);
6524 Qultra_condensed
= intern_c_string ("ultra-condensed");
6525 staticpro (&Qultra_condensed
);
6526 Qextra_condensed
= intern_c_string ("extra-condensed");
6527 staticpro (&Qextra_condensed
);
6528 Qcondensed
= intern_c_string ("condensed");
6529 staticpro (&Qcondensed
);
6530 Qsemi_condensed
= intern_c_string ("semi-condensed");
6531 staticpro (&Qsemi_condensed
);
6532 Qsemi_expanded
= intern_c_string ("semi-expanded");
6533 staticpro (&Qsemi_expanded
);
6534 Qexpanded
= intern_c_string ("expanded");
6535 staticpro (&Qexpanded
);
6536 Qextra_expanded
= intern_c_string ("extra-expanded");
6537 staticpro (&Qextra_expanded
);
6538 Qultra_expanded
= intern_c_string ("ultra-expanded");
6539 staticpro (&Qultra_expanded
);
6540 Qbackground_color
= intern_c_string ("background-color");
6541 staticpro (&Qbackground_color
);
6542 Qforeground_color
= intern_c_string ("foreground-color");
6543 staticpro (&Qforeground_color
);
6544 Qunspecified
= intern_c_string ("unspecified");
6545 staticpro (&Qunspecified
);
6546 Qignore_defface
= intern_c_string (":ignore-defface");
6547 staticpro (&Qignore_defface
);
6549 Qface_alias
= intern_c_string ("face-alias");
6550 staticpro (&Qface_alias
);
6551 Qdefault
= intern_c_string ("default");
6552 staticpro (&Qdefault
);
6553 Qtool_bar
= intern_c_string ("tool-bar");
6554 staticpro (&Qtool_bar
);
6555 Qregion
= intern_c_string ("region");
6556 staticpro (&Qregion
);
6557 Qfringe
= intern_c_string ("fringe");
6558 staticpro (&Qfringe
);
6559 Qheader_line
= intern_c_string ("header-line");
6560 staticpro (&Qheader_line
);
6561 Qscroll_bar
= intern_c_string ("scroll-bar");
6562 staticpro (&Qscroll_bar
);
6563 Qmenu
= intern_c_string ("menu");
6565 Qcursor
= intern_c_string ("cursor");
6566 staticpro (&Qcursor
);
6567 Qborder
= intern_c_string ("border");
6568 staticpro (&Qborder
);
6569 Qmouse
= intern_c_string ("mouse");
6570 staticpro (&Qmouse
);
6571 Qmode_line_inactive
= intern_c_string ("mode-line-inactive");
6572 staticpro (&Qmode_line_inactive
);
6573 Qvertical_border
= intern_c_string ("vertical-border");
6574 staticpro (&Qvertical_border
);
6575 Qtty_color_desc
= intern_c_string ("tty-color-desc");
6576 staticpro (&Qtty_color_desc
);
6577 Qtty_color_standard_values
= intern_c_string ("tty-color-standard-values");
6578 staticpro (&Qtty_color_standard_values
);
6579 Qtty_color_by_index
= intern_c_string ("tty-color-by-index");
6580 staticpro (&Qtty_color_by_index
);
6581 Qtty_color_alist
= intern_c_string ("tty-color-alist");
6582 staticpro (&Qtty_color_alist
);
6583 Qscalable_fonts_allowed
= intern_c_string ("scalable-fonts-allowed");
6584 staticpro (&Qscalable_fonts_allowed
);
6586 Vparam_value_alist
= Fcons (Fcons (Qnil
, Qnil
), Qnil
);
6587 staticpro (&Vparam_value_alist
);
6588 Vface_alternative_font_family_alist
= Qnil
;
6589 staticpro (&Vface_alternative_font_family_alist
);
6590 Vface_alternative_font_registry_alist
= Qnil
;
6591 staticpro (&Vface_alternative_font_registry_alist
);
6593 defsubr (&Sinternal_make_lisp_face
);
6594 defsubr (&Sinternal_lisp_face_p
);
6595 defsubr (&Sinternal_set_lisp_face_attribute
);
6596 #ifdef HAVE_WINDOW_SYSTEM
6597 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
6599 defsubr (&Scolor_gray_p
);
6600 defsubr (&Scolor_supported_p
);
6601 #ifndef HAVE_X_WINDOWS
6602 defsubr (&Sx_load_color_file
);
6604 defsubr (&Sface_attribute_relative_p
);
6605 defsubr (&Smerge_face_attribute
);
6606 defsubr (&Sinternal_get_lisp_face_attribute
);
6607 defsubr (&Sinternal_lisp_face_attribute_values
);
6608 defsubr (&Sinternal_lisp_face_equal_p
);
6609 defsubr (&Sinternal_lisp_face_empty_p
);
6610 defsubr (&Sinternal_copy_lisp_face
);
6611 defsubr (&Sinternal_merge_in_global_face
);
6612 defsubr (&Sface_font
);
6613 defsubr (&Sframe_face_alist
);
6614 defsubr (&Sdisplay_supports_face_attributes_p
);
6615 defsubr (&Scolor_distance
);
6616 defsubr (&Sinternal_set_font_selection_order
);
6617 defsubr (&Sinternal_set_alternative_font_family_alist
);
6618 defsubr (&Sinternal_set_alternative_font_registry_alist
);
6619 defsubr (&Sface_attributes_as_vector
);
6621 defsubr (&Sdump_face
);
6622 defsubr (&Sshow_face_resources
);
6623 #endif /* GLYPH_DEBUG */
6624 defsubr (&Sclear_face_cache
);
6625 defsubr (&Stty_suppress_bold_inverse_default_colors
);
6627 #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS
6628 defsubr (&Sdump_colors
);
6631 DEFVAR_LISP ("font-list-limit", Vfont_list_limit
,
6632 doc
: /* *Limit for font matching.
6633 If an integer > 0, font matching functions won't load more than
6634 that number of fonts when searching for a matching font. */);
6635 Vfont_list_limit
= make_number (DEFAULT_FONT_LIST_LIMIT
);
6637 DEFVAR_LISP ("face-new-frame-defaults", Vface_new_frame_defaults
,
6638 doc
: /* List of global face definitions (for internal use only.) */);
6639 Vface_new_frame_defaults
= Qnil
;
6641 DEFVAR_LISP ("face-default-stipple", Vface_default_stipple
,
6642 doc
: /* *Default stipple pattern used on monochrome displays.
6643 This stipple pattern is used on monochrome displays
6644 instead of shades of gray for a face background color.
6645 See `set-face-stipple' for possible values for this variable. */);
6646 Vface_default_stipple
= make_pure_c_string ("gray3");
6648 DEFVAR_LISP ("tty-defined-color-alist", Vtty_defined_color_alist
,
6649 doc
: /* An alist of defined terminal colors and their RGB values.
6650 See the docstring of `tty-color-alist' for the details. */);
6651 Vtty_defined_color_alist
= Qnil
;
6653 DEFVAR_LISP ("scalable-fonts-allowed", Vscalable_fonts_allowed
,
6654 doc
: /* Allowed scalable fonts.
6655 A value of nil means don't allow any scalable fonts.
6656 A value of t means allow any scalable font.
6657 Otherwise, value must be a list of regular expressions. A font may be
6658 scaled if its name matches a regular expression in the list.
6659 Note that if value is nil, a scalable font might still be used, if no
6660 other font of the appropriate family and registry is available. */);
6661 Vscalable_fonts_allowed
= Qnil
;
6663 DEFVAR_LISP ("face-ignored-fonts", Vface_ignored_fonts
,
6664 doc
: /* List of ignored fonts.
6665 Each element is a regular expression that matches names of fonts to
6667 Vface_ignored_fonts
= Qnil
;
6669 DEFVAR_LISP ("face-remapping-alist", Vface_remapping_alist
,
6670 doc
: /* Alist of face remappings.
6671 Each element is of the form:
6673 (FACE REPLACEMENT...),
6675 which causes display of the face FACE to use REPLACEMENT... instead.
6676 REPLACEMENT... is interpreted the same way as the value of a `face'
6677 text property: it may be (1) A face name, (2) A list of face names,
6678 (3) A property-list of face attribute/value pairs, or (4) A list of
6679 face names or lists containing face attribute/value pairs.
6681 Multiple entries in REPLACEMENT... are merged together to form the final
6682 result, with faces or attributes earlier in the list taking precedence
6683 over those that are later.
6685 Face-name remapping cycles are suppressed; recursive references use the
6686 underlying face instead of the remapped face. So a remapping of the form:
6688 (FACE EXTRA-FACE... FACE)
6692 (FACE (FACE-ATTR VAL ...) FACE)
6694 will cause EXTRA-FACE... or (FACE-ATTR VAL ...) to be _merged_ with the
6695 existing definition of FACE. Note that for the default face, this isn't
6696 necessary, as every face inherits from the default face.
6698 Making this variable buffer-local is a good way to allow buffer-specific
6699 face definitions. For instance, the mode my-mode could define a face
6700 `my-mode-default', and then in the mode setup function, do:
6702 (set (make-local-variable 'face-remapping-alist)
6703 '((default my-mode-default)))).
6705 Because Emacs normally only redraws screen areas when the underlying
6706 buffer contents change, you may need to call `redraw-display' after
6707 changing this variable for it to take effect. */);
6708 Vface_remapping_alist
= Qnil
;
6710 DEFVAR_LISP ("face-font-rescale-alist", Vface_font_rescale_alist
,
6711 doc
: /* Alist of fonts vs the rescaling factors.
6712 Each element is a cons (FONT-PATTERN . RESCALE-RATIO), where
6713 FONT-PATTERN is a font-spec or a regular expression matching a font name, and
6714 RESCALE-RATIO is a floating point number to specify how much larger
6715 \(or smaller) font we should use. For instance, if a face requests
6716 a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point. */);
6717 Vface_font_rescale_alist
= Qnil
;
6719 #ifdef HAVE_WINDOW_SYSTEM
6720 defsubr (&Sbitmap_spec_p
);
6721 defsubr (&Sx_list_fonts
);
6722 defsubr (&Sinternal_face_x_get_resource
);
6723 defsubr (&Sx_family_fonts
);