1 /* xfaces.c -- "Face" primitives.
2 Copyright (C) 1993, 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009 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 */
209 #include "character.h"
211 #include "keyboard.h"
213 #include "termhooks.h"
215 #ifdef HAVE_X_WINDOWS
219 #include <Xm/XmStrDefs.h>
220 #endif /* USE_MOTIF */
221 #endif /* HAVE_X_WINDOWS */
230 /* Redefine X specifics to W32 equivalents to avoid cluttering the
231 code with #ifdef blocks. */
232 #undef FRAME_X_DISPLAY_INFO
233 #define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO
234 #define x_display_info w32_display_info
235 #define FRAME_X_FONT_TABLE FRAME_W32_FONT_TABLE
236 #define check_x check_w32
237 #define GCGraphicsExposures 0
238 #endif /* WINDOWSNT */
242 #undef FRAME_X_DISPLAY_INFO
243 #define FRAME_X_DISPLAY_INFO FRAME_NS_DISPLAY_INFO
244 #define x_display_info ns_display_info
245 #define FRAME_X_FONT_TABLE FRAME_NS_FONT_TABLE
246 #define check_x check_ns
247 #define GCGraphicsExposures 0
251 #include "dispextern.h"
252 #include "blockinput.h"
254 #include "intervals.h"
255 #include "termchar.h"
258 #ifdef HAVE_WINDOW_SYSTEM
260 #endif /* HAVE_WINDOW_SYSTEM */
262 #ifdef HAVE_X_WINDOWS
264 /* Compensate for a bug in Xos.h on some systems, on which it requires
265 time.h. On some such systems, Xos.h tries to redefine struct
266 timeval and struct timezone if USG is #defined while it is
269 #ifdef XOS_NEEDS_TIME_H
275 #else /* not XOS_NEEDS_TIME_H */
277 #endif /* not XOS_NEEDS_TIME_H */
279 #endif /* HAVE_X_WINDOWS */
283 /* Number of pt per inch (from the TeXbook). */
285 #define PT_PER_INCH 72.27
287 /* Non-zero if face attribute ATTR is unspecified. */
289 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified)
291 /* Non-zero if face attribute ATTR is `ignore-defface'. */
293 #define IGNORE_DEFFACE_P(ATTR) EQ ((ATTR), Qignore_defface)
295 /* Value is the number of elements of VECTOR. */
297 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
299 /* Make a copy of string S on the stack using alloca. Value is a pointer
302 #define STRDUPA(S) strcpy ((char *) alloca (strlen ((S)) + 1), (S))
304 /* Make a copy of the contents of Lisp string S on the stack using
305 alloca. Value is a pointer to the copy. */
307 #define LSTRDUPA(S) STRDUPA (SDATA ((S)))
309 /* Size of hash table of realized faces in face caches (should be a
312 #define FACE_CACHE_BUCKETS_SIZE 1001
314 /* Keyword symbols used for face attribute names. */
316 Lisp_Object QCfamily
, QCheight
, QCweight
, QCslant
, QCunderline
;
317 Lisp_Object QCinverse_video
, QCforeground
, QCbackground
, QCstipple
;
318 Lisp_Object QCwidth
, QCfont
, QCbold
, QCitalic
;
319 Lisp_Object QCreverse_video
;
320 Lisp_Object QCoverline
, QCstrike_through
, QCbox
, QCinherit
;
321 Lisp_Object QCfontset
;
323 /* Keywords symbols used for font properties. */
324 extern Lisp_Object QCfoundry
, QCadstyle
, QCregistry
;
325 extern Lisp_Object QCspacing
, QCsize
, QCavgwidth
;
326 extern Lisp_Object Qp
;
328 /* Symbols used for attribute values. */
330 Lisp_Object Qnormal
, Qbold
, Qultra_light
, Qextra_light
, Qlight
;
331 Lisp_Object Qsemi_light
, Qsemi_bold
, Qextra_bold
, Qultra_bold
;
332 Lisp_Object Qoblique
, Qitalic
, Qreverse_oblique
, Qreverse_italic
;
333 Lisp_Object Qultra_condensed
, Qextra_condensed
, Qcondensed
;
334 Lisp_Object Qsemi_condensed
, Qsemi_expanded
, Qexpanded
, Qextra_expanded
;
335 Lisp_Object Qultra_expanded
;
336 Lisp_Object Qreleased_button
, Qpressed_button
;
337 Lisp_Object QCstyle
, QCcolor
, QCline_width
;
338 Lisp_Object Qunspecified
;
339 Lisp_Object Qignore_defface
;
341 char unspecified_fg
[] = "unspecified-fg", unspecified_bg
[] = "unspecified-bg";
343 /* The name of the function to call when the background of the frame
344 has changed, frame_set_background_mode. */
346 Lisp_Object Qframe_set_background_mode
;
348 /* Names of basic faces. */
350 Lisp_Object Qdefault
, Qtool_bar
, Qregion
, Qfringe
;
351 Lisp_Object Qheader_line
, Qscroll_bar
, Qcursor
, Qborder
, Qmouse
, Qmenu
;
352 Lisp_Object Qmode_line_inactive
, Qvertical_border
;
353 extern Lisp_Object Qmode_line
;
355 /* The symbol `face-alias'. A symbols having that property is an
356 alias for another face. Value of the property is the name of
359 Lisp_Object Qface_alias
;
361 extern Lisp_Object Qcircular_list
;
363 /* Default stipple pattern used on monochrome displays. This stipple
364 pattern is used on monochrome displays instead of shades of gray
365 for a face background color. See `set-face-stipple' for possible
366 values for this variable. */
368 Lisp_Object Vface_default_stipple
;
370 /* Alist of alternative font families. Each element is of the form
371 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
372 try FAMILY1, then FAMILY2, ... */
374 Lisp_Object Vface_alternative_font_family_alist
;
376 /* Alist of alternative font registries. Each element is of the form
377 (REGISTRY REGISTRY1 REGISTRY2...). If fonts of REGISTRY can't be
378 loaded, try REGISTRY1, then REGISTRY2, ... */
380 Lisp_Object Vface_alternative_font_registry_alist
;
382 /* Allowed scalable fonts. A value of nil means don't allow any
383 scalable fonts. A value of t means allow the use of any scalable
384 font. Otherwise, value must be a list of regular expressions. A
385 font may be scaled if its name matches a regular expression in the
388 Lisp_Object Vscalable_fonts_allowed
, Qscalable_fonts_allowed
;
390 /* List of regular expressions that matches names of fonts to ignore. */
392 Lisp_Object Vface_ignored_fonts
;
394 /* Alist of font name patterns vs the rescaling factor. */
396 Lisp_Object Vface_font_rescale_alist
;
398 /* Maximum number of fonts to consider in font_list. If not an
399 integer > 0, DEFAULT_FONT_LIST_LIMIT is used instead. */
401 Lisp_Object Vfont_list_limit
;
402 #define DEFAULT_FONT_LIST_LIMIT 100
404 /* The symbols `foreground-color' and `background-color' which can be
405 used as part of a `face' property. This is for compatibility with
408 Lisp_Object Qforeground_color
, Qbackground_color
;
410 /* The symbols `face' and `mouse-face' used as text properties. */
413 extern Lisp_Object Qmouse_face
;
415 /* Property for basic faces which other faces cannot inherit. */
417 Lisp_Object Qface_no_inherit
;
419 /* Error symbol for wrong_type_argument in load_pixmap. */
421 Lisp_Object Qbitmap_spec_p
;
423 /* Alist of global face definitions. Each element is of the form
424 (FACE . LFACE) where FACE is a symbol naming a face and LFACE
425 is a Lisp vector of face attributes. These faces are used
426 to initialize faces for new frames. */
428 Lisp_Object Vface_new_frame_defaults
;
430 /* Alist of face remappings. Each element is of the form:
431 (FACE REPLACEMENT...) which causes display of the face FACE to use
432 REPLACEMENT... instead. REPLACEMENT... is interpreted the same way
433 the value of a `face' text property is: it may be (1) A face name,
434 (2) A list of face names, (3) A property-list of face attribute/value
435 pairs, or (4) A list of face names intermixed with lists containing
436 face attribute/value pairs.
438 Multiple entries in REPLACEMENT... are merged together to form the final
439 result, with faces or attributes earlier in the list taking precedence
440 over those that are later.
442 Face-name remapping cycles are suppressed; recursive references use
443 the underlying face instead of the remapped face. */
445 Lisp_Object Vface_remapping_alist
;
447 /* The next ID to assign to Lisp faces. */
449 static int next_lface_id
;
451 /* A vector mapping Lisp face Id's to face names. */
453 static Lisp_Object
*lface_id_to_name
;
454 static int lface_id_to_name_size
;
456 /* TTY color-related functions (defined in tty-colors.el). */
458 Lisp_Object Qtty_color_desc
, Qtty_color_by_index
, Qtty_color_standard_values
;
460 /* The name of the function used to compute colors on TTYs. */
462 Lisp_Object Qtty_color_alist
;
464 /* An alist of defined terminal colors and their RGB values. */
466 Lisp_Object Vtty_defined_color_alist
;
468 /* Counter for calls to clear_face_cache. If this counter reaches
469 CLEAR_FONT_TABLE_COUNT, and a frame has more than
470 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
472 static int clear_font_table_count
;
473 #define CLEAR_FONT_TABLE_COUNT 100
474 #define CLEAR_FONT_TABLE_NFONTS 10
476 /* Non-zero means face attributes have been changed since the last
477 redisplay. Used in redisplay_internal. */
479 int face_change_count
;
481 /* Non-zero means don't display bold text if a face's foreground
482 and background colors are the inverse of the default colors of the
483 display. This is a kluge to suppress `bold black' foreground text
484 which is hard to read on an LCD monitor. */
486 int tty_suppress_bold_inverse_default_colors_p
;
488 /* A list of the form `((x . y))' used to avoid consing in
489 Finternal_set_lisp_face_attribute. */
491 static Lisp_Object Vparam_value_alist
;
493 /* The total number of colors currently allocated. */
496 static int ncolors_allocated
;
497 static int npixmaps_allocated
;
501 /* Non-zero means the definition of the `menu' face for new frames has
504 int menu_face_changed_default
;
507 /* Function prototypes. */
510 struct named_merge_point
;
512 static void map_tty_color
P_ ((struct frame
*, struct face
*,
513 enum lface_attribute_index
, int *));
514 static Lisp_Object resolve_face_name
P_ ((Lisp_Object
, int));
515 static int may_use_scalable_font_p
P_ ((const char *));
516 static void set_font_frame_param
P_ ((Lisp_Object
, Lisp_Object
));
517 static int get_lface_attributes
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
*,
518 int, struct named_merge_point
*));
519 static int load_pixmap
P_ ((struct frame
*, Lisp_Object
, unsigned *, unsigned *));
520 static struct frame
*frame_or_selected_frame
P_ ((Lisp_Object
, int));
521 static void load_face_colors
P_ ((struct frame
*, struct face
*, Lisp_Object
*));
522 static void free_face_colors
P_ ((struct frame
*, struct face
*));
523 static int face_color_gray_p
P_ ((struct frame
*, char *));
524 static struct face
*realize_face
P_ ((struct face_cache
*, Lisp_Object
*,
526 static struct face
*realize_non_ascii_face
P_ ((struct frame
*, Lisp_Object
,
528 static struct face
*realize_x_face
P_ ((struct face_cache
*, Lisp_Object
*));
529 static struct face
*realize_tty_face
P_ ((struct face_cache
*, Lisp_Object
*));
530 static int realize_basic_faces
P_ ((struct frame
*));
531 static int realize_default_face
P_ ((struct frame
*));
532 static void realize_named_face
P_ ((struct frame
*, Lisp_Object
, int));
533 static int lface_fully_specified_p
P_ ((Lisp_Object
*));
534 static int lface_equal_p
P_ ((Lisp_Object
*, Lisp_Object
*));
535 static unsigned hash_string_case_insensitive
P_ ((Lisp_Object
));
536 static unsigned lface_hash
P_ ((Lisp_Object
*));
537 static int lface_same_font_attributes_p
P_ ((Lisp_Object
*, Lisp_Object
*));
538 static struct face_cache
*make_face_cache
P_ ((struct frame
*));
539 static void clear_face_gcs
P_ ((struct face_cache
*));
540 static void free_face_cache
P_ ((struct face_cache
*));
541 static int face_fontset
P_ ((Lisp_Object
*));
542 static void merge_face_vectors
P_ ((struct frame
*, Lisp_Object
*, Lisp_Object
*,
543 struct named_merge_point
*));
544 static int merge_face_ref
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
*,
545 int, struct named_merge_point
*));
546 static int set_lface_from_font
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
548 static Lisp_Object lface_from_face_name
P_ ((struct frame
*, Lisp_Object
, int));
549 static struct face
*make_realized_face
P_ ((Lisp_Object
*));
550 static void cache_face
P_ ((struct face_cache
*, struct face
*, unsigned));
551 static void uncache_face
P_ ((struct face_cache
*, struct face
*));
553 #ifdef HAVE_WINDOW_SYSTEM
555 static GC x_create_gc
P_ ((struct frame
*, unsigned long, XGCValues
*));
556 static void x_free_gc
P_ ((struct frame
*, GC
));
559 static void x_update_menu_appearance
P_ ((struct frame
*));
561 extern void free_frame_menubar
P_ ((struct frame
*));
562 #endif /* USE_X_TOOLKIT */
564 #endif /* HAVE_WINDOW_SYSTEM */
567 /***********************************************************************
569 ***********************************************************************/
571 #ifdef HAVE_X_WINDOWS
573 #ifdef DEBUG_X_COLORS
575 /* The following is a poor mans infrastructure for debugging X color
576 allocation problems on displays with PseudoColor-8. Some X servers
577 like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement
578 color reference counts completely so that they don't signal an
579 error when a color is freed whose reference count is already 0.
580 Other X servers do. To help me debug this, the following code
581 implements a simple reference counting schema of its own, for a
582 single display/screen. --gerd. */
584 /* Reference counts for pixel colors. */
586 int color_count
[256];
588 /* Register color PIXEL as allocated. */
591 register_color (pixel
)
594 xassert (pixel
< 256);
595 ++color_count
[pixel
];
599 /* Register color PIXEL as deallocated. */
602 unregister_color (pixel
)
605 xassert (pixel
< 256);
606 if (color_count
[pixel
] > 0)
607 --color_count
[pixel
];
613 /* Register N colors from PIXELS as deallocated. */
616 unregister_colors (pixels
, n
)
617 unsigned long *pixels
;
621 for (i
= 0; i
< n
; ++i
)
622 unregister_color (pixels
[i
]);
626 DEFUN ("dump-colors", Fdump_colors
, Sdump_colors
, 0, 0, 0,
627 doc
: /* Dump currently allocated colors to stderr. */)
632 fputc ('\n', stderr
);
634 for (i
= n
= 0; i
< sizeof color_count
/ sizeof color_count
[0]; ++i
)
637 fprintf (stderr
, "%3d: %5d", i
, color_count
[i
]);
640 fputc ('\n', stderr
);
642 fputc ('\t', stderr
);
646 fputc ('\n', stderr
);
650 #endif /* DEBUG_X_COLORS */
653 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
654 color values. Interrupt input must be blocked when this function
658 x_free_colors (f
, pixels
, npixels
)
660 unsigned long *pixels
;
663 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
665 /* If display has an immutable color map, freeing colors is not
666 necessary and some servers don't allow it. So don't do it. */
667 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
669 #ifdef DEBUG_X_COLORS
670 unregister_colors (pixels
, npixels
);
672 XFreeColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
678 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
679 color values. Interrupt input must be blocked when this function
683 x_free_dpy_colors (dpy
, screen
, cmap
, pixels
, npixels
)
687 unsigned long *pixels
;
690 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
691 int class = dpyinfo
->visual
->class;
693 /* If display has an immutable color map, freeing colors is not
694 necessary and some servers don't allow it. So don't do it. */
695 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
697 #ifdef DEBUG_X_COLORS
698 unregister_colors (pixels
, npixels
);
700 XFreeColors (dpy
, cmap
, pixels
, npixels
, 0);
705 /* Create and return a GC for use on frame F. GC values and mask
706 are given by XGCV and MASK. */
709 x_create_gc (f
, mask
, xgcv
)
716 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
723 /* Free GC which was used on frame F. */
730 eassert (interrupt_input_blocked
);
731 IF_DEBUG (xassert (--ngcs
>= 0));
732 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
735 #endif /* HAVE_X_WINDOWS */
738 /* W32 emulation of GCs */
741 x_create_gc (f
, mask
, xgcv
)
748 gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, xgcv
);
755 /* Free GC which was used on frame F. */
762 IF_DEBUG (xassert (--ngcs
>= 0));
766 #endif /* WINDOWSNT */
769 /* NS emulation of GCs */
772 x_create_gc (f
, mask
, xgcv
)
777 GC gc
= xmalloc (sizeof (*gc
));
779 bcopy(xgcv
, gc
, sizeof(XGCValues
));
792 /* Like strcasecmp/stricmp. Used to compare parts of font names which
797 const unsigned char *s1
, *s2
;
801 unsigned char c1
= tolower (*s1
);
802 unsigned char c2
= tolower (*s2
);
804 return c1
< c2
? -1 : 1;
809 return *s2
== 0 ? 0 : -1;
814 /* If FRAME is nil, return a pointer to the selected frame.
815 Otherwise, check that FRAME is a live frame, and return a pointer
816 to it. NPARAM is the parameter number of FRAME, for
817 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
818 Lisp function definitions. */
820 static INLINE
struct frame
*
821 frame_or_selected_frame (frame
, nparam
)
826 frame
= selected_frame
;
828 CHECK_LIVE_FRAME (frame
);
829 return XFRAME (frame
);
833 /***********************************************************************
835 ***********************************************************************/
837 /* Initialize face cache and basic faces for frame F. */
843 /* Make a face cache, if F doesn't have one. */
844 if (FRAME_FACE_CACHE (f
) == NULL
)
845 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
847 #ifdef HAVE_WINDOW_SYSTEM
848 /* Make the image cache. */
849 if (FRAME_WINDOW_P (f
))
851 /* We initialize the image cache when creating the first frame
852 on a terminal, and not during terminal creation. This way,
853 `x-open-connection' on a tty won't create an image cache. */
854 if (FRAME_IMAGE_CACHE (f
) == NULL
)
855 FRAME_IMAGE_CACHE (f
) = make_image_cache ();
856 ++FRAME_IMAGE_CACHE (f
)->refcount
;
858 #endif /* HAVE_WINDOW_SYSTEM */
860 /* Realize basic faces. Must have enough information in frame
861 parameters to realize basic faces at this point. */
862 #ifdef HAVE_X_WINDOWS
863 if (!FRAME_X_P (f
) || FRAME_X_WINDOW (f
))
866 if (!FRAME_WINDOW_P (f
) || FRAME_W32_WINDOW (f
))
869 if (!FRAME_NS_P (f
) || FRAME_NS_WINDOW (f
))
871 if (!realize_basic_faces (f
))
876 /* Free face cache of frame F. Called from delete_frame. */
882 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
886 free_face_cache (face_cache
);
887 FRAME_FACE_CACHE (f
) = NULL
;
890 #ifdef HAVE_WINDOW_SYSTEM
891 if (FRAME_WINDOW_P (f
))
893 struct image_cache
*image_cache
= FRAME_IMAGE_CACHE (f
);
896 --image_cache
->refcount
;
897 if (image_cache
->refcount
== 0)
898 free_image_cache (f
);
901 #endif /* HAVE_WINDOW_SYSTEM */
905 /* Clear face caches, and recompute basic faces for frame F. Call
906 this after changing frame parameters on which those faces depend,
907 or when realized faces have been freed due to changing attributes
911 recompute_basic_faces (f
)
914 if (FRAME_FACE_CACHE (f
))
916 clear_face_cache (0);
917 if (!realize_basic_faces (f
))
923 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
924 try to free unused fonts, too. */
927 clear_face_cache (clear_fonts_p
)
930 #ifdef HAVE_WINDOW_SYSTEM
931 Lisp_Object tail
, frame
;
935 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
938 /* Not yet implemented. */
939 clear_font_cache (frame
);
942 /* From time to time see if we can unload some fonts. This also
943 frees all realized faces on all frames. Fonts needed by
944 faces will be loaded again when faces are realized again. */
945 clear_font_table_count
= 0;
947 FOR_EACH_FRAME (tail
, frame
)
949 struct frame
*f
= XFRAME (frame
);
950 if (FRAME_WINDOW_P (f
)
951 && FRAME_X_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
952 free_all_realized_faces (frame
);
957 /* Clear GCs of realized faces. */
958 FOR_EACH_FRAME (tail
, frame
)
961 if (FRAME_WINDOW_P (f
))
962 clear_face_gcs (FRAME_FACE_CACHE (f
));
964 clear_image_caches (Qnil
);
966 #endif /* HAVE_WINDOW_SYSTEM */
970 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
971 doc
: /* Clear face caches on all frames.
972 Optional THOROUGHLY non-nil means try to free unused fonts, too. */)
974 Lisp_Object thoroughly
;
976 clear_face_cache (!NILP (thoroughly
));
978 ++windows_or_buffers_changed
;
983 /***********************************************************************
985 ***********************************************************************/
987 #ifdef HAVE_WINDOW_SYSTEM
989 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
990 doc
: /* Value is non-nil if OBJECT is a valid bitmap specification.
991 A bitmap specification is either a string, a file name, or a list
992 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
993 HEIGHT is its height, and DATA is a string containing the bits of
994 the pixmap. Bits are stored row by row, each row occupies
995 \(WIDTH + 7)/8 bytes. */)
1001 if (STRINGP (object
))
1002 /* If OBJECT is a string, it's a file name. */
1004 else if (CONSP (object
))
1006 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
1007 HEIGHT must be integers > 0, and DATA must be string large
1008 enough to hold a bitmap of the specified size. */
1009 Lisp_Object width
, height
, data
;
1011 height
= width
= data
= Qnil
;
1015 width
= XCAR (object
);
1016 object
= XCDR (object
);
1019 height
= XCAR (object
);
1020 object
= XCDR (object
);
1022 data
= XCAR (object
);
1026 if (NATNUMP (width
) && NATNUMP (height
) && STRINGP (data
))
1028 int bytes_per_row
= ((XFASTINT (width
) + BITS_PER_CHAR
- 1)
1030 if (SBYTES (data
) >= bytes_per_row
* XINT (height
))
1035 return pixmap_p
? Qt
: Qnil
;
1039 /* Load a bitmap according to NAME (which is either a file name or a
1040 pixmap spec) for use on frame F. Value is the bitmap_id (see
1041 xfns.c). If NAME is nil, return with a bitmap id of zero. If
1042 bitmap cannot be loaded, display a message saying so, and return
1043 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
1044 if these pointers are not null. */
1047 load_pixmap (f
, name
, w_ptr
, h_ptr
)
1050 unsigned int *w_ptr
, *h_ptr
;
1057 CHECK_TYPE (!NILP (Fbitmap_spec_p (name
)), Qbitmap_spec_p
, name
);
1062 /* Decode a bitmap spec into a bitmap. */
1067 w
= XINT (Fcar (name
));
1068 h
= XINT (Fcar (Fcdr (name
)));
1069 bits
= Fcar (Fcdr (Fcdr (name
)));
1071 bitmap_id
= x_create_bitmap_from_data (f
, SDATA (bits
),
1076 /* It must be a string -- a file name. */
1077 bitmap_id
= x_create_bitmap_from_file (f
, name
);
1083 add_to_log ("Invalid or undefined bitmap `%s'", name
, Qnil
);
1094 ++npixmaps_allocated
;
1097 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
1100 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
1106 #endif /* HAVE_WINDOW_SYSTEM */
1110 /***********************************************************************
1112 ***********************************************************************/
1114 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
1115 RGB_LIST should contain (at least) 3 lisp integers.
1116 Return 0 if there's a problem with RGB_LIST, otherwise return 1. */
1119 parse_rgb_list (rgb_list
, color
)
1120 Lisp_Object rgb_list
;
1123 #define PARSE_RGB_LIST_FIELD(field) \
1124 if (CONSP (rgb_list) && INTEGERP (XCAR (rgb_list))) \
1126 color->field = XINT (XCAR (rgb_list)); \
1127 rgb_list = XCDR (rgb_list); \
1132 PARSE_RGB_LIST_FIELD (red
);
1133 PARSE_RGB_LIST_FIELD (green
);
1134 PARSE_RGB_LIST_FIELD (blue
);
1140 /* Lookup on frame F the color described by the lisp string COLOR.
1141 The resulting tty color is returned in TTY_COLOR; if STD_COLOR is
1142 non-zero, then the `standard' definition of the same color is
1146 tty_lookup_color (f
, color
, tty_color
, std_color
)
1149 XColor
*tty_color
, *std_color
;
1151 Lisp_Object frame
, color_desc
;
1153 if (!STRINGP (color
) || NILP (Ffboundp (Qtty_color_desc
)))
1156 XSETFRAME (frame
, f
);
1158 color_desc
= call2 (Qtty_color_desc
, color
, frame
);
1159 if (CONSP (color_desc
) && CONSP (XCDR (color_desc
)))
1163 if (! INTEGERP (XCAR (XCDR (color_desc
))))
1166 tty_color
->pixel
= XINT (XCAR (XCDR (color_desc
)));
1168 rgb
= XCDR (XCDR (color_desc
));
1169 if (! parse_rgb_list (rgb
, tty_color
))
1172 /* Should we fill in STD_COLOR too? */
1175 /* Default STD_COLOR to the same as TTY_COLOR. */
1176 *std_color
= *tty_color
;
1178 /* Do a quick check to see if the returned descriptor is
1179 actually _exactly_ equal to COLOR, otherwise we have to
1180 lookup STD_COLOR separately. If it's impossible to lookup
1181 a standard color, we just give up and use TTY_COLOR. */
1182 if ((!STRINGP (XCAR (color_desc
))
1183 || NILP (Fstring_equal (color
, XCAR (color_desc
))))
1184 && !NILP (Ffboundp (Qtty_color_standard_values
)))
1186 /* Look up STD_COLOR separately. */
1187 rgb
= call1 (Qtty_color_standard_values
, color
);
1188 if (! parse_rgb_list (rgb
, std_color
))
1195 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
1196 /* We were called early during startup, and the colors are not
1197 yet set up in tty-defined-color-alist. Don't return a failure
1198 indication, since this produces the annoying "Unable to
1199 load color" messages in the *Messages* buffer. */
1202 /* tty-color-desc seems to have returned a bad value. */
1206 /* A version of defined_color for non-X frames. */
1209 tty_defined_color (f
, color_name
, color_def
, alloc
)
1218 color_def
->pixel
= FACE_TTY_DEFAULT_COLOR
;
1220 color_def
->blue
= 0;
1221 color_def
->green
= 0;
1224 status
= tty_lookup_color (f
, build_string (color_name
), color_def
, NULL
);
1226 if (color_def
->pixel
== FACE_TTY_DEFAULT_COLOR
&& *color_name
)
1228 if (strcmp (color_name
, "unspecified-fg") == 0)
1229 color_def
->pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
1230 else if (strcmp (color_name
, "unspecified-bg") == 0)
1231 color_def
->pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
1234 if (color_def
->pixel
!= FACE_TTY_DEFAULT_COLOR
)
1241 /* Decide if color named COLOR_NAME is valid for the display
1242 associated with the frame F; if so, return the rgb values in
1243 COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell.
1245 This does the right thing for any type of frame. */
1248 defined_color (f
, color_name
, color_def
, alloc
)
1254 if (!FRAME_WINDOW_P (f
))
1255 return tty_defined_color (f
, color_name
, color_def
, alloc
);
1256 #ifdef HAVE_X_WINDOWS
1257 else if (FRAME_X_P (f
))
1258 return x_defined_color (f
, color_name
, color_def
, alloc
);
1261 else if (FRAME_W32_P (f
))
1262 return w32_defined_color (f
, color_name
, color_def
, alloc
);
1265 else if (FRAME_NS_P (f
))
1266 return ns_defined_color (f
, color_name
, color_def
, alloc
, 1);
1273 /* Given the index IDX of a tty color on frame F, return its name, a
1277 tty_color_name (f
, idx
)
1281 if (idx
>= 0 && !NILP (Ffboundp (Qtty_color_by_index
)))
1284 Lisp_Object coldesc
;
1286 XSETFRAME (frame
, f
);
1287 coldesc
= call2 (Qtty_color_by_index
, make_number (idx
), frame
);
1289 if (!NILP (coldesc
))
1290 return XCAR (coldesc
);
1293 /* We can have an MSDOG frame under -nw for a short window of
1294 opportunity before internal_terminal_init is called. DTRT. */
1295 if (FRAME_MSDOS_P (f
) && !inhibit_window_system
)
1296 return msdos_stdcolor_name (idx
);
1299 if (idx
== FACE_TTY_DEFAULT_FG_COLOR
)
1300 return build_string (unspecified_fg
);
1301 if (idx
== FACE_TTY_DEFAULT_BG_COLOR
)
1302 return build_string (unspecified_bg
);
1304 return Qunspecified
;
1308 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1311 The criterion implemented here is not a terribly sophisticated one. */
1314 face_color_gray_p (f
, color_name
)
1321 if (defined_color (f
, color_name
, &color
, 0))
1322 gray_p
= (/* Any color sufficiently close to black counts as grey. */
1323 (color
.red
< 5000 && color
.green
< 5000 && color
.blue
< 5000)
1325 ((eabs (color
.red
- color
.green
)
1326 < max (color
.red
, color
.green
) / 20)
1327 && (eabs (color
.green
- color
.blue
)
1328 < max (color
.green
, color
.blue
) / 20)
1329 && (eabs (color
.blue
- color
.red
)
1330 < max (color
.blue
, color
.red
) / 20)));
1338 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1339 BACKGROUND_P non-zero means the color will be used as background
1343 face_color_supported_p (f
, color_name
, background_p
)
1351 XSETFRAME (frame
, f
);
1353 #ifdef HAVE_WINDOW_SYSTEM
1355 ? (!NILP (Fxw_display_color_p (frame
))
1356 || xstrcasecmp (color_name
, "black") == 0
1357 || xstrcasecmp (color_name
, "white") == 0
1359 && face_color_gray_p (f
, color_name
))
1360 || (!NILP (Fx_display_grayscale_p (frame
))
1361 && face_color_gray_p (f
, color_name
)))
1364 tty_defined_color (f
, color_name
, ¬_used
, 0);
1368 DEFUN ("color-gray-p", Fcolor_gray_p
, Scolor_gray_p
, 1, 2, 0,
1369 doc
: /* Return non-nil if COLOR is a shade of gray (or white or black).
1370 FRAME specifies the frame and thus the display for interpreting COLOR.
1371 If FRAME is nil or omitted, use the selected frame. */)
1373 Lisp_Object color
, frame
;
1377 CHECK_STRING (color
);
1379 frame
= selected_frame
;
1381 CHECK_FRAME (frame
);
1383 return face_color_gray_p (f
, SDATA (color
)) ? Qt
: Qnil
;
1387 DEFUN ("color-supported-p", Fcolor_supported_p
,
1388 Scolor_supported_p
, 1, 3, 0,
1389 doc
: /* Return non-nil if COLOR can be displayed on FRAME.
1390 BACKGROUND-P non-nil means COLOR is used as a background.
1391 Otherwise, this function tells whether it can be used as a foreground.
1392 If FRAME is nil or omitted, use the selected frame.
1393 COLOR must be a valid color name. */)
1394 (color
, frame
, background_p
)
1395 Lisp_Object frame
, color
, background_p
;
1399 CHECK_STRING (color
);
1401 frame
= selected_frame
;
1403 CHECK_FRAME (frame
);
1405 if (face_color_supported_p (f
, SDATA (color
), !NILP (background_p
)))
1411 /* Load color with name NAME for use by face FACE on frame F.
1412 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1413 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1414 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1415 pixel color. If color cannot be loaded, display a message, and
1416 return the foreground, background or underline color of F, but
1417 record that fact in flags of the face so that we don't try to free
1421 load_color (f
, face
, name
, target_index
)
1425 enum lface_attribute_index target_index
;
1429 xassert (STRINGP (name
));
1430 xassert (target_index
== LFACE_FOREGROUND_INDEX
1431 || target_index
== LFACE_BACKGROUND_INDEX
1432 || target_index
== LFACE_UNDERLINE_INDEX
1433 || target_index
== LFACE_OVERLINE_INDEX
1434 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1435 || target_index
== LFACE_BOX_INDEX
);
1437 /* if the color map is full, defined_color will return a best match
1438 to the values in an existing cell. */
1439 if (!defined_color (f
, SDATA (name
), &color
, 1))
1441 add_to_log ("Unable to load color \"%s\"", name
, Qnil
);
1443 switch (target_index
)
1445 case LFACE_FOREGROUND_INDEX
:
1446 face
->foreground_defaulted_p
= 1;
1447 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1450 case LFACE_BACKGROUND_INDEX
:
1451 face
->background_defaulted_p
= 1;
1452 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1455 case LFACE_UNDERLINE_INDEX
:
1456 face
->underline_defaulted_p
= 1;
1457 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1460 case LFACE_OVERLINE_INDEX
:
1461 face
->overline_color_defaulted_p
= 1;
1462 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1465 case LFACE_STRIKE_THROUGH_INDEX
:
1466 face
->strike_through_color_defaulted_p
= 1;
1467 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1470 case LFACE_BOX_INDEX
:
1471 face
->box_color_defaulted_p
= 1;
1472 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1481 ++ncolors_allocated
;
1488 #ifdef HAVE_WINDOW_SYSTEM
1490 /* Load colors for face FACE which is used on frame F. Colors are
1491 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1492 of ATTRS. If the background color specified is not supported on F,
1493 try to emulate gray colors with a stipple from Vface_default_stipple. */
1496 load_face_colors (f
, face
, attrs
)
1503 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1504 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1506 /* Swap colors if face is inverse-video. */
1507 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1515 /* Check for support for foreground, not for background because
1516 face_color_supported_p is smart enough to know that grays are
1517 "supported" as background because we are supposed to use stipple
1519 if (!face_color_supported_p (f
, SDATA (bg
), 0)
1520 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1522 x_destroy_bitmap (f
, face
->stipple
);
1523 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1524 &face
->pixmap_w
, &face
->pixmap_h
);
1527 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1528 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1532 /* Free color PIXEL on frame F. */
1535 unload_color (f
, pixel
)
1537 unsigned long pixel
;
1539 #ifdef HAVE_X_WINDOWS
1543 x_free_colors (f
, &pixel
, 1);
1550 /* Free colors allocated for FACE. */
1553 free_face_colors (f
, face
)
1557 /* PENDING(NS): need to do something here? */
1558 #ifdef HAVE_X_WINDOWS
1559 if (face
->colors_copied_bitwise_p
)
1564 if (!face
->foreground_defaulted_p
)
1566 x_free_colors (f
, &face
->foreground
, 1);
1567 IF_DEBUG (--ncolors_allocated
);
1570 if (!face
->background_defaulted_p
)
1572 x_free_colors (f
, &face
->background
, 1);
1573 IF_DEBUG (--ncolors_allocated
);
1576 if (face
->underline_p
1577 && !face
->underline_defaulted_p
)
1579 x_free_colors (f
, &face
->underline_color
, 1);
1580 IF_DEBUG (--ncolors_allocated
);
1583 if (face
->overline_p
1584 && !face
->overline_color_defaulted_p
)
1586 x_free_colors (f
, &face
->overline_color
, 1);
1587 IF_DEBUG (--ncolors_allocated
);
1590 if (face
->strike_through_p
1591 && !face
->strike_through_color_defaulted_p
)
1593 x_free_colors (f
, &face
->strike_through_color
, 1);
1594 IF_DEBUG (--ncolors_allocated
);
1597 if (face
->box
!= FACE_NO_BOX
1598 && !face
->box_color_defaulted_p
)
1600 x_free_colors (f
, &face
->box_color
, 1);
1601 IF_DEBUG (--ncolors_allocated
);
1605 #endif /* HAVE_X_WINDOWS */
1608 #endif /* HAVE_WINDOW_SYSTEM */
1612 /***********************************************************************
1614 ***********************************************************************/
1616 /* An enumerator for each field of an XLFD font name. */
1637 /* An enumerator for each possible slant value of a font. Taken from
1638 the XLFD specification. */
1646 XLFD_SLANT_REVERSE_ITALIC
,
1647 XLFD_SLANT_REVERSE_OBLIQUE
,
1651 /* Relative font weight according to XLFD documentation. */
1655 XLFD_WEIGHT_UNKNOWN
,
1656 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1657 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1658 XLFD_WEIGHT_LIGHT
, /* 30 */
1659 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1660 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1661 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1662 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1663 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1664 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1667 /* Relative proportionate width. */
1671 XLFD_SWIDTH_UNKNOWN
,
1672 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1673 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1674 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1675 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1676 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1677 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1678 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1679 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1680 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1683 /* Order by which font selection chooses fonts. The default values
1684 mean `first, find a best match for the font width, then for the
1685 font height, then for weight, then for slant.' This variable can be
1686 set via set-face-font-sort-order. */
1688 static int font_sort_order
[4];
1690 #ifdef HAVE_WINDOW_SYSTEM
1692 static enum font_property_index font_props_for_sorting
[FONT_SIZE_INDEX
];
1695 compare_fonts_by_sort_order (v1
, v2
)
1696 const void *v1
, *v2
;
1698 Lisp_Object font1
= *(Lisp_Object
*) v1
;
1699 Lisp_Object font2
= *(Lisp_Object
*) v2
;
1702 for (i
= 0; i
< FONT_SIZE_INDEX
; i
++)
1704 enum font_property_index idx
= font_props_for_sorting
[i
];
1705 Lisp_Object val1
= AREF (font1
, idx
), val2
= AREF (font2
, idx
);
1708 if (idx
<= FONT_REGISTRY_INDEX
)
1711 result
= STRINGP (val2
) ? strcmp (SDATA (val1
), SDATA (val2
)) : -1;
1713 result
= STRINGP (val2
) ? 1 : 0;
1717 if (INTEGERP (val1
))
1718 result
= INTEGERP (val2
) ? XINT (val1
) - XINT (val2
) : -1;
1720 result
= INTEGERP (val2
) ? 1 : 0;
1728 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
1729 doc
: /* Return a list of available fonts of family FAMILY on FRAME.
1730 If FAMILY is omitted or nil, list all families.
1731 Otherwise, FAMILY must be a string, possibly containing wildcards
1733 If FRAME is omitted or nil, use the selected frame.
1734 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
1735 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
1736 FAMILY is the font family name. POINT-SIZE is the size of the
1737 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
1738 width, weight and slant of the font. These symbols are the same as for
1739 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
1740 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
1741 giving the registry and encoding of the font.
1742 The result list is sorted according to the current setting of
1743 the face font sort order. */)
1745 Lisp_Object family
, frame
;
1747 Lisp_Object font_spec
, vec
;
1752 frame
= selected_frame
;
1753 CHECK_LIVE_FRAME (frame
);
1755 font_spec
= Ffont_spec (0, NULL
);
1758 CHECK_STRING (family
);
1759 font_parse_family_registry (family
, Qnil
, font_spec
);
1761 vec
= font_list_entities (frame
, font_spec
);
1762 nfonts
= ASIZE (vec
);
1767 for (i
= 0; i
< 4; i
++)
1768 switch (font_sort_order
[i
])
1771 font_props_for_sorting
[i
] = FONT_WIDTH_INDEX
; break;
1772 case XLFD_POINT_SIZE
:
1773 font_props_for_sorting
[i
] = FONT_SIZE_INDEX
; break;
1775 font_props_for_sorting
[i
] = FONT_WEIGHT_INDEX
; break;
1777 font_props_for_sorting
[i
] = FONT_SLANT_INDEX
; break;
1779 font_props_for_sorting
[i
++] = FONT_FAMILY_INDEX
;
1780 font_props_for_sorting
[i
++] = FONT_FOUNDRY_INDEX
;
1781 font_props_for_sorting
[i
++] = FONT_ADSTYLE_INDEX
;
1782 font_props_for_sorting
[i
++] = FONT_REGISTRY_INDEX
;
1784 qsort (XVECTOR (vec
)->contents
, nfonts
, sizeof (Lisp_Object
),
1785 compare_fonts_by_sort_order
);
1789 for (i
= nfonts
- 1; i
>= 0; --i
)
1791 Lisp_Object font
= AREF (vec
, i
);
1792 Lisp_Object v
= Fmake_vector (make_number (8), Qnil
);
1794 Lisp_Object spacing
;
1796 ASET (v
, 0, AREF (font
, FONT_FAMILY_INDEX
));
1797 ASET (v
, 1, FONT_WIDTH_SYMBOLIC (font
));
1798 point
= PIXEL_TO_POINT (XINT (AREF (font
, FONT_SIZE_INDEX
)) * 10,
1799 XFRAME (frame
)->resy
);
1800 ASET (v
, 2, make_number (point
));
1801 ASET (v
, 3, FONT_WEIGHT_SYMBOLIC (font
));
1802 ASET (v
, 4, FONT_SLANT_SYMBOLIC (font
));
1803 spacing
= Ffont_get (font
, QCspacing
);
1804 ASET (v
, 5, (NILP (spacing
) || EQ (spacing
, Qp
)) ? Qnil
: Qt
);
1805 ASET (v
, 6, Ffont_xlfd_name (font
, Qnil
));
1806 ASET (v
, 7, AREF (font
, FONT_REGISTRY_INDEX
));
1808 result
= Fcons (v
, result
);
1814 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
1815 doc
: /* Return a list of the names of available fonts matching PATTERN.
1816 If optional arguments FACE and FRAME are specified, return only fonts
1817 the same size as FACE on FRAME.
1819 PATTERN should be a string containing a font name in the XLFD,
1820 Fontconfig, or GTK format. A font name given in the XLFD format may
1821 contain wildcard characters:
1822 the * character matches any substring, and
1823 the ? character matches any single character.
1824 PATTERN is case-insensitive.
1826 The return value is a list of strings, suitable as arguments to
1829 Fonts Emacs can't use may or may not be excluded
1830 even if they match PATTERN and FACE.
1831 The optional fourth argument MAXIMUM sets a limit on how many
1832 fonts to match. The first MAXIMUM fonts are reported.
1833 The optional fifth argument WIDTH, if specified, is a number of columns
1834 occupied by a character of a font. In that case, return only fonts
1835 the WIDTH times as wide as FACE on FRAME. */)
1836 (pattern
, face
, frame
, maximum
, width
)
1837 Lisp_Object pattern
, face
, frame
, maximum
, width
;
1843 CHECK_STRING (pattern
);
1845 if (! NILP (maximum
))
1846 CHECK_NATNUM (maximum
);
1849 CHECK_NUMBER (width
);
1851 /* We can't simply call check_x_frame because this function may be
1852 called before any frame is created. */
1854 frame
= selected_frame
;
1855 f
= frame_or_selected_frame (frame
, 2);
1856 if (! FRAME_WINDOW_P (f
))
1858 /* Perhaps we have not yet created any frame. */
1864 /* Determine the width standard for comparison with the fonts we find. */
1870 /* This is of limited utility since it works with character
1871 widths. Keep it for compatibility. --gerd. */
1872 int face_id
= lookup_named_face (f
, face
, 0);
1873 struct face
*face
= (face_id
< 0
1875 : FACE_FROM_ID (f
, face_id
));
1877 if (face
&& face
->font
)
1879 size
= face
->font
->pixel_size
;
1880 avgwidth
= face
->font
->average_width
;
1884 size
= FRAME_FONT (f
)->pixel_size
;
1885 avgwidth
= FRAME_FONT (f
)->average_width
;
1888 avgwidth
*= XINT (width
);
1892 Lisp_Object font_spec
;
1893 Lisp_Object args
[2], tail
;
1895 font_spec
= font_spec_from_name (pattern
);
1896 if (!FONTP (font_spec
))
1897 signal_error ("Invalid font name", pattern
);
1901 Ffont_put (font_spec
, QCsize
, make_number (size
));
1902 Ffont_put (font_spec
, QCavgwidth
, make_number (avgwidth
));
1904 args
[0] = Flist_fonts (font_spec
, frame
, maximum
, font_spec
);
1905 for (tail
= args
[0]; CONSP (tail
); tail
= XCDR (tail
))
1907 Lisp_Object font_entity
;
1909 font_entity
= XCAR (tail
);
1910 if ((NILP (AREF (font_entity
, FONT_SIZE_INDEX
))
1911 || XINT (AREF (font_entity
, FONT_SIZE_INDEX
)) == 0)
1912 && ! NILP (AREF (font_spec
, FONT_SIZE_INDEX
)))
1914 /* This is a scalable font. For backward compatibility,
1915 we set the specified size. */
1916 font_entity
= Fcopy_font_spec (font_entity
);
1917 ASET (font_entity
, FONT_SIZE_INDEX
,
1918 AREF (font_spec
, FONT_SIZE_INDEX
));
1920 XSETCAR (tail
, Ffont_xlfd_name (font_entity
, Qnil
));
1923 /* We don't have to check fontsets. */
1925 args
[1] = list_fontsets (f
, pattern
, size
);
1926 return Fnconc (2, args
);
1930 #endif /* HAVE_WINDOW_SYSTEM */
1933 /***********************************************************************
1935 ***********************************************************************/
1937 /* Access face attributes of face LFACE, a Lisp vector. */
1939 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
1940 #define LFACE_FOUNDRY(LFACE) AREF ((LFACE), LFACE_FOUNDRY_INDEX)
1941 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
1942 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
1943 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
1944 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
1945 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
1946 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
1947 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
1948 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
1949 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
1950 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
1951 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
1952 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
1953 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
1954 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
1955 #define LFACE_FONTSET(LFACE) AREF ((LFACE), LFACE_FONTSET_INDEX)
1957 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
1958 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
1960 #define LFACEP(LFACE) \
1962 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \
1963 && EQ (AREF (LFACE, 0), Qface))
1968 /* Check consistency of Lisp face attribute vector ATTRS. */
1971 check_lface_attrs (attrs
)
1974 xassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
1975 || IGNORE_DEFFACE_P (attrs
[LFACE_FAMILY_INDEX
])
1976 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
1977 xassert (UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
1978 || IGNORE_DEFFACE_P (attrs
[LFACE_FOUNDRY_INDEX
])
1979 || STRINGP (attrs
[LFACE_FOUNDRY_INDEX
]));
1980 xassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
1981 || IGNORE_DEFFACE_P (attrs
[LFACE_SWIDTH_INDEX
])
1982 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
1983 xassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
1984 || IGNORE_DEFFACE_P (attrs
[LFACE_HEIGHT_INDEX
])
1985 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
])
1986 || FLOATP (attrs
[LFACE_HEIGHT_INDEX
])
1987 || FUNCTIONP (attrs
[LFACE_HEIGHT_INDEX
]));
1988 xassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
1989 || IGNORE_DEFFACE_P (attrs
[LFACE_WEIGHT_INDEX
])
1990 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
1991 xassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
1992 || IGNORE_DEFFACE_P (attrs
[LFACE_SLANT_INDEX
])
1993 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
1994 xassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
1995 || IGNORE_DEFFACE_P (attrs
[LFACE_UNDERLINE_INDEX
])
1996 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
1997 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]));
1998 xassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
1999 || IGNORE_DEFFACE_P (attrs
[LFACE_OVERLINE_INDEX
])
2000 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
2001 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
2002 xassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
2003 || IGNORE_DEFFACE_P (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
2004 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
2005 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
2006 xassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
2007 || IGNORE_DEFFACE_P (attrs
[LFACE_BOX_INDEX
])
2008 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
2009 || STRINGP (attrs
[LFACE_BOX_INDEX
])
2010 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
2011 || CONSP (attrs
[LFACE_BOX_INDEX
]));
2012 xassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
2013 || IGNORE_DEFFACE_P (attrs
[LFACE_INVERSE_INDEX
])
2014 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
2015 xassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
2016 || IGNORE_DEFFACE_P (attrs
[LFACE_FOREGROUND_INDEX
])
2017 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
2018 xassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
2019 || IGNORE_DEFFACE_P (attrs
[LFACE_BACKGROUND_INDEX
])
2020 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
2021 xassert (UNSPECIFIEDP (attrs
[LFACE_INHERIT_INDEX
])
2022 || IGNORE_DEFFACE_P (attrs
[LFACE_INHERIT_INDEX
])
2023 || NILP (attrs
[LFACE_INHERIT_INDEX
])
2024 || SYMBOLP (attrs
[LFACE_INHERIT_INDEX
])
2025 || CONSP (attrs
[LFACE_INHERIT_INDEX
]));
2026 #ifdef HAVE_WINDOW_SYSTEM
2027 xassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
2028 || IGNORE_DEFFACE_P (attrs
[LFACE_STIPPLE_INDEX
])
2029 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
2030 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
2031 xassert (UNSPECIFIEDP (attrs
[LFACE_FONT_INDEX
])
2032 || IGNORE_DEFFACE_P (attrs
[LFACE_FONT_INDEX
])
2033 || FONTP (attrs
[LFACE_FONT_INDEX
]));
2034 xassert (UNSPECIFIEDP (attrs
[LFACE_FONTSET_INDEX
])
2035 || STRINGP (attrs
[LFACE_FONTSET_INDEX
]));
2040 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
2048 xassert (LFACEP (lface
));
2049 check_lface_attrs (XVECTOR (lface
)->contents
);
2053 #else /* GLYPH_DEBUG == 0 */
2055 #define check_lface_attrs(attrs) (void) 0
2056 #define check_lface(lface) (void) 0
2058 #endif /* GLYPH_DEBUG == 0 */
2062 /* Face-merge cycle checking. */
2064 enum named_merge_point_kind
2066 NAMED_MERGE_POINT_NORMAL
,
2067 NAMED_MERGE_POINT_REMAP
2070 /* A `named merge point' is simply a point during face-merging where we
2071 look up a face by name. We keep a stack of which named lookups we're
2072 currently processing so that we can easily detect cycles, using a
2073 linked- list of struct named_merge_point structures, typically
2074 allocated on the stack frame of the named lookup functions which are
2075 active (so no consing is required). */
2076 struct named_merge_point
2078 Lisp_Object face_name
;
2079 enum named_merge_point_kind named_merge_point_kind
;
2080 struct named_merge_point
*prev
;
2084 /* If a face merging cycle is detected for FACE_NAME, return 0,
2085 otherwise add NEW_NAMED_MERGE_POINT, which is initialized using
2086 FACE_NAME and NAMED_MERGE_POINT_KIND, as the head of the linked list
2087 pointed to by NAMED_MERGE_POINTS, and return 1. */
2090 push_named_merge_point (struct named_merge_point
*new_named_merge_point
,
2091 Lisp_Object face_name
,
2092 enum named_merge_point_kind named_merge_point_kind
,
2093 struct named_merge_point
**named_merge_points
)
2095 struct named_merge_point
*prev
;
2097 for (prev
= *named_merge_points
; prev
; prev
= prev
->prev
)
2098 if (EQ (face_name
, prev
->face_name
))
2100 if (prev
->named_merge_point_kind
== named_merge_point_kind
)
2101 /* A cycle, so fail. */
2103 else if (prev
->named_merge_point_kind
== NAMED_MERGE_POINT_REMAP
)
2104 /* A remap `hides ' any previous normal merge points
2105 (because the remap means that it's actually different face),
2106 so as we know the current merge point must be normal, we
2107 can just assume it's OK. */
2111 new_named_merge_point
->face_name
= face_name
;
2112 new_named_merge_point
->named_merge_point_kind
= named_merge_point_kind
;
2113 new_named_merge_point
->prev
= *named_merge_points
;
2115 *named_merge_points
= new_named_merge_point
;
2122 #if 0 /* Seems to be unused. */
2124 internal_resolve_face_name (nargs
, args
)
2128 return Fget (args
[0], args
[1]);
2132 resolve_face_name_error (ignore
)
2139 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
2140 to make it a symbol. If FACE_NAME is an alias for another face,
2141 return that face's name.
2143 Return default face in case of errors. */
2146 resolve_face_name (face_name
, signal_p
)
2147 Lisp_Object face_name
;
2150 Lisp_Object orig_face
;
2151 Lisp_Object tortoise
, hare
;
2153 if (STRINGP (face_name
))
2154 face_name
= intern (SDATA (face_name
));
2156 if (NILP (face_name
) || !SYMBOLP (face_name
))
2159 orig_face
= face_name
;
2160 tortoise
= hare
= face_name
;
2165 hare
= Fget (hare
, Qface_alias
);
2166 if (NILP (hare
) || !SYMBOLP (hare
))
2170 hare
= Fget (hare
, Qface_alias
);
2171 if (NILP (hare
) || !SYMBOLP (hare
))
2174 tortoise
= Fget (tortoise
, Qface_alias
);
2175 if (EQ (hare
, tortoise
))
2178 xsignal1 (Qcircular_list
, orig_face
);
2187 /* Return the face definition of FACE_NAME on frame F. F null means
2188 return the definition for new frames. FACE_NAME may be a string or
2189 a symbol (apparently Emacs 20.2 allowed strings as face names in
2190 face text properties; Ediff uses that). If SIGNAL_P is non-zero,
2191 signal an error if FACE_NAME is not a valid face name. If SIGNAL_P
2192 is zero, value is nil if FACE_NAME is not a valid face name. */
2193 static INLINE Lisp_Object
2194 lface_from_face_name_no_resolve (f
, face_name
, signal_p
)
2196 Lisp_Object face_name
;
2202 lface
= assq_no_quit (face_name
, f
->face_alist
);
2204 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
2207 lface
= XCDR (lface
);
2209 signal_error ("Invalid face", face_name
);
2211 check_lface (lface
);
2216 /* Return the face definition of FACE_NAME on frame F. F null means
2217 return the definition for new frames. FACE_NAME may be a string or
2218 a symbol (apparently Emacs 20.2 allowed strings as face names in
2219 face text properties; Ediff uses that). If FACE_NAME is an alias
2220 for another face, return that face's definition. If SIGNAL_P is
2221 non-zero, signal an error if FACE_NAME is not a valid face name.
2222 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
2224 static INLINE Lisp_Object
2225 lface_from_face_name (f
, face_name
, signal_p
)
2227 Lisp_Object face_name
;
2230 face_name
= resolve_face_name (face_name
, signal_p
);
2231 return lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2235 /* Get face attributes of face FACE_NAME from frame-local faces on
2236 frame F. Store the resulting attributes in ATTRS which must point
2237 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
2238 is non-zero, signal an error if FACE_NAME does not name a face.
2239 Otherwise, value is zero if FACE_NAME is not a face. */
2242 get_lface_attributes_no_remap (f
, face_name
, attrs
, signal_p
)
2244 Lisp_Object face_name
;
2250 lface
= lface_from_face_name_no_resolve (f
, face_name
, signal_p
);
2253 bcopy (XVECTOR (lface
)->contents
, attrs
,
2254 LFACE_VECTOR_SIZE
* sizeof *attrs
);
2256 return !NILP (lface
);
2259 /* Get face attributes of face FACE_NAME from frame-local faces on frame
2260 F. Store the resulting attributes in ATTRS which must point to a
2261 vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If FACE_NAME is an
2262 alias for another face, use that face's definition. If SIGNAL_P is
2263 non-zero, signal an error if FACE_NAME does not name a face.
2264 Otherwise, value is zero if FACE_NAME is not a face. */
2267 get_lface_attributes (f
, face_name
, attrs
, signal_p
, named_merge_points
)
2269 Lisp_Object face_name
;
2272 struct named_merge_point
*named_merge_points
;
2274 Lisp_Object face_remapping
;
2276 face_name
= resolve_face_name (face_name
, signal_p
);
2278 /* See if SYMBOL has been remapped to some other face (usually this
2279 is done buffer-locally). */
2280 face_remapping
= assq_no_quit (face_name
, Vface_remapping_alist
);
2281 if (CONSP (face_remapping
))
2283 struct named_merge_point named_merge_point
;
2285 if (push_named_merge_point (&named_merge_point
,
2286 face_name
, NAMED_MERGE_POINT_REMAP
,
2287 &named_merge_points
))
2291 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2292 attrs
[i
] = Qunspecified
;
2294 return merge_face_ref (f
, XCDR (face_remapping
), attrs
,
2295 signal_p
, named_merge_points
);
2299 /* Default case, no remapping. */
2300 return get_lface_attributes_no_remap (f
, face_name
, attrs
, signal_p
);
2304 /* Non-zero if all attributes in face attribute vector ATTRS are
2305 specified, i.e. are non-nil. */
2308 lface_fully_specified_p (attrs
)
2313 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2314 if (i
!= LFACE_FONT_INDEX
&& i
!= LFACE_INHERIT_INDEX
)
2315 if ((UNSPECIFIEDP (attrs
[i
]) || IGNORE_DEFFACE_P (attrs
[i
])))
2318 return i
== LFACE_VECTOR_SIZE
;
2321 #ifdef HAVE_WINDOW_SYSTEM
2323 /* Set font-related attributes of Lisp face LFACE from FONT-OBJECT.
2324 If FORCE_P is zero, set only unspecified attributes of LFACE. The
2325 exception is `font' attribute. It is set to FONT_OBJECT regardless
2329 set_lface_from_font (f
, lface
, font_object
, force_p
)
2331 Lisp_Object lface
, font_object
;
2335 struct font
*font
= XFONT_OBJECT (font_object
);
2337 /* Set attributes only if unspecified, otherwise face defaults for
2338 new frames would never take effect. If the font doesn't have a
2339 specific property, set a normal value for that. */
2341 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
2343 Lisp_Object family
= AREF (font_object
, FONT_FAMILY_INDEX
);
2345 LFACE_FAMILY (lface
) = SYMBOL_NAME (family
);
2348 if (force_p
|| UNSPECIFIEDP (LFACE_FOUNDRY (lface
)))
2350 Lisp_Object foundry
= AREF (font_object
, FONT_FOUNDRY_INDEX
);
2352 LFACE_FOUNDRY (lface
) = SYMBOL_NAME (foundry
);
2355 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
2357 int pt
= PIXEL_TO_POINT (font
->pixel_size
* 10, f
->resy
);
2360 LFACE_HEIGHT (lface
) = make_number (pt
);
2363 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
2365 val
= FONT_WEIGHT_FOR_FACE (font_object
);
2366 LFACE_WEIGHT (lface
) = ! NILP (val
) ? val
:Qnormal
;
2368 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
2370 val
= FONT_SLANT_FOR_FACE (font_object
);
2371 LFACE_SLANT (lface
) = ! NILP (val
) ? val
: Qnormal
;
2373 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
2375 val
= FONT_WIDTH_FOR_FACE (font_object
);
2376 LFACE_SWIDTH (lface
) = ! NILP (val
) ? val
: Qnormal
;
2379 LFACE_FONT (lface
) = font_object
;
2383 #endif /* HAVE_WINDOW_SYSTEM */
2386 /* Merges the face height FROM with the face height TO, and returns the
2387 merged height. If FROM is an invalid height, then INVALID is
2388 returned instead. FROM and TO may be either absolute face heights or
2389 `relative' heights; the returned value is always an absolute height
2390 unless both FROM and TO are relative. */
2393 merge_face_heights (from
, to
, invalid
)
2394 Lisp_Object from
, to
, invalid
;
2396 Lisp_Object result
= invalid
;
2398 if (INTEGERP (from
))
2399 /* FROM is absolute, just use it as is. */
2401 else if (FLOATP (from
))
2402 /* FROM is a scale, use it to adjust TO. */
2405 /* relative X absolute => absolute */
2406 result
= make_number ((EMACS_INT
)(XFLOAT_DATA (from
) * XINT (to
)));
2407 else if (FLOATP (to
))
2408 /* relative X relative => relative */
2409 result
= make_float (XFLOAT_DATA (from
) * XFLOAT_DATA (to
));
2410 else if (UNSPECIFIEDP (to
))
2413 else if (FUNCTIONP (from
))
2414 /* FROM is a function, which use to adjust TO. */
2416 /* Call function with current height as argument.
2417 From is the new height. */
2418 Lisp_Object args
[2];
2422 result
= safe_call (2, args
);
2424 /* Ensure that if TO was absolute, so is the result. */
2425 if (INTEGERP (to
) && !INTEGERP (result
))
2433 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
2434 store the resulting attributes in TO, which must be already be
2435 completely specified and contain only absolute attributes. Every
2436 specified attribute of FROM overrides the corresponding attribute of
2437 TO; relative attributes in FROM are merged with the absolute value in
2438 TO and replace it. NAMED_MERGE_POINTS is used internally to detect
2439 loops in face inheritance/remapping; it should be 0 when called from
2443 merge_face_vectors (f
, from
, to
, named_merge_points
)
2445 Lisp_Object
*from
, *to
;
2446 struct named_merge_point
*named_merge_points
;
2450 /* If FROM inherits from some other faces, merge their attributes into
2451 TO before merging FROM's direct attributes. Note that an :inherit
2452 attribute of `unspecified' is the same as one of nil; we never
2453 merge :inherit attributes, so nil is more correct, but lots of
2454 other code uses `unspecified' as a generic value for face attributes. */
2455 if (!UNSPECIFIEDP (from
[LFACE_INHERIT_INDEX
])
2456 && !NILP (from
[LFACE_INHERIT_INDEX
]))
2457 merge_face_ref (f
, from
[LFACE_INHERIT_INDEX
], to
, 0, named_merge_points
);
2459 i
= LFACE_FONT_INDEX
;
2460 if (!UNSPECIFIEDP (from
[i
]))
2462 if (!UNSPECIFIEDP (to
[i
]))
2463 to
[i
] = Fmerge_font_spec (from
[i
], to
[i
]);
2465 to
[i
] = Fcopy_font_spec (from
[i
]);
2466 if (! NILP (AREF (to
[i
], FONT_FOUNDRY_INDEX
)))
2467 to
[LFACE_FOUNDRY_INDEX
] = SYMBOL_NAME (AREF (to
[i
], FONT_FOUNDRY_INDEX
));
2468 if (! NILP (AREF (to
[i
], FONT_FAMILY_INDEX
)))
2469 to
[LFACE_FAMILY_INDEX
] = SYMBOL_NAME (AREF (to
[i
], FONT_FAMILY_INDEX
));
2470 if (! NILP (AREF (to
[i
], FONT_WEIGHT_INDEX
)))
2471 to
[LFACE_WEIGHT_INDEX
] = FONT_WEIGHT_FOR_FACE (to
[i
]);
2472 if (! NILP (AREF (to
[i
], FONT_SLANT_INDEX
)))
2473 to
[LFACE_SLANT_INDEX
] = FONT_SLANT_FOR_FACE (to
[i
]);
2474 if (! NILP (AREF (to
[i
], FONT_WIDTH_INDEX
)))
2475 to
[LFACE_SWIDTH_INDEX
] = FONT_WIDTH_FOR_FACE (to
[i
]);
2476 ASET (to
[i
], FONT_SIZE_INDEX
, Qnil
);
2479 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2480 if (!UNSPECIFIEDP (from
[i
]))
2482 if (i
== LFACE_HEIGHT_INDEX
&& !INTEGERP (from
[i
]))
2484 to
[i
] = merge_face_heights (from
[i
], to
[i
], to
[i
]);
2485 font_clear_prop (to
, FONT_SIZE_INDEX
);
2487 else if (i
!= LFACE_FONT_INDEX
2488 && ! EQ (to
[i
], from
[i
]))
2491 if (i
>= LFACE_FAMILY_INDEX
&& i
<=LFACE_SLANT_INDEX
)
2492 font_clear_prop (to
,
2493 (i
== LFACE_FAMILY_INDEX
? FONT_FAMILY_INDEX
2494 : i
== LFACE_FOUNDRY_INDEX
? FONT_FOUNDRY_INDEX
2495 : i
== LFACE_SWIDTH_INDEX
? FONT_WIDTH_INDEX
2496 : i
== LFACE_HEIGHT_INDEX
? FONT_SIZE_INDEX
2497 : i
== LFACE_WEIGHT_INDEX
? FONT_WEIGHT_INDEX
2498 : FONT_SLANT_INDEX
));
2502 /* TO is always an absolute face, which should inherit from nothing.
2503 We blindly copy the :inherit attribute above and fix it up here. */
2504 to
[LFACE_INHERIT_INDEX
] = Qnil
;
2507 /* Merge the named face FACE_NAME on frame F, into the vector of face
2508 attributes TO. NAMED_MERGE_POINTS is used to detect loops in face
2509 inheritance. Returns true if FACE_NAME is a valid face name and
2510 merging succeeded. */
2513 merge_named_face (f
, face_name
, to
, named_merge_points
)
2515 Lisp_Object face_name
;
2517 struct named_merge_point
*named_merge_points
;
2519 struct named_merge_point named_merge_point
;
2521 if (push_named_merge_point (&named_merge_point
,
2522 face_name
, NAMED_MERGE_POINT_NORMAL
,
2523 &named_merge_points
))
2525 struct gcpro gcpro1
;
2526 Lisp_Object from
[LFACE_VECTOR_SIZE
];
2527 int ok
= get_lface_attributes (f
, face_name
, from
, 0, named_merge_points
);
2531 GCPRO1 (named_merge_point
.face_name
);
2532 merge_face_vectors (f
, from
, to
, named_merge_points
);
2543 /* Merge face attributes from the lisp `face reference' FACE_REF on
2544 frame F into the face attribute vector TO. If ERR_MSGS is non-zero,
2545 problems with FACE_REF cause an error message to be shown. Return
2546 non-zero if no errors occurred (regardless of the value of ERR_MSGS).
2547 NAMED_MERGE_POINTS is used to detect loops in face inheritance or
2548 list structure; it may be 0 for most callers.
2550 FACE_REF may be a single face specification or a list of such
2551 specifications. Each face specification can be:
2553 1. A symbol or string naming a Lisp face.
2555 2. A property list of the form (KEYWORD VALUE ...) where each
2556 KEYWORD is a face attribute name, and value is an appropriate value
2559 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
2560 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
2561 for compatibility with 20.2.
2563 Face specifications earlier in lists take precedence over later
2567 merge_face_ref (f
, face_ref
, to
, err_msgs
, named_merge_points
)
2569 Lisp_Object face_ref
;
2572 struct named_merge_point
*named_merge_points
;
2574 int ok
= 1; /* Succeed without an error? */
2576 if (CONSP (face_ref
))
2578 Lisp_Object first
= XCAR (face_ref
);
2580 if (EQ (first
, Qforeground_color
)
2581 || EQ (first
, Qbackground_color
))
2583 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
2584 . COLOR). COLOR must be a string. */
2585 Lisp_Object color_name
= XCDR (face_ref
);
2586 Lisp_Object color
= first
;
2588 if (STRINGP (color_name
))
2590 if (EQ (color
, Qforeground_color
))
2591 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
2593 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
2598 add_to_log ("Invalid face color", color_name
, Qnil
);
2602 else if (SYMBOLP (first
)
2603 && *SDATA (SYMBOL_NAME (first
)) == ':')
2605 /* Assume this is the property list form. */
2606 while (CONSP (face_ref
) && CONSP (XCDR (face_ref
)))
2608 Lisp_Object keyword
= XCAR (face_ref
);
2609 Lisp_Object value
= XCAR (XCDR (face_ref
));
2612 /* Specifying `unspecified' is a no-op. */
2613 if (EQ (value
, Qunspecified
))
2615 else if (EQ (keyword
, QCfamily
))
2617 if (STRINGP (value
))
2619 to
[LFACE_FAMILY_INDEX
] = value
;
2620 font_clear_prop (to
, FONT_FAMILY_INDEX
);
2625 else if (EQ (keyword
, QCfoundry
))
2627 if (STRINGP (value
))
2629 to
[LFACE_FOUNDRY_INDEX
] = value
;
2630 font_clear_prop (to
, FONT_FOUNDRY_INDEX
);
2635 else if (EQ (keyword
, QCheight
))
2637 Lisp_Object new_height
=
2638 merge_face_heights (value
, to
[LFACE_HEIGHT_INDEX
], Qnil
);
2640 if (! NILP (new_height
))
2642 to
[LFACE_HEIGHT_INDEX
] = new_height
;
2643 font_clear_prop (to
, FONT_SIZE_INDEX
);
2648 else if (EQ (keyword
, QCweight
))
2650 if (SYMBOLP (value
) && FONT_WEIGHT_NAME_NUMERIC (value
) >= 0)
2652 to
[LFACE_WEIGHT_INDEX
] = value
;
2653 font_clear_prop (to
, FONT_WEIGHT_INDEX
);
2658 else if (EQ (keyword
, QCslant
))
2660 if (SYMBOLP (value
) && FONT_SLANT_NAME_NUMERIC (value
) >= 0)
2662 to
[LFACE_SLANT_INDEX
] = value
;
2663 font_clear_prop (to
, FONT_SLANT_INDEX
);
2668 else if (EQ (keyword
, QCunderline
))
2673 to
[LFACE_UNDERLINE_INDEX
] = value
;
2677 else if (EQ (keyword
, QCoverline
))
2682 to
[LFACE_OVERLINE_INDEX
] = value
;
2686 else if (EQ (keyword
, QCstrike_through
))
2691 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
2695 else if (EQ (keyword
, QCbox
))
2698 value
= make_number (1);
2699 if (INTEGERP (value
)
2703 to
[LFACE_BOX_INDEX
] = value
;
2707 else if (EQ (keyword
, QCinverse_video
)
2708 || EQ (keyword
, QCreverse_video
))
2710 if (EQ (value
, Qt
) || NILP (value
))
2711 to
[LFACE_INVERSE_INDEX
] = value
;
2715 else if (EQ (keyword
, QCforeground
))
2717 if (STRINGP (value
))
2718 to
[LFACE_FOREGROUND_INDEX
] = value
;
2722 else if (EQ (keyword
, QCbackground
))
2724 if (STRINGP (value
))
2725 to
[LFACE_BACKGROUND_INDEX
] = value
;
2729 else if (EQ (keyword
, QCstipple
))
2731 #if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
2732 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
2733 if (!NILP (pixmap_p
))
2734 to
[LFACE_STIPPLE_INDEX
] = value
;
2739 else if (EQ (keyword
, QCwidth
))
2741 if (SYMBOLP (value
) && FONT_WIDTH_NAME_NUMERIC (value
) >= 0)
2743 to
[LFACE_SWIDTH_INDEX
] = value
;
2744 font_clear_prop (to
, FONT_WIDTH_INDEX
);
2749 else if (EQ (keyword
, QCinherit
))
2751 /* This is not really very useful; it's just like a
2752 normal face reference. */
2753 if (! merge_face_ref (f
, value
, to
,
2754 err_msgs
, named_merge_points
))
2762 add_to_log ("Invalid face attribute %S %S", keyword
, value
);
2766 face_ref
= XCDR (XCDR (face_ref
));
2771 /* This is a list of face refs. Those at the beginning of the
2772 list take precedence over what follows, so we have to merge
2773 from the end backwards. */
2774 Lisp_Object next
= XCDR (face_ref
);
2777 ok
= merge_face_ref (f
, next
, to
, err_msgs
, named_merge_points
);
2779 if (! merge_face_ref (f
, first
, to
, err_msgs
, named_merge_points
))
2785 /* FACE_REF ought to be a face name. */
2786 ok
= merge_named_face (f
, face_ref
, to
, named_merge_points
);
2787 if (!ok
&& err_msgs
)
2788 add_to_log ("Invalid face reference: %s", face_ref
, Qnil
);
2795 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
2796 Sinternal_make_lisp_face
, 1, 2, 0,
2797 doc
: /* Make FACE, a symbol, a Lisp face with all attributes nil.
2798 If FACE was not known as a face before, create a new one.
2799 If optional argument FRAME is specified, make a frame-local face
2800 for that frame. Otherwise operate on the global face definition.
2801 Value is a vector of face attributes. */)
2803 Lisp_Object face
, frame
;
2805 Lisp_Object global_lface
, lface
;
2809 CHECK_SYMBOL (face
);
2810 global_lface
= lface_from_face_name (NULL
, face
, 0);
2814 CHECK_LIVE_FRAME (frame
);
2816 lface
= lface_from_face_name (f
, face
, 0);
2819 f
= NULL
, lface
= Qnil
;
2821 /* Add a global definition if there is none. */
2822 if (NILP (global_lface
))
2824 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2826 ASET (global_lface
, 0, Qface
);
2827 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
2828 Vface_new_frame_defaults
);
2830 /* Assign the new Lisp face a unique ID. The mapping from Lisp
2831 face id to Lisp face is given by the vector lface_id_to_name.
2832 The mapping from Lisp face to Lisp face id is given by the
2833 property `face' of the Lisp face name. */
2834 if (next_lface_id
== lface_id_to_name_size
)
2836 int new_size
= max (50, 2 * lface_id_to_name_size
);
2837 int sz
= new_size
* sizeof *lface_id_to_name
;
2838 lface_id_to_name
= (Lisp_Object
*) xrealloc (lface_id_to_name
, sz
);
2839 lface_id_to_name_size
= new_size
;
2842 lface_id_to_name
[next_lface_id
] = face
;
2843 Fput (face
, Qface
, make_number (next_lface_id
));
2847 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2848 ASET (global_lface
, i
, Qunspecified
);
2850 /* Add a frame-local definition. */
2855 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2857 ASET (lface
, 0, Qface
);
2858 f
->face_alist
= Fcons (Fcons (face
, lface
), f
->face_alist
);
2861 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2862 ASET (lface
, i
, Qunspecified
);
2865 lface
= global_lface
;
2867 /* Changing a named face means that all realized faces depending on
2868 that face are invalid. Since we cannot tell which realized faces
2869 depend on the face, make sure they are all removed. This is done
2870 by incrementing face_change_count. The next call to
2871 init_iterator will then free realized faces. */
2872 if (NILP (Fget (face
, Qface_no_inherit
)))
2874 ++face_change_count
;
2875 ++windows_or_buffers_changed
;
2878 xassert (LFACEP (lface
));
2879 check_lface (lface
);
2884 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
2885 Sinternal_lisp_face_p
, 1, 2, 0,
2886 doc
: /* Return non-nil if FACE names a face.
2887 If optional second argument FRAME is non-nil, check for the
2888 existence of a frame-local face with name FACE on that frame.
2889 Otherwise check for the existence of a global face. */)
2891 Lisp_Object face
, frame
;
2895 face
= resolve_face_name (face
, 1);
2899 CHECK_LIVE_FRAME (frame
);
2900 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2903 lface
= lface_from_face_name (NULL
, face
, 0);
2909 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
2910 Sinternal_copy_lisp_face
, 4, 4, 0,
2911 doc
: /* Copy face FROM to TO.
2912 If FRAME is t, copy the global face definition of FROM.
2913 Otherwise, copy the frame-local definition of FROM on FRAME.
2914 If NEW-FRAME is a frame, copy that data into the frame-local
2915 definition of TO on NEW-FRAME. If NEW-FRAME is nil,
2916 FRAME controls where the data is copied to.
2918 The value is TO. */)
2919 (from
, to
, frame
, new_frame
)
2920 Lisp_Object from
, to
, frame
, new_frame
;
2922 Lisp_Object lface
, copy
;
2924 CHECK_SYMBOL (from
);
2929 /* Copy global definition of FROM. We don't make copies of
2930 strings etc. because 20.2 didn't do it either. */
2931 lface
= lface_from_face_name (NULL
, from
, 1);
2932 copy
= Finternal_make_lisp_face (to
, Qnil
);
2936 /* Copy frame-local definition of FROM. */
2937 if (NILP (new_frame
))
2939 CHECK_LIVE_FRAME (frame
);
2940 CHECK_LIVE_FRAME (new_frame
);
2941 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
2942 copy
= Finternal_make_lisp_face (to
, new_frame
);
2945 bcopy (XVECTOR (lface
)->contents
, XVECTOR (copy
)->contents
,
2946 LFACE_VECTOR_SIZE
* sizeof (Lisp_Object
));
2948 /* Changing a named face means that all realized faces depending on
2949 that face are invalid. Since we cannot tell which realized faces
2950 depend on the face, make sure they are all removed. This is done
2951 by incrementing face_change_count. The next call to
2952 init_iterator will then free realized faces. */
2953 if (NILP (Fget (to
, Qface_no_inherit
)))
2955 ++face_change_count
;
2956 ++windows_or_buffers_changed
;
2963 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
2964 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
2965 doc
: /* Set attribute ATTR of FACE to VALUE.
2966 FRAME being a frame means change the face on that frame.
2967 FRAME nil means change the face of the selected frame.
2968 FRAME t means change the default for new frames.
2969 FRAME 0 means change the face on all frames, and change the default
2971 (face
, attr
, value
, frame
)
2972 Lisp_Object face
, attr
, value
, frame
;
2975 Lisp_Object old_value
= Qnil
;
2976 /* Set one of enum font_property_index (> 0) if ATTR is one of
2977 font-related attributes other than QCfont and QCfontset. */
2978 enum font_property_index prop_index
= 0;
2980 CHECK_SYMBOL (face
);
2981 CHECK_SYMBOL (attr
);
2983 face
= resolve_face_name (face
, 1);
2985 /* If FRAME is 0, change face on all frames, and change the
2986 default for new frames. */
2987 if (INTEGERP (frame
) && XINT (frame
) == 0)
2990 Finternal_set_lisp_face_attribute (face
, attr
, value
, Qt
);
2991 FOR_EACH_FRAME (tail
, frame
)
2992 Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
2996 /* Set lface to the Lisp attribute vector of FACE. */
2999 lface
= lface_from_face_name (NULL
, face
, 1);
3001 /* When updating face-new-frame-defaults, we put :ignore-defface
3002 where the caller wants `unspecified'. This forces the frame
3003 defaults to ignore the defface value. Otherwise, the defface
3004 will take effect, which is generally not what is intended.
3005 The value of that attribute will be inherited from some other
3006 face during face merging. See internal_merge_in_global_face. */
3007 if (UNSPECIFIEDP (value
))
3008 value
= Qignore_defface
;
3013 frame
= selected_frame
;
3015 CHECK_LIVE_FRAME (frame
);
3016 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3018 /* If a frame-local face doesn't exist yet, create one. */
3020 lface
= Finternal_make_lisp_face (face
, frame
);
3023 if (EQ (attr
, QCfamily
))
3025 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3027 CHECK_STRING (value
);
3028 if (SCHARS (value
) == 0)
3029 signal_error ("Invalid face family", value
);
3031 old_value
= LFACE_FAMILY (lface
);
3032 LFACE_FAMILY (lface
) = value
;
3033 prop_index
= FONT_FAMILY_INDEX
;
3035 else if (EQ (attr
, QCfoundry
))
3037 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3039 CHECK_STRING (value
);
3040 if (SCHARS (value
) == 0)
3041 signal_error ("Invalid face foundry", value
);
3043 old_value
= LFACE_FOUNDRY (lface
);
3044 LFACE_FOUNDRY (lface
) = value
;
3045 prop_index
= FONT_FOUNDRY_INDEX
;
3047 else if (EQ (attr
, QCheight
))
3049 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3051 if (EQ (face
, Qdefault
))
3053 /* The default face must have an absolute size. */
3054 if (!INTEGERP (value
) || XINT (value
) <= 0)
3055 signal_error ("Invalid default face height", value
);
3059 /* For non-default faces, do a test merge with a random
3060 height to see if VALUE's ok. */
3061 Lisp_Object test
= merge_face_heights (value
,
3064 if (!INTEGERP (test
) || XINT (test
) <= 0)
3065 signal_error ("Invalid face height", value
);
3069 old_value
= LFACE_HEIGHT (lface
);
3070 LFACE_HEIGHT (lface
) = value
;
3071 prop_index
= FONT_SIZE_INDEX
;
3073 else if (EQ (attr
, QCweight
))
3075 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3077 CHECK_SYMBOL (value
);
3078 if (FONT_WEIGHT_NAME_NUMERIC (value
) < 0)
3079 signal_error ("Invalid face weight", value
);
3081 old_value
= LFACE_WEIGHT (lface
);
3082 LFACE_WEIGHT (lface
) = value
;
3083 prop_index
= FONT_WEIGHT_INDEX
;
3085 else if (EQ (attr
, QCslant
))
3087 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3089 CHECK_SYMBOL (value
);
3090 if (FONT_SLANT_NAME_NUMERIC (value
) < 0)
3091 signal_error ("Invalid face slant", value
);
3093 old_value
= LFACE_SLANT (lface
);
3094 LFACE_SLANT (lface
) = value
;
3095 prop_index
= FONT_SLANT_INDEX
;
3097 else if (EQ (attr
, QCunderline
))
3099 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3100 if ((SYMBOLP (value
)
3102 && !EQ (value
, Qnil
))
3103 /* Underline color. */
3105 && SCHARS (value
) == 0))
3106 signal_error ("Invalid face underline", value
);
3108 old_value
= LFACE_UNDERLINE (lface
);
3109 LFACE_UNDERLINE (lface
) = value
;
3111 else if (EQ (attr
, QCoverline
))
3113 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3114 if ((SYMBOLP (value
)
3116 && !EQ (value
, Qnil
))
3117 /* Overline color. */
3119 && SCHARS (value
) == 0))
3120 signal_error ("Invalid face overline", value
);
3122 old_value
= LFACE_OVERLINE (lface
);
3123 LFACE_OVERLINE (lface
) = value
;
3125 else if (EQ (attr
, QCstrike_through
))
3127 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3128 if ((SYMBOLP (value
)
3130 && !EQ (value
, Qnil
))
3131 /* Strike-through color. */
3133 && SCHARS (value
) == 0))
3134 signal_error ("Invalid face strike-through", value
);
3136 old_value
= LFACE_STRIKE_THROUGH (lface
);
3137 LFACE_STRIKE_THROUGH (lface
) = value
;
3139 else if (EQ (attr
, QCbox
))
3143 /* Allow t meaning a simple box of width 1 in foreground color
3146 value
= make_number (1);
3148 if (UNSPECIFIEDP (value
) || IGNORE_DEFFACE_P (value
))
3150 else if (NILP (value
))
3152 else if (INTEGERP (value
))
3153 valid_p
= XINT (value
) != 0;
3154 else if (STRINGP (value
))
3155 valid_p
= SCHARS (value
) > 0;
3156 else if (CONSP (value
))
3172 if (EQ (k
, QCline_width
))
3174 if (!INTEGERP (v
) || XINT (v
) == 0)
3177 else if (EQ (k
, QCcolor
))
3179 if (!NILP (v
) && (!STRINGP (v
) || SCHARS (v
) == 0))
3182 else if (EQ (k
, QCstyle
))
3184 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
3191 valid_p
= NILP (tem
);
3197 signal_error ("Invalid face box", value
);
3199 old_value
= LFACE_BOX (lface
);
3200 LFACE_BOX (lface
) = value
;
3202 else if (EQ (attr
, QCinverse_video
)
3203 || EQ (attr
, QCreverse_video
))
3205 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3207 CHECK_SYMBOL (value
);
3208 if (!EQ (value
, Qt
) && !NILP (value
))
3209 signal_error ("Invalid inverse-video face attribute value", value
);
3211 old_value
= LFACE_INVERSE (lface
);
3212 LFACE_INVERSE (lface
) = value
;
3214 else if (EQ (attr
, QCforeground
))
3216 /* Compatibility with 20.x. */
3218 value
= Qunspecified
;
3219 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3221 /* Don't check for valid color names here because it depends
3222 on the frame (display) whether the color will be valid
3223 when the face is realized. */
3224 CHECK_STRING (value
);
3225 if (SCHARS (value
) == 0)
3226 signal_error ("Empty foreground color value", value
);
3228 old_value
= LFACE_FOREGROUND (lface
);
3229 LFACE_FOREGROUND (lface
) = value
;
3231 else if (EQ (attr
, QCbackground
))
3233 /* Compatibility with 20.x. */
3235 value
= Qunspecified
;
3236 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3238 /* Don't check for valid color names here because it depends
3239 on the frame (display) whether the color will be valid
3240 when the face is realized. */
3241 CHECK_STRING (value
);
3242 if (SCHARS (value
) == 0)
3243 signal_error ("Empty background color value", value
);
3245 old_value
= LFACE_BACKGROUND (lface
);
3246 LFACE_BACKGROUND (lface
) = value
;
3248 else if (EQ (attr
, QCstipple
))
3250 #if defined(HAVE_X_WINDOWS) || defined(HAVE_NS)
3251 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3253 && NILP (Fbitmap_spec_p (value
)))
3254 signal_error ("Invalid stipple attribute", value
);
3255 old_value
= LFACE_STIPPLE (lface
);
3256 LFACE_STIPPLE (lface
) = value
;
3257 #endif /* HAVE_X_WINDOWS || HAVE_NS */
3259 else if (EQ (attr
, QCwidth
))
3261 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3263 CHECK_SYMBOL (value
);
3264 if (FONT_WIDTH_NAME_NUMERIC (value
) < 0)
3265 signal_error ("Invalid face width", value
);
3267 old_value
= LFACE_SWIDTH (lface
);
3268 LFACE_SWIDTH (lface
) = value
;
3269 prop_index
= FONT_WIDTH_INDEX
;
3271 else if (EQ (attr
, QCfont
))
3273 #ifdef HAVE_WINDOW_SYSTEM
3274 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3276 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
3280 old_value
= LFACE_FONT (lface
);
3281 if (! FONTP (value
))
3283 if (STRINGP (value
))
3285 Lisp_Object name
= value
;
3286 int fontset
= fs_query_fontset (name
, 0);
3289 name
= fontset_ascii (fontset
);
3290 value
= font_spec_from_name (name
);
3292 signal_error ("Invalid font name", name
);
3295 signal_error ("Invalid font or font-spec", value
);
3298 f
= XFRAME (selected_frame
);
3301 if (! FONT_OBJECT_P (value
))
3303 Lisp_Object
*attrs
= XVECTOR (lface
)->contents
;
3304 Lisp_Object font_object
;
3306 font_object
= font_load_for_lface (f
, attrs
, value
);
3307 if (NILP (font_object
))
3308 signal_error ("Font not available", value
);
3309 value
= font_object
;
3311 set_lface_from_font (f
, lface
, value
, 1);
3314 LFACE_FONT (lface
) = value
;
3316 #endif /* HAVE_WINDOW_SYSTEM */
3318 else if (EQ (attr
, QCfontset
))
3320 #ifdef HAVE_WINDOW_SYSTEM
3321 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
3325 old_value
= LFACE_FONTSET (lface
);
3326 tmp
= Fquery_fontset (value
, Qnil
);
3328 signal_error ("Invalid fontset name", value
);
3329 LFACE_FONTSET (lface
) = value
= tmp
;
3331 #endif /* HAVE_WINDOW_SYSTEM */
3333 else if (EQ (attr
, QCinherit
))
3336 if (SYMBOLP (value
))
3339 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
3340 if (!SYMBOLP (XCAR (tail
)))
3343 LFACE_INHERIT (lface
) = value
;
3345 signal_error ("Invalid face inheritance", value
);
3347 else if (EQ (attr
, QCbold
))
3349 old_value
= LFACE_WEIGHT (lface
);
3350 LFACE_WEIGHT (lface
) = NILP (value
) ? Qnormal
: Qbold
;
3351 prop_index
= FONT_WEIGHT_INDEX
;
3353 else if (EQ (attr
, QCitalic
))
3356 old_value
= LFACE_SLANT (lface
);
3357 LFACE_SLANT (lface
) = NILP (value
) ? Qnormal
: Qitalic
;
3358 prop_index
= FONT_SLANT_INDEX
;
3361 signal_error ("Invalid face attribute name", attr
);
3365 /* If a font-related attribute other than QCfont and QCfontset
3366 is specified, and if the original QCfont attribute has a font
3367 (font-spec or font-object), set the corresponding property in
3368 the font to nil so that the font selector doesn't think that
3369 the attribute is mandatory. Also, clear the average
3371 font_clear_prop (XVECTOR (lface
)->contents
, prop_index
);
3374 /* Changing a named face means that all realized faces depending on
3375 that face are invalid. Since we cannot tell which realized faces
3376 depend on the face, make sure they are all removed. This is done
3377 by incrementing face_change_count. The next call to
3378 init_iterator will then free realized faces. */
3380 && NILP (Fget (face
, Qface_no_inherit
))
3381 && NILP (Fequal (old_value
, value
)))
3383 ++face_change_count
;
3384 ++windows_or_buffers_changed
;
3387 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
3388 && NILP (Fequal (old_value
, value
)))
3394 if (EQ (face
, Qdefault
))
3396 #ifdef HAVE_WINDOW_SYSTEM
3397 /* Changed font-related attributes of the `default' face are
3398 reflected in changed `font' frame parameters. */
3400 && (prop_index
|| EQ (attr
, QCfont
))
3401 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
3402 set_font_frame_param (frame
, lface
);
3404 #endif /* HAVE_WINDOW_SYSTEM */
3406 if (EQ (attr
, QCforeground
))
3407 param
= Qforeground_color
;
3408 else if (EQ (attr
, QCbackground
))
3409 param
= Qbackground_color
;
3411 #ifdef HAVE_WINDOW_SYSTEM
3413 else if (EQ (face
, Qscroll_bar
))
3415 /* Changing the colors of `scroll-bar' sets frame parameters
3416 `scroll-bar-foreground' and `scroll-bar-background'. */
3417 if (EQ (attr
, QCforeground
))
3418 param
= Qscroll_bar_foreground
;
3419 else if (EQ (attr
, QCbackground
))
3420 param
= Qscroll_bar_background
;
3422 #endif /* not WINDOWSNT */
3423 else if (EQ (face
, Qborder
))
3425 /* Changing background color of `border' sets frame parameter
3427 if (EQ (attr
, QCbackground
))
3428 param
= Qborder_color
;
3430 else if (EQ (face
, Qcursor
))
3432 /* Changing background color of `cursor' sets frame parameter
3434 if (EQ (attr
, QCbackground
))
3435 param
= Qcursor_color
;
3437 else if (EQ (face
, Qmouse
))
3439 /* Changing background color of `mouse' sets frame parameter
3441 if (EQ (attr
, QCbackground
))
3442 param
= Qmouse_color
;
3444 #endif /* HAVE_WINDOW_SYSTEM */
3445 else if (EQ (face
, Qmenu
))
3447 /* Indicate that we have to update the menu bar when
3448 realizing faces on FRAME. FRAME t change the
3449 default for new frames. We do this by setting
3450 setting the flag in new face caches */
3453 struct frame
*f
= XFRAME (frame
);
3454 if (FRAME_FACE_CACHE (f
) == NULL
)
3455 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
3456 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 1;
3459 menu_face_changed_default
= 1;
3465 /* Update `default-frame-alist', which is used for new frames. */
3467 store_in_alist (&Vdefault_frame_alist
, param
, value
);
3470 /* Update the current frame's parameters. */
3473 cons
= XCAR (Vparam_value_alist
);
3474 XSETCAR (cons
, param
);
3475 XSETCDR (cons
, value
);
3476 Fmodify_frame_parameters (frame
, Vparam_value_alist
);
3485 #ifdef HAVE_WINDOW_SYSTEM
3487 /* Set the `font' frame parameter of FRAME determined from the
3488 font-object set in `default' face attributes LFACE. */
3491 set_font_frame_param (frame
, lface
)
3492 Lisp_Object frame
, lface
;
3494 struct frame
*f
= XFRAME (frame
);
3497 if (FRAME_WINDOW_P (f
)
3498 /* Don't do anything if the font is `unspecified'. This can
3499 happen during frame creation. */
3500 && (font
= LFACE_FONT (lface
),
3501 ! UNSPECIFIEDP (font
)))
3503 if (FONT_SPEC_P (font
))
3505 font
= font_load_for_lface (f
, XVECTOR (lface
)->contents
, font
);
3508 LFACE_FONT (lface
) = font
;
3510 f
->default_face_done_p
= 0;
3511 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, font
), Qnil
));
3516 /* Update the corresponding face when frame parameter PARAM on frame F
3517 has been assigned the value NEW_VALUE. */
3520 update_face_from_frame_parameter (f
, param
, new_value
)
3522 Lisp_Object param
, new_value
;
3524 Lisp_Object face
= Qnil
;
3527 /* If there are no faces yet, give up. This is the case when called
3528 from Fx_create_frame, and we do the necessary things later in
3529 face-set-after-frame-defaults. */
3530 if (NILP (f
->face_alist
))
3533 if (EQ (param
, Qforeground_color
))
3536 lface
= lface_from_face_name (f
, face
, 1);
3537 LFACE_FOREGROUND (lface
) = (STRINGP (new_value
)
3538 ? new_value
: Qunspecified
);
3539 realize_basic_faces (f
);
3541 else if (EQ (param
, Qbackground_color
))
3545 /* Changing the background color might change the background
3546 mode, so that we have to load new defface specs.
3547 Call frame-update-face-colors to do that. */
3548 XSETFRAME (frame
, f
);
3549 call1 (Qframe_set_background_mode
, frame
);
3552 lface
= lface_from_face_name (f
, face
, 1);
3553 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3554 ? new_value
: Qunspecified
);
3555 realize_basic_faces (f
);
3557 else if (EQ (param
, Qborder_color
))
3560 lface
= lface_from_face_name (f
, face
, 1);
3561 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3562 ? new_value
: Qunspecified
);
3564 else if (EQ (param
, Qcursor_color
))
3567 lface
= lface_from_face_name (f
, face
, 1);
3568 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3569 ? new_value
: Qunspecified
);
3571 else if (EQ (param
, Qmouse_color
))
3574 lface
= lface_from_face_name (f
, face
, 1);
3575 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3576 ? new_value
: Qunspecified
);
3579 /* Changing a named face means that all realized faces depending on
3580 that face are invalid. Since we cannot tell which realized faces
3581 depend on the face, make sure they are all removed. This is done
3582 by incrementing face_change_count. The next call to
3583 init_iterator will then free realized faces. */
3585 && NILP (Fget (face
, Qface_no_inherit
)))
3587 ++face_change_count
;
3588 ++windows_or_buffers_changed
;
3593 /* Get the value of X resource RESOURCE, class CLASS for the display
3594 of frame FRAME. This is here because ordinary `x-get-resource'
3595 doesn't take a frame argument. */
3597 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
3598 Sinternal_face_x_get_resource
, 3, 3, 0, doc
: /* */)
3599 (resource
, class, frame
)
3600 Lisp_Object resource
, class, frame
;
3602 Lisp_Object value
= Qnil
;
3603 CHECK_STRING (resource
);
3604 CHECK_STRING (class);
3605 CHECK_LIVE_FRAME (frame
);
3607 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame
)),
3608 resource
, class, Qnil
, Qnil
);
3614 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
3615 If VALUE is "on" or "true", return t. If VALUE is "off" or
3616 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
3617 error; if SIGNAL_P is zero, return 0. */
3620 face_boolean_x_resource_value (value
, signal_p
)
3624 Lisp_Object result
= make_number (0);
3626 xassert (STRINGP (value
));
3628 if (xstrcasecmp (SDATA (value
), "on") == 0
3629 || xstrcasecmp (SDATA (value
), "true") == 0)
3631 else if (xstrcasecmp (SDATA (value
), "off") == 0
3632 || xstrcasecmp (SDATA (value
), "false") == 0)
3634 else if (xstrcasecmp (SDATA (value
), "unspecified") == 0)
3635 result
= Qunspecified
;
3637 signal_error ("Invalid face attribute value from X resource", value
);
3643 DEFUN ("internal-set-lisp-face-attribute-from-resource",
3644 Finternal_set_lisp_face_attribute_from_resource
,
3645 Sinternal_set_lisp_face_attribute_from_resource
,
3646 3, 4, 0, doc
: /* */)
3647 (face
, attr
, value
, frame
)
3648 Lisp_Object face
, attr
, value
, frame
;
3650 CHECK_SYMBOL (face
);
3651 CHECK_SYMBOL (attr
);
3652 CHECK_STRING (value
);
3654 if (xstrcasecmp (SDATA (value
), "unspecified") == 0)
3655 value
= Qunspecified
;
3656 else if (EQ (attr
, QCheight
))
3658 value
= Fstring_to_number (value
, make_number (10));
3659 if (XINT (value
) <= 0)
3660 signal_error ("Invalid face height from X resource", value
);
3662 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
3663 value
= face_boolean_x_resource_value (value
, 1);
3664 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
3665 value
= intern (SDATA (value
));
3666 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
3667 value
= face_boolean_x_resource_value (value
, 1);
3668 else if (EQ (attr
, QCunderline
)
3669 || EQ (attr
, QCoverline
)
3670 || EQ (attr
, QCstrike_through
))
3672 Lisp_Object boolean_value
;
3674 /* If the result of face_boolean_x_resource_value is t or nil,
3675 VALUE does NOT specify a color. */
3676 boolean_value
= face_boolean_x_resource_value (value
, 0);
3677 if (SYMBOLP (boolean_value
))
3678 value
= boolean_value
;
3680 else if (EQ (attr
, QCbox
) || EQ (attr
, QCinherit
))
3681 value
= Fcar (Fread_from_string (value
, Qnil
, Qnil
));
3683 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3686 #endif /* HAVE_WINDOW_SYSTEM */
3689 /***********************************************************************
3691 ***********************************************************************/
3693 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
3695 /* Make menus on frame F appear as specified by the `menu' face. */
3698 x_update_menu_appearance (f
)
3701 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3705 && (rdb
= XrmGetDatabase (FRAME_X_DISPLAY (f
)),
3709 Lisp_Object lface
= lface_from_face_name (f
, Qmenu
, 1);
3710 struct face
*face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
3711 const char *myname
= SDATA (Vx_resource_name
);
3714 const char *popup_path
= "popup_menu";
3716 const char *popup_path
= "menu.popup";
3719 if (STRINGP (LFACE_FOREGROUND (lface
)))
3721 sprintf (line
, "%s.%s*foreground: %s",
3723 SDATA (LFACE_FOREGROUND (lface
)));
3724 XrmPutLineResource (&rdb
, line
);
3725 sprintf (line
, "%s.pane.menubar*foreground: %s",
3726 myname
, SDATA (LFACE_FOREGROUND (lface
)));
3727 XrmPutLineResource (&rdb
, line
);
3731 if (STRINGP (LFACE_BACKGROUND (lface
)))
3733 sprintf (line
, "%s.%s*background: %s",
3735 SDATA (LFACE_BACKGROUND (lface
)));
3736 XrmPutLineResource (&rdb
, line
);
3737 sprintf (line
, "%s.pane.menubar*background: %s",
3738 myname
, SDATA (LFACE_BACKGROUND (lface
)));
3739 XrmPutLineResource (&rdb
, line
);
3744 /* On Solaris 5.8, it's been reported that the `menu' face
3745 can be unspecified here, during startup. Why this
3746 happens remains unknown. -- cyd */
3747 && FONTP (LFACE_FONT (lface
))
3748 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
3749 || !UNSPECIFIEDP (LFACE_FOUNDRY (lface
))
3750 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
3751 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3752 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
3753 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
3755 Lisp_Object xlfd
= Ffont_xlfd_name (LFACE_FONT (lface
), Qnil
);
3757 const char *suffix
= "List";
3760 #if defined HAVE_X_I18N
3762 const char *suffix
= "Set";
3764 const char *suffix
= "";
3771 #if defined HAVE_X_I18N
3772 extern char *xic_create_fontsetname
3773 P_ ((char *base_fontname
, Bool motif
));
3774 char *fontsetname
= xic_create_fontsetname (SDATA (xlfd
), motif
);
3776 char *fontsetname
= (char *) SDATA (xlfd
);
3778 sprintf (line
, "%s.pane.menubar*font%s: %s",
3779 myname
, suffix
, fontsetname
);
3780 XrmPutLineResource (&rdb
, line
);
3781 sprintf (line
, "%s.%s*font%s: %s",
3782 myname
, popup_path
, suffix
, fontsetname
);
3783 XrmPutLineResource (&rdb
, line
);
3785 if (fontsetname
!= (char *) SDATA (xlfd
))
3786 xfree (fontsetname
);
3790 if (changed_p
&& f
->output_data
.x
->menubar_widget
)
3791 free_frame_menubar (f
);
3795 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
3798 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p
,
3799 Sface_attribute_relative_p
,
3801 doc
: /* Check whether a face attribute value is relative.
3802 Specifically, this function returns t if the attribute ATTRIBUTE
3803 with the value VALUE is relative.
3805 A relative value is one that doesn't entirely override whatever is
3806 inherited from another face. For most possible attributes,
3807 the only relative value that users see is `unspecified'.
3808 However, for :height, floating point values are also relative. */)
3810 Lisp_Object attribute
, value
;
3812 if (EQ (value
, Qunspecified
) || (EQ (value
, Qignore_defface
)))
3814 else if (EQ (attribute
, QCheight
))
3815 return INTEGERP (value
) ? Qnil
: Qt
;
3820 DEFUN ("merge-face-attribute", Fmerge_face_attribute
, Smerge_face_attribute
,
3822 doc
: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
3823 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
3824 the result will be absolute, otherwise it will be relative. */)
3825 (attribute
, value1
, value2
)
3826 Lisp_Object attribute
, value1
, value2
;
3828 if (EQ (value1
, Qunspecified
) || EQ (value1
, Qignore_defface
))
3830 else if (EQ (attribute
, QCheight
))
3831 return merge_face_heights (value1
, value2
, value1
);
3837 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
3838 Sinternal_get_lisp_face_attribute
,
3840 doc
: /* Return face attribute KEYWORD of face SYMBOL.
3841 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
3842 face attribute name, signal an error.
3843 If the optional argument FRAME is given, report on face SYMBOL in that
3844 frame. If FRAME is t, report on the defaults for face SYMBOL (for new
3845 frames). If FRAME is omitted or nil, use the selected frame. */)
3846 (symbol
, keyword
, frame
)
3847 Lisp_Object symbol
, keyword
, frame
;
3849 Lisp_Object lface
, value
= Qnil
;
3851 CHECK_SYMBOL (symbol
);
3852 CHECK_SYMBOL (keyword
);
3855 lface
= lface_from_face_name (NULL
, symbol
, 1);
3859 frame
= selected_frame
;
3860 CHECK_LIVE_FRAME (frame
);
3861 lface
= lface_from_face_name (XFRAME (frame
), symbol
, 1);
3864 if (EQ (keyword
, QCfamily
))
3865 value
= LFACE_FAMILY (lface
);
3866 else if (EQ (keyword
, QCfoundry
))
3867 value
= LFACE_FOUNDRY (lface
);
3868 else if (EQ (keyword
, QCheight
))
3869 value
= LFACE_HEIGHT (lface
);
3870 else if (EQ (keyword
, QCweight
))
3871 value
= LFACE_WEIGHT (lface
);
3872 else if (EQ (keyword
, QCslant
))
3873 value
= LFACE_SLANT (lface
);
3874 else if (EQ (keyword
, QCunderline
))
3875 value
= LFACE_UNDERLINE (lface
);
3876 else if (EQ (keyword
, QCoverline
))
3877 value
= LFACE_OVERLINE (lface
);
3878 else if (EQ (keyword
, QCstrike_through
))
3879 value
= LFACE_STRIKE_THROUGH (lface
);
3880 else if (EQ (keyword
, QCbox
))
3881 value
= LFACE_BOX (lface
);
3882 else if (EQ (keyword
, QCinverse_video
)
3883 || EQ (keyword
, QCreverse_video
))
3884 value
= LFACE_INVERSE (lface
);
3885 else if (EQ (keyword
, QCforeground
))
3886 value
= LFACE_FOREGROUND (lface
);
3887 else if (EQ (keyword
, QCbackground
))
3888 value
= LFACE_BACKGROUND (lface
);
3889 else if (EQ (keyword
, QCstipple
))
3890 value
= LFACE_STIPPLE (lface
);
3891 else if (EQ (keyword
, QCwidth
))
3892 value
= LFACE_SWIDTH (lface
);
3893 else if (EQ (keyword
, QCinherit
))
3894 value
= LFACE_INHERIT (lface
);
3895 else if (EQ (keyword
, QCfont
))
3896 value
= LFACE_FONT (lface
);
3897 else if (EQ (keyword
, QCfontset
))
3898 value
= LFACE_FONTSET (lface
);
3900 signal_error ("Invalid face attribute name", keyword
);
3902 if (IGNORE_DEFFACE_P (value
))
3903 return Qunspecified
;
3909 DEFUN ("internal-lisp-face-attribute-values",
3910 Finternal_lisp_face_attribute_values
,
3911 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
3912 doc
: /* Return a list of valid discrete values for face attribute ATTR.
3913 Value is nil if ATTR doesn't have a discrete set of valid values. */)
3917 Lisp_Object result
= Qnil
;
3919 CHECK_SYMBOL (attr
);
3921 if (EQ (attr
, QCunderline
))
3922 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3923 else if (EQ (attr
, QCoverline
))
3924 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3925 else if (EQ (attr
, QCstrike_through
))
3926 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3927 else if (EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
3928 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3934 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
3935 Sinternal_merge_in_global_face
, 2, 2, 0,
3936 doc
: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
3937 Default face attributes override any local face attributes. */)
3939 Lisp_Object face
, frame
;
3942 Lisp_Object global_lface
, local_lface
, *gvec
, *lvec
;
3943 struct frame
*f
= XFRAME (frame
);
3945 CHECK_LIVE_FRAME (frame
);
3946 global_lface
= lface_from_face_name (NULL
, face
, 1);
3947 local_lface
= lface_from_face_name (f
, face
, 0);
3948 if (NILP (local_lface
))
3949 local_lface
= Finternal_make_lisp_face (face
, frame
);
3951 /* Make every specified global attribute override the local one.
3952 BEWARE!! This is only used from `face-set-after-frame-default' where
3953 the local frame is defined from default specs in `face-defface-spec'
3954 and those should be overridden by global settings. Hence the strange
3955 "global before local" priority. */
3956 lvec
= XVECTOR (local_lface
)->contents
;
3957 gvec
= XVECTOR (global_lface
)->contents
;
3958 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3959 if (IGNORE_DEFFACE_P (gvec
[i
]))
3960 lvec
[i
] = Qunspecified
;
3961 else if (! UNSPECIFIEDP (gvec
[i
]))
3964 /* If the default face was changed, update the face cache and the
3965 `font' frame parameter. */
3966 if (EQ (face
, Qdefault
))
3968 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
3969 struct face
*newface
, *oldface
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
3970 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
3972 /* This can be NULL (e.g., in batch mode). */
3975 /* Ensure that the face vector is fully specified by merging
3976 the previously-cached vector. */
3977 bcopy (oldface
->lface
, attrs
, sizeof attrs
);
3978 merge_face_vectors (f
, lvec
, attrs
, 0);
3979 bcopy (attrs
, lvec
, sizeof attrs
);
3980 newface
= realize_face (c
, lvec
, DEFAULT_FACE_ID
);
3982 if ((! UNSPECIFIEDP (gvec
[LFACE_FAMILY_INDEX
])
3983 || ! UNSPECIFIEDP (gvec
[LFACE_FOUNDRY_INDEX
])
3984 || ! UNSPECIFIEDP (gvec
[LFACE_HEIGHT_INDEX
])
3985 || ! UNSPECIFIEDP (gvec
[LFACE_WEIGHT_INDEX
])
3986 || ! UNSPECIFIEDP (gvec
[LFACE_SLANT_INDEX
])
3987 || ! UNSPECIFIEDP (gvec
[LFACE_SWIDTH_INDEX
])
3988 || ! UNSPECIFIEDP (gvec
[LFACE_FONT_INDEX
]))
3991 Lisp_Object name
= newface
->font
->props
[FONT_NAME_INDEX
];
3992 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, name
),
4002 /* The following function is implemented for compatibility with 20.2.
4003 The function is used in x-resolve-fonts when it is asked to
4004 return fonts with the same size as the font of a face. This is
4005 done in fontset.el. */
4007 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 3, 0,
4008 doc
: /* Return the font name of face FACE, or nil if it is unspecified.
4009 The font name is, by default, for ASCII characters.
4010 If the optional argument FRAME is given, report on face FACE in that frame.
4011 If FRAME is t, report on the defaults for face FACE (for new frames).
4012 The font default for a face is either nil, or a list
4013 of the form (bold), (italic) or (bold italic).
4014 If FRAME is omitted or nil, use the selected frame. And, in this case,
4015 if the optional third argument CHARACTER is given,
4016 return the font name used for CHARACTER. */)
4017 (face
, frame
, character
)
4018 Lisp_Object face
, frame
, character
;
4022 Lisp_Object result
= Qnil
;
4023 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
4025 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
4026 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
4027 result
= Fcons (Qbold
, result
);
4029 if (!UNSPECIFIEDP (LFACE_SLANT (lface
))
4030 && !EQ (LFACE_SLANT (lface
), Qnormal
))
4031 result
= Fcons (Qitalic
, result
);
4037 struct frame
*f
= frame_or_selected_frame (frame
, 1);
4038 int face_id
= lookup_named_face (f
, face
, 1);
4039 struct face
*face
= FACE_FROM_ID (f
, face_id
);
4043 #ifdef HAVE_WINDOW_SYSTEM
4044 if (FRAME_WINDOW_P (f
) && !NILP (character
))
4046 CHECK_CHARACTER (character
);
4047 face_id
= FACE_FOR_CHAR (f
, face
, XINT (character
), -1, Qnil
);
4048 face
= FACE_FROM_ID (f
, face_id
);
4051 ? face
->font
->props
[FONT_NAME_INDEX
]
4053 #else /* !HAVE_WINDOW_SYSTEM */
4054 return build_string (FRAME_MSDOS_P (f
)
4056 : FRAME_W32_P (f
) ? "w32term"
4063 /* Compare face-attribute values v1 and v2 for equality. Value is non-zero if
4064 all attributes are `equal'. Tries to be fast because this function
4065 is called quite often. */
4068 face_attr_equal_p (v1
, v2
)
4071 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
4072 and the other is specified. */
4073 if (XTYPE (v1
) != XTYPE (v2
))
4082 if (SBYTES (v1
) != SBYTES (v2
))
4085 return bcmp (SDATA (v1
), SDATA (v2
), SBYTES (v1
)) == 0;
4092 return !NILP (Fequal (v1
, v2
));
4097 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
4098 all attributes are `equal'. Tries to be fast because this function
4099 is called quite often. */
4102 lface_equal_p (v1
, v2
)
4103 Lisp_Object
*v1
, *v2
;
4107 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
4108 equal_p
= face_attr_equal_p (v1
[i
], v2
[i
]);
4114 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
4115 Sinternal_lisp_face_equal_p
, 2, 3, 0,
4116 doc
: /* True if FACE1 and FACE2 are equal.
4117 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
4118 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
4119 If FRAME is omitted or nil, use the selected frame. */)
4120 (face1
, face2
, frame
)
4121 Lisp_Object face1
, face2
, frame
;
4125 Lisp_Object lface1
, lface2
;
4130 /* Don't use check_x_frame here because this function is called
4131 before X frames exist. At that time, if FRAME is nil,
4132 selected_frame will be used which is the frame dumped with
4133 Emacs. That frame is not an X frame. */
4134 f
= frame_or_selected_frame (frame
, 2);
4136 lface1
= lface_from_face_name (f
, face1
, 1);
4137 lface2
= lface_from_face_name (f
, face2
, 1);
4138 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
4139 XVECTOR (lface2
)->contents
);
4140 return equal_p
? Qt
: Qnil
;
4144 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
4145 Sinternal_lisp_face_empty_p
, 1, 2, 0,
4146 doc
: /* True if FACE has no attribute specified.
4147 If the optional argument FRAME is given, report on face FACE in that frame.
4148 If FRAME is t, report on the defaults for face FACE (for new frames).
4149 If FRAME is omitted or nil, use the selected frame. */)
4151 Lisp_Object face
, frame
;
4158 frame
= selected_frame
;
4159 CHECK_LIVE_FRAME (frame
);
4163 lface
= lface_from_face_name (NULL
, face
, 1);
4165 lface
= lface_from_face_name (f
, face
, 1);
4167 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4168 if (!UNSPECIFIEDP (AREF (lface
, i
)))
4171 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
4175 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
4177 doc
: /* Return an alist of frame-local faces defined on FRAME.
4178 For internal use only. */)
4182 struct frame
*f
= frame_or_selected_frame (frame
, 0);
4183 return f
->face_alist
;
4187 /* Return a hash code for Lisp string STRING with case ignored. Used
4188 below in computing a hash value for a Lisp face. */
4190 static INLINE
unsigned
4191 hash_string_case_insensitive (string
)
4194 const unsigned char *s
;
4196 xassert (STRINGP (string
));
4197 for (s
= SDATA (string
); *s
; ++s
)
4198 hash
= (hash
<< 1) ^ tolower (*s
);
4203 /* Return a hash code for face attribute vector V. */
4205 static INLINE
unsigned
4209 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
4210 ^ hash_string_case_insensitive (v
[LFACE_FOUNDRY_INDEX
])
4211 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
4212 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
4213 ^ XHASH (v
[LFACE_WEIGHT_INDEX
])
4214 ^ XHASH (v
[LFACE_SLANT_INDEX
])
4215 ^ XHASH (v
[LFACE_SWIDTH_INDEX
])
4216 ^ XHASH (v
[LFACE_HEIGHT_INDEX
]));
4220 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
4221 considering charsets/registries). They do if they specify the same
4222 family, point size, weight, width, slant, and font. Both
4223 LFACE1 and LFACE2 must be fully-specified. */
4226 lface_same_font_attributes_p (lface1
, lface2
)
4227 Lisp_Object
*lface1
, *lface2
;
4229 xassert (lface_fully_specified_p (lface1
)
4230 && lface_fully_specified_p (lface2
));
4231 return (xstrcasecmp (SDATA (lface1
[LFACE_FAMILY_INDEX
]),
4232 SDATA (lface2
[LFACE_FAMILY_INDEX
])) == 0
4233 && xstrcasecmp (SDATA (lface1
[LFACE_FOUNDRY_INDEX
]),
4234 SDATA (lface2
[LFACE_FOUNDRY_INDEX
])) == 0
4235 && EQ (lface1
[LFACE_HEIGHT_INDEX
], lface2
[LFACE_HEIGHT_INDEX
])
4236 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
4237 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
4238 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
])
4239 && EQ (lface1
[LFACE_FONT_INDEX
], lface2
[LFACE_FONT_INDEX
])
4240 && (EQ (lface1
[LFACE_FONTSET_INDEX
], lface2
[LFACE_FONTSET_INDEX
])
4241 || (STRINGP (lface1
[LFACE_FONTSET_INDEX
])
4242 && STRINGP (lface2
[LFACE_FONTSET_INDEX
])
4243 && ! xstrcasecmp (SDATA (lface1
[LFACE_FONTSET_INDEX
]),
4244 SDATA (lface2
[LFACE_FONTSET_INDEX
]))))
4250 /***********************************************************************
4252 ***********************************************************************/
4254 /* Allocate and return a new realized face for Lisp face attribute
4257 static struct face
*
4258 make_realized_face (attr
)
4261 struct face
*face
= (struct face
*) xmalloc (sizeof *face
);
4262 bzero (face
, sizeof *face
);
4263 face
->ascii_face
= face
;
4264 bcopy (attr
, face
->lface
, sizeof face
->lface
);
4269 /* Free realized face FACE, including its X resources. FACE may
4273 free_realized_face (f
, face
)
4279 #ifdef HAVE_WINDOW_SYSTEM
4280 if (FRAME_WINDOW_P (f
))
4282 /* Free fontset of FACE if it is ASCII face. */
4283 if (face
->fontset
>= 0 && face
== face
->ascii_face
)
4284 free_face_fontset (f
, face
);
4289 font_done_for_face (f
, face
);
4290 x_free_gc (f
, face
->gc
);
4295 free_face_colors (f
, face
);
4296 x_destroy_bitmap (f
, face
->stipple
);
4298 #endif /* HAVE_WINDOW_SYSTEM */
4305 /* Prepare face FACE for subsequent display on frame F. This
4306 allocated GCs if they haven't been allocated yet or have been freed
4307 by clearing the face cache. */
4310 prepare_face_for_display (f
, face
)
4314 #ifdef HAVE_WINDOW_SYSTEM
4315 xassert (FRAME_WINDOW_P (f
));
4320 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
4322 xgcv
.foreground
= face
->foreground
;
4323 xgcv
.background
= face
->background
;
4324 #ifdef HAVE_X_WINDOWS
4325 xgcv
.graphics_exposures
= False
;
4329 #ifdef HAVE_X_WINDOWS
4332 xgcv
.fill_style
= FillOpaqueStippled
;
4333 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
4334 mask
|= GCFillStyle
| GCStipple
;
4337 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
4339 font_prepare_for_face (f
, face
);
4342 #endif /* HAVE_WINDOW_SYSTEM */
4346 /* Returns the `distance' between the colors X and Y. */
4349 color_distance (x
, y
)
4352 /* This formula is from a paper title `Colour metric' by Thiadmer Riemersma.
4353 Quoting from that paper:
4355 This formula has results that are very close to L*u*v* (with the
4356 modified lightness curve) and, more importantly, it is a more even
4357 algorithm: it does not have a range of colours where it suddenly
4358 gives far from optimal results.
4360 See <http://www.compuphase.com/cmetric.htm> for more info. */
4362 long r
= (x
->red
- y
->red
) >> 8;
4363 long g
= (x
->green
- y
->green
) >> 8;
4364 long b
= (x
->blue
- y
->blue
) >> 8;
4365 long r_mean
= (x
->red
+ y
->red
) >> 9;
4368 (((512 + r_mean
) * r
* r
) >> 8)
4370 + (((767 - r_mean
) * b
* b
) >> 8);
4374 DEFUN ("color-distance", Fcolor_distance
, Scolor_distance
, 2, 3, 0,
4375 doc
: /* Return an integer distance between COLOR1 and COLOR2 on FRAME.
4376 COLOR1 and COLOR2 may be either strings containing the color name,
4377 or lists of the form (RED GREEN BLUE).
4378 If FRAME is unspecified or nil, the current frame is used. */)
4379 (color1
, color2
, frame
)
4380 Lisp_Object color1
, color2
, frame
;
4383 XColor cdef1
, cdef2
;
4386 frame
= selected_frame
;
4387 CHECK_LIVE_FRAME (frame
);
4390 if (!(CONSP (color1
) && parse_rgb_list (color1
, &cdef1
))
4391 && !(STRINGP (color1
) && defined_color (f
, SDATA (color1
), &cdef1
, 0)))
4392 signal_error ("Invalid color", color1
);
4393 if (!(CONSP (color2
) && parse_rgb_list (color2
, &cdef2
))
4394 && !(STRINGP (color2
) && defined_color (f
, SDATA (color2
), &cdef2
, 0)))
4395 signal_error ("Invalid color", color2
);
4397 return make_number (color_distance (&cdef1
, &cdef2
));
4401 /***********************************************************************
4403 ***********************************************************************/
4405 /* Return a new face cache for frame F. */
4407 static struct face_cache
*
4411 struct face_cache
*c
;
4414 c
= (struct face_cache
*) xmalloc (sizeof *c
);
4415 bzero (c
, sizeof *c
);
4416 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4417 c
->buckets
= (struct face
**) xmalloc (size
);
4418 bzero (c
->buckets
, size
);
4420 c
->faces_by_id
= (struct face
**) xmalloc (c
->size
* sizeof *c
->faces_by_id
);
4422 c
->menu_face_changed_p
= menu_face_changed_default
;
4427 /* Clear out all graphics contexts for all realized faces, except for
4428 the basic faces. This should be done from time to time just to avoid
4429 keeping too many graphics contexts that are no longer needed. */
4433 struct face_cache
*c
;
4435 if (c
&& FRAME_WINDOW_P (c
->f
))
4437 #ifdef HAVE_WINDOW_SYSTEM
4439 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
4441 struct face
*face
= c
->faces_by_id
[i
];
4442 if (face
&& face
->gc
)
4446 font_done_for_face (c
->f
, face
);
4447 x_free_gc (c
->f
, face
->gc
);
4452 #endif /* HAVE_WINDOW_SYSTEM */
4457 /* Free all realized faces in face cache C, including basic faces.
4458 C may be null. If faces are freed, make sure the frame's current
4459 matrix is marked invalid, so that a display caused by an expose
4460 event doesn't try to use faces we destroyed. */
4463 free_realized_faces (c
)
4464 struct face_cache
*c
;
4469 struct frame
*f
= c
->f
;
4471 /* We must block input here because we can't process X events
4472 safely while only some faces are freed, or when the frame's
4473 current matrix still references freed faces. */
4476 for (i
= 0; i
< c
->used
; ++i
)
4478 free_realized_face (f
, c
->faces_by_id
[i
]);
4479 c
->faces_by_id
[i
] = NULL
;
4483 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4484 bzero (c
->buckets
, size
);
4486 /* Must do a thorough redisplay the next time. Mark current
4487 matrices as invalid because they will reference faces freed
4488 above. This function is also called when a frame is
4489 destroyed. In this case, the root window of F is nil. */
4490 if (WINDOWP (f
->root_window
))
4492 clear_current_matrices (f
);
4493 ++windows_or_buffers_changed
;
4501 /* Free all realized faces that are using FONTSET on frame F. */
4504 free_realized_faces_for_fontset (f
, fontset
)
4508 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4512 /* We must block input here because we can't process X events safely
4513 while only some faces are freed, or when the frame's current
4514 matrix still references freed faces. */
4517 for (i
= 0; i
< cache
->used
; i
++)
4519 face
= cache
->faces_by_id
[i
];
4521 && face
->fontset
== fontset
)
4523 uncache_face (cache
, face
);
4524 free_realized_face (f
, face
);
4528 /* Must do a thorough redisplay the next time. Mark current
4529 matrices as invalid because they will reference faces freed
4530 above. This function is also called when a frame is destroyed.
4531 In this case, the root window of F is nil. */
4532 if (WINDOWP (f
->root_window
))
4534 clear_current_matrices (f
);
4535 ++windows_or_buffers_changed
;
4542 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
4543 This is done after attributes of a named face have been changed,
4544 because we can't tell which realized faces depend on that face. */
4547 free_all_realized_faces (frame
)
4553 FOR_EACH_FRAME (rest
, frame
)
4554 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4557 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4561 /* Free face cache C and faces in it, including their X resources. */
4565 struct face_cache
*c
;
4569 free_realized_faces (c
);
4571 xfree (c
->faces_by_id
);
4577 /* Cache realized face FACE in face cache C. HASH is the hash value
4578 of FACE. If FACE is for ASCII characters (i.e. FACE->ascii_face ==
4579 FACE), insert the new face to the beginning of the collision list
4580 of the face hash table of C. Otherwise, add the new face to the
4581 end of the collision list. This way, lookup_face can quickly find
4582 that a requested face is not cached. */
4585 cache_face (c
, face
, hash
)
4586 struct face_cache
*c
;
4590 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4594 if (face
->ascii_face
!= face
)
4596 struct face
*last
= c
->buckets
[i
];
4607 c
->buckets
[i
] = face
;
4608 face
->prev
= face
->next
= NULL
;
4614 face
->next
= c
->buckets
[i
];
4616 face
->next
->prev
= face
;
4617 c
->buckets
[i
] = face
;
4620 /* Find a free slot in C->faces_by_id and use the index of the free
4621 slot as FACE->id. */
4622 for (i
= 0; i
< c
->used
; ++i
)
4623 if (c
->faces_by_id
[i
] == NULL
)
4627 /* Maybe enlarge C->faces_by_id. */
4630 if (c
->used
== c
->size
)
4633 new_size
= min (2 * c
->size
, MAX_FACE_ID
);
4634 if (new_size
== c
->size
)
4635 abort (); /* Alternatives? ++kfs */
4636 sz
= new_size
* sizeof *c
->faces_by_id
;
4637 c
->faces_by_id
= (struct face
**) xrealloc (c
->faces_by_id
, sz
);
4644 /* Check that FACE got a unique id. */
4649 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
4650 for (face
= c
->buckets
[j
]; face
; face
= face
->next
)
4656 #endif /* GLYPH_DEBUG */
4658 c
->faces_by_id
[i
] = face
;
4662 /* Remove face FACE from cache C. */
4665 uncache_face (c
, face
)
4666 struct face_cache
*c
;
4669 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
4672 face
->prev
->next
= face
->next
;
4674 c
->buckets
[i
] = face
->next
;
4677 face
->next
->prev
= face
->prev
;
4679 c
->faces_by_id
[face
->id
] = NULL
;
4680 if (face
->id
== c
->used
)
4685 /* Look up a realized face with face attributes ATTR in the face cache
4686 of frame F. The face will be used to display ASCII characters.
4687 Value is the ID of the face found. If no suitable face is found,
4688 realize a new one. */
4691 lookup_face (f
, attr
)
4695 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4700 xassert (cache
!= NULL
);
4701 check_lface_attrs (attr
);
4703 /* Look up ATTR in the face cache. */
4704 hash
= lface_hash (attr
);
4705 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4707 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4709 if (face
->ascii_face
!= face
)
4711 /* There's no more ASCII face. */
4715 if (face
->hash
== hash
4716 && lface_equal_p (face
->lface
, attr
))
4720 /* If not found, realize a new face. */
4722 face
= realize_face (cache
, attr
, -1);
4725 xassert (face
== FACE_FROM_ID (f
, face
->id
));
4726 #endif /* GLYPH_DEBUG */
4731 #ifdef HAVE_WINDOW_SYSTEM
4732 /* Look up a realized face that has the same attributes as BASE_FACE
4733 except for the font in the face cache of frame F. If FONT-OBJECT
4734 is not nil, it is an already opened font. If FONT-OBJECT is nil,
4735 the face has no font. Value is the ID of the face found. If no
4736 suitable face is found, realize a new one. */
4739 face_for_font (f
, font_object
, base_face
)
4741 Lisp_Object font_object
;
4742 struct face
*base_face
;
4744 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
4749 xassert (cache
!= NULL
);
4750 base_face
= base_face
->ascii_face
;
4751 hash
= lface_hash (base_face
->lface
);
4752 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4754 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
4756 if (face
->ascii_face
== face
)
4758 if (face
->ascii_face
== base_face
4759 && face
->font
== (NILP (font_object
) ? NULL
4760 : XFONT_OBJECT (font_object
))
4761 && lface_equal_p (face
->lface
, base_face
->lface
))
4765 /* If not found, realize a new face. */
4766 face
= realize_non_ascii_face (f
, font_object
, base_face
);
4769 #endif /* HAVE_WINDOW_SYSTEM */
4771 /* Return the face id of the realized face for named face SYMBOL on
4772 frame F suitable for displaying ASCII characters. Value is -1 if
4773 the face couldn't be determined, which might happen if the default
4774 face isn't realized and cannot be realized. */
4777 lookup_named_face (f
, symbol
, signal_p
)
4782 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4783 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4784 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4786 if (default_face
== NULL
)
4788 if (!realize_basic_faces (f
))
4790 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4791 if (default_face
== NULL
)
4792 abort (); /* realize_basic_faces must have set it up */
4795 if (! get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4798 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
4799 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4801 return lookup_face (f
, attrs
);
4805 /* Return the display face-id of the basic face who's canonical face-id
4806 is FACE_ID. The return value will usually simply be FACE_ID, unless that
4807 basic face has bee remapped via Vface_remapping_alist. This function is
4808 conservative: if something goes wrong, it will simply return FACE_ID
4809 rather than signal an error. */
4812 lookup_basic_face (f
, face_id
)
4816 Lisp_Object name
, mapping
;
4817 int remapped_face_id
;
4819 if (NILP (Vface_remapping_alist
))
4820 return face_id
; /* Nothing to do. */
4824 case DEFAULT_FACE_ID
: name
= Qdefault
; break;
4825 case MODE_LINE_FACE_ID
: name
= Qmode_line
; break;
4826 case MODE_LINE_INACTIVE_FACE_ID
: name
= Qmode_line_inactive
; break;
4827 case HEADER_LINE_FACE_ID
: name
= Qheader_line
; break;
4828 case TOOL_BAR_FACE_ID
: name
= Qtool_bar
; break;
4829 case FRINGE_FACE_ID
: name
= Qfringe
; break;
4830 case SCROLL_BAR_FACE_ID
: name
= Qscroll_bar
; break;
4831 case BORDER_FACE_ID
: name
= Qborder
; break;
4832 case CURSOR_FACE_ID
: name
= Qcursor
; break;
4833 case MOUSE_FACE_ID
: name
= Qmouse
; break;
4834 case MENU_FACE_ID
: name
= Qmenu
; break;
4837 abort (); /* the caller is supposed to pass us a basic face id */
4840 /* Do a quick scan through Vface_remapping_alist, and return immediately
4841 if there is no remapping for face NAME. This is just an optimization
4842 for the very common no-remapping case. */
4843 mapping
= assq_no_quit (name
, Vface_remapping_alist
);
4845 return face_id
; /* Give up. */
4847 /* If there is a remapping entry, lookup the face using NAME, which will
4848 handle the remapping too. */
4849 remapped_face_id
= lookup_named_face (f
, name
, 0);
4850 if (remapped_face_id
< 0)
4851 return face_id
; /* Give up. */
4853 return remapped_face_id
;
4857 /* Return the ID of the realized ASCII face of Lisp face with ID
4858 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
4861 ascii_face_of_lisp_face (f
, lface_id
)
4867 if (lface_id
>= 0 && lface_id
< lface_id_to_name_size
)
4869 Lisp_Object face_name
= lface_id_to_name
[lface_id
];
4870 face_id
= lookup_named_face (f
, face_name
, 1);
4879 /* Return a face for charset ASCII that is like the face with id
4880 FACE_ID on frame F, but has a font that is STEPS steps smaller.
4881 STEPS < 0 means larger. Value is the id of the face. */
4884 smaller_face (f
, face_id
, steps
)
4888 #ifdef HAVE_WINDOW_SYSTEM
4890 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4891 int pt
, last_pt
, last_height
;
4894 struct face
*new_face
;
4896 /* If not called for an X frame, just return the original face. */
4897 if (FRAME_TERMCAP_P (f
))
4900 /* Try in increments of 1/2 pt. */
4901 delta
= steps
< 0 ? 5 : -5;
4902 steps
= eabs (steps
);
4904 face
= FACE_FROM_ID (f
, face_id
);
4905 bcopy (face
->lface
, attrs
, sizeof attrs
);
4906 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
4907 new_face_id
= face_id
;
4908 last_height
= FONT_HEIGHT (face
->font
);
4912 /* Give up if we cannot find a font within 10pt. */
4913 && eabs (last_pt
- pt
) < 100)
4915 /* Look up a face for a slightly smaller/larger font. */
4917 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
4918 new_face_id
= lookup_face (f
, attrs
);
4919 new_face
= FACE_FROM_ID (f
, new_face_id
);
4921 /* If height changes, count that as one step. */
4922 if ((delta
< 0 && FONT_HEIGHT (new_face
->font
) < last_height
)
4923 || (delta
> 0 && FONT_HEIGHT (new_face
->font
) > last_height
))
4926 last_height
= FONT_HEIGHT (new_face
->font
);
4933 #else /* not HAVE_WINDOW_SYSTEM */
4937 #endif /* not HAVE_WINDOW_SYSTEM */
4941 /* Return a face for charset ASCII that is like the face with id
4942 FACE_ID on frame F, but has height HEIGHT. */
4945 face_with_height (f
, face_id
, height
)
4950 #ifdef HAVE_WINDOW_SYSTEM
4952 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4954 if (FRAME_TERMCAP_P (f
)
4958 face
= FACE_FROM_ID (f
, face_id
);
4959 bcopy (face
->lface
, attrs
, sizeof attrs
);
4960 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
4961 face_id
= lookup_face (f
, attrs
);
4962 #endif /* HAVE_WINDOW_SYSTEM */
4968 /* Return the face id of the realized face for named face SYMBOL on
4969 frame F suitable for displaying ASCII characters, and use
4970 attributes of the face FACE_ID for attributes that aren't
4971 completely specified by SYMBOL. This is like lookup_named_face,
4972 except that the default attributes come from FACE_ID, not from the
4973 default face. FACE_ID is assumed to be already realized. */
4976 lookup_derived_face (f
, symbol
, face_id
, signal_p
)
4982 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4983 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4984 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
4989 if (!get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
, 0))
4992 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
4993 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
4994 return lookup_face (f
, attrs
);
4997 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector
,
4998 Sface_attributes_as_vector
, 1, 1, 0,
4999 doc
: /* Return a vector of face attributes corresponding to PLIST. */)
5004 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
5006 merge_face_ref (XFRAME (selected_frame
), plist
, XVECTOR (lface
)->contents
,
5013 /***********************************************************************
5014 Face capability testing
5015 ***********************************************************************/
5018 /* If the distance (as returned by color_distance) between two colors is
5019 less than this, then they are considered the same, for determining
5020 whether a color is supported or not. The range of values is 0-65535. */
5022 #define TTY_SAME_COLOR_THRESHOLD 10000
5024 #ifdef HAVE_WINDOW_SYSTEM
5026 /* Return non-zero if all the face attributes in ATTRS are supported
5027 on the window-system frame F.
5029 The definition of `supported' is somewhat heuristic, but basically means
5030 that a face containing all the attributes in ATTRS, when merged with the
5031 default face for display, can be represented in a way that's
5033 \(1) different in appearance than the default face, and
5034 \(2) `close in spirit' to what the attributes specify, if not exact. */
5037 x_supports_face_attributes_p (f
, attrs
, def_face
)
5040 struct face
*def_face
;
5042 Lisp_Object
*def_attrs
= def_face
->lface
;
5044 /* Check that other specified attributes are different that the default
5046 if ((!UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
5047 && face_attr_equal_p (attrs
[LFACE_UNDERLINE_INDEX
],
5048 def_attrs
[LFACE_UNDERLINE_INDEX
]))
5049 || (!UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
5050 && face_attr_equal_p (attrs
[LFACE_INVERSE_INDEX
],
5051 def_attrs
[LFACE_INVERSE_INDEX
]))
5052 || (!UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
5053 && face_attr_equal_p (attrs
[LFACE_FOREGROUND_INDEX
],
5054 def_attrs
[LFACE_FOREGROUND_INDEX
]))
5055 || (!UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
5056 && face_attr_equal_p (attrs
[LFACE_BACKGROUND_INDEX
],
5057 def_attrs
[LFACE_BACKGROUND_INDEX
]))
5058 || (!UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
5059 && face_attr_equal_p (attrs
[LFACE_STIPPLE_INDEX
],
5060 def_attrs
[LFACE_STIPPLE_INDEX
]))
5061 || (!UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
5062 && face_attr_equal_p (attrs
[LFACE_OVERLINE_INDEX
],
5063 def_attrs
[LFACE_OVERLINE_INDEX
]))
5064 || (!UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
5065 && face_attr_equal_p (attrs
[LFACE_STRIKE_THROUGH_INDEX
],
5066 def_attrs
[LFACE_STRIKE_THROUGH_INDEX
]))
5067 || (!UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
5068 && face_attr_equal_p (attrs
[LFACE_BOX_INDEX
],
5069 def_attrs
[LFACE_BOX_INDEX
])))
5072 /* Check font-related attributes, as those are the most commonly
5073 "unsupported" on a window-system (because of missing fonts). */
5074 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
5075 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
5076 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
5077 || !UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
5078 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
5079 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
]))
5083 Lisp_Object merged_attrs
[LFACE_VECTOR_SIZE
];
5086 bcopy (def_attrs
, merged_attrs
, sizeof merged_attrs
);
5088 merge_face_vectors (f
, attrs
, merged_attrs
, 0);
5090 face_id
= lookup_face (f
, merged_attrs
);
5091 face
= FACE_FROM_ID (f
, face_id
);
5094 error ("Cannot make face");
5096 /* If the font is the same, or no font is found, then not
5098 if (face
->font
== def_face
->font
5101 for (i
= FONT_TYPE_INDEX
; i
<= FONT_SIZE_INDEX
; i
++)
5102 if (! EQ (face
->font
->props
[i
], def_face
->font
->props
[i
]))
5106 if (i
< FONT_FOUNDRY_INDEX
|| i
> FONT_REGISTRY_INDEX
5107 || face
->font
->driver
->case_sensitive
)
5109 s1
= SYMBOL_NAME (face
->font
->props
[i
]);
5110 s2
= SYMBOL_NAME (def_face
->font
->props
[i
]);
5111 if (! EQ (Fcompare_strings (s1
, make_number (0), Qnil
,
5112 s2
, make_number (0), Qnil
, Qt
), Qt
))
5118 /* Everything checks out, this face is supported. */
5122 #endif /* HAVE_WINDOW_SYSTEM */
5124 /* Return non-zero if all the face attributes in ATTRS are supported
5127 The definition of `supported' is somewhat heuristic, but basically means
5128 that a face containing all the attributes in ATTRS, when merged
5129 with the default face for display, can be represented in a way that's
5131 \(1) different in appearance than the default face, and
5132 \(2) `close in spirit' to what the attributes specify, if not exact.
5134 Point (2) implies that a `:weight black' attribute will be satisfied
5135 by any terminal that can display bold, and a `:foreground "yellow"' as
5136 long as the terminal can display a yellowish color, but `:slant italic'
5137 will _not_ be satisfied by the tty display code's automatic
5138 substitution of a `dim' face for italic. */
5141 tty_supports_face_attributes_p (f
, attrs
, def_face
)
5144 struct face
*def_face
;
5147 Lisp_Object val
, fg
, bg
;
5148 XColor fg_tty_color
, fg_std_color
;
5149 XColor bg_tty_color
, bg_std_color
;
5150 unsigned test_caps
= 0;
5151 Lisp_Object
*def_attrs
= def_face
->lface
;
5154 /* First check some easy-to-check stuff; ttys support none of the
5155 following attributes, so we can just return false if any are requested
5156 (even if `nominal' values are specified, we should still return false,
5157 as that will be the same value that the default face uses). We
5158 consider :slant unsupportable on ttys, even though the face code
5159 actually `fakes' them using a dim attribute if possible. This is
5160 because the faked result is too different from what the face
5162 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
5163 || !UNSPECIFIEDP (attrs
[LFACE_FOUNDRY_INDEX
])
5164 || !UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
5165 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
5166 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
5167 || !UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
5168 || !UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
5169 || !UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
5170 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
]))
5174 /* Test for terminal `capabilities' (non-color character attributes). */
5176 /* font weight (bold/dim) */
5177 val
= attrs
[LFACE_WEIGHT_INDEX
];
5178 if (!UNSPECIFIEDP (val
)
5179 && (weight
= FONT_WEIGHT_NAME_NUMERIC (val
), weight
>= 0))
5181 int def_weight
= FONT_WEIGHT_NAME_NUMERIC (def_attrs
[LFACE_WEIGHT_INDEX
]);
5185 if (def_weight
> 100)
5186 return 0; /* same as default */
5187 test_caps
= TTY_CAP_BOLD
;
5189 else if (weight
< 100)
5191 if (def_weight
< 100)
5192 return 0; /* same as default */
5193 test_caps
= TTY_CAP_DIM
;
5195 else if (def_weight
== 100)
5196 return 0; /* same as default */
5200 val
= attrs
[LFACE_UNDERLINE_INDEX
];
5201 if (!UNSPECIFIEDP (val
))
5204 return 0; /* ttys can't use colored underlines */
5205 else if (face_attr_equal_p (val
, def_attrs
[LFACE_UNDERLINE_INDEX
]))
5206 return 0; /* same as default */
5208 test_caps
|= TTY_CAP_UNDERLINE
;
5212 val
= attrs
[LFACE_INVERSE_INDEX
];
5213 if (!UNSPECIFIEDP (val
))
5215 if (face_attr_equal_p (val
, def_attrs
[LFACE_INVERSE_INDEX
]))
5216 return 0; /* same as default */
5218 test_caps
|= TTY_CAP_INVERSE
;
5222 /* Color testing. */
5224 /* Default the color indices in FG_TTY_COLOR and BG_TTY_COLOR, since
5225 we use them when calling `tty_capable_p' below, even if the face
5226 specifies no colors. */
5227 fg_tty_color
.pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5228 bg_tty_color
.pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5230 /* Check if foreground color is close enough. */
5231 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
5234 Lisp_Object def_fg
= def_attrs
[LFACE_FOREGROUND_INDEX
];
5236 if (face_attr_equal_p (fg
, def_fg
))
5237 return 0; /* same as default */
5238 else if (! tty_lookup_color (f
, fg
, &fg_tty_color
, &fg_std_color
))
5239 return 0; /* not a valid color */
5240 else if (color_distance (&fg_tty_color
, &fg_std_color
)
5241 > TTY_SAME_COLOR_THRESHOLD
)
5242 return 0; /* displayed color is too different */
5244 /* Make sure the color is really different than the default. */
5246 XColor def_fg_color
;
5247 if (tty_lookup_color (f
, def_fg
, &def_fg_color
, 0)
5248 && (color_distance (&fg_tty_color
, &def_fg_color
)
5249 <= TTY_SAME_COLOR_THRESHOLD
))
5254 /* Check if background color is close enough. */
5255 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
5258 Lisp_Object def_bg
= def_attrs
[LFACE_BACKGROUND_INDEX
];
5260 if (face_attr_equal_p (bg
, def_bg
))
5261 return 0; /* same as default */
5262 else if (! tty_lookup_color (f
, bg
, &bg_tty_color
, &bg_std_color
))
5263 return 0; /* not a valid color */
5264 else if (color_distance (&bg_tty_color
, &bg_std_color
)
5265 > TTY_SAME_COLOR_THRESHOLD
)
5266 return 0; /* displayed color is too different */
5268 /* Make sure the color is really different than the default. */
5270 XColor def_bg_color
;
5271 if (tty_lookup_color (f
, def_bg
, &def_bg_color
, 0)
5272 && (color_distance (&bg_tty_color
, &def_bg_color
)
5273 <= TTY_SAME_COLOR_THRESHOLD
))
5278 /* If both foreground and background are requested, see if the
5279 distance between them is OK. We just check to see if the distance
5280 between the tty's foreground and background is close enough to the
5281 distance between the standard foreground and background. */
5282 if (STRINGP (fg
) && STRINGP (bg
))
5285 = (color_distance (&fg_std_color
, &bg_std_color
)
5286 - color_distance (&fg_tty_color
, &bg_tty_color
));
5287 if (delta_delta
> TTY_SAME_COLOR_THRESHOLD
5288 || delta_delta
< -TTY_SAME_COLOR_THRESHOLD
)
5293 /* See if the capabilities we selected above are supported, with the
5295 if (test_caps
!= 0 &&
5296 ! tty_capable_p (FRAME_TTY (f
), test_caps
, fg_tty_color
.pixel
, bg_tty_color
.pixel
))
5300 /* Hmmm, everything checks out, this terminal must support this face. */
5305 DEFUN ("display-supports-face-attributes-p",
5306 Fdisplay_supports_face_attributes_p
, Sdisplay_supports_face_attributes_p
,
5308 doc
: /* Return non-nil if all the face attributes in ATTRIBUTES are supported.
5309 The optional argument DISPLAY can be a display name, a frame, or
5310 nil (meaning the selected frame's display).
5312 The definition of `supported' is somewhat heuristic, but basically means
5313 that a face containing all the attributes in ATTRIBUTES, when merged
5314 with the default face for display, can be represented in a way that's
5316 \(1) different in appearance than the default face, and
5317 \(2) `close in spirit' to what the attributes specify, if not exact.
5319 Point (2) implies that a `:weight black' attribute will be satisfied by
5320 any display that can display bold, and a `:foreground \"yellow\"' as long
5321 as it can display a yellowish color, but `:slant italic' will _not_ be
5322 satisfied by the tty display code's automatic substitution of a `dim'
5323 face for italic. */)
5324 (attributes
, display
)
5325 Lisp_Object attributes
, display
;
5327 int supports
= 0, i
;
5330 struct face
*def_face
;
5331 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5333 if (noninteractive
|| !initialized
)
5334 /* We may not be able to access low-level face information in batch
5335 mode, or before being dumped, and this function is not going to
5336 be very useful in those cases anyway, so just give up. */
5340 frame
= selected_frame
;
5341 else if (FRAMEP (display
))
5345 /* Find any frame on DISPLAY. */
5346 Lisp_Object fl_tail
;
5349 for (fl_tail
= Vframe_list
; CONSP (fl_tail
); fl_tail
= XCDR (fl_tail
))
5351 frame
= XCAR (fl_tail
);
5352 if (!NILP (Fequal (Fcdr (Fassq (Qdisplay
,
5353 XFRAME (frame
)->param_alist
)),
5359 CHECK_LIVE_FRAME (frame
);
5362 for (i
= 0; i
< LFACE_VECTOR_SIZE
; i
++)
5363 attrs
[i
] = Qunspecified
;
5364 merge_face_ref (f
, attributes
, attrs
, 1, 0);
5366 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5367 if (def_face
== NULL
)
5369 if (! realize_basic_faces (f
))
5370 error ("Cannot realize default face");
5371 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5372 if (def_face
== NULL
)
5373 abort (); /* realize_basic_faces must have set it up */
5376 /* Dispatch to the appropriate handler. */
5377 if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5378 supports
= tty_supports_face_attributes_p (f
, attrs
, def_face
);
5379 #ifdef HAVE_WINDOW_SYSTEM
5381 supports
= x_supports_face_attributes_p (f
, attrs
, def_face
);
5384 return supports
? Qt
: Qnil
;
5388 /***********************************************************************
5390 ***********************************************************************/
5392 DEFUN ("internal-set-font-selection-order",
5393 Finternal_set_font_selection_order
,
5394 Sinternal_set_font_selection_order
, 1, 1, 0,
5395 doc
: /* Set font selection order for face font selection to ORDER.
5396 ORDER must be a list of length 4 containing the symbols `:width',
5397 `:height', `:weight', and `:slant'. Face attributes appearing
5398 first in ORDER are matched first, e.g. if `:height' appears before
5399 `:weight' in ORDER, font selection first tries to find a font with
5400 a suitable height, and then tries to match the font weight.
5407 int indices
[DIM (font_sort_order
)];
5410 bzero (indices
, sizeof indices
);
5414 CONSP (list
) && i
< DIM (indices
);
5415 list
= XCDR (list
), ++i
)
5417 Lisp_Object attr
= XCAR (list
);
5420 if (EQ (attr
, QCwidth
))
5422 else if (EQ (attr
, QCheight
))
5423 xlfd
= XLFD_POINT_SIZE
;
5424 else if (EQ (attr
, QCweight
))
5426 else if (EQ (attr
, QCslant
))
5431 if (indices
[i
] != 0)
5436 if (!NILP (list
) || i
!= DIM (indices
))
5437 signal_error ("Invalid font sort order", order
);
5438 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5439 if (indices
[i
] == 0)
5440 signal_error ("Invalid font sort order", order
);
5442 if (bcmp (indices
, font_sort_order
, sizeof indices
) != 0)
5444 bcopy (indices
, font_sort_order
, sizeof font_sort_order
);
5445 free_all_realized_faces (Qnil
);
5448 font_update_sort_order (font_sort_order
);
5454 DEFUN ("internal-set-alternative-font-family-alist",
5455 Finternal_set_alternative_font_family_alist
,
5456 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
5457 doc
: /* Define alternative font families to try in face font selection.
5458 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5459 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
5460 be found. Value is ALIST. */)
5464 Lisp_Object entry
, tail
, tail2
;
5467 alist
= Fcopy_sequence (alist
);
5468 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5470 entry
= XCAR (tail
);
5472 entry
= Fcopy_sequence (entry
);
5473 XSETCAR (tail
, entry
);
5474 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5475 XSETCAR (tail2
, Fintern (XCAR (tail2
), Qnil
));
5478 Vface_alternative_font_family_alist
= alist
;
5479 free_all_realized_faces (Qnil
);
5484 DEFUN ("internal-set-alternative-font-registry-alist",
5485 Finternal_set_alternative_font_registry_alist
,
5486 Sinternal_set_alternative_font_registry_alist
, 1, 1, 0,
5487 doc
: /* Define alternative font registries to try in face font selection.
5488 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5489 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
5490 be found. Value is ALIST. */)
5494 Lisp_Object entry
, tail
, tail2
;
5497 alist
= Fcopy_sequence (alist
);
5498 for (tail
= alist
; CONSP (tail
); tail
= XCDR (tail
))
5500 entry
= XCAR (tail
);
5502 entry
= Fcopy_sequence (entry
);
5503 XSETCAR (tail
, entry
);
5504 for (tail2
= entry
; CONSP (tail2
); tail2
= XCDR (tail2
))
5505 XSETCAR (tail2
, Fdowncase (XCAR (tail2
)));
5507 Vface_alternative_font_registry_alist
= alist
;
5508 free_all_realized_faces (Qnil
);
5513 #ifdef HAVE_WINDOW_SYSTEM
5515 /* Ignore the difference of font point size less than this value. */
5517 #define FONT_POINT_SIZE_QUANTUM 5
5519 /* Return the fontset id of the base fontset name or alias name given
5520 by the fontset attribute of ATTRS. Value is -1 if the fontset
5521 attribute of ATTRS doesn't name a fontset. */
5524 face_fontset (attrs
)
5529 name
= attrs
[LFACE_FONTSET_INDEX
];
5530 if (!STRINGP (name
))
5532 return fs_query_fontset (name
, 0);
5535 #endif /* HAVE_WINDOW_SYSTEM */
5539 /***********************************************************************
5541 ***********************************************************************/
5543 /* Realize basic faces on frame F. Value is zero if frame parameters
5544 of F don't contain enough information needed to realize the default
5548 realize_basic_faces (f
)
5552 int count
= SPECPDL_INDEX ();
5554 /* Block input here so that we won't be surprised by an X expose
5555 event, for instance, without having the faces set up. */
5557 specbind (Qscalable_fonts_allowed
, Qt
);
5559 if (realize_default_face (f
))
5561 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
5562 realize_named_face (f
, Qmode_line_inactive
, MODE_LINE_INACTIVE_FACE_ID
);
5563 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
5564 realize_named_face (f
, Qfringe
, FRINGE_FACE_ID
);
5565 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
5566 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
5567 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
5568 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
5569 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
5570 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
5571 realize_named_face (f
, Qvertical_border
, VERTICAL_BORDER_FACE_ID
);
5573 /* Reflect changes in the `menu' face in menu bars. */
5574 if (FRAME_FACE_CACHE (f
)->menu_face_changed_p
)
5576 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 0;
5577 #ifdef USE_X_TOOLKIT
5578 if (FRAME_WINDOW_P (f
))
5579 x_update_menu_appearance (f
);
5586 unbind_to (count
, Qnil
);
5592 /* Realize the default face on frame F. If the face is not fully
5593 specified, make it fully-specified. Attributes of the default face
5594 that are not explicitly specified are taken from frame parameters. */
5597 realize_default_face (f
)
5600 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5602 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5605 /* If the `default' face is not yet known, create it. */
5606 lface
= lface_from_face_name (f
, Qdefault
, 0);
5610 XSETFRAME (frame
, f
);
5611 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
5614 #ifdef HAVE_WINDOW_SYSTEM
5615 if (FRAME_WINDOW_P (f
))
5617 Lisp_Object font_object
;
5619 XSETFONT (font_object
, FRAME_FONT (f
));
5620 set_lface_from_font (f
, lface
, font_object
, f
->default_face_done_p
);
5621 LFACE_FONTSET (lface
) = fontset_name (FRAME_FONTSET (f
));
5622 f
->default_face_done_p
= 1;
5624 #endif /* HAVE_WINDOW_SYSTEM */
5626 if (!FRAME_WINDOW_P (f
))
5628 LFACE_FAMILY (lface
) = build_string ("default");
5629 LFACE_FOUNDRY (lface
) = LFACE_FAMILY (lface
);
5630 LFACE_SWIDTH (lface
) = Qnormal
;
5631 LFACE_HEIGHT (lface
) = make_number (1);
5632 if (UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
5633 LFACE_WEIGHT (lface
) = Qnormal
;
5634 if (UNSPECIFIEDP (LFACE_SLANT (lface
)))
5635 LFACE_SLANT (lface
) = Qnormal
;
5636 if (UNSPECIFIEDP (LFACE_FONTSET (lface
)))
5637 LFACE_FONTSET (lface
) = Qnil
;
5640 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
5641 LFACE_UNDERLINE (lface
) = Qnil
;
5643 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
5644 LFACE_OVERLINE (lface
) = Qnil
;
5646 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
5647 LFACE_STRIKE_THROUGH (lface
) = Qnil
;
5649 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
5650 LFACE_BOX (lface
) = Qnil
;
5652 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
5653 LFACE_INVERSE (lface
) = Qnil
;
5655 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
5657 /* This function is called so early that colors are not yet
5658 set in the frame parameter list. */
5659 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
5661 if (CONSP (color
) && STRINGP (XCDR (color
)))
5662 LFACE_FOREGROUND (lface
) = XCDR (color
);
5663 else if (FRAME_WINDOW_P (f
))
5665 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5666 LFACE_FOREGROUND (lface
) = build_string (unspecified_fg
);
5671 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
5673 /* This function is called so early that colors are not yet
5674 set in the frame parameter list. */
5675 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
5676 if (CONSP (color
) && STRINGP (XCDR (color
)))
5677 LFACE_BACKGROUND (lface
) = XCDR (color
);
5678 else if (FRAME_WINDOW_P (f
))
5680 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5681 LFACE_BACKGROUND (lface
) = build_string (unspecified_bg
);
5686 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
5687 LFACE_STIPPLE (lface
) = Qnil
;
5689 /* Realize the face; it must be fully-specified now. */
5690 xassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
5691 check_lface (lface
);
5692 bcopy (XVECTOR (lface
)->contents
, attrs
, sizeof attrs
);
5693 face
= realize_face (c
, attrs
, DEFAULT_FACE_ID
);
5695 #ifdef HAVE_WINDOW_SYSTEM
5696 #ifdef HAVE_X_WINDOWS
5697 if (FRAME_X_P (f
) && face
->font
!= FRAME_FONT (f
))
5699 /* This can happen when making a frame on a display that does
5700 not support the default font. */
5704 /* Otherwise, the font specified for the frame was not
5705 acceptable as a font for the default face (perhaps because
5706 auto-scaled fonts are rejected), so we must adjust the frame
5708 x_set_font (f
, LFACE_FONT (lface
), Qnil
);
5710 #endif /* HAVE_X_WINDOWS */
5711 #endif /* HAVE_WINDOW_SYSTEM */
5716 /* Realize basic faces other than the default face in face cache C.
5717 SYMBOL is the face name, ID is the face id the realized face must
5718 have. The default face must have been realized already. */
5721 realize_named_face (f
, symbol
, id
)
5726 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5727 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
5728 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5729 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5730 struct face
*new_face
;
5732 /* The default face must exist and be fully specified. */
5733 get_lface_attributes_no_remap (f
, Qdefault
, attrs
, 1);
5734 check_lface_attrs (attrs
);
5735 xassert (lface_fully_specified_p (attrs
));
5737 /* If SYMBOL isn't know as a face, create it. */
5741 XSETFRAME (frame
, f
);
5742 lface
= Finternal_make_lisp_face (symbol
, frame
);
5745 /* Merge SYMBOL's face with the default face. */
5746 get_lface_attributes_no_remap (f
, symbol
, symbol_attrs
, 1);
5747 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
5749 /* Realize the face. */
5750 new_face
= realize_face (c
, attrs
, id
);
5754 /* Realize the fully-specified face with attributes ATTRS in face
5755 cache CACHE for ASCII characters. If FORMER_FACE_ID is
5756 non-negative, it is an ID of face to remove before caching the new
5757 face. Value is a pointer to the newly created realized face. */
5759 static struct face
*
5760 realize_face (cache
, attrs
, former_face_id
)
5761 struct face_cache
*cache
;
5767 /* LFACE must be fully specified. */
5768 xassert (cache
!= NULL
);
5769 check_lface_attrs (attrs
);
5771 if (former_face_id
>= 0 && cache
->used
> former_face_id
)
5773 /* Remove the former face. */
5774 struct face
*former_face
= cache
->faces_by_id
[former_face_id
];
5775 uncache_face (cache
, former_face
);
5776 free_realized_face (cache
->f
, former_face
);
5779 if (FRAME_WINDOW_P (cache
->f
))
5780 face
= realize_x_face (cache
, attrs
);
5781 else if (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
))
5782 face
= realize_tty_face (cache
, attrs
);
5783 else if (FRAME_INITIAL_P (cache
->f
))
5785 /* Create a dummy face. */
5786 face
= make_realized_face (attrs
);
5791 /* Insert the new face. */
5792 cache_face (cache
, face
, lface_hash (attrs
));
5797 #ifdef HAVE_WINDOW_SYSTEM
5798 /* Realize the fully-specified face that uses FONT-OBJECT and has the
5799 same attributes as BASE_FACE except for the font on frame F.
5800 FONT-OBJECT may be nil, in which case, realized a face of
5803 static struct face
*
5804 realize_non_ascii_face (f
, font_object
, base_face
)
5806 Lisp_Object font_object
;
5807 struct face
*base_face
;
5809 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5812 face
= (struct face
*) xmalloc (sizeof *face
);
5817 = (! NILP (font_object
)
5818 && FONT_WEIGHT_NAME_NUMERIC (face
->lface
[LFACE_WEIGHT_INDEX
]) > 100
5819 && FONT_WEIGHT_NUMERIC (font_object
) <= 100);
5821 /* Don't try to free the colors copied bitwise from BASE_FACE. */
5822 face
->colors_copied_bitwise_p
= 1;
5823 face
->font
= NILP (font_object
) ? NULL
: XFONT_OBJECT (font_object
);
5826 cache_face (cache
, face
, face
->hash
);
5830 #endif /* HAVE_WINDOW_SYSTEM */
5833 /* Realize the fully-specified face with attributes ATTRS in face
5834 cache CACHE for ASCII characters. Do it for X frame CACHE->f. If
5835 the new face doesn't share font with the default face, a fontname
5836 is allocated from the heap and set in `font_name' of the new face,
5837 but it is not yet loaded here. Value is a pointer to the newly
5838 created realized face. */
5840 static struct face
*
5841 realize_x_face (cache
, attrs
)
5842 struct face_cache
*cache
;
5845 struct face
*face
= NULL
;
5846 #ifdef HAVE_WINDOW_SYSTEM
5847 struct face
*default_face
;
5849 Lisp_Object stipple
, overline
, strike_through
, box
;
5851 xassert (FRAME_WINDOW_P (cache
->f
));
5853 /* Allocate a new realized face. */
5854 face
= make_realized_face (attrs
);
5855 face
->ascii_face
= face
;
5859 /* Determine the font to use. Most of the time, the font will be
5860 the same as the font of the default face, so try that first. */
5861 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5863 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
5865 face
->font
= default_face
->font
;
5867 = make_fontset_for_ascii_face (f
, default_face
->fontset
, face
);
5871 /* If the face attribute ATTRS specifies a fontset, use it as
5872 the base of a new realized fontset. Otherwise, use the same
5873 base fontset as of the default face. The base determines
5874 registry and encoding of a font. It may also determine
5875 foundry and family. The other fields of font name pattern
5876 are constructed from ATTRS. */
5877 int fontset
= face_fontset (attrs
);
5879 /* If we are realizing the default face, ATTRS should specify a
5880 fontset. In other words, if FONTSET is -1, we are not
5881 realizing the default face, thus the default face should have
5882 already been realized. */
5886 fontset
= default_face
->fontset
;
5890 if (! FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5891 attrs
[LFACE_FONT_INDEX
]
5892 = font_load_for_lface (f
, attrs
, attrs
[LFACE_FONT_INDEX
]);
5893 if (FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
]))
5895 face
->font
= XFONT_OBJECT (attrs
[LFACE_FONT_INDEX
]);
5896 face
->fontset
= make_fontset_for_ascii_face (f
, fontset
, face
);
5906 && FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]) > 100
5907 && FONT_WEIGHT_NUMERIC (attrs
[LFACE_FONT_INDEX
]) <= 100)
5908 face
->overstrike
= 1;
5910 /* Load colors, and set remaining attributes. */
5912 load_face_colors (f
, face
, attrs
);
5915 box
= attrs
[LFACE_BOX_INDEX
];
5918 /* A simple box of line width 1 drawn in color given by
5920 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
5922 face
->box
= FACE_SIMPLE_BOX
;
5923 face
->box_line_width
= 1;
5925 else if (INTEGERP (box
))
5927 /* Simple box of specified line width in foreground color of the
5929 xassert (XINT (box
) != 0);
5930 face
->box
= FACE_SIMPLE_BOX
;
5931 face
->box_line_width
= XINT (box
);
5932 face
->box_color
= face
->foreground
;
5933 face
->box_color_defaulted_p
= 1;
5935 else if (CONSP (box
))
5937 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
5938 being one of `raised' or `sunken'. */
5939 face
->box
= FACE_SIMPLE_BOX
;
5940 face
->box_color
= face
->foreground
;
5941 face
->box_color_defaulted_p
= 1;
5942 face
->box_line_width
= 1;
5946 Lisp_Object keyword
, value
;
5948 keyword
= XCAR (box
);
5956 if (EQ (keyword
, QCline_width
))
5958 if (INTEGERP (value
) && XINT (value
) != 0)
5959 face
->box_line_width
= XINT (value
);
5961 else if (EQ (keyword
, QCcolor
))
5963 if (STRINGP (value
))
5965 face
->box_color
= load_color (f
, face
, value
,
5967 face
->use_box_color_for_shadows_p
= 1;
5970 else if (EQ (keyword
, QCstyle
))
5972 if (EQ (value
, Qreleased_button
))
5973 face
->box
= FACE_RAISED_BOX
;
5974 else if (EQ (value
, Qpressed_button
))
5975 face
->box
= FACE_SUNKEN_BOX
;
5980 /* Text underline, overline, strike-through. */
5982 if (EQ (attrs
[LFACE_UNDERLINE_INDEX
], Qt
))
5984 /* Use default color (same as foreground color). */
5985 face
->underline_p
= 1;
5986 face
->underline_defaulted_p
= 1;
5987 face
->underline_color
= 0;
5989 else if (STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]))
5991 /* Use specified color. */
5992 face
->underline_p
= 1;
5993 face
->underline_defaulted_p
= 0;
5994 face
->underline_color
5995 = load_color (f
, face
, attrs
[LFACE_UNDERLINE_INDEX
],
5996 LFACE_UNDERLINE_INDEX
);
5998 else if (NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
6000 face
->underline_p
= 0;
6001 face
->underline_defaulted_p
= 0;
6002 face
->underline_color
= 0;
6005 overline
= attrs
[LFACE_OVERLINE_INDEX
];
6006 if (STRINGP (overline
))
6008 face
->overline_color
6009 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
6010 LFACE_OVERLINE_INDEX
);
6011 face
->overline_p
= 1;
6013 else if (EQ (overline
, Qt
))
6015 face
->overline_color
= face
->foreground
;
6016 face
->overline_color_defaulted_p
= 1;
6017 face
->overline_p
= 1;
6020 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
6021 if (STRINGP (strike_through
))
6023 face
->strike_through_color
6024 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
6025 LFACE_STRIKE_THROUGH_INDEX
);
6026 face
->strike_through_p
= 1;
6028 else if (EQ (strike_through
, Qt
))
6030 face
->strike_through_color
= face
->foreground
;
6031 face
->strike_through_color_defaulted_p
= 1;
6032 face
->strike_through_p
= 1;
6035 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
6036 if (!NILP (stipple
))
6037 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
6038 #endif /* HAVE_WINDOW_SYSTEM */
6044 /* Map a specified color of face FACE on frame F to a tty color index.
6045 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
6046 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
6047 default foreground/background colors. */
6050 map_tty_color (f
, face
, idx
, defaulted
)
6053 enum lface_attribute_index idx
;
6056 Lisp_Object frame
, color
, def
;
6057 int foreground_p
= idx
== LFACE_FOREGROUND_INDEX
;
6058 unsigned long default_pixel
, default_other_pixel
, pixel
;
6060 xassert (idx
== LFACE_FOREGROUND_INDEX
|| idx
== LFACE_BACKGROUND_INDEX
);
6064 pixel
= default_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
6065 default_other_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
6069 pixel
= default_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
6070 default_other_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
6073 XSETFRAME (frame
, f
);
6074 color
= face
->lface
[idx
];
6078 && CONSP (Vtty_defined_color_alist
)
6079 && (def
= assq_no_quit (color
, call1 (Qtty_color_alist
, frame
)),
6082 /* Associations in tty-defined-color-alist are of the form
6083 (NAME INDEX R G B). We need the INDEX part. */
6084 pixel
= XINT (XCAR (XCDR (def
)));
6087 if (pixel
== default_pixel
&& STRINGP (color
))
6089 pixel
= load_color (f
, face
, color
, idx
);
6092 /* If the foreground of the default face is the default color,
6093 use the foreground color defined by the frame. */
6094 if (FRAME_MSDOS_P (f
))
6096 if (pixel
== default_pixel
6097 || pixel
== FACE_TTY_DEFAULT_COLOR
)
6100 pixel
= FRAME_FOREGROUND_PIXEL (f
);
6102 pixel
= FRAME_BACKGROUND_PIXEL (f
);
6103 face
->lface
[idx
] = tty_color_name (f
, pixel
);
6106 else if (pixel
== default_other_pixel
)
6109 pixel
= FRAME_BACKGROUND_PIXEL (f
);
6111 pixel
= FRAME_FOREGROUND_PIXEL (f
);
6112 face
->lface
[idx
] = tty_color_name (f
, pixel
);
6120 face
->foreground
= pixel
;
6122 face
->background
= pixel
;
6126 /* Realize the fully-specified face with attributes ATTRS in face
6127 cache CACHE for ASCII characters. Do it for TTY frame CACHE->f.
6128 Value is a pointer to the newly created realized face. */
6130 static struct face
*
6131 realize_tty_face (cache
, attrs
)
6132 struct face_cache
*cache
;
6137 int face_colors_defaulted
= 0;
6138 struct frame
*f
= cache
->f
;
6140 /* Frame must be a termcap frame. */
6141 xassert (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
));
6143 /* Allocate a new realized face. */
6144 face
= make_realized_face (attrs
);
6146 face
->font_name
= FRAME_MSDOS_P (cache
->f
) ? "ms-dos" : "tty";
6149 /* Map face attributes to TTY appearances. We map slant to
6150 dimmed text because we want italic text to appear differently
6151 and because dimmed text is probably used infrequently. */
6152 weight
= FONT_WEIGHT_NAME_NUMERIC (attrs
[LFACE_WEIGHT_INDEX
]);
6153 slant
= FONT_SLANT_NAME_NUMERIC (attrs
[LFACE_SLANT_INDEX
]);
6155 face
->tty_bold_p
= 1;
6156 if (weight
< 100 || slant
!= 100)
6157 face
->tty_dim_p
= 1;
6158 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
6159 face
->tty_underline_p
= 1;
6160 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
6161 face
->tty_reverse_p
= 1;
6163 /* Map color names to color indices. */
6164 map_tty_color (f
, face
, LFACE_FOREGROUND_INDEX
, &face_colors_defaulted
);
6165 map_tty_color (f
, face
, LFACE_BACKGROUND_INDEX
, &face_colors_defaulted
);
6167 /* Swap colors if face is inverse-video. If the colors are taken
6168 from the frame colors, they are already inverted, since the
6169 frame-creation function calls x-handle-reverse-video. */
6170 if (face
->tty_reverse_p
&& !face_colors_defaulted
)
6172 unsigned long tem
= face
->foreground
;
6173 face
->foreground
= face
->background
;
6174 face
->background
= tem
;
6177 if (tty_suppress_bold_inverse_default_colors_p
6179 && face
->background
== FACE_TTY_DEFAULT_FG_COLOR
6180 && face
->foreground
== FACE_TTY_DEFAULT_BG_COLOR
)
6181 face
->tty_bold_p
= 0;
6187 DEFUN ("tty-suppress-bold-inverse-default-colors",
6188 Ftty_suppress_bold_inverse_default_colors
,
6189 Stty_suppress_bold_inverse_default_colors
, 1, 1, 0,
6190 doc
: /* Suppress/allow boldness of faces with inverse default colors.
6191 SUPPRESS non-nil means suppress it.
6192 This affects bold faces on TTYs whose foreground is the default background
6193 color of the display and whose background is the default foreground color.
6194 For such faces, the bold face attribute is ignored if this variable
6197 Lisp_Object suppress
;
6199 tty_suppress_bold_inverse_default_colors_p
= !NILP (suppress
);
6200 ++face_change_count
;
6206 /***********************************************************************
6208 ***********************************************************************/
6210 /* Return the ID of the face to use to display character CH with face
6211 property PROP on frame F in current_buffer. */
6214 compute_char_face (f
, ch
, prop
)
6221 if (NILP (current_buffer
->enable_multibyte_characters
))
6226 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6227 face_id
= FACE_FOR_CHAR (f
, face
, ch
, -1, Qnil
);
6231 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6232 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6233 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
6234 merge_face_ref (f
, prop
, attrs
, 1, 0);
6235 face_id
= lookup_face (f
, attrs
);
6241 /* Return the face ID associated with buffer position POS for
6242 displaying ASCII characters. Return in *ENDPTR the position at
6243 which a different face is needed, as far as text properties and
6244 overlays are concerned. W is a window displaying current_buffer.
6246 REGION_BEG, REGION_END delimit the region, so it can be
6249 LIMIT is a position not to scan beyond. That is to limit the time
6250 this function can take.
6252 If MOUSE is non-zero, use the character's mouse-face, not its face.
6254 BASE_FACE_ID, if non-negative, specifies a base face id to use
6255 instead of DEFAULT_FACE_ID.
6257 The face returned is suitable for displaying ASCII characters. */
6260 face_at_buffer_position (w
, pos
, region_beg
, region_end
,
6261 endptr
, limit
, mouse
, base_face_id
)
6264 EMACS_INT region_beg
, region_end
;
6270 struct frame
*f
= XFRAME (w
->frame
);
6271 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6272 Lisp_Object prop
, position
;
6274 Lisp_Object
*overlay_vec
;
6277 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
6278 Lisp_Object limit1
, end
;
6279 struct face
*default_face
;
6281 /* W must display the current buffer. We could write this function
6282 to use the frame and buffer of W, but right now it doesn't. */
6283 /* xassert (XBUFFER (w->buffer) == current_buffer); */
6285 XSETFRAME (frame
, f
);
6286 XSETFASTINT (position
, pos
);
6289 if (pos
< region_beg
&& region_beg
< endpos
)
6290 endpos
= region_beg
;
6292 /* Get the `face' or `mouse_face' text property at POS, and
6293 determine the next position at which the property changes. */
6294 prop
= Fget_text_property (position
, propname
, w
->buffer
);
6295 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6296 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
6298 endpos
= XINT (end
);
6300 /* Look at properties from overlays. */
6302 EMACS_INT next_overlay
;
6304 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, &next_overlay
, 0);
6305 if (next_overlay
< endpos
)
6306 endpos
= next_overlay
;
6311 default_face
= FACE_FROM_ID (f
, base_face_id
>= 0 ? base_face_id
6312 : NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
6313 : lookup_basic_face (f
, DEFAULT_FACE_ID
));
6315 /* Optimize common cases where we can use the default face. */
6318 && !(pos
>= region_beg
&& pos
< region_end
))
6319 return default_face
->id
;
6321 /* Begin with attributes from the default face. */
6322 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
6324 /* Merge in attributes specified via text properties. */
6326 merge_face_ref (f
, prop
, attrs
, 1, 0);
6328 /* Now merge the overlay data. */
6329 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6330 for (i
= 0; i
< noverlays
; i
++)
6335 prop
= Foverlay_get (overlay_vec
[i
], propname
);
6337 merge_face_ref (f
, prop
, attrs
, 1, 0);
6339 oend
= OVERLAY_END (overlay_vec
[i
]);
6340 oendpos
= OVERLAY_POSITION (oend
);
6341 if (oendpos
< endpos
)
6345 /* If in the region, merge in the region face. */
6346 if (pos
>= region_beg
&& pos
< region_end
)
6348 merge_named_face (f
, Qregion
, attrs
, 0);
6350 if (region_end
< endpos
)
6351 endpos
= region_end
;
6356 /* Look up a realized face with the given face attributes,
6357 or realize a new one for ASCII characters. */
6358 return lookup_face (f
, attrs
);
6361 /* Return the face ID at buffer position POS for displaying ASCII
6362 characters associated with overlay strings for overlay OVERLAY.
6364 Like face_at_buffer_position except for OVERLAY. Currently it
6365 simply disregards the `face' properties of all overlays. */
6368 face_for_overlay_string (w
, pos
, region_beg
, region_end
,
6369 endptr
, limit
, mouse
, overlay
)
6372 EMACS_INT region_beg
, region_end
;
6376 Lisp_Object overlay
;
6378 struct frame
*f
= XFRAME (w
->frame
);
6379 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6380 Lisp_Object prop
, position
;
6383 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
6384 Lisp_Object limit1
, end
;
6385 struct face
*default_face
;
6387 /* W must display the current buffer. We could write this function
6388 to use the frame and buffer of W, but right now it doesn't. */
6389 /* xassert (XBUFFER (w->buffer) == current_buffer); */
6391 XSETFRAME (frame
, f
);
6392 XSETFASTINT (position
, pos
);
6395 if (pos
< region_beg
&& region_beg
< endpos
)
6396 endpos
= region_beg
;
6398 /* Get the `face' or `mouse_face' text property at POS, and
6399 determine the next position at which the property changes. */
6400 prop
= Fget_text_property (position
, propname
, w
->buffer
);
6401 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6402 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
6404 endpos
= XINT (end
);
6408 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6410 /* Optimize common cases where we can use the default face. */
6412 && !(pos
>= region_beg
&& pos
< region_end
))
6413 return DEFAULT_FACE_ID
;
6415 /* Begin with attributes from the default face. */
6416 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
6418 /* Merge in attributes specified via text properties. */
6420 merge_face_ref (f
, prop
, attrs
, 1, 0);
6422 /* If in the region, merge in the region face. */
6423 if (pos
>= region_beg
&& pos
< region_end
)
6425 merge_named_face (f
, Qregion
, attrs
, 0);
6427 if (region_end
< endpos
)
6428 endpos
= region_end
;
6433 /* Look up a realized face with the given face attributes,
6434 or realize a new one for ASCII characters. */
6435 return lookup_face (f
, attrs
);
6439 /* Compute the face at character position POS in Lisp string STRING on
6440 window W, for ASCII characters.
6442 If STRING is an overlay string, it comes from position BUFPOS in
6443 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
6444 not an overlay string. W must display the current buffer.
6445 REGION_BEG and REGION_END give the start and end positions of the
6446 region; both are -1 if no region is visible.
6448 BASE_FACE_ID is the id of a face to merge with. For strings coming
6449 from overlays or the `display' property it is the face at BUFPOS.
6451 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
6453 Set *ENDPTR to the next position where to check for faces in
6454 STRING; -1 if the face is constant from POS to the end of the
6457 Value is the id of the face to use. The face returned is suitable
6458 for displaying ASCII characters. */
6461 face_at_string_position (w
, string
, pos
, bufpos
, region_beg
,
6462 region_end
, endptr
, base_face_id
, mouse_p
)
6465 EMACS_INT pos
, bufpos
;
6466 EMACS_INT region_beg
, region_end
;
6468 enum face_id base_face_id
;
6471 Lisp_Object prop
, position
, end
, limit
;
6472 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6473 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6474 struct face
*base_face
;
6475 int multibyte_p
= STRING_MULTIBYTE (string
);
6476 Lisp_Object prop_name
= mouse_p
? Qmouse_face
: Qface
;
6478 /* Get the value of the face property at the current position within
6479 STRING. Value is nil if there is no face property. */
6480 XSETFASTINT (position
, pos
);
6481 prop
= Fget_text_property (position
, prop_name
, string
);
6483 /* Get the next position at which to check for faces. Value of end
6484 is nil if face is constant all the way to the end of the string.
6485 Otherwise it is a string position where to check faces next.
6486 Limit is the maximum position up to which to check for property
6487 changes in Fnext_single_property_change. Strings are usually
6488 short, so set the limit to the end of the string. */
6489 XSETFASTINT (limit
, SCHARS (string
));
6490 end
= Fnext_single_property_change (position
, prop_name
, string
, limit
);
6492 *endptr
= XFASTINT (end
);
6496 base_face
= FACE_FROM_ID (f
, base_face_id
);
6497 xassert (base_face
);
6499 /* Optimize the default case that there is no face property and we
6500 are not in the region. */
6502 && (base_face_id
!= DEFAULT_FACE_ID
6503 /* BUFPOS <= 0 means STRING is not an overlay string, so
6504 that the region doesn't have to be taken into account. */
6506 || bufpos
< region_beg
6507 || bufpos
>= region_end
)
6509 /* We can't realize faces for different charsets differently
6510 if we don't have fonts, so we can stop here if not working
6511 on a window-system frame. */
6512 || !FRAME_WINDOW_P (f
)
6513 || FACE_SUITABLE_FOR_CHAR_P (base_face
, 0)))
6514 return base_face
->id
;
6516 /* Begin with attributes from the base face. */
6517 bcopy (base_face
->lface
, attrs
, sizeof attrs
);
6519 /* Merge in attributes specified via text properties. */
6521 merge_face_ref (f
, prop
, attrs
, 1, 0);
6523 /* If in the region, merge in the region face. */
6525 && bufpos
>= region_beg
6526 && bufpos
< region_end
)
6527 merge_named_face (f
, Qregion
, attrs
, 0);
6529 /* Look up a realized face with the given face attributes,
6530 or realize a new one for ASCII characters. */
6531 return lookup_face (f
, attrs
);
6535 /* Merge a face into a realized face.
6537 F is frame where faces are (to be) realized.
6539 FACE_NAME is named face to merge.
6541 If FACE_NAME is nil, FACE_ID is face_id of realized face to merge.
6543 If FACE_NAME is t, FACE_ID is lface_id of face to merge.
6545 BASE_FACE_ID is realized face to merge into.
6551 merge_faces (f
, face_name
, face_id
, base_face_id
)
6553 Lisp_Object face_name
;
6554 int face_id
, base_face_id
;
6556 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6557 struct face
*base_face
;
6559 base_face
= FACE_FROM_ID (f
, base_face_id
);
6561 return base_face_id
;
6563 if (EQ (face_name
, Qt
))
6565 if (face_id
< 0 || face_id
>= lface_id_to_name_size
)
6566 return base_face_id
;
6567 face_name
= lface_id_to_name
[face_id
];
6568 /* When called during make-frame, lookup_derived_face may fail
6569 if the faces are uninitialized. Don't signal an error. */
6570 face_id
= lookup_derived_face (f
, face_name
, base_face_id
, 0);
6571 return (face_id
>= 0 ? face_id
: base_face_id
);
6574 /* Begin with attributes from the base face. */
6575 bcopy (base_face
->lface
, attrs
, sizeof attrs
);
6577 if (!NILP (face_name
))
6579 if (!merge_named_face (f
, face_name
, attrs
, 0))
6580 return base_face_id
;
6586 return base_face_id
;
6587 face
= FACE_FROM_ID (f
, face_id
);
6589 return base_face_id
;
6590 merge_face_vectors (f
, face
->lface
, attrs
, 0);
6593 /* Look up a realized face with the given face attributes,
6594 or realize a new one for ASCII characters. */
6595 return lookup_face (f
, attrs
);
6600 #ifndef HAVE_X_WINDOWS
6601 DEFUN ("x-load-color-file", Fx_load_color_file
,
6602 Sx_load_color_file
, 1, 1, 0,
6603 doc
: /* Create an alist of color entries from an external file.
6605 The file should define one named RGB color per line like so:
6607 where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
6609 Lisp_Object filename
;
6612 Lisp_Object cmap
= Qnil
;
6613 Lisp_Object abspath
;
6615 CHECK_STRING (filename
);
6616 abspath
= Fexpand_file_name (filename
, Qnil
);
6618 fp
= fopen (SDATA (filename
), "rt");
6622 int red
, green
, blue
;
6627 while (fgets (buf
, sizeof (buf
), fp
) != NULL
) {
6628 if (sscanf (buf
, "%u %u %u %n", &red
, &green
, &blue
, &num
) == 3)
6630 char *name
= buf
+ num
;
6631 num
= strlen (name
) - 1;
6632 if (num
>= 0 && name
[num
] == '\n')
6634 cmap
= Fcons (Fcons (build_string (name
),
6636 make_number (RGB (red
, green
, blue
))),
6638 make_number ((red
<< 16) | (green
<< 8) | blue
)),
6653 /***********************************************************************
6655 ***********************************************************************/
6659 /* Print the contents of the realized face FACE to stderr. */
6662 dump_realized_face (face
)
6665 fprintf (stderr
, "ID: %d\n", face
->id
);
6666 #ifdef HAVE_X_WINDOWS
6667 fprintf (stderr
, "gc: %ld\n", (long) face
->gc
);
6669 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
6671 SDATA (face
->lface
[LFACE_FOREGROUND_INDEX
]));
6672 fprintf (stderr
, "background: 0x%lx (%s)\n",
6674 SDATA (face
->lface
[LFACE_BACKGROUND_INDEX
]));
6676 fprintf (stderr
, "font_name: %s (%s)\n",
6677 SDATA (face
->font
->props
[FONT_NAME_INDEX
]),
6678 SDATA (face
->lface
[LFACE_FAMILY_INDEX
]));
6679 #ifdef HAVE_X_WINDOWS
6680 fprintf (stderr
, "font = %p\n", face
->font
);
6682 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
6683 fprintf (stderr
, "underline: %d (%s)\n",
6685 SDATA (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
])));
6686 fprintf (stderr
, "hash: %d\n", face
->hash
);
6690 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, doc
: /* */)
6698 fprintf (stderr
, "font selection order: ");
6699 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6700 fprintf (stderr
, "%d ", font_sort_order
[i
]);
6701 fprintf (stderr
, "\n");
6703 fprintf (stderr
, "alternative fonts: ");
6704 debug_print (Vface_alternative_font_family_alist
);
6705 fprintf (stderr
, "\n");
6707 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
6708 Fdump_face (make_number (i
));
6714 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
6716 error ("Not a valid face");
6717 dump_realized_face (face
);
6724 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
6725 0, 0, 0, doc
: /* */)
6728 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
6729 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
6730 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
6734 #endif /* GLYPH_DEBUG != 0 */
6738 /***********************************************************************
6740 ***********************************************************************/
6745 Qface
= intern ("face");
6747 Qface_no_inherit
= intern ("face-no-inherit");
6748 staticpro (&Qface_no_inherit
);
6749 Qbitmap_spec_p
= intern ("bitmap-spec-p");
6750 staticpro (&Qbitmap_spec_p
);
6751 Qframe_set_background_mode
= intern ("frame-set-background-mode");
6752 staticpro (&Qframe_set_background_mode
);
6754 /* Lisp face attribute keywords. */
6755 QCfamily
= intern (":family");
6756 staticpro (&QCfamily
);
6757 QCheight
= intern (":height");
6758 staticpro (&QCheight
);
6759 QCweight
= intern (":weight");
6760 staticpro (&QCweight
);
6761 QCslant
= intern (":slant");
6762 staticpro (&QCslant
);
6763 QCunderline
= intern (":underline");
6764 staticpro (&QCunderline
);
6765 QCinverse_video
= intern (":inverse-video");
6766 staticpro (&QCinverse_video
);
6767 QCreverse_video
= intern (":reverse-video");
6768 staticpro (&QCreverse_video
);
6769 QCforeground
= intern (":foreground");
6770 staticpro (&QCforeground
);
6771 QCbackground
= intern (":background");
6772 staticpro (&QCbackground
);
6773 QCstipple
= intern (":stipple");
6774 staticpro (&QCstipple
);
6775 QCwidth
= intern (":width");
6776 staticpro (&QCwidth
);
6777 QCfont
= intern (":font");
6778 staticpro (&QCfont
);
6779 QCfontset
= intern (":fontset");
6780 staticpro (&QCfontset
);
6781 QCbold
= intern (":bold");
6782 staticpro (&QCbold
);
6783 QCitalic
= intern (":italic");
6784 staticpro (&QCitalic
);
6785 QCoverline
= intern (":overline");
6786 staticpro (&QCoverline
);
6787 QCstrike_through
= intern (":strike-through");
6788 staticpro (&QCstrike_through
);
6789 QCbox
= intern (":box");
6791 QCinherit
= intern (":inherit");
6792 staticpro (&QCinherit
);
6794 /* Symbols used for Lisp face attribute values. */
6795 QCcolor
= intern (":color");
6796 staticpro (&QCcolor
);
6797 QCline_width
= intern (":line-width");
6798 staticpro (&QCline_width
);
6799 QCstyle
= intern (":style");
6800 staticpro (&QCstyle
);
6801 Qreleased_button
= intern ("released-button");
6802 staticpro (&Qreleased_button
);
6803 Qpressed_button
= intern ("pressed-button");
6804 staticpro (&Qpressed_button
);
6805 Qnormal
= intern ("normal");
6806 staticpro (&Qnormal
);
6807 Qultra_light
= intern ("ultra-light");
6808 staticpro (&Qultra_light
);
6809 Qextra_light
= intern ("extra-light");
6810 staticpro (&Qextra_light
);
6811 Qlight
= intern ("light");
6812 staticpro (&Qlight
);
6813 Qsemi_light
= intern ("semi-light");
6814 staticpro (&Qsemi_light
);
6815 Qsemi_bold
= intern ("semi-bold");
6816 staticpro (&Qsemi_bold
);
6817 Qbold
= intern ("bold");
6819 Qextra_bold
= intern ("extra-bold");
6820 staticpro (&Qextra_bold
);
6821 Qultra_bold
= intern ("ultra-bold");
6822 staticpro (&Qultra_bold
);
6823 Qoblique
= intern ("oblique");
6824 staticpro (&Qoblique
);
6825 Qitalic
= intern ("italic");
6826 staticpro (&Qitalic
);
6827 Qreverse_oblique
= intern ("reverse-oblique");
6828 staticpro (&Qreverse_oblique
);
6829 Qreverse_italic
= intern ("reverse-italic");
6830 staticpro (&Qreverse_italic
);
6831 Qultra_condensed
= intern ("ultra-condensed");
6832 staticpro (&Qultra_condensed
);
6833 Qextra_condensed
= intern ("extra-condensed");
6834 staticpro (&Qextra_condensed
);
6835 Qcondensed
= intern ("condensed");
6836 staticpro (&Qcondensed
);
6837 Qsemi_condensed
= intern ("semi-condensed");
6838 staticpro (&Qsemi_condensed
);
6839 Qsemi_expanded
= intern ("semi-expanded");
6840 staticpro (&Qsemi_expanded
);
6841 Qexpanded
= intern ("expanded");
6842 staticpro (&Qexpanded
);
6843 Qextra_expanded
= intern ("extra-expanded");
6844 staticpro (&Qextra_expanded
);
6845 Qultra_expanded
= intern ("ultra-expanded");
6846 staticpro (&Qultra_expanded
);
6847 Qbackground_color
= intern ("background-color");
6848 staticpro (&Qbackground_color
);
6849 Qforeground_color
= intern ("foreground-color");
6850 staticpro (&Qforeground_color
);
6851 Qunspecified
= intern ("unspecified");
6852 staticpro (&Qunspecified
);
6853 Qignore_defface
= intern (":ignore-defface");
6854 staticpro (&Qignore_defface
);
6856 Qface_alias
= intern ("face-alias");
6857 staticpro (&Qface_alias
);
6858 Qdefault
= intern ("default");
6859 staticpro (&Qdefault
);
6860 Qtool_bar
= intern ("tool-bar");
6861 staticpro (&Qtool_bar
);
6862 Qregion
= intern ("region");
6863 staticpro (&Qregion
);
6864 Qfringe
= intern ("fringe");
6865 staticpro (&Qfringe
);
6866 Qheader_line
= intern ("header-line");
6867 staticpro (&Qheader_line
);
6868 Qscroll_bar
= intern ("scroll-bar");
6869 staticpro (&Qscroll_bar
);
6870 Qmenu
= intern ("menu");
6872 Qcursor
= intern ("cursor");
6873 staticpro (&Qcursor
);
6874 Qborder
= intern ("border");
6875 staticpro (&Qborder
);
6876 Qmouse
= intern ("mouse");
6877 staticpro (&Qmouse
);
6878 Qmode_line_inactive
= intern ("mode-line-inactive");
6879 staticpro (&Qmode_line_inactive
);
6880 Qvertical_border
= intern ("vertical-border");
6881 staticpro (&Qvertical_border
);
6882 Qtty_color_desc
= intern ("tty-color-desc");
6883 staticpro (&Qtty_color_desc
);
6884 Qtty_color_standard_values
= intern ("tty-color-standard-values");
6885 staticpro (&Qtty_color_standard_values
);
6886 Qtty_color_by_index
= intern ("tty-color-by-index");
6887 staticpro (&Qtty_color_by_index
);
6888 Qtty_color_alist
= intern ("tty-color-alist");
6889 staticpro (&Qtty_color_alist
);
6890 Qscalable_fonts_allowed
= intern ("scalable-fonts-allowed");
6891 staticpro (&Qscalable_fonts_allowed
);
6893 Vparam_value_alist
= Fcons (Fcons (Qnil
, Qnil
), Qnil
);
6894 staticpro (&Vparam_value_alist
);
6895 Vface_alternative_font_family_alist
= Qnil
;
6896 staticpro (&Vface_alternative_font_family_alist
);
6897 Vface_alternative_font_registry_alist
= Qnil
;
6898 staticpro (&Vface_alternative_font_registry_alist
);
6900 defsubr (&Sinternal_make_lisp_face
);
6901 defsubr (&Sinternal_lisp_face_p
);
6902 defsubr (&Sinternal_set_lisp_face_attribute
);
6903 #ifdef HAVE_WINDOW_SYSTEM
6904 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
6906 defsubr (&Scolor_gray_p
);
6907 defsubr (&Scolor_supported_p
);
6908 #ifndef HAVE_X_WINDOWS
6909 defsubr (&Sx_load_color_file
);
6911 defsubr (&Sface_attribute_relative_p
);
6912 defsubr (&Smerge_face_attribute
);
6913 defsubr (&Sinternal_get_lisp_face_attribute
);
6914 defsubr (&Sinternal_lisp_face_attribute_values
);
6915 defsubr (&Sinternal_lisp_face_equal_p
);
6916 defsubr (&Sinternal_lisp_face_empty_p
);
6917 defsubr (&Sinternal_copy_lisp_face
);
6918 defsubr (&Sinternal_merge_in_global_face
);
6919 defsubr (&Sface_font
);
6920 defsubr (&Sframe_face_alist
);
6921 defsubr (&Sdisplay_supports_face_attributes_p
);
6922 defsubr (&Scolor_distance
);
6923 defsubr (&Sinternal_set_font_selection_order
);
6924 defsubr (&Sinternal_set_alternative_font_family_alist
);
6925 defsubr (&Sinternal_set_alternative_font_registry_alist
);
6926 defsubr (&Sface_attributes_as_vector
);
6928 defsubr (&Sdump_face
);
6929 defsubr (&Sshow_face_resources
);
6930 #endif /* GLYPH_DEBUG */
6931 defsubr (&Sclear_face_cache
);
6932 defsubr (&Stty_suppress_bold_inverse_default_colors
);
6934 #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS
6935 defsubr (&Sdump_colors
);
6938 DEFVAR_LISP ("font-list-limit", &Vfont_list_limit
,
6939 doc
: /* *Limit for font matching.
6940 If an integer > 0, font matching functions won't load more than
6941 that number of fonts when searching for a matching font. */);
6942 Vfont_list_limit
= make_number (DEFAULT_FONT_LIST_LIMIT
);
6944 DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults
,
6945 doc
: /* List of global face definitions (for internal use only.) */);
6946 Vface_new_frame_defaults
= Qnil
;
6948 DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple
,
6949 doc
: /* *Default stipple pattern used on monochrome displays.
6950 This stipple pattern is used on monochrome displays
6951 instead of shades of gray for a face background color.
6952 See `set-face-stipple' for possible values for this variable. */);
6953 Vface_default_stipple
= build_string ("gray3");
6955 DEFVAR_LISP ("tty-defined-color-alist", &Vtty_defined_color_alist
,
6956 doc
: /* An alist of defined terminal colors and their RGB values. */);
6957 Vtty_defined_color_alist
= Qnil
;
6959 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed
,
6960 doc
: /* Allowed scalable fonts.
6961 A value of nil means don't allow any scalable fonts.
6962 A value of t means allow any scalable font.
6963 Otherwise, value must be a list of regular expressions. A font may be
6964 scaled if its name matches a regular expression in the list.
6965 Note that if value is nil, a scalable font might still be used, if no
6966 other font of the appropriate family and registry is available. */);
6967 Vscalable_fonts_allowed
= Qnil
;
6969 DEFVAR_LISP ("face-ignored-fonts", &Vface_ignored_fonts
,
6970 doc
: /* List of ignored fonts.
6971 Each element is a regular expression that matches names of fonts to
6973 Vface_ignored_fonts
= Qnil
;
6975 DEFVAR_LISP ("face-remapping-alist", &Vface_remapping_alist
,
6976 doc
: /* Alist of face remappings.
6977 Each element is of the form:
6979 (FACE REPLACEMENT...),
6981 which causes display of the face FACE to use REPLACEMENT... instead.
6982 REPLACEMENT... is interpreted the same way the value of a `face' text
6983 property is: it may be (1) A face name, (2) A list of face names, (3) A
6984 property-list of face attribute/value pairs, or (4) A list of face names
6985 intermixed with lists containing face attribute/value pairs.
6987 Multiple entries in REPLACEMENT... are merged together to form the final
6988 result, with faces or attributes earlier in the list taking precedence
6989 over those that are later.
6991 Face-name remapping cycles are suppressed; recursive references use the
6992 underlying face instead of the remapped face. So a remapping of the form:
6994 (FACE EXTRA-FACE... FACE)
6998 (FACE (FACE-ATTR VAL ...) FACE)
7000 will cause EXTRA-FACE... or (FACE-ATTR VAL ...) to be _merged_ with the
7001 existing definition of FACE. Note that for the default face, this isn't
7002 necessary, as every face inherits from the default face.
7004 Making this variable buffer-local is a good way to allow buffer-specific
7005 face definitions. For instance, the mode my-mode could define a face
7006 `my-mode-default', and then in the mode setup function, do:
7008 (set (make-local-variable 'face-remapping-alist)
7009 '((default my-mode-default)))). */);
7010 Vface_remapping_alist
= Qnil
;
7012 DEFVAR_LISP ("face-font-rescale-alist", &Vface_font_rescale_alist
,
7013 doc
: /* Alist of fonts vs the rescaling factors.
7014 Each element is a cons (FONT-PATTERN . RESCALE-RATIO), where
7015 FONT-PATTERN is a font-spec or a regular expression matching a font name, and
7016 RESCALE-RATIO is a floating point number to specify how much larger
7017 \(or smaller) font we should use. For instance, if a face requests
7018 a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point. */);
7019 Vface_font_rescale_alist
= Qnil
;
7021 #ifdef HAVE_WINDOW_SYSTEM
7022 defsubr (&Sbitmap_spec_p
);
7023 defsubr (&Sx_list_fonts
);
7024 defsubr (&Sinternal_face_x_get_resource
);
7025 defsubr (&Sx_family_fonts
);
7029 /* arch-tag: 8a0f7598-5517-408d-9ab3-1da6fcd4c749
7030 (do not change this comment) */