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. */)
954 (Lisp_Object thoroughly
)
956 clear_face_cache (!NILP (thoroughly
));
958 ++windows_or_buffers_changed
;
963 /***********************************************************************
965 ***********************************************************************/
967 #ifdef HAVE_WINDOW_SYSTEM
969 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
970 doc
: /* Value is non-nil if OBJECT is a valid bitmap specification.
971 A bitmap specification is either a string, a file name, or a list
972 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
973 HEIGHT is its height, and DATA is a string containing the bits of
974 the pixmap. Bits are stored row by row, each row occupies
975 \(WIDTH + 7)/8 bytes. */)
980 if (STRINGP (object
))
981 /* If OBJECT is a string, it's a file name. */
983 else if (CONSP (object
))
985 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
986 HEIGHT must be integers > 0, and DATA must be string large
987 enough to hold a bitmap of the specified size. */
988 Lisp_Object width
, height
, data
;
990 height
= width
= data
= Qnil
;
994 width
= XCAR (object
);
995 object
= XCDR (object
);
998 height
= XCAR (object
);
999 object
= XCDR (object
);
1001 data
= XCAR (object
);
1005 if (NATNUMP (width
) && NATNUMP (height
) && STRINGP (data
))
1007 int bytes_per_row
= ((XFASTINT (width
) + BITS_PER_CHAR
- 1)
1009 if (SBYTES (data
) >= bytes_per_row
* XINT (height
))
1014 return pixmap_p
? Qt
: Qnil
;
1018 /* Load a bitmap according to NAME (which is either a file name or a
1019 pixmap spec) for use on frame F. Value is the bitmap_id (see
1020 xfns.c). If NAME is nil, return with a bitmap id of zero. If
1021 bitmap cannot be loaded, display a message saying so, and return
1022 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
1023 if these pointers are not null. */
1026 load_pixmap (FRAME_PTR f
, Lisp_Object name
, unsigned int *w_ptr
, unsigned int *h_ptr
)
1033 CHECK_TYPE (!NILP (Fbitmap_spec_p (name
)), Qbitmap_spec_p
, name
);
1038 /* Decode a bitmap spec into a bitmap. */
1043 w
= XINT (Fcar (name
));
1044 h
= XINT (Fcar (Fcdr (name
)));
1045 bits
= Fcar (Fcdr (Fcdr (name
)));
1047 bitmap_id
= x_create_bitmap_from_data (f
, SDATA (bits
),
1052 /* It must be a string -- a file name. */
1053 bitmap_id
= x_create_bitmap_from_file (f
, name
);
1059 add_to_log ("Invalid or undefined bitmap `%s'", name
, Qnil
);
1070 ++npixmaps_allocated
;
1073 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
1076 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
1082 #endif /* HAVE_WINDOW_SYSTEM */
1086 /***********************************************************************
1088 ***********************************************************************/
1090 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
1091 RGB_LIST should contain (at least) 3 lisp integers.
1092 Return 0 if there's a problem with RGB_LIST, otherwise return 1. */
1095 parse_rgb_list (Lisp_Object rgb_list
, XColor
*color
)
1097 #define PARSE_RGB_LIST_FIELD(field) \
1098 if (CONSP (rgb_list) && INTEGERP (XCAR (rgb_list))) \
1100 color->field = XINT (XCAR (rgb_list)); \
1101 rgb_list = XCDR (rgb_list); \
1106 PARSE_RGB_LIST_FIELD (red
);
1107 PARSE_RGB_LIST_FIELD (green
);
1108 PARSE_RGB_LIST_FIELD (blue
);
1114 /* Lookup on frame F the color described by the lisp string COLOR.
1115 The resulting tty color is returned in TTY_COLOR; if STD_COLOR is
1116 non-zero, then the `standard' definition of the same color is
1120 tty_lookup_color (struct frame
*f
, Lisp_Object color
, XColor
*tty_color
, XColor
*std_color
)
1122 Lisp_Object frame
, color_desc
;
1124 if (!STRINGP (color
) || NILP (Ffboundp (Qtty_color_desc
)))
1127 XSETFRAME (frame
, f
);
1129 color_desc
= call2 (Qtty_color_desc
, color
, frame
);
1130 if (CONSP (color_desc
) && CONSP (XCDR (color_desc
)))
1134 if (! INTEGERP (XCAR (XCDR (color_desc
))))
1137 tty_color
->pixel
= XINT (XCAR (XCDR (color_desc
)));
1139 rgb
= XCDR (XCDR (color_desc
));
1140 if (! parse_rgb_list (rgb
, tty_color
))
1143 /* Should we fill in STD_COLOR too? */
1146 /* Default STD_COLOR to the same as TTY_COLOR. */
1147 *std_color
= *tty_color
;
1149 /* Do a quick check to see if the returned descriptor is
1150 actually _exactly_ equal to COLOR, otherwise we have to
1151 lookup STD_COLOR separately. If it's impossible to lookup
1152 a standard color, we just give up and use TTY_COLOR. */
1153 if ((!STRINGP (XCAR (color_desc
))
1154 || NILP (Fstring_equal (color
, XCAR (color_desc
))))
1155 && !NILP (Ffboundp (Qtty_color_standard_values
)))
1157 /* Look up STD_COLOR separately. */
1158 rgb
= call1 (Qtty_color_standard_values
, color
);
1159 if (! parse_rgb_list (rgb
, std_color
))
1166 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
1167 /* We were called early during startup, and the colors are not
1168 yet set up in tty-defined-color-alist. Don't return a failure
1169 indication, since this produces the annoying "Unable to
1170 load color" messages in the *Messages* buffer. */
1173 /* tty-color-desc seems to have returned a bad value. */
1177 /* A version of defined_color for non-X frames. */
1180 tty_defined_color (struct frame
*f
, char *color_name
, XColor
*color_def
, int alloc
)
1185 color_def
->pixel
= FACE_TTY_DEFAULT_COLOR
;
1187 color_def
->blue
= 0;
1188 color_def
->green
= 0;
1191 status
= tty_lookup_color (f
, build_string (color_name
), color_def
, NULL
);
1193 if (color_def
->pixel
== FACE_TTY_DEFAULT_COLOR
&& *color_name
)
1195 if (strcmp (color_name
, "unspecified-fg") == 0)
1196 color_def
->pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
1197 else if (strcmp (color_name
, "unspecified-bg") == 0)
1198 color_def
->pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
1201 if (color_def
->pixel
!= FACE_TTY_DEFAULT_COLOR
)
1208 /* Decide if color named COLOR_NAME is valid for the display
1209 associated with the frame F; if so, return the rgb values in
1210 COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell.
1212 This does the right thing for any type of frame. */
1215 defined_color (struct frame
*f
, char *color_name
, XColor
*color_def
, int alloc
)
1217 if (!FRAME_WINDOW_P (f
))
1218 return tty_defined_color (f
, color_name
, color_def
, alloc
);
1219 #ifdef HAVE_X_WINDOWS
1220 else if (FRAME_X_P (f
))
1221 return x_defined_color (f
, color_name
, color_def
, alloc
);
1224 else if (FRAME_W32_P (f
))
1225 return w32_defined_color (f
, color_name
, color_def
, alloc
);
1228 else if (FRAME_NS_P (f
))
1229 return ns_defined_color (f
, color_name
, color_def
, alloc
, 1);
1236 /* Given the index IDX of a tty color on frame F, return its name, a
1240 tty_color_name (struct frame
*f
, int idx
)
1242 if (idx
>= 0 && !NILP (Ffboundp (Qtty_color_by_index
)))
1245 Lisp_Object coldesc
;
1247 XSETFRAME (frame
, f
);
1248 coldesc
= call2 (Qtty_color_by_index
, make_number (idx
), frame
);
1250 if (!NILP (coldesc
))
1251 return XCAR (coldesc
);
1254 /* We can have an MSDOG frame under -nw for a short window of
1255 opportunity before internal_terminal_init is called. DTRT. */
1256 if (FRAME_MSDOS_P (f
) && !inhibit_window_system
)
1257 return msdos_stdcolor_name (idx
);
1260 if (idx
== FACE_TTY_DEFAULT_FG_COLOR
)
1261 return build_string (unspecified_fg
);
1262 if (idx
== FACE_TTY_DEFAULT_BG_COLOR
)
1263 return build_string (unspecified_bg
);
1265 return Qunspecified
;
1269 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1272 The criterion implemented here is not a terribly sophisticated one. */
1275 face_color_gray_p (struct frame
*f
, char *color_name
)
1280 if (defined_color (f
, color_name
, &color
, 0))
1281 gray_p
= (/* Any color sufficiently close to black counts as grey. */
1282 (color
.red
< 5000 && color
.green
< 5000 && color
.blue
< 5000)
1284 ((eabs (color
.red
- color
.green
)
1285 < max (color
.red
, color
.green
) / 20)
1286 && (eabs (color
.green
- color
.blue
)
1287 < max (color
.green
, color
.blue
) / 20)
1288 && (eabs (color
.blue
- color
.red
)
1289 < max (color
.blue
, color
.red
) / 20)));
1297 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1298 BACKGROUND_P non-zero means the color will be used as background
1302 face_color_supported_p (struct frame
*f
, char *color_name
, int background_p
)
1307 XSETFRAME (frame
, f
);
1309 #ifdef HAVE_WINDOW_SYSTEM
1311 ? (!NILP (Fxw_display_color_p (frame
))
1312 || xstrcasecmp (color_name
, "black") == 0
1313 || xstrcasecmp (color_name
, "white") == 0
1315 && face_color_gray_p (f
, color_name
))
1316 || (!NILP (Fx_display_grayscale_p (frame
))
1317 && face_color_gray_p (f
, color_name
)))
1320 tty_defined_color (f
, color_name
, ¬_used
, 0);
1324 DEFUN ("color-gray-p", Fcolor_gray_p
, Scolor_gray_p
, 1, 2, 0,
1325 doc
: /* Return non-nil if COLOR is a shade of gray (or white or black).
1326 FRAME specifies the frame and thus the display for interpreting COLOR.
1327 If FRAME is nil or omitted, use the selected frame. */)
1328 (Lisp_Object color
, Lisp_Object frame
)
1332 CHECK_STRING (color
);
1334 frame
= selected_frame
;
1336 CHECK_FRAME (frame
);
1338 return face_color_gray_p (f
, SDATA (color
)) ? Qt
: Qnil
;
1342 DEFUN ("color-supported-p", Fcolor_supported_p
,
1343 Scolor_supported_p
, 1, 3, 0,
1344 doc
: /* Return non-nil if COLOR can be displayed on FRAME.
1345 BACKGROUND-P non-nil means COLOR is used as a background.
1346 Otherwise, this function tells whether it can be used as a foreground.
1347 If FRAME is nil or omitted, use the selected frame.
1348 COLOR must be a valid color name. */)
1349 (Lisp_Object color
, Lisp_Object frame
, Lisp_Object background_p
)
1353 CHECK_STRING (color
);
1355 frame
= selected_frame
;
1357 CHECK_FRAME (frame
);
1359 if (face_color_supported_p (f
, SDATA (color
), !NILP (background_p
)))
1365 /* Load color with name NAME for use by face FACE on frame F.
1366 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1367 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1368 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1369 pixel color. If color cannot be loaded, display a message, and
1370 return the foreground, background or underline color of F, but
1371 record that fact in flags of the face so that we don't try to free
1375 load_color (struct frame
*f
, struct face
*face
, Lisp_Object name
, enum lface_attribute_index target_index
)
1379 xassert (STRINGP (name
));
1380 xassert (target_index
== LFACE_FOREGROUND_INDEX
1381 || target_index
== LFACE_BACKGROUND_INDEX
1382 || target_index
== LFACE_UNDERLINE_INDEX
1383 || target_index
== LFACE_OVERLINE_INDEX
1384 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1385 || target_index
== LFACE_BOX_INDEX
);
1387 /* if the color map is full, defined_color will return a best match
1388 to the values in an existing cell. */
1389 if (!defined_color (f
, SDATA (name
), &color
, 1))
1391 add_to_log ("Unable to load color \"%s\"", name
, Qnil
);
1393 switch (target_index
)
1395 case LFACE_FOREGROUND_INDEX
:
1396 face
->foreground_defaulted_p
= 1;
1397 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1400 case LFACE_BACKGROUND_INDEX
:
1401 face
->background_defaulted_p
= 1;
1402 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1405 case LFACE_UNDERLINE_INDEX
:
1406 face
->underline_defaulted_p
= 1;
1407 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1410 case LFACE_OVERLINE_INDEX
:
1411 face
->overline_color_defaulted_p
= 1;
1412 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1415 case LFACE_STRIKE_THROUGH_INDEX
:
1416 face
->strike_through_color_defaulted_p
= 1;
1417 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1420 case LFACE_BOX_INDEX
:
1421 face
->box_color_defaulted_p
= 1;
1422 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1431 ++ncolors_allocated
;
1438 #ifdef HAVE_WINDOW_SYSTEM
1440 /* Load colors for face FACE which is used on frame F. Colors are
1441 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1442 of ATTRS. If the background color specified is not supported on F,
1443 try to emulate gray colors with a stipple from Vface_default_stipple. */
1446 load_face_colors (struct frame
*f
, struct face
*face
, Lisp_Object
*attrs
)
1450 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1451 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1453 /* Swap colors if face is inverse-video. */
1454 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1462 /* Check for support for foreground, not for background because
1463 face_color_supported_p is smart enough to know that grays are
1464 "supported" as background because we are supposed to use stipple
1466 if (!face_color_supported_p (f
, SDATA (bg
), 0)
1467 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1469 x_destroy_bitmap (f
, face
->stipple
);
1470 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1471 &face
->pixmap_w
, &face
->pixmap_h
);
1474 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1475 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1479 /* Free color PIXEL on frame F. */
1482 unload_color (struct frame
*f
, long unsigned int pixel
)
1484 #ifdef HAVE_X_WINDOWS
1488 x_free_colors (f
, &pixel
, 1);
1495 /* Free colors allocated for FACE. */
1498 free_face_colors (struct frame
*f
, struct face
*face
)
1500 /* PENDING(NS): need to do something here? */
1501 #ifdef HAVE_X_WINDOWS
1502 if (face
->colors_copied_bitwise_p
)
1507 if (!face
->foreground_defaulted_p
)
1509 x_free_colors (f
, &face
->foreground
, 1);
1510 IF_DEBUG (--ncolors_allocated
);
1513 if (!face
->background_defaulted_p
)
1515 x_free_colors (f
, &face
->background
, 1);
1516 IF_DEBUG (--ncolors_allocated
);
1519 if (face
->underline_p
1520 && !face
->underline_defaulted_p
)
1522 x_free_colors (f
, &face
->underline_color
, 1);
1523 IF_DEBUG (--ncolors_allocated
);
1526 if (face
->overline_p
1527 && !face
->overline_color_defaulted_p
)
1529 x_free_colors (f
, &face
->overline_color
, 1);
1530 IF_DEBUG (--ncolors_allocated
);
1533 if (face
->strike_through_p
1534 && !face
->strike_through_color_defaulted_p
)
1536 x_free_colors (f
, &face
->strike_through_color
, 1);
1537 IF_DEBUG (--ncolors_allocated
);
1540 if (face
->box
!= FACE_NO_BOX
1541 && !face
->box_color_defaulted_p
)
1543 x_free_colors (f
, &face
->box_color
, 1);
1544 IF_DEBUG (--ncolors_allocated
);
1548 #endif /* HAVE_X_WINDOWS */
1551 #endif /* HAVE_WINDOW_SYSTEM */
1555 /***********************************************************************
1557 ***********************************************************************/
1559 /* An enumerator for each field of an XLFD font name. */
1580 /* An enumerator for each possible slant value of a font. Taken from
1581 the XLFD specification. */
1589 XLFD_SLANT_REVERSE_ITALIC
,
1590 XLFD_SLANT_REVERSE_OBLIQUE
,
1594 /* Relative font weight according to XLFD documentation. */
1598 XLFD_WEIGHT_UNKNOWN
,
1599 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1600 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1601 XLFD_WEIGHT_LIGHT
, /* 30 */
1602 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1603 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1604 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1605 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1606 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1607 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1610 /* Relative proportionate width. */
1614 XLFD_SWIDTH_UNKNOWN
,
1615 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1616 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1617 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1618 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1619 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1620 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1621 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1622 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1623 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1626 /* Order by which font selection chooses fonts. The default values
1627 mean `first, find a best match for the font width, then for the
1628 font height, then for weight, then for slant.' This variable can be
1629 set via set-face-font-sort-order. */
1631 static int font_sort_order
[4];
1633 #ifdef HAVE_WINDOW_SYSTEM
1635 static enum font_property_index font_props_for_sorting
[FONT_SIZE_INDEX
];
1638 compare_fonts_by_sort_order (const void *v1
, const void *v2
)
1640 Lisp_Object font1
= *(Lisp_Object
*) v1
;
1641 Lisp_Object font2
= *(Lisp_Object
*) v2
;
1644 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1646 enum font_property_index idx
= font_props_for_sorting
[i
];
1647 Lisp_Object val1
= AREF (font1
, idx
), val2
= AREF (font2
, idx
);
1650 if (idx
<= FONT_REGISTRY_INDEX
)
1653 result
= STRINGP (val2
) ? strcmp (SDATA (val1
), SDATA (val2
)) : -1;
1655 result
= STRINGP (val2
) ? 1 : 0;
1659 if (INTEGERP (val1
))
1660 result
= INTEGERP (val2
) ? XINT (val1
) - XINT (val2
) : -1;
1662 result
= INTEGERP (val2
) ? 1 : 0;
1670 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
1671 doc
: /* Return a list of available fonts of family FAMILY on FRAME.
1672 If FAMILY is omitted or nil, list all families.
1673 Otherwise, FAMILY must be a string, possibly containing wildcards
1675 If FRAME is omitted or nil, use the selected frame.
1676 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
1677 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
1678 FAMILY is the font family name. POINT-SIZE is the size of the
1679 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
1680 width, weight and slant of the font. These symbols are the same as for
1681 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
1682 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
1683 giving the registry and encoding of the font.
1684 The result list is sorted according to the current setting of
1685 the face font sort order. */)
1686 (Lisp_Object family
, Lisp_Object frame
)
1688 Lisp_Object font_spec
, list
, *drivers
, vec
;
1689 int i
, nfonts
, ndrivers
;
1693 frame
= selected_frame
;
1694 CHECK_LIVE_FRAME (frame
);
1696 font_spec
= Ffont_spec (0, NULL
);
1699 CHECK_STRING (family
);
1700 font_parse_family_registry (family
, Qnil
, font_spec
);
1703 list
= font_list_entities (frame
, font_spec
);
1707 /* Sort the font entities. */
1708 for (i
= 0; i
< 4; i
++)
1709 switch (font_sort_order
[i
])
1712 font_props_for_sorting
[i
] = FONT_WIDTH_INDEX
; break;
1713 case XLFD_POINT_SIZE
:
1714 font_props_for_sorting
[i
] = FONT_SIZE_INDEX
; break;
1716 font_props_for_sorting
[i
] = FONT_WEIGHT_INDEX
; break;
1718 font_props_for_sorting
[i
] = FONT_SLANT_INDEX
; break;
1720 font_props_for_sorting
[i
++] = FONT_FAMILY_INDEX
;
1721 font_props_for_sorting
[i
++] = FONT_FOUNDRY_INDEX
;
1722 font_props_for_sorting
[i
++] = FONT_ADSTYLE_INDEX
;
1723 font_props_for_sorting
[i
++] = FONT_REGISTRY_INDEX
;
1725 ndrivers
= XINT (Flength (list
));
1726 drivers
= alloca (sizeof (Lisp_Object
) * ndrivers
);
1727 for (i
= 0; i
< ndrivers
; i
++, list
= XCDR (list
))
1728 drivers
[i
] = XCAR (list
);
1729 vec
= Fvconcat (ndrivers
, drivers
);
1730 nfonts
= ASIZE (vec
);
1732 qsort (XVECTOR (vec
)->contents
, nfonts
, sizeof (Lisp_Object
),
1733 compare_fonts_by_sort_order
);
1736 for (i
= nfonts
- 1; i
>= 0; --i
)
1738 Lisp_Object font
= AREF (vec
, i
);
1739 Lisp_Object v
= Fmake_vector (make_number (8), Qnil
);
1741 Lisp_Object spacing
;
1743 ASET (v
, 0, AREF (font
, FONT_FAMILY_INDEX
));
1744 ASET (v
, 1, FONT_WIDTH_SYMBOLIC (font
));
1745 point
= PIXEL_TO_POINT (XINT (AREF (font
, FONT_SIZE_INDEX
)) * 10,
1746 XFRAME (frame
)->resy
);
1747 ASET (v
, 2, make_number (point
));
1748 ASET (v
, 3, FONT_WEIGHT_SYMBOLIC (font
));
1749 ASET (v
, 4, FONT_SLANT_SYMBOLIC (font
));
1750 spacing
= Ffont_get (font
, QCspacing
);
1751 ASET (v
, 5, (NILP (spacing
) || EQ (spacing
, Qp
)) ? Qnil
: Qt
);
1752 ASET (v
, 6, Ffont_xlfd_name (font
, Qnil
));
1753 ASET (v
, 7, AREF (font
, FONT_REGISTRY_INDEX
));
1755 result
= Fcons (v
, result
);
1761 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
1762 doc
: /* Return a list of the names of available fonts matching PATTERN.
1763 If optional arguments FACE and FRAME are specified, return only fonts
1764 the same size as FACE on FRAME.
1766 PATTERN should be a string containing a font name in the XLFD,
1767 Fontconfig, or GTK format. A font name given in the XLFD format may
1768 contain wildcard characters:
1769 the * character matches any substring, and
1770 the ? character matches any single character.
1771 PATTERN is case-insensitive.
1773 The return value is a list of strings, suitable as arguments to
1776 Fonts Emacs can't use may or may not be excluded
1777 even if they match PATTERN and FACE.
1778 The optional fourth argument MAXIMUM sets a limit on how many
1779 fonts to match. The first MAXIMUM fonts are reported.
1780 The optional fifth argument WIDTH, if specified, is a number of columns
1781 occupied by a character of a font. In that case, return only fonts
1782 the WIDTH times as wide as FACE on FRAME. */)
1783 (Lisp_Object pattern
, Lisp_Object face
, Lisp_Object frame
, Lisp_Object maximum
, Lisp_Object width
)
1789 CHECK_STRING (pattern
);
1791 if (! NILP (maximum
))
1792 CHECK_NATNUM (maximum
);
1795 CHECK_NUMBER (width
);
1797 /* We can't simply call check_x_frame because this function may be
1798 called before any frame is created. */
1800 frame
= selected_frame
;
1801 f
= frame_or_selected_frame (frame
, 2);
1802 if (! FRAME_WINDOW_P (f
))
1804 /* Perhaps we have not yet created any frame. */
1810 /* Determine the width standard for comparison with the fonts we find. */
1816 /* This is of limited utility since it works with character
1817 widths. Keep it for compatibility. --gerd. */
1818 int face_id
= lookup_named_face (f
, face
, 0);
1819 struct face
*face
= (face_id
< 0
1821 : FACE_FROM_ID (f
, face_id
));
1823 if (face
&& face
->font
)
1825 size
= face
->font
->pixel_size
;
1826 avgwidth
= face
->font
->average_width
;
1830 size
= FRAME_FONT (f
)->pixel_size
;
1831 avgwidth
= FRAME_FONT (f
)->average_width
;
1834 avgwidth
*= XINT (width
);
1838 Lisp_Object font_spec
;
1839 Lisp_Object args
[2], tail
;
1841 font_spec
= font_spec_from_name (pattern
);
1842 if (!FONTP (font_spec
))
1843 signal_error ("Invalid font name", pattern
);
1847 Ffont_put (font_spec
, QCsize
, make_number (size
));
1848 Ffont_put (font_spec
, QCavgwidth
, make_number (avgwidth
));
1850 args
[0] = Flist_fonts (font_spec
, frame
, maximum
, font_spec
);
1851 for (tail
= args
[0]; CONSP (tail
); tail
= XCDR (tail
))
1853 Lisp_Object font_entity
;
1855 font_entity
= XCAR (tail
);
1856 if ((NILP (AREF (font_entity
, FONT_SIZE_INDEX
))
1857 || XINT (AREF (font_entity
, FONT_SIZE_INDEX
)) == 0)
1858 && ! NILP (AREF (font_spec
, FONT_SIZE_INDEX
)))
1860 /* This is a scalable font. For backward compatibility,
1861 we set the specified size. */
1862 font_entity
= Fcopy_font_spec (font_entity
);
1863 ASET (font_entity
, FONT_SIZE_INDEX
,
1864 AREF (font_spec
, FONT_SIZE_INDEX
));
1866 XSETCAR (tail
, Ffont_xlfd_name (font_entity
, Qnil
));
1869 /* We don't have to check fontsets. */
1871 args
[1] = list_fontsets (f
, pattern
, size
);
1872 return Fnconc (2, args
);
1876 #endif /* HAVE_WINDOW_SYSTEM */
1879 /***********************************************************************
1881 ***********************************************************************/
1883 /* Access face attributes of face LFACE, a Lisp vector. */
1885 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
1886 #define LFACE_FOUNDRY(LFACE) AREF ((LFACE), LFACE_FOUNDRY_INDEX)
1887 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
1888 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
1889 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
1890 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
1891 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
1892 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
1893 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
1894 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
1895 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
1896 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
1897 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
1898 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
1899 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
1900 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
1901 #define LFACE_FONTSET(LFACE) AREF ((LFACE), LFACE_FONTSET_INDEX)
1903 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
1904 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
1906 #define LFACEP(LFACE) \
1908 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \
1909 && EQ (AREF (LFACE, 0), Qface))
1914 /* Check consistency of Lisp face attribute vector ATTRS. */
1917 check_lface_attrs (attrs
)
1920 xassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
1921 || IGNORE_DEFFACE_P (attrs
[LFACE_FAMILY_INDEX
])
1922 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
1923 xassert (UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
1924 || IGNORE_DEFFACE_P (attrs
[LFACE_FOUNDRY_INDEX
])
1925 || STRINGP (attrs
[LFACE_FOUNDRY_INDEX
]));
1926 xassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
1927 || IGNORE_DEFFACE_P (attrs
[LFACE_SWIDTH_INDEX
])
1928 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
1929 xassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
1930 || IGNORE_DEFFACE_P (attrs
[LFACE_HEIGHT_INDEX
])
1931 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
])
1932 || FLOATP (attrs
[LFACE_HEIGHT_INDEX
])
1933 || FUNCTIONP (attrs
[LFACE_HEIGHT_INDEX
]));
1934 xassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
1935 || IGNORE_DEFFACE_P (attrs
[LFACE_WEIGHT_INDEX
])
1936 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
1937 xassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
1938 || IGNORE_DEFFACE_P (attrs
[LFACE_SLANT_INDEX
])
1939 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
1940 xassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
1941 || IGNORE_DEFFACE_P (attrs
[LFACE_UNDERLINE_INDEX
])
1942 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
1943 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]));
1944 xassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
1945 || IGNORE_DEFFACE_P (attrs
[LFACE_OVERLINE_INDEX
])
1946 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
1947 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
1948 xassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1949 || IGNORE_DEFFACE_P (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1950 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
1951 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
1952 xassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
1953 || IGNORE_DEFFACE_P (attrs
[LFACE_BOX_INDEX
])
1954 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
1955 || STRINGP (attrs
[LFACE_BOX_INDEX
])
1956 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
1957 || CONSP (attrs
[LFACE_BOX_INDEX
]));
1958 xassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
1959 || IGNORE_DEFFACE_P (attrs
[LFACE_INVERSE_INDEX
])
1960 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
1961 xassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
1962 || IGNORE_DEFFACE_P (attrs
[LFACE_FOREGROUND_INDEX
])
1963 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
1964 xassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
1965 || IGNORE_DEFFACE_P (attrs
[LFACE_BACKGROUND_INDEX
])
1966 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
1967 xassert (UNSPECIFIEDP (attrs
[LFACE_INHERIT_INDEX
])
1968 || IGNORE_DEFFACE_P (attrs
[LFACE_INHERIT_INDEX
])
1969 || NILP (attrs
[LFACE_INHERIT_INDEX
])
1970 || SYMBOLP (attrs
[LFACE_INHERIT_INDEX
])
1971 || CONSP (attrs
[LFACE_INHERIT_INDEX
]));
1972 #ifdef HAVE_WINDOW_SYSTEM
1973 xassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
1974 || IGNORE_DEFFACE_P (attrs
[LFACE_STIPPLE_INDEX
])
1975 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
1976 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
1977 xassert (UNSPECIFIEDP (attrs
[LFACE_FONT_INDEX
])
1978 || IGNORE_DEFFACE_P (attrs
[LFACE_FONT_INDEX
])
1979 || FONTP (attrs
[LFACE_FONT_INDEX
]));
1980 xassert (UNSPECIFIEDP (attrs
[LFACE_FONTSET_INDEX
])
1981 || STRINGP (attrs
[LFACE_FONTSET_INDEX
]));
1986 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
1994 xassert (LFACEP (lface
));
1995 check_lface_attrs (XVECTOR (lface
)->contents
);
1999 #else /* GLYPH_DEBUG == 0 */
2001 #define check_lface_attrs(attrs) (void) 0
2002 #define check_lface(lface) (void) 0
2004 #endif /* GLYPH_DEBUG == 0 */
2008 /* Face-merge cycle checking. */
2010 enum named_merge_point_kind
2012 NAMED_MERGE_POINT_NORMAL
,
2013 NAMED_MERGE_POINT_REMAP
2016 /* A `named merge point' is simply a point during face-merging where we
2017 look up a face by name. We keep a stack of which named lookups we're
2018 currently processing so that we can easily detect cycles, using a
2019 linked- list of struct named_merge_point structures, typically
2020 allocated on the stack frame of the named lookup functions which are
2021 active (so no consing is required). */
2022 struct named_merge_point
2024 Lisp_Object face_name
;
2025 enum named_merge_point_kind named_merge_point_kind
;
2026 struct named_merge_point
*prev
;
2030 /* If a face merging cycle is detected for FACE_NAME, return 0,
2031 otherwise add NEW_NAMED_MERGE_POINT, which is initialized using
2032 FACE_NAME and NAMED_MERGE_POINT_KIND, as the head of the linked list
2033 pointed to by NAMED_MERGE_POINTS, and return 1. */
2036 push_named_merge_point (struct named_merge_point
*new_named_merge_point
,
2037 Lisp_Object face_name
,
2038 enum named_merge_point_kind named_merge_point_kind
,
2039 struct named_merge_point
**named_merge_points
)
2041 struct named_merge_point
*prev
;
2043 for (prev
= *named_merge_points
; prev
; prev
= prev
->prev
)
2044 if (EQ (face_name
, prev
->face_name
))
2046 if (prev
->named_merge_point_kind
== named_merge_point_kind
)
2047 /* A cycle, so fail. */
2049 else if (prev
->named_merge_point_kind
== NAMED_MERGE_POINT_REMAP
)
2050 /* A remap `hides ' any previous normal merge points
2051 (because the remap means that it's actually different face),
2052 so as we know the current merge point must be normal, we
2053 can just assume it's OK. */
2057 new_named_merge_point
->face_name
= face_name
;
2058 new_named_merge_point
->named_merge_point_kind
= named_merge_point_kind
;
2059 new_named_merge_point
->prev
= *named_merge_points
;
2061 *named_merge_points
= new_named_merge_point
;
2068 #if 0 /* Seems to be unused. */
2070 internal_resolve_face_name (nargs
, args
)
2074 return Fget (args
[0], args
[1]);
2078 resolve_face_name_error (ignore
)
2085 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
2086 to make it a symbol. If FACE_NAME is an alias for another face,
2087 return that face's name.
2089 Return default face in case of errors. */
2092 resolve_face_name (Lisp_Object face_name
, int signal_p
)
2094 Lisp_Object orig_face
;
2095 Lisp_Object tortoise
, hare
;
2097 if (STRINGP (face_name
))
2098 face_name
= intern (SDATA (face_name
));
2100 if (NILP (face_name
) || !SYMBOLP (face_name
))
2103 orig_face
= face_name
;
2104 tortoise
= hare
= face_name
;
2109 hare
= Fget (hare
, Qface_alias
);
2110 if (NILP (hare
) || !SYMBOLP (hare
))
2114 hare
= Fget (hare
, Qface_alias
);
2115 if (NILP (hare
) || !SYMBOLP (hare
))
2118 tortoise
= Fget (tortoise
, Qface_alias
);
2119 if (EQ (hare
, tortoise
))
2122 xsignal1 (Qcircular_list
, orig_face
);
2131 /* Return the face definition of FACE_NAME on frame F. F null means
2132 return the definition for new frames. FACE_NAME may be a string or
2133 a symbol (apparently Emacs 20.2 allowed strings as face names in
2134 face text properties; Ediff uses that). If SIGNAL_P is non-zero,
2135 signal an error if FACE_NAME is not a valid face name. If SIGNAL_P
2136 is zero, value is nil if FACE_NAME is not a valid face name. */
2137 static INLINE Lisp_Object
2138 lface_from_face_name_no_resolve (struct frame
*f
, Lisp_Object face_name
, int signal_p
)
2143 lface
= assq_no_quit (face_name
, f
->face_alist
);
2145 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
2148 lface
= XCDR (lface
);
2150 signal_error ("Invalid face", face_name
);
2152 check_lface (lface
);
2157 /* Return the face definition of FACE_NAME on frame F. F null means
2158 return the definition for new frames. FACE_NAME may be a string or
2159 a symbol (apparently Emacs 20.2 allowed strings as face names in
2160 face text properties; Ediff uses that). If FACE_NAME is an alias
2161 for another face, return that face's definition. If SIGNAL_P is
2162 non-zero, signal an error if FACE_NAME is not a valid face name.
2163 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
2165 static INLINE Lisp_Object
2166 lface_from_face_name (struct frame
*f
, Lisp_Object face_name
, int signal_p
)
2168 face_name
= resolve_face_name (face_name
, signal_p
);
2169 return lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2173 /* Get face attributes of face FACE_NAME from frame-local faces on
2174 frame F. Store the resulting attributes in ATTRS which must point
2175 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
2176 is non-zero, signal an error if FACE_NAME does not name a face.
2177 Otherwise, value is zero if FACE_NAME is not a face. */
2180 get_lface_attributes_no_remap (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*attrs
, int signal_p
)
2184 lface
= lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2187 memcpy (attrs
, XVECTOR (lface
)->contents
,
2188 LFACE_VECTOR_SIZE
* sizeof *attrs
);
2190 return !NILP (lface
);
2193 /* Get face attributes of face FACE_NAME from frame-local faces on frame
2194 F. Store the resulting attributes in ATTRS which must point to a
2195 vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If FACE_NAME is an
2196 alias for another face, use that face's definition. If SIGNAL_P is
2197 non-zero, signal an error if FACE_NAME does not name a face.
2198 Otherwise, value is zero if FACE_NAME is not a face. */
2201 get_lface_attributes (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*attrs
, int signal_p
, struct named_merge_point
*named_merge_points
)
2203 Lisp_Object face_remapping
;
2205 face_name
= resolve_face_name (face_name
, signal_p
);
2207 /* See if SYMBOL has been remapped to some other face (usually this
2208 is done buffer-locally). */
2209 face_remapping
= assq_no_quit (face_name
, Vface_remapping_alist
);
2210 if (CONSP (face_remapping
))
2212 struct named_merge_point named_merge_point
;
2214 if (push_named_merge_point (&named_merge_point
,
2215 face_name
, NAMED_MERGE_POINT_REMAP
,
2216 &named_merge_points
))
2220 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2221 attrs
[i
] = Qunspecified
;
2223 return merge_face_ref (f
, XCDR (face_remapping
), attrs
,
2224 signal_p
, named_merge_points
);
2228 /* Default case, no remapping. */
2229 return get_lface_attributes_no_remap (f
, face_name
, attrs
, signal_p
);
2233 /* Non-zero if all attributes in face attribute vector ATTRS are
2234 specified, i.e. are non-nil. */
2237 lface_fully_specified_p (Lisp_Object
*attrs
)
2241 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2242 if (i
!= LFACE_FONT_INDEX
&& i
!= LFACE_INHERIT_INDEX
)
2243 if ((UNSPECIFIEDP (attrs
[i
]) || IGNORE_DEFFACE_P (attrs
[i
])))
2246 return i
== LFACE_VECTOR_SIZE
;
2249 #ifdef HAVE_WINDOW_SYSTEM
2251 /* Set font-related attributes of Lisp face LFACE from FONT-OBJECT.
2252 If FORCE_P is zero, set only unspecified attributes of LFACE. The
2253 exception is `font' attribute. It is set to FONT_OBJECT regardless
2257 set_lface_from_font (struct frame
*f
, Lisp_Object lface
, Lisp_Object font_object
, int force_p
)
2260 struct font
*font
= XFONT_OBJECT (font_object
);
2262 /* Set attributes only if unspecified, otherwise face defaults for
2263 new frames would never take effect. If the font doesn't have a
2264 specific property, set a normal value for that. */
2266 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
2268 Lisp_Object family
= AREF (font_object
, FONT_FAMILY_INDEX
);
2270 LFACE_FAMILY (lface
) = SYMBOL_NAME (family
);
2273 if (force_p
|| UNSPECIFIEDP (LFACE_FOUNDRY (lface
)))
2275 Lisp_Object foundry
= AREF (font_object
, FONT_FOUNDRY_INDEX
);
2277 LFACE_FOUNDRY (lface
) = SYMBOL_NAME (foundry
);
2280 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
2282 int pt
= PIXEL_TO_POINT (font
->pixel_size
* 10, f
->resy
);
2285 LFACE_HEIGHT (lface
) = make_number (pt
);
2288 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
2290 val
= FONT_WEIGHT_FOR_FACE (font_object
);
2291 LFACE_WEIGHT (lface
) = ! NILP (val
) ? val
:Qnormal
;
2293 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
2295 val
= FONT_SLANT_FOR_FACE (font_object
);
2296 LFACE_SLANT (lface
) = ! NILP (val
) ? val
: Qnormal
;
2298 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
2300 val
= FONT_WIDTH_FOR_FACE (font_object
);
2301 LFACE_SWIDTH (lface
) = ! NILP (val
) ? val
: Qnormal
;
2304 LFACE_FONT (lface
) = font_object
;
2308 #endif /* HAVE_WINDOW_SYSTEM */
2311 /* Merges the face height FROM with the face height TO, and returns the
2312 merged height. If FROM is an invalid height, then INVALID is
2313 returned instead. FROM and TO may be either absolute face heights or
2314 `relative' heights; the returned value is always an absolute height
2315 unless both FROM and TO are relative. */
2318 merge_face_heights (Lisp_Object from
, Lisp_Object to
, Lisp_Object invalid
)
2320 Lisp_Object result
= invalid
;
2322 if (INTEGERP (from
))
2323 /* FROM is absolute, just use it as is. */
2325 else if (FLOATP (from
))
2326 /* FROM is a scale, use it to adjust TO. */
2329 /* relative X absolute => absolute */
2330 result
= make_number ((EMACS_INT
)(XFLOAT_DATA (from
) * XINT (to
)));
2331 else if (FLOATP (to
))
2332 /* relative X relative => relative */
2333 result
= make_float (XFLOAT_DATA (from
) * XFLOAT_DATA (to
));
2334 else if (UNSPECIFIEDP (to
))
2337 else if (FUNCTIONP (from
))
2338 /* FROM is a function, which use to adjust TO. */
2340 /* Call function with current height as argument.
2341 From is the new height. */
2342 Lisp_Object args
[2];
2346 result
= safe_call (2, args
);
2348 /* Ensure that if TO was absolute, so is the result. */
2349 if (INTEGERP (to
) && !INTEGERP (result
))
2357 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
2358 store the resulting attributes in TO, which must be already be
2359 completely specified and contain only absolute attributes. Every
2360 specified attribute of FROM overrides the corresponding attribute of
2361 TO; relative attributes in FROM are merged with the absolute value in
2362 TO and replace it. NAMED_MERGE_POINTS is used internally to detect
2363 loops in face inheritance/remapping; it should be 0 when called from
2367 merge_face_vectors (struct frame
*f
, Lisp_Object
*from
, Lisp_Object
*to
, struct named_merge_point
*named_merge_points
)
2371 /* If FROM inherits from some other faces, merge their attributes into
2372 TO before merging FROM's direct attributes. Note that an :inherit
2373 attribute of `unspecified' is the same as one of nil; we never
2374 merge :inherit attributes, so nil is more correct, but lots of
2375 other code uses `unspecified' as a generic value for face attributes. */
2376 if (!UNSPECIFIEDP (from
[LFACE_INHERIT_INDEX
])
2377 && !NILP (from
[LFACE_INHERIT_INDEX
]))
2378 merge_face_ref (f
, from
[LFACE_INHERIT_INDEX
], to
, 0, named_merge_points
);
2380 i
= LFACE_FONT_INDEX
;
2381 if (!UNSPECIFIEDP (from
[i
]))
2383 if (!UNSPECIFIEDP (to
[i
]))
2384 to
[i
] = Fmerge_font_spec (from
[i
], to
[i
]);
2386 to
[i
] = Fcopy_font_spec (from
[i
]);
2387 if (! NILP (AREF (to
[i
], FONT_FOUNDRY_INDEX
)))
2388 to
[LFACE_FOUNDRY_INDEX
] = SYMBOL_NAME (AREF (to
[i
], FONT_FOUNDRY_INDEX
));
2389 if (! NILP (AREF (to
[i
], FONT_FAMILY_INDEX
)))
2390 to
[LFACE_FAMILY_INDEX
] = SYMBOL_NAME (AREF (to
[i
], FONT_FAMILY_INDEX
));
2391 if (! NILP (AREF (to
[i
], FONT_WEIGHT_INDEX
)))
2392 to
[LFACE_WEIGHT_INDEX
] = FONT_WEIGHT_FOR_FACE (to
[i
]);
2393 if (! NILP (AREF (to
[i
], FONT_SLANT_INDEX
)))
2394 to
[LFACE_SLANT_INDEX
] = FONT_SLANT_FOR_FACE (to
[i
]);
2395 if (! NILP (AREF (to
[i
], FONT_WIDTH_INDEX
)))
2396 to
[LFACE_SWIDTH_INDEX
] = FONT_WIDTH_FOR_FACE (to
[i
]);
2397 ASET (to
[i
], FONT_SIZE_INDEX
, Qnil
);
2400 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2401 if (!UNSPECIFIEDP (from
[i
]))
2403 if (i
== LFACE_HEIGHT_INDEX
&& !INTEGERP (from
[i
]))
2405 to
[i
] = merge_face_heights (from
[i
], to
[i
], to
[i
]);
2406 font_clear_prop (to
, FONT_SIZE_INDEX
);
2408 else if (i
!= LFACE_FONT_INDEX
2409 && ! EQ (to
[i
], from
[i
]))
2412 if (i
>= LFACE_FAMILY_INDEX
&& i
<=LFACE_SLANT_INDEX
)
2413 font_clear_prop (to
,
2414 (i
== LFACE_FAMILY_INDEX
? FONT_FAMILY_INDEX
2415 : i
== LFACE_FOUNDRY_INDEX
? FONT_FOUNDRY_INDEX
2416 : i
== LFACE_SWIDTH_INDEX
? FONT_WIDTH_INDEX
2417 : i
== LFACE_HEIGHT_INDEX
? FONT_SIZE_INDEX
2418 : i
== LFACE_WEIGHT_INDEX
? FONT_WEIGHT_INDEX
2419 : FONT_SLANT_INDEX
));
2423 /* TO is always an absolute face, which should inherit from nothing.
2424 We blindly copy the :inherit attribute above and fix it up here. */
2425 to
[LFACE_INHERIT_INDEX
] = Qnil
;
2428 /* Merge the named face FACE_NAME on frame F, into the vector of face
2429 attributes TO. NAMED_MERGE_POINTS is used to detect loops in face
2430 inheritance. Returns true if FACE_NAME is a valid face name and
2431 merging succeeded. */
2434 merge_named_face (struct frame
*f
, Lisp_Object face_name
, Lisp_Object
*to
, struct named_merge_point
*named_merge_points
)
2436 struct named_merge_point named_merge_point
;
2438 if (push_named_merge_point (&named_merge_point
,
2439 face_name
, NAMED_MERGE_POINT_NORMAL
,
2440 &named_merge_points
))
2442 struct gcpro gcpro1
;
2443 Lisp_Object from
[LFACE_VECTOR_SIZE
];
2444 int ok
= get_lface_attributes (f
, face_name
, from
, 0, named_merge_points
);
2448 GCPRO1 (named_merge_point
.face_name
);
2449 merge_face_vectors (f
, from
, to
, named_merge_points
);
2460 /* Merge face attributes from the lisp `face reference' FACE_REF on
2461 frame F into the face attribute vector TO. If ERR_MSGS is non-zero,
2462 problems with FACE_REF cause an error message to be shown. Return
2463 non-zero if no errors occurred (regardless of the value of ERR_MSGS).
2464 NAMED_MERGE_POINTS is used to detect loops in face inheritance or
2465 list structure; it may be 0 for most callers.
2467 FACE_REF may be a single face specification or a list of such
2468 specifications. Each face specification can be:
2470 1. A symbol or string naming a Lisp face.
2472 2. A property list of the form (KEYWORD VALUE ...) where each
2473 KEYWORD is a face attribute name, and value is an appropriate value
2476 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
2477 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
2478 for compatibility with 20.2.
2480 Face specifications earlier in lists take precedence over later
2484 merge_face_ref (struct frame
*f
, Lisp_Object face_ref
, Lisp_Object
*to
, int err_msgs
, struct named_merge_point
*named_merge_points
)
2486 int ok
= 1; /* Succeed without an error? */
2488 if (CONSP (face_ref
))
2490 Lisp_Object first
= XCAR (face_ref
);
2492 if (EQ (first
, Qforeground_color
)
2493 || EQ (first
, Qbackground_color
))
2495 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
2496 . COLOR). COLOR must be a string. */
2497 Lisp_Object color_name
= XCDR (face_ref
);
2498 Lisp_Object color
= first
;
2500 if (STRINGP (color_name
))
2502 if (EQ (color
, Qforeground_color
))
2503 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
2505 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
2510 add_to_log ("Invalid face color", color_name
, Qnil
);
2514 else if (SYMBOLP (first
)
2515 && *SDATA (SYMBOL_NAME (first
)) == ':')
2517 /* Assume this is the property list form. */
2518 while (CONSP (face_ref
) && CONSP (XCDR (face_ref
)))
2520 Lisp_Object keyword
= XCAR (face_ref
);
2521 Lisp_Object value
= XCAR (XCDR (face_ref
));
2524 /* Specifying `unspecified' is a no-op. */
2525 if (EQ (value
, Qunspecified
))
2527 else if (EQ (keyword
, QCfamily
))
2529 if (STRINGP (value
))
2531 to
[LFACE_FAMILY_INDEX
] = value
;
2532 font_clear_prop (to
, FONT_FAMILY_INDEX
);
2537 else if (EQ (keyword
, QCfoundry
))
2539 if (STRINGP (value
))
2541 to
[LFACE_FOUNDRY_INDEX
] = value
;
2542 font_clear_prop (to
, FONT_FOUNDRY_INDEX
);
2547 else if (EQ (keyword
, QCheight
))
2549 Lisp_Object new_height
=
2550 merge_face_heights (value
, to
[LFACE_HEIGHT_INDEX
], Qnil
);
2552 if (! NILP (new_height
))
2554 to
[LFACE_HEIGHT_INDEX
] = new_height
;
2555 font_clear_prop (to
, FONT_SIZE_INDEX
);
2560 else if (EQ (keyword
, QCweight
))
2562 if (SYMBOLP (value
) && FONT_WEIGHT_NAME_NUMERIC (value
) >= 0)
2564 to
[LFACE_WEIGHT_INDEX
] = value
;
2565 font_clear_prop (to
, FONT_WEIGHT_INDEX
);
2570 else if (EQ (keyword
, QCslant
))
2572 if (SYMBOLP (value
) && FONT_SLANT_NAME_NUMERIC (value
) >= 0)
2574 to
[LFACE_SLANT_INDEX
] = value
;
2575 font_clear_prop (to
, FONT_SLANT_INDEX
);
2580 else if (EQ (keyword
, QCunderline
))
2585 to
[LFACE_UNDERLINE_INDEX
] = value
;
2589 else if (EQ (keyword
, QCoverline
))
2594 to
[LFACE_OVERLINE_INDEX
] = value
;
2598 else if (EQ (keyword
, QCstrike_through
))
2603 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
2607 else if (EQ (keyword
, QCbox
))
2610 value
= make_number (1);
2611 if (INTEGERP (value
)
2615 to
[LFACE_BOX_INDEX
] = value
;
2619 else if (EQ (keyword
, QCinverse_video
)
2620 || EQ (keyword
, QCreverse_video
))
2622 if (EQ (value
, Qt
) || NILP (value
))
2623 to
[LFACE_INVERSE_INDEX
] = value
;
2627 else if (EQ (keyword
, QCforeground
))
2629 if (STRINGP (value
))
2630 to
[LFACE_FOREGROUND_INDEX
] = value
;
2634 else if (EQ (keyword
, QCbackground
))
2636 if (STRINGP (value
))
2637 to
[LFACE_BACKGROUND_INDEX
] = value
;
2641 else if (EQ (keyword
, QCstipple
))
2643 #if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
2644 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
2645 if (!NILP (pixmap_p
))
2646 to
[LFACE_STIPPLE_INDEX
] = value
;
2651 else if (EQ (keyword
, QCwidth
))
2653 if (SYMBOLP (value
) && FONT_WIDTH_NAME_NUMERIC (value
) >= 0)
2655 to
[LFACE_SWIDTH_INDEX
] = value
;
2656 font_clear_prop (to
, FONT_WIDTH_INDEX
);
2661 else if (EQ (keyword
, QCinherit
))
2663 /* This is not really very useful; it's just like a
2664 normal face reference. */
2665 if (! merge_face_ref (f
, value
, to
,
2666 err_msgs
, named_merge_points
))
2674 add_to_log ("Invalid face attribute %S %S", keyword
, value
);
2678 face_ref
= XCDR (XCDR (face_ref
));
2683 /* This is a list of face refs. Those at the beginning of the
2684 list take precedence over what follows, so we have to merge
2685 from the end backwards. */
2686 Lisp_Object next
= XCDR (face_ref
);
2689 ok
= merge_face_ref (f
, next
, to
, err_msgs
, named_merge_points
);
2691 if (! merge_face_ref (f
, first
, to
, err_msgs
, named_merge_points
))
2697 /* FACE_REF ought to be a face name. */
2698 ok
= merge_named_face (f
, face_ref
, to
, named_merge_points
);
2699 if (!ok
&& err_msgs
)
2700 add_to_log ("Invalid face reference: %s", face_ref
, Qnil
);
2707 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
2708 Sinternal_make_lisp_face
, 1, 2, 0,
2709 doc
: /* Make FACE, a symbol, a Lisp face with all attributes nil.
2710 If FACE was not known as a face before, create a new one.
2711 If optional argument FRAME is specified, make a frame-local face
2712 for that frame. Otherwise operate on the global face definition.
2713 Value is a vector of face attributes. */)
2714 (Lisp_Object face
, Lisp_Object frame
)
2716 Lisp_Object global_lface
, lface
;
2720 CHECK_SYMBOL (face
);
2721 global_lface
= lface_from_face_name (NULL
, face
, 0);
2725 CHECK_LIVE_FRAME (frame
);
2727 lface
= lface_from_face_name (f
, face
, 0);
2730 f
= NULL
, lface
= Qnil
;
2732 /* Add a global definition if there is none. */
2733 if (NILP (global_lface
))
2735 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2737 ASET (global_lface
, 0, Qface
);
2738 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
2739 Vface_new_frame_defaults
);
2741 /* Assign the new Lisp face a unique ID. The mapping from Lisp
2742 face id to Lisp face is given by the vector lface_id_to_name.
2743 The mapping from Lisp face to Lisp face id is given by the
2744 property `face' of the Lisp face name. */
2745 if (next_lface_id
== lface_id_to_name_size
)
2747 int new_size
= max (50, 2 * lface_id_to_name_size
);
2748 int sz
= new_size
* sizeof *lface_id_to_name
;
2749 lface_id_to_name
= (Lisp_Object
*) xrealloc (lface_id_to_name
, sz
);
2750 lface_id_to_name_size
= new_size
;
2753 lface_id_to_name
[next_lface_id
] = face
;
2754 Fput (face
, Qface
, make_number (next_lface_id
));
2758 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2759 ASET (global_lface
, i
, Qunspecified
);
2761 /* Add a frame-local definition. */
2766 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2768 ASET (lface
, 0, Qface
);
2769 f
->face_alist
= Fcons (Fcons (face
, lface
), f
->face_alist
);
2772 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2773 ASET (lface
, i
, Qunspecified
);
2776 lface
= global_lface
;
2778 /* Changing a named face means that all realized faces depending on
2779 that face are invalid. Since we cannot tell which realized faces
2780 depend on the face, make sure they are all removed. This is done
2781 by incrementing face_change_count. The next call to
2782 init_iterator will then free realized faces. */
2783 if (NILP (Fget (face
, Qface_no_inherit
)))
2785 ++face_change_count
;
2786 ++windows_or_buffers_changed
;
2789 xassert (LFACEP (lface
));
2790 check_lface (lface
);
2795 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
2796 Sinternal_lisp_face_p
, 1, 2, 0,
2797 doc
: /* Return non-nil if FACE names a face.
2798 FACE should be a symbol or string.
2799 If optional second argument FRAME is non-nil, check for the
2800 existence of a frame-local face with name FACE on that frame.
2801 Otherwise check for the existence of a global face. */)
2802 (Lisp_Object face
, Lisp_Object frame
)
2806 face
= resolve_face_name (face
, 1);
2810 CHECK_LIVE_FRAME (frame
);
2811 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2814 lface
= lface_from_face_name (NULL
, face
, 0);
2820 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
2821 Sinternal_copy_lisp_face
, 4, 4, 0,
2822 doc
: /* Copy face FROM to TO.
2823 If FRAME is t, copy the global face definition of FROM.
2824 Otherwise, copy the frame-local definition of FROM on FRAME.
2825 If NEW-FRAME is a frame, copy that data into the frame-local
2826 definition of TO on NEW-FRAME. If NEW-FRAME is nil,
2827 FRAME controls where the data is copied to.
2829 The value is TO. */)
2830 (Lisp_Object from
, Lisp_Object to
, Lisp_Object frame
, Lisp_Object new_frame
)
2832 Lisp_Object lface
, copy
;
2834 CHECK_SYMBOL (from
);
2839 /* Copy global definition of FROM. We don't make copies of
2840 strings etc. because 20.2 didn't do it either. */
2841 lface
= lface_from_face_name (NULL
, from
, 1);
2842 copy
= Finternal_make_lisp_face (to
, Qnil
);
2846 /* Copy frame-local definition of FROM. */
2847 if (NILP (new_frame
))
2849 CHECK_LIVE_FRAME (frame
);
2850 CHECK_LIVE_FRAME (new_frame
);
2851 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
2852 copy
= Finternal_make_lisp_face (to
, new_frame
);
2855 memcpy (XVECTOR (copy
)->contents
, XVECTOR (lface
)->contents
,
2856 LFACE_VECTOR_SIZE
* sizeof (Lisp_Object
));
2858 /* Changing a named face means that all realized faces depending on
2859 that face are invalid. Since we cannot tell which realized faces
2860 depend on the face, make sure they are all removed. This is done
2861 by incrementing face_change_count. The next call to
2862 init_iterator will then free realized faces. */
2863 if (NILP (Fget (to
, Qface_no_inherit
)))
2865 ++face_change_count
;
2866 ++windows_or_buffers_changed
;
2873 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
2874 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
2875 doc
: /* Set attribute ATTR of FACE to VALUE.
2876 FRAME being a frame means change the face on that frame.
2877 FRAME nil means change the face of the selected frame.
2878 FRAME t means change the default for new frames.
2879 FRAME 0 means change the face on all frames, and change the default
2881 (Lisp_Object face
, Lisp_Object attr
, Lisp_Object value
, Lisp_Object frame
)
2884 Lisp_Object old_value
= Qnil
;
2885 /* Set one of enum font_property_index (> 0) if ATTR is one of
2886 font-related attributes other than QCfont and QCfontset. */
2887 enum font_property_index prop_index
= 0;
2889 CHECK_SYMBOL (face
);
2890 CHECK_SYMBOL (attr
);
2892 face
= resolve_face_name (face
, 1);
2894 /* If FRAME is 0, change face on all frames, and change the
2895 default for new frames. */
2896 if (INTEGERP (frame
) && XINT (frame
) == 0)
2899 Finternal_set_lisp_face_attribute (face
, attr
, value
, Qt
);
2900 FOR_EACH_FRAME (tail
, frame
)
2901 Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
2905 /* Set lface to the Lisp attribute vector of FACE. */
2908 lface
= lface_from_face_name (NULL
, face
, 1);
2910 /* When updating face-new-frame-defaults, we put :ignore-defface
2911 where the caller wants `unspecified'. This forces the frame
2912 defaults to ignore the defface value. Otherwise, the defface
2913 will take effect, which is generally not what is intended.
2914 The value of that attribute will be inherited from some other
2915 face during face merging. See internal_merge_in_global_face. */
2916 if (UNSPECIFIEDP (value
))
2917 value
= Qignore_defface
;
2922 frame
= selected_frame
;
2924 CHECK_LIVE_FRAME (frame
);
2925 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2927 /* If a frame-local face doesn't exist yet, create one. */
2929 lface
= Finternal_make_lisp_face (face
, frame
);
2932 if (EQ (attr
, QCfamily
))
2934 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2936 CHECK_STRING (value
);
2937 if (SCHARS (value
) == 0)
2938 signal_error ("Invalid face family", value
);
2940 old_value
= LFACE_FAMILY (lface
);
2941 LFACE_FAMILY (lface
) = value
;
2942 prop_index
= FONT_FAMILY_INDEX
;
2944 else if (EQ (attr
, QCfoundry
))
2946 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2948 CHECK_STRING (value
);
2949 if (SCHARS (value
) == 0)
2950 signal_error ("Invalid face foundry", value
);
2952 old_value
= LFACE_FOUNDRY (lface
);
2953 LFACE_FOUNDRY (lface
) = value
;
2954 prop_index
= FONT_FOUNDRY_INDEX
;
2956 else if (EQ (attr
, QCheight
))
2958 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2960 if (EQ (face
, Qdefault
))
2962 /* The default face must have an absolute size. */
2963 if (!INTEGERP (value
) || XINT (value
) <= 0)
2964 signal_error ("Invalid default face height", value
);
2968 /* For non-default faces, do a test merge with a random
2969 height to see if VALUE's ok. */
2970 Lisp_Object test
= merge_face_heights (value
,
2973 if (!INTEGERP (test
) || XINT (test
) <= 0)
2974 signal_error ("Invalid face height", value
);
2978 old_value
= LFACE_HEIGHT (lface
);
2979 LFACE_HEIGHT (lface
) = value
;
2980 prop_index
= FONT_SIZE_INDEX
;
2982 else if (EQ (attr
, QCweight
))
2984 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2986 CHECK_SYMBOL (value
);
2987 if (FONT_WEIGHT_NAME_NUMERIC (value
) < 0)
2988 signal_error ("Invalid face weight", value
);
2990 old_value
= LFACE_WEIGHT (lface
);
2991 LFACE_WEIGHT (lface
) = value
;
2992 prop_index
= FONT_WEIGHT_INDEX
;
2994 else if (EQ (attr
, QCslant
))
2996 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
2998 CHECK_SYMBOL (value
);
2999 if (FONT_SLANT_NAME_NUMERIC (value
) < 0)
3000 signal_error ("Invalid face slant", value
);
3002 old_value
= LFACE_SLANT (lface
);
3003 LFACE_SLANT (lface
) = value
;
3004 prop_index
= FONT_SLANT_INDEX
;
3006 else if (EQ (attr
, QCunderline
))
3008 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3009 if ((SYMBOLP (value
)
3011 && !EQ (value
, Qnil
))
3012 /* Underline color. */
3014 && SCHARS (value
) == 0))
3015 signal_error ("Invalid face underline", value
);
3017 old_value
= LFACE_UNDERLINE (lface
);
3018 LFACE_UNDERLINE (lface
) = value
;
3020 else if (EQ (attr
, QCoverline
))
3022 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3023 if ((SYMBOLP (value
)
3025 && !EQ (value
, Qnil
))
3026 /* Overline color. */
3028 && SCHARS (value
) == 0))
3029 signal_error ("Invalid face overline", value
);
3031 old_value
= LFACE_OVERLINE (lface
);
3032 LFACE_OVERLINE (lface
) = value
;
3034 else if (EQ (attr
, QCstrike_through
))
3036 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3037 if ((SYMBOLP (value
)
3039 && !EQ (value
, Qnil
))
3040 /* Strike-through color. */
3042 && SCHARS (value
) == 0))
3043 signal_error ("Invalid face strike-through", value
);
3045 old_value
= LFACE_STRIKE_THROUGH (lface
);
3046 LFACE_STRIKE_THROUGH (lface
) = value
;
3048 else if (EQ (attr
, QCbox
))
3052 /* Allow t meaning a simple box of width 1 in foreground color
3055 value
= make_number (1);
3057 if (UNSPECIFIEDP (value
) || IGNORE_DEFFACE_P (value
))
3059 else if (NILP (value
))
3061 else if (INTEGERP (value
))
3062 valid_p
= XINT (value
) != 0;
3063 else if (STRINGP (value
))
3064 valid_p
= SCHARS (value
) > 0;
3065 else if (CONSP (value
))
3081 if (EQ (k
, QCline_width
))
3083 if (!INTEGERP (v
) || XINT (v
) == 0)
3086 else if (EQ (k
, QCcolor
))
3088 if (!NILP (v
) && (!STRINGP (v
) || SCHARS (v
) == 0))
3091 else if (EQ (k
, QCstyle
))
3093 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
3100 valid_p
= NILP (tem
);
3106 signal_error ("Invalid face box", value
);
3108 old_value
= LFACE_BOX (lface
);
3109 LFACE_BOX (lface
) = value
;
3111 else if (EQ (attr
, QCinverse_video
)
3112 || EQ (attr
, QCreverse_video
))
3114 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3116 CHECK_SYMBOL (value
);
3117 if (!EQ (value
, Qt
) && !NILP (value
))
3118 signal_error ("Invalid inverse-video face attribute value", value
);
3120 old_value
= LFACE_INVERSE (lface
);
3121 LFACE_INVERSE (lface
) = value
;
3123 else if (EQ (attr
, QCforeground
))
3125 /* Compatibility with 20.x. */
3127 value
= Qunspecified
;
3128 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3130 /* Don't check for valid color names here because it depends
3131 on the frame (display) whether the color will be valid
3132 when the face is realized. */
3133 CHECK_STRING (value
);
3134 if (SCHARS (value
) == 0)
3135 signal_error ("Empty foreground color value", value
);
3137 old_value
= LFACE_FOREGROUND (lface
);
3138 LFACE_FOREGROUND (lface
) = value
;
3140 else if (EQ (attr
, QCbackground
))
3142 /* Compatibility with 20.x. */
3144 value
= Qunspecified
;
3145 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3147 /* Don't check for valid color names here because it depends
3148 on the frame (display) whether the color will be valid
3149 when the face is realized. */
3150 CHECK_STRING (value
);
3151 if (SCHARS (value
) == 0)
3152 signal_error ("Empty background color value", value
);
3154 old_value
= LFACE_BACKGROUND (lface
);
3155 LFACE_BACKGROUND (lface
) = value
;
3157 else if (EQ (attr
, QCstipple
))
3159 #if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
3160 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3162 && NILP (Fbitmap_spec_p (value
)))
3163 signal_error ("Invalid stipple attribute", value
);
3164 old_value
= LFACE_STIPPLE (lface
);
3165 LFACE_STIPPLE (lface
) = value
;
3166 #endif /* HAVE_X_WINDOWS || HAVE_NS */
3168 else if (EQ (attr
, QCwidth
))
3170 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3172 CHECK_SYMBOL (value
);
3173 if (FONT_WIDTH_NAME_NUMERIC (value
) < 0)
3174 signal_error ("Invalid face width", value
);
3176 old_value
= LFACE_SWIDTH (lface
);
3177 LFACE_SWIDTH (lface
) = value
;
3178 prop_index
= FONT_WIDTH_INDEX
;
3180 else if (EQ (attr
, QCfont
))
3182 #ifdef HAVE_WINDOW_SYSTEM
3183 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3185 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3189 old_value
= LFACE_FONT (lface
);
3190 if (! FONTP (value
))
3192 if (STRINGP (value
))
3194 Lisp_Object name
= value
;
3195 int fontset
= fs_query_fontset (name
, 0);
3198 name
= fontset_ascii (fontset
);
3199 value
= font_spec_from_name (name
);
3201 signal_error ("Invalid font name", name
);
3204 signal_error ("Invalid font or font-spec", value
);
3207 f
= XFRAME (selected_frame
);
3210 if (! FONT_OBJECT_P (value
))
3212 Lisp_Object
*attrs
= XVECTOR (lface
)->contents
;
3213 Lisp_Object font_object
;
3215 font_object
= font_load_for_lface (f
, attrs
, value
);
3216 if (NILP (font_object
))
3217 signal_error ("Font not available", value
);
3218 value
= font_object
;
3220 set_lface_from_font (f
, lface
, value
, 1);
3223 LFACE_FONT (lface
) = value
;
3225 #endif /* HAVE_WINDOW_SYSTEM */
3227 else if (EQ (attr
, QCfontset
))
3229 #ifdef HAVE_WINDOW_SYSTEM
3230 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3234 old_value
= LFACE_FONTSET (lface
);
3235 tmp
= Fquery_fontset (value
, Qnil
);
3237 signal_error ("Invalid fontset name", value
);
3238 LFACE_FONTSET (lface
) = value
= tmp
;
3240 #endif /* HAVE_WINDOW_SYSTEM */
3242 else if (EQ (attr
, QCinherit
))
3245 if (SYMBOLP (value
))
3248 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
3249 if (!SYMBOLP (XCAR (tail
)))
3252 LFACE_INHERIT (lface
) = value
;
3254 signal_error ("Invalid face inheritance", value
);
3256 else if (EQ (attr
, QCbold
))
3258 old_value
= LFACE_WEIGHT (lface
);
3259 LFACE_WEIGHT (lface
) = NILP (value
) ? Qnormal
: Qbold
;
3260 prop_index
= FONT_WEIGHT_INDEX
;
3262 else if (EQ (attr
, QCitalic
))
3265 old_value
= LFACE_SLANT (lface
);
3266 LFACE_SLANT (lface
) = NILP (value
) ? Qnormal
: Qitalic
;
3267 prop_index
= FONT_SLANT_INDEX
;
3270 signal_error ("Invalid face attribute name", attr
);
3274 /* If a font-related attribute other than QCfont and QCfontset
3275 is specified, and if the original QCfont attribute has a font
3276 (font-spec or font-object), set the corresponding property in
3277 the font to nil so that the font selector doesn't think that
3278 the attribute is mandatory. Also, clear the average
3280 font_clear_prop (XVECTOR (lface
)->contents
, prop_index
);
3283 /* Changing a named face means that all realized faces depending on
3284 that face are invalid. Since we cannot tell which realized faces
3285 depend on the face, make sure they are all removed. This is done
3286 by incrementing face_change_count. The next call to
3287 init_iterator will then free realized faces. */
3289 && NILP (Fget (face
, Qface_no_inherit
))
3290 && NILP (Fequal (old_value
, value
)))
3292 ++face_change_count
;
3293 ++windows_or_buffers_changed
;
3296 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3297 && NILP (Fequal (old_value
, value
)))
3303 if (EQ (face
, Qdefault
))
3305 #ifdef HAVE_WINDOW_SYSTEM
3306 /* Changed font-related attributes of the `default' face are
3307 reflected in changed `font' frame parameters. */
3309 && (prop_index
|| EQ (attr
, QCfont
))
3310 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
3311 set_font_frame_param (frame
, lface
);
3313 #endif /* HAVE_WINDOW_SYSTEM */
3315 if (EQ (attr
, QCforeground
))
3316 param
= Qforeground_color
;
3317 else if (EQ (attr
, QCbackground
))
3318 param
= Qbackground_color
;
3320 #ifdef HAVE_WINDOW_SYSTEM
3322 else if (EQ (face
, Qscroll_bar
))
3324 /* Changing the colors of `scroll-bar' sets frame parameters
3325 `scroll-bar-foreground' and `scroll-bar-background'. */
3326 if (EQ (attr
, QCforeground
))
3327 param
= Qscroll_bar_foreground
;
3328 else if (EQ (attr
, QCbackground
))
3329 param
= Qscroll_bar_background
;
3331 #endif /* not WINDOWSNT */
3332 else if (EQ (face
, Qborder
))
3334 /* Changing background color of `border' sets frame parameter
3336 if (EQ (attr
, QCbackground
))
3337 param
= Qborder_color
;
3339 else if (EQ (face
, Qcursor
))
3341 /* Changing background color of `cursor' sets frame parameter
3343 if (EQ (attr
, QCbackground
))
3344 param
= Qcursor_color
;
3346 else if (EQ (face
, Qmouse
))
3348 /* Changing background color of `mouse' sets frame parameter
3350 if (EQ (attr
, QCbackground
))
3351 param
= Qmouse_color
;
3353 #endif /* HAVE_WINDOW_SYSTEM */
3354 else if (EQ (face
, Qmenu
))
3356 /* Indicate that we have to update the menu bar when
3357 realizing faces on FRAME. FRAME t change the
3358 default for new frames. We do this by setting
3359 setting the flag in new face caches */
3362 struct frame
*f
= XFRAME (frame
);
3363 if (FRAME_FACE_CACHE (f
) == NULL
)
3364 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
3365 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 1;
3368 menu_face_changed_default
= 1;
3374 /* Update `default-frame-alist', which is used for new frames. */
3376 store_in_alist (&Vdefault_frame_alist
, param
, value
);
3379 /* Update the current frame's parameters. */
3382 cons
= XCAR (Vparam_value_alist
);
3383 XSETCAR (cons
, param
);
3384 XSETCDR (cons
, value
);
3385 Fmodify_frame_parameters (frame
, Vparam_value_alist
);
3394 /* Update the corresponding face when frame parameter PARAM on frame F
3395 has been assigned the value NEW_VALUE. */
3398 update_face_from_frame_parameter (struct frame
*f
, Lisp_Object param
, Lisp_Object new_value
)
3400 Lisp_Object face
= Qnil
;
3403 /* If there are no faces yet, give up. This is the case when called
3404 from Fx_create_frame, and we do the necessary things later in
3405 face-set-after-frame-defaults. */
3406 if (NILP (f
->face_alist
))
3409 if (EQ (param
, Qforeground_color
))
3412 lface
= lface_from_face_name (f
, face
, 1);
3413 LFACE_FOREGROUND (lface
) = (STRINGP (new_value
)
3414 ? new_value
: Qunspecified
);
3415 realize_basic_faces (f
);
3417 else if (EQ (param
, Qbackground_color
))
3421 /* Changing the background color might change the background
3422 mode, so that we have to load new defface specs.
3423 Call frame-update-face-colors to do that. */
3424 XSETFRAME (frame
, f
);
3425 call1 (Qframe_set_background_mode
, frame
);
3428 lface
= lface_from_face_name (f
, face
, 1);
3429 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3430 ? new_value
: Qunspecified
);
3431 realize_basic_faces (f
);
3433 #ifdef HAVE_WINDOW_SYSTEM
3434 else if (EQ (param
, Qborder_color
))
3437 lface
= lface_from_face_name (f
, face
, 1);
3438 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3439 ? new_value
: Qunspecified
);
3441 else if (EQ (param
, Qcursor_color
))
3444 lface
= lface_from_face_name (f
, face
, 1);
3445 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3446 ? new_value
: Qunspecified
);
3448 else if (EQ (param
, Qmouse_color
))
3451 lface
= lface_from_face_name (f
, face
, 1);
3452 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3453 ? new_value
: Qunspecified
);
3457 /* Changing a named face means that all realized faces depending on
3458 that face are invalid. Since we cannot tell which realized faces
3459 depend on the face, make sure they are all removed. This is done
3460 by incrementing face_change_count. The next call to
3461 init_iterator will then free realized faces. */
3463 && NILP (Fget (face
, Qface_no_inherit
)))
3465 ++face_change_count
;
3466 ++windows_or_buffers_changed
;
3471 #ifdef HAVE_WINDOW_SYSTEM
3473 /* Set the `font' frame parameter of FRAME determined from the
3474 font-object set in `default' face attributes LFACE. */
3477 set_font_frame_param (Lisp_Object frame
, Lisp_Object lface
)
3479 struct frame
*f
= XFRAME (frame
);
3482 if (FRAME_WINDOW_P (f
)
3483 /* Don't do anything if the font is `unspecified'. This can
3484 happen during frame creation. */
3485 && (font
= LFACE_FONT (lface
),
3486 ! UNSPECIFIEDP (font
)))
3488 if (FONT_SPEC_P (font
))
3490 font
= font_load_for_lface (f
, XVECTOR (lface
)->contents
, font
);
3493 LFACE_FONT (lface
) = font
;
3495 f
->default_face_done_p
= 0;
3496 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, font
), Qnil
));
3501 /* Get the value of X resource RESOURCE, class CLASS for the display
3502 of frame FRAME. This is here because ordinary `x-get-resource'
3503 doesn't take a frame argument. */
3505 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
3506 Sinternal_face_x_get_resource
, 3, 3, 0, doc
: /* */)
3507 (Lisp_Object resource
, Lisp_Object
class, Lisp_Object frame
)
3509 Lisp_Object value
= Qnil
;
3510 CHECK_STRING (resource
);
3511 CHECK_STRING (class);
3512 CHECK_LIVE_FRAME (frame
);
3514 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame
)),
3515 resource
, class, Qnil
, Qnil
);
3521 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
3522 If VALUE is "on" or "true", return t. If VALUE is "off" or
3523 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
3524 error; if SIGNAL_P is zero, return 0. */
3527 face_boolean_x_resource_value (Lisp_Object value
, int signal_p
)
3529 Lisp_Object result
= make_number (0);
3531 xassert (STRINGP (value
));
3533 if (xstrcasecmp (SDATA (value
), "on") == 0
3534 || xstrcasecmp (SDATA (value
), "true") == 0)
3536 else if (xstrcasecmp (SDATA (value
), "off") == 0
3537 || xstrcasecmp (SDATA (value
), "false") == 0)
3539 else if (xstrcasecmp (SDATA (value
), "unspecified") == 0)
3540 result
= Qunspecified
;
3542 signal_error ("Invalid face attribute value from X resource", value
);
3548 DEFUN ("internal-set-lisp-face-attribute-from-resource",
3549 Finternal_set_lisp_face_attribute_from_resource
,
3550 Sinternal_set_lisp_face_attribute_from_resource
,
3551 3, 4, 0, doc
: /* */)
3552 (Lisp_Object face
, Lisp_Object attr
, Lisp_Object value
, Lisp_Object frame
)
3554 CHECK_SYMBOL (face
);
3555 CHECK_SYMBOL (attr
);
3556 CHECK_STRING (value
);
3558 if (xstrcasecmp (SDATA (value
), "unspecified") == 0)
3559 value
= Qunspecified
;
3560 else if (EQ (attr
, QCheight
))
3562 value
= Fstring_to_number (value
, make_number (10));
3563 if (XINT (value
) <= 0)
3564 signal_error ("Invalid face height from X resource", value
);
3566 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
3567 value
= face_boolean_x_resource_value (value
, 1);
3568 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
3569 value
= intern (SDATA (value
));
3570 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
3571 value
= face_boolean_x_resource_value (value
, 1);
3572 else if (EQ (attr
, QCunderline
)
3573 || EQ (attr
, QCoverline
)
3574 || EQ (attr
, QCstrike_through
))
3576 Lisp_Object boolean_value
;
3578 /* If the result of face_boolean_x_resource_value is t or nil,
3579 VALUE does NOT specify a color. */
3580 boolean_value
= face_boolean_x_resource_value (value
, 0);
3581 if (SYMBOLP (boolean_value
))
3582 value
= boolean_value
;
3584 else if (EQ (attr
, QCbox
) || EQ (attr
, QCinherit
))
3585 value
= Fcar (Fread_from_string (value
, Qnil
, Qnil
));
3587 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3590 #endif /* HAVE_WINDOW_SYSTEM */
3593 /***********************************************************************
3595 ***********************************************************************/
3597 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
3599 /* Make menus on frame F appear as specified by the `menu' face. */
3602 x_update_menu_appearance (f
)
3605 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3609 && (rdb
= XrmGetDatabase (FRAME_X_DISPLAY (f
)),
3613 Lisp_Object lface
= lface_from_face_name (f
, Qmenu
, 1);
3614 struct face
*face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
3615 const char *myname
= SDATA (Vx_resource_name
);
3618 const char *popup_path
= "popup_menu";
3620 const char *popup_path
= "menu.popup";
3623 if (STRINGP (LFACE_FOREGROUND (lface
)))
3625 sprintf (line
, "%s.%s*foreground: %s",
3627 SDATA (LFACE_FOREGROUND (lface
)));
3628 XrmPutLineResource (&rdb
, line
);
3629 sprintf (line
, "%s.pane.menubar*foreground: %s",
3630 myname
, SDATA (LFACE_FOREGROUND (lface
)));
3631 XrmPutLineResource (&rdb
, line
);
3635 if (STRINGP (LFACE_BACKGROUND (lface
)))
3637 sprintf (line
, "%s.%s*background: %s",
3639 SDATA (LFACE_BACKGROUND (lface
)));
3640 XrmPutLineResource (&rdb
, line
);
3641 sprintf (line
, "%s.pane.menubar*background: %s",
3642 myname
, SDATA (LFACE_BACKGROUND (lface
)));
3643 XrmPutLineResource (&rdb
, line
);
3648 /* On Solaris 5.8, it's been reported that the `menu' face
3649 can be unspecified here, during startup. Why this
3650 happens remains unknown. -- cyd */
3651 && FONTP (LFACE_FONT (lface
))
3652 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
3653 || !UNSPECIFIEDP (LFACE_FOUNDRY (lface
))
3654 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
3655 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3656 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
3657 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
3659 Lisp_Object xlfd
= Ffont_xlfd_name (LFACE_FONT (lface
), Qnil
);
3661 const char *suffix
= "List";
3664 #if defined HAVE_X_I18N
3666 const char *suffix
= "Set";
3668 const char *suffix
= "";
3675 #if defined HAVE_X_I18N
3676 extern char *xic_create_fontsetname
3677 (char *base_fontname
, Bool motif
);
3678 char *fontsetname
= xic_create_fontsetname (SDATA (xlfd
), motif
);
3680 char *fontsetname
= (char *) SDATA (xlfd
);
3682 sprintf (line
, "%s.pane.menubar*font%s: %s",
3683 myname
, suffix
, fontsetname
);
3684 XrmPutLineResource (&rdb
, line
);
3685 sprintf (line
, "%s.%s*font%s: %s",
3686 myname
, popup_path
, suffix
, fontsetname
);
3687 XrmPutLineResource (&rdb
, line
);
3689 if (fontsetname
!= (char *) SDATA (xlfd
))
3690 xfree (fontsetname
);
3694 if (changed_p
&& f
->output_data
.x
->menubar_widget
)
3695 free_frame_menubar (f
);
3699 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
3702 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p
,
3703 Sface_attribute_relative_p
,
3705 doc
: /* Check whether a face attribute value is relative.
3706 Specifically, this function returns t if the attribute ATTRIBUTE
3707 with the value VALUE is relative.
3709 A relative value is one that doesn't entirely override whatever is
3710 inherited from another face. For most possible attributes,
3711 the only relative value that users see is `unspecified'.
3712 However, for :height, floating point values are also relative. */)
3713 (Lisp_Object attribute
, Lisp_Object value
)
3715 if (EQ (value
, Qunspecified
) || (EQ (value
, Qignore_defface
)))
3717 else if (EQ (attribute
, QCheight
))
3718 return INTEGERP (value
) ? Qnil
: Qt
;
3723 DEFUN ("merge-face-attribute", Fmerge_face_attribute
, Smerge_face_attribute
,
3725 doc
: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
3726 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
3727 the result will be absolute, otherwise it will be relative. */)
3728 (Lisp_Object attribute
, Lisp_Object value1
, Lisp_Object value2
)
3730 if (EQ (value1
, Qunspecified
) || EQ (value1
, Qignore_defface
))
3732 else if (EQ (attribute
, QCheight
))
3733 return merge_face_heights (value1
, value2
, value1
);
3739 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
3740 Sinternal_get_lisp_face_attribute
,
3742 doc
: /* Return face attribute KEYWORD of face SYMBOL.
3743 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
3744 face attribute name, signal an error.
3745 If the optional argument FRAME is given, report on face SYMBOL in that
3746 frame. If FRAME is t, report on the defaults for face SYMBOL (for new
3747 frames). If FRAME is omitted or nil, use the selected frame. */)
3748 (Lisp_Object symbol
, Lisp_Object keyword
, Lisp_Object frame
)
3750 Lisp_Object lface
, value
= Qnil
;
3752 CHECK_SYMBOL (symbol
);
3753 CHECK_SYMBOL (keyword
);
3756 lface
= lface_from_face_name (NULL
, symbol
, 1);
3760 frame
= selected_frame
;
3761 CHECK_LIVE_FRAME (frame
);
3762 lface
= lface_from_face_name (XFRAME (frame
), symbol
, 1);
3765 if (EQ (keyword
, QCfamily
))
3766 value
= LFACE_FAMILY (lface
);
3767 else if (EQ (keyword
, QCfoundry
))
3768 value
= LFACE_FOUNDRY (lface
);
3769 else if (EQ (keyword
, QCheight
))
3770 value
= LFACE_HEIGHT (lface
);
3771 else if (EQ (keyword
, QCweight
))
3772 value
= LFACE_WEIGHT (lface
);
3773 else if (EQ (keyword
, QCslant
))
3774 value
= LFACE_SLANT (lface
);
3775 else if (EQ (keyword
, QCunderline
))
3776 value
= LFACE_UNDERLINE (lface
);
3777 else if (EQ (keyword
, QCoverline
))
3778 value
= LFACE_OVERLINE (lface
);
3779 else if (EQ (keyword
, QCstrike_through
))
3780 value
= LFACE_STRIKE_THROUGH (lface
);
3781 else if (EQ (keyword
, QCbox
))
3782 value
= LFACE_BOX (lface
);
3783 else if (EQ (keyword
, QCinverse_video
)
3784 || EQ (keyword
, QCreverse_video
))
3785 value
= LFACE_INVERSE (lface
);
3786 else if (EQ (keyword
, QCforeground
))
3787 value
= LFACE_FOREGROUND (lface
);
3788 else if (EQ (keyword
, QCbackground
))
3789 value
= LFACE_BACKGROUND (lface
);
3790 else if (EQ (keyword
, QCstipple
))
3791 value
= LFACE_STIPPLE (lface
);
3792 else if (EQ (keyword
, QCwidth
))
3793 value
= LFACE_SWIDTH (lface
);
3794 else if (EQ (keyword
, QCinherit
))
3795 value
= LFACE_INHERIT (lface
);
3796 else if (EQ (keyword
, QCfont
))
3797 value
= LFACE_FONT (lface
);
3798 else if (EQ (keyword
, QCfontset
))
3799 value
= LFACE_FONTSET (lface
);
3801 signal_error ("Invalid face attribute name", keyword
);
3803 if (IGNORE_DEFFACE_P (value
))
3804 return Qunspecified
;
3810 DEFUN ("internal-lisp-face-attribute-values",
3811 Finternal_lisp_face_attribute_values
,
3812 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
3813 doc
: /* Return a list of valid discrete values for face attribute ATTR.
3814 Value is nil if ATTR doesn't have a discrete set of valid values. */)
3817 Lisp_Object result
= Qnil
;
3819 CHECK_SYMBOL (attr
);
3821 if (EQ (attr
, QCunderline
))
3822 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3823 else if (EQ (attr
, QCoverline
))
3824 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3825 else if (EQ (attr
, QCstrike_through
))
3826 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3827 else if (EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
3828 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3834 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
3835 Sinternal_merge_in_global_face
, 2, 2, 0,
3836 doc
: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
3837 Default face attributes override any local face attributes. */)
3838 (Lisp_Object face
, Lisp_Object frame
)
3841 Lisp_Object global_lface
, local_lface
, *gvec
, *lvec
;
3842 struct frame
*f
= XFRAME (frame
);
3844 CHECK_LIVE_FRAME (frame
);
3845 global_lface
= lface_from_face_name (NULL
, face
, 1);
3846 local_lface
= lface_from_face_name (f
, face
, 0);
3847 if (NILP (local_lface
))
3848 local_lface
= Finternal_make_lisp_face (face
, frame
);
3850 /* Make every specified global attribute override the local one.
3851 BEWARE!! This is only used from `face-set-after-frame-default' where
3852 the local frame is defined from default specs in `face-defface-spec'
3853 and those should be overridden by global settings. Hence the strange
3854 "global before local" priority. */
3855 lvec
= XVECTOR (local_lface
)->contents
;
3856 gvec
= XVECTOR (global_lface
)->contents
;
3857 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3858 if (IGNORE_DEFFACE_P (gvec
[i
]))
3859 lvec
[i
] = Qunspecified
;
3860 else if (! UNSPECIFIEDP (gvec
[i
]))
3863 /* If the default face was changed, update the face cache and the
3864 `font' frame parameter. */
3865 if (EQ (face
, Qdefault
))
3867 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
3868 struct face
*newface
, *oldface
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
3869 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
3871 /* This can be NULL (e.g., in batch mode). */
3874 /* Ensure that the face vector is fully specified by merging
3875 the previously-cached vector. */
3876 memcpy (attrs
, oldface
->lface
, sizeof attrs
);
3877 merge_face_vectors (f
, lvec
, attrs
, 0);
3878 memcpy (lvec
, attrs
, sizeof attrs
);
3879 newface
= realize_face (c
, lvec
, DEFAULT_FACE_ID
);
3881 if ((! UNSPECIFIEDP (gvec
[LFACE_FAMILY_INDEX
])
3882 || ! UNSPECIFIEDP (gvec
[LFACE_FOUNDRY_INDEX
])
3883 || ! UNSPECIFIEDP (gvec
[LFACE_HEIGHT_INDEX
])
3884 || ! UNSPECIFIEDP (gvec
[LFACE_WEIGHT_INDEX
])
3885 || ! UNSPECIFIEDP (gvec
[LFACE_SLANT_INDEX
])
3886 || ! UNSPECIFIEDP (gvec
[LFACE_SWIDTH_INDEX
])
3887 || ! UNSPECIFIEDP (gvec
[LFACE_FONT_INDEX
]))
3890 Lisp_Object name
= newface
->font
->props
[FONT_NAME_INDEX
];
3891 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, name
),
3901 /* The following function is implemented for compatibility with 20.2.
3902 The function is used in x-resolve-fonts when it is asked to
3903 return fonts with the same size as the font of a face. This is
3904 done in fontset.el. */
3906 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 3, 0,
3907 doc
: /* Return the font name of face FACE, or nil if it is unspecified.
3908 The font name is, by default, for ASCII characters.
3909 If the optional argument FRAME is given, report on face FACE in that frame.
3910 If FRAME is t, report on the defaults for face FACE (for new frames).
3911 The font default for a face is either nil, or a list
3912 of the form (bold), (italic) or (bold italic).
3913 If FRAME is omitted or nil, use the selected frame. And, in this case,
3914 if the optional third argument CHARACTER is given,
3915 return the font name used for CHARACTER. */)
3916 (Lisp_Object face
, Lisp_Object frame
, Lisp_Object character
)
3920 Lisp_Object result
= Qnil
;
3921 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
3923 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3924 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
3925 result
= Fcons (Qbold
, result
);
3927 if (!UNSPECIFIEDP (LFACE_SLANT (lface
))
3928 && !EQ (LFACE_SLANT (lface
), Qnormal
))
3929 result
= Fcons (Qitalic
, result
);
3935 struct frame
*f
= frame_or_selected_frame (frame
, 1);
3936 int face_id
= lookup_named_face (f
, face
, 1);
3937 struct face
*face
= FACE_FROM_ID (f
, face_id
);
3941 #ifdef HAVE_WINDOW_SYSTEM
3942 if (FRAME_WINDOW_P (f
) && !NILP (character
))
3944 CHECK_CHARACTER (character
);
3945 face_id
= FACE_FOR_CHAR (f
, face
, XINT (character
), -1, Qnil
);
3946 face
= FACE_FROM_ID (f
, face_id
);
3949 ? face
->font
->props
[FONT_NAME_INDEX
]
3951 #else /* !HAVE_WINDOW_SYSTEM */
3952 return build_string (FRAME_MSDOS_P (f
)
3954 : FRAME_W32_P (f
) ? "w32term"
3961 /* Compare face-attribute values v1 and v2 for equality. Value is non-zero if
3962 all attributes are `equal'. Tries to be fast because this function
3963 is called quite often. */
3966 face_attr_equal_p (Lisp_Object v1
, Lisp_Object v2
)
3968 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
3969 and the other is specified. */
3970 if (XTYPE (v1
) != XTYPE (v2
))
3979 if (SBYTES (v1
) != SBYTES (v2
))
3982 return memcmp (SDATA (v1
), SDATA (v2
), SBYTES (v1
)) == 0;
3989 return !NILP (Fequal (v1
, v2
));
3994 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
3995 all attributes are `equal'. Tries to be fast because this function
3996 is called quite often. */
3999 lface_equal_p (Lisp_Object
*v1
, Lisp_Object
*v2
)
4003 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
4004 equal_p
= face_attr_equal_p (v1
[i
], v2
[i
]);
4010 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
4011 Sinternal_lisp_face_equal_p
, 2, 3, 0,
4012 doc
: /* True if FACE1 and FACE2 are equal.
4013 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
4014 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
4015 If FRAME is omitted or nil, use the selected frame. */)
4016 (Lisp_Object face1
, Lisp_Object face2
, Lisp_Object frame
)
4020 Lisp_Object lface1
, lface2
;
4025 /* Don't use check_x_frame here because this function is called
4026 before X frames exist. At that time, if FRAME is nil,
4027 selected_frame will be used which is the frame dumped with
4028 Emacs. That frame is not an X frame. */
4029 f
= frame_or_selected_frame (frame
, 2);
4031 lface1
= lface_from_face_name (f
, face1
, 1);
4032 lface2
= lface_from_face_name (f
, face2
, 1);
4033 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
4034 XVECTOR (lface2
)->contents
);
4035 return equal_p
? Qt
: Qnil
;
4039 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
4040 Sinternal_lisp_face_empty_p
, 1, 2, 0,
4041 doc
: /* True if FACE has no attribute specified.
4042 If the optional argument FRAME is given, report on face FACE in that frame.
4043 If FRAME is t, report on the defaults for face FACE (for new frames).
4044 If FRAME is omitted or nil, use the selected frame. */)
4045 (Lisp_Object face
, Lisp_Object frame
)
4052 frame
= selected_frame
;
4053 CHECK_LIVE_FRAME (frame
);
4057 lface
= lface_from_face_name (NULL
, face
, 1);
4059 lface
= lface_from_face_name (f
, face
, 1);
4061 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4062 if (!UNSPECIFIEDP (AREF (lface
, i
)))
4065 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
4069 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
4071 doc
: /* Return an alist of frame-local faces defined on FRAME.
4072 For internal use only. */)
4075 struct frame
*f
= frame_or_selected_frame (frame
, 0);
4076 return f
->face_alist
;
4080 /* Return a hash code for Lisp string STRING with case ignored. Used
4081 below in computing a hash value for a Lisp face. */
4083 static INLINE
unsigned
4084 hash_string_case_insensitive (Lisp_Object string
)
4086 const unsigned char *s
;
4088 xassert (STRINGP (string
));
4089 for (s
= SDATA (string
); *s
; ++s
)
4090 hash
= (hash
<< 1) ^ tolower (*s
);
4095 /* Return a hash code for face attribute vector V. */
4097 static INLINE
unsigned
4098 lface_hash (Lisp_Object
*v
)
4100 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
4101 ^ hash_string_case_insensitive (v
[LFACE_FOUNDRY_INDEX
])
4102 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
4103 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
4104 ^ XHASH (v
[LFACE_WEIGHT_INDEX
])
4105 ^ XHASH (v
[LFACE_SLANT_INDEX
])
4106 ^ XHASH (v
[LFACE_SWIDTH_INDEX
])
4107 ^ XHASH (v
[LFACE_HEIGHT_INDEX
]));
4111 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
4112 considering charsets/registries). They do if they specify the same
4113 family, point size, weight, width, slant, and font. Both
4114 LFACE1 and LFACE2 must be fully-specified. */
4117 lface_same_font_attributes_p (Lisp_Object
*lface1
, Lisp_Object
*lface2
)
4119 xassert (lface_fully_specified_p (lface1
)
4120 && lface_fully_specified_p (lface2
));
4121 return (xstrcasecmp (SDATA (lface1
[LFACE_FAMILY_INDEX
]),
4122 SDATA (lface2
[LFACE_FAMILY_INDEX
])) == 0
4123 && xstrcasecmp (SDATA (lface1
[LFACE_FOUNDRY_INDEX
]),
4124 SDATA (lface2
[LFACE_FOUNDRY_INDEX
])) == 0
4125 && EQ (lface1
[LFACE_HEIGHT_INDEX
], lface2
[LFACE_HEIGHT_INDEX
])
4126 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
4127 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
4128 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
])
4129 && EQ (lface1
[LFACE_FONT_INDEX
], lface2
[LFACE_FONT_INDEX
])
4130 && (EQ (lface1
[LFACE_FONTSET_INDEX
], lface2
[LFACE_FONTSET_INDEX
])
4131 || (STRINGP (lface1
[LFACE_FONTSET_INDEX
])
4132 && STRINGP (lface2
[LFACE_FONTSET_INDEX
])
4133 && ! xstrcasecmp (SDATA (lface1
[LFACE_FONTSET_INDEX
]),
4134 SDATA (lface2
[LFACE_FONTSET_INDEX
]))))
4140 /***********************************************************************
4142 ***********************************************************************/
4144 /* Allocate and return a new realized face for Lisp face attribute
4147 static struct face
*
4148 make_realized_face (Lisp_Object
*attr
)
4150 struct face
*face
= (struct face
*) xmalloc (sizeof *face
);
4151 memset (face
, 0, sizeof *face
);
4152 face
->ascii_face
= face
;
4153 memcpy (face
->lface
, attr
, sizeof face
->lface
);
4158 /* Free realized face FACE, including its X resources. FACE may
4162 free_realized_face (struct frame
*f
, struct face
*face
)
4166 #ifdef HAVE_WINDOW_SYSTEM
4167 if (FRAME_WINDOW_P (f
))
4169 /* Free fontset of FACE if it is ASCII face. */
4170 if (face
->fontset
>= 0 && face
== face
->ascii_face
)
4171 free_face_fontset (f
, face
);
4176 font_done_for_face (f
, face
);
4177 x_free_gc (f
, face
->gc
);
4182 free_face_colors (f
, face
);
4183 x_destroy_bitmap (f
, face
->stipple
);
4185 #endif /* HAVE_WINDOW_SYSTEM */
4192 /* Prepare face FACE for subsequent display on frame F. This
4193 allocated GCs if they haven't been allocated yet or have been freed
4194 by clearing the face cache. */
4197 prepare_face_for_display (struct frame
*f
, struct face
*face
)
4199 #ifdef HAVE_WINDOW_SYSTEM
4200 xassert (FRAME_WINDOW_P (f
));
4205 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
4207 xgcv
.foreground
= face
->foreground
;
4208 xgcv
.background
= face
->background
;
4209 #ifdef HAVE_X_WINDOWS
4210 xgcv
.graphics_exposures
= False
;
4214 #ifdef HAVE_X_WINDOWS
4217 xgcv
.fill_style
= FillOpaqueStippled
;
4218 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
4219 mask
|= GCFillStyle
| GCStipple
;
4222 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
4224 font_prepare_for_face (f
, face
);
4227 #endif /* HAVE_WINDOW_SYSTEM */
4231 /* Returns the `distance' between the colors X and Y. */
4234 color_distance (XColor
*x
, XColor
*y
)
4236 /* This formula is from a paper title `Colour metric' by Thiadmer Riemersma.
4237 Quoting from that paper:
4239 This formula has results that are very close to L*u*v* (with the
4240 modified lightness curve) and, more importantly, it is a more even
4241 algorithm: it does not have a range of colours where it suddenly
4242 gives far from optimal results.
4244 See <http://www.compuphase.com/cmetric.htm> for more info. */
4246 long r
= (x
->red
- y
->red
) >> 8;
4247 long g
= (x
->green
- y
->green
) >> 8;
4248 long b
= (x
->blue
- y
->blue
) >> 8;
4249 long r_mean
= (x
->red
+ y
->red
) >> 9;
4252 (((512 + r_mean
) * r
* r
) >> 8)
4254 + (((767 - r_mean
) * b
* b
) >> 8);
4258 DEFUN ("color-distance", Fcolor_distance
, Scolor_distance
, 2, 3, 0,
4259 doc
: /* Return an integer distance between COLOR1 and COLOR2 on FRAME.
4260 COLOR1 and COLOR2 may be either strings containing the color name,
4261 or lists of the form (RED GREEN BLUE).
4262 If FRAME is unspecified or nil, the current frame is used. */)
4263 (Lisp_Object color1
, Lisp_Object color2
, Lisp_Object frame
)
4266 XColor cdef1
, cdef2
;
4269 frame
= selected_frame
;
4270 CHECK_LIVE_FRAME (frame
);
4273 if (!(CONSP (color1
) && parse_rgb_list (color1
, &cdef1
))
4274 && !(STRINGP (color1
) && defined_color (f
, SDATA (color1
), &cdef1
, 0)))
4275 signal_error ("Invalid color", color1
);
4276 if (!(CONSP (color2
) && parse_rgb_list (color2
, &cdef2
))
4277 && !(STRINGP (color2
) && defined_color (f
, SDATA (color2
), &cdef2
, 0)))
4278 signal_error ("Invalid color", color2
);
4280 return make_number (color_distance (&cdef1
, &cdef2
));
4284 /***********************************************************************
4286 ***********************************************************************/
4288 /* Return a new face cache for frame F. */
4290 static struct face_cache
*
4291 make_face_cache (struct frame
*f
)
4293 struct face_cache
*c
;
4296 c
= (struct face_cache
*) xmalloc (sizeof *c
);
4297 memset (c
, 0, sizeof *c
);
4298 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4299 c
->buckets
= (struct face
**) xmalloc (size
);
4300 memset (c
->buckets
, 0, size
);
4302 c
->faces_by_id
= (struct face
**) xmalloc (c
->size
* sizeof *c
->faces_by_id
);
4304 c
->menu_face_changed_p
= menu_face_changed_default
;
4309 /* Clear out all graphics contexts for all realized faces, except for
4310 the basic faces. This should be done from time to time just to avoid
4311 keeping too many graphics contexts that are no longer needed. */
4314 clear_face_gcs (struct face_cache
*c
)
4316 if (c
&& FRAME_WINDOW_P (c
->f
))
4318 #ifdef HAVE_WINDOW_SYSTEM
4320 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
4322 struct face
*face
= c
->faces_by_id
[i
];
4323 if (face
&& face
->gc
)
4327 font_done_for_face (c
->f
, face
);
4328 x_free_gc (c
->f
, face
->gc
);
4333 #endif /* HAVE_WINDOW_SYSTEM */
4338 /* Free all realized faces in face cache C, including basic faces.
4339 C may be null. If faces are freed, make sure the frame's current
4340 matrix is marked invalid, so that a display caused by an expose
4341 event doesn't try to use faces we destroyed. */
4344 free_realized_faces (struct face_cache
*c
)
4349 struct frame
*f
= c
->f
;
4351 /* We must block input here because we can't process X events
4352 safely while only some faces are freed, or when the frame's
4353 current matrix still references freed faces. */
4356 for (i
= 0; i
< c
->used
; ++i
)
4358 free_realized_face (f
, c
->faces_by_id
[i
]);
4359 c
->faces_by_id
[i
] = NULL
;
4363 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4364 memset (c
->buckets
, 0, size
);
4366 /* Must do a thorough redisplay the next time. Mark current
4367 matrices as invalid because they will reference faces freed
4368 above. This function is also called when a frame is
4369 destroyed. In this case, the root window of F is nil. */
4370 if (WINDOWP (f
->root_window
))
4372 clear_current_matrices (f
);
4373 ++windows_or_buffers_changed
;
4381 /* Free all realized faces that are using FONTSET on frame F. */
4384 free_realized_faces_for_fontset (struct frame
*f
, int fontset
)
4386 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4390 /* We must block input here because we can't process X events safely
4391 while only some faces are freed, or when the frame's current
4392 matrix still references freed faces. */
4395 for (i
= 0; i
< cache
->used
; i
++)
4397 face
= cache
->faces_by_id
[i
];
4399 && face
->fontset
== fontset
)
4401 uncache_face (cache
, face
);
4402 free_realized_face (f
, face
);
4406 /* Must do a thorough redisplay the next time. Mark current
4407 matrices as invalid because they will reference faces freed
4408 above. This function is also called when a frame is destroyed.
4409 In this case, the root window of F is nil. */
4410 if (WINDOWP (f
->root_window
))
4412 clear_current_matrices (f
);
4413 ++windows_or_buffers_changed
;
4420 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
4421 This is done after attributes of a named face have been changed,
4422 because we can't tell which realized faces depend on that face. */
4425 free_all_realized_faces (Lisp_Object frame
)
4430 FOR_EACH_FRAME (rest
, frame
)
4431 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4434 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4438 /* Free face cache C and faces in it, including their X resources. */
4441 free_face_cache (struct face_cache
*c
)
4445 free_realized_faces (c
);
4447 xfree (c
->faces_by_id
);
4453 /* Cache realized face FACE in face cache C. HASH is the hash value
4454 of FACE. If FACE is for ASCII characters (i.e. FACE->ascii_face ==
4455 FACE), insert the new face to the beginning of the collision list
4456 of the face hash table of C. Otherwise, add the new face to the
4457 end of the collision list. This way, lookup_face can quickly find
4458 that a requested face is not cached. */
4461 cache_face (struct face_cache
*c
, struct face
*face
, unsigned int hash
)
4463 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4467 if (face
->ascii_face
!= face
)
4469 struct face
*last
= c
->buckets
[i
];
4480 c
->buckets
[i
] = face
;
4481 face
->prev
= face
->next
= NULL
;
4487 face
->next
= c
->buckets
[i
];
4489 face
->next
->prev
= face
;
4490 c
->buckets
[i
] = face
;
4493 /* Find a free slot in C->faces_by_id and use the index of the free
4494 slot as FACE->id. */
4495 for (i
= 0; i
< c
->used
; ++i
)
4496 if (c
->faces_by_id
[i
] == NULL
)
4500 /* Maybe enlarge C->faces_by_id. */
4503 if (c
->used
== c
->size
)
4506 new_size
= min (2 * c
->size
, MAX_FACE_ID
);
4507 if (new_size
== c
->size
)
4508 abort (); /* Alternatives? ++kfs */
4509 sz
= new_size
* sizeof *c
->faces_by_id
;
4510 c
->faces_by_id
= (struct face
**) xrealloc (c
->faces_by_id
, sz
);
4517 /* Check that FACE got a unique id. */
4522 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
4523 for (face
= c
->buckets
[j
]; face
; face
= face
->next
)
4529 #endif /* GLYPH_DEBUG */
4531 c
->faces_by_id
[i
] = face
;
4535 /* Remove face FACE from cache C. */
4538 uncache_face (struct face_cache
*c
, struct face
*face
)
4540 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
4543 face
->prev
->next
= face
->next
;
4545 c
->buckets
[i
] = face
->next
;
4548 face
->next
->prev
= face
->prev
;
4550 c
->faces_by_id
[face
->id
] = NULL
;
4551 if (face
->id
== c
->used
)
4556 /* Look up a realized face with face attributes ATTR in the face cache
4557 of frame F. The face will be used to display ASCII characters.
4558 Value is the ID of the face found. If no suitable face is found,
4559 realize a new one. */
4562 lookup_face (struct frame
*f
, Lisp_Object
*attr
)
4564 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4569 xassert (cache
!= NULL
);
4570 check_lface_attrs (attr
);
4572 /* Look up ATTR in the face cache. */
4573 hash
= lface_hash (attr
);
4574 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4576 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4578 if (face
->ascii_face
!= face
)
4580 /* There's no more ASCII face. */
4584 if (face
->hash
== hash
4585 && lface_equal_p (face
->lface
, attr
))
4589 /* If not found, realize a new face. */
4591 face
= realize_face (cache
, attr
, -1);
4594 xassert (face
== FACE_FROM_ID (f
, face
->id
));
4595 #endif /* GLYPH_DEBUG */
4600 #ifdef HAVE_WINDOW_SYSTEM
4601 /* Look up a realized face that has the same attributes as BASE_FACE
4602 except for the font in the face cache of frame F. If FONT-OBJECT
4603 is not nil, it is an already opened font. If FONT-OBJECT is nil,
4604 the face has no font. Value is the ID of the face found. If no
4605 suitable face is found, realize a new one. */
4608 face_for_font (struct frame
*f
, Lisp_Object font_object
, struct face
*base_face
)
4610 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4615 xassert (cache
!= NULL
);
4616 base_face
= base_face
->ascii_face
;
4617 hash
= lface_hash (base_face
->lface
);
4618 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4620 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4622 if (face
->ascii_face
== face
)
4624 if (face
->ascii_face
== base_face
4625 && face
->font
== (NILP (font_object
) ? NULL
4626 : XFONT_OBJECT (font_object
))
4627 && lface_equal_p (face
->lface
, base_face
->lface
))
4631 /* If not found, realize a new face. */
4632 face
= realize_non_ascii_face (f
, font_object
, base_face
);
4635 #endif /* HAVE_WINDOW_SYSTEM */
4637 /* Return the face id of the realized face for named face SYMBOL on
4638 frame F suitable for displaying ASCII characters. Value is -1 if
4639 the face couldn't be determined, which might happen if the default
4640 face isn't realized and cannot be realized. */
4643 lookup_named_face (struct frame
*f
, Lisp_Object symbol
, int signal_p
)
4645 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4646 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4647 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4649 if (default_face
== NULL
)
4651 if (!realize_basic_faces (f
))
4653 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4654 if (default_face
== NULL
)
4655 abort (); /* realize_basic_faces must have set it up */
4658 if (! get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4661 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4662 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4664 return lookup_face (f
, attrs
);
4668 /* Return the display face-id of the basic face who's canonical face-id
4669 is FACE_ID. The return value will usually simply be FACE_ID, unless that
4670 basic face has bee remapped via Vface_remapping_alist. This function is
4671 conservative: if something goes wrong, it will simply return FACE_ID
4672 rather than signal an error. */
4675 lookup_basic_face (struct frame
*f
, int face_id
)
4677 Lisp_Object name
, mapping
;
4678 int remapped_face_id
;
4680 if (NILP (Vface_remapping_alist
))
4681 return face_id
; /* Nothing to do. */
4685 case DEFAULT_FACE_ID
: name
= Qdefault
; break;
4686 case MODE_LINE_FACE_ID
: name
= Qmode_line
; break;
4687 case MODE_LINE_INACTIVE_FACE_ID
: name
= Qmode_line_inactive
; break;
4688 case HEADER_LINE_FACE_ID
: name
= Qheader_line
; break;
4689 case TOOL_BAR_FACE_ID
: name
= Qtool_bar
; break;
4690 case FRINGE_FACE_ID
: name
= Qfringe
; break;
4691 case SCROLL_BAR_FACE_ID
: name
= Qscroll_bar
; break;
4692 case BORDER_FACE_ID
: name
= Qborder
; break;
4693 case CURSOR_FACE_ID
: name
= Qcursor
; break;
4694 case MOUSE_FACE_ID
: name
= Qmouse
; break;
4695 case MENU_FACE_ID
: name
= Qmenu
; break;
4698 abort (); /* the caller is supposed to pass us a basic face id */
4701 /* Do a quick scan through Vface_remapping_alist, and return immediately
4702 if there is no remapping for face NAME. This is just an optimization
4703 for the very common no-remapping case. */
4704 mapping
= assq_no_quit (name
, Vface_remapping_alist
);
4706 return face_id
; /* Give up. */
4708 /* If there is a remapping entry, lookup the face using NAME, which will
4709 handle the remapping too. */
4710 remapped_face_id
= lookup_named_face (f
, name
, 0);
4711 if (remapped_face_id
< 0)
4712 return face_id
; /* Give up. */
4714 return remapped_face_id
;
4718 /* Return the ID of the realized ASCII face of Lisp face with ID
4719 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
4722 ascii_face_of_lisp_face (struct frame
*f
, int lface_id
)
4726 if (lface_id
>= 0 && lface_id
< lface_id_to_name_size
)
4728 Lisp_Object face_name
= lface_id_to_name
[lface_id
];
4729 face_id
= lookup_named_face (f
, face_name
, 1);
4738 /* Return a face for charset ASCII that is like the face with id
4739 FACE_ID on frame F, but has a font that is STEPS steps smaller.
4740 STEPS < 0 means larger. Value is the id of the face. */
4743 smaller_face (struct frame
*f
, int face_id
, int steps
)
4745 #ifdef HAVE_WINDOW_SYSTEM
4747 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4748 int pt
, last_pt
, last_height
;
4751 struct face
*new_face
;
4753 /* If not called for an X frame, just return the original face. */
4754 if (FRAME_TERMCAP_P (f
))
4757 /* Try in increments of 1/2 pt. */
4758 delta
= steps
< 0 ? 5 : -5;
4759 steps
= eabs (steps
);
4761 face
= FACE_FROM_ID (f
, face_id
);
4762 memcpy (attrs
, face
->lface
, sizeof attrs
);
4763 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
4764 new_face_id
= face_id
;
4765 last_height
= FONT_HEIGHT (face
->font
);
4769 /* Give up if we cannot find a font within 10pt. */
4770 && eabs (last_pt
- pt
) < 100)
4772 /* Look up a face for a slightly smaller/larger font. */
4774 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
4775 new_face_id
= lookup_face (f
, attrs
);
4776 new_face
= FACE_FROM_ID (f
, new_face_id
);
4778 /* If height changes, count that as one step. */
4779 if ((delta
< 0 && FONT_HEIGHT (new_face
->font
) < last_height
)
4780 || (delta
> 0 && FONT_HEIGHT (new_face
->font
) > last_height
))
4783 last_height
= FONT_HEIGHT (new_face
->font
);
4790 #else /* not HAVE_WINDOW_SYSTEM */
4794 #endif /* not HAVE_WINDOW_SYSTEM */
4798 /* Return a face for charset ASCII that is like the face with id
4799 FACE_ID on frame F, but has height HEIGHT. */
4802 face_with_height (struct frame
*f
, int face_id
, int height
)
4804 #ifdef HAVE_WINDOW_SYSTEM
4806 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4808 if (FRAME_TERMCAP_P (f
)
4812 face
= FACE_FROM_ID (f
, face_id
);
4813 memcpy (attrs
, face
->lface
, sizeof attrs
);
4814 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
4815 font_clear_prop (attrs
, FONT_SIZE_INDEX
);
4816 face_id
= lookup_face (f
, attrs
);
4817 #endif /* HAVE_WINDOW_SYSTEM */
4823 /* Return the face id of the realized face for named face SYMBOL on
4824 frame F suitable for displaying ASCII characters, and use
4825 attributes of the face FACE_ID for attributes that aren't
4826 completely specified by SYMBOL. This is like lookup_named_face,
4827 except that the default attributes come from FACE_ID, not from the
4828 default face. FACE_ID is assumed to be already realized. */
4831 lookup_derived_face (struct frame
*f
, Lisp_Object symbol
, int face_id
, int signal_p
)
4833 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4834 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4835 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
4840 if (!get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4843 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
4844 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4845 return lookup_face (f
, attrs
);
4848 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector
,
4849 Sface_attributes_as_vector
, 1, 1, 0,
4850 doc
: /* Return a vector of face attributes corresponding to PLIST. */)
4854 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
4856 merge_face_ref (XFRAME (selected_frame
), plist
, XVECTOR (lface
)->contents
,
4863 /***********************************************************************
4864 Face capability testing
4865 ***********************************************************************/
4868 /* If the distance (as returned by color_distance) between two colors is
4869 less than this, then they are considered the same, for determining
4870 whether a color is supported or not. The range of values is 0-65535. */
4872 #define TTY_SAME_COLOR_THRESHOLD 10000
4874 #ifdef HAVE_WINDOW_SYSTEM
4876 /* Return non-zero if all the face attributes in ATTRS are supported
4877 on the window-system frame F.
4879 The definition of `supported' is somewhat heuristic, but basically means
4880 that a face containing all the attributes in ATTRS, when merged with the
4881 default face for display, can be represented in a way that's
4883 \(1) different in appearance than the default face, and
4884 \(2) `close in spirit' to what the attributes specify, if not exact. */
4887 x_supports_face_attributes_p (struct frame
*f
, Lisp_Object
*attrs
, struct face
*def_face
)
4889 Lisp_Object
*def_attrs
= def_face
->lface
;
4891 /* Check that other specified attributes are different that the default
4893 if ((!UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
4894 && face_attr_equal_p (attrs
[LFACE_UNDERLINE_INDEX
],
4895 def_attrs
[LFACE_UNDERLINE_INDEX
]))
4896 || (!UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
4897 && face_attr_equal_p (attrs
[LFACE_INVERSE_INDEX
],
4898 def_attrs
[LFACE_INVERSE_INDEX
]))
4899 || (!UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
4900 && face_attr_equal_p (attrs
[LFACE_FOREGROUND_INDEX
],
4901 def_attrs
[LFACE_FOREGROUND_INDEX
]))
4902 || (!UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
4903 && face_attr_equal_p (attrs
[LFACE_BACKGROUND_INDEX
],
4904 def_attrs
[LFACE_BACKGROUND_INDEX
]))
4905 || (!UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
4906 && face_attr_equal_p (attrs
[LFACE_STIPPLE_INDEX
],
4907 def_attrs
[LFACE_STIPPLE_INDEX
]))
4908 || (!UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
4909 && face_attr_equal_p (attrs
[LFACE_OVERLINE_INDEX
],
4910 def_attrs
[LFACE_OVERLINE_INDEX
]))
4911 || (!UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
4912 && face_attr_equal_p (attrs
[LFACE_STRIKE_THROUGH_INDEX
],
4913 def_attrs
[LFACE_STRIKE_THROUGH_INDEX
]))
4914 || (!UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
4915 && face_attr_equal_p (attrs
[LFACE_BOX_INDEX
],
4916 def_attrs
[LFACE_BOX_INDEX
])))
4919 /* Check font-related attributes, as those are the most commonly
4920 "unsupported" on a window-system (because of missing fonts). */
4921 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
4922 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
4923 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
4924 || !UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
4925 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
4926 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
]))
4930 Lisp_Object merged_attrs
[LFACE_VECTOR_SIZE
];
4933 memcpy (merged_attrs
, def_attrs
, sizeof merged_attrs
);
4935 merge_face_vectors (f
, attrs
, merged_attrs
, 0);
4937 face_id
= lookup_face (f
, merged_attrs
);
4938 face
= FACE_FROM_ID (f
, face_id
);
4941 error ("Cannot make face");
4943 /* If the font is the same, or no font is found, then not
4945 if (face
->font
== def_face
->font
4948 for (i
= FONT_TYPE_INDEX
; i
<= FONT_SIZE_INDEX
; i
++)
4949 if (! EQ (face
->font
->props
[i
], def_face
->font
->props
[i
]))
4953 if (i
< FONT_FOUNDRY_INDEX
|| i
> FONT_REGISTRY_INDEX
4954 || face
->font
->driver
->case_sensitive
)
4956 s1
= SYMBOL_NAME (face
->font
->props
[i
]);
4957 s2
= SYMBOL_NAME (def_face
->font
->props
[i
]);
4958 if (! EQ (Fcompare_strings (s1
, make_number (0), Qnil
,
4959 s2
, make_number (0), Qnil
, Qt
), Qt
))
4965 /* Everything checks out, this face is supported. */
4969 #endif /* HAVE_WINDOW_SYSTEM */
4971 /* Return non-zero if all the face attributes in ATTRS are supported
4974 The definition of `supported' is somewhat heuristic, but basically means
4975 that a face containing all the attributes in ATTRS, when merged
4976 with the default face for display, can be represented in a way that's
4978 \(1) different in appearance than the default face, and
4979 \(2) `close in spirit' to what the attributes specify, if not exact.
4981 Point (2) implies that a `:weight black' attribute will be satisfied
4982 by any terminal that can display bold, and a `:foreground "yellow"' as
4983 long as the terminal can display a yellowish color, but `:slant italic'
4984 will _not_ be satisfied by the tty display code's automatic
4985 substitution of a `dim' face for italic. */
4988 tty_supports_face_attributes_p (struct frame
*f
, Lisp_Object
*attrs
, struct face
*def_face
)
4991 Lisp_Object val
, fg
, bg
;
4992 XColor fg_tty_color
, fg_std_color
;
4993 XColor bg_tty_color
, bg_std_color
;
4994 unsigned test_caps
= 0;
4995 Lisp_Object
*def_attrs
= def_face
->lface
;
4998 /* First check some easy-to-check stuff; ttys support none of the
4999 following attributes, so we can just return false if any are requested
5000 (even if `nominal' values are specified, we should still return false,
5001 as that will be the same value that the default face uses). We
5002 consider :slant unsupportable on ttys, even though the face code
5003 actually `fakes' them using a dim attribute if possible. This is
5004 because the faked result is too different from what the face
5006 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
5007 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
5008 || !UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
5009 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
5010 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
5011 || !UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
5012 || !UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
5013 || !UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
5014 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
]))
5018 /* Test for terminal `capabilities' (non-color character attributes). */
5020 /* font weight (bold/dim) */
5021 val
= attrs
[LFACE_WEIGHT_INDEX
];
5022 if (!UNSPECIFIEDP (val
)
5023 && (weight
= FONT_WEIGHT_NAME_NUMERIC (val
), weight
>= 0))
5025 int def_weight
= FONT_WEIGHT_NAME_NUMERIC (def_attrs
[LFACE_WEIGHT_INDEX
]);
5029 if (def_weight
> 100)
5030 return 0; /* same as default */
5031 test_caps
= TTY_CAP_BOLD
;
5033 else if (weight
< 100)
5035 if (def_weight
< 100)
5036 return 0; /* same as default */
5037 test_caps
= TTY_CAP_DIM
;
5039 else if (def_weight
== 100)
5040 return 0; /* same as default */
5044 val
= attrs
[LFACE_UNDERLINE_INDEX
];
5045 if (!UNSPECIFIEDP (val
))
5048 return 0; /* ttys can't use colored underlines */
5049 else if (face_attr_equal_p (val
, def_attrs
[LFACE_UNDERLINE_INDEX
]))
5050 return 0; /* same as default */
5052 test_caps
|= TTY_CAP_UNDERLINE
;
5056 val
= attrs
[LFACE_INVERSE_INDEX
];
5057 if (!UNSPECIFIEDP (val
))
5059 if (face_attr_equal_p (val
, def_attrs
[LFACE_INVERSE_INDEX
]))
5060 return 0; /* same as default */
5062 test_caps
|= TTY_CAP_INVERSE
;
5066 /* Color testing. */
5068 /* Default the color indices in FG_TTY_COLOR and BG_TTY_COLOR, since
5069 we use them when calling `tty_capable_p' below, even if the face
5070 specifies no colors. */
5071 fg_tty_color
.pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5072 bg_tty_color
.pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5074 /* Check if foreground color is close enough. */
5075 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
5078 Lisp_Object def_fg
= def_attrs
[LFACE_FOREGROUND_INDEX
];
5080 if (face_attr_equal_p (fg
, def_fg
))
5081 return 0; /* same as default */
5082 else if (! tty_lookup_color (f
, fg
, &fg_tty_color
, &fg_std_color
))
5083 return 0; /* not a valid color */
5084 else if (color_distance (&fg_tty_color
, &fg_std_color
)
5085 > TTY_SAME_COLOR_THRESHOLD
)
5086 return 0; /* displayed color is too different */
5088 /* Make sure the color is really different than the default. */
5090 XColor def_fg_color
;
5091 if (tty_lookup_color (f
, def_fg
, &def_fg_color
, 0)
5092 && (color_distance (&fg_tty_color
, &def_fg_color
)
5093 <= TTY_SAME_COLOR_THRESHOLD
))
5098 /* Check if background color is close enough. */
5099 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
5102 Lisp_Object def_bg
= def_attrs
[LFACE_BACKGROUND_INDEX
];
5104 if (face_attr_equal_p (bg
, def_bg
))
5105 return 0; /* same as default */
5106 else if (! tty_lookup_color (f
, bg
, &bg_tty_color
, &bg_std_color
))
5107 return 0; /* not a valid color */
5108 else if (color_distance (&bg_tty_color
, &bg_std_color
)
5109 > TTY_SAME_COLOR_THRESHOLD
)
5110 return 0; /* displayed color is too different */
5112 /* Make sure the color is really different than the default. */
5114 XColor def_bg_color
;
5115 if (tty_lookup_color (f
, def_bg
, &def_bg_color
, 0)
5116 && (color_distance (&bg_tty_color
, &def_bg_color
)
5117 <= TTY_SAME_COLOR_THRESHOLD
))
5122 /* If both foreground and background are requested, see if the
5123 distance between them is OK. We just check to see if the distance
5124 between the tty's foreground and background is close enough to the
5125 distance between the standard foreground and background. */
5126 if (STRINGP (fg
) && STRINGP (bg
))
5129 = (color_distance (&fg_std_color
, &bg_std_color
)
5130 - color_distance (&fg_tty_color
, &bg_tty_color
));
5131 if (delta_delta
> TTY_SAME_COLOR_THRESHOLD
5132 || delta_delta
< -TTY_SAME_COLOR_THRESHOLD
)
5137 /* See if the capabilities we selected above are supported, with the
5139 if (test_caps
!= 0 &&
5140 ! tty_capable_p (FRAME_TTY (f
), test_caps
, fg_tty_color
.pixel
, bg_tty_color
.pixel
))
5144 /* Hmmm, everything checks out, this terminal must support this face. */
5149 DEFUN ("display-supports-face-attributes-p",
5150 Fdisplay_supports_face_attributes_p
, Sdisplay_supports_face_attributes_p
,
5152 doc
: /* Return non-nil if all the face attributes in ATTRIBUTES are supported.
5153 The optional argument DISPLAY can be a display name, a frame, or
5154 nil (meaning the selected frame's display).
5156 The definition of `supported' is somewhat heuristic, but basically means
5157 that a face containing all the attributes in ATTRIBUTES, when merged
5158 with the default face for display, can be represented in a way that's
5160 \(1) different in appearance than the default face, and
5161 \(2) `close in spirit' to what the attributes specify, if not exact.
5163 Point (2) implies that a `:weight black' attribute will be satisfied by
5164 any display that can display bold, and a `:foreground \"yellow\"' as long
5165 as it can display a yellowish color, but `:slant italic' will _not_ be
5166 satisfied by the tty display code's automatic substitution of a `dim'
5167 face for italic. */)
5168 (Lisp_Object attributes
, Lisp_Object display
)
5170 int supports
= 0, i
;
5173 struct face
*def_face
;
5174 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5176 if (noninteractive
|| !initialized
)
5177 /* We may not be able to access low-level face information in batch
5178 mode, or before being dumped, and this function is not going to
5179 be very useful in those cases anyway, so just give up. */
5183 frame
= selected_frame
;
5184 else if (FRAMEP (display
))
5188 /* Find any frame on DISPLAY. */
5189 Lisp_Object fl_tail
;
5192 for (fl_tail
= Vframe_list
; CONSP (fl_tail
); fl_tail
= XCDR (fl_tail
))
5194 frame
= XCAR (fl_tail
);
5195 if (!NILP (Fequal (Fcdr (Fassq (Qdisplay
,
5196 XFRAME (frame
)->param_alist
)),
5202 CHECK_LIVE_FRAME (frame
);
5205 for (i
= 0; i
< LFACE_VECTOR_SIZE
; i
++)
5206 attrs
[i
] = Qunspecified
;
5207 merge_face_ref (f
, attributes
, attrs
, 1, 0);
5209 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5210 if (def_face
== NULL
)
5212 if (! realize_basic_faces (f
))
5213 error ("Cannot realize default face");
5214 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5215 if (def_face
== NULL
)
5216 abort (); /* realize_basic_faces must have set it up */
5219 /* Dispatch to the appropriate handler. */
5220 if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5221 supports
= tty_supports_face_attributes_p (f
, attrs
, def_face
);
5222 #ifdef HAVE_WINDOW_SYSTEM
5224 supports
= x_supports_face_attributes_p (f
, attrs
, def_face
);
5227 return supports
? Qt
: Qnil
;
5231 /***********************************************************************
5233 ***********************************************************************/
5235 DEFUN ("internal-set-font-selection-order",
5236 Finternal_set_font_selection_order
,
5237 Sinternal_set_font_selection_order
, 1, 1, 0,
5238 doc
: /* Set font selection order for face font selection to ORDER.
5239 ORDER must be a list of length 4 containing the symbols `:width',
5240 `:height', `:weight', and `:slant'. Face attributes appearing
5241 first in ORDER are matched first, e.g. if `:height' appears before
5242 `:weight' in ORDER, font selection first tries to find a font with
5243 a suitable height, and then tries to match the font weight.
5249 int indices
[DIM (font_sort_order
)];
5252 memset (indices
, 0, sizeof indices
);
5256 CONSP (list
) && i
< DIM (indices
);
5257 list
= XCDR (list
), ++i
)
5259 Lisp_Object attr
= XCAR (list
);
5262 if (EQ (attr
, QCwidth
))
5264 else if (EQ (attr
, QCheight
))
5265 xlfd
= XLFD_POINT_SIZE
;
5266 else if (EQ (attr
, QCweight
))
5268 else if (EQ (attr
, QCslant
))
5273 if (indices
[i
] != 0)
5278 if (!NILP (list
) || i
!= DIM (indices
))
5279 signal_error ("Invalid font sort order", order
);
5280 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5281 if (indices
[i
] == 0)
5282 signal_error ("Invalid font sort order", order
);
5284 if (memcmp (indices
, font_sort_order
, sizeof indices
) != 0)
5286 memcpy (font_sort_order
, indices
, sizeof font_sort_order
);
5287 free_all_realized_faces (Qnil
);
5290 font_update_sort_order (font_sort_order
);
5296 DEFUN ("internal-set-alternative-font-family-alist",
5297 Finternal_set_alternative_font_family_alist
,
5298 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
5299 doc
: /* Define alternative font families to try in face font selection.
5300 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5301 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
5302 be found. Value is ALIST. */)
5305 Lisp_Object entry
, tail
, tail2
;
5308 alist
= Fcopy_sequence (alist
);
5309 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5311 entry
= XCAR (tail
);
5313 entry
= Fcopy_sequence (entry
);
5314 XSETCAR (tail
, entry
);
5315 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5316 XSETCAR (tail2
, Fintern (XCAR (tail2
), Qnil
));
5319 Vface_alternative_font_family_alist
= alist
;
5320 free_all_realized_faces (Qnil
);
5325 DEFUN ("internal-set-alternative-font-registry-alist",
5326 Finternal_set_alternative_font_registry_alist
,
5327 Sinternal_set_alternative_font_registry_alist
, 1, 1, 0,
5328 doc
: /* Define alternative font registries to try in face font selection.
5329 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5330 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
5331 be found. Value is ALIST. */)
5334 Lisp_Object entry
, tail
, tail2
;
5337 alist
= Fcopy_sequence (alist
);
5338 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5340 entry
= XCAR (tail
);
5342 entry
= Fcopy_sequence (entry
);
5343 XSETCAR (tail
, entry
);
5344 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5345 XSETCAR (tail2
, Fdowncase (XCAR (tail2
)));
5347 Vface_alternative_font_registry_alist
= alist
;
5348 free_all_realized_faces (Qnil
);
5353 #ifdef HAVE_WINDOW_SYSTEM
5355 /* Ignore the difference of font point size less than this value. */
5357 #define FONT_POINT_SIZE_QUANTUM 5
5359 /* Return the fontset id of the base fontset name or alias name given
5360 by the fontset attribute of ATTRS. Value is -1 if the fontset
5361 attribute of ATTRS doesn't name a fontset. */
5364 face_fontset (Lisp_Object
*attrs
)
5368 name
= attrs
[LFACE_FONTSET_INDEX
];
5369 if (!STRINGP (name
))
5371 return fs_query_fontset (name
, 0);
5374 #endif /* HAVE_WINDOW_SYSTEM */
5378 /***********************************************************************
5380 ***********************************************************************/
5382 /* Realize basic faces on frame F. Value is zero if frame parameters
5383 of F don't contain enough information needed to realize the default
5387 realize_basic_faces (struct frame
*f
)
5390 int count
= SPECPDL_INDEX ();
5392 /* Block input here so that we won't be surprised by an X expose
5393 event, for instance, without having the faces set up. */
5395 specbind (Qscalable_fonts_allowed
, Qt
);
5397 if (realize_default_face (f
))
5399 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
5400 realize_named_face (f
, Qmode_line_inactive
, MODE_LINE_INACTIVE_FACE_ID
);
5401 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
5402 realize_named_face (f
, Qfringe
, FRINGE_FACE_ID
);
5403 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
5404 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
5405 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
5406 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
5407 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
5408 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
5409 realize_named_face (f
, Qvertical_border
, VERTICAL_BORDER_FACE_ID
);
5411 /* Reflect changes in the `menu' face in menu bars. */
5412 if (FRAME_FACE_CACHE (f
)->menu_face_changed_p
)
5414 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 0;
5415 #ifdef USE_X_TOOLKIT
5416 if (FRAME_WINDOW_P (f
))
5417 x_update_menu_appearance (f
);
5424 unbind_to (count
, Qnil
);
5430 /* Realize the default face on frame F. If the face is not fully
5431 specified, make it fully-specified. Attributes of the default face
5432 that are not explicitly specified are taken from frame parameters. */
5435 realize_default_face (struct frame
*f
)
5437 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5439 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5442 /* If the `default' face is not yet known, create it. */
5443 lface
= lface_from_face_name (f
, Qdefault
, 0);
5447 XSETFRAME (frame
, f
);
5448 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
5451 #ifdef HAVE_WINDOW_SYSTEM
5452 if (FRAME_WINDOW_P (f
))
5454 Lisp_Object font_object
;
5456 XSETFONT (font_object
, FRAME_FONT (f
));
5457 set_lface_from_font (f
, lface
, font_object
, f
->default_face_done_p
);
5458 LFACE_FONTSET (lface
) = fontset_name (FRAME_FONTSET (f
));
5459 f
->default_face_done_p
= 1;
5461 #endif /* HAVE_WINDOW_SYSTEM */
5463 if (!FRAME_WINDOW_P (f
))
5465 LFACE_FAMILY (lface
) = build_string ("default");
5466 LFACE_FOUNDRY (lface
) = LFACE_FAMILY (lface
);
5467 LFACE_SWIDTH (lface
) = Qnormal
;
5468 LFACE_HEIGHT (lface
) = make_number (1);
5469 if (UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
5470 LFACE_WEIGHT (lface
) = Qnormal
;
5471 if (UNSPECIFIEDP (LFACE_SLANT (lface
)))
5472 LFACE_SLANT (lface
) = Qnormal
;
5473 if (UNSPECIFIEDP (LFACE_FONTSET (lface
)))
5474 LFACE_FONTSET (lface
) = Qnil
;
5477 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
5478 LFACE_UNDERLINE (lface
) = Qnil
;
5480 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
5481 LFACE_OVERLINE (lface
) = Qnil
;
5483 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
5484 LFACE_STRIKE_THROUGH (lface
) = Qnil
;
5486 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
5487 LFACE_BOX (lface
) = Qnil
;
5489 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
5490 LFACE_INVERSE (lface
) = Qnil
;
5492 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
5494 /* This function is called so early that colors are not yet
5495 set in the frame parameter list. */
5496 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
5498 if (CONSP (color
) && STRINGP (XCDR (color
)))
5499 LFACE_FOREGROUND (lface
) = XCDR (color
);
5500 else if (FRAME_WINDOW_P (f
))
5502 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5503 LFACE_FOREGROUND (lface
) = build_string (unspecified_fg
);
5508 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
5510 /* This function is called so early that colors are not yet
5511 set in the frame parameter list. */
5512 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
5513 if (CONSP (color
) && STRINGP (XCDR (color
)))
5514 LFACE_BACKGROUND (lface
) = XCDR (color
);
5515 else if (FRAME_WINDOW_P (f
))
5517 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5518 LFACE_BACKGROUND (lface
) = build_string (unspecified_bg
);
5523 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
5524 LFACE_STIPPLE (lface
) = Qnil
;
5526 /* Realize the face; it must be fully-specified now. */
5527 xassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
5528 check_lface (lface
);
5529 memcpy (attrs
, XVECTOR (lface
)->contents
, sizeof attrs
);
5530 face
= realize_face (c
, attrs
, DEFAULT_FACE_ID
);
5532 #ifdef HAVE_WINDOW_SYSTEM
5533 #ifdef HAVE_X_WINDOWS
5534 if (FRAME_X_P (f
) && face
->font
!= FRAME_FONT (f
))
5536 /* This can happen when making a frame on a display that does
5537 not support the default font. */
5541 /* Otherwise, the font specified for the frame was not
5542 acceptable as a font for the default face (perhaps because
5543 auto-scaled fonts are rejected), so we must adjust the frame
5545 x_set_font (f
, LFACE_FONT (lface
), Qnil
);
5547 #endif /* HAVE_X_WINDOWS */
5548 #endif /* HAVE_WINDOW_SYSTEM */
5553 /* Realize basic faces other than the default face in face cache C.
5554 SYMBOL is the face name, ID is the face id the realized face must
5555 have. The default face must have been realized already. */
5558 realize_named_face (struct frame
*f
, Lisp_Object symbol
, int id
)
5560 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5561 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
5562 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5563 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5564 struct face
*new_face
;
5566 /* The default face must exist and be fully specified. */
5567 get_lface_attributes_no_remap (f
, Qdefault
, attrs
, 1);
5568 check_lface_attrs (attrs
);
5569 xassert (lface_fully_specified_p (attrs
));
5571 /* If SYMBOL isn't know as a face, create it. */
5575 XSETFRAME (frame
, f
);
5576 lface
= Finternal_make_lisp_face (symbol
, frame
);
5579 /* Merge SYMBOL's face with the default face. */
5580 get_lface_attributes_no_remap (f
, symbol
, symbol_attrs
, 1);
5581 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
5583 /* Realize the face. */
5584 new_face
= realize_face (c
, attrs
, id
);
5588 /* Realize the fully-specified face with attributes ATTRS in face
5589 cache CACHE for ASCII characters. If FORMER_FACE_ID is
5590 non-negative, it is an ID of face to remove before caching the new
5591 face. Value is a pointer to the newly created realized face. */
5593 static struct face
*
5594 realize_face (struct face_cache
*cache
, Lisp_Object
*attrs
, int former_face_id
)
5598 /* LFACE must be fully specified. */
5599 xassert (cache
!= NULL
);
5600 check_lface_attrs (attrs
);
5602 if (former_face_id
>= 0 && cache
->used
> former_face_id
)
5604 /* Remove the former face. */
5605 struct face
*former_face
= cache
->faces_by_id
[former_face_id
];
5606 uncache_face (cache
, former_face
);
5607 free_realized_face (cache
->f
, former_face
);
5608 SET_FRAME_GARBAGED (cache
->f
);
5611 if (FRAME_WINDOW_P (cache
->f
))
5612 face
= realize_x_face (cache
, attrs
);
5613 else if (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
))
5614 face
= realize_tty_face (cache
, attrs
);
5615 else if (FRAME_INITIAL_P (cache
->f
))
5617 /* Create a dummy face. */
5618 face
= make_realized_face (attrs
);
5623 /* Insert the new face. */
5624 cache_face (cache
, face
, lface_hash (attrs
));
5629 #ifdef HAVE_WINDOW_SYSTEM
5630 /* Realize the fully-specified face that uses FONT-OBJECT and has the
5631 same attributes as BASE_FACE except for the font on frame F.
5632 FONT-OBJECT may be nil, in which case, realized a face of
5635 static struct face
*
5636 realize_non_ascii_face (struct frame
*f
, Lisp_Object font_object
, struct face
*base_face
)
5638 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5641 face
= (struct face
*) xmalloc (sizeof *face
);
5646 = (! NILP (font_object
)
5647 && FONT_WEIGHT_NAME_NUMERIC (face
->lface
[LFACE_WEIGHT_INDEX
]) > 100
5648 && FONT_WEIGHT_NUMERIC (font_object
) <= 100);
5650 /* Don't try to free the colors copied bitwise from BASE_FACE. */
5651 face
->colors_copied_bitwise_p
= 1;
5652 face
->font
= NILP (font_object
) ? NULL
: XFONT_OBJECT (font_object
);
5655 cache_face (cache
, face
, face
->hash
);
5659 #endif /* HAVE_WINDOW_SYSTEM */
5662 /* Realize the fully-specified face with attributes ATTRS in face
5663 cache CACHE for ASCII characters. Do it for X frame CACHE->f. If
5664 the new face doesn't share font with the default face, a fontname
5665 is allocated from the heap and set in `font_name' of the new face,
5666 but it is not yet loaded here. Value is a pointer to the newly
5667 created realized face. */
5669 static struct face
*
5670 realize_x_face (struct face_cache
*cache
, Lisp_Object
*attrs
)
5672 struct face
*face
= NULL
;
5673 #ifdef HAVE_WINDOW_SYSTEM
5674 struct face
*default_face
;
5676 Lisp_Object stipple
, overline
, strike_through
, box
;
5678 xassert (FRAME_WINDOW_P (cache
->f
));
5680 /* Allocate a new realized face. */
5681 face
= make_realized_face (attrs
);
5682 face
->ascii_face
= face
;
5686 /* Determine the font to use. Most of the time, the font will be
5687 the same as the font of the default face, so try that first. */
5688 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5690 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
5692 face
->font
= default_face
->font
;
5694 = make_fontset_for_ascii_face (f
, default_face
->fontset
, face
);
5698 /* If the face attribute ATTRS specifies a fontset, use it as
5699 the base of a new realized fontset. Otherwise, use the same
5700 base fontset as of the default face. The base determines
5701 registry and encoding of a font. It may also determine
5702 foundry and family. The other fields of font name pattern
5703 are constructed from ATTRS. */
5704 int fontset
= face_fontset (attrs
);
5706 /* If we are realizing the default face, ATTRS should specify a
5707 fontset. In other words, if FONTSET is -1, we are not
5708 realizing the default face, thus the default face should have
5709 already been realized. */
5713 fontset
= default_face
->fontset
;
5717 if (! FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5718 attrs
[LFACE_FONT_INDEX
]
5719 = font_load_for_lface (f
, attrs
, attrs
[LFACE_FONT_INDEX
]);
5720 if (FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5722 face
->font
= XFONT_OBJECT (attrs
[LFACE_FONT_INDEX
]);
5723 face
->fontset
= make_fontset_for_ascii_face (f
, fontset
, face
);
5733 && FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]) > 100
5734 && FONT_WEIGHT_NUMERIC (attrs
[LFACE_FONT_INDEX
]) <= 100)
5735 face
->overstrike
= 1;
5737 /* Load colors, and set remaining attributes. */
5739 load_face_colors (f
, face
, attrs
);
5742 box
= attrs
[LFACE_BOX_INDEX
];
5745 /* A simple box of line width 1 drawn in color given by
5747 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
5749 face
->box
= FACE_SIMPLE_BOX
;
5750 face
->box_line_width
= 1;
5752 else if (INTEGERP (box
))
5754 /* Simple box of specified line width in foreground color of the
5756 xassert (XINT (box
) != 0);
5757 face
->box
= FACE_SIMPLE_BOX
;
5758 face
->box_line_width
= XINT (box
);
5759 face
->box_color
= face
->foreground
;
5760 face
->box_color_defaulted_p
= 1;
5762 else if (CONSP (box
))
5764 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
5765 being one of `raised' or `sunken'. */
5766 face
->box
= FACE_SIMPLE_BOX
;
5767 face
->box_color
= face
->foreground
;
5768 face
->box_color_defaulted_p
= 1;
5769 face
->box_line_width
= 1;
5773 Lisp_Object keyword
, value
;
5775 keyword
= XCAR (box
);
5783 if (EQ (keyword
, QCline_width
))
5785 if (INTEGERP (value
) && XINT (value
) != 0)
5786 face
->box_line_width
= XINT (value
);
5788 else if (EQ (keyword
, QCcolor
))
5790 if (STRINGP (value
))
5792 face
->box_color
= load_color (f
, face
, value
,
5794 face
->use_box_color_for_shadows_p
= 1;
5797 else if (EQ (keyword
, QCstyle
))
5799 if (EQ (value
, Qreleased_button
))
5800 face
->box
= FACE_RAISED_BOX
;
5801 else if (EQ (value
, Qpressed_button
))
5802 face
->box
= FACE_SUNKEN_BOX
;
5807 /* Text underline, overline, strike-through. */
5809 if (EQ (attrs
[LFACE_UNDERLINE_INDEX
], Qt
))
5811 /* Use default color (same as foreground color). */
5812 face
->underline_p
= 1;
5813 face
->underline_defaulted_p
= 1;
5814 face
->underline_color
= 0;
5816 else if (STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]))
5818 /* Use specified color. */
5819 face
->underline_p
= 1;
5820 face
->underline_defaulted_p
= 0;
5821 face
->underline_color
5822 = load_color (f
, face
, attrs
[LFACE_UNDERLINE_INDEX
],
5823 LFACE_UNDERLINE_INDEX
);
5825 else if (NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5827 face
->underline_p
= 0;
5828 face
->underline_defaulted_p
= 0;
5829 face
->underline_color
= 0;
5832 overline
= attrs
[LFACE_OVERLINE_INDEX
];
5833 if (STRINGP (overline
))
5835 face
->overline_color
5836 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
5837 LFACE_OVERLINE_INDEX
);
5838 face
->overline_p
= 1;
5840 else if (EQ (overline
, Qt
))
5842 face
->overline_color
= face
->foreground
;
5843 face
->overline_color_defaulted_p
= 1;
5844 face
->overline_p
= 1;
5847 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
5848 if (STRINGP (strike_through
))
5850 face
->strike_through_color
5851 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
5852 LFACE_STRIKE_THROUGH_INDEX
);
5853 face
->strike_through_p
= 1;
5855 else if (EQ (strike_through
, Qt
))
5857 face
->strike_through_color
= face
->foreground
;
5858 face
->strike_through_color_defaulted_p
= 1;
5859 face
->strike_through_p
= 1;
5862 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
5863 if (!NILP (stipple
))
5864 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
5865 #endif /* HAVE_WINDOW_SYSTEM */
5871 /* Map a specified color of face FACE on frame F to a tty color index.
5872 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
5873 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
5874 default foreground/background colors. */
5877 map_tty_color (struct frame
*f
, struct face
*face
, enum lface_attribute_index idx
, int *defaulted
)
5879 Lisp_Object frame
, color
, def
;
5880 int foreground_p
= idx
== LFACE_FOREGROUND_INDEX
;
5881 unsigned long default_pixel
, default_other_pixel
, pixel
;
5883 xassert (idx
== LFACE_FOREGROUND_INDEX
|| idx
== LFACE_BACKGROUND_INDEX
);
5887 pixel
= default_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5888 default_other_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5892 pixel
= default_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5893 default_other_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5896 XSETFRAME (frame
, f
);
5897 color
= face
->lface
[idx
];
5901 && CONSP (Vtty_defined_color_alist
)
5902 && (def
= assq_no_quit (color
, call1 (Qtty_color_alist
, frame
)),
5905 /* Associations in tty-defined-color-alist are of the form
5906 (NAME INDEX R G B). We need the INDEX part. */
5907 pixel
= XINT (XCAR (XCDR (def
)));
5910 if (pixel
== default_pixel
&& STRINGP (color
))
5912 pixel
= load_color (f
, face
, color
, idx
);
5915 /* If the foreground of the default face is the default color,
5916 use the foreground color defined by the frame. */
5917 if (FRAME_MSDOS_P (f
))
5919 if (pixel
== default_pixel
5920 || pixel
== FACE_TTY_DEFAULT_COLOR
)
5923 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5925 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5926 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5929 else if (pixel
== default_other_pixel
)
5932 pixel
= FRAME_BACKGROUND_PIXEL (f
);
5934 pixel
= FRAME_FOREGROUND_PIXEL (f
);
5935 face
->lface
[idx
] = tty_color_name (f
, pixel
);
5943 face
->foreground
= pixel
;
5945 face
->background
= pixel
;
5949 /* Realize the fully-specified face with attributes ATTRS in face
5950 cache CACHE for ASCII characters. Do it for TTY frame CACHE->f.
5951 Value is a pointer to the newly created realized face. */
5953 static struct face
*
5954 realize_tty_face (struct face_cache
*cache
, Lisp_Object
*attrs
)
5958 int face_colors_defaulted
= 0;
5959 struct frame
*f
= cache
->f
;
5961 /* Frame must be a termcap frame. */
5962 xassert (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
));
5964 /* Allocate a new realized face. */
5965 face
= make_realized_face (attrs
);
5967 face
->font_name
= FRAME_MSDOS_P (cache
->f
) ? "ms-dos" : "tty";
5970 /* Map face attributes to TTY appearances. We map slant to
5971 dimmed text because we want italic text to appear differently
5972 and because dimmed text is probably used infrequently. */
5973 weight
= FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]);
5974 slant
= FONT_SLANT_NAME_NUMERIC (attrs
[LFACE_SLANT_INDEX
]);
5976 face
->tty_bold_p
= 1;
5977 if (weight
< 100 || slant
!= 100)
5978 face
->tty_dim_p
= 1;
5979 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5980 face
->tty_underline_p
= 1;
5981 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
5982 face
->tty_reverse_p
= 1;
5984 /* Map color names to color indices. */
5985 map_tty_color (f
, face
, LFACE_FOREGROUND_INDEX
, &face_colors_defaulted
);
5986 map_tty_color (f
, face
, LFACE_BACKGROUND_INDEX
, &face_colors_defaulted
);
5988 /* Swap colors if face is inverse-video. If the colors are taken
5989 from the frame colors, they are already inverted, since the
5990 frame-creation function calls x-handle-reverse-video. */
5991 if (face
->tty_reverse_p
&& !face_colors_defaulted
)
5993 unsigned long tem
= face
->foreground
;
5994 face
->foreground
= face
->background
;
5995 face
->background
= tem
;
5998 if (tty_suppress_bold_inverse_default_colors_p
6000 && face
->background
== FACE_TTY_DEFAULT_FG_COLOR
6001 && face
->foreground
== FACE_TTY_DEFAULT_BG_COLOR
)
6002 face
->tty_bold_p
= 0;
6008 DEFUN ("tty-suppress-bold-inverse-default-colors",
6009 Ftty_suppress_bold_inverse_default_colors
,
6010 Stty_suppress_bold_inverse_default_colors
, 1, 1, 0,
6011 doc
: /* Suppress/allow boldness of faces with inverse default colors.
6012 SUPPRESS non-nil means suppress it.
6013 This affects bold faces on TTYs whose foreground is the default background
6014 color of the display and whose background is the default foreground color.
6015 For such faces, the bold face attribute is ignored if this variable
6017 (Lisp_Object suppress
)
6019 tty_suppress_bold_inverse_default_colors_p
= !NILP (suppress
);
6020 ++face_change_count
;
6026 /***********************************************************************
6028 ***********************************************************************/
6030 /* Return the ID of the face to use to display character CH with face
6031 property PROP on frame F in current_buffer. */
6034 compute_char_face (struct frame
*f
, int ch
, Lisp_Object prop
)
6038 if (NILP (current_buffer
->enable_multibyte_characters
))
6043 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6044 face_id
= FACE_FOR_CHAR (f
, face
, ch
, -1, Qnil
);
6048 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6049 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6050 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6051 merge_face_ref (f
, prop
, attrs
, 1, 0);
6052 face_id
= lookup_face (f
, attrs
);
6058 /* Return the face ID associated with buffer position POS for
6059 displaying ASCII characters. Return in *ENDPTR the position at
6060 which a different face is needed, as far as text properties and
6061 overlays are concerned. W is a window displaying current_buffer.
6063 REGION_BEG, REGION_END delimit the region, so it can be
6066 LIMIT is a position not to scan beyond. That is to limit the time
6067 this function can take.
6069 If MOUSE is non-zero, use the character's mouse-face, not its face.
6071 BASE_FACE_ID, if non-negative, specifies a base face id to use
6072 instead of DEFAULT_FACE_ID.
6074 The face returned is suitable for displaying ASCII characters. */
6077 face_at_buffer_position (struct window
*w
, EMACS_INT pos
,
6078 EMACS_INT region_beg
, EMACS_INT region_end
,
6079 EMACS_INT
*endptr
, EMACS_INT limit
,
6080 int mouse
, int base_face_id
)
6082 struct frame
*f
= XFRAME (w
->frame
);
6083 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6084 Lisp_Object prop
, position
;
6086 Lisp_Object
*overlay_vec
;
6089 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
6090 Lisp_Object limit1
, end
;
6091 struct face
*default_face
;
6093 /* W must display the current buffer. We could write this function
6094 to use the frame and buffer of W, but right now it doesn't. */
6095 /* xassert (XBUFFER (w->buffer) == current_buffer); */
6097 XSETFRAME (frame
, f
);
6098 XSETFASTINT (position
, pos
);
6101 if (pos
< region_beg
&& region_beg
< endpos
)
6102 endpos
= region_beg
;
6104 /* Get the `face' or `mouse_face' text property at POS, and
6105 determine the next position at which the property changes. */
6106 prop
= Fget_text_property (position
, propname
, w
->buffer
);
6107 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6108 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
6110 endpos
= XINT (end
);
6112 /* Look at properties from overlays. */
6114 EMACS_INT next_overlay
;
6116 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, &next_overlay
, 0);
6117 if (next_overlay
< endpos
)
6118 endpos
= next_overlay
;
6123 default_face
= FACE_FROM_ID (f
, base_face_id
>= 0 ? base_face_id
6124 : NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
6125 : lookup_basic_face (f
, DEFAULT_FACE_ID
));
6127 /* Optimize common cases where we can use the default face. */
6130 && !(pos
>= region_beg
&& pos
< region_end
))
6131 return default_face
->id
;
6133 /* Begin with attributes from the default face. */
6134 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6136 /* Merge in attributes specified via text properties. */
6138 merge_face_ref (f
, prop
, attrs
, 1, 0);
6140 /* Now merge the overlay data. */
6141 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6142 for (i
= 0; i
< noverlays
; i
++)
6147 prop
= Foverlay_get (overlay_vec
[i
], propname
);
6149 merge_face_ref (f
, prop
, attrs
, 1, 0);
6151 oend
= OVERLAY_END (overlay_vec
[i
]);
6152 oendpos
= OVERLAY_POSITION (oend
);
6153 if (oendpos
< endpos
)
6157 /* If in the region, merge in the region face. */
6158 if (pos
>= region_beg
&& pos
< region_end
)
6160 merge_named_face (f
, Qregion
, attrs
, 0);
6162 if (region_end
< endpos
)
6163 endpos
= region_end
;
6168 /* Look up a realized face with the given face attributes,
6169 or realize a new one for ASCII characters. */
6170 return lookup_face (f
, attrs
);
6173 /* Return the face ID at buffer position POS for displaying ASCII
6174 characters associated with overlay strings for overlay OVERLAY.
6176 Like face_at_buffer_position except for OVERLAY. Currently it
6177 simply disregards the `face' properties of all overlays. */
6180 face_for_overlay_string (struct window
*w
, EMACS_INT pos
,
6181 EMACS_INT region_beg
, EMACS_INT region_end
,
6182 EMACS_INT
*endptr
, EMACS_INT limit
,
6183 int mouse
, Lisp_Object overlay
)
6185 struct frame
*f
= XFRAME (w
->frame
);
6186 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6187 Lisp_Object prop
, position
;
6190 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
6191 Lisp_Object limit1
, end
;
6192 struct face
*default_face
;
6194 /* W must display the current buffer. We could write this function
6195 to use the frame and buffer of W, but right now it doesn't. */
6196 /* xassert (XBUFFER (w->buffer) == current_buffer); */
6198 XSETFRAME (frame
, f
);
6199 XSETFASTINT (position
, pos
);
6202 if (pos
< region_beg
&& region_beg
< endpos
)
6203 endpos
= region_beg
;
6205 /* Get the `face' or `mouse_face' text property at POS, and
6206 determine the next position at which the property changes. */
6207 prop
= Fget_text_property (position
, propname
, w
->buffer
);
6208 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6209 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
6211 endpos
= XINT (end
);
6215 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6217 /* Optimize common cases where we can use the default face. */
6219 && !(pos
>= region_beg
&& pos
< region_end
))
6220 return DEFAULT_FACE_ID
;
6222 /* Begin with attributes from the default face. */
6223 memcpy (attrs
, default_face
->lface
, sizeof attrs
);
6225 /* Merge in attributes specified via text properties. */
6227 merge_face_ref (f
, prop
, attrs
, 1, 0);
6229 /* If in the region, merge in the region face. */
6230 if (pos
>= region_beg
&& pos
< region_end
)
6232 merge_named_face (f
, Qregion
, attrs
, 0);
6234 if (region_end
< endpos
)
6235 endpos
= region_end
;
6240 /* Look up a realized face with the given face attributes,
6241 or realize a new one for ASCII characters. */
6242 return lookup_face (f
, attrs
);
6246 /* Compute the face at character position POS in Lisp string STRING on
6247 window W, for ASCII characters.
6249 If STRING is an overlay string, it comes from position BUFPOS in
6250 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
6251 not an overlay string. W must display the current buffer.
6252 REGION_BEG and REGION_END give the start and end positions of the
6253 region; both are -1 if no region is visible.
6255 BASE_FACE_ID is the id of a face to merge with. For strings coming
6256 from overlays or the `display' property it is the face at BUFPOS.
6258 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
6260 Set *ENDPTR to the next position where to check for faces in
6261 STRING; -1 if the face is constant from POS to the end of the
6264 Value is the id of the face to use. The face returned is suitable
6265 for displaying ASCII characters. */
6268 face_at_string_position (struct window
*w
, Lisp_Object string
,
6269 EMACS_INT pos
, EMACS_INT bufpos
,
6270 EMACS_INT region_beg
, EMACS_INT region_end
,
6271 EMACS_INT
*endptr
, enum face_id base_face_id
,
6274 Lisp_Object prop
, position
, end
, limit
;
6275 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6276 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6277 struct face
*base_face
;
6278 int multibyte_p
= STRING_MULTIBYTE (string
);
6279 Lisp_Object prop_name
= mouse_p
? Qmouse_face
: Qface
;
6281 /* Get the value of the face property at the current position within
6282 STRING. Value is nil if there is no face property. */
6283 XSETFASTINT (position
, pos
);
6284 prop
= Fget_text_property (position
, prop_name
, string
);
6286 /* Get the next position at which to check for faces. Value of end
6287 is nil if face is constant all the way to the end of the string.
6288 Otherwise it is a string position where to check faces next.
6289 Limit is the maximum position up to which to check for property
6290 changes in Fnext_single_property_change. Strings are usually
6291 short, so set the limit to the end of the string. */
6292 XSETFASTINT (limit
, SCHARS (string
));
6293 end
= Fnext_single_property_change (position
, prop_name
, string
, limit
);
6295 *endptr
= XFASTINT (end
);
6299 base_face
= FACE_FROM_ID (f
, base_face_id
);
6300 xassert (base_face
);
6302 /* Optimize the default case that there is no face property and we
6303 are not in the region. */
6305 && (base_face_id
!= DEFAULT_FACE_ID
6306 /* BUFPOS <= 0 means STRING is not an overlay string, so
6307 that the region doesn't have to be taken into account. */
6309 || bufpos
< region_beg
6310 || bufpos
>= region_end
)
6312 /* We can't realize faces for different charsets differently
6313 if we don't have fonts, so we can stop here if not working
6314 on a window-system frame. */
6315 || !FRAME_WINDOW_P (f
)
6316 || FACE_SUITABLE_FOR_CHAR_P (base_face
, 0)))
6317 return base_face
->id
;
6319 /* Begin with attributes from the base face. */
6320 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6322 /* Merge in attributes specified via text properties. */
6324 merge_face_ref (f
, prop
, attrs
, 1, 0);
6326 /* If in the region, merge in the region face. */
6328 && bufpos
>= region_beg
6329 && bufpos
< region_end
)
6330 merge_named_face (f
, Qregion
, attrs
, 0);
6332 /* Look up a realized face with the given face attributes,
6333 or realize a new one for ASCII characters. */
6334 return lookup_face (f
, attrs
);
6338 /* Merge a face into a realized face.
6340 F is frame where faces are (to be) realized.
6342 FACE_NAME is named face to merge.
6344 If FACE_NAME is nil, FACE_ID is face_id of realized face to merge.
6346 If FACE_NAME is t, FACE_ID is lface_id of face to merge.
6348 BASE_FACE_ID is realized face to merge into.
6354 merge_faces (struct frame
*f
, Lisp_Object face_name
, int face_id
, int base_face_id
)
6356 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6357 struct face
*base_face
;
6359 base_face
= FACE_FROM_ID (f
, base_face_id
);
6361 return base_face_id
;
6363 if (EQ (face_name
, Qt
))
6365 if (face_id
< 0 || face_id
>= lface_id_to_name_size
)
6366 return base_face_id
;
6367 face_name
= lface_id_to_name
[face_id
];
6368 /* When called during make-frame, lookup_derived_face may fail
6369 if the faces are uninitialized. Don't signal an error. */
6370 face_id
= lookup_derived_face (f
, face_name
, base_face_id
, 0);
6371 return (face_id
>= 0 ? face_id
: base_face_id
);
6374 /* Begin with attributes from the base face. */
6375 memcpy (attrs
, base_face
->lface
, sizeof attrs
);
6377 if (!NILP (face_name
))
6379 if (!merge_named_face (f
, face_name
, attrs
, 0))
6380 return base_face_id
;
6386 return base_face_id
;
6387 face
= FACE_FROM_ID (f
, face_id
);
6389 return base_face_id
;
6390 merge_face_vectors (f
, face
->lface
, attrs
, 0);
6393 /* Look up a realized face with the given face attributes,
6394 or realize a new one for ASCII characters. */
6395 return lookup_face (f
, attrs
);
6400 #ifndef HAVE_X_WINDOWS
6401 DEFUN ("x-load-color-file", Fx_load_color_file
,
6402 Sx_load_color_file
, 1, 1, 0,
6403 doc
: /* Create an alist of color entries from an external file.
6405 The file should define one named RGB color per line like so:
6407 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6408 (Lisp_Object filename
)
6411 Lisp_Object cmap
= Qnil
;
6412 Lisp_Object abspath
;
6414 CHECK_STRING (filename
);
6415 abspath
= Fexpand_file_name (filename
, Qnil
);
6417 fp
= fopen (SDATA (filename
), "rt");
6421 int red
, green
, blue
;
6426 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
6427 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
6429 char *name
= buf
+ num
;
6430 num
= strlen (name
) - 1;
6431 if (num
>= 0 && name
[num
] == '\n')
6433 cmap
= Fcons (Fcons (build_string (name
),
6435 make_number (RGB (red
, green
, blue
))),
6437 make_number ((red
<< 16) | (green
<< 8) | blue
)),
6452 /***********************************************************************
6454 ***********************************************************************/
6458 /* Print the contents of the realized face FACE to stderr. */
6461 dump_realized_face (face
)
6464 fprintf (stderr
, "ID: %d\n", face
->id
);
6465 #ifdef HAVE_X_WINDOWS
6466 fprintf (stderr
, "gc: %ld\n", (long) face
->gc
);
6468 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
6470 SDATA (face
->lface
[LFACE_FOREGROUND_INDEX
]));
6471 fprintf (stderr
, "background: 0x%lx (%s)\n",
6473 SDATA (face
->lface
[LFACE_BACKGROUND_INDEX
]));
6475 fprintf (stderr
, "font_name: %s (%s)\n",
6476 SDATA (face
->font
->props
[FONT_NAME_INDEX
]),
6477 SDATA (face
->lface
[LFACE_FAMILY_INDEX
]));
6478 #ifdef HAVE_X_WINDOWS
6479 fprintf (stderr
, "font = %p\n", face
->font
);
6481 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
6482 fprintf (stderr
, "underline: %d (%s)\n",
6484 SDATA (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
])));
6485 fprintf (stderr
, "hash: %d\n", face
->hash
);
6489 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, doc
: /* */)
6496 fprintf (stderr
, "font selection order: ");
6497 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6498 fprintf (stderr
, "%d ", font_sort_order
[i
]);
6499 fprintf (stderr
, "\n");
6501 fprintf (stderr
, "alternative fonts: ");
6502 debug_print (Vface_alternative_font_family_alist
);
6503 fprintf (stderr
, "\n");
6505 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
6506 Fdump_face (make_number (i
));
6512 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
6514 error ("Not a valid face");
6515 dump_realized_face (face
);
6522 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
6523 0, 0, 0, doc
: /* */)
6526 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
6527 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
6528 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
6532 #endif /* GLYPH_DEBUG != 0 */
6536 /***********************************************************************
6538 ***********************************************************************/
6541 syms_of_xfaces (void)
6543 Qface
= intern_c_string ("face");
6545 Qface_no_inherit
= intern_c_string ("face-no-inherit");
6546 staticpro (&Qface_no_inherit
);
6547 Qbitmap_spec_p
= intern_c_string ("bitmap-spec-p");
6548 staticpro (&Qbitmap_spec_p
);
6549 Qframe_set_background_mode
= intern_c_string ("frame-set-background-mode");
6550 staticpro (&Qframe_set_background_mode
);
6552 /* Lisp face attribute keywords. */
6553 QCfamily
= intern_c_string (":family");
6554 staticpro (&QCfamily
);
6555 QCheight
= intern_c_string (":height");
6556 staticpro (&QCheight
);
6557 QCweight
= intern_c_string (":weight");
6558 staticpro (&QCweight
);
6559 QCslant
= intern_c_string (":slant");
6560 staticpro (&QCslant
);
6561 QCunderline
= intern_c_string (":underline");
6562 staticpro (&QCunderline
);
6563 QCinverse_video
= intern_c_string (":inverse-video");
6564 staticpro (&QCinverse_video
);
6565 QCreverse_video
= intern_c_string (":reverse-video");
6566 staticpro (&QCreverse_video
);
6567 QCforeground
= intern_c_string (":foreground");
6568 staticpro (&QCforeground
);
6569 QCbackground
= intern_c_string (":background");
6570 staticpro (&QCbackground
);
6571 QCstipple
= intern_c_string (":stipple");
6572 staticpro (&QCstipple
);
6573 QCwidth
= intern_c_string (":width");
6574 staticpro (&QCwidth
);
6575 QCfont
= intern_c_string (":font");
6576 staticpro (&QCfont
);
6577 QCfontset
= intern_c_string (":fontset");
6578 staticpro (&QCfontset
);
6579 QCbold
= intern_c_string (":bold");
6580 staticpro (&QCbold
);
6581 QCitalic
= intern_c_string (":italic");
6582 staticpro (&QCitalic
);
6583 QCoverline
= intern_c_string (":overline");
6584 staticpro (&QCoverline
);
6585 QCstrike_through
= intern_c_string (":strike-through");
6586 staticpro (&QCstrike_through
);
6587 QCbox
= intern_c_string (":box");
6589 QCinherit
= intern_c_string (":inherit");
6590 staticpro (&QCinherit
);
6592 /* Symbols used for Lisp face attribute values. */
6593 QCcolor
= intern_c_string (":color");
6594 staticpro (&QCcolor
);
6595 QCline_width
= intern_c_string (":line-width");
6596 staticpro (&QCline_width
);
6597 QCstyle
= intern_c_string (":style");
6598 staticpro (&QCstyle
);
6599 Qreleased_button
= intern_c_string ("released-button");
6600 staticpro (&Qreleased_button
);
6601 Qpressed_button
= intern_c_string ("pressed-button");
6602 staticpro (&Qpressed_button
);
6603 Qnormal
= intern_c_string ("normal");
6604 staticpro (&Qnormal
);
6605 Qultra_light
= intern_c_string ("ultra-light");
6606 staticpro (&Qultra_light
);
6607 Qextra_light
= intern_c_string ("extra-light");
6608 staticpro (&Qextra_light
);
6609 Qlight
= intern_c_string ("light");
6610 staticpro (&Qlight
);
6611 Qsemi_light
= intern_c_string ("semi-light");
6612 staticpro (&Qsemi_light
);
6613 Qsemi_bold
= intern_c_string ("semi-bold");
6614 staticpro (&Qsemi_bold
);
6615 Qbold
= intern_c_string ("bold");
6617 Qextra_bold
= intern_c_string ("extra-bold");
6618 staticpro (&Qextra_bold
);
6619 Qultra_bold
= intern_c_string ("ultra-bold");
6620 staticpro (&Qultra_bold
);
6621 Qoblique
= intern_c_string ("oblique");
6622 staticpro (&Qoblique
);
6623 Qitalic
= intern_c_string ("italic");
6624 staticpro (&Qitalic
);
6625 Qreverse_oblique
= intern_c_string ("reverse-oblique");
6626 staticpro (&Qreverse_oblique
);
6627 Qreverse_italic
= intern_c_string ("reverse-italic");
6628 staticpro (&Qreverse_italic
);
6629 Qultra_condensed
= intern_c_string ("ultra-condensed");
6630 staticpro (&Qultra_condensed
);
6631 Qextra_condensed
= intern_c_string ("extra-condensed");
6632 staticpro (&Qextra_condensed
);
6633 Qcondensed
= intern_c_string ("condensed");
6634 staticpro (&Qcondensed
);
6635 Qsemi_condensed
= intern_c_string ("semi-condensed");
6636 staticpro (&Qsemi_condensed
);
6637 Qsemi_expanded
= intern_c_string ("semi-expanded");
6638 staticpro (&Qsemi_expanded
);
6639 Qexpanded
= intern_c_string ("expanded");
6640 staticpro (&Qexpanded
);
6641 Qextra_expanded
= intern_c_string ("extra-expanded");
6642 staticpro (&Qextra_expanded
);
6643 Qultra_expanded
= intern_c_string ("ultra-expanded");
6644 staticpro (&Qultra_expanded
);
6645 Qbackground_color
= intern_c_string ("background-color");
6646 staticpro (&Qbackground_color
);
6647 Qforeground_color
= intern_c_string ("foreground-color");
6648 staticpro (&Qforeground_color
);
6649 Qunspecified
= intern_c_string ("unspecified");
6650 staticpro (&Qunspecified
);
6651 Qignore_defface
= intern_c_string (":ignore-defface");
6652 staticpro (&Qignore_defface
);
6654 Qface_alias
= intern_c_string ("face-alias");
6655 staticpro (&Qface_alias
);
6656 Qdefault
= intern_c_string ("default");
6657 staticpro (&Qdefault
);
6658 Qtool_bar
= intern_c_string ("tool-bar");
6659 staticpro (&Qtool_bar
);
6660 Qregion
= intern_c_string ("region");
6661 staticpro (&Qregion
);
6662 Qfringe
= intern_c_string ("fringe");
6663 staticpro (&Qfringe
);
6664 Qheader_line
= intern_c_string ("header-line");
6665 staticpro (&Qheader_line
);
6666 Qscroll_bar
= intern_c_string ("scroll-bar");
6667 staticpro (&Qscroll_bar
);
6668 Qmenu
= intern_c_string ("menu");
6670 Qcursor
= intern_c_string ("cursor");
6671 staticpro (&Qcursor
);
6672 Qborder
= intern_c_string ("border");
6673 staticpro (&Qborder
);
6674 Qmouse
= intern_c_string ("mouse");
6675 staticpro (&Qmouse
);
6676 Qmode_line_inactive
= intern_c_string ("mode-line-inactive");
6677 staticpro (&Qmode_line_inactive
);
6678 Qvertical_border
= intern_c_string ("vertical-border");
6679 staticpro (&Qvertical_border
);
6680 Qtty_color_desc
= intern_c_string ("tty-color-desc");
6681 staticpro (&Qtty_color_desc
);
6682 Qtty_color_standard_values
= intern_c_string ("tty-color-standard-values");
6683 staticpro (&Qtty_color_standard_values
);
6684 Qtty_color_by_index
= intern_c_string ("tty-color-by-index");
6685 staticpro (&Qtty_color_by_index
);
6686 Qtty_color_alist
= intern_c_string ("tty-color-alist");
6687 staticpro (&Qtty_color_alist
);
6688 Qscalable_fonts_allowed
= intern_c_string ("scalable-fonts-allowed");
6689 staticpro (&Qscalable_fonts_allowed
);
6691 Vparam_value_alist
= Fcons (Fcons (Qnil
, Qnil
), Qnil
);
6692 staticpro (&Vparam_value_alist
);
6693 Vface_alternative_font_family_alist
= Qnil
;
6694 staticpro (&Vface_alternative_font_family_alist
);
6695 Vface_alternative_font_registry_alist
= Qnil
;
6696 staticpro (&Vface_alternative_font_registry_alist
);
6698 defsubr (&Sinternal_make_lisp_face
);
6699 defsubr (&Sinternal_lisp_face_p
);
6700 defsubr (&Sinternal_set_lisp_face_attribute
);
6701 #ifdef HAVE_WINDOW_SYSTEM
6702 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
6704 defsubr (&Scolor_gray_p
);
6705 defsubr (&Scolor_supported_p
);
6706 #ifndef HAVE_X_WINDOWS
6707 defsubr (&Sx_load_color_file
);
6709 defsubr (&Sface_attribute_relative_p
);
6710 defsubr (&Smerge_face_attribute
);
6711 defsubr (&Sinternal_get_lisp_face_attribute
);
6712 defsubr (&Sinternal_lisp_face_attribute_values
);
6713 defsubr (&Sinternal_lisp_face_equal_p
);
6714 defsubr (&Sinternal_lisp_face_empty_p
);
6715 defsubr (&Sinternal_copy_lisp_face
);
6716 defsubr (&Sinternal_merge_in_global_face
);
6717 defsubr (&Sface_font
);
6718 defsubr (&Sframe_face_alist
);
6719 defsubr (&Sdisplay_supports_face_attributes_p
);
6720 defsubr (&Scolor_distance
);
6721 defsubr (&Sinternal_set_font_selection_order
);
6722 defsubr (&Sinternal_set_alternative_font_family_alist
);
6723 defsubr (&Sinternal_set_alternative_font_registry_alist
);
6724 defsubr (&Sface_attributes_as_vector
);
6726 defsubr (&Sdump_face
);
6727 defsubr (&Sshow_face_resources
);
6728 #endif /* GLYPH_DEBUG */
6729 defsubr (&Sclear_face_cache
);
6730 defsubr (&Stty_suppress_bold_inverse_default_colors
);
6732 #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS
6733 defsubr (&Sdump_colors
);
6736 DEFVAR_LISP ("font-list-limit", &Vfont_list_limit
,
6737 doc
: /* *Limit for font matching.
6738 If an integer > 0, font matching functions won't load more than
6739 that number of fonts when searching for a matching font. */);
6740 Vfont_list_limit
= make_number (DEFAULT_FONT_LIST_LIMIT
);
6742 DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults
,
6743 doc
: /* List of global face definitions (for internal use only.) */);
6744 Vface_new_frame_defaults
= Qnil
;
6746 DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple
,
6747 doc
: /* *Default stipple pattern used on monochrome displays.
6748 This stipple pattern is used on monochrome displays
6749 instead of shades of gray for a face background color.
6750 See `set-face-stipple' for possible values for this variable. */);
6751 Vface_default_stipple
= make_pure_c_string ("gray3");
6753 DEFVAR_LISP ("tty-defined-color-alist", &Vtty_defined_color_alist
,
6754 doc
: /* An alist of defined terminal colors and their RGB values. */);
6755 Vtty_defined_color_alist
= Qnil
;
6757 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed
,
6758 doc
: /* Allowed scalable fonts.
6759 A value of nil means don't allow any scalable fonts.
6760 A value of t means allow any scalable font.
6761 Otherwise, value must be a list of regular expressions. A font may be
6762 scaled if its name matches a regular expression in the list.
6763 Note that if value is nil, a scalable font might still be used, if no
6764 other font of the appropriate family and registry is available. */);
6765 Vscalable_fonts_allowed
= Qnil
;
6767 DEFVAR_LISP ("face-ignored-fonts", &Vface_ignored_fonts
,
6768 doc
: /* List of ignored fonts.
6769 Each element is a regular expression that matches names of fonts to
6771 Vface_ignored_fonts
= Qnil
;
6773 DEFVAR_LISP ("face-remapping-alist", &Vface_remapping_alist
,
6774 doc
: /* Alist of face remappings.
6775 Each element is of the form:
6777 (FACE REPLACEMENT...),
6779 which causes display of the face FACE to use REPLACEMENT... instead.
6780 REPLACEMENT... is interpreted the same way as the value of a `face'
6781 text property: it may be (1) A face name, (2) A list of face names,
6782 (3) A property-list of face attribute/value pairs, or (4) A list of
6783 face names or lists containing face attribute/value pairs.
6785 Multiple entries in REPLACEMENT... are merged together to form the final
6786 result, with faces or attributes earlier in the list taking precedence
6787 over those that are later.
6789 Face-name remapping cycles are suppressed; recursive references use the
6790 underlying face instead of the remapped face. So a remapping of the form:
6792 (FACE EXTRA-FACE... FACE)
6796 (FACE (FACE-ATTR VAL ...) FACE)
6798 will cause EXTRA-FACE... or (FACE-ATTR VAL ...) to be _merged_ with the
6799 existing definition of FACE. Note that for the default face, this isn't
6800 necessary, as every face inherits from the default face.
6802 Making this variable buffer-local is a good way to allow buffer-specific
6803 face definitions. For instance, the mode my-mode could define a face
6804 `my-mode-default', and then in the mode setup function, do:
6806 (set (make-local-variable 'face-remapping-alist)
6807 '((default my-mode-default)))).
6809 Because Emacs normally only redraws screen areas when the underlying
6810 buffer contents change, you may need to call `redraw-display' after
6811 changing this variable for it to take effect. */);
6812 Vface_remapping_alist
= Qnil
;
6814 DEFVAR_LISP ("face-font-rescale-alist", &Vface_font_rescale_alist
,
6815 doc
: /* Alist of fonts vs the rescaling factors.
6816 Each element is a cons (FONT-PATTERN . RESCALE-RATIO), where
6817 FONT-PATTERN is a font-spec or a regular expression matching a font name, and
6818 RESCALE-RATIO is a floating point number to specify how much larger
6819 \(or smaller) font we should use. For instance, if a face requests
6820 a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point. */);
6821 Vface_font_rescale_alist
= Qnil
;
6823 #ifdef HAVE_WINDOW_SYSTEM
6824 defsubr (&Sbitmap_spec_p
);
6825 defsubr (&Sx_list_fonts
);
6826 defsubr (&Sinternal_face_x_get_resource
);
6827 defsubr (&Sx_family_fonts
);
6831 /* arch-tag: 8a0f7598-5517-408d-9ab3-1da6fcd4c749
6832 (do not change this comment) */