1 /* xfaces.c -- "Face" primitives.
2 Copyright (C) 1993, 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New face implementation by Gerd Moellmann <gerd@gnu.org>. */
24 When using Emacs with X, the display style of characters can be
25 changed by defining `faces'. Each face can specify the following
30 2. Font foundary name.
32 3. Relative proportionate width, aka character set width or set
33 width (swidth), e.g. `semi-compressed'.
35 4. Font height in 1/10pt.
37 5. Font weight, e.g. `bold'.
39 6. Font slant, e.g. `italic'.
45 9. Whether or not characters should be underlined, and in what color.
47 10. Whether or not characters should be displayed in inverse video.
49 11. A background stipple, a bitmap.
51 12. Whether or not characters should be overlined, and in what color.
53 13. Whether or not characters should be strike-through, and in what
56 14. Whether or not a box should be drawn around characters, the box
57 type, and, for simple boxes, in what color.
59 15. Font-spec, or nil. This is a special attribute.
61 A font-spec is a collection of font attributes (specs).
63 When this attribute is specified, the face uses a font matching
64 with the specs as is except for what overwritten by the specs in
65 the fontset (see below). In addition, the other font-related
66 attributes (1st thru 5th) are updated from the spec.
68 On the other hand, if one of the other font-related attributes are
69 specified, the correspoinding specs in this attribute is set to nil.
71 15. A face name or list of face names from which to inherit attributes.
73 16. A specified average font width, which is invisible from Lisp,
74 and is used to ensure that a font specified on the command line,
75 for example, can be matched exactly.
77 17. A fontset name. This is another special attribute.
79 A fontset is a mappings from characters to font-specs, and the
80 specs overwrite the font-spec in the 14th attribute.
83 Faces are frame-local by nature because Emacs allows to define the
84 same named face (face names are symbols) differently for different
85 frames. Each frame has an alist of face definitions for all named
86 faces. The value of a named face in such an alist is a Lisp vector
87 with the symbol `face' in slot 0, and a slot for each of the face
88 attributes mentioned above.
90 There is also a global face alist `Vface_new_frame_defaults'. Face
91 definitions from this list are used to initialize faces of newly
94 A face doesn't have to specify all attributes. Those not specified
95 have a value of `unspecified'. Faces specifying all attributes but
96 the 14th are called `fully-specified'.
101 The display style of a given character in the text is determined by
102 combining several faces. This process is called `face merging'.
103 Any aspect of the display style that isn't specified by overlays or
104 text properties is taken from the `default' face. Since it is made
105 sure that the default face is always fully-specified, face merging
106 always results in a fully-specified face.
111 After all face attributes for a character have been determined by
112 merging faces of that character, that face is `realized'. The
113 realization process maps face attributes to what is physically
114 available on the system where Emacs runs. The result is a
115 `realized face' in form of a struct face which is stored in the
116 face cache of the frame on which it was realized.
118 Face realization is done in the context of the character to display
119 because different fonts may be used for different characters. In
120 other words, for characters that have different font
121 specifications, different realized faces are needed to display
124 Font specification is done by fontsets. See the comment in
125 fontset.c for the details. In the current implementation, all ASCII
126 characters share the same font in a fontset.
128 Faces are at first realized for ASCII characters, and, at that
129 time, assigned a specific realized fontset. Hereafter, we call
130 such a face as `ASCII face'. When a face for a multibyte character
131 is realized, it inherits (thus shares) a fontset of an ASCII face
132 that has the same attributes other than font-related ones.
134 Thus, all realized faces have a realized fontset.
139 Unibyte text (i.e. raw 8-bit characters) is displayed with the same
140 font as ASCII characters. That is because it is expected that
141 unibyte text users specify a font that is suitable both for ASCII
142 and raw 8-bit characters.
147 Font selection tries to find the best available matching font for a
148 given (character, face) combination.
150 If the face specifies a fontset name, that fontset determines a
151 pattern for fonts of the given character. If the face specifies a
152 font name or the other font-related attributes, a fontset is
153 realized from the default fontset. In that case, that
154 specification determines a pattern for ASCII characters and the
155 default fontset determines a pattern for multibyte characters.
157 Available fonts on the system on which Emacs runs are then matched
158 against the font pattern. The result of font selection is the best
159 match for the given face attributes in this font list.
161 Font selection can be influenced by the user.
163 1. The user can specify the relative importance he gives the face
164 attributes width, height, weight, and slant by setting
165 face-font-selection-order (faces.el) to a list of face attribute
166 names. The default is '(:width :height :weight :slant), and means
167 that font selection first tries to find a good match for the font
168 width specified by a face, then---within fonts with that
169 width---tries to find a best match for the specified font height,
172 2. Setting face-font-family-alternatives allows the user to
173 specify alternative font families to try if a family specified by a
176 3. Setting face-font-registry-alternatives allows the user to
177 specify all alternative font registries to try for a face
178 specifying a registry.
180 4. Setting face-ignored-fonts allows the user to ignore specific
184 Character composition.
186 Usually, the realization process is already finished when Emacs
187 actually reflects the desired glyph matrix on the screen. However,
188 on displaying a composition (sequence of characters to be composed
189 on the screen), a suitable font for the components of the
190 composition is selected and realized while drawing them on the
191 screen, i.e. the realization process is delayed but in principle
195 Initialization of basic faces.
197 The faces `default', `modeline' are considered `basic faces'.
198 When redisplay happens the first time for a newly created frame,
199 basic faces are realized for CHARSET_ASCII. Frame parameters are
200 used to fill in unspecified attributes of the default face. */
204 #include <sys/types.h>
205 #include <sys/stat.h>
206 #include <stdio.h> /* This needs to be before termchar.h */
210 #include "character.h"
212 #include "keyboard.h"
214 #include "termhooks.h"
216 #ifdef HAVE_X_WINDOWS
220 #include <Xm/XmStrDefs.h>
221 #endif /* USE_MOTIF */
222 #endif /* HAVE_X_WINDOWS */
231 /* Redefine X specifics to W32 equivalents to avoid cluttering the
232 code with #ifdef blocks. */
233 #undef FRAME_X_DISPLAY_INFO
234 #define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO
235 #define x_display_info w32_display_info
236 #define FRAME_X_FONT_TABLE FRAME_W32_FONT_TABLE
237 #define check_x check_w32
238 #define GCGraphicsExposures 0
239 #endif /* WINDOWSNT */
243 #undef FRAME_X_DISPLAY_INFO
244 #define FRAME_X_DISPLAY_INFO FRAME_NS_DISPLAY_INFO
245 #define x_display_info ns_display_info
246 #define FRAME_X_FONT_TABLE FRAME_NS_FONT_TABLE
247 #define check_x check_ns
248 #define GCGraphicsExposures 0
252 #include "dispextern.h"
253 #include "blockinput.h"
255 #include "intervals.h"
256 #include "termchar.h"
259 #ifdef HAVE_WINDOW_SYSTEM
261 #endif /* HAVE_WINDOW_SYSTEM */
263 #ifdef HAVE_X_WINDOWS
265 /* Compensate for a bug in Xos.h on some systems, on which it requires
266 time.h. On some such systems, Xos.h tries to redefine struct
267 timeval and struct timezone if USG is #defined while it is
270 #ifdef XOS_NEEDS_TIME_H
276 #else /* not XOS_NEEDS_TIME_H */
278 #endif /* not XOS_NEEDS_TIME_H */
280 #endif /* HAVE_X_WINDOWS */
284 /* Number of pt per inch (from the TeXbook). */
286 #define PT_PER_INCH 72.27
288 /* Non-zero if face attribute ATTR is unspecified. */
290 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified)
292 /* Non-zero if face attribute ATTR is `ignore-defface'. */
294 #define IGNORE_DEFFACE_P(ATTR) EQ ((ATTR), Qignore_defface)
296 /* Value is the number of elements of VECTOR. */
298 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
300 /* Make a copy of string S on the stack using alloca. Value is a pointer
303 #define STRDUPA(S) strcpy ((char *) alloca (strlen ((S)) + 1), (S))
305 /* Make a copy of the contents of Lisp string S on the stack using
306 alloca. Value is a pointer to the copy. */
308 #define LSTRDUPA(S) STRDUPA (SDATA ((S)))
310 /* Size of hash table of realized faces in face caches (should be a
313 #define FACE_CACHE_BUCKETS_SIZE 1001
315 /* Keyword symbols used for face attribute names. */
317 Lisp_Object QCfamily
, QCheight
, QCweight
, QCslant
, QCunderline
;
318 Lisp_Object QCinverse_video
, QCforeground
, QCbackground
, QCstipple
;
319 Lisp_Object QCwidth
, QCfont
, QCbold
, QCitalic
;
320 Lisp_Object QCreverse_video
;
321 Lisp_Object QCoverline
, QCstrike_through
, QCbox
, QCinherit
;
322 Lisp_Object QCfontset
;
324 /* Symbols used for attribute values. */
326 Lisp_Object Qnormal
, Qbold
, Qultra_light
, Qextra_light
, Qlight
;
327 Lisp_Object Qsemi_light
, Qsemi_bold
, Qextra_bold
, Qultra_bold
;
328 Lisp_Object Qoblique
, Qitalic
, Qreverse_oblique
, Qreverse_italic
;
329 Lisp_Object Qultra_condensed
, Qextra_condensed
, Qcondensed
;
330 Lisp_Object Qsemi_condensed
, Qsemi_expanded
, Qexpanded
, Qextra_expanded
;
331 Lisp_Object Qultra_expanded
;
332 Lisp_Object Qreleased_button
, Qpressed_button
;
333 Lisp_Object QCstyle
, QCcolor
, QCline_width
;
334 Lisp_Object Qunspecified
;
335 Lisp_Object Qignore_defface
;
337 char unspecified_fg
[] = "unspecified-fg", unspecified_bg
[] = "unspecified-bg";
339 /* The name of the function to call when the background of the frame
340 has changed, frame_set_background_mode. */
342 Lisp_Object Qframe_set_background_mode
;
344 /* Names of basic faces. */
346 Lisp_Object Qdefault
, Qtool_bar
, Qregion
, Qfringe
;
347 Lisp_Object Qheader_line
, Qscroll_bar
, Qcursor
, Qborder
, Qmouse
, Qmenu
;
348 Lisp_Object Qmode_line_inactive
, Qvertical_border
;
350 /* The symbol `face-alias'. A symbols having that property is an
351 alias for another face. Value of the property is the name of
354 Lisp_Object Qface_alias
;
356 /* Default stipple pattern used on monochrome displays. This stipple
357 pattern is used on monochrome displays instead of shades of gray
358 for a face background color. See `set-face-stipple' for possible
359 values for this variable. */
361 Lisp_Object Vface_default_stipple
;
363 /* Alist of alternative font families. Each element is of the form
364 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
365 try FAMILY1, then FAMILY2, ... */
367 Lisp_Object Vface_alternative_font_family_alist
;
369 /* Alist of alternative font registries. Each element is of the form
370 (REGISTRY REGISTRY1 REGISTRY2...). If fonts of REGISTRY can't be
371 loaded, try REGISTRY1, then REGISTRY2, ... */
373 Lisp_Object Vface_alternative_font_registry_alist
;
375 /* Allowed scalable fonts. A value of nil means don't allow any
376 scalable fonts. A value of t means allow the use of any scalable
377 font. Otherwise, value must be a list of regular expressions. A
378 font may be scaled if its name matches a regular expression in the
381 Lisp_Object Vscalable_fonts_allowed
, Qscalable_fonts_allowed
;
383 /* List of regular expressions that matches names of fonts to ignore. */
385 Lisp_Object Vface_ignored_fonts
;
387 /* Alist of font name patterns vs the rescaling factor. */
389 Lisp_Object Vface_font_rescale_alist
;
391 /* Maximum number of fonts to consider in font_list. If not an
392 integer > 0, DEFAULT_FONT_LIST_LIMIT is used instead. */
394 Lisp_Object Vfont_list_limit
;
395 #define DEFAULT_FONT_LIST_LIMIT 100
397 /* The symbols `foreground-color' and `background-color' which can be
398 used as part of a `face' property. This is for compatibility with
401 Lisp_Object Qforeground_color
, Qbackground_color
;
403 /* The symbols `face' and `mouse-face' used as text properties. */
407 /* Property for basic faces which other faces cannot inherit. */
409 Lisp_Object Qface_no_inherit
;
411 /* Error symbol for wrong_type_argument in load_pixmap. */
413 Lisp_Object Qbitmap_spec_p
;
415 /* Alist of global face definitions. Each element is of the form
416 (FACE . LFACE) where FACE is a symbol naming a face and LFACE
417 is a Lisp vector of face attributes. These faces are used
418 to initialize faces for new frames. */
420 Lisp_Object Vface_new_frame_defaults
;
422 /* Alist of face remappings. Each element is of the form:
423 (FACE REPLACEMENT...) which causes display of the face FACE to use
424 REPLACEMENT... instead. REPLACEMENT... is interpreted the same way
425 the value of a `face' text property is: it may be (1) A face name,
426 (2) A list of face names, (3) A property-list of face attribute/value
427 pairs, or (4) A list of face names intermixed with lists containing
428 face attribute/value pairs.
430 Multiple entries in REPLACEMENT... are merged together to form the final
431 result, with faces or attributes earlier in the list taking precedence
432 over those that are later.
434 Face-name remapping cycles are suppressed; recursive references use
435 the underlying face instead of the remapped face. */
437 Lisp_Object Vface_remapping_alist
;
439 /* The next ID to assign to Lisp faces. */
441 static int next_lface_id
;
443 /* A vector mapping Lisp face Id's to face names. */
445 static Lisp_Object
*lface_id_to_name
;
446 static int lface_id_to_name_size
;
448 /* TTY color-related functions (defined in tty-colors.el). */
450 Lisp_Object Qtty_color_desc
, Qtty_color_by_index
, Qtty_color_standard_values
;
452 /* The name of the function used to compute colors on TTYs. */
454 Lisp_Object Qtty_color_alist
;
456 /* An alist of defined terminal colors and their RGB values. */
458 Lisp_Object Vtty_defined_color_alist
;
460 /* Counter for calls to clear_face_cache. If this counter reaches
461 CLEAR_FONT_TABLE_COUNT, and a frame has more than
462 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
464 static int clear_font_table_count
;
465 #define CLEAR_FONT_TABLE_COUNT 100
466 #define CLEAR_FONT_TABLE_NFONTS 10
468 /* Non-zero means face attributes have been changed since the last
469 redisplay. Used in redisplay_internal. */
471 int face_change_count
;
473 /* Non-zero means don't display bold text if a face's foreground
474 and background colors are the inverse of the default colors of the
475 display. This is a kluge to suppress `bold black' foreground text
476 which is hard to read on an LCD monitor. */
478 int tty_suppress_bold_inverse_default_colors_p
;
480 /* A list of the form `((x . y))' used to avoid consing in
481 Finternal_set_lisp_face_attribute. */
483 static Lisp_Object Vparam_value_alist
;
485 /* The total number of colors currently allocated. */
488 static int ncolors_allocated
;
489 static int npixmaps_allocated
;
493 /* Non-zero means the definition of the `menu' face for new frames has
496 int menu_face_changed_default
;
499 /* Function prototypes. */
502 struct named_merge_point
;
504 static void map_tty_color (struct frame
*, struct face
*,
505 enum lface_attribute_index
, int *);
506 static Lisp_Object
resolve_face_name (Lisp_Object
, int);
507 static void set_font_frame_param (Lisp_Object
, Lisp_Object
);
508 static int get_lface_attributes (struct frame
*, Lisp_Object
, Lisp_Object
*,
509 int, struct named_merge_point
*);
510 static int load_pixmap (struct frame
*, Lisp_Object
, unsigned *, unsigned *);
511 static struct frame
*frame_or_selected_frame (Lisp_Object
, int);
512 static void load_face_colors (struct frame
*, struct face
*, Lisp_Object
*);
513 static void free_face_colors (struct frame
*, struct face
*);
514 static int face_color_gray_p (struct frame
*, const char *);
515 static struct face
*realize_face (struct face_cache
*, Lisp_Object
*,
517 static struct face
*realize_non_ascii_face (struct frame
*, Lisp_Object
,
519 static struct face
*realize_x_face (struct face_cache
*, Lisp_Object
*);
520 static struct face
*realize_tty_face (struct face_cache
*, Lisp_Object
*);
521 static int realize_basic_faces (struct frame
*);
522 static int realize_default_face (struct frame
*);
523 static void realize_named_face (struct frame
*, Lisp_Object
, int);
524 static int lface_fully_specified_p (Lisp_Object
*);
525 static int lface_equal_p (Lisp_Object
*, Lisp_Object
*);
526 static unsigned hash_string_case_insensitive (Lisp_Object
);
527 static unsigned lface_hash (Lisp_Object
*);
528 static int lface_same_font_attributes_p (Lisp_Object
*, Lisp_Object
*);
529 static struct face_cache
*make_face_cache (struct frame
*);
530 static void clear_face_gcs (struct face_cache
*);
531 static void free_face_cache (struct face_cache
*);
532 static int face_fontset (Lisp_Object
*);
533 static void merge_face_vectors (struct frame
*, Lisp_Object
*, Lisp_Object
*,
534 struct named_merge_point
*);
535 static int merge_face_ref (struct frame
*, Lisp_Object
, Lisp_Object
*,
536 int, struct named_merge_point
*);
537 static int set_lface_from_font (struct frame
*, Lisp_Object
, Lisp_Object
,
539 static Lisp_Object
lface_from_face_name (struct frame
*, Lisp_Object
, int);
540 static struct face
*make_realized_face (Lisp_Object
*);
541 static void cache_face (struct face_cache
*, struct face
*, unsigned);
542 static void uncache_face (struct face_cache
*, struct face
*);
544 #ifdef HAVE_WINDOW_SYSTEM
546 static GC
x_create_gc (struct frame
*, unsigned long, XGCValues
*);
547 static void x_free_gc (struct frame
*, GC
);
550 static void x_update_menu_appearance (struct frame
*);
552 extern void free_frame_menubar (struct frame
*);
553 #endif /* USE_X_TOOLKIT */
555 #endif /* HAVE_WINDOW_SYSTEM */
558 /***********************************************************************
560 ***********************************************************************/
562 #ifdef HAVE_X_WINDOWS
564 #ifdef DEBUG_X_COLORS
566 /* The following is a poor mans infrastructure for debugging X color
567 allocation problems on displays with PseudoColor-8. Some X servers
568 like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement
569 color reference counts completely so that they don't signal an
570 error when a color is freed whose reference count is already 0.
571 Other X servers do. To help me debug this, the following code
572 implements a simple reference counting schema of its own, for a
573 single display/screen. --gerd. */
575 /* Reference counts for pixel colors. */
577 int color_count
[256];
579 /* Register color PIXEL as allocated. */
582 register_color (pixel
)
585 xassert (pixel
< 256);
586 ++color_count
[pixel
];
590 /* Register color PIXEL as deallocated. */
593 unregister_color (pixel
)
596 xassert (pixel
< 256);
597 if (color_count
[pixel
] > 0)
598 --color_count
[pixel
];
604 /* Register N colors from PIXELS as deallocated. */
607 unregister_colors (pixels
, n
)
608 unsigned long *pixels
;
612 for (i
= 0; i
< n
; ++i
)
613 unregister_color (pixels
[i
]);
617 DEFUN ("dump-colors", Fdump_colors
, Sdump_colors
, 0, 0, 0,
618 doc
: /* Dump currently allocated colors to stderr. */)
623 fputc ('\n', stderr
);
625 for (i
= n
= 0; i
< sizeof color_count
/ sizeof color_count
[0]; ++i
)
628 fprintf (stderr
, "%3d: %5d", i
, color_count
[i
]);
631 fputc ('\n', stderr
);
633 fputc ('\t', stderr
);
637 fputc ('\n', stderr
);
641 #endif /* DEBUG_X_COLORS */
644 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
645 color values. Interrupt input must be blocked when this function
649 x_free_colors (struct frame
*f
, long unsigned int *pixels
, int npixels
)
651 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
653 /* If display has an immutable color map, freeing colors is not
654 necessary and some servers don't allow it. So don't do it. */
655 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
657 #ifdef DEBUG_X_COLORS
658 unregister_colors (pixels
, npixels
);
660 XFreeColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
666 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
667 color values. Interrupt input must be blocked when this function
671 x_free_dpy_colors (Display
*dpy
, Screen
*screen
, Colormap cmap
, long unsigned int *pixels
, int npixels
)
673 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
674 int class = dpyinfo
->visual
->class;
676 /* If display has an immutable color map, freeing colors is not
677 necessary and some servers don't allow it. So don't do it. */
678 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
680 #ifdef DEBUG_X_COLORS
681 unregister_colors (pixels
, npixels
);
683 XFreeColors (dpy
, cmap
, pixels
, npixels
, 0);
688 /* Create and return a GC for use on frame F. GC values and mask
689 are given by XGCV and MASK. */
692 x_create_gc (struct frame
*f
, long unsigned int mask
, XGCValues
*xgcv
)
696 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
703 /* Free GC which was used on frame F. */
706 x_free_gc (struct frame
*f
, GC gc
)
708 eassert (interrupt_input_blocked
);
709 IF_DEBUG (xassert (--ngcs
>= 0));
710 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
713 #endif /* HAVE_X_WINDOWS */
716 /* W32 emulation of GCs */
719 x_create_gc (struct frame
*f
, unsigned long mask
, XGCValues
*xgcv
)
723 gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, xgcv
);
730 /* Free GC which was used on frame F. */
733 x_free_gc (struct frame
*f
, GC gc
)
735 IF_DEBUG (xassert (--ngcs
>= 0));
739 #endif /* WINDOWSNT */
742 /* NS emulation of GCs */
745 x_create_gc (f
, mask
, xgcv
)
750 GC gc
= xmalloc (sizeof (*gc
));
752 memcpy (gc
, xgcv
, sizeof (XGCValues
));
765 /* Like strcasecmp/stricmp. Used to compare parts of font names which
769 xstrcasecmp (const unsigned char *s1
, const unsigned char *s2
)
773 unsigned char c1
= tolower (*s1
);
774 unsigned char c2
= tolower (*s2
);
776 return c1
< c2
? -1 : 1;
781 return *s2
== 0 ? 0 : -1;
786 /* If FRAME is nil, return a pointer to the selected frame.
787 Otherwise, check that FRAME is a live frame, and return a pointer
788 to it. NPARAM is the parameter number of FRAME, for
789 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
790 Lisp function definitions. */
792 static INLINE
struct frame
*
793 frame_or_selected_frame (Lisp_Object frame
, int nparam
)
796 frame
= selected_frame
;
798 CHECK_LIVE_FRAME (frame
);
799 return XFRAME (frame
);
803 /***********************************************************************
805 ***********************************************************************/
807 /* Initialize face cache and basic faces for frame F. */
810 init_frame_faces (struct frame
*f
)
812 /* Make a face cache, if F doesn't have one. */
813 if (FRAME_FACE_CACHE (f
) == NULL
)
814 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
816 #ifdef HAVE_WINDOW_SYSTEM
817 /* Make the image cache. */
818 if (FRAME_WINDOW_P (f
))
820 /* We initialize the image cache when creating the first frame
821 on a terminal, and not during terminal creation. This way,
822 `x-open-connection' on a tty won't create an image cache. */
823 if (FRAME_IMAGE_CACHE (f
) == NULL
)
824 FRAME_IMAGE_CACHE (f
) = make_image_cache ();
825 ++FRAME_IMAGE_CACHE (f
)->refcount
;
827 #endif /* HAVE_WINDOW_SYSTEM */
829 /* Realize basic faces. Must have enough information in frame
830 parameters to realize basic faces at this point. */
831 #ifdef HAVE_X_WINDOWS
832 if (!FRAME_X_P (f
) || FRAME_X_WINDOW (f
))
835 if (!FRAME_WINDOW_P (f
) || FRAME_W32_WINDOW (f
))
838 if (!FRAME_NS_P (f
) || FRAME_NS_WINDOW (f
))
840 if (!realize_basic_faces (f
))
845 /* Free face cache of frame F. Called from delete_frame. */
848 free_frame_faces (struct frame
*f
)
850 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
854 free_face_cache (face_cache
);
855 FRAME_FACE_CACHE (f
) = NULL
;
858 #ifdef HAVE_WINDOW_SYSTEM
859 if (FRAME_WINDOW_P (f
))
861 struct image_cache
*image_cache
= FRAME_IMAGE_CACHE (f
);
864 --image_cache
->refcount
;
865 if (image_cache
->refcount
== 0)
866 free_image_cache (f
);
869 #endif /* HAVE_WINDOW_SYSTEM */
873 /* Clear face caches, and recompute basic faces for frame F. Call
874 this after changing frame parameters on which those faces depend,
875 or when realized faces have been freed due to changing attributes
879 recompute_basic_faces (struct frame
*f
)
881 if (FRAME_FACE_CACHE (f
))
883 clear_face_cache (0);
884 if (!realize_basic_faces (f
))
890 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
891 try to free unused fonts, too. */
894 clear_face_cache (int clear_fonts_p
)
896 #ifdef HAVE_WINDOW_SYSTEM
897 Lisp_Object tail
, frame
;
901 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
904 /* Not yet implemented. */
905 clear_font_cache (frame
);
908 /* From time to time see if we can unload some fonts. This also
909 frees all realized faces on all frames. Fonts needed by
910 faces will be loaded again when faces are realized again. */
911 clear_font_table_count
= 0;
913 FOR_EACH_FRAME (tail
, frame
)
915 struct frame
*f
= XFRAME (frame
);
916 if (FRAME_WINDOW_P (f
)
917 && FRAME_X_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
918 free_all_realized_faces (frame
);
923 /* Clear GCs of realized faces. */
924 FOR_EACH_FRAME (tail
, frame
)
927 if (FRAME_WINDOW_P (f
))
928 clear_face_gcs (FRAME_FACE_CACHE (f
));
930 clear_image_caches (Qnil
);
932 #endif /* HAVE_WINDOW_SYSTEM */
936 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
937 doc
: /* Clear face caches on all frames.
938 Optional THOROUGHLY non-nil means try to free unused fonts, too. */)
939 (Lisp_Object thoroughly
)
941 clear_face_cache (!NILP (thoroughly
));
943 ++windows_or_buffers_changed
;
948 /***********************************************************************
950 ***********************************************************************/
952 #ifdef HAVE_WINDOW_SYSTEM
954 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
955 doc
: /* Value is non-nil if OBJECT is a valid bitmap specification.
956 A bitmap specification is either a string, a file name, or a list
957 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
958 HEIGHT is its height, and DATA is a string containing the bits of
959 the pixmap. Bits are stored row by row, each row occupies
960 \(WIDTH + 7)/8 bytes. */)
965 if (STRINGP (object
))
966 /* If OBJECT is a string, it's a file name. */
968 else if (CONSP (object
))
970 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
971 HEIGHT must be integers > 0, and DATA must be string large
972 enough to hold a bitmap of the specified size. */
973 Lisp_Object width
, height
, data
;
975 height
= width
= data
= Qnil
;
979 width
= XCAR (object
);
980 object
= XCDR (object
);
983 height
= XCAR (object
);
984 object
= XCDR (object
);
986 data
= XCAR (object
);
990 if (NATNUMP (width
) && NATNUMP (height
) && STRINGP (data
))
992 int bytes_per_row
= ((XFASTINT (width
) + BITS_PER_CHAR
- 1)
994 if (SBYTES (data
) >= bytes_per_row
* XINT (height
))
999 return pixmap_p
? Qt
: Qnil
;
1003 /* Load a bitmap according to NAME (which is either a file name or a
1004 pixmap spec) for use on frame F. Value is the bitmap_id (see
1005 xfns.c). If NAME is nil, return with a bitmap id of zero. If
1006 bitmap cannot be loaded, display a message saying so, and return
1007 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
1008 if these pointers are not null. */
1011 load_pixmap (FRAME_PTR f
, Lisp_Object name
, unsigned int *w_ptr
, unsigned int *h_ptr
)
1018 CHECK_TYPE (!NILP (Fbitmap_spec_p (name
)), Qbitmap_spec_p
, name
);
1023 /* Decode a bitmap spec into a bitmap. */
1028 w
= XINT (Fcar (name
));
1029 h
= XINT (Fcar (Fcdr (name
)));
1030 bits
= Fcar (Fcdr (Fcdr (name
)));
1032 bitmap_id
= x_create_bitmap_from_data (f
, SDATA (bits
),
1037 /* It must be a string -- a file name. */
1038 bitmap_id
= x_create_bitmap_from_file (f
, name
);
1044 add_to_log ("Invalid or undefined bitmap `%s'", name
, Qnil
);
1055 ++npixmaps_allocated
;
1058 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
1061 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
1067 #endif /* HAVE_WINDOW_SYSTEM */
1071 /***********************************************************************
1073 ***********************************************************************/
1075 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
1076 RGB_LIST should contain (at least) 3 lisp integers.
1077 Return 0 if there's a problem with RGB_LIST, otherwise return 1. */
1080 parse_rgb_list (Lisp_Object rgb_list
, XColor
*color
)
1082 #define PARSE_RGB_LIST_FIELD(field) \
1083 if (CONSP (rgb_list) && INTEGERP (XCAR (rgb_list))) \
1085 color->field = XINT (XCAR (rgb_list)); \
1086 rgb_list = XCDR (rgb_list); \
1091 PARSE_RGB_LIST_FIELD (red
);
1092 PARSE_RGB_LIST_FIELD (green
);
1093 PARSE_RGB_LIST_FIELD (blue
);
1099 /* Lookup on frame F the color described by the lisp string COLOR.
1100 The resulting tty color is returned in TTY_COLOR; if STD_COLOR is
1101 non-zero, then the `standard' definition of the same color is
1105 tty_lookup_color (struct frame
*f
, Lisp_Object color
, XColor
*tty_color
, XColor
*std_color
)
1107 Lisp_Object frame
, color_desc
;
1109 if (!STRINGP (color
) || NILP (Ffboundp (Qtty_color_desc
)))
1112 XSETFRAME (frame
, f
);
1114 color_desc
= call2 (Qtty_color_desc
, color
, frame
);
1115 if (CONSP (color_desc
) && CONSP (XCDR (color_desc
)))
1119 if (! INTEGERP (XCAR (XCDR (color_desc
))))
1122 tty_color
->pixel
= XINT (XCAR (XCDR (color_desc
)));
1124 rgb
= XCDR (XCDR (color_desc
));
1125 if (! parse_rgb_list (rgb
, tty_color
))
1128 /* Should we fill in STD_COLOR too? */
1131 /* Default STD_COLOR to the same as TTY_COLOR. */
1132 *std_color
= *tty_color
;
1134 /* Do a quick check to see if the returned descriptor is
1135 actually _exactly_ equal to COLOR, otherwise we have to
1136 lookup STD_COLOR separately. If it's impossible to lookup
1137 a standard color, we just give up and use TTY_COLOR. */
1138 if ((!STRINGP (XCAR (color_desc
))
1139 || NILP (Fstring_equal (color
, XCAR (color_desc
))))
1140 && !NILP (Ffboundp (Qtty_color_standard_values
)))
1142 /* Look up STD_COLOR separately. */
1143 rgb
= call1 (Qtty_color_standard_values
, color
);
1144 if (! parse_rgb_list (rgb
, std_color
))
1151 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
1152 /* We were called early during startup, and the colors are not
1153 yet set up in tty-defined-color-alist. Don't return a failure
1154 indication, since this produces the annoying "Unable to
1155 load color" messages in the *Messages* buffer. */
1158 /* tty-color-desc seems to have returned a bad value. */
1162 /* A version of defined_color for non-X frames. */
1165 tty_defined_color (struct frame
*f
, const char *color_name
,
1166 XColor
*color_def
, int alloc
)
1171 color_def
->pixel
= FACE_TTY_DEFAULT_COLOR
;
1173 color_def
->blue
= 0;
1174 color_def
->green
= 0;
1177 status
= tty_lookup_color (f
, build_string (color_name
), color_def
, NULL
);
1179 if (color_def
->pixel
== FACE_TTY_DEFAULT_COLOR
&& *color_name
)
1181 if (strcmp (color_name
, "unspecified-fg") == 0)
1182 color_def
->pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
1183 else if (strcmp (color_name
, "unspecified-bg") == 0)
1184 color_def
->pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
1187 if (color_def
->pixel
!= FACE_TTY_DEFAULT_COLOR
)
1194 /* Decide if color named COLOR_NAME is valid for the display
1195 associated with the frame F; if so, return the rgb values in
1196 COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell.
1198 This does the right thing for any type of frame. */
1201 defined_color (struct frame
*f
, const char *color_name
, XColor
*color_def
, int alloc
)
1203 if (!FRAME_WINDOW_P (f
))
1204 return tty_defined_color (f
, color_name
, color_def
, alloc
);
1205 #ifdef HAVE_X_WINDOWS
1206 else if (FRAME_X_P (f
))
1207 return x_defined_color (f
, color_name
, color_def
, alloc
);
1210 else if (FRAME_W32_P (f
))
1211 return w32_defined_color (f
, color_name
, color_def
, alloc
);
1214 else if (FRAME_NS_P (f
))
1215 return ns_defined_color (f
, color_name
, color_def
, alloc
, 1);
1222 /* Given the index IDX of a tty color on frame F, return its name, a
1226 tty_color_name (struct frame
*f
, int idx
)
1228 if (idx
>= 0 && !NILP (Ffboundp (Qtty_color_by_index
)))
1231 Lisp_Object coldesc
;
1233 XSETFRAME (frame
, f
);
1234 coldesc
= call2 (Qtty_color_by_index
, make_number (idx
), frame
);
1236 if (!NILP (coldesc
))
1237 return XCAR (coldesc
);
1240 /* We can have an MSDOG frame under -nw for a short window of
1241 opportunity before internal_terminal_init is called. DTRT. */
1242 if (FRAME_MSDOS_P (f
) && !inhibit_window_system
)
1243 return msdos_stdcolor_name (idx
);
1246 if (idx
== FACE_TTY_DEFAULT_FG_COLOR
)
1247 return build_string (unspecified_fg
);
1248 if (idx
== FACE_TTY_DEFAULT_BG_COLOR
)
1249 return build_string (unspecified_bg
);
1251 return Qunspecified
;
1255 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1258 The criterion implemented here is not a terribly sophisticated one. */
1261 face_color_gray_p (struct frame
*f
, const char *color_name
)
1266 if (defined_color (f
, color_name
, &color
, 0))
1267 gray_p
= (/* Any color sufficiently close to black counts as grey. */
1268 (color
.red
< 5000 && color
.green
< 5000 && color
.blue
< 5000)
1270 ((eabs (color
.red
- color
.green
)
1271 < max (color
.red
, color
.green
) / 20)
1272 && (eabs (color
.green
- color
.blue
)
1273 < max (color
.green
, color
.blue
) / 20)
1274 && (eabs (color
.blue
- color
.red
)
1275 < max (color
.blue
, color
.red
) / 20)));
1283 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1284 BACKGROUND_P non-zero means the color will be used as background
1288 face_color_supported_p (struct frame
*f
, const char *color_name
, int background_p
)
1293 XSETFRAME (frame
, f
);
1295 #ifdef HAVE_WINDOW_SYSTEM
1297 ? (!NILP (Fxw_display_color_p (frame
))
1298 || xstrcasecmp (color_name
, "black") == 0
1299 || xstrcasecmp (color_name
, "white") == 0
1301 && face_color_gray_p (f
, color_name
))
1302 || (!NILP (Fx_display_grayscale_p (frame
))
1303 && face_color_gray_p (f
, color_name
)))
1306 tty_defined_color (f
, color_name
, ¬_used
, 0);
1310 DEFUN ("color-gray-p", Fcolor_gray_p
, Scolor_gray_p
, 1, 2, 0,
1311 doc
: /* Return non-nil if COLOR is a shade of gray (or white or black).
1312 FRAME specifies the frame and thus the display for interpreting COLOR.
1313 If FRAME is nil or omitted, use the selected frame. */)
1314 (Lisp_Object color
, Lisp_Object frame
)
1318 CHECK_STRING (color
);
1320 frame
= selected_frame
;
1322 CHECK_FRAME (frame
);
1324 return face_color_gray_p (f
, SDATA (color
)) ? Qt
: Qnil
;
1328 DEFUN ("color-supported-p", Fcolor_supported_p
,
1329 Scolor_supported_p
, 1, 3, 0,
1330 doc
: /* Return non-nil if COLOR can be displayed on FRAME.
1331 BACKGROUND-P non-nil means COLOR is used as a background.
1332 Otherwise, this function tells whether it can be used as a foreground.
1333 If FRAME is nil or omitted, use the selected frame.
1334 COLOR must be a valid color name. */)
1335 (Lisp_Object color
, Lisp_Object frame
, Lisp_Object background_p
)
1339 CHECK_STRING (color
);
1341 frame
= selected_frame
;
1343 CHECK_FRAME (frame
);
1345 if (face_color_supported_p (f
, SDATA (color
), !NILP (background_p
)))
1351 /* Load color with name NAME for use by face FACE on frame F.
1352 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1353 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1354 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1355 pixel color. If color cannot be loaded, display a message, and
1356 return the foreground, background or underline color of F, but
1357 record that fact in flags of the face so that we don't try to free
1361 load_color (struct frame
*f
, struct face
*face
, Lisp_Object name
, enum lface_attribute_index target_index
)
1365 xassert (STRINGP (name
));
1366 xassert (target_index
== LFACE_FOREGROUND_INDEX
1367 || target_index
== LFACE_BACKGROUND_INDEX
1368 || target_index
== LFACE_UNDERLINE_INDEX
1369 || target_index
== LFACE_OVERLINE_INDEX
1370 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1371 || target_index
== LFACE_BOX_INDEX
);
1373 /* if the color map is full, defined_color will return a best match
1374 to the values in an existing cell. */
1375 if (!defined_color (f
, SDATA (name
), &color
, 1))
1377 add_to_log ("Unable to load color \"%s\"", name
, Qnil
);
1379 switch (target_index
)
1381 case LFACE_FOREGROUND_INDEX
:
1382 face
->foreground_defaulted_p
= 1;
1383 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1386 case LFACE_BACKGROUND_INDEX
:
1387 face
->background_defaulted_p
= 1;
1388 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1391 case LFACE_UNDERLINE_INDEX
:
1392 face
->underline_defaulted_p
= 1;
1393 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1396 case LFACE_OVERLINE_INDEX
:
1397 face
->overline_color_defaulted_p
= 1;
1398 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1401 case LFACE_STRIKE_THROUGH_INDEX
:
1402 face
->strike_through_color_defaulted_p
= 1;
1403 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1406 case LFACE_BOX_INDEX
:
1407 face
->box_color_defaulted_p
= 1;
1408 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1417 ++ncolors_allocated
;
1424 #ifdef HAVE_WINDOW_SYSTEM
1426 /* Load colors for face FACE which is used on frame F. Colors are
1427 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1428 of ATTRS. If the background color specified is not supported on F,
1429 try to emulate gray colors with a stipple from Vface_default_stipple. */
1432 load_face_colors (struct frame
*f
, struct face
*face
, Lisp_Object
*attrs
)
1436 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1437 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1439 /* Swap colors if face is inverse-video. */
1440 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1448 /* Check for support for foreground, not for background because
1449 face_color_supported_p is smart enough to know that grays are
1450 "supported" as background because we are supposed to use stipple
1452 if (!face_color_supported_p (f
, SDATA (bg
), 0)
1453 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1455 x_destroy_bitmap (f
, face
->stipple
);
1456 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1457 &face
->pixmap_w
, &face
->pixmap_h
);
1460 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1461 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1465 /* Free color PIXEL on frame F. */
1468 unload_color (struct frame
*f
, long unsigned int pixel
)
1470 #ifdef HAVE_X_WINDOWS
1474 x_free_colors (f
, &pixel
, 1);
1481 /* Free colors allocated for FACE. */
1484 free_face_colors (struct frame
*f
, struct face
*face
)
1486 /* PENDING(NS): need to do something here? */
1487 #ifdef HAVE_X_WINDOWS
1488 if (face
->colors_copied_bitwise_p
)
1493 if (!face
->foreground_defaulted_p
)
1495 x_free_colors (f
, &face
->foreground
, 1);
1496 IF_DEBUG (--ncolors_allocated
);
1499 if (!face
->background_defaulted_p
)
1501 x_free_colors (f
, &face
->background
, 1);
1502 IF_DEBUG (--ncolors_allocated
);
1505 if (face
->underline_p
1506 && !face
->underline_defaulted_p
)
1508 x_free_colors (f
, &face
->underline_color
, 1);
1509 IF_DEBUG (--ncolors_allocated
);
1512 if (face
->overline_p
1513 && !face
->overline_color_defaulted_p
)
1515 x_free_colors (f
, &face
->overline_color
, 1);
1516 IF_DEBUG (--ncolors_allocated
);
1519 if (face
->strike_through_p
1520 && !face
->strike_through_color_defaulted_p
)
1522 x_free_colors (f
, &face
->strike_through_color
, 1);
1523 IF_DEBUG (--ncolors_allocated
);
1526 if (face
->box
!= FACE_NO_BOX
1527 && !face
->box_color_defaulted_p
)
1529 x_free_colors (f
, &face
->box_color
, 1);
1530 IF_DEBUG (--ncolors_allocated
);
1534 #endif /* HAVE_X_WINDOWS */
1537 #endif /* HAVE_WINDOW_SYSTEM */
1541 /***********************************************************************
1543 ***********************************************************************/
1545 /* An enumerator for each field of an XLFD font name. */
1566 /* An enumerator for each possible slant value of a font. Taken from
1567 the XLFD specification. */
1575 XLFD_SLANT_REVERSE_ITALIC
,
1576 XLFD_SLANT_REVERSE_OBLIQUE
,
1580 /* Relative font weight according to XLFD documentation. */
1584 XLFD_WEIGHT_UNKNOWN
,
1585 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1586 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1587 XLFD_WEIGHT_LIGHT
, /* 30 */
1588 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1589 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1590 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1591 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1592 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1593 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1596 /* Relative proportionate width. */
1600 XLFD_SWIDTH_UNKNOWN
,
1601 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1602 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1603 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1604 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1605 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1606 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1607 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1608 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1609 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1612 /* Order by which font selection chooses fonts. The default values
1613 mean `first, find a best match for the font width, then for the
1614 font height, then for weight, then for slant.' This variable can be
1615 set via set-face-font-sort-order. */
1617 static int font_sort_order
[4];
1619 #ifdef HAVE_WINDOW_SYSTEM
1621 static enum font_property_index font_props_for_sorting
[FONT_SIZE_INDEX
];
1624 compare_fonts_by_sort_order (const void *v1
, const void *v2
)
1626 Lisp_Object font1
= *(Lisp_Object
*) v1
;
1627 Lisp_Object font2
= *(Lisp_Object
*) v2
;
1630 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1632 enum font_property_index idx
= font_props_for_sorting
[i
];
1633 Lisp_Object val1
= AREF (font1
, idx
), val2
= AREF (font2
, idx
);
1636 if (idx
<= FONT_REGISTRY_INDEX
)
1639 result
= STRINGP (val2
) ? strcmp (SDATA (val1
), SDATA (val2
)) : -1;
1641 result
= STRINGP (val2
) ? 1 : 0;
1645 if (INTEGERP (val1
))
1646 result
= INTEGERP (val2
) ? XINT (val1
) - XINT (val2
) : -1;
1648 result
= INTEGERP (val2
) ? 1 : 0;
1656 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
1657 doc
: /* Return a list of available fonts of family FAMILY on FRAME.
1658 If FAMILY is omitted or nil, list all families.
1659 Otherwise, FAMILY must be a string, possibly containing wildcards
1661 If FRAME is omitted or nil, use the selected frame.
1662 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
1663 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
1664 FAMILY is the font family name. POINT-SIZE is the size of the
1665 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
1666 width, weight and slant of the font. These symbols are the same as for
1667 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
1668 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
1669 giving the registry and encoding of the font.
1670 The result list is sorted according to the current setting of
1671 the face font sort order. */)
1672 (Lisp_Object family
, Lisp_Object frame
)
1674 Lisp_Object font_spec
, list
, *drivers
, vec
;
1675 int i
, nfonts
, ndrivers
;
1679 frame
= selected_frame
;
1680 CHECK_LIVE_FRAME (frame
);
1682 font_spec
= Ffont_spec (0, NULL
);
1685 CHECK_STRING (family
);
1686 font_parse_family_registry (family
, Qnil
, font_spec
);
1689 list
= font_list_entities (frame
, font_spec
);
1693 /* Sort the font entities. */
1694 for (i
= 0; i
< 4; i
++)
1695 switch (font_sort_order
[i
])
1698 font_props_for_sorting
[i
] = FONT_WIDTH_INDEX
; break;
1699 case XLFD_POINT_SIZE
:
1700 font_props_for_sorting
[i
] = FONT_SIZE_INDEX
; break;
1702 font_props_for_sorting
[i
] = FONT_WEIGHT_INDEX
; break;
1704 font_props_for_sorting
[i
] = FONT_SLANT_INDEX
; break;
1706 font_props_for_sorting
[i
++] = FONT_FAMILY_INDEX
;
1707 font_props_for_sorting
[i
++] = FONT_FOUNDRY_INDEX
;
1708 font_props_for_sorting
[i
++] = FONT_ADSTYLE_INDEX
;
1709 font_props_for_sorting
[i
++] = FONT_REGISTRY_INDEX
;
1711 ndrivers
= XINT (Flength (list
));
1712 drivers
= alloca (sizeof (Lisp_Object
) * ndrivers
);
1713 for (i
= 0; i
< ndrivers
; i
++, list
= XCDR (list
))
1714 drivers
[i
] = XCAR (list
);
1715 vec
= Fvconcat (ndrivers
, drivers
);
1716 nfonts
= ASIZE (vec
);
1718 qsort (XVECTOR (vec
)->contents
, nfonts
, sizeof (Lisp_Object
),
1719 compare_fonts_by_sort_order
);
1722 for (i
= nfonts
- 1; i
>= 0; --i
)
1724 Lisp_Object font
= AREF (vec
, i
);
1725 Lisp_Object v
= Fmake_vector (make_number (8), Qnil
);
1727 Lisp_Object spacing
;
1729 ASET (v
, 0, AREF (font
, FONT_FAMILY_INDEX
));
1730 ASET (v
, 1, FONT_WIDTH_SYMBOLIC (font
));
1731 point
= PIXEL_TO_POINT (XINT (AREF (font
, FONT_SIZE_INDEX
)) * 10,
1732 XFRAME (frame
)->resy
);
1733 ASET (v
, 2, make_number (point
));
1734 ASET (v
, 3, FONT_WEIGHT_SYMBOLIC (font
));
1735 ASET (v
, 4, FONT_SLANT_SYMBOLIC (font
));
1736 spacing
= Ffont_get (font
, QCspacing
);
1737 ASET (v
, 5, (NILP (spacing
) || EQ (spacing
, Qp
)) ? Qnil
: Qt
);
1738 ASET (v
, 6, Ffont_xlfd_name (font
, Qnil
));
1739 ASET (v
, 7, AREF (font
, FONT_REGISTRY_INDEX
));
1741 result
= Fcons (v
, result
);
1747 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
1748 doc
: /* Return a list of the names of available fonts matching PATTERN.
1749 If optional arguments FACE and FRAME are specified, return only fonts
1750 the same size as FACE on FRAME.
1752 PATTERN should be a string containing a font name in the XLFD,
1753 Fontconfig, or GTK format. A font name given in the XLFD format may
1754 contain wildcard characters:
1755 the * character matches any substring, and
1756 the ? character matches any single character.
1757 PATTERN is case-insensitive.
1759 The return value is a list of strings, suitable as arguments to
1762 Fonts Emacs can't use may or may not be excluded
1763 even if they match PATTERN and FACE.
1764 The optional fourth argument MAXIMUM sets a limit on how many
1765 fonts to match. The first MAXIMUM fonts are reported.
1766 The optional fifth argument WIDTH, if specified, is a number of columns
1767 occupied by a character of a font. In that case, return only fonts
1768 the WIDTH times as wide as FACE on FRAME. */)
1769 (Lisp_Object pattern
, Lisp_Object face
, Lisp_Object frame
, Lisp_Object maximum
, Lisp_Object width
)
1775 CHECK_STRING (pattern
);
1777 if (! NILP (maximum
))
1778 CHECK_NATNUM (maximum
);
1781 CHECK_NUMBER (width
);
1783 /* We can't simply call check_x_frame because this function may be
1784 called before any frame is created. */
1786 frame
= selected_frame
;
1787 f
= frame_or_selected_frame (frame
, 2);
1788 if (! FRAME_WINDOW_P (f
))
1790 /* Perhaps we have not yet created any frame. */
1796 /* Determine the width standard for comparison with the fonts we find. */
1802 /* This is of limited utility since it works with character
1803 widths. Keep it for compatibility. --gerd. */
1804 int face_id
= lookup_named_face (f
, face
, 0);
1805 struct face
*face
= (face_id
< 0
1807 : FACE_FROM_ID (f
, face_id
));
1809 if (face
&& face
->font
)
1811 size
= face
->font
->pixel_size
;
1812 avgwidth
= face
->font
->average_width
;
1816 size
= FRAME_FONT (f
)->pixel_size
;
1817 avgwidth
= FRAME_FONT (f
)->average_width
;
1820 avgwidth
*= XINT (width
);
1824 Lisp_Object font_spec
;
1825 Lisp_Object args
[2], tail
;
1827 font_spec
= font_spec_from_name (pattern
);
1828 if (!FONTP (font_spec
))
1829 signal_error ("Invalid font name", pattern
);
1833 Ffont_put (font_spec
, QCsize
, make_number (size
));
1834 Ffont_put (font_spec
, QCavgwidth
, make_number (avgwidth
));
1836 args
[0] = Flist_fonts (font_spec
, frame
, maximum
, font_spec
);
1837 for (tail
= args
[0]; CONSP (tail
); tail
= XCDR (tail
))
1839 Lisp_Object font_entity
;
1841 font_entity
= XCAR (tail
);
1842 if ((NILP (AREF (font_entity
, FONT_SIZE_INDEX
))
1843 || XINT (AREF (font_entity
, FONT_SIZE_INDEX
)) == 0)
1844 && ! NILP (AREF (font_spec
, FONT_SIZE_INDEX
)))
1846 /* This is a scalable font. For backward compatibility,
1847 we set the specified size. */
1848 font_entity
= Fcopy_font_spec (font_entity
);
1849 ASET (font_entity
, FONT_SIZE_INDEX
,
1850 AREF (font_spec
, FONT_SIZE_INDEX
));
1852 XSETCAR (tail
, Ffont_xlfd_name (font_entity
, Qnil
));
1855 /* We don't have to check fontsets. */
1857 args
[1] = list_fontsets (f
, pattern
, size
);
1858 return Fnconc (2, args
);
1862 #endif /* HAVE_WINDOW_SYSTEM */
1865 /***********************************************************************
1867 ***********************************************************************/
1869 /* Access face attributes of face LFACE, a Lisp vector. */
1871 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
1872 #define LFACE_FOUNDRY(LFACE) AREF ((LFACE), LFACE_FOUNDRY_INDEX)
1873 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
1874 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
1875 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
1876 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
1877 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
1878 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
1879 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
1880 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
1881 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
1882 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
1883 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
1884 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
1885 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
1886 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
1887 #define LFACE_FONTSET(LFACE) AREF ((LFACE), LFACE_FONTSET_INDEX)
1889 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
1890 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
1892 #define LFACEP(LFACE) \
1894 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \
1895 && EQ (AREF (LFACE, 0), Qface))
1900 /* Check consistency of Lisp face attribute vector ATTRS. */
1903 check_lface_attrs (attrs
)
1906 xassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
1907 || IGNORE_DEFFACE_P (attrs
[LFACE_FAMILY_INDEX
])
1908 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
1909 xassert (UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
1910 || IGNORE_DEFFACE_P (attrs
[LFACE_FOUNDRY_INDEX
])
1911 || STRINGP (attrs
[LFACE_FOUNDRY_INDEX
]));
1912 xassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
1913 || IGNORE_DEFFACE_P (attrs
[LFACE_SWIDTH_INDEX
])
1914 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
1915 xassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
1916 || IGNORE_DEFFACE_P (attrs
[LFACE_HEIGHT_INDEX
])
1917 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
])
1918 || FLOATP (attrs
[LFACE_HEIGHT_INDEX
])
1919 || FUNCTIONP (attrs
[LFACE_HEIGHT_INDEX
]));
1920 xassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
1921 || IGNORE_DEFFACE_P (attrs
[LFACE_WEIGHT_INDEX
])
1922 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
1923 xassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
1924 || IGNORE_DEFFACE_P (attrs
[LFACE_SLANT_INDEX
])
1925 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
1926 xassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
1927 || IGNORE_DEFFACE_P (attrs
[LFACE_UNDERLINE_INDEX
])
1928 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
1929 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]));
1930 xassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
1931 || IGNORE_DEFFACE_P (attrs
[LFACE_OVERLINE_INDEX
])
1932 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
1933 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
1934 xassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1935 || IGNORE_DEFFACE_P (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1936 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1937 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
1938 xassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
1939 || IGNORE_DEFFACE_P (attrs
[LFACE_BOX_INDEX
])
1940 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
1941 || STRINGP (attrs
[LFACE_BOX_INDEX
])
1942 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
1943 || CONSP (attrs
[LFACE_BOX_INDEX
]));
1944 xassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
1945 || IGNORE_DEFFACE_P (attrs
[LFACE_INVERSE_INDEX
])
1946 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
1947 xassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
1948 || IGNORE_DEFFACE_P (attrs
[LFACE_FOREGROUND_INDEX
])
1949 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
1950 xassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
1951 || IGNORE_DEFFACE_P (attrs
[LFACE_BACKGROUND_INDEX
])
1952 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
1953 xassert (UNSPECIFIEDP (attrs
[LFACE_INHERIT_INDEX
])
1954 || IGNORE_DEFFACE_P (attrs
[LFACE_INHERIT_INDEX
])
1955 || NILP (attrs
[LFACE_INHERIT_INDEX
])
1956 || SYMBOLP (attrs
[LFACE_INHERIT_INDEX
])
1957 || CONSP (attrs
[LFACE_INHERIT_INDEX
]));
1958 #ifdef HAVE_WINDOW_SYSTEM
1959 xassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
1960 || IGNORE_DEFFACE_P (attrs
[LFACE_STIPPLE_INDEX
])
1961 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
1962 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
1963 xassert (UNSPECIFIEDP (attrs
[LFACE_FONT_INDEX
])
1964 || IGNORE_DEFFACE_P (attrs
[LFACE_FONT_INDEX
])
1965 || FONTP (attrs
[LFACE_FONT_INDEX
]));
1966 xassert (UNSPECIFIEDP (attrs
[LFACE_FONTSET_INDEX
])
1967 || STRINGP (attrs
[LFACE_FONTSET_INDEX
]));
1972 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
1980 xassert (LFACEP (lface
));
1981 check_lface_attrs (XVECTOR (lface
)->contents
);
1985 #else /* GLYPH_DEBUG == 0 */
1987 #define check_lface_attrs(attrs) (void) 0
1988 #define check_lface(lface) (void) 0
1990 #endif /* GLYPH_DEBUG == 0 */
1994 /* Face-merge cycle checking. */
1996 enum named_merge_point_kind
1998 NAMED_MERGE_POINT_NORMAL
,
1999 NAMED_MERGE_POINT_REMAP
2002 /* A `named merge point' is simply a point during face-merging where we
2003 look up a face by name. We keep a stack of which named lookups we're
2004 currently processing so that we can easily detect cycles, using a
2005 linked- list of struct named_merge_point structures, typically
2006 allocated on the stack frame of the named lookup functions which are
2007 active (so no consing is required). */
2008 struct named_merge_point
2010 Lisp_Object face_name
;
2011 enum named_merge_point_kind named_merge_point_kind
;
2012 struct named_merge_point
*prev
;
2016 /* If a face merging cycle is detected for FACE_NAME, return 0,
2017 otherwise add NEW_NAMED_MERGE_POINT, which is initialized using
2018 FACE_NAME and NAMED_MERGE_POINT_KIND, as the head of the linked list
2019 pointed to by NAMED_MERGE_POINTS, and return 1. */
2022 push_named_merge_point (struct named_merge_point
*new_named_merge_point
,
2023 Lisp_Object face_name
,
2024 enum named_merge_point_kind named_merge_point_kind
,
2025 struct named_merge_point
**named_merge_points
)
2027 struct named_merge_point
*prev
;
2029 for (prev
= *named_merge_points
; prev
; prev
= prev
->prev
)
2030 if (EQ (face_name
, prev
->face_name
))
2032 if (prev
->named_merge_point_kind
== named_merge_point_kind
)
2033 /* A cycle, so fail. */
2035 else if (prev
->named_merge_point_kind
== NAMED_MERGE_POINT_REMAP
)
2036 /* A remap `hides ' any previous normal merge points
2037 (because the remap means that it's actually different face),
2038 so as we know the current merge point must be normal, we
2039 can just assume it's OK. */
2043 new_named_merge_point
->face_name
= face_name
;
2044 new_named_merge_point
->named_merge_point_kind
= named_merge_point_kind
;
2045 new_named_merge_point
->prev
= *named_merge_points
;
2047 *named_merge_points
= new_named_merge_point
;
2054 #if 0 /* Seems to be unused. */
2056 internal_resolve_face_name (nargs
, args
)
2060 return Fget (args
[0], args
[1]);
2064 resolve_face_name_error (ignore
)
2071 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
2072 to make it a symbol. If FACE_NAME is an alias for another face,
2073 return that face's name.
2075 Return default face in case of errors. */
2078 resolve_face_name (Lisp_Object face_name
, int signal_p
)
2080 Lisp_Object orig_face
;
2081 Lisp_Object tortoise
, hare
;
2083 if (STRINGP (face_name
))
2084 face_name
= intern (SDATA (face_name
));
2086 if (NILP (face_name
) || !SYMBOLP (face_name
))
2089 orig_face
= face_name
;
2090 tortoise
= hare
= face_name
;
2095 hare
= Fget (hare
, Qface_alias
);
2096 if (NILP (hare
) || !SYMBOLP (hare
))
2100 hare
= Fget (hare
, Qface_alias
);
2101 if (NILP (hare
) || !SYMBOLP (hare
))
2104 tortoise
= Fget (tortoise
, Qface_alias
);
2105 if (EQ (hare
, tortoise
))
2108 xsignal1 (Qcircular_list
, orig_face
);
2117 /* Return the face definition of FACE_NAME on frame F. F null means
2118 return the definition for new frames. FACE_NAME may be a string or
2119 a symbol (apparently Emacs 20.2 allowed strings as face names in
2120 face text properties; Ediff uses that). If SIGNAL_P is non-zero,
2121 signal an error if FACE_NAME is not a valid face name. If SIGNAL_P
2122 is zero, value is nil if FACE_NAME is not a valid face name. */
2123 static INLINE Lisp_Object
2124 lface_from_face_name_no_resolve (struct frame
*f
, Lisp_Object face_name
, int signal_p
)
2129 lface
= assq_no_quit (face_name
, f
->face_alist
);
2131 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
2134 lface
= XCDR (lface
);
2136 signal_error ("Invalid face", face_name
);
2138 check_lface (lface
);
2143 /* Return the face definition of FACE_NAME on frame F. F null means
2144 return the definition for new frames. FACE_NAME may be a string or
2145 a symbol (apparently Emacs 20.2 allowed strings as face names in
2146 face text properties; Ediff uses that). If FACE_NAME is an alias
2147 for another face, return that face's definition. If SIGNAL_P is
2148 non-zero, signal an error if FACE_NAME is not a valid face name.
2149 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
2151 static INLINE Lisp_Object
2152 lface_from_face_name (struct frame
*f
, Lisp_Object face_name
, int signal_p
)
2154 face_name
= resolve_face_name (face_name
, signal_p
);
2155 return lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2159 /* Get face attributes of face FACE_NAME from frame-local faces on
2160 frame F. Store the resulting attributes in ATTRS which must point
2161 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
2162 is non-zero, signal an error if FACE_NAME does not name a face.
2163 Otherwise, value is zero if FACE_NAME is not a face. */
2166 get_lface_attributes_no_remap (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*attrs
, int signal_p
)
2170 lface
= lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2173 memcpy (attrs
, XVECTOR (lface
)->contents
,
2174 LFACE_VECTOR_SIZE
* sizeof *attrs
);
2176 return !NILP (lface
);
2179 /* Get face attributes of face FACE_NAME from frame-local faces on frame
2180 F. Store the resulting attributes in ATTRS which must point to a
2181 vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If FACE_NAME is an
2182 alias for another face, use that face's definition. If SIGNAL_P is
2183 non-zero, signal an error if FACE_NAME does not name a face.
2184 Otherwise, value is zero if FACE_NAME is not a face. */
2187 get_lface_attributes (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*attrs
, int signal_p
, struct named_merge_point
*named_merge_points
)
2189 Lisp_Object face_remapping
;
2191 face_name
= resolve_face_name (face_name
, signal_p
);
2193 /* See if SYMBOL has been remapped to some other face (usually this
2194 is done buffer-locally). */
2195 face_remapping
= assq_no_quit (face_name
, Vface_remapping_alist
);
2196 if (CONSP (face_remapping
))
2198 struct named_merge_point named_merge_point
;
2200 if (push_named_merge_point (&named_merge_point
,
2201 face_name
, NAMED_MERGE_POINT_REMAP
,
2202 &named_merge_points
))
2206 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2207 attrs
[i
] = Qunspecified
;
2209 return merge_face_ref (f
, XCDR (face_remapping
), attrs
,
2210 signal_p
, named_merge_points
);
2214 /* Default case, no remapping. */
2215 return get_lface_attributes_no_remap (f
, face_name
, attrs
, signal_p
);
2219 /* Non-zero if all attributes in face attribute vector ATTRS are
2220 specified, i.e. are non-nil. */
2223 lface_fully_specified_p (Lisp_Object
*attrs
)
2227 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2228 if (i
!= LFACE_FONT_INDEX
&& i
!= LFACE_INHERIT_INDEX
)
2229 if ((UNSPECIFIEDP (attrs
[i
]) || IGNORE_DEFFACE_P (attrs
[i
])))
2232 return i
== LFACE_VECTOR_SIZE
;
2235 #ifdef HAVE_WINDOW_SYSTEM
2237 /* Set font-related attributes of Lisp face LFACE from FONT-OBJECT.
2238 If FORCE_P is zero, set only unspecified attributes of LFACE. The
2239 exception is `font' attribute. It is set to FONT_OBJECT regardless
2243 set_lface_from_font (struct frame
*f
, Lisp_Object lface
, Lisp_Object font_object
, int force_p
)
2246 struct font
*font
= XFONT_OBJECT (font_object
);
2248 /* Set attributes only if unspecified, otherwise face defaults for
2249 new frames would never take effect. If the font doesn't have a
2250 specific property, set a normal value for that. */
2252 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
2254 Lisp_Object family
= AREF (font_object
, FONT_FAMILY_INDEX
);
2256 LFACE_FAMILY (lface
) = SYMBOL_NAME (family
);
2259 if (force_p
|| UNSPECIFIEDP (LFACE_FOUNDRY (lface
)))
2261 Lisp_Object foundry
= AREF (font_object
, FONT_FOUNDRY_INDEX
);
2263 LFACE_FOUNDRY (lface
) = SYMBOL_NAME (foundry
);
2266 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
2268 int pt
= PIXEL_TO_POINT (font
->pixel_size
* 10, f
->resy
);
2271 LFACE_HEIGHT (lface
) = make_number (pt
);
2274 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
2276 val
= FONT_WEIGHT_FOR_FACE (font_object
);
2277 LFACE_WEIGHT (lface
) = ! NILP (val
) ? val
:Qnormal
;
2279 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
2281 val
= FONT_SLANT_FOR_FACE (font_object
);
2282 LFACE_SLANT (lface
) = ! NILP (val
) ? val
: Qnormal
;
2284 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
2286 val
= FONT_WIDTH_FOR_FACE (font_object
);
2287 LFACE_SWIDTH (lface
) = ! NILP (val
) ? val
: Qnormal
;
2290 LFACE_FONT (lface
) = font_object
;
2294 #endif /* HAVE_WINDOW_SYSTEM */
2297 /* Merges the face height FROM with the face height TO, and returns the
2298 merged height. If FROM is an invalid height, then INVALID is
2299 returned instead. FROM and TO may be either absolute face heights or
2300 `relative' heights; the returned value is always an absolute height
2301 unless both FROM and TO are relative. */
2304 merge_face_heights (Lisp_Object from
, Lisp_Object to
, Lisp_Object invalid
)
2306 Lisp_Object result
= invalid
;
2308 if (INTEGERP (from
))
2309 /* FROM is absolute, just use it as is. */
2311 else if (FLOATP (from
))
2312 /* FROM is a scale, use it to adjust TO. */
2315 /* relative X absolute => absolute */
2316 result
= make_number ((EMACS_INT
)(XFLOAT_DATA (from
) * XINT (to
)));
2317 else if (FLOATP (to
))
2318 /* relative X relative => relative */
2319 result
= make_float (XFLOAT_DATA (from
) * XFLOAT_DATA (to
));
2320 else if (UNSPECIFIEDP (to
))
2323 else if (FUNCTIONP (from
))
2324 /* FROM is a function, which use to adjust TO. */
2326 /* Call function with current height as argument.
2327 From is the new height. */
2328 Lisp_Object args
[2];
2332 result
= safe_call (2, args
);
2334 /* Ensure that if TO was absolute, so is the result. */
2335 if (INTEGERP (to
) && !INTEGERP (result
))
2343 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
2344 store the resulting attributes in TO, which must be already be
2345 completely specified and contain only absolute attributes. Every
2346 specified attribute of FROM overrides the corresponding attribute of
2347 TO; relative attributes in FROM are merged with the absolute value in
2348 TO and replace it. NAMED_MERGE_POINTS is used internally to detect
2349 loops in face inheritance/remapping; it should be 0 when called from
2353 merge_face_vectors (struct frame
*f
, Lisp_Object
*from
, Lisp_Object
*to
, struct named_merge_point
*named_merge_points
)
2357 /* If FROM inherits from some other faces, merge their attributes into
2358 TO before merging FROM's direct attributes. Note that an :inherit
2359 attribute of `unspecified' is the same as one of nil; we never
2360 merge :inherit attributes, so nil is more correct, but lots of
2361 other code uses `unspecified' as a generic value for face attributes. */
2362 if (!UNSPECIFIEDP (from
[LFACE_INHERIT_INDEX
])
2363 && !NILP (from
[LFACE_INHERIT_INDEX
]))
2364 merge_face_ref (f
, from
[LFACE_INHERIT_INDEX
], to
, 0, named_merge_points
);
2366 i
= LFACE_FONT_INDEX
;
2367 if (!UNSPECIFIEDP (from
[i
]))
2369 if (!UNSPECIFIEDP (to
[i
]))
2370 to
[i
] = Fmerge_font_spec (from
[i
], to
[i
]);
2372 to
[i
] = Fcopy_font_spec (from
[i
]);
2373 if (! NILP (AREF (to
[i
], FONT_FOUNDRY_INDEX
)))
2374 to
[LFACE_FOUNDRY_INDEX
] = SYMBOL_NAME (AREF (to
[i
], FONT_FOUNDRY_INDEX
));
2375 if (! NILP (AREF (to
[i
], FONT_FAMILY_INDEX
)))
2376 to
[LFACE_FAMILY_INDEX
] = SYMBOL_NAME (AREF (to
[i
], FONT_FAMILY_INDEX
));
2377 if (! NILP (AREF (to
[i
], FONT_WEIGHT_INDEX
)))
2378 to
[LFACE_WEIGHT_INDEX
] = FONT_WEIGHT_FOR_FACE (to
[i
]);
2379 if (! NILP (AREF (to
[i
], FONT_SLANT_INDEX
)))
2380 to
[LFACE_SLANT_INDEX
] = FONT_SLANT_FOR_FACE (to
[i
]);
2381 if (! NILP (AREF (to
[i
], FONT_WIDTH_INDEX
)))
2382 to
[LFACE_SWIDTH_INDEX
] = FONT_WIDTH_FOR_FACE (to
[i
]);
2383 ASET (to
[i
], FONT_SIZE_INDEX
, Qnil
);
2386 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2387 if (!UNSPECIFIEDP (from
[i
]))
2389 if (i
== LFACE_HEIGHT_INDEX
&& !INTEGERP (from
[i
]))
2391 to
[i
] = merge_face_heights (from
[i
], to
[i
], to
[i
]);
2392 font_clear_prop (to
, FONT_SIZE_INDEX
);
2394 else if (i
!= LFACE_FONT_INDEX
2395 && ! EQ (to
[i
], from
[i
]))
2398 if (i
>= LFACE_FAMILY_INDEX
&& i
<=LFACE_SLANT_INDEX
)
2399 font_clear_prop (to
,
2400 (i
== LFACE_FAMILY_INDEX
? FONT_FAMILY_INDEX
2401 : i
== LFACE_FOUNDRY_INDEX
? FONT_FOUNDRY_INDEX
2402 : i
== LFACE_SWIDTH_INDEX
? FONT_WIDTH_INDEX
2403 : i
== LFACE_HEIGHT_INDEX
? FONT_SIZE_INDEX
2404 : i
== LFACE_WEIGHT_INDEX
? FONT_WEIGHT_INDEX
2405 : FONT_SLANT_INDEX
));
2409 /* TO is always an absolute face, which should inherit from nothing.
2410 We blindly copy the :inherit attribute above and fix it up here. */
2411 to
[LFACE_INHERIT_INDEX
] = Qnil
;
2414 /* Merge the named face FACE_NAME on frame F, into the vector of face
2415 attributes TO. NAMED_MERGE_POINTS is used to detect loops in face
2416 inheritance. Returns true if FACE_NAME is a valid face name and
2417 merging succeeded. */
2420 merge_named_face (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*to
, struct named_merge_point
*named_merge_points
)
2422 struct named_merge_point named_merge_point
;
2424 if (push_named_merge_point (&named_merge_point
,
2425 face_name
, NAMED_MERGE_POINT_NORMAL
,
2426 &named_merge_points
))
2428 struct gcpro gcpro1
;
2429 Lisp_Object from
[LFACE_VECTOR_SIZE
];
2430 int ok
= get_lface_attributes (f
, face_name
, from
, 0, named_merge_points
);
2434 GCPRO1 (named_merge_point
.face_name
);
2435 merge_face_vectors (f
, from
, to
, named_merge_points
);
2446 /* Merge face attributes from the lisp `face reference' FACE_REF on
2447 frame F into the face attribute vector TO. If ERR_MSGS is non-zero,
2448 problems with FACE_REF cause an error message to be shown. Return
2449 non-zero if no errors occurred (regardless of the value of ERR_MSGS).
2450 NAMED_MERGE_POINTS is used to detect loops in face inheritance or
2451 list structure; it may be 0 for most callers.
2453 FACE_REF may be a single face specification or a list of such
2454 specifications. Each face specification can be:
2456 1. A symbol or string naming a Lisp face.
2458 2. A property list of the form (KEYWORD VALUE ...) where each
2459 KEYWORD is a face attribute name, and value is an appropriate value
2462 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
2463 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
2464 for compatibility with 20.2.
2466 Face specifications earlier in lists take precedence over later
2470 merge_face_ref (struct frame
*f
, Lisp_Object face_ref
, Lisp_Object
*to
, int err_msgs
, struct named_merge_point
*named_merge_points
)
2472 int ok
= 1; /* Succeed without an error? */
2474 if (CONSP (face_ref
))
2476 Lisp_Object first
= XCAR (face_ref
);
2478 if (EQ (first
, Qforeground_color
)
2479 || EQ (first
, Qbackground_color
))
2481 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
2482 . COLOR). COLOR must be a string. */
2483 Lisp_Object color_name
= XCDR (face_ref
);
2484 Lisp_Object color
= first
;
2486 if (STRINGP (color_name
))
2488 if (EQ (color
, Qforeground_color
))
2489 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
2491 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
2496 add_to_log ("Invalid face color", color_name
, Qnil
);
2500 else if (SYMBOLP (first
)
2501 && *SDATA (SYMBOL_NAME (first
)) == ':')
2503 /* Assume this is the property list form. */
2504 while (CONSP (face_ref
) && CONSP (XCDR (face_ref
)))
2506 Lisp_Object keyword
= XCAR (face_ref
);
2507 Lisp_Object value
= XCAR (XCDR (face_ref
));
2510 /* Specifying `unspecified' is a no-op. */
2511 if (EQ (value
, Qunspecified
))
2513 else if (EQ (keyword
, QCfamily
))
2515 if (STRINGP (value
))
2517 to
[LFACE_FAMILY_INDEX
] = value
;
2518 font_clear_prop (to
, FONT_FAMILY_INDEX
);
2523 else if (EQ (keyword
, QCfoundry
))
2525 if (STRINGP (value
))
2527 to
[LFACE_FOUNDRY_INDEX
] = value
;
2528 font_clear_prop (to
, FONT_FOUNDRY_INDEX
);
2533 else if (EQ (keyword
, QCheight
))
2535 Lisp_Object new_height
=
2536 merge_face_heights (value
, to
[LFACE_HEIGHT_INDEX
], Qnil
);
2538 if (! NILP (new_height
))
2540 to
[LFACE_HEIGHT_INDEX
] = new_height
;
2541 font_clear_prop (to
, FONT_SIZE_INDEX
);
2546 else if (EQ (keyword
, QCweight
))
2548 if (SYMBOLP (value
) && FONT_WEIGHT_NAME_NUMERIC (value
) >= 0)
2550 to
[LFACE_WEIGHT_INDEX
] = value
;
2551 font_clear_prop (to
, FONT_WEIGHT_INDEX
);
2556 else if (EQ (keyword
, QCslant
))
2558 if (SYMBOLP (value
) && FONT_SLANT_NAME_NUMERIC (value
) >= 0)
2560 to
[LFACE_SLANT_INDEX
] = value
;
2561 font_clear_prop (to
, FONT_SLANT_INDEX
);
2566 else if (EQ (keyword
, QCunderline
))
2571 to
[LFACE_UNDERLINE_INDEX
] = value
;
2575 else if (EQ (keyword
, QCoverline
))
2580 to
[LFACE_OVERLINE_INDEX
] = value
;
2584 else if (EQ (keyword
, QCstrike_through
))
2589 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
2593 else if (EQ (keyword
, QCbox
))
2596 value
= make_number (1);
2597 if (INTEGERP (value
)
2601 to
[LFACE_BOX_INDEX
] = value
;
2605 else if (EQ (keyword
, QCinverse_video
)
2606 || EQ (keyword
, QCreverse_video
))
2608 if (EQ (value
, Qt
) || NILP (value
))
2609 to
[LFACE_INVERSE_INDEX
] = value
;
2613 else if (EQ (keyword
, QCforeground
))
2615 if (STRINGP (value
))
2616 to
[LFACE_FOREGROUND_INDEX
] = value
;
2620 else if (EQ (keyword
, QCbackground
))
2622 if (STRINGP (value
))
2623 to
[LFACE_BACKGROUND_INDEX
] = value
;
2627 else if (EQ (keyword
, QCstipple
))
2629 #if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
2630 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
2631 if (!NILP (pixmap_p
))
2632 to
[LFACE_STIPPLE_INDEX
] = value
;
2637 else if (EQ (keyword
, QCwidth
))
2639 if (SYMBOLP (value
) && FONT_WIDTH_NAME_NUMERIC (value
) >= 0)
2641 to
[LFACE_SWIDTH_INDEX
] = value
;
2642 font_clear_prop (to
, FONT_WIDTH_INDEX
);
2647 else if (EQ (keyword
, QCinherit
))
2649 /* This is not really very useful; it's just like a
2650 normal face reference. */
2651 if (! merge_face_ref (f
, value
, to
,
2652 err_msgs
, named_merge_points
))
2660 add_to_log ("Invalid face attribute %S %S", keyword
, value
);
2664 face_ref
= XCDR (XCDR (face_ref
));
2669 /* This is a list of face refs. Those at the beginning of the
2670 list take precedence over what follows, so we have to merge
2671 from the end backwards. */
2672 Lisp_Object next
= XCDR (face_ref
);
2675 ok
= merge_face_ref (f
, next
, to
, err_msgs
, named_merge_points
);
2677 if (! merge_face_ref (f
, first
, to
, err_msgs
, named_merge_points
))
2683 /* FACE_REF ought to be a face name. */
2684 ok
= merge_named_face (f
, face_ref
, to
, named_merge_points
);
2685 if (!ok
&& err_msgs
)
2686 add_to_log ("Invalid face reference: %s", face_ref
, Qnil
);
2693 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
2694 Sinternal_make_lisp_face
, 1, 2, 0,
2695 doc
: /* Make FACE, a symbol, a Lisp face with all attributes nil.
2696 If FACE was not known as a face before, create a new one.
2697 If optional argument FRAME is specified, make a frame-local face
2698 for that frame. Otherwise operate on the global face definition.
2699 Value is a vector of face attributes. */)
2700 (Lisp_Object face
, Lisp_Object frame
)
2702 Lisp_Object global_lface
, lface
;
2706 CHECK_SYMBOL (face
);
2707 global_lface
= lface_from_face_name (NULL
, face
, 0);
2711 CHECK_LIVE_FRAME (frame
);
2713 lface
= lface_from_face_name (f
, face
, 0);
2716 f
= NULL
, lface
= Qnil
;
2718 /* Add a global definition if there is none. */
2719 if (NILP (global_lface
))
2721 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2723 ASET (global_lface
, 0, Qface
);
2724 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
2725 Vface_new_frame_defaults
);
2727 /* Assign the new Lisp face a unique ID. The mapping from Lisp
2728 face id to Lisp face is given by the vector lface_id_to_name.
2729 The mapping from Lisp face to Lisp face id is given by the
2730 property `face' of the Lisp face name. */
2731 if (next_lface_id
== lface_id_to_name_size
)
2733 int new_size
= max (50, 2 * lface_id_to_name_size
);
2734 int sz
= new_size
* sizeof *lface_id_to_name
;
2735 lface_id_to_name
= (Lisp_Object
*) xrealloc (lface_id_to_name
, sz
);
2736 lface_id_to_name_size
= new_size
;
2739 lface_id_to_name
[next_lface_id
] = face
;
2740 Fput (face
, Qface
, make_number (next_lface_id
));
2744 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2745 ASET (global_lface
, i
, Qunspecified
);
2747 /* Add a frame-local definition. */
2752 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2754 ASET (lface
, 0, Qface
);
2755 f
->face_alist
= Fcons (Fcons (face
, lface
), f
->face_alist
);
2758 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2759 ASET (lface
, i
, Qunspecified
);
2762 lface
= global_lface
;
2764 /* Changing a named face means that all realized faces depending on
2765 that face are invalid. Since we cannot tell which realized faces
2766 depend on the face, make sure they are all removed. This is done
2767 by incrementing face_change_count. The next call to
2768 init_iterator will then free realized faces. */
2769 if (NILP (Fget (face
, Qface_no_inherit
)))
2771 ++face_change_count
;
2772 ++windows_or_buffers_changed
;
2775 xassert (LFACEP (lface
));
2776 check_lface (lface
);
2781 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
2782 Sinternal_lisp_face_p
, 1, 2, 0,
2783 doc
: /* Return non-nil if FACE names a face.
2784 FACE should be a symbol or string.
2785 If optional second argument FRAME is non-nil, check for the
2786 existence of a frame-local face with name FACE on that frame.
2787 Otherwise check for the existence of a global face. */)
2788 (Lisp_Object face
, Lisp_Object frame
)
2792 face
= resolve_face_name (face
, 1);
2796 CHECK_LIVE_FRAME (frame
);
2797 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2800 lface
= lface_from_face_name (NULL
, face
, 0);
2806 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
2807 Sinternal_copy_lisp_face
, 4, 4, 0,
2808 doc
: /* Copy face FROM to TO.
2809 If FRAME is t, copy the global face definition of FROM.
2810 Otherwise, copy the frame-local definition of FROM on FRAME.
2811 If NEW-FRAME is a frame, copy that data into the frame-local
2812 definition of TO on NEW-FRAME. If NEW-FRAME is nil,
2813 FRAME controls where the data is copied to.
2815 The value is TO. */)
2816 (Lisp_Object from
, Lisp_Object to
, Lisp_Object frame
, Lisp_Object new_frame
)
2818 Lisp_Object lface
, copy
;
2820 CHECK_SYMBOL (from
);
2825 /* Copy global definition of FROM. We don't make copies of
2826 strings etc. because 20.2 didn't do it either. */
2827 lface
= lface_from_face_name (NULL
, from
, 1);
2828 copy
= Finternal_make_lisp_face (to
, Qnil
);
2832 /* Copy frame-local definition of FROM. */
2833 if (NILP (new_frame
))
2835 CHECK_LIVE_FRAME (frame
);
2836 CHECK_LIVE_FRAME (new_frame
);
2837 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
2838 copy
= Finternal_make_lisp_face (to
, new_frame
);
2841 memcpy (XVECTOR (copy
)->contents
, XVECTOR (lface
)->contents
,
2842 LFACE_VECTOR_SIZE
* sizeof (Lisp_Object
));
2844 /* Changing a named face means that all realized faces depending on
2845 that face are invalid. Since we cannot tell which realized faces
2846 depend on the face, make sure they are all removed. This is done
2847 by incrementing face_change_count. The next call to
2848 init_iterator will then free realized faces. */
2849 if (NILP (Fget (to
, Qface_no_inherit
)))
2851 ++face_change_count
;
2852 ++windows_or_buffers_changed
;
2859 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
2860 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
2861 doc
: /* Set attribute ATTR of FACE to VALUE.
2862 FRAME being a frame means change the face on that frame.
2863 FRAME nil means change the face of the selected frame.
2864 FRAME t means change the default for new frames.
2865 FRAME 0 means change the face on all frames, and change the default
2867 (Lisp_Object face
, Lisp_Object attr
, Lisp_Object value
, Lisp_Object frame
)
2870 Lisp_Object old_value
= Qnil
;
2871 /* Set one of enum font_property_index (> 0) if ATTR is one of
2872 font-related attributes other than QCfont and QCfontset. */
2873 enum font_property_index prop_index
= 0;
2875 CHECK_SYMBOL (face
);
2876 CHECK_SYMBOL (attr
);
2878 face
= resolve_face_name (face
, 1);
2880 /* If FRAME is 0, change face on all frames, and change the
2881 default for new frames. */
2882 if (INTEGERP (frame
) && XINT (frame
) == 0)
2885 Finternal_set_lisp_face_attribute (face
, attr
, value
, Qt
);
2886 FOR_EACH_FRAME (tail
, frame
)
2887 Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
2891 /* Set lface to the Lisp attribute vector of FACE. */
2894 lface
= lface_from_face_name (NULL
, face
, 1);
2896 /* When updating face-new-frame-defaults, we put :ignore-defface
2897 where the caller wants `unspecified'. This forces the frame
2898 defaults to ignore the defface value. Otherwise, the defface
2899 will take effect, which is generally not what is intended.
2900 The value of that attribute will be inherited from some other
2901 face during face merging. See internal_merge_in_global_face. */
2902 if (UNSPECIFIEDP (value
))
2903 value
= Qignore_defface
;
2908 frame
= selected_frame
;
2910 CHECK_LIVE_FRAME (frame
);
2911 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2913 /* If a frame-local face doesn't exist yet, create one. */
2915 lface
= Finternal_make_lisp_face (face
, frame
);
2918 if (EQ (attr
, QCfamily
))
2920 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2922 CHECK_STRING (value
);
2923 if (SCHARS (value
) == 0)
2924 signal_error ("Invalid face family", value
);
2926 old_value
= LFACE_FAMILY (lface
);
2927 LFACE_FAMILY (lface
) = value
;
2928 prop_index
= FONT_FAMILY_INDEX
;
2930 else if (EQ (attr
, QCfoundry
))
2932 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2934 CHECK_STRING (value
);
2935 if (SCHARS (value
) == 0)
2936 signal_error ("Invalid face foundry", value
);
2938 old_value
= LFACE_FOUNDRY (lface
);
2939 LFACE_FOUNDRY (lface
) = value
;
2940 prop_index
= FONT_FOUNDRY_INDEX
;
2942 else if (EQ (attr
, QCheight
))
2944 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2946 if (EQ (face
, Qdefault
))
2948 /* The default face must have an absolute size. */
2949 if (!INTEGERP (value
) || XINT (value
) <= 0)
2950 signal_error ("Invalid default face height", value
);
2954 /* For non-default faces, do a test merge with a random
2955 height to see if VALUE's ok. */
2956 Lisp_Object test
= merge_face_heights (value
,
2959 if (!INTEGERP (test
) || XINT (test
) <= 0)
2960 signal_error ("Invalid face height", value
);
2964 old_value
= LFACE_HEIGHT (lface
);
2965 LFACE_HEIGHT (lface
) = value
;
2966 prop_index
= FONT_SIZE_INDEX
;
2968 else if (EQ (attr
, QCweight
))
2970 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2972 CHECK_SYMBOL (value
);
2973 if (FONT_WEIGHT_NAME_NUMERIC (value
) < 0)
2974 signal_error ("Invalid face weight", value
);
2976 old_value
= LFACE_WEIGHT (lface
);
2977 LFACE_WEIGHT (lface
) = value
;
2978 prop_index
= FONT_WEIGHT_INDEX
;
2980 else if (EQ (attr
, QCslant
))
2982 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2984 CHECK_SYMBOL (value
);
2985 if (FONT_SLANT_NAME_NUMERIC (value
) < 0)
2986 signal_error ("Invalid face slant", value
);
2988 old_value
= LFACE_SLANT (lface
);
2989 LFACE_SLANT (lface
) = value
;
2990 prop_index
= FONT_SLANT_INDEX
;
2992 else if (EQ (attr
, QCunderline
))
2994 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2995 if ((SYMBOLP (value
)
2997 && !EQ (value
, Qnil
))
2998 /* Underline color. */
3000 && SCHARS (value
) == 0))
3001 signal_error ("Invalid face underline", value
);
3003 old_value
= LFACE_UNDERLINE (lface
);
3004 LFACE_UNDERLINE (lface
) = value
;
3006 else if (EQ (attr
, QCoverline
))
3008 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3009 if ((SYMBOLP (value
)
3011 && !EQ (value
, Qnil
))
3012 /* Overline color. */
3014 && SCHARS (value
) == 0))
3015 signal_error ("Invalid face overline", value
);
3017 old_value
= LFACE_OVERLINE (lface
);
3018 LFACE_OVERLINE (lface
) = value
;
3020 else if (EQ (attr
, QCstrike_through
))
3022 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3023 if ((SYMBOLP (value
)
3025 && !EQ (value
, Qnil
))
3026 /* Strike-through color. */
3028 && SCHARS (value
) == 0))
3029 signal_error ("Invalid face strike-through", value
);
3031 old_value
= LFACE_STRIKE_THROUGH (lface
);
3032 LFACE_STRIKE_THROUGH (lface
) = value
;
3034 else if (EQ (attr
, QCbox
))
3038 /* Allow t meaning a simple box of width 1 in foreground color
3041 value
= make_number (1);
3043 if (UNSPECIFIEDP (value
) || IGNORE_DEFFACE_P (value
))
3045 else if (NILP (value
))
3047 else if (INTEGERP (value
))
3048 valid_p
= XINT (value
) != 0;
3049 else if (STRINGP (value
))
3050 valid_p
= SCHARS (value
) > 0;
3051 else if (CONSP (value
))
3067 if (EQ (k
, QCline_width
))
3069 if (!INTEGERP (v
) || XINT (v
) == 0)
3072 else if (EQ (k
, QCcolor
))
3074 if (!NILP (v
) && (!STRINGP (v
) || SCHARS (v
) == 0))
3077 else if (EQ (k
, QCstyle
))
3079 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
3086 valid_p
= NILP (tem
);
3092 signal_error ("Invalid face box", value
);
3094 old_value
= LFACE_BOX (lface
);
3095 LFACE_BOX (lface
) = value
;
3097 else if (EQ (attr
, QCinverse_video
)
3098 || EQ (attr
, QCreverse_video
))
3100 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3102 CHECK_SYMBOL (value
);
3103 if (!EQ (value
, Qt
) && !NILP (value
))
3104 signal_error ("Invalid inverse-video face attribute value", value
);
3106 old_value
= LFACE_INVERSE (lface
);
3107 LFACE_INVERSE (lface
) = value
;
3109 else if (EQ (attr
, QCforeground
))
3111 /* Compatibility with 20.x. */
3113 value
= Qunspecified
;
3114 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3116 /* Don't check for valid color names here because it depends
3117 on the frame (display) whether the color will be valid
3118 when the face is realized. */
3119 CHECK_STRING (value
);
3120 if (SCHARS (value
) == 0)
3121 signal_error ("Empty foreground color value", value
);
3123 old_value
= LFACE_FOREGROUND (lface
);
3124 LFACE_FOREGROUND (lface
) = value
;
3126 else if (EQ (attr
, QCbackground
))
3128 /* Compatibility with 20.x. */
3130 value
= Qunspecified
;
3131 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3133 /* Don't check for valid color names here because it depends
3134 on the frame (display) whether the color will be valid
3135 when the face is realized. */
3136 CHECK_STRING (value
);
3137 if (SCHARS (value
) == 0)
3138 signal_error ("Empty background color value", value
);
3140 old_value
= LFACE_BACKGROUND (lface
);
3141 LFACE_BACKGROUND (lface
) = value
;
3143 else if (EQ (attr
, QCstipple
))
3145 #if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
3146 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3148 && NILP (Fbitmap_spec_p (value
)))
3149 signal_error ("Invalid stipple attribute", value
);
3150 old_value
= LFACE_STIPPLE (lface
);
3151 LFACE_STIPPLE (lface
) = value
;
3152 #endif /* HAVE_X_WINDOWS || HAVE_NS */
3154 else if (EQ (attr
, QCwidth
))
3156 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3158 CHECK_SYMBOL (value
);
3159 if (FONT_WIDTH_NAME_NUMERIC (value
) < 0)
3160 signal_error ("Invalid face width", value
);
3162 old_value
= LFACE_SWIDTH (lface
);
3163 LFACE_SWIDTH (lface
) = value
;
3164 prop_index
= FONT_WIDTH_INDEX
;
3166 else if (EQ (attr
, QCfont
))
3168 #ifdef HAVE_WINDOW_SYSTEM
3169 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3171 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3175 old_value
= LFACE_FONT (lface
);
3176 if (! FONTP (value
))
3178 if (STRINGP (value
))
3180 Lisp_Object name
= value
;
3181 int fontset
= fs_query_fontset (name
, 0);
3184 name
= fontset_ascii (fontset
);
3185 value
= font_spec_from_name (name
);
3187 signal_error ("Invalid font name", name
);
3190 signal_error ("Invalid font or font-spec", value
);
3193 f
= XFRAME (selected_frame
);
3196 if (! FONT_OBJECT_P (value
))
3198 Lisp_Object
*attrs
= XVECTOR (lface
)->contents
;
3199 Lisp_Object font_object
;
3201 font_object
= font_load_for_lface (f
, attrs
, value
);
3202 if (NILP (font_object
))
3203 signal_error ("Font not available", value
);
3204 value
= font_object
;
3206 set_lface_from_font (f
, lface
, value
, 1);
3209 LFACE_FONT (lface
) = value
;
3211 #endif /* HAVE_WINDOW_SYSTEM */
3213 else if (EQ (attr
, QCfontset
))
3215 #ifdef HAVE_WINDOW_SYSTEM
3216 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3220 old_value
= LFACE_FONTSET (lface
);
3221 tmp
= Fquery_fontset (value
, Qnil
);
3223 signal_error ("Invalid fontset name", value
);
3224 LFACE_FONTSET (lface
) = value
= tmp
;
3226 #endif /* HAVE_WINDOW_SYSTEM */
3228 else if (EQ (attr
, QCinherit
))
3231 if (SYMBOLP (value
))
3234 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
3235 if (!SYMBOLP (XCAR (tail
)))
3238 LFACE_INHERIT (lface
) = value
;
3240 signal_error ("Invalid face inheritance", value
);
3242 else if (EQ (attr
, QCbold
))
3244 old_value
= LFACE_WEIGHT (lface
);
3245 LFACE_WEIGHT (lface
) = NILP (value
) ? Qnormal
: Qbold
;
3246 prop_index
= FONT_WEIGHT_INDEX
;
3248 else if (EQ (attr
, QCitalic
))
3251 old_value
= LFACE_SLANT (lface
);
3252 LFACE_SLANT (lface
) = NILP (value
) ? Qnormal
: Qitalic
;
3253 prop_index
= FONT_SLANT_INDEX
;
3256 signal_error ("Invalid face attribute name", attr
);
3260 /* If a font-related attribute other than QCfont and QCfontset
3261 is specified, and if the original QCfont attribute has a font
3262 (font-spec or font-object), set the corresponding property in
3263 the font to nil so that the font selector doesn't think that
3264 the attribute is mandatory. Also, clear the average
3266 font_clear_prop (XVECTOR (lface
)->contents
, prop_index
);
3269 /* Changing a named face means that all realized faces depending on
3270 that face are invalid. Since we cannot tell which realized faces
3271 depend on the face, make sure they are all removed. This is done
3272 by incrementing face_change_count. The next call to
3273 init_iterator will then free realized faces. */
3275 && NILP (Fget (face
, Qface_no_inherit
))
3276 && NILP (Fequal (old_value
, value
)))
3278 ++face_change_count
;
3279 ++windows_or_buffers_changed
;
3282 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3283 && NILP (Fequal (old_value
, value
)))
3289 if (EQ (face
, Qdefault
))
3291 #ifdef HAVE_WINDOW_SYSTEM
3292 /* Changed font-related attributes of the `default' face are
3293 reflected in changed `font' frame parameters. */
3295 && (prop_index
|| EQ (attr
, QCfont
))
3296 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
3297 set_font_frame_param (frame
, lface
);
3299 #endif /* HAVE_WINDOW_SYSTEM */
3301 if (EQ (attr
, QCforeground
))
3302 param
= Qforeground_color
;
3303 else if (EQ (attr
, QCbackground
))
3304 param
= Qbackground_color
;
3306 #ifdef HAVE_WINDOW_SYSTEM
3308 else if (EQ (face
, Qscroll_bar
))
3310 /* Changing the colors of `scroll-bar' sets frame parameters
3311 `scroll-bar-foreground' and `scroll-bar-background'. */
3312 if (EQ (attr
, QCforeground
))
3313 param
= Qscroll_bar_foreground
;
3314 else if (EQ (attr
, QCbackground
))
3315 param
= Qscroll_bar_background
;
3317 #endif /* not WINDOWSNT */
3318 else if (EQ (face
, Qborder
))
3320 /* Changing background color of `border' sets frame parameter
3322 if (EQ (attr
, QCbackground
))
3323 param
= Qborder_color
;
3325 else if (EQ (face
, Qcursor
))
3327 /* Changing background color of `cursor' sets frame parameter
3329 if (EQ (attr
, QCbackground
))
3330 param
= Qcursor_color
;
3332 else if (EQ (face
, Qmouse
))
3334 /* Changing background color of `mouse' sets frame parameter
3336 if (EQ (attr
, QCbackground
))
3337 param
= Qmouse_color
;
3339 #endif /* HAVE_WINDOW_SYSTEM */
3340 else if (EQ (face
, Qmenu
))
3342 /* Indicate that we have to update the menu bar when
3343 realizing faces on FRAME. FRAME t change the
3344 default for new frames. We do this by setting
3345 setting the flag in new face caches */
3348 struct frame
*f
= XFRAME (frame
);
3349 if (FRAME_FACE_CACHE (f
) == NULL
)
3350 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
3351 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 1;
3354 menu_face_changed_default
= 1;
3360 /* Update `default-frame-alist', which is used for new frames. */
3362 store_in_alist (&Vdefault_frame_alist
, param
, value
);
3365 /* Update the current frame's parameters. */
3368 cons
= XCAR (Vparam_value_alist
);
3369 XSETCAR (cons
, param
);
3370 XSETCDR (cons
, value
);
3371 Fmodify_frame_parameters (frame
, Vparam_value_alist
);
3380 /* Update the corresponding face when frame parameter PARAM on frame F
3381 has been assigned the value NEW_VALUE. */
3384 update_face_from_frame_parameter (struct frame
*f
, Lisp_Object param
, Lisp_Object new_value
)
3386 Lisp_Object face
= Qnil
;
3389 /* If there are no faces yet, give up. This is the case when called
3390 from Fx_create_frame, and we do the necessary things later in
3391 face-set-after-frame-defaults. */
3392 if (NILP (f
->face_alist
))
3395 if (EQ (param
, Qforeground_color
))
3398 lface
= lface_from_face_name (f
, face
, 1);
3399 LFACE_FOREGROUND (lface
) = (STRINGP (new_value
)
3400 ? new_value
: Qunspecified
);
3401 realize_basic_faces (f
);
3403 else if (EQ (param
, Qbackground_color
))
3407 /* Changing the background color might change the background
3408 mode, so that we have to load new defface specs.
3409 Call frame-update-face-colors to do that. */
3410 XSETFRAME (frame
, f
);
3411 call1 (Qframe_set_background_mode
, frame
);
3414 lface
= lface_from_face_name (f
, face
, 1);
3415 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3416 ? new_value
: Qunspecified
);
3417 realize_basic_faces (f
);
3419 #ifdef HAVE_WINDOW_SYSTEM
3420 else if (EQ (param
, Qborder_color
))
3423 lface
= lface_from_face_name (f
, face
, 1);
3424 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3425 ? new_value
: Qunspecified
);
3427 else if (EQ (param
, Qcursor_color
))
3430 lface
= lface_from_face_name (f
, face
, 1);
3431 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3432 ? new_value
: Qunspecified
);
3434 else if (EQ (param
, Qmouse_color
))
3437 lface
= lface_from_face_name (f
, face
, 1);
3438 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3439 ? new_value
: Qunspecified
);
3443 /* Changing a named face means that all realized faces depending on
3444 that face are invalid. Since we cannot tell which realized faces
3445 depend on the face, make sure they are all removed. This is done
3446 by incrementing face_change_count. The next call to
3447 init_iterator will then free realized faces. */
3449 && NILP (Fget (face
, Qface_no_inherit
)))
3451 ++face_change_count
;
3452 ++windows_or_buffers_changed
;
3457 #ifdef HAVE_WINDOW_SYSTEM
3459 /* Set the `font' frame parameter of FRAME determined from the
3460 font-object set in `default' face attributes LFACE. */
3463 set_font_frame_param (Lisp_Object frame
, Lisp_Object lface
)
3465 struct frame
*f
= XFRAME (frame
);
3468 if (FRAME_WINDOW_P (f
)
3469 /* Don't do anything if the font is `unspecified'. This can
3470 happen during frame creation. */
3471 && (font
= LFACE_FONT (lface
),
3472 ! UNSPECIFIEDP (font
)))
3474 if (FONT_SPEC_P (font
))
3476 font
= font_load_for_lface (f
, XVECTOR (lface
)->contents
, font
);
3479 LFACE_FONT (lface
) = font
;
3481 f
->default_face_done_p
= 0;
3482 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, font
), Qnil
));
3487 /* Get the value of X resource RESOURCE, class CLASS for the display
3488 of frame FRAME. This is here because ordinary `x-get-resource'
3489 doesn't take a frame argument. */
3491 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
3492 Sinternal_face_x_get_resource
, 3, 3, 0, doc
: /* */)
3493 (Lisp_Object resource
, Lisp_Object
class, Lisp_Object frame
)
3495 Lisp_Object value
= Qnil
;
3496 CHECK_STRING (resource
);
3497 CHECK_STRING (class);
3498 CHECK_LIVE_FRAME (frame
);
3500 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame
)),
3501 resource
, class, Qnil
, Qnil
);
3507 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
3508 If VALUE is "on" or "true", return t. If VALUE is "off" or
3509 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
3510 error; if SIGNAL_P is zero, return 0. */
3513 face_boolean_x_resource_value (Lisp_Object value
, int signal_p
)
3515 Lisp_Object result
= make_number (0);
3517 xassert (STRINGP (value
));
3519 if (xstrcasecmp (SDATA (value
), "on") == 0
3520 || xstrcasecmp (SDATA (value
), "true") == 0)
3522 else if (xstrcasecmp (SDATA (value
), "off") == 0
3523 || xstrcasecmp (SDATA (value
), "false") == 0)
3525 else if (xstrcasecmp (SDATA (value
), "unspecified") == 0)
3526 result
= Qunspecified
;
3528 signal_error ("Invalid face attribute value from X resource", value
);
3534 DEFUN ("internal-set-lisp-face-attribute-from-resource",
3535 Finternal_set_lisp_face_attribute_from_resource
,
3536 Sinternal_set_lisp_face_attribute_from_resource
,
3537 3, 4, 0, doc
: /* */)
3538 (Lisp_Object face
, Lisp_Object attr
, Lisp_Object value
, Lisp_Object frame
)
3540 CHECK_SYMBOL (face
);
3541 CHECK_SYMBOL (attr
);
3542 CHECK_STRING (value
);
3544 if (xstrcasecmp (SDATA (value
), "unspecified") == 0)
3545 value
= Qunspecified
;
3546 else if (EQ (attr
, QCheight
))
3548 value
= Fstring_to_number (value
, make_number (10));
3549 if (XINT (value
) <= 0)
3550 signal_error ("Invalid face height from X resource", value
);
3552 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
3553 value
= face_boolean_x_resource_value (value
, 1);
3554 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
3555 value
= intern (SDATA (value
));
3556 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
3557 value
= face_boolean_x_resource_value (value
, 1);
3558 else if (EQ (attr
, QCunderline
)
3559 || EQ (attr
, QCoverline
)
3560 || EQ (attr
, QCstrike_through
))
3562 Lisp_Object boolean_value
;
3564 /* If the result of face_boolean_x_resource_value is t or nil,
3565 VALUE does NOT specify a color. */
3566 boolean_value
= face_boolean_x_resource_value (value
, 0);
3567 if (SYMBOLP (boolean_value
))
3568 value
= boolean_value
;
3570 else if (EQ (attr
, QCbox
) || EQ (attr
, QCinherit
))
3571 value
= Fcar (Fread_from_string (value
, Qnil
, Qnil
));
3573 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3576 #endif /* HAVE_WINDOW_SYSTEM */
3579 /***********************************************************************
3581 ***********************************************************************/
3583 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
3585 /* Make menus on frame F appear as specified by the `menu' face. */
3588 x_update_menu_appearance (struct frame
*f
)
3590 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3594 && (rdb
= XrmGetDatabase (FRAME_X_DISPLAY (f
)),
3598 Lisp_Object lface
= lface_from_face_name (f
, Qmenu
, 1);
3599 struct face
*face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
3600 const char *myname
= SDATA (Vx_resource_name
);
3603 const char *popup_path
= "popup_menu";
3605 const char *popup_path
= "menu.popup";
3608 if (STRINGP (LFACE_FOREGROUND (lface
)))
3610 sprintf (line
, "%s.%s*foreground: %s",
3612 SDATA (LFACE_FOREGROUND (lface
)));
3613 XrmPutLineResource (&rdb
, line
);
3614 sprintf (line
, "%s.pane.menubar*foreground: %s",
3615 myname
, SDATA (LFACE_FOREGROUND (lface
)));
3616 XrmPutLineResource (&rdb
, line
);
3620 if (STRINGP (LFACE_BACKGROUND (lface
)))
3622 sprintf (line
, "%s.%s*background: %s",
3624 SDATA (LFACE_BACKGROUND (lface
)));
3625 XrmPutLineResource (&rdb
, line
);
3626 sprintf (line
, "%s.pane.menubar*background: %s",
3627 myname
, SDATA (LFACE_BACKGROUND (lface
)));
3628 XrmPutLineResource (&rdb
, line
);
3633 /* On Solaris 5.8, it's been reported that the `menu' face
3634 can be unspecified here, during startup. Why this
3635 happens remains unknown. -- cyd */
3636 && FONTP (LFACE_FONT (lface
))
3637 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
3638 || !UNSPECIFIEDP (LFACE_FOUNDRY (lface
))
3639 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
3640 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3641 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
3642 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
3644 Lisp_Object xlfd
= Ffont_xlfd_name (LFACE_FONT (lface
), Qnil
);
3646 const char *suffix
= "List";
3649 #if defined HAVE_X_I18N
3651 const char *suffix
= "Set";
3653 const char *suffix
= "";
3660 #if defined HAVE_X_I18N
3661 char *fontsetname
= xic_create_fontsetname (SDATA (xlfd
), motif
);
3663 char *fontsetname
= (char *) SDATA (xlfd
);
3665 sprintf (line
, "%s.pane.menubar*font%s: %s",
3666 myname
, suffix
, fontsetname
);
3667 XrmPutLineResource (&rdb
, line
);
3668 sprintf (line
, "%s.%s*font%s: %s",
3669 myname
, popup_path
, suffix
, fontsetname
);
3670 XrmPutLineResource (&rdb
, line
);
3672 if (fontsetname
!= (char *) SDATA (xlfd
))
3673 xfree (fontsetname
);
3677 if (changed_p
&& f
->output_data
.x
->menubar_widget
)
3678 free_frame_menubar (f
);
3682 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
3685 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p
,
3686 Sface_attribute_relative_p
,
3688 doc
: /* Check whether a face attribute value is relative.
3689 Specifically, this function returns t if the attribute ATTRIBUTE
3690 with the value VALUE is relative.
3692 A relative value is one that doesn't entirely override whatever is
3693 inherited from another face. For most possible attributes,
3694 the only relative value that users see is `unspecified'.
3695 However, for :height, floating point values are also relative. */)
3696 (Lisp_Object attribute
, Lisp_Object value
)
3698 if (EQ (value
, Qunspecified
) || (EQ (value
, Qignore_defface
)))
3700 else if (EQ (attribute
, QCheight
))
3701 return INTEGERP (value
) ? Qnil
: Qt
;
3706 DEFUN ("merge-face-attribute", Fmerge_face_attribute
, Smerge_face_attribute
,
3708 doc
: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
3709 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
3710 the result will be absolute, otherwise it will be relative. */)
3711 (Lisp_Object attribute
, Lisp_Object value1
, Lisp_Object value2
)
3713 if (EQ (value1
, Qunspecified
) || EQ (value1
, Qignore_defface
))
3715 else if (EQ (attribute
, QCheight
))
3716 return merge_face_heights (value1
, value2
, value1
);
3722 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
3723 Sinternal_get_lisp_face_attribute
,
3725 doc
: /* Return face attribute KEYWORD of face SYMBOL.
3726 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
3727 face attribute name, signal an error.
3728 If the optional argument FRAME is given, report on face SYMBOL in that
3729 frame. If FRAME is t, report on the defaults for face SYMBOL (for new
3730 frames). If FRAME is omitted or nil, use the selected frame. */)
3731 (Lisp_Object symbol
, Lisp_Object keyword
, Lisp_Object frame
)
3733 Lisp_Object lface
, value
= Qnil
;
3735 CHECK_SYMBOL (symbol
);
3736 CHECK_SYMBOL (keyword
);
3739 lface
= lface_from_face_name (NULL
, symbol
, 1);
3743 frame
= selected_frame
;
3744 CHECK_LIVE_FRAME (frame
);
3745 lface
= lface_from_face_name (XFRAME (frame
), symbol
, 1);
3748 if (EQ (keyword
, QCfamily
))
3749 value
= LFACE_FAMILY (lface
);
3750 else if (EQ (keyword
, QCfoundry
))
3751 value
= LFACE_FOUNDRY (lface
);
3752 else if (EQ (keyword
, QCheight
))
3753 value
= LFACE_HEIGHT (lface
);
3754 else if (EQ (keyword
, QCweight
))
3755 value
= LFACE_WEIGHT (lface
);
3756 else if (EQ (keyword
, QCslant
))
3757 value
= LFACE_SLANT (lface
);
3758 else if (EQ (keyword
, QCunderline
))
3759 value
= LFACE_UNDERLINE (lface
);
3760 else if (EQ (keyword
, QCoverline
))
3761 value
= LFACE_OVERLINE (lface
);
3762 else if (EQ (keyword
, QCstrike_through
))
3763 value
= LFACE_STRIKE_THROUGH (lface
);
3764 else if (EQ (keyword
, QCbox
))
3765 value
= LFACE_BOX (lface
);
3766 else if (EQ (keyword
, QCinverse_video
)
3767 || EQ (keyword
, QCreverse_video
))
3768 value
= LFACE_INVERSE (lface
);
3769 else if (EQ (keyword
, QCforeground
))
3770 value
= LFACE_FOREGROUND (lface
);
3771 else if (EQ (keyword
, QCbackground
))
3772 value
= LFACE_BACKGROUND (lface
);
3773 else if (EQ (keyword
, QCstipple
))
3774 value
= LFACE_STIPPLE (lface
);
3775 else if (EQ (keyword
, QCwidth
))
3776 value
= LFACE_SWIDTH (lface
);
3777 else if (EQ (keyword
, QCinherit
))
3778 value
= LFACE_INHERIT (lface
);
3779 else if (EQ (keyword
, QCfont
))
3780 value
= LFACE_FONT (lface
);
3781 else if (EQ (keyword
, QCfontset
))
3782 value
= LFACE_FONTSET (lface
);
3784 signal_error ("Invalid face attribute name", keyword
);
3786 if (IGNORE_DEFFACE_P (value
))
3787 return Qunspecified
;
3793 DEFUN ("internal-lisp-face-attribute-values",
3794 Finternal_lisp_face_attribute_values
,
3795 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
3796 doc
: /* Return a list of valid discrete values for face attribute ATTR.
3797 Value is nil if ATTR doesn't have a discrete set of valid values. */)
3800 Lisp_Object result
= Qnil
;
3802 CHECK_SYMBOL (attr
);
3804 if (EQ (attr
, QCunderline
))
3805 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3806 else if (EQ (attr
, QCoverline
))
3807 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3808 else if (EQ (attr
, QCstrike_through
))
3809 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3810 else if (EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
3811 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3817 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
3818 Sinternal_merge_in_global_face
, 2, 2, 0,
3819 doc
: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
3820 Default face attributes override any local face attributes. */)
3821 (Lisp_Object face
, Lisp_Object frame
)
3824 Lisp_Object global_lface
, local_lface
, *gvec
, *lvec
;
3825 struct frame
*f
= XFRAME (frame
);
3827 CHECK_LIVE_FRAME (frame
);
3828 global_lface
= lface_from_face_name (NULL
, face
, 1);
3829 local_lface
= lface_from_face_name (f
, face
, 0);
3830 if (NILP (local_lface
))
3831 local_lface
= Finternal_make_lisp_face (face
, frame
);
3833 /* Make every specified global attribute override the local one.
3834 BEWARE!! This is only used from `face-set-after-frame-default' where
3835 the local frame is defined from default specs in `face-defface-spec'
3836 and those should be overridden by global settings. Hence the strange
3837 "global before local" priority. */
3838 lvec
= XVECTOR (local_lface
)->contents
;
3839 gvec
= XVECTOR (global_lface
)->contents
;
3840 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3841 if (IGNORE_DEFFACE_P (gvec
[i
]))
3842 lvec
[i
] = Qunspecified
;
3843 else if (! UNSPECIFIEDP (gvec
[i
]))
3846 /* If the default face was changed, update the face cache and the
3847 `font' frame parameter. */
3848 if (EQ (face
, Qdefault
))
3850 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
3851 struct face
*newface
, *oldface
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
3852 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
3854 /* This can be NULL (e.g., in batch mode). */
3857 /* Ensure that the face vector is fully specified by merging
3858 the previously-cached vector. */
3859 memcpy (attrs
, oldface
->lface
, sizeof attrs
);
3860 merge_face_vectors (f
, lvec
, attrs
, 0);
3861 memcpy (lvec
, attrs
, sizeof attrs
);
3862 newface
= realize_face (c
, lvec
, DEFAULT_FACE_ID
);
3864 if ((! UNSPECIFIEDP (gvec
[LFACE_FAMILY_INDEX
])
3865 || ! UNSPECIFIEDP (gvec
[LFACE_FOUNDRY_INDEX
])
3866 || ! UNSPECIFIEDP (gvec
[LFACE_HEIGHT_INDEX
])
3867 || ! UNSPECIFIEDP (gvec
[LFACE_WEIGHT_INDEX
])
3868 || ! UNSPECIFIEDP (gvec
[LFACE_SLANT_INDEX
])
3869 || ! UNSPECIFIEDP (gvec
[LFACE_SWIDTH_INDEX
])
3870 || ! UNSPECIFIEDP (gvec
[LFACE_FONT_INDEX
]))
3873 Lisp_Object name
= newface
->font
->props
[FONT_NAME_INDEX
];
3874 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, name
),
3884 /* The following function is implemented for compatibility with 20.2.
3885 The function is used in x-resolve-fonts when it is asked to
3886 return fonts with the same size as the font of a face. This is
3887 done in fontset.el. */
3889 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 3, 0,
3890 doc
: /* Return the font name of face FACE, or nil if it is unspecified.
3891 The font name is, by default, for ASCII characters.
3892 If the optional argument FRAME is given, report on face FACE in that frame.
3893 If FRAME is t, report on the defaults for face FACE (for new frames).
3894 The font default for a face is either nil, or a list
3895 of the form (bold), (italic) or (bold italic).
3896 If FRAME is omitted or nil, use the selected frame. And, in this case,
3897 if the optional third argument CHARACTER is given,
3898 return the font name used for CHARACTER. */)
3899 (Lisp_Object face
, Lisp_Object frame
, Lisp_Object character
)
3903 Lisp_Object result
= Qnil
;
3904 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
3906 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3907 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
3908 result
= Fcons (Qbold
, result
);
3910 if (!UNSPECIFIEDP (LFACE_SLANT (lface
))
3911 && !EQ (LFACE_SLANT (lface
), Qnormal
))
3912 result
= Fcons (Qitalic
, result
);
3918 struct frame
*f
= frame_or_selected_frame (frame
, 1);
3919 int face_id
= lookup_named_face (f
, face
, 1);
3920 struct face
*face
= FACE_FROM_ID (f
, face_id
);
3924 #ifdef HAVE_WINDOW_SYSTEM
3925 if (FRAME_WINDOW_P (f
) && !NILP (character
))
3927 CHECK_CHARACTER (character
);
3928 face_id
= FACE_FOR_CHAR (f
, face
, XINT (character
), -1, Qnil
);
3929 face
= FACE_FROM_ID (f
, face_id
);
3932 ? face
->font
->props
[FONT_NAME_INDEX
]
3934 #else /* !HAVE_WINDOW_SYSTEM */
3935 return build_string (FRAME_MSDOS_P (f
)
3937 : FRAME_W32_P (f
) ? "w32term"
3944 /* Compare face-attribute values v1 and v2 for equality. Value is non-zero if
3945 all attributes are `equal'. Tries to be fast because this function
3946 is called quite often. */
3949 face_attr_equal_p (Lisp_Object v1
, Lisp_Object v2
)
3951 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
3952 and the other is specified. */
3953 if (XTYPE (v1
) != XTYPE (v2
))
3962 if (SBYTES (v1
) != SBYTES (v2
))
3965 return memcmp (SDATA (v1
), SDATA (v2
), SBYTES (v1
)) == 0;
3972 return !NILP (Fequal (v1
, v2
));
3977 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
3978 all attributes are `equal'. Tries to be fast because this function
3979 is called quite often. */
3982 lface_equal_p (Lisp_Object
*v1
, Lisp_Object
*v2
)
3986 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
3987 equal_p
= face_attr_equal_p (v1
[i
], v2
[i
]);
3993 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
3994 Sinternal_lisp_face_equal_p
, 2, 3, 0,
3995 doc
: /* True if FACE1 and FACE2 are equal.
3996 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
3997 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
3998 If FRAME is omitted or nil, use the selected frame. */)
3999 (Lisp_Object face1
, Lisp_Object face2
, Lisp_Object frame
)
4003 Lisp_Object lface1
, lface2
;
4008 /* Don't use check_x_frame here because this function is called
4009 before X frames exist. At that time, if FRAME is nil,
4010 selected_frame will be used which is the frame dumped with
4011 Emacs. That frame is not an X frame. */
4012 f
= frame_or_selected_frame (frame
, 2);
4014 lface1
= lface_from_face_name (f
, face1
, 1);
4015 lface2
= lface_from_face_name (f
, face2
, 1);
4016 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
4017 XVECTOR (lface2
)->contents
);
4018 return equal_p
? Qt
: Qnil
;
4022 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
4023 Sinternal_lisp_face_empty_p
, 1, 2, 0,
4024 doc
: /* True if FACE has no attribute specified.
4025 If the optional argument FRAME is given, report on face FACE in that frame.
4026 If FRAME is t, report on the defaults for face FACE (for new frames).
4027 If FRAME is omitted or nil, use the selected frame. */)
4028 (Lisp_Object face
, Lisp_Object frame
)
4035 frame
= selected_frame
;
4036 CHECK_LIVE_FRAME (frame
);
4040 lface
= lface_from_face_name (NULL
, face
, 1);
4042 lface
= lface_from_face_name (f
, face
, 1);
4044 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4045 if (!UNSPECIFIEDP (AREF (lface
, i
)))
4048 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
4052 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
4054 doc
: /* Return an alist of frame-local faces defined on FRAME.
4055 For internal use only. */)
4058 struct frame
*f
= frame_or_selected_frame (frame
, 0);
4059 return f
->face_alist
;
4063 /* Return a hash code for Lisp string STRING with case ignored. Used
4064 below in computing a hash value for a Lisp face. */
4066 static INLINE
unsigned
4067 hash_string_case_insensitive (Lisp_Object string
)
4069 const unsigned char *s
;
4071 xassert (STRINGP (string
));
4072 for (s
= SDATA (string
); *s
; ++s
)
4073 hash
= (hash
<< 1) ^ tolower (*s
);
4078 /* Return a hash code for face attribute vector V. */
4080 static INLINE
unsigned
4081 lface_hash (Lisp_Object
*v
)
4083 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
4084 ^ hash_string_case_insensitive (v
[LFACE_FOUNDRY_INDEX
])
4085 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
4086 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
4087 ^ XHASH (v
[LFACE_WEIGHT_INDEX
])
4088 ^ XHASH (v
[LFACE_SLANT_INDEX
])
4089 ^ XHASH (v
[LFACE_SWIDTH_INDEX
])
4090 ^ XHASH (v
[LFACE_HEIGHT_INDEX
]));
4094 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
4095 considering charsets/registries). They do if they specify the same
4096 family, point size, weight, width, slant, and font. Both
4097 LFACE1 and LFACE2 must be fully-specified. */
4100 lface_same_font_attributes_p (Lisp_Object
*lface1
, Lisp_Object
*lface2
)
4102 xassert (lface_fully_specified_p (lface1
)
4103 && lface_fully_specified_p (lface2
));
4104 return (xstrcasecmp (SDATA (lface1
[LFACE_FAMILY_INDEX
]),
4105 SDATA (lface2
[LFACE_FAMILY_INDEX
])) == 0
4106 && xstrcasecmp (SDATA (lface1
[LFACE_FOUNDRY_INDEX
]),
4107 SDATA (lface2
[LFACE_FOUNDRY_INDEX
])) == 0
4108 && EQ (lface1
[LFACE_HEIGHT_INDEX
], lface2
[LFACE_HEIGHT_INDEX
])
4109 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
4110 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
4111 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
])
4112 && EQ (lface1
[LFACE_FONT_INDEX
], lface2
[LFACE_FONT_INDEX
])
4113 && (EQ (lface1
[LFACE_FONTSET_INDEX
], lface2
[LFACE_FONTSET_INDEX
])
4114 || (STRINGP (lface1
[LFACE_FONTSET_INDEX
])
4115 && STRINGP (lface2
[LFACE_FONTSET_INDEX
])
4116 && ! xstrcasecmp (SDATA (lface1
[LFACE_FONTSET_INDEX
]),
4117 SDATA (lface2
[LFACE_FONTSET_INDEX
]))))
4123 /***********************************************************************
4125 ***********************************************************************/
4127 /* Allocate and return a new realized face for Lisp face attribute
4130 static struct face
*
4131 make_realized_face (Lisp_Object
*attr
)
4133 struct face
*face
= (struct face
*) xmalloc (sizeof *face
);
4134 memset (face
, 0, sizeof *face
);
4135 face
->ascii_face
= face
;
4136 memcpy (face
->lface
, attr
, sizeof face
->lface
);
4141 /* Free realized face FACE, including its X resources. FACE may
4145 free_realized_face (struct frame
*f
, struct face
*face
)
4149 #ifdef HAVE_WINDOW_SYSTEM
4150 if (FRAME_WINDOW_P (f
))
4152 /* Free fontset of FACE if it is ASCII face. */
4153 if (face
->fontset
>= 0 && face
== face
->ascii_face
)
4154 free_face_fontset (f
, face
);
4159 font_done_for_face (f
, face
);
4160 x_free_gc (f
, face
->gc
);
4165 free_face_colors (f
, face
);
4166 x_destroy_bitmap (f
, face
->stipple
);
4168 #endif /* HAVE_WINDOW_SYSTEM */
4175 /* Prepare face FACE for subsequent display on frame F. This
4176 allocated GCs if they haven't been allocated yet or have been freed
4177 by clearing the face cache. */
4180 prepare_face_for_display (struct frame
*f
, struct face
*face
)
4182 #ifdef HAVE_WINDOW_SYSTEM
4183 xassert (FRAME_WINDOW_P (f
));
4188 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
4190 xgcv
.foreground
= face
->foreground
;
4191 xgcv
.background
= face
->background
;
4192 #ifdef HAVE_X_WINDOWS
4193 xgcv
.graphics_exposures
= False
;
4197 #ifdef HAVE_X_WINDOWS
4200 xgcv
.fill_style
= FillOpaqueStippled
;
4201 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
4202 mask
|= GCFillStyle
| GCStipple
;
4205 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
4207 font_prepare_for_face (f
, face
);
4210 #endif /* HAVE_WINDOW_SYSTEM */
4214 /* Returns the `distance' between the colors X and Y. */
4217 color_distance (XColor
*x
, XColor
*y
)
4219 /* This formula is from a paper title `Colour metric' by Thiadmer Riemersma.
4220 Quoting from that paper:
4222 This formula has results that are very close to L*u*v* (with the
4223 modified lightness curve) and, more importantly, it is a more even
4224 algorithm: it does not have a range of colours where it suddenly
4225 gives far from optimal results.
4227 See <http://www.compuphase.com/cmetric.htm> for more info. */
4229 long r
= (x
->red
- y
->red
) >> 8;
4230 long g
= (x
->green
- y
->green
) >> 8;
4231 long b
= (x
->blue
- y
->blue
) >> 8;
4232 long r_mean
= (x
->red
+ y
->red
) >> 9;
4235 (((512 + r_mean
) * r
* r
) >> 8)
4237 + (((767 - r_mean
) * b
* b
) >> 8);
4241 DEFUN ("color-distance", Fcolor_distance
, Scolor_distance
, 2, 3, 0,
4242 doc
: /* Return an integer distance between COLOR1 and COLOR2 on FRAME.
4243 COLOR1 and COLOR2 may be either strings containing the color name,
4244 or lists of the form (RED GREEN BLUE).
4245 If FRAME is unspecified or nil, the current frame is used. */)
4246 (Lisp_Object color1
, Lisp_Object color2
, Lisp_Object frame
)
4249 XColor cdef1
, cdef2
;
4252 frame
= selected_frame
;
4253 CHECK_LIVE_FRAME (frame
);
4256 if (!(CONSP (color1
) && parse_rgb_list (color1
, &cdef1
))
4257 && !(STRINGP (color1
) && defined_color (f
, SDATA (color1
), &cdef1
, 0)))
4258 signal_error ("Invalid color", color1
);
4259 if (!(CONSP (color2
) && parse_rgb_list (color2
, &cdef2
))
4260 && !(STRINGP (color2
) && defined_color (f
, SDATA (color2
), &cdef2
, 0)))
4261 signal_error ("Invalid color", color2
);
4263 return make_number (color_distance (&cdef1
, &cdef2
));
4267 /***********************************************************************
4269 ***********************************************************************/
4271 /* Return a new face cache for frame F. */
4273 static struct face_cache
*
4274 make_face_cache (struct frame
*f
)
4276 struct face_cache
*c
;
4279 c
= (struct face_cache
*) xmalloc (sizeof *c
);
4280 memset (c
, 0, sizeof *c
);
4281 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4282 c
->buckets
= (struct face
**) xmalloc (size
);
4283 memset (c
->buckets
, 0, size
);
4285 c
->faces_by_id
= (struct face
**) xmalloc (c
->size
* sizeof *c
->faces_by_id
);
4287 c
->menu_face_changed_p
= menu_face_changed_default
;
4292 /* Clear out all graphics contexts for all realized faces, except for
4293 the basic faces. This should be done from time to time just to avoid
4294 keeping too many graphics contexts that are no longer needed. */
4297 clear_face_gcs (struct face_cache
*c
)
4299 if (c
&& FRAME_WINDOW_P (c
->f
))
4301 #ifdef HAVE_WINDOW_SYSTEM
4303 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
4305 struct face
*face
= c
->faces_by_id
[i
];
4306 if (face
&& face
->gc
)
4310 font_done_for_face (c
->f
, face
);
4311 x_free_gc (c
->f
, face
->gc
);
4316 #endif /* HAVE_WINDOW_SYSTEM */
4321 /* Free all realized faces in face cache C, including basic faces.
4322 C may be null. If faces are freed, make sure the frame's current
4323 matrix is marked invalid, so that a display caused by an expose
4324 event doesn't try to use faces we destroyed. */
4327 free_realized_faces (struct face_cache
*c
)
4332 struct frame
*f
= c
->f
;
4334 /* We must block input here because we can't process X events
4335 safely while only some faces are freed, or when the frame's
4336 current matrix still references freed faces. */
4339 for (i
= 0; i
< c
->used
; ++i
)
4341 free_realized_face (f
, c
->faces_by_id
[i
]);
4342 c
->faces_by_id
[i
] = NULL
;
4346 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4347 memset (c
->buckets
, 0, size
);
4349 /* Must do a thorough redisplay the next time. Mark current
4350 matrices as invalid because they will reference faces freed
4351 above. This function is also called when a frame is
4352 destroyed. In this case, the root window of F is nil. */
4353 if (WINDOWP (f
->root_window
))
4355 clear_current_matrices (f
);
4356 ++windows_or_buffers_changed
;
4364 /* Free all realized faces that are using FONTSET on frame F. */
4367 free_realized_faces_for_fontset (struct frame
*f
, int fontset
)
4369 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4373 /* We must block input here because we can't process X events safely
4374 while only some faces are freed, or when the frame's current
4375 matrix still references freed faces. */
4378 for (i
= 0; i
< cache
->used
; i
++)
4380 face
= cache
->faces_by_id
[i
];
4382 && face
->fontset
== fontset
)
4384 uncache_face (cache
, face
);
4385 free_realized_face (f
, face
);
4389 /* Must do a thorough redisplay the next time. Mark current
4390 matrices as invalid because they will reference faces freed
4391 above. This function is also called when a frame is destroyed.
4392 In this case, the root window of F is nil. */
4393 if (WINDOWP (f
->root_window
))
4395 clear_current_matrices (f
);
4396 ++windows_or_buffers_changed
;
4403 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
4404 This is done after attributes of a named face have been changed,
4405 because we can't tell which realized faces depend on that face. */
4408 free_all_realized_faces (Lisp_Object frame
)
4413 FOR_EACH_FRAME (rest
, frame
)
4414 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4417 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4421 /* Free face cache C and faces in it, including their X resources. */
4424 free_face_cache (struct face_cache
*c
)
4428 free_realized_faces (c
);
4430 xfree (c
->faces_by_id
);
4436 /* Cache realized face FACE in face cache C. HASH is the hash value
4437 of FACE. If FACE is for ASCII characters (i.e. FACE->ascii_face ==
4438 FACE), insert the new face to the beginning of the collision list
4439 of the face hash table of C. Otherwise, add the new face to the
4440 end of the collision list. This way, lookup_face can quickly find
4441 that a requested face is not cached. */
4444 cache_face (struct face_cache
*c
, struct face
*face
, unsigned int hash
)
4446 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4450 if (face
->ascii_face
!= face
)
4452 struct face
*last
= c
->buckets
[i
];
4463 c
->buckets
[i
] = face
;
4464 face
->prev
= face
->next
= NULL
;
4470 face
->next
= c
->buckets
[i
];
4472 face
->next
->prev
= face
;
4473 c
->buckets
[i
] = face
;
4476 /* Find a free slot in C->faces_by_id and use the index of the free
4477 slot as FACE->id. */
4478 for (i
= 0; i
< c
->used
; ++i
)
4479 if (c
->faces_by_id
[i
] == NULL
)
4483 /* Maybe enlarge C->faces_by_id. */
4486 if (c
->used
== c
->size
)
4489 new_size
= min (2 * c
->size
, MAX_FACE_ID
);
4490 if (new_size
== c
->size
)
4491 abort (); /* Alternatives? ++kfs */
4492 sz
= new_size
* sizeof *c
->faces_by_id
;
4493 c
->faces_by_id
= (struct face
**) xrealloc (c
->faces_by_id
, sz
);
4500 /* Check that FACE got a unique id. */
4505 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
4506 for (face
= c
->buckets
[j
]; face
; face
= face
->next
)
4512 #endif /* GLYPH_DEBUG */
4514 c
->faces_by_id
[i
] = face
;
4518 /* Remove face FACE from cache C. */
4521 uncache_face (struct face_cache
*c
, struct face
*face
)
4523 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
4526 face
->prev
->next
= face
->next
;
4528 c
->buckets
[i
] = face
->next
;
4531 face
->next
->prev
= face
->prev
;
4533 c
->faces_by_id
[face
->id
] = NULL
;
4534 if (face
->id
== c
->used
)
4539 /* Look up a realized face with face attributes ATTR in the face cache
4540 of frame F. The face will be used to display ASCII characters.
4541 Value is the ID of the face found. If no suitable face is found,
4542 realize a new one. */
4545 lookup_face (struct frame
*f
, Lisp_Object
*attr
)
4547 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4552 xassert (cache
!= NULL
);
4553 check_lface_attrs (attr
);
4555 /* Look up ATTR in the face cache. */
4556 hash
= lface_hash (attr
);
4557 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4559 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4561 if (face
->ascii_face
!= face
)
4563 /* There's no more ASCII face. */
4567 if (face
->hash
== hash
4568 && lface_equal_p (face
->lface
, attr
))
4572 /* If not found, realize a new face. */
4574 face
= realize_face (cache
, attr
, -1);
4577 xassert (face
== FACE_FROM_ID (f
, face
->id
));
4578 #endif /* GLYPH_DEBUG */
4583 #ifdef HAVE_WINDOW_SYSTEM
4584 /* Look up a realized face that has the same attributes as BASE_FACE
4585 except for the font in the face cache of frame F. If FONT-OBJECT
4586 is not nil, it is an already opened font. If FONT-OBJECT is nil,
4587 the face has no font. Value is the ID of the face found. If no
4588 suitable face is found, realize a new one. */
4591 face_for_font (struct frame
*f
, Lisp_Object font_object
, struct face
*base_face
)
4593 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4598 xassert (cache
!= NULL
);
4599 base_face
= base_face
->ascii_face
;
4600 hash
= lface_hash (base_face
->lface
);
4601 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4603 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4605 if (face
->ascii_face
== face
)
4607 if (face
->ascii_face
== base_face
4608 && face
->font
== (NILP (font_object
) ? NULL
4609 : XFONT_OBJECT (font_object
))
4610 && lface_equal_p (face
->lface
, base_face
->lface
))
4614 /* If not found, realize a new face. */
4615 face
= realize_non_ascii_face (f
, font_object
, base_face
);
4618 #endif /* HAVE_WINDOW_SYSTEM */
4620 /* Return the face id of the realized face for named face SYMBOL on
4621 frame F suitable for displaying ASCII characters. Value is -1 if
4622 the face couldn't be determined, which might happen if the default
4623 face isn't realized and cannot be realized. */
4626 lookup_named_face (struct frame
*f
, Lisp_Object symbol
, int signal_p
)
4628 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4629 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4630 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4632 if (default_face
== NULL
)
4634 if (!realize_basic_faces (f
))
4636 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4637 if (default_face
== NULL
)
4638 abort (); /* realize_basic_faces must have set it up */
4641 if (! get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4644 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4645 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4647 return lookup_face (f
, attrs
);
4651 /* Return the display face-id of the basic face who's canonical face-id
4652 is FACE_ID. The return value will usually simply be FACE_ID, unless that
4653 basic face has bee remapped via Vface_remapping_alist. This function is
4654 conservative: if something goes wrong, it will simply return FACE_ID
4655 rather than signal an error. */
4658 lookup_basic_face (struct frame
*f
, int face_id
)
4660 Lisp_Object name
, mapping
;
4661 int remapped_face_id
;
4663 if (NILP (Vface_remapping_alist
))
4664 return face_id
; /* Nothing to do. */
4668 case DEFAULT_FACE_ID
: name
= Qdefault
; break;
4669 case MODE_LINE_FACE_ID
: name
= Qmode_line
; break;
4670 case MODE_LINE_INACTIVE_FACE_ID
: name
= Qmode_line_inactive
; break;
4671 case HEADER_LINE_FACE_ID
: name
= Qheader_line
; break;
4672 case TOOL_BAR_FACE_ID
: name
= Qtool_bar
; break;
4673 case FRINGE_FACE_ID
: name
= Qfringe
; break;
4674 case SCROLL_BAR_FACE_ID
: name
= Qscroll_bar
; break;
4675 case BORDER_FACE_ID
: name
= Qborder
; break;
4676 case CURSOR_FACE_ID
: name
= Qcursor
; break;
4677 case MOUSE_FACE_ID
: name
= Qmouse
; break;
4678 case MENU_FACE_ID
: name
= Qmenu
; break;
4681 abort (); /* the caller is supposed to pass us a basic face id */
4684 /* Do a quick scan through Vface_remapping_alist, and return immediately
4685 if there is no remapping for face NAME. This is just an optimization
4686 for the very common no-remapping case. */
4687 mapping
= assq_no_quit (name
, Vface_remapping_alist
);
4689 return face_id
; /* Give up. */
4691 /* If there is a remapping entry, lookup the face using NAME, which will
4692 handle the remapping too. */
4693 remapped_face_id
= lookup_named_face (f
, name
, 0);
4694 if (remapped_face_id
< 0)
4695 return face_id
; /* Give up. */
4697 return remapped_face_id
;
4701 /* Return the ID of the realized ASCII face of Lisp face with ID
4702 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
4705 ascii_face_of_lisp_face (struct frame
*f
, int lface_id
)
4709 if (lface_id
>= 0 && lface_id
< lface_id_to_name_size
)
4711 Lisp_Object face_name
= lface_id_to_name
[lface_id
];
4712 face_id
= lookup_named_face (f
, face_name
, 1);
4721 /* Return a face for charset ASCII that is like the face with id
4722 FACE_ID on frame F, but has a font that is STEPS steps smaller.
4723 STEPS < 0 means larger. Value is the id of the face. */
4726 smaller_face (struct frame
*f
, int face_id
, int steps
)
4728 #ifdef HAVE_WINDOW_SYSTEM
4730 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4731 int pt
, last_pt
, last_height
;
4734 struct face
*new_face
;
4736 /* If not called for an X frame, just return the original face. */
4737 if (FRAME_TERMCAP_P (f
))
4740 /* Try in increments of 1/2 pt. */
4741 delta
= steps
< 0 ? 5 : -5;
4742 steps
= eabs (steps
);
4744 face
= FACE_FROM_ID (f
, face_id
);
4745 memcpy (attrs
, face
->lface
, sizeof attrs
);
4746 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
4747 new_face_id
= face_id
;
4748 last_height
= FONT_HEIGHT (face
->font
);
4752 /* Give up if we cannot find a font within 10pt. */
4753 && eabs (last_pt
- pt
) < 100)
4755 /* Look up a face for a slightly smaller/larger font. */
4757 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
4758 new_face_id
= lookup_face (f
, attrs
);
4759 new_face
= FACE_FROM_ID (f
, new_face_id
);
4761 /* If height changes, count that as one step. */
4762 if ((delta
< 0 && FONT_HEIGHT (new_face
->font
) < last_height
)
4763 || (delta
> 0 && FONT_HEIGHT (new_face
->font
) > last_height
))
4766 last_height
= FONT_HEIGHT (new_face
->font
);
4773 #else /* not HAVE_WINDOW_SYSTEM */
4777 #endif /* not HAVE_WINDOW_SYSTEM */
4781 /* Return a face for charset ASCII that is like the face with id
4782 FACE_ID on frame F, but has height HEIGHT. */
4785 face_with_height (struct frame
*f
, int face_id
, int height
)
4787 #ifdef HAVE_WINDOW_SYSTEM
4789 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4791 if (FRAME_TERMCAP_P (f
)
4795 face
= FACE_FROM_ID (f
, face_id
);
4796 memcpy (attrs
, face
->lface
, sizeof attrs
);
4797 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
4798 font_clear_prop (attrs
, FONT_SIZE_INDEX
);
4799 face_id
= lookup_face (f
, attrs
);
4800 #endif /* HAVE_WINDOW_SYSTEM */
4806 /* Return the face id of the realized face for named face SYMBOL on
4807 frame F suitable for displaying ASCII characters, and use
4808 attributes of the face FACE_ID for attributes that aren't
4809 completely specified by SYMBOL. This is like lookup_named_face,
4810 except that the default attributes come from FACE_ID, not from the
4811 default face. FACE_ID is assumed to be already realized. */
4814 lookup_derived_face (struct frame
*f
, Lisp_Object symbol
, int face_id
, int signal_p
)
4816 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4817 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4818 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
4823 if (!get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4826 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4827 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4828 return lookup_face (f
, attrs
);
4831 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector
,
4832 Sface_attributes_as_vector
, 1, 1, 0,
4833 doc
: /* Return a vector of face attributes corresponding to PLIST. */)
4837 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
4839 merge_face_ref (XFRAME (selected_frame
), plist
, XVECTOR (lface
)->contents
,
4846 /***********************************************************************
4847 Face capability testing
4848 ***********************************************************************/
4851 /* If the distance (as returned by color_distance) between two colors is
4852 less than this, then they are considered the same, for determining
4853 whether a color is supported or not. The range of values is 0-65535. */
4855 #define TTY_SAME_COLOR_THRESHOLD 10000
4857 #ifdef HAVE_WINDOW_SYSTEM
4859 /* Return non-zero if all the face attributes in ATTRS are supported
4860 on the window-system frame F.
4862 The definition of `supported' is somewhat heuristic, but basically means
4863 that a face containing all the attributes in ATTRS, when merged with the
4864 default face for display, can be represented in a way that's
4866 \(1) different in appearance than the default face, and
4867 \(2) `close in spirit' to what the attributes specify, if not exact. */
4870 x_supports_face_attributes_p (struct frame
*f
, Lisp_Object
*attrs
, struct face
*def_face
)
4872 Lisp_Object
*def_attrs
= def_face
->lface
;
4874 /* Check that other specified attributes are different that the default
4876 if ((!UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
4877 && face_attr_equal_p (attrs
[LFACE_UNDERLINE_INDEX
],
4878 def_attrs
[LFACE_UNDERLINE_INDEX
]))
4879 || (!UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
4880 && face_attr_equal_p (attrs
[LFACE_INVERSE_INDEX
],
4881 def_attrs
[LFACE_INVERSE_INDEX
]))
4882 || (!UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
4883 && face_attr_equal_p (attrs
[LFACE_FOREGROUND_INDEX
],
4884 def_attrs
[LFACE_FOREGROUND_INDEX
]))
4885 || (!UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
4886 && face_attr_equal_p (attrs
[LFACE_BACKGROUND_INDEX
],
4887 def_attrs
[LFACE_BACKGROUND_INDEX
]))
4888 || (!UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
4889 && face_attr_equal_p (attrs
[LFACE_STIPPLE_INDEX
],
4890 def_attrs
[LFACE_STIPPLE_INDEX
]))
4891 || (!UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
4892 && face_attr_equal_p (attrs
[LFACE_OVERLINE_INDEX
],
4893 def_attrs
[LFACE_OVERLINE_INDEX
]))
4894 || (!UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
4895 && face_attr_equal_p (attrs
[LFACE_STRIKE_THROUGH_INDEX
],
4896 def_attrs
[LFACE_STRIKE_THROUGH_INDEX
]))
4897 || (!UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
4898 && face_attr_equal_p (attrs
[LFACE_BOX_INDEX
],
4899 def_attrs
[LFACE_BOX_INDEX
])))
4902 /* Check font-related attributes, as those are the most commonly
4903 "unsupported" on a window-system (because of missing fonts). */
4904 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
4905 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
4906 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
4907 || !UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
4908 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
4909 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
]))
4913 Lisp_Object merged_attrs
[LFACE_VECTOR_SIZE
];
4916 memcpy (merged_attrs
, def_attrs
, sizeof merged_attrs
);
4918 merge_face_vectors (f
, attrs
, merged_attrs
, 0);
4920 face_id
= lookup_face (f
, merged_attrs
);
4921 face
= FACE_FROM_ID (f
, face_id
);
4924 error ("Cannot make face");
4926 /* If the font is the same, or no font is found, then not
4928 if (face
->font
== def_face
->font
4931 for (i
= FONT_TYPE_INDEX
; i
<= FONT_SIZE_INDEX
; i
++)
4932 if (! EQ (face
->font
->props
[i
], def_face
->font
->props
[i
]))
4936 if (i
< FONT_FOUNDRY_INDEX
|| i
> FONT_REGISTRY_INDEX
4937 || face
->font
->driver
->case_sensitive
)
4939 s1
= SYMBOL_NAME (face
->font
->props
[i
]);
4940 s2
= SYMBOL_NAME (def_face
->font
->props
[i
]);
4941 if (! EQ (Fcompare_strings (s1
, make_number (0), Qnil
,
4942 s2
, make_number (0), Qnil
, Qt
), Qt
))
4948 /* Everything checks out, this face is supported. */
4952 #endif /* HAVE_WINDOW_SYSTEM */
4954 /* Return non-zero if all the face attributes in ATTRS are supported
4957 The definition of `supported' is somewhat heuristic, but basically means
4958 that a face containing all the attributes in ATTRS, when merged
4959 with the default face for display, can be represented in a way that's
4961 \(1) different in appearance than the default face, and
4962 \(2) `close in spirit' to what the attributes specify, if not exact.
4964 Point (2) implies that a `:weight black' attribute will be satisfied
4965 by any terminal that can display bold, and a `:foreground "yellow"' as
4966 long as the terminal can display a yellowish color, but `:slant italic'
4967 will _not_ be satisfied by the tty display code's automatic
4968 substitution of a `dim' face for italic. */
4971 tty_supports_face_attributes_p (struct frame
*f
, Lisp_Object
*attrs
, struct face
*def_face
)
4974 Lisp_Object val
, fg
, bg
;
4975 XColor fg_tty_color
, fg_std_color
;
4976 XColor bg_tty_color
, bg_std_color
;
4977 unsigned test_caps
= 0;
4978 Lisp_Object
*def_attrs
= def_face
->lface
;
4981 /* First check some easy-to-check stuff; ttys support none of the
4982 following attributes, so we can just return false if any are requested
4983 (even if `nominal' values are specified, we should still return false,
4984 as that will be the same value that the default face uses). We
4985 consider :slant unsupportable on ttys, even though the face code
4986 actually `fakes' them using a dim attribute if possible. This is
4987 because the faked result is too different from what the face
4989 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
4990 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
4991 || !UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
4992 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
4993 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
4994 || !UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
4995 || !UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
4996 || !UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
4997 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
]))
5001 /* Test for terminal `capabilities' (non-color character attributes). */
5003 /* font weight (bold/dim) */
5004 val
= attrs
[LFACE_WEIGHT_INDEX
];
5005 if (!UNSPECIFIEDP (val
)
5006 && (weight
= FONT_WEIGHT_NAME_NUMERIC (val
), weight
>= 0))
5008 int def_weight
= FONT_WEIGHT_NAME_NUMERIC (def_attrs
[LFACE_WEIGHT_INDEX
]);
5012 if (def_weight
> 100)
5013 return 0; /* same as default */
5014 test_caps
= TTY_CAP_BOLD
;
5016 else if (weight
< 100)
5018 if (def_weight
< 100)
5019 return 0; /* same as default */
5020 test_caps
= TTY_CAP_DIM
;
5022 else if (def_weight
== 100)
5023 return 0; /* same as default */
5027 val
= attrs
[LFACE_UNDERLINE_INDEX
];
5028 if (!UNSPECIFIEDP (val
))
5031 return 0; /* ttys can't use colored underlines */
5032 else if (face_attr_equal_p (val
, def_attrs
[LFACE_UNDERLINE_INDEX
]))
5033 return 0; /* same as default */
5035 test_caps
|= TTY_CAP_UNDERLINE
;
5039 val
= attrs
[LFACE_INVERSE_INDEX
];
5040 if (!UNSPECIFIEDP (val
))
5042 if (face_attr_equal_p (val
, def_attrs
[LFACE_INVERSE_INDEX
]))
5043 return 0; /* same as default */
5045 test_caps
|= TTY_CAP_INVERSE
;
5049 /* Color testing. */
5051 /* Default the color indices in FG_TTY_COLOR and BG_TTY_COLOR, since
5052 we use them when calling `tty_capable_p' below, even if the face
5053 specifies no colors. */
5054 fg_tty_color
.pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5055 bg_tty_color
.pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5057 /* Check if foreground color is close enough. */
5058 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
5061 Lisp_Object def_fg
= def_attrs
[LFACE_FOREGROUND_INDEX
];
5063 if (face_attr_equal_p (fg
, def_fg
))
5064 return 0; /* same as default */
5065 else if (! tty_lookup_color (f
, fg
, &fg_tty_color
, &fg_std_color
))
5066 return 0; /* not a valid color */
5067 else if (color_distance (&fg_tty_color
, &fg_std_color
)
5068 > TTY_SAME_COLOR_THRESHOLD
)
5069 return 0; /* displayed color is too different */
5071 /* Make sure the color is really different than the default. */
5073 XColor def_fg_color
;
5074 if (tty_lookup_color (f
, def_fg
, &def_fg_color
, 0)
5075 && (color_distance (&fg_tty_color
, &def_fg_color
)
5076 <= TTY_SAME_COLOR_THRESHOLD
))
5081 /* Check if background color is close enough. */
5082 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
5085 Lisp_Object def_bg
= def_attrs
[LFACE_BACKGROUND_INDEX
];
5087 if (face_attr_equal_p (bg
, def_bg
))
5088 return 0; /* same as default */
5089 else if (! tty_lookup_color (f
, bg
, &bg_tty_color
, &bg_std_color
))
5090 return 0; /* not a valid color */
5091 else if (color_distance (&bg_tty_color
, &bg_std_color
)
5092 > TTY_SAME_COLOR_THRESHOLD
)
5093 return 0; /* displayed color is too different */
5095 /* Make sure the color is really different than the default. */
5097 XColor def_bg_color
;
5098 if (tty_lookup_color (f
, def_bg
, &def_bg_color
, 0)
5099 && (color_distance (&bg_tty_color
, &def_bg_color
)
5100 <= TTY_SAME_COLOR_THRESHOLD
))
5105 /* If both foreground and background are requested, see if the
5106 distance between them is OK. We just check to see if the distance
5107 between the tty's foreground and background is close enough to the
5108 distance between the standard foreground and background. */
5109 if (STRINGP (fg
) && STRINGP (bg
))
5112 = (color_distance (&fg_std_color
, &bg_std_color
)
5113 - color_distance (&fg_tty_color
, &bg_tty_color
));
5114 if (delta_delta
> TTY_SAME_COLOR_THRESHOLD
5115 || delta_delta
< -TTY_SAME_COLOR_THRESHOLD
)
5120 /* See if the capabilities we selected above are supported, with the
5122 if (test_caps
!= 0 &&
5123 ! tty_capable_p (FRAME_TTY (f
), test_caps
, fg_tty_color
.pixel
, bg_tty_color
.pixel
))
5127 /* Hmmm, everything checks out, this terminal must support this face. */
5132 DEFUN ("display-supports-face-attributes-p",
5133 Fdisplay_supports_face_attributes_p
, Sdisplay_supports_face_attributes_p
,
5135 doc
: /* Return non-nil if all the face attributes in ATTRIBUTES are supported.
5136 The optional argument DISPLAY can be a display name, a frame, or
5137 nil (meaning the selected frame's display).
5139 The definition of `supported' is somewhat heuristic, but basically means
5140 that a face containing all the attributes in ATTRIBUTES, when merged
5141 with the default face for display, can be represented in a way that's
5143 \(1) different in appearance than the default face, and
5144 \(2) `close in spirit' to what the attributes specify, if not exact.
5146 Point (2) implies that a `:weight black' attribute will be satisfied by
5147 any display that can display bold, and a `:foreground \"yellow\"' as long
5148 as it can display a yellowish color, but `:slant italic' will _not_ be
5149 satisfied by the tty display code's automatic substitution of a `dim'
5150 face for italic. */)
5151 (Lisp_Object attributes
, Lisp_Object display
)
5153 int supports
= 0, i
;
5156 struct face
*def_face
;
5157 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5159 if (noninteractive
|| !initialized
)
5160 /* We may not be able to access low-level face information in batch
5161 mode, or before being dumped, and this function is not going to
5162 be very useful in those cases anyway, so just give up. */
5166 frame
= selected_frame
;
5167 else if (FRAMEP (display
))
5171 /* Find any frame on DISPLAY. */
5172 Lisp_Object fl_tail
;
5175 for (fl_tail
= Vframe_list
; CONSP (fl_tail
); fl_tail
= XCDR (fl_tail
))
5177 frame
= XCAR (fl_tail
);
5178 if (!NILP (Fequal (Fcdr (Fassq (Qdisplay
,
5179 XFRAME (frame
)->param_alist
)),
5185 CHECK_LIVE_FRAME (frame
);
5188 for (i
= 0; i
< LFACE_VECTOR_SIZE
; i
++)
5189 attrs
[i
] = Qunspecified
;
5190 merge_face_ref (f
, attributes
, attrs
, 1, 0);
5192 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5193 if (def_face
== NULL
)
5195 if (! realize_basic_faces (f
))
5196 error ("Cannot realize default face");
5197 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5198 if (def_face
== NULL
)
5199 abort (); /* realize_basic_faces must have set it up */
5202 /* Dispatch to the appropriate handler. */
5203 if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5204 supports
= tty_supports_face_attributes_p (f
, attrs
, def_face
);
5205 #ifdef HAVE_WINDOW_SYSTEM
5207 supports
= x_supports_face_attributes_p (f
, attrs
, def_face
);
5210 return supports
? Qt
: Qnil
;
5214 /***********************************************************************
5216 ***********************************************************************/
5218 DEFUN ("internal-set-font-selection-order",
5219 Finternal_set_font_selection_order
,
5220 Sinternal_set_font_selection_order
, 1, 1, 0,
5221 doc
: /* Set font selection order for face font selection to ORDER.
5222 ORDER must be a list of length 4 containing the symbols `:width',
5223 `:height', `:weight', and `:slant'. Face attributes appearing
5224 first in ORDER are matched first, e.g. if `:height' appears before
5225 `:weight' in ORDER, font selection first tries to find a font with
5226 a suitable height, and then tries to match the font weight.
5232 int indices
[DIM (font_sort_order
)];
5235 memset (indices
, 0, sizeof indices
);
5239 CONSP (list
) && i
< DIM (indices
);
5240 list
= XCDR (list
), ++i
)
5242 Lisp_Object attr
= XCAR (list
);
5245 if (EQ (attr
, QCwidth
))
5247 else if (EQ (attr
, QCheight
))
5248 xlfd
= XLFD_POINT_SIZE
;
5249 else if (EQ (attr
, QCweight
))
5251 else if (EQ (attr
, QCslant
))
5256 if (indices
[i
] != 0)
5261 if (!NILP (list
) || i
!= DIM (indices
))
5262 signal_error ("Invalid font sort order", order
);
5263 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5264 if (indices
[i
] == 0)
5265 signal_error ("Invalid font sort order", order
);
5267 if (memcmp (indices
, font_sort_order
, sizeof indices
) != 0)
5269 memcpy (font_sort_order
, indices
, sizeof font_sort_order
);
5270 free_all_realized_faces (Qnil
);
5273 font_update_sort_order (font_sort_order
);
5279 DEFUN ("internal-set-alternative-font-family-alist",
5280 Finternal_set_alternative_font_family_alist
,
5281 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
5282 doc
: /* Define alternative font families to try in face font selection.
5283 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5284 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
5285 be found. Value is ALIST. */)
5288 Lisp_Object entry
, tail
, tail2
;
5291 alist
= Fcopy_sequence (alist
);
5292 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5294 entry
= XCAR (tail
);
5296 entry
= Fcopy_sequence (entry
);
5297 XSETCAR (tail
, entry
);
5298 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5299 XSETCAR (tail2
, Fintern (XCAR (tail2
), Qnil
));
5302 Vface_alternative_font_family_alist
= alist
;
5303 free_all_realized_faces (Qnil
);
5308 DEFUN ("internal-set-alternative-font-registry-alist",
5309 Finternal_set_alternative_font_registry_alist
,
5310 Sinternal_set_alternative_font_registry_alist
, 1, 1, 0,
5311 doc
: /* Define alternative font registries to try in face font selection.
5312 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5313 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
5314 be found. Value is ALIST. */)
5317 Lisp_Object entry
, tail
, tail2
;
5320 alist
= Fcopy_sequence (alist
);
5321 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5323 entry
= XCAR (tail
);
5325 entry
= Fcopy_sequence (entry
);
5326 XSETCAR (tail
, entry
);
5327 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5328 XSETCAR (tail2
, Fdowncase (XCAR (tail2
)));
5330 Vface_alternative_font_registry_alist
= alist
;
5331 free_all_realized_faces (Qnil
);
5336 #ifdef HAVE_WINDOW_SYSTEM
5338 /* Ignore the difference of font point size less than this value. */
5340 #define FONT_POINT_SIZE_QUANTUM 5
5342 /* Return the fontset id of the base fontset name or alias name given
5343 by the fontset attribute of ATTRS. Value is -1 if the fontset
5344 attribute of ATTRS doesn't name a fontset. */
5347 face_fontset (Lisp_Object
*attrs
)
5351 name
= attrs
[LFACE_FONTSET_INDEX
];
5352 if (!STRINGP (name
))
5354 return fs_query_fontset (name
, 0);
5357 #endif /* HAVE_WINDOW_SYSTEM */
5361 /***********************************************************************
5363 ***********************************************************************/
5365 /* Realize basic faces on frame F. Value is zero if frame parameters
5366 of F don't contain enough information needed to realize the default
5370 realize_basic_faces (struct frame
*f
)
5373 int count
= SPECPDL_INDEX ();
5375 /* Block input here so that we won't be surprised by an X expose
5376 event, for instance, without having the faces set up. */
5378 specbind (Qscalable_fonts_allowed
, Qt
);
5380 if (realize_default_face (f
))
5382 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
5383 realize_named_face (f
, Qmode_line_inactive
, MODE_LINE_INACTIVE_FACE_ID
);
5384 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
5385 realize_named_face (f
, Qfringe
, FRINGE_FACE_ID
);
5386 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
5387 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
5388 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
5389 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
5390 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
5391 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
5392 realize_named_face (f
, Qvertical_border
, VERTICAL_BORDER_FACE_ID
);
5394 /* Reflect changes in the `menu' face in menu bars. */
5395 if (FRAME_FACE_CACHE (f
)->menu_face_changed_p
)
5397 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 0;
5398 #ifdef USE_X_TOOLKIT
5399 if (FRAME_WINDOW_P (f
))
5400 x_update_menu_appearance (f
);
5407 unbind_to (count
, Qnil
);
5413 /* Realize the default face on frame F. If the face is not fully
5414 specified, make it fully-specified. Attributes of the default face
5415 that are not explicitly specified are taken from frame parameters. */
5418 realize_default_face (struct frame
*f
)
5420 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5422 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5425 /* If the `default' face is not yet known, create it. */
5426 lface
= lface_from_face_name (f
, Qdefault
, 0);
5430 XSETFRAME (frame
, f
);
5431 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
5434 #ifdef HAVE_WINDOW_SYSTEM
5435 if (FRAME_WINDOW_P (f
))
5437 Lisp_Object font_object
;
5439 XSETFONT (font_object
, FRAME_FONT (f
));
5440 set_lface_from_font (f
, lface
, font_object
, f
->default_face_done_p
);
5441 LFACE_FONTSET (lface
) = fontset_name (FRAME_FONTSET (f
));
5442 f
->default_face_done_p
= 1;
5444 #endif /* HAVE_WINDOW_SYSTEM */
5446 if (!FRAME_WINDOW_P (f
))
5448 LFACE_FAMILY (lface
) = build_string ("default");
5449 LFACE_FOUNDRY (lface
) = LFACE_FAMILY (lface
);
5450 LFACE_SWIDTH (lface
) = Qnormal
;
5451 LFACE_HEIGHT (lface
) = make_number (1);
5452 if (UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
5453 LFACE_WEIGHT (lface
) = Qnormal
;
5454 if (UNSPECIFIEDP (LFACE_SLANT (lface
)))
5455 LFACE_SLANT (lface
) = Qnormal
;
5456 if (UNSPECIFIEDP (LFACE_FONTSET (lface
)))
5457 LFACE_FONTSET (lface
) = Qnil
;
5460 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
5461 LFACE_UNDERLINE (lface
) = Qnil
;
5463 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
5464 LFACE_OVERLINE (lface
) = Qnil
;
5466 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
5467 LFACE_STRIKE_THROUGH (lface
) = Qnil
;
5469 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
5470 LFACE_BOX (lface
) = Qnil
;
5472 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
5473 LFACE_INVERSE (lface
) = Qnil
;
5475 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
5477 /* This function is called so early that colors are not yet
5478 set in the frame parameter list. */
5479 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
5481 if (CONSP (color
) && STRINGP (XCDR (color
)))
5482 LFACE_FOREGROUND (lface
) = XCDR (color
);
5483 else if (FRAME_WINDOW_P (f
))
5485 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5486 LFACE_FOREGROUND (lface
) = build_string (unspecified_fg
);
5491 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
5493 /* This function is called so early that colors are not yet
5494 set in the frame parameter list. */
5495 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
5496 if (CONSP (color
) && STRINGP (XCDR (color
)))
5497 LFACE_BACKGROUND (lface
) = XCDR (color
);
5498 else if (FRAME_WINDOW_P (f
))
5500 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5501 LFACE_BACKGROUND (lface
) = build_string (unspecified_bg
);
5506 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
5507 LFACE_STIPPLE (lface
) = Qnil
;
5509 /* Realize the face; it must be fully-specified now. */
5510 xassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
5511 check_lface (lface
);
5512 memcpy (attrs
, XVECTOR (lface
)->contents
, sizeof attrs
);
5513 face
= realize_face (c
, attrs
, DEFAULT_FACE_ID
);
5515 #ifdef HAVE_WINDOW_SYSTEM
5516 #ifdef HAVE_X_WINDOWS
5517 if (FRAME_X_P (f
) && face
->font
!= FRAME_FONT (f
))
5519 /* This can happen when making a frame on a display that does
5520 not support the default font. */
5524 /* Otherwise, the font specified for the frame was not
5525 acceptable as a font for the default face (perhaps because
5526 auto-scaled fonts are rejected), so we must adjust the frame
5528 x_set_font (f
, LFACE_FONT (lface
), Qnil
);
5530 #endif /* HAVE_X_WINDOWS */
5531 #endif /* HAVE_WINDOW_SYSTEM */
5536 /* Realize basic faces other than the default face in face cache C.
5537 SYMBOL is the face name, ID is the face id the realized face must
5538 have. The default face must have been realized already. */
5541 realize_named_face (struct frame
*f
, Lisp_Object symbol
, int id
)
5543 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5544 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
5545 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5546 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5547 struct face
*new_face
;
5549 /* The default face must exist and be fully specified. */
5550 get_lface_attributes_no_remap (f
, Qdefault
, attrs
, 1);
5551 check_lface_attrs (attrs
);
5552 xassert (lface_fully_specified_p (attrs
));
5554 /* If SYMBOL isn't know as a face, create it. */
5558 XSETFRAME (frame
, f
);
5559 lface
= Finternal_make_lisp_face (symbol
, frame
);
5562 /* Merge SYMBOL's face with the default face. */
5563 get_lface_attributes_no_remap (f
, symbol
, symbol_attrs
, 1);
5564 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
5566 /* Realize the face. */
5567 new_face
= realize_face (c
, attrs
, id
);
5571 /* Realize the fully-specified face with attributes ATTRS in face
5572 cache CACHE for ASCII characters. If FORMER_FACE_ID is
5573 non-negative, it is an ID of face to remove before caching the new
5574 face. Value is a pointer to the newly created realized face. */
5576 static struct face
*
5577 realize_face (struct face_cache
*cache
, Lisp_Object
*attrs
, int former_face_id
)
5581 /* LFACE must be fully specified. */
5582 xassert (cache
!= NULL
);
5583 check_lface_attrs (attrs
);
5585 if (former_face_id
>= 0 && cache
->used
> former_face_id
)
5587 /* Remove the former face. */
5588 struct face
*former_face
= cache
->faces_by_id
[former_face_id
];
5589 uncache_face (cache
, former_face
);
5590 free_realized_face (cache
->f
, former_face
);
5591 SET_FRAME_GARBAGED (cache
->f
);
5594 if (FRAME_WINDOW_P (cache
->f
))
5595 face
= realize_x_face (cache
, attrs
);
5596 else if (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
))
5597 face
= realize_tty_face (cache
, attrs
);
5598 else if (FRAME_INITIAL_P (cache
->f
))
5600 /* Create a dummy face. */
5601 face
= make_realized_face (attrs
);
5606 /* Insert the new face. */
5607 cache_face (cache
, face
, lface_hash (attrs
));
5612 #ifdef HAVE_WINDOW_SYSTEM
5613 /* Realize the fully-specified face that uses FONT-OBJECT and has the
5614 same attributes as BASE_FACE except for the font on frame F.
5615 FONT-OBJECT may be nil, in which case, realized a face of
5618 static struct face
*
5619 realize_non_ascii_face (struct frame
*f
, Lisp_Object font_object
, struct face
*base_face
)
5621 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5624 face
= (struct face
*) xmalloc (sizeof *face
);
5629 = (! NILP (font_object
)
5630 && FONT_WEIGHT_NAME_NUMERIC (face
->lface
[LFACE_WEIGHT_INDEX
]) > 100
5631 && FONT_WEIGHT_NUMERIC (font_object
) <= 100);
5633 /* Don't try to free the colors copied bitwise from BASE_FACE. */
5634 face
->colors_copied_bitwise_p
= 1;
5635 face
->font
= NILP (font_object
) ? NULL
: XFONT_OBJECT (font_object
);
5638 cache_face (cache
, face
, face
->hash
);
5642 #endif /* HAVE_WINDOW_SYSTEM */
5645 /* Realize the fully-specified face with attributes ATTRS in face
5646 cache CACHE for ASCII characters. Do it for X frame CACHE->f. If
5647 the new face doesn't share font with the default face, a fontname
5648 is allocated from the heap and set in `font_name' of the new face,
5649 but it is not yet loaded here. Value is a pointer to the newly
5650 created realized face. */
5652 static struct face
*
5653 realize_x_face (struct face_cache
*cache
, Lisp_Object
*attrs
)
5655 struct face
*face
= NULL
;
5656 #ifdef HAVE_WINDOW_SYSTEM
5657 struct face
*default_face
;
5659 Lisp_Object stipple
, overline
, strike_through
, box
;
5661 xassert (FRAME_WINDOW_P (cache
->f
));
5663 /* Allocate a new realized face. */
5664 face
= make_realized_face (attrs
);
5665 face
->ascii_face
= face
;
5669 /* Determine the font to use. Most of the time, the font will be
5670 the same as the font of the default face, so try that first. */
5671 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5673 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
5675 face
->font
= default_face
->font
;
5677 = make_fontset_for_ascii_face (f
, default_face
->fontset
, face
);
5681 /* If the face attribute ATTRS specifies a fontset, use it as
5682 the base of a new realized fontset. Otherwise, use the same
5683 base fontset as of the default face. The base determines
5684 registry and encoding of a font. It may also determine
5685 foundry and family. The other fields of font name pattern
5686 are constructed from ATTRS. */
5687 int fontset
= face_fontset (attrs
);
5689 /* If we are realizing the default face, ATTRS should specify a
5690 fontset. In other words, if FONTSET is -1, we are not
5691 realizing the default face, thus the default face should have
5692 already been realized. */
5696 fontset
= default_face
->fontset
;
5700 if (! FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5701 attrs
[LFACE_FONT_INDEX
]
5702 = font_load_for_lface (f
, attrs
, attrs
[LFACE_FONT_INDEX
]);
5703 if (FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5705 face
->font
= XFONT_OBJECT (attrs
[LFACE_FONT_INDEX
]);
5706 face
->fontset
= make_fontset_for_ascii_face (f
, fontset
, face
);
5716 && FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]) > 100
5717 && FONT_WEIGHT_NUMERIC (attrs
[LFACE_FONT_INDEX
]) <= 100)
5718 face
->overstrike
= 1;
5720 /* Load colors, and set remaining attributes. */
5722 load_face_colors (f
, face
, attrs
);
5725 box
= attrs
[LFACE_BOX_INDEX
];
5728 /* A simple box of line width 1 drawn in color given by
5730 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
5732 face
->box
= FACE_SIMPLE_BOX
;
5733 face
->box_line_width
= 1;
5735 else if (INTEGERP (box
))
5737 /* Simple box of specified line width in foreground color of the
5739 xassert (XINT (box
) != 0);
5740 face
->box
= FACE_SIMPLE_BOX
;
5741 face
->box_line_width
= XINT (box
);
5742 face
->box_color
= face
->foreground
;
5743 face
->box_color_defaulted_p
= 1;
5745 else if (CONSP (box
))
5747 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
5748 being one of `raised' or `sunken'. */
5749 face
->box
= FACE_SIMPLE_BOX
;
5750 face
->box_color
= face
->foreground
;
5751 face
->box_color_defaulted_p
= 1;
5752 face
->box_line_width
= 1;
5756 Lisp_Object keyword
, value
;
5758 keyword
= XCAR (box
);
5766 if (EQ (keyword
, QCline_width
))
5768 if (INTEGERP (value
) && XINT (value
) != 0)
5769 face
->box_line_width
= XINT (value
);
5771 else if (EQ (keyword
, QCcolor
))
5773 if (STRINGP (value
))
5775 face
->box_color
= load_color (f
, face
, value
,
5777 face
->use_box_color_for_shadows_p
= 1;
5780 else if (EQ (keyword
, QCstyle
))
5782 if (EQ (value
, Qreleased_button
))
5783 face
->box
= FACE_RAISED_BOX
;
5784 else if (EQ (value
, Qpressed_button
))
5785 face
->box
= FACE_SUNKEN_BOX
;
5790 /* Text underline, overline, strike-through. */
5792 if (EQ (attrs
[LFACE_UNDERLINE_INDEX
], Qt
))
5794 /* Use default color (same as foreground color). */
5795 face
->underline_p
= 1;
5796 face
->underline_defaulted_p
= 1;
5797 face
->underline_color
= 0;
5799 else if (STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]))
5801 /* Use specified color. */
5802 face
->underline_p
= 1;
5803 face
->underline_defaulted_p
= 0;
5804 face
->underline_color
5805 = load_color (f
, face
, attrs
[LFACE_UNDERLINE_INDEX
],
5806 LFACE_UNDERLINE_INDEX
);
5808 else if (NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5810 face
->underline_p
= 0;
5811 face
->underline_defaulted_p
= 0;
5812 face
->underline_color
= 0;
5815 overline
= attrs
[LFACE_OVERLINE_INDEX
];
5816 if (STRINGP (overline
))
5818 face
->overline_color
5819 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
5820 LFACE_OVERLINE_INDEX
);
5821 face
->overline_p
= 1;
5823 else if (EQ (overline
, Qt
))
5825 face
->overline_color
= face
->foreground
;
5826 face
->overline_color_defaulted_p
= 1;
5827 face
->overline_p
= 1;
5830 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
5831 if (STRINGP (strike_through
))
5833 face
->strike_through_color
5834 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
5835 LFACE_STRIKE_THROUGH_INDEX
);
5836 face
->strike_through_p
= 1;
5838 else if (EQ (strike_through
, Qt
))
5840 face
->strike_through_color
= face
->foreground
;
5841 face
->strike_through_color_defaulted_p
= 1;
5842 face
->strike_through_p
= 1;
5845 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
5846 if (!NILP (stipple
))
5847 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
5848 #endif /* HAVE_WINDOW_SYSTEM */
5854 /* Map a specified color of face FACE on frame F to a tty color index.
5855 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
5856 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
5857 default foreground/background colors. */
5860 map_tty_color (struct frame
*f
, struct face
*face
, enum lface_attribute_index idx
, int *defaulted
)
5862 Lisp_Object frame
, color
, def
;
5863 int foreground_p
= idx
== LFACE_FOREGROUND_INDEX
;
5864 unsigned long default_pixel
, default_other_pixel
, pixel
;
5866 xassert (idx
== LFACE_FOREGROUND_INDEX
|| idx
== LFACE_BACKGROUND_INDEX
);
5870 pixel
= default_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5871 default_other_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5875 pixel
= default_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5876 default_other_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5879 XSETFRAME (frame
, f
);
5880 color
= face
->lface
[idx
];
5884 && CONSP (Vtty_defined_color_alist
)
5885 && (def
= assq_no_quit (color
, call1 (Qtty_color_alist
, frame
)),
5888 /* Associations in tty-defined-color-alist are of the form
5889 (NAME INDEX R G B). We need the INDEX part. */
5890 pixel
= XINT (XCAR (XCDR (def
)));
5893 if (pixel
== default_pixel
&& STRINGP (color
))
5895 pixel
= load_color (f
, face
, color
, idx
);
5898 /* If the foreground of the default face is the default color,
5899 use the foreground color defined by the frame. */
5900 if (FRAME_MSDOS_P (f
))
5902 if (pixel
== default_pixel
5903 || pixel
== FACE_TTY_DEFAULT_COLOR
)
5906 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5908 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5909 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5912 else if (pixel
== default_other_pixel
)
5915 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5917 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5918 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5926 face
->foreground
= pixel
;
5928 face
->background
= pixel
;
5932 /* Realize the fully-specified face with attributes ATTRS in face
5933 cache CACHE for ASCII characters. Do it for TTY frame CACHE->f.
5934 Value is a pointer to the newly created realized face. */
5936 static struct face
*
5937 realize_tty_face (struct face_cache
*cache
, Lisp_Object
*attrs
)
5941 int face_colors_defaulted
= 0;
5942 struct frame
*f
= cache
->f
;
5944 /* Frame must be a termcap frame. */
5945 xassert (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
));
5947 /* Allocate a new realized face. */
5948 face
= make_realized_face (attrs
);
5950 face
->font_name
= FRAME_MSDOS_P (cache
->f
) ? "ms-dos" : "tty";
5953 /* Map face attributes to TTY appearances. We map slant to
5954 dimmed text because we want italic text to appear differently
5955 and because dimmed text is probably used infrequently. */
5956 weight
= FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]);
5957 slant
= FONT_SLANT_NAME_NUMERIC (attrs
[LFACE_SLANT_INDEX
]);
5959 face
->tty_bold_p
= 1;
5960 if (weight
< 100 || slant
!= 100)
5961 face
->tty_dim_p
= 1;
5962 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5963 face
->tty_underline_p
= 1;
5964 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
5965 face
->tty_reverse_p
= 1;
5967 /* Map color names to color indices. */
5968 map_tty_color (f
, face
, LFACE_FOREGROUND_INDEX
, &face_colors_defaulted
);
5969 map_tty_color (f
, face
, LFACE_BACKGROUND_INDEX
, &face_colors_defaulted
);
5971 /* Swap colors if face is inverse-video. If the colors are taken
5972 from the frame colors, they are already inverted, since the
5973 frame-creation function calls x-handle-reverse-video. */
5974 if (face
->tty_reverse_p
&& !face_colors_defaulted
)
5976 unsigned long tem
= face
->foreground
;
5977 face
->foreground
= face
->background
;
5978 face
->background
= tem
;
5981 if (tty_suppress_bold_inverse_default_colors_p
5983 && face
->background
== FACE_TTY_DEFAULT_FG_COLOR
5984 && face
->foreground
== FACE_TTY_DEFAULT_BG_COLOR
)
5985 face
->tty_bold_p
= 0;
5991 DEFUN ("tty-suppress-bold-inverse-default-colors",
5992 Ftty_suppress_bold_inverse_default_colors
,
5993 Stty_suppress_bold_inverse_default_colors
, 1, 1, 0,
5994 doc
: /* Suppress/allow boldness of faces with inverse default colors.
5995 SUPPRESS non-nil means suppress it.
5996 This affects bold faces on TTYs whose foreground is the default background
5997 color of the display and whose background is the default foreground color.
5998 For such faces, the bold face attribute is ignored if this variable
6000 (Lisp_Object suppress
)
6002 tty_suppress_bold_inverse_default_colors_p
= !NILP (suppress
);
6003 ++face_change_count
;
6009 /***********************************************************************
6011 ***********************************************************************/
6013 /* Return the ID of the face to use to display character CH with face
6014 property PROP on frame F in current_buffer. */
6017 compute_char_face (struct frame
*f
, int ch
, Lisp_Object prop
)
6021 if (NILP (current_buffer
->enable_multibyte_characters
))
6026 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6027 face_id
= FACE_FOR_CHAR (f
, face
, ch
, -1, Qnil
);
6031 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6032 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6033 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6034 merge_face_ref (f
, prop
, attrs
, 1, 0);
6035 face_id
= lookup_face (f
, attrs
);
6041 /* Return the face ID associated with buffer position POS for
6042 displaying ASCII characters. Return in *ENDPTR the position at
6043 which a different face is needed, as far as text properties and
6044 overlays are concerned. W is a window displaying current_buffer.
6046 REGION_BEG, REGION_END delimit the region, so it can be
6049 LIMIT is a position not to scan beyond. That is to limit the time
6050 this function can take.
6052 If MOUSE is non-zero, use the character's mouse-face, not its face.
6054 BASE_FACE_ID, if non-negative, specifies a base face id to use
6055 instead of DEFAULT_FACE_ID.
6057 The face returned is suitable for displaying ASCII characters. */
6060 face_at_buffer_position (struct window
*w
, EMACS_INT pos
,
6061 EMACS_INT region_beg
, EMACS_INT region_end
,
6062 EMACS_INT
*endptr
, EMACS_INT limit
,
6063 int mouse
, int base_face_id
)
6065 struct frame
*f
= XFRAME (w
->frame
);
6066 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6067 Lisp_Object prop
, position
;
6069 Lisp_Object
*overlay_vec
;
6072 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
6073 Lisp_Object limit1
, end
;
6074 struct face
*default_face
;
6076 /* W must display the current buffer. We could write this function
6077 to use the frame and buffer of W, but right now it doesn't. */
6078 /* xassert (XBUFFER (w->buffer) == current_buffer); */
6080 XSETFRAME (frame
, f
);
6081 XSETFASTINT (position
, pos
);
6084 if (pos
< region_beg
&& region_beg
< endpos
)
6085 endpos
= region_beg
;
6087 /* Get the `face' or `mouse_face' text property at POS, and
6088 determine the next position at which the property changes. */
6089 prop
= Fget_text_property (position
, propname
, w
->buffer
);
6090 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6091 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
6093 endpos
= XINT (end
);
6095 /* Look at properties from overlays. */
6097 EMACS_INT next_overlay
;
6099 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, &next_overlay
, 0);
6100 if (next_overlay
< endpos
)
6101 endpos
= next_overlay
;
6106 default_face
= FACE_FROM_ID (f
, base_face_id
>= 0 ? base_face_id
6107 : NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
6108 : lookup_basic_face (f
, DEFAULT_FACE_ID
));
6110 /* Optimize common cases where we can use the default face. */
6113 && !(pos
>= region_beg
&& pos
< region_end
))
6114 return default_face
->id
;
6116 /* Begin with attributes from the default face. */
6117 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6119 /* Merge in attributes specified via text properties. */
6121 merge_face_ref (f
, prop
, attrs
, 1, 0);
6123 /* Now merge the overlay data. */
6124 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6125 for (i
= 0; i
< noverlays
; i
++)
6130 prop
= Foverlay_get (overlay_vec
[i
], propname
);
6132 merge_face_ref (f
, prop
, attrs
, 1, 0);
6134 oend
= OVERLAY_END (overlay_vec
[i
]);
6135 oendpos
= OVERLAY_POSITION (oend
);
6136 if (oendpos
< endpos
)
6140 /* If in the region, merge in the region face. */
6141 if (pos
>= region_beg
&& pos
< region_end
)
6143 merge_named_face (f
, Qregion
, attrs
, 0);
6145 if (region_end
< endpos
)
6146 endpos
= region_end
;
6151 /* Look up a realized face with the given face attributes,
6152 or realize a new one for ASCII characters. */
6153 return lookup_face (f
, attrs
);
6156 /* Return the face ID at buffer position POS for displaying ASCII
6157 characters associated with overlay strings for overlay OVERLAY.
6159 Like face_at_buffer_position except for OVERLAY. Currently it
6160 simply disregards the `face' properties of all overlays. */
6163 face_for_overlay_string (struct window
*w
, EMACS_INT pos
,
6164 EMACS_INT region_beg
, EMACS_INT region_end
,
6165 EMACS_INT
*endptr
, EMACS_INT limit
,
6166 int mouse
, Lisp_Object overlay
)
6168 struct frame
*f
= XFRAME (w
->frame
);
6169 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6170 Lisp_Object prop
, position
;
6173 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
6174 Lisp_Object limit1
, end
;
6175 struct face
*default_face
;
6177 /* W must display the current buffer. We could write this function
6178 to use the frame and buffer of W, but right now it doesn't. */
6179 /* xassert (XBUFFER (w->buffer) == current_buffer); */
6181 XSETFRAME (frame
, f
);
6182 XSETFASTINT (position
, pos
);
6185 if (pos
< region_beg
&& region_beg
< endpos
)
6186 endpos
= region_beg
;
6188 /* Get the `face' or `mouse_face' text property at POS, and
6189 determine the next position at which the property changes. */
6190 prop
= Fget_text_property (position
, propname
, w
->buffer
);
6191 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6192 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
6194 endpos
= XINT (end
);
6198 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6200 /* Optimize common cases where we can use the default face. */
6202 && !(pos
>= region_beg
&& pos
< region_end
))
6203 return DEFAULT_FACE_ID
;
6205 /* Begin with attributes from the default face. */
6206 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6208 /* Merge in attributes specified via text properties. */
6210 merge_face_ref (f
, prop
, attrs
, 1, 0);
6212 /* If in the region, merge in the region face. */
6213 if (pos
>= region_beg
&& pos
< region_end
)
6215 merge_named_face (f
, Qregion
, attrs
, 0);
6217 if (region_end
< endpos
)
6218 endpos
= region_end
;
6223 /* Look up a realized face with the given face attributes,
6224 or realize a new one for ASCII characters. */
6225 return lookup_face (f
, attrs
);
6229 /* Compute the face at character position POS in Lisp string STRING on
6230 window W, for ASCII characters.
6232 If STRING is an overlay string, it comes from position BUFPOS in
6233 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
6234 not an overlay string. W must display the current buffer.
6235 REGION_BEG and REGION_END give the start and end positions of the
6236 region; both are -1 if no region is visible.
6238 BASE_FACE_ID is the id of a face to merge with. For strings coming
6239 from overlays or the `display' property it is the face at BUFPOS.
6241 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
6243 Set *ENDPTR to the next position where to check for faces in
6244 STRING; -1 if the face is constant from POS to the end of the
6247 Value is the id of the face to use. The face returned is suitable
6248 for displaying ASCII characters. */
6251 face_at_string_position (struct window
*w
, Lisp_Object string
,
6252 EMACS_INT pos
, EMACS_INT bufpos
,
6253 EMACS_INT region_beg
, EMACS_INT region_end
,
6254 EMACS_INT
*endptr
, enum face_id base_face_id
,
6257 Lisp_Object prop
, position
, end
, limit
;
6258 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6259 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6260 struct face
*base_face
;
6261 int multibyte_p
= STRING_MULTIBYTE (string
);
6262 Lisp_Object prop_name
= mouse_p
? Qmouse_face
: Qface
;
6264 /* Get the value of the face property at the current position within
6265 STRING. Value is nil if there is no face property. */
6266 XSETFASTINT (position
, pos
);
6267 prop
= Fget_text_property (position
, prop_name
, string
);
6269 /* Get the next position at which to check for faces. Value of end
6270 is nil if face is constant all the way to the end of the string.
6271 Otherwise it is a string position where to check faces next.
6272 Limit is the maximum position up to which to check for property
6273 changes in Fnext_single_property_change. Strings are usually
6274 short, so set the limit to the end of the string. */
6275 XSETFASTINT (limit
, SCHARS (string
));
6276 end
= Fnext_single_property_change (position
, prop_name
, string
, limit
);
6278 *endptr
= XFASTINT (end
);
6282 base_face
= FACE_FROM_ID (f
, base_face_id
);
6283 xassert (base_face
);
6285 /* Optimize the default case that there is no face property and we
6286 are not in the region. */
6288 && (base_face_id
!= DEFAULT_FACE_ID
6289 /* BUFPOS <= 0 means STRING is not an overlay string, so
6290 that the region doesn't have to be taken into account. */
6292 || bufpos
< region_beg
6293 || bufpos
>= region_end
)
6295 /* We can't realize faces for different charsets differently
6296 if we don't have fonts, so we can stop here if not working
6297 on a window-system frame. */
6298 || !FRAME_WINDOW_P (f
)
6299 || FACE_SUITABLE_FOR_CHAR_P (base_face
, 0)))
6300 return base_face
->id
;
6302 /* Begin with attributes from the base face. */
6303 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6305 /* Merge in attributes specified via text properties. */
6307 merge_face_ref (f
, prop
, attrs
, 1, 0);
6309 /* If in the region, merge in the region face. */
6311 && bufpos
>= region_beg
6312 && bufpos
< region_end
)
6313 merge_named_face (f
, Qregion
, attrs
, 0);
6315 /* Look up a realized face with the given face attributes,
6316 or realize a new one for ASCII characters. */
6317 return lookup_face (f
, attrs
);
6321 /* Merge a face into a realized face.
6323 F is frame where faces are (to be) realized.
6325 FACE_NAME is named face to merge.
6327 If FACE_NAME is nil, FACE_ID is face_id of realized face to merge.
6329 If FACE_NAME is t, FACE_ID is lface_id of face to merge.
6331 BASE_FACE_ID is realized face to merge into.
6337 merge_faces (struct frame
*f
, Lisp_Object face_name
, int face_id
, int base_face_id
)
6339 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6340 struct face
*base_face
;
6342 base_face
= FACE_FROM_ID (f
, base_face_id
);
6344 return base_face_id
;
6346 if (EQ (face_name
, Qt
))
6348 if (face_id
< 0 || face_id
>= lface_id_to_name_size
)
6349 return base_face_id
;
6350 face_name
= lface_id_to_name
[face_id
];
6351 /* When called during make-frame, lookup_derived_face may fail
6352 if the faces are uninitialized. Don't signal an error. */
6353 face_id
= lookup_derived_face (f
, face_name
, base_face_id
, 0);
6354 return (face_id
>= 0 ? face_id
: base_face_id
);
6357 /* Begin with attributes from the base face. */
6358 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6360 if (!NILP (face_name
))
6362 if (!merge_named_face (f
, face_name
, attrs
, 0))
6363 return base_face_id
;
6369 return base_face_id
;
6370 face
= FACE_FROM_ID (f
, face_id
);
6372 return base_face_id
;
6373 merge_face_vectors (f
, face
->lface
, attrs
, 0);
6376 /* Look up a realized face with the given face attributes,
6377 or realize a new one for ASCII characters. */
6378 return lookup_face (f
, attrs
);
6383 #ifndef HAVE_X_WINDOWS
6384 DEFUN ("x-load-color-file", Fx_load_color_file
,
6385 Sx_load_color_file
, 1, 1, 0,
6386 doc
: /* Create an alist of color entries from an external file.
6388 The file should define one named RGB color per line like so:
6390 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6391 (Lisp_Object filename
)
6394 Lisp_Object cmap
= Qnil
;
6395 Lisp_Object abspath
;
6397 CHECK_STRING (filename
);
6398 abspath
= Fexpand_file_name (filename
, Qnil
);
6400 fp
= fopen (SDATA (filename
), "rt");
6404 int red
, green
, blue
;
6409 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
6410 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
6412 char *name
= buf
+ num
;
6413 num
= strlen (name
) - 1;
6414 if (num
>= 0 && name
[num
] == '\n')
6416 cmap
= Fcons (Fcons (build_string (name
),
6418 make_number (RGB (red
, green
, blue
))),
6420 make_number ((red
<< 16) | (green
<< 8) | blue
)),
6435 /***********************************************************************
6437 ***********************************************************************/
6441 /* Print the contents of the realized face FACE to stderr. */
6444 dump_realized_face (face
)
6447 fprintf (stderr
, "ID: %d\n", face
->id
);
6448 #ifdef HAVE_X_WINDOWS
6449 fprintf (stderr
, "gc: %ld\n", (long) face
->gc
);
6451 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
6453 SDATA (face
->lface
[LFACE_FOREGROUND_INDEX
]));
6454 fprintf (stderr
, "background: 0x%lx (%s)\n",
6456 SDATA (face
->lface
[LFACE_BACKGROUND_INDEX
]));
6458 fprintf (stderr
, "font_name: %s (%s)\n",
6459 SDATA (face
->font
->props
[FONT_NAME_INDEX
]),
6460 SDATA (face
->lface
[LFACE_FAMILY_INDEX
]));
6461 #ifdef HAVE_X_WINDOWS
6462 fprintf (stderr
, "font = %p\n", face
->font
);
6464 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
6465 fprintf (stderr
, "underline: %d (%s)\n",
6467 SDATA (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
])));
6468 fprintf (stderr
, "hash: %d\n", face
->hash
);
6472 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, doc
: /* */)
6479 fprintf (stderr
, "font selection order: ");
6480 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6481 fprintf (stderr
, "%d ", font_sort_order
[i
]);
6482 fprintf (stderr
, "\n");
6484 fprintf (stderr
, "alternative fonts: ");
6485 debug_print (Vface_alternative_font_family_alist
);
6486 fprintf (stderr
, "\n");
6488 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
6489 Fdump_face (make_number (i
));
6495 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
6497 error ("Not a valid face");
6498 dump_realized_face (face
);
6505 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
6506 0, 0, 0, doc
: /* */)
6509 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
6510 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
6511 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
6515 #endif /* GLYPH_DEBUG != 0 */
6519 /***********************************************************************
6521 ***********************************************************************/
6524 syms_of_xfaces (void)
6526 Qface
= intern_c_string ("face");
6528 Qface_no_inherit
= intern_c_string ("face-no-inherit");
6529 staticpro (&Qface_no_inherit
);
6530 Qbitmap_spec_p
= intern_c_string ("bitmap-spec-p");
6531 staticpro (&Qbitmap_spec_p
);
6532 Qframe_set_background_mode
= intern_c_string ("frame-set-background-mode");
6533 staticpro (&Qframe_set_background_mode
);
6535 /* Lisp face attribute keywords. */
6536 QCfamily
= intern_c_string (":family");
6537 staticpro (&QCfamily
);
6538 QCheight
= intern_c_string (":height");
6539 staticpro (&QCheight
);
6540 QCweight
= intern_c_string (":weight");
6541 staticpro (&QCweight
);
6542 QCslant
= intern_c_string (":slant");
6543 staticpro (&QCslant
);
6544 QCunderline
= intern_c_string (":underline");
6545 staticpro (&QCunderline
);
6546 QCinverse_video
= intern_c_string (":inverse-video");
6547 staticpro (&QCinverse_video
);
6548 QCreverse_video
= intern_c_string (":reverse-video");
6549 staticpro (&QCreverse_video
);
6550 QCforeground
= intern_c_string (":foreground");
6551 staticpro (&QCforeground
);
6552 QCbackground
= intern_c_string (":background");
6553 staticpro (&QCbackground
);
6554 QCstipple
= intern_c_string (":stipple");
6555 staticpro (&QCstipple
);
6556 QCwidth
= intern_c_string (":width");
6557 staticpro (&QCwidth
);
6558 QCfont
= intern_c_string (":font");
6559 staticpro (&QCfont
);
6560 QCfontset
= intern_c_string (":fontset");
6561 staticpro (&QCfontset
);
6562 QCbold
= intern_c_string (":bold");
6563 staticpro (&QCbold
);
6564 QCitalic
= intern_c_string (":italic");
6565 staticpro (&QCitalic
);
6566 QCoverline
= intern_c_string (":overline");
6567 staticpro (&QCoverline
);
6568 QCstrike_through
= intern_c_string (":strike-through");
6569 staticpro (&QCstrike_through
);
6570 QCbox
= intern_c_string (":box");
6572 QCinherit
= intern_c_string (":inherit");
6573 staticpro (&QCinherit
);
6575 /* Symbols used for Lisp face attribute values. */
6576 QCcolor
= intern_c_string (":color");
6577 staticpro (&QCcolor
);
6578 QCline_width
= intern_c_string (":line-width");
6579 staticpro (&QCline_width
);
6580 QCstyle
= intern_c_string (":style");
6581 staticpro (&QCstyle
);
6582 Qreleased_button
= intern_c_string ("released-button");
6583 staticpro (&Qreleased_button
);
6584 Qpressed_button
= intern_c_string ("pressed-button");
6585 staticpro (&Qpressed_button
);
6586 Qnormal
= intern_c_string ("normal");
6587 staticpro (&Qnormal
);
6588 Qultra_light
= intern_c_string ("ultra-light");
6589 staticpro (&Qultra_light
);
6590 Qextra_light
= intern_c_string ("extra-light");
6591 staticpro (&Qextra_light
);
6592 Qlight
= intern_c_string ("light");
6593 staticpro (&Qlight
);
6594 Qsemi_light
= intern_c_string ("semi-light");
6595 staticpro (&Qsemi_light
);
6596 Qsemi_bold
= intern_c_string ("semi-bold");
6597 staticpro (&Qsemi_bold
);
6598 Qbold
= intern_c_string ("bold");
6600 Qextra_bold
= intern_c_string ("extra-bold");
6601 staticpro (&Qextra_bold
);
6602 Qultra_bold
= intern_c_string ("ultra-bold");
6603 staticpro (&Qultra_bold
);
6604 Qoblique
= intern_c_string ("oblique");
6605 staticpro (&Qoblique
);
6606 Qitalic
= intern_c_string ("italic");
6607 staticpro (&Qitalic
);
6608 Qreverse_oblique
= intern_c_string ("reverse-oblique");
6609 staticpro (&Qreverse_oblique
);
6610 Qreverse_italic
= intern_c_string ("reverse-italic");
6611 staticpro (&Qreverse_italic
);
6612 Qultra_condensed
= intern_c_string ("ultra-condensed");
6613 staticpro (&Qultra_condensed
);
6614 Qextra_condensed
= intern_c_string ("extra-condensed");
6615 staticpro (&Qextra_condensed
);
6616 Qcondensed
= intern_c_string ("condensed");
6617 staticpro (&Qcondensed
);
6618 Qsemi_condensed
= intern_c_string ("semi-condensed");
6619 staticpro (&Qsemi_condensed
);
6620 Qsemi_expanded
= intern_c_string ("semi-expanded");
6621 staticpro (&Qsemi_expanded
);
6622 Qexpanded
= intern_c_string ("expanded");
6623 staticpro (&Qexpanded
);
6624 Qextra_expanded
= intern_c_string ("extra-expanded");
6625 staticpro (&Qextra_expanded
);
6626 Qultra_expanded
= intern_c_string ("ultra-expanded");
6627 staticpro (&Qultra_expanded
);
6628 Qbackground_color
= intern_c_string ("background-color");
6629 staticpro (&Qbackground_color
);
6630 Qforeground_color
= intern_c_string ("foreground-color");
6631 staticpro (&Qforeground_color
);
6632 Qunspecified
= intern_c_string ("unspecified");
6633 staticpro (&Qunspecified
);
6634 Qignore_defface
= intern_c_string (":ignore-defface");
6635 staticpro (&Qignore_defface
);
6637 Qface_alias
= intern_c_string ("face-alias");
6638 staticpro (&Qface_alias
);
6639 Qdefault
= intern_c_string ("default");
6640 staticpro (&Qdefault
);
6641 Qtool_bar
= intern_c_string ("tool-bar");
6642 staticpro (&Qtool_bar
);
6643 Qregion
= intern_c_string ("region");
6644 staticpro (&Qregion
);
6645 Qfringe
= intern_c_string ("fringe");
6646 staticpro (&Qfringe
);
6647 Qheader_line
= intern_c_string ("header-line");
6648 staticpro (&Qheader_line
);
6649 Qscroll_bar
= intern_c_string ("scroll-bar");
6650 staticpro (&Qscroll_bar
);
6651 Qmenu
= intern_c_string ("menu");
6653 Qcursor
= intern_c_string ("cursor");
6654 staticpro (&Qcursor
);
6655 Qborder
= intern_c_string ("border");
6656 staticpro (&Qborder
);
6657 Qmouse
= intern_c_string ("mouse");
6658 staticpro (&Qmouse
);
6659 Qmode_line_inactive
= intern_c_string ("mode-line-inactive");
6660 staticpro (&Qmode_line_inactive
);
6661 Qvertical_border
= intern_c_string ("vertical-border");
6662 staticpro (&Qvertical_border
);
6663 Qtty_color_desc
= intern_c_string ("tty-color-desc");
6664 staticpro (&Qtty_color_desc
);
6665 Qtty_color_standard_values
= intern_c_string ("tty-color-standard-values");
6666 staticpro (&Qtty_color_standard_values
);
6667 Qtty_color_by_index
= intern_c_string ("tty-color-by-index");
6668 staticpro (&Qtty_color_by_index
);
6669 Qtty_color_alist
= intern_c_string ("tty-color-alist");
6670 staticpro (&Qtty_color_alist
);
6671 Qscalable_fonts_allowed
= intern_c_string ("scalable-fonts-allowed");
6672 staticpro (&Qscalable_fonts_allowed
);
6674 Vparam_value_alist
= Fcons (Fcons (Qnil
, Qnil
), Qnil
);
6675 staticpro (&Vparam_value_alist
);
6676 Vface_alternative_font_family_alist
= Qnil
;
6677 staticpro (&Vface_alternative_font_family_alist
);
6678 Vface_alternative_font_registry_alist
= Qnil
;
6679 staticpro (&Vface_alternative_font_registry_alist
);
6681 defsubr (&Sinternal_make_lisp_face
);
6682 defsubr (&Sinternal_lisp_face_p
);
6683 defsubr (&Sinternal_set_lisp_face_attribute
);
6684 #ifdef HAVE_WINDOW_SYSTEM
6685 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
6687 defsubr (&Scolor_gray_p
);
6688 defsubr (&Scolor_supported_p
);
6689 #ifndef HAVE_X_WINDOWS
6690 defsubr (&Sx_load_color_file
);
6692 defsubr (&Sface_attribute_relative_p
);
6693 defsubr (&Smerge_face_attribute
);
6694 defsubr (&Sinternal_get_lisp_face_attribute
);
6695 defsubr (&Sinternal_lisp_face_attribute_values
);
6696 defsubr (&Sinternal_lisp_face_equal_p
);
6697 defsubr (&Sinternal_lisp_face_empty_p
);
6698 defsubr (&Sinternal_copy_lisp_face
);
6699 defsubr (&Sinternal_merge_in_global_face
);
6700 defsubr (&Sface_font
);
6701 defsubr (&Sframe_face_alist
);
6702 defsubr (&Sdisplay_supports_face_attributes_p
);
6703 defsubr (&Scolor_distance
);
6704 defsubr (&Sinternal_set_font_selection_order
);
6705 defsubr (&Sinternal_set_alternative_font_family_alist
);
6706 defsubr (&Sinternal_set_alternative_font_registry_alist
);
6707 defsubr (&Sface_attributes_as_vector
);
6709 defsubr (&Sdump_face
);
6710 defsubr (&Sshow_face_resources
);
6711 #endif /* GLYPH_DEBUG */
6712 defsubr (&Sclear_face_cache
);
6713 defsubr (&Stty_suppress_bold_inverse_default_colors
);
6715 #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS
6716 defsubr (&Sdump_colors
);
6719 DEFVAR_LISP ("font-list-limit", &Vfont_list_limit
,
6720 doc
: /* *Limit for font matching.
6721 If an integer > 0, font matching functions won't load more than
6722 that number of fonts when searching for a matching font. */);
6723 Vfont_list_limit
= make_number (DEFAULT_FONT_LIST_LIMIT
);
6725 DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults
,
6726 doc
: /* List of global face definitions (for internal use only.) */);
6727 Vface_new_frame_defaults
= Qnil
;
6729 DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple
,
6730 doc
: /* *Default stipple pattern used on monochrome displays.
6731 This stipple pattern is used on monochrome displays
6732 instead of shades of gray for a face background color.
6733 See `set-face-stipple' for possible values for this variable. */);
6734 Vface_default_stipple
= make_pure_c_string ("gray3");
6736 DEFVAR_LISP ("tty-defined-color-alist", &Vtty_defined_color_alist
,
6737 doc
: /* An alist of defined terminal colors and their RGB values. */);
6738 Vtty_defined_color_alist
= Qnil
;
6740 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed
,
6741 doc
: /* Allowed scalable fonts.
6742 A value of nil means don't allow any scalable fonts.
6743 A value of t means allow any scalable font.
6744 Otherwise, value must be a list of regular expressions. A font may be
6745 scaled if its name matches a regular expression in the list.
6746 Note that if value is nil, a scalable font might still be used, if no
6747 other font of the appropriate family and registry is available. */);
6748 Vscalable_fonts_allowed
= Qnil
;
6750 DEFVAR_LISP ("face-ignored-fonts", &Vface_ignored_fonts
,
6751 doc
: /* List of ignored fonts.
6752 Each element is a regular expression that matches names of fonts to
6754 Vface_ignored_fonts
= Qnil
;
6756 DEFVAR_LISP ("face-remapping-alist", &Vface_remapping_alist
,
6757 doc
: /* Alist of face remappings.
6758 Each element is of the form:
6760 (FACE REPLACEMENT...),
6762 which causes display of the face FACE to use REPLACEMENT... instead.
6763 REPLACEMENT... is interpreted the same way as the value of a `face'
6764 text property: it may be (1) A face name, (2) A list of face names,
6765 (3) A property-list of face attribute/value pairs, or (4) A list of
6766 face names or lists containing face attribute/value pairs.
6768 Multiple entries in REPLACEMENT... are merged together to form the final
6769 result, with faces or attributes earlier in the list taking precedence
6770 over those that are later.
6772 Face-name remapping cycles are suppressed; recursive references use the
6773 underlying face instead of the remapped face. So a remapping of the form:
6775 (FACE EXTRA-FACE... FACE)
6779 (FACE (FACE-ATTR VAL ...) FACE)
6781 will cause EXTRA-FACE... or (FACE-ATTR VAL ...) to be _merged_ with the
6782 existing definition of FACE. Note that for the default face, this isn't
6783 necessary, as every face inherits from the default face.
6785 Making this variable buffer-local is a good way to allow buffer-specific
6786 face definitions. For instance, the mode my-mode could define a face
6787 `my-mode-default', and then in the mode setup function, do:
6789 (set (make-local-variable 'face-remapping-alist)
6790 '((default my-mode-default)))).
6792 Because Emacs normally only redraws screen areas when the underlying
6793 buffer contents change, you may need to call `redraw-display' after
6794 changing this variable for it to take effect. */);
6795 Vface_remapping_alist
= Qnil
;
6797 DEFVAR_LISP ("face-font-rescale-alist", &Vface_font_rescale_alist
,
6798 doc
: /* Alist of fonts vs the rescaling factors.
6799 Each element is a cons (FONT-PATTERN . RESCALE-RATIO), where
6800 FONT-PATTERN is a font-spec or a regular expression matching a font name, and
6801 RESCALE-RATIO is a floating point number to specify how much larger
6802 \(or smaller) font we should use. For instance, if a face requests
6803 a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point. */);
6804 Vface_font_rescale_alist
= Qnil
;
6806 #ifdef HAVE_WINDOW_SYSTEM
6807 defsubr (&Sbitmap_spec_p
);
6808 defsubr (&Sx_list_fonts
);
6809 defsubr (&Sinternal_face_x_get_resource
);
6810 defsubr (&Sx_family_fonts
);
6814 /* arch-tag: 8a0f7598-5517-408d-9ab3-1da6fcd4c749
6815 (do not change this comment) */