1 /* xfaces.c -- "Face" primitives.
3 Copyright (C) 1993-1994, 1998-2012 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 form of a struct face which is stored in the
116 face cache of the frame on which it was realized.
118 Face realization is done in the context of the character to display
119 because different fonts may be used for different characters. In
120 other words, for characters that have different font
121 specifications, different realized faces are needed to display
124 Font specification is done by fontsets. See the comment in
125 fontset.c for the details. In the current implementation, all ASCII
126 characters share the same font in a fontset.
128 Faces are at first realized for ASCII characters, and, at that
129 time, assigned a specific realized fontset. Hereafter, we call
130 such a face as `ASCII face'. When a face for a multibyte character
131 is realized, it inherits (thus shares) a fontset of an ASCII face
132 that has the same attributes other than font-related ones.
134 Thus, all realized faces have a realized fontset.
139 Unibyte text (i.e. raw 8-bit characters) is displayed with the same
140 font as ASCII characters. That is because it is expected that
141 unibyte text users specify a font that is suitable both for ASCII
142 and raw 8-bit characters.
147 Font selection tries to find the best available matching font for a
148 given (character, face) combination.
150 If the face specifies a fontset name, that fontset determines a
151 pattern for fonts of the given character. If the face specifies a
152 font name or the other font-related attributes, a fontset is
153 realized from the default fontset. In that case, that
154 specification determines a pattern for ASCII characters and the
155 default fontset determines a pattern for multibyte characters.
157 Available fonts on the system on which Emacs runs are then matched
158 against the font pattern. The result of font selection is the best
159 match for the given face attributes in this font list.
161 Font selection can be influenced by the user.
163 1. The user can specify the relative importance he gives the face
164 attributes width, height, weight, and slant by setting
165 face-font-selection-order (faces.el) to a list of face attribute
166 names. The default is '(:width :height :weight :slant), and means
167 that font selection first tries to find a good match for the font
168 width specified by a face, then---within fonts with that
169 width---tries to find a best match for the specified font height,
172 2. Setting face-font-family-alternatives allows the user to
173 specify alternative font families to try if a family specified by a
176 3. Setting face-font-registry-alternatives allows the user to
177 specify all alternative font registries to try for a face
178 specifying a registry.
180 4. Setting face-ignored-fonts allows the user to ignore specific
184 Character composition.
186 Usually, the realization process is already finished when Emacs
187 actually reflects the desired glyph matrix on the screen. However,
188 on displaying a composition (sequence of characters to be composed
189 on the screen), a suitable font for the components of the
190 composition is selected and realized while drawing them on the
191 screen, i.e. the realization process is delayed but in principle
195 Initialization of basic faces.
197 The faces `default', `modeline' are considered `basic faces'.
198 When redisplay happens the first time for a newly created frame,
199 basic faces are realized for CHARSET_ASCII. Frame parameters are
200 used to fill in unspecified attributes of the default face. */
204 #include <sys/types.h>
205 #include <sys/stat.h>
206 #include <stdio.h> /* This needs to be before termchar.h */
210 #include "character.h"
212 #include "keyboard.h"
214 #include "termhooks.h"
216 #ifdef HAVE_X_WINDOWS
220 #include <Xm/XmStrDefs.h>
221 #endif /* USE_MOTIF */
222 #endif /* HAVE_X_WINDOWS */
231 /* Redefine X specifics to W32 equivalents to avoid cluttering the
232 code with #ifdef blocks. */
233 #undef FRAME_X_DISPLAY_INFO
234 #define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO
235 #define x_display_info w32_display_info
236 #define check_x check_w32
237 #define GCGraphicsExposures 0
238 #endif /* WINDOWSNT */
242 #undef FRAME_X_DISPLAY_INFO
243 #define FRAME_X_DISPLAY_INFO FRAME_NS_DISPLAY_INFO
244 #define x_display_info ns_display_info
245 #define check_x check_ns
246 #define GCGraphicsExposures 0
250 #include "dispextern.h"
251 #include "blockinput.h"
253 #include "intervals.h"
254 #include "termchar.h"
257 #ifdef HAVE_WINDOW_SYSTEM
259 #endif /* HAVE_WINDOW_SYSTEM */
261 #ifdef HAVE_X_WINDOWS
263 /* Compensate for a bug in Xos.h on some systems, on which it requires
264 time.h. On some such systems, Xos.h tries to redefine struct
265 timeval and struct timezone if USG is #defined while it is
268 #ifdef XOS_NEEDS_TIME_H
274 #if defined USG || defined __TIMEVAL__ /* Don't warn about unused macros. */
276 #else /* not XOS_NEEDS_TIME_H */
278 #endif /* not XOS_NEEDS_TIME_H */
280 #endif /* HAVE_X_WINDOWS */
284 /* Number of pt per inch (from the TeXbook). */
286 #define PT_PER_INCH 72.27
288 /* Non-zero if face attribute ATTR is unspecified. */
290 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified)
292 /* Non-zero if face attribute ATTR is `ignore-defface'. */
294 #define IGNORE_DEFFACE_P(ATTR) EQ ((ATTR), QCignore_defface)
296 /* Value is the number of elements of VECTOR. */
298 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
300 /* Size of hash table of realized faces in face caches (should be a
303 #define FACE_CACHE_BUCKETS_SIZE 1001
305 /* Keyword symbols used for face attribute names. */
307 Lisp_Object QCfamily
, QCheight
, QCweight
, QCslant
;
308 static Lisp_Object QCunderline
;
309 static Lisp_Object QCinverse_video
, QCstipple
;
310 Lisp_Object QCforeground
, QCbackground
;
312 static Lisp_Object QCfont
, QCbold
, QCitalic
;
313 static Lisp_Object QCreverse_video
;
314 static Lisp_Object QCoverline
, QCstrike_through
, QCbox
, QCinherit
;
315 static Lisp_Object QCfontset
;
317 /* Symbols used for attribute values. */
321 static Lisp_Object Qline
, Qwave
;
322 static Lisp_Object Qultra_light
, Qextra_light
, Qlight
;
323 static Lisp_Object Qsemi_light
, Qsemi_bold
, Qextra_bold
, Qultra_bold
;
324 static Lisp_Object Qoblique
, Qreverse_oblique
, Qreverse_italic
;
326 static Lisp_Object Qultra_condensed
, Qextra_condensed
;
327 Lisp_Object Qcondensed
;
328 static Lisp_Object Qsemi_condensed
, Qsemi_expanded
, Qextra_expanded
;
329 Lisp_Object Qexpanded
;
330 static Lisp_Object Qultra_expanded
;
331 static Lisp_Object Qreleased_button
, Qpressed_button
;
332 static Lisp_Object QCstyle
, QCcolor
, QCline_width
;
333 Lisp_Object Qunspecified
; /* used in dosfns.c */
334 static Lisp_Object QCignore_defface
;
336 char unspecified_fg
[] = "unspecified-fg", unspecified_bg
[] = "unspecified-bg";
338 /* The name of the function to call when the background of the frame
339 has changed, frame_set_background_mode. */
341 static Lisp_Object Qframe_set_background_mode
;
343 /* Names of basic faces. */
345 Lisp_Object Qdefault
, Qtool_bar
, Qfringe
;
346 static Lisp_Object Qregion
;
347 Lisp_Object Qheader_line
, Qscroll_bar
, Qcursor
;
348 static Lisp_Object Qborder
, Qmouse
, Qmenu
;
349 Lisp_Object Qmode_line_inactive
;
350 static Lisp_Object Qvertical_border
;
352 /* The symbol `face-alias'. A symbols having that property is an
353 alias for another face. Value of the property is the name of
356 static Lisp_Object Qface_alias
;
358 /* Alist of alternative font families. Each element is of the form
359 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
360 try FAMILY1, then FAMILY2, ... */
362 Lisp_Object Vface_alternative_font_family_alist
;
364 /* Alist of alternative font registries. Each element is of the form
365 (REGISTRY REGISTRY1 REGISTRY2...). If fonts of REGISTRY can't be
366 loaded, try REGISTRY1, then REGISTRY2, ... */
368 Lisp_Object Vface_alternative_font_registry_alist
;
370 /* Allowed scalable fonts. A value of nil means don't allow any
371 scalable fonts. A value of t means allow the use of any scalable
372 font. Otherwise, value must be a list of regular expressions. A
373 font may be scaled if its name matches a regular expression in the
376 static Lisp_Object Qscalable_fonts_allowed
;
378 #define DEFAULT_FONT_LIST_LIMIT 100
380 /* The symbols `foreground-color' and `background-color' which can be
381 used as part of a `face' property. This is for compatibility with
384 Lisp_Object Qforeground_color
, Qbackground_color
;
386 /* The symbols `face' and `mouse-face' used as text properties. */
390 /* Property for basic faces which other faces cannot inherit. */
392 static Lisp_Object Qface_no_inherit
;
394 /* Error symbol for wrong_type_argument in load_pixmap. */
396 static Lisp_Object Qbitmap_spec_p
;
398 /* The next ID to assign to Lisp faces. */
400 static int next_lface_id
;
402 /* A vector mapping Lisp face Id's to face names. */
404 static Lisp_Object
*lface_id_to_name
;
405 static ptrdiff_t lface_id_to_name_size
;
407 /* TTY color-related functions (defined in tty-colors.el). */
409 static Lisp_Object Qtty_color_desc
, Qtty_color_by_index
, Qtty_color_standard_values
;
411 /* The name of the function used to compute colors on TTYs. */
413 static Lisp_Object Qtty_color_alist
;
415 /* Counter for calls to clear_face_cache. If this counter reaches
416 CLEAR_FONT_TABLE_COUNT, and a frame has more than
417 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
419 static int clear_font_table_count
;
420 #define CLEAR_FONT_TABLE_COUNT 100
421 #define CLEAR_FONT_TABLE_NFONTS 10
423 /* Non-zero means face attributes have been changed since the last
424 redisplay. Used in redisplay_internal. */
426 int face_change_count
;
428 /* Non-zero means don't display bold text if a face's foreground
429 and background colors are the inverse of the default colors of the
430 display. This is a kluge to suppress `bold black' foreground text
431 which is hard to read on an LCD monitor. */
433 static int tty_suppress_bold_inverse_default_colors_p
;
435 /* A list of the form `((x . y))' used to avoid consing in
436 Finternal_set_lisp_face_attribute. */
438 static Lisp_Object Vparam_value_alist
;
440 /* The total number of colors currently allocated. */
443 static int ncolors_allocated
;
444 static int npixmaps_allocated
;
448 /* Non-zero means the definition of the `menu' face for new frames has
451 static int menu_face_changed_default
;
454 /* Function prototypes. */
457 struct named_merge_point
;
459 static void map_tty_color (struct frame
*, struct face
*,
460 enum lface_attribute_index
, int *);
461 static Lisp_Object
resolve_face_name (Lisp_Object
, int);
462 static void set_font_frame_param (Lisp_Object
, Lisp_Object
);
463 static int get_lface_attributes (struct frame
*, Lisp_Object
, Lisp_Object
*,
464 int, struct named_merge_point
*);
465 static ptrdiff_t load_pixmap (struct frame
*, Lisp_Object
,
466 unsigned *, unsigned *);
467 static struct frame
*frame_or_selected_frame (Lisp_Object
, int);
468 static void load_face_colors (struct frame
*, struct face
*, Lisp_Object
*);
469 static void free_face_colors (struct frame
*, struct face
*);
470 static int face_color_gray_p (struct frame
*, const char *);
471 static struct face
*realize_face (struct face_cache
*, Lisp_Object
*,
473 static struct face
*realize_non_ascii_face (struct frame
*, Lisp_Object
,
475 static struct face
*realize_x_face (struct face_cache
*, Lisp_Object
*);
476 static struct face
*realize_tty_face (struct face_cache
*, Lisp_Object
*);
477 static int realize_basic_faces (struct frame
*);
478 static int realize_default_face (struct frame
*);
479 static void realize_named_face (struct frame
*, Lisp_Object
, int);
480 static int lface_fully_specified_p (Lisp_Object
*);
481 static int lface_equal_p (Lisp_Object
*, Lisp_Object
*);
482 static unsigned hash_string_case_insensitive (Lisp_Object
);
483 static unsigned lface_hash (Lisp_Object
*);
484 static int lface_same_font_attributes_p (Lisp_Object
*, Lisp_Object
*);
485 static struct face_cache
*make_face_cache (struct frame
*);
486 static void clear_face_gcs (struct face_cache
*);
487 static void free_face_cache (struct face_cache
*);
488 static int face_fontset (Lisp_Object
*);
489 static void merge_face_vectors (struct frame
*, Lisp_Object
*, Lisp_Object
*,
490 struct named_merge_point
*);
491 static int merge_face_ref (struct frame
*, Lisp_Object
, Lisp_Object
*,
492 int, struct named_merge_point
*);
493 static int set_lface_from_font (struct frame
*, Lisp_Object
, Lisp_Object
,
495 static Lisp_Object
lface_from_face_name (struct frame
*, Lisp_Object
, int);
496 static struct face
*make_realized_face (Lisp_Object
*);
497 static void cache_face (struct face_cache
*, struct face
*, unsigned);
498 static void uncache_face (struct face_cache
*, struct face
*);
500 #ifdef HAVE_WINDOW_SYSTEM
502 static GC
x_create_gc (struct frame
*, unsigned long, XGCValues
*);
503 static void x_free_gc (struct frame
*, GC
);
506 static void x_update_menu_appearance (struct frame
*);
508 extern void free_frame_menubar (struct frame
*);
509 #endif /* USE_X_TOOLKIT */
511 #endif /* HAVE_WINDOW_SYSTEM */
514 /***********************************************************************
516 ***********************************************************************/
518 #ifdef HAVE_X_WINDOWS
520 #ifdef DEBUG_X_COLORS
522 /* The following is a poor mans infrastructure for debugging X color
523 allocation problems on displays with PseudoColor-8. Some X servers
524 like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement
525 color reference counts completely so that they don't signal an
526 error when a color is freed whose reference count is already 0.
527 Other X servers do. To help me debug this, the following code
528 implements a simple reference counting schema of its own, for a
529 single display/screen. --gerd. */
531 /* Reference counts for pixel colors. */
533 int color_count
[256];
535 /* Register color PIXEL as allocated. */
538 register_color (unsigned long pixel
)
540 eassert (pixel
< 256);
541 ++color_count
[pixel
];
545 /* Register color PIXEL as deallocated. */
548 unregister_color (unsigned long pixel
)
550 eassert (pixel
< 256);
551 if (color_count
[pixel
] > 0)
552 --color_count
[pixel
];
558 /* Register N colors from PIXELS as deallocated. */
561 unregister_colors (unsigned long *pixels
, int n
)
564 for (i
= 0; i
< n
; ++i
)
565 unregister_color (pixels
[i
]);
569 DEFUN ("dump-colors", Fdump_colors
, Sdump_colors
, 0, 0, 0,
570 doc
: /* Dump currently allocated colors to stderr. */)
575 fputc ('\n', stderr
);
577 for (i
= n
= 0; i
< sizeof color_count
/ sizeof color_count
[0]; ++i
)
580 fprintf (stderr
, "%3d: %5d", i
, color_count
[i
]);
583 fputc ('\n', stderr
);
585 fputc ('\t', stderr
);
589 fputc ('\n', stderr
);
593 #endif /* DEBUG_X_COLORS */
596 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
597 color values. Interrupt input must be blocked when this function
601 x_free_colors (struct frame
*f
, long unsigned int *pixels
, int npixels
)
603 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
605 /* If display has an immutable color map, freeing colors is not
606 necessary and some servers don't allow it. So don't do it. */
607 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
609 #ifdef DEBUG_X_COLORS
610 unregister_colors (pixels
, npixels
);
612 XFreeColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
620 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
621 color values. Interrupt input must be blocked when this function
625 x_free_dpy_colors (Display
*dpy
, Screen
*screen
, Colormap cmap
,
626 long unsigned int *pixels
, int npixels
)
628 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
629 int class = dpyinfo
->visual
->class;
631 /* If display has an immutable color map, freeing colors is not
632 necessary and some servers don't allow it. So don't do it. */
633 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
635 #ifdef DEBUG_X_COLORS
636 unregister_colors (pixels
, npixels
);
638 XFreeColors (dpy
, cmap
, pixels
, npixels
, 0);
641 #endif /* USE_X_TOOLKIT */
643 /* Create and return a GC for use on frame F. GC values and mask
644 are given by XGCV and MASK. */
647 x_create_gc (struct frame
*f
, long unsigned int mask
, XGCValues
*xgcv
)
651 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
658 /* Free GC which was used on frame F. */
661 x_free_gc (struct frame
*f
, GC gc
)
663 eassert (interrupt_input_blocked
);
664 IF_DEBUG (eassert (--ngcs
>= 0));
665 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
668 #endif /* HAVE_X_WINDOWS */
671 /* W32 emulation of GCs */
674 x_create_gc (struct frame
*f
, unsigned long mask
, XGCValues
*xgcv
)
678 gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, xgcv
);
685 /* Free GC which was used on frame F. */
688 x_free_gc (struct frame
*f
, GC gc
)
690 IF_DEBUG (eassert (--ngcs
>= 0));
694 #endif /* WINDOWSNT */
697 /* NS emulation of GCs */
700 x_create_gc (struct frame
*f
,
704 GC gc
= xmalloc (sizeof *gc
);
705 memcpy (gc
, xgcv
, sizeof (XGCValues
));
710 x_free_gc (struct frame
*f
, GC gc
)
716 /* If FRAME is nil, return a pointer to the selected frame.
717 Otherwise, check that FRAME is a live frame, and return a pointer
718 to it. NPARAM is the parameter number of FRAME, for
719 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
720 Lisp function definitions. */
722 static inline struct frame
*
723 frame_or_selected_frame (Lisp_Object frame
, int nparam
)
726 frame
= selected_frame
;
728 CHECK_LIVE_FRAME (frame
);
729 return XFRAME (frame
);
733 /***********************************************************************
735 ***********************************************************************/
737 /* Initialize face cache and basic faces for frame F. */
740 init_frame_faces (struct frame
*f
)
742 /* Make a face cache, if F doesn't have one. */
743 if (FRAME_FACE_CACHE (f
) == NULL
)
744 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
746 #ifdef HAVE_WINDOW_SYSTEM
747 /* Make the image cache. */
748 if (FRAME_WINDOW_P (f
))
750 /* We initialize the image cache when creating the first frame
751 on a terminal, and not during terminal creation. This way,
752 `x-open-connection' on a tty won't create an image cache. */
753 if (FRAME_IMAGE_CACHE (f
) == NULL
)
754 FRAME_IMAGE_CACHE (f
) = make_image_cache ();
755 ++FRAME_IMAGE_CACHE (f
)->refcount
;
757 #endif /* HAVE_WINDOW_SYSTEM */
759 /* Realize basic faces. Must have enough information in frame
760 parameters to realize basic faces at this point. */
761 #ifdef HAVE_X_WINDOWS
762 if (!FRAME_X_P (f
) || FRAME_X_WINDOW (f
))
765 if (!FRAME_WINDOW_P (f
) || FRAME_W32_WINDOW (f
))
768 if (!FRAME_NS_P (f
) || FRAME_NS_WINDOW (f
))
770 if (!realize_basic_faces (f
))
775 /* Free face cache of frame F. Called from delete_frame. */
778 free_frame_faces (struct frame
*f
)
780 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
784 free_face_cache (face_cache
);
785 FRAME_FACE_CACHE (f
) = NULL
;
788 #ifdef HAVE_WINDOW_SYSTEM
789 if (FRAME_WINDOW_P (f
))
791 struct image_cache
*image_cache
= FRAME_IMAGE_CACHE (f
);
794 --image_cache
->refcount
;
795 if (image_cache
->refcount
== 0)
796 free_image_cache (f
);
799 #endif /* HAVE_WINDOW_SYSTEM */
803 /* Clear face caches, and recompute basic faces for frame F. Call
804 this after changing frame parameters on which those faces depend,
805 or when realized faces have been freed due to changing attributes
809 recompute_basic_faces (struct frame
*f
)
811 if (FRAME_FACE_CACHE (f
))
813 clear_face_cache (0);
814 if (!realize_basic_faces (f
))
820 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
821 try to free unused fonts, too. */
824 clear_face_cache (int clear_fonts_p
)
826 #ifdef HAVE_WINDOW_SYSTEM
827 Lisp_Object tail
, frame
;
830 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
833 /* Not yet implemented. */
834 clear_font_cache (frame
);
837 /* From time to time see if we can unload some fonts. This also
838 frees all realized faces on all frames. Fonts needed by
839 faces will be loaded again when faces are realized again. */
840 clear_font_table_count
= 0;
842 FOR_EACH_FRAME (tail
, frame
)
844 struct frame
*f
= XFRAME (frame
);
845 if (FRAME_WINDOW_P (f
)
846 && FRAME_X_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
847 free_all_realized_faces (frame
);
852 /* Clear GCs of realized faces. */
853 FOR_EACH_FRAME (tail
, frame
)
855 struct frame
*f
= XFRAME (frame
);
856 if (FRAME_WINDOW_P (f
))
857 clear_face_gcs (FRAME_FACE_CACHE (f
));
859 clear_image_caches (Qnil
);
861 #endif /* HAVE_WINDOW_SYSTEM */
865 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
866 doc
: /* Clear face caches on all frames.
867 Optional THOROUGHLY non-nil means try to free unused fonts, too. */)
868 (Lisp_Object thoroughly
)
870 clear_face_cache (!NILP (thoroughly
));
872 ++windows_or_buffers_changed
;
877 /***********************************************************************
879 ***********************************************************************/
881 #ifdef HAVE_WINDOW_SYSTEM
883 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
884 doc
: /* Value is non-nil if OBJECT is a valid bitmap specification.
885 A bitmap specification is either a string, a file name, or a list
886 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
887 HEIGHT is its height, and DATA is a string containing the bits of
888 the pixmap. Bits are stored row by row, each row occupies
889 \(WIDTH + 7)/8 bytes. */)
894 if (STRINGP (object
))
895 /* If OBJECT is a string, it's a file name. */
897 else if (CONSP (object
))
899 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
900 HEIGHT must be ints > 0, and DATA must be string large
901 enough to hold a bitmap of the specified size. */
902 Lisp_Object width
, height
, data
;
904 height
= width
= data
= Qnil
;
908 width
= XCAR (object
);
909 object
= XCDR (object
);
912 height
= XCAR (object
);
913 object
= XCDR (object
);
915 data
= XCAR (object
);
920 && RANGED_INTEGERP (1, width
, INT_MAX
)
921 && RANGED_INTEGERP (1, height
, INT_MAX
))
923 int bytes_per_row
= ((XINT (width
) + BITS_PER_CHAR
- 1)
925 if (XINT (height
) <= SBYTES (data
) / bytes_per_row
)
930 return pixmap_p
? Qt
: Qnil
;
934 /* Load a bitmap according to NAME (which is either a file name or a
935 pixmap spec) for use on frame F. Value is the bitmap_id (see
936 xfns.c). If NAME is nil, return with a bitmap id of zero. If
937 bitmap cannot be loaded, display a message saying so, and return
938 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
939 if these pointers are not null. */
942 load_pixmap (FRAME_PTR f
, Lisp_Object name
, unsigned int *w_ptr
,
950 CHECK_TYPE (!NILP (Fbitmap_spec_p (name
)), Qbitmap_spec_p
, name
);
955 /* Decode a bitmap spec into a bitmap. */
960 w
= XINT (Fcar (name
));
961 h
= XINT (Fcar (Fcdr (name
)));
962 bits
= Fcar (Fcdr (Fcdr (name
)));
964 bitmap_id
= x_create_bitmap_from_data (f
, SSDATA (bits
),
969 /* It must be a string -- a file name. */
970 bitmap_id
= x_create_bitmap_from_file (f
, name
);
976 add_to_log ("Invalid or undefined bitmap `%s'", name
, Qnil
);
987 ++npixmaps_allocated
;
990 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
993 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
999 #endif /* HAVE_WINDOW_SYSTEM */
1003 /***********************************************************************
1005 ***********************************************************************/
1007 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
1008 RGB_LIST should contain (at least) 3 lisp integers.
1009 Return 0 if there's a problem with RGB_LIST, otherwise return 1. */
1012 parse_rgb_list (Lisp_Object rgb_list
, XColor
*color
)
1014 #define PARSE_RGB_LIST_FIELD(field) \
1015 if (CONSP (rgb_list) && INTEGERP (XCAR (rgb_list))) \
1017 color->field = XINT (XCAR (rgb_list)); \
1018 rgb_list = XCDR (rgb_list); \
1023 PARSE_RGB_LIST_FIELD (red
);
1024 PARSE_RGB_LIST_FIELD (green
);
1025 PARSE_RGB_LIST_FIELD (blue
);
1031 /* Lookup on frame F the color described by the lisp string COLOR.
1032 The resulting tty color is returned in TTY_COLOR; if STD_COLOR is
1033 non-zero, then the `standard' definition of the same color is
1037 tty_lookup_color (struct frame
*f
, Lisp_Object color
, XColor
*tty_color
,
1040 Lisp_Object frame
, color_desc
;
1042 if (!STRINGP (color
) || NILP (Ffboundp (Qtty_color_desc
)))
1045 XSETFRAME (frame
, f
);
1047 color_desc
= call2 (Qtty_color_desc
, color
, frame
);
1048 if (CONSP (color_desc
) && CONSP (XCDR (color_desc
)))
1052 if (! INTEGERP (XCAR (XCDR (color_desc
))))
1055 tty_color
->pixel
= XINT (XCAR (XCDR (color_desc
)));
1057 rgb
= XCDR (XCDR (color_desc
));
1058 if (! parse_rgb_list (rgb
, tty_color
))
1061 /* Should we fill in STD_COLOR too? */
1064 /* Default STD_COLOR to the same as TTY_COLOR. */
1065 *std_color
= *tty_color
;
1067 /* Do a quick check to see if the returned descriptor is
1068 actually _exactly_ equal to COLOR, otherwise we have to
1069 lookup STD_COLOR separately. If it's impossible to lookup
1070 a standard color, we just give up and use TTY_COLOR. */
1071 if ((!STRINGP (XCAR (color_desc
))
1072 || NILP (Fstring_equal (color
, XCAR (color_desc
))))
1073 && !NILP (Ffboundp (Qtty_color_standard_values
)))
1075 /* Look up STD_COLOR separately. */
1076 rgb
= call1 (Qtty_color_standard_values
, color
);
1077 if (! parse_rgb_list (rgb
, std_color
))
1084 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
1085 /* We were called early during startup, and the colors are not
1086 yet set up in tty-defined-color-alist. Don't return a failure
1087 indication, since this produces the annoying "Unable to
1088 load color" messages in the *Messages* buffer. */
1091 /* tty-color-desc seems to have returned a bad value. */
1095 /* A version of defined_color for non-X frames. */
1098 tty_defined_color (struct frame
*f
, const char *color_name
,
1099 XColor
*color_def
, int alloc
)
1104 color_def
->pixel
= FACE_TTY_DEFAULT_COLOR
;
1106 color_def
->blue
= 0;
1107 color_def
->green
= 0;
1110 status
= tty_lookup_color (f
, build_string (color_name
), color_def
, NULL
);
1112 if (color_def
->pixel
== FACE_TTY_DEFAULT_COLOR
&& *color_name
)
1114 if (strcmp (color_name
, "unspecified-fg") == 0)
1115 color_def
->pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
1116 else if (strcmp (color_name
, "unspecified-bg") == 0)
1117 color_def
->pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
1120 if (color_def
->pixel
!= FACE_TTY_DEFAULT_COLOR
)
1127 /* Decide if color named COLOR_NAME is valid for the display
1128 associated with the frame F; if so, return the rgb values in
1129 COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell.
1131 This does the right thing for any type of frame. */
1134 defined_color (struct frame
*f
, const char *color_name
, XColor
*color_def
,
1137 if (!FRAME_WINDOW_P (f
))
1138 return tty_defined_color (f
, color_name
, color_def
, alloc
);
1139 #ifdef HAVE_X_WINDOWS
1140 else if (FRAME_X_P (f
))
1141 return x_defined_color (f
, color_name
, color_def
, alloc
);
1144 else if (FRAME_W32_P (f
))
1145 return w32_defined_color (f
, color_name
, color_def
, alloc
);
1148 else if (FRAME_NS_P (f
))
1149 return ns_defined_color (f
, color_name
, color_def
, alloc
, 1);
1156 /* Given the index IDX of a tty color on frame F, return its name, a
1160 tty_color_name (struct frame
*f
, int idx
)
1162 if (idx
>= 0 && !NILP (Ffboundp (Qtty_color_by_index
)))
1165 Lisp_Object coldesc
;
1167 XSETFRAME (frame
, f
);
1168 coldesc
= call2 (Qtty_color_by_index
, make_number (idx
), frame
);
1170 if (!NILP (coldesc
))
1171 return XCAR (coldesc
);
1174 /* We can have an MSDOG frame under -nw for a short window of
1175 opportunity before internal_terminal_init is called. DTRT. */
1176 if (FRAME_MSDOS_P (f
) && !inhibit_window_system
)
1177 return msdos_stdcolor_name (idx
);
1180 if (idx
== FACE_TTY_DEFAULT_FG_COLOR
)
1181 return build_string (unspecified_fg
);
1182 if (idx
== FACE_TTY_DEFAULT_BG_COLOR
)
1183 return build_string (unspecified_bg
);
1185 return Qunspecified
;
1189 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1192 The criterion implemented here is not a terribly sophisticated one. */
1195 face_color_gray_p (struct frame
*f
, const char *color_name
)
1200 if (defined_color (f
, color_name
, &color
, 0))
1201 gray_p
= (/* Any color sufficiently close to black counts as gray. */
1202 (color
.red
< 5000 && color
.green
< 5000 && color
.blue
< 5000)
1204 ((eabs (color
.red
- color
.green
)
1205 < max (color
.red
, color
.green
) / 20)
1206 && (eabs (color
.green
- color
.blue
)
1207 < max (color
.green
, color
.blue
) / 20)
1208 && (eabs (color
.blue
- color
.red
)
1209 < max (color
.blue
, color
.red
) / 20)));
1217 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1218 BACKGROUND_P non-zero means the color will be used as background
1222 face_color_supported_p (struct frame
*f
, const char *color_name
,
1228 XSETFRAME (frame
, f
);
1230 #ifdef HAVE_WINDOW_SYSTEM
1232 ? (!NILP (Fxw_display_color_p (frame
))
1233 || xstrcasecmp (color_name
, "black") == 0
1234 || xstrcasecmp (color_name
, "white") == 0
1236 && face_color_gray_p (f
, color_name
))
1237 || (!NILP (Fx_display_grayscale_p (frame
))
1238 && face_color_gray_p (f
, color_name
)))
1241 tty_defined_color (f
, color_name
, ¬_used
, 0);
1245 DEFUN ("color-gray-p", Fcolor_gray_p
, Scolor_gray_p
, 1, 2, 0,
1246 doc
: /* Return non-nil if COLOR is a shade of gray (or white or black).
1247 FRAME specifies the frame and thus the display for interpreting COLOR.
1248 If FRAME is nil or omitted, use the selected frame. */)
1249 (Lisp_Object color
, Lisp_Object frame
)
1253 CHECK_STRING (color
);
1255 frame
= selected_frame
;
1257 CHECK_FRAME (frame
);
1259 return face_color_gray_p (f
, SSDATA (color
)) ? Qt
: Qnil
;
1263 DEFUN ("color-supported-p", Fcolor_supported_p
,
1264 Scolor_supported_p
, 1, 3, 0,
1265 doc
: /* Return non-nil if COLOR can be displayed on FRAME.
1266 BACKGROUND-P non-nil means COLOR is used as a background.
1267 Otherwise, this function tells whether it can be used as a foreground.
1268 If FRAME is nil or omitted, use the selected frame.
1269 COLOR must be a valid color name. */)
1270 (Lisp_Object color
, Lisp_Object frame
, Lisp_Object background_p
)
1274 CHECK_STRING (color
);
1276 frame
= selected_frame
;
1278 CHECK_FRAME (frame
);
1280 if (face_color_supported_p (f
, SSDATA (color
), !NILP (background_p
)))
1286 /* Load color with name NAME for use by face FACE on frame F.
1287 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1288 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1289 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1290 pixel color. If color cannot be loaded, display a message, and
1291 return the foreground, background or underline color of F, but
1292 record that fact in flags of the face so that we don't try to free
1296 load_color (struct frame
*f
, struct face
*face
, Lisp_Object name
,
1297 enum lface_attribute_index target_index
)
1301 eassert (STRINGP (name
));
1302 eassert (target_index
== LFACE_FOREGROUND_INDEX
1303 || target_index
== LFACE_BACKGROUND_INDEX
1304 || target_index
== LFACE_UNDERLINE_INDEX
1305 || target_index
== LFACE_OVERLINE_INDEX
1306 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1307 || target_index
== LFACE_BOX_INDEX
);
1309 /* if the color map is full, defined_color will return a best match
1310 to the values in an existing cell. */
1311 if (!defined_color (f
, SSDATA (name
), &color
, 1))
1313 add_to_log ("Unable to load color \"%s\"", name
, Qnil
);
1315 switch (target_index
)
1317 case LFACE_FOREGROUND_INDEX
:
1318 face
->foreground_defaulted_p
= 1;
1319 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1322 case LFACE_BACKGROUND_INDEX
:
1323 face
->background_defaulted_p
= 1;
1324 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1327 case LFACE_UNDERLINE_INDEX
:
1328 face
->underline_defaulted_p
= 1;
1329 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1332 case LFACE_OVERLINE_INDEX
:
1333 face
->overline_color_defaulted_p
= 1;
1334 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1337 case LFACE_STRIKE_THROUGH_INDEX
:
1338 face
->strike_through_color_defaulted_p
= 1;
1339 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1342 case LFACE_BOX_INDEX
:
1343 face
->box_color_defaulted_p
= 1;
1344 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1353 ++ncolors_allocated
;
1360 #ifdef HAVE_WINDOW_SYSTEM
1362 /* Load colors for face FACE which is used on frame F. Colors are
1363 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1364 of ATTRS. If the background color specified is not supported on F,
1365 try to emulate gray colors with a stipple from Vface_default_stipple. */
1368 load_face_colors (struct frame
*f
, struct face
*face
, Lisp_Object
*attrs
)
1372 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1373 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1375 /* Swap colors if face is inverse-video. */
1376 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1384 /* Check for support for foreground, not for background because
1385 face_color_supported_p is smart enough to know that grays are
1386 "supported" as background because we are supposed to use stipple
1388 if (!face_color_supported_p (f
, SSDATA (bg
), 0)
1389 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1391 x_destroy_bitmap (f
, face
->stipple
);
1392 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1393 &face
->pixmap_w
, &face
->pixmap_h
);
1396 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1397 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1401 /* Free color PIXEL on frame F. */
1404 unload_color (struct frame
*f
, long unsigned int pixel
)
1406 #ifdef HAVE_X_WINDOWS
1410 x_free_colors (f
, &pixel
, 1);
1417 /* Free colors allocated for FACE. */
1420 free_face_colors (struct frame
*f
, struct face
*face
)
1422 /* PENDING(NS): need to do something here? */
1423 #ifdef HAVE_X_WINDOWS
1424 if (face
->colors_copied_bitwise_p
)
1429 if (!face
->foreground_defaulted_p
)
1431 x_free_colors (f
, &face
->foreground
, 1);
1432 IF_DEBUG (--ncolors_allocated
);
1435 if (!face
->background_defaulted_p
)
1437 x_free_colors (f
, &face
->background
, 1);
1438 IF_DEBUG (--ncolors_allocated
);
1441 if (face
->underline_p
1442 && !face
->underline_defaulted_p
)
1444 x_free_colors (f
, &face
->underline_color
, 1);
1445 IF_DEBUG (--ncolors_allocated
);
1448 if (face
->overline_p
1449 && !face
->overline_color_defaulted_p
)
1451 x_free_colors (f
, &face
->overline_color
, 1);
1452 IF_DEBUG (--ncolors_allocated
);
1455 if (face
->strike_through_p
1456 && !face
->strike_through_color_defaulted_p
)
1458 x_free_colors (f
, &face
->strike_through_color
, 1);
1459 IF_DEBUG (--ncolors_allocated
);
1462 if (face
->box
!= FACE_NO_BOX
1463 && !face
->box_color_defaulted_p
)
1465 x_free_colors (f
, &face
->box_color
, 1);
1466 IF_DEBUG (--ncolors_allocated
);
1470 #endif /* HAVE_X_WINDOWS */
1473 #endif /* HAVE_WINDOW_SYSTEM */
1477 /***********************************************************************
1479 ***********************************************************************/
1481 /* An enumerator for each field of an XLFD font name. */
1502 /* An enumerator for each possible slant value of a font. Taken from
1503 the XLFD specification. */
1511 XLFD_SLANT_REVERSE_ITALIC
,
1512 XLFD_SLANT_REVERSE_OBLIQUE
,
1516 /* Relative font weight according to XLFD documentation. */
1520 XLFD_WEIGHT_UNKNOWN
,
1521 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1522 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1523 XLFD_WEIGHT_LIGHT
, /* 30 */
1524 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1525 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1526 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1527 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1528 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1529 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1532 /* Relative proportionate width. */
1536 XLFD_SWIDTH_UNKNOWN
,
1537 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1538 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1539 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1540 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1541 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1542 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1543 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1544 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1545 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1548 /* Order by which font selection chooses fonts. The default values
1549 mean `first, find a best match for the font width, then for the
1550 font height, then for weight, then for slant.' This variable can be
1551 set via set-face-font-sort-order. */
1553 static int font_sort_order
[4];
1555 #ifdef HAVE_WINDOW_SYSTEM
1557 static enum font_property_index font_props_for_sorting
[FONT_SIZE_INDEX
];
1560 compare_fonts_by_sort_order (const void *v1
, const void *v2
)
1562 Lisp_Object font1
= *(Lisp_Object
*) v1
;
1563 Lisp_Object font2
= *(Lisp_Object
*) v2
;
1566 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1568 enum font_property_index idx
= font_props_for_sorting
[i
];
1569 Lisp_Object val1
= AREF (font1
, idx
), val2
= AREF (font2
, idx
);
1572 if (idx
<= FONT_REGISTRY_INDEX
)
1575 result
= STRINGP (val2
) ? strcmp (SSDATA (val1
), SSDATA (val2
)) : -1;
1577 result
= STRINGP (val2
) ? 1 : 0;
1581 if (INTEGERP (val1
))
1582 result
= (INTEGERP (val2
) && XINT (val1
) >= XINT (val2
)
1583 ? XINT (val1
) > XINT (val2
)
1586 result
= INTEGERP (val2
) ? 1 : 0;
1594 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
1595 doc
: /* Return a list of available fonts of family FAMILY on FRAME.
1596 If FAMILY is omitted or nil, list all families.
1597 Otherwise, FAMILY must be a string, possibly containing wildcards
1599 If FRAME is omitted or nil, use the selected frame.
1600 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
1601 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
1602 FAMILY is the font family name. POINT-SIZE is the size of the
1603 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
1604 width, weight and slant of the font. These symbols are the same as for
1605 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
1606 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
1607 giving the registry and encoding of the font.
1608 The result list is sorted according to the current setting of
1609 the face font sort order. */)
1610 (Lisp_Object family
, Lisp_Object frame
)
1612 Lisp_Object font_spec
, list
, *drivers
, vec
;
1613 ptrdiff_t i
, nfonts
;
1619 frame
= selected_frame
;
1620 CHECK_LIVE_FRAME (frame
);
1622 font_spec
= Ffont_spec (0, NULL
);
1625 CHECK_STRING (family
);
1626 font_parse_family_registry (family
, Qnil
, font_spec
);
1629 list
= font_list_entities (frame
, font_spec
);
1633 /* Sort the font entities. */
1634 for (i
= 0; i
< 4; i
++)
1635 switch (font_sort_order
[i
])
1638 font_props_for_sorting
[i
] = FONT_WIDTH_INDEX
; break;
1639 case XLFD_POINT_SIZE
:
1640 font_props_for_sorting
[i
] = FONT_SIZE_INDEX
; break;
1642 font_props_for_sorting
[i
] = FONT_WEIGHT_INDEX
; break;
1644 font_props_for_sorting
[i
] = FONT_SLANT_INDEX
; break;
1646 font_props_for_sorting
[i
++] = FONT_FAMILY_INDEX
;
1647 font_props_for_sorting
[i
++] = FONT_FOUNDRY_INDEX
;
1648 font_props_for_sorting
[i
++] = FONT_ADSTYLE_INDEX
;
1649 font_props_for_sorting
[i
++] = FONT_REGISTRY_INDEX
;
1651 ndrivers
= XINT (Flength (list
));
1652 SAFE_ALLOCA_LISP (drivers
, ndrivers
);
1653 for (i
= 0; i
< ndrivers
; i
++, list
= XCDR (list
))
1654 drivers
[i
] = XCAR (list
);
1655 vec
= Fvconcat (ndrivers
, drivers
);
1656 nfonts
= ASIZE (vec
);
1658 qsort (XVECTOR (vec
)->contents
, nfonts
, sizeof (Lisp_Object
),
1659 compare_fonts_by_sort_order
);
1662 for (i
= nfonts
- 1; i
>= 0; --i
)
1664 Lisp_Object font
= AREF (vec
, i
);
1665 Lisp_Object v
= Fmake_vector (make_number (8), Qnil
);
1667 Lisp_Object spacing
;
1669 ASET (v
, 0, AREF (font
, FONT_FAMILY_INDEX
));
1670 ASET (v
, 1, FONT_WIDTH_SYMBOLIC (font
));
1671 point
= PIXEL_TO_POINT (XINT (AREF (font
, FONT_SIZE_INDEX
)) * 10,
1672 XFRAME (frame
)->resy
);
1673 ASET (v
, 2, make_number (point
));
1674 ASET (v
, 3, FONT_WEIGHT_SYMBOLIC (font
));
1675 ASET (v
, 4, FONT_SLANT_SYMBOLIC (font
));
1676 spacing
= Ffont_get (font
, QCspacing
);
1677 ASET (v
, 5, (NILP (spacing
) || EQ (spacing
, Qp
)) ? Qnil
: Qt
);
1678 ASET (v
, 6, Ffont_xlfd_name (font
, Qnil
));
1679 ASET (v
, 7, AREF (font
, FONT_REGISTRY_INDEX
));
1681 result
= Fcons (v
, result
);
1688 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
1689 doc
: /* Return a list of the names of available fonts matching PATTERN.
1690 If optional arguments FACE and FRAME are specified, return only fonts
1691 the same size as FACE on FRAME.
1693 PATTERN should be a string containing a font name in the XLFD,
1694 Fontconfig, or GTK format. A font name given in the XLFD format may
1695 contain wildcard characters:
1696 the * character matches any substring, and
1697 the ? character matches any single character.
1698 PATTERN is case-insensitive.
1700 The return value is a list of strings, suitable as arguments to
1703 Fonts Emacs can't use may or may not be excluded
1704 even if they match PATTERN and FACE.
1705 The optional fourth argument MAXIMUM sets a limit on how many
1706 fonts to match. The first MAXIMUM fonts are reported.
1707 The optional fifth argument WIDTH, if specified, is a number of columns
1708 occupied by a character of a font. In that case, return only fonts
1709 the WIDTH times as wide as FACE on FRAME. */)
1710 (Lisp_Object pattern
, Lisp_Object face
, Lisp_Object frame
,
1711 Lisp_Object maximum
, Lisp_Object width
)
1714 int size
, avgwidth
IF_LINT (= 0);
1717 CHECK_STRING (pattern
);
1719 if (! NILP (maximum
))
1720 CHECK_NATNUM (maximum
);
1723 CHECK_NUMBER (width
);
1725 /* We can't simply call check_x_frame because this function may be
1726 called before any frame is created. */
1728 frame
= selected_frame
;
1729 f
= frame_or_selected_frame (frame
, 2);
1730 if (! FRAME_WINDOW_P (f
))
1732 /* Perhaps we have not yet created any frame. */
1738 /* Determine the width standard for comparison with the fonts we find. */
1744 /* This is of limited utility since it works with character
1745 widths. Keep it for compatibility. --gerd. */
1746 int face_id
= lookup_named_face (f
, face
, 0);
1747 struct face
*width_face
= (face_id
< 0
1749 : FACE_FROM_ID (f
, face_id
));
1751 if (width_face
&& width_face
->font
)
1753 size
= width_face
->font
->pixel_size
;
1754 avgwidth
= width_face
->font
->average_width
;
1758 size
= FRAME_FONT (f
)->pixel_size
;
1759 avgwidth
= FRAME_FONT (f
)->average_width
;
1762 avgwidth
*= XINT (width
);
1766 Lisp_Object font_spec
;
1767 Lisp_Object args
[2], tail
;
1769 font_spec
= font_spec_from_name (pattern
);
1770 if (!FONTP (font_spec
))
1771 signal_error ("Invalid font name", pattern
);
1775 Ffont_put (font_spec
, QCsize
, make_number (size
));
1776 Ffont_put (font_spec
, QCavgwidth
, make_number (avgwidth
));
1778 args
[0] = Flist_fonts (font_spec
, frame
, maximum
, font_spec
);
1779 for (tail
= args
[0]; CONSP (tail
); tail
= XCDR (tail
))
1781 Lisp_Object font_entity
;
1783 font_entity
= XCAR (tail
);
1784 if ((NILP (AREF (font_entity
, FONT_SIZE_INDEX
))
1785 || XINT (AREF (font_entity
, FONT_SIZE_INDEX
)) == 0)
1786 && ! NILP (AREF (font_spec
, FONT_SIZE_INDEX
)))
1788 /* This is a scalable font. For backward compatibility,
1789 we set the specified size. */
1790 font_entity
= copy_font_spec (font_entity
);
1791 ASET (font_entity
, FONT_SIZE_INDEX
,
1792 AREF (font_spec
, FONT_SIZE_INDEX
));
1794 XSETCAR (tail
, Ffont_xlfd_name (font_entity
, Qnil
));
1797 /* We don't have to check fontsets. */
1799 args
[1] = list_fontsets (f
, pattern
, size
);
1800 return Fnconc (2, args
);
1804 #endif /* HAVE_WINDOW_SYSTEM */
1807 /***********************************************************************
1809 ***********************************************************************/
1811 /* Access face attributes of face LFACE, a Lisp vector. */
1813 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
1814 #define LFACE_FOUNDRY(LFACE) AREF ((LFACE), LFACE_FOUNDRY_INDEX)
1815 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
1816 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
1817 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
1818 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
1819 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
1820 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
1821 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
1822 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
1823 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
1824 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
1825 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
1826 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
1827 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
1828 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
1829 #define LFACE_FONTSET(LFACE) AREF ((LFACE), LFACE_FONTSET_INDEX)
1831 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
1832 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
1834 #define LFACEP(LFACE) \
1836 && ASIZE (LFACE) == LFACE_VECTOR_SIZE \
1837 && EQ (AREF (LFACE, 0), Qface))
1842 /* Check consistency of Lisp face attribute vector ATTRS. */
1845 check_lface_attrs (Lisp_Object
*attrs
)
1847 eassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
1848 || IGNORE_DEFFACE_P (attrs
[LFACE_FAMILY_INDEX
])
1849 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
1850 eassert (UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
1851 || IGNORE_DEFFACE_P (attrs
[LFACE_FOUNDRY_INDEX
])
1852 || STRINGP (attrs
[LFACE_FOUNDRY_INDEX
]));
1853 eassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
1854 || IGNORE_DEFFACE_P (attrs
[LFACE_SWIDTH_INDEX
])
1855 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
1856 eassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
1857 || IGNORE_DEFFACE_P (attrs
[LFACE_HEIGHT_INDEX
])
1858 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
])
1859 || FLOATP (attrs
[LFACE_HEIGHT_INDEX
])
1860 || FUNCTIONP (attrs
[LFACE_HEIGHT_INDEX
]));
1861 eassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
1862 || IGNORE_DEFFACE_P (attrs
[LFACE_WEIGHT_INDEX
])
1863 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
1864 eassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
1865 || IGNORE_DEFFACE_P (attrs
[LFACE_SLANT_INDEX
])
1866 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
1867 eassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
1868 || IGNORE_DEFFACE_P (attrs
[LFACE_UNDERLINE_INDEX
])
1869 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
1870 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
])
1871 || CONSP (attrs
[LFACE_UNDERLINE_INDEX
]));
1872 eassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
1873 || IGNORE_DEFFACE_P (attrs
[LFACE_OVERLINE_INDEX
])
1874 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
1875 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
1876 eassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1877 || IGNORE_DEFFACE_P (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1878 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1879 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
1880 eassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
1881 || IGNORE_DEFFACE_P (attrs
[LFACE_BOX_INDEX
])
1882 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
1883 || STRINGP (attrs
[LFACE_BOX_INDEX
])
1884 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
1885 || CONSP (attrs
[LFACE_BOX_INDEX
]));
1886 eassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
1887 || IGNORE_DEFFACE_P (attrs
[LFACE_INVERSE_INDEX
])
1888 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
1889 eassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
1890 || IGNORE_DEFFACE_P (attrs
[LFACE_FOREGROUND_INDEX
])
1891 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
1892 eassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
1893 || IGNORE_DEFFACE_P (attrs
[LFACE_BACKGROUND_INDEX
])
1894 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
1895 eassert (UNSPECIFIEDP (attrs
[LFACE_INHERIT_INDEX
])
1896 || IGNORE_DEFFACE_P (attrs
[LFACE_INHERIT_INDEX
])
1897 || NILP (attrs
[LFACE_INHERIT_INDEX
])
1898 || SYMBOLP (attrs
[LFACE_INHERIT_INDEX
])
1899 || CONSP (attrs
[LFACE_INHERIT_INDEX
]));
1900 #ifdef HAVE_WINDOW_SYSTEM
1901 eassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
1902 || IGNORE_DEFFACE_P (attrs
[LFACE_STIPPLE_INDEX
])
1903 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
1904 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
1905 eassert (UNSPECIFIEDP (attrs
[LFACE_FONT_INDEX
])
1906 || IGNORE_DEFFACE_P (attrs
[LFACE_FONT_INDEX
])
1907 || FONTP (attrs
[LFACE_FONT_INDEX
]));
1908 eassert (UNSPECIFIEDP (attrs
[LFACE_FONTSET_INDEX
])
1909 || STRINGP (attrs
[LFACE_FONTSET_INDEX
])
1910 || NILP (attrs
[LFACE_FONTSET_INDEX
]));
1915 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
1918 check_lface (Lisp_Object lface
)
1922 eassert (LFACEP (lface
));
1923 check_lface_attrs (XVECTOR (lface
)->contents
);
1927 #else /* not GLYPH_DEBUG */
1929 #define check_lface_attrs(attrs) (void) 0
1930 #define check_lface(lface) (void) 0
1932 #endif /* GLYPH_DEBUG */
1936 /* Face-merge cycle checking. */
1938 enum named_merge_point_kind
1940 NAMED_MERGE_POINT_NORMAL
,
1941 NAMED_MERGE_POINT_REMAP
1944 /* A `named merge point' is simply a point during face-merging where we
1945 look up a face by name. We keep a stack of which named lookups we're
1946 currently processing so that we can easily detect cycles, using a
1947 linked- list of struct named_merge_point structures, typically
1948 allocated on the stack frame of the named lookup functions which are
1949 active (so no consing is required). */
1950 struct named_merge_point
1952 Lisp_Object face_name
;
1953 enum named_merge_point_kind named_merge_point_kind
;
1954 struct named_merge_point
*prev
;
1958 /* If a face merging cycle is detected for FACE_NAME, return 0,
1959 otherwise add NEW_NAMED_MERGE_POINT, which is initialized using
1960 FACE_NAME and NAMED_MERGE_POINT_KIND, as the head of the linked list
1961 pointed to by NAMED_MERGE_POINTS, and return 1. */
1964 push_named_merge_point (struct named_merge_point
*new_named_merge_point
,
1965 Lisp_Object face_name
,
1966 enum named_merge_point_kind named_merge_point_kind
,
1967 struct named_merge_point
**named_merge_points
)
1969 struct named_merge_point
*prev
;
1971 for (prev
= *named_merge_points
; prev
; prev
= prev
->prev
)
1972 if (EQ (face_name
, prev
->face_name
))
1974 if (prev
->named_merge_point_kind
== named_merge_point_kind
)
1975 /* A cycle, so fail. */
1977 else if (prev
->named_merge_point_kind
== NAMED_MERGE_POINT_REMAP
)
1978 /* A remap `hides ' any previous normal merge points
1979 (because the remap means that it's actually different face),
1980 so as we know the current merge point must be normal, we
1981 can just assume it's OK. */
1985 new_named_merge_point
->face_name
= face_name
;
1986 new_named_merge_point
->named_merge_point_kind
= named_merge_point_kind
;
1987 new_named_merge_point
->prev
= *named_merge_points
;
1989 *named_merge_points
= new_named_merge_point
;
1995 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
1996 to make it a symbol. If FACE_NAME is an alias for another face,
1997 return that face's name.
1999 Return default face in case of errors. */
2002 resolve_face_name (Lisp_Object face_name
, int signal_p
)
2004 Lisp_Object orig_face
;
2005 Lisp_Object tortoise
, hare
;
2007 if (STRINGP (face_name
))
2008 face_name
= intern (SSDATA (face_name
));
2010 if (NILP (face_name
) || !SYMBOLP (face_name
))
2013 orig_face
= face_name
;
2014 tortoise
= hare
= face_name
;
2019 hare
= Fget (hare
, Qface_alias
);
2020 if (NILP (hare
) || !SYMBOLP (hare
))
2024 hare
= Fget (hare
, Qface_alias
);
2025 if (NILP (hare
) || !SYMBOLP (hare
))
2028 tortoise
= Fget (tortoise
, Qface_alias
);
2029 if (EQ (hare
, tortoise
))
2032 xsignal1 (Qcircular_list
, orig_face
);
2041 /* Return the face definition of FACE_NAME on frame F. F null means
2042 return the definition for new frames. FACE_NAME may be a string or
2043 a symbol (apparently Emacs 20.2 allowed strings as face names in
2044 face text properties; Ediff uses that). If SIGNAL_P is non-zero,
2045 signal an error if FACE_NAME is not a valid face name. If SIGNAL_P
2046 is zero, value is nil if FACE_NAME is not a valid face name. */
2047 static inline Lisp_Object
2048 lface_from_face_name_no_resolve (struct frame
*f
, Lisp_Object face_name
,
2054 lface
= assq_no_quit (face_name
, f
->face_alist
);
2056 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
2059 lface
= XCDR (lface
);
2061 signal_error ("Invalid face", face_name
);
2063 check_lface (lface
);
2068 /* Return the face definition of FACE_NAME on frame F. F null means
2069 return the definition for new frames. FACE_NAME may be a string or
2070 a symbol (apparently Emacs 20.2 allowed strings as face names in
2071 face text properties; Ediff uses that). If FACE_NAME is an alias
2072 for another face, return that face's definition. If SIGNAL_P is
2073 non-zero, signal an error if FACE_NAME is not a valid face name.
2074 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
2076 static inline Lisp_Object
2077 lface_from_face_name (struct frame
*f
, Lisp_Object face_name
, int signal_p
)
2079 face_name
= resolve_face_name (face_name
, signal_p
);
2080 return lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2084 /* Get face attributes of face FACE_NAME from frame-local faces on
2085 frame F. Store the resulting attributes in ATTRS which must point
2086 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
2087 is non-zero, signal an error if FACE_NAME does not name a face.
2088 Otherwise, value is zero if FACE_NAME is not a face. */
2091 get_lface_attributes_no_remap (struct frame
*f
, Lisp_Object face_name
,
2092 Lisp_Object
*attrs
, int signal_p
)
2096 lface
= lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2099 memcpy (attrs
, XVECTOR (lface
)->contents
,
2100 LFACE_VECTOR_SIZE
* sizeof *attrs
);
2102 return !NILP (lface
);
2105 /* Get face attributes of face FACE_NAME from frame-local faces on frame
2106 F. Store the resulting attributes in ATTRS which must point to a
2107 vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If FACE_NAME is an
2108 alias for another face, use that face's definition. If SIGNAL_P is
2109 non-zero, signal an error if FACE_NAME does not name a face.
2110 Otherwise, value is zero if FACE_NAME is not a face. */
2113 get_lface_attributes (struct frame
*f
, Lisp_Object face_name
,
2114 Lisp_Object
*attrs
, int signal_p
,
2115 struct named_merge_point
*named_merge_points
)
2117 Lisp_Object face_remapping
;
2119 face_name
= resolve_face_name (face_name
, signal_p
);
2121 /* See if SYMBOL has been remapped to some other face (usually this
2122 is done buffer-locally). */
2123 face_remapping
= assq_no_quit (face_name
, Vface_remapping_alist
);
2124 if (CONSP (face_remapping
))
2126 struct named_merge_point named_merge_point
;
2128 if (push_named_merge_point (&named_merge_point
,
2129 face_name
, NAMED_MERGE_POINT_REMAP
,
2130 &named_merge_points
))
2134 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2135 attrs
[i
] = Qunspecified
;
2137 return merge_face_ref (f
, XCDR (face_remapping
), attrs
,
2138 signal_p
, named_merge_points
);
2142 /* Default case, no remapping. */
2143 return get_lface_attributes_no_remap (f
, face_name
, attrs
, signal_p
);
2147 /* Non-zero if all attributes in face attribute vector ATTRS are
2148 specified, i.e. are non-nil. */
2151 lface_fully_specified_p (Lisp_Object
*attrs
)
2155 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2156 if (i
!= LFACE_FONT_INDEX
&& i
!= LFACE_INHERIT_INDEX
)
2157 if ((UNSPECIFIEDP (attrs
[i
]) || IGNORE_DEFFACE_P (attrs
[i
])))
2160 return i
== LFACE_VECTOR_SIZE
;
2163 #ifdef HAVE_WINDOW_SYSTEM
2165 /* Set font-related attributes of Lisp face LFACE from FONT-OBJECT.
2166 If FORCE_P is zero, set only unspecified attributes of LFACE. The
2167 exception is `font' attribute. It is set to FONT_OBJECT regardless
2171 set_lface_from_font (struct frame
*f
, Lisp_Object lface
,
2172 Lisp_Object font_object
, int force_p
)
2175 struct font
*font
= XFONT_OBJECT (font_object
);
2177 /* Set attributes only if unspecified, otherwise face defaults for
2178 new frames would never take effect. If the font doesn't have a
2179 specific property, set a normal value for that. */
2181 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
2183 Lisp_Object family
= AREF (font_object
, FONT_FAMILY_INDEX
);
2185 LFACE_FAMILY (lface
) = SYMBOL_NAME (family
);
2188 if (force_p
|| UNSPECIFIEDP (LFACE_FOUNDRY (lface
)))
2190 Lisp_Object foundry
= AREF (font_object
, FONT_FOUNDRY_INDEX
);
2192 LFACE_FOUNDRY (lface
) = SYMBOL_NAME (foundry
);
2195 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
2197 int pt
= PIXEL_TO_POINT (font
->pixel_size
* 10, f
->resy
);
2200 LFACE_HEIGHT (lface
) = make_number (pt
);
2203 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
2205 val
= FONT_WEIGHT_FOR_FACE (font_object
);
2206 LFACE_WEIGHT (lface
) = ! NILP (val
) ? val
:Qnormal
;
2208 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
2210 val
= FONT_SLANT_FOR_FACE (font_object
);
2211 LFACE_SLANT (lface
) = ! NILP (val
) ? val
: Qnormal
;
2213 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
2215 val
= FONT_WIDTH_FOR_FACE (font_object
);
2216 LFACE_SWIDTH (lface
) = ! NILP (val
) ? val
: Qnormal
;
2219 LFACE_FONT (lface
) = font_object
;
2223 #endif /* HAVE_WINDOW_SYSTEM */
2226 /* Merges the face height FROM with the face height TO, and returns the
2227 merged height. If FROM is an invalid height, then INVALID is
2228 returned instead. FROM and TO may be either absolute face heights or
2229 `relative' heights; the returned value is always an absolute height
2230 unless both FROM and TO are relative. */
2233 merge_face_heights (Lisp_Object from
, Lisp_Object to
, Lisp_Object invalid
)
2235 Lisp_Object result
= invalid
;
2237 if (INTEGERP (from
))
2238 /* FROM is absolute, just use it as is. */
2240 else if (FLOATP (from
))
2241 /* FROM is a scale, use it to adjust TO. */
2244 /* relative X absolute => absolute */
2245 result
= make_number (XFLOAT_DATA (from
) * XINT (to
));
2246 else if (FLOATP (to
))
2247 /* relative X relative => relative */
2248 result
= make_float (XFLOAT_DATA (from
) * XFLOAT_DATA (to
));
2249 else if (UNSPECIFIEDP (to
))
2252 else if (FUNCTIONP (from
))
2253 /* FROM is a function, which use to adjust TO. */
2255 /* Call function with current height as argument.
2256 From is the new height. */
2257 Lisp_Object args
[2];
2261 result
= safe_call (2, args
);
2263 /* Ensure that if TO was absolute, so is the result. */
2264 if (INTEGERP (to
) && !INTEGERP (result
))
2272 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
2273 store the resulting attributes in TO, which must be already be
2274 completely specified and contain only absolute attributes. Every
2275 specified attribute of FROM overrides the corresponding attribute of
2276 TO; relative attributes in FROM are merged with the absolute value in
2277 TO and replace it. NAMED_MERGE_POINTS is used internally to detect
2278 loops in face inheritance/remapping; it should be 0 when called from
2282 merge_face_vectors (struct frame
*f
, Lisp_Object
*from
, Lisp_Object
*to
,
2283 struct named_merge_point
*named_merge_points
)
2287 /* If FROM inherits from some other faces, merge their attributes into
2288 TO before merging FROM's direct attributes. Note that an :inherit
2289 attribute of `unspecified' is the same as one of nil; we never
2290 merge :inherit attributes, so nil is more correct, but lots of
2291 other code uses `unspecified' as a generic value for face attributes. */
2292 if (!UNSPECIFIEDP (from
[LFACE_INHERIT_INDEX
])
2293 && !NILP (from
[LFACE_INHERIT_INDEX
]))
2294 merge_face_ref (f
, from
[LFACE_INHERIT_INDEX
], to
, 0, named_merge_points
);
2296 i
= LFACE_FONT_INDEX
;
2297 if (!UNSPECIFIEDP (from
[i
]))
2299 if (!UNSPECIFIEDP (to
[i
]))
2300 to
[i
] = merge_font_spec (from
[i
], to
[i
]);
2302 to
[i
] = copy_font_spec (from
[i
]);
2303 if (! NILP (AREF (to
[i
], FONT_FOUNDRY_INDEX
)))
2304 to
[LFACE_FOUNDRY_INDEX
] = SYMBOL_NAME (AREF (to
[i
], FONT_FOUNDRY_INDEX
));
2305 if (! NILP (AREF (to
[i
], FONT_FAMILY_INDEX
)))
2306 to
[LFACE_FAMILY_INDEX
] = SYMBOL_NAME (AREF (to
[i
], FONT_FAMILY_INDEX
));
2307 if (! NILP (AREF (to
[i
], FONT_WEIGHT_INDEX
)))
2308 to
[LFACE_WEIGHT_INDEX
] = FONT_WEIGHT_FOR_FACE (to
[i
]);
2309 if (! NILP (AREF (to
[i
], FONT_SLANT_INDEX
)))
2310 to
[LFACE_SLANT_INDEX
] = FONT_SLANT_FOR_FACE (to
[i
]);
2311 if (! NILP (AREF (to
[i
], FONT_WIDTH_INDEX
)))
2312 to
[LFACE_SWIDTH_INDEX
] = FONT_WIDTH_FOR_FACE (to
[i
]);
2313 ASET (to
[i
], FONT_SIZE_INDEX
, Qnil
);
2316 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2317 if (!UNSPECIFIEDP (from
[i
]))
2319 if (i
== LFACE_HEIGHT_INDEX
&& !INTEGERP (from
[i
]))
2321 to
[i
] = merge_face_heights (from
[i
], to
[i
], to
[i
]);
2322 font_clear_prop (to
, FONT_SIZE_INDEX
);
2324 else if (i
!= LFACE_FONT_INDEX
2325 && ! EQ (to
[i
], from
[i
]))
2328 if (i
>= LFACE_FAMILY_INDEX
&& i
<=LFACE_SLANT_INDEX
)
2329 font_clear_prop (to
,
2330 (i
== LFACE_FAMILY_INDEX
? FONT_FAMILY_INDEX
2331 : i
== LFACE_FOUNDRY_INDEX
? FONT_FOUNDRY_INDEX
2332 : i
== LFACE_SWIDTH_INDEX
? FONT_WIDTH_INDEX
2333 : i
== LFACE_HEIGHT_INDEX
? FONT_SIZE_INDEX
2334 : i
== LFACE_WEIGHT_INDEX
? FONT_WEIGHT_INDEX
2335 : FONT_SLANT_INDEX
));
2339 /* TO is always an absolute face, which should inherit from nothing.
2340 We blindly copy the :inherit attribute above and fix it up here. */
2341 to
[LFACE_INHERIT_INDEX
] = Qnil
;
2344 /* Merge the named face FACE_NAME on frame F, into the vector of face
2345 attributes TO. NAMED_MERGE_POINTS is used to detect loops in face
2346 inheritance. Returns true if FACE_NAME is a valid face name and
2347 merging succeeded. */
2350 merge_named_face (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*to
,
2351 struct named_merge_point
*named_merge_points
)
2353 struct named_merge_point named_merge_point
;
2355 if (push_named_merge_point (&named_merge_point
,
2356 face_name
, NAMED_MERGE_POINT_NORMAL
,
2357 &named_merge_points
))
2359 struct gcpro gcpro1
;
2360 Lisp_Object from
[LFACE_VECTOR_SIZE
];
2361 int ok
= get_lface_attributes (f
, face_name
, from
, 0, named_merge_points
);
2365 GCPRO1 (named_merge_point
.face_name
);
2366 merge_face_vectors (f
, from
, to
, named_merge_points
);
2377 /* Merge face attributes from the lisp `face reference' FACE_REF on
2378 frame F into the face attribute vector TO. If ERR_MSGS is non-zero,
2379 problems with FACE_REF cause an error message to be shown. Return
2380 non-zero if no errors occurred (regardless of the value of ERR_MSGS).
2381 NAMED_MERGE_POINTS is used to detect loops in face inheritance or
2382 list structure; it may be 0 for most callers.
2384 FACE_REF may be a single face specification or a list of such
2385 specifications. Each face specification can be:
2387 1. A symbol or string naming a Lisp face.
2389 2. A property list of the form (KEYWORD VALUE ...) where each
2390 KEYWORD is a face attribute name, and value is an appropriate value
2393 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
2394 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
2395 for compatibility with 20.2.
2397 Face specifications earlier in lists take precedence over later
2401 merge_face_ref (struct frame
*f
, Lisp_Object face_ref
, Lisp_Object
*to
,
2402 int err_msgs
, struct named_merge_point
*named_merge_points
)
2404 int ok
= 1; /* Succeed without an error? */
2406 if (CONSP (face_ref
))
2408 Lisp_Object first
= XCAR (face_ref
);
2410 if (EQ (first
, Qforeground_color
)
2411 || EQ (first
, Qbackground_color
))
2413 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
2414 . COLOR). COLOR must be a string. */
2415 Lisp_Object color_name
= XCDR (face_ref
);
2416 Lisp_Object color
= first
;
2418 if (STRINGP (color_name
))
2420 if (EQ (color
, Qforeground_color
))
2421 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
2423 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
2428 add_to_log ("Invalid face color", color_name
, Qnil
);
2432 else if (SYMBOLP (first
)
2433 && *SDATA (SYMBOL_NAME (first
)) == ':')
2435 /* Assume this is the property list form. */
2436 while (CONSP (face_ref
) && CONSP (XCDR (face_ref
)))
2438 Lisp_Object keyword
= XCAR (face_ref
);
2439 Lisp_Object value
= XCAR (XCDR (face_ref
));
2442 /* Specifying `unspecified' is a no-op. */
2443 if (EQ (value
, Qunspecified
))
2445 else if (EQ (keyword
, QCfamily
))
2447 if (STRINGP (value
))
2449 to
[LFACE_FAMILY_INDEX
] = value
;
2450 font_clear_prop (to
, FONT_FAMILY_INDEX
);
2455 else if (EQ (keyword
, QCfoundry
))
2457 if (STRINGP (value
))
2459 to
[LFACE_FOUNDRY_INDEX
] = value
;
2460 font_clear_prop (to
, FONT_FOUNDRY_INDEX
);
2465 else if (EQ (keyword
, QCheight
))
2467 Lisp_Object new_height
=
2468 merge_face_heights (value
, to
[LFACE_HEIGHT_INDEX
], Qnil
);
2470 if (! NILP (new_height
))
2472 to
[LFACE_HEIGHT_INDEX
] = new_height
;
2473 font_clear_prop (to
, FONT_SIZE_INDEX
);
2478 else if (EQ (keyword
, QCweight
))
2480 if (SYMBOLP (value
) && FONT_WEIGHT_NAME_NUMERIC (value
) >= 0)
2482 to
[LFACE_WEIGHT_INDEX
] = value
;
2483 font_clear_prop (to
, FONT_WEIGHT_INDEX
);
2488 else if (EQ (keyword
, QCslant
))
2490 if (SYMBOLP (value
) && FONT_SLANT_NAME_NUMERIC (value
) >= 0)
2492 to
[LFACE_SLANT_INDEX
] = value
;
2493 font_clear_prop (to
, FONT_SLANT_INDEX
);
2498 else if (EQ (keyword
, QCunderline
))
2504 to
[LFACE_UNDERLINE_INDEX
] = value
;
2508 else if (EQ (keyword
, QCoverline
))
2513 to
[LFACE_OVERLINE_INDEX
] = value
;
2517 else if (EQ (keyword
, QCstrike_through
))
2522 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
2526 else if (EQ (keyword
, QCbox
))
2529 value
= make_number (1);
2530 if (INTEGERP (value
)
2534 to
[LFACE_BOX_INDEX
] = value
;
2538 else if (EQ (keyword
, QCinverse_video
)
2539 || EQ (keyword
, QCreverse_video
))
2541 if (EQ (value
, Qt
) || NILP (value
))
2542 to
[LFACE_INVERSE_INDEX
] = value
;
2546 else if (EQ (keyword
, QCforeground
))
2548 if (STRINGP (value
))
2549 to
[LFACE_FOREGROUND_INDEX
] = value
;
2553 else if (EQ (keyword
, QCbackground
))
2555 if (STRINGP (value
))
2556 to
[LFACE_BACKGROUND_INDEX
] = value
;
2560 else if (EQ (keyword
, QCstipple
))
2562 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NS)
2563 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
2564 if (!NILP (pixmap_p
))
2565 to
[LFACE_STIPPLE_INDEX
] = value
;
2570 else if (EQ (keyword
, QCwidth
))
2572 if (SYMBOLP (value
) && FONT_WIDTH_NAME_NUMERIC (value
) >= 0)
2574 to
[LFACE_SWIDTH_INDEX
] = value
;
2575 font_clear_prop (to
, FONT_WIDTH_INDEX
);
2580 else if (EQ (keyword
, QCinherit
))
2582 /* This is not really very useful; it's just like a
2583 normal face reference. */
2584 if (! merge_face_ref (f
, value
, to
,
2585 err_msgs
, named_merge_points
))
2593 add_to_log ("Invalid face attribute %S %S", keyword
, value
);
2597 face_ref
= XCDR (XCDR (face_ref
));
2602 /* This is a list of face refs. Those at the beginning of the
2603 list take precedence over what follows, so we have to merge
2604 from the end backwards. */
2605 Lisp_Object next
= XCDR (face_ref
);
2608 ok
= merge_face_ref (f
, next
, to
, err_msgs
, named_merge_points
);
2610 if (! merge_face_ref (f
, first
, to
, err_msgs
, named_merge_points
))
2616 /* FACE_REF ought to be a face name. */
2617 ok
= merge_named_face (f
, face_ref
, to
, named_merge_points
);
2618 if (!ok
&& err_msgs
)
2619 add_to_log ("Invalid face reference: %s", face_ref
, Qnil
);
2626 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
2627 Sinternal_make_lisp_face
, 1, 2, 0,
2628 doc
: /* Make FACE, a symbol, a Lisp face with all attributes nil.
2629 If FACE was not known as a face before, create a new one.
2630 If optional argument FRAME is specified, make a frame-local face
2631 for that frame. Otherwise operate on the global face definition.
2632 Value is a vector of face attributes. */)
2633 (Lisp_Object face
, Lisp_Object frame
)
2635 Lisp_Object global_lface
, lface
;
2639 CHECK_SYMBOL (face
);
2640 global_lface
= lface_from_face_name (NULL
, face
, 0);
2644 CHECK_LIVE_FRAME (frame
);
2646 lface
= lface_from_face_name (f
, face
, 0);
2649 f
= NULL
, lface
= Qnil
;
2651 /* Add a global definition if there is none. */
2652 if (NILP (global_lface
))
2654 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2656 ASET (global_lface
, 0, Qface
);
2657 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
2658 Vface_new_frame_defaults
);
2660 /* Assign the new Lisp face a unique ID. The mapping from Lisp
2661 face id to Lisp face is given by the vector lface_id_to_name.
2662 The mapping from Lisp face to Lisp face id is given by the
2663 property `face' of the Lisp face name. */
2664 if (next_lface_id
== lface_id_to_name_size
)
2666 xpalloc (lface_id_to_name
, &lface_id_to_name_size
, 1, MAX_FACE_ID
,
2667 sizeof *lface_id_to_name
);
2669 lface_id_to_name
[next_lface_id
] = face
;
2670 Fput (face
, Qface
, make_number (next_lface_id
));
2674 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2675 ASET (global_lface
, i
, Qunspecified
);
2677 /* Add a frame-local definition. */
2682 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2684 ASET (lface
, 0, Qface
);
2685 f
->face_alist
= Fcons (Fcons (face
, lface
), f
->face_alist
);
2688 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2689 ASET (lface
, i
, Qunspecified
);
2692 lface
= global_lface
;
2694 /* Changing a named face means that all realized faces depending on
2695 that face are invalid. Since we cannot tell which realized faces
2696 depend on the face, make sure they are all removed. This is done
2697 by incrementing face_change_count. The next call to
2698 init_iterator will then free realized faces. */
2699 if (NILP (Fget (face
, Qface_no_inherit
)))
2701 ++face_change_count
;
2702 ++windows_or_buffers_changed
;
2705 eassert (LFACEP (lface
));
2706 check_lface (lface
);
2711 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
2712 Sinternal_lisp_face_p
, 1, 2, 0,
2713 doc
: /* Return non-nil if FACE names a face.
2714 FACE should be a symbol or string.
2715 If optional second argument FRAME is non-nil, check for the
2716 existence of a frame-local face with name FACE on that frame.
2717 Otherwise check for the existence of a global face. */)
2718 (Lisp_Object face
, Lisp_Object frame
)
2722 face
= resolve_face_name (face
, 1);
2726 CHECK_LIVE_FRAME (frame
);
2727 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2730 lface
= lface_from_face_name (NULL
, face
, 0);
2736 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
2737 Sinternal_copy_lisp_face
, 4, 4, 0,
2738 doc
: /* Copy face FROM to TO.
2739 If FRAME is t, copy the global face definition of FROM.
2740 Otherwise, copy the frame-local definition of FROM on FRAME.
2741 If NEW-FRAME is a frame, copy that data into the frame-local
2742 definition of TO on NEW-FRAME. If NEW-FRAME is nil,
2743 FRAME controls where the data is copied to.
2745 The value is TO. */)
2746 (Lisp_Object from
, Lisp_Object to
, Lisp_Object frame
, Lisp_Object new_frame
)
2748 Lisp_Object lface
, copy
;
2750 CHECK_SYMBOL (from
);
2755 /* Copy global definition of FROM. We don't make copies of
2756 strings etc. because 20.2 didn't do it either. */
2757 lface
= lface_from_face_name (NULL
, from
, 1);
2758 copy
= Finternal_make_lisp_face (to
, Qnil
);
2762 /* Copy frame-local definition of FROM. */
2763 if (NILP (new_frame
))
2765 CHECK_LIVE_FRAME (frame
);
2766 CHECK_LIVE_FRAME (new_frame
);
2767 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
2768 copy
= Finternal_make_lisp_face (to
, new_frame
);
2771 memcpy (XVECTOR (copy
)->contents
, XVECTOR (lface
)->contents
,
2772 LFACE_VECTOR_SIZE
* sizeof (Lisp_Object
));
2774 /* Changing a named face means that all realized faces depending on
2775 that face are invalid. Since we cannot tell which realized faces
2776 depend on the face, make sure they are all removed. This is done
2777 by incrementing face_change_count. The next call to
2778 init_iterator will then free realized faces. */
2779 if (NILP (Fget (to
, Qface_no_inherit
)))
2781 ++face_change_count
;
2782 ++windows_or_buffers_changed
;
2789 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
2790 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
2791 doc
: /* Set attribute ATTR of FACE to VALUE.
2792 FRAME being a frame means change the face on that frame.
2793 FRAME nil means change the face of the selected frame.
2794 FRAME t means change the default for new frames.
2795 FRAME 0 means change the face on all frames, and change the default
2797 (Lisp_Object face
, Lisp_Object attr
, Lisp_Object value
, Lisp_Object frame
)
2800 Lisp_Object old_value
= Qnil
;
2801 /* Set one of enum font_property_index (> 0) if ATTR is one of
2802 font-related attributes other than QCfont and QCfontset. */
2803 enum font_property_index prop_index
= 0;
2805 CHECK_SYMBOL (face
);
2806 CHECK_SYMBOL (attr
);
2808 face
= resolve_face_name (face
, 1);
2810 /* If FRAME is 0, change face on all frames, and change the
2811 default for new frames. */
2812 if (INTEGERP (frame
) && XINT (frame
) == 0)
2815 Finternal_set_lisp_face_attribute (face
, attr
, value
, Qt
);
2816 FOR_EACH_FRAME (tail
, frame
)
2817 Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
2821 /* Set lface to the Lisp attribute vector of FACE. */
2824 lface
= lface_from_face_name (NULL
, face
, 1);
2826 /* When updating face-new-frame-defaults, we put :ignore-defface
2827 where the caller wants `unspecified'. This forces the frame
2828 defaults to ignore the defface value. Otherwise, the defface
2829 will take effect, which is generally not what is intended.
2830 The value of that attribute will be inherited from some other
2831 face during face merging. See internal_merge_in_global_face. */
2832 if (UNSPECIFIEDP (value
))
2833 value
= QCignore_defface
;
2838 frame
= selected_frame
;
2840 CHECK_LIVE_FRAME (frame
);
2841 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2843 /* If a frame-local face doesn't exist yet, create one. */
2845 lface
= Finternal_make_lisp_face (face
, frame
);
2848 if (EQ (attr
, QCfamily
))
2850 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2852 CHECK_STRING (value
);
2853 if (SCHARS (value
) == 0)
2854 signal_error ("Invalid face family", value
);
2856 old_value
= LFACE_FAMILY (lface
);
2857 LFACE_FAMILY (lface
) = value
;
2858 prop_index
= FONT_FAMILY_INDEX
;
2860 else if (EQ (attr
, QCfoundry
))
2862 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2864 CHECK_STRING (value
);
2865 if (SCHARS (value
) == 0)
2866 signal_error ("Invalid face foundry", value
);
2868 old_value
= LFACE_FOUNDRY (lface
);
2869 LFACE_FOUNDRY (lface
) = value
;
2870 prop_index
= FONT_FOUNDRY_INDEX
;
2872 else if (EQ (attr
, QCheight
))
2874 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2876 if (EQ (face
, Qdefault
))
2878 /* The default face must have an absolute size. */
2879 if (!INTEGERP (value
) || XINT (value
) <= 0)
2880 signal_error ("Default face height not absolute and positive",
2885 /* For non-default faces, do a test merge with a random
2886 height to see if VALUE's ok. */
2887 Lisp_Object test
= merge_face_heights (value
,
2890 if (!INTEGERP (test
) || XINT (test
) <= 0)
2891 signal_error ("Face height does not produce a positive integer",
2896 old_value
= LFACE_HEIGHT (lface
);
2897 LFACE_HEIGHT (lface
) = value
;
2898 prop_index
= FONT_SIZE_INDEX
;
2900 else if (EQ (attr
, QCweight
))
2902 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2904 CHECK_SYMBOL (value
);
2905 if (FONT_WEIGHT_NAME_NUMERIC (value
) < 0)
2906 signal_error ("Invalid face weight", value
);
2908 old_value
= LFACE_WEIGHT (lface
);
2909 LFACE_WEIGHT (lface
) = value
;
2910 prop_index
= FONT_WEIGHT_INDEX
;
2912 else if (EQ (attr
, QCslant
))
2914 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2916 CHECK_SYMBOL (value
);
2917 if (FONT_SLANT_NAME_NUMERIC (value
) < 0)
2918 signal_error ("Invalid face slant", value
);
2920 old_value
= LFACE_SLANT (lface
);
2921 LFACE_SLANT (lface
) = value
;
2922 prop_index
= FONT_SLANT_INDEX
;
2924 else if (EQ (attr
, QCunderline
))
2928 if (UNSPECIFIEDP (value
) || IGNORE_DEFFACE_P (value
))
2930 else if (NILP (value
) || EQ (value
, Qt
))
2932 else if (STRINGP (value
) && SCHARS (value
) > 0)
2934 else if (CONSP (value
))
2936 Lisp_Object key
, val
, list
;
2941 while (!NILP (CAR_SAFE(list
)))
2943 key
= CAR_SAFE (list
);
2944 list
= CDR_SAFE (list
);
2945 val
= CAR_SAFE (list
);
2946 list
= CDR_SAFE (list
);
2948 if (NILP (key
) || NILP (val
))
2954 else if (EQ (key
, QCcolor
)
2955 && !(EQ (val
, Qforeground_color
)
2956 || (STRINGP (val
) && SCHARS (val
) > 0)))
2962 else if (EQ (key
, QCstyle
)
2963 && !(EQ (val
, Qline
) || EQ (val
, Qwave
)))
2972 signal_error ("Invalid face underline", value
);
2974 old_value
= LFACE_UNDERLINE (lface
);
2975 LFACE_UNDERLINE (lface
) = value
;
2977 else if (EQ (attr
, QCoverline
))
2979 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2980 if ((SYMBOLP (value
)
2982 && !EQ (value
, Qnil
))
2983 /* Overline color. */
2985 && SCHARS (value
) == 0))
2986 signal_error ("Invalid face overline", value
);
2988 old_value
= LFACE_OVERLINE (lface
);
2989 LFACE_OVERLINE (lface
) = value
;
2991 else if (EQ (attr
, QCstrike_through
))
2993 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2994 if ((SYMBOLP (value
)
2996 && !EQ (value
, Qnil
))
2997 /* Strike-through color. */
2999 && SCHARS (value
) == 0))
3000 signal_error ("Invalid face strike-through", value
);
3002 old_value
= LFACE_STRIKE_THROUGH (lface
);
3003 LFACE_STRIKE_THROUGH (lface
) = value
;
3005 else if (EQ (attr
, QCbox
))
3009 /* Allow t meaning a simple box of width 1 in foreground color
3012 value
= make_number (1);
3014 if (UNSPECIFIEDP (value
) || IGNORE_DEFFACE_P (value
))
3016 else if (NILP (value
))
3018 else if (INTEGERP (value
))
3019 valid_p
= XINT (value
) != 0;
3020 else if (STRINGP (value
))
3021 valid_p
= SCHARS (value
) > 0;
3022 else if (CONSP (value
))
3038 if (EQ (k
, QCline_width
))
3040 if (!INTEGERP (v
) || XINT (v
) == 0)
3043 else if (EQ (k
, QCcolor
))
3045 if (!NILP (v
) && (!STRINGP (v
) || SCHARS (v
) == 0))
3048 else if (EQ (k
, QCstyle
))
3050 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
3057 valid_p
= NILP (tem
);
3063 signal_error ("Invalid face box", value
);
3065 old_value
= LFACE_BOX (lface
);
3066 LFACE_BOX (lface
) = value
;
3068 else if (EQ (attr
, QCinverse_video
)
3069 || EQ (attr
, QCreverse_video
))
3071 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3073 CHECK_SYMBOL (value
);
3074 if (!EQ (value
, Qt
) && !NILP (value
))
3075 signal_error ("Invalid inverse-video face attribute value", value
);
3077 old_value
= LFACE_INVERSE (lface
);
3078 LFACE_INVERSE (lface
) = value
;
3080 else if (EQ (attr
, QCforeground
))
3082 /* Compatibility with 20.x. */
3084 value
= Qunspecified
;
3085 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3087 /* Don't check for valid color names here because it depends
3088 on the frame (display) whether the color will be valid
3089 when the face is realized. */
3090 CHECK_STRING (value
);
3091 if (SCHARS (value
) == 0)
3092 signal_error ("Empty foreground color value", value
);
3094 old_value
= LFACE_FOREGROUND (lface
);
3095 LFACE_FOREGROUND (lface
) = value
;
3097 else if (EQ (attr
, QCbackground
))
3099 /* Compatibility with 20.x. */
3101 value
= Qunspecified
;
3102 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3104 /* Don't check for valid color names here because it depends
3105 on the frame (display) whether the color will be valid
3106 when the face is realized. */
3107 CHECK_STRING (value
);
3108 if (SCHARS (value
) == 0)
3109 signal_error ("Empty background color value", value
);
3111 old_value
= LFACE_BACKGROUND (lface
);
3112 LFACE_BACKGROUND (lface
) = value
;
3114 else if (EQ (attr
, QCstipple
))
3116 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NS)
3117 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3119 && NILP (Fbitmap_spec_p (value
)))
3120 signal_error ("Invalid stipple attribute", value
);
3121 old_value
= LFACE_STIPPLE (lface
);
3122 LFACE_STIPPLE (lface
) = value
;
3123 #endif /* HAVE_X_WINDOWS || HAVE_NS */
3125 else if (EQ (attr
, QCwidth
))
3127 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3129 CHECK_SYMBOL (value
);
3130 if (FONT_WIDTH_NAME_NUMERIC (value
) < 0)
3131 signal_error ("Invalid face width", value
);
3133 old_value
= LFACE_SWIDTH (lface
);
3134 LFACE_SWIDTH (lface
) = value
;
3135 prop_index
= FONT_WIDTH_INDEX
;
3137 else if (EQ (attr
, QCfont
))
3139 #ifdef HAVE_WINDOW_SYSTEM
3140 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3142 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3146 old_value
= LFACE_FONT (lface
);
3147 if (! FONTP (value
))
3149 if (STRINGP (value
))
3151 Lisp_Object name
= value
;
3152 int fontset
= fs_query_fontset (name
, 0);
3155 name
= fontset_ascii (fontset
);
3156 value
= font_spec_from_name (name
);
3158 signal_error ("Invalid font name", name
);
3161 signal_error ("Invalid font or font-spec", value
);
3164 f
= XFRAME (selected_frame
);
3167 if (! FONT_OBJECT_P (value
))
3169 Lisp_Object
*attrs
= XVECTOR (lface
)->contents
;
3170 Lisp_Object font_object
;
3172 font_object
= font_load_for_lface (f
, attrs
, value
);
3173 if (NILP (font_object
))
3174 signal_error ("Font not available", value
);
3175 value
= font_object
;
3177 set_lface_from_font (f
, lface
, value
, 1);
3180 LFACE_FONT (lface
) = value
;
3182 #endif /* HAVE_WINDOW_SYSTEM */
3184 else if (EQ (attr
, QCfontset
))
3186 #ifdef HAVE_WINDOW_SYSTEM
3187 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3191 old_value
= LFACE_FONTSET (lface
);
3192 tmp
= Fquery_fontset (value
, Qnil
);
3194 signal_error ("Invalid fontset name", value
);
3195 LFACE_FONTSET (lface
) = value
= tmp
;
3197 #endif /* HAVE_WINDOW_SYSTEM */
3199 else if (EQ (attr
, QCinherit
))
3202 if (SYMBOLP (value
))
3205 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
3206 if (!SYMBOLP (XCAR (tail
)))
3209 LFACE_INHERIT (lface
) = value
;
3211 signal_error ("Invalid face inheritance", value
);
3213 else if (EQ (attr
, QCbold
))
3215 old_value
= LFACE_WEIGHT (lface
);
3216 LFACE_WEIGHT (lface
) = NILP (value
) ? Qnormal
: Qbold
;
3217 prop_index
= FONT_WEIGHT_INDEX
;
3219 else if (EQ (attr
, QCitalic
))
3222 old_value
= LFACE_SLANT (lface
);
3223 LFACE_SLANT (lface
) = NILP (value
) ? Qnormal
: Qitalic
;
3224 prop_index
= FONT_SLANT_INDEX
;
3227 signal_error ("Invalid face attribute name", attr
);
3231 /* If a font-related attribute other than QCfont and QCfontset
3232 is specified, and if the original QCfont attribute has a font
3233 (font-spec or font-object), set the corresponding property in
3234 the font to nil so that the font selector doesn't think that
3235 the attribute is mandatory. Also, clear the average
3237 font_clear_prop (XVECTOR (lface
)->contents
, prop_index
);
3240 /* Changing a named face means that all realized faces depending on
3241 that face are invalid. Since we cannot tell which realized faces
3242 depend on the face, make sure they are all removed. This is done
3243 by incrementing face_change_count. The next call to
3244 init_iterator will then free realized faces. */
3246 && NILP (Fget (face
, Qface_no_inherit
))
3247 && NILP (Fequal (old_value
, value
)))
3249 ++face_change_count
;
3250 ++windows_or_buffers_changed
;
3253 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3254 && NILP (Fequal (old_value
, value
)))
3260 if (EQ (face
, Qdefault
))
3262 #ifdef HAVE_WINDOW_SYSTEM
3263 /* Changed font-related attributes of the `default' face are
3264 reflected in changed `font' frame parameters. */
3266 && (prop_index
|| EQ (attr
, QCfont
))
3267 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
3268 set_font_frame_param (frame
, lface
);
3270 #endif /* HAVE_WINDOW_SYSTEM */
3272 if (EQ (attr
, QCforeground
))
3273 param
= Qforeground_color
;
3274 else if (EQ (attr
, QCbackground
))
3275 param
= Qbackground_color
;
3277 #ifdef HAVE_WINDOW_SYSTEM
3279 else if (EQ (face
, Qscroll_bar
))
3281 /* Changing the colors of `scroll-bar' sets frame parameters
3282 `scroll-bar-foreground' and `scroll-bar-background'. */
3283 if (EQ (attr
, QCforeground
))
3284 param
= Qscroll_bar_foreground
;
3285 else if (EQ (attr
, QCbackground
))
3286 param
= Qscroll_bar_background
;
3288 #endif /* not WINDOWSNT */
3289 else if (EQ (face
, Qborder
))
3291 /* Changing background color of `border' sets frame parameter
3293 if (EQ (attr
, QCbackground
))
3294 param
= Qborder_color
;
3296 else if (EQ (face
, Qcursor
))
3298 /* Changing background color of `cursor' sets frame parameter
3300 if (EQ (attr
, QCbackground
))
3301 param
= Qcursor_color
;
3303 else if (EQ (face
, Qmouse
))
3305 /* Changing background color of `mouse' sets frame parameter
3307 if (EQ (attr
, QCbackground
))
3308 param
= Qmouse_color
;
3310 #endif /* HAVE_WINDOW_SYSTEM */
3311 else if (EQ (face
, Qmenu
))
3313 /* Indicate that we have to update the menu bar when
3314 realizing faces on FRAME. FRAME t change the
3315 default for new frames. We do this by setting
3316 setting the flag in new face caches */
3319 struct frame
*f
= XFRAME (frame
);
3320 if (FRAME_FACE_CACHE (f
) == NULL
)
3321 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
3322 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 1;
3325 menu_face_changed_default
= 1;
3331 /* Update `default-frame-alist', which is used for new frames. */
3333 store_in_alist (&Vdefault_frame_alist
, param
, value
);
3336 /* Update the current frame's parameters. */
3339 cons
= XCAR (Vparam_value_alist
);
3340 XSETCAR (cons
, param
);
3341 XSETCDR (cons
, value
);
3342 Fmodify_frame_parameters (frame
, Vparam_value_alist
);
3351 /* Update the corresponding face when frame parameter PARAM on frame F
3352 has been assigned the value NEW_VALUE. */
3355 update_face_from_frame_parameter (struct frame
*f
, Lisp_Object param
,
3356 Lisp_Object new_value
)
3358 Lisp_Object face
= Qnil
;
3361 /* If there are no faces yet, give up. This is the case when called
3362 from Fx_create_frame, and we do the necessary things later in
3363 face-set-after-frame-defaults. */
3364 if (NILP (f
->face_alist
))
3367 if (EQ (param
, Qforeground_color
))
3370 lface
= lface_from_face_name (f
, face
, 1);
3371 LFACE_FOREGROUND (lface
) = (STRINGP (new_value
)
3372 ? new_value
: Qunspecified
);
3373 realize_basic_faces (f
);
3375 else if (EQ (param
, Qbackground_color
))
3379 /* Changing the background color might change the background
3380 mode, so that we have to load new defface specs.
3381 Call frame-set-background-mode to do that. */
3382 XSETFRAME (frame
, f
);
3383 call1 (Qframe_set_background_mode
, frame
);
3386 lface
= lface_from_face_name (f
, face
, 1);
3387 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3388 ? new_value
: Qunspecified
);
3389 realize_basic_faces (f
);
3391 #ifdef HAVE_WINDOW_SYSTEM
3392 else if (EQ (param
, Qborder_color
))
3395 lface
= lface_from_face_name (f
, face
, 1);
3396 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3397 ? new_value
: Qunspecified
);
3399 else if (EQ (param
, Qcursor_color
))
3402 lface
= lface_from_face_name (f
, face
, 1);
3403 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3404 ? new_value
: Qunspecified
);
3406 else if (EQ (param
, Qmouse_color
))
3409 lface
= lface_from_face_name (f
, face
, 1);
3410 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3411 ? new_value
: Qunspecified
);
3415 /* Changing a named face means that all realized faces depending on
3416 that face are invalid. Since we cannot tell which realized faces
3417 depend on the face, make sure they are all removed. This is done
3418 by incrementing face_change_count. The next call to
3419 init_iterator will then free realized faces. */
3421 && NILP (Fget (face
, Qface_no_inherit
)))
3423 ++face_change_count
;
3424 ++windows_or_buffers_changed
;
3429 #ifdef HAVE_WINDOW_SYSTEM
3431 /* Set the `font' frame parameter of FRAME determined from the
3432 font-object set in `default' face attributes LFACE. */
3435 set_font_frame_param (Lisp_Object frame
, Lisp_Object lface
)
3437 struct frame
*f
= XFRAME (frame
);
3440 if (FRAME_WINDOW_P (f
)
3441 /* Don't do anything if the font is `unspecified'. This can
3442 happen during frame creation. */
3443 && (font
= LFACE_FONT (lface
),
3444 ! UNSPECIFIEDP (font
)))
3446 if (FONT_SPEC_P (font
))
3448 font
= font_load_for_lface (f
, XVECTOR (lface
)->contents
, font
);
3451 LFACE_FONT (lface
) = font
;
3453 f
->default_face_done_p
= 0;
3454 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, font
), Qnil
));
3459 /* Get the value of X resource RESOURCE, class CLASS for the display
3460 of frame FRAME. This is here because ordinary `x-get-resource'
3461 doesn't take a frame argument. */
3463 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
3464 Sinternal_face_x_get_resource
, 3, 3, 0, doc
: /* */)
3465 (Lisp_Object resource
, Lisp_Object
class, Lisp_Object frame
)
3467 Lisp_Object value
= Qnil
;
3468 CHECK_STRING (resource
);
3469 CHECK_STRING (class);
3470 CHECK_LIVE_FRAME (frame
);
3472 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame
)),
3473 resource
, class, Qnil
, Qnil
);
3479 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
3480 If VALUE is "on" or "true", return t. If VALUE is "off" or
3481 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
3482 error; if SIGNAL_P is zero, return 0. */
3485 face_boolean_x_resource_value (Lisp_Object value
, int signal_p
)
3487 Lisp_Object result
= make_number (0);
3489 eassert (STRINGP (value
));
3491 if (xstrcasecmp (SSDATA (value
), "on") == 0
3492 || xstrcasecmp (SSDATA (value
), "true") == 0)
3494 else if (xstrcasecmp (SSDATA (value
), "off") == 0
3495 || xstrcasecmp (SSDATA (value
), "false") == 0)
3497 else if (xstrcasecmp (SSDATA (value
), "unspecified") == 0)
3498 result
= Qunspecified
;
3500 signal_error ("Invalid face attribute value from X resource", value
);
3506 DEFUN ("internal-set-lisp-face-attribute-from-resource",
3507 Finternal_set_lisp_face_attribute_from_resource
,
3508 Sinternal_set_lisp_face_attribute_from_resource
,
3509 3, 4, 0, doc
: /* */)
3510 (Lisp_Object face
, Lisp_Object attr
, Lisp_Object value
, Lisp_Object frame
)
3512 CHECK_SYMBOL (face
);
3513 CHECK_SYMBOL (attr
);
3514 CHECK_STRING (value
);
3516 if (xstrcasecmp (SSDATA (value
), "unspecified") == 0)
3517 value
= Qunspecified
;
3518 else if (EQ (attr
, QCheight
))
3520 value
= Fstring_to_number (value
, make_number (10));
3521 if (XINT (value
) <= 0)
3522 signal_error ("Invalid face height from X resource", value
);
3524 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
3525 value
= face_boolean_x_resource_value (value
, 1);
3526 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
3527 value
= intern (SSDATA (value
));
3528 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
3529 value
= face_boolean_x_resource_value (value
, 1);
3530 else if (EQ (attr
, QCunderline
)
3531 || EQ (attr
, QCoverline
)
3532 || EQ (attr
, QCstrike_through
))
3534 Lisp_Object boolean_value
;
3536 /* If the result of face_boolean_x_resource_value is t or nil,
3537 VALUE does NOT specify a color. */
3538 boolean_value
= face_boolean_x_resource_value (value
, 0);
3539 if (SYMBOLP (boolean_value
))
3540 value
= boolean_value
;
3542 else if (EQ (attr
, QCbox
) || EQ (attr
, QCinherit
))
3543 value
= Fcar (Fread_from_string (value
, Qnil
, Qnil
));
3545 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3548 #endif /* HAVE_WINDOW_SYSTEM */
3551 /***********************************************************************
3553 ***********************************************************************/
3555 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
3557 /* Make menus on frame F appear as specified by the `menu' face. */
3560 x_update_menu_appearance (struct frame
*f
)
3562 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3566 && (rdb
= XrmGetDatabase (FRAME_X_DISPLAY (f
)),
3571 ptrdiff_t bufsize
= sizeof line
;
3572 Lisp_Object lface
= lface_from_face_name (f
, Qmenu
, 1);
3573 struct face
*face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
3574 const char *myname
= SSDATA (Vx_resource_name
);
3577 const char *popup_path
= "popup_menu";
3579 const char *popup_path
= "menu.popup";
3582 if (STRINGP (LFACE_FOREGROUND (lface
)))
3584 exprintf (&buf
, &bufsize
, line
, -1, "%s.%s*foreground: %s",
3586 SDATA (LFACE_FOREGROUND (lface
)));
3587 XrmPutLineResource (&rdb
, line
);
3588 exprintf (&buf
, &bufsize
, line
, -1, "%s.pane.menubar*foreground: %s",
3589 myname
, SDATA (LFACE_FOREGROUND (lface
)));
3590 XrmPutLineResource (&rdb
, line
);
3594 if (STRINGP (LFACE_BACKGROUND (lface
)))
3596 exprintf (&buf
, &bufsize
, line
, -1, "%s.%s*background: %s",
3598 SDATA (LFACE_BACKGROUND (lface
)));
3599 XrmPutLineResource (&rdb
, line
);
3601 exprintf (&buf
, &bufsize
, line
, -1, "%s.pane.menubar*background: %s",
3602 myname
, SDATA (LFACE_BACKGROUND (lface
)));
3603 XrmPutLineResource (&rdb
, line
);
3608 /* On Solaris 5.8, it's been reported that the `menu' face
3609 can be unspecified here, during startup. Why this
3610 happens remains unknown. -- cyd */
3611 && FONTP (LFACE_FONT (lface
))
3612 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
3613 || !UNSPECIFIEDP (LFACE_FOUNDRY (lface
))
3614 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
3615 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3616 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
3617 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
3619 Lisp_Object xlfd
= Ffont_xlfd_name (LFACE_FONT (lface
), Qnil
);
3621 const char *suffix
= "List";
3624 #if defined HAVE_X_I18N
3626 const char *suffix
= "Set";
3628 const char *suffix
= "";
3635 #if defined HAVE_X_I18N
3636 char *fontsetname
= xic_create_fontsetname (SSDATA (xlfd
), motif
);
3638 char *fontsetname
= SSDATA (xlfd
);
3640 exprintf (&buf
, &bufsize
, line
, -1, "%s.pane.menubar*font%s: %s",
3641 myname
, suffix
, fontsetname
);
3642 XrmPutLineResource (&rdb
, line
);
3644 exprintf (&buf
, &bufsize
, line
, -1, "%s.%s*font%s: %s",
3645 myname
, popup_path
, suffix
, fontsetname
);
3646 XrmPutLineResource (&rdb
, line
);
3648 if (fontsetname
!= SSDATA (xlfd
))
3649 xfree (fontsetname
);
3653 if (changed_p
&& f
->output_data
.x
->menubar_widget
)
3654 free_frame_menubar (f
);
3661 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
3664 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p
,
3665 Sface_attribute_relative_p
,
3667 doc
: /* Check whether a face attribute value is relative.
3668 Specifically, this function returns t if the attribute ATTRIBUTE
3669 with the value VALUE is relative.
3671 A relative value is one that doesn't entirely override whatever is
3672 inherited from another face. For most possible attributes,
3673 the only relative value that users see is `unspecified'.
3674 However, for :height, floating point values are also relative. */)
3675 (Lisp_Object attribute
, Lisp_Object value
)
3677 if (EQ (value
, Qunspecified
) || (EQ (value
, QCignore_defface
)))
3679 else if (EQ (attribute
, QCheight
))
3680 return INTEGERP (value
) ? Qnil
: Qt
;
3685 DEFUN ("merge-face-attribute", Fmerge_face_attribute
, Smerge_face_attribute
,
3687 doc
: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
3688 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
3689 the result will be absolute, otherwise it will be relative. */)
3690 (Lisp_Object attribute
, Lisp_Object value1
, Lisp_Object value2
)
3692 if (EQ (value1
, Qunspecified
) || EQ (value1
, QCignore_defface
))
3694 else if (EQ (attribute
, QCheight
))
3695 return merge_face_heights (value1
, value2
, value1
);
3701 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
3702 Sinternal_get_lisp_face_attribute
,
3704 doc
: /* Return face attribute KEYWORD of face SYMBOL.
3705 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
3706 face attribute name, signal an error.
3707 If the optional argument FRAME is given, report on face SYMBOL in that
3708 frame. If FRAME is t, report on the defaults for face SYMBOL (for new
3709 frames). If FRAME is omitted or nil, use the selected frame. */)
3710 (Lisp_Object symbol
, Lisp_Object keyword
, Lisp_Object frame
)
3712 Lisp_Object lface
, value
= Qnil
;
3714 CHECK_SYMBOL (symbol
);
3715 CHECK_SYMBOL (keyword
);
3718 lface
= lface_from_face_name (NULL
, symbol
, 1);
3722 frame
= selected_frame
;
3723 CHECK_LIVE_FRAME (frame
);
3724 lface
= lface_from_face_name (XFRAME (frame
), symbol
, 1);
3727 if (EQ (keyword
, QCfamily
))
3728 value
= LFACE_FAMILY (lface
);
3729 else if (EQ (keyword
, QCfoundry
))
3730 value
= LFACE_FOUNDRY (lface
);
3731 else if (EQ (keyword
, QCheight
))
3732 value
= LFACE_HEIGHT (lface
);
3733 else if (EQ (keyword
, QCweight
))
3734 value
= LFACE_WEIGHT (lface
);
3735 else if (EQ (keyword
, QCslant
))
3736 value
= LFACE_SLANT (lface
);
3737 else if (EQ (keyword
, QCunderline
))
3738 value
= LFACE_UNDERLINE (lface
);
3739 else if (EQ (keyword
, QCoverline
))
3740 value
= LFACE_OVERLINE (lface
);
3741 else if (EQ (keyword
, QCstrike_through
))
3742 value
= LFACE_STRIKE_THROUGH (lface
);
3743 else if (EQ (keyword
, QCbox
))
3744 value
= LFACE_BOX (lface
);
3745 else if (EQ (keyword
, QCinverse_video
)
3746 || EQ (keyword
, QCreverse_video
))
3747 value
= LFACE_INVERSE (lface
);
3748 else if (EQ (keyword
, QCforeground
))
3749 value
= LFACE_FOREGROUND (lface
);
3750 else if (EQ (keyword
, QCbackground
))
3751 value
= LFACE_BACKGROUND (lface
);
3752 else if (EQ (keyword
, QCstipple
))
3753 value
= LFACE_STIPPLE (lface
);
3754 else if (EQ (keyword
, QCwidth
))
3755 value
= LFACE_SWIDTH (lface
);
3756 else if (EQ (keyword
, QCinherit
))
3757 value
= LFACE_INHERIT (lface
);
3758 else if (EQ (keyword
, QCfont
))
3759 value
= LFACE_FONT (lface
);
3760 else if (EQ (keyword
, QCfontset
))
3761 value
= LFACE_FONTSET (lface
);
3763 signal_error ("Invalid face attribute name", keyword
);
3765 if (IGNORE_DEFFACE_P (value
))
3766 return Qunspecified
;
3772 DEFUN ("internal-lisp-face-attribute-values",
3773 Finternal_lisp_face_attribute_values
,
3774 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
3775 doc
: /* Return a list of valid discrete values for face attribute ATTR.
3776 Value is nil if ATTR doesn't have a discrete set of valid values. */)
3779 Lisp_Object result
= Qnil
;
3781 CHECK_SYMBOL (attr
);
3783 if (EQ (attr
, QCunderline
))
3784 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3785 else if (EQ (attr
, QCoverline
))
3786 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3787 else if (EQ (attr
, QCstrike_through
))
3788 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3789 else if (EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
3790 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3796 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
3797 Sinternal_merge_in_global_face
, 2, 2, 0,
3798 doc
: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
3799 Default face attributes override any local face attributes. */)
3800 (Lisp_Object face
, Lisp_Object frame
)
3803 Lisp_Object global_lface
, local_lface
, *gvec
, *lvec
;
3804 struct frame
*f
= XFRAME (frame
);
3806 CHECK_LIVE_FRAME (frame
);
3807 global_lface
= lface_from_face_name (NULL
, face
, 1);
3808 local_lface
= lface_from_face_name (f
, face
, 0);
3809 if (NILP (local_lface
))
3810 local_lface
= Finternal_make_lisp_face (face
, frame
);
3812 /* Make every specified global attribute override the local one.
3813 BEWARE!! This is only used from `face-set-after-frame-default' where
3814 the local frame is defined from default specs in `face-defface-spec'
3815 and those should be overridden by global settings. Hence the strange
3816 "global before local" priority. */
3817 lvec
= XVECTOR (local_lface
)->contents
;
3818 gvec
= XVECTOR (global_lface
)->contents
;
3819 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3820 if (IGNORE_DEFFACE_P (gvec
[i
]))
3821 lvec
[i
] = Qunspecified
;
3822 else if (! UNSPECIFIEDP (gvec
[i
]))
3825 /* If the default face was changed, update the face cache and the
3826 `font' frame parameter. */
3827 if (EQ (face
, Qdefault
))
3829 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
3830 struct face
*newface
, *oldface
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
3831 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
3833 /* This can be NULL (e.g., in batch mode). */
3836 /* Ensure that the face vector is fully specified by merging
3837 the previously-cached vector. */
3838 memcpy (attrs
, oldface
->lface
, sizeof attrs
);
3839 merge_face_vectors (f
, lvec
, attrs
, 0);
3840 memcpy (lvec
, attrs
, sizeof attrs
);
3841 newface
= realize_face (c
, lvec
, DEFAULT_FACE_ID
);
3843 if ((! UNSPECIFIEDP (gvec
[LFACE_FAMILY_INDEX
])
3844 || ! UNSPECIFIEDP (gvec
[LFACE_FOUNDRY_INDEX
])
3845 || ! UNSPECIFIEDP (gvec
[LFACE_HEIGHT_INDEX
])
3846 || ! UNSPECIFIEDP (gvec
[LFACE_WEIGHT_INDEX
])
3847 || ! UNSPECIFIEDP (gvec
[LFACE_SLANT_INDEX
])
3848 || ! UNSPECIFIEDP (gvec
[LFACE_SWIDTH_INDEX
])
3849 || ! UNSPECIFIEDP (gvec
[LFACE_FONT_INDEX
]))
3852 Lisp_Object name
= newface
->font
->props
[FONT_NAME_INDEX
];
3853 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, name
),
3857 if (STRINGP (gvec
[LFACE_FOREGROUND_INDEX
]))
3858 Fmodify_frame_parameters (frame
,
3859 Fcons (Fcons (Qforeground_color
,
3860 gvec
[LFACE_FOREGROUND_INDEX
]),
3863 if (STRINGP (gvec
[LFACE_BACKGROUND_INDEX
]))
3864 Fmodify_frame_parameters (frame
,
3865 Fcons (Fcons (Qbackground_color
,
3866 gvec
[LFACE_BACKGROUND_INDEX
]),
3875 /* The following function is implemented for compatibility with 20.2.
3876 The function is used in x-resolve-fonts when it is asked to
3877 return fonts with the same size as the font of a face. This is
3878 done in fontset.el. */
3880 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 3, 0,
3881 doc
: /* Return the font name of face FACE, or nil if it is unspecified.
3882 The font name is, by default, for ASCII characters.
3883 If the optional argument FRAME is given, report on face FACE in that frame.
3884 If FRAME is t, report on the defaults for face FACE (for new frames).
3885 The font default for a face is either nil, or a list
3886 of the form (bold), (italic) or (bold italic).
3887 If FRAME is omitted or nil, use the selected frame. And, in this case,
3888 if the optional third argument CHARACTER is given,
3889 return the font name used for CHARACTER. */)
3890 (Lisp_Object face
, Lisp_Object frame
, Lisp_Object character
)
3894 Lisp_Object result
= Qnil
;
3895 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
3897 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3898 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
3899 result
= Fcons (Qbold
, result
);
3901 if (!UNSPECIFIEDP (LFACE_SLANT (lface
))
3902 && !EQ (LFACE_SLANT (lface
), Qnormal
))
3903 result
= Fcons (Qitalic
, result
);
3909 struct frame
*f
= frame_or_selected_frame (frame
, 1);
3910 int face_id
= lookup_named_face (f
, face
, 1);
3911 struct face
*fface
= FACE_FROM_ID (f
, face_id
);
3915 #ifdef HAVE_WINDOW_SYSTEM
3916 if (FRAME_WINDOW_P (f
) && !NILP (character
))
3918 CHECK_CHARACTER (character
);
3919 face_id
= FACE_FOR_CHAR (f
, fface
, XINT (character
), -1, Qnil
);
3920 fface
= FACE_FROM_ID (f
, face_id
);
3923 ? fface
->font
->props
[FONT_NAME_INDEX
]
3925 #else /* !HAVE_WINDOW_SYSTEM */
3926 return build_string (FRAME_MSDOS_P (f
)
3928 : FRAME_W32_P (f
) ? "w32term"
3935 /* Compare face-attribute values v1 and v2 for equality. Value is non-zero if
3936 all attributes are `equal'. Tries to be fast because this function
3937 is called quite often. */
3940 face_attr_equal_p (Lisp_Object v1
, Lisp_Object v2
)
3942 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
3943 and the other is specified. */
3944 if (XTYPE (v1
) != XTYPE (v2
))
3953 if (SBYTES (v1
) != SBYTES (v2
))
3956 return memcmp (SDATA (v1
), SDATA (v2
), SBYTES (v1
)) == 0;
3963 return !NILP (Fequal (v1
, v2
));
3968 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
3969 all attributes are `equal'. Tries to be fast because this function
3970 is called quite often. */
3973 lface_equal_p (Lisp_Object
*v1
, Lisp_Object
*v2
)
3977 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
3978 equal_p
= face_attr_equal_p (v1
[i
], v2
[i
]);
3984 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
3985 Sinternal_lisp_face_equal_p
, 2, 3, 0,
3986 doc
: /* True if FACE1 and FACE2 are equal.
3987 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
3988 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
3989 If FRAME is omitted or nil, use the selected frame. */)
3990 (Lisp_Object face1
, Lisp_Object face2
, Lisp_Object frame
)
3994 Lisp_Object lface1
, lface2
;
3999 /* Don't use check_x_frame here because this function is called
4000 before X frames exist. At that time, if FRAME is nil,
4001 selected_frame will be used which is the frame dumped with
4002 Emacs. That frame is not an X frame. */
4003 f
= frame_or_selected_frame (frame
, 2);
4005 lface1
= lface_from_face_name (f
, face1
, 1);
4006 lface2
= lface_from_face_name (f
, face2
, 1);
4007 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
4008 XVECTOR (lface2
)->contents
);
4009 return equal_p
? Qt
: Qnil
;
4013 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
4014 Sinternal_lisp_face_empty_p
, 1, 2, 0,
4015 doc
: /* True if FACE has no attribute specified.
4016 If the optional argument FRAME is given, report on face FACE in that frame.
4017 If FRAME is t, report on the defaults for face FACE (for new frames).
4018 If FRAME is omitted or nil, use the selected frame. */)
4019 (Lisp_Object face
, Lisp_Object frame
)
4026 frame
= selected_frame
;
4027 CHECK_LIVE_FRAME (frame
);
4031 lface
= lface_from_face_name (NULL
, face
, 1);
4033 lface
= lface_from_face_name (f
, face
, 1);
4035 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4036 if (!UNSPECIFIEDP (AREF (lface
, i
)))
4039 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
4043 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
4045 doc
: /* Return an alist of frame-local faces defined on FRAME.
4046 For internal use only. */)
4049 struct frame
*f
= frame_or_selected_frame (frame
, 0);
4050 return f
->face_alist
;
4054 /* Return a hash code for Lisp string STRING with case ignored. Used
4055 below in computing a hash value for a Lisp face. */
4057 static inline unsigned
4058 hash_string_case_insensitive (Lisp_Object string
)
4060 const unsigned char *s
;
4062 eassert (STRINGP (string
));
4063 for (s
= SDATA (string
); *s
; ++s
)
4064 hash
= (hash
<< 1) ^ tolower (*s
);
4069 /* Return a hash code for face attribute vector V. */
4071 static inline unsigned
4072 lface_hash (Lisp_Object
*v
)
4074 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
4075 ^ hash_string_case_insensitive (v
[LFACE_FOUNDRY_INDEX
])
4076 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
4077 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
4078 ^ XHASH (v
[LFACE_WEIGHT_INDEX
])
4079 ^ XHASH (v
[LFACE_SLANT_INDEX
])
4080 ^ XHASH (v
[LFACE_SWIDTH_INDEX
])
4081 ^ XHASH (v
[LFACE_HEIGHT_INDEX
]));
4085 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
4086 considering charsets/registries). They do if they specify the same
4087 family, point size, weight, width, slant, and font. Both
4088 LFACE1 and LFACE2 must be fully-specified. */
4091 lface_same_font_attributes_p (Lisp_Object
*lface1
, Lisp_Object
*lface2
)
4093 eassert (lface_fully_specified_p (lface1
)
4094 && lface_fully_specified_p (lface2
));
4095 return (xstrcasecmp (SSDATA (lface1
[LFACE_FAMILY_INDEX
]),
4096 SSDATA (lface2
[LFACE_FAMILY_INDEX
])) == 0
4097 && xstrcasecmp (SSDATA (lface1
[LFACE_FOUNDRY_INDEX
]),
4098 SSDATA (lface2
[LFACE_FOUNDRY_INDEX
])) == 0
4099 && EQ (lface1
[LFACE_HEIGHT_INDEX
], lface2
[LFACE_HEIGHT_INDEX
])
4100 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
4101 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
4102 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
])
4103 && EQ (lface1
[LFACE_FONT_INDEX
], lface2
[LFACE_FONT_INDEX
])
4104 && (EQ (lface1
[LFACE_FONTSET_INDEX
], lface2
[LFACE_FONTSET_INDEX
])
4105 || (STRINGP (lface1
[LFACE_FONTSET_INDEX
])
4106 && STRINGP (lface2
[LFACE_FONTSET_INDEX
])
4107 && ! xstrcasecmp (SSDATA (lface1
[LFACE_FONTSET_INDEX
]),
4108 SSDATA (lface2
[LFACE_FONTSET_INDEX
]))))
4114 /***********************************************************************
4116 ***********************************************************************/
4118 /* Allocate and return a new realized face for Lisp face attribute
4121 static struct face
*
4122 make_realized_face (Lisp_Object
*attr
)
4124 struct face
*face
= xzalloc (sizeof *face
);
4125 face
->ascii_face
= face
;
4126 memcpy (face
->lface
, attr
, sizeof face
->lface
);
4131 /* Free realized face FACE, including its X resources. FACE may
4135 free_realized_face (struct frame
*f
, struct face
*face
)
4139 #ifdef HAVE_WINDOW_SYSTEM
4140 if (FRAME_WINDOW_P (f
))
4142 /* Free fontset of FACE if it is ASCII face. */
4143 if (face
->fontset
>= 0 && face
== face
->ascii_face
)
4144 free_face_fontset (f
, face
);
4149 font_done_for_face (f
, face
);
4150 x_free_gc (f
, face
->gc
);
4155 free_face_colors (f
, face
);
4156 x_destroy_bitmap (f
, face
->stipple
);
4158 #endif /* HAVE_WINDOW_SYSTEM */
4165 /* Prepare face FACE for subsequent display on frame F. This
4166 allocated GCs if they haven't been allocated yet or have been freed
4167 by clearing the face cache. */
4170 prepare_face_for_display (struct frame
*f
, struct face
*face
)
4172 #ifdef HAVE_WINDOW_SYSTEM
4173 eassert (FRAME_WINDOW_P (f
));
4178 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
4180 xgcv
.foreground
= face
->foreground
;
4181 xgcv
.background
= face
->background
;
4182 #ifdef HAVE_X_WINDOWS
4183 xgcv
.graphics_exposures
= False
;
4187 #ifdef HAVE_X_WINDOWS
4190 xgcv
.fill_style
= FillOpaqueStippled
;
4191 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
4192 mask
|= GCFillStyle
| GCStipple
;
4195 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
4197 font_prepare_for_face (f
, face
);
4200 #endif /* HAVE_WINDOW_SYSTEM */
4204 /* Returns the `distance' between the colors X and Y. */
4207 color_distance (XColor
*x
, XColor
*y
)
4209 /* This formula is from a paper titled `Colour metric' by Thiadmer Riemersma.
4210 Quoting from that paper:
4212 This formula has results that are very close to L*u*v* (with the
4213 modified lightness curve) and, more importantly, it is a more even
4214 algorithm: it does not have a range of colors where it suddenly
4215 gives far from optimal results.
4217 See <http://www.compuphase.com/cmetric.htm> for more info. */
4219 long r
= (x
->red
- y
->red
) >> 8;
4220 long g
= (x
->green
- y
->green
) >> 8;
4221 long b
= (x
->blue
- y
->blue
) >> 8;
4222 long r_mean
= (x
->red
+ y
->red
) >> 9;
4225 (((512 + r_mean
) * r
* r
) >> 8)
4227 + (((767 - r_mean
) * b
* b
) >> 8);
4231 DEFUN ("color-distance", Fcolor_distance
, Scolor_distance
, 2, 3, 0,
4232 doc
: /* Return an integer distance between COLOR1 and COLOR2 on FRAME.
4233 COLOR1 and COLOR2 may be either strings containing the color name,
4234 or lists of the form (RED GREEN BLUE).
4235 If FRAME is unspecified or nil, the current frame is used. */)
4236 (Lisp_Object color1
, Lisp_Object color2
, Lisp_Object frame
)
4239 XColor cdef1
, cdef2
;
4242 frame
= selected_frame
;
4243 CHECK_LIVE_FRAME (frame
);
4246 if (!(CONSP (color1
) && parse_rgb_list (color1
, &cdef1
))
4247 && !(STRINGP (color1
) && defined_color (f
, SSDATA (color1
), &cdef1
, 0)))
4248 signal_error ("Invalid color", color1
);
4249 if (!(CONSP (color2
) && parse_rgb_list (color2
, &cdef2
))
4250 && !(STRINGP (color2
) && defined_color (f
, SSDATA (color2
), &cdef2
, 0)))
4251 signal_error ("Invalid color", color2
);
4253 return make_number (color_distance (&cdef1
, &cdef2
));
4257 /***********************************************************************
4259 ***********************************************************************/
4261 /* Return a new face cache for frame F. */
4263 static struct face_cache
*
4264 make_face_cache (struct frame
*f
)
4266 struct face_cache
*c
;
4269 c
= xzalloc (sizeof *c
);
4270 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4271 c
->buckets
= xzalloc (size
);
4273 c
->faces_by_id
= xmalloc (c
->size
* sizeof *c
->faces_by_id
);
4275 c
->menu_face_changed_p
= menu_face_changed_default
;
4280 /* Clear out all graphics contexts for all realized faces, except for
4281 the basic faces. This should be done from time to time just to avoid
4282 keeping too many graphics contexts that are no longer needed. */
4285 clear_face_gcs (struct face_cache
*c
)
4287 if (c
&& FRAME_WINDOW_P (c
->f
))
4289 #ifdef HAVE_WINDOW_SYSTEM
4291 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
4293 struct face
*face
= c
->faces_by_id
[i
];
4294 if (face
&& face
->gc
)
4298 font_done_for_face (c
->f
, face
);
4299 x_free_gc (c
->f
, face
->gc
);
4304 #endif /* HAVE_WINDOW_SYSTEM */
4309 /* Free all realized faces in face cache C, including basic faces.
4310 C may be null. If faces are freed, make sure the frame's current
4311 matrix is marked invalid, so that a display caused by an expose
4312 event doesn't try to use faces we destroyed. */
4315 free_realized_faces (struct face_cache
*c
)
4320 struct frame
*f
= c
->f
;
4322 /* We must block input here because we can't process X events
4323 safely while only some faces are freed, or when the frame's
4324 current matrix still references freed faces. */
4327 for (i
= 0; i
< c
->used
; ++i
)
4329 free_realized_face (f
, c
->faces_by_id
[i
]);
4330 c
->faces_by_id
[i
] = NULL
;
4334 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4335 memset (c
->buckets
, 0, size
);
4337 /* Must do a thorough redisplay the next time. Mark current
4338 matrices as invalid because they will reference faces freed
4339 above. This function is also called when a frame is
4340 destroyed. In this case, the root window of F is nil. */
4341 if (WINDOWP (f
->root_window
))
4343 clear_current_matrices (f
);
4344 ++windows_or_buffers_changed
;
4352 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
4353 This is done after attributes of a named face have been changed,
4354 because we can't tell which realized faces depend on that face. */
4357 free_all_realized_faces (Lisp_Object frame
)
4362 FOR_EACH_FRAME (rest
, frame
)
4363 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4366 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4370 /* Free face cache C and faces in it, including their X resources. */
4373 free_face_cache (struct face_cache
*c
)
4377 free_realized_faces (c
);
4379 xfree (c
->faces_by_id
);
4385 /* Cache realized face FACE in face cache C. HASH is the hash value
4386 of FACE. If FACE is for ASCII characters (i.e. FACE->ascii_face ==
4387 FACE), insert the new face to the beginning of the collision list
4388 of the face hash table of C. Otherwise, add the new face to the
4389 end of the collision list. This way, lookup_face can quickly find
4390 that a requested face is not cached. */
4393 cache_face (struct face_cache
*c
, struct face
*face
, unsigned int hash
)
4395 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4399 if (face
->ascii_face
!= face
)
4401 struct face
*last
= c
->buckets
[i
];
4412 c
->buckets
[i
] = face
;
4413 face
->prev
= face
->next
= NULL
;
4419 face
->next
= c
->buckets
[i
];
4421 face
->next
->prev
= face
;
4422 c
->buckets
[i
] = face
;
4425 /* Find a free slot in C->faces_by_id and use the index of the free
4426 slot as FACE->id. */
4427 for (i
= 0; i
< c
->used
; ++i
)
4428 if (c
->faces_by_id
[i
] == NULL
)
4433 /* Check that FACE got a unique id. */
4438 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
4439 for (face1
= c
->buckets
[j
]; face1
; face1
= face1
->next
)
4445 #endif /* GLYPH_DEBUG */
4447 /* Maybe enlarge C->faces_by_id. */
4450 if (c
->used
== c
->size
)
4451 c
->faces_by_id
= xpalloc (c
->faces_by_id
, &c
->size
, 1, MAX_FACE_ID
,
4452 sizeof *c
->faces_by_id
);
4456 c
->faces_by_id
[i
] = face
;
4460 /* Remove face FACE from cache C. */
4463 uncache_face (struct face_cache
*c
, struct face
*face
)
4465 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
4468 face
->prev
->next
= face
->next
;
4470 c
->buckets
[i
] = face
->next
;
4473 face
->next
->prev
= face
->prev
;
4475 c
->faces_by_id
[face
->id
] = NULL
;
4476 if (face
->id
== c
->used
)
4481 /* Look up a realized face with face attributes ATTR in the face cache
4482 of frame F. The face will be used to display ASCII characters.
4483 Value is the ID of the face found. If no suitable face is found,
4484 realize a new one. */
4487 lookup_face (struct frame
*f
, Lisp_Object
*attr
)
4489 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4494 eassert (cache
!= NULL
);
4495 check_lface_attrs (attr
);
4497 /* Look up ATTR in the face cache. */
4498 hash
= lface_hash (attr
);
4499 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4501 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4503 if (face
->ascii_face
!= face
)
4505 /* There's no more ASCII face. */
4509 if (face
->hash
== hash
4510 && lface_equal_p (face
->lface
, attr
))
4514 /* If not found, realize a new face. */
4516 face
= realize_face (cache
, attr
, -1);
4519 eassert (face
== FACE_FROM_ID (f
, face
->id
));
4520 #endif /* GLYPH_DEBUG */
4525 #ifdef HAVE_WINDOW_SYSTEM
4526 /* Look up a realized face that has the same attributes as BASE_FACE
4527 except for the font in the face cache of frame F. If FONT-OBJECT
4528 is not nil, it is an already opened font. If FONT-OBJECT is nil,
4529 the face has no font. Value is the ID of the face found. If no
4530 suitable face is found, realize a new one. */
4533 face_for_font (struct frame
*f
, Lisp_Object font_object
, struct face
*base_face
)
4535 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4540 eassert (cache
!= NULL
);
4541 base_face
= base_face
->ascii_face
;
4542 hash
= lface_hash (base_face
->lface
);
4543 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4545 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4547 if (face
->ascii_face
== face
)
4549 if (face
->ascii_face
== base_face
4550 && face
->font
== (NILP (font_object
) ? NULL
4551 : XFONT_OBJECT (font_object
))
4552 && lface_equal_p (face
->lface
, base_face
->lface
))
4556 /* If not found, realize a new face. */
4557 face
= realize_non_ascii_face (f
, font_object
, base_face
);
4560 #endif /* HAVE_WINDOW_SYSTEM */
4562 /* Return the face id of the realized face for named face SYMBOL on
4563 frame F suitable for displaying ASCII characters. Value is -1 if
4564 the face couldn't be determined, which might happen if the default
4565 face isn't realized and cannot be realized. */
4568 lookup_named_face (struct frame
*f
, Lisp_Object symbol
, int signal_p
)
4570 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4571 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4572 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4574 if (default_face
== NULL
)
4576 if (!realize_basic_faces (f
))
4578 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4579 if (default_face
== NULL
)
4580 abort (); /* realize_basic_faces must have set it up */
4583 if (! get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4586 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4587 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4589 return lookup_face (f
, attrs
);
4593 /* Return the display face-id of the basic face whose canonical face-id
4594 is FACE_ID. The return value will usually simply be FACE_ID, unless that
4595 basic face has bee remapped via Vface_remapping_alist. This function is
4596 conservative: if something goes wrong, it will simply return FACE_ID
4597 rather than signal an error. */
4600 lookup_basic_face (struct frame
*f
, int face_id
)
4602 Lisp_Object name
, mapping
;
4603 int remapped_face_id
;
4605 if (NILP (Vface_remapping_alist
))
4606 return face_id
; /* Nothing to do. */
4610 case DEFAULT_FACE_ID
: name
= Qdefault
; break;
4611 case MODE_LINE_FACE_ID
: name
= Qmode_line
; break;
4612 case MODE_LINE_INACTIVE_FACE_ID
: name
= Qmode_line_inactive
; break;
4613 case HEADER_LINE_FACE_ID
: name
= Qheader_line
; break;
4614 case TOOL_BAR_FACE_ID
: name
= Qtool_bar
; break;
4615 case FRINGE_FACE_ID
: name
= Qfringe
; break;
4616 case SCROLL_BAR_FACE_ID
: name
= Qscroll_bar
; break;
4617 case BORDER_FACE_ID
: name
= Qborder
; break;
4618 case CURSOR_FACE_ID
: name
= Qcursor
; break;
4619 case MOUSE_FACE_ID
: name
= Qmouse
; break;
4620 case MENU_FACE_ID
: name
= Qmenu
; break;
4623 abort (); /* the caller is supposed to pass us a basic face id */
4626 /* Do a quick scan through Vface_remapping_alist, and return immediately
4627 if there is no remapping for face NAME. This is just an optimization
4628 for the very common no-remapping case. */
4629 mapping
= assq_no_quit (name
, Vface_remapping_alist
);
4631 return face_id
; /* Give up. */
4633 /* If there is a remapping entry, lookup the face using NAME, which will
4634 handle the remapping too. */
4635 remapped_face_id
= lookup_named_face (f
, name
, 0);
4636 if (remapped_face_id
< 0)
4637 return face_id
; /* Give up. */
4639 return remapped_face_id
;
4643 /* Return a face for charset ASCII that is like the face with id
4644 FACE_ID on frame F, but has a font that is STEPS steps smaller.
4645 STEPS < 0 means larger. Value is the id of the face. */
4648 smaller_face (struct frame
*f
, int face_id
, int steps
)
4650 #ifdef HAVE_WINDOW_SYSTEM
4652 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4653 int pt
, last_pt
, last_height
;
4656 struct face
*new_face
;
4658 /* If not called for an X frame, just return the original face. */
4659 if (FRAME_TERMCAP_P (f
))
4662 /* Try in increments of 1/2 pt. */
4663 delta
= steps
< 0 ? 5 : -5;
4664 steps
= eabs (steps
);
4666 face
= FACE_FROM_ID (f
, face_id
);
4667 memcpy (attrs
, face
->lface
, sizeof attrs
);
4668 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
4669 new_face_id
= face_id
;
4670 last_height
= FONT_HEIGHT (face
->font
);
4674 /* Give up if we cannot find a font within 10pt. */
4675 && eabs (last_pt
- pt
) < 100)
4677 /* Look up a face for a slightly smaller/larger font. */
4679 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
4680 new_face_id
= lookup_face (f
, attrs
);
4681 new_face
= FACE_FROM_ID (f
, new_face_id
);
4683 /* If height changes, count that as one step. */
4684 if ((delta
< 0 && FONT_HEIGHT (new_face
->font
) < last_height
)
4685 || (delta
> 0 && FONT_HEIGHT (new_face
->font
) > last_height
))
4688 last_height
= FONT_HEIGHT (new_face
->font
);
4695 #else /* not HAVE_WINDOW_SYSTEM */
4699 #endif /* not HAVE_WINDOW_SYSTEM */
4703 /* Return a face for charset ASCII that is like the face with id
4704 FACE_ID on frame F, but has height HEIGHT. */
4707 face_with_height (struct frame
*f
, int face_id
, int height
)
4709 #ifdef HAVE_WINDOW_SYSTEM
4711 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4713 if (FRAME_TERMCAP_P (f
)
4717 face
= FACE_FROM_ID (f
, face_id
);
4718 memcpy (attrs
, face
->lface
, sizeof attrs
);
4719 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
4720 font_clear_prop (attrs
, FONT_SIZE_INDEX
);
4721 face_id
= lookup_face (f
, attrs
);
4722 #endif /* HAVE_WINDOW_SYSTEM */
4728 /* Return the face id of the realized face for named face SYMBOL on
4729 frame F suitable for displaying ASCII characters, and use
4730 attributes of the face FACE_ID for attributes that aren't
4731 completely specified by SYMBOL. This is like lookup_named_face,
4732 except that the default attributes come from FACE_ID, not from the
4733 default face. FACE_ID is assumed to be already realized. */
4736 lookup_derived_face (struct frame
*f
, Lisp_Object symbol
, int face_id
,
4739 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4740 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4741 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
4746 if (!get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4749 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4750 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4751 return lookup_face (f
, attrs
);
4754 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector
,
4755 Sface_attributes_as_vector
, 1, 1, 0,
4756 doc
: /* Return a vector of face attributes corresponding to PLIST. */)
4760 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
4762 merge_face_ref (XFRAME (selected_frame
), plist
, XVECTOR (lface
)->contents
,
4769 /***********************************************************************
4770 Face capability testing
4771 ***********************************************************************/
4774 /* If the distance (as returned by color_distance) between two colors is
4775 less than this, then they are considered the same, for determining
4776 whether a color is supported or not. The range of values is 0-65535. */
4778 #define TTY_SAME_COLOR_THRESHOLD 10000
4780 #ifdef HAVE_WINDOW_SYSTEM
4782 /* Return non-zero if all the face attributes in ATTRS are supported
4783 on the window-system frame F.
4785 The definition of `supported' is somewhat heuristic, but basically means
4786 that a face containing all the attributes in ATTRS, when merged with the
4787 default face for display, can be represented in a way that's
4789 \(1) different in appearance than the default face, and
4790 \(2) `close in spirit' to what the attributes specify, if not exact. */
4793 x_supports_face_attributes_p (struct frame
*f
, Lisp_Object
*attrs
,
4794 struct face
*def_face
)
4796 Lisp_Object
*def_attrs
= def_face
->lface
;
4798 /* Check that other specified attributes are different that the default
4800 if ((!UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
4801 && face_attr_equal_p (attrs
[LFACE_UNDERLINE_INDEX
],
4802 def_attrs
[LFACE_UNDERLINE_INDEX
]))
4803 || (!UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
4804 && face_attr_equal_p (attrs
[LFACE_INVERSE_INDEX
],
4805 def_attrs
[LFACE_INVERSE_INDEX
]))
4806 || (!UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
4807 && face_attr_equal_p (attrs
[LFACE_FOREGROUND_INDEX
],
4808 def_attrs
[LFACE_FOREGROUND_INDEX
]))
4809 || (!UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
4810 && face_attr_equal_p (attrs
[LFACE_BACKGROUND_INDEX
],
4811 def_attrs
[LFACE_BACKGROUND_INDEX
]))
4812 || (!UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
4813 && face_attr_equal_p (attrs
[LFACE_STIPPLE_INDEX
],
4814 def_attrs
[LFACE_STIPPLE_INDEX
]))
4815 || (!UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
4816 && face_attr_equal_p (attrs
[LFACE_OVERLINE_INDEX
],
4817 def_attrs
[LFACE_OVERLINE_INDEX
]))
4818 || (!UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
4819 && face_attr_equal_p (attrs
[LFACE_STRIKE_THROUGH_INDEX
],
4820 def_attrs
[LFACE_STRIKE_THROUGH_INDEX
]))
4821 || (!UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
4822 && face_attr_equal_p (attrs
[LFACE_BOX_INDEX
],
4823 def_attrs
[LFACE_BOX_INDEX
])))
4826 /* Check font-related attributes, as those are the most commonly
4827 "unsupported" on a window-system (because of missing fonts). */
4828 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
4829 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
4830 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
4831 || !UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
4832 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
4833 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
]))
4837 Lisp_Object merged_attrs
[LFACE_VECTOR_SIZE
];
4840 memcpy (merged_attrs
, def_attrs
, sizeof merged_attrs
);
4842 merge_face_vectors (f
, attrs
, merged_attrs
, 0);
4844 face_id
= lookup_face (f
, merged_attrs
);
4845 face
= FACE_FROM_ID (f
, face_id
);
4848 error ("Cannot make face");
4850 /* If the font is the same, or no font is found, then not
4852 if (face
->font
== def_face
->font
4855 for (i
= FONT_TYPE_INDEX
; i
<= FONT_SIZE_INDEX
; i
++)
4856 if (! EQ (face
->font
->props
[i
], def_face
->font
->props
[i
]))
4860 if (i
< FONT_FOUNDRY_INDEX
|| i
> FONT_REGISTRY_INDEX
4861 || face
->font
->driver
->case_sensitive
)
4863 s1
= SYMBOL_NAME (face
->font
->props
[i
]);
4864 s2
= SYMBOL_NAME (def_face
->font
->props
[i
]);
4865 if (! EQ (Fcompare_strings (s1
, make_number (0), Qnil
,
4866 s2
, make_number (0), Qnil
, Qt
), Qt
))
4872 /* Everything checks out, this face is supported. */
4876 #endif /* HAVE_WINDOW_SYSTEM */
4878 /* Return non-zero if all the face attributes in ATTRS are supported
4881 The definition of `supported' is somewhat heuristic, but basically means
4882 that a face containing all the attributes in ATTRS, when merged
4883 with the default face for display, can be represented in a way that's
4885 \(1) different in appearance than the default face, and
4886 \(2) `close in spirit' to what the attributes specify, if not exact.
4888 Point (2) implies that a `:weight black' attribute will be satisfied
4889 by any terminal that can display bold, and a `:foreground "yellow"' as
4890 long as the terminal can display a yellowish color, but `:slant italic'
4891 will _not_ be satisfied by the tty display code's automatic
4892 substitution of a `dim' face for italic. */
4895 tty_supports_face_attributes_p (struct frame
*f
, Lisp_Object
*attrs
,
4896 struct face
*def_face
)
4899 Lisp_Object val
, fg
, bg
;
4900 XColor fg_tty_color
, fg_std_color
;
4901 XColor bg_tty_color
, bg_std_color
;
4902 unsigned test_caps
= 0;
4903 Lisp_Object
*def_attrs
= def_face
->lface
;
4905 /* First check some easy-to-check stuff; ttys support none of the
4906 following attributes, so we can just return false if any are requested
4907 (even if `nominal' values are specified, we should still return false,
4908 as that will be the same value that the default face uses). We
4909 consider :slant unsupportable on ttys, even though the face code
4910 actually `fakes' them using a dim attribute if possible. This is
4911 because the faked result is too different from what the face
4913 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
4914 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
4915 || !UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
4916 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
4917 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
4918 || !UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
4919 || !UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
4920 || !UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
]))
4923 /* Test for terminal `capabilities' (non-color character attributes). */
4925 /* font weight (bold/dim) */
4926 val
= attrs
[LFACE_WEIGHT_INDEX
];
4927 if (!UNSPECIFIEDP (val
)
4928 && (weight
= FONT_WEIGHT_NAME_NUMERIC (val
), weight
>= 0))
4930 int def_weight
= FONT_WEIGHT_NAME_NUMERIC (def_attrs
[LFACE_WEIGHT_INDEX
]);
4934 if (def_weight
> 100)
4935 return 0; /* same as default */
4936 test_caps
= TTY_CAP_BOLD
;
4938 else if (weight
< 100)
4940 if (def_weight
< 100)
4941 return 0; /* same as default */
4942 test_caps
= TTY_CAP_DIM
;
4944 else if (def_weight
== 100)
4945 return 0; /* same as default */
4949 val
= attrs
[LFACE_SLANT_INDEX
];
4950 if (!UNSPECIFIEDP (val
)
4951 && (slant
= FONT_SLANT_NAME_NUMERIC (val
), slant
>= 0))
4953 int def_slant
= FONT_SLANT_NAME_NUMERIC (def_attrs
[LFACE_SLANT_INDEX
]);
4954 if (slant
== 100 || slant
== def_slant
)
4955 return 0; /* same as default */
4957 test_caps
|= TTY_CAP_ITALIC
;
4961 val
= attrs
[LFACE_UNDERLINE_INDEX
];
4962 if (!UNSPECIFIEDP (val
))
4965 return 0; /* ttys can't use colored underlines */
4966 else if (face_attr_equal_p (val
, def_attrs
[LFACE_UNDERLINE_INDEX
]))
4967 return 0; /* same as default */
4969 test_caps
|= TTY_CAP_UNDERLINE
;
4973 val
= attrs
[LFACE_INVERSE_INDEX
];
4974 if (!UNSPECIFIEDP (val
))
4976 if (face_attr_equal_p (val
, def_attrs
[LFACE_INVERSE_INDEX
]))
4977 return 0; /* same as default */
4979 test_caps
|= TTY_CAP_INVERSE
;
4983 /* Color testing. */
4985 /* Default the color indices in FG_TTY_COLOR and BG_TTY_COLOR, since
4986 we use them when calling `tty_capable_p' below, even if the face
4987 specifies no colors. */
4988 fg_tty_color
.pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
4989 bg_tty_color
.pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
4991 /* Check if foreground color is close enough. */
4992 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
4995 Lisp_Object def_fg
= def_attrs
[LFACE_FOREGROUND_INDEX
];
4997 if (face_attr_equal_p (fg
, def_fg
))
4998 return 0; /* same as default */
4999 else if (! tty_lookup_color (f
, fg
, &fg_tty_color
, &fg_std_color
))
5000 return 0; /* not a valid color */
5001 else if (color_distance (&fg_tty_color
, &fg_std_color
)
5002 > TTY_SAME_COLOR_THRESHOLD
)
5003 return 0; /* displayed color is too different */
5005 /* Make sure the color is really different than the default. */
5007 XColor def_fg_color
;
5008 if (tty_lookup_color (f
, def_fg
, &def_fg_color
, 0)
5009 && (color_distance (&fg_tty_color
, &def_fg_color
)
5010 <= TTY_SAME_COLOR_THRESHOLD
))
5015 /* Check if background color is close enough. */
5016 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
5019 Lisp_Object def_bg
= def_attrs
[LFACE_BACKGROUND_INDEX
];
5021 if (face_attr_equal_p (bg
, def_bg
))
5022 return 0; /* same as default */
5023 else if (! tty_lookup_color (f
, bg
, &bg_tty_color
, &bg_std_color
))
5024 return 0; /* not a valid color */
5025 else if (color_distance (&bg_tty_color
, &bg_std_color
)
5026 > TTY_SAME_COLOR_THRESHOLD
)
5027 return 0; /* displayed color is too different */
5029 /* Make sure the color is really different than the default. */
5031 XColor def_bg_color
;
5032 if (tty_lookup_color (f
, def_bg
, &def_bg_color
, 0)
5033 && (color_distance (&bg_tty_color
, &def_bg_color
)
5034 <= TTY_SAME_COLOR_THRESHOLD
))
5039 /* If both foreground and background are requested, see if the
5040 distance between them is OK. We just check to see if the distance
5041 between the tty's foreground and background is close enough to the
5042 distance between the standard foreground and background. */
5043 if (STRINGP (fg
) && STRINGP (bg
))
5046 = (color_distance (&fg_std_color
, &bg_std_color
)
5047 - color_distance (&fg_tty_color
, &bg_tty_color
));
5048 if (delta_delta
> TTY_SAME_COLOR_THRESHOLD
5049 || delta_delta
< -TTY_SAME_COLOR_THRESHOLD
)
5054 /* See if the capabilities we selected above are supported, with the
5056 if (test_caps
!= 0 &&
5057 ! tty_capable_p (FRAME_TTY (f
), test_caps
, fg_tty_color
.pixel
,
5058 bg_tty_color
.pixel
))
5062 /* Hmmm, everything checks out, this terminal must support this face. */
5067 DEFUN ("display-supports-face-attributes-p",
5068 Fdisplay_supports_face_attributes_p
, Sdisplay_supports_face_attributes_p
,
5070 doc
: /* Return non-nil if all the face attributes in ATTRIBUTES are supported.
5071 The optional argument DISPLAY can be a display name, a frame, or
5072 nil (meaning the selected frame's display).
5074 The definition of `supported' is somewhat heuristic, but basically means
5075 that a face containing all the attributes in ATTRIBUTES, when merged
5076 with the default face for display, can be represented in a way that's
5078 \(1) different in appearance than the default face, and
5079 \(2) `close in spirit' to what the attributes specify, if not exact.
5081 Point (2) implies that a `:weight black' attribute will be satisfied by
5082 any display that can display bold, and a `:foreground \"yellow\"' as long
5083 as it can display a yellowish color, but `:slant italic' will _not_ be
5084 satisfied by the tty display code's automatic substitution of a `dim'
5085 face for italic. */)
5086 (Lisp_Object attributes
, Lisp_Object display
)
5088 int supports
= 0, i
;
5091 struct face
*def_face
;
5092 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5094 if (noninteractive
|| !initialized
)
5095 /* We may not be able to access low-level face information in batch
5096 mode, or before being dumped, and this function is not going to
5097 be very useful in those cases anyway, so just give up. */
5101 frame
= selected_frame
;
5102 else if (FRAMEP (display
))
5106 /* Find any frame on DISPLAY. */
5107 Lisp_Object fl_tail
;
5110 for (fl_tail
= Vframe_list
; CONSP (fl_tail
); fl_tail
= XCDR (fl_tail
))
5112 frame
= XCAR (fl_tail
);
5113 if (!NILP (Fequal (Fcdr (Fassq (Qdisplay
,
5114 XFRAME (frame
)->param_alist
)),
5120 CHECK_LIVE_FRAME (frame
);
5123 for (i
= 0; i
< LFACE_VECTOR_SIZE
; i
++)
5124 attrs
[i
] = Qunspecified
;
5125 merge_face_ref (f
, attributes
, attrs
, 1, 0);
5127 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5128 if (def_face
== NULL
)
5130 if (! realize_basic_faces (f
))
5131 error ("Cannot realize default face");
5132 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5133 if (def_face
== NULL
)
5134 abort (); /* realize_basic_faces must have set it up */
5137 /* Dispatch to the appropriate handler. */
5138 if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5139 supports
= tty_supports_face_attributes_p (f
, attrs
, def_face
);
5140 #ifdef HAVE_WINDOW_SYSTEM
5142 supports
= x_supports_face_attributes_p (f
, attrs
, def_face
);
5145 return supports
? Qt
: Qnil
;
5149 /***********************************************************************
5151 ***********************************************************************/
5153 DEFUN ("internal-set-font-selection-order",
5154 Finternal_set_font_selection_order
,
5155 Sinternal_set_font_selection_order
, 1, 1, 0,
5156 doc
: /* Set font selection order for face font selection to ORDER.
5157 ORDER must be a list of length 4 containing the symbols `:width',
5158 `:height', `:weight', and `:slant'. Face attributes appearing
5159 first in ORDER are matched first, e.g. if `:height' appears before
5160 `:weight' in ORDER, font selection first tries to find a font with
5161 a suitable height, and then tries to match the font weight.
5167 int indices
[DIM (font_sort_order
)];
5170 memset (indices
, 0, sizeof indices
);
5174 CONSP (list
) && i
< DIM (indices
);
5175 list
= XCDR (list
), ++i
)
5177 Lisp_Object attr
= XCAR (list
);
5180 if (EQ (attr
, QCwidth
))
5182 else if (EQ (attr
, QCheight
))
5183 xlfd
= XLFD_POINT_SIZE
;
5184 else if (EQ (attr
, QCweight
))
5186 else if (EQ (attr
, QCslant
))
5191 if (indices
[i
] != 0)
5196 if (!NILP (list
) || i
!= DIM (indices
))
5197 signal_error ("Invalid font sort order", order
);
5198 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5199 if (indices
[i
] == 0)
5200 signal_error ("Invalid font sort order", order
);
5202 if (memcmp (indices
, font_sort_order
, sizeof indices
) != 0)
5204 memcpy (font_sort_order
, indices
, sizeof font_sort_order
);
5205 free_all_realized_faces (Qnil
);
5208 font_update_sort_order (font_sort_order
);
5214 DEFUN ("internal-set-alternative-font-family-alist",
5215 Finternal_set_alternative_font_family_alist
,
5216 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
5217 doc
: /* Define alternative font families to try in face font selection.
5218 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5219 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
5220 be found. Value is ALIST. */)
5223 Lisp_Object entry
, tail
, tail2
;
5226 alist
= Fcopy_sequence (alist
);
5227 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5229 entry
= XCAR (tail
);
5231 entry
= Fcopy_sequence (entry
);
5232 XSETCAR (tail
, entry
);
5233 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5234 XSETCAR (tail2
, Fintern (XCAR (tail2
), Qnil
));
5237 Vface_alternative_font_family_alist
= alist
;
5238 free_all_realized_faces (Qnil
);
5243 DEFUN ("internal-set-alternative-font-registry-alist",
5244 Finternal_set_alternative_font_registry_alist
,
5245 Sinternal_set_alternative_font_registry_alist
, 1, 1, 0,
5246 doc
: /* Define alternative font registries to try in face font selection.
5247 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5248 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
5249 be found. Value is ALIST. */)
5252 Lisp_Object entry
, tail
, tail2
;
5255 alist
= Fcopy_sequence (alist
);
5256 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5258 entry
= XCAR (tail
);
5260 entry
= Fcopy_sequence (entry
);
5261 XSETCAR (tail
, entry
);
5262 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5263 XSETCAR (tail2
, Fdowncase (XCAR (tail2
)));
5265 Vface_alternative_font_registry_alist
= alist
;
5266 free_all_realized_faces (Qnil
);
5271 #ifdef HAVE_WINDOW_SYSTEM
5273 /* Return the fontset id of the base fontset name or alias name given
5274 by the fontset attribute of ATTRS. Value is -1 if the fontset
5275 attribute of ATTRS doesn't name a fontset. */
5278 face_fontset (Lisp_Object
*attrs
)
5282 name
= attrs
[LFACE_FONTSET_INDEX
];
5283 if (!STRINGP (name
))
5285 return fs_query_fontset (name
, 0);
5288 #endif /* HAVE_WINDOW_SYSTEM */
5292 /***********************************************************************
5294 ***********************************************************************/
5296 /* Realize basic faces on frame F. Value is zero if frame parameters
5297 of F don't contain enough information needed to realize the default
5301 realize_basic_faces (struct frame
*f
)
5304 ptrdiff_t count
= SPECPDL_INDEX ();
5306 /* Block input here so that we won't be surprised by an X expose
5307 event, for instance, without having the faces set up. */
5309 specbind (Qscalable_fonts_allowed
, Qt
);
5311 if (realize_default_face (f
))
5313 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
5314 realize_named_face (f
, Qmode_line_inactive
, MODE_LINE_INACTIVE_FACE_ID
);
5315 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
5316 realize_named_face (f
, Qfringe
, FRINGE_FACE_ID
);
5317 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
5318 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
5319 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
5320 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
5321 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
5322 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
5323 realize_named_face (f
, Qvertical_border
, VERTICAL_BORDER_FACE_ID
);
5325 /* Reflect changes in the `menu' face in menu bars. */
5326 if (FRAME_FACE_CACHE (f
)->menu_face_changed_p
)
5328 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 0;
5329 #ifdef USE_X_TOOLKIT
5330 if (FRAME_WINDOW_P (f
))
5331 x_update_menu_appearance (f
);
5338 unbind_to (count
, Qnil
);
5344 /* Realize the default face on frame F. If the face is not fully
5345 specified, make it fully-specified. Attributes of the default face
5346 that are not explicitly specified are taken from frame parameters. */
5349 realize_default_face (struct frame
*f
)
5351 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5353 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5356 /* If the `default' face is not yet known, create it. */
5357 lface
= lface_from_face_name (f
, Qdefault
, 0);
5361 XSETFRAME (frame
, f
);
5362 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
5365 #ifdef HAVE_WINDOW_SYSTEM
5366 if (FRAME_WINDOW_P (f
))
5368 Lisp_Object font_object
;
5370 XSETFONT (font_object
, FRAME_FONT (f
));
5371 set_lface_from_font (f
, lface
, font_object
, f
->default_face_done_p
);
5372 LFACE_FONTSET (lface
) = fontset_name (FRAME_FONTSET (f
));
5373 f
->default_face_done_p
= 1;
5375 #endif /* HAVE_WINDOW_SYSTEM */
5377 if (!FRAME_WINDOW_P (f
))
5379 LFACE_FAMILY (lface
) = build_string ("default");
5380 LFACE_FOUNDRY (lface
) = LFACE_FAMILY (lface
);
5381 LFACE_SWIDTH (lface
) = Qnormal
;
5382 LFACE_HEIGHT (lface
) = make_number (1);
5383 if (UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
5384 LFACE_WEIGHT (lface
) = Qnormal
;
5385 if (UNSPECIFIEDP (LFACE_SLANT (lface
)))
5386 LFACE_SLANT (lface
) = Qnormal
;
5387 if (UNSPECIFIEDP (LFACE_FONTSET (lface
)))
5388 LFACE_FONTSET (lface
) = Qnil
;
5391 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
5392 LFACE_UNDERLINE (lface
) = Qnil
;
5394 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
5395 LFACE_OVERLINE (lface
) = Qnil
;
5397 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
5398 LFACE_STRIKE_THROUGH (lface
) = Qnil
;
5400 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
5401 LFACE_BOX (lface
) = Qnil
;
5403 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
5404 LFACE_INVERSE (lface
) = Qnil
;
5406 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
5408 /* This function is called so early that colors are not yet
5409 set in the frame parameter list. */
5410 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
5412 if (CONSP (color
) && STRINGP (XCDR (color
)))
5413 LFACE_FOREGROUND (lface
) = XCDR (color
);
5414 else if (FRAME_WINDOW_P (f
))
5416 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5417 LFACE_FOREGROUND (lface
) = build_string (unspecified_fg
);
5422 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
5424 /* This function is called so early that colors are not yet
5425 set in the frame parameter list. */
5426 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
5427 if (CONSP (color
) && STRINGP (XCDR (color
)))
5428 LFACE_BACKGROUND (lface
) = XCDR (color
);
5429 else if (FRAME_WINDOW_P (f
))
5431 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5432 LFACE_BACKGROUND (lface
) = build_string (unspecified_bg
);
5437 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
5438 LFACE_STIPPLE (lface
) = Qnil
;
5440 /* Realize the face; it must be fully-specified now. */
5441 eassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
5442 check_lface (lface
);
5443 memcpy (attrs
, XVECTOR (lface
)->contents
, sizeof attrs
);
5444 face
= realize_face (c
, attrs
, DEFAULT_FACE_ID
);
5446 #ifdef HAVE_WINDOW_SYSTEM
5447 #ifdef HAVE_X_WINDOWS
5448 if (FRAME_X_P (f
) && face
->font
!= FRAME_FONT (f
))
5450 /* This can happen when making a frame on a display that does
5451 not support the default font. */
5455 /* Otherwise, the font specified for the frame was not
5456 acceptable as a font for the default face (perhaps because
5457 auto-scaled fonts are rejected), so we must adjust the frame
5459 x_set_font (f
, LFACE_FONT (lface
), Qnil
);
5461 #endif /* HAVE_X_WINDOWS */
5462 #endif /* HAVE_WINDOW_SYSTEM */
5467 /* Realize basic faces other than the default face in face cache C.
5468 SYMBOL is the face name, ID is the face id the realized face must
5469 have. The default face must have been realized already. */
5472 realize_named_face (struct frame
*f
, Lisp_Object symbol
, int id
)
5474 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5475 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
5476 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5477 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5479 /* The default face must exist and be fully specified. */
5480 get_lface_attributes_no_remap (f
, Qdefault
, attrs
, 1);
5481 check_lface_attrs (attrs
);
5482 eassert (lface_fully_specified_p (attrs
));
5484 /* If SYMBOL isn't know as a face, create it. */
5488 XSETFRAME (frame
, f
);
5489 lface
= Finternal_make_lisp_face (symbol
, frame
);
5492 /* Merge SYMBOL's face with the default face. */
5493 get_lface_attributes_no_remap (f
, symbol
, symbol_attrs
, 1);
5494 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
5496 /* Realize the face. */
5497 realize_face (c
, attrs
, id
);
5501 /* Realize the fully-specified face with attributes ATTRS in face
5502 cache CACHE for ASCII characters. If FORMER_FACE_ID is
5503 non-negative, it is an ID of face to remove before caching the new
5504 face. Value is a pointer to the newly created realized face. */
5506 static struct face
*
5507 realize_face (struct face_cache
*cache
, Lisp_Object
*attrs
, int former_face_id
)
5511 /* LFACE must be fully specified. */
5512 eassert (cache
!= NULL
);
5513 check_lface_attrs (attrs
);
5515 if (former_face_id
>= 0 && cache
->used
> former_face_id
)
5517 /* Remove the former face. */
5518 struct face
*former_face
= cache
->faces_by_id
[former_face_id
];
5519 uncache_face (cache
, former_face
);
5520 free_realized_face (cache
->f
, former_face
);
5521 SET_FRAME_GARBAGED (cache
->f
);
5524 if (FRAME_WINDOW_P (cache
->f
))
5525 face
= realize_x_face (cache
, attrs
);
5526 else if (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
))
5527 face
= realize_tty_face (cache
, attrs
);
5528 else if (FRAME_INITIAL_P (cache
->f
))
5530 /* Create a dummy face. */
5531 face
= make_realized_face (attrs
);
5536 /* Insert the new face. */
5537 cache_face (cache
, face
, lface_hash (attrs
));
5542 #ifdef HAVE_WINDOW_SYSTEM
5543 /* Realize the fully-specified face that uses FONT-OBJECT and has the
5544 same attributes as BASE_FACE except for the font on frame F.
5545 FONT-OBJECT may be nil, in which case, realized a face of
5548 static struct face
*
5549 realize_non_ascii_face (struct frame
*f
, Lisp_Object font_object
,
5550 struct face
*base_face
)
5552 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5555 face
= xmalloc (sizeof *face
);
5560 = (! NILP (font_object
)
5561 && FONT_WEIGHT_NAME_NUMERIC (face
->lface
[LFACE_WEIGHT_INDEX
]) > 100
5562 && FONT_WEIGHT_NUMERIC (font_object
) <= 100);
5564 /* Don't try to free the colors copied bitwise from BASE_FACE. */
5565 face
->colors_copied_bitwise_p
= 1;
5566 face
->font
= NILP (font_object
) ? NULL
: XFONT_OBJECT (font_object
);
5569 cache_face (cache
, face
, face
->hash
);
5573 #endif /* HAVE_WINDOW_SYSTEM */
5576 /* Realize the fully-specified face with attributes ATTRS in face
5577 cache CACHE for ASCII characters. Do it for X frame CACHE->f. If
5578 the new face doesn't share font with the default face, a fontname
5579 is allocated from the heap and set in `font_name' of the new face,
5580 but it is not yet loaded here. Value is a pointer to the newly
5581 created realized face. */
5583 static struct face
*
5584 realize_x_face (struct face_cache
*cache
, Lisp_Object
*attrs
)
5586 struct face
*face
= NULL
;
5587 #ifdef HAVE_WINDOW_SYSTEM
5588 struct face
*default_face
;
5590 Lisp_Object stipple
, underline
, overline
, strike_through
, box
;
5592 eassert (FRAME_WINDOW_P (cache
->f
));
5594 /* Allocate a new realized face. */
5595 face
= make_realized_face (attrs
);
5596 face
->ascii_face
= face
;
5600 /* Determine the font to use. Most of the time, the font will be
5601 the same as the font of the default face, so try that first. */
5602 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5604 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
5606 face
->font
= default_face
->font
;
5608 = make_fontset_for_ascii_face (f
, default_face
->fontset
, face
);
5612 /* If the face attribute ATTRS specifies a fontset, use it as
5613 the base of a new realized fontset. Otherwise, use the same
5614 base fontset as of the default face. The base determines
5615 registry and encoding of a font. It may also determine
5616 foundry and family. The other fields of font name pattern
5617 are constructed from ATTRS. */
5618 int fontset
= face_fontset (attrs
);
5620 /* If we are realizing the default face, ATTRS should specify a
5621 fontset. In other words, if FONTSET is -1, we are not
5622 realizing the default face, thus the default face should have
5623 already been realized. */
5627 fontset
= default_face
->fontset
;
5631 if (! FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5632 attrs
[LFACE_FONT_INDEX
]
5633 = font_load_for_lface (f
, attrs
, attrs
[LFACE_FONT_INDEX
]);
5634 if (FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5636 face
->font
= XFONT_OBJECT (attrs
[LFACE_FONT_INDEX
]);
5637 face
->fontset
= make_fontset_for_ascii_face (f
, fontset
, face
);
5647 && FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]) > 100
5648 && FONT_WEIGHT_NUMERIC (attrs
[LFACE_FONT_INDEX
]) <= 100)
5649 face
->overstrike
= 1;
5651 /* Load colors, and set remaining attributes. */
5653 load_face_colors (f
, face
, attrs
);
5656 box
= attrs
[LFACE_BOX_INDEX
];
5659 /* A simple box of line width 1 drawn in color given by
5661 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
5663 face
->box
= FACE_SIMPLE_BOX
;
5664 face
->box_line_width
= 1;
5666 else if (INTEGERP (box
))
5668 /* Simple box of specified line width in foreground color of the
5670 eassert (XINT (box
) != 0);
5671 face
->box
= FACE_SIMPLE_BOX
;
5672 face
->box_line_width
= XINT (box
);
5673 face
->box_color
= face
->foreground
;
5674 face
->box_color_defaulted_p
= 1;
5676 else if (CONSP (box
))
5678 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
5679 being one of `raised' or `sunken'. */
5680 face
->box
= FACE_SIMPLE_BOX
;
5681 face
->box_color
= face
->foreground
;
5682 face
->box_color_defaulted_p
= 1;
5683 face
->box_line_width
= 1;
5687 Lisp_Object keyword
, value
;
5689 keyword
= XCAR (box
);
5697 if (EQ (keyword
, QCline_width
))
5699 if (INTEGERP (value
) && XINT (value
) != 0)
5700 face
->box_line_width
= XINT (value
);
5702 else if (EQ (keyword
, QCcolor
))
5704 if (STRINGP (value
))
5706 face
->box_color
= load_color (f
, face
, value
,
5708 face
->use_box_color_for_shadows_p
= 1;
5711 else if (EQ (keyword
, QCstyle
))
5713 if (EQ (value
, Qreleased_button
))
5714 face
->box
= FACE_RAISED_BOX
;
5715 else if (EQ (value
, Qpressed_button
))
5716 face
->box
= FACE_SUNKEN_BOX
;
5721 /* Text underline, overline, strike-through. */
5723 underline
= attrs
[LFACE_UNDERLINE_INDEX
];
5724 if (EQ (underline
, Qt
))
5726 /* Use default color (same as foreground color). */
5727 face
->underline_p
= 1;
5728 face
->underline_type
= FACE_UNDER_LINE
;
5729 face
->underline_defaulted_p
= 1;
5730 face
->underline_color
= 0;
5732 else if (STRINGP (underline
))
5734 /* Use specified color. */
5735 face
->underline_p
= 1;
5736 face
->underline_type
= FACE_UNDER_LINE
;
5737 face
->underline_defaulted_p
= 0;
5738 face
->underline_color
5739 = load_color (f
, face
, underline
,
5740 LFACE_UNDERLINE_INDEX
);
5742 else if (NILP (underline
))
5744 face
->underline_p
= 0;
5745 face
->underline_defaulted_p
= 0;
5746 face
->underline_color
= 0;
5748 else if (CONSP (underline
))
5750 /* `(:color COLOR :style STYLE)'.
5751 STYLE being one of `line' or `wave'. */
5752 face
->underline_p
= 1;
5753 face
->underline_color
= 0;
5754 face
->underline_defaulted_p
= 1;
5755 face
->underline_type
= FACE_UNDER_LINE
;
5757 while (CONSP (underline
))
5759 Lisp_Object keyword
, value
;
5761 keyword
= XCAR (underline
);
5762 underline
= XCDR (underline
);
5764 if (!CONSP (underline
))
5766 value
= XCAR (underline
);
5767 underline
= XCDR (underline
);
5769 if (EQ (keyword
, QCcolor
))
5771 if (EQ (value
, Qforeground_color
))
5773 face
->underline_defaulted_p
= 1;
5774 face
->underline_color
= 0;
5776 else if (STRINGP (value
))
5778 face
->underline_defaulted_p
= 0;
5779 face
->underline_color
= load_color (f
, face
, value
,
5780 LFACE_UNDERLINE_INDEX
);
5783 else if (EQ (keyword
, QCstyle
))
5785 if (EQ (value
, Qline
))
5786 face
->underline_type
= FACE_UNDER_LINE
;
5787 else if (EQ (value
, Qwave
))
5788 face
->underline_type
= FACE_UNDER_WAVE
;
5793 overline
= attrs
[LFACE_OVERLINE_INDEX
];
5794 if (STRINGP (overline
))
5796 face
->overline_color
5797 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
5798 LFACE_OVERLINE_INDEX
);
5799 face
->overline_p
= 1;
5801 else if (EQ (overline
, Qt
))
5803 face
->overline_color
= face
->foreground
;
5804 face
->overline_color_defaulted_p
= 1;
5805 face
->overline_p
= 1;
5808 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
5809 if (STRINGP (strike_through
))
5811 face
->strike_through_color
5812 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
5813 LFACE_STRIKE_THROUGH_INDEX
);
5814 face
->strike_through_p
= 1;
5816 else if (EQ (strike_through
, Qt
))
5818 face
->strike_through_color
= face
->foreground
;
5819 face
->strike_through_color_defaulted_p
= 1;
5820 face
->strike_through_p
= 1;
5823 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
5824 if (!NILP (stipple
))
5825 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
5826 #endif /* HAVE_WINDOW_SYSTEM */
5832 /* Map a specified color of face FACE on frame F to a tty color index.
5833 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
5834 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
5835 default foreground/background colors. */
5838 map_tty_color (struct frame
*f
, struct face
*face
,
5839 enum lface_attribute_index idx
, int *defaulted
)
5841 Lisp_Object frame
, color
, def
;
5842 int foreground_p
= idx
== LFACE_FOREGROUND_INDEX
;
5843 unsigned long default_pixel
=
5844 foreground_p
? FACE_TTY_DEFAULT_FG_COLOR
: FACE_TTY_DEFAULT_BG_COLOR
;
5845 unsigned long pixel
= default_pixel
;
5847 unsigned long default_other_pixel
=
5848 foreground_p
? FACE_TTY_DEFAULT_BG_COLOR
: FACE_TTY_DEFAULT_FG_COLOR
;
5851 eassert (idx
== LFACE_FOREGROUND_INDEX
|| idx
== LFACE_BACKGROUND_INDEX
);
5853 XSETFRAME (frame
, f
);
5854 color
= face
->lface
[idx
];
5858 && CONSP (Vtty_defined_color_alist
)
5859 && (def
= assq_no_quit (color
, call1 (Qtty_color_alist
, frame
)),
5862 /* Associations in tty-defined-color-alist are of the form
5863 (NAME INDEX R G B). We need the INDEX part. */
5864 pixel
= XINT (XCAR (XCDR (def
)));
5867 if (pixel
== default_pixel
&& STRINGP (color
))
5869 pixel
= load_color (f
, face
, color
, idx
);
5872 /* If the foreground of the default face is the default color,
5873 use the foreground color defined by the frame. */
5874 if (FRAME_MSDOS_P (f
))
5876 if (pixel
== default_pixel
5877 || pixel
== FACE_TTY_DEFAULT_COLOR
)
5880 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5882 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5883 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5886 else if (pixel
== default_other_pixel
)
5889 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5891 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5892 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5900 face
->foreground
= pixel
;
5902 face
->background
= pixel
;
5906 /* Realize the fully-specified face with attributes ATTRS in face
5907 cache CACHE for ASCII characters. Do it for TTY frame CACHE->f.
5908 Value is a pointer to the newly created realized face. */
5910 static struct face
*
5911 realize_tty_face (struct face_cache
*cache
, Lisp_Object
*attrs
)
5915 int face_colors_defaulted
= 0;
5916 struct frame
*f
= cache
->f
;
5918 /* Frame must be a termcap frame. */
5919 eassert (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
));
5921 /* Allocate a new realized face. */
5922 face
= make_realized_face (attrs
);
5924 face
->font_name
= FRAME_MSDOS_P (cache
->f
) ? "ms-dos" : "tty";
5927 /* Map face attributes to TTY appearances. */
5928 weight
= FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]);
5929 slant
= FONT_SLANT_NAME_NUMERIC (attrs
[LFACE_SLANT_INDEX
]);
5931 face
->tty_bold_p
= 1;
5933 face
->tty_italic_p
= 1;
5934 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5935 face
->tty_underline_p
= 1;
5936 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
5937 face
->tty_reverse_p
= 1;
5939 /* Map color names to color indices. */
5940 map_tty_color (f
, face
, LFACE_FOREGROUND_INDEX
, &face_colors_defaulted
);
5941 map_tty_color (f
, face
, LFACE_BACKGROUND_INDEX
, &face_colors_defaulted
);
5943 /* Swap colors if face is inverse-video. If the colors are taken
5944 from the frame colors, they are already inverted, since the
5945 frame-creation function calls x-handle-reverse-video. */
5946 if (face
->tty_reverse_p
&& !face_colors_defaulted
)
5948 unsigned long tem
= face
->foreground
;
5949 face
->foreground
= face
->background
;
5950 face
->background
= tem
;
5953 if (tty_suppress_bold_inverse_default_colors_p
5955 && face
->background
== FACE_TTY_DEFAULT_FG_COLOR
5956 && face
->foreground
== FACE_TTY_DEFAULT_BG_COLOR
)
5957 face
->tty_bold_p
= 0;
5963 DEFUN ("tty-suppress-bold-inverse-default-colors",
5964 Ftty_suppress_bold_inverse_default_colors
,
5965 Stty_suppress_bold_inverse_default_colors
, 1, 1, 0,
5966 doc
: /* Suppress/allow boldness of faces with inverse default colors.
5967 SUPPRESS non-nil means suppress it.
5968 This affects bold faces on TTYs whose foreground is the default background
5969 color of the display and whose background is the default foreground color.
5970 For such faces, the bold face attribute is ignored if this variable
5972 (Lisp_Object suppress
)
5974 tty_suppress_bold_inverse_default_colors_p
= !NILP (suppress
);
5975 ++face_change_count
;
5981 /***********************************************************************
5983 ***********************************************************************/
5985 /* Return the ID of the face to use to display character CH with face
5986 property PROP on frame F in current_buffer. */
5989 compute_char_face (struct frame
*f
, int ch
, Lisp_Object prop
)
5993 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
5998 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5999 face_id
= FACE_FOR_CHAR (f
, face
, ch
, -1, Qnil
);
6003 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6004 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6005 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6006 merge_face_ref (f
, prop
, attrs
, 1, 0);
6007 face_id
= lookup_face (f
, attrs
);
6013 /* Return the face ID associated with buffer position POS for
6014 displaying ASCII characters. Return in *ENDPTR the position at
6015 which a different face is needed, as far as text properties and
6016 overlays are concerned. W is a window displaying current_buffer.
6018 REGION_BEG, REGION_END delimit the region, so it can be
6021 LIMIT is a position not to scan beyond. That is to limit the time
6022 this function can take.
6024 If MOUSE is non-zero, use the character's mouse-face, not its face.
6026 BASE_FACE_ID, if non-negative, specifies a base face id to use
6027 instead of DEFAULT_FACE_ID.
6029 The face returned is suitable for displaying ASCII characters. */
6032 face_at_buffer_position (struct window
*w
, ptrdiff_t pos
,
6033 ptrdiff_t region_beg
, ptrdiff_t region_end
,
6034 ptrdiff_t *endptr
, ptrdiff_t limit
,
6035 int mouse
, int base_face_id
)
6037 struct frame
*f
= XFRAME (w
->frame
);
6038 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6039 Lisp_Object prop
, position
;
6040 ptrdiff_t i
, noverlays
;
6041 Lisp_Object
*overlay_vec
;
6044 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
6045 Lisp_Object limit1
, end
;
6046 struct face
*default_face
;
6048 /* W must display the current buffer. We could write this function
6049 to use the frame and buffer of W, but right now it doesn't. */
6050 /* eassert (XBUFFER (w->buffer) == current_buffer); */
6052 XSETFRAME (frame
, f
);
6053 XSETFASTINT (position
, pos
);
6056 if (pos
< region_beg
&& region_beg
< endpos
)
6057 endpos
= region_beg
;
6059 /* Get the `face' or `mouse_face' text property at POS, and
6060 determine the next position at which the property changes. */
6061 prop
= Fget_text_property (position
, propname
, w
->buffer
);
6062 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6063 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
6065 endpos
= XINT (end
);
6067 /* Look at properties from overlays. */
6069 ptrdiff_t next_overlay
;
6071 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, &next_overlay
, 0);
6072 if (next_overlay
< endpos
)
6073 endpos
= next_overlay
;
6081 if (base_face_id
>= 0)
6082 face_id
= base_face_id
;
6083 else if (NILP (Vface_remapping_alist
))
6084 face_id
= DEFAULT_FACE_ID
;
6086 face_id
= lookup_basic_face (f
, DEFAULT_FACE_ID
);
6088 default_face
= FACE_FROM_ID (f
, face_id
);
6091 /* Optimize common cases where we can use the default face. */
6094 && !(pos
>= region_beg
&& pos
< region_end
))
6095 return default_face
->id
;
6097 /* Begin with attributes from the default face. */
6098 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6100 /* Merge in attributes specified via text properties. */
6102 merge_face_ref (f
, prop
, attrs
, 1, 0);
6104 /* Now merge the overlay data. */
6105 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6106 for (i
= 0; i
< noverlays
; i
++)
6111 prop
= Foverlay_get (overlay_vec
[i
], propname
);
6113 merge_face_ref (f
, prop
, attrs
, 1, 0);
6115 oend
= OVERLAY_END (overlay_vec
[i
]);
6116 oendpos
= OVERLAY_POSITION (oend
);
6117 if (oendpos
< endpos
)
6121 /* If in the region, merge in the region face. */
6122 if (pos
>= region_beg
&& pos
< region_end
)
6124 merge_named_face (f
, Qregion
, attrs
, 0);
6126 if (region_end
< endpos
)
6127 endpos
= region_end
;
6132 /* Look up a realized face with the given face attributes,
6133 or realize a new one for ASCII characters. */
6134 return lookup_face (f
, attrs
);
6137 /* Return the face ID at buffer position POS for displaying ASCII
6138 characters associated with overlay strings for overlay OVERLAY.
6140 Like face_at_buffer_position except for OVERLAY. Currently it
6141 simply disregards the `face' properties of all overlays. */
6144 face_for_overlay_string (struct window
*w
, ptrdiff_t pos
,
6145 ptrdiff_t region_beg
, ptrdiff_t region_end
,
6146 ptrdiff_t *endptr
, ptrdiff_t limit
,
6147 int mouse
, Lisp_Object overlay
)
6149 struct frame
*f
= XFRAME (w
->frame
);
6150 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6151 Lisp_Object prop
, position
;
6154 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
6155 Lisp_Object limit1
, end
;
6156 struct face
*default_face
;
6158 /* W must display the current buffer. We could write this function
6159 to use the frame and buffer of W, but right now it doesn't. */
6160 /* eassert (XBUFFER (w->buffer) == current_buffer); */
6162 XSETFRAME (frame
, f
);
6163 XSETFASTINT (position
, pos
);
6166 if (pos
< region_beg
&& region_beg
< endpos
)
6167 endpos
= region_beg
;
6169 /* Get the `face' or `mouse_face' text property at POS, and
6170 determine the next position at which the property changes. */
6171 prop
= Fget_text_property (position
, propname
, w
->buffer
);
6172 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6173 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
6175 endpos
= XINT (end
);
6179 /* Optimize common case where we can use the default face. */
6181 && !(pos
>= region_beg
&& pos
< region_end
)
6182 && NILP (Vface_remapping_alist
))
6183 return DEFAULT_FACE_ID
;
6185 /* Begin with attributes from the default face. */
6186 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
6187 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6189 /* Merge in attributes specified via text properties. */
6191 merge_face_ref (f
, prop
, attrs
, 1, 0);
6193 /* If in the region, merge in the region face. */
6194 if (pos
>= region_beg
&& pos
< region_end
)
6196 merge_named_face (f
, Qregion
, attrs
, 0);
6198 if (region_end
< endpos
)
6199 endpos
= region_end
;
6204 /* Look up a realized face with the given face attributes,
6205 or realize a new one for ASCII characters. */
6206 return lookup_face (f
, attrs
);
6210 /* Compute the face at character position POS in Lisp string STRING on
6211 window W, for ASCII characters.
6213 If STRING is an overlay string, it comes from position BUFPOS in
6214 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
6215 not an overlay string. W must display the current buffer.
6216 REGION_BEG and REGION_END give the start and end positions of the
6217 region; both are -1 if no region is visible.
6219 BASE_FACE_ID is the id of a face to merge with. For strings coming
6220 from overlays or the `display' property it is the face at BUFPOS.
6222 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
6224 Set *ENDPTR to the next position where to check for faces in
6225 STRING; -1 if the face is constant from POS to the end of the
6228 Value is the id of the face to use. The face returned is suitable
6229 for displaying ASCII characters. */
6232 face_at_string_position (struct window
*w
, Lisp_Object string
,
6233 ptrdiff_t pos
, ptrdiff_t bufpos
,
6234 ptrdiff_t region_beg
, ptrdiff_t region_end
,
6235 ptrdiff_t *endptr
, enum face_id base_face_id
,
6238 Lisp_Object prop
, position
, end
, limit
;
6239 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6240 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6241 struct face
*base_face
;
6242 int multibyte_p
= STRING_MULTIBYTE (string
);
6243 Lisp_Object prop_name
= mouse_p
? Qmouse_face
: Qface
;
6245 /* Get the value of the face property at the current position within
6246 STRING. Value is nil if there is no face property. */
6247 XSETFASTINT (position
, pos
);
6248 prop
= Fget_text_property (position
, prop_name
, string
);
6250 /* Get the next position at which to check for faces. Value of end
6251 is nil if face is constant all the way to the end of the string.
6252 Otherwise it is a string position where to check faces next.
6253 Limit is the maximum position up to which to check for property
6254 changes in Fnext_single_property_change. Strings are usually
6255 short, so set the limit to the end of the string. */
6256 XSETFASTINT (limit
, SCHARS (string
));
6257 end
= Fnext_single_property_change (position
, prop_name
, string
, limit
);
6259 *endptr
= XFASTINT (end
);
6263 base_face
= FACE_FROM_ID (f
, base_face_id
);
6264 eassert (base_face
);
6266 /* Optimize the default case that there is no face property and we
6267 are not in the region. */
6269 && (base_face_id
!= DEFAULT_FACE_ID
6270 /* BUFPOS <= 0 means STRING is not an overlay string, so
6271 that the region doesn't have to be taken into account. */
6273 || bufpos
< region_beg
6274 || bufpos
>= region_end
)
6276 /* We can't realize faces for different charsets differently
6277 if we don't have fonts, so we can stop here if not working
6278 on a window-system frame. */
6279 || !FRAME_WINDOW_P (f
)
6280 || FACE_SUITABLE_FOR_ASCII_CHAR_P (base_face
, 0)))
6281 return base_face
->id
;
6283 /* Begin with attributes from the base face. */
6284 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6286 /* Merge in attributes specified via text properties. */
6288 merge_face_ref (f
, prop
, attrs
, 1, 0);
6290 /* If in the region, merge in the region face. */
6292 && bufpos
>= region_beg
6293 && bufpos
< region_end
)
6294 merge_named_face (f
, Qregion
, attrs
, 0);
6296 /* Look up a realized face with the given face attributes,
6297 or realize a new one for ASCII characters. */
6298 return lookup_face (f
, attrs
);
6302 /* Merge a face into a realized face.
6304 F is frame where faces are (to be) realized.
6306 FACE_NAME is named face to merge.
6308 If FACE_NAME is nil, FACE_ID is face_id of realized face to merge.
6310 If FACE_NAME is t, FACE_ID is lface_id of face to merge.
6312 BASE_FACE_ID is realized face to merge into.
6318 merge_faces (struct frame
*f
, Lisp_Object face_name
, int face_id
,
6321 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6322 struct face
*base_face
;
6324 base_face
= FACE_FROM_ID (f
, base_face_id
);
6326 return base_face_id
;
6328 if (EQ (face_name
, Qt
))
6330 if (face_id
< 0 || face_id
>= lface_id_to_name_size
)
6331 return base_face_id
;
6332 face_name
= lface_id_to_name
[face_id
];
6333 /* When called during make-frame, lookup_derived_face may fail
6334 if the faces are uninitialized. Don't signal an error. */
6335 face_id
= lookup_derived_face (f
, face_name
, base_face_id
, 0);
6336 return (face_id
>= 0 ? face_id
: base_face_id
);
6339 /* Begin with attributes from the base face. */
6340 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6342 if (!NILP (face_name
))
6344 if (!merge_named_face (f
, face_name
, attrs
, 0))
6345 return base_face_id
;
6351 return base_face_id
;
6352 face
= FACE_FROM_ID (f
, face_id
);
6354 return base_face_id
;
6355 merge_face_vectors (f
, face
->lface
, attrs
, 0);
6358 /* Look up a realized face with the given face attributes,
6359 or realize a new one for ASCII characters. */
6360 return lookup_face (f
, attrs
);
6365 #ifndef HAVE_X_WINDOWS
6366 DEFUN ("x-load-color-file", Fx_load_color_file
,
6367 Sx_load_color_file
, 1, 1, 0,
6368 doc
: /* Create an alist of color entries from an external file.
6370 The file should define one named RGB color per line like so:
6372 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6373 (Lisp_Object filename
)
6376 Lisp_Object cmap
= Qnil
;
6377 Lisp_Object abspath
;
6379 CHECK_STRING (filename
);
6380 abspath
= Fexpand_file_name (filename
, Qnil
);
6382 fp
= fopen (SSDATA (abspath
), "rt");
6386 int red
, green
, blue
;
6391 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
6392 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
6394 char *name
= buf
+ num
;
6395 num
= strlen (name
) - 1;
6396 if (num
>= 0 && name
[num
] == '\n')
6398 cmap
= Fcons (Fcons (build_string (name
),
6400 make_number (RGB (red
, green
, blue
))),
6402 make_number ((red
<< 16) | (green
<< 8) | blue
)),
6417 /***********************************************************************
6419 ***********************************************************************/
6423 /* Print the contents of the realized face FACE to stderr. */
6426 dump_realized_face (struct face
*face
)
6428 fprintf (stderr
, "ID: %d\n", face
->id
);
6429 #ifdef HAVE_X_WINDOWS
6430 fprintf (stderr
, "gc: %ld\n", (long) face
->gc
);
6432 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
6434 SDATA (face
->lface
[LFACE_FOREGROUND_INDEX
]));
6435 fprintf (stderr
, "background: 0x%lx (%s)\n",
6437 SDATA (face
->lface
[LFACE_BACKGROUND_INDEX
]));
6439 fprintf (stderr
, "font_name: %s (%s)\n",
6440 SDATA (face
->font
->props
[FONT_NAME_INDEX
]),
6441 SDATA (face
->lface
[LFACE_FAMILY_INDEX
]));
6442 #ifdef HAVE_X_WINDOWS
6443 fprintf (stderr
, "font = %p\n", face
->font
);
6445 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
6446 fprintf (stderr
, "underline: %d (%s)\n",
6448 SDATA (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
])));
6449 fprintf (stderr
, "hash: %d\n", face
->hash
);
6453 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, doc
: /* */)
6460 fprintf (stderr
, "font selection order: ");
6461 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6462 fprintf (stderr
, "%d ", font_sort_order
[i
]);
6463 fprintf (stderr
, "\n");
6465 fprintf (stderr
, "alternative fonts: ");
6466 debug_print (Vface_alternative_font_family_alist
);
6467 fprintf (stderr
, "\n");
6469 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
6470 Fdump_face (make_number (i
));
6476 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
6478 error ("Not a valid face");
6479 dump_realized_face (face
);
6486 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
6487 0, 0, 0, doc
: /* */)
6490 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
6491 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
6492 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
6496 #endif /* GLYPH_DEBUG */
6500 /***********************************************************************
6502 ***********************************************************************/
6505 syms_of_xfaces (void)
6507 DEFSYM (Qface
, "face");
6508 DEFSYM (Qface_no_inherit
, "face-no-inherit");
6509 DEFSYM (Qbitmap_spec_p
, "bitmap-spec-p");
6510 DEFSYM (Qframe_set_background_mode
, "frame-set-background-mode");
6512 /* Lisp face attribute keywords. */
6513 DEFSYM (QCfamily
, ":family");
6514 DEFSYM (QCheight
, ":height");
6515 DEFSYM (QCweight
, ":weight");
6516 DEFSYM (QCslant
, ":slant");
6517 DEFSYM (QCunderline
, ":underline");
6518 DEFSYM (QCinverse_video
, ":inverse-video");
6519 DEFSYM (QCreverse_video
, ":reverse-video");
6520 DEFSYM (QCforeground
, ":foreground");
6521 DEFSYM (QCbackground
, ":background");
6522 DEFSYM (QCstipple
, ":stipple");
6523 DEFSYM (QCwidth
, ":width");
6524 DEFSYM (QCfont
, ":font");
6525 DEFSYM (QCfontset
, ":fontset");
6526 DEFSYM (QCbold
, ":bold");
6527 DEFSYM (QCitalic
, ":italic");
6528 DEFSYM (QCoverline
, ":overline");
6529 DEFSYM (QCstrike_through
, ":strike-through");
6530 DEFSYM (QCbox
, ":box");
6531 DEFSYM (QCinherit
, ":inherit");
6533 /* Symbols used for Lisp face attribute values. */
6534 DEFSYM (QCcolor
, ":color");
6535 DEFSYM (QCline_width
, ":line-width");
6536 DEFSYM (QCstyle
, ":style");
6537 DEFSYM (Qline
, "line");
6538 DEFSYM (Qwave
, "wave");
6539 DEFSYM (Qreleased_button
, "released-button");
6540 DEFSYM (Qpressed_button
, "pressed-button");
6541 DEFSYM (Qnormal
, "normal");
6542 DEFSYM (Qultra_light
, "ultra-light");
6543 DEFSYM (Qextra_light
, "extra-light");
6544 DEFSYM (Qlight
, "light");
6545 DEFSYM (Qsemi_light
, "semi-light");
6546 DEFSYM (Qsemi_bold
, "semi-bold");
6547 DEFSYM (Qbold
, "bold");
6548 DEFSYM (Qextra_bold
, "extra-bold");
6549 DEFSYM (Qultra_bold
, "ultra-bold");
6550 DEFSYM (Qoblique
, "oblique");
6551 DEFSYM (Qitalic
, "italic");
6552 DEFSYM (Qreverse_oblique
, "reverse-oblique");
6553 DEFSYM (Qreverse_italic
, "reverse-italic");
6554 DEFSYM (Qultra_condensed
, "ultra-condensed");
6555 DEFSYM (Qextra_condensed
, "extra-condensed");
6556 DEFSYM (Qcondensed
, "condensed");
6557 DEFSYM (Qsemi_condensed
, "semi-condensed");
6558 DEFSYM (Qsemi_expanded
, "semi-expanded");
6559 DEFSYM (Qexpanded
, "expanded");
6560 DEFSYM (Qextra_expanded
, "extra-expanded");
6561 DEFSYM (Qultra_expanded
, "ultra-expanded");
6562 DEFSYM (Qbackground_color
, "background-color");
6563 DEFSYM (Qforeground_color
, "foreground-color");
6564 DEFSYM (Qunspecified
, "unspecified");
6565 DEFSYM (QCignore_defface
, ":ignore-defface");
6567 DEFSYM (Qface_alias
, "face-alias");
6568 DEFSYM (Qdefault
, "default");
6569 DEFSYM (Qtool_bar
, "tool-bar");
6570 DEFSYM (Qregion
, "region");
6571 DEFSYM (Qfringe
, "fringe");
6572 DEFSYM (Qheader_line
, "header-line");
6573 DEFSYM (Qscroll_bar
, "scroll-bar");
6574 DEFSYM (Qmenu
, "menu");
6575 DEFSYM (Qcursor
, "cursor");
6576 DEFSYM (Qborder
, "border");
6577 DEFSYM (Qmouse
, "mouse");
6578 DEFSYM (Qmode_line_inactive
, "mode-line-inactive");
6579 DEFSYM (Qvertical_border
, "vertical-border");
6580 DEFSYM (Qtty_color_desc
, "tty-color-desc");
6581 DEFSYM (Qtty_color_standard_values
, "tty-color-standard-values");
6582 DEFSYM (Qtty_color_by_index
, "tty-color-by-index");
6583 DEFSYM (Qtty_color_alist
, "tty-color-alist");
6584 DEFSYM (Qscalable_fonts_allowed
, "scalable-fonts-allowed");
6586 Vparam_value_alist
= Fcons (Fcons (Qnil
, Qnil
), Qnil
);
6587 staticpro (&Vparam_value_alist
);
6588 Vface_alternative_font_family_alist
= Qnil
;
6589 staticpro (&Vface_alternative_font_family_alist
);
6590 Vface_alternative_font_registry_alist
= Qnil
;
6591 staticpro (&Vface_alternative_font_registry_alist
);
6593 defsubr (&Sinternal_make_lisp_face
);
6594 defsubr (&Sinternal_lisp_face_p
);
6595 defsubr (&Sinternal_set_lisp_face_attribute
);
6596 #ifdef HAVE_WINDOW_SYSTEM
6597 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
6599 defsubr (&Scolor_gray_p
);
6600 defsubr (&Scolor_supported_p
);
6601 #ifndef HAVE_X_WINDOWS
6602 defsubr (&Sx_load_color_file
);
6604 defsubr (&Sface_attribute_relative_p
);
6605 defsubr (&Smerge_face_attribute
);
6606 defsubr (&Sinternal_get_lisp_face_attribute
);
6607 defsubr (&Sinternal_lisp_face_attribute_values
);
6608 defsubr (&Sinternal_lisp_face_equal_p
);
6609 defsubr (&Sinternal_lisp_face_empty_p
);
6610 defsubr (&Sinternal_copy_lisp_face
);
6611 defsubr (&Sinternal_merge_in_global_face
);
6612 defsubr (&Sface_font
);
6613 defsubr (&Sframe_face_alist
);
6614 defsubr (&Sdisplay_supports_face_attributes_p
);
6615 defsubr (&Scolor_distance
);
6616 defsubr (&Sinternal_set_font_selection_order
);
6617 defsubr (&Sinternal_set_alternative_font_family_alist
);
6618 defsubr (&Sinternal_set_alternative_font_registry_alist
);
6619 defsubr (&Sface_attributes_as_vector
);
6621 defsubr (&Sdump_face
);
6622 defsubr (&Sshow_face_resources
);
6623 #endif /* GLYPH_DEBUG */
6624 defsubr (&Sclear_face_cache
);
6625 defsubr (&Stty_suppress_bold_inverse_default_colors
);
6627 #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS
6628 defsubr (&Sdump_colors
);
6631 DEFVAR_LISP ("font-list-limit", Vfont_list_limit
,
6632 doc
: /* Limit for font matching.
6633 If an integer > 0, font matching functions won't load more than
6634 that number of fonts when searching for a matching font. */);
6635 Vfont_list_limit
= make_number (DEFAULT_FONT_LIST_LIMIT
);
6637 DEFVAR_LISP ("face-new-frame-defaults", Vface_new_frame_defaults
,
6638 doc
: /* List of global face definitions (for internal use only.) */);
6639 Vface_new_frame_defaults
= Qnil
;
6641 DEFVAR_LISP ("face-default-stipple", Vface_default_stipple
,
6642 doc
: /* Default stipple pattern used on monochrome displays.
6643 This stipple pattern is used on monochrome displays
6644 instead of shades of gray for a face background color.
6645 See `set-face-stipple' for possible values for this variable. */);
6646 Vface_default_stipple
= build_pure_c_string ("gray3");
6648 DEFVAR_LISP ("tty-defined-color-alist", Vtty_defined_color_alist
,
6649 doc
: /* An alist of defined terminal colors and their RGB values.
6650 See the docstring of `tty-color-alist' for the details. */);
6651 Vtty_defined_color_alist
= Qnil
;
6653 DEFVAR_LISP ("scalable-fonts-allowed", Vscalable_fonts_allowed
,
6654 doc
: /* Allowed scalable fonts.
6655 A value of nil means don't allow any scalable fonts.
6656 A value of t means allow any scalable font.
6657 Otherwise, value must be a list of regular expressions. A font may be
6658 scaled if its name matches a regular expression in the list.
6659 Note that if value is nil, a scalable font might still be used, if no
6660 other font of the appropriate family and registry is available. */);
6661 Vscalable_fonts_allowed
= Qnil
;
6663 DEFVAR_LISP ("face-ignored-fonts", Vface_ignored_fonts
,
6664 doc
: /* List of ignored fonts.
6665 Each element is a regular expression that matches names of fonts to
6667 Vface_ignored_fonts
= Qnil
;
6669 DEFVAR_LISP ("face-remapping-alist", Vface_remapping_alist
,
6670 doc
: /* Alist of face remappings.
6671 Each element is of the form:
6673 (FACE . REPLACEMENT),
6675 which causes display of the face FACE to use REPLACEMENT instead.
6676 REPLACEMENT is a face specification, i.e. one of the following:
6679 (2) a property list of attribute/value pairs, or
6680 (3) a list in which each element has the form of (1) or (2).
6682 List values for REPLACEMENT are merged to form the final face
6683 specification, with earlier entries taking precedence, in the same as
6684 as in the `face' text property.
6686 Face-name remapping cycles are suppressed; recursive references use
6687 the underlying face instead of the remapped face. So a remapping of
6690 (FACE EXTRA-FACE... FACE)
6694 (FACE (FACE-ATTR VAL ...) FACE)
6696 causes EXTRA-FACE... or (FACE-ATTR VAL ...) to be _merged_ with the
6697 existing definition of FACE. Note that this isn't necessary for the
6698 default face, since every face inherits from the default face.
6700 If this variable is made buffer-local, the face remapping takes effect
6701 only in that buffer. For instance, the mode my-mode could define a
6702 face `my-mode-default', and then in the mode setup function, do:
6704 (set (make-local-variable 'face-remapping-alist)
6705 '((default my-mode-default)))).
6707 Because Emacs normally only redraws screen areas when the underlying
6708 buffer contents change, you may need to call `redraw-display' after
6709 changing this variable for it to take effect. */);
6710 Vface_remapping_alist
= Qnil
;
6712 DEFVAR_LISP ("face-font-rescale-alist", Vface_font_rescale_alist
,
6713 doc
: /* Alist of fonts vs the rescaling factors.
6714 Each element is a cons (FONT-PATTERN . RESCALE-RATIO), where
6715 FONT-PATTERN is a font-spec or a regular expression matching a font name, and
6716 RESCALE-RATIO is a floating point number to specify how much larger
6717 \(or smaller) font we should use. For instance, if a face requests
6718 a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point. */);
6719 Vface_font_rescale_alist
= Qnil
;
6721 #ifdef HAVE_WINDOW_SYSTEM
6722 defsubr (&Sbitmap_spec_p
);
6723 defsubr (&Sx_list_fonts
);
6724 defsubr (&Sinternal_face_x_get_resource
);
6725 defsubr (&Sx_family_fonts
);