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 (XSTRING ((S))->data)
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_ ((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 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
))
921 if (!realize_basic_faces (f
))
926 /* Free face cache of frame F. Called from Fdelete_frame. */
932 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
936 free_face_cache (face_cache
);
937 FRAME_FACE_CACHE (f
) = NULL
;
940 #ifdef HAVE_WINDOW_SYSTEM
941 if (FRAME_WINDOW_P (f
))
943 struct image_cache
*image_cache
= FRAME_X_IMAGE_CACHE (f
);
946 --image_cache
->refcount
;
947 if (image_cache
->refcount
== 0)
948 free_image_cache (f
);
951 #endif /* HAVE_WINDOW_SYSTEM */
955 /* Clear face caches, and recompute basic faces for frame F. Call
956 this after changing frame parameters on which those faces depend,
957 or when realized faces have been freed due to changing attributes
961 recompute_basic_faces (f
)
964 if (FRAME_FACE_CACHE (f
))
966 clear_face_cache (0);
967 if (!realize_basic_faces (f
))
973 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
974 try to free unused fonts, too. */
977 clear_face_cache (clear_fonts_p
)
980 #ifdef HAVE_WINDOW_SYSTEM
981 Lisp_Object tail
, frame
;
985 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
987 struct x_display_info
*dpyinfo
;
989 /* Fonts are common for frames on one display, i.e. on
991 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
992 if (dpyinfo
->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
993 clear_font_table (dpyinfo
);
995 /* From time to time see if we can unload some fonts. This also
996 frees all realized faces on all frames. Fonts needed by
997 faces will be loaded again when faces are realized again. */
998 clear_font_table_count
= 0;
1000 FOR_EACH_FRAME (tail
, frame
)
1002 struct frame
*f
= XFRAME (frame
);
1003 if (FRAME_WINDOW_P (f
)
1004 && FRAME_X_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
1005 free_all_realized_faces (frame
);
1010 /* Clear GCs of realized faces. */
1011 FOR_EACH_FRAME (tail
, frame
)
1014 if (FRAME_WINDOW_P (f
))
1016 clear_face_gcs (FRAME_FACE_CACHE (f
));
1017 clear_image_cache (f
, 0);
1021 #endif /* HAVE_WINDOW_SYSTEM */
1025 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
1026 doc
: /* Clear face caches on all frames.
1027 Optional THOROUGHLY non-nil means try to free unused fonts, too. */)
1029 Lisp_Object thoroughly
;
1031 clear_face_cache (!NILP (thoroughly
));
1032 ++face_change_count
;
1033 ++windows_or_buffers_changed
;
1039 #ifdef HAVE_WINDOW_SYSTEM
1042 /* Remove fonts from the font table of DPYINFO except for the default
1043 ASCII fonts of frames on that display. Called from clear_face_cache
1044 from time to time. */
1047 clear_font_table (dpyinfo
)
1048 struct x_display_info
*dpyinfo
;
1052 /* Free those fonts that are not used by frames on DPYINFO. */
1053 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
1055 struct font_info
*font_info
= dpyinfo
->font_table
+ i
;
1056 Lisp_Object tail
, frame
;
1058 /* Check if slot is already free. */
1059 if (font_info
->name
== NULL
)
1062 /* Don't free a default font of some frame. */
1063 FOR_EACH_FRAME (tail
, frame
)
1065 struct frame
*f
= XFRAME (frame
);
1066 if (FRAME_WINDOW_P (f
)
1067 && font_info
->font
== FRAME_FONT (f
))
1075 if (font_info
->full_name
!= font_info
->name
)
1076 xfree (font_info
->full_name
);
1077 xfree (font_info
->name
);
1079 /* Free the font. */
1081 #ifdef HAVE_X_WINDOWS
1082 XFreeFont (dpyinfo
->display
, font_info
->font
);
1085 w32_unload_font (dpyinfo
, font_info
->font
);
1089 /* Mark font table slot free. */
1090 font_info
->font
= NULL
;
1091 font_info
->name
= font_info
->full_name
= NULL
;
1095 #endif /* HAVE_WINDOW_SYSTEM */
1099 /***********************************************************************
1101 ***********************************************************************/
1103 #ifdef HAVE_WINDOW_SYSTEM
1105 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
1106 doc
: /* Value is non-nil if OBJECT is a valid bitmap specification.
1107 A bitmap specification is either a string, a file name, or a list
1108 \(WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,
1109 HEIGHT is its height, and DATA is a string containing the bits of
1110 the pixmap. Bits are stored row by row, each row occupies
1111 \(WIDTH + 7)/8 bytes. */)
1117 if (STRINGP (object
))
1118 /* If OBJECT is a string, it's a file name. */
1120 else if (CONSP (object
))
1122 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
1123 HEIGHT must be integers > 0, and DATA must be string large
1124 enough to hold a bitmap of the specified size. */
1125 Lisp_Object width
, height
, data
;
1127 height
= width
= data
= Qnil
;
1131 width
= XCAR (object
);
1132 object
= XCDR (object
);
1135 height
= XCAR (object
);
1136 object
= XCDR (object
);
1138 data
= XCAR (object
);
1142 if (NATNUMP (width
) && NATNUMP (height
) && STRINGP (data
))
1144 int bytes_per_row
= ((XFASTINT (width
) + BITS_PER_CHAR
- 1)
1146 if (STRING_BYTES (XSTRING (data
)) >= bytes_per_row
* XINT (height
))
1151 return pixmap_p
? Qt
: Qnil
;
1155 /* Load a bitmap according to NAME (which is either a file name or a
1156 pixmap spec) for use on frame F. Value is the bitmap_id (see
1157 xfns.c). If NAME is nil, return with a bitmap id of zero. If
1158 bitmap cannot be loaded, display a message saying so, and return
1159 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
1160 if these pointers are not null. */
1163 load_pixmap (f
, name
, w_ptr
, h_ptr
)
1166 unsigned int *w_ptr
, *h_ptr
;
1174 tem
= Fbitmap_spec_p (name
);
1176 wrong_type_argument (Qbitmap_spec_p
, name
);
1181 /* Decode a bitmap spec into a bitmap. */
1186 w
= XINT (Fcar (name
));
1187 h
= XINT (Fcar (Fcdr (name
)));
1188 bits
= Fcar (Fcdr (Fcdr (name
)));
1190 bitmap_id
= x_create_bitmap_from_data (f
, XSTRING (bits
)->data
,
1195 /* It must be a string -- a file name. */
1196 bitmap_id
= x_create_bitmap_from_file (f
, name
);
1202 add_to_log ("Invalid or undefined bitmap %s", name
, Qnil
);
1213 ++npixmaps_allocated
;
1216 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
1219 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
1225 #endif /* HAVE_WINDOW_SYSTEM */
1229 /***********************************************************************
1231 ***********************************************************************/
1233 #ifdef HAVE_WINDOW_SYSTEM
1235 /* Update the line_height of frame F. Return non-zero if line height
1239 frame_update_line_height (f
)
1242 int line_height
, changed_p
;
1244 line_height
= FONT_HEIGHT (FRAME_FONT (f
));
1245 changed_p
= line_height
!= FRAME_LINE_HEIGHT (f
);
1246 FRAME_LINE_HEIGHT (f
) = line_height
;
1250 #endif /* HAVE_WINDOW_SYSTEM */
1253 /***********************************************************************
1255 ***********************************************************************/
1257 #ifdef HAVE_WINDOW_SYSTEM
1259 /* Load font of face FACE which is used on frame F to display
1260 character C. The name of the font to load is determined by lface
1261 and fontset of FACE. */
1264 load_face_font (f
, face
, c
)
1269 struct font_info
*font_info
= NULL
;
1272 face
->font_info_id
= -1;
1275 font_name
= choose_face_font (f
, face
->lface
, face
->fontset
, c
);
1280 font_info
= FS_LOAD_FACE_FONT (f
, c
, font_name
, face
);
1285 face
->font_info_id
= font_info
->font_idx
;
1286 face
->font
= font_info
->font
;
1287 face
->font_name
= font_info
->full_name
;
1290 x_free_gc (f
, face
->gc
);
1295 add_to_log ("Unable to load font %s",
1296 build_string (font_name
), Qnil
);
1300 #endif /* HAVE_WINDOW_SYSTEM */
1304 /***********************************************************************
1306 ***********************************************************************/
1308 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
1309 RGB_LIST should contain (at least) 3 lisp integers.
1310 Return 0 if there's a problem with RGB_LIST, otherwise return 1. */
1313 parse_rgb_list (rgb_list
, color
)
1314 Lisp_Object rgb_list
;
1317 #define PARSE_RGB_LIST_FIELD(field) \
1318 if (CONSP (rgb_list) && INTEGERP (XCAR (rgb_list))) \
1320 color->field = XINT (XCAR (rgb_list)); \
1321 rgb_list = XCDR (rgb_list); \
1326 PARSE_RGB_LIST_FIELD (red
);
1327 PARSE_RGB_LIST_FIELD (green
);
1328 PARSE_RGB_LIST_FIELD (blue
);
1334 /* Lookup on frame F the color described by the lisp string COLOR.
1335 The resulting tty color is returned in TTY_COLOR; if STD_COLOR is
1336 non-zero, then the `standard' definition of the same color is
1340 tty_lookup_color (f
, color
, tty_color
, std_color
)
1343 XColor
*tty_color
, *std_color
;
1345 Lisp_Object frame
, color_desc
;
1347 if (!STRINGP (color
) || NILP (Ffboundp (Qtty_color_desc
)))
1350 XSETFRAME (frame
, f
);
1352 color_desc
= call2 (Qtty_color_desc
, color
, frame
);
1353 if (CONSP (color_desc
) && CONSP (XCDR (color_desc
)))
1357 if (! INTEGERP (XCAR (XCDR (color_desc
))))
1360 tty_color
->pixel
= XINT (XCAR (XCDR (color_desc
)));
1362 rgb
= XCDR (XCDR (color_desc
));
1363 if (! parse_rgb_list (rgb
, tty_color
))
1366 /* Should we fill in STD_COLOR too? */
1369 /* Default STD_COLOR to the same as TTY_COLOR. */
1370 *std_color
= *tty_color
;
1372 /* Do a quick check to see if the returned descriptor is
1373 actually _exactly_ equal to COLOR, otherwise we have to
1374 lookup STD_COLOR separately. If it's impossible to lookup
1375 a standard color, we just give up and use TTY_COLOR. */
1376 if ((!STRINGP (XCAR (color_desc
))
1377 || NILP (Fstring_equal (color
, XCAR (color_desc
))))
1378 && Ffboundp (Qtty_color_standard_values
))
1380 /* Look up STD_COLOR separately. */
1381 rgb
= call1 (Qtty_color_standard_values
, color
);
1382 if (! parse_rgb_list (rgb
, std_color
))
1389 else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
1390 /* We were called early during startup, and the colors are not
1391 yet set up in tty-defined-color-alist. Don't return a failure
1392 indication, since this produces the annoying "Unable to
1393 load color" messages in the *Messages* buffer. */
1396 /* tty-color-desc seems to have returned a bad value. */
1400 /* A version of defined_color for non-X frames. */
1403 tty_defined_color (f
, color_name
, color_def
, alloc
)
1412 color_def
->pixel
= FACE_TTY_DEFAULT_COLOR
;
1414 color_def
->blue
= 0;
1415 color_def
->green
= 0;
1418 status
= tty_lookup_color (f
, build_string (color_name
), color_def
, 0);
1420 if (color_def
->pixel
== FACE_TTY_DEFAULT_COLOR
&& *color_name
)
1422 if (strcmp (color_name
, "unspecified-fg") == 0)
1423 color_def
->pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
1424 else if (strcmp (color_name
, "unspecified-bg") == 0)
1425 color_def
->pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
1428 if (color_def
->pixel
!= FACE_TTY_DEFAULT_COLOR
)
1435 /* Decide if color named COLOR_NAME is valid for the display
1436 associated with the frame F; if so, return the rgb values in
1437 COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell.
1439 This does the right thing for any type of frame. */
1442 defined_color (f
, color_name
, color_def
, alloc
)
1448 if (!FRAME_WINDOW_P (f
))
1449 return tty_defined_color (f
, color_name
, color_def
, alloc
);
1450 #ifdef HAVE_X_WINDOWS
1451 else if (FRAME_X_P (f
))
1452 return x_defined_color (f
, color_name
, color_def
, alloc
);
1455 else if (FRAME_W32_P (f
))
1456 return w32_defined_color (f
, color_name
, color_def
, alloc
);
1459 else if (FRAME_MAC_P (f
))
1460 return mac_defined_color (f
, color_name
, color_def
, alloc
);
1467 /* Given the index IDX of a tty color on frame F, return its name, a
1471 tty_color_name (f
, idx
)
1475 if (idx
>= 0 && !NILP (Ffboundp (Qtty_color_by_index
)))
1478 Lisp_Object coldesc
;
1480 XSETFRAME (frame
, f
);
1481 coldesc
= call2 (Qtty_color_by_index
, make_number (idx
), frame
);
1483 if (!NILP (coldesc
))
1484 return XCAR (coldesc
);
1487 /* We can have an MSDOG frame under -nw for a short window of
1488 opportunity before internal_terminal_init is called. DTRT. */
1489 if (FRAME_MSDOS_P (f
) && !inhibit_window_system
)
1490 return msdos_stdcolor_name (idx
);
1493 if (idx
== FACE_TTY_DEFAULT_FG_COLOR
)
1494 return build_string (unspecified_fg
);
1495 if (idx
== FACE_TTY_DEFAULT_BG_COLOR
)
1496 return build_string (unspecified_bg
);
1499 return vga_stdcolor_name (idx
);
1502 return Qunspecified
;
1506 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1507 black) on frame F. The algorithm is taken from 20.2 faces.el. */
1510 face_color_gray_p (f
, color_name
)
1517 if (defined_color (f
, color_name
, &color
, 0))
1518 gray_p
= ((abs (color
.red
- color
.green
)
1519 < max (color
.red
, color
.green
) / 20)
1520 && (abs (color
.green
- color
.blue
)
1521 < max (color
.green
, color
.blue
) / 20)
1522 && (abs (color
.blue
- color
.red
)
1523 < max (color
.blue
, color
.red
) / 20));
1531 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1532 BACKGROUND_P non-zero means the color will be used as background
1536 face_color_supported_p (f
, color_name
, background_p
)
1544 XSETFRAME (frame
, f
);
1545 return (FRAME_WINDOW_P (f
)
1546 ? (!NILP (Fxw_display_color_p (frame
))
1547 || xstricmp (color_name
, "black") == 0
1548 || xstricmp (color_name
, "white") == 0
1550 && face_color_gray_p (f
, color_name
))
1551 || (!NILP (Fx_display_grayscale_p (frame
))
1552 && face_color_gray_p (f
, color_name
)))
1553 : tty_defined_color (f
, color_name
, ¬_used
, 0));
1557 DEFUN ("color-gray-p", Fcolor_gray_p
, Scolor_gray_p
, 1, 2, 0,
1558 doc
: /* Return non-nil if COLOR is a shade of gray (or white or black).
1559 FRAME specifies the frame and thus the display for interpreting COLOR.
1560 If FRAME is nil or omitted, use the selected frame. */)
1562 Lisp_Object color
, frame
;
1566 CHECK_FRAME (frame
);
1567 CHECK_STRING (color
);
1569 return face_color_gray_p (f
, XSTRING (color
)->data
) ? Qt
: Qnil
;
1573 DEFUN ("color-supported-p", Fcolor_supported_p
,
1574 Scolor_supported_p
, 2, 3, 0,
1575 doc
: /* Return non-nil if COLOR can be displayed on FRAME.
1576 BACKGROUND-P non-nil means COLOR is used as a background.
1577 If FRAME is nil or omitted, use the selected frame.
1578 COLOR must be a valid color name. */)
1579 (color
, frame
, background_p
)
1580 Lisp_Object frame
, color
, background_p
;
1584 CHECK_FRAME (frame
);
1585 CHECK_STRING (color
);
1587 if (face_color_supported_p (f
, XSTRING (color
)->data
, !NILP (background_p
)))
1593 /* Load color with name NAME for use by face FACE on frame F.
1594 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1595 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1596 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1597 pixel color. If color cannot be loaded, display a message, and
1598 return the foreground, background or underline color of F, but
1599 record that fact in flags of the face so that we don't try to free
1603 load_color (f
, face
, name
, target_index
)
1607 enum lface_attribute_index target_index
;
1611 xassert (STRINGP (name
));
1612 xassert (target_index
== LFACE_FOREGROUND_INDEX
1613 || target_index
== LFACE_BACKGROUND_INDEX
1614 || target_index
== LFACE_UNDERLINE_INDEX
1615 || target_index
== LFACE_OVERLINE_INDEX
1616 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1617 || target_index
== LFACE_BOX_INDEX
);
1619 /* if the color map is full, defined_color will return a best match
1620 to the values in an existing cell. */
1621 if (!defined_color (f
, XSTRING (name
)->data
, &color
, 1))
1623 add_to_log ("Unable to load color \"%s\"", name
, Qnil
);
1625 switch (target_index
)
1627 case LFACE_FOREGROUND_INDEX
:
1628 face
->foreground_defaulted_p
= 1;
1629 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1632 case LFACE_BACKGROUND_INDEX
:
1633 face
->background_defaulted_p
= 1;
1634 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1637 case LFACE_UNDERLINE_INDEX
:
1638 face
->underline_defaulted_p
= 1;
1639 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1642 case LFACE_OVERLINE_INDEX
:
1643 face
->overline_color_defaulted_p
= 1;
1644 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1647 case LFACE_STRIKE_THROUGH_INDEX
:
1648 face
->strike_through_color_defaulted_p
= 1;
1649 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1652 case LFACE_BOX_INDEX
:
1653 face
->box_color_defaulted_p
= 1;
1654 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1663 ++ncolors_allocated
;
1670 #ifdef HAVE_WINDOW_SYSTEM
1672 /* Load colors for face FACE which is used on frame F. Colors are
1673 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1674 of ATTRS. If the background color specified is not supported on F,
1675 try to emulate gray colors with a stipple from Vface_default_stipple. */
1678 load_face_colors (f
, face
, attrs
)
1685 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1686 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1688 /* Swap colors if face is inverse-video. */
1689 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1697 /* Check for support for foreground, not for background because
1698 face_color_supported_p is smart enough to know that grays are
1699 "supported" as background because we are supposed to use stipple
1701 if (!face_color_supported_p (f
, XSTRING (bg
)->data
, 0)
1702 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1704 x_destroy_bitmap (f
, face
->stipple
);
1705 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1706 &face
->pixmap_w
, &face
->pixmap_h
);
1709 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1710 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1714 /* Free color PIXEL on frame F. */
1717 unload_color (f
, pixel
)
1719 unsigned long pixel
;
1721 #ifdef HAVE_X_WINDOWS
1725 x_free_colors (f
, &pixel
, 1);
1732 /* Free colors allocated for FACE. */
1735 free_face_colors (f
, face
)
1739 #ifdef HAVE_X_WINDOWS
1740 if (face
->colors_copied_bitwise_p
)
1745 if (!face
->foreground_defaulted_p
)
1747 x_free_colors (f
, &face
->foreground
, 1);
1748 IF_DEBUG (--ncolors_allocated
);
1751 if (!face
->background_defaulted_p
)
1753 x_free_colors (f
, &face
->background
, 1);
1754 IF_DEBUG (--ncolors_allocated
);
1757 if (face
->underline_p
1758 && !face
->underline_defaulted_p
)
1760 x_free_colors (f
, &face
->underline_color
, 1);
1761 IF_DEBUG (--ncolors_allocated
);
1764 if (face
->overline_p
1765 && !face
->overline_color_defaulted_p
)
1767 x_free_colors (f
, &face
->overline_color
, 1);
1768 IF_DEBUG (--ncolors_allocated
);
1771 if (face
->strike_through_p
1772 && !face
->strike_through_color_defaulted_p
)
1774 x_free_colors (f
, &face
->strike_through_color
, 1);
1775 IF_DEBUG (--ncolors_allocated
);
1778 if (face
->box
!= FACE_NO_BOX
1779 && !face
->box_color_defaulted_p
)
1781 x_free_colors (f
, &face
->box_color
, 1);
1782 IF_DEBUG (--ncolors_allocated
);
1786 #endif /* HAVE_X_WINDOWS */
1789 #endif /* HAVE_WINDOW_SYSTEM */
1793 /***********************************************************************
1795 ***********************************************************************/
1797 /* An enumerator for each field of an XLFD font name. */
1818 /* An enumerator for each possible slant value of a font. Taken from
1819 the XLFD specification. */
1827 XLFD_SLANT_REVERSE_ITALIC
,
1828 XLFD_SLANT_REVERSE_OBLIQUE
,
1832 /* Relative font weight according to XLFD documentation. */
1836 XLFD_WEIGHT_UNKNOWN
,
1837 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1838 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1839 XLFD_WEIGHT_LIGHT
, /* 30 */
1840 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1841 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1842 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1843 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1844 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1845 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1848 /* Relative proportionate width. */
1852 XLFD_SWIDTH_UNKNOWN
,
1853 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1854 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1855 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1856 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1857 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1858 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1859 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1860 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1861 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1864 /* Structure used for tables mapping XLFD weight, slant, and width
1865 names to numeric and symbolic values. */
1871 Lisp_Object
*symbol
;
1874 /* Table of XLFD slant names and their numeric and symbolic
1875 representations. This table must be sorted by slant names in
1878 static struct table_entry slant_table
[] =
1880 {"i", XLFD_SLANT_ITALIC
, &Qitalic
},
1881 {"o", XLFD_SLANT_OBLIQUE
, &Qoblique
},
1882 {"ot", XLFD_SLANT_OTHER
, &Qitalic
},
1883 {"r", XLFD_SLANT_ROMAN
, &Qnormal
},
1884 {"ri", XLFD_SLANT_REVERSE_ITALIC
, &Qreverse_italic
},
1885 {"ro", XLFD_SLANT_REVERSE_OBLIQUE
, &Qreverse_oblique
}
1888 /* Table of XLFD weight names. This table must be sorted by weight
1889 names in ascending order. */
1891 static struct table_entry weight_table
[] =
1893 {"black", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
},
1894 {"bold", XLFD_WEIGHT_BOLD
, &Qbold
},
1895 {"book", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1896 {"demi", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1897 {"demibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1898 {"extralight", XLFD_WEIGHT_EXTRA_LIGHT
, &Qextra_light
},
1899 {"extrabold", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1900 {"heavy", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1901 {"light", XLFD_WEIGHT_LIGHT
, &Qlight
},
1902 {"medium", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1903 {"normal", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1904 {"regular", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1905 {"semibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1906 {"semilight", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1907 {"ultralight", XLFD_WEIGHT_ULTRA_LIGHT
, &Qultra_light
},
1908 {"ultrabold", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
}
1911 /* Table of XLFD width names. This table must be sorted by width
1912 names in ascending order. */
1914 static struct table_entry swidth_table
[] =
1916 {"compressed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1917 {"condensed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1918 {"demiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1919 {"expanded", XLFD_SWIDTH_EXPANDED
, &Qexpanded
},
1920 {"extracondensed", XLFD_SWIDTH_EXTRA_CONDENSED
, &Qextra_condensed
},
1921 {"extraexpanded", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
},
1922 {"medium", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1923 {"narrow", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1924 {"normal", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1925 {"regular", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1926 {"semicondensed", XLFD_SWIDTH_SEMI_CONDENSED
, &Qsemi_condensed
},
1927 {"semiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1928 {"ultracondensed", XLFD_SWIDTH_ULTRA_CONDENSED
, &Qultra_condensed
},
1929 {"ultraexpanded", XLFD_SWIDTH_ULTRA_EXPANDED
, &Qultra_expanded
},
1930 {"wide", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
}
1933 /* Structure used to hold the result of splitting font names in XLFD
1934 format into their fields. */
1938 /* The original name which is modified destructively by
1939 split_font_name. The pointer is kept here to be able to free it
1940 if it was allocated from the heap. */
1943 /* Font name fields. Each vector element points into `name' above.
1944 Fields are NUL-terminated. */
1945 char *fields
[XLFD_LAST
];
1947 /* Numeric values for those fields that interest us. See
1948 split_font_name for which these are. */
1949 int numeric
[XLFD_LAST
];
1951 /* Lower value mean higher priority. */
1952 int registry_priority
;
1955 /* The frame in effect when sorting font names. Set temporarily in
1956 sort_fonts so that it is available in font comparison functions. */
1958 static struct frame
*font_frame
;
1960 /* Order by which font selection chooses fonts. The default values
1961 mean `first, find a best match for the font width, then for the
1962 font height, then for weight, then for slant.' This variable can be
1963 set via set-face-font-sort-order. */
1966 static int font_sort_order
[4] = {
1967 XLFD_SWIDTH
, XLFD_POINT_SIZE
, XLFD_WEIGHT
, XLFD_SLANT
1970 static int font_sort_order
[4];
1973 /* Look up FONT.fields[FIELD_INDEX] in TABLE which has DIM entries.
1974 TABLE must be sorted by TABLE[i]->name in ascending order. Value
1975 is a pointer to the matching table entry or null if no table entry
1978 static struct table_entry
*
1979 xlfd_lookup_field_contents (table
, dim
, font
, field_index
)
1980 struct table_entry
*table
;
1982 struct font_name
*font
;
1985 /* Function split_font_name converts fields to lower-case, so there
1986 is no need to use xstrlwr or xstricmp here. */
1987 char *s
= font
->fields
[field_index
];
1988 int low
, mid
, high
, cmp
;
1995 mid
= (low
+ high
) / 2;
1996 cmp
= strcmp (table
[mid
].name
, s
);
2010 /* Return a numeric representation for font name field
2011 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
2012 has DIM entries. Value is the numeric value found or DFLT if no
2013 table entry matches. This function is used to translate weight,
2014 slant, and swidth names of XLFD font names to numeric values. */
2017 xlfd_numeric_value (table
, dim
, font
, field_index
, dflt
)
2018 struct table_entry
*table
;
2020 struct font_name
*font
;
2024 struct table_entry
*p
;
2025 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
2026 return p
? p
->numeric
: dflt
;
2030 /* Return a symbolic representation for font name field
2031 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
2032 has DIM entries. Value is the symbolic value found or DFLT if no
2033 table entry matches. This function is used to translate weight,
2034 slant, and swidth names of XLFD font names to symbols. */
2036 static INLINE Lisp_Object
2037 xlfd_symbolic_value (table
, dim
, font
, field_index
, dflt
)
2038 struct table_entry
*table
;
2040 struct font_name
*font
;
2044 struct table_entry
*p
;
2045 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
2046 return p
? *p
->symbol
: dflt
;
2050 /* Return a numeric value for the slant of the font given by FONT. */
2053 xlfd_numeric_slant (font
)
2054 struct font_name
*font
;
2056 return xlfd_numeric_value (slant_table
, DIM (slant_table
),
2057 font
, XLFD_SLANT
, XLFD_SLANT_ROMAN
);
2061 /* Return a symbol representing the weight of the font given by FONT. */
2063 static INLINE Lisp_Object
2064 xlfd_symbolic_slant (font
)
2065 struct font_name
*font
;
2067 return xlfd_symbolic_value (slant_table
, DIM (slant_table
),
2068 font
, XLFD_SLANT
, Qnormal
);
2072 /* Return a numeric value for the weight of the font given by FONT. */
2075 xlfd_numeric_weight (font
)
2076 struct font_name
*font
;
2078 return xlfd_numeric_value (weight_table
, DIM (weight_table
),
2079 font
, XLFD_WEIGHT
, XLFD_WEIGHT_MEDIUM
);
2083 /* Return a symbol representing the slant of the font given by FONT. */
2085 static INLINE Lisp_Object
2086 xlfd_symbolic_weight (font
)
2087 struct font_name
*font
;
2089 return xlfd_symbolic_value (weight_table
, DIM (weight_table
),
2090 font
, XLFD_WEIGHT
, Qnormal
);
2094 /* Return a numeric value for the swidth of the font whose XLFD font
2095 name fields are found in FONT. */
2098 xlfd_numeric_swidth (font
)
2099 struct font_name
*font
;
2101 return xlfd_numeric_value (swidth_table
, DIM (swidth_table
),
2102 font
, XLFD_SWIDTH
, XLFD_SWIDTH_MEDIUM
);
2106 /* Return a symbolic value for the swidth of FONT. */
2108 static INLINE Lisp_Object
2109 xlfd_symbolic_swidth (font
)
2110 struct font_name
*font
;
2112 return xlfd_symbolic_value (swidth_table
, DIM (swidth_table
),
2113 font
, XLFD_SWIDTH
, Qnormal
);
2117 /* Look up the entry of SYMBOL in the vector TABLE which has DIM
2118 entries. Value is a pointer to the matching table entry or null if
2119 no element of TABLE contains SYMBOL. */
2121 static struct table_entry
*
2122 face_value (table
, dim
, symbol
)
2123 struct table_entry
*table
;
2129 xassert (SYMBOLP (symbol
));
2131 for (i
= 0; i
< dim
; ++i
)
2132 if (EQ (*table
[i
].symbol
, symbol
))
2135 return i
< dim
? table
+ i
: NULL
;
2139 /* Return a numeric value for SYMBOL in the vector TABLE which has DIM
2140 entries. Value is -1 if SYMBOL is not found in TABLE. */
2143 face_numeric_value (table
, dim
, symbol
)
2144 struct table_entry
*table
;
2148 struct table_entry
*p
= face_value (table
, dim
, symbol
);
2149 return p
? p
->numeric
: -1;
2153 /* Return a numeric value representing the weight specified by Lisp
2154 symbol WEIGHT. Value is one of the enumerators of enum
2158 face_numeric_weight (weight
)
2161 return face_numeric_value (weight_table
, DIM (weight_table
), weight
);
2165 /* Return a numeric value representing the slant specified by Lisp
2166 symbol SLANT. Value is one of the enumerators of enum xlfd_slant. */
2169 face_numeric_slant (slant
)
2172 return face_numeric_value (slant_table
, DIM (slant_table
), slant
);
2176 /* Return a numeric value representing the swidth specified by Lisp
2177 symbol WIDTH. Value is one of the enumerators of enum xlfd_swidth. */
2180 face_numeric_swidth (width
)
2183 return face_numeric_value (swidth_table
, DIM (swidth_table
), width
);
2187 #ifdef HAVE_WINDOW_SYSTEM
2189 /* Return non-zero if FONT is the name of a fixed-pitch font. */
2193 struct font_name
*font
;
2195 /* Function split_font_name converts fields to lower-case, so there
2196 is no need to use tolower here. */
2197 return *font
->fields
[XLFD_SPACING
] != 'p';
2201 /* Return the point size of FONT on frame F, measured in 1/10 pt.
2203 The actual height of the font when displayed on F depends on the
2204 resolution of both the font and frame. For example, a 10pt font
2205 designed for a 100dpi display will display larger than 10pt on a
2206 75dpi display. (It's not unusual to use fonts not designed for the
2207 display one is using. For example, some intlfonts are available in
2208 72dpi versions, only.)
2210 Value is the real point size of FONT on frame F, or 0 if it cannot
2214 xlfd_point_size (f
, font
)
2216 struct font_name
*font
;
2218 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
2219 char *pixel_field
= font
->fields
[XLFD_PIXEL_SIZE
];
2223 if (*pixel_field
== '[')
2225 /* The pixel size field is `[A B C D]' which specifies
2226 a transformation matrix.
2232 by which all glyphs of the font are transformed. The spec
2233 says that s scalar value N for the pixel size is equivalent
2234 to A = N * resx/resy, B = C = 0, D = N. */
2235 char *start
= pixel_field
+ 1, *end
;
2239 for (i
= 0; i
< 4; ++i
)
2241 matrix
[i
] = strtod (start
, &end
);
2248 pixel
= atoi (pixel_field
);
2253 real_pt
= PT_PER_INCH
* 10.0 * pixel
/ resy
+ 0.5;
2259 /* Return point size of PIXEL dots while considering Y-resultion (DPI)
2260 of frame F. This function is used to guess a point size of font
2261 when only the pixel height of the font is available. */
2264 pixel_point_size (f
, pixel
)
2268 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
2272 /* As one inch is PT_PER_INCH points, PT_PER_INCH/RESY gives the
2273 point size of one dot. */
2274 real_pt
= pixel
* PT_PER_INCH
/ resy
;
2275 int_pt
= real_pt
+ 0.5;
2281 /* Split XLFD font name FONT->name destructively into NUL-terminated,
2282 lower-case fields in FONT->fields. NUMERIC_P non-zero means
2283 compute numeric values for fields XLFD_POINT_SIZE, XLFD_SWIDTH,
2284 XLFD_RESY, XLFD_SLANT, and XLFD_WEIGHT in FONT->numeric. Value is
2285 zero if the font name doesn't have the format we expect. The
2286 expected format is a font name that starts with a `-' and has
2287 XLFD_LAST fields separated by `-'. */
2290 split_font_name (f
, font
, numeric_p
)
2292 struct font_name
*font
;
2298 if (*font
->name
== '-')
2300 char *p
= xstrlwr (font
->name
) + 1;
2302 while (i
< XLFD_LAST
)
2304 font
->fields
[i
] = p
;
2307 /* Pixel and point size may be of the form `[....]'. For
2308 BNF, see XLFD spec, chapter 4. Negative values are
2309 indicated by tilde characters which we replace with
2310 `-' characters, here. */
2312 && (i
- 1 == XLFD_PIXEL_SIZE
2313 || i
- 1 == XLFD_POINT_SIZE
))
2318 for (++p
; *p
&& *p
!= ']'; ++p
)
2322 /* Check that the matrix contains 4 floating point
2324 for (j
= 0, start
= font
->fields
[i
- 1] + 1;
2327 if (strtod (start
, &end
) == 0 && start
== end
)
2334 while (*p
&& *p
!= '-')
2344 success_p
= i
== XLFD_LAST
;
2346 /* If requested, and font name was in the expected format,
2347 compute numeric values for some fields. */
2348 if (numeric_p
&& success_p
)
2350 font
->numeric
[XLFD_POINT_SIZE
] = xlfd_point_size (f
, font
);
2351 font
->numeric
[XLFD_RESY
] = atoi (font
->fields
[XLFD_RESY
]);
2352 font
->numeric
[XLFD_SLANT
] = xlfd_numeric_slant (font
);
2353 font
->numeric
[XLFD_WEIGHT
] = xlfd_numeric_weight (font
);
2354 font
->numeric
[XLFD_SWIDTH
] = xlfd_numeric_swidth (font
);
2355 font
->numeric
[XLFD_AVGWIDTH
] = atoi (font
->fields
[XLFD_AVGWIDTH
]);
2358 /* Initialize it to zero. It will be overridden by font_list while
2359 trying alternate registries. */
2360 font
->registry_priority
= 0;
2366 /* Build an XLFD font name from font name fields in FONT. Value is a
2367 pointer to the font name, which is allocated via xmalloc. */
2370 build_font_name (font
)
2371 struct font_name
*font
;
2375 char *font_name
= (char *) xmalloc (size
);
2376 int total_length
= 0;
2378 for (i
= 0; i
< XLFD_LAST
; ++i
)
2380 /* Add 1 because of the leading `-'. */
2381 int len
= strlen (font
->fields
[i
]) + 1;
2383 /* Reallocate font_name if necessary. Add 1 for the final
2385 if (total_length
+ len
+ 1 >= size
)
2387 int new_size
= max (2 * size
, size
+ len
+ 1);
2388 int sz
= new_size
* sizeof *font_name
;
2389 font_name
= (char *) xrealloc (font_name
, sz
);
2393 font_name
[total_length
] = '-';
2394 bcopy (font
->fields
[i
], font_name
+ total_length
+ 1, len
- 1);
2395 total_length
+= len
;
2398 font_name
[total_length
] = 0;
2403 /* Free an array FONTS of N font_name structures. This frees FONTS
2404 itself and all `name' fields in its elements. */
2407 free_font_names (fonts
, n
)
2408 struct font_name
*fonts
;
2412 xfree (fonts
[--n
].name
);
2417 /* Sort vector FONTS of font_name structures which contains NFONTS
2418 elements using qsort and comparison function CMPFN. F is the frame
2419 on which the fonts will be used. The global variable font_frame
2420 is temporarily set to F to make it available in CMPFN. */
2423 sort_fonts (f
, fonts
, nfonts
, cmpfn
)
2425 struct font_name
*fonts
;
2427 int (*cmpfn
) P_ ((const void *, const void *));
2430 qsort (fonts
, nfonts
, sizeof *fonts
, cmpfn
);
2435 /* Get fonts matching PATTERN on frame F. If F is null, use the first
2436 display in x_display_list. FONTS is a pointer to a vector of
2437 NFONTS font_name structures. TRY_ALTERNATIVES_P non-zero means try
2438 alternative patterns from Valternate_fontname_alist if no fonts are
2439 found matching PATTERN.
2441 For all fonts found, set FONTS[i].name to the name of the font,
2442 allocated via xmalloc, and split font names into fields. Ignore
2443 fonts that we can't parse. Value is the number of fonts found. */
2446 x_face_list_fonts (f
, pattern
, fonts
, nfonts
, try_alternatives_p
)
2449 struct font_name
*fonts
;
2450 int nfonts
, try_alternatives_p
;
2454 /* NTEMACS_TODO : currently this uses w32_list_fonts, but it may be
2455 better to do it the other way around. */
2457 Lisp_Object lpattern
, tem
;
2459 lpattern
= build_string (pattern
);
2461 /* Get the list of fonts matching PATTERN. */
2464 lfonts
= w32_list_fonts (f
, lpattern
, 0, nfonts
);
2467 lfonts
= x_list_fonts (f
, lpattern
, -1, nfonts
);
2470 /* Make a copy of the font names we got from X, and
2471 split them into fields. */
2473 for (tem
= lfonts
; CONSP (tem
) && n
< nfonts
; tem
= XCDR (tem
))
2475 Lisp_Object elt
, tail
;
2476 char *name
= XSTRING (XCAR (tem
))->data
;
2478 /* Ignore fonts matching a pattern from face-ignored-fonts. */
2479 for (tail
= Vface_ignored_fonts
; CONSP (tail
); tail
= XCDR (tail
))
2483 && fast_c_string_match_ignore_case (elt
, name
) >= 0)
2492 /* Make a copy of the font name. */
2493 fonts
[n
].name
= xstrdup (name
);
2495 if (split_font_name (f
, fonts
+ n
, 1))
2497 if (font_scalable_p (fonts
+ n
)
2498 && !may_use_scalable_font_p (name
))
2501 xfree (fonts
[n
].name
);
2507 xfree (fonts
[n
].name
);
2510 /* If no fonts found, try patterns from Valternate_fontname_alist. */
2511 if (n
== 0 && try_alternatives_p
)
2513 Lisp_Object list
= Valternate_fontname_alist
;
2515 while (CONSP (list
))
2517 Lisp_Object entry
= XCAR (list
);
2519 && STRINGP (XCAR (entry
))
2520 && strcmp (XSTRING (XCAR (entry
))->data
, pattern
) == 0)
2527 Lisp_Object patterns
= XCAR (list
);
2530 while (CONSP (patterns
)
2531 /* If list is screwed up, give up. */
2532 && (name
= XCAR (patterns
),
2534 /* Ignore patterns equal to PATTERN because we tried that
2535 already with no success. */
2536 && (strcmp (XSTRING (name
)->data
, pattern
) == 0
2537 || (n
= x_face_list_fonts (f
, XSTRING (name
)->data
,
2540 patterns
= XCDR (patterns
);
2548 /* Determine fonts matching PATTERN on frame F. Sort resulting fonts
2549 using comparison function CMPFN. Value is the number of fonts
2550 found. If value is non-zero, *FONTS is set to a vector of
2551 font_name structures allocated from the heap containing matching
2552 fonts. Each element of *FONTS contains a name member that is also
2553 allocated from the heap. Font names in these structures are split
2554 into fields. Use free_font_names to free such an array. */
2557 sorted_font_list (f
, pattern
, cmpfn
, fonts
)
2560 int (*cmpfn
) P_ ((const void *, const void *));
2561 struct font_name
**fonts
;
2565 /* Get the list of fonts matching pattern. 100 should suffice. */
2566 nfonts
= DEFAULT_FONT_LIST_LIMIT
;
2567 if (INTEGERP (Vfont_list_limit
) && XINT (Vfont_list_limit
) > 0)
2568 nfonts
= XFASTINT (Vfont_list_limit
);
2570 *fonts
= (struct font_name
*) xmalloc (nfonts
* sizeof **fonts
);
2571 nfonts
= x_face_list_fonts (f
, pattern
, *fonts
, nfonts
, 1);
2573 /* Sort the resulting array and return it in *FONTS. If no
2574 fonts were found, make sure to set *FONTS to null. */
2576 sort_fonts (f
, *fonts
, nfonts
, cmpfn
);
2587 /* Compare two font_name structures *A and *B. Value is analogous to
2588 strcmp. Sort order is given by the global variable
2589 font_sort_order. Font names are sorted so that, everything else
2590 being equal, fonts with a resolution closer to that of the frame on
2591 which they are used are listed first. The global variable
2592 font_frame is the frame on which we operate. */
2595 cmp_font_names (a
, b
)
2598 struct font_name
*x
= (struct font_name
*) a
;
2599 struct font_name
*y
= (struct font_name
*) b
;
2602 /* All strings have been converted to lower-case by split_font_name,
2603 so we can use strcmp here. */
2604 cmp
= strcmp (x
->fields
[XLFD_FAMILY
], y
->fields
[XLFD_FAMILY
]);
2609 for (i
= 0; i
< DIM (font_sort_order
) && cmp
== 0; ++i
)
2611 int j
= font_sort_order
[i
];
2612 cmp
= x
->numeric
[j
] - y
->numeric
[j
];
2617 /* Everything else being equal, we prefer fonts with an
2618 y-resolution closer to that of the frame. */
2619 int resy
= FRAME_X_DISPLAY_INFO (font_frame
)->resy
;
2620 int x_resy
= x
->numeric
[XLFD_RESY
];
2621 int y_resy
= y
->numeric
[XLFD_RESY
];
2622 cmp
= abs (resy
- x_resy
) - abs (resy
- y_resy
);
2630 /* Get a sorted list of fonts of family FAMILY on frame F. If PATTERN
2631 is non-nil list fonts matching that pattern. Otherwise, if
2632 REGISTRY is non-nil return only fonts with that registry, otherwise
2633 return fonts of any registry. Set *FONTS to a vector of font_name
2634 structures allocated from the heap containing the fonts found.
2635 Value is the number of fonts found. */
2638 font_list_1 (f
, pattern
, family
, registry
, fonts
)
2640 Lisp_Object pattern
, family
, registry
;
2641 struct font_name
**fonts
;
2643 char *pattern_str
, *family_str
, *registry_str
;
2647 family_str
= (NILP (family
) ? "*" : (char *) XSTRING (family
)->data
);
2648 registry_str
= (NILP (registry
) ? "*" : (char *) XSTRING (registry
)->data
);
2650 pattern_str
= (char *) alloca (strlen (family_str
)
2651 + strlen (registry_str
)
2653 strcpy (pattern_str
, index (family_str
, '-') ? "-" : "-*-");
2654 strcat (pattern_str
, family_str
);
2655 strcat (pattern_str
, "-*-");
2656 strcat (pattern_str
, registry_str
);
2657 if (!index (registry_str
, '-'))
2659 if (registry_str
[strlen (registry_str
) - 1] == '*')
2660 strcat (pattern_str
, "-*");
2662 strcat (pattern_str
, "*-*");
2666 pattern_str
= (char *) XSTRING (pattern
)->data
;
2668 return sorted_font_list (f
, pattern_str
, cmp_font_names
, fonts
);
2672 /* Concatenate font list FONTS1 and FONTS2. FONTS1 and FONTS2
2673 contains NFONTS1 fonts and NFONTS2 fonts respectively. Return a
2674 pointer to a newly allocated font list. FONTS1 and FONTS2 are
2677 static struct font_name
*
2678 concat_font_list (fonts1
, nfonts1
, fonts2
, nfonts2
)
2679 struct font_name
*fonts1
, *fonts2
;
2680 int nfonts1
, nfonts2
;
2682 int new_nfonts
= nfonts1
+ nfonts2
;
2683 struct font_name
*new_fonts
;
2685 new_fonts
= (struct font_name
*) xmalloc (sizeof *new_fonts
* new_nfonts
);
2686 bcopy (fonts1
, new_fonts
, sizeof *new_fonts
* nfonts1
);
2687 bcopy (fonts2
, new_fonts
+ nfonts1
, sizeof *new_fonts
* nfonts2
);
2694 /* Get a sorted list of fonts of family FAMILY on frame F.
2696 If PATTERN is non-nil list fonts matching that pattern.
2698 If REGISTRY is non-nil, return fonts with that registry and the
2699 alternative registries from Vface_alternative_font_registry_alist.
2701 If REGISTRY is nil return fonts of any registry.
2703 Set *FONTS to a vector of font_name structures allocated from the
2704 heap containing the fonts found. Value is the number of fonts
2708 font_list (f
, pattern
, family
, registry
, fonts
)
2710 Lisp_Object pattern
, family
, registry
;
2711 struct font_name
**fonts
;
2713 int nfonts
= font_list_1 (f
, pattern
, family
, registry
, fonts
);
2715 if (!NILP (registry
)
2716 && CONSP (Vface_alternative_font_registry_alist
))
2720 alter
= Fassoc (registry
, Vface_alternative_font_registry_alist
);
2725 for (alter
= XCDR (alter
), reg_prio
= 1;
2727 alter
= XCDR (alter
), reg_prio
++)
2728 if (STRINGP (XCAR (alter
)))
2731 struct font_name
*fonts2
;
2733 nfonts2
= font_list_1 (f
, pattern
, family
, XCAR (alter
),
2735 for (i
= 0; i
< nfonts2
; i
++)
2736 fonts2
[i
].registry_priority
= reg_prio
;
2737 *fonts
= (nfonts
> 0
2738 ? concat_font_list (*fonts
, nfonts
, fonts2
, nfonts2
)
2749 /* Remove elements from LIST whose cars are `equal'. Called from
2750 x-family-fonts and x-font-family-list to remove duplicate font
2754 remove_duplicates (list
)
2757 Lisp_Object tail
= list
;
2759 while (!NILP (tail
) && !NILP (XCDR (tail
)))
2761 Lisp_Object next
= XCDR (tail
);
2762 if (!NILP (Fequal (XCAR (next
), XCAR (tail
))))
2763 XSETCDR (tail
, XCDR (next
));
2770 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
2771 doc
: /* Return a list of available fonts of family FAMILY on FRAME.
2772 If FAMILY is omitted or nil, list all families.
2773 Otherwise, FAMILY must be a string, possibly containing wildcards
2775 If FRAME is omitted or nil, use the selected frame.
2776 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT
2777 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].
2778 FAMILY is the font family name. POINT-SIZE is the size of the
2779 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the
2780 width, weight and slant of the font. These symbols are the same as for
2781 face attributes. FIXED-P is non-nil if the font is fixed-pitch.
2782 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string
2783 giving the registry and encoding of the font.
2784 The result list is sorted according to the current setting of
2785 the face font sort order. */)
2787 Lisp_Object family
, frame
;
2789 struct frame
*f
= check_x_frame (frame
);
2790 struct font_name
*fonts
;
2793 struct gcpro gcpro1
;
2796 CHECK_STRING (family
);
2800 nfonts
= font_list (f
, Qnil
, family
, Qnil
, &fonts
);
2801 for (i
= nfonts
- 1; i
>= 0; --i
)
2803 Lisp_Object v
= Fmake_vector (make_number (8), Qnil
);
2806 ASET (v
, 0, build_string (fonts
[i
].fields
[XLFD_FAMILY
]));
2807 ASET (v
, 1, xlfd_symbolic_swidth (fonts
+ i
));
2808 ASET (v
, 2, make_number (xlfd_point_size (f
, fonts
+ i
)));
2809 ASET (v
, 3, xlfd_symbolic_weight (fonts
+ i
));
2810 ASET (v
, 4, xlfd_symbolic_slant (fonts
+ i
));
2811 ASET (v
, 5, xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
);
2812 tem
= build_font_name (fonts
+ i
);
2813 ASET (v
, 6, build_string (tem
));
2814 sprintf (tem
, "%s-%s", fonts
[i
].fields
[XLFD_REGISTRY
],
2815 fonts
[i
].fields
[XLFD_ENCODING
]);
2816 ASET (v
, 7, build_string (tem
));
2819 result
= Fcons (v
, result
);
2822 remove_duplicates (result
);
2823 free_font_names (fonts
, nfonts
);
2829 DEFUN ("x-font-family-list", Fx_font_family_list
, Sx_font_family_list
,
2831 doc
: /* Return a list of available font families on FRAME.
2832 If FRAME is omitted or nil, use the selected frame.
2833 Value is a list of conses (FAMILY . FIXED-P) where FAMILY
2834 is a font family, and FIXED-P is non-nil if fonts of that family
2835 are fixed-pitch. */)
2839 struct frame
*f
= check_x_frame (frame
);
2841 struct font_name
*fonts
;
2843 struct gcpro gcpro1
;
2844 int count
= specpdl_ptr
- specpdl
;
2847 /* Let's consider all fonts. Increase the limit for matching
2848 fonts until we have them all. */
2851 specbind (intern ("font-list-limit"), make_number (limit
));
2852 nfonts
= font_list (f
, Qnil
, Qnil
, Qnil
, &fonts
);
2854 if (nfonts
== limit
)
2856 free_font_names (fonts
, nfonts
);
2865 for (i
= nfonts
- 1; i
>= 0; --i
)
2866 result
= Fcons (Fcons (build_string (fonts
[i
].fields
[XLFD_FAMILY
]),
2867 xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
),
2870 remove_duplicates (result
);
2871 free_font_names (fonts
, nfonts
);
2873 return unbind_to (count
, result
);
2877 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
2878 doc
: /* Return a list of the names of available fonts matching PATTERN.
2879 If optional arguments FACE and FRAME are specified, return only fonts
2880 the same size as FACE on FRAME.
2881 PATTERN is a string, perhaps with wildcard characters;
2882 the * character matches any substring, and
2883 the ? character matches any single character.
2884 PATTERN is case-insensitive.
2885 FACE is a face name--a symbol.
2887 The return value is a list of strings, suitable as arguments to
2890 Fonts Emacs can't use may or may not be excluded
2891 even if they match PATTERN and FACE.
2892 The optional fourth argument MAXIMUM sets a limit on how many
2893 fonts to match. The first MAXIMUM fonts are reported.
2894 The optional fifth argument WIDTH, if specified, is a number of columns
2895 occupied by a character of a font. In that case, return only fonts
2896 the WIDTH times as wide as FACE on FRAME. */)
2897 (pattern
, face
, frame
, maximum
, width
)
2898 Lisp_Object pattern
, face
, frame
, maximum
, width
;
2905 CHECK_STRING (pattern
);
2911 CHECK_NATNUM (maximum
);
2912 maxnames
= XINT (maximum
);
2916 CHECK_NUMBER (width
);
2918 /* We can't simply call check_x_frame because this function may be
2919 called before any frame is created. */
2920 f
= frame_or_selected_frame (frame
, 2);
2921 if (!FRAME_WINDOW_P (f
))
2923 /* Perhaps we have not yet created any frame. */
2928 /* Determine the width standard for comparison with the fonts we find. */
2934 /* This is of limited utility since it works with character
2935 widths. Keep it for compatibility. --gerd. */
2936 int face_id
= lookup_named_face (f
, face
, 0);
2937 struct face
*face
= (face_id
< 0
2939 : FACE_FROM_ID (f
, face_id
));
2941 if (face
&& face
->font
)
2942 size
= FONT_WIDTH (face
->font
);
2944 size
= FONT_WIDTH (FRAME_FONT (f
));
2947 size
*= XINT (width
);
2951 Lisp_Object args
[2];
2953 args
[0] = x_list_fonts (f
, pattern
, size
, maxnames
);
2955 /* We don't have to check fontsets. */
2957 args
[1] = list_fontsets (f
, pattern
, size
);
2958 return Fnconc (2, args
);
2962 #endif /* HAVE_WINDOW_SYSTEM */
2966 /***********************************************************************
2968 ***********************************************************************/
2970 /* Access face attributes of face LFACE, a Lisp vector. */
2972 #define LFACE_FAMILY(LFACE) AREF ((LFACE), LFACE_FAMILY_INDEX)
2973 #define LFACE_HEIGHT(LFACE) AREF ((LFACE), LFACE_HEIGHT_INDEX)
2974 #define LFACE_WEIGHT(LFACE) AREF ((LFACE), LFACE_WEIGHT_INDEX)
2975 #define LFACE_SLANT(LFACE) AREF ((LFACE), LFACE_SLANT_INDEX)
2976 #define LFACE_UNDERLINE(LFACE) AREF ((LFACE), LFACE_UNDERLINE_INDEX)
2977 #define LFACE_INVERSE(LFACE) AREF ((LFACE), LFACE_INVERSE_INDEX)
2978 #define LFACE_FOREGROUND(LFACE) AREF ((LFACE), LFACE_FOREGROUND_INDEX)
2979 #define LFACE_BACKGROUND(LFACE) AREF ((LFACE), LFACE_BACKGROUND_INDEX)
2980 #define LFACE_STIPPLE(LFACE) AREF ((LFACE), LFACE_STIPPLE_INDEX)
2981 #define LFACE_SWIDTH(LFACE) AREF ((LFACE), LFACE_SWIDTH_INDEX)
2982 #define LFACE_OVERLINE(LFACE) AREF ((LFACE), LFACE_OVERLINE_INDEX)
2983 #define LFACE_STRIKE_THROUGH(LFACE) AREF ((LFACE), LFACE_STRIKE_THROUGH_INDEX)
2984 #define LFACE_BOX(LFACE) AREF ((LFACE), LFACE_BOX_INDEX)
2985 #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX)
2986 #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX)
2987 #define LFACE_AVGWIDTH(LFACE) AREF ((LFACE), LFACE_AVGWIDTH_INDEX)
2989 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
2990 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
2992 #define LFACEP(LFACE) \
2994 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \
2995 && EQ (AREF (LFACE, 0), Qface))
3000 /* Check consistency of Lisp face attribute vector ATTRS. */
3003 check_lface_attrs (attrs
)
3006 xassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
3007 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
3008 xassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
3009 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
3010 xassert (UNSPECIFIEDP (attrs
[LFACE_AVGWIDTH_INDEX
])
3011 || INTEGERP (attrs
[LFACE_AVGWIDTH_INDEX
]));
3012 xassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
3013 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
])
3014 || FLOATP (attrs
[LFACE_HEIGHT_INDEX
])
3015 || FUNCTIONP (attrs
[LFACE_HEIGHT_INDEX
]));
3016 xassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
3017 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
3018 xassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
3019 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
3020 xassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
3021 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
3022 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]));
3023 xassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
3024 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
3025 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
3026 xassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
3027 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
3028 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
3029 xassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
3030 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
3031 || STRINGP (attrs
[LFACE_BOX_INDEX
])
3032 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
3033 || CONSP (attrs
[LFACE_BOX_INDEX
]));
3034 xassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
3035 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
3036 xassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
3037 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
3038 xassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
3039 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
3040 xassert (UNSPECIFIEDP (attrs
[LFACE_INHERIT_INDEX
])
3041 || NILP (attrs
[LFACE_INHERIT_INDEX
])
3042 || SYMBOLP (attrs
[LFACE_INHERIT_INDEX
])
3043 || CONSP (attrs
[LFACE_INHERIT_INDEX
]));
3044 #ifdef HAVE_WINDOW_SYSTEM
3045 xassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
3046 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
3047 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
3048 xassert (UNSPECIFIEDP (attrs
[LFACE_FONT_INDEX
])
3049 || NILP (attrs
[LFACE_FONT_INDEX
])
3050 || STRINGP (attrs
[LFACE_FONT_INDEX
]));
3055 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
3063 xassert (LFACEP (lface
));
3064 check_lface_attrs (XVECTOR (lface
)->contents
);
3068 #else /* GLYPH_DEBUG == 0 */
3070 #define check_lface_attrs(attrs) (void) 0
3071 #define check_lface(lface) (void) 0
3073 #endif /* GLYPH_DEBUG == 0 */
3076 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
3077 to make it a symvol. If FACE_NAME is an alias for another face,
3078 return that face's name. */
3081 resolve_face_name (face_name
)
3082 Lisp_Object face_name
;
3084 Lisp_Object aliased
;
3086 if (STRINGP (face_name
))
3087 face_name
= intern (XSTRING (face_name
)->data
);
3089 while (SYMBOLP (face_name
))
3091 aliased
= Fget (face_name
, Qface_alias
);
3095 face_name
= aliased
;
3102 /* Return the face definition of FACE_NAME on frame F. F null means
3103 return the definition for new frames. FACE_NAME may be a string or
3104 a symbol (apparently Emacs 20.2 allowed strings as face names in
3105 face text properties; Ediff uses that). If FACE_NAME is an alias
3106 for another face, return that face's definition. If SIGNAL_P is
3107 non-zero, signal an error if FACE_NAME is not a valid face name.
3108 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
3111 static INLINE Lisp_Object
3112 lface_from_face_name (f
, face_name
, signal_p
)
3114 Lisp_Object face_name
;
3119 face_name
= resolve_face_name (face_name
);
3122 lface
= assq_no_quit (face_name
, f
->face_alist
);
3124 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
3127 lface
= XCDR (lface
);
3129 signal_error ("Invalid face", face_name
);
3131 check_lface (lface
);
3136 /* Get face attributes of face FACE_NAME from frame-local faces on
3137 frame F. Store the resulting attributes in ATTRS which must point
3138 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
3139 is non-zero, signal an error if FACE_NAME does not name a face.
3140 Otherwise, value is zero if FACE_NAME is not a face. */
3143 get_lface_attributes (f
, face_name
, attrs
, signal_p
)
3145 Lisp_Object face_name
;
3152 lface
= lface_from_face_name (f
, face_name
, signal_p
);
3155 bcopy (XVECTOR (lface
)->contents
, attrs
,
3156 LFACE_VECTOR_SIZE
* sizeof *attrs
);
3166 /* Non-zero if all attributes in face attribute vector ATTRS are
3167 specified, i.e. are non-nil. */
3170 lface_fully_specified_p (attrs
)
3175 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3176 if (i
!= LFACE_FONT_INDEX
&& i
!= LFACE_INHERIT_INDEX
3177 && i
!= LFACE_AVGWIDTH_INDEX
)
3178 if (UNSPECIFIEDP (attrs
[i
]))
3181 return i
== LFACE_VECTOR_SIZE
;
3184 #ifdef HAVE_WINDOW_SYSTEM
3186 /* Set font-related attributes of Lisp face LFACE from the fullname of
3187 the font opened by FONTNAME. If FORCE_P is zero, set only
3188 unspecified attributes of LFACE. The exception is `font'
3189 attribute. It is set to FONTNAME as is regardless of FORCE_P.
3191 If FONTNAME is not available on frame F,
3192 return 0 if MAY_FAIL_P is non-zero, otherwise abort.
3193 If the fullname is not in a valid XLFD format,
3194 return 0 if MAY_FAIL_P is non-zero, otherwise set normal values
3195 in LFACE and return 1.
3196 Otherwise, return 1. */
3199 set_lface_from_font_name (f
, lface
, fontname
, force_p
, may_fail_p
)
3202 Lisp_Object fontname
;
3203 int force_p
, may_fail_p
;
3205 struct font_name font
;
3210 char *font_name
= XSTRING (fontname
)->data
;
3211 struct font_info
*font_info
;
3213 /* If FONTNAME is actually a fontset name, get ASCII font name of it. */
3214 fontset
= fs_query_fontset (fontname
, 0);
3216 font_name
= XSTRING (fontset_ascii (fontset
))->data
;
3218 /* Check if FONT_NAME is surely available on the system. Usually
3219 FONT_NAME is already cached for the frame F and FS_LOAD_FONT
3220 returns quickly. But, even if FONT_NAME is not yet cached,
3221 caching it now is not futail because we anyway load the font
3224 font_info
= FS_LOAD_FONT (f
, 0, font_name
, -1);
3234 font
.name
= STRDUPA (font_info
->full_name
);
3235 have_xlfd_p
= split_font_name (f
, &font
, 1);
3237 /* Set attributes only if unspecified, otherwise face defaults for
3238 new frames would never take effect. If we couldn't get a font
3239 name conforming to XLFD, set normal values. */
3241 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
3246 buffer
= (char *) alloca (strlen (font
.fields
[XLFD_FAMILY
])
3247 + strlen (font
.fields
[XLFD_FOUNDRY
])
3249 sprintf (buffer
, "%s-%s", font
.fields
[XLFD_FOUNDRY
],
3250 font
.fields
[XLFD_FAMILY
]);
3251 val
= build_string (buffer
);
3254 val
= build_string ("*");
3255 LFACE_FAMILY (lface
) = val
;
3258 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
3261 pt
= xlfd_point_size (f
, &font
);
3263 pt
= pixel_point_size (f
, font_info
->height
* 10);
3265 LFACE_HEIGHT (lface
) = make_number (pt
);
3268 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
3269 LFACE_SWIDTH (lface
)
3270 = have_xlfd_p
? xlfd_symbolic_swidth (&font
) : Qnormal
;
3272 if (force_p
|| UNSPECIFIEDP (LFACE_AVGWIDTH (lface
)))
3273 LFACE_AVGWIDTH (lface
)
3275 ? make_number (font
.numeric
[XLFD_AVGWIDTH
])
3278 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
3279 LFACE_WEIGHT (lface
)
3280 = have_xlfd_p
? xlfd_symbolic_weight (&font
) : Qnormal
;
3282 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
3284 = have_xlfd_p
? xlfd_symbolic_slant (&font
) : Qnormal
;
3286 LFACE_FONT (lface
) = fontname
;
3291 #endif /* HAVE_WINDOW_SYSTEM */
3294 /* Merges the face height FROM with the face height TO, and returns the
3295 merged height. If FROM is an invalid height, then INVALID is
3296 returned instead. FROM and TO may be either absolute face heights or
3297 `relative' heights; the returned value is always an absolute height
3298 unless both FROM and TO are relative. GCPRO is a lisp value that
3299 will be protected from garbage-collection if this function makes a
3303 merge_face_heights (from
, to
, invalid
, gcpro
)
3304 Lisp_Object from
, to
, invalid
, gcpro
;
3306 Lisp_Object result
= invalid
;
3308 if (INTEGERP (from
))
3309 /* FROM is absolute, just use it as is. */
3311 else if (FLOATP (from
))
3312 /* FROM is a scale, use it to adjust TO. */
3315 /* relative X absolute => absolute */
3316 result
= make_number ((EMACS_INT
)(XFLOAT_DATA (from
) * XINT (to
)));
3317 else if (FLOATP (to
))
3318 /* relative X relative => relative */
3319 result
= make_float (XFLOAT_DATA (from
) * XFLOAT_DATA (to
));
3321 else if (FUNCTIONP (from
))
3322 /* FROM is a function, which use to adjust TO. */
3324 /* Call function with current height as argument.
3325 From is the new height. */
3326 Lisp_Object args
[2];
3327 struct gcpro gcpro1
;
3333 result
= safe_call (2, args
);
3337 /* Ensure that if TO was absolute, so is the result. */
3338 if (INTEGERP (to
) && !INTEGERP (result
))
3346 /* Merge two Lisp face attribute vectors on frame F, FROM and TO, and
3347 store the resulting attributes in TO, which must be already be
3348 completely specified and contain only absolute attributes. Every
3349 specified attribute of FROM overrides the corresponding attribute of
3350 TO; relative attributes in FROM are merged with the absolute value in
3351 TO and replace it. CYCLE_CHECK is used internally to detect loops in
3352 face inheritance; it should be Qnil when called from other places. */
3355 merge_face_vectors (f
, from
, to
, cycle_check
)
3357 Lisp_Object
*from
, *to
;
3358 Lisp_Object cycle_check
;
3362 /* If FROM inherits from some other faces, merge their attributes into
3363 TO before merging FROM's direct attributes. Note that an :inherit
3364 attribute of `unspecified' is the same as one of nil; we never
3365 merge :inherit attributes, so nil is more correct, but lots of
3366 other code uses `unspecified' as a generic value for face attributes. */
3367 if (!UNSPECIFIEDP (from
[LFACE_INHERIT_INDEX
])
3368 && !NILP (from
[LFACE_INHERIT_INDEX
]))
3369 merge_face_inheritance (f
, from
[LFACE_INHERIT_INDEX
], to
, cycle_check
);
3371 /* If TO specifies a :font attribute, and FROM specifies some
3372 font-related attribute, we need to clear TO's :font attribute
3373 (because it will be inconsistent with whatever FROM specifies, and
3374 FROM takes precedence). */
3375 if (!NILP (to
[LFACE_FONT_INDEX
])
3376 && (!UNSPECIFIEDP (from
[LFACE_FAMILY_INDEX
])
3377 || !UNSPECIFIEDP (from
[LFACE_HEIGHT_INDEX
])
3378 || !UNSPECIFIEDP (from
[LFACE_WEIGHT_INDEX
])
3379 || !UNSPECIFIEDP (from
[LFACE_SLANT_INDEX
])
3380 || !UNSPECIFIEDP (from
[LFACE_SWIDTH_INDEX
])
3381 || !UNSPECIFIEDP (from
[LFACE_AVGWIDTH_INDEX
])))
3382 to
[LFACE_FONT_INDEX
] = Qnil
;
3384 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3385 if (!UNSPECIFIEDP (from
[i
]))
3387 if (i
== LFACE_HEIGHT_INDEX
&& !INTEGERP (from
[i
]))
3388 to
[i
] = merge_face_heights (from
[i
], to
[i
], to
[i
], cycle_check
);
3393 /* TO is always an absolute face, which should inherit from nothing.
3394 We blindly copy the :inherit attribute above and fix it up here. */
3395 to
[LFACE_INHERIT_INDEX
] = Qnil
;
3399 /* Checks the `cycle check' variable CHECK to see if it indicates that
3400 EL is part of a cycle; CHECK must be either Qnil or a value returned
3401 by an earlier use of CYCLE_CHECK. SUSPICIOUS is the number of
3402 elements after which a cycle might be suspected; after that many
3403 elements, this macro begins consing in order to keep more precise
3406 Returns nil if a cycle was detected, otherwise a new value for CHECK
3409 CHECK is evaluated multiple times, EL and SUSPICIOUS 0 or 1 times, so
3410 the caller should make sure that's ok. */
3412 #define CYCLE_CHECK(check, el, suspicious) \
3415 : (INTEGERP (check) \
3416 ? (XFASTINT (check) < (suspicious) \
3417 ? make_number (XFASTINT (check) + 1) \
3418 : Fcons (el, Qnil)) \
3419 : (!NILP (Fmemq ((el), (check))) \
3421 : Fcons ((el), (check)))))
3424 /* Merge face attributes from the face on frame F whose name is
3425 INHERITS, into the vector of face attributes TO; INHERITS may also be
3426 a list of face names, in which case they are applied in order.
3427 CYCLE_CHECK is used to detect loops in face inheritance.
3428 Returns true if any of the inherited attributes are `font-related'. */
3431 merge_face_inheritance (f
, inherit
, to
, cycle_check
)
3433 Lisp_Object inherit
;
3435 Lisp_Object cycle_check
;
3437 if (SYMBOLP (inherit
) && !EQ (inherit
, Qunspecified
))
3438 /* Inherit from the named face INHERIT. */
3442 /* Make sure we're not in an inheritance loop. */
3443 cycle_check
= CYCLE_CHECK (cycle_check
, inherit
, 15);
3444 if (NILP (cycle_check
))
3445 /* Cycle detected, ignore any further inheritance. */
3448 lface
= lface_from_face_name (f
, inherit
, 0);
3450 merge_face_vectors (f
, XVECTOR (lface
)->contents
, to
, cycle_check
);
3452 else if (CONSP (inherit
))
3453 /* Handle a list of inherited faces by calling ourselves recursively
3454 on each element. Note that we only do so for symbol elements, so
3455 it's not possible to infinitely recurse. */
3457 while (CONSP (inherit
))
3459 if (SYMBOLP (XCAR (inherit
)))
3460 merge_face_inheritance (f
, XCAR (inherit
), to
, cycle_check
);
3462 /* Check for a circular inheritance list. */
3463 cycle_check
= CYCLE_CHECK (cycle_check
, inherit
, 15);
3464 if (NILP (cycle_check
))
3465 /* Cycle detected. */
3468 inherit
= XCDR (inherit
);
3474 /* Given a Lisp face attribute vector TO and a Lisp object PROP that
3475 is a face property, determine the resulting face attributes on
3476 frame F, and store them in TO. PROP may be a single face
3477 specification or a list of such specifications. Each face
3478 specification can be
3480 1. A symbol or string naming a Lisp face.
3482 2. A property list of the form (KEYWORD VALUE ...) where each
3483 KEYWORD is a face attribute name, and value is an appropriate value
3486 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
3487 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
3488 for compatibility with 20.2.
3490 Face specifications earlier in lists take precedence over later
3494 merge_face_vector_with_property (f
, to
, prop
)
3501 Lisp_Object first
= XCAR (prop
);
3503 if (EQ (first
, Qforeground_color
)
3504 || EQ (first
, Qbackground_color
))
3506 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
3507 . COLOR). COLOR must be a string. */
3508 Lisp_Object color_name
= XCDR (prop
);
3509 Lisp_Object color
= first
;
3511 if (STRINGP (color_name
))
3513 if (EQ (color
, Qforeground_color
))
3514 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
3516 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
3519 add_to_log ("Invalid face color", color_name
, Qnil
);
3521 else if (SYMBOLP (first
)
3522 && *XSTRING (SYMBOL_NAME (first
))->data
== ':')
3524 /* Assume this is the property list form. */
3525 while (CONSP (prop
) && CONSP (XCDR (prop
)))
3527 Lisp_Object keyword
= XCAR (prop
);
3528 Lisp_Object value
= XCAR (XCDR (prop
));
3530 if (EQ (keyword
, QCfamily
))
3532 if (STRINGP (value
))
3533 to
[LFACE_FAMILY_INDEX
] = value
;
3535 add_to_log ("Invalid face font family", value
, Qnil
);
3537 else if (EQ (keyword
, QCheight
))
3539 Lisp_Object new_height
=
3540 merge_face_heights (value
, to
[LFACE_HEIGHT_INDEX
],
3543 if (NILP (new_height
))
3544 add_to_log ("Invalid face font height", value
, Qnil
);
3546 to
[LFACE_HEIGHT_INDEX
] = new_height
;
3548 else if (EQ (keyword
, QCweight
))
3551 && face_numeric_weight (value
) >= 0)
3552 to
[LFACE_WEIGHT_INDEX
] = value
;
3554 add_to_log ("Invalid face weight", value
, Qnil
);
3556 else if (EQ (keyword
, QCslant
))
3559 && face_numeric_slant (value
) >= 0)
3560 to
[LFACE_SLANT_INDEX
] = value
;
3562 add_to_log ("Invalid face slant", value
, Qnil
);
3564 else if (EQ (keyword
, QCunderline
))
3569 to
[LFACE_UNDERLINE_INDEX
] = value
;
3571 add_to_log ("Invalid face underline", value
, Qnil
);
3573 else if (EQ (keyword
, QCoverline
))
3578 to
[LFACE_OVERLINE_INDEX
] = value
;
3580 add_to_log ("Invalid face overline", value
, Qnil
);
3582 else if (EQ (keyword
, QCstrike_through
))
3587 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
3589 add_to_log ("Invalid face strike-through", value
, Qnil
);
3591 else if (EQ (keyword
, QCbox
))
3594 value
= make_number (1);
3595 if (INTEGERP (value
)
3599 to
[LFACE_BOX_INDEX
] = value
;
3601 add_to_log ("Invalid face box", value
, Qnil
);
3603 else if (EQ (keyword
, QCinverse_video
)
3604 || EQ (keyword
, QCreverse_video
))
3606 if (EQ (value
, Qt
) || NILP (value
))
3607 to
[LFACE_INVERSE_INDEX
] = value
;
3609 add_to_log ("Invalid face inverse-video", value
, Qnil
);
3611 else if (EQ (keyword
, QCforeground
))
3613 if (STRINGP (value
))
3614 to
[LFACE_FOREGROUND_INDEX
] = value
;
3616 add_to_log ("Invalid face foreground", value
, Qnil
);
3618 else if (EQ (keyword
, QCbackground
))
3620 if (STRINGP (value
))
3621 to
[LFACE_BACKGROUND_INDEX
] = value
;
3623 add_to_log ("Invalid face background", value
, Qnil
);
3625 else if (EQ (keyword
, QCstipple
))
3627 #ifdef HAVE_X_WINDOWS
3628 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
3629 if (!NILP (pixmap_p
))
3630 to
[LFACE_STIPPLE_INDEX
] = value
;
3632 add_to_log ("Invalid face stipple", value
, Qnil
);
3635 else if (EQ (keyword
, QCwidth
))
3638 && face_numeric_swidth (value
) >= 0)
3639 to
[LFACE_SWIDTH_INDEX
] = value
;
3641 add_to_log ("Invalid face width", value
, Qnil
);
3643 else if (EQ (keyword
, QCinherit
))
3645 if (SYMBOLP (value
))
3646 to
[LFACE_INHERIT_INDEX
] = value
;
3650 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
3651 if (!SYMBOLP (XCAR (tail
)))
3654 to
[LFACE_INHERIT_INDEX
] = value
;
3656 add_to_log ("Invalid face inherit", value
, Qnil
);
3660 add_to_log ("Invalid attribute %s in face property",
3663 prop
= XCDR (XCDR (prop
));
3668 /* This is a list of face specs. Specifications at the
3669 beginning of the list take precedence over later
3670 specifications, so we have to merge starting with the
3671 last specification. */
3672 Lisp_Object next
= XCDR (prop
);
3674 merge_face_vector_with_property (f
, to
, next
);
3675 merge_face_vector_with_property (f
, to
, first
);
3680 /* PROP ought to be a face name. */
3681 Lisp_Object lface
= lface_from_face_name (f
, prop
, 0);
3683 add_to_log ("Invalid face text property value: %s", prop
, Qnil
);
3685 merge_face_vectors (f
, XVECTOR (lface
)->contents
, to
, Qnil
);
3690 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
3691 Sinternal_make_lisp_face
, 1, 2, 0,
3692 doc
: /* Make FACE, a symbol, a Lisp face with all attributes nil.
3693 If FACE was not known as a face before, create a new one.
3694 If optional argument FRAME is specified, make a frame-local face
3695 for that frame. Otherwise operate on the global face definition.
3696 Value is a vector of face attributes. */)
3698 Lisp_Object face
, frame
;
3700 Lisp_Object global_lface
, lface
;
3704 CHECK_SYMBOL (face
);
3705 global_lface
= lface_from_face_name (NULL
, face
, 0);
3709 CHECK_LIVE_FRAME (frame
);
3711 lface
= lface_from_face_name (f
, face
, 0);
3714 f
= NULL
, lface
= Qnil
;
3716 /* Add a global definition if there is none. */
3717 if (NILP (global_lface
))
3719 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
3721 AREF (global_lface
, 0) = Qface
;
3722 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
3723 Vface_new_frame_defaults
);
3725 /* Assign the new Lisp face a unique ID. The mapping from Lisp
3726 face id to Lisp face is given by the vector lface_id_to_name.
3727 The mapping from Lisp face to Lisp face id is given by the
3728 property `face' of the Lisp face name. */
3729 if (next_lface_id
== lface_id_to_name_size
)
3731 int new_size
= max (50, 2 * lface_id_to_name_size
);
3732 int sz
= new_size
* sizeof *lface_id_to_name
;
3733 lface_id_to_name
= (Lisp_Object
*) xrealloc (lface_id_to_name
, sz
);
3734 lface_id_to_name_size
= new_size
;
3737 lface_id_to_name
[next_lface_id
] = face
;
3738 Fput (face
, Qface
, make_number (next_lface_id
));
3742 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3743 AREF (global_lface
, i
) = Qunspecified
;
3745 /* Add a frame-local definition. */
3750 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
3752 AREF (lface
, 0) = Qface
;
3753 f
->face_alist
= Fcons (Fcons (face
, lface
), f
->face_alist
);
3756 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3757 AREF (lface
, i
) = Qunspecified
;
3760 lface
= global_lface
;
3762 /* Changing a named face means that all realized faces depending on
3763 that face are invalid. Since we cannot tell which realized faces
3764 depend on the face, make sure they are all removed. This is done
3765 by incrementing face_change_count. The next call to
3766 init_iterator will then free realized faces. */
3767 ++face_change_count
;
3768 ++windows_or_buffers_changed
;
3770 xassert (LFACEP (lface
));
3771 check_lface (lface
);
3776 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
3777 Sinternal_lisp_face_p
, 1, 2, 0,
3778 doc
: /* Return non-nil if FACE names a face.
3779 If optional second parameter FRAME is non-nil, check for the
3780 existence of a frame-local face with name FACE on that frame.
3781 Otherwise check for the existence of a global face. */)
3783 Lisp_Object face
, frame
;
3789 CHECK_LIVE_FRAME (frame
);
3790 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3793 lface
= lface_from_face_name (NULL
, face
, 0);
3799 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
3800 Sinternal_copy_lisp_face
, 4, 4, 0,
3801 doc
: /* Copy face FROM to TO.
3802 If FRAME it t, copy the global face definition of FROM to the
3803 global face definition of TO. Otherwise, copy the frame-local
3804 definition of FROM on FRAME to the frame-local definition of TO
3805 on NEW-FRAME, or FRAME if NEW-FRAME is nil.
3808 (from
, to
, frame
, new_frame
)
3809 Lisp_Object from
, to
, frame
, new_frame
;
3811 Lisp_Object lface
, copy
;
3813 CHECK_SYMBOL (from
);
3815 if (NILP (new_frame
))
3820 /* Copy global definition of FROM. We don't make copies of
3821 strings etc. because 20.2 didn't do it either. */
3822 lface
= lface_from_face_name (NULL
, from
, 1);
3823 copy
= Finternal_make_lisp_face (to
, Qnil
);
3827 /* Copy frame-local definition of FROM. */
3828 CHECK_LIVE_FRAME (frame
);
3829 CHECK_LIVE_FRAME (new_frame
);
3830 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
3831 copy
= Finternal_make_lisp_face (to
, new_frame
);
3834 bcopy (XVECTOR (lface
)->contents
, XVECTOR (copy
)->contents
,
3835 LFACE_VECTOR_SIZE
* sizeof (Lisp_Object
));
3837 /* Changing a named face means that all realized faces depending on
3838 that face are invalid. Since we cannot tell which realized faces
3839 depend on the face, make sure they are all removed. This is done
3840 by incrementing face_change_count. The next call to
3841 init_iterator will then free realized faces. */
3842 ++face_change_count
;
3843 ++windows_or_buffers_changed
;
3849 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
3850 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
3851 doc
: /* Set attribute ATTR of FACE to VALUE.
3852 FRAME being a frame means change the face on that frame.
3853 FRAME nil means change the face of the selected frame.
3854 FRAME t means change the default for new frames.
3855 FRAME 0 means change the face on all frames, and change the default
3857 (face
, attr
, value
, frame
)
3858 Lisp_Object face
, attr
, value
, frame
;
3861 Lisp_Object old_value
= Qnil
;
3862 /* Set 1 if ATTR is QCfont. */
3863 int font_attr_p
= 0;
3864 /* Set 1 if ATTR is one of font-related attributes other than QCfont. */
3865 int font_related_attr_p
= 0;
3867 CHECK_SYMBOL (face
);
3868 CHECK_SYMBOL (attr
);
3870 face
= resolve_face_name (face
);
3872 /* If FRAME is 0, change face on all frames, and change the
3873 default for new frames. */
3874 if (INTEGERP (frame
) && XINT (frame
) == 0)
3877 Finternal_set_lisp_face_attribute (face
, attr
, value
, Qt
);
3878 FOR_EACH_FRAME (tail
, frame
)
3879 Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3883 /* Set lface to the Lisp attribute vector of FACE. */
3885 lface
= lface_from_face_name (NULL
, face
, 1);
3889 frame
= selected_frame
;
3891 CHECK_LIVE_FRAME (frame
);
3892 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3894 /* If a frame-local face doesn't exist yet, create one. */
3896 lface
= Finternal_make_lisp_face (face
, frame
);
3899 if (EQ (attr
, QCfamily
))
3901 if (!UNSPECIFIEDP (value
))
3903 CHECK_STRING (value
);
3904 if (XSTRING (value
)->size
== 0)
3905 signal_error ("Invalid face family", value
);
3907 old_value
= LFACE_FAMILY (lface
);
3908 LFACE_FAMILY (lface
) = value
;
3909 font_related_attr_p
= 1;
3911 else if (EQ (attr
, QCheight
))
3913 if (!UNSPECIFIEDP (value
))
3917 test
= (EQ (face
, Qdefault
)
3919 /* The default face must have an absolute size,
3920 otherwise, we do a test merge with a random
3921 height to see if VALUE's ok. */
3922 : merge_face_heights (value
, make_number (10), Qnil
, Qnil
));
3924 if (!INTEGERP (test
) || XINT (test
) <= 0)
3925 signal_error ("Invalid face height", value
);
3928 old_value
= LFACE_HEIGHT (lface
);
3929 LFACE_HEIGHT (lface
) = value
;
3930 font_related_attr_p
= 1;
3932 else if (EQ (attr
, QCweight
))
3934 if (!UNSPECIFIEDP (value
))
3936 CHECK_SYMBOL (value
);
3937 if (face_numeric_weight (value
) < 0)
3938 signal_error ("Invalid face weight", value
);
3940 old_value
= LFACE_WEIGHT (lface
);
3941 LFACE_WEIGHT (lface
) = value
;
3942 font_related_attr_p
= 1;
3944 else if (EQ (attr
, QCslant
))
3946 if (!UNSPECIFIEDP (value
))
3948 CHECK_SYMBOL (value
);
3949 if (face_numeric_slant (value
) < 0)
3950 signal_error ("Invalid face slant", value
);
3952 old_value
= LFACE_SLANT (lface
);
3953 LFACE_SLANT (lface
) = value
;
3954 font_related_attr_p
= 1;
3956 else if (EQ (attr
, QCunderline
))
3958 if (!UNSPECIFIEDP (value
))
3959 if ((SYMBOLP (value
)
3961 && !EQ (value
, Qnil
))
3962 /* Underline color. */
3964 && XSTRING (value
)->size
== 0))
3965 signal_error ("Invalid face underline", value
);
3967 old_value
= LFACE_UNDERLINE (lface
);
3968 LFACE_UNDERLINE (lface
) = value
;
3970 else if (EQ (attr
, QCoverline
))
3972 if (!UNSPECIFIEDP (value
))
3973 if ((SYMBOLP (value
)
3975 && !EQ (value
, Qnil
))
3976 /* Overline color. */
3978 && XSTRING (value
)->size
== 0))
3979 signal_error ("Invalid face overline", value
);
3981 old_value
= LFACE_OVERLINE (lface
);
3982 LFACE_OVERLINE (lface
) = value
;
3984 else if (EQ (attr
, QCstrike_through
))
3986 if (!UNSPECIFIEDP (value
))
3987 if ((SYMBOLP (value
)
3989 && !EQ (value
, Qnil
))
3990 /* Strike-through color. */
3992 && XSTRING (value
)->size
== 0))
3993 signal_error ("Invalid face strike-through", value
);
3995 old_value
= LFACE_STRIKE_THROUGH (lface
);
3996 LFACE_STRIKE_THROUGH (lface
) = value
;
3998 else if (EQ (attr
, QCbox
))
4002 /* Allow t meaning a simple box of width 1 in foreground color
4005 value
= make_number (1);
4007 if (UNSPECIFIEDP (value
))
4009 else if (NILP (value
))
4011 else if (INTEGERP (value
))
4012 valid_p
= XINT (value
) != 0;
4013 else if (STRINGP (value
))
4014 valid_p
= XSTRING (value
)->size
> 0;
4015 else if (CONSP (value
))
4031 if (EQ (k
, QCline_width
))
4033 if (!INTEGERP (v
) || XINT (v
) == 0)
4036 else if (EQ (k
, QCcolor
))
4038 if (!STRINGP (v
) || XSTRING (v
)->size
== 0)
4041 else if (EQ (k
, QCstyle
))
4043 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
4050 valid_p
= NILP (tem
);
4056 signal_error ("Invalid face box", value
);
4058 old_value
= LFACE_BOX (lface
);
4059 LFACE_BOX (lface
) = value
;
4061 else if (EQ (attr
, QCinverse_video
)
4062 || EQ (attr
, QCreverse_video
))
4064 if (!UNSPECIFIEDP (value
))
4066 CHECK_SYMBOL (value
);
4067 if (!EQ (value
, Qt
) && !NILP (value
))
4068 signal_error ("Invalid inverse-video face attribute value", value
);
4070 old_value
= LFACE_INVERSE (lface
);
4071 LFACE_INVERSE (lface
) = value
;
4073 else if (EQ (attr
, QCforeground
))
4075 if (!UNSPECIFIEDP (value
))
4077 /* Don't check for valid color names here because it depends
4078 on the frame (display) whether the color will be valid
4079 when the face is realized. */
4080 CHECK_STRING (value
);
4081 if (XSTRING (value
)->size
== 0)
4082 signal_error ("Empty foreground color value", value
);
4084 old_value
= LFACE_FOREGROUND (lface
);
4085 LFACE_FOREGROUND (lface
) = value
;
4087 else if (EQ (attr
, QCbackground
))
4089 if (!UNSPECIFIEDP (value
))
4091 /* Don't check for valid color names here because it depends
4092 on the frame (display) whether the color will be valid
4093 when the face is realized. */
4094 CHECK_STRING (value
);
4095 if (XSTRING (value
)->size
== 0)
4096 signal_error ("Empty background color value", value
);
4098 old_value
= LFACE_BACKGROUND (lface
);
4099 LFACE_BACKGROUND (lface
) = value
;
4101 else if (EQ (attr
, QCstipple
))
4103 #ifdef HAVE_X_WINDOWS
4104 if (!UNSPECIFIEDP (value
)
4106 && NILP (Fbitmap_spec_p (value
)))
4107 signal_error ("Invalid stipple attribute", value
);
4108 old_value
= LFACE_STIPPLE (lface
);
4109 LFACE_STIPPLE (lface
) = value
;
4110 #endif /* HAVE_X_WINDOWS */
4112 else if (EQ (attr
, QCwidth
))
4114 if (!UNSPECIFIEDP (value
))
4116 CHECK_SYMBOL (value
);
4117 if (face_numeric_swidth (value
) < 0)
4118 signal_error ("Invalid face width", value
);
4120 old_value
= LFACE_SWIDTH (lface
);
4121 LFACE_SWIDTH (lface
) = value
;
4122 font_related_attr_p
= 1;
4124 else if (EQ (attr
, QCfont
))
4126 #ifdef HAVE_WINDOW_SYSTEM
4127 if (EQ (frame
, Qt
) || FRAME_WINDOW_P (XFRAME (frame
)))
4129 /* Set font-related attributes of the Lisp face from an XLFD
4134 CHECK_STRING (value
);
4136 f
= SELECTED_FRAME ();
4138 f
= check_x_frame (frame
);
4140 /* VALUE may be a fontset name or an alias of fontset. In
4141 such a case, use the base fontset name. */
4142 tmp
= Fquery_fontset (value
, Qnil
);
4146 if (!set_lface_from_font_name (f
, lface
, value
, 1, 1))
4147 signal_error ("Invalid font or fontset name", value
);
4151 #endif /* HAVE_WINDOW_SYSTEM */
4153 else if (EQ (attr
, QCinherit
))
4156 if (SYMBOLP (value
))
4159 for (tail
= value
; CONSP (tail
); tail
= XCDR (tail
))
4160 if (!SYMBOLP (XCAR (tail
)))
4163 LFACE_INHERIT (lface
) = value
;
4165 signal_error ("Invalid face inheritance", value
);
4167 else if (EQ (attr
, QCbold
))
4169 old_value
= LFACE_WEIGHT (lface
);
4170 LFACE_WEIGHT (lface
) = NILP (value
) ? Qnormal
: Qbold
;
4171 font_related_attr_p
= 1;
4173 else if (EQ (attr
, QCitalic
))
4175 old_value
= LFACE_SLANT (lface
);
4176 LFACE_SLANT (lface
) = NILP (value
) ? Qnormal
: Qitalic
;
4177 font_related_attr_p
= 1;
4180 signal_error ("Invalid face attribute name", attr
);
4182 if (font_related_attr_p
4183 && !UNSPECIFIEDP (value
))
4184 /* If a font-related attribute other than QCfont is specified, the
4185 original `font' attribute nor that of default face is useless
4186 to determine a new font. Thus, we set it to nil so that font
4187 selection mechanism doesn't use it. */
4188 LFACE_FONT (lface
) = Qnil
;
4190 /* Changing a named face means that all realized faces depending on
4191 that face are invalid. Since we cannot tell which realized faces
4192 depend on the face, make sure they are all removed. This is done
4193 by incrementing face_change_count. The next call to
4194 init_iterator will then free realized faces. */
4196 && (EQ (attr
, QCfont
)
4197 || NILP (Fequal (old_value
, value
))))
4199 ++face_change_count
;
4200 ++windows_or_buffers_changed
;
4203 if (!UNSPECIFIEDP (value
)
4204 && NILP (Fequal (old_value
, value
)))
4210 if (EQ (face
, Qdefault
))
4212 #ifdef HAVE_WINDOW_SYSTEM
4213 /* Changed font-related attributes of the `default' face are
4214 reflected in changed `font' frame parameters. */
4216 && (font_related_attr_p
|| font_attr_p
)
4217 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
4218 set_font_frame_param (frame
, lface
);
4220 #endif /* HAVE_WINDOW_SYSTEM */
4222 if (EQ (attr
, QCforeground
))
4223 param
= Qforeground_color
;
4224 else if (EQ (attr
, QCbackground
))
4225 param
= Qbackground_color
;
4227 #ifdef HAVE_WINDOW_SYSTEM
4229 else if (EQ (face
, Qscroll_bar
))
4231 /* Changing the colors of `scroll-bar' sets frame parameters
4232 `scroll-bar-foreground' and `scroll-bar-background'. */
4233 if (EQ (attr
, QCforeground
))
4234 param
= Qscroll_bar_foreground
;
4235 else if (EQ (attr
, QCbackground
))
4236 param
= Qscroll_bar_background
;
4238 #endif /* not WINDOWSNT */
4239 else if (EQ (face
, Qborder
))
4241 /* Changing background color of `border' sets frame parameter
4243 if (EQ (attr
, QCbackground
))
4244 param
= Qborder_color
;
4246 else if (EQ (face
, Qcursor
))
4248 /* Changing background color of `cursor' sets frame parameter
4250 if (EQ (attr
, QCbackground
))
4251 param
= Qcursor_color
;
4253 else if (EQ (face
, Qmouse
))
4255 /* Changing background color of `mouse' sets frame parameter
4257 if (EQ (attr
, QCbackground
))
4258 param
= Qmouse_color
;
4260 #endif /* HAVE_WINDOW_SYSTEM */
4261 else if (EQ (face
, Qmenu
))
4263 /* Indicate that we have to update the menu bar when
4264 realizing faces on FRAME. FRAME t change the
4265 default for new frames. We do this by setting
4266 setting the flag in new face caches */
4269 struct frame
*f
= XFRAME (frame
);
4270 if (FRAME_FACE_CACHE (f
) == NULL
)
4271 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
4272 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 1;
4275 menu_face_changed_default
= 1;
4281 /* Update `default-frame-alist', which is used for new frames. */
4283 store_in_alist (&Vdefault_frame_alist
, param
, value
);
4286 /* Update the current frame's parameters. */
4289 cons
= XCAR (Vparam_value_alist
);
4290 XSETCAR (cons
, param
);
4291 XSETCDR (cons
, value
);
4292 Fmodify_frame_parameters (frame
, Vparam_value_alist
);
4301 #ifdef HAVE_WINDOW_SYSTEM
4303 /* Set the `font' frame parameter of FRAME determined from `default'
4304 face attributes LFACE. If a face or fontset name is explicitely
4305 specfied in LFACE, use it as is. Otherwise, determine a font name
4306 from the other font-related atrributes of LFACE. In that case, if
4307 there's no matching font, signals an error. */
4310 set_font_frame_param (frame
, lface
)
4311 Lisp_Object frame
, lface
;
4313 struct frame
*f
= XFRAME (frame
);
4315 if (FRAME_WINDOW_P (f
))
4317 Lisp_Object font_name
;
4320 if (STRINGP (LFACE_FONT (lface
)))
4321 font_name
= LFACE_FONT (lface
);
4324 /* Choose a font name that reflects LFACE's attributes and has
4325 the registry and encoding pattern specified in the default
4326 fontset (3rd arg: -1) for ASCII characters (4th arg: 0). */
4327 font
= choose_face_font (f
, XVECTOR (lface
)->contents
, -1, 0);
4329 error ("No font matches the specified attribute");
4330 font_name
= build_string (font
);
4334 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qfont
, font_name
), Qnil
));
4339 /* Update the corresponding face when frame parameter PARAM on frame F
4340 has been assigned the value NEW_VALUE. */
4343 update_face_from_frame_parameter (f
, param
, new_value
)
4345 Lisp_Object param
, new_value
;
4349 /* If there are no faces yet, give up. This is the case when called
4350 from Fx_create_frame, and we do the necessary things later in
4351 face-set-after-frame-defaults. */
4352 if (NILP (f
->face_alist
))
4355 /* Changing a named face means that all realized faces depending on
4356 that face are invalid. Since we cannot tell which realized faces
4357 depend on the face, make sure they are all removed. This is done
4358 by incrementing face_change_count. The next call to
4359 init_iterator will then free realized faces. */
4360 ++face_change_count
;
4361 ++windows_or_buffers_changed
;
4363 if (EQ (param
, Qforeground_color
))
4365 lface
= lface_from_face_name (f
, Qdefault
, 1);
4366 LFACE_FOREGROUND (lface
) = (STRINGP (new_value
)
4367 ? new_value
: Qunspecified
);
4368 realize_basic_faces (f
);
4370 else if (EQ (param
, Qbackground_color
))
4374 /* Changing the background color might change the background
4375 mode, so that we have to load new defface specs. Call
4376 frame-update-face-colors to do that. */
4377 XSETFRAME (frame
, f
);
4378 call1 (Qframe_update_face_colors
, frame
);
4380 lface
= lface_from_face_name (f
, Qdefault
, 1);
4381 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4382 ? new_value
: Qunspecified
);
4383 realize_basic_faces (f
);
4385 if (EQ (param
, Qborder_color
))
4387 lface
= lface_from_face_name (f
, Qborder
, 1);
4388 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4389 ? new_value
: Qunspecified
);
4391 else if (EQ (param
, Qcursor_color
))
4393 lface
= lface_from_face_name (f
, Qcursor
, 1);
4394 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4395 ? new_value
: Qunspecified
);
4397 else if (EQ (param
, Qmouse_color
))
4399 lface
= lface_from_face_name (f
, Qmouse
, 1);
4400 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
4401 ? new_value
: Qunspecified
);
4406 /* Get the value of X resource RESOURCE, class CLASS for the display
4407 of frame FRAME. This is here because ordinary `x-get-resource'
4408 doesn't take a frame argument. */
4410 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
4411 Sinternal_face_x_get_resource
, 3, 3, 0, doc
: /* */)
4412 (resource
, class, frame
)
4413 Lisp_Object resource
, class, frame
;
4415 Lisp_Object value
= Qnil
;
4418 CHECK_STRING (resource
);
4419 CHECK_STRING (class);
4420 CHECK_LIVE_FRAME (frame
);
4422 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame
)),
4423 resource
, class, Qnil
, Qnil
);
4425 #endif /* not MAC_OS */
4426 #endif /* not WINDOWSNT */
4431 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
4432 If VALUE is "on" or "true", return t. If VALUE is "off" or
4433 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
4434 error; if SIGNAL_P is zero, return 0. */
4437 face_boolean_x_resource_value (value
, signal_p
)
4441 Lisp_Object result
= make_number (0);
4443 xassert (STRINGP (value
));
4445 if (xstricmp (XSTRING (value
)->data
, "on") == 0
4446 || xstricmp (XSTRING (value
)->data
, "true") == 0)
4448 else if (xstricmp (XSTRING (value
)->data
, "off") == 0
4449 || xstricmp (XSTRING (value
)->data
, "false") == 0)
4451 else if (xstricmp (XSTRING (value
)->data
, "unspecified") == 0)
4452 result
= Qunspecified
;
4454 signal_error ("Invalid face attribute value from X resource", value
);
4460 DEFUN ("internal-set-lisp-face-attribute-from-resource",
4461 Finternal_set_lisp_face_attribute_from_resource
,
4462 Sinternal_set_lisp_face_attribute_from_resource
,
4463 3, 4, 0, doc
: /* */)
4464 (face
, attr
, value
, frame
)
4465 Lisp_Object face
, attr
, value
, frame
;
4467 CHECK_SYMBOL (face
);
4468 CHECK_SYMBOL (attr
);
4469 CHECK_STRING (value
);
4471 if (xstricmp (XSTRING (value
)->data
, "unspecified") == 0)
4472 value
= Qunspecified
;
4473 else if (EQ (attr
, QCheight
))
4475 value
= Fstring_to_number (value
, make_number (10));
4476 if (XINT (value
) <= 0)
4477 signal_error ("Invalid face height from X resource", value
);
4479 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
4480 value
= face_boolean_x_resource_value (value
, 1);
4481 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
4482 value
= intern (XSTRING (value
)->data
);
4483 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
4484 value
= face_boolean_x_resource_value (value
, 1);
4485 else if (EQ (attr
, QCunderline
)
4486 || EQ (attr
, QCoverline
)
4487 || EQ (attr
, QCstrike_through
))
4489 Lisp_Object boolean_value
;
4491 /* If the result of face_boolean_x_resource_value is t or nil,
4492 VALUE does NOT specify a color. */
4493 boolean_value
= face_boolean_x_resource_value (value
, 0);
4494 if (SYMBOLP (boolean_value
))
4495 value
= boolean_value
;
4497 else if (EQ (attr
, QCbox
))
4498 value
= Fcar (Fread_from_string (value
, Qnil
, Qnil
));
4500 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
4503 #endif /* HAVE_WINDOW_SYSTEM */
4506 /***********************************************************************
4508 ***********************************************************************/
4510 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
4512 /* Make menus on frame F appear as specified by the `menu' face. */
4515 x_update_menu_appearance (f
)
4518 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
4522 && (rdb
= XrmGetDatabase (FRAME_X_DISPLAY (f
)),
4526 Lisp_Object lface
= lface_from_face_name (f
, Qmenu
, 1);
4527 struct face
*face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
4528 char *myname
= XSTRING (Vx_resource_name
)->data
;
4531 const char *popup_path
= "popup_menu";
4533 const char *popup_path
= "menu.popup";
4536 if (STRINGP (LFACE_FOREGROUND (lface
)))
4538 sprintf (line
, "%s.%s*foreground: %s",
4540 XSTRING (LFACE_FOREGROUND (lface
))->data
);
4541 XrmPutLineResource (&rdb
, line
);
4542 sprintf (line
, "%s.pane.menubar*foreground: %s",
4543 myname
, XSTRING (LFACE_FOREGROUND (lface
))->data
);
4544 XrmPutLineResource (&rdb
, line
);
4548 if (STRINGP (LFACE_BACKGROUND (lface
)))
4550 sprintf (line
, "%s.%s*background: %s",
4552 XSTRING (LFACE_BACKGROUND (lface
))->data
);
4553 XrmPutLineResource (&rdb
, line
);
4554 sprintf (line
, "%s.pane.menubar*background: %s",
4555 myname
, XSTRING (LFACE_BACKGROUND (lface
))->data
);
4556 XrmPutLineResource (&rdb
, line
);
4561 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
4562 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
4563 || !UNSPECIFIEDP (LFACE_AVGWIDTH (lface
))
4564 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
4565 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
4566 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
4569 const char *suffix
= "List";
4571 const char *suffix
= "";
4573 sprintf (line
, "%s.pane.menubar*font%s: %s",
4574 myname
, suffix
, face
->font_name
);
4575 XrmPutLineResource (&rdb
, line
);
4576 sprintf (line
, "%s.%s*font%s: %s",
4577 myname
, popup_path
, suffix
, face
->font_name
);
4578 XrmPutLineResource (&rdb
, line
);
4582 if (changed_p
&& f
->output_data
.x
->menubar_widget
)
4583 free_frame_menubar (f
);
4587 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
4590 DEFUN ("face-attribute-relative-p", Fface_attribute_relative_p
,
4591 Sface_attribute_relative_p
,
4593 doc
: /* Return non-nil if face ATTRIBUTE VALUE is relative. */)
4595 Lisp_Object attribute
, value
;
4597 if (EQ (value
, Qunspecified
))
4599 else if (EQ (attribute
, QCheight
))
4600 return INTEGERP (value
) ? Qnil
: Qt
;
4605 DEFUN ("merge-face-attribute", Fmerge_face_attribute
, Smerge_face_attribute
,
4607 doc
: /* Return face ATTRIBUTE VALUE1 merged with VALUE2.
4608 If VALUE1 or VALUE2 are absolute (see `face-attribute-relative-p'), then
4609 the result will be absolute, otherwise it will be relative. */)
4610 (attribute
, value1
, value2
)
4611 Lisp_Object attribute
, value1
, value2
;
4613 if (EQ (value1
, Qunspecified
))
4615 else if (EQ (attribute
, QCheight
))
4616 return merge_face_heights (value1
, value2
, value1
, Qnil
);
4622 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
4623 Sinternal_get_lisp_face_attribute
,
4625 doc
: /* Return face attribute KEYWORD of face SYMBOL.
4626 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid
4627 face attribute name, signal an error.
4628 If the optional argument FRAME is given, report on face FACE in that
4629 frame. If FRAME is t, report on the defaults for face FACE (for new
4630 frames). If FRAME is omitted or nil, use the selected frame. */)
4631 (symbol
, keyword
, frame
)
4632 Lisp_Object symbol
, keyword
, frame
;
4634 Lisp_Object lface
, value
= Qnil
;
4636 CHECK_SYMBOL (symbol
);
4637 CHECK_SYMBOL (keyword
);
4640 lface
= lface_from_face_name (NULL
, symbol
, 1);
4644 frame
= selected_frame
;
4645 CHECK_LIVE_FRAME (frame
);
4646 lface
= lface_from_face_name (XFRAME (frame
), symbol
, 1);
4649 if (EQ (keyword
, QCfamily
))
4650 value
= LFACE_FAMILY (lface
);
4651 else if (EQ (keyword
, QCheight
))
4652 value
= LFACE_HEIGHT (lface
);
4653 else if (EQ (keyword
, QCweight
))
4654 value
= LFACE_WEIGHT (lface
);
4655 else if (EQ (keyword
, QCslant
))
4656 value
= LFACE_SLANT (lface
);
4657 else if (EQ (keyword
, QCunderline
))
4658 value
= LFACE_UNDERLINE (lface
);
4659 else if (EQ (keyword
, QCoverline
))
4660 value
= LFACE_OVERLINE (lface
);
4661 else if (EQ (keyword
, QCstrike_through
))
4662 value
= LFACE_STRIKE_THROUGH (lface
);
4663 else if (EQ (keyword
, QCbox
))
4664 value
= LFACE_BOX (lface
);
4665 else if (EQ (keyword
, QCinverse_video
)
4666 || EQ (keyword
, QCreverse_video
))
4667 value
= LFACE_INVERSE (lface
);
4668 else if (EQ (keyword
, QCforeground
))
4669 value
= LFACE_FOREGROUND (lface
);
4670 else if (EQ (keyword
, QCbackground
))
4671 value
= LFACE_BACKGROUND (lface
);
4672 else if (EQ (keyword
, QCstipple
))
4673 value
= LFACE_STIPPLE (lface
);
4674 else if (EQ (keyword
, QCwidth
))
4675 value
= LFACE_SWIDTH (lface
);
4676 else if (EQ (keyword
, QCinherit
))
4677 value
= LFACE_INHERIT (lface
);
4678 else if (EQ (keyword
, QCfont
))
4679 value
= LFACE_FONT (lface
);
4681 signal_error ("Invalid face attribute name", keyword
);
4687 DEFUN ("internal-lisp-face-attribute-values",
4688 Finternal_lisp_face_attribute_values
,
4689 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
4690 doc
: /* Return a list of valid discrete values for face attribute ATTR.
4691 Value is nil if ATTR doesn't have a discrete set of valid values. */)
4695 Lisp_Object result
= Qnil
;
4697 CHECK_SYMBOL (attr
);
4699 if (EQ (attr
, QCweight
)
4700 || EQ (attr
, QCslant
)
4701 || EQ (attr
, QCwidth
))
4703 /* Extract permissible symbols from tables. */
4704 struct table_entry
*table
;
4707 if (EQ (attr
, QCweight
))
4708 table
= weight_table
, dim
= DIM (weight_table
);
4709 else if (EQ (attr
, QCslant
))
4710 table
= slant_table
, dim
= DIM (slant_table
);
4712 table
= swidth_table
, dim
= DIM (swidth_table
);
4714 for (i
= 0; i
< dim
; ++i
)
4716 Lisp_Object symbol
= *table
[i
].symbol
;
4717 Lisp_Object tail
= result
;
4720 && !EQ (XCAR (tail
), symbol
))
4724 result
= Fcons (symbol
, result
);
4727 else if (EQ (attr
, QCunderline
))
4728 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4729 else if (EQ (attr
, QCoverline
))
4730 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4731 else if (EQ (attr
, QCstrike_through
))
4732 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4733 else if (EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
4734 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4740 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
4741 Sinternal_merge_in_global_face
, 2, 2, 0,
4742 doc
: /* Add attributes from frame-default definition of FACE to FACE on FRAME.
4743 Default face attributes override any local face attributes. */)
4745 Lisp_Object face
, frame
;
4748 Lisp_Object global_lface
, local_lface
, *gvec
, *lvec
;
4750 CHECK_LIVE_FRAME (frame
);
4751 global_lface
= lface_from_face_name (NULL
, face
, 1);
4752 local_lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
4753 if (NILP (local_lface
))
4754 local_lface
= Finternal_make_lisp_face (face
, frame
);
4756 /* Make every specified global attribute override the local one.
4757 BEWARE!! This is only used from `face-set-after-frame-default' where
4758 the local frame is defined from default specs in `face-defface-spec'
4759 and those should be overridden by global settings. Hence the strange
4760 "global before local" priority. */
4761 lvec
= XVECTOR (local_lface
)->contents
;
4762 gvec
= XVECTOR (global_lface
)->contents
;
4763 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4764 if (! UNSPECIFIEDP (gvec
[i
]))
4771 /* The following function is implemented for compatibility with 20.2.
4772 The function is used in x-resolve-fonts when it is asked to
4773 return fonts with the same size as the font of a face. This is
4774 done in fontset.el. */
4776 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 2, 0,
4777 doc
: /* Return the font name of face FACE, or nil if it is unspecified.
4778 If the optional argument FRAME is given, report on face FACE in that frame.
4779 If FRAME is t, report on the defaults for face FACE (for new frames).
4780 The font default for a face is either nil, or a list
4781 of the form (bold), (italic) or (bold italic).
4782 If FRAME is omitted or nil, use the selected frame. */)
4784 Lisp_Object face
, frame
;
4788 Lisp_Object result
= Qnil
;
4789 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
4791 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
4792 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
4793 result
= Fcons (Qbold
, result
);
4795 if (!UNSPECIFIEDP (LFACE_SLANT (lface
))
4796 && !EQ (LFACE_SLANT (lface
), Qnormal
))
4797 result
= Fcons (Qitalic
, result
);
4803 struct frame
*f
= frame_or_selected_frame (frame
, 1);
4804 int face_id
= lookup_named_face (f
, face
, 0);
4805 struct face
*face
= FACE_FROM_ID (f
, face_id
);
4806 return face
? build_string (face
->font_name
) : Qnil
;
4811 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
4812 all attributes are `equal'. Tries to be fast because this function
4813 is called quite often. */
4816 lface_equal_p (v1
, v2
)
4817 Lisp_Object
*v1
, *v2
;
4821 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
4823 Lisp_Object a
= v1
[i
];
4824 Lisp_Object b
= v2
[i
];
4826 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
4827 and the other is specified. */
4828 equal_p
= XTYPE (a
) == XTYPE (b
);
4837 equal_p
= ((STRING_BYTES (XSTRING (a
))
4838 == STRING_BYTES (XSTRING (b
)))
4839 && bcmp (XSTRING (a
)->data
, XSTRING (b
)->data
,
4840 STRING_BYTES (XSTRING (a
))) == 0);
4849 equal_p
= !NILP (Fequal (a
, b
));
4859 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
4860 Sinternal_lisp_face_equal_p
, 2, 3, 0,
4861 doc
: /* True if FACE1 and FACE2 are equal.
4862 If the optional argument FRAME is given, report on face FACE in that frame.
4863 If FRAME is t, report on the defaults for face FACE (for new frames).
4864 If FRAME is omitted or nil, use the selected frame. */)
4865 (face1
, face2
, frame
)
4866 Lisp_Object face1
, face2
, frame
;
4870 Lisp_Object lface1
, lface2
;
4875 /* Don't use check_x_frame here because this function is called
4876 before X frames exist. At that time, if FRAME is nil,
4877 selected_frame will be used which is the frame dumped with
4878 Emacs. That frame is not an X frame. */
4879 f
= frame_or_selected_frame (frame
, 2);
4881 lface1
= lface_from_face_name (NULL
, face1
, 1);
4882 lface2
= lface_from_face_name (NULL
, face2
, 1);
4883 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
4884 XVECTOR (lface2
)->contents
);
4885 return equal_p
? Qt
: Qnil
;
4889 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
4890 Sinternal_lisp_face_empty_p
, 1, 2, 0,
4891 doc
: /* True if FACE has no attribute specified.
4892 If the optional argument FRAME is given, report on face FACE in that frame.
4893 If FRAME is t, report on the defaults for face FACE (for new frames).
4894 If FRAME is omitted or nil, use the selected frame. */)
4896 Lisp_Object face
, frame
;
4903 frame
= selected_frame
;
4904 CHECK_LIVE_FRAME (frame
);
4908 lface
= lface_from_face_name (NULL
, face
, 1);
4910 lface
= lface_from_face_name (f
, face
, 1);
4912 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4913 if (!UNSPECIFIEDP (AREF (lface
, i
)))
4916 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
4920 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
4922 doc
: /* Return an alist of frame-local faces defined on FRAME.
4923 For internal use only. */)
4927 struct frame
*f
= frame_or_selected_frame (frame
, 0);
4928 return f
->face_alist
;
4932 /* Return a hash code for Lisp string STRING with case ignored. Used
4933 below in computing a hash value for a Lisp face. */
4935 static INLINE
unsigned
4936 hash_string_case_insensitive (string
)
4941 xassert (STRINGP (string
));
4942 for (s
= XSTRING (string
)->data
; *s
; ++s
)
4943 hash
= (hash
<< 1) ^ tolower (*s
);
4948 /* Return a hash code for face attribute vector V. */
4950 static INLINE
unsigned
4954 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
4955 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
4956 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
4957 ^ XFASTINT (v
[LFACE_WEIGHT_INDEX
])
4958 ^ XFASTINT (v
[LFACE_SLANT_INDEX
])
4959 ^ XFASTINT (v
[LFACE_SWIDTH_INDEX
])
4960 ^ XFASTINT (v
[LFACE_HEIGHT_INDEX
]));
4964 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
4965 considering charsets/registries). They do if they specify the same
4966 family, point size, weight, width, slant, and fontset. Both LFACE1
4967 and LFACE2 must be fully-specified. */
4970 lface_same_font_attributes_p (lface1
, lface2
)
4971 Lisp_Object
*lface1
, *lface2
;
4973 xassert (lface_fully_specified_p (lface1
)
4974 && lface_fully_specified_p (lface2
));
4975 return (xstricmp (XSTRING (lface1
[LFACE_FAMILY_INDEX
])->data
,
4976 XSTRING (lface2
[LFACE_FAMILY_INDEX
])->data
) == 0
4977 && EQ (lface1
[LFACE_HEIGHT_INDEX
], lface2
[LFACE_HEIGHT_INDEX
])
4978 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
4979 && EQ (lface1
[LFACE_AVGWIDTH_INDEX
], lface2
[LFACE_AVGWIDTH_INDEX
])
4980 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
4981 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
])
4982 && (EQ (lface1
[LFACE_FONT_INDEX
], lface2
[LFACE_FONT_INDEX
])
4983 || (STRINGP (lface1
[LFACE_FONT_INDEX
])
4984 && STRINGP (lface2
[LFACE_FONT_INDEX
])
4985 && xstricmp (XSTRING (lface1
[LFACE_FONT_INDEX
])->data
,
4986 XSTRING (lface2
[LFACE_FONT_INDEX
])->data
))));
4991 /***********************************************************************
4993 ***********************************************************************/
4995 /* Allocate and return a new realized face for Lisp face attribute
4998 static struct face
*
4999 make_realized_face (attr
)
5002 struct face
*face
= (struct face
*) xmalloc (sizeof *face
);
5003 bzero (face
, sizeof *face
);
5004 face
->ascii_face
= face
;
5005 bcopy (attr
, face
->lface
, sizeof face
->lface
);
5010 /* Free realized face FACE, including its X resources. FACE may
5014 free_realized_face (f
, face
)
5020 #ifdef HAVE_WINDOW_SYSTEM
5021 if (FRAME_WINDOW_P (f
))
5023 /* Free fontset of FACE if it is ASCII face. */
5024 if (face
->fontset
>= 0 && face
== face
->ascii_face
)
5025 free_face_fontset (f
, face
);
5028 x_free_gc (f
, face
->gc
);
5032 free_face_colors (f
, face
);
5033 x_destroy_bitmap (f
, face
->stipple
);
5035 #endif /* HAVE_WINDOW_SYSTEM */
5042 /* Prepare face FACE for subsequent display on frame F. This
5043 allocated GCs if they haven't been allocated yet or have been freed
5044 by clearing the face cache. */
5047 prepare_face_for_display (f
, face
)
5051 #ifdef HAVE_WINDOW_SYSTEM
5052 xassert (FRAME_WINDOW_P (f
));
5057 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
5059 xgcv
.foreground
= face
->foreground
;
5060 xgcv
.background
= face
->background
;
5061 #ifdef HAVE_X_WINDOWS
5062 xgcv
.graphics_exposures
= False
;
5064 /* The font of FACE may be null if we couldn't load it. */
5067 #ifdef HAVE_X_WINDOWS
5068 xgcv
.font
= face
->font
->fid
;
5071 xgcv
.font
= face
->font
;
5074 xgcv
.font
= face
->font
;
5080 #ifdef HAVE_X_WINDOWS
5083 xgcv
.fill_style
= FillOpaqueStippled
;
5084 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
5085 mask
|= GCFillStyle
| GCStipple
;
5088 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
5091 #endif /* HAVE_WINDOW_SYSTEM */
5095 /* Returns the `distance' between the colors X and Y. */
5098 color_distance (x
, y
)
5101 /* This formula is from a paper title `Colour metric' by Thiadmer Riemersma.
5102 Quoting from that paper:
5104 This formula has results that are very close to L*u*v* (with the
5105 modified lightness curve) and, more importantly, it is a more even
5106 algorithm: it does not have a range of colours where it suddenly
5107 gives far from optimal results.
5109 See <http://www.compuphase.com/cmetric.htm> for more info. */
5111 long r
= (x
->red
- y
->red
) >> 8;
5112 long g
= (x
->green
- y
->green
) >> 8;
5113 long b
= (x
->blue
- y
->blue
) >> 8;
5114 long r_mean
= (x
->red
+ y
->red
) >> 9;
5117 (((512 + r_mean
) * r
* r
) >> 8)
5119 + (((767 - r_mean
) * b
* b
) >> 8);
5123 DEFUN ("color-distance", Fcolor_distance
, Scolor_distance
, 2, 3, 0,
5124 doc
: /* Return an integer distance between COLOR1 and COLOR2 on FRAME.
5125 COLOR1 and COLOR2 may be either strings containing the color name,
5126 or lists of the form (RED GREEN BLUE).
5127 If FRAME is unspecified or nil, the current frame is used. */)
5128 (color1
, color2
, frame
)
5129 Lisp_Object color1
, color2
, frame
;
5132 XColor cdef1
, cdef2
;
5135 frame
= selected_frame
;
5136 CHECK_LIVE_FRAME (frame
);
5139 if ((CONSP (color1
) && !parse_rgb_list (color1
, &cdef1
))
5140 || !STRINGP (color1
)
5141 || !defined_color (f
, XSTRING (color1
)->data
, &cdef1
, 0))
5142 signal_error ("Invalid color", color1
);
5143 if ((CONSP (color2
) && !parse_rgb_list (color2
, &cdef2
))
5144 || !STRINGP (color2
)
5145 || !defined_color (f
, XSTRING (color2
)->data
, &cdef2
, 0))
5146 signal_error ("Invalid color", color2
);
5148 return make_number (color_distance (&cdef1
, &cdef2
));
5152 /***********************************************************************
5153 Face capability testing for ttys
5154 ***********************************************************************/
5157 /* If the distance (as returned by color_distance) between two colors is
5158 less than this, then they are considered the same, for determining
5159 whether a color is supported or not. The range of values is 0-65535. */
5161 #define TTY_SAME_COLOR_THRESHOLD 10000
5164 DEFUN ("tty-supports-face-attributes-p",
5165 Ftty_supports_face_attributes_p
, Stty_supports_face_attributes_p
,
5167 doc
: /* Return non-nil if all the face attributes in ATTRIBUTES are supported.
5168 The optional argument FRAME is the frame on which to test; if it is nil
5169 or unspecified, then the current frame is used. If FRAME is not a tty
5170 frame, then nil is returned.
5172 The definition of `supported' is somewhat heuristic, but basically means
5173 that a face containing all the attributes in ATTRIBUTES, when merged
5174 with the default face for display, can be represented in a way that's
5176 \(1) different in appearance than the default face, and
5177 \(2) `close in spirit' to what the attributes specify, if not exact.
5179 Point (2) implies that a `:weight black' attribute will be satisified
5180 by any terminal that can display bold, and a `:foreground "yellow"' as
5181 long as the terminal can display a yellowish color, but `:slant italic'
5182 will _not_ be satisified by the tty display code's automatic
5183 substitution of a `dim' face for italic. */)
5185 Lisp_Object attributes
, frame
;
5189 Lisp_Object val
, fg
, bg
;
5190 XColor fg_tty_color
, fg_std_color
;
5191 XColor bg_tty_color
, bg_std_color
;
5192 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5193 unsigned test_caps
= 0;
5196 frame
= selected_frame
;
5197 CHECK_LIVE_FRAME (frame
);
5200 for (i
= 0; i
< LFACE_VECTOR_SIZE
; i
++)
5201 attrs
[i
] = Qunspecified
;
5202 merge_face_vector_with_property (f
, attrs
, attributes
);
5204 /* This function only works on ttys. */
5205 if (!FRAME_TERMCAP_P (f
) && !FRAME_MSDOS_P (f
))
5208 /* First check some easy-to-check stuff; ttys support none of the
5209 following attributes, so we can just return nil if any are requested. */
5212 val
= attrs
[LFACE_STIPPLE_INDEX
];
5213 if (!UNSPECIFIEDP (val
) && !NILP (val
))
5217 val
= attrs
[LFACE_HEIGHT_INDEX
];
5218 if (!UNSPECIFIEDP (val
) && !NILP (val
))
5222 val
= attrs
[LFACE_SWIDTH_INDEX
];
5223 if (!UNSPECIFIEDP (val
) && !NILP (val
)
5224 && face_numeric_swidth (val
) != XLFD_SWIDTH_MEDIUM
)
5228 val
= attrs
[LFACE_OVERLINE_INDEX
];
5229 if (!UNSPECIFIEDP (val
) && !NILP (val
))
5232 /* strike-through */
5233 val
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
5234 if (!UNSPECIFIEDP (val
) && !NILP (val
))
5238 val
= attrs
[LFACE_BOX_INDEX
];
5239 if (!UNSPECIFIEDP (val
) && !NILP (val
))
5242 /* slant (italics/oblique); We consider any non-default value
5243 unsupportable on ttys, even though the face code actually `fakes'
5244 them using a dim attribute if possible. This is because the faked
5245 result is too different from what the face specifies. */
5246 val
= attrs
[LFACE_SLANT_INDEX
];
5247 if (!UNSPECIFIEDP (val
) && !NILP (val
)
5248 && face_numeric_slant (val
) != XLFD_SLANT_ROMAN
)
5252 /* Test for terminal `capabilities' (non-color character attributes). */
5254 /* font weight (bold/dim) */
5255 weight
= face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
5258 if (weight
> XLFD_WEIGHT_MEDIUM
)
5259 test_caps
= TTY_CAP_BOLD
;
5260 else if (weight
< XLFD_WEIGHT_MEDIUM
)
5261 test_caps
= TTY_CAP_DIM
;
5265 val
= attrs
[LFACE_UNDERLINE_INDEX
];
5266 if (!UNSPECIFIEDP (val
) && !NILP (val
))
5269 return Qnil
; /* ttys don't support colored underlines */
5271 test_caps
|= TTY_CAP_UNDERLINE
;
5275 val
= attrs
[LFACE_INVERSE_INDEX
];
5276 if (!UNSPECIFIEDP (val
) && !NILP (val
))
5277 test_caps
|= TTY_CAP_INVERSE
;
5280 /* Color testing. */
5282 /* Default the color indices in FG_TTY_COLOR and BG_TTY_COLOR, since
5283 we use them when calling `tty_capable_p' below, even if the face
5284 specifies no colors. */
5285 fg_tty_color
.pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
5286 bg_tty_color
.pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
5288 /* Check if foreground color is close enough. */
5289 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
5292 if (! tty_lookup_color (f
, fg
, &fg_tty_color
, &fg_std_color
))
5294 else if (color_distance (&fg_tty_color
, &fg_std_color
)
5295 > TTY_SAME_COLOR_THRESHOLD
)
5299 /* Check if background color is close enough. */
5300 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
5303 if (! tty_lookup_color (f
, bg
, &bg_tty_color
, &bg_std_color
))
5305 else if (color_distance (&bg_tty_color
, &bg_std_color
)
5306 > TTY_SAME_COLOR_THRESHOLD
)
5310 /* If both foreground and background are requested, see if the
5311 distance between them is OK. We just check to see if the distance
5312 between the tty's foreground and background is close enough to the
5313 distance between the standard foreground and background. */
5314 if (STRINGP (fg
) && STRINGP (bg
))
5317 = (color_distance (&fg_std_color
, &bg_std_color
)
5318 - color_distance (&fg_tty_color
, &bg_tty_color
));
5319 if (delta_delta
> TTY_SAME_COLOR_THRESHOLD
5320 || delta_delta
< -TTY_SAME_COLOR_THRESHOLD
)
5325 /* See if the capabilities we selected above are supported, with the
5327 if (test_caps
!= 0 &&
5328 ! tty_capable_p (f
, test_caps
, fg_tty_color
.pixel
, bg_tty_color
.pixel
))
5332 /* Hmmm, everything checks out, this terminal must support this face. */
5338 /***********************************************************************
5340 ***********************************************************************/
5342 /* Return a new face cache for frame F. */
5344 static struct face_cache
*
5348 struct face_cache
*c
;
5351 c
= (struct face_cache
*) xmalloc (sizeof *c
);
5352 bzero (c
, sizeof *c
);
5353 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
5354 c
->buckets
= (struct face
**) xmalloc (size
);
5355 bzero (c
->buckets
, size
);
5357 c
->faces_by_id
= (struct face
**) xmalloc (c
->size
* sizeof *c
->faces_by_id
);
5359 c
->menu_face_changed_p
= menu_face_changed_default
;
5364 /* Clear out all graphics contexts for all realized faces, except for
5365 the basic faces. This should be done from time to time just to avoid
5366 keeping too many graphics contexts that are no longer needed. */
5370 struct face_cache
*c
;
5372 if (c
&& FRAME_WINDOW_P (c
->f
))
5374 #ifdef HAVE_WINDOW_SYSTEM
5376 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
5378 struct face
*face
= c
->faces_by_id
[i
];
5379 if (face
&& face
->gc
)
5381 x_free_gc (c
->f
, face
->gc
);
5385 #endif /* HAVE_WINDOW_SYSTEM */
5390 /* Free all realized faces in face cache C, including basic faces. C
5391 may be null. If faces are freed, make sure the frame's current
5392 matrix is marked invalid, so that a display caused by an expose
5393 event doesn't try to use faces we destroyed. */
5396 free_realized_faces (c
)
5397 struct face_cache
*c
;
5402 struct frame
*f
= c
->f
;
5404 /* We must block input here because we can't process X events
5405 safely while only some faces are freed, or when the frame's
5406 current matrix still references freed faces. */
5409 for (i
= 0; i
< c
->used
; ++i
)
5411 free_realized_face (f
, c
->faces_by_id
[i
]);
5412 c
->faces_by_id
[i
] = NULL
;
5416 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
5417 bzero (c
->buckets
, size
);
5419 /* Must do a thorough redisplay the next time. Mark current
5420 matrices as invalid because they will reference faces freed
5421 above. This function is also called when a frame is
5422 destroyed. In this case, the root window of F is nil. */
5423 if (WINDOWP (f
->root_window
))
5425 clear_current_matrices (f
);
5426 ++windows_or_buffers_changed
;
5434 /* Free all faces realized for multibyte characters on frame F that
5438 free_realized_multibyte_face (f
, fontset
)
5442 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5446 /* We must block input here because we can't process X events safely
5447 while only some faces are freed, or when the frame's current
5448 matrix still references freed faces. */
5451 for (i
= 0; i
< cache
->used
; i
++)
5453 face
= cache
->faces_by_id
[i
];
5455 && face
!= face
->ascii_face
5456 && face
->fontset
== fontset
)
5458 uncache_face (cache
, face
);
5459 free_realized_face (f
, face
);
5463 /* Must do a thorough redisplay the next time. Mark current
5464 matrices as invalid because they will reference faces freed
5465 above. This function is also called when a frame is destroyed.
5466 In this case, the root window of F is nil. */
5467 if (WINDOWP (f
->root_window
))
5469 clear_current_matrices (f
);
5470 ++windows_or_buffers_changed
;
5477 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
5478 This is done after attributes of a named face have been changed,
5479 because we can't tell which realized faces depend on that face. */
5482 free_all_realized_faces (frame
)
5488 FOR_EACH_FRAME (rest
, frame
)
5489 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
5492 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
5496 /* Free face cache C and faces in it, including their X resources. */
5500 struct face_cache
*c
;
5504 free_realized_faces (c
);
5506 xfree (c
->faces_by_id
);
5512 /* Cache realized face FACE in face cache C. HASH is the hash value
5513 of FACE. If FACE->fontset >= 0, add the new face to the end of the
5514 collision list of the face hash table of C. This is done because
5515 otherwise lookup_face would find FACE for every character, even if
5516 faces with the same attributes but for specific characters exist. */
5519 cache_face (c
, face
, hash
)
5520 struct face_cache
*c
;
5524 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
5528 if (face
->fontset
>= 0)
5530 struct face
*last
= c
->buckets
[i
];
5541 c
->buckets
[i
] = face
;
5542 face
->prev
= face
->next
= NULL
;
5548 face
->next
= c
->buckets
[i
];
5550 face
->next
->prev
= face
;
5551 c
->buckets
[i
] = face
;
5554 /* Find a free slot in C->faces_by_id and use the index of the free
5555 slot as FACE->id. */
5556 for (i
= 0; i
< c
->used
; ++i
)
5557 if (c
->faces_by_id
[i
] == NULL
)
5561 /* Maybe enlarge C->faces_by_id. */
5562 if (i
== c
->used
&& c
->used
== c
->size
)
5564 int new_size
= 2 * c
->size
;
5565 int sz
= new_size
* sizeof *c
->faces_by_id
;
5566 c
->faces_by_id
= (struct face
**) xrealloc (c
->faces_by_id
, sz
);
5571 /* Check that FACE got a unique id. */
5576 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
5577 for (face
= c
->buckets
[j
]; face
; face
= face
->next
)
5583 #endif /* GLYPH_DEBUG */
5585 c
->faces_by_id
[i
] = face
;
5591 /* Remove face FACE from cache C. */
5594 uncache_face (c
, face
)
5595 struct face_cache
*c
;
5598 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
5601 face
->prev
->next
= face
->next
;
5603 c
->buckets
[i
] = face
->next
;
5606 face
->next
->prev
= face
->prev
;
5608 c
->faces_by_id
[face
->id
] = NULL
;
5609 if (face
->id
== c
->used
)
5614 /* Look up a realized face with face attributes ATTR in the face cache
5615 of frame F. The face will be used to display character C. Value
5616 is the ID of the face found. If no suitable face is found, realize
5617 a new one. In that case, if C is a multibyte character, BASE_FACE
5618 is a face that has the same attributes. */
5621 lookup_face (f
, attr
, c
, base_face
)
5625 struct face
*base_face
;
5627 struct face_cache
*cache
= FRAME_FACE_CACHE (f
);
5632 xassert (cache
!= NULL
);
5633 check_lface_attrs (attr
);
5635 /* Look up ATTR in the face cache. */
5636 hash
= lface_hash (attr
);
5637 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
5639 for (face
= cache
->buckets
[i
]; face
; face
= face
->next
)
5640 if (face
->hash
== hash
5641 && (!FRAME_WINDOW_P (f
)
5642 || FACE_SUITABLE_FOR_CHAR_P (face
, c
))
5643 && lface_equal_p (face
->lface
, attr
))
5646 /* If not found, realize a new face. */
5648 face
= realize_face (cache
, attr
, c
, base_face
, -1);
5651 xassert (face
== FACE_FROM_ID (f
, face
->id
));
5653 /* When this function is called from face_for_char (in this case, C is
5654 a multibyte character), a fontset of a face returned by
5655 realize_face is not yet set, i.e. FACE_SUITABLE_FOR_CHAR_P (FACE,
5656 C) is not sutisfied. The fontset is set for this face by
5657 face_for_char later. */
5659 if (FRAME_WINDOW_P (f
))
5660 xassert (FACE_SUITABLE_FOR_CHAR_P (face
, c
));
5662 #endif /* GLYPH_DEBUG */
5668 /* Return the face id of the realized face for named face SYMBOL on
5669 frame F suitable for displaying character C. Value is -1 if the
5670 face couldn't be determined, which might happen if the default face
5671 isn't realized and cannot be realized. */
5674 lookup_named_face (f
, symbol
, c
)
5679 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5680 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5681 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5683 if (default_face
== NULL
)
5685 if (!realize_basic_faces (f
))
5687 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5690 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
5691 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
5692 merge_face_vectors (f
, symbol_attrs
, attrs
, Qnil
);
5693 return lookup_face (f
, attrs
, c
, NULL
);
5697 /* Return the ID of the realized ASCII face of Lisp face with ID
5698 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
5701 ascii_face_of_lisp_face (f
, lface_id
)
5707 if (lface_id
>= 0 && lface_id
< lface_id_to_name_size
)
5709 Lisp_Object face_name
= lface_id_to_name
[lface_id
];
5710 face_id
= lookup_named_face (f
, face_name
, 0);
5719 /* Return a face for charset ASCII that is like the face with id
5720 FACE_ID on frame F, but has a font that is STEPS steps smaller.
5721 STEPS < 0 means larger. Value is the id of the face. */
5724 smaller_face (f
, face_id
, steps
)
5728 #ifdef HAVE_WINDOW_SYSTEM
5730 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5731 int pt
, last_pt
, last_height
;
5734 struct face
*new_face
;
5736 /* If not called for an X frame, just return the original face. */
5737 if (FRAME_TERMCAP_P (f
))
5740 /* Try in increments of 1/2 pt. */
5741 delta
= steps
< 0 ? 5 : -5;
5742 steps
= abs (steps
);
5744 face
= FACE_FROM_ID (f
, face_id
);
5745 bcopy (face
->lface
, attrs
, sizeof attrs
);
5746 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
5747 new_face_id
= face_id
;
5748 last_height
= FONT_HEIGHT (face
->font
);
5752 /* Give up if we cannot find a font within 10pt. */
5753 && abs (last_pt
- pt
) < 100)
5755 /* Look up a face for a slightly smaller/larger font. */
5757 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
5758 new_face_id
= lookup_face (f
, attrs
, 0, NULL
);
5759 new_face
= FACE_FROM_ID (f
, new_face_id
);
5761 /* If height changes, count that as one step. */
5762 if ((delta
< 0 && FONT_HEIGHT (new_face
->font
) < last_height
)
5763 || (delta
> 0 && FONT_HEIGHT (new_face
->font
) > last_height
))
5766 last_height
= FONT_HEIGHT (new_face
->font
);
5773 #else /* not HAVE_WINDOW_SYSTEM */
5777 #endif /* not HAVE_WINDOW_SYSTEM */
5781 /* Return a face for charset ASCII that is like the face with id
5782 FACE_ID on frame F, but has height HEIGHT. */
5785 face_with_height (f
, face_id
, height
)
5790 #ifdef HAVE_WINDOW_SYSTEM
5792 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5794 if (FRAME_TERMCAP_P (f
)
5798 face
= FACE_FROM_ID (f
, face_id
);
5799 bcopy (face
->lface
, attrs
, sizeof attrs
);
5800 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
5801 face_id
= lookup_face (f
, attrs
, 0, NULL
);
5802 #endif /* HAVE_WINDOW_SYSTEM */
5808 /* Return the face id of the realized face for named face SYMBOL on
5809 frame F suitable for displaying character C, and use attributes of
5810 the face FACE_ID for attributes that aren't completely specified by
5811 SYMBOL. This is like lookup_named_face, except that the default
5812 attributes come from FACE_ID, not from the default face. FACE_ID
5813 is assumed to be already realized. */
5816 lookup_derived_face (f
, symbol
, c
, face_id
)
5822 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5823 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5824 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
5829 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
5830 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
5831 merge_face_vectors (f
, symbol_attrs
, attrs
, Qnil
);
5832 return lookup_face (f
, attrs
, c
, default_face
);
5835 DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector
,
5836 Sface_attributes_as_vector
, 1, 1, 0,
5837 doc
: /* Return a vector of face attributes corresponding to PLIST. */)
5842 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
5844 merge_face_vector_with_property (XFRAME (selected_frame
),
5845 XVECTOR (lface
)->contents
,
5852 /***********************************************************************
5854 ***********************************************************************/
5856 DEFUN ("internal-set-font-selection-order",
5857 Finternal_set_font_selection_order
,
5858 Sinternal_set_font_selection_order
, 1, 1, 0,
5859 doc
: /* Set font selection order for face font selection to ORDER.
5860 ORDER must be a list of length 4 containing the symbols `:width',
5861 `:height', `:weight', and `:slant'. Face attributes appearing
5862 first in ORDER are matched first, e.g. if `:height' appears before
5863 `:weight' in ORDER, font selection first tries to find a font with
5864 a suitable height, and then tries to match the font weight.
5871 int indices
[DIM (font_sort_order
)];
5874 bzero (indices
, sizeof indices
);
5878 CONSP (list
) && i
< DIM (indices
);
5879 list
= XCDR (list
), ++i
)
5881 Lisp_Object attr
= XCAR (list
);
5884 if (EQ (attr
, QCwidth
))
5886 else if (EQ (attr
, QCheight
))
5887 xlfd
= XLFD_POINT_SIZE
;
5888 else if (EQ (attr
, QCweight
))
5890 else if (EQ (attr
, QCslant
))
5895 if (indices
[i
] != 0)
5900 if (!NILP (list
) || i
!= DIM (indices
))
5901 signal_error ("Invalid font sort order", order
);
5902 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5903 if (indices
[i
] == 0)
5904 signal_error ("Invalid font sort order", order
);
5906 if (bcmp (indices
, font_sort_order
, sizeof indices
) != 0)
5908 bcopy (indices
, font_sort_order
, sizeof font_sort_order
);
5909 free_all_realized_faces (Qnil
);
5916 DEFUN ("internal-set-alternative-font-family-alist",
5917 Finternal_set_alternative_font_family_alist
,
5918 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
5919 doc
: /* Define alternative font families to try in face font selection.
5920 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5921 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can
5922 be found. Value is ALIST. */)
5927 Vface_alternative_font_family_alist
= alist
;
5928 free_all_realized_faces (Qnil
);
5933 DEFUN ("internal-set-alternative-font-registry-alist",
5934 Finternal_set_alternative_font_registry_alist
,
5935 Sinternal_set_alternative_font_registry_alist
, 1, 1, 0,
5936 doc
: /* Define alternative font registries to try in face font selection.
5937 ALIST is an alist of (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...) entries.
5938 Each ALTERNATIVE is tried in order if no fonts of font registry REGISTRY can
5939 be found. Value is ALIST. */)
5944 Vface_alternative_font_registry_alist
= alist
;
5945 free_all_realized_faces (Qnil
);
5950 #ifdef HAVE_WINDOW_SYSTEM
5952 /* Value is non-zero if FONT is the name of a scalable font. The
5953 X11R6 XLFD spec says that point size, pixel size, and average width
5954 are zero for scalable fonts. Intlfonts contain at least one
5955 scalable font ("*-muleindian-1") for which this isn't true, so we
5956 just test average width. */
5959 font_scalable_p (font
)
5960 struct font_name
*font
;
5962 char *s
= font
->fields
[XLFD_AVGWIDTH
];
5963 return (*s
== '0' && *(s
+ 1) == '\0')
5965 /* Windows implementation of XLFD is slightly broken for backward
5966 compatibility with previous broken versions, so test for
5967 wildcards as well as 0. */
5974 /* Ignore the difference of font point size less than this value. */
5976 #define FONT_POINT_SIZE_QUANTUM 5
5978 /* Value is non-zero if FONT1 is a better match for font attributes
5979 VALUES than FONT2. VALUES is an array of face attribute values in
5980 font sort order. COMPARE_PT_P zero means don't compare point
5981 sizes. AVGWIDTH, if not zero, is a specified font average width
5985 better_font_p (values
, font1
, font2
, compare_pt_p
, avgwidth
)
5987 struct font_name
*font1
, *font2
;
5988 int compare_pt_p
, avgwidth
;
5992 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5994 int xlfd_idx
= font_sort_order
[i
];
5996 if (compare_pt_p
|| xlfd_idx
!= XLFD_POINT_SIZE
)
5998 int delta1
= abs (values
[i
] - font1
->numeric
[xlfd_idx
]);
5999 int delta2
= abs (values
[i
] - font2
->numeric
[xlfd_idx
]);
6001 if (xlfd_idx
== XLFD_POINT_SIZE
6002 && abs (delta1
- delta2
) < FONT_POINT_SIZE_QUANTUM
)
6004 if (delta1
> delta2
)
6006 else if (delta1
< delta2
)
6010 /* The difference may be equal because, e.g., the face
6011 specifies `italic' but we have only `regular' and
6012 `oblique'. Prefer `oblique' in this case. */
6013 if ((xlfd_idx
== XLFD_WEIGHT
|| xlfd_idx
== XLFD_SLANT
)
6014 && font1
->numeric
[xlfd_idx
] > values
[i
]
6015 && font2
->numeric
[xlfd_idx
] < values
[i
])
6023 int delta1
= abs (avgwidth
- font1
->numeric
[XLFD_AVGWIDTH
]);
6024 int delta2
= abs (avgwidth
- font2
->numeric
[XLFD_AVGWIDTH
]);
6025 if (delta1
> delta2
)
6027 else if (delta1
< delta2
)
6031 return font1
->registry_priority
< font2
->registry_priority
;
6035 /* Value is non-zero if FONT is an exact match for face attributes in
6036 SPECIFIED. SPECIFIED is an array of face attribute values in font
6037 sort order. AVGWIDTH, if non-zero, is an average width to compare
6041 exact_face_match_p (specified
, font
, avgwidth
)
6043 struct font_name
*font
;
6048 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6049 if (specified
[i
] != font
->numeric
[font_sort_order
[i
]])
6052 return (i
== DIM (font_sort_order
)
6054 || avgwidth
== font
->numeric
[XLFD_AVGWIDTH
]));
6058 /* Value is the name of a scaled font, generated from scalable font
6059 FONT on frame F. SPECIFIED_PT is the point-size to scale FONT to.
6060 Value is allocated from heap. */
6063 build_scalable_font_name (f
, font
, specified_pt
)
6065 struct font_name
*font
;
6068 char point_size
[20], pixel_size
[20];
6070 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
6073 /* If scalable font is for a specific resolution, compute
6074 the point size we must specify from the resolution of
6075 the display and the specified resolution of the font. */
6076 if (font
->numeric
[XLFD_RESY
] != 0)
6078 pt
= resy
/ font
->numeric
[XLFD_RESY
] * specified_pt
+ 0.5;
6079 pixel_value
= font
->numeric
[XLFD_RESY
] / (PT_PER_INCH
* 10.0) * pt
;
6084 pixel_value
= resy
/ (PT_PER_INCH
* 10.0) * pt
;
6087 /* Set point size of the font. */
6088 sprintf (point_size
, "%d", (int) pt
);
6089 font
->fields
[XLFD_POINT_SIZE
] = point_size
;
6090 font
->numeric
[XLFD_POINT_SIZE
] = pt
;
6092 /* Set pixel size. */
6093 sprintf (pixel_size
, "%d", pixel_value
);
6094 font
->fields
[XLFD_PIXEL_SIZE
] = pixel_size
;
6095 font
->numeric
[XLFD_PIXEL_SIZE
] = pixel_value
;
6097 /* If font doesn't specify its resolution, use the
6098 resolution of the display. */
6099 if (font
->numeric
[XLFD_RESY
] == 0)
6102 sprintf (buffer
, "%d", (int) resy
);
6103 font
->fields
[XLFD_RESY
] = buffer
;
6104 font
->numeric
[XLFD_RESY
] = resy
;
6107 if (strcmp (font
->fields
[XLFD_RESX
], "0") == 0)
6110 int resx
= FRAME_X_DISPLAY_INFO (f
)->resx
;
6111 sprintf (buffer
, "%d", resx
);
6112 font
->fields
[XLFD_RESX
] = buffer
;
6113 font
->numeric
[XLFD_RESX
] = resx
;
6116 return build_font_name (font
);
6120 /* Value is non-zero if we are allowed to use scalable font FONT. We
6121 can't run a Lisp function here since this function may be called
6122 with input blocked. */
6125 may_use_scalable_font_p (font
)
6128 if (EQ (Vscalable_fonts_allowed
, Qt
))
6130 else if (CONSP (Vscalable_fonts_allowed
))
6132 Lisp_Object tail
, regexp
;
6134 for (tail
= Vscalable_fonts_allowed
; CONSP (tail
); tail
= XCDR (tail
))
6136 regexp
= XCAR (tail
);
6137 if (STRINGP (regexp
)
6138 && fast_c_string_match_ignore_case (regexp
, font
) >= 0)
6148 /* Return the name of the best matching font for face attributes ATTRS
6149 in the array of font_name structures FONTS which contains NFONTS
6150 elements. WIDTH_RATIO is a factor with which to multiply average
6151 widths if ATTRS specifies such a width.
6153 Value is a font name which is allocated from the heap. FONTS is
6154 freed by this function. */
6157 best_matching_font (f
, attrs
, fonts
, nfonts
, width_ratio
)
6160 struct font_name
*fonts
;
6165 struct font_name
*best
;
6168 int exact_p
, avgwidth
;
6173 /* Make specified font attributes available in `specified',
6174 indexed by sort order. */
6175 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6177 int xlfd_idx
= font_sort_order
[i
];
6179 if (xlfd_idx
== XLFD_SWIDTH
)
6180 specified
[i
] = face_numeric_swidth (attrs
[LFACE_SWIDTH_INDEX
]);
6181 else if (xlfd_idx
== XLFD_POINT_SIZE
)
6182 specified
[i
] = pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
6183 else if (xlfd_idx
== XLFD_WEIGHT
)
6184 specified
[i
] = face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
6185 else if (xlfd_idx
== XLFD_SLANT
)
6186 specified
[i
] = face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
6191 avgwidth
= (UNSPECIFIEDP (attrs
[LFACE_AVGWIDTH_INDEX
])
6193 : XFASTINT (attrs
[LFACE_AVGWIDTH_INDEX
]) * width_ratio
);
6197 /* Start with the first non-scalable font in the list. */
6198 for (i
= 0; i
< nfonts
; ++i
)
6199 if (!font_scalable_p (fonts
+ i
))
6202 /* Find the best match among the non-scalable fonts. */
6207 for (i
= 1; i
< nfonts
; ++i
)
6208 if (!font_scalable_p (fonts
+ i
)
6209 && better_font_p (specified
, fonts
+ i
, best
, 1, avgwidth
))
6213 exact_p
= exact_face_match_p (specified
, best
, avgwidth
);
6222 /* Unless we found an exact match among non-scalable fonts, see if
6223 we can find a better match among scalable fonts. */
6226 /* A scalable font is better if
6228 1. its weight, slant, swidth attributes are better, or.
6230 2. the best non-scalable font doesn't have the required
6231 point size, and the scalable fonts weight, slant, swidth
6234 int non_scalable_has_exact_height_p
;
6236 if (best
&& best
->numeric
[XLFD_POINT_SIZE
] == pt
)
6237 non_scalable_has_exact_height_p
= 1;
6239 non_scalable_has_exact_height_p
= 0;
6241 for (i
= 0; i
< nfonts
; ++i
)
6242 if (font_scalable_p (fonts
+ i
))
6245 || better_font_p (specified
, fonts
+ i
, best
, 0, 0)
6246 || (!non_scalable_has_exact_height_p
6247 && !better_font_p (specified
, best
, fonts
+ i
, 0, 0)))
6252 if (font_scalable_p (best
))
6253 font_name
= build_scalable_font_name (f
, best
, pt
);
6255 font_name
= build_font_name (best
);
6257 /* Free font_name structures. */
6258 free_font_names (fonts
, nfonts
);
6264 /* Get a list of matching fonts on frame F, considering FAMILY
6265 and alternative font families from Vface_alternative_font_registry_alist.
6267 FAMILY is the font family whose alternatives are considered.
6269 REGISTRY, if a string, specifies a font registry and encoding to
6270 match. A value of nil means include fonts of any registry and
6273 Return in *FONTS a pointer to a vector of font_name structures for
6274 the fonts matched. Value is the number of fonts found. */
6277 try_alternative_families (f
, family
, registry
, fonts
)
6279 Lisp_Object family
, registry
;
6280 struct font_name
**fonts
;
6285 nfonts
= font_list (f
, Qnil
, family
, registry
, fonts
);
6288 /* Try alternative font families. */
6289 alter
= Fassoc (family
, Vface_alternative_font_family_alist
);
6292 for (alter
= XCDR (alter
);
6293 CONSP (alter
) && nfonts
== 0;
6294 alter
= XCDR (alter
))
6296 if (STRINGP (XCAR (alter
)))
6297 nfonts
= font_list (f
, Qnil
, XCAR (alter
), registry
, fonts
);
6301 /* Try scalable fonts before giving up. */
6302 if (nfonts
== 0 && NILP (Vscalable_fonts_allowed
))
6304 int count
= BINDING_STACK_SIZE ();
6305 specbind (Qscalable_fonts_allowed
, Qt
);
6306 nfonts
= try_alternative_families (f
, family
, registry
, fonts
);
6307 unbind_to (count
, Qnil
);
6314 /* Get a list of matching fonts on frame F.
6316 FAMILY, if a string, specifies a font family derived from the fontset.
6317 It is only used if the face does not specify any family in ATTRS or
6318 if we cannot find any font of the face's family.
6320 REGISTRY, if a string, specifies a font registry and encoding to
6321 match. A value of nil means include fonts of any registry and
6324 Return in *FONTS a pointer to a vector of font_name structures for
6325 the fonts matched. Value is the number of fonts found. */
6328 try_font_list (f
, attrs
, family
, registry
, fonts
)
6331 Lisp_Object family
, registry
;
6332 struct font_name
**fonts
;
6335 Lisp_Object face_family
= attrs
[LFACE_FAMILY_INDEX
];
6337 if (STRINGP (face_family
))
6338 nfonts
= try_alternative_families (f
, face_family
, registry
, fonts
);
6340 if (nfonts
== 0 && !NILP (family
))
6341 nfonts
= try_alternative_families (f
, family
, registry
, fonts
);
6343 /* Try font family of the default face or "fixed". */
6346 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6348 family
= default_face
->lface
[LFACE_FAMILY_INDEX
];
6350 family
= build_string ("fixed");
6351 nfonts
= font_list (f
, Qnil
, family
, registry
, fonts
);
6354 /* Try any family with the given registry. */
6356 nfonts
= font_list (f
, Qnil
, Qnil
, registry
, fonts
);
6362 /* Return the fontset id of the base fontset name or alias name given
6363 by the fontset attribute of ATTRS. Value is -1 if the fontset
6364 attribute of ATTRS doesn't name a fontset. */
6367 face_fontset (attrs
)
6372 name
= attrs
[LFACE_FONT_INDEX
];
6373 if (!STRINGP (name
))
6375 return fs_query_fontset (name
, 0);
6379 /* Choose a name of font to use on frame F to display character C with
6380 Lisp face attributes specified by ATTRS. The font name is
6381 determined by the font-related attributes in ATTRS and the name
6382 pattern for C in FONTSET. Value is the font name which is
6383 allocated from the heap and must be freed by the caller, or NULL if
6384 we can get no information about the font name of C. It is assured
6385 that we always get some information for a single byte
6389 choose_face_font (f
, attrs
, fontset
, c
)
6394 Lisp_Object pattern
;
6395 char *font_name
= NULL
;
6396 struct font_name
*fonts
;
6397 int nfonts
, width_ratio
;
6399 /* Get (foundry and) family name and registry (and encoding) name of
6401 pattern
= fontset_font_pattern (f
, fontset
, c
);
6404 xassert (!SINGLE_BYTE_CHAR_P (c
));
6408 /* If what we got is a name pattern, return it. */
6409 if (STRINGP (pattern
))
6410 return xstrdup (XSTRING (pattern
)->data
);
6412 /* Get a list of fonts matching that pattern and choose the
6413 best match for the specified face attributes from it. */
6414 nfonts
= try_font_list (f
, attrs
, XCAR (pattern
), XCDR (pattern
), &fonts
);
6415 width_ratio
= (SINGLE_BYTE_CHAR_P (c
)
6417 : CHARSET_WIDTH (CHAR_CHARSET (c
)));
6418 font_name
= best_matching_font (f
, attrs
, fonts
, nfonts
, width_ratio
);
6422 #endif /* HAVE_WINDOW_SYSTEM */
6426 /***********************************************************************
6428 ***********************************************************************/
6430 /* Realize basic faces on frame F. Value is zero if frame parameters
6431 of F don't contain enough information needed to realize the default
6435 realize_basic_faces (f
)
6439 int count
= BINDING_STACK_SIZE ();
6441 /* Block input here so that we won't be surprised by an X expose
6442 event, for instance, without having the faces set up. */
6444 specbind (Qscalable_fonts_allowed
, Qt
);
6446 if (realize_default_face (f
))
6448 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
6449 realize_named_face (f
, Qmode_line_inactive
, MODE_LINE_INACTIVE_FACE_ID
);
6450 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
6451 realize_named_face (f
, Qfringe
, FRINGE_FACE_ID
);
6452 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
6453 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
6454 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
6455 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
6456 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
6457 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
6459 /* Reflect changes in the `menu' face in menu bars. */
6460 if (FRAME_FACE_CACHE (f
)->menu_face_changed_p
)
6462 FRAME_FACE_CACHE (f
)->menu_face_changed_p
= 0;
6463 #ifdef USE_X_TOOLKIT
6464 x_update_menu_appearance (f
);
6471 unbind_to (count
, Qnil
);
6477 /* Realize the default face on frame F. If the face is not fully
6478 specified, make it fully-specified. Attributes of the default face
6479 that are not explicitly specified are taken from frame parameters. */
6482 realize_default_face (f
)
6485 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
6487 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6488 Lisp_Object frame_font
;
6491 /* If the `default' face is not yet known, create it. */
6492 lface
= lface_from_face_name (f
, Qdefault
, 0);
6496 XSETFRAME (frame
, f
);
6497 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
6500 #ifdef HAVE_WINDOW_SYSTEM
6501 if (FRAME_WINDOW_P (f
))
6503 /* Set frame_font to the value of the `font' frame parameter. */
6504 frame_font
= Fassq (Qfont
, f
->param_alist
);
6505 xassert (CONSP (frame_font
) && STRINGP (XCDR (frame_font
)));
6506 frame_font
= XCDR (frame_font
);
6507 set_lface_from_font_name (f
, lface
, frame_font
, 1, 1);
6509 #endif /* HAVE_WINDOW_SYSTEM */
6511 if (!FRAME_WINDOW_P (f
))
6513 LFACE_FAMILY (lface
) = build_string ("default");
6514 LFACE_SWIDTH (lface
) = Qnormal
;
6515 LFACE_HEIGHT (lface
) = make_number (1);
6516 if (UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
6517 LFACE_WEIGHT (lface
) = Qnormal
;
6518 if (UNSPECIFIEDP (LFACE_SLANT (lface
)))
6519 LFACE_SLANT (lface
) = Qnormal
;
6520 LFACE_AVGWIDTH (lface
) = Qunspecified
;
6523 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
6524 LFACE_UNDERLINE (lface
) = Qnil
;
6526 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
6527 LFACE_OVERLINE (lface
) = Qnil
;
6529 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
6530 LFACE_STRIKE_THROUGH (lface
) = Qnil
;
6532 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
6533 LFACE_BOX (lface
) = Qnil
;
6535 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
6536 LFACE_INVERSE (lface
) = Qnil
;
6538 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
6540 /* This function is called so early that colors are not yet
6541 set in the frame parameter list. */
6542 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
6544 if (CONSP (color
) && STRINGP (XCDR (color
)))
6545 LFACE_FOREGROUND (lface
) = XCDR (color
);
6546 else if (FRAME_WINDOW_P (f
))
6548 else if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
6549 LFACE_FOREGROUND (lface
) = build_string (unspecified_fg
);
6554 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
6556 /* This function is called so early that colors are not yet
6557 set in the frame parameter list. */
6558 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
6559 if (CONSP (color
) && STRINGP (XCDR (color
)))
6560 LFACE_BACKGROUND (lface
) = XCDR (color
);
6561 else if (FRAME_WINDOW_P (f
))
6563 else if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
6564 LFACE_BACKGROUND (lface
) = build_string (unspecified_bg
);
6569 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
6570 LFACE_STIPPLE (lface
) = Qnil
;
6572 /* Realize the face; it must be fully-specified now. */
6573 xassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
6574 check_lface (lface
);
6575 bcopy (XVECTOR (lface
)->contents
, attrs
, sizeof attrs
);
6576 face
= realize_face (c
, attrs
, 0, NULL
, DEFAULT_FACE_ID
);
6581 /* Realize basic faces other than the default face in face cache C.
6582 SYMBOL is the face name, ID is the face id the realized face must
6583 have. The default face must have been realized already. */
6586 realize_named_face (f
, symbol
, id
)
6591 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
6592 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
6593 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6594 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
6595 struct face
*new_face
;
6597 /* The default face must exist and be fully specified. */
6598 get_lface_attributes (f
, Qdefault
, attrs
, 1);
6599 check_lface_attrs (attrs
);
6600 xassert (lface_fully_specified_p (attrs
));
6602 /* If SYMBOL isn't know as a face, create it. */
6606 XSETFRAME (frame
, f
);
6607 lface
= Finternal_make_lisp_face (symbol
, frame
);
6610 /* Merge SYMBOL's face with the default face. */
6611 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
6612 merge_face_vectors (f
, symbol_attrs
, attrs
, Qnil
);
6614 /* Realize the face. */
6615 new_face
= realize_face (c
, attrs
, 0, NULL
, id
);
6619 /* Realize the fully-specified face with attributes ATTRS in face
6620 cache CACHE for character C. If C is a multibyte character,
6621 BASE_FACE is a face that has the same attributes. Otherwise,
6622 BASE_FACE is ignored. If FORMER_FACE_ID is non-negative, it is an
6623 ID of face to remove before caching the new face. Value is a
6624 pointer to the newly created realized face. */
6626 static struct face
*
6627 realize_face (cache
, attrs
, c
, base_face
, former_face_id
)
6628 struct face_cache
*cache
;
6631 struct face
*base_face
;
6636 /* LFACE must be fully specified. */
6637 xassert (cache
!= NULL
);
6638 check_lface_attrs (attrs
);
6640 if (former_face_id
>= 0 && cache
->used
> former_face_id
)
6642 /* Remove the former face. */
6643 struct face
*former_face
= cache
->faces_by_id
[former_face_id
];
6644 uncache_face (cache
, former_face
);
6645 free_realized_face (cache
->f
, former_face
);
6648 if (FRAME_WINDOW_P (cache
->f
))
6649 face
= realize_x_face (cache
, attrs
, c
, base_face
);
6650 else if (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
))
6651 face
= realize_tty_face (cache
, attrs
, c
);
6655 /* Insert the new face. */
6656 cache_face (cache
, face
, lface_hash (attrs
));
6657 #ifdef HAVE_WINDOW_SYSTEM
6658 if (FRAME_WINDOW_P (cache
->f
) && face
->font
== NULL
)
6659 load_face_font (cache
->f
, face
, c
);
6660 #endif /* HAVE_WINDOW_SYSTEM */
6665 /* Realize the fully-specified face with attributes ATTRS in face
6666 cache CACHE for character C. Do it for X frame CACHE->f. If C is
6667 a multibyte character, BASE_FACE is a face that has the same
6668 attributes. Otherwise, BASE_FACE is ignored. If the new face
6669 doesn't share font with the default face, a fontname is allocated
6670 from the heap and set in `font_name' of the new face, but it is not
6671 yet loaded here. Value is a pointer to the newly created realized
6674 static struct face
*
6675 realize_x_face (cache
, attrs
, c
, base_face
)
6676 struct face_cache
*cache
;
6679 struct face
*base_face
;
6681 #ifdef HAVE_WINDOW_SYSTEM
6682 struct face
*face
, *default_face
;
6684 Lisp_Object stipple
, overline
, strike_through
, box
;
6686 xassert (FRAME_WINDOW_P (cache
->f
));
6687 xassert (SINGLE_BYTE_CHAR_P (c
)
6690 /* Allocate a new realized face. */
6691 face
= make_realized_face (attrs
);
6695 /* If C is a multibyte character, we share all face attirbutes with
6696 BASE_FACE including the realized fontset. But, we must load a
6698 if (!SINGLE_BYTE_CHAR_P (c
))
6700 bcopy (base_face
, face
, sizeof *face
);
6703 /* Don't try to free the colors copied bitwise from BASE_FACE. */
6704 face
->colors_copied_bitwise_p
= 1;
6706 /* to force realize_face to load font */
6711 /* Now we are realizing a face for ASCII (and unibyte) characters. */
6713 /* Determine the font to use. Most of the time, the font will be
6714 the same as the font of the default face, so try that first. */
6715 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6717 && FACE_SUITABLE_FOR_CHAR_P (default_face
, c
)
6718 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
6720 face
->font
= default_face
->font
;
6721 face
->fontset
= default_face
->fontset
;
6722 face
->font_info_id
= default_face
->font_info_id
;
6723 face
->font_name
= default_face
->font_name
;
6724 face
->ascii_face
= face
;
6726 /* But, as we can't share the fontset, make a new realized
6727 fontset that has the same base fontset as of the default
6730 = make_fontset_for_ascii_face (f
, default_face
->fontset
);
6734 /* If the face attribute ATTRS specifies a fontset, use it as
6735 the base of a new realized fontset. Otherwise, use the same
6736 base fontset as of the default face. The base determines
6737 registry and encoding of a font. It may also determine
6738 foundry and family. The other fields of font name pattern
6739 are constructed from ATTRS. */
6740 int fontset
= face_fontset (attrs
);
6742 if ((fontset
== -1) && default_face
)
6743 fontset
= default_face
->fontset
;
6744 face
->fontset
= make_fontset_for_ascii_face (f
, fontset
);
6745 face
->font
= NULL
; /* to force realize_face to load font */
6748 /* Load the font if it is specified in ATTRS. This fixes
6749 changing frame font on the Mac. */
6750 if (STRINGP (attrs
[LFACE_FONT_INDEX
]))
6752 struct font_info
*font_info
=
6753 FS_LOAD_FONT (f
, 0, XSTRING (attrs
[LFACE_FONT_INDEX
])->data
, -1);
6755 face
->font
= font_info
->font
;
6760 /* Load colors, and set remaining attributes. */
6762 load_face_colors (f
, face
, attrs
);
6765 box
= attrs
[LFACE_BOX_INDEX
];
6768 /* A simple box of line width 1 drawn in color given by
6770 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
6772 face
->box
= FACE_SIMPLE_BOX
;
6773 face
->box_line_width
= 1;
6775 else if (INTEGERP (box
))
6777 /* Simple box of specified line width in foreground color of the
6779 xassert (XINT (box
) != 0);
6780 face
->box
= FACE_SIMPLE_BOX
;
6781 face
->box_line_width
= XINT (box
);
6782 face
->box_color
= face
->foreground
;
6783 face
->box_color_defaulted_p
= 1;
6785 else if (CONSP (box
))
6787 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
6788 being one of `raised' or `sunken'. */
6789 face
->box
= FACE_SIMPLE_BOX
;
6790 face
->box_color
= face
->foreground
;
6791 face
->box_color_defaulted_p
= 1;
6792 face
->box_line_width
= 1;
6796 Lisp_Object keyword
, value
;
6798 keyword
= XCAR (box
);
6806 if (EQ (keyword
, QCline_width
))
6808 if (INTEGERP (value
) && XINT (value
) != 0)
6809 face
->box_line_width
= XINT (value
);
6811 else if (EQ (keyword
, QCcolor
))
6813 if (STRINGP (value
))
6815 face
->box_color
= load_color (f
, face
, value
,
6817 face
->use_box_color_for_shadows_p
= 1;
6820 else if (EQ (keyword
, QCstyle
))
6822 if (EQ (value
, Qreleased_button
))
6823 face
->box
= FACE_RAISED_BOX
;
6824 else if (EQ (value
, Qpressed_button
))
6825 face
->box
= FACE_SUNKEN_BOX
;
6830 /* Text underline, overline, strike-through. */
6832 if (EQ (attrs
[LFACE_UNDERLINE_INDEX
], Qt
))
6834 /* Use default color (same as foreground color). */
6835 face
->underline_p
= 1;
6836 face
->underline_defaulted_p
= 1;
6837 face
->underline_color
= 0;
6839 else if (STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]))
6841 /* Use specified color. */
6842 face
->underline_p
= 1;
6843 face
->underline_defaulted_p
= 0;
6844 face
->underline_color
6845 = load_color (f
, face
, attrs
[LFACE_UNDERLINE_INDEX
],
6846 LFACE_UNDERLINE_INDEX
);
6848 else if (NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
6850 face
->underline_p
= 0;
6851 face
->underline_defaulted_p
= 0;
6852 face
->underline_color
= 0;
6855 overline
= attrs
[LFACE_OVERLINE_INDEX
];
6856 if (STRINGP (overline
))
6858 face
->overline_color
6859 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
6860 LFACE_OVERLINE_INDEX
);
6861 face
->overline_p
= 1;
6863 else if (EQ (overline
, Qt
))
6865 face
->overline_color
= face
->foreground
;
6866 face
->overline_color_defaulted_p
= 1;
6867 face
->overline_p
= 1;
6870 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
6871 if (STRINGP (strike_through
))
6873 face
->strike_through_color
6874 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
6875 LFACE_STRIKE_THROUGH_INDEX
);
6876 face
->strike_through_p
= 1;
6878 else if (EQ (strike_through
, Qt
))
6880 face
->strike_through_color
= face
->foreground
;
6881 face
->strike_through_color_defaulted_p
= 1;
6882 face
->strike_through_p
= 1;
6885 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
6886 if (!NILP (stipple
))
6887 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
6889 xassert (FACE_SUITABLE_FOR_CHAR_P (face
, c
));
6891 #endif /* HAVE_WINDOW_SYSTEM */
6895 /* Map a specified color of face FACE on frame F to a tty color index.
6896 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and
6897 specifies which color to map. Set *DEFAULTED to 1 if mapping to the
6898 default foreground/background colors. */
6901 map_tty_color (f
, face
, idx
, defaulted
)
6904 enum lface_attribute_index idx
;
6907 Lisp_Object frame
, color
, def
;
6908 int foreground_p
= idx
== LFACE_FOREGROUND_INDEX
;
6909 unsigned long default_pixel
, default_other_pixel
, pixel
;
6911 xassert (idx
== LFACE_FOREGROUND_INDEX
|| idx
== LFACE_BACKGROUND_INDEX
);
6915 pixel
= default_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
6916 default_other_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
6920 pixel
= default_pixel
= FACE_TTY_DEFAULT_BG_COLOR
;
6921 default_other_pixel
= FACE_TTY_DEFAULT_FG_COLOR
;
6924 XSETFRAME (frame
, f
);
6925 color
= face
->lface
[idx
];
6928 && XSTRING (color
)->size
6929 && CONSP (Vtty_defined_color_alist
)
6930 && (def
= assq_no_quit (color
, call1 (Qtty_color_alist
, frame
)),
6933 /* Associations in tty-defined-color-alist are of the form
6934 (NAME INDEX R G B). We need the INDEX part. */
6935 pixel
= XINT (XCAR (XCDR (def
)));
6938 if (pixel
== default_pixel
&& STRINGP (color
))
6940 pixel
= load_color (f
, face
, color
, idx
);
6942 #if defined (MSDOS) || defined (WINDOWSNT)
6943 /* If the foreground of the default face is the default color,
6944 use the foreground color defined by the frame. */
6946 if (FRAME_MSDOS_P (f
))
6949 if (pixel
== default_pixel
6950 || pixel
== FACE_TTY_DEFAULT_COLOR
)
6953 pixel
= FRAME_FOREGROUND_PIXEL (f
);
6955 pixel
= FRAME_BACKGROUND_PIXEL (f
);
6956 face
->lface
[idx
] = tty_color_name (f
, pixel
);
6959 else if (pixel
== default_other_pixel
)
6962 pixel
= FRAME_BACKGROUND_PIXEL (f
);
6964 pixel
= FRAME_FOREGROUND_PIXEL (f
);
6965 face
->lface
[idx
] = tty_color_name (f
, pixel
);
6971 #endif /* MSDOS or WINDOWSNT */
6975 face
->foreground
= pixel
;
6977 face
->background
= pixel
;
6981 /* Realize the fully-specified face with attributes ATTRS in face
6982 cache CACHE for character C. Do it for TTY frame CACHE->f. Value is a
6983 pointer to the newly created realized face. */
6985 static struct face
*
6986 realize_tty_face (cache
, attrs
, c
)
6987 struct face_cache
*cache
;
6993 int face_colors_defaulted
= 0;
6994 struct frame
*f
= cache
->f
;
6996 /* Frame must be a termcap frame. */
6997 xassert (FRAME_TERMCAP_P (cache
->f
) || FRAME_MSDOS_P (cache
->f
));
6999 /* Allocate a new realized face. */
7000 face
= make_realized_face (attrs
);
7001 face
->font_name
= FRAME_MSDOS_P (cache
->f
) ? "ms-dos" : "tty";
7003 /* Map face attributes to TTY appearances. We map slant to
7004 dimmed text because we want italic text to appear differently
7005 and because dimmed text is probably used infrequently. */
7006 weight
= face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
7007 slant
= face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
7009 if (weight
> XLFD_WEIGHT_MEDIUM
)
7010 face
->tty_bold_p
= 1;
7011 if (weight
< XLFD_WEIGHT_MEDIUM
|| slant
!= XLFD_SLANT_ROMAN
)
7012 face
->tty_dim_p
= 1;
7013 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
7014 face
->tty_underline_p
= 1;
7015 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
7016 face
->tty_reverse_p
= 1;
7018 /* Map color names to color indices. */
7019 map_tty_color (f
, face
, LFACE_FOREGROUND_INDEX
, &face_colors_defaulted
);
7020 map_tty_color (f
, face
, LFACE_BACKGROUND_INDEX
, &face_colors_defaulted
);
7022 /* Swap colors if face is inverse-video. If the colors are taken
7023 from the frame colors, they are already inverted, since the
7024 frame-creation function calls x-handle-reverse-video. */
7025 if (face
->tty_reverse_p
&& !face_colors_defaulted
)
7027 unsigned long tem
= face
->foreground
;
7028 face
->foreground
= face
->background
;
7029 face
->background
= tem
;
7032 if (tty_suppress_bold_inverse_default_colors_p
7034 && face
->background
== FACE_TTY_DEFAULT_FG_COLOR
7035 && face
->foreground
== FACE_TTY_DEFAULT_BG_COLOR
)
7036 face
->tty_bold_p
= 0;
7042 DEFUN ("tty-suppress-bold-inverse-default-colors",
7043 Ftty_suppress_bold_inverse_default_colors
,
7044 Stty_suppress_bold_inverse_default_colors
, 1, 1, 0,
7045 doc
: /* Suppress/allow boldness of faces with inverse default colors.
7046 SUPPRESS non-nil means suppress it.
7047 This affects bold faces on TTYs whose foreground is the default background
7048 color of the display and whose background is the default foreground color.
7049 For such faces, the bold face attribute is ignored if this variable
7052 Lisp_Object suppress
;
7054 tty_suppress_bold_inverse_default_colors_p
= !NILP (suppress
);
7055 ++face_change_count
;
7061 /***********************************************************************
7063 ***********************************************************************/
7065 /* Return the ID of the face to use to display character CH with face
7066 property PROP on frame F in current_buffer. */
7069 compute_char_face (f
, ch
, prop
)
7076 if (NILP (current_buffer
->enable_multibyte_characters
))
7081 struct face
*face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7082 face_id
= FACE_FOR_CHAR (f
, face
, ch
);
7086 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
7087 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7088 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
7089 merge_face_vector_with_property (f
, attrs
, prop
);
7090 face_id
= lookup_face (f
, attrs
, ch
, NULL
);
7096 /* Return the face ID associated with buffer position POS for
7097 displaying ASCII characters. Return in *ENDPTR the position at
7098 which a different face is needed, as far as text properties and
7099 overlays are concerned. W is a window displaying current_buffer.
7101 REGION_BEG, REGION_END delimit the region, so it can be
7104 LIMIT is a position not to scan beyond. That is to limit the time
7105 this function can take.
7107 If MOUSE is non-zero, use the character's mouse-face, not its face.
7109 The face returned is suitable for displaying ASCII characters. */
7112 face_at_buffer_position (w
, pos
, region_beg
, region_end
,
7113 endptr
, limit
, mouse
)
7116 int region_beg
, region_end
;
7121 struct frame
*f
= XFRAME (w
->frame
);
7122 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
7123 Lisp_Object prop
, position
;
7125 Lisp_Object
*overlay_vec
;
7128 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
7129 Lisp_Object limit1
, end
;
7130 struct face
*default_face
;
7132 /* W must display the current buffer. We could write this function
7133 to use the frame and buffer of W, but right now it doesn't. */
7134 /* xassert (XBUFFER (w->buffer) == current_buffer); */
7136 XSETFRAME (frame
, f
);
7137 XSETFASTINT (position
, pos
);
7140 if (pos
< region_beg
&& region_beg
< endpos
)
7141 endpos
= region_beg
;
7143 /* Get the `face' or `mouse_face' text property at POS, and
7144 determine the next position at which the property changes. */
7145 prop
= Fget_text_property (position
, propname
, w
->buffer
);
7146 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
7147 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
7149 endpos
= XINT (end
);
7151 /* Look at properties from overlays. */
7156 /* First try with room for 40 overlays. */
7158 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7159 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
7160 &next_overlay
, NULL
, 0);
7162 /* If there are more than 40, make enough space for all, and try
7164 if (noverlays
> len
)
7167 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7168 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
7169 &next_overlay
, NULL
, 0);
7172 if (next_overlay
< endpos
)
7173 endpos
= next_overlay
;
7178 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
7180 /* Optimize common cases where we can use the default face. */
7183 && !(pos
>= region_beg
&& pos
< region_end
))
7184 return DEFAULT_FACE_ID
;
7186 /* Begin with attributes from the default face. */
7187 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
7189 /* Merge in attributes specified via text properties. */
7191 merge_face_vector_with_property (f
, attrs
, prop
);
7193 /* Now merge the overlay data. */
7194 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
7195 for (i
= 0; i
< noverlays
; i
++)
7200 prop
= Foverlay_get (overlay_vec
[i
], propname
);
7202 merge_face_vector_with_property (f
, attrs
, prop
);
7204 oend
= OVERLAY_END (overlay_vec
[i
]);
7205 oendpos
= OVERLAY_POSITION (oend
);
7206 if (oendpos
< endpos
)
7210 /* If in the region, merge in the region face. */
7211 if (pos
>= region_beg
&& pos
< region_end
)
7213 Lisp_Object region_face
= lface_from_face_name (f
, Qregion
, 0);
7214 merge_face_vectors (f
, XVECTOR (region_face
)->contents
, attrs
, Qnil
);
7216 if (region_end
< endpos
)
7217 endpos
= region_end
;
7222 /* Look up a realized face with the given face attributes,
7223 or realize a new one for ASCII characters. */
7224 return lookup_face (f
, attrs
, 0, NULL
);
7228 /* Compute the face at character position POS in Lisp string STRING on
7229 window W, for ASCII characters.
7231 If STRING is an overlay string, it comes from position BUFPOS in
7232 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
7233 not an overlay string. W must display the current buffer.
7234 REGION_BEG and REGION_END give the start and end positions of the
7235 region; both are -1 if no region is visible.
7237 BASE_FACE_ID is the id of a face to merge with. For strings coming
7238 from overlays or the `display' property it is the face at BUFPOS.
7240 If MOUSE_P is non-zero, use the character's mouse-face, not its face.
7242 Set *ENDPTR to the next position where to check for faces in
7243 STRING; -1 if the face is constant from POS to the end of the
7246 Value is the id of the face to use. The face returned is suitable
7247 for displaying ASCII characters. */
7250 face_at_string_position (w
, string
, pos
, bufpos
, region_beg
,
7251 region_end
, endptr
, base_face_id
, mouse_p
)
7255 int region_beg
, region_end
;
7257 enum face_id base_face_id
;
7260 Lisp_Object prop
, position
, end
, limit
;
7261 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7262 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
7263 struct face
*base_face
;
7264 int multibyte_p
= STRING_MULTIBYTE (string
);
7265 Lisp_Object prop_name
= mouse_p
? Qmouse_face
: Qface
;
7267 /* Get the value of the face property at the current position within
7268 STRING. Value is nil if there is no face property. */
7269 XSETFASTINT (position
, pos
);
7270 prop
= Fget_text_property (position
, prop_name
, string
);
7272 /* Get the next position at which to check for faces. Value of end
7273 is nil if face is constant all the way to the end of the string.
7274 Otherwise it is a string position where to check faces next.
7275 Limit is the maximum position up to which to check for property
7276 changes in Fnext_single_property_change. Strings are usually
7277 short, so set the limit to the end of the string. */
7278 XSETFASTINT (limit
, XSTRING (string
)->size
);
7279 end
= Fnext_single_property_change (position
, prop_name
, string
, limit
);
7281 *endptr
= XFASTINT (end
);
7285 base_face
= FACE_FROM_ID (f
, base_face_id
);
7286 xassert (base_face
);
7288 /* Optimize the default case that there is no face property and we
7289 are not in the region. */
7291 && (base_face_id
!= DEFAULT_FACE_ID
7292 /* BUFPOS <= 0 means STRING is not an overlay string, so
7293 that the region doesn't have to be taken into account. */
7295 || bufpos
< region_beg
7296 || bufpos
>= region_end
)
7298 /* We can't realize faces for different charsets differently
7299 if we don't have fonts, so we can stop here if not working
7300 on a window-system frame. */
7301 || !FRAME_WINDOW_P (f
)
7302 || FACE_SUITABLE_FOR_CHAR_P (base_face
, 0)))
7303 return base_face
->id
;
7305 /* Begin with attributes from the base face. */
7306 bcopy (base_face
->lface
, attrs
, sizeof attrs
);
7308 /* Merge in attributes specified via text properties. */
7310 merge_face_vector_with_property (f
, attrs
, prop
);
7312 /* If in the region, merge in the region face. */
7314 && bufpos
>= region_beg
7315 && bufpos
< region_end
)
7317 Lisp_Object region_face
= lface_from_face_name (f
, Qregion
, 0);
7318 merge_face_vectors (f
, XVECTOR (region_face
)->contents
, attrs
, Qnil
);
7321 /* Look up a realized face with the given face attributes,
7322 or realize a new one for ASCII characters. */
7323 return lookup_face (f
, attrs
, 0, NULL
);
7328 /***********************************************************************
7330 ***********************************************************************/
7334 /* Print the contents of the realized face FACE to stderr. */
7337 dump_realized_face (face
)
7340 fprintf (stderr
, "ID: %d\n", face
->id
);
7341 #ifdef HAVE_X_WINDOWS
7342 fprintf (stderr
, "gc: %d\n", (int) face
->gc
);
7344 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
7346 XSTRING (face
->lface
[LFACE_FOREGROUND_INDEX
])->data
);
7347 fprintf (stderr
, "background: 0x%lx (%s)\n",
7349 XSTRING (face
->lface
[LFACE_BACKGROUND_INDEX
])->data
);
7350 fprintf (stderr
, "font_name: %s (%s)\n",
7352 XSTRING (face
->lface
[LFACE_FAMILY_INDEX
])->data
);
7353 #ifdef HAVE_X_WINDOWS
7354 fprintf (stderr
, "font = %p\n", face
->font
);
7356 fprintf (stderr
, "font_info_id = %d\n", face
->font_info_id
);
7357 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
7358 fprintf (stderr
, "underline: %d (%s)\n",
7360 XSTRING (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
]))->data
);
7361 fprintf (stderr
, "hash: %d\n", face
->hash
);
7362 fprintf (stderr
, "charset: %d\n", face
->charset
);
7366 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, doc
: /* */)
7374 fprintf (stderr
, "font selection order: ");
7375 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
7376 fprintf (stderr
, "%d ", font_sort_order
[i
]);
7377 fprintf (stderr
, "\n");
7379 fprintf (stderr
, "alternative fonts: ");
7380 debug_print (Vface_alternative_font_family_alist
);
7381 fprintf (stderr
, "\n");
7383 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
7384 Fdump_face (make_number (i
));
7390 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
7392 error ("Not a valid face");
7393 dump_realized_face (face
);
7400 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
7401 0, 0, 0, doc
: /* */)
7404 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
7405 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
7406 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
7410 #endif /* GLYPH_DEBUG != 0 */
7414 /***********************************************************************
7416 ***********************************************************************/
7421 Qface
= intern ("face");
7423 Qbitmap_spec_p
= intern ("bitmap-spec-p");
7424 staticpro (&Qbitmap_spec_p
);
7425 Qframe_update_face_colors
= intern ("frame-update-face-colors");
7426 staticpro (&Qframe_update_face_colors
);
7428 /* Lisp face attribute keywords. */
7429 QCfamily
= intern (":family");
7430 staticpro (&QCfamily
);
7431 QCheight
= intern (":height");
7432 staticpro (&QCheight
);
7433 QCweight
= intern (":weight");
7434 staticpro (&QCweight
);
7435 QCslant
= intern (":slant");
7436 staticpro (&QCslant
);
7437 QCunderline
= intern (":underline");
7438 staticpro (&QCunderline
);
7439 QCinverse_video
= intern (":inverse-video");
7440 staticpro (&QCinverse_video
);
7441 QCreverse_video
= intern (":reverse-video");
7442 staticpro (&QCreverse_video
);
7443 QCforeground
= intern (":foreground");
7444 staticpro (&QCforeground
);
7445 QCbackground
= intern (":background");
7446 staticpro (&QCbackground
);
7447 QCstipple
= intern (":stipple");;
7448 staticpro (&QCstipple
);
7449 QCwidth
= intern (":width");
7450 staticpro (&QCwidth
);
7451 QCfont
= intern (":font");
7452 staticpro (&QCfont
);
7453 QCbold
= intern (":bold");
7454 staticpro (&QCbold
);
7455 QCitalic
= intern (":italic");
7456 staticpro (&QCitalic
);
7457 QCoverline
= intern (":overline");
7458 staticpro (&QCoverline
);
7459 QCstrike_through
= intern (":strike-through");
7460 staticpro (&QCstrike_through
);
7461 QCbox
= intern (":box");
7463 QCinherit
= intern (":inherit");
7464 staticpro (&QCinherit
);
7466 /* Symbols used for Lisp face attribute values. */
7467 QCcolor
= intern (":color");
7468 staticpro (&QCcolor
);
7469 QCline_width
= intern (":line-width");
7470 staticpro (&QCline_width
);
7471 QCstyle
= intern (":style");
7472 staticpro (&QCstyle
);
7473 Qreleased_button
= intern ("released-button");
7474 staticpro (&Qreleased_button
);
7475 Qpressed_button
= intern ("pressed-button");
7476 staticpro (&Qpressed_button
);
7477 Qnormal
= intern ("normal");
7478 staticpro (&Qnormal
);
7479 Qultra_light
= intern ("ultra-light");
7480 staticpro (&Qultra_light
);
7481 Qextra_light
= intern ("extra-light");
7482 staticpro (&Qextra_light
);
7483 Qlight
= intern ("light");
7484 staticpro (&Qlight
);
7485 Qsemi_light
= intern ("semi-light");
7486 staticpro (&Qsemi_light
);
7487 Qsemi_bold
= intern ("semi-bold");
7488 staticpro (&Qsemi_bold
);
7489 Qbold
= intern ("bold");
7491 Qextra_bold
= intern ("extra-bold");
7492 staticpro (&Qextra_bold
);
7493 Qultra_bold
= intern ("ultra-bold");
7494 staticpro (&Qultra_bold
);
7495 Qoblique
= intern ("oblique");
7496 staticpro (&Qoblique
);
7497 Qitalic
= intern ("italic");
7498 staticpro (&Qitalic
);
7499 Qreverse_oblique
= intern ("reverse-oblique");
7500 staticpro (&Qreverse_oblique
);
7501 Qreverse_italic
= intern ("reverse-italic");
7502 staticpro (&Qreverse_italic
);
7503 Qultra_condensed
= intern ("ultra-condensed");
7504 staticpro (&Qultra_condensed
);
7505 Qextra_condensed
= intern ("extra-condensed");
7506 staticpro (&Qextra_condensed
);
7507 Qcondensed
= intern ("condensed");
7508 staticpro (&Qcondensed
);
7509 Qsemi_condensed
= intern ("semi-condensed");
7510 staticpro (&Qsemi_condensed
);
7511 Qsemi_expanded
= intern ("semi-expanded");
7512 staticpro (&Qsemi_expanded
);
7513 Qexpanded
= intern ("expanded");
7514 staticpro (&Qexpanded
);
7515 Qextra_expanded
= intern ("extra-expanded");
7516 staticpro (&Qextra_expanded
);
7517 Qultra_expanded
= intern ("ultra-expanded");
7518 staticpro (&Qultra_expanded
);
7519 Qbackground_color
= intern ("background-color");
7520 staticpro (&Qbackground_color
);
7521 Qforeground_color
= intern ("foreground-color");
7522 staticpro (&Qforeground_color
);
7523 Qunspecified
= intern ("unspecified");
7524 staticpro (&Qunspecified
);
7526 Qface_alias
= intern ("face-alias");
7527 staticpro (&Qface_alias
);
7528 Qdefault
= intern ("default");
7529 staticpro (&Qdefault
);
7530 Qtool_bar
= intern ("tool-bar");
7531 staticpro (&Qtool_bar
);
7532 Qregion
= intern ("region");
7533 staticpro (&Qregion
);
7534 Qfringe
= intern ("fringe");
7535 staticpro (&Qfringe
);
7536 Qheader_line
= intern ("header-line");
7537 staticpro (&Qheader_line
);
7538 Qscroll_bar
= intern ("scroll-bar");
7539 staticpro (&Qscroll_bar
);
7540 Qmenu
= intern ("menu");
7542 Qcursor
= intern ("cursor");
7543 staticpro (&Qcursor
);
7544 Qborder
= intern ("border");
7545 staticpro (&Qborder
);
7546 Qmouse
= intern ("mouse");
7547 staticpro (&Qmouse
);
7548 Qmode_line_inactive
= intern ("mode-line-inactive");
7549 staticpro (&Qmode_line_inactive
);
7550 Qtty_color_desc
= intern ("tty-color-desc");
7551 staticpro (&Qtty_color_desc
);
7552 Qtty_color_standard_values
= intern ("tty-color-standard-values");
7553 staticpro (&Qtty_color_standard_values
);
7554 Qtty_color_by_index
= intern ("tty-color-by-index");
7555 staticpro (&Qtty_color_by_index
);
7556 Qtty_color_alist
= intern ("tty-color-alist");
7557 staticpro (&Qtty_color_alist
);
7558 Qscalable_fonts_allowed
= intern ("scalable-fonts-allowed");
7559 staticpro (&Qscalable_fonts_allowed
);
7561 Vparam_value_alist
= Fcons (Fcons (Qnil
, Qnil
), Qnil
);
7562 staticpro (&Vparam_value_alist
);
7563 Vface_alternative_font_family_alist
= Qnil
;
7564 staticpro (&Vface_alternative_font_family_alist
);
7565 Vface_alternative_font_registry_alist
= Qnil
;
7566 staticpro (&Vface_alternative_font_registry_alist
);
7568 defsubr (&Sinternal_make_lisp_face
);
7569 defsubr (&Sinternal_lisp_face_p
);
7570 defsubr (&Sinternal_set_lisp_face_attribute
);
7571 #ifdef HAVE_WINDOW_SYSTEM
7572 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
7574 defsubr (&Scolor_gray_p
);
7575 defsubr (&Scolor_supported_p
);
7576 defsubr (&Sface_attribute_relative_p
);
7577 defsubr (&Smerge_face_attribute
);
7578 defsubr (&Sinternal_get_lisp_face_attribute
);
7579 defsubr (&Sinternal_lisp_face_attribute_values
);
7580 defsubr (&Sinternal_lisp_face_equal_p
);
7581 defsubr (&Sinternal_lisp_face_empty_p
);
7582 defsubr (&Sinternal_copy_lisp_face
);
7583 defsubr (&Sinternal_merge_in_global_face
);
7584 defsubr (&Sface_font
);
7585 defsubr (&Sframe_face_alist
);
7586 defsubr (&Stty_supports_face_attributes_p
);
7587 defsubr (&Scolor_distance
);
7588 defsubr (&Sinternal_set_font_selection_order
);
7589 defsubr (&Sinternal_set_alternative_font_family_alist
);
7590 defsubr (&Sinternal_set_alternative_font_registry_alist
);
7591 defsubr (&Sface_attributes_as_vector
);
7593 defsubr (&Sdump_face
);
7594 defsubr (&Sshow_face_resources
);
7595 #endif /* GLYPH_DEBUG */
7596 defsubr (&Sclear_face_cache
);
7597 defsubr (&Stty_suppress_bold_inverse_default_colors
);
7599 #if defined DEBUG_X_COLORS && defined HAVE_X_WINDOWS
7600 defsubr (&Sdump_colors
);
7603 DEFVAR_LISP ("font-list-limit", &Vfont_list_limit
,
7604 doc
: /* *Limit for font matching.
7605 If an integer > 0, font matching functions won't load more than
7606 that number of fonts when searching for a matching font. */);
7607 Vfont_list_limit
= make_number (DEFAULT_FONT_LIST_LIMIT
);
7609 DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults
,
7610 doc
: /* List of global face definitions (for internal use only.) */);
7611 Vface_new_frame_defaults
= Qnil
;
7613 DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple
,
7614 doc
: /* *Default stipple pattern used on monochrome displays.
7615 This stipple pattern is used on monochrome displays
7616 instead of shades of gray for a face background color.
7617 See `set-face-stipple' for possible values for this variable. */);
7618 Vface_default_stipple
= build_string ("gray3");
7620 DEFVAR_LISP ("tty-defined-color-alist", &Vtty_defined_color_alist
,
7621 doc
: /* An alist of defined terminal colors and their RGB values. */);
7622 Vtty_defined_color_alist
= Qnil
;
7624 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed
,
7625 doc
: /* Allowed scalable fonts.
7626 A value of nil means don't allow any scalable fonts.
7627 A value of t means allow any scalable font.
7628 Otherwise, value must be a list of regular expressions. A font may be
7629 scaled if its name matches a regular expression in the list.
7630 Note that if value is nil, a scalable font might still be used, if no
7631 other font of the appropriate family and registry is available. */);
7632 Vscalable_fonts_allowed
= Qnil
;
7634 DEFVAR_LISP ("face-ignored-fonts", &Vface_ignored_fonts
,
7635 doc
: /* List of ignored fonts.
7636 Each element is a regular expression that matches names of fonts to
7638 Vface_ignored_fonts
= Qnil
;
7640 #ifdef HAVE_WINDOW_SYSTEM
7641 defsubr (&Sbitmap_spec_p
);
7642 defsubr (&Sx_list_fonts
);
7643 defsubr (&Sinternal_face_x_get_resource
);
7644 defsubr (&Sx_family_fonts
);
7645 defsubr (&Sx_font_family_list
);
7646 #endif /* HAVE_WINDOW_SYSTEM */