1 /* xfaces.c -- "Face" primitives.
3 Copyright (C) 1993-1994, 1998-2013 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"
214 #ifdef HAVE_X_WINDOWS
218 #include <Xm/XmStrDefs.h>
219 #endif /* USE_MOTIF */
220 #endif /* HAVE_X_WINDOWS */
226 #ifdef HAVE_WINDOW_SYSTEM
230 #undef FRAME_X_DISPLAY_INFO
231 #define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO
232 #define x_display_info w32_display_info
233 #define GCGraphicsExposures 0
234 #endif /* HAVE_NTGUI */
237 #undef FRAME_X_DISPLAY_INFO
238 #define FRAME_X_DISPLAY_INFO FRAME_NS_DISPLAY_INFO
239 #define GCGraphicsExposures 0
241 #endif /* HAVE_WINDOW_SYSTEM */
244 #include "dispextern.h"
245 #include "blockinput.h"
247 #include "intervals.h"
248 #include "termchar.h"
252 #ifdef HAVE_X_WINDOWS
254 /* Compensate for a bug in Xos.h on some systems, on which it requires
255 time.h. On some such systems, Xos.h tries to redefine struct
256 timeval and struct timezone if USG is #defined while it is
259 #ifdef XOS_NEEDS_TIME_H
265 #if defined USG || defined __TIMEVAL__ /* Don't warn about unused macros. */
267 #else /* not XOS_NEEDS_TIME_H */
269 #endif /* not XOS_NEEDS_TIME_H */
271 #endif /* HAVE_X_WINDOWS */
275 /* Number of pt per inch (from the TeXbook). */
277 #define PT_PER_INCH 72.27
279 /* Non-zero if face attribute ATTR is unspecified. */
281 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified)
283 /* Non-zero if face attribute ATTR is `ignore-defface'. */
285 #define IGNORE_DEFFACE_P(ATTR) EQ ((ATTR), QCignore_defface)
287 /* Value is the number of elements of VECTOR. */
289 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
291 /* Size of hash table of realized faces in face caches (should be a
294 #define FACE_CACHE_BUCKETS_SIZE 1001
296 /* Keyword symbols used for face attribute names. */
298 Lisp_Object QCfamily
, QCheight
, QCweight
, QCslant
;
299 static Lisp_Object QCunderline
;
300 static Lisp_Object QCinverse_video
, QCstipple
;
301 Lisp_Object QCforeground
, QCbackground
;
303 static Lisp_Object QCfont
, QCbold
, QCitalic
;
304 static Lisp_Object QCreverse_video
;
305 static Lisp_Object QCoverline
, QCstrike_through
, QCbox
, QCinherit
;
306 static Lisp_Object QCfontset
;
308 /* Symbols used for attribute values. */
312 static Lisp_Object Qline
, Qwave
;
313 Lisp_Object Qextra_light
, Qlight
;
314 Lisp_Object Qsemi_light
, Qsemi_bold
, Qextra_bold
, Qultra_bold
;
315 Lisp_Object Qoblique
;
317 static Lisp_Object Qreleased_button
, Qpressed_button
;
318 static Lisp_Object QCstyle
, QCcolor
, QCline_width
;
319 Lisp_Object Qunspecified
; /* used in dosfns.c */
320 static Lisp_Object QCignore_defface
;
322 char unspecified_fg
[] = "unspecified-fg", unspecified_bg
[] = "unspecified-bg";
324 /* The name of the function to call when the background of the frame
325 has changed, frame_set_background_mode. */
327 static Lisp_Object Qframe_set_background_mode
;
329 /* Names of basic faces. */
331 Lisp_Object Qdefault
, Qtool_bar
, Qfringe
;
332 static Lisp_Object Qregion
;
333 Lisp_Object Qheader_line
, Qscroll_bar
, Qcursor
;
334 static Lisp_Object Qborder
, Qmouse
, Qmenu
;
335 Lisp_Object Qmode_line_inactive
;
336 static Lisp_Object Qvertical_border
;
338 /* The symbol `face-alias'. A symbols having that property is an
339 alias for another face. Value of the property is the name of
342 static Lisp_Object Qface_alias
;
344 /* Alist of alternative font families. Each element is of the form
345 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
346 try FAMILY1, then FAMILY2, ... */
348 Lisp_Object Vface_alternative_font_family_alist
;
350 /* Alist of alternative font registries. Each element is of the form
351 (REGISTRY REGISTRY1 REGISTRY2...). If fonts of REGISTRY can't be
352 loaded, try REGISTRY1, then REGISTRY2, ... */
354 Lisp_Object Vface_alternative_font_registry_alist
;
356 /* Allowed scalable fonts. A value of nil means don't allow any
357 scalable fonts. A value of t means allow the use of any scalable
358 font. Otherwise, value must be a list of regular expressions. A
359 font may be scaled if its name matches a regular expression in the
362 static Lisp_Object Qscalable_fonts_allowed
;
364 /* The symbols `foreground-color' and `background-color' which can be
365 used as part of a `face' property. This is for compatibility with
368 Lisp_Object Qforeground_color
, Qbackground_color
;
370 /* The symbols `face' and `mouse-face' used as text properties. */
374 /* Property for basic faces which other faces cannot inherit. */
376 static Lisp_Object Qface_no_inherit
;
378 /* Error symbol for wrong_type_argument in load_pixmap. */
380 static Lisp_Object Qbitmap_spec_p
;
382 /* The next ID to assign to Lisp faces. */
384 static int next_lface_id
;
386 /* A vector mapping Lisp face Id's to face names. */
388 static Lisp_Object
*lface_id_to_name
;
389 static ptrdiff_t lface_id_to_name_size
;
391 /* TTY color-related functions (defined in tty-colors.el). */
393 static Lisp_Object Qtty_color_desc
, Qtty_color_by_index
, Qtty_color_standard_values
;
395 /* The name of the function used to compute colors on TTYs. */
397 static Lisp_Object Qtty_color_alist
;
399 /* Counter for calls to clear_face_cache. If this counter reaches
400 CLEAR_FONT_TABLE_COUNT, and a frame has more than
401 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
403 static int clear_font_table_count
;
404 #define CLEAR_FONT_TABLE_COUNT 100
405 #define CLEAR_FONT_TABLE_NFONTS 10
407 /* Non-zero means face attributes have been changed since the last
408 redisplay. Used in redisplay_internal. */
410 int face_change_count
;
412 /* Non-zero means don't display bold text if a face's foreground
413 and background colors are the inverse of the default colors of the
414 display. This is a kluge to suppress `bold black' foreground text
415 which is hard to read on an LCD monitor. */
417 static int tty_suppress_bold_inverse_default_colors_p
;
419 /* A list of the form `((x . y))' used to avoid consing in
420 Finternal_set_lisp_face_attribute. */
422 static Lisp_Object Vparam_value_alist
;
424 /* The total number of colors currently allocated. */
427 static int ncolors_allocated
;
428 static int npixmaps_allocated
;
432 /* Non-zero means the definition of the `menu' face for new frames has
435 static int menu_face_changed_default
;
438 /* Function prototypes. */
441 struct named_merge_point
;
443 static void set_font_frame_param (Lisp_Object
, Lisp_Object
);
444 static struct face
*realize_face (struct face_cache
*, Lisp_Object
*,
446 static struct face
*realize_non_ascii_face (struct frame
*, Lisp_Object
,
448 static struct face
*realize_x_face (struct face_cache
*, Lisp_Object
*);
449 static struct face
*realize_tty_face (struct face_cache
*, Lisp_Object
*);
450 static bool realize_basic_faces (struct frame
*);
451 static bool realize_default_face (struct frame
*);
452 static void realize_named_face (struct frame
*, Lisp_Object
, int);
453 static struct face_cache
*make_face_cache (struct frame
*);
454 static void clear_face_gcs (struct face_cache
*);
455 static void free_face_cache (struct face_cache
*);
456 static int merge_face_ref (struct frame
*, Lisp_Object
, Lisp_Object
*,
457 int, struct named_merge_point
*);
460 /***********************************************************************
462 ***********************************************************************/
464 #ifdef HAVE_X_WINDOWS
466 #ifdef DEBUG_X_COLORS
468 /* The following is a poor mans infrastructure for debugging X color
469 allocation problems on displays with PseudoColor-8. Some X servers
470 like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement
471 color reference counts completely so that they don't signal an
472 error when a color is freed whose reference count is already 0.
473 Other X servers do. To help me debug this, the following code
474 implements a simple reference counting schema of its own, for a
475 single display/screen. --gerd. */
477 /* Reference counts for pixel colors. */
479 int color_count
[256];
481 /* Register color PIXEL as allocated. */
484 register_color (unsigned long pixel
)
486 eassert (pixel
< 256);
487 ++color_count
[pixel
];
491 /* Register color PIXEL as deallocated. */
494 unregister_color (unsigned long pixel
)
496 eassert (pixel
< 256);
497 if (color_count
[pixel
] > 0)
498 --color_count
[pixel
];
504 /* Register N colors from PIXELS as deallocated. */
507 unregister_colors (unsigned long *pixels
, int n
)
510 for (i
= 0; i
< n
; ++i
)
511 unregister_color (pixels
[i
]);
515 DEFUN ("dump-colors", Fdump_colors
, Sdump_colors
, 0, 0, 0,
516 doc
: /* Dump currently allocated colors to stderr. */)
521 fputc ('\n', stderr
);
523 for (i
= n
= 0; i
< sizeof color_count
/ sizeof color_count
[0]; ++i
)
526 fprintf (stderr
, "%3d: %5d", i
, color_count
[i
]);
529 fputc ('\n', stderr
);
531 fputc ('\t', stderr
);
535 fputc ('\n', stderr
);
539 #endif /* DEBUG_X_COLORS */
542 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
543 color values. Interrupt input must be blocked when this function
547 x_free_colors (struct frame
*f
, long unsigned int *pixels
, int npixels
)
549 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
551 /* If display has an immutable color map, freeing colors is not
552 necessary and some servers don't allow it. So don't do it. */
553 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
555 #ifdef DEBUG_X_COLORS
556 unregister_colors (pixels
, npixels
);
558 XFreeColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
566 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
567 color values. Interrupt input must be blocked when this function
571 x_free_dpy_colors (Display
*dpy
, Screen
*screen
, Colormap cmap
,
572 long unsigned int *pixels
, int npixels
)
574 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
575 int class = dpyinfo
->visual
->class;
577 /* If display has an immutable color map, freeing colors is not
578 necessary and some servers don't allow it. So don't do it. */
579 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
581 #ifdef DEBUG_X_COLORS
582 unregister_colors (pixels
, npixels
);
584 XFreeColors (dpy
, cmap
, pixels
, npixels
, 0);
587 #endif /* USE_X_TOOLKIT */
589 /* Create and return a GC for use on frame F. GC values and mask
590 are given by XGCV and MASK. */
593 x_create_gc (struct frame
*f
, long unsigned int mask
, XGCValues
*xgcv
)
597 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
604 /* Free GC which was used on frame F. */
607 x_free_gc (struct frame
*f
, GC gc
)
609 eassert (input_blocked_p ());
610 IF_DEBUG (eassert (--ngcs
>= 0));
611 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
614 #endif /* HAVE_X_WINDOWS */
617 /* W32 emulation of GCs */
620 x_create_gc (struct frame
*f
, unsigned long mask
, XGCValues
*xgcv
)
624 gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, xgcv
);
631 /* Free GC which was used on frame F. */
634 x_free_gc (struct frame
*f
, GC gc
)
636 IF_DEBUG (eassert (--ngcs
>= 0));
640 #endif /* HAVE_NTGUI */
643 /* NS emulation of GCs */
646 x_create_gc (struct frame
*f
,
650 GC gc
= xmalloc (sizeof *gc
);
656 x_free_gc (struct frame
*f
, GC gc
)
662 /***********************************************************************
664 ***********************************************************************/
666 /* Initialize face cache and basic faces for frame F. */
669 init_frame_faces (struct frame
*f
)
671 /* Make a face cache, if F doesn't have one. */
672 if (FRAME_FACE_CACHE (f
) == NULL
)
673 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
675 #ifdef HAVE_WINDOW_SYSTEM
676 /* Make the image cache. */
677 if (FRAME_WINDOW_P (f
))
679 /* We initialize the image cache when creating the first frame
680 on a terminal, and not during terminal creation. This way,
681 `x-open-connection' on a tty won't create an image cache. */
682 if (FRAME_IMAGE_CACHE (f
) == NULL
)
683 FRAME_IMAGE_CACHE (f
) = make_image_cache ();
684 ++FRAME_IMAGE_CACHE (f
)->refcount
;
686 #endif /* HAVE_WINDOW_SYSTEM */
688 /* Realize basic faces. Must have enough information in frame
689 parameters to realize basic faces at this point. */
690 #ifdef HAVE_X_WINDOWS
691 if (!FRAME_X_P (f
) || FRAME_X_WINDOW (f
))
694 if (!FRAME_WINDOW_P (f
) || FRAME_W32_WINDOW (f
))
697 if (!FRAME_NS_P (f
) || FRAME_NS_WINDOW (f
))
699 if (!realize_basic_faces (f
))
704 /* Free face cache of frame F. Called from delete_frame. */
707 free_frame_faces (struct frame
*f
)
709 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
713 free_face_cache (face_cache
);
714 FRAME_FACE_CACHE (f
) = NULL
;
717 #ifdef HAVE_WINDOW_SYSTEM
718 if (FRAME_WINDOW_P (f
))
720 struct image_cache
*image_cache
= FRAME_IMAGE_CACHE (f
);
723 --image_cache
->refcount
;
724 if (image_cache
->refcount
== 0)
725 free_image_cache (f
);
728 #endif /* HAVE_WINDOW_SYSTEM */
732 /* Clear face caches, and recompute basic faces for frame F. Call
733 this after changing frame parameters on which those faces depend,
734 or when realized faces have been freed due to changing attributes
738 recompute_basic_faces (struct frame
*f
)
740 if (FRAME_FACE_CACHE (f
))
742 clear_face_cache (0);
743 if (!realize_basic_faces (f
))
749 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
750 try to free unused fonts, too. */
753 clear_face_cache (int clear_fonts_p
)
755 #ifdef HAVE_WINDOW_SYSTEM
756 Lisp_Object tail
, frame
;
759 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
761 /* From time to time see if we can unload some fonts. This also
762 frees all realized faces on all frames. Fonts needed by
763 faces will be loaded again when faces are realized again. */
764 clear_font_table_count
= 0;
766 FOR_EACH_FRAME (tail
, frame
)
768 struct frame
*f
= XFRAME (frame
);
769 if (FRAME_WINDOW_P (f
)
770 && FRAME_X_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
772 clear_font_cache (f
);
773 free_all_realized_faces (frame
);
779 /* Clear GCs of realized faces. */
780 FOR_EACH_FRAME (tail
, frame
)
782 struct frame
*f
= XFRAME (frame
);
783 if (FRAME_WINDOW_P (f
))
784 clear_face_gcs (FRAME_FACE_CACHE (f
));
786 clear_image_caches (Qnil
);
788 #endif /* HAVE_WINDOW_SYSTEM */
792 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
793 doc
: /* Clear face caches on all frames.
794 Optional THOROUGHLY non-nil means try to free unused fonts, too. */)
795 (Lisp_Object thoroughly
)
797 clear_face_cache (!NILP (thoroughly
));
799 ++windows_or_buffers_changed
;
804 /***********************************************************************
806 ***********************************************************************/
808 #ifdef HAVE_WINDOW_SYSTEM
810 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
811 doc
: /* Value is non-nil if OBJECT is a valid bitmap specification.
812 A bitmap specification is either a string, a file name, or a list
813 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
814 HEIGHT is its height, and DATA is a string containing the bits of
815 the pixmap. Bits are stored row by row, each row occupies
816 \(WIDTH + 7)/8 bytes. */)
821 if (STRINGP (object
))
822 /* If OBJECT is a string, it's a file name. */
824 else if (CONSP (object
))
826 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
827 HEIGHT must be ints > 0, and DATA must be string large
828 enough to hold a bitmap of the specified size. */
829 Lisp_Object width
, height
, data
;
831 height
= width
= data
= Qnil
;
835 width
= XCAR (object
);
836 object
= XCDR (object
);
839 height
= XCAR (object
);
840 object
= XCDR (object
);
842 data
= XCAR (object
);
847 && RANGED_INTEGERP (1, width
, INT_MAX
)
848 && RANGED_INTEGERP (1, height
, INT_MAX
))
850 int bytes_per_row
= ((XINT (width
) + BITS_PER_CHAR
- 1)
852 if (XINT (height
) <= SBYTES (data
) / bytes_per_row
)
857 return pixmap_p
? Qt
: Qnil
;
861 /* Load a bitmap according to NAME (which is either a file name or a
862 pixmap spec) for use on frame F. Value is the bitmap_id (see
863 xfns.c). If NAME is nil, return with a bitmap id of zero. If
864 bitmap cannot be loaded, display a message saying so, and return
865 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
866 if these pointers are not null. */
869 load_pixmap (struct frame
*f
, Lisp_Object name
, unsigned int *w_ptr
,
877 CHECK_TYPE (!NILP (Fbitmap_spec_p (name
)), Qbitmap_spec_p
, name
);
882 /* Decode a bitmap spec into a bitmap. */
887 w
= XINT (Fcar (name
));
888 h
= XINT (Fcar (Fcdr (name
)));
889 bits
= Fcar (Fcdr (Fcdr (name
)));
891 bitmap_id
= x_create_bitmap_from_data (f
, SSDATA (bits
),
896 /* It must be a string -- a file name. */
897 bitmap_id
= x_create_bitmap_from_file (f
, name
);
903 add_to_log ("Invalid or undefined bitmap `%s'", name
, Qnil
);
914 ++npixmaps_allocated
;
917 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
920 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
926 #endif /* HAVE_WINDOW_SYSTEM */
930 /***********************************************************************
932 ***********************************************************************/
934 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
935 RGB_LIST should contain (at least) 3 lisp integers.
936 Return 0 if there's a problem with RGB_LIST, otherwise return 1. */
939 parse_rgb_list (Lisp_Object rgb_list
, XColor
*color
)
941 #define PARSE_RGB_LIST_FIELD(field) \
942 if (CONSP (rgb_list) && INTEGERP (XCAR (rgb_list))) \
944 color->field = XINT (XCAR (rgb_list)); \
945 rgb_list = XCDR (rgb_list); \
950 PARSE_RGB_LIST_FIELD (red
);
951 PARSE_RGB_LIST_FIELD (green
);
952 PARSE_RGB_LIST_FIELD (blue
);
958 /* Lookup on frame F the color described by the lisp string COLOR.
959 The resulting tty color is returned in TTY_COLOR; if STD_COLOR is
960 non-zero, then the `standard' definition of the same color is
964 tty_lookup_color (struct frame
*f
, Lisp_Object color
, XColor
*tty_color
,
967 Lisp_Object frame
, color_desc
;
969 if (!STRINGP (color
) || NILP (Ffboundp (Qtty_color_desc
)))
972 XSETFRAME (frame
, f
);
974 color_desc
= call2 (Qtty_color_desc
, color
, frame
);
975 if (CONSP (color_desc
) && CONSP (XCDR (color_desc
)))
979 if (! INTEGERP (XCAR (XCDR (color_desc
))))
982 tty_color
->pixel
= XINT (XCAR (XCDR (color_desc
)));
984 rgb
= XCDR (XCDR (color_desc
));
985 if (! parse_rgb_list (rgb
, tty_color
))
988 /* Should we fill in STD_COLOR too? */
991 /* Default STD_COLOR to the same as TTY_COLOR. */
992 *std_color
= *tty_color
;
994 /* Do a quick check to see if the returned descriptor is
995 actually _exactly_ equal to COLOR, otherwise we have to
996 lookup STD_COLOR separately. If it's impossible to lookup
997 a standard color, we just give up and use TTY_COLOR. */
998 if ((!STRINGP (XCAR (color_desc
))
999 || NILP (Fstring_equal (color
, XCAR (color_desc
))))
1000 && !NILP (Ffboundp (Qtty_color_standard_values
)))
1002 /* Look up STD_COLOR separately. */
1003 rgb
= call1 (Qtty_color_standard_values
, color
);
1004 if (! parse_rgb_list (rgb
, std_color
))
1011 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
1012 /* We were called early during startup, and the colors are not
1013 yet set up in tty-defined-color-alist. Don't return a failure
1014 indication, since this produces the annoying "Unable to
1015 load color" messages in the *Messages* buffer. */
1018 /* tty-color-desc seems to have returned a bad value. */
1022 /* A version of defined_color for non-X frames. */
1025 tty_defined_color (struct frame
*f
, const char *color_name
,
1026 XColor
*color_def
, bool alloc
)
1031 color_def
->pixel
= FACE_TTY_DEFAULT_COLOR
;
1033 color_def
->blue
= 0;
1034 color_def
->green
= 0;
1037 status
= tty_lookup_color (f
, build_string (color_name
), color_def
, NULL
);
1039 if (color_def
->pixel
== FACE_TTY_DEFAULT_COLOR
&& *color_name
)
1041 if (strcmp (color_name
, "unspecified-fg") == 0)
1042 color_def
->pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
1043 else if (strcmp (color_name
, "unspecified-bg") == 0)
1044 color_def
->pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
1047 if (color_def
->pixel
!= FACE_TTY_DEFAULT_COLOR
)
1054 /* Decide if color named COLOR_NAME is valid for the display
1055 associated with the frame F; if so, return the rgb values in
1056 COLOR_DEF. If ALLOC, allocate a new colormap cell.
1058 This does the right thing for any type of frame. */
1061 defined_color (struct frame
*f
, const char *color_name
, XColor
*color_def
,
1064 if (!FRAME_WINDOW_P (f
))
1065 return tty_defined_color (f
, color_name
, color_def
, alloc
);
1066 #ifdef HAVE_X_WINDOWS
1067 else if (FRAME_X_P (f
))
1068 return x_defined_color (f
, color_name
, color_def
, alloc
);
1071 else if (FRAME_W32_P (f
))
1072 return w32_defined_color (f
, color_name
, color_def
, alloc
);
1075 else if (FRAME_NS_P (f
))
1076 return ns_defined_color (f
, color_name
, color_def
, alloc
, 1);
1083 /* Given the index IDX of a tty color on frame F, return its name, a
1087 tty_color_name (struct frame
*f
, int idx
)
1089 if (idx
>= 0 && !NILP (Ffboundp (Qtty_color_by_index
)))
1092 Lisp_Object coldesc
;
1094 XSETFRAME (frame
, f
);
1095 coldesc
= call2 (Qtty_color_by_index
, make_number (idx
), frame
);
1097 if (!NILP (coldesc
))
1098 return XCAR (coldesc
);
1101 /* We can have an MSDOG frame under -nw for a short window of
1102 opportunity before internal_terminal_init is called. DTRT. */
1103 if (FRAME_MSDOS_P (f
) && !inhibit_window_system
)
1104 return msdos_stdcolor_name (idx
);
1107 if (idx
== FACE_TTY_DEFAULT_FG_COLOR
)
1108 return build_string (unspecified_fg
);
1109 if (idx
== FACE_TTY_DEFAULT_BG_COLOR
)
1110 return build_string (unspecified_bg
);
1112 return Qunspecified
;
1116 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1119 The criterion implemented here is not a terribly sophisticated one. */
1122 face_color_gray_p (struct frame
*f
, const char *color_name
)
1127 if (defined_color (f
, color_name
, &color
, 0))
1128 gray_p
= (/* Any color sufficiently close to black counts as gray. */
1129 (color
.red
< 5000 && color
.green
< 5000 && color
.blue
< 5000)
1131 ((eabs (color
.red
- color
.green
)
1132 < max (color
.red
, color
.green
) / 20)
1133 && (eabs (color
.green
- color
.blue
)
1134 < max (color
.green
, color
.blue
) / 20)
1135 && (eabs (color
.blue
- color
.red
)
1136 < max (color
.blue
, color
.red
) / 20)));
1144 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1145 BACKGROUND_P non-zero means the color will be used as background
1149 face_color_supported_p (struct frame
*f
, const char *color_name
,
1155 XSETFRAME (frame
, f
);
1157 #ifdef HAVE_WINDOW_SYSTEM
1159 ? (!NILP (Fxw_display_color_p (frame
))
1160 || xstrcasecmp (color_name
, "black") == 0
1161 || xstrcasecmp (color_name
, "white") == 0
1163 && face_color_gray_p (f
, color_name
))
1164 || (!NILP (Fx_display_grayscale_p (frame
))
1165 && face_color_gray_p (f
, color_name
)))
1168 tty_defined_color (f
, color_name
, ¬_used
, 0);
1172 DEFUN ("color-gray-p", Fcolor_gray_p
, Scolor_gray_p
, 1, 2, 0,
1173 doc
: /* Return non-nil if COLOR is a shade of gray (or white or black).
1174 FRAME specifies the frame and thus the display for interpreting COLOR.
1175 If FRAME is nil or omitted, use the selected frame. */)
1176 (Lisp_Object color
, Lisp_Object frame
)
1178 CHECK_STRING (color
);
1179 return (face_color_gray_p (decode_any_frame (frame
), SSDATA (color
))
1184 DEFUN ("color-supported-p", Fcolor_supported_p
,
1185 Scolor_supported_p
, 1, 3, 0,
1186 doc
: /* Return non-nil if COLOR can be displayed on FRAME.
1187 BACKGROUND-P non-nil means COLOR is used as a background.
1188 Otherwise, this function tells whether it can be used as a foreground.
1189 If FRAME is nil or omitted, use the selected frame.
1190 COLOR must be a valid color name. */)
1191 (Lisp_Object color
, Lisp_Object frame
, Lisp_Object background_p
)
1193 CHECK_STRING (color
);
1194 return (face_color_supported_p (decode_any_frame (frame
),
1195 SSDATA (color
), !NILP (background_p
))
1200 /* Load color with name NAME for use by face FACE on frame F.
1201 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1202 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1203 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1204 pixel color. If color cannot be loaded, display a message, and
1205 return the foreground, background or underline color of F, but
1206 record that fact in flags of the face so that we don't try to free
1210 load_color (struct frame
*f
, struct face
*face
, Lisp_Object name
,
1211 enum lface_attribute_index target_index
)
1215 eassert (STRINGP (name
));
1216 eassert (target_index
== LFACE_FOREGROUND_INDEX
1217 || target_index
== LFACE_BACKGROUND_INDEX
1218 || target_index
== LFACE_UNDERLINE_INDEX
1219 || target_index
== LFACE_OVERLINE_INDEX
1220 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1221 || target_index
== LFACE_BOX_INDEX
);
1223 /* if the color map is full, defined_color will return a best match
1224 to the values in an existing cell. */
1225 if (!defined_color (f
, SSDATA (name
), &color
, 1))
1227 add_to_log ("Unable to load color \"%s\"", name
, Qnil
);
1229 switch (target_index
)
1231 case LFACE_FOREGROUND_INDEX
:
1232 face
->foreground_defaulted_p
= 1;
1233 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1236 case LFACE_BACKGROUND_INDEX
:
1237 face
->background_defaulted_p
= 1;
1238 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1241 case LFACE_UNDERLINE_INDEX
:
1242 face
->underline_defaulted_p
= 1;
1243 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1246 case LFACE_OVERLINE_INDEX
:
1247 face
->overline_color_defaulted_p
= 1;
1248 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1251 case LFACE_STRIKE_THROUGH_INDEX
:
1252 face
->strike_through_color_defaulted_p
= 1;
1253 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1256 case LFACE_BOX_INDEX
:
1257 face
->box_color_defaulted_p
= 1;
1258 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1267 ++ncolors_allocated
;
1274 #ifdef HAVE_WINDOW_SYSTEM
1276 /* Load colors for face FACE which is used on frame F. Colors are
1277 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1278 of ATTRS. If the background color specified is not supported on F,
1279 try to emulate gray colors with a stipple from Vface_default_stipple. */
1282 load_face_colors (struct frame
*f
, struct face
*face
,
1283 Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
1287 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1288 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1290 /* Swap colors if face is inverse-video. */
1291 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1299 /* Check for support for foreground, not for background because
1300 face_color_supported_p is smart enough to know that grays are
1301 "supported" as background because we are supposed to use stipple
1303 if (!face_color_supported_p (f
, SSDATA (bg
), 0)
1304 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1306 x_destroy_bitmap (f
, face
->stipple
);
1307 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1308 &face
->pixmap_w
, &face
->pixmap_h
);
1311 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1312 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1316 /* Free color PIXEL on frame F. */
1319 unload_color (struct frame
*f
, long unsigned int pixel
)
1321 #ifdef HAVE_X_WINDOWS
1325 x_free_colors (f
, &pixel
, 1);
1332 /* Free colors allocated for FACE. */
1335 free_face_colors (struct frame
*f
, struct face
*face
)
1337 /* PENDING(NS): need to do something here? */
1338 #ifdef HAVE_X_WINDOWS
1339 if (face
->colors_copied_bitwise_p
)
1344 if (!face
->foreground_defaulted_p
)
1346 x_free_colors (f
, &face
->foreground
, 1);
1347 IF_DEBUG (--ncolors_allocated
);
1350 if (!face
->background_defaulted_p
)
1352 x_free_colors (f
, &face
->background
, 1);
1353 IF_DEBUG (--ncolors_allocated
);
1356 if (face
->underline_p
1357 && !face
->underline_defaulted_p
)
1359 x_free_colors (f
, &face
->underline_color
, 1);
1360 IF_DEBUG (--ncolors_allocated
);
1363 if (face
->overline_p
1364 && !face
->overline_color_defaulted_p
)
1366 x_free_colors (f
, &face
->overline_color
, 1);
1367 IF_DEBUG (--ncolors_allocated
);
1370 if (face
->strike_through_p
1371 && !face
->strike_through_color_defaulted_p
)
1373 x_free_colors (f
, &face
->strike_through_color
, 1);
1374 IF_DEBUG (--ncolors_allocated
);
1377 if (face
->box
!= FACE_NO_BOX
1378 && !face
->box_color_defaulted_p
)
1380 x_free_colors (f
, &face
->box_color
, 1);
1381 IF_DEBUG (--ncolors_allocated
);
1385 #endif /* HAVE_X_WINDOWS */
1388 #endif /* HAVE_WINDOW_SYSTEM */
1392 /***********************************************************************
1394 ***********************************************************************/
1396 /* An enumerator for each field of an XLFD font name. */
1417 /* An enumerator for each possible slant value of a font. Taken from
1418 the XLFD specification. */
1426 XLFD_SLANT_REVERSE_ITALIC
,
1427 XLFD_SLANT_REVERSE_OBLIQUE
,
1431 /* Relative font weight according to XLFD documentation. */
1435 XLFD_WEIGHT_UNKNOWN
,
1436 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1437 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1438 XLFD_WEIGHT_LIGHT
, /* 30 */
1439 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1440 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1441 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1442 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1443 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1444 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1447 /* Relative proportionate width. */
1451 XLFD_SWIDTH_UNKNOWN
,
1452 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1453 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1454 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1455 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1456 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1457 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1458 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1459 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1460 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1463 /* Order by which font selection chooses fonts. The default values
1464 mean `first, find a best match for the font width, then for the
1465 font height, then for weight, then for slant.' This variable can be
1466 set via set-face-font-sort-order. */
1468 static int font_sort_order
[4];
1470 #ifdef HAVE_WINDOW_SYSTEM
1472 static enum font_property_index font_props_for_sorting
[FONT_SIZE_INDEX
];
1475 compare_fonts_by_sort_order (const void *v1
, const void *v2
)
1477 Lisp_Object
const *p1
= v1
;
1478 Lisp_Object
const *p2
= v2
;
1479 Lisp_Object font1
= *p1
;
1480 Lisp_Object font2
= *p2
;
1483 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1485 enum font_property_index idx
= font_props_for_sorting
[i
];
1486 Lisp_Object val1
= AREF (font1
, idx
), val2
= AREF (font2
, idx
);
1489 if (idx
<= FONT_REGISTRY_INDEX
)
1492 result
= STRINGP (val2
) ? strcmp (SSDATA (val1
), SSDATA (val2
)) : -1;
1494 result
= STRINGP (val2
) ? 1 : 0;
1498 if (INTEGERP (val1
))
1499 result
= (INTEGERP (val2
) && XINT (val1
) >= XINT (val2
)
1500 ? XINT (val1
) > XINT (val2
)
1503 result
= INTEGERP (val2
) ? 1 : 0;
1511 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
1512 doc
: /* Return a list of available fonts of family FAMILY on FRAME.
1513 If FAMILY is omitted or nil, list all families.
1514 Otherwise, FAMILY must be a string, possibly containing wildcards
1516 If FRAME is omitted or nil, use the selected frame.
1517 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
1518 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
1519 FAMILY is the font family name. POINT-SIZE is the size of the
1520 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
1521 width, weight and slant of the font. These symbols are the same as for
1522 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
1523 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
1524 giving the registry and encoding of the font.
1525 The result list is sorted according to the current setting of
1526 the face font sort order. */)
1527 (Lisp_Object family
, Lisp_Object frame
)
1529 Lisp_Object font_spec
, list
, *drivers
, vec
;
1530 struct frame
*f
= decode_live_frame (frame
);
1531 ptrdiff_t i
, nfonts
;
1536 font_spec
= Ffont_spec (0, NULL
);
1539 CHECK_STRING (family
);
1540 font_parse_family_registry (family
, Qnil
, font_spec
);
1543 list
= font_list_entities (f
, font_spec
);
1547 /* Sort the font entities. */
1548 for (i
= 0; i
< 4; i
++)
1549 switch (font_sort_order
[i
])
1552 font_props_for_sorting
[i
] = FONT_WIDTH_INDEX
; break;
1553 case XLFD_POINT_SIZE
:
1554 font_props_for_sorting
[i
] = FONT_SIZE_INDEX
; break;
1556 font_props_for_sorting
[i
] = FONT_WEIGHT_INDEX
; break;
1558 font_props_for_sorting
[i
] = FONT_SLANT_INDEX
; break;
1560 font_props_for_sorting
[i
++] = FONT_FAMILY_INDEX
;
1561 font_props_for_sorting
[i
++] = FONT_FOUNDRY_INDEX
;
1562 font_props_for_sorting
[i
++] = FONT_ADSTYLE_INDEX
;
1563 font_props_for_sorting
[i
++] = FONT_REGISTRY_INDEX
;
1565 ndrivers
= XINT (Flength (list
));
1566 SAFE_ALLOCA_LISP (drivers
, ndrivers
);
1567 for (i
= 0; i
< ndrivers
; i
++, list
= XCDR (list
))
1568 drivers
[i
] = XCAR (list
);
1569 vec
= Fvconcat (ndrivers
, drivers
);
1570 nfonts
= ASIZE (vec
);
1572 qsort (XVECTOR (vec
)->contents
, nfonts
, word_size
,
1573 compare_fonts_by_sort_order
);
1576 for (i
= nfonts
- 1; i
>= 0; --i
)
1578 Lisp_Object font
= AREF (vec
, i
);
1579 Lisp_Object v
= make_uninit_vector (8);
1581 Lisp_Object spacing
;
1583 ASET (v
, 0, AREF (font
, FONT_FAMILY_INDEX
));
1584 ASET (v
, 1, FONT_WIDTH_SYMBOLIC (font
));
1585 point
= PIXEL_TO_POINT (XINT (AREF (font
, FONT_SIZE_INDEX
)) * 10,
1587 ASET (v
, 2, make_number (point
));
1588 ASET (v
, 3, FONT_WEIGHT_SYMBOLIC (font
));
1589 ASET (v
, 4, FONT_SLANT_SYMBOLIC (font
));
1590 spacing
= Ffont_get (font
, QCspacing
);
1591 ASET (v
, 5, (NILP (spacing
) || EQ (spacing
, Qp
)) ? Qnil
: Qt
);
1592 ASET (v
, 6, Ffont_xlfd_name (font
, Qnil
));
1593 ASET (v
, 7, AREF (font
, FONT_REGISTRY_INDEX
));
1595 result
= Fcons (v
, result
);
1602 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
1603 doc
: /* Return a list of the names of available fonts matching PATTERN.
1604 If optional arguments FACE and FRAME are specified, return only fonts
1605 the same size as FACE on FRAME.
1607 PATTERN should be a string containing a font name in the XLFD,
1608 Fontconfig, or GTK format. A font name given in the XLFD format may
1609 contain wildcard characters:
1610 the * character matches any substring, and
1611 the ? character matches any single character.
1612 PATTERN is case-insensitive.
1614 The return value is a list of strings, suitable as arguments to
1617 Fonts Emacs can't use may or may not be excluded
1618 even if they match PATTERN and FACE.
1619 The optional fourth argument MAXIMUM sets a limit on how many
1620 fonts to match. The first MAXIMUM fonts are reported.
1621 The optional fifth argument WIDTH, if specified, is a number of columns
1622 occupied by a character of a font. In that case, return only fonts
1623 the WIDTH times as wide as FACE on FRAME. */)
1624 (Lisp_Object pattern
, Lisp_Object face
, Lisp_Object frame
,
1625 Lisp_Object maximum
, Lisp_Object width
)
1628 int size
, avgwidth
IF_LINT (= 0);
1630 check_window_system (NULL
);
1631 CHECK_STRING (pattern
);
1633 if (! NILP (maximum
))
1634 CHECK_NATNUM (maximum
);
1637 CHECK_NUMBER (width
);
1639 /* We can't simply call decode_window_system_frame because
1640 this function may be called before any frame is created. */
1641 f
= decode_live_frame (frame
);
1642 if (! FRAME_WINDOW_P (f
))
1644 /* Perhaps we have not yet created any frame. */
1650 XSETFRAME (frame
, f
);
1652 /* Determine the width standard for comparison with the fonts we find. */
1658 /* This is of limited utility since it works with character
1659 widths. Keep it for compatibility. --gerd. */
1660 int face_id
= lookup_named_face (f
, face
, 0);
1661 struct face
*width_face
= (face_id
< 0
1663 : FACE_FROM_ID (f
, face_id
));
1665 if (width_face
&& width_face
->font
)
1667 size
= width_face
->font
->pixel_size
;
1668 avgwidth
= width_face
->font
->average_width
;
1672 size
= FRAME_FONT (f
)->pixel_size
;
1673 avgwidth
= FRAME_FONT (f
)->average_width
;
1676 avgwidth
*= XINT (width
);
1680 Lisp_Object font_spec
;
1681 Lisp_Object args
[2], tail
;
1683 font_spec
= font_spec_from_name (pattern
);
1684 if (!FONTP (font_spec
))
1685 signal_error ("Invalid font name", pattern
);
1689 Ffont_put (font_spec
, QCsize
, make_number (size
));
1690 Ffont_put (font_spec
, QCavgwidth
, make_number (avgwidth
));
1692 args
[0] = Flist_fonts (font_spec
, frame
, maximum
, font_spec
);
1693 for (tail
= args
[0]; CONSP (tail
); tail
= XCDR (tail
))
1695 Lisp_Object font_entity
;
1697 font_entity
= XCAR (tail
);
1698 if ((NILP (AREF (font_entity
, FONT_SIZE_INDEX
))
1699 || XINT (AREF (font_entity
, FONT_SIZE_INDEX
)) == 0)
1700 && ! NILP (AREF (font_spec
, FONT_SIZE_INDEX
)))
1702 /* This is a scalable font. For backward compatibility,
1703 we set the specified size. */
1704 font_entity
= copy_font_spec (font_entity
);
1705 ASET (font_entity
, FONT_SIZE_INDEX
,
1706 AREF (font_spec
, FONT_SIZE_INDEX
));
1708 XSETCAR (tail
, Ffont_xlfd_name (font_entity
, Qnil
));
1711 /* We don't have to check fontsets. */
1713 args
[1] = list_fontsets (f
, pattern
, size
);
1714 return Fnconc (2, args
);
1718 #endif /* HAVE_WINDOW_SYSTEM */
1721 /***********************************************************************
1723 ***********************************************************************/
1725 /* Access face attributes of face LFACE, a Lisp vector. */
1727 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
1728 #define LFACE_FOUNDRY(LFACE) AREF ((LFACE), LFACE_FOUNDRY_INDEX)
1729 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
1730 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
1731 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
1732 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
1733 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
1734 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
1735 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
1736 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
1737 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
1738 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
1739 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
1740 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
1741 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
1742 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
1743 #define LFACE_FONTSET(LFACE) AREF ((LFACE), LFACE_FONTSET_INDEX)
1745 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
1746 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
1748 #define LFACEP(LFACE) \
1750 && ASIZE (LFACE) == LFACE_VECTOR_SIZE \
1751 && EQ (AREF (LFACE, 0), Qface))
1756 /* Check consistency of Lisp face attribute vector ATTRS. */
1759 check_lface_attrs (Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
1761 eassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
1762 || IGNORE_DEFFACE_P (attrs
[LFACE_FAMILY_INDEX
])
1763 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
1764 eassert (UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
1765 || IGNORE_DEFFACE_P (attrs
[LFACE_FOUNDRY_INDEX
])
1766 || STRINGP (attrs
[LFACE_FOUNDRY_INDEX
]));
1767 eassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
1768 || IGNORE_DEFFACE_P (attrs
[LFACE_SWIDTH_INDEX
])
1769 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
1770 eassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
1771 || IGNORE_DEFFACE_P (attrs
[LFACE_HEIGHT_INDEX
])
1772 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
])
1773 || FLOATP (attrs
[LFACE_HEIGHT_INDEX
])
1774 || FUNCTIONP (attrs
[LFACE_HEIGHT_INDEX
]));
1775 eassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
1776 || IGNORE_DEFFACE_P (attrs
[LFACE_WEIGHT_INDEX
])
1777 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
1778 eassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
1779 || IGNORE_DEFFACE_P (attrs
[LFACE_SLANT_INDEX
])
1780 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
1781 eassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
1782 || IGNORE_DEFFACE_P (attrs
[LFACE_UNDERLINE_INDEX
])
1783 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
1784 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
])
1785 || CONSP (attrs
[LFACE_UNDERLINE_INDEX
]));
1786 eassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
1787 || IGNORE_DEFFACE_P (attrs
[LFACE_OVERLINE_INDEX
])
1788 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
1789 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
1790 eassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1791 || IGNORE_DEFFACE_P (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1792 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1793 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
1794 eassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
1795 || IGNORE_DEFFACE_P (attrs
[LFACE_BOX_INDEX
])
1796 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
1797 || STRINGP (attrs
[LFACE_BOX_INDEX
])
1798 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
1799 || CONSP (attrs
[LFACE_BOX_INDEX
]));
1800 eassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
1801 || IGNORE_DEFFACE_P (attrs
[LFACE_INVERSE_INDEX
])
1802 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
1803 eassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
1804 || IGNORE_DEFFACE_P (attrs
[LFACE_FOREGROUND_INDEX
])
1805 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
1806 eassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
1807 || IGNORE_DEFFACE_P (attrs
[LFACE_BACKGROUND_INDEX
])
1808 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
1809 eassert (UNSPECIFIEDP (attrs
[LFACE_INHERIT_INDEX
])
1810 || IGNORE_DEFFACE_P (attrs
[LFACE_INHERIT_INDEX
])
1811 || NILP (attrs
[LFACE_INHERIT_INDEX
])
1812 || SYMBOLP (attrs
[LFACE_INHERIT_INDEX
])
1813 || CONSP (attrs
[LFACE_INHERIT_INDEX
]));
1814 #ifdef HAVE_WINDOW_SYSTEM
1815 eassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
1816 || IGNORE_DEFFACE_P (attrs
[LFACE_STIPPLE_INDEX
])
1817 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
1818 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
1819 eassert (UNSPECIFIEDP (attrs
[LFACE_FONT_INDEX
])
1820 || IGNORE_DEFFACE_P (attrs
[LFACE_FONT_INDEX
])
1821 || FONTP (attrs
[LFACE_FONT_INDEX
]));
1822 eassert (UNSPECIFIEDP (attrs
[LFACE_FONTSET_INDEX
])
1823 || STRINGP (attrs
[LFACE_FONTSET_INDEX
])
1824 || NILP (attrs
[LFACE_FONTSET_INDEX
]));
1829 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
1832 check_lface (Lisp_Object lface
)
1836 eassert (LFACEP (lface
));
1837 check_lface_attrs (XVECTOR (lface
)->contents
);
1841 #else /* not GLYPH_DEBUG */
1843 #define check_lface_attrs(attrs) (void) 0
1844 #define check_lface(lface) (void) 0
1846 #endif /* GLYPH_DEBUG */
1850 /* Face-merge cycle checking. */
1852 enum named_merge_point_kind
1854 NAMED_MERGE_POINT_NORMAL
,
1855 NAMED_MERGE_POINT_REMAP
1858 /* A `named merge point' is simply a point during face-merging where we
1859 look up a face by name. We keep a stack of which named lookups we're
1860 currently processing so that we can easily detect cycles, using a
1861 linked- list of struct named_merge_point structures, typically
1862 allocated on the stack frame of the named lookup functions which are
1863 active (so no consing is required). */
1864 struct named_merge_point
1866 Lisp_Object face_name
;
1867 enum named_merge_point_kind named_merge_point_kind
;
1868 struct named_merge_point
*prev
;
1872 /* If a face merging cycle is detected for FACE_NAME, return 0,
1873 otherwise add NEW_NAMED_MERGE_POINT, which is initialized using
1874 FACE_NAME and NAMED_MERGE_POINT_KIND, as the head of the linked list
1875 pointed to by NAMED_MERGE_POINTS, and return 1. */
1878 push_named_merge_point (struct named_merge_point
*new_named_merge_point
,
1879 Lisp_Object face_name
,
1880 enum named_merge_point_kind named_merge_point_kind
,
1881 struct named_merge_point
**named_merge_points
)
1883 struct named_merge_point
*prev
;
1885 for (prev
= *named_merge_points
; prev
; prev
= prev
->prev
)
1886 if (EQ (face_name
, prev
->face_name
))
1888 if (prev
->named_merge_point_kind
== named_merge_point_kind
)
1889 /* A cycle, so fail. */
1891 else if (prev
->named_merge_point_kind
== NAMED_MERGE_POINT_REMAP
)
1892 /* A remap `hides ' any previous normal merge points
1893 (because the remap means that it's actually different face),
1894 so as we know the current merge point must be normal, we
1895 can just assume it's OK. */
1899 new_named_merge_point
->face_name
= face_name
;
1900 new_named_merge_point
->named_merge_point_kind
= named_merge_point_kind
;
1901 new_named_merge_point
->prev
= *named_merge_points
;
1903 *named_merge_points
= new_named_merge_point
;
1909 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
1910 to make it a symbol. If FACE_NAME is an alias for another face,
1911 return that face's name.
1913 Return default face in case of errors. */
1916 resolve_face_name (Lisp_Object face_name
, int signal_p
)
1918 Lisp_Object orig_face
;
1919 Lisp_Object tortoise
, hare
;
1921 if (STRINGP (face_name
))
1922 face_name
= intern (SSDATA (face_name
));
1924 if (NILP (face_name
) || !SYMBOLP (face_name
))
1927 orig_face
= face_name
;
1928 tortoise
= hare
= face_name
;
1933 hare
= Fget (hare
, Qface_alias
);
1934 if (NILP (hare
) || !SYMBOLP (hare
))
1938 hare
= Fget (hare
, Qface_alias
);
1939 if (NILP (hare
) || !SYMBOLP (hare
))
1942 tortoise
= Fget (tortoise
, Qface_alias
);
1943 if (EQ (hare
, tortoise
))
1946 xsignal1 (Qcircular_list
, orig_face
);
1955 /* Return the face definition of FACE_NAME on frame F. F null means
1956 return the definition for new frames. FACE_NAME may be a string or
1957 a symbol (apparently Emacs 20.2 allowed strings as face names in
1958 face text properties; Ediff uses that). If SIGNAL_P is non-zero,
1959 signal an error if FACE_NAME is not a valid face name. If SIGNAL_P
1960 is zero, value is nil if FACE_NAME is not a valid face name. */
1962 lface_from_face_name_no_resolve (struct frame
*f
, Lisp_Object face_name
,
1968 lface
= assq_no_quit (face_name
, f
->face_alist
);
1970 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
1973 lface
= XCDR (lface
);
1975 signal_error ("Invalid face", face_name
);
1977 check_lface (lface
);
1982 /* Return the face definition of FACE_NAME on frame F. F null means
1983 return the definition for new frames. FACE_NAME may be a string or
1984 a symbol (apparently Emacs 20.2 allowed strings as face names in
1985 face text properties; Ediff uses that). If FACE_NAME is an alias
1986 for another face, return that face's definition. If SIGNAL_P is
1987 non-zero, signal an error if FACE_NAME is not a valid face name.
1988 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
1991 lface_from_face_name (struct frame
*f
, Lisp_Object face_name
, int signal_p
)
1993 face_name
= resolve_face_name (face_name
, signal_p
);
1994 return lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
1998 /* Get face attributes of face FACE_NAME from frame-local faces on
1999 frame F. Store the resulting attributes in ATTRS which must point
2000 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
2001 is non-zero, signal an error if FACE_NAME does not name a face.
2002 Otherwise, value is zero if FACE_NAME is not a face. */
2005 get_lface_attributes_no_remap (struct frame
*f
, Lisp_Object face_name
,
2006 Lisp_Object attrs
[LFACE_VECTOR_SIZE
],
2011 lface
= lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2014 memcpy (attrs
, XVECTOR (lface
)->contents
,
2015 LFACE_VECTOR_SIZE
* sizeof *attrs
);
2017 return !NILP (lface
);
2020 /* Get face attributes of face FACE_NAME from frame-local faces on frame
2021 F. Store the resulting attributes in ATTRS which must point to a
2022 vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If FACE_NAME is an
2023 alias for another face, use that face's definition. If SIGNAL_P is
2024 non-zero, signal an error if FACE_NAME does not name a face.
2025 Otherwise, value is zero if FACE_NAME is not a face. */
2028 get_lface_attributes (struct frame
*f
, Lisp_Object face_name
,
2029 Lisp_Object attrs
[LFACE_VECTOR_SIZE
], int signal_p
,
2030 struct named_merge_point
*named_merge_points
)
2032 Lisp_Object face_remapping
;
2034 face_name
= resolve_face_name (face_name
, signal_p
);
2036 /* See if SYMBOL has been remapped to some other face (usually this
2037 is done buffer-locally). */
2038 face_remapping
= assq_no_quit (face_name
, Vface_remapping_alist
);
2039 if (CONSP (face_remapping
))
2041 struct named_merge_point named_merge_point
;
2043 if (push_named_merge_point (&named_merge_point
,
2044 face_name
, NAMED_MERGE_POINT_REMAP
,
2045 &named_merge_points
))
2049 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2050 attrs
[i
] = Qunspecified
;
2052 return merge_face_ref (f
, XCDR (face_remapping
), attrs
,
2053 signal_p
, named_merge_points
);
2057 /* Default case, no remapping. */
2058 return get_lface_attributes_no_remap (f
, face_name
, attrs
, signal_p
);
2062 /* Non-zero if all attributes in face attribute vector ATTRS are
2063 specified, i.e. are non-nil. */
2066 lface_fully_specified_p (Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
2070 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2071 if (i
!= LFACE_FONT_INDEX
&& i
!= LFACE_INHERIT_INDEX
)
2072 if ((UNSPECIFIEDP (attrs
[i
]) || IGNORE_DEFFACE_P (attrs
[i
])))
2075 return i
== LFACE_VECTOR_SIZE
;
2078 #ifdef HAVE_WINDOW_SYSTEM
2080 /* Set font-related attributes of Lisp face LFACE from FONT-OBJECT.
2081 If FORCE_P is zero, set only unspecified attributes of LFACE. The
2082 exception is `font' attribute. It is set to FONT_OBJECT regardless
2086 set_lface_from_font (struct frame
*f
, Lisp_Object lface
,
2087 Lisp_Object font_object
, int force_p
)
2090 struct font
*font
= XFONT_OBJECT (font_object
);
2092 /* Set attributes only if unspecified, otherwise face defaults for
2093 new frames would never take effect. If the font doesn't have a
2094 specific property, set a normal value for that. */
2096 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
2098 Lisp_Object family
= AREF (font_object
, FONT_FAMILY_INDEX
);
2100 ASET (lface
, LFACE_FAMILY_INDEX
, SYMBOL_NAME (family
));
2103 if (force_p
|| UNSPECIFIEDP (LFACE_FOUNDRY (lface
)))
2105 Lisp_Object foundry
= AREF (font_object
, FONT_FOUNDRY_INDEX
);
2107 ASET (lface
, LFACE_FOUNDRY_INDEX
, SYMBOL_NAME (foundry
));
2110 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
2112 int pt
= PIXEL_TO_POINT (font
->pixel_size
* 10, FRAME_RES_Y (f
));
2115 ASET (lface
, LFACE_HEIGHT_INDEX
, make_number (pt
));
2118 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
2120 val
= FONT_WEIGHT_FOR_FACE (font_object
);
2121 ASET (lface
, LFACE_WEIGHT_INDEX
, ! NILP (val
) ? val
:Qnormal
);
2123 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
2125 val
= FONT_SLANT_FOR_FACE (font_object
);
2126 ASET (lface
, LFACE_SLANT_INDEX
, ! NILP (val
) ? val
: Qnormal
);
2128 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
2130 val
= FONT_WIDTH_FOR_FACE (font_object
);
2131 ASET (lface
, LFACE_SWIDTH_INDEX
, ! NILP (val
) ? val
: Qnormal
);
2134 ASET (lface
, LFACE_FONT_INDEX
, font_object
);
2138 #endif /* HAVE_WINDOW_SYSTEM */
2141 /* Merges the face height FROM with the face height TO, and returns the
2142 merged height. If FROM is an invalid height, then INVALID is
2143 returned instead. FROM and TO may be either absolute face heights or
2144 `relative' heights; the returned value is always an absolute height
2145 unless both FROM and TO are relative. */
2148 merge_face_heights (Lisp_Object from
, Lisp_Object to
, Lisp_Object invalid
)
2150 Lisp_Object result
= invalid
;
2152 if (INTEGERP (from
))
2153 /* FROM is absolute, just use it as is. */
2155 else if (FLOATP (from
))
2156 /* FROM is a scale, use it to adjust TO. */
2159 /* relative X absolute => absolute */
2160 result
= make_number (XFLOAT_DATA (from
) * XINT (to
));
2161 else if (FLOATP (to
))
2162 /* relative X relative => relative */
2163 result
= make_float (XFLOAT_DATA (from
) * XFLOAT_DATA (to
));
2164 else if (UNSPECIFIEDP (to
))
2167 else if (FUNCTIONP (from
))
2168 /* FROM is a function, which use to adjust TO. */
2170 /* Call function with current height as argument.
2171 From is the new height. */
2172 result
= safe_call1 (from
, to
);
2174 /* Ensure that if TO was absolute, so is the result. */
2175 if (INTEGERP (to
) && !INTEGERP (result
))
2183 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
2184 store the resulting attributes in TO, which must be already be
2185 completely specified and contain only absolute attributes. Every
2186 specified attribute of FROM overrides the corresponding attribute of
2187 TO; relative attributes in FROM are merged with the absolute value in
2188 TO and replace it. NAMED_MERGE_POINTS is used internally to detect
2189 loops in face inheritance/remapping; it should be 0 when called from
2193 merge_face_vectors (struct frame
*f
, Lisp_Object
*from
, Lisp_Object
*to
,
2194 struct named_merge_point
*named_merge_points
)
2197 Lisp_Object font
= Qnil
;
2199 /* If FROM inherits from some other faces, merge their attributes into
2200 TO before merging FROM's direct attributes. Note that an :inherit
2201 attribute of `unspecified' is the same as one of nil; we never
2202 merge :inherit attributes, so nil is more correct, but lots of
2203 other code uses `unspecified' as a generic value for face attributes. */
2204 if (!UNSPECIFIEDP (from
[LFACE_INHERIT_INDEX
])
2205 && !NILP (from
[LFACE_INHERIT_INDEX
]))
2206 merge_face_ref (f
, from
[LFACE_INHERIT_INDEX
], to
, 0, named_merge_points
);
2208 if (FONT_SPEC_P (from
[LFACE_FONT_INDEX
]))
2210 if (!UNSPECIFIEDP (to
[LFACE_FONT_INDEX
]))
2211 font
= merge_font_spec (from
[LFACE_FONT_INDEX
], to
[LFACE_FONT_INDEX
]);
2213 font
= copy_font_spec (from
[LFACE_FONT_INDEX
]);
2214 to
[LFACE_FONT_INDEX
] = font
;
2217 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2218 if (!UNSPECIFIEDP (from
[i
]))
2220 if (i
== LFACE_HEIGHT_INDEX
&& !INTEGERP (from
[i
]))
2222 to
[i
] = merge_face_heights (from
[i
], to
[i
], to
[i
]);
2223 font_clear_prop (to
, FONT_SIZE_INDEX
);
2225 else if (i
!= LFACE_FONT_INDEX
&& ! EQ (to
[i
], from
[i
]))
2228 if (i
>= LFACE_FAMILY_INDEX
&& i
<=LFACE_SLANT_INDEX
)
2229 font_clear_prop (to
,
2230 (i
== LFACE_FAMILY_INDEX
? FONT_FAMILY_INDEX
2231 : i
== LFACE_FOUNDRY_INDEX
? FONT_FOUNDRY_INDEX
2232 : i
== LFACE_SWIDTH_INDEX
? FONT_WIDTH_INDEX
2233 : i
== LFACE_HEIGHT_INDEX
? FONT_SIZE_INDEX
2234 : i
== LFACE_WEIGHT_INDEX
? FONT_WEIGHT_INDEX
2235 : FONT_SLANT_INDEX
));
2239 /* If FROM specifies a font spec, make its contents take precedence
2240 over :family and other attributes. This is needed for face
2241 remapping using :font to work. */
2245 if (! NILP (AREF (font
, FONT_FOUNDRY_INDEX
)))
2246 to
[LFACE_FOUNDRY_INDEX
] = SYMBOL_NAME (AREF (font
, FONT_FOUNDRY_INDEX
));
2247 if (! NILP (AREF (font
, FONT_FAMILY_INDEX
)))
2248 to
[LFACE_FAMILY_INDEX
] = SYMBOL_NAME (AREF (font
, FONT_FAMILY_INDEX
));
2249 if (! NILP (AREF (font
, FONT_WEIGHT_INDEX
)))
2250 to
[LFACE_WEIGHT_INDEX
] = FONT_WEIGHT_FOR_FACE (font
);
2251 if (! NILP (AREF (font
, FONT_SLANT_INDEX
)))
2252 to
[LFACE_SLANT_INDEX
] = FONT_SLANT_FOR_FACE (font
);
2253 if (! NILP (AREF (font
, FONT_WIDTH_INDEX
)))
2254 to
[LFACE_SWIDTH_INDEX
] = FONT_WIDTH_FOR_FACE (font
);
2255 ASET (font
, FONT_SIZE_INDEX
, Qnil
);
2258 /* TO is always an absolute face, which should inherit from nothing.
2259 We blindly copy the :inherit attribute above and fix it up here. */
2260 to
[LFACE_INHERIT_INDEX
] = Qnil
;
2263 /* Merge the named face FACE_NAME on frame F, into the vector of face
2264 attributes TO. NAMED_MERGE_POINTS is used to detect loops in face
2265 inheritance. Returns true if FACE_NAME is a valid face name and
2266 merging succeeded. */
2269 merge_named_face (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*to
,
2270 struct named_merge_point
*named_merge_points
)
2272 struct named_merge_point named_merge_point
;
2274 if (push_named_merge_point (&named_merge_point
,
2275 face_name
, NAMED_MERGE_POINT_NORMAL
,
2276 &named_merge_points
))
2278 struct gcpro gcpro1
;
2279 Lisp_Object from
[LFACE_VECTOR_SIZE
];
2280 int ok
= get_lface_attributes (f
, face_name
, from
, 0, named_merge_points
);
2284 GCPRO1 (named_merge_point
.face_name
);
2285 merge_face_vectors (f
, from
, to
, named_merge_points
);
2296 /* Merge face attributes from the lisp `face reference' FACE_REF on
2297 frame F into the face attribute vector TO. If ERR_MSGS is non-zero,
2298 problems with FACE_REF cause an error message to be shown. Return
2299 non-zero if no errors occurred (regardless of the value of ERR_MSGS).
2300 NAMED_MERGE_POINTS is used to detect loops in face inheritance or
2301 list structure; it may be 0 for most callers.
2303 FACE_REF may be a single face specification or a list of such
2304 specifications. Each face specification can be:
2306 1. A symbol or string naming a Lisp face.
2308 2. A property list of the form (KEYWORD VALUE ...) where each
2309 KEYWORD is a face attribute name, and value is an appropriate value
2312 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
2313 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
2314 for compatibility with 20.2.
2316 Face specifications earlier in lists take precedence over later
2320 merge_face_ref (struct frame
*f
, Lisp_Object face_ref
, Lisp_Object
*to
,
2321 int err_msgs
, struct named_merge_point
*named_merge_points
)
2323 int ok
= 1; /* Succeed without an error? */
2325 if (CONSP (face_ref
))
2327 Lisp_Object first
= XCAR (face_ref
);
2329 if (EQ (first
, Qforeground_color
)
2330 || EQ (first
, Qbackground_color
))
2332 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
2333 . COLOR). COLOR must be a string. */
2334 Lisp_Object color_name
= XCDR (face_ref
);
2335 Lisp_Object color
= first
;
2337 if (STRINGP (color_name
))
2339 if (EQ (color
, Qforeground_color
))
2340 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
2342 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
2347 add_to_log ("Invalid face color", color_name
, Qnil
);
2351 else if (SYMBOLP (first
)
2352 && *SDATA (SYMBOL_NAME (first
)) == ':')
2354 /* Assume this is the property list form. */
2355 while (CONSP (face_ref
) && CONSP (XCDR (face_ref
)))
2357 Lisp_Object keyword
= XCAR (face_ref
);
2358 Lisp_Object value
= XCAR (XCDR (face_ref
));
2361 /* Specifying `unspecified' is a no-op. */
2362 if (EQ (value
, Qunspecified
))
2364 else if (EQ (keyword
, QCfamily
))
2366 if (STRINGP (value
))
2368 to
[LFACE_FAMILY_INDEX
] = value
;
2369 font_clear_prop (to
, FONT_FAMILY_INDEX
);
2374 else if (EQ (keyword
, QCfoundry
))
2376 if (STRINGP (value
))
2378 to
[LFACE_FOUNDRY_INDEX
] = value
;
2379 font_clear_prop (to
, FONT_FOUNDRY_INDEX
);
2384 else if (EQ (keyword
, QCheight
))
2386 Lisp_Object new_height
=
2387 merge_face_heights (value
, to
[LFACE_HEIGHT_INDEX
], Qnil
);
2389 if (! NILP (new_height
))
2391 to
[LFACE_HEIGHT_INDEX
] = new_height
;
2392 font_clear_prop (to
, FONT_SIZE_INDEX
);
2397 else if (EQ (keyword
, QCweight
))
2399 if (SYMBOLP (value
) && FONT_WEIGHT_NAME_NUMERIC (value
) >= 0)
2401 to
[LFACE_WEIGHT_INDEX
] = value
;
2402 font_clear_prop (to
, FONT_WEIGHT_INDEX
);
2407 else if (EQ (keyword
, QCslant
))
2409 if (SYMBOLP (value
) && FONT_SLANT_NAME_NUMERIC (value
) >= 0)
2411 to
[LFACE_SLANT_INDEX
] = value
;
2412 font_clear_prop (to
, FONT_SLANT_INDEX
);
2417 else if (EQ (keyword
, QCunderline
))
2423 to
[LFACE_UNDERLINE_INDEX
] = value
;
2427 else if (EQ (keyword
, QCoverline
))
2432 to
[LFACE_OVERLINE_INDEX
] = value
;
2436 else if (EQ (keyword
, QCstrike_through
))
2441 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
2445 else if (EQ (keyword
, QCbox
))
2448 value
= make_number (1);
2449 if (INTEGERP (value
)
2453 to
[LFACE_BOX_INDEX
] = value
;
2457 else if (EQ (keyword
, QCinverse_video
)
2458 || EQ (keyword
, QCreverse_video
))
2460 if (EQ (value
, Qt
) || NILP (value
))
2461 to
[LFACE_INVERSE_INDEX
] = value
;
2465 else if (EQ (keyword
, QCforeground
))
2467 if (STRINGP (value
))
2468 to
[LFACE_FOREGROUND_INDEX
] = value
;
2472 else if (EQ (keyword
, QCbackground
))
2474 if (STRINGP (value
))
2475 to
[LFACE_BACKGROUND_INDEX
] = value
;
2479 else if (EQ (keyword
, QCstipple
))
2481 #if defined (HAVE_WINDOW_SYSTEM)
2482 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
2483 if (!NILP (pixmap_p
))
2484 to
[LFACE_STIPPLE_INDEX
] = value
;
2487 #endif /* HAVE_WINDOW_SYSTEM */
2489 else if (EQ (keyword
, QCwidth
))
2491 if (SYMBOLP (value
) && FONT_WIDTH_NAME_NUMERIC (value
) >= 0)
2493 to
[LFACE_SWIDTH_INDEX
] = value
;
2494 font_clear_prop (to
, FONT_WIDTH_INDEX
);
2499 else if (EQ (keyword
, QCfont
))
2502 to
[LFACE_FONT_INDEX
] = value
;
2506 else if (EQ (keyword
, QCinherit
))
2508 /* This is not really very useful; it's just like a
2509 normal face reference. */
2510 if (! merge_face_ref (f
, value
, to
,
2511 err_msgs
, named_merge_points
))
2519 add_to_log ("Invalid face attribute %S %S", keyword
, value
);
2523 face_ref
= XCDR (XCDR (face_ref
));
2528 /* This is a list of face refs. Those at the beginning of the
2529 list take precedence over what follows, so we have to merge
2530 from the end backwards. */
2531 Lisp_Object next
= XCDR (face_ref
);
2534 ok
= merge_face_ref (f
, next
, to
, err_msgs
, named_merge_points
);
2536 if (! merge_face_ref (f
, first
, to
, err_msgs
, named_merge_points
))
2542 /* FACE_REF ought to be a face name. */
2543 ok
= merge_named_face (f
, face_ref
, to
, named_merge_points
);
2544 if (!ok
&& err_msgs
)
2545 add_to_log ("Invalid face reference: %s", face_ref
, Qnil
);
2552 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
2553 Sinternal_make_lisp_face
, 1, 2, 0,
2554 doc
: /* Make FACE, a symbol, a Lisp face with all attributes nil.
2555 If FACE was not known as a face before, create a new one.
2556 If optional argument FRAME is specified, make a frame-local face
2557 for that frame. Otherwise operate on the global face definition.
2558 Value is a vector of face attributes. */)
2559 (Lisp_Object face
, Lisp_Object frame
)
2561 Lisp_Object global_lface
, lface
;
2565 CHECK_SYMBOL (face
);
2566 global_lface
= lface_from_face_name (NULL
, face
, 0);
2570 CHECK_LIVE_FRAME (frame
);
2572 lface
= lface_from_face_name (f
, face
, 0);
2575 f
= NULL
, lface
= Qnil
;
2577 /* Add a global definition if there is none. */
2578 if (NILP (global_lface
))
2580 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2582 ASET (global_lface
, 0, Qface
);
2583 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
2584 Vface_new_frame_defaults
);
2586 /* Assign the new Lisp face a unique ID. The mapping from Lisp
2587 face id to Lisp face is given by the vector lface_id_to_name.
2588 The mapping from Lisp face to Lisp face id is given by the
2589 property `face' of the Lisp face name. */
2590 if (next_lface_id
== lface_id_to_name_size
)
2592 xpalloc (lface_id_to_name
, &lface_id_to_name_size
, 1, MAX_FACE_ID
,
2593 sizeof *lface_id_to_name
);
2595 lface_id_to_name
[next_lface_id
] = face
;
2596 Fput (face
, Qface
, make_number (next_lface_id
));
2600 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2601 ASET (global_lface
, i
, Qunspecified
);
2603 /* Add a frame-local definition. */
2608 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2610 ASET (lface
, 0, Qface
);
2611 fset_face_alist (f
, Fcons (Fcons (face
, lface
), f
->face_alist
));
2614 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2615 ASET (lface
, i
, Qunspecified
);
2618 lface
= global_lface
;
2620 /* Changing a named face means that all realized faces depending on
2621 that face are invalid. Since we cannot tell which realized faces
2622 depend on the face, make sure they are all removed. This is done
2623 by incrementing face_change_count. The next call to
2624 init_iterator will then free realized faces. */
2625 if (NILP (Fget (face
, Qface_no_inherit
)))
2627 ++face_change_count
;
2628 ++windows_or_buffers_changed
;
2631 eassert (LFACEP (lface
));
2632 check_lface (lface
);
2637 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
2638 Sinternal_lisp_face_p
, 1, 2, 0,
2639 doc
: /* Return non-nil if FACE names a face.
2640 FACE should be a symbol or string.
2641 If optional second argument FRAME is non-nil, check for the
2642 existence of a frame-local face with name FACE on that frame.
2643 Otherwise check for the existence of a global face. */)
2644 (Lisp_Object face
, Lisp_Object frame
)
2648 face
= resolve_face_name (face
, 1);
2652 CHECK_LIVE_FRAME (frame
);
2653 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2656 lface
= lface_from_face_name (NULL
, face
, 0);
2662 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
2663 Sinternal_copy_lisp_face
, 4, 4, 0,
2664 doc
: /* Copy face FROM to TO.
2665 If FRAME is t, copy the global face definition of FROM.
2666 Otherwise, copy the frame-local definition of FROM on FRAME.
2667 If NEW-FRAME is a frame, copy that data into the frame-local
2668 definition of TO on NEW-FRAME. If NEW-FRAME is nil,
2669 FRAME controls where the data is copied to.
2671 The value is TO. */)
2672 (Lisp_Object from
, Lisp_Object to
, Lisp_Object frame
, Lisp_Object new_frame
)
2674 Lisp_Object lface
, copy
;
2676 CHECK_SYMBOL (from
);
2681 /* Copy global definition of FROM. We don't make copies of
2682 strings etc. because 20.2 didn't do it either. */
2683 lface
= lface_from_face_name (NULL
, from
, 1);
2684 copy
= Finternal_make_lisp_face (to
, Qnil
);
2688 /* Copy frame-local definition of FROM. */
2689 if (NILP (new_frame
))
2691 CHECK_LIVE_FRAME (frame
);
2692 CHECK_LIVE_FRAME (new_frame
);
2693 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
2694 copy
= Finternal_make_lisp_face (to
, new_frame
);
2697 vcopy (copy
, 0, XVECTOR (lface
)->contents
, LFACE_VECTOR_SIZE
);
2699 /* Changing a named face means that all realized faces depending on
2700 that face are invalid. Since we cannot tell which realized faces
2701 depend on the face, make sure they are all removed. This is done
2702 by incrementing face_change_count. The next call to
2703 init_iterator will then free realized faces. */
2704 if (NILP (Fget (to
, Qface_no_inherit
)))
2706 ++face_change_count
;
2707 ++windows_or_buffers_changed
;
2714 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
2715 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
2716 doc
: /* Set attribute ATTR of FACE to VALUE.
2717 FRAME being a frame means change the face on that frame.
2718 FRAME nil means change the face of the selected frame.
2719 FRAME t means change the default for new frames.
2720 FRAME 0 means change the face on all frames, and change the default
2722 (Lisp_Object face
, Lisp_Object attr
, Lisp_Object value
, Lisp_Object frame
)
2725 Lisp_Object old_value
= Qnil
;
2726 /* Set one of enum font_property_index (> 0) if ATTR is one of
2727 font-related attributes other than QCfont and QCfontset. */
2728 enum font_property_index prop_index
= 0;
2730 CHECK_SYMBOL (face
);
2731 CHECK_SYMBOL (attr
);
2733 face
= resolve_face_name (face
, 1);
2735 /* If FRAME is 0, change face on all frames, and change the
2736 default for new frames. */
2737 if (INTEGERP (frame
) && XINT (frame
) == 0)
2740 Finternal_set_lisp_face_attribute (face
, attr
, value
, Qt
);
2741 FOR_EACH_FRAME (tail
, frame
)
2742 Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
2746 /* Set lface to the Lisp attribute vector of FACE. */
2749 lface
= lface_from_face_name (NULL
, face
, 1);
2751 /* When updating face-new-frame-defaults, we put :ignore-defface
2752 where the caller wants `unspecified'. This forces the frame
2753 defaults to ignore the defface value. Otherwise, the defface
2754 will take effect, which is generally not what is intended.
2755 The value of that attribute will be inherited from some other
2756 face during face merging. See internal_merge_in_global_face. */
2757 if (UNSPECIFIEDP (value
))
2758 value
= QCignore_defface
;
2763 frame
= selected_frame
;
2765 CHECK_LIVE_FRAME (frame
);
2766 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2768 /* If a frame-local face doesn't exist yet, create one. */
2770 lface
= Finternal_make_lisp_face (face
, frame
);
2773 if (EQ (attr
, QCfamily
))
2775 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2777 CHECK_STRING (value
);
2778 if (SCHARS (value
) == 0)
2779 signal_error ("Invalid face family", value
);
2781 old_value
= LFACE_FAMILY (lface
);
2782 ASET (lface
, LFACE_FAMILY_INDEX
, value
);
2783 prop_index
= FONT_FAMILY_INDEX
;
2785 else if (EQ (attr
, QCfoundry
))
2787 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2789 CHECK_STRING (value
);
2790 if (SCHARS (value
) == 0)
2791 signal_error ("Invalid face foundry", value
);
2793 old_value
= LFACE_FOUNDRY (lface
);
2794 ASET (lface
, LFACE_FOUNDRY_INDEX
, value
);
2795 prop_index
= FONT_FOUNDRY_INDEX
;
2797 else if (EQ (attr
, QCheight
))
2799 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2801 if (EQ (face
, Qdefault
))
2803 /* The default face must have an absolute size. */
2804 if (!INTEGERP (value
) || XINT (value
) <= 0)
2805 signal_error ("Default face height not absolute and positive",
2810 /* For non-default faces, do a test merge with a random
2811 height to see if VALUE's ok. */
2812 Lisp_Object test
= merge_face_heights (value
,
2815 if (!INTEGERP (test
) || XINT (test
) <= 0)
2816 signal_error ("Face height does not produce a positive integer",
2821 old_value
= LFACE_HEIGHT (lface
);
2822 ASET (lface
, LFACE_HEIGHT_INDEX
, value
);
2823 prop_index
= FONT_SIZE_INDEX
;
2825 else if (EQ (attr
, QCweight
))
2827 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2829 CHECK_SYMBOL (value
);
2830 if (FONT_WEIGHT_NAME_NUMERIC (value
) < 0)
2831 signal_error ("Invalid face weight", value
);
2833 old_value
= LFACE_WEIGHT (lface
);
2834 ASET (lface
, LFACE_WEIGHT_INDEX
, value
);
2835 prop_index
= FONT_WEIGHT_INDEX
;
2837 else if (EQ (attr
, QCslant
))
2839 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2841 CHECK_SYMBOL (value
);
2842 if (FONT_SLANT_NAME_NUMERIC (value
) < 0)
2843 signal_error ("Invalid face slant", value
);
2845 old_value
= LFACE_SLANT (lface
);
2846 ASET (lface
, LFACE_SLANT_INDEX
, value
);
2847 prop_index
= FONT_SLANT_INDEX
;
2849 else if (EQ (attr
, QCunderline
))
2853 if (UNSPECIFIEDP (value
) || IGNORE_DEFFACE_P (value
))
2855 else if (NILP (value
) || EQ (value
, Qt
))
2857 else if (STRINGP (value
) && SCHARS (value
) > 0)
2859 else if (CONSP (value
))
2861 Lisp_Object key
, val
, list
;
2864 /* FIXME? This errs on the side of acceptance. Eg it accepts:
2865 (defface foo '((t :underline 'foo) "doc")
2866 Maybe this is intentional, maybe it isn't.
2867 Non-nil symbols other than t are not documented as being valid.
2868 Eg compare with inverse-video, which explicitly rejects them.
2872 while (!NILP (CAR_SAFE(list
)))
2874 key
= CAR_SAFE (list
);
2875 list
= CDR_SAFE (list
);
2876 val
= CAR_SAFE (list
);
2877 list
= CDR_SAFE (list
);
2879 if (NILP (key
) || NILP (val
))
2885 else if (EQ (key
, QCcolor
)
2886 && !(EQ (val
, Qforeground_color
)
2887 || (STRINGP (val
) && SCHARS (val
) > 0)))
2893 else if (EQ (key
, QCstyle
)
2894 && !(EQ (val
, Qline
) || EQ (val
, Qwave
)))
2903 signal_error ("Invalid face underline", value
);
2905 old_value
= LFACE_UNDERLINE (lface
);
2906 ASET (lface
, LFACE_UNDERLINE_INDEX
, value
);
2908 else if (EQ (attr
, QCoverline
))
2910 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2911 if ((SYMBOLP (value
)
2913 && !EQ (value
, Qnil
))
2914 /* Overline color. */
2916 && SCHARS (value
) == 0))
2917 signal_error ("Invalid face overline", value
);
2919 old_value
= LFACE_OVERLINE (lface
);
2920 ASET (lface
, LFACE_OVERLINE_INDEX
, value
);
2922 else if (EQ (attr
, QCstrike_through
))
2924 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2925 if ((SYMBOLP (value
)
2927 && !EQ (value
, Qnil
))
2928 /* Strike-through color. */
2930 && SCHARS (value
) == 0))
2931 signal_error ("Invalid face strike-through", value
);
2933 old_value
= LFACE_STRIKE_THROUGH (lface
);
2934 ASET (lface
, LFACE_STRIKE_THROUGH_INDEX
, value
);
2936 else if (EQ (attr
, QCbox
))
2940 /* Allow t meaning a simple box of width 1 in foreground color
2943 value
= make_number (1);
2945 if (UNSPECIFIEDP (value
) || IGNORE_DEFFACE_P (value
))
2947 else if (NILP (value
))
2949 else if (INTEGERP (value
))
2950 valid_p
= XINT (value
) != 0;
2951 else if (STRINGP (value
))
2952 valid_p
= SCHARS (value
) > 0;
2953 else if (CONSP (value
))
2969 if (EQ (k
, QCline_width
))
2971 if (!INTEGERP (v
) || XINT (v
) == 0)
2974 else if (EQ (k
, QCcolor
))
2976 if (!NILP (v
) && (!STRINGP (v
) || SCHARS (v
) == 0))
2979 else if (EQ (k
, QCstyle
))
2981 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
2988 valid_p
= NILP (tem
);
2994 signal_error ("Invalid face box", value
);
2996 old_value
= LFACE_BOX (lface
);
2997 ASET (lface
, LFACE_BOX_INDEX
, value
);
2999 else if (EQ (attr
, QCinverse_video
)
3000 || EQ (attr
, QCreverse_video
))
3002 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3004 CHECK_SYMBOL (value
);
3005 if (!EQ (value
, Qt
) && !NILP (value
))
3006 signal_error ("Invalid inverse-video face attribute value", value
);
3008 old_value
= LFACE_INVERSE (lface
);
3009 ASET (lface
, LFACE_INVERSE_INDEX
, value
);
3011 else if (EQ (attr
, QCforeground
))
3013 /* Compatibility with 20.x. */
3015 value
= Qunspecified
;
3016 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3018 /* Don't check for valid color names here because it depends
3019 on the frame (display) whether the color will be valid
3020 when the face is realized. */
3021 CHECK_STRING (value
);
3022 if (SCHARS (value
) == 0)
3023 signal_error ("Empty foreground color value", value
);
3025 old_value
= LFACE_FOREGROUND (lface
);
3026 ASET (lface
, LFACE_FOREGROUND_INDEX
, value
);
3028 else if (EQ (attr
, QCbackground
))
3030 /* Compatibility with 20.x. */
3032 value
= Qunspecified
;
3033 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3035 /* Don't check for valid color names here because it depends
3036 on the frame (display) whether the color will be valid
3037 when the face is realized. */
3038 CHECK_STRING (value
);
3039 if (SCHARS (value
) == 0)
3040 signal_error ("Empty background color value", value
);
3042 old_value
= LFACE_BACKGROUND (lface
);
3043 ASET (lface
, LFACE_BACKGROUND_INDEX
, value
);
3045 else if (EQ (attr
, QCstipple
))
3047 #if defined (HAVE_WINDOW_SYSTEM)
3048 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3050 && NILP (Fbitmap_spec_p (value
)))
3051 signal_error ("Invalid stipple attribute", value
);
3052 old_value
= LFACE_STIPPLE (lface
);
3053 ASET (lface
, LFACE_STIPPLE_INDEX
, value
);
3054 #endif /* HAVE_WINDOW_SYSTEM */
3056 else if (EQ (attr
, QCwidth
))
3058 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3060 CHECK_SYMBOL (value
);
3061 if (FONT_WIDTH_NAME_NUMERIC (value
) < 0)
3062 signal_error ("Invalid face width", value
);
3064 old_value
= LFACE_SWIDTH (lface
);
3065 ASET (lface
, LFACE_SWIDTH_INDEX
, value
);
3066 prop_index
= FONT_WIDTH_INDEX
;
3068 else if (EQ (attr
, QCfont
))
3070 #ifdef HAVE_WINDOW_SYSTEM
3071 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3073 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3077 old_value
= LFACE_FONT (lface
);
3078 if (! FONTP (value
))
3080 if (STRINGP (value
))
3082 Lisp_Object name
= value
;
3083 int fontset
= fs_query_fontset (name
, 0);
3086 name
= fontset_ascii (fontset
);
3087 value
= font_spec_from_name (name
);
3089 signal_error ("Invalid font name", name
);
3092 signal_error ("Invalid font or font-spec", value
);
3095 f
= XFRAME (selected_frame
);
3098 if (! FONT_OBJECT_P (value
))
3100 Lisp_Object
*attrs
= XVECTOR (lface
)->contents
;
3101 Lisp_Object font_object
;
3103 font_object
= font_load_for_lface (f
, attrs
, value
);
3104 if (NILP (font_object
))
3105 signal_error ("Font not available", value
);
3106 value
= font_object
;
3108 set_lface_from_font (f
, lface
, value
, 1);
3111 ASET (lface
, LFACE_FONT_INDEX
, value
);
3113 #endif /* HAVE_WINDOW_SYSTEM */
3115 else if (EQ (attr
, QCfontset
))
3117 #ifdef HAVE_WINDOW_SYSTEM
3118 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3122 old_value
= LFACE_FONTSET (lface
);
3123 tmp
= Fquery_fontset (value
, Qnil
);
3125 signal_error ("Invalid fontset name", value
);
3126 ASET (lface
, LFACE_FONTSET_INDEX
, value
= tmp
);
3128 #endif /* HAVE_WINDOW_SYSTEM */
3130 else if (EQ (attr
, QCinherit
))
3133 if (SYMBOLP (value
))
3136 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
3137 if (!SYMBOLP (XCAR (tail
)))
3140 ASET (lface
, LFACE_INHERIT_INDEX
, value
);
3142 signal_error ("Invalid face inheritance", value
);
3144 else if (EQ (attr
, QCbold
))
3146 old_value
= LFACE_WEIGHT (lface
);
3147 ASET (lface
, LFACE_WEIGHT_INDEX
, NILP (value
) ? Qnormal
: Qbold
);
3148 prop_index
= FONT_WEIGHT_INDEX
;
3150 else if (EQ (attr
, QCitalic
))
3153 old_value
= LFACE_SLANT (lface
);
3154 ASET (lface
, LFACE_SLANT_INDEX
, NILP (value
) ? Qnormal
: Qitalic
);
3155 prop_index
= FONT_SLANT_INDEX
;
3158 signal_error ("Invalid face attribute name", attr
);
3162 /* If a font-related attribute other than QCfont and QCfontset
3163 is specified, and if the original QCfont attribute has a font
3164 (font-spec or font-object), set the corresponding property in
3165 the font to nil so that the font selector doesn't think that
3166 the attribute is mandatory. Also, clear the average
3168 font_clear_prop (XVECTOR (lface
)->contents
, prop_index
);
3171 /* Changing a named face means that all realized faces depending on
3172 that face are invalid. Since we cannot tell which realized faces
3173 depend on the face, make sure they are all removed. This is done
3174 by incrementing face_change_count. The next call to
3175 init_iterator will then free realized faces. */
3177 && NILP (Fget (face
, Qface_no_inherit
))
3178 && NILP (Fequal (old_value
, value
)))
3180 ++face_change_count
;
3181 ++windows_or_buffers_changed
;
3184 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3185 && NILP (Fequal (old_value
, value
)))
3191 if (EQ (face
, Qdefault
))
3193 #ifdef HAVE_WINDOW_SYSTEM
3194 /* Changed font-related attributes of the `default' face are
3195 reflected in changed `font' frame parameters. */
3197 && (prop_index
|| EQ (attr
, QCfont
))
3198 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
3199 set_font_frame_param (frame
, lface
);
3201 #endif /* HAVE_WINDOW_SYSTEM */
3203 if (EQ (attr
, QCforeground
))
3204 param
= Qforeground_color
;
3205 else if (EQ (attr
, QCbackground
))
3206 param
= Qbackground_color
;
3208 #ifdef HAVE_WINDOW_SYSTEM
3210 else if (EQ (face
, Qscroll_bar
))
3212 /* Changing the colors of `scroll-bar' sets frame parameters
3213 `scroll-bar-foreground' and `scroll-bar-background'. */
3214 if (EQ (attr
, QCforeground
))
3215 param
= Qscroll_bar_foreground
;
3216 else if (EQ (attr
, QCbackground
))
3217 param
= Qscroll_bar_background
;
3219 #endif /* not HAVE_NTGUI */
3220 else if (EQ (face
, Qborder
))
3222 /* Changing background color of `border' sets frame parameter
3224 if (EQ (attr
, QCbackground
))
3225 param
= Qborder_color
;
3227 else if (EQ (face
, Qcursor
))
3229 /* Changing background color of `cursor' sets frame parameter
3231 if (EQ (attr
, QCbackground
))
3232 param
= Qcursor_color
;
3234 else if (EQ (face
, Qmouse
))
3236 /* Changing background color of `mouse' sets frame parameter
3238 if (EQ (attr
, QCbackground
))
3239 param
= Qmouse_color
;
3241 #endif /* HAVE_WINDOW_SYSTEM */
3242 else if (EQ (face
, Qmenu
))
3244 /* Indicate that we have to update the menu bar when realizing
3245 faces on FRAME. FRAME t change the default for new frames.
3246 We do this by setting the flag in new face caches. */
3249 struct frame
*f
= XFRAME (frame
);
3250 if (FRAME_FACE_CACHE (f
) == NULL
)
3251 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
3252 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 1;
3255 menu_face_changed_default
= 1;
3261 /* Update `default-frame-alist', which is used for new frames. */
3263 store_in_alist (&Vdefault_frame_alist
, param
, value
);
3266 /* Update the current frame's parameters. */
3269 cons
= XCAR (Vparam_value_alist
);
3270 XSETCAR (cons
, param
);
3271 XSETCDR (cons
, value
);
3272 Fmodify_frame_parameters (frame
, Vparam_value_alist
);
3281 /* Update the corresponding face when frame parameter PARAM on frame F
3282 has been assigned the value NEW_VALUE. */
3285 update_face_from_frame_parameter (struct frame
*f
, Lisp_Object param
,
3286 Lisp_Object new_value
)
3288 Lisp_Object face
= Qnil
;
3291 /* If there are no faces yet, give up. This is the case when called
3292 from Fx_create_frame, and we do the necessary things later in
3293 face-set-after-frame-defaults. */
3294 if (NILP (f
->face_alist
))
3297 if (EQ (param
, Qforeground_color
))
3300 lface
= lface_from_face_name (f
, face
, 1);
3301 ASET (lface
, LFACE_FOREGROUND_INDEX
,
3302 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3303 realize_basic_faces (f
);
3305 else if (EQ (param
, Qbackground_color
))
3309 /* Changing the background color might change the background
3310 mode, so that we have to load new defface specs.
3311 Call frame-set-background-mode to do that. */
3312 XSETFRAME (frame
, f
);
3313 call1 (Qframe_set_background_mode
, frame
);
3316 lface
= lface_from_face_name (f
, face
, 1);
3317 ASET (lface
, LFACE_BACKGROUND_INDEX
,
3318 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3319 realize_basic_faces (f
);
3321 #ifdef HAVE_WINDOW_SYSTEM
3322 else if (EQ (param
, Qborder_color
))
3325 lface
= lface_from_face_name (f
, face
, 1);
3326 ASET (lface
, LFACE_BACKGROUND_INDEX
,
3327 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3329 else if (EQ (param
, Qcursor_color
))
3332 lface
= lface_from_face_name (f
, face
, 1);
3333 ASET (lface
, LFACE_BACKGROUND_INDEX
,
3334 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3336 else if (EQ (param
, Qmouse_color
))
3339 lface
= lface_from_face_name (f
, face
, 1);
3340 ASET (lface
, LFACE_BACKGROUND_INDEX
,
3341 (STRINGP (new_value
) ? new_value
: Qunspecified
));
3345 /* Changing a named face means that all realized faces depending on
3346 that face are invalid. Since we cannot tell which realized faces
3347 depend on the face, make sure they are all removed. This is done
3348 by incrementing face_change_count. The next call to
3349 init_iterator will then free realized faces. */
3351 && NILP (Fget (face
, Qface_no_inherit
)))
3353 ++face_change_count
;
3354 ++windows_or_buffers_changed
;
3359 #ifdef HAVE_WINDOW_SYSTEM
3361 /* Set the `font' frame parameter of FRAME determined from the
3362 font-object set in `default' face attributes LFACE. */
3365 set_font_frame_param (Lisp_Object frame
, Lisp_Object lface
)
3367 struct frame
*f
= XFRAME (frame
);
3370 if (FRAME_WINDOW_P (f
)
3371 /* Don't do anything if the font is `unspecified'. This can
3372 happen during frame creation. */
3373 && (font
= LFACE_FONT (lface
),
3374 ! UNSPECIFIEDP (font
)))
3376 if (FONT_SPEC_P (font
))
3378 font
= font_load_for_lface (f
, XVECTOR (lface
)->contents
, font
);
3381 ASET (lface
, LFACE_FONT_INDEX
, font
);
3383 f
->default_face_done_p
= 0;
3384 Fmodify_frame_parameters (frame
, list1 (Fcons (Qfont
, font
)));
3388 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
3389 Sinternal_face_x_get_resource
, 2, 3, 0,
3390 doc
: /* Get the value of X resource RESOURCE, class CLASS.
3391 Returned value is for the display of frame FRAME. If FRAME is not
3392 specified or nil, use selected frame. This function exists because
3393 ordinary `x-get-resource' doesn't take a frame argument. */)
3394 (Lisp_Object resource
, Lisp_Object
class, Lisp_Object frame
)
3396 Lisp_Object value
= Qnil
;
3399 CHECK_STRING (resource
);
3400 CHECK_STRING (class);
3401 f
= decode_live_frame (frame
);
3403 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (f
),
3404 resource
, class, Qnil
, Qnil
);
3410 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
3411 If VALUE is "on" or "true", return t. If VALUE is "off" or
3412 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
3413 error; if SIGNAL_P is zero, return 0. */
3416 face_boolean_x_resource_value (Lisp_Object value
, int signal_p
)
3418 Lisp_Object result
= make_number (0);
3420 eassert (STRINGP (value
));
3422 if (xstrcasecmp (SSDATA (value
), "on") == 0
3423 || xstrcasecmp (SSDATA (value
), "true") == 0)
3425 else if (xstrcasecmp (SSDATA (value
), "off") == 0
3426 || xstrcasecmp (SSDATA (value
), "false") == 0)
3428 else if (xstrcasecmp (SSDATA (value
), "unspecified") == 0)
3429 result
= Qunspecified
;
3431 signal_error ("Invalid face attribute value from X resource", value
);
3437 DEFUN ("internal-set-lisp-face-attribute-from-resource",
3438 Finternal_set_lisp_face_attribute_from_resource
,
3439 Sinternal_set_lisp_face_attribute_from_resource
,
3440 3, 4, 0, doc
: /* */)
3441 (Lisp_Object face
, Lisp_Object attr
, Lisp_Object value
, Lisp_Object frame
)
3443 CHECK_SYMBOL (face
);
3444 CHECK_SYMBOL (attr
);
3445 CHECK_STRING (value
);
3447 if (xstrcasecmp (SSDATA (value
), "unspecified") == 0)
3448 value
= Qunspecified
;
3449 else if (EQ (attr
, QCheight
))
3451 value
= Fstring_to_number (value
, make_number (10));
3452 if (XINT (value
) <= 0)
3453 signal_error ("Invalid face height from X resource", value
);
3455 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
3456 value
= face_boolean_x_resource_value (value
, 1);
3457 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
3458 value
= intern (SSDATA (value
));
3459 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
3460 value
= face_boolean_x_resource_value (value
, 1);
3461 else if (EQ (attr
, QCunderline
)
3462 || EQ (attr
, QCoverline
)
3463 || EQ (attr
, QCstrike_through
))
3465 Lisp_Object boolean_value
;
3467 /* If the result of face_boolean_x_resource_value is t or nil,
3468 VALUE does NOT specify a color. */
3469 boolean_value
= face_boolean_x_resource_value (value
, 0);
3470 if (SYMBOLP (boolean_value
))
3471 value
= boolean_value
;
3473 else if (EQ (attr
, QCbox
) || EQ (attr
, QCinherit
))
3474 value
= Fcar (Fread_from_string (value
, Qnil
, Qnil
));
3476 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3479 #endif /* HAVE_WINDOW_SYSTEM */
3482 /***********************************************************************
3484 ***********************************************************************/
3486 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
3488 /* Make menus on frame F appear as specified by the `menu' face. */
3491 x_update_menu_appearance (struct frame
*f
)
3493 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3497 && (rdb
= XrmGetDatabase (FRAME_X_DISPLAY (f
)),
3502 ptrdiff_t bufsize
= sizeof line
;
3503 Lisp_Object lface
= lface_from_face_name (f
, Qmenu
, 1);
3504 struct face
*face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
3505 const char *myname
= SSDATA (Vx_resource_name
);
3508 const char *popup_path
= "popup_menu";
3510 const char *popup_path
= "menu.popup";
3513 if (STRINGP (LFACE_FOREGROUND (lface
)))
3515 exprintf (&buf
, &bufsize
, line
, -1, "%s.%s*foreground: %s",
3517 SDATA (LFACE_FOREGROUND (lface
)));
3518 XrmPutLineResource (&rdb
, line
);
3519 exprintf (&buf
, &bufsize
, line
, -1, "%s.pane.menubar*foreground: %s",
3520 myname
, SDATA (LFACE_FOREGROUND (lface
)));
3521 XrmPutLineResource (&rdb
, line
);
3525 if (STRINGP (LFACE_BACKGROUND (lface
)))
3527 exprintf (&buf
, &bufsize
, line
, -1, "%s.%s*background: %s",
3529 SDATA (LFACE_BACKGROUND (lface
)));
3530 XrmPutLineResource (&rdb
, line
);
3532 exprintf (&buf
, &bufsize
, line
, -1, "%s.pane.menubar*background: %s",
3533 myname
, SDATA (LFACE_BACKGROUND (lface
)));
3534 XrmPutLineResource (&rdb
, line
);
3539 /* On Solaris 5.8, it's been reported that the `menu' face
3540 can be unspecified here, during startup. Why this
3541 happens remains unknown. -- cyd */
3542 && FONTP (LFACE_FONT (lface
))
3543 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
3544 || !UNSPECIFIEDP (LFACE_FOUNDRY (lface
))
3545 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
3546 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3547 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
3548 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
3550 Lisp_Object xlfd
= Ffont_xlfd_name (LFACE_FONT (lface
), Qnil
);
3552 const char *suffix
= "List";
3555 #if defined HAVE_X_I18N
3557 const char *suffix
= "Set";
3559 const char *suffix
= "";
3566 #if defined HAVE_X_I18N
3567 char *fontsetname
= xic_create_fontsetname (SSDATA (xlfd
), motif
);
3569 char *fontsetname
= SSDATA (xlfd
);
3571 exprintf (&buf
, &bufsize
, line
, -1, "%s.pane.menubar*font%s: %s",
3572 myname
, suffix
, fontsetname
);
3573 XrmPutLineResource (&rdb
, line
);
3575 exprintf (&buf
, &bufsize
, line
, -1, "%s.%s*font%s: %s",
3576 myname
, popup_path
, suffix
, fontsetname
);
3577 XrmPutLineResource (&rdb
, line
);
3579 if (fontsetname
!= SSDATA (xlfd
))
3580 xfree (fontsetname
);
3584 if (changed_p
&& f
->output_data
.x
->menubar_widget
)
3585 free_frame_menubar (f
);
3592 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
3595 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p
,
3596 Sface_attribute_relative_p
,
3598 doc
: /* Check whether a face attribute value is relative.
3599 Specifically, this function returns t if the attribute ATTRIBUTE
3600 with the value VALUE is relative.
3602 A relative value is one that doesn't entirely override whatever is
3603 inherited from another face. For most possible attributes,
3604 the only relative value that users see is `unspecified'.
3605 However, for :height, floating point values are also relative. */)
3606 (Lisp_Object attribute
, Lisp_Object value
)
3608 if (EQ (value
, Qunspecified
) || (EQ (value
, QCignore_defface
)))
3610 else if (EQ (attribute
, QCheight
))
3611 return INTEGERP (value
) ? Qnil
: Qt
;
3616 DEFUN ("merge-face-attribute", Fmerge_face_attribute
, Smerge_face_attribute
,
3618 doc
: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
3619 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
3620 the result will be absolute, otherwise it will be relative. */)
3621 (Lisp_Object attribute
, Lisp_Object value1
, Lisp_Object value2
)
3623 if (EQ (value1
, Qunspecified
) || EQ (value1
, QCignore_defface
))
3625 else if (EQ (attribute
, QCheight
))
3626 return merge_face_heights (value1
, value2
, value1
);
3632 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
3633 Sinternal_get_lisp_face_attribute
,
3635 doc
: /* Return face attribute KEYWORD of face SYMBOL.
3636 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
3637 face attribute name, signal an error.
3638 If the optional argument FRAME is given, report on face SYMBOL in that
3639 frame. If FRAME is t, report on the defaults for face SYMBOL (for new
3640 frames). If FRAME is omitted or nil, use the selected frame. */)
3641 (Lisp_Object symbol
, Lisp_Object keyword
, Lisp_Object frame
)
3643 struct frame
*f
= EQ (frame
, Qt
) ? NULL
: decode_live_frame (frame
);
3644 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 1), value
= Qnil
;
3646 CHECK_SYMBOL (symbol
);
3647 CHECK_SYMBOL (keyword
);
3649 if (EQ (keyword
, QCfamily
))
3650 value
= LFACE_FAMILY (lface
);
3651 else if (EQ (keyword
, QCfoundry
))
3652 value
= LFACE_FOUNDRY (lface
);
3653 else if (EQ (keyword
, QCheight
))
3654 value
= LFACE_HEIGHT (lface
);
3655 else if (EQ (keyword
, QCweight
))
3656 value
= LFACE_WEIGHT (lface
);
3657 else if (EQ (keyword
, QCslant
))
3658 value
= LFACE_SLANT (lface
);
3659 else if (EQ (keyword
, QCunderline
))
3660 value
= LFACE_UNDERLINE (lface
);
3661 else if (EQ (keyword
, QCoverline
))
3662 value
= LFACE_OVERLINE (lface
);
3663 else if (EQ (keyword
, QCstrike_through
))
3664 value
= LFACE_STRIKE_THROUGH (lface
);
3665 else if (EQ (keyword
, QCbox
))
3666 value
= LFACE_BOX (lface
);
3667 else if (EQ (keyword
, QCinverse_video
)
3668 || EQ (keyword
, QCreverse_video
))
3669 value
= LFACE_INVERSE (lface
);
3670 else if (EQ (keyword
, QCforeground
))
3671 value
= LFACE_FOREGROUND (lface
);
3672 else if (EQ (keyword
, QCbackground
))
3673 value
= LFACE_BACKGROUND (lface
);
3674 else if (EQ (keyword
, QCstipple
))
3675 value
= LFACE_STIPPLE (lface
);
3676 else if (EQ (keyword
, QCwidth
))
3677 value
= LFACE_SWIDTH (lface
);
3678 else if (EQ (keyword
, QCinherit
))
3679 value
= LFACE_INHERIT (lface
);
3680 else if (EQ (keyword
, QCfont
))
3681 value
= LFACE_FONT (lface
);
3682 else if (EQ (keyword
, QCfontset
))
3683 value
= LFACE_FONTSET (lface
);
3685 signal_error ("Invalid face attribute name", keyword
);
3687 if (IGNORE_DEFFACE_P (value
))
3688 return Qunspecified
;
3694 DEFUN ("internal-lisp-face-attribute-values",
3695 Finternal_lisp_face_attribute_values
,
3696 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
3697 doc
: /* Return a list of valid discrete values for face attribute ATTR.
3698 Value is nil if ATTR doesn't have a discrete set of valid values. */)
3701 Lisp_Object result
= Qnil
;
3703 CHECK_SYMBOL (attr
);
3705 if (EQ (attr
, QCunderline
) || EQ (attr
, QCoverline
)
3706 || EQ (attr
, QCstrike_through
)
3707 || EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
3708 result
= list2 (Qt
, Qnil
);
3714 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
3715 Sinternal_merge_in_global_face
, 2, 2, 0,
3716 doc
: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
3717 Default face attributes override any local face attributes. */)
3718 (Lisp_Object face
, Lisp_Object frame
)
3721 Lisp_Object global_lface
, local_lface
, *gvec
, *lvec
;
3722 struct frame
*f
= XFRAME (frame
);
3724 CHECK_LIVE_FRAME (frame
);
3725 global_lface
= lface_from_face_name (NULL
, face
, 1);
3726 local_lface
= lface_from_face_name (f
, face
, 0);
3727 if (NILP (local_lface
))
3728 local_lface
= Finternal_make_lisp_face (face
, frame
);
3730 /* Make every specified global attribute override the local one.
3731 BEWARE!! This is only used from `face-set-after-frame-default' where
3732 the local frame is defined from default specs in `face-defface-spec'
3733 and those should be overridden by global settings. Hence the strange
3734 "global before local" priority. */
3735 lvec
= XVECTOR (local_lface
)->contents
;
3736 gvec
= XVECTOR (global_lface
)->contents
;
3737 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3738 if (IGNORE_DEFFACE_P (gvec
[i
]))
3739 ASET (local_lface
, i
, Qunspecified
);
3740 else if (! UNSPECIFIEDP (gvec
[i
]))
3741 ASET (local_lface
, i
, AREF (global_lface
, i
));
3743 /* If the default face was changed, update the face cache and the
3744 `font' frame parameter. */
3745 if (EQ (face
, Qdefault
))
3747 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
3748 struct face
*newface
, *oldface
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
3749 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
3751 /* This can be NULL (e.g., in batch mode). */
3754 /* Ensure that the face vector is fully specified by merging
3755 the previously-cached vector. */
3756 memcpy (attrs
, oldface
->lface
, sizeof attrs
);
3757 merge_face_vectors (f
, lvec
, attrs
, 0);
3758 vcopy (local_lface
, 0, attrs
, LFACE_VECTOR_SIZE
);
3759 newface
= realize_face (c
, lvec
, DEFAULT_FACE_ID
);
3761 if ((! UNSPECIFIEDP (gvec
[LFACE_FAMILY_INDEX
])
3762 || ! UNSPECIFIEDP (gvec
[LFACE_FOUNDRY_INDEX
])
3763 || ! UNSPECIFIEDP (gvec
[LFACE_HEIGHT_INDEX
])
3764 || ! UNSPECIFIEDP (gvec
[LFACE_WEIGHT_INDEX
])
3765 || ! UNSPECIFIEDP (gvec
[LFACE_SLANT_INDEX
])
3766 || ! UNSPECIFIEDP (gvec
[LFACE_SWIDTH_INDEX
])
3767 || ! UNSPECIFIEDP (gvec
[LFACE_FONT_INDEX
]))
3770 Lisp_Object name
= newface
->font
->props
[FONT_NAME_INDEX
];
3771 Fmodify_frame_parameters (frame
, list1 (Fcons (Qfont
, name
)));
3774 if (STRINGP (gvec
[LFACE_FOREGROUND_INDEX
]))
3775 Fmodify_frame_parameters (frame
,
3776 list1 (Fcons (Qforeground_color
,
3777 gvec
[LFACE_FOREGROUND_INDEX
])));
3779 if (STRINGP (gvec
[LFACE_BACKGROUND_INDEX
]))
3780 Fmodify_frame_parameters (frame
,
3781 list1 (Fcons (Qbackground_color
,
3782 gvec
[LFACE_BACKGROUND_INDEX
])));
3790 /* The following function is implemented for compatibility with 20.2.
3791 The function is used in x-resolve-fonts when it is asked to
3792 return fonts with the same size as the font of a face. This is
3793 done in fontset.el. */
3795 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 3, 0,
3796 doc
: /* Return the font name of face FACE, or nil if it is unspecified.
3797 The font name is, by default, for ASCII characters.
3798 If the optional argument FRAME is given, report on face FACE in that frame.
3799 If FRAME is t, report on the defaults for face FACE (for new frames).
3800 The font default for a face is either nil, or a list
3801 of the form (bold), (italic) or (bold italic).
3802 If FRAME is omitted or nil, use the selected frame. And, in this case,
3803 if the optional third argument CHARACTER is given,
3804 return the font name used for CHARACTER. */)
3805 (Lisp_Object face
, Lisp_Object frame
, Lisp_Object character
)
3809 Lisp_Object result
= Qnil
;
3810 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
3812 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3813 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
3814 result
= Fcons (Qbold
, result
);
3816 if (!UNSPECIFIEDP (LFACE_SLANT (lface
))
3817 && !EQ (LFACE_SLANT (lface
), Qnormal
))
3818 result
= Fcons (Qitalic
, result
);
3824 struct frame
*f
= decode_live_frame (frame
);
3825 int face_id
= lookup_named_face (f
, face
, 1);
3826 struct face
*fface
= FACE_FROM_ID (f
, face_id
);
3830 #ifdef HAVE_WINDOW_SYSTEM
3831 if (FRAME_WINDOW_P (f
) && !NILP (character
))
3833 CHECK_CHARACTER (character
);
3834 face_id
= FACE_FOR_CHAR (f
, fface
, XINT (character
), -1, Qnil
);
3835 fface
= FACE_FROM_ID (f
, face_id
);
3838 ? fface
->font
->props
[FONT_NAME_INDEX
]
3840 #else /* !HAVE_WINDOW_SYSTEM */
3841 return build_string (FRAME_MSDOS_P (f
)
3843 : FRAME_W32_P (f
) ? "w32term"
3850 /* Compare face-attribute values v1 and v2 for equality. Value is non-zero if
3851 all attributes are `equal'. Tries to be fast because this function
3852 is called quite often. */
3855 face_attr_equal_p (Lisp_Object v1
, Lisp_Object v2
)
3857 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
3858 and the other is specified. */
3859 if (XTYPE (v1
) != XTYPE (v2
))
3868 if (SBYTES (v1
) != SBYTES (v2
))
3871 return memcmp (SDATA (v1
), SDATA (v2
), SBYTES (v1
)) == 0;
3878 return !NILP (Fequal (v1
, v2
));
3883 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
3884 all attributes are `equal'. Tries to be fast because this function
3885 is called quite often. */
3888 lface_equal_p (Lisp_Object
*v1
, Lisp_Object
*v2
)
3893 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
3894 equal_p
= face_attr_equal_p (v1
[i
], v2
[i
]);
3900 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
3901 Sinternal_lisp_face_equal_p
, 2, 3, 0,
3902 doc
: /* True if FACE1 and FACE2 are equal.
3903 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
3904 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
3905 If FRAME is omitted or nil, use the selected frame. */)
3906 (Lisp_Object face1
, Lisp_Object face2
, Lisp_Object frame
)
3910 Lisp_Object lface1
, lface2
;
3912 /* Don't use decode_window_system_frame here because this function
3913 is called before X frames exist. At that time, if FRAME is nil,
3914 selected_frame will be used which is the frame dumped with
3915 Emacs. That frame is not an X frame. */
3916 f
= EQ (frame
, Qt
) ? NULL
: decode_live_frame (frame
);
3918 lface1
= lface_from_face_name (f
, face1
, 1);
3919 lface2
= lface_from_face_name (f
, face2
, 1);
3920 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
3921 XVECTOR (lface2
)->contents
);
3922 return equal_p
? Qt
: Qnil
;
3926 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
3927 Sinternal_lisp_face_empty_p
, 1, 2, 0,
3928 doc
: /* True if FACE has no attribute specified.
3929 If the optional argument FRAME is given, report on face FACE in that frame.
3930 If FRAME is t, report on the defaults for face FACE (for new frames).
3931 If FRAME is omitted or nil, use the selected frame. */)
3932 (Lisp_Object face
, Lisp_Object frame
)
3934 struct frame
*f
= EQ (frame
, Qt
) ? NULL
: decode_live_frame (frame
);
3935 Lisp_Object lface
= lface_from_face_name (f
, face
, 1);
3938 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3939 if (!UNSPECIFIEDP (AREF (lface
, i
)))
3942 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
3946 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
3948 doc
: /* Return an alist of frame-local faces defined on FRAME.
3949 For internal use only. */)
3952 return decode_live_frame (frame
)->face_alist
;
3956 /* Return a hash code for Lisp string STRING with case ignored. Used
3957 below in computing a hash value for a Lisp face. */
3960 hash_string_case_insensitive (Lisp_Object string
)
3962 const unsigned char *s
;
3964 eassert (STRINGP (string
));
3965 for (s
= SDATA (string
); *s
; ++s
)
3966 hash
= (hash
<< 1) ^ c_tolower (*s
);
3971 /* Return a hash code for face attribute vector V. */
3974 lface_hash (Lisp_Object
*v
)
3976 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
3977 ^ hash_string_case_insensitive (v
[LFACE_FOUNDRY_INDEX
])
3978 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
3979 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
3980 ^ XHASH (v
[LFACE_WEIGHT_INDEX
])
3981 ^ XHASH (v
[LFACE_SLANT_INDEX
])
3982 ^ XHASH (v
[LFACE_SWIDTH_INDEX
])
3983 ^ XHASH (v
[LFACE_HEIGHT_INDEX
]));
3987 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
3988 considering charsets/registries). They do if they specify the same
3989 family, point size, weight, width, slant, and font. Both
3990 LFACE1 and LFACE2 must be fully-specified. */
3993 lface_same_font_attributes_p (Lisp_Object
*lface1
, Lisp_Object
*lface2
)
3995 eassert (lface_fully_specified_p (lface1
)
3996 && lface_fully_specified_p (lface2
));
3997 return (xstrcasecmp (SSDATA (lface1
[LFACE_FAMILY_INDEX
]),
3998 SSDATA (lface2
[LFACE_FAMILY_INDEX
])) == 0
3999 && xstrcasecmp (SSDATA (lface1
[LFACE_FOUNDRY_INDEX
]),
4000 SSDATA (lface2
[LFACE_FOUNDRY_INDEX
])) == 0
4001 && EQ (lface1
[LFACE_HEIGHT_INDEX
], lface2
[LFACE_HEIGHT_INDEX
])
4002 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
4003 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
4004 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
])
4005 && EQ (lface1
[LFACE_FONT_INDEX
], lface2
[LFACE_FONT_INDEX
])
4006 && (EQ (lface1
[LFACE_FONTSET_INDEX
], lface2
[LFACE_FONTSET_INDEX
])
4007 || (STRINGP (lface1
[LFACE_FONTSET_INDEX
])
4008 && STRINGP (lface2
[LFACE_FONTSET_INDEX
])
4009 && ! xstrcasecmp (SSDATA (lface1
[LFACE_FONTSET_INDEX
]),
4010 SSDATA (lface2
[LFACE_FONTSET_INDEX
]))))
4016 /***********************************************************************
4018 ***********************************************************************/
4020 /* Allocate and return a new realized face for Lisp face attribute
4023 static struct face
*
4024 make_realized_face (Lisp_Object
*attr
)
4026 struct face
*face
= xzalloc (sizeof *face
);
4027 face
->ascii_face
= face
;
4028 memcpy (face
->lface
, attr
, sizeof face
->lface
);
4033 /* Free realized face FACE, including its X resources. FACE may
4037 free_realized_face (struct frame
*f
, struct face
*face
)
4041 #ifdef HAVE_WINDOW_SYSTEM
4042 if (FRAME_WINDOW_P (f
))
4044 /* Free fontset of FACE if it is ASCII face. */
4045 if (face
->fontset
>= 0 && face
== face
->ascii_face
)
4046 free_face_fontset (f
, face
);
4051 font_done_for_face (f
, face
);
4052 x_free_gc (f
, face
->gc
);
4057 free_face_colors (f
, face
);
4058 x_destroy_bitmap (f
, face
->stipple
);
4060 #endif /* HAVE_WINDOW_SYSTEM */
4067 /* Prepare face FACE for subsequent display on frame F. This
4068 allocated GCs if they haven't been allocated yet or have been freed
4069 by clearing the face cache. */
4072 prepare_face_for_display (struct frame
*f
, struct face
*face
)
4074 #ifdef HAVE_WINDOW_SYSTEM
4075 eassert (FRAME_WINDOW_P (f
));
4080 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
4082 xgcv
.foreground
= face
->foreground
;
4083 xgcv
.background
= face
->background
;
4084 #ifdef HAVE_X_WINDOWS
4085 xgcv
.graphics_exposures
= False
;
4089 #ifdef HAVE_X_WINDOWS
4092 xgcv
.fill_style
= FillOpaqueStippled
;
4093 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
4094 mask
|= GCFillStyle
| GCStipple
;
4097 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
4099 font_prepare_for_face (f
, face
);
4102 #endif /* HAVE_WINDOW_SYSTEM */
4106 /* Returns the `distance' between the colors X and Y. */
4109 color_distance (XColor
*x
, XColor
*y
)
4111 /* This formula is from a paper titled `Colour metric' by Thiadmer Riemersma.
4112 Quoting from that paper:
4114 This formula has results that are very close to L*u*v* (with the
4115 modified lightness curve) and, more importantly, it is a more even
4116 algorithm: it does not have a range of colors where it suddenly
4117 gives far from optimal results.
4119 See <http://www.compuphase.com/cmetric.htm> for more info. */
4121 long r
= (x
->red
- y
->red
) >> 8;
4122 long g
= (x
->green
- y
->green
) >> 8;
4123 long b
= (x
->blue
- y
->blue
) >> 8;
4124 long r_mean
= (x
->red
+ y
->red
) >> 9;
4127 (((512 + r_mean
) * r
* r
) >> 8)
4129 + (((767 - r_mean
) * b
* b
) >> 8);
4133 DEFUN ("color-distance", Fcolor_distance
, Scolor_distance
, 2, 3, 0,
4134 doc
: /* Return an integer distance between COLOR1 and COLOR2 on FRAME.
4135 COLOR1 and COLOR2 may be either strings containing the color name,
4136 or lists of the form (RED GREEN BLUE).
4137 If FRAME is unspecified or nil, the current frame is used. */)
4138 (Lisp_Object color1
, Lisp_Object color2
, Lisp_Object frame
)
4140 struct frame
*f
= decode_live_frame (frame
);
4141 XColor cdef1
, cdef2
;
4143 if (!(CONSP (color1
) && parse_rgb_list (color1
, &cdef1
))
4144 && !(STRINGP (color1
) && defined_color (f
, SSDATA (color1
), &cdef1
, 0)))
4145 signal_error ("Invalid color", color1
);
4146 if (!(CONSP (color2
) && parse_rgb_list (color2
, &cdef2
))
4147 && !(STRINGP (color2
) && defined_color (f
, SSDATA (color2
), &cdef2
, 0)))
4148 signal_error ("Invalid color", color2
);
4150 return make_number (color_distance (&cdef1
, &cdef2
));
4154 /***********************************************************************
4156 ***********************************************************************/
4158 /* Return a new face cache for frame F. */
4160 static struct face_cache
*
4161 make_face_cache (struct frame
*f
)
4163 struct face_cache
*c
= xmalloc (sizeof *c
);
4165 c
->buckets
= xzalloc (FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
);
4168 c
->faces_by_id
= xmalloc (c
->size
* sizeof *c
->faces_by_id
);
4170 c
->menu_face_changed_p
= menu_face_changed_default
;
4175 /* Clear out all graphics contexts for all realized faces, except for
4176 the basic faces. This should be done from time to time just to avoid
4177 keeping too many graphics contexts that are no longer needed. */
4180 clear_face_gcs (struct face_cache
*c
)
4182 if (c
&& FRAME_WINDOW_P (c
->f
))
4184 #ifdef HAVE_WINDOW_SYSTEM
4186 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
4188 struct face
*face
= c
->faces_by_id
[i
];
4189 if (face
&& face
->gc
)
4193 font_done_for_face (c
->f
, face
);
4194 x_free_gc (c
->f
, face
->gc
);
4199 #endif /* HAVE_WINDOW_SYSTEM */
4204 /* Free all realized faces in face cache C, including basic faces.
4205 C may be null. If faces are freed, make sure the frame's current
4206 matrix is marked invalid, so that a display caused by an expose
4207 event doesn't try to use faces we destroyed. */
4210 free_realized_faces (struct face_cache
*c
)
4215 struct frame
*f
= c
->f
;
4217 /* We must block input here because we can't process X events
4218 safely while only some faces are freed, or when the frame's
4219 current matrix still references freed faces. */
4222 for (i
= 0; i
< c
->used
; ++i
)
4224 free_realized_face (f
, c
->faces_by_id
[i
]);
4225 c
->faces_by_id
[i
] = NULL
;
4229 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4230 memset (c
->buckets
, 0, size
);
4232 /* Must do a thorough redisplay the next time. Mark current
4233 matrices as invalid because they will reference faces freed
4234 above. This function is also called when a frame is
4235 destroyed. In this case, the root window of F is nil. */
4236 if (WINDOWP (f
->root_window
))
4238 clear_current_matrices (f
);
4239 ++windows_or_buffers_changed
;
4247 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
4248 This is done after attributes of a named face have been changed,
4249 because we can't tell which realized faces depend on that face. */
4252 free_all_realized_faces (Lisp_Object frame
)
4257 FOR_EACH_FRAME (rest
, frame
)
4258 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4261 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4265 /* Free face cache C and faces in it, including their X resources. */
4268 free_face_cache (struct face_cache
*c
)
4272 free_realized_faces (c
);
4274 xfree (c
->faces_by_id
);
4280 /* Cache realized face FACE in face cache C. HASH is the hash value
4281 of FACE. If FACE is for ASCII characters (i.e. FACE->ascii_face ==
4282 FACE), insert the new face to the beginning of the collision list
4283 of the face hash table of C. Otherwise, add the new face to the
4284 end of the collision list. This way, lookup_face can quickly find
4285 that a requested face is not cached. */
4288 cache_face (struct face_cache
*c
, struct face
*face
, unsigned int hash
)
4290 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4294 if (face
->ascii_face
!= face
)
4296 struct face
*last
= c
->buckets
[i
];
4307 c
->buckets
[i
] = face
;
4308 face
->prev
= face
->next
= NULL
;
4314 face
->next
= c
->buckets
[i
];
4316 face
->next
->prev
= face
;
4317 c
->buckets
[i
] = face
;
4320 /* Find a free slot in C->faces_by_id and use the index of the free
4321 slot as FACE->id. */
4322 for (i
= 0; i
< c
->used
; ++i
)
4323 if (c
->faces_by_id
[i
] == NULL
)
4328 /* Check that FACE got a unique id. */
4333 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
4334 for (face1
= c
->buckets
[j
]; face1
; face1
= face1
->next
)
4340 #endif /* GLYPH_DEBUG */
4342 /* Maybe enlarge C->faces_by_id. */
4345 if (c
->used
== c
->size
)
4346 c
->faces_by_id
= xpalloc (c
->faces_by_id
, &c
->size
, 1, MAX_FACE_ID
,
4347 sizeof *c
->faces_by_id
);
4351 c
->faces_by_id
[i
] = face
;
4355 /* Remove face FACE from cache C. */
4358 uncache_face (struct face_cache
*c
, struct face
*face
)
4360 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
4363 face
->prev
->next
= face
->next
;
4365 c
->buckets
[i
] = face
->next
;
4368 face
->next
->prev
= face
->prev
;
4370 c
->faces_by_id
[face
->id
] = NULL
;
4371 if (face
->id
== c
->used
)
4376 /* Look up a realized face with face attributes ATTR in the face cache
4377 of frame F. The face will be used to display ASCII characters.
4378 Value is the ID of the face found. If no suitable face is found,
4379 realize a new one. */
4382 lookup_face (struct frame
*f
, Lisp_Object
*attr
)
4384 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4389 eassert (cache
!= NULL
);
4390 check_lface_attrs (attr
);
4392 /* Look up ATTR in the face cache. */
4393 hash
= lface_hash (attr
);
4394 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4396 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4398 if (face
->ascii_face
!= face
)
4400 /* There's no more ASCII face. */
4404 if (face
->hash
== hash
4405 && lface_equal_p (face
->lface
, attr
))
4409 /* If not found, realize a new face. */
4411 face
= realize_face (cache
, attr
, -1);
4414 eassert (face
== FACE_FROM_ID (f
, face
->id
));
4415 #endif /* GLYPH_DEBUG */
4420 #ifdef HAVE_WINDOW_SYSTEM
4421 /* Look up a realized face that has the same attributes as BASE_FACE
4422 except for the font in the face cache of frame F. If FONT-OBJECT
4423 is not nil, it is an already opened font. If FONT-OBJECT is nil,
4424 the face has no font. Value is the ID of the face found. If no
4425 suitable face is found, realize a new one. */
4428 face_for_font (struct frame
*f
, Lisp_Object font_object
, struct face
*base_face
)
4430 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4435 eassert (cache
!= NULL
);
4436 base_face
= base_face
->ascii_face
;
4437 hash
= lface_hash (base_face
->lface
);
4438 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4440 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4442 if (face
->ascii_face
== face
)
4444 if (face
->ascii_face
== base_face
4445 && face
->font
== (NILP (font_object
) ? NULL
4446 : XFONT_OBJECT (font_object
))
4447 && lface_equal_p (face
->lface
, base_face
->lface
))
4451 /* If not found, realize a new face. */
4452 face
= realize_non_ascii_face (f
, font_object
, base_face
);
4455 #endif /* HAVE_WINDOW_SYSTEM */
4457 /* Return the face id of the realized face for named face SYMBOL on
4458 frame F suitable for displaying ASCII characters. Value is -1 if
4459 the face couldn't be determined, which might happen if the default
4460 face isn't realized and cannot be realized. */
4463 lookup_named_face (struct frame
*f
, Lisp_Object symbol
, int signal_p
)
4465 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4466 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4467 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4469 if (default_face
== NULL
)
4471 if (!realize_basic_faces (f
))
4473 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4474 if (default_face
== NULL
)
4475 emacs_abort (); /* realize_basic_faces must have set it up */
4478 if (! get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4481 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4482 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4484 return lookup_face (f
, attrs
);
4488 /* Return the display face-id of the basic face whose canonical face-id
4489 is FACE_ID. The return value will usually simply be FACE_ID, unless that
4490 basic face has bee remapped via Vface_remapping_alist. This function is
4491 conservative: if something goes wrong, it will simply return FACE_ID
4492 rather than signal an error. */
4495 lookup_basic_face (struct frame
*f
, int face_id
)
4497 Lisp_Object name
, mapping
;
4498 int remapped_face_id
;
4500 if (NILP (Vface_remapping_alist
))
4501 return face_id
; /* Nothing to do. */
4505 case DEFAULT_FACE_ID
: name
= Qdefault
; break;
4506 case MODE_LINE_FACE_ID
: name
= Qmode_line
; break;
4507 case MODE_LINE_INACTIVE_FACE_ID
: name
= Qmode_line_inactive
; break;
4508 case HEADER_LINE_FACE_ID
: name
= Qheader_line
; break;
4509 case TOOL_BAR_FACE_ID
: name
= Qtool_bar
; break;
4510 case FRINGE_FACE_ID
: name
= Qfringe
; break;
4511 case SCROLL_BAR_FACE_ID
: name
= Qscroll_bar
; break;
4512 case BORDER_FACE_ID
: name
= Qborder
; break;
4513 case CURSOR_FACE_ID
: name
= Qcursor
; break;
4514 case MOUSE_FACE_ID
: name
= Qmouse
; break;
4515 case MENU_FACE_ID
: name
= Qmenu
; break;
4518 emacs_abort (); /* the caller is supposed to pass us a basic face id */
4521 /* Do a quick scan through Vface_remapping_alist, and return immediately
4522 if there is no remapping for face NAME. This is just an optimization
4523 for the very common no-remapping case. */
4524 mapping
= assq_no_quit (name
, Vface_remapping_alist
);
4526 return face_id
; /* Give up. */
4528 /* If there is a remapping entry, lookup the face using NAME, which will
4529 handle the remapping too. */
4530 remapped_face_id
= lookup_named_face (f
, name
, 0);
4531 if (remapped_face_id
< 0)
4532 return face_id
; /* Give up. */
4534 return remapped_face_id
;
4538 /* Return a face for charset ASCII that is like the face with id
4539 FACE_ID on frame F, but has a font that is STEPS steps smaller.
4540 STEPS < 0 means larger. Value is the id of the face. */
4543 smaller_face (struct frame
*f
, int face_id
, int steps
)
4545 #ifdef HAVE_WINDOW_SYSTEM
4547 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4548 int pt
, last_pt
, last_height
;
4551 struct face
*new_face
;
4553 /* If not called for an X frame, just return the original face. */
4554 if (FRAME_TERMCAP_P (f
))
4557 /* Try in increments of 1/2 pt. */
4558 delta
= steps
< 0 ? 5 : -5;
4559 steps
= eabs (steps
);
4561 face
= FACE_FROM_ID (f
, face_id
);
4562 memcpy (attrs
, face
->lface
, sizeof attrs
);
4563 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
4564 new_face_id
= face_id
;
4565 last_height
= FONT_HEIGHT (face
->font
);
4569 /* Give up if we cannot find a font within 10pt. */
4570 && eabs (last_pt
- pt
) < 100)
4572 /* Look up a face for a slightly smaller/larger font. */
4574 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
4575 new_face_id
= lookup_face (f
, attrs
);
4576 new_face
= FACE_FROM_ID (f
, new_face_id
);
4578 /* If height changes, count that as one step. */
4579 if ((delta
< 0 && FONT_HEIGHT (new_face
->font
) < last_height
)
4580 || (delta
> 0 && FONT_HEIGHT (new_face
->font
) > last_height
))
4583 last_height
= FONT_HEIGHT (new_face
->font
);
4590 #else /* not HAVE_WINDOW_SYSTEM */
4594 #endif /* not HAVE_WINDOW_SYSTEM */
4598 /* Return a face for charset ASCII that is like the face with id
4599 FACE_ID on frame F, but has height HEIGHT. */
4602 face_with_height (struct frame
*f
, int face_id
, int height
)
4604 #ifdef HAVE_WINDOW_SYSTEM
4606 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4608 if (FRAME_TERMCAP_P (f
)
4612 face
= FACE_FROM_ID (f
, face_id
);
4613 memcpy (attrs
, face
->lface
, sizeof attrs
);
4614 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
4615 font_clear_prop (attrs
, FONT_SIZE_INDEX
);
4616 face_id
= lookup_face (f
, attrs
);
4617 #endif /* HAVE_WINDOW_SYSTEM */
4623 /* Return the face id of the realized face for named face SYMBOL on
4624 frame F suitable for displaying ASCII characters, and use
4625 attributes of the face FACE_ID for attributes that aren't
4626 completely specified by SYMBOL. This is like lookup_named_face,
4627 except that the default attributes come from FACE_ID, not from the
4628 default face. FACE_ID is assumed to be already realized. */
4631 lookup_derived_face (struct frame
*f
, Lisp_Object symbol
, int face_id
,
4634 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4635 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4636 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
4641 if (!get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4644 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4645 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4646 return lookup_face (f
, attrs
);
4649 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector
,
4650 Sface_attributes_as_vector
, 1, 1, 0,
4651 doc
: /* Return a vector of face attributes corresponding to PLIST. */)
4655 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
4657 merge_face_ref (XFRAME (selected_frame
), plist
, XVECTOR (lface
)->contents
,
4664 /***********************************************************************
4665 Face capability testing
4666 ***********************************************************************/
4669 /* If the distance (as returned by color_distance) between two colors is
4670 less than this, then they are considered the same, for determining
4671 whether a color is supported or not. The range of values is 0-65535. */
4673 #define TTY_SAME_COLOR_THRESHOLD 10000
4675 #ifdef HAVE_WINDOW_SYSTEM
4677 /* Return non-zero if all the face attributes in ATTRS are supported
4678 on the window-system frame F.
4680 The definition of `supported' is somewhat heuristic, but basically means
4681 that a face containing all the attributes in ATTRS, when merged with the
4682 default face for display, can be represented in a way that's
4684 \(1) different in appearance than the default face, and
4685 \(2) `close in spirit' to what the attributes specify, if not exact. */
4688 x_supports_face_attributes_p (struct frame
*f
,
4689 Lisp_Object attrs
[LFACE_VECTOR_SIZE
],
4690 struct face
*def_face
)
4692 Lisp_Object
*def_attrs
= def_face
->lface
;
4694 /* Check that other specified attributes are different that the default
4696 if ((!UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
4697 && face_attr_equal_p (attrs
[LFACE_UNDERLINE_INDEX
],
4698 def_attrs
[LFACE_UNDERLINE_INDEX
]))
4699 || (!UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
4700 && face_attr_equal_p (attrs
[LFACE_INVERSE_INDEX
],
4701 def_attrs
[LFACE_INVERSE_INDEX
]))
4702 || (!UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
4703 && face_attr_equal_p (attrs
[LFACE_FOREGROUND_INDEX
],
4704 def_attrs
[LFACE_FOREGROUND_INDEX
]))
4705 || (!UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
4706 && face_attr_equal_p (attrs
[LFACE_BACKGROUND_INDEX
],
4707 def_attrs
[LFACE_BACKGROUND_INDEX
]))
4708 || (!UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
4709 && face_attr_equal_p (attrs
[LFACE_STIPPLE_INDEX
],
4710 def_attrs
[LFACE_STIPPLE_INDEX
]))
4711 || (!UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
4712 && face_attr_equal_p (attrs
[LFACE_OVERLINE_INDEX
],
4713 def_attrs
[LFACE_OVERLINE_INDEX
]))
4714 || (!UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
4715 && face_attr_equal_p (attrs
[LFACE_STRIKE_THROUGH_INDEX
],
4716 def_attrs
[LFACE_STRIKE_THROUGH_INDEX
]))
4717 || (!UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
4718 && face_attr_equal_p (attrs
[LFACE_BOX_INDEX
],
4719 def_attrs
[LFACE_BOX_INDEX
])))
4722 /* Check font-related attributes, as those are the most commonly
4723 "unsupported" on a window-system (because of missing fonts). */
4724 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
4725 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
4726 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
4727 || !UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
4728 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
4729 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
]))
4733 Lisp_Object merged_attrs
[LFACE_VECTOR_SIZE
];
4736 memcpy (merged_attrs
, def_attrs
, sizeof merged_attrs
);
4738 merge_face_vectors (f
, attrs
, merged_attrs
, 0);
4740 face_id
= lookup_face (f
, merged_attrs
);
4741 face
= FACE_FROM_ID (f
, face_id
);
4744 error ("Cannot make face");
4746 /* If the font is the same, or no font is found, then not
4748 if (face
->font
== def_face
->font
4751 for (i
= FONT_TYPE_INDEX
; i
<= FONT_SIZE_INDEX
; i
++)
4752 if (! EQ (face
->font
->props
[i
], def_face
->font
->props
[i
]))
4756 if (i
< FONT_FOUNDRY_INDEX
|| i
> FONT_REGISTRY_INDEX
4757 || face
->font
->driver
->case_sensitive
)
4759 s1
= SYMBOL_NAME (face
->font
->props
[i
]);
4760 s2
= SYMBOL_NAME (def_face
->font
->props
[i
]);
4761 if (! EQ (Fcompare_strings (s1
, make_number (0), Qnil
,
4762 s2
, make_number (0), Qnil
, Qt
), Qt
))
4768 /* Everything checks out, this face is supported. */
4772 #endif /* HAVE_WINDOW_SYSTEM */
4774 /* Return non-zero if all the face attributes in ATTRS are supported
4777 The definition of `supported' is somewhat heuristic, but basically means
4778 that a face containing all the attributes in ATTRS, when merged
4779 with the default face for display, can be represented in a way that's
4781 \(1) different in appearance than the default face, and
4782 \(2) `close in spirit' to what the attributes specify, if not exact.
4784 Point (2) implies that a `:weight black' attribute will be satisfied
4785 by any terminal that can display bold, and a `:foreground "yellow"' as
4786 long as the terminal can display a yellowish color, but `:slant italic'
4787 will _not_ be satisfied by the tty display code's automatic
4788 substitution of a `dim' face for italic. */
4791 tty_supports_face_attributes_p (struct frame
*f
,
4792 Lisp_Object attrs
[LFACE_VECTOR_SIZE
],
4793 struct face
*def_face
)
4796 Lisp_Object val
, fg
, bg
;
4797 XColor fg_tty_color
, fg_std_color
;
4798 XColor bg_tty_color
, bg_std_color
;
4799 unsigned test_caps
= 0;
4800 Lisp_Object
*def_attrs
= def_face
->lface
;
4802 /* First check some easy-to-check stuff; ttys support none of the
4803 following attributes, so we can just return false if any are requested
4804 (even if `nominal' values are specified, we should still return false,
4805 as that will be the same value that the default face uses). We
4806 consider :slant unsupportable on ttys, even though the face code
4807 actually `fakes' them using a dim attribute if possible. This is
4808 because the faked result is too different from what the face
4810 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
4811 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
4812 || !UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
4813 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
4814 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
4815 || !UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
4816 || !UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
4817 || !UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
]))
4820 /* Test for terminal `capabilities' (non-color character attributes). */
4822 /* font weight (bold/dim) */
4823 val
= attrs
[LFACE_WEIGHT_INDEX
];
4824 if (!UNSPECIFIEDP (val
)
4825 && (weight
= FONT_WEIGHT_NAME_NUMERIC (val
), weight
>= 0))
4827 int def_weight
= FONT_WEIGHT_NAME_NUMERIC (def_attrs
[LFACE_WEIGHT_INDEX
]);
4831 if (def_weight
> 100)
4832 return 0; /* same as default */
4833 test_caps
= TTY_CAP_BOLD
;
4835 else if (weight
< 100)
4837 if (def_weight
< 100)
4838 return 0; /* same as default */
4839 test_caps
= TTY_CAP_DIM
;
4841 else if (def_weight
== 100)
4842 return 0; /* same as default */
4846 val
= attrs
[LFACE_SLANT_INDEX
];
4847 if (!UNSPECIFIEDP (val
)
4848 && (slant
= FONT_SLANT_NAME_NUMERIC (val
), slant
>= 0))
4850 int def_slant
= FONT_SLANT_NAME_NUMERIC (def_attrs
[LFACE_SLANT_INDEX
]);
4851 if (slant
== 100 || slant
== def_slant
)
4852 return 0; /* same as default */
4854 test_caps
|= TTY_CAP_ITALIC
;
4858 val
= attrs
[LFACE_UNDERLINE_INDEX
];
4859 if (!UNSPECIFIEDP (val
))
4862 return 0; /* ttys can't use colored underlines */
4863 else if (EQ (CAR_SAFE (val
), QCstyle
) && EQ (CAR_SAFE (CDR_SAFE (val
)), Qwave
))
4864 return 0; /* ttys can't use wave underlines */
4865 else if (face_attr_equal_p (val
, def_attrs
[LFACE_UNDERLINE_INDEX
]))
4866 return 0; /* same as default */
4868 test_caps
|= TTY_CAP_UNDERLINE
;
4872 val
= attrs
[LFACE_INVERSE_INDEX
];
4873 if (!UNSPECIFIEDP (val
))
4875 if (face_attr_equal_p (val
, def_attrs
[LFACE_INVERSE_INDEX
]))
4876 return 0; /* same as default */
4878 test_caps
|= TTY_CAP_INVERSE
;
4882 /* Color testing. */
4884 /* Default the color indices in FG_TTY_COLOR and BG_TTY_COLOR, since
4885 we use them when calling `tty_capable_p' below, even if the face
4886 specifies no colors. */
4887 fg_tty_color
.pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
4888 bg_tty_color
.pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
4890 /* Check if foreground color is close enough. */
4891 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
4894 Lisp_Object def_fg
= def_attrs
[LFACE_FOREGROUND_INDEX
];
4896 if (face_attr_equal_p (fg
, def_fg
))
4897 return 0; /* same as default */
4898 else if (! tty_lookup_color (f
, fg
, &fg_tty_color
, &fg_std_color
))
4899 return 0; /* not a valid color */
4900 else if (color_distance (&fg_tty_color
, &fg_std_color
)
4901 > TTY_SAME_COLOR_THRESHOLD
)
4902 return 0; /* displayed color is too different */
4904 /* Make sure the color is really different than the default. */
4906 XColor def_fg_color
;
4907 if (tty_lookup_color (f
, def_fg
, &def_fg_color
, 0)
4908 && (color_distance (&fg_tty_color
, &def_fg_color
)
4909 <= TTY_SAME_COLOR_THRESHOLD
))
4914 /* Check if background color is close enough. */
4915 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
4918 Lisp_Object def_bg
= def_attrs
[LFACE_BACKGROUND_INDEX
];
4920 if (face_attr_equal_p (bg
, def_bg
))
4921 return 0; /* same as default */
4922 else if (! tty_lookup_color (f
, bg
, &bg_tty_color
, &bg_std_color
))
4923 return 0; /* not a valid color */
4924 else if (color_distance (&bg_tty_color
, &bg_std_color
)
4925 > TTY_SAME_COLOR_THRESHOLD
)
4926 return 0; /* displayed color is too different */
4928 /* Make sure the color is really different than the default. */
4930 XColor def_bg_color
;
4931 if (tty_lookup_color (f
, def_bg
, &def_bg_color
, 0)
4932 && (color_distance (&bg_tty_color
, &def_bg_color
)
4933 <= TTY_SAME_COLOR_THRESHOLD
))
4938 /* If both foreground and background are requested, see if the
4939 distance between them is OK. We just check to see if the distance
4940 between the tty's foreground and background is close enough to the
4941 distance between the standard foreground and background. */
4942 if (STRINGP (fg
) && STRINGP (bg
))
4945 = (color_distance (&fg_std_color
, &bg_std_color
)
4946 - color_distance (&fg_tty_color
, &bg_tty_color
));
4947 if (delta_delta
> TTY_SAME_COLOR_THRESHOLD
4948 || delta_delta
< -TTY_SAME_COLOR_THRESHOLD
)
4953 /* See if the capabilities we selected above are supported, with the
4955 if (test_caps
!= 0 &&
4956 ! tty_capable_p (FRAME_TTY (f
), test_caps
, fg_tty_color
.pixel
,
4957 bg_tty_color
.pixel
))
4961 /* Hmmm, everything checks out, this terminal must support this face. */
4966 DEFUN ("display-supports-face-attributes-p",
4967 Fdisplay_supports_face_attributes_p
, Sdisplay_supports_face_attributes_p
,
4969 doc
: /* Return non-nil if all the face attributes in ATTRIBUTES are supported.
4970 The optional argument DISPLAY can be a display name, a frame, or
4971 nil (meaning the selected frame's display).
4973 The definition of `supported' is somewhat heuristic, but basically means
4974 that a face containing all the attributes in ATTRIBUTES, when merged
4975 with the default face for display, can be represented in a way that's
4977 \(1) different in appearance than the default face, and
4978 \(2) `close in spirit' to what the attributes specify, if not exact.
4980 Point (2) implies that a `:weight black' attribute will be satisfied by
4981 any display that can display bold, and a `:foreground \"yellow\"' as long
4982 as it can display a yellowish color, but `:slant italic' will _not_ be
4983 satisfied by the tty display code's automatic substitution of a `dim'
4984 face for italic. */)
4985 (Lisp_Object attributes
, Lisp_Object display
)
4987 int supports
= 0, i
;
4990 struct face
*def_face
;
4991 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4993 if (noninteractive
|| !initialized
)
4994 /* We may not be able to access low-level face information in batch
4995 mode, or before being dumped, and this function is not going to
4996 be very useful in those cases anyway, so just give up. */
5000 frame
= selected_frame
;
5001 else if (FRAMEP (display
))
5005 /* Find any frame on DISPLAY. */
5009 FOR_EACH_FRAME (tail
, frame
)
5010 if (!NILP (Fequal (Fcdr (Fassq (Qdisplay
,
5011 XFRAME (frame
)->param_alist
)),
5016 CHECK_LIVE_FRAME (frame
);
5019 for (i
= 0; i
< LFACE_VECTOR_SIZE
; i
++)
5020 attrs
[i
] = Qunspecified
;
5021 merge_face_ref (f
, attributes
, attrs
, 1, 0);
5023 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5024 if (def_face
== NULL
)
5026 if (! realize_basic_faces (f
))
5027 error ("Cannot realize default face");
5028 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5029 if (def_face
== NULL
)
5030 emacs_abort (); /* realize_basic_faces must have set it up */
5033 /* Dispatch to the appropriate handler. */
5034 if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5035 supports
= tty_supports_face_attributes_p (f
, attrs
, def_face
);
5036 #ifdef HAVE_WINDOW_SYSTEM
5038 supports
= x_supports_face_attributes_p (f
, attrs
, def_face
);
5041 return supports
? Qt
: Qnil
;
5045 /***********************************************************************
5047 ***********************************************************************/
5049 DEFUN ("internal-set-font-selection-order",
5050 Finternal_set_font_selection_order
,
5051 Sinternal_set_font_selection_order
, 1, 1, 0,
5052 doc
: /* Set font selection order for face font selection to ORDER.
5053 ORDER must be a list of length 4 containing the symbols `:width',
5054 `:height', `:weight', and `:slant'. Face attributes appearing
5055 first in ORDER are matched first, e.g. if `:height' appears before
5056 `:weight' in ORDER, font selection first tries to find a font with
5057 a suitable height, and then tries to match the font weight.
5063 int indices
[DIM (font_sort_order
)];
5066 memset (indices
, 0, sizeof indices
);
5070 CONSP (list
) && i
< DIM (indices
);
5071 list
= XCDR (list
), ++i
)
5073 Lisp_Object attr
= XCAR (list
);
5076 if (EQ (attr
, QCwidth
))
5078 else if (EQ (attr
, QCheight
))
5079 xlfd
= XLFD_POINT_SIZE
;
5080 else if (EQ (attr
, QCweight
))
5082 else if (EQ (attr
, QCslant
))
5087 if (indices
[i
] != 0)
5092 if (!NILP (list
) || i
!= DIM (indices
))
5093 signal_error ("Invalid font sort order", order
);
5094 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5095 if (indices
[i
] == 0)
5096 signal_error ("Invalid font sort order", order
);
5098 if (memcmp (indices
, font_sort_order
, sizeof indices
) != 0)
5100 memcpy (font_sort_order
, indices
, sizeof font_sort_order
);
5101 free_all_realized_faces (Qnil
);
5104 font_update_sort_order (font_sort_order
);
5110 DEFUN ("internal-set-alternative-font-family-alist",
5111 Finternal_set_alternative_font_family_alist
,
5112 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
5113 doc
: /* Define alternative font families to try in face font selection.
5114 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5115 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
5116 be found. Value is ALIST. */)
5119 Lisp_Object entry
, tail
, tail2
;
5122 alist
= Fcopy_sequence (alist
);
5123 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5125 entry
= XCAR (tail
);
5127 entry
= Fcopy_sequence (entry
);
5128 XSETCAR (tail
, entry
);
5129 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5130 XSETCAR (tail2
, Fintern (XCAR (tail2
), Qnil
));
5133 Vface_alternative_font_family_alist
= alist
;
5134 free_all_realized_faces (Qnil
);
5139 DEFUN ("internal-set-alternative-font-registry-alist",
5140 Finternal_set_alternative_font_registry_alist
,
5141 Sinternal_set_alternative_font_registry_alist
, 1, 1, 0,
5142 doc
: /* Define alternative font registries to try in face font selection.
5143 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5144 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
5145 be found. Value is ALIST. */)
5148 Lisp_Object entry
, tail
, tail2
;
5151 alist
= Fcopy_sequence (alist
);
5152 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5154 entry
= XCAR (tail
);
5156 entry
= Fcopy_sequence (entry
);
5157 XSETCAR (tail
, entry
);
5158 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5159 XSETCAR (tail2
, Fdowncase (XCAR (tail2
)));
5161 Vface_alternative_font_registry_alist
= alist
;
5162 free_all_realized_faces (Qnil
);
5167 #ifdef HAVE_WINDOW_SYSTEM
5169 /* Return the fontset id of the base fontset name or alias name given
5170 by the fontset attribute of ATTRS. Value is -1 if the fontset
5171 attribute of ATTRS doesn't name a fontset. */
5174 face_fontset (Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
5178 name
= attrs
[LFACE_FONTSET_INDEX
];
5179 if (!STRINGP (name
))
5181 return fs_query_fontset (name
, 0);
5184 #endif /* HAVE_WINDOW_SYSTEM */
5188 /***********************************************************************
5190 ***********************************************************************/
5192 /* Realize basic faces on frame F. Value is zero if frame parameters
5193 of F don't contain enough information needed to realize the default
5197 realize_basic_faces (struct frame
*f
)
5200 ptrdiff_t count
= SPECPDL_INDEX ();
5202 /* Block input here so that we won't be surprised by an X expose
5203 event, for instance, without having the faces set up. */
5205 specbind (Qscalable_fonts_allowed
, Qt
);
5207 if (realize_default_face (f
))
5209 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
5210 realize_named_face (f
, Qmode_line_inactive
, MODE_LINE_INACTIVE_FACE_ID
);
5211 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
5212 realize_named_face (f
, Qfringe
, FRINGE_FACE_ID
);
5213 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
5214 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
5215 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
5216 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
5217 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
5218 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
5219 realize_named_face (f
, Qvertical_border
, VERTICAL_BORDER_FACE_ID
);
5221 /* Reflect changes in the `menu' face in menu bars. */
5222 if (FRAME_FACE_CACHE (f
)->menu_face_changed_p
)
5224 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 0;
5225 #ifdef USE_X_TOOLKIT
5226 if (FRAME_WINDOW_P (f
))
5227 x_update_menu_appearance (f
);
5234 unbind_to (count
, Qnil
);
5240 /* Realize the default face on frame F. If the face is not fully
5241 specified, make it fully-specified. Attributes of the default face
5242 that are not explicitly specified are taken from frame parameters. */
5245 realize_default_face (struct frame
*f
)
5247 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5249 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5252 /* If the `default' face is not yet known, create it. */
5253 lface
= lface_from_face_name (f
, Qdefault
, 0);
5257 XSETFRAME (frame
, f
);
5258 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
5261 #ifdef HAVE_WINDOW_SYSTEM
5262 if (FRAME_WINDOW_P (f
))
5264 Lisp_Object font_object
;
5266 XSETFONT (font_object
, FRAME_FONT (f
));
5267 set_lface_from_font (f
, lface
, font_object
, f
->default_face_done_p
);
5268 ASET (lface
, LFACE_FONTSET_INDEX
, fontset_name (FRAME_FONTSET (f
)));
5269 f
->default_face_done_p
= 1;
5271 #endif /* HAVE_WINDOW_SYSTEM */
5273 if (!FRAME_WINDOW_P (f
))
5275 ASET (lface
, LFACE_FAMILY_INDEX
, build_string ("default"));
5276 ASET (lface
, LFACE_FOUNDRY_INDEX
, LFACE_FAMILY (lface
));
5277 ASET (lface
, LFACE_SWIDTH_INDEX
, Qnormal
);
5278 ASET (lface
, LFACE_HEIGHT_INDEX
, make_number (1));
5279 if (UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
5280 ASET (lface
, LFACE_WEIGHT_INDEX
, Qnormal
);
5281 if (UNSPECIFIEDP (LFACE_SLANT (lface
)))
5282 ASET (lface
, LFACE_SLANT_INDEX
, Qnormal
);
5283 if (UNSPECIFIEDP (LFACE_FONTSET (lface
)))
5284 ASET (lface
, LFACE_FONTSET_INDEX
, Qnil
);
5287 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
5288 ASET (lface
, LFACE_UNDERLINE_INDEX
, Qnil
);
5290 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
5291 ASET (lface
, LFACE_OVERLINE_INDEX
, Qnil
);
5293 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
5294 ASET (lface
, LFACE_STRIKE_THROUGH_INDEX
, Qnil
);
5296 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
5297 ASET (lface
, LFACE_BOX_INDEX
, Qnil
);
5299 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
5300 ASET (lface
, LFACE_INVERSE_INDEX
, Qnil
);
5302 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
5304 /* This function is called so early that colors are not yet
5305 set in the frame parameter list. */
5306 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
5308 if (CONSP (color
) && STRINGP (XCDR (color
)))
5309 ASET (lface
, LFACE_FOREGROUND_INDEX
, XCDR (color
));
5310 else if (FRAME_WINDOW_P (f
))
5312 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5313 ASET (lface
, LFACE_FOREGROUND_INDEX
, build_string (unspecified_fg
));
5318 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
5320 /* This function is called so early that colors are not yet
5321 set in the frame parameter list. */
5322 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
5323 if (CONSP (color
) && STRINGP (XCDR (color
)))
5324 ASET (lface
, LFACE_BACKGROUND_INDEX
, XCDR (color
));
5325 else if (FRAME_WINDOW_P (f
))
5327 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5328 ASET (lface
, LFACE_BACKGROUND_INDEX
, build_string (unspecified_bg
));
5333 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
5334 ASET (lface
, LFACE_STIPPLE_INDEX
, Qnil
);
5336 /* Realize the face; it must be fully-specified now. */
5337 eassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
5338 check_lface (lface
);
5339 memcpy (attrs
, XVECTOR (lface
)->contents
, sizeof attrs
);
5340 face
= realize_face (c
, attrs
, DEFAULT_FACE_ID
);
5342 #ifdef HAVE_WINDOW_SYSTEM
5343 #ifdef HAVE_X_WINDOWS
5344 if (FRAME_X_P (f
) && face
->font
!= FRAME_FONT (f
))
5346 /* This can happen when making a frame on a display that does
5347 not support the default font. */
5351 /* Otherwise, the font specified for the frame was not
5352 acceptable as a font for the default face (perhaps because
5353 auto-scaled fonts are rejected), so we must adjust the frame
5355 x_set_font (f
, LFACE_FONT (lface
), Qnil
);
5357 #endif /* HAVE_X_WINDOWS */
5358 #endif /* HAVE_WINDOW_SYSTEM */
5363 /* Realize basic faces other than the default face in face cache C.
5364 SYMBOL is the face name, ID is the face id the realized face must
5365 have. The default face must have been realized already. */
5368 realize_named_face (struct frame
*f
, Lisp_Object symbol
, int id
)
5370 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5371 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
5372 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5373 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5375 /* The default face must exist and be fully specified. */
5376 get_lface_attributes_no_remap (f
, Qdefault
, attrs
, 1);
5377 check_lface_attrs (attrs
);
5378 eassert (lface_fully_specified_p (attrs
));
5380 /* If SYMBOL isn't know as a face, create it. */
5384 XSETFRAME (frame
, f
);
5385 lface
= Finternal_make_lisp_face (symbol
, frame
);
5388 /* Merge SYMBOL's face with the default face. */
5389 get_lface_attributes_no_remap (f
, symbol
, symbol_attrs
, 1);
5390 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
5392 /* Realize the face. */
5393 realize_face (c
, attrs
, id
);
5397 /* Realize the fully-specified face with attributes ATTRS in face
5398 cache CACHE for ASCII characters. If FORMER_FACE_ID is
5399 non-negative, it is an ID of face to remove before caching the new
5400 face. Value is a pointer to the newly created realized face. */
5402 static struct face
*
5403 realize_face (struct face_cache
*cache
, Lisp_Object attrs
[LFACE_VECTOR_SIZE
],
5408 /* LFACE must be fully specified. */
5409 eassert (cache
!= NULL
);
5410 check_lface_attrs (attrs
);
5412 if (former_face_id
>= 0 && cache
->used
> former_face_id
)
5414 /* Remove the former face. */
5415 struct face
*former_face
= cache
->faces_by_id
[former_face_id
];
5416 uncache_face (cache
, former_face
);
5417 free_realized_face (cache
->f
, former_face
);
5418 SET_FRAME_GARBAGED (cache
->f
);
5421 if (FRAME_WINDOW_P (cache
->f
))
5422 face
= realize_x_face (cache
, attrs
);
5423 else if (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
))
5424 face
= realize_tty_face (cache
, attrs
);
5425 else if (FRAME_INITIAL_P (cache
->f
))
5427 /* Create a dummy face. */
5428 face
= make_realized_face (attrs
);
5433 /* Insert the new face. */
5434 cache_face (cache
, face
, lface_hash (attrs
));
5439 #ifdef HAVE_WINDOW_SYSTEM
5440 /* Realize the fully-specified face that uses FONT-OBJECT and has the
5441 same attributes as BASE_FACE except for the font on frame F.
5442 FONT-OBJECT may be nil, in which case, realized a face of
5445 static struct face
*
5446 realize_non_ascii_face (struct frame
*f
, Lisp_Object font_object
,
5447 struct face
*base_face
)
5449 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5452 face
= xmalloc (sizeof *face
);
5457 = (! NILP (font_object
)
5458 && FONT_WEIGHT_NAME_NUMERIC (face
->lface
[LFACE_WEIGHT_INDEX
]) > 100
5459 && FONT_WEIGHT_NUMERIC (font_object
) <= 100);
5461 /* Don't try to free the colors copied bitwise from BASE_FACE. */
5462 face
->colors_copied_bitwise_p
= 1;
5463 face
->font
= NILP (font_object
) ? NULL
: XFONT_OBJECT (font_object
);
5466 cache_face (cache
, face
, face
->hash
);
5470 #endif /* HAVE_WINDOW_SYSTEM */
5473 /* Realize the fully-specified face with attributes ATTRS in face
5474 cache CACHE for ASCII characters. Do it for X frame CACHE->f. If
5475 the new face doesn't share font with the default face, a fontname
5476 is allocated from the heap and set in `font_name' of the new face,
5477 but it is not yet loaded here. Value is a pointer to the newly
5478 created realized face. */
5480 static struct face
*
5481 realize_x_face (struct face_cache
*cache
, Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
5483 struct face
*face
= NULL
;
5484 #ifdef HAVE_WINDOW_SYSTEM
5485 struct face
*default_face
;
5487 Lisp_Object stipple
, underline
, overline
, strike_through
, box
;
5489 eassert (FRAME_WINDOW_P (cache
->f
));
5491 /* Allocate a new realized face. */
5492 face
= make_realized_face (attrs
);
5493 face
->ascii_face
= face
;
5497 /* Determine the font to use. Most of the time, the font will be
5498 the same as the font of the default face, so try that first. */
5499 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5501 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
5503 face
->font
= default_face
->font
;
5505 = make_fontset_for_ascii_face (f
, default_face
->fontset
, face
);
5509 /* If the face attribute ATTRS specifies a fontset, use it as
5510 the base of a new realized fontset. Otherwise, use the same
5511 base fontset as of the default face. The base determines
5512 registry and encoding of a font. It may also determine
5513 foundry and family. The other fields of font name pattern
5514 are constructed from ATTRS. */
5515 int fontset
= face_fontset (attrs
);
5517 /* If we are realizing the default face, ATTRS should specify a
5518 fontset. In other words, if FONTSET is -1, we are not
5519 realizing the default face, thus the default face should have
5520 already been realized. */
5524 fontset
= default_face
->fontset
;
5528 if (! FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5529 attrs
[LFACE_FONT_INDEX
]
5530 = font_load_for_lface (f
, attrs
, attrs
[LFACE_FONT_INDEX
]);
5531 if (FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5533 face
->font
= XFONT_OBJECT (attrs
[LFACE_FONT_INDEX
]);
5534 face
->fontset
= make_fontset_for_ascii_face (f
, fontset
, face
);
5544 && FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]) > 100
5545 && FONT_WEIGHT_NUMERIC (attrs
[LFACE_FONT_INDEX
]) <= 100)
5546 face
->overstrike
= 1;
5548 /* Load colors, and set remaining attributes. */
5550 load_face_colors (f
, face
, attrs
);
5553 box
= attrs
[LFACE_BOX_INDEX
];
5556 /* A simple box of line width 1 drawn in color given by
5558 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
5560 face
->box
= FACE_SIMPLE_BOX
;
5561 face
->box_line_width
= 1;
5563 else if (INTEGERP (box
))
5565 /* Simple box of specified line width in foreground color of the
5567 eassert (XINT (box
) != 0);
5568 face
->box
= FACE_SIMPLE_BOX
;
5569 face
->box_line_width
= XINT (box
);
5570 face
->box_color
= face
->foreground
;
5571 face
->box_color_defaulted_p
= 1;
5573 else if (CONSP (box
))
5575 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
5576 being one of `raised' or `sunken'. */
5577 face
->box
= FACE_SIMPLE_BOX
;
5578 face
->box_color
= face
->foreground
;
5579 face
->box_color_defaulted_p
= 1;
5580 face
->box_line_width
= 1;
5584 Lisp_Object keyword
, value
;
5586 keyword
= XCAR (box
);
5594 if (EQ (keyword
, QCline_width
))
5596 if (INTEGERP (value
) && XINT (value
) != 0)
5597 face
->box_line_width
= XINT (value
);
5599 else if (EQ (keyword
, QCcolor
))
5601 if (STRINGP (value
))
5603 face
->box_color
= load_color (f
, face
, value
,
5605 face
->use_box_color_for_shadows_p
= 1;
5608 else if (EQ (keyword
, QCstyle
))
5610 if (EQ (value
, Qreleased_button
))
5611 face
->box
= FACE_RAISED_BOX
;
5612 else if (EQ (value
, Qpressed_button
))
5613 face
->box
= FACE_SUNKEN_BOX
;
5618 /* Text underline, overline, strike-through. */
5620 underline
= attrs
[LFACE_UNDERLINE_INDEX
];
5621 if (EQ (underline
, Qt
))
5623 /* Use default color (same as foreground color). */
5624 face
->underline_p
= 1;
5625 face
->underline_type
= FACE_UNDER_LINE
;
5626 face
->underline_defaulted_p
= 1;
5627 face
->underline_color
= 0;
5629 else if (STRINGP (underline
))
5631 /* Use specified color. */
5632 face
->underline_p
= 1;
5633 face
->underline_type
= FACE_UNDER_LINE
;
5634 face
->underline_defaulted_p
= 0;
5635 face
->underline_color
5636 = load_color (f
, face
, underline
,
5637 LFACE_UNDERLINE_INDEX
);
5639 else if (NILP (underline
))
5641 face
->underline_p
= 0;
5642 face
->underline_defaulted_p
= 0;
5643 face
->underline_color
= 0;
5645 else if (CONSP (underline
))
5647 /* `(:color COLOR :style STYLE)'.
5648 STYLE being one of `line' or `wave'. */
5649 face
->underline_p
= 1;
5650 face
->underline_color
= 0;
5651 face
->underline_defaulted_p
= 1;
5652 face
->underline_type
= FACE_UNDER_LINE
;
5654 /* FIXME? This is also not robust about checking the precise form.
5655 See comments in Finternal_set_lisp_face_attribute. */
5656 while (CONSP (underline
))
5658 Lisp_Object keyword
, value
;
5660 keyword
= XCAR (underline
);
5661 underline
= XCDR (underline
);
5663 if (!CONSP (underline
))
5665 value
= XCAR (underline
);
5666 underline
= XCDR (underline
);
5668 if (EQ (keyword
, QCcolor
))
5670 if (EQ (value
, Qforeground_color
))
5672 face
->underline_defaulted_p
= 1;
5673 face
->underline_color
= 0;
5675 else if (STRINGP (value
))
5677 face
->underline_defaulted_p
= 0;
5678 face
->underline_color
= load_color (f
, face
, value
,
5679 LFACE_UNDERLINE_INDEX
);
5682 else if (EQ (keyword
, QCstyle
))
5684 if (EQ (value
, Qline
))
5685 face
->underline_type
= FACE_UNDER_LINE
;
5686 else if (EQ (value
, Qwave
))
5687 face
->underline_type
= FACE_UNDER_WAVE
;
5692 overline
= attrs
[LFACE_OVERLINE_INDEX
];
5693 if (STRINGP (overline
))
5695 face
->overline_color
5696 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
5697 LFACE_OVERLINE_INDEX
);
5698 face
->overline_p
= 1;
5700 else if (EQ (overline
, Qt
))
5702 face
->overline_color
= face
->foreground
;
5703 face
->overline_color_defaulted_p
= 1;
5704 face
->overline_p
= 1;
5707 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
5708 if (STRINGP (strike_through
))
5710 face
->strike_through_color
5711 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
5712 LFACE_STRIKE_THROUGH_INDEX
);
5713 face
->strike_through_p
= 1;
5715 else if (EQ (strike_through
, Qt
))
5717 face
->strike_through_color
= face
->foreground
;
5718 face
->strike_through_color_defaulted_p
= 1;
5719 face
->strike_through_p
= 1;
5722 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
5723 if (!NILP (stipple
))
5724 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
5725 #endif /* HAVE_WINDOW_SYSTEM */
5731 /* Map a specified color of face FACE on frame F to a tty color index.
5732 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
5733 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
5734 default foreground/background colors. */
5737 map_tty_color (struct frame
*f
, struct face
*face
,
5738 enum lface_attribute_index idx
, int *defaulted
)
5740 Lisp_Object frame
, color
, def
;
5741 int foreground_p
= idx
== LFACE_FOREGROUND_INDEX
;
5742 unsigned long default_pixel
=
5743 foreground_p
? FACE_TTY_DEFAULT_FG_COLOR
: FACE_TTY_DEFAULT_BG_COLOR
;
5744 unsigned long pixel
= default_pixel
;
5746 unsigned long default_other_pixel
=
5747 foreground_p
? FACE_TTY_DEFAULT_BG_COLOR
: FACE_TTY_DEFAULT_FG_COLOR
;
5750 eassert (idx
== LFACE_FOREGROUND_INDEX
|| idx
== LFACE_BACKGROUND_INDEX
);
5752 XSETFRAME (frame
, f
);
5753 color
= face
->lface
[idx
];
5757 && CONSP (Vtty_defined_color_alist
)
5758 && (def
= assq_no_quit (color
, call1 (Qtty_color_alist
, frame
)),
5761 /* Associations in tty-defined-color-alist are of the form
5762 (NAME INDEX R G B). We need the INDEX part. */
5763 pixel
= XINT (XCAR (XCDR (def
)));
5766 if (pixel
== default_pixel
&& STRINGP (color
))
5768 pixel
= load_color (f
, face
, color
, idx
);
5771 /* If the foreground of the default face is the default color,
5772 use the foreground color defined by the frame. */
5773 if (FRAME_MSDOS_P (f
))
5775 if (pixel
== default_pixel
5776 || pixel
== FACE_TTY_DEFAULT_COLOR
)
5779 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5781 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5782 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5785 else if (pixel
== default_other_pixel
)
5788 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5790 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5791 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5799 face
->foreground
= pixel
;
5801 face
->background
= pixel
;
5805 /* Realize the fully-specified face with attributes ATTRS in face
5806 cache CACHE for ASCII characters. Do it for TTY frame CACHE->f.
5807 Value is a pointer to the newly created realized face. */
5809 static struct face
*
5810 realize_tty_face (struct face_cache
*cache
,
5811 Lisp_Object attrs
[LFACE_VECTOR_SIZE
])
5815 int face_colors_defaulted
= 0;
5816 struct frame
*f
= cache
->f
;
5818 /* Frame must be a termcap frame. */
5819 eassert (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
));
5821 /* Allocate a new realized face. */
5822 face
= make_realized_face (attrs
);
5824 face
->font_name
= FRAME_MSDOS_P (cache
->f
) ? "ms-dos" : "tty";
5827 /* Map face attributes to TTY appearances. */
5828 weight
= FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]);
5829 slant
= FONT_SLANT_NAME_NUMERIC (attrs
[LFACE_SLANT_INDEX
]);
5831 face
->tty_bold_p
= 1;
5833 face
->tty_italic_p
= 1;
5834 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5835 face
->tty_underline_p
= 1;
5836 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
5837 face
->tty_reverse_p
= 1;
5839 /* Map color names to color indices. */
5840 map_tty_color (f
, face
, LFACE_FOREGROUND_INDEX
, &face_colors_defaulted
);
5841 map_tty_color (f
, face
, LFACE_BACKGROUND_INDEX
, &face_colors_defaulted
);
5843 /* Swap colors if face is inverse-video. If the colors are taken
5844 from the frame colors, they are already inverted, since the
5845 frame-creation function calls x-handle-reverse-video. */
5846 if (face
->tty_reverse_p
&& !face_colors_defaulted
)
5848 unsigned long tem
= face
->foreground
;
5849 face
->foreground
= face
->background
;
5850 face
->background
= tem
;
5853 if (tty_suppress_bold_inverse_default_colors_p
5855 && face
->background
== FACE_TTY_DEFAULT_FG_COLOR
5856 && face
->foreground
== FACE_TTY_DEFAULT_BG_COLOR
)
5857 face
->tty_bold_p
= 0;
5863 DEFUN ("tty-suppress-bold-inverse-default-colors",
5864 Ftty_suppress_bold_inverse_default_colors
,
5865 Stty_suppress_bold_inverse_default_colors
, 1, 1, 0,
5866 doc
: /* Suppress/allow boldness of faces with inverse default colors.
5867 SUPPRESS non-nil means suppress it.
5868 This affects bold faces on TTYs whose foreground is the default background
5869 color of the display and whose background is the default foreground color.
5870 For such faces, the bold face attribute is ignored if this variable
5872 (Lisp_Object suppress
)
5874 tty_suppress_bold_inverse_default_colors_p
= !NILP (suppress
);
5875 ++face_change_count
;
5881 /***********************************************************************
5883 ***********************************************************************/
5885 /* Return the ID of the face to use to display character CH with face
5886 property PROP on frame F in current_buffer. */
5889 compute_char_face (struct frame
*f
, int ch
, Lisp_Object prop
)
5893 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
5898 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5899 face_id
= FACE_FOR_CHAR (f
, face
, ch
, -1, Qnil
);
5903 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5904 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5905 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
5906 merge_face_ref (f
, prop
, attrs
, 1, 0);
5907 face_id
= lookup_face (f
, attrs
);
5913 /* Return the face ID associated with buffer position POS for
5914 displaying ASCII characters. Return in *ENDPTR the position at
5915 which a different face is needed, as far as text properties and
5916 overlays are concerned. W is a window displaying current_buffer.
5918 REGION_BEG, REGION_END delimit the region, so it can be
5921 LIMIT is a position not to scan beyond. That is to limit the time
5922 this function can take.
5924 If MOUSE is non-zero, use the character's mouse-face, not its face.
5926 BASE_FACE_ID, if non-negative, specifies a base face id to use
5927 instead of DEFAULT_FACE_ID.
5929 The face returned is suitable for displaying ASCII characters. */
5932 face_at_buffer_position (struct window
*w
, ptrdiff_t pos
,
5933 ptrdiff_t region_beg
, ptrdiff_t region_end
,
5934 ptrdiff_t *endptr
, ptrdiff_t limit
,
5935 int mouse
, int base_face_id
)
5937 struct frame
*f
= XFRAME (w
->frame
);
5938 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5939 Lisp_Object prop
, position
;
5940 ptrdiff_t i
, noverlays
;
5941 Lisp_Object
*overlay_vec
;
5943 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
5944 Lisp_Object limit1
, end
;
5945 struct face
*default_face
;
5947 /* W must display the current buffer. We could write this function
5948 to use the frame and buffer of W, but right now it doesn't. */
5949 /* eassert (XBUFFER (w->contents) == current_buffer); */
5951 XSETFASTINT (position
, pos
);
5954 if (pos
< region_beg
&& region_beg
< endpos
)
5955 endpos
= region_beg
;
5957 /* Get the `face' or `mouse_face' text property at POS, and
5958 determine the next position at which the property changes. */
5959 prop
= Fget_text_property (position
, propname
, w
->contents
);
5960 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
5961 end
= Fnext_single_property_change (position
, propname
, w
->contents
, limit1
);
5963 endpos
= XINT (end
);
5965 /* Look at properties from overlays. */
5967 ptrdiff_t next_overlay
;
5969 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, &next_overlay
, 0);
5970 if (next_overlay
< endpos
)
5971 endpos
= next_overlay
;
5979 if (base_face_id
>= 0)
5980 face_id
= base_face_id
;
5981 else if (NILP (Vface_remapping_alist
))
5982 face_id
= DEFAULT_FACE_ID
;
5984 face_id
= lookup_basic_face (f
, DEFAULT_FACE_ID
);
5986 default_face
= FACE_FROM_ID (f
, face_id
);
5989 /* Optimize common cases where we can use the default face. */
5992 && !(pos
>= region_beg
&& pos
< region_end
))
5993 return default_face
->id
;
5995 /* Begin with attributes from the default face. */
5996 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
5998 /* Merge in attributes specified via text properties. */
6000 merge_face_ref (f
, prop
, attrs
, 1, 0);
6002 /* Now merge the overlay data. */
6003 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6004 for (i
= 0; i
< noverlays
; i
++)
6009 prop
= Foverlay_get (overlay_vec
[i
], propname
);
6011 merge_face_ref (f
, prop
, attrs
, 1, 0);
6013 oend
= OVERLAY_END (overlay_vec
[i
]);
6014 oendpos
= OVERLAY_POSITION (oend
);
6015 if (oendpos
< endpos
)
6019 /* If in the region, merge in the region face. */
6020 if (pos
>= region_beg
&& pos
< region_end
)
6022 merge_named_face (f
, Qregion
, attrs
, 0);
6024 if (region_end
< endpos
)
6025 endpos
= region_end
;
6030 /* Look up a realized face with the given face attributes,
6031 or realize a new one for ASCII characters. */
6032 return lookup_face (f
, attrs
);
6035 /* Return the face ID at buffer position POS for displaying ASCII
6036 characters associated with overlay strings for overlay OVERLAY.
6038 Like face_at_buffer_position except for OVERLAY. Currently it
6039 simply disregards the `face' properties of all overlays. */
6042 face_for_overlay_string (struct window
*w
, ptrdiff_t pos
,
6043 ptrdiff_t region_beg
, ptrdiff_t region_end
,
6044 ptrdiff_t *endptr
, ptrdiff_t limit
,
6045 int mouse
, Lisp_Object overlay
)
6047 struct frame
*f
= XFRAME (w
->frame
);
6048 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6049 Lisp_Object prop
, position
;
6051 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
6052 Lisp_Object limit1
, end
;
6053 struct face
*default_face
;
6055 /* W must display the current buffer. We could write this function
6056 to use the frame and buffer of W, but right now it doesn't. */
6057 /* eassert (XBUFFER (w->contents) == current_buffer); */
6059 XSETFASTINT (position
, pos
);
6062 if (pos
< region_beg
&& region_beg
< endpos
)
6063 endpos
= region_beg
;
6065 /* Get the `face' or `mouse_face' text property at POS, and
6066 determine the next position at which the property changes. */
6067 prop
= Fget_text_property (position
, propname
, w
->contents
);
6068 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6069 end
= Fnext_single_property_change (position
, propname
, w
->contents
, limit1
);
6071 endpos
= XINT (end
);
6075 /* Optimize common case where we can use the default face. */
6077 && !(pos
>= region_beg
&& pos
< region_end
)
6078 && NILP (Vface_remapping_alist
))
6079 return DEFAULT_FACE_ID
;
6081 /* Begin with attributes from the default face. */
6082 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
6083 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6085 /* Merge in attributes specified via text properties. */
6087 merge_face_ref (f
, prop
, attrs
, 1, 0);
6089 /* If in the region, merge in the region face. */
6090 if (pos
>= region_beg
&& pos
< region_end
)
6092 merge_named_face (f
, Qregion
, attrs
, 0);
6094 if (region_end
< endpos
)
6095 endpos
= region_end
;
6100 /* Look up a realized face with the given face attributes,
6101 or realize a new one for ASCII characters. */
6102 return lookup_face (f
, attrs
);
6106 /* Compute the face at character position POS in Lisp string STRING on
6107 window W, for ASCII characters.
6109 If STRING is an overlay string, it comes from position BUFPOS in
6110 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
6111 not an overlay string. W must display the current buffer.
6112 REGION_BEG and REGION_END give the start and end positions of the
6113 region; both are -1 if no region is visible.
6115 BASE_FACE_ID is the id of a face to merge with. For strings coming
6116 from overlays or the `display' property it is the face at BUFPOS.
6118 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
6120 Set *ENDPTR to the next position where to check for faces in
6121 STRING; -1 if the face is constant from POS to the end of the
6124 Value is the id of the face to use. The face returned is suitable
6125 for displaying ASCII characters. */
6128 face_at_string_position (struct window
*w
, Lisp_Object string
,
6129 ptrdiff_t pos
, ptrdiff_t bufpos
,
6130 ptrdiff_t region_beg
, ptrdiff_t region_end
,
6131 ptrdiff_t *endptr
, enum face_id base_face_id
,
6134 Lisp_Object prop
, position
, end
, limit
;
6135 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6136 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6137 struct face
*base_face
;
6138 bool multibyte_p
= STRING_MULTIBYTE (string
);
6139 Lisp_Object prop_name
= mouse_p
? Qmouse_face
: Qface
;
6141 /* Get the value of the face property at the current position within
6142 STRING. Value is nil if there is no face property. */
6143 XSETFASTINT (position
, pos
);
6144 prop
= Fget_text_property (position
, prop_name
, string
);
6146 /* Get the next position at which to check for faces. Value of end
6147 is nil if face is constant all the way to the end of the string.
6148 Otherwise it is a string position where to check faces next.
6149 Limit is the maximum position up to which to check for property
6150 changes in Fnext_single_property_change. Strings are usually
6151 short, so set the limit to the end of the string. */
6152 XSETFASTINT (limit
, SCHARS (string
));
6153 end
= Fnext_single_property_change (position
, prop_name
, string
, limit
);
6155 *endptr
= XFASTINT (end
);
6159 base_face
= FACE_FROM_ID (f
, base_face_id
);
6160 eassert (base_face
);
6162 /* Optimize the default case that there is no face property and we
6163 are not in the region. */
6165 && (base_face_id
!= DEFAULT_FACE_ID
6166 /* BUFPOS <= 0 means STRING is not an overlay string, so
6167 that the region doesn't have to be taken into account. */
6169 || bufpos
< region_beg
6170 || bufpos
>= region_end
)
6172 /* We can't realize faces for different charsets differently
6173 if we don't have fonts, so we can stop here if not working
6174 on a window-system frame. */
6175 || !FRAME_WINDOW_P (f
)
6176 || FACE_SUITABLE_FOR_ASCII_CHAR_P (base_face
, 0)))
6177 return base_face
->id
;
6179 /* Begin with attributes from the base face. */
6180 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6182 /* Merge in attributes specified via text properties. */
6184 merge_face_ref (f
, prop
, attrs
, 1, 0);
6186 /* If in the region, merge in the region face. */
6188 && bufpos
>= region_beg
6189 && bufpos
< region_end
)
6190 merge_named_face (f
, Qregion
, attrs
, 0);
6192 /* Look up a realized face with the given face attributes,
6193 or realize a new one for ASCII characters. */
6194 return lookup_face (f
, attrs
);
6198 /* Merge a face into a realized face.
6200 F is frame where faces are (to be) realized.
6202 FACE_NAME is named face to merge.
6204 If FACE_NAME is nil, FACE_ID is face_id of realized face to merge.
6206 If FACE_NAME is t, FACE_ID is lface_id of face to merge.
6208 BASE_FACE_ID is realized face to merge into.
6214 merge_faces (struct frame
*f
, Lisp_Object face_name
, int face_id
,
6217 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6218 struct face
*base_face
;
6220 base_face
= FACE_FROM_ID (f
, base_face_id
);
6222 return base_face_id
;
6224 if (EQ (face_name
, Qt
))
6226 if (face_id
< 0 || face_id
>= lface_id_to_name_size
)
6227 return base_face_id
;
6228 face_name
= lface_id_to_name
[face_id
];
6229 /* When called during make-frame, lookup_derived_face may fail
6230 if the faces are uninitialized. Don't signal an error. */
6231 face_id
= lookup_derived_face (f
, face_name
, base_face_id
, 0);
6232 return (face_id
>= 0 ? face_id
: base_face_id
);
6235 /* Begin with attributes from the base face. */
6236 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6238 if (!NILP (face_name
))
6240 if (!merge_named_face (f
, face_name
, attrs
, 0))
6241 return base_face_id
;
6247 return base_face_id
;
6248 face
= FACE_FROM_ID (f
, face_id
);
6250 return base_face_id
;
6251 merge_face_vectors (f
, face
->lface
, attrs
, 0);
6254 /* Look up a realized face with the given face attributes,
6255 or realize a new one for ASCII characters. */
6256 return lookup_face (f
, attrs
);
6261 #ifndef HAVE_X_WINDOWS
6262 DEFUN ("x-load-color-file", Fx_load_color_file
,
6263 Sx_load_color_file
, 1, 1, 0,
6264 doc
: /* Create an alist of color entries from an external file.
6266 The file should define one named RGB color per line like so:
6268 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6269 (Lisp_Object filename
)
6272 Lisp_Object cmap
= Qnil
;
6273 Lisp_Object abspath
;
6275 CHECK_STRING (filename
);
6276 abspath
= Fexpand_file_name (filename
, Qnil
);
6279 fp
= emacs_fopen (SSDATA (abspath
), "rt");
6283 int red
, green
, blue
;
6286 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
6287 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
6290 int color
= RGB (red
, green
, blue
);
6292 int color
= (red
<< 16) | (green
<< 8) | blue
;
6294 char *name
= buf
+ num
;
6295 ptrdiff_t len
= strlen (name
);
6296 len
-= 0 < len
&& name
[len
- 1] == '\n';
6297 cmap
= Fcons (Fcons (make_string (name
, len
), make_number (color
)),
6309 /***********************************************************************
6311 ***********************************************************************/
6315 /* Print the contents of the realized face FACE to stderr. */
6318 dump_realized_face (struct face
*face
)
6320 fprintf (stderr
, "ID: %d\n", face
->id
);
6321 #ifdef HAVE_X_WINDOWS
6322 fprintf (stderr
, "gc: %ld\n", (long) face
->gc
);
6324 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
6326 SDATA (face
->lface
[LFACE_FOREGROUND_INDEX
]));
6327 fprintf (stderr
, "background: 0x%lx (%s)\n",
6329 SDATA (face
->lface
[LFACE_BACKGROUND_INDEX
]));
6331 fprintf (stderr
, "font_name: %s (%s)\n",
6332 SDATA (face
->font
->props
[FONT_NAME_INDEX
]),
6333 SDATA (face
->lface
[LFACE_FAMILY_INDEX
]));
6334 #ifdef HAVE_X_WINDOWS
6335 fprintf (stderr
, "font = %p\n", face
->font
);
6337 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
6338 fprintf (stderr
, "underline: %d (%s)\n",
6340 SDATA (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
])));
6341 fprintf (stderr
, "hash: %d\n", face
->hash
);
6345 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, doc
: /* */)
6352 fprintf (stderr
, "font selection order: ");
6353 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6354 fprintf (stderr
, "%d ", font_sort_order
[i
]);
6355 fprintf (stderr
, "\n");
6357 fprintf (stderr
, "alternative fonts: ");
6358 debug_print (Vface_alternative_font_family_alist
);
6359 fprintf (stderr
, "\n");
6361 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
6362 Fdump_face (make_number (i
));
6368 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
6370 error ("Not a valid face");
6371 dump_realized_face (face
);
6378 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
6379 0, 0, 0, doc
: /* */)
6382 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
6383 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
6384 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
6388 #endif /* GLYPH_DEBUG */
6392 /***********************************************************************
6394 ***********************************************************************/
6397 syms_of_xfaces (void)
6399 DEFSYM (Qface
, "face");
6400 DEFSYM (Qface_no_inherit
, "face-no-inherit");
6401 DEFSYM (Qbitmap_spec_p
, "bitmap-spec-p");
6402 DEFSYM (Qframe_set_background_mode
, "frame-set-background-mode");
6404 /* Lisp face attribute keywords. */
6405 DEFSYM (QCfamily
, ":family");
6406 DEFSYM (QCheight
, ":height");
6407 DEFSYM (QCweight
, ":weight");
6408 DEFSYM (QCslant
, ":slant");
6409 DEFSYM (QCunderline
, ":underline");
6410 DEFSYM (QCinverse_video
, ":inverse-video");
6411 DEFSYM (QCreverse_video
, ":reverse-video");
6412 DEFSYM (QCforeground
, ":foreground");
6413 DEFSYM (QCbackground
, ":background");
6414 DEFSYM (QCstipple
, ":stipple");
6415 DEFSYM (QCwidth
, ":width");
6416 DEFSYM (QCfont
, ":font");
6417 DEFSYM (QCfontset
, ":fontset");
6418 DEFSYM (QCbold
, ":bold");
6419 DEFSYM (QCitalic
, ":italic");
6420 DEFSYM (QCoverline
, ":overline");
6421 DEFSYM (QCstrike_through
, ":strike-through");
6422 DEFSYM (QCbox
, ":box");
6423 DEFSYM (QCinherit
, ":inherit");
6425 /* Symbols used for Lisp face attribute values. */
6426 DEFSYM (QCcolor
, ":color");
6427 DEFSYM (QCline_width
, ":line-width");
6428 DEFSYM (QCstyle
, ":style");
6429 DEFSYM (Qline
, "line");
6430 DEFSYM (Qwave
, "wave");
6431 DEFSYM (Qreleased_button
, "released-button");
6432 DEFSYM (Qpressed_button
, "pressed-button");
6433 DEFSYM (Qnormal
, "normal");
6434 DEFSYM (Qextra_light
, "extra-light");
6435 DEFSYM (Qlight
, "light");
6436 DEFSYM (Qsemi_light
, "semi-light");
6437 DEFSYM (Qsemi_bold
, "semi-bold");
6438 DEFSYM (Qbold
, "bold");
6439 DEFSYM (Qextra_bold
, "extra-bold");
6440 DEFSYM (Qultra_bold
, "ultra-bold");
6441 DEFSYM (Qoblique
, "oblique");
6442 DEFSYM (Qitalic
, "italic");
6443 DEFSYM (Qbackground_color
, "background-color");
6444 DEFSYM (Qforeground_color
, "foreground-color");
6445 DEFSYM (Qunspecified
, "unspecified");
6446 DEFSYM (QCignore_defface
, ":ignore-defface");
6448 DEFSYM (Qface_alias
, "face-alias");
6449 DEFSYM (Qdefault
, "default");
6450 DEFSYM (Qtool_bar
, "tool-bar");
6451 DEFSYM (Qregion
, "region");
6452 DEFSYM (Qfringe
, "fringe");
6453 DEFSYM (Qheader_line
, "header-line");
6454 DEFSYM (Qscroll_bar
, "scroll-bar");
6455 DEFSYM (Qmenu
, "menu");
6456 DEFSYM (Qcursor
, "cursor");
6457 DEFSYM (Qborder
, "border");
6458 DEFSYM (Qmouse
, "mouse");
6459 DEFSYM (Qmode_line_inactive
, "mode-line-inactive");
6460 DEFSYM (Qvertical_border
, "vertical-border");
6461 DEFSYM (Qtty_color_desc
, "tty-color-desc");
6462 DEFSYM (Qtty_color_standard_values
, "tty-color-standard-values");
6463 DEFSYM (Qtty_color_by_index
, "tty-color-by-index");
6464 DEFSYM (Qtty_color_alist
, "tty-color-alist");
6465 DEFSYM (Qscalable_fonts_allowed
, "scalable-fonts-allowed");
6467 Vparam_value_alist
= list1 (Fcons (Qnil
, Qnil
));
6468 staticpro (&Vparam_value_alist
);
6469 Vface_alternative_font_family_alist
= Qnil
;
6470 staticpro (&Vface_alternative_font_family_alist
);
6471 Vface_alternative_font_registry_alist
= Qnil
;
6472 staticpro (&Vface_alternative_font_registry_alist
);
6474 defsubr (&Sinternal_make_lisp_face
);
6475 defsubr (&Sinternal_lisp_face_p
);
6476 defsubr (&Sinternal_set_lisp_face_attribute
);
6477 #ifdef HAVE_WINDOW_SYSTEM
6478 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
6480 defsubr (&Scolor_gray_p
);
6481 defsubr (&Scolor_supported_p
);
6482 #ifndef HAVE_X_WINDOWS
6483 defsubr (&Sx_load_color_file
);
6485 defsubr (&Sface_attribute_relative_p
);
6486 defsubr (&Smerge_face_attribute
);
6487 defsubr (&Sinternal_get_lisp_face_attribute
);
6488 defsubr (&Sinternal_lisp_face_attribute_values
);
6489 defsubr (&Sinternal_lisp_face_equal_p
);
6490 defsubr (&Sinternal_lisp_face_empty_p
);
6491 defsubr (&Sinternal_copy_lisp_face
);
6492 defsubr (&Sinternal_merge_in_global_face
);
6493 defsubr (&Sface_font
);
6494 defsubr (&Sframe_face_alist
);
6495 defsubr (&Sdisplay_supports_face_attributes_p
);
6496 defsubr (&Scolor_distance
);
6497 defsubr (&Sinternal_set_font_selection_order
);
6498 defsubr (&Sinternal_set_alternative_font_family_alist
);
6499 defsubr (&Sinternal_set_alternative_font_registry_alist
);
6500 defsubr (&Sface_attributes_as_vector
);
6502 defsubr (&Sdump_face
);
6503 defsubr (&Sshow_face_resources
);
6504 #endif /* GLYPH_DEBUG */
6505 defsubr (&Sclear_face_cache
);
6506 defsubr (&Stty_suppress_bold_inverse_default_colors
);
6508 #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS
6509 defsubr (&Sdump_colors
);
6512 DEFVAR_LISP ("face-new-frame-defaults", Vface_new_frame_defaults
,
6513 doc
: /* List of global face definitions (for internal use only.) */);
6514 Vface_new_frame_defaults
= Qnil
;
6516 DEFVAR_LISP ("face-default-stipple", Vface_default_stipple
,
6517 doc
: /* Default stipple pattern used on monochrome displays.
6518 This stipple pattern is used on monochrome displays
6519 instead of shades of gray for a face background color.
6520 See `set-face-stipple' for possible values for this variable. */);
6521 Vface_default_stipple
= build_pure_c_string ("gray3");
6523 DEFVAR_LISP ("tty-defined-color-alist", Vtty_defined_color_alist
,
6524 doc
: /* An alist of defined terminal colors and their RGB values.
6525 See the docstring of `tty-color-alist' for the details. */);
6526 Vtty_defined_color_alist
= Qnil
;
6528 DEFVAR_LISP ("scalable-fonts-allowed", Vscalable_fonts_allowed
,
6529 doc
: /* Allowed scalable fonts.
6530 A value of nil means don't allow any scalable fonts.
6531 A value of t means allow any scalable font.
6532 Otherwise, value must be a list of regular expressions. A font may be
6533 scaled if its name matches a regular expression in the list.
6534 Note that if value is nil, a scalable font might still be used, if no
6535 other font of the appropriate family and registry is available. */);
6536 Vscalable_fonts_allowed
= Qnil
;
6538 DEFVAR_LISP ("face-ignored-fonts", Vface_ignored_fonts
,
6539 doc
: /* List of ignored fonts.
6540 Each element is a regular expression that matches names of fonts to
6542 Vface_ignored_fonts
= Qnil
;
6544 DEFVAR_LISP ("face-remapping-alist", Vface_remapping_alist
,
6545 doc
: /* Alist of face remappings.
6546 Each element is of the form:
6548 (FACE . REPLACEMENT),
6550 which causes display of the face FACE to use REPLACEMENT instead.
6551 REPLACEMENT is a face specification, i.e. one of the following:
6554 (2) a property list of attribute/value pairs, or
6555 (3) a list in which each element has the form of (1) or (2).
6557 List values for REPLACEMENT are merged to form the final face
6558 specification, with earlier entries taking precedence, in the same as
6559 as in the `face' text property.
6561 Face-name remapping cycles are suppressed; recursive references use
6562 the underlying face instead of the remapped face. So a remapping of
6565 (FACE EXTRA-FACE... FACE)
6569 (FACE (FACE-ATTR VAL ...) FACE)
6571 causes EXTRA-FACE... or (FACE-ATTR VAL ...) to be _merged_ with the
6572 existing definition of FACE. Note that this isn't necessary for the
6573 default face, since every face inherits from the default face.
6575 If this variable is made buffer-local, the face remapping takes effect
6576 only in that buffer. For instance, the mode my-mode could define a
6577 face `my-mode-default', and then in the mode setup function, do:
6579 (set (make-local-variable 'face-remapping-alist)
6580 '((default my-mode-default)))).
6582 Because Emacs normally only redraws screen areas when the underlying
6583 buffer contents change, you may need to call `redraw-display' after
6584 changing this variable for it to take effect. */);
6585 Vface_remapping_alist
= Qnil
;
6587 DEFVAR_LISP ("face-font-rescale-alist", Vface_font_rescale_alist
,
6588 doc
: /* Alist of fonts vs the rescaling factors.
6589 Each element is a cons (FONT-PATTERN . RESCALE-RATIO), where
6590 FONT-PATTERN is a font-spec or a regular expression matching a font name, and
6591 RESCALE-RATIO is a floating point number to specify how much larger
6592 \(or smaller) font we should use. For instance, if a face requests
6593 a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point. */);
6594 Vface_font_rescale_alist
= Qnil
;
6596 #ifdef HAVE_WINDOW_SYSTEM
6597 defsubr (&Sbitmap_spec_p
);
6598 defsubr (&Sx_list_fonts
);
6599 defsubr (&Sinternal_face_x_get_resource
);
6600 defsubr (&Sx_family_fonts
);