1 /* xfaces.c -- "Face" primitives.
2 Copyright (C) 1993, 1994, 1998, 1999 Free Software Foundation.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* New face implementation by Gerd Moellmann <gerd@gnu.org>. */
25 When using Emacs with X, the display style of characters can be
26 changed by defining `faces'. Each face can specify the following
29 1. Font family or fontset alias name.
31 2. Relative proportionate width, aka character set width or set
32 width (swidth), e.g. `semi-compressed'.
34 3. Font height in 1/10pt
36 4. Font weight, e.g. `bold'.
38 5. Font slant, e.g. `italic'.
44 8. Whether or not characters should be underlined, and in what color.
46 9. Whether or not characters should be displayed in inverse video.
48 10. A background stipple, a bitmap.
50 11. Whether or not characters should be overlined, and in what color.
52 12. Whether or not characters should be strike-through, and in what
55 13. Whether or not a box should be drawn around characters, the box
56 type, and, for simple boxes, in what color.
58 Faces are frame-local by nature because Emacs allows to define the
59 same named face (face names are symbols) differently for different
60 frames. Each frame has an alist of face definitions for all named
61 faces. The value of a named face in such an alist is a Lisp vector
62 with the symbol `face' in slot 0, and a slot for each each of the
63 face attributes mentioned above.
65 There is also a global face alist `Vface_new_frame_defaults'. Face
66 definitions from this list are used to initialize faces of newly
69 A face doesn't have to specify all attributes. Those not specified
70 have a value of `unspecified'. Faces specifying all attributes are
71 called `fully-specified'.
76 The display style of a given character in the text is determined by
77 combining several faces. This process is called `face merging'.
78 Any aspect of the display style that isn't specified by overlays or
79 text properties is taken from the `default' face. Since it is made
80 sure that the default face is always fully-specified, face merging
81 always results in a fully-specified face.
86 After all face attributes for a character have been determined by
87 merging faces of that character, that face is `realized'. The
88 realization process maps face attributes to what is physically
89 available on the system where Emacs runs. The result is a
90 `realized face' in form of a struct face which is stored in the
91 face cache of the frame on which it was realized.
93 Face realization is done in the context of the charset of the
94 character to display because different fonts and encodings are used
95 for different charsets. In other words, for characters of
96 different charsets, different realized faces are needed to display
99 Except for composite characters (CHARSET_COMPOSITION), faces are
100 always realized for a specific character set and contain a specific
101 font, even if the face being realized specifies a fontset (see
102 `font selection' below). The reason is that the result of the new
103 font selection stage is better than what can be done with
104 statically defined font name patterns in fontsets.
109 In unibyte text, Emacs' charsets aren't applicable; function
110 `char-charset' reports CHARSET_ASCII for all characters, including
111 those > 0x7f. The X registry and encoding of fonts to use is
112 determined from the variable `x-unibyte-registry-and-encoding' in
113 this case. The variable is initialized at Emacs startup time from
114 the font the user specified for Emacs.
116 Currently all unibyte text, i.e. all buffers with
117 enable_multibyte_characters nil are displayed with fonts of the
118 same registry and encoding `x-unibyte-registry-and-encoding'. This
119 is consistent with the fact that languages can also be set
125 Font selection tries to find the best available matching font for a
126 given (charset, face) combination. This is done slightly
127 differently for faces specifying a fontset, or a font family name.
129 If the face specifies a fontset alias name, that fontset determines
130 a pattern for fonts of the given charset. If the face specifies a
131 font family, a font pattern is constructed. Charset symbols have a
132 property `x-charset-registry' for that purpose that maps a charset
133 to an XLFD registry and encoding in the font pattern constructed.
135 Available fonts on the system on which Emacs runs are then matched
136 against the font pattern. The result of font selection is the best
137 match for the given face attributes in this font list.
139 Font selection can be influenced by the user.
141 1. The user can specify the relative importance he gives the face
142 attributes width, height, weight, and slant by setting
143 face-font-selection-order (faces.el) to a list of face attribute
144 names. The default is '(:width :height :weight :slant), and means
145 that font selection first tries to find a good match for the font
146 width specified by a face, then---within fonts with that
147 width---tries to find a best match for the specified font height,
150 2. Setting face-alternative-font-family-alist allows the user to
151 specify alternative font families to try if a family specified by a
155 Composite characters.
157 Realized faces for composite characters are the only ones having a
158 fontset id >= 0. When a composite character is encoded into a
159 sequence of non-composite characters (in xterm.c), a suitable font
160 for the non-composite characters is then selected and realized,
161 i.e. the realization process is delayed but in principle the same.
164 Initialization of basic faces.
166 The faces `default', `modeline' are considered `basic faces'.
167 When redisplay happens the first time for a newly created frame,
168 basic faces are realized for CHARSET_ASCII. Frame parameters are
169 used to fill in unspecified attributes of the default face. */
171 /* Define SCALABLE_FONTS to a non-zero value to enable scalable
172 font use. Define it to zero to disable scalable font use.
174 Use of too many or too large scalable fonts can crash XFree86
175 servers. That's why I've put the code dealing with scalable fonts
178 #define SCALABLE_FONTS 1
180 #include <sys/types.h>
181 #include <sys/stat.h>
187 #ifdef HAVE_X_WINDOWS
197 #include "dispextern.h"
198 #include "blockinput.h"
200 #include "intervals.h"
202 #ifdef HAVE_X_WINDOWS
204 /* Compensate for a bug in Xos.h on some systems, on which it requires
205 time.h. On some such systems, Xos.h tries to redefine struct
206 timeval and struct timezone if USG is #defined while it is
209 #ifdef XOS_NEEDS_TIME_H
215 #else /* not XOS_NEEDS_TIME_H */
217 #endif /* not XOS_NEEDS_TIME_H */
219 #endif /* HAVE_X_WINDOWS */
224 #include "keyboard.h"
227 #define max(A, B) ((A) > (B) ? (A) : (B))
228 #define min(A, B) ((A) < (B) ? (A) : (B))
229 #define abs(X) ((X) < 0 ? -(X) : (X))
232 /* Non-zero if face attribute ATTR is unspecified. */
234 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified)
236 /* Value is the number of elements of VECTOR. */
238 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
240 /* Make a copy of string S on the stack using alloca. Value is a pointer
243 #define STRDUPA(S) strcpy ((char *) alloca (strlen ((S)) + 1), (S))
245 /* Make a copy of the contents of Lisp string S on the stack using
246 alloca. Value is a pointer to the copy. */
248 #define LSTRDUPA(S) STRDUPA (XSTRING ((S))->data)
250 /* Size of hash table of realized faces in face caches (should be a
253 #define FACE_CACHE_BUCKETS_SIZE 1001
255 /* Keyword symbols used for face attribute names. */
257 Lisp_Object QCfamily
, QCheight
, QCweight
, QCslant
, QCunderline
;
258 Lisp_Object QCinverse_video
, QCforeground
, QCbackground
, QCstipple
;
259 Lisp_Object QCwidth
, QCfont
, QCbold
, QCitalic
;
260 Lisp_Object QCreverse_video
;
261 Lisp_Object QCoverline
, QCstrike_through
, QCbox
;
263 /* Symbols used for attribute values. */
265 Lisp_Object Qnormal
, Qbold
, Qultra_light
, Qextra_light
, Qlight
;
266 Lisp_Object Qsemi_light
, Qsemi_bold
, Qextra_bold
, Qultra_bold
;
267 Lisp_Object Qoblique
, Qitalic
, Qreverse_oblique
, Qreverse_italic
;
268 Lisp_Object Qultra_condensed
, Qextra_condensed
, Qcondensed
;
269 Lisp_Object Qsemi_condensed
, Qsemi_expanded
, Qexpanded
, Qextra_expanded
;
270 Lisp_Object Qultra_expanded
;
271 Lisp_Object Qreleased_button
, Qpressed_button
;
272 Lisp_Object QCstyle
, QCcolor
, QCline_width
;
273 Lisp_Object Qunspecified
;
275 /* The symbol `x-charset-registry'. This property of charsets defines
276 the X registry and encoding that fonts should have that are used to
277 display characters of that charset. */
279 Lisp_Object Qx_charset_registry
;
281 /* The name of the function to call when the background of the frame
282 has changed, frame_update_face_colors. */
284 Lisp_Object Qframe_update_face_colors
;
286 /* Names of basic faces. */
288 Lisp_Object Qdefault
, Qmode_line
, Qtool_bar
, Qregion
, Qfringe
;
289 Lisp_Object Qheader_line
, Qscroll_bar
, Qcursor
, Qborder
, Qmouse
;;
291 /* The symbol `face-alias'. A symbols having that property is an
292 alias for another face. Value of the property is the name of
295 Lisp_Object Qface_alias
;
297 /* Names of frame parameters related to faces. */
299 extern Lisp_Object Qscroll_bar_foreground
, Qscroll_bar_background
;
300 extern Lisp_Object Qborder_color
, Qcursor_color
, Qmouse_color
;
302 /* Default stipple pattern used on monochrome displays. This stipple
303 pattern is used on monochrome displays instead of shades of gray
304 for a face background color. See `set-face-stipple' for possible
305 values for this variable. */
307 Lisp_Object Vface_default_stipple
;
309 /* Default registry and encoding to use for charsets whose charset
310 symbols don't specify one. */
312 Lisp_Object Vface_default_registry
;
314 /* Alist of alternative font families. Each element is of the form
315 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
316 try FAMILY1, then FAMILY2, ... */
318 Lisp_Object Vface_alternative_font_family_alist
;
320 /* Allowed scalable fonts. A value of nil means don't allow any
321 scalable fonts. A value of t means allow the use of any scalable
322 font. Otherwise, value must be a list of regular expressions. A
323 font may be scaled if its name matches a regular expression in the
327 Lisp_Object Vscalable_fonts_allowed
;
330 /* Maximum number of fonts to consider in font_list. If not an
331 integer > 0, DEFAULT_FONT_LIST_LIMIT is used instead. */
333 Lisp_Object Vfont_list_limit
;
334 #define DEFAULT_FONT_LIST_LIMIT 100
336 /* The symbols `foreground-color' and `background-color' which can be
337 used as part of a `face' property. This is for compatibility with
340 Lisp_Object Qforeground_color
, Qbackground_color
;
342 /* The symbols `face' and `mouse-face' used as text properties. */
345 extern Lisp_Object Qmouse_face
;
347 /* Error symbol for wrong_type_argument in load_pixmap. */
349 Lisp_Object Qpixmap_spec_p
;
351 /* Alist of global face definitions. Each element is of the form
352 (FACE . LFACE) where FACE is a symbol naming a face and LFACE
353 is a Lisp vector of face attributes. These faces are used
354 to initialize faces for new frames. */
356 Lisp_Object Vface_new_frame_defaults
;
358 /* The next ID to assign to Lisp faces. */
360 static int next_lface_id
;
362 /* A vector mapping Lisp face Id's to face names. */
364 static Lisp_Object
*lface_id_to_name
;
365 static int lface_id_to_name_size
;
367 /* An alist of elements (COLOR-NAME . INDEX) mapping color names
368 to color indices for tty frames. */
370 Lisp_Object Vface_tty_color_alist
;
372 /* Counter for calls to clear_face_cache. If this counter reaches
373 CLEAR_FONT_TABLE_COUNT, and a frame has more than
374 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
376 static int clear_font_table_count
;
377 #define CLEAR_FONT_TABLE_COUNT 100
378 #define CLEAR_FONT_TABLE_NFONTS 10
380 /* Non-zero means face attributes have been changed since the last
381 redisplay. Used in redisplay_internal. */
383 int face_change_count
;
385 /* The total number of colors currently allocated. */
388 static int ncolors_allocated
;
389 static int npixmaps_allocated
;
395 /* Function prototypes. */
400 static int may_use_scalable_font_p
P_ ((struct font_name
*, char *));
401 static void set_font_frame_param
P_ ((Lisp_Object
, Lisp_Object
));
402 static int better_font_p
P_ ((int *, struct font_name
*, struct font_name
*,
404 static int first_font_matching
P_ ((struct frame
*f
, char *,
405 struct font_name
*));
406 static int x_face_list_fonts
P_ ((struct frame
*, char *,
407 struct font_name
*, int, int, int));
408 static int font_scalable_p
P_ ((struct font_name
*));
409 static Lisp_Object deduce_unibyte_registry
P_ ((struct frame
*, char *));
410 static int get_lface_attributes
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
*, int));
411 static int load_pixmap
P_ ((struct frame
*, Lisp_Object
, unsigned *, unsigned *));
412 static char *xstrdup
P_ ((char *));
413 static unsigned char *xstrlwr
P_ ((unsigned char *));
414 static void signal_error
P_ ((char *, Lisp_Object
));
415 static struct frame
*frame_or_selected_frame
P_ ((Lisp_Object
, int));
416 static void load_face_font_or_fontset
P_ ((struct frame
*, struct face
*, char *, int));
417 static void load_face_colors
P_ ((struct frame
*, struct face
*, Lisp_Object
*));
418 static void free_face_colors
P_ ((struct frame
*, struct face
*));
419 static int face_color_gray_p
P_ ((struct frame
*, char *));
420 static char *build_font_name
P_ ((struct font_name
*));
421 static void free_font_names
P_ ((struct font_name
*, int));
422 static int sorted_font_list
P_ ((struct frame
*, char *,
423 int (*cmpfn
) P_ ((const void *, const void *)),
424 struct font_name
**));
425 static int font_list
P_ ((struct frame
*, char *, char *, char *, struct font_name
**));
426 static int try_font_list
P_ ((struct frame
*, Lisp_Object
*, char *, char *, char *,
427 struct font_name
**));
428 static int cmp_font_names
P_ ((const void *, const void *));
429 static struct face
*realize_face
P_ ((struct face_cache
*,
430 Lisp_Object
*, int));
431 static struct face
*realize_x_face
P_ ((struct face_cache
*,
432 Lisp_Object
*, int));
433 static struct face
*realize_tty_face
P_ ((struct face_cache
*,
434 Lisp_Object
*, int));
435 static int realize_basic_faces
P_ ((struct frame
*));
436 static int realize_default_face
P_ ((struct frame
*));
437 static void realize_named_face
P_ ((struct frame
*, Lisp_Object
, int));
438 static int lface_fully_specified_p
P_ ((Lisp_Object
*));
439 static int lface_equal_p
P_ ((Lisp_Object
*, Lisp_Object
*));
440 static unsigned hash_string_case_insensitive
P_ ((Lisp_Object
));
441 static unsigned lface_hash
P_ ((Lisp_Object
*));
442 static int lface_same_font_attributes_p
P_ ((Lisp_Object
*, Lisp_Object
*));
443 static struct face_cache
*make_face_cache
P_ ((struct frame
*));
444 static void free_realized_face
P_ ((struct frame
*, struct face
*));
445 static void clear_face_gcs
P_ ((struct face_cache
*));
446 static void free_face_cache
P_ ((struct face_cache
*));
447 static int face_numeric_weight
P_ ((Lisp_Object
));
448 static int face_numeric_slant
P_ ((Lisp_Object
));
449 static int face_numeric_swidth
P_ ((Lisp_Object
));
450 static int face_fontset
P_ ((struct frame
*, Lisp_Object
*));
451 static char *choose_face_font
P_ ((struct frame
*, Lisp_Object
*, int,
453 static char *choose_face_fontset_font
P_ ((struct frame
*, Lisp_Object
*,
455 static void merge_face_vectors
P_ ((Lisp_Object
*from
, Lisp_Object
*));
456 static void merge_face_vector_with_property
P_ ((struct frame
*, Lisp_Object
*,
458 static int set_lface_from_font_name
P_ ((struct frame
*, Lisp_Object
, char *,
460 static Lisp_Object lface_from_face_name
P_ ((struct frame
*, Lisp_Object
, int));
461 static struct face
*make_realized_face
P_ ((Lisp_Object
*, int, Lisp_Object
));
462 static void free_realized_faces
P_ ((struct face_cache
*));
463 static char *best_matching_font
P_ ((struct frame
*, Lisp_Object
*,
464 struct font_name
*, int));
465 static void cache_face
P_ ((struct face_cache
*, struct face
*, unsigned));
466 static void uncache_face
P_ ((struct face_cache
*, struct face
*));
467 static int xlfd_numeric_slant
P_ ((struct font_name
*));
468 static int xlfd_numeric_weight
P_ ((struct font_name
*));
469 static int xlfd_numeric_swidth
P_ ((struct font_name
*));
470 static Lisp_Object xlfd_symbolic_slant
P_ ((struct font_name
*));
471 static Lisp_Object xlfd_symbolic_weight
P_ ((struct font_name
*));
472 static Lisp_Object xlfd_symbolic_swidth
P_ ((struct font_name
*));
473 static int xlfd_fixed_p
P_ ((struct font_name
*));
474 static int xlfd_numeric_value
P_ ((struct table_entry
*, int, struct font_name
*,
476 static Lisp_Object xlfd_symbolic_value
P_ ((struct table_entry
*, int,
477 struct font_name
*, int, int));
478 static struct table_entry
*xlfd_lookup_field_contents
P_ ((struct table_entry
*, int,
479 struct font_name
*, int));
481 #ifdef HAVE_X_WINDOWS
483 static int split_font_name
P_ ((struct frame
*, struct font_name
*, int));
484 static int xlfd_point_size
P_ ((struct frame
*, struct font_name
*));
485 static void sort_fonts
P_ ((struct frame
*, struct font_name
*, int,
486 int (*cmpfn
) P_ ((const void *, const void *))));
487 static GC x_create_gc
P_ ((struct frame
*, unsigned long, XGCValues
*));
488 static void x_free_gc
P_ ((struct frame
*, GC
));
489 static void clear_font_table
P_ ((struct frame
*));
491 #endif /* HAVE_X_WINDOWS */
494 /***********************************************************************
496 ***********************************************************************/
498 #ifdef HAVE_X_WINDOWS
500 /* Create and return a GC for use on frame F. GC values and mask
501 are given by XGCV and MASK. */
504 x_create_gc (f
, mask
, xgcv
)
511 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
518 /* Free GC which was used on frame F. */
526 xassert (--ngcs
>= 0);
527 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
531 #endif /* HAVE_X_WINDOWS */
534 /* Like strdup, but uses xmalloc. */
540 int len
= strlen (s
) + 1;
541 char *p
= (char *) xmalloc (len
);
547 /* Like stricmp. Used to compare parts of font names which are in
552 unsigned char *s1
, *s2
;
556 unsigned char c1
= tolower (*s1
);
557 unsigned char c2
= tolower (*s2
);
559 return c1
< c2
? -1 : 1;
564 return *s2
== 0 ? 0 : -1;
569 /* Like strlwr, which might not always be available. */
571 static unsigned char *
575 unsigned char *p
= s
;
584 /* Signal `error' with message S, and additional argument ARG. */
587 signal_error (s
, arg
)
591 Fsignal (Qerror
, Fcons (build_string (s
), Fcons (arg
, Qnil
)));
595 /* If FRAME is nil, return a pointer to the selected frame.
596 Otherwise, check that FRAME is a live frame, and return a pointer
597 to it. NPARAM is the parameter number of FRAME, for
598 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
599 Lisp function definitions. */
601 static INLINE
struct frame
*
602 frame_or_selected_frame (frame
, nparam
)
607 frame
= selected_frame
;
609 CHECK_LIVE_FRAME (frame
, nparam
);
610 return XFRAME (frame
);
614 /***********************************************************************
616 ***********************************************************************/
618 /* Initialize face cache and basic faces for frame F. */
624 /* Make a face cache, if F doesn't have one. */
625 if (FRAME_FACE_CACHE (f
) == NULL
)
626 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
628 #ifdef HAVE_X_WINDOWS
629 /* Make the image cache. */
632 if (FRAME_X_IMAGE_CACHE (f
) == NULL
)
633 FRAME_X_IMAGE_CACHE (f
) = make_image_cache ();
634 ++FRAME_X_IMAGE_CACHE (f
)->refcount
;
636 #endif /* HAVE_X_WINDOWS */
638 /* Realize basic faces. Must have enough information in frame
639 parameters to realize basic faces at this point. */
640 #ifdef HAVE_X_WINDOWS
641 if (!FRAME_X_P (f
) || FRAME_X_WINDOW (f
))
643 if (!realize_basic_faces (f
))
648 /* Free face cache of frame F. Called from Fdelete_frame. */
654 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
658 free_face_cache (face_cache
);
659 FRAME_FACE_CACHE (f
) = NULL
;
662 #ifdef HAVE_X_WINDOWS
665 struct image_cache
*image_cache
= FRAME_X_IMAGE_CACHE (f
);
668 --image_cache
->refcount
;
669 if (image_cache
->refcount
== 0)
670 free_image_cache (f
);
673 #endif /* HAVE_X_WINDOWS */
677 /* Clear face caches, and recompute basic faces for frame F. Call
678 this after changing frame parameters on which those faces depend,
679 or when realized faces have been freed due to changing attributes
683 recompute_basic_faces (f
)
686 if (FRAME_FACE_CACHE (f
))
689 clear_face_cache (0);
690 realized_p
= realize_basic_faces (f
);
691 xassert (realized_p
);
696 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
697 try to free unused fonts, too. */
700 clear_face_cache (clear_fonts_p
)
703 #ifdef HAVE_X_WINDOWS
704 Lisp_Object tail
, frame
;
708 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
710 /* From time to time see if we can unload some fonts. This also
711 frees all realized faces on all frames. Fonts needed by
712 faces will be loaded again when faces are realized again. */
713 clear_font_table_count
= 0;
715 FOR_EACH_FRAME (tail
, frame
)
719 && FRAME_X_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
721 free_all_realized_faces (frame
);
722 clear_font_table (f
);
728 /* Clear GCs of realized faces. */
729 FOR_EACH_FRAME (tail
, frame
)
734 clear_face_gcs (FRAME_FACE_CACHE (f
));
735 clear_image_cache (f
, 0);
739 #endif /* HAVE_X_WINDOWS */
743 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
744 "Clear face caches on all frames.\n\
745 Optional THOROUGHLY non-nil means try to free unused fonts, too.")
747 Lisp_Object thorougly
;
749 clear_face_cache (!NILP (thorougly
));
755 #ifdef HAVE_X_WINDOWS
758 /* Remove those fonts from the font table of frame F that are not used
759 by fontsets. Called from clear_face_cache from time to time. */
765 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
767 Lisp_Object rest
, frame
;
770 xassert (FRAME_X_P (f
));
772 used
= (char *) alloca (dpyinfo
->n_fonts
* sizeof *used
);
773 bzero (used
, dpyinfo
->n_fonts
* sizeof *used
);
775 /* For all frames with the same x_display_info as F, record
776 in `used' those fonts that are in use by fontsets. */
777 FOR_EACH_FRAME (rest
, frame
)
778 if (FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
780 struct frame
*f
= XFRAME (frame
);
781 struct fontset_data
*fontset_data
= FRAME_FONTSET_DATA (f
);
783 for (i
= 0; i
< fontset_data
->n_fontsets
; ++i
)
785 struct fontset_info
*info
= fontset_data
->fontset_table
[i
];
788 for (j
= 0; j
<= MAX_CHARSET
; ++j
)
790 int idx
= info
->font_indexes
[j
];
797 /* Free those fonts that are not used by fontsets. */
798 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
799 if (used
[i
] == 0 && dpyinfo
->font_table
[i
].name
)
801 struct font_info
*font_info
= dpyinfo
->font_table
+ i
;
803 /* Free names. In xfns.c there is a comment that full_name
804 should never be freed because it is always shared with
805 something else. I don't think this is true anymore---see
806 x_load_font. It's either equal to font_info->name or
807 allocated via xmalloc, and there seems to be no place in
808 the source files where full_name is transferred to another
810 if (font_info
->full_name
!= font_info
->name
)
811 xfree (font_info
->full_name
);
812 xfree (font_info
->name
);
816 XFreeFont (dpyinfo
->display
, font_info
->font
);
819 /* Mark font table slot free. */
820 font_info
->font
= NULL
;
821 font_info
->name
= font_info
->full_name
= NULL
;
826 #endif /* HAVE_X_WINDOWS */
830 /***********************************************************************
832 ***********************************************************************/
834 #ifdef HAVE_X_WINDOWS
836 DEFUN ("pixmap-spec-p", Fpixmap_spec_p
, Spixmap_spec_p
, 1, 1, 0,
837 "Non-nil if OBJECT is a valid pixmap specification.\n\
838 A pixmap specification is either a string, or a list (WIDTH HEIGHT DATA)\n\
839 where WIDTH is the pixel width of the pixmap, HEIGHT is its height,\n\
840 and DATA contains the bits of the pixmap.")
844 Lisp_Object height
, width
;
846 return ((STRINGP (object
)
848 && CONSP (XCONS (object
)->cdr
)
849 && CONSP (XCONS (XCONS (object
)->cdr
)->cdr
)
850 && NILP (XCONS (XCONS (XCONS (object
)->cdr
)->cdr
)->cdr
)
851 && (width
= XCONS (object
)->car
, INTEGERP (width
))
852 && (height
= XCONS (XCONS (object
)->cdr
)->car
,
854 && STRINGP (XCONS (XCONS (XCONS (object
)->cdr
)->cdr
)->car
)
857 /* The string must have enough bits for width * height. */
858 && ((XSTRING (XCONS (XCONS (XCONS (object
)->cdr
)->cdr
)->car
)->size
859 * (BITS_PER_INT
/ sizeof (int)))
860 >= XFASTINT (width
) * XFASTINT (height
))))
865 /* Load a bitmap according to NAME (which is either a file name or a
866 pixmap spec) for use on frame F. Value is the bitmap_id (see
867 xfns.c). If NAME is nil, return with a bitmap id of zero. If
868 bitmap cannot be loaded, display a message saying so, and return
869 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
870 if these pointers are not null. */
873 load_pixmap (f
, name
, w_ptr
, h_ptr
)
876 unsigned int *w_ptr
, *h_ptr
;
884 tem
= Fpixmap_spec_p (name
);
886 wrong_type_argument (Qpixmap_spec_p
, name
);
891 /* Decode a bitmap spec into a bitmap. */
896 w
= XINT (Fcar (name
));
897 h
= XINT (Fcar (Fcdr (name
)));
898 bits
= Fcar (Fcdr (Fcdr (name
)));
900 bitmap_id
= x_create_bitmap_from_data (f
, XSTRING (bits
)->data
,
905 /* It must be a string -- a file name. */
906 bitmap_id
= x_create_bitmap_from_file (f
, name
);
912 add_to_log ("Invalid or undefined bitmap %s", name
, Qnil
);
923 ++npixmaps_allocated
;
926 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
929 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
935 #endif /* HAVE_X_WINDOWS */
939 /***********************************************************************
941 ***********************************************************************/
943 #ifdef HAVE_X_WINDOWS
945 /* Update the line_height of frame F. Return non-zero if line height
949 frame_update_line_height (f
)
952 int fontset
, line_height
, changed_p
;
954 fontset
= f
->output_data
.x
->fontset
;
956 line_height
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
]->height
;
958 line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
960 changed_p
= line_height
!= f
->output_data
.x
->line_height
;
961 f
->output_data
.x
->line_height
= line_height
;
965 #endif /* HAVE_X_WINDOWS */
968 /***********************************************************************
970 ***********************************************************************/
972 #ifdef HAVE_X_WINDOWS
974 /* Load font or fontset of face FACE which is used on frame F.
975 FONTSET is the fontset FACE should use or -1, if FACE doesn't use a
976 fontset. FONT_NAME is the name of the font to load, if no fontset
977 is used. It is null if no suitable font name could be determined
981 load_face_font_or_fontset (f
, face
, font_name
, fontset
)
987 struct font_info
*font_info
= NULL
;
989 face
->font_info_id
= -1;
990 face
->fontset
= fontset
;
995 font_info
= FS_LOAD_FONT (f
, FRAME_X_FONT_TABLE (f
), CHARSET_ASCII
,
998 font_info
= FS_LOAD_FONT (f
, FRAME_X_FONT_TABLE (f
), face
->charset
,
1007 face
->font_info_id
= FONT_INFO_ID (f
, font_info
);
1008 face
->font
= font_info
->font
;
1009 face
->font_name
= font_info
->full_name
;
1011 /* Make the registry part of the font name readily accessible.
1012 The registry is used to find suitable faces for unibyte text. */
1013 s
= font_info
->full_name
+ strlen (font_info
->full_name
);
1015 while (i
< 2 && --s
>= font_info
->full_name
)
1019 if (!STRINGP (face
->registry
)
1020 || xstricmp (XSTRING (face
->registry
)->data
, s
+ 1) != 0)
1022 if (STRINGP (Vface_default_registry
)
1023 && !xstricmp (XSTRING (Vface_default_registry
)->data
, s
+ 1))
1024 face
->registry
= Vface_default_registry
;
1026 face
->registry
= build_string (s
+ 1);
1029 else if (fontset
>= 0)
1030 add_to_log ("Unable to load ASCII font of fontset %d",
1031 make_number (fontset
), Qnil
);
1033 add_to_log ("Unable to load font %s",
1034 build_string (font_name
), Qnil
);
1037 #endif /* HAVE_X_WINDOWS */
1041 /***********************************************************************
1043 ***********************************************************************/
1045 #ifdef HAVE_X_WINDOWS
1047 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1048 black) on frame F. The algorithm is taken from 20.2 faces.el. */
1051 face_color_gray_p (f
, color_name
)
1058 if (defined_color (f
, color_name
, &color
, 0))
1059 gray_p
= ((abs (color
.red
- color
.green
)
1060 < max (color
.red
, color
.green
) / 20)
1061 && (abs (color
.green
- color
.blue
)
1062 < max (color
.green
, color
.blue
) / 20)
1063 && (abs (color
.blue
- color
.red
)
1064 < max (color
.blue
, color
.red
) / 20));
1072 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1073 BACKGROUND_P non-zero means the color will be used as background
1077 face_color_supported_p (f
, color_name
, background_p
)
1084 XSETFRAME (frame
, f
);
1085 return (!NILP (Vwindow_system
)
1086 && (!NILP (Fx_display_color_p (frame
))
1087 || xstricmp (color_name
, "black") == 0
1088 || xstricmp (color_name
, "white") == 0
1090 && face_color_gray_p (f
, color_name
))
1091 || (!NILP (Fx_display_grayscale_p (frame
))
1092 && face_color_gray_p (f
, color_name
))));
1096 DEFUN ("face-color-gray-p", Fface_color_gray_p
, Sface_color_gray_p
, 1, 2, 0,
1097 "Return non-nil if COLOR is a shade of gray (or white or black).\n\
1098 FRAME specifies the frame and thus the display for interpreting COLOR.\n\
1099 If FRAME is nil or omitted, use the selected frame.")
1101 Lisp_Object color
, frame
;
1103 struct frame
*f
= check_x_frame (frame
);
1104 CHECK_STRING (color
, 0);
1105 return face_color_gray_p (f
, XSTRING (color
)->data
) ? Qt
: Qnil
;
1109 DEFUN ("face-color-supported-p", Fface_color_supported_p
,
1110 Sface_color_supported_p
, 2, 3, 0,
1111 "Return non-nil if COLOR can be displayed on FRAME.\n\
1112 BACKGROUND-P non-nil means COLOR is used as a background.\n\
1113 If FRAME is nil or omitted, use the selected frame.\n\
1114 COLOR must be a valid color name.")
1115 (frame
, color
, background_p
)
1116 Lisp_Object frame
, color
, background_p
;
1118 struct frame
*f
= check_x_frame (frame
);
1119 CHECK_STRING (color
, 0);
1120 if (face_color_supported_p (f
, XSTRING (color
)->data
, !NILP (background_p
)))
1125 /* Load color with name NAME for use by face FACE on frame F.
1126 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1127 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1128 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1129 pixel color. If color cannot be loaded, display a message, and
1130 return the foreground, background or underline color of F, but
1131 record that fact in flags of the face so that we don't try to free
1135 load_color (f
, face
, name
, target_index
)
1139 enum lface_attribute_index target_index
;
1143 xassert (STRINGP (name
));
1144 xassert (target_index
== LFACE_FOREGROUND_INDEX
1145 || target_index
== LFACE_BACKGROUND_INDEX
1146 || target_index
== LFACE_UNDERLINE_INDEX
1147 || target_index
== LFACE_OVERLINE_INDEX
1148 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1149 || target_index
== LFACE_BOX_INDEX
);
1151 /* if the color map is full, defined_color will return a best match
1152 to the values in an existing cell. */
1153 if (!defined_color (f
, XSTRING (name
)->data
, &color
, 1))
1155 add_to_log ("Unable to load color %s", name
, Qnil
);
1157 switch (target_index
)
1159 case LFACE_FOREGROUND_INDEX
:
1160 face
->foreground_defaulted_p
= 1;
1161 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1164 case LFACE_BACKGROUND_INDEX
:
1165 face
->background_defaulted_p
= 1;
1166 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1169 case LFACE_UNDERLINE_INDEX
:
1170 face
->underline_defaulted_p
= 1;
1171 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1174 case LFACE_OVERLINE_INDEX
:
1175 face
->overline_color_defaulted_p
= 1;
1176 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1179 case LFACE_STRIKE_THROUGH_INDEX
:
1180 face
->strike_through_color_defaulted_p
= 1;
1181 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1184 case LFACE_BOX_INDEX
:
1185 face
->box_color_defaulted_p
= 1;
1186 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1195 ++ncolors_allocated
;
1202 /* Load colors for face FACE which is used on frame F. Colors are
1203 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1204 of ATTRS. If the background color specified is not supported on F,
1205 try to emulate gray colors with a stipple from Vface_default_stipple. */
1208 load_face_colors (f
, face
, attrs
)
1215 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1216 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1218 /* Swap colors if face is inverse-video. */
1219 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1227 /* Check for support for foreground, not for background because
1228 face_color_supported_p is smart enough to know that grays are
1229 "supported" as background because we are supposed to use stipple
1231 if (!face_color_supported_p (f
, XSTRING (bg
)->data
, 0)
1232 && !NILP (Fpixmap_spec_p (Vface_default_stipple
)))
1234 x_destroy_bitmap (f
, face
->stipple
);
1235 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1236 &face
->pixmap_w
, &face
->pixmap_h
);
1239 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1240 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1244 /* Free color PIXEL on frame F. */
1247 unload_color (f
, pixel
)
1249 unsigned long pixel
;
1251 Display
*dpy
= FRAME_X_DISPLAY (f
);
1252 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
1254 if (pixel
== BLACK_PIX_DEFAULT (f
)
1255 || pixel
== WHITE_PIX_DEFAULT (f
))
1260 /* If display has an immutable color map, freeing colors is not
1261 necessary and some servers don't allow it. So don't do it. */
1262 if (! (class == StaticColor
|| class == StaticGray
|| class == TrueColor
))
1264 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
1265 XFreeColors (dpy
, cmap
, &pixel
, 1, 0);
1272 /* Free colors allocated for FACE. */
1275 free_face_colors (f
, face
)
1279 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
1281 /* If display has an immutable color map, freeing colors is not
1282 necessary and some servers don't allow it. So don't do it. */
1283 if (class != StaticColor
1284 && class != StaticGray
1285 && class != TrueColor
)
1291 dpy
= FRAME_X_DISPLAY (f
);
1292 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
1294 if (face
->foreground
!= BLACK_PIX_DEFAULT (f
)
1295 && face
->foreground
!= WHITE_PIX_DEFAULT (f
)
1296 && !face
->foreground_defaulted_p
)
1298 XFreeColors (dpy
, cmap
, &face
->foreground
, 1, 0);
1299 IF_DEBUG (--ncolors_allocated
);
1302 if (face
->background
!= BLACK_PIX_DEFAULT (f
)
1303 && face
->background
!= WHITE_PIX_DEFAULT (f
)
1304 && !face
->background_defaulted_p
)
1306 XFreeColors (dpy
, cmap
, &face
->background
, 1, 0);
1307 IF_DEBUG (--ncolors_allocated
);
1310 if (face
->underline_p
1311 && !face
->underline_defaulted_p
1312 && face
->underline_color
!= BLACK_PIX_DEFAULT (f
)
1313 && face
->underline_color
!= WHITE_PIX_DEFAULT (f
))
1315 XFreeColors (dpy
, cmap
, &face
->underline_color
, 1, 0);
1316 IF_DEBUG (--ncolors_allocated
);
1319 if (face
->overline_p
1320 && !face
->overline_color_defaulted_p
1321 && face
->overline_color
!= BLACK_PIX_DEFAULT (f
)
1322 && face
->overline_color
!= WHITE_PIX_DEFAULT (f
))
1324 XFreeColors (dpy
, cmap
, &face
->overline_color
, 1, 0);
1325 IF_DEBUG (--ncolors_allocated
);
1328 if (face
->strike_through_p
1329 && !face
->strike_through_color_defaulted_p
1330 && face
->strike_through_color
!= BLACK_PIX_DEFAULT (f
)
1331 && face
->strike_through_color
!= WHITE_PIX_DEFAULT (f
))
1333 XFreeColors (dpy
, cmap
, &face
->strike_through_color
, 1, 0);
1334 IF_DEBUG (--ncolors_allocated
);
1337 if (face
->box
!= FACE_NO_BOX
1338 && !face
->box_color_defaulted_p
1339 && face
->box_color
!= BLACK_PIX_DEFAULT (f
)
1340 && face
->box_color
!= WHITE_PIX_DEFAULT (f
))
1342 XFreeColors (dpy
, cmap
, &face
->box_color
, 1, 0);
1343 IF_DEBUG (--ncolors_allocated
);
1350 #else /* ! HAVE_X_WINDOWS */
1354 load_color (f
, face
, name
, target_index
)
1358 enum lface_attribute_index target_index
;
1361 int color_idx
= FACE_TTY_DEFAULT_COLOR
;
1364 return (unsigned long)FACE_TTY_DEFAULT_COLOR
;
1366 CHECK_STRING (name
, 0);
1369 if (XSTRING (name
)->size
&& !NILP (Ffboundp (Qmsdos_color_translate
)))
1371 color
= call1 (Qmsdos_color_translate
, name
);
1373 if (INTEGERP (color
))
1374 return (unsigned long)XINT (color
);
1376 add_to_log ("Unable to load color %s", name
, Qnil
);
1378 switch (target_index
)
1380 case LFACE_FOREGROUND_INDEX
:
1381 face
->foreground_defaulted_p
= 1;
1382 color_idx
= FRAME_FOREGROUND_PIXEL (f
);
1385 case LFACE_BACKGROUND_INDEX
:
1386 face
->background_defaulted_p
= 1;
1387 color_idx
= FRAME_BACKGROUND_PIXEL (f
);
1390 case LFACE_UNDERLINE_INDEX
:
1391 face
->underline_defaulted_p
= 1;
1392 color_idx
= FRAME_FOREGROUND_PIXEL (f
);
1395 case LFACE_OVERLINE_INDEX
:
1396 face
->overline_color_defaulted_p
= 1;
1397 color_idx
= FRAME_FOREGROUND_PIXEL (f
);
1400 case LFACE_STRIKE_THROUGH_INDEX
:
1401 face
->strike_through_color_defaulted_p
= 1;
1402 color_idx
= FRAME_FOREGROUND_PIXEL (f
);
1405 case LFACE_BOX_INDEX
:
1406 face
->box_color_defaulted_p
= 1;
1407 color_idx
= FRAME_FOREGROUND_PIXEL (f
);
1412 color_idx
= msdos_stdcolor_idx (XSTRING (name
)->data
);
1414 return (unsigned long)color_idx
;
1417 #endif /* ! HAVE_X_WINDOWS */
1421 /***********************************************************************
1423 ***********************************************************************/
1425 /* An enumerator for each field of an XLFD font name. */
1446 /* An enumerator for each possible slant value of a font. Taken from
1447 the XLFD specification. */
1455 XLFD_SLANT_REVERSE_ITALIC
,
1456 XLFD_SLANT_REVERSE_OBLIQUE
,
1460 /* Relative font weight according to XLFD documentation. */
1464 XLFD_WEIGHT_UNKNOWN
,
1465 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1466 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1467 XLFD_WEIGHT_LIGHT
, /* 30 */
1468 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1469 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1470 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1471 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1472 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1473 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1476 /* Relative proportionate width. */
1480 XLFD_SWIDTH_UNKNOWN
,
1481 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1482 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1483 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1484 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1485 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1486 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1487 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1488 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1489 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1492 /* Structure used for tables mapping XLFD weight, slant, and width
1493 names to numeric and symbolic values. */
1499 Lisp_Object
*symbol
;
1502 /* Table of XLFD slant names and their numeric and symbolic
1503 representations. This table must be sorted by slant names in
1506 static struct table_entry slant_table
[] =
1508 {"i", XLFD_SLANT_ITALIC
, &Qitalic
},
1509 {"o", XLFD_SLANT_OBLIQUE
, &Qoblique
},
1510 {"ot", XLFD_SLANT_OTHER
, &Qitalic
},
1511 {"r", XLFD_SLANT_ROMAN
, &Qnormal
},
1512 {"ri", XLFD_SLANT_REVERSE_ITALIC
, &Qreverse_italic
},
1513 {"ro", XLFD_SLANT_REVERSE_OBLIQUE
, &Qreverse_oblique
}
1516 /* Table of XLFD weight names. This table must be sorted by weight
1517 names in ascending order. */
1519 static struct table_entry weight_table
[] =
1521 {"black", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
},
1522 {"bold", XLFD_WEIGHT_BOLD
, &Qbold
},
1523 {"book", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1524 {"demibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1525 {"extralight", XLFD_WEIGHT_EXTRA_LIGHT
, &Qextra_light
},
1526 {"extrabold", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1527 {"heavy", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1528 {"light", XLFD_WEIGHT_LIGHT
, &Qlight
},
1529 {"medium", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1530 {"normal", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1531 {"regular", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1532 {"semibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1533 {"semilight", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1534 {"ultralight", XLFD_WEIGHT_ULTRA_LIGHT
, &Qultra_light
},
1535 {"ultrabold", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
}
1538 /* Table of XLFD width names. This table must be sorted by width
1539 names in ascending order. */
1541 static struct table_entry swidth_table
[] =
1543 {"compressed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1544 {"condensed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1545 {"demiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1546 {"expanded", XLFD_SWIDTH_EXPANDED
, &Qexpanded
},
1547 {"extracondensed", XLFD_SWIDTH_EXTRA_CONDENSED
, &Qextra_condensed
},
1548 {"extraexpanded", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
},
1549 {"medium", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1550 {"narrow", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1551 {"normal", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1552 {"regular", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1553 {"semicondensed", XLFD_SWIDTH_SEMI_CONDENSED
, &Qsemi_condensed
},
1554 {"semiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1555 {"ultracondensed", XLFD_SWIDTH_ULTRA_CONDENSED
, &Qultra_condensed
},
1556 {"ultraexpanded", XLFD_SWIDTH_ULTRA_EXPANDED
, &Qultra_expanded
},
1557 {"wide", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
}
1560 /* Structure used to hold the result of splitting font names in XLFD
1561 format into their fields. */
1565 /* The original name which is modified destructively by
1566 split_font_name. The pointer is kept here to be able to free it
1567 if it was allocated from the heap. */
1570 /* Font name fields. Each vector element points into `name' above.
1571 Fields are NUL-terminated. */
1572 char *fields
[XLFD_LAST
];
1574 /* Numeric values for those fields that interest us. See
1575 split_font_name for which these are. */
1576 int numeric
[XLFD_LAST
];
1579 /* The frame in effect when sorting font names. Set temporarily in
1580 sort_fonts so that it is available in font comparison functions. */
1582 static struct frame
*font_frame
;
1584 /* Order by which font selection chooses fonts. The default values
1585 mean `first, find a best match for the font width, then for the
1586 font height, then for weight, then for slant.' This variable can be
1587 set via set-face-font-sort-order. */
1589 static int font_sort_order
[4];
1592 /* Look up FONT.fields[FIELD_INDEX] in TABLE which has DIM entries.
1593 TABLE must be sorted by TABLE[i]->name in ascending order. Value
1594 is a pointer to the matching table entry or null if no table entry
1597 static struct table_entry
*
1598 xlfd_lookup_field_contents (table
, dim
, font
, field_index
)
1599 struct table_entry
*table
;
1601 struct font_name
*font
;
1604 /* Function split_font_name converts fields to lower-case, so there
1605 is no need to use xstrlwr or xstricmp here. */
1606 char *s
= font
->fields
[field_index
];
1607 int low
, mid
, high
, cmp
;
1614 mid
= (low
+ high
) / 2;
1615 cmp
= strcmp (table
[mid
].name
, s
);
1629 /* Return a numeric representation for font name field
1630 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
1631 has DIM entries. Value is the numeric value found or DFLT if no
1632 table entry matches. This function is used to translate weight,
1633 slant, and swidth names of XLFD font names to numeric values. */
1636 xlfd_numeric_value (table
, dim
, font
, field_index
, dflt
)
1637 struct table_entry
*table
;
1639 struct font_name
*font
;
1643 struct table_entry
*p
;
1644 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
1645 return p
? p
->numeric
: dflt
;
1649 /* Return a symbolic representation for font name field
1650 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
1651 has DIM entries. Value is the symbolic value found or DFLT if no
1652 table entry matches. This function is used to translate weight,
1653 slant, and swidth names of XLFD font names to symbols. */
1655 static INLINE Lisp_Object
1656 xlfd_symbolic_value (table
, dim
, font
, field_index
, dflt
)
1657 struct table_entry
*table
;
1659 struct font_name
*font
;
1663 struct table_entry
*p
;
1664 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
1665 return p
? *p
->symbol
: dflt
;
1669 /* Return a numeric value for the slant of the font given by FONT. */
1672 xlfd_numeric_slant (font
)
1673 struct font_name
*font
;
1675 return xlfd_numeric_value (slant_table
, DIM (slant_table
),
1676 font
, XLFD_SLANT
, XLFD_SLANT_ROMAN
);
1680 /* Return a symbol representing the weight of the font given by FONT. */
1682 static INLINE Lisp_Object
1683 xlfd_symbolic_slant (font
)
1684 struct font_name
*font
;
1686 return xlfd_symbolic_value (slant_table
, DIM (slant_table
),
1687 font
, XLFD_SLANT
, Qnormal
);
1691 /* Return a numeric value for the weight of the font given by FONT. */
1694 xlfd_numeric_weight (font
)
1695 struct font_name
*font
;
1697 return xlfd_numeric_value (weight_table
, DIM (weight_table
),
1698 font
, XLFD_WEIGHT
, XLFD_WEIGHT_MEDIUM
);
1702 /* Return a symbol representing the slant of the font given by FONT. */
1704 static INLINE Lisp_Object
1705 xlfd_symbolic_weight (font
)
1706 struct font_name
*font
;
1708 return xlfd_symbolic_value (weight_table
, DIM (weight_table
),
1709 font
, XLFD_WEIGHT
, Qnormal
);
1713 /* Return a numeric value for the swidth of the font whose XLFD font
1714 name fields are found in FONT. */
1717 xlfd_numeric_swidth (font
)
1718 struct font_name
*font
;
1720 return xlfd_numeric_value (swidth_table
, DIM (swidth_table
),
1721 font
, XLFD_SWIDTH
, XLFD_SWIDTH_MEDIUM
);
1725 /* Return a symbolic value for the swidth of FONT. */
1727 static INLINE Lisp_Object
1728 xlfd_symbolic_swidth (font
)
1729 struct font_name
*font
;
1731 return xlfd_symbolic_value (swidth_table
, DIM (swidth_table
),
1732 font
, XLFD_SWIDTH
, Qnormal
);
1736 /* Look up the entry of SYMBOL in the vector TABLE which has DIM
1737 entries. Value is a pointer to the matching table entry or null if
1738 no element of TABLE contains SYMBOL. */
1740 static struct table_entry
*
1741 face_value (table
, dim
, symbol
)
1742 struct table_entry
*table
;
1748 xassert (SYMBOLP (symbol
));
1750 for (i
= 0; i
< dim
; ++i
)
1751 if (EQ (*table
[i
].symbol
, symbol
))
1754 return i
< dim
? table
+ i
: NULL
;
1758 /* Return a numeric value for SYMBOL in the vector TABLE which has DIM
1759 entries. Value is -1 if SYMBOL is not found in TABLE. */
1762 face_numeric_value (table
, dim
, symbol
)
1763 struct table_entry
*table
;
1767 struct table_entry
*p
= face_value (table
, dim
, symbol
);
1768 return p
? p
->numeric
: -1;
1772 /* Return a numeric value representing the weight specified by Lisp
1773 symbol WEIGHT. Value is one of the enumerators of enum
1777 face_numeric_weight (weight
)
1780 return face_numeric_value (weight_table
, DIM (weight_table
), weight
);
1784 /* Return a numeric value representing the slant specified by Lisp
1785 symbol SLANT. Value is one of the enumerators of enum xlfd_slant. */
1788 face_numeric_slant (slant
)
1791 return face_numeric_value (slant_table
, DIM (slant_table
), slant
);
1795 /* Return a numeric value representing the swidth specified by Lisp
1796 symbol WIDTH. Value is one of the enumerators of enum xlfd_swidth. */
1799 face_numeric_swidth (width
)
1802 return face_numeric_value (swidth_table
, DIM (swidth_table
), width
);
1806 #ifdef HAVE_X_WINDOWS
1808 /* Return non-zero if FONT is the name of a fixed-pitch font. */
1812 struct font_name
*font
;
1814 /* Function split_font_name converts fields to lower-case, so there
1815 is no need to use tolower here. */
1816 return *font
->fields
[XLFD_SPACING
] != 'p';
1820 /* Return the point size of FONT on frame F, measured in 1/10 pt.
1822 The actual height of the font when displayed on F depends on the
1823 resolution of both the font and frame. For example, a 10pt font
1824 designed for a 100dpi display will display larger than 10pt on a
1825 75dpi display. (It's not unusual to use fonts not designed for the
1826 display one is using. For example, some intlfonts are available in
1827 72dpi versions, only.)
1829 Value is the real point size of FONT on frame F, or 0 if it cannot
1833 xlfd_point_size (f
, font
)
1835 struct font_name
*font
;
1837 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
1838 double font_resy
= atoi (font
->fields
[XLFD_RESY
]);
1839 double font_pt
= atoi (font
->fields
[XLFD_POINT_SIZE
]);
1842 if (font_resy
== 0 || font_pt
== 0)
1845 real_pt
= (font_resy
/ resy
) * font_pt
+ 0.5;
1851 /* Split XLFD font name FONT->name destructively into NUL-terminated,
1852 lower-case fields in FONT->fields. NUMERIC_P non-zero means
1853 compute numeric values for fields XLFD_POINT_SIZE, XLFD_SWIDTH,
1854 XLFD_RESY, XLFD_SLANT, and XLFD_WEIGHT in FONT->numeric. Value is
1855 zero if the font name doesn't have the format we expect. The
1856 expected format is a font name that starts with a `-' and has
1857 XLFD_LAST fields separated by `-'. (The XLFD specification allows
1858 forms of font names where certain field contents are enclosed in
1859 square brackets. We don't support that, for now. */
1862 split_font_name (f
, font
, numeric_p
)
1864 struct font_name
*font
;
1870 if (*font
->name
== '-')
1872 char *p
= xstrlwr (font
->name
) + 1;
1874 while (i
< XLFD_LAST
)
1876 font
->fields
[i
] = p
;
1879 while (*p
&& *p
!= '-')
1889 success_p
= i
== XLFD_LAST
;
1891 /* If requested, and font name was in the expected format,
1892 compute numeric values for some fields. */
1893 if (numeric_p
&& success_p
)
1895 font
->numeric
[XLFD_POINT_SIZE
] = xlfd_point_size (f
, font
);
1896 font
->numeric
[XLFD_RESY
] = atoi (font
->fields
[XLFD_RESY
]);
1897 font
->numeric
[XLFD_SLANT
] = xlfd_numeric_slant (font
);
1898 font
->numeric
[XLFD_WEIGHT
] = xlfd_numeric_weight (font
);
1899 font
->numeric
[XLFD_SWIDTH
] = xlfd_numeric_swidth (font
);
1906 /* Build an XLFD font name from font name fields in FONT. Value is a
1907 pointer to the font name, which is allocated via xmalloc. */
1910 build_font_name (font
)
1911 struct font_name
*font
;
1915 char *font_name
= (char *) xmalloc (size
);
1916 int total_length
= 0;
1918 for (i
= 0; i
< XLFD_LAST
; ++i
)
1920 /* Add 1 because of the leading `-'. */
1921 int len
= strlen (font
->fields
[i
]) + 1;
1923 /* Reallocate font_name if necessary. Add 1 for the final
1925 if (total_length
+ len
+ 1 >= size
)
1927 int new_size
= max (2 * size
, size
+ len
+ 1);
1928 int sz
= new_size
* sizeof *font_name
;
1929 font_name
= (char *) xrealloc (font_name
, sz
);
1933 font_name
[total_length
] = '-';
1934 bcopy (font
->fields
[i
], font_name
+ total_length
+ 1, len
- 1);
1935 total_length
+= len
;
1938 font_name
[total_length
] = 0;
1943 /* Free an array FONTS of N font_name structures. This frees FONTS
1944 itself and all `name' fields in its elements. */
1947 free_font_names (fonts
, n
)
1948 struct font_name
*fonts
;
1952 xfree (fonts
[--n
].name
);
1957 /* Sort vector FONTS of font_name structures which contains NFONTS
1958 elements using qsort and comparison function CMPFN. F is the frame
1959 on which the fonts will be used. The global variable font_frame
1960 is temporarily set to F to make it available in CMPFN. */
1963 sort_fonts (f
, fonts
, nfonts
, cmpfn
)
1965 struct font_name
*fonts
;
1967 int (*cmpfn
) P_ ((const void *, const void *));
1970 qsort (fonts
, nfonts
, sizeof *fonts
, cmpfn
);
1975 /* Get fonts matching PATTERN on frame F. If F is null, use the first
1976 display in x_display_list. FONTS is a pointer to a vector of
1977 NFONTS font_name structures. TRY_ALTERNATIVES_P non-zero means try
1978 alternative patterns from Valternate_fontname_alist if no fonts are
1979 found matching PATTERN. SCALABLE_FONTS_P non-zero means include
1982 For all fonts found, set FONTS[i].name to the name of the font,
1983 allocated via xmalloc, and split font names into fields. Ignore
1984 fonts that we can't parse. Value is the number of fonts found.
1986 This is similar to x_list_fonts. The differences are:
1988 1. It avoids consing.
1989 2. It never calls XLoadQueryFont. */
1992 x_face_list_fonts (f
, pattern
, fonts
, nfonts
, try_alternatives_p
,
1996 struct font_name
*fonts
;
1997 int nfonts
, try_alternatives_p
;
1998 int scalable_fonts_p
;
2000 Display
*dpy
= f
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
2004 /* Get the list of fonts matching PATTERN from the X server. */
2006 names
= XListFonts (dpy
, pattern
, nfonts
, &n
);
2011 /* Make a copy of the font names we got from X, and
2012 split them into fields. */
2013 for (i
= j
= 0; i
< n
; ++i
)
2015 /* Make a copy of the font name. */
2016 fonts
[j
].name
= xstrdup (names
[i
]);
2018 /* Ignore fonts having a name that we can't parse. */
2019 if (!split_font_name (f
, fonts
+ j
, 1))
2020 xfree (fonts
[j
].name
);
2021 else if (font_scalable_p (fonts
+ j
))
2024 if (!scalable_fonts_p
2025 || !may_use_scalable_font_p (fonts
+ j
, names
[i
]))
2026 xfree (fonts
[j
].name
);
2029 #else /* !SCALABLE_FONTS */
2030 /* Always ignore scalable fonts. */
2031 xfree (fonts
[j
].name
);
2032 #endif /* !SCALABLE_FONTS */
2040 /* Free font names. */
2042 XFreeFontNames (names
);
2047 /* If no fonts found, try patterns from Valternate_fontname_alist. */
2048 if (n
== 0 && try_alternatives_p
)
2050 Lisp_Object list
= Valternate_fontname_alist
;
2052 while (CONSP (list
))
2054 Lisp_Object entry
= XCAR (list
);
2056 && STRINGP (XCAR (entry
))
2057 && strcmp (XSTRING (XCAR (entry
))->data
, pattern
) == 0)
2064 Lisp_Object patterns
= XCAR (list
);
2067 while (CONSP (patterns
)
2068 /* If list is screwed up, give up. */
2069 && (name
= XCAR (patterns
),
2071 /* Ignore patterns equal to PATTERN because we tried that
2072 already with no success. */
2073 && (strcmp (XSTRING (name
)->data
, pattern
) == 0
2074 || (n
= x_face_list_fonts (f
, XSTRING (name
)->data
,
2078 patterns
= XCDR (patterns
);
2086 /* Determine the first font matching PATTERN on frame F. Return in
2087 *FONT the matching font name, split into fields. Value is non-zero
2088 if a match was found. */
2091 first_font_matching (f
, pattern
, font
)
2094 struct font_name
*font
;
2097 struct font_name
*fonts
;
2099 fonts
= (struct font_name
*) xmalloc (nfonts
* sizeof *fonts
);
2100 nfonts
= x_face_list_fonts (f
, pattern
, fonts
, nfonts
, 1, 0);
2104 bcopy (&fonts
[0], font
, sizeof *font
);
2106 fonts
[0].name
= NULL
;
2107 free_font_names (fonts
, nfonts
);
2114 /* Determine fonts matching PATTERN on frame F. Sort resulting fonts
2115 using comparison function CMPFN. Value is the number of fonts
2116 found. If value is non-zero, *FONTS is set to a vector of
2117 font_name structures allocated from the heap containing matching
2118 fonts. Each element of *FONTS contains a name member that is also
2119 allocated from the heap. Font names in these structures are split
2120 into fields. Use free_font_names to free such an array. */
2123 sorted_font_list (f
, pattern
, cmpfn
, fonts
)
2126 int (*cmpfn
) P_ ((const void *, const void *));
2127 struct font_name
**fonts
;
2131 /* Get the list of fonts matching pattern. 100 should suffice. */
2132 nfonts
= DEFAULT_FONT_LIST_LIMIT
;
2133 if (INTEGERP (Vfont_list_limit
) && XINT (Vfont_list_limit
) > 0)
2134 nfonts
= XFASTINT (Vfont_list_limit
);
2136 *fonts
= (struct font_name
*) xmalloc (nfonts
* sizeof **fonts
);
2138 nfonts
= x_face_list_fonts (f
, pattern
, *fonts
, nfonts
, 1, 1);
2140 nfonts
= x_face_list_fonts (f
, pattern
, *fonts
, nfonts
, 1, 0);
2143 /* Sort the resulting array and return it in *FONTS. If no
2144 fonts were found, make sure to set *FONTS to null. */
2146 sort_fonts (f
, *fonts
, nfonts
, cmpfn
);
2157 /* Compare two font_name structures *A and *B. Value is analogous to
2158 strcmp. Sort order is given by the global variable
2159 font_sort_order. Font names are sorted so that, everything else
2160 being equal, fonts with a resolution closer to that of the frame on
2161 which they are used are listed first. The global variable
2162 font_frame is the frame on which we operate. */
2165 cmp_font_names (a
, b
)
2168 struct font_name
*x
= (struct font_name
*) a
;
2169 struct font_name
*y
= (struct font_name
*) b
;
2172 /* All strings have been converted to lower-case by split_font_name,
2173 so we can use strcmp here. */
2174 cmp
= strcmp (x
->fields
[XLFD_FAMILY
], y
->fields
[XLFD_FAMILY
]);
2179 for (i
= 0; i
< DIM (font_sort_order
) && cmp
== 0; ++i
)
2181 int j
= font_sort_order
[i
];
2182 cmp
= x
->numeric
[j
] - y
->numeric
[j
];
2187 /* Everything else being equal, we prefer fonts with an
2188 y-resolution closer to that of the frame. */
2189 int resy
= FRAME_X_DISPLAY_INFO (font_frame
)->resy
;
2190 int x_resy
= x
->numeric
[XLFD_RESY
];
2191 int y_resy
= y
->numeric
[XLFD_RESY
];
2192 cmp
= abs (resy
- x_resy
) - abs (resy
- y_resy
);
2200 /* Get a sorted list of fonts of family FAMILY on frame F. If PATTERN
2201 is non-null list fonts matching that pattern. Otherwise, if
2202 REGISTRY_AND_ENCODING is non-null return only fonts with that
2203 registry and encoding, otherwise return fonts of any registry and
2204 encoding. Set *FONTS to a vector of font_name structures allocated
2205 from the heap containing the fonts found. Value is the number of
2209 font_list (f
, pattern
, family
, registry_and_encoding
, fonts
)
2213 char *registry_and_encoding
;
2214 struct font_name
**fonts
;
2216 if (pattern
== NULL
)
2221 if (registry_and_encoding
== NULL
)
2222 registry_and_encoding
= "*";
2224 pattern
= (char *) alloca (strlen (family
)
2225 + strlen (registry_and_encoding
)
2227 if (index (family
, '-'))
2228 sprintf (pattern
, "-%s-*-%s", family
, registry_and_encoding
);
2230 sprintf (pattern
, "-*-%s-*-%s", family
, registry_and_encoding
);
2233 return sorted_font_list (f
, pattern
, cmp_font_names
, fonts
);
2237 /* Remove elements from LIST whose cars are `equal'. Called from
2238 x-family-fonts and x-font-family-list to remove duplicate font
2242 remove_duplicates (list
)
2245 Lisp_Object tail
= list
;
2247 while (!NILP (tail
) && !NILP (XCDR (tail
)))
2249 Lisp_Object next
= XCDR (tail
);
2250 if (!NILP (Fequal (XCAR (next
), XCAR (tail
))))
2251 XCDR (tail
) = XCDR (next
);
2258 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
2259 "Return a list of available fonts of family FAMILY on FRAME.\n\
2260 If FAMILY is omitted or nil, list all families.\n\
2261 Otherwise, FAMILY must be a string, possibly containing wildcards\n\
2263 If FRAME is omitted or nil, use the selected frame.\n\
2264 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT\n\
2265 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].\n\
2266 FAMILY is the font family name. POINT-SIZE is the size of the\n\
2267 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the\n\
2268 width, weight and slant of the font. These symbols are the same as for\n\
2269 face attributes. FIXED-P is non-nil if the font is fixed-pitch.\n\
2270 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string\n\
2271 giving the registry and encoding of the font.\n\
2272 The result list is sorted according to the current setting of\n\
2273 the face font sort order.")
2275 Lisp_Object family
, frame
;
2277 struct frame
*f
= check_x_frame (frame
);
2278 struct font_name
*fonts
;
2281 struct gcpro gcpro1
;
2282 char *family_pattern
;
2285 family_pattern
= "*";
2288 CHECK_STRING (family
, 1);
2289 family_pattern
= LSTRDUPA (family
);
2294 nfonts
= font_list (f
, NULL
, family_pattern
, NULL
, &fonts
);
2295 for (i
= nfonts
- 1; i
>= 0; --i
)
2297 Lisp_Object v
= Fmake_vector (make_number (8), Qnil
);
2300 #define ASET(VECTOR, IDX, VAL) (XVECTOR (VECTOR)->contents[IDX] = (VAL))
2302 ASET (v
, 0, build_string (fonts
[i
].fields
[XLFD_FAMILY
]));
2303 ASET (v
, 1, xlfd_symbolic_swidth (fonts
+ i
));
2304 ASET (v
, 2, make_number (xlfd_point_size (f
, fonts
+ i
)));
2305 ASET (v
, 3, xlfd_symbolic_weight (fonts
+ i
));
2306 ASET (v
, 4, xlfd_symbolic_slant (fonts
+ i
));
2307 ASET (v
, 5, xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
);
2308 tem
= build_font_name (fonts
+ i
);
2309 ASET (v
, 6, build_string (tem
));
2310 sprintf (tem
, "%s-%s", fonts
[i
].fields
[XLFD_REGISTRY
],
2311 fonts
[i
].fields
[XLFD_ENCODING
]);
2312 ASET (v
, 7, build_string (tem
));
2315 result
= Fcons (v
, result
);
2320 remove_duplicates (result
);
2321 free_font_names (fonts
, nfonts
);
2327 DEFUN ("x-font-family-list", Fx_font_family_list
, Sx_font_family_list
,
2329 "Return a list of available font families on FRAME.\n\
2330 If FRAME is omitted or nil, use the selected frame.\n\
2331 Value is a list of conses (FAMILY . FIXED-P) where FAMILY\n\
2332 is a font family, and FIXED-P is non-nil if fonts of that family\n\
2337 struct frame
*f
= check_x_frame (frame
);
2339 struct font_name
*fonts
;
2341 struct gcpro gcpro1
;
2342 int count
= specpdl_ptr
- specpdl
;
2345 /* Let's consider all fonts. Increase the limit for matching
2346 fonts until we have them all. */
2349 specbind (intern ("font-list-limit"), make_number (limit
));
2350 nfonts
= font_list (f
, NULL
, "*", NULL
, &fonts
);
2352 if (nfonts
== limit
)
2354 free_font_names (fonts
, nfonts
);
2363 for (i
= nfonts
- 1; i
>= 0; --i
)
2364 result
= Fcons (Fcons (build_string (fonts
[i
].fields
[XLFD_FAMILY
]),
2365 xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
),
2368 remove_duplicates (result
);
2369 free_font_names (fonts
, nfonts
);
2371 return unbind_to (count
, result
);
2375 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
2376 "Return a list of the names of available fonts matching PATTERN.\n\
2377 If optional arguments FACE and FRAME are specified, return only fonts\n\
2378 the same size as FACE on FRAME.\n\
2379 PATTERN is a string, perhaps with wildcard characters;\n\
2380 the * character matches any substring, and\n\
2381 the ? character matches any single character.\n\
2382 PATTERN is case-insensitive.\n\
2383 FACE is a face name--a symbol.\n\
2385 The return value is a list of strings, suitable as arguments to\n\
2388 Fonts Emacs can't use may or may not be excluded\n\
2389 even if they match PATTERN and FACE.\n\
2390 The optional fourth argument MAXIMUM sets a limit on how many\n\
2391 fonts to match. The first MAXIMUM fonts are reported.\n\
2392 The optional fifth argument WIDTH, if specified, is a number of columns\n\
2393 occupied by a character of a font. In that case, return only fonts\n\
2394 the WIDTH times as wide as FACE on FRAME.")
2395 (pattern
, face
, frame
, maximum
, width
)
2396 Lisp_Object pattern
, face
, frame
, maximum
, width
;
2403 CHECK_STRING (pattern
, 0);
2409 CHECK_NATNUM (maximum
, 0);
2410 maxnames
= XINT (maximum
);
2414 CHECK_NUMBER (width
, 4);
2416 /* We can't simply call check_x_frame because this function may be
2417 called before any frame is created. */
2418 f
= frame_or_selected_frame (frame
, 2);
2421 /* Perhaps we have not yet created any frame. */
2426 /* Determine the width standard for comparison with the fonts we find. */
2432 /* This is of limited utility since it works with character
2433 widths. Keep it for compatibility. --gerd. */
2434 int face_id
= lookup_named_face (f
, face
, CHARSET_ASCII
);
2435 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2438 size
= face
->font
->max_bounds
.width
;
2440 size
= FRAME_FONT (f
)->max_bounds
.width
;
2443 size
*= XINT (width
);
2447 Lisp_Object args
[2];
2449 args
[0] = x_list_fonts (f
, pattern
, size
, maxnames
);
2451 /* We don't have to check fontsets. */
2453 args
[1] = list_fontsets (f
, pattern
, size
);
2454 return Fnconc (2, args
);
2458 #endif /* HAVE_X_WINDOWS */
2462 /***********************************************************************
2464 ***********************************************************************/
2466 /* Access face attributes of face FACE, a Lisp vector. */
2468 #define LFACE_FAMILY(LFACE) \
2469 XVECTOR (LFACE)->contents[LFACE_FAMILY_INDEX]
2470 #define LFACE_HEIGHT(LFACE) \
2471 XVECTOR (LFACE)->contents[LFACE_HEIGHT_INDEX]
2472 #define LFACE_WEIGHT(LFACE) \
2473 XVECTOR (LFACE)->contents[LFACE_WEIGHT_INDEX]
2474 #define LFACE_SLANT(LFACE) \
2475 XVECTOR (LFACE)->contents[LFACE_SLANT_INDEX]
2476 #define LFACE_UNDERLINE(LFACE) \
2477 XVECTOR (LFACE)->contents[LFACE_UNDERLINE_INDEX]
2478 #define LFACE_INVERSE(LFACE) \
2479 XVECTOR (LFACE)->contents[LFACE_INVERSE_INDEX]
2480 #define LFACE_FOREGROUND(LFACE) \
2481 XVECTOR (LFACE)->contents[LFACE_FOREGROUND_INDEX]
2482 #define LFACE_BACKGROUND(LFACE) \
2483 XVECTOR (LFACE)->contents[LFACE_BACKGROUND_INDEX]
2484 #define LFACE_STIPPLE(LFACE) \
2485 XVECTOR (LFACE)->contents[LFACE_STIPPLE_INDEX]
2486 #define LFACE_SWIDTH(LFACE) \
2487 XVECTOR (LFACE)->contents[LFACE_SWIDTH_INDEX]
2488 #define LFACE_OVERLINE(LFACE) \
2489 XVECTOR (LFACE)->contents[LFACE_OVERLINE_INDEX]
2490 #define LFACE_STRIKE_THROUGH(LFACE) \
2491 XVECTOR (LFACE)->contents[LFACE_STRIKE_THROUGH_INDEX]
2492 #define LFACE_BOX(LFACE) \
2493 XVECTOR (LFACE)->contents[LFACE_BOX_INDEX]
2495 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
2496 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
2498 #define LFACEP(LFACE) \
2500 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \
2501 && EQ (XVECTOR (LFACE)->contents[0], Qface))
2506 /* Check consistency of Lisp face attribute vector ATTRS. */
2509 check_lface_attrs (attrs
)
2512 xassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
2513 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
2514 xassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
2515 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
2516 xassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
2517 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
]));
2518 xassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
2519 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
2520 xassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
2521 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
2522 xassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
2523 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
2524 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]));
2525 xassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
2526 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
2527 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
2528 xassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
2529 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
2530 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
2531 xassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
2532 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
2533 || STRINGP (attrs
[LFACE_BOX_INDEX
])
2534 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
2535 || CONSP (attrs
[LFACE_BOX_INDEX
]));
2536 xassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
2537 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
2538 xassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
2539 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
2540 xassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
2541 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
2542 #ifdef HAVE_WINDOW_SYSTEM
2543 xassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
2544 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
2545 || !NILP (Fpixmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
2550 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
2558 xassert (LFACEP (lface
));
2559 check_lface_attrs (XVECTOR (lface
)->contents
);
2563 #else /* GLYPH_DEBUG == 0 */
2565 #define check_lface_attrs(attrs) (void) 0
2566 #define check_lface(lface) (void) 0
2568 #endif /* GLYPH_DEBUG == 0 */
2571 /* Return the face definition of FACE_NAME on frame F. F null means
2572 return the global definition. FACE_NAME may be a string or a
2573 symbol (apparently Emacs 20.2 allows strings as face names in face
2574 text properties; ediff uses that). If FACE_NAME is an alias for
2575 another face, return that face's definition. If SIGNAL_P is
2576 non-zero, signal an error if FACE_NAME is not a valid face name.
2577 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
2580 static INLINE Lisp_Object
2581 lface_from_face_name (f
, face_name
, signal_p
)
2583 Lisp_Object face_name
;
2586 Lisp_Object lface
, alias
;
2588 if (STRINGP (face_name
))
2589 face_name
= intern (XSTRING (face_name
)->data
);
2591 /* If FACE_NAME is an alias for another face, return the definition
2592 of the aliased face. */
2593 alias
= Fget (face_name
, Qface_alias
);
2598 lface
= assq_no_quit (face_name
, f
->face_alist
);
2600 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
2603 lface
= XCDR (lface
);
2605 signal_error ("Invalid face", face_name
);
2607 check_lface (lface
);
2612 /* Get face attributes of face FACE_NAME from frame-local faces on
2613 frame F. Store the resulting attributes in ATTRS which must point
2614 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
2615 is non-zero, signal an error if FACE_NAME does not name a face.
2616 Otherwise, value is zero if FACE_NAME is not a face. */
2619 get_lface_attributes (f
, face_name
, attrs
, signal_p
)
2621 Lisp_Object face_name
;
2628 lface
= lface_from_face_name (f
, face_name
, signal_p
);
2631 bcopy (XVECTOR (lface
)->contents
, attrs
,
2632 LFACE_VECTOR_SIZE
* sizeof *attrs
);
2642 /* Non-zero if all attributes in face attribute vector ATTRS are
2643 specified, i.e. are non-nil. */
2646 lface_fully_specified_p (attrs
)
2651 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2652 if (UNSPECIFIEDP (attrs
[i
]))
2655 return i
== LFACE_VECTOR_SIZE
;
2659 #ifdef HAVE_X_WINDOWS
2661 /* Set font-related attributes of Lisp face LFACE from XLFD font name
2662 FONT_NAME. If FORCE_P is zero, set only unspecified attributes of
2663 LFACE. Ignore fields of FONT_NAME containing wildcards. Value is
2664 zero if not successful because FONT_NAME was not in a valid format.
2665 A valid format is one that is suitable for split_font_name, see the
2669 set_lface_from_font_name (f
, lface
, font_name
, force_p
)
2675 struct font_name font
;
2678 int free_font_name_p
= 0;
2680 /* If FONT_NAME contains wildcards, use the first matching font. */
2681 if (index (font_name
, '*') || index (font_name
, '?'))
2683 if (!first_font_matching (f
, font_name
, &font
))
2685 free_font_name_p
= 1;
2689 font
.name
= STRDUPA (font_name
);
2690 if (!split_font_name (f
, &font
, 1))
2692 /* The font name may be something like `6x13'. Make
2693 sure we use the full name. */
2694 struct font_info
*font_info
;
2697 font_info
= fs_load_font (f
, FRAME_X_FONT_TABLE (f
),
2698 CHARSET_ASCII
, font_name
, -1);
2704 font
.name
= STRDUPA (font_info
->full_name
);
2705 split_font_name (f
, &font
, 1);
2708 /* FONT_NAME should not be a fontset name, here. */
2709 xassert (xstricmp (font
.fields
[XLFD_REGISTRY
], "fontset") != 0);
2712 /* Set attributes only if unspecified, otherwise face defaults for
2713 new frames would never take effect. */
2715 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
2717 buffer
= (char *) alloca (strlen (font
.fields
[XLFD_FAMILY
])
2718 + strlen (font
.fields
[XLFD_FOUNDRY
])
2720 sprintf (buffer
, "%s-%s", font
.fields
[XLFD_FOUNDRY
],
2721 font
.fields
[XLFD_FAMILY
]);
2722 LFACE_FAMILY (lface
) = build_string (buffer
);
2725 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
2727 pt
= xlfd_point_size (f
, &font
);
2729 LFACE_HEIGHT (lface
) = make_number (pt
);
2732 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
2733 LFACE_SWIDTH (lface
) = xlfd_symbolic_swidth (&font
);
2735 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
2736 LFACE_WEIGHT (lface
) = xlfd_symbolic_weight (&font
);
2738 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
2739 LFACE_SLANT (lface
) = xlfd_symbolic_slant (&font
);
2741 if (free_font_name_p
)
2747 #endif /* HAVE_X_WINDOWS */
2750 /* Merge two Lisp face attribute vectors FROM and TO and store the
2751 resulting attributes in TO. Every non-nil attribute of FROM
2752 overrides the corresponding attribute of TO. */
2755 merge_face_vectors (from
, to
)
2756 Lisp_Object
*from
, *to
;
2759 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2760 if (!UNSPECIFIEDP (from
[i
]))
2765 /* Given a Lisp face attribute vector TO and a Lisp object PROP that
2766 is a face property, determine the resulting face attributes on
2767 frame F, and store them in TO. PROP may be a single face
2768 specification or a list of such specifications. Each face
2769 specification can be
2771 1. A symbol or string naming a Lisp face.
2773 2. A property list of the form (KEYWORD VALUE ...) where each
2774 KEYWORD is a face attribute name, and value is an appropriate value
2777 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
2778 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
2779 for compatibility with 20.2.
2781 Face specifications earlier in lists take precedence over later
2785 merge_face_vector_with_property (f
, to
, prop
)
2792 Lisp_Object first
= XCAR (prop
);
2794 if (EQ (first
, Qforeground_color
)
2795 || EQ (first
, Qbackground_color
))
2797 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
2798 . COLOR). COLOR must be a string. */
2799 Lisp_Object color_name
= XCDR (prop
);
2800 Lisp_Object color
= first
;
2802 if (STRINGP (color_name
))
2804 if (EQ (color
, Qforeground_color
))
2805 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
2807 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
2810 add_to_log ("Invalid face color", color_name
, Qnil
);
2812 else if (SYMBOLP (first
)
2813 && *XSYMBOL (first
)->name
->data
== ':')
2815 /* Assume this is the property list form. */
2816 while (CONSP (prop
) && CONSP (XCDR (prop
)))
2818 Lisp_Object keyword
= XCAR (prop
);
2819 Lisp_Object value
= XCAR (XCDR (prop
));
2821 if (EQ (keyword
, QCfamily
))
2823 if (STRINGP (value
))
2824 to
[LFACE_FAMILY_INDEX
] = value
;
2826 add_to_log ("Illegal face font family", value
, Qnil
);
2828 else if (EQ (keyword
, QCheight
))
2830 if (INTEGERP (value
))
2831 to
[LFACE_HEIGHT_INDEX
] = value
;
2833 add_to_log ("Illegal face font height", value
, Qnil
);
2835 else if (EQ (keyword
, QCweight
))
2838 && face_numeric_weight (value
) >= 0)
2839 to
[LFACE_WEIGHT_INDEX
] = value
;
2841 add_to_log ("Illegal face weight", value
, Qnil
);
2843 else if (EQ (keyword
, QCslant
))
2846 && face_numeric_slant (value
) >= 0)
2847 to
[LFACE_SLANT_INDEX
] = value
;
2849 add_to_log ("Illegal face slant", value
, Qnil
);
2851 else if (EQ (keyword
, QCunderline
))
2856 to
[LFACE_UNDERLINE_INDEX
] = value
;
2858 add_to_log ("Illegal face underline", value
, Qnil
);
2860 else if (EQ (keyword
, QCoverline
))
2865 to
[LFACE_OVERLINE_INDEX
] = value
;
2867 add_to_log ("Illegal face overline", value
, Qnil
);
2869 else if (EQ (keyword
, QCstrike_through
))
2874 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
2876 add_to_log ("Illegal face strike-through", value
, Qnil
);
2878 else if (EQ (keyword
, QCbox
))
2881 value
= make_number (1);
2882 if (INTEGERP (value
)
2886 to
[LFACE_BOX_INDEX
] = value
;
2888 add_to_log ("Illegal face box", value
, Qnil
);
2890 else if (EQ (keyword
, QCinverse_video
)
2891 || EQ (keyword
, QCreverse_video
))
2893 if (EQ (value
, Qt
) || NILP (value
))
2894 to
[LFACE_INVERSE_INDEX
] = value
;
2896 add_to_log ("Illegal face inverse-video", value
, Qnil
);
2898 else if (EQ (keyword
, QCforeground
))
2900 if (STRINGP (value
))
2901 to
[LFACE_FOREGROUND_INDEX
] = value
;
2903 add_to_log ("Illegal face foreground", value
, Qnil
);
2905 else if (EQ (keyword
, QCbackground
))
2907 if (STRINGP (value
))
2908 to
[LFACE_BACKGROUND_INDEX
] = value
;
2910 add_to_log ("Illegal face background", value
, Qnil
);
2912 else if (EQ (keyword
, QCstipple
))
2914 #ifdef HAVE_X_WINDOWS
2915 Lisp_Object pixmap_p
= Fpixmap_spec_p (value
);
2916 if (!NILP (pixmap_p
))
2917 to
[LFACE_STIPPLE_INDEX
] = value
;
2919 add_to_log ("Illegal face stipple", value
, Qnil
);
2922 else if (EQ (keyword
, QCwidth
))
2925 && face_numeric_swidth (value
) >= 0)
2926 to
[LFACE_SWIDTH_INDEX
] = value
;
2928 add_to_log ("Illegal face width", value
, Qnil
);
2931 add_to_log ("Invalid attribute %s in face property",
2934 prop
= XCDR (XCDR (prop
));
2939 /* This is a list of face specs. Specifications at the
2940 beginning of the list take precedence over later
2941 specifications, so we have to merge starting with the
2942 last specification. */
2943 Lisp_Object next
= XCDR (prop
);
2945 merge_face_vector_with_property (f
, to
, next
);
2946 merge_face_vector_with_property (f
, to
, first
);
2951 /* PROP ought to be a face name. */
2952 Lisp_Object lface
= lface_from_face_name (f
, prop
, 0);
2954 add_to_log ("Invalid face text property value: %s", prop
, Qnil
);
2956 merge_face_vectors (XVECTOR (lface
)->contents
, to
);
2961 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
2962 Sinternal_make_lisp_face
, 1, 2, 0,
2963 "Make FACE, a symbol, a Lisp face with all attributes nil.\n\
2964 If FACE was not known as a face before, create a new one.\n\
2965 If optional argument FRAME is specified, make a frame-local face\n\
2966 for that frame. Otherwise operate on the global face definition.\n\
2967 Value is a vector of face attributes.")
2969 Lisp_Object face
, frame
;
2971 Lisp_Object global_lface
, lface
;
2975 CHECK_SYMBOL (face
, 0);
2976 global_lface
= lface_from_face_name (NULL
, face
, 0);
2980 CHECK_LIVE_FRAME (frame
, 1);
2982 lface
= lface_from_face_name (f
, face
, 0);
2985 f
= NULL
, lface
= Qnil
;
2987 /* Add a global definition if there is none. */
2988 if (NILP (global_lface
))
2990 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2992 XVECTOR (global_lface
)->contents
[0] = Qface
;
2993 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
2994 Vface_new_frame_defaults
);
2996 /* Assign the new Lisp face a unique ID. The mapping from Lisp
2997 face id to Lisp face is given by the vector lface_id_to_name.
2998 The mapping from Lisp face to Lisp face id is given by the
2999 property `face' of the Lisp face name. */
3000 if (next_lface_id
== lface_id_to_name_size
)
3002 int new_size
= max (50, 2 * lface_id_to_name_size
);
3003 int sz
= new_size
* sizeof *lface_id_to_name
;
3004 lface_id_to_name
= (Lisp_Object
*) xrealloc (lface_id_to_name
, sz
);
3005 lface_id_to_name_size
= new_size
;
3008 lface_id_to_name
[next_lface_id
] = face
;
3009 Fput (face
, Qface
, make_number (next_lface_id
));
3013 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3014 XVECTOR (global_lface
)->contents
[i
] = Qunspecified
;
3016 /* Add a frame-local definition. */
3021 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
3023 XVECTOR (lface
)->contents
[0] = Qface
;
3024 f
->face_alist
= Fcons (Fcons (face
, lface
), f
->face_alist
);
3027 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3028 XVECTOR (lface
)->contents
[i
] = Qunspecified
;
3031 lface
= global_lface
;
3033 xassert (LFACEP (lface
));
3034 check_lface (lface
);
3039 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
3040 Sinternal_lisp_face_p
, 1, 2, 0,
3041 "Return non-nil if FACE names a face.\n\
3042 If optional second parameter FRAME is non-nil, check for the\n\
3043 existence of a frame-local face with name FACE on that frame.\n\
3044 Otherwise check for the existence of a global face.")
3046 Lisp_Object face
, frame
;
3052 CHECK_LIVE_FRAME (frame
, 1);
3053 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3056 lface
= lface_from_face_name (NULL
, face
, 0);
3062 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
3063 Sinternal_copy_lisp_face
, 4, 4, 0,
3064 "Copy face FROM to TO.\n\
3065 If FRAME it t, copy the global face definition of FROM to the\n\
3066 global face definition of TO. Otherwise, copy the frame-local\n\
3067 definition of FROM on FRAME to the frame-local definition of TO\n\
3068 on NEW-FRAME, or FRAME if NEW-FRAME is nil.\n\
3071 (from
, to
, frame
, new_frame
)
3072 Lisp_Object from
, to
, frame
, new_frame
;
3074 Lisp_Object lface
, copy
;
3076 CHECK_SYMBOL (from
, 0);
3077 CHECK_SYMBOL (to
, 1);
3078 if (NILP (new_frame
))
3083 /* Copy global definition of FROM. We don't make copies of
3084 strings etc. because 20.2 didn't do it either. */
3085 lface
= lface_from_face_name (NULL
, from
, 1);
3086 copy
= Finternal_make_lisp_face (to
, Qnil
);
3090 /* Copy frame-local definition of FROM. */
3091 CHECK_LIVE_FRAME (frame
, 2);
3092 CHECK_LIVE_FRAME (new_frame
, 3);
3093 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
3094 copy
= Finternal_make_lisp_face (to
, new_frame
);
3097 bcopy (XVECTOR (lface
)->contents
, XVECTOR (copy
)->contents
,
3098 LFACE_VECTOR_SIZE
* sizeof (Lisp_Object
));
3104 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
3105 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
3106 "Set attribute ATTR of FACE to VALUE.\n\
3107 If optional argument FRAME is given, set the face attribute of face FACE\n\
3108 on that frame. If FRAME is t, set the attribute of the default for face\n\
3109 FACE (for new frames). If FRAME is omitted or nil, use the selected\n\
3111 (face
, attr
, value
, frame
)
3112 Lisp_Object face
, attr
, value
, frame
;
3115 Lisp_Object old_value
= Qnil
;
3116 int font_related_attr_p
= 0;
3118 CHECK_SYMBOL (face
, 0);
3119 CHECK_SYMBOL (attr
, 1);
3121 /* Set lface to the Lisp attribute vector of FACE. */
3123 lface
= lface_from_face_name (NULL
, face
, 1);
3127 frame
= selected_frame
;
3129 CHECK_LIVE_FRAME (frame
, 3);
3130 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3132 /* If a frame-local face doesn't exist yet, create one. */
3134 lface
= Finternal_make_lisp_face (face
, frame
);
3137 if (EQ (attr
, QCfamily
))
3139 if (!UNSPECIFIEDP (value
))
3141 CHECK_STRING (value
, 3);
3142 if (XSTRING (value
)->size
== 0)
3143 signal_error ("Invalid face family", value
);
3145 old_value
= LFACE_FAMILY (lface
);
3146 LFACE_FAMILY (lface
) = value
;
3147 font_related_attr_p
= 1;
3149 else if (EQ (attr
, QCheight
))
3151 if (!UNSPECIFIEDP (value
))
3153 CHECK_NUMBER (value
, 3);
3154 if (XINT (value
) <= 0)
3155 signal_error ("Invalid face height", value
);
3157 old_value
= LFACE_HEIGHT (lface
);
3158 LFACE_HEIGHT (lface
) = value
;
3159 font_related_attr_p
= 1;
3161 else if (EQ (attr
, QCweight
))
3163 if (!UNSPECIFIEDP (value
))
3165 CHECK_SYMBOL (value
, 3);
3166 if (face_numeric_weight (value
) < 0)
3167 signal_error ("Invalid face weight", value
);
3169 old_value
= LFACE_WEIGHT (lface
);
3170 LFACE_WEIGHT (lface
) = value
;
3171 font_related_attr_p
= 1;
3173 else if (EQ (attr
, QCslant
))
3175 if (!UNSPECIFIEDP (value
))
3177 CHECK_SYMBOL (value
, 3);
3178 if (face_numeric_slant (value
) < 0)
3179 signal_error ("Invalid face slant", value
);
3181 old_value
= LFACE_SLANT (lface
);
3182 LFACE_SLANT (lface
) = value
;
3183 font_related_attr_p
= 1;
3185 else if (EQ (attr
, QCunderline
))
3187 if (!UNSPECIFIEDP (value
))
3188 if ((SYMBOLP (value
)
3190 && !EQ (value
, Qnil
))
3191 /* Underline color. */
3193 && XSTRING (value
)->size
== 0))
3194 signal_error ("Invalid face underline", value
);
3196 old_value
= LFACE_UNDERLINE (lface
);
3197 LFACE_UNDERLINE (lface
) = value
;
3199 else if (EQ (attr
, QCoverline
))
3201 if (!UNSPECIFIEDP (value
))
3202 if ((SYMBOLP (value
)
3204 && !EQ (value
, Qnil
))
3205 /* Overline color. */
3207 && XSTRING (value
)->size
== 0))
3208 signal_error ("Invalid face overline", value
);
3210 old_value
= LFACE_OVERLINE (lface
);
3211 LFACE_OVERLINE (lface
) = value
;
3213 else if (EQ (attr
, QCstrike_through
))
3215 if (!UNSPECIFIEDP (value
))
3216 if ((SYMBOLP (value
)
3218 && !EQ (value
, Qnil
))
3219 /* Strike-through color. */
3221 && XSTRING (value
)->size
== 0))
3222 signal_error ("Invalid face strike-through", value
);
3224 old_value
= LFACE_STRIKE_THROUGH (lface
);
3225 LFACE_STRIKE_THROUGH (lface
) = value
;
3227 else if (EQ (attr
, QCbox
))
3231 /* Allow t meaning a simple box of width 1 in foreground color
3234 value
= make_number (1);
3236 if (UNSPECIFIEDP (value
))
3238 else if (NILP (value
))
3240 else if (INTEGERP (value
))
3241 valid_p
= XINT (value
) > 0;
3242 else if (STRINGP (value
))
3243 valid_p
= XSTRING (value
)->size
> 0;
3244 else if (CONSP (value
))
3260 if (EQ (k
, QCline_width
))
3262 if (!INTEGERP (v
) || XINT (v
) <= 0)
3265 else if (EQ (k
, QCcolor
))
3267 if (!STRINGP (v
) || XSTRING (v
)->size
== 0)
3270 else if (EQ (k
, QCstyle
))
3272 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
3279 valid_p
= NILP (tem
);
3285 signal_error ("Invalid face box", value
);
3287 old_value
= LFACE_BOX (lface
);
3288 LFACE_BOX (lface
) = value
;
3290 else if (EQ (attr
, QCinverse_video
)
3291 || EQ (attr
, QCreverse_video
))
3293 if (!UNSPECIFIEDP (value
))
3295 CHECK_SYMBOL (value
, 3);
3296 if (!EQ (value
, Qt
) && !NILP (value
))
3297 signal_error ("Invalid inverse-video face attribute value", value
);
3299 old_value
= LFACE_INVERSE (lface
);
3300 LFACE_INVERSE (lface
) = value
;
3302 else if (EQ (attr
, QCforeground
))
3304 if (!UNSPECIFIEDP (value
))
3306 /* Don't check for valid color names here because it depends
3307 on the frame (display) whether the color will be valid
3308 when the face is realized. */
3309 CHECK_STRING (value
, 3);
3310 if (XSTRING (value
)->size
== 0)
3311 signal_error ("Empty foreground color value", value
);
3313 old_value
= LFACE_FOREGROUND (lface
);
3314 LFACE_FOREGROUND (lface
) = value
;
3316 else if (EQ (attr
, QCbackground
))
3318 if (!UNSPECIFIEDP (value
))
3320 /* Don't check for valid color names here because it depends
3321 on the frame (display) whether the color will be valid
3322 when the face is realized. */
3323 CHECK_STRING (value
, 3);
3324 if (XSTRING (value
)->size
== 0)
3325 signal_error ("Empty background color value", value
);
3327 old_value
= LFACE_BACKGROUND (lface
);
3328 LFACE_BACKGROUND (lface
) = value
;
3330 else if (EQ (attr
, QCstipple
))
3332 #ifdef HAVE_X_WINDOWS
3333 if (!UNSPECIFIEDP (value
)
3335 && NILP (Fpixmap_spec_p (value
)))
3336 signal_error ("Invalid stipple attribute", value
);
3337 old_value
= LFACE_STIPPLE (lface
);
3338 LFACE_STIPPLE (lface
) = value
;
3339 #endif /* HAVE_X_WINDOWS */
3341 else if (EQ (attr
, QCwidth
))
3343 if (!UNSPECIFIEDP (value
))
3345 CHECK_SYMBOL (value
, 3);
3346 if (face_numeric_swidth (value
) < 0)
3347 signal_error ("Invalid face width", value
);
3349 old_value
= LFACE_SWIDTH (lface
);
3350 LFACE_SWIDTH (lface
) = value
;
3351 font_related_attr_p
= 1;
3353 else if (EQ (attr
, QCfont
))
3355 #ifdef HAVE_X_WINDOWS
3356 /* Set font-related attributes of the Lisp face from an
3360 CHECK_STRING (value
, 3);
3362 f
= SELECTED_FRAME ();
3364 f
= check_x_frame (frame
);
3366 if (!set_lface_from_font_name (f
, lface
, XSTRING (value
)->data
, 1))
3367 signal_error ("Invalid font name", value
);
3369 font_related_attr_p
= 1;
3370 #endif /* HAVE_X_WINDOWS */
3372 else if (EQ (attr
, QCbold
))
3374 old_value
= LFACE_WEIGHT (lface
);
3375 LFACE_WEIGHT (lface
) = NILP (value
) ? Qnormal
: Qbold
;
3376 font_related_attr_p
= 1;
3378 else if (EQ (attr
, QCitalic
))
3380 old_value
= LFACE_SLANT (lface
);
3381 LFACE_SLANT (lface
) = NILP (value
) ? Qnormal
: Qitalic
;
3382 font_related_attr_p
= 1;
3385 signal_error ("Invalid face attribute name", attr
);
3387 /* Changing a named face means that all realized faces depending on
3388 that face are invalid. Since we cannot tell which realized faces
3389 depend on the face, make sure they are all removed. This is done
3390 by incrementing face_change_count. The next call to
3391 init_iterator will then free realized faces. */
3393 && (EQ (attr
, QCfont
)
3394 || NILP (Fequal (old_value
, value
))))
3396 ++face_change_count
;
3397 ++windows_or_buffers_changed
;
3400 #ifdef HAVE_X_WINDOWS
3403 && !UNSPECIFIEDP (value
)
3404 && NILP (Fequal (old_value
, value
)))
3410 if (EQ (face
, Qdefault
))
3412 /* Changed font-related attributes of the `default' face are
3413 reflected in changed `font' frame parameters. */
3414 if (font_related_attr_p
3415 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
3416 set_font_frame_param (frame
, lface
);
3417 else if (EQ (attr
, QCforeground
))
3418 param
= Qforeground_color
;
3419 else if (EQ (attr
, QCbackground
))
3420 param
= Qbackground_color
;
3422 else if (EQ (face
, Qscroll_bar
))
3424 /* Changing the colors of `scroll-bar' sets frame parameters
3425 `scroll-bar-foreground' and `scroll-bar-background'. */
3426 if (EQ (attr
, QCforeground
))
3427 param
= Qscroll_bar_foreground
;
3428 else if (EQ (attr
, QCbackground
))
3429 param
= Qscroll_bar_background
;
3431 else if (EQ (face
, Qborder
))
3433 /* Changing background color of `border' sets frame parameter
3435 if (EQ (attr
, QCbackground
))
3436 param
= Qborder_color
;
3438 else if (EQ (face
, Qcursor
))
3440 /* Changing background color of `cursor' sets frame parameter
3442 if (EQ (attr
, QCbackground
))
3443 param
= Qcursor_color
;
3445 else if (EQ (face
, Qmouse
))
3447 /* Changing background color of `mouse' sets frame parameter
3449 if (EQ (attr
, QCbackground
))
3450 param
= Qmouse_color
;
3453 if (SYMBOLP (param
))
3454 Fmodify_frame_parameters (frame
, Fcons (Fcons (param
, value
), Qnil
));
3457 #endif /* HAVE_X_WINDOWS */
3463 #ifdef HAVE_X_WINDOWS
3465 /* Set the `font' frame parameter of FRAME according to `default' face
3466 attributes LFACE. */
3469 set_font_frame_param (frame
, lface
)
3470 Lisp_Object frame
, lface
;
3472 struct frame
*f
= XFRAME (frame
);
3473 Lisp_Object frame_font
;
3477 /* Get FRAME's font parameter. */
3478 frame_font
= Fassq (Qfont
, f
->param_alist
);
3479 xassert (CONSP (frame_font
) && STRINGP (XCDR (frame_font
)));
3480 frame_font
= XCDR (frame_font
);
3482 fontset
= fs_query_fontset (f
, XSTRING (frame_font
)->data
);
3485 /* Frame parameter is a fontset name. Modify the fontset so
3486 that all its fonts reflect face attributes LFACE. */
3488 struct fontset_info
*fontset_info
;
3490 fontset_info
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
];
3492 for (charset
= 0; charset
< MAX_CHARSET
; ++charset
)
3493 if (fontset_info
->fontname
[charset
])
3495 font
= choose_face_fontset_font (f
, XVECTOR (lface
)->contents
,
3497 Fset_fontset_font (frame_font
, CHARSET_SYMBOL (charset
),
3498 build_string (font
), frame
);
3504 /* Frame parameter is an X font name. I believe this can
3505 only happen in unibyte mode. */
3506 font
= choose_face_font (f
, XVECTOR (lface
)->contents
,
3507 -1, Vface_default_registry
);
3510 store_frame_param (f
, Qfont
, build_string (font
));
3517 /* Update the corresponding face when frame parameter PARAM on frame F
3518 has been assigned the value NEW_VALUE. */
3521 update_face_from_frame_parameter (f
, param
, new_value
)
3523 Lisp_Object param
, new_value
;
3527 /* If there are no faces yet, give up. This is the case when called
3528 from Fx_create_frame, and we do the necessary things later in
3529 face-set-after-frame-defaults. */
3530 if (NILP (f
->face_alist
))
3533 if (EQ (param
, Qforeground_color
))
3535 lface
= lface_from_face_name (f
, Qdefault
, 1);
3536 LFACE_FOREGROUND (lface
) = (STRINGP (new_value
)
3537 ? new_value
: Qunspecified
);
3538 realize_basic_faces (f
);
3540 else if (EQ (param
, Qbackground_color
))
3544 /* Changing the background color might change the background
3545 mode, so that we have to load new defface specs. Call
3546 frame-update-face-colors to do that. */
3547 XSETFRAME (frame
, f
);
3548 call1 (Qframe_update_face_colors
, frame
);
3550 lface
= lface_from_face_name (f
, Qdefault
, 1);
3551 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3552 ? new_value
: Qunspecified
);
3553 realize_basic_faces (f
);
3555 if (EQ (param
, Qborder_color
))
3557 lface
= lface_from_face_name (f
, Qborder
, 1);
3558 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3559 ? new_value
: Qunspecified
);
3561 else if (EQ (param
, Qcursor_color
))
3563 lface
= lface_from_face_name (f
, Qcursor
, 1);
3564 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3565 ? new_value
: Qunspecified
);
3567 else if (EQ (param
, Qmouse_color
))
3569 lface
= lface_from_face_name (f
, Qmouse
, 1);
3570 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3571 ? new_value
: Qunspecified
);
3576 /* Get the value of X resource RESOURCE, class CLASS for the display
3577 of frame FRAME. This is here because ordinary `x-get-resource'
3578 doesn't take a frame argument. */
3580 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
3581 Sinternal_face_x_get_resource
, 3, 3, 0, "")
3582 (resource
, class, frame
)
3583 Lisp_Object resource
, class, frame
;
3586 CHECK_STRING (resource
, 0);
3587 CHECK_STRING (class, 1);
3588 CHECK_LIVE_FRAME (frame
, 2);
3590 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame
)),
3591 resource
, class, Qnil
, Qnil
);
3597 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
3598 If VALUE is "on" or "true", return t. If VALUE is "off" or
3599 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
3600 error; if SIGNAL_P is zero, return 0. */
3603 face_boolean_x_resource_value (value
, signal_p
)
3607 Lisp_Object result
= make_number (0);
3609 xassert (STRINGP (value
));
3611 if (xstricmp (XSTRING (value
)->data
, "on") == 0
3612 || xstricmp (XSTRING (value
)->data
, "true") == 0)
3614 else if (xstricmp (XSTRING (value
)->data
, "off") == 0
3615 || xstricmp (XSTRING (value
)->data
, "false") == 0)
3617 else if (xstricmp (XSTRING (value
)->data
, "unspecified") == 0)
3618 result
= Qunspecified
;
3620 signal_error ("Invalid face attribute value from X resource", value
);
3626 DEFUN ("internal-set-lisp-face-attribute-from-resource",
3627 Finternal_set_lisp_face_attribute_from_resource
,
3628 Sinternal_set_lisp_face_attribute_from_resource
,
3630 (face
, attr
, value
, frame
)
3631 Lisp_Object face
, attr
, value
, frame
;
3633 CHECK_SYMBOL (face
, 0);
3634 CHECK_SYMBOL (attr
, 1);
3635 CHECK_STRING (value
, 2);
3637 if (xstricmp (XSTRING (value
)->data
, "unspecified") == 0)
3638 value
= Qunspecified
;
3639 else if (EQ (attr
, QCheight
))
3641 value
= Fstring_to_number (value
, make_number (10));
3642 if (XINT (value
) <= 0)
3643 signal_error ("Invalid face height from X resource", value
);
3645 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
3646 value
= face_boolean_x_resource_value (value
, 1);
3647 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
3648 value
= intern (XSTRING (value
)->data
);
3649 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
3650 value
= face_boolean_x_resource_value (value
, 1);
3651 else if (EQ (attr
, QCunderline
)
3652 || EQ (attr
, QCoverline
)
3653 || EQ (attr
, QCstrike_through
)
3654 || EQ (attr
, QCbox
))
3656 Lisp_Object boolean_value
;
3658 /* If the result of face_boolean_x_resource_value is t or nil,
3659 VALUE does NOT specify a color. */
3660 boolean_value
= face_boolean_x_resource_value (value
, 0);
3661 if (SYMBOLP (boolean_value
))
3662 value
= boolean_value
;
3665 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3669 #endif /* HAVE_X_WINDOWS */
3673 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
3674 Sinternal_get_lisp_face_attribute
,
3676 "Return face attribute KEYWORD of face SYMBOL.\n\
3677 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid\n\
3678 face attribute name, signal an error.\n\
3679 If the optional argument FRAME is given, report on face FACE in that\n\
3680 frame. If FRAME is t, report on the defaults for face FACE (for new\n\
3681 frames). If FRAME is omitted or nil, use the selected frame.")
3682 (symbol
, keyword
, frame
)
3683 Lisp_Object symbol
, keyword
, frame
;
3685 Lisp_Object lface
, value
= Qnil
;
3687 CHECK_SYMBOL (symbol
, 0);
3688 CHECK_SYMBOL (keyword
, 1);
3691 lface
= lface_from_face_name (NULL
, symbol
, 1);
3695 frame
= selected_frame
;
3696 CHECK_LIVE_FRAME (frame
, 2);
3697 lface
= lface_from_face_name (XFRAME (frame
), symbol
, 1);
3700 if (EQ (keyword
, QCfamily
))
3701 value
= LFACE_FAMILY (lface
);
3702 else if (EQ (keyword
, QCheight
))
3703 value
= LFACE_HEIGHT (lface
);
3704 else if (EQ (keyword
, QCweight
))
3705 value
= LFACE_WEIGHT (lface
);
3706 else if (EQ (keyword
, QCslant
))
3707 value
= LFACE_SLANT (lface
);
3708 else if (EQ (keyword
, QCunderline
))
3709 value
= LFACE_UNDERLINE (lface
);
3710 else if (EQ (keyword
, QCoverline
))
3711 value
= LFACE_OVERLINE (lface
);
3712 else if (EQ (keyword
, QCstrike_through
))
3713 value
= LFACE_STRIKE_THROUGH (lface
);
3714 else if (EQ (keyword
, QCbox
))
3715 value
= LFACE_BOX (lface
);
3716 else if (EQ (keyword
, QCinverse_video
)
3717 || EQ (keyword
, QCreverse_video
))
3718 value
= LFACE_INVERSE (lface
);
3719 else if (EQ (keyword
, QCforeground
))
3720 value
= LFACE_FOREGROUND (lface
);
3721 else if (EQ (keyword
, QCbackground
))
3722 value
= LFACE_BACKGROUND (lface
);
3723 else if (EQ (keyword
, QCstipple
))
3724 value
= LFACE_STIPPLE (lface
);
3725 else if (EQ (keyword
, QCwidth
))
3726 value
= LFACE_SWIDTH (lface
);
3728 signal_error ("Invalid face attribute name", keyword
);
3734 DEFUN ("internal-lisp-face-attribute-values",
3735 Finternal_lisp_face_attribute_values
,
3736 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
3737 "Return a list of valid discrete values for face attribute ATTR.\n\
3738 Value is nil if ATTR doesn't have a discrete set of valid values.")
3742 Lisp_Object result
= Qnil
;
3744 CHECK_SYMBOL (attr
, 0);
3746 if (EQ (attr
, QCweight
)
3747 || EQ (attr
, QCslant
)
3748 || EQ (attr
, QCwidth
))
3750 /* Extract permissible symbols from tables. */
3751 struct table_entry
*table
;
3754 if (EQ (attr
, QCweight
))
3755 table
= weight_table
, dim
= DIM (weight_table
);
3756 else if (EQ (attr
, QCslant
))
3757 table
= slant_table
, dim
= DIM (slant_table
);
3759 table
= swidth_table
, dim
= DIM (swidth_table
);
3761 for (i
= 0; i
< dim
; ++i
)
3763 Lisp_Object symbol
= *table
[i
].symbol
;
3764 Lisp_Object tail
= result
;
3767 && !EQ (XCAR (tail
), symbol
))
3771 result
= Fcons (symbol
, result
);
3774 else if (EQ (attr
, QCunderline
))
3775 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3776 else if (EQ (attr
, QCoverline
))
3777 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3778 else if (EQ (attr
, QCstrike_through
))
3779 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3780 else if (EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
3781 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3787 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
3788 Sinternal_merge_in_global_face
, 2, 2, 0,
3789 "Add attributes from frame-default definition of FACE to FACE on FRAME.")
3791 Lisp_Object face
, frame
;
3793 Lisp_Object global_lface
, local_lface
;
3794 CHECK_LIVE_FRAME (frame
, 1);
3795 global_lface
= lface_from_face_name (NULL
, face
, 1);
3796 local_lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3797 if (NILP (local_lface
))
3798 local_lface
= Finternal_make_lisp_face (face
, frame
);
3799 merge_face_vectors (XVECTOR (global_lface
)->contents
,
3800 XVECTOR (local_lface
)->contents
);
3805 /* The following function is implemented for compatibility with 20.2.
3806 The function is used in x-resolve-fonts when it is asked to
3807 return fonts with the same size as the font of a face. This is
3808 done in fontset.el. */
3810 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 2, 0,
3811 "Return the font name of face FACE, or nil if it is unspecified.\n\
3812 If the optional argument FRAME is given, report on face FACE in that frame.\n\
3813 If FRAME is t, report on the defaults for face FACE (for new frames).\n\
3814 The font default for a face is either nil, or a list\n\
3815 of the form (bold), (italic) or (bold italic).\n\
3816 If FRAME is omitted or nil, use the selected frame.")
3818 Lisp_Object face
, frame
;
3822 Lisp_Object result
= Qnil
;
3823 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
3825 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3826 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
3827 result
= Fcons (Qbold
, result
);
3829 if (!NILP (LFACE_SLANT (lface
))
3830 && !EQ (LFACE_SLANT (lface
), Qnormal
))
3831 result
= Fcons (Qitalic
, result
);
3837 struct frame
*f
= frame_or_selected_frame (frame
, 1);
3838 int face_id
= lookup_named_face (f
, face
, CHARSET_ASCII
);
3839 struct face
*face
= FACE_FROM_ID (f
, face_id
);
3840 return build_string (face
->font_name
);
3845 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
3846 all attributes are `equal'. Tries to be fast because this function
3847 is called quite often. */
3850 lface_equal_p (v1
, v2
)
3851 Lisp_Object
*v1
, *v2
;
3855 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
3857 Lisp_Object a
= v1
[i
];
3858 Lisp_Object b
= v2
[i
];
3860 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
3861 and the other is specified. */
3862 equal_p
= XTYPE (a
) == XTYPE (b
);
3871 equal_p
= (XSTRING (a
)->size
== XSTRING (b
)->size
3872 && bcmp (XSTRING (a
)->data
, XSTRING (b
)->data
,
3873 XSTRING (a
)->size
) == 0);
3882 equal_p
= !NILP (Fequal (a
, b
));
3892 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
3893 Sinternal_lisp_face_equal_p
, 2, 3, 0,
3894 "True if FACE1 and FACE2 are equal.\n\
3895 If the optional argument FRAME is given, report on face FACE in that frame.\n\
3896 If FRAME is t, report on the defaults for face FACE (for new frames).\n\
3897 If FRAME is omitted or nil, use the selected frame.")
3898 (face1
, face2
, frame
)
3899 Lisp_Object face1
, face2
, frame
;
3903 Lisp_Object lface1
, lface2
;
3908 /* Don't use check_x_frame here because this function is called
3909 before X frames exist. At that time, if FRAME is nil,
3910 selected_frame will be used which is the frame dumped with
3911 Emacs. That frame is not an X frame. */
3912 f
= frame_or_selected_frame (frame
, 2);
3914 lface1
= lface_from_face_name (NULL
, face1
, 1);
3915 lface2
= lface_from_face_name (NULL
, face2
, 1);
3916 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
3917 XVECTOR (lface2
)->contents
);
3918 return equal_p
? Qt
: Qnil
;
3922 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
3923 Sinternal_lisp_face_empty_p
, 1, 2, 0,
3924 "True if FACE has no attribute specified.\n\
3925 If the optional argument FRAME is given, report on face FACE in that frame.\n\
3926 If FRAME is t, report on the defaults for face FACE (for new frames).\n\
3927 If FRAME is omitted or nil, use the selected frame.")
3929 Lisp_Object face
, frame
;
3936 frame
= selected_frame
;
3937 CHECK_LIVE_FRAME (frame
, 0);
3941 lface
= lface_from_face_name (NULL
, face
, 1);
3943 lface
= lface_from_face_name (f
, face
, 1);
3945 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3946 if (!UNSPECIFIEDP (XVECTOR (lface
)->contents
[i
]))
3949 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
3953 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
3955 "Return an alist of frame-local faces defined on FRAME.\n\
3956 For internal use only.")
3960 struct frame
*f
= frame_or_selected_frame (frame
, 0);
3961 return f
->face_alist
;
3965 /* Return a hash code for Lisp string STRING with case ignored. Used
3966 below in computing a hash value for a Lisp face. */
3968 static INLINE
unsigned
3969 hash_string_case_insensitive (string
)
3974 xassert (STRINGP (string
));
3975 for (s
= XSTRING (string
)->data
; *s
; ++s
)
3976 hash
= (hash
<< 1) ^ tolower (*s
);
3981 /* Return a hash code for face attribute vector V. */
3983 static INLINE
unsigned
3987 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
3988 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
3989 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
3990 ^ (unsigned) v
[LFACE_WEIGHT_INDEX
]
3991 ^ (unsigned) v
[LFACE_SLANT_INDEX
]
3992 ^ (unsigned) v
[LFACE_SWIDTH_INDEX
]
3993 ^ XFASTINT (v
[LFACE_HEIGHT_INDEX
]));
3997 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
3998 considering charsets/registries). They do if they specify the same
3999 family, point size, weight, width and slant. Both LFACE1 and
4000 LFACE2 must be fully-specified. */
4003 lface_same_font_attributes_p (lface1
, lface2
)
4004 Lisp_Object
*lface1
, *lface2
;
4006 xassert (lface_fully_specified_p (lface1
)
4007 && lface_fully_specified_p (lface2
));
4008 return (xstricmp (XSTRING (lface1
[LFACE_FAMILY_INDEX
])->data
,
4009 XSTRING (lface2
[LFACE_FAMILY_INDEX
])->data
) == 0
4010 && (XFASTINT (lface1
[LFACE_HEIGHT_INDEX
])
4011 == XFASTINT (lface2
[LFACE_HEIGHT_INDEX
]))
4012 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
4013 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
4014 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
]));
4019 /***********************************************************************
4021 ***********************************************************************/
4023 /* Allocate and return a new realized face for Lisp face attribute
4024 vector ATTR, charset CHARSET, and registry REGISTRY. */
4026 static struct face
*
4027 make_realized_face (attr
, charset
, registry
)
4030 Lisp_Object registry
;
4032 struct face
*face
= (struct face
*) xmalloc (sizeof *face
);
4033 bzero (face
, sizeof *face
);
4034 face
->charset
= charset
;
4035 face
->registry
= registry
;
4036 bcopy (attr
, face
->lface
, sizeof face
->lface
);
4041 /* Free realized face FACE, including its X resources. FACE may
4045 free_realized_face (f
, face
)
4051 #ifdef HAVE_X_WINDOWS
4056 x_free_gc (f
, face
->gc
);
4060 free_face_colors (f
, face
);
4061 x_destroy_bitmap (f
, face
->stipple
);
4063 #endif /* HAVE_X_WINDOWS */
4070 /* Prepare face FACE for subsequent display on frame F. This
4071 allocated GCs if they haven't been allocated yet or have been freed
4072 by clearing the face cache. */
4075 prepare_face_for_display (f
, face
)
4079 #ifdef HAVE_X_WINDOWS
4080 xassert (FRAME_X_P (f
));
4085 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
4087 xgcv
.foreground
= face
->foreground
;
4088 xgcv
.background
= face
->background
;
4089 xgcv
.graphics_exposures
= False
;
4091 /* The font of FACE may be null if we couldn't load it. */
4094 xgcv
.font
= face
->font
->fid
;
4101 xgcv
.fill_style
= FillOpaqueStippled
;
4102 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
4103 mask
|= GCFillStyle
| GCStipple
;
4106 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
4113 /* Non-zero if FACE is suitable for displaying ISO8859-1. Used in
4114 macro FACE_SUITABLE_FOR_CHARSET_P to avoid realizing a new face for
4115 ISO8859-1 if the ASCII face suffices. */
4118 face_suitable_for_iso8859_1_p (face
)
4121 int len
= strlen (face
->font_name
);
4122 return len
>= 9 && xstricmp (face
->font_name
+ len
- 9, "iso8859-1") == 0;
4126 /* Value is non-zero if FACE is suitable for displaying characters
4127 of CHARSET. CHARSET < 0 means unibyte text. */
4130 face_suitable_for_charset_p (face
, charset
)
4138 if (EQ (face
->registry
, Vface_default_registry
)
4139 || !NILP (Fequal (face
->registry
, Vface_default_registry
)))
4142 else if (face
->charset
== charset
)
4144 else if (face
->charset
== CHARSET_ASCII
4145 && charset
== charset_latin_iso8859_1
)
4146 suitable_p
= face_suitable_for_iso8859_1_p (face
);
4147 else if (face
->charset
== charset_latin_iso8859_1
4148 && charset
== CHARSET_ASCII
)
4156 /***********************************************************************
4158 ***********************************************************************/
4160 /* Return a new face cache for frame F. */
4162 static struct face_cache
*
4166 struct face_cache
*c
;
4169 c
= (struct face_cache
*) xmalloc (sizeof *c
);
4170 bzero (c
, sizeof *c
);
4171 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4172 c
->buckets
= (struct face
**) xmalloc (size
);
4173 bzero (c
->buckets
, size
);
4175 c
->faces_by_id
= (struct face
**) xmalloc (c
->size
* sizeof *c
->faces_by_id
);
4181 /* Clear out all graphics contexts for all realized faces, except for
4182 the basic faces. This should be done from time to time just to avoid
4183 keeping too many graphics contexts that are no longer needed. */
4187 struct face_cache
*c
;
4189 if (c
&& FRAME_X_P (c
->f
))
4191 #ifdef HAVE_X_WINDOWS
4193 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
4195 struct face
*face
= c
->faces_by_id
[i
];
4196 if (face
&& face
->gc
)
4198 x_free_gc (c
->f
, face
->gc
);
4202 #endif /* HAVE_X_WINDOWS */
4207 /* Free all realized faces in face cache C, including basic faces. C
4208 may be null. If faces are freed, make sure the frame's current
4209 matrix is marked invalid, so that a display caused by an expose
4210 event doesn't try to use faces we destroyed. */
4213 free_realized_faces (c
)
4214 struct face_cache
*c
;
4219 struct frame
*f
= c
->f
;
4221 for (i
= 0; i
< c
->used
; ++i
)
4223 free_realized_face (f
, c
->faces_by_id
[i
]);
4224 c
->faces_by_id
[i
] = NULL
;
4228 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4229 bzero (c
->buckets
, size
);
4231 /* Must do a thorough redisplay the next time. Mark current
4232 matrices as invalid because they will reference faces freed
4233 above. This function is also called when a frame is
4234 destroyed. In this case, the root window of F is nil. */
4235 if (WINDOWP (f
->root_window
))
4237 clear_current_matrices (f
);
4238 ++windows_or_buffers_changed
;
4244 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
4245 This is done after attributes of a named face have been changed,
4246 because we can't tell which realized faces depend on that face. */
4249 free_all_realized_faces (frame
)
4255 FOR_EACH_FRAME (rest
, frame
)
4256 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4259 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4263 /* Free face cache C and faces in it, including their X resources. */
4267 struct face_cache
*c
;
4271 free_realized_faces (c
);
4273 xfree (c
->faces_by_id
);
4279 /* Cache realized face FACE in face cache C. HASH is the hash value
4280 of FACE. If FACE->fontset >= 0, add the new face to the end of the
4281 collision list of the face hash table of C. This is done because
4282 otherwise lookup_face would find FACE for every charset, even if
4283 faces with the same attributes but for specific charsets exist. */
4286 cache_face (c
, face
, hash
)
4287 struct face_cache
*c
;
4291 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4295 if (face
->fontset
>= 0)
4297 struct face
*last
= c
->buckets
[i
];
4308 c
->buckets
[i
] = face
;
4309 face
->prev
= face
->next
= NULL
;
4315 face
->next
= c
->buckets
[i
];
4317 face
->next
->prev
= face
;
4318 c
->buckets
[i
] = face
;
4321 /* Find a free slot in C->faces_by_id and use the index of the free
4322 slot as FACE->id. */
4323 for (i
= 0; i
< c
->used
; ++i
)
4324 if (c
->faces_by_id
[i
] == NULL
)
4328 /* Maybe enlarge C->faces_by_id. */
4329 if (i
== c
->used
&& c
->used
== c
->size
)
4331 int new_size
= 2 * c
->size
;
4332 int sz
= new_size
* sizeof *c
->faces_by_id
;
4333 c
->faces_by_id
= (struct face
**) xrealloc (c
->faces_by_id
, sz
);
4338 /* Check that FACE got a unique id. */
4343 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
4344 for (face
= c
->buckets
[j
]; face
; face
= face
->next
)
4350 #endif /* GLYPH_DEBUG */
4352 c
->faces_by_id
[i
] = face
;
4358 /* Remove face FACE from cache C. */
4361 uncache_face (c
, face
)
4362 struct face_cache
*c
;
4365 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
4368 face
->prev
->next
= face
->next
;
4370 c
->buckets
[i
] = face
->next
;
4373 face
->next
->prev
= face
->prev
;
4375 c
->faces_by_id
[face
->id
] = NULL
;
4376 if (face
->id
== c
->used
)
4381 /* Look up a realized face with face attributes ATTR in the face cache
4382 of frame F. The face will be used to display characters of
4383 CHARSET. CHARSET < 0 means the face will be used to display
4384 unibyte text. The value of face-default-registry is used to choose
4385 a font for the face in that case. Value is the ID of the face
4386 found. If no suitable face is found, realize a new one. */
4389 lookup_face (f
, attr
, charset
)
4394 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
4399 xassert (c
!= NULL
);
4400 check_lface_attrs (attr
);
4402 /* Look up ATTR in the face cache. */
4403 hash
= lface_hash (attr
);
4404 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4406 for (face
= c
->buckets
[i
]; face
; face
= face
->next
)
4407 if (face
->hash
== hash
4408 && (!FRAME_WINDOW_P (f
)
4409 || FACE_SUITABLE_FOR_CHARSET_P (face
, charset
))
4410 && lface_equal_p (face
->lface
, attr
))
4413 /* If not found, realize a new face. */
4416 face
= realize_face (c
, attr
, charset
);
4417 cache_face (c
, face
, hash
);
4421 xassert (face
== FACE_FROM_ID (f
, face
->id
));
4423 xassert (charset
< 0 || FACE_SUITABLE_FOR_CHARSET_P (face
, charset
));
4424 #endif /* GLYPH_DEBUG */
4430 /* Return the face id of the realized face for named face SYMBOL on
4431 frame F suitable for displaying characters from CHARSET. CHARSET <
4432 0 means unibyte text. */
4435 lookup_named_face (f
, symbol
, charset
)
4440 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4441 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4442 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4444 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
4445 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
4446 merge_face_vectors (symbol_attrs
, attrs
);
4447 return lookup_face (f
, attrs
, charset
);
4451 /* Return the ID of the realized ASCII face of Lisp face with ID
4452 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
4455 ascii_face_of_lisp_face (f
, lface_id
)
4461 if (lface_id
>= 0 && lface_id
< lface_id_to_name_size
)
4463 Lisp_Object face_name
= lface_id_to_name
[lface_id
];
4464 face_id
= lookup_named_face (f
, face_name
, CHARSET_ASCII
);
4473 /* Return a face for charset ASCII that is like the face with id
4474 FACE_ID on frame F, but has a font that is STEPS steps smaller.
4475 STEPS < 0 means larger. Value is the id of the face. */
4478 smaller_face (f
, face_id
, steps
)
4482 #ifdef HAVE_X_WINDOWS
4484 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4485 int pt
, last_pt
, last_height
;
4488 struct face
*new_face
;
4490 /* If not called for an X frame, just return the original face. */
4491 if (FRAME_TERMCAP_P (f
))
4494 /* Try in increments of 1/2 pt. */
4495 delta
= steps
< 0 ? 5 : -5;
4496 steps
= abs (steps
);
4498 face
= FACE_FROM_ID (f
, face_id
);
4499 bcopy (face
->lface
, attrs
, sizeof attrs
);
4500 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
4501 new_face_id
= face_id
;
4502 last_height
= FONT_HEIGHT (face
->font
);
4506 /* Give up if we cannot find a font within 10pt. */
4507 && abs (last_pt
- pt
) < 100)
4509 /* Look up a face for a slightly smaller/larger font. */
4511 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
4512 new_face_id
= lookup_face (f
, attrs
, CHARSET_ASCII
);
4513 new_face
= FACE_FROM_ID (f
, new_face_id
);
4515 /* If height changes, count that as one step. */
4516 if (FONT_HEIGHT (new_face
->font
) != last_height
)
4519 last_height
= FONT_HEIGHT (new_face
->font
);
4526 #else /* not HAVE_X_WINDOWS */
4530 #endif /* not HAVE_X_WINDOWS */
4534 /* Return a face for charset ASCII that is like the face with id
4535 FACE_ID on frame F, but has height HEIGHT. */
4538 face_with_height (f
, face_id
, height
)
4543 #ifdef HAVE_X_WINDOWS
4545 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4547 if (FRAME_TERMCAP_P (f
)
4551 face
= FACE_FROM_ID (f
, face_id
);
4552 bcopy (face
->lface
, attrs
, sizeof attrs
);
4553 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
4554 face_id
= lookup_face (f
, attrs
, CHARSET_ASCII
);
4555 #endif /* HAVE_X_WINDOWS */
4560 /* Return the face id of the realized face for named face SYMBOL on
4561 frame F suitable for displaying characters from CHARSET (CHARSET <
4562 0 means unibyte text), and use attributes of the face FACE_ID for
4563 attributes that aren't completely specified by SYMBOL. This is
4564 like lookup_named_face, except that the default attributes come
4565 from FACE_ID, not from the default face. FACE_ID is assumed to
4566 be already realized. */
4569 lookup_derived_face (f
, symbol
, charset
, face_id
)
4575 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4576 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4577 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
4582 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
4583 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
4584 merge_face_vectors (symbol_attrs
, attrs
);
4585 return lookup_face (f
, attrs
, charset
);
4590 /***********************************************************************
4592 ***********************************************************************/
4594 DEFUN ("internal-set-font-selection-order",
4595 Finternal_set_font_selection_order
,
4596 Sinternal_set_font_selection_order
, 1, 1, 0,
4597 "Set font selection order for face font selection to ORDER.\n\
4598 ORDER must be a list of length 4 containing the symbols `:width',\n\
4599 `:height', `:weight', and `:slant'. Face attributes appearing\n\
4600 first in ORDER are matched first, e.g. if `:height' appears before\n\
4601 `:weight' in ORDER, font selection first tries to find a font with\n\
4602 a suitable height, and then tries to match the font weight.\n\
4611 CHECK_LIST (order
, 0);
4612 bzero (indices
, sizeof indices
);
4616 CONSP (list
) && i
< DIM (indices
);
4617 list
= XCDR (list
), ++i
)
4619 Lisp_Object attr
= XCAR (list
);
4622 if (EQ (attr
, QCwidth
))
4624 else if (EQ (attr
, QCheight
))
4625 xlfd
= XLFD_POINT_SIZE
;
4626 else if (EQ (attr
, QCweight
))
4628 else if (EQ (attr
, QCslant
))
4633 if (indices
[i
] != 0)
4639 || i
!= DIM (indices
)
4644 signal_error ("Invalid font sort order", order
);
4646 if (bcmp (indices
, font_sort_order
, sizeof indices
) != 0)
4648 bcopy (indices
, font_sort_order
, sizeof font_sort_order
);
4649 free_all_realized_faces (Qnil
);
4656 DEFUN ("internal-set-alternative-font-family-alist",
4657 Finternal_set_alternative_font_family_alist
,
4658 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
4659 "Define alternative font families to try in face font selection.\n\
4660 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.\n\
4661 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can\n\
4662 be found. Value is ALIST.")
4666 CHECK_LIST (alist
, 0);
4667 Vface_alternative_font_family_alist
= alist
;
4668 free_all_realized_faces (Qnil
);
4673 #ifdef HAVE_X_WINDOWS
4675 /* Return the X registry and encoding of font name FONT_NAME on frame F.
4676 Value is nil if not successful. */
4679 deduce_unibyte_registry (f
, font_name
)
4683 struct font_name font
;
4684 Lisp_Object registry
= Qnil
;
4686 font
.name
= STRDUPA (font_name
);
4687 if (split_font_name (f
, &font
, 0))
4691 /* Extract registry and encoding. */
4692 buffer
= (char *) alloca (strlen (font
.fields
[XLFD_REGISTRY
])
4693 + strlen (font
.fields
[XLFD_ENCODING
])
4695 strcpy (buffer
, font
.fields
[XLFD_REGISTRY
]);
4696 strcat (buffer
, "-");
4697 strcat (buffer
, font
.fields
[XLFD_ENCODING
]);
4698 registry
= build_string (buffer
);
4705 /* Value is non-zero if FONT is the name of a scalable font. The
4706 X11R6 XLFD spec says that point size, pixel size, and average width
4707 are zero for scalable fonts. Intlfonts contain at least one
4708 scalable font ("*-muleindian-1") for which this isn't true, so we
4709 just test average width. */
4712 font_scalable_p (font
)
4713 struct font_name
*font
;
4715 char *s
= font
->fields
[XLFD_AVGWIDTH
];
4716 return *s
== '0' && *(s
+ 1) == '\0';
4720 /* Value is non-zero if FONT1 is a better match for font attributes
4721 VALUES than FONT2. VALUES is an array of face attribute values in
4722 font sort order. COMPARE_PT_P zero means don't compare point
4726 better_font_p (values
, font1
, font2
, compare_pt_p
)
4728 struct font_name
*font1
, *font2
;
4733 for (i
= 0; i
< 4; ++i
)
4735 int xlfd_idx
= font_sort_order
[i
];
4737 if (compare_pt_p
|| xlfd_idx
!= XLFD_POINT_SIZE
)
4739 int delta1
= abs (values
[i
] - font1
->numeric
[xlfd_idx
]);
4740 int delta2
= abs (values
[i
] - font2
->numeric
[xlfd_idx
]);
4742 if (delta1
> delta2
)
4744 else if (delta1
< delta2
)
4748 /* The difference may be equal because, e.g., the face
4749 specifies `italic' but we have only `regular' and
4750 `oblique'. Prefer `oblique' in this case. */
4751 if ((xlfd_idx
== XLFD_WEIGHT
|| xlfd_idx
== XLFD_SLANT
)
4752 && font1
->numeric
[xlfd_idx
] > values
[i
]
4753 && font2
->numeric
[xlfd_idx
] < values
[i
])
4765 /* Value is non-zero if FONT is an exact match for face attributes in
4766 SPECIFIED. SPECIFIED is an array of face attribute values in font
4770 exact_face_match_p (specified
, font
)
4772 struct font_name
*font
;
4776 for (i
= 0; i
< 4; ++i
)
4777 if (specified
[i
] != font
->numeric
[font_sort_order
[i
]])
4784 /* Value is the name of a scaled font, generated from scalable font
4785 FONT on frame F. SPECIFIED_PT is the point-size to scale FONT to.
4786 Value is allocated from heap. */
4789 build_scalable_font_name (f
, font
, specified_pt
)
4791 struct font_name
*font
;
4794 char point_size
[20], pixel_size
[20];
4796 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
4799 /* If scalable font is for a specific resolution, compute
4800 the point size we must specify from the resolution of
4801 the display and the specified resolution of the font. */
4802 if (font
->numeric
[XLFD_RESY
] != 0)
4804 pt
= resy
/ font
->numeric
[XLFD_RESY
] * specified_pt
+ 0.5;
4805 pixel_value
= font
->numeric
[XLFD_RESY
] / 720.0 * pt
;
4810 pixel_value
= resy
/ 720.0 * pt
;
4813 /* Set point size of the font. */
4814 sprintf (point_size
, "%d", (int) pt
);
4815 font
->fields
[XLFD_POINT_SIZE
] = point_size
;
4816 font
->numeric
[XLFD_POINT_SIZE
] = pt
;
4818 /* Set pixel size. */
4819 sprintf (pixel_size
, "%d", pixel_value
);
4820 font
->fields
[XLFD_PIXEL_SIZE
] = pixel_size
;
4821 font
->numeric
[XLFD_PIXEL_SIZE
] = pixel_value
;
4823 /* If font doesn't specify its resolution, use the
4824 resolution of the display. */
4825 if (font
->numeric
[XLFD_RESY
] == 0)
4828 sprintf (buffer
, "%d", (int) resy
);
4829 font
->fields
[XLFD_RESY
] = buffer
;
4830 font
->numeric
[XLFD_RESY
] = resy
;
4833 if (strcmp (font
->fields
[XLFD_RESX
], "0") == 0)
4836 int resx
= FRAME_X_DISPLAY_INFO (f
)->resx
;
4837 sprintf (buffer
, "%d", resx
);
4838 font
->fields
[XLFD_RESX
] = buffer
;
4839 font
->numeric
[XLFD_RESX
] = resx
;
4842 return build_font_name (font
);
4846 /* Value is non-zero if we are allowed to use scalable font FONT. We
4847 can't run a Lisp function here since this function may be called
4848 with input blocked. */
4851 may_use_scalable_font_p (font
, name
)
4852 struct font_name
*font
;
4855 if (EQ (Vscalable_fonts_allowed
, Qt
))
4857 else if (CONSP (Vscalable_fonts_allowed
))
4859 Lisp_Object tail
, regexp
;
4861 for (tail
= Vscalable_fonts_allowed
; CONSP (tail
); tail
= XCDR (tail
))
4863 regexp
= XCAR (tail
);
4864 if (STRINGP (regexp
)
4865 && fast_c_string_match_ignore_case (regexp
, name
) >= 0)
4873 #endif /* SCALABLE_FONTS != 0 */
4876 /* Return the name of the best matching font for face attributes
4877 ATTRS in the array of font_name structures FONTS which contains
4878 NFONTS elements. Value is a font name which is allocated from
4879 the heap. FONTS is freed by this function. */
4882 best_matching_font (f
, attrs
, fonts
, nfonts
)
4885 struct font_name
*fonts
;
4889 struct font_name
*best
;
4897 /* Make specified font attributes available in `specified',
4898 indexed by sort order. */
4899 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
4901 int xlfd_idx
= font_sort_order
[i
];
4903 if (xlfd_idx
== XLFD_SWIDTH
)
4904 specified
[i
] = face_numeric_swidth (attrs
[LFACE_SWIDTH_INDEX
]);
4905 else if (xlfd_idx
== XLFD_POINT_SIZE
)
4906 specified
[i
] = pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
4907 else if (xlfd_idx
== XLFD_WEIGHT
)
4908 specified
[i
] = face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
4909 else if (xlfd_idx
== XLFD_SLANT
)
4910 specified
[i
] = face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
4920 /* Start with the first non-scalable font in the list. */
4921 for (i
= 0; i
< nfonts
; ++i
)
4922 if (!font_scalable_p (fonts
+ i
))
4925 /* Find the best match among the non-scalable fonts. */
4930 for (i
= 1; i
< nfonts
; ++i
)
4931 if (!font_scalable_p (fonts
+ i
)
4932 && better_font_p (specified
, fonts
+ i
, best
, 1))
4936 exact_p
= exact_face_match_p (specified
, best
);
4945 /* Unless we found an exact match among non-scalable fonts, see if
4946 we can find a better match among scalable fonts. */
4949 /* A scalable font is better if
4951 1. its weight, slant, swidth attributes are better, or.
4953 2. the best non-scalable font doesn't have the required
4954 point size, and the scalable fonts weight, slant, swidth
4957 int non_scalable_has_exact_height_p
;
4959 if (best
&& best
->numeric
[XLFD_POINT_SIZE
] == pt
)
4960 non_scalable_has_exact_height_p
= 1;
4962 non_scalable_has_exact_height_p
= 0;
4964 for (i
= 0; i
< nfonts
; ++i
)
4965 if (font_scalable_p (fonts
+ i
))
4968 || better_font_p (specified
, fonts
+ i
, best
, 0)
4969 || (!non_scalable_has_exact_height_p
4970 && !better_font_p (specified
, best
, fonts
+ i
, 0)))
4975 if (font_scalable_p (best
))
4976 font_name
= build_scalable_font_name (f
, best
, pt
);
4978 font_name
= build_font_name (best
);
4980 #else /* !SCALABLE_FONTS */
4982 /* Find the best non-scalable font. */
4985 for (i
= 1; i
< nfonts
; ++i
)
4987 xassert (!font_scalable_p (fonts
+ i
));
4988 if (better_font_p (specified
, fonts
+ i
, best
, 1))
4992 font_name
= build_font_name (best
);
4994 #endif /* !SCALABLE_FONTS */
4996 /* Free font_name structures. */
4997 free_font_names (fonts
, nfonts
);
5003 /* Try to get a list of fonts on frame F with font family FAMILY and
5004 registry/encoding REGISTRY. Return in *FONTS a pointer to a vector
5005 of font_name structures for the fonts matched. Value is the number
5009 try_font_list (f
, attrs
, pattern
, family
, registry
, fonts
)
5012 char *pattern
, *family
, *registry
;
5013 struct font_name
**fonts
;
5018 family
= LSTRDUPA (attrs
[LFACE_FAMILY_INDEX
]);
5020 nfonts
= font_list (f
, pattern
, family
, registry
, fonts
);
5026 /* Try alternative font families from
5027 Vface_alternative_font_family_alist. */
5028 alter
= Fassoc (build_string (family
),
5029 Vface_alternative_font_family_alist
);
5031 for (alter
= XCDR (alter
);
5032 CONSP (alter
) && nfonts
== 0;
5033 alter
= XCDR (alter
))
5035 if (STRINGP (XCAR (alter
)))
5037 family
= LSTRDUPA (XCAR (alter
));
5038 nfonts
= font_list (f
, NULL
, family
, registry
, fonts
);
5042 /* Try font family of the default face or "fixed". */
5045 struct face
*dflt
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5047 family
= LSTRDUPA (dflt
->lface
[LFACE_FAMILY_INDEX
]);
5050 nfonts
= font_list (f
, NULL
, family
, registry
, fonts
);
5053 /* Try any family with the given registry. */
5055 nfonts
= font_list (f
, NULL
, "*", registry
, fonts
);
5062 /* Return the registry and encoding pattern that fonts for CHARSET
5063 should match. Value is allocated from the heap. */
5066 x_charset_registry (charset
)
5069 Lisp_Object prop
, charset_plist
;
5072 /* Get registry and encoding from the charset's plist. */
5073 charset_plist
= CHARSET_TABLE_INFO (charset
, CHARSET_PLIST_IDX
);
5074 prop
= Fplist_get (charset_plist
, Qx_charset_registry
);
5078 if (index (XSTRING (prop
)->data
, '-'))
5079 registry
= xstrdup (XSTRING (prop
)->data
);
5082 /* If registry doesn't contain a `-', make it a pattern. */
5083 registry
= (char *) xmalloc (STRING_BYTES (XSTRING (prop
)) + 5);
5084 strcpy (registry
, XSTRING (prop
)->data
);
5085 strcat (registry
, "*-*");
5088 else if (STRINGP (Vface_default_registry
))
5089 registry
= xstrdup (XSTRING (Vface_default_registry
)->data
);
5091 registry
= xstrdup ("iso8859-1");
5097 /* Return the fontset id of the fontset name or alias name given by
5098 the family attribute of ATTRS on frame F. Value is -1 if the
5099 family attribute of ATTRS doesn't name a fontset. */
5102 face_fontset (f
, attrs
)
5106 Lisp_Object name
= attrs
[LFACE_FAMILY_INDEX
];
5109 name
= Fquery_fontset (name
, Qnil
);
5113 fontset
= fs_query_fontset (f
, XSTRING (name
)->data
);
5119 /* Get the font to use for the face realizing the fully-specified Lisp
5120 face ATTRS for charset CHARSET on frame F. CHARSET < 0 means
5121 unibyte text; UNIBYTE_REGISTRY is the registry and encoding to use
5122 in this case. Value is the font name which is allocated from the
5123 heap (which means that it must be freed eventually). */
5126 choose_face_font (f
, attrs
, charset
, unibyte_registry
)
5130 Lisp_Object unibyte_registry
;
5132 struct font_name
*fonts
;
5136 /* ATTRS must be fully-specified. */
5137 xassert (lface_fully_specified_p (attrs
));
5139 if (STRINGP (unibyte_registry
))
5140 registry
= xstrdup (XSTRING (unibyte_registry
)->data
);
5142 registry
= x_charset_registry (charset
);
5144 nfonts
= try_font_list (f
, attrs
, NULL
, NULL
, registry
, &fonts
);
5146 return best_matching_font (f
, attrs
, fonts
, nfonts
);
5150 /* Choose a font to use on frame F to display CHARSET using FONTSET
5151 with Lisp face attributes specified by ATTRS. CHARSET may be any
5152 valid charset except CHARSET_COMPOSITION. CHARSET < 0 means
5153 unibyte text. If the fontset doesn't contain a font pattern for
5154 charset, use the pattern for CHARSET_ASCII. Value is the font name
5155 which is allocated from the heap and must be freed by the caller. */
5158 choose_face_fontset_font (f
, attrs
, fontset
, charset
)
5161 int fontset
, charset
;
5164 char *font_name
= NULL
;
5165 struct fontset_info
*fontset_info
;
5166 struct font_name
*fonts
;
5169 xassert (charset
!= CHARSET_COMPOSITION
);
5170 xassert (fontset
>= 0 && fontset
< FRAME_FONTSET_DATA (f
)->n_fontsets
);
5172 /* For unibyte text, use the ASCII font of the fontset. Using the
5173 ASCII font seems to be the most reasonable thing we can do in
5176 charset
= CHARSET_ASCII
;
5178 /* Get the font name pattern to use for CHARSET from the fontset. */
5179 fontset_info
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
];
5180 pattern
= fontset_info
->fontname
[charset
];
5182 pattern
= fontset_info
->fontname
[CHARSET_ASCII
];
5185 /* Get a list of fonts matching that pattern and choose the
5186 best match for the specified face attributes from it. */
5187 nfonts
= try_font_list (f
, attrs
, pattern
, NULL
, NULL
, &fonts
);
5188 font_name
= best_matching_font (f
, attrs
, fonts
, nfonts
);
5192 #endif /* HAVE_X_WINDOWS */
5196 /***********************************************************************
5198 ***********************************************************************/
5200 /* Realize basic faces on frame F. Value is zero if frame parameters
5201 of F don't contain enough information needed to realize the default
5205 realize_basic_faces (f
)
5210 if (realize_default_face (f
))
5212 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
5213 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
5214 realize_named_face (f
, Qfringe
, BITMAP_AREA_FACE_ID
);
5215 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
5216 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
5217 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
5218 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
5219 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
5227 /* Realize the default face on frame F. If the face is not fully
5228 specified, make it fully-specified. Attributes of the default face
5229 that are not explicitly specified are taken from frame parameters. */
5232 realize_default_face (f
)
5235 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5237 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5238 Lisp_Object unibyte_registry
;
5239 Lisp_Object frame_font
;
5243 /* If the `default' face is not yet known, create it. */
5244 lface
= lface_from_face_name (f
, Qdefault
, 0);
5248 XSETFRAME (frame
, f
);
5249 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
5252 #ifdef HAVE_X_WINDOWS
5255 /* Set frame_font to the value of the `font' frame parameter. */
5256 frame_font
= Fassq (Qfont
, f
->param_alist
);
5257 xassert (CONSP (frame_font
) && STRINGP (XCDR (frame_font
)));
5258 frame_font
= XCDR (frame_font
);
5260 fontset
= fs_query_fontset (f
, XSTRING (frame_font
)->data
);
5263 /* If frame_font is a fontset name, don't use that for
5264 determining font-related attributes of the default face
5265 because it is just an artificial name. Use the ASCII font of
5266 the fontset, instead. */
5267 struct font_info
*font_info
;
5268 struct font_name font
;
5271 font_info
= FS_LOAD_FONT (f
, FRAME_X_FONT_TABLE (f
), CHARSET_ASCII
,
5275 /* Set weight etc. from the ASCII font. */
5276 if (!set_lface_from_font_name (f
, lface
, font_info
->full_name
, 0))
5279 /* Remember registry and encoding of the frame font. */
5280 unibyte_registry
= deduce_unibyte_registry (f
, font_info
->full_name
);
5281 if (STRINGP (unibyte_registry
))
5282 Vface_default_registry
= unibyte_registry
;
5284 Vface_default_registry
= build_string ("iso8859-1");
5286 /* But set the family to the fontset alias name. Implementation
5287 note: When a font is passed to Emacs via `-fn FONT', a
5288 fontset is created in `x-win.el' whose name ends in
5289 `fontset-startup'. This fontset has an alias name that is
5290 equal to frame_font. */
5291 xassert (STRINGP (frame_font
));
5292 font
.name
= LSTRDUPA (frame_font
);
5294 if (!split_font_name (f
, &font
, 1)
5295 || xstricmp (font
.fields
[XLFD_REGISTRY
], "fontset") != 0
5296 || xstricmp (font
.fields
[XLFD_ENCODING
], "startup") != 0)
5297 LFACE_FAMILY (lface
) = frame_font
;
5301 /* Frame parameters contain a real font. Fill default face
5302 attributes from that font. */
5303 if (!set_lface_from_font_name (f
, lface
,
5304 XSTRING (frame_font
)->data
, 0))
5307 /* Remember registry and encoding of the frame font. */
5309 = deduce_unibyte_registry (f
, XSTRING (frame_font
)->data
);
5310 if (STRINGP (unibyte_registry
))
5311 Vface_default_registry
= unibyte_registry
;
5313 Vface_default_registry
= build_string ("iso8859-1");
5316 #endif /* HAVE_X_WINDOWS */
5318 if (!FRAME_WINDOW_P (f
))
5320 LFACE_FAMILY (lface
) = build_string ("default");
5321 LFACE_SWIDTH (lface
) = Qnormal
;
5322 LFACE_HEIGHT (lface
) = make_number (1);
5323 LFACE_WEIGHT (lface
) = Qnormal
;
5324 LFACE_SLANT (lface
) = Qnormal
;
5327 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
5328 LFACE_UNDERLINE (lface
) = Qnil
;
5330 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
5331 LFACE_OVERLINE (lface
) = Qnil
;
5333 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
5334 LFACE_STRIKE_THROUGH (lface
) = Qnil
;
5336 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
5337 LFACE_BOX (lface
) = Qnil
;
5339 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
5340 LFACE_INVERSE (lface
) = Qnil
;
5342 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
5344 /* This function is called so early that colors are not yet
5345 set in the frame parameter list. */
5346 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
5348 if (CONSP (color
) && STRINGP (XCDR (color
)))
5349 LFACE_FOREGROUND (lface
) = XCDR (color
);
5350 else if (FRAME_X_P (f
))
5352 else if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5353 /* Frame parameters for terminal frames usually don't contain
5354 a color. Use an empty string to indicate that the face
5355 should use the (unknown) default color of the terminal. */
5356 LFACE_FOREGROUND (lface
) = build_string ("");
5361 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
5363 /* This function is called so early that colors are not yet
5364 set in the frame parameter list. */
5365 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
5366 if (CONSP (color
) && STRINGP (XCDR (color
)))
5367 LFACE_BACKGROUND (lface
) = XCDR (color
);
5368 else if (FRAME_X_P (f
))
5370 else if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5371 /* Frame parameters for terminal frames usually don't contain
5372 a color. Use an empty string to indicate that the face
5373 should use the (unknown) default color of the terminal. */
5374 LFACE_BACKGROUND (lface
) = build_string ("");
5379 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
5380 LFACE_STIPPLE (lface
) = Qnil
;
5382 /* Realize the face; it must be fully-specified now. */
5383 xassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
5384 check_lface (lface
);
5385 bcopy (XVECTOR (lface
)->contents
, attrs
, sizeof attrs
);
5386 face
= realize_face (c
, attrs
, CHARSET_ASCII
);
5388 /* Remove the former default face. */
5389 if (c
->used
> DEFAULT_FACE_ID
)
5391 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5392 uncache_face (c
, default_face
);
5393 free_realized_face (f
, default_face
);
5396 /* Insert the new default face. */
5397 cache_face (c
, face
, lface_hash (attrs
));
5398 xassert (face
->id
== DEFAULT_FACE_ID
);
5403 /* Realize basic faces other than the default face in face cache C.
5404 SYMBOL is the face name, ID is the face id the realized face must
5405 have. The default face must have been realized already. */
5408 realize_named_face (f
, symbol
, id
)
5413 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5414 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
5415 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5416 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5417 struct face
*new_face
;
5419 /* The default face must exist and be fully specified. */
5420 get_lface_attributes (f
, Qdefault
, attrs
, 1);
5421 check_lface_attrs (attrs
);
5422 xassert (lface_fully_specified_p (attrs
));
5424 /* If SYMBOL isn't know as a face, create it. */
5428 XSETFRAME (frame
, f
);
5429 lface
= Finternal_make_lisp_face (symbol
, frame
);
5432 /* Merge SYMBOL's face with the default face. */
5433 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
5434 merge_face_vectors (symbol_attrs
, attrs
);
5436 /* Realize the face. */
5437 new_face
= realize_face (c
, attrs
, CHARSET_ASCII
);
5439 /* Remove the former face. */
5442 struct face
*old_face
= c
->faces_by_id
[id
];
5443 uncache_face (c
, old_face
);
5444 free_realized_face (f
, old_face
);
5447 /* Insert the new face. */
5448 cache_face (c
, new_face
, lface_hash (attrs
));
5449 xassert (new_face
->id
== id
);
5453 /* Realize the fully-specified face with attributes ATTRS in face
5454 cache C for character set CHARSET or for unibyte text if CHARSET <
5455 0. Value is a pointer to the newly created realized face. */
5457 static struct face
*
5458 realize_face (c
, attrs
, charset
)
5459 struct face_cache
*c
;
5465 /* LFACE must be fully specified. */
5466 xassert (c
!= NULL
);
5467 check_lface_attrs (attrs
);
5469 if (FRAME_X_P (c
->f
))
5470 face
= realize_x_face (c
, attrs
, charset
);
5471 else if (FRAME_TERMCAP_P (c
->f
) || FRAME_MSDOS_P (c
->f
))
5472 face
= realize_tty_face (c
, attrs
, charset
);
5480 /* Realize the fully-specified face with attributes ATTRS in face
5481 cache C for character set CHARSET or for unibyte text if CHARSET <
5482 0. Do it for X frame C->f. Value is a pointer to the newly
5483 created realized face. */
5485 static struct face
*
5486 realize_x_face (c
, attrs
, charset
)
5487 struct face_cache
*c
;
5491 #ifdef HAVE_X_WINDOWS
5492 struct face
*face
, *default_face
;
5493 struct frame
*f
= c
->f
;
5494 Lisp_Object stipple
, overline
, strike_through
, box
;
5495 Lisp_Object unibyte_registry
;
5496 struct gcpro gcpro1
;
5498 xassert (FRAME_X_P (f
));
5500 /* If realizing a face for use in unibyte text, get the X registry
5501 and encoding to use from Vface_default_registry. */
5503 unibyte_registry
= (STRINGP (Vface_default_registry
)
5504 ? Vface_default_registry
5505 : build_string ("iso8859-1"));
5507 unibyte_registry
= Qnil
;
5508 GCPRO1 (unibyte_registry
);
5510 /* Allocate a new realized face. */
5511 face
= make_realized_face (attrs
, charset
, unibyte_registry
);
5513 /* Determine the font to use. Most of the time, the font will be
5514 the same as the font of the default face, so try that first. */
5515 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5517 && FACE_SUITABLE_FOR_CHARSET_P (default_face
, charset
)
5518 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
5520 face
->font
= default_face
->font
;
5521 face
->fontset
= default_face
->fontset
;
5522 face
->font_info_id
= default_face
->font_info_id
;
5523 face
->font_name
= default_face
->font_name
;
5524 face
->registry
= default_face
->registry
;
5526 else if (charset
>= 0)
5528 /* For all charsets except CHARSET_COMPOSITION, we use our own
5529 font selection functions to choose a best matching font for
5530 the specified face attributes. If the face specifies a
5531 fontset alias name, the fontset determines the font name
5532 pattern, otherwise we construct a font pattern from face
5533 attributes and charset.
5535 If charset is CHARSET_COMPOSITION, we always construct a face
5536 with a fontset, even if the face doesn't specify a fontset alias
5537 (we use fontset-standard in that case). When the composite
5538 character is displayed in xterm.c, a suitable concrete font is
5539 loaded in x_get_char_font_and_encoding. */
5541 char *font_name
= NULL
;
5542 int fontset
= face_fontset (f
, attrs
);
5544 if (charset
== CHARSET_COMPOSITION
)
5545 fontset
= max (0, fontset
);
5546 else if (fontset
< 0)
5547 font_name
= choose_face_font (f
, attrs
, charset
, Qnil
);
5550 font_name
= choose_face_fontset_font (f
, attrs
, fontset
, charset
);
5554 load_face_font_or_fontset (f
, face
, font_name
, fontset
);
5559 /* Unibyte case, and font is not equal to that of the default
5560 face. UNIBYTE_REGISTRY is the X registry and encoding the
5561 font should have. What is a reasonable thing to do if the
5562 user specified a fontset alias name for the face in this
5563 case? We choose a font by taking the ASCII font of the
5564 fontset, but using UNIBYTE_REGISTRY for its registry and
5567 char *font_name
= NULL
;
5568 int fontset
= face_fontset (f
, attrs
);
5571 font_name
= choose_face_font (f
, attrs
, charset
, unibyte_registry
);
5573 font_name
= choose_face_fontset_font (f
, attrs
, fontset
, charset
);
5575 load_face_font_or_fontset (f
, face
, font_name
, -1);
5579 /* Load colors, and set remaining attributes. */
5581 load_face_colors (f
, face
, attrs
);
5584 box
= attrs
[LFACE_BOX_INDEX
];
5587 /* A simple box of line width 1 drawn in color given by
5589 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
5591 face
->box
= FACE_SIMPLE_BOX
;
5592 face
->box_line_width
= 1;
5594 else if (INTEGERP (box
))
5596 /* Simple box of specified line width in foreground color of the
5598 xassert (XINT (box
) > 0);
5599 face
->box
= FACE_SIMPLE_BOX
;
5600 face
->box_line_width
= XFASTINT (box
);
5601 face
->box_color
= face
->foreground
;
5602 face
->box_color_defaulted_p
= 1;
5604 else if (CONSP (box
))
5606 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
5607 being one of `raised' or `sunken'. */
5608 face
->box
= FACE_SIMPLE_BOX
;
5609 face
->box_color
= face
->foreground
;
5610 face
->box_color_defaulted_p
= 1;
5611 face
->box_line_width
= 1;
5615 Lisp_Object keyword
, value
;
5617 keyword
= XCAR (box
);
5625 if (EQ (keyword
, QCline_width
))
5627 if (INTEGERP (value
) && XINT (value
) > 0)
5628 face
->box_line_width
= XFASTINT (value
);
5630 else if (EQ (keyword
, QCcolor
))
5632 if (STRINGP (value
))
5634 face
->box_color
= load_color (f
, face
, value
,
5636 face
->use_box_color_for_shadows_p
= 1;
5639 else if (EQ (keyword
, QCstyle
))
5641 if (EQ (value
, Qreleased_button
))
5642 face
->box
= FACE_RAISED_BOX
;
5643 else if (EQ (value
, Qpressed_button
))
5644 face
->box
= FACE_SUNKEN_BOX
;
5649 /* Text underline, overline, strike-through. */
5651 if (EQ (attrs
[LFACE_UNDERLINE_INDEX
], Qt
))
5653 /* Use default color (same as foreground color). */
5654 face
->underline_p
= 1;
5655 face
->underline_defaulted_p
= 1;
5656 face
->underline_color
= 0;
5658 else if (STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]))
5660 /* Use specified color. */
5661 face
->underline_p
= 1;
5662 face
->underline_defaulted_p
= 0;
5663 face
->underline_color
5664 = load_color (f
, face
, attrs
[LFACE_UNDERLINE_INDEX
],
5665 LFACE_UNDERLINE_INDEX
);
5667 else if (NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5669 face
->underline_p
= 0;
5670 face
->underline_defaulted_p
= 0;
5671 face
->underline_color
= 0;
5674 overline
= attrs
[LFACE_OVERLINE_INDEX
];
5675 if (STRINGP (overline
))
5677 face
->overline_color
5678 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
5679 LFACE_OVERLINE_INDEX
);
5680 face
->overline_p
= 1;
5682 else if (EQ (overline
, Qt
))
5684 face
->overline_color
= face
->foreground
;
5685 face
->overline_color_defaulted_p
= 1;
5686 face
->overline_p
= 1;
5689 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
5690 if (STRINGP (strike_through
))
5692 face
->strike_through_color
5693 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
5694 LFACE_STRIKE_THROUGH_INDEX
);
5695 face
->strike_through_p
= 1;
5697 else if (EQ (strike_through
, Qt
))
5699 face
->strike_through_color
= face
->foreground
;
5700 face
->strike_through_color_defaulted_p
= 1;
5701 face
->strike_through_p
= 1;
5704 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
5705 if (!NILP (stipple
))
5706 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
5709 xassert (face
->fontset
< 0 || face
->charset
== CHARSET_COMPOSITION
);
5710 xassert (FACE_SUITABLE_FOR_CHARSET_P (face
, charset
));
5712 #endif /* HAVE_X_WINDOWS */
5716 /* Realize the fully-specified face with attributes ATTRS in face
5717 cache C for character set CHARSET or for unibyte text if CHARSET <
5718 0. Do it for TTY frame C->f. Value is a pointer to the newly
5719 created realized face. */
5721 static struct face
*
5722 realize_tty_face (c
, attrs
, charset
)
5723 struct face_cache
*c
;
5731 /* Frame must be a termcap frame. */
5732 xassert (FRAME_TERMCAP_P (c
->f
) || FRAME_MSDOS_P (c
->f
));
5734 /* Allocate a new realized face. */
5735 face
= make_realized_face (attrs
, charset
, Qnil
);
5736 face
->font_name
= FRAME_MSDOS_P (c
->f
) ? "ms-dos" : "tty";
5738 /* Map face attributes to TTY appearances. We map slant to
5739 dimmed text because we want italic text to appear differently
5740 and because dimmed text is probably used infrequently. */
5741 weight
= face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
5742 slant
= face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
5744 if (weight
> XLFD_WEIGHT_MEDIUM
)
5745 face
->tty_bold_p
= 1;
5746 if (weight
< XLFD_WEIGHT_MEDIUM
|| slant
!= XLFD_SLANT_ROMAN
)
5747 face
->tty_dim_p
= 1;
5748 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5749 face
->tty_underline_p
= 1;
5750 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
5751 face
->tty_reverse_p
= 1;
5753 /* Map color names to color indices. */
5754 face
->foreground
= face
->background
= FACE_TTY_DEFAULT_COLOR
;
5756 color
= attrs
[LFACE_FOREGROUND_INDEX
];
5757 if (XSTRING (color
)->size
5758 && (color
= Fassoc (color
, Vface_tty_color_alist
),
5760 face
->foreground
= XINT (XCDR (color
));
5763 if (FRAME_MSDOS_P (c
->f
) && face
->foreground
== FACE_TTY_DEFAULT_COLOR
)
5765 face
->foreground
= load_color (c
->f
, face
,
5766 attrs
[LFACE_FOREGROUND_INDEX
],
5767 LFACE_FOREGROUND_INDEX
);
5768 /* If the foreground of the default face is the default color,
5769 use the foreground color defined by the frame. */
5770 if (face
->foreground
== FACE_TTY_DEFAULT_COLOR
)
5772 face
->foreground
= FRAME_FOREGROUND_PIXEL (f
);
5773 attrs
[LFACE_FOREGROUND_INDEX
] =
5774 build_string (msdos_stdcolor_name (face
->foreground
));
5779 color
= attrs
[LFACE_BACKGROUND_INDEX
];
5780 if (XSTRING (color
)->size
5781 && (color
= Fassoc (color
, Vface_tty_color_alist
),
5783 face
->background
= XINT (XCDR (color
));
5786 if (FRAME_MSDOS_P (c
->f
) && face
->background
== FACE_TTY_DEFAULT_COLOR
)
5788 face
->background
= load_color (c
->f
, face
,
5789 attrs
[LFACE_BACKGROUND_INDEX
],
5790 LFACE_BACKGROUND_INDEX
);
5791 /* If the background of the default face is the default color,
5792 use the background color defined by the frame. */
5793 if (face
->background
== FACE_TTY_DEFAULT_COLOR
)
5795 face
->background
= FRAME_BACKGROUND_PIXEL (f
);
5796 attrs
[LFACE_BACKGROUND_INDEX
] =
5797 build_string (msdos_stdcolor_name (face
->background
));
5801 /* Swap colors if face is inverse-video. */
5802 if (face
->tty_reverse_p
)
5804 unsigned long tem
= face
->foreground
;
5806 face
->foreground
= face
->background
;
5807 face
->background
= tem
;
5815 DEFUN ("face-register-tty-color", Fface_register_tty_color
,
5816 Sface_register_tty_color
, 2, 2, 0,
5817 "Say that COLOR is color number NUMBER on the terminal.\n\
5818 COLOR is a string, the color name. Value is COLOR.")
5820 Lisp_Object color
, number
;
5824 CHECK_STRING (color
, 0);
5825 CHECK_NUMBER (number
, 1);
5826 entry
= Fassoc (color
, Vface_tty_color_alist
);
5828 Vface_tty_color_alist
= Fcons (Fcons (color
, number
),
5829 Vface_tty_color_alist
);
5831 Fsetcdr (entry
, number
);
5836 DEFUN ("face-clear-tty-colors", Fface_clear_tty_colors
,
5837 Sface_clear_tty_colors
, 0, 0, 0,
5838 "Unregister all registered tty colors.")
5841 return Vface_tty_color_alist
= Qnil
;
5845 DEFUN ("tty-defined-colors", Ftty_defined_colors
,
5846 Stty_defined_colors
, 0, 0, 0,
5847 "Return a list of registered tty colors.")
5850 Lisp_Object list
, colors
;
5853 for (list
= Vface_tty_color_alist
; CONSP (list
); list
= XCDR (list
))
5854 colors
= Fcons (XCAR (XCAR (list
)), colors
);
5861 /***********************************************************************
5863 ***********************************************************************/
5865 /* Return the ID of the face to use to display character CH with face
5866 property PROP on frame F in current_buffer. */
5869 compute_char_face (f
, ch
, prop
)
5875 int charset
= (NILP (current_buffer
->enable_multibyte_characters
)
5877 : CHAR_CHARSET (ch
));
5880 face_id
= FACE_FOR_CHARSET (f
, DEFAULT_FACE_ID
, charset
);
5883 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5884 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5885 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
5886 merge_face_vector_with_property (f
, attrs
, prop
);
5887 face_id
= lookup_face (f
, attrs
, charset
);
5894 /* Return the face ID associated with buffer position POS for
5895 displaying ASCII characters. Return in *ENDPTR the position at
5896 which a different face is needed, as far as text properties and
5897 overlays are concerned. W is a window displaying current_buffer.
5899 REGION_BEG, REGION_END delimit the region, so it can be
5902 LIMIT is a position not to scan beyond. That is to limit the time
5903 this function can take.
5905 If MOUSE is non-zero, use the character's mouse-face, not its face.
5907 The face returned is suitable for displaying CHARSET_ASCII if
5908 current_buffer->enable_multibyte_characters is non-nil. Otherwise,
5909 the face is suitable for displaying unibyte text. */
5912 face_at_buffer_position (w
, pos
, region_beg
, region_end
,
5913 endptr
, limit
, mouse
)
5916 int region_beg
, region_end
;
5921 struct frame
*f
= XFRAME (w
->frame
);
5922 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5923 Lisp_Object prop
, position
;
5925 Lisp_Object
*overlay_vec
;
5928 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
5929 Lisp_Object limit1
, end
;
5930 struct face
*default_face
;
5931 int multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5933 /* W must display the current buffer. We could write this function
5934 to use the frame and buffer of W, but right now it doesn't. */
5935 /* xassert (XBUFFER (w->buffer) == current_buffer); */
5937 XSETFRAME (frame
, f
);
5938 XSETFASTINT (position
, pos
);
5941 if (pos
< region_beg
&& region_beg
< endpos
)
5942 endpos
= region_beg
;
5944 /* Get the `face' or `mouse_face' text property at POS, and
5945 determine the next position at which the property changes. */
5946 prop
= Fget_text_property (position
, propname
, w
->buffer
);
5947 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
5948 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
5950 endpos
= XINT (end
);
5952 /* Look at properties from overlays. */
5957 /* First try with room for 40 overlays. */
5959 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
5960 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
5961 &next_overlay
, NULL
);
5963 /* If there are more than 40, make enough space for all, and try
5965 if (noverlays
> len
)
5968 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
5969 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
5970 &next_overlay
, NULL
);
5973 if (next_overlay
< endpos
)
5974 endpos
= next_overlay
;
5979 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5981 /* Optimize common cases where we can use the default face. */
5984 && !(pos
>= region_beg
&& pos
< region_end
)
5986 || !FRAME_WINDOW_P (f
)
5987 || FACE_SUITABLE_FOR_CHARSET_P (default_face
, -1)))
5988 return DEFAULT_FACE_ID
;
5990 /* Begin with attributes from the default face. */
5991 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
5993 /* Merge in attributes specified via text properties. */
5995 merge_face_vector_with_property (f
, attrs
, prop
);
5997 /* Now merge the overlay data. */
5998 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
5999 for (i
= 0; i
< noverlays
; i
++)
6004 prop
= Foverlay_get (overlay_vec
[i
], propname
);
6006 merge_face_vector_with_property (f
, attrs
, prop
);
6008 oend
= OVERLAY_END (overlay_vec
[i
]);
6009 oendpos
= OVERLAY_POSITION (oend
);
6010 if (oendpos
< endpos
)
6014 /* If in the region, merge in the region face. */
6015 if (pos
>= region_beg
&& pos
< region_end
)
6017 Lisp_Object region_face
= lface_from_face_name (f
, Qregion
, 0);
6018 merge_face_vectors (XVECTOR (region_face
)->contents
, attrs
);
6020 if (region_end
< endpos
)
6021 endpos
= region_end
;
6026 /* Look up a realized face with the given face attributes,
6027 or realize a new one. Charset is ignored for tty frames. */
6028 return lookup_face (f
, attrs
, multibyte_p
? CHARSET_ASCII
: -1);
6032 /* Compute the face at character position POS in Lisp string STRING on
6033 window W, for charset CHARSET_ASCII.
6035 If STRING is an overlay string, it comes from position BUFPOS in
6036 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
6037 not an overlay string. W must display the current buffer.
6038 REGION_BEG and REGION_END give the start and end positions of the
6039 region; both are -1 if no region is visible. BASE_FACE_ID is the
6040 id of the basic face to merge with. It is usually equal to
6041 DEFAULT_FACE_ID but can be MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID
6042 for strings displayed in the mode or top line.
6044 Set *ENDPTR to the next position where to check for faces in
6045 STRING; -1 if the face is constant from POS to the end of the
6048 Value is the id of the face to use. The face returned is suitable
6049 for displaying CHARSET_ASCII if STRING is multibyte. Otherwise,
6050 the face is suitable for displaying unibyte text. */
6053 face_at_string_position (w
, string
, pos
, bufpos
, region_beg
,
6054 region_end
, endptr
, base_face_id
)
6058 int region_beg
, region_end
;
6060 enum face_id base_face_id
;
6062 Lisp_Object prop
, position
, end
, limit
;
6063 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6064 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6065 struct face
*base_face
;
6066 int multibyte_p
= STRING_MULTIBYTE (string
);
6068 /* Get the value of the face property at the current position within
6069 STRING. Value is nil if there is no face property. */
6070 XSETFASTINT (position
, pos
);
6071 prop
= Fget_text_property (position
, Qface
, string
);
6073 /* Get the next position at which to check for faces. Value of end
6074 is nil if face is constant all the way to the end of the string.
6075 Otherwise it is a string position where to check faces next.
6076 Limit is the maximum position up to which to check for property
6077 changes in Fnext_single_property_change. Strings are usually
6078 short, so set the limit to the end of the string. */
6079 XSETFASTINT (limit
, XSTRING (string
)->size
);
6080 end
= Fnext_single_property_change (position
, Qface
, string
, limit
);
6082 *endptr
= XFASTINT (end
);
6086 base_face
= FACE_FROM_ID (f
, base_face_id
);
6087 xassert (base_face
);
6089 /* Optimize the default case that there is no face property and we
6090 are not in the region. */
6092 && (base_face_id
!= DEFAULT_FACE_ID
6093 /* BUFPOS <= 0 means STRING is not an overlay string, so
6094 that the region doesn't have to be taken into account. */
6096 || bufpos
< region_beg
6097 || bufpos
>= region_end
)
6099 /* We can't realize faces for different charsets differently
6100 if we don't have fonts, so we can stop here if not working
6101 on a window-system frame. */
6102 || !FRAME_WINDOW_P (f
)
6103 || FACE_SUITABLE_FOR_CHARSET_P (base_face
, -1)))
6104 return base_face
->id
;
6106 /* Begin with attributes from the base face. */
6107 bcopy (base_face
->lface
, attrs
, sizeof attrs
);
6109 /* Merge in attributes specified via text properties. */
6111 merge_face_vector_with_property (f
, attrs
, prop
);
6113 /* If in the region, merge in the region face. */
6115 && bufpos
>= region_beg
6116 && bufpos
< region_end
)
6118 Lisp_Object region_face
= lface_from_face_name (f
, Qregion
, 0);
6119 merge_face_vectors (XVECTOR (region_face
)->contents
, attrs
);
6122 /* Look up a realized face with the given face attributes,
6123 or realize a new one. */
6124 return lookup_face (f
, attrs
, multibyte_p
? CHARSET_ASCII
: -1);
6129 /***********************************************************************
6131 ***********************************************************************/
6135 /* Print the contents of the realized face FACE to stderr. */
6138 dump_realized_face (face
)
6141 fprintf (stderr
, "ID: %d\n", face
->id
);
6142 #ifdef HAVE_X_WINDOWS
6143 fprintf (stderr
, "gc: %d\n", (int) face
->gc
);
6145 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
6147 XSTRING (face
->lface
[LFACE_FOREGROUND_INDEX
])->data
);
6148 fprintf (stderr
, "background: 0x%lx (%s)\n",
6150 XSTRING (face
->lface
[LFACE_BACKGROUND_INDEX
])->data
);
6151 fprintf (stderr
, "font_name: %s (%s)\n",
6153 XSTRING (face
->lface
[LFACE_FAMILY_INDEX
])->data
);
6154 #ifdef HAVE_X_WINDOWS
6155 fprintf (stderr
, "font = %p\n", face
->font
);
6157 fprintf (stderr
, "font_info_id = %d\n", face
->font_info_id
);
6158 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
6159 fprintf (stderr
, "underline: %d (%s)\n",
6161 XSTRING (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
]))->data
);
6162 fprintf (stderr
, "hash: %d\n", face
->hash
);
6163 fprintf (stderr
, "charset: %d\n", face
->charset
);
6167 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, "")
6175 fprintf (stderr
, "font selection order: ");
6176 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6177 fprintf (stderr
, "%d ", font_sort_order
[i
]);
6178 fprintf (stderr
, "\n");
6180 fprintf (stderr
, "alternative fonts: ");
6181 debug_print (Vface_alternative_font_family_alist
);
6182 fprintf (stderr
, "\n");
6184 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
6185 Fdump_face (make_number (i
));
6190 CHECK_NUMBER (n
, 0);
6191 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
6193 error ("Not a valid face");
6194 dump_realized_face (face
);
6201 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
6205 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
6206 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
6207 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
6211 #endif /* GLYPH_DEBUG != 0 */
6215 /***********************************************************************
6217 ***********************************************************************/
6222 Qface
= intern ("face");
6224 Qpixmap_spec_p
= intern ("pixmap-spec-p");
6225 staticpro (&Qpixmap_spec_p
);
6226 Qframe_update_face_colors
= intern ("frame-update-face-colors");
6227 staticpro (&Qframe_update_face_colors
);
6229 /* Lisp face attribute keywords. */
6230 QCfamily
= intern (":family");
6231 staticpro (&QCfamily
);
6232 QCheight
= intern (":height");
6233 staticpro (&QCheight
);
6234 QCweight
= intern (":weight");
6235 staticpro (&QCweight
);
6236 QCslant
= intern (":slant");
6237 staticpro (&QCslant
);
6238 QCunderline
= intern (":underline");
6239 staticpro (&QCunderline
);
6240 QCinverse_video
= intern (":inverse-video");
6241 staticpro (&QCinverse_video
);
6242 QCreverse_video
= intern (":reverse-video");
6243 staticpro (&QCreverse_video
);
6244 QCforeground
= intern (":foreground");
6245 staticpro (&QCforeground
);
6246 QCbackground
= intern (":background");
6247 staticpro (&QCbackground
);
6248 QCstipple
= intern (":stipple");;
6249 staticpro (&QCstipple
);
6250 QCwidth
= intern (":width");
6251 staticpro (&QCwidth
);
6252 QCfont
= intern (":font");
6253 staticpro (&QCfont
);
6254 QCbold
= intern (":bold");
6255 staticpro (&QCbold
);
6256 QCitalic
= intern (":italic");
6257 staticpro (&QCitalic
);
6258 QCoverline
= intern (":overline");
6259 staticpro (&QCoverline
);
6260 QCstrike_through
= intern (":strike-through");
6261 staticpro (&QCstrike_through
);
6262 QCbox
= intern (":box");
6265 /* Symbols used for Lisp face attribute values. */
6266 QCcolor
= intern (":color");
6267 staticpro (&QCcolor
);
6268 QCline_width
= intern (":line-width");
6269 staticpro (&QCline_width
);
6270 QCstyle
= intern (":style");
6271 staticpro (&QCstyle
);
6272 Qreleased_button
= intern ("released-button");
6273 staticpro (&Qreleased_button
);
6274 Qpressed_button
= intern ("pressed-button");
6275 staticpro (&Qpressed_button
);
6276 Qnormal
= intern ("normal");
6277 staticpro (&Qnormal
);
6278 Qultra_light
= intern ("ultra-light");
6279 staticpro (&Qultra_light
);
6280 Qextra_light
= intern ("extra-light");
6281 staticpro (&Qextra_light
);
6282 Qlight
= intern ("light");
6283 staticpro (&Qlight
);
6284 Qsemi_light
= intern ("semi-light");
6285 staticpro (&Qsemi_light
);
6286 Qsemi_bold
= intern ("semi-bold");
6287 staticpro (&Qsemi_bold
);
6288 Qbold
= intern ("bold");
6290 Qextra_bold
= intern ("extra-bold");
6291 staticpro (&Qextra_bold
);
6292 Qultra_bold
= intern ("ultra-bold");
6293 staticpro (&Qultra_bold
);
6294 Qoblique
= intern ("oblique");
6295 staticpro (&Qoblique
);
6296 Qitalic
= intern ("italic");
6297 staticpro (&Qitalic
);
6298 Qreverse_oblique
= intern ("reverse-oblique");
6299 staticpro (&Qreverse_oblique
);
6300 Qreverse_italic
= intern ("reverse-italic");
6301 staticpro (&Qreverse_italic
);
6302 Qultra_condensed
= intern ("ultra-condensed");
6303 staticpro (&Qultra_condensed
);
6304 Qextra_condensed
= intern ("extra-condensed");
6305 staticpro (&Qextra_condensed
);
6306 Qcondensed
= intern ("condensed");
6307 staticpro (&Qcondensed
);
6308 Qsemi_condensed
= intern ("semi-condensed");
6309 staticpro (&Qsemi_condensed
);
6310 Qsemi_expanded
= intern ("semi-expanded");
6311 staticpro (&Qsemi_expanded
);
6312 Qexpanded
= intern ("expanded");
6313 staticpro (&Qexpanded
);
6314 Qextra_expanded
= intern ("extra-expanded");
6315 staticpro (&Qextra_expanded
);
6316 Qultra_expanded
= intern ("ultra-expanded");
6317 staticpro (&Qultra_expanded
);
6318 Qbackground_color
= intern ("background-color");
6319 staticpro (&Qbackground_color
);
6320 Qforeground_color
= intern ("foreground-color");
6321 staticpro (&Qforeground_color
);
6322 Qunspecified
= intern ("unspecified");
6323 staticpro (&Qunspecified
);
6325 Qx_charset_registry
= intern ("x-charset-registry");
6326 staticpro (&Qx_charset_registry
);
6327 Qface_alias
= intern ("face-alias");
6328 staticpro (&Qface_alias
);
6329 Qdefault
= intern ("default");
6330 staticpro (&Qdefault
);
6331 Qmode_line
= intern ("mode-line");
6332 staticpro (&Qmode_line
);
6333 Qtool_bar
= intern ("tool-bar");
6334 staticpro (&Qtool_bar
);
6335 Qregion
= intern ("region");
6336 staticpro (&Qregion
);
6337 Qfringe
= intern ("fringe");
6338 staticpro (&Qfringe
);
6339 Qheader_line
= intern ("header-line");
6340 staticpro (&Qheader_line
);
6341 Qscroll_bar
= intern ("scroll-bar");
6342 staticpro (&Qscroll_bar
);
6343 Qcursor
= intern ("cursor");
6344 staticpro (&Qcursor
);
6345 Qborder
= intern ("border");
6346 staticpro (&Qborder
);
6347 Qmouse
= intern ("mouse");
6348 staticpro (&Qmouse
);
6350 defsubr (&Sinternal_make_lisp_face
);
6351 defsubr (&Sinternal_lisp_face_p
);
6352 defsubr (&Sinternal_set_lisp_face_attribute
);
6353 #ifdef HAVE_X_WINDOWS
6354 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
6355 defsubr (&Sface_color_gray_p
);
6356 defsubr (&Sface_color_supported_p
);
6358 defsubr (&Sinternal_get_lisp_face_attribute
);
6359 defsubr (&Sinternal_lisp_face_attribute_values
);
6360 defsubr (&Sinternal_lisp_face_equal_p
);
6361 defsubr (&Sinternal_lisp_face_empty_p
);
6362 defsubr (&Sinternal_copy_lisp_face
);
6363 defsubr (&Sinternal_merge_in_global_face
);
6364 defsubr (&Sface_font
);
6365 defsubr (&Sframe_face_alist
);
6366 defsubr (&Sinternal_set_font_selection_order
);
6367 defsubr (&Sinternal_set_alternative_font_family_alist
);
6369 defsubr (&Sdump_face
);
6370 defsubr (&Sshow_face_resources
);
6371 #endif /* GLYPH_DEBUG */
6372 defsubr (&Sclear_face_cache
);
6374 DEFVAR_LISP ("font-list-limit", &Vfont_list_limit
,
6375 "*Limit for font matching.\n\
6376 If an integer > 0, font matching functions won't load more than\n\
6377 that number of fonts when searching for a matching font.");
6378 Vfont_list_limit
= make_number (DEFAULT_FONT_LIST_LIMIT
);
6380 DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults
,
6381 "List of global face definitions (for internal use only.)");
6382 Vface_new_frame_defaults
= Qnil
;
6384 DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple
,
6385 "*Default stipple pattern used on monochrome displays.\n\
6386 This stipple pattern is used on monochrome displays\n\
6387 instead of shades of gray for a face background color.\n\
6388 See `set-face-stipple' for possible values for this variable.");
6389 Vface_default_stipple
= build_string ("gray3");
6391 DEFVAR_LISP ("face-default-registry", &Vface_default_registry
,
6392 "Default registry and encoding to use.\n\
6393 This registry and encoding is used for unibyte text. It is set up\n\
6394 from the specified frame font when Emacs starts. (For internal use only.)");
6395 Vface_default_registry
= Qnil
;
6397 DEFVAR_LISP ("face-alternative-font-family-alist",
6398 &Vface_alternative_font_family_alist
, "");
6399 Vface_alternative_font_family_alist
= Qnil
;
6403 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed
,
6404 "Allowed scalable fonts.\n\
6405 A value of nil means don't allow any scalable fonts.\n\
6406 A value of t means allow any scalable font.\n\
6407 Otherwise, value must be a list of regular expressions. A font may be\n\
6408 scaled if its name matches a regular expression in the list.");
6409 Vscalable_fonts_allowed
= Qnil
;
6411 #endif /* SCALABLE_FONTS */
6413 #ifdef HAVE_X_WINDOWS
6414 defsubr (&Spixmap_spec_p
);
6415 defsubr (&Sx_list_fonts
);
6416 defsubr (&Sinternal_face_x_get_resource
);
6417 defsubr (&Sx_family_fonts
);
6418 defsubr (&Sx_font_family_list
);
6419 #endif /* HAVE_X_WINDOWS */
6421 /* TTY face support. */
6422 defsubr (&Sface_register_tty_color
);
6423 defsubr (&Sface_clear_tty_colors
);
6424 defsubr (&Stty_defined_colors
);
6425 Vface_tty_color_alist
= Qnil
;
6426 staticpro (&Vface_tty_color_alist
);