1 /* xfaces.c -- "Face" primitives.
3 Copyright (C) 1993-1994, 1998-2014 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New face implementation by Gerd Moellmann <gerd@gnu.org>. */
24 When using Emacs with X, the display style of characters can be
25 changed by defining `faces'. Each face can specify the following
32 3. Relative proportionate width, aka character set width or set
33 width (swidth), e.g. `semi-compressed'.
35 4. Font height in 1/10pt.
37 5. Font weight, e.g. `bold'.
39 6. Font slant, e.g. `italic'.
45 9. Whether or not characters should be underlined, and in what color.
47 10. Whether or not characters should be displayed in inverse video.
49 11. A background stipple, a bitmap.
51 12. Whether or not characters should be overlined, and in what color.
53 13. Whether or not characters should be strike-through, and in what
56 14. Whether or not a box should be drawn around characters, the box
57 type, and, for simple boxes, in what color.
59 15. Font-spec, or nil. This is a special attribute.
61 A font-spec is a collection of font attributes (specs).
63 When this attribute is specified, the face uses a font matching
64 with the specs as is except for what overwritten by the specs in
65 the fontset (see below). In addition, the other font-related
66 attributes (1st thru 5th) are updated from the spec.
68 On the other hand, if one of the other font-related attributes are
69 specified, the corresponding specs in this attribute is set to nil.
71 15. A face name or list of face names from which to inherit attributes.
73 16. A specified average font width, which is invisible from Lisp,
74 and is used to ensure that a font specified on the command line,
75 for example, can be matched exactly.
77 17. A fontset name. This is another special attribute.
79 A fontset is a mappings from characters to font-specs, and the
80 specs overwrite the font-spec in the 14th attribute.
83 Faces are frame-local by nature because Emacs allows to define the
84 same named face (face names are symbols) differently for different
85 frames. Each frame has an alist of face definitions for all named
86 faces. The value of a named face in such an alist is a Lisp vector
87 with the symbol `face' in slot 0, and a slot for each of the face
88 attributes mentioned above.
90 There is also a global face alist `Vface_new_frame_defaults'. Face
91 definitions from this list are used to initialize faces of newly
94 A face doesn't have to specify all attributes. Those not specified
95 have a value of `unspecified'. Faces specifying all attributes but
96 the 14th are called `fully-specified'.
101 The display style of a given character in the text is determined by
102 combining several faces. This process is called `face merging'.
103 Any aspect of the display style that isn't specified by overlays or
104 text properties is taken from the `default' face. Since it is made
105 sure that the default face is always fully-specified, face merging
106 always results in a fully-specified face.
111 After all face attributes for a character have been determined by
112 merging faces of that character, that face is `realized'. The
113 realization process maps face attributes to what is physically
114 available on the system where Emacs runs. The result is a
115 `realized face' in the form of a struct face which is stored in the
116 face cache of the frame on which it was realized.
118 Face realization is done in the context of the character to display
119 because different fonts may be used for different characters. In
120 other words, for characters that have different font
121 specifications, different realized faces are needed to display
124 Font specification is done by fontsets. See the comment in
125 fontset.c for the details. In the current implementation, all ASCII
126 characters share the same font in a fontset.
128 Faces are at first realized for ASCII characters, and, at that
129 time, assigned a specific realized fontset. Hereafter, we call
130 such a face as `ASCII face'. When a face for a multibyte character
131 is realized, it inherits (thus shares) a fontset of an ASCII face
132 that has the same attributes other than font-related ones.
134 Thus, all realized faces have a realized fontset.
139 Unibyte text (i.e. raw 8-bit characters) is displayed with the same
140 font as ASCII characters. That is because it is expected that
141 unibyte text users specify a font that is suitable both for ASCII
142 and raw 8-bit characters.
147 Font selection tries to find the best available matching font for a
148 given (character, face) combination.
150 If the face specifies a fontset name, that fontset determines a
151 pattern for fonts of the given character. If the face specifies a
152 font name or the other font-related attributes, a fontset is
153 realized from the default fontset. In that case, that
154 specification determines a pattern for ASCII characters and the
155 default fontset determines a pattern for multibyte characters.
157 Available fonts on the system on which Emacs runs are then matched
158 against the font pattern. The result of font selection is the best
159 match for the given face attributes in this font list.
161 Font selection can be influenced by the user.
163 1. The user can specify the relative importance he gives the face
164 attributes width, height, weight, and slant by setting
165 face-font-selection-order (faces.el) to a list of face attribute
166 names. The default is '(:width :height :weight :slant), and means
167 that font selection first tries to find a good match for the font
168 width specified by a face, then---within fonts with that
169 width---tries to find a best match for the specified font height,
172 2. Setting face-font-family-alternatives allows the user to
173 specify alternative font families to try if a family specified by a
176 3. Setting face-font-registry-alternatives allows the user to
177 specify all alternative font registries to try for a face
178 specifying a registry.
180 4. Setting face-ignored-fonts allows the user to ignore specific
184 Character composition.
186 Usually, the realization process is already finished when Emacs
187 actually reflects the desired glyph matrix on the screen. However,
188 on displaying a composition (sequence of characters to be composed
189 on the screen), a suitable font for the components of the
190 composition is selected and realized while drawing them on the
191 screen, i.e. the realization process is delayed but in principle
195 Initialization of basic faces.
197 The faces `default', `modeline' are considered `basic faces'.
198 When redisplay happens the first time for a newly created frame,
199 basic faces are realized for CHARSET_ASCII. Frame parameters are
200 used to fill in unspecified attributes of the default face. */
203 #include "sysstdio.h"
204 #include <sys/types.h>
205 #include <sys/stat.h>
208 #include "character.h"
210 #include "keyboard.h"
212 #include "termhooks.h"
216 #include <Xm/XmStrDefs.h>
217 #endif /* USE_MOTIF */
223 #ifdef HAVE_WINDOW_SYSTEM
227 #define x_display_info w32_display_info
228 #define GCGraphicsExposures 0
229 #endif /* HAVE_NTGUI */
232 #define GCGraphicsExposures 0
234 #endif /* HAVE_WINDOW_SYSTEM */
237 #include "dispextern.h"
238 #include "blockinput.h"
240 #include "intervals.h"
241 #include "termchar.h"
245 #ifdef HAVE_X_WINDOWS
247 /* Compensate for a bug in Xos.h on some systems, on which it requires
248 time.h. On some such systems, Xos.h tries to redefine struct
249 timeval and struct timezone if USG is #defined while it is
252 #ifdef XOS_NEEDS_TIME_H
258 #if defined USG || defined __TIMEVAL__ /* Don't warn about unused macros. */
260 #else /* not XOS_NEEDS_TIME_H */
262 #endif /* not XOS_NEEDS_TIME_H */
264 #endif /* HAVE_X_WINDOWS */
268 /* Non-zero if face attribute ATTR is unspecified. */
270 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified)
272 /* Non-zero if face attribute ATTR is `ignore-defface'. */
274 #define IGNORE_DEFFACE_P(ATTR) EQ ((ATTR), QCignore_defface)
276 /* Size of hash table of realized faces in face caches (should be a
279 #define FACE_CACHE_BUCKETS_SIZE 1001
281 /* Keyword symbols used for face attribute names. */
283 Lisp_Object QCfamily
, QCheight
, QCweight
, QCslant
;
284 static Lisp_Object QCunderline
;
285 static Lisp_Object QCinverse_video
, QCstipple
;
286 Lisp_Object QCforeground
, QCbackground
;
288 static Lisp_Object QCfont
, QCbold
, QCitalic
;
289 static Lisp_Object QCreverse_video
;
290 static Lisp_Object QCoverline
, QCstrike_through
, QCbox
, QCinherit
;
291 static Lisp_Object QCfontset
, QCdistant_foreground
;
293 /* Symbols used for attribute values. */
297 static Lisp_Object Qline
, Qwave
;
298 Lisp_Object Qextra_light
, Qlight
;
299 Lisp_Object Qsemi_light
, Qsemi_bold
, Qextra_bold
, Qultra_bold
;
300 Lisp_Object Qoblique
;
302 static Lisp_Object Qreleased_button
, Qpressed_button
;
303 static Lisp_Object QCstyle
, QCcolor
, QCline_width
;
304 Lisp_Object Qunspecified
; /* used in dosfns.c */
305 static Lisp_Object QCignore_defface
;
307 char unspecified_fg
[] = "unspecified-fg", unspecified_bg
[] = "unspecified-bg";
309 /* The name of the function to call when the background of the frame
310 has changed, frame_set_background_mode. */
312 static Lisp_Object Qframe_set_background_mode
;
314 /* Names of basic faces. */
316 Lisp_Object Qdefault
, Qtool_bar
, Qfringe
;
317 static Lisp_Object Qregion
;
318 Lisp_Object Qheader_line
, Qscroll_bar
, Qcursor
;
319 static Lisp_Object Qborder
, Qmouse
, Qmenu
;
320 Lisp_Object Qmode_line_inactive
;
321 static Lisp_Object Qvertical_border
;
322 static Lisp_Object Qwindow_divider
;
323 static Lisp_Object Qwindow_divider_first_pixel
;
324 static Lisp_Object Qwindow_divider_last_pixel
;
326 /* The symbol `face-alias'. A symbols having that property is an
327 alias for another face. Value of the property is the name of
330 static Lisp_Object Qface_alias
;
332 /* Alist of alternative font families. Each element is of the form
333 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
334 try FAMILY1, then FAMILY2, ... */
336 Lisp_Object Vface_alternative_font_family_alist
;
338 /* Alist of alternative font registries. Each element is of the form
339 (REGISTRY REGISTRY1 REGISTRY2...). If fonts of REGISTRY can't be
340 loaded, try REGISTRY1, then REGISTRY2, ... */
342 Lisp_Object Vface_alternative_font_registry_alist
;
344 /* Allowed scalable fonts. A value of nil means don't allow any
345 scalable fonts. A value of t means allow the use of any scalable
346 font. Otherwise, value must be a list of regular expressions. A
347 font may be scaled if its name matches a regular expression in the
350 static Lisp_Object Qscalable_fonts_allowed
;
352 /* The symbols `foreground-color' and `background-color' which can be
353 used as part of a `face' property. This is for compatibility with
356 Lisp_Object Qforeground_color
, Qbackground_color
;
358 /* The symbols `face' and `mouse-face' used as text properties. */
362 /* Property for basic faces which other faces cannot inherit. */
364 static Lisp_Object Qface_no_inherit
;
366 /* Error symbol for wrong_type_argument in load_pixmap. */
368 static Lisp_Object Qbitmap_spec_p
;
370 /* The next ID to assign to Lisp faces. */
372 static int next_lface_id
;
374 /* A vector mapping Lisp face Id's to face names. */
376 static Lisp_Object
*lface_id_to_name
;
377 static ptrdiff_t lface_id_to_name_size
;
379 /* TTY color-related functions (defined in tty-colors.el). */
381 static Lisp_Object Qtty_color_desc
, Qtty_color_by_index
, Qtty_color_standard_values
;
383 /* The name of the function used to compute colors on TTYs. */
385 static Lisp_Object Qtty_color_alist
;
387 #ifdef HAVE_WINDOW_SYSTEM
389 /* Counter for calls to clear_face_cache. If this counter reaches
390 CLEAR_FONT_TABLE_COUNT, and a frame has more than
391 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
393 static int clear_font_table_count
;
394 #define CLEAR_FONT_TABLE_COUNT 100
395 #define CLEAR_FONT_TABLE_NFONTS 10
397 #endif /* HAVE_WINDOW_SYSTEM */
399 /* Non-zero means face attributes have been changed since the last
400 redisplay. Used in redisplay_internal. */
402 int face_change_count
;
404 /* Non-zero means don't display bold text if a face's foreground
405 and background colors are the inverse of the default colors of the
406 display. This is a kluge to suppress `bold black' foreground text
407 which is hard to read on an LCD monitor. */
409 static int tty_suppress_bold_inverse_default_colors_p
;
411 /* A list of the form `((x . y))' used to avoid consing in
412 Finternal_set_lisp_face_attribute. */
414 static Lisp_Object Vparam_value_alist
;
416 /* The total number of colors currently allocated. */
419 static int ncolors_allocated
;
420 static int npixmaps_allocated
;
424 /* Non-zero means the definition of the `menu' face for new frames has
427 static int menu_face_changed_default
;
429 struct named_merge_point
;
431 static struct face
*realize_face (struct face_cache
*, Lisp_Object
*,
433 static struct face
*realize_x_face (struct face_cache
*, Lisp_Object
*);
434 static struct face
*realize_tty_face (struct face_cache
*, Lisp_Object
*);
435 static bool realize_basic_faces (struct frame
*);
436 static bool realize_default_face (struct frame
*);
437 static void realize_named_face (struct frame
*, Lisp_Object
, int);
438 static struct face_cache
*make_face_cache (struct frame
*);
439 static void free_face_cache (struct face_cache
*);
440 static int merge_face_ref (struct frame
*, Lisp_Object
, Lisp_Object
*,
441 int, struct named_merge_point
*);
442 static int color_distance (XColor
*x
, XColor
*y
);
444 #ifdef HAVE_WINDOW_SYSTEM
445 static void set_font_frame_param (Lisp_Object
, Lisp_Object
);
446 static void clear_face_gcs (struct face_cache
*);
447 static struct face
*realize_non_ascii_face (struct frame
*, Lisp_Object
,
449 #endif /* HAVE_WINDOW_SYSTEM */
451 /***********************************************************************
453 ***********************************************************************/
455 #ifdef HAVE_X_WINDOWS
457 #ifdef DEBUG_X_COLORS
459 /* The following is a poor mans infrastructure for debugging X color
460 allocation problems on displays with PseudoColor-8. Some X servers
461 like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement
462 color reference counts completely so that they don't signal an
463 error when a color is freed whose reference count is already 0.
464 Other X servers do. To help me debug this, the following code
465 implements a simple reference counting schema of its own, for a
466 single display/screen. --gerd. */
468 /* Reference counts for pixel colors. */
470 int color_count
[256];
472 /* Register color PIXEL as allocated. */
475 register_color (unsigned long pixel
)
477 eassert (pixel
< 256);
478 ++color_count
[pixel
];
482 /* Register color PIXEL as deallocated. */
485 unregister_color (unsigned long pixel
)
487 eassert (pixel
< 256);
488 if (color_count
[pixel
] > 0)
489 --color_count
[pixel
];
495 /* Register N colors from PIXELS as deallocated. */
498 unregister_colors (unsigned long *pixels
, int n
)
501 for (i
= 0; i
< n
; ++i
)
502 unregister_color (pixels
[i
]);
506 DEFUN ("dump-colors", Fdump_colors
, Sdump_colors
, 0, 0, 0,
507 doc
: /* Dump currently allocated colors to stderr. */)
512 fputc ('\n', stderr
);
514 for (i
= n
= 0; i
< ARRAYELTS (color_count
); ++i
)
517 fprintf (stderr
, "%3d: %5d", i
, color_count
[i
]);
520 fputc ('\n', stderr
);
522 fputc ('\t', stderr
);
526 fputc ('\n', stderr
);
530 #endif /* DEBUG_X_COLORS */
533 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
534 color values. Interrupt input must be blocked when this function
538 x_free_colors (struct frame
*f
, unsigned long *pixels
, int npixels
)
540 int class = FRAME_DISPLAY_INFO (f
)->visual
->class;
542 /* If display has an immutable color map, freeing colors is not
543 necessary and some servers don't allow it. So don't do it. */
544 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
546 #ifdef DEBUG_X_COLORS
547 unregister_colors (pixels
, npixels
);
549 XFreeColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
557 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
558 color values. Interrupt input must be blocked when this function
562 x_free_dpy_colors (Display
*dpy
, Screen
*screen
, Colormap cmap
,
563 unsigned long *pixels
, int npixels
)
565 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
566 int class = dpyinfo
->visual
->class;
568 /* If display has an immutable color map, freeing colors is not
569 necessary and some servers don't allow it. So don't do it. */
570 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
572 #ifdef DEBUG_X_COLORS
573 unregister_colors (pixels
, npixels
);
575 XFreeColors (dpy
, cmap
, pixels
, npixels
, 0);
578 #endif /* USE_X_TOOLKIT */
580 /* Create and return a GC for use on frame F. GC values and mask
581 are given by XGCV and MASK. */
584 x_create_gc (struct frame
*f
, unsigned long mask
, XGCValues
*xgcv
)
588 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
595 /* Free GC which was used on frame F. */
598 x_free_gc (struct frame
*f
, GC gc
)
600 eassert (input_blocked_p ());
601 IF_DEBUG ((--ngcs
, eassert (ngcs
>= 0)));
602 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
605 #endif /* HAVE_X_WINDOWS */
608 /* W32 emulation of GCs */
611 x_create_gc (struct frame
*f
, unsigned long mask
, XGCValues
*xgcv
)
615 gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, xgcv
);
622 /* Free GC which was used on frame F. */
625 x_free_gc (struct frame
*f
, GC gc
)
627 IF_DEBUG ((--ngcs
, eassert (ngcs
>= 0)));
631 #endif /* HAVE_NTGUI */
634 /* NS emulation of GCs */
637 x_create_gc (struct frame
*f
,
641 GC gc
= xmalloc (sizeof *gc
);
647 x_free_gc (struct frame
*f
, GC gc
)
653 /***********************************************************************
655 ***********************************************************************/
657 /* Initialize face cache and basic faces for frame F. */
660 init_frame_faces (struct frame
*f
)
662 /* Make a face cache, if F doesn't have one. */
663 if (FRAME_FACE_CACHE (f
) == NULL
)
664 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
666 #ifdef HAVE_WINDOW_SYSTEM
667 /* Make the image cache. */
668 if (FRAME_WINDOW_P (f
))
670 /* We initialize the image cache when creating the first frame
671 on a terminal, and not during terminal creation. This way,
672 `x-open-connection' on a tty won't create an image cache. */
673 if (FRAME_IMAGE_CACHE (f
) == NULL
)
674 FRAME_IMAGE_CACHE (f
) = make_image_cache ();
675 ++FRAME_IMAGE_CACHE (f
)->refcount
;
677 #endif /* HAVE_WINDOW_SYSTEM */
679 /* Realize basic faces. Must have enough information in frame
680 parameters to realize basic faces at this point. */
681 #ifdef HAVE_X_WINDOWS
682 if (!FRAME_X_P (f
) || FRAME_X_WINDOW (f
))
685 if (!FRAME_WINDOW_P (f
) || FRAME_W32_WINDOW (f
))
688 if (!FRAME_NS_P (f
) || FRAME_NS_WINDOW (f
))
690 if (!realize_basic_faces (f
))
695 /* Free face cache of frame F. Called from frame-dependent
696 resource freeing function, e.g. (x|tty)_free_frame_resources. */
699 free_frame_faces (struct frame
*f
)
701 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
705 free_face_cache (face_cache
);
706 FRAME_FACE_CACHE (f
) = NULL
;
709 #ifdef HAVE_WINDOW_SYSTEM
710 if (FRAME_WINDOW_P (f
))
712 struct image_cache
*image_cache
= FRAME_IMAGE_CACHE (f
);
715 --image_cache
->refcount
;
716 if (image_cache
->refcount
== 0)
717 free_image_cache (f
);
720 #endif /* HAVE_WINDOW_SYSTEM */
724 /* Clear face caches, and recompute basic faces for frame F. Call
725 this after changing frame parameters on which those faces depend,
726 or when realized faces have been freed due to changing attributes
730 recompute_basic_faces (struct frame
*f
)
732 if (FRAME_FACE_CACHE (f
))
734 clear_face_cache (0);
735 if (!realize_basic_faces (f
))
741 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
742 try to free unused fonts, too. */
745 clear_face_cache (int clear_fonts_p
)
747 #ifdef HAVE_WINDOW_SYSTEM
748 Lisp_Object tail
, frame
;
751 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
753 /* From time to time see if we can unload some fonts. This also
754 frees all realized faces on all frames. Fonts needed by
755 faces will be loaded again when faces are realized again. */
756 clear_font_table_count
= 0;
758 FOR_EACH_FRAME (tail
, frame
)
760 struct frame
*f
= XFRAME (frame
);
761 if (FRAME_WINDOW_P (f
)
762 && FRAME_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
764 clear_font_cache (f
);
765 free_all_realized_faces (frame
);
771 /* Clear GCs of realized faces. */
772 FOR_EACH_FRAME (tail
, frame
)
774 struct frame
*f
= XFRAME (frame
);
775 if (FRAME_WINDOW_P (f
))
776 clear_face_gcs (FRAME_FACE_CACHE (f
));
778 clear_image_caches (Qnil
);
780 #endif /* HAVE_WINDOW_SYSTEM */
784 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
785 doc
: /* Clear face caches on all frames.
786 Optional THOROUGHLY non-nil means try to free unused fonts, too. */)
787 (Lisp_Object thoroughly
)
789 clear_face_cache (!NILP (thoroughly
));
791 windows_or_buffers_changed
= 53;
796 /***********************************************************************
798 ***********************************************************************/
800 #ifdef HAVE_WINDOW_SYSTEM
802 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
803 doc
: /* Value is non-nil if OBJECT is a valid bitmap specification.
804 A bitmap specification is either a string, a file name, or a list
805 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
806 HEIGHT is its height, and DATA is a string containing the bits of
807 the pixmap. Bits are stored row by row, each row occupies
808 \(WIDTH + 7)/8 bytes. */)
813 if (STRINGP (object
))
814 /* If OBJECT is a string, it's a file name. */
816 else if (CONSP (object
))
818 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
819 HEIGHT must be ints > 0, and DATA must be string large
820 enough to hold a bitmap of the specified size. */
821 Lisp_Object width
, height
, data
;
823 height
= width
= data
= Qnil
;
827 width
= XCAR (object
);
828 object
= XCDR (object
);
831 height
= XCAR (object
);
832 object
= XCDR (object
);
834 data
= XCAR (object
);
839 && RANGED_INTEGERP (1, width
, INT_MAX
)
840 && RANGED_INTEGERP (1, height
, INT_MAX
))
842 int bytes_per_row
= ((XINT (width
) + BITS_PER_CHAR
- 1)
844 if (XINT (height
) <= SBYTES (data
) / bytes_per_row
)
849 return pixmap_p
? Qt
: Qnil
;
853 /* Load a bitmap according to NAME (which is either a file name or a
854 pixmap spec) for use on frame F. Value is the bitmap_id (see
855 xfns.c). If NAME is nil, return with a bitmap id of zero. If
856 bitmap cannot be loaded, display a message saying so, and return
860 load_pixmap (struct frame
*f
, Lisp_Object name
)
867 CHECK_TYPE (!NILP (Fbitmap_spec_p (name
)), Qbitmap_spec_p
, name
);
872 /* Decode a bitmap spec into a bitmap. */
877 w
= XINT (Fcar (name
));
878 h
= XINT (Fcar (Fcdr (name
)));
879 bits
= Fcar (Fcdr (Fcdr (name
)));
881 bitmap_id
= x_create_bitmap_from_data (f
, SSDATA (bits
),
886 /* It must be a string -- a file name. */
887 bitmap_id
= x_create_bitmap_from_file (f
, name
);
893 add_to_log ("Invalid or undefined bitmap `%s'", name
, Qnil
);
899 ++npixmaps_allocated
;
906 #endif /* HAVE_WINDOW_SYSTEM */
910 /***********************************************************************
912 ***********************************************************************/
914 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
915 RGB_LIST should contain (at least) 3 lisp integers.
916 Return 0 if there's a problem with RGB_LIST, otherwise return 1. */
919 parse_rgb_list (Lisp_Object rgb_list
, XColor
*color
)
921 #define PARSE_RGB_LIST_FIELD(field) \
922 if (CONSP (rgb_list) && INTEGERP (XCAR (rgb_list))) \
924 color->field = XINT (XCAR (rgb_list)); \
925 rgb_list = XCDR (rgb_list); \
930 PARSE_RGB_LIST_FIELD (red
);
931 PARSE_RGB_LIST_FIELD (green
);
932 PARSE_RGB_LIST_FIELD (blue
);
938 /* Lookup on frame F the color described by the lisp string COLOR.
939 The resulting tty color is returned in TTY_COLOR; if STD_COLOR is
940 non-zero, then the `standard' definition of the same color is
944 tty_lookup_color (struct frame
*f
, Lisp_Object color
, XColor
*tty_color
,
947 Lisp_Object frame
, color_desc
;
949 if (!STRINGP (color
) || NILP (Ffboundp (Qtty_color_desc
)))
952 XSETFRAME (frame
, f
);
954 color_desc
= call2 (Qtty_color_desc
, color
, frame
);
955 if (CONSP (color_desc
) && CONSP (XCDR (color_desc
)))
959 if (! INTEGERP (XCAR (XCDR (color_desc
))))
962 tty_color
->pixel
= XINT (XCAR (XCDR (color_desc
)));
964 rgb
= XCDR (XCDR (color_desc
));
965 if (! parse_rgb_list (rgb
, tty_color
))
968 /* Should we fill in STD_COLOR too? */
971 /* Default STD_COLOR to the same as TTY_COLOR. */
972 *std_color
= *tty_color
;
974 /* Do a quick check to see if the returned descriptor is
975 actually _exactly_ equal to COLOR, otherwise we have to
976 lookup STD_COLOR separately. If it's impossible to lookup
977 a standard color, we just give up and use TTY_COLOR. */
978 if ((!STRINGP (XCAR (color_desc
))
979 || NILP (Fstring_equal (color
, XCAR (color_desc
))))
980 && !NILP (Ffboundp (Qtty_color_standard_values
)))
982 /* Look up STD_COLOR separately. */
983 rgb
= call1 (Qtty_color_standard_values
, color
);
984 if (! parse_rgb_list (rgb
, std_color
))
991 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
992 /* We were called early during startup, and the colors are not
993 yet set up in tty-defined-color-alist. Don't return a failure
994 indication, since this produces the annoying "Unable to
995 load color" messages in the *Messages* buffer. */
998 /* tty-color-desc seems to have returned a bad value. */
1002 /* A version of defined_color for non-X frames. */
1005 tty_defined_color (struct frame
*f
, const char *color_name
,
1006 XColor
*color_def
, bool alloc
)
1011 color_def
->pixel
= FACE_TTY_DEFAULT_COLOR
;
1013 color_def
->blue
= 0;
1014 color_def
->green
= 0;
1017 status
= tty_lookup_color (f
, build_string (color_name
), color_def
, NULL
);
1019 if (color_def
->pixel
== FACE_TTY_DEFAULT_COLOR
&& *color_name
)
1021 if (strcmp (color_name
, "unspecified-fg") == 0)
1022 color_def
->pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
1023 else if (strcmp (color_name
, "unspecified-bg") == 0)
1024 color_def
->pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
1027 if (color_def
->pixel
!= FACE_TTY_DEFAULT_COLOR
)
1034 /* Decide if color named COLOR_NAME is valid for the display
1035 associated with the frame F; if so, return the rgb values in
1036 COLOR_DEF. If ALLOC, allocate a new colormap cell.
1038 This does the right thing for any type of frame. */
1041 defined_color (struct frame
*f
, const char *color_name
, XColor
*color_def
,
1044 if (!FRAME_WINDOW_P (f
))
1045 return tty_defined_color (f
, color_name
, color_def
, alloc
);
1046 #ifdef HAVE_X_WINDOWS
1047 else if (FRAME_X_P (f
))
1048 return x_defined_color (f
, color_name
, color_def
, alloc
);
1051 else if (FRAME_W32_P (f
))
1052 return w32_defined_color (f
, color_name
, color_def
, alloc
);
1055 else if (FRAME_NS_P (f
))
1056 return ns_defined_color (f
, color_name
, color_def
, alloc
, 1);
1063 /* Given the index IDX of a tty color on frame F, return its name, a
1067 tty_color_name (struct frame
*f
, int idx
)
1069 if (idx
>= 0 && !NILP (Ffboundp (Qtty_color_by_index
)))
1072 Lisp_Object coldesc
;
1074 XSETFRAME (frame
, f
);
1075 coldesc
= call2 (Qtty_color_by_index
, make_number (idx
), frame
);
1077 if (!NILP (coldesc
))
1078 return XCAR (coldesc
);
1081 /* We can have an MSDOG frame under -nw for a short window of
1082 opportunity before internal_terminal_init is called. DTRT. */
1083 if (FRAME_MSDOS_P (f
) && !inhibit_window_system
)
1084 return msdos_stdcolor_name (idx
);
1087 if (idx
== FACE_TTY_DEFAULT_FG_COLOR
)
1088 return build_string (unspecified_fg
);
1089 if (idx
== FACE_TTY_DEFAULT_BG_COLOR
)
1090 return build_string (unspecified_bg
);
1092 return Qunspecified
;
1096 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1099 The criterion implemented here is not a terribly sophisticated one. */
1102 face_color_gray_p (struct frame
*f
, const char *color_name
)
1107 if (defined_color (f
, color_name
, &color
, 0))
1108 gray_p
= (/* Any color sufficiently close to black counts as gray. */
1109 (color
.red
< 5000 && color
.green
< 5000 && color
.blue
< 5000)
1111 ((eabs (color
.red
- color
.green
)
1112 < max (color
.red
, color
.green
) / 20)
1113 && (eabs (color
.green
- color
.blue
)
1114 < max (color
.green
, color
.blue
) / 20)
1115 && (eabs (color
.blue
- color
.red
)
1116 < max (color
.blue
, color
.red
) / 20)));
1124 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1125 BACKGROUND_P non-zero means the color will be used as background
1129 face_color_supported_p (struct frame
*f
, const char *color_name
,
1135 XSETFRAME (frame
, f
);
1137 #ifdef HAVE_WINDOW_SYSTEM
1139 ? (!NILP (Fxw_display_color_p (frame
))
1140 || xstrcasecmp (color_name
, "black") == 0
1141 || xstrcasecmp (color_name
, "white") == 0
1143 && face_color_gray_p (f
, color_name
))
1144 || (!NILP (Fx_display_grayscale_p (frame
))
1145 && face_color_gray_p (f
, color_name
)))
1148 tty_defined_color (f
, color_name
, ¬_used
, 0);
1152 DEFUN ("color-gray-p", Fcolor_gray_p
, Scolor_gray_p
, 1, 2, 0,
1153 doc
: /* Return non-nil if COLOR is a shade of gray (or white or black).
1154 FRAME specifies the frame and thus the display for interpreting COLOR.
1155 If FRAME is nil or omitted, use the selected frame. */)
1156 (Lisp_Object color
, Lisp_Object frame
)
1158 CHECK_STRING (color
);
1159 return (face_color_gray_p (decode_any_frame (frame
), SSDATA (color
))
1164 DEFUN ("color-supported-p", Fcolor_supported_p
,
1165 Scolor_supported_p
, 1, 3, 0,
1166 doc
: /* Return non-nil if COLOR can be displayed on FRAME.
1167 BACKGROUND-P non-nil means COLOR is used as a background.
1168 Otherwise, this function tells whether it can be used as a foreground.
1169 If FRAME is nil or omitted, use the selected frame.
1170 COLOR must be a valid color name. */)
1171 (Lisp_Object color
, Lisp_Object frame
, Lisp_Object background_p
)
1173 CHECK_STRING (color
);
1174 return (face_color_supported_p (decode_any_frame (frame
),
1175 SSDATA (color
), !NILP (background_p
))
1180 static unsigned long
1181 load_color2 (struct frame
*f
, struct face
*face
, Lisp_Object name
,
1182 enum lface_attribute_index target_index
, XColor
*color
)
1184 eassert (STRINGP (name
));
1185 eassert (target_index
== LFACE_FOREGROUND_INDEX
1186 || target_index
== LFACE_BACKGROUND_INDEX
1187 || target_index
== LFACE_UNDERLINE_INDEX
1188 || target_index
== LFACE_OVERLINE_INDEX
1189 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1190 || target_index
== LFACE_BOX_INDEX
);
1192 /* if the color map is full, defined_color will return a best match
1193 to the values in an existing cell. */
1194 if (!defined_color (f
, SSDATA (name
), color
, 1))
1196 add_to_log ("Unable to load color \"%s\"", name
, Qnil
);
1198 switch (target_index
)
1200 case LFACE_FOREGROUND_INDEX
:
1201 face
->foreground_defaulted_p
= 1;
1202 color
->pixel
= FRAME_FOREGROUND_PIXEL (f
);
1205 case LFACE_BACKGROUND_INDEX
:
1206 face
->background_defaulted_p
= 1;
1207 color
->pixel
= FRAME_BACKGROUND_PIXEL (f
);
1210 case LFACE_UNDERLINE_INDEX
:
1211 face
->underline_defaulted_p
= 1;
1212 color
->pixel
= FRAME_FOREGROUND_PIXEL (f
);
1215 case LFACE_OVERLINE_INDEX
:
1216 face
->overline_color_defaulted_p
= 1;
1217 color
->pixel
= FRAME_FOREGROUND_PIXEL (f
);
1220 case LFACE_STRIKE_THROUGH_INDEX
:
1221 face
->strike_through_color_defaulted_p
= 1;
1222 color
->pixel
= FRAME_FOREGROUND_PIXEL (f
);
1225 case LFACE_BOX_INDEX
:
1226 face
->box_color_defaulted_p
= 1;
1227 color
->pixel
= FRAME_FOREGROUND_PIXEL (f
);
1236 ++ncolors_allocated
;
1239 return color
->pixel
;
1242 /* Load color with name NAME for use by face FACE on frame F.
1243 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1244 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1245 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1246 pixel color. If color cannot be loaded, display a message, and
1247 return the foreground, background or underline color of F, but
1248 record that fact in flags of the face so that we don't try to free
1252 load_color (struct frame
*f
, struct face
*face
, Lisp_Object name
,
1253 enum lface_attribute_index target_index
)
1256 return load_color2 (f
, face
, name
, target_index
, &color
);
1260 #ifdef HAVE_WINDOW_SYSTEM
1262 #define NEAR_SAME_COLOR_THRESHOLD 30000
1264 /* Load colors for face FACE which is used on frame F. Colors are
1265 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1266 of ATTRS. If the background color specified is not supported on F,
1267 try to emulate gray colors with a stipple from Vface_default_stipple. */
1270 load_face_colors (struct frame
*f
, struct face
*face
,
1271 Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
1273 Lisp_Object fg
, bg
, dfg
;
1276 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1277 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1279 /* Swap colors if face is inverse-video. */
1280 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1288 /* Check for support for foreground, not for background because
1289 face_color_supported_p is smart enough to know that grays are
1290 "supported" as background because we are supposed to use stipple
1292 if (!face_color_supported_p (f
, SSDATA (bg
), 0)
1293 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1295 x_destroy_bitmap (f
, face
->stipple
);
1296 face
->stipple
= load_pixmap (f
, Vface_default_stipple
);
1299 face
->background
= load_color2 (f
, face
, bg
, LFACE_BACKGROUND_INDEX
, &xbg
);
1300 face
->foreground
= load_color2 (f
, face
, fg
, LFACE_FOREGROUND_INDEX
, &xfg
);
1302 dfg
= attrs
[LFACE_DISTANT_FOREGROUND_INDEX
];
1303 if (!NILP (dfg
) && !UNSPECIFIEDP (dfg
)
1304 && color_distance (&xbg
, &xfg
) < NEAR_SAME_COLOR_THRESHOLD
)
1306 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1307 face
->background
= load_color (f
, face
, dfg
, LFACE_BACKGROUND_INDEX
);
1309 face
->foreground
= load_color (f
, face
, dfg
, LFACE_FOREGROUND_INDEX
);
1313 #ifdef HAVE_X_WINDOWS
1315 /* Free color PIXEL on frame F. */
1318 unload_color (struct frame
*f
, unsigned long pixel
)
1323 x_free_colors (f
, &pixel
, 1);
1328 /* Free colors allocated for FACE. */
1331 free_face_colors (struct frame
*f
, struct face
*face
)
1333 /* PENDING(NS): need to do something here? */
1335 if (face
->colors_copied_bitwise_p
)
1340 if (!face
->foreground_defaulted_p
)
1342 x_free_colors (f
, &face
->foreground
, 1);
1343 IF_DEBUG (--ncolors_allocated
);
1346 if (!face
->background_defaulted_p
)
1348 x_free_colors (f
, &face
->background
, 1);
1349 IF_DEBUG (--ncolors_allocated
);
1352 if (face
->underline_p
1353 && !face
->underline_defaulted_p
)
1355 x_free_colors (f
, &face
->underline_color
, 1);
1356 IF_DEBUG (--ncolors_allocated
);
1359 if (face
->overline_p
1360 && !face
->overline_color_defaulted_p
)
1362 x_free_colors (f
, &face
->overline_color
, 1);
1363 IF_DEBUG (--ncolors_allocated
);
1366 if (face
->strike_through_p
1367 && !face
->strike_through_color_defaulted_p
)
1369 x_free_colors (f
, &face
->strike_through_color
, 1);
1370 IF_DEBUG (--ncolors_allocated
);
1373 if (face
->box
!= FACE_NO_BOX
1374 && !face
->box_color_defaulted_p
)
1376 x_free_colors (f
, &face
->box_color
, 1);
1377 IF_DEBUG (--ncolors_allocated
);
1383 #endif /* HAVE_X_WINDOWS */
1385 #endif /* HAVE_WINDOW_SYSTEM */
1389 /***********************************************************************
1391 ***********************************************************************/
1393 /* An enumerator for each field of an XLFD font name. */
1414 /* An enumerator for each possible slant value of a font. Taken from
1415 the XLFD specification. */
1423 XLFD_SLANT_REVERSE_ITALIC
,
1424 XLFD_SLANT_REVERSE_OBLIQUE
,
1428 /* Relative font weight according to XLFD documentation. */
1432 XLFD_WEIGHT_UNKNOWN
,
1433 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1434 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1435 XLFD_WEIGHT_LIGHT
, /* 30 */
1436 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1437 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1438 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1439 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1440 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1441 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1444 /* Relative proportionate width. */
1448 XLFD_SWIDTH_UNKNOWN
,
1449 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1450 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1451 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1452 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1453 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1454 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1455 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1456 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1457 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1460 /* Order by which font selection chooses fonts. The default values
1461 mean `first, find a best match for the font width, then for the
1462 font height, then for weight, then for slant.' This variable can be
1463 set via set-face-font-sort-order. */
1465 static int font_sort_order
[4];
1467 #ifdef HAVE_WINDOW_SYSTEM
1469 static enum font_property_index font_props_for_sorting
[FONT_SIZE_INDEX
];
1472 compare_fonts_by_sort_order (const void *v1
, const void *v2
)
1474 Lisp_Object
const *p1
= v1
;
1475 Lisp_Object
const *p2
= v2
;
1476 Lisp_Object font1
= *p1
;
1477 Lisp_Object font2
= *p2
;
1480 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1482 enum font_property_index idx
= font_props_for_sorting
[i
];
1483 Lisp_Object val1
= AREF (font1
, idx
), val2
= AREF (font2
, idx
);
1486 if (idx
<= FONT_REGISTRY_INDEX
)
1489 result
= STRINGP (val2
) ? strcmp (SSDATA (val1
), SSDATA (val2
)) : -1;
1491 result
= STRINGP (val2
) ? 1 : 0;
1495 if (INTEGERP (val1
))
1496 result
= (INTEGERP (val2
) && XINT (val1
) >= XINT (val2
)
1497 ? XINT (val1
) > XINT (val2
)
1500 result
= INTEGERP (val2
) ? 1 : 0;
1508 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
1509 doc
: /* Return a list of available fonts of family FAMILY on FRAME.
1510 If FAMILY is omitted or nil, list all families.
1511 Otherwise, FAMILY must be a string, possibly containing wildcards
1513 If FRAME is omitted or nil, use the selected frame.
1514 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
1515 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
1516 FAMILY is the font family name. POINT-SIZE is the size of the
1517 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
1518 width, weight and slant of the font. These symbols are the same as for
1519 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
1520 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
1521 giving the registry and encoding of the font.
1522 The result list is sorted according to the current setting of
1523 the face font sort order. */)
1524 (Lisp_Object family
, Lisp_Object frame
)
1526 Lisp_Object font_spec
, list
, *drivers
, vec
;
1527 struct frame
*f
= decode_live_frame (frame
);
1528 ptrdiff_t i
, nfonts
;
1533 font_spec
= Ffont_spec (0, NULL
);
1536 CHECK_STRING (family
);
1537 font_parse_family_registry (family
, Qnil
, font_spec
);
1540 list
= font_list_entities (f
, font_spec
);
1544 /* Sort the font entities. */
1545 for (i
= 0; i
< 4; i
++)
1546 switch (font_sort_order
[i
])
1549 font_props_for_sorting
[i
] = FONT_WIDTH_INDEX
; break;
1550 case XLFD_POINT_SIZE
:
1551 font_props_for_sorting
[i
] = FONT_SIZE_INDEX
; break;
1553 font_props_for_sorting
[i
] = FONT_WEIGHT_INDEX
; break;
1555 font_props_for_sorting
[i
] = FONT_SLANT_INDEX
; break;
1557 font_props_for_sorting
[i
++] = FONT_FAMILY_INDEX
;
1558 font_props_for_sorting
[i
++] = FONT_FOUNDRY_INDEX
;
1559 font_props_for_sorting
[i
++] = FONT_ADSTYLE_INDEX
;
1560 font_props_for_sorting
[i
++] = FONT_REGISTRY_INDEX
;
1562 ndrivers
= XINT (Flength (list
));
1563 SAFE_ALLOCA_LISP (drivers
, ndrivers
);
1564 for (i
= 0; i
< ndrivers
; i
++, list
= XCDR (list
))
1565 drivers
[i
] = XCAR (list
);
1566 vec
= Fvconcat (ndrivers
, drivers
);
1567 nfonts
= ASIZE (vec
);
1569 qsort (XVECTOR (vec
)->contents
, nfonts
, word_size
,
1570 compare_fonts_by_sort_order
);
1573 for (i
= nfonts
- 1; i
>= 0; --i
)
1575 Lisp_Object font
= AREF (vec
, i
);
1576 Lisp_Object v
= make_uninit_vector (8);
1578 Lisp_Object spacing
;
1580 ASET (v
, 0, AREF (font
, FONT_FAMILY_INDEX
));
1581 ASET (v
, 1, FONT_WIDTH_SYMBOLIC (font
));
1582 point
= PIXEL_TO_POINT (XINT (AREF (font
, FONT_SIZE_INDEX
)) * 10,
1584 ASET (v
, 2, make_number (point
));
1585 ASET (v
, 3, FONT_WEIGHT_SYMBOLIC (font
));
1586 ASET (v
, 4, FONT_SLANT_SYMBOLIC (font
));
1587 spacing
= Ffont_get (font
, QCspacing
);
1588 ASET (v
, 5, (NILP (spacing
) || EQ (spacing
, Qp
)) ? Qnil
: Qt
);
1589 ASET (v
, 6, Ffont_xlfd_name (font
, Qnil
));
1590 ASET (v
, 7, AREF (font
, FONT_REGISTRY_INDEX
));
1592 result
= Fcons (v
, result
);
1599 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
1600 doc
: /* Return a list of the names of available fonts matching PATTERN.
1601 If optional arguments FACE and FRAME are specified, return only fonts
1602 the same size as FACE on FRAME.
1604 PATTERN should be a string containing a font name in the XLFD,
1605 Fontconfig, or GTK format. A font name given in the XLFD format may
1606 contain wildcard characters:
1607 the * character matches any substring, and
1608 the ? character matches any single character.
1609 PATTERN is case-insensitive.
1611 The return value is a list of strings, suitable as arguments to
1614 Fonts Emacs can't use may or may not be excluded
1615 even if they match PATTERN and FACE.
1616 The optional fourth argument MAXIMUM sets a limit on how many
1617 fonts to match. The first MAXIMUM fonts are reported.
1618 The optional fifth argument WIDTH, if specified, is a number of columns
1619 occupied by a character of a font. In that case, return only fonts
1620 the WIDTH times as wide as FACE on FRAME. */)
1621 (Lisp_Object pattern
, Lisp_Object face
, Lisp_Object frame
,
1622 Lisp_Object maximum
, Lisp_Object width
)
1625 int size
, avgwidth
IF_LINT (= 0);
1627 check_window_system (NULL
);
1628 CHECK_STRING (pattern
);
1630 if (! NILP (maximum
))
1631 CHECK_NATNUM (maximum
);
1634 CHECK_NUMBER (width
);
1636 /* We can't simply call decode_window_system_frame because
1637 this function may be called before any frame is created. */
1638 f
= decode_live_frame (frame
);
1639 if (! FRAME_WINDOW_P (f
))
1641 /* Perhaps we have not yet created any frame. */
1647 XSETFRAME (frame
, f
);
1649 /* Determine the width standard for comparison with the fonts we find. */
1655 /* This is of limited utility since it works with character
1656 widths. Keep it for compatibility. --gerd. */
1657 int face_id
= lookup_named_face (f
, face
, 0);
1658 struct face
*width_face
= (face_id
< 0
1660 : FACE_FROM_ID (f
, face_id
));
1662 if (width_face
&& width_face
->font
)
1664 size
= width_face
->font
->pixel_size
;
1665 avgwidth
= width_face
->font
->average_width
;
1669 size
= FRAME_FONT (f
)->pixel_size
;
1670 avgwidth
= FRAME_FONT (f
)->average_width
;
1673 avgwidth
*= XINT (width
);
1677 Lisp_Object font_spec
;
1678 Lisp_Object args
[2], tail
;
1680 font_spec
= font_spec_from_name (pattern
);
1681 if (!FONTP (font_spec
))
1682 signal_error ("Invalid font name", pattern
);
1686 Ffont_put (font_spec
, QCsize
, make_number (size
));
1687 Ffont_put (font_spec
, QCavgwidth
, make_number (avgwidth
));
1689 args
[0] = Flist_fonts (font_spec
, frame
, maximum
, font_spec
);
1690 for (tail
= args
[0]; CONSP (tail
); tail
= XCDR (tail
))
1692 Lisp_Object font_entity
;
1694 font_entity
= XCAR (tail
);
1695 if ((NILP (AREF (font_entity
, FONT_SIZE_INDEX
))
1696 || XINT (AREF (font_entity
, FONT_SIZE_INDEX
)) == 0)
1697 && ! NILP (AREF (font_spec
, FONT_SIZE_INDEX
)))
1699 /* This is a scalable font. For backward compatibility,
1700 we set the specified size. */
1701 font_entity
= copy_font_spec (font_entity
);
1702 ASET (font_entity
, FONT_SIZE_INDEX
,
1703 AREF (font_spec
, FONT_SIZE_INDEX
));
1705 XSETCAR (tail
, Ffont_xlfd_name (font_entity
, Qnil
));
1708 /* We don't have to check fontsets. */
1710 args
[1] = list_fontsets (f
, pattern
, size
);
1711 return Fnconc (2, args
);
1715 #endif /* HAVE_WINDOW_SYSTEM */
1718 /***********************************************************************
1720 ***********************************************************************/
1722 /* Access face attributes of face LFACE, a Lisp vector. */
1724 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
1725 #define LFACE_FOUNDRY(LFACE) AREF ((LFACE), LFACE_FOUNDRY_INDEX)
1726 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
1727 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
1728 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
1729 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
1730 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
1731 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
1732 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
1733 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
1734 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
1735 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
1736 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
1737 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
1738 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
1739 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
1740 #define LFACE_FONTSET(LFACE) AREF ((LFACE), LFACE_FONTSET_INDEX)
1741 #define LFACE_DISTANT_FOREGROUND(LFACE) \
1742 AREF ((LFACE), LFACE_DISTANT_FOREGROUND_INDEX)
1744 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
1745 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
1747 #define LFACEP(LFACE) \
1749 && ASIZE (LFACE) == LFACE_VECTOR_SIZE \
1750 && EQ (AREF (LFACE, 0), Qface))
1755 /* Check consistency of Lisp face attribute vector ATTRS. */
1758 check_lface_attrs (Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
1760 eassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
1761 || IGNORE_DEFFACE_P (attrs
[LFACE_FAMILY_INDEX
])
1762 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
1763 eassert (UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
1764 || IGNORE_DEFFACE_P (attrs
[LFACE_FOUNDRY_INDEX
])
1765 || STRINGP (attrs
[LFACE_FOUNDRY_INDEX
]));
1766 eassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
1767 || IGNORE_DEFFACE_P (attrs
[LFACE_SWIDTH_INDEX
])
1768 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
1769 eassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
1770 || IGNORE_DEFFACE_P (attrs
[LFACE_HEIGHT_INDEX
])
1771 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
])
1772 || FLOATP (attrs
[LFACE_HEIGHT_INDEX
])
1773 || FUNCTIONP (attrs
[LFACE_HEIGHT_INDEX
]));
1774 eassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
1775 || IGNORE_DEFFACE_P (attrs
[LFACE_WEIGHT_INDEX
])
1776 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
1777 eassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
1778 || IGNORE_DEFFACE_P (attrs
[LFACE_SLANT_INDEX
])
1779 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
1780 eassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
1781 || IGNORE_DEFFACE_P (attrs
[LFACE_UNDERLINE_INDEX
])
1782 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
1783 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
])
1784 || CONSP (attrs
[LFACE_UNDERLINE_INDEX
]));
1785 eassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
1786 || IGNORE_DEFFACE_P (attrs
[LFACE_OVERLINE_INDEX
])
1787 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
1788 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
1789 eassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1790 || IGNORE_DEFFACE_P (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1791 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1792 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
1793 eassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
1794 || IGNORE_DEFFACE_P (attrs
[LFACE_BOX_INDEX
])
1795 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
1796 || STRINGP (attrs
[LFACE_BOX_INDEX
])
1797 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
1798 || CONSP (attrs
[LFACE_BOX_INDEX
]));
1799 eassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
1800 || IGNORE_DEFFACE_P (attrs
[LFACE_INVERSE_INDEX
])
1801 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
1802 eassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
1803 || IGNORE_DEFFACE_P (attrs
[LFACE_FOREGROUND_INDEX
])
1804 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
1805 eassert (UNSPECIFIEDP (attrs
[LFACE_DISTANT_FOREGROUND_INDEX
])
1806 || IGNORE_DEFFACE_P (attrs
[LFACE_DISTANT_FOREGROUND_INDEX
])
1807 || STRINGP (attrs
[LFACE_DISTANT_FOREGROUND_INDEX
]));
1808 eassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
1809 || IGNORE_DEFFACE_P (attrs
[LFACE_BACKGROUND_INDEX
])
1810 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
1811 eassert (UNSPECIFIEDP (attrs
[LFACE_INHERIT_INDEX
])
1812 || IGNORE_DEFFACE_P (attrs
[LFACE_INHERIT_INDEX
])
1813 || NILP (attrs
[LFACE_INHERIT_INDEX
])
1814 || SYMBOLP (attrs
[LFACE_INHERIT_INDEX
])
1815 || CONSP (attrs
[LFACE_INHERIT_INDEX
]));
1816 #ifdef HAVE_WINDOW_SYSTEM
1817 eassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
1818 || IGNORE_DEFFACE_P (attrs
[LFACE_STIPPLE_INDEX
])
1819 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
1820 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
1821 eassert (UNSPECIFIEDP (attrs
[LFACE_FONT_INDEX
])
1822 || IGNORE_DEFFACE_P (attrs
[LFACE_FONT_INDEX
])
1823 || FONTP (attrs
[LFACE_FONT_INDEX
]));
1824 eassert (UNSPECIFIEDP (attrs
[LFACE_FONTSET_INDEX
])
1825 || STRINGP (attrs
[LFACE_FONTSET_INDEX
])
1826 || NILP (attrs
[LFACE_FONTSET_INDEX
]));
1831 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
1834 check_lface (Lisp_Object lface
)
1838 eassert (LFACEP (lface
));
1839 check_lface_attrs (XVECTOR (lface
)->contents
);
1843 #else /* not GLYPH_DEBUG */
1845 #define check_lface_attrs(attrs) (void) 0
1846 #define check_lface(lface) (void) 0
1848 #endif /* GLYPH_DEBUG */
1852 /* Face-merge cycle checking. */
1854 enum named_merge_point_kind
1856 NAMED_MERGE_POINT_NORMAL
,
1857 NAMED_MERGE_POINT_REMAP
1860 /* A `named merge point' is simply a point during face-merging where we
1861 look up a face by name. We keep a stack of which named lookups we're
1862 currently processing so that we can easily detect cycles, using a
1863 linked- list of struct named_merge_point structures, typically
1864 allocated on the stack frame of the named lookup functions which are
1865 active (so no consing is required). */
1866 struct named_merge_point
1868 Lisp_Object face_name
;
1869 enum named_merge_point_kind named_merge_point_kind
;
1870 struct named_merge_point
*prev
;
1874 /* If a face merging cycle is detected for FACE_NAME, return 0,
1875 otherwise add NEW_NAMED_MERGE_POINT, which is initialized using
1876 FACE_NAME and NAMED_MERGE_POINT_KIND, as the head of the linked list
1877 pointed to by NAMED_MERGE_POINTS, and return 1. */
1880 push_named_merge_point (struct named_merge_point
*new_named_merge_point
,
1881 Lisp_Object face_name
,
1882 enum named_merge_point_kind named_merge_point_kind
,
1883 struct named_merge_point
**named_merge_points
)
1885 struct named_merge_point
*prev
;
1887 for (prev
= *named_merge_points
; prev
; prev
= prev
->prev
)
1888 if (EQ (face_name
, prev
->face_name
))
1890 if (prev
->named_merge_point_kind
== named_merge_point_kind
)
1891 /* A cycle, so fail. */
1893 else if (prev
->named_merge_point_kind
== NAMED_MERGE_POINT_REMAP
)
1894 /* A remap `hides ' any previous normal merge points
1895 (because the remap means that it's actually different face),
1896 so as we know the current merge point must be normal, we
1897 can just assume it's OK. */
1901 new_named_merge_point
->face_name
= face_name
;
1902 new_named_merge_point
->named_merge_point_kind
= named_merge_point_kind
;
1903 new_named_merge_point
->prev
= *named_merge_points
;
1905 *named_merge_points
= new_named_merge_point
;
1911 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
1912 to make it a symbol. If FACE_NAME is an alias for another face,
1913 return that face's name.
1915 Return default face in case of errors. */
1918 resolve_face_name (Lisp_Object face_name
, int signal_p
)
1920 Lisp_Object orig_face
;
1921 Lisp_Object tortoise
, hare
;
1923 if (STRINGP (face_name
))
1924 face_name
= intern (SSDATA (face_name
));
1926 if (NILP (face_name
) || !SYMBOLP (face_name
))
1929 orig_face
= face_name
;
1930 tortoise
= hare
= face_name
;
1935 hare
= Fget (hare
, Qface_alias
);
1936 if (NILP (hare
) || !SYMBOLP (hare
))
1940 hare
= Fget (hare
, Qface_alias
);
1941 if (NILP (hare
) || !SYMBOLP (hare
))
1944 tortoise
= Fget (tortoise
, Qface_alias
);
1945 if (EQ (hare
, tortoise
))
1948 xsignal1 (Qcircular_list
, orig_face
);
1957 /* Return the face definition of FACE_NAME on frame F. F null means
1958 return the definition for new frames. FACE_NAME may be a string or
1959 a symbol (apparently Emacs 20.2 allowed strings as face names in
1960 face text properties; Ediff uses that). If SIGNAL_P is non-zero,
1961 signal an error if FACE_NAME is not a valid face name. If SIGNAL_P
1962 is zero, value is nil if FACE_NAME is not a valid face name. */
1964 lface_from_face_name_no_resolve (struct frame
*f
, Lisp_Object face_name
,
1970 lface
= assq_no_quit (face_name
, f
->face_alist
);
1972 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
1975 lface
= XCDR (lface
);
1977 signal_error ("Invalid face", face_name
);
1979 check_lface (lface
);
1984 /* Return the face definition of FACE_NAME on frame F. F null means
1985 return the definition for new frames. FACE_NAME may be a string or
1986 a symbol (apparently Emacs 20.2 allowed strings as face names in
1987 face text properties; Ediff uses that). If FACE_NAME is an alias
1988 for another face, return that face's definition. If SIGNAL_P is
1989 non-zero, signal an error if FACE_NAME is not a valid face name.
1990 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
1993 lface_from_face_name (struct frame
*f
, Lisp_Object face_name
, int signal_p
)
1995 face_name
= resolve_face_name (face_name
, signal_p
);
1996 return lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2000 /* Get face attributes of face FACE_NAME from frame-local faces on
2001 frame F. Store the resulting attributes in ATTRS which must point
2002 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
2003 is non-zero, signal an error if FACE_NAME does not name a face.
2004 Otherwise, value is zero if FACE_NAME is not a face. */
2007 get_lface_attributes_no_remap (struct frame
*f
, Lisp_Object face_name
,
2008 Lisp_Object attrs
[LFACE_VECTOR_SIZE
],
2013 lface
= lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2016 memcpy (attrs
, XVECTOR (lface
)->contents
,
2017 LFACE_VECTOR_SIZE
* sizeof *attrs
);
2019 return !NILP (lface
);
2022 /* Get face attributes of face FACE_NAME from frame-local faces on frame
2023 F. Store the resulting attributes in ATTRS which must point to a
2024 vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If FACE_NAME is an
2025 alias for another face, use that face's definition. If SIGNAL_P is
2026 non-zero, signal an error if FACE_NAME does not name a face.
2027 Otherwise, value is zero if FACE_NAME is not a face. */
2030 get_lface_attributes (struct frame
*f
, Lisp_Object face_name
,
2031 Lisp_Object attrs
[LFACE_VECTOR_SIZE
], int signal_p
,
2032 struct named_merge_point
*named_merge_points
)
2034 Lisp_Object face_remapping
;
2036 face_name
= resolve_face_name (face_name
, signal_p
);
2038 /* See if SYMBOL has been remapped to some other face (usually this
2039 is done buffer-locally). */
2040 face_remapping
= assq_no_quit (face_name
, Vface_remapping_alist
);
2041 if (CONSP (face_remapping
))
2043 struct named_merge_point named_merge_point
;
2045 if (push_named_merge_point (&named_merge_point
,
2046 face_name
, NAMED_MERGE_POINT_REMAP
,
2047 &named_merge_points
))
2051 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2052 attrs
[i
] = Qunspecified
;
2054 return merge_face_ref (f
, XCDR (face_remapping
), attrs
,
2055 signal_p
, named_merge_points
);
2059 /* Default case, no remapping. */
2060 return get_lface_attributes_no_remap (f
, face_name
, attrs
, signal_p
);
2064 /* Non-zero if all attributes in face attribute vector ATTRS are
2065 specified, i.e. are non-nil. */
2068 lface_fully_specified_p (Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
2072 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2073 if (i
!= LFACE_FONT_INDEX
&& i
!= LFACE_INHERIT_INDEX
2074 && i
!= LFACE_DISTANT_FOREGROUND_INDEX
)
2075 if ((UNSPECIFIEDP (attrs
[i
]) || IGNORE_DEFFACE_P (attrs
[i
])))
2078 return i
== LFACE_VECTOR_SIZE
;
2081 #ifdef HAVE_WINDOW_SYSTEM
2083 /* Set font-related attributes of Lisp face LFACE from FONT-OBJECT.
2084 If FORCE_P is zero, set only unspecified attributes of LFACE. The
2085 exception is `font' attribute. It is set to FONT_OBJECT regardless
2089 set_lface_from_font (struct frame
*f
, Lisp_Object lface
,
2090 Lisp_Object font_object
, int force_p
)
2093 struct font
*font
= XFONT_OBJECT (font_object
);
2095 /* Set attributes only if unspecified, otherwise face defaults for
2096 new frames would never take effect. If the font doesn't have a
2097 specific property, set a normal value for that. */
2099 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
2101 Lisp_Object family
= AREF (font_object
, FONT_FAMILY_INDEX
);
2103 ASET (lface
, LFACE_FAMILY_INDEX
, SYMBOL_NAME (family
));
2106 if (force_p
|| UNSPECIFIEDP (LFACE_FOUNDRY (lface
)))
2108 Lisp_Object foundry
= AREF (font_object
, FONT_FOUNDRY_INDEX
);
2110 ASET (lface
, LFACE_FOUNDRY_INDEX
, SYMBOL_NAME (foundry
));
2113 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
2115 int pt
= PIXEL_TO_POINT (font
->pixel_size
* 10, FRAME_RES_Y (f
));
2118 ASET (lface
, LFACE_HEIGHT_INDEX
, make_number (pt
));
2121 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
2123 val
= FONT_WEIGHT_FOR_FACE (font_object
);
2124 ASET (lface
, LFACE_WEIGHT_INDEX
, ! NILP (val
) ? val
:Qnormal
);
2126 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
2128 val
= FONT_SLANT_FOR_FACE (font_object
);
2129 ASET (lface
, LFACE_SLANT_INDEX
, ! NILP (val
) ? val
: Qnormal
);
2131 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
2133 val
= FONT_WIDTH_FOR_FACE (font_object
);
2134 ASET (lface
, LFACE_SWIDTH_INDEX
, ! NILP (val
) ? val
: Qnormal
);
2137 ASET (lface
, LFACE_FONT_INDEX
, font_object
);
2141 #endif /* HAVE_WINDOW_SYSTEM */
2144 /* Merges the face height FROM with the face height TO, and returns the
2145 merged height. If FROM is an invalid height, then INVALID is
2146 returned instead. FROM and TO may be either absolute face heights or
2147 `relative' heights; the returned value is always an absolute height
2148 unless both FROM and TO are relative. */
2151 merge_face_heights (Lisp_Object from
, Lisp_Object to
, Lisp_Object invalid
)
2153 Lisp_Object result
= invalid
;
2155 if (INTEGERP (from
))
2156 /* FROM is absolute, just use it as is. */
2158 else if (FLOATP (from
))
2159 /* FROM is a scale, use it to adjust TO. */
2162 /* relative X absolute => absolute */
2163 result
= make_number (XFLOAT_DATA (from
) * XINT (to
));
2164 else if (FLOATP (to
))
2165 /* relative X relative => relative */
2166 result
= make_float (XFLOAT_DATA (from
) * XFLOAT_DATA (to
));
2167 else if (UNSPECIFIEDP (to
))
2170 else if (FUNCTIONP (from
))
2171 /* FROM is a function, which use to adjust TO. */
2173 /* Call function with current height as argument.
2174 From is the new height. */
2175 result
= safe_call1 (from
, to
);
2177 /* Ensure that if TO was absolute, so is the result. */
2178 if (INTEGERP (to
) && !INTEGERP (result
))
2186 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
2187 store the resulting attributes in TO, which must be already be
2188 completely specified and contain only absolute attributes. Every
2189 specified attribute of FROM overrides the corresponding attribute of
2190 TO; relative attributes in FROM are merged with the absolute value in
2191 TO and replace it. NAMED_MERGE_POINTS is used internally to detect
2192 loops in face inheritance/remapping; it should be 0 when called from
2196 merge_face_vectors (struct frame
*f
, Lisp_Object
*from
, Lisp_Object
*to
,
2197 struct named_merge_point
*named_merge_points
)
2200 Lisp_Object font
= Qnil
;
2202 /* If FROM inherits from some other faces, merge their attributes into
2203 TO before merging FROM's direct attributes. Note that an :inherit
2204 attribute of `unspecified' is the same as one of nil; we never
2205 merge :inherit attributes, so nil is more correct, but lots of
2206 other code uses `unspecified' as a generic value for face attributes. */
2207 if (!UNSPECIFIEDP (from
[LFACE_INHERIT_INDEX
])
2208 && !NILP (from
[LFACE_INHERIT_INDEX
]))
2209 merge_face_ref (f
, from
[LFACE_INHERIT_INDEX
], to
, 0, named_merge_points
);
2211 if (FONT_SPEC_P (from
[LFACE_FONT_INDEX
]))
2213 if (!UNSPECIFIEDP (to
[LFACE_FONT_INDEX
]))
2214 font
= merge_font_spec (from
[LFACE_FONT_INDEX
], to
[LFACE_FONT_INDEX
]);
2216 font
= copy_font_spec (from
[LFACE_FONT_INDEX
]);
2217 to
[LFACE_FONT_INDEX
] = font
;
2220 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2221 if (!UNSPECIFIEDP (from
[i
]))
2223 if (i
== LFACE_HEIGHT_INDEX
&& !INTEGERP (from
[i
]))
2225 to
[i
] = merge_face_heights (from
[i
], to
[i
], to
[i
]);
2226 font_clear_prop (to
, FONT_SIZE_INDEX
);
2228 else if (i
!= LFACE_FONT_INDEX
&& ! EQ (to
[i
], from
[i
]))
2231 if (i
>= LFACE_FAMILY_INDEX
&& i
<=LFACE_SLANT_INDEX
)
2232 font_clear_prop (to
,
2233 (i
== LFACE_FAMILY_INDEX
? FONT_FAMILY_INDEX
2234 : i
== LFACE_FOUNDRY_INDEX
? FONT_FOUNDRY_INDEX
2235 : i
== LFACE_SWIDTH_INDEX
? FONT_WIDTH_INDEX
2236 : i
== LFACE_HEIGHT_INDEX
? FONT_SIZE_INDEX
2237 : i
== LFACE_WEIGHT_INDEX
? FONT_WEIGHT_INDEX
2238 : FONT_SLANT_INDEX
));
2242 /* If FROM specifies a font spec, make its contents take precedence
2243 over :family and other attributes. This is needed for face
2244 remapping using :font to work. */
2248 if (! NILP (AREF (font
, FONT_FOUNDRY_INDEX
)))
2249 to
[LFACE_FOUNDRY_INDEX
] = SYMBOL_NAME (AREF (font
, FONT_FOUNDRY_INDEX
));
2250 if (! NILP (AREF (font
, FONT_FAMILY_INDEX
)))
2251 to
[LFACE_FAMILY_INDEX
] = SYMBOL_NAME (AREF (font
, FONT_FAMILY_INDEX
));
2252 if (! NILP (AREF (font
, FONT_WEIGHT_INDEX
)))
2253 to
[LFACE_WEIGHT_INDEX
] = FONT_WEIGHT_FOR_FACE (font
);
2254 if (! NILP (AREF (font
, FONT_SLANT_INDEX
)))
2255 to
[LFACE_SLANT_INDEX
] = FONT_SLANT_FOR_FACE (font
);
2256 if (! NILP (AREF (font
, FONT_WIDTH_INDEX
)))
2257 to
[LFACE_SWIDTH_INDEX
] = FONT_WIDTH_FOR_FACE (font
);
2258 ASET (font
, FONT_SIZE_INDEX
, Qnil
);
2261 /* TO is always an absolute face, which should inherit from nothing.
2262 We blindly copy the :inherit attribute above and fix it up here. */
2263 to
[LFACE_INHERIT_INDEX
] = Qnil
;
2266 /* Merge the named face FACE_NAME on frame F, into the vector of face
2267 attributes TO. NAMED_MERGE_POINTS is used to detect loops in face
2268 inheritance. Returns true if FACE_NAME is a valid face name and
2269 merging succeeded. */
2272 merge_named_face (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*to
,
2273 struct named_merge_point
*named_merge_points
)
2275 struct named_merge_point named_merge_point
;
2277 if (push_named_merge_point (&named_merge_point
,
2278 face_name
, NAMED_MERGE_POINT_NORMAL
,
2279 &named_merge_points
))
2281 struct gcpro gcpro1
;
2282 Lisp_Object from
[LFACE_VECTOR_SIZE
];
2283 int ok
= get_lface_attributes (f
, face_name
, from
, 0, named_merge_points
);
2287 GCPRO1 (named_merge_point
.face_name
);
2288 merge_face_vectors (f
, from
, to
, named_merge_points
);
2299 /* Merge face attributes from the lisp `face reference' FACE_REF on
2300 frame F into the face attribute vector TO. If ERR_MSGS is non-zero,
2301 problems with FACE_REF cause an error message to be shown. Return
2302 non-zero if no errors occurred (regardless of the value of ERR_MSGS).
2303 NAMED_MERGE_POINTS is used to detect loops in face inheritance or
2304 list structure; it may be 0 for most callers.
2306 FACE_REF may be a single face specification or a list of such
2307 specifications. Each face specification can be:
2309 1. A symbol or string naming a Lisp face.
2311 2. A property list of the form (KEYWORD VALUE ...) where each
2312 KEYWORD is a face attribute name, and value is an appropriate value
2315 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
2316 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
2317 for compatibility with 20.2.
2319 Face specifications earlier in lists take precedence over later
2323 merge_face_ref (struct frame
*f
, Lisp_Object face_ref
, Lisp_Object
*to
,
2324 int err_msgs
, struct named_merge_point
*named_merge_points
)
2326 int ok
= 1; /* Succeed without an error? */
2328 if (CONSP (face_ref
))
2330 Lisp_Object first
= XCAR (face_ref
);
2332 if (EQ (first
, Qforeground_color
)
2333 || EQ (first
, Qbackground_color
))
2335 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
2336 . COLOR). COLOR must be a string. */
2337 Lisp_Object color_name
= XCDR (face_ref
);
2338 Lisp_Object color
= first
;
2340 if (STRINGP (color_name
))
2342 if (EQ (color
, Qforeground_color
))
2343 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
2345 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
2350 add_to_log ("Invalid face color", color_name
, Qnil
);
2354 else if (SYMBOLP (first
)
2355 && *SDATA (SYMBOL_NAME (first
)) == ':')
2357 /* Assume this is the property list form. */
2358 while (CONSP (face_ref
) && CONSP (XCDR (face_ref
)))
2360 Lisp_Object keyword
= XCAR (face_ref
);
2361 Lisp_Object value
= XCAR (XCDR (face_ref
));
2364 /* Specifying `unspecified' is a no-op. */
2365 if (EQ (value
, Qunspecified
))
2367 else if (EQ (keyword
, QCfamily
))
2369 if (STRINGP (value
))
2371 to
[LFACE_FAMILY_INDEX
] = value
;
2372 font_clear_prop (to
, FONT_FAMILY_INDEX
);
2377 else if (EQ (keyword
, QCfoundry
))
2379 if (STRINGP (value
))
2381 to
[LFACE_FOUNDRY_INDEX
] = value
;
2382 font_clear_prop (to
, FONT_FOUNDRY_INDEX
);
2387 else if (EQ (keyword
, QCheight
))
2389 Lisp_Object new_height
=
2390 merge_face_heights (value
, to
[LFACE_HEIGHT_INDEX
], Qnil
);
2392 if (! NILP (new_height
))
2394 to
[LFACE_HEIGHT_INDEX
] = new_height
;
2395 font_clear_prop (to
, FONT_SIZE_INDEX
);
2400 else if (EQ (keyword
, QCweight
))
2402 if (SYMBOLP (value
) && FONT_WEIGHT_NAME_NUMERIC (value
) >= 0)
2404 to
[LFACE_WEIGHT_INDEX
] = value
;
2405 font_clear_prop (to
, FONT_WEIGHT_INDEX
);
2410 else if (EQ (keyword
, QCslant
))
2412 if (SYMBOLP (value
) && FONT_SLANT_NAME_NUMERIC (value
) >= 0)
2414 to
[LFACE_SLANT_INDEX
] = value
;
2415 font_clear_prop (to
, FONT_SLANT_INDEX
);
2420 else if (EQ (keyword
, QCunderline
))
2426 to
[LFACE_UNDERLINE_INDEX
] = value
;
2430 else if (EQ (keyword
, QCoverline
))
2435 to
[LFACE_OVERLINE_INDEX
] = value
;
2439 else if (EQ (keyword
, QCstrike_through
))
2444 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
2448 else if (EQ (keyword
, QCbox
))
2451 value
= make_number (1);
2452 if (INTEGERP (value
)
2456 to
[LFACE_BOX_INDEX
] = value
;
2460 else if (EQ (keyword
, QCinverse_video
)
2461 || EQ (keyword
, QCreverse_video
))
2463 if (EQ (value
, Qt
) || NILP (value
))
2464 to
[LFACE_INVERSE_INDEX
] = value
;
2468 else if (EQ (keyword
, QCforeground
))
2470 if (STRINGP (value
))
2471 to
[LFACE_FOREGROUND_INDEX
] = value
;
2475 else if (EQ (keyword
, QCdistant_foreground
))
2477 if (STRINGP (value
))
2478 to
[LFACE_DISTANT_FOREGROUND_INDEX
] = value
;
2482 else if (EQ (keyword
, QCbackground
))
2484 if (STRINGP (value
))
2485 to
[LFACE_BACKGROUND_INDEX
] = value
;
2489 else if (EQ (keyword
, QCstipple
))
2491 #if defined (HAVE_WINDOW_SYSTEM)
2492 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
2493 if (!NILP (pixmap_p
))
2494 to
[LFACE_STIPPLE_INDEX
] = value
;
2497 #endif /* HAVE_WINDOW_SYSTEM */
2499 else if (EQ (keyword
, QCwidth
))
2501 if (SYMBOLP (value
) && FONT_WIDTH_NAME_NUMERIC (value
) >= 0)
2503 to
[LFACE_SWIDTH_INDEX
] = value
;
2504 font_clear_prop (to
, FONT_WIDTH_INDEX
);
2509 else if (EQ (keyword
, QCfont
))
2512 to
[LFACE_FONT_INDEX
] = value
;
2516 else if (EQ (keyword
, QCinherit
))
2518 /* This is not really very useful; it's just like a
2519 normal face reference. */
2520 if (! merge_face_ref (f
, value
, to
,
2521 err_msgs
, named_merge_points
))
2529 add_to_log ("Invalid face attribute %S %S", keyword
, value
);
2533 face_ref
= XCDR (XCDR (face_ref
));
2538 /* This is a list of face refs. Those at the beginning of the
2539 list take precedence over what follows, so we have to merge
2540 from the end backwards. */
2541 Lisp_Object next
= XCDR (face_ref
);
2544 ok
= merge_face_ref (f
, next
, to
, err_msgs
, named_merge_points
);
2546 if (! merge_face_ref (f
, first
, to
, err_msgs
, named_merge_points
))
2552 /* FACE_REF ought to be a face name. */
2553 ok
= merge_named_face (f
, face_ref
, to
, named_merge_points
);
2554 if (!ok
&& err_msgs
)
2555 add_to_log ("Invalid face reference: %s", face_ref
, Qnil
);
2562 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
2563 Sinternal_make_lisp_face
, 1, 2, 0,
2564 doc
: /* Make FACE, a symbol, a Lisp face with all attributes nil.
2565 If FACE was not known as a face before, create a new one.
2566 If optional argument FRAME is specified, make a frame-local face
2567 for that frame. Otherwise operate on the global face definition.
2568 Value is a vector of face attributes. */)
2569 (Lisp_Object face
, Lisp_Object frame
)
2571 Lisp_Object global_lface
, lface
;
2575 CHECK_SYMBOL (face
);
2576 global_lface
= lface_from_face_name (NULL
, face
, 0);
2580 CHECK_LIVE_FRAME (frame
);
2582 lface
= lface_from_face_name (f
, face
, 0);
2585 f
= NULL
, lface
= Qnil
;
2587 /* Add a global definition if there is none. */
2588 if (NILP (global_lface
))
2590 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2592 ASET (global_lface
, 0, Qface
);
2593 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
2594 Vface_new_frame_defaults
);
2596 /* Assign the new Lisp face a unique ID. The mapping from Lisp
2597 face id to Lisp face is given by the vector lface_id_to_name.
2598 The mapping from Lisp face to Lisp face id is given by the
2599 property `face' of the Lisp face name. */
2600 if (next_lface_id
== lface_id_to_name_size
)
2602 xpalloc (lface_id_to_name
, &lface_id_to_name_size
, 1, MAX_FACE_ID
,
2603 sizeof *lface_id_to_name
);
2605 lface_id_to_name
[next_lface_id
] = face
;
2606 Fput (face
, Qface
, make_number (next_lface_id
));
2610 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2611 ASET (global_lface
, i
, Qunspecified
);
2613 /* Add a frame-local definition. */
2618 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2620 ASET (lface
, 0, Qface
);
2621 fset_face_alist (f
, Fcons (Fcons (face
, lface
), f
->face_alist
));
2624 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2625 ASET (lface
, i
, Qunspecified
);
2628 lface
= global_lface
;
2630 /* Changing a named face means that all realized faces depending on
2631 that face are invalid. Since we cannot tell which realized faces
2632 depend on the face, make sure they are all removed. This is done
2633 by incrementing face_change_count. The next call to
2634 init_iterator will then free realized faces. */
2635 if (NILP (Fget (face
, Qface_no_inherit
)))
2637 ++face_change_count
;
2638 windows_or_buffers_changed
= 54;
2641 eassert (LFACEP (lface
));
2642 check_lface (lface
);
2647 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
2648 Sinternal_lisp_face_p
, 1, 2, 0,
2649 doc
: /* Return non-nil if FACE names a face.
2650 FACE should be a symbol or string.
2651 If optional second argument FRAME is non-nil, check for the
2652 existence of a frame-local face with name FACE on that frame.
2653 Otherwise check for the existence of a global face. */)
2654 (Lisp_Object face
, Lisp_Object frame
)
2658 face
= resolve_face_name (face
, 1);
2662 CHECK_LIVE_FRAME (frame
);
2663 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2666 lface
= lface_from_face_name (NULL
, face
, 0);
2672 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
2673 Sinternal_copy_lisp_face
, 4, 4, 0,
2674 doc
: /* Copy face FROM to TO.
2675 If FRAME is t, copy the global face definition of FROM.
2676 Otherwise, copy the frame-local definition of FROM on FRAME.
2677 If NEW-FRAME is a frame, copy that data into the frame-local
2678 definition of TO on NEW-FRAME. If NEW-FRAME is nil,
2679 FRAME controls where the data is copied to.
2681 The value is TO. */)
2682 (Lisp_Object from
, Lisp_Object to
, Lisp_Object frame
, Lisp_Object new_frame
)
2684 Lisp_Object lface
, copy
;
2686 CHECK_SYMBOL (from
);
2691 /* Copy global definition of FROM. We don't make copies of
2692 strings etc. because 20.2 didn't do it either. */
2693 lface
= lface_from_face_name (NULL
, from
, 1);
2694 copy
= Finternal_make_lisp_face (to
, Qnil
);
2698 /* Copy frame-local definition of FROM. */
2699 if (NILP (new_frame
))
2701 CHECK_LIVE_FRAME (frame
);
2702 CHECK_LIVE_FRAME (new_frame
);
2703 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
2704 copy
= Finternal_make_lisp_face (to
, new_frame
);
2707 vcopy (copy
, 0, XVECTOR (lface
)->contents
, LFACE_VECTOR_SIZE
);
2709 /* Changing a named face means that all realized faces depending on
2710 that face are invalid. Since we cannot tell which realized faces
2711 depend on the face, make sure they are all removed. This is done
2712 by incrementing face_change_count. The next call to
2713 init_iterator will then free realized faces. */
2714 if (NILP (Fget (to
, Qface_no_inherit
)))
2716 ++face_change_count
;
2717 windows_or_buffers_changed
= 55;
2724 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
2725 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
2726 doc
: /* Set attribute ATTR of FACE to VALUE.
2727 FRAME being a frame means change the face on that frame.
2728 FRAME nil means change the face of the selected frame.
2729 FRAME t means change the default for new frames.
2730 FRAME 0 means change the face on all frames, and change the default
2732 (Lisp_Object face
, Lisp_Object attr
, Lisp_Object value
, Lisp_Object frame
)
2735 Lisp_Object old_value
= Qnil
;
2736 /* Set one of enum font_property_index (> 0) if ATTR is one of
2737 font-related attributes other than QCfont and QCfontset. */
2738 enum font_property_index prop_index
= 0;
2740 CHECK_SYMBOL (face
);
2741 CHECK_SYMBOL (attr
);
2743 face
= resolve_face_name (face
, 1);
2745 /* If FRAME is 0, change face on all frames, and change the
2746 default for new frames. */
2747 if (INTEGERP (frame
) && XINT (frame
) == 0)
2750 Finternal_set_lisp_face_attribute (face
, attr
, value
, Qt
);
2751 FOR_EACH_FRAME (tail
, frame
)
2752 Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
2756 /* Set lface to the Lisp attribute vector of FACE. */
2759 lface
= lface_from_face_name (NULL
, face
, 1);
2761 /* When updating face-new-frame-defaults, we put :ignore-defface
2762 where the caller wants `unspecified'. This forces the frame
2763 defaults to ignore the defface value. Otherwise, the defface
2764 will take effect, which is generally not what is intended.
2765 The value of that attribute will be inherited from some other
2766 face during face merging. See internal_merge_in_global_face. */
2767 if (UNSPECIFIEDP (value
))
2768 value
= QCignore_defface
;
2773 frame
= selected_frame
;
2775 CHECK_LIVE_FRAME (frame
);
2776 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2778 /* If a frame-local face doesn't exist yet, create one. */
2780 lface
= Finternal_make_lisp_face (face
, frame
);
2783 if (EQ (attr
, QCfamily
))
2785 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2787 CHECK_STRING (value
);
2788 if (SCHARS (value
) == 0)
2789 signal_error ("Invalid face family", value
);
2791 old_value
= LFACE_FAMILY (lface
);
2792 ASET (lface
, LFACE_FAMILY_INDEX
, value
);
2793 prop_index
= FONT_FAMILY_INDEX
;
2795 else if (EQ (attr
, QCfoundry
))
2797 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2799 CHECK_STRING (value
);
2800 if (SCHARS (value
) == 0)
2801 signal_error ("Invalid face foundry", value
);
2803 old_value
= LFACE_FOUNDRY (lface
);
2804 ASET (lface
, LFACE_FOUNDRY_INDEX
, value
);
2805 prop_index
= FONT_FOUNDRY_INDEX
;
2807 else if (EQ (attr
, QCheight
))
2809 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2811 if (EQ (face
, Qdefault
))
2813 /* The default face must have an absolute size. */
2814 if (!INTEGERP (value
) || XINT (value
) <= 0)
2815 signal_error ("Default face height not absolute and positive",
2820 /* For non-default faces, do a test merge with a random
2821 height to see if VALUE's ok. */
2822 Lisp_Object test
= merge_face_heights (value
,
2825 if (!INTEGERP (test
) || XINT (test
) <= 0)
2826 signal_error ("Face height does not produce a positive integer",
2831 old_value
= LFACE_HEIGHT (lface
);
2832 ASET (lface
, LFACE_HEIGHT_INDEX
, value
);
2833 prop_index
= FONT_SIZE_INDEX
;
2835 else if (EQ (attr
, QCweight
))
2837 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2839 CHECK_SYMBOL (value
);
2840 if (FONT_WEIGHT_NAME_NUMERIC (value
) < 0)
2841 signal_error ("Invalid face weight", value
);
2843 old_value
= LFACE_WEIGHT (lface
);
2844 ASET (lface
, LFACE_WEIGHT_INDEX
, value
);
2845 prop_index
= FONT_WEIGHT_INDEX
;
2847 else if (EQ (attr
, QCslant
))
2849 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2851 CHECK_SYMBOL (value
);
2852 if (FONT_SLANT_NAME_NUMERIC (value
) < 0)
2853 signal_error ("Invalid face slant", value
);
2855 old_value
= LFACE_SLANT (lface
);
2856 ASET (lface
, LFACE_SLANT_INDEX
, value
);
2857 prop_index
= FONT_SLANT_INDEX
;
2859 else if (EQ (attr
, QCunderline
))
2863 if (UNSPECIFIEDP (value
) || IGNORE_DEFFACE_P (value
))
2865 else if (NILP (value
) || EQ (value
, Qt
))
2867 else if (STRINGP (value
) && SCHARS (value
) > 0)
2869 else if (CONSP (value
))
2871 Lisp_Object key
, val
, list
;
2874 /* FIXME? This errs on the side of acceptance. Eg it accepts:
2875 (defface foo '((t :underline 'foo) "doc")
2876 Maybe this is intentional, maybe it isn't.
2877 Non-nil symbols other than t are not documented as being valid.
2878 Eg compare with inverse-video, which explicitly rejects them.
2882 while (!NILP (CAR_SAFE(list
)))
2884 key
= CAR_SAFE (list
);
2885 list
= CDR_SAFE (list
);
2886 val
= CAR_SAFE (list
);
2887 list
= CDR_SAFE (list
);
2889 if (NILP (key
) || NILP (val
))
2895 else if (EQ (key
, QCcolor
)
2896 && !(EQ (val
, Qforeground_color
)
2897 || (STRINGP (val
) && SCHARS (val
) > 0)))
2903 else if (EQ (key
, QCstyle
)
2904 && !(EQ (val
, Qline
) || EQ (val
, Qwave
)))
2913 signal_error ("Invalid face underline", value
);
2915 old_value
= LFACE_UNDERLINE (lface
);
2916 ASET (lface
, LFACE_UNDERLINE_INDEX
, value
);
2918 else if (EQ (attr
, QCoverline
))
2920 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2921 if ((SYMBOLP (value
)
2923 && !EQ (value
, Qnil
))
2924 /* Overline color. */
2926 && SCHARS (value
) == 0))
2927 signal_error ("Invalid face overline", value
);
2929 old_value
= LFACE_OVERLINE (lface
);
2930 ASET (lface
, LFACE_OVERLINE_INDEX
, value
);
2932 else if (EQ (attr
, QCstrike_through
))
2934 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2935 if ((SYMBOLP (value
)
2937 && !EQ (value
, Qnil
))
2938 /* Strike-through color. */
2940 && SCHARS (value
) == 0))
2941 signal_error ("Invalid face strike-through", value
);
2943 old_value
= LFACE_STRIKE_THROUGH (lface
);
2944 ASET (lface
, LFACE_STRIKE_THROUGH_INDEX
, value
);
2946 else if (EQ (attr
, QCbox
))
2950 /* Allow t meaning a simple box of width 1 in foreground color
2953 value
= make_number (1);
2955 if (UNSPECIFIEDP (value
) || IGNORE_DEFFACE_P (value
))
2957 else if (NILP (value
))
2959 else if (INTEGERP (value
))
2960 valid_p
= XINT (value
) != 0;
2961 else if (STRINGP (value
))
2962 valid_p
= SCHARS (value
) > 0;
2963 else if (CONSP (value
))
2979 if (EQ (k
, QCline_width
))
2981 if (!INTEGERP (v
) || XINT (v
) == 0)
2984 else if (EQ (k
, QCcolor
))
2986 if (!NILP (v
) && (!STRINGP (v
) || SCHARS (v
) == 0))
2989 else if (EQ (k
, QCstyle
))
2991 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
2998 valid_p
= NILP (tem
);
3004 signal_error ("Invalid face box", value
);
3006 old_value
= LFACE_BOX (lface
);
3007 ASET (lface
, LFACE_BOX_INDEX
, value
);
3009 else if (EQ (attr
, QCinverse_video
)
3010 || EQ (attr
, QCreverse_video
))
3012 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3014 CHECK_SYMBOL (value
);
3015 if (!EQ (value
, Qt
) && !NILP (value
))
3016 signal_error ("Invalid inverse-video face attribute value", value
);
3018 old_value
= LFACE_INVERSE (lface
);
3019 ASET (lface
, LFACE_INVERSE_INDEX
, value
);
3021 else if (EQ (attr
, QCforeground
))
3023 /* Compatibility with 20.x. */
3025 value
= Qunspecified
;
3026 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3028 /* Don't check for valid color names here because it depends
3029 on the frame (display) whether the color will be valid
3030 when the face is realized. */
3031 CHECK_STRING (value
);
3032 if (SCHARS (value
) == 0)
3033 signal_error ("Empty foreground color value", value
);
3035 old_value
= LFACE_FOREGROUND (lface
);
3036 ASET (lface
, LFACE_FOREGROUND_INDEX
, value
);
3038 else if (EQ (attr
, QCdistant_foreground
))
3040 /* Compatibility with 20.x. */
3042 value
= Qunspecified
;
3043 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3045 /* Don't check for valid color names here because it depends
3046 on the frame (display) whether the color will be valid
3047 when the face is realized. */
3048 CHECK_STRING (value
);
3049 if (SCHARS (value
) == 0)
3050 signal_error ("Empty distant-foreground color value", value
);
3052 old_value
= LFACE_DISTANT_FOREGROUND (lface
);
3053 ASET (lface
, LFACE_DISTANT_FOREGROUND_INDEX
, value
);
3055 else if (EQ (attr
, QCbackground
))
3057 /* Compatibility with 20.x. */
3059 value
= Qunspecified
;
3060 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3062 /* Don't check for valid color names here because it depends
3063 on the frame (display) whether the color will be valid
3064 when the face is realized. */
3065 CHECK_STRING (value
);
3066 if (SCHARS (value
) == 0)
3067 signal_error ("Empty background color value", value
);
3069 old_value
= LFACE_BACKGROUND (lface
);
3070 ASET (lface
, LFACE_BACKGROUND_INDEX
, value
);
3072 else if (EQ (attr
, QCstipple
))
3074 #if defined (HAVE_WINDOW_SYSTEM)
3075 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3077 && NILP (Fbitmap_spec_p (value
)))
3078 signal_error ("Invalid stipple attribute", value
);
3079 old_value
= LFACE_STIPPLE (lface
);
3080 ASET (lface
, LFACE_STIPPLE_INDEX
, value
);
3081 #endif /* HAVE_WINDOW_SYSTEM */
3083 else if (EQ (attr
, QCwidth
))
3085 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3087 CHECK_SYMBOL (value
);
3088 if (FONT_WIDTH_NAME_NUMERIC (value
) < 0)
3089 signal_error ("Invalid face width", value
);
3091 old_value
= LFACE_SWIDTH (lface
);
3092 ASET (lface
, LFACE_SWIDTH_INDEX
, value
);
3093 prop_index
= FONT_WIDTH_INDEX
;
3095 else if (EQ (attr
, QCfont
))
3097 #ifdef HAVE_WINDOW_SYSTEM
3098 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3100 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3104 old_value
= LFACE_FONT (lface
);
3105 if (! FONTP (value
))
3107 if (STRINGP (value
))
3109 Lisp_Object name
= value
;
3110 int fontset
= fs_query_fontset (name
, 0);
3113 name
= fontset_ascii (fontset
);
3114 value
= font_spec_from_name (name
);
3116 signal_error ("Invalid font name", name
);
3119 signal_error ("Invalid font or font-spec", value
);
3122 f
= XFRAME (selected_frame
);
3125 if (! FONT_OBJECT_P (value
))
3127 Lisp_Object
*attrs
= XVECTOR (lface
)->contents
;
3128 Lisp_Object font_object
;
3130 font_object
= font_load_for_lface (f
, attrs
, value
);
3131 if (NILP (font_object
))
3132 signal_error ("Font not available", value
);
3133 value
= font_object
;
3135 set_lface_from_font (f
, lface
, value
, 1);
3138 ASET (lface
, LFACE_FONT_INDEX
, value
);
3140 #endif /* HAVE_WINDOW_SYSTEM */
3142 else if (EQ (attr
, QCfontset
))
3144 #ifdef HAVE_WINDOW_SYSTEM
3145 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3149 old_value
= LFACE_FONTSET (lface
);
3150 tmp
= Fquery_fontset (value
, Qnil
);
3152 signal_error ("Invalid fontset name", value
);
3153 ASET (lface
, LFACE_FONTSET_INDEX
, value
= tmp
);
3155 #endif /* HAVE_WINDOW_SYSTEM */
3157 else if (EQ (attr
, QCinherit
))
3160 if (SYMBOLP (value
))
3163 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
3164 if (!SYMBOLP (XCAR (tail
)))
3167 ASET (lface
, LFACE_INHERIT_INDEX
, value
);
3169 signal_error ("Invalid face inheritance", value
);
3171 else if (EQ (attr
, QCbold
))
3173 old_value
= LFACE_WEIGHT (lface
);
3174 ASET (lface
, LFACE_WEIGHT_INDEX
, NILP (value
) ? Qnormal
: Qbold
);
3175 prop_index
= FONT_WEIGHT_INDEX
;
3177 else if (EQ (attr
, QCitalic
))
3180 old_value
= LFACE_SLANT (lface
);
3181 ASET (lface
, LFACE_SLANT_INDEX
, NILP (value
) ? Qnormal
: Qitalic
);
3182 prop_index
= FONT_SLANT_INDEX
;
3185 signal_error ("Invalid face attribute name", attr
);
3189 /* If a font-related attribute other than QCfont and QCfontset
3190 is specified, and if the original QCfont attribute has a font
3191 (font-spec or font-object), set the corresponding property in
3192 the font to nil so that the font selector doesn't think that
3193 the attribute is mandatory. Also, clear the average
3195 font_clear_prop (XVECTOR (lface
)->contents
, prop_index
);
3198 /* Changing a named face means that all realized faces depending on
3199 that face are invalid. Since we cannot tell which realized faces
3200 depend on the face, make sure they are all removed. This is done
3201 by incrementing face_change_count. The next call to
3202 init_iterator will then free realized faces. */
3204 && NILP (Fget (face
, Qface_no_inherit
))
3205 && NILP (Fequal (old_value
, value
)))
3207 ++face_change_count
;
3208 windows_or_buffers_changed
= 56;
3211 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3212 && NILP (Fequal (old_value
, value
)))
3218 if (EQ (face
, Qdefault
))
3220 #ifdef HAVE_WINDOW_SYSTEM
3221 /* Changed font-related attributes of the `default' face are
3222 reflected in changed `font' frame parameters. */
3224 && (prop_index
|| EQ (attr
, QCfont
))
3225 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
3226 set_font_frame_param (frame
, lface
);
3228 #endif /* HAVE_WINDOW_SYSTEM */
3230 if (EQ (attr
, QCforeground
))
3231 param
= Qforeground_color
;
3232 else if (EQ (attr
, QCbackground
))
3233 param
= Qbackground_color
;
3235 #ifdef HAVE_WINDOW_SYSTEM
3237 else if (EQ (face
, Qscroll_bar
))
3239 /* Changing the colors of `scroll-bar' sets frame parameters
3240 `scroll-bar-foreground' and `scroll-bar-background'. */
3241 if (EQ (attr
, QCforeground
))
3242 param
= Qscroll_bar_foreground
;
3243 else if (EQ (attr
, QCbackground
))
3244 param
= Qscroll_bar_background
;
3246 #endif /* not HAVE_NTGUI */
3247 else if (EQ (face
, Qborder
))
3249 /* Changing background color of `border' sets frame parameter
3251 if (EQ (attr
, QCbackground
))
3252 param
= Qborder_color
;
3254 else if (EQ (face
, Qcursor
))
3256 /* Changing background color of `cursor' sets frame parameter
3258 if (EQ (attr
, QCbackground
))
3259 param
= Qcursor_color
;
3261 else if (EQ (face
, Qmouse
))
3263 /* Changing background color of `mouse' sets frame parameter
3265 if (EQ (attr
, QCbackground
))
3266 param
= Qmouse_color
;
3268 #endif /* HAVE_WINDOW_SYSTEM */
3269 else if (EQ (face
, Qmenu
))
3271 /* Indicate that we have to update the menu bar when realizing
3272 faces on FRAME. FRAME t change the default for new frames.
3273 We do this by setting the flag in new face caches. */
3276 struct frame
*f
= XFRAME (frame
);
3277 if (FRAME_FACE_CACHE (f
) == NULL
)
3278 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
3279 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 1;
3282 menu_face_changed_default
= 1;
3288 /* Update `default-frame-alist', which is used for new frames. */
3290 store_in_alist (&Vdefault_frame_alist
, param
, value
);
3293 /* Update the current frame's parameters. */
3296 cons
= XCAR (Vparam_value_alist
);
3297 XSETCAR (cons
, param
);
3298 XSETCDR (cons
, value
);
3299 Fmodify_frame_parameters (frame
, Vparam_value_alist
);
3308 /* Update the corresponding face when frame parameter PARAM on frame F
3309 has been assigned the value NEW_VALUE. */
3312 update_face_from_frame_parameter (struct frame
*f
, Lisp_Object param
,
3313 Lisp_Object new_value
)
3315 Lisp_Object face
= Qnil
;
3318 /* If there are no faces yet, give up. This is the case when called
3319 from Fx_create_frame, and we do the necessary things later in
3320 face-set-after-frame-defaults. */
3321 if (NILP (f
->face_alist
))
3324 if (EQ (param
, Qforeground_color
))
3327 lface
= lface_from_face_name (f
, face
, 1);
3328 ASET (lface
, LFACE_FOREGROUND_INDEX
,
3329 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3330 realize_basic_faces (f
);
3332 else if (EQ (param
, Qbackground_color
))
3336 /* Changing the background color might change the background
3337 mode, so that we have to load new defface specs.
3338 Call frame-set-background-mode to do that. */
3339 XSETFRAME (frame
, f
);
3340 call1 (Qframe_set_background_mode
, frame
);
3343 lface
= lface_from_face_name (f
, face
, 1);
3344 ASET (lface
, LFACE_BACKGROUND_INDEX
,
3345 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3346 realize_basic_faces (f
);
3348 #ifdef HAVE_WINDOW_SYSTEM
3349 else if (EQ (param
, Qborder_color
))
3352 lface
= lface_from_face_name (f
, face
, 1);
3353 ASET (lface
, LFACE_BACKGROUND_INDEX
,
3354 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3356 else if (EQ (param
, Qcursor_color
))
3359 lface
= lface_from_face_name (f
, face
, 1);
3360 ASET (lface
, LFACE_BACKGROUND_INDEX
,
3361 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3363 else if (EQ (param
, Qmouse_color
))
3366 lface
= lface_from_face_name (f
, face
, 1);
3367 ASET (lface
, LFACE_BACKGROUND_INDEX
,
3368 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3372 /* Changing a named face means that all realized faces depending on
3373 that face are invalid. Since we cannot tell which realized faces
3374 depend on the face, make sure they are all removed. This is done
3375 by incrementing face_change_count. The next call to
3376 init_iterator will then free realized faces. */
3378 && NILP (Fget (face
, Qface_no_inherit
)))
3380 ++face_change_count
;
3381 windows_or_buffers_changed
= 57;
3386 #ifdef HAVE_WINDOW_SYSTEM
3388 /* Set the `font' frame parameter of FRAME determined from the
3389 font-object set in `default' face attributes LFACE. */
3392 set_font_frame_param (Lisp_Object frame
, Lisp_Object lface
)
3394 struct frame
*f
= XFRAME (frame
);
3397 if (FRAME_WINDOW_P (f
)
3398 /* Don't do anything if the font is `unspecified'. This can
3399 happen during frame creation. */
3400 && (font
= LFACE_FONT (lface
),
3401 ! UNSPECIFIEDP (font
)))
3403 if (FONT_SPEC_P (font
))
3405 font
= font_load_for_lface (f
, XVECTOR (lface
)->contents
, font
);
3408 ASET (lface
, LFACE_FONT_INDEX
, font
);
3410 f
->default_face_done_p
= 0;
3411 Fmodify_frame_parameters (frame
, list1 (Fcons (Qfont
, font
)));
3415 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
3416 Sinternal_face_x_get_resource
, 2, 3, 0,
3417 doc
: /* Get the value of X resource RESOURCE, class CLASS.
3418 Returned value is for the display of frame FRAME. If FRAME is not
3419 specified or nil, use selected frame. This function exists because
3420 ordinary `x-get-resource' doesn't take a frame argument. */)
3421 (Lisp_Object resource
, Lisp_Object
class, Lisp_Object frame
)
3423 Lisp_Object value
= Qnil
;
3426 CHECK_STRING (resource
);
3427 CHECK_STRING (class);
3428 f
= decode_live_frame (frame
);
3430 value
= display_x_get_resource (FRAME_DISPLAY_INFO (f
),
3431 resource
, class, Qnil
, Qnil
);
3437 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
3438 If VALUE is "on" or "true", return t. If VALUE is "off" or
3439 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
3440 error; if SIGNAL_P is zero, return 0. */
3443 face_boolean_x_resource_value (Lisp_Object value
, int signal_p
)
3445 Lisp_Object result
= make_number (0);
3447 eassert (STRINGP (value
));
3449 if (xstrcasecmp (SSDATA (value
), "on") == 0
3450 || xstrcasecmp (SSDATA (value
), "true") == 0)
3452 else if (xstrcasecmp (SSDATA (value
), "off") == 0
3453 || xstrcasecmp (SSDATA (value
), "false") == 0)
3455 else if (xstrcasecmp (SSDATA (value
), "unspecified") == 0)
3456 result
= Qunspecified
;
3458 signal_error ("Invalid face attribute value from X resource", value
);
3464 DEFUN ("internal-set-lisp-face-attribute-from-resource",
3465 Finternal_set_lisp_face_attribute_from_resource
,
3466 Sinternal_set_lisp_face_attribute_from_resource
,
3467 3, 4, 0, doc
: /* */)
3468 (Lisp_Object face
, Lisp_Object attr
, Lisp_Object value
, Lisp_Object frame
)
3470 CHECK_SYMBOL (face
);
3471 CHECK_SYMBOL (attr
);
3472 CHECK_STRING (value
);
3474 if (xstrcasecmp (SSDATA (value
), "unspecified") == 0)
3475 value
= Qunspecified
;
3476 else if (EQ (attr
, QCheight
))
3478 value
= Fstring_to_number (value
, make_number (10));
3479 if (XINT (value
) <= 0)
3480 signal_error ("Invalid face height from X resource", value
);
3482 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
3483 value
= face_boolean_x_resource_value (value
, 1);
3484 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
3485 value
= intern (SSDATA (value
));
3486 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
3487 value
= face_boolean_x_resource_value (value
, 1);
3488 else if (EQ (attr
, QCunderline
)
3489 || EQ (attr
, QCoverline
)
3490 || EQ (attr
, QCstrike_through
))
3492 Lisp_Object boolean_value
;
3494 /* If the result of face_boolean_x_resource_value is t or nil,
3495 VALUE does NOT specify a color. */
3496 boolean_value
= face_boolean_x_resource_value (value
, 0);
3497 if (SYMBOLP (boolean_value
))
3498 value
= boolean_value
;
3500 else if (EQ (attr
, QCbox
) || EQ (attr
, QCinherit
))
3501 value
= Fcar (Fread_from_string (value
, Qnil
, Qnil
));
3503 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3506 #endif /* HAVE_WINDOW_SYSTEM */
3509 /***********************************************************************
3511 ***********************************************************************/
3513 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
3515 /* Make menus on frame F appear as specified by the `menu' face. */
3518 x_update_menu_appearance (struct frame
*f
)
3520 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
3524 && (rdb
= XrmGetDatabase (FRAME_X_DISPLAY (f
)),
3529 ptrdiff_t bufsize
= sizeof line
;
3530 Lisp_Object lface
= lface_from_face_name (f
, Qmenu
, 1);
3531 struct face
*face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
3532 const char *myname
= SSDATA (Vx_resource_name
);
3535 const char *popup_path
= "popup_menu";
3537 const char *popup_path
= "menu.popup";
3540 if (STRINGP (LFACE_FOREGROUND (lface
)))
3542 exprintf (&buf
, &bufsize
, line
, -1, "%s.%s*foreground: %s",
3544 SDATA (LFACE_FOREGROUND (lface
)));
3545 XrmPutLineResource (&rdb
, line
);
3546 exprintf (&buf
, &bufsize
, line
, -1, "%s.pane.menubar*foreground: %s",
3547 myname
, SDATA (LFACE_FOREGROUND (lface
)));
3548 XrmPutLineResource (&rdb
, line
);
3552 if (STRINGP (LFACE_BACKGROUND (lface
)))
3554 exprintf (&buf
, &bufsize
, line
, -1, "%s.%s*background: %s",
3556 SDATA (LFACE_BACKGROUND (lface
)));
3557 XrmPutLineResource (&rdb
, line
);
3559 exprintf (&buf
, &bufsize
, line
, -1, "%s.pane.menubar*background: %s",
3560 myname
, SDATA (LFACE_BACKGROUND (lface
)));
3561 XrmPutLineResource (&rdb
, line
);
3566 /* On Solaris 5.8, it's been reported that the `menu' face
3567 can be unspecified here, during startup. Why this
3568 happens remains unknown. -- cyd */
3569 && FONTP (LFACE_FONT (lface
))
3570 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
3571 || !UNSPECIFIEDP (LFACE_FOUNDRY (lface
))
3572 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
3573 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3574 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
3575 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
3577 Lisp_Object xlfd
= Ffont_xlfd_name (LFACE_FONT (lface
), Qnil
);
3579 const char *suffix
= "List";
3582 #if defined HAVE_X_I18N
3584 const char *suffix
= "Set";
3586 const char *suffix
= "";
3593 #if defined HAVE_X_I18N
3594 char *fontsetname
= xic_create_fontsetname (SSDATA (xlfd
), motif
);
3596 char *fontsetname
= SSDATA (xlfd
);
3598 exprintf (&buf
, &bufsize
, line
, -1, "%s.pane.menubar*font%s: %s",
3599 myname
, suffix
, fontsetname
);
3600 XrmPutLineResource (&rdb
, line
);
3602 exprintf (&buf
, &bufsize
, line
, -1, "%s.%s*font%s: %s",
3603 myname
, popup_path
, suffix
, fontsetname
);
3604 XrmPutLineResource (&rdb
, line
);
3606 if (fontsetname
!= SSDATA (xlfd
))
3607 xfree (fontsetname
);
3611 if (changed_p
&& f
->output_data
.x
->menubar_widget
)
3612 free_frame_menubar (f
);
3619 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
3622 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p
,
3623 Sface_attribute_relative_p
,
3625 doc
: /* Check whether a face attribute value is relative.
3626 Specifically, this function returns t if the attribute ATTRIBUTE
3627 with the value VALUE is relative.
3629 A relative value is one that doesn't entirely override whatever is
3630 inherited from another face. For most possible attributes,
3631 the only relative value that users see is `unspecified'.
3632 However, for :height, floating point values are also relative. */)
3633 (Lisp_Object attribute
, Lisp_Object value
)
3635 if (EQ (value
, Qunspecified
) || (EQ (value
, QCignore_defface
)))
3637 else if (EQ (attribute
, QCheight
))
3638 return INTEGERP (value
) ? Qnil
: Qt
;
3643 DEFUN ("merge-face-attribute", Fmerge_face_attribute
, Smerge_face_attribute
,
3645 doc
: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
3646 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
3647 the result will be absolute, otherwise it will be relative. */)
3648 (Lisp_Object attribute
, Lisp_Object value1
, Lisp_Object value2
)
3650 if (EQ (value1
, Qunspecified
) || EQ (value1
, QCignore_defface
))
3652 else if (EQ (attribute
, QCheight
))
3653 return merge_face_heights (value1
, value2
, value1
);
3659 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
3660 Sinternal_get_lisp_face_attribute
,
3662 doc
: /* Return face attribute KEYWORD of face SYMBOL.
3663 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
3664 face attribute name, signal an error.
3665 If the optional argument FRAME is given, report on face SYMBOL in that
3666 frame. If FRAME is t, report on the defaults for face SYMBOL (for new
3667 frames). If FRAME is omitted or nil, use the selected frame. */)
3668 (Lisp_Object symbol
, Lisp_Object keyword
, Lisp_Object frame
)
3670 struct frame
*f
= EQ (frame
, Qt
) ? NULL
: decode_live_frame (frame
);
3671 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 1), value
= Qnil
;
3673 CHECK_SYMBOL (symbol
);
3674 CHECK_SYMBOL (keyword
);
3676 if (EQ (keyword
, QCfamily
))
3677 value
= LFACE_FAMILY (lface
);
3678 else if (EQ (keyword
, QCfoundry
))
3679 value
= LFACE_FOUNDRY (lface
);
3680 else if (EQ (keyword
, QCheight
))
3681 value
= LFACE_HEIGHT (lface
);
3682 else if (EQ (keyword
, QCweight
))
3683 value
= LFACE_WEIGHT (lface
);
3684 else if (EQ (keyword
, QCslant
))
3685 value
= LFACE_SLANT (lface
);
3686 else if (EQ (keyword
, QCunderline
))
3687 value
= LFACE_UNDERLINE (lface
);
3688 else if (EQ (keyword
, QCoverline
))
3689 value
= LFACE_OVERLINE (lface
);
3690 else if (EQ (keyword
, QCstrike_through
))
3691 value
= LFACE_STRIKE_THROUGH (lface
);
3692 else if (EQ (keyword
, QCbox
))
3693 value
= LFACE_BOX (lface
);
3694 else if (EQ (keyword
, QCinverse_video
)
3695 || EQ (keyword
, QCreverse_video
))
3696 value
= LFACE_INVERSE (lface
);
3697 else if (EQ (keyword
, QCforeground
))
3698 value
= LFACE_FOREGROUND (lface
);
3699 else if (EQ (keyword
, QCdistant_foreground
))
3700 value
= LFACE_DISTANT_FOREGROUND (lface
);
3701 else if (EQ (keyword
, QCbackground
))
3702 value
= LFACE_BACKGROUND (lface
);
3703 else if (EQ (keyword
, QCstipple
))
3704 value
= LFACE_STIPPLE (lface
);
3705 else if (EQ (keyword
, QCwidth
))
3706 value
= LFACE_SWIDTH (lface
);
3707 else if (EQ (keyword
, QCinherit
))
3708 value
= LFACE_INHERIT (lface
);
3709 else if (EQ (keyword
, QCfont
))
3710 value
= LFACE_FONT (lface
);
3711 else if (EQ (keyword
, QCfontset
))
3712 value
= LFACE_FONTSET (lface
);
3714 signal_error ("Invalid face attribute name", keyword
);
3716 if (IGNORE_DEFFACE_P (value
))
3717 return Qunspecified
;
3723 DEFUN ("internal-lisp-face-attribute-values",
3724 Finternal_lisp_face_attribute_values
,
3725 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
3726 doc
: /* Return a list of valid discrete values for face attribute ATTR.
3727 Value is nil if ATTR doesn't have a discrete set of valid values. */)
3730 Lisp_Object result
= Qnil
;
3732 CHECK_SYMBOL (attr
);
3734 if (EQ (attr
, QCunderline
) || EQ (attr
, QCoverline
)
3735 || EQ (attr
, QCstrike_through
)
3736 || EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
3737 result
= list2 (Qt
, Qnil
);
3743 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
3744 Sinternal_merge_in_global_face
, 2, 2, 0,
3745 doc
: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
3746 Default face attributes override any local face attributes. */)
3747 (Lisp_Object face
, Lisp_Object frame
)
3750 Lisp_Object global_lface
, local_lface
, *gvec
, *lvec
;
3751 struct frame
*f
= XFRAME (frame
);
3753 CHECK_LIVE_FRAME (frame
);
3754 global_lface
= lface_from_face_name (NULL
, face
, 1);
3755 local_lface
= lface_from_face_name (f
, face
, 0);
3756 if (NILP (local_lface
))
3757 local_lface
= Finternal_make_lisp_face (face
, frame
);
3759 /* Make every specified global attribute override the local one.
3760 BEWARE!! This is only used from `face-set-after-frame-default' where
3761 the local frame is defined from default specs in `face-defface-spec'
3762 and those should be overridden by global settings. Hence the strange
3763 "global before local" priority. */
3764 lvec
= XVECTOR (local_lface
)->contents
;
3765 gvec
= XVECTOR (global_lface
)->contents
;
3766 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3767 if (IGNORE_DEFFACE_P (gvec
[i
]))
3768 ASET (local_lface
, i
, Qunspecified
);
3769 else if (! UNSPECIFIEDP (gvec
[i
]))
3770 ASET (local_lface
, i
, AREF (global_lface
, i
));
3772 /* If the default face was changed, update the face cache and the
3773 `font' frame parameter. */
3774 if (EQ (face
, Qdefault
))
3776 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
3777 struct face
*newface
, *oldface
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
3778 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
3780 /* This can be NULL (e.g., in batch mode). */
3783 /* Ensure that the face vector is fully specified by merging
3784 the previously-cached vector. */
3785 memcpy (attrs
, oldface
->lface
, sizeof attrs
);
3786 merge_face_vectors (f
, lvec
, attrs
, 0);
3787 vcopy (local_lface
, 0, attrs
, LFACE_VECTOR_SIZE
);
3788 newface
= realize_face (c
, lvec
, DEFAULT_FACE_ID
);
3790 if ((! UNSPECIFIEDP (gvec
[LFACE_FAMILY_INDEX
])
3791 || ! UNSPECIFIEDP (gvec
[LFACE_FOUNDRY_INDEX
])
3792 || ! UNSPECIFIEDP (gvec
[LFACE_HEIGHT_INDEX
])
3793 || ! UNSPECIFIEDP (gvec
[LFACE_WEIGHT_INDEX
])
3794 || ! UNSPECIFIEDP (gvec
[LFACE_SLANT_INDEX
])
3795 || ! UNSPECIFIEDP (gvec
[LFACE_SWIDTH_INDEX
])
3796 || ! UNSPECIFIEDP (gvec
[LFACE_FONT_INDEX
]))
3799 Lisp_Object name
= newface
->font
->props
[FONT_NAME_INDEX
];
3800 Fmodify_frame_parameters (frame
, list1 (Fcons (Qfont
, name
)));
3803 if (STRINGP (gvec
[LFACE_FOREGROUND_INDEX
]))
3804 Fmodify_frame_parameters (frame
,
3805 list1 (Fcons (Qforeground_color
,
3806 gvec
[LFACE_FOREGROUND_INDEX
])));
3808 if (STRINGP (gvec
[LFACE_BACKGROUND_INDEX
]))
3809 Fmodify_frame_parameters (frame
,
3810 list1 (Fcons (Qbackground_color
,
3811 gvec
[LFACE_BACKGROUND_INDEX
])));
3819 /* The following function is implemented for compatibility with 20.2.
3820 The function is used in x-resolve-fonts when it is asked to
3821 return fonts with the same size as the font of a face. This is
3822 done in fontset.el. */
3824 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 3, 0,
3825 doc
: /* Return the font name of face FACE, or nil if it is unspecified.
3826 The font name is, by default, for ASCII characters.
3827 If the optional argument FRAME is given, report on face FACE in that frame.
3828 If FRAME is t, report on the defaults for face FACE (for new frames).
3829 The font default for a face is either nil, or a list
3830 of the form (bold), (italic) or (bold italic).
3831 If FRAME is omitted or nil, use the selected frame. And, in this case,
3832 if the optional third argument CHARACTER is given,
3833 return the font name used for CHARACTER. */)
3834 (Lisp_Object face
, Lisp_Object frame
, Lisp_Object character
)
3838 Lisp_Object result
= Qnil
;
3839 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
3841 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3842 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
3843 result
= Fcons (Qbold
, result
);
3845 if (!UNSPECIFIEDP (LFACE_SLANT (lface
))
3846 && !EQ (LFACE_SLANT (lface
), Qnormal
))
3847 result
= Fcons (Qitalic
, result
);
3853 struct frame
*f
= decode_live_frame (frame
);
3854 int face_id
= lookup_named_face (f
, face
, 1);
3855 struct face
*fface
= FACE_FROM_ID (f
, face_id
);
3859 #ifdef HAVE_WINDOW_SYSTEM
3860 if (FRAME_WINDOW_P (f
) && !NILP (character
))
3862 CHECK_CHARACTER (character
);
3863 face_id
= FACE_FOR_CHAR (f
, fface
, XINT (character
), -1, Qnil
);
3864 fface
= FACE_FROM_ID (f
, face_id
);
3867 ? fface
->font
->props
[FONT_NAME_INDEX
]
3869 #else /* !HAVE_WINDOW_SYSTEM */
3870 return build_string (FRAME_MSDOS_P (f
)
3872 : FRAME_W32_P (f
) ? "w32term"
3879 /* Compare face-attribute values v1 and v2 for equality. Value is non-zero if
3880 all attributes are `equal'. Tries to be fast because this function
3881 is called quite often. */
3884 face_attr_equal_p (Lisp_Object v1
, Lisp_Object v2
)
3886 return !NILP (Fequal (v1
, v2
));
3890 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
3891 all attributes are `equal'. Tries to be fast because this function
3892 is called quite often. */
3895 lface_equal_p (Lisp_Object
*v1
, Lisp_Object
*v2
)
3900 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
3901 equal_p
= face_attr_equal_p (v1
[i
], v2
[i
]);
3907 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
3908 Sinternal_lisp_face_equal_p
, 2, 3, 0,
3909 doc
: /* True if FACE1 and FACE2 are equal.
3910 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
3911 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
3912 If FRAME is omitted or nil, use the selected frame. */)
3913 (Lisp_Object face1
, Lisp_Object face2
, Lisp_Object frame
)
3917 Lisp_Object lface1
, lface2
;
3919 /* Don't use decode_window_system_frame here because this function
3920 is called before X frames exist. At that time, if FRAME is nil,
3921 selected_frame will be used which is the frame dumped with
3922 Emacs. That frame is not an X frame. */
3923 f
= EQ (frame
, Qt
) ? NULL
: decode_live_frame (frame
);
3925 lface1
= lface_from_face_name (f
, face1
, 1);
3926 lface2
= lface_from_face_name (f
, face2
, 1);
3927 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
3928 XVECTOR (lface2
)->contents
);
3929 return equal_p
? Qt
: Qnil
;
3933 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
3934 Sinternal_lisp_face_empty_p
, 1, 2, 0,
3935 doc
: /* True if FACE has no attribute specified.
3936 If the optional argument FRAME is given, report on face FACE in that frame.
3937 If FRAME is t, report on the defaults for face FACE (for new frames).
3938 If FRAME is omitted or nil, use the selected frame. */)
3939 (Lisp_Object face
, Lisp_Object frame
)
3941 struct frame
*f
= EQ (frame
, Qt
) ? NULL
: decode_live_frame (frame
);
3942 Lisp_Object lface
= lface_from_face_name (f
, face
, 1);
3945 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3946 if (!UNSPECIFIEDP (AREF (lface
, i
)))
3949 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
3953 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
3955 doc
: /* Return an alist of frame-local faces defined on FRAME.
3956 For internal use only. */)
3959 return decode_live_frame (frame
)->face_alist
;
3963 /* Return a hash code for Lisp string STRING with case ignored. Used
3964 below in computing a hash value for a Lisp face. */
3967 hash_string_case_insensitive (Lisp_Object string
)
3969 const unsigned char *s
;
3971 eassert (STRINGP (string
));
3972 for (s
= SDATA (string
); *s
; ++s
)
3973 hash
= (hash
<< 1) ^ c_tolower (*s
);
3978 /* Return a hash code for face attribute vector V. */
3981 lface_hash (Lisp_Object
*v
)
3983 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
3984 ^ hash_string_case_insensitive (v
[LFACE_FOUNDRY_INDEX
])
3985 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
3986 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
3987 ^ XHASH (v
[LFACE_WEIGHT_INDEX
])
3988 ^ XHASH (v
[LFACE_SLANT_INDEX
])
3989 ^ XHASH (v
[LFACE_SWIDTH_INDEX
])
3990 ^ XHASH (v
[LFACE_HEIGHT_INDEX
]));
3993 #ifdef HAVE_WINDOW_SYSTEM
3995 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
3996 considering charsets/registries). They do if they specify the same
3997 family, point size, weight, width, slant, and font. Both
3998 LFACE1 and LFACE2 must be fully-specified. */
4001 lface_same_font_attributes_p (Lisp_Object
*lface1
, Lisp_Object
*lface2
)
4003 eassert (lface_fully_specified_p (lface1
)
4004 && lface_fully_specified_p (lface2
));
4005 return (xstrcasecmp (SSDATA (lface1
[LFACE_FAMILY_INDEX
]),
4006 SSDATA (lface2
[LFACE_FAMILY_INDEX
])) == 0
4007 && xstrcasecmp (SSDATA (lface1
[LFACE_FOUNDRY_INDEX
]),
4008 SSDATA (lface2
[LFACE_FOUNDRY_INDEX
])) == 0
4009 && EQ (lface1
[LFACE_HEIGHT_INDEX
], lface2
[LFACE_HEIGHT_INDEX
])
4010 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
4011 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
4012 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
])
4013 && EQ (lface1
[LFACE_FONT_INDEX
], lface2
[LFACE_FONT_INDEX
])
4014 && (EQ (lface1
[LFACE_FONTSET_INDEX
], lface2
[LFACE_FONTSET_INDEX
])
4015 || (STRINGP (lface1
[LFACE_FONTSET_INDEX
])
4016 && STRINGP (lface2
[LFACE_FONTSET_INDEX
])
4017 && ! xstrcasecmp (SSDATA (lface1
[LFACE_FONTSET_INDEX
]),
4018 SSDATA (lface2
[LFACE_FONTSET_INDEX
]))))
4022 #endif /* HAVE_WINDOW_SYSTEM */
4024 /***********************************************************************
4026 ***********************************************************************/
4028 /* Allocate and return a new realized face for Lisp face attribute
4031 static struct face
*
4032 make_realized_face (Lisp_Object
*attr
)
4034 enum { off
= offsetof (struct face
, id
) };
4035 struct face
*face
= xmalloc (sizeof *face
);
4037 memcpy (face
->lface
, attr
, sizeof face
->lface
);
4038 memset (&face
->id
, 0, sizeof *face
- off
);
4039 face
->ascii_face
= face
;
4045 /* Free realized face FACE, including its X resources. FACE may
4049 free_realized_face (struct frame
*f
, struct face
*face
)
4053 #ifdef HAVE_WINDOW_SYSTEM
4054 if (FRAME_WINDOW_P (f
))
4056 /* Free fontset of FACE if it is ASCII face. */
4057 if (face
->fontset
>= 0 && face
== face
->ascii_face
)
4058 free_face_fontset (f
, face
);
4063 font_done_for_face (f
, face
);
4064 x_free_gc (f
, face
->gc
);
4068 #ifdef HAVE_X_WINDOWS
4069 free_face_colors (f
, face
);
4070 #endif /* HAVE_X_WINDOWS */
4071 x_destroy_bitmap (f
, face
->stipple
);
4073 #endif /* HAVE_WINDOW_SYSTEM */
4079 #ifdef HAVE_WINDOW_SYSTEM
4081 /* Prepare face FACE for subsequent display on frame F. This must be called
4082 before using X resources of FACE to allocate GCs if they haven't been
4083 allocated yet or have been freed by clearing the face cache. */
4086 prepare_face_for_display (struct frame
*f
, struct face
*face
)
4088 eassert (FRAME_WINDOW_P (f
));
4093 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
4095 xgcv
.foreground
= face
->foreground
;
4096 xgcv
.background
= face
->background
;
4097 #ifdef HAVE_X_WINDOWS
4098 xgcv
.graphics_exposures
= False
;
4102 #ifdef HAVE_X_WINDOWS
4105 xgcv
.fill_style
= FillOpaqueStippled
;
4106 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
4107 mask
|= GCFillStyle
| GCStipple
;
4110 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
4112 font_prepare_for_face (f
, face
);
4117 #endif /* HAVE_WINDOW_SYSTEM */
4119 /* Returns the `distance' between the colors X and Y. */
4122 color_distance (XColor
*x
, XColor
*y
)
4124 /* This formula is from a paper titled `Colour metric' by Thiadmer Riemersma.
4125 Quoting from that paper:
4127 This formula has results that are very close to L*u*v* (with the
4128 modified lightness curve) and, more importantly, it is a more even
4129 algorithm: it does not have a range of colors where it suddenly
4130 gives far from optimal results.
4132 See <http://www.compuphase.com/cmetric.htm> for more info. */
4134 long r
= (x
->red
- y
->red
) >> 8;
4135 long g
= (x
->green
- y
->green
) >> 8;
4136 long b
= (x
->blue
- y
->blue
) >> 8;
4137 long r_mean
= (x
->red
+ y
->red
) >> 9;
4140 (((512 + r_mean
) * r
* r
) >> 8)
4142 + (((767 - r_mean
) * b
* b
) >> 8);
4146 DEFUN ("color-distance", Fcolor_distance
, Scolor_distance
, 2, 3, 0,
4147 doc
: /* Return an integer distance between COLOR1 and COLOR2 on FRAME.
4148 COLOR1 and COLOR2 may be either strings containing the color name,
4149 or lists of the form (RED GREEN BLUE).
4150 If FRAME is unspecified or nil, the current frame is used. */)
4151 (Lisp_Object color1
, Lisp_Object color2
, Lisp_Object frame
)
4153 struct frame
*f
= decode_live_frame (frame
);
4154 XColor cdef1
, cdef2
;
4156 if (!(CONSP (color1
) && parse_rgb_list (color1
, &cdef1
))
4157 && !(STRINGP (color1
) && defined_color (f
, SSDATA (color1
), &cdef1
, 0)))
4158 signal_error ("Invalid color", color1
);
4159 if (!(CONSP (color2
) && parse_rgb_list (color2
, &cdef2
))
4160 && !(STRINGP (color2
) && defined_color (f
, SSDATA (color2
), &cdef2
, 0)))
4161 signal_error ("Invalid color", color2
);
4163 return make_number (color_distance (&cdef1
, &cdef2
));
4167 /***********************************************************************
4169 ***********************************************************************/
4171 /* Return a new face cache for frame F. */
4173 static struct face_cache
*
4174 make_face_cache (struct frame
*f
)
4176 struct face_cache
*c
= xmalloc (sizeof *c
);
4178 c
->buckets
= xzalloc (FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
);
4181 c
->faces_by_id
= xmalloc (c
->size
* sizeof *c
->faces_by_id
);
4183 c
->menu_face_changed_p
= menu_face_changed_default
;
4187 #ifdef HAVE_WINDOW_SYSTEM
4189 /* Clear out all graphics contexts for all realized faces, except for
4190 the basic faces. This should be done from time to time just to avoid
4191 keeping too many graphics contexts that are no longer needed. */
4194 clear_face_gcs (struct face_cache
*c
)
4196 if (c
&& FRAME_WINDOW_P (c
->f
))
4199 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
4201 struct face
*face
= c
->faces_by_id
[i
];
4202 if (face
&& face
->gc
)
4206 font_done_for_face (c
->f
, face
);
4207 x_free_gc (c
->f
, face
->gc
);
4215 #endif /* HAVE_WINDOW_SYSTEM */
4217 /* Free all realized faces in face cache C, including basic faces.
4218 C may be null. If faces are freed, make sure the frame's current
4219 matrix is marked invalid, so that a display caused by an expose
4220 event doesn't try to use faces we destroyed. */
4223 free_realized_faces (struct face_cache
*c
)
4228 struct frame
*f
= c
->f
;
4230 /* We must block input here because we can't process X events
4231 safely while only some faces are freed, or when the frame's
4232 current matrix still references freed faces. */
4235 for (i
= 0; i
< c
->used
; ++i
)
4237 free_realized_face (f
, c
->faces_by_id
[i
]);
4238 c
->faces_by_id
[i
] = NULL
;
4242 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4243 memset (c
->buckets
, 0, size
);
4245 /* Must do a thorough redisplay the next time. Mark current
4246 matrices as invalid because they will reference faces freed
4247 above. This function is also called when a frame is
4248 destroyed. In this case, the root window of F is nil. */
4249 if (WINDOWP (f
->root_window
))
4251 clear_current_matrices (f
);
4252 windows_or_buffers_changed
= 58;
4260 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
4261 This is done after attributes of a named face have been changed,
4262 because we can't tell which realized faces depend on that face. */
4265 free_all_realized_faces (Lisp_Object frame
)
4270 FOR_EACH_FRAME (rest
, frame
)
4271 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4274 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4278 /* Free face cache C and faces in it, including their X resources. */
4281 free_face_cache (struct face_cache
*c
)
4285 free_realized_faces (c
);
4287 xfree (c
->faces_by_id
);
4293 /* Cache realized face FACE in face cache C. HASH is the hash value
4294 of FACE. If FACE is for ASCII characters (i.e. FACE->ascii_face ==
4295 FACE), insert the new face to the beginning of the collision list
4296 of the face hash table of C. Otherwise, add the new face to the
4297 end of the collision list. This way, lookup_face can quickly find
4298 that a requested face is not cached. */
4301 cache_face (struct face_cache
*c
, struct face
*face
, unsigned int hash
)
4303 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4307 if (face
->ascii_face
!= face
)
4309 struct face
*last
= c
->buckets
[i
];
4320 c
->buckets
[i
] = face
;
4321 face
->prev
= face
->next
= NULL
;
4327 face
->next
= c
->buckets
[i
];
4329 face
->next
->prev
= face
;
4330 c
->buckets
[i
] = face
;
4333 /* Find a free slot in C->faces_by_id and use the index of the free
4334 slot as FACE->id. */
4335 for (i
= 0; i
< c
->used
; ++i
)
4336 if (c
->faces_by_id
[i
] == NULL
)
4341 /* Check that FACE got a unique id. */
4346 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
4347 for (face1
= c
->buckets
[j
]; face1
; face1
= face1
->next
)
4353 #endif /* GLYPH_DEBUG */
4355 /* Maybe enlarge C->faces_by_id. */
4358 if (c
->used
== c
->size
)
4359 c
->faces_by_id
= xpalloc (c
->faces_by_id
, &c
->size
, 1, MAX_FACE_ID
,
4360 sizeof *c
->faces_by_id
);
4364 c
->faces_by_id
[i
] = face
;
4368 /* Remove face FACE from cache C. */
4371 uncache_face (struct face_cache
*c
, struct face
*face
)
4373 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
4376 face
->prev
->next
= face
->next
;
4378 c
->buckets
[i
] = face
->next
;
4381 face
->next
->prev
= face
->prev
;
4383 c
->faces_by_id
[face
->id
] = NULL
;
4384 if (face
->id
== c
->used
)
4389 /* Look up a realized face with face attributes ATTR in the face cache
4390 of frame F. The face will be used to display ASCII characters.
4391 Value is the ID of the face found. If no suitable face is found,
4392 realize a new one. */
4395 lookup_face (struct frame
*f
, Lisp_Object
*attr
)
4397 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4402 eassert (cache
!= NULL
);
4403 check_lface_attrs (attr
);
4405 /* Look up ATTR in the face cache. */
4406 hash
= lface_hash (attr
);
4407 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4409 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4411 if (face
->ascii_face
!= face
)
4413 /* There's no more ASCII face. */
4417 if (face
->hash
== hash
4418 && lface_equal_p (face
->lface
, attr
))
4422 /* If not found, realize a new face. */
4424 face
= realize_face (cache
, attr
, -1);
4427 eassert (face
== FACE_FROM_ID (f
, face
->id
));
4428 #endif /* GLYPH_DEBUG */
4433 #ifdef HAVE_WINDOW_SYSTEM
4434 /* Look up a realized face that has the same attributes as BASE_FACE
4435 except for the font in the face cache of frame F. If FONT-OBJECT
4436 is not nil, it is an already opened font. If FONT-OBJECT is nil,
4437 the face has no font. Value is the ID of the face found. If no
4438 suitable face is found, realize a new one. */
4441 face_for_font (struct frame
*f
, Lisp_Object font_object
, struct face
*base_face
)
4443 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4448 eassert (cache
!= NULL
);
4449 base_face
= base_face
->ascii_face
;
4450 hash
= lface_hash (base_face
->lface
);
4451 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4453 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4455 if (face
->ascii_face
== face
)
4457 if (face
->ascii_face
== base_face
4458 && face
->font
== (NILP (font_object
) ? NULL
4459 : XFONT_OBJECT (font_object
))
4460 && lface_equal_p (face
->lface
, base_face
->lface
))
4464 /* If not found, realize a new face. */
4465 face
= realize_non_ascii_face (f
, font_object
, base_face
);
4468 #endif /* HAVE_WINDOW_SYSTEM */
4470 /* Return the face id of the realized face for named face SYMBOL on
4471 frame F suitable for displaying ASCII characters. Value is -1 if
4472 the face couldn't be determined, which might happen if the default
4473 face isn't realized and cannot be realized. */
4476 lookup_named_face (struct frame
*f
, Lisp_Object symbol
, int signal_p
)
4478 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4479 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4480 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4482 if (default_face
== NULL
)
4484 if (!realize_basic_faces (f
))
4486 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4487 if (default_face
== NULL
)
4488 emacs_abort (); /* realize_basic_faces must have set it up */
4491 if (! get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4494 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4495 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4497 return lookup_face (f
, attrs
);
4501 /* Return the display face-id of the basic face whose canonical face-id
4502 is FACE_ID. The return value will usually simply be FACE_ID, unless that
4503 basic face has bee remapped via Vface_remapping_alist. This function is
4504 conservative: if something goes wrong, it will simply return FACE_ID
4505 rather than signal an error. */
4508 lookup_basic_face (struct frame
*f
, int face_id
)
4510 Lisp_Object name
, mapping
;
4511 int remapped_face_id
;
4513 if (NILP (Vface_remapping_alist
))
4514 return face_id
; /* Nothing to do. */
4518 case DEFAULT_FACE_ID
: name
= Qdefault
; break;
4519 case MODE_LINE_FACE_ID
: name
= Qmode_line
; break;
4520 case MODE_LINE_INACTIVE_FACE_ID
: name
= Qmode_line_inactive
; break;
4521 case HEADER_LINE_FACE_ID
: name
= Qheader_line
; break;
4522 case TOOL_BAR_FACE_ID
: name
= Qtool_bar
; break;
4523 case FRINGE_FACE_ID
: name
= Qfringe
; break;
4524 case SCROLL_BAR_FACE_ID
: name
= Qscroll_bar
; break;
4525 case BORDER_FACE_ID
: name
= Qborder
; break;
4526 case CURSOR_FACE_ID
: name
= Qcursor
; break;
4527 case MOUSE_FACE_ID
: name
= Qmouse
; break;
4528 case MENU_FACE_ID
: name
= Qmenu
; break;
4531 emacs_abort (); /* the caller is supposed to pass us a basic face id */
4534 /* Do a quick scan through Vface_remapping_alist, and return immediately
4535 if there is no remapping for face NAME. This is just an optimization
4536 for the very common no-remapping case. */
4537 mapping
= assq_no_quit (name
, Vface_remapping_alist
);
4539 return face_id
; /* Give up. */
4541 /* If there is a remapping entry, lookup the face using NAME, which will
4542 handle the remapping too. */
4543 remapped_face_id
= lookup_named_face (f
, name
, 0);
4544 if (remapped_face_id
< 0)
4545 return face_id
; /* Give up. */
4547 return remapped_face_id
;
4551 /* Return a face for charset ASCII that is like the face with id
4552 FACE_ID on frame F, but has a font that is STEPS steps smaller.
4553 STEPS < 0 means larger. Value is the id of the face. */
4556 smaller_face (struct frame
*f
, int face_id
, int steps
)
4558 #ifdef HAVE_WINDOW_SYSTEM
4560 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4561 int pt
, last_pt
, last_height
;
4564 struct face
*new_face
;
4566 /* If not called for an X frame, just return the original face. */
4567 if (FRAME_TERMCAP_P (f
))
4570 /* Try in increments of 1/2 pt. */
4571 delta
= steps
< 0 ? 5 : -5;
4572 steps
= eabs (steps
);
4574 face
= FACE_FROM_ID (f
, face_id
);
4575 memcpy (attrs
, face
->lface
, sizeof attrs
);
4576 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
4577 new_face_id
= face_id
;
4578 last_height
= FONT_HEIGHT (face
->font
);
4582 /* Give up if we cannot find a font within 10pt. */
4583 && eabs (last_pt
- pt
) < 100)
4585 /* Look up a face for a slightly smaller/larger font. */
4587 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
4588 new_face_id
= lookup_face (f
, attrs
);
4589 new_face
= FACE_FROM_ID (f
, new_face_id
);
4591 /* If height changes, count that as one step. */
4592 if ((delta
< 0 && FONT_HEIGHT (new_face
->font
) < last_height
)
4593 || (delta
> 0 && FONT_HEIGHT (new_face
->font
) > last_height
))
4596 last_height
= FONT_HEIGHT (new_face
->font
);
4603 #else /* not HAVE_WINDOW_SYSTEM */
4607 #endif /* not HAVE_WINDOW_SYSTEM */
4611 /* Return a face for charset ASCII that is like the face with id
4612 FACE_ID on frame F, but has height HEIGHT. */
4615 face_with_height (struct frame
*f
, int face_id
, int height
)
4617 #ifdef HAVE_WINDOW_SYSTEM
4619 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4621 if (FRAME_TERMCAP_P (f
)
4625 face
= FACE_FROM_ID (f
, face_id
);
4626 memcpy (attrs
, face
->lface
, sizeof attrs
);
4627 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
4628 font_clear_prop (attrs
, FONT_SIZE_INDEX
);
4629 face_id
= lookup_face (f
, attrs
);
4630 #endif /* HAVE_WINDOW_SYSTEM */
4636 /* Return the face id of the realized face for named face SYMBOL on
4637 frame F suitable for displaying ASCII characters, and use
4638 attributes of the face FACE_ID for attributes that aren't
4639 completely specified by SYMBOL. This is like lookup_named_face,
4640 except that the default attributes come from FACE_ID, not from the
4641 default face. FACE_ID is assumed to be already realized. */
4644 lookup_derived_face (struct frame
*f
, Lisp_Object symbol
, int face_id
,
4647 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4648 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4649 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
4654 if (!get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4657 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4658 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4659 return lookup_face (f
, attrs
);
4662 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector
,
4663 Sface_attributes_as_vector
, 1, 1, 0,
4664 doc
: /* Return a vector of face attributes corresponding to PLIST. */)
4668 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
4670 merge_face_ref (XFRAME (selected_frame
), plist
, XVECTOR (lface
)->contents
,
4677 /***********************************************************************
4678 Face capability testing
4679 ***********************************************************************/
4682 /* If the distance (as returned by color_distance) between two colors is
4683 less than this, then they are considered the same, for determining
4684 whether a color is supported or not. The range of values is 0-65535. */
4686 #define TTY_SAME_COLOR_THRESHOLD 10000
4688 #ifdef HAVE_WINDOW_SYSTEM
4690 /* Return true if all the face attributes in ATTRS are supported
4691 on the window-system frame F.
4693 The definition of `supported' is somewhat heuristic, but basically means
4694 that a face containing all the attributes in ATTRS, when merged with the
4695 default face for display, can be represented in a way that's
4697 \(1) different in appearance than the default face, and
4698 \(2) `close in spirit' to what the attributes specify, if not exact. */
4701 x_supports_face_attributes_p (struct frame
*f
,
4702 Lisp_Object attrs
[LFACE_VECTOR_SIZE
],
4703 struct face
*def_face
)
4705 Lisp_Object
*def_attrs
= def_face
->lface
;
4707 /* Check that other specified attributes are different that the default
4709 if ((!UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
4710 && face_attr_equal_p (attrs
[LFACE_UNDERLINE_INDEX
],
4711 def_attrs
[LFACE_UNDERLINE_INDEX
]))
4712 || (!UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
4713 && face_attr_equal_p (attrs
[LFACE_INVERSE_INDEX
],
4714 def_attrs
[LFACE_INVERSE_INDEX
]))
4715 || (!UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
4716 && face_attr_equal_p (attrs
[LFACE_FOREGROUND_INDEX
],
4717 def_attrs
[LFACE_FOREGROUND_INDEX
]))
4718 || (!UNSPECIFIEDP (attrs
[LFACE_DISTANT_FOREGROUND_INDEX
])
4719 && face_attr_equal_p (attrs
[LFACE_DISTANT_FOREGROUND_INDEX
],
4720 def_attrs
[LFACE_DISTANT_FOREGROUND_INDEX
]))
4721 || (!UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
4722 && face_attr_equal_p (attrs
[LFACE_BACKGROUND_INDEX
],
4723 def_attrs
[LFACE_BACKGROUND_INDEX
]))
4724 || (!UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
4725 && face_attr_equal_p (attrs
[LFACE_STIPPLE_INDEX
],
4726 def_attrs
[LFACE_STIPPLE_INDEX
]))
4727 || (!UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
4728 && face_attr_equal_p (attrs
[LFACE_OVERLINE_INDEX
],
4729 def_attrs
[LFACE_OVERLINE_INDEX
]))
4730 || (!UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
4731 && face_attr_equal_p (attrs
[LFACE_STRIKE_THROUGH_INDEX
],
4732 def_attrs
[LFACE_STRIKE_THROUGH_INDEX
]))
4733 || (!UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
4734 && face_attr_equal_p (attrs
[LFACE_BOX_INDEX
],
4735 def_attrs
[LFACE_BOX_INDEX
])))
4738 /* Check font-related attributes, as those are the most commonly
4739 "unsupported" on a window-system (because of missing fonts). */
4740 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
4741 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
4742 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
4743 || !UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
4744 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
4745 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
]))
4749 Lisp_Object merged_attrs
[LFACE_VECTOR_SIZE
];
4752 memcpy (merged_attrs
, def_attrs
, sizeof merged_attrs
);
4754 merge_face_vectors (f
, attrs
, merged_attrs
, 0);
4756 face_id
= lookup_face (f
, merged_attrs
);
4757 face
= FACE_FROM_ID (f
, face_id
);
4760 error ("Cannot make face");
4762 /* If the font is the same, or no font is found, then not
4764 if (face
->font
== def_face
->font
4767 for (i
= FONT_TYPE_INDEX
; i
<= FONT_SIZE_INDEX
; i
++)
4768 if (! EQ (face
->font
->props
[i
], def_face
->font
->props
[i
]))
4772 if (i
< FONT_FOUNDRY_INDEX
|| i
> FONT_REGISTRY_INDEX
4773 || face
->font
->driver
->case_sensitive
)
4775 s1
= SYMBOL_NAME (face
->font
->props
[i
]);
4776 s2
= SYMBOL_NAME (def_face
->font
->props
[i
]);
4777 if (! EQ (Fcompare_strings (s1
, make_number (0), Qnil
,
4778 s2
, make_number (0), Qnil
, Qt
), Qt
))
4784 /* Everything checks out, this face is supported. */
4788 #endif /* HAVE_WINDOW_SYSTEM */
4790 /* Return true if all the face attributes in ATTRS are supported
4793 The definition of `supported' is somewhat heuristic, but basically means
4794 that a face containing all the attributes in ATTRS, when merged
4795 with the default face for display, can be represented in a way that's
4797 \(1) different in appearance than the default face, and
4798 \(2) `close in spirit' to what the attributes specify, if not exact.
4800 Point (2) implies that a `:weight black' attribute will be satisfied
4801 by any terminal that can display bold, and a `:foreground "yellow"' as
4802 long as the terminal can display a yellowish color, but `:slant italic'
4803 will _not_ be satisfied by the tty display code's automatic
4804 substitution of a `dim' face for italic. */
4807 tty_supports_face_attributes_p (struct frame
*f
,
4808 Lisp_Object attrs
[LFACE_VECTOR_SIZE
],
4809 struct face
*def_face
)
4812 Lisp_Object val
, fg
, bg
;
4813 XColor fg_tty_color
, fg_std_color
;
4814 XColor bg_tty_color
, bg_std_color
;
4815 unsigned test_caps
= 0;
4816 Lisp_Object
*def_attrs
= def_face
->lface
;
4818 /* First check some easy-to-check stuff; ttys support none of the
4819 following attributes, so we can just return false if any are requested
4820 (even if `nominal' values are specified, we should still return false,
4821 as that will be the same value that the default face uses). We
4822 consider :slant unsupportable on ttys, even though the face code
4823 actually `fakes' them using a dim attribute if possible. This is
4824 because the faked result is too different from what the face
4826 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
4827 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
4828 || !UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
4829 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
4830 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
4831 || !UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
4832 || !UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
4833 || !UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
]))
4836 /* Test for terminal `capabilities' (non-color character attributes). */
4838 /* font weight (bold/dim) */
4839 val
= attrs
[LFACE_WEIGHT_INDEX
];
4840 if (!UNSPECIFIEDP (val
)
4841 && (weight
= FONT_WEIGHT_NAME_NUMERIC (val
), weight
>= 0))
4843 int def_weight
= FONT_WEIGHT_NAME_NUMERIC (def_attrs
[LFACE_WEIGHT_INDEX
]);
4847 if (def_weight
> 100)
4848 return 0; /* same as default */
4849 test_caps
= TTY_CAP_BOLD
;
4851 else if (weight
< 100)
4853 if (def_weight
< 100)
4854 return 0; /* same as default */
4855 test_caps
= TTY_CAP_DIM
;
4857 else if (def_weight
== 100)
4858 return 0; /* same as default */
4862 val
= attrs
[LFACE_SLANT_INDEX
];
4863 if (!UNSPECIFIEDP (val
)
4864 && (slant
= FONT_SLANT_NAME_NUMERIC (val
), slant
>= 0))
4866 int def_slant
= FONT_SLANT_NAME_NUMERIC (def_attrs
[LFACE_SLANT_INDEX
]);
4867 if (slant
== 100 || slant
== def_slant
)
4868 return 0; /* same as default */
4870 test_caps
|= TTY_CAP_ITALIC
;
4874 val
= attrs
[LFACE_UNDERLINE_INDEX
];
4875 if (!UNSPECIFIEDP (val
))
4878 return 0; /* ttys can't use colored underlines */
4879 else if (EQ (CAR_SAFE (val
), QCstyle
) && EQ (CAR_SAFE (CDR_SAFE (val
)), Qwave
))
4880 return 0; /* ttys can't use wave underlines */
4881 else if (face_attr_equal_p (val
, def_attrs
[LFACE_UNDERLINE_INDEX
]))
4882 return 0; /* same as default */
4884 test_caps
|= TTY_CAP_UNDERLINE
;
4888 val
= attrs
[LFACE_INVERSE_INDEX
];
4889 if (!UNSPECIFIEDP (val
))
4891 if (face_attr_equal_p (val
, def_attrs
[LFACE_INVERSE_INDEX
]))
4892 return 0; /* same as default */
4894 test_caps
|= TTY_CAP_INVERSE
;
4898 /* Color testing. */
4900 /* Check if foreground color is close enough. */
4901 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
4904 Lisp_Object def_fg
= def_attrs
[LFACE_FOREGROUND_INDEX
];
4906 if (face_attr_equal_p (fg
, def_fg
))
4907 return 0; /* same as default */
4908 else if (! tty_lookup_color (f
, fg
, &fg_tty_color
, &fg_std_color
))
4909 return 0; /* not a valid color */
4910 else if (color_distance (&fg_tty_color
, &fg_std_color
)
4911 > TTY_SAME_COLOR_THRESHOLD
)
4912 return 0; /* displayed color is too different */
4914 /* Make sure the color is really different than the default. */
4916 XColor def_fg_color
;
4917 if (tty_lookup_color (f
, def_fg
, &def_fg_color
, 0)
4918 && (color_distance (&fg_tty_color
, &def_fg_color
)
4919 <= TTY_SAME_COLOR_THRESHOLD
))
4924 /* Check if background color is close enough. */
4925 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
4928 Lisp_Object def_bg
= def_attrs
[LFACE_BACKGROUND_INDEX
];
4930 if (face_attr_equal_p (bg
, def_bg
))
4931 return 0; /* same as default */
4932 else if (! tty_lookup_color (f
, bg
, &bg_tty_color
, &bg_std_color
))
4933 return 0; /* not a valid color */
4934 else if (color_distance (&bg_tty_color
, &bg_std_color
)
4935 > TTY_SAME_COLOR_THRESHOLD
)
4936 return 0; /* displayed color is too different */
4938 /* Make sure the color is really different than the default. */
4940 XColor def_bg_color
;
4941 if (tty_lookup_color (f
, def_bg
, &def_bg_color
, 0)
4942 && (color_distance (&bg_tty_color
, &def_bg_color
)
4943 <= TTY_SAME_COLOR_THRESHOLD
))
4948 /* If both foreground and background are requested, see if the
4949 distance between them is OK. We just check to see if the distance
4950 between the tty's foreground and background is close enough to the
4951 distance between the standard foreground and background. */
4952 if (STRINGP (fg
) && STRINGP (bg
))
4955 = (color_distance (&fg_std_color
, &bg_std_color
)
4956 - color_distance (&fg_tty_color
, &bg_tty_color
));
4957 if (delta_delta
> TTY_SAME_COLOR_THRESHOLD
4958 || delta_delta
< -TTY_SAME_COLOR_THRESHOLD
)
4963 /* See if the capabilities we selected above are supported, with the
4965 return tty_capable_p (FRAME_TTY (f
), test_caps
);
4969 DEFUN ("display-supports-face-attributes-p",
4970 Fdisplay_supports_face_attributes_p
, Sdisplay_supports_face_attributes_p
,
4972 doc
: /* Return non-nil if all the face attributes in ATTRIBUTES are supported.
4973 The optional argument DISPLAY can be a display name, a frame, or
4974 nil (meaning the selected frame's display).
4976 The definition of `supported' is somewhat heuristic, but basically means
4977 that a face containing all the attributes in ATTRIBUTES, when merged
4978 with the default face for display, can be represented in a way that's
4980 \(1) different in appearance than the default face, and
4981 \(2) `close in spirit' to what the attributes specify, if not exact.
4983 Point (2) implies that a `:weight black' attribute will be satisfied by
4984 any display that can display bold, and a `:foreground \"yellow\"' as long
4985 as it can display a yellowish color, but `:slant italic' will _not_ be
4986 satisfied by the tty display code's automatic substitution of a `dim'
4987 face for italic. */)
4988 (Lisp_Object attributes
, Lisp_Object display
)
4994 struct face
*def_face
;
4995 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4997 if (noninteractive
|| !initialized
)
4998 /* We may not be able to access low-level face information in batch
4999 mode, or before being dumped, and this function is not going to
5000 be very useful in those cases anyway, so just give up. */
5004 frame
= selected_frame
;
5005 else if (FRAMEP (display
))
5009 /* Find any frame on DISPLAY. */
5013 FOR_EACH_FRAME (tail
, frame
)
5014 if (!NILP (Fequal (Fcdr (Fassq (Qdisplay
,
5015 XFRAME (frame
)->param_alist
)),
5020 CHECK_LIVE_FRAME (frame
);
5023 for (i
= 0; i
< LFACE_VECTOR_SIZE
; i
++)
5024 attrs
[i
] = Qunspecified
;
5025 merge_face_ref (f
, attributes
, attrs
, 1, 0);
5027 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5028 if (def_face
== NULL
)
5030 if (! realize_basic_faces (f
))
5031 error ("Cannot realize default face");
5032 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5033 if (def_face
== NULL
)
5034 emacs_abort (); /* realize_basic_faces must have set it up */
5037 /* Dispatch to the appropriate handler. */
5038 if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5039 supports
= tty_supports_face_attributes_p (f
, attrs
, def_face
);
5040 #ifdef HAVE_WINDOW_SYSTEM
5042 supports
= x_supports_face_attributes_p (f
, attrs
, def_face
);
5045 return supports
? Qt
: Qnil
;
5049 /***********************************************************************
5051 ***********************************************************************/
5053 DEFUN ("internal-set-font-selection-order",
5054 Finternal_set_font_selection_order
,
5055 Sinternal_set_font_selection_order
, 1, 1, 0,
5056 doc
: /* Set font selection order for face font selection to ORDER.
5057 ORDER must be a list of length 4 containing the symbols `:width',
5058 `:height', `:weight', and `:slant'. Face attributes appearing
5059 first in ORDER are matched first, e.g. if `:height' appears before
5060 `:weight' in ORDER, font selection first tries to find a font with
5061 a suitable height, and then tries to match the font weight.
5067 int indices
[ARRAYELTS (font_sort_order
)];
5070 memset (indices
, 0, sizeof indices
);
5074 CONSP (list
) && i
< ARRAYELTS (indices
);
5075 list
= XCDR (list
), ++i
)
5077 Lisp_Object attr
= XCAR (list
);
5080 if (EQ (attr
, QCwidth
))
5082 else if (EQ (attr
, QCheight
))
5083 xlfd
= XLFD_POINT_SIZE
;
5084 else if (EQ (attr
, QCweight
))
5086 else if (EQ (attr
, QCslant
))
5091 if (indices
[i
] != 0)
5096 if (!NILP (list
) || i
!= ARRAYELTS (indices
))
5097 signal_error ("Invalid font sort order", order
);
5098 for (i
= 0; i
< ARRAYELTS (font_sort_order
); ++i
)
5099 if (indices
[i
] == 0)
5100 signal_error ("Invalid font sort order", order
);
5102 if (memcmp (indices
, font_sort_order
, sizeof indices
) != 0)
5104 memcpy (font_sort_order
, indices
, sizeof font_sort_order
);
5105 free_all_realized_faces (Qnil
);
5108 font_update_sort_order (font_sort_order
);
5114 DEFUN ("internal-set-alternative-font-family-alist",
5115 Finternal_set_alternative_font_family_alist
,
5116 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
5117 doc
: /* Define alternative font families to try in face font selection.
5118 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5119 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
5120 be found. Value is ALIST. */)
5123 Lisp_Object entry
, tail
, tail2
;
5126 alist
= Fcopy_sequence (alist
);
5127 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5129 entry
= XCAR (tail
);
5131 entry
= Fcopy_sequence (entry
);
5132 XSETCAR (tail
, entry
);
5133 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5134 XSETCAR (tail2
, Fintern (XCAR (tail2
), Qnil
));
5137 Vface_alternative_font_family_alist
= alist
;
5138 free_all_realized_faces (Qnil
);
5143 DEFUN ("internal-set-alternative-font-registry-alist",
5144 Finternal_set_alternative_font_registry_alist
,
5145 Sinternal_set_alternative_font_registry_alist
, 1, 1, 0,
5146 doc
: /* Define alternative font registries to try in face font selection.
5147 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5148 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
5149 be found. Value is ALIST. */)
5152 Lisp_Object entry
, tail
, tail2
;
5155 alist
= Fcopy_sequence (alist
);
5156 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5158 entry
= XCAR (tail
);
5160 entry
= Fcopy_sequence (entry
);
5161 XSETCAR (tail
, entry
);
5162 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5163 XSETCAR (tail2
, Fdowncase (XCAR (tail2
)));
5165 Vface_alternative_font_registry_alist
= alist
;
5166 free_all_realized_faces (Qnil
);
5171 #ifdef HAVE_WINDOW_SYSTEM
5173 /* Return the fontset id of the base fontset name or alias name given
5174 by the fontset attribute of ATTRS. Value is -1 if the fontset
5175 attribute of ATTRS doesn't name a fontset. */
5178 face_fontset (Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
5182 name
= attrs
[LFACE_FONTSET_INDEX
];
5183 if (!STRINGP (name
))
5185 return fs_query_fontset (name
, 0);
5188 #endif /* HAVE_WINDOW_SYSTEM */
5192 /***********************************************************************
5194 ***********************************************************************/
5196 /* Realize basic faces on frame F. Value is zero if frame parameters
5197 of F don't contain enough information needed to realize the default
5201 realize_basic_faces (struct frame
*f
)
5206 /* Block input here so that we won't be surprised by an X expose
5207 event, for instance, without having the faces set up. */
5209 specbind (Qscalable_fonts_allowed
, Qt
);
5211 if (realize_default_face (f
))
5213 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
5214 realize_named_face (f
, Qmode_line_inactive
, MODE_LINE_INACTIVE_FACE_ID
);
5215 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
5216 realize_named_face (f
, Qfringe
, FRINGE_FACE_ID
);
5217 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
5218 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
5219 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
5220 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
5221 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
5222 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
5223 realize_named_face (f
, Qvertical_border
, VERTICAL_BORDER_FACE_ID
);
5224 realize_named_face (f
, Qwindow_divider
, WINDOW_DIVIDER_FACE_ID
);
5225 realize_named_face (f
, Qwindow_divider_first_pixel
,
5226 WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID
);
5227 realize_named_face (f
, Qwindow_divider_last_pixel
,
5228 WINDOW_DIVIDER_LAST_PIXEL_FACE_ID
);
5230 /* Reflect changes in the `menu' face in menu bars. */
5231 if (FRAME_FACE_CACHE (f
)->menu_face_changed_p
)
5233 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 0;
5234 #ifdef USE_X_TOOLKIT
5235 if (FRAME_WINDOW_P (f
))
5236 x_update_menu_appearance (f
);
5249 /* Realize the default face on frame F. If the face is not fully
5250 specified, make it fully-specified. Attributes of the default face
5251 that are not explicitly specified are taken from frame parameters. */
5254 realize_default_face (struct frame
*f
)
5256 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5258 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5261 /* If the `default' face is not yet known, create it. */
5262 lface
= lface_from_face_name (f
, Qdefault
, 0);
5266 XSETFRAME (frame
, f
);
5267 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
5270 #ifdef HAVE_WINDOW_SYSTEM
5271 if (FRAME_WINDOW_P (f
))
5273 Lisp_Object font_object
;
5275 XSETFONT (font_object
, FRAME_FONT (f
));
5276 set_lface_from_font (f
, lface
, font_object
, f
->default_face_done_p
);
5277 ASET (lface
, LFACE_FONTSET_INDEX
, fontset_name (FRAME_FONTSET (f
)));
5278 f
->default_face_done_p
= 1;
5280 #endif /* HAVE_WINDOW_SYSTEM */
5282 if (!FRAME_WINDOW_P (f
))
5284 ASET (lface
, LFACE_FAMILY_INDEX
, build_string ("default"));
5285 ASET (lface
, LFACE_FOUNDRY_INDEX
, LFACE_FAMILY (lface
));
5286 ASET (lface
, LFACE_SWIDTH_INDEX
, Qnormal
);
5287 ASET (lface
, LFACE_HEIGHT_INDEX
, make_number (1));
5288 if (UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
5289 ASET (lface
, LFACE_WEIGHT_INDEX
, Qnormal
);
5290 if (UNSPECIFIEDP (LFACE_SLANT (lface
)))
5291 ASET (lface
, LFACE_SLANT_INDEX
, Qnormal
);
5292 if (UNSPECIFIEDP (LFACE_FONTSET (lface
)))
5293 ASET (lface
, LFACE_FONTSET_INDEX
, Qnil
);
5296 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
5297 ASET (lface
, LFACE_UNDERLINE_INDEX
, Qnil
);
5299 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
5300 ASET (lface
, LFACE_OVERLINE_INDEX
, Qnil
);
5302 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
5303 ASET (lface
, LFACE_STRIKE_THROUGH_INDEX
, Qnil
);
5305 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
5306 ASET (lface
, LFACE_BOX_INDEX
, Qnil
);
5308 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
5309 ASET (lface
, LFACE_INVERSE_INDEX
, Qnil
);
5311 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
5313 /* This function is called so early that colors are not yet
5314 set in the frame parameter list. */
5315 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
5317 if (CONSP (color
) && STRINGP (XCDR (color
)))
5318 ASET (lface
, LFACE_FOREGROUND_INDEX
, XCDR (color
));
5319 else if (FRAME_WINDOW_P (f
))
5321 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5322 ASET (lface
, LFACE_FOREGROUND_INDEX
, build_string (unspecified_fg
));
5327 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
5329 /* This function is called so early that colors are not yet
5330 set in the frame parameter list. */
5331 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
5332 if (CONSP (color
) && STRINGP (XCDR (color
)))
5333 ASET (lface
, LFACE_BACKGROUND_INDEX
, XCDR (color
));
5334 else if (FRAME_WINDOW_P (f
))
5336 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5337 ASET (lface
, LFACE_BACKGROUND_INDEX
, build_string (unspecified_bg
));
5342 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
5343 ASET (lface
, LFACE_STIPPLE_INDEX
, Qnil
);
5345 /* Realize the face; it must be fully-specified now. */
5346 eassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
5347 check_lface (lface
);
5348 memcpy (attrs
, XVECTOR (lface
)->contents
, sizeof attrs
);
5349 face
= realize_face (c
, attrs
, DEFAULT_FACE_ID
);
5351 #ifdef HAVE_WINDOW_SYSTEM
5352 #ifdef HAVE_X_WINDOWS
5353 if (FRAME_X_P (f
) && face
->font
!= FRAME_FONT (f
))
5355 /* This can happen when making a frame on a display that does
5356 not support the default font. */
5360 /* Otherwise, the font specified for the frame was not
5361 acceptable as a font for the default face (perhaps because
5362 auto-scaled fonts are rejected), so we must adjust the frame
5364 x_set_font (f
, LFACE_FONT (lface
), Qnil
);
5366 #endif /* HAVE_X_WINDOWS */
5367 #endif /* HAVE_WINDOW_SYSTEM */
5372 /* Realize basic faces other than the default face in face cache C.
5373 SYMBOL is the face name, ID is the face id the realized face must
5374 have. The default face must have been realized already. */
5377 realize_named_face (struct frame
*f
, Lisp_Object symbol
, int id
)
5379 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5380 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
5381 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5382 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5384 /* The default face must exist and be fully specified. */
5385 get_lface_attributes_no_remap (f
, Qdefault
, attrs
, 1);
5386 check_lface_attrs (attrs
);
5387 eassert (lface_fully_specified_p (attrs
));
5389 /* If SYMBOL isn't know as a face, create it. */
5393 XSETFRAME (frame
, f
);
5394 lface
= Finternal_make_lisp_face (symbol
, frame
);
5397 /* Merge SYMBOL's face with the default face. */
5398 get_lface_attributes_no_remap (f
, symbol
, symbol_attrs
, 1);
5399 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
5401 /* Realize the face. */
5402 realize_face (c
, attrs
, id
);
5406 /* Realize the fully-specified face with attributes ATTRS in face
5407 cache CACHE for ASCII characters. If FORMER_FACE_ID is
5408 non-negative, it is an ID of face to remove before caching the new
5409 face. Value is a pointer to the newly created realized face. */
5411 static struct face
*
5412 realize_face (struct face_cache
*cache
, Lisp_Object attrs
[LFACE_VECTOR_SIZE
],
5417 /* LFACE must be fully specified. */
5418 eassert (cache
!= NULL
);
5419 check_lface_attrs (attrs
);
5421 if (former_face_id
>= 0 && cache
->used
> former_face_id
)
5423 /* Remove the former face. */
5424 struct face
*former_face
= cache
->faces_by_id
[former_face_id
];
5425 uncache_face (cache
, former_face
);
5426 free_realized_face (cache
->f
, former_face
);
5427 SET_FRAME_GARBAGED (cache
->f
);
5430 if (FRAME_WINDOW_P (cache
->f
))
5431 face
= realize_x_face (cache
, attrs
);
5432 else if (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
))
5433 face
= realize_tty_face (cache
, attrs
);
5434 else if (FRAME_INITIAL_P (cache
->f
))
5436 /* Create a dummy face. */
5437 face
= make_realized_face (attrs
);
5442 /* Insert the new face. */
5443 cache_face (cache
, face
, lface_hash (attrs
));
5448 #ifdef HAVE_WINDOW_SYSTEM
5449 /* Realize the fully-specified face that uses FONT-OBJECT and has the
5450 same attributes as BASE_FACE except for the font on frame F.
5451 FONT-OBJECT may be nil, in which case, realized a face of
5454 static struct face
*
5455 realize_non_ascii_face (struct frame
*f
, Lisp_Object font_object
,
5456 struct face
*base_face
)
5458 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5461 face
= xmalloc (sizeof *face
);
5465 = (! NILP (font_object
)
5466 && FONT_WEIGHT_NAME_NUMERIC (face
->lface
[LFACE_WEIGHT_INDEX
]) > 100
5467 && FONT_WEIGHT_NUMERIC (font_object
) <= 100);
5469 /* Don't try to free the colors copied bitwise from BASE_FACE. */
5470 face
->colors_copied_bitwise_p
= 1;
5471 face
->font
= NILP (font_object
) ? NULL
: XFONT_OBJECT (font_object
);
5474 cache_face (cache
, face
, face
->hash
);
5478 #endif /* HAVE_WINDOW_SYSTEM */
5481 /* Realize the fully-specified face with attributes ATTRS in face
5482 cache CACHE for ASCII characters. Do it for X frame CACHE->f. If
5483 the new face doesn't share font with the default face, a fontname
5484 is allocated from the heap and set in `font_name' of the new face,
5485 but it is not yet loaded here. Value is a pointer to the newly
5486 created realized face. */
5488 static struct face
*
5489 realize_x_face (struct face_cache
*cache
, Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
5491 struct face
*face
= NULL
;
5492 #ifdef HAVE_WINDOW_SYSTEM
5493 struct face
*default_face
;
5495 Lisp_Object stipple
, underline
, overline
, strike_through
, box
;
5497 eassert (FRAME_WINDOW_P (cache
->f
));
5499 /* Allocate a new realized face. */
5500 face
= make_realized_face (attrs
);
5501 face
->ascii_face
= face
;
5505 /* Determine the font to use. Most of the time, the font will be
5506 the same as the font of the default face, so try that first. */
5507 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5509 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
5511 face
->font
= default_face
->font
;
5513 = make_fontset_for_ascii_face (f
, default_face
->fontset
, face
);
5517 /* If the face attribute ATTRS specifies a fontset, use it as
5518 the base of a new realized fontset. Otherwise, use the same
5519 base fontset as of the default face. The base determines
5520 registry and encoding of a font. It may also determine
5521 foundry and family. The other fields of font name pattern
5522 are constructed from ATTRS. */
5523 int fontset
= face_fontset (attrs
);
5525 /* If we are realizing the default face, ATTRS should specify a
5526 fontset. In other words, if FONTSET is -1, we are not
5527 realizing the default face, thus the default face should have
5528 already been realized. */
5532 fontset
= default_face
->fontset
;
5536 if (! FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5537 attrs
[LFACE_FONT_INDEX
]
5538 = font_load_for_lface (f
, attrs
, attrs
[LFACE_FONT_INDEX
]);
5539 if (FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5541 face
->font
= XFONT_OBJECT (attrs
[LFACE_FONT_INDEX
]);
5542 face
->fontset
= make_fontset_for_ascii_face (f
, fontset
, face
);
5552 && FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]) > 100
5553 && FONT_WEIGHT_NUMERIC (attrs
[LFACE_FONT_INDEX
]) <= 100)
5554 face
->overstrike
= 1;
5556 /* Load colors, and set remaining attributes. */
5558 load_face_colors (f
, face
, attrs
);
5561 box
= attrs
[LFACE_BOX_INDEX
];
5564 /* A simple box of line width 1 drawn in color given by
5566 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
5568 face
->box
= FACE_SIMPLE_BOX
;
5569 face
->box_line_width
= 1;
5571 else if (INTEGERP (box
))
5573 /* Simple box of specified line width in foreground color of the
5575 eassert (XINT (box
) != 0);
5576 face
->box
= FACE_SIMPLE_BOX
;
5577 face
->box_line_width
= XINT (box
);
5578 face
->box_color
= face
->foreground
;
5579 face
->box_color_defaulted_p
= 1;
5581 else if (CONSP (box
))
5583 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
5584 being one of `raised' or `sunken'. */
5585 face
->box
= FACE_SIMPLE_BOX
;
5586 face
->box_color
= face
->foreground
;
5587 face
->box_color_defaulted_p
= 1;
5588 face
->box_line_width
= 1;
5592 Lisp_Object keyword
, value
;
5594 keyword
= XCAR (box
);
5602 if (EQ (keyword
, QCline_width
))
5604 if (INTEGERP (value
) && XINT (value
) != 0)
5605 face
->box_line_width
= XINT (value
);
5607 else if (EQ (keyword
, QCcolor
))
5609 if (STRINGP (value
))
5611 face
->box_color
= load_color (f
, face
, value
,
5613 face
->use_box_color_for_shadows_p
= 1;
5616 else if (EQ (keyword
, QCstyle
))
5618 if (EQ (value
, Qreleased_button
))
5619 face
->box
= FACE_RAISED_BOX
;
5620 else if (EQ (value
, Qpressed_button
))
5621 face
->box
= FACE_SUNKEN_BOX
;
5626 /* Text underline, overline, strike-through. */
5628 underline
= attrs
[LFACE_UNDERLINE_INDEX
];
5629 if (EQ (underline
, Qt
))
5631 /* Use default color (same as foreground color). */
5632 face
->underline_p
= 1;
5633 face
->underline_type
= FACE_UNDER_LINE
;
5634 face
->underline_defaulted_p
= 1;
5635 face
->underline_color
= 0;
5637 else if (STRINGP (underline
))
5639 /* Use specified color. */
5640 face
->underline_p
= 1;
5641 face
->underline_type
= FACE_UNDER_LINE
;
5642 face
->underline_defaulted_p
= 0;
5643 face
->underline_color
5644 = load_color (f
, face
, underline
,
5645 LFACE_UNDERLINE_INDEX
);
5647 else if (NILP (underline
))
5649 face
->underline_p
= 0;
5650 face
->underline_defaulted_p
= 0;
5651 face
->underline_color
= 0;
5653 else if (CONSP (underline
))
5655 /* `(:color COLOR :style STYLE)'.
5656 STYLE being one of `line' or `wave'. */
5657 face
->underline_p
= 1;
5658 face
->underline_color
= 0;
5659 face
->underline_defaulted_p
= 1;
5660 face
->underline_type
= FACE_UNDER_LINE
;
5662 /* FIXME? This is also not robust about checking the precise form.
5663 See comments in Finternal_set_lisp_face_attribute. */
5664 while (CONSP (underline
))
5666 Lisp_Object keyword
, value
;
5668 keyword
= XCAR (underline
);
5669 underline
= XCDR (underline
);
5671 if (!CONSP (underline
))
5673 value
= XCAR (underline
);
5674 underline
= XCDR (underline
);
5676 if (EQ (keyword
, QCcolor
))
5678 if (EQ (value
, Qforeground_color
))
5680 face
->underline_defaulted_p
= 1;
5681 face
->underline_color
= 0;
5683 else if (STRINGP (value
))
5685 face
->underline_defaulted_p
= 0;
5686 face
->underline_color
= load_color (f
, face
, value
,
5687 LFACE_UNDERLINE_INDEX
);
5690 else if (EQ (keyword
, QCstyle
))
5692 if (EQ (value
, Qline
))
5693 face
->underline_type
= FACE_UNDER_LINE
;
5694 else if (EQ (value
, Qwave
))
5695 face
->underline_type
= FACE_UNDER_WAVE
;
5700 overline
= attrs
[LFACE_OVERLINE_INDEX
];
5701 if (STRINGP (overline
))
5703 face
->overline_color
5704 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
5705 LFACE_OVERLINE_INDEX
);
5706 face
->overline_p
= 1;
5708 else if (EQ (overline
, Qt
))
5710 face
->overline_color
= face
->foreground
;
5711 face
->overline_color_defaulted_p
= 1;
5712 face
->overline_p
= 1;
5715 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
5716 if (STRINGP (strike_through
))
5718 face
->strike_through_color
5719 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
5720 LFACE_STRIKE_THROUGH_INDEX
);
5721 face
->strike_through_p
= 1;
5723 else if (EQ (strike_through
, Qt
))
5725 face
->strike_through_color
= face
->foreground
;
5726 face
->strike_through_color_defaulted_p
= 1;
5727 face
->strike_through_p
= 1;
5730 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
5731 if (!NILP (stipple
))
5732 face
->stipple
= load_pixmap (f
, stipple
);
5733 #endif /* HAVE_WINDOW_SYSTEM */
5739 /* Map a specified color of face FACE on frame F to a tty color index.
5740 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
5741 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
5742 default foreground/background colors. */
5745 map_tty_color (struct frame
*f
, struct face
*face
,
5746 enum lface_attribute_index idx
, int *defaulted
)
5748 Lisp_Object frame
, color
, def
;
5749 int foreground_p
= idx
== LFACE_FOREGROUND_INDEX
;
5750 unsigned long default_pixel
=
5751 foreground_p
? FACE_TTY_DEFAULT_FG_COLOR
: FACE_TTY_DEFAULT_BG_COLOR
;
5752 unsigned long pixel
= default_pixel
;
5754 unsigned long default_other_pixel
=
5755 foreground_p
? FACE_TTY_DEFAULT_BG_COLOR
: FACE_TTY_DEFAULT_FG_COLOR
;
5758 eassert (idx
== LFACE_FOREGROUND_INDEX
|| idx
== LFACE_BACKGROUND_INDEX
);
5760 XSETFRAME (frame
, f
);
5761 color
= face
->lface
[idx
];
5765 && CONSP (Vtty_defined_color_alist
)
5766 && (def
= assq_no_quit (color
, call1 (Qtty_color_alist
, frame
)),
5769 /* Associations in tty-defined-color-alist are of the form
5770 (NAME INDEX R G B). We need the INDEX part. */
5771 pixel
= XINT (XCAR (XCDR (def
)));
5774 if (pixel
== default_pixel
&& STRINGP (color
))
5776 pixel
= load_color (f
, face
, color
, idx
);
5779 /* If the foreground of the default face is the default color,
5780 use the foreground color defined by the frame. */
5781 if (FRAME_MSDOS_P (f
))
5783 if (pixel
== default_pixel
5784 || pixel
== FACE_TTY_DEFAULT_COLOR
)
5787 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5789 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5790 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5793 else if (pixel
== default_other_pixel
)
5796 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5798 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5799 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5807 face
->foreground
= pixel
;
5809 face
->background
= pixel
;
5813 /* Realize the fully-specified face with attributes ATTRS in face
5814 cache CACHE for ASCII characters. Do it for TTY frame CACHE->f.
5815 Value is a pointer to the newly created realized face. */
5817 static struct face
*
5818 realize_tty_face (struct face_cache
*cache
,
5819 Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
5823 int face_colors_defaulted
= 0;
5824 struct frame
*f
= cache
->f
;
5826 /* Frame must be a termcap frame. */
5827 eassert (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
));
5829 /* Allocate a new realized face. */
5830 face
= make_realized_face (attrs
);
5832 face
->font_name
= FRAME_MSDOS_P (cache
->f
) ? "ms-dos" : "tty";
5835 /* Map face attributes to TTY appearances. */
5836 weight
= FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]);
5837 slant
= FONT_SLANT_NAME_NUMERIC (attrs
[LFACE_SLANT_INDEX
]);
5839 face
->tty_bold_p
= 1;
5841 face
->tty_italic_p
= 1;
5842 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5843 face
->tty_underline_p
= 1;
5844 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
5845 face
->tty_reverse_p
= 1;
5847 /* Map color names to color indices. */
5848 map_tty_color (f
, face
, LFACE_FOREGROUND_INDEX
, &face_colors_defaulted
);
5849 map_tty_color (f
, face
, LFACE_BACKGROUND_INDEX
, &face_colors_defaulted
);
5851 /* Swap colors if face is inverse-video. If the colors are taken
5852 from the frame colors, they are already inverted, since the
5853 frame-creation function calls x-handle-reverse-video. */
5854 if (face
->tty_reverse_p
&& !face_colors_defaulted
)
5856 unsigned long tem
= face
->foreground
;
5857 face
->foreground
= face
->background
;
5858 face
->background
= tem
;
5861 if (tty_suppress_bold_inverse_default_colors_p
5863 && face
->background
== FACE_TTY_DEFAULT_FG_COLOR
5864 && face
->foreground
== FACE_TTY_DEFAULT_BG_COLOR
)
5865 face
->tty_bold_p
= 0;
5871 DEFUN ("tty-suppress-bold-inverse-default-colors",
5872 Ftty_suppress_bold_inverse_default_colors
,
5873 Stty_suppress_bold_inverse_default_colors
, 1, 1, 0,
5874 doc
: /* Suppress/allow boldness of faces with inverse default colors.
5875 SUPPRESS non-nil means suppress it.
5876 This affects bold faces on TTYs whose foreground is the default background
5877 color of the display and whose background is the default foreground color.
5878 For such faces, the bold face attribute is ignored if this variable
5880 (Lisp_Object suppress
)
5882 tty_suppress_bold_inverse_default_colors_p
= !NILP (suppress
);
5883 ++face_change_count
;
5889 /***********************************************************************
5891 ***********************************************************************/
5893 /* Return the ID of the face to use to display character CH with face
5894 property PROP on frame F in current_buffer. */
5897 compute_char_face (struct frame
*f
, int ch
, Lisp_Object prop
)
5901 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
5906 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5907 face_id
= FACE_FOR_CHAR (f
, face
, ch
, -1, Qnil
);
5911 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5912 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5913 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
5914 merge_face_ref (f
, prop
, attrs
, 1, 0);
5915 face_id
= lookup_face (f
, attrs
);
5921 /* Return the face ID associated with buffer position POS for
5922 displaying ASCII characters. Return in *ENDPTR the position at
5923 which a different face is needed, as far as text properties and
5924 overlays are concerned. W is a window displaying current_buffer.
5926 REGION_BEG, REGION_END delimit the region, so it can be
5929 LIMIT is a position not to scan beyond. That is to limit the time
5930 this function can take.
5932 If MOUSE is non-zero, use the character's mouse-face, not its face.
5934 BASE_FACE_ID, if non-negative, specifies a base face id to use
5935 instead of DEFAULT_FACE_ID.
5937 The face returned is suitable for displaying ASCII characters. */
5940 face_at_buffer_position (struct window
*w
, ptrdiff_t pos
,
5941 ptrdiff_t *endptr
, ptrdiff_t limit
,
5942 int mouse
, int base_face_id
)
5944 struct frame
*f
= XFRAME (w
->frame
);
5945 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5946 Lisp_Object prop
, position
;
5947 ptrdiff_t i
, noverlays
;
5948 Lisp_Object
*overlay_vec
;
5950 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
5951 Lisp_Object limit1
, end
;
5952 struct face
*default_face
;
5954 /* W must display the current buffer. We could write this function
5955 to use the frame and buffer of W, but right now it doesn't. */
5956 /* eassert (XBUFFER (w->contents) == current_buffer); */
5958 XSETFASTINT (position
, pos
);
5962 /* Get the `face' or `mouse_face' text property at POS, and
5963 determine the next position at which the property changes. */
5964 prop
= Fget_text_property (position
, propname
, w
->contents
);
5965 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
5966 end
= Fnext_single_property_change (position
, propname
, w
->contents
, limit1
);
5968 endpos
= XINT (end
);
5970 /* Look at properties from overlays. */
5972 ptrdiff_t next_overlay
;
5974 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, &next_overlay
, 0);
5975 if (next_overlay
< endpos
)
5976 endpos
= next_overlay
;
5984 if (base_face_id
>= 0)
5985 face_id
= base_face_id
;
5986 else if (NILP (Vface_remapping_alist
))
5987 face_id
= DEFAULT_FACE_ID
;
5989 face_id
= lookup_basic_face (f
, DEFAULT_FACE_ID
);
5991 default_face
= FACE_FROM_ID (f
, face_id
);
5994 /* Optimize common cases where we can use the default face. */
5997 return default_face
->id
;
5999 /* Begin with attributes from the default face. */
6000 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6002 /* Merge in attributes specified via text properties. */
6004 merge_face_ref (f
, prop
, attrs
, 1, 0);
6006 /* Now merge the overlay data. */
6007 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6008 for (i
= 0; i
< noverlays
; i
++)
6013 prop
= Foverlay_get (overlay_vec
[i
], propname
);
6015 merge_face_ref (f
, prop
, attrs
, 1, 0);
6017 oend
= OVERLAY_END (overlay_vec
[i
]);
6018 oendpos
= OVERLAY_POSITION (oend
);
6019 if (oendpos
< endpos
)
6025 /* Look up a realized face with the given face attributes,
6026 or realize a new one for ASCII characters. */
6027 return lookup_face (f
, attrs
);
6030 /* Return the face ID at buffer position POS for displaying ASCII
6031 characters associated with overlay strings for overlay OVERLAY.
6033 Like face_at_buffer_position except for OVERLAY. Currently it
6034 simply disregards the `face' properties of all overlays. */
6037 face_for_overlay_string (struct window
*w
, ptrdiff_t pos
,
6038 ptrdiff_t *endptr
, ptrdiff_t limit
,
6039 int mouse
, Lisp_Object overlay
)
6041 struct frame
*f
= XFRAME (w
->frame
);
6042 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6043 Lisp_Object prop
, position
;
6045 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
6046 Lisp_Object limit1
, end
;
6047 struct face
*default_face
;
6049 /* W must display the current buffer. We could write this function
6050 to use the frame and buffer of W, but right now it doesn't. */
6051 /* eassert (XBUFFER (w->contents) == current_buffer); */
6053 XSETFASTINT (position
, pos
);
6057 /* Get the `face' or `mouse_face' text property at POS, and
6058 determine the next position at which the property changes. */
6059 prop
= Fget_text_property (position
, propname
, w
->contents
);
6060 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6061 end
= Fnext_single_property_change (position
, propname
, w
->contents
, limit1
);
6063 endpos
= XINT (end
);
6067 /* Optimize common case where we can use the default face. */
6069 && NILP (Vface_remapping_alist
))
6070 return DEFAULT_FACE_ID
;
6072 /* Begin with attributes from the default face. */
6073 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
6074 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6076 /* Merge in attributes specified via text properties. */
6078 merge_face_ref (f
, prop
, attrs
, 1, 0);
6082 /* Look up a realized face with the given face attributes,
6083 or realize a new one for ASCII characters. */
6084 return lookup_face (f
, attrs
);
6088 /* Compute the face at character position POS in Lisp string STRING on
6089 window W, for ASCII characters.
6091 If STRING is an overlay string, it comes from position BUFPOS in
6092 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
6093 not an overlay string. W must display the current buffer.
6094 REGION_BEG and REGION_END give the start and end positions of the
6095 region; both are -1 if no region is visible.
6097 BASE_FACE_ID is the id of a face to merge with. For strings coming
6098 from overlays or the `display' property it is the face at BUFPOS.
6100 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
6102 Set *ENDPTR to the next position where to check for faces in
6103 STRING; -1 if the face is constant from POS to the end of the
6106 Value is the id of the face to use. The face returned is suitable
6107 for displaying ASCII characters. */
6110 face_at_string_position (struct window
*w
, Lisp_Object string
,
6111 ptrdiff_t pos
, ptrdiff_t bufpos
,
6112 ptrdiff_t *endptr
, enum face_id base_face_id
,
6115 Lisp_Object prop
, position
, end
, limit
;
6116 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6117 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6118 struct face
*base_face
;
6119 bool multibyte_p
= STRING_MULTIBYTE (string
);
6120 Lisp_Object prop_name
= mouse_p
? Qmouse_face
: Qface
;
6122 /* Get the value of the face property at the current position within
6123 STRING. Value is nil if there is no face property. */
6124 XSETFASTINT (position
, pos
);
6125 prop
= Fget_text_property (position
, prop_name
, string
);
6127 /* Get the next position at which to check for faces. Value of end
6128 is nil if face is constant all the way to the end of the string.
6129 Otherwise it is a string position where to check faces next.
6130 Limit is the maximum position up to which to check for property
6131 changes in Fnext_single_property_change. Strings are usually
6132 short, so set the limit to the end of the string. */
6133 XSETFASTINT (limit
, SCHARS (string
));
6134 end
= Fnext_single_property_change (position
, prop_name
, string
, limit
);
6136 *endptr
= XFASTINT (end
);
6140 base_face
= FACE_FROM_ID (f
, base_face_id
);
6141 eassert (base_face
);
6143 /* Optimize the default case that there is no face property. */
6146 /* We can't realize faces for different charsets differently
6147 if we don't have fonts, so we can stop here if not working
6148 on a window-system frame. */
6149 || !FRAME_WINDOW_P (f
)
6150 || FACE_SUITABLE_FOR_ASCII_CHAR_P (base_face
, 0)))
6151 return base_face
->id
;
6153 /* Begin with attributes from the base face. */
6154 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6156 /* Merge in attributes specified via text properties. */
6158 merge_face_ref (f
, prop
, attrs
, 1, 0);
6160 /* Look up a realized face with the given face attributes,
6161 or realize a new one for ASCII characters. */
6162 return lookup_face (f
, attrs
);
6166 /* Merge a face into a realized face.
6168 F is frame where faces are (to be) realized.
6170 FACE_NAME is named face to merge.
6172 If FACE_NAME is nil, FACE_ID is face_id of realized face to merge.
6174 If FACE_NAME is t, FACE_ID is lface_id of face to merge.
6176 BASE_FACE_ID is realized face to merge into.
6182 merge_faces (struct frame
*f
, Lisp_Object face_name
, int face_id
,
6185 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6186 struct face
*base_face
;
6188 base_face
= FACE_FROM_ID (f
, base_face_id
);
6190 return base_face_id
;
6192 if (EQ (face_name
, Qt
))
6194 if (face_id
< 0 || face_id
>= lface_id_to_name_size
)
6195 return base_face_id
;
6196 face_name
= lface_id_to_name
[face_id
];
6197 /* When called during make-frame, lookup_derived_face may fail
6198 if the faces are uninitialized. Don't signal an error. */
6199 face_id
= lookup_derived_face (f
, face_name
, base_face_id
, 0);
6200 return (face_id
>= 0 ? face_id
: base_face_id
);
6203 /* Begin with attributes from the base face. */
6204 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6206 if (!NILP (face_name
))
6208 if (!merge_named_face (f
, face_name
, attrs
, 0))
6209 return base_face_id
;
6215 return base_face_id
;
6216 face
= FACE_FROM_ID (f
, face_id
);
6218 return base_face_id
;
6219 merge_face_vectors (f
, face
->lface
, attrs
, 0);
6222 /* Look up a realized face with the given face attributes,
6223 or realize a new one for ASCII characters. */
6224 return lookup_face (f
, attrs
);
6229 #ifndef HAVE_X_WINDOWS
6230 DEFUN ("x-load-color-file", Fx_load_color_file
,
6231 Sx_load_color_file
, 1, 1, 0,
6232 doc
: /* Create an alist of color entries from an external file.
6234 The file should define one named RGB color per line like so:
6236 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6237 (Lisp_Object filename
)
6240 Lisp_Object cmap
= Qnil
;
6241 Lisp_Object abspath
;
6243 CHECK_STRING (filename
);
6244 abspath
= Fexpand_file_name (filename
, Qnil
);
6247 fp
= emacs_fopen (SSDATA (abspath
), "rt");
6251 int red
, green
, blue
;
6254 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
6255 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
6258 int color
= RGB (red
, green
, blue
);
6260 int color
= (red
<< 16) | (green
<< 8) | blue
;
6262 char *name
= buf
+ num
;
6263 ptrdiff_t len
= strlen (name
);
6264 len
-= 0 < len
&& name
[len
- 1] == '\n';
6265 cmap
= Fcons (Fcons (make_string (name
, len
), make_number (color
)),
6277 /***********************************************************************
6279 ***********************************************************************/
6283 /* Print the contents of the realized face FACE to stderr. */
6286 dump_realized_face (struct face
*face
)
6288 fprintf (stderr
, "ID: %d\n", face
->id
);
6289 #ifdef HAVE_X_WINDOWS
6290 fprintf (stderr
, "gc: %ld\n", (long) face
->gc
);
6292 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
6294 SDATA (face
->lface
[LFACE_FOREGROUND_INDEX
]));
6295 fprintf (stderr
, "background: 0x%lx (%s)\n",
6297 SDATA (face
->lface
[LFACE_BACKGROUND_INDEX
]));
6299 fprintf (stderr
, "font_name: %s (%s)\n",
6300 SDATA (face
->font
->props
[FONT_NAME_INDEX
]),
6301 SDATA (face
->lface
[LFACE_FAMILY_INDEX
]));
6302 #ifdef HAVE_X_WINDOWS
6303 fprintf (stderr
, "font = %p\n", face
->font
);
6305 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
6306 fprintf (stderr
, "underline: %d (%s)\n",
6308 SDATA (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
])));
6309 fprintf (stderr
, "hash: %d\n", face
->hash
);
6313 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, doc
: /* */)
6320 fprintf (stderr
, "font selection order: ");
6321 for (i
= 0; i
< ARRAYELTS (font_sort_order
); ++i
)
6322 fprintf (stderr
, "%d ", font_sort_order
[i
]);
6323 fprintf (stderr
, "\n");
6325 fprintf (stderr
, "alternative fonts: ");
6326 debug_print (Vface_alternative_font_family_alist
);
6327 fprintf (stderr
, "\n");
6329 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
6330 Fdump_face (make_number (i
));
6336 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
6338 error ("Not a valid face");
6339 dump_realized_face (face
);
6346 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
6347 0, 0, 0, doc
: /* */)
6350 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
6351 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
6352 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
6356 #endif /* GLYPH_DEBUG */
6360 /***********************************************************************
6362 ***********************************************************************/
6365 syms_of_xfaces (void)
6369 DEFSYM (Qface
, "face");
6370 DEFSYM (Qface_no_inherit
, "face-no-inherit");
6371 DEFSYM (Qbitmap_spec_p
, "bitmap-spec-p");
6372 DEFSYM (Qframe_set_background_mode
, "frame-set-background-mode");
6374 /* Lisp face attribute keywords. */
6375 DEFSYM (QCfamily
, ":family");
6376 DEFSYM (QCheight
, ":height");
6377 DEFSYM (QCweight
, ":weight");
6378 DEFSYM (QCslant
, ":slant");
6379 DEFSYM (QCunderline
, ":underline");
6380 DEFSYM (QCinverse_video
, ":inverse-video");
6381 DEFSYM (QCreverse_video
, ":reverse-video");
6382 DEFSYM (QCforeground
, ":foreground");
6383 DEFSYM (QCbackground
, ":background");
6384 DEFSYM (QCstipple
, ":stipple");
6385 DEFSYM (QCwidth
, ":width");
6386 DEFSYM (QCfont
, ":font");
6387 DEFSYM (QCfontset
, ":fontset");
6388 DEFSYM (QCdistant_foreground
, ":distant-foreground");
6389 DEFSYM (QCbold
, ":bold");
6390 DEFSYM (QCitalic
, ":italic");
6391 DEFSYM (QCoverline
, ":overline");
6392 DEFSYM (QCstrike_through
, ":strike-through");
6393 DEFSYM (QCbox
, ":box");
6394 DEFSYM (QCinherit
, ":inherit");
6396 /* Symbols used for Lisp face attribute values. */
6397 DEFSYM (QCcolor
, ":color");
6398 DEFSYM (QCline_width
, ":line-width");
6399 DEFSYM (QCstyle
, ":style");
6400 DEFSYM (Qline
, "line");
6401 DEFSYM (Qwave
, "wave");
6402 DEFSYM (Qreleased_button
, "released-button");
6403 DEFSYM (Qpressed_button
, "pressed-button");
6404 DEFSYM (Qnormal
, "normal");
6405 DEFSYM (Qextra_light
, "extra-light");
6406 DEFSYM (Qlight
, "light");
6407 DEFSYM (Qsemi_light
, "semi-light");
6408 DEFSYM (Qsemi_bold
, "semi-bold");
6409 DEFSYM (Qbold
, "bold");
6410 DEFSYM (Qextra_bold
, "extra-bold");
6411 DEFSYM (Qultra_bold
, "ultra-bold");
6412 DEFSYM (Qoblique
, "oblique");
6413 DEFSYM (Qitalic
, "italic");
6414 DEFSYM (Qbackground_color
, "background-color");
6415 DEFSYM (Qforeground_color
, "foreground-color");
6416 DEFSYM (Qunspecified
, "unspecified");
6417 DEFSYM (QCignore_defface
, ":ignore-defface");
6419 DEFSYM (Qface_alias
, "face-alias");
6420 DEFSYM (Qdefault
, "default");
6421 DEFSYM (Qtool_bar
, "tool-bar");
6422 DEFSYM (Qregion
, "region");
6423 DEFSYM (Qfringe
, "fringe");
6424 DEFSYM (Qheader_line
, "header-line");
6425 DEFSYM (Qscroll_bar
, "scroll-bar");
6426 DEFSYM (Qmenu
, "menu");
6427 DEFSYM (Qcursor
, "cursor");
6428 DEFSYM (Qborder
, "border");
6429 DEFSYM (Qmouse
, "mouse");
6430 DEFSYM (Qmode_line_inactive
, "mode-line-inactive");
6431 DEFSYM (Qvertical_border
, "vertical-border");
6432 DEFSYM (Qwindow_divider
, "window-divider");
6433 DEFSYM (Qwindow_divider_first_pixel
, "window-divider-first-pixel");
6434 DEFSYM (Qwindow_divider_last_pixel
, "window-divider-last-pixel");
6435 DEFSYM (Qtty_color_desc
, "tty-color-desc");
6436 DEFSYM (Qtty_color_standard_values
, "tty-color-standard-values");
6437 DEFSYM (Qtty_color_by_index
, "tty-color-by-index");
6438 DEFSYM (Qtty_color_alist
, "tty-color-alist");
6439 DEFSYM (Qscalable_fonts_allowed
, "scalable-fonts-allowed");
6441 Vparam_value_alist
= list1 (Fcons (Qnil
, Qnil
));
6442 staticpro (&Vparam_value_alist
);
6443 Vface_alternative_font_family_alist
= Qnil
;
6444 staticpro (&Vface_alternative_font_family_alist
);
6445 Vface_alternative_font_registry_alist
= Qnil
;
6446 staticpro (&Vface_alternative_font_registry_alist
);
6448 DEFVAR_LISP ("face-new-frame-defaults", Vface_new_frame_defaults
,
6449 doc
: /* List of global face definitions (for internal use only.) */);
6450 Vface_new_frame_defaults
= Qnil
;
6452 DEFVAR_LISP ("face-default-stipple", Vface_default_stipple
,
6453 doc
: /* Default stipple pattern used on monochrome displays.
6454 This stipple pattern is used on monochrome displays
6455 instead of shades of gray for a face background color.
6456 See `set-face-stipple' for possible values for this variable. */);
6457 Vface_default_stipple
= build_pure_c_string ("gray3");
6459 DEFVAR_LISP ("tty-defined-color-alist", Vtty_defined_color_alist
,
6460 doc
: /* An alist of defined terminal colors and their RGB values.
6461 See the docstring of `tty-color-alist' for the details. */);
6462 Vtty_defined_color_alist
= Qnil
;
6464 DEFVAR_LISP ("scalable-fonts-allowed", Vscalable_fonts_allowed
,
6465 doc
: /* Allowed scalable fonts.
6466 A value of nil means don't allow any scalable fonts.
6467 A value of t means allow any scalable font.
6468 Otherwise, value must be a list of regular expressions. A font may be
6469 scaled if its name matches a regular expression in the list.
6470 Note that if value is nil, a scalable font might still be used, if no
6471 other font of the appropriate family and registry is available. */);
6472 Vscalable_fonts_allowed
= Qnil
;
6474 DEFVAR_LISP ("face-ignored-fonts", Vface_ignored_fonts
,
6475 doc
: /* List of ignored fonts.
6476 Each element is a regular expression that matches names of fonts to
6478 Vface_ignored_fonts
= Qnil
;
6480 DEFVAR_LISP ("face-remapping-alist", Vface_remapping_alist
,
6481 doc
: /* Alist of face remappings.
6482 Each element is of the form:
6484 (FACE . REPLACEMENT),
6486 which causes display of the face FACE to use REPLACEMENT instead.
6487 REPLACEMENT is a face specification, i.e. one of the following:
6490 (2) a property list of attribute/value pairs, or
6491 (3) a list in which each element has the form of (1) or (2).
6493 List values for REPLACEMENT are merged to form the final face
6494 specification, with earlier entries taking precedence, in the same as
6495 as in the `face' text property.
6497 Face-name remapping cycles are suppressed; recursive references use
6498 the underlying face instead of the remapped face. So a remapping of
6501 (FACE EXTRA-FACE... FACE)
6505 (FACE (FACE-ATTR VAL ...) FACE)
6507 causes EXTRA-FACE... or (FACE-ATTR VAL ...) to be _merged_ with the
6508 existing definition of FACE. Note that this isn't necessary for the
6509 default face, since every face inherits from the default face.
6511 If this variable is made buffer-local, the face remapping takes effect
6512 only in that buffer. For instance, the mode my-mode could define a
6513 face `my-mode-default', and then in the mode setup function, do:
6515 (set (make-local-variable 'face-remapping-alist)
6516 '((default my-mode-default)))).
6518 Because Emacs normally only redraws screen areas when the underlying
6519 buffer contents change, you may need to call `redraw-display' after
6520 changing this variable for it to take effect. */);
6521 Vface_remapping_alist
= Qnil
;
6523 DEFVAR_LISP ("face-font-rescale-alist", Vface_font_rescale_alist
,
6524 doc
: /* Alist of fonts vs the rescaling factors.
6525 Each element is a cons (FONT-PATTERN . RESCALE-RATIO), where
6526 FONT-PATTERN is a font-spec or a regular expression matching a font name, and
6527 RESCALE-RATIO is a floating point number to specify how much larger
6528 \(or smaller) font we should use. For instance, if a face requests
6529 a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point. */);
6530 Vface_font_rescale_alist
= Qnil
;