1 /* xfaces.c -- "Face" primitives.
2 Copyright (C) 1993, 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation.
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 2, or (at your option)
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; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New face implementation by Gerd Moellmann <gerd@gnu.org>. */
26 When using Emacs with X, the display style of characters can be
27 changed by defining `faces'. Each face can specify the following
32 2. Relative proportionate width, aka character set width or set
33 width (swidth), e.g. `semi-compressed'.
35 3. Font height in 1/10pt.
37 4. Font weight, e.g. `bold'.
39 5. Font slant, e.g. `italic'.
45 8. Whether or not characters should be underlined, and in what color.
47 9. Whether or not characters should be displayed in inverse video.
49 10. A background stipple, a bitmap.
51 11. Whether or not characters should be overlined, and in what color.
53 12. Whether or not characters should be strike-through, and in what
56 13. Whether or not a box should be drawn around characters, the box
57 type, and, for simple boxes, in what color.
59 14. Font or fontset pattern, or nil. This is a special attribute.
60 When this attribute is specified, the face uses a font opened by
61 that pattern as is. In addition, all the other font-related
62 attributes (1st thru 5th) are generated from the opened font name.
63 On the other hand, if one of the other font-related attributes are
64 specified, this attribute is set to nil. In that case, the face
65 doesn't inherit this attribute from the `default' face, and uses a
66 font determined by the other attributes (those may be inherited
67 from the `default' face).
69 15. A face name or list of face names from which to inherit attributes.
71 16. A specified average font width, which is invisible from Lisp,
72 and is used to ensure that a font specified on the command line,
73 for example, can be matched exactly.
75 Faces are frame-local by nature because Emacs allows to define the
76 same named face (face names are symbols) differently for different
77 frames. Each frame has an alist of face definitions for all named
78 faces. The value of a named face in such an alist is a Lisp vector
79 with the symbol `face' in slot 0, and a slot for each of the face
80 attributes mentioned above.
82 There is also a global face alist `Vface_new_frame_defaults'. Face
83 definitions from this list are used to initialize faces of newly
86 A face doesn't have to specify all attributes. Those not specified
87 have a value of `unspecified'. Faces specifying all attributes but
88 the 14th are called `fully-specified'.
93 The display style of a given character in the text is determined by
94 combining several faces. This process is called `face merging'.
95 Any aspect of the display style that isn't specified by overlays or
96 text properties is taken from the `default' face. Since it is made
97 sure that the default face is always fully-specified, face merging
98 always results in a fully-specified face.
103 After all face attributes for a character have been determined by
104 merging faces of that character, that face is `realized'. The
105 realization process maps face attributes to what is physically
106 available on the system where Emacs runs. The result is a
107 `realized face' in form of a struct face which is stored in the
108 face cache of the frame on which it was realized.
110 Face realization is done in the context of the character to display
111 because different fonts may be used for different characters. In
112 other words, for characters that have different font
113 specifications, different realized faces are needed to display
116 Font specification is done by fontsets. See the comment in
117 fontset.c for the details. In the current implementation, all ASCII
118 characters share the same font in a fontset.
120 Faces are at first realized for ASCII characters, and, at that
121 time, assigned a specific realized fontset. Hereafter, we call
122 such a face as `ASCII face'. When a face for a multibyte character
123 is realized, it inherits (thus shares) a fontset of an ASCII face
124 that has the same attributes other than font-related ones.
126 Thus, all realized face have a realized fontset.
131 Unibyte text (i.e. raw 8-bit characters) is displayed with the same
132 font as ASCII characters. That is because it is expected that
133 unibyte text users specify a font that is suitable both for ASCII
134 and raw 8-bit characters.
139 Font selection tries to find the best available matching font for a
140 given (character, face) combination.
142 If the face specifies a fontset name, that fontset determines a
143 pattern for fonts of the given character. If the face specifies a
144 font name or the other font-related attributes, a fontset is
145 realized from the default fontset. In that case, that
146 specification determines a pattern for ASCII characters and the
147 default fontset determines a pattern for multibyte characters.
149 Available fonts on the system on which Emacs runs are then matched
150 against the font pattern. The result of font selection is the best
151 match for the given face attributes in this font list.
153 Font selection can be influenced by the user.
155 1. The user can specify the relative importance he gives the face
156 attributes width, height, weight, and slant by setting
157 face-font-selection-order (faces.el) to a list of face attribute
158 names. The default is '(:width :height :weight :slant), and means
159 that font selection first tries to find a good match for the font
160 width specified by a face, then---within fonts with that
161 width---tries to find a best match for the specified font height,
164 2. Setting face-font-family-alternatives allows the user to
165 specify alternative font families to try if a family specified by a
168 3. Setting face-font-registry-alternatives allows the user to
169 specify all alternative font registries to try for a face
170 specifying a registry.
172 4. Setting face-ignored-fonts allows the user to ignore specific
176 Character composition.
178 Usually, the realization process is already finished when Emacs
179 actually reflects the desired glyph matrix on the screen. However,
180 on displaying a composition (sequence of characters to be composed
181 on the screen), a suitable font for the components of the
182 composition is selected and realized while drawing them on the
183 screen, i.e. the realization process is delayed but in principle
187 Initialization of basic faces.
189 The faces `default', `modeline' are considered `basic faces'.
190 When redisplay happens the first time for a newly created frame,
191 basic faces are realized for CHARSET_ASCII. Frame parameters are
192 used to fill in unspecified attributes of the default face. */
196 #include <sys/types.h>
197 #include <sys/stat.h>
201 #include "keyboard.h"
204 #ifdef HAVE_WINDOW_SYSTEM
206 #endif /* HAVE_WINDOW_SYSTEM */
208 #ifdef HAVE_X_WINDOWS
212 #include <Xm/XmStrDefs.h>
213 #endif /* USE_MOTIF */
214 #endif /* HAVE_X_WINDOWS */
223 /* Redefine X specifics to W32 equivalents to avoid cluttering the
224 code with #ifdef blocks. */
225 #undef FRAME_X_DISPLAY_INFO
226 #define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO
227 #define x_display_info w32_display_info
228 #define FRAME_X_FONT_TABLE FRAME_W32_FONT_TABLE
229 #define check_x check_w32
230 #define x_list_fonts w32_list_fonts
231 #define GCGraphicsExposures 0
232 #endif /* WINDOWSNT */
236 #define x_display_info mac_display_info
237 #define check_x check_mac
241 #include "dispextern.h"
242 #include "blockinput.h"
244 #include "intervals.h"
246 #ifdef HAVE_X_WINDOWS
248 /* Compensate for a bug in Xos.h on some systems, on which it requires
249 time.h. On some such systems, Xos.h tries to redefine struct
250 timeval and struct timezone if USG is #defined while it is
253 #ifdef XOS_NEEDS_TIME_H
259 #else /* not XOS_NEEDS_TIME_H */
261 #endif /* not XOS_NEEDS_TIME_H */
263 #endif /* HAVE_X_WINDOWS */
267 #define abs(X) ((X) < 0 ? -(X) : (X))
269 /* Number of pt per inch (from the TeXbook). */
271 #define PT_PER_INCH 72.27
273 /* Non-zero if face attribute ATTR is unspecified. */
275 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified)
277 /* Value is the number of elements of VECTOR. */
279 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
281 /* Make a copy of string S on the stack using alloca. Value is a pointer
284 #define STRDUPA(S) strcpy ((char *) alloca (strlen ((S)) + 1), (S))
286 /* Make a copy of the contents of Lisp string S on the stack using
287 alloca. Value is a pointer to the copy. */
289 #define LSTRDUPA(S) STRDUPA (SDATA ((S)))
291 /* Size of hash table of realized faces in face caches (should be a
294 #define FACE_CACHE_BUCKETS_SIZE 1001
296 /* Keyword symbols used for face attribute names. */
298 Lisp_Object QCfamily
, QCheight
, QCweight
, QCslant
, QCunderline
;
299 Lisp_Object QCinverse_video
, QCforeground
, QCbackground
, QCstipple
;
300 Lisp_Object QCwidth
, QCfont
, QCbold
, QCitalic
;
301 Lisp_Object QCreverse_video
;
302 Lisp_Object QCoverline
, QCstrike_through
, QCbox
, QCinherit
;
304 /* Symbols used for attribute values. */
306 Lisp_Object Qnormal
, Qbold
, Qultra_light
, Qextra_light
, Qlight
;
307 Lisp_Object Qsemi_light
, Qsemi_bold
, Qextra_bold
, Qultra_bold
;
308 Lisp_Object Qoblique
, Qitalic
, Qreverse_oblique
, Qreverse_italic
;
309 Lisp_Object Qultra_condensed
, Qextra_condensed
, Qcondensed
;
310 Lisp_Object Qsemi_condensed
, Qsemi_expanded
, Qexpanded
, Qextra_expanded
;
311 Lisp_Object Qultra_expanded
;
312 Lisp_Object Qreleased_button
, Qpressed_button
;
313 Lisp_Object QCstyle
, QCcolor
, QCline_width
;
314 Lisp_Object Qunspecified
;
316 char unspecified_fg
[] = "unspecified-fg", unspecified_bg
[] = "unspecified-bg";
318 /* The name of the function to call when the background of the frame
319 has changed, frame_update_face_colors. */
321 Lisp_Object Qframe_update_face_colors
;
323 /* Names of basic faces. */
325 Lisp_Object Qdefault
, Qtool_bar
, Qregion
, Qfringe
;
326 Lisp_Object Qheader_line
, Qscroll_bar
, Qcursor
, Qborder
, Qmouse
, Qmenu
;
327 Lisp_Object Qmode_line_inactive
;
328 extern Lisp_Object Qmode_line
;
330 /* The symbol `face-alias'. A symbols having that property is an
331 alias for another face. Value of the property is the name of
334 Lisp_Object Qface_alias
;
336 /* Default stipple pattern used on monochrome displays. This stipple
337 pattern is used on monochrome displays instead of shades of gray
338 for a face background color. See `set-face-stipple' for possible
339 values for this variable. */
341 Lisp_Object Vface_default_stipple
;
343 /* Alist of alternative font families. Each element is of the form
344 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
345 try FAMILY1, then FAMILY2, ... */
347 Lisp_Object Vface_alternative_font_family_alist
;
349 /* Alist of alternative font registries. Each element is of the form
350 (REGISTRY REGISTRY1 REGISTRY2...). If fonts of REGISTRY can't be
351 loaded, try REGISTRY1, then REGISTRY2, ... */
353 Lisp_Object Vface_alternative_font_registry_alist
;
355 /* Allowed scalable fonts. A value of nil means don't allow any
356 scalable fonts. A value of t means allow the use of any scalable
357 font. Otherwise, value must be a list of regular expressions. A
358 font may be scaled if its name matches a regular expression in the
361 Lisp_Object Vscalable_fonts_allowed
, Qscalable_fonts_allowed
;
363 /* List of regular expressions that matches names of fonts to ignore. */
365 Lisp_Object Vface_ignored_fonts
;
367 /* Alist of font name patterns vs the rescaling factor. */
369 Lisp_Object Vface_font_rescale_alist
;
371 /* Maximum number of fonts to consider in font_list. If not an
372 integer > 0, DEFAULT_FONT_LIST_LIMIT is used instead. */
374 Lisp_Object Vfont_list_limit
;
375 #define DEFAULT_FONT_LIST_LIMIT 100
377 /* The symbols `foreground-color' and `background-color' which can be
378 used as part of a `face' property. This is for compatibility with
381 Lisp_Object Qforeground_color
, Qbackground_color
;
383 /* The symbols `face' and `mouse-face' used as text properties. */
386 extern Lisp_Object Qmouse_face
;
388 /* Property for basic faces which other faces cannot inherit. */
390 Lisp_Object Qface_no_inherit
;
392 /* Error symbol for wrong_type_argument in load_pixmap. */
394 Lisp_Object Qbitmap_spec_p
;
396 /* Alist of global face definitions. Each element is of the form
397 (FACE . LFACE) where FACE is a symbol naming a face and LFACE
398 is a Lisp vector of face attributes. These faces are used
399 to initialize faces for new frames. */
401 Lisp_Object Vface_new_frame_defaults
;
403 /* The next ID to assign to Lisp faces. */
405 static int next_lface_id
;
407 /* A vector mapping Lisp face Id's to face names. */
409 static Lisp_Object
*lface_id_to_name
;
410 static int lface_id_to_name_size
;
412 /* TTY color-related functions (defined in tty-colors.el). */
414 Lisp_Object Qtty_color_desc
, Qtty_color_by_index
, Qtty_color_standard_values
;
416 /* The name of the function used to compute colors on TTYs. */
418 Lisp_Object Qtty_color_alist
;
420 /* An alist of defined terminal colors and their RGB values. */
422 Lisp_Object Vtty_defined_color_alist
;
424 /* Counter for calls to clear_face_cache. If this counter reaches
425 CLEAR_FONT_TABLE_COUNT, and a frame has more than
426 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
428 static int clear_font_table_count
;
429 #define CLEAR_FONT_TABLE_COUNT 100
430 #define CLEAR_FONT_TABLE_NFONTS 10
432 /* Non-zero means face attributes have been changed since the last
433 redisplay. Used in redisplay_internal. */
435 int face_change_count
;
437 /* Non-zero means don't display bold text if a face's foreground
438 and background colors are the inverse of the default colors of the
439 display. This is a kluge to suppress `bold black' foreground text
440 which is hard to read on an LCD monitor. */
442 int tty_suppress_bold_inverse_default_colors_p
;
444 /* A list of the form `((x . y))' used to avoid consing in
445 Finternal_set_lisp_face_attribute. */
447 static Lisp_Object Vparam_value_alist
;
449 /* The total number of colors currently allocated. */
452 static int ncolors_allocated
;
453 static int npixmaps_allocated
;
457 /* Non-zero means the definition of the `menu' face for new frames has
460 int menu_face_changed_default
;
463 /* Function prototypes. */
467 struct named_merge_point
;
469 static void map_tty_color
P_ ((struct frame
*, struct face
*,
470 enum lface_attribute_index
, int *));
471 static Lisp_Object resolve_face_name
P_ ((Lisp_Object
));
472 static int may_use_scalable_font_p
P_ ((const char *));
473 static void set_font_frame_param
P_ ((Lisp_Object
, Lisp_Object
));
474 static int better_font_p
P_ ((int *, struct font_name
*, struct font_name
*,
476 static int x_face_list_fonts
P_ ((struct frame
*, char *,
477 struct font_name
**, int, int));
478 static int font_scalable_p
P_ ((struct font_name
*));
479 static int get_lface_attributes
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
*, int));
480 static int load_pixmap
P_ ((struct frame
*, Lisp_Object
, unsigned *, unsigned *));
481 static unsigned char *xstrlwr
P_ ((unsigned char *));
482 static void signal_error
P_ ((char *, Lisp_Object
));
483 static struct frame
*frame_or_selected_frame
P_ ((Lisp_Object
, int));
484 static void load_face_font
P_ ((struct frame
*, struct face
*, int));
485 static void load_face_colors
P_ ((struct frame
*, struct face
*, Lisp_Object
*));
486 static void free_face_colors
P_ ((struct frame
*, struct face
*));
487 static int face_color_gray_p
P_ ((struct frame
*, char *));
488 static char *build_font_name
P_ ((struct font_name
*));
489 static void free_font_names
P_ ((struct font_name
*, int));
490 static int sorted_font_list
P_ ((struct frame
*, char *,
491 int (*cmpfn
) P_ ((const void *, const void *)),
492 struct font_name
**));
493 static int font_list_1
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
494 Lisp_Object
, struct font_name
**));
495 static int font_list
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
496 Lisp_Object
, struct font_name
**));
497 static int try_font_list
P_ ((struct frame
*, Lisp_Object
*,
498 Lisp_Object
, Lisp_Object
, struct font_name
**,
500 static int try_alternative_families
P_ ((struct frame
*f
, Lisp_Object
,
501 Lisp_Object
, struct font_name
**));
502 static int cmp_font_names
P_ ((const void *, const void *));
503 static struct face
*realize_face
P_ ((struct face_cache
*, Lisp_Object
*, int,
504 struct face
*, int));
505 static struct face
*realize_x_face
P_ ((struct face_cache
*,
506 Lisp_Object
*, int, struct face
*));
507 static struct face
*realize_tty_face
P_ ((struct face_cache
*,
508 Lisp_Object
*, int));
509 static int realize_basic_faces
P_ ((struct frame
*));
510 static int realize_default_face
P_ ((struct frame
*));
511 static void realize_named_face
P_ ((struct frame
*, Lisp_Object
, int));
512 static int lface_fully_specified_p
P_ ((Lisp_Object
*));
513 static int lface_equal_p
P_ ((Lisp_Object
*, Lisp_Object
*));
514 static unsigned hash_string_case_insensitive
P_ ((Lisp_Object
));
515 static unsigned lface_hash
P_ ((Lisp_Object
*));
516 static int lface_same_font_attributes_p
P_ ((Lisp_Object
*, Lisp_Object
*));
517 static struct face_cache
*make_face_cache
P_ ((struct frame
*));
518 static void free_realized_face
P_ ((struct frame
*, struct face
*));
519 static void clear_face_gcs
P_ ((struct face_cache
*));
520 static void free_face_cache
P_ ((struct face_cache
*));
521 static int face_numeric_weight
P_ ((Lisp_Object
));
522 static int face_numeric_slant
P_ ((Lisp_Object
));
523 static int face_numeric_swidth
P_ ((Lisp_Object
));
524 static int face_fontset
P_ ((Lisp_Object
*));
525 static char *choose_face_font
P_ ((struct frame
*, Lisp_Object
*, int, int, int*));
526 static void merge_face_vectors
P_ ((struct frame
*, Lisp_Object
*, Lisp_Object
*,
527 struct named_merge_point
*));
528 static int merge_face_ref
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
*,
529 int, struct named_merge_point
*));
530 static int set_lface_from_font_name
P_ ((struct frame
*, Lisp_Object
,
531 Lisp_Object
, int, int));
532 static Lisp_Object lface_from_face_name
P_ ((struct frame
*, Lisp_Object
, int));
533 static struct face
*make_realized_face
P_ ((Lisp_Object
*));
534 static void free_realized_faces
P_ ((struct face_cache
*));
535 static char *best_matching_font
P_ ((struct frame
*, Lisp_Object
*,
536 struct font_name
*, int, int, int *));
537 static void cache_face
P_ ((struct face_cache
*, struct face
*, unsigned));
538 static void uncache_face
P_ ((struct face_cache
*, struct face
*));
539 static int xlfd_numeric_slant
P_ ((struct font_name
*));
540 static int xlfd_numeric_weight
P_ ((struct font_name
*));
541 static int xlfd_numeric_swidth
P_ ((struct font_name
*));
542 static Lisp_Object xlfd_symbolic_slant
P_ ((struct font_name
*));
543 static Lisp_Object xlfd_symbolic_weight
P_ ((struct font_name
*));
544 static Lisp_Object xlfd_symbolic_swidth
P_ ((struct font_name
*));
545 static int xlfd_fixed_p
P_ ((struct font_name
*));
546 static int xlfd_numeric_value
P_ ((struct table_entry
*, int, struct font_name
*,
548 static Lisp_Object xlfd_symbolic_value
P_ ((struct table_entry
*, int,
549 struct font_name
*, int,
551 static struct table_entry
*xlfd_lookup_field_contents
P_ ((struct table_entry
*, int,
552 struct font_name
*, int));
554 #ifdef HAVE_WINDOW_SYSTEM
556 static int split_font_name
P_ ((struct frame
*, struct font_name
*, int));
557 static int xlfd_point_size
P_ ((struct frame
*, struct font_name
*));
558 static void sort_fonts
P_ ((struct frame
*, struct font_name
*, int,
559 int (*cmpfn
) P_ ((const void *, const void *))));
560 static GC x_create_gc
P_ ((struct frame
*, unsigned long, XGCValues
*));
561 static void x_free_gc
P_ ((struct frame
*, GC
));
562 static void clear_font_table
P_ ((struct x_display_info
*));
565 extern Lisp_Object w32_list_fonts
P_ ((struct frame
*, Lisp_Object
, int, int));
566 #endif /* WINDOWSNT */
569 static void x_update_menu_appearance
P_ ((struct frame
*));
571 extern void free_frame_menubar
P_ ((struct frame
*));
572 #endif /* USE_X_TOOLKIT */
574 #endif /* HAVE_WINDOW_SYSTEM */
577 /***********************************************************************
579 ***********************************************************************/
581 #ifdef HAVE_X_WINDOWS
583 #ifdef DEBUG_X_COLORS
585 /* The following is a poor mans infrastructure for debugging X color
586 allocation problems on displays with PseudoColor-8. Some X servers
587 like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement
588 color reference counts completely so that they don't signal an
589 error when a color is freed whose reference count is already 0.
590 Other X servers do. To help me debug this, the following code
591 implements a simple reference counting schema of its own, for a
592 single display/screen. --gerd. */
594 /* Reference counts for pixel colors. */
596 int color_count
[256];
598 /* Register color PIXEL as allocated. */
601 register_color (pixel
)
604 xassert (pixel
< 256);
605 ++color_count
[pixel
];
609 /* Register color PIXEL as deallocated. */
612 unregister_color (pixel
)
615 xassert (pixel
< 256);
616 if (color_count
[pixel
] > 0)
617 --color_count
[pixel
];
623 /* Register N colors from PIXELS as deallocated. */
626 unregister_colors (pixels
, n
)
627 unsigned long *pixels
;
631 for (i
= 0; i
< n
; ++i
)
632 unregister_color (pixels
[i
]);
636 DEFUN ("dump-colors", Fdump_colors
, Sdump_colors
, 0, 0, 0,
637 doc
: /* Dump currently allocated colors to stderr. */)
642 fputc ('\n', stderr
);
644 for (i
= n
= 0; i
< sizeof color_count
/ sizeof color_count
[0]; ++i
)
647 fprintf (stderr
, "%3d: %5d", i
, color_count
[i
]);
650 fputc ('\n', stderr
);
652 fputc ('\t', stderr
);
656 fputc ('\n', stderr
);
660 #endif /* DEBUG_X_COLORS */
663 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
664 color values. Interrupt input must be blocked when this function
668 x_free_colors (f
, pixels
, npixels
)
670 unsigned long *pixels
;
673 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
675 /* If display has an immutable color map, freeing colors is not
676 necessary and some servers don't allow it. So don't do it. */
677 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
679 #ifdef DEBUG_X_COLORS
680 unregister_colors (pixels
, npixels
);
682 XFreeColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
688 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
689 color values. Interrupt input must be blocked when this function
693 x_free_dpy_colors (dpy
, screen
, cmap
, pixels
, npixels
)
697 unsigned long *pixels
;
700 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
701 int class = dpyinfo
->visual
->class;
703 /* If display has an immutable color map, freeing colors is not
704 necessary and some servers don't allow it. So don't do it. */
705 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
707 #ifdef DEBUG_X_COLORS
708 unregister_colors (pixels
, npixels
);
710 XFreeColors (dpy
, cmap
, pixels
, npixels
, 0);
715 /* Create and return a GC for use on frame F. GC values and mask
716 are given by XGCV and MASK. */
719 x_create_gc (f
, mask
, xgcv
)
726 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
733 /* Free GC which was used on frame F. */
741 xassert (--ngcs
>= 0);
742 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
746 #endif /* HAVE_X_WINDOWS */
749 /* W32 emulation of GCs */
752 x_create_gc (f
, mask
, xgcv
)
759 gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, xgcv
);
766 /* Free GC which was used on frame F. */
774 xassert (--ngcs
>= 0);
779 #endif /* WINDOWSNT */
782 /* Mac OS emulation of GCs */
784 extern XGCValues
*XCreateGC (void *, Window
, unsigned long, XGCValues
*);
787 x_create_gc (f
, mask
, xgcv
)
793 gc
= XCreateGC (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), mask
, xgcv
);
802 XFreeGC (FRAME_MAC_DISPLAY (f
), gc
);
807 /* Like stricmp. Used to compare parts of font names which are in
812 const unsigned char *s1
, *s2
;
816 unsigned char c1
= tolower (*s1
);
817 unsigned char c2
= tolower (*s2
);
819 return c1
< c2
? -1 : 1;
824 return *s2
== 0 ? 0 : -1;
829 /* Like strlwr, which might not always be available. */
831 static unsigned char *
835 unsigned char *p
= s
;
844 /* Signal `error' with message S, and additional argument ARG. */
847 signal_error (s
, arg
)
851 Fsignal (Qerror
, Fcons (build_string (s
), Fcons (arg
, Qnil
)));
855 /* If FRAME is nil, return a pointer to the selected frame.
856 Otherwise, check that FRAME is a live frame, and return a pointer
857 to it. NPARAM is the parameter number of FRAME, for
858 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
859 Lisp function definitions. */
861 static INLINE
struct frame
*
862 frame_or_selected_frame (frame
, nparam
)
867 frame
= selected_frame
;
869 CHECK_LIVE_FRAME (frame
);
870 return XFRAME (frame
);
874 /***********************************************************************
876 ***********************************************************************/
878 /* Initialize face cache and basic faces for frame F. */
884 /* Make a face cache, if F doesn't have one. */
885 if (FRAME_FACE_CACHE (f
) == NULL
)
886 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
888 #ifdef HAVE_WINDOW_SYSTEM
889 /* Make the image cache. */
890 if (FRAME_WINDOW_P (f
))
892 if (FRAME_X_IMAGE_CACHE (f
) == NULL
)
893 FRAME_X_IMAGE_CACHE (f
) = make_image_cache ();
894 ++FRAME_X_IMAGE_CACHE (f
)->refcount
;
896 #endif /* HAVE_WINDOW_SYSTEM */
898 /* Realize basic faces. Must have enough information in frame
899 parameters to realize basic faces at this point. */
900 #ifdef HAVE_X_WINDOWS
901 if (!FRAME_X_P (f
) || FRAME_X_WINDOW (f
))
904 if (!FRAME_WINDOW_P (f
) || FRAME_W32_WINDOW (f
))
907 if (!FRAME_MAC_P (f
) || FRAME_MAC_WINDOW (f
))
909 if (!realize_basic_faces (f
))
914 /* Free face cache of frame F. Called from Fdelete_frame. */
920 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
924 free_face_cache (face_cache
);
925 FRAME_FACE_CACHE (f
) = NULL
;
928 #ifdef HAVE_WINDOW_SYSTEM
929 if (FRAME_WINDOW_P (f
))
931 struct image_cache
*image_cache
= FRAME_X_IMAGE_CACHE (f
);
934 --image_cache
->refcount
;
935 if (image_cache
->refcount
== 0)
936 free_image_cache (f
);
939 #endif /* HAVE_WINDOW_SYSTEM */
943 /* Clear face caches, and recompute basic faces for frame F. Call
944 this after changing frame parameters on which those faces depend,
945 or when realized faces have been freed due to changing attributes
949 recompute_basic_faces (f
)
952 if (FRAME_FACE_CACHE (f
))
954 clear_face_cache (0);
955 if (!realize_basic_faces (f
))
961 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
962 try to free unused fonts, too. */
965 clear_face_cache (clear_fonts_p
)
968 #ifdef HAVE_WINDOW_SYSTEM
969 Lisp_Object tail
, frame
;
973 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
975 struct x_display_info
*dpyinfo
;
977 /* Fonts are common for frames on one display, i.e. on
979 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
980 if (dpyinfo
->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
981 clear_font_table (dpyinfo
);
983 /* From time to time see if we can unload some fonts. This also
984 frees all realized faces on all frames. Fonts needed by
985 faces will be loaded again when faces are realized again. */
986 clear_font_table_count
= 0;
988 FOR_EACH_FRAME (tail
, frame
)
990 struct frame
*f
= XFRAME (frame
);
991 if (FRAME_WINDOW_P (f
)
992 && FRAME_X_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
993 free_all_realized_faces (frame
);
998 /* Clear GCs of realized faces. */
999 FOR_EACH_FRAME (tail
, frame
)
1002 if (FRAME_WINDOW_P (f
))
1004 clear_face_gcs (FRAME_FACE_CACHE (f
));
1005 clear_image_cache (f
, 0);
1009 #endif /* HAVE_WINDOW_SYSTEM */
1013 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
1014 doc
: /* Clear face caches on all frames.
1015 Optional THOROUGHLY non-nil means try to free unused fonts, too. */)
1017 Lisp_Object thoroughly
;
1019 clear_face_cache (!NILP (thoroughly
));
1020 ++face_change_count
;
1021 ++windows_or_buffers_changed
;
1027 #ifdef HAVE_WINDOW_SYSTEM
1030 /* Remove fonts from the font table of DPYINFO except for the default
1031 ASCII fonts of frames on that display. Called from clear_face_cache
1032 from time to time. */
1035 clear_font_table (dpyinfo
)
1036 struct x_display_info
*dpyinfo
;
1040 /* Free those fonts that are not used by frames on DPYINFO. */
1041 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
1043 struct font_info
*font_info
= dpyinfo
->font_table
+ i
;
1044 Lisp_Object tail
, frame
;
1046 /* Check if slot is already free. */
1047 if (font_info
->name
== NULL
)
1050 /* Don't free a default font of some frame. */
1051 FOR_EACH_FRAME (tail
, frame
)
1053 struct frame
*f
= XFRAME (frame
);
1054 if (FRAME_WINDOW_P (f
)
1055 && font_info
->font
== FRAME_FONT (f
))
1063 if (font_info
->full_name
!= font_info
->name
)
1064 xfree (font_info
->full_name
);
1065 xfree (font_info
->name
);
1067 /* Free the font. */
1069 #ifdef HAVE_X_WINDOWS
1070 XFreeFont (dpyinfo
->display
, font_info
->font
);
1073 w32_unload_font (dpyinfo
, font_info
->font
);
1077 /* Mark font table slot free. */
1078 font_info
->font
= NULL
;
1079 font_info
->name
= font_info
->full_name
= NULL
;
1083 #endif /* HAVE_WINDOW_SYSTEM */
1087 /***********************************************************************
1089 ***********************************************************************/
1091 #ifdef HAVE_WINDOW_SYSTEM
1093 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
1094 doc
: /* Value is non-nil if OBJECT is a valid bitmap specification.
1095 A bitmap specification is either a string, a file name, or a list
1096 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
1097 HEIGHT is its height, and DATA is a string containing the bits of
1098 the pixmap. Bits are stored row by row, each row occupies
1099 \(WIDTH + 7)/8 bytes. */)
1105 if (STRINGP (object
))
1106 /* If OBJECT is a string, it's a file name. */
1108 else if (CONSP (object
))
1110 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
1111 HEIGHT must be integers > 0, and DATA must be string large
1112 enough to hold a bitmap of the specified size. */
1113 Lisp_Object width
, height
, data
;
1115 height
= width
= data
= Qnil
;
1119 width
= XCAR (object
);
1120 object
= XCDR (object
);
1123 height
= XCAR (object
);
1124 object
= XCDR (object
);
1126 data
= XCAR (object
);
1130 if (NATNUMP (width
) && NATNUMP (height
) && STRINGP (data
))
1132 int bytes_per_row
= ((XFASTINT (width
) + BITS_PER_CHAR
- 1)
1134 if (SBYTES (data
) >= bytes_per_row
* XINT (height
))
1139 return pixmap_p
? Qt
: Qnil
;
1143 /* Load a bitmap according to NAME (which is either a file name or a
1144 pixmap spec) for use on frame F. Value is the bitmap_id (see
1145 xfns.c). If NAME is nil, return with a bitmap id of zero. If
1146 bitmap cannot be loaded, display a message saying so, and return
1147 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
1148 if these pointers are not null. */
1151 load_pixmap (f
, name
, w_ptr
, h_ptr
)
1154 unsigned int *w_ptr
, *h_ptr
;
1162 tem
= Fbitmap_spec_p (name
);
1164 wrong_type_argument (Qbitmap_spec_p
, name
);
1169 /* Decode a bitmap spec into a bitmap. */
1174 w
= XINT (Fcar (name
));
1175 h
= XINT (Fcar (Fcdr (name
)));
1176 bits
= Fcar (Fcdr (Fcdr (name
)));
1178 bitmap_id
= x_create_bitmap_from_data (f
, SDATA (bits
),
1183 /* It must be a string -- a file name. */
1184 bitmap_id
= x_create_bitmap_from_file (f
, name
);
1190 add_to_log ("Invalid or undefined bitmap %s", name
, Qnil
);
1201 ++npixmaps_allocated
;
1204 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
1207 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
1213 #endif /* HAVE_WINDOW_SYSTEM */
1217 /***********************************************************************
1219 ***********************************************************************/
1221 #ifdef HAVE_WINDOW_SYSTEM
1223 /* Load font of face FACE which is used on frame F to display
1224 character C. The name of the font to load is determined by lface
1225 and fontset of FACE. */
1228 load_face_font (f
, face
, c
)
1233 struct font_info
*font_info
= NULL
;
1235 int needs_overstrike
;
1237 face
->font_info_id
= -1;
1240 font_name
= choose_face_font (f
, face
->lface
, face
->fontset
, c
,
1246 font_info
= FS_LOAD_FACE_FONT (f
, c
, font_name
, face
);
1251 face
->font_info_id
= font_info
->font_idx
;
1252 face
->font
= font_info
->font
;
1253 face
->font_name
= font_info
->full_name
;
1254 face
->overstrike
= needs_overstrike
;
1257 x_free_gc (f
, face
->gc
);
1262 add_to_log ("Unable to load font %s",
1263 build_string (font_name
), Qnil
);
1267 #endif /* HAVE_WINDOW_SYSTEM */
1271 /***********************************************************************
1273 ***********************************************************************/
1275 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
1276 RGB_LIST should contain (at least) 3 lisp integers.
1277 Return 0 if there's a problem with RGB_LIST, otherwise return 1. */
1280 parse_rgb_list (rgb_list
, color
)
1281 Lisp_Object rgb_list
;
1284 #define PARSE_RGB_LIST_FIELD(field) \
1285 if (CONSP (rgb_list) && INTEGERP (XCAR (rgb_list))) \
1287 color->field = XINT (XCAR (rgb_list)); \
1288 rgb_list = XCDR (rgb_list); \
1293 PARSE_RGB_LIST_FIELD (red
);
1294 PARSE_RGB_LIST_FIELD (green
);
1295 PARSE_RGB_LIST_FIELD (blue
);
1301 /* Lookup on frame F the color described by the lisp string COLOR.
1302 The resulting tty color is returned in TTY_COLOR; if STD_COLOR is
1303 non-zero, then the `standard' definition of the same color is
1307 tty_lookup_color (f
, color
, tty_color
, std_color
)
1310 XColor
*tty_color
, *std_color
;
1312 Lisp_Object frame
, color_desc
;
1314 if (!STRINGP (color
) || NILP (Ffboundp (Qtty_color_desc
)))
1317 XSETFRAME (frame
, f
);
1319 color_desc
= call2 (Qtty_color_desc
, color
, frame
);
1320 if (CONSP (color_desc
) && CONSP (XCDR (color_desc
)))
1324 if (! INTEGERP (XCAR (XCDR (color_desc
))))
1327 tty_color
->pixel
= XINT (XCAR (XCDR (color_desc
)));
1329 rgb
= XCDR (XCDR (color_desc
));
1330 if (! parse_rgb_list (rgb
, tty_color
))
1333 /* Should we fill in STD_COLOR too? */
1336 /* Default STD_COLOR to the same as TTY_COLOR. */
1337 *std_color
= *tty_color
;
1339 /* Do a quick check to see if the returned descriptor is
1340 actually _exactly_ equal to COLOR, otherwise we have to
1341 lookup STD_COLOR separately. If it's impossible to lookup
1342 a standard color, we just give up and use TTY_COLOR. */
1343 if ((!STRINGP (XCAR (color_desc
))
1344 || NILP (Fstring_equal (color
, XCAR (color_desc
))))
1345 && !NILP (Ffboundp (Qtty_color_standard_values
)))
1347 /* Look up STD_COLOR separately. */
1348 rgb
= call1 (Qtty_color_standard_values
, color
);
1349 if (! parse_rgb_list (rgb
, std_color
))
1356 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
1357 /* We were called early during startup, and the colors are not
1358 yet set up in tty-defined-color-alist. Don't return a failure
1359 indication, since this produces the annoying "Unable to
1360 load color" messages in the *Messages* buffer. */
1363 /* tty-color-desc seems to have returned a bad value. */
1367 /* A version of defined_color for non-X frames. */
1370 tty_defined_color (f
, color_name
, color_def
, alloc
)
1379 color_def
->pixel
= FACE_TTY_DEFAULT_COLOR
;
1381 color_def
->blue
= 0;
1382 color_def
->green
= 0;
1385 status
= tty_lookup_color (f
, build_string (color_name
), color_def
, 0);
1387 if (color_def
->pixel
== FACE_TTY_DEFAULT_COLOR
&& *color_name
)
1389 if (strcmp (color_name
, "unspecified-fg") == 0)
1390 color_def
->pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
1391 else if (strcmp (color_name
, "unspecified-bg") == 0)
1392 color_def
->pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
1395 if (color_def
->pixel
!= FACE_TTY_DEFAULT_COLOR
)
1402 /* Decide if color named COLOR_NAME is valid for the display
1403 associated with the frame F; if so, return the rgb values in
1404 COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell.
1406 This does the right thing for any type of frame. */
1409 defined_color (f
, color_name
, color_def
, alloc
)
1415 if (!FRAME_WINDOW_P (f
))
1416 return tty_defined_color (f
, color_name
, color_def
, alloc
);
1417 #ifdef HAVE_X_WINDOWS
1418 else if (FRAME_X_P (f
))
1419 return x_defined_color (f
, color_name
, color_def
, alloc
);
1422 else if (FRAME_W32_P (f
))
1423 return w32_defined_color (f
, color_name
, color_def
, alloc
);
1426 else if (FRAME_MAC_P (f
))
1427 return mac_defined_color (f
, color_name
, color_def
, alloc
);
1434 /* Given the index IDX of a tty color on frame F, return its name, a
1438 tty_color_name (f
, idx
)
1442 if (idx
>= 0 && !NILP (Ffboundp (Qtty_color_by_index
)))
1445 Lisp_Object coldesc
;
1447 XSETFRAME (frame
, f
);
1448 coldesc
= call2 (Qtty_color_by_index
, make_number (idx
), frame
);
1450 if (!NILP (coldesc
))
1451 return XCAR (coldesc
);
1454 /* We can have an MSDOG frame under -nw for a short window of
1455 opportunity before internal_terminal_init is called. DTRT. */
1456 if (FRAME_MSDOS_P (f
) && !inhibit_window_system
)
1457 return msdos_stdcolor_name (idx
);
1460 if (idx
== FACE_TTY_DEFAULT_FG_COLOR
)
1461 return build_string (unspecified_fg
);
1462 if (idx
== FACE_TTY_DEFAULT_BG_COLOR
)
1463 return build_string (unspecified_bg
);
1466 return vga_stdcolor_name (idx
);
1469 return Qunspecified
;
1473 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1474 black) on frame F. The algorithm is taken from 20.2 faces.el. */
1477 face_color_gray_p (f
, color_name
)
1484 if (defined_color (f
, color_name
, &color
, 0))
1485 gray_p
= ((abs (color
.red
- color
.green
)
1486 < max (color
.red
, color
.green
) / 20)
1487 && (abs (color
.green
- color
.blue
)
1488 < max (color
.green
, color
.blue
) / 20)
1489 && (abs (color
.blue
- color
.red
)
1490 < max (color
.blue
, color
.red
) / 20));
1498 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1499 BACKGROUND_P non-zero means the color will be used as background
1503 face_color_supported_p (f
, color_name
, background_p
)
1511 XSETFRAME (frame
, f
);
1513 #ifdef HAVE_X_WINDOWS
1515 ? (!NILP (Fxw_display_color_p (frame
))
1516 || xstricmp (color_name
, "black") == 0
1517 || xstricmp (color_name
, "white") == 0
1519 && face_color_gray_p (f
, color_name
))
1520 || (!NILP (Fx_display_grayscale_p (frame
))
1521 && face_color_gray_p (f
, color_name
)))
1524 tty_defined_color (f
, color_name
, ¬_used
, 0);
1528 DEFUN ("color-gray-p", Fcolor_gray_p
, Scolor_gray_p
, 1, 2, 0,
1529 doc
: /* Return non-nil if COLOR is a shade of gray (or white or black).
1530 FRAME specifies the frame and thus the display for interpreting COLOR.
1531 If FRAME is nil or omitted, use the selected frame. */)
1533 Lisp_Object color
, frame
;
1537 CHECK_STRING (color
);
1539 frame
= selected_frame
;
1541 CHECK_FRAME (frame
);
1543 return face_color_gray_p (f
, SDATA (color
)) ? Qt
: Qnil
;
1547 DEFUN ("color-supported-p", Fcolor_supported_p
,
1548 Scolor_supported_p
, 1, 3, 0,
1549 doc
: /* Return non-nil if COLOR can be displayed on FRAME.
1550 BACKGROUND-P non-nil means COLOR is used as a background.
1551 Otherwise, this function tells whether it can be used as a foreground.
1552 If FRAME is nil or omitted, use the selected frame.
1553 COLOR must be a valid color name. */)
1554 (color
, frame
, background_p
)
1555 Lisp_Object frame
, color
, background_p
;
1559 CHECK_STRING (color
);
1561 frame
= selected_frame
;
1563 CHECK_FRAME (frame
);
1565 if (face_color_supported_p (f
, SDATA (color
), !NILP (background_p
)))
1571 /* Load color with name NAME for use by face FACE on frame F.
1572 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1573 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1574 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1575 pixel color. If color cannot be loaded, display a message, and
1576 return the foreground, background or underline color of F, but
1577 record that fact in flags of the face so that we don't try to free
1581 load_color (f
, face
, name
, target_index
)
1585 enum lface_attribute_index target_index
;
1589 xassert (STRINGP (name
));
1590 xassert (target_index
== LFACE_FOREGROUND_INDEX
1591 || target_index
== LFACE_BACKGROUND_INDEX
1592 || target_index
== LFACE_UNDERLINE_INDEX
1593 || target_index
== LFACE_OVERLINE_INDEX
1594 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1595 || target_index
== LFACE_BOX_INDEX
);
1597 /* if the color map is full, defined_color will return a best match
1598 to the values in an existing cell. */
1599 if (!defined_color (f
, SDATA (name
), &color
, 1))
1601 add_to_log ("Unable to load color \"%s\"", name
, Qnil
);
1603 switch (target_index
)
1605 case LFACE_FOREGROUND_INDEX
:
1606 face
->foreground_defaulted_p
= 1;
1607 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1610 case LFACE_BACKGROUND_INDEX
:
1611 face
->background_defaulted_p
= 1;
1612 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1615 case LFACE_UNDERLINE_INDEX
:
1616 face
->underline_defaulted_p
= 1;
1617 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1620 case LFACE_OVERLINE_INDEX
:
1621 face
->overline_color_defaulted_p
= 1;
1622 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1625 case LFACE_STRIKE_THROUGH_INDEX
:
1626 face
->strike_through_color_defaulted_p
= 1;
1627 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1630 case LFACE_BOX_INDEX
:
1631 face
->box_color_defaulted_p
= 1;
1632 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1641 ++ncolors_allocated
;
1648 #ifdef HAVE_WINDOW_SYSTEM
1650 /* Load colors for face FACE which is used on frame F. Colors are
1651 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1652 of ATTRS. If the background color specified is not supported on F,
1653 try to emulate gray colors with a stipple from Vface_default_stipple. */
1656 load_face_colors (f
, face
, attrs
)
1663 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1664 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1666 /* Swap colors if face is inverse-video. */
1667 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1675 /* Check for support for foreground, not for background because
1676 face_color_supported_p is smart enough to know that grays are
1677 "supported" as background because we are supposed to use stipple
1679 if (!face_color_supported_p (f
, SDATA (bg
), 0)
1680 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1682 x_destroy_bitmap (f
, face
->stipple
);
1683 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1684 &face
->pixmap_w
, &face
->pixmap_h
);
1687 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1688 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1692 /* Free color PIXEL on frame F. */
1695 unload_color (f
, pixel
)
1697 unsigned long pixel
;
1699 #ifdef HAVE_X_WINDOWS
1703 x_free_colors (f
, &pixel
, 1);
1710 /* Free colors allocated for FACE. */
1713 free_face_colors (f
, face
)
1717 #ifdef HAVE_X_WINDOWS
1718 if (face
->colors_copied_bitwise_p
)
1723 if (!face
->foreground_defaulted_p
)
1725 x_free_colors (f
, &face
->foreground
, 1);
1726 IF_DEBUG (--ncolors_allocated
);
1729 if (!face
->background_defaulted_p
)
1731 x_free_colors (f
, &face
->background
, 1);
1732 IF_DEBUG (--ncolors_allocated
);
1735 if (face
->underline_p
1736 && !face
->underline_defaulted_p
)
1738 x_free_colors (f
, &face
->underline_color
, 1);
1739 IF_DEBUG (--ncolors_allocated
);
1742 if (face
->overline_p
1743 && !face
->overline_color_defaulted_p
)
1745 x_free_colors (f
, &face
->overline_color
, 1);
1746 IF_DEBUG (--ncolors_allocated
);
1749 if (face
->strike_through_p
1750 && !face
->strike_through_color_defaulted_p
)
1752 x_free_colors (f
, &face
->strike_through_color
, 1);
1753 IF_DEBUG (--ncolors_allocated
);
1756 if (face
->box
!= FACE_NO_BOX
1757 && !face
->box_color_defaulted_p
)
1759 x_free_colors (f
, &face
->box_color
, 1);
1760 IF_DEBUG (--ncolors_allocated
);
1764 #endif /* HAVE_X_WINDOWS */
1767 #endif /* HAVE_WINDOW_SYSTEM */
1771 /***********************************************************************
1773 ***********************************************************************/
1775 /* An enumerator for each field of an XLFD font name. */
1796 /* An enumerator for each possible slant value of a font. Taken from
1797 the XLFD specification. */
1805 XLFD_SLANT_REVERSE_ITALIC
,
1806 XLFD_SLANT_REVERSE_OBLIQUE
,
1810 /* Relative font weight according to XLFD documentation. */
1814 XLFD_WEIGHT_UNKNOWN
,
1815 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1816 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1817 XLFD_WEIGHT_LIGHT
, /* 30 */
1818 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1819 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1820 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1821 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1822 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1823 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1826 /* Relative proportionate width. */
1830 XLFD_SWIDTH_UNKNOWN
,
1831 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1832 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1833 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1834 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1835 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1836 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1837 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1838 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1839 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1842 /* Structure used for tables mapping XLFD weight, slant, and width
1843 names to numeric and symbolic values. */
1849 Lisp_Object
*symbol
;
1852 /* Table of XLFD slant names and their numeric and symbolic
1853 representations. This table must be sorted by slant names in
1856 static struct table_entry slant_table
[] =
1858 {"i", XLFD_SLANT_ITALIC
, &Qitalic
},
1859 {"o", XLFD_SLANT_OBLIQUE
, &Qoblique
},
1860 {"ot", XLFD_SLANT_OTHER
, &Qitalic
},
1861 {"r", XLFD_SLANT_ROMAN
, &Qnormal
},
1862 {"ri", XLFD_SLANT_REVERSE_ITALIC
, &Qreverse_italic
},
1863 {"ro", XLFD_SLANT_REVERSE_OBLIQUE
, &Qreverse_oblique
}
1866 /* Table of XLFD weight names. This table must be sorted by weight
1867 names in ascending order. */
1869 static struct table_entry weight_table
[] =
1871 {"black", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
},
1872 {"bold", XLFD_WEIGHT_BOLD
, &Qbold
},
1873 {"book", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1874 {"demi", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1875 {"demibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1876 {"extralight", XLFD_WEIGHT_EXTRA_LIGHT
, &Qextra_light
},
1877 {"extrabold", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1878 {"heavy", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1879 {"light", XLFD_WEIGHT_LIGHT
, &Qlight
},
1880 {"medium", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1881 {"normal", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1882 {"regular", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1883 {"semibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1884 {"semilight", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1885 {"ultralight", XLFD_WEIGHT_ULTRA_LIGHT
, &Qultra_light
},
1886 {"ultrabold", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
}
1889 /* Table of XLFD width names. This table must be sorted by width
1890 names in ascending order. */
1892 static struct table_entry swidth_table
[] =
1894 {"compressed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1895 {"condensed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1896 {"demiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1897 {"expanded", XLFD_SWIDTH_EXPANDED
, &Qexpanded
},
1898 {"extracondensed", XLFD_SWIDTH_EXTRA_CONDENSED
, &Qextra_condensed
},
1899 {"extraexpanded", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
},
1900 {"medium", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1901 {"narrow", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1902 {"normal", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1903 {"regular", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1904 {"semicondensed", XLFD_SWIDTH_SEMI_CONDENSED
, &Qsemi_condensed
},
1905 {"semiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1906 {"ultracondensed", XLFD_SWIDTH_ULTRA_CONDENSED
, &Qultra_condensed
},
1907 {"ultraexpanded", XLFD_SWIDTH_ULTRA_EXPANDED
, &Qultra_expanded
},
1908 {"wide", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
}
1911 /* Structure used to hold the result of splitting font names in XLFD
1912 format into their fields. */
1916 /* The original name which is modified destructively by
1917 split_font_name. The pointer is kept here to be able to free it
1918 if it was allocated from the heap. */
1921 /* Font name fields. Each vector element points into `name' above.
1922 Fields are NUL-terminated. */
1923 char *fields
[XLFD_LAST
];
1925 /* Numeric values for those fields that interest us. See
1926 split_font_name for which these are. */
1927 int numeric
[XLFD_LAST
];
1929 /* If the original name matches one of Vface_font_rescale_alist,
1930 the value is the corresponding rescale ratio. Otherwise, the
1932 double rescale_ratio
;
1934 /* Lower value mean higher priority. */
1935 int registry_priority
;
1938 /* The frame in effect when sorting font names. Set temporarily in
1939 sort_fonts so that it is available in font comparison functions. */
1941 static struct frame
*font_frame
;
1943 /* Order by which font selection chooses fonts. The default values
1944 mean `first, find a best match for the font width, then for the
1945 font height, then for weight, then for slant.' This variable can be
1946 set via set-face-font-sort-order. */
1949 static int font_sort_order
[4] = {
1950 XLFD_SWIDTH
, XLFD_POINT_SIZE
, XLFD_WEIGHT
, XLFD_SLANT
1953 static int font_sort_order
[4];
1956 /* Look up FONT.fields[FIELD_INDEX] in TABLE which has DIM entries.
1957 TABLE must be sorted by TABLE[i]->name in ascending order. Value
1958 is a pointer to the matching table entry or null if no table entry
1961 static struct table_entry
*
1962 xlfd_lookup_field_contents (table
, dim
, font
, field_index
)
1963 struct table_entry
*table
;
1965 struct font_name
*font
;
1968 /* Function split_font_name converts fields to lower-case, so there
1969 is no need to use xstrlwr or xstricmp here. */
1970 char *s
= font
->fields
[field_index
];
1971 int low
, mid
, high
, cmp
;
1978 mid
= (low
+ high
) / 2;
1979 cmp
= strcmp (table
[mid
].name
, s
);
1993 /* Return a numeric representation for font name field
1994 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
1995 has DIM entries. Value is the numeric value found or DFLT if no
1996 table entry matches. This function is used to translate weight,
1997 slant, and swidth names of XLFD font names to numeric values. */
2000 xlfd_numeric_value (table
, dim
, font
, field_index
, dflt
)
2001 struct table_entry
*table
;
2003 struct font_name
*font
;
2007 struct table_entry
*p
;
2008 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
2009 return p
? p
->numeric
: dflt
;
2013 /* Return a symbolic representation for font name field
2014 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
2015 has DIM entries. Value is the symbolic value found or DFLT if no
2016 table entry matches. This function is used to translate weight,
2017 slant, and swidth names of XLFD font names to symbols. */
2019 static INLINE Lisp_Object
2020 xlfd_symbolic_value (table
, dim
, font
, field_index
, dflt
)
2021 struct table_entry
*table
;
2023 struct font_name
*font
;
2027 struct table_entry
*p
;
2028 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
2029 return p
? *p
->symbol
: dflt
;
2033 /* Return a numeric value for the slant of the font given by FONT. */
2036 xlfd_numeric_slant (font
)
2037 struct font_name
*font
;
2039 return xlfd_numeric_value (slant_table
, DIM (slant_table
),
2040 font
, XLFD_SLANT
, XLFD_SLANT_ROMAN
);
2044 /* Return a symbol representing the weight of the font given by FONT. */
2046 static INLINE Lisp_Object
2047 xlfd_symbolic_slant (font
)
2048 struct font_name
*font
;
2050 return xlfd_symbolic_value (slant_table
, DIM (slant_table
),
2051 font
, XLFD_SLANT
, Qnormal
);
2055 /* Return a numeric value for the weight of the font given by FONT. */
2058 xlfd_numeric_weight (font
)
2059 struct font_name
*font
;
2061 return xlfd_numeric_value (weight_table
, DIM (weight_table
),
2062 font
, XLFD_WEIGHT
, XLFD_WEIGHT_MEDIUM
);
2066 /* Return a symbol representing the slant of the font given by FONT. */
2068 static INLINE Lisp_Object
2069 xlfd_symbolic_weight (font
)
2070 struct font_name
*font
;
2072 return xlfd_symbolic_value (weight_table
, DIM (weight_table
),
2073 font
, XLFD_WEIGHT
, Qnormal
);
2077 /* Return a numeric value for the swidth of the font whose XLFD font
2078 name fields are found in FONT. */
2081 xlfd_numeric_swidth (font
)
2082 struct font_name
*font
;
2084 return xlfd_numeric_value (swidth_table
, DIM (swidth_table
),
2085 font
, XLFD_SWIDTH
, XLFD_SWIDTH_MEDIUM
);
2089 /* Return a symbolic value for the swidth of FONT. */
2091 static INLINE Lisp_Object
2092 xlfd_symbolic_swidth (font
)
2093 struct font_name
*font
;
2095 return xlfd_symbolic_value (swidth_table
, DIM (swidth_table
),
2096 font
, XLFD_SWIDTH
, Qnormal
);
2100 /* Look up the entry of SYMBOL in the vector TABLE which has DIM
2101 entries. Value is a pointer to the matching table entry or null if
2102 no element of TABLE contains SYMBOL. */
2104 static struct table_entry
*
2105 face_value (table
, dim
, symbol
)
2106 struct table_entry
*table
;
2112 xassert (SYMBOLP (symbol
));
2114 for (i
= 0; i
< dim
; ++i
)
2115 if (EQ (*table
[i
].symbol
, symbol
))
2118 return i
< dim
? table
+ i
: NULL
;
2122 /* Return a numeric value for SYMBOL in the vector TABLE which has DIM
2123 entries. Value is -1 if SYMBOL is not found in TABLE. */
2126 face_numeric_value (table
, dim
, symbol
)
2127 struct table_entry
*table
;
2131 struct table_entry
*p
= face_value (table
, dim
, symbol
);
2132 return p
? p
->numeric
: -1;
2136 /* Return a numeric value representing the weight specified by Lisp
2137 symbol WEIGHT. Value is one of the enumerators of enum
2141 face_numeric_weight (weight
)
2144 return face_numeric_value (weight_table
, DIM (weight_table
), weight
);
2148 /* Return a numeric value representing the slant specified by Lisp
2149 symbol SLANT. Value is one of the enumerators of enum xlfd_slant. */
2152 face_numeric_slant (slant
)
2155 return face_numeric_value (slant_table
, DIM (slant_table
), slant
);
2159 /* Return a numeric value representing the swidth specified by Lisp
2160 symbol WIDTH. Value is one of the enumerators of enum xlfd_swidth. */
2163 face_numeric_swidth (width
)
2166 return face_numeric_value (swidth_table
, DIM (swidth_table
), width
);
2170 #ifdef HAVE_WINDOW_SYSTEM
2172 /* Return non-zero if FONT is the name of a fixed-pitch font. */
2176 struct font_name
*font
;
2178 /* Function split_font_name converts fields to lower-case, so there
2179 is no need to use tolower here. */
2180 return *font
->fields
[XLFD_SPACING
] != 'p';
2184 /* Return the point size of FONT on frame F, measured in 1/10 pt.
2186 The actual height of the font when displayed on F depends on the
2187 resolution of both the font and frame. For example, a 10pt font
2188 designed for a 100dpi display will display larger than 10pt on a
2189 75dpi display. (It's not unusual to use fonts not designed for the
2190 display one is using. For example, some intlfonts are available in
2191 72dpi versions, only.)
2193 Value is the real point size of FONT on frame F, or 0 if it cannot
2197 xlfd_point_size (f
, font
)
2199 struct font_name
*font
;
2201 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
2202 char *pixel_field
= font
->fields
[XLFD_PIXEL_SIZE
];
2206 if (*pixel_field
== '[')
2208 /* The pixel size field is `[A B C D]' which specifies
2209 a transformation matrix.
2215 by which all glyphs of the font are transformed. The spec
2216 says that s scalar value N for the pixel size is equivalent
2217 to A = N * resx/resy, B = C = 0, D = N. */
2218 char *start
= pixel_field
+ 1, *end
;
2222 for (i
= 0; i
< 4; ++i
)
2224 matrix
[i
] = strtod (start
, &end
);
2231 pixel
= atoi (pixel_field
);
2236 real_pt
= PT_PER_INCH
* 10.0 * pixel
/ resy
+ 0.5;
2242 /* Return point size of PIXEL dots while considering Y-resultion (DPI)
2243 of frame F. This function is used to guess a point size of font
2244 when only the pixel height of the font is available. */
2247 pixel_point_size (f
, pixel
)
2251 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
2255 /* As one inch is PT_PER_INCH points, PT_PER_INCH/RESY gives the
2256 point size of one dot. */
2257 real_pt
= pixel
* PT_PER_INCH
/ resy
;
2258 int_pt
= real_pt
+ 0.5;
2264 /* Return a rescaling ratio of a font of NAME. */
2267 font_rescale_ratio (name
)
2270 Lisp_Object tail
, elt
;
2272 for (tail
= Vface_font_rescale_alist
; CONSP (tail
); tail
= XCDR (tail
))
2275 if (STRINGP (XCAR (elt
)) && FLOATP (XCDR (elt
))
2276 && fast_c_string_match_ignore_case (XCAR (elt
), name
) >= 0)
2277 return XFLOAT_DATA (XCDR (elt
));
2283 /* Split XLFD font name FONT->name destructively into NUL-terminated,
2284 lower-case fields in FONT->fields. NUMERIC_P non-zero means
2285 compute numeric values for fields XLFD_POINT_SIZE, XLFD_SWIDTH,
2286 XLFD_RESY, XLFD_SLANT, and XLFD_WEIGHT in FONT->numeric. Value is
2287 zero if the font name doesn't have the format we expect. The
2288 expected format is a font name that starts with a `-' and has
2289 XLFD_LAST fields separated by `-'. */
2292 split_font_name (f
, font
, numeric_p
)
2294 struct font_name
*font
;
2299 double rescale_ratio
;
2302 /* This must be done before splitting the font name. */
2303 rescale_ratio
= font_rescale_ratio (font
->name
);
2305 if (*font
->name
== '-')
2307 char *p
= xstrlwr (font
->name
) + 1;
2309 while (i
< XLFD_LAST
)
2311 font
->fields
[i
] = p
;
2314 /* Pixel and point size may be of the form `[....]'. For
2315 BNF, see XLFD spec, chapter 4. Negative values are
2316 indicated by tilde characters which we replace with
2317 `-' characters, here. */
2319 && (i
- 1 == XLFD_PIXEL_SIZE
2320 || i
- 1 == XLFD_POINT_SIZE
))
2325 for (++p
; *p
&& *p
!= ']'; ++p
)
2329 /* Check that the matrix contains 4 floating point
2331 for (j
= 0, start
= font
->fields
[i
- 1] + 1;
2334 if (strtod (start
, &end
) == 0 && start
== end
)
2341 while (*p
&& *p
!= '-')
2351 success_p
= i
== XLFD_LAST
;
2353 /* If requested, and font name was in the expected format,
2354 compute numeric values for some fields. */
2355 if (numeric_p
&& success_p
)
2357 font
->numeric
[XLFD_POINT_SIZE
] = xlfd_point_size (f
, font
);
2358 font
->numeric
[XLFD_RESY
] = atoi (font
->fields
[XLFD_RESY
]);
2359 font
->numeric
[XLFD_SLANT
] = xlfd_numeric_slant (font
);
2360 font
->numeric
[XLFD_WEIGHT
] = xlfd_numeric_weight (font
);
2361 font
->numeric
[XLFD_SWIDTH
] = xlfd_numeric_swidth (font
);
2362 font
->numeric
[XLFD_AVGWIDTH
] = atoi (font
->fields
[XLFD_AVGWIDTH
]);
2363 font
->rescale_ratio
= rescale_ratio
;
2366 /* Initialize it to zero. It will be overridden by font_list while
2367 trying alternate registries. */
2368 font
->registry_priority
= 0;
2374 /* Build an XLFD font name from font name fields in FONT. Value is a
2375 pointer to the font name, which is allocated via xmalloc. */
2378 build_font_name (font
)
2379 struct font_name
*font
;
2383 char *font_name
= (char *) xmalloc (size
);
2384 int total_length
= 0;
2386 for (i
= 0; i
< XLFD_LAST
; ++i
)
2388 /* Add 1 because of the leading `-'. */
2389 int len
= strlen (font
->fields
[i
]) + 1;
2391 /* Reallocate font_name if necessary. Add 1 for the final
2393 if (total_length
+ len
+ 1 >= size
)
2395 int new_size
= max (2 * size
, size
+ len
+ 1);
2396 int sz
= new_size
* sizeof *font_name
;
2397 font_name
= (char *) xrealloc (font_name
, sz
);
2401 font_name
[total_length
] = '-';
2402 bcopy (font
->fields
[i
], font_name
+ total_length
+ 1, len
- 1);
2403 total_length
+= len
;
2406 font_name
[total_length
] = 0;
2411 /* Free an array FONTS of N font_name structures. This frees FONTS
2412 itself and all `name' fields in its elements. */
2415 free_font_names (fonts
, n
)
2416 struct font_name
*fonts
;
2420 xfree (fonts
[--n
].name
);
2425 /* Sort vector FONTS of font_name structures which contains NFONTS
2426 elements using qsort and comparison function CMPFN. F is the frame
2427 on which the fonts will be used. The global variable font_frame
2428 is temporarily set to F to make it available in CMPFN. */
2431 sort_fonts (f
, fonts
, nfonts
, cmpfn
)
2433 struct font_name
*fonts
;
2435 int (*cmpfn
) P_ ((const void *, const void *));
2438 qsort (fonts
, nfonts
, sizeof *fonts
, cmpfn
);
2443 /* Get fonts matching PATTERN on frame F. If F is null, use the first
2444 display in x_display_list. FONTS is a pointer to a vector of
2445 NFONTS font_name structures. TRY_ALTERNATIVES_P non-zero means try
2446 alternative patterns from Valternate_fontname_alist if no fonts are
2447 found matching PATTERN.
2449 For all fonts found, set FONTS[i].name to the name of the font,
2450 allocated via xmalloc, and split font names into fields. Ignore
2451 fonts that we can't parse. Value is the number of fonts found. */
2454 x_face_list_fonts (f
, pattern
, pfonts
, nfonts
, try_alternatives_p
)
2457 struct font_name
**pfonts
;
2458 int nfonts
, try_alternatives_p
;
2462 /* NTEMACS_TODO : currently this uses w32_list_fonts, but it may be
2463 better to do it the other way around. */
2465 Lisp_Object lpattern
, tem
;
2466 struct font_name
*fonts
= 0;
2467 int num_fonts
= nfonts
;
2470 lpattern
= build_string (pattern
);
2472 /* Get the list of fonts matching PATTERN. */
2475 lfonts
= w32_list_fonts (f
, lpattern
, 0, nfonts
);
2478 lfonts
= x_list_fonts (f
, lpattern
, -1, nfonts
);
2481 if (nfonts
< 0 && CONSP (lfonts
))
2482 num_fonts
= XFASTINT (Flength (lfonts
));
2484 /* Make a copy of the font names we got from X, and
2485 split them into fields. */
2487 for (tem
= lfonts
; CONSP (tem
) && n
< num_fonts
; tem
= XCDR (tem
))
2489 Lisp_Object elt
, tail
;
2490 const char *name
= SDATA (XCAR (tem
));
2492 /* Ignore fonts matching a pattern from face-ignored-fonts. */
2493 for (tail
= Vface_ignored_fonts
; CONSP (tail
); tail
= XCDR (tail
))
2497 && fast_c_string_match_ignore_case (elt
, name
) >= 0)
2508 *pfonts
= (struct font_name
*) xmalloc (num_fonts
* sizeof **pfonts
);
2512 /* Make a copy of the font name. */
2513 fonts
[n
].name
= xstrdup (name
);
2515 if (split_font_name (f
, fonts
+ n
, 1))
2517 if (font_scalable_p (fonts
+ n
)
2518 && !may_use_scalable_font_p (name
))
2521 xfree (fonts
[n
].name
);
2527 xfree (fonts
[n
].name
);
2530 /* If no fonts found, try patterns from Valternate_fontname_alist. */
2531 if (n
== 0 && try_alternatives_p
)
2533 Lisp_Object list
= Valternate_fontname_alist
;
2541 while (CONSP (list
))
2543 Lisp_Object entry
= XCAR (list
);
2545 && STRINGP (XCAR (entry
))
2546 && strcmp (SDATA (XCAR (entry
)), pattern
) == 0)
2553 Lisp_Object patterns
= XCAR (list
);
2556 while (CONSP (patterns
)
2557 /* If list is screwed up, give up. */
2558 && (name
= XCAR (patterns
),
2560 /* Ignore patterns equal to PATTERN because we tried that
2561 already with no success. */
2562 && (strcmp (SDATA (name
), pattern
) == 0
2563 || (n
= x_face_list_fonts (f
, SDATA (name
),
2566 patterns
= XCDR (patterns
);
2574 /* Check if a font matching pattern_offset_t on frame F is available
2575 or not. PATTERN may be a cons (FAMILY . REGISTRY), in which case,
2576 a font name pattern is generated from FAMILY and REGISTRY. */
2579 face_font_available_p (f
, pattern
)
2581 Lisp_Object pattern
;
2585 if (! STRINGP (pattern
))
2587 Lisp_Object family
, registry
;
2588 char *family_str
, *registry_str
, *pattern_str
;
2590 CHECK_CONS (pattern
);
2591 family
= XCAR (pattern
);
2596 CHECK_STRING (family
);
2597 family_str
= (char *) SDATA (family
);
2599 registry
= XCDR (pattern
);
2600 if (NILP (registry
))
2604 CHECK_STRING (registry
);
2605 registry_str
= (char *) SDATA (registry
);
2608 pattern_str
= (char *) alloca (strlen (family_str
)
2609 + strlen (registry_str
)
2611 strcpy (pattern_str
, index (family_str
, '-') ? "-" : "-*-");
2612 strcat (pattern_str
, family_str
);
2613 strcat (pattern_str
, "-*-");
2614 strcat (pattern_str
, registry_str
);
2615 if (!index (registry_str
, '-'))
2617 if (registry_str
[strlen (registry_str
) - 1] == '*')
2618 strcat (pattern_str
, "-*");
2620 strcat (pattern_str
, "*-*");
2622 pattern
= build_string (pattern_str
);
2625 /* Get the list of fonts matching PATTERN. */
2628 fonts
= w32_list_fonts (f
, pattern
, 0, 1);
2631 fonts
= x_list_fonts (f
, pattern
, -1, 1);
2633 return XINT (Flength (fonts
));
2637 /* Determine fonts matching PATTERN on frame F. Sort resulting fonts
2638 using comparison function CMPFN. Value is the number of fonts
2639 found. If value is non-zero, *FONTS is set to a vector of
2640 font_name structures allocated from the heap containing matching
2641 fonts. Each element of *FONTS contains a name member that is also
2642 allocated from the heap. Font names in these structures are split
2643 into fields. Use free_font_names to free such an array. */
2646 sorted_font_list (f
, pattern
, cmpfn
, fonts
)
2649 int (*cmpfn
) P_ ((const void *, const void *));
2650 struct font_name
**fonts
;
2654 /* Get the list of fonts matching pattern. 100 should suffice. */
2655 nfonts
= DEFAULT_FONT_LIST_LIMIT
;
2656 if (INTEGERP (Vfont_list_limit
))
2657 nfonts
= XINT (Vfont_list_limit
);
2660 nfonts
= x_face_list_fonts (f
, pattern
, fonts
, nfonts
, 1);
2662 /* Sort the resulting array and return it in *FONTS. If no
2663 fonts were found, make sure to set *FONTS to null. */
2665 sort_fonts (f
, *fonts
, nfonts
, cmpfn
);
2676 /* Compare two font_name structures *A and *B. Value is analogous to
2677 strcmp. Sort order is given by the global variable
2678 font_sort_order. Font names are sorted so that, everything else
2679 being equal, fonts with a resolution closer to that of the frame on
2680 which they are used are listed first. The global variable
2681 font_frame is the frame on which we operate. */
2684 cmp_font_names (a
, b
)
2687 struct font_name
*x
= (struct font_name
*) a
;
2688 struct font_name
*y
= (struct font_name
*) b
;
2691 /* All strings have been converted to lower-case by split_font_name,
2692 so we can use strcmp here. */
2693 cmp
= strcmp (x
->fields
[XLFD_FAMILY
], y
->fields
[XLFD_FAMILY
]);
2698 for (i
= 0; i
< DIM (font_sort_order
) && cmp
== 0; ++i
)
2700 int j
= font_sort_order
[i
];
2701 cmp
= x
->numeric
[j
] - y
->numeric
[j
];
2706 /* Everything else being equal, we prefer fonts with an
2707 y-resolution closer to that of the frame. */
2708 int resy
= FRAME_X_DISPLAY_INFO (font_frame
)->resy
;
2709 int x_resy
= x
->numeric
[XLFD_RESY
];
2710 int y_resy
= y
->numeric
[XLFD_RESY
];
2711 cmp
= abs (resy
- x_resy
) - abs (resy
- y_resy
);
2719 /* Get a sorted list of fonts of family FAMILY on frame F. If PATTERN
2720 is non-nil list fonts matching that pattern. Otherwise, if
2721 REGISTRY is non-nil return only fonts with that registry, otherwise
2722 return fonts of any registry. Set *FONTS to a vector of font_name
2723 structures allocated from the heap containing the fonts found.
2724 Value is the number of fonts found. */
2727 font_list_1 (f
, pattern
, family
, registry
, fonts
)
2729 Lisp_Object pattern
, family
, registry
;
2730 struct font_name
**fonts
;
2732 char *pattern_str
, *family_str
, *registry_str
;
2736 family_str
= (NILP (family
) ? "*" : (char *) SDATA (family
));
2737 registry_str
= (NILP (registry
) ? "*" : (char *) SDATA (registry
));
2739 pattern_str
= (char *) alloca (strlen (family_str
)
2740 + strlen (registry_str
)
2742 strcpy (pattern_str
, index (family_str
, '-') ? "-" : "-*-");
2743 strcat (pattern_str
, family_str
);
2744 strcat (pattern_str
, "-*-");
2745 strcat (pattern_str
, registry_str
);
2746 if (!index (registry_str
, '-'))
2748 if (registry_str
[strlen (registry_str
) - 1] == '*')
2749 strcat (pattern_str
, "-*");
2751 strcat (pattern_str
, "*-*");
2755 pattern_str
= (char *) SDATA (pattern
);
2757 return sorted_font_list (f
, pattern_str
, cmp_font_names
, fonts
);
2761 /* Concatenate font list FONTS1 and FONTS2. FONTS1 and FONTS2
2762 contains NFONTS1 fonts and NFONTS2 fonts respectively. Return a
2763 pointer to a newly allocated font list. FONTS1 and FONTS2 are
2766 static struct font_name
*
2767 concat_font_list (fonts1
, nfonts1
, fonts2
, nfonts2
)
2768 struct font_name
*fonts1
, *fonts2
;
2769 int nfonts1
, nfonts2
;
2771 int new_nfonts
= nfonts1
+ nfonts2
;
2772 struct font_name
*new_fonts
;
2774 new_fonts
= (struct font_name
*) xmalloc (sizeof *new_fonts
* new_nfonts
);
2775 bcopy (fonts1
, new_fonts
, sizeof *new_fonts
* nfonts1
);
2776 bcopy (fonts2
, new_fonts
+ nfonts1
, sizeof *new_fonts
* nfonts2
);
2783 /* Get a sorted list of fonts of family FAMILY on frame F.
2785 If PATTERN is non-nil list fonts matching that pattern.
2787 If REGISTRY is non-nil, return fonts with that registry and the
2788 alternative registries from Vface_alternative_font_registry_alist.
2790 If REGISTRY is nil return fonts of any registry.
2792 Set *FONTS to a vector of font_name structures allocated from the
2793 heap containing the fonts found. Value is the number of fonts
2797 font_list (f
, pattern
, family
, registry
, fonts
)
2799 Lisp_Object pattern
, family
, registry
;
2800 struct font_name
**fonts
;
2802 int nfonts
= font_list_1 (f
, pattern
, family
, registry
, fonts
);
2804 if (!NILP (registry
)
2805 && CONSP (Vface_alternative_font_registry_alist
))
2809 alter
= Fassoc (registry
, Vface_alternative_font_registry_alist
);
2814 for (alter
= XCDR (alter
), reg_prio
= 1;
2816 alter
= XCDR (alter
), reg_prio
++)
2817 if (STRINGP (XCAR (alter
)))
2820 struct font_name
*fonts2
;
2822 nfonts2
= font_list_1 (f
, pattern
, family
, XCAR (alter
),
2824 for (i
= 0; i
< nfonts2
; i
++)
2825 fonts2
[i
].registry_priority
= reg_prio
;
2826 *fonts
= (nfonts
> 0
2827 ? concat_font_list (*fonts
, nfonts
, fonts2
, nfonts2
)
2838 /* Remove elements from LIST whose cars are `equal'. Called from
2839 x-family-fonts and x-font-family-list to remove duplicate font
2843 remove_duplicates (list
)
2846 Lisp_Object tail
= list
;
2848 while (!NILP (tail
) && !NILP (XCDR (tail
)))
2850 Lisp_Object next
= XCDR (tail
);
2851 if (!NILP (Fequal (XCAR (next
), XCAR (tail
))))
2852 XSETCDR (tail
, XCDR (next
));
2859 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
2860 doc
: /* Return a list of available fonts of family FAMILY on FRAME.
2861 If FAMILY is omitted or nil, list all families.
2862 Otherwise, FAMILY must be a string, possibly containing wildcards
2864 If FRAME is omitted or nil, use the selected frame.
2865 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
2866 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
2867 FAMILY is the font family name. POINT-SIZE is the size of the
2868 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
2869 width, weight and slant of the font. These symbols are the same as for
2870 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
2871 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
2872 giving the registry and encoding of the font.
2873 The result list is sorted according to the current setting of
2874 the face font sort order. */)
2876 Lisp_Object family
, frame
;
2878 struct frame
*f
= check_x_frame (frame
);
2879 struct font_name
*fonts
;
2882 struct gcpro gcpro1
;
2885 CHECK_STRING (family
);
2889 nfonts
= font_list (f
, Qnil
, family
, Qnil
, &fonts
);
2890 for (i
= nfonts
- 1; i
>= 0; --i
)
2892 Lisp_Object v
= Fmake_vector (make_number (8), Qnil
);
2895 ASET (v
, 0, build_string (fonts
[i
].fields
[XLFD_FAMILY
]));
2896 ASET (v
, 1, xlfd_symbolic_swidth (fonts
+ i
));
2897 ASET (v
, 2, make_number (xlfd_point_size (f
, fonts
+ i
)));
2898 ASET (v
, 3, xlfd_symbolic_weight (fonts
+ i
));
2899 ASET (v
, 4, xlfd_symbolic_slant (fonts
+ i
));
2900 ASET (v
, 5, xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
);
2901 tem
= build_font_name (fonts
+ i
);
2902 ASET (v
, 6, build_string (tem
));
2903 sprintf (tem
, "%s-%s", fonts
[i
].fields
[XLFD_REGISTRY
],
2904 fonts
[i
].fields
[XLFD_ENCODING
]);
2905 ASET (v
, 7, build_string (tem
));
2908 result
= Fcons (v
, result
);
2911 remove_duplicates (result
);
2912 free_font_names (fonts
, nfonts
);
2918 DEFUN ("x-font-family-list", Fx_font_family_list
, Sx_font_family_list
,
2920 doc
: /* Return a list of available font families on FRAME.
2921 If FRAME is omitted or nil, use the selected frame.
2922 Value is a list of conses (FAMILY . FIXED-P) where FAMILY
2923 is a font family, and FIXED-P is non-nil if fonts of that family
2924 are fixed-pitch. */)
2928 struct frame
*f
= check_x_frame (frame
);
2930 struct font_name
*fonts
;
2932 struct gcpro gcpro1
;
2933 int count
= SPECPDL_INDEX ();
2935 /* Let's consider all fonts. */
2936 specbind (intern ("font-list-limit"), make_number (-1));
2937 nfonts
= font_list (f
, Qnil
, Qnil
, Qnil
, &fonts
);
2941 for (i
= nfonts
- 1; i
>= 0; --i
)
2942 result
= Fcons (Fcons (build_string (fonts
[i
].fields
[XLFD_FAMILY
]),
2943 xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
),
2946 remove_duplicates (result
);
2947 free_font_names (fonts
, nfonts
);
2949 return unbind_to (count
, result
);
2953 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
2954 doc
: /* Return a list of the names of available fonts matching PATTERN.
2955 If optional arguments FACE and FRAME are specified, return only fonts
2956 the same size as FACE on FRAME.
2957 PATTERN is a string, perhaps with wildcard characters;
2958 the * character matches any substring, and
2959 the ? character matches any single character.
2960 PATTERN is case-insensitive.
2961 FACE is a face name--a symbol.
2963 The return value is a list of strings, suitable as arguments to
2966 Fonts Emacs can't use may or may not be excluded
2967 even if they match PATTERN and FACE.
2968 The optional fourth argument MAXIMUM sets a limit on how many
2969 fonts to match. The first MAXIMUM fonts are reported.
2970 The optional fifth argument WIDTH, if specified, is a number of columns
2971 occupied by a character of a font. In that case, return only fonts
2972 the WIDTH times as wide as FACE on FRAME. */)
2973 (pattern
, face
, frame
, maximum
, width
)
2974 Lisp_Object pattern
, face
, frame
, maximum
, width
;
2981 CHECK_STRING (pattern
);
2987 CHECK_NATNUM (maximum
);
2988 maxnames
= XINT (maximum
);
2992 CHECK_NUMBER (width
);
2994 /* We can't simply call check_x_frame because this function may be
2995 called before any frame is created. */
2996 f
= frame_or_selected_frame (frame
, 2);
2997 if (!FRAME_WINDOW_P (f
))
2999 /* Perhaps we have not yet created any frame. */
3004 /* Determine the width standard for comparison with the fonts we find. */
3010 /* This is of limited utility since it works with character
3011 widths. Keep it for compatibility. --gerd. */
3012 int face_id
= lookup_named_face (f
, face
, 0, 0);
3013 struct face
*face
= (face_id
< 0
3015 : FACE_FROM_ID (f
, face_id
));
3018 /* For historic reasons, FONT_WIDTH refers to average width on W32,
3019 not maximum as on X. Redefine here. */
3021 #define FONT_WIDTH FONT_MAX_WIDTH
3024 if (face
&& face
->font
)
3025 size
= FONT_WIDTH (face
->font
);
3027 size
= FONT_WIDTH (FRAME_FONT (f
)); /* FRAME_COLUMN_WIDTH (f) */
3030 size
*= XINT (width
);
3034 Lisp_Object args
[2];
3036 args
[0] = x_list_fonts (f
, pattern
, size
, maxnames
);
3038 /* We don't have to check fontsets. */
3040 args
[1] = list_fontsets (f
, pattern
, size
);
3041 return Fnconc (2, args
);
3045 #endif /* HAVE_WINDOW_SYSTEM */
3049 /***********************************************************************
3051 ***********************************************************************/
3053 /* Access face attributes of face LFACE, a Lisp vector. */
3055 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
3056 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
3057 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
3058 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
3059 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
3060 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
3061 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
3062 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
3063 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
3064 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
3065 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
3066 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
3067 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
3068 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
3069 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
3070 #define LFACE_AVGWIDTH(LFACE) AREF ((LFACE), LFACE_AVGWIDTH_INDEX)
3072 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
3073 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
3075 #define LFACEP(LFACE) \
3077 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \
3078 && EQ (AREF (LFACE, 0), Qface))
3083 /* Check consistency of Lisp face attribute vector ATTRS. */
3086 check_lface_attrs (attrs
)
3089 xassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
3090 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
3091 xassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
3092 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
3093 xassert (UNSPECIFIEDP (attrs
[LFACE_AVGWIDTH_INDEX
])
3094 || INTEGERP (attrs
[LFACE_AVGWIDTH_INDEX
]));
3095 xassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
3096 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
])
3097 || FLOATP (attrs
[LFACE_HEIGHT_INDEX
])
3098 || FUNCTIONP (attrs
[LFACE_HEIGHT_INDEX
]));
3099 xassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
3100 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
3101 xassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
3102 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
3103 xassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
3104 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
3105 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]));
3106 xassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
3107 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
3108 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
3109 xassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
3110 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
3111 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
3112 xassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
3113 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
3114 || STRINGP (attrs
[LFACE_BOX_INDEX
])
3115 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
3116 || CONSP (attrs
[LFACE_BOX_INDEX
]));
3117 xassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
3118 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
3119 xassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
3120 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
3121 xassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
3122 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
3123 xassert (UNSPECIFIEDP (attrs
[LFACE_INHERIT_INDEX
])
3124 || NILP (attrs
[LFACE_INHERIT_INDEX
])
3125 || SYMBOLP (attrs
[LFACE_INHERIT_INDEX
])
3126 || CONSP (attrs
[LFACE_INHERIT_INDEX
]));
3127 #ifdef HAVE_WINDOW_SYSTEM
3128 xassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
3129 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
3130 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
3131 xassert (UNSPECIFIEDP (attrs
[LFACE_FONT_INDEX
])
3132 || NILP (attrs
[LFACE_FONT_INDEX
])
3133 || STRINGP (attrs
[LFACE_FONT_INDEX
]));
3138 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
3146 xassert (LFACEP (lface
));
3147 check_lface_attrs (XVECTOR (lface
)->contents
);
3151 #else /* GLYPH_DEBUG == 0 */
3153 #define check_lface_attrs(attrs) (void) 0
3154 #define check_lface(lface) (void) 0
3156 #endif /* GLYPH_DEBUG == 0 */
3160 /* Face-merge cycle checking. */
3162 /* A `named merge point' is simply a point during face-merging where we
3163 look up a face by name. We keep a stack of which named lookups we're
3164 currently processing so that we can easily detect cycles, using a
3165 linked- list of struct named_merge_point structures, typically
3166 allocated on the stack frame of the named lookup functions which are
3167 active (so no consing is required). */
3168 struct named_merge_point
3170 Lisp_Object face_name
;
3171 struct named_merge_point
*prev
;
3175 /* If a face merging cycle is detected for FACE_NAME, return 0,
3176 otherwise add NEW_NAMED_MERGE_POINT, which is initialized using
3177 FACE_NAME, as the head of the linked list pointed to by
3178 NAMED_MERGE_POINTS, and return 1. */
3181 push_named_merge_point (struct named_merge_point
*new_named_merge_point
,
3182 Lisp_Object face_name
,
3183 struct named_merge_point
**named_merge_points
)
3185 struct named_merge_point
*prev
;
3187 for (prev
= *named_merge_points
; prev
; prev
= prev
->prev
)
3188 if (EQ (face_name
, prev
->face_name
))
3191 new_named_merge_point
->face_name
= face_name
;
3192 new_named_merge_point
->prev
= *named_merge_points
;
3194 *named_merge_points
= new_named_merge_point
;
3202 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
3203 to make it a symvol. If FACE_NAME is an alias for another face,
3204 return that face's name. */
3207 resolve_face_name (face_name
)
3208 Lisp_Object face_name
;
3210 Lisp_Object aliased
;
3212 if (STRINGP (face_name
))
3213 face_name
= intern (SDATA (face_name
));
3215 while (SYMBOLP (face_name
))
3217 aliased
= Fget (face_name
, Qface_alias
);
3221 face_name
= aliased
;
3228 /* Return the face definition of FACE_NAME on frame F. F null means
3229 return the definition for new frames. FACE_NAME may be a string or
3230 a symbol (apparently Emacs 20.2 allowed strings as face names in
3231 face text properties; Ediff uses that). If FACE_NAME is an alias
3232 for another face, return that face's definition. If SIGNAL_P is
3233 non-zero, signal an error if FACE_NAME is not a valid face name.
3234 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
3237 static INLINE Lisp_Object
3238 lface_from_face_name (f
, face_name
, signal_p
)
3240 Lisp_Object face_name
;
3245 face_name
= resolve_face_name (face_name
);
3248 lface
= assq_no_quit (face_name
, f
->face_alist
);
3250 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
3253 lface
= XCDR (lface
);
3255 signal_error ("Invalid face", face_name
);
3257 check_lface (lface
);
3262 /* Get face attributes of face FACE_NAME from frame-local faces on
3263 frame F. Store the resulting attributes in ATTRS which must point
3264 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
3265 is non-zero, signal an error if FACE_NAME does not name a face.
3266 Otherwise, value is zero if FACE_NAME is not a face. */
3269 get_lface_attributes (f
, face_name
, attrs
, signal_p
)
3271 Lisp_Object face_name
;
3278 lface
= lface_from_face_name (f
, face_name
, signal_p
);
3281 bcopy (XVECTOR (lface
)->contents
, attrs
,
3282 LFACE_VECTOR_SIZE
* sizeof *attrs
);
3292 /* Non-zero if all attributes in face attribute vector ATTRS are
3293 specified, i.e. are non-nil. */
3296 lface_fully_specified_p (attrs
)
3301 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3302 if (i
!= LFACE_FONT_INDEX
&& i
!= LFACE_INHERIT_INDEX
3303 && i
!= LFACE_AVGWIDTH_INDEX
)
3304 if (UNSPECIFIEDP (attrs
[i
])
3306 /* MAC_TODO: No stipple support on Mac OS yet, this index is
3307 always unspecified. */
3308 && i
!= LFACE_STIPPLE_INDEX
3313 return i
== LFACE_VECTOR_SIZE
;
3316 #ifdef HAVE_WINDOW_SYSTEM
3318 /* Set font-related attributes of Lisp face LFACE from the fullname of
3319 the font opened by FONTNAME. If FORCE_P is zero, set only
3320 unspecified attributes of LFACE. The exception is `font'
3321 attribute. It is set to FONTNAME as is regardless of FORCE_P.
3323 If FONTNAME is not available on frame F,
3324 return 0 if MAY_FAIL_P is non-zero, otherwise abort.
3325 If the fullname is not in a valid XLFD format,
3326 return 0 if MAY_FAIL_P is non-zero, otherwise set normal values
3327 in LFACE and return 1.
3328 Otherwise, return 1. */
3331 set_lface_from_font_name (f
, lface
, fontname
, force_p
, may_fail_p
)
3334 Lisp_Object fontname
;
3335 int force_p
, may_fail_p
;
3337 struct font_name font
;
3342 char *font_name
= SDATA (fontname
);
3343 struct font_info
*font_info
;
3345 /* If FONTNAME is actually a fontset name, get ASCII font name of it. */
3346 fontset
= fs_query_fontset (fontname
, 0);
3348 font_name
= SDATA (fontset_ascii (fontset
));
3350 /* Check if FONT_NAME is surely available on the system. Usually
3351 FONT_NAME is already cached for the frame F and FS_LOAD_FONT
3352 returns quickly. But, even if FONT_NAME is not yet cached,
3353 caching it now is not futail because we anyway load the font
3356 font_info
= FS_LOAD_FONT (f
, 0, font_name
, -1);
3366 font
.name
= STRDUPA (font_info
->full_name
);
3367 have_xlfd_p
= split_font_name (f
, &font
, 1);
3369 /* Set attributes only if unspecified, otherwise face defaults for
3370 new frames would never take effect. If we couldn't get a font
3371 name conforming to XLFD, set normal values. */
3373 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
3378 buffer
= (char *) alloca (strlen (font
.fields
[XLFD_FAMILY
])
3379 + strlen (font
.fields
[XLFD_FOUNDRY
])
3381 sprintf (buffer
, "%s-%s", font
.fields
[XLFD_FOUNDRY
],
3382 font
.fields
[XLFD_FAMILY
]);
3383 val
= build_string (buffer
);
3386 val
= build_string ("*");
3387 LFACE_FAMILY (lface
) = val
;
3390 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
3393 pt
= xlfd_point_size (f
, &font
);
3395 pt
= pixel_point_size (f
, font_info
->height
* 10);
3397 LFACE_HEIGHT (lface
) = make_number (pt
);
3400 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
3401 LFACE_SWIDTH (lface
)
3402 = have_xlfd_p
? xlfd_symbolic_swidth (&font
) : Qnormal
;
3404 if (force_p
|| UNSPECIFIEDP (LFACE_AVGWIDTH (lface
)))
3405 LFACE_AVGWIDTH (lface
)
3407 ? make_number (font
.numeric
[XLFD_AVGWIDTH
])
3410 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
3411 LFACE_WEIGHT (lface
)
3412 = have_xlfd_p
? xlfd_symbolic_weight (&font
) : Qnormal
;
3414 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
3416 = have_xlfd_p
? xlfd_symbolic_slant (&font
) : Qnormal
;
3418 LFACE_FONT (lface
) = fontname
;
3423 #endif /* HAVE_WINDOW_SYSTEM */
3426 /* Merges the face height FROM with the face height TO, and returns the
3427 merged height. If FROM is an invalid height, then INVALID is
3428 returned instead. FROM and TO may be either absolute face heights or
3429 `relative' heights; the returned value is always an absolute height
3430 unless both FROM and TO are relative. GCPRO is a lisp value that
3431 will be protected from garbage-collection if this function makes a
3435 merge_face_heights (from
, to
, invalid
)
3436 Lisp_Object from
, to
, invalid
;
3438 Lisp_Object result
= invalid
;
3440 if (INTEGERP (from
))
3441 /* FROM is absolute, just use it as is. */
3443 else if (FLOATP (from
))
3444 /* FROM is a scale, use it to adjust TO. */
3447 /* relative X absolute => absolute */
3448 result
= make_number ((EMACS_INT
)(XFLOAT_DATA (from
) * XINT (to
)));
3449 else if (FLOATP (to
))
3450 /* relative X relative => relative */
3451 result
= make_float (XFLOAT_DATA (from
) * XFLOAT_DATA (to
));
3452 else if (UNSPECIFIEDP (to
))
3455 else if (FUNCTIONP (from
))
3456 /* FROM is a function, which use to adjust TO. */
3458 /* Call function with current height as argument.
3459 From is the new height. */
3460 Lisp_Object args
[2];
3464 result
= safe_call (2, args
);
3466 /* Ensure that if TO was absolute, so is the result. */
3467 if (INTEGERP (to
) && !INTEGERP (result
))
3475 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
3476 store the resulting attributes in TO, which must be already be
3477 completely specified and contain only absolute attributes. Every
3478 specified attribute of FROM overrides the corresponding attribute of
3479 TO; relative attributes in FROM are merged with the absolute value in
3480 TO and replace it. NAMED_MERGE_POINTS is used internally to detect
3481 loops in face inheritance; it should be 0 when called from other
3485 merge_face_vectors (f
, from
, to
, named_merge_points
)
3487 Lisp_Object
*from
, *to
;
3488 struct named_merge_point
*named_merge_points
;
3492 /* If FROM inherits from some other faces, merge their attributes into
3493 TO before merging FROM's direct attributes. Note that an :inherit
3494 attribute of `unspecified' is the same as one of nil; we never
3495 merge :inherit attributes, so nil is more correct, but lots of
3496 other code uses `unspecified' as a generic value for face attributes. */
3497 if (!UNSPECIFIEDP (from
[LFACE_INHERIT_INDEX
])
3498 && !NILP (from
[LFACE_INHERIT_INDEX
]))
3499 merge_face_ref (f
, from
[LFACE_INHERIT_INDEX
], to
, 0, named_merge_points
);
3501 /* If TO specifies a :font attribute, and FROM specifies some
3502 font-related attribute, we need to clear TO's :font attribute
3503 (because it will be inconsistent with whatever FROM specifies, and
3504 FROM takes precedence). */
3505 if (!NILP (to
[LFACE_FONT_INDEX
])
3506 && (!UNSPECIFIEDP (from
[LFACE_FAMILY_INDEX
])
3507 || !UNSPECIFIEDP (from
[LFACE_HEIGHT_INDEX
])
3508 || !UNSPECIFIEDP (from
[LFACE_WEIGHT_INDEX
])
3509 || !UNSPECIFIEDP (from
[LFACE_SLANT_INDEX
])
3510 || !UNSPECIFIEDP (from
[LFACE_SWIDTH_INDEX
])
3511 || !UNSPECIFIEDP (from
[LFACE_AVGWIDTH_INDEX
])))
3512 to
[LFACE_FONT_INDEX
] = Qnil
;
3514 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3515 if (!UNSPECIFIEDP (from
[i
]))
3517 if (i
== LFACE_HEIGHT_INDEX
&& !INTEGERP (from
[i
]))
3518 to
[i
] = merge_face_heights (from
[i
], to
[i
], to
[i
]);
3523 /* TO is always an absolute face, which should inherit from nothing.
3524 We blindly copy the :inherit attribute above and fix it up here. */
3525 to
[LFACE_INHERIT_INDEX
] = Qnil
;
3528 /* Merge the named face FACE_NAME on frame F, into the vector of face
3529 attributes TO. NAMED_MERGE_POINTS is used to detect loops in face
3530 inheritance. Returns true if FACE_NAME is a valid face name and
3531 merging succeeded. */
3534 merge_named_face (f
, face_name
, to
, named_merge_points
)
3536 Lisp_Object face_name
;
3538 struct named_merge_point
*named_merge_points
;
3540 struct named_merge_point named_merge_point
;
3542 if (push_named_merge_point (&named_merge_point
,
3543 face_name
, &named_merge_points
))
3545 struct gcpro gcpro1
;
3546 Lisp_Object from
[LFACE_VECTOR_SIZE
];
3547 int ok
= get_lface_attributes (f
, face_name
, from
, 0);
3551 GCPRO1 (named_merge_point
.face_name
);
3552 merge_face_vectors (f
, from
, to
, named_merge_points
);
3563 /* Merge face attributes from the lisp `face reference' FACE_REF on
3564 frame F into the face attribute vector TO. If ERR_MSGS is non-zero,
3565 problems with FACE_REF cause an error message to be shown. Return
3566 non-zero if no errors occurred (regardless of the value of ERR_MSGS).
3567 NAMED_MERGE_POINTS is used to detect loops in face inheritance or
3568 list structure; it may be 0 for most callers.
3570 FACE_REF may be a single face specification or a list of such
3571 specifications. Each face specification can be:
3573 1. A symbol or string naming a Lisp face.
3575 2. A property list of the form (KEYWORD VALUE ...) where each
3576 KEYWORD is a face attribute name, and value is an appropriate value
3579 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
3580 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
3581 for compatibility with 20.2.
3583 Face specifications earlier in lists take precedence over later
3587 merge_face_ref (f
, face_ref
, to
, err_msgs
, named_merge_points
)
3589 Lisp_Object face_ref
;
3592 struct named_merge_point
*named_merge_points
;
3594 int ok
= 1; /* Succeed without an error? */
3596 if (CONSP (face_ref
))
3598 Lisp_Object first
= XCAR (face_ref
);
3600 if (EQ (first
, Qforeground_color
)
3601 || EQ (first
, Qbackground_color
))
3603 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
3604 . COLOR). COLOR must be a string. */
3605 Lisp_Object color_name
= XCDR (face_ref
);
3606 Lisp_Object color
= first
;
3608 if (STRINGP (color_name
))
3610 if (EQ (color
, Qforeground_color
))
3611 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
3613 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
3618 add_to_log ("Invalid face color", color_name
, Qnil
);
3622 else if (SYMBOLP (first
)
3623 && *SDATA (SYMBOL_NAME (first
)) == ':')
3625 /* Assume this is the property list form. */
3626 while (CONSP (face_ref
) && CONSP (XCDR (face_ref
)))
3628 Lisp_Object keyword
= XCAR (face_ref
);
3629 Lisp_Object value
= XCAR (XCDR (face_ref
));
3632 /* Specifying `unspecified' is a no-op. */
3633 if (EQ (value
, Qunspecified
))
3635 else if (EQ (keyword
, QCfamily
))
3637 if (STRINGP (value
))
3638 to
[LFACE_FAMILY_INDEX
] = value
;
3642 else if (EQ (keyword
, QCheight
))
3644 Lisp_Object new_height
=
3645 merge_face_heights (value
, to
[LFACE_HEIGHT_INDEX
], Qnil
);
3647 if (! NILP (new_height
))
3648 to
[LFACE_HEIGHT_INDEX
] = new_height
;
3652 else if (EQ (keyword
, QCweight
))
3655 && face_numeric_weight (value
) >= 0)
3656 to
[LFACE_WEIGHT_INDEX
] = value
;
3660 else if (EQ (keyword
, QCslant
))
3663 && face_numeric_slant (value
) >= 0)
3664 to
[LFACE_SLANT_INDEX
] = value
;
3668 else if (EQ (keyword
, QCunderline
))
3673 to
[LFACE_UNDERLINE_INDEX
] = value
;
3677 else if (EQ (keyword
, QCoverline
))
3682 to
[LFACE_OVERLINE_INDEX
] = value
;
3686 else if (EQ (keyword
, QCstrike_through
))
3691 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
3695 else if (EQ (keyword
, QCbox
))
3698 value
= make_number (1);
3699 if (INTEGERP (value
)
3703 to
[LFACE_BOX_INDEX
] = value
;
3707 else if (EQ (keyword
, QCinverse_video
)
3708 || EQ (keyword
, QCreverse_video
))
3710 if (EQ (value
, Qt
) || NILP (value
))
3711 to
[LFACE_INVERSE_INDEX
] = value
;
3715 else if (EQ (keyword
, QCforeground
))
3717 if (STRINGP (value
))
3718 to
[LFACE_FOREGROUND_INDEX
] = value
;
3722 else if (EQ (keyword
, QCbackground
))
3724 if (STRINGP (value
))
3725 to
[LFACE_BACKGROUND_INDEX
] = value
;
3729 else if (EQ (keyword
, QCstipple
))
3731 #ifdef HAVE_X_WINDOWS
3732 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
3733 if (!NILP (pixmap_p
))
3734 to
[LFACE_STIPPLE_INDEX
] = value
;
3739 else if (EQ (keyword
, QCwidth
))
3742 && face_numeric_swidth (value
) >= 0)
3743 to
[LFACE_SWIDTH_INDEX
] = value
;
3747 else if (EQ (keyword
, QCinherit
))
3749 /* This is not really very useful; it's just like a
3750 normal face reference. */
3751 if (! merge_face_ref (f
, value
, to
,
3752 err_msgs
, named_merge_points
))
3760 add_to_log ("Invalid face attribute %S %S", keyword
, value
);
3764 face_ref
= XCDR (XCDR (face_ref
));
3769 /* This is a list of face refs. Those at the beginning of the
3770 list take precedence over what follows, so we have to merge
3771 from the end backwards. */
3772 Lisp_Object next
= XCDR (face_ref
);
3775 ok
= merge_face_ref (f
, next
, to
, err_msgs
, named_merge_points
);
3777 if (! merge_face_ref (f
, first
, to
, err_msgs
, named_merge_points
))
3783 /* FACE_REF ought to be a face name. */
3784 ok
= merge_named_face (f
, face_ref
, to
, named_merge_points
);
3785 if (!ok
&& err_msgs
)
3786 add_to_log ("Invalid face reference: %s", face_ref
, Qnil
);
3793 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
3794 Sinternal_make_lisp_face
, 1, 2, 0,
3795 doc
: /* Make FACE, a symbol, a Lisp face with all attributes nil.
3796 If FACE was not known as a face before, create a new one.
3797 If optional argument FRAME is specified, make a frame-local face
3798 for that frame. Otherwise operate on the global face definition.
3799 Value is a vector of face attributes. */)
3801 Lisp_Object face
, frame
;
3803 Lisp_Object global_lface
, lface
;
3807 CHECK_SYMBOL (face
);
3808 global_lface
= lface_from_face_name (NULL
, face
, 0);
3812 CHECK_LIVE_FRAME (frame
);
3814 lface
= lface_from_face_name (f
, face
, 0);
3817 f
= NULL
, lface
= Qnil
;
3819 /* Add a global definition if there is none. */
3820 if (NILP (global_lface
))
3822 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
3824 AREF (global_lface
, 0) = Qface
;
3825 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
3826 Vface_new_frame_defaults
);
3828 /* Assign the new Lisp face a unique ID. The mapping from Lisp
3829 face id to Lisp face is given by the vector lface_id_to_name.
3830 The mapping from Lisp face to Lisp face id is given by the
3831 property `face' of the Lisp face name. */
3832 if (next_lface_id
== lface_id_to_name_size
)
3834 int new_size
= max (50, 2 * lface_id_to_name_size
);
3835 int sz
= new_size
* sizeof *lface_id_to_name
;
3836 lface_id_to_name
= (Lisp_Object
*) xrealloc (lface_id_to_name
, sz
);
3837 lface_id_to_name_size
= new_size
;
3840 lface_id_to_name
[next_lface_id
] = face
;
3841 Fput (face
, Qface
, make_number (next_lface_id
));
3845 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3846 AREF (global_lface
, i
) = Qunspecified
;
3848 /* Add a frame-local definition. */
3853 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
3855 AREF (lface
, 0) = Qface
;
3856 f
->face_alist
= Fcons (Fcons (face
, lface
), f
->face_alist
);
3859 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3860 AREF (lface
, i
) = Qunspecified
;
3863 lface
= global_lface
;
3865 /* Changing a named face means that all realized faces depending on
3866 that face are invalid. Since we cannot tell which realized faces
3867 depend on the face, make sure they are all removed. This is done
3868 by incrementing face_change_count. The next call to
3869 init_iterator will then free realized faces. */
3870 if (NILP (Fget (face
, Qface_no_inherit
)))
3872 ++face_change_count
;
3873 ++windows_or_buffers_changed
;
3876 xassert (LFACEP (lface
));
3877 check_lface (lface
);
3882 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
3883 Sinternal_lisp_face_p
, 1, 2, 0,
3884 doc
: /* Return non-nil if FACE names a face.
3885 If optional second parameter FRAME is non-nil, check for the
3886 existence of a frame-local face with name FACE on that frame.
3887 Otherwise check for the existence of a global face. */)
3889 Lisp_Object face
, frame
;
3895 CHECK_LIVE_FRAME (frame
);
3896 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3899 lface
= lface_from_face_name (NULL
, face
, 0);
3905 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
3906 Sinternal_copy_lisp_face
, 4, 4, 0,
3907 doc
: /* Copy face FROM to TO.
3908 If FRAME is t, copy the global face definition of FROM.
3909 Otherwise, copy the frame-local definition of FROM on FRAME.
3910 If NEW-FRAME is a frame, copy that data into the frame-local
3911 definition of TO on NEW-FRAME. If NEW-FRAME is nil.
3912 FRAME controls where the data is copied to.
3914 The value is TO. */)
3915 (from
, to
, frame
, new_frame
)
3916 Lisp_Object from
, to
, frame
, new_frame
;
3918 Lisp_Object lface
, copy
;
3920 CHECK_SYMBOL (from
);
3925 /* Copy global definition of FROM. We don't make copies of
3926 strings etc. because 20.2 didn't do it either. */
3927 lface
= lface_from_face_name (NULL
, from
, 1);
3928 copy
= Finternal_make_lisp_face (to
, Qnil
);
3932 /* Copy frame-local definition of FROM. */
3933 if (NILP (new_frame
))
3935 CHECK_LIVE_FRAME (frame
);
3936 CHECK_LIVE_FRAME (new_frame
);
3937 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
3938 copy
= Finternal_make_lisp_face (to
, new_frame
);
3941 bcopy (XVECTOR (lface
)->contents
, XVECTOR (copy
)->contents
,
3942 LFACE_VECTOR_SIZE
* sizeof (Lisp_Object
));
3944 /* Changing a named face means that all realized faces depending on
3945 that face are invalid. Since we cannot tell which realized faces
3946 depend on the face, make sure they are all removed. This is done
3947 by incrementing face_change_count. The next call to
3948 init_iterator will then free realized faces. */
3949 if (NILP (Fget (to
, Qface_no_inherit
)))
3951 ++face_change_count
;
3952 ++windows_or_buffers_changed
;
3959 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
3960 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
3961 doc
: /* Set attribute ATTR of FACE to VALUE.
3962 FRAME being a frame means change the face on that frame.
3963 FRAME nil means change the face of the selected frame.
3964 FRAME t means change the default for new frames.
3965 FRAME 0 means change the face on all frames, and change the default
3967 (face
, attr
, value
, frame
)
3968 Lisp_Object face
, attr
, value
, frame
;
3971 Lisp_Object old_value
= Qnil
;
3972 /* Set 1 if ATTR is QCfont. */
3973 int font_attr_p
= 0;
3974 /* Set 1 if ATTR is one of font-related attributes other than QCfont. */
3975 int font_related_attr_p
= 0;
3977 CHECK_SYMBOL (face
);
3978 CHECK_SYMBOL (attr
);
3980 face
= resolve_face_name (face
);
3982 /* If FRAME is 0, change face on all frames, and change the
3983 default for new frames. */
3984 if (INTEGERP (frame
) && XINT (frame
) == 0)
3987 Finternal_set_lisp_face_attribute (face
, attr
, value
, Qt
);
3988 FOR_EACH_FRAME (tail
, frame
)
3989 Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3993 /* Set lface to the Lisp attribute vector of FACE. */
3995 lface
= lface_from_face_name (NULL
, face
, 1);
3999 frame
= selected_frame
;
4001 CHECK_LIVE_FRAME (frame
);
4002 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
4004 /* If a frame-local face doesn't exist yet, create one. */
4006 lface
= Finternal_make_lisp_face (face
, frame
);
4009 if (EQ (attr
, QCfamily
))
4011 if (!UNSPECIFIEDP (value
))
4013 CHECK_STRING (value
);
4014 if (SCHARS (value
) == 0)
4015 signal_error ("Invalid face family", value
);
4017 old_value
= LFACE_FAMILY (lface
);
4018 LFACE_FAMILY (lface
) = value
;
4019 font_related_attr_p
= 1;
4021 else if (EQ (attr
, QCheight
))
4023 if (!UNSPECIFIEDP (value
))
4027 test
= (EQ (face
, Qdefault
)
4029 /* The default face must have an absolute size,
4030 otherwise, we do a test merge with a random
4031 height to see if VALUE's ok. */
4032 : merge_face_heights (value
, make_number (10), Qnil
));
4034 if (!INTEGERP (test
) || XINT (test
) <= 0)
4035 signal_error ("Invalid face height", value
);
4038 old_value
= LFACE_HEIGHT (lface
);
4039 LFACE_HEIGHT (lface
) = value
;
4040 font_related_attr_p
= 1;
4042 else if (EQ (attr
, QCweight
))
4044 if (!UNSPECIFIEDP (value
))
4046 CHECK_SYMBOL (value
);
4047 if (face_numeric_weight (value
) < 0)
4048 signal_error ("Invalid face weight", value
);
4050 old_value
= LFACE_WEIGHT (lface
);
4051 LFACE_WEIGHT (lface
) = value
;
4052 font_related_attr_p
= 1;
4054 else if (EQ (attr
, QCslant
))
4056 if (!UNSPECIFIEDP (value
))
4058 CHECK_SYMBOL (value
);
4059 if (face_numeric_slant (value
) < 0)
4060 signal_error ("Invalid face slant", value
);
4062 old_value
= LFACE_SLANT (lface
);
4063 LFACE_SLANT (lface
) = value
;
4064 font_related_attr_p
= 1;
4066 else if (EQ (attr
, QCunderline
))
4068 if (!UNSPECIFIEDP (value
))
4069 if ((SYMBOLP (value
)
4071 && !EQ (value
, Qnil
))
4072 /* Underline color. */
4074 && SCHARS (value
) == 0))
4075 signal_error ("Invalid face underline", value
);
4077 old_value
= LFACE_UNDERLINE (lface
);
4078 LFACE_UNDERLINE (lface
) = value
;
4080 else if (EQ (attr
, QCoverline
))
4082 if (!UNSPECIFIEDP (value
))
4083 if ((SYMBOLP (value
)
4085 && !EQ (value
, Qnil
))
4086 /* Overline color. */
4088 && SCHARS (value
) == 0))
4089 signal_error ("Invalid face overline", value
);
4091 old_value
= LFACE_OVERLINE (lface
);
4092 LFACE_OVERLINE (lface
) = value
;
4094 else if (EQ (attr
, QCstrike_through
))
4096 if (!UNSPECIFIEDP (value
))
4097 if ((SYMBOLP (value
)
4099 && !EQ (value
, Qnil
))
4100 /* Strike-through color. */
4102 && SCHARS (value
) == 0))
4103 signal_error ("Invalid face strike-through", value
);
4105 old_value
= LFACE_STRIKE_THROUGH (lface
);
4106 LFACE_STRIKE_THROUGH (lface
) = value
;
4108 else if (EQ (attr
, QCbox
))
4112 /* Allow t meaning a simple box of width 1 in foreground color
4115 value
= make_number (1);
4117 if (UNSPECIFIEDP (value
))
4119 else if (NILP (value
))
4121 else if (INTEGERP (value
))
4122 valid_p
= XINT (value
) != 0;
4123 else if (STRINGP (value
))
4124 valid_p
= SCHARS (value
) > 0;
4125 else if (CONSP (value
))
4141 if (EQ (k
, QCline_width
))
4143 if (!INTEGERP (v
) || XINT (v
) == 0)
4146 else if (EQ (k
, QCcolor
))
4148 if (!STRINGP (v
) || SCHARS (v
) == 0)
4151 else if (EQ (k
, QCstyle
))
4153 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
4160 valid_p
= NILP (tem
);
4166 signal_error ("Invalid face box", value
);
4168 old_value
= LFACE_BOX (lface
);
4169 LFACE_BOX (lface
) = value
;
4171 else if (EQ (attr
, QCinverse_video
)
4172 || EQ (attr
, QCreverse_video
))
4174 if (!UNSPECIFIEDP (value
))
4176 CHECK_SYMBOL (value
);
4177 if (!EQ (value
, Qt
) && !NILP (value
))
4178 signal_error ("Invalid inverse-video face attribute value", value
);
4180 old_value
= LFACE_INVERSE (lface
);
4181 LFACE_INVERSE (lface
) = value
;
4183 else if (EQ (attr
, QCforeground
))
4185 if (!UNSPECIFIEDP (value
))
4187 /* Don't check for valid color names here because it depends
4188 on the frame (display) whether the color will be valid
4189 when the face is realized. */
4190 CHECK_STRING (value
);
4191 if (SCHARS (value
) == 0)
4192 signal_error ("Empty foreground color value", value
);
4194 old_value
= LFACE_FOREGROUND (lface
);
4195 LFACE_FOREGROUND (lface
) = value
;
4197 else if (EQ (attr
, QCbackground
))
4199 if (!UNSPECIFIEDP (value
))
4201 /* Don't check for valid color names here because it depends
4202 on the frame (display) whether the color will be valid
4203 when the face is realized. */
4204 CHECK_STRING (value
);
4205 if (SCHARS (value
) == 0)
4206 signal_error ("Empty background color value", value
);
4208 old_value
= LFACE_BACKGROUND (lface
);
4209 LFACE_BACKGROUND (lface
) = value
;
4211 else if (EQ (attr
, QCstipple
))
4213 #ifdef HAVE_X_WINDOWS
4214 if (!UNSPECIFIEDP (value
)
4216 && NILP (Fbitmap_spec_p (value
)))
4217 signal_error ("Invalid stipple attribute", value
);
4218 old_value
= LFACE_STIPPLE (lface
);
4219 LFACE_STIPPLE (lface
) = value
;
4220 #endif /* HAVE_X_WINDOWS */
4222 else if (EQ (attr
, QCwidth
))
4224 if (!UNSPECIFIEDP (value
))
4226 CHECK_SYMBOL (value
);
4227 if (face_numeric_swidth (value
) < 0)
4228 signal_error ("Invalid face width", value
);
4230 old_value
= LFACE_SWIDTH (lface
);
4231 LFACE_SWIDTH (lface
) = value
;
4232 font_related_attr_p
= 1;
4234 else if (EQ (attr
, QCfont
))
4236 #ifdef HAVE_WINDOW_SYSTEM
4237 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
4239 /* Set font-related attributes of the Lisp face from an XLFD
4245 f
= SELECTED_FRAME ();
4247 f
= check_x_frame (frame
);
4249 if (!UNSPECIFIEDP (value
))
4251 CHECK_STRING (value
);
4253 /* VALUE may be a fontset name or an alias of fontset. In
4254 such a case, use the base fontset name. */
4255 tmp
= Fquery_fontset (value
, Qnil
);
4259 if (!set_lface_from_font_name (f
, lface
, value
, 1, 1))
4260 signal_error ("Invalid font or fontset name", value
);
4265 #endif /* HAVE_WINDOW_SYSTEM */
4267 else if (EQ (attr
, QCinherit
))
4270 if (SYMBOLP (value
))
4273 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
4274 if (!SYMBOLP (XCAR (tail
)))
4277 LFACE_INHERIT (lface
) = value
;
4279 signal_error ("Invalid face inheritance", value
);
4281 else if (EQ (attr
, QCbold
))
4283 old_value
= LFACE_WEIGHT (lface
);
4284 LFACE_WEIGHT (lface
) = NILP (value
) ? Qnormal
: Qbold
;
4285 font_related_attr_p
= 1;
4287 else if (EQ (attr
, QCitalic
))
4289 old_value
= LFACE_SLANT (lface
);
4290 LFACE_SLANT (lface
) = NILP (value
) ? Qnormal
: Qitalic
;
4291 font_related_attr_p
= 1;
4294 signal_error ("Invalid face attribute name", attr
);
4296 if (font_related_attr_p
4297 && !UNSPECIFIEDP (value
))
4298 /* If a font-related attribute other than QCfont is specified, the
4299 original `font' attribute nor that of default face is useless
4300 to determine a new font. Thus, we set it to nil so that font
4301 selection mechanism doesn't use it. */
4302 LFACE_FONT (lface
) = Qnil
;
4304 /* Changing a named face means that all realized faces depending on
4305 that face are invalid. Since we cannot tell which realized faces
4306 depend on the face, make sure they are all removed. This is done
4307 by incrementing face_change_count. The next call to
4308 init_iterator will then free realized faces. */
4310 && NILP (Fget (face
, Qface_no_inherit
))
4311 && (EQ (attr
, QCfont
)
4312 || NILP (Fequal (old_value
, value
))))
4314 ++face_change_count
;
4315 ++windows_or_buffers_changed
;
4318 if (!UNSPECIFIEDP (value
)
4319 && NILP (Fequal (old_value
, value
)))
4325 if (EQ (face
, Qdefault
))
4327 #ifdef HAVE_WINDOW_SYSTEM
4328 /* Changed font-related attributes of the `default' face are
4329 reflected in changed `font' frame parameters. */
4331 && (font_related_attr_p
|| font_attr_p
)
4332 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
4333 set_font_frame_param (frame
, lface
);
4335 #endif /* HAVE_WINDOW_SYSTEM */
4337 if (EQ (attr
, QCforeground
))
4338 param
= Qforeground_color
;
4339 else if (EQ (attr
, QCbackground
))
4340 param
= Qbackground_color
;
4342 #ifdef HAVE_WINDOW_SYSTEM
4344 else if (EQ (face
, Qscroll_bar
))
4346 /* Changing the colors of `scroll-bar' sets frame parameters
4347 `scroll-bar-foreground' and `scroll-bar-background'. */
4348 if (EQ (attr
, QCforeground
))
4349 param
= Qscroll_bar_foreground
;
4350 else if (EQ (attr
, QCbackground
))
4351 param
= Qscroll_bar_background
;
4353 #endif /* not WINDOWSNT */
4354 else if (EQ (face
, Qborder
))
4356 /* Changing background color of `border' sets frame parameter
4358 if (EQ (attr
, QCbackground
))
4359 param
= Qborder_color
;
4361 else if (EQ (face
, Qcursor
))
4363 /* Changing background color of `cursor' sets frame parameter
4365 if (EQ (attr
, QCbackground
))
4366 param
= Qcursor_color
;
4368 else if (EQ (face
, Qmouse
))
4370 /* Changing background color of `mouse' sets frame parameter
4372 if (EQ (attr
, QCbackground
))
4373 param
= Qmouse_color
;
4375 #endif /* HAVE_WINDOW_SYSTEM */
4376 else if (EQ (face
, Qmenu
))
4378 /* Indicate that we have to update the menu bar when
4379 realizing faces on FRAME. FRAME t change the
4380 default for new frames. We do this by setting
4381 setting the flag in new face caches */
4384 struct frame
*f
= XFRAME (frame
);
4385 if (FRAME_FACE_CACHE (f
) == NULL
)
4386 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
4387 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 1;
4390 menu_face_changed_default
= 1;
4396 /* Update `default-frame-alist', which is used for new frames. */
4398 store_in_alist (&Vdefault_frame_alist
, param
, value
);
4401 /* Update the current frame's parameters. */
4404 cons
= XCAR (Vparam_value_alist
);
4405 XSETCAR (cons
, param
);
4406 XSETCDR (cons
, value
);
4407 Fmodify_frame_parameters (frame
, Vparam_value_alist
);
4416 #ifdef HAVE_WINDOW_SYSTEM
4418 /* Set the `font' frame parameter of FRAME determined from `default'
4419 face attributes LFACE. If a face or fontset name is explicitely
4420 specfied in LFACE, use it as is. Otherwise, determine a font name
4421 from the other font-related atrributes of LFACE. In that case, if
4422 there's no matching font, signals an error. */
4425 set_font_frame_param (frame
, lface
)
4426 Lisp_Object frame
, lface
;
4428 struct frame
*f
= XFRAME (frame
);
4430 if (FRAME_WINDOW_P (f
))
4432 Lisp_Object font_name
;
4435 if (STRINGP (LFACE_FONT (lface
)))
4436 font_name
= LFACE_FONT (lface
);
4439 /* Choose a font name that reflects LFACE's attributes and has
4440 the registry and encoding pattern specified in the default
4441 fontset (3rd arg: -1) for ASCII characters (4th arg: 0). */
4442 font
= choose_face_font (f
, XVECTOR (lface
)->contents
, -1, 0, 0);
4444 error ("No font matches the specified attribute");
4445 font_name
= build_string (font
);
4449 f
->default_face_done_p
= 0;
4450 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, font_name
), Qnil
));
4455 /* Update the corresponding face when frame parameter PARAM on frame F
4456 has been assigned the value NEW_VALUE. */
4459 update_face_from_frame_parameter (f
, param
, new_value
)
4461 Lisp_Object param
, new_value
;
4463 Lisp_Object face
= Qnil
;
4466 /* If there are no faces yet, give up. This is the case when called
4467 from Fx_create_frame, and we do the necessary things later in
4468 face-set-after-frame-defaults. */
4469 if (NILP (f
->face_alist
))
4472 if (EQ (param
, Qforeground_color
))
4475 lface
= lface_from_face_name (f
, face
, 1);
4476 LFACE_FOREGROUND (lface
) = (STRINGP (new_value
)
4477 ? new_value
: Qunspecified
);
4478 realize_basic_faces (f
);
4480 else if (EQ (param
, Qbackground_color
))
4484 /* Changing the background color might change the background
4485 mode, so that we have to load new defface specs. Call
4486 frame-update-face-colors to do that. */
4487 XSETFRAME (frame
, f
);
4488 call1 (Qframe_update_face_colors
, frame
);
4491 lface
= lface_from_face_name (f
, face
, 1);
4492 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4493 ? new_value
: Qunspecified
);
4494 realize_basic_faces (f
);
4496 else if (EQ (param
, Qborder_color
))
4499 lface
= lface_from_face_name (f
, face
, 1);
4500 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4501 ? new_value
: Qunspecified
);
4503 else if (EQ (param
, Qcursor_color
))
4506 lface
= lface_from_face_name (f
, face
, 1);
4507 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4508 ? new_value
: Qunspecified
);
4510 else if (EQ (param
, Qmouse_color
))
4513 lface
= lface_from_face_name (f
, face
, 1);
4514 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4515 ? new_value
: Qunspecified
);
4518 /* Changing a named face means that all realized faces depending on
4519 that face are invalid. Since we cannot tell which realized faces
4520 depend on the face, make sure they are all removed. This is done
4521 by incrementing face_change_count. The next call to
4522 init_iterator will then free realized faces. */
4524 && NILP (Fget (face
, Qface_no_inherit
)))
4526 ++face_change_count
;
4527 ++windows_or_buffers_changed
;
4532 /* Get the value of X resource RESOURCE, class CLASS for the display
4533 of frame FRAME. This is here because ordinary `x-get-resource'
4534 doesn't take a frame argument. */
4536 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
4537 Sinternal_face_x_get_resource
, 3, 3, 0, doc
: /* */)
4538 (resource
, class, frame
)
4539 Lisp_Object resource
, class, frame
;
4541 Lisp_Object value
= Qnil
;
4542 CHECK_STRING (resource
);
4543 CHECK_STRING (class);
4544 CHECK_LIVE_FRAME (frame
);
4546 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame
)),
4547 resource
, class, Qnil
, Qnil
);
4553 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
4554 If VALUE is "on" or "true", return t. If VALUE is "off" or
4555 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
4556 error; if SIGNAL_P is zero, return 0. */
4559 face_boolean_x_resource_value (value
, signal_p
)
4563 Lisp_Object result
= make_number (0);
4565 xassert (STRINGP (value
));
4567 if (xstricmp (SDATA (value
), "on") == 0
4568 || xstricmp (SDATA (value
), "true") == 0)
4570 else if (xstricmp (SDATA (value
), "off") == 0
4571 || xstricmp (SDATA (value
), "false") == 0)
4573 else if (xstricmp (SDATA (value
), "unspecified") == 0)
4574 result
= Qunspecified
;
4576 signal_error ("Invalid face attribute value from X resource", value
);
4582 DEFUN ("internal-set-lisp-face-attribute-from-resource",
4583 Finternal_set_lisp_face_attribute_from_resource
,
4584 Sinternal_set_lisp_face_attribute_from_resource
,
4585 3, 4, 0, doc
: /* */)
4586 (face
, attr
, value
, frame
)
4587 Lisp_Object face
, attr
, value
, frame
;
4589 CHECK_SYMBOL (face
);
4590 CHECK_SYMBOL (attr
);
4591 CHECK_STRING (value
);
4593 if (xstricmp (SDATA (value
), "unspecified") == 0)
4594 value
= Qunspecified
;
4595 else if (EQ (attr
, QCheight
))
4597 value
= Fstring_to_number (value
, make_number (10));
4598 if (XINT (value
) <= 0)
4599 signal_error ("Invalid face height from X resource", value
);
4601 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
4602 value
= face_boolean_x_resource_value (value
, 1);
4603 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
4604 value
= intern (SDATA (value
));
4605 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
4606 value
= face_boolean_x_resource_value (value
, 1);
4607 else if (EQ (attr
, QCunderline
)
4608 || EQ (attr
, QCoverline
)
4609 || EQ (attr
, QCstrike_through
))
4611 Lisp_Object boolean_value
;
4613 /* If the result of face_boolean_x_resource_value is t or nil,
4614 VALUE does NOT specify a color. */
4615 boolean_value
= face_boolean_x_resource_value (value
, 0);
4616 if (SYMBOLP (boolean_value
))
4617 value
= boolean_value
;
4619 else if (EQ (attr
, QCbox
))
4620 value
= Fcar (Fread_from_string (value
, Qnil
, Qnil
));
4622 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
4625 #endif /* HAVE_WINDOW_SYSTEM */
4628 /***********************************************************************
4630 ***********************************************************************/
4632 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
4634 /* Make menus on frame F appear as specified by the `menu' face. */
4637 x_update_menu_appearance (f
)
4640 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
4644 && (rdb
= XrmGetDatabase (FRAME_X_DISPLAY (f
)),
4648 Lisp_Object lface
= lface_from_face_name (f
, Qmenu
, 1);
4649 struct face
*face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
4650 const char *myname
= SDATA (Vx_resource_name
);
4653 const char *popup_path
= "popup_menu";
4655 const char *popup_path
= "menu.popup";
4658 if (STRINGP (LFACE_FOREGROUND (lface
)))
4660 sprintf (line
, "%s.%s*foreground: %s",
4662 SDATA (LFACE_FOREGROUND (lface
)));
4663 XrmPutLineResource (&rdb
, line
);
4664 sprintf (line
, "%s.pane.menubar*foreground: %s",
4665 myname
, SDATA (LFACE_FOREGROUND (lface
)));
4666 XrmPutLineResource (&rdb
, line
);
4670 if (STRINGP (LFACE_BACKGROUND (lface
)))
4672 sprintf (line
, "%s.%s*background: %s",
4674 SDATA (LFACE_BACKGROUND (lface
)));
4675 XrmPutLineResource (&rdb
, line
);
4676 sprintf (line
, "%s.pane.menubar*background: %s",
4677 myname
, SDATA (LFACE_BACKGROUND (lface
)));
4678 XrmPutLineResource (&rdb
, line
);
4683 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
4684 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
4685 || !UNSPECIFIEDP (LFACE_AVGWIDTH (lface
))
4686 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
4687 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
4688 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
4691 const char *suffix
= "List";
4693 const char *suffix
= "";
4695 sprintf (line
, "%s.pane.menubar*font%s: %s",
4696 myname
, suffix
, face
->font_name
);
4697 XrmPutLineResource (&rdb
, line
);
4698 sprintf (line
, "%s.%s*font%s: %s",
4699 myname
, popup_path
, suffix
, face
->font_name
);
4700 XrmPutLineResource (&rdb
, line
);
4704 if (changed_p
&& f
->output_data
.x
->menubar_widget
)
4705 free_frame_menubar (f
);
4709 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
4712 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p
,
4713 Sface_attribute_relative_p
,
4715 doc
: /* Return non-nil if face ATTRIBUTE VALUE is relative. */)
4717 Lisp_Object attribute
, value
;
4719 if (EQ (value
, Qunspecified
))
4721 else if (EQ (attribute
, QCheight
))
4722 return INTEGERP (value
) ? Qnil
: Qt
;
4727 DEFUN ("merge-face-attribute", Fmerge_face_attribute
, Smerge_face_attribute
,
4729 doc
: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
4730 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
4731 the result will be absolute, otherwise it will be relative. */)
4732 (attribute
, value1
, value2
)
4733 Lisp_Object attribute
, value1
, value2
;
4735 if (EQ (value1
, Qunspecified
))
4737 else if (EQ (attribute
, QCheight
))
4738 return merge_face_heights (value1
, value2
, value1
);
4744 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
4745 Sinternal_get_lisp_face_attribute
,
4747 doc
: /* Return face attribute KEYWORD of face SYMBOL.
4748 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
4749 face attribute name, signal an error.
4750 If the optional argument FRAME is given, report on face SYMBOL in that
4751 frame. If FRAME is t, report on the defaults for face SYMBOL (for new
4752 frames). If FRAME is omitted or nil, use the selected frame. */)
4753 (symbol
, keyword
, frame
)
4754 Lisp_Object symbol
, keyword
, frame
;
4756 Lisp_Object lface
, value
= Qnil
;
4758 CHECK_SYMBOL (symbol
);
4759 CHECK_SYMBOL (keyword
);
4762 lface
= lface_from_face_name (NULL
, symbol
, 1);
4766 frame
= selected_frame
;
4767 CHECK_LIVE_FRAME (frame
);
4768 lface
= lface_from_face_name (XFRAME (frame
), symbol
, 1);
4771 if (EQ (keyword
, QCfamily
))
4772 value
= LFACE_FAMILY (lface
);
4773 else if (EQ (keyword
, QCheight
))
4774 value
= LFACE_HEIGHT (lface
);
4775 else if (EQ (keyword
, QCweight
))
4776 value
= LFACE_WEIGHT (lface
);
4777 else if (EQ (keyword
, QCslant
))
4778 value
= LFACE_SLANT (lface
);
4779 else if (EQ (keyword
, QCunderline
))
4780 value
= LFACE_UNDERLINE (lface
);
4781 else if (EQ (keyword
, QCoverline
))
4782 value
= LFACE_OVERLINE (lface
);
4783 else if (EQ (keyword
, QCstrike_through
))
4784 value
= LFACE_STRIKE_THROUGH (lface
);
4785 else if (EQ (keyword
, QCbox
))
4786 value
= LFACE_BOX (lface
);
4787 else if (EQ (keyword
, QCinverse_video
)
4788 || EQ (keyword
, QCreverse_video
))
4789 value
= LFACE_INVERSE (lface
);
4790 else if (EQ (keyword
, QCforeground
))
4791 value
= LFACE_FOREGROUND (lface
);
4792 else if (EQ (keyword
, QCbackground
))
4793 value
= LFACE_BACKGROUND (lface
);
4794 else if (EQ (keyword
, QCstipple
))
4795 value
= LFACE_STIPPLE (lface
);
4796 else if (EQ (keyword
, QCwidth
))
4797 value
= LFACE_SWIDTH (lface
);
4798 else if (EQ (keyword
, QCinherit
))
4799 value
= LFACE_INHERIT (lface
);
4800 else if (EQ (keyword
, QCfont
))
4801 value
= LFACE_FONT (lface
);
4803 signal_error ("Invalid face attribute name", keyword
);
4809 DEFUN ("internal-lisp-face-attribute-values",
4810 Finternal_lisp_face_attribute_values
,
4811 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
4812 doc
: /* Return a list of valid discrete values for face attribute ATTR.
4813 Value is nil if ATTR doesn't have a discrete set of valid values. */)
4817 Lisp_Object result
= Qnil
;
4819 CHECK_SYMBOL (attr
);
4821 if (EQ (attr
, QCweight
)
4822 || EQ (attr
, QCslant
)
4823 || EQ (attr
, QCwidth
))
4825 /* Extract permissible symbols from tables. */
4826 struct table_entry
*table
;
4829 if (EQ (attr
, QCweight
))
4830 table
= weight_table
, dim
= DIM (weight_table
);
4831 else if (EQ (attr
, QCslant
))
4832 table
= slant_table
, dim
= DIM (slant_table
);
4834 table
= swidth_table
, dim
= DIM (swidth_table
);
4836 for (i
= 0; i
< dim
; ++i
)
4838 Lisp_Object symbol
= *table
[i
].symbol
;
4839 Lisp_Object tail
= result
;
4842 && !EQ (XCAR (tail
), symbol
))
4846 result
= Fcons (symbol
, result
);
4849 else if (EQ (attr
, QCunderline
))
4850 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4851 else if (EQ (attr
, QCoverline
))
4852 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4853 else if (EQ (attr
, QCstrike_through
))
4854 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4855 else if (EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
4856 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4862 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
4863 Sinternal_merge_in_global_face
, 2, 2, 0,
4864 doc
: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
4865 Default face attributes override any local face attributes. */)
4867 Lisp_Object face
, frame
;
4870 Lisp_Object global_lface
, local_lface
, *gvec
, *lvec
;
4872 CHECK_LIVE_FRAME (frame
);
4873 global_lface
= lface_from_face_name (NULL
, face
, 1);
4874 local_lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
4875 if (NILP (local_lface
))
4876 local_lface
= Finternal_make_lisp_face (face
, frame
);
4878 /* Make every specified global attribute override the local one.
4879 BEWARE!! This is only used from `face-set-after-frame-default' where
4880 the local frame is defined from default specs in `face-defface-spec'
4881 and those should be overridden by global settings. Hence the strange
4882 "global before local" priority. */
4883 lvec
= XVECTOR (local_lface
)->contents
;
4884 gvec
= XVECTOR (global_lface
)->contents
;
4885 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4886 if (! UNSPECIFIEDP (gvec
[i
]))
4893 /* The following function is implemented for compatibility with 20.2.
4894 The function is used in x-resolve-fonts when it is asked to
4895 return fonts with the same size as the font of a face. This is
4896 done in fontset.el. */
4898 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 2, 0,
4899 doc
: /* Return the font name of face FACE, or nil if it is unspecified.
4900 If the optional argument FRAME is given, report on face FACE in that frame.
4901 If FRAME is t, report on the defaults for face FACE (for new frames).
4902 The font default for a face is either nil, or a list
4903 of the form (bold), (italic) or (bold italic).
4904 If FRAME is omitted or nil, use the selected frame. */)
4906 Lisp_Object face
, frame
;
4910 Lisp_Object result
= Qnil
;
4911 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
4913 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
4914 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
4915 result
= Fcons (Qbold
, result
);
4917 if (!UNSPECIFIEDP (LFACE_SLANT (lface
))
4918 && !EQ (LFACE_SLANT (lface
), Qnormal
))
4919 result
= Fcons (Qitalic
, result
);
4925 struct frame
*f
= frame_or_selected_frame (frame
, 1);
4926 int face_id
= lookup_named_face (f
, face
, 0, 1);
4927 struct face
*face
= FACE_FROM_ID (f
, face_id
);
4928 return face
? build_string (face
->font_name
) : Qnil
;
4933 /* Compare face-attribute values v1 and v2 for equality. Value is non-zero if
4934 all attributes are `equal'. Tries to be fast because this function
4935 is called quite often. */
4938 face_attr_equal_p (v1
, v2
)
4941 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
4942 and the other is specified. */
4943 if (XTYPE (v1
) != XTYPE (v2
))
4952 if (SBYTES (v1
) != SBYTES (v2
))
4955 return bcmp (SDATA (v1
), SDATA (v2
), SBYTES (v1
)) == 0;
4962 return !NILP (Fequal (v1
, v2
));
4967 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
4968 all attributes are `equal'. Tries to be fast because this function
4969 is called quite often. */
4972 lface_equal_p (v1
, v2
)
4973 Lisp_Object
*v1
, *v2
;
4977 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
4978 equal_p
= face_attr_equal_p (v1
[i
], v2
[i
]);
4984 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
4985 Sinternal_lisp_face_equal_p
, 2, 3, 0,
4986 doc
: /* True if FACE1 and FACE2 are equal.
4987 If the optional argument FRAME is given, report on face FACE in that frame.
4988 If FRAME is t, report on the defaults for face FACE (for new frames).
4989 If FRAME is omitted or nil, use the selected frame. */)
4990 (face1
, face2
, frame
)
4991 Lisp_Object face1
, face2
, frame
;
4995 Lisp_Object lface1
, lface2
;
5000 /* Don't use check_x_frame here because this function is called
5001 before X frames exist. At that time, if FRAME is nil,
5002 selected_frame will be used which is the frame dumped with
5003 Emacs. That frame is not an X frame. */
5004 f
= frame_or_selected_frame (frame
, 2);
5006 lface1
= lface_from_face_name (NULL
, face1
, 1);
5007 lface2
= lface_from_face_name (NULL
, face2
, 1);
5008 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
5009 XVECTOR (lface2
)->contents
);
5010 return equal_p
? Qt
: Qnil
;
5014 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
5015 Sinternal_lisp_face_empty_p
, 1, 2, 0,
5016 doc
: /* True if FACE has no attribute specified.
5017 If the optional argument FRAME is given, report on face FACE in that frame.
5018 If FRAME is t, report on the defaults for face FACE (for new frames).
5019 If FRAME is omitted or nil, use the selected frame. */)
5021 Lisp_Object face
, frame
;
5028 frame
= selected_frame
;
5029 CHECK_LIVE_FRAME (frame
);
5033 lface
= lface_from_face_name (NULL
, face
, 1);
5035 lface
= lface_from_face_name (f
, face
, 1);
5037 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
5038 if (!UNSPECIFIEDP (AREF (lface
, i
)))
5041 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
5045 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
5047 doc
: /* Return an alist of frame-local faces defined on FRAME.
5048 For internal use only. */)
5052 struct frame
*f
= frame_or_selected_frame (frame
, 0);
5053 return f
->face_alist
;
5057 /* Return a hash code for Lisp string STRING with case ignored. Used
5058 below in computing a hash value for a Lisp face. */
5060 static INLINE
unsigned
5061 hash_string_case_insensitive (string
)
5064 const unsigned char *s
;
5066 xassert (STRINGP (string
));
5067 for (s
= SDATA (string
); *s
; ++s
)
5068 hash
= (hash
<< 1) ^ tolower (*s
);
5073 /* Return a hash code for face attribute vector V. */
5075 static INLINE
unsigned
5079 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
5080 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
5081 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
5082 ^ XFASTINT (v
[LFACE_WEIGHT_INDEX
])
5083 ^ XFASTINT (v
[LFACE_SLANT_INDEX
])
5084 ^ XFASTINT (v
[LFACE_SWIDTH_INDEX
])
5085 ^ XFASTINT (v
[LFACE_HEIGHT_INDEX
]));
5089 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
5090 considering charsets/registries). They do if they specify the same
5091 family, point size, weight, width, slant, and fontset. Both LFACE1
5092 and LFACE2 must be fully-specified. */
5095 lface_same_font_attributes_p (lface1
, lface2
)
5096 Lisp_Object
*lface1
, *lface2
;
5098 xassert (lface_fully_specified_p (lface1
)
5099 && lface_fully_specified_p (lface2
));
5100 return (xstricmp (SDATA (lface1
[LFACE_FAMILY_INDEX
]),
5101 SDATA (lface2
[LFACE_FAMILY_INDEX
])) == 0
5102 && EQ (lface1
[LFACE_HEIGHT_INDEX
], lface2
[LFACE_HEIGHT_INDEX
])
5103 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
5104 && EQ (lface1
[LFACE_AVGWIDTH_INDEX
], lface2
[LFACE_AVGWIDTH_INDEX
])
5105 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
5106 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
])
5107 && (EQ (lface1
[LFACE_FONT_INDEX
], lface2
[LFACE_FONT_INDEX
])
5108 || (STRINGP (lface1
[LFACE_FONT_INDEX
])
5109 && STRINGP (lface2
[LFACE_FONT_INDEX
])
5110 && xstricmp (SDATA (lface1
[LFACE_FONT_INDEX
]),
5111 SDATA (lface2
[LFACE_FONT_INDEX
])))));
5116 /***********************************************************************
5118 ***********************************************************************/
5120 /* Allocate and return a new realized face for Lisp face attribute
5123 static struct face
*
5124 make_realized_face (attr
)
5127 struct face
*face
= (struct face
*) xmalloc (sizeof *face
);
5128 bzero (face
, sizeof *face
);
5129 face
->ascii_face
= face
;
5130 bcopy (attr
, face
->lface
, sizeof face
->lface
);
5135 /* Free realized face FACE, including its X resources. FACE may
5139 free_realized_face (f
, face
)
5145 #ifdef HAVE_WINDOW_SYSTEM
5146 if (FRAME_WINDOW_P (f
))
5148 /* Free fontset of FACE if it is ASCII face. */
5149 if (face
->fontset
>= 0 && face
== face
->ascii_face
)
5150 free_face_fontset (f
, face
);
5153 x_free_gc (f
, face
->gc
);
5157 free_face_colors (f
, face
);
5158 x_destroy_bitmap (f
, face
->stipple
);
5160 #endif /* HAVE_WINDOW_SYSTEM */
5167 /* Prepare face FACE for subsequent display on frame F. This
5168 allocated GCs if they haven't been allocated yet or have been freed
5169 by clearing the face cache. */
5172 prepare_face_for_display (f
, face
)
5176 #ifdef HAVE_WINDOW_SYSTEM
5177 xassert (FRAME_WINDOW_P (f
));
5182 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
5184 xgcv
.foreground
= face
->foreground
;
5185 xgcv
.background
= face
->background
;
5186 #ifdef HAVE_X_WINDOWS
5187 xgcv
.graphics_exposures
= False
;
5189 /* The font of FACE may be null if we couldn't load it. */
5192 #ifdef HAVE_X_WINDOWS
5193 xgcv
.font
= face
->font
->fid
;
5196 xgcv
.font
= face
->font
;
5199 xgcv
.font
= face
->font
;
5205 #ifdef HAVE_X_WINDOWS
5208 xgcv
.fill_style
= FillOpaqueStippled
;
5209 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
5210 mask
|= GCFillStyle
| GCStipple
;
5213 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
5216 #endif /* HAVE_WINDOW_SYSTEM */
5220 /* Returns the `distance' between the colors X and Y. */
5223 color_distance (x
, y
)
5226 /* This formula is from a paper title `Colour metric' by Thiadmer Riemersma.
5227 Quoting from that paper:
5229 This formula has results that are very close to L*u*v* (with the
5230 modified lightness curve) and, more importantly, it is a more even
5231 algorithm: it does not have a range of colours where it suddenly
5232 gives far from optimal results.
5234 See <http://www.compuphase.com/cmetric.htm> for more info. */
5236 long r
= (x
->red
- y
->red
) >> 8;
5237 long g
= (x
->green
- y
->green
) >> 8;
5238 long b
= (x
->blue
- y
->blue
) >> 8;
5239 long r_mean
= (x
->red
+ y
->red
) >> 9;
5242 (((512 + r_mean
) * r
* r
) >> 8)
5244 + (((767 - r_mean
) * b
* b
) >> 8);
5248 DEFUN ("color-distance", Fcolor_distance
, Scolor_distance
, 2, 3, 0,
5249 doc
: /* Return an integer distance between COLOR1 and COLOR2 on FRAME.
5250 COLOR1 and COLOR2 may be either strings containing the color name,
5251 or lists of the form (RED GREEN BLUE).
5252 If FRAME is unspecified or nil, the current frame is used. */)
5253 (color1
, color2
, frame
)
5254 Lisp_Object color1
, color2
, frame
;
5257 XColor cdef1
, cdef2
;
5260 frame
= selected_frame
;
5261 CHECK_LIVE_FRAME (frame
);
5264 if ((CONSP (color1
) && !parse_rgb_list (color1
, &cdef1
))
5265 || !STRINGP (color1
)
5266 || !defined_color (f
, SDATA (color1
), &cdef1
, 0))
5267 signal_error ("Invalid color", color1
);
5268 if ((CONSP (color2
) && !parse_rgb_list (color2
, &cdef2
))
5269 || !STRINGP (color2
)
5270 || !defined_color (f
, SDATA (color2
), &cdef2
, 0))
5271 signal_error ("Invalid color", color2
);
5273 return make_number (color_distance (&cdef1
, &cdef2
));
5277 /***********************************************************************
5279 ***********************************************************************/
5281 /* Return a new face cache for frame F. */
5283 static struct face_cache
*
5287 struct face_cache
*c
;
5290 c
= (struct face_cache
*) xmalloc (sizeof *c
);
5291 bzero (c
, sizeof *c
);
5292 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
5293 c
->buckets
= (struct face
**) xmalloc (size
);
5294 bzero (c
->buckets
, size
);
5296 c
->faces_by_id
= (struct face
**) xmalloc (c
->size
* sizeof *c
->faces_by_id
);
5298 c
->menu_face_changed_p
= menu_face_changed_default
;
5303 /* Clear out all graphics contexts for all realized faces, except for
5304 the basic faces. This should be done from time to time just to avoid
5305 keeping too many graphics contexts that are no longer needed. */
5309 struct face_cache
*c
;
5311 if (c
&& FRAME_WINDOW_P (c
->f
))
5313 #ifdef HAVE_WINDOW_SYSTEM
5315 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
5317 struct face
*face
= c
->faces_by_id
[i
];
5318 if (face
&& face
->gc
)
5320 x_free_gc (c
->f
, face
->gc
);
5324 #endif /* HAVE_WINDOW_SYSTEM */
5329 /* Free all realized faces in face cache C, including basic faces.
5330 C may be null. If faces are freed, make sure the frame's current
5331 matrix is marked invalid, so that a display caused by an expose
5332 event doesn't try to use faces we destroyed. */
5335 free_realized_faces (c
)
5336 struct face_cache
*c
;
5341 struct frame
*f
= c
->f
;
5343 /* We must block input here because we can't process X events
5344 safely while only some faces are freed, or when the frame's
5345 current matrix still references freed faces. */
5348 for (i
= 0; i
< c
->used
; ++i
)
5350 free_realized_face (f
, c
->faces_by_id
[i
]);
5351 c
->faces_by_id
[i
] = NULL
;
5355 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
5356 bzero (c
->buckets
, size
);
5358 /* Must do a thorough redisplay the next time. Mark current
5359 matrices as invalid because they will reference faces freed
5360 above. This function is also called when a frame is
5361 destroyed. In this case, the root window of F is nil. */
5362 if (WINDOWP (f
->root_window
))
5364 clear_current_matrices (f
);
5365 ++windows_or_buffers_changed
;
5373 /* Free all faces realized for multibyte characters on frame F that
5377 free_realized_multibyte_face (f
, fontset
)
5381 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5385 /* We must block input here because we can't process X events safely
5386 while only some faces are freed, or when the frame's current
5387 matrix still references freed faces. */
5390 for (i
= 0; i
< cache
->used
; i
++)
5392 face
= cache
->faces_by_id
[i
];
5394 && face
!= face
->ascii_face
5395 && face
->fontset
== fontset
)
5397 uncache_face (cache
, face
);
5398 free_realized_face (f
, face
);
5402 /* Must do a thorough redisplay the next time. Mark current
5403 matrices as invalid because they will reference faces freed
5404 above. This function is also called when a frame is destroyed.
5405 In this case, the root window of F is nil. */
5406 if (WINDOWP (f
->root_window
))
5408 clear_current_matrices (f
);
5409 ++windows_or_buffers_changed
;
5416 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
5417 This is done after attributes of a named face have been changed,
5418 because we can't tell which realized faces depend on that face. */
5421 free_all_realized_faces (frame
)
5427 FOR_EACH_FRAME (rest
, frame
)
5428 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
5431 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
5435 /* Free face cache C and faces in it, including their X resources. */
5439 struct face_cache
*c
;
5443 free_realized_faces (c
);
5445 xfree (c
->faces_by_id
);
5451 /* Cache realized face FACE in face cache C. HASH is the hash value
5452 of FACE. If FACE->fontset >= 0, add the new face to the end of the
5453 collision list of the face hash table of C. This is done because
5454 otherwise lookup_face would find FACE for every character, even if
5455 faces with the same attributes but for specific characters exist. */
5458 cache_face (c
, face
, hash
)
5459 struct face_cache
*c
;
5463 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
5467 if (face
->fontset
>= 0)
5469 struct face
*last
= c
->buckets
[i
];
5480 c
->buckets
[i
] = face
;
5481 face
->prev
= face
->next
= NULL
;
5487 face
->next
= c
->buckets
[i
];
5489 face
->next
->prev
= face
;
5490 c
->buckets
[i
] = face
;
5493 /* Find a free slot in C->faces_by_id and use the index of the free
5494 slot as FACE->id. */
5495 for (i
= 0; i
< c
->used
; ++i
)
5496 if (c
->faces_by_id
[i
] == NULL
)
5500 /* Maybe enlarge C->faces_by_id. */
5503 if (c
->used
== c
->size
)
5506 new_size
= min (2 * c
->size
, MAX_FACE_ID
);
5507 if (new_size
== c
->size
)
5508 abort (); /* Alternatives? ++kfs */
5509 sz
= new_size
* sizeof *c
->faces_by_id
;
5510 c
->faces_by_id
= (struct face
**) xrealloc (c
->faces_by_id
, sz
);
5517 /* Check that FACE got a unique id. */
5522 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
5523 for (face
= c
->buckets
[j
]; face
; face
= face
->next
)
5529 #endif /* GLYPH_DEBUG */
5531 c
->faces_by_id
[i
] = face
;
5535 /* Remove face FACE from cache C. */
5538 uncache_face (c
, face
)
5539 struct face_cache
*c
;
5542 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
5545 face
->prev
->next
= face
->next
;
5547 c
->buckets
[i
] = face
->next
;
5550 face
->next
->prev
= face
->prev
;
5552 c
->faces_by_id
[face
->id
] = NULL
;
5553 if (face
->id
== c
->used
)
5558 /* Look up a realized face with face attributes ATTR in the face cache
5559 of frame F. The face will be used to display character C. Value
5560 is the ID of the face found. If no suitable face is found, realize
5561 a new one. In that case, if C is a multibyte character, BASE_FACE
5562 is a face that has the same attributes. */
5565 lookup_face (f
, attr
, c
, base_face
)
5569 struct face
*base_face
;
5571 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5576 xassert (cache
!= NULL
);
5577 check_lface_attrs (attr
);
5579 /* Look up ATTR in the face cache. */
5580 hash
= lface_hash (attr
);
5581 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
5583 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
5584 if (face
->hash
== hash
5585 && (!FRAME_WINDOW_P (f
)
5586 || FACE_SUITABLE_FOR_CHAR_P (face
, c
))
5587 && lface_equal_p (face
->lface
, attr
))
5590 /* If not found, realize a new face. */
5592 face
= realize_face (cache
, attr
, c
, base_face
, -1);
5595 xassert (face
== FACE_FROM_ID (f
, face
->id
));
5597 /* When this function is called from face_for_char (in this case, C is
5598 a multibyte character), a fontset of a face returned by
5599 realize_face is not yet set, i.e. FACE_SUITABLE_FOR_CHAR_P (FACE,
5600 C) is not sutisfied. The fontset is set for this face by
5601 face_for_char later. */
5603 if (FRAME_WINDOW_P (f
))
5604 xassert (FACE_SUITABLE_FOR_CHAR_P (face
, c
));
5606 #endif /* GLYPH_DEBUG */
5612 /* Return the face id of the realized face for named face SYMBOL on
5613 frame F suitable for displaying character C. Value is -1 if the
5614 face couldn't be determined, which might happen if the default face
5615 isn't realized and cannot be realized. */
5618 lookup_named_face (f
, symbol
, c
, signal_p
)
5624 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5625 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5626 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5628 if (default_face
== NULL
)
5630 if (!realize_basic_faces (f
))
5632 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5635 if (!get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
))
5638 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
5639 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
5641 return lookup_face (f
, attrs
, c
, NULL
);
5645 /* Return the ID of the realized ASCII face of Lisp face with ID
5646 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
5649 ascii_face_of_lisp_face (f
, lface_id
)
5655 if (lface_id
>= 0 && lface_id
< lface_id_to_name_size
)
5657 Lisp_Object face_name
= lface_id_to_name
[lface_id
];
5658 face_id
= lookup_named_face (f
, face_name
, 0, 1);
5667 /* Return a face for charset ASCII that is like the face with id
5668 FACE_ID on frame F, but has a font that is STEPS steps smaller.
5669 STEPS < 0 means larger. Value is the id of the face. */
5672 smaller_face (f
, face_id
, steps
)
5676 #ifdef HAVE_WINDOW_SYSTEM
5678 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5679 int pt
, last_pt
, last_height
;
5682 struct face
*new_face
;
5684 /* If not called for an X frame, just return the original face. */
5685 if (FRAME_TERMCAP_P (f
))
5688 /* Try in increments of 1/2 pt. */
5689 delta
= steps
< 0 ? 5 : -5;
5690 steps
= abs (steps
);
5692 face
= FACE_FROM_ID (f
, face_id
);
5693 bcopy (face
->lface
, attrs
, sizeof attrs
);
5694 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
5695 new_face_id
= face_id
;
5696 last_height
= FONT_HEIGHT (face
->font
);
5700 /* Give up if we cannot find a font within 10pt. */
5701 && abs (last_pt
- pt
) < 100)
5703 /* Look up a face for a slightly smaller/larger font. */
5705 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
5706 new_face_id
= lookup_face (f
, attrs
, 0, NULL
);
5707 new_face
= FACE_FROM_ID (f
, new_face_id
);
5709 /* If height changes, count that as one step. */
5710 if ((delta
< 0 && FONT_HEIGHT (new_face
->font
) < last_height
)
5711 || (delta
> 0 && FONT_HEIGHT (new_face
->font
) > last_height
))
5714 last_height
= FONT_HEIGHT (new_face
->font
);
5721 #else /* not HAVE_WINDOW_SYSTEM */
5725 #endif /* not HAVE_WINDOW_SYSTEM */
5729 /* Return a face for charset ASCII that is like the face with id
5730 FACE_ID on frame F, but has height HEIGHT. */
5733 face_with_height (f
, face_id
, height
)
5738 #ifdef HAVE_WINDOW_SYSTEM
5740 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5742 if (FRAME_TERMCAP_P (f
)
5746 face
= FACE_FROM_ID (f
, face_id
);
5747 bcopy (face
->lface
, attrs
, sizeof attrs
);
5748 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
5749 face_id
= lookup_face (f
, attrs
, 0, NULL
);
5750 #endif /* HAVE_WINDOW_SYSTEM */
5756 /* Return the face id of the realized face for named face SYMBOL on
5757 frame F suitable for displaying character C, and use attributes of
5758 the face FACE_ID for attributes that aren't completely specified by
5759 SYMBOL. This is like lookup_named_face, except that the default
5760 attributes come from FACE_ID, not from the default face. FACE_ID
5761 is assumed to be already realized. */
5764 lookup_derived_face (f
, symbol
, c
, face_id
)
5770 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5771 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5772 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
5777 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
5778 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
5779 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
5780 return lookup_face (f
, attrs
, c
, default_face
);
5783 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector
,
5784 Sface_attributes_as_vector
, 1, 1, 0,
5785 doc
: /* Return a vector of face attributes corresponding to PLIST. */)
5790 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
5792 merge_face_ref (XFRAME (selected_frame
), plist
, XVECTOR (lface
)->contents
,
5799 /***********************************************************************
5800 Face capability testing
5801 ***********************************************************************/
5804 /* If the distance (as returned by color_distance) between two colors is
5805 less than this, then they are considered the same, for determining
5806 whether a color is supported or not. The range of values is 0-65535. */
5808 #define TTY_SAME_COLOR_THRESHOLD 10000
5810 #ifdef HAVE_WINDOW_SYSTEM
5812 /* Return non-zero if all the face attributes in ATTRS are supported
5813 on the window-system frame F.
5815 The definition of `supported' is somewhat heuristic, but basically means
5816 that a face containing all the attributes in ATTRS, when merged with the
5817 default face for display, can be represented in a way that's
5819 \(1) different in appearance than the default face, and
5820 \(2) `close in spirit' to what the attributes specify, if not exact. */
5823 x_supports_face_attributes_p (f
, attrs
, def_face
)
5826 struct face
*def_face
;
5828 Lisp_Object
*def_attrs
= def_face
->lface
;
5830 /* Check that other specified attributes are different that the default
5832 if ((!UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
5833 && face_attr_equal_p (attrs
[LFACE_UNDERLINE_INDEX
],
5834 def_attrs
[LFACE_UNDERLINE_INDEX
]))
5835 || (!UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
5836 && face_attr_equal_p (attrs
[LFACE_INVERSE_INDEX
],
5837 def_attrs
[LFACE_INVERSE_INDEX
]))
5838 || (!UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
5839 && face_attr_equal_p (attrs
[LFACE_FOREGROUND_INDEX
],
5840 def_attrs
[LFACE_FOREGROUND_INDEX
]))
5841 || (!UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
5842 && face_attr_equal_p (attrs
[LFACE_BACKGROUND_INDEX
],
5843 def_attrs
[LFACE_BACKGROUND_INDEX
]))
5844 || (!UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
5845 && face_attr_equal_p (attrs
[LFACE_STIPPLE_INDEX
],
5846 def_attrs
[LFACE_STIPPLE_INDEX
]))
5847 || (!UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
5848 && face_attr_equal_p (attrs
[LFACE_OVERLINE_INDEX
],
5849 def_attrs
[LFACE_OVERLINE_INDEX
]))
5850 || (!UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
5851 && face_attr_equal_p (attrs
[LFACE_STRIKE_THROUGH_INDEX
],
5852 def_attrs
[LFACE_STRIKE_THROUGH_INDEX
]))
5853 || (!UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
5854 && face_attr_equal_p (attrs
[LFACE_BOX_INDEX
],
5855 def_attrs
[LFACE_BOX_INDEX
])))
5858 /* Check font-related attributes, as those are the most commonly
5859 "unsupported" on a window-system (because of missing fonts). */
5860 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
5861 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
5862 || !UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
5863 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
5864 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
5865 || !UNSPECIFIEDP (attrs
[LFACE_AVGWIDTH_INDEX
]))
5868 Lisp_Object merged_attrs
[LFACE_VECTOR_SIZE
];
5870 bcopy (def_attrs
, merged_attrs
, sizeof merged_attrs
);
5872 merge_face_vectors (f
, attrs
, merged_attrs
, 0);
5874 face
= FACE_FROM_ID (f
, lookup_face (f
, merged_attrs
, 0, 0));
5877 error ("cannot make face");
5879 /* If the font is the same, then not supported. */
5880 if (face
->font
== def_face
->font
)
5884 /* Everything checks out, this face is supported. */
5888 #endif /* HAVE_WINDOW_SYSTEM */
5890 /* Return non-zero if all the face attributes in ATTRS are supported
5893 The definition of `supported' is somewhat heuristic, but basically means
5894 that a face containing all the attributes in ATTRS, when merged
5895 with the default face for display, can be represented in a way that's
5897 \(1) different in appearance than the default face, and
5898 \(2) `close in spirit' to what the attributes specify, if not exact.
5900 Point (2) implies that a `:weight black' attribute will be satisfied
5901 by any terminal that can display bold, and a `:foreground "yellow"' as
5902 long as the terminal can display a yellowish color, but `:slant italic'
5903 will _not_ be satisfied by the tty display code's automatic
5904 substitution of a `dim' face for italic. */
5907 tty_supports_face_attributes_p (f
, attrs
, def_face
)
5910 struct face
*def_face
;
5913 Lisp_Object val
, fg
, bg
;
5914 XColor fg_tty_color
, fg_std_color
;
5915 XColor bg_tty_color
, bg_std_color
;
5916 unsigned test_caps
= 0;
5917 Lisp_Object
*def_attrs
= def_face
->lface
;
5920 /* First check some easy-to-check stuff; ttys support none of the
5921 following attributes, so we can just return false if any are requested
5922 (even if `nominal' values are specified, we should still return false,
5923 as that will be the same value that the default face uses). We
5924 consider :slant unsupportable on ttys, even though the face code
5925 actually `fakes' them using a dim attribute if possible. This is
5926 because the faked result is too different from what the face
5928 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
5929 || !UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
5930 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
5931 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
5932 || !UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
5933 || !UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
5934 || !UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
5935 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
]))
5939 /* Test for terminal `capabilities' (non-color character attributes). */
5941 /* font weight (bold/dim) */
5942 weight
= face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
5945 int def_weight
= face_numeric_weight (def_attrs
[LFACE_WEIGHT_INDEX
]);
5947 if (weight
> XLFD_WEIGHT_MEDIUM
)
5949 if (def_weight
> XLFD_WEIGHT_MEDIUM
)
5950 return 0; /* same as default */
5951 test_caps
= TTY_CAP_BOLD
;
5953 else if (weight
< XLFD_WEIGHT_MEDIUM
)
5955 if (def_weight
< XLFD_WEIGHT_MEDIUM
)
5956 return 0; /* same as default */
5957 test_caps
= TTY_CAP_DIM
;
5959 else if (def_weight
== XLFD_WEIGHT_MEDIUM
)
5960 return 0; /* same as default */
5964 val
= attrs
[LFACE_UNDERLINE_INDEX
];
5965 if (!UNSPECIFIEDP (val
))
5968 return 0; /* ttys can't use colored underlines */
5969 else if (face_attr_equal_p (val
, def_attrs
[LFACE_UNDERLINE_INDEX
]))
5970 return 0; /* same as default */
5972 test_caps
|= TTY_CAP_UNDERLINE
;
5976 val
= attrs
[LFACE_INVERSE_INDEX
];
5977 if (!UNSPECIFIEDP (val
))
5979 if (face_attr_equal_p (val
, def_attrs
[LFACE_UNDERLINE_INDEX
]))
5980 return 0; /* same as default */
5982 test_caps
|= TTY_CAP_INVERSE
;
5986 /* Color testing. */
5988 /* Default the color indices in FG_TTY_COLOR and BG_TTY_COLOR, since
5989 we use them when calling `tty_capable_p' below, even if the face
5990 specifies no colors. */
5991 fg_tty_color
.pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5992 bg_tty_color
.pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5994 /* Check if foreground color is close enough. */
5995 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
5998 Lisp_Object def_fg
= def_attrs
[LFACE_FOREGROUND_INDEX
];
6000 if (face_attr_equal_p (fg
, def_fg
))
6001 return 0; /* same as default */
6002 else if (! tty_lookup_color (f
, fg
, &fg_tty_color
, &fg_std_color
))
6003 return 0; /* not a valid color */
6004 else if (color_distance (&fg_tty_color
, &fg_std_color
)
6005 > TTY_SAME_COLOR_THRESHOLD
)
6006 return 0; /* displayed color is too different */
6008 /* Make sure the color is really different than the default. */
6010 XColor def_fg_color
;
6011 if (tty_lookup_color (f
, def_fg
, &def_fg_color
, 0)
6012 && (color_distance (&fg_tty_color
, &def_fg_color
)
6013 <= TTY_SAME_COLOR_THRESHOLD
))
6018 /* Check if background color is close enough. */
6019 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
6022 Lisp_Object def_bg
= def_attrs
[LFACE_FOREGROUND_INDEX
];
6024 if (face_attr_equal_p (bg
, def_bg
))
6025 return 0; /* same as default */
6026 else if (! tty_lookup_color (f
, bg
, &bg_tty_color
, &bg_std_color
))
6027 return 0; /* not a valid color */
6028 else if (color_distance (&bg_tty_color
, &bg_std_color
)
6029 > TTY_SAME_COLOR_THRESHOLD
)
6030 return 0; /* displayed color is too different */
6032 /* Make sure the color is really different than the default. */
6034 XColor def_bg_color
;
6035 if (tty_lookup_color (f
, def_bg
, &def_bg_color
, 0)
6036 && (color_distance (&bg_tty_color
, &def_bg_color
)
6037 <= TTY_SAME_COLOR_THRESHOLD
))
6042 /* If both foreground and background are requested, see if the
6043 distance between them is OK. We just check to see if the distance
6044 between the tty's foreground and background is close enough to the
6045 distance between the standard foreground and background. */
6046 if (STRINGP (fg
) && STRINGP (bg
))
6049 = (color_distance (&fg_std_color
, &bg_std_color
)
6050 - color_distance (&fg_tty_color
, &bg_tty_color
));
6051 if (delta_delta
> TTY_SAME_COLOR_THRESHOLD
6052 || delta_delta
< -TTY_SAME_COLOR_THRESHOLD
)
6057 /* See if the capabilities we selected above are supported, with the
6059 if (test_caps
!= 0 &&
6060 ! tty_capable_p (f
, test_caps
, fg_tty_color
.pixel
, bg_tty_color
.pixel
))
6064 /* Hmmm, everything checks out, this terminal must support this face. */
6069 DEFUN ("display-supports-face-attributes-p",
6070 Fdisplay_supports_face_attributes_p
, Sdisplay_supports_face_attributes_p
,
6072 doc
: /* Return non-nil if all the face attributes in ATTRIBUTES are supported.
6073 The optional argument DISPLAY can be a display name, a frame, or
6074 nil (meaning the selected frame's display)
6076 The definition of `supported' is somewhat heuristic, but basically means
6077 that a face containing all the attributes in ATTRIBUTES, when merged
6078 with the default face for display, can be represented in a way that's
6080 \(1) different in appearance than the default face, and
6081 \(2) `close in spirit' to what the attributes specify, if not exact.
6083 Point (2) implies that a `:weight black' attribute will be satisfied by
6084 any display that can display bold, and a `:foreground \"yellow\"' as long
6085 as it can display a yellowish color, but `:slant italic' will _not_ be
6086 satisfied by the tty display code's automatic substitution of a `dim'
6087 face for italic. */)
6088 (attributes
, display
)
6089 Lisp_Object attributes
, display
;
6094 struct face
*def_face
;
6095 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6097 if (noninteractive
|| !initialized
)
6098 /* We may not be able to access low-level face information in batch
6099 mode, or before being dumped, and this function is not going to
6100 be very useful in those cases anyway, so just give up. */
6104 frame
= selected_frame
;
6105 else if (FRAMEP (display
))
6109 /* Find any frame on DISPLAY. */
6110 Lisp_Object fl_tail
;
6113 for (fl_tail
= Vframe_list
; CONSP (fl_tail
); fl_tail
= XCDR (fl_tail
))
6115 frame
= XCAR (fl_tail
);
6116 if (!NILP (Fequal (Fcdr (Fassq (Qdisplay
,
6117 XFRAME (frame
)->param_alist
)),
6123 CHECK_LIVE_FRAME (frame
);
6126 for (i
= 0; i
< LFACE_VECTOR_SIZE
; i
++)
6127 attrs
[i
] = Qunspecified
;
6128 merge_face_ref (f
, attributes
, attrs
, 1, 0);
6130 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6131 if (def_face
== NULL
)
6133 if (! realize_basic_faces (f
))
6134 error ("Cannot realize default face");
6135 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6138 /* Dispatch to the appropriate handler. */
6139 if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
6140 supports
= tty_supports_face_attributes_p (f
, attrs
, def_face
);
6141 #ifdef HAVE_WINDOW_SYSTEM
6143 supports
= x_supports_face_attributes_p (f
, attrs
, def_face
);
6146 return supports
? Qt
: Qnil
;
6150 /***********************************************************************
6152 ***********************************************************************/
6154 DEFUN ("internal-set-font-selection-order",
6155 Finternal_set_font_selection_order
,
6156 Sinternal_set_font_selection_order
, 1, 1, 0,
6157 doc
: /* Set font selection order for face font selection to ORDER.
6158 ORDER must be a list of length 4 containing the symbols `:width',
6159 `:height', `:weight', and `:slant'. Face attributes appearing
6160 first in ORDER are matched first, e.g. if `:height' appears before
6161 `:weight' in ORDER, font selection first tries to find a font with
6162 a suitable height, and then tries to match the font weight.
6169 int indices
[DIM (font_sort_order
)];
6172 bzero (indices
, sizeof indices
);
6176 CONSP (list
) && i
< DIM (indices
);
6177 list
= XCDR (list
), ++i
)
6179 Lisp_Object attr
= XCAR (list
);
6182 if (EQ (attr
, QCwidth
))
6184 else if (EQ (attr
, QCheight
))
6185 xlfd
= XLFD_POINT_SIZE
;
6186 else if (EQ (attr
, QCweight
))
6188 else if (EQ (attr
, QCslant
))
6193 if (indices
[i
] != 0)
6198 if (!NILP (list
) || i
!= DIM (indices
))
6199 signal_error ("Invalid font sort order", order
);
6200 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6201 if (indices
[i
] == 0)
6202 signal_error ("Invalid font sort order", order
);
6204 if (bcmp (indices
, font_sort_order
, sizeof indices
) != 0)
6206 bcopy (indices
, font_sort_order
, sizeof font_sort_order
);
6207 free_all_realized_faces (Qnil
);
6214 DEFUN ("internal-set-alternative-font-family-alist",
6215 Finternal_set_alternative_font_family_alist
,
6216 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
6217 doc
: /* Define alternative font families to try in face font selection.
6218 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
6219 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
6220 be found. Value is ALIST. */)
6225 Vface_alternative_font_family_alist
= alist
;
6226 free_all_realized_faces (Qnil
);
6231 DEFUN ("internal-set-alternative-font-registry-alist",
6232 Finternal_set_alternative_font_registry_alist
,
6233 Sinternal_set_alternative_font_registry_alist
, 1, 1, 0,
6234 doc
: /* Define alternative font registries to try in face font selection.
6235 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
6236 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
6237 be found. Value is ALIST. */)
6242 Vface_alternative_font_registry_alist
= alist
;
6243 free_all_realized_faces (Qnil
);
6248 #ifdef HAVE_WINDOW_SYSTEM
6250 /* Value is non-zero if FONT is the name of a scalable font. The
6251 X11R6 XLFD spec says that point size, pixel size, and average width
6252 are zero for scalable fonts. Intlfonts contain at least one
6253 scalable font ("*-muleindian-1") for which this isn't true, so we
6254 just test average width. */
6257 font_scalable_p (font
)
6258 struct font_name
*font
;
6260 char *s
= font
->fields
[XLFD_AVGWIDTH
];
6261 return (*s
== '0' && *(s
+ 1) == '\0')
6263 /* Windows implementation of XLFD is slightly broken for backward
6264 compatibility with previous broken versions, so test for
6265 wildcards as well as 0. */
6272 /* Ignore the difference of font point size less than this value. */
6274 #define FONT_POINT_SIZE_QUANTUM 5
6276 /* Value is non-zero if FONT1 is a better match for font attributes
6277 VALUES than FONT2. VALUES is an array of face attribute values in
6278 font sort order. COMPARE_PT_P zero means don't compare point
6279 sizes. AVGWIDTH, if not zero, is a specified font average width
6283 better_font_p (values
, font1
, font2
, compare_pt_p
, avgwidth
)
6285 struct font_name
*font1
, *font2
;
6286 int compare_pt_p
, avgwidth
;
6290 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6292 int xlfd_idx
= font_sort_order
[i
];
6294 if (compare_pt_p
|| xlfd_idx
!= XLFD_POINT_SIZE
)
6298 if (xlfd_idx
== XLFD_POINT_SIZE
)
6300 delta1
= abs (values
[i
] - (font1
->numeric
[xlfd_idx
]
6301 / font1
->rescale_ratio
));
6302 delta2
= abs (values
[i
] - (font2
->numeric
[xlfd_idx
]
6303 / font2
->rescale_ratio
));
6304 if (abs (delta1
- delta2
) < FONT_POINT_SIZE_QUANTUM
)
6309 delta1
= abs (values
[i
] - font1
->numeric
[xlfd_idx
]);
6310 delta2
= abs (values
[i
] - font2
->numeric
[xlfd_idx
]);
6313 if (delta1
> delta2
)
6315 else if (delta1
< delta2
)
6319 /* The difference may be equal because, e.g., the face
6320 specifies `italic' but we have only `regular' and
6321 `oblique'. Prefer `oblique' in this case. */
6322 if ((xlfd_idx
== XLFD_WEIGHT
|| xlfd_idx
== XLFD_SLANT
)
6323 && font1
->numeric
[xlfd_idx
] > values
[i
]
6324 && font2
->numeric
[xlfd_idx
] < values
[i
])
6332 int delta1
= abs (avgwidth
- font1
->numeric
[XLFD_AVGWIDTH
]);
6333 int delta2
= abs (avgwidth
- font2
->numeric
[XLFD_AVGWIDTH
]);
6334 if (delta1
> delta2
)
6336 else if (delta1
< delta2
)
6342 /* We prefer a real scalable font; i.e. not what autoscaled. */
6343 int auto_scaled_1
= (font1
->numeric
[XLFD_POINT_SIZE
] == 0
6344 && font1
->numeric
[XLFD_RESY
] > 0);
6345 int auto_scaled_2
= (font2
->numeric
[XLFD_POINT_SIZE
] == 0
6346 && font2
->numeric
[XLFD_RESY
] > 0);
6348 if (auto_scaled_1
!= auto_scaled_2
)
6349 return auto_scaled_2
;
6352 return font1
->registry_priority
< font2
->registry_priority
;
6356 /* Value is non-zero if FONT is an exact match for face attributes in
6357 SPECIFIED. SPECIFIED is an array of face attribute values in font
6358 sort order. AVGWIDTH, if non-zero, is an average width to compare
6362 exact_face_match_p (specified
, font
, avgwidth
)
6364 struct font_name
*font
;
6369 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6370 if (specified
[i
] != font
->numeric
[font_sort_order
[i
]])
6373 return (i
== DIM (font_sort_order
)
6375 || avgwidth
== font
->numeric
[XLFD_AVGWIDTH
]));
6379 /* Value is the name of a scaled font, generated from scalable font
6380 FONT on frame F. SPECIFIED_PT is the point-size to scale FONT to.
6381 Value is allocated from heap. */
6384 build_scalable_font_name (f
, font
, specified_pt
)
6386 struct font_name
*font
;
6389 char pixel_size
[20];
6391 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
6394 /* If scalable font is for a specific resolution, compute
6395 the point size we must specify from the resolution of
6396 the display and the specified resolution of the font. */
6397 if (font
->numeric
[XLFD_RESY
] != 0)
6399 pt
= resy
/ font
->numeric
[XLFD_RESY
] * specified_pt
+ 0.5;
6400 pixel_value
= font
->numeric
[XLFD_RESY
] / (PT_PER_INCH
* 10.0) * pt
;
6405 pixel_value
= resy
/ (PT_PER_INCH
* 10.0) * pt
;
6407 /* We may need a font of the different size. */
6408 pixel_value
*= font
->rescale_ratio
;
6410 /* We should keep POINT_SIZE 0. Otherwise, X server can't open a
6411 font of the specified PIXEL_SIZE. */
6413 { /* Set point size of the font. */
6414 char point_size
[20];
6415 sprintf (point_size
, "%d", (int) pt
);
6416 font
->fields
[XLFD_POINT_SIZE
] = point_size
;
6417 font
->numeric
[XLFD_POINT_SIZE
] = pt
;
6421 /* Set pixel size. */
6422 sprintf (pixel_size
, "%d", pixel_value
);
6423 font
->fields
[XLFD_PIXEL_SIZE
] = pixel_size
;
6424 font
->numeric
[XLFD_PIXEL_SIZE
] = pixel_value
;
6426 /* If font doesn't specify its resolution, use the
6427 resolution of the display. */
6428 if (font
->numeric
[XLFD_RESY
] == 0)
6431 sprintf (buffer
, "%d", (int) resy
);
6432 font
->fields
[XLFD_RESY
] = buffer
;
6433 font
->numeric
[XLFD_RESY
] = resy
;
6436 if (strcmp (font
->fields
[XLFD_RESX
], "0") == 0)
6439 int resx
= FRAME_X_DISPLAY_INFO (f
)->resx
;
6440 sprintf (buffer
, "%d", resx
);
6441 font
->fields
[XLFD_RESX
] = buffer
;
6442 font
->numeric
[XLFD_RESX
] = resx
;
6445 return build_font_name (font
);
6449 /* Value is non-zero if we are allowed to use scalable font FONT. We
6450 can't run a Lisp function here since this function may be called
6451 with input blocked. */
6454 may_use_scalable_font_p (font
)
6457 if (EQ (Vscalable_fonts_allowed
, Qt
))
6459 else if (CONSP (Vscalable_fonts_allowed
))
6461 Lisp_Object tail
, regexp
;
6463 for (tail
= Vscalable_fonts_allowed
; CONSP (tail
); tail
= XCDR (tail
))
6465 regexp
= XCAR (tail
);
6466 if (STRINGP (regexp
)
6467 && fast_c_string_match_ignore_case (regexp
, font
) >= 0)
6477 /* Return the name of the best matching font for face attributes ATTRS
6478 in the array of font_name structures FONTS which contains NFONTS
6479 elements. WIDTH_RATIO is a factor with which to multiply average
6480 widths if ATTRS specifies such a width.
6482 Value is a font name which is allocated from the heap. FONTS is
6483 freed by this function.
6485 If NEEDS_OVERSTRIKE is non-zero, a boolean is returned in it to
6486 indicate whether the resulting font should be drawn using overstrike
6487 to simulate bold-face. */
6490 best_matching_font (f
, attrs
, fonts
, nfonts
, width_ratio
, needs_overstrike
)
6493 struct font_name
*fonts
;
6496 int *needs_overstrike
;
6499 struct font_name
*best
;
6502 int exact_p
, avgwidth
;
6507 /* Make specified font attributes available in `specified',
6508 indexed by sort order. */
6509 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6511 int xlfd_idx
= font_sort_order
[i
];
6513 if (xlfd_idx
== XLFD_SWIDTH
)
6514 specified
[i
] = face_numeric_swidth (attrs
[LFACE_SWIDTH_INDEX
]);
6515 else if (xlfd_idx
== XLFD_POINT_SIZE
)
6516 specified
[i
] = pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
6517 else if (xlfd_idx
== XLFD_WEIGHT
)
6518 specified
[i
] = face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
6519 else if (xlfd_idx
== XLFD_SLANT
)
6520 specified
[i
] = face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
6525 avgwidth
= (UNSPECIFIEDP (attrs
[LFACE_AVGWIDTH_INDEX
])
6527 : XFASTINT (attrs
[LFACE_AVGWIDTH_INDEX
]) * width_ratio
);
6531 if (needs_overstrike
)
6532 *needs_overstrike
= 0;
6534 /* Start with the first non-scalable font in the list. */
6535 for (i
= 0; i
< nfonts
; ++i
)
6536 if (!font_scalable_p (fonts
+ i
))
6539 /* Find the best match among the non-scalable fonts. */
6544 for (i
= 1; i
< nfonts
; ++i
)
6545 if (!font_scalable_p (fonts
+ i
)
6546 && better_font_p (specified
, fonts
+ i
, best
, 1, avgwidth
))
6550 exact_p
= exact_face_match_p (specified
, best
, avgwidth
);
6558 /* Unless we found an exact match among non-scalable fonts, see if
6559 we can find a better match among scalable fonts. */
6562 /* A scalable font is better if
6564 1. its weight, slant, swidth attributes are better, or.
6566 2. the best non-scalable font doesn't have the required
6567 point size, and the scalable fonts weight, slant, swidth
6570 int non_scalable_has_exact_height_p
;
6572 if (best
&& best
->numeric
[XLFD_POINT_SIZE
] == pt
)
6573 non_scalable_has_exact_height_p
= 1;
6575 non_scalable_has_exact_height_p
= 0;
6577 for (i
= 0; i
< nfonts
; ++i
)
6578 if (font_scalable_p (fonts
+ i
))
6581 || better_font_p (specified
, fonts
+ i
, best
, 0, 0)
6582 || (!non_scalable_has_exact_height_p
6583 && !better_font_p (specified
, best
, fonts
+ i
, 0, 0)))
6585 non_scalable_has_exact_height_p
= 1;
6590 if (needs_overstrike
)
6592 enum xlfd_weight want_weight
= specified
[XLFD_WEIGHT
];
6593 enum xlfd_weight got_weight
= best
->numeric
[XLFD_WEIGHT
];
6595 if (want_weight
> XLFD_WEIGHT_MEDIUM
&& want_weight
> got_weight
)
6597 /* We want a bold font, but didn't get one; try to use
6598 overstriking instead to simulate bold-face. However,
6599 don't overstrike an already-bold fontn unless the
6600 desired weight grossly exceeds the available weight. */
6601 if (got_weight
> XLFD_WEIGHT_MEDIUM
)
6602 *needs_overstrike
= (got_weight
- want_weight
) > 2;
6604 *needs_overstrike
= 1;
6609 if (font_scalable_p (best
))
6610 font_name
= build_scalable_font_name (f
, best
, pt
);
6612 font_name
= build_font_name (best
);
6614 /* Free font_name structures. */
6615 free_font_names (fonts
, nfonts
);
6621 /* Get a list of matching fonts on frame F, considering FAMILY
6622 and alternative font families from Vface_alternative_font_registry_alist.
6624 FAMILY is the font family whose alternatives are considered.
6626 REGISTRY, if a string, specifies a font registry and encoding to
6627 match. A value of nil means include fonts of any registry and
6630 Return in *FONTS a pointer to a vector of font_name structures for
6631 the fonts matched. Value is the number of fonts found. */
6634 try_alternative_families (f
, family
, registry
, fonts
)
6636 Lisp_Object family
, registry
;
6637 struct font_name
**fonts
;
6642 nfonts
= font_list (f
, Qnil
, family
, registry
, fonts
);
6645 /* Try alternative font families. */
6646 alter
= Fassoc (family
, Vface_alternative_font_family_alist
);
6649 for (alter
= XCDR (alter
);
6650 CONSP (alter
) && nfonts
== 0;
6651 alter
= XCDR (alter
))
6653 if (STRINGP (XCAR (alter
)))
6654 nfonts
= font_list (f
, Qnil
, XCAR (alter
), registry
, fonts
);
6658 /* Try all scalable fonts before giving up. */
6659 if (nfonts
== 0 && ! EQ (Vscalable_fonts_allowed
, Qt
))
6661 int count
= SPECPDL_INDEX ();
6662 specbind (Qscalable_fonts_allowed
, Qt
);
6663 nfonts
= try_alternative_families (f
, family
, registry
, fonts
);
6664 unbind_to (count
, Qnil
);
6671 /* Get a list of matching fonts on frame F.
6673 FAMILY, if a string, specifies a font family derived from the fontset.
6674 It is only used if the face does not specify any family in ATTRS or
6675 if we cannot find any font of the face's family.
6677 REGISTRY, if a string, specifies a font registry and encoding to
6678 match. A value of nil means include fonts of any registry and
6681 If PREFER_FACE_FAMILY is nonzero, perfer face's family to FAMILY.
6682 Otherwise, prefer FAMILY.
6684 Return in *FONTS a pointer to a vector of font_name structures for
6685 the fonts matched. Value is the number of fonts found. */
6688 try_font_list (f
, attrs
, family
, registry
, fonts
, prefer_face_family
)
6691 Lisp_Object family
, registry
;
6692 struct font_name
**fonts
;
6693 int prefer_face_family
;
6696 Lisp_Object face_family
= attrs
[LFACE_FAMILY_INDEX
];
6697 Lisp_Object try_family
;
6699 try_family
= (prefer_face_family
|| NILP (family
)) ? face_family
: family
;
6701 if (STRINGP (try_family
))
6702 nfonts
= try_alternative_families (f
, try_family
, registry
, fonts
);
6705 /* When realizing the default face and a font spec does not matched
6706 exactly, Emacs looks for ones with the same registry as the
6707 default font. On the Mac, this is mac-roman, which does not work
6708 if the family is -etl-fixed, e.g. The following widens the
6709 choices and fixes that problem. */
6710 if (nfonts
== 0 && STRINGP (try_family
) && STRINGP (registry
)
6711 && xstricmp (SDATA (registry
), "mac-roman") == 0)
6712 nfonts
= try_alternative_families (f
, try_family
, Qnil
, fonts
);
6715 if (EQ (try_family
, family
))
6716 family
= face_family
;
6718 if (nfonts
== 0 && STRINGP (family
))
6719 nfonts
= try_alternative_families (f
, family
, registry
, fonts
);
6721 /* Try font family of the default face or "fixed". */
6724 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6726 family
= default_face
->lface
[LFACE_FAMILY_INDEX
];
6728 family
= build_string ("fixed");
6729 nfonts
= font_list (f
, Qnil
, family
, registry
, fonts
);
6732 /* Try any family with the given registry. */
6734 nfonts
= try_alternative_families (f
, Qnil
, registry
, fonts
);
6740 /* Return the fontset id of the base fontset name or alias name given
6741 by the fontset attribute of ATTRS. Value is -1 if the fontset
6742 attribute of ATTRS doesn't name a fontset. */
6745 face_fontset (attrs
)
6750 name
= attrs
[LFACE_FONT_INDEX
];
6751 if (!STRINGP (name
))
6753 return fs_query_fontset (name
, 0);
6757 /* Choose a name of font to use on frame F to display character C with
6758 Lisp face attributes specified by ATTRS. The font name is
6759 determined by the font-related attributes in ATTRS and the name
6760 pattern for C in FONTSET. Value is the font name which is
6761 allocated from the heap and must be freed by the caller, or NULL if
6762 we can get no information about the font name of C. It is assured
6763 that we always get some information for a single byte
6766 If NEEDS_OVERSTRIKE is non-zero, a boolean is returned in it to
6767 indicate whether the resulting font should be drawn using overstrike
6768 to simulate bold-face. */
6771 choose_face_font (f
, attrs
, fontset
, c
, needs_overstrike
)
6775 int *needs_overstrike
;
6777 Lisp_Object pattern
;
6778 char *font_name
= NULL
;
6779 struct font_name
*fonts
;
6780 int nfonts
, width_ratio
;
6782 if (needs_overstrike
)
6783 *needs_overstrike
= 0;
6785 /* Get (foundry and) family name and registry (and encoding) name of
6787 pattern
= fontset_font_pattern (f
, fontset
, c
);
6790 xassert (!SINGLE_BYTE_CHAR_P (c
));
6794 /* If what we got is a name pattern, return it. */
6795 if (STRINGP (pattern
))
6796 return xstrdup (SDATA (pattern
));
6798 /* Get a list of fonts matching that pattern and choose the
6799 best match for the specified face attributes from it. */
6800 nfonts
= try_font_list (f
, attrs
, XCAR (pattern
), XCDR (pattern
), &fonts
,
6801 (SINGLE_BYTE_CHAR_P (c
)
6802 || CHAR_CHARSET (c
) == charset_latin_iso8859_1
));
6803 width_ratio
= (SINGLE_BYTE_CHAR_P (c
)
6805 : CHARSET_WIDTH (CHAR_CHARSET (c
)));
6806 font_name
= best_matching_font (f
, attrs
, fonts
, nfonts
, width_ratio
,
6811 #endif /* HAVE_WINDOW_SYSTEM */
6815 /***********************************************************************
6817 ***********************************************************************/
6819 /* Realize basic faces on frame F. Value is zero if frame parameters
6820 of F don't contain enough information needed to realize the default
6824 realize_basic_faces (f
)
6828 int count
= SPECPDL_INDEX ();
6830 /* Block input here so that we won't be surprised by an X expose
6831 event, for instance, without having the faces set up. */
6833 specbind (Qscalable_fonts_allowed
, Qt
);
6835 if (realize_default_face (f
))
6837 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
6838 realize_named_face (f
, Qmode_line_inactive
, MODE_LINE_INACTIVE_FACE_ID
);
6839 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
6840 realize_named_face (f
, Qfringe
, FRINGE_FACE_ID
);
6841 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
6842 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
6843 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
6844 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
6845 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
6846 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
6848 /* Reflect changes in the `menu' face in menu bars. */
6849 if (FRAME_FACE_CACHE (f
)->menu_face_changed_p
)
6851 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 0;
6852 #ifdef USE_X_TOOLKIT
6853 x_update_menu_appearance (f
);
6860 unbind_to (count
, Qnil
);
6866 /* Realize the default face on frame F. If the face is not fully
6867 specified, make it fully-specified. Attributes of the default face
6868 that are not explicitly specified are taken from frame parameters. */
6871 realize_default_face (f
)
6874 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
6876 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6877 Lisp_Object frame_font
;
6880 /* If the `default' face is not yet known, create it. */
6881 lface
= lface_from_face_name (f
, Qdefault
, 0);
6885 XSETFRAME (frame
, f
);
6886 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
6890 #ifdef HAVE_WINDOW_SYSTEM
6891 if (FRAME_WINDOW_P (f
))
6893 /* Set frame_font to the value of the `font' frame parameter. */
6894 frame_font
= Fassq (Qfont
, f
->param_alist
);
6895 xassert (CONSP (frame_font
) && STRINGP (XCDR (frame_font
)));
6896 frame_font
= XCDR (frame_font
);
6897 set_lface_from_font_name (f
, lface
, frame_font
,
6898 f
->default_face_done_p
, 1);
6899 f
->default_face_done_p
= 1;
6901 #endif /* HAVE_WINDOW_SYSTEM */
6903 if (!FRAME_WINDOW_P (f
))
6905 LFACE_FAMILY (lface
) = build_string ("default");
6906 LFACE_SWIDTH (lface
) = Qnormal
;
6907 LFACE_HEIGHT (lface
) = make_number (1);
6908 if (UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
6909 LFACE_WEIGHT (lface
) = Qnormal
;
6910 if (UNSPECIFIEDP (LFACE_SLANT (lface
)))
6911 LFACE_SLANT (lface
) = Qnormal
;
6912 LFACE_AVGWIDTH (lface
) = Qunspecified
;
6915 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
6916 LFACE_UNDERLINE (lface
) = Qnil
;
6918 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
6919 LFACE_OVERLINE (lface
) = Qnil
;
6921 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
6922 LFACE_STRIKE_THROUGH (lface
) = Qnil
;
6924 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
6925 LFACE_BOX (lface
) = Qnil
;
6927 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
6928 LFACE_INVERSE (lface
) = Qnil
;
6930 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
6932 /* This function is called so early that colors are not yet
6933 set in the frame parameter list. */
6934 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
6936 if (CONSP (color
) && STRINGP (XCDR (color
)))
6937 LFACE_FOREGROUND (lface
) = XCDR (color
);
6938 else if (FRAME_WINDOW_P (f
))
6940 else if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
6941 LFACE_FOREGROUND (lface
) = build_string (unspecified_fg
);
6946 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
6948 /* This function is called so early that colors are not yet
6949 set in the frame parameter list. */
6950 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
6951 if (CONSP (color
) && STRINGP (XCDR (color
)))
6952 LFACE_BACKGROUND (lface
) = XCDR (color
);
6953 else if (FRAME_WINDOW_P (f
))
6955 else if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
6956 LFACE_BACKGROUND (lface
) = build_string (unspecified_bg
);
6961 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
6962 LFACE_STIPPLE (lface
) = Qnil
;
6964 /* Realize the face; it must be fully-specified now. */
6965 xassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
6966 check_lface (lface
);
6967 bcopy (XVECTOR (lface
)->contents
, attrs
, sizeof attrs
);
6968 face
= realize_face (c
, attrs
, 0, NULL
, DEFAULT_FACE_ID
);
6973 /* Realize basic faces other than the default face in face cache C.
6974 SYMBOL is the face name, ID is the face id the realized face must
6975 have. The default face must have been realized already. */
6978 realize_named_face (f
, symbol
, id
)
6983 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
6984 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
6985 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6986 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
6987 struct face
*new_face
;
6989 /* The default face must exist and be fully specified. */
6990 get_lface_attributes (f
, Qdefault
, attrs
, 1);
6991 check_lface_attrs (attrs
);
6992 xassert (lface_fully_specified_p (attrs
));
6994 /* If SYMBOL isn't know as a face, create it. */
6998 XSETFRAME (frame
, f
);
6999 lface
= Finternal_make_lisp_face (symbol
, frame
);
7002 /* Merge SYMBOL's face with the default face. */
7003 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
7004 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
7006 /* Realize the face. */
7007 new_face
= realize_face (c
, attrs
, 0, NULL
, id
);
7011 /* Realize the fully-specified face with attributes ATTRS in face
7012 cache CACHE for character C. If C is a multibyte character,
7013 BASE_FACE is a face that has the same attributes. Otherwise,
7014 BASE_FACE is ignored. If FORMER_FACE_ID is non-negative, it is an
7015 ID of face to remove before caching the new face. Value is a
7016 pointer to the newly created realized face. */
7018 static struct face
*
7019 realize_face (cache
, attrs
, c
, base_face
, former_face_id
)
7020 struct face_cache
*cache
;
7023 struct face
*base_face
;
7028 /* LFACE must be fully specified. */
7029 xassert (cache
!= NULL
);
7030 check_lface_attrs (attrs
);
7032 if (former_face_id
>= 0 && cache
->used
> former_face_id
)
7034 /* Remove the former face. */
7035 struct face
*former_face
= cache
->faces_by_id
[former_face_id
];
7036 uncache_face (cache
, former_face
);
7037 free_realized_face (cache
->f
, former_face
);
7040 if (FRAME_WINDOW_P (cache
->f
))
7041 face
= realize_x_face (cache
, attrs
, c
, base_face
);
7042 else if (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
))
7043 face
= realize_tty_face (cache
, attrs
, c
);
7047 /* Insert the new face. */
7048 cache_face (cache
, face
, lface_hash (attrs
));
7049 #ifdef HAVE_WINDOW_SYSTEM
7050 if (FRAME_WINDOW_P (cache
->f
) && face
->font
== NULL
)
7051 load_face_font (cache
->f
, face
, c
);
7052 #endif /* HAVE_WINDOW_SYSTEM */
7057 /* Realize the fully-specified face with attributes ATTRS in face
7058 cache CACHE for character C. Do it for X frame CACHE->f. If C is
7059 a multibyte character, BASE_FACE is a face that has the same
7060 attributes. Otherwise, BASE_FACE is ignored. If the new face
7061 doesn't share font with the default face, a fontname is allocated
7062 from the heap and set in `font_name' of the new face, but it is not
7063 yet loaded here. Value is a pointer to the newly created realized
7066 static struct face
*
7067 realize_x_face (cache
, attrs
, c
, base_face
)
7068 struct face_cache
*cache
;
7071 struct face
*base_face
;
7073 #ifdef HAVE_WINDOW_SYSTEM
7074 struct face
*face
, *default_face
;
7076 Lisp_Object stipple
, overline
, strike_through
, box
;
7078 xassert (FRAME_WINDOW_P (cache
->f
));
7079 xassert (SINGLE_BYTE_CHAR_P (c
)
7082 /* Allocate a new realized face. */
7083 face
= make_realized_face (attrs
);
7087 /* If C is a multibyte character, we share all face attirbutes with
7088 BASE_FACE including the realized fontset. But, we must load a
7090 if (!SINGLE_BYTE_CHAR_P (c
))
7092 bcopy (base_face
, face
, sizeof *face
);
7095 /* Don't try to free the colors copied bitwise from BASE_FACE. */
7096 face
->colors_copied_bitwise_p
= 1;
7098 /* to force realize_face to load font */
7103 /* Now we are realizing a face for ASCII (and unibyte) characters. */
7105 /* Determine the font to use. Most of the time, the font will be
7106 the same as the font of the default face, so try that first. */
7107 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7109 && FACE_SUITABLE_FOR_CHAR_P (default_face
, c
)
7110 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
7112 face
->font
= default_face
->font
;
7113 face
->fontset
= default_face
->fontset
;
7114 face
->font_info_id
= default_face
->font_info_id
;
7115 face
->font_name
= default_face
->font_name
;
7116 face
->ascii_face
= face
;
7118 /* But, as we can't share the fontset, make a new realized
7119 fontset that has the same base fontset as of the default
7122 = make_fontset_for_ascii_face (f
, default_face
->fontset
);
7126 /* If the face attribute ATTRS specifies a fontset, use it as
7127 the base of a new realized fontset. Otherwise, use the same
7128 base fontset as of the default face. The base determines
7129 registry and encoding of a font. It may also determine
7130 foundry and family. The other fields of font name pattern
7131 are constructed from ATTRS. */
7132 int fontset
= face_fontset (attrs
);
7134 if ((fontset
== -1) && default_face
)
7135 fontset
= default_face
->fontset
;
7136 face
->fontset
= make_fontset_for_ascii_face (f
, fontset
);
7137 face
->font
= NULL
; /* to force realize_face to load font */
7140 /* Load colors, and set remaining attributes. */
7142 load_face_colors (f
, face
, attrs
);
7145 box
= attrs
[LFACE_BOX_INDEX
];
7148 /* A simple box of line width 1 drawn in color given by
7150 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
7152 face
->box
= FACE_SIMPLE_BOX
;
7153 face
->box_line_width
= 1;
7155 else if (INTEGERP (box
))
7157 /* Simple box of specified line width in foreground color of the
7159 xassert (XINT (box
) != 0);
7160 face
->box
= FACE_SIMPLE_BOX
;
7161 face
->box_line_width
= XINT (box
);
7162 face
->box_color
= face
->foreground
;
7163 face
->box_color_defaulted_p
= 1;
7165 else if (CONSP (box
))
7167 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
7168 being one of `raised' or `sunken'. */
7169 face
->box
= FACE_SIMPLE_BOX
;
7170 face
->box_color
= face
->foreground
;
7171 face
->box_color_defaulted_p
= 1;
7172 face
->box_line_width
= 1;
7176 Lisp_Object keyword
, value
;
7178 keyword
= XCAR (box
);
7186 if (EQ (keyword
, QCline_width
))
7188 if (INTEGERP (value
) && XINT (value
) != 0)
7189 face
->box_line_width
= XINT (value
);
7191 else if (EQ (keyword
, QCcolor
))
7193 if (STRINGP (value
))
7195 face
->box_color
= load_color (f
, face
, value
,
7197 face
->use_box_color_for_shadows_p
= 1;
7200 else if (EQ (keyword
, QCstyle
))
7202 if (EQ (value
, Qreleased_button
))
7203 face
->box
= FACE_RAISED_BOX
;
7204 else if (EQ (value
, Qpressed_button
))
7205 face
->box
= FACE_SUNKEN_BOX
;
7210 /* Text underline, overline, strike-through. */
7212 if (EQ (attrs
[LFACE_UNDERLINE_INDEX
], Qt
))
7214 /* Use default color (same as foreground color). */
7215 face
->underline_p
= 1;
7216 face
->underline_defaulted_p
= 1;
7217 face
->underline_color
= 0;
7219 else if (STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]))
7221 /* Use specified color. */
7222 face
->underline_p
= 1;
7223 face
->underline_defaulted_p
= 0;
7224 face
->underline_color
7225 = load_color (f
, face
, attrs
[LFACE_UNDERLINE_INDEX
],
7226 LFACE_UNDERLINE_INDEX
);
7228 else if (NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
7230 face
->underline_p
= 0;
7231 face
->underline_defaulted_p
= 0;
7232 face
->underline_color
= 0;
7235 overline
= attrs
[LFACE_OVERLINE_INDEX
];
7236 if (STRINGP (overline
))
7238 face
->overline_color
7239 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
7240 LFACE_OVERLINE_INDEX
);
7241 face
->overline_p
= 1;
7243 else if (EQ (overline
, Qt
))
7245 face
->overline_color
= face
->foreground
;
7246 face
->overline_color_defaulted_p
= 1;
7247 face
->overline_p
= 1;
7250 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
7251 if (STRINGP (strike_through
))
7253 face
->strike_through_color
7254 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
7255 LFACE_STRIKE_THROUGH_INDEX
);
7256 face
->strike_through_p
= 1;
7258 else if (EQ (strike_through
, Qt
))
7260 face
->strike_through_color
= face
->foreground
;
7261 face
->strike_through_color_defaulted_p
= 1;
7262 face
->strike_through_p
= 1;
7265 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
7266 if (!NILP (stipple
))
7267 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
7269 xassert (FACE_SUITABLE_FOR_CHAR_P (face
, c
));
7271 #endif /* HAVE_WINDOW_SYSTEM */
7275 /* Map a specified color of face FACE on frame F to a tty color index.
7276 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
7277 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
7278 default foreground/background colors. */
7281 map_tty_color (f
, face
, idx
, defaulted
)
7284 enum lface_attribute_index idx
;
7287 Lisp_Object frame
, color
, def
;
7288 int foreground_p
= idx
== LFACE_FOREGROUND_INDEX
;
7289 unsigned long default_pixel
, default_other_pixel
, pixel
;
7291 xassert (idx
== LFACE_FOREGROUND_INDEX
|| idx
== LFACE_BACKGROUND_INDEX
);
7295 pixel
= default_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
7296 default_other_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
7300 pixel
= default_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
7301 default_other_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
7304 XSETFRAME (frame
, f
);
7305 color
= face
->lface
[idx
];
7309 && CONSP (Vtty_defined_color_alist
)
7310 && (def
= assq_no_quit (color
, call1 (Qtty_color_alist
, frame
)),
7313 /* Associations in tty-defined-color-alist are of the form
7314 (NAME INDEX R G B). We need the INDEX part. */
7315 pixel
= XINT (XCAR (XCDR (def
)));
7318 if (pixel
== default_pixel
&& STRINGP (color
))
7320 pixel
= load_color (f
, face
, color
, idx
);
7322 #if defined (MSDOS) || defined (WINDOWSNT)
7323 /* If the foreground of the default face is the default color,
7324 use the foreground color defined by the frame. */
7326 if (FRAME_MSDOS_P (f
))
7329 if (pixel
== default_pixel
7330 || pixel
== FACE_TTY_DEFAULT_COLOR
)
7333 pixel
= FRAME_FOREGROUND_PIXEL (f
);
7335 pixel
= FRAME_BACKGROUND_PIXEL (f
);
7336 face
->lface
[idx
] = tty_color_name (f
, pixel
);
7339 else if (pixel
== default_other_pixel
)
7342 pixel
= FRAME_BACKGROUND_PIXEL (f
);
7344 pixel
= FRAME_FOREGROUND_PIXEL (f
);
7345 face
->lface
[idx
] = tty_color_name (f
, pixel
);
7351 #endif /* MSDOS or WINDOWSNT */
7355 face
->foreground
= pixel
;
7357 face
->background
= pixel
;
7361 /* Realize the fully-specified face with attributes ATTRS in face
7362 cache CACHE for character C. Do it for TTY frame CACHE->f. Value is a
7363 pointer to the newly created realized face. */
7365 static struct face
*
7366 realize_tty_face (cache
, attrs
, c
)
7367 struct face_cache
*cache
;
7373 int face_colors_defaulted
= 0;
7374 struct frame
*f
= cache
->f
;
7376 /* Frame must be a termcap frame. */
7377 xassert (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
));
7379 /* Allocate a new realized face. */
7380 face
= make_realized_face (attrs
);
7381 face
->font_name
= FRAME_MSDOS_P (cache
->f
) ? "ms-dos" : "tty";
7383 /* Map face attributes to TTY appearances. We map slant to
7384 dimmed text because we want italic text to appear differently
7385 and because dimmed text is probably used infrequently. */
7386 weight
= face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
7387 slant
= face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
7389 if (weight
> XLFD_WEIGHT_MEDIUM
)
7390 face
->tty_bold_p
= 1;
7391 if (weight
< XLFD_WEIGHT_MEDIUM
|| slant
!= XLFD_SLANT_ROMAN
)
7392 face
->tty_dim_p
= 1;
7393 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
7394 face
->tty_underline_p
= 1;
7395 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
7396 face
->tty_reverse_p
= 1;
7398 /* Map color names to color indices. */
7399 map_tty_color (f
, face
, LFACE_FOREGROUND_INDEX
, &face_colors_defaulted
);
7400 map_tty_color (f
, face
, LFACE_BACKGROUND_INDEX
, &face_colors_defaulted
);
7402 /* Swap colors if face is inverse-video. If the colors are taken
7403 from the frame colors, they are already inverted, since the
7404 frame-creation function calls x-handle-reverse-video. */
7405 if (face
->tty_reverse_p
&& !face_colors_defaulted
)
7407 unsigned long tem
= face
->foreground
;
7408 face
->foreground
= face
->background
;
7409 face
->background
= tem
;
7412 if (tty_suppress_bold_inverse_default_colors_p
7414 && face
->background
== FACE_TTY_DEFAULT_FG_COLOR
7415 && face
->foreground
== FACE_TTY_DEFAULT_BG_COLOR
)
7416 face
->tty_bold_p
= 0;
7422 DEFUN ("tty-suppress-bold-inverse-default-colors",
7423 Ftty_suppress_bold_inverse_default_colors
,
7424 Stty_suppress_bold_inverse_default_colors
, 1, 1, 0,
7425 doc
: /* Suppress/allow boldness of faces with inverse default colors.
7426 SUPPRESS non-nil means suppress it.
7427 This affects bold faces on TTYs whose foreground is the default background
7428 color of the display and whose background is the default foreground color.
7429 For such faces, the bold face attribute is ignored if this variable
7432 Lisp_Object suppress
;
7434 tty_suppress_bold_inverse_default_colors_p
= !NILP (suppress
);
7435 ++face_change_count
;
7441 /***********************************************************************
7443 ***********************************************************************/
7445 /* Return the ID of the face to use to display character CH with face
7446 property PROP on frame F in current_buffer. */
7449 compute_char_face (f
, ch
, prop
)
7456 if (NILP (current_buffer
->enable_multibyte_characters
))
7461 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7462 face_id
= FACE_FOR_CHAR (f
, face
, ch
);
7466 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
7467 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7468 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
7469 merge_face_ref (f
, prop
, attrs
, 1, 0);
7470 face_id
= lookup_face (f
, attrs
, ch
, NULL
);
7476 /* Return the face ID associated with buffer position POS for
7477 displaying ASCII characters. Return in *ENDPTR the position at
7478 which a different face is needed, as far as text properties and
7479 overlays are concerned. W is a window displaying current_buffer.
7481 REGION_BEG, REGION_END delimit the region, so it can be
7484 LIMIT is a position not to scan beyond. That is to limit the time
7485 this function can take.
7487 If MOUSE is non-zero, use the character's mouse-face, not its face.
7489 The face returned is suitable for displaying ASCII characters. */
7492 face_at_buffer_position (w
, pos
, region_beg
, region_end
,
7493 endptr
, limit
, mouse
)
7496 int region_beg
, region_end
;
7501 struct frame
*f
= XFRAME (w
->frame
);
7502 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
7503 Lisp_Object prop
, position
;
7505 Lisp_Object
*overlay_vec
;
7508 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
7509 Lisp_Object limit1
, end
;
7510 struct face
*default_face
;
7512 /* W must display the current buffer. We could write this function
7513 to use the frame and buffer of W, but right now it doesn't. */
7514 /* xassert (XBUFFER (w->buffer) == current_buffer); */
7516 XSETFRAME (frame
, f
);
7517 XSETFASTINT (position
, pos
);
7520 if (pos
< region_beg
&& region_beg
< endpos
)
7521 endpos
= region_beg
;
7523 /* Get the `face' or `mouse_face' text property at POS, and
7524 determine the next position at which the property changes. */
7525 prop
= Fget_text_property (position
, propname
, w
->buffer
);
7526 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
7527 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
7529 endpos
= XINT (end
);
7531 /* Look at properties from overlays. */
7535 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, &next_overlay
, 0);
7536 if (next_overlay
< endpos
)
7537 endpos
= next_overlay
;
7542 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7544 /* Optimize common cases where we can use the default face. */
7547 && !(pos
>= region_beg
&& pos
< region_end
))
7548 return DEFAULT_FACE_ID
;
7550 /* Begin with attributes from the default face. */
7551 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
7553 /* Merge in attributes specified via text properties. */
7555 merge_face_ref (f
, prop
, attrs
, 1, 0);
7557 /* Now merge the overlay data. */
7558 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
7559 for (i
= 0; i
< noverlays
; i
++)
7564 prop
= Foverlay_get (overlay_vec
[i
], propname
);
7566 merge_face_ref (f
, prop
, attrs
, 1, 0);
7568 oend
= OVERLAY_END (overlay_vec
[i
]);
7569 oendpos
= OVERLAY_POSITION (oend
);
7570 if (oendpos
< endpos
)
7574 /* If in the region, merge in the region face. */
7575 if (pos
>= region_beg
&& pos
< region_end
)
7577 merge_named_face (f
, Qregion
, attrs
, 0);
7579 if (region_end
< endpos
)
7580 endpos
= region_end
;
7585 /* Look up a realized face with the given face attributes,
7586 or realize a new one for ASCII characters. */
7587 return lookup_face (f
, attrs
, 0, NULL
);
7591 /* Compute the face at character position POS in Lisp string STRING on
7592 window W, for ASCII characters.
7594 If STRING is an overlay string, it comes from position BUFPOS in
7595 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
7596 not an overlay string. W must display the current buffer.
7597 REGION_BEG and REGION_END give the start and end positions of the
7598 region; both are -1 if no region is visible.
7600 BASE_FACE_ID is the id of a face to merge with. For strings coming
7601 from overlays or the `display' property it is the face at BUFPOS.
7603 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
7605 Set *ENDPTR to the next position where to check for faces in
7606 STRING; -1 if the face is constant from POS to the end of the
7609 Value is the id of the face to use. The face returned is suitable
7610 for displaying ASCII characters. */
7613 face_at_string_position (w
, string
, pos
, bufpos
, region_beg
,
7614 region_end
, endptr
, base_face_id
, mouse_p
)
7618 int region_beg
, region_end
;
7620 enum face_id base_face_id
;
7623 Lisp_Object prop
, position
, end
, limit
;
7624 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7625 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
7626 struct face
*base_face
;
7627 int multibyte_p
= STRING_MULTIBYTE (string
);
7628 Lisp_Object prop_name
= mouse_p
? Qmouse_face
: Qface
;
7630 /* Get the value of the face property at the current position within
7631 STRING. Value is nil if there is no face property. */
7632 XSETFASTINT (position
, pos
);
7633 prop
= Fget_text_property (position
, prop_name
, string
);
7635 /* Get the next position at which to check for faces. Value of end
7636 is nil if face is constant all the way to the end of the string.
7637 Otherwise it is a string position where to check faces next.
7638 Limit is the maximum position up to which to check for property
7639 changes in Fnext_single_property_change. Strings are usually
7640 short, so set the limit to the end of the string. */
7641 XSETFASTINT (limit
, SCHARS (string
));
7642 end
= Fnext_single_property_change (position
, prop_name
, string
, limit
);
7644 *endptr
= XFASTINT (end
);
7648 base_face
= FACE_FROM_ID (f
, base_face_id
);
7649 xassert (base_face
);
7651 /* Optimize the default case that there is no face property and we
7652 are not in the region. */
7654 && (base_face_id
!= DEFAULT_FACE_ID
7655 /* BUFPOS <= 0 means STRING is not an overlay string, so
7656 that the region doesn't have to be taken into account. */
7658 || bufpos
< region_beg
7659 || bufpos
>= region_end
)
7661 /* We can't realize faces for different charsets differently
7662 if we don't have fonts, so we can stop here if not working
7663 on a window-system frame. */
7664 || !FRAME_WINDOW_P (f
)
7665 || FACE_SUITABLE_FOR_CHAR_P (base_face
, 0)))
7666 return base_face
->id
;
7668 /* Begin with attributes from the base face. */
7669 bcopy (base_face
->lface
, attrs
, sizeof attrs
);
7671 /* Merge in attributes specified via text properties. */
7673 merge_face_ref (f
, prop
, attrs
, 1, 0);
7675 /* If in the region, merge in the region face. */
7677 && bufpos
>= region_beg
7678 && bufpos
< region_end
)
7679 merge_named_face (f
, Qregion
, attrs
, 0);
7681 /* Look up a realized face with the given face attributes,
7682 or realize a new one for ASCII characters. */
7683 return lookup_face (f
, attrs
, 0, NULL
);
7688 /***********************************************************************
7690 ***********************************************************************/
7694 /* Print the contents of the realized face FACE to stderr. */
7697 dump_realized_face (face
)
7700 fprintf (stderr
, "ID: %d\n", face
->id
);
7701 #ifdef HAVE_X_WINDOWS
7702 fprintf (stderr
, "gc: %d\n", (int) face
->gc
);
7704 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
7706 SDATA (face
->lface
[LFACE_FOREGROUND_INDEX
]));
7707 fprintf (stderr
, "background: 0x%lx (%s)\n",
7709 SDATA (face
->lface
[LFACE_BACKGROUND_INDEX
]));
7710 fprintf (stderr
, "font_name: %s (%s)\n",
7712 SDATA (face
->lface
[LFACE_FAMILY_INDEX
]));
7713 #ifdef HAVE_X_WINDOWS
7714 fprintf (stderr
, "font = %p\n", face
->font
);
7716 fprintf (stderr
, "font_info_id = %d\n", face
->font_info_id
);
7717 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
7718 fprintf (stderr
, "underline: %d (%s)\n",
7720 SDATA (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
])));
7721 fprintf (stderr
, "hash: %d\n", face
->hash
);
7722 fprintf (stderr
, "charset: %d\n", face
->charset
);
7726 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, doc
: /* */)
7734 fprintf (stderr
, "font selection order: ");
7735 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
7736 fprintf (stderr
, "%d ", font_sort_order
[i
]);
7737 fprintf (stderr
, "\n");
7739 fprintf (stderr
, "alternative fonts: ");
7740 debug_print (Vface_alternative_font_family_alist
);
7741 fprintf (stderr
, "\n");
7743 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
7744 Fdump_face (make_number (i
));
7750 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
7752 error ("Not a valid face");
7753 dump_realized_face (face
);
7760 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
7761 0, 0, 0, doc
: /* */)
7764 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
7765 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
7766 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
7770 #endif /* GLYPH_DEBUG != 0 */
7774 /***********************************************************************
7776 ***********************************************************************/
7781 Qface
= intern ("face");
7783 Qface_no_inherit
= intern ("face-no-inherit");
7784 staticpro (&Qface_no_inherit
);
7785 Qbitmap_spec_p
= intern ("bitmap-spec-p");
7786 staticpro (&Qbitmap_spec_p
);
7787 Qframe_update_face_colors
= intern ("frame-update-face-colors");
7788 staticpro (&Qframe_update_face_colors
);
7790 /* Lisp face attribute keywords. */
7791 QCfamily
= intern (":family");
7792 staticpro (&QCfamily
);
7793 QCheight
= intern (":height");
7794 staticpro (&QCheight
);
7795 QCweight
= intern (":weight");
7796 staticpro (&QCweight
);
7797 QCslant
= intern (":slant");
7798 staticpro (&QCslant
);
7799 QCunderline
= intern (":underline");
7800 staticpro (&QCunderline
);
7801 QCinverse_video
= intern (":inverse-video");
7802 staticpro (&QCinverse_video
);
7803 QCreverse_video
= intern (":reverse-video");
7804 staticpro (&QCreverse_video
);
7805 QCforeground
= intern (":foreground");
7806 staticpro (&QCforeground
);
7807 QCbackground
= intern (":background");
7808 staticpro (&QCbackground
);
7809 QCstipple
= intern (":stipple");;
7810 staticpro (&QCstipple
);
7811 QCwidth
= intern (":width");
7812 staticpro (&QCwidth
);
7813 QCfont
= intern (":font");
7814 staticpro (&QCfont
);
7815 QCbold
= intern (":bold");
7816 staticpro (&QCbold
);
7817 QCitalic
= intern (":italic");
7818 staticpro (&QCitalic
);
7819 QCoverline
= intern (":overline");
7820 staticpro (&QCoverline
);
7821 QCstrike_through
= intern (":strike-through");
7822 staticpro (&QCstrike_through
);
7823 QCbox
= intern (":box");
7825 QCinherit
= intern (":inherit");
7826 staticpro (&QCinherit
);
7828 /* Symbols used for Lisp face attribute values. */
7829 QCcolor
= intern (":color");
7830 staticpro (&QCcolor
);
7831 QCline_width
= intern (":line-width");
7832 staticpro (&QCline_width
);
7833 QCstyle
= intern (":style");
7834 staticpro (&QCstyle
);
7835 Qreleased_button
= intern ("released-button");
7836 staticpro (&Qreleased_button
);
7837 Qpressed_button
= intern ("pressed-button");
7838 staticpro (&Qpressed_button
);
7839 Qnormal
= intern ("normal");
7840 staticpro (&Qnormal
);
7841 Qultra_light
= intern ("ultra-light");
7842 staticpro (&Qultra_light
);
7843 Qextra_light
= intern ("extra-light");
7844 staticpro (&Qextra_light
);
7845 Qlight
= intern ("light");
7846 staticpro (&Qlight
);
7847 Qsemi_light
= intern ("semi-light");
7848 staticpro (&Qsemi_light
);
7849 Qsemi_bold
= intern ("semi-bold");
7850 staticpro (&Qsemi_bold
);
7851 Qbold
= intern ("bold");
7853 Qextra_bold
= intern ("extra-bold");
7854 staticpro (&Qextra_bold
);
7855 Qultra_bold
= intern ("ultra-bold");
7856 staticpro (&Qultra_bold
);
7857 Qoblique
= intern ("oblique");
7858 staticpro (&Qoblique
);
7859 Qitalic
= intern ("italic");
7860 staticpro (&Qitalic
);
7861 Qreverse_oblique
= intern ("reverse-oblique");
7862 staticpro (&Qreverse_oblique
);
7863 Qreverse_italic
= intern ("reverse-italic");
7864 staticpro (&Qreverse_italic
);
7865 Qultra_condensed
= intern ("ultra-condensed");
7866 staticpro (&Qultra_condensed
);
7867 Qextra_condensed
= intern ("extra-condensed");
7868 staticpro (&Qextra_condensed
);
7869 Qcondensed
= intern ("condensed");
7870 staticpro (&Qcondensed
);
7871 Qsemi_condensed
= intern ("semi-condensed");
7872 staticpro (&Qsemi_condensed
);
7873 Qsemi_expanded
= intern ("semi-expanded");
7874 staticpro (&Qsemi_expanded
);
7875 Qexpanded
= intern ("expanded");
7876 staticpro (&Qexpanded
);
7877 Qextra_expanded
= intern ("extra-expanded");
7878 staticpro (&Qextra_expanded
);
7879 Qultra_expanded
= intern ("ultra-expanded");
7880 staticpro (&Qultra_expanded
);
7881 Qbackground_color
= intern ("background-color");
7882 staticpro (&Qbackground_color
);
7883 Qforeground_color
= intern ("foreground-color");
7884 staticpro (&Qforeground_color
);
7885 Qunspecified
= intern ("unspecified");
7886 staticpro (&Qunspecified
);
7888 Qface_alias
= intern ("face-alias");
7889 staticpro (&Qface_alias
);
7890 Qdefault
= intern ("default");
7891 staticpro (&Qdefault
);
7892 Qtool_bar
= intern ("tool-bar");
7893 staticpro (&Qtool_bar
);
7894 Qregion
= intern ("region");
7895 staticpro (&Qregion
);
7896 Qfringe
= intern ("fringe");
7897 staticpro (&Qfringe
);
7898 Qheader_line
= intern ("header-line");
7899 staticpro (&Qheader_line
);
7900 Qscroll_bar
= intern ("scroll-bar");
7901 staticpro (&Qscroll_bar
);
7902 Qmenu
= intern ("menu");
7904 Qcursor
= intern ("cursor");
7905 staticpro (&Qcursor
);
7906 Qborder
= intern ("border");
7907 staticpro (&Qborder
);
7908 Qmouse
= intern ("mouse");
7909 staticpro (&Qmouse
);
7910 Qmode_line_inactive
= intern ("mode-line-inactive");
7911 staticpro (&Qmode_line_inactive
);
7912 Qtty_color_desc
= intern ("tty-color-desc");
7913 staticpro (&Qtty_color_desc
);
7914 Qtty_color_standard_values
= intern ("tty-color-standard-values");
7915 staticpro (&Qtty_color_standard_values
);
7916 Qtty_color_by_index
= intern ("tty-color-by-index");
7917 staticpro (&Qtty_color_by_index
);
7918 Qtty_color_alist
= intern ("tty-color-alist");
7919 staticpro (&Qtty_color_alist
);
7920 Qscalable_fonts_allowed
= intern ("scalable-fonts-allowed");
7921 staticpro (&Qscalable_fonts_allowed
);
7923 Vparam_value_alist
= Fcons (Fcons (Qnil
, Qnil
), Qnil
);
7924 staticpro (&Vparam_value_alist
);
7925 Vface_alternative_font_family_alist
= Qnil
;
7926 staticpro (&Vface_alternative_font_family_alist
);
7927 Vface_alternative_font_registry_alist
= Qnil
;
7928 staticpro (&Vface_alternative_font_registry_alist
);
7930 defsubr (&Sinternal_make_lisp_face
);
7931 defsubr (&Sinternal_lisp_face_p
);
7932 defsubr (&Sinternal_set_lisp_face_attribute
);
7933 #ifdef HAVE_WINDOW_SYSTEM
7934 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
7936 defsubr (&Scolor_gray_p
);
7937 defsubr (&Scolor_supported_p
);
7938 defsubr (&Sface_attribute_relative_p
);
7939 defsubr (&Smerge_face_attribute
);
7940 defsubr (&Sinternal_get_lisp_face_attribute
);
7941 defsubr (&Sinternal_lisp_face_attribute_values
);
7942 defsubr (&Sinternal_lisp_face_equal_p
);
7943 defsubr (&Sinternal_lisp_face_empty_p
);
7944 defsubr (&Sinternal_copy_lisp_face
);
7945 defsubr (&Sinternal_merge_in_global_face
);
7946 defsubr (&Sface_font
);
7947 defsubr (&Sframe_face_alist
);
7948 defsubr (&Sdisplay_supports_face_attributes_p
);
7949 defsubr (&Scolor_distance
);
7950 defsubr (&Sinternal_set_font_selection_order
);
7951 defsubr (&Sinternal_set_alternative_font_family_alist
);
7952 defsubr (&Sinternal_set_alternative_font_registry_alist
);
7953 defsubr (&Sface_attributes_as_vector
);
7955 defsubr (&Sdump_face
);
7956 defsubr (&Sshow_face_resources
);
7957 #endif /* GLYPH_DEBUG */
7958 defsubr (&Sclear_face_cache
);
7959 defsubr (&Stty_suppress_bold_inverse_default_colors
);
7961 #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS
7962 defsubr (&Sdump_colors
);
7965 DEFVAR_LISP ("font-list-limit", &Vfont_list_limit
,
7966 doc
: /* *Limit for font matching.
7967 If an integer > 0, font matching functions won't load more than
7968 that number of fonts when searching for a matching font. */);
7969 Vfont_list_limit
= make_number (DEFAULT_FONT_LIST_LIMIT
);
7971 DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults
,
7972 doc
: /* List of global face definitions (for internal use only.) */);
7973 Vface_new_frame_defaults
= Qnil
;
7975 DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple
,
7976 doc
: /* *Default stipple pattern used on monochrome displays.
7977 This stipple pattern is used on monochrome displays
7978 instead of shades of gray for a face background color.
7979 See `set-face-stipple' for possible values for this variable. */);
7980 Vface_default_stipple
= build_string ("gray3");
7982 DEFVAR_LISP ("tty-defined-color-alist", &Vtty_defined_color_alist
,
7983 doc
: /* An alist of defined terminal colors and their RGB values. */);
7984 Vtty_defined_color_alist
= Qnil
;
7986 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed
,
7987 doc
: /* Allowed scalable fonts.
7988 A value of nil means don't allow any scalable fonts.
7989 A value of t means allow any scalable font.
7990 Otherwise, value must be a list of regular expressions. A font may be
7991 scaled if its name matches a regular expression in the list.
7992 Note that if value is nil, a scalable font might still be used, if no
7993 other font of the appropriate family and registry is available. */);
7994 Vscalable_fonts_allowed
= Qnil
;
7996 DEFVAR_LISP ("face-ignored-fonts", &Vface_ignored_fonts
,
7997 doc
: /* List of ignored fonts.
7998 Each element is a regular expression that matches names of fonts to
8000 Vface_ignored_fonts
= Qnil
;
8002 DEFVAR_LISP ("face-font-rescale-alist", &Vface_font_rescale_alist
,
8003 doc
: /* Alist of fonts vs the rescaling factors.
8004 Each element is a cons (FONT-NAME-PATTERN . RESCALE-RATIO), where
8005 FONT-NAME-PATTERN is a regular expression matching a font name, and
8006 RESCALE-RATIO is a floating point number to specify how much larger
8007 \(or smaller) font we should use. For instance, if a face requests
8008 a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point. */);
8009 Vface_font_rescale_alist
= Qnil
;
8011 #ifdef HAVE_WINDOW_SYSTEM
8012 defsubr (&Sbitmap_spec_p
);
8013 defsubr (&Sx_list_fonts
);
8014 defsubr (&Sinternal_face_x_get_resource
);
8015 defsubr (&Sx_family_fonts
);
8016 defsubr (&Sx_font_family_list
);
8017 #endif /* HAVE_WINDOW_SYSTEM */
8020 /* arch-tag: 8a0f7598-5517-408d-9ab3-1da6fcd4c749
8021 (do not change this comment) */