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 or fontset pattern, or nil. This is a special attribute.
60 When this attribute is specified, the face uses a font opened by
61 that pattern as is. In addition, all the other font-related
62 attributes (1st thru 5th) are generated from the opened font name.
63 On the other hand, if one of the other font-related attributes are
64 specified, this attribute is set to nil. In that case, the face
65 doesn't inherit this attribute from the `default' face, and uses a
66 font determined by the other attributes (those may be inherited
67 from the `default' face).
69 15. A face name or list of face names from which to inherit attributes.
71 16. A specified average font width, which is invisible from Lisp,
72 and is used to ensure that a font specified on the command line,
73 for example, can be matched exactly.
75 Faces are frame-local by nature because Emacs allows to define the
76 same named face (face names are symbols) differently for different
77 frames. Each frame has an alist of face definitions for all named
78 faces. The value of a named face in such an alist is a Lisp vector
79 with the symbol `face' in slot 0, and a slot for each of the face
80 attributes mentioned above.
82 There is also a global face alist `Vface_new_frame_defaults'. Face
83 definitions from this list are used to initialize faces of newly
86 A face doesn't have to specify all attributes. Those not specified
87 have a value of `unspecified'. Faces specifying all attributes but
88 the 14th are called `fully-specified'.
93 The display style of a given character in the text is determined by
94 combining several faces. This process is called `face merging'.
95 Any aspect of the display style that isn't specified by overlays or
96 text properties is taken from the `default' face. Since it is made
97 sure that the default face is always fully-specified, face merging
98 always results in a fully-specified face.
103 After all face attributes for a character have been determined by
104 merging faces of that character, that face is `realized'. The
105 realization process maps face attributes to what is physically
106 available on the system where Emacs runs. The result is a
107 `realized face' in form of a struct face which is stored in the
108 face cache of the frame on which it was realized.
110 Face realization is done in the context of the character to display
111 because different fonts may be used for different characters. In
112 other words, for characters that have different font
113 specifications, different realized faces are needed to display
116 Font specification is done by fontsets. See the comment in
117 fontset.c for the details. In the current implementation, all ASCII
118 characters share the same font in a fontset.
120 Faces are at first realized for ASCII characters, and, at that
121 time, assigned a specific realized fontset. Hereafter, we call
122 such a face as `ASCII face'. When a face for a multibyte character
123 is realized, it inherits (thus shares) a fontset of an ASCII face
124 that has the same attributes other than font-related ones.
126 Thus, all realized face have a realized fontset.
131 Unibyte text (i.e. raw 8-bit characters) is displayed with the same
132 font as ASCII characters. That is because it is expected that
133 unibyte text users specify a font that is suitable both for ASCII
134 and raw 8-bit characters.
139 Font selection tries to find the best available matching font for a
140 given (character, face) combination.
142 If the face specifies a fontset name, that fontset determines a
143 pattern for fonts of the given character. If the face specifies a
144 font name or the other font-related attributes, a fontset is
145 realized from the default fontset. In that case, that
146 specification determines a pattern for ASCII characters and the
147 default fontset determines a pattern for multibyte characters.
149 Available fonts on the system on which Emacs runs are then matched
150 against the font pattern. The result of font selection is the best
151 match for the given face attributes in this font list.
153 Font selection can be influenced by the user.
155 1. The user can specify the relative importance he gives the face
156 attributes width, height, weight, and slant by setting
157 face-font-selection-order (faces.el) to a list of face attribute
158 names. The default is '(:width :height :weight :slant), and means
159 that font selection first tries to find a good match for the font
160 width specified by a face, then---within fonts with that
161 width---tries to find a best match for the specified font height,
164 2. Setting face-font-family-alternatives allows the user to
165 specify alternative font families to try if a family specified by a
168 3. Setting face-font-registry-alternatives allows the user to
169 specify all alternative font registries to try for a face
170 specifying a registry.
172 4. Setting face-ignored-fonts allows the user to ignore specific
176 Character composition.
178 Usually, the realization process is already finished when Emacs
179 actually reflects the desired glyph matrix on the screen. However,
180 on displaying a composition (sequence of characters to be composed
181 on the screen), a suitable font for the components of the
182 composition is selected and realized while drawing them on the
183 screen, i.e. the realization process is delayed but in principle
187 Initialization of basic faces.
189 The faces `default', `modeline' are considered `basic faces'.
190 When redisplay happens the first time for a newly created frame,
191 basic faces are realized for CHARSET_ASCII. Frame parameters are
192 used to fill in unspecified attributes of the default face. */
195 #include <sys/types.h>
196 #include <sys/stat.h>
200 #include "keyboard.h"
203 #ifdef HAVE_WINDOW_SYSTEM
205 #endif /* HAVE_WINDOW_SYSTEM */
207 #ifdef HAVE_X_WINDOWS
211 #include <Xm/XmStrDefs.h>
212 #endif /* USE_MOTIF */
213 #endif /* HAVE_X_WINDOWS */
222 /* Redefine X specifics to W32 equivalents to avoid cluttering the
223 code with #ifdef blocks. */
224 #undef FRAME_X_DISPLAY_INFO
225 #define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO
226 #define x_display_info w32_display_info
227 #define FRAME_X_FONT_TABLE FRAME_W32_FONT_TABLE
228 #define check_x check_w32
229 #define x_list_fonts w32_list_fonts
230 #define GCGraphicsExposures 0
231 /* For historic reasons, FONT_WIDTH refers to average width on W32,
232 not maximum as on X. Redefine here. */
234 #define FONT_WIDTH FONT_MAX_WIDTH
235 #endif /* WINDOWSNT */
239 #define x_display_info mac_display_info
240 #define check_x check_mac
244 #include "dispextern.h"
245 #include "blockinput.h"
247 #include "intervals.h"
249 #ifdef HAVE_X_WINDOWS
251 /* Compensate for a bug in Xos.h on some systems, on which it requires
252 time.h. On some such systems, Xos.h tries to redefine struct
253 timeval and struct timezone if USG is #defined while it is
256 #ifdef XOS_NEEDS_TIME_H
262 #else /* not XOS_NEEDS_TIME_H */
264 #endif /* not XOS_NEEDS_TIME_H */
266 #endif /* HAVE_X_WINDOWS */
271 #define abs(X) ((X) < 0 ? -(X) : (X))
273 /* Number of pt per inch (from the TeXbook). */
275 #define PT_PER_INCH 72.27
277 /* Non-zero if face attribute ATTR is unspecified. */
279 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified)
281 /* Value is the number of elements of VECTOR. */
283 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
285 /* Make a copy of string S on the stack using alloca. Value is a pointer
288 #define STRDUPA(S) strcpy ((char *) alloca (strlen ((S)) + 1), (S))
290 /* Make a copy of the contents of Lisp string S on the stack using
291 alloca. Value is a pointer to the copy. */
293 #define LSTRDUPA(S) STRDUPA (SDATA ((S)))
295 /* Size of hash table of realized faces in face caches (should be a
298 #define FACE_CACHE_BUCKETS_SIZE 1001
300 /* A definition of XColor for non-X frames. */
302 #ifndef HAVE_X_WINDOWS
307 unsigned short red
, green
, blue
;
313 #endif /* not HAVE_X_WINDOWS */
315 /* Keyword symbols used for face attribute names. */
317 Lisp_Object QCfamily
, QCheight
, QCweight
, QCslant
, QCunderline
;
318 Lisp_Object QCinverse_video
, QCforeground
, QCbackground
, QCstipple
;
319 Lisp_Object QCwidth
, QCfont
, QCbold
, QCitalic
;
320 Lisp_Object QCreverse_video
;
321 Lisp_Object QCoverline
, QCstrike_through
, QCbox
, QCinherit
;
323 /* Symbols used for attribute values. */
325 Lisp_Object Qnormal
, Qbold
, Qultra_light
, Qextra_light
, Qlight
;
326 Lisp_Object Qsemi_light
, Qsemi_bold
, Qextra_bold
, Qultra_bold
;
327 Lisp_Object Qoblique
, Qitalic
, Qreverse_oblique
, Qreverse_italic
;
328 Lisp_Object Qultra_condensed
, Qextra_condensed
, Qcondensed
;
329 Lisp_Object Qsemi_condensed
, Qsemi_expanded
, Qexpanded
, Qextra_expanded
;
330 Lisp_Object Qultra_expanded
;
331 Lisp_Object Qreleased_button
, Qpressed_button
;
332 Lisp_Object QCstyle
, QCcolor
, QCline_width
;
333 Lisp_Object Qunspecified
;
335 char unspecified_fg
[] = "unspecified-fg", unspecified_bg
[] = "unspecified-bg";
337 /* The name of the function to call when the background of the frame
338 has changed, frame_update_face_colors. */
340 Lisp_Object Qframe_update_face_colors
;
342 /* Names of basic faces. */
344 Lisp_Object Qdefault
, Qtool_bar
, Qregion
, Qfringe
;
345 Lisp_Object Qheader_line
, Qscroll_bar
, Qcursor
, Qborder
, Qmouse
, Qmenu
;
346 Lisp_Object Qmode_line_inactive
;
347 extern Lisp_Object Qmode_line
;
349 /* The symbol `face-alias'. A symbols having that property is an
350 alias for another face. Value of the property is the name of
353 Lisp_Object Qface_alias
;
355 /* Names of frame parameters related to faces. */
357 extern Lisp_Object Qscroll_bar_foreground
, Qscroll_bar_background
;
358 extern Lisp_Object Qborder_color
, Qcursor_color
, Qmouse_color
;
360 /* Default stipple pattern used on monochrome displays. This stipple
361 pattern is used on monochrome displays instead of shades of gray
362 for a face background color. See `set-face-stipple' for possible
363 values for this variable. */
365 Lisp_Object Vface_default_stipple
;
367 /* Alist of alternative font families. Each element is of the form
368 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
369 try FAMILY1, then FAMILY2, ... */
371 Lisp_Object Vface_alternative_font_family_alist
;
373 /* Alist of alternative font registries. Each element is of the form
374 (REGISTRY REGISTRY1 REGISTRY2...). If fonts of REGISTRY can't be
375 loaded, try REGISTRY1, then REGISTRY2, ... */
377 Lisp_Object Vface_alternative_font_registry_alist
;
379 /* Allowed scalable fonts. A value of nil means don't allow any
380 scalable fonts. A value of t means allow the use of any scalable
381 font. Otherwise, value must be a list of regular expressions. A
382 font may be scaled if its name matches a regular expression in the
385 Lisp_Object Vscalable_fonts_allowed
, Qscalable_fonts_allowed
;
387 /* List of regular expressions that matches names of fonts to ignore. */
389 Lisp_Object Vface_ignored_fonts
;
391 /* Maximum number of fonts to consider in font_list. If not an
392 integer > 0, DEFAULT_FONT_LIST_LIMIT is used instead. */
394 Lisp_Object Vfont_list_limit
;
395 #define DEFAULT_FONT_LIST_LIMIT 100
397 /* The symbols `foreground-color' and `background-color' which can be
398 used as part of a `face' property. This is for compatibility with
401 Lisp_Object Qforeground_color
, Qbackground_color
;
403 /* The symbols `face' and `mouse-face' used as text properties. */
406 extern Lisp_Object Qmouse_face
;
408 /* Error symbol for wrong_type_argument in load_pixmap. */
410 Lisp_Object Qbitmap_spec_p
;
412 /* Alist of global face definitions. Each element is of the form
413 (FACE . LFACE) where FACE is a symbol naming a face and LFACE
414 is a Lisp vector of face attributes. These faces are used
415 to initialize faces for new frames. */
417 Lisp_Object Vface_new_frame_defaults
;
419 /* The next ID to assign to Lisp faces. */
421 static int next_lface_id
;
423 /* A vector mapping Lisp face Id's to face names. */
425 static Lisp_Object
*lface_id_to_name
;
426 static int lface_id_to_name_size
;
428 /* TTY color-related functions (defined in tty-colors.el). */
430 Lisp_Object Qtty_color_desc
, Qtty_color_by_index
, Qtty_color_standard_values
;
432 /* The name of the function used to compute colors on TTYs. */
434 Lisp_Object Qtty_color_alist
;
436 /* An alist of defined terminal colors and their RGB values. */
438 Lisp_Object Vtty_defined_color_alist
;
440 /* Counter for calls to clear_face_cache. If this counter reaches
441 CLEAR_FONT_TABLE_COUNT, and a frame has more than
442 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
444 static int clear_font_table_count
;
445 #define CLEAR_FONT_TABLE_COUNT 100
446 #define CLEAR_FONT_TABLE_NFONTS 10
448 /* Non-zero means face attributes have been changed since the last
449 redisplay. Used in redisplay_internal. */
451 int face_change_count
;
453 /* Non-zero means don't display bold text if a face's foreground
454 and background colors are the inverse of the default colors of the
455 display. This is a kluge to suppress `bold black' foreground text
456 which is hard to read on an LCD monitor. */
458 int tty_suppress_bold_inverse_default_colors_p
;
460 /* A list of the form `((x . y))' used to avoid consing in
461 Finternal_set_lisp_face_attribute. */
463 static Lisp_Object Vparam_value_alist
;
465 /* The total number of colors currently allocated. */
468 static int ncolors_allocated
;
469 static int npixmaps_allocated
;
473 /* Non-zero means the definition of the `menu' face for new frames has
476 int menu_face_changed_default
;
479 /* Function prototypes. */
484 static void map_tty_color
P_ ((struct frame
*, struct face
*,
485 enum lface_attribute_index
, int *));
486 static Lisp_Object resolve_face_name
P_ ((Lisp_Object
));
487 static int may_use_scalable_font_p
P_ ((const char *));
488 static void set_font_frame_param
P_ ((Lisp_Object
, Lisp_Object
));
489 static int better_font_p
P_ ((int *, struct font_name
*, struct font_name
*,
491 static int x_face_list_fonts
P_ ((struct frame
*, char *,
492 struct font_name
*, int, int));
493 static int font_scalable_p
P_ ((struct font_name
*));
494 static int get_lface_attributes
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
*, int));
495 static int load_pixmap
P_ ((struct frame
*, Lisp_Object
, unsigned *, unsigned *));
496 static unsigned char *xstrlwr
P_ ((unsigned char *));
497 static void signal_error
P_ ((char *, Lisp_Object
));
498 static struct frame
*frame_or_selected_frame
P_ ((Lisp_Object
, int));
499 static void load_face_font
P_ ((struct frame
*, struct face
*, int));
500 static void load_face_colors
P_ ((struct frame
*, struct face
*, Lisp_Object
*));
501 static void free_face_colors
P_ ((struct frame
*, struct face
*));
502 static int face_color_gray_p
P_ ((struct frame
*, char *));
503 static char *build_font_name
P_ ((struct font_name
*));
504 static void free_font_names
P_ ((struct font_name
*, int));
505 static int sorted_font_list
P_ ((struct frame
*, char *,
506 int (*cmpfn
) P_ ((const void *, const void *)),
507 struct font_name
**));
508 static int font_list_1
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
509 Lisp_Object
, struct font_name
**));
510 static int font_list
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
511 Lisp_Object
, struct font_name
**));
512 static int try_font_list
P_ ((struct frame
*, Lisp_Object
*,
513 Lisp_Object
, Lisp_Object
, struct font_name
**));
514 static int try_alternative_families
P_ ((struct frame
*f
, Lisp_Object
,
515 Lisp_Object
, struct font_name
**));
516 static int cmp_font_names
P_ ((const void *, const void *));
517 static struct face
*realize_face
P_ ((struct face_cache
*, Lisp_Object
*, int,
518 struct face
*, int));
519 static struct face
*realize_x_face
P_ ((struct face_cache
*,
520 Lisp_Object
*, int, struct face
*));
521 static struct face
*realize_tty_face
P_ ((struct face_cache
*,
522 Lisp_Object
*, int));
523 static int realize_basic_faces
P_ ((struct frame
*));
524 static int realize_default_face
P_ ((struct frame
*));
525 static void realize_named_face
P_ ((struct frame
*, Lisp_Object
, int));
526 static int lface_fully_specified_p
P_ ((Lisp_Object
*));
527 static int lface_equal_p
P_ ((Lisp_Object
*, Lisp_Object
*));
528 static unsigned hash_string_case_insensitive
P_ ((Lisp_Object
));
529 static unsigned lface_hash
P_ ((Lisp_Object
*));
530 static int lface_same_font_attributes_p
P_ ((Lisp_Object
*, Lisp_Object
*));
531 static struct face_cache
*make_face_cache
P_ ((struct frame
*));
532 static void free_realized_face
P_ ((struct frame
*, struct face
*));
533 static void clear_face_gcs
P_ ((struct face_cache
*));
534 static void free_face_cache
P_ ((struct face_cache
*));
535 static int face_numeric_weight
P_ ((Lisp_Object
));
536 static int face_numeric_slant
P_ ((Lisp_Object
));
537 static int face_numeric_swidth
P_ ((Lisp_Object
));
538 static int face_fontset
P_ ((Lisp_Object
*));
539 static char *choose_face_font
P_ ((struct frame
*, Lisp_Object
*, int, int));
540 static void merge_face_vectors
P_ ((struct frame
*, Lisp_Object
*, Lisp_Object
*, Lisp_Object
));
541 static void merge_face_inheritance
P_ ((struct frame
*f
, Lisp_Object
,
542 Lisp_Object
*, Lisp_Object
));
543 static void merge_face_vector_with_property
P_ ((struct frame
*, Lisp_Object
*,
545 static int set_lface_from_font_name
P_ ((struct frame
*, Lisp_Object
,
546 Lisp_Object
, int, int));
547 static Lisp_Object lface_from_face_name
P_ ((struct frame
*, Lisp_Object
, int));
548 static struct face
*make_realized_face
P_ ((Lisp_Object
*));
549 static void free_realized_faces
P_ ((struct face_cache
*));
550 static char *best_matching_font
P_ ((struct frame
*, Lisp_Object
*,
551 struct font_name
*, int, int));
552 static void cache_face
P_ ((struct face_cache
*, struct face
*, unsigned));
553 static void uncache_face
P_ ((struct face_cache
*, struct face
*));
554 static int xlfd_numeric_slant
P_ ((struct font_name
*));
555 static int xlfd_numeric_weight
P_ ((struct font_name
*));
556 static int xlfd_numeric_swidth
P_ ((struct font_name
*));
557 static Lisp_Object xlfd_symbolic_slant
P_ ((struct font_name
*));
558 static Lisp_Object xlfd_symbolic_weight
P_ ((struct font_name
*));
559 static Lisp_Object xlfd_symbolic_swidth
P_ ((struct font_name
*));
560 static int xlfd_fixed_p
P_ ((struct font_name
*));
561 static int xlfd_numeric_value
P_ ((struct table_entry
*, int, struct font_name
*,
563 static Lisp_Object xlfd_symbolic_value
P_ ((struct table_entry
*, int,
564 struct font_name
*, int,
566 static struct table_entry
*xlfd_lookup_field_contents
P_ ((struct table_entry
*, int,
567 struct font_name
*, int));
569 #ifdef HAVE_WINDOW_SYSTEM
571 static int split_font_name
P_ ((struct frame
*, struct font_name
*, int));
572 static int xlfd_point_size
P_ ((struct frame
*, struct font_name
*));
573 static void sort_fonts
P_ ((struct frame
*, struct font_name
*, int,
574 int (*cmpfn
) P_ ((const void *, const void *))));
575 static GC x_create_gc
P_ ((struct frame
*, unsigned long, XGCValues
*));
576 static void x_free_gc
P_ ((struct frame
*, GC
));
577 static void clear_font_table
P_ ((struct x_display_info
*));
580 extern Lisp_Object w32_list_fonts
P_ ((struct frame
*, Lisp_Object
, int, int));
581 #endif /* WINDOWSNT */
584 static void x_update_menu_appearance
P_ ((struct frame
*));
586 extern void free_frame_menubar
P_ ((struct frame
*));
587 #endif /* USE_X_TOOLKIT */
589 #endif /* HAVE_WINDOW_SYSTEM */
592 /***********************************************************************
594 ***********************************************************************/
596 #ifdef HAVE_X_WINDOWS
598 #ifdef DEBUG_X_COLORS
600 /* The following is a poor mans infrastructure for debugging X color
601 allocation problems on displays with PseudoColor-8. Some X servers
602 like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement
603 color reference counts completely so that they don't signal an
604 error when a color is freed whose reference count is already 0.
605 Other X servers do. To help me debug this, the following code
606 implements a simple reference counting schema of its own, for a
607 single display/screen. --gerd. */
609 /* Reference counts for pixel colors. */
611 int color_count
[256];
613 /* Register color PIXEL as allocated. */
616 register_color (pixel
)
619 xassert (pixel
< 256);
620 ++color_count
[pixel
];
624 /* Register color PIXEL as deallocated. */
627 unregister_color (pixel
)
630 xassert (pixel
< 256);
631 if (color_count
[pixel
] > 0)
632 --color_count
[pixel
];
638 /* Register N colors from PIXELS as deallocated. */
641 unregister_colors (pixels
, n
)
642 unsigned long *pixels
;
646 for (i
= 0; i
< n
; ++i
)
647 unregister_color (pixels
[i
]);
651 DEFUN ("dump-colors", Fdump_colors
, Sdump_colors
, 0, 0, 0,
652 doc
: /* Dump currently allocated colors to stderr. */)
657 fputc ('\n', stderr
);
659 for (i
= n
= 0; i
< sizeof color_count
/ sizeof color_count
[0]; ++i
)
662 fprintf (stderr
, "%3d: %5d", i
, color_count
[i
]);
665 fputc ('\n', stderr
);
667 fputc ('\t', stderr
);
671 fputc ('\n', stderr
);
675 #endif /* DEBUG_X_COLORS */
678 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
679 color values. Interrupt input must be blocked when this function
683 x_free_colors (f
, pixels
, npixels
)
685 unsigned long *pixels
;
688 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
690 /* If display has an immutable color map, freeing colors is not
691 necessary and some servers don't allow it. So don't do it. */
692 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
694 #ifdef DEBUG_X_COLORS
695 unregister_colors (pixels
, npixels
);
697 XFreeColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
703 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel
704 color values. Interrupt input must be blocked when this function
708 x_free_dpy_colors (dpy
, screen
, cmap
, pixels
, npixels
)
712 unsigned long *pixels
;
715 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
716 int class = dpyinfo
->visual
->class;
718 /* If display has an immutable color map, freeing colors is not
719 necessary and some servers don't allow it. So don't do it. */
720 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
722 #ifdef DEBUG_X_COLORS
723 unregister_colors (pixels
, npixels
);
725 XFreeColors (dpy
, cmap
, pixels
, npixels
, 0);
730 /* Create and return a GC for use on frame F. GC values and mask
731 are given by XGCV and MASK. */
734 x_create_gc (f
, mask
, xgcv
)
741 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
748 /* Free GC which was used on frame F. */
756 xassert (--ngcs
>= 0);
757 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
761 #endif /* HAVE_X_WINDOWS */
764 /* W32 emulation of GCs */
767 x_create_gc (f
, mask
, xgcv
)
774 gc
= XCreateGC (NULL
, FRAME_W32_WINDOW (f
), mask
, xgcv
);
781 /* Free GC which was used on frame F. */
789 xassert (--ngcs
>= 0);
794 #endif /* WINDOWSNT */
797 /* Mac OS emulation of GCs */
799 extern XGCValues
*XCreateGC (void *, Window
, unsigned long, XGCValues
*);
802 x_create_gc (f
, mask
, xgcv
)
808 gc
= XCreateGC (FRAME_MAC_DISPLAY (f
), FRAME_MAC_WINDOW (f
), mask
, xgcv
);
817 XFreeGC (FRAME_MAC_DISPLAY (f
), gc
);
822 /* Like stricmp. Used to compare parts of font names which are in
827 const unsigned char *s1
, *s2
;
831 unsigned char c1
= tolower (*s1
);
832 unsigned char c2
= tolower (*s2
);
834 return c1
< c2
? -1 : 1;
839 return *s2
== 0 ? 0 : -1;
844 /* Like strlwr, which might not always be available. */
846 static unsigned char *
850 unsigned char *p
= s
;
859 /* Signal `error' with message S, and additional argument ARG. */
862 signal_error (s
, arg
)
866 Fsignal (Qerror
, Fcons (build_string (s
), Fcons (arg
, Qnil
)));
870 /* If FRAME is nil, return a pointer to the selected frame.
871 Otherwise, check that FRAME is a live frame, and return a pointer
872 to it. NPARAM is the parameter number of FRAME, for
873 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
874 Lisp function definitions. */
876 static INLINE
struct frame
*
877 frame_or_selected_frame (frame
, nparam
)
882 frame
= selected_frame
;
884 CHECK_LIVE_FRAME (frame
);
885 return XFRAME (frame
);
889 /***********************************************************************
891 ***********************************************************************/
893 /* Initialize face cache and basic faces for frame F. */
899 /* Make a face cache, if F doesn't have one. */
900 if (FRAME_FACE_CACHE (f
) == NULL
)
901 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
903 #ifdef HAVE_WINDOW_SYSTEM
904 /* Make the image cache. */
905 if (FRAME_WINDOW_P (f
))
907 if (FRAME_X_IMAGE_CACHE (f
) == NULL
)
908 FRAME_X_IMAGE_CACHE (f
) = make_image_cache ();
909 ++FRAME_X_IMAGE_CACHE (f
)->refcount
;
911 #endif /* HAVE_WINDOW_SYSTEM */
913 /* Realize basic faces. Must have enough information in frame
914 parameters to realize basic faces at this point. */
915 #ifdef HAVE_X_WINDOWS
916 if (!FRAME_X_P (f
) || FRAME_X_WINDOW (f
))
919 if (!FRAME_WINDOW_P (f
) || FRAME_W32_WINDOW (f
))
922 if (!FRAME_MAC_P (f
) || FRAME_MAC_WINDOW (f
))
924 if (!realize_basic_faces (f
))
929 /* Free face cache of frame F. Called from Fdelete_frame. */
935 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
939 free_face_cache (face_cache
);
940 FRAME_FACE_CACHE (f
) = NULL
;
943 #ifdef HAVE_WINDOW_SYSTEM
944 if (FRAME_WINDOW_P (f
))
946 struct image_cache
*image_cache
= FRAME_X_IMAGE_CACHE (f
);
949 --image_cache
->refcount
;
950 if (image_cache
->refcount
== 0)
951 free_image_cache (f
);
954 #endif /* HAVE_WINDOW_SYSTEM */
958 /* Clear face caches, and recompute basic faces for frame F. Call
959 this after changing frame parameters on which those faces depend,
960 or when realized faces have been freed due to changing attributes
964 recompute_basic_faces (f
)
967 if (FRAME_FACE_CACHE (f
))
969 clear_face_cache (0);
970 if (!realize_basic_faces (f
))
976 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
977 try to free unused fonts, too. */
980 clear_face_cache (clear_fonts_p
)
983 #ifdef HAVE_WINDOW_SYSTEM
984 Lisp_Object tail
, frame
;
988 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
990 struct x_display_info
*dpyinfo
;
992 /* Fonts are common for frames on one display, i.e. on
994 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
995 if (dpyinfo
->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
996 clear_font_table (dpyinfo
);
998 /* From time to time see if we can unload some fonts. This also
999 frees all realized faces on all frames. Fonts needed by
1000 faces will be loaded again when faces are realized again. */
1001 clear_font_table_count
= 0;
1003 FOR_EACH_FRAME (tail
, frame
)
1005 struct frame
*f
= XFRAME (frame
);
1006 if (FRAME_WINDOW_P (f
)
1007 && FRAME_X_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
1008 free_all_realized_faces (frame
);
1013 /* Clear GCs of realized faces. */
1014 FOR_EACH_FRAME (tail
, frame
)
1017 if (FRAME_WINDOW_P (f
))
1019 clear_face_gcs (FRAME_FACE_CACHE (f
));
1020 clear_image_cache (f
, 0);
1024 #endif /* HAVE_WINDOW_SYSTEM */
1028 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
1029 doc
: /* Clear face caches on all frames.
1030 Optional THOROUGHLY non-nil means try to free unused fonts, too. */)
1032 Lisp_Object thoroughly
;
1034 clear_face_cache (!NILP (thoroughly
));
1035 ++face_change_count
;
1036 ++windows_or_buffers_changed
;
1042 #ifdef HAVE_WINDOW_SYSTEM
1045 /* Remove fonts from the font table of DPYINFO except for the default
1046 ASCII fonts of frames on that display. Called from clear_face_cache
1047 from time to time. */
1050 clear_font_table (dpyinfo
)
1051 struct x_display_info
*dpyinfo
;
1055 /* Free those fonts that are not used by frames on DPYINFO. */
1056 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
1058 struct font_info
*font_info
= dpyinfo
->font_table
+ i
;
1059 Lisp_Object tail
, frame
;
1061 /* Check if slot is already free. */
1062 if (font_info
->name
== NULL
)
1065 /* Don't free a default font of some frame. */
1066 FOR_EACH_FRAME (tail
, frame
)
1068 struct frame
*f
= XFRAME (frame
);
1069 if (FRAME_WINDOW_P (f
)
1070 && font_info
->font
== FRAME_FONT (f
))
1078 if (font_info
->full_name
!= font_info
->name
)
1079 xfree (font_info
->full_name
);
1080 xfree (font_info
->name
);
1082 /* Free the font. */
1084 #ifdef HAVE_X_WINDOWS
1085 XFreeFont (dpyinfo
->display
, font_info
->font
);
1088 w32_unload_font (dpyinfo
, font_info
->font
);
1092 /* Mark font table slot free. */
1093 font_info
->font
= NULL
;
1094 font_info
->name
= font_info
->full_name
= NULL
;
1098 #endif /* HAVE_WINDOW_SYSTEM */
1102 /***********************************************************************
1104 ***********************************************************************/
1106 #ifdef HAVE_WINDOW_SYSTEM
1108 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
1109 doc
: /* Value is non-nil if OBJECT is a valid bitmap specification.
1110 A bitmap specification is either a string, a file name, or a list
1111 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
1112 HEIGHT is its height, and DATA is a string containing the bits of
1113 the pixmap. Bits are stored row by row, each row occupies
1114 \(WIDTH + 7)/8 bytes. */)
1120 if (STRINGP (object
))
1121 /* If OBJECT is a string, it's a file name. */
1123 else if (CONSP (object
))
1125 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
1126 HEIGHT must be integers > 0, and DATA must be string large
1127 enough to hold a bitmap of the specified size. */
1128 Lisp_Object width
, height
, data
;
1130 height
= width
= data
= Qnil
;
1134 width
= XCAR (object
);
1135 object
= XCDR (object
);
1138 height
= XCAR (object
);
1139 object
= XCDR (object
);
1141 data
= XCAR (object
);
1145 if (NATNUMP (width
) && NATNUMP (height
) && STRINGP (data
))
1147 int bytes_per_row
= ((XFASTINT (width
) + BITS_PER_CHAR
- 1)
1149 if (SBYTES (data
) >= bytes_per_row
* XINT (height
))
1154 return pixmap_p
? Qt
: Qnil
;
1158 /* Load a bitmap according to NAME (which is either a file name or a
1159 pixmap spec) for use on frame F. Value is the bitmap_id (see
1160 xfns.c). If NAME is nil, return with a bitmap id of zero. If
1161 bitmap cannot be loaded, display a message saying so, and return
1162 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
1163 if these pointers are not null. */
1166 load_pixmap (f
, name
, w_ptr
, h_ptr
)
1169 unsigned int *w_ptr
, *h_ptr
;
1177 tem
= Fbitmap_spec_p (name
);
1179 wrong_type_argument (Qbitmap_spec_p
, name
);
1184 /* Decode a bitmap spec into a bitmap. */
1189 w
= XINT (Fcar (name
));
1190 h
= XINT (Fcar (Fcdr (name
)));
1191 bits
= Fcar (Fcdr (Fcdr (name
)));
1193 bitmap_id
= x_create_bitmap_from_data (f
, SDATA (bits
),
1198 /* It must be a string -- a file name. */
1199 bitmap_id
= x_create_bitmap_from_file (f
, name
);
1205 add_to_log ("Invalid or undefined bitmap %s", name
, Qnil
);
1216 ++npixmaps_allocated
;
1219 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
1222 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
1228 #endif /* HAVE_WINDOW_SYSTEM */
1232 /***********************************************************************
1234 ***********************************************************************/
1236 #ifdef HAVE_WINDOW_SYSTEM
1238 /* Update the line_height of frame F. Return non-zero if line height
1242 frame_update_line_height (f
)
1245 int line_height
, changed_p
;
1247 line_height
= FONT_HEIGHT (FRAME_FONT (f
));
1248 changed_p
= line_height
!= FRAME_LINE_HEIGHT (f
);
1249 FRAME_LINE_HEIGHT (f
) = line_height
;
1253 #endif /* HAVE_WINDOW_SYSTEM */
1256 /***********************************************************************
1258 ***********************************************************************/
1260 #ifdef HAVE_WINDOW_SYSTEM
1262 /* Load font of face FACE which is used on frame F to display
1263 character C. The name of the font to load is determined by lface
1264 and fontset of FACE. */
1267 load_face_font (f
, face
, c
)
1272 struct font_info
*font_info
= NULL
;
1275 face
->font_info_id
= -1;
1278 font_name
= choose_face_font (f
, face
->lface
, face
->fontset
, c
);
1283 font_info
= FS_LOAD_FACE_FONT (f
, c
, font_name
, face
);
1288 face
->font_info_id
= font_info
->font_idx
;
1289 face
->font
= font_info
->font
;
1290 face
->font_name
= font_info
->full_name
;
1293 x_free_gc (f
, face
->gc
);
1298 add_to_log ("Unable to load font %s",
1299 build_string (font_name
), Qnil
);
1303 #endif /* HAVE_WINDOW_SYSTEM */
1307 /***********************************************************************
1309 ***********************************************************************/
1311 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
1312 RGB_LIST should contain (at least) 3 lisp integers.
1313 Return 0 if there's a problem with RGB_LIST, otherwise return 1. */
1316 parse_rgb_list (rgb_list
, color
)
1317 Lisp_Object rgb_list
;
1320 #define PARSE_RGB_LIST_FIELD(field) \
1321 if (CONSP (rgb_list) && INTEGERP (XCAR (rgb_list))) \
1323 color->field = XINT (XCAR (rgb_list)); \
1324 rgb_list = XCDR (rgb_list); \
1329 PARSE_RGB_LIST_FIELD (red
);
1330 PARSE_RGB_LIST_FIELD (green
);
1331 PARSE_RGB_LIST_FIELD (blue
);
1337 /* Lookup on frame F the color described by the lisp string COLOR.
1338 The resulting tty color is returned in TTY_COLOR; if STD_COLOR is
1339 non-zero, then the `standard' definition of the same color is
1343 tty_lookup_color (f
, color
, tty_color
, std_color
)
1346 XColor
*tty_color
, *std_color
;
1348 Lisp_Object frame
, color_desc
;
1350 if (!STRINGP (color
) || NILP (Ffboundp (Qtty_color_desc
)))
1353 XSETFRAME (frame
, f
);
1355 color_desc
= call2 (Qtty_color_desc
, color
, frame
);
1356 if (CONSP (color_desc
) && CONSP (XCDR (color_desc
)))
1360 if (! INTEGERP (XCAR (XCDR (color_desc
))))
1363 tty_color
->pixel
= XINT (XCAR (XCDR (color_desc
)));
1365 rgb
= XCDR (XCDR (color_desc
));
1366 if (! parse_rgb_list (rgb
, tty_color
))
1369 /* Should we fill in STD_COLOR too? */
1372 /* Default STD_COLOR to the same as TTY_COLOR. */
1373 *std_color
= *tty_color
;
1375 /* Do a quick check to see if the returned descriptor is
1376 actually _exactly_ equal to COLOR, otherwise we have to
1377 lookup STD_COLOR separately. If it's impossible to lookup
1378 a standard color, we just give up and use TTY_COLOR. */
1379 if ((!STRINGP (XCAR (color_desc
))
1380 || NILP (Fstring_equal (color
, XCAR (color_desc
))))
1381 && !NILP (Ffboundp (Qtty_color_standard_values
)))
1383 /* Look up STD_COLOR separately. */
1384 rgb
= call1 (Qtty_color_standard_values
, color
);
1385 if (! parse_rgb_list (rgb
, std_color
))
1392 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
1393 /* We were called early during startup, and the colors are not
1394 yet set up in tty-defined-color-alist. Don't return a failure
1395 indication, since this produces the annoying "Unable to
1396 load color" messages in the *Messages* buffer. */
1399 /* tty-color-desc seems to have returned a bad value. */
1403 /* A version of defined_color for non-X frames. */
1406 tty_defined_color (f
, color_name
, color_def
, alloc
)
1415 color_def
->pixel
= FACE_TTY_DEFAULT_COLOR
;
1417 color_def
->blue
= 0;
1418 color_def
->green
= 0;
1421 status
= tty_lookup_color (f
, build_string (color_name
), color_def
, 0);
1423 if (color_def
->pixel
== FACE_TTY_DEFAULT_COLOR
&& *color_name
)
1425 if (strcmp (color_name
, "unspecified-fg") == 0)
1426 color_def
->pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
1427 else if (strcmp (color_name
, "unspecified-bg") == 0)
1428 color_def
->pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
1431 if (color_def
->pixel
!= FACE_TTY_DEFAULT_COLOR
)
1438 /* Decide if color named COLOR_NAME is valid for the display
1439 associated with the frame F; if so, return the rgb values in
1440 COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell.
1442 This does the right thing for any type of frame. */
1445 defined_color (f
, color_name
, color_def
, alloc
)
1451 if (!FRAME_WINDOW_P (f
))
1452 return tty_defined_color (f
, color_name
, color_def
, alloc
);
1453 #ifdef HAVE_X_WINDOWS
1454 else if (FRAME_X_P (f
))
1455 return x_defined_color (f
, color_name
, color_def
, alloc
);
1458 else if (FRAME_W32_P (f
))
1459 return w32_defined_color (f
, color_name
, color_def
, alloc
);
1462 else if (FRAME_MAC_P (f
))
1463 return mac_defined_color (f
, color_name
, color_def
, alloc
);
1470 /* Given the index IDX of a tty color on frame F, return its name, a
1474 tty_color_name (f
, idx
)
1478 if (idx
>= 0 && !NILP (Ffboundp (Qtty_color_by_index
)))
1481 Lisp_Object coldesc
;
1483 XSETFRAME (frame
, f
);
1484 coldesc
= call2 (Qtty_color_by_index
, make_number (idx
), frame
);
1486 if (!NILP (coldesc
))
1487 return XCAR (coldesc
);
1490 /* We can have an MSDOG frame under -nw for a short window of
1491 opportunity before internal_terminal_init is called. DTRT. */
1492 if (FRAME_MSDOS_P (f
) && !inhibit_window_system
)
1493 return msdos_stdcolor_name (idx
);
1496 if (idx
== FACE_TTY_DEFAULT_FG_COLOR
)
1497 return build_string (unspecified_fg
);
1498 if (idx
== FACE_TTY_DEFAULT_BG_COLOR
)
1499 return build_string (unspecified_bg
);
1502 return vga_stdcolor_name (idx
);
1505 return Qunspecified
;
1509 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1510 black) on frame F. The algorithm is taken from 20.2 faces.el. */
1513 face_color_gray_p (f
, color_name
)
1520 if (defined_color (f
, color_name
, &color
, 0))
1521 gray_p
= ((abs (color
.red
- color
.green
)
1522 < max (color
.red
, color
.green
) / 20)
1523 && (abs (color
.green
- color
.blue
)
1524 < max (color
.green
, color
.blue
) / 20)
1525 && (abs (color
.blue
- color
.red
)
1526 < max (color
.blue
, color
.red
) / 20));
1534 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1535 BACKGROUND_P non-zero means the color will be used as background
1539 face_color_supported_p (f
, color_name
, background_p
)
1547 XSETFRAME (frame
, f
);
1548 return (FRAME_WINDOW_P (f
)
1549 ? (!NILP (Fxw_display_color_p (frame
))
1550 || xstricmp (color_name
, "black") == 0
1551 || xstricmp (color_name
, "white") == 0
1553 && face_color_gray_p (f
, color_name
))
1554 || (!NILP (Fx_display_grayscale_p (frame
))
1555 && face_color_gray_p (f
, color_name
)))
1556 : tty_defined_color (f
, color_name
, ¬_used
, 0));
1560 DEFUN ("color-gray-p", Fcolor_gray_p
, Scolor_gray_p
, 1, 2, 0,
1561 doc
: /* Return non-nil if COLOR is a shade of gray (or white or black).
1562 FRAME specifies the frame and thus the display for interpreting COLOR.
1563 If FRAME is nil or omitted, use the selected frame. */)
1565 Lisp_Object color
, frame
;
1569 CHECK_FRAME (frame
);
1570 CHECK_STRING (color
);
1572 return face_color_gray_p (f
, SDATA (color
)) ? Qt
: Qnil
;
1576 DEFUN ("color-supported-p", Fcolor_supported_p
,
1577 Scolor_supported_p
, 1, 3, 0,
1578 doc
: /* Return non-nil if COLOR can be displayed on FRAME.
1579 BACKGROUND-P non-nil means COLOR is used as a background.
1580 If FRAME is nil or omitted, use the selected frame.
1581 COLOR must be a valid color name. */)
1582 (color
, frame
, background_p
)
1583 Lisp_Object frame
, color
, background_p
;
1587 CHECK_FRAME (frame
);
1588 CHECK_STRING (color
);
1590 if (face_color_supported_p (f
, SDATA (color
), !NILP (background_p
)))
1596 /* Load color with name NAME for use by face FACE on frame F.
1597 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1598 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1599 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1600 pixel color. If color cannot be loaded, display a message, and
1601 return the foreground, background or underline color of F, but
1602 record that fact in flags of the face so that we don't try to free
1606 load_color (f
, face
, name
, target_index
)
1610 enum lface_attribute_index target_index
;
1614 xassert (STRINGP (name
));
1615 xassert (target_index
== LFACE_FOREGROUND_INDEX
1616 || target_index
== LFACE_BACKGROUND_INDEX
1617 || target_index
== LFACE_UNDERLINE_INDEX
1618 || target_index
== LFACE_OVERLINE_INDEX
1619 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1620 || target_index
== LFACE_BOX_INDEX
);
1622 /* if the color map is full, defined_color will return a best match
1623 to the values in an existing cell. */
1624 if (!defined_color (f
, SDATA (name
), &color
, 1))
1626 add_to_log ("Unable to load color \"%s\"", name
, Qnil
);
1628 switch (target_index
)
1630 case LFACE_FOREGROUND_INDEX
:
1631 face
->foreground_defaulted_p
= 1;
1632 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1635 case LFACE_BACKGROUND_INDEX
:
1636 face
->background_defaulted_p
= 1;
1637 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1640 case LFACE_UNDERLINE_INDEX
:
1641 face
->underline_defaulted_p
= 1;
1642 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1645 case LFACE_OVERLINE_INDEX
:
1646 face
->overline_color_defaulted_p
= 1;
1647 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1650 case LFACE_STRIKE_THROUGH_INDEX
:
1651 face
->strike_through_color_defaulted_p
= 1;
1652 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1655 case LFACE_BOX_INDEX
:
1656 face
->box_color_defaulted_p
= 1;
1657 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1666 ++ncolors_allocated
;
1673 #ifdef HAVE_WINDOW_SYSTEM
1675 /* Load colors for face FACE which is used on frame F. Colors are
1676 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1677 of ATTRS. If the background color specified is not supported on F,
1678 try to emulate gray colors with a stipple from Vface_default_stipple. */
1681 load_face_colors (f
, face
, attrs
)
1688 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1689 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1691 /* Swap colors if face is inverse-video. */
1692 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1700 /* Check for support for foreground, not for background because
1701 face_color_supported_p is smart enough to know that grays are
1702 "supported" as background because we are supposed to use stipple
1704 if (!face_color_supported_p (f
, SDATA (bg
), 0)
1705 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1707 x_destroy_bitmap (f
, face
->stipple
);
1708 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1709 &face
->pixmap_w
, &face
->pixmap_h
);
1712 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1713 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1717 /* Free color PIXEL on frame F. */
1720 unload_color (f
, pixel
)
1722 unsigned long pixel
;
1724 #ifdef HAVE_X_WINDOWS
1728 x_free_colors (f
, &pixel
, 1);
1735 /* Free colors allocated for FACE. */
1738 free_face_colors (f
, face
)
1742 #ifdef HAVE_X_WINDOWS
1743 if (face
->colors_copied_bitwise_p
)
1748 if (!face
->foreground_defaulted_p
)
1750 x_free_colors (f
, &face
->foreground
, 1);
1751 IF_DEBUG (--ncolors_allocated
);
1754 if (!face
->background_defaulted_p
)
1756 x_free_colors (f
, &face
->background
, 1);
1757 IF_DEBUG (--ncolors_allocated
);
1760 if (face
->underline_p
1761 && !face
->underline_defaulted_p
)
1763 x_free_colors (f
, &face
->underline_color
, 1);
1764 IF_DEBUG (--ncolors_allocated
);
1767 if (face
->overline_p
1768 && !face
->overline_color_defaulted_p
)
1770 x_free_colors (f
, &face
->overline_color
, 1);
1771 IF_DEBUG (--ncolors_allocated
);
1774 if (face
->strike_through_p
1775 && !face
->strike_through_color_defaulted_p
)
1777 x_free_colors (f
, &face
->strike_through_color
, 1);
1778 IF_DEBUG (--ncolors_allocated
);
1781 if (face
->box
!= FACE_NO_BOX
1782 && !face
->box_color_defaulted_p
)
1784 x_free_colors (f
, &face
->box_color
, 1);
1785 IF_DEBUG (--ncolors_allocated
);
1789 #endif /* HAVE_X_WINDOWS */
1792 #endif /* HAVE_WINDOW_SYSTEM */
1796 /***********************************************************************
1798 ***********************************************************************/
1800 /* An enumerator for each field of an XLFD font name. */
1821 /* An enumerator for each possible slant value of a font. Taken from
1822 the XLFD specification. */
1830 XLFD_SLANT_REVERSE_ITALIC
,
1831 XLFD_SLANT_REVERSE_OBLIQUE
,
1835 /* Relative font weight according to XLFD documentation. */
1839 XLFD_WEIGHT_UNKNOWN
,
1840 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1841 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1842 XLFD_WEIGHT_LIGHT
, /* 30 */
1843 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1844 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1845 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1846 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1847 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1848 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1851 /* Relative proportionate width. */
1855 XLFD_SWIDTH_UNKNOWN
,
1856 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1857 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1858 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1859 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1860 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1861 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1862 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1863 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1864 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1867 /* Structure used for tables mapping XLFD weight, slant, and width
1868 names to numeric and symbolic values. */
1874 Lisp_Object
*symbol
;
1877 /* Table of XLFD slant names and their numeric and symbolic
1878 representations. This table must be sorted by slant names in
1881 static struct table_entry slant_table
[] =
1883 {"i", XLFD_SLANT_ITALIC
, &Qitalic
},
1884 {"o", XLFD_SLANT_OBLIQUE
, &Qoblique
},
1885 {"ot", XLFD_SLANT_OTHER
, &Qitalic
},
1886 {"r", XLFD_SLANT_ROMAN
, &Qnormal
},
1887 {"ri", XLFD_SLANT_REVERSE_ITALIC
, &Qreverse_italic
},
1888 {"ro", XLFD_SLANT_REVERSE_OBLIQUE
, &Qreverse_oblique
}
1891 /* Table of XLFD weight names. This table must be sorted by weight
1892 names in ascending order. */
1894 static struct table_entry weight_table
[] =
1896 {"black", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
},
1897 {"bold", XLFD_WEIGHT_BOLD
, &Qbold
},
1898 {"book", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1899 {"demi", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1900 {"demibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1901 {"extralight", XLFD_WEIGHT_EXTRA_LIGHT
, &Qextra_light
},
1902 {"extrabold", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1903 {"heavy", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1904 {"light", XLFD_WEIGHT_LIGHT
, &Qlight
},
1905 {"medium", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1906 {"normal", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1907 {"regular", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1908 {"semibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1909 {"semilight", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1910 {"ultralight", XLFD_WEIGHT_ULTRA_LIGHT
, &Qultra_light
},
1911 {"ultrabold", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
}
1914 /* Table of XLFD width names. This table must be sorted by width
1915 names in ascending order. */
1917 static struct table_entry swidth_table
[] =
1919 {"compressed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1920 {"condensed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1921 {"demiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1922 {"expanded", XLFD_SWIDTH_EXPANDED
, &Qexpanded
},
1923 {"extracondensed", XLFD_SWIDTH_EXTRA_CONDENSED
, &Qextra_condensed
},
1924 {"extraexpanded", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
},
1925 {"medium", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1926 {"narrow", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1927 {"normal", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1928 {"regular", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1929 {"semicondensed", XLFD_SWIDTH_SEMI_CONDENSED
, &Qsemi_condensed
},
1930 {"semiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1931 {"ultracondensed", XLFD_SWIDTH_ULTRA_CONDENSED
, &Qultra_condensed
},
1932 {"ultraexpanded", XLFD_SWIDTH_ULTRA_EXPANDED
, &Qultra_expanded
},
1933 {"wide", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
}
1936 /* Structure used to hold the result of splitting font names in XLFD
1937 format into their fields. */
1941 /* The original name which is modified destructively by
1942 split_font_name. The pointer is kept here to be able to free it
1943 if it was allocated from the heap. */
1946 /* Font name fields. Each vector element points into `name' above.
1947 Fields are NUL-terminated. */
1948 char *fields
[XLFD_LAST
];
1950 /* Numeric values for those fields that interest us. See
1951 split_font_name for which these are. */
1952 int numeric
[XLFD_LAST
];
1954 /* Lower value mean higher priority. */
1955 int registry_priority
;
1958 /* The frame in effect when sorting font names. Set temporarily in
1959 sort_fonts so that it is available in font comparison functions. */
1961 static struct frame
*font_frame
;
1963 /* Order by which font selection chooses fonts. The default values
1964 mean `first, find a best match for the font width, then for the
1965 font height, then for weight, then for slant.' This variable can be
1966 set via set-face-font-sort-order. */
1969 static int font_sort_order
[4] = {
1970 XLFD_SWIDTH
, XLFD_POINT_SIZE
, XLFD_WEIGHT
, XLFD_SLANT
1973 static int font_sort_order
[4];
1976 /* Look up FONT.fields[FIELD_INDEX] in TABLE which has DIM entries.
1977 TABLE must be sorted by TABLE[i]->name in ascending order. Value
1978 is a pointer to the matching table entry or null if no table entry
1981 static struct table_entry
*
1982 xlfd_lookup_field_contents (table
, dim
, font
, field_index
)
1983 struct table_entry
*table
;
1985 struct font_name
*font
;
1988 /* Function split_font_name converts fields to lower-case, so there
1989 is no need to use xstrlwr or xstricmp here. */
1990 char *s
= font
->fields
[field_index
];
1991 int low
, mid
, high
, cmp
;
1998 mid
= (low
+ high
) / 2;
1999 cmp
= strcmp (table
[mid
].name
, s
);
2013 /* Return a numeric representation for font name field
2014 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
2015 has DIM entries. Value is the numeric value found or DFLT if no
2016 table entry matches. This function is used to translate weight,
2017 slant, and swidth names of XLFD font names to numeric values. */
2020 xlfd_numeric_value (table
, dim
, font
, field_index
, dflt
)
2021 struct table_entry
*table
;
2023 struct font_name
*font
;
2027 struct table_entry
*p
;
2028 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
2029 return p
? p
->numeric
: dflt
;
2033 /* Return a symbolic representation for font name field
2034 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
2035 has DIM entries. Value is the symbolic value found or DFLT if no
2036 table entry matches. This function is used to translate weight,
2037 slant, and swidth names of XLFD font names to symbols. */
2039 static INLINE Lisp_Object
2040 xlfd_symbolic_value (table
, dim
, font
, field_index
, dflt
)
2041 struct table_entry
*table
;
2043 struct font_name
*font
;
2047 struct table_entry
*p
;
2048 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
2049 return p
? *p
->symbol
: dflt
;
2053 /* Return a numeric value for the slant of the font given by FONT. */
2056 xlfd_numeric_slant (font
)
2057 struct font_name
*font
;
2059 return xlfd_numeric_value (slant_table
, DIM (slant_table
),
2060 font
, XLFD_SLANT
, XLFD_SLANT_ROMAN
);
2064 /* Return a symbol representing the weight of the font given by FONT. */
2066 static INLINE Lisp_Object
2067 xlfd_symbolic_slant (font
)
2068 struct font_name
*font
;
2070 return xlfd_symbolic_value (slant_table
, DIM (slant_table
),
2071 font
, XLFD_SLANT
, Qnormal
);
2075 /* Return a numeric value for the weight of the font given by FONT. */
2078 xlfd_numeric_weight (font
)
2079 struct font_name
*font
;
2081 return xlfd_numeric_value (weight_table
, DIM (weight_table
),
2082 font
, XLFD_WEIGHT
, XLFD_WEIGHT_MEDIUM
);
2086 /* Return a symbol representing the slant of the font given by FONT. */
2088 static INLINE Lisp_Object
2089 xlfd_symbolic_weight (font
)
2090 struct font_name
*font
;
2092 return xlfd_symbolic_value (weight_table
, DIM (weight_table
),
2093 font
, XLFD_WEIGHT
, Qnormal
);
2097 /* Return a numeric value for the swidth of the font whose XLFD font
2098 name fields are found in FONT. */
2101 xlfd_numeric_swidth (font
)
2102 struct font_name
*font
;
2104 return xlfd_numeric_value (swidth_table
, DIM (swidth_table
),
2105 font
, XLFD_SWIDTH
, XLFD_SWIDTH_MEDIUM
);
2109 /* Return a symbolic value for the swidth of FONT. */
2111 static INLINE Lisp_Object
2112 xlfd_symbolic_swidth (font
)
2113 struct font_name
*font
;
2115 return xlfd_symbolic_value (swidth_table
, DIM (swidth_table
),
2116 font
, XLFD_SWIDTH
, Qnormal
);
2120 /* Look up the entry of SYMBOL in the vector TABLE which has DIM
2121 entries. Value is a pointer to the matching table entry or null if
2122 no element of TABLE contains SYMBOL. */
2124 static struct table_entry
*
2125 face_value (table
, dim
, symbol
)
2126 struct table_entry
*table
;
2132 xassert (SYMBOLP (symbol
));
2134 for (i
= 0; i
< dim
; ++i
)
2135 if (EQ (*table
[i
].symbol
, symbol
))
2138 return i
< dim
? table
+ i
: NULL
;
2142 /* Return a numeric value for SYMBOL in the vector TABLE which has DIM
2143 entries. Value is -1 if SYMBOL is not found in TABLE. */
2146 face_numeric_value (table
, dim
, symbol
)
2147 struct table_entry
*table
;
2151 struct table_entry
*p
= face_value (table
, dim
, symbol
);
2152 return p
? p
->numeric
: -1;
2156 /* Return a numeric value representing the weight specified by Lisp
2157 symbol WEIGHT. Value is one of the enumerators of enum
2161 face_numeric_weight (weight
)
2164 return face_numeric_value (weight_table
, DIM (weight_table
), weight
);
2168 /* Return a numeric value representing the slant specified by Lisp
2169 symbol SLANT. Value is one of the enumerators of enum xlfd_slant. */
2172 face_numeric_slant (slant
)
2175 return face_numeric_value (slant_table
, DIM (slant_table
), slant
);
2179 /* Return a numeric value representing the swidth specified by Lisp
2180 symbol WIDTH. Value is one of the enumerators of enum xlfd_swidth. */
2183 face_numeric_swidth (width
)
2186 return face_numeric_value (swidth_table
, DIM (swidth_table
), width
);
2190 #ifdef HAVE_WINDOW_SYSTEM
2192 /* Return non-zero if FONT is the name of a fixed-pitch font. */
2196 struct font_name
*font
;
2198 /* Function split_font_name converts fields to lower-case, so there
2199 is no need to use tolower here. */
2200 return *font
->fields
[XLFD_SPACING
] != 'p';
2204 /* Return the point size of FONT on frame F, measured in 1/10 pt.
2206 The actual height of the font when displayed on F depends on the
2207 resolution of both the font and frame. For example, a 10pt font
2208 designed for a 100dpi display will display larger than 10pt on a
2209 75dpi display. (It's not unusual to use fonts not designed for the
2210 display one is using. For example, some intlfonts are available in
2211 72dpi versions, only.)
2213 Value is the real point size of FONT on frame F, or 0 if it cannot
2217 xlfd_point_size (f
, font
)
2219 struct font_name
*font
;
2221 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
2222 char *pixel_field
= font
->fields
[XLFD_PIXEL_SIZE
];
2226 if (*pixel_field
== '[')
2228 /* The pixel size field is `[A B C D]' which specifies
2229 a transformation matrix.
2235 by which all glyphs of the font are transformed. The spec
2236 says that s scalar value N for the pixel size is equivalent
2237 to A = N * resx/resy, B = C = 0, D = N. */
2238 char *start
= pixel_field
+ 1, *end
;
2242 for (i
= 0; i
< 4; ++i
)
2244 matrix
[i
] = strtod (start
, &end
);
2251 pixel
= atoi (pixel_field
);
2256 real_pt
= PT_PER_INCH
* 10.0 * pixel
/ resy
+ 0.5;
2262 /* Return point size of PIXEL dots while considering Y-resultion (DPI)
2263 of frame F. This function is used to guess a point size of font
2264 when only the pixel height of the font is available. */
2267 pixel_point_size (f
, pixel
)
2271 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
2275 /* As one inch is PT_PER_INCH points, PT_PER_INCH/RESY gives the
2276 point size of one dot. */
2277 real_pt
= pixel
* PT_PER_INCH
/ resy
;
2278 int_pt
= real_pt
+ 0.5;
2284 /* Split XLFD font name FONT->name destructively into NUL-terminated,
2285 lower-case fields in FONT->fields. NUMERIC_P non-zero means
2286 compute numeric values for fields XLFD_POINT_SIZE, XLFD_SWIDTH,
2287 XLFD_RESY, XLFD_SLANT, and XLFD_WEIGHT in FONT->numeric. Value is
2288 zero if the font name doesn't have the format we expect. The
2289 expected format is a font name that starts with a `-' and has
2290 XLFD_LAST fields separated by `-'. */
2293 split_font_name (f
, font
, numeric_p
)
2295 struct font_name
*font
;
2301 if (*font
->name
== '-')
2303 char *p
= xstrlwr (font
->name
) + 1;
2305 while (i
< XLFD_LAST
)
2307 font
->fields
[i
] = p
;
2310 /* Pixel and point size may be of the form `[....]'. For
2311 BNF, see XLFD spec, chapter 4. Negative values are
2312 indicated by tilde characters which we replace with
2313 `-' characters, here. */
2315 && (i
- 1 == XLFD_PIXEL_SIZE
2316 || i
- 1 == XLFD_POINT_SIZE
))
2321 for (++p
; *p
&& *p
!= ']'; ++p
)
2325 /* Check that the matrix contains 4 floating point
2327 for (j
= 0, start
= font
->fields
[i
- 1] + 1;
2330 if (strtod (start
, &end
) == 0 && start
== end
)
2337 while (*p
&& *p
!= '-')
2347 success_p
= i
== XLFD_LAST
;
2349 /* If requested, and font name was in the expected format,
2350 compute numeric values for some fields. */
2351 if (numeric_p
&& success_p
)
2353 font
->numeric
[XLFD_POINT_SIZE
] = xlfd_point_size (f
, font
);
2354 font
->numeric
[XLFD_RESY
] = atoi (font
->fields
[XLFD_RESY
]);
2355 font
->numeric
[XLFD_SLANT
] = xlfd_numeric_slant (font
);
2356 font
->numeric
[XLFD_WEIGHT
] = xlfd_numeric_weight (font
);
2357 font
->numeric
[XLFD_SWIDTH
] = xlfd_numeric_swidth (font
);
2358 font
->numeric
[XLFD_AVGWIDTH
] = atoi (font
->fields
[XLFD_AVGWIDTH
]);
2361 /* Initialize it to zero. It will be overridden by font_list while
2362 trying alternate registries. */
2363 font
->registry_priority
= 0;
2369 /* Build an XLFD font name from font name fields in FONT. Value is a
2370 pointer to the font name, which is allocated via xmalloc. */
2373 build_font_name (font
)
2374 struct font_name
*font
;
2378 char *font_name
= (char *) xmalloc (size
);
2379 int total_length
= 0;
2381 for (i
= 0; i
< XLFD_LAST
; ++i
)
2383 /* Add 1 because of the leading `-'. */
2384 int len
= strlen (font
->fields
[i
]) + 1;
2386 /* Reallocate font_name if necessary. Add 1 for the final
2388 if (total_length
+ len
+ 1 >= size
)
2390 int new_size
= max (2 * size
, size
+ len
+ 1);
2391 int sz
= new_size
* sizeof *font_name
;
2392 font_name
= (char *) xrealloc (font_name
, sz
);
2396 font_name
[total_length
] = '-';
2397 bcopy (font
->fields
[i
], font_name
+ total_length
+ 1, len
- 1);
2398 total_length
+= len
;
2401 font_name
[total_length
] = 0;
2406 /* Free an array FONTS of N font_name structures. This frees FONTS
2407 itself and all `name' fields in its elements. */
2410 free_font_names (fonts
, n
)
2411 struct font_name
*fonts
;
2415 xfree (fonts
[--n
].name
);
2420 /* Sort vector FONTS of font_name structures which contains NFONTS
2421 elements using qsort and comparison function CMPFN. F is the frame
2422 on which the fonts will be used. The global variable font_frame
2423 is temporarily set to F to make it available in CMPFN. */
2426 sort_fonts (f
, fonts
, nfonts
, cmpfn
)
2428 struct font_name
*fonts
;
2430 int (*cmpfn
) P_ ((const void *, const void *));
2433 qsort (fonts
, nfonts
, sizeof *fonts
, cmpfn
);
2438 /* Get fonts matching PATTERN on frame F. If F is null, use the first
2439 display in x_display_list. FONTS is a pointer to a vector of
2440 NFONTS font_name structures. TRY_ALTERNATIVES_P non-zero means try
2441 alternative patterns from Valternate_fontname_alist if no fonts are
2442 found matching PATTERN.
2444 For all fonts found, set FONTS[i].name to the name of the font,
2445 allocated via xmalloc, and split font names into fields. Ignore
2446 fonts that we can't parse. Value is the number of fonts found. */
2449 x_face_list_fonts (f
, pattern
, fonts
, nfonts
, try_alternatives_p
)
2452 struct font_name
*fonts
;
2453 int nfonts
, try_alternatives_p
;
2457 /* NTEMACS_TODO : currently this uses w32_list_fonts, but it may be
2458 better to do it the other way around. */
2460 Lisp_Object lpattern
, tem
;
2462 lpattern
= build_string (pattern
);
2464 /* Get the list of fonts matching PATTERN. */
2467 lfonts
= w32_list_fonts (f
, lpattern
, 0, nfonts
);
2470 lfonts
= x_list_fonts (f
, lpattern
, -1, nfonts
);
2473 /* Make a copy of the font names we got from X, and
2474 split them into fields. */
2476 for (tem
= lfonts
; CONSP (tem
) && n
< nfonts
; tem
= XCDR (tem
))
2478 Lisp_Object elt
, tail
;
2479 const char *name
= SDATA (XCAR (tem
));
2481 /* Ignore fonts matching a pattern from face-ignored-fonts. */
2482 for (tail
= Vface_ignored_fonts
; CONSP (tail
); tail
= XCDR (tail
))
2486 && fast_c_string_match_ignore_case (elt
, name
) >= 0)
2495 /* Make a copy of the font name. */
2496 fonts
[n
].name
= xstrdup (name
);
2498 if (split_font_name (f
, fonts
+ n
, 1))
2500 if (font_scalable_p (fonts
+ n
)
2501 && !may_use_scalable_font_p (name
))
2504 xfree (fonts
[n
].name
);
2510 xfree (fonts
[n
].name
);
2513 /* If no fonts found, try patterns from Valternate_fontname_alist. */
2514 if (n
== 0 && try_alternatives_p
)
2516 Lisp_Object list
= Valternate_fontname_alist
;
2518 while (CONSP (list
))
2520 Lisp_Object entry
= XCAR (list
);
2522 && STRINGP (XCAR (entry
))
2523 && strcmp (SDATA (XCAR (entry
)), pattern
) == 0)
2530 Lisp_Object patterns
= XCAR (list
);
2533 while (CONSP (patterns
)
2534 /* If list is screwed up, give up. */
2535 && (name
= XCAR (patterns
),
2537 /* Ignore patterns equal to PATTERN because we tried that
2538 already with no success. */
2539 && (strcmp (SDATA (name
), pattern
) == 0
2540 || (n
= x_face_list_fonts (f
, SDATA (name
),
2543 patterns
= XCDR (patterns
);
2551 /* Determine fonts matching PATTERN on frame F. Sort resulting fonts
2552 using comparison function CMPFN. Value is the number of fonts
2553 found. If value is non-zero, *FONTS is set to a vector of
2554 font_name structures allocated from the heap containing matching
2555 fonts. Each element of *FONTS contains a name member that is also
2556 allocated from the heap. Font names in these structures are split
2557 into fields. Use free_font_names to free such an array. */
2560 sorted_font_list (f
, pattern
, cmpfn
, fonts
)
2563 int (*cmpfn
) P_ ((const void *, const void *));
2564 struct font_name
**fonts
;
2568 /* Get the list of fonts matching pattern. 100 should suffice. */
2569 nfonts
= DEFAULT_FONT_LIST_LIMIT
;
2570 if (INTEGERP (Vfont_list_limit
) && XINT (Vfont_list_limit
) > 0)
2571 nfonts
= XFASTINT (Vfont_list_limit
);
2573 *fonts
= (struct font_name
*) xmalloc (nfonts
* sizeof **fonts
);
2574 nfonts
= x_face_list_fonts (f
, pattern
, *fonts
, nfonts
, 1);
2576 /* Sort the resulting array and return it in *FONTS. If no
2577 fonts were found, make sure to set *FONTS to null. */
2579 sort_fonts (f
, *fonts
, nfonts
, cmpfn
);
2590 /* Compare two font_name structures *A and *B. Value is analogous to
2591 strcmp. Sort order is given by the global variable
2592 font_sort_order. Font names are sorted so that, everything else
2593 being equal, fonts with a resolution closer to that of the frame on
2594 which they are used are listed first. The global variable
2595 font_frame is the frame on which we operate. */
2598 cmp_font_names (a
, b
)
2601 struct font_name
*x
= (struct font_name
*) a
;
2602 struct font_name
*y
= (struct font_name
*) b
;
2605 /* All strings have been converted to lower-case by split_font_name,
2606 so we can use strcmp here. */
2607 cmp
= strcmp (x
->fields
[XLFD_FAMILY
], y
->fields
[XLFD_FAMILY
]);
2612 for (i
= 0; i
< DIM (font_sort_order
) && cmp
== 0; ++i
)
2614 int j
= font_sort_order
[i
];
2615 cmp
= x
->numeric
[j
] - y
->numeric
[j
];
2620 /* Everything else being equal, we prefer fonts with an
2621 y-resolution closer to that of the frame. */
2622 int resy
= FRAME_X_DISPLAY_INFO (font_frame
)->resy
;
2623 int x_resy
= x
->numeric
[XLFD_RESY
];
2624 int y_resy
= y
->numeric
[XLFD_RESY
];
2625 cmp
= abs (resy
- x_resy
) - abs (resy
- y_resy
);
2633 /* Get a sorted list of fonts of family FAMILY on frame F. If PATTERN
2634 is non-nil list fonts matching that pattern. Otherwise, if
2635 REGISTRY is non-nil return only fonts with that registry, otherwise
2636 return fonts of any registry. Set *FONTS to a vector of font_name
2637 structures allocated from the heap containing the fonts found.
2638 Value is the number of fonts found. */
2641 font_list_1 (f
, pattern
, family
, registry
, fonts
)
2643 Lisp_Object pattern
, family
, registry
;
2644 struct font_name
**fonts
;
2646 char *pattern_str
, *family_str
, *registry_str
;
2650 family_str
= (NILP (family
) ? "*" : (char *) SDATA (family
));
2651 registry_str
= (NILP (registry
) ? "*" : (char *) SDATA (registry
));
2653 pattern_str
= (char *) alloca (strlen (family_str
)
2654 + strlen (registry_str
)
2656 strcpy (pattern_str
, index (family_str
, '-') ? "-" : "-*-");
2657 strcat (pattern_str
, family_str
);
2658 strcat (pattern_str
, "-*-");
2659 strcat (pattern_str
, registry_str
);
2660 if (!index (registry_str
, '-'))
2662 if (registry_str
[strlen (registry_str
) - 1] == '*')
2663 strcat (pattern_str
, "-*");
2665 strcat (pattern_str
, "*-*");
2669 pattern_str
= (char *) SDATA (pattern
);
2671 return sorted_font_list (f
, pattern_str
, cmp_font_names
, fonts
);
2675 /* Concatenate font list FONTS1 and FONTS2. FONTS1 and FONTS2
2676 contains NFONTS1 fonts and NFONTS2 fonts respectively. Return a
2677 pointer to a newly allocated font list. FONTS1 and FONTS2 are
2680 static struct font_name
*
2681 concat_font_list (fonts1
, nfonts1
, fonts2
, nfonts2
)
2682 struct font_name
*fonts1
, *fonts2
;
2683 int nfonts1
, nfonts2
;
2685 int new_nfonts
= nfonts1
+ nfonts2
;
2686 struct font_name
*new_fonts
;
2688 new_fonts
= (struct font_name
*) xmalloc (sizeof *new_fonts
* new_nfonts
);
2689 bcopy (fonts1
, new_fonts
, sizeof *new_fonts
* nfonts1
);
2690 bcopy (fonts2
, new_fonts
+ nfonts1
, sizeof *new_fonts
* nfonts2
);
2697 /* Get a sorted list of fonts of family FAMILY on frame F.
2699 If PATTERN is non-nil list fonts matching that pattern.
2701 If REGISTRY is non-nil, return fonts with that registry and the
2702 alternative registries from Vface_alternative_font_registry_alist.
2704 If REGISTRY is nil return fonts of any registry.
2706 Set *FONTS to a vector of font_name structures allocated from the
2707 heap containing the fonts found. Value is the number of fonts
2711 font_list (f
, pattern
, family
, registry
, fonts
)
2713 Lisp_Object pattern
, family
, registry
;
2714 struct font_name
**fonts
;
2716 int nfonts
= font_list_1 (f
, pattern
, family
, registry
, fonts
);
2718 if (!NILP (registry
)
2719 && CONSP (Vface_alternative_font_registry_alist
))
2723 alter
= Fassoc (registry
, Vface_alternative_font_registry_alist
);
2728 for (alter
= XCDR (alter
), reg_prio
= 1;
2730 alter
= XCDR (alter
), reg_prio
++)
2731 if (STRINGP (XCAR (alter
)))
2734 struct font_name
*fonts2
;
2736 nfonts2
= font_list_1 (f
, pattern
, family
, XCAR (alter
),
2738 for (i
= 0; i
< nfonts2
; i
++)
2739 fonts2
[i
].registry_priority
= reg_prio
;
2740 *fonts
= (nfonts
> 0
2741 ? concat_font_list (*fonts
, nfonts
, fonts2
, nfonts2
)
2752 /* Remove elements from LIST whose cars are `equal'. Called from
2753 x-family-fonts and x-font-family-list to remove duplicate font
2757 remove_duplicates (list
)
2760 Lisp_Object tail
= list
;
2762 while (!NILP (tail
) && !NILP (XCDR (tail
)))
2764 Lisp_Object next
= XCDR (tail
);
2765 if (!NILP (Fequal (XCAR (next
), XCAR (tail
))))
2766 XSETCDR (tail
, XCDR (next
));
2773 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
2774 doc
: /* Return a list of available fonts of family FAMILY on FRAME.
2775 If FAMILY is omitted or nil, list all families.
2776 Otherwise, FAMILY must be a string, possibly containing wildcards
2778 If FRAME is omitted or nil, use the selected frame.
2779 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
2780 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
2781 FAMILY is the font family name. POINT-SIZE is the size of the
2782 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
2783 width, weight and slant of the font. These symbols are the same as for
2784 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
2785 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
2786 giving the registry and encoding of the font.
2787 The result list is sorted according to the current setting of
2788 the face font sort order. */)
2790 Lisp_Object family
, frame
;
2792 struct frame
*f
= check_x_frame (frame
);
2793 struct font_name
*fonts
;
2796 struct gcpro gcpro1
;
2799 CHECK_STRING (family
);
2803 nfonts
= font_list (f
, Qnil
, family
, Qnil
, &fonts
);
2804 for (i
= nfonts
- 1; i
>= 0; --i
)
2806 Lisp_Object v
= Fmake_vector (make_number (8), Qnil
);
2809 ASET (v
, 0, build_string (fonts
[i
].fields
[XLFD_FAMILY
]));
2810 ASET (v
, 1, xlfd_symbolic_swidth (fonts
+ i
));
2811 ASET (v
, 2, make_number (xlfd_point_size (f
, fonts
+ i
)));
2812 ASET (v
, 3, xlfd_symbolic_weight (fonts
+ i
));
2813 ASET (v
, 4, xlfd_symbolic_slant (fonts
+ i
));
2814 ASET (v
, 5, xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
);
2815 tem
= build_font_name (fonts
+ i
);
2816 ASET (v
, 6, build_string (tem
));
2817 sprintf (tem
, "%s-%s", fonts
[i
].fields
[XLFD_REGISTRY
],
2818 fonts
[i
].fields
[XLFD_ENCODING
]);
2819 ASET (v
, 7, build_string (tem
));
2822 result
= Fcons (v
, result
);
2825 remove_duplicates (result
);
2826 free_font_names (fonts
, nfonts
);
2832 DEFUN ("x-font-family-list", Fx_font_family_list
, Sx_font_family_list
,
2834 doc
: /* Return a list of available font families on FRAME.
2835 If FRAME is omitted or nil, use the selected frame.
2836 Value is a list of conses (FAMILY . FIXED-P) where FAMILY
2837 is a font family, and FIXED-P is non-nil if fonts of that family
2838 are fixed-pitch. */)
2842 struct frame
*f
= check_x_frame (frame
);
2844 struct font_name
*fonts
;
2846 struct gcpro gcpro1
;
2847 int count
= SPECPDL_INDEX ();
2850 /* Let's consider all fonts. Increase the limit for matching
2851 fonts until we have them all. */
2854 specbind (intern ("font-list-limit"), make_number (limit
));
2855 nfonts
= font_list (f
, Qnil
, Qnil
, Qnil
, &fonts
);
2857 if (nfonts
== limit
)
2859 free_font_names (fonts
, nfonts
);
2868 for (i
= nfonts
- 1; i
>= 0; --i
)
2869 result
= Fcons (Fcons (build_string (fonts
[i
].fields
[XLFD_FAMILY
]),
2870 xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
),
2873 remove_duplicates (result
);
2874 free_font_names (fonts
, nfonts
);
2876 return unbind_to (count
, result
);
2880 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
2881 doc
: /* Return a list of the names of available fonts matching PATTERN.
2882 If optional arguments FACE and FRAME are specified, return only fonts
2883 the same size as FACE on FRAME.
2884 PATTERN is a string, perhaps with wildcard characters;
2885 the * character matches any substring, and
2886 the ? character matches any single character.
2887 PATTERN is case-insensitive.
2888 FACE is a face name--a symbol.
2890 The return value is a list of strings, suitable as arguments to
2893 Fonts Emacs can't use may or may not be excluded
2894 even if they match PATTERN and FACE.
2895 The optional fourth argument MAXIMUM sets a limit on how many
2896 fonts to match. The first MAXIMUM fonts are reported.
2897 The optional fifth argument WIDTH, if specified, is a number of columns
2898 occupied by a character of a font. In that case, return only fonts
2899 the WIDTH times as wide as FACE on FRAME. */)
2900 (pattern
, face
, frame
, maximum
, width
)
2901 Lisp_Object pattern
, face
, frame
, maximum
, width
;
2908 CHECK_STRING (pattern
);
2914 CHECK_NATNUM (maximum
);
2915 maxnames
= XINT (maximum
);
2919 CHECK_NUMBER (width
);
2921 /* We can't simply call check_x_frame because this function may be
2922 called before any frame is created. */
2923 f
= frame_or_selected_frame (frame
, 2);
2924 if (!FRAME_WINDOW_P (f
))
2926 /* Perhaps we have not yet created any frame. */
2931 /* Determine the width standard for comparison with the fonts we find. */
2937 /* This is of limited utility since it works with character
2938 widths. Keep it for compatibility. --gerd. */
2939 int face_id
= lookup_named_face (f
, face
, 0);
2940 struct face
*face
= (face_id
< 0
2942 : FACE_FROM_ID (f
, face_id
));
2944 if (face
&& face
->font
)
2945 size
= FONT_WIDTH (face
->font
);
2947 size
= FONT_WIDTH (FRAME_FONT (f
));
2950 size
*= XINT (width
);
2954 Lisp_Object args
[2];
2956 args
[0] = x_list_fonts (f
, pattern
, size
, maxnames
);
2958 /* We don't have to check fontsets. */
2960 args
[1] = list_fontsets (f
, pattern
, size
);
2961 return Fnconc (2, args
);
2965 #endif /* HAVE_WINDOW_SYSTEM */
2969 /***********************************************************************
2971 ***********************************************************************/
2973 /* Access face attributes of face LFACE, a Lisp vector. */
2975 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
2976 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
2977 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
2978 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
2979 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
2980 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
2981 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
2982 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
2983 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
2984 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
2985 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
2986 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
2987 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
2988 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
2989 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
2990 #define LFACE_AVGWIDTH(LFACE) AREF ((LFACE), LFACE_AVGWIDTH_INDEX)
2992 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
2993 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
2995 #define LFACEP(LFACE) \
2997 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \
2998 && EQ (AREF (LFACE, 0), Qface))
3003 /* Check consistency of Lisp face attribute vector ATTRS. */
3006 check_lface_attrs (attrs
)
3009 xassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
3010 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
3011 xassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
3012 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
3013 xassert (UNSPECIFIEDP (attrs
[LFACE_AVGWIDTH_INDEX
])
3014 || INTEGERP (attrs
[LFACE_AVGWIDTH_INDEX
]));
3015 xassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
3016 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
])
3017 || FLOATP (attrs
[LFACE_HEIGHT_INDEX
])
3018 || FUNCTIONP (attrs
[LFACE_HEIGHT_INDEX
]));
3019 xassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
3020 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
3021 xassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
3022 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
3023 xassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
3024 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
3025 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]));
3026 xassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
3027 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
3028 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
3029 xassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
3030 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
3031 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
3032 xassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
3033 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
3034 || STRINGP (attrs
[LFACE_BOX_INDEX
])
3035 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
3036 || CONSP (attrs
[LFACE_BOX_INDEX
]));
3037 xassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
3038 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
3039 xassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
3040 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
3041 xassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
3042 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
3043 xassert (UNSPECIFIEDP (attrs
[LFACE_INHERIT_INDEX
])
3044 || NILP (attrs
[LFACE_INHERIT_INDEX
])
3045 || SYMBOLP (attrs
[LFACE_INHERIT_INDEX
])
3046 || CONSP (attrs
[LFACE_INHERIT_INDEX
]));
3047 #ifdef HAVE_WINDOW_SYSTEM
3048 xassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
3049 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
3050 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
3051 xassert (UNSPECIFIEDP (attrs
[LFACE_FONT_INDEX
])
3052 || NILP (attrs
[LFACE_FONT_INDEX
])
3053 || STRINGP (attrs
[LFACE_FONT_INDEX
]));
3058 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
3066 xassert (LFACEP (lface
));
3067 check_lface_attrs (XVECTOR (lface
)->contents
);
3071 #else /* GLYPH_DEBUG == 0 */
3073 #define check_lface_attrs(attrs) (void) 0
3074 #define check_lface(lface) (void) 0
3076 #endif /* GLYPH_DEBUG == 0 */
3079 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
3080 to make it a symvol. If FACE_NAME is an alias for another face,
3081 return that face's name. */
3084 resolve_face_name (face_name
)
3085 Lisp_Object face_name
;
3087 Lisp_Object aliased
;
3089 if (STRINGP (face_name
))
3090 face_name
= intern (SDATA (face_name
));
3092 while (SYMBOLP (face_name
))
3094 aliased
= Fget (face_name
, Qface_alias
);
3098 face_name
= aliased
;
3105 /* Return the face definition of FACE_NAME on frame F. F null means
3106 return the definition for new frames. FACE_NAME may be a string or
3107 a symbol (apparently Emacs 20.2 allowed strings as face names in
3108 face text properties; Ediff uses that). If FACE_NAME is an alias
3109 for another face, return that face's definition. If SIGNAL_P is
3110 non-zero, signal an error if FACE_NAME is not a valid face name.
3111 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
3114 static INLINE Lisp_Object
3115 lface_from_face_name (f
, face_name
, signal_p
)
3117 Lisp_Object face_name
;
3122 face_name
= resolve_face_name (face_name
);
3125 lface
= assq_no_quit (face_name
, f
->face_alist
);
3127 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
3130 lface
= XCDR (lface
);
3132 signal_error ("Invalid face", face_name
);
3134 check_lface (lface
);
3139 /* Get face attributes of face FACE_NAME from frame-local faces on
3140 frame F. Store the resulting attributes in ATTRS which must point
3141 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
3142 is non-zero, signal an error if FACE_NAME does not name a face.
3143 Otherwise, value is zero if FACE_NAME is not a face. */
3146 get_lface_attributes (f
, face_name
, attrs
, signal_p
)
3148 Lisp_Object face_name
;
3155 lface
= lface_from_face_name (f
, face_name
, signal_p
);
3158 bcopy (XVECTOR (lface
)->contents
, attrs
,
3159 LFACE_VECTOR_SIZE
* sizeof *attrs
);
3169 /* Non-zero if all attributes in face attribute vector ATTRS are
3170 specified, i.e. are non-nil. */
3173 lface_fully_specified_p (attrs
)
3178 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3179 if (i
!= LFACE_FONT_INDEX
&& i
!= LFACE_INHERIT_INDEX
3180 && i
!= LFACE_AVGWIDTH_INDEX
)
3181 if (UNSPECIFIEDP (attrs
[i
]))
3184 return i
== LFACE_VECTOR_SIZE
;
3187 #ifdef HAVE_WINDOW_SYSTEM
3189 /* Set font-related attributes of Lisp face LFACE from the fullname of
3190 the font opened by FONTNAME. If FORCE_P is zero, set only
3191 unspecified attributes of LFACE. The exception is `font'
3192 attribute. It is set to FONTNAME as is regardless of FORCE_P.
3194 If FONTNAME is not available on frame F,
3195 return 0 if MAY_FAIL_P is non-zero, otherwise abort.
3196 If the fullname is not in a valid XLFD format,
3197 return 0 if MAY_FAIL_P is non-zero, otherwise set normal values
3198 in LFACE and return 1.
3199 Otherwise, return 1. */
3202 set_lface_from_font_name (f
, lface
, fontname
, force_p
, may_fail_p
)
3205 Lisp_Object fontname
;
3206 int force_p
, may_fail_p
;
3208 struct font_name font
;
3213 char *font_name
= SDATA (fontname
);
3214 struct font_info
*font_info
;
3216 /* If FONTNAME is actually a fontset name, get ASCII font name of it. */
3217 fontset
= fs_query_fontset (fontname
, 0);
3219 font_name
= SDATA (fontset_ascii (fontset
));
3221 /* Check if FONT_NAME is surely available on the system. Usually
3222 FONT_NAME is already cached for the frame F and FS_LOAD_FONT
3223 returns quickly. But, even if FONT_NAME is not yet cached,
3224 caching it now is not futail because we anyway load the font
3227 font_info
= FS_LOAD_FONT (f
, 0, font_name
, -1);
3237 font
.name
= STRDUPA (font_info
->full_name
);
3238 have_xlfd_p
= split_font_name (f
, &font
, 1);
3240 /* Set attributes only if unspecified, otherwise face defaults for
3241 new frames would never take effect. If we couldn't get a font
3242 name conforming to XLFD, set normal values. */
3244 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
3249 buffer
= (char *) alloca (strlen (font
.fields
[XLFD_FAMILY
])
3250 + strlen (font
.fields
[XLFD_FOUNDRY
])
3252 sprintf (buffer
, "%s-%s", font
.fields
[XLFD_FOUNDRY
],
3253 font
.fields
[XLFD_FAMILY
]);
3254 val
= build_string (buffer
);
3257 val
= build_string ("*");
3258 LFACE_FAMILY (lface
) = val
;
3261 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
3264 pt
= xlfd_point_size (f
, &font
);
3266 pt
= pixel_point_size (f
, font_info
->height
* 10);
3268 LFACE_HEIGHT (lface
) = make_number (pt
);
3271 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
3272 LFACE_SWIDTH (lface
)
3273 = have_xlfd_p
? xlfd_symbolic_swidth (&font
) : Qnormal
;
3275 if (force_p
|| UNSPECIFIEDP (LFACE_AVGWIDTH (lface
)))
3276 LFACE_AVGWIDTH (lface
)
3278 ? make_number (font
.numeric
[XLFD_AVGWIDTH
])
3281 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
3282 LFACE_WEIGHT (lface
)
3283 = have_xlfd_p
? xlfd_symbolic_weight (&font
) : Qnormal
;
3285 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
3287 = have_xlfd_p
? xlfd_symbolic_slant (&font
) : Qnormal
;
3289 LFACE_FONT (lface
) = fontname
;
3294 #endif /* HAVE_WINDOW_SYSTEM */
3297 /* Merges the face height FROM with the face height TO, and returns the
3298 merged height. If FROM is an invalid height, then INVALID is
3299 returned instead. FROM and TO may be either absolute face heights or
3300 `relative' heights; the returned value is always an absolute height
3301 unless both FROM and TO are relative. GCPRO is a lisp value that
3302 will be protected from garbage-collection if this function makes a
3306 merge_face_heights (from
, to
, invalid
, gcpro
)
3307 Lisp_Object from
, to
, invalid
, gcpro
;
3309 Lisp_Object result
= invalid
;
3311 if (INTEGERP (from
))
3312 /* FROM is absolute, just use it as is. */
3314 else if (FLOATP (from
))
3315 /* FROM is a scale, use it to adjust TO. */
3318 /* relative X absolute => absolute */
3319 result
= make_number ((EMACS_INT
)(XFLOAT_DATA (from
) * XINT (to
)));
3320 else if (FLOATP (to
))
3321 /* relative X relative => relative */
3322 result
= make_float (XFLOAT_DATA (from
) * XFLOAT_DATA (to
));
3324 else if (FUNCTIONP (from
))
3325 /* FROM is a function, which use to adjust TO. */
3327 /* Call function with current height as argument.
3328 From is the new height. */
3329 Lisp_Object args
[2];
3330 struct gcpro gcpro1
;
3336 result
= safe_call (2, args
);
3340 /* Ensure that if TO was absolute, so is the result. */
3341 if (INTEGERP (to
) && !INTEGERP (result
))
3349 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
3350 store the resulting attributes in TO, which must be already be
3351 completely specified and contain only absolute attributes. Every
3352 specified attribute of FROM overrides the corresponding attribute of
3353 TO; relative attributes in FROM are merged with the absolute value in
3354 TO and replace it. CYCLE_CHECK is used internally to detect loops in
3355 face inheritance; it should be Qnil when called from other places. */
3358 merge_face_vectors (f
, from
, to
, cycle_check
)
3360 Lisp_Object
*from
, *to
;
3361 Lisp_Object cycle_check
;
3365 /* If FROM inherits from some other faces, merge their attributes into
3366 TO before merging FROM's direct attributes. Note that an :inherit
3367 attribute of `unspecified' is the same as one of nil; we never
3368 merge :inherit attributes, so nil is more correct, but lots of
3369 other code uses `unspecified' as a generic value for face attributes. */
3370 if (!UNSPECIFIEDP (from
[LFACE_INHERIT_INDEX
])
3371 && !NILP (from
[LFACE_INHERIT_INDEX
]))
3372 merge_face_inheritance (f
, from
[LFACE_INHERIT_INDEX
], to
, cycle_check
);
3374 /* If TO specifies a :font attribute, and FROM specifies some
3375 font-related attribute, we need to clear TO's :font attribute
3376 (because it will be inconsistent with whatever FROM specifies, and
3377 FROM takes precedence). */
3378 if (!NILP (to
[LFACE_FONT_INDEX
])
3379 && (!UNSPECIFIEDP (from
[LFACE_FAMILY_INDEX
])
3380 || !UNSPECIFIEDP (from
[LFACE_HEIGHT_INDEX
])
3381 || !UNSPECIFIEDP (from
[LFACE_WEIGHT_INDEX
])
3382 || !UNSPECIFIEDP (from
[LFACE_SLANT_INDEX
])
3383 || !UNSPECIFIEDP (from
[LFACE_SWIDTH_INDEX
])
3384 || !UNSPECIFIEDP (from
[LFACE_AVGWIDTH_INDEX
])))
3385 to
[LFACE_FONT_INDEX
] = Qnil
;
3387 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3388 if (!UNSPECIFIEDP (from
[i
]))
3390 if (i
== LFACE_HEIGHT_INDEX
&& !INTEGERP (from
[i
]))
3391 to
[i
] = merge_face_heights (from
[i
], to
[i
], to
[i
], cycle_check
);
3396 /* TO is always an absolute face, which should inherit from nothing.
3397 We blindly copy the :inherit attribute above and fix it up here. */
3398 to
[LFACE_INHERIT_INDEX
] = Qnil
;
3402 /* Checks the `cycle check' variable CHECK to see if it indicates that
3403 EL is part of a cycle; CHECK must be either Qnil or a value returned
3404 by an earlier use of CYCLE_CHECK. SUSPICIOUS is the number of
3405 elements after which a cycle might be suspected; after that many
3406 elements, this macro begins consing in order to keep more precise
3409 Returns nil if a cycle was detected, otherwise a new value for CHECK
3412 CHECK is evaluated multiple times, EL and SUSPICIOUS 0 or 1 times, so
3413 the caller should make sure that's ok. */
3415 #define CYCLE_CHECK(check, el, suspicious) \
3418 : (INTEGERP (check) \
3419 ? (XFASTINT (check) < (suspicious) \
3420 ? make_number (XFASTINT (check) + 1) \
3421 : Fcons (el, Qnil)) \
3422 : (!NILP (Fmemq ((el), (check))) \
3424 : Fcons ((el), (check)))))
3427 /* Merge face attributes from the face on frame F whose name is
3428 INHERITS, into the vector of face attributes TO; INHERITS may also be
3429 a list of face names, in which case they are applied in order.
3430 CYCLE_CHECK is used to detect loops in face inheritance.
3431 Returns true if any of the inherited attributes are `font-related'. */
3434 merge_face_inheritance (f
, inherit
, to
, cycle_check
)
3436 Lisp_Object inherit
;
3438 Lisp_Object cycle_check
;
3440 if (SYMBOLP (inherit
) && !EQ (inherit
, Qunspecified
))
3441 /* Inherit from the named face INHERIT. */
3445 /* Make sure we're not in an inheritance loop. */
3446 cycle_check
= CYCLE_CHECK (cycle_check
, inherit
, 15);
3447 if (NILP (cycle_check
))
3448 /* Cycle detected, ignore any further inheritance. */
3451 lface
= lface_from_face_name (f
, inherit
, 0);
3453 merge_face_vectors (f
, XVECTOR (lface
)->contents
, to
, cycle_check
);
3455 else if (CONSP (inherit
))
3456 /* Handle a list of inherited faces by calling ourselves recursively
3457 on each element. Note that we only do so for symbol elements, so
3458 it's not possible to infinitely recurse. */
3460 while (CONSP (inherit
))
3462 if (SYMBOLP (XCAR (inherit
)))
3463 merge_face_inheritance (f
, XCAR (inherit
), to
, cycle_check
);
3465 /* Check for a circular inheritance list. */
3466 cycle_check
= CYCLE_CHECK (cycle_check
, inherit
, 15);
3467 if (NILP (cycle_check
))
3468 /* Cycle detected. */
3471 inherit
= XCDR (inherit
);
3477 /* Given a Lisp face attribute vector TO and a Lisp object PROP that
3478 is a face property, determine the resulting face attributes on
3479 frame F, and store them in TO. PROP may be a single face
3480 specification or a list of such specifications. Each face
3481 specification can be
3483 1. A symbol or string naming a Lisp face.
3485 2. A property list of the form (KEYWORD VALUE ...) where each
3486 KEYWORD is a face attribute name, and value is an appropriate value
3489 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
3490 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
3491 for compatibility with 20.2.
3493 Face specifications earlier in lists take precedence over later
3497 merge_face_vector_with_property (f
, to
, prop
)
3504 Lisp_Object first
= XCAR (prop
);
3506 if (EQ (first
, Qforeground_color
)
3507 || EQ (first
, Qbackground_color
))
3509 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
3510 . COLOR). COLOR must be a string. */
3511 Lisp_Object color_name
= XCDR (prop
);
3512 Lisp_Object color
= first
;
3514 if (STRINGP (color_name
))
3516 if (EQ (color
, Qforeground_color
))
3517 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
3519 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
3522 add_to_log ("Invalid face color", color_name
, Qnil
);
3524 else if (SYMBOLP (first
)
3525 && *SDATA (SYMBOL_NAME (first
)) == ':')
3527 /* Assume this is the property list form. */
3528 while (CONSP (prop
) && CONSP (XCDR (prop
)))
3530 Lisp_Object keyword
= XCAR (prop
);
3531 Lisp_Object value
= XCAR (XCDR (prop
));
3533 if (EQ (keyword
, QCfamily
))
3535 if (STRINGP (value
))
3536 to
[LFACE_FAMILY_INDEX
] = value
;
3538 add_to_log ("Invalid face font family", value
, Qnil
);
3540 else if (EQ (keyword
, QCheight
))
3542 Lisp_Object new_height
=
3543 merge_face_heights (value
, to
[LFACE_HEIGHT_INDEX
],
3546 if (NILP (new_height
))
3547 add_to_log ("Invalid face font height", value
, Qnil
);
3549 to
[LFACE_HEIGHT_INDEX
] = new_height
;
3551 else if (EQ (keyword
, QCweight
))
3554 && face_numeric_weight (value
) >= 0)
3555 to
[LFACE_WEIGHT_INDEX
] = value
;
3557 add_to_log ("Invalid face weight", value
, Qnil
);
3559 else if (EQ (keyword
, QCslant
))
3562 && face_numeric_slant (value
) >= 0)
3563 to
[LFACE_SLANT_INDEX
] = value
;
3565 add_to_log ("Invalid face slant", value
, Qnil
);
3567 else if (EQ (keyword
, QCunderline
))
3572 to
[LFACE_UNDERLINE_INDEX
] = value
;
3574 add_to_log ("Invalid face underline", value
, Qnil
);
3576 else if (EQ (keyword
, QCoverline
))
3581 to
[LFACE_OVERLINE_INDEX
] = value
;
3583 add_to_log ("Invalid face overline", value
, Qnil
);
3585 else if (EQ (keyword
, QCstrike_through
))
3590 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
3592 add_to_log ("Invalid face strike-through", value
, Qnil
);
3594 else if (EQ (keyword
, QCbox
))
3597 value
= make_number (1);
3598 if (INTEGERP (value
)
3602 to
[LFACE_BOX_INDEX
] = value
;
3604 add_to_log ("Invalid face box", value
, Qnil
);
3606 else if (EQ (keyword
, QCinverse_video
)
3607 || EQ (keyword
, QCreverse_video
))
3609 if (EQ (value
, Qt
) || NILP (value
))
3610 to
[LFACE_INVERSE_INDEX
] = value
;
3612 add_to_log ("Invalid face inverse-video", value
, Qnil
);
3614 else if (EQ (keyword
, QCforeground
))
3616 if (STRINGP (value
))
3617 to
[LFACE_FOREGROUND_INDEX
] = value
;
3619 add_to_log ("Invalid face foreground", value
, Qnil
);
3621 else if (EQ (keyword
, QCbackground
))
3623 if (STRINGP (value
))
3624 to
[LFACE_BACKGROUND_INDEX
] = value
;
3626 add_to_log ("Invalid face background", value
, Qnil
);
3628 else if (EQ (keyword
, QCstipple
))
3630 #ifdef HAVE_X_WINDOWS
3631 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
3632 if (!NILP (pixmap_p
))
3633 to
[LFACE_STIPPLE_INDEX
] = value
;
3635 add_to_log ("Invalid face stipple", value
, Qnil
);
3638 else if (EQ (keyword
, QCwidth
))
3641 && face_numeric_swidth (value
) >= 0)
3642 to
[LFACE_SWIDTH_INDEX
] = value
;
3644 add_to_log ("Invalid face width", value
, Qnil
);
3646 else if (EQ (keyword
, QCinherit
))
3648 if (SYMBOLP (value
))
3649 to
[LFACE_INHERIT_INDEX
] = value
;
3653 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
3654 if (!SYMBOLP (XCAR (tail
)))
3657 to
[LFACE_INHERIT_INDEX
] = value
;
3659 add_to_log ("Invalid face inherit", value
, Qnil
);
3663 add_to_log ("Invalid attribute %s in face property",
3666 prop
= XCDR (XCDR (prop
));
3671 /* This is a list of face specs. Specifications at the
3672 beginning of the list take precedence over later
3673 specifications, so we have to merge starting with the
3674 last specification. */
3675 Lisp_Object next
= XCDR (prop
);
3677 merge_face_vector_with_property (f
, to
, next
);
3678 merge_face_vector_with_property (f
, to
, first
);
3683 /* PROP ought to be a face name. */
3684 Lisp_Object lface
= lface_from_face_name (f
, prop
, 0);
3686 add_to_log ("Invalid face text property value: %s", prop
, Qnil
);
3688 merge_face_vectors (f
, XVECTOR (lface
)->contents
, to
, Qnil
);
3693 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
3694 Sinternal_make_lisp_face
, 1, 2, 0,
3695 doc
: /* Make FACE, a symbol, a Lisp face with all attributes nil.
3696 If FACE was not known as a face before, create a new one.
3697 If optional argument FRAME is specified, make a frame-local face
3698 for that frame. Otherwise operate on the global face definition.
3699 Value is a vector of face attributes. */)
3701 Lisp_Object face
, frame
;
3703 Lisp_Object global_lface
, lface
;
3707 CHECK_SYMBOL (face
);
3708 global_lface
= lface_from_face_name (NULL
, face
, 0);
3712 CHECK_LIVE_FRAME (frame
);
3714 lface
= lface_from_face_name (f
, face
, 0);
3717 f
= NULL
, lface
= Qnil
;
3719 /* Add a global definition if there is none. */
3720 if (NILP (global_lface
))
3722 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
3724 AREF (global_lface
, 0) = Qface
;
3725 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
3726 Vface_new_frame_defaults
);
3728 /* Assign the new Lisp face a unique ID. The mapping from Lisp
3729 face id to Lisp face is given by the vector lface_id_to_name.
3730 The mapping from Lisp face to Lisp face id is given by the
3731 property `face' of the Lisp face name. */
3732 if (next_lface_id
== lface_id_to_name_size
)
3734 int new_size
= max (50, 2 * lface_id_to_name_size
);
3735 int sz
= new_size
* sizeof *lface_id_to_name
;
3736 lface_id_to_name
= (Lisp_Object
*) xrealloc (lface_id_to_name
, sz
);
3737 lface_id_to_name_size
= new_size
;
3740 lface_id_to_name
[next_lface_id
] = face
;
3741 Fput (face
, Qface
, make_number (next_lface_id
));
3745 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3746 AREF (global_lface
, i
) = Qunspecified
;
3748 /* Add a frame-local definition. */
3753 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
3755 AREF (lface
, 0) = Qface
;
3756 f
->face_alist
= Fcons (Fcons (face
, lface
), f
->face_alist
);
3759 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3760 AREF (lface
, i
) = Qunspecified
;
3763 lface
= global_lface
;
3765 /* Changing a named face means that all realized faces depending on
3766 that face are invalid. Since we cannot tell which realized faces
3767 depend on the face, make sure they are all removed. This is done
3768 by incrementing face_change_count. The next call to
3769 init_iterator will then free realized faces. */
3770 ++face_change_count
;
3771 ++windows_or_buffers_changed
;
3773 xassert (LFACEP (lface
));
3774 check_lface (lface
);
3779 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
3780 Sinternal_lisp_face_p
, 1, 2, 0,
3781 doc
: /* Return non-nil if FACE names a face.
3782 If optional second parameter FRAME is non-nil, check for the
3783 existence of a frame-local face with name FACE on that frame.
3784 Otherwise check for the existence of a global face. */)
3786 Lisp_Object face
, frame
;
3792 CHECK_LIVE_FRAME (frame
);
3793 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3796 lface
= lface_from_face_name (NULL
, face
, 0);
3802 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
3803 Sinternal_copy_lisp_face
, 4, 4, 0,
3804 doc
: /* Copy face FROM to TO.
3805 If FRAME it t, copy the global face definition of FROM to the
3806 global face definition of TO. Otherwise, copy the frame-local
3807 definition of FROM on FRAME to the frame-local definition of TO
3808 on NEW-FRAME, or FRAME if NEW-FRAME is nil.
3811 (from
, to
, frame
, new_frame
)
3812 Lisp_Object from
, to
, frame
, new_frame
;
3814 Lisp_Object lface
, copy
;
3816 CHECK_SYMBOL (from
);
3818 if (NILP (new_frame
))
3823 /* Copy global definition of FROM. We don't make copies of
3824 strings etc. because 20.2 didn't do it either. */
3825 lface
= lface_from_face_name (NULL
, from
, 1);
3826 copy
= Finternal_make_lisp_face (to
, Qnil
);
3830 /* Copy frame-local definition of FROM. */
3831 CHECK_LIVE_FRAME (frame
);
3832 CHECK_LIVE_FRAME (new_frame
);
3833 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
3834 copy
= Finternal_make_lisp_face (to
, new_frame
);
3837 bcopy (XVECTOR (lface
)->contents
, XVECTOR (copy
)->contents
,
3838 LFACE_VECTOR_SIZE
* sizeof (Lisp_Object
));
3840 /* Changing a named face means that all realized faces depending on
3841 that face are invalid. Since we cannot tell which realized faces
3842 depend on the face, make sure they are all removed. This is done
3843 by incrementing face_change_count. The next call to
3844 init_iterator will then free realized faces. */
3845 ++face_change_count
;
3846 ++windows_or_buffers_changed
;
3852 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
3853 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
3854 doc
: /* Set attribute ATTR of FACE to VALUE.
3855 FRAME being a frame means change the face on that frame.
3856 FRAME nil means change the face of the selected frame.
3857 FRAME t means change the default for new frames.
3858 FRAME 0 means change the face on all frames, and change the default
3860 (face
, attr
, value
, frame
)
3861 Lisp_Object face
, attr
, value
, frame
;
3864 Lisp_Object old_value
= Qnil
;
3865 /* Set 1 if ATTR is QCfont. */
3866 int font_attr_p
= 0;
3867 /* Set 1 if ATTR is one of font-related attributes other than QCfont. */
3868 int font_related_attr_p
= 0;
3870 CHECK_SYMBOL (face
);
3871 CHECK_SYMBOL (attr
);
3873 face
= resolve_face_name (face
);
3875 /* If FRAME is 0, change face on all frames, and change the
3876 default for new frames. */
3877 if (INTEGERP (frame
) && XINT (frame
) == 0)
3880 Finternal_set_lisp_face_attribute (face
, attr
, value
, Qt
);
3881 FOR_EACH_FRAME (tail
, frame
)
3882 Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3886 /* Set lface to the Lisp attribute vector of FACE. */
3888 lface
= lface_from_face_name (NULL
, face
, 1);
3892 frame
= selected_frame
;
3894 CHECK_LIVE_FRAME (frame
);
3895 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3897 /* If a frame-local face doesn't exist yet, create one. */
3899 lface
= Finternal_make_lisp_face (face
, frame
);
3902 if (EQ (attr
, QCfamily
))
3904 if (!UNSPECIFIEDP (value
))
3906 CHECK_STRING (value
);
3907 if (SCHARS (value
) == 0)
3908 signal_error ("Invalid face family", value
);
3910 old_value
= LFACE_FAMILY (lface
);
3911 LFACE_FAMILY (lface
) = value
;
3912 font_related_attr_p
= 1;
3914 else if (EQ (attr
, QCheight
))
3916 if (!UNSPECIFIEDP (value
))
3920 test
= (EQ (face
, Qdefault
)
3922 /* The default face must have an absolute size,
3923 otherwise, we do a test merge with a random
3924 height to see if VALUE's ok. */
3925 : merge_face_heights (value
, make_number (10), Qnil
, Qnil
));
3927 if (!INTEGERP (test
) || XINT (test
) <= 0)
3928 signal_error ("Invalid face height", value
);
3931 old_value
= LFACE_HEIGHT (lface
);
3932 LFACE_HEIGHT (lface
) = value
;
3933 font_related_attr_p
= 1;
3935 else if (EQ (attr
, QCweight
))
3937 if (!UNSPECIFIEDP (value
))
3939 CHECK_SYMBOL (value
);
3940 if (face_numeric_weight (value
) < 0)
3941 signal_error ("Invalid face weight", value
);
3943 old_value
= LFACE_WEIGHT (lface
);
3944 LFACE_WEIGHT (lface
) = value
;
3945 font_related_attr_p
= 1;
3947 else if (EQ (attr
, QCslant
))
3949 if (!UNSPECIFIEDP (value
))
3951 CHECK_SYMBOL (value
);
3952 if (face_numeric_slant (value
) < 0)
3953 signal_error ("Invalid face slant", value
);
3955 old_value
= LFACE_SLANT (lface
);
3956 LFACE_SLANT (lface
) = value
;
3957 font_related_attr_p
= 1;
3959 else if (EQ (attr
, QCunderline
))
3961 if (!UNSPECIFIEDP (value
))
3962 if ((SYMBOLP (value
)
3964 && !EQ (value
, Qnil
))
3965 /* Underline color. */
3967 && SCHARS (value
) == 0))
3968 signal_error ("Invalid face underline", value
);
3970 old_value
= LFACE_UNDERLINE (lface
);
3971 LFACE_UNDERLINE (lface
) = value
;
3973 else if (EQ (attr
, QCoverline
))
3975 if (!UNSPECIFIEDP (value
))
3976 if ((SYMBOLP (value
)
3978 && !EQ (value
, Qnil
))
3979 /* Overline color. */
3981 && SCHARS (value
) == 0))
3982 signal_error ("Invalid face overline", value
);
3984 old_value
= LFACE_OVERLINE (lface
);
3985 LFACE_OVERLINE (lface
) = value
;
3987 else if (EQ (attr
, QCstrike_through
))
3989 if (!UNSPECIFIEDP (value
))
3990 if ((SYMBOLP (value
)
3992 && !EQ (value
, Qnil
))
3993 /* Strike-through color. */
3995 && SCHARS (value
) == 0))
3996 signal_error ("Invalid face strike-through", value
);
3998 old_value
= LFACE_STRIKE_THROUGH (lface
);
3999 LFACE_STRIKE_THROUGH (lface
) = value
;
4001 else if (EQ (attr
, QCbox
))
4005 /* Allow t meaning a simple box of width 1 in foreground color
4008 value
= make_number (1);
4010 if (UNSPECIFIEDP (value
))
4012 else if (NILP (value
))
4014 else if (INTEGERP (value
))
4015 valid_p
= XINT (value
) != 0;
4016 else if (STRINGP (value
))
4017 valid_p
= SCHARS (value
) > 0;
4018 else if (CONSP (value
))
4034 if (EQ (k
, QCline_width
))
4036 if (!INTEGERP (v
) || XINT (v
) == 0)
4039 else if (EQ (k
, QCcolor
))
4041 if (!STRINGP (v
) || SCHARS (v
) == 0)
4044 else if (EQ (k
, QCstyle
))
4046 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
4053 valid_p
= NILP (tem
);
4059 signal_error ("Invalid face box", value
);
4061 old_value
= LFACE_BOX (lface
);
4062 LFACE_BOX (lface
) = value
;
4064 else if (EQ (attr
, QCinverse_video
)
4065 || EQ (attr
, QCreverse_video
))
4067 if (!UNSPECIFIEDP (value
))
4069 CHECK_SYMBOL (value
);
4070 if (!EQ (value
, Qt
) && !NILP (value
))
4071 signal_error ("Invalid inverse-video face attribute value", value
);
4073 old_value
= LFACE_INVERSE (lface
);
4074 LFACE_INVERSE (lface
) = value
;
4076 else if (EQ (attr
, QCforeground
))
4078 if (!UNSPECIFIEDP (value
))
4080 /* Don't check for valid color names here because it depends
4081 on the frame (display) whether the color will be valid
4082 when the face is realized. */
4083 CHECK_STRING (value
);
4084 if (SCHARS (value
) == 0)
4085 signal_error ("Empty foreground color value", value
);
4087 old_value
= LFACE_FOREGROUND (lface
);
4088 LFACE_FOREGROUND (lface
) = value
;
4090 else if (EQ (attr
, QCbackground
))
4092 if (!UNSPECIFIEDP (value
))
4094 /* Don't check for valid color names here because it depends
4095 on the frame (display) whether the color will be valid
4096 when the face is realized. */
4097 CHECK_STRING (value
);
4098 if (SCHARS (value
) == 0)
4099 signal_error ("Empty background color value", value
);
4101 old_value
= LFACE_BACKGROUND (lface
);
4102 LFACE_BACKGROUND (lface
) = value
;
4104 else if (EQ (attr
, QCstipple
))
4106 #ifdef HAVE_X_WINDOWS
4107 if (!UNSPECIFIEDP (value
)
4109 && NILP (Fbitmap_spec_p (value
)))
4110 signal_error ("Invalid stipple attribute", value
);
4111 old_value
= LFACE_STIPPLE (lface
);
4112 LFACE_STIPPLE (lface
) = value
;
4113 #endif /* HAVE_X_WINDOWS */
4115 else if (EQ (attr
, QCwidth
))
4117 if (!UNSPECIFIEDP (value
))
4119 CHECK_SYMBOL (value
);
4120 if (face_numeric_swidth (value
) < 0)
4121 signal_error ("Invalid face width", value
);
4123 old_value
= LFACE_SWIDTH (lface
);
4124 LFACE_SWIDTH (lface
) = value
;
4125 font_related_attr_p
= 1;
4127 else if (EQ (attr
, QCfont
))
4129 #ifdef HAVE_WINDOW_SYSTEM
4130 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
4132 /* Set font-related attributes of the Lisp face from an XLFD
4137 CHECK_STRING (value
);
4139 f
= SELECTED_FRAME ();
4141 f
= check_x_frame (frame
);
4143 /* VALUE may be a fontset name or an alias of fontset. In
4144 such a case, use the base fontset name. */
4145 tmp
= Fquery_fontset (value
, Qnil
);
4149 if (!set_lface_from_font_name (f
, lface
, value
, 1, 1))
4150 signal_error ("Invalid font or fontset name", value
);
4154 #endif /* HAVE_WINDOW_SYSTEM */
4156 else if (EQ (attr
, QCinherit
))
4159 if (SYMBOLP (value
))
4162 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
4163 if (!SYMBOLP (XCAR (tail
)))
4166 LFACE_INHERIT (lface
) = value
;
4168 signal_error ("Invalid face inheritance", value
);
4170 else if (EQ (attr
, QCbold
))
4172 old_value
= LFACE_WEIGHT (lface
);
4173 LFACE_WEIGHT (lface
) = NILP (value
) ? Qnormal
: Qbold
;
4174 font_related_attr_p
= 1;
4176 else if (EQ (attr
, QCitalic
))
4178 old_value
= LFACE_SLANT (lface
);
4179 LFACE_SLANT (lface
) = NILP (value
) ? Qnormal
: Qitalic
;
4180 font_related_attr_p
= 1;
4183 signal_error ("Invalid face attribute name", attr
);
4185 if (font_related_attr_p
4186 && !UNSPECIFIEDP (value
))
4187 /* If a font-related attribute other than QCfont is specified, the
4188 original `font' attribute nor that of default face is useless
4189 to determine a new font. Thus, we set it to nil so that font
4190 selection mechanism doesn't use it. */
4191 LFACE_FONT (lface
) = Qnil
;
4193 /* Changing a named face means that all realized faces depending on
4194 that face are invalid. Since we cannot tell which realized faces
4195 depend on the face, make sure they are all removed. This is done
4196 by incrementing face_change_count. The next call to
4197 init_iterator will then free realized faces. */
4199 && (EQ (attr
, QCfont
)
4200 || NILP (Fequal (old_value
, value
))))
4202 ++face_change_count
;
4203 ++windows_or_buffers_changed
;
4206 if (!UNSPECIFIEDP (value
)
4207 && NILP (Fequal (old_value
, value
)))
4213 if (EQ (face
, Qdefault
))
4215 #ifdef HAVE_WINDOW_SYSTEM
4216 /* Changed font-related attributes of the `default' face are
4217 reflected in changed `font' frame parameters. */
4219 && (font_related_attr_p
|| font_attr_p
)
4220 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
4221 set_font_frame_param (frame
, lface
);
4223 #endif /* HAVE_WINDOW_SYSTEM */
4225 if (EQ (attr
, QCforeground
))
4226 param
= Qforeground_color
;
4227 else if (EQ (attr
, QCbackground
))
4228 param
= Qbackground_color
;
4230 #ifdef HAVE_WINDOW_SYSTEM
4232 else if (EQ (face
, Qscroll_bar
))
4234 /* Changing the colors of `scroll-bar' sets frame parameters
4235 `scroll-bar-foreground' and `scroll-bar-background'. */
4236 if (EQ (attr
, QCforeground
))
4237 param
= Qscroll_bar_foreground
;
4238 else if (EQ (attr
, QCbackground
))
4239 param
= Qscroll_bar_background
;
4241 #endif /* not WINDOWSNT */
4242 else if (EQ (face
, Qborder
))
4244 /* Changing background color of `border' sets frame parameter
4246 if (EQ (attr
, QCbackground
))
4247 param
= Qborder_color
;
4249 else if (EQ (face
, Qcursor
))
4251 /* Changing background color of `cursor' sets frame parameter
4253 if (EQ (attr
, QCbackground
))
4254 param
= Qcursor_color
;
4256 else if (EQ (face
, Qmouse
))
4258 /* Changing background color of `mouse' sets frame parameter
4260 if (EQ (attr
, QCbackground
))
4261 param
= Qmouse_color
;
4263 #endif /* HAVE_WINDOW_SYSTEM */
4264 else if (EQ (face
, Qmenu
))
4266 /* Indicate that we have to update the menu bar when
4267 realizing faces on FRAME. FRAME t change the
4268 default for new frames. We do this by setting
4269 setting the flag in new face caches */
4272 struct frame
*f
= XFRAME (frame
);
4273 if (FRAME_FACE_CACHE (f
) == NULL
)
4274 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
4275 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 1;
4278 menu_face_changed_default
= 1;
4284 /* Update `default-frame-alist', which is used for new frames. */
4286 store_in_alist (&Vdefault_frame_alist
, param
, value
);
4289 /* Update the current frame's parameters. */
4292 cons
= XCAR (Vparam_value_alist
);
4293 XSETCAR (cons
, param
);
4294 XSETCDR (cons
, value
);
4295 Fmodify_frame_parameters (frame
, Vparam_value_alist
);
4304 #ifdef HAVE_WINDOW_SYSTEM
4306 /* Set the `font' frame parameter of FRAME determined from `default'
4307 face attributes LFACE. If a face or fontset name is explicitely
4308 specfied in LFACE, use it as is. Otherwise, determine a font name
4309 from the other font-related atrributes of LFACE. In that case, if
4310 there's no matching font, signals an error. */
4313 set_font_frame_param (frame
, lface
)
4314 Lisp_Object frame
, lface
;
4316 struct frame
*f
= XFRAME (frame
);
4318 if (FRAME_WINDOW_P (f
))
4320 Lisp_Object font_name
;
4323 if (STRINGP (LFACE_FONT (lface
)))
4324 font_name
= LFACE_FONT (lface
);
4327 /* Choose a font name that reflects LFACE's attributes and has
4328 the registry and encoding pattern specified in the default
4329 fontset (3rd arg: -1) for ASCII characters (4th arg: 0). */
4330 font
= choose_face_font (f
, XVECTOR (lface
)->contents
, -1, 0);
4332 error ("No font matches the specified attribute");
4333 font_name
= build_string (font
);
4337 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, font_name
), Qnil
));
4342 /* Update the corresponding face when frame parameter PARAM on frame F
4343 has been assigned the value NEW_VALUE. */
4346 update_face_from_frame_parameter (f
, param
, new_value
)
4348 Lisp_Object param
, new_value
;
4352 /* If there are no faces yet, give up. This is the case when called
4353 from Fx_create_frame, and we do the necessary things later in
4354 face-set-after-frame-defaults. */
4355 if (NILP (f
->face_alist
))
4358 /* Changing a named face means that all realized faces depending on
4359 that face are invalid. Since we cannot tell which realized faces
4360 depend on the face, make sure they are all removed. This is done
4361 by incrementing face_change_count. The next call to
4362 init_iterator will then free realized faces. */
4363 ++face_change_count
;
4364 ++windows_or_buffers_changed
;
4366 if (EQ (param
, Qforeground_color
))
4368 lface
= lface_from_face_name (f
, Qdefault
, 1);
4369 LFACE_FOREGROUND (lface
) = (STRINGP (new_value
)
4370 ? new_value
: Qunspecified
);
4371 realize_basic_faces (f
);
4373 else if (EQ (param
, Qbackground_color
))
4377 /* Changing the background color might change the background
4378 mode, so that we have to load new defface specs. Call
4379 frame-update-face-colors to do that. */
4380 XSETFRAME (frame
, f
);
4381 call1 (Qframe_update_face_colors
, frame
);
4383 lface
= lface_from_face_name (f
, Qdefault
, 1);
4384 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4385 ? new_value
: Qunspecified
);
4386 realize_basic_faces (f
);
4388 if (EQ (param
, Qborder_color
))
4390 lface
= lface_from_face_name (f
, Qborder
, 1);
4391 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4392 ? new_value
: Qunspecified
);
4394 else if (EQ (param
, Qcursor_color
))
4396 lface
= lface_from_face_name (f
, Qcursor
, 1);
4397 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4398 ? new_value
: Qunspecified
);
4400 else if (EQ (param
, Qmouse_color
))
4402 lface
= lface_from_face_name (f
, Qmouse
, 1);
4403 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4404 ? new_value
: Qunspecified
);
4409 /* Get the value of X resource RESOURCE, class CLASS for the display
4410 of frame FRAME. This is here because ordinary `x-get-resource'
4411 doesn't take a frame argument. */
4413 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
4414 Sinternal_face_x_get_resource
, 3, 3, 0, doc
: /* */)
4415 (resource
, class, frame
)
4416 Lisp_Object resource
, class, frame
;
4418 Lisp_Object value
= Qnil
;
4421 CHECK_STRING (resource
);
4422 CHECK_STRING (class);
4423 CHECK_LIVE_FRAME (frame
);
4425 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame
)),
4426 resource
, class, Qnil
, Qnil
);
4428 #endif /* not MAC_OS */
4429 #endif /* not WINDOWSNT */
4434 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
4435 If VALUE is "on" or "true", return t. If VALUE is "off" or
4436 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
4437 error; if SIGNAL_P is zero, return 0. */
4440 face_boolean_x_resource_value (value
, signal_p
)
4444 Lisp_Object result
= make_number (0);
4446 xassert (STRINGP (value
));
4448 if (xstricmp (SDATA (value
), "on") == 0
4449 || xstricmp (SDATA (value
), "true") == 0)
4451 else if (xstricmp (SDATA (value
), "off") == 0
4452 || xstricmp (SDATA (value
), "false") == 0)
4454 else if (xstricmp (SDATA (value
), "unspecified") == 0)
4455 result
= Qunspecified
;
4457 signal_error ("Invalid face attribute value from X resource", value
);
4463 DEFUN ("internal-set-lisp-face-attribute-from-resource",
4464 Finternal_set_lisp_face_attribute_from_resource
,
4465 Sinternal_set_lisp_face_attribute_from_resource
,
4466 3, 4, 0, doc
: /* */)
4467 (face
, attr
, value
, frame
)
4468 Lisp_Object face
, attr
, value
, frame
;
4470 CHECK_SYMBOL (face
);
4471 CHECK_SYMBOL (attr
);
4472 CHECK_STRING (value
);
4474 if (xstricmp (SDATA (value
), "unspecified") == 0)
4475 value
= Qunspecified
;
4476 else if (EQ (attr
, QCheight
))
4478 value
= Fstring_to_number (value
, make_number (10));
4479 if (XINT (value
) <= 0)
4480 signal_error ("Invalid face height from X resource", value
);
4482 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
4483 value
= face_boolean_x_resource_value (value
, 1);
4484 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
4485 value
= intern (SDATA (value
));
4486 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
4487 value
= face_boolean_x_resource_value (value
, 1);
4488 else if (EQ (attr
, QCunderline
)
4489 || EQ (attr
, QCoverline
)
4490 || EQ (attr
, QCstrike_through
))
4492 Lisp_Object boolean_value
;
4494 /* If the result of face_boolean_x_resource_value is t or nil,
4495 VALUE does NOT specify a color. */
4496 boolean_value
= face_boolean_x_resource_value (value
, 0);
4497 if (SYMBOLP (boolean_value
))
4498 value
= boolean_value
;
4500 else if (EQ (attr
, QCbox
))
4501 value
= Fcar (Fread_from_string (value
, Qnil
, Qnil
));
4503 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
4506 #endif /* HAVE_WINDOW_SYSTEM */
4509 /***********************************************************************
4511 ***********************************************************************/
4513 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
4515 /* Make menus on frame F appear as specified by the `menu' face. */
4518 x_update_menu_appearance (f
)
4521 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
4525 && (rdb
= XrmGetDatabase (FRAME_X_DISPLAY (f
)),
4529 Lisp_Object lface
= lface_from_face_name (f
, Qmenu
, 1);
4530 struct face
*face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
4531 const char *myname
= SDATA (Vx_resource_name
);
4534 const char *popup_path
= "popup_menu";
4536 const char *popup_path
= "menu.popup";
4539 if (STRINGP (LFACE_FOREGROUND (lface
)))
4541 sprintf (line
, "%s.%s*foreground: %s",
4543 SDATA (LFACE_FOREGROUND (lface
)));
4544 XrmPutLineResource (&rdb
, line
);
4545 sprintf (line
, "%s.pane.menubar*foreground: %s",
4546 myname
, SDATA (LFACE_FOREGROUND (lface
)));
4547 XrmPutLineResource (&rdb
, line
);
4551 if (STRINGP (LFACE_BACKGROUND (lface
)))
4553 sprintf (line
, "%s.%s*background: %s",
4555 SDATA (LFACE_BACKGROUND (lface
)));
4556 XrmPutLineResource (&rdb
, line
);
4557 sprintf (line
, "%s.pane.menubar*background: %s",
4558 myname
, SDATA (LFACE_BACKGROUND (lface
)));
4559 XrmPutLineResource (&rdb
, line
);
4564 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
4565 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
4566 || !UNSPECIFIEDP (LFACE_AVGWIDTH (lface
))
4567 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
4568 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
4569 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
4572 const char *suffix
= "List";
4574 const char *suffix
= "";
4576 sprintf (line
, "%s.pane.menubar*font%s: %s",
4577 myname
, suffix
, face
->font_name
);
4578 XrmPutLineResource (&rdb
, line
);
4579 sprintf (line
, "%s.%s*font%s: %s",
4580 myname
, popup_path
, suffix
, face
->font_name
);
4581 XrmPutLineResource (&rdb
, line
);
4585 if (changed_p
&& f
->output_data
.x
->menubar_widget
)
4586 free_frame_menubar (f
);
4590 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
4593 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p
,
4594 Sface_attribute_relative_p
,
4596 doc
: /* Return non-nil if face ATTRIBUTE VALUE is relative. */)
4598 Lisp_Object attribute
, value
;
4600 if (EQ (value
, Qunspecified
))
4602 else if (EQ (attribute
, QCheight
))
4603 return INTEGERP (value
) ? Qnil
: Qt
;
4608 DEFUN ("merge-face-attribute", Fmerge_face_attribute
, Smerge_face_attribute
,
4610 doc
: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
4611 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
4612 the result will be absolute, otherwise it will be relative. */)
4613 (attribute
, value1
, value2
)
4614 Lisp_Object attribute
, value1
, value2
;
4616 if (EQ (value1
, Qunspecified
))
4618 else if (EQ (attribute
, QCheight
))
4619 return merge_face_heights (value1
, value2
, value1
, Qnil
);
4625 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
4626 Sinternal_get_lisp_face_attribute
,
4628 doc
: /* Return face attribute KEYWORD of face SYMBOL.
4629 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
4630 face attribute name, signal an error.
4631 If the optional argument FRAME is given, report on face FACE in that
4632 frame. If FRAME is t, report on the defaults for face FACE (for new
4633 frames). If FRAME is omitted or nil, use the selected frame. */)
4634 (symbol
, keyword
, frame
)
4635 Lisp_Object symbol
, keyword
, frame
;
4637 Lisp_Object lface
, value
= Qnil
;
4639 CHECK_SYMBOL (symbol
);
4640 CHECK_SYMBOL (keyword
);
4643 lface
= lface_from_face_name (NULL
, symbol
, 1);
4647 frame
= selected_frame
;
4648 CHECK_LIVE_FRAME (frame
);
4649 lface
= lface_from_face_name (XFRAME (frame
), symbol
, 1);
4652 if (EQ (keyword
, QCfamily
))
4653 value
= LFACE_FAMILY (lface
);
4654 else if (EQ (keyword
, QCheight
))
4655 value
= LFACE_HEIGHT (lface
);
4656 else if (EQ (keyword
, QCweight
))
4657 value
= LFACE_WEIGHT (lface
);
4658 else if (EQ (keyword
, QCslant
))
4659 value
= LFACE_SLANT (lface
);
4660 else if (EQ (keyword
, QCunderline
))
4661 value
= LFACE_UNDERLINE (lface
);
4662 else if (EQ (keyword
, QCoverline
))
4663 value
= LFACE_OVERLINE (lface
);
4664 else if (EQ (keyword
, QCstrike_through
))
4665 value
= LFACE_STRIKE_THROUGH (lface
);
4666 else if (EQ (keyword
, QCbox
))
4667 value
= LFACE_BOX (lface
);
4668 else if (EQ (keyword
, QCinverse_video
)
4669 || EQ (keyword
, QCreverse_video
))
4670 value
= LFACE_INVERSE (lface
);
4671 else if (EQ (keyword
, QCforeground
))
4672 value
= LFACE_FOREGROUND (lface
);
4673 else if (EQ (keyword
, QCbackground
))
4674 value
= LFACE_BACKGROUND (lface
);
4675 else if (EQ (keyword
, QCstipple
))
4676 value
= LFACE_STIPPLE (lface
);
4677 else if (EQ (keyword
, QCwidth
))
4678 value
= LFACE_SWIDTH (lface
);
4679 else if (EQ (keyword
, QCinherit
))
4680 value
= LFACE_INHERIT (lface
);
4681 else if (EQ (keyword
, QCfont
))
4682 value
= LFACE_FONT (lface
);
4684 signal_error ("Invalid face attribute name", keyword
);
4690 DEFUN ("internal-lisp-face-attribute-values",
4691 Finternal_lisp_face_attribute_values
,
4692 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
4693 doc
: /* Return a list of valid discrete values for face attribute ATTR.
4694 Value is nil if ATTR doesn't have a discrete set of valid values. */)
4698 Lisp_Object result
= Qnil
;
4700 CHECK_SYMBOL (attr
);
4702 if (EQ (attr
, QCweight
)
4703 || EQ (attr
, QCslant
)
4704 || EQ (attr
, QCwidth
))
4706 /* Extract permissible symbols from tables. */
4707 struct table_entry
*table
;
4710 if (EQ (attr
, QCweight
))
4711 table
= weight_table
, dim
= DIM (weight_table
);
4712 else if (EQ (attr
, QCslant
))
4713 table
= slant_table
, dim
= DIM (slant_table
);
4715 table
= swidth_table
, dim
= DIM (swidth_table
);
4717 for (i
= 0; i
< dim
; ++i
)
4719 Lisp_Object symbol
= *table
[i
].symbol
;
4720 Lisp_Object tail
= result
;
4723 && !EQ (XCAR (tail
), symbol
))
4727 result
= Fcons (symbol
, result
);
4730 else if (EQ (attr
, QCunderline
))
4731 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4732 else if (EQ (attr
, QCoverline
))
4733 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4734 else if (EQ (attr
, QCstrike_through
))
4735 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4736 else if (EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
4737 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4743 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
4744 Sinternal_merge_in_global_face
, 2, 2, 0,
4745 doc
: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
4746 Default face attributes override any local face attributes. */)
4748 Lisp_Object face
, frame
;
4751 Lisp_Object global_lface
, local_lface
, *gvec
, *lvec
;
4753 CHECK_LIVE_FRAME (frame
);
4754 global_lface
= lface_from_face_name (NULL
, face
, 1);
4755 local_lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
4756 if (NILP (local_lface
))
4757 local_lface
= Finternal_make_lisp_face (face
, frame
);
4759 /* Make every specified global attribute override the local one.
4760 BEWARE!! This is only used from `face-set-after-frame-default' where
4761 the local frame is defined from default specs in `face-defface-spec'
4762 and those should be overridden by global settings. Hence the strange
4763 "global before local" priority. */
4764 lvec
= XVECTOR (local_lface
)->contents
;
4765 gvec
= XVECTOR (global_lface
)->contents
;
4766 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4767 if (! UNSPECIFIEDP (gvec
[i
]))
4774 /* The following function is implemented for compatibility with 20.2.
4775 The function is used in x-resolve-fonts when it is asked to
4776 return fonts with the same size as the font of a face. This is
4777 done in fontset.el. */
4779 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 2, 0,
4780 doc
: /* Return the font name of face FACE, or nil if it is unspecified.
4781 If the optional argument FRAME is given, report on face FACE in that frame.
4782 If FRAME is t, report on the defaults for face FACE (for new frames).
4783 The font default for a face is either nil, or a list
4784 of the form (bold), (italic) or (bold italic).
4785 If FRAME is omitted or nil, use the selected frame. */)
4787 Lisp_Object face
, frame
;
4791 Lisp_Object result
= Qnil
;
4792 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
4794 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
4795 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
4796 result
= Fcons (Qbold
, result
);
4798 if (!UNSPECIFIEDP (LFACE_SLANT (lface
))
4799 && !EQ (LFACE_SLANT (lface
), Qnormal
))
4800 result
= Fcons (Qitalic
, result
);
4806 struct frame
*f
= frame_or_selected_frame (frame
, 1);
4807 int face_id
= lookup_named_face (f
, face
, 0);
4808 struct face
*face
= FACE_FROM_ID (f
, face_id
);
4809 return face
? build_string (face
->font_name
) : Qnil
;
4814 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
4815 all attributes are `equal'. Tries to be fast because this function
4816 is called quite often. */
4819 lface_equal_p (v1
, v2
)
4820 Lisp_Object
*v1
, *v2
;
4824 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
4826 Lisp_Object a
= v1
[i
];
4827 Lisp_Object b
= v2
[i
];
4829 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
4830 and the other is specified. */
4831 equal_p
= XTYPE (a
) == XTYPE (b
);
4840 equal_p
= ((SBYTES (a
)
4842 && bcmp (SDATA (a
), SDATA (b
),
4852 equal_p
= !NILP (Fequal (a
, b
));
4862 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
4863 Sinternal_lisp_face_equal_p
, 2, 3, 0,
4864 doc
: /* True if FACE1 and FACE2 are equal.
4865 If the optional argument FRAME is given, report on face FACE in that frame.
4866 If FRAME is t, report on the defaults for face FACE (for new frames).
4867 If FRAME is omitted or nil, use the selected frame. */)
4868 (face1
, face2
, frame
)
4869 Lisp_Object face1
, face2
, frame
;
4873 Lisp_Object lface1
, lface2
;
4878 /* Don't use check_x_frame here because this function is called
4879 before X frames exist. At that time, if FRAME is nil,
4880 selected_frame will be used which is the frame dumped with
4881 Emacs. That frame is not an X frame. */
4882 f
= frame_or_selected_frame (frame
, 2);
4884 lface1
= lface_from_face_name (NULL
, face1
, 1);
4885 lface2
= lface_from_face_name (NULL
, face2
, 1);
4886 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
4887 XVECTOR (lface2
)->contents
);
4888 return equal_p
? Qt
: Qnil
;
4892 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
4893 Sinternal_lisp_face_empty_p
, 1, 2, 0,
4894 doc
: /* True if FACE has no attribute specified.
4895 If the optional argument FRAME is given, report on face FACE in that frame.
4896 If FRAME is t, report on the defaults for face FACE (for new frames).
4897 If FRAME is omitted or nil, use the selected frame. */)
4899 Lisp_Object face
, frame
;
4906 frame
= selected_frame
;
4907 CHECK_LIVE_FRAME (frame
);
4911 lface
= lface_from_face_name (NULL
, face
, 1);
4913 lface
= lface_from_face_name (f
, face
, 1);
4915 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4916 if (!UNSPECIFIEDP (AREF (lface
, i
)))
4919 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
4923 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
4925 doc
: /* Return an alist of frame-local faces defined on FRAME.
4926 For internal use only. */)
4930 struct frame
*f
= frame_or_selected_frame (frame
, 0);
4931 return f
->face_alist
;
4935 /* Return a hash code for Lisp string STRING with case ignored. Used
4936 below in computing a hash value for a Lisp face. */
4938 static INLINE
unsigned
4939 hash_string_case_insensitive (string
)
4942 const unsigned char *s
;
4944 xassert (STRINGP (string
));
4945 for (s
= SDATA (string
); *s
; ++s
)
4946 hash
= (hash
<< 1) ^ tolower (*s
);
4951 /* Return a hash code for face attribute vector V. */
4953 static INLINE
unsigned
4957 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
4958 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
4959 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
4960 ^ XFASTINT (v
[LFACE_WEIGHT_INDEX
])
4961 ^ XFASTINT (v
[LFACE_SLANT_INDEX
])
4962 ^ XFASTINT (v
[LFACE_SWIDTH_INDEX
])
4963 ^ XFASTINT (v
[LFACE_HEIGHT_INDEX
]));
4967 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
4968 considering charsets/registries). They do if they specify the same
4969 family, point size, weight, width, slant, and fontset. Both LFACE1
4970 and LFACE2 must be fully-specified. */
4973 lface_same_font_attributes_p (lface1
, lface2
)
4974 Lisp_Object
*lface1
, *lface2
;
4976 xassert (lface_fully_specified_p (lface1
)
4977 && lface_fully_specified_p (lface2
));
4978 return (xstricmp (SDATA (lface1
[LFACE_FAMILY_INDEX
]),
4979 SDATA (lface2
[LFACE_FAMILY_INDEX
])) == 0
4980 && EQ (lface1
[LFACE_HEIGHT_INDEX
], lface2
[LFACE_HEIGHT_INDEX
])
4981 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
4982 && EQ (lface1
[LFACE_AVGWIDTH_INDEX
], lface2
[LFACE_AVGWIDTH_INDEX
])
4983 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
4984 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
])
4985 && (EQ (lface1
[LFACE_FONT_INDEX
], lface2
[LFACE_FONT_INDEX
])
4986 || (STRINGP (lface1
[LFACE_FONT_INDEX
])
4987 && STRINGP (lface2
[LFACE_FONT_INDEX
])
4988 && xstricmp (SDATA (lface1
[LFACE_FONT_INDEX
]),
4989 SDATA (lface2
[LFACE_FONT_INDEX
])))));
4994 /***********************************************************************
4996 ***********************************************************************/
4998 /* Allocate and return a new realized face for Lisp face attribute
5001 static struct face
*
5002 make_realized_face (attr
)
5005 struct face
*face
= (struct face
*) xmalloc (sizeof *face
);
5006 bzero (face
, sizeof *face
);
5007 face
->ascii_face
= face
;
5008 bcopy (attr
, face
->lface
, sizeof face
->lface
);
5013 /* Free realized face FACE, including its X resources. FACE may
5017 free_realized_face (f
, face
)
5023 #ifdef HAVE_WINDOW_SYSTEM
5024 if (FRAME_WINDOW_P (f
))
5026 /* Free fontset of FACE if it is ASCII face. */
5027 if (face
->fontset
>= 0 && face
== face
->ascii_face
)
5028 free_face_fontset (f
, face
);
5031 x_free_gc (f
, face
->gc
);
5035 free_face_colors (f
, face
);
5036 x_destroy_bitmap (f
, face
->stipple
);
5038 #endif /* HAVE_WINDOW_SYSTEM */
5045 /* Prepare face FACE for subsequent display on frame F. This
5046 allocated GCs if they haven't been allocated yet or have been freed
5047 by clearing the face cache. */
5050 prepare_face_for_display (f
, face
)
5054 #ifdef HAVE_WINDOW_SYSTEM
5055 xassert (FRAME_WINDOW_P (f
));
5060 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
5062 xgcv
.foreground
= face
->foreground
;
5063 xgcv
.background
= face
->background
;
5064 #ifdef HAVE_X_WINDOWS
5065 xgcv
.graphics_exposures
= False
;
5067 /* The font of FACE may be null if we couldn't load it. */
5070 #ifdef HAVE_X_WINDOWS
5071 xgcv
.font
= face
->font
->fid
;
5074 xgcv
.font
= face
->font
;
5077 xgcv
.font
= face
->font
;
5083 #ifdef HAVE_X_WINDOWS
5086 xgcv
.fill_style
= FillOpaqueStippled
;
5087 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
5088 mask
|= GCFillStyle
| GCStipple
;
5091 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
5094 #endif /* HAVE_WINDOW_SYSTEM */
5098 /* Returns the `distance' between the colors X and Y. */
5101 color_distance (x
, y
)
5104 /* This formula is from a paper title `Colour metric' by Thiadmer Riemersma.
5105 Quoting from that paper:
5107 This formula has results that are very close to L*u*v* (with the
5108 modified lightness curve) and, more importantly, it is a more even
5109 algorithm: it does not have a range of colours where it suddenly
5110 gives far from optimal results.
5112 See <http://www.compuphase.com/cmetric.htm> for more info. */
5114 long r
= (x
->red
- y
->red
) >> 8;
5115 long g
= (x
->green
- y
->green
) >> 8;
5116 long b
= (x
->blue
- y
->blue
) >> 8;
5117 long r_mean
= (x
->red
+ y
->red
) >> 9;
5120 (((512 + r_mean
) * r
* r
) >> 8)
5122 + (((767 - r_mean
) * b
* b
) >> 8);
5126 DEFUN ("color-distance", Fcolor_distance
, Scolor_distance
, 2, 3, 0,
5127 doc
: /* Return an integer distance between COLOR1 and COLOR2 on FRAME.
5128 COLOR1 and COLOR2 may be either strings containing the color name,
5129 or lists of the form (RED GREEN BLUE).
5130 If FRAME is unspecified or nil, the current frame is used. */)
5131 (color1
, color2
, frame
)
5132 Lisp_Object color1
, color2
, frame
;
5135 XColor cdef1
, cdef2
;
5138 frame
= selected_frame
;
5139 CHECK_LIVE_FRAME (frame
);
5142 if ((CONSP (color1
) && !parse_rgb_list (color1
, &cdef1
))
5143 || !STRINGP (color1
)
5144 || !defined_color (f
, SDATA (color1
), &cdef1
, 0))
5145 signal_error ("Invalid color", color1
);
5146 if ((CONSP (color2
) && !parse_rgb_list (color2
, &cdef2
))
5147 || !STRINGP (color2
)
5148 || !defined_color (f
, SDATA (color2
), &cdef2
, 0))
5149 signal_error ("Invalid color", color2
);
5151 return make_number (color_distance (&cdef1
, &cdef2
));
5155 /***********************************************************************
5156 Face capability testing for ttys
5157 ***********************************************************************/
5160 /* If the distance (as returned by color_distance) between two colors is
5161 less than this, then they are considered the same, for determining
5162 whether a color is supported or not. The range of values is 0-65535. */
5164 #define TTY_SAME_COLOR_THRESHOLD 10000
5167 DEFUN ("tty-supports-face-attributes-p",
5168 Ftty_supports_face_attributes_p
, Stty_supports_face_attributes_p
,
5170 doc
: /* Return non-nil if all the face attributes in ATTRIBUTES are supported.
5171 The optional argument FRAME is the frame on which to test; if it is nil
5172 or unspecified, then the current frame is used. If FRAME is not a tty
5173 frame, then nil is returned.
5175 The definition of `supported' is somewhat heuristic, but basically means
5176 that a face containing all the attributes in ATTRIBUTES, when merged
5177 with the default face for display, can be represented in a way that's
5179 \(1) different in appearance than the default face, and
5180 \(2) `close in spirit' to what the attributes specify, if not exact.
5182 Point (2) implies that a `:weight black' attribute will be satisified
5183 by any terminal that can display bold, and a `:foreground "yellow"' as
5184 long as the terminal can display a yellowish color, but `:slant italic'
5185 will _not_ be satisified by the tty display code's automatic
5186 substitution of a `dim' face for italic. */)
5188 Lisp_Object attributes
, frame
;
5192 Lisp_Object val
, fg
, bg
;
5193 XColor fg_tty_color
, fg_std_color
;
5194 XColor bg_tty_color
, bg_std_color
;
5195 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5196 unsigned test_caps
= 0;
5199 frame
= selected_frame
;
5200 CHECK_LIVE_FRAME (frame
);
5203 for (i
= 0; i
< LFACE_VECTOR_SIZE
; i
++)
5204 attrs
[i
] = Qunspecified
;
5205 merge_face_vector_with_property (f
, attrs
, attributes
);
5207 /* This function only works on ttys. */
5208 if (!FRAME_TERMCAP_P (f
) && !FRAME_MSDOS_P (f
))
5211 /* First check some easy-to-check stuff; ttys support none of the
5212 following attributes, so we can just return nil if any are requested. */
5215 val
= attrs
[LFACE_STIPPLE_INDEX
];
5216 if (!UNSPECIFIEDP (val
) && !NILP (val
))
5220 val
= attrs
[LFACE_HEIGHT_INDEX
];
5221 if (!UNSPECIFIEDP (val
) && !NILP (val
))
5225 val
= attrs
[LFACE_SWIDTH_INDEX
];
5226 if (!UNSPECIFIEDP (val
) && !NILP (val
)
5227 && face_numeric_swidth (val
) != XLFD_SWIDTH_MEDIUM
)
5231 val
= attrs
[LFACE_OVERLINE_INDEX
];
5232 if (!UNSPECIFIEDP (val
) && !NILP (val
))
5235 /* strike-through */
5236 val
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
5237 if (!UNSPECIFIEDP (val
) && !NILP (val
))
5241 val
= attrs
[LFACE_BOX_INDEX
];
5242 if (!UNSPECIFIEDP (val
) && !NILP (val
))
5245 /* slant (italics/oblique); We consider any non-default value
5246 unsupportable on ttys, even though the face code actually `fakes'
5247 them using a dim attribute if possible. This is because the faked
5248 result is too different from what the face specifies. */
5249 val
= attrs
[LFACE_SLANT_INDEX
];
5250 if (!UNSPECIFIEDP (val
) && !NILP (val
)
5251 && face_numeric_slant (val
) != XLFD_SLANT_ROMAN
)
5255 /* Test for terminal `capabilities' (non-color character attributes). */
5257 /* font weight (bold/dim) */
5258 weight
= face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
5261 if (weight
> XLFD_WEIGHT_MEDIUM
)
5262 test_caps
= TTY_CAP_BOLD
;
5263 else if (weight
< XLFD_WEIGHT_MEDIUM
)
5264 test_caps
= TTY_CAP_DIM
;
5268 val
= attrs
[LFACE_UNDERLINE_INDEX
];
5269 if (!UNSPECIFIEDP (val
) && !NILP (val
))
5272 return Qnil
; /* ttys don't support colored underlines */
5274 test_caps
|= TTY_CAP_UNDERLINE
;
5278 val
= attrs
[LFACE_INVERSE_INDEX
];
5279 if (!UNSPECIFIEDP (val
) && !NILP (val
))
5280 test_caps
|= TTY_CAP_INVERSE
;
5283 /* Color testing. */
5285 /* Default the color indices in FG_TTY_COLOR and BG_TTY_COLOR, since
5286 we use them when calling `tty_capable_p' below, even if the face
5287 specifies no colors. */
5288 fg_tty_color
.pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5289 bg_tty_color
.pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5291 /* Check if foreground color is close enough. */
5292 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
5295 if (! tty_lookup_color (f
, fg
, &fg_tty_color
, &fg_std_color
))
5297 else if (color_distance (&fg_tty_color
, &fg_std_color
)
5298 > TTY_SAME_COLOR_THRESHOLD
)
5302 /* Check if background color is close enough. */
5303 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
5306 if (! tty_lookup_color (f
, bg
, &bg_tty_color
, &bg_std_color
))
5308 else if (color_distance (&bg_tty_color
, &bg_std_color
)
5309 > TTY_SAME_COLOR_THRESHOLD
)
5313 /* If both foreground and background are requested, see if the
5314 distance between them is OK. We just check to see if the distance
5315 between the tty's foreground and background is close enough to the
5316 distance between the standard foreground and background. */
5317 if (STRINGP (fg
) && STRINGP (bg
))
5320 = (color_distance (&fg_std_color
, &bg_std_color
)
5321 - color_distance (&fg_tty_color
, &bg_tty_color
));
5322 if (delta_delta
> TTY_SAME_COLOR_THRESHOLD
5323 || delta_delta
< -TTY_SAME_COLOR_THRESHOLD
)
5328 /* See if the capabilities we selected above are supported, with the
5330 if (test_caps
!= 0 &&
5331 ! tty_capable_p (f
, test_caps
, fg_tty_color
.pixel
, bg_tty_color
.pixel
))
5335 /* Hmmm, everything checks out, this terminal must support this face. */
5341 /***********************************************************************
5343 ***********************************************************************/
5345 /* Return a new face cache for frame F. */
5347 static struct face_cache
*
5351 struct face_cache
*c
;
5354 c
= (struct face_cache
*) xmalloc (sizeof *c
);
5355 bzero (c
, sizeof *c
);
5356 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
5357 c
->buckets
= (struct face
**) xmalloc (size
);
5358 bzero (c
->buckets
, size
);
5360 c
->faces_by_id
= (struct face
**) xmalloc (c
->size
* sizeof *c
->faces_by_id
);
5362 c
->menu_face_changed_p
= menu_face_changed_default
;
5367 /* Clear out all graphics contexts for all realized faces, except for
5368 the basic faces. This should be done from time to time just to avoid
5369 keeping too many graphics contexts that are no longer needed. */
5373 struct face_cache
*c
;
5375 if (c
&& FRAME_WINDOW_P (c
->f
))
5377 #ifdef HAVE_WINDOW_SYSTEM
5379 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
5381 struct face
*face
= c
->faces_by_id
[i
];
5382 if (face
&& face
->gc
)
5384 x_free_gc (c
->f
, face
->gc
);
5388 #endif /* HAVE_WINDOW_SYSTEM */
5393 /* Free all realized faces in face cache C, including basic faces. C
5394 may be null. If faces are freed, make sure the frame's current
5395 matrix is marked invalid, so that a display caused by an expose
5396 event doesn't try to use faces we destroyed. */
5399 free_realized_faces (c
)
5400 struct face_cache
*c
;
5405 struct frame
*f
= c
->f
;
5407 /* We must block input here because we can't process X events
5408 safely while only some faces are freed, or when the frame's
5409 current matrix still references freed faces. */
5412 for (i
= 0; i
< c
->used
; ++i
)
5414 free_realized_face (f
, c
->faces_by_id
[i
]);
5415 c
->faces_by_id
[i
] = NULL
;
5419 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
5420 bzero (c
->buckets
, size
);
5422 /* Must do a thorough redisplay the next time. Mark current
5423 matrices as invalid because they will reference faces freed
5424 above. This function is also called when a frame is
5425 destroyed. In this case, the root window of F is nil. */
5426 if (WINDOWP (f
->root_window
))
5428 clear_current_matrices (f
);
5429 ++windows_or_buffers_changed
;
5437 /* Free all faces realized for multibyte characters on frame F that
5441 free_realized_multibyte_face (f
, fontset
)
5445 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5449 /* We must block input here because we can't process X events safely
5450 while only some faces are freed, or when the frame's current
5451 matrix still references freed faces. */
5454 for (i
= 0; i
< cache
->used
; i
++)
5456 face
= cache
->faces_by_id
[i
];
5458 && face
!= face
->ascii_face
5459 && face
->fontset
== fontset
)
5461 uncache_face (cache
, face
);
5462 free_realized_face (f
, face
);
5466 /* Must do a thorough redisplay the next time. Mark current
5467 matrices as invalid because they will reference faces freed
5468 above. This function is also called when a frame is destroyed.
5469 In this case, the root window of F is nil. */
5470 if (WINDOWP (f
->root_window
))
5472 clear_current_matrices (f
);
5473 ++windows_or_buffers_changed
;
5480 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
5481 This is done after attributes of a named face have been changed,
5482 because we can't tell which realized faces depend on that face. */
5485 free_all_realized_faces (frame
)
5491 FOR_EACH_FRAME (rest
, frame
)
5492 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
5495 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
5499 /* Free face cache C and faces in it, including their X resources. */
5503 struct face_cache
*c
;
5507 free_realized_faces (c
);
5509 xfree (c
->faces_by_id
);
5515 /* Cache realized face FACE in face cache C. HASH is the hash value
5516 of FACE. If FACE->fontset >= 0, add the new face to the end of the
5517 collision list of the face hash table of C. This is done because
5518 otherwise lookup_face would find FACE for every character, even if
5519 faces with the same attributes but for specific characters exist. */
5522 cache_face (c
, face
, hash
)
5523 struct face_cache
*c
;
5527 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
5531 if (face
->fontset
>= 0)
5533 struct face
*last
= c
->buckets
[i
];
5544 c
->buckets
[i
] = face
;
5545 face
->prev
= face
->next
= NULL
;
5551 face
->next
= c
->buckets
[i
];
5553 face
->next
->prev
= face
;
5554 c
->buckets
[i
] = face
;
5557 /* Find a free slot in C->faces_by_id and use the index of the free
5558 slot as FACE->id. */
5559 for (i
= 0; i
< c
->used
; ++i
)
5560 if (c
->faces_by_id
[i
] == NULL
)
5564 /* Maybe enlarge C->faces_by_id. */
5565 if (i
== c
->used
&& c
->used
== c
->size
)
5567 int new_size
= 2 * c
->size
;
5568 int sz
= new_size
* sizeof *c
->faces_by_id
;
5569 c
->faces_by_id
= (struct face
**) xrealloc (c
->faces_by_id
, sz
);
5574 /* Check that FACE got a unique id. */
5579 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
5580 for (face
= c
->buckets
[j
]; face
; face
= face
->next
)
5586 #endif /* GLYPH_DEBUG */
5588 c
->faces_by_id
[i
] = face
;
5594 /* Remove face FACE from cache C. */
5597 uncache_face (c
, face
)
5598 struct face_cache
*c
;
5601 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
5604 face
->prev
->next
= face
->next
;
5606 c
->buckets
[i
] = face
->next
;
5609 face
->next
->prev
= face
->prev
;
5611 c
->faces_by_id
[face
->id
] = NULL
;
5612 if (face
->id
== c
->used
)
5617 /* Look up a realized face with face attributes ATTR in the face cache
5618 of frame F. The face will be used to display character C. Value
5619 is the ID of the face found. If no suitable face is found, realize
5620 a new one. In that case, if C is a multibyte character, BASE_FACE
5621 is a face that has the same attributes. */
5624 lookup_face (f
, attr
, c
, base_face
)
5628 struct face
*base_face
;
5630 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5635 xassert (cache
!= NULL
);
5636 check_lface_attrs (attr
);
5638 /* Look up ATTR in the face cache. */
5639 hash
= lface_hash (attr
);
5640 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
5642 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
5643 if (face
->hash
== hash
5644 && (!FRAME_WINDOW_P (f
)
5645 || FACE_SUITABLE_FOR_CHAR_P (face
, c
))
5646 && lface_equal_p (face
->lface
, attr
))
5649 /* If not found, realize a new face. */
5651 face
= realize_face (cache
, attr
, c
, base_face
, -1);
5654 xassert (face
== FACE_FROM_ID (f
, face
->id
));
5656 /* When this function is called from face_for_char (in this case, C is
5657 a multibyte character), a fontset of a face returned by
5658 realize_face is not yet set, i.e. FACE_SUITABLE_FOR_CHAR_P (FACE,
5659 C) is not sutisfied. The fontset is set for this face by
5660 face_for_char later. */
5662 if (FRAME_WINDOW_P (f
))
5663 xassert (FACE_SUITABLE_FOR_CHAR_P (face
, c
));
5665 #endif /* GLYPH_DEBUG */
5671 /* Return the face id of the realized face for named face SYMBOL on
5672 frame F suitable for displaying character C. Value is -1 if the
5673 face couldn't be determined, which might happen if the default face
5674 isn't realized and cannot be realized. */
5677 lookup_named_face (f
, symbol
, c
)
5682 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5683 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5684 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5686 if (default_face
== NULL
)
5688 if (!realize_basic_faces (f
))
5690 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5693 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
5694 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
5695 merge_face_vectors (f
, symbol_attrs
, attrs
, Qnil
);
5696 return lookup_face (f
, attrs
, c
, NULL
);
5700 /* Return the ID of the realized ASCII face of Lisp face with ID
5701 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
5704 ascii_face_of_lisp_face (f
, lface_id
)
5710 if (lface_id
>= 0 && lface_id
< lface_id_to_name_size
)
5712 Lisp_Object face_name
= lface_id_to_name
[lface_id
];
5713 face_id
= lookup_named_face (f
, face_name
, 0);
5722 /* Return a face for charset ASCII that is like the face with id
5723 FACE_ID on frame F, but has a font that is STEPS steps smaller.
5724 STEPS < 0 means larger. Value is the id of the face. */
5727 smaller_face (f
, face_id
, steps
)
5731 #ifdef HAVE_WINDOW_SYSTEM
5733 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5734 int pt
, last_pt
, last_height
;
5737 struct face
*new_face
;
5739 /* If not called for an X frame, just return the original face. */
5740 if (FRAME_TERMCAP_P (f
))
5743 /* Try in increments of 1/2 pt. */
5744 delta
= steps
< 0 ? 5 : -5;
5745 steps
= abs (steps
);
5747 face
= FACE_FROM_ID (f
, face_id
);
5748 bcopy (face
->lface
, attrs
, sizeof attrs
);
5749 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
5750 new_face_id
= face_id
;
5751 last_height
= FONT_HEIGHT (face
->font
);
5755 /* Give up if we cannot find a font within 10pt. */
5756 && abs (last_pt
- pt
) < 100)
5758 /* Look up a face for a slightly smaller/larger font. */
5760 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
5761 new_face_id
= lookup_face (f
, attrs
, 0, NULL
);
5762 new_face
= FACE_FROM_ID (f
, new_face_id
);
5764 /* If height changes, count that as one step. */
5765 if ((delta
< 0 && FONT_HEIGHT (new_face
->font
) < last_height
)
5766 || (delta
> 0 && FONT_HEIGHT (new_face
->font
) > last_height
))
5769 last_height
= FONT_HEIGHT (new_face
->font
);
5776 #else /* not HAVE_WINDOW_SYSTEM */
5780 #endif /* not HAVE_WINDOW_SYSTEM */
5784 /* Return a face for charset ASCII that is like the face with id
5785 FACE_ID on frame F, but has height HEIGHT. */
5788 face_with_height (f
, face_id
, height
)
5793 #ifdef HAVE_WINDOW_SYSTEM
5795 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5797 if (FRAME_TERMCAP_P (f
)
5801 face
= FACE_FROM_ID (f
, face_id
);
5802 bcopy (face
->lface
, attrs
, sizeof attrs
);
5803 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
5804 face_id
= lookup_face (f
, attrs
, 0, NULL
);
5805 #endif /* HAVE_WINDOW_SYSTEM */
5811 /* Return the face id of the realized face for named face SYMBOL on
5812 frame F suitable for displaying character C, and use attributes of
5813 the face FACE_ID for attributes that aren't completely specified by
5814 SYMBOL. This is like lookup_named_face, except that the default
5815 attributes come from FACE_ID, not from the default face. FACE_ID
5816 is assumed to be already realized. */
5819 lookup_derived_face (f
, symbol
, c
, face_id
)
5825 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5826 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5827 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
5832 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
5833 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
5834 merge_face_vectors (f
, symbol_attrs
, attrs
, Qnil
);
5835 return lookup_face (f
, attrs
, c
, default_face
);
5838 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector
,
5839 Sface_attributes_as_vector
, 1, 1, 0,
5840 doc
: /* Return a vector of face attributes corresponding to PLIST. */)
5845 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
5847 merge_face_vector_with_property (XFRAME (selected_frame
),
5848 XVECTOR (lface
)->contents
,
5855 /***********************************************************************
5857 ***********************************************************************/
5859 DEFUN ("internal-set-font-selection-order",
5860 Finternal_set_font_selection_order
,
5861 Sinternal_set_font_selection_order
, 1, 1, 0,
5862 doc
: /* Set font selection order for face font selection to ORDER.
5863 ORDER must be a list of length 4 containing the symbols `:width',
5864 `:height', `:weight', and `:slant'. Face attributes appearing
5865 first in ORDER are matched first, e.g. if `:height' appears before
5866 `:weight' in ORDER, font selection first tries to find a font with
5867 a suitable height, and then tries to match the font weight.
5874 int indices
[DIM (font_sort_order
)];
5877 bzero (indices
, sizeof indices
);
5881 CONSP (list
) && i
< DIM (indices
);
5882 list
= XCDR (list
), ++i
)
5884 Lisp_Object attr
= XCAR (list
);
5887 if (EQ (attr
, QCwidth
))
5889 else if (EQ (attr
, QCheight
))
5890 xlfd
= XLFD_POINT_SIZE
;
5891 else if (EQ (attr
, QCweight
))
5893 else if (EQ (attr
, QCslant
))
5898 if (indices
[i
] != 0)
5903 if (!NILP (list
) || i
!= DIM (indices
))
5904 signal_error ("Invalid font sort order", order
);
5905 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5906 if (indices
[i
] == 0)
5907 signal_error ("Invalid font sort order", order
);
5909 if (bcmp (indices
, font_sort_order
, sizeof indices
) != 0)
5911 bcopy (indices
, font_sort_order
, sizeof font_sort_order
);
5912 free_all_realized_faces (Qnil
);
5919 DEFUN ("internal-set-alternative-font-family-alist",
5920 Finternal_set_alternative_font_family_alist
,
5921 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
5922 doc
: /* Define alternative font families to try in face font selection.
5923 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5924 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
5925 be found. Value is ALIST. */)
5930 Vface_alternative_font_family_alist
= alist
;
5931 free_all_realized_faces (Qnil
);
5936 DEFUN ("internal-set-alternative-font-registry-alist",
5937 Finternal_set_alternative_font_registry_alist
,
5938 Sinternal_set_alternative_font_registry_alist
, 1, 1, 0,
5939 doc
: /* Define alternative font registries to try in face font selection.
5940 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5941 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
5942 be found. Value is ALIST. */)
5947 Vface_alternative_font_registry_alist
= alist
;
5948 free_all_realized_faces (Qnil
);
5953 #ifdef HAVE_WINDOW_SYSTEM
5955 /* Value is non-zero if FONT is the name of a scalable font. The
5956 X11R6 XLFD spec says that point size, pixel size, and average width
5957 are zero for scalable fonts. Intlfonts contain at least one
5958 scalable font ("*-muleindian-1") for which this isn't true, so we
5959 just test average width. */
5962 font_scalable_p (font
)
5963 struct font_name
*font
;
5965 char *s
= font
->fields
[XLFD_AVGWIDTH
];
5966 return (*s
== '0' && *(s
+ 1) == '\0')
5968 /* Windows implementation of XLFD is slightly broken for backward
5969 compatibility with previous broken versions, so test for
5970 wildcards as well as 0. */
5977 /* Ignore the difference of font point size less than this value. */
5979 #define FONT_POINT_SIZE_QUANTUM 5
5981 /* Value is non-zero if FONT1 is a better match for font attributes
5982 VALUES than FONT2. VALUES is an array of face attribute values in
5983 font sort order. COMPARE_PT_P zero means don't compare point
5984 sizes. AVGWIDTH, if not zero, is a specified font average width
5988 better_font_p (values
, font1
, font2
, compare_pt_p
, avgwidth
)
5990 struct font_name
*font1
, *font2
;
5991 int compare_pt_p
, avgwidth
;
5995 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5997 int xlfd_idx
= font_sort_order
[i
];
5999 if (compare_pt_p
|| xlfd_idx
!= XLFD_POINT_SIZE
)
6001 int delta1
= abs (values
[i
] - font1
->numeric
[xlfd_idx
]);
6002 int delta2
= abs (values
[i
] - font2
->numeric
[xlfd_idx
]);
6004 if (xlfd_idx
== XLFD_POINT_SIZE
6005 && abs (delta1
- delta2
) < FONT_POINT_SIZE_QUANTUM
)
6007 if (delta1
> delta2
)
6009 else if (delta1
< delta2
)
6013 /* The difference may be equal because, e.g., the face
6014 specifies `italic' but we have only `regular' and
6015 `oblique'. Prefer `oblique' in this case. */
6016 if ((xlfd_idx
== XLFD_WEIGHT
|| xlfd_idx
== XLFD_SLANT
)
6017 && font1
->numeric
[xlfd_idx
] > values
[i
]
6018 && font2
->numeric
[xlfd_idx
] < values
[i
])
6026 int delta1
= abs (avgwidth
- font1
->numeric
[XLFD_AVGWIDTH
]);
6027 int delta2
= abs (avgwidth
- font2
->numeric
[XLFD_AVGWIDTH
]);
6028 if (delta1
> delta2
)
6030 else if (delta1
< delta2
)
6034 return font1
->registry_priority
< font2
->registry_priority
;
6038 /* Value is non-zero if FONT is an exact match for face attributes in
6039 SPECIFIED. SPECIFIED is an array of face attribute values in font
6040 sort order. AVGWIDTH, if non-zero, is an average width to compare
6044 exact_face_match_p (specified
, font
, avgwidth
)
6046 struct font_name
*font
;
6051 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6052 if (specified
[i
] != font
->numeric
[font_sort_order
[i
]])
6055 return (i
== DIM (font_sort_order
)
6057 || avgwidth
== font
->numeric
[XLFD_AVGWIDTH
]));
6061 /* Value is the name of a scaled font, generated from scalable font
6062 FONT on frame F. SPECIFIED_PT is the point-size to scale FONT to.
6063 Value is allocated from heap. */
6066 build_scalable_font_name (f
, font
, specified_pt
)
6068 struct font_name
*font
;
6071 char point_size
[20], pixel_size
[20];
6073 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
6076 /* If scalable font is for a specific resolution, compute
6077 the point size we must specify from the resolution of
6078 the display and the specified resolution of the font. */
6079 if (font
->numeric
[XLFD_RESY
] != 0)
6081 pt
= resy
/ font
->numeric
[XLFD_RESY
] * specified_pt
+ 0.5;
6082 pixel_value
= font
->numeric
[XLFD_RESY
] / (PT_PER_INCH
* 10.0) * pt
;
6087 pixel_value
= resy
/ (PT_PER_INCH
* 10.0) * pt
;
6090 /* Set point size of the font. */
6091 sprintf (point_size
, "%d", (int) pt
);
6092 font
->fields
[XLFD_POINT_SIZE
] = point_size
;
6093 font
->numeric
[XLFD_POINT_SIZE
] = pt
;
6095 /* Set pixel size. */
6096 sprintf (pixel_size
, "%d", pixel_value
);
6097 font
->fields
[XLFD_PIXEL_SIZE
] = pixel_size
;
6098 font
->numeric
[XLFD_PIXEL_SIZE
] = pixel_value
;
6100 /* If font doesn't specify its resolution, use the
6101 resolution of the display. */
6102 if (font
->numeric
[XLFD_RESY
] == 0)
6105 sprintf (buffer
, "%d", (int) resy
);
6106 font
->fields
[XLFD_RESY
] = buffer
;
6107 font
->numeric
[XLFD_RESY
] = resy
;
6110 if (strcmp (font
->fields
[XLFD_RESX
], "0") == 0)
6113 int resx
= FRAME_X_DISPLAY_INFO (f
)->resx
;
6114 sprintf (buffer
, "%d", resx
);
6115 font
->fields
[XLFD_RESX
] = buffer
;
6116 font
->numeric
[XLFD_RESX
] = resx
;
6119 return build_font_name (font
);
6123 /* Value is non-zero if we are allowed to use scalable font FONT. We
6124 can't run a Lisp function here since this function may be called
6125 with input blocked. */
6128 may_use_scalable_font_p (font
)
6131 if (EQ (Vscalable_fonts_allowed
, Qt
))
6133 else if (CONSP (Vscalable_fonts_allowed
))
6135 Lisp_Object tail
, regexp
;
6137 for (tail
= Vscalable_fonts_allowed
; CONSP (tail
); tail
= XCDR (tail
))
6139 regexp
= XCAR (tail
);
6140 if (STRINGP (regexp
)
6141 && fast_c_string_match_ignore_case (regexp
, font
) >= 0)
6151 /* Return the name of the best matching font for face attributes ATTRS
6152 in the array of font_name structures FONTS which contains NFONTS
6153 elements. WIDTH_RATIO is a factor with which to multiply average
6154 widths if ATTRS specifies such a width.
6156 Value is a font name which is allocated from the heap. FONTS is
6157 freed by this function. */
6160 best_matching_font (f
, attrs
, fonts
, nfonts
, width_ratio
)
6163 struct font_name
*fonts
;
6168 struct font_name
*best
;
6171 int exact_p
, avgwidth
;
6176 /* Make specified font attributes available in `specified',
6177 indexed by sort order. */
6178 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6180 int xlfd_idx
= font_sort_order
[i
];
6182 if (xlfd_idx
== XLFD_SWIDTH
)
6183 specified
[i
] = face_numeric_swidth (attrs
[LFACE_SWIDTH_INDEX
]);
6184 else if (xlfd_idx
== XLFD_POINT_SIZE
)
6185 specified
[i
] = pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
6186 else if (xlfd_idx
== XLFD_WEIGHT
)
6187 specified
[i
] = face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
6188 else if (xlfd_idx
== XLFD_SLANT
)
6189 specified
[i
] = face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
6194 avgwidth
= (UNSPECIFIEDP (attrs
[LFACE_AVGWIDTH_INDEX
])
6196 : XFASTINT (attrs
[LFACE_AVGWIDTH_INDEX
]) * width_ratio
);
6200 /* Start with the first non-scalable font in the list. */
6201 for (i
= 0; i
< nfonts
; ++i
)
6202 if (!font_scalable_p (fonts
+ i
))
6205 /* Find the best match among the non-scalable fonts. */
6210 for (i
= 1; i
< nfonts
; ++i
)
6211 if (!font_scalable_p (fonts
+ i
)
6212 && better_font_p (specified
, fonts
+ i
, best
, 1, avgwidth
))
6216 exact_p
= exact_face_match_p (specified
, best
, avgwidth
);
6225 /* Unless we found an exact match among non-scalable fonts, see if
6226 we can find a better match among scalable fonts. */
6229 /* A scalable font is better if
6231 1. its weight, slant, swidth attributes are better, or.
6233 2. the best non-scalable font doesn't have the required
6234 point size, and the scalable fonts weight, slant, swidth
6237 int non_scalable_has_exact_height_p
;
6239 if (best
&& best
->numeric
[XLFD_POINT_SIZE
] == pt
)
6240 non_scalable_has_exact_height_p
= 1;
6242 non_scalable_has_exact_height_p
= 0;
6244 for (i
= 0; i
< nfonts
; ++i
)
6245 if (font_scalable_p (fonts
+ i
))
6248 || better_font_p (specified
, fonts
+ i
, best
, 0, 0)
6249 || (!non_scalable_has_exact_height_p
6250 && !better_font_p (specified
, best
, fonts
+ i
, 0, 0)))
6255 if (font_scalable_p (best
))
6256 font_name
= build_scalable_font_name (f
, best
, pt
);
6258 font_name
= build_font_name (best
);
6260 /* Free font_name structures. */
6261 free_font_names (fonts
, nfonts
);
6267 /* Get a list of matching fonts on frame F, considering FAMILY
6268 and alternative font families from Vface_alternative_font_registry_alist.
6270 FAMILY is the font family whose alternatives are considered.
6272 REGISTRY, if a string, specifies a font registry and encoding to
6273 match. A value of nil means include fonts of any registry and
6276 Return in *FONTS a pointer to a vector of font_name structures for
6277 the fonts matched. Value is the number of fonts found. */
6280 try_alternative_families (f
, family
, registry
, fonts
)
6282 Lisp_Object family
, registry
;
6283 struct font_name
**fonts
;
6288 nfonts
= font_list (f
, Qnil
, family
, registry
, fonts
);
6291 /* Try alternative font families. */
6292 alter
= Fassoc (family
, Vface_alternative_font_family_alist
);
6295 for (alter
= XCDR (alter
);
6296 CONSP (alter
) && nfonts
== 0;
6297 alter
= XCDR (alter
))
6299 if (STRINGP (XCAR (alter
)))
6300 nfonts
= font_list (f
, Qnil
, XCAR (alter
), registry
, fonts
);
6304 /* Try scalable fonts before giving up. */
6305 if (nfonts
== 0 && NILP (Vscalable_fonts_allowed
))
6307 int count
= SPECPDL_INDEX ();
6308 specbind (Qscalable_fonts_allowed
, Qt
);
6309 nfonts
= try_alternative_families (f
, family
, registry
, fonts
);
6310 unbind_to (count
, Qnil
);
6317 /* Get a list of matching fonts on frame F.
6319 FAMILY, if a string, specifies a font family derived from the fontset.
6320 It is only used if the face does not specify any family in ATTRS or
6321 if we cannot find any font of the face's family.
6323 REGISTRY, if a string, specifies a font registry and encoding to
6324 match. A value of nil means include fonts of any registry and
6327 Return in *FONTS a pointer to a vector of font_name structures for
6328 the fonts matched. Value is the number of fonts found. */
6331 try_font_list (f
, attrs
, family
, registry
, fonts
)
6334 Lisp_Object family
, registry
;
6335 struct font_name
**fonts
;
6338 Lisp_Object face_family
= attrs
[LFACE_FAMILY_INDEX
];
6340 if (STRINGP (face_family
))
6341 nfonts
= try_alternative_families (f
, face_family
, registry
, fonts
);
6344 /* When realizing the default face and a font spec does not matched
6345 exactly, Emacs looks for ones with the same registry as the
6346 default font. On the Mac, this is mac-roman, which does not work
6347 if the family is -etl-fixed, e.g. The following widens the
6348 choices and fixes that problem. */
6349 if (nfonts
== 0 && STRINGP (face_family
) && STRINGP (registry
)
6350 && xstricmp (SDATA (registry
), "mac-roman") == 0)
6351 nfonts
= try_alternative_families (f
, face_family
, Qnil
, fonts
);
6354 if (nfonts
== 0 && !NILP (family
))
6355 nfonts
= try_alternative_families (f
, family
, registry
, fonts
);
6357 /* Try font family of the default face or "fixed". */
6360 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6362 family
= default_face
->lface
[LFACE_FAMILY_INDEX
];
6364 family
= build_string ("fixed");
6365 nfonts
= font_list (f
, Qnil
, family
, registry
, fonts
);
6368 /* Try any family with the given registry. */
6370 nfonts
= font_list (f
, Qnil
, Qnil
, registry
, fonts
);
6376 /* Return the fontset id of the base fontset name or alias name given
6377 by the fontset attribute of ATTRS. Value is -1 if the fontset
6378 attribute of ATTRS doesn't name a fontset. */
6381 face_fontset (attrs
)
6386 name
= attrs
[LFACE_FONT_INDEX
];
6387 if (!STRINGP (name
))
6389 return fs_query_fontset (name
, 0);
6393 /* Choose a name of font to use on frame F to display character C with
6394 Lisp face attributes specified by ATTRS. The font name is
6395 determined by the font-related attributes in ATTRS and the name
6396 pattern for C in FONTSET. Value is the font name which is
6397 allocated from the heap and must be freed by the caller, or NULL if
6398 we can get no information about the font name of C. It is assured
6399 that we always get some information for a single byte
6403 choose_face_font (f
, attrs
, fontset
, c
)
6408 Lisp_Object pattern
;
6409 char *font_name
= NULL
;
6410 struct font_name
*fonts
;
6411 int nfonts
, width_ratio
;
6413 /* Get (foundry and) family name and registry (and encoding) name of
6415 pattern
= fontset_font_pattern (f
, fontset
, c
);
6418 xassert (!SINGLE_BYTE_CHAR_P (c
));
6422 /* If what we got is a name pattern, return it. */
6423 if (STRINGP (pattern
))
6424 return xstrdup (SDATA (pattern
));
6426 /* Get a list of fonts matching that pattern and choose the
6427 best match for the specified face attributes from it. */
6428 nfonts
= try_font_list (f
, attrs
, XCAR (pattern
), XCDR (pattern
), &fonts
);
6429 width_ratio
= (SINGLE_BYTE_CHAR_P (c
)
6431 : CHARSET_WIDTH (CHAR_CHARSET (c
)));
6432 font_name
= best_matching_font (f
, attrs
, fonts
, nfonts
, width_ratio
);
6436 #endif /* HAVE_WINDOW_SYSTEM */
6440 /***********************************************************************
6442 ***********************************************************************/
6444 /* Realize basic faces on frame F. Value is zero if frame parameters
6445 of F don't contain enough information needed to realize the default
6449 realize_basic_faces (f
)
6453 int count
= SPECPDL_INDEX ();
6455 /* Block input here so that we won't be surprised by an X expose
6456 event, for instance, without having the faces set up. */
6458 specbind (Qscalable_fonts_allowed
, Qt
);
6460 if (realize_default_face (f
))
6462 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
6463 realize_named_face (f
, Qmode_line_inactive
, MODE_LINE_INACTIVE_FACE_ID
);
6464 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
6465 realize_named_face (f
, Qfringe
, FRINGE_FACE_ID
);
6466 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
6467 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
6468 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
6469 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
6470 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
6471 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
6473 /* Reflect changes in the `menu' face in menu bars. */
6474 if (FRAME_FACE_CACHE (f
)->menu_face_changed_p
)
6476 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 0;
6477 #ifdef USE_X_TOOLKIT
6478 x_update_menu_appearance (f
);
6485 unbind_to (count
, Qnil
);
6491 /* Realize the default face on frame F. If the face is not fully
6492 specified, make it fully-specified. Attributes of the default face
6493 that are not explicitly specified are taken from frame parameters. */
6496 realize_default_face (f
)
6499 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
6501 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6502 Lisp_Object frame_font
;
6505 /* If the `default' face is not yet known, create it. */
6506 lface
= lface_from_face_name (f
, Qdefault
, 0);
6510 XSETFRAME (frame
, f
);
6511 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
6514 #ifdef HAVE_WINDOW_SYSTEM
6515 if (FRAME_WINDOW_P (f
))
6517 /* Set frame_font to the value of the `font' frame parameter. */
6518 frame_font
= Fassq (Qfont
, f
->param_alist
);
6519 xassert (CONSP (frame_font
) && STRINGP (XCDR (frame_font
)));
6520 frame_font
= XCDR (frame_font
);
6521 set_lface_from_font_name (f
, lface
, frame_font
, 1, 1);
6523 #endif /* HAVE_WINDOW_SYSTEM */
6525 if (!FRAME_WINDOW_P (f
))
6527 LFACE_FAMILY (lface
) = build_string ("default");
6528 LFACE_SWIDTH (lface
) = Qnormal
;
6529 LFACE_HEIGHT (lface
) = make_number (1);
6530 if (UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
6531 LFACE_WEIGHT (lface
) = Qnormal
;
6532 if (UNSPECIFIEDP (LFACE_SLANT (lface
)))
6533 LFACE_SLANT (lface
) = Qnormal
;
6534 LFACE_AVGWIDTH (lface
) = Qunspecified
;
6537 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
6538 LFACE_UNDERLINE (lface
) = Qnil
;
6540 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
6541 LFACE_OVERLINE (lface
) = Qnil
;
6543 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
6544 LFACE_STRIKE_THROUGH (lface
) = Qnil
;
6546 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
6547 LFACE_BOX (lface
) = Qnil
;
6549 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
6550 LFACE_INVERSE (lface
) = Qnil
;
6552 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
6554 /* This function is called so early that colors are not yet
6555 set in the frame parameter list. */
6556 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
6558 if (CONSP (color
) && STRINGP (XCDR (color
)))
6559 LFACE_FOREGROUND (lface
) = XCDR (color
);
6560 else if (FRAME_WINDOW_P (f
))
6562 else if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
6563 LFACE_FOREGROUND (lface
) = build_string (unspecified_fg
);
6568 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
6570 /* This function is called so early that colors are not yet
6571 set in the frame parameter list. */
6572 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
6573 if (CONSP (color
) && STRINGP (XCDR (color
)))
6574 LFACE_BACKGROUND (lface
) = XCDR (color
);
6575 else if (FRAME_WINDOW_P (f
))
6577 else if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
6578 LFACE_BACKGROUND (lface
) = build_string (unspecified_bg
);
6583 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
6584 LFACE_STIPPLE (lface
) = Qnil
;
6586 /* Realize the face; it must be fully-specified now. */
6587 xassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
6588 check_lface (lface
);
6589 bcopy (XVECTOR (lface
)->contents
, attrs
, sizeof attrs
);
6590 face
= realize_face (c
, attrs
, 0, NULL
, DEFAULT_FACE_ID
);
6595 /* Realize basic faces other than the default face in face cache C.
6596 SYMBOL is the face name, ID is the face id the realized face must
6597 have. The default face must have been realized already. */
6600 realize_named_face (f
, symbol
, id
)
6605 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
6606 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
6607 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6608 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
6609 struct face
*new_face
;
6611 /* The default face must exist and be fully specified. */
6612 get_lface_attributes (f
, Qdefault
, attrs
, 1);
6613 check_lface_attrs (attrs
);
6614 xassert (lface_fully_specified_p (attrs
));
6616 /* If SYMBOL isn't know as a face, create it. */
6620 XSETFRAME (frame
, f
);
6621 lface
= Finternal_make_lisp_face (symbol
, frame
);
6624 /* Merge SYMBOL's face with the default face. */
6625 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
6626 merge_face_vectors (f
, symbol_attrs
, attrs
, Qnil
);
6628 /* Realize the face. */
6629 new_face
= realize_face (c
, attrs
, 0, NULL
, id
);
6633 /* Realize the fully-specified face with attributes ATTRS in face
6634 cache CACHE for character C. If C is a multibyte character,
6635 BASE_FACE is a face that has the same attributes. Otherwise,
6636 BASE_FACE is ignored. If FORMER_FACE_ID is non-negative, it is an
6637 ID of face to remove before caching the new face. Value is a
6638 pointer to the newly created realized face. */
6640 static struct face
*
6641 realize_face (cache
, attrs
, c
, base_face
, former_face_id
)
6642 struct face_cache
*cache
;
6645 struct face
*base_face
;
6650 /* LFACE must be fully specified. */
6651 xassert (cache
!= NULL
);
6652 check_lface_attrs (attrs
);
6654 if (former_face_id
>= 0 && cache
->used
> former_face_id
)
6656 /* Remove the former face. */
6657 struct face
*former_face
= cache
->faces_by_id
[former_face_id
];
6658 uncache_face (cache
, former_face
);
6659 free_realized_face (cache
->f
, former_face
);
6662 if (FRAME_WINDOW_P (cache
->f
))
6663 face
= realize_x_face (cache
, attrs
, c
, base_face
);
6664 else if (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
))
6665 face
= realize_tty_face (cache
, attrs
, c
);
6669 /* Insert the new face. */
6670 cache_face (cache
, face
, lface_hash (attrs
));
6671 #ifdef HAVE_WINDOW_SYSTEM
6672 if (FRAME_WINDOW_P (cache
->f
) && face
->font
== NULL
)
6673 load_face_font (cache
->f
, face
, c
);
6674 #endif /* HAVE_WINDOW_SYSTEM */
6679 /* Realize the fully-specified face with attributes ATTRS in face
6680 cache CACHE for character C. Do it for X frame CACHE->f. If C is
6681 a multibyte character, BASE_FACE is a face that has the same
6682 attributes. Otherwise, BASE_FACE is ignored. If the new face
6683 doesn't share font with the default face, a fontname is allocated
6684 from the heap and set in `font_name' of the new face, but it is not
6685 yet loaded here. Value is a pointer to the newly created realized
6688 static struct face
*
6689 realize_x_face (cache
, attrs
, c
, base_face
)
6690 struct face_cache
*cache
;
6693 struct face
*base_face
;
6695 #ifdef HAVE_WINDOW_SYSTEM
6696 struct face
*face
, *default_face
;
6698 Lisp_Object stipple
, overline
, strike_through
, box
;
6700 xassert (FRAME_WINDOW_P (cache
->f
));
6701 xassert (SINGLE_BYTE_CHAR_P (c
)
6704 /* Allocate a new realized face. */
6705 face
= make_realized_face (attrs
);
6709 /* If C is a multibyte character, we share all face attirbutes with
6710 BASE_FACE including the realized fontset. But, we must load a
6712 if (!SINGLE_BYTE_CHAR_P (c
))
6714 bcopy (base_face
, face
, sizeof *face
);
6717 /* Don't try to free the colors copied bitwise from BASE_FACE. */
6718 face
->colors_copied_bitwise_p
= 1;
6720 /* to force realize_face to load font */
6725 /* Now we are realizing a face for ASCII (and unibyte) characters. */
6727 /* Determine the font to use. Most of the time, the font will be
6728 the same as the font of the default face, so try that first. */
6729 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6731 && FACE_SUITABLE_FOR_CHAR_P (default_face
, c
)
6732 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
6734 face
->font
= default_face
->font
;
6735 face
->fontset
= default_face
->fontset
;
6736 face
->font_info_id
= default_face
->font_info_id
;
6737 face
->font_name
= default_face
->font_name
;
6738 face
->ascii_face
= face
;
6740 /* But, as we can't share the fontset, make a new realized
6741 fontset that has the same base fontset as of the default
6744 = make_fontset_for_ascii_face (f
, default_face
->fontset
);
6748 /* If the face attribute ATTRS specifies a fontset, use it as
6749 the base of a new realized fontset. Otherwise, use the same
6750 base fontset as of the default face. The base determines
6751 registry and encoding of a font. It may also determine
6752 foundry and family. The other fields of font name pattern
6753 are constructed from ATTRS. */
6754 int fontset
= face_fontset (attrs
);
6756 if ((fontset
== -1) && default_face
)
6757 fontset
= default_face
->fontset
;
6758 face
->fontset
= make_fontset_for_ascii_face (f
, fontset
);
6759 face
->font
= NULL
; /* to force realize_face to load font */
6762 /* Load colors, and set remaining attributes. */
6764 load_face_colors (f
, face
, attrs
);
6767 box
= attrs
[LFACE_BOX_INDEX
];
6770 /* A simple box of line width 1 drawn in color given by
6772 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
6774 face
->box
= FACE_SIMPLE_BOX
;
6775 face
->box_line_width
= 1;
6777 else if (INTEGERP (box
))
6779 /* Simple box of specified line width in foreground color of the
6781 xassert (XINT (box
) != 0);
6782 face
->box
= FACE_SIMPLE_BOX
;
6783 face
->box_line_width
= XINT (box
);
6784 face
->box_color
= face
->foreground
;
6785 face
->box_color_defaulted_p
= 1;
6787 else if (CONSP (box
))
6789 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
6790 being one of `raised' or `sunken'. */
6791 face
->box
= FACE_SIMPLE_BOX
;
6792 face
->box_color
= face
->foreground
;
6793 face
->box_color_defaulted_p
= 1;
6794 face
->box_line_width
= 1;
6798 Lisp_Object keyword
, value
;
6800 keyword
= XCAR (box
);
6808 if (EQ (keyword
, QCline_width
))
6810 if (INTEGERP (value
) && XINT (value
) != 0)
6811 face
->box_line_width
= XINT (value
);
6813 else if (EQ (keyword
, QCcolor
))
6815 if (STRINGP (value
))
6817 face
->box_color
= load_color (f
, face
, value
,
6819 face
->use_box_color_for_shadows_p
= 1;
6822 else if (EQ (keyword
, QCstyle
))
6824 if (EQ (value
, Qreleased_button
))
6825 face
->box
= FACE_RAISED_BOX
;
6826 else if (EQ (value
, Qpressed_button
))
6827 face
->box
= FACE_SUNKEN_BOX
;
6832 /* Text underline, overline, strike-through. */
6834 if (EQ (attrs
[LFACE_UNDERLINE_INDEX
], Qt
))
6836 /* Use default color (same as foreground color). */
6837 face
->underline_p
= 1;
6838 face
->underline_defaulted_p
= 1;
6839 face
->underline_color
= 0;
6841 else if (STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]))
6843 /* Use specified color. */
6844 face
->underline_p
= 1;
6845 face
->underline_defaulted_p
= 0;
6846 face
->underline_color
6847 = load_color (f
, face
, attrs
[LFACE_UNDERLINE_INDEX
],
6848 LFACE_UNDERLINE_INDEX
);
6850 else if (NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
6852 face
->underline_p
= 0;
6853 face
->underline_defaulted_p
= 0;
6854 face
->underline_color
= 0;
6857 overline
= attrs
[LFACE_OVERLINE_INDEX
];
6858 if (STRINGP (overline
))
6860 face
->overline_color
6861 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
6862 LFACE_OVERLINE_INDEX
);
6863 face
->overline_p
= 1;
6865 else if (EQ (overline
, Qt
))
6867 face
->overline_color
= face
->foreground
;
6868 face
->overline_color_defaulted_p
= 1;
6869 face
->overline_p
= 1;
6872 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
6873 if (STRINGP (strike_through
))
6875 face
->strike_through_color
6876 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
6877 LFACE_STRIKE_THROUGH_INDEX
);
6878 face
->strike_through_p
= 1;
6880 else if (EQ (strike_through
, Qt
))
6882 face
->strike_through_color
= face
->foreground
;
6883 face
->strike_through_color_defaulted_p
= 1;
6884 face
->strike_through_p
= 1;
6887 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
6888 if (!NILP (stipple
))
6889 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
6891 xassert (FACE_SUITABLE_FOR_CHAR_P (face
, c
));
6893 #endif /* HAVE_WINDOW_SYSTEM */
6897 /* Map a specified color of face FACE on frame F to a tty color index.
6898 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
6899 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
6900 default foreground/background colors. */
6903 map_tty_color (f
, face
, idx
, defaulted
)
6906 enum lface_attribute_index idx
;
6909 Lisp_Object frame
, color
, def
;
6910 int foreground_p
= idx
== LFACE_FOREGROUND_INDEX
;
6911 unsigned long default_pixel
, default_other_pixel
, pixel
;
6913 xassert (idx
== LFACE_FOREGROUND_INDEX
|| idx
== LFACE_BACKGROUND_INDEX
);
6917 pixel
= default_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
6918 default_other_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
6922 pixel
= default_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
6923 default_other_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
6926 XSETFRAME (frame
, f
);
6927 color
= face
->lface
[idx
];
6931 && CONSP (Vtty_defined_color_alist
)
6932 && (def
= assq_no_quit (color
, call1 (Qtty_color_alist
, frame
)),
6935 /* Associations in tty-defined-color-alist are of the form
6936 (NAME INDEX R G B). We need the INDEX part. */
6937 pixel
= XINT (XCAR (XCDR (def
)));
6940 if (pixel
== default_pixel
&& STRINGP (color
))
6942 pixel
= load_color (f
, face
, color
, idx
);
6944 #if defined (MSDOS) || defined (WINDOWSNT)
6945 /* If the foreground of the default face is the default color,
6946 use the foreground color defined by the frame. */
6948 if (FRAME_MSDOS_P (f
))
6951 if (pixel
== default_pixel
6952 || pixel
== FACE_TTY_DEFAULT_COLOR
)
6955 pixel
= FRAME_FOREGROUND_PIXEL (f
);
6957 pixel
= FRAME_BACKGROUND_PIXEL (f
);
6958 face
->lface
[idx
] = tty_color_name (f
, pixel
);
6961 else if (pixel
== default_other_pixel
)
6964 pixel
= FRAME_BACKGROUND_PIXEL (f
);
6966 pixel
= FRAME_FOREGROUND_PIXEL (f
);
6967 face
->lface
[idx
] = tty_color_name (f
, pixel
);
6973 #endif /* MSDOS or WINDOWSNT */
6977 face
->foreground
= pixel
;
6979 face
->background
= pixel
;
6983 /* Realize the fully-specified face with attributes ATTRS in face
6984 cache CACHE for character C. Do it for TTY frame CACHE->f. Value is a
6985 pointer to the newly created realized face. */
6987 static struct face
*
6988 realize_tty_face (cache
, attrs
, c
)
6989 struct face_cache
*cache
;
6995 int face_colors_defaulted
= 0;
6996 struct frame
*f
= cache
->f
;
6998 /* Frame must be a termcap frame. */
6999 xassert (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
));
7001 /* Allocate a new realized face. */
7002 face
= make_realized_face (attrs
);
7003 face
->font_name
= FRAME_MSDOS_P (cache
->f
) ? "ms-dos" : "tty";
7005 /* Map face attributes to TTY appearances. We map slant to
7006 dimmed text because we want italic text to appear differently
7007 and because dimmed text is probably used infrequently. */
7008 weight
= face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
7009 slant
= face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
7011 if (weight
> XLFD_WEIGHT_MEDIUM
)
7012 face
->tty_bold_p
= 1;
7013 if (weight
< XLFD_WEIGHT_MEDIUM
|| slant
!= XLFD_SLANT_ROMAN
)
7014 face
->tty_dim_p
= 1;
7015 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
7016 face
->tty_underline_p
= 1;
7017 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
7018 face
->tty_reverse_p
= 1;
7020 /* Map color names to color indices. */
7021 map_tty_color (f
, face
, LFACE_FOREGROUND_INDEX
, &face_colors_defaulted
);
7022 map_tty_color (f
, face
, LFACE_BACKGROUND_INDEX
, &face_colors_defaulted
);
7024 /* Swap colors if face is inverse-video. If the colors are taken
7025 from the frame colors, they are already inverted, since the
7026 frame-creation function calls x-handle-reverse-video. */
7027 if (face
->tty_reverse_p
&& !face_colors_defaulted
)
7029 unsigned long tem
= face
->foreground
;
7030 face
->foreground
= face
->background
;
7031 face
->background
= tem
;
7034 if (tty_suppress_bold_inverse_default_colors_p
7036 && face
->background
== FACE_TTY_DEFAULT_FG_COLOR
7037 && face
->foreground
== FACE_TTY_DEFAULT_BG_COLOR
)
7038 face
->tty_bold_p
= 0;
7044 DEFUN ("tty-suppress-bold-inverse-default-colors",
7045 Ftty_suppress_bold_inverse_default_colors
,
7046 Stty_suppress_bold_inverse_default_colors
, 1, 1, 0,
7047 doc
: /* Suppress/allow boldness of faces with inverse default colors.
7048 SUPPRESS non-nil means suppress it.
7049 This affects bold faces on TTYs whose foreground is the default background
7050 color of the display and whose background is the default foreground color.
7051 For such faces, the bold face attribute is ignored if this variable
7054 Lisp_Object suppress
;
7056 tty_suppress_bold_inverse_default_colors_p
= !NILP (suppress
);
7057 ++face_change_count
;
7063 /***********************************************************************
7065 ***********************************************************************/
7067 /* Return the ID of the face to use to display character CH with face
7068 property PROP on frame F in current_buffer. */
7071 compute_char_face (f
, ch
, prop
)
7078 if (NILP (current_buffer
->enable_multibyte_characters
))
7083 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7084 face_id
= FACE_FOR_CHAR (f
, face
, ch
);
7088 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
7089 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7090 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
7091 merge_face_vector_with_property (f
, attrs
, prop
);
7092 face_id
= lookup_face (f
, attrs
, ch
, NULL
);
7098 /* Return the face ID associated with buffer position POS for
7099 displaying ASCII characters. Return in *ENDPTR the position at
7100 which a different face is needed, as far as text properties and
7101 overlays are concerned. W is a window displaying current_buffer.
7103 REGION_BEG, REGION_END delimit the region, so it can be
7106 LIMIT is a position not to scan beyond. That is to limit the time
7107 this function can take.
7109 If MOUSE is non-zero, use the character's mouse-face, not its face.
7111 The face returned is suitable for displaying ASCII characters. */
7114 face_at_buffer_position (w
, pos
, region_beg
, region_end
,
7115 endptr
, limit
, mouse
)
7118 int region_beg
, region_end
;
7123 struct frame
*f
= XFRAME (w
->frame
);
7124 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
7125 Lisp_Object prop
, position
;
7127 Lisp_Object
*overlay_vec
;
7130 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
7131 Lisp_Object limit1
, end
;
7132 struct face
*default_face
;
7134 /* W must display the current buffer. We could write this function
7135 to use the frame and buffer of W, but right now it doesn't. */
7136 /* xassert (XBUFFER (w->buffer) == current_buffer); */
7138 XSETFRAME (frame
, f
);
7139 XSETFASTINT (position
, pos
);
7142 if (pos
< region_beg
&& region_beg
< endpos
)
7143 endpos
= region_beg
;
7145 /* Get the `face' or `mouse_face' text property at POS, and
7146 determine the next position at which the property changes. */
7147 prop
= Fget_text_property (position
, propname
, w
->buffer
);
7148 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
7149 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
7151 endpos
= XINT (end
);
7153 /* Look at properties from overlays. */
7158 /* First try with room for 40 overlays. */
7160 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7161 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
7162 &next_overlay
, NULL
, 0);
7164 /* If there are more than 40, make enough space for all, and try
7166 if (noverlays
> len
)
7169 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7170 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
7171 &next_overlay
, NULL
, 0);
7174 if (next_overlay
< endpos
)
7175 endpos
= next_overlay
;
7180 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7182 /* Optimize common cases where we can use the default face. */
7185 && !(pos
>= region_beg
&& pos
< region_end
))
7186 return DEFAULT_FACE_ID
;
7188 /* Begin with attributes from the default face. */
7189 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
7191 /* Merge in attributes specified via text properties. */
7193 merge_face_vector_with_property (f
, attrs
, prop
);
7195 /* Now merge the overlay data. */
7196 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
7197 for (i
= 0; i
< noverlays
; i
++)
7202 prop
= Foverlay_get (overlay_vec
[i
], propname
);
7204 merge_face_vector_with_property (f
, attrs
, prop
);
7206 oend
= OVERLAY_END (overlay_vec
[i
]);
7207 oendpos
= OVERLAY_POSITION (oend
);
7208 if (oendpos
< endpos
)
7212 /* If in the region, merge in the region face. */
7213 if (pos
>= region_beg
&& pos
< region_end
)
7215 Lisp_Object region_face
= lface_from_face_name (f
, Qregion
, 0);
7216 merge_face_vectors (f
, XVECTOR (region_face
)->contents
, attrs
, Qnil
);
7218 if (region_end
< endpos
)
7219 endpos
= region_end
;
7224 /* Look up a realized face with the given face attributes,
7225 or realize a new one for ASCII characters. */
7226 return lookup_face (f
, attrs
, 0, NULL
);
7230 /* Compute the face at character position POS in Lisp string STRING on
7231 window W, for ASCII characters.
7233 If STRING is an overlay string, it comes from position BUFPOS in
7234 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
7235 not an overlay string. W must display the current buffer.
7236 REGION_BEG and REGION_END give the start and end positions of the
7237 region; both are -1 if no region is visible.
7239 BASE_FACE_ID is the id of a face to merge with. For strings coming
7240 from overlays or the `display' property it is the face at BUFPOS.
7242 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
7244 Set *ENDPTR to the next position where to check for faces in
7245 STRING; -1 if the face is constant from POS to the end of the
7248 Value is the id of the face to use. The face returned is suitable
7249 for displaying ASCII characters. */
7252 face_at_string_position (w
, string
, pos
, bufpos
, region_beg
,
7253 region_end
, endptr
, base_face_id
, mouse_p
)
7257 int region_beg
, region_end
;
7259 enum face_id base_face_id
;
7262 Lisp_Object prop
, position
, end
, limit
;
7263 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7264 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
7265 struct face
*base_face
;
7266 int multibyte_p
= STRING_MULTIBYTE (string
);
7267 Lisp_Object prop_name
= mouse_p
? Qmouse_face
: Qface
;
7269 /* Get the value of the face property at the current position within
7270 STRING. Value is nil if there is no face property. */
7271 XSETFASTINT (position
, pos
);
7272 prop
= Fget_text_property (position
, prop_name
, string
);
7274 /* Get the next position at which to check for faces. Value of end
7275 is nil if face is constant all the way to the end of the string.
7276 Otherwise it is a string position where to check faces next.
7277 Limit is the maximum position up to which to check for property
7278 changes in Fnext_single_property_change. Strings are usually
7279 short, so set the limit to the end of the string. */
7280 XSETFASTINT (limit
, SCHARS (string
));
7281 end
= Fnext_single_property_change (position
, prop_name
, string
, limit
);
7283 *endptr
= XFASTINT (end
);
7287 base_face
= FACE_FROM_ID (f
, base_face_id
);
7288 xassert (base_face
);
7290 /* Optimize the default case that there is no face property and we
7291 are not in the region. */
7293 && (base_face_id
!= DEFAULT_FACE_ID
7294 /* BUFPOS <= 0 means STRING is not an overlay string, so
7295 that the region doesn't have to be taken into account. */
7297 || bufpos
< region_beg
7298 || bufpos
>= region_end
)
7300 /* We can't realize faces for different charsets differently
7301 if we don't have fonts, so we can stop here if not working
7302 on a window-system frame. */
7303 || !FRAME_WINDOW_P (f
)
7304 || FACE_SUITABLE_FOR_CHAR_P (base_face
, 0)))
7305 return base_face
->id
;
7307 /* Begin with attributes from the base face. */
7308 bcopy (base_face
->lface
, attrs
, sizeof attrs
);
7310 /* Merge in attributes specified via text properties. */
7312 merge_face_vector_with_property (f
, attrs
, prop
);
7314 /* If in the region, merge in the region face. */
7316 && bufpos
>= region_beg
7317 && bufpos
< region_end
)
7319 Lisp_Object region_face
= lface_from_face_name (f
, Qregion
, 0);
7320 merge_face_vectors (f
, XVECTOR (region_face
)->contents
, attrs
, Qnil
);
7323 /* Look up a realized face with the given face attributes,
7324 or realize a new one for ASCII characters. */
7325 return lookup_face (f
, attrs
, 0, NULL
);
7330 /***********************************************************************
7332 ***********************************************************************/
7336 /* Print the contents of the realized face FACE to stderr. */
7339 dump_realized_face (face
)
7342 fprintf (stderr
, "ID: %d\n", face
->id
);
7343 #ifdef HAVE_X_WINDOWS
7344 fprintf (stderr
, "gc: %d\n", (int) face
->gc
);
7346 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
7348 SDATA (face
->lface
[LFACE_FOREGROUND_INDEX
]));
7349 fprintf (stderr
, "background: 0x%lx (%s)\n",
7351 SDATA (face
->lface
[LFACE_BACKGROUND_INDEX
]));
7352 fprintf (stderr
, "font_name: %s (%s)\n",
7354 SDATA (face
->lface
[LFACE_FAMILY_INDEX
]));
7355 #ifdef HAVE_X_WINDOWS
7356 fprintf (stderr
, "font = %p\n", face
->font
);
7358 fprintf (stderr
, "font_info_id = %d\n", face
->font_info_id
);
7359 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
7360 fprintf (stderr
, "underline: %d (%s)\n",
7362 SDATA (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
])));
7363 fprintf (stderr
, "hash: %d\n", face
->hash
);
7364 fprintf (stderr
, "charset: %d\n", face
->charset
);
7368 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, doc
: /* */)
7376 fprintf (stderr
, "font selection order: ");
7377 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
7378 fprintf (stderr
, "%d ", font_sort_order
[i
]);
7379 fprintf (stderr
, "\n");
7381 fprintf (stderr
, "alternative fonts: ");
7382 debug_print (Vface_alternative_font_family_alist
);
7383 fprintf (stderr
, "\n");
7385 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
7386 Fdump_face (make_number (i
));
7392 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
7394 error ("Not a valid face");
7395 dump_realized_face (face
);
7402 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
7403 0, 0, 0, doc
: /* */)
7406 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
7407 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
7408 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
7412 #endif /* GLYPH_DEBUG != 0 */
7416 /***********************************************************************
7418 ***********************************************************************/
7423 Qface
= intern ("face");
7425 Qbitmap_spec_p
= intern ("bitmap-spec-p");
7426 staticpro (&Qbitmap_spec_p
);
7427 Qframe_update_face_colors
= intern ("frame-update-face-colors");
7428 staticpro (&Qframe_update_face_colors
);
7430 /* Lisp face attribute keywords. */
7431 QCfamily
= intern (":family");
7432 staticpro (&QCfamily
);
7433 QCheight
= intern (":height");
7434 staticpro (&QCheight
);
7435 QCweight
= intern (":weight");
7436 staticpro (&QCweight
);
7437 QCslant
= intern (":slant");
7438 staticpro (&QCslant
);
7439 QCunderline
= intern (":underline");
7440 staticpro (&QCunderline
);
7441 QCinverse_video
= intern (":inverse-video");
7442 staticpro (&QCinverse_video
);
7443 QCreverse_video
= intern (":reverse-video");
7444 staticpro (&QCreverse_video
);
7445 QCforeground
= intern (":foreground");
7446 staticpro (&QCforeground
);
7447 QCbackground
= intern (":background");
7448 staticpro (&QCbackground
);
7449 QCstipple
= intern (":stipple");;
7450 staticpro (&QCstipple
);
7451 QCwidth
= intern (":width");
7452 staticpro (&QCwidth
);
7453 QCfont
= intern (":font");
7454 staticpro (&QCfont
);
7455 QCbold
= intern (":bold");
7456 staticpro (&QCbold
);
7457 QCitalic
= intern (":italic");
7458 staticpro (&QCitalic
);
7459 QCoverline
= intern (":overline");
7460 staticpro (&QCoverline
);
7461 QCstrike_through
= intern (":strike-through");
7462 staticpro (&QCstrike_through
);
7463 QCbox
= intern (":box");
7465 QCinherit
= intern (":inherit");
7466 staticpro (&QCinherit
);
7468 /* Symbols used for Lisp face attribute values. */
7469 QCcolor
= intern (":color");
7470 staticpro (&QCcolor
);
7471 QCline_width
= intern (":line-width");
7472 staticpro (&QCline_width
);
7473 QCstyle
= intern (":style");
7474 staticpro (&QCstyle
);
7475 Qreleased_button
= intern ("released-button");
7476 staticpro (&Qreleased_button
);
7477 Qpressed_button
= intern ("pressed-button");
7478 staticpro (&Qpressed_button
);
7479 Qnormal
= intern ("normal");
7480 staticpro (&Qnormal
);
7481 Qultra_light
= intern ("ultra-light");
7482 staticpro (&Qultra_light
);
7483 Qextra_light
= intern ("extra-light");
7484 staticpro (&Qextra_light
);
7485 Qlight
= intern ("light");
7486 staticpro (&Qlight
);
7487 Qsemi_light
= intern ("semi-light");
7488 staticpro (&Qsemi_light
);
7489 Qsemi_bold
= intern ("semi-bold");
7490 staticpro (&Qsemi_bold
);
7491 Qbold
= intern ("bold");
7493 Qextra_bold
= intern ("extra-bold");
7494 staticpro (&Qextra_bold
);
7495 Qultra_bold
= intern ("ultra-bold");
7496 staticpro (&Qultra_bold
);
7497 Qoblique
= intern ("oblique");
7498 staticpro (&Qoblique
);
7499 Qitalic
= intern ("italic");
7500 staticpro (&Qitalic
);
7501 Qreverse_oblique
= intern ("reverse-oblique");
7502 staticpro (&Qreverse_oblique
);
7503 Qreverse_italic
= intern ("reverse-italic");
7504 staticpro (&Qreverse_italic
);
7505 Qultra_condensed
= intern ("ultra-condensed");
7506 staticpro (&Qultra_condensed
);
7507 Qextra_condensed
= intern ("extra-condensed");
7508 staticpro (&Qextra_condensed
);
7509 Qcondensed
= intern ("condensed");
7510 staticpro (&Qcondensed
);
7511 Qsemi_condensed
= intern ("semi-condensed");
7512 staticpro (&Qsemi_condensed
);
7513 Qsemi_expanded
= intern ("semi-expanded");
7514 staticpro (&Qsemi_expanded
);
7515 Qexpanded
= intern ("expanded");
7516 staticpro (&Qexpanded
);
7517 Qextra_expanded
= intern ("extra-expanded");
7518 staticpro (&Qextra_expanded
);
7519 Qultra_expanded
= intern ("ultra-expanded");
7520 staticpro (&Qultra_expanded
);
7521 Qbackground_color
= intern ("background-color");
7522 staticpro (&Qbackground_color
);
7523 Qforeground_color
= intern ("foreground-color");
7524 staticpro (&Qforeground_color
);
7525 Qunspecified
= intern ("unspecified");
7526 staticpro (&Qunspecified
);
7528 Qface_alias
= intern ("face-alias");
7529 staticpro (&Qface_alias
);
7530 Qdefault
= intern ("default");
7531 staticpro (&Qdefault
);
7532 Qtool_bar
= intern ("tool-bar");
7533 staticpro (&Qtool_bar
);
7534 Qregion
= intern ("region");
7535 staticpro (&Qregion
);
7536 Qfringe
= intern ("fringe");
7537 staticpro (&Qfringe
);
7538 Qheader_line
= intern ("header-line");
7539 staticpro (&Qheader_line
);
7540 Qscroll_bar
= intern ("scroll-bar");
7541 staticpro (&Qscroll_bar
);
7542 Qmenu
= intern ("menu");
7544 Qcursor
= intern ("cursor");
7545 staticpro (&Qcursor
);
7546 Qborder
= intern ("border");
7547 staticpro (&Qborder
);
7548 Qmouse
= intern ("mouse");
7549 staticpro (&Qmouse
);
7550 Qmode_line_inactive
= intern ("mode-line-inactive");
7551 staticpro (&Qmode_line_inactive
);
7552 Qtty_color_desc
= intern ("tty-color-desc");
7553 staticpro (&Qtty_color_desc
);
7554 Qtty_color_standard_values
= intern ("tty-color-standard-values");
7555 staticpro (&Qtty_color_standard_values
);
7556 Qtty_color_by_index
= intern ("tty-color-by-index");
7557 staticpro (&Qtty_color_by_index
);
7558 Qtty_color_alist
= intern ("tty-color-alist");
7559 staticpro (&Qtty_color_alist
);
7560 Qscalable_fonts_allowed
= intern ("scalable-fonts-allowed");
7561 staticpro (&Qscalable_fonts_allowed
);
7563 Vparam_value_alist
= Fcons (Fcons (Qnil
, Qnil
), Qnil
);
7564 staticpro (&Vparam_value_alist
);
7565 Vface_alternative_font_family_alist
= Qnil
;
7566 staticpro (&Vface_alternative_font_family_alist
);
7567 Vface_alternative_font_registry_alist
= Qnil
;
7568 staticpro (&Vface_alternative_font_registry_alist
);
7570 defsubr (&Sinternal_make_lisp_face
);
7571 defsubr (&Sinternal_lisp_face_p
);
7572 defsubr (&Sinternal_set_lisp_face_attribute
);
7573 #ifdef HAVE_WINDOW_SYSTEM
7574 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
7576 defsubr (&Scolor_gray_p
);
7577 defsubr (&Scolor_supported_p
);
7578 defsubr (&Sface_attribute_relative_p
);
7579 defsubr (&Smerge_face_attribute
);
7580 defsubr (&Sinternal_get_lisp_face_attribute
);
7581 defsubr (&Sinternal_lisp_face_attribute_values
);
7582 defsubr (&Sinternal_lisp_face_equal_p
);
7583 defsubr (&Sinternal_lisp_face_empty_p
);
7584 defsubr (&Sinternal_copy_lisp_face
);
7585 defsubr (&Sinternal_merge_in_global_face
);
7586 defsubr (&Sface_font
);
7587 defsubr (&Sframe_face_alist
);
7588 defsubr (&Stty_supports_face_attributes_p
);
7589 defsubr (&Scolor_distance
);
7590 defsubr (&Sinternal_set_font_selection_order
);
7591 defsubr (&Sinternal_set_alternative_font_family_alist
);
7592 defsubr (&Sinternal_set_alternative_font_registry_alist
);
7593 defsubr (&Sface_attributes_as_vector
);
7595 defsubr (&Sdump_face
);
7596 defsubr (&Sshow_face_resources
);
7597 #endif /* GLYPH_DEBUG */
7598 defsubr (&Sclear_face_cache
);
7599 defsubr (&Stty_suppress_bold_inverse_default_colors
);
7601 #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS
7602 defsubr (&Sdump_colors
);
7605 DEFVAR_LISP ("font-list-limit", &Vfont_list_limit
,
7606 doc
: /* *Limit for font matching.
7607 If an integer > 0, font matching functions won't load more than
7608 that number of fonts when searching for a matching font. */);
7609 Vfont_list_limit
= make_number (DEFAULT_FONT_LIST_LIMIT
);
7611 DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults
,
7612 doc
: /* List of global face definitions (for internal use only.) */);
7613 Vface_new_frame_defaults
= Qnil
;
7615 DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple
,
7616 doc
: /* *Default stipple pattern used on monochrome displays.
7617 This stipple pattern is used on monochrome displays
7618 instead of shades of gray for a face background color.
7619 See `set-face-stipple' for possible values for this variable. */);
7620 Vface_default_stipple
= build_string ("gray3");
7622 DEFVAR_LISP ("tty-defined-color-alist", &Vtty_defined_color_alist
,
7623 doc
: /* An alist of defined terminal colors and their RGB values. */);
7624 Vtty_defined_color_alist
= Qnil
;
7626 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed
,
7627 doc
: /* Allowed scalable fonts.
7628 A value of nil means don't allow any scalable fonts.
7629 A value of t means allow any scalable font.
7630 Otherwise, value must be a list of regular expressions. A font may be
7631 scaled if its name matches a regular expression in the list.
7632 Note that if value is nil, a scalable font might still be used, if no
7633 other font of the appropriate family and registry is available. */);
7634 Vscalable_fonts_allowed
= Qnil
;
7636 DEFVAR_LISP ("face-ignored-fonts", &Vface_ignored_fonts
,
7637 doc
: /* List of ignored fonts.
7638 Each element is a regular expression that matches names of fonts to
7640 Vface_ignored_fonts
= Qnil
;
7642 #ifdef HAVE_WINDOW_SYSTEM
7643 defsubr (&Sbitmap_spec_p
);
7644 defsubr (&Sx_list_fonts
);
7645 defsubr (&Sinternal_face_x_get_resource
);
7646 defsubr (&Sx_family_fonts
);
7647 defsubr (&Sx_font_family_list
);
7648 #endif /* HAVE_WINDOW_SYSTEM */