1 /* xfaces.c -- "Face" primitives.
2 Copyright (C) 1993, 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, 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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, 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 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.
77 Faces are frame-local by nature because Emacs allows to define the
78 same named face (face names are symbols) differently for different
79 frames. Each frame has an alist of face definitions for all named
80 faces. The value of a named face in such an alist is a Lisp vector
81 with the symbol `face' in slot 0, and a slot for each of the face
82 attributes mentioned above.
84 There is also a global face alist `Vface_new_frame_defaults'. Face
85 definitions from this list are used to initialize faces of newly
88 A face doesn't have to specify all attributes. Those not specified
89 have a value of `unspecified'. Faces specifying all attributes but
90 the 14th are called `fully-specified'.
95 The display style of a given character in the text is determined by
96 combining several faces. This process is called `face merging'.
97 Any aspect of the display style that isn't specified by overlays or
98 text properties is taken from the `default' face. Since it is made
99 sure that the default face is always fully-specified, face merging
100 always results in a fully-specified face.
105 After all face attributes for a character have been determined by
106 merging faces of that character, that face is `realized'. The
107 realization process maps face attributes to what is physically
108 available on the system where Emacs runs. The result is a
109 `realized face' in form of a struct face which is stored in the
110 face cache of the frame on which it was realized.
112 Face realization is done in the context of the character to display
113 because different fonts may be used for different characters. In
114 other words, for characters that have different font
115 specifications, different realized faces are needed to display
118 Font specification is done by fontsets. See the comment in
119 fontset.c for the details. In the current implementation, all ASCII
120 characters share the same font in a fontset.
122 Faces are at first realized for ASCII characters, and, at that
123 time, assigned a specific realized fontset. Hereafter, we call
124 such a face as `ASCII face'. When a face for a multibyte character
125 is realized, it inherits (thus shares) a fontset of an ASCII face
126 that has the same attributes other than font-related ones.
128 Thus, all realized faces have a realized fontset.
133 Unibyte text (i.e. raw 8-bit characters) is displayed with the same
134 font as ASCII characters. That is because it is expected that
135 unibyte text users specify a font that is suitable both for ASCII
136 and raw 8-bit characters.
141 Font selection tries to find the best available matching font for a
142 given (character, face) combination.
144 If the face specifies a fontset name, that fontset determines a
145 pattern for fonts of the given character. If the face specifies a
146 font name or the other font-related attributes, a fontset is
147 realized from the default fontset. In that case, that
148 specification determines a pattern for ASCII characters and the
149 default fontset determines a pattern for multibyte characters.
151 Available fonts on the system on which Emacs runs are then matched
152 against the font pattern. The result of font selection is the best
153 match for the given face attributes in this font list.
155 Font selection can be influenced by the user.
157 1. The user can specify the relative importance he gives the face
158 attributes width, height, weight, and slant by setting
159 face-font-selection-order (faces.el) to a list of face attribute
160 names. The default is '(:width :height :weight :slant), and means
161 that font selection first tries to find a good match for the font
162 width specified by a face, then---within fonts with that
163 width---tries to find a best match for the specified font height,
166 2. Setting face-font-family-alternatives allows the user to
167 specify alternative font families to try if a family specified by a
170 3. Setting face-font-registry-alternatives allows the user to
171 specify all alternative font registries to try for a face
172 specifying a registry.
174 4. Setting face-ignored-fonts allows the user to ignore specific
178 Character composition.
180 Usually, the realization process is already finished when Emacs
181 actually reflects the desired glyph matrix on the screen. However,
182 on displaying a composition (sequence of characters to be composed
183 on the screen), a suitable font for the components of the
184 composition is selected and realized while drawing them on the
185 screen, i.e. the realization process is delayed but in principle
189 Initialization of basic faces.
191 The faces `default', `modeline' are considered `basic faces'.
192 When redisplay happens the first time for a newly created frame,
193 basic faces are realized for CHARSET_ASCII. Frame parameters are
194 used to fill in unspecified attributes of the default face. */
198 #include <sys/types.h>
199 #include <sys/stat.h>
200 #include <stdio.h> /* This needs to be before termchar.h */
203 #include "character.h"
205 #include "keyboard.h"
207 #include "termhooks.h"
209 #ifdef HAVE_WINDOW_SYSTEM
211 #endif /* HAVE_WINDOW_SYSTEM */
213 #ifdef HAVE_X_WINDOWS
217 #include <Xm/XmStrDefs.h>
218 #endif /* USE_MOTIF */
219 #endif /* HAVE_X_WINDOWS */
228 /* Redefine X specifics to W32 equivalents to avoid cluttering the
229 code with #ifdef blocks. */
230 #undef FRAME_X_DISPLAY_INFO
231 #define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO
232 #define x_display_info w32_display_info
233 #define FRAME_X_FONT_TABLE FRAME_W32_FONT_TABLE
234 #define check_x check_w32
235 #define x_list_fonts w32_list_fonts
236 #define GCGraphicsExposures 0
237 #endif /* WINDOWSNT */
241 #define x_display_info mac_display_info
242 #define check_x check_mac
246 #include "dispextern.h"
247 #include "blockinput.h"
249 #include "intervals.h"
250 #include "termchar.h"
252 #ifdef HAVE_WINDOW_SYSTEM
254 #endif /* HAVE_WINDOW_SYSTEM */
256 #ifdef HAVE_X_WINDOWS
258 /* Compensate for a bug in Xos.h on some systems, on which it requires
259 time.h. On some such systems, Xos.h tries to redefine struct
260 timeval and struct timezone if USG is #defined while it is
263 #ifdef XOS_NEEDS_TIME_H
269 #else /* not XOS_NEEDS_TIME_H */
271 #endif /* not XOS_NEEDS_TIME_H */
273 #endif /* HAVE_X_WINDOWS */
277 /* Number of pt per inch (from the TeXbook). */
279 #define PT_PER_INCH 72.27
281 /* Non-zero if face attribute ATTR is unspecified. */
283 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified)
285 /* Non-zero if face attribute ATTR is `ignore-defface'. */
287 #define IGNORE_DEFFACE_P(ATTR) EQ ((ATTR), Qignore_defface)
289 /* Value is the number of elements of VECTOR. */
291 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
293 /* Make a copy of string S on the stack using alloca. Value is a pointer
296 #define STRDUPA(S) strcpy ((char *) alloca (strlen ((S)) + 1), (S))
298 /* Make a copy of the contents of Lisp string S on the stack using
299 alloca. Value is a pointer to the copy. */
301 #define LSTRDUPA(S) STRDUPA (SDATA ((S)))
303 /* Size of hash table of realized faces in face caches (should be a
306 #define FACE_CACHE_BUCKETS_SIZE 1001
308 /* Keyword symbols used for face attribute names. */
310 Lisp_Object QCfamily
, QCheight
, QCweight
, QCslant
, QCunderline
;
311 Lisp_Object QCinverse_video
, QCforeground
, QCbackground
, QCstipple
;
312 Lisp_Object QCwidth
, QCfont
, QCbold
, QCitalic
;
313 Lisp_Object QCreverse_video
;
314 Lisp_Object QCoverline
, QCstrike_through
, QCbox
, QCinherit
;
315 Lisp_Object QCfontset
;
317 /* Symbols used for attribute values. */
319 Lisp_Object Qnormal
, Qbold
, Qultra_light
, Qextra_light
, Qlight
;
320 Lisp_Object Qsemi_light
, Qsemi_bold
, Qextra_bold
, Qultra_bold
;
321 Lisp_Object Qoblique
, Qitalic
, Qreverse_oblique
, Qreverse_italic
;
322 Lisp_Object Qultra_condensed
, Qextra_condensed
, Qcondensed
;
323 Lisp_Object Qsemi_condensed
, Qsemi_expanded
, Qexpanded
, Qextra_expanded
;
324 Lisp_Object Qultra_expanded
;
325 Lisp_Object Qreleased_button
, Qpressed_button
;
326 Lisp_Object QCstyle
, QCcolor
, QCline_width
;
327 Lisp_Object Qunspecified
;
328 Lisp_Object Qignore_defface
;
330 char unspecified_fg
[] = "unspecified-fg", unspecified_bg
[] = "unspecified-bg";
332 /* The name of the function to call when the background of the frame
333 has changed, frame_set_background_mode. */
335 Lisp_Object Qframe_set_background_mode
;
337 /* Names of basic faces. */
339 Lisp_Object Qdefault
, Qtool_bar
, Qregion
, Qfringe
;
340 Lisp_Object Qheader_line
, Qscroll_bar
, Qcursor
, Qborder
, Qmouse
, Qmenu
;
341 Lisp_Object Qmode_line_inactive
, Qvertical_border
;
342 extern Lisp_Object Qmode_line
;
344 /* The symbol `face-alias'. A symbols having that property is an
345 alias for another face. Value of the property is the name of
348 Lisp_Object Qface_alias
;
350 extern Lisp_Object Qcircular_list
;
352 /* Default stipple pattern used on monochrome displays. This stipple
353 pattern is used on monochrome displays instead of shades of gray
354 for a face background color. See `set-face-stipple' for possible
355 values for this variable. */
357 Lisp_Object Vface_default_stipple
;
359 /* Alist of alternative font families. Each element is of the form
360 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
361 try FAMILY1, then FAMILY2, ... */
363 Lisp_Object Vface_alternative_font_family_alist
;
365 /* Alist of alternative font registries. Each element is of the form
366 (REGISTRY REGISTRY1 REGISTRY2...). If fonts of REGISTRY can't be
367 loaded, try REGISTRY1, then REGISTRY2, ... */
369 Lisp_Object Vface_alternative_font_registry_alist
;
371 /* Allowed scalable fonts. A value of nil means don't allow any
372 scalable fonts. A value of t means allow the use of any scalable
373 font. Otherwise, value must be a list of regular expressions. A
374 font may be scaled if its name matches a regular expression in the
377 Lisp_Object Vscalable_fonts_allowed
, Qscalable_fonts_allowed
;
379 /* List of regular expressions that matches names of fonts to ignore. */
381 Lisp_Object Vface_ignored_fonts
;
383 /* Alist of font name patterns vs the rescaling factor. */
385 Lisp_Object Vface_font_rescale_alist
;
387 /* Maximum number of fonts to consider in font_list. If not an
388 integer > 0, DEFAULT_FONT_LIST_LIMIT is used instead. */
390 Lisp_Object Vfont_list_limit
;
391 #define DEFAULT_FONT_LIST_LIMIT 100
393 /* The symbols `foreground-color' and `background-color' which can be
394 used as part of a `face' property. This is for compatibility with
397 Lisp_Object Qforeground_color
, Qbackground_color
;
399 /* The symbols `face' and `mouse-face' used as text properties. */
402 extern Lisp_Object Qmouse_face
;
404 /* Property for basic faces which other faces cannot inherit. */
406 Lisp_Object Qface_no_inherit
;
408 /* Error symbol for wrong_type_argument in load_pixmap. */
410 Lisp_Object Qbitmap_spec_p
;
412 /* Alist of global face definitions. Each element is of the form
413 (FACE . LFACE) where FACE is a symbol naming a face and LFACE
414 is a Lisp vector of face attributes. These faces are used
415 to initialize faces for new frames. */
417 Lisp_Object Vface_new_frame_defaults
;
419 /* The next ID to assign to Lisp faces. */
421 static int next_lface_id
;
423 /* A vector mapping Lisp face Id's to face names. */
425 static Lisp_Object
*lface_id_to_name
;
426 static int lface_id_to_name_size
;
428 /* TTY color-related functions (defined in tty-colors.el). */
430 Lisp_Object Qtty_color_desc
, Qtty_color_by_index
, Qtty_color_standard_values
;
432 /* The name of the function used to compute colors on TTYs. */
434 Lisp_Object Qtty_color_alist
;
436 /* An alist of defined terminal colors and their RGB values. */
438 Lisp_Object Vtty_defined_color_alist
;
440 /* Counter for calls to clear_face_cache. If this counter reaches
441 CLEAR_FONT_TABLE_COUNT, and a frame has more than
442 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
444 static int clear_font_table_count
;
445 #define CLEAR_FONT_TABLE_COUNT 100
446 #define CLEAR_FONT_TABLE_NFONTS 10
448 /* Non-zero means face attributes have been changed since the last
449 redisplay. Used in redisplay_internal. */
451 int face_change_count
;
453 /* Non-zero means don't display bold text if a face's foreground
454 and background colors are the inverse of the default colors of the
455 display. This is a kluge to suppress `bold black' foreground text
456 which is hard to read on an LCD monitor. */
458 int tty_suppress_bold_inverse_default_colors_p
;
460 /* A list of the form `((x . y))' used to avoid consing in
461 Finternal_set_lisp_face_attribute. */
463 static Lisp_Object Vparam_value_alist
;
465 /* The total number of colors currently allocated. */
468 static int ncolors_allocated
;
469 static int npixmaps_allocated
;
473 /* Non-zero means the definition of the `menu' face for new frames has
476 int menu_face_changed_default
;
479 /* Function prototypes. */
483 struct named_merge_point
;
485 static void map_tty_color
P_ ((struct frame
*, struct face
*,
486 enum lface_attribute_index
, int *));
487 static Lisp_Object resolve_face_name
P_ ((Lisp_Object
, int));
488 static int may_use_scalable_font_p
P_ ((const char *));
489 static void set_font_frame_param
P_ ((Lisp_Object
, Lisp_Object
));
490 static int better_font_p
P_ ((int *, struct font_name
*, struct font_name
*,
492 static int x_face_list_fonts
P_ ((struct frame
*, char *,
493 struct font_name
**, int, int));
494 static int font_scalable_p
P_ ((struct font_name
*));
495 static int get_lface_attributes
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
*, int));
496 static int load_pixmap
P_ ((struct frame
*, Lisp_Object
, unsigned *, unsigned *));
497 static unsigned char *xstrlwr
P_ ((unsigned char *));
498 static struct frame
*frame_or_selected_frame
P_ ((Lisp_Object
, int));
499 static void load_face_font
P_ ((struct frame
*, struct face
*));
500 static void load_face_colors
P_ ((struct frame
*, struct face
*, Lisp_Object
*));
501 static void free_face_colors
P_ ((struct frame
*, struct face
*));
502 static int face_color_gray_p
P_ ((struct frame
*, char *));
503 static char *build_font_name
P_ ((struct font_name
*));
504 static void free_font_names
P_ ((struct font_name
*, int));
505 static int sorted_font_list
P_ ((struct frame
*, char *,
506 int (*cmpfn
) P_ ((const void *, const void *)),
507 struct font_name
**));
508 static int font_list_1
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
509 Lisp_Object
, struct font_name
**));
510 static int font_list
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
511 Lisp_Object
, struct font_name
**));
512 static int try_font_list
P_ ((struct frame
*, Lisp_Object
,
513 Lisp_Object
, Lisp_Object
, struct font_name
**));
514 static int try_alternative_families
P_ ((struct frame
*f
, Lisp_Object
,
515 Lisp_Object
, struct font_name
**));
516 static int cmp_font_names
P_ ((const void *, const void *));
517 static struct face
*realize_face
P_ ((struct face_cache
*, Lisp_Object
*,
519 static struct face
*realize_non_ascii_face
P_ ((struct frame
*, int,
521 static struct face
*realize_x_face
P_ ((struct face_cache
*, Lisp_Object
*));
522 static struct face
*realize_tty_face
P_ ((struct face_cache
*, Lisp_Object
*));
523 static int realize_basic_faces
P_ ((struct frame
*));
524 static int realize_default_face
P_ ((struct frame
*));
525 static void realize_named_face
P_ ((struct frame
*, Lisp_Object
, int));
526 static int lface_fully_specified_p
P_ ((Lisp_Object
*));
527 static int lface_equal_p
P_ ((Lisp_Object
*, Lisp_Object
*));
528 static unsigned hash_string_case_insensitive
P_ ((Lisp_Object
));
529 static unsigned lface_hash
P_ ((Lisp_Object
*));
530 static int lface_same_font_attributes_p
P_ ((Lisp_Object
*, Lisp_Object
*));
531 static struct face_cache
*make_face_cache
P_ ((struct frame
*));
532 static void clear_face_gcs
P_ ((struct face_cache
*));
533 static void free_face_cache
P_ ((struct face_cache
*));
534 static int face_numeric_weight
P_ ((Lisp_Object
));
535 static int face_numeric_slant
P_ ((Lisp_Object
));
536 static int face_numeric_swidth
P_ ((Lisp_Object
));
537 static int face_fontset
P_ ((Lisp_Object
*));
538 static void merge_face_vectors
P_ ((struct frame
*, Lisp_Object
*, Lisp_Object
*,
539 struct named_merge_point
*));
540 static int merge_face_ref
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
*,
541 int, struct named_merge_point
*));
542 static int set_lface_from_font_name
P_ ((struct frame
*, Lisp_Object
,
543 Lisp_Object
, int, int));
544 static void set_lface_from_font_and_fontset
P_ ((struct frame
*, Lisp_Object
,
545 Lisp_Object
, int, int));
546 static Lisp_Object lface_from_face_name
P_ ((struct frame
*, Lisp_Object
, int));
547 static struct face
*make_realized_face
P_ ((Lisp_Object
*));
548 static char *best_matching_font
P_ ((struct frame
*, Lisp_Object
*,
549 struct font_name
*, int, int, int *));
550 static void cache_face
P_ ((struct face_cache
*, struct face
*, unsigned));
551 static void uncache_face
P_ ((struct face_cache
*, struct face
*));
552 static int xlfd_numeric_slant
P_ ((struct font_name
*));
553 static int xlfd_numeric_weight
P_ ((struct font_name
*));
554 static int xlfd_numeric_swidth
P_ ((struct font_name
*));
555 static Lisp_Object xlfd_symbolic_slant
P_ ((struct font_name
*));
556 static Lisp_Object xlfd_symbolic_weight
P_ ((struct font_name
*));
557 static Lisp_Object xlfd_symbolic_swidth
P_ ((struct font_name
*));
558 static int xlfd_fixed_p
P_ ((struct font_name
*));
559 static int xlfd_numeric_value
P_ ((struct table_entry
*, int, struct font_name
*,
561 static Lisp_Object xlfd_symbolic_value
P_ ((struct table_entry
*, int,
562 struct font_name
*, int,
564 static struct table_entry
*xlfd_lookup_field_contents
P_ ((struct table_entry
*, int,
565 struct font_name
*, int));
567 #ifdef HAVE_WINDOW_SYSTEM
569 static int split_font_name
P_ ((struct frame
*, struct font_name
*, int));
570 static int xlfd_point_size
P_ ((struct frame
*, struct font_name
*));
571 static void sort_fonts
P_ ((struct frame
*, struct font_name
*, int,
572 int (*cmpfn
) P_ ((const void *, const void *))));
573 static GC x_create_gc
P_ ((struct frame
*, unsigned long, XGCValues
*));
574 static void x_free_gc
P_ ((struct frame
*, GC
));
575 static void clear_font_table
P_ ((struct x_display_info
*));
578 extern Lisp_Object w32_list_fonts
P_ ((struct frame
*, Lisp_Object
, int, int));
579 #endif /* WINDOWSNT */
582 static void x_update_menu_appearance
P_ ((struct frame
*));
584 extern void free_frame_menubar
P_ ((struct frame
*));
585 #endif /* USE_X_TOOLKIT */
587 #endif /* HAVE_WINDOW_SYSTEM */
590 /***********************************************************************
592 ***********************************************************************/
594 #ifdef HAVE_X_WINDOWS
596 #ifdef DEBUG_X_COLORS
598 /* The following is a poor mans infrastructure for debugging X color
599 allocation problems on displays with PseudoColor-8. Some X servers
600 like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement
601 color reference counts completely so that they don't signal an
602 error when a color is freed whose reference count is already 0.
603 Other X servers do. To help me debug this, the following code
604 implements a simple reference counting schema of its own, for a
605 single display/screen. --gerd. */
607 /* Reference counts for pixel colors. */
609 int color_count
[256];
611 /* Register color PIXEL as allocated. */
614 register_color (pixel
)
617 xassert (pixel
< 256);
618 ++color_count
[pixel
];
622 /* Register color PIXEL as deallocated. */
625 unregister_color (pixel
)
628 xassert (pixel
< 256);
629 if (color_count
[pixel
] > 0)
630 --color_count
[pixel
];
636 /* Register N colors from PIXELS as deallocated. */
639 unregister_colors (pixels
, n
)
640 unsigned long *pixels
;
644 for (i
= 0; i
< n
; ++i
)
645 unregister_color (pixels
[i
]);
649 DEFUN ("dump-colors", Fdump_colors
, Sdump_colors
, 0, 0, 0,
650 doc
: /* Dump currently allocated colors to stderr. */)
655 fputc ('\n', stderr
);
657 for (i
= n
= 0; i
< sizeof color_count
/ sizeof color_count
[0]; ++i
)
660 fprintf (stderr
, "%3d: %5d", i
, color_count
[i
]);
663 fputc ('\n', stderr
);
665 fputc ('\t', stderr
);
669 fputc ('\n', stderr
);
673 #endif /* DEBUG_X_COLORS */
676 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
677 color values. Interrupt input must be blocked when this function
681 x_free_colors (f
, pixels
, npixels
)
683 unsigned long *pixels
;
686 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
688 /* If display has an immutable color map, freeing colors is not
689 necessary and some servers don't allow it. So don't do it. */
690 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
692 #ifdef DEBUG_X_COLORS
693 unregister_colors (pixels
, npixels
);
695 XFreeColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
701 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
702 color values. Interrupt input must be blocked when this function
706 x_free_dpy_colors (dpy
, screen
, cmap
, pixels
, npixels
)
710 unsigned long *pixels
;
713 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
714 int class = dpyinfo
->visual
->class;
716 /* If display has an immutable color map, freeing colors is not
717 necessary and some servers don't allow it. So don't do it. */
718 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
720 #ifdef DEBUG_X_COLORS
721 unregister_colors (pixels
, npixels
);
723 XFreeColors (dpy
, cmap
, pixels
, npixels
, 0);
728 /* Create and return a GC for use on frame F. GC values and mask
729 are given by XGCV and MASK. */
732 x_create_gc (f
, mask
, xgcv
)
739 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
746 /* Free GC which was used on frame F. */
753 eassert (interrupt_input_blocked
);
754 IF_DEBUG (xassert (--ngcs
>= 0));
755 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
758 #endif /* HAVE_X_WINDOWS */
761 /* W32 emulation of GCs */
764 x_create_gc (f
, mask
, xgcv
)
771 gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, xgcv
);
778 /* Free GC which was used on frame F. */
785 IF_DEBUG (xassert (--ngcs
>= 0));
789 #endif /* WINDOWSNT */
792 /* Mac OS emulation of GCs */
795 x_create_gc (f
, mask
, xgcv
)
802 gc
= XCreateGC (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), mask
, xgcv
);
813 eassert (interrupt_input_blocked
);
814 IF_DEBUG (xassert (--ngcs
>= 0));
815 XFreeGC (FRAME_MAC_DISPLAY (f
), gc
);
820 /* Like stricmp. Used to compare parts of font names which are in
825 const unsigned char *s1
, *s2
;
829 unsigned char c1
= tolower (*s1
);
830 unsigned char c2
= tolower (*s2
);
832 return c1
< c2
? -1 : 1;
837 return *s2
== 0 ? 0 : -1;
842 /* Like strlwr, which might not always be available. */
844 static unsigned char *
848 unsigned char *p
= s
;
851 /* On Mac OS X 10.3, tolower also converts non-ASCII characters
860 /* If FRAME is nil, return a pointer to the selected frame.
861 Otherwise, check that FRAME is a live frame, and return a pointer
862 to it. NPARAM is the parameter number of FRAME, for
863 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
864 Lisp function definitions. */
866 static INLINE
struct frame
*
867 frame_or_selected_frame (frame
, nparam
)
872 frame
= selected_frame
;
874 CHECK_LIVE_FRAME (frame
);
875 return XFRAME (frame
);
879 /***********************************************************************
881 ***********************************************************************/
883 /* Initialize face cache and basic faces for frame F. */
889 /* Make a face cache, if F doesn't have one. */
890 if (FRAME_FACE_CACHE (f
) == NULL
)
891 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
893 #ifdef HAVE_WINDOW_SYSTEM
894 /* Make the image cache. */
895 if (FRAME_WINDOW_P (f
))
897 if (FRAME_IMAGE_CACHE (f
) == NULL
)
898 /* Is that ever possible?? --Stef */
899 FRAME_IMAGE_CACHE (f
) = make_image_cache ();
900 ++FRAME_IMAGE_CACHE (f
)->refcount
;
902 #endif /* HAVE_WINDOW_SYSTEM */
904 /* Realize basic faces. Must have enough information in frame
905 parameters to realize basic faces at this point. */
906 #ifdef HAVE_X_WINDOWS
907 if (!FRAME_X_P (f
) || FRAME_X_WINDOW (f
))
910 if (!FRAME_WINDOW_P (f
) || FRAME_W32_WINDOW (f
))
913 if (!FRAME_MAC_P (f
) || FRAME_MAC_WINDOW (f
))
915 if (!realize_basic_faces (f
))
920 /* Free face cache of frame F. Called from Fdelete_frame. */
926 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
930 free_face_cache (face_cache
);
931 FRAME_FACE_CACHE (f
) = NULL
;
934 #ifdef HAVE_WINDOW_SYSTEM
935 if (FRAME_WINDOW_P (f
))
937 struct image_cache
*image_cache
= FRAME_IMAGE_CACHE (f
);
940 --image_cache
->refcount
;
941 if (image_cache
->refcount
== 0)
942 free_image_cache (f
);
945 #endif /* HAVE_WINDOW_SYSTEM */
949 /* Clear face caches, and recompute basic faces for frame F. Call
950 this after changing frame parameters on which those faces depend,
951 or when realized faces have been freed due to changing attributes
955 recompute_basic_faces (f
)
958 if (FRAME_FACE_CACHE (f
))
960 clear_face_cache (0);
961 if (!realize_basic_faces (f
))
967 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
968 try to free unused fonts, too. */
971 clear_face_cache (clear_fonts_p
)
974 #ifdef HAVE_WINDOW_SYSTEM
975 Lisp_Object tail
, frame
;
979 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
981 struct x_display_info
*dpyinfo
;
983 #ifdef USE_FONT_BACKEND
984 if (! enable_font_backend
)
985 #endif /* USE_FONT_BACKEND */
986 /* Fonts are common for frames on one display, i.e. on
988 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
989 if (dpyinfo
->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
990 clear_font_table (dpyinfo
);
992 /* From time to time see if we can unload some fonts. This also
993 frees all realized faces on all frames. Fonts needed by
994 faces will be loaded again when faces are realized again. */
995 clear_font_table_count
= 0;
997 FOR_EACH_FRAME (tail
, frame
)
999 struct frame
*f
= XFRAME (frame
);
1000 if (FRAME_WINDOW_P (f
)
1001 && FRAME_X_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
1002 free_all_realized_faces (frame
);
1007 /* Clear GCs of realized faces. */
1008 FOR_EACH_FRAME (tail
, frame
)
1011 if (FRAME_WINDOW_P (f
))
1012 clear_face_gcs (FRAME_FACE_CACHE (f
));
1014 clear_image_caches (Qnil
);
1016 #endif /* HAVE_WINDOW_SYSTEM */
1020 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
1021 doc
: /* Clear face caches on all frames.
1022 Optional THOROUGHLY non-nil means try to free unused fonts, too. */)
1024 Lisp_Object thoroughly
;
1026 clear_face_cache (!NILP (thoroughly
));
1027 ++face_change_count
;
1028 ++windows_or_buffers_changed
;
1034 #ifdef HAVE_WINDOW_SYSTEM
1037 /* Remove fonts from the font table of DPYINFO except for the default
1038 ASCII fonts of frames on that display. Called from clear_face_cache
1039 from time to time. */
1042 clear_font_table (dpyinfo
)
1043 struct x_display_info
*dpyinfo
;
1047 /* Free those fonts that are not used by frames on DPYINFO. */
1048 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
1050 struct font_info
*font_info
= dpyinfo
->font_table
+ i
;
1051 Lisp_Object tail
, frame
;
1053 /* Check if slot is already free. */
1054 if (font_info
->name
== NULL
)
1057 /* Don't free a default font of some frame. */
1058 FOR_EACH_FRAME (tail
, frame
)
1060 struct frame
*f
= XFRAME (frame
);
1061 if (FRAME_WINDOW_P (f
)
1062 && font_info
->font
== FRAME_FONT (f
))
1070 if (font_info
->full_name
!= font_info
->name
)
1071 xfree (font_info
->full_name
);
1072 xfree (font_info
->name
);
1074 /* Free the font. */
1076 #ifdef HAVE_X_WINDOWS
1077 XFreeFont (dpyinfo
->display
, font_info
->font
);
1080 w32_unload_font (dpyinfo
, font_info
->font
);
1083 mac_unload_font (dpyinfo
, font_info
->font
);
1087 /* Mark font table slot free. */
1088 font_info
->font
= NULL
;
1089 font_info
->name
= font_info
->full_name
= NULL
;
1093 #endif /* HAVE_WINDOW_SYSTEM */
1097 /***********************************************************************
1099 ***********************************************************************/
1101 #ifdef HAVE_WINDOW_SYSTEM
1103 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
1104 doc
: /* Value is non-nil if OBJECT is a valid bitmap specification.
1105 A bitmap specification is either a string, a file name, or a list
1106 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
1107 HEIGHT is its height, and DATA is a string containing the bits of
1108 the pixmap. Bits are stored row by row, each row occupies
1109 \(WIDTH + 7)/8 bytes. */)
1115 if (STRINGP (object
))
1116 /* If OBJECT is a string, it's a file name. */
1118 else if (CONSP (object
))
1120 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
1121 HEIGHT must be integers > 0, and DATA must be string large
1122 enough to hold a bitmap of the specified size. */
1123 Lisp_Object width
, height
, data
;
1125 height
= width
= data
= Qnil
;
1129 width
= XCAR (object
);
1130 object
= XCDR (object
);
1133 height
= XCAR (object
);
1134 object
= XCDR (object
);
1136 data
= XCAR (object
);
1140 if (NATNUMP (width
) && NATNUMP (height
) && STRINGP (data
))
1142 int bytes_per_row
= ((XFASTINT (width
) + BITS_PER_CHAR
- 1)
1144 if (SBYTES (data
) >= bytes_per_row
* XINT (height
))
1149 return pixmap_p
? Qt
: Qnil
;
1153 /* Load a bitmap according to NAME (which is either a file name or a
1154 pixmap spec) for use on frame F. Value is the bitmap_id (see
1155 xfns.c). If NAME is nil, return with a bitmap id of zero. If
1156 bitmap cannot be loaded, display a message saying so, and return
1157 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
1158 if these pointers are not null. */
1161 load_pixmap (f
, name
, w_ptr
, h_ptr
)
1164 unsigned int *w_ptr
, *h_ptr
;
1171 CHECK_TYPE (!NILP (Fbitmap_spec_p (name
)), Qbitmap_spec_p
, name
);
1176 /* Decode a bitmap spec into a bitmap. */
1181 w
= XINT (Fcar (name
));
1182 h
= XINT (Fcar (Fcdr (name
)));
1183 bits
= Fcar (Fcdr (Fcdr (name
)));
1185 bitmap_id
= x_create_bitmap_from_data (f
, SDATA (bits
),
1190 /* It must be a string -- a file name. */
1191 bitmap_id
= x_create_bitmap_from_file (f
, name
);
1197 add_to_log ("Invalid or undefined bitmap `%s'", name
, Qnil
);
1208 ++npixmaps_allocated
;
1211 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
1214 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
1220 #endif /* HAVE_WINDOW_SYSTEM */
1224 /***********************************************************************
1226 ***********************************************************************/
1228 #ifdef HAVE_WINDOW_SYSTEM
1230 /* Load font of face FACE which is used on frame F to display ASCII
1231 characters. The name of the font to load is determined by lface. */
1234 load_face_font (f
, face
)
1238 struct font_info
*font_info
= NULL
;
1240 int needs_overstrike
;
1242 #ifdef USE_FONT_BACKEND
1243 if (enable_font_backend
)
1245 #endif /* USE_FONT_BACKEND */
1246 face
->font_info_id
= -1;
1248 face
->font_name
= NULL
;
1250 font_name
= choose_face_font (f
, face
->lface
, Qnil
, &needs_overstrike
);
1255 font_info
= FS_LOAD_FONT (f
, font_name
);
1260 face
->font_info_id
= font_info
->font_idx
;
1261 face
->font
= font_info
->font
;
1262 face
->font_name
= font_info
->full_name
;
1263 face
->overstrike
= needs_overstrike
;
1267 x_free_gc (f
, face
->gc
);
1273 add_to_log ("Unable to load font %s",
1274 build_string (font_name
), Qnil
);
1278 #endif /* HAVE_WINDOW_SYSTEM */
1282 /***********************************************************************
1284 ***********************************************************************/
1286 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
1287 RGB_LIST should contain (at least) 3 lisp integers.
1288 Return 0 if there's a problem with RGB_LIST, otherwise return 1. */
1291 parse_rgb_list (rgb_list
, color
)
1292 Lisp_Object rgb_list
;
1295 #define PARSE_RGB_LIST_FIELD(field) \
1296 if (CONSP (rgb_list) && INTEGERP (XCAR (rgb_list))) \
1298 color->field = XINT (XCAR (rgb_list)); \
1299 rgb_list = XCDR (rgb_list); \
1304 PARSE_RGB_LIST_FIELD (red
);
1305 PARSE_RGB_LIST_FIELD (green
);
1306 PARSE_RGB_LIST_FIELD (blue
);
1312 /* Lookup on frame F the color described by the lisp string COLOR.
1313 The resulting tty color is returned in TTY_COLOR; if STD_COLOR is
1314 non-zero, then the `standard' definition of the same color is
1318 tty_lookup_color (f
, color
, tty_color
, std_color
)
1321 XColor
*tty_color
, *std_color
;
1323 Lisp_Object frame
, color_desc
;
1325 if (!STRINGP (color
) || NILP (Ffboundp (Qtty_color_desc
)))
1328 XSETFRAME (frame
, f
);
1330 color_desc
= call2 (Qtty_color_desc
, color
, frame
);
1331 if (CONSP (color_desc
) && CONSP (XCDR (color_desc
)))
1335 if (! INTEGERP (XCAR (XCDR (color_desc
))))
1338 tty_color
->pixel
= XINT (XCAR (XCDR (color_desc
)));
1340 rgb
= XCDR (XCDR (color_desc
));
1341 if (! parse_rgb_list (rgb
, tty_color
))
1344 /* Should we fill in STD_COLOR too? */
1347 /* Default STD_COLOR to the same as TTY_COLOR. */
1348 *std_color
= *tty_color
;
1350 /* Do a quick check to see if the returned descriptor is
1351 actually _exactly_ equal to COLOR, otherwise we have to
1352 lookup STD_COLOR separately. If it's impossible to lookup
1353 a standard color, we just give up and use TTY_COLOR. */
1354 if ((!STRINGP (XCAR (color_desc
))
1355 || NILP (Fstring_equal (color
, XCAR (color_desc
))))
1356 && !NILP (Ffboundp (Qtty_color_standard_values
)))
1358 /* Look up STD_COLOR separately. */
1359 rgb
= call1 (Qtty_color_standard_values
, color
);
1360 if (! parse_rgb_list (rgb
, std_color
))
1367 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
1368 /* We were called early during startup, and the colors are not
1369 yet set up in tty-defined-color-alist. Don't return a failure
1370 indication, since this produces the annoying "Unable to
1371 load color" messages in the *Messages* buffer. */
1374 /* tty-color-desc seems to have returned a bad value. */
1378 /* A version of defined_color for non-X frames. */
1381 tty_defined_color (f
, color_name
, color_def
, alloc
)
1390 color_def
->pixel
= FACE_TTY_DEFAULT_COLOR
;
1392 color_def
->blue
= 0;
1393 color_def
->green
= 0;
1396 status
= tty_lookup_color (f
, build_string (color_name
), color_def
, NULL
);
1398 if (color_def
->pixel
== FACE_TTY_DEFAULT_COLOR
&& *color_name
)
1400 if (strcmp (color_name
, "unspecified-fg") == 0)
1401 color_def
->pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
1402 else if (strcmp (color_name
, "unspecified-bg") == 0)
1403 color_def
->pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
1406 if (color_def
->pixel
!= FACE_TTY_DEFAULT_COLOR
)
1413 /* Decide if color named COLOR_NAME is valid for the display
1414 associated with the frame F; if so, return the rgb values in
1415 COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell.
1417 This does the right thing for any type of frame. */
1420 defined_color (f
, color_name
, color_def
, alloc
)
1426 if (!FRAME_WINDOW_P (f
))
1427 return tty_defined_color (f
, color_name
, color_def
, alloc
);
1428 #ifdef HAVE_X_WINDOWS
1429 else if (FRAME_X_P (f
))
1430 return x_defined_color (f
, color_name
, color_def
, alloc
);
1433 else if (FRAME_W32_P (f
))
1434 return w32_defined_color (f
, color_name
, color_def
, alloc
);
1437 else if (FRAME_MAC_P (f
))
1438 return mac_defined_color (f
, color_name
, color_def
, alloc
);
1445 /* Given the index IDX of a tty color on frame F, return its name, a
1449 tty_color_name (f
, idx
)
1453 if (idx
>= 0 && !NILP (Ffboundp (Qtty_color_by_index
)))
1456 Lisp_Object coldesc
;
1458 XSETFRAME (frame
, f
);
1459 coldesc
= call2 (Qtty_color_by_index
, make_number (idx
), frame
);
1461 if (!NILP (coldesc
))
1462 return XCAR (coldesc
);
1465 /* We can have an MSDOG frame under -nw for a short window of
1466 opportunity before internal_terminal_init is called. DTRT. */
1467 if (FRAME_MSDOS_P (f
) && !inhibit_window_system
)
1468 return msdos_stdcolor_name (idx
);
1471 if (idx
== FACE_TTY_DEFAULT_FG_COLOR
)
1472 return build_string (unspecified_fg
);
1473 if (idx
== FACE_TTY_DEFAULT_BG_COLOR
)
1474 return build_string (unspecified_bg
);
1476 return Qunspecified
;
1480 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1483 The criterion implemented here is not a terribly sophisticated one. */
1486 face_color_gray_p (f
, color_name
)
1493 if (defined_color (f
, color_name
, &color
, 0))
1494 gray_p
= (/* Any color sufficiently close to black counts as grey. */
1495 (color
.red
< 5000 && color
.green
< 5000 && color
.blue
< 5000)
1497 ((eabs (color
.red
- color
.green
)
1498 < max (color
.red
, color
.green
) / 20)
1499 && (eabs (color
.green
- color
.blue
)
1500 < max (color
.green
, color
.blue
) / 20)
1501 && (eabs (color
.blue
- color
.red
)
1502 < max (color
.blue
, color
.red
) / 20)));
1510 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1511 BACKGROUND_P non-zero means the color will be used as background
1515 face_color_supported_p (f
, color_name
, background_p
)
1523 XSETFRAME (frame
, f
);
1525 #ifdef HAVE_WINDOW_SYSTEM
1527 ? (!NILP (Fxw_display_color_p (frame
))
1528 || xstricmp (color_name
, "black") == 0
1529 || xstricmp (color_name
, "white") == 0
1531 && face_color_gray_p (f
, color_name
))
1532 || (!NILP (Fx_display_grayscale_p (frame
))
1533 && face_color_gray_p (f
, color_name
)))
1536 tty_defined_color (f
, color_name
, ¬_used
, 0);
1540 DEFUN ("color-gray-p", Fcolor_gray_p
, Scolor_gray_p
, 1, 2, 0,
1541 doc
: /* Return non-nil if COLOR is a shade of gray (or white or black).
1542 FRAME specifies the frame and thus the display for interpreting COLOR.
1543 If FRAME is nil or omitted, use the selected frame. */)
1545 Lisp_Object color
, frame
;
1549 CHECK_STRING (color
);
1551 frame
= selected_frame
;
1553 CHECK_FRAME (frame
);
1555 return face_color_gray_p (f
, SDATA (color
)) ? Qt
: Qnil
;
1559 DEFUN ("color-supported-p", Fcolor_supported_p
,
1560 Scolor_supported_p
, 1, 3, 0,
1561 doc
: /* Return non-nil if COLOR can be displayed on FRAME.
1562 BACKGROUND-P non-nil means COLOR is used as a background.
1563 Otherwise, this function tells whether it can be used as a foreground.
1564 If FRAME is nil or omitted, use the selected frame.
1565 COLOR must be a valid color name. */)
1566 (color
, frame
, background_p
)
1567 Lisp_Object frame
, color
, background_p
;
1571 CHECK_STRING (color
);
1573 frame
= selected_frame
;
1575 CHECK_FRAME (frame
);
1577 if (face_color_supported_p (f
, SDATA (color
), !NILP (background_p
)))
1583 /* Load color with name NAME for use by face FACE on frame F.
1584 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1585 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1586 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1587 pixel color. If color cannot be loaded, display a message, and
1588 return the foreground, background or underline color of F, but
1589 record that fact in flags of the face so that we don't try to free
1593 load_color (f
, face
, name
, target_index
)
1597 enum lface_attribute_index target_index
;
1601 xassert (STRINGP (name
));
1602 xassert (target_index
== LFACE_FOREGROUND_INDEX
1603 || target_index
== LFACE_BACKGROUND_INDEX
1604 || target_index
== LFACE_UNDERLINE_INDEX
1605 || target_index
== LFACE_OVERLINE_INDEX
1606 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1607 || target_index
== LFACE_BOX_INDEX
);
1609 /* if the color map is full, defined_color will return a best match
1610 to the values in an existing cell. */
1611 if (!defined_color (f
, SDATA (name
), &color
, 1))
1613 add_to_log ("Unable to load color \"%s\"", name
, Qnil
);
1615 switch (target_index
)
1617 case LFACE_FOREGROUND_INDEX
:
1618 face
->foreground_defaulted_p
= 1;
1619 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1622 case LFACE_BACKGROUND_INDEX
:
1623 face
->background_defaulted_p
= 1;
1624 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1627 case LFACE_UNDERLINE_INDEX
:
1628 face
->underline_defaulted_p
= 1;
1629 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1632 case LFACE_OVERLINE_INDEX
:
1633 face
->overline_color_defaulted_p
= 1;
1634 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1637 case LFACE_STRIKE_THROUGH_INDEX
:
1638 face
->strike_through_color_defaulted_p
= 1;
1639 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1642 case LFACE_BOX_INDEX
:
1643 face
->box_color_defaulted_p
= 1;
1644 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1653 ++ncolors_allocated
;
1660 #ifdef HAVE_WINDOW_SYSTEM
1662 /* Load colors for face FACE which is used on frame F. Colors are
1663 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1664 of ATTRS. If the background color specified is not supported on F,
1665 try to emulate gray colors with a stipple from Vface_default_stipple. */
1668 load_face_colors (f
, face
, attrs
)
1675 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1676 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1678 /* Swap colors if face is inverse-video. */
1679 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1687 /* Check for support for foreground, not for background because
1688 face_color_supported_p is smart enough to know that grays are
1689 "supported" as background because we are supposed to use stipple
1691 if (!face_color_supported_p (f
, SDATA (bg
), 0)
1692 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1694 x_destroy_bitmap (f
, face
->stipple
);
1695 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1696 &face
->pixmap_w
, &face
->pixmap_h
);
1699 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1700 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1704 /* Free color PIXEL on frame F. */
1707 unload_color (f
, pixel
)
1709 unsigned long pixel
;
1711 #ifdef HAVE_X_WINDOWS
1715 x_free_colors (f
, &pixel
, 1);
1722 /* Free colors allocated for FACE. */
1725 free_face_colors (f
, face
)
1729 #ifdef HAVE_X_WINDOWS
1730 if (face
->colors_copied_bitwise_p
)
1735 if (!face
->foreground_defaulted_p
)
1737 x_free_colors (f
, &face
->foreground
, 1);
1738 IF_DEBUG (--ncolors_allocated
);
1741 if (!face
->background_defaulted_p
)
1743 x_free_colors (f
, &face
->background
, 1);
1744 IF_DEBUG (--ncolors_allocated
);
1747 if (face
->underline_p
1748 && !face
->underline_defaulted_p
)
1750 x_free_colors (f
, &face
->underline_color
, 1);
1751 IF_DEBUG (--ncolors_allocated
);
1754 if (face
->overline_p
1755 && !face
->overline_color_defaulted_p
)
1757 x_free_colors (f
, &face
->overline_color
, 1);
1758 IF_DEBUG (--ncolors_allocated
);
1761 if (face
->strike_through_p
1762 && !face
->strike_through_color_defaulted_p
)
1764 x_free_colors (f
, &face
->strike_through_color
, 1);
1765 IF_DEBUG (--ncolors_allocated
);
1768 if (face
->box
!= FACE_NO_BOX
1769 && !face
->box_color_defaulted_p
)
1771 x_free_colors (f
, &face
->box_color
, 1);
1772 IF_DEBUG (--ncolors_allocated
);
1776 #endif /* HAVE_X_WINDOWS */
1779 #endif /* HAVE_WINDOW_SYSTEM */
1783 /***********************************************************************
1785 ***********************************************************************/
1787 /* An enumerator for each field of an XLFD font name. */
1808 /* An enumerator for each possible slant value of a font. Taken from
1809 the XLFD specification. */
1817 XLFD_SLANT_REVERSE_ITALIC
,
1818 XLFD_SLANT_REVERSE_OBLIQUE
,
1822 /* Relative font weight according to XLFD documentation. */
1826 XLFD_WEIGHT_UNKNOWN
,
1827 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1828 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1829 XLFD_WEIGHT_LIGHT
, /* 30 */
1830 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1831 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1832 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1833 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1834 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1835 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1838 /* Relative proportionate width. */
1842 XLFD_SWIDTH_UNKNOWN
,
1843 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1844 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1845 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1846 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1847 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1848 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1849 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1850 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1851 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1854 /* Structure used for tables mapping XLFD weight, slant, and width
1855 names to numeric and symbolic values. */
1861 Lisp_Object
*symbol
;
1864 /* Table of XLFD slant names and their numeric and symbolic
1865 representations. This table must be sorted by slant names in
1868 static struct table_entry slant_table
[] =
1870 {"i", XLFD_SLANT_ITALIC
, &Qitalic
},
1871 {"o", XLFD_SLANT_OBLIQUE
, &Qoblique
},
1872 {"ot", XLFD_SLANT_OTHER
, &Qitalic
},
1873 {"r", XLFD_SLANT_ROMAN
, &Qnormal
},
1874 {"ri", XLFD_SLANT_REVERSE_ITALIC
, &Qreverse_italic
},
1875 {"ro", XLFD_SLANT_REVERSE_OBLIQUE
, &Qreverse_oblique
}
1878 /* Table of XLFD weight names. This table must be sorted by weight
1879 names in ascending order. */
1881 static struct table_entry weight_table
[] =
1883 {"black", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
},
1884 {"bold", XLFD_WEIGHT_BOLD
, &Qbold
},
1885 {"book", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1886 {"demi", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1887 {"demibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1888 {"extralight", XLFD_WEIGHT_EXTRA_LIGHT
, &Qextra_light
},
1889 {"extrabold", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1890 {"heavy", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1891 {"light", XLFD_WEIGHT_LIGHT
, &Qlight
},
1892 {"medium", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1893 {"normal", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1894 {"regular", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1895 {"semibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1896 {"semilight", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1897 {"ultralight", XLFD_WEIGHT_ULTRA_LIGHT
, &Qultra_light
},
1898 {"ultrabold", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
}
1901 /* Table of XLFD width names. This table must be sorted by width
1902 names in ascending order. */
1904 static struct table_entry swidth_table
[] =
1906 {"compressed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1907 {"condensed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1908 {"demiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1909 {"expanded", XLFD_SWIDTH_EXPANDED
, &Qexpanded
},
1910 {"extracondensed", XLFD_SWIDTH_EXTRA_CONDENSED
, &Qextra_condensed
},
1911 {"extraexpanded", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
},
1912 {"medium", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1913 {"narrow", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1914 {"normal", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1915 {"regular", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1916 {"semicondensed", XLFD_SWIDTH_SEMI_CONDENSED
, &Qsemi_condensed
},
1917 {"semiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1918 {"ultracondensed", XLFD_SWIDTH_ULTRA_CONDENSED
, &Qultra_condensed
},
1919 {"ultraexpanded", XLFD_SWIDTH_ULTRA_EXPANDED
, &Qultra_expanded
},
1920 {"wide", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
}
1923 /* Structure used to hold the result of splitting font names in XLFD
1924 format into their fields. */
1928 /* The original name which is modified destructively by
1929 split_font_name. The pointer is kept here to be able to free it
1930 if it was allocated from the heap. */
1933 /* Font name fields. Each vector element points into `name' above.
1934 Fields are NUL-terminated. */
1935 char *fields
[XLFD_LAST
];
1937 /* Numeric values for those fields that interest us. See
1938 split_font_name for which these are. */
1939 int numeric
[XLFD_LAST
];
1941 /* If the original name matches one of Vface_font_rescale_alist,
1942 the value is the corresponding rescale ratio. Otherwise, the
1944 double rescale_ratio
;
1946 /* Lower value mean higher priority. */
1947 int registry_priority
;
1950 /* The frame in effect when sorting font names. Set temporarily in
1951 sort_fonts so that it is available in font comparison functions. */
1953 static struct frame
*font_frame
;
1955 /* Order by which font selection chooses fonts. The default values
1956 mean `first, find a best match for the font width, then for the
1957 font height, then for weight, then for slant.' This variable can be
1958 set via set-face-font-sort-order. */
1961 static int font_sort_order
[4] = {
1962 XLFD_SWIDTH
, XLFD_POINT_SIZE
, XLFD_WEIGHT
, XLFD_SLANT
1965 static int font_sort_order
[4];
1968 /* Look up FONT.fields[FIELD_INDEX] in TABLE which has DIM entries.
1969 TABLE must be sorted by TABLE[i]->name in ascending order. Value
1970 is a pointer to the matching table entry or null if no table entry
1973 static struct table_entry
*
1974 xlfd_lookup_field_contents (table
, dim
, font
, field_index
)
1975 struct table_entry
*table
;
1977 struct font_name
*font
;
1980 /* Function split_font_name converts fields to lower-case, so there
1981 is no need to use xstrlwr or xstricmp here. */
1982 char *s
= font
->fields
[field_index
];
1983 int low
, mid
, high
, cmp
;
1990 mid
= (low
+ high
) / 2;
1991 cmp
= strcmp (table
[mid
].name
, s
);
2005 /* Return a numeric representation for font name field
2006 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
2007 has DIM entries. Value is the numeric value found or DFLT if no
2008 table entry matches. This function is used to translate weight,
2009 slant, and swidth names of XLFD font names to numeric values. */
2012 xlfd_numeric_value (table
, dim
, font
, field_index
, dflt
)
2013 struct table_entry
*table
;
2015 struct font_name
*font
;
2019 struct table_entry
*p
;
2020 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
2021 return p
? p
->numeric
: dflt
;
2025 /* Return a symbolic representation for font name field
2026 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
2027 has DIM entries. Value is the symbolic value found or DFLT if no
2028 table entry matches. This function is used to translate weight,
2029 slant, and swidth names of XLFD font names to symbols. */
2031 static INLINE Lisp_Object
2032 xlfd_symbolic_value (table
, dim
, font
, field_index
, dflt
)
2033 struct table_entry
*table
;
2035 struct font_name
*font
;
2039 struct table_entry
*p
;
2040 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
2041 return p
? *p
->symbol
: dflt
;
2045 /* Return a numeric value for the slant of the font given by FONT. */
2048 xlfd_numeric_slant (font
)
2049 struct font_name
*font
;
2051 return xlfd_numeric_value (slant_table
, DIM (slant_table
),
2052 font
, XLFD_SLANT
, XLFD_SLANT_ROMAN
);
2056 /* Return a symbol representing the weight of the font given by FONT. */
2058 static INLINE Lisp_Object
2059 xlfd_symbolic_slant (font
)
2060 struct font_name
*font
;
2062 return xlfd_symbolic_value (slant_table
, DIM (slant_table
),
2063 font
, XLFD_SLANT
, Qnormal
);
2067 /* Return a numeric value for the weight of the font given by FONT. */
2070 xlfd_numeric_weight (font
)
2071 struct font_name
*font
;
2073 return xlfd_numeric_value (weight_table
, DIM (weight_table
),
2074 font
, XLFD_WEIGHT
, XLFD_WEIGHT_MEDIUM
);
2078 /* Return a symbol representing the slant of the font given by FONT. */
2080 static INLINE Lisp_Object
2081 xlfd_symbolic_weight (font
)
2082 struct font_name
*font
;
2084 return xlfd_symbolic_value (weight_table
, DIM (weight_table
),
2085 font
, XLFD_WEIGHT
, Qnormal
);
2089 /* Return a numeric value for the swidth of the font whose XLFD font
2090 name fields are found in FONT. */
2093 xlfd_numeric_swidth (font
)
2094 struct font_name
*font
;
2096 return xlfd_numeric_value (swidth_table
, DIM (swidth_table
),
2097 font
, XLFD_SWIDTH
, XLFD_SWIDTH_MEDIUM
);
2101 /* Return a symbolic value for the swidth of FONT. */
2103 static INLINE Lisp_Object
2104 xlfd_symbolic_swidth (font
)
2105 struct font_name
*font
;
2107 return xlfd_symbolic_value (swidth_table
, DIM (swidth_table
),
2108 font
, XLFD_SWIDTH
, Qnormal
);
2112 /* Look up the entry of SYMBOL in the vector TABLE which has DIM
2113 entries. Value is a pointer to the matching table entry or null if
2114 no element of TABLE contains SYMBOL. */
2116 static struct table_entry
*
2117 face_value (table
, dim
, symbol
)
2118 struct table_entry
*table
;
2124 xassert (SYMBOLP (symbol
));
2126 for (i
= 0; i
< dim
; ++i
)
2127 if (EQ (*table
[i
].symbol
, symbol
))
2130 return i
< dim
? table
+ i
: NULL
;
2134 /* Return a numeric value for SYMBOL in the vector TABLE which has DIM
2135 entries. Value is -1 if SYMBOL is not found in TABLE. */
2138 face_numeric_value (table
, dim
, symbol
)
2139 struct table_entry
*table
;
2143 struct table_entry
*p
= face_value (table
, dim
, symbol
);
2144 return p
? p
->numeric
: -1;
2148 /* Return a numeric value representing the weight specified by Lisp
2149 symbol WEIGHT. Value is one of the enumerators of enum
2153 face_numeric_weight (weight
)
2156 return face_numeric_value (weight_table
, DIM (weight_table
), weight
);
2160 /* Return a numeric value representing the slant specified by Lisp
2161 symbol SLANT. Value is one of the enumerators of enum xlfd_slant. */
2164 face_numeric_slant (slant
)
2167 return face_numeric_value (slant_table
, DIM (slant_table
), slant
);
2171 /* Return a numeric value representing the swidth specified by Lisp
2172 symbol WIDTH. Value is one of the enumerators of enum xlfd_swidth. */
2175 face_numeric_swidth (width
)
2178 return face_numeric_value (swidth_table
, DIM (swidth_table
), width
);
2181 #ifdef HAVE_WINDOW_SYSTEM
2183 #ifdef USE_FONT_BACKEND
2184 static INLINE Lisp_Object
2185 face_symbolic_value (table
, dim
, font_prop
)
2186 struct table_entry
*table
;
2188 Lisp_Object font_prop
;
2190 struct table_entry
*p
;
2191 char *s
= SDATA (SYMBOL_NAME (font_prop
));
2192 int low
, mid
, high
, cmp
;
2199 mid
= (low
+ high
) / 2;
2200 cmp
= strcmp (table
[mid
].name
, s
);
2207 return *table
[mid
].symbol
;
2213 static INLINE Lisp_Object
2214 face_symbolic_weight (weight
)
2217 return face_symbolic_value (weight_table
, DIM (weight_table
), weight
);
2220 static INLINE Lisp_Object
2221 face_symbolic_slant (slant
)
2224 return face_symbolic_value (slant_table
, DIM (slant_table
), slant
);
2227 static INLINE Lisp_Object
2228 face_symbolic_swidth (width
)
2231 return face_symbolic_value (swidth_table
, DIM (swidth_table
), width
);
2233 #endif /* USE_FONT_BACKEND */
2236 split_font_name_into_vector (fontname
)
2237 Lisp_Object fontname
;
2239 struct font_name font
;
2243 font
.name
= LSTRDUPA (fontname
);
2244 if (! split_font_name (NULL
, &font
, 0))
2246 vec
= Fmake_vector (make_number (XLFD_LAST
), Qnil
);
2247 for (i
= 0; i
< XLFD_LAST
; i
++)
2248 if (font
.fields
[i
][0] != '*')
2249 ASET (vec
, i
, build_string (font
.fields
[i
]));
2254 build_font_name_from_vector (vec
)
2257 struct font_name font
;
2258 Lisp_Object fontname
;
2262 for (i
= 0; i
< XLFD_LAST
; i
++)
2264 font
.fields
[i
] = (NILP (AREF (vec
, i
))
2265 ? "*" : (char *) SDATA (AREF (vec
, i
)));
2266 if ((i
== XLFD_FAMILY
|| i
== XLFD_REGISTRY
)
2267 && (p
= strchr (font
.fields
[i
], '-')))
2269 char *p1
= STRDUPA (font
.fields
[i
]);
2271 p1
[p
- font
.fields
[i
]] = '\0';
2272 if (i
== XLFD_FAMILY
)
2274 font
.fields
[XLFD_FOUNDRY
] = p1
;
2275 font
.fields
[XLFD_FAMILY
] = p
+ 1;
2279 font
.fields
[XLFD_REGISTRY
] = p1
;
2280 font
.fields
[XLFD_ENCODING
] = p
+ 1;
2286 p
= build_font_name (&font
);
2287 fontname
= build_string (p
);
2292 /* Return non-zero if FONT is the name of a fixed-pitch font. */
2296 struct font_name
*font
;
2298 /* Function split_font_name converts fields to lower-case, so there
2299 is no need to use tolower here. */
2300 return *font
->fields
[XLFD_SPACING
] != 'p';
2304 /* Return the point size of FONT on frame F, measured in 1/10 pt.
2306 The actual height of the font when displayed on F depends on the
2307 resolution of both the font and frame. For example, a 10pt font
2308 designed for a 100dpi display will display larger than 10pt on a
2309 75dpi display. (It's not unusual to use fonts not designed for the
2310 display one is using. For example, some intlfonts are available in
2311 72dpi versions, only.)
2313 Value is the real point size of FONT on frame F, or 0 if it cannot
2316 By side effect, set FONT->numeric[XLFD_PIXEL_SIZE]. */
2319 xlfd_point_size (f
, font
)
2321 struct font_name
*font
;
2323 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
2324 char *pixel_field
= font
->fields
[XLFD_PIXEL_SIZE
];
2328 if (*pixel_field
== '[')
2330 /* The pixel size field is `[A B C D]' which specifies
2331 a transformation matrix.
2337 by which all glyphs of the font are transformed. The spec
2338 says that s scalar value N for the pixel size is equivalent
2339 to A = N * resx/resy, B = C = 0, D = N. */
2340 char *start
= pixel_field
+ 1, *end
;
2344 for (i
= 0; i
< 4; ++i
)
2346 matrix
[i
] = strtod (start
, &end
);
2353 pixel
= atoi (pixel_field
);
2355 font
->numeric
[XLFD_PIXEL_SIZE
] = pixel
;
2359 real_pt
= PT_PER_INCH
* 10.0 * pixel
/ resy
+ 0.5;
2365 /* Return point size of PIXEL dots while considering Y-resultion (DPI)
2366 of frame F. This function is used to guess a point size of font
2367 when only the pixel height of the font is available. */
2370 pixel_point_size (f
, pixel
)
2374 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
2378 /* As one inch is PT_PER_INCH points, PT_PER_INCH/RESY gives the
2379 point size of one dot. */
2380 real_pt
= pixel
* PT_PER_INCH
/ resy
;
2381 int_pt
= real_pt
+ 0.5;
2387 /* Return a rescaling ratio of a font of NAME. */
2390 font_rescale_ratio (name
)
2393 Lisp_Object tail
, elt
;
2395 for (tail
= Vface_font_rescale_alist
; CONSP (tail
); tail
= XCDR (tail
))
2398 if (STRINGP (XCAR (elt
)) && FLOATP (XCDR (elt
))
2399 && fast_c_string_match_ignore_case (XCAR (elt
), name
) >= 0)
2400 return XFLOAT_DATA (XCDR (elt
));
2406 /* Split XLFD font name FONT->name destructively into NUL-terminated,
2407 lower-case fields in FONT->fields. NUMERIC_P non-zero means
2408 compute numeric values for fields XLFD_POINT_SIZE, XLFD_SWIDTH,
2409 XLFD_RESY, XLFD_SLANT, and XLFD_WEIGHT in FONT->numeric. Value is
2410 zero if the font name doesn't have the format we expect. The
2411 expected format is a font name that starts with a `-' and has
2412 XLFD_LAST fields separated by `-'. */
2415 split_font_name (f
, font
, numeric_p
)
2417 struct font_name
*font
;
2422 double rescale_ratio
;
2425 /* This must be done before splitting the font name. */
2426 rescale_ratio
= font_rescale_ratio (font
->name
);
2428 if (*font
->name
== '-')
2430 char *p
= xstrlwr (font
->name
) + 1;
2432 while (i
< XLFD_LAST
)
2434 font
->fields
[i
] = p
;
2437 /* Pixel and point size may be of the form `[....]'. For
2438 BNF, see XLFD spec, chapter 4. Negative values are
2439 indicated by tilde characters which we replace with
2440 `-' characters, here. */
2442 && (i
- 1 == XLFD_PIXEL_SIZE
2443 || i
- 1 == XLFD_POINT_SIZE
))
2448 for (++p
; *p
&& *p
!= ']'; ++p
)
2452 /* Check that the matrix contains 4 floating point
2454 for (j
= 0, start
= font
->fields
[i
- 1] + 1;
2457 if (strtod (start
, &end
) == 0 && start
== end
)
2464 while (*p
&& *p
!= '-')
2474 success_p
= i
== XLFD_LAST
;
2476 /* If requested, and font name was in the expected format,
2477 compute numeric values for some fields. */
2478 if (numeric_p
&& success_p
)
2480 font
->numeric
[XLFD_POINT_SIZE
] = xlfd_point_size (f
, font
);
2481 font
->numeric
[XLFD_RESY
] = atoi (font
->fields
[XLFD_RESY
]);
2482 font
->numeric
[XLFD_SLANT
] = xlfd_numeric_slant (font
);
2483 font
->numeric
[XLFD_WEIGHT
] = xlfd_numeric_weight (font
);
2484 font
->numeric
[XLFD_SWIDTH
] = xlfd_numeric_swidth (font
);
2485 font
->numeric
[XLFD_AVGWIDTH
] = atoi (font
->fields
[XLFD_AVGWIDTH
]);
2486 font
->rescale_ratio
= rescale_ratio
;
2489 /* Initialize it to zero. It will be overridden by font_list while
2490 trying alternate registries. */
2491 font
->registry_priority
= 0;
2497 /* Build an XLFD font name from font name fields in FONT. Value is a
2498 pointer to the font name, which is allocated via xmalloc. */
2501 build_font_name (font
)
2502 struct font_name
*font
;
2506 char *font_name
= (char *) xmalloc (size
);
2507 int total_length
= 0;
2509 for (i
= 0; i
< XLFD_LAST
; ++i
)
2511 /* Add 1 because of the leading `-'. */
2512 int len
= strlen (font
->fields
[i
]) + 1;
2514 /* Reallocate font_name if necessary. Add 1 for the final
2516 if (total_length
+ len
+ 1 >= size
)
2518 int new_size
= max (2 * size
, size
+ len
+ 1);
2519 int sz
= new_size
* sizeof *font_name
;
2520 font_name
= (char *) xrealloc (font_name
, sz
);
2524 font_name
[total_length
] = '-';
2525 bcopy (font
->fields
[i
], font_name
+ total_length
+ 1, len
- 1);
2526 total_length
+= len
;
2529 font_name
[total_length
] = 0;
2534 /* Free an array FONTS of N font_name structures. This frees FONTS
2535 itself and all `name' fields in its elements. */
2538 free_font_names (fonts
, n
)
2539 struct font_name
*fonts
;
2543 xfree (fonts
[--n
].name
);
2548 /* Sort vector FONTS of font_name structures which contains NFONTS
2549 elements using qsort and comparison function CMPFN. F is the frame
2550 on which the fonts will be used. The global variable font_frame
2551 is temporarily set to F to make it available in CMPFN. */
2554 sort_fonts (f
, fonts
, nfonts
, cmpfn
)
2556 struct font_name
*fonts
;
2558 int (*cmpfn
) P_ ((const void *, const void *));
2561 qsort (fonts
, nfonts
, sizeof *fonts
, cmpfn
);
2566 /* Get fonts matching PATTERN on frame F. If F is null, use the first
2567 display in x_display_list. FONTS is a pointer to a vector of
2568 NFONTS font_name structures. TRY_ALTERNATIVES_P non-zero means try
2569 alternative patterns from Valternate_fontname_alist if no fonts are
2570 found matching PATTERN.
2572 For all fonts found, set FONTS[i].name to the name of the font,
2573 allocated via xmalloc, and split font names into fields. Ignore
2574 fonts that we can't parse. Value is the number of fonts found. */
2577 x_face_list_fonts (f
, pattern
, pfonts
, nfonts
, try_alternatives_p
)
2580 struct font_name
**pfonts
;
2581 int nfonts
, try_alternatives_p
;
2585 /* NTEMACS_TODO : currently this uses w32_list_fonts, but it may be
2586 better to do it the other way around. */
2588 Lisp_Object lpattern
, tem
;
2589 struct font_name
*fonts
= 0;
2590 int num_fonts
= nfonts
;
2593 lpattern
= build_string (pattern
);
2595 /* Get the list of fonts matching PATTERN. */
2598 lfonts
= w32_list_fonts (f
, lpattern
, 0, nfonts
);
2601 lfonts
= x_list_fonts (f
, lpattern
, -1, nfonts
);
2604 if (nfonts
< 0 && CONSP (lfonts
))
2605 num_fonts
= XFASTINT (Flength (lfonts
));
2607 /* Make a copy of the font names we got from X, and
2608 split them into fields. */
2610 for (tem
= lfonts
; CONSP (tem
) && n
< num_fonts
; tem
= XCDR (tem
))
2612 Lisp_Object elt
, tail
;
2613 const char *name
= SDATA (XCAR (tem
));
2615 /* Ignore fonts matching a pattern from face-ignored-fonts. */
2616 for (tail
= Vface_ignored_fonts
; CONSP (tail
); tail
= XCDR (tail
))
2620 && fast_c_string_match_ignore_case (elt
, name
) >= 0)
2631 *pfonts
= (struct font_name
*) xmalloc (num_fonts
* sizeof **pfonts
);
2635 /* Make a copy of the font name. */
2636 fonts
[n
].name
= xstrdup (name
);
2638 if (split_font_name (f
, fonts
+ n
, 1))
2640 if (font_scalable_p (fonts
+ n
)
2641 && !may_use_scalable_font_p (name
))
2644 xfree (fonts
[n
].name
);
2650 xfree (fonts
[n
].name
);
2653 /* If no fonts found, try patterns from Valternate_fontname_alist. */
2654 if (n
== 0 && try_alternatives_p
)
2656 Lisp_Object list
= Valternate_fontname_alist
;
2664 while (CONSP (list
))
2666 Lisp_Object entry
= XCAR (list
);
2668 && STRINGP (XCAR (entry
))
2669 && strcmp (SDATA (XCAR (entry
)), pattern
) == 0)
2676 Lisp_Object patterns
= XCAR (list
);
2679 while (CONSP (patterns
)
2680 /* If list is screwed up, give up. */
2681 && (name
= XCAR (patterns
),
2683 /* Ignore patterns equal to PATTERN because we tried that
2684 already with no success. */
2685 && (strcmp (SDATA (name
), pattern
) == 0
2686 || (n
= x_face_list_fonts (f
, SDATA (name
),
2689 patterns
= XCDR (patterns
);
2697 /* Check if a font matching pattern_offset_t on frame F is available
2698 or not. PATTERN may be a cons (FAMILY . REGISTRY), in which case,
2699 a font name pattern is generated from FAMILY and REGISTRY. */
2702 face_font_available_p (f
, pattern
)
2704 Lisp_Object pattern
;
2708 if (! STRINGP (pattern
))
2710 Lisp_Object family
, registry
;
2711 char *family_str
, *registry_str
, *pattern_str
;
2713 CHECK_CONS (pattern
);
2714 family
= XCAR (pattern
);
2719 CHECK_STRING (family
);
2720 family_str
= (char *) SDATA (family
);
2722 registry
= XCDR (pattern
);
2723 if (NILP (registry
))
2727 CHECK_STRING (registry
);
2728 registry_str
= (char *) SDATA (registry
);
2731 pattern_str
= (char *) alloca (strlen (family_str
)
2732 + strlen (registry_str
)
2734 strcpy (pattern_str
, index (family_str
, '-') ? "-" : "-*-");
2735 strcat (pattern_str
, family_str
);
2736 strcat (pattern_str
, "-*-");
2737 strcat (pattern_str
, registry_str
);
2738 if (!index (registry_str
, '-'))
2740 if (registry_str
[strlen (registry_str
) - 1] == '*')
2741 strcat (pattern_str
, "-*");
2743 strcat (pattern_str
, "*-*");
2745 pattern
= build_string (pattern_str
);
2748 /* Get the list of fonts matching PATTERN. */
2751 fonts
= w32_list_fonts (f
, pattern
, 0, 1);
2754 fonts
= x_list_fonts (f
, pattern
, -1, 1);
2756 return XINT (Flength (fonts
));
2760 /* Determine fonts matching PATTERN on frame F. Sort resulting fonts
2761 using comparison function CMPFN. Value is the number of fonts
2762 found. If value is non-zero, *FONTS is set to a vector of
2763 font_name structures allocated from the heap containing matching
2764 fonts. Each element of *FONTS contains a name member that is also
2765 allocated from the heap. Font names in these structures are split
2766 into fields. Use free_font_names to free such an array. */
2769 sorted_font_list (f
, pattern
, cmpfn
, fonts
)
2772 int (*cmpfn
) P_ ((const void *, const void *));
2773 struct font_name
**fonts
;
2777 /* Get the list of fonts matching pattern. 100 should suffice. */
2778 nfonts
= DEFAULT_FONT_LIST_LIMIT
;
2779 if (INTEGERP (Vfont_list_limit
))
2780 nfonts
= XINT (Vfont_list_limit
);
2783 nfonts
= x_face_list_fonts (f
, pattern
, fonts
, nfonts
, 1);
2785 /* Sort the resulting array and return it in *FONTS. If no
2786 fonts were found, make sure to set *FONTS to null. */
2788 sort_fonts (f
, *fonts
, nfonts
, cmpfn
);
2799 /* Compare two font_name structures *A and *B. Value is analogous to
2800 strcmp. Sort order is given by the global variable
2801 font_sort_order. Font names are sorted so that, everything else
2802 being equal, fonts with a resolution closer to that of the frame on
2803 which they are used are listed first. The global variable
2804 font_frame is the frame on which we operate. */
2807 cmp_font_names (a
, b
)
2810 struct font_name
*x
= (struct font_name
*) a
;
2811 struct font_name
*y
= (struct font_name
*) b
;
2814 /* All strings have been converted to lower-case by split_font_name,
2815 so we can use strcmp here. */
2816 cmp
= strcmp (x
->fields
[XLFD_FAMILY
], y
->fields
[XLFD_FAMILY
]);
2821 for (i
= 0; i
< DIM (font_sort_order
) && cmp
== 0; ++i
)
2823 int j
= font_sort_order
[i
];
2824 cmp
= x
->numeric
[j
] - y
->numeric
[j
];
2829 /* Everything else being equal, we prefer fonts with an
2830 y-resolution closer to that of the frame. */
2831 int resy
= FRAME_X_DISPLAY_INFO (font_frame
)->resy
;
2832 int x_resy
= x
->numeric
[XLFD_RESY
];
2833 int y_resy
= y
->numeric
[XLFD_RESY
];
2834 cmp
= eabs (resy
- x_resy
) - eabs (resy
- y_resy
);
2842 /* Get a sorted list of fonts matching PATTERN on frame F. If PATTERN
2843 is nil, list fonts matching FAMILY and REGISTRY. FAMILY is a
2844 family name string or nil. REGISTRY is a registry name string.
2845 Set *FONTS to a vector of font_name structures allocated from the
2846 heap containing the fonts found. Value is the number of fonts
2850 font_list_1 (f
, pattern
, family
, registry
, fonts
)
2852 Lisp_Object pattern
, family
, registry
;
2853 struct font_name
**fonts
;
2855 char *pattern_str
, *family_str
, *registry_str
;
2859 family_str
= (NILP (family
) ? "*" : (char *) SDATA (family
));
2860 registry_str
= (NILP (registry
) ? "*" : (char *) SDATA (registry
));
2862 pattern_str
= (char *) alloca (strlen (family_str
)
2863 + strlen (registry_str
)
2865 strcpy (pattern_str
, index (family_str
, '-') ? "-" : "-*-");
2866 strcat (pattern_str
, family_str
);
2867 strcat (pattern_str
, "-*-");
2868 strcat (pattern_str
, registry_str
);
2869 if (!index (registry_str
, '-'))
2871 if (registry_str
[strlen (registry_str
) - 1] == '*')
2872 strcat (pattern_str
, "-*");
2874 strcat (pattern_str
, "*-*");
2878 pattern_str
= (char *) SDATA (pattern
);
2880 return sorted_font_list (f
, pattern_str
, cmp_font_names
, fonts
);
2884 /* Concatenate font list FONTS1 and FONTS2. FONTS1 and FONTS2
2885 contains NFONTS1 fonts and NFONTS2 fonts respectively. Return a
2886 pointer to a newly allocated font list. FONTS1 and FONTS2 are
2889 static struct font_name
*
2890 concat_font_list (fonts1
, nfonts1
, fonts2
, nfonts2
)
2891 struct font_name
*fonts1
, *fonts2
;
2892 int nfonts1
, nfonts2
;
2894 int new_nfonts
= nfonts1
+ nfonts2
;
2895 struct font_name
*new_fonts
;
2897 new_fonts
= (struct font_name
*) xmalloc (sizeof *new_fonts
* new_nfonts
);
2898 bcopy (fonts1
, new_fonts
, sizeof *new_fonts
* nfonts1
);
2899 bcopy (fonts2
, new_fonts
+ nfonts1
, sizeof *new_fonts
* nfonts2
);
2906 /* Get a sorted list of fonts of family FAMILY on frame F.
2908 If PATTERN is non-nil, list fonts matching that pattern.
2910 If REGISTRY is non-nil, it is a list of registry (and encoding)
2911 names. Return fonts with those registries and the alternative
2912 registries from Vface_alternative_font_registry_alist.
2914 If REGISTRY is nil return fonts of any registry.
2916 Set *FONTS to a vector of font_name structures allocated from the
2917 heap containing the fonts found. Value is the number of fonts
2921 font_list (f
, pattern
, family
, registry
, fonts
)
2923 Lisp_Object pattern
, family
, registry
;
2924 struct font_name
**fonts
;
2930 if (NILP (registry
))
2931 return font_list_1 (f
, pattern
, family
, registry
, fonts
);
2933 for (reg_prio
= 0, nfonts
= 0; CONSP (registry
); registry
= XCDR (registry
))
2935 Lisp_Object elt
, alter
;
2937 struct font_name
*fonts2
;
2939 elt
= XCAR (registry
);
2940 alter
= Fassoc (elt
, Vface_alternative_font_registry_alist
);
2942 alter
= Fcons (elt
, Qnil
);
2943 for (; CONSP (alter
); alter
= XCDR (alter
), reg_prio
++)
2945 nfonts2
= font_list_1 (f
, pattern
, family
, XCAR (alter
), &fonts2
);
2949 for (i
= 0; i
< nfonts2
; i
++)
2950 fonts2
[i
].registry_priority
= reg_prio
;
2952 *fonts
= concat_font_list (*fonts
, nfonts
, fonts2
, nfonts2
);
2964 /* Remove elements from LIST whose cars are `equal'. Called from
2965 x-family-fonts and x-font-family-list to remove duplicate font
2969 remove_duplicates (list
)
2972 Lisp_Object tail
= list
;
2974 while (!NILP (tail
) && !NILP (XCDR (tail
)))
2976 Lisp_Object next
= XCDR (tail
);
2977 if (!NILP (Fequal (XCAR (next
), XCAR (tail
))))
2978 XSETCDR (tail
, XCDR (next
));
2985 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
2986 doc
: /* Return a list of available fonts of family FAMILY on FRAME.
2987 If FAMILY is omitted or nil, list all families.
2988 Otherwise, FAMILY must be a string, possibly containing wildcards
2990 If FRAME is omitted or nil, use the selected frame.
2991 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
2992 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
2993 FAMILY is the font family name. POINT-SIZE is the size of the
2994 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
2995 width, weight and slant of the font. These symbols are the same as for
2996 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
2997 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
2998 giving the registry and encoding of the font.
2999 The result list is sorted according to the current setting of
3000 the face font sort order. */)
3002 Lisp_Object family
, frame
;
3004 struct frame
*f
= check_x_frame (frame
);
3005 struct font_name
*fonts
;
3008 struct gcpro gcpro1
;
3011 CHECK_STRING (family
);
3015 nfonts
= font_list (f
, Qnil
, family
, Qnil
, &fonts
);
3016 for (i
= nfonts
- 1; i
>= 0; --i
)
3018 Lisp_Object v
= Fmake_vector (make_number (8), Qnil
);
3021 ASET (v
, 0, build_string (fonts
[i
].fields
[XLFD_FAMILY
]));
3022 ASET (v
, 1, xlfd_symbolic_swidth (fonts
+ i
));
3023 ASET (v
, 2, make_number (xlfd_point_size (f
, fonts
+ i
)));
3024 ASET (v
, 3, xlfd_symbolic_weight (fonts
+ i
));
3025 ASET (v
, 4, xlfd_symbolic_slant (fonts
+ i
));
3026 ASET (v
, 5, xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
);
3027 tem
= build_font_name (fonts
+ i
);
3028 ASET (v
, 6, build_string (tem
));
3029 sprintf (tem
, "%s-%s", fonts
[i
].fields
[XLFD_REGISTRY
],
3030 fonts
[i
].fields
[XLFD_ENCODING
]);
3031 ASET (v
, 7, build_string (tem
));
3034 result
= Fcons (v
, result
);
3037 remove_duplicates (result
);
3038 free_font_names (fonts
, nfonts
);
3044 DEFUN ("x-font-family-list", Fx_font_family_list
, Sx_font_family_list
,
3046 doc
: /* Return a list of available font families on FRAME.
3047 If FRAME is omitted or nil, use the selected frame.
3048 Value is a list of conses (FAMILY . FIXED-P) where FAMILY
3049 is a font family, and FIXED-P is non-nil if fonts of that family
3050 are fixed-pitch. */)
3054 struct frame
*f
= check_x_frame (frame
);
3056 struct font_name
*fonts
;
3058 struct gcpro gcpro1
;
3059 int count
= SPECPDL_INDEX ();
3061 /* Let's consider all fonts. */
3062 specbind (intern ("font-list-limit"), make_number (-1));
3063 nfonts
= font_list (f
, Qnil
, Qnil
, Qnil
, &fonts
);
3067 for (i
= nfonts
- 1; i
>= 0; --i
)
3068 result
= Fcons (Fcons (build_string (fonts
[i
].fields
[XLFD_FAMILY
]),
3069 xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
),
3072 remove_duplicates (result
);
3073 free_font_names (fonts
, nfonts
);
3075 return unbind_to (count
, result
);
3079 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
3080 doc
: /* Return a list of the names of available fonts matching PATTERN.
3081 If optional arguments FACE and FRAME are specified, return only fonts
3082 the same size as FACE on FRAME.
3083 PATTERN is a string, perhaps with wildcard characters;
3084 the * character matches any substring, and
3085 the ? character matches any single character.
3086 PATTERN is case-insensitive.
3087 FACE is a face name--a symbol.
3089 The return value is a list of strings, suitable as arguments to
3092 Fonts Emacs can't use may or may not be excluded
3093 even if they match PATTERN and FACE.
3094 The optional fourth argument MAXIMUM sets a limit on how many
3095 fonts to match. The first MAXIMUM fonts are reported.
3096 The optional fifth argument WIDTH, if specified, is a number of columns
3097 occupied by a character of a font. In that case, return only fonts
3098 the WIDTH times as wide as FACE on FRAME. */)
3099 (pattern
, face
, frame
, maximum
, width
)
3100 Lisp_Object pattern
, face
, frame
, maximum
, width
;
3107 CHECK_STRING (pattern
);
3113 CHECK_NATNUM (maximum
);
3114 maxnames
= XINT (maximum
);
3118 CHECK_NUMBER (width
);
3120 /* We can't simply call check_x_frame because this function may be
3121 called before any frame is created. */
3122 f
= frame_or_selected_frame (frame
, 2);
3123 if (!FRAME_WINDOW_P (f
))
3125 /* Perhaps we have not yet created any frame. */
3130 /* Determine the width standard for comparison with the fonts we find. */
3136 /* This is of limited utility since it works with character
3137 widths. Keep it for compatibility. --gerd. */
3138 int face_id
= lookup_named_face (f
, face
, 0);
3139 struct face
*face
= (face_id
< 0
3141 : FACE_FROM_ID (f
, face_id
));
3143 if (face
&& face
->font
)
3144 size
= FONT_WIDTH (face
->font
);
3146 size
= FONT_WIDTH (FRAME_FONT (f
)); /* FRAME_COLUMN_WIDTH (f) */
3149 size
*= XINT (width
);
3153 Lisp_Object args
[2];
3155 args
[0] = x_list_fonts (f
, pattern
, size
, maxnames
);
3157 /* We don't have to check fontsets. */
3159 args
[1] = list_fontsets (f
, pattern
, size
);
3160 return Fnconc (2, args
);
3164 #endif /* HAVE_WINDOW_SYSTEM */
3168 /***********************************************************************
3170 ***********************************************************************/
3172 /* Access face attributes of face LFACE, a Lisp vector. */
3174 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
3175 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
3176 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
3177 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
3178 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
3179 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
3180 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
3181 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
3182 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
3183 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
3184 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
3185 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
3186 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
3187 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
3188 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
3189 #define LFACE_AVGWIDTH(LFACE) AREF ((LFACE), LFACE_AVGWIDTH_INDEX)
3190 #define LFACE_FONTSET(LFACE) AREF ((LFACE), LFACE_FONTSET_INDEX)
3192 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
3193 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
3195 #define LFACEP(LFACE) \
3197 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \
3198 && EQ (AREF (LFACE, 0), Qface))
3203 /* Check consistency of Lisp face attribute vector ATTRS. */
3206 check_lface_attrs (attrs
)
3209 xassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
3210 || IGNORE_DEFFACE_P (attrs
[LFACE_FAMILY_INDEX
])
3211 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
3212 xassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
3213 || IGNORE_DEFFACE_P (attrs
[LFACE_SWIDTH_INDEX
])
3214 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
3215 xassert (UNSPECIFIEDP (attrs
[LFACE_AVGWIDTH_INDEX
])
3216 || IGNORE_DEFFACE_P (attrs
[LFACE_AVGWIDTH_INDEX
])
3217 || INTEGERP (attrs
[LFACE_AVGWIDTH_INDEX
]));
3218 xassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
3219 || IGNORE_DEFFACE_P (attrs
[LFACE_HEIGHT_INDEX
])
3220 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
])
3221 || FLOATP (attrs
[LFACE_HEIGHT_INDEX
])
3222 || FUNCTIONP (attrs
[LFACE_HEIGHT_INDEX
]));
3223 xassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
3224 || IGNORE_DEFFACE_P (attrs
[LFACE_WEIGHT_INDEX
])
3225 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
3226 xassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
3227 || IGNORE_DEFFACE_P (attrs
[LFACE_SLANT_INDEX
])
3228 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
3229 xassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
3230 || IGNORE_DEFFACE_P (attrs
[LFACE_UNDERLINE_INDEX
])
3231 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
3232 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]));
3233 xassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
3234 || IGNORE_DEFFACE_P (attrs
[LFACE_OVERLINE_INDEX
])
3235 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
3236 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
3237 xassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
3238 || IGNORE_DEFFACE_P (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
3239 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
3240 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
3241 xassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
3242 || IGNORE_DEFFACE_P (attrs
[LFACE_BOX_INDEX
])
3243 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
3244 || STRINGP (attrs
[LFACE_BOX_INDEX
])
3245 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
3246 || CONSP (attrs
[LFACE_BOX_INDEX
]));
3247 xassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
3248 || IGNORE_DEFFACE_P (attrs
[LFACE_INVERSE_INDEX
])
3249 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
3250 xassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
3251 || IGNORE_DEFFACE_P (attrs
[LFACE_FOREGROUND_INDEX
])
3252 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
3253 xassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
3254 || IGNORE_DEFFACE_P (attrs
[LFACE_BACKGROUND_INDEX
])
3255 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
3256 xassert (UNSPECIFIEDP (attrs
[LFACE_INHERIT_INDEX
])
3257 || IGNORE_DEFFACE_P (attrs
[LFACE_INHERIT_INDEX
])
3258 || NILP (attrs
[LFACE_INHERIT_INDEX
])
3259 || SYMBOLP (attrs
[LFACE_INHERIT_INDEX
])
3260 || CONSP (attrs
[LFACE_INHERIT_INDEX
]));
3261 #ifdef HAVE_WINDOW_SYSTEM
3262 xassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
3263 || IGNORE_DEFFACE_P (attrs
[LFACE_STIPPLE_INDEX
])
3264 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
3265 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
3266 xassert (UNSPECIFIEDP (attrs
[LFACE_FONT_INDEX
])
3267 || IGNORE_DEFFACE_P (attrs
[LFACE_FONT_INDEX
])
3268 || NILP (attrs
[LFACE_FONT_INDEX
])
3269 #ifdef USE_FONT_BACKEND
3270 || FONT_OBJECT_P (attrs
[LFACE_FONT_INDEX
])
3271 #endif /* USE_FONT_BACKEND */
3272 || STRINGP (attrs
[LFACE_FONT_INDEX
]));
3273 xassert (UNSPECIFIEDP (attrs
[LFACE_FONTSET_INDEX
])
3274 || STRINGP (attrs
[LFACE_FONTSET_INDEX
]));
3279 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
3287 xassert (LFACEP (lface
));
3288 check_lface_attrs (XVECTOR (lface
)->contents
);
3292 #else /* GLYPH_DEBUG == 0 */
3294 #define check_lface_attrs(attrs) (void) 0
3295 #define check_lface(lface) (void) 0
3297 #endif /* GLYPH_DEBUG == 0 */
3301 /* Face-merge cycle checking. */
3303 /* A `named merge point' is simply a point during face-merging where we
3304 look up a face by name. We keep a stack of which named lookups we're
3305 currently processing so that we can easily detect cycles, using a
3306 linked- list of struct named_merge_point structures, typically
3307 allocated on the stack frame of the named lookup functions which are
3308 active (so no consing is required). */
3309 struct named_merge_point
3311 Lisp_Object face_name
;
3312 struct named_merge_point
*prev
;
3316 /* If a face merging cycle is detected for FACE_NAME, return 0,
3317 otherwise add NEW_NAMED_MERGE_POINT, which is initialized using
3318 FACE_NAME, as the head of the linked list pointed to by
3319 NAMED_MERGE_POINTS, and return 1. */
3322 push_named_merge_point (struct named_merge_point
*new_named_merge_point
,
3323 Lisp_Object face_name
,
3324 struct named_merge_point
**named_merge_points
)
3326 struct named_merge_point
*prev
;
3328 for (prev
= *named_merge_points
; prev
; prev
= prev
->prev
)
3329 if (EQ (face_name
, prev
->face_name
))
3332 new_named_merge_point
->face_name
= face_name
;
3333 new_named_merge_point
->prev
= *named_merge_points
;
3335 *named_merge_points
= new_named_merge_point
;
3342 #if 0 /* Seems to be unused. */
3344 internal_resolve_face_name (nargs
, args
)
3348 return Fget (args
[0], args
[1]);
3352 resolve_face_name_error (ignore
)
3359 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
3360 to make it a symbol. If FACE_NAME is an alias for another face,
3361 return that face's name.
3363 Return default face in case of errors. */
3366 resolve_face_name (face_name
, signal_p
)
3367 Lisp_Object face_name
;
3370 Lisp_Object orig_face
;
3371 Lisp_Object tortoise
, hare
;
3373 if (STRINGP (face_name
))
3374 face_name
= intern (SDATA (face_name
));
3376 if (NILP (face_name
) || !SYMBOLP (face_name
))
3379 orig_face
= face_name
;
3380 tortoise
= hare
= face_name
;
3385 hare
= Fget (hare
, Qface_alias
);
3386 if (NILP (hare
) || !SYMBOLP (hare
))
3390 hare
= Fget (hare
, Qface_alias
);
3391 if (NILP (hare
) || !SYMBOLP (hare
))
3394 tortoise
= Fget (tortoise
, Qface_alias
);
3395 if (EQ (hare
, tortoise
))
3398 xsignal1 (Qcircular_list
, orig_face
);
3407 /* Return the face definition of FACE_NAME on frame F. F null means
3408 return the definition for new frames. FACE_NAME may be a string or
3409 a symbol (apparently Emacs 20.2 allowed strings as face names in
3410 face text properties; Ediff uses that). If FACE_NAME is an alias
3411 for another face, return that face's definition. If SIGNAL_P is
3412 non-zero, signal an error if FACE_NAME is not a valid face name.
3413 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
3416 static INLINE Lisp_Object
3417 lface_from_face_name (f
, face_name
, signal_p
)
3419 Lisp_Object face_name
;
3424 face_name
= resolve_face_name (face_name
, signal_p
);
3427 lface
= assq_no_quit (face_name
, f
->face_alist
);
3429 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
3432 lface
= XCDR (lface
);
3434 signal_error ("Invalid face", face_name
);
3436 check_lface (lface
);
3441 /* Get face attributes of face FACE_NAME from frame-local faces on
3442 frame F. Store the resulting attributes in ATTRS which must point
3443 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
3444 is non-zero, signal an error if FACE_NAME does not name a face.
3445 Otherwise, value is zero if FACE_NAME is not a face. */
3448 get_lface_attributes (f
, face_name
, attrs
, signal_p
)
3450 Lisp_Object face_name
;
3457 lface
= lface_from_face_name (f
, face_name
, signal_p
);
3460 bcopy (XVECTOR (lface
)->contents
, attrs
,
3461 LFACE_VECTOR_SIZE
* sizeof *attrs
);
3471 /* Non-zero if all attributes in face attribute vector ATTRS are
3472 specified, i.e. are non-nil. */
3475 lface_fully_specified_p (attrs
)
3480 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3481 if (i
!= LFACE_FONT_INDEX
&& i
!= LFACE_INHERIT_INDEX
3482 && i
!= LFACE_AVGWIDTH_INDEX
&& i
!= LFACE_FONTSET_INDEX
)
3483 if ((UNSPECIFIEDP (attrs
[i
]) || IGNORE_DEFFACE_P (attrs
[i
]))
3485 /* MAC_TODO: No stipple support on Mac OS yet, this index is
3486 always unspecified. */
3487 && i
!= LFACE_STIPPLE_INDEX
3492 return i
== LFACE_VECTOR_SIZE
;
3495 #ifdef HAVE_WINDOW_SYSTEM
3497 /* Set font-related attributes of Lisp face LFACE from the fullname of
3498 the font opened by FONTNAME. If FORCE_P is zero, set only
3499 unspecified attributes of LFACE. The exception is `font'
3500 attribute. It is set to FONTNAME as is regardless of FORCE_P.
3502 If FONTNAME is not available on frame F,
3503 return 0 if MAY_FAIL_P is non-zero, otherwise abort.
3504 If the fullname is not in a valid XLFD format,
3505 return 0 if MAY_FAIL_P is non-zero, otherwise set normal values
3506 in LFACE and return 1.
3507 Otherwise, return 1. */
3510 set_lface_from_font_name (f
, lface
, fontname
, force_p
, may_fail_p
)
3513 Lisp_Object fontname
;
3514 int force_p
, may_fail_p
;
3516 struct font_name font
;
3521 char *font_name
= SDATA (fontname
);
3522 struct font_info
*font_info
;
3524 /* If FONTNAME is actually a fontset name, get ASCII font name of it. */
3525 fontset
= fs_query_fontset (fontname
, 0);
3528 font_name
= SDATA (fontset_ascii (fontset
));
3529 else if (fontset
== 0)
3536 /* Check if FONT_NAME is surely available on the system. Usually
3537 FONT_NAME is already cached for the frame F and FS_LOAD_FONT
3538 returns quickly. But, even if FONT_NAME is not yet cached,
3539 caching it now is not futail because we anyway load the font
3542 font_info
= FS_LOAD_FONT (f
, font_name
);
3552 font
.name
= STRDUPA (font_info
->full_name
);
3553 have_xlfd_p
= split_font_name (f
, &font
, 1);
3555 /* Set attributes only if unspecified, otherwise face defaults for
3556 new frames would never take effect. If we couldn't get a font
3557 name conforming to XLFD, set normal values. */
3559 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
3564 buffer
= (char *) alloca (strlen (font
.fields
[XLFD_FAMILY
])
3565 + strlen (font
.fields
[XLFD_FOUNDRY
])
3567 sprintf (buffer
, "%s-%s", font
.fields
[XLFD_FOUNDRY
],
3568 font
.fields
[XLFD_FAMILY
]);
3569 val
= build_string (buffer
);
3572 val
= build_string ("*");
3573 LFACE_FAMILY (lface
) = val
;
3576 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
3579 pt
= xlfd_point_size (f
, &font
);
3581 pt
= pixel_point_size (f
, font_info
->height
* 10);
3583 LFACE_HEIGHT (lface
) = make_number (pt
);
3586 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
3587 LFACE_SWIDTH (lface
)
3588 = have_xlfd_p
? xlfd_symbolic_swidth (&font
) : Qnormal
;
3590 if (force_p
|| UNSPECIFIEDP (LFACE_AVGWIDTH (lface
)))
3591 LFACE_AVGWIDTH (lface
)
3593 ? make_number (font
.numeric
[XLFD_AVGWIDTH
])
3596 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
3597 LFACE_WEIGHT (lface
)
3598 = have_xlfd_p
? xlfd_symbolic_weight (&font
) : Qnormal
;
3600 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
3602 = have_xlfd_p
? xlfd_symbolic_slant (&font
) : Qnormal
;
3606 LFACE_FONT (lface
) = build_string (font_info
->full_name
);
3607 LFACE_FONTSET (lface
) = fontset_name (fontset
);
3611 LFACE_FONT (lface
) = fontname
;
3613 = new_fontset_from_font_name (build_string (font_info
->full_name
));
3614 LFACE_FONTSET (lface
) = fontset_name (fontset
);
3619 #ifdef USE_FONT_BACKEND
3620 /* Set font-related attributes of Lisp face LFACE from FONT-OBJECT and
3621 FONTSET. If FORCE_P is zero, set only unspecified attributes of
3622 LFACE. The exceptions are `font' and `fontset' attributes. They
3623 are set regardless of FORCE_P. */
3626 set_lface_from_font_and_fontset (f
, lface
, font_object
, fontset
, force_p
)
3628 Lisp_Object lface
, font_object
;
3632 struct font
*font
= XSAVE_VALUE (font_object
)->pointer
;
3633 Lisp_Object entity
= font
->entity
;
3636 /* Set attributes only if unspecified, otherwise face defaults for
3637 new frames would never take effect. If the font doesn't have a
3638 specific property, set a normal value for that. */
3640 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
3642 Lisp_Object foundry
= AREF (entity
, FONT_FOUNDRY_INDEX
);
3643 Lisp_Object family
= AREF (entity
, FONT_FAMILY_INDEX
);
3645 if (! NILP (foundry
))
3647 if (! NILP (family
))
3648 val
= concat3 (SYMBOL_NAME (foundry
), build_string ("-"),
3649 SYMBOL_NAME (family
));
3651 val
= concat2 (SYMBOL_NAME (foundry
), build_string ("-*"));
3655 if (! NILP (family
))
3656 val
= SYMBOL_NAME (family
);
3658 val
= build_string ("*");
3660 LFACE_FAMILY (lface
) = val
;
3663 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
3665 int pt
= pixel_point_size (f
, font
->pixel_size
* 10);
3668 LFACE_HEIGHT (lface
) = make_number (pt
);
3671 if (force_p
|| UNSPECIFIEDP (LFACE_AVGWIDTH (lface
)))
3672 LFACE_AVGWIDTH (lface
) = make_number (font
->font
.average_width
);
3674 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
3676 Lisp_Object weight
= font_symbolic_weight (entity
);
3678 val
= NILP (weight
) ? Qnormal
: face_symbolic_weight (weight
);
3679 LFACE_WEIGHT (lface
) = ! NILP (val
) ? val
: weight
;
3681 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
3683 Lisp_Object slant
= font_symbolic_slant (entity
);
3685 val
= NILP (slant
) ? Qnormal
: face_symbolic_slant (slant
);
3686 LFACE_SLANT (lface
) = ! NILP (val
) ? val
: slant
;
3688 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
3690 Lisp_Object width
= font_symbolic_width (entity
);
3692 val
= NILP (width
) ? Qnormal
: face_symbolic_swidth (width
);
3693 LFACE_SWIDTH (lface
) = ! NILP (val
) ? val
: width
;
3696 LFACE_FONT (lface
) = make_unibyte_string (font
->font
.full_name
,
3697 strlen (font
->font
.full_name
));
3698 LFACE_FONTSET (lface
) = fontset_name (fontset
);
3700 #endif /* USE_FONT_BACKEND */
3702 #endif /* HAVE_WINDOW_SYSTEM */
3705 /* Merges the face height FROM with the face height TO, and returns the
3706 merged height. If FROM is an invalid height, then INVALID is
3707 returned instead. FROM and TO may be either absolute face heights or
3708 `relative' heights; the returned value is always an absolute height
3709 unless both FROM and TO are relative. GCPRO is a lisp value that
3710 will be protected from garbage-collection if this function makes a
3714 merge_face_heights (from
, to
, invalid
)
3715 Lisp_Object from
, to
, invalid
;
3717 Lisp_Object result
= invalid
;
3719 if (INTEGERP (from
))
3720 /* FROM is absolute, just use it as is. */
3722 else if (FLOATP (from
))
3723 /* FROM is a scale, use it to adjust TO. */
3726 /* relative X absolute => absolute */
3727 result
= make_number ((EMACS_INT
)(XFLOAT_DATA (from
) * XINT (to
)));
3728 else if (FLOATP (to
))
3729 /* relative X relative => relative */
3730 result
= make_float (XFLOAT_DATA (from
) * XFLOAT_DATA (to
));
3731 else if (UNSPECIFIEDP (to
))
3734 else if (FUNCTIONP (from
))
3735 /* FROM is a function, which use to adjust TO. */
3737 /* Call function with current height as argument.
3738 From is the new height. */
3739 Lisp_Object args
[2];
3743 result
= safe_call (2, args
);
3745 /* Ensure that if TO was absolute, so is the result. */
3746 if (INTEGERP (to
) && !INTEGERP (result
))
3754 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
3755 store the resulting attributes in TO, which must be already be
3756 completely specified and contain only absolute attributes. Every
3757 specified attribute of FROM overrides the corresponding attribute of
3758 TO; relative attributes in FROM are merged with the absolute value in
3759 TO and replace it. NAMED_MERGE_POINTS is used internally to detect
3760 loops in face inheritance; it should be 0 when called from other
3764 merge_face_vectors (f
, from
, to
, named_merge_points
)
3766 Lisp_Object
*from
, *to
;
3767 struct named_merge_point
*named_merge_points
;
3771 /* If FROM inherits from some other faces, merge their attributes into
3772 TO before merging FROM's direct attributes. Note that an :inherit
3773 attribute of `unspecified' is the same as one of nil; we never
3774 merge :inherit attributes, so nil is more correct, but lots of
3775 other code uses `unspecified' as a generic value for face attributes. */
3776 if (!UNSPECIFIEDP (from
[LFACE_INHERIT_INDEX
])
3777 && !NILP (from
[LFACE_INHERIT_INDEX
]))
3778 merge_face_ref (f
, from
[LFACE_INHERIT_INDEX
], to
, 0, named_merge_points
);
3780 /* If TO specifies a :font attribute, and FROM specifies some
3781 font-related attribute, we need to clear TO's :font attribute
3782 (because it will be inconsistent with whatever FROM specifies, and
3783 FROM takes precedence). */
3784 if (!NILP (to
[LFACE_FONT_INDEX
])
3785 && (!UNSPECIFIEDP (from
[LFACE_FAMILY_INDEX
])
3786 || !UNSPECIFIEDP (from
[LFACE_HEIGHT_INDEX
])
3787 || !UNSPECIFIEDP (from
[LFACE_WEIGHT_INDEX
])
3788 || !UNSPECIFIEDP (from
[LFACE_SLANT_INDEX
])
3789 || !UNSPECIFIEDP (from
[LFACE_SWIDTH_INDEX
])
3790 || !UNSPECIFIEDP (from
[LFACE_AVGWIDTH_INDEX
])))
3791 to
[LFACE_FONT_INDEX
] = Qnil
;
3793 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3794 if (!UNSPECIFIEDP (from
[i
]))
3796 if (i
== LFACE_HEIGHT_INDEX
&& !INTEGERP (from
[i
]))
3797 to
[i
] = merge_face_heights (from
[i
], to
[i
], to
[i
]);
3802 /* TO is always an absolute face, which should inherit from nothing.
3803 We blindly copy the :inherit attribute above and fix it up here. */
3804 to
[LFACE_INHERIT_INDEX
] = Qnil
;
3807 /* Merge the named face FACE_NAME on frame F, into the vector of face
3808 attributes TO. NAMED_MERGE_POINTS is used to detect loops in face
3809 inheritance. Returns true if FACE_NAME is a valid face name and
3810 merging succeeded. */
3813 merge_named_face (f
, face_name
, to
, named_merge_points
)
3815 Lisp_Object face_name
;
3817 struct named_merge_point
*named_merge_points
;
3819 struct named_merge_point named_merge_point
;
3821 if (push_named_merge_point (&named_merge_point
,
3822 face_name
, &named_merge_points
))
3824 struct gcpro gcpro1
;
3825 Lisp_Object from
[LFACE_VECTOR_SIZE
];
3826 int ok
= get_lface_attributes (f
, face_name
, from
, 0);
3830 GCPRO1 (named_merge_point
.face_name
);
3831 merge_face_vectors (f
, from
, to
, named_merge_points
);
3842 /* Merge face attributes from the lisp `face reference' FACE_REF on
3843 frame F into the face attribute vector TO. If ERR_MSGS is non-zero,
3844 problems with FACE_REF cause an error message to be shown. Return
3845 non-zero if no errors occurred (regardless of the value of ERR_MSGS).
3846 NAMED_MERGE_POINTS is used to detect loops in face inheritance or
3847 list structure; it may be 0 for most callers.
3849 FACE_REF may be a single face specification or a list of such
3850 specifications. Each face specification can be:
3852 1. A symbol or string naming a Lisp face.
3854 2. A property list of the form (KEYWORD VALUE ...) where each
3855 KEYWORD is a face attribute name, and value is an appropriate value
3858 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
3859 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
3860 for compatibility with 20.2.
3862 Face specifications earlier in lists take precedence over later
3866 merge_face_ref (f
, face_ref
, to
, err_msgs
, named_merge_points
)
3868 Lisp_Object face_ref
;
3871 struct named_merge_point
*named_merge_points
;
3873 int ok
= 1; /* Succeed without an error? */
3875 if (CONSP (face_ref
))
3877 Lisp_Object first
= XCAR (face_ref
);
3879 if (EQ (first
, Qforeground_color
)
3880 || EQ (first
, Qbackground_color
))
3882 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
3883 . COLOR). COLOR must be a string. */
3884 Lisp_Object color_name
= XCDR (face_ref
);
3885 Lisp_Object color
= first
;
3887 if (STRINGP (color_name
))
3889 if (EQ (color
, Qforeground_color
))
3890 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
3892 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
3897 add_to_log ("Invalid face color", color_name
, Qnil
);
3901 else if (SYMBOLP (first
)
3902 && *SDATA (SYMBOL_NAME (first
)) == ':')
3904 /* Assume this is the property list form. */
3905 while (CONSP (face_ref
) && CONSP (XCDR (face_ref
)))
3907 Lisp_Object keyword
= XCAR (face_ref
);
3908 Lisp_Object value
= XCAR (XCDR (face_ref
));
3911 /* Specifying `unspecified' is a no-op. */
3912 if (EQ (value
, Qunspecified
))
3914 else if (EQ (keyword
, QCfamily
))
3916 if (STRINGP (value
))
3917 to
[LFACE_FAMILY_INDEX
] = value
;
3921 else if (EQ (keyword
, QCheight
))
3923 Lisp_Object new_height
=
3924 merge_face_heights (value
, to
[LFACE_HEIGHT_INDEX
], Qnil
);
3926 if (! NILP (new_height
))
3927 to
[LFACE_HEIGHT_INDEX
] = new_height
;
3931 else if (EQ (keyword
, QCweight
))
3934 && face_numeric_weight (value
) >= 0)
3935 to
[LFACE_WEIGHT_INDEX
] = value
;
3939 else if (EQ (keyword
, QCslant
))
3942 && face_numeric_slant (value
) >= 0)
3943 to
[LFACE_SLANT_INDEX
] = value
;
3947 else if (EQ (keyword
, QCunderline
))
3952 to
[LFACE_UNDERLINE_INDEX
] = value
;
3956 else if (EQ (keyword
, QCoverline
))
3961 to
[LFACE_OVERLINE_INDEX
] = value
;
3965 else if (EQ (keyword
, QCstrike_through
))
3970 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
3974 else if (EQ (keyword
, QCbox
))
3977 value
= make_number (1);
3978 if (INTEGERP (value
)
3982 to
[LFACE_BOX_INDEX
] = value
;
3986 else if (EQ (keyword
, QCinverse_video
)
3987 || EQ (keyword
, QCreverse_video
))
3989 if (EQ (value
, Qt
) || NILP (value
))
3990 to
[LFACE_INVERSE_INDEX
] = value
;
3994 else if (EQ (keyword
, QCforeground
))
3996 if (STRINGP (value
))
3997 to
[LFACE_FOREGROUND_INDEX
] = value
;
4001 else if (EQ (keyword
, QCbackground
))
4003 if (STRINGP (value
))
4004 to
[LFACE_BACKGROUND_INDEX
] = value
;
4008 else if (EQ (keyword
, QCstipple
))
4010 #ifdef HAVE_X_WINDOWS
4011 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
4012 if (!NILP (pixmap_p
))
4013 to
[LFACE_STIPPLE_INDEX
] = value
;
4018 else if (EQ (keyword
, QCwidth
))
4021 && face_numeric_swidth (value
) >= 0)
4022 to
[LFACE_SWIDTH_INDEX
] = value
;
4026 else if (EQ (keyword
, QCinherit
))
4028 /* This is not really very useful; it's just like a
4029 normal face reference. */
4030 if (! merge_face_ref (f
, value
, to
,
4031 err_msgs
, named_merge_points
))
4039 add_to_log ("Invalid face attribute %S %S", keyword
, value
);
4043 face_ref
= XCDR (XCDR (face_ref
));
4048 /* This is a list of face refs. Those at the beginning of the
4049 list take precedence over what follows, so we have to merge
4050 from the end backwards. */
4051 Lisp_Object next
= XCDR (face_ref
);
4054 ok
= merge_face_ref (f
, next
, to
, err_msgs
, named_merge_points
);
4056 if (! merge_face_ref (f
, first
, to
, err_msgs
, named_merge_points
))
4062 /* FACE_REF ought to be a face name. */
4063 ok
= merge_named_face (f
, face_ref
, to
, named_merge_points
);
4064 if (!ok
&& err_msgs
)
4065 add_to_log ("Invalid face reference: %s", face_ref
, Qnil
);
4072 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
4073 Sinternal_make_lisp_face
, 1, 2, 0,
4074 doc
: /* Make FACE, a symbol, a Lisp face with all attributes nil.
4075 If FACE was not known as a face before, create a new one.
4076 If optional argument FRAME is specified, make a frame-local face
4077 for that frame. Otherwise operate on the global face definition.
4078 Value is a vector of face attributes. */)
4080 Lisp_Object face
, frame
;
4082 Lisp_Object global_lface
, lface
;
4086 CHECK_SYMBOL (face
);
4087 global_lface
= lface_from_face_name (NULL
, face
, 0);
4091 CHECK_LIVE_FRAME (frame
);
4093 lface
= lface_from_face_name (f
, face
, 0);
4096 f
= NULL
, lface
= Qnil
;
4098 /* Add a global definition if there is none. */
4099 if (NILP (global_lface
))
4101 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
4103 ASET (global_lface
, 0, Qface
);
4104 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
4105 Vface_new_frame_defaults
);
4107 /* Assign the new Lisp face a unique ID. The mapping from Lisp
4108 face id to Lisp face is given by the vector lface_id_to_name.
4109 The mapping from Lisp face to Lisp face id is given by the
4110 property `face' of the Lisp face name. */
4111 if (next_lface_id
== lface_id_to_name_size
)
4113 int new_size
= max (50, 2 * lface_id_to_name_size
);
4114 int sz
= new_size
* sizeof *lface_id_to_name
;
4115 lface_id_to_name
= (Lisp_Object
*) xrealloc (lface_id_to_name
, sz
);
4116 lface_id_to_name_size
= new_size
;
4119 lface_id_to_name
[next_lface_id
] = face
;
4120 Fput (face
, Qface
, make_number (next_lface_id
));
4124 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4125 ASET (global_lface
, i
, Qunspecified
);
4127 /* Add a frame-local definition. */
4132 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
4134 ASET (lface
, 0, Qface
);
4135 f
->face_alist
= Fcons (Fcons (face
, lface
), f
->face_alist
);
4138 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4139 ASET (lface
, i
, Qunspecified
);
4142 lface
= global_lface
;
4144 /* Changing a named face means that all realized faces depending on
4145 that face are invalid. Since we cannot tell which realized faces
4146 depend on the face, make sure they are all removed. This is done
4147 by incrementing face_change_count. The next call to
4148 init_iterator will then free realized faces. */
4149 if (NILP (Fget (face
, Qface_no_inherit
)))
4151 ++face_change_count
;
4152 ++windows_or_buffers_changed
;
4155 xassert (LFACEP (lface
));
4156 check_lface (lface
);
4161 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
4162 Sinternal_lisp_face_p
, 1, 2, 0,
4163 doc
: /* Return non-nil if FACE names a face.
4164 If optional second argument FRAME is non-nil, check for the
4165 existence of a frame-local face with name FACE on that frame.
4166 Otherwise check for the existence of a global face. */)
4168 Lisp_Object face
, frame
;
4172 face
= resolve_face_name (face
, 1);
4176 CHECK_LIVE_FRAME (frame
);
4177 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
4180 lface
= lface_from_face_name (NULL
, face
, 0);
4186 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
4187 Sinternal_copy_lisp_face
, 4, 4, 0,
4188 doc
: /* Copy face FROM to TO.
4189 If FRAME is t, copy the global face definition of FROM.
4190 Otherwise, copy the frame-local definition of FROM on FRAME.
4191 If NEW-FRAME is a frame, copy that data into the frame-local
4192 definition of TO on NEW-FRAME. If NEW-FRAME is nil.
4193 FRAME controls where the data is copied to.
4195 The value is TO. */)
4196 (from
, to
, frame
, new_frame
)
4197 Lisp_Object from
, to
, frame
, new_frame
;
4199 Lisp_Object lface
, copy
;
4201 CHECK_SYMBOL (from
);
4206 /* Copy global definition of FROM. We don't make copies of
4207 strings etc. because 20.2 didn't do it either. */
4208 lface
= lface_from_face_name (NULL
, from
, 1);
4209 copy
= Finternal_make_lisp_face (to
, Qnil
);
4213 /* Copy frame-local definition of FROM. */
4214 if (NILP (new_frame
))
4216 CHECK_LIVE_FRAME (frame
);
4217 CHECK_LIVE_FRAME (new_frame
);
4218 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
4219 copy
= Finternal_make_lisp_face (to
, new_frame
);
4222 bcopy (XVECTOR (lface
)->contents
, XVECTOR (copy
)->contents
,
4223 LFACE_VECTOR_SIZE
* sizeof (Lisp_Object
));
4225 /* Changing a named face means that all realized faces depending on
4226 that face are invalid. Since we cannot tell which realized faces
4227 depend on the face, make sure they are all removed. This is done
4228 by incrementing face_change_count. The next call to
4229 init_iterator will then free realized faces. */
4230 if (NILP (Fget (to
, Qface_no_inherit
)))
4232 ++face_change_count
;
4233 ++windows_or_buffers_changed
;
4240 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
4241 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
4242 doc
: /* Set attribute ATTR of FACE to VALUE.
4243 FRAME being a frame means change the face on that frame.
4244 FRAME nil means change the face of the selected frame.
4245 FRAME t means change the default for new frames.
4246 FRAME 0 means change the face on all frames, and change the default
4248 (face
, attr
, value
, frame
)
4249 Lisp_Object face
, attr
, value
, frame
;
4252 Lisp_Object old_value
= Qnil
;
4253 /* Set 1 if ATTR is QCfont. */
4254 int font_attr_p
= 0;
4255 /* Set 1 if ATTR is one of font-related attributes other than QCfont. */
4256 int font_related_attr_p
= 0;
4258 CHECK_SYMBOL (face
);
4259 CHECK_SYMBOL (attr
);
4261 face
= resolve_face_name (face
, 1);
4263 /* If FRAME is 0, change face on all frames, and change the
4264 default for new frames. */
4265 if (INTEGERP (frame
) && XINT (frame
) == 0)
4268 Finternal_set_lisp_face_attribute (face
, attr
, value
, Qt
);
4269 FOR_EACH_FRAME (tail
, frame
)
4270 Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
4274 /* Set lface to the Lisp attribute vector of FACE. */
4277 lface
= lface_from_face_name (NULL
, face
, 1);
4279 /* When updating face-new-frame-defaults, we put :ignore-defface
4280 where the caller wants `unspecified'. This forces the frame
4281 defaults to ignore the defface value. Otherwise, the defface
4282 will take effect, which is generally not what is intended.
4283 The value of that attribute will be inherited from some other
4284 face during face merging. See internal_merge_in_global_face. */
4285 if (UNSPECIFIEDP (value
))
4286 value
= Qignore_defface
;
4291 frame
= selected_frame
;
4293 CHECK_LIVE_FRAME (frame
);
4294 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
4296 /* If a frame-local face doesn't exist yet, create one. */
4298 lface
= Finternal_make_lisp_face (face
, frame
);
4301 if (EQ (attr
, QCfamily
))
4303 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
4305 CHECK_STRING (value
);
4306 if (SCHARS (value
) == 0)
4307 signal_error ("Invalid face family", value
);
4309 old_value
= LFACE_FAMILY (lface
);
4310 LFACE_FAMILY (lface
) = value
;
4311 font_related_attr_p
= 1;
4313 else if (EQ (attr
, QCheight
))
4315 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
4319 test
= (EQ (face
, Qdefault
)
4321 /* The default face must have an absolute size,
4322 otherwise, we do a test merge with a random
4323 height to see if VALUE's ok. */
4324 : merge_face_heights (value
, make_number (10), Qnil
));
4326 if (!INTEGERP (test
) || XINT (test
) <= 0)
4327 signal_error ("Invalid face height", value
);
4330 old_value
= LFACE_HEIGHT (lface
);
4331 LFACE_HEIGHT (lface
) = value
;
4332 font_related_attr_p
= 1;
4334 else if (EQ (attr
, QCweight
))
4336 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
4338 CHECK_SYMBOL (value
);
4339 if (face_numeric_weight (value
) < 0)
4340 signal_error ("Invalid face weight", value
);
4342 old_value
= LFACE_WEIGHT (lface
);
4343 LFACE_WEIGHT (lface
) = value
;
4344 font_related_attr_p
= 1;
4346 else if (EQ (attr
, QCslant
))
4348 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
4350 CHECK_SYMBOL (value
);
4351 if (face_numeric_slant (value
) < 0)
4352 signal_error ("Invalid face slant", value
);
4354 old_value
= LFACE_SLANT (lface
);
4355 LFACE_SLANT (lface
) = value
;
4356 font_related_attr_p
= 1;
4358 else if (EQ (attr
, QCunderline
))
4360 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
4361 if ((SYMBOLP (value
)
4363 && !EQ (value
, Qnil
))
4364 /* Underline color. */
4366 && SCHARS (value
) == 0))
4367 signal_error ("Invalid face underline", value
);
4369 old_value
= LFACE_UNDERLINE (lface
);
4370 LFACE_UNDERLINE (lface
) = value
;
4372 else if (EQ (attr
, QCoverline
))
4374 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
4375 if ((SYMBOLP (value
)
4377 && !EQ (value
, Qnil
))
4378 /* Overline color. */
4380 && SCHARS (value
) == 0))
4381 signal_error ("Invalid face overline", value
);
4383 old_value
= LFACE_OVERLINE (lface
);
4384 LFACE_OVERLINE (lface
) = value
;
4386 else if (EQ (attr
, QCstrike_through
))
4388 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
4389 if ((SYMBOLP (value
)
4391 && !EQ (value
, Qnil
))
4392 /* Strike-through color. */
4394 && SCHARS (value
) == 0))
4395 signal_error ("Invalid face strike-through", value
);
4397 old_value
= LFACE_STRIKE_THROUGH (lface
);
4398 LFACE_STRIKE_THROUGH (lface
) = value
;
4400 else if (EQ (attr
, QCbox
))
4404 /* Allow t meaning a simple box of width 1 in foreground color
4407 value
= make_number (1);
4409 if (UNSPECIFIEDP (value
) || IGNORE_DEFFACE_P (value
))
4411 else if (NILP (value
))
4413 else if (INTEGERP (value
))
4414 valid_p
= XINT (value
) != 0;
4415 else if (STRINGP (value
))
4416 valid_p
= SCHARS (value
) > 0;
4417 else if (CONSP (value
))
4433 if (EQ (k
, QCline_width
))
4435 if (!INTEGERP (v
) || XINT (v
) == 0)
4438 else if (EQ (k
, QCcolor
))
4440 if (!NILP (v
) && (!STRINGP (v
) || SCHARS (v
) == 0))
4443 else if (EQ (k
, QCstyle
))
4445 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
4452 valid_p
= NILP (tem
);
4458 signal_error ("Invalid face box", value
);
4460 old_value
= LFACE_BOX (lface
);
4461 LFACE_BOX (lface
) = value
;
4463 else if (EQ (attr
, QCinverse_video
)
4464 || EQ (attr
, QCreverse_video
))
4466 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
4468 CHECK_SYMBOL (value
);
4469 if (!EQ (value
, Qt
) && !NILP (value
))
4470 signal_error ("Invalid inverse-video face attribute value", value
);
4472 old_value
= LFACE_INVERSE (lface
);
4473 LFACE_INVERSE (lface
) = value
;
4475 else if (EQ (attr
, QCforeground
))
4477 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
4479 /* Don't check for valid color names here because it depends
4480 on the frame (display) whether the color will be valid
4481 when the face is realized. */
4482 CHECK_STRING (value
);
4483 if (SCHARS (value
) == 0)
4484 signal_error ("Empty foreground color value", value
);
4486 old_value
= LFACE_FOREGROUND (lface
);
4487 LFACE_FOREGROUND (lface
) = value
;
4489 else if (EQ (attr
, QCbackground
))
4491 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
4493 /* Don't check for valid color names here because it depends
4494 on the frame (display) whether the color will be valid
4495 when the face is realized. */
4496 CHECK_STRING (value
);
4497 if (SCHARS (value
) == 0)
4498 signal_error ("Empty background color value", value
);
4500 old_value
= LFACE_BACKGROUND (lface
);
4501 LFACE_BACKGROUND (lface
) = value
;
4503 else if (EQ (attr
, QCstipple
))
4505 #ifdef HAVE_X_WINDOWS
4506 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
4508 && NILP (Fbitmap_spec_p (value
)))
4509 signal_error ("Invalid stipple attribute", value
);
4510 old_value
= LFACE_STIPPLE (lface
);
4511 LFACE_STIPPLE (lface
) = value
;
4512 #endif /* HAVE_X_WINDOWS */
4514 else if (EQ (attr
, QCwidth
))
4516 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
4518 CHECK_SYMBOL (value
);
4519 if (face_numeric_swidth (value
) < 0)
4520 signal_error ("Invalid face width", value
);
4522 old_value
= LFACE_SWIDTH (lface
);
4523 LFACE_SWIDTH (lface
) = value
;
4524 font_related_attr_p
= 1;
4526 else if (EQ (attr
, QCfont
) || EQ (attr
, QCfontset
))
4528 #ifdef HAVE_WINDOW_SYSTEM
4529 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
4531 /* Set font-related attributes of the Lisp face from an XLFD
4537 f
= SELECTED_FRAME ();
4539 f
= check_x_frame (frame
);
4541 #ifdef USE_FONT_BACKEND
4542 if (enable_font_backend
4543 && !UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
4545 tmp
= Fquery_fontset (value
, Qnil
);
4546 if (EQ (attr
, QCfontset
))
4549 signal_error ("Invalid fontset name", value
);
4550 LFACE_FONTSET (lface
) = tmp
;
4555 Lisp_Object font_object
;
4559 fontset
= fs_query_fontset (tmp
, 0);
4560 value
= fontset_ascii (fontset
);
4564 fontset
= FRAME_FONTSET (f
);
4566 font_object
= font_open_by_name (f
, SDATA (value
));
4567 if (NILP (font_object
))
4568 signal_error ("Invalid font", value
);
4569 set_lface_from_font_and_fontset (f
, lface
, font_object
,
4574 #endif /* USE_FONT_BACKEND */
4575 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
4577 CHECK_STRING (value
);
4579 /* VALUE may be a fontset name or an alias of fontset. In
4580 such a case, use the base fontset name. */
4581 tmp
= Fquery_fontset (value
, Qnil
);
4584 else if (EQ (attr
, QCfontset
))
4585 signal_error ("Invalid fontset name", value
);
4587 if (EQ (attr
, QCfont
))
4589 if (!set_lface_from_font_name (f
, lface
, value
, 1, 1))
4590 signal_error ("Invalid font or fontset name", value
);
4593 LFACE_FONTSET (lface
) = value
;
4598 #endif /* HAVE_WINDOW_SYSTEM */
4600 else if (EQ (attr
, QCinherit
))
4603 if (SYMBOLP (value
))
4606 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
4607 if (!SYMBOLP (XCAR (tail
)))
4610 LFACE_INHERIT (lface
) = value
;
4612 signal_error ("Invalid face inheritance", value
);
4614 else if (EQ (attr
, QCbold
))
4616 old_value
= LFACE_WEIGHT (lface
);
4617 LFACE_WEIGHT (lface
) = NILP (value
) ? Qnormal
: Qbold
;
4618 font_related_attr_p
= 1;
4620 else if (EQ (attr
, QCitalic
))
4622 old_value
= LFACE_SLANT (lface
);
4623 LFACE_SLANT (lface
) = NILP (value
) ? Qnormal
: Qitalic
;
4624 font_related_attr_p
= 1;
4627 signal_error ("Invalid face attribute name", attr
);
4629 if (font_related_attr_p
4630 && !UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
))
4631 /* If a font-related attribute other than QCfont is specified, the
4632 original `font' attribute nor that of default face is useless
4633 to determine a new font. Thus, we set it to nil so that font
4634 selection mechanism doesn't use it. */
4635 LFACE_FONT (lface
) = Qnil
;
4637 /* Changing a named face means that all realized faces depending on
4638 that face are invalid. Since we cannot tell which realized faces
4639 depend on the face, make sure they are all removed. This is done
4640 by incrementing face_change_count. The next call to
4641 init_iterator will then free realized faces. */
4643 && NILP (Fget (face
, Qface_no_inherit
))
4644 && (EQ (attr
, QCfont
)
4645 || EQ (attr
, QCfontset
)
4646 || NILP (Fequal (old_value
, value
))))
4648 ++face_change_count
;
4649 ++windows_or_buffers_changed
;
4652 if (!UNSPECIFIEDP (value
) && !IGNORE_DEFFACE_P (value
)
4653 && NILP (Fequal (old_value
, value
)))
4659 if (EQ (face
, Qdefault
))
4661 #ifdef HAVE_WINDOW_SYSTEM
4662 /* Changed font-related attributes of the `default' face are
4663 reflected in changed `font' frame parameters. */
4665 && (font_related_attr_p
|| font_attr_p
)
4666 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
4667 set_font_frame_param (frame
, lface
);
4669 #endif /* HAVE_WINDOW_SYSTEM */
4671 if (EQ (attr
, QCforeground
))
4672 param
= Qforeground_color
;
4673 else if (EQ (attr
, QCbackground
))
4674 param
= Qbackground_color
;
4676 #ifdef HAVE_WINDOW_SYSTEM
4678 else if (EQ (face
, Qscroll_bar
))
4680 /* Changing the colors of `scroll-bar' sets frame parameters
4681 `scroll-bar-foreground' and `scroll-bar-background'. */
4682 if (EQ (attr
, QCforeground
))
4683 param
= Qscroll_bar_foreground
;
4684 else if (EQ (attr
, QCbackground
))
4685 param
= Qscroll_bar_background
;
4687 #endif /* not WINDOWSNT */
4688 else if (EQ (face
, Qborder
))
4690 /* Changing background color of `border' sets frame parameter
4692 if (EQ (attr
, QCbackground
))
4693 param
= Qborder_color
;
4695 else if (EQ (face
, Qcursor
))
4697 /* Changing background color of `cursor' sets frame parameter
4699 if (EQ (attr
, QCbackground
))
4700 param
= Qcursor_color
;
4702 else if (EQ (face
, Qmouse
))
4704 /* Changing background color of `mouse' sets frame parameter
4706 if (EQ (attr
, QCbackground
))
4707 param
= Qmouse_color
;
4709 #endif /* HAVE_WINDOW_SYSTEM */
4710 else if (EQ (face
, Qmenu
))
4712 /* Indicate that we have to update the menu bar when
4713 realizing faces on FRAME. FRAME t change the
4714 default for new frames. We do this by setting
4715 setting the flag in new face caches */
4718 struct frame
*f
= XFRAME (frame
);
4719 if (FRAME_FACE_CACHE (f
) == NULL
)
4720 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
4721 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 1;
4724 menu_face_changed_default
= 1;
4730 /* Update `default-frame-alist', which is used for new frames. */
4732 store_in_alist (&Vdefault_frame_alist
, param
, value
);
4735 /* Update the current frame's parameters. */
4738 cons
= XCAR (Vparam_value_alist
);
4739 XSETCAR (cons
, param
);
4740 XSETCDR (cons
, value
);
4741 Fmodify_frame_parameters (frame
, Vparam_value_alist
);
4750 #ifdef HAVE_WINDOW_SYSTEM
4752 /* Set the `font' frame parameter of FRAME determined from `default'
4753 face attributes LFACE. If a font name is explicitely
4754 specfied in LFACE, use it as is. Otherwise, determine a font name
4755 from the other font-related atrributes of LFACE. In that case, if
4756 there's no matching font, signals an error. */
4759 set_font_frame_param (frame
, lface
)
4760 Lisp_Object frame
, lface
;
4762 struct frame
*f
= XFRAME (frame
);
4764 if (FRAME_WINDOW_P (f
))
4766 Lisp_Object font_name
;
4769 if (STRINGP (LFACE_FONT (lface
)))
4770 font_name
= LFACE_FONT (lface
);
4771 #ifdef USE_FONT_BACKEND
4772 else if (enable_font_backend
)
4774 /* We set FONT_NAME to a font-object. */
4775 if (FONT_OBJECT_P (LFACE_FONT (lface
)))
4776 font_name
= LFACE_FONT (lface
);
4779 font_name
= font_find_for_lface (f
, &AREF (lface
, 0), Qnil
, -1);
4780 if (NILP (font_name
))
4781 error ("No font matches the specified attribute");
4782 font_name
= font_open_for_lface (f
, font_name
, &AREF (lface
, 0),
4784 if (NILP (font_name
))
4785 error ("No font matches the specified attribute");
4791 /* Choose a font name that reflects LFACE's attributes and has
4792 the registry and encoding pattern specified in the default
4793 fontset (3rd arg: -1) for ASCII characters (4th arg: 0). */
4794 font
= choose_face_font (f
, XVECTOR (lface
)->contents
, Qnil
, NULL
);
4796 error ("No font matches the specified attribute");
4797 font_name
= build_string (font
);
4801 f
->default_face_done_p
= 0;
4802 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, font_name
), Qnil
));
4807 /* Update the corresponding face when frame parameter PARAM on frame F
4808 has been assigned the value NEW_VALUE. */
4811 update_face_from_frame_parameter (f
, param
, new_value
)
4813 Lisp_Object param
, new_value
;
4815 Lisp_Object face
= Qnil
;
4818 /* If there are no faces yet, give up. This is the case when called
4819 from Fx_create_frame, and we do the necessary things later in
4820 face-set-after-frame-defaults. */
4821 if (NILP (f
->face_alist
))
4824 if (EQ (param
, Qforeground_color
))
4827 lface
= lface_from_face_name (f
, face
, 1);
4828 LFACE_FOREGROUND (lface
) = (STRINGP (new_value
)
4829 ? new_value
: Qunspecified
);
4830 realize_basic_faces (f
);
4832 else if (EQ (param
, Qbackground_color
))
4836 /* Changing the background color might change the background
4837 mode, so that we have to load new defface specs.
4838 Call frame-set-background-mode to do that. */
4839 XSETFRAME (frame
, f
);
4840 call1 (Qframe_set_background_mode
, frame
);
4843 lface
= lface_from_face_name (f
, face
, 1);
4844 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4845 ? new_value
: Qunspecified
);
4846 realize_basic_faces (f
);
4848 else if (EQ (param
, Qborder_color
))
4851 lface
= lface_from_face_name (f
, face
, 1);
4852 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4853 ? new_value
: Qunspecified
);
4855 else if (EQ (param
, Qcursor_color
))
4858 lface
= lface_from_face_name (f
, face
, 1);
4859 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4860 ? new_value
: Qunspecified
);
4862 else if (EQ (param
, Qmouse_color
))
4865 lface
= lface_from_face_name (f
, face
, 1);
4866 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4867 ? new_value
: Qunspecified
);
4870 /* Changing a named face means that all realized faces depending on
4871 that face are invalid. Since we cannot tell which realized faces
4872 depend on the face, make sure they are all removed. This is done
4873 by incrementing face_change_count. The next call to
4874 init_iterator will then free realized faces. */
4876 && NILP (Fget (face
, Qface_no_inherit
)))
4878 ++face_change_count
;
4879 ++windows_or_buffers_changed
;
4884 /* Get the value of X resource RESOURCE, class CLASS for the display
4885 of frame FRAME. This is here because ordinary `x-get-resource'
4886 doesn't take a frame argument. */
4888 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
4889 Sinternal_face_x_get_resource
, 3, 3, 0, doc
: /* */)
4890 (resource
, class, frame
)
4891 Lisp_Object resource
, class, frame
;
4893 Lisp_Object value
= Qnil
;
4894 CHECK_STRING (resource
);
4895 CHECK_STRING (class);
4896 CHECK_LIVE_FRAME (frame
);
4898 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame
)),
4899 resource
, class, Qnil
, Qnil
);
4905 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
4906 If VALUE is "on" or "true", return t. If VALUE is "off" or
4907 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
4908 error; if SIGNAL_P is zero, return 0. */
4911 face_boolean_x_resource_value (value
, signal_p
)
4915 Lisp_Object result
= make_number (0);
4917 xassert (STRINGP (value
));
4919 if (xstricmp (SDATA (value
), "on") == 0
4920 || xstricmp (SDATA (value
), "true") == 0)
4922 else if (xstricmp (SDATA (value
), "off") == 0
4923 || xstricmp (SDATA (value
), "false") == 0)
4925 else if (xstricmp (SDATA (value
), "unspecified") == 0)
4926 result
= Qunspecified
;
4928 signal_error ("Invalid face attribute value from X resource", value
);
4934 DEFUN ("internal-set-lisp-face-attribute-from-resource",
4935 Finternal_set_lisp_face_attribute_from_resource
,
4936 Sinternal_set_lisp_face_attribute_from_resource
,
4937 3, 4, 0, doc
: /* */)
4938 (face
, attr
, value
, frame
)
4939 Lisp_Object face
, attr
, value
, frame
;
4941 CHECK_SYMBOL (face
);
4942 CHECK_SYMBOL (attr
);
4943 CHECK_STRING (value
);
4945 if (xstricmp (SDATA (value
), "unspecified") == 0)
4946 value
= Qunspecified
;
4947 else if (EQ (attr
, QCheight
))
4949 value
= Fstring_to_number (value
, make_number (10));
4950 if (XINT (value
) <= 0)
4951 signal_error ("Invalid face height from X resource", value
);
4953 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
4954 value
= face_boolean_x_resource_value (value
, 1);
4955 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
4956 value
= intern (SDATA (value
));
4957 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
4958 value
= face_boolean_x_resource_value (value
, 1);
4959 else if (EQ (attr
, QCunderline
)
4960 || EQ (attr
, QCoverline
)
4961 || EQ (attr
, QCstrike_through
))
4963 Lisp_Object boolean_value
;
4965 /* If the result of face_boolean_x_resource_value is t or nil,
4966 VALUE does NOT specify a color. */
4967 boolean_value
= face_boolean_x_resource_value (value
, 0);
4968 if (SYMBOLP (boolean_value
))
4969 value
= boolean_value
;
4971 else if (EQ (attr
, QCbox
) || EQ (attr
, QCinherit
))
4972 value
= Fcar (Fread_from_string (value
, Qnil
, Qnil
));
4974 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
4977 #endif /* HAVE_WINDOW_SYSTEM */
4980 /***********************************************************************
4982 ***********************************************************************/
4984 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
4986 /* Make menus on frame F appear as specified by the `menu' face. */
4989 x_update_menu_appearance (f
)
4992 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
4996 && (rdb
= XrmGetDatabase (FRAME_X_DISPLAY (f
)),
5000 Lisp_Object lface
= lface_from_face_name (f
, Qmenu
, 1);
5001 struct face
*face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
5002 const char *myname
= SDATA (Vx_resource_name
);
5005 const char *popup_path
= "popup_menu";
5007 const char *popup_path
= "menu.popup";
5010 if (STRINGP (LFACE_FOREGROUND (lface
)))
5012 sprintf (line
, "%s.%s*foreground: %s",
5014 SDATA (LFACE_FOREGROUND (lface
)));
5015 XrmPutLineResource (&rdb
, line
);
5016 sprintf (line
, "%s.pane.menubar*foreground: %s",
5017 myname
, SDATA (LFACE_FOREGROUND (lface
)));
5018 XrmPutLineResource (&rdb
, line
);
5022 if (STRINGP (LFACE_BACKGROUND (lface
)))
5024 sprintf (line
, "%s.%s*background: %s",
5026 SDATA (LFACE_BACKGROUND (lface
)));
5027 XrmPutLineResource (&rdb
, line
);
5028 sprintf (line
, "%s.pane.menubar*background: %s",
5029 myname
, SDATA (LFACE_BACKGROUND (lface
)));
5030 XrmPutLineResource (&rdb
, line
);
5035 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
5036 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
5037 || !UNSPECIFIEDP (LFACE_AVGWIDTH (lface
))
5038 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
5039 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
5040 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
5043 const char *suffix
= "List";
5046 #if defined HAVE_X_I18N
5048 const char *suffix
= "Set";
5050 const char *suffix
= "";
5054 #if defined HAVE_X_I18N
5055 extern char *xic_create_fontsetname
5056 P_ ((char *base_fontname
, Bool motif
));
5057 char *fontsetname
= xic_create_fontsetname (face
->font_name
, motif
);
5059 char *fontsetname
= face
->font_name
;
5061 sprintf (line
, "%s.pane.menubar*font%s: %s",
5062 myname
, suffix
, fontsetname
);
5063 XrmPutLineResource (&rdb
, line
);
5064 sprintf (line
, "%s.%s*font%s: %s",
5065 myname
, popup_path
, suffix
, fontsetname
);
5066 XrmPutLineResource (&rdb
, line
);
5068 if (fontsetname
!= face
->font_name
)
5069 xfree (fontsetname
);
5072 if (changed_p
&& f
->output_data
.x
->menubar_widget
)
5073 free_frame_menubar (f
);
5077 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
5080 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p
,
5081 Sface_attribute_relative_p
,
5083 doc
: /* Check whether a face attribute value is relative.
5084 Specifically, this function returns t if the attribute ATTRIBUTE
5085 with the value VALUE is relative.
5087 A relative value is one that doesn't entirely override whatever is
5088 inherited from another face. For most possible attributes,
5089 the only relative value that users see is `unspecified'.
5090 However, for :height, floating point values are also relative. */)
5092 Lisp_Object attribute
, value
;
5094 if (EQ (value
, Qunspecified
) || (EQ (value
, Qignore_defface
)))
5096 else if (EQ (attribute
, QCheight
))
5097 return INTEGERP (value
) ? Qnil
: Qt
;
5102 DEFUN ("merge-face-attribute", Fmerge_face_attribute
, Smerge_face_attribute
,
5104 doc
: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
5105 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
5106 the result will be absolute, otherwise it will be relative. */)
5107 (attribute
, value1
, value2
)
5108 Lisp_Object attribute
, value1
, value2
;
5110 if (EQ (value1
, Qunspecified
) || EQ (value1
, Qignore_defface
))
5112 else if (EQ (attribute
, QCheight
))
5113 return merge_face_heights (value1
, value2
, value1
);
5119 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
5120 Sinternal_get_lisp_face_attribute
,
5122 doc
: /* Return face attribute KEYWORD of face SYMBOL.
5123 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
5124 face attribute name, signal an error.
5125 If the optional argument FRAME is given, report on face SYMBOL in that
5126 frame. If FRAME is t, report on the defaults for face SYMBOL (for new
5127 frames). If FRAME is omitted or nil, use the selected frame. */)
5128 (symbol
, keyword
, frame
)
5129 Lisp_Object symbol
, keyword
, frame
;
5131 Lisp_Object lface
, value
= Qnil
;
5133 CHECK_SYMBOL (symbol
);
5134 CHECK_SYMBOL (keyword
);
5137 lface
= lface_from_face_name (NULL
, symbol
, 1);
5141 frame
= selected_frame
;
5142 CHECK_LIVE_FRAME (frame
);
5143 lface
= lface_from_face_name (XFRAME (frame
), symbol
, 1);
5146 if (EQ (keyword
, QCfamily
))
5147 value
= LFACE_FAMILY (lface
);
5148 else if (EQ (keyword
, QCheight
))
5149 value
= LFACE_HEIGHT (lface
);
5150 else if (EQ (keyword
, QCweight
))
5151 value
= LFACE_WEIGHT (lface
);
5152 else if (EQ (keyword
, QCslant
))
5153 value
= LFACE_SLANT (lface
);
5154 else if (EQ (keyword
, QCunderline
))
5155 value
= LFACE_UNDERLINE (lface
);
5156 else if (EQ (keyword
, QCoverline
))
5157 value
= LFACE_OVERLINE (lface
);
5158 else if (EQ (keyword
, QCstrike_through
))
5159 value
= LFACE_STRIKE_THROUGH (lface
);
5160 else if (EQ (keyword
, QCbox
))
5161 value
= LFACE_BOX (lface
);
5162 else if (EQ (keyword
, QCinverse_video
)
5163 || EQ (keyword
, QCreverse_video
))
5164 value
= LFACE_INVERSE (lface
);
5165 else if (EQ (keyword
, QCforeground
))
5166 value
= LFACE_FOREGROUND (lface
);
5167 else if (EQ (keyword
, QCbackground
))
5168 value
= LFACE_BACKGROUND (lface
);
5169 else if (EQ (keyword
, QCstipple
))
5170 value
= LFACE_STIPPLE (lface
);
5171 else if (EQ (keyword
, QCwidth
))
5172 value
= LFACE_SWIDTH (lface
);
5173 else if (EQ (keyword
, QCinherit
))
5174 value
= LFACE_INHERIT (lface
);
5175 else if (EQ (keyword
, QCfont
))
5176 value
= LFACE_FONT (lface
);
5177 else if (EQ (keyword
, QCfontset
))
5178 value
= LFACE_FONTSET (lface
);
5180 signal_error ("Invalid face attribute name", keyword
);
5182 if (IGNORE_DEFFACE_P (value
))
5183 return Qunspecified
;
5189 DEFUN ("internal-lisp-face-attribute-values",
5190 Finternal_lisp_face_attribute_values
,
5191 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
5192 doc
: /* Return a list of valid discrete values for face attribute ATTR.
5193 Value is nil if ATTR doesn't have a discrete set of valid values. */)
5197 Lisp_Object result
= Qnil
;
5199 CHECK_SYMBOL (attr
);
5201 if (EQ (attr
, QCweight
)
5202 || EQ (attr
, QCslant
)
5203 || EQ (attr
, QCwidth
))
5205 /* Extract permissible symbols from tables. */
5206 struct table_entry
*table
;
5209 if (EQ (attr
, QCweight
))
5210 table
= weight_table
, dim
= DIM (weight_table
);
5211 else if (EQ (attr
, QCslant
))
5212 table
= slant_table
, dim
= DIM (slant_table
);
5214 table
= swidth_table
, dim
= DIM (swidth_table
);
5216 for (i
= 0; i
< dim
; ++i
)
5218 Lisp_Object symbol
= *table
[i
].symbol
;
5219 Lisp_Object tail
= result
;
5222 && !EQ (XCAR (tail
), symbol
))
5226 result
= Fcons (symbol
, result
);
5229 else if (EQ (attr
, QCunderline
))
5230 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
5231 else if (EQ (attr
, QCoverline
))
5232 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
5233 else if (EQ (attr
, QCstrike_through
))
5234 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
5235 else if (EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
5236 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
5242 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
5243 Sinternal_merge_in_global_face
, 2, 2, 0,
5244 doc
: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
5245 Default face attributes override any local face attributes. */)
5247 Lisp_Object face
, frame
;
5250 Lisp_Object global_lface
, local_lface
, *gvec
, *lvec
;
5252 CHECK_LIVE_FRAME (frame
);
5253 global_lface
= lface_from_face_name (NULL
, face
, 1);
5254 local_lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
5255 if (NILP (local_lface
))
5256 local_lface
= Finternal_make_lisp_face (face
, frame
);
5258 /* Make every specified global attribute override the local one.
5259 BEWARE!! This is only used from `face-set-after-frame-default' where
5260 the local frame is defined from default specs in `face-defface-spec'
5261 and those should be overridden by global settings. Hence the strange
5262 "global before local" priority. */
5263 lvec
= XVECTOR (local_lface
)->contents
;
5264 gvec
= XVECTOR (global_lface
)->contents
;
5265 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
5266 if (! UNSPECIFIEDP (gvec
[i
]))
5268 if (IGNORE_DEFFACE_P (gvec
[i
]))
5269 lvec
[i
] = Qunspecified
;
5278 /* The following function is implemented for compatibility with 20.2.
5279 The function is used in x-resolve-fonts when it is asked to
5280 return fonts with the same size as the font of a face. This is
5281 done in fontset.el. */
5283 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 3, 0,
5284 doc
: /* Return the font name of face FACE, or nil if it is unspecified.
5285 The font name is, by default, for ASCII characters.
5286 If the optional argument FRAME is given, report on face FACE in that frame.
5287 If FRAME is t, report on the defaults for face FACE (for new frames).
5288 The font default for a face is either nil, or a list
5289 of the form (bold), (italic) or (bold italic).
5290 If FRAME is omitted or nil, use the selected frame. And, in this case,
5291 if the optional third argument CHARACTER is given,
5292 return the font name used for CHARACTER. */)
5293 (face
, frame
, character
)
5294 Lisp_Object face
, frame
, character
;
5298 Lisp_Object result
= Qnil
;
5299 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
5301 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
5302 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
5303 result
= Fcons (Qbold
, result
);
5305 if (!UNSPECIFIEDP (LFACE_SLANT (lface
))
5306 && !EQ (LFACE_SLANT (lface
), Qnormal
))
5307 result
= Fcons (Qitalic
, result
);
5313 struct frame
*f
= frame_or_selected_frame (frame
, 1);
5314 int face_id
= lookup_named_face (f
, face
, 1);
5315 struct face
*face
= FACE_FROM_ID (f
, face_id
);
5319 #ifdef HAVE_WINDOW_SYSTEM
5320 if (FRAME_WINDOW_P (f
) && !NILP (character
))
5322 CHECK_CHARACTER (character
);
5323 face_id
= FACE_FOR_CHAR (f
, face
, XINT (character
), -1, Qnil
);
5324 face
= FACE_FROM_ID (f
, face_id
);
5325 return (face
->font
&& face
->font_name
5326 ? build_string (face
->font_name
)
5330 return build_string (face
->font_name
);
5335 /* Compare face-attribute values v1 and v2 for equality. Value is non-zero if
5336 all attributes are `equal'. Tries to be fast because this function
5337 is called quite often. */
5340 face_attr_equal_p (v1
, v2
)
5343 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
5344 and the other is specified. */
5345 if (XTYPE (v1
) != XTYPE (v2
))
5354 if (SBYTES (v1
) != SBYTES (v2
))
5357 return bcmp (SDATA (v1
), SDATA (v2
), SBYTES (v1
)) == 0;
5364 return !NILP (Fequal (v1
, v2
));
5369 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
5370 all attributes are `equal'. Tries to be fast because this function
5371 is called quite often. */
5374 lface_equal_p (v1
, v2
)
5375 Lisp_Object
*v1
, *v2
;
5379 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
5380 equal_p
= face_attr_equal_p (v1
[i
], v2
[i
]);
5386 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
5387 Sinternal_lisp_face_equal_p
, 2, 3, 0,
5388 doc
: /* True if FACE1 and FACE2 are equal.
5389 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
5390 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
5391 If FRAME is omitted or nil, use the selected frame. */)
5392 (face1
, face2
, frame
)
5393 Lisp_Object face1
, face2
, frame
;
5397 Lisp_Object lface1
, lface2
;
5402 /* Don't use check_x_frame here because this function is called
5403 before X frames exist. At that time, if FRAME is nil,
5404 selected_frame will be used which is the frame dumped with
5405 Emacs. That frame is not an X frame. */
5406 f
= frame_or_selected_frame (frame
, 2);
5408 lface1
= lface_from_face_name (f
, face1
, 1);
5409 lface2
= lface_from_face_name (f
, face2
, 1);
5410 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
5411 XVECTOR (lface2
)->contents
);
5412 return equal_p
? Qt
: Qnil
;
5416 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
5417 Sinternal_lisp_face_empty_p
, 1, 2, 0,
5418 doc
: /* True if FACE has no attribute specified.
5419 If the optional argument FRAME is given, report on face FACE in that frame.
5420 If FRAME is t, report on the defaults for face FACE (for new frames).
5421 If FRAME is omitted or nil, use the selected frame. */)
5423 Lisp_Object face
, frame
;
5430 frame
= selected_frame
;
5431 CHECK_LIVE_FRAME (frame
);
5435 lface
= lface_from_face_name (NULL
, face
, 1);
5437 lface
= lface_from_face_name (f
, face
, 1);
5439 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
5440 if (!UNSPECIFIEDP (AREF (lface
, i
)))
5443 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
5447 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
5449 doc
: /* Return an alist of frame-local faces defined on FRAME.
5450 For internal use only. */)
5454 struct frame
*f
= frame_or_selected_frame (frame
, 0);
5455 return f
->face_alist
;
5459 /* Return a hash code for Lisp string STRING with case ignored. Used
5460 below in computing a hash value for a Lisp face. */
5462 static INLINE
unsigned
5463 hash_string_case_insensitive (string
)
5466 const unsigned char *s
;
5468 xassert (STRINGP (string
));
5469 for (s
= SDATA (string
); *s
; ++s
)
5470 hash
= (hash
<< 1) ^ tolower (*s
);
5475 /* Return a hash code for face attribute vector V. */
5477 static INLINE
unsigned
5481 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
5482 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
5483 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
5484 ^ XHASH (v
[LFACE_WEIGHT_INDEX
])
5485 ^ XHASH (v
[LFACE_SLANT_INDEX
])
5486 ^ XHASH (v
[LFACE_SWIDTH_INDEX
])
5487 ^ XHASH (v
[LFACE_HEIGHT_INDEX
]));
5491 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
5492 considering charsets/registries). They do if they specify the same
5493 family, point size, weight, width, slant, font, and fontset. Both
5494 LFACE1 and LFACE2 must be fully-specified. */
5497 lface_same_font_attributes_p (lface1
, lface2
)
5498 Lisp_Object
*lface1
, *lface2
;
5500 xassert (lface_fully_specified_p (lface1
)
5501 && lface_fully_specified_p (lface2
));
5502 return (xstricmp (SDATA (lface1
[LFACE_FAMILY_INDEX
]),
5503 SDATA (lface2
[LFACE_FAMILY_INDEX
])) == 0
5504 && EQ (lface1
[LFACE_HEIGHT_INDEX
], lface2
[LFACE_HEIGHT_INDEX
])
5505 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
5506 && EQ (lface1
[LFACE_AVGWIDTH_INDEX
], lface2
[LFACE_AVGWIDTH_INDEX
])
5507 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
5508 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
])
5509 && (EQ (lface1
[LFACE_FONT_INDEX
], lface2
[LFACE_FONT_INDEX
])
5510 || (STRINGP (lface1
[LFACE_FONT_INDEX
])
5511 && STRINGP (lface2
[LFACE_FONT_INDEX
])
5512 && ! xstricmp (SDATA (lface1
[LFACE_FONT_INDEX
]),
5513 SDATA (lface2
[LFACE_FONT_INDEX
]))))
5514 && (EQ (lface1
[LFACE_FONTSET_INDEX
], lface2
[LFACE_FONTSET_INDEX
])
5515 || (STRINGP (lface1
[LFACE_FONTSET_INDEX
])
5516 && STRINGP (lface2
[LFACE_FONTSET_INDEX
])
5517 && ! xstricmp (SDATA (lface1
[LFACE_FONTSET_INDEX
]),
5518 SDATA (lface2
[LFACE_FONTSET_INDEX
]))))
5524 /***********************************************************************
5526 ***********************************************************************/
5528 /* Allocate and return a new realized face for Lisp face attribute
5531 static struct face
*
5532 make_realized_face (attr
)
5535 struct face
*face
= (struct face
*) xmalloc (sizeof *face
);
5536 bzero (face
, sizeof *face
);
5537 face
->ascii_face
= face
;
5538 bcopy (attr
, face
->lface
, sizeof face
->lface
);
5543 /* Free realized face FACE, including its X resources. FACE may
5547 free_realized_face (f
, face
)
5553 #ifdef HAVE_WINDOW_SYSTEM
5554 if (FRAME_WINDOW_P (f
))
5556 /* Free fontset of FACE if it is ASCII face. */
5557 if (face
->fontset
>= 0 && face
== face
->ascii_face
)
5558 free_face_fontset (f
, face
);
5562 #ifdef USE_FONT_BACKEND
5563 if (enable_font_backend
&& face
->font_info
)
5564 font_done_for_face (f
, face
);
5565 #endif /* USE_FONT_BACKEND */
5566 x_free_gc (f
, face
->gc
);
5571 free_face_colors (f
, face
);
5572 x_destroy_bitmap (f
, face
->stipple
);
5574 #endif /* HAVE_WINDOW_SYSTEM */
5581 /* Prepare face FACE for subsequent display on frame F. This
5582 allocated GCs if they haven't been allocated yet or have been freed
5583 by clearing the face cache. */
5586 prepare_face_for_display (f
, face
)
5590 #ifdef HAVE_WINDOW_SYSTEM
5591 xassert (FRAME_WINDOW_P (f
));
5596 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
5598 xgcv
.foreground
= face
->foreground
;
5599 xgcv
.background
= face
->background
;
5600 #ifdef HAVE_X_WINDOWS
5601 xgcv
.graphics_exposures
= False
;
5603 /* The font of FACE may be null if we couldn't load it. */
5606 #ifdef HAVE_X_WINDOWS
5607 #ifdef USE_FONT_BACKEND
5608 if (enable_font_backend
)
5609 xgcv
.font
= FRAME_X_DISPLAY_INFO (f
)->font
->fid
;
5612 xgcv
.font
= face
->font
->fid
;
5615 xgcv
.font
= face
->font
;
5618 xgcv
.font
= face
->font
;
5624 #ifdef HAVE_X_WINDOWS
5627 xgcv
.fill_style
= FillOpaqueStippled
;
5628 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
5629 mask
|= GCFillStyle
| GCStipple
;
5632 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
5633 #ifdef USE_FONT_BACKEND
5634 if (enable_font_backend
&& face
->font
)
5635 font_prepare_for_face (f
, face
);
5636 #endif /* USE_FONT_BACKEND */
5639 #endif /* HAVE_WINDOW_SYSTEM */
5643 /* Returns the `distance' between the colors X and Y. */
5646 color_distance (x
, y
)
5649 /* This formula is from a paper title `Colour metric' by Thiadmer Riemersma.
5650 Quoting from that paper:
5652 This formula has results that are very close to L*u*v* (with the
5653 modified lightness curve) and, more importantly, it is a more even
5654 algorithm: it does not have a range of colours where it suddenly
5655 gives far from optimal results.
5657 See <http://www.compuphase.com/cmetric.htm> for more info. */
5659 long r
= (x
->red
- y
->red
) >> 8;
5660 long g
= (x
->green
- y
->green
) >> 8;
5661 long b
= (x
->blue
- y
->blue
) >> 8;
5662 long r_mean
= (x
->red
+ y
->red
) >> 9;
5665 (((512 + r_mean
) * r
* r
) >> 8)
5667 + (((767 - r_mean
) * b
* b
) >> 8);
5671 DEFUN ("color-distance", Fcolor_distance
, Scolor_distance
, 2, 3, 0,
5672 doc
: /* Return an integer distance between COLOR1 and COLOR2 on FRAME.
5673 COLOR1 and COLOR2 may be either strings containing the color name,
5674 or lists of the form (RED GREEN BLUE).
5675 If FRAME is unspecified or nil, the current frame is used. */)
5676 (color1
, color2
, frame
)
5677 Lisp_Object color1
, color2
, frame
;
5680 XColor cdef1
, cdef2
;
5683 frame
= selected_frame
;
5684 CHECK_LIVE_FRAME (frame
);
5687 if (!(CONSP (color1
) && parse_rgb_list (color1
, &cdef1
))
5688 && !(STRINGP (color1
) && defined_color (f
, SDATA (color1
), &cdef1
, 0)))
5689 signal_error ("Invalid color", color1
);
5690 if (!(CONSP (color2
) && parse_rgb_list (color2
, &cdef2
))
5691 && !(STRINGP (color2
) && defined_color (f
, SDATA (color2
), &cdef2
, 0)))
5692 signal_error ("Invalid color", color2
);
5694 return make_number (color_distance (&cdef1
, &cdef2
));
5698 /***********************************************************************
5700 ***********************************************************************/
5702 /* Return a new face cache for frame F. */
5704 static struct face_cache
*
5708 struct face_cache
*c
;
5711 c
= (struct face_cache
*) xmalloc (sizeof *c
);
5712 bzero (c
, sizeof *c
);
5713 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
5714 c
->buckets
= (struct face
**) xmalloc (size
);
5715 bzero (c
->buckets
, size
);
5717 c
->faces_by_id
= (struct face
**) xmalloc (c
->size
* sizeof *c
->faces_by_id
);
5719 c
->menu_face_changed_p
= menu_face_changed_default
;
5724 /* Clear out all graphics contexts for all realized faces, except for
5725 the basic faces. This should be done from time to time just to avoid
5726 keeping too many graphics contexts that are no longer needed. */
5730 struct face_cache
*c
;
5732 if (c
&& FRAME_WINDOW_P (c
->f
))
5734 #ifdef HAVE_WINDOW_SYSTEM
5736 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
5738 struct face
*face
= c
->faces_by_id
[i
];
5739 if (face
&& face
->gc
)
5742 #ifdef USE_FONT_BACKEND
5743 if (enable_font_backend
&& face
->font_info
)
5744 font_done_for_face (c
->f
, face
);
5745 #endif /* USE_FONT_BACKEND */
5746 x_free_gc (c
->f
, face
->gc
);
5751 #endif /* HAVE_WINDOW_SYSTEM */
5756 /* Free all realized faces in face cache C, including basic faces.
5757 C may be null. If faces are freed, make sure the frame's current
5758 matrix is marked invalid, so that a display caused by an expose
5759 event doesn't try to use faces we destroyed. */
5762 free_realized_faces (c
)
5763 struct face_cache
*c
;
5768 struct frame
*f
= c
->f
;
5770 /* We must block input here because we can't process X events
5771 safely while only some faces are freed, or when the frame's
5772 current matrix still references freed faces. */
5775 for (i
= 0; i
< c
->used
; ++i
)
5777 free_realized_face (f
, c
->faces_by_id
[i
]);
5778 c
->faces_by_id
[i
] = NULL
;
5782 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
5783 bzero (c
->buckets
, size
);
5785 /* Must do a thorough redisplay the next time. Mark current
5786 matrices as invalid because they will reference faces freed
5787 above. This function is also called when a frame is
5788 destroyed. In this case, the root window of F is nil. */
5789 if (WINDOWP (f
->root_window
))
5791 clear_current_matrices (f
);
5792 ++windows_or_buffers_changed
;
5800 /* Free all realized faces that are using FONTSET on frame F. */
5803 free_realized_faces_for_fontset (f
, fontset
)
5807 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5811 /* We must block input here because we can't process X events safely
5812 while only some faces are freed, or when the frame's current
5813 matrix still references freed faces. */
5816 for (i
= 0; i
< cache
->used
; i
++)
5818 face
= cache
->faces_by_id
[i
];
5820 && face
->fontset
== fontset
)
5822 uncache_face (cache
, face
);
5823 free_realized_face (f
, face
);
5827 /* Must do a thorough redisplay the next time. Mark current
5828 matrices as invalid because they will reference faces freed
5829 above. This function is also called when a frame is destroyed.
5830 In this case, the root window of F is nil. */
5831 if (WINDOWP (f
->root_window
))
5833 clear_current_matrices (f
);
5834 ++windows_or_buffers_changed
;
5841 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
5842 This is done after attributes of a named face have been changed,
5843 because we can't tell which realized faces depend on that face. */
5846 free_all_realized_faces (frame
)
5852 FOR_EACH_FRAME (rest
, frame
)
5853 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
5856 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
5860 /* Free face cache C and faces in it, including their X resources. */
5864 struct face_cache
*c
;
5868 free_realized_faces (c
);
5870 xfree (c
->faces_by_id
);
5876 /* Cache realized face FACE in face cache C. HASH is the hash value
5877 of FACE. If FACE is for ASCII characters (i.e. FACE->ascii_face ==
5878 FACE), insert the new face to the beginning of the collision list
5879 of the face hash table of C. Otherwise, add the new face to the
5880 end of the collision list. This way, lookup_face can quickly find
5881 that a requested face is not cached. */
5884 cache_face (c
, face
, hash
)
5885 struct face_cache
*c
;
5889 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
5893 if (face
->ascii_face
!= face
)
5895 struct face
*last
= c
->buckets
[i
];
5906 c
->buckets
[i
] = face
;
5907 face
->prev
= face
->next
= NULL
;
5913 face
->next
= c
->buckets
[i
];
5915 face
->next
->prev
= face
;
5916 c
->buckets
[i
] = face
;
5919 /* Find a free slot in C->faces_by_id and use the index of the free
5920 slot as FACE->id. */
5921 for (i
= 0; i
< c
->used
; ++i
)
5922 if (c
->faces_by_id
[i
] == NULL
)
5926 /* Maybe enlarge C->faces_by_id. */
5929 if (c
->used
== c
->size
)
5932 new_size
= min (2 * c
->size
, MAX_FACE_ID
);
5933 if (new_size
== c
->size
)
5934 abort (); /* Alternatives? ++kfs */
5935 sz
= new_size
* sizeof *c
->faces_by_id
;
5936 c
->faces_by_id
= (struct face
**) xrealloc (c
->faces_by_id
, sz
);
5943 /* Check that FACE got a unique id. */
5948 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
5949 for (face
= c
->buckets
[j
]; face
; face
= face
->next
)
5955 #endif /* GLYPH_DEBUG */
5957 c
->faces_by_id
[i
] = face
;
5961 /* Remove face FACE from cache C. */
5964 uncache_face (c
, face
)
5965 struct face_cache
*c
;
5968 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
5971 face
->prev
->next
= face
->next
;
5973 c
->buckets
[i
] = face
->next
;
5976 face
->next
->prev
= face
->prev
;
5978 c
->faces_by_id
[face
->id
] = NULL
;
5979 if (face
->id
== c
->used
)
5984 /* Look up a realized face with face attributes ATTR in the face cache
5985 of frame F. The face will be used to display ASCII characters.
5986 Value is the ID of the face found. If no suitable face is found,
5987 realize a new one. */
5990 lookup_face (f
, attr
)
5994 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5999 xassert (cache
!= NULL
);
6000 check_lface_attrs (attr
);
6002 /* Look up ATTR in the face cache. */
6003 hash
= lface_hash (attr
);
6004 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
6006 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
6008 if (face
->ascii_face
!= face
)
6010 /* There's no more ASCII face. */
6014 if (face
->hash
== hash
6015 && lface_equal_p (face
->lface
, attr
))
6019 /* If not found, realize a new face. */
6021 face
= realize_face (cache
, attr
, -1);
6024 xassert (face
== FACE_FROM_ID (f
, face
->id
));
6025 #endif /* GLYPH_DEBUG */
6030 #ifdef HAVE_WINDOW_SYSTEM
6031 /* Look up a realized face that has the same attributes as BASE_FACE
6032 except for the font in the face cache of frame F. If FONT_ID is
6033 not negative, it is an ID number of an already opened font that is
6034 used by the face. If FONT_ID is negative, the face has no font.
6035 Value is the ID of the face found. If no suitable face is found,
6036 realize a new one. */
6039 lookup_non_ascii_face (f
, font_id
, base_face
)
6042 struct face
*base_face
;
6044 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
6049 xassert (cache
!= NULL
);
6050 base_face
= base_face
->ascii_face
;
6051 hash
= lface_hash (base_face
->lface
);
6052 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
6054 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
6056 if (face
->ascii_face
== face
)
6058 if (face
->ascii_face
== base_face
6059 && face
->font_info_id
== font_id
)
6063 /* If not found, realize a new face. */
6065 face
= realize_non_ascii_face (f
, font_id
, base_face
);
6068 xassert (face
== FACE_FROM_ID (f
, face
->id
));
6069 #endif /* GLYPH_DEBUG */
6074 #ifdef USE_FONT_BACKEND
6076 face_for_font (f
, font
, base_face
)
6079 struct face
*base_face
;
6081 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
6086 xassert (cache
!= NULL
);
6087 base_face
= base_face
->ascii_face
;
6088 hash
= lface_hash (base_face
->lface
);
6089 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
6091 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
6093 if (face
->ascii_face
== face
)
6095 if (face
->ascii_face
== base_face
6096 && face
->font
== font
->font
.font
6097 && face
->font_info
== (struct font_info
*) font
)
6101 /* If not found, realize a new face. */
6102 face
= realize_non_ascii_face (f
, -1, base_face
);
6103 face
->font
= font
->font
.font
;
6104 face
->font_info
= (struct font_info
*) font
;
6105 face
->font_info_id
= 0;
6106 face
->font_name
= font
->font
.full_name
;
6109 #endif /* USE_FONT_BACKEND */
6111 #endif /* HAVE_WINDOW_SYSTEM */
6113 /* Return the face id of the realized face for named face SYMBOL on
6114 frame F suitable for displaying ASCII characters. Value is -1 if
6115 the face couldn't be determined, which might happen if the default
6116 face isn't realized and cannot be realized. */
6119 lookup_named_face (f
, symbol
, signal_p
)
6124 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6125 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
6126 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6128 if (default_face
== NULL
)
6130 if (!realize_basic_faces (f
))
6132 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6133 if (default_face
== NULL
)
6134 abort (); /* realize_basic_faces must have set it up */
6137 if (!get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
))
6140 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
6141 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
6143 return lookup_face (f
, attrs
);
6147 /* Return the ID of the realized ASCII face of Lisp face with ID
6148 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
6151 ascii_face_of_lisp_face (f
, lface_id
)
6157 if (lface_id
>= 0 && lface_id
< lface_id_to_name_size
)
6159 Lisp_Object face_name
= lface_id_to_name
[lface_id
];
6160 face_id
= lookup_named_face (f
, face_name
, 1);
6169 /* Return a face for charset ASCII that is like the face with id
6170 FACE_ID on frame F, but has a font that is STEPS steps smaller.
6171 STEPS < 0 means larger. Value is the id of the face. */
6174 smaller_face (f
, face_id
, steps
)
6178 #ifdef HAVE_WINDOW_SYSTEM
6180 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6181 int pt
, last_pt
, last_height
;
6184 struct face
*new_face
;
6186 /* If not called for an X frame, just return the original face. */
6187 if (FRAME_TERMCAP_P (f
))
6190 /* Try in increments of 1/2 pt. */
6191 delta
= steps
< 0 ? 5 : -5;
6192 steps
= eabs (steps
);
6194 face
= FACE_FROM_ID (f
, face_id
);
6195 bcopy (face
->lface
, attrs
, sizeof attrs
);
6196 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
6197 new_face_id
= face_id
;
6198 last_height
= FONT_HEIGHT (face
->font
);
6202 /* Give up if we cannot find a font within 10pt. */
6203 && eabs (last_pt
- pt
) < 100)
6205 /* Look up a face for a slightly smaller/larger font. */
6207 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
6208 new_face_id
= lookup_face (f
, attrs
);
6209 new_face
= FACE_FROM_ID (f
, new_face_id
);
6211 /* If height changes, count that as one step. */
6212 if ((delta
< 0 && FONT_HEIGHT (new_face
->font
) < last_height
)
6213 || (delta
> 0 && FONT_HEIGHT (new_face
->font
) > last_height
))
6216 last_height
= FONT_HEIGHT (new_face
->font
);
6223 #else /* not HAVE_WINDOW_SYSTEM */
6227 #endif /* not HAVE_WINDOW_SYSTEM */
6231 /* Return a face for charset ASCII that is like the face with id
6232 FACE_ID on frame F, but has height HEIGHT. */
6235 face_with_height (f
, face_id
, height
)
6240 #ifdef HAVE_WINDOW_SYSTEM
6242 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6244 if (FRAME_TERMCAP_P (f
)
6248 face
= FACE_FROM_ID (f
, face_id
);
6249 bcopy (face
->lface
, attrs
, sizeof attrs
);
6250 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
6251 face_id
= lookup_face (f
, attrs
);
6252 #endif /* HAVE_WINDOW_SYSTEM */
6258 /* Return the face id of the realized face for named face SYMBOL on
6259 frame F suitable for displaying ASCII characters, and use
6260 attributes of the face FACE_ID for attributes that aren't
6261 completely specified by SYMBOL. This is like lookup_named_face,
6262 except that the default attributes come from FACE_ID, not from the
6263 default face. FACE_ID is assumed to be already realized. */
6266 lookup_derived_face (f
, symbol
, face_id
, signal_p
)
6272 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6273 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
6274 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
6279 get_lface_attributes (f
, symbol
, symbol_attrs
, signal_p
);
6280 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
6281 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
6282 return lookup_face (f
, attrs
);
6285 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector
,
6286 Sface_attributes_as_vector
, 1, 1, 0,
6287 doc
: /* Return a vector of face attributes corresponding to PLIST. */)
6292 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
6294 merge_face_ref (XFRAME (selected_frame
), plist
, XVECTOR (lface
)->contents
,
6301 /***********************************************************************
6302 Face capability testing
6303 ***********************************************************************/
6306 /* If the distance (as returned by color_distance) between two colors is
6307 less than this, then they are considered the same, for determining
6308 whether a color is supported or not. The range of values is 0-65535. */
6310 #define TTY_SAME_COLOR_THRESHOLD 10000
6312 #ifdef HAVE_WINDOW_SYSTEM
6314 /* Return non-zero if all the face attributes in ATTRS are supported
6315 on the window-system frame F.
6317 The definition of `supported' is somewhat heuristic, but basically means
6318 that a face containing all the attributes in ATTRS, when merged with the
6319 default face for display, can be represented in a way that's
6321 \(1) different in appearance than the default face, and
6322 \(2) `close in spirit' to what the attributes specify, if not exact. */
6325 x_supports_face_attributes_p (f
, attrs
, def_face
)
6328 struct face
*def_face
;
6330 Lisp_Object
*def_attrs
= def_face
->lface
;
6332 /* Check that other specified attributes are different that the default
6334 if ((!UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
6335 && face_attr_equal_p (attrs
[LFACE_UNDERLINE_INDEX
],
6336 def_attrs
[LFACE_UNDERLINE_INDEX
]))
6337 || (!UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
6338 && face_attr_equal_p (attrs
[LFACE_INVERSE_INDEX
],
6339 def_attrs
[LFACE_INVERSE_INDEX
]))
6340 || (!UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
6341 && face_attr_equal_p (attrs
[LFACE_FOREGROUND_INDEX
],
6342 def_attrs
[LFACE_FOREGROUND_INDEX
]))
6343 || (!UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
6344 && face_attr_equal_p (attrs
[LFACE_BACKGROUND_INDEX
],
6345 def_attrs
[LFACE_BACKGROUND_INDEX
]))
6346 || (!UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
6347 && face_attr_equal_p (attrs
[LFACE_STIPPLE_INDEX
],
6348 def_attrs
[LFACE_STIPPLE_INDEX
]))
6349 || (!UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
6350 && face_attr_equal_p (attrs
[LFACE_OVERLINE_INDEX
],
6351 def_attrs
[LFACE_OVERLINE_INDEX
]))
6352 || (!UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
6353 && face_attr_equal_p (attrs
[LFACE_STRIKE_THROUGH_INDEX
],
6354 def_attrs
[LFACE_STRIKE_THROUGH_INDEX
]))
6355 || (!UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
6356 && face_attr_equal_p (attrs
[LFACE_BOX_INDEX
],
6357 def_attrs
[LFACE_BOX_INDEX
])))
6360 /* Check font-related attributes, as those are the most commonly
6361 "unsupported" on a window-system (because of missing fonts). */
6362 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
6363 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
6364 || !UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
6365 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
6366 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
6367 || !UNSPECIFIEDP (attrs
[LFACE_AVGWIDTH_INDEX
]))
6371 Lisp_Object merged_attrs
[LFACE_VECTOR_SIZE
];
6373 bcopy (def_attrs
, merged_attrs
, sizeof merged_attrs
);
6375 merge_face_vectors (f
, attrs
, merged_attrs
, 0);
6377 face_id
= lookup_face (f
, merged_attrs
);
6378 face
= FACE_FROM_ID (f
, face_id
);
6381 error ("Cannot make face");
6383 /* If the font is the same, then not supported. */
6384 if (face
->font
== def_face
->font
)
6388 /* Everything checks out, this face is supported. */
6392 #endif /* HAVE_WINDOW_SYSTEM */
6394 /* Return non-zero if all the face attributes in ATTRS are supported
6397 The definition of `supported' is somewhat heuristic, but basically means
6398 that a face containing all the attributes in ATTRS, when merged
6399 with the default face for display, can be represented in a way that's
6401 \(1) different in appearance than the default face, and
6402 \(2) `close in spirit' to what the attributes specify, if not exact.
6404 Point (2) implies that a `:weight black' attribute will be satisfied
6405 by any terminal that can display bold, and a `:foreground "yellow"' as
6406 long as the terminal can display a yellowish color, but `:slant italic'
6407 will _not_ be satisfied by the tty display code's automatic
6408 substitution of a `dim' face for italic. */
6411 tty_supports_face_attributes_p (f
, attrs
, def_face
)
6414 struct face
*def_face
;
6417 Lisp_Object val
, fg
, bg
;
6418 XColor fg_tty_color
, fg_std_color
;
6419 XColor bg_tty_color
, bg_std_color
;
6420 unsigned test_caps
= 0;
6421 Lisp_Object
*def_attrs
= def_face
->lface
;
6424 /* First check some easy-to-check stuff; ttys support none of the
6425 following attributes, so we can just return false if any are requested
6426 (even if `nominal' values are specified, we should still return false,
6427 as that will be the same value that the default face uses). We
6428 consider :slant unsupportable on ttys, even though the face code
6429 actually `fakes' them using a dim attribute if possible. This is
6430 because the faked result is too different from what the face
6432 if (!UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
6433 || !UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
6434 || !UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
6435 || !UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
6436 || !UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
6437 || !UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
6438 || !UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
6439 || !UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
]))
6443 /* Test for terminal `capabilities' (non-color character attributes). */
6445 /* font weight (bold/dim) */
6446 weight
= face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
6449 int def_weight
= face_numeric_weight (def_attrs
[LFACE_WEIGHT_INDEX
]);
6451 if (weight
> XLFD_WEIGHT_MEDIUM
)
6453 if (def_weight
> XLFD_WEIGHT_MEDIUM
)
6454 return 0; /* same as default */
6455 test_caps
= TTY_CAP_BOLD
;
6457 else if (weight
< XLFD_WEIGHT_MEDIUM
)
6459 if (def_weight
< XLFD_WEIGHT_MEDIUM
)
6460 return 0; /* same as default */
6461 test_caps
= TTY_CAP_DIM
;
6463 else if (def_weight
== XLFD_WEIGHT_MEDIUM
)
6464 return 0; /* same as default */
6468 val
= attrs
[LFACE_UNDERLINE_INDEX
];
6469 if (!UNSPECIFIEDP (val
))
6472 return 0; /* ttys can't use colored underlines */
6473 else if (face_attr_equal_p (val
, def_attrs
[LFACE_UNDERLINE_INDEX
]))
6474 return 0; /* same as default */
6476 test_caps
|= TTY_CAP_UNDERLINE
;
6480 val
= attrs
[LFACE_INVERSE_INDEX
];
6481 if (!UNSPECIFIEDP (val
))
6483 if (face_attr_equal_p (val
, def_attrs
[LFACE_INVERSE_INDEX
]))
6484 return 0; /* same as default */
6486 test_caps
|= TTY_CAP_INVERSE
;
6490 /* Color testing. */
6492 /* Default the color indices in FG_TTY_COLOR and BG_TTY_COLOR, since
6493 we use them when calling `tty_capable_p' below, even if the face
6494 specifies no colors. */
6495 fg_tty_color
.pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
6496 bg_tty_color
.pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
6498 /* Check if foreground color is close enough. */
6499 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
6502 Lisp_Object def_fg
= def_attrs
[LFACE_FOREGROUND_INDEX
];
6504 if (face_attr_equal_p (fg
, def_fg
))
6505 return 0; /* same as default */
6506 else if (! tty_lookup_color (f
, fg
, &fg_tty_color
, &fg_std_color
))
6507 return 0; /* not a valid color */
6508 else if (color_distance (&fg_tty_color
, &fg_std_color
)
6509 > TTY_SAME_COLOR_THRESHOLD
)
6510 return 0; /* displayed color is too different */
6512 /* Make sure the color is really different than the default. */
6514 XColor def_fg_color
;
6515 if (tty_lookup_color (f
, def_fg
, &def_fg_color
, 0)
6516 && (color_distance (&fg_tty_color
, &def_fg_color
)
6517 <= TTY_SAME_COLOR_THRESHOLD
))
6522 /* Check if background color is close enough. */
6523 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
6526 Lisp_Object def_bg
= def_attrs
[LFACE_BACKGROUND_INDEX
];
6528 if (face_attr_equal_p (bg
, def_bg
))
6529 return 0; /* same as default */
6530 else if (! tty_lookup_color (f
, bg
, &bg_tty_color
, &bg_std_color
))
6531 return 0; /* not a valid color */
6532 else if (color_distance (&bg_tty_color
, &bg_std_color
)
6533 > TTY_SAME_COLOR_THRESHOLD
)
6534 return 0; /* displayed color is too different */
6536 /* Make sure the color is really different than the default. */
6538 XColor def_bg_color
;
6539 if (tty_lookup_color (f
, def_bg
, &def_bg_color
, 0)
6540 && (color_distance (&bg_tty_color
, &def_bg_color
)
6541 <= TTY_SAME_COLOR_THRESHOLD
))
6546 /* If both foreground and background are requested, see if the
6547 distance between them is OK. We just check to see if the distance
6548 between the tty's foreground and background is close enough to the
6549 distance between the standard foreground and background. */
6550 if (STRINGP (fg
) && STRINGP (bg
))
6553 = (color_distance (&fg_std_color
, &bg_std_color
)
6554 - color_distance (&fg_tty_color
, &bg_tty_color
));
6555 if (delta_delta
> TTY_SAME_COLOR_THRESHOLD
6556 || delta_delta
< -TTY_SAME_COLOR_THRESHOLD
)
6561 /* See if the capabilities we selected above are supported, with the
6563 if (test_caps
!= 0 &&
6564 ! tty_capable_p (FRAME_TTY (f
), test_caps
, fg_tty_color
.pixel
, bg_tty_color
.pixel
))
6568 /* Hmmm, everything checks out, this terminal must support this face. */
6573 DEFUN ("display-supports-face-attributes-p",
6574 Fdisplay_supports_face_attributes_p
, Sdisplay_supports_face_attributes_p
,
6576 doc
: /* Return non-nil if all the face attributes in ATTRIBUTES are supported.
6577 The optional argument DISPLAY can be a display name, a frame, or
6578 nil (meaning the selected frame's display).
6580 The definition of `supported' is somewhat heuristic, but basically means
6581 that a face containing all the attributes in ATTRIBUTES, when merged
6582 with the default face for display, can be represented in a way that's
6584 \(1) different in appearance than the default face, and
6585 \(2) `close in spirit' to what the attributes specify, if not exact.
6587 Point (2) implies that a `:weight black' attribute will be satisfied by
6588 any display that can display bold, and a `:foreground \"yellow\"' as long
6589 as it can display a yellowish color, but `:slant italic' will _not_ be
6590 satisfied by the tty display code's automatic substitution of a `dim'
6591 face for italic. */)
6592 (attributes
, display
)
6593 Lisp_Object attributes
, display
;
6595 int supports
= 0, i
;
6598 struct face
*def_face
;
6599 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6601 if (noninteractive
|| !initialized
)
6602 /* We may not be able to access low-level face information in batch
6603 mode, or before being dumped, and this function is not going to
6604 be very useful in those cases anyway, so just give up. */
6608 frame
= selected_frame
;
6609 else if (FRAMEP (display
))
6613 /* Find any frame on DISPLAY. */
6614 Lisp_Object fl_tail
;
6617 for (fl_tail
= Vframe_list
; CONSP (fl_tail
); fl_tail
= XCDR (fl_tail
))
6619 frame
= XCAR (fl_tail
);
6620 if (!NILP (Fequal (Fcdr (Fassq (Qdisplay
,
6621 XFRAME (frame
)->param_alist
)),
6627 CHECK_LIVE_FRAME (frame
);
6630 for (i
= 0; i
< LFACE_VECTOR_SIZE
; i
++)
6631 attrs
[i
] = Qunspecified
;
6632 merge_face_ref (f
, attributes
, attrs
, 1, 0);
6634 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6635 if (def_face
== NULL
)
6637 if (! realize_basic_faces (f
))
6638 error ("Cannot realize default face");
6639 def_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6640 if (def_face
== NULL
)
6641 abort (); /* realize_basic_faces must have set it up */
6644 /* Dispatch to the appropriate handler. */
6645 if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
6646 supports
= tty_supports_face_attributes_p (f
, attrs
, def_face
);
6647 #ifdef HAVE_WINDOW_SYSTEM
6649 supports
= x_supports_face_attributes_p (f
, attrs
, def_face
);
6652 return supports
? Qt
: Qnil
;
6656 /***********************************************************************
6658 ***********************************************************************/
6660 DEFUN ("internal-set-font-selection-order",
6661 Finternal_set_font_selection_order
,
6662 Sinternal_set_font_selection_order
, 1, 1, 0,
6663 doc
: /* Set font selection order for face font selection to ORDER.
6664 ORDER must be a list of length 4 containing the symbols `:width',
6665 `:height', `:weight', and `:slant'. Face attributes appearing
6666 first in ORDER are matched first, e.g. if `:height' appears before
6667 `:weight' in ORDER, font selection first tries to find a font with
6668 a suitable height, and then tries to match the font weight.
6675 int indices
[DIM (font_sort_order
)];
6678 bzero (indices
, sizeof indices
);
6682 CONSP (list
) && i
< DIM (indices
);
6683 list
= XCDR (list
), ++i
)
6685 Lisp_Object attr
= XCAR (list
);
6688 if (EQ (attr
, QCwidth
))
6690 else if (EQ (attr
, QCheight
))
6691 xlfd
= XLFD_POINT_SIZE
;
6692 else if (EQ (attr
, QCweight
))
6694 else if (EQ (attr
, QCslant
))
6699 if (indices
[i
] != 0)
6704 if (!NILP (list
) || i
!= DIM (indices
))
6705 signal_error ("Invalid font sort order", order
);
6706 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6707 if (indices
[i
] == 0)
6708 signal_error ("Invalid font sort order", order
);
6710 if (bcmp (indices
, font_sort_order
, sizeof indices
) != 0)
6712 bcopy (indices
, font_sort_order
, sizeof font_sort_order
);
6713 free_all_realized_faces (Qnil
);
6716 #ifdef USE_FONT_BACKEND
6717 if (enable_font_backend
)
6718 font_update_sort_order (font_sort_order
);
6719 #endif /* USE_FONT_BACKEND */
6725 DEFUN ("internal-set-alternative-font-family-alist",
6726 Finternal_set_alternative_font_family_alist
,
6727 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
6728 doc
: /* Define alternative font families to try in face font selection.
6729 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
6730 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
6731 be found. Value is ALIST. */)
6736 Vface_alternative_font_family_alist
= alist
;
6737 free_all_realized_faces (Qnil
);
6742 DEFUN ("internal-set-alternative-font-registry-alist",
6743 Finternal_set_alternative_font_registry_alist
,
6744 Sinternal_set_alternative_font_registry_alist
, 1, 1, 0,
6745 doc
: /* Define alternative font registries to try in face font selection.
6746 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
6747 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
6748 be found. Value is ALIST. */)
6753 Vface_alternative_font_registry_alist
= alist
;
6754 free_all_realized_faces (Qnil
);
6759 #ifdef HAVE_WINDOW_SYSTEM
6761 /* Value is non-zero if FONT is the name of a scalable font. The
6762 X11R6 XLFD spec says that point size, pixel size, and average width
6763 are zero for scalable fonts. Intlfonts contain at least one
6764 scalable font ("*-muleindian-1") for which this isn't true, so we
6765 just test average width. */
6768 font_scalable_p (font
)
6769 struct font_name
*font
;
6771 char *s
= font
->fields
[XLFD_AVGWIDTH
];
6772 return (*s
== '0' && *(s
+ 1) == '\0')
6774 /* Windows implementation of XLFD is slightly broken for backward
6775 compatibility with previous broken versions, so test for
6776 wildcards as well as 0. */
6783 /* Ignore the difference of font point size less than this value. */
6785 #define FONT_POINT_SIZE_QUANTUM 5
6787 /* Value is non-zero if FONT1 is a better match for font attributes
6788 VALUES than FONT2. VALUES is an array of face attribute values in
6789 font sort order. COMPARE_PT_P zero means don't compare point
6790 sizes. AVGWIDTH, if not zero, is a specified font average width
6794 better_font_p (values
, font1
, font2
, compare_pt_p
, avgwidth
)
6796 struct font_name
*font1
, *font2
;
6797 int compare_pt_p
, avgwidth
;
6801 /* Any font is better than no font. */
6807 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6809 int xlfd_idx
= font_sort_order
[i
];
6811 if (compare_pt_p
|| xlfd_idx
!= XLFD_POINT_SIZE
)
6815 if (xlfd_idx
== XLFD_POINT_SIZE
)
6817 delta1
= eabs (values
[i
] - (font1
->numeric
[xlfd_idx
]
6818 / font1
->rescale_ratio
));
6819 delta2
= eabs (values
[i
] - (font2
->numeric
[xlfd_idx
]
6820 / font2
->rescale_ratio
));
6821 if (eabs (delta1
- delta2
) < FONT_POINT_SIZE_QUANTUM
)
6826 delta1
= eabs (values
[i
] - font1
->numeric
[xlfd_idx
]);
6827 delta2
= eabs (values
[i
] - font2
->numeric
[xlfd_idx
]);
6830 if (delta1
> delta2
)
6832 else if (delta1
< delta2
)
6836 /* The difference may be equal because, e.g., the face
6837 specifies `italic' but we have only `regular' and
6838 `oblique'. Prefer `oblique' in this case. */
6839 if ((xlfd_idx
== XLFD_WEIGHT
|| xlfd_idx
== XLFD_SLANT
)
6840 && font1
->numeric
[xlfd_idx
] > values
[i
]
6841 && font2
->numeric
[xlfd_idx
] < values
[i
])
6849 int delta1
= eabs (avgwidth
- font1
->numeric
[XLFD_AVGWIDTH
]);
6850 int delta2
= eabs (avgwidth
- font2
->numeric
[XLFD_AVGWIDTH
]);
6851 if (delta1
> delta2
)
6853 else if (delta1
< delta2
)
6859 /* We prefer a real scalable font; i.e. not what autoscaled. */
6860 int auto_scaled_1
= (font1
->numeric
[XLFD_POINT_SIZE
] == 0
6861 && font1
->numeric
[XLFD_RESY
] > 0);
6862 int auto_scaled_2
= (font2
->numeric
[XLFD_POINT_SIZE
] == 0
6863 && font2
->numeric
[XLFD_RESY
] > 0);
6865 if (auto_scaled_1
!= auto_scaled_2
)
6866 return auto_scaled_2
;
6869 return font1
->registry_priority
< font2
->registry_priority
;
6873 /* Value is non-zero if FONT is an exact match for face attributes in
6874 SPECIFIED. SPECIFIED is an array of face attribute values in font
6875 sort order. AVGWIDTH, if non-zero, is an average width to compare
6879 exact_face_match_p (specified
, font
, avgwidth
)
6881 struct font_name
*font
;
6886 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6887 if (specified
[i
] != font
->numeric
[font_sort_order
[i
]])
6890 return (i
== DIM (font_sort_order
)
6892 || avgwidth
== font
->numeric
[XLFD_AVGWIDTH
]));
6896 /* Value is the name of a scaled font, generated from scalable font
6897 FONT on frame F. SPECIFIED_PT is the point-size to scale FONT to.
6898 Value is allocated from heap. */
6901 build_scalable_font_name (f
, font
, specified_pt
)
6903 struct font_name
*font
;
6906 char pixel_size
[20];
6908 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
6911 if (font
->numeric
[XLFD_PIXEL_SIZE
] != 0
6912 || font
->numeric
[XLFD_POINT_SIZE
] != 0)
6913 /* This is a scalable font but is requested for a specific size.
6914 We should not change that size. */
6915 return build_font_name (font
);
6917 /* If scalable font is for a specific resolution, compute
6918 the point size we must specify from the resolution of
6919 the display and the specified resolution of the font. */
6920 if (font
->numeric
[XLFD_RESY
] != 0)
6922 pt
= resy
/ font
->numeric
[XLFD_RESY
] * specified_pt
+ 0.5;
6923 pixel_value
= font
->numeric
[XLFD_RESY
] / (PT_PER_INCH
* 10.0) * pt
+ 0.5;
6928 pixel_value
= resy
/ (PT_PER_INCH
* 10.0) * pt
+ 0.5;
6930 /* We may need a font of the different size. */
6931 pixel_value
*= font
->rescale_ratio
;
6933 /* We should keep POINT_SIZE 0. Otherwise, X server can't open a
6934 font of the specified PIXEL_SIZE. */
6936 { /* Set point size of the font. */
6937 char point_size
[20];
6938 sprintf (point_size
, "%d", (int) pt
);
6939 font
->fields
[XLFD_POINT_SIZE
] = point_size
;
6940 font
->numeric
[XLFD_POINT_SIZE
] = pt
;
6944 /* Set pixel size. */
6945 sprintf (pixel_size
, "%d", pixel_value
);
6946 font
->fields
[XLFD_PIXEL_SIZE
] = pixel_size
;
6947 font
->numeric
[XLFD_PIXEL_SIZE
] = pixel_value
;
6949 /* If font doesn't specify its resolution, use the
6950 resolution of the display. */
6951 if (font
->numeric
[XLFD_RESY
] == 0)
6954 sprintf (buffer
, "%d", (int) resy
);
6955 font
->fields
[XLFD_RESY
] = buffer
;
6956 font
->numeric
[XLFD_RESY
] = resy
;
6959 if (strcmp (font
->fields
[XLFD_RESX
], "0") == 0)
6962 int resx
= FRAME_X_DISPLAY_INFO (f
)->resx
;
6963 sprintf (buffer
, "%d", resx
);
6964 font
->fields
[XLFD_RESX
] = buffer
;
6965 font
->numeric
[XLFD_RESX
] = resx
;
6968 return build_font_name (font
);
6972 /* Value is non-zero if we are allowed to use scalable font FONT. We
6973 can't run a Lisp function here since this function may be called
6974 with input blocked. */
6977 may_use_scalable_font_p (font
)
6980 if (EQ (Vscalable_fonts_allowed
, Qt
))
6982 else if (CONSP (Vscalable_fonts_allowed
))
6984 Lisp_Object tail
, regexp
;
6986 for (tail
= Vscalable_fonts_allowed
; CONSP (tail
); tail
= XCDR (tail
))
6988 regexp
= XCAR (tail
);
6989 if (STRINGP (regexp
)
6990 && fast_c_string_match_ignore_case (regexp
, font
) >= 0)
7000 /* Return the name of the best matching font for face attributes ATTRS
7001 in the array of font_name structures FONTS which contains NFONTS
7002 elements. WIDTH_RATIO is a factor with which to multiply average
7003 widths if ATTRS specifies such a width.
7005 Value is a font name which is allocated from the heap. FONTS is
7006 freed by this function.
7008 If NEEDS_OVERSTRIKE is non-zero, a boolean is returned in it to
7009 indicate whether the resulting font should be drawn using overstrike
7010 to simulate bold-face. */
7013 best_matching_font (f
, attrs
, fonts
, nfonts
, width_ratio
, needs_overstrike
)
7016 struct font_name
*fonts
;
7019 int *needs_overstrike
;
7022 struct font_name
*best
;
7025 int exact_p
, avgwidth
;
7030 /* Make specified font attributes available in `specified',
7031 indexed by sort order. */
7032 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
7034 int xlfd_idx
= font_sort_order
[i
];
7036 if (xlfd_idx
== XLFD_SWIDTH
)
7037 specified
[i
] = face_numeric_swidth (attrs
[LFACE_SWIDTH_INDEX
]);
7038 else if (xlfd_idx
== XLFD_POINT_SIZE
)
7039 specified
[i
] = pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
7040 else if (xlfd_idx
== XLFD_WEIGHT
)
7041 specified
[i
] = face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
7042 else if (xlfd_idx
== XLFD_SLANT
)
7043 specified
[i
] = face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
7048 avgwidth
= (UNSPECIFIEDP (attrs
[LFACE_AVGWIDTH_INDEX
])
7050 : XFASTINT (attrs
[LFACE_AVGWIDTH_INDEX
]) * width_ratio
);
7054 if (needs_overstrike
)
7055 *needs_overstrike
= 0;
7059 /* Find the best match among the non-scalable fonts. */
7060 for (i
= 0; i
< nfonts
; ++i
)
7061 if (!font_scalable_p (fonts
+ i
)
7062 && better_font_p (specified
, fonts
+ i
, best
, 1, avgwidth
))
7066 exact_p
= exact_face_match_p (specified
, best
, avgwidth
);
7071 /* Unless we found an exact match among non-scalable fonts, see if
7072 we can find a better match among scalable fonts. */
7075 /* A scalable font is better if
7077 1. its weight, slant, swidth attributes are better, or.
7079 2. the best non-scalable font doesn't have the required
7080 point size, and the scalable fonts weight, slant, swidth
7083 int non_scalable_has_exact_height_p
;
7085 if (best
&& best
->numeric
[XLFD_POINT_SIZE
] == pt
)
7086 non_scalable_has_exact_height_p
= 1;
7088 non_scalable_has_exact_height_p
= 0;
7090 for (i
= 0; i
< nfonts
; ++i
)
7091 if (font_scalable_p (fonts
+ i
))
7093 if (better_font_p (specified
, fonts
+ i
, best
, 0, 0)
7094 || (!non_scalable_has_exact_height_p
7095 && !better_font_p (specified
, best
, fonts
+ i
, 0, 0)))
7097 non_scalable_has_exact_height_p
= 1;
7103 /* We should have found SOME font. */
7107 if (! exact_p
&& needs_overstrike
)
7109 enum xlfd_weight want_weight
= specified
[XLFD_WEIGHT
];
7110 enum xlfd_weight got_weight
= best
->numeric
[XLFD_WEIGHT
];
7112 if (want_weight
> XLFD_WEIGHT_MEDIUM
&& want_weight
> got_weight
)
7114 /* We want a bold font, but didn't get one; try to use
7115 overstriking instead to simulate bold-face. However,
7116 don't overstrike an already-bold font unless the
7117 desired weight grossly exceeds the available weight. */
7118 if (got_weight
> XLFD_WEIGHT_MEDIUM
)
7119 *needs_overstrike
= (want_weight
- got_weight
) > 2;
7121 *needs_overstrike
= 1;
7125 if (font_scalable_p (best
))
7126 font_name
= build_scalable_font_name (f
, best
, pt
);
7128 font_name
= build_font_name (best
);
7130 /* Free font_name structures. */
7131 free_font_names (fonts
, nfonts
);
7137 /* Get a list of matching fonts on frame F, considering FAMILY
7138 and alternative font families from Vface_alternative_font_registry_alist.
7140 FAMILY is the font family whose alternatives are considered.
7142 REGISTRY, if a string, specifies a font registry and encoding to
7143 match. A value of nil means include fonts of any registry and
7146 Return in *FONTS a pointer to a vector of font_name structures for
7147 the fonts matched. Value is the number of fonts found. */
7150 try_alternative_families (f
, family
, registry
, fonts
)
7152 Lisp_Object family
, registry
;
7153 struct font_name
**fonts
;
7158 nfonts
= font_list (f
, Qnil
, family
, registry
, fonts
);
7161 /* Try alternative font families. */
7162 alter
= Fassoc (family
, Vface_alternative_font_family_alist
);
7165 for (alter
= XCDR (alter
);
7166 CONSP (alter
) && nfonts
== 0;
7167 alter
= XCDR (alter
))
7169 if (STRINGP (XCAR (alter
)))
7170 nfonts
= font_list (f
, Qnil
, XCAR (alter
), registry
, fonts
);
7174 /* Try all scalable fonts before giving up. */
7175 if (nfonts
== 0 && ! EQ (Vscalable_fonts_allowed
, Qt
))
7177 int count
= SPECPDL_INDEX ();
7178 specbind (Qscalable_fonts_allowed
, Qt
);
7179 nfonts
= try_alternative_families (f
, family
, registry
, fonts
);
7180 unbind_to (count
, Qnil
);
7187 /* Get a list of matching fonts on frame F.
7189 PATTERN, if a string, specifies a font name pattern to match while
7190 ignoring FAMILY and REGISTRY.
7192 FAMILY, if a list, specifies a list of font families to try.
7194 REGISTRY, if a list, specifies a list of font registries and
7197 Return in *FONTS a pointer to a vector of font_name structures for
7198 the fonts matched. Value is the number of fonts found. */
7201 try_font_list (f
, pattern
, family
, registry
, fonts
)
7203 Lisp_Object pattern
, family
, registry
;
7204 struct font_name
**fonts
;
7208 if (STRINGP (pattern
))
7210 nfonts
= font_list (f
, pattern
, Qnil
, Qnil
, fonts
);
7211 if (nfonts
== 0 && ! EQ (Vscalable_fonts_allowed
, Qt
))
7213 int count
= SPECPDL_INDEX ();
7214 specbind (Qscalable_fonts_allowed
, Qt
);
7215 nfonts
= font_list (f
, pattern
, Qnil
, Qnil
, fonts
);
7216 unbind_to (count
, Qnil
);
7224 nfonts
= font_list (f
, Qnil
, Qnil
, registry
, fonts
);
7226 for (tail
= family
; ! nfonts
&& CONSP (tail
); tail
= XCDR (tail
))
7227 nfonts
= try_alternative_families (f
, XCAR (tail
), registry
, fonts
);
7229 /* Try font family of the default face or "fixed". */
7230 if (nfonts
== 0 && !NILP (family
))
7232 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7234 family
= default_face
->lface
[LFACE_FAMILY_INDEX
];
7236 family
= build_string ("fixed");
7237 nfonts
= try_alternative_families (f
, family
, registry
, fonts
);
7240 /* Try any family with the given registry. */
7241 if (nfonts
== 0 && !NILP (family
))
7242 nfonts
= try_alternative_families (f
, Qnil
, registry
, fonts
);
7249 /* Return the fontset id of the base fontset name or alias name given
7250 by the fontset attribute of ATTRS. Value is -1 if the fontset
7251 attribute of ATTRS doesn't name a fontset. */
7254 face_fontset (attrs
)
7259 name
= attrs
[LFACE_FONTSET_INDEX
];
7260 if (!STRINGP (name
))
7262 return fs_query_fontset (name
, 0);
7266 /* Choose a name of font to use on frame F to display characters with
7267 Lisp face attributes specified by ATTRS. The font name is
7268 determined by the font-related attributes in ATTRS and FONT-SPEC
7271 When we are choosing a font for ASCII characters, FONT-SPEC is
7272 always nil. Otherwise FONT-SPEC is an object created by
7273 `font-spec' or a string specifying a font name pattern.
7275 If NEEDS_OVERSTRIKE is not NULL, a boolean is returned in it to
7276 indicate whether the resulting font should be drawn using
7277 overstrike to simulate bold-face.
7279 Value is the font name which is allocated from the heap and must be
7280 freed by the caller. */
7283 choose_face_font (f
, attrs
, font_spec
, needs_overstrike
)
7286 Lisp_Object font_spec
;
7287 int *needs_overstrike
;
7289 Lisp_Object pattern
, family
, adstyle
, registry
;
7290 char *font_name
= NULL
;
7291 struct font_name
*fonts
;
7294 if (needs_overstrike
)
7295 *needs_overstrike
= 0;
7297 /* If we are choosing an ASCII font and a font name is explicitly
7298 specified in ATTRS, return it. */
7299 if (NILP (font_spec
) && STRINGP (attrs
[LFACE_FONT_INDEX
]))
7300 return xstrdup (SDATA (attrs
[LFACE_FONT_INDEX
]));
7302 if (NILP (attrs
[LFACE_FAMILY_INDEX
]))
7305 family
= Fcons (attrs
[LFACE_FAMILY_INDEX
], Qnil
);
7307 /* Decide FAMILY, ADSTYLE, and REGISTRY from FONT_SPEC. But,
7308 ADSTYLE is not used in the font selector for the moment. */
7309 if (VECTORP (font_spec
))
7312 if (! NILP (AREF (font_spec
, FONT_FAMILY_INDEX
)))
7313 family
= Fcons (SYMBOL_NAME (AREF (font_spec
, FONT_FAMILY_INDEX
)),
7315 adstyle
= AREF (font_spec
, FONT_ADSTYLE_INDEX
);
7316 registry
= Fcons (SYMBOL_NAME (AREF (font_spec
, FONT_REGISTRY_INDEX
)),
7319 else if (STRINGP (font_spec
))
7321 pattern
= font_spec
;
7328 /* We are choosing an ASCII font. By default, use the registry
7329 name "iso8859-1". But, if the registry name of the ASCII
7330 font specified in the fontset of ATTRS is not "iso8859-1"
7331 (e.g "iso10646-1"), use also that name with higher
7333 int fontset
= face_fontset (attrs
);
7336 struct font_name font
;
7340 registry
= Fcons (build_string ("iso8859-1"), Qnil
);
7342 ascii
= fontset_ascii (fontset
);
7343 len
= SBYTES (ascii
);
7345 || strcmp (SDATA (ascii
) + len
- 9, "iso8859-1"))
7347 font
.name
= LSTRDUPA (ascii
);
7348 /* Check if the name is in XLFD. */
7349 if (split_font_name (f
, &font
, 0))
7351 font
.fields
[XLFD_ENCODING
][-1] = '-';
7352 registry
= Fcons (build_string (font
.fields
[XLFD_REGISTRY
]),
7358 /* Get a list of fonts matching that pattern and choose the
7359 best match for the specified face attributes from it. */
7360 nfonts
= try_font_list (f
, pattern
, family
, registry
, &fonts
);
7361 font_name
= best_matching_font (f
, attrs
, fonts
, nfonts
, NILP (font_spec
),
7366 #endif /* HAVE_WINDOW_SYSTEM */
7370 /***********************************************************************
7372 ***********************************************************************/
7374 /* Realize basic faces on frame F. Value is zero if frame parameters
7375 of F don't contain enough information needed to realize the default
7379 realize_basic_faces (f
)
7383 int count
= SPECPDL_INDEX ();
7385 /* Block input here so that we won't be surprised by an X expose
7386 event, for instance, without having the faces set up. */
7388 specbind (Qscalable_fonts_allowed
, Qt
);
7390 if (realize_default_face (f
))
7392 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
7393 realize_named_face (f
, Qmode_line_inactive
, MODE_LINE_INACTIVE_FACE_ID
);
7394 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
7395 realize_named_face (f
, Qfringe
, FRINGE_FACE_ID
);
7396 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
7397 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
7398 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
7399 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
7400 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
7401 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
7402 realize_named_face (f
, Qvertical_border
, VERTICAL_BORDER_FACE_ID
);
7404 /* Reflect changes in the `menu' face in menu bars. */
7405 if (FRAME_FACE_CACHE (f
)->menu_face_changed_p
)
7407 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 0;
7408 #ifdef USE_X_TOOLKIT
7409 if (FRAME_WINDOW_P (f
))
7410 x_update_menu_appearance (f
);
7417 unbind_to (count
, Qnil
);
7423 /* Realize the default face on frame F. If the face is not fully
7424 specified, make it fully-specified. Attributes of the default face
7425 that are not explicitly specified are taken from frame parameters. */
7428 realize_default_face (f
)
7431 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
7433 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
7434 Lisp_Object frame_font
;
7437 /* If the `default' face is not yet known, create it. */
7438 lface
= lface_from_face_name (f
, Qdefault
, 0);
7442 XSETFRAME (frame
, f
);
7443 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
7447 #ifdef HAVE_WINDOW_SYSTEM
7448 if (FRAME_WINDOW_P (f
))
7450 #ifdef USE_FONT_BACKEND
7451 if (enable_font_backend
)
7453 frame_font
= font_find_object (FRAME_FONT_OBJECT (f
));
7454 xassert (FONT_OBJECT_P (frame_font
));
7455 set_lface_from_font_and_fontset (f
, lface
, frame_font
,
7457 f
->default_face_done_p
);
7461 #endif /* USE_FONT_BACKEND */
7462 /* Set frame_font to the value of the `font' frame parameter. */
7463 frame_font
= Fassq (Qfont
, f
->param_alist
);
7464 xassert (CONSP (frame_font
) && STRINGP (XCDR (frame_font
)));
7465 frame_font
= XCDR (frame_font
);
7466 set_lface_from_font_name (f
, lface
, frame_font
,
7467 f
->default_face_done_p
, 1);
7468 #ifdef USE_FONT_BACKEND
7470 #endif /* USE_FONT_BACKEND */
7471 f
->default_face_done_p
= 1;
7473 #endif /* HAVE_WINDOW_SYSTEM */
7475 if (!FRAME_WINDOW_P (f
))
7477 LFACE_FAMILY (lface
) = build_string ("default");
7478 LFACE_SWIDTH (lface
) = Qnormal
;
7479 LFACE_HEIGHT (lface
) = make_number (1);
7480 if (UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
7481 LFACE_WEIGHT (lface
) = Qnormal
;
7482 if (UNSPECIFIEDP (LFACE_SLANT (lface
)))
7483 LFACE_SLANT (lface
) = Qnormal
;
7484 LFACE_AVGWIDTH (lface
) = Qunspecified
;
7487 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
7488 LFACE_UNDERLINE (lface
) = Qnil
;
7490 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
7491 LFACE_OVERLINE (lface
) = Qnil
;
7493 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
7494 LFACE_STRIKE_THROUGH (lface
) = Qnil
;
7496 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
7497 LFACE_BOX (lface
) = Qnil
;
7499 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
7500 LFACE_INVERSE (lface
) = Qnil
;
7502 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
7504 /* This function is called so early that colors are not yet
7505 set in the frame parameter list. */
7506 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
7508 if (CONSP (color
) && STRINGP (XCDR (color
)))
7509 LFACE_FOREGROUND (lface
) = XCDR (color
);
7510 else if (FRAME_WINDOW_P (f
))
7512 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
7513 LFACE_FOREGROUND (lface
) = build_string (unspecified_fg
);
7518 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
7520 /* This function is called so early that colors are not yet
7521 set in the frame parameter list. */
7522 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
7523 if (CONSP (color
) && STRINGP (XCDR (color
)))
7524 LFACE_BACKGROUND (lface
) = XCDR (color
);
7525 else if (FRAME_WINDOW_P (f
))
7527 else if (FRAME_INITIAL_P (f
) || FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
7528 LFACE_BACKGROUND (lface
) = build_string (unspecified_bg
);
7533 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
7534 LFACE_STIPPLE (lface
) = Qnil
;
7536 /* Realize the face; it must be fully-specified now. */
7537 xassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
7538 check_lface (lface
);
7539 bcopy (XVECTOR (lface
)->contents
, attrs
, sizeof attrs
);
7540 face
= realize_face (c
, attrs
, DEFAULT_FACE_ID
);
7542 #ifdef HAVE_WINDOW_SYSTEM
7543 #ifdef HAVE_X_WINDOWS
7544 if (FRAME_X_P (f
) && face
->font
!= FRAME_FONT (f
))
7546 /* This can happen when making a frame on a display that does
7547 not support the default font. */
7551 /* Otherwise, the font specified for the frame was not
7552 acceptable as a font for the default face (perhaps because
7553 auto-scaled fonts are rejected), so we must adjust the frame
7555 x_set_font (f
, build_string (face
->font_name
), Qnil
);
7557 #endif /* HAVE_X_WINDOWS */
7558 #endif /* HAVE_WINDOW_SYSTEM */
7563 /* Realize basic faces other than the default face in face cache C.
7564 SYMBOL is the face name, ID is the face id the realized face must
7565 have. The default face must have been realized already. */
7568 realize_named_face (f
, symbol
, id
)
7573 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
7574 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
7575 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
7576 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
7577 struct face
*new_face
;
7579 /* The default face must exist and be fully specified. */
7580 get_lface_attributes (f
, Qdefault
, attrs
, 1);
7581 check_lface_attrs (attrs
);
7582 xassert (lface_fully_specified_p (attrs
));
7584 /* If SYMBOL isn't know as a face, create it. */
7588 XSETFRAME (frame
, f
);
7589 lface
= Finternal_make_lisp_face (symbol
, frame
);
7592 /* Merge SYMBOL's face with the default face. */
7593 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
7594 merge_face_vectors (f
, symbol_attrs
, attrs
, 0);
7596 /* Realize the face. */
7597 new_face
= realize_face (c
, attrs
, id
);
7601 /* Realize the fully-specified face with attributes ATTRS in face
7602 cache CACHE for ASCII characters. If FORMER_FACE_ID is
7603 non-negative, it is an ID of face to remove before caching the new
7604 face. Value is a pointer to the newly created realized face. */
7606 static struct face
*
7607 realize_face (cache
, attrs
, former_face_id
)
7608 struct face_cache
*cache
;
7614 /* LFACE must be fully specified. */
7615 xassert (cache
!= NULL
);
7616 check_lface_attrs (attrs
);
7618 if (former_face_id
>= 0 && cache
->used
> former_face_id
)
7620 /* Remove the former face. */
7621 struct face
*former_face
= cache
->faces_by_id
[former_face_id
];
7622 uncache_face (cache
, former_face
);
7623 free_realized_face (cache
->f
, former_face
);
7626 if (FRAME_WINDOW_P (cache
->f
))
7627 face
= realize_x_face (cache
, attrs
);
7628 else if (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
))
7629 face
= realize_tty_face (cache
, attrs
);
7630 else if (FRAME_INITIAL_P (cache
->f
))
7632 /* Create a dummy face. */
7633 face
= make_realized_face (attrs
);
7638 /* Insert the new face. */
7639 cache_face (cache
, face
, lface_hash (attrs
));
7644 #ifdef HAVE_WINDOW_SYSTEM
7645 /* Realize the fully-specified face that has the same attributes as
7646 BASE_FACE except for the font on frame F. If FONT_ID is not
7647 negative, it is an ID number of an already opened font that should
7648 be used by the face. If FONT_ID is negative, the face has no font,
7649 i.e., characters are displayed by empty boxes. */
7651 static struct face
*
7652 realize_non_ascii_face (f
, font_id
, base_face
)
7655 struct face
*base_face
;
7657 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
7659 struct font_info
*font_info
;
7661 face
= (struct face
*) xmalloc (sizeof *face
);
7664 #ifdef USE_FONT_BACKEND
7666 #endif /* USE_FONT_BACKEND */
7668 /* Don't try to free the colors copied bitwise from BASE_FACE. */
7669 face
->colors_copied_bitwise_p
= 1;
7671 face
->font_info_id
= font_id
;
7674 font_info
= FONT_INFO_FROM_ID (f
, font_id
);
7675 face
->font
= font_info
->font
;
7676 face
->font_name
= font_info
->full_name
;
7681 face
->font_name
= NULL
;
7686 cache_face (cache
, face
, face
->hash
);
7690 #endif /* HAVE_WINDOW_SYSTEM */
7693 /* Realize the fully-specified face with attributes ATTRS in face
7694 cache CACHE for ASCII characters. Do it for X frame CACHE->f. If
7695 the new face doesn't share font with the default face, a fontname
7696 is allocated from the heap and set in `font_name' of the new face,
7697 but it is not yet loaded here. Value is a pointer to the newly
7698 created realized face. */
7700 static struct face
*
7701 realize_x_face (cache
, attrs
)
7702 struct face_cache
*cache
;
7705 struct face
*face
= NULL
;
7706 #ifdef HAVE_WINDOW_SYSTEM
7707 struct face
*default_face
;
7709 Lisp_Object stipple
, overline
, strike_through
, box
;
7711 xassert (FRAME_WINDOW_P (cache
->f
));
7713 /* Allocate a new realized face. */
7714 face
= make_realized_face (attrs
);
7715 face
->ascii_face
= face
;
7719 /* Determine the font to use. Most of the time, the font will be
7720 the same as the font of the default face, so try that first. */
7721 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7723 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
7725 face
->font
= default_face
->font
;
7726 face
->font_info_id
= default_face
->font_info_id
;
7727 #ifdef USE_FONT_BACKEND
7728 if (enable_font_backend
)
7729 face
->font_info
= default_face
->font_info
;
7730 #endif /* USE_FONT_BACKEND */
7731 face
->font_name
= default_face
->font_name
;
7733 = make_fontset_for_ascii_face (f
, default_face
->fontset
, face
);
7737 /* If the face attribute ATTRS specifies a fontset, use it as
7738 the base of a new realized fontset. Otherwise, use the same
7739 base fontset as of the default face. The base determines
7740 registry and encoding of a font. It may also determine
7741 foundry and family. The other fields of font name pattern
7742 are constructed from ATTRS. */
7743 int fontset
= face_fontset (attrs
);
7745 /* If we are realizing the default face, ATTRS should specify a
7746 fontset. In other words, if FONTSET is -1, we are not
7747 realizing the default face, thus the default face should have
7748 already been realized. */
7750 fontset
= default_face
->fontset
;
7753 #ifdef USE_FONT_BACKEND
7754 if (enable_font_backend
)
7755 font_load_for_face (f
, face
);
7757 #endif /* USE_FONT_BACKEND */
7758 load_face_font (f
, face
);
7760 face
->fontset
= make_fontset_for_ascii_face (f
, fontset
, face
);
7765 /* Load colors, and set remaining attributes. */
7767 load_face_colors (f
, face
, attrs
);
7770 box
= attrs
[LFACE_BOX_INDEX
];
7773 /* A simple box of line width 1 drawn in color given by
7775 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
7777 face
->box
= FACE_SIMPLE_BOX
;
7778 face
->box_line_width
= 1;
7780 else if (INTEGERP (box
))
7782 /* Simple box of specified line width in foreground color of the
7784 xassert (XINT (box
) != 0);
7785 face
->box
= FACE_SIMPLE_BOX
;
7786 face
->box_line_width
= XINT (box
);
7787 face
->box_color
= face
->foreground
;
7788 face
->box_color_defaulted_p
= 1;
7790 else if (CONSP (box
))
7792 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
7793 being one of `raised' or `sunken'. */
7794 face
->box
= FACE_SIMPLE_BOX
;
7795 face
->box_color
= face
->foreground
;
7796 face
->box_color_defaulted_p
= 1;
7797 face
->box_line_width
= 1;
7801 Lisp_Object keyword
, value
;
7803 keyword
= XCAR (box
);
7811 if (EQ (keyword
, QCline_width
))
7813 if (INTEGERP (value
) && XINT (value
) != 0)
7814 face
->box_line_width
= XINT (value
);
7816 else if (EQ (keyword
, QCcolor
))
7818 if (STRINGP (value
))
7820 face
->box_color
= load_color (f
, face
, value
,
7822 face
->use_box_color_for_shadows_p
= 1;
7825 else if (EQ (keyword
, QCstyle
))
7827 if (EQ (value
, Qreleased_button
))
7828 face
->box
= FACE_RAISED_BOX
;
7829 else if (EQ (value
, Qpressed_button
))
7830 face
->box
= FACE_SUNKEN_BOX
;
7835 /* Text underline, overline, strike-through. */
7837 if (EQ (attrs
[LFACE_UNDERLINE_INDEX
], Qt
))
7839 /* Use default color (same as foreground color). */
7840 face
->underline_p
= 1;
7841 face
->underline_defaulted_p
= 1;
7842 face
->underline_color
= 0;
7844 else if (STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]))
7846 /* Use specified color. */
7847 face
->underline_p
= 1;
7848 face
->underline_defaulted_p
= 0;
7849 face
->underline_color
7850 = load_color (f
, face
, attrs
[LFACE_UNDERLINE_INDEX
],
7851 LFACE_UNDERLINE_INDEX
);
7853 else if (NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
7855 face
->underline_p
= 0;
7856 face
->underline_defaulted_p
= 0;
7857 face
->underline_color
= 0;
7860 overline
= attrs
[LFACE_OVERLINE_INDEX
];
7861 if (STRINGP (overline
))
7863 face
->overline_color
7864 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
7865 LFACE_OVERLINE_INDEX
);
7866 face
->overline_p
= 1;
7868 else if (EQ (overline
, Qt
))
7870 face
->overline_color
= face
->foreground
;
7871 face
->overline_color_defaulted_p
= 1;
7872 face
->overline_p
= 1;
7875 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
7876 if (STRINGP (strike_through
))
7878 face
->strike_through_color
7879 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
7880 LFACE_STRIKE_THROUGH_INDEX
);
7881 face
->strike_through_p
= 1;
7883 else if (EQ (strike_through
, Qt
))
7885 face
->strike_through_color
= face
->foreground
;
7886 face
->strike_through_color_defaulted_p
= 1;
7887 face
->strike_through_p
= 1;
7890 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
7891 if (!NILP (stipple
))
7892 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
7893 #endif /* HAVE_WINDOW_SYSTEM */
7899 /* Map a specified color of face FACE on frame F to a tty color index.
7900 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
7901 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
7902 default foreground/background colors. */
7905 map_tty_color (f
, face
, idx
, defaulted
)
7908 enum lface_attribute_index idx
;
7911 Lisp_Object frame
, color
, def
;
7912 int foreground_p
= idx
== LFACE_FOREGROUND_INDEX
;
7913 unsigned long default_pixel
, default_other_pixel
, pixel
;
7915 xassert (idx
== LFACE_FOREGROUND_INDEX
|| idx
== LFACE_BACKGROUND_INDEX
);
7919 pixel
= default_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
7920 default_other_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
7924 pixel
= default_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
7925 default_other_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
7928 XSETFRAME (frame
, f
);
7929 color
= face
->lface
[idx
];
7933 && CONSP (Vtty_defined_color_alist
)
7934 && (def
= assq_no_quit (color
, call1 (Qtty_color_alist
, frame
)),
7937 /* Associations in tty-defined-color-alist are of the form
7938 (NAME INDEX R G B). We need the INDEX part. */
7939 pixel
= XINT (XCAR (XCDR (def
)));
7942 if (pixel
== default_pixel
&& STRINGP (color
))
7944 pixel
= load_color (f
, face
, color
, idx
);
7947 /* If the foreground of the default face is the default color,
7948 use the foreground color defined by the frame. */
7949 if (FRAME_MSDOS_P (f
))
7951 if (pixel
== default_pixel
7952 || pixel
== FACE_TTY_DEFAULT_COLOR
)
7955 pixel
= FRAME_FOREGROUND_PIXEL (f
);
7957 pixel
= FRAME_BACKGROUND_PIXEL (f
);
7958 face
->lface
[idx
] = tty_color_name (f
, pixel
);
7961 else if (pixel
== default_other_pixel
)
7964 pixel
= FRAME_BACKGROUND_PIXEL (f
);
7966 pixel
= FRAME_FOREGROUND_PIXEL (f
);
7967 face
->lface
[idx
] = tty_color_name (f
, pixel
);
7975 face
->foreground
= pixel
;
7977 face
->background
= pixel
;
7981 /* Realize the fully-specified face with attributes ATTRS in face
7982 cache CACHE for ASCII characters. Do it for TTY frame CACHE->f.
7983 Value is a pointer to the newly created realized face. */
7985 static struct face
*
7986 realize_tty_face (cache
, attrs
)
7987 struct face_cache
*cache
;
7992 int face_colors_defaulted
= 0;
7993 struct frame
*f
= cache
->f
;
7995 /* Frame must be a termcap frame. */
7996 xassert (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
));
7998 /* Allocate a new realized face. */
7999 face
= make_realized_face (attrs
);
8000 face
->font_name
= FRAME_MSDOS_P (cache
->f
) ? "ms-dos" : "tty";
8002 /* Map face attributes to TTY appearances. We map slant to
8003 dimmed text because we want italic text to appear differently
8004 and because dimmed text is probably used infrequently. */
8005 weight
= face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
8006 slant
= face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
8008 if (weight
> XLFD_WEIGHT_MEDIUM
)
8009 face
->tty_bold_p
= 1;
8010 if (weight
< XLFD_WEIGHT_MEDIUM
|| slant
!= XLFD_SLANT_ROMAN
)
8011 face
->tty_dim_p
= 1;
8012 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
8013 face
->tty_underline_p
= 1;
8014 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
8015 face
->tty_reverse_p
= 1;
8017 /* Map color names to color indices. */
8018 map_tty_color (f
, face
, LFACE_FOREGROUND_INDEX
, &face_colors_defaulted
);
8019 map_tty_color (f
, face
, LFACE_BACKGROUND_INDEX
, &face_colors_defaulted
);
8021 /* Swap colors if face is inverse-video. If the colors are taken
8022 from the frame colors, they are already inverted, since the
8023 frame-creation function calls x-handle-reverse-video. */
8024 if (face
->tty_reverse_p
&& !face_colors_defaulted
)
8026 unsigned long tem
= face
->foreground
;
8027 face
->foreground
= face
->background
;
8028 face
->background
= tem
;
8031 if (tty_suppress_bold_inverse_default_colors_p
8033 && face
->background
== FACE_TTY_DEFAULT_FG_COLOR
8034 && face
->foreground
== FACE_TTY_DEFAULT_BG_COLOR
)
8035 face
->tty_bold_p
= 0;
8041 DEFUN ("tty-suppress-bold-inverse-default-colors",
8042 Ftty_suppress_bold_inverse_default_colors
,
8043 Stty_suppress_bold_inverse_default_colors
, 1, 1, 0,
8044 doc
: /* Suppress/allow boldness of faces with inverse default colors.
8045 SUPPRESS non-nil means suppress it.
8046 This affects bold faces on TTYs whose foreground is the default background
8047 color of the display and whose background is the default foreground color.
8048 For such faces, the bold face attribute is ignored if this variable
8051 Lisp_Object suppress
;
8053 tty_suppress_bold_inverse_default_colors_p
= !NILP (suppress
);
8054 ++face_change_count
;
8060 /***********************************************************************
8062 ***********************************************************************/
8064 /* Return the ID of the face to use to display character CH with face
8065 property PROP on frame F in current_buffer. */
8068 compute_char_face (f
, ch
, prop
)
8075 if (NILP (current_buffer
->enable_multibyte_characters
))
8080 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
8081 face_id
= FACE_FOR_CHAR (f
, face
, ch
, -1, Qnil
);
8085 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
8086 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
8087 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
8088 merge_face_ref (f
, prop
, attrs
, 1, 0);
8089 face_id
= lookup_face (f
, attrs
);
8095 /* Return the face ID associated with buffer position POS for
8096 displaying ASCII characters. Return in *ENDPTR the position at
8097 which a different face is needed, as far as text properties and
8098 overlays are concerned. W is a window displaying current_buffer.
8100 REGION_BEG, REGION_END delimit the region, so it can be
8103 LIMIT is a position not to scan beyond. That is to limit the time
8104 this function can take.
8106 If MOUSE is non-zero, use the character's mouse-face, not its face.
8108 The face returned is suitable for displaying ASCII characters. */
8111 face_at_buffer_position (w
, pos
, region_beg
, region_end
,
8112 endptr
, limit
, mouse
)
8115 EMACS_INT region_beg
, region_end
;
8120 struct frame
*f
= XFRAME (w
->frame
);
8121 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
8122 Lisp_Object prop
, position
;
8124 Lisp_Object
*overlay_vec
;
8127 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
8128 Lisp_Object limit1
, end
;
8129 struct face
*default_face
;
8131 /* W must display the current buffer. We could write this function
8132 to use the frame and buffer of W, but right now it doesn't. */
8133 /* xassert (XBUFFER (w->buffer) == current_buffer); */
8135 XSETFRAME (frame
, f
);
8136 XSETFASTINT (position
, pos
);
8139 if (pos
< region_beg
&& region_beg
< endpos
)
8140 endpos
= region_beg
;
8142 /* Get the `face' or `mouse_face' text property at POS, and
8143 determine the next position at which the property changes. */
8144 prop
= Fget_text_property (position
, propname
, w
->buffer
);
8145 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
8146 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
8148 endpos
= XINT (end
);
8150 /* Look at properties from overlays. */
8152 EMACS_INT next_overlay
;
8154 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, &next_overlay
, 0);
8155 if (next_overlay
< endpos
)
8156 endpos
= next_overlay
;
8161 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
8163 /* Optimize common cases where we can use the default face. */
8166 && !(pos
>= region_beg
&& pos
< region_end
))
8167 return DEFAULT_FACE_ID
;
8169 /* Begin with attributes from the default face. */
8170 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
8172 /* Merge in attributes specified via text properties. */
8174 merge_face_ref (f
, prop
, attrs
, 1, 0);
8176 /* Now merge the overlay data. */
8177 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
8178 for (i
= 0; i
< noverlays
; i
++)
8183 prop
= Foverlay_get (overlay_vec
[i
], propname
);
8185 merge_face_ref (f
, prop
, attrs
, 1, 0);
8187 oend
= OVERLAY_END (overlay_vec
[i
]);
8188 oendpos
= OVERLAY_POSITION (oend
);
8189 if (oendpos
< endpos
)
8193 /* If in the region, merge in the region face. */
8194 if (pos
>= region_beg
&& pos
< region_end
)
8196 merge_named_face (f
, Qregion
, attrs
, 0);
8198 if (region_end
< endpos
)
8199 endpos
= region_end
;
8204 /* Look up a realized face with the given face attributes,
8205 or realize a new one for ASCII characters. */
8206 return lookup_face (f
, attrs
);
8209 /* Return the face ID at buffer position POS for displaying ASCII
8210 characters associated with overlay strings for overlay OVERLAY.
8212 Like face_at_buffer_position except for OVERLAY. Currently it
8213 simply disregards the `face' properties of all overlays. */
8216 face_for_overlay_string (w
, pos
, region_beg
, region_end
,
8217 endptr
, limit
, mouse
, overlay
)
8220 EMACS_INT region_beg
, region_end
;
8224 Lisp_Object overlay
;
8226 struct frame
*f
= XFRAME (w
->frame
);
8227 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
8228 Lisp_Object prop
, position
;
8231 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
8232 Lisp_Object limit1
, end
;
8233 struct face
*default_face
;
8235 /* W must display the current buffer. We could write this function
8236 to use the frame and buffer of W, but right now it doesn't. */
8237 /* xassert (XBUFFER (w->buffer) == current_buffer); */
8239 XSETFRAME (frame
, f
);
8240 XSETFASTINT (position
, pos
);
8243 if (pos
< region_beg
&& region_beg
< endpos
)
8244 endpos
= region_beg
;
8246 /* Get the `face' or `mouse_face' text property at POS, and
8247 determine the next position at which the property changes. */
8248 prop
= Fget_text_property (position
, propname
, w
->buffer
);
8249 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
8250 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
8252 endpos
= XINT (end
);
8256 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
8258 /* Optimize common cases where we can use the default face. */
8260 && !(pos
>= region_beg
&& pos
< region_end
))
8261 return DEFAULT_FACE_ID
;
8263 /* Begin with attributes from the default face. */
8264 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
8266 /* Merge in attributes specified via text properties. */
8268 merge_face_ref (f
, prop
, attrs
, 1, 0);
8270 /* If in the region, merge in the region face. */
8271 if (pos
>= region_beg
&& pos
< region_end
)
8273 merge_named_face (f
, Qregion
, attrs
, 0);
8275 if (region_end
< endpos
)
8276 endpos
= region_end
;
8281 /* Look up a realized face with the given face attributes,
8282 or realize a new one for ASCII characters. */
8283 return lookup_face (f
, attrs
);
8287 /* Compute the face at character position POS in Lisp string STRING on
8288 window W, for ASCII characters.
8290 If STRING is an overlay string, it comes from position BUFPOS in
8291 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
8292 not an overlay string. W must display the current buffer.
8293 REGION_BEG and REGION_END give the start and end positions of the
8294 region; both are -1 if no region is visible.
8296 BASE_FACE_ID is the id of a face to merge with. For strings coming
8297 from overlays or the `display' property it is the face at BUFPOS.
8299 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
8301 Set *ENDPTR to the next position where to check for faces in
8302 STRING; -1 if the face is constant from POS to the end of the
8305 Value is the id of the face to use. The face returned is suitable
8306 for displaying ASCII characters. */
8309 face_at_string_position (w
, string
, pos
, bufpos
, region_beg
,
8310 region_end
, endptr
, base_face_id
, mouse_p
)
8313 EMACS_INT pos
, bufpos
;
8314 EMACS_INT region_beg
, region_end
;
8316 enum face_id base_face_id
;
8319 Lisp_Object prop
, position
, end
, limit
;
8320 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8321 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
8322 struct face
*base_face
;
8323 int multibyte_p
= STRING_MULTIBYTE (string
);
8324 Lisp_Object prop_name
= mouse_p
? Qmouse_face
: Qface
;
8326 /* Get the value of the face property at the current position within
8327 STRING. Value is nil if there is no face property. */
8328 XSETFASTINT (position
, pos
);
8329 prop
= Fget_text_property (position
, prop_name
, string
);
8331 /* Get the next position at which to check for faces. Value of end
8332 is nil if face is constant all the way to the end of the string.
8333 Otherwise it is a string position where to check faces next.
8334 Limit is the maximum position up to which to check for property
8335 changes in Fnext_single_property_change. Strings are usually
8336 short, so set the limit to the end of the string. */
8337 XSETFASTINT (limit
, SCHARS (string
));
8338 end
= Fnext_single_property_change (position
, prop_name
, string
, limit
);
8340 *endptr
= XFASTINT (end
);
8344 base_face
= FACE_FROM_ID (f
, base_face_id
);
8345 xassert (base_face
);
8347 /* Optimize the default case that there is no face property and we
8348 are not in the region. */
8350 && (base_face_id
!= DEFAULT_FACE_ID
8351 /* BUFPOS <= 0 means STRING is not an overlay string, so
8352 that the region doesn't have to be taken into account. */
8354 || bufpos
< region_beg
8355 || bufpos
>= region_end
)
8357 /* We can't realize faces for different charsets differently
8358 if we don't have fonts, so we can stop here if not working
8359 on a window-system frame. */
8360 || !FRAME_WINDOW_P (f
)
8361 || FACE_SUITABLE_FOR_CHAR_P (base_face
, 0)))
8362 return base_face
->id
;
8364 /* Begin with attributes from the base face. */
8365 bcopy (base_face
->lface
, attrs
, sizeof attrs
);
8367 /* Merge in attributes specified via text properties. */
8369 merge_face_ref (f
, prop
, attrs
, 1, 0);
8371 /* If in the region, merge in the region face. */
8373 && bufpos
>= region_beg
8374 && bufpos
< region_end
)
8375 merge_named_face (f
, Qregion
, attrs
, 0);
8377 /* Look up a realized face with the given face attributes,
8378 or realize a new one for ASCII characters. */
8379 return lookup_face (f
, attrs
);
8383 /* Merge a face into a realized face.
8385 F is frame where faces are (to be) realized.
8387 FACE_NAME is named face to merge.
8389 If FACE_NAME is nil, FACE_ID is face_id of realized face to merge.
8391 If FACE_NAME is t, FACE_ID is lface_id of face to merge.
8393 BASE_FACE_ID is realized face to merge into.
8399 merge_faces (f
, face_name
, face_id
, base_face_id
)
8401 Lisp_Object face_name
;
8402 int face_id
, base_face_id
;
8404 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
8405 struct face
*base_face
;
8407 base_face
= FACE_FROM_ID (f
, base_face_id
);
8409 return base_face_id
;
8411 if (EQ (face_name
, Qt
))
8413 if (face_id
< 0 || face_id
>= lface_id_to_name_size
)
8414 return base_face_id
;
8415 face_name
= lface_id_to_name
[face_id
];
8416 face_id
= lookup_derived_face (f
, face_name
, base_face_id
, 1);
8419 return base_face_id
;
8422 /* Begin with attributes from the base face. */
8423 bcopy (base_face
->lface
, attrs
, sizeof attrs
);
8425 if (!NILP (face_name
))
8427 if (!merge_named_face (f
, face_name
, attrs
, 0))
8428 return base_face_id
;
8434 return base_face_id
;
8435 face
= FACE_FROM_ID (f
, face_id
);
8437 return base_face_id
;
8438 merge_face_vectors (f
, face
->lface
, attrs
, 0);
8441 /* Look up a realized face with the given face attributes,
8442 or realize a new one for ASCII characters. */
8443 return lookup_face (f
, attrs
);
8447 /***********************************************************************
8449 ***********************************************************************/
8453 /* Print the contents of the realized face FACE to stderr. */
8456 dump_realized_face (face
)
8459 fprintf (stderr
, "ID: %d\n", face
->id
);
8460 #ifdef HAVE_X_WINDOWS
8461 fprintf (stderr
, "gc: %ld\n", (long) face
->gc
);
8463 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
8465 SDATA (face
->lface
[LFACE_FOREGROUND_INDEX
]));
8466 fprintf (stderr
, "background: 0x%lx (%s)\n",
8468 SDATA (face
->lface
[LFACE_BACKGROUND_INDEX
]));
8469 fprintf (stderr
, "font_name: %s (%s)\n",
8471 SDATA (face
->lface
[LFACE_FAMILY_INDEX
]));
8472 #ifdef HAVE_X_WINDOWS
8473 fprintf (stderr
, "font = %p\n", face
->font
);
8475 fprintf (stderr
, "font_info_id = %d\n", face
->font_info_id
);
8476 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
8477 fprintf (stderr
, "underline: %d (%s)\n",
8479 SDATA (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
])));
8480 fprintf (stderr
, "hash: %d\n", face
->hash
);
8484 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, doc
: /* */)
8492 fprintf (stderr
, "font selection order: ");
8493 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
8494 fprintf (stderr
, "%d ", font_sort_order
[i
]);
8495 fprintf (stderr
, "\n");
8497 fprintf (stderr
, "alternative fonts: ");
8498 debug_print (Vface_alternative_font_family_alist
);
8499 fprintf (stderr
, "\n");
8501 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
8502 Fdump_face (make_number (i
));
8508 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
8510 error ("Not a valid face");
8511 dump_realized_face (face
);
8518 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
8519 0, 0, 0, doc
: /* */)
8522 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
8523 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
8524 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
8528 #endif /* GLYPH_DEBUG != 0 */
8532 /***********************************************************************
8534 ***********************************************************************/
8539 Qface
= intern ("face");
8541 Qface_no_inherit
= intern ("face-no-inherit");
8542 staticpro (&Qface_no_inherit
);
8543 Qbitmap_spec_p
= intern ("bitmap-spec-p");
8544 staticpro (&Qbitmap_spec_p
);
8545 Qframe_set_background_mode
= intern ("frame-set-background-mode");
8546 staticpro (&Qframe_set_background_mode
);
8548 /* Lisp face attribute keywords. */
8549 QCfamily
= intern (":family");
8550 staticpro (&QCfamily
);
8551 QCheight
= intern (":height");
8552 staticpro (&QCheight
);
8553 QCweight
= intern (":weight");
8554 staticpro (&QCweight
);
8555 QCslant
= intern (":slant");
8556 staticpro (&QCslant
);
8557 QCunderline
= intern (":underline");
8558 staticpro (&QCunderline
);
8559 QCinverse_video
= intern (":inverse-video");
8560 staticpro (&QCinverse_video
);
8561 QCreverse_video
= intern (":reverse-video");
8562 staticpro (&QCreverse_video
);
8563 QCforeground
= intern (":foreground");
8564 staticpro (&QCforeground
);
8565 QCbackground
= intern (":background");
8566 staticpro (&QCbackground
);
8567 QCstipple
= intern (":stipple");
8568 staticpro (&QCstipple
);
8569 QCwidth
= intern (":width");
8570 staticpro (&QCwidth
);
8571 QCfont
= intern (":font");
8572 staticpro (&QCfont
);
8573 QCfontset
= intern (":fontset");
8574 staticpro (&QCfontset
);
8575 QCbold
= intern (":bold");
8576 staticpro (&QCbold
);
8577 QCitalic
= intern (":italic");
8578 staticpro (&QCitalic
);
8579 QCoverline
= intern (":overline");
8580 staticpro (&QCoverline
);
8581 QCstrike_through
= intern (":strike-through");
8582 staticpro (&QCstrike_through
);
8583 QCbox
= intern (":box");
8585 QCinherit
= intern (":inherit");
8586 staticpro (&QCinherit
);
8588 /* Symbols used for Lisp face attribute values. */
8589 QCcolor
= intern (":color");
8590 staticpro (&QCcolor
);
8591 QCline_width
= intern (":line-width");
8592 staticpro (&QCline_width
);
8593 QCstyle
= intern (":style");
8594 staticpro (&QCstyle
);
8595 Qreleased_button
= intern ("released-button");
8596 staticpro (&Qreleased_button
);
8597 Qpressed_button
= intern ("pressed-button");
8598 staticpro (&Qpressed_button
);
8599 Qnormal
= intern ("normal");
8600 staticpro (&Qnormal
);
8601 Qultra_light
= intern ("ultra-light");
8602 staticpro (&Qultra_light
);
8603 Qextra_light
= intern ("extra-light");
8604 staticpro (&Qextra_light
);
8605 Qlight
= intern ("light");
8606 staticpro (&Qlight
);
8607 Qsemi_light
= intern ("semi-light");
8608 staticpro (&Qsemi_light
);
8609 Qsemi_bold
= intern ("semi-bold");
8610 staticpro (&Qsemi_bold
);
8611 Qbold
= intern ("bold");
8613 Qextra_bold
= intern ("extra-bold");
8614 staticpro (&Qextra_bold
);
8615 Qultra_bold
= intern ("ultra-bold");
8616 staticpro (&Qultra_bold
);
8617 Qoblique
= intern ("oblique");
8618 staticpro (&Qoblique
);
8619 Qitalic
= intern ("italic");
8620 staticpro (&Qitalic
);
8621 Qreverse_oblique
= intern ("reverse-oblique");
8622 staticpro (&Qreverse_oblique
);
8623 Qreverse_italic
= intern ("reverse-italic");
8624 staticpro (&Qreverse_italic
);
8625 Qultra_condensed
= intern ("ultra-condensed");
8626 staticpro (&Qultra_condensed
);
8627 Qextra_condensed
= intern ("extra-condensed");
8628 staticpro (&Qextra_condensed
);
8629 Qcondensed
= intern ("condensed");
8630 staticpro (&Qcondensed
);
8631 Qsemi_condensed
= intern ("semi-condensed");
8632 staticpro (&Qsemi_condensed
);
8633 Qsemi_expanded
= intern ("semi-expanded");
8634 staticpro (&Qsemi_expanded
);
8635 Qexpanded
= intern ("expanded");
8636 staticpro (&Qexpanded
);
8637 Qextra_expanded
= intern ("extra-expanded");
8638 staticpro (&Qextra_expanded
);
8639 Qultra_expanded
= intern ("ultra-expanded");
8640 staticpro (&Qultra_expanded
);
8641 Qbackground_color
= intern ("background-color");
8642 staticpro (&Qbackground_color
);
8643 Qforeground_color
= intern ("foreground-color");
8644 staticpro (&Qforeground_color
);
8645 Qunspecified
= intern ("unspecified");
8646 staticpro (&Qunspecified
);
8647 Qignore_defface
= intern (":ignore-defface");
8648 staticpro (&Qignore_defface
);
8650 Qface_alias
= intern ("face-alias");
8651 staticpro (&Qface_alias
);
8652 Qdefault
= intern ("default");
8653 staticpro (&Qdefault
);
8654 Qtool_bar
= intern ("tool-bar");
8655 staticpro (&Qtool_bar
);
8656 Qregion
= intern ("region");
8657 staticpro (&Qregion
);
8658 Qfringe
= intern ("fringe");
8659 staticpro (&Qfringe
);
8660 Qheader_line
= intern ("header-line");
8661 staticpro (&Qheader_line
);
8662 Qscroll_bar
= intern ("scroll-bar");
8663 staticpro (&Qscroll_bar
);
8664 Qmenu
= intern ("menu");
8666 Qcursor
= intern ("cursor");
8667 staticpro (&Qcursor
);
8668 Qborder
= intern ("border");
8669 staticpro (&Qborder
);
8670 Qmouse
= intern ("mouse");
8671 staticpro (&Qmouse
);
8672 Qmode_line_inactive
= intern ("mode-line-inactive");
8673 staticpro (&Qmode_line_inactive
);
8674 Qvertical_border
= intern ("vertical-border");
8675 staticpro (&Qvertical_border
);
8676 Qtty_color_desc
= intern ("tty-color-desc");
8677 staticpro (&Qtty_color_desc
);
8678 Qtty_color_standard_values
= intern ("tty-color-standard-values");
8679 staticpro (&Qtty_color_standard_values
);
8680 Qtty_color_by_index
= intern ("tty-color-by-index");
8681 staticpro (&Qtty_color_by_index
);
8682 Qtty_color_alist
= intern ("tty-color-alist");
8683 staticpro (&Qtty_color_alist
);
8684 Qscalable_fonts_allowed
= intern ("scalable-fonts-allowed");
8685 staticpro (&Qscalable_fonts_allowed
);
8687 Vparam_value_alist
= Fcons (Fcons (Qnil
, Qnil
), Qnil
);
8688 staticpro (&Vparam_value_alist
);
8689 Vface_alternative_font_family_alist
= Qnil
;
8690 staticpro (&Vface_alternative_font_family_alist
);
8691 Vface_alternative_font_registry_alist
= Qnil
;
8692 staticpro (&Vface_alternative_font_registry_alist
);
8694 defsubr (&Sinternal_make_lisp_face
);
8695 defsubr (&Sinternal_lisp_face_p
);
8696 defsubr (&Sinternal_set_lisp_face_attribute
);
8697 #ifdef HAVE_WINDOW_SYSTEM
8698 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
8700 defsubr (&Scolor_gray_p
);
8701 defsubr (&Scolor_supported_p
);
8702 defsubr (&Sface_attribute_relative_p
);
8703 defsubr (&Smerge_face_attribute
);
8704 defsubr (&Sinternal_get_lisp_face_attribute
);
8705 defsubr (&Sinternal_lisp_face_attribute_values
);
8706 defsubr (&Sinternal_lisp_face_equal_p
);
8707 defsubr (&Sinternal_lisp_face_empty_p
);
8708 defsubr (&Sinternal_copy_lisp_face
);
8709 defsubr (&Sinternal_merge_in_global_face
);
8710 defsubr (&Sface_font
);
8711 defsubr (&Sframe_face_alist
);
8712 defsubr (&Sdisplay_supports_face_attributes_p
);
8713 defsubr (&Scolor_distance
);
8714 defsubr (&Sinternal_set_font_selection_order
);
8715 defsubr (&Sinternal_set_alternative_font_family_alist
);
8716 defsubr (&Sinternal_set_alternative_font_registry_alist
);
8717 defsubr (&Sface_attributes_as_vector
);
8719 defsubr (&Sdump_face
);
8720 defsubr (&Sshow_face_resources
);
8721 #endif /* GLYPH_DEBUG */
8722 defsubr (&Sclear_face_cache
);
8723 defsubr (&Stty_suppress_bold_inverse_default_colors
);
8725 #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS
8726 defsubr (&Sdump_colors
);
8729 DEFVAR_LISP ("font-list-limit", &Vfont_list_limit
,
8730 doc
: /* *Limit for font matching.
8731 If an integer > 0, font matching functions won't load more than
8732 that number of fonts when searching for a matching font. */);
8733 Vfont_list_limit
= make_number (DEFAULT_FONT_LIST_LIMIT
);
8735 DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults
,
8736 doc
: /* List of global face definitions (for internal use only.) */);
8737 Vface_new_frame_defaults
= Qnil
;
8739 DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple
,
8740 doc
: /* *Default stipple pattern used on monochrome displays.
8741 This stipple pattern is used on monochrome displays
8742 instead of shades of gray for a face background color.
8743 See `set-face-stipple' for possible values for this variable. */);
8744 Vface_default_stipple
= build_string ("gray3");
8746 DEFVAR_LISP ("tty-defined-color-alist", &Vtty_defined_color_alist
,
8747 doc
: /* An alist of defined terminal colors and their RGB values. */);
8748 Vtty_defined_color_alist
= Qnil
;
8750 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed
,
8751 doc
: /* Allowed scalable fonts.
8752 A value of nil means don't allow any scalable fonts.
8753 A value of t means allow any scalable font.
8754 Otherwise, value must be a list of regular expressions. A font may be
8755 scaled if its name matches a regular expression in the list.
8756 Note that if value is nil, a scalable font might still be used, if no
8757 other font of the appropriate family and registry is available. */);
8758 Vscalable_fonts_allowed
= Qnil
;
8760 DEFVAR_LISP ("face-ignored-fonts", &Vface_ignored_fonts
,
8761 doc
: /* List of ignored fonts.
8762 Each element is a regular expression that matches names of fonts to
8764 Vface_ignored_fonts
= Qnil
;
8766 DEFVAR_LISP ("face-font-rescale-alist", &Vface_font_rescale_alist
,
8767 doc
: /* Alist of fonts vs the rescaling factors.
8768 Each element is a cons (FONT-NAME-PATTERN . RESCALE-RATIO), where
8769 FONT-NAME-PATTERN is a regular expression matching a font name, and
8770 RESCALE-RATIO is a floating point number to specify how much larger
8771 \(or smaller) font we should use. For instance, if a face requests
8772 a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point. */);
8773 Vface_font_rescale_alist
= Qnil
;
8775 #ifdef HAVE_WINDOW_SYSTEM
8776 defsubr (&Sbitmap_spec_p
);
8777 defsubr (&Sx_list_fonts
);
8778 defsubr (&Sinternal_face_x_get_resource
);
8779 defsubr (&Sx_family_fonts
);
8780 defsubr (&Sx_font_family_list
);
8781 #endif /* HAVE_WINDOW_SYSTEM */
8784 /* arch-tag: 8a0f7598-5517-408d-9ab3-1da6fcd4c749
8785 (do not change this comment) */