1 /* xfaces.c -- "Face" primitives.
2 Copyright (C) 1993, 1994, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New face implementation by Gerd Moellmann <gerd@gnu.org>. */
26 When using Emacs with X, the display style of characters can be
27 changed by defining `faces'. Each face can specify the following
32 2. Relative proportionate width, aka character set width or set
33 width (swidth), e.g. `semi-compressed'.
35 3. Font height in 1/10pt.
37 4. Font weight, e.g. `bold'.
39 5. Font slant, e.g. `italic'.
45 8. Whether or not characters should be underlined, and in what color.
47 9. Whether or not characters should be displayed in inverse video.
49 10. A background stipple, a bitmap.
51 11. Whether or not characters should be overlined, and in what color.
53 12. Whether or not characters should be strike-through, and in what
56 13. Whether or not a box should be drawn around characters, the box
57 type, and, for simple boxes, in what color.
59 14. Font 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. */
197 #include <sys/types.h>
198 #include <sys/stat.h>
201 #include "character.h"
203 #include "keyboard.h"
206 #ifdef HAVE_WINDOW_SYSTEM
208 #endif /* HAVE_WINDOW_SYSTEM */
210 #ifdef HAVE_X_WINDOWS
214 #include <Xm/XmStrDefs.h>
215 #endif /* USE_MOTIF */
216 #endif /* HAVE_X_WINDOWS */
225 /* Redefine X specifics to W32 equivalents to avoid cluttering the
226 code with #ifdef blocks. */
227 #undef FRAME_X_DISPLAY_INFO
228 #define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO
229 #define x_display_info w32_display_info
230 #define FRAME_X_FONT_TABLE FRAME_W32_FONT_TABLE
231 #define check_x check_w32
232 #define x_list_fonts w32_list_fonts
233 #define GCGraphicsExposures 0
234 /* For historic reasons, FONT_WIDTH refers to average width on W32,
235 not maximum as on X. Redefine here. */
237 #define FONT_WIDTH FONT_MAX_WIDTH
238 #endif /* WINDOWSNT */
242 #define x_display_info mac_display_info
243 #define check_x check_mac
245 extern XGCValues
*XCreateGC (void *, WindowPtr
, unsigned long, XGCValues
*);
248 x_create_gc (f
, mask
, xgcv
)
254 gc
= XCreateGC (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), mask
, xgcv
);
263 XFreeGC (FRAME_MAC_DISPLAY (f
), gc
);
268 #include "dispextern.h"
269 #include "blockinput.h"
271 #include "intervals.h"
273 #ifdef HAVE_X_WINDOWS
275 /* Compensate for a bug in Xos.h on some systems, on which it requires
276 time.h. On some such systems, Xos.h tries to redefine struct
277 timeval and struct timezone if USG is #defined while it is
280 #ifdef XOS_NEEDS_TIME_H
286 #else /* not XOS_NEEDS_TIME_H */
288 #endif /* not XOS_NEEDS_TIME_H */
290 #endif /* HAVE_X_WINDOWS */
295 #define abs(X) ((X) < 0 ? -(X) : (X))
297 /* Number of pt per inch (from the TeXbook). */
299 #define PT_PER_INCH 72.27
301 /* Non-zero if face attribute ATTR is unspecified. */
303 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified)
305 /* Value is the number of elements of VECTOR. */
307 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
309 /* Make a copy of string S on the stack using alloca. Value is a pointer
312 #define STRDUPA(S) strcpy ((char *) alloca (strlen ((S)) + 1), (S))
314 /* Make a copy of the contents of Lisp string S on the stack using
315 alloca. Value is a pointer to the copy. */
317 #define LSTRDUPA(S) STRDUPA (XSTRING ((S))->data)
319 /* Size of hash table of realized faces in face caches (should be a
322 #define FACE_CACHE_BUCKETS_SIZE 1001
324 /* A definition of XColor for non-X frames. */
326 #ifndef HAVE_X_WINDOWS
331 unsigned short red
, green
, blue
;
337 #endif /* not HAVE_X_WINDOWS */
339 /* Keyword symbols used for face attribute names. */
341 Lisp_Object QCfamily
, QCheight
, QCweight
, QCslant
, QCunderline
;
342 Lisp_Object QCinverse_video
, QCforeground
, QCbackground
, QCstipple
;
343 Lisp_Object QCwidth
, QCfont
, QCbold
, QCitalic
;
344 Lisp_Object QCreverse_video
;
345 Lisp_Object QCoverline
, QCstrike_through
, QCbox
, QCinherit
;
346 Lisp_Object QCfontset
;
348 /* Symbols used for attribute values. */
350 Lisp_Object Qnormal
, Qbold
, Qultra_light
, Qextra_light
, Qlight
;
351 Lisp_Object Qsemi_light
, Qsemi_bold
, Qextra_bold
, Qultra_bold
;
352 Lisp_Object Qoblique
, Qitalic
, Qreverse_oblique
, Qreverse_italic
;
353 Lisp_Object Qultra_condensed
, Qextra_condensed
, Qcondensed
;
354 Lisp_Object Qsemi_condensed
, Qsemi_expanded
, Qexpanded
, Qextra_expanded
;
355 Lisp_Object Qultra_expanded
;
356 Lisp_Object Qreleased_button
, Qpressed_button
;
357 Lisp_Object QCstyle
, QCcolor
, QCline_width
;
358 Lisp_Object Qunspecified
;
360 char unspecified_fg
[] = "unspecified-fg", unspecified_bg
[] = "unspecified-bg";
362 /* The name of the function to call when the background of the frame
363 has changed, frame_update_face_colors. */
365 Lisp_Object Qframe_update_face_colors
;
367 /* Names of basic faces. */
369 Lisp_Object Qdefault
, Qtool_bar
, Qregion
, Qfringe
;
370 Lisp_Object Qheader_line
, Qscroll_bar
, Qcursor
, Qborder
, Qmouse
, Qmenu
;
371 Lisp_Object Qmode_line_inactive
;
372 extern Lisp_Object Qmode_line
;
374 /* The symbol `face-alias'. A symbols having that property is an
375 alias for another face. Value of the property is the name of
378 Lisp_Object Qface_alias
;
380 /* Names of frame parameters related to faces. */
382 extern Lisp_Object Qscroll_bar_foreground
, Qscroll_bar_background
;
383 extern Lisp_Object Qborder_color
, Qcursor_color
, Qmouse_color
;
385 /* Default stipple pattern used on monochrome displays. This stipple
386 pattern is used on monochrome displays instead of shades of gray
387 for a face background color. See `set-face-stipple' for possible
388 values for this variable. */
390 Lisp_Object Vface_default_stipple
;
392 /* Alist of alternative font families. Each element is of the form
393 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
394 try FAMILY1, then FAMILY2, ... */
396 Lisp_Object Vface_alternative_font_family_alist
;
398 /* Alist of alternative font registries. Each element is of the form
399 (REGISTRY REGISTRY1 REGISTRY2...). If fonts of REGISTRY can't be
400 loaded, try REGISTRY1, then REGISTRY2, ... */
402 Lisp_Object Vface_alternative_font_registry_alist
;
404 /* Allowed scalable fonts. A value of nil means don't allow any
405 scalable fonts. A value of t means allow the use of any scalable
406 font. Otherwise, value must be a list of regular expressions. A
407 font may be scaled if its name matches a regular expression in the
410 Lisp_Object Vscalable_fonts_allowed
, Qscalable_fonts_allowed
;
412 /* List of regular expressions that matches names of fonts to ignore. */
414 Lisp_Object Vface_ignored_fonts
;
416 /* Alist of font name patterns vs the resizing factor. */
418 Lisp_Object Vface_resizing_fonts
;
420 /* Maximum number of fonts to consider in font_list. If not an
421 integer > 0, DEFAULT_FONT_LIST_LIMIT is used instead. */
423 Lisp_Object Vfont_list_limit
;
424 #define DEFAULT_FONT_LIST_LIMIT 100
426 /* The symbols `foreground-color' and `background-color' which can be
427 used as part of a `face' property. This is for compatibility with
430 Lisp_Object Qforeground_color
, Qbackground_color
;
432 /* The symbols `face' and `mouse-face' used as text properties. */
435 extern Lisp_Object Qmouse_face
;
437 /* Error symbol for wrong_type_argument in load_pixmap. */
439 Lisp_Object Qbitmap_spec_p
;
441 /* Alist of global face definitions. Each element is of the form
442 (FACE . LFACE) where FACE is a symbol naming a face and LFACE
443 is a Lisp vector of face attributes. These faces are used
444 to initialize faces for new frames. */
446 Lisp_Object Vface_new_frame_defaults
;
448 /* The next ID to assign to Lisp faces. */
450 static int next_lface_id
;
452 /* A vector mapping Lisp face Id's to face names. */
454 static Lisp_Object
*lface_id_to_name
;
455 static int lface_id_to_name_size
;
457 /* TTY color-related functions (defined in tty-colors.el). */
459 Lisp_Object Qtty_color_desc
, Qtty_color_by_index
;
461 /* The name of the function used to compute colors on TTYs. */
463 Lisp_Object Qtty_color_alist
;
465 /* An alist of defined terminal colors and their RGB values. */
467 Lisp_Object Vtty_defined_color_alist
;
469 /* Counter for calls to clear_face_cache. If this counter reaches
470 CLEAR_FONT_TABLE_COUNT, and a frame has more than
471 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
473 static int clear_font_table_count
;
474 #define CLEAR_FONT_TABLE_COUNT 100
475 #define CLEAR_FONT_TABLE_NFONTS 10
477 /* Non-zero means face attributes have been changed since the last
478 redisplay. Used in redisplay_internal. */
480 int face_change_count
;
482 /* Non-zero means don't display bold text if a face's foreground
483 and background colors are the inverse of the default colors of the
484 display. This is a kluge to suppress `bold black' foreground text
485 which is hard to read on an LCD monitor. */
487 int tty_suppress_bold_inverse_default_colors_p
;
489 /* A list of the form `((x . y))' used to avoid consing in
490 Finternal_set_lisp_face_attribute. */
492 static Lisp_Object Vparam_value_alist
;
494 /* The total number of colors currently allocated. */
497 static int ncolors_allocated
;
498 static int npixmaps_allocated
;
502 /* Non-zero means the definition of the `menu' face for new frames has
505 int menu_face_changed_default
;
508 /* Function prototypes. */
513 static void map_tty_color
P_ ((struct frame
*, struct face
*,
514 enum lface_attribute_index
, int *));
515 static Lisp_Object resolve_face_name
P_ ((Lisp_Object
));
516 static int may_use_scalable_font_p
P_ ((char *));
517 static void set_font_frame_param
P_ ((Lisp_Object
, Lisp_Object
));
518 static int better_font_p
P_ ((int *, struct font_name
*, struct font_name
*,
520 static int x_face_list_fonts
P_ ((struct frame
*, char *,
521 struct font_name
*, int, int));
522 static int font_scalable_p
P_ ((struct font_name
*));
523 static int get_lface_attributes
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
*, int));
524 static int load_pixmap
P_ ((struct frame
*, Lisp_Object
, unsigned *, unsigned *));
525 static unsigned char *xstrlwr
P_ ((unsigned char *));
526 static void signal_error
P_ ((char *, Lisp_Object
));
527 static struct frame
*frame_or_selected_frame
P_ ((Lisp_Object
, int));
528 static void load_face_font
P_ ((struct frame
*, struct face
*));
529 static void load_face_colors
P_ ((struct frame
*, struct face
*, Lisp_Object
*));
530 static void free_face_colors
P_ ((struct frame
*, struct face
*));
531 static int face_color_gray_p
P_ ((struct frame
*, char *));
532 static char *build_font_name
P_ ((struct font_name
*));
533 static void free_font_names
P_ ((struct font_name
*, int));
534 static int sorted_font_list
P_ ((struct frame
*, char *,
535 int (*cmpfn
) P_ ((const void *, const void *)),
536 struct font_name
**));
537 static int font_list_1
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
538 Lisp_Object
, struct font_name
**));
539 static int font_list
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
540 Lisp_Object
, struct font_name
**));
541 static int try_font_list
P_ ((struct frame
*, Lisp_Object
,
542 Lisp_Object
, Lisp_Object
, struct font_name
**));
543 static int try_alternative_families
P_ ((struct frame
*f
, Lisp_Object
,
544 Lisp_Object
, struct font_name
**));
545 static int cmp_font_names
P_ ((const void *, const void *));
546 static struct face
*realize_face
P_ ((struct face_cache
*, Lisp_Object
*,
548 static struct face
*realize_non_ascii_face
P_ ((struct frame
*, int,
551 static struct face
*realize_x_face
P_ ((struct face_cache
*, Lisp_Object
*));
552 static struct face
*realize_tty_face
P_ ((struct face_cache
*, Lisp_Object
*));
553 static int realize_basic_faces
P_ ((struct frame
*));
554 static int realize_default_face
P_ ((struct frame
*));
555 static void realize_named_face
P_ ((struct frame
*, Lisp_Object
, int));
556 static int lface_fully_specified_p
P_ ((Lisp_Object
*));
557 static int lface_equal_p
P_ ((Lisp_Object
*, Lisp_Object
*));
558 static unsigned hash_string_case_insensitive
P_ ((Lisp_Object
));
559 static unsigned lface_hash
P_ ((Lisp_Object
*));
560 static int lface_same_font_attributes_p
P_ ((Lisp_Object
*, Lisp_Object
*));
561 static struct face_cache
*make_face_cache
P_ ((struct frame
*));
562 static void clear_face_gcs
P_ ((struct face_cache
*));
563 static void free_face_cache
P_ ((struct face_cache
*));
564 static int face_numeric_weight
P_ ((Lisp_Object
));
565 static int face_numeric_slant
P_ ((Lisp_Object
));
566 static int face_numeric_swidth
P_ ((Lisp_Object
));
567 static int face_fontset
P_ ((Lisp_Object
*));
568 static void merge_face_vectors
P_ ((struct frame
*, Lisp_Object
*, Lisp_Object
*, Lisp_Object
));
569 static void merge_face_inheritance
P_ ((struct frame
*f
, Lisp_Object
,
570 Lisp_Object
*, Lisp_Object
));
571 static void merge_face_vector_with_property
P_ ((struct frame
*, Lisp_Object
*,
573 static int set_lface_from_font_name
P_ ((struct frame
*, Lisp_Object
,
574 Lisp_Object
, int, int));
575 static Lisp_Object lface_from_face_name
P_ ((struct frame
*, Lisp_Object
, int));
576 static struct face
*make_realized_face
P_ ((Lisp_Object
*));
577 static char *best_matching_font
P_ ((struct frame
*, Lisp_Object
*,
578 struct font_name
*, int, int));
579 static void cache_face
P_ ((struct face_cache
*, struct face
*, unsigned));
580 static void uncache_face
P_ ((struct face_cache
*, struct face
*));
581 static int xlfd_numeric_slant
P_ ((struct font_name
*));
582 static int xlfd_numeric_weight
P_ ((struct font_name
*));
583 static int xlfd_numeric_swidth
P_ ((struct font_name
*));
584 static Lisp_Object xlfd_symbolic_slant
P_ ((struct font_name
*));
585 static Lisp_Object xlfd_symbolic_weight
P_ ((struct font_name
*));
586 static Lisp_Object xlfd_symbolic_swidth
P_ ((struct font_name
*));
587 static int xlfd_fixed_p
P_ ((struct font_name
*));
588 static int xlfd_numeric_value
P_ ((struct table_entry
*, int, struct font_name
*,
590 static Lisp_Object xlfd_symbolic_value
P_ ((struct table_entry
*, int,
591 struct font_name
*, int,
593 static struct table_entry
*xlfd_lookup_field_contents
P_ ((struct table_entry
*, int,
594 struct font_name
*, int));
596 #ifdef HAVE_WINDOW_SYSTEM
598 static int split_font_name
P_ ((struct frame
*, struct font_name
*, int));
599 static int xlfd_point_size
P_ ((struct frame
*, struct font_name
*));
600 static void sort_fonts
P_ ((struct frame
*, struct font_name
*, int,
601 int (*cmpfn
) P_ ((const void *, const void *))));
602 static GC x_create_gc
P_ ((struct frame
*, unsigned long, XGCValues
*));
603 static void x_free_gc
P_ ((struct frame
*, GC
));
604 static void clear_font_table
P_ ((struct x_display_info
*));
607 extern Lisp_Object w32_list_fonts
P_ ((struct frame
*, Lisp_Object
, int, int));
608 #endif /* WINDOWSNT */
611 static void x_update_menu_appearance
P_ ((struct frame
*));
613 extern void free_frame_menubar
P_ ((struct frame
*));
614 #endif /* USE_X_TOOLKIT */
616 #endif /* HAVE_WINDOW_SYSTEM */
619 /***********************************************************************
621 ***********************************************************************/
623 #ifdef HAVE_X_WINDOWS
625 #ifdef DEBUG_X_COLORS
627 /* The following is a poor mans infrastructure for debugging X color
628 allocation problems on displays with PseudoColor-8. Some X servers
629 like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement
630 color reference counts completely so that they don't signal an
631 error when a color is freed whose reference count is already 0.
632 Other X servers do. To help me debug this, the following code
633 implements a simple reference counting schema of its own, for a
634 single display/screen. --gerd. */
636 /* Reference counts for pixel colors. */
638 int color_count
[256];
640 /* Register color PIXEL as allocated. */
643 register_color (pixel
)
646 xassert (pixel
< 256);
647 ++color_count
[pixel
];
651 /* Register color PIXEL as deallocated. */
654 unregister_color (pixel
)
657 xassert (pixel
< 256);
658 if (color_count
[pixel
] > 0)
659 --color_count
[pixel
];
665 /* Register N colors from PIXELS as deallocated. */
668 unregister_colors (pixels
, n
)
669 unsigned long *pixels
;
673 for (i
= 0; i
< n
; ++i
)
674 unregister_color (pixels
[i
]);
678 DEFUN ("dump-colors", Fdump_colors
, Sdump_colors
, 0, 0, 0,
679 doc
: /* Dump currently allocated colors to stderr. */)
684 fputc ('\n', stderr
);
686 for (i
= n
= 0; i
< sizeof color_count
/ sizeof color_count
[0]; ++i
)
689 fprintf (stderr
, "%3d: %5d", i
, color_count
[i
]);
692 fputc ('\n', stderr
);
694 fputc ('\t', stderr
);
698 fputc ('\n', stderr
);
702 #endif /* DEBUG_X_COLORS */
705 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
706 color values. Interrupt input must be blocked when this function
710 x_free_colors (f
, pixels
, npixels
)
712 unsigned long *pixels
;
715 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
717 /* If display has an immutable color map, freeing colors is not
718 necessary and some servers don't allow it. So don't do it. */
719 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
721 #ifdef DEBUG_X_COLORS
722 unregister_colors (pixels
, npixels
);
724 XFreeColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
730 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
731 color values. Interrupt input must be blocked when this function
735 x_free_dpy_colors (dpy
, screen
, cmap
, pixels
, npixels
)
739 unsigned long *pixels
;
742 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
743 int class = dpyinfo
->visual
->class;
745 /* If display has an immutable color map, freeing colors is not
746 necessary and some servers don't allow it. So don't do it. */
747 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
749 #ifdef DEBUG_X_COLORS
750 unregister_colors (pixels
, npixels
);
752 XFreeColors (dpy
, cmap
, pixels
, npixels
, 0);
757 /* Create and return a GC for use on frame F. GC values and mask
758 are given by XGCV and MASK. */
761 x_create_gc (f
, mask
, xgcv
)
768 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
775 /* Free GC which was used on frame F. */
783 xassert (--ngcs
>= 0);
784 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
788 #endif /* HAVE_X_WINDOWS */
791 /* W32 emulation of GCs */
794 x_create_gc (f
, mask
, xgcv
)
801 gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, xgcv
);
808 /* Free GC which was used on frame F. */
816 xassert (--ngcs
>= 0);
821 #endif /* WINDOWSNT */
823 /* Like stricmp. Used to compare parts of font names which are in
828 unsigned char *s1
, *s2
;
832 unsigned char c1
= tolower (*s1
);
833 unsigned char c2
= tolower (*s2
);
835 return c1
< c2
? -1 : 1;
840 return *s2
== 0 ? 0 : -1;
845 /* Like strlwr, which might not always be available. */
847 static unsigned char *
851 unsigned char *p
= s
;
860 /* Signal `error' with message S, and additional argument ARG. */
863 signal_error (s
, arg
)
867 Fsignal (Qerror
, Fcons (build_string (s
), Fcons (arg
, Qnil
)));
871 /* If FRAME is nil, return a pointer to the selected frame.
872 Otherwise, check that FRAME is a live frame, and return a pointer
873 to it. NPARAM is the parameter number of FRAME, for
874 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
875 Lisp function definitions. */
877 static INLINE
struct frame
*
878 frame_or_selected_frame (frame
, nparam
)
883 frame
= selected_frame
;
885 CHECK_LIVE_FRAME (frame
);
886 return XFRAME (frame
);
890 /***********************************************************************
892 ***********************************************************************/
894 /* Initialize face cache and basic faces for frame F. */
900 /* Make a face cache, if F doesn't have one. */
901 if (FRAME_FACE_CACHE (f
) == NULL
)
902 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
904 #ifdef HAVE_WINDOW_SYSTEM
905 /* Make the image cache. */
906 if (FRAME_WINDOW_P (f
))
908 if (FRAME_X_IMAGE_CACHE (f
) == NULL
)
909 FRAME_X_IMAGE_CACHE (f
) = make_image_cache ();
910 ++FRAME_X_IMAGE_CACHE (f
)->refcount
;
912 #endif /* HAVE_WINDOW_SYSTEM */
914 /* Realize basic faces. Must have enough information in frame
915 parameters to realize basic faces at this point. */
916 #ifdef HAVE_X_WINDOWS
917 if (!FRAME_X_P (f
) || FRAME_X_WINDOW (f
))
920 if (!FRAME_WINDOW_P (f
) || FRAME_W32_WINDOW (f
))
922 if (!realize_basic_faces (f
))
927 /* Free face cache of frame F. Called from Fdelete_frame. */
933 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
937 free_face_cache (face_cache
);
938 FRAME_FACE_CACHE (f
) = NULL
;
941 #ifdef HAVE_WINDOW_SYSTEM
942 if (FRAME_WINDOW_P (f
))
944 struct image_cache
*image_cache
= FRAME_X_IMAGE_CACHE (f
);
947 --image_cache
->refcount
;
948 if (image_cache
->refcount
== 0)
949 free_image_cache (f
);
952 #endif /* HAVE_WINDOW_SYSTEM */
956 /* Clear face caches, and recompute basic faces for frame F. Call
957 this after changing frame parameters on which those faces depend,
958 or when realized faces have been freed due to changing attributes
962 recompute_basic_faces (f
)
965 if (FRAME_FACE_CACHE (f
))
967 clear_face_cache (0);
968 if (!realize_basic_faces (f
))
974 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
975 try to free unused fonts, too. */
978 clear_face_cache (clear_fonts_p
)
981 #ifdef HAVE_WINDOW_SYSTEM
982 Lisp_Object tail
, frame
;
986 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
988 struct x_display_info
*dpyinfo
;
990 /* Fonts are common for frames on one display, i.e. on
992 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
993 if (dpyinfo
->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
994 clear_font_table (dpyinfo
);
996 /* From time to time see if we can unload some fonts. This also
997 frees all realized faces on all frames. Fonts needed by
998 faces will be loaded again when faces are realized again. */
999 clear_font_table_count
= 0;
1001 FOR_EACH_FRAME (tail
, frame
)
1003 struct frame
*f
= XFRAME (frame
);
1004 if (FRAME_WINDOW_P (f
)
1005 && FRAME_X_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
1006 free_all_realized_faces (frame
);
1011 /* Clear GCs of realized faces. */
1012 FOR_EACH_FRAME (tail
, frame
)
1015 if (FRAME_WINDOW_P (f
))
1017 clear_face_gcs (FRAME_FACE_CACHE (f
));
1018 clear_image_cache (f
, 0);
1022 #endif /* HAVE_WINDOW_SYSTEM */
1026 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
1027 doc
: /* Clear face caches on all frames.
1028 Optional THOROUGHLY non-nil means try to free unused fonts, too. */)
1030 Lisp_Object thoroughly
;
1032 clear_face_cache (!NILP (thoroughly
));
1033 ++face_change_count
;
1034 ++windows_or_buffers_changed
;
1040 #ifdef HAVE_WINDOW_SYSTEM
1043 /* Remove fonts from the font table of DPYINFO except for the default
1044 ASCII fonts of frames on that display. Called from clear_face_cache
1045 from time to time. */
1048 clear_font_table (dpyinfo
)
1049 struct x_display_info
*dpyinfo
;
1053 /* Free those fonts that are not used by frames on DPYINFO. */
1054 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
1056 struct font_info
*font_info
= dpyinfo
->font_table
+ i
;
1057 Lisp_Object tail
, frame
;
1059 /* Check if slot is already free. */
1060 if (font_info
->name
== NULL
)
1063 /* Don't free a default font of some frame on this display. */
1064 FOR_EACH_FRAME (tail
, frame
)
1066 struct frame
*f
= XFRAME (frame
);
1067 if (FRAME_WINDOW_P (f
)
1068 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
1069 && font_info
->font
== FRAME_FONT (f
))
1077 if (font_info
->full_name
!= font_info
->name
)
1078 xfree (font_info
->full_name
);
1079 xfree (font_info
->name
);
1081 /* Free the font. */
1083 #ifdef HAVE_X_WINDOWS
1084 XFreeFont (dpyinfo
->display
, font_info
->font
);
1087 w32_unload_font (dpyinfo
, font_info
->font
);
1091 /* Mark font table slot free. */
1092 font_info
->font
= NULL
;
1093 font_info
->name
= font_info
->full_name
= NULL
;
1097 #endif /* HAVE_WINDOW_SYSTEM */
1101 /***********************************************************************
1103 ***********************************************************************/
1105 #ifdef HAVE_WINDOW_SYSTEM
1107 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
1108 doc
: /* Value is non-nil if OBJECT is a valid bitmap specification.
1109 A bitmap specification is either a string, a file name, or a list
1110 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
1111 HEIGHT is its height, and DATA is a string containing the bits of
1112 the pixmap. Bits are stored row by row, each row occupies
1113 \(WIDTH + 7)/8 bytes. */)
1119 if (STRINGP (object
))
1120 /* If OBJECT is a string, it's a file name. */
1122 else if (CONSP (object
))
1124 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
1125 HEIGHT must be integers > 0, and DATA must be string large
1126 enough to hold a bitmap of the specified size. */
1127 Lisp_Object width
, height
, data
;
1129 height
= width
= data
= Qnil
;
1133 width
= XCAR (object
);
1134 object
= XCDR (object
);
1137 height
= XCAR (object
);
1138 object
= XCDR (object
);
1140 data
= XCAR (object
);
1144 if (NATNUMP (width
) && NATNUMP (height
) && STRINGP (data
))
1146 int bytes_per_row
= ((XFASTINT (width
) + BITS_PER_CHAR
- 1)
1148 if (STRING_BYTES (XSTRING (data
)) >= bytes_per_row
* XINT (height
))
1153 return pixmap_p
? Qt
: Qnil
;
1157 /* Load a bitmap according to NAME (which is either a file name or a
1158 pixmap spec) for use on frame F. Value is the bitmap_id (see
1159 xfns.c). If NAME is nil, return with a bitmap id of zero. If
1160 bitmap cannot be loaded, display a message saying so, and return
1161 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
1162 if these pointers are not null. */
1165 load_pixmap (f
, name
, w_ptr
, h_ptr
)
1168 unsigned int *w_ptr
, *h_ptr
;
1176 tem
= Fbitmap_spec_p (name
);
1178 wrong_type_argument (Qbitmap_spec_p
, name
);
1183 /* Decode a bitmap spec into a bitmap. */
1188 w
= XINT (Fcar (name
));
1189 h
= XINT (Fcar (Fcdr (name
)));
1190 bits
= Fcar (Fcdr (Fcdr (name
)));
1192 bitmap_id
= x_create_bitmap_from_data (f
, XSTRING (bits
)->data
,
1197 /* It must be a string -- a file name. */
1198 bitmap_id
= x_create_bitmap_from_file (f
, name
);
1204 add_to_log ("Invalid or undefined bitmap %s", name
, Qnil
);
1215 ++npixmaps_allocated
;
1218 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
1221 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
1227 #endif /* HAVE_WINDOW_SYSTEM */
1231 /***********************************************************************
1233 ***********************************************************************/
1235 #ifdef HAVE_WINDOW_SYSTEM
1237 /* Update the line_height of frame F. Return non-zero if line height
1241 frame_update_line_height (f
)
1244 int line_height
, changed_p
;
1246 line_height
= FONT_HEIGHT (FRAME_FONT (f
));
1247 changed_p
= line_height
!= FRAME_LINE_HEIGHT (f
);
1248 FRAME_LINE_HEIGHT (f
) = line_height
;
1252 #endif /* HAVE_WINDOW_SYSTEM */
1255 /***********************************************************************
1257 ***********************************************************************/
1259 #ifdef HAVE_WINDOW_SYSTEM
1261 /* Load font of face FACE which is used on frame F to display ASCII
1262 characters. The name of the font to load is determined by lface. */
1265 load_face_font (f
, face
)
1269 struct font_info
*font_info
= NULL
;
1272 face
->font_info_id
= -1;
1274 face
->font_name
= NULL
;
1276 font_name
= choose_face_font (f
, face
->lface
, Qnil
);
1282 font_info
= FS_LOAD_FONT (f
, font_name
);
1287 face
->font_info_id
= font_info
->font_idx
;
1288 face
->font
= font_info
->font
;
1289 face
->font_name
= font_info
->full_name
;
1292 x_free_gc (f
, face
->gc
);
1297 add_to_log ("Unable to load font %s",
1298 build_string (font_name
), Qnil
);
1302 #endif /* HAVE_WINDOW_SYSTEM */
1306 /***********************************************************************
1308 ***********************************************************************/
1310 /* A version of defined_color for non-X frames. */
1313 tty_defined_color (f
, color_name
, color_def
, alloc
)
1319 Lisp_Object color_desc
;
1320 unsigned long color_idx
= FACE_TTY_DEFAULT_COLOR
;
1321 unsigned long red
= 0, green
= 0, blue
= 0;
1324 if (*color_name
&& !NILP (Ffboundp (Qtty_color_desc
)))
1328 XSETFRAME (frame
, f
);
1330 color_desc
= call2 (Qtty_color_desc
, build_string (color_name
), frame
);
1331 if (CONSP (color_desc
) && CONSP (XCDR (color_desc
)))
1333 color_idx
= XINT (XCAR (XCDR (color_desc
)));
1334 if (CONSP (XCDR (XCDR (color_desc
))))
1336 red
= XINT (XCAR (XCDR (XCDR (color_desc
))));
1337 green
= XINT (XCAR (XCDR (XCDR (XCDR (color_desc
)))));
1338 blue
= XINT (XCAR (XCDR (XCDR (XCDR (XCDR (color_desc
))))));
1342 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
1343 /* We were called early during startup, and the colors are not
1344 yet set up in tty-defined-color-alist. Don't return a failure
1345 indication, since this produces the annoying "Unable to
1346 load color" messages in the *Messages* buffer. */
1349 if (color_idx
== FACE_TTY_DEFAULT_COLOR
&& *color_name
)
1351 if (strcmp (color_name
, "unspecified-fg") == 0)
1352 color_idx
= FACE_TTY_DEFAULT_FG_COLOR
;
1353 else if (strcmp (color_name
, "unspecified-bg") == 0)
1354 color_idx
= FACE_TTY_DEFAULT_BG_COLOR
;
1357 if (color_idx
!= FACE_TTY_DEFAULT_COLOR
)
1360 color_def
->pixel
= color_idx
;
1361 color_def
->red
= red
;
1362 color_def
->green
= green
;
1363 color_def
->blue
= blue
;
1369 /* Decide if color named COLOR_NAME is valid for the display
1370 associated with the frame F; if so, return the rgb values in
1371 COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell.
1373 This does the right thing for any type of frame. */
1376 defined_color (f
, color_name
, color_def
, alloc
)
1382 if (!FRAME_WINDOW_P (f
))
1383 return tty_defined_color (f
, color_name
, color_def
, alloc
);
1384 #ifdef HAVE_X_WINDOWS
1385 else if (FRAME_X_P (f
))
1386 return x_defined_color (f
, color_name
, color_def
, alloc
);
1389 else if (FRAME_W32_P (f
))
1390 return w32_defined_color (f
, color_name
, color_def
, alloc
);
1393 else if (FRAME_MAC_P (f
))
1394 return mac_defined_color (f
, color_name
, color_def
, alloc
);
1401 /* Given the index IDX of a tty color on frame F, return its name, a
1405 tty_color_name (f
, idx
)
1409 if (idx
>= 0 && !NILP (Ffboundp (Qtty_color_by_index
)))
1412 Lisp_Object coldesc
;
1414 XSETFRAME (frame
, f
);
1415 coldesc
= call2 (Qtty_color_by_index
, make_number (idx
), frame
);
1417 if (!NILP (coldesc
))
1418 return XCAR (coldesc
);
1421 /* We can have an MSDOG frame under -nw for a short window of
1422 opportunity before internal_terminal_init is called. DTRT. */
1423 if (FRAME_MSDOS_P (f
) && !inhibit_window_system
)
1424 return msdos_stdcolor_name (idx
);
1427 if (idx
== FACE_TTY_DEFAULT_FG_COLOR
)
1428 return build_string (unspecified_fg
);
1429 if (idx
== FACE_TTY_DEFAULT_BG_COLOR
)
1430 return build_string (unspecified_bg
);
1433 return vga_stdcolor_name (idx
);
1436 return Qunspecified
;
1440 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1441 black) on frame F. The algorithm is taken from 20.2 faces.el. */
1444 face_color_gray_p (f
, color_name
)
1451 if (defined_color (f
, color_name
, &color
, 0))
1452 gray_p
= ((abs (color
.red
- color
.green
)
1453 < max (color
.red
, color
.green
) / 20)
1454 && (abs (color
.green
- color
.blue
)
1455 < max (color
.green
, color
.blue
) / 20)
1456 && (abs (color
.blue
- color
.red
)
1457 < max (color
.blue
, color
.red
) / 20));
1465 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1466 BACKGROUND_P non-zero means the color will be used as background
1470 face_color_supported_p (f
, color_name
, background_p
)
1478 XSETFRAME (frame
, f
);
1479 return (FRAME_WINDOW_P (f
)
1480 ? (!NILP (Fxw_display_color_p (frame
))
1481 || xstricmp (color_name
, "black") == 0
1482 || xstricmp (color_name
, "white") == 0
1484 && face_color_gray_p (f
, color_name
))
1485 || (!NILP (Fx_display_grayscale_p (frame
))
1486 && face_color_gray_p (f
, color_name
)))
1487 : tty_defined_color (f
, color_name
, ¬_used
, 0));
1491 DEFUN ("color-gray-p", Fcolor_gray_p
, Scolor_gray_p
, 1, 2, 0,
1492 doc
: /* Return non-nil if COLOR is a shade of gray (or white or black).
1493 FRAME specifies the frame and thus the display for interpreting COLOR.
1494 If FRAME is nil or omitted, use the selected frame. */)
1496 Lisp_Object color
, frame
;
1500 CHECK_FRAME (frame
);
1501 CHECK_STRING (color
);
1503 return face_color_gray_p (f
, XSTRING (color
)->data
) ? Qt
: Qnil
;
1507 DEFUN ("color-supported-p", Fcolor_supported_p
,
1508 Scolor_supported_p
, 2, 3, 0,
1509 doc
: /* Return non-nil if COLOR can be displayed on FRAME.
1510 BACKGROUND-P non-nil means COLOR is used as a background.
1511 If FRAME is nil or omitted, use the selected frame.
1512 COLOR must be a valid color name. */)
1513 (color
, frame
, background_p
)
1514 Lisp_Object frame
, color
, background_p
;
1518 CHECK_FRAME (frame
);
1519 CHECK_STRING (color
);
1521 if (face_color_supported_p (f
, XSTRING (color
)->data
, !NILP (background_p
)))
1527 /* Load color with name NAME for use by face FACE on frame F.
1528 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1529 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1530 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1531 pixel color. If color cannot be loaded, display a message, and
1532 return the foreground, background or underline color of F, but
1533 record that fact in flags of the face so that we don't try to free
1537 load_color (f
, face
, name
, target_index
)
1541 enum lface_attribute_index target_index
;
1545 xassert (STRINGP (name
));
1546 xassert (target_index
== LFACE_FOREGROUND_INDEX
1547 || target_index
== LFACE_BACKGROUND_INDEX
1548 || target_index
== LFACE_UNDERLINE_INDEX
1549 || target_index
== LFACE_OVERLINE_INDEX
1550 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1551 || target_index
== LFACE_BOX_INDEX
);
1553 /* if the color map is full, defined_color will return a best match
1554 to the values in an existing cell. */
1555 if (!defined_color (f
, XSTRING (name
)->data
, &color
, 1))
1557 add_to_log ("Unable to load color \"%s\"", name
, Qnil
);
1559 switch (target_index
)
1561 case LFACE_FOREGROUND_INDEX
:
1562 face
->foreground_defaulted_p
= 1;
1563 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1566 case LFACE_BACKGROUND_INDEX
:
1567 face
->background_defaulted_p
= 1;
1568 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1571 case LFACE_UNDERLINE_INDEX
:
1572 face
->underline_defaulted_p
= 1;
1573 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1576 case LFACE_OVERLINE_INDEX
:
1577 face
->overline_color_defaulted_p
= 1;
1578 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1581 case LFACE_STRIKE_THROUGH_INDEX
:
1582 face
->strike_through_color_defaulted_p
= 1;
1583 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1586 case LFACE_BOX_INDEX
:
1587 face
->box_color_defaulted_p
= 1;
1588 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1597 ++ncolors_allocated
;
1604 #ifdef HAVE_WINDOW_SYSTEM
1606 /* Load colors for face FACE which is used on frame F. Colors are
1607 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1608 of ATTRS. If the background color specified is not supported on F,
1609 try to emulate gray colors with a stipple from Vface_default_stipple. */
1612 load_face_colors (f
, face
, attrs
)
1619 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1620 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1622 /* Swap colors if face is inverse-video. */
1623 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1631 /* Check for support for foreground, not for background because
1632 face_color_supported_p is smart enough to know that grays are
1633 "supported" as background because we are supposed to use stipple
1635 if (!face_color_supported_p (f
, XSTRING (bg
)->data
, 0)
1636 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1638 x_destroy_bitmap (f
, face
->stipple
);
1639 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1640 &face
->pixmap_w
, &face
->pixmap_h
);
1643 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1644 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1648 /* Free color PIXEL on frame F. */
1651 unload_color (f
, pixel
)
1653 unsigned long pixel
;
1655 #ifdef HAVE_X_WINDOWS
1659 x_free_colors (f
, &pixel
, 1);
1666 /* Free colors allocated for FACE. */
1669 free_face_colors (f
, face
)
1673 #ifdef HAVE_X_WINDOWS
1674 if (face
->colors_copied_bitwise_p
)
1679 if (!face
->foreground_defaulted_p
)
1681 x_free_colors (f
, &face
->foreground
, 1);
1682 IF_DEBUG (--ncolors_allocated
);
1685 if (!face
->background_defaulted_p
)
1687 x_free_colors (f
, &face
->background
, 1);
1688 IF_DEBUG (--ncolors_allocated
);
1691 if (face
->underline_p
1692 && !face
->underline_defaulted_p
)
1694 x_free_colors (f
, &face
->underline_color
, 1);
1695 IF_DEBUG (--ncolors_allocated
);
1698 if (face
->overline_p
1699 && !face
->overline_color_defaulted_p
)
1701 x_free_colors (f
, &face
->overline_color
, 1);
1702 IF_DEBUG (--ncolors_allocated
);
1705 if (face
->strike_through_p
1706 && !face
->strike_through_color_defaulted_p
)
1708 x_free_colors (f
, &face
->strike_through_color
, 1);
1709 IF_DEBUG (--ncolors_allocated
);
1712 if (face
->box
!= FACE_NO_BOX
1713 && !face
->box_color_defaulted_p
)
1715 x_free_colors (f
, &face
->box_color
, 1);
1716 IF_DEBUG (--ncolors_allocated
);
1720 #endif /* HAVE_X_WINDOWS */
1723 #endif /* HAVE_WINDOW_SYSTEM */
1727 /***********************************************************************
1729 ***********************************************************************/
1731 /* An enumerator for each field of an XLFD font name. */
1752 /* An enumerator for each possible slant value of a font. Taken from
1753 the XLFD specification. */
1761 XLFD_SLANT_REVERSE_ITALIC
,
1762 XLFD_SLANT_REVERSE_OBLIQUE
,
1766 /* Relative font weight according to XLFD documentation. */
1770 XLFD_WEIGHT_UNKNOWN
,
1771 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1772 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1773 XLFD_WEIGHT_LIGHT
, /* 30 */
1774 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1775 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1776 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1777 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1778 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1779 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1782 /* Relative proportionate width. */
1786 XLFD_SWIDTH_UNKNOWN
,
1787 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1788 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1789 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1790 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1791 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1792 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1793 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1794 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1795 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1798 /* Structure used for tables mapping XLFD weight, slant, and width
1799 names to numeric and symbolic values. */
1805 Lisp_Object
*symbol
;
1808 /* Table of XLFD slant names and their numeric and symbolic
1809 representations. This table must be sorted by slant names in
1812 static struct table_entry slant_table
[] =
1814 {"i", XLFD_SLANT_ITALIC
, &Qitalic
},
1815 {"o", XLFD_SLANT_OBLIQUE
, &Qoblique
},
1816 {"ot", XLFD_SLANT_OTHER
, &Qitalic
},
1817 {"r", XLFD_SLANT_ROMAN
, &Qnormal
},
1818 {"ri", XLFD_SLANT_REVERSE_ITALIC
, &Qreverse_italic
},
1819 {"ro", XLFD_SLANT_REVERSE_OBLIQUE
, &Qreverse_oblique
}
1822 /* Table of XLFD weight names. This table must be sorted by weight
1823 names in ascending order. */
1825 static struct table_entry weight_table
[] =
1827 {"black", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
},
1828 {"bold", XLFD_WEIGHT_BOLD
, &Qbold
},
1829 {"book", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1830 {"demi", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1831 {"demibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1832 {"extralight", XLFD_WEIGHT_EXTRA_LIGHT
, &Qextra_light
},
1833 {"extrabold", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1834 {"heavy", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1835 {"light", XLFD_WEIGHT_LIGHT
, &Qlight
},
1836 {"medium", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1837 {"normal", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1838 {"regular", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1839 {"semibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1840 {"semilight", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1841 {"ultralight", XLFD_WEIGHT_ULTRA_LIGHT
, &Qultra_light
},
1842 {"ultrabold", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
}
1845 /* Table of XLFD width names. This table must be sorted by width
1846 names in ascending order. */
1848 static struct table_entry swidth_table
[] =
1850 {"compressed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1851 {"condensed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1852 {"demiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1853 {"expanded", XLFD_SWIDTH_EXPANDED
, &Qexpanded
},
1854 {"extracondensed", XLFD_SWIDTH_EXTRA_CONDENSED
, &Qextra_condensed
},
1855 {"extraexpanded", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
},
1856 {"medium", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1857 {"narrow", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1858 {"normal", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1859 {"regular", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1860 {"semicondensed", XLFD_SWIDTH_SEMI_CONDENSED
, &Qsemi_condensed
},
1861 {"semiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1862 {"ultracondensed", XLFD_SWIDTH_ULTRA_CONDENSED
, &Qultra_condensed
},
1863 {"ultraexpanded", XLFD_SWIDTH_ULTRA_EXPANDED
, &Qultra_expanded
},
1864 {"wide", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
}
1867 /* Structure used to hold the result of splitting font names in XLFD
1868 format into their fields. */
1872 /* The original name which is modified destructively by
1873 split_font_name. The pointer is kept here to be able to free it
1874 if it was allocated from the heap. */
1877 /* Font name fields. Each vector element points into `name' above.
1878 Fields are NUL-terminated. */
1879 char *fields
[XLFD_LAST
];
1881 /* Numeric values for those fields that interest us. See
1882 split_font_name for which these are. */
1883 int numeric
[XLFD_LAST
];
1885 /* If the original name matches one of Vface_resizing_fonts, the
1886 value is the corresponding resizing ratio. Otherwise, the value
1888 double resizing_ratio
;
1890 /* Lower value mean higher priority. */
1891 int registry_priority
;
1894 /* The frame in effect when sorting font names. Set temporarily in
1895 sort_fonts so that it is available in font comparison functions. */
1897 static struct frame
*font_frame
;
1899 /* Order by which font selection chooses fonts. The default values
1900 mean `first, find a best match for the font width, then for the
1901 font height, then for weight, then for slant.' This variable can be
1902 set via set-face-font-sort-order. */
1905 static int font_sort_order
[4] = {
1906 XLFD_SWIDTH
, XLFD_POINT_SIZE
, XLFD_WEIGHT
, XLFD_SLANT
1909 static int font_sort_order
[4];
1912 /* Look up FONT.fields[FIELD_INDEX] in TABLE which has DIM entries.
1913 TABLE must be sorted by TABLE[i]->name in ascending order. Value
1914 is a pointer to the matching table entry or null if no table entry
1917 static struct table_entry
*
1918 xlfd_lookup_field_contents (table
, dim
, font
, field_index
)
1919 struct table_entry
*table
;
1921 struct font_name
*font
;
1924 /* Function split_font_name converts fields to lower-case, so there
1925 is no need to use xstrlwr or xstricmp here. */
1926 char *s
= font
->fields
[field_index
];
1927 int low
, mid
, high
, cmp
;
1934 mid
= (low
+ high
) / 2;
1935 cmp
= strcmp (table
[mid
].name
, s
);
1949 /* Return a numeric representation for font name field
1950 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
1951 has DIM entries. Value is the numeric value found or DFLT if no
1952 table entry matches. This function is used to translate weight,
1953 slant, and swidth names of XLFD font names to numeric values. */
1956 xlfd_numeric_value (table
, dim
, font
, field_index
, dflt
)
1957 struct table_entry
*table
;
1959 struct font_name
*font
;
1963 struct table_entry
*p
;
1964 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
1965 return p
? p
->numeric
: dflt
;
1969 /* Return a symbolic representation for font name field
1970 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
1971 has DIM entries. Value is the symbolic value found or DFLT if no
1972 table entry matches. This function is used to translate weight,
1973 slant, and swidth names of XLFD font names to symbols. */
1975 static INLINE Lisp_Object
1976 xlfd_symbolic_value (table
, dim
, font
, field_index
, dflt
)
1977 struct table_entry
*table
;
1979 struct font_name
*font
;
1983 struct table_entry
*p
;
1984 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
1985 return p
? *p
->symbol
: dflt
;
1989 /* Return a numeric value for the slant of the font given by FONT. */
1992 xlfd_numeric_slant (font
)
1993 struct font_name
*font
;
1995 return xlfd_numeric_value (slant_table
, DIM (slant_table
),
1996 font
, XLFD_SLANT
, XLFD_SLANT_ROMAN
);
2000 /* Return a symbol representing the weight of the font given by FONT. */
2002 static INLINE Lisp_Object
2003 xlfd_symbolic_slant (font
)
2004 struct font_name
*font
;
2006 return xlfd_symbolic_value (slant_table
, DIM (slant_table
),
2007 font
, XLFD_SLANT
, Qnormal
);
2011 /* Return a numeric value for the weight of the font given by FONT. */
2014 xlfd_numeric_weight (font
)
2015 struct font_name
*font
;
2017 return xlfd_numeric_value (weight_table
, DIM (weight_table
),
2018 font
, XLFD_WEIGHT
, XLFD_WEIGHT_MEDIUM
);
2022 /* Return a symbol representing the slant of the font given by FONT. */
2024 static INLINE Lisp_Object
2025 xlfd_symbolic_weight (font
)
2026 struct font_name
*font
;
2028 return xlfd_symbolic_value (weight_table
, DIM (weight_table
),
2029 font
, XLFD_WEIGHT
, Qnormal
);
2033 /* Return a numeric value for the swidth of the font whose XLFD font
2034 name fields are found in FONT. */
2037 xlfd_numeric_swidth (font
)
2038 struct font_name
*font
;
2040 return xlfd_numeric_value (swidth_table
, DIM (swidth_table
),
2041 font
, XLFD_SWIDTH
, XLFD_SWIDTH_MEDIUM
);
2045 /* Return a symbolic value for the swidth of FONT. */
2047 static INLINE Lisp_Object
2048 xlfd_symbolic_swidth (font
)
2049 struct font_name
*font
;
2051 return xlfd_symbolic_value (swidth_table
, DIM (swidth_table
),
2052 font
, XLFD_SWIDTH
, Qnormal
);
2056 /* Look up the entry of SYMBOL in the vector TABLE which has DIM
2057 entries. Value is a pointer to the matching table entry or null if
2058 no element of TABLE contains SYMBOL. */
2060 static struct table_entry
*
2061 face_value (table
, dim
, symbol
)
2062 struct table_entry
*table
;
2068 xassert (SYMBOLP (symbol
));
2070 for (i
= 0; i
< dim
; ++i
)
2071 if (EQ (*table
[i
].symbol
, symbol
))
2074 return i
< dim
? table
+ i
: NULL
;
2078 /* Return a numeric value for SYMBOL in the vector TABLE which has DIM
2079 entries. Value is -1 if SYMBOL is not found in TABLE. */
2082 face_numeric_value (table
, dim
, symbol
)
2083 struct table_entry
*table
;
2087 struct table_entry
*p
= face_value (table
, dim
, symbol
);
2088 return p
? p
->numeric
: -1;
2092 /* Return a numeric value representing the weight specified by Lisp
2093 symbol WEIGHT. Value is one of the enumerators of enum
2097 face_numeric_weight (weight
)
2100 return face_numeric_value (weight_table
, DIM (weight_table
), weight
);
2104 /* Return a numeric value representing the slant specified by Lisp
2105 symbol SLANT. Value is one of the enumerators of enum xlfd_slant. */
2108 face_numeric_slant (slant
)
2111 return face_numeric_value (slant_table
, DIM (slant_table
), slant
);
2115 /* Return a numeric value representing the swidth specified by Lisp
2116 symbol WIDTH. Value is one of the enumerators of enum xlfd_swidth. */
2119 face_numeric_swidth (width
)
2122 return face_numeric_value (swidth_table
, DIM (swidth_table
), width
);
2127 split_font_name_into_vector (fontname
)
2128 Lisp_Object fontname
;
2130 struct font_name font
;
2134 font
.name
= LSTRDUPA (fontname
);
2135 if (! split_font_name (NULL
, &font
, 0))
2137 vec
= Fmake_vector (make_number (XLFD_LAST
), Qnil
);
2138 for (i
= 0; i
< XLFD_LAST
; i
++)
2139 if (font
.fields
[i
][0] != '*')
2140 ASET (vec
, i
, build_string (font
.fields
[i
]));
2145 build_font_name_from_vector (vec
)
2148 struct font_name font
;
2149 Lisp_Object fontname
;
2153 for (i
= 0; i
< XLFD_LAST
; i
++)
2155 font
.fields
[i
] = (NILP (AREF (vec
, i
))
2156 ? "*" : (char *) XSTRING (AREF (vec
, i
))->data
);
2157 if ((i
== XLFD_FAMILY
|| i
== XLFD_REGISTRY
)
2158 && (p
= strchr (font
.fields
[i
], '-')))
2160 char *p1
= STRDUPA (font
.fields
[i
]);
2162 p1
[p
- font
.fields
[i
]] = '\0';
2163 if (i
== XLFD_FAMILY
)
2165 font
.fields
[XLFD_FOUNDRY
] = p1
;
2166 font
.fields
[XLFD_FAMILY
] = p
+ 1;
2170 font
.fields
[XLFD_REGISTRY
] = p1
;
2171 font
.fields
[XLFD_ENCODING
] = p
+ 1;
2177 p
= build_font_name (&font
);
2178 fontname
= build_string (p
);
2183 #ifdef HAVE_WINDOW_SYSTEM
2185 /* Return non-zero if FONT is the name of a fixed-pitch font. */
2189 struct font_name
*font
;
2191 /* Function split_font_name converts fields to lower-case, so there
2192 is no need to use tolower here. */
2193 return *font
->fields
[XLFD_SPACING
] != 'p';
2197 /* Return the point size of FONT on frame F, measured in 1/10 pt.
2199 The actual height of the font when displayed on F depends on the
2200 resolution of both the font and frame. For example, a 10pt font
2201 designed for a 100dpi display will display larger than 10pt on a
2202 75dpi display. (It's not unusual to use fonts not designed for the
2203 display one is using. For example, some intlfonts are available in
2204 72dpi versions, only.)
2206 Value is the real point size of FONT on frame F, or 0 if it cannot
2210 xlfd_point_size (f
, font
)
2212 struct font_name
*font
;
2214 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
2215 char *pixel_field
= font
->fields
[XLFD_PIXEL_SIZE
];
2219 if (*pixel_field
== '[')
2221 /* The pixel size field is `[A B C D]' which specifies
2222 a transformation matrix.
2228 by which all glyphs of the font are transformed. The spec
2229 says that s scalar value N for the pixel size is equivalent
2230 to A = N * resx/resy, B = C = 0, D = N. */
2231 char *start
= pixel_field
+ 1, *end
;
2235 for (i
= 0; i
< 4; ++i
)
2237 matrix
[i
] = strtod (start
, &end
);
2244 pixel
= atoi (pixel_field
);
2249 real_pt
= PT_PER_INCH
* 10.0 * pixel
/ resy
+ 0.5;
2255 /* Return point size of PIXEL dots while considering Y-resultion (DPI)
2256 of frame F. This function is used to guess a point size of font
2257 when only the pixel height of the font is available. */
2260 pixel_point_size (f
, pixel
)
2264 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
2268 /* As one inch is PT_PER_INCH points, PT_PER_INCH/RESY gives the
2269 point size of one dot. */
2270 real_pt
= pixel
* PT_PER_INCH
/ resy
;
2271 int_pt
= real_pt
+ 0.5;
2277 /* Return a resizing ratio of a font of NAME. */
2279 static INLINE
double
2280 font_resizing_ratio (char *name
)
2282 Lisp_Object tail
, elt
;
2284 if (CONSP (Vface_resizing_fonts
))
2286 for (tail
= Vface_resizing_fonts
; CONSP (tail
); tail
= XCDR (tail
))
2289 if (STRINGP (XCAR (elt
)) && FLOATP (XCDR (elt
))
2290 && fast_c_string_match_ignore_case (XCAR (elt
), name
) >= 0)
2291 return XFLOAT_DATA (XCDR (elt
));
2298 /* Split XLFD font name FONT->name destructively into NUL-terminated,
2299 lower-case fields in FONT->fields. NUMERIC_P non-zero means
2300 compute numeric values for fields XLFD_POINT_SIZE, XLFD_SWIDTH,
2301 XLFD_RESY, XLFD_SLANT, and XLFD_WEIGHT in FONT->numeric. Value is
2302 zero if the font name doesn't have the format we expect. The
2303 expected format is a font name that starts with a `-' and has
2304 XLFD_LAST fields separated by `-'. */
2307 split_font_name (f
, font
, numeric_p
)
2309 struct font_name
*font
;
2314 double resizing_ratio
= 1.0;
2316 if (numeric_p
&& CONSP (Vface_resizing_fonts
))
2317 resizing_ratio
= font_resizing_ratio (font
->name
);
2319 if (*font
->name
== '-')
2321 char *p
= xstrlwr (font
->name
) + 1;
2323 while (i
< XLFD_LAST
)
2325 font
->fields
[i
] = p
;
2328 /* Pixel and point size may be of the form `[....]'. For
2329 BNF, see XLFD spec, chapter 4. Negative values are
2330 indicated by tilde characters which we replace with
2331 `-' characters, here. */
2333 && (i
- 1 == XLFD_PIXEL_SIZE
2334 || i
- 1 == XLFD_POINT_SIZE
))
2339 for (++p
; *p
&& *p
!= ']'; ++p
)
2343 /* Check that the matrix contains 4 floating point
2345 for (j
= 0, start
= font
->fields
[i
- 1] + 1;
2348 if (strtod (start
, &end
) == 0 && start
== end
)
2355 while (*p
&& *p
!= '-')
2365 success_p
= i
== XLFD_LAST
;
2367 /* If requested, and font name was in the expected format,
2368 compute numeric values for some fields. */
2369 if (numeric_p
&& success_p
)
2371 font
->numeric
[XLFD_POINT_SIZE
] = xlfd_point_size (f
, font
);
2372 font
->numeric
[XLFD_RESY
] = atoi (font
->fields
[XLFD_RESY
]);
2373 font
->numeric
[XLFD_SLANT
] = xlfd_numeric_slant (font
);
2374 font
->numeric
[XLFD_WEIGHT
] = xlfd_numeric_weight (font
);
2375 font
->numeric
[XLFD_SWIDTH
] = xlfd_numeric_swidth (font
);
2376 font
->numeric
[XLFD_AVGWIDTH
] = atoi (font
->fields
[XLFD_AVGWIDTH
]);
2377 font
->resizing_ratio
= resizing_ratio
;
2380 /* Initialize it to zero. It will be overridden by font_list while
2381 trying alternate registries. */
2382 font
->registry_priority
= 0;
2388 /* Build an XLFD font name from font name fields in FONT. Value is a
2389 pointer to the font name, which is allocated via xmalloc. */
2392 build_font_name (font
)
2393 struct font_name
*font
;
2397 char *font_name
= (char *) xmalloc (size
);
2398 int total_length
= 0;
2400 for (i
= 0; i
< XLFD_LAST
; ++i
)
2402 /* Add 1 because of the leading `-'. */
2403 int len
= strlen (font
->fields
[i
]) + 1;
2405 /* Reallocate font_name if necessary. Add 1 for the final
2407 if (total_length
+ len
+ 1 >= size
)
2409 int new_size
= max (2 * size
, size
+ len
+ 1);
2410 int sz
= new_size
* sizeof *font_name
;
2411 font_name
= (char *) xrealloc (font_name
, sz
);
2415 font_name
[total_length
] = '-';
2416 bcopy (font
->fields
[i
], font_name
+ total_length
+ 1, len
- 1);
2417 total_length
+= len
;
2420 font_name
[total_length
] = 0;
2425 /* Free an array FONTS of N font_name structures. This frees FONTS
2426 itself and all `name' fields in its elements. */
2429 free_font_names (fonts
, n
)
2430 struct font_name
*fonts
;
2434 xfree (fonts
[--n
].name
);
2439 /* Sort vector FONTS of font_name structures which contains NFONTS
2440 elements using qsort and comparison function CMPFN. F is the frame
2441 on which the fonts will be used. The global variable font_frame
2442 is temporarily set to F to make it available in CMPFN. */
2445 sort_fonts (f
, fonts
, nfonts
, cmpfn
)
2447 struct font_name
*fonts
;
2449 int (*cmpfn
) P_ ((const void *, const void *));
2452 qsort (fonts
, nfonts
, sizeof *fonts
, cmpfn
);
2457 /* Get fonts matching PATTERN on frame F. If F is null, use the first
2458 display in x_display_list. FONTS is a pointer to a vector of
2459 NFONTS font_name structures. TRY_ALTERNATIVES_P non-zero means try
2460 alternative patterns from Valternate_fontname_alist if no fonts are
2461 found matching PATTERN.
2463 For all fonts found, set FONTS[i].name to the name of the font,
2464 allocated via xmalloc, and split font names into fields. Ignore
2465 fonts that we can't parse. Value is the number of fonts found. */
2468 x_face_list_fonts (f
, pattern
, fonts
, nfonts
, try_alternatives_p
)
2471 struct font_name
*fonts
;
2472 int nfonts
, try_alternatives_p
;
2476 /* NTEMACS_TODO : currently this uses w32_list_fonts, but it may be
2477 better to do it the other way around. */
2479 Lisp_Object lpattern
, tem
;
2481 lpattern
= build_string (pattern
);
2483 /* Get the list of fonts matching PATTERN. */
2486 lfonts
= w32_list_fonts (f
, lpattern
, 0, nfonts
);
2489 lfonts
= x_list_fonts (f
, lpattern
, -1, nfonts
);
2492 /* Make a copy of the font names we got from X, and
2493 split them into fields. */
2495 for (tem
= lfonts
; CONSP (tem
) && n
< nfonts
; tem
= XCDR (tem
))
2497 Lisp_Object elt
, tail
;
2498 char *name
= XSTRING (XCAR (tem
))->data
;
2500 /* Ignore fonts matching a pattern from face-ignored-fonts. */
2501 for (tail
= Vface_ignored_fonts
; CONSP (tail
); tail
= XCDR (tail
))
2505 && fast_c_string_match_ignore_case (elt
, name
) >= 0)
2514 /* Make a copy of the font name. */
2515 fonts
[n
].name
= xstrdup (name
);
2517 if (split_font_name (f
, fonts
+ n
, 1))
2519 if (font_scalable_p (fonts
+ n
)
2520 && !may_use_scalable_font_p (name
))
2523 xfree (fonts
[n
].name
);
2529 xfree (fonts
[n
].name
);
2532 /* If no fonts found, try patterns from Valternate_fontname_alist. */
2533 if (n
== 0 && try_alternatives_p
)
2535 Lisp_Object list
= Valternate_fontname_alist
;
2537 while (CONSP (list
))
2539 Lisp_Object entry
= XCAR (list
);
2541 && STRINGP (XCAR (entry
))
2542 && strcmp (XSTRING (XCAR (entry
))->data
, pattern
) == 0)
2549 Lisp_Object patterns
= XCAR (list
);
2552 while (CONSP (patterns
)
2553 /* If list is screwed up, give up. */
2554 && (name
= XCAR (patterns
),
2556 /* Ignore patterns equal to PATTERN because we tried that
2557 already with no success. */
2558 && (strcmp (XSTRING (name
)->data
, pattern
) == 0
2559 || (n
= x_face_list_fonts (f
, XSTRING (name
)->data
,
2562 patterns
= XCDR (patterns
);
2570 /* Determine fonts matching PATTERN on frame F. Sort resulting fonts
2571 using comparison function CMPFN. Value is the number of fonts
2572 found. If value is non-zero, *FONTS is set to a vector of
2573 font_name structures allocated from the heap containing matching
2574 fonts. Each element of *FONTS contains a name member that is also
2575 allocated from the heap. Font names in these structures are split
2576 into fields. Use free_font_names to free such an array. */
2579 sorted_font_list (f
, pattern
, cmpfn
, fonts
)
2582 int (*cmpfn
) P_ ((const void *, const void *));
2583 struct font_name
**fonts
;
2587 /* Get the list of fonts matching pattern. 100 should suffice. */
2588 nfonts
= DEFAULT_FONT_LIST_LIMIT
;
2589 if (INTEGERP (Vfont_list_limit
) && XINT (Vfont_list_limit
) > 0)
2590 nfonts
= XFASTINT (Vfont_list_limit
);
2592 *fonts
= (struct font_name
*) xmalloc (nfonts
* sizeof **fonts
);
2593 nfonts
= x_face_list_fonts (f
, pattern
, *fonts
, nfonts
, 1);
2595 /* Sort the resulting array and return it in *FONTS. If no
2596 fonts were found, make sure to set *FONTS to null. */
2598 sort_fonts (f
, *fonts
, nfonts
, cmpfn
);
2609 /* Compare two font_name structures *A and *B. Value is analogous to
2610 strcmp. Sort order is given by the global variable
2611 font_sort_order. Font names are sorted so that, everything else
2612 being equal, fonts with a resolution closer to that of the frame on
2613 which they are used are listed first. The global variable
2614 font_frame is the frame on which we operate. */
2617 cmp_font_names (a
, b
)
2620 struct font_name
*x
= (struct font_name
*) a
;
2621 struct font_name
*y
= (struct font_name
*) b
;
2624 /* All strings have been converted to lower-case by split_font_name,
2625 so we can use strcmp here. */
2626 cmp
= strcmp (x
->fields
[XLFD_FAMILY
], y
->fields
[XLFD_FAMILY
]);
2631 for (i
= 0; i
< DIM (font_sort_order
) && cmp
== 0; ++i
)
2633 int j
= font_sort_order
[i
];
2634 cmp
= x
->numeric
[j
] - y
->numeric
[j
];
2639 /* Everything else being equal, we prefer fonts with an
2640 y-resolution closer to that of the frame. */
2641 int resy
= FRAME_X_DISPLAY_INFO (font_frame
)->resy
;
2642 int x_resy
= x
->numeric
[XLFD_RESY
];
2643 int y_resy
= y
->numeric
[XLFD_RESY
];
2644 cmp
= abs (resy
- x_resy
) - abs (resy
- y_resy
);
2652 /* Get a sorted list of fonts matching PATTERN. If PATTERN is nil,
2653 list fonts matching FAMILY and REGISTRY. FAMILY is a family name
2654 string or nil. REGISTRY is a registry name string. Set *FONTS to
2655 a vector of font_name structures allocated from the heap containing
2656 the fonts found. Value is the number of fonts found. */
2659 font_list_1 (f
, pattern
, family
, registry
, fonts
)
2661 Lisp_Object pattern
, family
, registry
;
2662 struct font_name
**fonts
;
2664 char *pattern_str
, *family_str
, *registry_str
;
2668 family_str
= (NILP (family
) ? "*" : (char *) XSTRING (family
)->data
);
2669 registry_str
= (NILP (registry
) ? "*" : (char *) XSTRING (registry
)->data
);
2671 pattern_str
= (char *) alloca (strlen (family_str
)
2672 + strlen (registry_str
)
2674 strcpy (pattern_str
, index (family_str
, '-') ? "-" : "-*-");
2675 strcat (pattern_str
, family_str
);
2676 strcat (pattern_str
, "-*-");
2677 strcat (pattern_str
, registry_str
);
2678 if (!index (registry_str
, '-'))
2680 if (registry_str
[strlen (registry_str
) - 1] == '*')
2681 strcat (pattern_str
, "-*");
2683 strcat (pattern_str
, "*-*");
2687 pattern_str
= (char *) XSTRING (pattern
)->data
;
2689 return sorted_font_list (f
, pattern_str
, cmp_font_names
, fonts
);
2693 /* Concatenate font list FONTS1 and FONTS2. FONTS1 and FONTS2
2694 contains NFONTS1 fonts and NFONTS2 fonts respectively. Return a
2695 pointer to a newly allocated font list. FONTS1 and FONTS2 are
2698 static struct font_name
*
2699 concat_font_list (fonts1
, nfonts1
, fonts2
, nfonts2
)
2700 struct font_name
*fonts1
, *fonts2
;
2701 int nfonts1
, nfonts2
;
2703 int new_nfonts
= nfonts1
+ nfonts2
;
2704 struct font_name
*new_fonts
;
2706 new_fonts
= (struct font_name
*) xmalloc (sizeof *new_fonts
* new_nfonts
);
2707 bcopy (fonts1
, new_fonts
, sizeof *new_fonts
* nfonts1
);
2708 bcopy (fonts2
, new_fonts
+ nfonts1
, sizeof *new_fonts
* nfonts2
);
2715 /* Get a sorted list of fonts of family FAMILY on frame F.
2717 If PATTERN is non-nil, list fonts matching that pattern.
2719 If REGISTRY is non-nil, it is a list of registry (and encoding)
2720 names. Return fonts with those registries and the alternative
2721 registries from Vface_alternative_font_registry_alist.
2723 If REGISTRY is nil return fonts of any registry.
2725 Set *FONTS to a vector of font_name structures allocated from the
2726 heap containing the fonts found. Value is the number of fonts
2730 font_list (f
, pattern
, family
, registry
, fonts
)
2732 Lisp_Object pattern
, family
, registry
;
2733 struct font_name
**fonts
;
2739 if (NILP (registry
))
2740 return font_list_1 (f
, pattern
, family
, registry
, fonts
);
2742 for (reg_prio
= 0, nfonts
= 0; CONSP (registry
); registry
= XCDR (registry
))
2744 Lisp_Object elt
, alter
;
2746 struct font_name
*fonts2
;
2748 elt
= XCAR (registry
);
2749 alter
= Fassoc (elt
, Vface_alternative_font_registry_alist
);
2751 alter
= Fcons (elt
, Qnil
);
2752 for (; CONSP (alter
); alter
= XCDR (alter
), reg_prio
++)
2754 nfonts2
= font_list_1 (f
, pattern
, family
, XCAR (alter
), &fonts2
);
2758 for (i
= 0; i
< nfonts2
; i
++)
2759 fonts2
[i
].registry_priority
= reg_prio
;
2761 *fonts
= concat_font_list (*fonts
, nfonts
, fonts2
, nfonts2
);
2773 /* Remove elements from LIST whose cars are `equal'. Called from
2774 x-family-fonts and x-font-family-list to remove duplicate font
2778 remove_duplicates (list
)
2781 Lisp_Object tail
= list
;
2783 while (!NILP (tail
) && !NILP (XCDR (tail
)))
2785 Lisp_Object next
= XCDR (tail
);
2786 if (!NILP (Fequal (XCAR (next
), XCAR (tail
))))
2787 XSETCDR (tail
, XCDR (next
));
2794 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
2795 doc
: /* Return a list of available fonts of family FAMILY on FRAME.
2796 If FAMILY is omitted or nil, list all families.
2797 Otherwise, FAMILY must be a string, possibly containing wildcards
2799 If FRAME is omitted or nil, use the selected frame.
2800 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
2801 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
2802 FAMILY is the font family name. POINT-SIZE is the size of the
2803 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
2804 width, weight and slant of the font. These symbols are the same as for
2805 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
2806 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
2807 giving the registry and encoding of the font.
2808 The result list is sorted according to the current setting of
2809 the face font sort order. */)
2811 Lisp_Object family
, frame
;
2813 struct frame
*f
= check_x_frame (frame
);
2814 struct font_name
*fonts
;
2817 struct gcpro gcpro1
;
2820 CHECK_STRING (family
);
2824 nfonts
= font_list (f
, Qnil
, family
, Qnil
, &fonts
);
2825 for (i
= nfonts
- 1; i
>= 0; --i
)
2827 Lisp_Object v
= Fmake_vector (make_number (8), Qnil
);
2830 ASET (v
, 0, build_string (fonts
[i
].fields
[XLFD_FAMILY
]));
2831 ASET (v
, 1, xlfd_symbolic_swidth (fonts
+ i
));
2832 ASET (v
, 2, make_number (xlfd_point_size (f
, fonts
+ i
)));
2833 ASET (v
, 3, xlfd_symbolic_weight (fonts
+ i
));
2834 ASET (v
, 4, xlfd_symbolic_slant (fonts
+ i
));
2835 ASET (v
, 5, xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
);
2836 tem
= build_font_name (fonts
+ i
);
2837 ASET (v
, 6, build_string (tem
));
2838 sprintf (tem
, "%s-%s", fonts
[i
].fields
[XLFD_REGISTRY
],
2839 fonts
[i
].fields
[XLFD_ENCODING
]);
2840 ASET (v
, 7, build_string (tem
));
2843 result
= Fcons (v
, result
);
2846 remove_duplicates (result
);
2847 free_font_names (fonts
, nfonts
);
2853 DEFUN ("x-font-family-list", Fx_font_family_list
, Sx_font_family_list
,
2855 doc
: /* Return a list of available font families on FRAME.
2856 If FRAME is omitted or nil, use the selected frame.
2857 Value is a list of conses (FAMILY . FIXED-P) where FAMILY
2858 is a font family, and FIXED-P is non-nil if fonts of that family
2859 are fixed-pitch. */)
2863 struct frame
*f
= check_x_frame (frame
);
2865 struct font_name
*fonts
;
2867 struct gcpro gcpro1
;
2868 int count
= specpdl_ptr
- specpdl
;
2871 /* Let's consider all fonts. Increase the limit for matching
2872 fonts until we have them all. */
2875 specbind (intern ("font-list-limit"), make_number (limit
));
2876 nfonts
= font_list (f
, Qnil
, Qnil
, Qnil
, &fonts
);
2878 if (nfonts
== limit
)
2880 free_font_names (fonts
, nfonts
);
2889 for (i
= nfonts
- 1; i
>= 0; --i
)
2890 result
= Fcons (Fcons (build_string (fonts
[i
].fields
[XLFD_FAMILY
]),
2891 xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
),
2894 remove_duplicates (result
);
2895 free_font_names (fonts
, nfonts
);
2897 return unbind_to (count
, result
);
2901 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
2902 doc
: /* Return a list of the names of available fonts matching PATTERN.
2903 If optional arguments FACE and FRAME are specified, return only fonts
2904 the same size as FACE on FRAME.
2905 PATTERN is a string, perhaps with wildcard characters;
2906 the * character matches any substring, and
2907 the ? character matches any single character.
2908 PATTERN is case-insensitive.
2909 FACE is a face name--a symbol.
2911 The return value is a list of strings, suitable as arguments to
2914 Fonts Emacs can't use may or may not be excluded
2915 even if they match PATTERN and FACE.
2916 The optional fourth argument MAXIMUM sets a limit on how many
2917 fonts to match. The first MAXIMUM fonts are reported.
2918 The optional fifth argument WIDTH, if specified, is a number of columns
2919 occupied by a character of a font. In that case, return only fonts
2920 the WIDTH times as wide as FACE on FRAME. */)
2921 (pattern
, face
, frame
, maximum
, width
)
2922 Lisp_Object pattern
, face
, frame
, maximum
, width
;
2929 CHECK_STRING (pattern
);
2935 CHECK_NATNUM (maximum
);
2936 maxnames
= XINT (maximum
);
2940 CHECK_NUMBER (width
);
2942 /* We can't simply call check_x_frame because this function may be
2943 called before any frame is created. */
2944 f
= frame_or_selected_frame (frame
, 2);
2945 if (!FRAME_WINDOW_P (f
))
2947 /* Perhaps we have not yet created any frame. */
2952 /* Determine the width standard for comparison with the fonts we find. */
2958 /* This is of limited utility since it works with character
2959 widths. Keep it for compatibility. --gerd. */
2960 int face_id
= lookup_named_face (f
, face
);
2961 struct face
*face
= (face_id
< 0
2963 : FACE_FROM_ID (f
, face_id
));
2965 if (face
&& face
->font
)
2966 size
= FONT_WIDTH (face
->font
);
2968 size
= FONT_WIDTH (FRAME_FONT (f
));
2971 size
*= XINT (width
);
2975 Lisp_Object args
[2];
2977 args
[0] = x_list_fonts (f
, pattern
, size
, maxnames
);
2979 /* We don't have to check fontsets. */
2981 args
[1] = list_fontsets (f
, pattern
, size
);
2982 return Fnconc (2, args
);
2986 #endif /* HAVE_WINDOW_SYSTEM */
2990 /***********************************************************************
2992 ***********************************************************************/
2994 /* Access face attributes of face LFACE, a Lisp vector. */
2996 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
2997 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
2998 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
2999 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
3000 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
3001 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
3002 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
3003 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
3004 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
3005 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
3006 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
3007 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
3008 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
3009 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
3010 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
3011 #define LFACE_AVGWIDTH(LFACE) AREF ((LFACE), LFACE_AVGWIDTH_INDEX)
3012 #define LFACE_FONTSET(LFACE) AREF ((LFACE), LFACE_FONTSET_INDEX)
3014 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
3015 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
3017 #define LFACEP(LFACE) \
3019 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \
3020 && EQ (AREF (LFACE, 0), Qface))
3025 /* Check consistency of Lisp face attribute vector ATTRS. */
3028 check_lface_attrs (attrs
)
3031 xassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
3032 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
3033 xassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
3034 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
3035 xassert (UNSPECIFIEDP (attrs
[LFACE_AVGWIDTH_INDEX
])
3036 || INTEGERP (attrs
[LFACE_AVGWIDTH_INDEX
]));
3037 xassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
3038 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
])
3039 || FLOATP (attrs
[LFACE_HEIGHT_INDEX
])
3040 || FUNCTIONP (attrs
[LFACE_HEIGHT_INDEX
]));
3041 xassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
3042 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
3043 xassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
3044 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
3045 xassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
3046 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
3047 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]));
3048 xassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
3049 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
3050 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
3051 xassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
3052 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
3053 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
3054 xassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
3055 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
3056 || STRINGP (attrs
[LFACE_BOX_INDEX
])
3057 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
3058 || CONSP (attrs
[LFACE_BOX_INDEX
]));
3059 xassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
3060 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
3061 xassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
3062 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
3063 xassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
3064 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
3065 xassert (UNSPECIFIEDP (attrs
[LFACE_INHERIT_INDEX
])
3066 || NILP (attrs
[LFACE_INHERIT_INDEX
])
3067 || SYMBOLP (attrs
[LFACE_INHERIT_INDEX
])
3068 || CONSP (attrs
[LFACE_INHERIT_INDEX
]));
3069 #ifdef HAVE_WINDOW_SYSTEM
3070 xassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
3071 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
3072 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
3073 xassert (UNSPECIFIEDP (attrs
[LFACE_FONT_INDEX
])
3074 || NILP (attrs
[LFACE_FONT_INDEX
])
3075 || STRINGP (attrs
[LFACE_FONT_INDEX
]));
3076 xassert (UNSPECIFIEDP (attrs
[LFACE_FONTSET_INDEX
])
3077 || STRINGP (attrs
[LFACE_FONTSET_INDEX
]));
3082 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
3090 xassert (LFACEP (lface
));
3091 check_lface_attrs (XVECTOR (lface
)->contents
);
3095 #else /* GLYPH_DEBUG == 0 */
3097 #define check_lface_attrs(attrs) (void) 0
3098 #define check_lface(lface) (void) 0
3100 #endif /* GLYPH_DEBUG == 0 */
3103 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
3104 to make it a symvol. If FACE_NAME is an alias for another face,
3105 return that face's name. */
3108 resolve_face_name (face_name
)
3109 Lisp_Object face_name
;
3111 Lisp_Object aliased
;
3113 if (STRINGP (face_name
))
3114 face_name
= intern (XSTRING (face_name
)->data
);
3116 while (SYMBOLP (face_name
))
3118 aliased
= Fget (face_name
, Qface_alias
);
3122 face_name
= aliased
;
3129 /* Return the face definition of FACE_NAME on frame F. F null means
3130 return the definition for new frames. FACE_NAME may be a string or
3131 a symbol (apparently Emacs 20.2 allowed strings as face names in
3132 face text properties; Ediff uses that). If FACE_NAME is an alias
3133 for another face, return that face's definition. If SIGNAL_P is
3134 non-zero, signal an error if FACE_NAME is not a valid face name.
3135 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
3138 static INLINE Lisp_Object
3139 lface_from_face_name (f
, face_name
, signal_p
)
3141 Lisp_Object face_name
;
3146 face_name
= resolve_face_name (face_name
);
3149 lface
= assq_no_quit (face_name
, f
->face_alist
);
3151 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
3154 lface
= XCDR (lface
);
3156 signal_error ("Invalid face", face_name
);
3158 check_lface (lface
);
3163 /* Get face attributes of face FACE_NAME from frame-local faces on
3164 frame F. Store the resulting attributes in ATTRS which must point
3165 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
3166 is non-zero, signal an error if FACE_NAME does not name a face.
3167 Otherwise, value is zero if FACE_NAME is not a face. */
3170 get_lface_attributes (f
, face_name
, attrs
, signal_p
)
3172 Lisp_Object face_name
;
3179 lface
= lface_from_face_name (f
, face_name
, signal_p
);
3182 bcopy (XVECTOR (lface
)->contents
, attrs
,
3183 LFACE_VECTOR_SIZE
* sizeof *attrs
);
3193 /* Non-zero if all attributes in face attribute vector ATTRS are
3194 specified, i.e. are non-nil. */
3197 lface_fully_specified_p (attrs
)
3202 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3203 if (i
!= LFACE_FONT_INDEX
&& i
!= LFACE_INHERIT_INDEX
3204 && i
!= LFACE_AVGWIDTH_INDEX
)
3205 if (UNSPECIFIEDP (attrs
[i
]))
3208 return i
== LFACE_VECTOR_SIZE
;
3211 #ifdef HAVE_WINDOW_SYSTEM
3213 /* Set font-related attributes of Lisp face LFACE from the fullname of
3214 the font opened by FONTNAME. If FORCE_P is zero, set only
3215 unspecified attributes of LFACE. The exception is `font'
3216 attribute. It is set to FONTNAME as is regardless of FORCE_P.
3218 If FONTNAME is not available on frame F,
3219 return 0 if MAY_FAIL_P is non-zero, otherwise abort.
3220 If the fullname is not in a valid XLFD format,
3221 return 0 if MAY_FAIL_P is non-zero, otherwise set normal values
3222 in LFACE and return 1.
3223 Otherwise, return 1.
3225 Currently this function is always called with both FORCE_P and
3226 MAIL_FAIL_P non-zero. */
3229 set_lface_from_font_name (f
, lface
, fontname
, force_p
, may_fail_p
)
3232 Lisp_Object fontname
;
3233 int force_p
, may_fail_p
;
3235 struct font_name font
;
3240 char *font_name
= XSTRING (fontname
)->data
;
3241 struct font_info
*font_info
;
3243 /* If FONTNAME is actually a fontset name, get ASCII font name of it. */
3244 fontset
= fs_query_fontset (fontname
, 0);
3246 font_name
= XSTRING (fontset_ascii (fontset
))->data
;
3247 else if (fontset
== 0)
3254 /* Check if FONT_NAME is surely available on the system. Usually
3255 FONT_NAME is already cached for the frame F and FS_LOAD_FONT
3256 returns quickly. But, even if FONT_NAME is not yet cached,
3257 caching it now is not futail because we anyway load the font
3260 font_info
= FS_LOAD_FONT (f
, font_name
);
3270 font
.name
= STRDUPA (font_info
->full_name
);
3271 have_xlfd_p
= split_font_name (f
, &font
, 1);
3273 /* Set attributes only if unspecified, otherwise face defaults for
3274 new frames would never take effect. If we couldn't get a font
3275 name conforming to XLFD, set normal values. */
3277 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
3282 buffer
= (char *) alloca (strlen (font
.fields
[XLFD_FAMILY
])
3283 + strlen (font
.fields
[XLFD_FOUNDRY
])
3285 sprintf (buffer
, "%s-%s", font
.fields
[XLFD_FOUNDRY
],
3286 font
.fields
[XLFD_FAMILY
]);
3287 val
= build_string (buffer
);
3290 val
= build_string ("*");
3291 LFACE_FAMILY (lface
) = val
;
3294 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
3297 pt
= xlfd_point_size (f
, &font
);
3299 pt
= pixel_point_size (f
, font_info
->height
* 10);
3301 LFACE_HEIGHT (lface
) = make_number (pt
);
3304 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
3305 LFACE_SWIDTH (lface
)
3306 = have_xlfd_p
? xlfd_symbolic_swidth (&font
) : Qnormal
;
3308 if (force_p
|| UNSPECIFIEDP (LFACE_AVGWIDTH (lface
)))
3309 LFACE_AVGWIDTH (lface
)
3311 ? make_number (font
.numeric
[XLFD_AVGWIDTH
])
3314 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
3315 LFACE_WEIGHT (lface
)
3316 = have_xlfd_p
? xlfd_symbolic_weight (&font
) : Qnormal
;
3318 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
3320 = have_xlfd_p
? xlfd_symbolic_slant (&font
) : Qnormal
;
3324 LFACE_FONT (lface
) = build_string (font_info
->full_name
);
3325 LFACE_FONTSET (lface
) = fontset_name (fontset
);
3328 LFACE_FONT (lface
) = fontname
;
3332 #endif /* HAVE_WINDOW_SYSTEM */
3335 /* Merges the face height FROM with the face height TO, and returns the
3336 merged height. If FROM is an invalid height, then INVALID is
3337 returned instead. FROM and TO may be either absolute face heights or
3338 `relative' heights; the returned value is always an absolute height
3339 unless both FROM and TO are relative. GCPRO is a lisp value that
3340 will be protected from garbage-collection if this function makes a
3344 merge_face_heights (from
, to
, invalid
, gcpro
)
3345 Lisp_Object from
, to
, invalid
, gcpro
;
3347 Lisp_Object result
= invalid
;
3349 if (INTEGERP (from
))
3350 /* FROM is absolute, just use it as is. */
3352 else if (FLOATP (from
))
3353 /* FROM is a scale, use it to adjust TO. */
3356 /* relative X absolute => absolute */
3357 result
= make_number ((EMACS_INT
)(XFLOAT_DATA (from
) * XINT (to
)));
3358 else if (FLOATP (to
))
3359 /* relative X relative => relative */
3360 result
= make_float (XFLOAT_DATA (from
) * XFLOAT_DATA (to
));
3362 else if (FUNCTIONP (from
))
3363 /* FROM is a function, which use to adjust TO. */
3365 /* Call function with current height as argument.
3366 From is the new height. */
3367 Lisp_Object args
[2];
3368 struct gcpro gcpro1
;
3374 result
= safe_call (2, args
);
3378 /* Ensure that if TO was absolute, so is the result. */
3379 if (INTEGERP (to
) && !INTEGERP (result
))
3387 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
3388 store the resulting attributes in TO, which must be already be
3389 completely specified and contain only absolute attributes. Every
3390 specified attribute of FROM overrides the corresponding attribute of
3391 TO; relative attributes in FROM are merged with the absolute value in
3392 TO and replace it. CYCLE_CHECK is used internally to detect loops in
3393 face inheritance; it should be Qnil when called from other places. */
3396 merge_face_vectors (f
, from
, to
, cycle_check
)
3398 Lisp_Object
*from
, *to
;
3399 Lisp_Object cycle_check
;
3403 /* If FROM inherits from some other faces, merge their attributes into
3404 TO before merging FROM's direct attributes. Note that an :inherit
3405 attribute of `unspecified' is the same as one of nil; we never
3406 merge :inherit attributes, so nil is more correct, but lots of
3407 other code uses `unspecified' as a generic value for face attributes. */
3408 if (!UNSPECIFIEDP (from
[LFACE_INHERIT_INDEX
])
3409 && !NILP (from
[LFACE_INHERIT_INDEX
]))
3410 merge_face_inheritance (f
, from
[LFACE_INHERIT_INDEX
], to
, cycle_check
);
3412 /* If TO specifies a :font attribute, and FROM specifies some
3413 font-related attribute, we need to clear TO's :font attribute
3414 (because it will be inconsistent with whatever FROM specifies, and
3415 FROM takes precedence). */
3416 if (!NILP (to
[LFACE_FONT_INDEX
])
3417 && (!UNSPECIFIEDP (from
[LFACE_FAMILY_INDEX
])
3418 || !UNSPECIFIEDP (from
[LFACE_HEIGHT_INDEX
])
3419 || !UNSPECIFIEDP (from
[LFACE_WEIGHT_INDEX
])
3420 || !UNSPECIFIEDP (from
[LFACE_SLANT_INDEX
])
3421 || !UNSPECIFIEDP (from
[LFACE_SWIDTH_INDEX
])
3422 || !UNSPECIFIEDP (from
[LFACE_AVGWIDTH_INDEX
])))
3423 to
[LFACE_FONT_INDEX
] = Qnil
;
3425 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3426 if (!UNSPECIFIEDP (from
[i
]))
3428 if (i
== LFACE_HEIGHT_INDEX
&& !INTEGERP (from
[i
]))
3429 to
[i
] = merge_face_heights (from
[i
], to
[i
], to
[i
], cycle_check
);
3434 /* TO is always an absolute face, which should inherit from nothing.
3435 We blindly copy the :inherit attribute above and fix it up here. */
3436 to
[LFACE_INHERIT_INDEX
] = Qnil
;
3440 /* Checks the `cycle check' variable CHECK to see if it indicates that
3441 EL is part of a cycle; CHECK must be either Qnil or a value returned
3442 by an earlier use of CYCLE_CHECK. SUSPICIOUS is the number of
3443 elements after which a cycle might be suspected; after that many
3444 elements, this macro begins consing in order to keep more precise
3447 Returns nil if a cycle was detected, otherwise a new value for CHECK
3450 CHECK is evaluated multiple times, EL and SUSPICIOUS 0 or 1 times, so
3451 the caller should make sure that's ok. */
3453 #define CYCLE_CHECK(check, el, suspicious) \
3456 : (INTEGERP (check) \
3457 ? (XFASTINT (check) < (suspicious) \
3458 ? make_number (XFASTINT (check) + 1) \
3459 : Fcons (el, Qnil)) \
3460 : (!NILP (Fmemq ((el), (check))) \
3462 : Fcons ((el), (check)))))
3465 /* Merge face attributes from the face on frame F whose name is
3466 INHERITS, into the vector of face attributes TO; INHERITS may also be
3467 a list of face names, in which case they are applied in order.
3468 CYCLE_CHECK is used to detect loops in face inheritance.
3469 Returns true if any of the inherited attributes are `font-related'. */
3472 merge_face_inheritance (f
, inherit
, to
, cycle_check
)
3474 Lisp_Object inherit
;
3476 Lisp_Object cycle_check
;
3478 if (SYMBOLP (inherit
) && !EQ (inherit
, Qunspecified
))
3479 /* Inherit from the named face INHERIT. */
3483 /* Make sure we're not in an inheritance loop. */
3484 cycle_check
= CYCLE_CHECK (cycle_check
, inherit
, 15);
3485 if (NILP (cycle_check
))
3486 /* Cycle detected, ignore any further inheritance. */
3489 lface
= lface_from_face_name (f
, inherit
, 0);
3491 merge_face_vectors (f
, XVECTOR (lface
)->contents
, to
, cycle_check
);
3493 else if (CONSP (inherit
))
3494 /* Handle a list of inherited faces by calling ourselves recursively
3495 on each element. Note that we only do so for symbol elements, so
3496 it's not possible to infinitely recurse. */
3498 while (CONSP (inherit
))
3500 if (SYMBOLP (XCAR (inherit
)))
3501 merge_face_inheritance (f
, XCAR (inherit
), to
, cycle_check
);
3503 /* Check for a circular inheritance list. */
3504 cycle_check
= CYCLE_CHECK (cycle_check
, inherit
, 15);
3505 if (NILP (cycle_check
))
3506 /* Cycle detected. */
3509 inherit
= XCDR (inherit
);
3515 /* Given a Lisp face attribute vector TO and a Lisp object PROP that
3516 is a face property, determine the resulting face attributes on
3517 frame F, and store them in TO. PROP may be a single face
3518 specification or a list of such specifications. Each face
3519 specification can be
3521 1. A symbol or string naming a Lisp face.
3523 2. A property list of the form (KEYWORD VALUE ...) where each
3524 KEYWORD is a face attribute name, and value is an appropriate value
3527 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
3528 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
3529 for compatibility with 20.2.
3531 Face specifications earlier in lists take precedence over later
3535 merge_face_vector_with_property (f
, to
, prop
)
3542 Lisp_Object first
= XCAR (prop
);
3544 if (EQ (first
, Qforeground_color
)
3545 || EQ (first
, Qbackground_color
))
3547 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
3548 . COLOR). COLOR must be a string. */
3549 Lisp_Object color_name
= XCDR (prop
);
3550 Lisp_Object color
= first
;
3552 if (STRINGP (color_name
))
3554 if (EQ (color
, Qforeground_color
))
3555 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
3557 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
3560 add_to_log ("Invalid face color", color_name
, Qnil
);
3562 else if (SYMBOLP (first
)
3563 && *XSYMBOL (first
)->name
->data
== ':')
3565 /* Assume this is the property list form. */
3566 while (CONSP (prop
) && CONSP (XCDR (prop
)))
3568 Lisp_Object keyword
= XCAR (prop
);
3569 Lisp_Object value
= XCAR (XCDR (prop
));
3571 if (EQ (keyword
, QCfamily
))
3573 if (STRINGP (value
))
3574 to
[LFACE_FAMILY_INDEX
] = value
;
3576 add_to_log ("Invalid face font family", value
, Qnil
);
3578 else if (EQ (keyword
, QCheight
))
3580 Lisp_Object new_height
=
3581 merge_face_heights (value
, to
[LFACE_HEIGHT_INDEX
],
3584 if (NILP (new_height
))
3585 add_to_log ("Invalid face font height", value
, Qnil
);
3587 to
[LFACE_HEIGHT_INDEX
] = new_height
;
3589 else if (EQ (keyword
, QCweight
))
3592 && face_numeric_weight (value
) >= 0)
3593 to
[LFACE_WEIGHT_INDEX
] = value
;
3595 add_to_log ("Invalid face weight", value
, Qnil
);
3597 else if (EQ (keyword
, QCslant
))
3600 && face_numeric_slant (value
) >= 0)
3601 to
[LFACE_SLANT_INDEX
] = value
;
3603 add_to_log ("Invalid face slant", value
, Qnil
);
3605 else if (EQ (keyword
, QCunderline
))
3610 to
[LFACE_UNDERLINE_INDEX
] = value
;
3612 add_to_log ("Invalid face underline", value
, Qnil
);
3614 else if (EQ (keyword
, QCoverline
))
3619 to
[LFACE_OVERLINE_INDEX
] = value
;
3621 add_to_log ("Invalid face overline", value
, Qnil
);
3623 else if (EQ (keyword
, QCstrike_through
))
3628 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
3630 add_to_log ("Invalid face strike-through", value
, Qnil
);
3632 else if (EQ (keyword
, QCbox
))
3635 value
= make_number (1);
3636 if (INTEGERP (value
)
3640 to
[LFACE_BOX_INDEX
] = value
;
3642 add_to_log ("Invalid face box", value
, Qnil
);
3644 else if (EQ (keyword
, QCinverse_video
)
3645 || EQ (keyword
, QCreverse_video
))
3647 if (EQ (value
, Qt
) || NILP (value
))
3648 to
[LFACE_INVERSE_INDEX
] = value
;
3650 add_to_log ("Invalid face inverse-video", value
, Qnil
);
3652 else if (EQ (keyword
, QCforeground
))
3654 if (STRINGP (value
))
3655 to
[LFACE_FOREGROUND_INDEX
] = value
;
3657 add_to_log ("Invalid face foreground", value
, Qnil
);
3659 else if (EQ (keyword
, QCbackground
))
3661 if (STRINGP (value
))
3662 to
[LFACE_BACKGROUND_INDEX
] = value
;
3664 add_to_log ("Invalid face background", value
, Qnil
);
3666 else if (EQ (keyword
, QCstipple
))
3668 #ifdef HAVE_X_WINDOWS
3669 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
3670 if (!NILP (pixmap_p
))
3671 to
[LFACE_STIPPLE_INDEX
] = value
;
3673 add_to_log ("Invalid face stipple", value
, Qnil
);
3676 else if (EQ (keyword
, QCwidth
))
3679 && face_numeric_swidth (value
) >= 0)
3680 to
[LFACE_SWIDTH_INDEX
] = value
;
3682 add_to_log ("Invalid face width", value
, Qnil
);
3684 else if (EQ (keyword
, QCinherit
))
3686 if (SYMBOLP (value
))
3687 to
[LFACE_INHERIT_INDEX
] = value
;
3691 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
3692 if (!SYMBOLP (XCAR (tail
)))
3695 to
[LFACE_INHERIT_INDEX
] = value
;
3697 add_to_log ("Invalid face inherit", value
, Qnil
);
3701 add_to_log ("Invalid attribute %s in face property",
3704 prop
= XCDR (XCDR (prop
));
3709 /* This is a list of face specs. Specifications at the
3710 beginning of the list take precedence over later
3711 specifications, so we have to merge starting with the
3712 last specification. */
3713 Lisp_Object next
= XCDR (prop
);
3715 merge_face_vector_with_property (f
, to
, next
);
3716 merge_face_vector_with_property (f
, to
, first
);
3721 /* PROP ought to be a face name. */
3722 Lisp_Object lface
= lface_from_face_name (f
, prop
, 0);
3724 add_to_log ("Invalid face text property value: %s", prop
, Qnil
);
3726 merge_face_vectors (f
, XVECTOR (lface
)->contents
, to
, Qnil
);
3731 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
3732 Sinternal_make_lisp_face
, 1, 2, 0,
3733 doc
: /* Make FACE, a symbol, a Lisp face with all attributes nil.
3734 If FACE was not known as a face before, create a new one.
3735 If optional argument FRAME is specified, make a frame-local face
3736 for that frame. Otherwise operate on the global face definition.
3737 Value is a vector of face attributes. */)
3739 Lisp_Object face
, frame
;
3741 Lisp_Object global_lface
, lface
;
3745 CHECK_SYMBOL (face
);
3746 global_lface
= lface_from_face_name (NULL
, face
, 0);
3750 CHECK_LIVE_FRAME (frame
);
3752 lface
= lface_from_face_name (f
, face
, 0);
3755 f
= NULL
, lface
= Qnil
;
3757 /* Add a global definition if there is none. */
3758 if (NILP (global_lface
))
3760 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
3762 AREF (global_lface
, 0) = Qface
;
3763 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
3764 Vface_new_frame_defaults
);
3766 /* Assign the new Lisp face a unique ID. The mapping from Lisp
3767 face id to Lisp face is given by the vector lface_id_to_name.
3768 The mapping from Lisp face to Lisp face id is given by the
3769 property `face' of the Lisp face name. */
3770 if (next_lface_id
== lface_id_to_name_size
)
3772 int new_size
= max (50, 2 * lface_id_to_name_size
);
3773 int sz
= new_size
* sizeof *lface_id_to_name
;
3774 lface_id_to_name
= (Lisp_Object
*) xrealloc (lface_id_to_name
, sz
);
3775 lface_id_to_name_size
= new_size
;
3778 lface_id_to_name
[next_lface_id
] = face
;
3779 Fput (face
, Qface
, make_number (next_lface_id
));
3783 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3784 AREF (global_lface
, i
) = Qunspecified
;
3786 /* Add a frame-local definition. */
3791 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
3793 AREF (lface
, 0) = Qface
;
3794 f
->face_alist
= Fcons (Fcons (face
, lface
), f
->face_alist
);
3797 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3798 AREF (lface
, i
) = Qunspecified
;
3801 lface
= global_lface
;
3803 /* Changing a named face means that all realized faces depending on
3804 that face are invalid. Since we cannot tell which realized faces
3805 depend on the face, make sure they are all removed. This is done
3806 by incrementing face_change_count. The next call to
3807 init_iterator will then free realized faces. */
3808 ++face_change_count
;
3809 ++windows_or_buffers_changed
;
3811 xassert (LFACEP (lface
));
3812 check_lface (lface
);
3817 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
3818 Sinternal_lisp_face_p
, 1, 2, 0,
3819 doc
: /* Return non-nil if FACE names a face.
3820 If optional second parameter FRAME is non-nil, check for the
3821 existence of a frame-local face with name FACE on that frame.
3822 Otherwise check for the existence of a global face. */)
3824 Lisp_Object face
, frame
;
3830 CHECK_LIVE_FRAME (frame
);
3831 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3834 lface
= lface_from_face_name (NULL
, face
, 0);
3840 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
3841 Sinternal_copy_lisp_face
, 4, 4, 0,
3842 doc
: /* Copy face FROM to TO.
3843 If FRAME it t, copy the global face definition of FROM to the
3844 global face definition of TO. Otherwise, copy the frame-local
3845 definition of FROM on FRAME to the frame-local definition of TO
3846 on NEW-FRAME, or FRAME if NEW-FRAME is nil.
3849 (from
, to
, frame
, new_frame
)
3850 Lisp_Object from
, to
, frame
, new_frame
;
3852 Lisp_Object lface
, copy
;
3854 CHECK_SYMBOL (from
);
3856 if (NILP (new_frame
))
3861 /* Copy global definition of FROM. We don't make copies of
3862 strings etc. because 20.2 didn't do it either. */
3863 lface
= lface_from_face_name (NULL
, from
, 1);
3864 copy
= Finternal_make_lisp_face (to
, Qnil
);
3868 /* Copy frame-local definition of FROM. */
3869 CHECK_LIVE_FRAME (frame
);
3870 CHECK_LIVE_FRAME (new_frame
);
3871 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
3872 copy
= Finternal_make_lisp_face (to
, new_frame
);
3875 bcopy (XVECTOR (lface
)->contents
, XVECTOR (copy
)->contents
,
3876 LFACE_VECTOR_SIZE
* sizeof (Lisp_Object
));
3878 /* Changing a named face means that all realized faces depending on
3879 that face are invalid. Since we cannot tell which realized faces
3880 depend on the face, make sure they are all removed. This is done
3881 by incrementing face_change_count. The next call to
3882 init_iterator will then free realized faces. */
3883 ++face_change_count
;
3884 ++windows_or_buffers_changed
;
3890 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
3891 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
3892 doc
: /* Set attribute ATTR of FACE to VALUE.
3893 FRAME being a frame means change the face on that frame.
3894 FRAME nil means change the face of the selected frame.
3895 FRAME t means change the default for new frames.
3896 FRAME 0 means change the face on all frames, and change the default
3898 (face
, attr
, value
, frame
)
3899 Lisp_Object face
, attr
, value
, frame
;
3902 Lisp_Object old_value
= Qnil
;
3903 /* Set 1 if ATTR is QCfont. */
3904 int font_attr_p
= 0;
3905 /* Set 1 if ATTR is one of font-related attributes other than QCfont. */
3906 int font_related_attr_p
= 0;
3908 CHECK_SYMBOL (face
);
3909 CHECK_SYMBOL (attr
);
3911 face
= resolve_face_name (face
);
3913 /* If FRAME is 0, change face on all frames, and change the
3914 default for new frames. */
3915 if (INTEGERP (frame
) && XINT (frame
) == 0)
3918 Finternal_set_lisp_face_attribute (face
, attr
, value
, Qt
);
3919 FOR_EACH_FRAME (tail
, frame
)
3920 Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3924 /* Set lface to the Lisp attribute vector of FACE. */
3926 lface
= lface_from_face_name (NULL
, face
, 1);
3930 frame
= selected_frame
;
3932 CHECK_LIVE_FRAME (frame
);
3933 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3935 /* If a frame-local face doesn't exist yet, create one. */
3937 lface
= Finternal_make_lisp_face (face
, frame
);
3940 if (EQ (attr
, QCfamily
))
3942 if (!UNSPECIFIEDP (value
))
3944 CHECK_STRING (value
);
3945 if (XSTRING (value
)->size
== 0)
3946 signal_error ("Invalid face family", value
);
3948 old_value
= LFACE_FAMILY (lface
);
3949 LFACE_FAMILY (lface
) = value
;
3950 font_related_attr_p
= 1;
3952 else if (EQ (attr
, QCheight
))
3954 if (!UNSPECIFIEDP (value
))
3958 test
= (EQ (face
, Qdefault
)
3960 /* The default face must have an absolute size,
3961 otherwise, we do a test merge with a random
3962 height to see if VALUE's ok. */
3963 : merge_face_heights (value
, make_number (10), Qnil
, Qnil
));
3965 if (!INTEGERP (test
) || XINT (test
) <= 0)
3966 signal_error ("Invalid face height", value
);
3969 old_value
= LFACE_HEIGHT (lface
);
3970 LFACE_HEIGHT (lface
) = value
;
3971 font_related_attr_p
= 1;
3973 else if (EQ (attr
, QCweight
))
3975 if (!UNSPECIFIEDP (value
))
3977 CHECK_SYMBOL (value
);
3978 if (face_numeric_weight (value
) < 0)
3979 signal_error ("Invalid face weight", value
);
3981 old_value
= LFACE_WEIGHT (lface
);
3982 LFACE_WEIGHT (lface
) = value
;
3983 font_related_attr_p
= 1;
3985 else if (EQ (attr
, QCslant
))
3987 if (!UNSPECIFIEDP (value
))
3989 CHECK_SYMBOL (value
);
3990 if (face_numeric_slant (value
) < 0)
3991 signal_error ("Invalid face slant", value
);
3993 old_value
= LFACE_SLANT (lface
);
3994 LFACE_SLANT (lface
) = value
;
3995 font_related_attr_p
= 1;
3997 else if (EQ (attr
, QCunderline
))
3999 if (!UNSPECIFIEDP (value
))
4000 if ((SYMBOLP (value
)
4002 && !EQ (value
, Qnil
))
4003 /* Underline color. */
4005 && XSTRING (value
)->size
== 0))
4006 signal_error ("Invalid face underline", value
);
4008 old_value
= LFACE_UNDERLINE (lface
);
4009 LFACE_UNDERLINE (lface
) = value
;
4011 else if (EQ (attr
, QCoverline
))
4013 if (!UNSPECIFIEDP (value
))
4014 if ((SYMBOLP (value
)
4016 && !EQ (value
, Qnil
))
4017 /* Overline color. */
4019 && XSTRING (value
)->size
== 0))
4020 signal_error ("Invalid face overline", value
);
4022 old_value
= LFACE_OVERLINE (lface
);
4023 LFACE_OVERLINE (lface
) = value
;
4025 else if (EQ (attr
, QCstrike_through
))
4027 if (!UNSPECIFIEDP (value
))
4028 if ((SYMBOLP (value
)
4030 && !EQ (value
, Qnil
))
4031 /* Strike-through color. */
4033 && XSTRING (value
)->size
== 0))
4034 signal_error ("Invalid face strike-through", value
);
4036 old_value
= LFACE_STRIKE_THROUGH (lface
);
4037 LFACE_STRIKE_THROUGH (lface
) = value
;
4039 else if (EQ (attr
, QCbox
))
4043 /* Allow t meaning a simple box of width 1 in foreground color
4046 value
= make_number (1);
4048 if (UNSPECIFIEDP (value
))
4050 else if (NILP (value
))
4052 else if (INTEGERP (value
))
4053 valid_p
= XINT (value
) != 0;
4054 else if (STRINGP (value
))
4055 valid_p
= XSTRING (value
)->size
> 0;
4056 else if (CONSP (value
))
4072 if (EQ (k
, QCline_width
))
4074 if (!INTEGERP (v
) || XINT (v
) == 0)
4077 else if (EQ (k
, QCcolor
))
4079 if (!STRINGP (v
) || XSTRING (v
)->size
== 0)
4082 else if (EQ (k
, QCstyle
))
4084 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
4091 valid_p
= NILP (tem
);
4097 signal_error ("Invalid face box", value
);
4099 old_value
= LFACE_BOX (lface
);
4100 LFACE_BOX (lface
) = value
;
4102 else if (EQ (attr
, QCinverse_video
)
4103 || EQ (attr
, QCreverse_video
))
4105 if (!UNSPECIFIEDP (value
))
4107 CHECK_SYMBOL (value
);
4108 if (!EQ (value
, Qt
) && !NILP (value
))
4109 signal_error ("Invalid inverse-video face attribute value", value
);
4111 old_value
= LFACE_INVERSE (lface
);
4112 LFACE_INVERSE (lface
) = value
;
4114 else if (EQ (attr
, QCforeground
))
4116 if (!UNSPECIFIEDP (value
))
4118 /* Don't check for valid color names here because it depends
4119 on the frame (display) whether the color will be valid
4120 when the face is realized. */
4121 CHECK_STRING (value
);
4122 if (XSTRING (value
)->size
== 0)
4123 signal_error ("Empty foreground color value", value
);
4125 old_value
= LFACE_FOREGROUND (lface
);
4126 LFACE_FOREGROUND (lface
) = value
;
4128 else if (EQ (attr
, QCbackground
))
4130 if (!UNSPECIFIEDP (value
))
4132 /* Don't check for valid color names here because it depends
4133 on the frame (display) whether the color will be valid
4134 when the face is realized. */
4135 CHECK_STRING (value
);
4136 if (XSTRING (value
)->size
== 0)
4137 signal_error ("Empty background color value", value
);
4139 old_value
= LFACE_BACKGROUND (lface
);
4140 LFACE_BACKGROUND (lface
) = value
;
4142 else if (EQ (attr
, QCstipple
))
4144 #ifdef HAVE_X_WINDOWS
4145 if (!UNSPECIFIEDP (value
)
4147 && NILP (Fbitmap_spec_p (value
)))
4148 signal_error ("Invalid stipple attribute", value
);
4149 old_value
= LFACE_STIPPLE (lface
);
4150 LFACE_STIPPLE (lface
) = value
;
4151 #endif /* HAVE_X_WINDOWS */
4153 else if (EQ (attr
, QCwidth
))
4155 if (!UNSPECIFIEDP (value
))
4157 CHECK_SYMBOL (value
);
4158 if (face_numeric_swidth (value
) < 0)
4159 signal_error ("Invalid face width", value
);
4161 old_value
= LFACE_SWIDTH (lface
);
4162 LFACE_SWIDTH (lface
) = value
;
4163 font_related_attr_p
= 1;
4165 else if (EQ (attr
, QCfont
) || EQ (attr
, QCfontset
))
4167 #ifdef HAVE_WINDOW_SYSTEM
4168 if (FRAME_WINDOW_P (XFRAME (frame
)))
4170 /* Set font-related attributes of the Lisp face from an XLFD
4175 CHECK_STRING (value
);
4177 f
= SELECTED_FRAME ();
4179 f
= check_x_frame (frame
);
4181 /* VALUE may be a fontset name or an alias of fontset. In
4182 such a case, use the base fontset name. */
4183 tmp
= Fquery_fontset (value
, Qnil
);
4186 else if (EQ (attr
, QCfontset
))
4187 signal_error ("Invalid fontset name", value
);
4189 if (EQ (attr
, QCfont
))
4191 if (!set_lface_from_font_name (f
, lface
, value
, 1, 1))
4192 signal_error ("Invalid font or fontset name", value
);
4195 LFACE_FONTSET (lface
) = value
;
4199 #endif /* HAVE_WINDOW_SYSTEM */
4201 else if (EQ (attr
, QCinherit
))
4204 if (SYMBOLP (value
))
4207 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
4208 if (!SYMBOLP (XCAR (tail
)))
4211 LFACE_INHERIT (lface
) = value
;
4213 signal_error ("Invalid face inheritance", value
);
4215 else if (EQ (attr
, QCbold
))
4217 old_value
= LFACE_WEIGHT (lface
);
4218 LFACE_WEIGHT (lface
) = NILP (value
) ? Qnormal
: Qbold
;
4219 font_related_attr_p
= 1;
4221 else if (EQ (attr
, QCitalic
))
4223 old_value
= LFACE_SLANT (lface
);
4224 LFACE_SLANT (lface
) = NILP (value
) ? Qnormal
: Qitalic
;
4225 font_related_attr_p
= 1;
4228 signal_error ("Invalid face attribute name", attr
);
4230 if (font_related_attr_p
4231 && !UNSPECIFIEDP (value
))
4232 /* If a font-related attribute other than QCfont is specified, the
4233 original `font' attribute nor that of default face is useless
4234 to determine a new font. Thus, we set it to nil so that font
4235 selection mechanism doesn't use it. */
4236 LFACE_FONT (lface
) = Qnil
;
4238 /* Changing a named face means that all realized faces depending on
4239 that face are invalid. Since we cannot tell which realized faces
4240 depend on the face, make sure they are all removed. This is done
4241 by incrementing face_change_count. The next call to
4242 init_iterator will then free realized faces. */
4244 && (EQ (attr
, QCfont
)
4245 || EQ (attr
, QCfontset
)
4246 || NILP (Fequal (old_value
, value
))))
4248 ++face_change_count
;
4249 ++windows_or_buffers_changed
;
4252 if (!UNSPECIFIEDP (value
)
4253 && NILP (Fequal (old_value
, value
)))
4259 if (EQ (face
, Qdefault
))
4261 #ifdef HAVE_WINDOW_SYSTEM
4262 /* Changed font-related attributes of the `default' face are
4263 reflected in changed `font' frame parameters. */
4265 && (font_related_attr_p
|| font_attr_p
)
4266 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
4267 set_font_frame_param (frame
, lface
);
4269 #endif /* HAVE_WINDOW_SYSTEM */
4271 if (EQ (attr
, QCforeground
))
4272 param
= Qforeground_color
;
4273 else if (EQ (attr
, QCbackground
))
4274 param
= Qbackground_color
;
4276 #ifdef HAVE_WINDOW_SYSTEM
4278 else if (EQ (face
, Qscroll_bar
))
4280 /* Changing the colors of `scroll-bar' sets frame parameters
4281 `scroll-bar-foreground' and `scroll-bar-background'. */
4282 if (EQ (attr
, QCforeground
))
4283 param
= Qscroll_bar_foreground
;
4284 else if (EQ (attr
, QCbackground
))
4285 param
= Qscroll_bar_background
;
4287 #endif /* not WINDOWSNT */
4288 else if (EQ (face
, Qborder
))
4290 /* Changing background color of `border' sets frame parameter
4292 if (EQ (attr
, QCbackground
))
4293 param
= Qborder_color
;
4295 else if (EQ (face
, Qcursor
))
4297 /* Changing background color of `cursor' sets frame parameter
4299 if (EQ (attr
, QCbackground
))
4300 param
= Qcursor_color
;
4302 else if (EQ (face
, Qmouse
))
4304 /* Changing background color of `mouse' sets frame parameter
4306 if (EQ (attr
, QCbackground
))
4307 param
= Qmouse_color
;
4309 #endif /* HAVE_WINDOW_SYSTEM */
4310 else if (EQ (face
, Qmenu
))
4312 /* Indicate that we have to update the menu bar when
4313 realizing faces on FRAME. FRAME t change the
4314 default for new frames. We do this by setting
4315 setting the flag in new face caches */
4318 struct frame
*f
= XFRAME (frame
);
4319 if (FRAME_FACE_CACHE (f
) == NULL
)
4320 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
4321 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 1;
4324 menu_face_changed_default
= 1;
4330 /* Update `default-frame-alist', which is used for new frames. */
4332 store_in_alist (&Vdefault_frame_alist
, param
, value
);
4335 /* Update the current frame's parameters. */
4338 cons
= XCAR (Vparam_value_alist
);
4339 XSETCAR (cons
, param
);
4340 XSETCDR (cons
, value
);
4341 Fmodify_frame_parameters (frame
, Vparam_value_alist
);
4350 #ifdef HAVE_WINDOW_SYSTEM
4352 /* Set the `font' frame parameter of FRAME determined from `default'
4353 face attributes LFACE. If a font name is explicitely
4354 specfied in LFACE, use it as is. Otherwise, determine a font name
4355 from the other font-related atrributes of LFACE. In that case, if
4356 there's no matching font, signals an error. */
4359 set_font_frame_param (frame
, lface
)
4360 Lisp_Object frame
, lface
;
4362 struct frame
*f
= XFRAME (frame
);
4364 if (FRAME_WINDOW_P (f
))
4366 Lisp_Object font_name
;
4369 if (STRINGP (LFACE_FONT (lface
)))
4370 font_name
= LFACE_FONT (lface
);
4373 /* Choose a font name that reflects LFACE's attributes and has
4374 the registry and encoding pattern specified in the default
4375 fontset (3rd arg: -1) for ASCII characters (4th arg: 0). */
4376 font
= choose_face_font (f
, XVECTOR (lface
)->contents
, Qnil
);
4378 error ("No font matches the specified attribute");
4379 font_name
= build_string (font
);
4383 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, font_name
), Qnil
));
4388 /* Update the corresponding face when frame parameter PARAM on frame F
4389 has been assigned the value NEW_VALUE. */
4392 update_face_from_frame_parameter (f
, param
, new_value
)
4394 Lisp_Object param
, new_value
;
4398 /* If there are no faces yet, give up. This is the case when called
4399 from Fx_create_frame, and we do the necessary things later in
4400 face-set-after-frame-defaults. */
4401 if (NILP (f
->face_alist
))
4404 /* Changing a named face means that all realized faces depending on
4405 that face are invalid. Since we cannot tell which realized faces
4406 depend on the face, make sure they are all removed. This is done
4407 by incrementing face_change_count. The next call to
4408 init_iterator will then free realized faces. */
4409 ++face_change_count
;
4410 ++windows_or_buffers_changed
;
4412 if (EQ (param
, Qforeground_color
))
4414 lface
= lface_from_face_name (f
, Qdefault
, 1);
4415 LFACE_FOREGROUND (lface
) = (STRINGP (new_value
)
4416 ? new_value
: Qunspecified
);
4417 realize_basic_faces (f
);
4419 else if (EQ (param
, Qbackground_color
))
4423 /* Changing the background color might change the background
4424 mode, so that we have to load new defface specs. Call
4425 frame-update-face-colors to do that. */
4426 XSETFRAME (frame
, f
);
4427 call1 (Qframe_update_face_colors
, frame
);
4429 lface
= lface_from_face_name (f
, Qdefault
, 1);
4430 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4431 ? new_value
: Qunspecified
);
4432 realize_basic_faces (f
);
4434 if (EQ (param
, Qborder_color
))
4436 lface
= lface_from_face_name (f
, Qborder
, 1);
4437 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4438 ? new_value
: Qunspecified
);
4440 else if (EQ (param
, Qcursor_color
))
4442 lface
= lface_from_face_name (f
, Qcursor
, 1);
4443 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4444 ? new_value
: Qunspecified
);
4446 else if (EQ (param
, Qmouse_color
))
4448 lface
= lface_from_face_name (f
, Qmouse
, 1);
4449 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4450 ? new_value
: Qunspecified
);
4455 /* Get the value of X resource RESOURCE, class CLASS for the display
4456 of frame FRAME. This is here because ordinary `x-get-resource'
4457 doesn't take a frame argument. */
4459 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
4460 Sinternal_face_x_get_resource
, 3, 3, 0, doc
: /* */)
4461 (resource
, class, frame
)
4462 Lisp_Object resource
, class, frame
;
4464 Lisp_Object value
= Qnil
;
4467 CHECK_STRING (resource
);
4468 CHECK_STRING (class);
4469 CHECK_LIVE_FRAME (frame
);
4471 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame
)),
4472 resource
, class, Qnil
, Qnil
);
4474 #endif /* not macintosh */
4475 #endif /* not WINDOWSNT */
4480 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
4481 If VALUE is "on" or "true", return t. If VALUE is "off" or
4482 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
4483 error; if SIGNAL_P is zero, return 0. */
4486 face_boolean_x_resource_value (value
, signal_p
)
4490 Lisp_Object result
= make_number (0);
4492 xassert (STRINGP (value
));
4494 if (xstricmp (XSTRING (value
)->data
, "on") == 0
4495 || xstricmp (XSTRING (value
)->data
, "true") == 0)
4497 else if (xstricmp (XSTRING (value
)->data
, "off") == 0
4498 || xstricmp (XSTRING (value
)->data
, "false") == 0)
4500 else if (xstricmp (XSTRING (value
)->data
, "unspecified") == 0)
4501 result
= Qunspecified
;
4503 signal_error ("Invalid face attribute value from X resource", value
);
4509 DEFUN ("internal-set-lisp-face-attribute-from-resource",
4510 Finternal_set_lisp_face_attribute_from_resource
,
4511 Sinternal_set_lisp_face_attribute_from_resource
,
4512 3, 4, 0, doc
: /* */)
4513 (face
, attr
, value
, frame
)
4514 Lisp_Object face
, attr
, value
, frame
;
4516 CHECK_SYMBOL (face
);
4517 CHECK_SYMBOL (attr
);
4518 CHECK_STRING (value
);
4520 if (xstricmp (XSTRING (value
)->data
, "unspecified") == 0)
4521 value
= Qunspecified
;
4522 else if (EQ (attr
, QCheight
))
4524 value
= Fstring_to_number (value
, make_number (10));
4525 if (XINT (value
) <= 0)
4526 signal_error ("Invalid face height from X resource", value
);
4528 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
4529 value
= face_boolean_x_resource_value (value
, 1);
4530 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
4531 value
= intern (XSTRING (value
)->data
);
4532 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
4533 value
= face_boolean_x_resource_value (value
, 1);
4534 else if (EQ (attr
, QCunderline
)
4535 || EQ (attr
, QCoverline
)
4536 || EQ (attr
, QCstrike_through
))
4538 Lisp_Object boolean_value
;
4540 /* If the result of face_boolean_x_resource_value is t or nil,
4541 VALUE does NOT specify a color. */
4542 boolean_value
= face_boolean_x_resource_value (value
, 0);
4543 if (SYMBOLP (boolean_value
))
4544 value
= boolean_value
;
4546 else if (EQ (attr
, QCbox
))
4547 value
= Fcar (Fread_from_string (value
, Qnil
, Qnil
));
4549 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
4552 #endif /* HAVE_WINDOW_SYSTEM */
4555 /***********************************************************************
4557 ***********************************************************************/
4559 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
4561 /* Make menus on frame F appear as specified by the `menu' face. */
4564 x_update_menu_appearance (f
)
4567 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
4571 && (rdb
= XrmGetDatabase (FRAME_X_DISPLAY (f
)),
4575 Lisp_Object lface
= lface_from_face_name (f
, Qmenu
, 1);
4576 struct face
*face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
4577 char *myname
= XSTRING (Vx_resource_name
)->data
;
4580 const char *popup_path
= "popup_menu";
4582 const char *popup_path
= "menu.popup";
4585 if (STRINGP (LFACE_FOREGROUND (lface
)))
4587 sprintf (line
, "%s.%s*foreground: %s",
4589 XSTRING (LFACE_FOREGROUND (lface
))->data
);
4590 XrmPutLineResource (&rdb
, line
);
4591 sprintf (line
, "%s.pane.menubar*foreground: %s",
4592 myname
, XSTRING (LFACE_FOREGROUND (lface
))->data
);
4593 XrmPutLineResource (&rdb
, line
);
4597 if (STRINGP (LFACE_BACKGROUND (lface
)))
4599 sprintf (line
, "%s.%s*background: %s",
4601 XSTRING (LFACE_BACKGROUND (lface
))->data
);
4602 XrmPutLineResource (&rdb
, line
);
4603 sprintf (line
, "%s.pane.menubar*background: %s",
4604 myname
, XSTRING (LFACE_BACKGROUND (lface
))->data
);
4605 XrmPutLineResource (&rdb
, line
);
4610 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
4611 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
4612 || !UNSPECIFIEDP (LFACE_AVGWIDTH (lface
))
4613 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
4614 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
4615 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
4618 const char *suffix
= "List";
4620 const char *suffix
= "";
4622 sprintf (line
, "%s.pane.menubar*font%s: %s",
4623 myname
, suffix
, face
->font_name
);
4624 XrmPutLineResource (&rdb
, line
);
4625 sprintf (line
, "%s.%s*font%s: %s",
4626 myname
, popup_path
, suffix
, face
->font_name
);
4627 XrmPutLineResource (&rdb
, line
);
4631 if (changed_p
&& f
->output_data
.x
->menubar_widget
)
4632 free_frame_menubar (f
);
4636 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
4639 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p
,
4640 Sface_attribute_relative_p
,
4642 doc
: /* Return non-nil if face ATTRIBUTE VALUE is relative. */)
4644 Lisp_Object attribute
, value
;
4646 if (EQ (value
, Qunspecified
))
4648 else if (EQ (attribute
, QCheight
))
4649 return INTEGERP (value
) ? Qnil
: Qt
;
4654 DEFUN ("merge-face-attribute", Fmerge_face_attribute
, Smerge_face_attribute
,
4656 doc
: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
4657 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
4658 the result will be absolute, otherwise it will be relative. */)
4659 (attribute
, value1
, value2
)
4660 Lisp_Object attribute
, value1
, value2
;
4662 if (EQ (value1
, Qunspecified
))
4664 else if (EQ (attribute
, QCheight
))
4665 return merge_face_heights (value1
, value2
, value1
, Qnil
);
4671 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
4672 Sinternal_get_lisp_face_attribute
,
4674 doc
: /* Return face attribute KEYWORD of face SYMBOL.
4675 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
4676 face attribute name, signal an error.
4677 If the optional argument FRAME is given, report on face FACE in that
4678 frame. If FRAME is t, report on the defaults for face FACE (for new
4679 frames). If FRAME is omitted or nil, use the selected frame. */)
4680 (symbol
, keyword
, frame
)
4681 Lisp_Object symbol
, keyword
, frame
;
4683 Lisp_Object lface
, value
= Qnil
;
4685 CHECK_SYMBOL (symbol
);
4686 CHECK_SYMBOL (keyword
);
4689 lface
= lface_from_face_name (NULL
, symbol
, 1);
4693 frame
= selected_frame
;
4694 CHECK_LIVE_FRAME (frame
);
4695 lface
= lface_from_face_name (XFRAME (frame
), symbol
, 1);
4698 if (EQ (keyword
, QCfamily
))
4699 value
= LFACE_FAMILY (lface
);
4700 else if (EQ (keyword
, QCheight
))
4701 value
= LFACE_HEIGHT (lface
);
4702 else if (EQ (keyword
, QCweight
))
4703 value
= LFACE_WEIGHT (lface
);
4704 else if (EQ (keyword
, QCslant
))
4705 value
= LFACE_SLANT (lface
);
4706 else if (EQ (keyword
, QCunderline
))
4707 value
= LFACE_UNDERLINE (lface
);
4708 else if (EQ (keyword
, QCoverline
))
4709 value
= LFACE_OVERLINE (lface
);
4710 else if (EQ (keyword
, QCstrike_through
))
4711 value
= LFACE_STRIKE_THROUGH (lface
);
4712 else if (EQ (keyword
, QCbox
))
4713 value
= LFACE_BOX (lface
);
4714 else if (EQ (keyword
, QCinverse_video
)
4715 || EQ (keyword
, QCreverse_video
))
4716 value
= LFACE_INVERSE (lface
);
4717 else if (EQ (keyword
, QCforeground
))
4718 value
= LFACE_FOREGROUND (lface
);
4719 else if (EQ (keyword
, QCbackground
))
4720 value
= LFACE_BACKGROUND (lface
);
4721 else if (EQ (keyword
, QCstipple
))
4722 value
= LFACE_STIPPLE (lface
);
4723 else if (EQ (keyword
, QCwidth
))
4724 value
= LFACE_SWIDTH (lface
);
4725 else if (EQ (keyword
, QCinherit
))
4726 value
= LFACE_INHERIT (lface
);
4727 else if (EQ (keyword
, QCfont
))
4728 value
= LFACE_FONT (lface
);
4729 else if (EQ (keyword
, QCfontset
))
4730 value
= LFACE_FONTSET (lface
);
4732 signal_error ("Invalid face attribute name", keyword
);
4738 DEFUN ("internal-lisp-face-attribute-values",
4739 Finternal_lisp_face_attribute_values
,
4740 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
4741 doc
: /* Return a list of valid discrete values for face attribute ATTR.
4742 Value is nil if ATTR doesn't have a discrete set of valid values. */)
4746 Lisp_Object result
= Qnil
;
4748 CHECK_SYMBOL (attr
);
4750 if (EQ (attr
, QCweight
)
4751 || EQ (attr
, QCslant
)
4752 || EQ (attr
, QCwidth
))
4754 /* Extract permissible symbols from tables. */
4755 struct table_entry
*table
;
4758 if (EQ (attr
, QCweight
))
4759 table
= weight_table
, dim
= DIM (weight_table
);
4760 else if (EQ (attr
, QCslant
))
4761 table
= slant_table
, dim
= DIM (slant_table
);
4763 table
= swidth_table
, dim
= DIM (swidth_table
);
4765 for (i
= 0; i
< dim
; ++i
)
4767 Lisp_Object symbol
= *table
[i
].symbol
;
4768 Lisp_Object tail
= result
;
4771 && !EQ (XCAR (tail
), symbol
))
4775 result
= Fcons (symbol
, result
);
4778 else if (EQ (attr
, QCunderline
))
4779 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4780 else if (EQ (attr
, QCoverline
))
4781 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4782 else if (EQ (attr
, QCstrike_through
))
4783 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4784 else if (EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
4785 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4791 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
4792 Sinternal_merge_in_global_face
, 2, 2, 0,
4793 doc
: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
4794 Default face attributes override any local face attributes. */)
4796 Lisp_Object face
, frame
;
4799 Lisp_Object global_lface
, local_lface
, *gvec
, *lvec
;
4801 CHECK_LIVE_FRAME (frame
);
4802 global_lface
= lface_from_face_name (NULL
, face
, 1);
4803 local_lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
4804 if (NILP (local_lface
))
4805 local_lface
= Finternal_make_lisp_face (face
, frame
);
4807 /* Make every specified global attribute override the local one.
4808 BEWARE!! This is only used from `face-set-after-frame-default' where
4809 the local frame is defined from default specs in `face-defface-spec'
4810 and those should be overridden by global settings. Hence the strange
4811 "global before local" priority. */
4812 lvec
= XVECTOR (local_lface
)->contents
;
4813 gvec
= XVECTOR (global_lface
)->contents
;
4814 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4815 if (! UNSPECIFIEDP (gvec
[i
]))
4822 /* The following function is implemented for compatibility with 20.2.
4823 The function is used in x-resolve-fonts when it is asked to
4824 return fonts with the same size as the font of a face. This is
4825 done in fontset.el. */
4827 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 2, 0,
4828 doc
: /* Return the font name of face FACE, or nil if it is unspecified.
4829 If the optional argument FRAME is given, report on face FACE in that frame.
4830 If FRAME is t, report on the defaults for face FACE (for new frames).
4831 The font default for a face is either nil, or a list
4832 of the form (bold), (italic) or (bold italic).
4833 If FRAME is omitted or nil, use the selected frame. */)
4835 Lisp_Object face
, frame
;
4839 Lisp_Object result
= Qnil
;
4840 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
4842 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
4843 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
4844 result
= Fcons (Qbold
, result
);
4846 if (!UNSPECIFIEDP (LFACE_SLANT (lface
))
4847 && !EQ (LFACE_SLANT (lface
), Qnormal
))
4848 result
= Fcons (Qitalic
, result
);
4854 struct frame
*f
= frame_or_selected_frame (frame
, 1);
4855 int face_id
= lookup_named_face (f
, face
);
4856 struct face
*face
= FACE_FROM_ID (f
, face_id
);
4857 return face
? build_string (face
->font_name
) : Qnil
;
4862 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
4863 all attributes are `equal'. Tries to be fast because this function
4864 is called quite often. */
4867 lface_equal_p (v1
, v2
)
4868 Lisp_Object
*v1
, *v2
;
4872 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
4874 Lisp_Object a
= v1
[i
];
4875 Lisp_Object b
= v2
[i
];
4877 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
4878 and the other is specified. */
4879 equal_p
= XTYPE (a
) == XTYPE (b
);
4888 equal_p
= ((STRING_BYTES (XSTRING (a
))
4889 == STRING_BYTES (XSTRING (b
)))
4890 && bcmp (XSTRING (a
)->data
, XSTRING (b
)->data
,
4891 STRING_BYTES (XSTRING (a
))) == 0);
4900 equal_p
= !NILP (Fequal (a
, b
));
4910 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
4911 Sinternal_lisp_face_equal_p
, 2, 3, 0,
4912 doc
: /* True if FACE1 and FACE2 are equal.
4913 If the optional argument FRAME is given, report on face FACE in that frame.
4914 If FRAME is t, report on the defaults for face FACE (for new frames).
4915 If FRAME is omitted or nil, use the selected frame. */)
4916 (face1
, face2
, frame
)
4917 Lisp_Object face1
, face2
, frame
;
4921 Lisp_Object lface1
, lface2
;
4926 /* Don't use check_x_frame here because this function is called
4927 before X frames exist. At that time, if FRAME is nil,
4928 selected_frame will be used which is the frame dumped with
4929 Emacs. That frame is not an X frame. */
4930 f
= frame_or_selected_frame (frame
, 2);
4932 lface1
= lface_from_face_name (NULL
, face1
, 1);
4933 lface2
= lface_from_face_name (NULL
, face2
, 1);
4934 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
4935 XVECTOR (lface2
)->contents
);
4936 return equal_p
? Qt
: Qnil
;
4940 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
4941 Sinternal_lisp_face_empty_p
, 1, 2, 0,
4942 doc
: /* True if FACE has no attribute specified.
4943 If the optional argument FRAME is given, report on face FACE in that frame.
4944 If FRAME is t, report on the defaults for face FACE (for new frames).
4945 If FRAME is omitted or nil, use the selected frame. */)
4947 Lisp_Object face
, frame
;
4954 frame
= selected_frame
;
4955 CHECK_LIVE_FRAME (frame
);
4959 lface
= lface_from_face_name (NULL
, face
, 1);
4961 lface
= lface_from_face_name (f
, face
, 1);
4963 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4964 if (!UNSPECIFIEDP (AREF (lface
, i
)))
4967 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
4971 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
4973 doc
: /* Return an alist of frame-local faces defined on FRAME.
4974 For internal use only. */)
4978 struct frame
*f
= frame_or_selected_frame (frame
, 0);
4979 return f
->face_alist
;
4983 /* Return a hash code for Lisp string STRING with case ignored. Used
4984 below in computing a hash value for a Lisp face. */
4986 static INLINE
unsigned
4987 hash_string_case_insensitive (string
)
4992 xassert (STRINGP (string
));
4993 for (s
= XSTRING (string
)->data
; *s
; ++s
)
4994 hash
= (hash
<< 1) ^ tolower (*s
);
4999 /* Return a hash code for face attribute vector V. */
5001 static INLINE
unsigned
5005 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
5006 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
5007 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
5008 ^ XFASTINT (v
[LFACE_WEIGHT_INDEX
])
5009 ^ XFASTINT (v
[LFACE_SLANT_INDEX
])
5010 ^ XFASTINT (v
[LFACE_SWIDTH_INDEX
])
5011 ^ XFASTINT (v
[LFACE_HEIGHT_INDEX
]));
5015 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
5016 considering charsets/registries). They do if they specify the same
5017 family, point size, weight, width, slant, font, and fontset. Both
5018 LFACE1 and LFACE2 must be fully-specified. */
5021 lface_same_font_attributes_p (lface1
, lface2
)
5022 Lisp_Object
*lface1
, *lface2
;
5024 xassert (lface_fully_specified_p (lface1
)
5025 && lface_fully_specified_p (lface2
));
5026 return (xstricmp (XSTRING (lface1
[LFACE_FAMILY_INDEX
])->data
,
5027 XSTRING (lface2
[LFACE_FAMILY_INDEX
])->data
) == 0
5028 && EQ (lface1
[LFACE_HEIGHT_INDEX
], lface2
[LFACE_HEIGHT_INDEX
])
5029 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
5030 && EQ (lface1
[LFACE_AVGWIDTH_INDEX
], lface2
[LFACE_AVGWIDTH_INDEX
])
5031 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
5032 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
])
5033 && (EQ (lface1
[LFACE_FONT_INDEX
], lface2
[LFACE_FONT_INDEX
])
5034 || (STRINGP (lface1
[LFACE_FONT_INDEX
])
5035 && STRINGP (lface2
[LFACE_FONT_INDEX
])
5036 && ! xstricmp (XSTRING (lface1
[LFACE_FONT_INDEX
])->data
,
5037 XSTRING (lface2
[LFACE_FONT_INDEX
])->data
)))
5038 && (EQ (lface1
[LFACE_FONTSET_INDEX
], lface2
[LFACE_FONTSET_INDEX
])
5039 || (STRINGP (lface1
[LFACE_FONTSET_INDEX
])
5040 && STRINGP (lface2
[LFACE_FONTSET_INDEX
])
5041 && ! xstricmp (XSTRING (lface1
[LFACE_FONTSET_INDEX
])->data
,
5042 XSTRING (lface2
[LFACE_FONTSET_INDEX
])->data
)))
5048 /***********************************************************************
5050 ***********************************************************************/
5052 /* Allocate and return a new realized face for Lisp face attribute
5055 static struct face
*
5056 make_realized_face (attr
)
5059 struct face
*face
= (struct face
*) xmalloc (sizeof *face
);
5060 bzero (face
, sizeof *face
);
5061 face
->ascii_face
= face
;
5062 bcopy (attr
, face
->lface
, sizeof face
->lface
);
5067 /* Free realized face FACE, including its X resources. FACE may
5071 free_realized_face (f
, face
)
5077 #ifdef HAVE_WINDOW_SYSTEM
5078 if (FRAME_WINDOW_P (f
))
5080 /* Free fontset of FACE if it is ASCII face. */
5081 if (face
->fontset
>= 0 && face
== face
->ascii_face
)
5082 free_face_fontset (f
, face
);
5085 x_free_gc (f
, face
->gc
);
5089 free_face_colors (f
, face
);
5090 x_destroy_bitmap (f
, face
->stipple
);
5092 #endif /* HAVE_WINDOW_SYSTEM */
5099 /* Prepare face FACE for subsequent display on frame F. This
5100 allocated GCs if they haven't been allocated yet or have been freed
5101 by clearing the face cache. */
5104 prepare_face_for_display (f
, face
)
5108 #ifdef HAVE_WINDOW_SYSTEM
5109 xassert (FRAME_WINDOW_P (f
));
5114 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
5116 xgcv
.foreground
= face
->foreground
;
5117 xgcv
.background
= face
->background
;
5118 #ifdef HAVE_X_WINDOWS
5119 xgcv
.graphics_exposures
= False
;
5121 /* The font of FACE may be null if we couldn't load it. */
5124 #ifdef HAVE_X_WINDOWS
5125 xgcv
.font
= face
->font
->fid
;
5128 xgcv
.font
= face
->font
;
5131 xgcv
.font
= face
->font
;
5137 #ifdef HAVE_X_WINDOWS
5140 xgcv
.fill_style
= FillOpaqueStippled
;
5141 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
5142 mask
|= GCFillStyle
| GCStipple
;
5145 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
5148 #endif /* HAVE_WINDOW_SYSTEM */
5152 /***********************************************************************
5154 ***********************************************************************/
5156 /* Return a new face cache for frame F. */
5158 static struct face_cache
*
5162 struct face_cache
*c
;
5165 c
= (struct face_cache
*) xmalloc (sizeof *c
);
5166 bzero (c
, sizeof *c
);
5167 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
5168 c
->buckets
= (struct face
**) xmalloc (size
);
5169 bzero (c
->buckets
, size
);
5171 c
->faces_by_id
= (struct face
**) xmalloc (c
->size
* sizeof *c
->faces_by_id
);
5173 c
->menu_face_changed_p
= menu_face_changed_default
;
5178 /* Clear out all graphics contexts for all realized faces, except for
5179 the basic faces. This should be done from time to time just to avoid
5180 keeping too many graphics contexts that are no longer needed. */
5184 struct face_cache
*c
;
5186 if (c
&& FRAME_WINDOW_P (c
->f
))
5188 #ifdef HAVE_WINDOW_SYSTEM
5190 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
5192 struct face
*face
= c
->faces_by_id
[i
];
5193 if (face
&& face
->gc
)
5195 x_free_gc (c
->f
, face
->gc
);
5199 #endif /* HAVE_WINDOW_SYSTEM */
5204 /* Free all realized faces in face cache C, including basic faces. C
5205 may be null. If faces are freed, make sure the frame's current
5206 matrix is marked invalid, so that a display caused by an expose
5207 event doesn't try to use faces we destroyed. */
5210 free_realized_faces (c
)
5211 struct face_cache
*c
;
5216 struct frame
*f
= c
->f
;
5218 /* We must block input here because we can't process X events
5219 safely while only some faces are freed, or when the frame's
5220 current matrix still references freed faces. */
5223 for (i
= 0; i
< c
->used
; ++i
)
5225 free_realized_face (f
, c
->faces_by_id
[i
]);
5226 c
->faces_by_id
[i
] = NULL
;
5230 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
5231 bzero (c
->buckets
, size
);
5233 /* Must do a thorough redisplay the next time. Mark current
5234 matrices as invalid because they will reference faces freed
5235 above. This function is also called when a frame is
5236 destroyed. In this case, the root window of F is nil. */
5237 if (WINDOWP (f
->root_window
))
5239 clear_current_matrices (f
);
5240 ++windows_or_buffers_changed
;
5248 /* Free all realized faces that are using FONTSET on frame F. */
5251 free_realized_faces_for_fontset (f
, fontset
)
5255 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5259 /* We must block input here because we can't process X events safely
5260 while only some faces are freed, or when the frame's current
5261 matrix still references freed faces. */
5264 for (i
= 0; i
< cache
->used
; i
++)
5266 face
= cache
->faces_by_id
[i
];
5268 && face
->fontset
== fontset
)
5270 uncache_face (cache
, face
);
5271 free_realized_face (f
, face
);
5275 /* Must do a thorough redisplay the next time. Mark current
5276 matrices as invalid because they will reference faces freed
5277 above. This function is also called when a frame is destroyed.
5278 In this case, the root window of F is nil. */
5279 if (WINDOWP (f
->root_window
))
5281 clear_current_matrices (f
);
5282 ++windows_or_buffers_changed
;
5289 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
5290 This is done after attributes of a named face have been changed,
5291 because we can't tell which realized faces depend on that face. */
5294 free_all_realized_faces (frame
)
5300 FOR_EACH_FRAME (rest
, frame
)
5301 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
5304 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
5308 /* Free face cache C and faces in it, including their X resources. */
5312 struct face_cache
*c
;
5316 free_realized_faces (c
);
5318 xfree (c
->faces_by_id
);
5324 /* Cache realized face FACE in face cache C. HASH is the hash value
5325 of FACE. If FACE is for ASCII characters (i.e. FACE->ascii_face ==
5326 FACE), insert the new face to the beginning of the collision list
5327 of the face hash table of C. Otherwise, add the new face to the
5328 end of the collision list. This way, lookup_face can quickly find
5329 that a requested face is not cached. */
5332 cache_face (c
, face
, hash
)
5333 struct face_cache
*c
;
5337 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
5341 if (face
->ascii_face
!= face
)
5343 struct face
*last
= c
->buckets
[i
];
5354 c
->buckets
[i
] = face
;
5355 face
->prev
= face
->next
= NULL
;
5361 face
->next
= c
->buckets
[i
];
5363 face
->next
->prev
= face
;
5364 c
->buckets
[i
] = face
;
5367 /* Find a free slot in C->faces_by_id and use the index of the free
5368 slot as FACE->id. */
5369 for (i
= 0; i
< c
->used
; ++i
)
5370 if (c
->faces_by_id
[i
] == NULL
)
5374 /* Maybe enlarge C->faces_by_id. */
5375 if (i
== c
->used
&& c
->used
== c
->size
)
5377 int new_size
= 2 * c
->size
;
5378 int sz
= new_size
* sizeof *c
->faces_by_id
;
5379 c
->faces_by_id
= (struct face
**) xrealloc (c
->faces_by_id
, sz
);
5384 /* Check that FACE got a unique id. */
5389 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
5390 for (face
= c
->buckets
[j
]; face
; face
= face
->next
)
5396 #endif /* GLYPH_DEBUG */
5398 c
->faces_by_id
[i
] = face
;
5404 /* Remove face FACE from cache C. */
5407 uncache_face (c
, face
)
5408 struct face_cache
*c
;
5411 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
5414 face
->prev
->next
= face
->next
;
5416 c
->buckets
[i
] = face
->next
;
5419 face
->next
->prev
= face
->prev
;
5421 c
->faces_by_id
[face
->id
] = NULL
;
5422 if (face
->id
== c
->used
)
5427 /* Look up a realized face with face attributes ATTR in the face cache
5428 of frame F. The face will be used to display ASCII characters.
5429 Value is the ID of the face found. If no suitable face is found,
5430 realize a new one. */
5433 lookup_face (f
, attr
)
5437 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5442 xassert (cache
!= NULL
);
5443 check_lface_attrs (attr
);
5445 /* Look up ATTR in the face cache. */
5446 hash
= lface_hash (attr
);
5447 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
5449 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
5451 if (face
->ascii_face
!= face
)
5453 /* There's no more ASCII face. */
5457 if (face
->hash
== hash
5458 && lface_equal_p (face
->lface
, attr
))
5462 /* If not found, realize a new face. */
5464 face
= realize_face (cache
, attr
, -1);
5467 xassert (face
== FACE_FROM_ID (f
, face
->id
));
5468 #endif /* GLYPH_DEBUG */
5474 /* Look up a realized face that has the same attributes as BASE_FACE
5475 except for the font in the face cache of frame F. If FONT_ID is
5476 not negative, it is an ID number of an already opened font that is
5477 used by the face. If FONT_ID is negative, the face has no font.
5478 Value is the ID of the face found. If no suitable face is found,
5479 realize a new one. */
5482 lookup_non_ascii_face (f
, font_id
, base_face
)
5485 struct face
*base_face
;
5487 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5492 xassert (cache
!= NULL
);
5493 base_face
= base_face
->ascii_face
;
5494 hash
= lface_hash (base_face
->lface
);
5495 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
5497 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
5499 if (face
->ascii_face
== face
)
5501 if (face
->ascii_face
== base_face
5502 && face
->font_info_id
== font_id
)
5506 /* If not found, realize a new face. */
5508 face
= realize_non_ascii_face (f
, font_id
, base_face
);
5511 xassert (face
== FACE_FROM_ID (f
, face
->id
));
5512 #endif /* GLYPH_DEBUG */
5518 /* Return the face id of the realized face for named face SYMBOL on
5519 frame F suitable for displaying ASCII characters. Value is -1 if
5520 the face couldn't be determined, which might happen if the default
5521 face isn't realized and cannot be realized. */
5524 lookup_named_face (f
, symbol
)
5528 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5529 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5530 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5532 if (default_face
== NULL
)
5534 if (!realize_basic_faces (f
))
5536 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5539 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
5540 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
5541 merge_face_vectors (f
, symbol_attrs
, attrs
, Qnil
);
5542 return lookup_face (f
, attrs
);
5546 /* Return the ID of the realized ASCII face of Lisp face with ID
5547 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
5550 ascii_face_of_lisp_face (f
, lface_id
)
5556 if (lface_id
>= 0 && lface_id
< lface_id_to_name_size
)
5558 Lisp_Object face_name
= lface_id_to_name
[lface_id
];
5559 face_id
= lookup_named_face (f
, face_name
);
5568 /* Return a face for charset ASCII that is like the face with id
5569 FACE_ID on frame F, but has a font that is STEPS steps smaller.
5570 STEPS < 0 means larger. Value is the id of the face. */
5573 smaller_face (f
, face_id
, steps
)
5577 #ifdef HAVE_WINDOW_SYSTEM
5579 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5580 int pt
, last_pt
, last_height
;
5583 struct face
*new_face
;
5585 /* If not called for an X frame, just return the original face. */
5586 if (FRAME_TERMCAP_P (f
))
5589 /* Try in increments of 1/2 pt. */
5590 delta
= steps
< 0 ? 5 : -5;
5591 steps
= abs (steps
);
5593 face
= FACE_FROM_ID (f
, face_id
);
5594 bcopy (face
->lface
, attrs
, sizeof attrs
);
5595 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
5596 new_face_id
= face_id
;
5597 last_height
= FONT_HEIGHT (face
->font
);
5601 /* Give up if we cannot find a font within 10pt. */
5602 && abs (last_pt
- pt
) < 100)
5604 /* Look up a face for a slightly smaller/larger font. */
5606 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
5607 new_face_id
= lookup_face (f
, attrs
);
5608 new_face
= FACE_FROM_ID (f
, new_face_id
);
5610 /* If height changes, count that as one step. */
5611 if ((delta
< 0 && FONT_HEIGHT (new_face
->font
) < last_height
)
5612 || (delta
> 0 && FONT_HEIGHT (new_face
->font
) > last_height
))
5615 last_height
= FONT_HEIGHT (new_face
->font
);
5622 #else /* not HAVE_WINDOW_SYSTEM */
5626 #endif /* not HAVE_WINDOW_SYSTEM */
5630 /* Return a face for charset ASCII that is like the face with id
5631 FACE_ID on frame F, but has height HEIGHT. */
5634 face_with_height (f
, face_id
, height
)
5639 #ifdef HAVE_WINDOW_SYSTEM
5641 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5643 if (FRAME_TERMCAP_P (f
)
5647 face
= FACE_FROM_ID (f
, face_id
);
5648 bcopy (face
->lface
, attrs
, sizeof attrs
);
5649 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
5650 face_id
= lookup_face (f
, attrs
);
5651 #endif /* HAVE_WINDOW_SYSTEM */
5657 /* Return the face id of the realized face for named face SYMBOL on
5658 frame F suitable for displaying ASCII characters, and use
5659 attributes of the face FACE_ID for attributes that aren't
5660 completely specified by SYMBOL. This is like lookup_named_face,
5661 except that the default attributes come from FACE_ID, not from the
5662 default face. FACE_ID is assumed to be already realized. */
5665 lookup_derived_face (f
, symbol
, face_id
)
5670 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5671 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5672 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
5677 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
5678 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
5679 merge_face_vectors (f
, symbol_attrs
, attrs
, Qnil
);
5680 return lookup_face (f
, attrs
);
5683 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector
,
5684 Sface_attributes_as_vector
, 1, 1, 0,
5685 doc
: /* Return a vector of face attributes corresponding to PLIST. */)
5690 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
5692 merge_face_vector_with_property (XFRAME (selected_frame
),
5693 XVECTOR (lface
)->contents
,
5700 /***********************************************************************
5702 ***********************************************************************/
5704 DEFUN ("internal-set-font-selection-order",
5705 Finternal_set_font_selection_order
,
5706 Sinternal_set_font_selection_order
, 1, 1, 0,
5707 doc
: /* Set font selection order for face font selection to ORDER.
5708 ORDER must be a list of length 4 containing the symbols `:width',
5709 `:height', `:weight', and `:slant'. Face attributes appearing
5710 first in ORDER are matched first, e.g. if `:height' appears before
5711 `:weight' in ORDER, font selection first tries to find a font with
5712 a suitable height, and then tries to match the font weight.
5719 int indices
[DIM (font_sort_order
)];
5722 bzero (indices
, sizeof indices
);
5726 CONSP (list
) && i
< DIM (indices
);
5727 list
= XCDR (list
), ++i
)
5729 Lisp_Object attr
= XCAR (list
);
5732 if (EQ (attr
, QCwidth
))
5734 else if (EQ (attr
, QCheight
))
5735 xlfd
= XLFD_POINT_SIZE
;
5736 else if (EQ (attr
, QCweight
))
5738 else if (EQ (attr
, QCslant
))
5743 if (indices
[i
] != 0)
5748 if (!NILP (list
) || i
!= DIM (indices
))
5749 signal_error ("Invalid font sort order", order
);
5750 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5751 if (indices
[i
] == 0)
5752 signal_error ("Invalid font sort order", order
);
5754 if (bcmp (indices
, font_sort_order
, sizeof indices
) != 0)
5756 bcopy (indices
, font_sort_order
, sizeof font_sort_order
);
5757 free_all_realized_faces (Qnil
);
5764 DEFUN ("internal-set-alternative-font-family-alist",
5765 Finternal_set_alternative_font_family_alist
,
5766 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
5767 doc
: /* Define alternative font families to try in face font selection.
5768 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5769 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
5770 be found. Value is ALIST. */)
5775 Vface_alternative_font_family_alist
= alist
;
5776 free_all_realized_faces (Qnil
);
5781 DEFUN ("internal-set-alternative-font-registry-alist",
5782 Finternal_set_alternative_font_registry_alist
,
5783 Sinternal_set_alternative_font_registry_alist
, 1, 1, 0,
5784 doc
: /* Define alternative font registries to try in face font selection.
5785 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5786 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
5787 be found. Value is ALIST. */)
5792 Vface_alternative_font_registry_alist
= alist
;
5793 free_all_realized_faces (Qnil
);
5798 #ifdef HAVE_WINDOW_SYSTEM
5800 /* Value is non-zero if FONT is the name of a scalable font. The
5801 X11R6 XLFD spec says that point size, pixel size, and average width
5802 are zero for scalable fonts. Intlfonts contain at least one
5803 scalable font ("*-muleindian-1") for which this isn't true, so we
5804 just test average width. */
5807 font_scalable_p (font
)
5808 struct font_name
*font
;
5810 char *s
= font
->fields
[XLFD_AVGWIDTH
];
5811 return (*s
== '0' && *(s
+ 1) == '\0')
5813 /* Windows implementation of XLFD is slightly broken for backward
5814 compatibility with previous broken versions, so test for
5815 wildcards as well as 0. */
5822 /* Ignore the difference of font point size less than this value. */
5824 #define FONT_POINT_SIZE_QUANTUM 5
5826 /* Value is non-zero if FONT1 is a better match for font attributes
5827 VALUES than FONT2. VALUES is an array of face attribute values in
5828 font sort order. COMPARE_PT_P zero means don't compare point
5829 sizes. AVGWIDTH, if not zero, is a specified font average width
5833 better_font_p (values
, font1
, font2
, compare_pt_p
, avgwidth
)
5835 struct font_name
*font1
, *font2
;
5836 int compare_pt_p
, avgwidth
;
5840 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5842 int xlfd_idx
= font_sort_order
[i
];
5844 if (compare_pt_p
|| xlfd_idx
!= XLFD_POINT_SIZE
)
5848 if (xlfd_idx
== XLFD_POINT_SIZE
)
5850 delta1
= abs (values
[i
] - (font1
->numeric
[xlfd_idx
]
5851 / font1
->resizing_ratio
));
5852 delta2
= abs (values
[i
] - (font2
->numeric
[xlfd_idx
]
5853 / font2
->resizing_ratio
));
5854 if (abs (delta1
- delta2
) < FONT_POINT_SIZE_QUANTUM
)
5859 delta1
= abs (values
[i
] - font1
->numeric
[xlfd_idx
]);
5860 delta2
= abs (values
[i
] - font2
->numeric
[xlfd_idx
]);
5863 if (delta1
> delta2
)
5865 else if (delta1
< delta2
)
5869 /* The difference may be equal because, e.g., the face
5870 specifies `italic' but we have only `regular' and
5871 `oblique'. Prefer `oblique' in this case. */
5872 if ((xlfd_idx
== XLFD_WEIGHT
|| xlfd_idx
== XLFD_SLANT
)
5873 && font1
->numeric
[xlfd_idx
] > values
[i
]
5874 && font2
->numeric
[xlfd_idx
] < values
[i
])
5882 int delta1
= abs (avgwidth
- font1
->numeric
[XLFD_AVGWIDTH
]);
5883 int delta2
= abs (avgwidth
- font2
->numeric
[XLFD_AVGWIDTH
]);
5884 if (delta1
> delta2
)
5886 else if (delta1
< delta2
)
5890 return font1
->registry_priority
< font2
->registry_priority
;
5894 /* Value is non-zero if FONT is an exact match for face attributes in
5895 SPECIFIED. SPECIFIED is an array of face attribute values in font
5896 sort order. AVGWIDTH, if non-zero, is an average width to compare
5900 exact_face_match_p (specified
, font
, avgwidth
)
5902 struct font_name
*font
;
5907 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5908 if (specified
[i
] != font
->numeric
[font_sort_order
[i
]])
5911 return (i
== DIM (font_sort_order
)
5913 || avgwidth
== font
->numeric
[XLFD_AVGWIDTH
]));
5917 /* Value is the name of a scaled font, generated from scalable font
5918 FONT on frame F. SPECIFIED_PT is the point-size to scale FONT to.
5919 Value is allocated from heap. */
5922 build_scalable_font_name (f
, font
, specified_pt
)
5924 struct font_name
*font
;
5927 char point_size
[20], pixel_size
[20];
5929 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
5932 /* If scalable font is for a specific resolution, compute
5933 the point size we must specify from the resolution of
5934 the display and the specified resolution of the font. */
5935 if (font
->numeric
[XLFD_RESY
] != 0)
5937 pt
= resy
/ font
->numeric
[XLFD_RESY
] * specified_pt
+ 0.5;
5938 pixel_value
= font
->numeric
[XLFD_RESY
] / (PT_PER_INCH
* 10.0) * pt
;
5943 pixel_value
= resy
/ (PT_PER_INCH
* 10.0) * pt
;
5945 /* We may need a font of the different size. */
5946 pixel_value
*= font
->resizing_ratio
;
5948 /* Set pixel size. */
5949 sprintf (pixel_size
, "%d", pixel_value
);
5950 font
->fields
[XLFD_PIXEL_SIZE
] = pixel_size
;
5951 font
->numeric
[XLFD_PIXEL_SIZE
] = pixel_value
;
5953 /* We don't have to change POINT_SIZE, RESX, and RESY of the font
5956 /* Set point size of the font. */
5957 sprintf (point_size
, "%d", (int) pt
);
5958 font
->fields
[XLFD_POINT_SIZE
] = point_size
;
5959 font
->numeric
[XLFD_POINT_SIZE
] = pt
;
5961 /* If font doesn't specify its resolution, use the
5962 resolution of the display. */
5963 if (font
->numeric
[XLFD_RESY
] == 0)
5966 sprintf (buffer
, "%d", (int) resy
);
5967 font
->fields
[XLFD_RESY
] = buffer
;
5968 font
->numeric
[XLFD_RESY
] = resy
;
5971 if (strcmp (font
->fields
[XLFD_RESX
], "0") == 0)
5974 int resx
= FRAME_X_DISPLAY_INFO (f
)->resx
;
5975 sprintf (buffer
, "%d", resx
);
5976 font
->fields
[XLFD_RESX
] = buffer
;
5977 font
->numeric
[XLFD_RESX
] = resx
;
5981 return build_font_name (font
);
5985 /* Value is non-zero if we are allowed to use scalable font FONT. We
5986 can't run a Lisp function here since this function may be called
5987 with input blocked. */
5990 may_use_scalable_font_p (font
)
5993 if (EQ (Vscalable_fonts_allowed
, Qt
))
5995 else if (CONSP (Vscalable_fonts_allowed
))
5997 Lisp_Object tail
, regexp
;
5999 for (tail
= Vscalable_fonts_allowed
; CONSP (tail
); tail
= XCDR (tail
))
6001 regexp
= XCAR (tail
);
6002 if (STRINGP (regexp
)
6003 && fast_c_string_match_ignore_case (regexp
, font
) >= 0)
6013 /* Return the name of the best matching font for face attributes ATTRS
6014 in the array of font_name structures FONTS which contains NFONTS
6015 elements. WIDTH_RATIO is a factor with which to multiply average
6016 widths if ATTRS specifies such a width.
6018 Value is a font name which is allocated from the heap. FONTS is
6019 freed by this function. */
6022 best_matching_font (f
, attrs
, fonts
, nfonts
, width_ratio
)
6025 struct font_name
*fonts
;
6030 struct font_name
*best
;
6033 int exact_p
, avgwidth
;
6038 /* Make specified font attributes available in `specified',
6039 indexed by sort order. */
6040 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6042 int xlfd_idx
= font_sort_order
[i
];
6044 if (xlfd_idx
== XLFD_SWIDTH
)
6045 specified
[i
] = face_numeric_swidth (attrs
[LFACE_SWIDTH_INDEX
]);
6046 else if (xlfd_idx
== XLFD_POINT_SIZE
)
6047 specified
[i
] = pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
6048 else if (xlfd_idx
== XLFD_WEIGHT
)
6049 specified
[i
] = face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
6050 else if (xlfd_idx
== XLFD_SLANT
)
6051 specified
[i
] = face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
6056 avgwidth
= (UNSPECIFIEDP (attrs
[LFACE_AVGWIDTH_INDEX
])
6058 : XFASTINT (attrs
[LFACE_AVGWIDTH_INDEX
]) * width_ratio
);
6062 /* Start with the first non-scalable font in the list. */
6063 for (i
= 0; i
< nfonts
; ++i
)
6064 if (!font_scalable_p (fonts
+ i
))
6067 /* Find the best match among the non-scalable fonts. */
6072 for (i
= 1; i
< nfonts
; ++i
)
6073 if (!font_scalable_p (fonts
+ i
)
6074 && better_font_p (specified
, fonts
+ i
, best
, 1, avgwidth
))
6078 exact_p
= exact_face_match_p (specified
, best
, avgwidth
);
6087 /* Unless we found an exact match among non-scalable fonts, see if
6088 we can find a better match among scalable fonts. */
6091 /* A scalable font is better if
6093 1. its weight, slant, swidth attributes are better, or.
6095 2. the best non-scalable font doesn't have the required
6096 point size, and the scalable fonts weight, slant, swidth
6099 int non_scalable_has_exact_height_p
;
6101 if (best
&& best
->numeric
[XLFD_POINT_SIZE
] == pt
)
6102 non_scalable_has_exact_height_p
= 1;
6104 non_scalable_has_exact_height_p
= 0;
6106 for (i
= 0; i
< nfonts
; ++i
)
6107 if (font_scalable_p (fonts
+ i
))
6110 || better_font_p (specified
, fonts
+ i
, best
, 0, 0)
6111 || (!non_scalable_has_exact_height_p
6112 && !better_font_p (specified
, best
, fonts
+ i
, 0, 0)))
6117 if (font_scalable_p (best
))
6118 font_name
= build_scalable_font_name (f
, best
, pt
);
6120 font_name
= build_font_name (best
);
6122 /* Free font_name structures. */
6123 free_font_names (fonts
, nfonts
);
6129 /* Get a list of matching fonts on frame F, considering FAMILY
6130 and alternative font families from Vface_alternative_font_registry_alist.
6132 FAMILY is the font family whose alternatives are considered.
6134 REGISTRY, if a string, specifies a font registry and encoding to
6135 match. A value of nil means include fonts of any registry and
6138 Return in *FONTS a pointer to a vector of font_name structures for
6139 the fonts matched. Value is the number of fonts found. */
6142 try_alternative_families (f
, family
, registry
, fonts
)
6144 Lisp_Object family
, registry
;
6145 struct font_name
**fonts
;
6150 nfonts
= font_list (f
, Qnil
, family
, registry
, fonts
);
6153 /* Try alternative font families. */
6154 alter
= Fassoc (family
, Vface_alternative_font_family_alist
);
6157 for (alter
= XCDR (alter
);
6158 CONSP (alter
) && nfonts
== 0;
6159 alter
= XCDR (alter
))
6161 if (STRINGP (XCAR (alter
)))
6162 nfonts
= font_list (f
, Qnil
, XCAR (alter
), registry
, fonts
);
6166 /* Try scalable fonts before giving up. */
6167 if (nfonts
== 0 && ! EQ (Vscalable_fonts_allowed
, Qt
))
6169 int count
= BINDING_STACK_SIZE ();
6170 specbind (Qscalable_fonts_allowed
, Qt
);
6171 nfonts
= try_alternative_families (f
, family
, registry
, fonts
);
6172 unbind_to (count
, Qnil
);
6179 /* Get a list of matching fonts on frame F.
6181 PATTERN, if a string, specifies a font name pattern to match while
6182 ignoring FAMILY and REGISTRY.
6184 FAMILY, if a list, specifies a list of font families to try.
6186 REGISTRY, if a list, specifies a list of font registries and
6189 Return in *FONTS a pointer to a vector of font_name structures for
6190 the fonts matched. Value is the number of fonts found. */
6193 try_font_list (f
, pattern
, family
, registry
, fonts
)
6195 Lisp_Object pattern
, family
, registry
;
6196 struct font_name
**fonts
;
6200 if (STRINGP (pattern
))
6201 nfonts
= font_list (f
, pattern
, Qnil
, Qnil
, fonts
);
6207 nfonts
= font_list (f
, Qnil
, Qnil
, registry
, fonts
);
6209 for (tail
= family
; ! nfonts
&& CONSP (tail
); tail
= XCDR (tail
))
6210 nfonts
= try_alternative_families (f
, XCAR (tail
), registry
, fonts
);
6212 /* Try font family of the default face or "fixed". */
6213 if (nfonts
== 0 && !NILP (family
))
6215 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6217 family
= default_face
->lface
[LFACE_FAMILY_INDEX
];
6219 family
= build_string ("fixed");
6220 nfonts
= font_list (f
, Qnil
, family
, registry
, fonts
);
6223 /* Try any family with the given registry. */
6224 if (nfonts
== 0 && !NILP (family
))
6225 nfonts
= font_list (f
, Qnil
, Qnil
, registry
, fonts
);
6232 /* Return the fontset id of the base fontset name or alias name given
6233 by the fontset attribute of ATTRS. Value is -1 if the fontset
6234 attribute of ATTRS doesn't name a fontset. */
6237 face_fontset (attrs
)
6243 name
= attrs
[LFACE_FONTSET_INDEX
];
6244 if (!STRINGP (name
))
6246 return fs_query_fontset (name
, 0);
6250 /* Choose a name of font to use on frame F to display characters with
6251 Lisp face attributes specified by ATTRS. The font name is
6252 determined by the font-related attributes in ATTRS and FONT-SPEC
6255 When we are choosing a font for ASCII characters, FONT-SPEC is
6256 always nil. Otherwise FONT-SPEC is a list
6257 [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
6258 or a string specifying a font name pattern.
6260 Value is the font name which is allocated from the heap and must be
6261 freed by the caller. */
6264 choose_face_font (f
, attrs
, font_spec
)
6267 Lisp_Object font_spec
;
6269 Lisp_Object pattern
, family
, adstyle
, registry
;
6270 char *font_name
= NULL
;
6271 struct font_name
*fonts
;
6274 /* If we are choosing an ASCII font and a font name is explicitly
6275 specified in ATTRS, return it. */
6276 if (NILP (font_spec
) && STRINGP (attrs
[LFACE_FONT_INDEX
]))
6277 return xstrdup (XSTRING (attrs
[LFACE_FONT_INDEX
])->data
);
6279 if (NILP (attrs
[LFACE_FAMILY_INDEX
]))
6282 family
= Fcons (attrs
[LFACE_FAMILY_INDEX
], Qnil
);
6284 /* Decide FAMILY, ADSTYLE, and REGISTRY from FONT_SPEC. But,
6285 ADSTYLE is not used in the font selector for the moment. */
6286 if (VECTORP (font_spec
))
6289 if (STRINGP (AREF (font_spec
, FONT_SPEC_FAMILY_INDEX
)))
6290 family
= Fcons (AREF (font_spec
, FONT_SPEC_FAMILY_INDEX
), family
);
6291 adstyle
= AREF (font_spec
, FONT_SPEC_ADSTYLE_INDEX
);
6292 registry
= Fcons (AREF (font_spec
, FONT_SPEC_REGISTRY_INDEX
), Qnil
);
6294 else if (STRINGP (font_spec
))
6296 pattern
= font_spec
;
6303 /* We are choosing an ASCII font. By default, use the registry
6304 name "iso8859-1". But, if the registry name of the ASCII
6305 font specified in the fontset of ATTRS is not "iso8859-1"
6306 (e.g "iso10646-1"), use also that name with higher
6308 int fontset
= face_fontset (attrs
);
6311 struct font_name font
;
6315 registry
= Fcons (build_string ("iso8859-1"), Qnil
);
6317 ascii
= fontset_ascii (fontset
);
6318 len
= STRING_BYTES (XSTRING (ascii
));
6320 || strcmp (XSTRING (ascii
)->data
+ len
- 9, "iso8859-1"))
6322 font
.name
= LSTRDUPA (ascii
);
6323 /* Check if the name is in XLFD. */
6324 if (split_font_name (f
, &font
, 0))
6326 font
.fields
[XLFD_ENCODING
][-1] = '-';
6327 registry
= Fcons (build_string (font
.fields
[XLFD_REGISTRY
]),
6333 /* Get a list of fonts matching that pattern and choose the
6334 best match for the specified face attributes from it. */
6335 nfonts
= try_font_list (f
, pattern
, family
, registry
, &fonts
);
6336 font_name
= best_matching_font (f
, attrs
, fonts
, nfonts
, NILP (font_spec
));
6340 #endif /* HAVE_WINDOW_SYSTEM */
6344 /***********************************************************************
6346 ***********************************************************************/
6348 /* Realize basic faces on frame F. Value is zero if frame parameters
6349 of F don't contain enough information needed to realize the default
6353 realize_basic_faces (f
)
6357 int count
= BINDING_STACK_SIZE ();
6359 /* Block input here so that we won't be surprised by an X expose
6360 event, for instance, without having the faces set up. */
6362 specbind (Qscalable_fonts_allowed
, Qt
);
6364 if (realize_default_face (f
))
6366 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
6367 realize_named_face (f
, Qmode_line_inactive
, MODE_LINE_INACTIVE_FACE_ID
);
6368 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
6369 realize_named_face (f
, Qfringe
, FRINGE_FACE_ID
);
6370 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
6371 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
6372 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
6373 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
6374 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
6375 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
6377 /* Reflect changes in the `menu' face in menu bars. */
6378 if (FRAME_FACE_CACHE (f
)->menu_face_changed_p
)
6380 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 0;
6381 #ifdef USE_X_TOOLKIT
6382 x_update_menu_appearance (f
);
6389 unbind_to (count
, Qnil
);
6395 /* Realize the default face on frame F. If the face is not fully
6396 specified, make it fully-specified. Attributes of the default face
6397 that are not explicitly specified are taken from frame parameters. */
6400 realize_default_face (f
)
6403 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
6405 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6406 Lisp_Object frame_font
;
6409 /* If the `default' face is not yet known, create it. */
6410 lface
= lface_from_face_name (f
, Qdefault
, 0);
6414 XSETFRAME (frame
, f
);
6415 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
6418 #ifdef HAVE_WINDOW_SYSTEM
6419 if (FRAME_WINDOW_P (f
))
6421 /* Set frame_font to the value of the `font' frame parameter. */
6422 frame_font
= Fassq (Qfont
, f
->param_alist
);
6423 xassert (CONSP (frame_font
) && STRINGP (XCDR (frame_font
)));
6424 frame_font
= XCDR (frame_font
);
6425 set_lface_from_font_name (f
, lface
, frame_font
, 1, 1);
6427 #endif /* HAVE_WINDOW_SYSTEM */
6429 if (!FRAME_WINDOW_P (f
))
6431 LFACE_FAMILY (lface
) = build_string ("default");
6432 LFACE_SWIDTH (lface
) = Qnormal
;
6433 LFACE_HEIGHT (lface
) = make_number (1);
6434 if (UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
6435 LFACE_WEIGHT (lface
) = Qnormal
;
6436 if (UNSPECIFIEDP (LFACE_SLANT (lface
)))
6437 LFACE_SLANT (lface
) = Qnormal
;
6438 LFACE_AVGWIDTH (lface
) = Qunspecified
;
6441 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
6442 LFACE_UNDERLINE (lface
) = Qnil
;
6444 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
6445 LFACE_OVERLINE (lface
) = Qnil
;
6447 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
6448 LFACE_STRIKE_THROUGH (lface
) = Qnil
;
6450 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
6451 LFACE_BOX (lface
) = Qnil
;
6453 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
6454 LFACE_INVERSE (lface
) = Qnil
;
6456 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
6458 /* This function is called so early that colors are not yet
6459 set in the frame parameter list. */
6460 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
6462 if (CONSP (color
) && STRINGP (XCDR (color
)))
6463 LFACE_FOREGROUND (lface
) = XCDR (color
);
6464 else if (FRAME_WINDOW_P (f
))
6466 else if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
6467 LFACE_FOREGROUND (lface
) = build_string (unspecified_fg
);
6472 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
6474 /* This function is called so early that colors are not yet
6475 set in the frame parameter list. */
6476 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
6477 if (CONSP (color
) && STRINGP (XCDR (color
)))
6478 LFACE_BACKGROUND (lface
) = XCDR (color
);
6479 else if (FRAME_WINDOW_P (f
))
6481 else if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
6482 LFACE_BACKGROUND (lface
) = build_string (unspecified_bg
);
6487 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
6488 LFACE_STIPPLE (lface
) = Qnil
;
6490 /* Realize the face; it must be fully-specified now. */
6491 xassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
6492 check_lface (lface
);
6493 bcopy (XVECTOR (lface
)->contents
, attrs
, sizeof attrs
);
6494 face
= realize_face (c
, attrs
, DEFAULT_FACE_ID
);
6499 /* Realize basic faces other than the default face in face cache C.
6500 SYMBOL is the face name, ID is the face id the realized face must
6501 have. The default face must have been realized already. */
6504 realize_named_face (f
, symbol
, id
)
6509 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
6510 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
6511 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6512 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
6513 struct face
*new_face
;
6515 /* The default face must exist and be fully specified. */
6516 get_lface_attributes (f
, Qdefault
, attrs
, 1);
6517 check_lface_attrs (attrs
);
6518 xassert (lface_fully_specified_p (attrs
));
6520 /* If SYMBOL isn't know as a face, create it. */
6524 XSETFRAME (frame
, f
);
6525 lface
= Finternal_make_lisp_face (symbol
, frame
);
6528 /* Merge SYMBOL's face with the default face. */
6529 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
6530 merge_face_vectors (f
, symbol_attrs
, attrs
, Qnil
);
6532 /* Realize the face. */
6533 new_face
= realize_face (c
, attrs
, id
);
6537 /* Realize the fully-specified face with attributes ATTRS in face
6538 cache CACHE for ASCII characters. If FORMER_FACE_ID is
6539 non-negative, it is an ID of face to remove before caching the new
6540 face. Value is a pointer to the newly created realized face. */
6542 static struct face
*
6543 realize_face (cache
, attrs
, former_face_id
)
6544 struct face_cache
*cache
;
6550 /* LFACE must be fully specified. */
6551 xassert (cache
!= NULL
);
6552 check_lface_attrs (attrs
);
6554 if (former_face_id
>= 0 && cache
->used
> former_face_id
)
6556 /* Remove the former face. */
6557 struct face
*former_face
= cache
->faces_by_id
[former_face_id
];
6558 uncache_face (cache
, former_face
);
6559 free_realized_face (cache
->f
, former_face
);
6562 if (FRAME_WINDOW_P (cache
->f
))
6563 face
= realize_x_face (cache
, attrs
);
6564 else if (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
))
6565 face
= realize_tty_face (cache
, attrs
);
6569 /* Insert the new face. */
6570 cache_face (cache
, face
, lface_hash (attrs
));
6575 /* Realize the fully-specified face that has the same attributes as
6576 BASE_FACE except for the font on frame F. If FONT_ID is not
6577 negative, it is an ID number of an already opened font that should
6578 be used by the face. If FONT_ID is negative, the face has no font,
6579 i.e., characters are displayed by empty boxes. */
6581 static struct face
*
6582 realize_non_ascii_face (f
, font_id
, base_face
)
6585 struct face
*base_face
;
6587 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
6589 struct font_info
*font_info
;
6591 face
= (struct face
*) xmalloc (sizeof *face
);
6595 /* Don't try to free the colors copied bitwise from BASE_FACE. */
6596 face
->colors_copied_bitwise_p
= 1;
6598 face
->font_info_id
= font_id
;
6601 font_info
= FONT_INFO_FROM_ID (f
, font_id
);
6602 face
->font
= font_info
->font
;
6603 face
->font_name
= font_info
->full_name
;
6608 face
->font_name
= NULL
;
6613 cache_face (cache
, face
, face
->hash
);
6619 /* Realize the fully-specified face with attributes ATTRS in face
6620 cache CACHE for ASCII characters. Do it for X frame CACHE->f. If
6621 the new face doesn't share font with the default face, a fontname
6622 is allocated from the heap and set in `font_name' of the new face,
6623 but it is not yet loaded here. Value is a pointer to the newly
6624 created realized face. */
6626 static struct face
*
6627 realize_x_face (cache
, attrs
)
6628 struct face_cache
*cache
;
6631 #ifdef HAVE_WINDOW_SYSTEM
6632 struct face
*face
, *default_face
;
6634 Lisp_Object stipple
, overline
, strike_through
, box
;
6636 xassert (FRAME_WINDOW_P (cache
->f
));
6638 /* Allocate a new realized face. */
6639 face
= make_realized_face (attrs
);
6640 face
->ascii_face
= face
;
6644 /* Determine the font to use. Most of the time, the font will be
6645 the same as the font of the default face, so try that first. */
6646 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6648 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
6650 face
->font
= default_face
->font
;
6651 face
->font_info_id
= default_face
->font_info_id
;
6652 face
->font_name
= default_face
->font_name
;
6654 = make_fontset_for_ascii_face (f
, default_face
->fontset
, face
);
6658 /* If the face attribute ATTRS specifies a fontset, use it as
6659 the base of a new realized fontset. Otherwise, use the same
6660 base fontset as of the default face. The base determines
6661 registry and encoding of a font. It may also determine
6662 foundry and family. The other fields of font name pattern
6663 are constructed from ATTRS. */
6664 int fontset
= face_fontset (attrs
);
6666 /* If we are realizing the default face, ATTRS should specify a
6667 fontset. In other words, if FONTSET is -1, we are not
6668 realizing the default face, thus the default face should have
6669 already been realized. */
6671 fontset
= default_face
->fontset
;
6674 face
->font
= NULL
; /* to force realize_face to load font */
6677 /* Load the font if it is specified in ATTRS. This fixes
6678 changing frame font on the Mac. */
6679 if (STRINGP (attrs
[LFACE_FONT_INDEX
]))
6681 struct font_info
*font_info
=
6682 FS_LOAD_FONT (f
, XSTRING (attrs
[LFACE_FONT_INDEX
])->data
);
6684 face
->font
= font_info
->font
;
6688 load_face_font (f
, face
);
6689 face
->fontset
= make_fontset_for_ascii_face (f
, fontset
, face
);
6692 /* Load colors, and set remaining attributes. */
6694 load_face_colors (f
, face
, attrs
);
6697 box
= attrs
[LFACE_BOX_INDEX
];
6700 /* A simple box of line width 1 drawn in color given by
6702 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
6704 face
->box
= FACE_SIMPLE_BOX
;
6705 face
->box_line_width
= 1;
6707 else if (INTEGERP (box
))
6709 /* Simple box of specified line width in foreground color of the
6711 xassert (XINT (box
) != 0);
6712 face
->box
= FACE_SIMPLE_BOX
;
6713 face
->box_line_width
= XINT (box
);
6714 face
->box_color
= face
->foreground
;
6715 face
->box_color_defaulted_p
= 1;
6717 else if (CONSP (box
))
6719 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
6720 being one of `raised' or `sunken'. */
6721 face
->box
= FACE_SIMPLE_BOX
;
6722 face
->box_color
= face
->foreground
;
6723 face
->box_color_defaulted_p
= 1;
6724 face
->box_line_width
= 1;
6728 Lisp_Object keyword
, value
;
6730 keyword
= XCAR (box
);
6738 if (EQ (keyword
, QCline_width
))
6740 if (INTEGERP (value
) && XINT (value
) != 0)
6741 face
->box_line_width
= XINT (value
);
6743 else if (EQ (keyword
, QCcolor
))
6745 if (STRINGP (value
))
6747 face
->box_color
= load_color (f
, face
, value
,
6749 face
->use_box_color_for_shadows_p
= 1;
6752 else if (EQ (keyword
, QCstyle
))
6754 if (EQ (value
, Qreleased_button
))
6755 face
->box
= FACE_RAISED_BOX
;
6756 else if (EQ (value
, Qpressed_button
))
6757 face
->box
= FACE_SUNKEN_BOX
;
6762 /* Text underline, overline, strike-through. */
6764 if (EQ (attrs
[LFACE_UNDERLINE_INDEX
], Qt
))
6766 /* Use default color (same as foreground color). */
6767 face
->underline_p
= 1;
6768 face
->underline_defaulted_p
= 1;
6769 face
->underline_color
= 0;
6771 else if (STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]))
6773 /* Use specified color. */
6774 face
->underline_p
= 1;
6775 face
->underline_defaulted_p
= 0;
6776 face
->underline_color
6777 = load_color (f
, face
, attrs
[LFACE_UNDERLINE_INDEX
],
6778 LFACE_UNDERLINE_INDEX
);
6780 else if (NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
6782 face
->underline_p
= 0;
6783 face
->underline_defaulted_p
= 0;
6784 face
->underline_color
= 0;
6787 overline
= attrs
[LFACE_OVERLINE_INDEX
];
6788 if (STRINGP (overline
))
6790 face
->overline_color
6791 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
6792 LFACE_OVERLINE_INDEX
);
6793 face
->overline_p
= 1;
6795 else if (EQ (overline
, Qt
))
6797 face
->overline_color
= face
->foreground
;
6798 face
->overline_color_defaulted_p
= 1;
6799 face
->overline_p
= 1;
6802 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
6803 if (STRINGP (strike_through
))
6805 face
->strike_through_color
6806 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
6807 LFACE_STRIKE_THROUGH_INDEX
);
6808 face
->strike_through_p
= 1;
6810 else if (EQ (strike_through
, Qt
))
6812 face
->strike_through_color
= face
->foreground
;
6813 face
->strike_through_color_defaulted_p
= 1;
6814 face
->strike_through_p
= 1;
6817 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
6818 if (!NILP (stipple
))
6819 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
6821 xassert (FACE_SUITABLE_FOR_CHAR_P (face
, c
));
6823 #endif /* HAVE_WINDOW_SYSTEM */
6827 /* Map a specified color of face FACE on frame F to a tty color index.
6828 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
6829 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
6830 default foreground/background colors. */
6833 map_tty_color (f
, face
, idx
, defaulted
)
6836 enum lface_attribute_index idx
;
6839 Lisp_Object frame
, color
, def
;
6840 int foreground_p
= idx
== LFACE_FOREGROUND_INDEX
;
6841 unsigned long default_pixel
, default_other_pixel
, pixel
;
6843 xassert (idx
== LFACE_FOREGROUND_INDEX
|| idx
== LFACE_BACKGROUND_INDEX
);
6847 pixel
= default_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
6848 default_other_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
6852 pixel
= default_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
6853 default_other_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
6856 XSETFRAME (frame
, f
);
6857 color
= face
->lface
[idx
];
6860 && XSTRING (color
)->size
6861 && CONSP (Vtty_defined_color_alist
)
6862 && (def
= assq_no_quit (color
, call1 (Qtty_color_alist
, frame
)),
6865 /* Associations in tty-defined-color-alist are of the form
6866 (NAME INDEX R G B). We need the INDEX part. */
6867 pixel
= XINT (XCAR (XCDR (def
)));
6870 if (pixel
== default_pixel
&& STRINGP (color
))
6872 pixel
= load_color (f
, face
, color
, idx
);
6874 #if defined (MSDOS) || defined (WINDOWSNT)
6875 /* If the foreground of the default face is the default color,
6876 use the foreground color defined by the frame. */
6878 if (FRAME_MSDOS_P (f
))
6881 if (pixel
== default_pixel
6882 || pixel
== FACE_TTY_DEFAULT_COLOR
)
6885 pixel
= FRAME_FOREGROUND_PIXEL (f
);
6887 pixel
= FRAME_BACKGROUND_PIXEL (f
);
6888 face
->lface
[idx
] = tty_color_name (f
, pixel
);
6891 else if (pixel
== default_other_pixel
)
6894 pixel
= FRAME_BACKGROUND_PIXEL (f
);
6896 pixel
= FRAME_FOREGROUND_PIXEL (f
);
6897 face
->lface
[idx
] = tty_color_name (f
, pixel
);
6903 #endif /* MSDOS or WINDOWSNT */
6907 face
->foreground
= pixel
;
6909 face
->background
= pixel
;
6913 /* Realize the fully-specified face with attributes ATTRS in face
6914 cache CACHE for ASCII characters. Do it for TTY frame CACHE->f.
6915 Value is a pointer to the newly created realized face. */
6917 static struct face
*
6918 realize_tty_face (cache
, attrs
)
6919 struct face_cache
*cache
;
6924 int face_colors_defaulted
= 0;
6925 struct frame
*f
= cache
->f
;
6927 /* Frame must be a termcap frame. */
6928 xassert (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
));
6930 /* Allocate a new realized face. */
6931 face
= make_realized_face (attrs
);
6932 face
->font_name
= FRAME_MSDOS_P (cache
->f
) ? "ms-dos" : "tty";
6934 /* Map face attributes to TTY appearances. We map slant to
6935 dimmed text because we want italic text to appear differently
6936 and because dimmed text is probably used infrequently. */
6937 weight
= face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
6938 slant
= face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
6940 if (weight
> XLFD_WEIGHT_MEDIUM
)
6941 face
->tty_bold_p
= 1;
6942 if (weight
< XLFD_WEIGHT_MEDIUM
|| slant
!= XLFD_SLANT_ROMAN
)
6943 face
->tty_dim_p
= 1;
6944 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
6945 face
->tty_underline_p
= 1;
6946 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
6947 face
->tty_reverse_p
= 1;
6949 /* Map color names to color indices. */
6950 map_tty_color (f
, face
, LFACE_FOREGROUND_INDEX
, &face_colors_defaulted
);
6951 map_tty_color (f
, face
, LFACE_BACKGROUND_INDEX
, &face_colors_defaulted
);
6953 /* Swap colors if face is inverse-video. If the colors are taken
6954 from the frame colors, they are already inverted, since the
6955 frame-creation function calls x-handle-reverse-video. */
6956 if (face
->tty_reverse_p
&& !face_colors_defaulted
)
6958 unsigned long tem
= face
->foreground
;
6959 face
->foreground
= face
->background
;
6960 face
->background
= tem
;
6963 if (tty_suppress_bold_inverse_default_colors_p
6965 && face
->background
== FACE_TTY_DEFAULT_FG_COLOR
6966 && face
->foreground
== FACE_TTY_DEFAULT_BG_COLOR
)
6967 face
->tty_bold_p
= 0;
6973 DEFUN ("tty-suppress-bold-inverse-default-colors",
6974 Ftty_suppress_bold_inverse_default_colors
,
6975 Stty_suppress_bold_inverse_default_colors
, 1, 1, 0,
6976 doc
: /* Suppress/allow boldness of faces with inverse default colors.
6977 SUPPRESS non-nil means suppress it.
6978 This affects bold faces on TTYs whose foreground is the default background
6979 color of the display and whose background is the default foreground color.
6980 For such faces, the bold face attribute is ignored if this variable
6983 Lisp_Object suppress
;
6985 tty_suppress_bold_inverse_default_colors_p
= !NILP (suppress
);
6986 ++face_change_count
;
6992 /***********************************************************************
6994 ***********************************************************************/
6996 /* Return the ID of the face to use to display character CH with face
6997 property PROP on frame F in current_buffer. */
7000 compute_char_face (f
, ch
, prop
)
7007 if (NILP (current_buffer
->enable_multibyte_characters
))
7012 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7013 face_id
= FACE_FOR_CHAR (f
, face
, ch
);
7017 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
7018 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7019 bcopy (face
->lface
, attrs
, sizeof attrs
);
7020 merge_face_vector_with_property (f
, attrs
, prop
);
7021 face_id
= lookup_face (f
, attrs
);
7022 if (! ASCII_CHAR_P (ch
))
7024 face
= FACE_FROM_ID (f
, face_id
);
7025 face_id
= FACE_FOR_CHAR (f
, face
, ch
);
7032 /* Return the face ID associated with buffer position POS for
7033 displaying ASCII characters. Return in *ENDPTR the position at
7034 which a different face is needed, as far as text properties and
7035 overlays are concerned. W is a window displaying current_buffer.
7037 REGION_BEG, REGION_END delimit the region, so it can be
7040 LIMIT is a position not to scan beyond. That is to limit the time
7041 this function can take.
7043 If MOUSE is non-zero, use the character's mouse-face, not its face.
7045 The face returned is suitable for displaying ASCII characters. */
7048 face_at_buffer_position (w
, pos
, region_beg
, region_end
,
7049 endptr
, limit
, mouse
)
7052 int region_beg
, region_end
;
7057 struct frame
*f
= XFRAME (w
->frame
);
7058 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
7059 Lisp_Object prop
, position
;
7061 Lisp_Object
*overlay_vec
;
7064 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
7065 Lisp_Object limit1
, end
;
7066 struct face
*default_face
;
7068 /* W must display the current buffer. We could write this function
7069 to use the frame and buffer of W, but right now it doesn't. */
7070 /* xassert (XBUFFER (w->buffer) == current_buffer); */
7072 XSETFRAME (frame
, f
);
7073 XSETFASTINT (position
, pos
);
7076 if (pos
< region_beg
&& region_beg
< endpos
)
7077 endpos
= region_beg
;
7079 /* Get the `face' or `mouse_face' text property at POS, and
7080 determine the next position at which the property changes. */
7081 prop
= Fget_text_property (position
, propname
, w
->buffer
);
7082 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
7083 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
7085 endpos
= XINT (end
);
7087 /* Look at properties from overlays. */
7092 /* First try with room for 40 overlays. */
7094 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7095 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
7096 &next_overlay
, NULL
, 0);
7098 /* If there are more than 40, make enough space for all, and try
7100 if (noverlays
> len
)
7103 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7104 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
7105 &next_overlay
, NULL
, 0);
7108 if (next_overlay
< endpos
)
7109 endpos
= next_overlay
;
7114 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7116 /* Optimize common cases where we can use the default face. */
7119 && !(pos
>= region_beg
&& pos
< region_end
))
7120 return DEFAULT_FACE_ID
;
7122 /* Begin with attributes from the default face. */
7123 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
7125 /* Merge in attributes specified via text properties. */
7127 merge_face_vector_with_property (f
, attrs
, prop
);
7129 /* Now merge the overlay data. */
7130 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
7131 for (i
= 0; i
< noverlays
; i
++)
7136 prop
= Foverlay_get (overlay_vec
[i
], propname
);
7138 merge_face_vector_with_property (f
, attrs
, prop
);
7140 oend
= OVERLAY_END (overlay_vec
[i
]);
7141 oendpos
= OVERLAY_POSITION (oend
);
7142 if (oendpos
< endpos
)
7146 /* If in the region, merge in the region face. */
7147 if (pos
>= region_beg
&& pos
< region_end
)
7149 Lisp_Object region_face
= lface_from_face_name (f
, Qregion
, 0);
7150 merge_face_vectors (f
, XVECTOR (region_face
)->contents
, attrs
, Qnil
);
7152 if (region_end
< endpos
)
7153 endpos
= region_end
;
7158 /* Look up a realized face with the given face attributes,
7159 or realize a new one for ASCII characters. */
7160 return lookup_face (f
, attrs
);
7164 /* Compute the face at character position POS in Lisp string STRING on
7165 window W, for ASCII characters.
7167 If STRING is an overlay string, it comes from position BUFPOS in
7168 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
7169 not an overlay string. W must display the current buffer.
7170 REGION_BEG and REGION_END give the start and end positions of the
7171 region; both are -1 if no region is visible.
7173 BASE_FACE_ID is the id of a face to merge with. For strings coming
7174 from overlays or the `display' property it is the face at BUFPOS.
7176 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
7178 Set *ENDPTR to the next position where to check for faces in
7179 STRING; -1 if the face is constant from POS to the end of the
7182 Value is the id of the face to use. The face returned is suitable
7183 for displaying ASCII characters. */
7186 face_at_string_position (w
, string
, pos
, bufpos
, region_beg
,
7187 region_end
, endptr
, base_face_id
, mouse_p
)
7191 int region_beg
, region_end
;
7193 enum face_id base_face_id
;
7196 Lisp_Object prop
, position
, end
, limit
;
7197 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7198 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
7199 struct face
*base_face
;
7200 int multibyte_p
= STRING_MULTIBYTE (string
);
7201 Lisp_Object prop_name
= mouse_p
? Qmouse_face
: Qface
;
7203 /* Get the value of the face property at the current position within
7204 STRING. Value is nil if there is no face property. */
7205 XSETFASTINT (position
, pos
);
7206 prop
= Fget_text_property (position
, prop_name
, string
);
7208 /* Get the next position at which to check for faces. Value of end
7209 is nil if face is constant all the way to the end of the string.
7210 Otherwise it is a string position where to check faces next.
7211 Limit is the maximum position up to which to check for property
7212 changes in Fnext_single_property_change. Strings are usually
7213 short, so set the limit to the end of the string. */
7214 XSETFASTINT (limit
, XSTRING (string
)->size
);
7215 end
= Fnext_single_property_change (position
, prop_name
, string
, limit
);
7217 *endptr
= XFASTINT (end
);
7221 base_face
= FACE_FROM_ID (f
, base_face_id
);
7222 xassert (base_face
);
7224 /* Optimize the default case that there is no face property and we
7225 are not in the region. */
7227 && (base_face_id
!= DEFAULT_FACE_ID
7228 /* BUFPOS <= 0 means STRING is not an overlay string, so
7229 that the region doesn't have to be taken into account. */
7231 || bufpos
< region_beg
7232 || bufpos
>= region_end
)
7234 /* We can't realize faces for different charsets differently
7235 if we don't have fonts, so we can stop here if not working
7236 on a window-system frame. */
7237 || !FRAME_WINDOW_P (f
)
7238 || FACE_SUITABLE_FOR_CHAR_P (base_face
, 0)))
7239 return base_face
->id
;
7241 /* Begin with attributes from the base face. */
7242 bcopy (base_face
->lface
, attrs
, sizeof attrs
);
7244 /* Merge in attributes specified via text properties. */
7246 merge_face_vector_with_property (f
, attrs
, prop
);
7248 /* If in the region, merge in the region face. */
7250 && bufpos
>= region_beg
7251 && bufpos
< region_end
)
7253 Lisp_Object region_face
= lface_from_face_name (f
, Qregion
, 0);
7254 merge_face_vectors (f
, XVECTOR (region_face
)->contents
, attrs
, Qnil
);
7257 /* Look up a realized face with the given face attributes,
7258 or realize a new one for ASCII characters. */
7259 return lookup_face (f
, attrs
);
7264 /***********************************************************************
7266 ***********************************************************************/
7270 /* Print the contents of the realized face FACE to stderr. */
7273 dump_realized_face (face
)
7276 fprintf (stderr
, "ID: %d\n", face
->id
);
7277 #ifdef HAVE_X_WINDOWS
7278 fprintf (stderr
, "gc: %d\n", (int) face
->gc
);
7280 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
7282 XSTRING (face
->lface
[LFACE_FOREGROUND_INDEX
])->data
);
7283 fprintf (stderr
, "background: 0x%lx (%s)\n",
7285 XSTRING (face
->lface
[LFACE_BACKGROUND_INDEX
])->data
);
7286 fprintf (stderr
, "font_name: %s (%s)\n",
7288 XSTRING (face
->lface
[LFACE_FAMILY_INDEX
])->data
);
7289 #ifdef HAVE_X_WINDOWS
7290 fprintf (stderr
, "font = %p\n", face
->font
);
7292 fprintf (stderr
, "font_info_id = %d\n", face
->font_info_id
);
7293 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
7294 fprintf (stderr
, "underline: %d (%s)\n",
7296 XSTRING (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
]))->data
);
7297 fprintf (stderr
, "hash: %d\n", face
->hash
);
7301 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, doc
: /* */)
7309 fprintf (stderr
, "font selection order: ");
7310 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
7311 fprintf (stderr
, "%d ", font_sort_order
[i
]);
7312 fprintf (stderr
, "\n");
7314 fprintf (stderr
, "alternative fonts: ");
7315 debug_print (Vface_alternative_font_family_alist
);
7316 fprintf (stderr
, "\n");
7318 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
7319 Fdump_face (make_number (i
));
7325 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
7327 error ("Not a valid face");
7328 dump_realized_face (face
);
7335 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
7336 0, 0, 0, doc
: /* */)
7339 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
7340 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
7341 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
7345 #endif /* GLYPH_DEBUG != 0 */
7349 /***********************************************************************
7351 ***********************************************************************/
7356 Qface
= intern ("face");
7358 Qbitmap_spec_p
= intern ("bitmap-spec-p");
7359 staticpro (&Qbitmap_spec_p
);
7360 Qframe_update_face_colors
= intern ("frame-update-face-colors");
7361 staticpro (&Qframe_update_face_colors
);
7363 /* Lisp face attribute keywords. */
7364 QCfamily
= intern (":family");
7365 staticpro (&QCfamily
);
7366 QCheight
= intern (":height");
7367 staticpro (&QCheight
);
7368 QCweight
= intern (":weight");
7369 staticpro (&QCweight
);
7370 QCslant
= intern (":slant");
7371 staticpro (&QCslant
);
7372 QCunderline
= intern (":underline");
7373 staticpro (&QCunderline
);
7374 QCinverse_video
= intern (":inverse-video");
7375 staticpro (&QCinverse_video
);
7376 QCreverse_video
= intern (":reverse-video");
7377 staticpro (&QCreverse_video
);
7378 QCforeground
= intern (":foreground");
7379 staticpro (&QCforeground
);
7380 QCbackground
= intern (":background");
7381 staticpro (&QCbackground
);
7382 QCstipple
= intern (":stipple");;
7383 staticpro (&QCstipple
);
7384 QCwidth
= intern (":width");
7385 staticpro (&QCwidth
);
7386 QCfont
= intern (":font");
7387 staticpro (&QCfont
);
7388 QCfontset
= intern (":fontset");
7389 staticpro (&QCfontset
);
7390 QCbold
= intern (":bold");
7391 staticpro (&QCbold
);
7392 QCitalic
= intern (":italic");
7393 staticpro (&QCitalic
);
7394 QCoverline
= intern (":overline");
7395 staticpro (&QCoverline
);
7396 QCstrike_through
= intern (":strike-through");
7397 staticpro (&QCstrike_through
);
7398 QCbox
= intern (":box");
7400 QCinherit
= intern (":inherit");
7401 staticpro (&QCinherit
);
7403 /* Symbols used for Lisp face attribute values. */
7404 QCcolor
= intern (":color");
7405 staticpro (&QCcolor
);
7406 QCline_width
= intern (":line-width");
7407 staticpro (&QCline_width
);
7408 QCstyle
= intern (":style");
7409 staticpro (&QCstyle
);
7410 Qreleased_button
= intern ("released-button");
7411 staticpro (&Qreleased_button
);
7412 Qpressed_button
= intern ("pressed-button");
7413 staticpro (&Qpressed_button
);
7414 Qnormal
= intern ("normal");
7415 staticpro (&Qnormal
);
7416 Qultra_light
= intern ("ultra-light");
7417 staticpro (&Qultra_light
);
7418 Qextra_light
= intern ("extra-light");
7419 staticpro (&Qextra_light
);
7420 Qlight
= intern ("light");
7421 staticpro (&Qlight
);
7422 Qsemi_light
= intern ("semi-light");
7423 staticpro (&Qsemi_light
);
7424 Qsemi_bold
= intern ("semi-bold");
7425 staticpro (&Qsemi_bold
);
7426 Qbold
= intern ("bold");
7428 Qextra_bold
= intern ("extra-bold");
7429 staticpro (&Qextra_bold
);
7430 Qultra_bold
= intern ("ultra-bold");
7431 staticpro (&Qultra_bold
);
7432 Qoblique
= intern ("oblique");
7433 staticpro (&Qoblique
);
7434 Qitalic
= intern ("italic");
7435 staticpro (&Qitalic
);
7436 Qreverse_oblique
= intern ("reverse-oblique");
7437 staticpro (&Qreverse_oblique
);
7438 Qreverse_italic
= intern ("reverse-italic");
7439 staticpro (&Qreverse_italic
);
7440 Qultra_condensed
= intern ("ultra-condensed");
7441 staticpro (&Qultra_condensed
);
7442 Qextra_condensed
= intern ("extra-condensed");
7443 staticpro (&Qextra_condensed
);
7444 Qcondensed
= intern ("condensed");
7445 staticpro (&Qcondensed
);
7446 Qsemi_condensed
= intern ("semi-condensed");
7447 staticpro (&Qsemi_condensed
);
7448 Qsemi_expanded
= intern ("semi-expanded");
7449 staticpro (&Qsemi_expanded
);
7450 Qexpanded
= intern ("expanded");
7451 staticpro (&Qexpanded
);
7452 Qextra_expanded
= intern ("extra-expanded");
7453 staticpro (&Qextra_expanded
);
7454 Qultra_expanded
= intern ("ultra-expanded");
7455 staticpro (&Qultra_expanded
);
7456 Qbackground_color
= intern ("background-color");
7457 staticpro (&Qbackground_color
);
7458 Qforeground_color
= intern ("foreground-color");
7459 staticpro (&Qforeground_color
);
7460 Qunspecified
= intern ("unspecified");
7461 staticpro (&Qunspecified
);
7463 Qface_alias
= intern ("face-alias");
7464 staticpro (&Qface_alias
);
7465 Qdefault
= intern ("default");
7466 staticpro (&Qdefault
);
7467 Qtool_bar
= intern ("tool-bar");
7468 staticpro (&Qtool_bar
);
7469 Qregion
= intern ("region");
7470 staticpro (&Qregion
);
7471 Qfringe
= intern ("fringe");
7472 staticpro (&Qfringe
);
7473 Qheader_line
= intern ("header-line");
7474 staticpro (&Qheader_line
);
7475 Qscroll_bar
= intern ("scroll-bar");
7476 staticpro (&Qscroll_bar
);
7477 Qmenu
= intern ("menu");
7479 Qcursor
= intern ("cursor");
7480 staticpro (&Qcursor
);
7481 Qborder
= intern ("border");
7482 staticpro (&Qborder
);
7483 Qmouse
= intern ("mouse");
7484 staticpro (&Qmouse
);
7485 Qmode_line_inactive
= intern ("mode-line-inactive");
7486 staticpro (&Qmode_line_inactive
);
7487 Qtty_color_desc
= intern ("tty-color-desc");
7488 staticpro (&Qtty_color_desc
);
7489 Qtty_color_by_index
= intern ("tty-color-by-index");
7490 staticpro (&Qtty_color_by_index
);
7491 Qtty_color_alist
= intern ("tty-color-alist");
7492 staticpro (&Qtty_color_alist
);
7493 Qscalable_fonts_allowed
= intern ("scalable-fonts-allowed");
7494 staticpro (&Qscalable_fonts_allowed
);
7496 Vparam_value_alist
= Fcons (Fcons (Qnil
, Qnil
), Qnil
);
7497 staticpro (&Vparam_value_alist
);
7498 Vface_alternative_font_family_alist
= Qnil
;
7499 staticpro (&Vface_alternative_font_family_alist
);
7500 Vface_alternative_font_registry_alist
= Qnil
;
7501 staticpro (&Vface_alternative_font_registry_alist
);
7503 defsubr (&Sinternal_make_lisp_face
);
7504 defsubr (&Sinternal_lisp_face_p
);
7505 defsubr (&Sinternal_set_lisp_face_attribute
);
7506 #ifdef HAVE_WINDOW_SYSTEM
7507 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
7509 defsubr (&Scolor_gray_p
);
7510 defsubr (&Scolor_supported_p
);
7511 defsubr (&Sface_attribute_relative_p
);
7512 defsubr (&Smerge_face_attribute
);
7513 defsubr (&Sinternal_get_lisp_face_attribute
);
7514 defsubr (&Sinternal_lisp_face_attribute_values
);
7515 defsubr (&Sinternal_lisp_face_equal_p
);
7516 defsubr (&Sinternal_lisp_face_empty_p
);
7517 defsubr (&Sinternal_copy_lisp_face
);
7518 defsubr (&Sinternal_merge_in_global_face
);
7519 defsubr (&Sface_font
);
7520 defsubr (&Sframe_face_alist
);
7521 defsubr (&Sinternal_set_font_selection_order
);
7522 defsubr (&Sinternal_set_alternative_font_family_alist
);
7523 defsubr (&Sinternal_set_alternative_font_registry_alist
);
7524 defsubr (&Sface_attributes_as_vector
);
7526 defsubr (&Sdump_face
);
7527 defsubr (&Sshow_face_resources
);
7528 #endif /* GLYPH_DEBUG */
7529 defsubr (&Sclear_face_cache
);
7530 defsubr (&Stty_suppress_bold_inverse_default_colors
);
7532 #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS
7533 defsubr (&Sdump_colors
);
7536 DEFVAR_LISP ("font-list-limit", &Vfont_list_limit
,
7537 doc
: /* *Limit for font matching.
7538 If an integer > 0, font matching functions won't load more than
7539 that number of fonts when searching for a matching font. */);
7540 Vfont_list_limit
= make_number (DEFAULT_FONT_LIST_LIMIT
);
7542 DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults
,
7543 doc
: /* List of global face definitions (for internal use only.) */);
7544 Vface_new_frame_defaults
= Qnil
;
7546 DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple
,
7547 doc
: /* *Default stipple pattern used on monochrome displays.
7548 This stipple pattern is used on monochrome displays
7549 instead of shades of gray for a face background color.
7550 See `set-face-stipple' for possible values for this variable. */);
7551 Vface_default_stipple
= build_string ("gray3");
7553 DEFVAR_LISP ("tty-defined-color-alist", &Vtty_defined_color_alist
,
7554 doc
: /* An alist of defined terminal colors and their RGB values. */);
7555 Vtty_defined_color_alist
= Qnil
;
7557 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed
,
7558 doc
: /* Allowed scalable fonts.
7559 A value of nil means don't allow any scalable fonts.
7560 A value of t means allow any scalable font.
7561 Otherwise, value must be a list of regular expressions. A font may be
7562 scaled if its name matches a regular expression in the list.
7563 Note that if value is nil, a scalable font might still be used, if no
7564 other font of the appropriate family and registry is available. */);
7565 Vscalable_fonts_allowed
= Qnil
;
7567 DEFVAR_LISP ("face-ignored-fonts", &Vface_ignored_fonts
,
7568 doc
: /* List of ignored fonts.
7569 Each element is a regular expression that matches names of fonts to
7571 Vface_ignored_fonts
= Qnil
;
7573 DEFVAR_LISP ("face-resizing-fonts", &Vface_resizing_fonts
,
7574 doc
: /* Alist of fonts vs the resizing factors.
7575 Each element is a cons (FONT-NAME-PATTERN . RESIZING-RATIO), where
7576 FONT-NAME-PATTERN is a regular expression matching a font name, and
7577 RESIZING-RATIO is a floating point number to specify how much larger
7578 \(or smaller) font we should use. For instance, if a face requests
7579 a font of 10 point, we actually use a font of 10 * RESIZING-FACE points. */);
7581 #ifdef HAVE_WINDOW_SYSTEM
7582 defsubr (&Sbitmap_spec_p
);
7583 defsubr (&Sx_list_fonts
);
7584 defsubr (&Sinternal_face_x_get_resource
);
7585 defsubr (&Sx_family_fonts
);
7586 defsubr (&Sx_font_family_list
);
7587 #endif /* HAVE_WINDOW_SYSTEM */