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 /* Keywords symbols used for font properties. */
325 extern Lisp_Object QCfoundry
, QCadstyle
, QCregistry
;
326 extern Lisp_Object QCspacing
, QCsize
, QCavgwidth
;
327 extern Lisp_Object Qp
;
329 /* Symbols used for attribute values. */
331 Lisp_Object Qnormal
, Qbold
, Qultra_light
, Qextra_light
, Qlight
;
332 Lisp_Object Qsemi_light
, Qsemi_bold
, Qextra_bold
, Qultra_bold
;
333 Lisp_Object Qoblique
, Qitalic
, Qreverse_oblique
, Qreverse_italic
;
334 Lisp_Object Qultra_condensed
, Qextra_condensed
, Qcondensed
;
335 Lisp_Object Qsemi_condensed
, Qsemi_expanded
, Qexpanded
, Qextra_expanded
;
336 Lisp_Object Qultra_expanded
;
337 Lisp_Object Qreleased_button
, Qpressed_button
;
338 Lisp_Object QCstyle
, QCcolor
, QCline_width
;
339 Lisp_Object Qunspecified
;
340 Lisp_Object Qignore_defface
;
342 char unspecified_fg
[] = "unspecified-fg", unspecified_bg
[] = "unspecified-bg";
344 /* The name of the function to call when the background of the frame
345 has changed, frame_set_background_mode. */
347 Lisp_Object Qframe_set_background_mode
;
349 /* Names of basic faces. */
351 Lisp_Object Qdefault
, Qtool_bar
, Qregion
, Qfringe
;
352 Lisp_Object Qheader_line
, Qscroll_bar
, Qcursor
, Qborder
, Qmouse
, Qmenu
;
353 Lisp_Object Qmode_line_inactive
, Qvertical_border
;
354 extern Lisp_Object Qmode_line
;
356 /* The symbol `face-alias'. A symbols having that property is an
357 alias for another face. Value of the property is the name of
360 Lisp_Object Qface_alias
;
362 extern Lisp_Object Qcircular_list
;
364 /* Default stipple pattern used on monochrome displays. This stipple
365 pattern is used on monochrome displays instead of shades of gray
366 for a face background color. See `set-face-stipple' for possible
367 values for this variable. */
369 Lisp_Object Vface_default_stipple
;
371 /* Alist of alternative font families. Each element is of the form
372 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
373 try FAMILY1, then FAMILY2, ... */
375 Lisp_Object Vface_alternative_font_family_alist
;
377 /* Alist of alternative font registries. Each element is of the form
378 (REGISTRY REGISTRY1 REGISTRY2...). If fonts of REGISTRY can't be
379 loaded, try REGISTRY1, then REGISTRY2, ... */
381 Lisp_Object Vface_alternative_font_registry_alist
;
383 /* Allowed scalable fonts. A value of nil means don't allow any
384 scalable fonts. A value of t means allow the use of any scalable
385 font. Otherwise, value must be a list of regular expressions. A
386 font may be scaled if its name matches a regular expression in the
389 Lisp_Object Vscalable_fonts_allowed
, Qscalable_fonts_allowed
;
391 /* List of regular expressions that matches names of fonts to ignore. */
393 Lisp_Object Vface_ignored_fonts
;
395 /* Alist of font name patterns vs the rescaling factor. */
397 Lisp_Object Vface_font_rescale_alist
;
399 /* Maximum number of fonts to consider in font_list. If not an
400 integer > 0, DEFAULT_FONT_LIST_LIMIT is used instead. */
402 Lisp_Object Vfont_list_limit
;
403 #define DEFAULT_FONT_LIST_LIMIT 100
405 /* The symbols `foreground-color' and `background-color' which can be
406 used as part of a `face' property. This is for compatibility with
409 Lisp_Object Qforeground_color
, Qbackground_color
;
411 /* The symbols `face' and `mouse-face' used as text properties. */
414 extern Lisp_Object Qmouse_face
;
416 /* Property for basic faces which other faces cannot inherit. */
418 Lisp_Object Qface_no_inherit
;
420 /* Error symbol for wrong_type_argument in load_pixmap. */
422 Lisp_Object Qbitmap_spec_p
;
424 /* Alist of global face definitions. Each element is of the form
425 (FACE . LFACE) where FACE is a symbol naming a face and LFACE
426 is a Lisp vector of face attributes. These faces are used
427 to initialize faces for new frames. */
429 Lisp_Object Vface_new_frame_defaults
;
431 /* Alist of face remappings. Each element is of the form:
432 (FACE REPLACEMENT...) which causes display of the face FACE to use
433 REPLACEMENT... instead. REPLACEMENT... is interpreted the same way
434 the value of a `face' text property is: it may be (1) A face name,
435 (2) A list of face names, (3) A property-list of face attribute/value
436 pairs, or (4) A list of face names intermixed with lists containing
437 face attribute/value pairs.
439 Multiple entries in REPLACEMENT... are merged together to form the final
440 result, with faces or attributes earlier in the list taking precedence
441 over those that are later.
443 Face-name remapping cycles are suppressed; recursive references use
444 the underlying face instead of the remapped face. */
446 Lisp_Object Vface_remapping_alist
;
448 /* The next ID to assign to Lisp faces. */
450 static int next_lface_id
;
452 /* A vector mapping Lisp face Id's to face names. */
454 static Lisp_Object
*lface_id_to_name
;
455 static int lface_id_to_name_size
;
457 /* TTY color-related functions (defined in tty-colors.el). */
459 Lisp_Object Qtty_color_desc
, Qtty_color_by_index
, Qtty_color_standard_values
;
461 /* The name of the function used to compute colors on TTYs. */
463 Lisp_Object Qtty_color_alist
;
465 /* An alist of defined terminal colors and their RGB values. */
467 Lisp_Object Vtty_defined_color_alist
;
469 /* Counter for calls to clear_face_cache. If this counter reaches
470 CLEAR_FONT_TABLE_COUNT, and a frame has more than
471 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
473 static int clear_font_table_count
;
474 #define CLEAR_FONT_TABLE_COUNT 100
475 #define CLEAR_FONT_TABLE_NFONTS 10
477 /* Non-zero means face attributes have been changed since the last
478 redisplay. Used in redisplay_internal. */
480 int face_change_count
;
482 /* Non-zero means don't display bold text if a face's foreground
483 and background colors are the inverse of the default colors of the
484 display. This is a kluge to suppress `bold black' foreground text
485 which is hard to read on an LCD monitor. */
487 int tty_suppress_bold_inverse_default_colors_p
;
489 /* A list of the form `((x . y))' used to avoid consing in
490 Finternal_set_lisp_face_attribute. */
492 static Lisp_Object Vparam_value_alist
;
494 /* The total number of colors currently allocated. */
497 static int ncolors_allocated
;
498 static int npixmaps_allocated
;
502 /* Non-zero means the definition of the `menu' face for new frames has
505 int menu_face_changed_default
;
508 /* Function prototypes. */
511 struct named_merge_point
;
513 static void map_tty_color (struct frame
*, struct face
*,
514 enum lface_attribute_index
, int *);
515 static Lisp_Object
resolve_face_name (Lisp_Object
, int);
516 static int may_use_scalable_font_p (const char *);
517 static void set_font_frame_param (Lisp_Object
, Lisp_Object
);
518 static int get_lface_attributes (struct frame
*, Lisp_Object
, Lisp_Object
*,
519 int, struct named_merge_point
*);
520 static int load_pixmap (struct frame
*, Lisp_Object
, unsigned *, unsigned *);
521 static struct frame
*frame_or_selected_frame (Lisp_Object
, int);
522 static void load_face_colors (struct frame
*, struct face
*, Lisp_Object
*);
523 static void free_face_colors (struct frame
*, struct face
*);
524 static int face_color_gray_p (struct frame
*, char *);
525 static struct face
*realize_face (struct face_cache
*, Lisp_Object
*,
527 static struct face
*realize_non_ascii_face (struct frame
*, Lisp_Object
,
529 static struct face
*realize_x_face (struct face_cache
*, Lisp_Object
*);
530 static struct face
*realize_tty_face (struct face_cache
*, Lisp_Object
*);
531 static int realize_basic_faces (struct frame
*);
532 static int realize_default_face (struct frame
*);
533 static void realize_named_face (struct frame
*, Lisp_Object
, int);
534 static int lface_fully_specified_p (Lisp_Object
*);
535 static int lface_equal_p (Lisp_Object
*, Lisp_Object
*);
536 static unsigned hash_string_case_insensitive (Lisp_Object
);
537 static unsigned lface_hash (Lisp_Object
*);
538 static int lface_same_font_attributes_p (Lisp_Object
*, Lisp_Object
*);
539 static struct face_cache
*make_face_cache (struct frame
*);
540 static void clear_face_gcs (struct face_cache
*);
541 static void free_face_cache (struct face_cache
*);
542 static int face_fontset (Lisp_Object
*);
543 static void merge_face_vectors (struct frame
*, Lisp_Object
*, Lisp_Object
*,
544 struct named_merge_point
*);
545 static int merge_face_ref (struct frame
*, Lisp_Object
, Lisp_Object
*,
546 int, struct named_merge_point
*);
547 static int set_lface_from_font (struct frame
*, Lisp_Object
, Lisp_Object
,
549 static Lisp_Object
lface_from_face_name (struct frame
*, Lisp_Object
, int);
550 static struct face
*make_realized_face (Lisp_Object
*);
551 static void cache_face (struct face_cache
*, struct face
*, unsigned);
552 static void uncache_face (struct face_cache
*, struct face
*);
554 #ifdef HAVE_WINDOW_SYSTEM
556 static GC
x_create_gc (struct frame
*, unsigned long, XGCValues
*);
557 static void x_free_gc (struct frame
*, GC
);
560 static void x_update_menu_appearance (struct frame
*);
562 extern void free_frame_menubar (struct frame
*);
563 #endif /* USE_X_TOOLKIT */
565 #endif /* HAVE_WINDOW_SYSTEM */
568 /***********************************************************************
570 ***********************************************************************/
572 #ifdef HAVE_X_WINDOWS
574 #ifdef DEBUG_X_COLORS
576 /* The following is a poor mans infrastructure for debugging X color
577 allocation problems on displays with PseudoColor-8. Some X servers
578 like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement
579 color reference counts completely so that they don't signal an
580 error when a color is freed whose reference count is already 0.
581 Other X servers do. To help me debug this, the following code
582 implements a simple reference counting schema of its own, for a
583 single display/screen. --gerd. */
585 /* Reference counts for pixel colors. */
587 int color_count
[256];
589 /* Register color PIXEL as allocated. */
592 register_color (pixel
)
595 xassert (pixel
< 256);
596 ++color_count
[pixel
];
600 /* Register color PIXEL as deallocated. */
603 unregister_color (pixel
)
606 xassert (pixel
< 256);
607 if (color_count
[pixel
] > 0)
608 --color_count
[pixel
];
614 /* Register N colors from PIXELS as deallocated. */
617 unregister_colors (pixels
, n
)
618 unsigned long *pixels
;
622 for (i
= 0; i
< n
; ++i
)
623 unregister_color (pixels
[i
]);
627 DEFUN ("dump-colors", Fdump_colors
, Sdump_colors
, 0, 0, 0,
628 doc
: /* Dump currently allocated colors to stderr. */)
633 fputc ('\n', stderr
);
635 for (i
= n
= 0; i
< sizeof color_count
/ sizeof color_count
[0]; ++i
)
638 fprintf (stderr
, "%3d: %5d", i
, color_count
[i
]);
641 fputc ('\n', stderr
);
643 fputc ('\t', stderr
);
647 fputc ('\n', stderr
);
651 #endif /* DEBUG_X_COLORS */
654 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
655 color values. Interrupt input must be blocked when this function
659 x_free_colors (struct frame
*f
, long unsigned int *pixels
, int npixels
)
661 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
663 /* If display has an immutable color map, freeing colors is not
664 necessary and some servers don't allow it. So don't do it. */
665 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
667 #ifdef DEBUG_X_COLORS
668 unregister_colors (pixels
, npixels
);
670 XFreeColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
676 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
677 color values. Interrupt input must be blocked when this function
681 x_free_dpy_colors (Display
*dpy
, Screen
*screen
, Colormap cmap
, long unsigned int *pixels
, int npixels
)
683 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
684 int class = dpyinfo
->visual
->class;
686 /* If display has an immutable color map, freeing colors is not
687 necessary and some servers don't allow it. So don't do it. */
688 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
690 #ifdef DEBUG_X_COLORS
691 unregister_colors (pixels
, npixels
);
693 XFreeColors (dpy
, cmap
, pixels
, npixels
, 0);
698 /* Create and return a GC for use on frame F. GC values and mask
699 are given by XGCV and MASK. */
702 x_create_gc (struct frame
*f
, long unsigned int mask
, XGCValues
*xgcv
)
706 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
713 /* Free GC which was used on frame F. */
716 x_free_gc (struct frame
*f
, GC gc
)
718 eassert (interrupt_input_blocked
);
719 IF_DEBUG (xassert (--ngcs
>= 0));
720 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
723 #endif /* HAVE_X_WINDOWS */
726 /* W32 emulation of GCs */
729 x_create_gc (f
, mask
, xgcv
)
736 gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, xgcv
);
743 /* Free GC which was used on frame F. */
750 IF_DEBUG (xassert (--ngcs
>= 0));
754 #endif /* WINDOWSNT */
757 /* NS emulation of GCs */
760 x_create_gc (f
, mask
, xgcv
)
765 GC gc
= xmalloc (sizeof (*gc
));
767 memcpy (gc
, xgcv
, sizeof (XGCValues
));
780 /* Like strcasecmp/stricmp. Used to compare parts of font names which
784 xstrcasecmp (const unsigned char *s1
, const unsigned char *s2
)
788 unsigned char c1
= tolower (*s1
);
789 unsigned char c2
= tolower (*s2
);
791 return c1
< c2
? -1 : 1;
796 return *s2
== 0 ? 0 : -1;
801 /* If FRAME is nil, return a pointer to the selected frame.
802 Otherwise, check that FRAME is a live frame, and return a pointer
803 to it. NPARAM is the parameter number of FRAME, for
804 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
805 Lisp function definitions. */
807 static INLINE
struct frame
*
808 frame_or_selected_frame (Lisp_Object frame
, int nparam
)
811 frame
= selected_frame
;
813 CHECK_LIVE_FRAME (frame
);
814 return XFRAME (frame
);
818 /***********************************************************************
820 ***********************************************************************/
822 /* Initialize face cache and basic faces for frame F. */
825 init_frame_faces (struct frame
*f
)
827 /* Make a face cache, if F doesn't have one. */
828 if (FRAME_FACE_CACHE (f
) == NULL
)
829 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
831 #ifdef HAVE_WINDOW_SYSTEM
832 /* Make the image cache. */
833 if (FRAME_WINDOW_P (f
))
835 /* We initialize the image cache when creating the first frame
836 on a terminal, and not during terminal creation. This way,
837 `x-open-connection' on a tty won't create an image cache. */
838 if (FRAME_IMAGE_CACHE (f
) == NULL
)
839 FRAME_IMAGE_CACHE (f
) = make_image_cache ();
840 ++FRAME_IMAGE_CACHE (f
)->refcount
;
842 #endif /* HAVE_WINDOW_SYSTEM */
844 /* Realize basic faces. Must have enough information in frame
845 parameters to realize basic faces at this point. */
846 #ifdef HAVE_X_WINDOWS
847 if (!FRAME_X_P (f
) || FRAME_X_WINDOW (f
))
850 if (!FRAME_WINDOW_P (f
) || FRAME_W32_WINDOW (f
))
853 if (!FRAME_NS_P (f
) || FRAME_NS_WINDOW (f
))
855 if (!realize_basic_faces (f
))
860 /* Free face cache of frame F. Called from delete_frame. */
863 free_frame_faces (struct frame
*f
)
865 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
869 free_face_cache (face_cache
);
870 FRAME_FACE_CACHE (f
) = NULL
;
873 #ifdef HAVE_WINDOW_SYSTEM
874 if (FRAME_WINDOW_P (f
))
876 struct image_cache
*image_cache
= FRAME_IMAGE_CACHE (f
);
879 --image_cache
->refcount
;
880 if (image_cache
->refcount
== 0)
881 free_image_cache (f
);
884 #endif /* HAVE_WINDOW_SYSTEM */
888 /* Clear face caches, and recompute basic faces for frame F. Call
889 this after changing frame parameters on which those faces depend,
890 or when realized faces have been freed due to changing attributes
894 recompute_basic_faces (struct frame
*f
)
896 if (FRAME_FACE_CACHE (f
))
898 clear_face_cache (0);
899 if (!realize_basic_faces (f
))
905 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
906 try to free unused fonts, too. */
909 clear_face_cache (int clear_fonts_p
)
911 #ifdef HAVE_WINDOW_SYSTEM
912 Lisp_Object tail
, frame
;
916 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
919 /* Not yet implemented. */
920 clear_font_cache (frame
);
923 /* From time to time see if we can unload some fonts. This also
924 frees all realized faces on all frames. Fonts needed by
925 faces will be loaded again when faces are realized again. */
926 clear_font_table_count
= 0;
928 FOR_EACH_FRAME (tail
, frame
)
930 struct frame
*f
= XFRAME (frame
);
931 if (FRAME_WINDOW_P (f
)
932 && FRAME_X_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
933 free_all_realized_faces (frame
);
938 /* Clear GCs of realized faces. */
939 FOR_EACH_FRAME (tail
, frame
)
942 if (FRAME_WINDOW_P (f
))
943 clear_face_gcs (FRAME_FACE_CACHE (f
));
945 clear_image_caches (Qnil
);
947 #endif /* HAVE_WINDOW_SYSTEM */
951 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
952 doc
: /* Clear face caches on all frames.
953 Optional THOROUGHLY non-nil means try to free unused fonts, too. */)
955 Lisp_Object thoroughly
;
957 clear_face_cache (!NILP (thoroughly
));
959 ++windows_or_buffers_changed
;
964 /***********************************************************************
966 ***********************************************************************/
968 #ifdef HAVE_WINDOW_SYSTEM
970 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
971 doc
: /* Value is non-nil if OBJECT is a valid bitmap specification.
972 A bitmap specification is either a string, a file name, or a list
973 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
974 HEIGHT is its height, and DATA is a string containing the bits of
975 the pixmap. Bits are stored row by row, each row occupies
976 \(WIDTH + 7)/8 bytes. */)
982 if (STRINGP (object
))
983 /* If OBJECT is a string, it's a file name. */
985 else if (CONSP (object
))
987 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
988 HEIGHT must be integers > 0, and DATA must be string large
989 enough to hold a bitmap of the specified size. */
990 Lisp_Object width
, height
, data
;
992 height
= width
= data
= Qnil
;
996 width
= XCAR (object
);
997 object
= XCDR (object
);
1000 height
= XCAR (object
);
1001 object
= XCDR (object
);
1003 data
= XCAR (object
);
1007 if (NATNUMP (width
) && NATNUMP (height
) && STRINGP (data
))
1009 int bytes_per_row
= ((XFASTINT (width
) + BITS_PER_CHAR
- 1)
1011 if (SBYTES (data
) >= bytes_per_row
* XINT (height
))
1016 return pixmap_p
? Qt
: Qnil
;
1020 /* Load a bitmap according to NAME (which is either a file name or a
1021 pixmap spec) for use on frame F. Value is the bitmap_id (see
1022 xfns.c). If NAME is nil, return with a bitmap id of zero. If
1023 bitmap cannot be loaded, display a message saying so, and return
1024 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
1025 if these pointers are not null. */
1028 load_pixmap (FRAME_PTR f
, Lisp_Object name
, unsigned int *w_ptr
, unsigned int *h_ptr
)
1035 CHECK_TYPE (!NILP (Fbitmap_spec_p (name
)), Qbitmap_spec_p
, name
);
1040 /* Decode a bitmap spec into a bitmap. */
1045 w
= XINT (Fcar (name
));
1046 h
= XINT (Fcar (Fcdr (name
)));
1047 bits
= Fcar (Fcdr (Fcdr (name
)));
1049 bitmap_id
= x_create_bitmap_from_data (f
, SDATA (bits
),
1054 /* It must be a string -- a file name. */
1055 bitmap_id
= x_create_bitmap_from_file (f
, name
);
1061 add_to_log ("Invalid or undefined bitmap `%s'", name
, Qnil
);
1072 ++npixmaps_allocated
;
1075 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
1078 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
1084 #endif /* HAVE_WINDOW_SYSTEM */
1088 /***********************************************************************
1090 ***********************************************************************/
1092 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
1093 RGB_LIST should contain (at least) 3 lisp integers.
1094 Return 0 if there's a problem with RGB_LIST, otherwise return 1. */
1097 parse_rgb_list (Lisp_Object rgb_list
, XColor
*color
)
1099 #define PARSE_RGB_LIST_FIELD(field) \
1100 if (CONSP (rgb_list) && INTEGERP (XCAR (rgb_list))) \
1102 color->field = XINT (XCAR (rgb_list)); \
1103 rgb_list = XCDR (rgb_list); \
1108 PARSE_RGB_LIST_FIELD (red
);
1109 PARSE_RGB_LIST_FIELD (green
);
1110 PARSE_RGB_LIST_FIELD (blue
);
1116 /* Lookup on frame F the color described by the lisp string COLOR.
1117 The resulting tty color is returned in TTY_COLOR; if STD_COLOR is
1118 non-zero, then the `standard' definition of the same color is
1122 tty_lookup_color (struct frame
*f
, Lisp_Object color
, XColor
*tty_color
, XColor
*std_color
)
1124 Lisp_Object frame
, color_desc
;
1126 if (!STRINGP (color
) || NILP (Ffboundp (Qtty_color_desc
)))
1129 XSETFRAME (frame
, f
);
1131 color_desc
= call2 (Qtty_color_desc
, color
, frame
);
1132 if (CONSP (color_desc
) && CONSP (XCDR (color_desc
)))
1136 if (! INTEGERP (XCAR (XCDR (color_desc
))))
1139 tty_color
->pixel
= XINT (XCAR (XCDR (color_desc
)));
1141 rgb
= XCDR (XCDR (color_desc
));
1142 if (! parse_rgb_list (rgb
, tty_color
))
1145 /* Should we fill in STD_COLOR too? */
1148 /* Default STD_COLOR to the same as TTY_COLOR. */
1149 *std_color
= *tty_color
;
1151 /* Do a quick check to see if the returned descriptor is
1152 actually _exactly_ equal to COLOR, otherwise we have to
1153 lookup STD_COLOR separately. If it's impossible to lookup
1154 a standard color, we just give up and use TTY_COLOR. */
1155 if ((!STRINGP (XCAR (color_desc
))
1156 || NILP (Fstring_equal (color
, XCAR (color_desc
))))
1157 && !NILP (Ffboundp (Qtty_color_standard_values
)))
1159 /* Look up STD_COLOR separately. */
1160 rgb
= call1 (Qtty_color_standard_values
, color
);
1161 if (! parse_rgb_list (rgb
, std_color
))
1168 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
1169 /* We were called early during startup, and the colors are not
1170 yet set up in tty-defined-color-alist. Don't return a failure
1171 indication, since this produces the annoying "Unable to
1172 load color" messages in the *Messages* buffer. */
1175 /* tty-color-desc seems to have returned a bad value. */
1179 /* A version of defined_color for non-X frames. */
1182 tty_defined_color (struct frame
*f
, char *color_name
, XColor
*color_def
, int alloc
)
1187 color_def
->pixel
= FACE_TTY_DEFAULT_COLOR
;
1189 color_def
->blue
= 0;
1190 color_def
->green
= 0;
1193 status
= tty_lookup_color (f
, build_string (color_name
), color_def
, NULL
);
1195 if (color_def
->pixel
== FACE_TTY_DEFAULT_COLOR
&& *color_name
)
1197 if (strcmp (color_name
, "unspecified-fg") == 0)
1198 color_def
->pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
1199 else if (strcmp (color_name
, "unspecified-bg") == 0)
1200 color_def
->pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
1203 if (color_def
->pixel
!= FACE_TTY_DEFAULT_COLOR
)
1210 /* Decide if color named COLOR_NAME is valid for the display
1211 associated with the frame F; if so, return the rgb values in
1212 COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell.
1214 This does the right thing for any type of frame. */
1217 defined_color (struct frame
*f
, char *color_name
, XColor
*color_def
, int alloc
)
1219 if (!FRAME_WINDOW_P (f
))
1220 return tty_defined_color (f
, color_name
, color_def
, alloc
);
1221 #ifdef HAVE_X_WINDOWS
1222 else if (FRAME_X_P (f
))
1223 return x_defined_color (f
, color_name
, color_def
, alloc
);
1226 else if (FRAME_W32_P (f
))
1227 return w32_defined_color (f
, color_name
, color_def
, alloc
);
1230 else if (FRAME_NS_P (f
))
1231 return ns_defined_color (f
, color_name
, color_def
, alloc
, 1);
1238 /* Given the index IDX of a tty color on frame F, return its name, a
1242 tty_color_name (struct frame
*f
, int idx
)
1244 if (idx
>= 0 && !NILP (Ffboundp (Qtty_color_by_index
)))
1247 Lisp_Object coldesc
;
1249 XSETFRAME (frame
, f
);
1250 coldesc
= call2 (Qtty_color_by_index
, make_number (idx
), frame
);
1252 if (!NILP (coldesc
))
1253 return XCAR (coldesc
);
1256 /* We can have an MSDOG frame under -nw for a short window of
1257 opportunity before internal_terminal_init is called. DTRT. */
1258 if (FRAME_MSDOS_P (f
) && !inhibit_window_system
)
1259 return msdos_stdcolor_name (idx
);
1262 if (idx
== FACE_TTY_DEFAULT_FG_COLOR
)
1263 return build_string (unspecified_fg
);
1264 if (idx
== FACE_TTY_DEFAULT_BG_COLOR
)
1265 return build_string (unspecified_bg
);
1267 return Qunspecified
;
1271 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1274 The criterion implemented here is not a terribly sophisticated one. */
1277 face_color_gray_p (struct frame
*f
, char *color_name
)
1282 if (defined_color (f
, color_name
, &color
, 0))
1283 gray_p
= (/* Any color sufficiently close to black counts as grey. */
1284 (color
.red
< 5000 && color
.green
< 5000 && color
.blue
< 5000)
1286 ((eabs (color
.red
- color
.green
)
1287 < max (color
.red
, color
.green
) / 20)
1288 && (eabs (color
.green
- color
.blue
)
1289 < max (color
.green
, color
.blue
) / 20)
1290 && (eabs (color
.blue
- color
.red
)
1291 < max (color
.blue
, color
.red
) / 20)));
1299 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1300 BACKGROUND_P non-zero means the color will be used as background
1304 face_color_supported_p (struct frame
*f
, char *color_name
, int background_p
)
1309 XSETFRAME (frame
, f
);
1311 #ifdef HAVE_WINDOW_SYSTEM
1313 ? (!NILP (Fxw_display_color_p (frame
))
1314 || xstrcasecmp (color_name
, "black") == 0
1315 || xstrcasecmp (color_name
, "white") == 0
1317 && face_color_gray_p (f
, color_name
))
1318 || (!NILP (Fx_display_grayscale_p (frame
))
1319 && face_color_gray_p (f
, color_name
)))
1322 tty_defined_color (f
, color_name
, ¬_used
, 0);
1326 DEFUN ("color-gray-p", Fcolor_gray_p
, Scolor_gray_p
, 1, 2, 0,
1327 doc
: /* Return non-nil if COLOR is a shade of gray (or white or black).
1328 FRAME specifies the frame and thus the display for interpreting COLOR.
1329 If FRAME is nil or omitted, use the selected frame. */)
1331 Lisp_Object color
, frame
;
1335 CHECK_STRING (color
);
1337 frame
= selected_frame
;
1339 CHECK_FRAME (frame
);
1341 return face_color_gray_p (f
, SDATA (color
)) ? Qt
: Qnil
;
1345 DEFUN ("color-supported-p", Fcolor_supported_p
,
1346 Scolor_supported_p
, 1, 3, 0,
1347 doc
: /* Return non-nil if COLOR can be displayed on FRAME.
1348 BACKGROUND-P non-nil means COLOR is used as a background.
1349 Otherwise, this function tells whether it can be used as a foreground.
1350 If FRAME is nil or omitted, use the selected frame.
1351 COLOR must be a valid color name. */)
1352 (color
, frame
, background_p
)
1353 Lisp_Object frame
, color
, background_p
;
1357 CHECK_STRING (color
);
1359 frame
= selected_frame
;
1361 CHECK_FRAME (frame
);
1363 if (face_color_supported_p (f
, SDATA (color
), !NILP (background_p
)))
1369 /* Load color with name NAME for use by face FACE on frame F.
1370 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1371 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1372 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1373 pixel color. If color cannot be loaded, display a message, and
1374 return the foreground, background or underline color of F, but
1375 record that fact in flags of the face so that we don't try to free
1379 load_color (struct frame
*f
, struct face
*face
, Lisp_Object name
, enum lface_attribute_index target_index
)
1383 xassert (STRINGP (name
));
1384 xassert (target_index
== LFACE_FOREGROUND_INDEX
1385 || target_index
== LFACE_BACKGROUND_INDEX
1386 || target_index
== LFACE_UNDERLINE_INDEX
1387 || target_index
== LFACE_OVERLINE_INDEX
1388 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1389 || target_index
== LFACE_BOX_INDEX
);
1391 /* if the color map is full, defined_color will return a best match
1392 to the values in an existing cell. */
1393 if (!defined_color (f
, SDATA (name
), &color
, 1))
1395 add_to_log ("Unable to load color \"%s\"", name
, Qnil
);
1397 switch (target_index
)
1399 case LFACE_FOREGROUND_INDEX
:
1400 face
->foreground_defaulted_p
= 1;
1401 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1404 case LFACE_BACKGROUND_INDEX
:
1405 face
->background_defaulted_p
= 1;
1406 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1409 case LFACE_UNDERLINE_INDEX
:
1410 face
->underline_defaulted_p
= 1;
1411 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1414 case LFACE_OVERLINE_INDEX
:
1415 face
->overline_color_defaulted_p
= 1;
1416 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1419 case LFACE_STRIKE_THROUGH_INDEX
:
1420 face
->strike_through_color_defaulted_p
= 1;
1421 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1424 case LFACE_BOX_INDEX
:
1425 face
->box_color_defaulted_p
= 1;
1426 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1435 ++ncolors_allocated
;
1442 #ifdef HAVE_WINDOW_SYSTEM
1444 /* Load colors for face FACE which is used on frame F. Colors are
1445 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1446 of ATTRS. If the background color specified is not supported on F,
1447 try to emulate gray colors with a stipple from Vface_default_stipple. */
1450 load_face_colors (struct frame
*f
, struct face
*face
, Lisp_Object
*attrs
)
1454 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1455 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1457 /* Swap colors if face is inverse-video. */
1458 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1466 /* Check for support for foreground, not for background because
1467 face_color_supported_p is smart enough to know that grays are
1468 "supported" as background because we are supposed to use stipple
1470 if (!face_color_supported_p (f
, SDATA (bg
), 0)
1471 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1473 x_destroy_bitmap (f
, face
->stipple
);
1474 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1475 &face
->pixmap_w
, &face
->pixmap_h
);
1478 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1479 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1483 /* Free color PIXEL on frame F. */
1486 unload_color (struct frame
*f
, long unsigned int pixel
)
1488 #ifdef HAVE_X_WINDOWS
1492 x_free_colors (f
, &pixel
, 1);
1499 /* Free colors allocated for FACE. */
1502 free_face_colors (struct frame
*f
, struct face
*face
)
1504 /* PENDING(NS): need to do something here? */
1505 #ifdef HAVE_X_WINDOWS
1506 if (face
->colors_copied_bitwise_p
)
1511 if (!face
->foreground_defaulted_p
)
1513 x_free_colors (f
, &face
->foreground
, 1);
1514 IF_DEBUG (--ncolors_allocated
);
1517 if (!face
->background_defaulted_p
)
1519 x_free_colors (f
, &face
->background
, 1);
1520 IF_DEBUG (--ncolors_allocated
);
1523 if (face
->underline_p
1524 && !face
->underline_defaulted_p
)
1526 x_free_colors (f
, &face
->underline_color
, 1);
1527 IF_DEBUG (--ncolors_allocated
);
1530 if (face
->overline_p
1531 && !face
->overline_color_defaulted_p
)
1533 x_free_colors (f
, &face
->overline_color
, 1);
1534 IF_DEBUG (--ncolors_allocated
);
1537 if (face
->strike_through_p
1538 && !face
->strike_through_color_defaulted_p
)
1540 x_free_colors (f
, &face
->strike_through_color
, 1);
1541 IF_DEBUG (--ncolors_allocated
);
1544 if (face
->box
!= FACE_NO_BOX
1545 && !face
->box_color_defaulted_p
)
1547 x_free_colors (f
, &face
->box_color
, 1);
1548 IF_DEBUG (--ncolors_allocated
);
1552 #endif /* HAVE_X_WINDOWS */
1555 #endif /* HAVE_WINDOW_SYSTEM */
1559 /***********************************************************************
1561 ***********************************************************************/
1563 /* An enumerator for each field of an XLFD font name. */
1584 /* An enumerator for each possible slant value of a font. Taken from
1585 the XLFD specification. */
1593 XLFD_SLANT_REVERSE_ITALIC
,
1594 XLFD_SLANT_REVERSE_OBLIQUE
,
1598 /* Relative font weight according to XLFD documentation. */
1602 XLFD_WEIGHT_UNKNOWN
,
1603 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1604 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1605 XLFD_WEIGHT_LIGHT
, /* 30 */
1606 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1607 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1608 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1609 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1610 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1611 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1614 /* Relative proportionate width. */
1618 XLFD_SWIDTH_UNKNOWN
,
1619 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1620 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1621 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1622 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1623 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1624 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1625 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1626 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1627 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1630 /* Order by which font selection chooses fonts. The default values
1631 mean `first, find a best match for the font width, then for the
1632 font height, then for weight, then for slant.' This variable can be
1633 set via set-face-font-sort-order. */
1635 static int font_sort_order
[4];
1637 #ifdef HAVE_WINDOW_SYSTEM
1639 static enum font_property_index font_props_for_sorting
[FONT_SIZE_INDEX
];
1642 compare_fonts_by_sort_order (const void *v1
, const void *v2
)
1644 Lisp_Object font1
= *(Lisp_Object
*) v1
;
1645 Lisp_Object font2
= *(Lisp_Object
*) v2
;
1648 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1650 enum font_property_index idx
= font_props_for_sorting
[i
];
1651 Lisp_Object val1
= AREF (font1
, idx
), val2
= AREF (font2
, idx
);
1654 if (idx
<= FONT_REGISTRY_INDEX
)
1657 result
= STRINGP (val2
) ? strcmp (SDATA (val1
), SDATA (val2
)) : -1;
1659 result
= STRINGP (val2
) ? 1 : 0;
1663 if (INTEGERP (val1
))
1664 result
= INTEGERP (val2
) ? XINT (val1
) - XINT (val2
) : -1;
1666 result
= INTEGERP (val2
) ? 1 : 0;
1674 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
1675 doc
: /* Return a list of available fonts of family FAMILY on FRAME.
1676 If FAMILY is omitted or nil, list all families.
1677 Otherwise, FAMILY must be a string, possibly containing wildcards
1679 If FRAME is omitted or nil, use the selected frame.
1680 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
1681 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
1682 FAMILY is the font family name. POINT-SIZE is the size of the
1683 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
1684 width, weight and slant of the font. These symbols are the same as for
1685 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
1686 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
1687 giving the registry and encoding of the font.
1688 The result list is sorted according to the current setting of
1689 the face font sort order. */)
1691 Lisp_Object family
, frame
;
1693 Lisp_Object font_spec
, list
, *drivers
, vec
;
1694 int i
, nfonts
, ndrivers
;
1698 frame
= selected_frame
;
1699 CHECK_LIVE_FRAME (frame
);
1701 font_spec
= Ffont_spec (0, NULL
);
1704 CHECK_STRING (family
);
1705 font_parse_family_registry (family
, Qnil
, font_spec
);
1708 list
= font_list_entities (frame
, font_spec
);
1712 /* Sort the font entities. */
1713 for (i
= 0; i
< 4; i
++)
1714 switch (font_sort_order
[i
])
1717 font_props_for_sorting
[i
] = FONT_WIDTH_INDEX
; break;
1718 case XLFD_POINT_SIZE
:
1719 font_props_for_sorting
[i
] = FONT_SIZE_INDEX
; break;
1721 font_props_for_sorting
[i
] = FONT_WEIGHT_INDEX
; break;
1723 font_props_for_sorting
[i
] = FONT_SLANT_INDEX
; break;
1725 font_props_for_sorting
[i
++] = FONT_FAMILY_INDEX
;
1726 font_props_for_sorting
[i
++] = FONT_FOUNDRY_INDEX
;
1727 font_props_for_sorting
[i
++] = FONT_ADSTYLE_INDEX
;
1728 font_props_for_sorting
[i
++] = FONT_REGISTRY_INDEX
;
1730 ndrivers
= XINT (Flength (list
));
1731 drivers
= alloca (sizeof (Lisp_Object
) * ndrivers
);
1732 for (i
= 0; i
< ndrivers
; i
++, list
= XCDR (list
))
1733 drivers
[i
] = XCAR (list
);
1734 vec
= Fvconcat (ndrivers
, drivers
);
1735 nfonts
= ASIZE (vec
);
1737 qsort (XVECTOR (vec
)->contents
, nfonts
, sizeof (Lisp_Object
),
1738 compare_fonts_by_sort_order
);
1741 for (i
= nfonts
- 1; i
>= 0; --i
)
1743 Lisp_Object font
= AREF (vec
, i
);
1744 Lisp_Object v
= Fmake_vector (make_number (8), Qnil
);
1746 Lisp_Object spacing
;
1748 ASET (v
, 0, AREF (font
, FONT_FAMILY_INDEX
));
1749 ASET (v
, 1, FONT_WIDTH_SYMBOLIC (font
));
1750 point
= PIXEL_TO_POINT (XINT (AREF (font
, FONT_SIZE_INDEX
)) * 10,
1751 XFRAME (frame
)->resy
);
1752 ASET (v
, 2, make_number (point
));
1753 ASET (v
, 3, FONT_WEIGHT_SYMBOLIC (font
));
1754 ASET (v
, 4, FONT_SLANT_SYMBOLIC (font
));
1755 spacing
= Ffont_get (font
, QCspacing
);
1756 ASET (v
, 5, (NILP (spacing
) || EQ (spacing
, Qp
)) ? Qnil
: Qt
);
1757 ASET (v
, 6, Ffont_xlfd_name (font
, Qnil
));
1758 ASET (v
, 7, AREF (font
, FONT_REGISTRY_INDEX
));
1760 result
= Fcons (v
, result
);
1766 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
1767 doc
: /* Return a list of the names of available fonts matching PATTERN.
1768 If optional arguments FACE and FRAME are specified, return only fonts
1769 the same size as FACE on FRAME.
1771 PATTERN should be a string containing a font name in the XLFD,
1772 Fontconfig, or GTK format. A font name given in the XLFD format may
1773 contain wildcard characters:
1774 the * character matches any substring, and
1775 the ? character matches any single character.
1776 PATTERN is case-insensitive.
1778 The return value is a list of strings, suitable as arguments to
1781 Fonts Emacs can't use may or may not be excluded
1782 even if they match PATTERN and FACE.
1783 The optional fourth argument MAXIMUM sets a limit on how many
1784 fonts to match. The first MAXIMUM fonts are reported.
1785 The optional fifth argument WIDTH, if specified, is a number of columns
1786 occupied by a character of a font. In that case, return only fonts
1787 the WIDTH times as wide as FACE on FRAME. */)
1788 (pattern
, face
, frame
, maximum
, width
)
1789 Lisp_Object pattern
, face
, frame
, maximum
, width
;
1795 CHECK_STRING (pattern
);
1797 if (! NILP (maximum
))
1798 CHECK_NATNUM (maximum
);
1801 CHECK_NUMBER (width
);
1803 /* We can't simply call check_x_frame because this function may be
1804 called before any frame is created. */
1806 frame
= selected_frame
;
1807 f
= frame_or_selected_frame (frame
, 2);
1808 if (! FRAME_WINDOW_P (f
))
1810 /* Perhaps we have not yet created any frame. */
1816 /* Determine the width standard for comparison with the fonts we find. */
1822 /* This is of limited utility since it works with character
1823 widths. Keep it for compatibility. --gerd. */
1824 int face_id
= lookup_named_face (f
, face
, 0);
1825 struct face
*face
= (face_id
< 0
1827 : FACE_FROM_ID (f
, face_id
));
1829 if (face
&& face
->font
)
1831 size
= face
->font
->pixel_size
;
1832 avgwidth
= face
->font
->average_width
;
1836 size
= FRAME_FONT (f
)->pixel_size
;
1837 avgwidth
= FRAME_FONT (f
)->average_width
;
1840 avgwidth
*= XINT (width
);
1844 Lisp_Object font_spec
;
1845 Lisp_Object args
[2], tail
;
1847 font_spec
= font_spec_from_name (pattern
);
1848 if (!FONTP (font_spec
))
1849 signal_error ("Invalid font name", pattern
);
1853 Ffont_put (font_spec
, QCsize
, make_number (size
));
1854 Ffont_put (font_spec
, QCavgwidth
, make_number (avgwidth
));
1856 args
[0] = Flist_fonts (font_spec
, frame
, maximum
, font_spec
);
1857 for (tail
= args
[0]; CONSP (tail
); tail
= XCDR (tail
))
1859 Lisp_Object font_entity
;
1861 font_entity
= XCAR (tail
);
1862 if ((NILP (AREF (font_entity
, FONT_SIZE_INDEX
))
1863 || XINT (AREF (font_entity
, FONT_SIZE_INDEX
)) == 0)
1864 && ! NILP (AREF (font_spec
, FONT_SIZE_INDEX
)))
1866 /* This is a scalable font. For backward compatibility,
1867 we set the specified size. */
1868 font_entity
= Fcopy_font_spec (font_entity
);
1869 ASET (font_entity
, FONT_SIZE_INDEX
,
1870 AREF (font_spec
, FONT_SIZE_INDEX
));
1872 XSETCAR (tail
, Ffont_xlfd_name (font_entity
, Qnil
));
1875 /* We don't have to check fontsets. */
1877 args
[1] = list_fontsets (f
, pattern
, size
);
1878 return Fnconc (2, args
);
1882 #endif /* HAVE_WINDOW_SYSTEM */
1885 /***********************************************************************
1887 ***********************************************************************/
1889 /* Access face attributes of face LFACE, a Lisp vector. */
1891 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
1892 #define LFACE_FOUNDRY(LFACE) AREF ((LFACE), LFACE_FOUNDRY_INDEX)
1893 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
1894 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
1895 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
1896 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
1897 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
1898 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
1899 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
1900 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
1901 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
1902 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
1903 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
1904 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
1905 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
1906 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
1907 #define LFACE_FONTSET(LFACE) AREF ((LFACE), LFACE_FONTSET_INDEX)
1909 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
1910 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
1912 #define LFACEP(LFACE) \
1914 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \
1915 && EQ (AREF (LFACE, 0), Qface))
1920 /* Check consistency of Lisp face attribute vector ATTRS. */
1923 check_lface_attrs (attrs
)
1926 xassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
1927 || IGNORE_DEFFACE_P (attrs
[LFACE_FAMILY_INDEX
])
1928 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
1929 xassert (UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
1930 || IGNORE_DEFFACE_P (attrs
[LFACE_FOUNDRY_INDEX
])
1931 || STRINGP (attrs
[LFACE_FOUNDRY_INDEX
]));
1932 xassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
1933 || IGNORE_DEFFACE_P (attrs
[LFACE_SWIDTH_INDEX
])
1934 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
1935 xassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
1936 || IGNORE_DEFFACE_P (attrs
[LFACE_HEIGHT_INDEX
])
1937 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
])
1938 || FLOATP (attrs
[LFACE_HEIGHT_INDEX
])
1939 || FUNCTIONP (attrs
[LFACE_HEIGHT_INDEX
]));
1940 xassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
1941 || IGNORE_DEFFACE_P (attrs
[LFACE_WEIGHT_INDEX
])
1942 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
1943 xassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
1944 || IGNORE_DEFFACE_P (attrs
[LFACE_SLANT_INDEX
])
1945 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
1946 xassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
1947 || IGNORE_DEFFACE_P (attrs
[LFACE_UNDERLINE_INDEX
])
1948 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
1949 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]));
1950 xassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
1951 || IGNORE_DEFFACE_P (attrs
[LFACE_OVERLINE_INDEX
])
1952 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
1953 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
1954 xassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1955 || IGNORE_DEFFACE_P (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1956 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1957 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
1958 xassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
1959 || IGNORE_DEFFACE_P (attrs
[LFACE_BOX_INDEX
])
1960 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
1961 || STRINGP (attrs
[LFACE_BOX_INDEX
])
1962 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
1963 || CONSP (attrs
[LFACE_BOX_INDEX
]));
1964 xassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
1965 || IGNORE_DEFFACE_P (attrs
[LFACE_INVERSE_INDEX
])
1966 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
1967 xassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
1968 || IGNORE_DEFFACE_P (attrs
[LFACE_FOREGROUND_INDEX
])
1969 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
1970 xassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
1971 || IGNORE_DEFFACE_P (attrs
[LFACE_BACKGROUND_INDEX
])
1972 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
1973 xassert (UNSPECIFIEDP (attrs
[LFACE_INHERIT_INDEX
])
1974 || IGNORE_DEFFACE_P (attrs
[LFACE_INHERIT_INDEX
])
1975 || NILP (attrs
[LFACE_INHERIT_INDEX
])
1976 || SYMBOLP (attrs
[LFACE_INHERIT_INDEX
])
1977 || CONSP (attrs
[LFACE_INHERIT_INDEX
]));
1978 #ifdef HAVE_WINDOW_SYSTEM
1979 xassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
1980 || IGNORE_DEFFACE_P (attrs
[LFACE_STIPPLE_INDEX
])
1981 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
1982 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
1983 xassert (UNSPECIFIEDP (attrs
[LFACE_FONT_INDEX
])
1984 || IGNORE_DEFFACE_P (attrs
[LFACE_FONT_INDEX
])
1985 || FONTP (attrs
[LFACE_FONT_INDEX
]));
1986 xassert (UNSPECIFIEDP (attrs
[LFACE_FONTSET_INDEX
])
1987 || STRINGP (attrs
[LFACE_FONTSET_INDEX
]));
1992 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
2000 xassert (LFACEP (lface
));
2001 check_lface_attrs (XVECTOR (lface
)->contents
);
2005 #else /* GLYPH_DEBUG == 0 */
2007 #define check_lface_attrs(attrs) (void) 0
2008 #define check_lface(lface) (void) 0
2010 #endif /* GLYPH_DEBUG == 0 */
2014 /* Face-merge cycle checking. */
2016 enum named_merge_point_kind
2018 NAMED_MERGE_POINT_NORMAL
,
2019 NAMED_MERGE_POINT_REMAP
2022 /* A `named merge point' is simply a point during face-merging where we
2023 look up a face by name. We keep a stack of which named lookups we're
2024 currently processing so that we can easily detect cycles, using a
2025 linked- list of struct named_merge_point structures, typically
2026 allocated on the stack frame of the named lookup functions which are
2027 active (so no consing is required). */
2028 struct named_merge_point
2030 Lisp_Object face_name
;
2031 enum named_merge_point_kind named_merge_point_kind
;
2032 struct named_merge_point
*prev
;
2036 /* If a face merging cycle is detected for FACE_NAME, return 0,
2037 otherwise add NEW_NAMED_MERGE_POINT, which is initialized using
2038 FACE_NAME and NAMED_MERGE_POINT_KIND, as the head of the linked list
2039 pointed to by NAMED_MERGE_POINTS, and return 1. */
2042 push_named_merge_point (struct named_merge_point
*new_named_merge_point
,
2043 Lisp_Object face_name
,
2044 enum named_merge_point_kind named_merge_point_kind
,
2045 struct named_merge_point
**named_merge_points
)
2047 struct named_merge_point
*prev
;
2049 for (prev
= *named_merge_points
; prev
; prev
= prev
->prev
)
2050 if (EQ (face_name
, prev
->face_name
))
2052 if (prev
->named_merge_point_kind
== named_merge_point_kind
)
2053 /* A cycle, so fail. */
2055 else if (prev
->named_merge_point_kind
== NAMED_MERGE_POINT_REMAP
)
2056 /* A remap `hides ' any previous normal merge points
2057 (because the remap means that it's actually different face),
2058 so as we know the current merge point must be normal, we
2059 can just assume it's OK. */
2063 new_named_merge_point
->face_name
= face_name
;
2064 new_named_merge_point
->named_merge_point_kind
= named_merge_point_kind
;
2065 new_named_merge_point
->prev
= *named_merge_points
;
2067 *named_merge_points
= new_named_merge_point
;
2074 #if 0 /* Seems to be unused. */
2076 internal_resolve_face_name (nargs
, args
)
2080 return Fget (args
[0], args
[1]);
2084 resolve_face_name_error (ignore
)
2091 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
2092 to make it a symbol. If FACE_NAME is an alias for another face,
2093 return that face's name.
2095 Return default face in case of errors. */
2098 resolve_face_name (Lisp_Object face_name
, int signal_p
)
2100 Lisp_Object orig_face
;
2101 Lisp_Object tortoise
, hare
;
2103 if (STRINGP (face_name
))
2104 face_name
= intern (SDATA (face_name
));
2106 if (NILP (face_name
) || !SYMBOLP (face_name
))
2109 orig_face
= face_name
;
2110 tortoise
= hare
= face_name
;
2115 hare
= Fget (hare
, Qface_alias
);
2116 if (NILP (hare
) || !SYMBOLP (hare
))
2120 hare
= Fget (hare
, Qface_alias
);
2121 if (NILP (hare
) || !SYMBOLP (hare
))
2124 tortoise
= Fget (tortoise
, Qface_alias
);
2125 if (EQ (hare
, tortoise
))
2128 xsignal1 (Qcircular_list
, orig_face
);
2137 /* Return the face definition of FACE_NAME on frame F. F null means
2138 return the definition for new frames. FACE_NAME may be a string or
2139 a symbol (apparently Emacs 20.2 allowed strings as face names in
2140 face text properties; Ediff uses that). If SIGNAL_P is non-zero,
2141 signal an error if FACE_NAME is not a valid face name. If SIGNAL_P
2142 is zero, value is nil if FACE_NAME is not a valid face name. */
2143 static INLINE Lisp_Object
2144 lface_from_face_name_no_resolve (struct frame
*f
, Lisp_Object face_name
, int signal_p
)
2149 lface
= assq_no_quit (face_name
, f
->face_alist
);
2151 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
2154 lface
= XCDR (lface
);
2156 signal_error ("Invalid face", face_name
);
2158 check_lface (lface
);
2163 /* Return the face definition of FACE_NAME on frame F. F null means
2164 return the definition for new frames. FACE_NAME may be a string or
2165 a symbol (apparently Emacs 20.2 allowed strings as face names in
2166 face text properties; Ediff uses that). If FACE_NAME is an alias
2167 for another face, return that face's definition. If SIGNAL_P is
2168 non-zero, signal an error if FACE_NAME is not a valid face name.
2169 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
2171 static INLINE Lisp_Object
2172 lface_from_face_name (struct frame
*f
, Lisp_Object face_name
, int signal_p
)
2174 face_name
= resolve_face_name (face_name
, signal_p
);
2175 return lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2179 /* Get face attributes of face FACE_NAME from frame-local faces on
2180 frame F. Store the resulting attributes in ATTRS which must point
2181 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
2182 is non-zero, signal an error if FACE_NAME does not name a face.
2183 Otherwise, value is zero if FACE_NAME is not a face. */
2186 get_lface_attributes_no_remap (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*attrs
, int signal_p
)
2190 lface
= lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2193 memcpy (attrs
, XVECTOR (lface
)->contents
,
2194 LFACE_VECTOR_SIZE
* sizeof *attrs
);
2196 return !NILP (lface
);
2199 /* Get face attributes of face FACE_NAME from frame-local faces on frame
2200 F. Store the resulting attributes in ATTRS which must point to a
2201 vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If FACE_NAME is an
2202 alias for another face, use that face's definition. If SIGNAL_P is
2203 non-zero, signal an error if FACE_NAME does not name a face.
2204 Otherwise, value is zero if FACE_NAME is not a face. */
2207 get_lface_attributes (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*attrs
, int signal_p
, struct named_merge_point
*named_merge_points
)
2209 Lisp_Object face_remapping
;
2211 face_name
= resolve_face_name (face_name
, signal_p
);
2213 /* See if SYMBOL has been remapped to some other face (usually this
2214 is done buffer-locally). */
2215 face_remapping
= assq_no_quit (face_name
, Vface_remapping_alist
);
2216 if (CONSP (face_remapping
))
2218 struct named_merge_point named_merge_point
;
2220 if (push_named_merge_point (&named_merge_point
,
2221 face_name
, NAMED_MERGE_POINT_REMAP
,
2222 &named_merge_points
))
2226 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2227 attrs
[i
] = Qunspecified
;
2229 return merge_face_ref (f
, XCDR (face_remapping
), attrs
,
2230 signal_p
, named_merge_points
);
2234 /* Default case, no remapping. */
2235 return get_lface_attributes_no_remap (f
, face_name
, attrs
, signal_p
);
2239 /* Non-zero if all attributes in face attribute vector ATTRS are
2240 specified, i.e. are non-nil. */
2243 lface_fully_specified_p (Lisp_Object
*attrs
)
2247 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2248 if (i
!= LFACE_FONT_INDEX
&& i
!= LFACE_INHERIT_INDEX
)
2249 if ((UNSPECIFIEDP (attrs
[i
]) || IGNORE_DEFFACE_P (attrs
[i
])))
2252 return i
== LFACE_VECTOR_SIZE
;
2255 #ifdef HAVE_WINDOW_SYSTEM
2257 /* Set font-related attributes of Lisp face LFACE from FONT-OBJECT.
2258 If FORCE_P is zero, set only unspecified attributes of LFACE. The
2259 exception is `font' attribute. It is set to FONT_OBJECT regardless
2263 set_lface_from_font (struct frame
*f
, Lisp_Object lface
, Lisp_Object font_object
, int force_p
)
2266 struct font
*font
= XFONT_OBJECT (font_object
);
2268 /* Set attributes only if unspecified, otherwise face defaults for
2269 new frames would never take effect. If the font doesn't have a
2270 specific property, set a normal value for that. */
2272 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
2274 Lisp_Object family
= AREF (font_object
, FONT_FAMILY_INDEX
);
2276 LFACE_FAMILY (lface
) = SYMBOL_NAME (family
);
2279 if (force_p
|| UNSPECIFIEDP (LFACE_FOUNDRY (lface
)))
2281 Lisp_Object foundry
= AREF (font_object
, FONT_FOUNDRY_INDEX
);
2283 LFACE_FOUNDRY (lface
) = SYMBOL_NAME (foundry
);
2286 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
2288 int pt
= PIXEL_TO_POINT (font
->pixel_size
* 10, f
->resy
);
2291 LFACE_HEIGHT (lface
) = make_number (pt
);
2294 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
2296 val
= FONT_WEIGHT_FOR_FACE (font_object
);
2297 LFACE_WEIGHT (lface
) = ! NILP (val
) ? val
:Qnormal
;
2299 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
2301 val
= FONT_SLANT_FOR_FACE (font_object
);
2302 LFACE_SLANT (lface
) = ! NILP (val
) ? val
: Qnormal
;
2304 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
2306 val
= FONT_WIDTH_FOR_FACE (font_object
);
2307 LFACE_SWIDTH (lface
) = ! NILP (val
) ? val
: Qnormal
;
2310 LFACE_FONT (lface
) = font_object
;
2314 #endif /* HAVE_WINDOW_SYSTEM */
2317 /* Merges the face height FROM with the face height TO, and returns the
2318 merged height. If FROM is an invalid height, then INVALID is
2319 returned instead. FROM and TO may be either absolute face heights or
2320 `relative' heights; the returned value is always an absolute height
2321 unless both FROM and TO are relative. */
2324 merge_face_heights (Lisp_Object from
, Lisp_Object to
, Lisp_Object invalid
)
2326 Lisp_Object result
= invalid
;
2328 if (INTEGERP (from
))
2329 /* FROM is absolute, just use it as is. */
2331 else if (FLOATP (from
))
2332 /* FROM is a scale, use it to adjust TO. */
2335 /* relative X absolute => absolute */
2336 result
= make_number ((EMACS_INT
)(XFLOAT_DATA (from
) * XINT (to
)));
2337 else if (FLOATP (to
))
2338 /* relative X relative => relative */
2339 result
= make_float (XFLOAT_DATA (from
) * XFLOAT_DATA (to
));
2340 else if (UNSPECIFIEDP (to
))
2343 else if (FUNCTIONP (from
))
2344 /* FROM is a function, which use to adjust TO. */
2346 /* Call function with current height as argument.
2347 From is the new height. */
2348 Lisp_Object args
[2];
2352 result
= safe_call (2, args
);
2354 /* Ensure that if TO was absolute, so is the result. */
2355 if (INTEGERP (to
) && !INTEGERP (result
))
2363 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
2364 store the resulting attributes in TO, which must be already be
2365 completely specified and contain only absolute attributes. Every
2366 specified attribute of FROM overrides the corresponding attribute of
2367 TO; relative attributes in FROM are merged with the absolute value in
2368 TO and replace it. NAMED_MERGE_POINTS is used internally to detect
2369 loops in face inheritance/remapping; it should be 0 when called from
2373 merge_face_vectors (struct frame
*f
, Lisp_Object
*from
, Lisp_Object
*to
, struct named_merge_point
*named_merge_points
)
2377 /* If FROM inherits from some other faces, merge their attributes into
2378 TO before merging FROM's direct attributes. Note that an :inherit
2379 attribute of `unspecified' is the same as one of nil; we never
2380 merge :inherit attributes, so nil is more correct, but lots of
2381 other code uses `unspecified' as a generic value for face attributes. */
2382 if (!UNSPECIFIEDP (from
[LFACE_INHERIT_INDEX
])
2383 && !NILP (from
[LFACE_INHERIT_INDEX
]))
2384 merge_face_ref (f
, from
[LFACE_INHERIT_INDEX
], to
, 0, named_merge_points
);
2386 i
= LFACE_FONT_INDEX
;
2387 if (!UNSPECIFIEDP (from
[i
]))
2389 if (!UNSPECIFIEDP (to
[i
]))
2390 to
[i
] = Fmerge_font_spec (from
[i
], to
[i
]);
2392 to
[i
] = Fcopy_font_spec (from
[i
]);
2393 if (! NILP (AREF (to
[i
], FONT_FOUNDRY_INDEX
)))
2394 to
[LFACE_FOUNDRY_INDEX
] = SYMBOL_NAME (AREF (to
[i
], FONT_FOUNDRY_INDEX
));
2395 if (! NILP (AREF (to
[i
], FONT_FAMILY_INDEX
)))
2396 to
[LFACE_FAMILY_INDEX
] = SYMBOL_NAME (AREF (to
[i
], FONT_FAMILY_INDEX
));
2397 if (! NILP (AREF (to
[i
], FONT_WEIGHT_INDEX
)))
2398 to
[LFACE_WEIGHT_INDEX
] = FONT_WEIGHT_FOR_FACE (to
[i
]);
2399 if (! NILP (AREF (to
[i
], FONT_SLANT_INDEX
)))
2400 to
[LFACE_SLANT_INDEX
] = FONT_SLANT_FOR_FACE (to
[i
]);
2401 if (! NILP (AREF (to
[i
], FONT_WIDTH_INDEX
)))
2402 to
[LFACE_SWIDTH_INDEX
] = FONT_WIDTH_FOR_FACE (to
[i
]);
2403 ASET (to
[i
], FONT_SIZE_INDEX
, Qnil
);
2406 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2407 if (!UNSPECIFIEDP (from
[i
]))
2409 if (i
== LFACE_HEIGHT_INDEX
&& !INTEGERP (from
[i
]))
2411 to
[i
] = merge_face_heights (from
[i
], to
[i
], to
[i
]);
2412 font_clear_prop (to
, FONT_SIZE_INDEX
);
2414 else if (i
!= LFACE_FONT_INDEX
2415 && ! EQ (to
[i
], from
[i
]))
2418 if (i
>= LFACE_FAMILY_INDEX
&& i
<=LFACE_SLANT_INDEX
)
2419 font_clear_prop (to
,
2420 (i
== LFACE_FAMILY_INDEX
? FONT_FAMILY_INDEX
2421 : i
== LFACE_FOUNDRY_INDEX
? FONT_FOUNDRY_INDEX
2422 : i
== LFACE_SWIDTH_INDEX
? FONT_WIDTH_INDEX
2423 : i
== LFACE_HEIGHT_INDEX
? FONT_SIZE_INDEX
2424 : i
== LFACE_WEIGHT_INDEX
? FONT_WEIGHT_INDEX
2425 : FONT_SLANT_INDEX
));
2429 /* TO is always an absolute face, which should inherit from nothing.
2430 We blindly copy the :inherit attribute above and fix it up here. */
2431 to
[LFACE_INHERIT_INDEX
] = Qnil
;
2434 /* Merge the named face FACE_NAME on frame F, into the vector of face
2435 attributes TO. NAMED_MERGE_POINTS is used to detect loops in face
2436 inheritance. Returns true if FACE_NAME is a valid face name and
2437 merging succeeded. */
2440 merge_named_face (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*to
, struct named_merge_point
*named_merge_points
)
2442 struct named_merge_point named_merge_point
;
2444 if (push_named_merge_point (&named_merge_point
,
2445 face_name
, NAMED_MERGE_POINT_NORMAL
,
2446 &named_merge_points
))
2448 struct gcpro gcpro1
;
2449 Lisp_Object from
[LFACE_VECTOR_SIZE
];
2450 int ok
= get_lface_attributes (f
, face_name
, from
, 0, named_merge_points
);
2454 GCPRO1 (named_merge_point
.face_name
);
2455 merge_face_vectors (f
, from
, to
, named_merge_points
);
2466 /* Merge face attributes from the lisp `face reference' FACE_REF on
2467 frame F into the face attribute vector TO. If ERR_MSGS is non-zero,
2468 problems with FACE_REF cause an error message to be shown. Return
2469 non-zero if no errors occurred (regardless of the value of ERR_MSGS).
2470 NAMED_MERGE_POINTS is used to detect loops in face inheritance or
2471 list structure; it may be 0 for most callers.
2473 FACE_REF may be a single face specification or a list of such
2474 specifications. Each face specification can be:
2476 1. A symbol or string naming a Lisp face.
2478 2. A property list of the form (KEYWORD VALUE ...) where each
2479 KEYWORD is a face attribute name, and value is an appropriate value
2482 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
2483 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
2484 for compatibility with 20.2.
2486 Face specifications earlier in lists take precedence over later
2490 merge_face_ref (struct frame
*f
, Lisp_Object face_ref
, Lisp_Object
*to
, int err_msgs
, struct named_merge_point
*named_merge_points
)
2492 int ok
= 1; /* Succeed without an error? */
2494 if (CONSP (face_ref
))
2496 Lisp_Object first
= XCAR (face_ref
);
2498 if (EQ (first
, Qforeground_color
)
2499 || EQ (first
, Qbackground_color
))
2501 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
2502 . COLOR). COLOR must be a string. */
2503 Lisp_Object color_name
= XCDR (face_ref
);
2504 Lisp_Object color
= first
;
2506 if (STRINGP (color_name
))
2508 if (EQ (color
, Qforeground_color
))
2509 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
2511 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
2516 add_to_log ("Invalid face color", color_name
, Qnil
);
2520 else if (SYMBOLP (first
)
2521 && *SDATA (SYMBOL_NAME (first
)) == ':')
2523 /* Assume this is the property list form. */
2524 while (CONSP (face_ref
) && CONSP (XCDR (face_ref
)))
2526 Lisp_Object keyword
= XCAR (face_ref
);
2527 Lisp_Object value
= XCAR (XCDR (face_ref
));
2530 /* Specifying `unspecified' is a no-op. */
2531 if (EQ (value
, Qunspecified
))
2533 else if (EQ (keyword
, QCfamily
))
2535 if (STRINGP (value
))
2537 to
[LFACE_FAMILY_INDEX
] = value
;
2538 font_clear_prop (to
, FONT_FAMILY_INDEX
);
2543 else if (EQ (keyword
, QCfoundry
))
2545 if (STRINGP (value
))
2547 to
[LFACE_FOUNDRY_INDEX
] = value
;
2548 font_clear_prop (to
, FONT_FOUNDRY_INDEX
);
2553 else if (EQ (keyword
, QCheight
))
2555 Lisp_Object new_height
=
2556 merge_face_heights (value
, to
[LFACE_HEIGHT_INDEX
], Qnil
);
2558 if (! NILP (new_height
))
2560 to
[LFACE_HEIGHT_INDEX
] = new_height
;
2561 font_clear_prop (to
, FONT_SIZE_INDEX
);
2566 else if (EQ (keyword
, QCweight
))
2568 if (SYMBOLP (value
) && FONT_WEIGHT_NAME_NUMERIC (value
) >= 0)
2570 to
[LFACE_WEIGHT_INDEX
] = value
;
2571 font_clear_prop (to
, FONT_WEIGHT_INDEX
);
2576 else if (EQ (keyword
, QCslant
))
2578 if (SYMBOLP (value
) && FONT_SLANT_NAME_NUMERIC (value
) >= 0)
2580 to
[LFACE_SLANT_INDEX
] = value
;
2581 font_clear_prop (to
, FONT_SLANT_INDEX
);
2586 else if (EQ (keyword
, QCunderline
))
2591 to
[LFACE_UNDERLINE_INDEX
] = value
;
2595 else if (EQ (keyword
, QCoverline
))
2600 to
[LFACE_OVERLINE_INDEX
] = value
;
2604 else if (EQ (keyword
, QCstrike_through
))
2609 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
2613 else if (EQ (keyword
, QCbox
))
2616 value
= make_number (1);
2617 if (INTEGERP (value
)
2621 to
[LFACE_BOX_INDEX
] = value
;
2625 else if (EQ (keyword
, QCinverse_video
)
2626 || EQ (keyword
, QCreverse_video
))
2628 if (EQ (value
, Qt
) || NILP (value
))
2629 to
[LFACE_INVERSE_INDEX
] = value
;
2633 else if (EQ (keyword
, QCforeground
))
2635 if (STRINGP (value
))
2636 to
[LFACE_FOREGROUND_INDEX
] = value
;
2640 else if (EQ (keyword
, QCbackground
))
2642 if (STRINGP (value
))
2643 to
[LFACE_BACKGROUND_INDEX
] = value
;
2647 else if (EQ (keyword
, QCstipple
))
2649 #if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
2650 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
2651 if (!NILP (pixmap_p
))
2652 to
[LFACE_STIPPLE_INDEX
] = value
;
2657 else if (EQ (keyword
, QCwidth
))
2659 if (SYMBOLP (value
) && FONT_WIDTH_NAME_NUMERIC (value
) >= 0)
2661 to
[LFACE_SWIDTH_INDEX
] = value
;
2662 font_clear_prop (to
, FONT_WIDTH_INDEX
);
2667 else if (EQ (keyword
, QCinherit
))
2669 /* This is not really very useful; it's just like a
2670 normal face reference. */
2671 if (! merge_face_ref (f
, value
, to
,
2672 err_msgs
, named_merge_points
))
2680 add_to_log ("Invalid face attribute %S %S", keyword
, value
);
2684 face_ref
= XCDR (XCDR (face_ref
));
2689 /* This is a list of face refs. Those at the beginning of the
2690 list take precedence over what follows, so we have to merge
2691 from the end backwards. */
2692 Lisp_Object next
= XCDR (face_ref
);
2695 ok
= merge_face_ref (f
, next
, to
, err_msgs
, named_merge_points
);
2697 if (! merge_face_ref (f
, first
, to
, err_msgs
, named_merge_points
))
2703 /* FACE_REF ought to be a face name. */
2704 ok
= merge_named_face (f
, face_ref
, to
, named_merge_points
);
2705 if (!ok
&& err_msgs
)
2706 add_to_log ("Invalid face reference: %s", face_ref
, Qnil
);
2713 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
2714 Sinternal_make_lisp_face
, 1, 2, 0,
2715 doc
: /* Make FACE, a symbol, a Lisp face with all attributes nil.
2716 If FACE was not known as a face before, create a new one.
2717 If optional argument FRAME is specified, make a frame-local face
2718 for that frame. Otherwise operate on the global face definition.
2719 Value is a vector of face attributes. */)
2721 Lisp_Object face
, frame
;
2723 Lisp_Object global_lface
, lface
;
2727 CHECK_SYMBOL (face
);
2728 global_lface
= lface_from_face_name (NULL
, face
, 0);
2732 CHECK_LIVE_FRAME (frame
);
2734 lface
= lface_from_face_name (f
, face
, 0);
2737 f
= NULL
, lface
= Qnil
;
2739 /* Add a global definition if there is none. */
2740 if (NILP (global_lface
))
2742 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2744 ASET (global_lface
, 0, Qface
);
2745 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
2746 Vface_new_frame_defaults
);
2748 /* Assign the new Lisp face a unique ID. The mapping from Lisp
2749 face id to Lisp face is given by the vector lface_id_to_name.
2750 The mapping from Lisp face to Lisp face id is given by the
2751 property `face' of the Lisp face name. */
2752 if (next_lface_id
== lface_id_to_name_size
)
2754 int new_size
= max (50, 2 * lface_id_to_name_size
);
2755 int sz
= new_size
* sizeof *lface_id_to_name
;
2756 lface_id_to_name
= (Lisp_Object
*) xrealloc (lface_id_to_name
, sz
);
2757 lface_id_to_name_size
= new_size
;
2760 lface_id_to_name
[next_lface_id
] = face
;
2761 Fput (face
, Qface
, make_number (next_lface_id
));
2765 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2766 ASET (global_lface
, i
, Qunspecified
);
2768 /* Add a frame-local definition. */
2773 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2775 ASET (lface
, 0, Qface
);
2776 f
->face_alist
= Fcons (Fcons (face
, lface
), f
->face_alist
);
2779 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2780 ASET (lface
, i
, Qunspecified
);
2783 lface
= global_lface
;
2785 /* Changing a named face means that all realized faces depending on
2786 that face are invalid. Since we cannot tell which realized faces
2787 depend on the face, make sure they are all removed. This is done
2788 by incrementing face_change_count. The next call to
2789 init_iterator will then free realized faces. */
2790 if (NILP (Fget (face
, Qface_no_inherit
)))
2792 ++face_change_count
;
2793 ++windows_or_buffers_changed
;
2796 xassert (LFACEP (lface
));
2797 check_lface (lface
);
2802 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
2803 Sinternal_lisp_face_p
, 1, 2, 0,
2804 doc
: /* Return non-nil if FACE names a face.
2805 FACE should be a symbol or string.
2806 If optional second argument FRAME is non-nil, check for the
2807 existence of a frame-local face with name FACE on that frame.
2808 Otherwise check for the existence of a global face. */)
2810 Lisp_Object face
, frame
;
2814 face
= resolve_face_name (face
, 1);
2818 CHECK_LIVE_FRAME (frame
);
2819 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2822 lface
= lface_from_face_name (NULL
, face
, 0);
2828 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
2829 Sinternal_copy_lisp_face
, 4, 4, 0,
2830 doc
: /* Copy face FROM to TO.
2831 If FRAME is t, copy the global face definition of FROM.
2832 Otherwise, copy the frame-local definition of FROM on FRAME.
2833 If NEW-FRAME is a frame, copy that data into the frame-local
2834 definition of TO on NEW-FRAME. If NEW-FRAME is nil,
2835 FRAME controls where the data is copied to.
2837 The value is TO. */)
2838 (from
, to
, frame
, new_frame
)
2839 Lisp_Object from
, to
, frame
, new_frame
;
2841 Lisp_Object lface
, copy
;
2843 CHECK_SYMBOL (from
);
2848 /* Copy global definition of FROM. We don't make copies of
2849 strings etc. because 20.2 didn't do it either. */
2850 lface
= lface_from_face_name (NULL
, from
, 1);
2851 copy
= Finternal_make_lisp_face (to
, Qnil
);
2855 /* Copy frame-local definition of FROM. */
2856 if (NILP (new_frame
))
2858 CHECK_LIVE_FRAME (frame
);
2859 CHECK_LIVE_FRAME (new_frame
);
2860 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
2861 copy
= Finternal_make_lisp_face (to
, new_frame
);
2864 memcpy (XVECTOR (copy
)->contents
, XVECTOR (lface
)->contents
,
2865 LFACE_VECTOR_SIZE
* sizeof (Lisp_Object
));
2867 /* Changing a named face means that all realized faces depending on
2868 that face are invalid. Since we cannot tell which realized faces
2869 depend on the face, make sure they are all removed. This is done
2870 by incrementing face_change_count. The next call to
2871 init_iterator will then free realized faces. */
2872 if (NILP (Fget (to
, Qface_no_inherit
)))
2874 ++face_change_count
;
2875 ++windows_or_buffers_changed
;
2882 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
2883 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
2884 doc
: /* Set attribute ATTR of FACE to VALUE.
2885 FRAME being a frame means change the face on that frame.
2886 FRAME nil means change the face of the selected frame.
2887 FRAME t means change the default for new frames.
2888 FRAME 0 means change the face on all frames, and change the default
2890 (face
, attr
, value
, frame
)
2891 Lisp_Object face
, attr
, value
, frame
;
2894 Lisp_Object old_value
= Qnil
;
2895 /* Set one of enum font_property_index (> 0) if ATTR is one of
2896 font-related attributes other than QCfont and QCfontset. */
2897 enum font_property_index prop_index
= 0;
2899 CHECK_SYMBOL (face
);
2900 CHECK_SYMBOL (attr
);
2902 face
= resolve_face_name (face
, 1);
2904 /* If FRAME is 0, change face on all frames, and change the
2905 default for new frames. */
2906 if (INTEGERP (frame
) && XINT (frame
) == 0)
2909 Finternal_set_lisp_face_attribute (face
, attr
, value
, Qt
);
2910 FOR_EACH_FRAME (tail
, frame
)
2911 Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
2915 /* Set lface to the Lisp attribute vector of FACE. */
2918 lface
= lface_from_face_name (NULL
, face
, 1);
2920 /* When updating face-new-frame-defaults, we put :ignore-defface
2921 where the caller wants `unspecified'. This forces the frame
2922 defaults to ignore the defface value. Otherwise, the defface
2923 will take effect, which is generally not what is intended.
2924 The value of that attribute will be inherited from some other
2925 face during face merging. See internal_merge_in_global_face. */
2926 if (UNSPECIFIEDP (value
))
2927 value
= Qignore_defface
;
2932 frame
= selected_frame
;
2934 CHECK_LIVE_FRAME (frame
);
2935 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2937 /* If a frame-local face doesn't exist yet, create one. */
2939 lface
= Finternal_make_lisp_face (face
, frame
);
2942 if (EQ (attr
, QCfamily
))
2944 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2946 CHECK_STRING (value
);
2947 if (SCHARS (value
) == 0)
2948 signal_error ("Invalid face family", value
);
2950 old_value
= LFACE_FAMILY (lface
);
2951 LFACE_FAMILY (lface
) = value
;
2952 prop_index
= FONT_FAMILY_INDEX
;
2954 else if (EQ (attr
, QCfoundry
))
2956 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2958 CHECK_STRING (value
);
2959 if (SCHARS (value
) == 0)
2960 signal_error ("Invalid face foundry", value
);
2962 old_value
= LFACE_FOUNDRY (lface
);
2963 LFACE_FOUNDRY (lface
) = value
;
2964 prop_index
= FONT_FOUNDRY_INDEX
;
2966 else if (EQ (attr
, QCheight
))
2968 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2970 if (EQ (face
, Qdefault
))
2972 /* The default face must have an absolute size. */
2973 if (!INTEGERP (value
) || XINT (value
) <= 0)
2974 signal_error ("Invalid default face height", value
);
2978 /* For non-default faces, do a test merge with a random
2979 height to see if VALUE's ok. */
2980 Lisp_Object test
= merge_face_heights (value
,
2983 if (!INTEGERP (test
) || XINT (test
) <= 0)
2984 signal_error ("Invalid face height", value
);
2988 old_value
= LFACE_HEIGHT (lface
);
2989 LFACE_HEIGHT (lface
) = value
;
2990 prop_index
= FONT_SIZE_INDEX
;
2992 else if (EQ (attr
, QCweight
))
2994 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2996 CHECK_SYMBOL (value
);
2997 if (FONT_WEIGHT_NAME_NUMERIC (value
) < 0)
2998 signal_error ("Invalid face weight", value
);
3000 old_value
= LFACE_WEIGHT (lface
);
3001 LFACE_WEIGHT (lface
) = value
;
3002 prop_index
= FONT_WEIGHT_INDEX
;
3004 else if (EQ (attr
, QCslant
))
3006 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3008 CHECK_SYMBOL (value
);
3009 if (FONT_SLANT_NAME_NUMERIC (value
) < 0)
3010 signal_error ("Invalid face slant", value
);
3012 old_value
= LFACE_SLANT (lface
);
3013 LFACE_SLANT (lface
) = value
;
3014 prop_index
= FONT_SLANT_INDEX
;
3016 else if (EQ (attr
, QCunderline
))
3018 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3019 if ((SYMBOLP (value
)
3021 && !EQ (value
, Qnil
))
3022 /* Underline color. */
3024 && SCHARS (value
) == 0))
3025 signal_error ("Invalid face underline", value
);
3027 old_value
= LFACE_UNDERLINE (lface
);
3028 LFACE_UNDERLINE (lface
) = value
;
3030 else if (EQ (attr
, QCoverline
))
3032 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3033 if ((SYMBOLP (value
)
3035 && !EQ (value
, Qnil
))
3036 /* Overline color. */
3038 && SCHARS (value
) == 0))
3039 signal_error ("Invalid face overline", value
);
3041 old_value
= LFACE_OVERLINE (lface
);
3042 LFACE_OVERLINE (lface
) = value
;
3044 else if (EQ (attr
, QCstrike_through
))
3046 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3047 if ((SYMBOLP (value
)
3049 && !EQ (value
, Qnil
))
3050 /* Strike-through color. */
3052 && SCHARS (value
) == 0))
3053 signal_error ("Invalid face strike-through", value
);
3055 old_value
= LFACE_STRIKE_THROUGH (lface
);
3056 LFACE_STRIKE_THROUGH (lface
) = value
;
3058 else if (EQ (attr
, QCbox
))
3062 /* Allow t meaning a simple box of width 1 in foreground color
3065 value
= make_number (1);
3067 if (UNSPECIFIEDP (value
) || IGNORE_DEFFACE_P (value
))
3069 else if (NILP (value
))
3071 else if (INTEGERP (value
))
3072 valid_p
= XINT (value
) != 0;
3073 else if (STRINGP (value
))
3074 valid_p
= SCHARS (value
) > 0;
3075 else if (CONSP (value
))
3091 if (EQ (k
, QCline_width
))
3093 if (!INTEGERP (v
) || XINT (v
) == 0)
3096 else if (EQ (k
, QCcolor
))
3098 if (!NILP (v
) && (!STRINGP (v
) || SCHARS (v
) == 0))
3101 else if (EQ (k
, QCstyle
))
3103 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
3110 valid_p
= NILP (tem
);
3116 signal_error ("Invalid face box", value
);
3118 old_value
= LFACE_BOX (lface
);
3119 LFACE_BOX (lface
) = value
;
3121 else if (EQ (attr
, QCinverse_video
)
3122 || EQ (attr
, QCreverse_video
))
3124 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3126 CHECK_SYMBOL (value
);
3127 if (!EQ (value
, Qt
) && !NILP (value
))
3128 signal_error ("Invalid inverse-video face attribute value", value
);
3130 old_value
= LFACE_INVERSE (lface
);
3131 LFACE_INVERSE (lface
) = value
;
3133 else if (EQ (attr
, QCforeground
))
3135 /* Compatibility with 20.x. */
3137 value
= Qunspecified
;
3138 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3140 /* Don't check for valid color names here because it depends
3141 on the frame (display) whether the color will be valid
3142 when the face is realized. */
3143 CHECK_STRING (value
);
3144 if (SCHARS (value
) == 0)
3145 signal_error ("Empty foreground color value", value
);
3147 old_value
= LFACE_FOREGROUND (lface
);
3148 LFACE_FOREGROUND (lface
) = value
;
3150 else if (EQ (attr
, QCbackground
))
3152 /* Compatibility with 20.x. */
3154 value
= Qunspecified
;
3155 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3157 /* Don't check for valid color names here because it depends
3158 on the frame (display) whether the color will be valid
3159 when the face is realized. */
3160 CHECK_STRING (value
);
3161 if (SCHARS (value
) == 0)
3162 signal_error ("Empty background color value", value
);
3164 old_value
= LFACE_BACKGROUND (lface
);
3165 LFACE_BACKGROUND (lface
) = value
;
3167 else if (EQ (attr
, QCstipple
))
3169 #if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
3170 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3172 && NILP (Fbitmap_spec_p (value
)))
3173 signal_error ("Invalid stipple attribute", value
);
3174 old_value
= LFACE_STIPPLE (lface
);
3175 LFACE_STIPPLE (lface
) = value
;
3176 #endif /* HAVE_X_WINDOWS || HAVE_NS */
3178 else if (EQ (attr
, QCwidth
))
3180 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3182 CHECK_SYMBOL (value
);
3183 if (FONT_WIDTH_NAME_NUMERIC (value
) < 0)
3184 signal_error ("Invalid face width", value
);
3186 old_value
= LFACE_SWIDTH (lface
);
3187 LFACE_SWIDTH (lface
) = value
;
3188 prop_index
= FONT_WIDTH_INDEX
;
3190 else if (EQ (attr
, QCfont
))
3192 #ifdef HAVE_WINDOW_SYSTEM
3193 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3195 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3199 old_value
= LFACE_FONT (lface
);
3200 if (! FONTP (value
))
3202 if (STRINGP (value
))
3204 Lisp_Object name
= value
;
3205 int fontset
= fs_query_fontset (name
, 0);
3208 name
= fontset_ascii (fontset
);
3209 value
= font_spec_from_name (name
);
3211 signal_error ("Invalid font name", name
);
3214 signal_error ("Invalid font or font-spec", value
);
3217 f
= XFRAME (selected_frame
);
3220 if (! FONT_OBJECT_P (value
))
3222 Lisp_Object
*attrs
= XVECTOR (lface
)->contents
;
3223 Lisp_Object font_object
;
3225 font_object
= font_load_for_lface (f
, attrs
, value
);
3226 if (NILP (font_object
))
3227 signal_error ("Font not available", value
);
3228 value
= font_object
;
3230 set_lface_from_font (f
, lface
, value
, 1);
3233 LFACE_FONT (lface
) = value
;
3235 #endif /* HAVE_WINDOW_SYSTEM */
3237 else if (EQ (attr
, QCfontset
))
3239 #ifdef HAVE_WINDOW_SYSTEM
3240 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3244 old_value
= LFACE_FONTSET (lface
);
3245 tmp
= Fquery_fontset (value
, Qnil
);
3247 signal_error ("Invalid fontset name", value
);
3248 LFACE_FONTSET (lface
) = value
= tmp
;
3250 #endif /* HAVE_WINDOW_SYSTEM */
3252 else if (EQ (attr
, QCinherit
))
3255 if (SYMBOLP (value
))
3258 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
3259 if (!SYMBOLP (XCAR (tail
)))
3262 LFACE_INHERIT (lface
) = value
;
3264 signal_error ("Invalid face inheritance", value
);
3266 else if (EQ (attr
, QCbold
))
3268 old_value
= LFACE_WEIGHT (lface
);
3269 LFACE_WEIGHT (lface
) = NILP (value
) ? Qnormal
: Qbold
;
3270 prop_index
= FONT_WEIGHT_INDEX
;
3272 else if (EQ (attr
, QCitalic
))
3275 old_value
= LFACE_SLANT (lface
);
3276 LFACE_SLANT (lface
) = NILP (value
) ? Qnormal
: Qitalic
;
3277 prop_index
= FONT_SLANT_INDEX
;
3280 signal_error ("Invalid face attribute name", attr
);
3284 /* If a font-related attribute other than QCfont and QCfontset
3285 is specified, and if the original QCfont attribute has a font
3286 (font-spec or font-object), set the corresponding property in
3287 the font to nil so that the font selector doesn't think that
3288 the attribute is mandatory. Also, clear the average
3290 font_clear_prop (XVECTOR (lface
)->contents
, prop_index
);
3293 /* Changing a named face means that all realized faces depending on
3294 that face are invalid. Since we cannot tell which realized faces
3295 depend on the face, make sure they are all removed. This is done
3296 by incrementing face_change_count. The next call to
3297 init_iterator will then free realized faces. */
3299 && NILP (Fget (face
, Qface_no_inherit
))
3300 && NILP (Fequal (old_value
, value
)))
3302 ++face_change_count
;
3303 ++windows_or_buffers_changed
;
3306 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3307 && NILP (Fequal (old_value
, value
)))
3313 if (EQ (face
, Qdefault
))
3315 #ifdef HAVE_WINDOW_SYSTEM
3316 /* Changed font-related attributes of the `default' face are
3317 reflected in changed `font' frame parameters. */
3319 && (prop_index
|| EQ (attr
, QCfont
))
3320 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
3321 set_font_frame_param (frame
, lface
);
3323 #endif /* HAVE_WINDOW_SYSTEM */
3325 if (EQ (attr
, QCforeground
))
3326 param
= Qforeground_color
;
3327 else if (EQ (attr
, QCbackground
))
3328 param
= Qbackground_color
;
3330 #ifdef HAVE_WINDOW_SYSTEM
3332 else if (EQ (face
, Qscroll_bar
))
3334 /* Changing the colors of `scroll-bar' sets frame parameters
3335 `scroll-bar-foreground' and `scroll-bar-background'. */
3336 if (EQ (attr
, QCforeground
))
3337 param
= Qscroll_bar_foreground
;
3338 else if (EQ (attr
, QCbackground
))
3339 param
= Qscroll_bar_background
;
3341 #endif /* not WINDOWSNT */
3342 else if (EQ (face
, Qborder
))
3344 /* Changing background color of `border' sets frame parameter
3346 if (EQ (attr
, QCbackground
))
3347 param
= Qborder_color
;
3349 else if (EQ (face
, Qcursor
))
3351 /* Changing background color of `cursor' sets frame parameter
3353 if (EQ (attr
, QCbackground
))
3354 param
= Qcursor_color
;
3356 else if (EQ (face
, Qmouse
))
3358 /* Changing background color of `mouse' sets frame parameter
3360 if (EQ (attr
, QCbackground
))
3361 param
= Qmouse_color
;
3363 #endif /* HAVE_WINDOW_SYSTEM */
3364 else if (EQ (face
, Qmenu
))
3366 /* Indicate that we have to update the menu bar when
3367 realizing faces on FRAME. FRAME t change the
3368 default for new frames. We do this by setting
3369 setting the flag in new face caches */
3372 struct frame
*f
= XFRAME (frame
);
3373 if (FRAME_FACE_CACHE (f
) == NULL
)
3374 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
3375 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 1;
3378 menu_face_changed_default
= 1;
3384 /* Update `default-frame-alist', which is used for new frames. */
3386 store_in_alist (&Vdefault_frame_alist
, param
, value
);
3389 /* Update the current frame's parameters. */
3392 cons
= XCAR (Vparam_value_alist
);
3393 XSETCAR (cons
, param
);
3394 XSETCDR (cons
, value
);
3395 Fmodify_frame_parameters (frame
, Vparam_value_alist
);
3404 /* Update the corresponding face when frame parameter PARAM on frame F
3405 has been assigned the value NEW_VALUE. */
3408 update_face_from_frame_parameter (struct frame
*f
, Lisp_Object param
, Lisp_Object new_value
)
3410 Lisp_Object face
= Qnil
;
3413 /* If there are no faces yet, give up. This is the case when called
3414 from Fx_create_frame, and we do the necessary things later in
3415 face-set-after-frame-defaults. */
3416 if (NILP (f
->face_alist
))
3419 if (EQ (param
, Qforeground_color
))
3422 lface
= lface_from_face_name (f
, face
, 1);
3423 LFACE_FOREGROUND (lface
) = (STRINGP (new_value
)
3424 ? new_value
: Qunspecified
);
3425 realize_basic_faces (f
);
3427 else if (EQ (param
, Qbackground_color
))
3431 /* Changing the background color might change the background
3432 mode, so that we have to load new defface specs.
3433 Call frame-update-face-colors to do that. */
3434 XSETFRAME (frame
, f
);
3435 call1 (Qframe_set_background_mode
, frame
);
3438 lface
= lface_from_face_name (f
, face
, 1);
3439 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3440 ? new_value
: Qunspecified
);
3441 realize_basic_faces (f
);
3443 #ifdef HAVE_WINDOW_SYSTEM
3444 else if (EQ (param
, Qborder_color
))
3447 lface
= lface_from_face_name (f
, face
, 1);
3448 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3449 ? new_value
: Qunspecified
);
3451 else if (EQ (param
, Qcursor_color
))
3454 lface
= lface_from_face_name (f
, face
, 1);
3455 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3456 ? new_value
: Qunspecified
);
3458 else if (EQ (param
, Qmouse_color
))
3461 lface
= lface_from_face_name (f
, face
, 1);
3462 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3463 ? new_value
: Qunspecified
);
3467 /* Changing a named face means that all realized faces depending on
3468 that face are invalid. Since we cannot tell which realized faces
3469 depend on the face, make sure they are all removed. This is done
3470 by incrementing face_change_count. The next call to
3471 init_iterator will then free realized faces. */
3473 && NILP (Fget (face
, Qface_no_inherit
)))
3475 ++face_change_count
;
3476 ++windows_or_buffers_changed
;
3481 #ifdef HAVE_WINDOW_SYSTEM
3483 /* Set the `font' frame parameter of FRAME determined from the
3484 font-object set in `default' face attributes LFACE. */
3487 set_font_frame_param (Lisp_Object frame
, Lisp_Object lface
)
3489 struct frame
*f
= XFRAME (frame
);
3492 if (FRAME_WINDOW_P (f
)
3493 /* Don't do anything if the font is `unspecified'. This can
3494 happen during frame creation. */
3495 && (font
= LFACE_FONT (lface
),
3496 ! UNSPECIFIEDP (font
)))
3498 if (FONT_SPEC_P (font
))
3500 font
= font_load_for_lface (f
, XVECTOR (lface
)->contents
, font
);
3503 LFACE_FONT (lface
) = font
;
3505 f
->default_face_done_p
= 0;
3506 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, font
), Qnil
));
3511 /* Get the value of X resource RESOURCE, class CLASS for the display
3512 of frame FRAME. This is here because ordinary `x-get-resource'
3513 doesn't take a frame argument. */
3515 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
3516 Sinternal_face_x_get_resource
, 3, 3, 0, doc
: /* */)
3517 (resource
, class, frame
)
3518 Lisp_Object resource
, class, frame
;
3520 Lisp_Object value
= Qnil
;
3521 CHECK_STRING (resource
);
3522 CHECK_STRING (class);
3523 CHECK_LIVE_FRAME (frame
);
3525 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame
)),
3526 resource
, class, Qnil
, Qnil
);
3532 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
3533 If VALUE is "on" or "true", return t. If VALUE is "off" or
3534 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
3535 error; if SIGNAL_P is zero, return 0. */
3538 face_boolean_x_resource_value (Lisp_Object value
, int signal_p
)
3540 Lisp_Object result
= make_number (0);
3542 xassert (STRINGP (value
));
3544 if (xstrcasecmp (SDATA (value
), "on") == 0
3545 || xstrcasecmp (SDATA (value
), "true") == 0)
3547 else if (xstrcasecmp (SDATA (value
), "off") == 0
3548 || xstrcasecmp (SDATA (value
), "false") == 0)
3550 else if (xstrcasecmp (SDATA (value
), "unspecified") == 0)
3551 result
= Qunspecified
;
3553 signal_error ("Invalid face attribute value from X resource", value
);
3559 DEFUN ("internal-set-lisp-face-attribute-from-resource",
3560 Finternal_set_lisp_face_attribute_from_resource
,
3561 Sinternal_set_lisp_face_attribute_from_resource
,
3562 3, 4, 0, doc
: /* */)
3563 (face
, attr
, value
, frame
)
3564 Lisp_Object face
, attr
, value
, frame
;
3566 CHECK_SYMBOL (face
);
3567 CHECK_SYMBOL (attr
);
3568 CHECK_STRING (value
);
3570 if (xstrcasecmp (SDATA (value
), "unspecified") == 0)
3571 value
= Qunspecified
;
3572 else if (EQ (attr
, QCheight
))
3574 value
= Fstring_to_number (value
, make_number (10));
3575 if (XINT (value
) <= 0)
3576 signal_error ("Invalid face height from X resource", value
);
3578 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
3579 value
= face_boolean_x_resource_value (value
, 1);
3580 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
3581 value
= intern (SDATA (value
));
3582 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
3583 value
= face_boolean_x_resource_value (value
, 1);
3584 else if (EQ (attr
, QCunderline
)
3585 || EQ (attr
, QCoverline
)
3586 || EQ (attr
, QCstrike_through
))
3588 Lisp_Object boolean_value
;
3590 /* If the result of face_boolean_x_resource_value is t or nil,
3591 VALUE does NOT specify a color. */
3592 boolean_value
= face_boolean_x_resource_value (value
, 0);
3593 if (SYMBOLP (boolean_value
))
3594 value
= boolean_value
;
3596 else if (EQ (attr
, QCbox
) || EQ (attr
, QCinherit
))
3597 value
= Fcar (Fread_from_string (value
, Qnil
, Qnil
));
3599 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3602 #endif /* HAVE_WINDOW_SYSTEM */
3605 /***********************************************************************
3607 ***********************************************************************/
3609 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
3611 /* Make menus on frame F appear as specified by the `menu' face. */
3614 x_update_menu_appearance (f
)
3617 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3621 && (rdb
= XrmGetDatabase (FRAME_X_DISPLAY (f
)),
3625 Lisp_Object lface
= lface_from_face_name (f
, Qmenu
, 1);
3626 struct face
*face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
3627 const char *myname
= SDATA (Vx_resource_name
);
3630 const char *popup_path
= "popup_menu";
3632 const char *popup_path
= "menu.popup";
3635 if (STRINGP (LFACE_FOREGROUND (lface
)))
3637 sprintf (line
, "%s.%s*foreground: %s",
3639 SDATA (LFACE_FOREGROUND (lface
)));
3640 XrmPutLineResource (&rdb
, line
);
3641 sprintf (line
, "%s.pane.menubar*foreground: %s",
3642 myname
, SDATA (LFACE_FOREGROUND (lface
)));
3643 XrmPutLineResource (&rdb
, line
);
3647 if (STRINGP (LFACE_BACKGROUND (lface
)))
3649 sprintf (line
, "%s.%s*background: %s",
3651 SDATA (LFACE_BACKGROUND (lface
)));
3652 XrmPutLineResource (&rdb
, line
);
3653 sprintf (line
, "%s.pane.menubar*background: %s",
3654 myname
, SDATA (LFACE_BACKGROUND (lface
)));
3655 XrmPutLineResource (&rdb
, line
);
3660 /* On Solaris 5.8, it's been reported that the `menu' face
3661 can be unspecified here, during startup. Why this
3662 happens remains unknown. -- cyd */
3663 && FONTP (LFACE_FONT (lface
))
3664 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
3665 || !UNSPECIFIEDP (LFACE_FOUNDRY (lface
))
3666 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
3667 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3668 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
3669 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
3671 Lisp_Object xlfd
= Ffont_xlfd_name (LFACE_FONT (lface
), Qnil
);
3673 const char *suffix
= "List";
3676 #if defined HAVE_X_I18N
3678 const char *suffix
= "Set";
3680 const char *suffix
= "";
3687 #if defined HAVE_X_I18N
3688 extern char *xic_create_fontsetname
3689 (char *base_fontname
, Bool motif
);
3690 char *fontsetname
= xic_create_fontsetname (SDATA (xlfd
), motif
);
3692 char *fontsetname
= (char *) SDATA (xlfd
);
3694 sprintf (line
, "%s.pane.menubar*font%s: %s",
3695 myname
, suffix
, fontsetname
);
3696 XrmPutLineResource (&rdb
, line
);
3697 sprintf (line
, "%s.%s*font%s: %s",
3698 myname
, popup_path
, suffix
, fontsetname
);
3699 XrmPutLineResource (&rdb
, line
);
3701 if (fontsetname
!= (char *) SDATA (xlfd
))
3702 xfree (fontsetname
);
3706 if (changed_p
&& f
->output_data
.x
->menubar_widget
)
3707 free_frame_menubar (f
);
3711 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
3714 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p
,
3715 Sface_attribute_relative_p
,
3717 doc
: /* Check whether a face attribute value is relative.
3718 Specifically, this function returns t if the attribute ATTRIBUTE
3719 with the value VALUE is relative.
3721 A relative value is one that doesn't entirely override whatever is
3722 inherited from another face. For most possible attributes,
3723 the only relative value that users see is `unspecified'.
3724 However, for :height, floating point values are also relative. */)
3726 Lisp_Object attribute
, value
;
3728 if (EQ (value
, Qunspecified
) || (EQ (value
, Qignore_defface
)))
3730 else if (EQ (attribute
, QCheight
))
3731 return INTEGERP (value
) ? Qnil
: Qt
;
3736 DEFUN ("merge-face-attribute", Fmerge_face_attribute
, Smerge_face_attribute
,
3738 doc
: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
3739 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
3740 the result will be absolute, otherwise it will be relative. */)
3741 (attribute
, value1
, value2
)
3742 Lisp_Object attribute
, value1
, value2
;
3744 if (EQ (value1
, Qunspecified
) || EQ (value1
, Qignore_defface
))
3746 else if (EQ (attribute
, QCheight
))
3747 return merge_face_heights (value1
, value2
, value1
);
3753 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
3754 Sinternal_get_lisp_face_attribute
,
3756 doc
: /* Return face attribute KEYWORD of face SYMBOL.
3757 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
3758 face attribute name, signal an error.
3759 If the optional argument FRAME is given, report on face SYMBOL in that
3760 frame. If FRAME is t, report on the defaults for face SYMBOL (for new
3761 frames). If FRAME is omitted or nil, use the selected frame. */)
3762 (symbol
, keyword
, frame
)
3763 Lisp_Object symbol
, keyword
, frame
;
3765 Lisp_Object lface
, value
= Qnil
;
3767 CHECK_SYMBOL (symbol
);
3768 CHECK_SYMBOL (keyword
);
3771 lface
= lface_from_face_name (NULL
, symbol
, 1);
3775 frame
= selected_frame
;
3776 CHECK_LIVE_FRAME (frame
);
3777 lface
= lface_from_face_name (XFRAME (frame
), symbol
, 1);
3780 if (EQ (keyword
, QCfamily
))
3781 value
= LFACE_FAMILY (lface
);
3782 else if (EQ (keyword
, QCfoundry
))
3783 value
= LFACE_FOUNDRY (lface
);
3784 else if (EQ (keyword
, QCheight
))
3785 value
= LFACE_HEIGHT (lface
);
3786 else if (EQ (keyword
, QCweight
))
3787 value
= LFACE_WEIGHT (lface
);
3788 else if (EQ (keyword
, QCslant
))
3789 value
= LFACE_SLANT (lface
);
3790 else if (EQ (keyword
, QCunderline
))
3791 value
= LFACE_UNDERLINE (lface
);
3792 else if (EQ (keyword
, QCoverline
))
3793 value
= LFACE_OVERLINE (lface
);
3794 else if (EQ (keyword
, QCstrike_through
))
3795 value
= LFACE_STRIKE_THROUGH (lface
);
3796 else if (EQ (keyword
, QCbox
))
3797 value
= LFACE_BOX (lface
);
3798 else if (EQ (keyword
, QCinverse_video
)
3799 || EQ (keyword
, QCreverse_video
))
3800 value
= LFACE_INVERSE (lface
);
3801 else if (EQ (keyword
, QCforeground
))
3802 value
= LFACE_FOREGROUND (lface
);
3803 else if (EQ (keyword
, QCbackground
))
3804 value
= LFACE_BACKGROUND (lface
);
3805 else if (EQ (keyword
, QCstipple
))
3806 value
= LFACE_STIPPLE (lface
);
3807 else if (EQ (keyword
, QCwidth
))
3808 value
= LFACE_SWIDTH (lface
);
3809 else if (EQ (keyword
, QCinherit
))
3810 value
= LFACE_INHERIT (lface
);
3811 else if (EQ (keyword
, QCfont
))
3812 value
= LFACE_FONT (lface
);
3813 else if (EQ (keyword
, QCfontset
))
3814 value
= LFACE_FONTSET (lface
);
3816 signal_error ("Invalid face attribute name", keyword
);
3818 if (IGNORE_DEFFACE_P (value
))
3819 return Qunspecified
;
3825 DEFUN ("internal-lisp-face-attribute-values",
3826 Finternal_lisp_face_attribute_values
,
3827 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
3828 doc
: /* Return a list of valid discrete values for face attribute ATTR.
3829 Value is nil if ATTR doesn't have a discrete set of valid values. */)
3833 Lisp_Object result
= Qnil
;
3835 CHECK_SYMBOL (attr
);
3837 if (EQ (attr
, QCunderline
))
3838 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3839 else if (EQ (attr
, QCoverline
))
3840 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3841 else if (EQ (attr
, QCstrike_through
))
3842 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3843 else if (EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
3844 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3850 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
3851 Sinternal_merge_in_global_face
, 2, 2, 0,
3852 doc
: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
3853 Default face attributes override any local face attributes. */)
3855 Lisp_Object face
, frame
;
3858 Lisp_Object global_lface
, local_lface
, *gvec
, *lvec
;
3859 struct frame
*f
= XFRAME (frame
);
3861 CHECK_LIVE_FRAME (frame
);
3862 global_lface
= lface_from_face_name (NULL
, face
, 1);
3863 local_lface
= lface_from_face_name (f
, face
, 0);
3864 if (NILP (local_lface
))
3865 local_lface
= Finternal_make_lisp_face (face
, frame
);
3867 /* Make every specified global attribute override the local one.
3868 BEWARE!! This is only used from `face-set-after-frame-default' where
3869 the local frame is defined from default specs in `face-defface-spec'
3870 and those should be overridden by global settings. Hence the strange
3871 "global before local" priority. */
3872 lvec
= XVECTOR (local_lface
)->contents
;
3873 gvec
= XVECTOR (global_lface
)->contents
;
3874 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3875 if (IGNORE_DEFFACE_P (gvec
[i
]))
3876 lvec
[i
] = Qunspecified
;
3877 else if (! UNSPECIFIEDP (gvec
[i
]))
3880 /* If the default face was changed, update the face cache and the
3881 `font' frame parameter. */
3882 if (EQ (face
, Qdefault
))
3884 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
3885 struct face
*newface
, *oldface
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
3886 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
3888 /* This can be NULL (e.g., in batch mode). */
3891 /* Ensure that the face vector is fully specified by merging
3892 the previously-cached vector. */
3893 memcpy (attrs
, oldface
->lface
, sizeof attrs
);
3894 merge_face_vectors (f
, lvec
, attrs
, 0);
3895 memcpy (lvec
, attrs
, sizeof attrs
);
3896 newface
= realize_face (c
, lvec
, DEFAULT_FACE_ID
);
3898 if ((! UNSPECIFIEDP (gvec
[LFACE_FAMILY_INDEX
])
3899 || ! UNSPECIFIEDP (gvec
[LFACE_FOUNDRY_INDEX
])
3900 || ! UNSPECIFIEDP (gvec
[LFACE_HEIGHT_INDEX
])
3901 || ! UNSPECIFIEDP (gvec
[LFACE_WEIGHT_INDEX
])
3902 || ! UNSPECIFIEDP (gvec
[LFACE_SLANT_INDEX
])
3903 || ! UNSPECIFIEDP (gvec
[LFACE_SWIDTH_INDEX
])
3904 || ! UNSPECIFIEDP (gvec
[LFACE_FONT_INDEX
]))
3907 Lisp_Object name
= newface
->font
->props
[FONT_NAME_INDEX
];
3908 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, name
),
3918 /* The following function is implemented for compatibility with 20.2.
3919 The function is used in x-resolve-fonts when it is asked to
3920 return fonts with the same size as the font of a face. This is
3921 done in fontset.el. */
3923 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 3, 0,
3924 doc
: /* Return the font name of face FACE, or nil if it is unspecified.
3925 The font name is, by default, for ASCII characters.
3926 If the optional argument FRAME is given, report on face FACE in that frame.
3927 If FRAME is t, report on the defaults for face FACE (for new frames).
3928 The font default for a face is either nil, or a list
3929 of the form (bold), (italic) or (bold italic).
3930 If FRAME is omitted or nil, use the selected frame. And, in this case,
3931 if the optional third argument CHARACTER is given,
3932 return the font name used for CHARACTER. */)
3933 (face
, frame
, character
)
3934 Lisp_Object face
, frame
, character
;
3938 Lisp_Object result
= Qnil
;
3939 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
3941 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3942 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
3943 result
= Fcons (Qbold
, result
);
3945 if (!UNSPECIFIEDP (LFACE_SLANT (lface
))
3946 && !EQ (LFACE_SLANT (lface
), Qnormal
))
3947 result
= Fcons (Qitalic
, result
);
3953 struct frame
*f
= frame_or_selected_frame (frame
, 1);
3954 int face_id
= lookup_named_face (f
, face
, 1);
3955 struct face
*face
= FACE_FROM_ID (f
, face_id
);
3959 #ifdef HAVE_WINDOW_SYSTEM
3960 if (FRAME_WINDOW_P (f
) && !NILP (character
))
3962 CHECK_CHARACTER (character
);
3963 face_id
= FACE_FOR_CHAR (f
, face
, XINT (character
), -1, Qnil
);
3964 face
= FACE_FROM_ID (f
, face_id
);
3967 ? face
->font
->props
[FONT_NAME_INDEX
]
3969 #else /* !HAVE_WINDOW_SYSTEM */
3970 return build_string (FRAME_MSDOS_P (f
)
3972 : FRAME_W32_P (f
) ? "w32term"
3979 /* Compare face-attribute values v1 and v2 for equality. Value is non-zero if
3980 all attributes are `equal'. Tries to be fast because this function
3981 is called quite often. */
3984 face_attr_equal_p (Lisp_Object v1
, Lisp_Object v2
)
3986 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
3987 and the other is specified. */
3988 if (XTYPE (v1
) != XTYPE (v2
))
3997 if (SBYTES (v1
) != SBYTES (v2
))
4000 return memcmp (SDATA (v1
), SDATA (v2
), SBYTES (v1
)) == 0;
4007 return !NILP (Fequal (v1
, v2
));
4012 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
4013 all attributes are `equal'. Tries to be fast because this function
4014 is called quite often. */
4017 lface_equal_p (Lisp_Object
*v1
, Lisp_Object
*v2
)
4021 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
4022 equal_p
= face_attr_equal_p (v1
[i
], v2
[i
]);
4028 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
4029 Sinternal_lisp_face_equal_p
, 2, 3, 0,
4030 doc
: /* True if FACE1 and FACE2 are equal.
4031 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
4032 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
4033 If FRAME is omitted or nil, use the selected frame. */)
4034 (face1
, face2
, frame
)
4035 Lisp_Object face1
, face2
, frame
;
4039 Lisp_Object lface1
, lface2
;
4044 /* Don't use check_x_frame here because this function is called
4045 before X frames exist. At that time, if FRAME is nil,
4046 selected_frame will be used which is the frame dumped with
4047 Emacs. That frame is not an X frame. */
4048 f
= frame_or_selected_frame (frame
, 2);
4050 lface1
= lface_from_face_name (f
, face1
, 1);
4051 lface2
= lface_from_face_name (f
, face2
, 1);
4052 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
4053 XVECTOR (lface2
)->contents
);
4054 return equal_p
? Qt
: Qnil
;
4058 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
4059 Sinternal_lisp_face_empty_p
, 1, 2, 0,
4060 doc
: /* True if FACE has no attribute specified.
4061 If the optional argument FRAME is given, report on face FACE in that frame.
4062 If FRAME is t, report on the defaults for face FACE (for new frames).
4063 If FRAME is omitted or nil, use the selected frame. */)
4065 Lisp_Object face
, frame
;
4072 frame
= selected_frame
;
4073 CHECK_LIVE_FRAME (frame
);
4077 lface
= lface_from_face_name (NULL
, face
, 1);
4079 lface
= lface_from_face_name (f
, face
, 1);
4081 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4082 if (!UNSPECIFIEDP (AREF (lface
, i
)))
4085 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
4089 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
4091 doc
: /* Return an alist of frame-local faces defined on FRAME.
4092 For internal use only. */)
4096 struct frame
*f
= frame_or_selected_frame (frame
, 0);
4097 return f
->face_alist
;
4101 /* Return a hash code for Lisp string STRING with case ignored. Used
4102 below in computing a hash value for a Lisp face. */
4104 static INLINE
unsigned
4105 hash_string_case_insensitive (Lisp_Object string
)
4107 const unsigned char *s
;
4109 xassert (STRINGP (string
));
4110 for (s
= SDATA (string
); *s
; ++s
)
4111 hash
= (hash
<< 1) ^ tolower (*s
);
4116 /* Return a hash code for face attribute vector V. */
4118 static INLINE
unsigned
4119 lface_hash (Lisp_Object
*v
)
4121 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
4122 ^ hash_string_case_insensitive (v
[LFACE_FOUNDRY_INDEX
])
4123 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
4124 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
4125 ^ XHASH (v
[LFACE_WEIGHT_INDEX
])
4126 ^ XHASH (v
[LFACE_SLANT_INDEX
])
4127 ^ XHASH (v
[LFACE_SWIDTH_INDEX
])
4128 ^ XHASH (v
[LFACE_HEIGHT_INDEX
]));
4132 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
4133 considering charsets/registries). They do if they specify the same
4134 family, point size, weight, width, slant, and font. Both
4135 LFACE1 and LFACE2 must be fully-specified. */
4138 lface_same_font_attributes_p (Lisp_Object
*lface1
, Lisp_Object
*lface2
)
4140 xassert (lface_fully_specified_p (lface1
)
4141 && lface_fully_specified_p (lface2
));
4142 return (xstrcasecmp (SDATA (lface1
[LFACE_FAMILY_INDEX
]),
4143 SDATA (lface2
[LFACE_FAMILY_INDEX
])) == 0
4144 && xstrcasecmp (SDATA (lface1
[LFACE_FOUNDRY_INDEX
]),
4145 SDATA (lface2
[LFACE_FOUNDRY_INDEX
])) == 0
4146 && EQ (lface1
[LFACE_HEIGHT_INDEX
], lface2
[LFACE_HEIGHT_INDEX
])
4147 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
4148 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
4149 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
])
4150 && EQ (lface1
[LFACE_FONT_INDEX
], lface2
[LFACE_FONT_INDEX
])
4151 && (EQ (lface1
[LFACE_FONTSET_INDEX
], lface2
[LFACE_FONTSET_INDEX
])
4152 || (STRINGP (lface1
[LFACE_FONTSET_INDEX
])
4153 && STRINGP (lface2
[LFACE_FONTSET_INDEX
])
4154 && ! xstrcasecmp (SDATA (lface1
[LFACE_FONTSET_INDEX
]),
4155 SDATA (lface2
[LFACE_FONTSET_INDEX
]))))
4161 /***********************************************************************
4163 ***********************************************************************/
4165 /* Allocate and return a new realized face for Lisp face attribute
4168 static struct face
*
4169 make_realized_face (Lisp_Object
*attr
)
4171 struct face
*face
= (struct face
*) xmalloc (sizeof *face
);
4172 memset (face
, 0, sizeof *face
);
4173 face
->ascii_face
= face
;
4174 memcpy (face
->lface
, attr
, sizeof face
->lface
);
4179 /* Free realized face FACE, including its X resources. FACE may
4183 free_realized_face (struct frame
*f
, struct face
*face
)
4187 #ifdef HAVE_WINDOW_SYSTEM
4188 if (FRAME_WINDOW_P (f
))
4190 /* Free fontset of FACE if it is ASCII face. */
4191 if (face
->fontset
>= 0 && face
== face
->ascii_face
)
4192 free_face_fontset (f
, face
);
4197 font_done_for_face (f
, face
);
4198 x_free_gc (f
, face
->gc
);
4203 free_face_colors (f
, face
);
4204 x_destroy_bitmap (f
, face
->stipple
);
4206 #endif /* HAVE_WINDOW_SYSTEM */
4213 /* Prepare face FACE for subsequent display on frame F. This
4214 allocated GCs if they haven't been allocated yet or have been freed
4215 by clearing the face cache. */
4218 prepare_face_for_display (struct frame
*f
, struct face
*face
)
4220 #ifdef HAVE_WINDOW_SYSTEM
4221 xassert (FRAME_WINDOW_P (f
));
4226 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
4228 xgcv
.foreground
= face
->foreground
;
4229 xgcv
.background
= face
->background
;
4230 #ifdef HAVE_X_WINDOWS
4231 xgcv
.graphics_exposures
= False
;
4235 #ifdef HAVE_X_WINDOWS
4238 xgcv
.fill_style
= FillOpaqueStippled
;
4239 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
4240 mask
|= GCFillStyle
| GCStipple
;
4243 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
4245 font_prepare_for_face (f
, face
);
4248 #endif /* HAVE_WINDOW_SYSTEM */
4252 /* Returns the `distance' between the colors X and Y. */
4255 color_distance (XColor
*x
, XColor
*y
)
4257 /* This formula is from a paper title `Colour metric' by Thiadmer Riemersma.
4258 Quoting from that paper:
4260 This formula has results that are very close to L*u*v* (with the
4261 modified lightness curve) and, more importantly, it is a more even
4262 algorithm: it does not have a range of colours where it suddenly
4263 gives far from optimal results.
4265 See <http://www.compuphase.com/cmetric.htm> for more info. */
4267 long r
= (x
->red
- y
->red
) >> 8;
4268 long g
= (x
->green
- y
->green
) >> 8;
4269 long b
= (x
->blue
- y
->blue
) >> 8;
4270 long r_mean
= (x
->red
+ y
->red
) >> 9;
4273 (((512 + r_mean
) * r
* r
) >> 8)
4275 + (((767 - r_mean
) * b
* b
) >> 8);
4279 DEFUN ("color-distance", Fcolor_distance
, Scolor_distance
, 2, 3, 0,
4280 doc
: /* Return an integer distance between COLOR1 and COLOR2 on FRAME.
4281 COLOR1 and COLOR2 may be either strings containing the color name,
4282 or lists of the form (RED GREEN BLUE).
4283 If FRAME is unspecified or nil, the current frame is used. */)
4284 (color1
, color2
, frame
)
4285 Lisp_Object color1
, color2
, frame
;
4288 XColor cdef1
, cdef2
;
4291 frame
= selected_frame
;
4292 CHECK_LIVE_FRAME (frame
);
4295 if (!(CONSP (color1
) && parse_rgb_list (color1
, &cdef1
))
4296 && !(STRINGP (color1
) && defined_color (f
, SDATA (color1
), &cdef1
, 0)))
4297 signal_error ("Invalid color", color1
);
4298 if (!(CONSP (color2
) && parse_rgb_list (color2
, &cdef2
))
4299 && !(STRINGP (color2
) && defined_color (f
, SDATA (color2
), &cdef2
, 0)))
4300 signal_error ("Invalid color", color2
);
4302 return make_number (color_distance (&cdef1
, &cdef2
));
4306 /***********************************************************************
4308 ***********************************************************************/
4310 /* Return a new face cache for frame F. */
4312 static struct face_cache
*
4313 make_face_cache (struct frame
*f
)
4315 struct face_cache
*c
;
4318 c
= (struct face_cache
*) xmalloc (sizeof *c
);
4319 memset (c
, 0, sizeof *c
);
4320 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4321 c
->buckets
= (struct face
**) xmalloc (size
);
4322 memset (c
->buckets
, 0, size
);
4324 c
->faces_by_id
= (struct face
**) xmalloc (c
->size
* sizeof *c
->faces_by_id
);
4326 c
->menu_face_changed_p
= menu_face_changed_default
;
4331 /* Clear out all graphics contexts for all realized faces, except for
4332 the basic faces. This should be done from time to time just to avoid
4333 keeping too many graphics contexts that are no longer needed. */
4336 clear_face_gcs (struct face_cache
*c
)
4338 if (c
&& FRAME_WINDOW_P (c
->f
))
4340 #ifdef HAVE_WINDOW_SYSTEM
4342 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
4344 struct face
*face
= c
->faces_by_id
[i
];
4345 if (face
&& face
->gc
)
4349 font_done_for_face (c
->f
, face
);
4350 x_free_gc (c
->f
, face
->gc
);
4355 #endif /* HAVE_WINDOW_SYSTEM */
4360 /* Free all realized faces in face cache C, including basic faces.
4361 C may be null. If faces are freed, make sure the frame's current
4362 matrix is marked invalid, so that a display caused by an expose
4363 event doesn't try to use faces we destroyed. */
4366 free_realized_faces (struct face_cache
*c
)
4371 struct frame
*f
= c
->f
;
4373 /* We must block input here because we can't process X events
4374 safely while only some faces are freed, or when the frame's
4375 current matrix still references freed faces. */
4378 for (i
= 0; i
< c
->used
; ++i
)
4380 free_realized_face (f
, c
->faces_by_id
[i
]);
4381 c
->faces_by_id
[i
] = NULL
;
4385 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4386 memset (c
->buckets
, 0, size
);
4388 /* Must do a thorough redisplay the next time. Mark current
4389 matrices as invalid because they will reference faces freed
4390 above. This function is also called when a frame is
4391 destroyed. In this case, the root window of F is nil. */
4392 if (WINDOWP (f
->root_window
))
4394 clear_current_matrices (f
);
4395 ++windows_or_buffers_changed
;
4403 /* Free all realized faces that are using FONTSET on frame F. */
4406 free_realized_faces_for_fontset (struct frame
*f
, int fontset
)
4408 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4412 /* We must block input here because we can't process X events safely
4413 while only some faces are freed, or when the frame's current
4414 matrix still references freed faces. */
4417 for (i
= 0; i
< cache
->used
; i
++)
4419 face
= cache
->faces_by_id
[i
];
4421 && face
->fontset
== fontset
)
4423 uncache_face (cache
, face
);
4424 free_realized_face (f
, face
);
4428 /* Must do a thorough redisplay the next time. Mark current
4429 matrices as invalid because they will reference faces freed
4430 above. This function is also called when a frame is destroyed.
4431 In this case, the root window of F is nil. */
4432 if (WINDOWP (f
->root_window
))
4434 clear_current_matrices (f
);
4435 ++windows_or_buffers_changed
;
4442 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
4443 This is done after attributes of a named face have been changed,
4444 because we can't tell which realized faces depend on that face. */
4447 free_all_realized_faces (Lisp_Object frame
)
4452 FOR_EACH_FRAME (rest
, frame
)
4453 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4456 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4460 /* Free face cache C and faces in it, including their X resources. */
4463 free_face_cache (struct face_cache
*c
)
4467 free_realized_faces (c
);
4469 xfree (c
->faces_by_id
);
4475 /* Cache realized face FACE in face cache C. HASH is the hash value
4476 of FACE. If FACE is for ASCII characters (i.e. FACE->ascii_face ==
4477 FACE), insert the new face to the beginning of the collision list
4478 of the face hash table of C. Otherwise, add the new face to the
4479 end of the collision list. This way, lookup_face can quickly find
4480 that a requested face is not cached. */
4483 cache_face (struct face_cache
*c
, struct face
*face
, unsigned int hash
)
4485 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4489 if (face
->ascii_face
!= face
)
4491 struct face
*last
= c
->buckets
[i
];
4502 c
->buckets
[i
] = face
;
4503 face
->prev
= face
->next
= NULL
;
4509 face
->next
= c
->buckets
[i
];
4511 face
->next
->prev
= face
;
4512 c
->buckets
[i
] = face
;
4515 /* Find a free slot in C->faces_by_id and use the index of the free
4516 slot as FACE->id. */
4517 for (i
= 0; i
< c
->used
; ++i
)
4518 if (c
->faces_by_id
[i
] == NULL
)
4522 /* Maybe enlarge C->faces_by_id. */
4525 if (c
->used
== c
->size
)
4528 new_size
= min (2 * c
->size
, MAX_FACE_ID
);
4529 if (new_size
== c
->size
)
4530 abort (); /* Alternatives? ++kfs */
4531 sz
= new_size
* sizeof *c
->faces_by_id
;
4532 c
->faces_by_id
= (struct face
**) xrealloc (c
->faces_by_id
, sz
);
4539 /* Check that FACE got a unique id. */
4544 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
4545 for (face
= c
->buckets
[j
]; face
; face
= face
->next
)
4551 #endif /* GLYPH_DEBUG */
4553 c
->faces_by_id
[i
] = face
;
4557 /* Remove face FACE from cache C. */
4560 uncache_face (struct face_cache
*c
, struct face
*face
)
4562 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
4565 face
->prev
->next
= face
->next
;
4567 c
->buckets
[i
] = face
->next
;
4570 face
->next
->prev
= face
->prev
;
4572 c
->faces_by_id
[face
->id
] = NULL
;
4573 if (face
->id
== c
->used
)
4578 /* Look up a realized face with face attributes ATTR in the face cache
4579 of frame F. The face will be used to display ASCII characters.
4580 Value is the ID of the face found. If no suitable face is found,
4581 realize a new one. */
4584 lookup_face (struct frame
*f
, Lisp_Object
*attr
)
4586 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4591 xassert (cache
!= NULL
);
4592 check_lface_attrs (attr
);
4594 /* Look up ATTR in the face cache. */
4595 hash
= lface_hash (attr
);
4596 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4598 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4600 if (face
->ascii_face
!= face
)
4602 /* There's no more ASCII face. */
4606 if (face
->hash
== hash
4607 && lface_equal_p (face
->lface
, attr
))
4611 /* If not found, realize a new face. */
4613 face
= realize_face (cache
, attr
, -1);
4616 xassert (face
== FACE_FROM_ID (f
, face
->id
));
4617 #endif /* GLYPH_DEBUG */
4622 #ifdef HAVE_WINDOW_SYSTEM
4623 /* Look up a realized face that has the same attributes as BASE_FACE
4624 except for the font in the face cache of frame F. If FONT-OBJECT
4625 is not nil, it is an already opened font. If FONT-OBJECT is nil,
4626 the face has no font. Value is the ID of the face found. If no
4627 suitable face is found, realize a new one. */
4630 face_for_font (struct frame
*f
, Lisp_Object font_object
, struct face
*base_face
)
4632 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4637 xassert (cache
!= NULL
);
4638 base_face
= base_face
->ascii_face
;
4639 hash
= lface_hash (base_face
->lface
);
4640 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4642 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4644 if (face
->ascii_face
== face
)
4646 if (face
->ascii_face
== base_face
4647 && face
->font
== (NILP (font_object
) ? NULL
4648 : XFONT_OBJECT (font_object
))
4649 && lface_equal_p (face
->lface
, base_face
->lface
))
4653 /* If not found, realize a new face. */
4654 face
= realize_non_ascii_face (f
, font_object
, base_face
);
4657 #endif /* HAVE_WINDOW_SYSTEM */
4659 /* Return the face id of the realized face for named face SYMBOL on
4660 frame F suitable for displaying ASCII characters. Value is -1 if
4661 the face couldn't be determined, which might happen if the default
4662 face isn't realized and cannot be realized. */
4665 lookup_named_face (struct frame
*f
, Lisp_Object symbol
, int signal_p
)
4667 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4668 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4669 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4671 if (default_face
== NULL
)
4673 if (!realize_basic_faces (f
))
4675 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4676 if (default_face
== NULL
)
4677 abort (); /* realize_basic_faces must have set it up */
4680 if (! get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4683 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4684 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4686 return lookup_face (f
, attrs
);
4690 /* Return the display face-id of the basic face who's canonical face-id
4691 is FACE_ID. The return value will usually simply be FACE_ID, unless that
4692 basic face has bee remapped via Vface_remapping_alist. This function is
4693 conservative: if something goes wrong, it will simply return FACE_ID
4694 rather than signal an error. */
4697 lookup_basic_face (struct frame
*f
, int face_id
)
4699 Lisp_Object name
, mapping
;
4700 int remapped_face_id
;
4702 if (NILP (Vface_remapping_alist
))
4703 return face_id
; /* Nothing to do. */
4707 case DEFAULT_FACE_ID
: name
= Qdefault
; break;
4708 case MODE_LINE_FACE_ID
: name
= Qmode_line
; break;
4709 case MODE_LINE_INACTIVE_FACE_ID
: name
= Qmode_line_inactive
; break;
4710 case HEADER_LINE_FACE_ID
: name
= Qheader_line
; break;
4711 case TOOL_BAR_FACE_ID
: name
= Qtool_bar
; break;
4712 case FRINGE_FACE_ID
: name
= Qfringe
; break;
4713 case SCROLL_BAR_FACE_ID
: name
= Qscroll_bar
; break;
4714 case BORDER_FACE_ID
: name
= Qborder
; break;
4715 case CURSOR_FACE_ID
: name
= Qcursor
; break;
4716 case MOUSE_FACE_ID
: name
= Qmouse
; break;
4717 case MENU_FACE_ID
: name
= Qmenu
; break;
4720 abort (); /* the caller is supposed to pass us a basic face id */
4723 /* Do a quick scan through Vface_remapping_alist, and return immediately
4724 if there is no remapping for face NAME. This is just an optimization
4725 for the very common no-remapping case. */
4726 mapping
= assq_no_quit (name
, Vface_remapping_alist
);
4728 return face_id
; /* Give up. */
4730 /* If there is a remapping entry, lookup the face using NAME, which will
4731 handle the remapping too. */
4732 remapped_face_id
= lookup_named_face (f
, name
, 0);
4733 if (remapped_face_id
< 0)
4734 return face_id
; /* Give up. */
4736 return remapped_face_id
;
4740 /* Return the ID of the realized ASCII face of Lisp face with ID
4741 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
4744 ascii_face_of_lisp_face (struct frame
*f
, int lface_id
)
4748 if (lface_id
>= 0 && lface_id
< lface_id_to_name_size
)
4750 Lisp_Object face_name
= lface_id_to_name
[lface_id
];
4751 face_id
= lookup_named_face (f
, face_name
, 1);
4760 /* Return a face for charset ASCII that is like the face with id
4761 FACE_ID on frame F, but has a font that is STEPS steps smaller.
4762 STEPS < 0 means larger. Value is the id of the face. */
4765 smaller_face (struct frame
*f
, int face_id
, int steps
)
4767 #ifdef HAVE_WINDOW_SYSTEM
4769 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4770 int pt
, last_pt
, last_height
;
4773 struct face
*new_face
;
4775 /* If not called for an X frame, just return the original face. */
4776 if (FRAME_TERMCAP_P (f
))
4779 /* Try in increments of 1/2 pt. */
4780 delta
= steps
< 0 ? 5 : -5;
4781 steps
= eabs (steps
);
4783 face
= FACE_FROM_ID (f
, face_id
);
4784 memcpy (attrs
, face
->lface
, sizeof attrs
);
4785 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
4786 new_face_id
= face_id
;
4787 last_height
= FONT_HEIGHT (face
->font
);
4791 /* Give up if we cannot find a font within 10pt. */
4792 && eabs (last_pt
- pt
) < 100)
4794 /* Look up a face for a slightly smaller/larger font. */
4796 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
4797 new_face_id
= lookup_face (f
, attrs
);
4798 new_face
= FACE_FROM_ID (f
, new_face_id
);
4800 /* If height changes, count that as one step. */
4801 if ((delta
< 0 && FONT_HEIGHT (new_face
->font
) < last_height
)
4802 || (delta
> 0 && FONT_HEIGHT (new_face
->font
) > last_height
))
4805 last_height
= FONT_HEIGHT (new_face
->font
);
4812 #else /* not HAVE_WINDOW_SYSTEM */
4816 #endif /* not HAVE_WINDOW_SYSTEM */
4820 /* Return a face for charset ASCII that is like the face with id
4821 FACE_ID on frame F, but has height HEIGHT. */
4824 face_with_height (struct frame
*f
, int face_id
, int height
)
4826 #ifdef HAVE_WINDOW_SYSTEM
4828 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4830 if (FRAME_TERMCAP_P (f
)
4834 face
= FACE_FROM_ID (f
, face_id
);
4835 memcpy (attrs
, face
->lface
, sizeof attrs
);
4836 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
4837 font_clear_prop (attrs
, FONT_SIZE_INDEX
);
4838 face_id
= lookup_face (f
, attrs
);
4839 #endif /* HAVE_WINDOW_SYSTEM */
4845 /* Return the face id of the realized face for named face SYMBOL on
4846 frame F suitable for displaying ASCII characters, and use
4847 attributes of the face FACE_ID for attributes that aren't
4848 completely specified by SYMBOL. This is like lookup_named_face,
4849 except that the default attributes come from FACE_ID, not from the
4850 default face. FACE_ID is assumed to be already realized. */
4853 lookup_derived_face (struct frame
*f
, Lisp_Object symbol
, int face_id
, int signal_p
)
4855 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4856 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4857 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
4862 if (!get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4865 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4866 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4867 return lookup_face (f
, attrs
);
4870 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector
,
4871 Sface_attributes_as_vector
, 1, 1, 0,
4872 doc
: /* Return a vector of face attributes corresponding to PLIST. */)
4877 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
4879 merge_face_ref (XFRAME (selected_frame
), plist
, XVECTOR (lface
)->contents
,
4886 /***********************************************************************
4887 Face capability testing
4888 ***********************************************************************/
4891 /* If the distance (as returned by color_distance) between two colors is
4892 less than this, then they are considered the same, for determining
4893 whether a color is supported or not. The range of values is 0-65535. */
4895 #define TTY_SAME_COLOR_THRESHOLD 10000
4897 #ifdef HAVE_WINDOW_SYSTEM
4899 /* Return non-zero if all the face attributes in ATTRS are supported
4900 on the window-system frame F.
4902 The definition of `supported' is somewhat heuristic, but basically means
4903 that a face containing all the attributes in ATTRS, when merged with the
4904 default face for display, can be represented in a way that's
4906 \(1) different in appearance than the default face, and
4907 \(2) `close in spirit' to what the attributes specify, if not exact. */
4910 x_supports_face_attributes_p (struct frame
*f
, Lisp_Object
*attrs
, struct face
*def_face
)
4912 Lisp_Object
*def_attrs
= def_face
->lface
;
4914 /* Check that other specified attributes are different that the default
4916 if ((!UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
4917 && face_attr_equal_p (attrs
[LFACE_UNDERLINE_INDEX
],
4918 def_attrs
[LFACE_UNDERLINE_INDEX
]))
4919 || (!UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
4920 && face_attr_equal_p (attrs
[LFACE_INVERSE_INDEX
],
4921 def_attrs
[LFACE_INVERSE_INDEX
]))
4922 || (!UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
4923 && face_attr_equal_p (attrs
[LFACE_FOREGROUND_INDEX
],
4924 def_attrs
[LFACE_FOREGROUND_INDEX
]))
4925 || (!UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
4926 && face_attr_equal_p (attrs
[LFACE_BACKGROUND_INDEX
],
4927 def_attrs
[LFACE_BACKGROUND_INDEX
]))
4928 || (!UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
4929 && face_attr_equal_p (attrs
[LFACE_STIPPLE_INDEX
],
4930 def_attrs
[LFACE_STIPPLE_INDEX
]))
4931 || (!UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
4932 && face_attr_equal_p (attrs
[LFACE_OVERLINE_INDEX
],
4933 def_attrs
[LFACE_OVERLINE_INDEX
]))
4934 || (!UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
4935 && face_attr_equal_p (attrs
[LFACE_STRIKE_THROUGH_INDEX
],
4936 def_attrs
[LFACE_STRIKE_THROUGH_INDEX
]))
4937 || (!UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
4938 && face_attr_equal_p (attrs
[LFACE_BOX_INDEX
],
4939 def_attrs
[LFACE_BOX_INDEX
])))
4942 /* Check font-related attributes, as those are the most commonly
4943 "unsupported" on a window-system (because of missing fonts). */
4944 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
4945 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
4946 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
4947 || !UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
4948 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
4949 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
]))
4953 Lisp_Object merged_attrs
[LFACE_VECTOR_SIZE
];
4956 memcpy (merged_attrs
, def_attrs
, sizeof merged_attrs
);
4958 merge_face_vectors (f
, attrs
, merged_attrs
, 0);
4960 face_id
= lookup_face (f
, merged_attrs
);
4961 face
= FACE_FROM_ID (f
, face_id
);
4964 error ("Cannot make face");
4966 /* If the font is the same, or no font is found, then not
4968 if (face
->font
== def_face
->font
4971 for (i
= FONT_TYPE_INDEX
; i
<= FONT_SIZE_INDEX
; i
++)
4972 if (! EQ (face
->font
->props
[i
], def_face
->font
->props
[i
]))
4976 if (i
< FONT_FOUNDRY_INDEX
|| i
> FONT_REGISTRY_INDEX
4977 || face
->font
->driver
->case_sensitive
)
4979 s1
= SYMBOL_NAME (face
->font
->props
[i
]);
4980 s2
= SYMBOL_NAME (def_face
->font
->props
[i
]);
4981 if (! EQ (Fcompare_strings (s1
, make_number (0), Qnil
,
4982 s2
, make_number (0), Qnil
, Qt
), Qt
))
4988 /* Everything checks out, this face is supported. */
4992 #endif /* HAVE_WINDOW_SYSTEM */
4994 /* Return non-zero if all the face attributes in ATTRS are supported
4997 The definition of `supported' is somewhat heuristic, but basically means
4998 that a face containing all the attributes in ATTRS, when merged
4999 with the default face for display, can be represented in a way that's
5001 \(1) different in appearance than the default face, and
5002 \(2) `close in spirit' to what the attributes specify, if not exact.
5004 Point (2) implies that a `:weight black' attribute will be satisfied
5005 by any terminal that can display bold, and a `:foreground "yellow"' as
5006 long as the terminal can display a yellowish color, but `:slant italic'
5007 will _not_ be satisfied by the tty display code's automatic
5008 substitution of a `dim' face for italic. */
5011 tty_supports_face_attributes_p (struct frame
*f
, Lisp_Object
*attrs
, struct face
*def_face
)
5014 Lisp_Object val
, fg
, bg
;
5015 XColor fg_tty_color
, fg_std_color
;
5016 XColor bg_tty_color
, bg_std_color
;
5017 unsigned test_caps
= 0;
5018 Lisp_Object
*def_attrs
= def_face
->lface
;
5021 /* First check some easy-to-check stuff; ttys support none of the
5022 following attributes, so we can just return false if any are requested
5023 (even if `nominal' values are specified, we should still return false,
5024 as that will be the same value that the default face uses). We
5025 consider :slant unsupportable on ttys, even though the face code
5026 actually `fakes' them using a dim attribute if possible. This is
5027 because the faked result is too different from what the face
5029 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
5030 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
5031 || !UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
5032 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
5033 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
5034 || !UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
5035 || !UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
5036 || !UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
5037 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
]))
5041 /* Test for terminal `capabilities' (non-color character attributes). */
5043 /* font weight (bold/dim) */
5044 val
= attrs
[LFACE_WEIGHT_INDEX
];
5045 if (!UNSPECIFIEDP (val
)
5046 && (weight
= FONT_WEIGHT_NAME_NUMERIC (val
), weight
>= 0))
5048 int def_weight
= FONT_WEIGHT_NAME_NUMERIC (def_attrs
[LFACE_WEIGHT_INDEX
]);
5052 if (def_weight
> 100)
5053 return 0; /* same as default */
5054 test_caps
= TTY_CAP_BOLD
;
5056 else if (weight
< 100)
5058 if (def_weight
< 100)
5059 return 0; /* same as default */
5060 test_caps
= TTY_CAP_DIM
;
5062 else if (def_weight
== 100)
5063 return 0; /* same as default */
5067 val
= attrs
[LFACE_UNDERLINE_INDEX
];
5068 if (!UNSPECIFIEDP (val
))
5071 return 0; /* ttys can't use colored underlines */
5072 else if (face_attr_equal_p (val
, def_attrs
[LFACE_UNDERLINE_INDEX
]))
5073 return 0; /* same as default */
5075 test_caps
|= TTY_CAP_UNDERLINE
;
5079 val
= attrs
[LFACE_INVERSE_INDEX
];
5080 if (!UNSPECIFIEDP (val
))
5082 if (face_attr_equal_p (val
, def_attrs
[LFACE_INVERSE_INDEX
]))
5083 return 0; /* same as default */
5085 test_caps
|= TTY_CAP_INVERSE
;
5089 /* Color testing. */
5091 /* Default the color indices in FG_TTY_COLOR and BG_TTY_COLOR, since
5092 we use them when calling `tty_capable_p' below, even if the face
5093 specifies no colors. */
5094 fg_tty_color
.pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5095 bg_tty_color
.pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5097 /* Check if foreground color is close enough. */
5098 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
5101 Lisp_Object def_fg
= def_attrs
[LFACE_FOREGROUND_INDEX
];
5103 if (face_attr_equal_p (fg
, def_fg
))
5104 return 0; /* same as default */
5105 else if (! tty_lookup_color (f
, fg
, &fg_tty_color
, &fg_std_color
))
5106 return 0; /* not a valid color */
5107 else if (color_distance (&fg_tty_color
, &fg_std_color
)
5108 > TTY_SAME_COLOR_THRESHOLD
)
5109 return 0; /* displayed color is too different */
5111 /* Make sure the color is really different than the default. */
5113 XColor def_fg_color
;
5114 if (tty_lookup_color (f
, def_fg
, &def_fg_color
, 0)
5115 && (color_distance (&fg_tty_color
, &def_fg_color
)
5116 <= TTY_SAME_COLOR_THRESHOLD
))
5121 /* Check if background color is close enough. */
5122 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
5125 Lisp_Object def_bg
= def_attrs
[LFACE_BACKGROUND_INDEX
];
5127 if (face_attr_equal_p (bg
, def_bg
))
5128 return 0; /* same as default */
5129 else if (! tty_lookup_color (f
, bg
, &bg_tty_color
, &bg_std_color
))
5130 return 0; /* not a valid color */
5131 else if (color_distance (&bg_tty_color
, &bg_std_color
)
5132 > TTY_SAME_COLOR_THRESHOLD
)
5133 return 0; /* displayed color is too different */
5135 /* Make sure the color is really different than the default. */
5137 XColor def_bg_color
;
5138 if (tty_lookup_color (f
, def_bg
, &def_bg_color
, 0)
5139 && (color_distance (&bg_tty_color
, &def_bg_color
)
5140 <= TTY_SAME_COLOR_THRESHOLD
))
5145 /* If both foreground and background are requested, see if the
5146 distance between them is OK. We just check to see if the distance
5147 between the tty's foreground and background is close enough to the
5148 distance between the standard foreground and background. */
5149 if (STRINGP (fg
) && STRINGP (bg
))
5152 = (color_distance (&fg_std_color
, &bg_std_color
)
5153 - color_distance (&fg_tty_color
, &bg_tty_color
));
5154 if (delta_delta
> TTY_SAME_COLOR_THRESHOLD
5155 || delta_delta
< -TTY_SAME_COLOR_THRESHOLD
)
5160 /* See if the capabilities we selected above are supported, with the
5162 if (test_caps
!= 0 &&
5163 ! tty_capable_p (FRAME_TTY (f
), test_caps
, fg_tty_color
.pixel
, bg_tty_color
.pixel
))
5167 /* Hmmm, everything checks out, this terminal must support this face. */
5172 DEFUN ("display-supports-face-attributes-p",
5173 Fdisplay_supports_face_attributes_p
, Sdisplay_supports_face_attributes_p
,
5175 doc
: /* Return non-nil if all the face attributes in ATTRIBUTES are supported.
5176 The optional argument DISPLAY can be a display name, a frame, or
5177 nil (meaning the selected frame's display).
5179 The definition of `supported' is somewhat heuristic, but basically means
5180 that a face containing all the attributes in ATTRIBUTES, when merged
5181 with the default face for display, can be represented in a way that's
5183 \(1) different in appearance than the default face, and
5184 \(2) `close in spirit' to what the attributes specify, if not exact.
5186 Point (2) implies that a `:weight black' attribute will be satisfied by
5187 any display that can display bold, and a `:foreground \"yellow\"' as long
5188 as it can display a yellowish color, but `:slant italic' will _not_ be
5189 satisfied by the tty display code's automatic substitution of a `dim'
5190 face for italic. */)
5191 (attributes
, display
)
5192 Lisp_Object attributes
, display
;
5194 int supports
= 0, i
;
5197 struct face
*def_face
;
5198 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5200 if (noninteractive
|| !initialized
)
5201 /* We may not be able to access low-level face information in batch
5202 mode, or before being dumped, and this function is not going to
5203 be very useful in those cases anyway, so just give up. */
5207 frame
= selected_frame
;
5208 else if (FRAMEP (display
))
5212 /* Find any frame on DISPLAY. */
5213 Lisp_Object fl_tail
;
5216 for (fl_tail
= Vframe_list
; CONSP (fl_tail
); fl_tail
= XCDR (fl_tail
))
5218 frame
= XCAR (fl_tail
);
5219 if (!NILP (Fequal (Fcdr (Fassq (Qdisplay
,
5220 XFRAME (frame
)->param_alist
)),
5226 CHECK_LIVE_FRAME (frame
);
5229 for (i
= 0; i
< LFACE_VECTOR_SIZE
; i
++)
5230 attrs
[i
] = Qunspecified
;
5231 merge_face_ref (f
, attributes
, attrs
, 1, 0);
5233 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5234 if (def_face
== NULL
)
5236 if (! realize_basic_faces (f
))
5237 error ("Cannot realize default face");
5238 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5239 if (def_face
== NULL
)
5240 abort (); /* realize_basic_faces must have set it up */
5243 /* Dispatch to the appropriate handler. */
5244 if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5245 supports
= tty_supports_face_attributes_p (f
, attrs
, def_face
);
5246 #ifdef HAVE_WINDOW_SYSTEM
5248 supports
= x_supports_face_attributes_p (f
, attrs
, def_face
);
5251 return supports
? Qt
: Qnil
;
5255 /***********************************************************************
5257 ***********************************************************************/
5259 DEFUN ("internal-set-font-selection-order",
5260 Finternal_set_font_selection_order
,
5261 Sinternal_set_font_selection_order
, 1, 1, 0,
5262 doc
: /* Set font selection order for face font selection to ORDER.
5263 ORDER must be a list of length 4 containing the symbols `:width',
5264 `:height', `:weight', and `:slant'. Face attributes appearing
5265 first in ORDER are matched first, e.g. if `:height' appears before
5266 `:weight' in ORDER, font selection first tries to find a font with
5267 a suitable height, and then tries to match the font weight.
5274 int indices
[DIM (font_sort_order
)];
5277 memset (indices
, 0, sizeof indices
);
5281 CONSP (list
) && i
< DIM (indices
);
5282 list
= XCDR (list
), ++i
)
5284 Lisp_Object attr
= XCAR (list
);
5287 if (EQ (attr
, QCwidth
))
5289 else if (EQ (attr
, QCheight
))
5290 xlfd
= XLFD_POINT_SIZE
;
5291 else if (EQ (attr
, QCweight
))
5293 else if (EQ (attr
, QCslant
))
5298 if (indices
[i
] != 0)
5303 if (!NILP (list
) || i
!= DIM (indices
))
5304 signal_error ("Invalid font sort order", order
);
5305 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5306 if (indices
[i
] == 0)
5307 signal_error ("Invalid font sort order", order
);
5309 if (memcmp (indices
, font_sort_order
, sizeof indices
) != 0)
5311 memcpy (font_sort_order
, indices
, sizeof font_sort_order
);
5312 free_all_realized_faces (Qnil
);
5315 font_update_sort_order (font_sort_order
);
5321 DEFUN ("internal-set-alternative-font-family-alist",
5322 Finternal_set_alternative_font_family_alist
,
5323 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
5324 doc
: /* Define alternative font families to try in face font selection.
5325 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5326 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
5327 be found. Value is ALIST. */)
5331 Lisp_Object entry
, tail
, tail2
;
5334 alist
= Fcopy_sequence (alist
);
5335 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5337 entry
= XCAR (tail
);
5339 entry
= Fcopy_sequence (entry
);
5340 XSETCAR (tail
, entry
);
5341 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5342 XSETCAR (tail2
, Fintern (XCAR (tail2
), Qnil
));
5345 Vface_alternative_font_family_alist
= alist
;
5346 free_all_realized_faces (Qnil
);
5351 DEFUN ("internal-set-alternative-font-registry-alist",
5352 Finternal_set_alternative_font_registry_alist
,
5353 Sinternal_set_alternative_font_registry_alist
, 1, 1, 0,
5354 doc
: /* Define alternative font registries to try in face font selection.
5355 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5356 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
5357 be found. Value is ALIST. */)
5361 Lisp_Object entry
, tail
, tail2
;
5364 alist
= Fcopy_sequence (alist
);
5365 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5367 entry
= XCAR (tail
);
5369 entry
= Fcopy_sequence (entry
);
5370 XSETCAR (tail
, entry
);
5371 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5372 XSETCAR (tail2
, Fdowncase (XCAR (tail2
)));
5374 Vface_alternative_font_registry_alist
= alist
;
5375 free_all_realized_faces (Qnil
);
5380 #ifdef HAVE_WINDOW_SYSTEM
5382 /* Ignore the difference of font point size less than this value. */
5384 #define FONT_POINT_SIZE_QUANTUM 5
5386 /* Return the fontset id of the base fontset name or alias name given
5387 by the fontset attribute of ATTRS. Value is -1 if the fontset
5388 attribute of ATTRS doesn't name a fontset. */
5391 face_fontset (Lisp_Object
*attrs
)
5395 name
= attrs
[LFACE_FONTSET_INDEX
];
5396 if (!STRINGP (name
))
5398 return fs_query_fontset (name
, 0);
5401 #endif /* HAVE_WINDOW_SYSTEM */
5405 /***********************************************************************
5407 ***********************************************************************/
5409 /* Realize basic faces on frame F. Value is zero if frame parameters
5410 of F don't contain enough information needed to realize the default
5414 realize_basic_faces (struct frame
*f
)
5417 int count
= SPECPDL_INDEX ();
5419 /* Block input here so that we won't be surprised by an X expose
5420 event, for instance, without having the faces set up. */
5422 specbind (Qscalable_fonts_allowed
, Qt
);
5424 if (realize_default_face (f
))
5426 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
5427 realize_named_face (f
, Qmode_line_inactive
, MODE_LINE_INACTIVE_FACE_ID
);
5428 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
5429 realize_named_face (f
, Qfringe
, FRINGE_FACE_ID
);
5430 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
5431 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
5432 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
5433 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
5434 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
5435 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
5436 realize_named_face (f
, Qvertical_border
, VERTICAL_BORDER_FACE_ID
);
5438 /* Reflect changes in the `menu' face in menu bars. */
5439 if (FRAME_FACE_CACHE (f
)->menu_face_changed_p
)
5441 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 0;
5442 #ifdef USE_X_TOOLKIT
5443 if (FRAME_WINDOW_P (f
))
5444 x_update_menu_appearance (f
);
5451 unbind_to (count
, Qnil
);
5457 /* Realize the default face on frame F. If the face is not fully
5458 specified, make it fully-specified. Attributes of the default face
5459 that are not explicitly specified are taken from frame parameters. */
5462 realize_default_face (struct frame
*f
)
5464 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5466 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5469 /* If the `default' face is not yet known, create it. */
5470 lface
= lface_from_face_name (f
, Qdefault
, 0);
5474 XSETFRAME (frame
, f
);
5475 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
5478 #ifdef HAVE_WINDOW_SYSTEM
5479 if (FRAME_WINDOW_P (f
))
5481 Lisp_Object font_object
;
5483 XSETFONT (font_object
, FRAME_FONT (f
));
5484 set_lface_from_font (f
, lface
, font_object
, f
->default_face_done_p
);
5485 LFACE_FONTSET (lface
) = fontset_name (FRAME_FONTSET (f
));
5486 f
->default_face_done_p
= 1;
5488 #endif /* HAVE_WINDOW_SYSTEM */
5490 if (!FRAME_WINDOW_P (f
))
5492 LFACE_FAMILY (lface
) = build_string ("default");
5493 LFACE_FOUNDRY (lface
) = LFACE_FAMILY (lface
);
5494 LFACE_SWIDTH (lface
) = Qnormal
;
5495 LFACE_HEIGHT (lface
) = make_number (1);
5496 if (UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
5497 LFACE_WEIGHT (lface
) = Qnormal
;
5498 if (UNSPECIFIEDP (LFACE_SLANT (lface
)))
5499 LFACE_SLANT (lface
) = Qnormal
;
5500 if (UNSPECIFIEDP (LFACE_FONTSET (lface
)))
5501 LFACE_FONTSET (lface
) = Qnil
;
5504 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
5505 LFACE_UNDERLINE (lface
) = Qnil
;
5507 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
5508 LFACE_OVERLINE (lface
) = Qnil
;
5510 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
5511 LFACE_STRIKE_THROUGH (lface
) = Qnil
;
5513 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
5514 LFACE_BOX (lface
) = Qnil
;
5516 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
5517 LFACE_INVERSE (lface
) = Qnil
;
5519 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
5521 /* This function is called so early that colors are not yet
5522 set in the frame parameter list. */
5523 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
5525 if (CONSP (color
) && STRINGP (XCDR (color
)))
5526 LFACE_FOREGROUND (lface
) = XCDR (color
);
5527 else if (FRAME_WINDOW_P (f
))
5529 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5530 LFACE_FOREGROUND (lface
) = build_string (unspecified_fg
);
5535 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
5537 /* This function is called so early that colors are not yet
5538 set in the frame parameter list. */
5539 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
5540 if (CONSP (color
) && STRINGP (XCDR (color
)))
5541 LFACE_BACKGROUND (lface
) = XCDR (color
);
5542 else if (FRAME_WINDOW_P (f
))
5544 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5545 LFACE_BACKGROUND (lface
) = build_string (unspecified_bg
);
5550 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
5551 LFACE_STIPPLE (lface
) = Qnil
;
5553 /* Realize the face; it must be fully-specified now. */
5554 xassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
5555 check_lface (lface
);
5556 memcpy (attrs
, XVECTOR (lface
)->contents
, sizeof attrs
);
5557 face
= realize_face (c
, attrs
, DEFAULT_FACE_ID
);
5559 #ifdef HAVE_WINDOW_SYSTEM
5560 #ifdef HAVE_X_WINDOWS
5561 if (FRAME_X_P (f
) && face
->font
!= FRAME_FONT (f
))
5563 /* This can happen when making a frame on a display that does
5564 not support the default font. */
5568 /* Otherwise, the font specified for the frame was not
5569 acceptable as a font for the default face (perhaps because
5570 auto-scaled fonts are rejected), so we must adjust the frame
5572 x_set_font (f
, LFACE_FONT (lface
), Qnil
);
5574 #endif /* HAVE_X_WINDOWS */
5575 #endif /* HAVE_WINDOW_SYSTEM */
5580 /* Realize basic faces other than the default face in face cache C.
5581 SYMBOL is the face name, ID is the face id the realized face must
5582 have. The default face must have been realized already. */
5585 realize_named_face (struct frame
*f
, Lisp_Object symbol
, int id
)
5587 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5588 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
5589 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5590 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5591 struct face
*new_face
;
5593 /* The default face must exist and be fully specified. */
5594 get_lface_attributes_no_remap (f
, Qdefault
, attrs
, 1);
5595 check_lface_attrs (attrs
);
5596 xassert (lface_fully_specified_p (attrs
));
5598 /* If SYMBOL isn't know as a face, create it. */
5602 XSETFRAME (frame
, f
);
5603 lface
= Finternal_make_lisp_face (symbol
, frame
);
5606 /* Merge SYMBOL's face with the default face. */
5607 get_lface_attributes_no_remap (f
, symbol
, symbol_attrs
, 1);
5608 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
5610 /* Realize the face. */
5611 new_face
= realize_face (c
, attrs
, id
);
5615 /* Realize the fully-specified face with attributes ATTRS in face
5616 cache CACHE for ASCII characters. If FORMER_FACE_ID is
5617 non-negative, it is an ID of face to remove before caching the new
5618 face. Value is a pointer to the newly created realized face. */
5620 static struct face
*
5621 realize_face (struct face_cache
*cache
, Lisp_Object
*attrs
, int former_face_id
)
5625 /* LFACE must be fully specified. */
5626 xassert (cache
!= NULL
);
5627 check_lface_attrs (attrs
);
5629 if (former_face_id
>= 0 && cache
->used
> former_face_id
)
5631 /* Remove the former face. */
5632 struct face
*former_face
= cache
->faces_by_id
[former_face_id
];
5633 uncache_face (cache
, former_face
);
5634 free_realized_face (cache
->f
, former_face
);
5637 if (FRAME_WINDOW_P (cache
->f
))
5638 face
= realize_x_face (cache
, attrs
);
5639 else if (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
))
5640 face
= realize_tty_face (cache
, attrs
);
5641 else if (FRAME_INITIAL_P (cache
->f
))
5643 /* Create a dummy face. */
5644 face
= make_realized_face (attrs
);
5649 /* Insert the new face. */
5650 cache_face (cache
, face
, lface_hash (attrs
));
5655 #ifdef HAVE_WINDOW_SYSTEM
5656 /* Realize the fully-specified face that uses FONT-OBJECT and has the
5657 same attributes as BASE_FACE except for the font on frame F.
5658 FONT-OBJECT may be nil, in which case, realized a face of
5661 static struct face
*
5662 realize_non_ascii_face (struct frame
*f
, Lisp_Object font_object
, struct face
*base_face
)
5664 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5667 face
= (struct face
*) xmalloc (sizeof *face
);
5672 = (! NILP (font_object
)
5673 && FONT_WEIGHT_NAME_NUMERIC (face
->lface
[LFACE_WEIGHT_INDEX
]) > 100
5674 && FONT_WEIGHT_NUMERIC (font_object
) <= 100);
5676 /* Don't try to free the colors copied bitwise from BASE_FACE. */
5677 face
->colors_copied_bitwise_p
= 1;
5678 face
->font
= NILP (font_object
) ? NULL
: XFONT_OBJECT (font_object
);
5681 cache_face (cache
, face
, face
->hash
);
5685 #endif /* HAVE_WINDOW_SYSTEM */
5688 /* Realize the fully-specified face with attributes ATTRS in face
5689 cache CACHE for ASCII characters. Do it for X frame CACHE->f. If
5690 the new face doesn't share font with the default face, a fontname
5691 is allocated from the heap and set in `font_name' of the new face,
5692 but it is not yet loaded here. Value is a pointer to the newly
5693 created realized face. */
5695 static struct face
*
5696 realize_x_face (struct face_cache
*cache
, Lisp_Object
*attrs
)
5698 struct face
*face
= NULL
;
5699 #ifdef HAVE_WINDOW_SYSTEM
5700 struct face
*default_face
;
5702 Lisp_Object stipple
, overline
, strike_through
, box
;
5704 xassert (FRAME_WINDOW_P (cache
->f
));
5706 /* Allocate a new realized face. */
5707 face
= make_realized_face (attrs
);
5708 face
->ascii_face
= face
;
5712 /* Determine the font to use. Most of the time, the font will be
5713 the same as the font of the default face, so try that first. */
5714 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5716 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
5718 face
->font
= default_face
->font
;
5720 = make_fontset_for_ascii_face (f
, default_face
->fontset
, face
);
5724 /* If the face attribute ATTRS specifies a fontset, use it as
5725 the base of a new realized fontset. Otherwise, use the same
5726 base fontset as of the default face. The base determines
5727 registry and encoding of a font. It may also determine
5728 foundry and family. The other fields of font name pattern
5729 are constructed from ATTRS. */
5730 int fontset
= face_fontset (attrs
);
5732 /* If we are realizing the default face, ATTRS should specify a
5733 fontset. In other words, if FONTSET is -1, we are not
5734 realizing the default face, thus the default face should have
5735 already been realized. */
5739 fontset
= default_face
->fontset
;
5743 if (! FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5744 attrs
[LFACE_FONT_INDEX
]
5745 = font_load_for_lface (f
, attrs
, attrs
[LFACE_FONT_INDEX
]);
5746 if (FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5748 face
->font
= XFONT_OBJECT (attrs
[LFACE_FONT_INDEX
]);
5749 face
->fontset
= make_fontset_for_ascii_face (f
, fontset
, face
);
5759 && FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]) > 100
5760 && FONT_WEIGHT_NUMERIC (attrs
[LFACE_FONT_INDEX
]) <= 100)
5761 face
->overstrike
= 1;
5763 /* Load colors, and set remaining attributes. */
5765 load_face_colors (f
, face
, attrs
);
5768 box
= attrs
[LFACE_BOX_INDEX
];
5771 /* A simple box of line width 1 drawn in color given by
5773 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
5775 face
->box
= FACE_SIMPLE_BOX
;
5776 face
->box_line_width
= 1;
5778 else if (INTEGERP (box
))
5780 /* Simple box of specified line width in foreground color of the
5782 xassert (XINT (box
) != 0);
5783 face
->box
= FACE_SIMPLE_BOX
;
5784 face
->box_line_width
= XINT (box
);
5785 face
->box_color
= face
->foreground
;
5786 face
->box_color_defaulted_p
= 1;
5788 else if (CONSP (box
))
5790 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
5791 being one of `raised' or `sunken'. */
5792 face
->box
= FACE_SIMPLE_BOX
;
5793 face
->box_color
= face
->foreground
;
5794 face
->box_color_defaulted_p
= 1;
5795 face
->box_line_width
= 1;
5799 Lisp_Object keyword
, value
;
5801 keyword
= XCAR (box
);
5809 if (EQ (keyword
, QCline_width
))
5811 if (INTEGERP (value
) && XINT (value
) != 0)
5812 face
->box_line_width
= XINT (value
);
5814 else if (EQ (keyword
, QCcolor
))
5816 if (STRINGP (value
))
5818 face
->box_color
= load_color (f
, face
, value
,
5820 face
->use_box_color_for_shadows_p
= 1;
5823 else if (EQ (keyword
, QCstyle
))
5825 if (EQ (value
, Qreleased_button
))
5826 face
->box
= FACE_RAISED_BOX
;
5827 else if (EQ (value
, Qpressed_button
))
5828 face
->box
= FACE_SUNKEN_BOX
;
5833 /* Text underline, overline, strike-through. */
5835 if (EQ (attrs
[LFACE_UNDERLINE_INDEX
], Qt
))
5837 /* Use default color (same as foreground color). */
5838 face
->underline_p
= 1;
5839 face
->underline_defaulted_p
= 1;
5840 face
->underline_color
= 0;
5842 else if (STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]))
5844 /* Use specified color. */
5845 face
->underline_p
= 1;
5846 face
->underline_defaulted_p
= 0;
5847 face
->underline_color
5848 = load_color (f
, face
, attrs
[LFACE_UNDERLINE_INDEX
],
5849 LFACE_UNDERLINE_INDEX
);
5851 else if (NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5853 face
->underline_p
= 0;
5854 face
->underline_defaulted_p
= 0;
5855 face
->underline_color
= 0;
5858 overline
= attrs
[LFACE_OVERLINE_INDEX
];
5859 if (STRINGP (overline
))
5861 face
->overline_color
5862 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
5863 LFACE_OVERLINE_INDEX
);
5864 face
->overline_p
= 1;
5866 else if (EQ (overline
, Qt
))
5868 face
->overline_color
= face
->foreground
;
5869 face
->overline_color_defaulted_p
= 1;
5870 face
->overline_p
= 1;
5873 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
5874 if (STRINGP (strike_through
))
5876 face
->strike_through_color
5877 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
5878 LFACE_STRIKE_THROUGH_INDEX
);
5879 face
->strike_through_p
= 1;
5881 else if (EQ (strike_through
, Qt
))
5883 face
->strike_through_color
= face
->foreground
;
5884 face
->strike_through_color_defaulted_p
= 1;
5885 face
->strike_through_p
= 1;
5888 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
5889 if (!NILP (stipple
))
5890 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
5891 #endif /* HAVE_WINDOW_SYSTEM */
5897 /* Map a specified color of face FACE on frame F to a tty color index.
5898 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
5899 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
5900 default foreground/background colors. */
5903 map_tty_color (struct frame
*f
, struct face
*face
, enum lface_attribute_index idx
, int *defaulted
)
5905 Lisp_Object frame
, color
, def
;
5906 int foreground_p
= idx
== LFACE_FOREGROUND_INDEX
;
5907 unsigned long default_pixel
, default_other_pixel
, pixel
;
5909 xassert (idx
== LFACE_FOREGROUND_INDEX
|| idx
== LFACE_BACKGROUND_INDEX
);
5913 pixel
= default_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5914 default_other_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5918 pixel
= default_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5919 default_other_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5922 XSETFRAME (frame
, f
);
5923 color
= face
->lface
[idx
];
5927 && CONSP (Vtty_defined_color_alist
)
5928 && (def
= assq_no_quit (color
, call1 (Qtty_color_alist
, frame
)),
5931 /* Associations in tty-defined-color-alist are of the form
5932 (NAME INDEX R G B). We need the INDEX part. */
5933 pixel
= XINT (XCAR (XCDR (def
)));
5936 if (pixel
== default_pixel
&& STRINGP (color
))
5938 pixel
= load_color (f
, face
, color
, idx
);
5941 /* If the foreground of the default face is the default color,
5942 use the foreground color defined by the frame. */
5943 if (FRAME_MSDOS_P (f
))
5945 if (pixel
== default_pixel
5946 || pixel
== FACE_TTY_DEFAULT_COLOR
)
5949 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5951 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5952 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5955 else if (pixel
== default_other_pixel
)
5958 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5960 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5961 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5969 face
->foreground
= pixel
;
5971 face
->background
= pixel
;
5975 /* Realize the fully-specified face with attributes ATTRS in face
5976 cache CACHE for ASCII characters. Do it for TTY frame CACHE->f.
5977 Value is a pointer to the newly created realized face. */
5979 static struct face
*
5980 realize_tty_face (struct face_cache
*cache
, Lisp_Object
*attrs
)
5984 int face_colors_defaulted
= 0;
5985 struct frame
*f
= cache
->f
;
5987 /* Frame must be a termcap frame. */
5988 xassert (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
));
5990 /* Allocate a new realized face. */
5991 face
= make_realized_face (attrs
);
5993 face
->font_name
= FRAME_MSDOS_P (cache
->f
) ? "ms-dos" : "tty";
5996 /* Map face attributes to TTY appearances. We map slant to
5997 dimmed text because we want italic text to appear differently
5998 and because dimmed text is probably used infrequently. */
5999 weight
= FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]);
6000 slant
= FONT_SLANT_NAME_NUMERIC (attrs
[LFACE_SLANT_INDEX
]);
6002 face
->tty_bold_p
= 1;
6003 if (weight
< 100 || slant
!= 100)
6004 face
->tty_dim_p
= 1;
6005 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
6006 face
->tty_underline_p
= 1;
6007 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
6008 face
->tty_reverse_p
= 1;
6010 /* Map color names to color indices. */
6011 map_tty_color (f
, face
, LFACE_FOREGROUND_INDEX
, &face_colors_defaulted
);
6012 map_tty_color (f
, face
, LFACE_BACKGROUND_INDEX
, &face_colors_defaulted
);
6014 /* Swap colors if face is inverse-video. If the colors are taken
6015 from the frame colors, they are already inverted, since the
6016 frame-creation function calls x-handle-reverse-video. */
6017 if (face
->tty_reverse_p
&& !face_colors_defaulted
)
6019 unsigned long tem
= face
->foreground
;
6020 face
->foreground
= face
->background
;
6021 face
->background
= tem
;
6024 if (tty_suppress_bold_inverse_default_colors_p
6026 && face
->background
== FACE_TTY_DEFAULT_FG_COLOR
6027 && face
->foreground
== FACE_TTY_DEFAULT_BG_COLOR
)
6028 face
->tty_bold_p
= 0;
6034 DEFUN ("tty-suppress-bold-inverse-default-colors",
6035 Ftty_suppress_bold_inverse_default_colors
,
6036 Stty_suppress_bold_inverse_default_colors
, 1, 1, 0,
6037 doc
: /* Suppress/allow boldness of faces with inverse default colors.
6038 SUPPRESS non-nil means suppress it.
6039 This affects bold faces on TTYs whose foreground is the default background
6040 color of the display and whose background is the default foreground color.
6041 For such faces, the bold face attribute is ignored if this variable
6044 Lisp_Object suppress
;
6046 tty_suppress_bold_inverse_default_colors_p
= !NILP (suppress
);
6047 ++face_change_count
;
6053 /***********************************************************************
6055 ***********************************************************************/
6057 /* Return the ID of the face to use to display character CH with face
6058 property PROP on frame F in current_buffer. */
6061 compute_char_face (struct frame
*f
, int ch
, Lisp_Object prop
)
6065 if (NILP (current_buffer
->enable_multibyte_characters
))
6070 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6071 face_id
= FACE_FOR_CHAR (f
, face
, ch
, -1, Qnil
);
6075 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6076 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6077 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6078 merge_face_ref (f
, prop
, attrs
, 1, 0);
6079 face_id
= lookup_face (f
, attrs
);
6085 /* Return the face ID associated with buffer position POS for
6086 displaying ASCII characters. Return in *ENDPTR the position at
6087 which a different face is needed, as far as text properties and
6088 overlays are concerned. W is a window displaying current_buffer.
6090 REGION_BEG, REGION_END delimit the region, so it can be
6093 LIMIT is a position not to scan beyond. That is to limit the time
6094 this function can take.
6096 If MOUSE is non-zero, use the character's mouse-face, not its face.
6098 BASE_FACE_ID, if non-negative, specifies a base face id to use
6099 instead of DEFAULT_FACE_ID.
6101 The face returned is suitable for displaying ASCII characters. */
6104 face_at_buffer_position (w
, pos
, region_beg
, region_end
,
6105 endptr
, limit
, mouse
, base_face_id
)
6108 EMACS_INT region_beg
, region_end
;
6114 struct frame
*f
= XFRAME (w
->frame
);
6115 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6116 Lisp_Object prop
, position
;
6118 Lisp_Object
*overlay_vec
;
6121 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
6122 Lisp_Object limit1
, end
;
6123 struct face
*default_face
;
6125 /* W must display the current buffer. We could write this function
6126 to use the frame and buffer of W, but right now it doesn't. */
6127 /* xassert (XBUFFER (w->buffer) == current_buffer); */
6129 XSETFRAME (frame
, f
);
6130 XSETFASTINT (position
, pos
);
6133 if (pos
< region_beg
&& region_beg
< endpos
)
6134 endpos
= region_beg
;
6136 /* Get the `face' or `mouse_face' text property at POS, and
6137 determine the next position at which the property changes. */
6138 prop
= Fget_text_property (position
, propname
, w
->buffer
);
6139 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6140 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
6142 endpos
= XINT (end
);
6144 /* Look at properties from overlays. */
6146 EMACS_INT next_overlay
;
6148 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, &next_overlay
, 0);
6149 if (next_overlay
< endpos
)
6150 endpos
= next_overlay
;
6155 default_face
= FACE_FROM_ID (f
, base_face_id
>= 0 ? base_face_id
6156 : NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
6157 : lookup_basic_face (f
, DEFAULT_FACE_ID
));
6159 /* Optimize common cases where we can use the default face. */
6162 && !(pos
>= region_beg
&& pos
< region_end
))
6163 return default_face
->id
;
6165 /* Begin with attributes from the default face. */
6166 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6168 /* Merge in attributes specified via text properties. */
6170 merge_face_ref (f
, prop
, attrs
, 1, 0);
6172 /* Now merge the overlay data. */
6173 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6174 for (i
= 0; i
< noverlays
; i
++)
6179 prop
= Foverlay_get (overlay_vec
[i
], propname
);
6181 merge_face_ref (f
, prop
, attrs
, 1, 0);
6183 oend
= OVERLAY_END (overlay_vec
[i
]);
6184 oendpos
= OVERLAY_POSITION (oend
);
6185 if (oendpos
< endpos
)
6189 /* If in the region, merge in the region face. */
6190 if (pos
>= region_beg
&& pos
< region_end
)
6192 merge_named_face (f
, Qregion
, attrs
, 0);
6194 if (region_end
< endpos
)
6195 endpos
= region_end
;
6200 /* Look up a realized face with the given face attributes,
6201 or realize a new one for ASCII characters. */
6202 return lookup_face (f
, attrs
);
6205 /* Return the face ID at buffer position POS for displaying ASCII
6206 characters associated with overlay strings for overlay OVERLAY.
6208 Like face_at_buffer_position except for OVERLAY. Currently it
6209 simply disregards the `face' properties of all overlays. */
6212 face_for_overlay_string (w
, pos
, region_beg
, region_end
,
6213 endptr
, limit
, mouse
, overlay
)
6216 EMACS_INT region_beg
, region_end
;
6220 Lisp_Object overlay
;
6222 struct frame
*f
= XFRAME (w
->frame
);
6223 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6224 Lisp_Object prop
, position
;
6227 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
6228 Lisp_Object limit1
, end
;
6229 struct face
*default_face
;
6231 /* W must display the current buffer. We could write this function
6232 to use the frame and buffer of W, but right now it doesn't. */
6233 /* xassert (XBUFFER (w->buffer) == current_buffer); */
6235 XSETFRAME (frame
, f
);
6236 XSETFASTINT (position
, pos
);
6239 if (pos
< region_beg
&& region_beg
< endpos
)
6240 endpos
= region_beg
;
6242 /* Get the `face' or `mouse_face' text property at POS, and
6243 determine the next position at which the property changes. */
6244 prop
= Fget_text_property (position
, propname
, w
->buffer
);
6245 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6246 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
6248 endpos
= XINT (end
);
6252 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6254 /* Optimize common cases where we can use the default face. */
6256 && !(pos
>= region_beg
&& pos
< region_end
))
6257 return DEFAULT_FACE_ID
;
6259 /* Begin with attributes from the default face. */
6260 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6262 /* Merge in attributes specified via text properties. */
6264 merge_face_ref (f
, prop
, attrs
, 1, 0);
6266 /* If in the region, merge in the region face. */
6267 if (pos
>= region_beg
&& pos
< region_end
)
6269 merge_named_face (f
, Qregion
, attrs
, 0);
6271 if (region_end
< endpos
)
6272 endpos
= region_end
;
6277 /* Look up a realized face with the given face attributes,
6278 or realize a new one for ASCII characters. */
6279 return lookup_face (f
, attrs
);
6283 /* Compute the face at character position POS in Lisp string STRING on
6284 window W, for ASCII characters.
6286 If STRING is an overlay string, it comes from position BUFPOS in
6287 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
6288 not an overlay string. W must display the current buffer.
6289 REGION_BEG and REGION_END give the start and end positions of the
6290 region; both are -1 if no region is visible.
6292 BASE_FACE_ID is the id of a face to merge with. For strings coming
6293 from overlays or the `display' property it is the face at BUFPOS.
6295 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
6297 Set *ENDPTR to the next position where to check for faces in
6298 STRING; -1 if the face is constant from POS to the end of the
6301 Value is the id of the face to use. The face returned is suitable
6302 for displaying ASCII characters. */
6305 face_at_string_position (w
, string
, pos
, bufpos
, region_beg
,
6306 region_end
, endptr
, base_face_id
, mouse_p
)
6309 EMACS_INT pos
, bufpos
;
6310 EMACS_INT region_beg
, region_end
;
6312 enum face_id base_face_id
;
6315 Lisp_Object prop
, position
, end
, limit
;
6316 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6317 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6318 struct face
*base_face
;
6319 int multibyte_p
= STRING_MULTIBYTE (string
);
6320 Lisp_Object prop_name
= mouse_p
? Qmouse_face
: Qface
;
6322 /* Get the value of the face property at the current position within
6323 STRING. Value is nil if there is no face property. */
6324 XSETFASTINT (position
, pos
);
6325 prop
= Fget_text_property (position
, prop_name
, string
);
6327 /* Get the next position at which to check for faces. Value of end
6328 is nil if face is constant all the way to the end of the string.
6329 Otherwise it is a string position where to check faces next.
6330 Limit is the maximum position up to which to check for property
6331 changes in Fnext_single_property_change. Strings are usually
6332 short, so set the limit to the end of the string. */
6333 XSETFASTINT (limit
, SCHARS (string
));
6334 end
= Fnext_single_property_change (position
, prop_name
, string
, limit
);
6336 *endptr
= XFASTINT (end
);
6340 base_face
= FACE_FROM_ID (f
, base_face_id
);
6341 xassert (base_face
);
6343 /* Optimize the default case that there is no face property and we
6344 are not in the region. */
6346 && (base_face_id
!= DEFAULT_FACE_ID
6347 /* BUFPOS <= 0 means STRING is not an overlay string, so
6348 that the region doesn't have to be taken into account. */
6350 || bufpos
< region_beg
6351 || bufpos
>= region_end
)
6353 /* We can't realize faces for different charsets differently
6354 if we don't have fonts, so we can stop here if not working
6355 on a window-system frame. */
6356 || !FRAME_WINDOW_P (f
)
6357 || FACE_SUITABLE_FOR_CHAR_P (base_face
, 0)))
6358 return base_face
->id
;
6360 /* Begin with attributes from the base face. */
6361 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6363 /* Merge in attributes specified via text properties. */
6365 merge_face_ref (f
, prop
, attrs
, 1, 0);
6367 /* If in the region, merge in the region face. */
6369 && bufpos
>= region_beg
6370 && bufpos
< region_end
)
6371 merge_named_face (f
, Qregion
, attrs
, 0);
6373 /* Look up a realized face with the given face attributes,
6374 or realize a new one for ASCII characters. */
6375 return lookup_face (f
, attrs
);
6379 /* Merge a face into a realized face.
6381 F is frame where faces are (to be) realized.
6383 FACE_NAME is named face to merge.
6385 If FACE_NAME is nil, FACE_ID is face_id of realized face to merge.
6387 If FACE_NAME is t, FACE_ID is lface_id of face to merge.
6389 BASE_FACE_ID is realized face to merge into.
6395 merge_faces (struct frame
*f
, Lisp_Object face_name
, int face_id
, int base_face_id
)
6397 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6398 struct face
*base_face
;
6400 base_face
= FACE_FROM_ID (f
, base_face_id
);
6402 return base_face_id
;
6404 if (EQ (face_name
, Qt
))
6406 if (face_id
< 0 || face_id
>= lface_id_to_name_size
)
6407 return base_face_id
;
6408 face_name
= lface_id_to_name
[face_id
];
6409 /* When called during make-frame, lookup_derived_face may fail
6410 if the faces are uninitialized. Don't signal an error. */
6411 face_id
= lookup_derived_face (f
, face_name
, base_face_id
, 0);
6412 return (face_id
>= 0 ? face_id
: base_face_id
);
6415 /* Begin with attributes from the base face. */
6416 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6418 if (!NILP (face_name
))
6420 if (!merge_named_face (f
, face_name
, attrs
, 0))
6421 return base_face_id
;
6427 return base_face_id
;
6428 face
= FACE_FROM_ID (f
, face_id
);
6430 return base_face_id
;
6431 merge_face_vectors (f
, face
->lface
, attrs
, 0);
6434 /* Look up a realized face with the given face attributes,
6435 or realize a new one for ASCII characters. */
6436 return lookup_face (f
, attrs
);
6441 #ifndef HAVE_X_WINDOWS
6442 DEFUN ("x-load-color-file", Fx_load_color_file
,
6443 Sx_load_color_file
, 1, 1, 0,
6444 doc
: /* Create an alist of color entries from an external file.
6446 The file should define one named RGB color per line like so:
6448 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6450 Lisp_Object filename
;
6453 Lisp_Object cmap
= Qnil
;
6454 Lisp_Object abspath
;
6456 CHECK_STRING (filename
);
6457 abspath
= Fexpand_file_name (filename
, Qnil
);
6459 fp
= fopen (SDATA (filename
), "rt");
6463 int red
, green
, blue
;
6468 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
6469 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
6471 char *name
= buf
+ num
;
6472 num
= strlen (name
) - 1;
6473 if (num
>= 0 && name
[num
] == '\n')
6475 cmap
= Fcons (Fcons (build_string (name
),
6477 make_number (RGB (red
, green
, blue
))),
6479 make_number ((red
<< 16) | (green
<< 8) | blue
)),
6494 /***********************************************************************
6496 ***********************************************************************/
6500 /* Print the contents of the realized face FACE to stderr. */
6503 dump_realized_face (face
)
6506 fprintf (stderr
, "ID: %d\n", face
->id
);
6507 #ifdef HAVE_X_WINDOWS
6508 fprintf (stderr
, "gc: %ld\n", (long) face
->gc
);
6510 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
6512 SDATA (face
->lface
[LFACE_FOREGROUND_INDEX
]));
6513 fprintf (stderr
, "background: 0x%lx (%s)\n",
6515 SDATA (face
->lface
[LFACE_BACKGROUND_INDEX
]));
6517 fprintf (stderr
, "font_name: %s (%s)\n",
6518 SDATA (face
->font
->props
[FONT_NAME_INDEX
]),
6519 SDATA (face
->lface
[LFACE_FAMILY_INDEX
]));
6520 #ifdef HAVE_X_WINDOWS
6521 fprintf (stderr
, "font = %p\n", face
->font
);
6523 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
6524 fprintf (stderr
, "underline: %d (%s)\n",
6526 SDATA (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
])));
6527 fprintf (stderr
, "hash: %d\n", face
->hash
);
6531 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, doc
: /* */)
6539 fprintf (stderr
, "font selection order: ");
6540 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6541 fprintf (stderr
, "%d ", font_sort_order
[i
]);
6542 fprintf (stderr
, "\n");
6544 fprintf (stderr
, "alternative fonts: ");
6545 debug_print (Vface_alternative_font_family_alist
);
6546 fprintf (stderr
, "\n");
6548 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
6549 Fdump_face (make_number (i
));
6555 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
6557 error ("Not a valid face");
6558 dump_realized_face (face
);
6565 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
6566 0, 0, 0, doc
: /* */)
6569 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
6570 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
6571 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
6575 #endif /* GLYPH_DEBUG != 0 */
6579 /***********************************************************************
6581 ***********************************************************************/
6584 syms_of_xfaces (void)
6586 Qface
= intern_c_string ("face");
6588 Qface_no_inherit
= intern_c_string ("face-no-inherit");
6589 staticpro (&Qface_no_inherit
);
6590 Qbitmap_spec_p
= intern_c_string ("bitmap-spec-p");
6591 staticpro (&Qbitmap_spec_p
);
6592 Qframe_set_background_mode
= intern_c_string ("frame-set-background-mode");
6593 staticpro (&Qframe_set_background_mode
);
6595 /* Lisp face attribute keywords. */
6596 QCfamily
= intern_c_string (":family");
6597 staticpro (&QCfamily
);
6598 QCheight
= intern_c_string (":height");
6599 staticpro (&QCheight
);
6600 QCweight
= intern_c_string (":weight");
6601 staticpro (&QCweight
);
6602 QCslant
= intern_c_string (":slant");
6603 staticpro (&QCslant
);
6604 QCunderline
= intern_c_string (":underline");
6605 staticpro (&QCunderline
);
6606 QCinverse_video
= intern_c_string (":inverse-video");
6607 staticpro (&QCinverse_video
);
6608 QCreverse_video
= intern_c_string (":reverse-video");
6609 staticpro (&QCreverse_video
);
6610 QCforeground
= intern_c_string (":foreground");
6611 staticpro (&QCforeground
);
6612 QCbackground
= intern_c_string (":background");
6613 staticpro (&QCbackground
);
6614 QCstipple
= intern_c_string (":stipple");
6615 staticpro (&QCstipple
);
6616 QCwidth
= intern_c_string (":width");
6617 staticpro (&QCwidth
);
6618 QCfont
= intern_c_string (":font");
6619 staticpro (&QCfont
);
6620 QCfontset
= intern_c_string (":fontset");
6621 staticpro (&QCfontset
);
6622 QCbold
= intern_c_string (":bold");
6623 staticpro (&QCbold
);
6624 QCitalic
= intern_c_string (":italic");
6625 staticpro (&QCitalic
);
6626 QCoverline
= intern_c_string (":overline");
6627 staticpro (&QCoverline
);
6628 QCstrike_through
= intern_c_string (":strike-through");
6629 staticpro (&QCstrike_through
);
6630 QCbox
= intern_c_string (":box");
6632 QCinherit
= intern_c_string (":inherit");
6633 staticpro (&QCinherit
);
6635 /* Symbols used for Lisp face attribute values. */
6636 QCcolor
= intern_c_string (":color");
6637 staticpro (&QCcolor
);
6638 QCline_width
= intern_c_string (":line-width");
6639 staticpro (&QCline_width
);
6640 QCstyle
= intern_c_string (":style");
6641 staticpro (&QCstyle
);
6642 Qreleased_button
= intern_c_string ("released-button");
6643 staticpro (&Qreleased_button
);
6644 Qpressed_button
= intern_c_string ("pressed-button");
6645 staticpro (&Qpressed_button
);
6646 Qnormal
= intern_c_string ("normal");
6647 staticpro (&Qnormal
);
6648 Qultra_light
= intern_c_string ("ultra-light");
6649 staticpro (&Qultra_light
);
6650 Qextra_light
= intern_c_string ("extra-light");
6651 staticpro (&Qextra_light
);
6652 Qlight
= intern_c_string ("light");
6653 staticpro (&Qlight
);
6654 Qsemi_light
= intern_c_string ("semi-light");
6655 staticpro (&Qsemi_light
);
6656 Qsemi_bold
= intern_c_string ("semi-bold");
6657 staticpro (&Qsemi_bold
);
6658 Qbold
= intern_c_string ("bold");
6660 Qextra_bold
= intern_c_string ("extra-bold");
6661 staticpro (&Qextra_bold
);
6662 Qultra_bold
= intern_c_string ("ultra-bold");
6663 staticpro (&Qultra_bold
);
6664 Qoblique
= intern_c_string ("oblique");
6665 staticpro (&Qoblique
);
6666 Qitalic
= intern_c_string ("italic");
6667 staticpro (&Qitalic
);
6668 Qreverse_oblique
= intern_c_string ("reverse-oblique");
6669 staticpro (&Qreverse_oblique
);
6670 Qreverse_italic
= intern_c_string ("reverse-italic");
6671 staticpro (&Qreverse_italic
);
6672 Qultra_condensed
= intern_c_string ("ultra-condensed");
6673 staticpro (&Qultra_condensed
);
6674 Qextra_condensed
= intern_c_string ("extra-condensed");
6675 staticpro (&Qextra_condensed
);
6676 Qcondensed
= intern_c_string ("condensed");
6677 staticpro (&Qcondensed
);
6678 Qsemi_condensed
= intern_c_string ("semi-condensed");
6679 staticpro (&Qsemi_condensed
);
6680 Qsemi_expanded
= intern_c_string ("semi-expanded");
6681 staticpro (&Qsemi_expanded
);
6682 Qexpanded
= intern_c_string ("expanded");
6683 staticpro (&Qexpanded
);
6684 Qextra_expanded
= intern_c_string ("extra-expanded");
6685 staticpro (&Qextra_expanded
);
6686 Qultra_expanded
= intern_c_string ("ultra-expanded");
6687 staticpro (&Qultra_expanded
);
6688 Qbackground_color
= intern_c_string ("background-color");
6689 staticpro (&Qbackground_color
);
6690 Qforeground_color
= intern_c_string ("foreground-color");
6691 staticpro (&Qforeground_color
);
6692 Qunspecified
= intern_c_string ("unspecified");
6693 staticpro (&Qunspecified
);
6694 Qignore_defface
= intern_c_string (":ignore-defface");
6695 staticpro (&Qignore_defface
);
6697 Qface_alias
= intern_c_string ("face-alias");
6698 staticpro (&Qface_alias
);
6699 Qdefault
= intern_c_string ("default");
6700 staticpro (&Qdefault
);
6701 Qtool_bar
= intern_c_string ("tool-bar");
6702 staticpro (&Qtool_bar
);
6703 Qregion
= intern_c_string ("region");
6704 staticpro (&Qregion
);
6705 Qfringe
= intern_c_string ("fringe");
6706 staticpro (&Qfringe
);
6707 Qheader_line
= intern_c_string ("header-line");
6708 staticpro (&Qheader_line
);
6709 Qscroll_bar
= intern_c_string ("scroll-bar");
6710 staticpro (&Qscroll_bar
);
6711 Qmenu
= intern_c_string ("menu");
6713 Qcursor
= intern_c_string ("cursor");
6714 staticpro (&Qcursor
);
6715 Qborder
= intern_c_string ("border");
6716 staticpro (&Qborder
);
6717 Qmouse
= intern_c_string ("mouse");
6718 staticpro (&Qmouse
);
6719 Qmode_line_inactive
= intern_c_string ("mode-line-inactive");
6720 staticpro (&Qmode_line_inactive
);
6721 Qvertical_border
= intern_c_string ("vertical-border");
6722 staticpro (&Qvertical_border
);
6723 Qtty_color_desc
= intern_c_string ("tty-color-desc");
6724 staticpro (&Qtty_color_desc
);
6725 Qtty_color_standard_values
= intern_c_string ("tty-color-standard-values");
6726 staticpro (&Qtty_color_standard_values
);
6727 Qtty_color_by_index
= intern_c_string ("tty-color-by-index");
6728 staticpro (&Qtty_color_by_index
);
6729 Qtty_color_alist
= intern_c_string ("tty-color-alist");
6730 staticpro (&Qtty_color_alist
);
6731 Qscalable_fonts_allowed
= intern_c_string ("scalable-fonts-allowed");
6732 staticpro (&Qscalable_fonts_allowed
);
6734 Vparam_value_alist
= Fcons (Fcons (Qnil
, Qnil
), Qnil
);
6735 staticpro (&Vparam_value_alist
);
6736 Vface_alternative_font_family_alist
= Qnil
;
6737 staticpro (&Vface_alternative_font_family_alist
);
6738 Vface_alternative_font_registry_alist
= Qnil
;
6739 staticpro (&Vface_alternative_font_registry_alist
);
6741 defsubr (&Sinternal_make_lisp_face
);
6742 defsubr (&Sinternal_lisp_face_p
);
6743 defsubr (&Sinternal_set_lisp_face_attribute
);
6744 #ifdef HAVE_WINDOW_SYSTEM
6745 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
6747 defsubr (&Scolor_gray_p
);
6748 defsubr (&Scolor_supported_p
);
6749 #ifndef HAVE_X_WINDOWS
6750 defsubr (&Sx_load_color_file
);
6752 defsubr (&Sface_attribute_relative_p
);
6753 defsubr (&Smerge_face_attribute
);
6754 defsubr (&Sinternal_get_lisp_face_attribute
);
6755 defsubr (&Sinternal_lisp_face_attribute_values
);
6756 defsubr (&Sinternal_lisp_face_equal_p
);
6757 defsubr (&Sinternal_lisp_face_empty_p
);
6758 defsubr (&Sinternal_copy_lisp_face
);
6759 defsubr (&Sinternal_merge_in_global_face
);
6760 defsubr (&Sface_font
);
6761 defsubr (&Sframe_face_alist
);
6762 defsubr (&Sdisplay_supports_face_attributes_p
);
6763 defsubr (&Scolor_distance
);
6764 defsubr (&Sinternal_set_font_selection_order
);
6765 defsubr (&Sinternal_set_alternative_font_family_alist
);
6766 defsubr (&Sinternal_set_alternative_font_registry_alist
);
6767 defsubr (&Sface_attributes_as_vector
);
6769 defsubr (&Sdump_face
);
6770 defsubr (&Sshow_face_resources
);
6771 #endif /* GLYPH_DEBUG */
6772 defsubr (&Sclear_face_cache
);
6773 defsubr (&Stty_suppress_bold_inverse_default_colors
);
6775 #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS
6776 defsubr (&Sdump_colors
);
6779 DEFVAR_LISP ("font-list-limit", &Vfont_list_limit
,
6780 doc
: /* *Limit for font matching.
6781 If an integer > 0, font matching functions won't load more than
6782 that number of fonts when searching for a matching font. */);
6783 Vfont_list_limit
= make_number (DEFAULT_FONT_LIST_LIMIT
);
6785 DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults
,
6786 doc
: /* List of global face definitions (for internal use only.) */);
6787 Vface_new_frame_defaults
= Qnil
;
6789 DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple
,
6790 doc
: /* *Default stipple pattern used on monochrome displays.
6791 This stipple pattern is used on monochrome displays
6792 instead of shades of gray for a face background color.
6793 See `set-face-stipple' for possible values for this variable. */);
6794 Vface_default_stipple
= make_pure_c_string ("gray3");
6796 DEFVAR_LISP ("tty-defined-color-alist", &Vtty_defined_color_alist
,
6797 doc
: /* An alist of defined terminal colors and their RGB values. */);
6798 Vtty_defined_color_alist
= Qnil
;
6800 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed
,
6801 doc
: /* Allowed scalable fonts.
6802 A value of nil means don't allow any scalable fonts.
6803 A value of t means allow any scalable font.
6804 Otherwise, value must be a list of regular expressions. A font may be
6805 scaled if its name matches a regular expression in the list.
6806 Note that if value is nil, a scalable font might still be used, if no
6807 other font of the appropriate family and registry is available. */);
6808 Vscalable_fonts_allowed
= Qnil
;
6810 DEFVAR_LISP ("face-ignored-fonts", &Vface_ignored_fonts
,
6811 doc
: /* List of ignored fonts.
6812 Each element is a regular expression that matches names of fonts to
6814 Vface_ignored_fonts
= Qnil
;
6816 DEFVAR_LISP ("face-remapping-alist", &Vface_remapping_alist
,
6817 doc
: /* Alist of face remappings.
6818 Each element is of the form:
6820 (FACE REPLACEMENT...),
6822 which causes display of the face FACE to use REPLACEMENT... instead.
6823 REPLACEMENT... is interpreted the same way the value of a `face' text
6824 property is: it may be (1) A face name, (2) A list of face names, (3) A
6825 property-list of face attribute/value pairs, or (4) A list of face names
6826 intermixed with lists containing face attribute/value pairs.
6828 Multiple entries in REPLACEMENT... are merged together to form the final
6829 result, with faces or attributes earlier in the list taking precedence
6830 over those that are later.
6832 Face-name remapping cycles are suppressed; recursive references use the
6833 underlying face instead of the remapped face. So a remapping of the form:
6835 (FACE EXTRA-FACE... FACE)
6839 (FACE (FACE-ATTR VAL ...) FACE)
6841 will cause EXTRA-FACE... or (FACE-ATTR VAL ...) to be _merged_ with the
6842 existing definition of FACE. Note that for the default face, this isn't
6843 necessary, as every face inherits from the default face.
6845 Making this variable buffer-local is a good way to allow buffer-specific
6846 face definitions. For instance, the mode my-mode could define a face
6847 `my-mode-default', and then in the mode setup function, do:
6849 (set (make-local-variable 'face-remapping-alist)
6850 '((default my-mode-default)))). */);
6851 Vface_remapping_alist
= Qnil
;
6853 DEFVAR_LISP ("face-font-rescale-alist", &Vface_font_rescale_alist
,
6854 doc
: /* Alist of fonts vs the rescaling factors.
6855 Each element is a cons (FONT-PATTERN . RESCALE-RATIO), where
6856 FONT-PATTERN is a font-spec or a regular expression matching a font name, and
6857 RESCALE-RATIO is a floating point number to specify how much larger
6858 \(or smaller) font we should use. For instance, if a face requests
6859 a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point. */);
6860 Vface_font_rescale_alist
= Qnil
;
6862 #ifdef HAVE_WINDOW_SYSTEM
6863 defsubr (&Sbitmap_spec_p
);
6864 defsubr (&Sx_list_fonts
);
6865 defsubr (&Sinternal_face_x_get_resource
);
6866 defsubr (&Sx_family_fonts
);
6870 /* arch-tag: 8a0f7598-5517-408d-9ab3-1da6fcd4c749
6871 (do not change this comment) */