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 /* Names of basic faces. */
283 Lisp_Object Qdefault
, Qmodeline
, Qtoolbar
, Qregion
, Qbitmap_area
;
284 Lisp_Object Qtop_line
;
286 /* Default stipple pattern used on monochrome displays. This stipple
287 pattern is used on monochrome displays instead of shades of gray
288 for a face background color. See `set-face-stipple' for possible
289 values for this variable. */
291 Lisp_Object Vface_default_stipple
;
293 /* Default registry and encoding to use for charsets whose charset
294 symbols don't specify one. */
296 Lisp_Object Vface_default_registry
;
298 /* Alist of alternative font families. Each element is of the form
299 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
300 try FAMILY1, then FAMILY2, ... */
302 Lisp_Object Vface_alternative_font_family_alist
;
304 /* Allowed scalable fonts. A value of nil means don't allow any
305 scalable fonts. A value of t means allow the use of any scalable
306 font. Otherwise, value must be a list of regular expressions. A
307 font may be scaled if its name matches a regular expression in the
311 Lisp_Object Vscalable_fonts_allowed
;
314 /* The symbols `foreground-color' and `background-color' which can be
315 used as part of a `face' property. This is for compatibility with
318 Lisp_Object Qforeground_color
, Qbackground_color
;
320 /* The symbols `face' and `mouse-face' used as text properties. */
323 extern Lisp_Object Qmouse_face
;
325 /* Error symbol for wrong_type_argument in load_pixmap. */
327 Lisp_Object Qpixmap_spec_p
;
329 /* Alist of global face definitions. Each element is of the form
330 (FACE . LFACE) where FACE is a symbol naming a face and LFACE
331 is a Lisp vector of face attributes. These faces are used
332 to initialize faces for new frames. */
334 Lisp_Object Vface_new_frame_defaults
;
336 /* The next ID to assign to Lisp faces. */
338 static int next_lface_id
;
340 /* A vector mapping Lisp face Id's to face names. */
342 static Lisp_Object
*lface_id_to_name
;
343 static int lface_id_to_name_size
;
345 /* An alist of elements (COLOR-NAME . INDEX) mapping color names
346 to color indices for tty frames. */
348 Lisp_Object Vface_tty_color_alist
;
350 /* Counter for calls to clear_face_cache. If this counter reaches
351 CLEAR_FONT_TABLE_COUNT, and a frame has more than
352 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
354 static int clear_font_table_count
;
355 #define CLEAR_FONT_TABLE_COUNT 100
356 #define CLEAR_FONT_TABLE_NFONTS 10
358 /* Non-zero means face attributes have been changed since the last
359 redisplay. Used in redisplay_internal. */
361 int face_change_count
;
363 /* The total number of colors currently allocated. */
366 static int ncolors_allocated
;
367 static int npixmaps_allocated
;
373 /* Function prototypes. */
378 static int may_use_scalable_font_p
P_ ((struct font_name
*, char *));
379 static void set_font_frame_param
P_ ((Lisp_Object
, Lisp_Object
));
380 static int better_font_p
P_ ((int *, struct font_name
*, struct font_name
*,
382 static int first_font_matching
P_ ((struct frame
*f
, char *,
383 struct font_name
*));
384 static int x_face_list_fonts
P_ ((struct frame
*, char *,
385 struct font_name
*, int, int, int));
386 static int font_scalable_p
P_ ((struct font_name
*));
387 static Lisp_Object deduce_unibyte_registry
P_ ((struct frame
*, char *));
388 static int get_lface_attributes
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
*, int));
389 static int load_pixmap
P_ ((struct frame
*, Lisp_Object
, unsigned *, unsigned *));
390 static char *xstrdup
P_ ((char *));
391 static unsigned char *xstrlwr
P_ ((unsigned char *));
392 static void signal_error
P_ ((char *, Lisp_Object
));
393 static void display_message
P_ ((struct frame
*, char *, Lisp_Object
, Lisp_Object
));
394 static struct frame
*frame_or_selected_frame
P_ ((Lisp_Object
, int));
395 static void load_face_font_or_fontset
P_ ((struct frame
*, struct face
*, char *, int));
396 static unsigned long load_color
P_ ((struct frame
*,
399 enum lface_attribute_index
));
400 static void load_face_colors
P_ ((struct frame
*, struct face
*, Lisp_Object
*));
401 static void free_face_colors
P_ ((struct frame
*, struct face
*));
402 static int face_color_gray_p
P_ ((struct frame
*, char *));
403 static char *build_font_name
P_ ((struct font_name
*));
404 static void free_font_names
P_ ((struct font_name
*, int));
405 static int sorted_font_list
P_ ((struct frame
*, char *,
406 int (*cmpfn
) P_ ((const void *, const void *)),
407 struct font_name
**));
408 static int font_list
P_ ((struct frame
*, char *, char *, char *, struct font_name
**));
409 static int try_font_list
P_ ((struct frame
*, Lisp_Object
*, char *, char *, char *,
410 struct font_name
**));
411 static int cmp_font_names
P_ ((const void *, const void *));
412 static struct face
*realize_face
P_ ((struct face_cache
*,
413 Lisp_Object
*, int));
414 static struct face
*realize_x_face
P_ ((struct face_cache
*,
415 Lisp_Object
*, int));
416 static struct face
*realize_tty_face
P_ ((struct face_cache
*,
417 Lisp_Object
*, int));
418 static int realize_basic_faces
P_ ((struct frame
*));
419 static int realize_default_face
P_ ((struct frame
*));
420 static void realize_named_face
P_ ((struct frame
*, Lisp_Object
, int));
421 static int lface_fully_specified_p
P_ ((Lisp_Object
*));
422 static int lface_equal_p
P_ ((Lisp_Object
*, Lisp_Object
*));
423 static unsigned hash_string_case_insensitive
P_ ((Lisp_Object
));
424 static unsigned lface_hash
P_ ((Lisp_Object
*));
425 static int lface_same_font_attributes_p
P_ ((Lisp_Object
*, Lisp_Object
*));
426 static struct face_cache
*make_face_cache
P_ ((struct frame
*));
427 static void free_realized_face
P_ ((struct frame
*, struct face
*));
428 static void clear_face_gcs
P_ ((struct face_cache
*));
429 static void free_face_cache
P_ ((struct face_cache
*));
430 static int face_numeric_weight
P_ ((Lisp_Object
));
431 static int face_numeric_slant
P_ ((Lisp_Object
));
432 static int face_numeric_swidth
P_ ((Lisp_Object
));
433 static int face_fontset
P_ ((struct frame
*, Lisp_Object
*));
434 static char *choose_face_font
P_ ((struct frame
*, Lisp_Object
*, int,
436 static char *choose_face_fontset_font
P_ ((struct frame
*, Lisp_Object
*,
438 static void merge_face_vectors
P_ ((Lisp_Object
*from
, Lisp_Object
*));
439 static void merge_face_vector_with_property
P_ ((struct frame
*, Lisp_Object
*,
441 static int set_lface_from_font_name
P_ ((struct frame
*, Lisp_Object
, char *,
443 static Lisp_Object lface_from_face_name
P_ ((struct frame
*, Lisp_Object
, int));
444 static struct face
*make_realized_face
P_ ((Lisp_Object
*, int, Lisp_Object
));
445 static void free_realized_faces
P_ ((struct face_cache
*));
446 static char *best_matching_font
P_ ((struct frame
*, Lisp_Object
*,
447 struct font_name
*, int));
448 static void cache_face
P_ ((struct face_cache
*, struct face
*, unsigned));
449 static void uncache_face
P_ ((struct face_cache
*, struct face
*));
450 static int xlfd_numeric_slant
P_ ((struct font_name
*));
451 static int xlfd_numeric_weight
P_ ((struct font_name
*));
452 static int xlfd_numeric_swidth
P_ ((struct font_name
*));
453 static Lisp_Object xlfd_symbolic_slant
P_ ((struct font_name
*));
454 static Lisp_Object xlfd_symbolic_weight
P_ ((struct font_name
*));
455 static Lisp_Object xlfd_symbolic_swidth
P_ ((struct font_name
*));
456 static int xlfd_fixed_p
P_ ((struct font_name
*));
457 static int xlfd_numeric_value
P_ ((struct table_entry
*, int, struct font_name
*,
459 static Lisp_Object xlfd_symbolic_value
P_ ((struct table_entry
*, int,
460 struct font_name
*, int, int));
461 static struct table_entry
*xlfd_lookup_field_contents
P_ ((struct table_entry
*, int,
462 struct font_name
*, int));
464 #ifdef HAVE_X_WINDOWS
466 static int split_font_name
P_ ((struct frame
*, struct font_name
*, int));
467 static int xlfd_point_size
P_ ((struct frame
*, struct font_name
*));
468 static void sort_fonts
P_ ((struct frame
*, struct font_name
*, int,
469 int (*cmpfn
) P_ ((const void *, const void *))));
470 static GC x_create_gc
P_ ((struct frame
*, unsigned long, XGCValues
*));
471 static void x_free_gc
P_ ((struct frame
*, GC
));
472 static void clear_font_table
P_ ((struct frame
*));
474 #endif /* HAVE_X_WINDOWS */
477 /***********************************************************************
479 ***********************************************************************/
481 #ifdef HAVE_X_WINDOWS
483 /* Create and return a GC for use on frame F. GC values and mask
484 are given by XGCV and MASK. */
487 x_create_gc (f
, mask
, xgcv
)
494 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
501 /* Free GC which was used on frame F. */
509 xassert (--ngcs
>= 0);
510 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
514 #endif /* HAVE_X_WINDOWS */
517 /* Like strdup, but uses xmalloc. */
523 int len
= strlen (s
) + 1;
524 char *p
= (char *) xmalloc (len
);
530 /* Like stricmp. Used to compare parts of font names which are in
535 unsigned char *s1
, *s2
;
539 unsigned char c1
= tolower (*s1
);
540 unsigned char c2
= tolower (*s2
);
542 return c1
< c2
? -1 : 1;
547 return *s2
== 0 ? 0 : -1;
552 /* Like strlwr, which might not always be available. */
554 static unsigned char *
558 unsigned char *p
= s
;
567 /* Signal `error' with message S, and additional argument ARG. */
570 signal_error (s
, arg
)
574 Fsignal (Qerror
, Fcons (build_string (s
), Fcons (arg
, Qnil
)));
578 /* Display a message with format string FORMAT and arguments ARG1 and
579 ARG2 on frame F. Used to display errors if fonts, bitmaps, colors
580 etc. for a realized face on frame F cannot be loaded. (If we would
581 signal an error in these cases, we would end up in an infinite
582 recursion because this would stop realization, and the redisplay
583 triggered by the signal would try to realize that same face again.)
585 If basic faces of F are not realized, just add the message to the
586 messages buffer "*Messages*". Because Fmessage calls
587 echo_area_display which tries to realize basic faces again, we would
588 otherwise also end in an infinite recursion. */
591 display_message (f
, format
, arg1
, arg2
)
594 Lisp_Object arg1
, arg2
;
598 extern int waiting_for_input
;
600 /* Function note_mouse_highlight calls face_at_buffer_position which
601 may realize a face. If some attribute of that face is invalid,
602 say an invalid color, don't display an error to avoid calling
603 Lisp from XTread_socket. */
604 if (waiting_for_input
)
607 nargs
= make_number (DIM (args
));
608 args
[0] = build_string (format
);
612 if (f
->face_cache
->used
>= BASIC_FACE_ID_SENTINEL
)
613 Fmessage (nargs
, args
);
616 Lisp_Object msg
= Fformat (nargs
, args
);
617 char *buffer
= LSTRDUPA (msg
);
618 message_dolog (buffer
, strlen (buffer
), 1, 0);
623 /* If FRAME is nil, return selected_frame. Otherwise, check that
624 FRAME is a live frame, and return a pointer to it. NPARAM
625 is the parameter number of FRAME, for CHECK_LIVE_FRAME. This is
626 here because it's a frequent pattern in Lisp function definitions. */
628 static INLINE
struct frame
*
629 frame_or_selected_frame (frame
, nparam
)
639 CHECK_LIVE_FRAME (frame
, nparam
);
647 /***********************************************************************
649 ***********************************************************************/
651 /* Initialize face cache and basic faces for frame F. */
657 /* Make a face cache, if F doesn't have one. */
658 if (FRAME_FACE_CACHE (f
) == NULL
)
659 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
661 #ifdef HAVE_X_WINDOWS
662 /* Make the image cache. */
665 if (FRAME_X_IMAGE_CACHE (f
) == NULL
)
666 FRAME_X_IMAGE_CACHE (f
) = make_image_cache ();
667 ++FRAME_X_IMAGE_CACHE (f
)->refcount
;
669 #endif /* HAVE_X_WINDOWS */
671 /* Realize basic faces. Must have enough information in frame
672 parameters to realize basic faces at this point. */
673 #ifdef HAVE_X_WINDOWS
674 if (!FRAME_X_P (f
) || FRAME_X_WINDOW (f
))
676 if (!realize_basic_faces (f
))
681 /* Free face cache of frame F. Called from Fdelete_frame. */
687 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
691 free_face_cache (face_cache
);
692 FRAME_FACE_CACHE (f
) = NULL
;
695 #ifdef HAVE_X_WINDOWS
698 struct image_cache
*image_cache
= FRAME_X_IMAGE_CACHE (f
);
701 --image_cache
->refcount
;
702 if (image_cache
->refcount
== 0)
703 free_image_cache (f
);
706 #endif /* HAVE_X_WINDOWS */
710 /* Recompute basic faces for frame F. Call this after changing frame
711 parameters on which those faces depend, or when realized faces have
712 been freed due to changing attributes of named faces. */
715 recompute_basic_faces (f
)
718 if (FRAME_FACE_CACHE (f
))
720 int realized_p
= realize_basic_faces (f
);
721 xassert (realized_p
);
726 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
727 try to free unused fonts, too. */
730 clear_face_cache (clear_fonts_p
)
733 #ifdef HAVE_X_WINDOWS
734 Lisp_Object tail
, frame
;
738 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
740 /* From time to time see if we can unload some fonts. This also
741 frees all realized faces on all frames. Fonts needed by
742 faces will be loaded again when faces are realized again. */
743 clear_font_table_count
= 0;
745 FOR_EACH_FRAME (tail
, frame
)
749 && FRAME_X_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
751 free_all_realized_faces (frame
);
752 clear_font_table (f
);
758 /* Clear GCs of realized faces. */
759 FOR_EACH_FRAME (tail
, frame
)
764 clear_face_gcs (FRAME_FACE_CACHE (f
));
765 clear_image_cache (f
, 0);
769 #endif /* HAVE_X_WINDOWS */
773 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
774 "Clear face caches on all frames.\n\
775 Optional THOROUGHLY non-nil means try to free unused fonts, too.")
777 Lisp_Object thorougly
;
779 clear_face_cache (!NILP (thorougly
));
785 #ifdef HAVE_X_WINDOWS
788 /* Remove those fonts from the font table of frame F that are not used
789 by fontsets. Called from clear_face_cache from time to time. */
795 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
797 Lisp_Object rest
, frame
;
800 xassert (FRAME_X_P (f
));
802 used
= (char *) alloca (dpyinfo
->n_fonts
* sizeof *used
);
803 bzero (used
, dpyinfo
->n_fonts
* sizeof *used
);
805 /* For all frames with the same x_display_info as F, record
806 in `used' those fonts that are in use by fontsets. */
807 FOR_EACH_FRAME (rest
, frame
)
808 if (FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
810 struct frame
*f
= XFRAME (frame
);
811 struct fontset_data
*fontset_data
= FRAME_FONTSET_DATA (f
);
813 for (i
= 0; i
< fontset_data
->n_fontsets
; ++i
)
815 struct fontset_info
*info
= fontset_data
->fontset_table
[i
];
818 for (j
= 0; j
<= MAX_CHARSET
; ++j
)
820 int idx
= info
->font_indexes
[j
];
827 /* Free those fonts that are not used by fontsets. */
828 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
829 if (used
[i
] == 0 && dpyinfo
->font_table
[i
].name
)
831 struct font_info
*font_info
= dpyinfo
->font_table
+ i
;
833 /* Free names. In xfns.c there is a comment that full_name
834 should never be freed because it is always shared with
835 something else. I don't think this is true anymore---see
836 x_load_font. It's either equal to font_info->name or
837 allocated via xmalloc, and there seems to be no place in
838 the source files where full_name is transferred to another
840 if (font_info
->full_name
!= font_info
->name
)
841 xfree (font_info
->full_name
);
842 xfree (font_info
->name
);
846 XFreeFont (dpyinfo
->display
, font_info
->font
);
849 /* Mark font table slot free. */
850 font_info
->font
= NULL
;
851 font_info
->name
= font_info
->full_name
= NULL
;
856 #endif /* HAVE_X_WINDOWS */
860 /***********************************************************************
862 ***********************************************************************/
864 #ifdef HAVE_X_WINDOWS
866 DEFUN ("pixmap-spec-p", Fpixmap_spec_p
, Spixmap_spec_p
, 1, 1, 0,
867 "Non-nil if OBJECT is a valid pixmap specification.\n\
868 A pixmap specification is either a string, or a list (WIDTH HEIGHT DATA)\n\
869 where WIDTH is the pixel width of the pixmap, HEIGHT is its height,\n\
870 and DATA contains the bits of the pixmap.")
874 Lisp_Object height
, width
;
876 return ((STRINGP (object
)
878 && CONSP (XCONS (object
)->cdr
)
879 && CONSP (XCONS (XCONS (object
)->cdr
)->cdr
)
880 && NILP (XCONS (XCONS (XCONS (object
)->cdr
)->cdr
)->cdr
)
881 && (width
= XCONS (object
)->car
, INTEGERP (width
))
882 && (height
= XCONS (XCONS (object
)->cdr
)->car
,
884 && STRINGP (XCONS (XCONS (XCONS (object
)->cdr
)->cdr
)->car
)
887 /* The string must have enough bits for width * height. */
888 && ((XSTRING (XCONS (XCONS (XCONS (object
)->cdr
)->cdr
)->car
)->size
889 * (BITS_PER_INT
/ sizeof (int)))
890 >= XFASTINT (width
) * XFASTINT (height
))))
895 /* Load a bitmap according to NAME (which is either a file name or a
896 pixmap spec) for use on frame F. Value is the bitmap_id (see
897 xfns.c). If NAME is nil, return with a bitmap id of zero. If
898 bitmap cannot be loaded, display a message saying so, and return
899 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
900 if these pointers are not null. */
903 load_pixmap (f
, name
, w_ptr
, h_ptr
)
906 unsigned int *w_ptr
, *h_ptr
;
914 tem
= Fpixmap_spec_p (name
);
916 wrong_type_argument (Qpixmap_spec_p
, name
);
921 /* Decode a bitmap spec into a bitmap. */
926 w
= XINT (Fcar (name
));
927 h
= XINT (Fcar (Fcdr (name
)));
928 bits
= Fcar (Fcdr (Fcdr (name
)));
930 bitmap_id
= x_create_bitmap_from_data (f
, XSTRING (bits
)->data
,
935 /* It must be a string -- a file name. */
936 bitmap_id
= x_create_bitmap_from_file (f
, name
);
942 display_message (f
, "Invalid or undefined bitmap %s", name
, Qnil
);
953 ++npixmaps_allocated
;
956 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
959 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
965 #endif /* HAVE_X_WINDOWS */
969 /***********************************************************************
971 ***********************************************************************/
973 #ifdef HAVE_X_WINDOWS
975 /* Update the line_height of frame F. Return non-zero if line height
979 frame_update_line_height (f
)
982 int fontset
, line_height
, changed_p
;
984 fontset
= f
->output_data
.x
->fontset
;
986 line_height
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
]->height
;
988 line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
990 changed_p
= line_height
!= f
->output_data
.x
->line_height
;
991 f
->output_data
.x
->line_height
= line_height
;
995 #endif /* HAVE_X_WINDOWS */
998 /***********************************************************************
1000 ***********************************************************************/
1002 #ifdef HAVE_X_WINDOWS
1004 /* Load font or fontset of face FACE which is used on frame F.
1005 FONTSET is the fontset FACE should use or -1, if FACE doesn't use a
1006 fontset. FONT_NAME is the name of the font to load, if no fontset
1007 is used. It is null if no suitable font name could be determined
1011 load_face_font_or_fontset (f
, face
, font_name
, fontset
)
1017 struct font_info
*font_info
= NULL
;
1019 face
->font_info_id
= -1;
1020 face
->fontset
= fontset
;
1025 font_info
= FS_LOAD_FONT (f
, FRAME_X_FONT_TABLE (f
), CHARSET_ASCII
,
1028 font_info
= FS_LOAD_FONT (f
, FRAME_X_FONT_TABLE (f
), face
->charset
,
1037 face
->font_info_id
= FONT_INFO_ID (f
, font_info
);
1038 face
->font
= font_info
->font
;
1039 face
->font_name
= font_info
->full_name
;
1041 /* Make the registry part of the font name readily accessible.
1042 The registry is used to find suitable faces for unibyte text. */
1043 s
= font_info
->full_name
+ strlen (font_info
->full_name
);
1045 while (i
< 2 && --s
>= font_info
->full_name
)
1049 if (!STRINGP (face
->registry
)
1050 || xstricmp (XSTRING (face
->registry
)->data
, s
+ 1) != 0)
1052 if (STRINGP (Vface_default_registry
)
1053 && !xstricmp (XSTRING (Vface_default_registry
)->data
, s
+ 1))
1054 face
->registry
= Vface_default_registry
;
1056 face
->registry
= build_string (s
+ 1);
1059 else if (fontset
>= 0)
1060 display_message (f
, "Unable to load ASCII font of fontset %d",
1061 make_number (fontset
), Qnil
);
1063 display_message (f
, "Unable to load font %s",
1064 build_string (font_name
), Qnil
);
1067 #endif /* HAVE_X_WINDOWS */
1071 /***********************************************************************
1073 ***********************************************************************/
1075 #ifdef HAVE_X_WINDOWS
1077 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1078 black) on frame F. The algorithm is taken from 20.2 faces.el. */
1081 face_color_gray_p (f
, color_name
)
1088 if (defined_color (f
, color_name
, &color
, 0))
1089 gray_p
= ((abs (color
.red
- color
.green
)
1090 < max (color
.red
, color
.green
) / 20)
1091 && (abs (color
.green
- color
.blue
)
1092 < max (color
.green
, color
.blue
) / 20)
1093 && (abs (color
.blue
- color
.red
)
1094 < max (color
.blue
, color
.red
) / 20));
1102 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1103 BACKGROUND_P non-zero means the color will be used as background
1107 face_color_supported_p (f
, color_name
, background_p
)
1114 XSETFRAME (frame
, f
);
1115 return (!NILP (Vwindow_system
)
1116 && (!NILP (Fx_display_color_p (frame
))
1117 || xstricmp (color_name
, "black") == 0
1118 || xstricmp (color_name
, "white") == 0
1120 && face_color_gray_p (f
, color_name
))
1121 || (!NILP (Fx_display_grayscale_p (frame
))
1122 && face_color_gray_p (f
, color_name
))));
1126 DEFUN ("face-color-gray-p", Fface_color_gray_p
, Sface_color_gray_p
, 1, 2, 0,
1127 "Return non-nil if COLOR is a shade of gray (or white or black).\n\
1128 FRAME specifies the frame and thus the display for interpreting COLOR.\n\
1129 If FRAME is nil or omitted, use the selected frame.")
1131 Lisp_Object color
, frame
;
1133 struct frame
*f
= check_x_frame (frame
);
1134 CHECK_STRING (color
, 0);
1135 return face_color_gray_p (f
, XSTRING (color
)->data
) ? Qt
: Qnil
;
1139 DEFUN ("face-color-supported-p", Fface_color_supported_p
,
1140 Sface_color_supported_p
, 2, 3, 0,
1141 "Return non-nil if COLOR can be displayed on FRAME.\n\
1142 BACKGROUND-P non-nil means COLOR is used as a background.\n\
1143 If FRAME is nil or omitted, use the selected frame.\n\
1144 COLOR must be a valid color name.")
1145 (frame
, color
, background_p
)
1146 Lisp_Object frame
, color
, background_p
;
1148 struct frame
*f
= check_x_frame (frame
);
1149 CHECK_STRING (color
, 0);
1150 if (face_color_supported_p (f
, XSTRING (color
)->data
, !NILP (background_p
)))
1155 /* Load color with name NAME for use by face FACE on frame F.
1156 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1157 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1158 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1159 pixel color. If color cannot be loaded, display a message, and
1160 return the foreground, background or underline color of F, but
1161 record that fact in flags of the face so that we don't try to free
1164 static unsigned long
1165 load_color (f
, face
, name
, target_index
)
1169 enum lface_attribute_index target_index
;
1173 xassert (STRINGP (name
));
1174 xassert (target_index
== LFACE_FOREGROUND_INDEX
1175 || target_index
== LFACE_BACKGROUND_INDEX
1176 || target_index
== LFACE_UNDERLINE_INDEX
1177 || target_index
== LFACE_OVERLINE_INDEX
1178 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1179 || target_index
== LFACE_BOX_INDEX
);
1181 /* if the color map is full, defined_color will return a best match
1182 to the values in an existing cell. */
1183 if (!defined_color (f
, XSTRING (name
)->data
, &color
, 1))
1185 display_message (f
, "Unable to load color %s", name
, Qnil
);
1187 switch (target_index
)
1189 case LFACE_FOREGROUND_INDEX
:
1190 face
->foreground_defaulted_p
= 1;
1191 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1194 case LFACE_BACKGROUND_INDEX
:
1195 face
->background_defaulted_p
= 1;
1196 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1199 case LFACE_UNDERLINE_INDEX
:
1200 face
->underline_defaulted_p
= 1;
1201 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1204 case LFACE_OVERLINE_INDEX
:
1205 face
->overline_color_defaulted_p
= 1;
1206 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1209 case LFACE_STRIKE_THROUGH_INDEX
:
1210 face
->strike_through_color_defaulted_p
= 1;
1211 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1214 case LFACE_BOX_INDEX
:
1215 face
->box_color_defaulted_p
= 1;
1216 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1225 ++ncolors_allocated
;
1232 /* Load colors for face FACE which is used on frame F. Colors are
1233 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1234 of ATTRS. If the background color specified is not supported on F,
1235 try to emulate gray colors with a stipple from Vface_default_stipple. */
1238 load_face_colors (f
, face
, attrs
)
1245 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1246 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1248 /* Swap colors if face is inverse-video. */
1249 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1257 /* Check for support for foreground, not for background because
1258 face_color_supported_p is smart enough to know that grays are
1259 "supported" as background because we are supposed to use stipple
1261 if (!face_color_supported_p (f
, XSTRING (bg
)->data
, 0)
1262 && !NILP (Fpixmap_spec_p (Vface_default_stipple
)))
1264 x_destroy_bitmap (f
, face
->stipple
);
1265 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1266 &face
->pixmap_w
, &face
->pixmap_h
);
1269 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1271 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1275 /* Free color PIXEL on frame F. */
1278 unload_color (f
, pixel
)
1280 unsigned long pixel
;
1282 Display
*dpy
= FRAME_X_DISPLAY (f
);
1283 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
1285 if (pixel
== BLACK_PIX_DEFAULT (f
)
1286 || pixel
== WHITE_PIX_DEFAULT (f
))
1291 /* If display has an immutable color map, freeing colors is not
1292 necessary and some servers don't allow it. So don't do it. */
1293 if (! (class == StaticColor
|| class == StaticGray
|| class == TrueColor
))
1295 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
1296 XFreeColors (dpy
, cmap
, &pixel
, 1, 0);
1303 /* Free colors allocated for FACE. */
1306 free_face_colors (f
, face
)
1310 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
1312 /* If display has an immutable color map, freeing colors is not
1313 necessary and some servers don't allow it. So don't do it. */
1314 if (class != StaticColor
1315 && class != StaticGray
1316 && class != TrueColor
)
1322 dpy
= FRAME_X_DISPLAY (f
);
1323 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
1325 if (face
->foreground
!= BLACK_PIX_DEFAULT (f
)
1326 && face
->foreground
!= WHITE_PIX_DEFAULT (f
)
1327 && !face
->foreground_defaulted_p
)
1329 XFreeColors (dpy
, cmap
, &face
->foreground
, 1, 0);
1330 IF_DEBUG (--ncolors_allocated
);
1333 if (face
->background
!= BLACK_PIX_DEFAULT (f
)
1334 && face
->background
!= WHITE_PIX_DEFAULT (f
)
1335 && !face
->background_defaulted_p
)
1337 XFreeColors (dpy
, cmap
, &face
->background
, 1, 0);
1338 IF_DEBUG (--ncolors_allocated
);
1341 if (face
->underline_p
1342 && !face
->underline_defaulted_p
1343 && face
->underline_color
!= BLACK_PIX_DEFAULT (f
)
1344 && face
->underline_color
!= WHITE_PIX_DEFAULT (f
))
1346 XFreeColors (dpy
, cmap
, &face
->underline_color
, 1, 0);
1347 IF_DEBUG (--ncolors_allocated
);
1350 if (face
->overline_p
1351 && !face
->overline_color_defaulted_p
1352 && face
->overline_color
!= BLACK_PIX_DEFAULT (f
)
1353 && face
->overline_color
!= WHITE_PIX_DEFAULT (f
))
1355 XFreeColors (dpy
, cmap
, &face
->overline_color
, 1, 0);
1356 IF_DEBUG (--ncolors_allocated
);
1359 if (face
->strike_through_p
1360 && !face
->strike_through_color_defaulted_p
1361 && face
->strike_through_color
!= BLACK_PIX_DEFAULT (f
)
1362 && face
->strike_through_color
!= WHITE_PIX_DEFAULT (f
))
1364 XFreeColors (dpy
, cmap
, &face
->strike_through_color
, 1, 0);
1365 IF_DEBUG (--ncolors_allocated
);
1368 if (face
->box
!= FACE_NO_BOX
1369 && !face
->box_color_defaulted_p
1370 && face
->box_color
!= BLACK_PIX_DEFAULT (f
)
1371 && face
->box_color
!= WHITE_PIX_DEFAULT (f
))
1373 XFreeColors (dpy
, cmap
, &face
->box_color
, 1, 0);
1374 IF_DEBUG (--ncolors_allocated
);
1381 #endif /* HAVE_X_WINDOWS */
1385 /***********************************************************************
1387 ***********************************************************************/
1389 /* An enumerator for each field of an XLFD font name. */
1410 /* An enumerator for each possible slant value of a font. Taken from
1411 the XLFD specification. */
1419 XLFD_SLANT_REVERSE_ITALIC
,
1420 XLFD_SLANT_REVERSE_OBLIQUE
,
1424 /* Relative font weight according to XLFD documentation. */
1428 XLFD_WEIGHT_UNKNOWN
,
1429 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1430 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1431 XLFD_WEIGHT_LIGHT
, /* 30 */
1432 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1433 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1434 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1435 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1436 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1437 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1440 /* Relative proportionate width. */
1444 XLFD_SWIDTH_UNKNOWN
,
1445 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1446 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1447 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1448 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1449 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1450 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1451 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1452 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1453 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1456 /* Structure used for tables mapping XLFD weight, slant, and width
1457 names to numeric and symbolic values. */
1463 Lisp_Object
*symbol
;
1466 /* Table of XLFD slant names and their numeric and symbolic
1467 representations. This table must be sorted by slant names in
1470 static struct table_entry slant_table
[] =
1472 {"i", XLFD_SLANT_ITALIC
, &Qitalic
},
1473 {"o", XLFD_SLANT_OBLIQUE
, &Qoblique
},
1474 {"ot", XLFD_SLANT_OTHER
, &Qitalic
},
1475 {"r", XLFD_SLANT_ROMAN
, &Qnormal
},
1476 {"ri", XLFD_SLANT_REVERSE_ITALIC
, &Qreverse_italic
},
1477 {"ro", XLFD_SLANT_REVERSE_OBLIQUE
, &Qreverse_oblique
}
1480 /* Table of XLFD weight names. This table must be sorted by weight
1481 names in ascending order. */
1483 static struct table_entry weight_table
[] =
1485 {"black", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
},
1486 {"bold", XLFD_WEIGHT_BOLD
, &Qbold
},
1487 {"book", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1488 {"demibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1489 {"extralight", XLFD_WEIGHT_EXTRA_LIGHT
, &Qextra_light
},
1490 {"extrabold", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1491 {"heavy", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1492 {"light", XLFD_WEIGHT_LIGHT
, &Qlight
},
1493 {"medium", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1494 {"normal", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1495 {"regular", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1496 {"semibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1497 {"semilight", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1498 {"ultralight", XLFD_WEIGHT_ULTRA_LIGHT
, &Qultra_light
},
1499 {"ultrabold", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
}
1502 /* Table of XLFD width names. This table must be sorted by width
1503 names in ascending order. */
1505 static struct table_entry swidth_table
[] =
1507 {"compressed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1508 {"condensed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1509 {"demiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1510 {"expanded", XLFD_SWIDTH_EXPANDED
, &Qexpanded
},
1511 {"extracondensed", XLFD_SWIDTH_EXTRA_CONDENSED
, &Qextra_condensed
},
1512 {"extraexpanded", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
},
1513 {"medium", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1514 {"narrow", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1515 {"normal", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1516 {"regular", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1517 {"semicondensed", XLFD_SWIDTH_SEMI_CONDENSED
, &Qsemi_condensed
},
1518 {"semiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1519 {"ultracondensed", XLFD_SWIDTH_ULTRA_CONDENSED
, &Qultra_condensed
},
1520 {"ultraexpanded", XLFD_SWIDTH_ULTRA_EXPANDED
, &Qultra_expanded
},
1521 {"wide", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
}
1524 /* Structure used to hold the result of splitting font names in XLFD
1525 format into their fields. */
1529 /* The original name which is modified destructively by
1530 split_font_name. The pointer is kept here to be able to free it
1531 if it was allocated from the heap. */
1534 /* Font name fields. Each vector element points into `name' above.
1535 Fields are NUL-terminated. */
1536 char *fields
[XLFD_LAST
];
1538 /* Numeric values for those fields that interest us. See
1539 split_font_name for which these are. */
1540 int numeric
[XLFD_LAST
];
1543 /* The frame in effect when sorting font names. Set temporarily in
1544 sort_fonts so that it is available in font comparison functions. */
1546 static struct frame
*font_frame
;
1548 /* Order by which font selection chooses fonts. The default values
1549 mean `first, find a best match for the font width, then for the
1550 font height, then for weight, then for slant.' This variable can be
1551 set via set-face-font-sort-order. */
1553 static int font_sort_order
[4];
1556 /* Look up FONT.fields[FIELD_INDEX] in TABLE which has DIM entries.
1557 TABLE must be sorted by TABLE[i]->name in ascending order. Value
1558 is a pointer to the matching table entry or null if no table entry
1561 static struct table_entry
*
1562 xlfd_lookup_field_contents (table
, dim
, font
, field_index
)
1563 struct table_entry
*table
;
1565 struct font_name
*font
;
1568 /* Function split_font_name converts fields to lower-case, so there
1569 is no need to use xstrlwr or xstricmp here. */
1570 char *s
= font
->fields
[field_index
];
1571 int low
, mid
, high
, cmp
;
1578 mid
= (low
+ high
) / 2;
1579 cmp
= strcmp (table
[mid
].name
, s
);
1593 /* Return a numeric representation for font name field
1594 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
1595 has DIM entries. Value is the numeric value found or DFLT if no
1596 table entry matches. This function is used to translate weight,
1597 slant, and swidth names of XLFD font names to numeric values. */
1600 xlfd_numeric_value (table
, dim
, font
, field_index
, dflt
)
1601 struct table_entry
*table
;
1603 struct font_name
*font
;
1607 struct table_entry
*p
;
1608 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
1609 return p
? p
->numeric
: dflt
;
1613 /* Return a symbolic representation for font name field
1614 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
1615 has DIM entries. Value is the symbolic value found or DFLT if no
1616 table entry matches. This function is used to translate weight,
1617 slant, and swidth names of XLFD font names to symbols. */
1619 static INLINE Lisp_Object
1620 xlfd_symbolic_value (table
, dim
, font
, field_index
, dflt
)
1621 struct table_entry
*table
;
1623 struct font_name
*font
;
1627 struct table_entry
*p
;
1628 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
1629 return p
? *p
->symbol
: dflt
;
1633 /* Return a numeric value for the slant of the font given by FONT. */
1636 xlfd_numeric_slant (font
)
1637 struct font_name
*font
;
1639 return xlfd_numeric_value (slant_table
, DIM (slant_table
),
1640 font
, XLFD_SLANT
, XLFD_SLANT_ROMAN
);
1644 /* Return a symbol representing the weight of the font given by FONT. */
1646 static INLINE Lisp_Object
1647 xlfd_symbolic_slant (font
)
1648 struct font_name
*font
;
1650 return xlfd_symbolic_value (slant_table
, DIM (slant_table
),
1651 font
, XLFD_SLANT
, Qnormal
);
1655 /* Return a numeric value for the weight of the font given by FONT. */
1658 xlfd_numeric_weight (font
)
1659 struct font_name
*font
;
1661 return xlfd_numeric_value (weight_table
, DIM (weight_table
),
1662 font
, XLFD_WEIGHT
, XLFD_WEIGHT_MEDIUM
);
1666 /* Return a symbol representing the slant of the font given by FONT. */
1668 static INLINE Lisp_Object
1669 xlfd_symbolic_weight (font
)
1670 struct font_name
*font
;
1672 return xlfd_symbolic_value (weight_table
, DIM (weight_table
),
1673 font
, XLFD_WEIGHT
, Qnormal
);
1677 /* Return a numeric value for the swidth of the font whose XLFD font
1678 name fields are found in FONT. */
1681 xlfd_numeric_swidth (font
)
1682 struct font_name
*font
;
1684 return xlfd_numeric_value (swidth_table
, DIM (swidth_table
),
1685 font
, XLFD_SWIDTH
, XLFD_SWIDTH_MEDIUM
);
1689 /* Return a symbolic value for the swidth of FONT. */
1691 static INLINE Lisp_Object
1692 xlfd_symbolic_swidth (font
)
1693 struct font_name
*font
;
1695 return xlfd_symbolic_value (swidth_table
, DIM (swidth_table
),
1696 font
, XLFD_SWIDTH
, Qnormal
);
1700 /* Look up the entry of SYMBOL in the vector TABLE which has DIM
1701 entries. Value is a pointer to the matching table entry or null if
1702 no element of TABLE contains SYMBOL. */
1704 static struct table_entry
*
1705 face_value (table
, dim
, symbol
)
1706 struct table_entry
*table
;
1712 xassert (SYMBOLP (symbol
));
1714 for (i
= 0; i
< dim
; ++i
)
1715 if (EQ (*table
[i
].symbol
, symbol
))
1718 return i
< dim
? table
+ i
: NULL
;
1722 /* Return a numeric value for SYMBOL in the vector TABLE which has DIM
1723 entries. Value is -1 if SYMBOL is not found in TABLE. */
1726 face_numeric_value (table
, dim
, symbol
)
1727 struct table_entry
*table
;
1731 struct table_entry
*p
= face_value (table
, dim
, symbol
);
1732 return p
? p
->numeric
: -1;
1736 /* Return a numeric value representing the weight specified by Lisp
1737 symbol WEIGHT. Value is one of the enumerators of enum
1741 face_numeric_weight (weight
)
1744 return face_numeric_value (weight_table
, DIM (weight_table
), weight
);
1748 /* Return a numeric value representing the slant specified by Lisp
1749 symbol SLANT. Value is one of the enumerators of enum xlfd_slant. */
1752 face_numeric_slant (slant
)
1755 return face_numeric_value (slant_table
, DIM (slant_table
), slant
);
1759 /* Return a numeric value representing the swidth specified by Lisp
1760 symbol WIDTH. Value is one of the enumerators of enum xlfd_swidth. */
1763 face_numeric_swidth (width
)
1766 return face_numeric_value (swidth_table
, DIM (swidth_table
), width
);
1770 #ifdef HAVE_X_WINDOWS
1772 /* Return non-zero if FONT is the name of a fixed-pitch font. */
1776 struct font_name
*font
;
1778 /* Function split_font_name converts fields to lower-case, so there
1779 is no need to use tolower here. */
1780 return *font
->fields
[XLFD_SPACING
] != 'p';
1784 /* Return the point size of FONT on frame F, measured in 1/10 pt.
1786 The actual height of the font when displayed on F depends on the
1787 resolution of both the font and frame. For example, a 10pt font
1788 designed for a 100dpi display will display larger than 10pt on a
1789 75dpi display. (It's not unusual to use fonts not designed for the
1790 display one is using. For example, some intlfonts are available in
1791 72dpi versions, only.)
1793 Value is the real point size of FONT on frame F, or 0 if it cannot
1797 xlfd_point_size (f
, font
)
1799 struct font_name
*font
;
1801 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
1802 double font_resy
= atoi (font
->fields
[XLFD_RESY
]);
1803 double font_pt
= atoi (font
->fields
[XLFD_POINT_SIZE
]);
1806 if (font_resy
== 0 || font_pt
== 0)
1809 real_pt
= (font_resy
/ resy
) * font_pt
+ 0.5;
1815 /* Split XLFD font name FONT->name destructively into NUL-terminated,
1816 lower-case fields in FONT->fields. NUMERIC_P non-zero means
1817 compute numeric values for fields XLFD_POINT_SIZE, XLFD_SWIDTH,
1818 XLFD_RESY, XLFD_SLANT, and XLFD_WEIGHT in FONT->numeric. Value is
1819 zero if the font name doesn't have the format we expect. The
1820 expected format is a font name that starts with a `-' and has
1821 XLFD_LAST fields separated by `-'. (The XLFD specification allows
1822 forms of font names where certain field contents are enclosed in
1823 square brackets. We don't support that, for now. */
1826 split_font_name (f
, font
, numeric_p
)
1828 struct font_name
*font
;
1834 if (*font
->name
== '-')
1836 char *p
= xstrlwr (font
->name
) + 1;
1838 while (i
< XLFD_LAST
)
1840 font
->fields
[i
] = p
;
1843 while (*p
&& *p
!= '-')
1853 success_p
= i
== XLFD_LAST
;
1855 /* If requested, and font name was in the expected format,
1856 compute numeric values for some fields. */
1857 if (numeric_p
&& success_p
)
1859 font
->numeric
[XLFD_POINT_SIZE
] = xlfd_point_size (f
, font
);
1860 font
->numeric
[XLFD_RESY
] = atoi (font
->fields
[XLFD_RESY
]);
1861 font
->numeric
[XLFD_SLANT
] = xlfd_numeric_slant (font
);
1862 font
->numeric
[XLFD_WEIGHT
] = xlfd_numeric_weight (font
);
1863 font
->numeric
[XLFD_SWIDTH
] = xlfd_numeric_swidth (font
);
1870 /* Build an XLFD font name from font name fields in FONT. Value is a
1871 pointer to the font name, which is allocated via xmalloc. */
1874 build_font_name (font
)
1875 struct font_name
*font
;
1879 char *font_name
= (char *) xmalloc (size
);
1880 int total_length
= 0;
1882 for (i
= 0; i
< XLFD_LAST
; ++i
)
1884 /* Add 1 because of the leading `-'. */
1885 int len
= strlen (font
->fields
[i
]) + 1;
1887 /* Reallocate font_name if necessary. Add 1 for the final
1889 if (total_length
+ len
+ 1 >= size
)
1891 int new_size
= max (2 * size
, size
+ len
+ 1);
1892 int sz
= new_size
* sizeof *font_name
;
1893 font_name
= (char *) xrealloc (font_name
, sz
);
1897 font_name
[total_length
] = '-';
1898 bcopy (font
->fields
[i
], font_name
+ total_length
+ 1, len
- 1);
1899 total_length
+= len
;
1902 font_name
[total_length
] = 0;
1907 /* Free an array FONTS of N font_name structures. This frees FONTS
1908 itself and all `name' fields in its elements. */
1911 free_font_names (fonts
, n
)
1912 struct font_name
*fonts
;
1916 xfree (fonts
[--n
].name
);
1921 /* Sort vector FONTS of font_name structures which contains NFONTS
1922 elements using qsort and comparison function CMPFN. F is the frame
1923 on which the fonts will be used. The global variable font_frame
1924 is temporarily set to F to make it available in CMPFN. */
1927 sort_fonts (f
, fonts
, nfonts
, cmpfn
)
1929 struct font_name
*fonts
;
1931 int (*cmpfn
) P_ ((const void *, const void *));
1934 qsort (fonts
, nfonts
, sizeof *fonts
, cmpfn
);
1939 /* Get fonts matching PATTERN on frame F. If F is null, use the first
1940 display in x_display_list. FONTS is a pointer to a vector of
1941 NFONTS font_name structures. TRY_ALTERNATIVES_P non-zero means try
1942 alternative patterns from Valternate_fontname_alist if no fonts are
1943 found matching PATTERN. SCALABLE_FONTS_P non-zero means include
1946 For all fonts found, set FONTS[i].name to the name of the font,
1947 allocated via xmalloc, and split font names into fields. Ignore
1948 fonts that we can't parse. Value is the number of fonts found.
1950 This is similar to x_list_fonts. The differences are:
1952 1. It avoids consing.
1953 2. It never calls XLoadQueryFont. */
1956 x_face_list_fonts (f
, pattern
, fonts
, nfonts
, try_alternatives_p
,
1960 struct font_name
*fonts
;
1961 int nfonts
, try_alternatives_p
;
1962 int scalable_fonts_p
;
1964 Display
*dpy
= f
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
1968 /* Get the list of fonts matching PATTERN from the X server. */
1970 names
= XListFonts (dpy
, pattern
, nfonts
, &n
);
1975 /* Make a copy of the font names we got from X, and
1976 split them into fields. */
1977 for (i
= j
= 0; i
< n
; ++i
)
1979 /* Make a copy of the font name. */
1980 fonts
[j
].name
= xstrdup (names
[i
]);
1982 /* Ignore fonts having a name that we can't parse. */
1983 if (!split_font_name (f
, fonts
+ j
, 1))
1984 xfree (fonts
[j
].name
);
1985 else if (font_scalable_p (fonts
+ j
))
1988 if (!scalable_fonts_p
1989 || !may_use_scalable_font_p (fonts
+ j
, names
[i
]))
1990 xfree (fonts
[j
].name
);
1993 #else /* !SCALABLE_FONTS */
1994 /* Always ignore scalable fonts. */
1995 xfree (fonts
[j
].name
);
1996 #endif /* !SCALABLE_FONTS */
2004 /* Free font names. */
2006 XFreeFontNames (names
);
2011 /* If no fonts found, try patterns from Valternate_fontname_alist. */
2012 if (n
== 0 && try_alternatives_p
)
2014 Lisp_Object list
= Valternate_fontname_alist
;
2016 while (CONSP (list
))
2018 Lisp_Object entry
= XCAR (list
);
2020 && STRINGP (XCAR (entry
))
2021 && strcmp (XSTRING (XCAR (entry
))->data
, pattern
) == 0)
2028 Lisp_Object patterns
= XCAR (list
);
2031 while (CONSP (patterns
)
2032 /* If list is screwed up, give up. */
2033 && (name
= XCAR (patterns
),
2035 /* Ignore patterns equal to PATTERN because we tried that
2036 already with no success. */
2037 && (strcmp (XSTRING (name
)->data
, pattern
) == 0
2038 || (n
= x_face_list_fonts (f
, XSTRING (name
)->data
,
2042 patterns
= XCDR (patterns
);
2050 /* Determine the first font matching PATTERN on frame F. Return in
2051 *FONT the matching font name, split into fields. Value is non-zero
2052 if a match was found. */
2055 first_font_matching (f
, pattern
, font
)
2058 struct font_name
*font
;
2061 struct font_name
*fonts
;
2063 fonts
= (struct font_name
*) xmalloc (nfonts
* sizeof *fonts
);
2064 nfonts
= x_face_list_fonts (f
, pattern
, fonts
, nfonts
, 1, 0);
2068 bcopy (&fonts
[0], font
, sizeof *font
);
2070 fonts
[0].name
= NULL
;
2071 free_font_names (fonts
, nfonts
);
2078 /* Determine fonts matching PATTERN on frame F. Sort resulting fonts
2079 using comparison function CMPFN. Value is the number of fonts
2080 found. If value is non-zero, *FONTS is set to a vector of
2081 font_name structures allocated from the heap containing matching
2082 fonts. Each element of *FONTS contains a name member that is also
2083 allocated from the heap. Font names in these structures are split
2084 into fields. Use free_font_names to free such an array. */
2087 sorted_font_list (f
, pattern
, cmpfn
, fonts
)
2090 int (*cmpfn
) P_ ((const void *, const void *));
2091 struct font_name
**fonts
;
2095 /* Get the list of fonts matching pattern. 100 should suffice. */
2097 *fonts
= (struct font_name
*) xmalloc (nfonts
* sizeof **fonts
);
2099 nfonts
= x_face_list_fonts (f
, pattern
, *fonts
, nfonts
, 1, 1);
2101 nfonts
= x_face_list_fonts (f
, pattern
, *fonts
, nfonts
, 1, 0);
2104 /* Sort the resulting array and return it in *FONTS. If no
2105 fonts were found, make sure to set *FONTS to null. */
2107 sort_fonts (f
, *fonts
, nfonts
, cmpfn
);
2118 /* Compare two font_name structures *A and *B. Value is analogous to
2119 strcmp. Sort order is given by the global variable
2120 font_sort_order. Font names are sorted so that, everything else
2121 being equal, fonts with a resolution closer to that of the frame on
2122 which they are used are listed first. The global variable
2123 font_frame is the frame on which we operate. */
2126 cmp_font_names (a
, b
)
2129 struct font_name
*x
= (struct font_name
*) a
;
2130 struct font_name
*y
= (struct font_name
*) b
;
2133 /* All strings have been converted to lower-case by split_font_name,
2134 so we can use strcmp here. */
2135 cmp
= strcmp (x
->fields
[XLFD_FAMILY
], y
->fields
[XLFD_FAMILY
]);
2140 for (i
= 0; i
< DIM (font_sort_order
) && cmp
== 0; ++i
)
2142 int j
= font_sort_order
[i
];
2143 cmp
= x
->numeric
[j
] - y
->numeric
[j
];
2148 /* Everything else being equal, we prefer fonts with an
2149 y-resolution closer to that of the frame. */
2150 int resy
= FRAME_X_DISPLAY_INFO (font_frame
)->resy
;
2151 int x_resy
= x
->numeric
[XLFD_RESY
];
2152 int y_resy
= y
->numeric
[XLFD_RESY
];
2153 cmp
= abs (resy
- x_resy
) - abs (resy
- y_resy
);
2161 /* Get a sorted list of fonts of family FAMILY on frame F. If PATTERN
2162 is non-null list fonts matching that pattern. Otherwise, if
2163 REGISTRY_AND_ENCODING is non-null return only fonts with that
2164 registry and encoding, otherwise return fonts of any registry and
2165 encoding. Set *FONTS to a vector of font_name structures allocated
2166 from the heap containing the fonts found. Value is the number of
2170 font_list (f
, pattern
, family
, registry_and_encoding
, fonts
)
2174 char *registry_and_encoding
;
2175 struct font_name
**fonts
;
2177 if (pattern
== NULL
)
2182 if (registry_and_encoding
== NULL
)
2183 registry_and_encoding
= "*";
2185 pattern
= (char *) alloca (strlen (family
)
2186 + strlen (registry_and_encoding
)
2188 if (index (family
, '-'))
2189 sprintf (pattern
, "-%s-*-%s", family
, registry_and_encoding
);
2191 sprintf (pattern
, "-*-%s-*-%s", family
, registry_and_encoding
);
2194 return sorted_font_list (f
, pattern
, cmp_font_names
, fonts
);
2198 /* Remove elements from LIST whose cars are `equal'. Called from
2199 x-font-list and x-font-family-list to remove duplicate font
2203 remove_duplicates (list
)
2206 Lisp_Object tail
= list
;
2208 while (!NILP (tail
) && !NILP (XCDR (tail
)))
2210 Lisp_Object next
= XCDR (tail
);
2211 if (!NILP (Fequal (XCAR (next
), XCAR (tail
))))
2212 XCDR (tail
) = XCDR (next
);
2219 DEFUN ("x-font-list", Fxfont_list
, Sx_font_list
, 0, 2, 0,
2220 "Return a list of available fonts of family FAMILY on FRAME.\n\
2221 If FAMILY is omitted or nil, list all families.\n\
2222 Otherwise, FAMILY must be a string, possibly containing wildcards\n\
2224 If FRAME is omitted or nil, use the selected frame.\n\
2225 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT\n\
2227 FAMILY is the font family name. POINT-SIZE is the size of the\n\
2228 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the\n\
2229 width, weight and slant of the font. These symbols are the same as for\n\
2230 face attributes. FIXED-P is non-nil if the font is fixed-pitch.\n\
2231 The result list is sorted according to the current setting of\n\
2232 the face font sort order.")
2234 Lisp_Object family
, frame
;
2236 struct frame
*f
= check_x_frame (frame
);
2237 struct font_name
*fonts
;
2240 struct gcpro gcpro1
;
2241 char *family_pattern
;
2244 family_pattern
= "*";
2247 CHECK_STRING (family
, 1);
2248 family_pattern
= LSTRDUPA (family
);
2253 nfonts
= font_list (f
, NULL
, family_pattern
, NULL
, &fonts
);
2254 for (i
= nfonts
- 1; i
>= 0; --i
)
2256 Lisp_Object v
= Fmake_vector (make_number (6), Qnil
);
2258 #define ASET(VECTOR, IDX, VAL) (XVECTOR (VECTOR)->contents[IDX] = (VAL))
2260 ASET (v
, 0, build_string (fonts
[i
].fields
[XLFD_FAMILY
]));
2261 ASET (v
, 1, xlfd_symbolic_swidth (fonts
+ i
));
2262 ASET (v
, 2, make_number (xlfd_point_size (f
, fonts
+ i
)));
2263 ASET (v
, 3, xlfd_symbolic_weight (fonts
+ i
));
2264 ASET (v
, 4, xlfd_symbolic_slant (fonts
+ i
));
2265 ASET (v
, 5, xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
);
2266 result
= Fcons (v
, result
);
2271 remove_duplicates (result
);
2272 free_font_names (fonts
, nfonts
);
2278 DEFUN ("x-font-family-list", Fx_font_family_list
, Sx_font_family_list
,
2280 "Return a list of available font families on FRAME.\n\
2281 If FRAME is omitted or nil, use the selected frame.\n\
2282 Value is a list of conses (FAMILY . FIXED-P) where FAMILY\n\
2283 is a font family, and FIXED-P is non-nil if fonts of that family\n\
2288 struct frame
*f
= check_x_frame (frame
);
2290 struct font_name
*fonts
;
2292 struct gcpro gcpro1
;
2294 nfonts
= font_list (f
, NULL
, "*", NULL
, &fonts
);
2297 for (i
= nfonts
- 1; i
>= 0; --i
)
2298 result
= Fcons (Fcons (build_string (fonts
[i
].fields
[XLFD_FAMILY
]),
2299 xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
),
2302 remove_duplicates (result
);
2303 free_font_names (fonts
, nfonts
);
2309 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
2310 "Return a list of the names of available fonts matching PATTERN.\n\
2311 If optional arguments FACE and FRAME are specified, return only fonts\n\
2312 the same size as FACE on FRAME.\n\
2313 PATTERN is a string, perhaps with wildcard characters;\n\
2314 the * character matches any substring, and\n\
2315 the ? character matches any single character.\n\
2316 PATTERN is case-insensitive.\n\
2317 FACE is a face name--a symbol.\n\
2319 The return value is a list of strings, suitable as arguments to\n\
2322 Fonts Emacs can't use may or may not be excluded\n\
2323 even if they match PATTERN and FACE.\n\
2324 The optional fourth argument MAXIMUM sets a limit on how many\n\
2325 fonts to match. The first MAXIMUM fonts are reported.\n\
2326 The optional fifth argument WIDTH, if specified, is a number of columns\n\
2327 occupied by a character of a font. In that case, return only fonts\n\
2328 the WIDTH times as wide as FACE on FRAME.")
2329 (pattern
, face
, frame
, maximum
, width
)
2330 Lisp_Object pattern
, face
, frame
, maximum
, width
;
2337 CHECK_STRING (pattern
, 0);
2343 CHECK_NATNUM (maximum
, 0);
2344 maxnames
= XINT (maximum
);
2348 CHECK_NUMBER (width
, 4);
2350 /* We can't simply call check_x_frame because this function may be
2351 called before any frame is created. */
2352 f
= frame_or_selected_frame (frame
, 2);
2355 /* Perhaps we have not yet created any frame. */
2360 /* Determine the width standard for comparison with the fonts we find. */
2366 /* This is of limited utility since it works with character
2367 widths. Keep it for compatibility. --gerd. */
2368 int face_id
= lookup_named_face (f
, face
, CHARSET_ASCII
);
2369 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2372 size
= face
->font
->max_bounds
.width
;
2374 size
= FRAME_FONT (f
)->max_bounds
.width
;
2377 size
*= XINT (width
);
2381 Lisp_Object args
[2];
2383 args
[0] = x_list_fonts (f
, pattern
, size
, maxnames
);
2385 /* We don't have to check fontsets. */
2387 args
[1] = list_fontsets (f
, pattern
, size
);
2388 return Fnconc (2, args
);
2392 #endif /* HAVE_X_WINDOWS */
2396 /***********************************************************************
2398 ***********************************************************************/
2400 /* Access face attributes of face FACE, a Lisp vector. */
2402 #define LFACE_FAMILY(LFACE) \
2403 XVECTOR (LFACE)->contents[LFACE_FAMILY_INDEX]
2404 #define LFACE_HEIGHT(LFACE) \
2405 XVECTOR (LFACE)->contents[LFACE_HEIGHT_INDEX]
2406 #define LFACE_WEIGHT(LFACE) \
2407 XVECTOR (LFACE)->contents[LFACE_WEIGHT_INDEX]
2408 #define LFACE_SLANT(LFACE) \
2409 XVECTOR (LFACE)->contents[LFACE_SLANT_INDEX]
2410 #define LFACE_UNDERLINE(LFACE) \
2411 XVECTOR (LFACE)->contents[LFACE_UNDERLINE_INDEX]
2412 #define LFACE_INVERSE(LFACE) \
2413 XVECTOR (LFACE)->contents[LFACE_INVERSE_INDEX]
2414 #define LFACE_FOREGROUND(LFACE) \
2415 XVECTOR (LFACE)->contents[LFACE_FOREGROUND_INDEX]
2416 #define LFACE_BACKGROUND(LFACE) \
2417 XVECTOR (LFACE)->contents[LFACE_BACKGROUND_INDEX]
2418 #define LFACE_STIPPLE(LFACE) \
2419 XVECTOR (LFACE)->contents[LFACE_STIPPLE_INDEX]
2420 #define LFACE_SWIDTH(LFACE) \
2421 XVECTOR (LFACE)->contents[LFACE_SWIDTH_INDEX]
2422 #define LFACE_OVERLINE(LFACE) \
2423 XVECTOR (LFACE)->contents[LFACE_OVERLINE_INDEX]
2424 #define LFACE_STRIKE_THROUGH(LFACE) \
2425 XVECTOR (LFACE)->contents[LFACE_STRIKE_THROUGH_INDEX]
2426 #define LFACE_BOX(LFACE) \
2427 XVECTOR (LFACE)->contents[LFACE_BOX_INDEX]
2429 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
2430 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
2432 #define LFACEP(LFACE) \
2434 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \
2435 && EQ (XVECTOR (LFACE)->contents[0], Qface))
2440 /* Check consistency of Lisp face attribute vector ATTRS. */
2443 check_lface_attrs (attrs
)
2446 xassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
2447 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
2448 xassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
2449 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
2450 xassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
2451 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
]));
2452 xassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
2453 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
2454 xassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
2455 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
2456 xassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
2457 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
2458 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]));
2459 xassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
2460 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
2461 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
2462 xassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
2463 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
2464 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
2465 xassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
2466 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
2467 || STRINGP (attrs
[LFACE_BOX_INDEX
])
2468 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
2469 || CONSP (attrs
[LFACE_BOX_INDEX
]));
2470 xassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
2471 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
2472 xassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
2473 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
2474 xassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
2475 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
2476 #ifdef HAVE_WINDOW_SYSTEM
2477 xassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
2478 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
2479 || !NILP (Fpixmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
2484 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
2492 xassert (LFACEP (lface
));
2493 check_lface_attrs (XVECTOR (lface
)->contents
);
2497 #else /* GLYPH_DEBUG == 0 */
2499 #define check_lface_attrs(attrs) (void) 0
2500 #define check_lface(lface) (void) 0
2502 #endif /* GLYPH_DEBUG == 0 */
2505 /* Return the face definition of FACE_NAME on frame F. F null means
2506 return the global definition. FACE_NAME may be a string or a
2507 symbol (apparently Emacs 20.2 allows strings as face names in face
2508 text properties; ediff uses that). If SIGNAL_P is non-zero, signal
2509 an error if FACE_NAME is not a valid face name. If SIGNAL_P is
2510 zero, value is nil if FACE_NAME is not a valid face name. */
2512 static INLINE Lisp_Object
2513 lface_from_face_name (f
, face_name
, signal_p
)
2515 Lisp_Object face_name
;
2520 if (STRINGP (face_name
))
2521 face_name
= intern (XSTRING (face_name
)->data
);
2524 lface
= assq_no_quit (face_name
, f
->face_alist
);
2526 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
2529 lface
= XCDR (lface
);
2531 signal_error ("Invalid face", face_name
);
2533 check_lface (lface
);
2538 /* Get face attributes of face FACE_NAME from frame-local faces on
2539 frame F. Store the resulting attributes in ATTRS which must point
2540 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
2541 is non-zero, signal an error if FACE_NAME does not name a face.
2542 Otherwise, value is zero if FACE_NAME is not a face. */
2545 get_lface_attributes (f
, face_name
, attrs
, signal_p
)
2547 Lisp_Object face_name
;
2554 lface
= lface_from_face_name (f
, face_name
, signal_p
);
2557 bcopy (XVECTOR (lface
)->contents
, attrs
,
2558 LFACE_VECTOR_SIZE
* sizeof *attrs
);
2568 /* Non-zero if all attributes in face attribute vector ATTRS are
2569 specified, i.e. are non-nil. */
2572 lface_fully_specified_p (attrs
)
2577 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2578 if (UNSPECIFIEDP (attrs
[i
]))
2581 return i
== LFACE_VECTOR_SIZE
;
2585 #ifdef HAVE_X_WINDOWS
2587 /* Set font-related attributes of Lisp face LFACE from XLFD font name
2588 FONT_NAME. If FORCE_P is zero, set only unspecified attributes of
2589 LFACE. Ignore fields of FONT_NAME containing wildcards. Value is
2590 zero if not successful because FONT_NAME was not in a valid format.
2591 A valid format is one that is suitable for split_font_name, see the
2595 set_lface_from_font_name (f
, lface
, font_name
, force_p
)
2601 struct font_name font
;
2604 int free_font_name_p
= 0;
2606 /* If FONT_NAME contains wildcards, use the first matching font. */
2607 if (index (font_name
, '*') || index (font_name
, '?'))
2609 if (!first_font_matching (f
, font_name
, &font
))
2611 free_font_name_p
= 1;
2615 font
.name
= STRDUPA (font_name
);
2616 if (!split_font_name (f
, &font
, 1))
2618 /* The font name may be something like `6x13'. Make
2619 sure we use the full name. */
2620 struct font_info
*font_info
;
2623 font_info
= fs_load_font (f
, FRAME_X_FONT_TABLE (f
),
2624 CHARSET_ASCII
, font_name
, -1);
2630 font
.name
= STRDUPA (font_info
->full_name
);
2631 split_font_name (f
, &font
, 1);
2634 /* FONT_NAME should not be a fontset name, here. */
2635 xassert (xstricmp (font
.fields
[XLFD_REGISTRY
], "fontset") != 0);
2638 /* Set attributes only if unspecified, otherwise face defaults for
2639 new frames would never take effect. */
2641 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
2643 buffer
= (char *) alloca (strlen (font
.fields
[XLFD_FAMILY
])
2644 + strlen (font
.fields
[XLFD_FOUNDRY
])
2646 sprintf (buffer
, "%s-%s", font
.fields
[XLFD_FOUNDRY
],
2647 font
.fields
[XLFD_FAMILY
]);
2648 LFACE_FAMILY (lface
) = build_string (buffer
);
2651 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
2653 pt
= xlfd_point_size (f
, &font
);
2655 LFACE_HEIGHT (lface
) = make_number (pt
);
2658 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
2659 LFACE_SWIDTH (lface
) = xlfd_symbolic_swidth (&font
);
2661 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
2662 LFACE_WEIGHT (lface
) = xlfd_symbolic_weight (&font
);
2664 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
2665 LFACE_SLANT (lface
) = xlfd_symbolic_slant (&font
);
2667 if (free_font_name_p
)
2673 #endif /* HAVE_X_WINDOWS */
2676 /* Merge two Lisp face attribute vectors FROM and TO and store the
2677 resulting attributes in TO. Every non-nil attribute of FROM
2678 overrides the corresponding attribute of TO. */
2681 merge_face_vectors (from
, to
)
2682 Lisp_Object
*from
, *to
;
2685 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2686 if (!UNSPECIFIEDP (from
[i
]))
2691 /* Given a Lisp face attribute vector TO and a Lisp object PROP that
2692 is a face property, determine the resulting face attributes on
2693 frame F, and store them in TO. PROP may be a single face
2694 specification or a list of such specifications. Each face
2695 specification can be
2697 1. A symbol or string naming a Lisp face.
2699 2. A property list of the form (KEYWORD VALUE ...) where each
2700 KEYWORD is a face attribute name, and value is an appropriate value
2703 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
2704 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
2705 for compatibility with 20.2.
2707 Face specifications earlier in lists take precedence over later
2711 merge_face_vector_with_property (f
, to
, prop
)
2718 Lisp_Object first
= XCAR (prop
);
2720 if (EQ (first
, Qforeground_color
)
2721 || EQ (first
, Qbackground_color
))
2723 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
2724 . COLOR). COLOR must be a string. */
2725 Lisp_Object color_name
= XCDR (prop
);
2726 Lisp_Object color
= first
;
2728 if (STRINGP (color_name
))
2730 if (EQ (color
, Qforeground_color
))
2731 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
2733 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
2736 display_message (f
, "Invalid face color", color_name
, Qnil
);
2738 else if (SYMBOLP (first
)
2739 && *XSYMBOL (first
)->name
->data
== ':')
2741 /* Assume this is the property list form. */
2742 while (CONSP (prop
) && CONSP (XCDR (prop
)))
2744 Lisp_Object keyword
= XCAR (prop
);
2745 Lisp_Object value
= XCAR (XCDR (prop
));
2747 if (EQ (keyword
, QCfamily
))
2749 if (STRINGP (value
))
2750 to
[LFACE_FAMILY_INDEX
] = value
;
2752 display_message (f
, "Illegal face font family",
2755 else if (EQ (keyword
, QCheight
))
2757 if (INTEGERP (value
))
2758 to
[LFACE_HEIGHT_INDEX
] = value
;
2760 display_message (f
, "Illegal face font height",
2763 else if (EQ (keyword
, QCweight
))
2766 && face_numeric_weight (value
) >= 0)
2767 to
[LFACE_WEIGHT_INDEX
] = value
;
2769 display_message (f
, "Illegal face weight", value
, Qnil
);
2771 else if (EQ (keyword
, QCslant
))
2774 && face_numeric_slant (value
) >= 0)
2775 to
[LFACE_SLANT_INDEX
] = value
;
2777 display_message (f
, "Illegal face slant", value
, Qnil
);
2779 else if (EQ (keyword
, QCunderline
))
2784 to
[LFACE_UNDERLINE_INDEX
] = value
;
2786 display_message (f
, "Illegal face underline", value
, Qnil
);
2788 else if (EQ (keyword
, QCoverline
))
2793 to
[LFACE_OVERLINE_INDEX
] = value
;
2795 display_message (f
, "Illegal face overline", value
, Qnil
);
2797 else if (EQ (keyword
, QCstrike_through
))
2802 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
2804 display_message (f
, "Illegal face strike-through",
2807 else if (EQ (keyword
, QCbox
))
2810 value
= make_number (1);
2811 if (INTEGERP (value
)
2815 to
[LFACE_BOX_INDEX
] = value
;
2817 display_message (f
, "Illegal face box", value
, Qnil
);
2819 else if (EQ (keyword
, QCinverse_video
)
2820 || EQ (keyword
, QCreverse_video
))
2822 if (EQ (value
, Qt
) || NILP (value
))
2823 to
[LFACE_INVERSE_INDEX
] = value
;
2825 display_message (f
, "Illegal face inverse-video",
2828 else if (EQ (keyword
, QCforeground
))
2830 if (STRINGP (value
))
2831 to
[LFACE_FOREGROUND_INDEX
] = value
;
2833 display_message (f
, "Illegal face foreground",
2836 else if (EQ (keyword
, QCbackground
))
2838 if (STRINGP (value
))
2839 to
[LFACE_BACKGROUND_INDEX
] = value
;
2841 display_message (f
, "Illegal face background",
2844 else if (EQ (keyword
, QCstipple
))
2846 #ifdef HAVE_X_WINDOWS
2847 Lisp_Object pixmap_p
= Fpixmap_spec_p (value
);
2848 if (!NILP (pixmap_p
))
2849 to
[LFACE_STIPPLE_INDEX
] = value
;
2851 display_message (f
, "Illegal face stipple", value
, Qnil
);
2854 else if (EQ (keyword
, QCwidth
))
2857 && face_numeric_swidth (value
) >= 0)
2858 to
[LFACE_SWIDTH_INDEX
] = value
;
2860 display_message (f
, "Illegal face width", value
, Qnil
);
2863 display_message (f
, "Invalid attribute %s in face property",
2866 prop
= XCDR (XCDR (prop
));
2871 /* This is a list of face specs. Specifications at the
2872 beginning of the list take precedence over later
2873 specifications, so we have to merge starting with the
2874 last specification. */
2875 Lisp_Object next
= XCDR (prop
);
2877 merge_face_vector_with_property (f
, to
, next
);
2878 merge_face_vector_with_property (f
, to
, first
);
2883 /* PROP ought to be a face name. */
2884 Lisp_Object lface
= lface_from_face_name (f
, prop
, 0);
2886 display_message (f
, "Invalid face text property value: %s",
2889 merge_face_vectors (XVECTOR (lface
)->contents
, to
);
2894 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
2895 Sinternal_make_lisp_face
, 1, 2, 0,
2896 "Make FACE, a symbol, a Lisp face with all attributes nil.\n\
2897 If FACE was not known as a face before, create a new one.\n\
2898 If optional argument FRAME is specified, make a frame-local face\n\
2899 for that frame. Otherwise operate on the global face definition.\n\
2900 Value is a vector of face attributes.")
2902 Lisp_Object face
, frame
;
2904 Lisp_Object global_lface
, lface
;
2908 CHECK_SYMBOL (face
, 0);
2909 global_lface
= lface_from_face_name (NULL
, face
, 0);
2913 CHECK_LIVE_FRAME (frame
, 1);
2915 lface
= lface_from_face_name (f
, face
, 0);
2918 f
= NULL
, lface
= Qnil
;
2920 /* Add a global definition if there is none. */
2921 if (NILP (global_lface
))
2923 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2925 XVECTOR (global_lface
)->contents
[0] = Qface
;
2926 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
2927 Vface_new_frame_defaults
);
2929 /* Assign the new Lisp face a unique ID. The mapping from Lisp
2930 face id to Lisp face is given by the vector lface_id_to_name.
2931 The mapping from Lisp face to Lisp face id is given by the
2932 property `face' of the Lisp face name. */
2933 if (next_lface_id
== lface_id_to_name_size
)
2935 int new_size
= max (50, 2 * lface_id_to_name_size
);
2936 int sz
= new_size
* sizeof *lface_id_to_name
;
2937 lface_id_to_name
= (Lisp_Object
*) xrealloc (lface_id_to_name
, sz
);
2938 lface_id_to_name_size
= new_size
;
2941 lface_id_to_name
[next_lface_id
] = face
;
2942 Fput (face
, Qface
, make_number (next_lface_id
));
2946 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2947 XVECTOR (global_lface
)->contents
[i
] = Qunspecified
;
2949 /* Add a frame-local definition. */
2954 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
2956 XVECTOR (lface
)->contents
[0] = Qface
;
2957 f
->face_alist
= Fcons (Fcons (face
, lface
), f
->face_alist
);
2960 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2961 XVECTOR (lface
)->contents
[i
] = Qunspecified
;
2964 lface
= global_lface
;
2966 xassert (LFACEP (lface
));
2967 check_lface (lface
);
2972 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
2973 Sinternal_lisp_face_p
, 1, 2, 0,
2974 "Return non-nil if FACE names a face.\n\
2975 If optional second parameter FRAME is non-nil, check for the\n\
2976 existence of a frame-local face with name FACE on that frame.\n\
2977 Otherwise check for the existence of a global face.")
2979 Lisp_Object face
, frame
;
2985 CHECK_LIVE_FRAME (frame
, 1);
2986 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
2989 lface
= lface_from_face_name (NULL
, face
, 0);
2995 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
2996 Sinternal_copy_lisp_face
, 4, 4, 0,
2997 "Copy face FROM to TO.\n\
2998 If FRAME it t, copy the global face definition of FROM to the\n\
2999 global face definition of TO. Otherwise, copy the frame-local\n\
3000 definition of FROM on FRAME to the frame-local definition of TO\n\
3001 on NEW-FRAME, or FRAME if NEW-FRAME is nil.\n\
3004 (from
, to
, frame
, new_frame
)
3005 Lisp_Object from
, to
, frame
, new_frame
;
3007 Lisp_Object lface
, copy
;
3009 CHECK_SYMBOL (from
, 0);
3010 CHECK_SYMBOL (to
, 1);
3011 if (NILP (new_frame
))
3016 /* Copy global definition of FROM. We don't make copies of
3017 strings etc. because 20.2 didn't do it either. */
3018 lface
= lface_from_face_name (NULL
, from
, 1);
3019 copy
= Finternal_make_lisp_face (to
, Qnil
);
3023 /* Copy frame-local definition of FROM. */
3024 CHECK_LIVE_FRAME (frame
, 2);
3025 CHECK_LIVE_FRAME (new_frame
, 3);
3026 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
3027 copy
= Finternal_make_lisp_face (to
, new_frame
);
3030 bcopy (XVECTOR (lface
)->contents
, XVECTOR (copy
)->contents
,
3031 LFACE_VECTOR_SIZE
* sizeof (Lisp_Object
));
3037 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
3038 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
3039 "Set attribute ATTR of FACE to VALUE.\n\
3040 If optional argument FRAME is given, set the face attribute of face FACE\n\
3041 on that frame. If FRAME is t, set the attribute of the default for face\n\
3042 FACE (for new frames). If FRAME is omitted or nil, use the selected\n\
3044 (face
, attr
, value
, frame
)
3045 Lisp_Object face
, attr
, value
, frame
;
3048 Lisp_Object old_value
= Qnil
;
3049 int font_related_attr_p
= 0;
3051 CHECK_SYMBOL (face
, 0);
3052 CHECK_SYMBOL (attr
, 1);
3054 /* Set lface to the Lisp attribute vector of FACE. */
3056 lface
= lface_from_face_name (NULL
, face
, 1);
3060 XSETFRAME (frame
, selected_frame
);
3062 CHECK_LIVE_FRAME (frame
, 3);
3063 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3065 /* If a frame-local face doesn't exist yet, create one. */
3067 lface
= Finternal_make_lisp_face (face
, frame
);
3070 if (EQ (attr
, QCfamily
))
3072 if (!UNSPECIFIEDP (value
))
3074 CHECK_STRING (value
, 3);
3075 if (XSTRING (value
)->size
== 0)
3076 signal_error ("Invalid face family", value
);
3078 old_value
= LFACE_FAMILY (lface
);
3079 LFACE_FAMILY (lface
) = value
;
3080 font_related_attr_p
= 1;
3082 else if (EQ (attr
, QCheight
))
3084 if (!UNSPECIFIEDP (value
))
3086 CHECK_NUMBER (value
, 3);
3087 if (XINT (value
) <= 0)
3088 signal_error ("Invalid face height", value
);
3090 old_value
= LFACE_HEIGHT (lface
);
3091 LFACE_HEIGHT (lface
) = value
;
3092 font_related_attr_p
= 1;
3094 else if (EQ (attr
, QCweight
))
3096 if (!UNSPECIFIEDP (value
))
3098 CHECK_SYMBOL (value
, 3);
3099 if (face_numeric_weight (value
) < 0)
3100 signal_error ("Invalid face weight", value
);
3102 old_value
= LFACE_WEIGHT (lface
);
3103 LFACE_WEIGHT (lface
) = value
;
3104 font_related_attr_p
= 1;
3106 else if (EQ (attr
, QCslant
))
3108 if (!UNSPECIFIEDP (value
))
3110 CHECK_SYMBOL (value
, 3);
3111 if (face_numeric_slant (value
) < 0)
3112 signal_error ("Invalid face slant", value
);
3114 old_value
= LFACE_SLANT (lface
);
3115 LFACE_SLANT (lface
) = value
;
3116 font_related_attr_p
= 1;
3118 else if (EQ (attr
, QCunderline
))
3120 if (!UNSPECIFIEDP (value
))
3121 if ((SYMBOLP (value
)
3123 && !EQ (value
, Qnil
))
3124 /* Underline color. */
3126 && XSTRING (value
)->size
== 0))
3127 signal_error ("Invalid face underline", value
);
3129 old_value
= LFACE_UNDERLINE (lface
);
3130 LFACE_UNDERLINE (lface
) = value
;
3132 else if (EQ (attr
, QCoverline
))
3134 if (!UNSPECIFIEDP (value
))
3135 if ((SYMBOLP (value
)
3137 && !EQ (value
, Qnil
))
3138 /* Overline color. */
3140 && XSTRING (value
)->size
== 0))
3141 signal_error ("Invalid face overline", value
);
3143 old_value
= LFACE_OVERLINE (lface
);
3144 LFACE_OVERLINE (lface
) = value
;
3146 else if (EQ (attr
, QCstrike_through
))
3148 if (!UNSPECIFIEDP (value
))
3149 if ((SYMBOLP (value
)
3151 && !EQ (value
, Qnil
))
3152 /* Strike-through color. */
3154 && XSTRING (value
)->size
== 0))
3155 signal_error ("Invalid face strike-through", value
);
3157 old_value
= LFACE_STRIKE_THROUGH (lface
);
3158 LFACE_STRIKE_THROUGH (lface
) = value
;
3160 else if (EQ (attr
, QCbox
))
3164 /* Allow t meaning a simple box of width 1 in foreground color
3167 value
= make_number (1);
3169 if (UNSPECIFIEDP (value
))
3171 else if (NILP (value
))
3173 else if (INTEGERP (value
))
3174 valid_p
= XINT (value
) > 0;
3175 else if (STRINGP (value
))
3176 valid_p
= XSTRING (value
)->size
> 0;
3177 else if (CONSP (value
))
3193 if (EQ (k
, QCline_width
))
3195 if (!INTEGERP (v
) || XINT (v
) <= 0)
3198 else if (EQ (k
, QCcolor
))
3200 if (!STRINGP (v
) || XSTRING (v
)->size
== 0)
3203 else if (EQ (k
, QCstyle
))
3205 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
3212 valid_p
= NILP (tem
);
3218 signal_error ("Invalid face box", value
);
3220 old_value
= LFACE_BOX (lface
);
3221 LFACE_BOX (lface
) = value
;
3223 else if (EQ (attr
, QCinverse_video
)
3224 || EQ (attr
, QCreverse_video
))
3226 if (!UNSPECIFIEDP (value
))
3228 CHECK_SYMBOL (value
, 3);
3229 if (!EQ (value
, Qt
) && !NILP (value
))
3230 signal_error ("Invalid inverse-video face attribute value", value
);
3232 old_value
= LFACE_INVERSE (lface
);
3233 LFACE_INVERSE (lface
) = value
;
3235 else if (EQ (attr
, QCforeground
))
3237 if (!UNSPECIFIEDP (value
))
3239 /* Don't check for valid color names here because it depends
3240 on the frame (display) whether the color will be valid
3241 when the face is realized. */
3242 CHECK_STRING (value
, 3);
3243 if (XSTRING (value
)->size
== 0)
3244 signal_error ("Empty foreground color value", value
);
3246 old_value
= LFACE_FOREGROUND (lface
);
3247 LFACE_FOREGROUND (lface
) = value
;
3249 else if (EQ (attr
, QCbackground
))
3251 if (!UNSPECIFIEDP (value
))
3253 /* Don't check for valid color names here because it depends
3254 on the frame (display) whether the color will be valid
3255 when the face is realized. */
3256 CHECK_STRING (value
, 3);
3257 if (XSTRING (value
)->size
== 0)
3258 signal_error ("Empty background color value", value
);
3260 old_value
= LFACE_BACKGROUND (lface
);
3261 LFACE_BACKGROUND (lface
) = value
;
3263 else if (EQ (attr
, QCstipple
))
3265 #ifdef HAVE_X_WINDOWS
3266 if (!UNSPECIFIEDP (value
)
3268 && NILP (Fpixmap_spec_p (value
)))
3269 signal_error ("Invalid stipple attribute", value
);
3270 old_value
= LFACE_STIPPLE (lface
);
3271 LFACE_STIPPLE (lface
) = value
;
3272 #endif /* HAVE_X_WINDOWS */
3274 else if (EQ (attr
, QCwidth
))
3276 if (!UNSPECIFIEDP (value
))
3278 CHECK_SYMBOL (value
, 3);
3279 if (face_numeric_swidth (value
) < 0)
3280 signal_error ("Invalid face width", value
);
3282 old_value
= LFACE_SWIDTH (lface
);
3283 LFACE_SWIDTH (lface
) = value
;
3284 font_related_attr_p
= 1;
3286 else if (EQ (attr
, QCfont
))
3288 #ifdef HAVE_X_WINDOWS
3289 /* Set font-related attributes of the Lisp face from an
3293 CHECK_STRING (value
, 3);
3297 f
= check_x_frame (frame
);
3299 if (!set_lface_from_font_name (f
, lface
, XSTRING (value
)->data
, 1))
3300 signal_error ("Invalid font name", value
);
3302 font_related_attr_p
= 1;
3303 #endif /* HAVE_X_WINDOWS */
3305 else if (EQ (attr
, QCbold
))
3307 old_value
= LFACE_WEIGHT (lface
);
3308 LFACE_WEIGHT (lface
) = NILP (value
) ? Qnormal
: Qbold
;
3309 font_related_attr_p
= 1;
3311 else if (EQ (attr
, QCitalic
))
3313 old_value
= LFACE_SLANT (lface
);
3314 LFACE_SLANT (lface
) = NILP (value
) ? Qnormal
: Qitalic
;
3315 font_related_attr_p
= 1;
3318 signal_error ("Invalid face attribute name", attr
);
3320 /* Changing a named face means that all realized faces depending on
3321 that face are invalid. Since we cannot tell which realized faces
3322 depend on the face, make sure they are all removed. This is done
3323 by incrementing face_change_count. The next call to
3324 init_iterator will then free realized faces. */
3326 && (EQ (attr
, QCfont
)
3327 || NILP (Fequal (old_value
, value
))))
3329 ++face_change_count
;
3330 ++windows_or_buffers_changed
;
3333 #ifdef HAVE_X_WINDOWS
3334 /* Changed font-related attributes of the `default' face are
3335 reflected in changed `font' frame parameters. */
3336 if (EQ (face
, Qdefault
)
3338 && font_related_attr_p
3339 && lface_fully_specified_p (XVECTOR (lface
)->contents
)
3340 && NILP (Fequal (old_value
, value
)))
3341 set_font_frame_param (frame
, lface
);
3343 #endif /* HAVE_X_WINDOWS */
3349 #ifdef HAVE_X_WINDOWS
3351 /* Set the `font' frame parameter of FRAME according to `default' face
3352 attributes LFACE. */
3355 set_font_frame_param (frame
, lface
)
3356 Lisp_Object frame
, lface
;
3358 struct frame
*f
= XFRAME (frame
);
3359 Lisp_Object frame_font
;
3363 /* Get FRAME's font parameter. */
3364 frame_font
= Fassq (Qfont
, f
->param_alist
);
3365 xassert (CONSP (frame_font
) && STRINGP (XCDR (frame_font
)));
3366 frame_font
= XCDR (frame_font
);
3368 fontset
= fs_query_fontset (f
, XSTRING (frame_font
)->data
);
3371 /* Frame parameter is a fontset name. Modify the fontset so
3372 that all its fonts reflect face attributes LFACE. */
3374 struct fontset_info
*fontset_info
;
3376 fontset_info
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
];
3378 for (charset
= 0; charset
< MAX_CHARSET
; ++charset
)
3379 if (fontset_info
->fontname
[charset
])
3381 font
= choose_face_fontset_font (f
, XVECTOR (lface
)->contents
,
3383 Fset_fontset_font (frame_font
, CHARSET_SYMBOL (charset
),
3384 build_string (font
), frame
);
3390 /* Frame parameter is an X font name. I believe this can
3391 only happen in unibyte mode. */
3392 font
= choose_face_font (f
, XVECTOR (lface
)->contents
,
3393 -1, Vface_default_registry
);
3396 store_frame_param (f
, Qfont
, build_string (font
));
3403 /* Get the value of X resource RESOURCE, class CLASS for the display
3404 of frame FRAME. This is here because ordinary `x-get-resource'
3405 doesn't take a frame argument. */
3407 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
3408 Sinternal_face_x_get_resource
, 3, 3, 0, "")
3409 (resource
, class, frame
)
3410 Lisp_Object resource
, class, frame
;
3413 CHECK_STRING (resource
, 0);
3414 CHECK_STRING (class, 1);
3415 CHECK_LIVE_FRAME (frame
, 2);
3417 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame
)),
3418 resource
, class, Qnil
, Qnil
);
3424 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
3425 If VALUE is "on" or "true", return t. If VALUE is "off" or
3426 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
3427 error; if SIGNAL_P is zero, return 0. */
3430 face_boolean_x_resource_value (value
, signal_p
)
3434 Lisp_Object result
= make_number (0);
3436 xassert (STRINGP (value
));
3438 if (xstricmp (XSTRING (value
)->data
, "on") == 0
3439 || xstricmp (XSTRING (value
)->data
, "true") == 0)
3441 else if (xstricmp (XSTRING (value
)->data
, "off") == 0
3442 || xstricmp (XSTRING (value
)->data
, "false") == 0)
3444 else if (xstricmp (XSTRING (value
)->data
, "unspecified") == 0)
3445 result
= Qunspecified
;
3447 signal_error ("Invalid face attribute value from X resource", value
);
3453 DEFUN ("internal-set-lisp-face-attribute-from-resource",
3454 Finternal_set_lisp_face_attribute_from_resource
,
3455 Sinternal_set_lisp_face_attribute_from_resource
,
3457 (face
, attr
, value
, frame
)
3458 Lisp_Object face
, attr
, value
, frame
;
3460 CHECK_SYMBOL (face
, 0);
3461 CHECK_SYMBOL (attr
, 1);
3462 CHECK_STRING (value
, 2);
3464 if (xstricmp (XSTRING (value
)->data
, "unspecified") == 0)
3465 value
= Qunspecified
;
3466 else if (EQ (attr
, QCheight
))
3468 value
= Fstring_to_number (value
, make_number (10));
3469 if (XINT (value
) <= 0)
3470 signal_error ("Invalid face height from X resource", value
);
3472 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
3473 value
= face_boolean_x_resource_value (value
, 1);
3474 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
3475 value
= intern (XSTRING (value
)->data
);
3476 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
3477 value
= face_boolean_x_resource_value (value
, 1);
3478 else if (EQ (attr
, QCunderline
)
3479 || EQ (attr
, QCoverline
)
3480 || EQ (attr
, QCstrike_through
)
3481 || EQ (attr
, QCbox
))
3483 Lisp_Object boolean_value
;
3485 /* If the result of face_boolean_x_resource_value is t or nil,
3486 VALUE does NOT specify a color. */
3487 boolean_value
= face_boolean_x_resource_value (value
, 0);
3488 if (SYMBOLP (boolean_value
))
3489 value
= boolean_value
;
3492 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3496 #endif /* HAVE_X_WINDOWS */
3500 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
3501 Sinternal_get_lisp_face_attribute
,
3503 "Return face attribute KEYWORD of face SYMBOL.\n\
3504 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid\n\
3505 face attribute name, signal an error.\n\
3506 If the optional argument FRAME is given, report on face FACE in that\n\
3507 frame. If FRAME is t, report on the defaults for face FACE (for new\n\
3508 frames). If FRAME is omitted or nil, use the selected frame.")
3509 (symbol
, keyword
, frame
)
3510 Lisp_Object symbol
, keyword
, frame
;
3512 Lisp_Object lface
, value
= Qnil
;
3514 CHECK_SYMBOL (symbol
, 0);
3515 CHECK_SYMBOL (keyword
, 1);
3518 lface
= lface_from_face_name (NULL
, symbol
, 1);
3522 XSETFRAME (frame
, selected_frame
);
3523 CHECK_LIVE_FRAME (frame
, 2);
3524 lface
= lface_from_face_name (XFRAME (frame
), symbol
, 1);
3527 if (EQ (keyword
, QCfamily
))
3528 value
= LFACE_FAMILY (lface
);
3529 else if (EQ (keyword
, QCheight
))
3530 value
= LFACE_HEIGHT (lface
);
3531 else if (EQ (keyword
, QCweight
))
3532 value
= LFACE_WEIGHT (lface
);
3533 else if (EQ (keyword
, QCslant
))
3534 value
= LFACE_SLANT (lface
);
3535 else if (EQ (keyword
, QCunderline
))
3536 value
= LFACE_UNDERLINE (lface
);
3537 else if (EQ (keyword
, QCoverline
))
3538 value
= LFACE_OVERLINE (lface
);
3539 else if (EQ (keyword
, QCstrike_through
))
3540 value
= LFACE_STRIKE_THROUGH (lface
);
3541 else if (EQ (keyword
, QCbox
))
3542 value
= LFACE_BOX (lface
);
3543 else if (EQ (keyword
, QCinverse_video
)
3544 || EQ (keyword
, QCreverse_video
))
3545 value
= LFACE_INVERSE (lface
);
3546 else if (EQ (keyword
, QCforeground
))
3547 value
= LFACE_FOREGROUND (lface
);
3548 else if (EQ (keyword
, QCbackground
))
3549 value
= LFACE_BACKGROUND (lface
);
3550 else if (EQ (keyword
, QCstipple
))
3551 value
= LFACE_STIPPLE (lface
);
3552 else if (EQ (keyword
, QCwidth
))
3553 value
= LFACE_SWIDTH (lface
);
3555 signal_error ("Invalid face attribute name", keyword
);
3561 DEFUN ("internal-lisp-face-attribute-values",
3562 Finternal_lisp_face_attribute_values
,
3563 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
3564 "Return a list of valid discrete values for face attribute ATTR.\n\
3565 Value is nil if ATTR doesn't have a discrete set of valid values.")
3569 Lisp_Object result
= Qnil
;
3571 CHECK_SYMBOL (attr
, 0);
3573 if (EQ (attr
, QCweight
)
3574 || EQ (attr
, QCslant
)
3575 || EQ (attr
, QCwidth
))
3577 /* Extract permissible symbols from tables. */
3578 struct table_entry
*table
;
3581 if (EQ (attr
, QCweight
))
3582 table
= weight_table
, dim
= DIM (weight_table
);
3583 else if (EQ (attr
, QCslant
))
3584 table
= slant_table
, dim
= DIM (slant_table
);
3586 table
= swidth_table
, dim
= DIM (swidth_table
);
3588 for (i
= 0; i
< dim
; ++i
)
3590 Lisp_Object symbol
= *table
[i
].symbol
;
3591 Lisp_Object tail
= result
;
3594 && !EQ (XCAR (tail
), symbol
))
3598 result
= Fcons (symbol
, result
);
3601 else if (EQ (attr
, QCunderline
))
3602 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3603 else if (EQ (attr
, QCoverline
))
3604 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3605 else if (EQ (attr
, QCstrike_through
))
3606 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3607 else if (EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
3608 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
3614 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
3615 Sinternal_merge_in_global_face
, 2, 2, 0,
3616 "Add attributes from frame-default definition of FACE to FACE on FRAME.")
3618 Lisp_Object face
, frame
;
3620 Lisp_Object global_lface
, local_lface
;
3621 CHECK_LIVE_FRAME (frame
, 1);
3622 global_lface
= lface_from_face_name (NULL
, face
, 1);
3623 local_lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3624 if (NILP (local_lface
))
3625 local_lface
= Finternal_make_lisp_face (face
, frame
);
3626 merge_face_vectors (XVECTOR (global_lface
)->contents
,
3627 XVECTOR (local_lface
)->contents
);
3632 /* The following function is implemented for compatibility with 20.2.
3633 The function is used in x-resolve-fonts when it is asked to
3634 return fonts with the same size as the font of a face. This is
3635 done in fontset.el. */
3637 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 2, 0,
3638 "Return the font name of face FACE, or nil if it is unspecified.\n\
3639 If the optional argument FRAME is given, report on face FACE in that frame.\n\
3640 If FRAME is t, report on the defaults for face FACE (for new frames).\n\
3641 The font default for a face is either nil, or a list\n\
3642 of the form (bold), (italic) or (bold italic).\n\
3643 If FRAME is omitted or nil, use the selected frame.")
3645 Lisp_Object face
, frame
;
3649 Lisp_Object result
= Qnil
;
3650 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
3652 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3653 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
3654 result
= Fcons (Qbold
, result
);
3656 if (!NILP (LFACE_SLANT (lface
))
3657 && !EQ (LFACE_SLANT (lface
), Qnormal
))
3658 result
= Fcons (Qitalic
, result
);
3664 struct frame
*f
= frame_or_selected_frame (frame
, 1);
3665 int face_id
= lookup_named_face (f
, face
, CHARSET_ASCII
);
3666 struct face
*face
= FACE_FROM_ID (f
, face_id
);
3667 return build_string (face
->font_name
);
3672 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
3673 all attributes are `equal'. Tries to be fast because this function
3674 is called quite often. */
3677 lface_equal_p (v1
, v2
)
3678 Lisp_Object
*v1
, *v2
;
3682 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
3684 Lisp_Object a
= v1
[i
];
3685 Lisp_Object b
= v2
[i
];
3687 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
3688 and the other is specified. */
3689 equal_p
= XTYPE (a
) == XTYPE (b
);
3698 equal_p
= (XSTRING (a
)->size
== XSTRING (b
)->size
3699 && bcmp (XSTRING (a
)->data
, XSTRING (b
)->data
,
3700 XSTRING (a
)->size
) == 0);
3709 equal_p
= !NILP (Fequal (a
, b
));
3719 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
3720 Sinternal_lisp_face_equal_p
, 2, 3, 0,
3721 "True if FACE1 and FACE2 are equal.\n\
3722 If the optional argument FRAME is given, report on face FACE in that frame.\n\
3723 If FRAME is t, report on the defaults for face FACE (for new frames).\n\
3724 If FRAME is omitted or nil, use the selected frame.")
3725 (face1
, face2
, frame
)
3726 Lisp_Object face1
, face2
, frame
;
3730 Lisp_Object lface1
, lface2
;
3735 /* Don't use check_x_frame here because this function is called
3736 before X frames exist. At that time, if FRAME is nil,
3737 selected_frame will be used which is the frame dumped with
3738 Emacs. That frame is not an X frame. */
3739 f
= frame_or_selected_frame (frame
, 2);
3741 lface1
= lface_from_face_name (NULL
, face1
, 1);
3742 lface2
= lface_from_face_name (NULL
, face2
, 1);
3743 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
3744 XVECTOR (lface2
)->contents
);
3745 return equal_p
? Qt
: Qnil
;
3749 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
3750 Sinternal_lisp_face_empty_p
, 1, 2, 0,
3751 "True if FACE has no attribute specified.\n\
3752 If the optional argument FRAME is given, report on face FACE in that frame.\n\
3753 If FRAME is t, report on the defaults for face FACE (for new frames).\n\
3754 If FRAME is omitted or nil, use the selected frame.")
3756 Lisp_Object face
, frame
;
3766 CHECK_LIVE_FRAME (frame
, 0);
3771 lface
= lface_from_face_name (NULL
, face
, 1);
3773 lface
= lface_from_face_name (f
, face
, 1);
3775 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3776 if (!UNSPECIFIEDP (XVECTOR (lface
)->contents
[i
]))
3779 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
3783 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
3785 "Return an alist of frame-local faces defined on FRAME.\n\
3786 For internal use only.")
3790 struct frame
*f
= frame_or_selected_frame (frame
, 0);
3791 return f
->face_alist
;
3795 /* Return a hash code for Lisp string STRING with case ignored. Used
3796 below in computing a hash value for a Lisp face. */
3798 static INLINE
unsigned
3799 hash_string_case_insensitive (string
)
3804 xassert (STRINGP (string
));
3805 for (s
= XSTRING (string
)->data
; *s
; ++s
)
3806 hash
= (hash
<< 1) ^ tolower (*s
);
3811 /* Return a hash code for face attribute vector V. */
3813 static INLINE
unsigned
3817 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
3818 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
3819 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
3820 ^ (unsigned) v
[LFACE_WEIGHT_INDEX
]
3821 ^ (unsigned) v
[LFACE_SLANT_INDEX
]
3822 ^ (unsigned) v
[LFACE_SWIDTH_INDEX
]
3823 ^ XFASTINT (v
[LFACE_HEIGHT_INDEX
]));
3827 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
3828 considering charsets/registries). They do if they specify the same
3829 family, point size, weight, width and slant. Both LFACE1 and
3830 LFACE2 must be fully-specified. */
3833 lface_same_font_attributes_p (lface1
, lface2
)
3834 Lisp_Object
*lface1
, *lface2
;
3836 xassert (lface_fully_specified_p (lface1
)
3837 && lface_fully_specified_p (lface2
));
3838 return (xstricmp (XSTRING (lface1
[LFACE_FAMILY_INDEX
])->data
,
3839 XSTRING (lface2
[LFACE_FAMILY_INDEX
])->data
) == 0
3840 && (XFASTINT (lface1
[LFACE_HEIGHT_INDEX
])
3841 == XFASTINT (lface2
[LFACE_HEIGHT_INDEX
]))
3842 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
3843 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
3844 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
]));
3849 /***********************************************************************
3851 ***********************************************************************/
3853 /* Allocate and return a new realized face for Lisp face attribute
3854 vector ATTR, charset CHARSET, and registry REGISTRY. */
3856 static struct face
*
3857 make_realized_face (attr
, charset
, registry
)
3860 Lisp_Object registry
;
3862 struct face
*face
= (struct face
*) xmalloc (sizeof *face
);
3863 bzero (face
, sizeof *face
);
3864 face
->charset
= charset
;
3865 face
->registry
= registry
;
3866 bcopy (attr
, face
->lface
, sizeof face
->lface
);
3871 /* Free realized face FACE, including its X resources. FACE may
3875 free_realized_face (f
, face
)
3881 #ifdef HAVE_X_WINDOWS
3886 x_free_gc (f
, face
->gc
);
3890 free_face_colors (f
, face
);
3891 x_destroy_bitmap (f
, face
->stipple
);
3893 #endif /* HAVE_X_WINDOWS */
3900 /* Prepare face FACE for subsequent display on frame F. This
3901 allocated GCs if they haven't been allocated yet or have been freed
3902 by clearing the face cache. */
3905 prepare_face_for_display (f
, face
)
3909 #ifdef HAVE_X_WINDOWS
3910 xassert (FRAME_X_P (f
));
3915 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
3917 xgcv
.foreground
= face
->foreground
;
3918 xgcv
.background
= face
->background
;
3919 xgcv
.graphics_exposures
= False
;
3921 /* The font of FACE may be null if we couldn't load it. */
3924 xgcv
.font
= face
->font
->fid
;
3931 xgcv
.fill_style
= FillStippled
;
3932 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
3933 mask
|= GCFillStyle
| GCStipple
;
3936 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
3943 /* Non-zero if FACE is suitable for displaying ISO8859-1. Used in
3944 macro FACE_SUITABLE_FOR_CHARSET_P to avoid realizing a new face for
3945 ISO8859-1 if the ASCII face suffices. */
3948 face_suitable_for_iso8859_1_p (face
)
3951 int len
= strlen (face
->font_name
);
3952 return len
>= 9 && xstricmp (face
->font_name
+ len
- 9, "iso8859-1") == 0;
3956 /* Value is non-zero if FACE is suitable for displaying characters
3957 of CHARSET. CHARSET < 0 means unibyte text. */
3960 face_suitable_for_charset_p (face
, charset
)
3968 if (EQ (face
->registry
, Vface_default_registry
)
3969 || !NILP (Fequal (face
->registry
, Vface_default_registry
)))
3972 else if (face
->charset
== charset
)
3974 else if (face
->charset
== CHARSET_ASCII
3975 && charset
== charset_latin_iso8859_1
)
3976 suitable_p
= face_suitable_for_iso8859_1_p (face
);
3977 else if (face
->charset
== charset_latin_iso8859_1
3978 && charset
== CHARSET_ASCII
)
3986 /***********************************************************************
3988 ***********************************************************************/
3990 /* Return a new face cache for frame F. */
3992 static struct face_cache
*
3996 struct face_cache
*c
;
3999 c
= (struct face_cache
*) xmalloc (sizeof *c
);
4000 bzero (c
, sizeof *c
);
4001 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4002 c
->buckets
= (struct face
**) xmalloc (size
);
4003 bzero (c
->buckets
, size
);
4005 c
->faces_by_id
= (struct face
**) xmalloc (c
->size
* sizeof *c
->faces_by_id
);
4011 /* Clear out all graphics contexts for all realized faces, except for
4012 the basic faces. This should be done from time to time just to avoid
4013 keeping too many graphics contexts that are no longer needed. */
4017 struct face_cache
*c
;
4019 if (c
&& FRAME_X_P (c
->f
))
4021 #ifdef HAVE_X_WINDOWS
4023 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
4025 struct face
*face
= c
->faces_by_id
[i
];
4026 if (face
&& face
->gc
)
4028 x_free_gc (c
->f
, face
->gc
);
4032 #endif /* HAVE_X_WINDOWS */
4037 /* Free all realized faces in face cache C, including basic faces. C
4038 may be null. If faces are freed, make sure the frame's current
4039 matrix is marked invalid, so that a display caused by an expose
4040 event doesn't try to use faces we destroyed. */
4043 free_realized_faces (c
)
4044 struct face_cache
*c
;
4049 struct frame
*f
= c
->f
;
4051 for (i
= 0; i
< c
->used
; ++i
)
4053 free_realized_face (f
, c
->faces_by_id
[i
]);
4054 c
->faces_by_id
[i
] = NULL
;
4058 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4059 bzero (c
->buckets
, size
);
4061 /* Must do a thorough redisplay the next time. Mark current
4062 matrices as invalid because they will reference faces freed
4063 above. This function is also called when a frame is
4064 destroyed. In this case, the root window of F is nil. */
4065 if (WINDOWP (f
->root_window
))
4067 clear_current_matrices (f
);
4068 ++windows_or_buffers_changed
;
4074 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
4075 This is done after attributes of a named face have been changed,
4076 because we can't tell which realized faces depend on that face. */
4079 free_all_realized_faces (frame
)
4085 FOR_EACH_FRAME (rest
, frame
)
4086 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4089 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4093 /* Free face cache C and faces in it, including their X resources. */
4097 struct face_cache
*c
;
4101 free_realized_faces (c
);
4103 xfree (c
->faces_by_id
);
4109 /* Cache realized face FACE in face cache C. HASH is the hash value
4110 of FACE. If FACE->fontset >= 0, add the new face to the end of the
4111 collision list of the face hash table of C. This is done because
4112 otherwise lookup_face would find FACE for every charset, even if
4113 faces with the same attributes but for specific charsets exist. */
4116 cache_face (c
, face
, hash
)
4117 struct face_cache
*c
;
4121 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4125 if (face
->fontset
>= 0)
4127 struct face
*last
= c
->buckets
[i
];
4138 c
->buckets
[i
] = face
;
4139 face
->prev
= face
->next
= NULL
;
4145 face
->next
= c
->buckets
[i
];
4147 face
->next
->prev
= face
;
4148 c
->buckets
[i
] = face
;
4151 /* Find a free slot in C->faces_by_id and use the index of the free
4152 slot as FACE->id. */
4153 for (i
= 0; i
< c
->used
; ++i
)
4154 if (c
->faces_by_id
[i
] == NULL
)
4158 /* Maybe enlarge C->faces_by_id. */
4159 if (i
== c
->used
&& c
->used
== c
->size
)
4161 int new_size
= 2 * c
->size
;
4162 int sz
= new_size
* sizeof *c
->faces_by_id
;
4163 c
->faces_by_id
= (struct face
**) xrealloc (c
->faces_by_id
, sz
);
4168 /* Check that FACE got a unique id. */
4173 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
4174 for (face
= c
->buckets
[j
]; face
; face
= face
->next
)
4180 #endif /* GLYPH_DEBUG */
4182 c
->faces_by_id
[i
] = face
;
4188 /* Remove face FACE from cache C. */
4191 uncache_face (c
, face
)
4192 struct face_cache
*c
;
4195 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
4198 face
->prev
->next
= face
->next
;
4200 c
->buckets
[i
] = face
->next
;
4203 face
->next
->prev
= face
->prev
;
4205 c
->faces_by_id
[face
->id
] = NULL
;
4206 if (face
->id
== c
->used
)
4211 /* Look up a realized face with face attributes ATTR in the face cache
4212 of frame F. The face will be used to display characters of
4213 CHARSET. CHARSET < 0 means the face will be used to display
4214 unibyte text. The value of face-default-registry is used to choose
4215 a font for the face in that case. Value is the ID of the face
4216 found. If no suitable face is found, realize a new one. */
4219 lookup_face (f
, attr
, charset
)
4224 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
4229 xassert (c
!= NULL
);
4230 check_lface_attrs (attr
);
4232 /* Look up ATTR in the face cache. */
4233 hash
= lface_hash (attr
);
4234 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4236 for (face
= c
->buckets
[i
]; face
; face
= face
->next
)
4237 if (face
->hash
== hash
4238 && (FRAME_TERMCAP_P (f
)
4239 || FACE_SUITABLE_FOR_CHARSET_P (face
, charset
))
4240 && lface_equal_p (face
->lface
, attr
))
4243 /* If not found, realize a new face. */
4246 face
= realize_face (c
, attr
, charset
);
4247 cache_face (c
, face
, hash
);
4251 xassert (face
== FACE_FROM_ID (f
, face
->id
));
4253 xassert (charset
< 0 || FACE_SUITABLE_FOR_CHARSET_P (face
, charset
));
4254 #endif /* GLYPH_DEBUG */
4260 /* Return the face id of the realized face for named face SYMBOL on
4261 frame F suitable for displaying characters from CHARSET. CHARSET <
4262 0 means unibyte text. */
4265 lookup_named_face (f
, symbol
, charset
)
4270 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4271 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4272 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4274 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
4275 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
4276 merge_face_vectors (symbol_attrs
, attrs
);
4277 return lookup_face (f
, attrs
, charset
);
4281 /* Return the ID of the realized ASCII face of Lisp face with ID
4282 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
4285 ascii_face_of_lisp_face (f
, lface_id
)
4291 if (lface_id
>= 0 && lface_id
< lface_id_to_name_size
)
4293 Lisp_Object face_name
= lface_id_to_name
[lface_id
];
4294 face_id
= lookup_named_face (f
, face_name
, CHARSET_ASCII
);
4303 /* Return a face for charset ASCII that is like the face with id
4304 FACE_ID on frame F, but has a font that is STEPS steps smaller.
4305 STEPS < 0 means larger. Value is the id of the face. */
4308 smaller_face (f
, face_id
, steps
)
4312 #ifdef HAVE_X_WINDOWS
4314 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4315 int pt
, last_pt
, last_height
;
4318 struct face
*new_face
;
4320 /* If not called for an X frame, just return the original face. */
4321 if (FRAME_TERMCAP_P (f
))
4324 /* Try in increments of 1/2 pt. */
4325 delta
= steps
< 0 ? 5 : -5;
4326 steps
= abs (steps
);
4328 face
= FACE_FROM_ID (f
, face_id
);
4329 bcopy (face
->lface
, attrs
, sizeof attrs
);
4330 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
4331 new_face_id
= face_id
;
4332 last_height
= FONT_HEIGHT (face
->font
);
4336 /* Give up if we cannot find a font within 10pt. */
4337 && abs (last_pt
- pt
) < 100)
4339 /* Look up a face for a slightly smaller/larger font. */
4341 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
4342 new_face_id
= lookup_face (f
, attrs
, CHARSET_ASCII
);
4343 new_face
= FACE_FROM_ID (f
, new_face_id
);
4345 /* If height changes, count that as one step. */
4346 if (FONT_HEIGHT (new_face
->font
) != last_height
)
4349 last_height
= FONT_HEIGHT (new_face
->font
);
4356 #else /* not HAVE_X_WINDOWS */
4360 #endif /* not HAVE_X_WINDOWS */
4364 /* Return a face for charset ASCII that is like the face with id
4365 FACE_ID on frame F, but has height HEIGHT. */
4368 face_with_height (f
, face_id
, height
)
4373 #ifdef HAVE_X_WINDOWS
4375 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4377 if (FRAME_TERMCAP_P (f
)
4381 face
= FACE_FROM_ID (f
, face_id
);
4382 bcopy (face
->lface
, attrs
, sizeof attrs
);
4383 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
4384 face_id
= lookup_face (f
, attrs
, CHARSET_ASCII
);
4385 #endif /* HAVE_X_WINDOWS */
4392 /***********************************************************************
4394 ***********************************************************************/
4396 DEFUN ("internal-set-font-selection-order",
4397 Finternal_set_font_selection_order
,
4398 Sinternal_set_font_selection_order
, 1, 1, 0,
4399 "Set font selection order for face font selection to ORDER.\n\
4400 ORDER must be a list of length 4 containing the symbols `:width',\n\
4401 `:height', `:weight', and `:slant'. Face attributes appearing\n\
4402 first in ORDER are matched first, e.g. if `:height' appears before\n\
4403 `:weight' in ORDER, font selection first tries to find a font with\n\
4404 a suitable height, and then tries to match the font weight.\n\
4413 CHECK_LIST (order
, 0);
4414 bzero (indices
, sizeof indices
);
4418 CONSP (list
) && i
< DIM (indices
);
4419 list
= XCDR (list
), ++i
)
4421 Lisp_Object attr
= XCAR (list
);
4424 if (EQ (attr
, QCwidth
))
4426 else if (EQ (attr
, QCheight
))
4427 xlfd
= XLFD_POINT_SIZE
;
4428 else if (EQ (attr
, QCweight
))
4430 else if (EQ (attr
, QCslant
))
4435 if (indices
[i
] != 0)
4441 || i
!= DIM (indices
)
4446 signal_error ("Invalid font sort order", order
);
4448 if (bcmp (indices
, font_sort_order
, sizeof indices
) != 0)
4450 bcopy (indices
, font_sort_order
, sizeof font_sort_order
);
4451 free_all_realized_faces (Qnil
);
4458 DEFUN ("internal-set-alternative-font-family-alist",
4459 Finternal_set_alternative_font_family_alist
,
4460 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
4461 "Define alternative font families to try in face font selection.\n\
4462 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.\n\
4463 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can\n\
4464 be found. Value is ALIST.")
4468 CHECK_LIST (alist
, 0);
4469 Vface_alternative_font_family_alist
= alist
;
4470 free_all_realized_faces (Qnil
);
4475 #ifdef HAVE_X_WINDOWS
4477 /* Return the X registry and encoding of font name FONT_NAME on frame F.
4478 Value is nil if not successful. */
4481 deduce_unibyte_registry (f
, font_name
)
4485 struct font_name font
;
4486 Lisp_Object registry
= Qnil
;
4488 font
.name
= STRDUPA (font_name
);
4489 if (split_font_name (f
, &font
, 0))
4493 /* Extract registry and encoding. */
4494 buffer
= (char *) alloca (strlen (font
.fields
[XLFD_REGISTRY
])
4495 + strlen (font
.fields
[XLFD_ENCODING
])
4497 strcpy (buffer
, font
.fields
[XLFD_REGISTRY
]);
4498 strcat (buffer
, "-");
4499 strcat (buffer
, font
.fields
[XLFD_ENCODING
]);
4500 registry
= build_string (buffer
);
4507 /* Value is non-zero if FONT is the name of a scalable font. The
4508 X11R6 XLFD spec says that point size, pixel size, and average width
4509 are zero for scalable fonts. Intlfonts contain at least one
4510 scalable font ("*-muleindian-1") for which this isn't true, so we
4511 just test average width. */
4514 font_scalable_p (font
)
4515 struct font_name
*font
;
4517 char *s
= font
->fields
[XLFD_AVGWIDTH
];
4518 return *s
== '0' && *(s
+ 1) == '\0';
4522 /* Value is non-zero if FONT1 is a better match for font attributes
4523 VALUES than FONT2. VALUES is an array of face attribute values in
4524 font sort order. COMPARE_PT_P zero means don't compare point
4528 better_font_p (values
, font1
, font2
, compare_pt_p
)
4530 struct font_name
*font1
, *font2
;
4535 for (i
= 0; i
< 4; ++i
)
4537 int xlfd_idx
= font_sort_order
[i
];
4539 if (compare_pt_p
|| xlfd_idx
!= XLFD_POINT_SIZE
)
4541 int delta1
= abs (values
[i
] - font1
->numeric
[xlfd_idx
]);
4542 int delta2
= abs (values
[i
] - font2
->numeric
[xlfd_idx
]);
4544 if (delta1
> delta2
)
4546 else if (delta1
< delta2
)
4550 /* The difference may be equal because, e.g., the face
4551 specifies `italic' but we have only `regular' and
4552 `oblique'. Prefer `oblique' in this case. */
4553 if ((xlfd_idx
== XLFD_WEIGHT
|| xlfd_idx
== XLFD_SLANT
)
4554 && font1
->numeric
[xlfd_idx
] > values
[i
]
4555 && font2
->numeric
[xlfd_idx
] < values
[i
])
4567 /* Value is non-zero if FONT is an exact match for face attributes in
4568 SPECIFIED. SPECIFIED is an array of face attribute values in font
4572 exact_face_match_p (specified
, font
)
4574 struct font_name
*font
;
4578 for (i
= 0; i
< 4; ++i
)
4579 if (specified
[i
] != font
->numeric
[font_sort_order
[i
]])
4586 /* Value is the name of a scaled font, generated from scalable font
4587 FONT on frame F. SPECIFIED_PT is the point-size to scale FONT to.
4588 Value is allocated from heap. */
4591 build_scalable_font_name (f
, font
, specified_pt
)
4593 struct font_name
*font
;
4596 char point_size
[20], pixel_size
[20];
4598 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
4601 /* If scalable font is for a specific resolution, compute
4602 the point size we must specify from the resolution of
4603 the display and the specified resolution of the font. */
4604 if (font
->numeric
[XLFD_RESY
] != 0)
4606 pt
= resy
/ font
->numeric
[XLFD_RESY
] * specified_pt
+ 0.5;
4607 pixel_value
= font
->numeric
[XLFD_RESY
] / 720.0 * pt
;
4612 pixel_value
= resy
/ 720.0 * pt
;
4615 /* Set point size of the font. */
4616 sprintf (point_size
, "%d", (int) pt
);
4617 font
->fields
[XLFD_POINT_SIZE
] = point_size
;
4618 font
->numeric
[XLFD_POINT_SIZE
] = pt
;
4620 /* Set pixel size. */
4621 sprintf (pixel_size
, "%d", pixel_value
);
4622 font
->fields
[XLFD_PIXEL_SIZE
] = pixel_size
;
4623 font
->numeric
[XLFD_PIXEL_SIZE
] = pixel_value
;
4625 /* If font doesn't specify its resolution, use the
4626 resolution of the display. */
4627 if (font
->numeric
[XLFD_RESY
] == 0)
4630 sprintf (buffer
, "%d", (int) resy
);
4631 font
->fields
[XLFD_RESY
] = buffer
;
4632 font
->numeric
[XLFD_RESY
] = resy
;
4635 if (strcmp (font
->fields
[XLFD_RESX
], "0") == 0)
4638 int resx
= FRAME_X_DISPLAY_INFO (f
)->resx
;
4639 sprintf (buffer
, "%d", resx
);
4640 font
->fields
[XLFD_RESX
] = buffer
;
4641 font
->numeric
[XLFD_RESX
] = resx
;
4644 return build_font_name (font
);
4648 /* Value is non-zero if we are allowed to use scalable font FONT. We
4649 can't run a Lisp function here since this function may be called
4650 with input blocked. */
4653 may_use_scalable_font_p (font
, name
)
4654 struct font_name
*font
;
4657 if (EQ (Vscalable_fonts_allowed
, Qt
))
4659 else if (CONSP (Vscalable_fonts_allowed
))
4661 Lisp_Object tail
, regexp
;
4663 for (tail
= Vscalable_fonts_allowed
; CONSP (tail
); tail
= XCDR (tail
))
4665 regexp
= XCAR (tail
);
4666 if (STRINGP (regexp
)
4667 && fast_c_string_match_ignore_case (regexp
, name
) >= 0)
4675 #endif /* SCALABLE_FONTS != 0 */
4678 /* Return the name of the best matching font for face attributes
4679 ATTRS in the array of font_name structures FONTS which contains
4680 NFONTS elements. Value is a font name which is allocated from
4681 the heap. FONTS is freed by this function. */
4684 best_matching_font (f
, attrs
, fonts
, nfonts
)
4687 struct font_name
*fonts
;
4691 struct font_name
*best
;
4699 /* Make specified font attributes available in `specified',
4700 indexed by sort order. */
4701 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
4703 int xlfd_idx
= font_sort_order
[i
];
4705 if (xlfd_idx
== XLFD_SWIDTH
)
4706 specified
[i
] = face_numeric_swidth (attrs
[LFACE_SWIDTH_INDEX
]);
4707 else if (xlfd_idx
== XLFD_POINT_SIZE
)
4708 specified
[i
] = pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
4709 else if (xlfd_idx
== XLFD_WEIGHT
)
4710 specified
[i
] = face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
4711 else if (xlfd_idx
== XLFD_SLANT
)
4712 specified
[i
] = face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
4722 /* Start with the first non-scalable font in the list. */
4723 for (i
= 0; i
< nfonts
; ++i
)
4724 if (!font_scalable_p (fonts
+ i
))
4727 /* Find the best match among the non-scalable fonts. */
4732 for (i
= 1; i
< nfonts
; ++i
)
4733 if (!font_scalable_p (fonts
+ i
)
4734 && better_font_p (specified
, fonts
+ i
, best
, 1))
4738 exact_p
= exact_face_match_p (specified
, best
);
4747 /* Unless we found an exact match among non-scalable fonts, see if
4748 we can find a better match among scalable fonts. */
4751 /* A scalable font is better if
4753 1. its weight, slant, swidth attributes are better, or.
4755 2. the best non-scalable font doesn't have the required
4756 point size, and the scalable fonts weight, slant, swidth
4759 int non_scalable_has_exact_height_p
;
4761 if (best
&& best
->numeric
[XLFD_POINT_SIZE
] == pt
)
4762 non_scalable_has_exact_height_p
= 1;
4764 non_scalable_has_exact_height_p
= 0;
4766 for (i
= 0; i
< nfonts
; ++i
)
4767 if (font_scalable_p (fonts
+ i
))
4770 || better_font_p (specified
, fonts
+ i
, best
, 0)
4771 || (!non_scalable_has_exact_height_p
4772 && !better_font_p (specified
, best
, fonts
+ i
, 0)))
4777 if (font_scalable_p (best
))
4778 font_name
= build_scalable_font_name (f
, best
, pt
);
4780 font_name
= build_font_name (best
);
4782 #else /* !SCALABLE_FONTS */
4784 /* Find the best non-scalable font. */
4787 for (i
= 1; i
< nfonts
; ++i
)
4789 xassert (!font_scalable_p (fonts
+ i
));
4790 if (better_font_p (specified
, fonts
+ i
, best
, 1))
4794 font_name
= build_font_name (best
);
4796 #endif /* !SCALABLE_FONTS */
4798 /* Free font_name structures. */
4799 free_font_names (fonts
, nfonts
);
4805 /* Try to get a list of fonts on frame F with font family FAMILY and
4806 registry/encoding REGISTRY. Return in *FONTS a pointer to a vector
4807 of font_name structures for the fonts matched. Value is the number
4811 try_font_list (f
, attrs
, pattern
, family
, registry
, fonts
)
4814 char *pattern
, *family
, *registry
;
4815 struct font_name
**fonts
;
4820 family
= LSTRDUPA (attrs
[LFACE_FAMILY_INDEX
]);
4822 nfonts
= font_list (f
, pattern
, family
, registry
, fonts
);
4828 /* Try alternative font families from
4829 Vface_alternative_font_family_alist. */
4830 alter
= Fassoc (build_string (family
),
4831 Vface_alternative_font_family_alist
);
4833 for (alter
= XCDR (alter
);
4834 CONSP (alter
) && nfonts
== 0;
4835 alter
= XCDR (alter
))
4837 if (STRINGP (XCAR (alter
)))
4839 family
= LSTRDUPA (XCAR (alter
));
4840 nfonts
= font_list (f
, NULL
, family
, registry
, fonts
);
4844 /* Try font family of the default face or "fixed". */
4847 struct face
*dflt
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4849 family
= LSTRDUPA (dflt
->lface
[LFACE_FAMILY_INDEX
]);
4852 nfonts
= font_list (f
, NULL
, family
, registry
, fonts
);
4855 /* Try any family with the given registry. */
4857 nfonts
= font_list (f
, NULL
, "*", registry
, fonts
);
4864 /* Return the registry and encoding pattern that fonts for CHARSET
4865 should match. Value is allocated from the heap. */
4868 x_charset_registry (charset
)
4871 Lisp_Object prop
, charset_plist
;
4874 /* Get registry and encoding from the charset's plist. */
4875 charset_plist
= CHARSET_TABLE_INFO (charset
, CHARSET_PLIST_IDX
);
4876 prop
= Fplist_get (charset_plist
, Qx_charset_registry
);
4880 if (index (XSTRING (prop
)->data
, '-'))
4881 registry
= xstrdup (XSTRING (prop
)->data
);
4884 /* If registry doesn't contain a `-', make it a pattern. */
4885 registry
= (char *) xmalloc (STRING_BYTES (XSTRING (prop
)) + 5);
4886 strcpy (registry
, XSTRING (prop
)->data
);
4887 strcat (registry
, "*-*");
4890 else if (STRINGP (Vface_default_registry
))
4891 registry
= xstrdup (XSTRING (Vface_default_registry
)->data
);
4893 registry
= xstrdup ("iso8859-1");
4899 /* Return the fontset id of the fontset name or alias name given by
4900 the family attribute of ATTRS on frame F. Value is -1 if the
4901 family attribute of ATTRS doesn't name a fontset. */
4904 face_fontset (f
, attrs
)
4908 Lisp_Object name
= attrs
[LFACE_FAMILY_INDEX
];
4911 name
= Fquery_fontset (name
, Qnil
);
4915 fontset
= fs_query_fontset (f
, XSTRING (name
)->data
);
4921 /* Get the font to use for the face realizing the fully-specified Lisp
4922 face ATTRS for charset CHARSET on frame F. CHARSET < 0 means
4923 unibyte text; UNIBYTE_REGISTRY is the registry and encoding to use
4924 in this case. Value is the font name which is allocated from the
4925 heap (which means that it must be freed eventually). */
4928 choose_face_font (f
, attrs
, charset
, unibyte_registry
)
4932 Lisp_Object unibyte_registry
;
4934 struct font_name
*fonts
;
4938 /* ATTRS must be fully-specified. */
4939 xassert (lface_fully_specified_p (attrs
));
4941 if (STRINGP (unibyte_registry
))
4942 registry
= xstrdup (XSTRING (unibyte_registry
)->data
);
4944 registry
= x_charset_registry (charset
);
4946 nfonts
= try_font_list (f
, attrs
, NULL
, NULL
, registry
, &fonts
);
4948 return best_matching_font (f
, attrs
, fonts
, nfonts
);
4952 /* Choose a font to use on frame F to display CHARSET using FONTSET
4953 with Lisp face attributes specified by ATTRS. CHARSET may be any
4954 valid charset except CHARSET_COMPOSITION. CHARSET < 0 means
4955 unibyte text. If the fontset doesn't contain a font pattern for
4956 charset, use the pattern for CHARSET_ASCII. Value is the font name
4957 which is allocated from the heap and must be freed by the caller. */
4960 choose_face_fontset_font (f
, attrs
, fontset
, charset
)
4963 int fontset
, charset
;
4966 char *font_name
= NULL
;
4967 struct fontset_info
*fontset_info
;
4968 struct font_name
*fonts
;
4971 xassert (charset
!= CHARSET_COMPOSITION
);
4972 xassert (fontset
>= 0 && fontset
< FRAME_FONTSET_DATA (f
)->n_fontsets
);
4974 /* For unibyte text, use the ASCII font of the fontset. Using the
4975 ASCII font seems to be the most reasonable thing we can do in
4978 charset
= CHARSET_ASCII
;
4980 /* Get the font name pattern to use for CHARSET from the fontset. */
4981 fontset_info
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
];
4982 pattern
= fontset_info
->fontname
[charset
];
4984 pattern
= fontset_info
->fontname
[CHARSET_ASCII
];
4987 /* Get a list of fonts matching that pattern and choose the
4988 best match for the specified face attributes from it. */
4989 nfonts
= try_font_list (f
, attrs
, pattern
, NULL
, NULL
, &fonts
);
4990 font_name
= best_matching_font (f
, attrs
, fonts
, nfonts
);
4994 #endif /* HAVE_X_WINDOWS */
4998 /***********************************************************************
5000 ***********************************************************************/
5002 /* Realize basic faces on frame F. Value is zero if frame parameters
5003 of F don't contain enough information needed to realize the default
5007 realize_basic_faces (f
)
5012 if (realize_default_face (f
))
5014 realize_named_face (f
, Qmodeline
, MODE_LINE_FACE_ID
);
5015 realize_named_face (f
, Qtoolbar
, TOOLBAR_FACE_ID
);
5016 realize_named_face (f
, Qbitmap_area
, BITMAP_AREA_FACE_ID
);
5017 realize_named_face (f
, Qtop_line
, TOP_LINE_FACE_ID
);
5025 /* Realize the default face on frame F. If the face is not fully
5026 specified, make it fully-specified. Attributes of the default face
5027 that are not explicitly specified are taken from frame parameters. */
5030 realize_default_face (f
)
5033 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5035 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5036 Lisp_Object unibyte_registry
;
5037 Lisp_Object frame_font
;
5041 /* If the `default' face is not yet known, create it. */
5042 lface
= lface_from_face_name (f
, Qdefault
, 0);
5046 XSETFRAME (frame
, f
);
5047 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
5050 #ifdef HAVE_X_WINDOWS
5053 /* Set frame_font to the value of the `font' frame parameter. */
5054 frame_font
= Fassq (Qfont
, f
->param_alist
);
5055 xassert (CONSP (frame_font
) && STRINGP (XCDR (frame_font
)));
5056 frame_font
= XCDR (frame_font
);
5058 fontset
= fs_query_fontset (f
, XSTRING (frame_font
)->data
);
5061 /* If frame_font is a fontset name, don't use that for
5062 determining font-related attributes of the default face
5063 because it is just an artificial name. Use the ASCII font of
5064 the fontset, instead. */
5065 struct font_info
*font_info
;
5066 struct font_name font
;
5069 font_info
= FS_LOAD_FONT (f
, FRAME_X_FONT_TABLE (f
), CHARSET_ASCII
,
5073 /* Set weight etc. from the ASCII font. */
5074 if (!set_lface_from_font_name (f
, lface
, font_info
->full_name
, 0))
5077 /* Remember registry and encoding of the frame font. */
5078 unibyte_registry
= deduce_unibyte_registry (f
, font_info
->full_name
);
5079 if (STRINGP (unibyte_registry
))
5080 Vface_default_registry
= unibyte_registry
;
5082 Vface_default_registry
= build_string ("iso8859-1");
5084 /* But set the family to the fontset alias name. Implementation
5085 note: When a font is passed to Emacs via `-fn FONT', a
5086 fontset is created in `x-win.el' whose name ends in
5087 `fontset-startup'. This fontset has an alias name that is
5088 equal to frame_font. */
5089 xassert (STRINGP (frame_font
));
5090 font
.name
= LSTRDUPA (frame_font
);
5092 if (!split_font_name (f
, &font
, 1)
5093 || xstricmp (font
.fields
[XLFD_REGISTRY
], "fontset") != 0
5094 || xstricmp (font
.fields
[XLFD_ENCODING
], "startup") != 0)
5095 LFACE_FAMILY (lface
) = frame_font
;
5099 /* Frame parameters contain a real font. Fill default face
5100 attributes from that font. */
5101 if (!set_lface_from_font_name (f
, lface
,
5102 XSTRING (frame_font
)->data
, 0))
5105 /* Remember registry and encoding of the frame font. */
5107 = deduce_unibyte_registry (f
, XSTRING (frame_font
)->data
);
5108 if (STRINGP (unibyte_registry
))
5109 Vface_default_registry
= unibyte_registry
;
5111 Vface_default_registry
= build_string ("iso8859-1");
5114 #endif /* HAVE_X_WINDOWS */
5116 if (FRAME_TERMCAP_P (f
))
5118 LFACE_FAMILY (lface
) = build_string ("default");
5119 LFACE_SWIDTH (lface
) = Qnormal
;
5120 LFACE_HEIGHT (lface
) = make_number (1);
5121 LFACE_WEIGHT (lface
) = Qnormal
;
5122 LFACE_SLANT (lface
) = Qnormal
;
5125 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
5126 LFACE_UNDERLINE (lface
) = Qnil
;
5128 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
5129 LFACE_OVERLINE (lface
) = Qnil
;
5131 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
5132 LFACE_STRIKE_THROUGH (lface
) = Qnil
;
5134 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
5135 LFACE_BOX (lface
) = Qnil
;
5137 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
5138 LFACE_INVERSE (lface
) = Qnil
;
5140 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
5142 /* This function is called so early that colors are not yet
5143 set in the frame parameter list. */
5144 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
5146 if (CONSP (color
) && STRINGP (XCDR (color
)))
5147 LFACE_FOREGROUND (lface
) = XCDR (color
);
5148 else if (FRAME_X_P (f
))
5150 else if (FRAME_TERMCAP_P (f
))
5151 /* Frame parameters for terminal frames usually don't contain
5152 a color. Use an empty string to indicate that the face
5153 should use the (unknown) default color of the terminal. */
5154 LFACE_FOREGROUND (lface
) = build_string ("");
5159 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
5161 /* This function is called so early that colors are not yet
5162 set in the frame parameter list. */
5163 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
5164 if (CONSP (color
) && STRINGP (XCDR (color
)))
5165 LFACE_BACKGROUND (lface
) = XCDR (color
);
5166 else if (FRAME_X_P (f
))
5168 else if (FRAME_TERMCAP_P (f
))
5169 /* Frame parameters for terminal frames usually don't contain
5170 a color. Use an empty string to indicate that the face
5171 should use the (unknown) default color of the terminal. */
5172 LFACE_BACKGROUND (lface
) = build_string ("");
5177 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
5178 LFACE_STIPPLE (lface
) = Qnil
;
5180 /* Realize the face; it must be fully-specified now. */
5181 xassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
5182 check_lface (lface
);
5183 bcopy (XVECTOR (lface
)->contents
, attrs
, sizeof attrs
);
5184 face
= realize_face (c
, attrs
, CHARSET_ASCII
);
5186 /* Remove the former default face. */
5187 if (c
->used
> DEFAULT_FACE_ID
)
5189 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5190 uncache_face (c
, default_face
);
5191 free_realized_face (f
, default_face
);
5194 /* Insert the new default face. */
5195 cache_face (c
, face
, lface_hash (attrs
));
5196 xassert (face
->id
== DEFAULT_FACE_ID
);
5201 /* Realize basic faces other than the default face in face cache C.
5202 SYMBOL is the face name, ID is the face id the realized face must
5203 have. The default face must have been realized already. */
5206 realize_named_face (f
, symbol
, id
)
5211 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5212 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
5213 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5214 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5215 struct face
*new_face
;
5217 /* The default face must exist and be fully specified. */
5218 get_lface_attributes (f
, Qdefault
, attrs
, 1);
5219 check_lface_attrs (attrs
);
5220 xassert (lface_fully_specified_p (attrs
));
5222 /* If SYMBOL isn't know as a face, create it. */
5226 XSETFRAME (frame
, f
);
5227 lface
= Finternal_make_lisp_face (symbol
, frame
);
5230 /* Merge SYMBOL's face with the default face. */
5231 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
5232 merge_face_vectors (symbol_attrs
, attrs
);
5234 /* Realize the face. */
5235 new_face
= realize_face (c
, attrs
, CHARSET_ASCII
);
5237 /* Remove the former face. */
5240 struct face
*old_face
= c
->faces_by_id
[id
];
5241 uncache_face (c
, old_face
);
5242 free_realized_face (f
, old_face
);
5245 /* Insert the new face. */
5246 cache_face (c
, new_face
, lface_hash (attrs
));
5247 xassert (new_face
->id
== id
);
5251 /* Realize the fully-specified face with attributes ATTRS in face
5252 cache C for character set CHARSET or for unibyte text if CHARSET <
5253 0. Value is a pointer to the newly created realized face. */
5255 static struct face
*
5256 realize_face (c
, attrs
, charset
)
5257 struct face_cache
*c
;
5263 /* LFACE must be fully specified. */
5264 xassert (c
!= NULL
);
5265 check_lface_attrs (attrs
);
5267 if (FRAME_X_P (c
->f
))
5268 face
= realize_x_face (c
, attrs
, charset
);
5269 else if (FRAME_TERMCAP_P (c
->f
))
5270 face
= realize_tty_face (c
, attrs
, charset
);
5278 /* Realize the fully-specified face with attributes ATTRS in face
5279 cache C for character set CHARSET or for unibyte text if CHARSET <
5280 0. Do it for X frame C->f. Value is a pointer to the newly
5281 created realized face. */
5283 static struct face
*
5284 realize_x_face (c
, attrs
, charset
)
5285 struct face_cache
*c
;
5289 #ifdef HAVE_X_WINDOWS
5290 struct face
*face
, *default_face
;
5291 struct frame
*f
= c
->f
;
5292 Lisp_Object stipple
, overline
, strike_through
, box
;
5293 Lisp_Object unibyte_registry
;
5294 struct gcpro gcpro1
;
5296 xassert (FRAME_X_P (f
));
5298 /* If realizing a face for use in unibyte text, get the X registry
5299 and encoding to use from Vface_default_registry. */
5301 unibyte_registry
= (STRINGP (Vface_default_registry
)
5302 ? Vface_default_registry
5303 : build_string ("iso8859-1"));
5305 unibyte_registry
= Qnil
;
5306 GCPRO1 (unibyte_registry
);
5308 /* Allocate a new realized face. */
5309 face
= make_realized_face (attrs
, charset
, unibyte_registry
);
5311 /* Determine the font to use. Most of the time, the font will be
5312 the same as the font of the default face, so try that first. */
5313 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5315 && FACE_SUITABLE_FOR_CHARSET_P (default_face
, charset
)
5316 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
5318 face
->font
= default_face
->font
;
5319 face
->fontset
= default_face
->fontset
;
5320 face
->font_info_id
= default_face
->font_info_id
;
5321 face
->font_name
= default_face
->font_name
;
5322 face
->registry
= default_face
->registry
;
5324 else if (charset
>= 0)
5326 /* For all charsets except CHARSET_COMPOSITION, we use our own
5327 font selection functions to choose a best matching font for
5328 the specified face attributes. If the face specifies a
5329 fontset alias name, the fontset determines the font name
5330 pattern, otherwise we construct a font pattern from face
5331 attributes and charset.
5333 If charset is CHARSET_COMPOSITION, we always construct a face
5334 with a fontset, even if the face doesn't specify a fontset alias
5335 (we use fontset-standard in that case). When the composite
5336 character is displayed in xterm.c, a suitable concrete font is
5337 loaded in x_get_char_font_and_encoding. */
5339 char *font_name
= NULL
;
5340 int fontset
= face_fontset (f
, attrs
);
5342 if (charset
== CHARSET_COMPOSITION
)
5343 fontset
= max (0, fontset
);
5344 else if (fontset
< 0)
5345 font_name
= choose_face_font (f
, attrs
, charset
, Qnil
);
5348 font_name
= choose_face_fontset_font (f
, attrs
, fontset
, charset
);
5352 load_face_font_or_fontset (f
, face
, font_name
, fontset
);
5357 /* Unibyte case, and font is not equal to that of the default
5358 face. UNIBYTE_REGISTRY is the X registry and encoding the
5359 font should have. What is a reasonable thing to do if the
5360 user specified a fontset alias name for the face in this
5361 case? We choose a font by taking the ASCII font of the
5362 fontset, but using UNIBYTE_REGISTRY for its registry and
5365 char *font_name
= NULL
;
5366 int fontset
= face_fontset (f
, attrs
);
5369 font_name
= choose_face_font (f
, attrs
, charset
, unibyte_registry
);
5371 font_name
= choose_face_fontset_font (f
, attrs
, fontset
, charset
);
5373 load_face_font_or_fontset (f
, face
, font_name
, -1);
5377 /* Load colors, and set remaining attributes. */
5379 load_face_colors (f
, face
, attrs
);
5382 box
= attrs
[LFACE_BOX_INDEX
];
5385 /* A simple box of line width 1 drawn in color given by
5387 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
5389 face
->box
= FACE_SIMPLE_BOX
;
5390 face
->box_line_width
= 1;
5392 else if (INTEGERP (box
))
5394 /* Simple box of specified line width in foreground color of the
5396 xassert (XINT (box
) > 0);
5397 face
->box
= FACE_SIMPLE_BOX
;
5398 face
->box_line_width
= XFASTINT (box
);
5399 face
->box_color
= face
->foreground
;
5400 face
->box_color_defaulted_p
= 1;
5402 else if (CONSP (box
))
5404 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
5405 being one of `raised' or `sunken'. */
5406 face
->box
= FACE_SIMPLE_BOX
;
5407 face
->box_color
= face
->foreground
;
5408 face
->box_color_defaulted_p
= 1;
5409 face
->box_line_width
= 1;
5413 Lisp_Object keyword
, value
;
5415 keyword
= XCAR (box
);
5423 if (EQ (keyword
, QCline_width
))
5425 if (INTEGERP (value
) && XINT (value
) > 0)
5426 face
->box_line_width
= XFASTINT (value
);
5428 else if (EQ (keyword
, QCcolor
))
5430 if (STRINGP (value
))
5432 face
->box_color
= load_color (f
, face
, value
,
5434 face
->use_box_color_for_shadows_p
= 1;
5437 else if (EQ (keyword
, QCstyle
))
5439 if (EQ (value
, Qreleased_button
))
5440 face
->box
= FACE_RAISED_BOX
;
5441 else if (EQ (value
, Qpressed_button
))
5442 face
->box
= FACE_SUNKEN_BOX
;
5447 /* Text underline, overline, strike-through. */
5449 if (EQ (attrs
[LFACE_UNDERLINE_INDEX
], Qt
))
5451 /* Use default color (same as foreground color). */
5452 face
->underline_p
= 1;
5453 face
->underline_defaulted_p
= 1;
5454 face
->underline_color
= 0;
5456 else if (STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]))
5458 /* Use specified color. */
5459 face
->underline_p
= 1;
5460 face
->underline_defaulted_p
= 0;
5461 face
->underline_color
5462 = load_color (f
, face
, attrs
[LFACE_UNDERLINE_INDEX
],
5463 LFACE_UNDERLINE_INDEX
);
5465 else if (NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5467 face
->underline_p
= 0;
5468 face
->underline_defaulted_p
= 0;
5469 face
->underline_color
= 0;
5472 overline
= attrs
[LFACE_OVERLINE_INDEX
];
5473 if (STRINGP (overline
))
5475 face
->overline_color
5476 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
5477 LFACE_OVERLINE_INDEX
);
5478 face
->overline_p
= 1;
5480 else if (EQ (overline
, Qt
))
5482 face
->overline_color
= face
->foreground
;
5483 face
->overline_color_defaulted_p
= 1;
5484 face
->overline_p
= 1;
5487 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
5488 if (STRINGP (strike_through
))
5490 face
->strike_through_color
5491 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
5492 LFACE_STRIKE_THROUGH_INDEX
);
5493 face
->strike_through_p
= 1;
5495 else if (EQ (strike_through
, Qt
))
5497 face
->strike_through_color
= face
->foreground
;
5498 face
->strike_through_color_defaulted_p
= 1;
5499 face
->strike_through_p
= 1;
5502 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
5503 if (!NILP (stipple
))
5504 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
5507 xassert (face
->fontset
< 0 || face
->charset
== CHARSET_COMPOSITION
);
5508 xassert (FACE_SUITABLE_FOR_CHARSET_P (face
, charset
));
5510 #endif /* HAVE_X_WINDOWS */
5514 /* Realize the fully-specified face with attributes ATTRS in face
5515 cache C for character set CHARSET or for unibyte text if CHARSET <
5516 0. Do it for TTY frame C->f. Value is a pointer to the newly
5517 created realized face. */
5519 static struct face
*
5520 realize_tty_face (c
, attrs
, charset
)
5521 struct face_cache
*c
;
5529 /* Frame must be a termcap frame. */
5530 xassert (FRAME_TERMCAP_P (c
->f
));
5532 /* Allocate a new realized face. */
5533 face
= make_realized_face (attrs
, charset
, Qnil
);
5534 face
->font_name
= "tty";
5536 /* Map face attributes to TTY appearances. We map slant to
5537 dimmed text because we want italic text to appear differently
5538 and because dimmed text is probably used infrequently. */
5539 weight
= face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
5540 slant
= face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
5542 if (weight
> XLFD_WEIGHT_MEDIUM
)
5543 face
->tty_bold_p
= 1;
5544 if (weight
< XLFD_WEIGHT_MEDIUM
|| slant
!= XLFD_SLANT_ROMAN
)
5545 face
->tty_dim_p
= 1;
5546 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5547 face
->tty_underline_p
= 1;
5548 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
5549 face
->tty_reverse_p
= 1;
5551 /* Map color names to color indices. */
5552 face
->foreground
= face
->background
= FACE_TTY_DEFAULT_COLOR
;
5554 color
= attrs
[LFACE_FOREGROUND_INDEX
];
5555 if (XSTRING (color
)->size
5556 && (color
= Fassoc (color
, Vface_tty_color_alist
),
5558 face
->foreground
= XINT (XCDR (color
));
5560 color
= attrs
[LFACE_BACKGROUND_INDEX
];
5561 if (XSTRING (color
)->size
5562 && (color
= Fassoc (color
, Vface_tty_color_alist
),
5564 face
->background
= XINT (XCDR (color
));
5570 DEFUN ("face-register-tty-color", Fface_register_tty_color
,
5571 Sface_register_tty_color
, 2, 2, 0,
5572 "Say that COLOR is color number NUMBER on the terminal.\n\
5573 COLOR is a string, the color name. Value is COLOR.")
5575 Lisp_Object color
, number
;
5579 CHECK_STRING (color
, 0);
5580 CHECK_NUMBER (number
, 1);
5581 entry
= Fassoc (color
, Vface_tty_color_alist
);
5583 Vface_tty_color_alist
= Fcons (Fcons (color
, number
),
5584 Vface_tty_color_alist
);
5586 Fsetcdr (entry
, number
);
5591 DEFUN ("face-clear-tty-colors", Fface_clear_tty_colors
,
5592 Sface_clear_tty_colors
, 0, 0, 0,
5593 "Unregister all registered tty colors.")
5596 return Vface_tty_color_alist
= Qnil
;
5600 DEFUN ("tty-defined-colors", Ftty_defined_colors
,
5601 Stty_defined_colors
, 0, 0, 0,
5602 "Return a list of registered tty colors.")
5605 Lisp_Object list
, colors
;
5608 for (list
= Vface_tty_color_alist
; CONSP (list
); list
= XCDR (list
))
5609 colors
= Fcons (XCAR (XCAR (list
)), colors
);
5616 /***********************************************************************
5618 ***********************************************************************/
5620 /* Return the ID of the face to use to display character CH with face
5621 property PROP on frame F in current_buffer. */
5624 compute_char_face (f
, ch
, prop
)
5630 int charset
= (NILP (current_buffer
->enable_multibyte_characters
)
5632 : CHAR_CHARSET (ch
));
5635 face_id
= FACE_FOR_CHARSET (f
, DEFAULT_FACE_ID
, charset
);
5638 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5639 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5640 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
5641 merge_face_vector_with_property (f
, attrs
, prop
);
5642 face_id
= lookup_face (f
, attrs
, charset
);
5649 /* Return the face ID associated with buffer position POS for
5650 displaying ASCII characters. Return in *ENDPTR the position at
5651 which a different face is needed, as far as text properties and
5652 overlays are concerned. W is a window displaying current_buffer.
5654 REGION_BEG, REGION_END delimit the region, so it can be
5657 LIMIT is a position not to scan beyond. That is to limit the time
5658 this function can take.
5660 If MOUSE is non-zero, use the character's mouse-face, not its face.
5662 The face returned is suitable for displaying CHARSET_ASCII if
5663 current_buffer->enable_multibyte_characters is non-nil. Otherwise,
5664 the face is suitable for displaying unibyte text. */
5667 face_at_buffer_position (w
, pos
, region_beg
, region_end
,
5668 endptr
, limit
, mouse
)
5671 int region_beg
, region_end
;
5676 struct frame
*f
= XFRAME (w
->frame
);
5677 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5678 Lisp_Object prop
, position
;
5680 Lisp_Object
*overlay_vec
;
5683 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
5684 Lisp_Object limit1
, end
;
5685 struct face
*default_face
;
5686 int multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5688 /* W must display the current buffer. We could write this function
5689 to use the frame and buffer of W, but right now it doesn't. */
5690 xassert (XBUFFER (w
->buffer
) == current_buffer
);
5692 XSETFRAME (frame
, f
);
5693 XSETFASTINT (position
, pos
);
5696 if (pos
< region_beg
&& region_beg
< endpos
)
5697 endpos
= region_beg
;
5699 /* Get the `face' or `mouse_face' text property at POS, and
5700 determine the next position at which the property changes. */
5701 prop
= Fget_text_property (position
, propname
, w
->buffer
);
5702 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
5703 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
5705 endpos
= XINT (end
);
5707 /* Look at properties from overlays. */
5712 /* First try with room for 40 overlays. */
5714 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
5715 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
5716 &next_overlay
, NULL
);
5718 /* If there are more than 40, make enough space for all, and try
5720 if (noverlays
> len
)
5723 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
5724 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
5725 &next_overlay
, NULL
);
5728 if (next_overlay
< endpos
)
5729 endpos
= next_overlay
;
5734 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5736 /* Optimize common cases where we can use the default face. */
5739 && !(pos
>= region_beg
&& pos
< region_end
)
5741 || !FRAME_WINDOW_P (f
)
5742 || FACE_SUITABLE_FOR_CHARSET_P (default_face
, -1)))
5743 return DEFAULT_FACE_ID
;
5745 /* Begin with attributes from the default face. */
5746 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
5748 /* Merge in attributes specified via text properties. */
5750 merge_face_vector_with_property (f
, attrs
, prop
);
5752 /* Now merge the overlay data. */
5753 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
5754 for (i
= 0; i
< noverlays
; i
++)
5759 prop
= Foverlay_get (overlay_vec
[i
], propname
);
5761 merge_face_vector_with_property (f
, attrs
, prop
);
5763 oend
= OVERLAY_END (overlay_vec
[i
]);
5764 oendpos
= OVERLAY_POSITION (oend
);
5765 if (oendpos
< endpos
)
5769 /* If in the region, merge in the region face. */
5770 if (pos
>= region_beg
&& pos
< region_end
)
5772 Lisp_Object region_face
= lface_from_face_name (f
, Qregion
, 0);
5773 merge_face_vectors (XVECTOR (region_face
)->contents
, attrs
);
5775 if (region_end
< endpos
)
5776 endpos
= region_end
;
5781 /* Look up a realized face with the given face attributes,
5782 or realize a new one. Charset is ignored for tty frames. */
5783 return lookup_face (f
, attrs
, multibyte_p
? CHARSET_ASCII
: -1);
5787 /* Compute the face at character position POS in Lisp string STRING on
5788 window W, for charset CHARSET_ASCII.
5790 If STRING is an overlay string, it comes from position BUFPOS in
5791 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
5792 not an overlay string. W must display the current buffer.
5793 REGION_BEG and REGION_END give the start and end positions of the
5794 region; both are -1 if no region is visible. BASE_FACE_ID is the
5795 id of the basic face to merge with. It is usually equal to
5796 DEFAULT_FACE_ID but can be MODE_LINE_FACE_ID or TOP_LINE_FACE_ID
5797 for strings displayed in the mode or top line.
5799 Set *ENDPTR to the next position where to check for faces in
5800 STRING; -1 if the face is constant from POS to the end of the
5803 Value is the id of the face to use. The face returned is suitable
5804 for displaying CHARSET_ASCII if STRING is multibyte. Otherwise,
5805 the face is suitable for displaying unibyte text. */
5808 face_at_string_position (w
, string
, pos
, bufpos
, region_beg
,
5809 region_end
, endptr
, base_face_id
)
5813 int region_beg
, region_end
;
5815 enum face_id base_face_id
;
5817 Lisp_Object prop
, position
, end
, limit
;
5818 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5819 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5820 struct face
*base_face
;
5821 int multibyte_p
= STRING_MULTIBYTE (string
);
5823 /* Get the value of the face property at the current position within
5824 STRING. Value is nil if there is no face property. */
5825 XSETFASTINT (position
, pos
);
5826 prop
= Fget_text_property (position
, Qface
, string
);
5828 /* Get the next position at which to check for faces. Value of end
5829 is nil if face is constant all the way to the end of the string.
5830 Otherwise it is a string position where to check faces next.
5831 Limit is the maximum position up to which to check for property
5832 changes in Fnext_single_property_change. Strings are usually
5833 short, so set the limit to the end of the string. */
5834 XSETFASTINT (limit
, XSTRING (string
)->size
);
5835 end
= Fnext_single_property_change (position
, Qface
, string
, limit
);
5837 *endptr
= XFASTINT (end
);
5841 base_face
= FACE_FROM_ID (f
, base_face_id
);
5842 xassert (base_face
);
5844 /* Optimize the default case that there is no face property and we
5845 are not in the region. */
5847 && (base_face_id
!= DEFAULT_FACE_ID
5848 /* BUFPOS <= 0 means STRING is not an overlay string, so
5849 that the region doesn't have to be taken into account. */
5851 || bufpos
< region_beg
5852 || bufpos
>= region_end
)
5854 /* We can't realize faces for different charsets differently
5855 if we don't have fonts, so we can stop here if not working
5856 on a window-system frame. */
5857 || !FRAME_WINDOW_P (f
)
5858 || FACE_SUITABLE_FOR_CHARSET_P (base_face
, -1)))
5859 return base_face
->id
;
5861 /* Begin with attributes from the base face. */
5862 bcopy (base_face
->lface
, attrs
, sizeof attrs
);
5864 /* Merge in attributes specified via text properties. */
5866 merge_face_vector_with_property (f
, attrs
, prop
);
5868 /* If in the region, merge in the region face. */
5870 && bufpos
>= region_beg
5871 && bufpos
< region_end
)
5873 Lisp_Object region_face
= lface_from_face_name (f
, Qregion
, 0);
5874 merge_face_vectors (XVECTOR (region_face
)->contents
, attrs
);
5877 /* Look up a realized face with the given face attributes,
5878 or realize a new one. */
5879 return lookup_face (f
, attrs
, multibyte_p
? CHARSET_ASCII
: -1);
5884 /***********************************************************************
5886 ***********************************************************************/
5890 /* Print the contents of the realized face FACE to stderr. */
5893 dump_realized_face (face
)
5896 fprintf (stderr
, "ID: %d\n", face
->id
);
5897 #ifdef HAVE_X_WINDOWS
5898 fprintf (stderr
, "gc: %d\n", (int) face
->gc
);
5900 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
5902 XSTRING (face
->lface
[LFACE_FOREGROUND_INDEX
])->data
);
5903 fprintf (stderr
, "background: 0x%lx (%s)\n",
5905 XSTRING (face
->lface
[LFACE_BACKGROUND_INDEX
])->data
);
5906 fprintf (stderr
, "font_name: %s (%s)\n",
5908 XSTRING (face
->lface
[LFACE_FAMILY_INDEX
])->data
);
5909 #ifdef HAVE_X_WINDOWS
5910 fprintf (stderr
, "font = %p\n", face
->font
);
5912 fprintf (stderr
, "font_info_id = %d\n", face
->font_info_id
);
5913 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
5914 fprintf (stderr
, "underline: %d (%s)\n",
5916 XSTRING (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
]))->data
);
5917 fprintf (stderr
, "hash: %d\n", face
->hash
);
5918 fprintf (stderr
, "charset: %d\n", face
->charset
);
5922 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, "")
5930 fprintf (stderr
, "font selection order: ");
5931 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5932 fprintf (stderr
, "%d ", font_sort_order
[i
]);
5933 fprintf (stderr
, "\n");
5935 fprintf (stderr
, "alternative fonts: ");
5936 debug_print (Vface_alternative_font_family_alist
);
5937 fprintf (stderr
, "\n");
5939 for (i
= 0; i
< FRAME_FACE_CACHE (selected_frame
)->used
; ++i
)
5940 Fdump_face (make_number (i
));
5945 CHECK_NUMBER (n
, 0);
5946 face
= FACE_FROM_ID (selected_frame
, XINT (n
));
5948 error ("Not a valid face");
5949 dump_realized_face (face
);
5956 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
5960 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
5961 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
5962 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
5966 #endif /* GLYPH_DEBUG != 0 */
5970 /***********************************************************************
5972 ***********************************************************************/
5977 Qface
= intern ("face");
5979 Qpixmap_spec_p
= intern ("pixmap-spec-p");
5980 staticpro (&Qpixmap_spec_p
);
5982 /* Lisp face attribute keywords. */
5983 QCfamily
= intern (":family");
5984 staticpro (&QCfamily
);
5985 QCheight
= intern (":height");
5986 staticpro (&QCheight
);
5987 QCweight
= intern (":weight");
5988 staticpro (&QCweight
);
5989 QCslant
= intern (":slant");
5990 staticpro (&QCslant
);
5991 QCunderline
= intern (":underline");
5992 staticpro (&QCunderline
);
5993 QCinverse_video
= intern (":inverse-video");
5994 staticpro (&QCinverse_video
);
5995 QCreverse_video
= intern (":reverse-video");
5996 staticpro (&QCreverse_video
);
5997 QCforeground
= intern (":foreground");
5998 staticpro (&QCforeground
);
5999 QCbackground
= intern (":background");
6000 staticpro (&QCbackground
);
6001 QCstipple
= intern (":stipple");;
6002 staticpro (&QCstipple
);
6003 QCwidth
= intern (":width");
6004 staticpro (&QCwidth
);
6005 QCfont
= intern (":font");
6006 staticpro (&QCfont
);
6007 QCbold
= intern (":bold");
6008 staticpro (&QCbold
);
6009 QCitalic
= intern (":italic");
6010 staticpro (&QCitalic
);
6011 QCoverline
= intern (":overline");
6012 staticpro (&QCoverline
);
6013 QCstrike_through
= intern (":strike-through");
6014 staticpro (&QCstrike_through
);
6015 QCbox
= intern (":box");
6018 /* Symbols used for Lisp face attribute values. */
6019 QCcolor
= intern (":color");
6020 staticpro (&QCcolor
);
6021 QCline_width
= intern (":line-width");
6022 staticpro (&QCline_width
);
6023 QCstyle
= intern (":style");
6024 staticpro (&QCstyle
);
6025 Qreleased_button
= intern ("released-button");
6026 staticpro (&Qreleased_button
);
6027 Qpressed_button
= intern ("pressed-button");
6028 staticpro (&Qpressed_button
);
6029 Qnormal
= intern ("normal");
6030 staticpro (&Qnormal
);
6031 Qultra_light
= intern ("ultra-light");
6032 staticpro (&Qultra_light
);
6033 Qextra_light
= intern ("extra-light");
6034 staticpro (&Qextra_light
);
6035 Qlight
= intern ("light");
6036 staticpro (&Qlight
);
6037 Qsemi_light
= intern ("semi-light");
6038 staticpro (&Qsemi_light
);
6039 Qsemi_bold
= intern ("semi-bold");
6040 staticpro (&Qsemi_bold
);
6041 Qbold
= intern ("bold");
6043 Qextra_bold
= intern ("extra-bold");
6044 staticpro (&Qextra_bold
);
6045 Qultra_bold
= intern ("ultra-bold");
6046 staticpro (&Qultra_bold
);
6047 Qoblique
= intern ("oblique");
6048 staticpro (&Qoblique
);
6049 Qitalic
= intern ("italic");
6050 staticpro (&Qitalic
);
6051 Qreverse_oblique
= intern ("reverse-oblique");
6052 staticpro (&Qreverse_oblique
);
6053 Qreverse_italic
= intern ("reverse-italic");
6054 staticpro (&Qreverse_italic
);
6055 Qultra_condensed
= intern ("ultra-condensed");
6056 staticpro (&Qultra_condensed
);
6057 Qextra_condensed
= intern ("extra-condensed");
6058 staticpro (&Qextra_condensed
);
6059 Qcondensed
= intern ("condensed");
6060 staticpro (&Qcondensed
);
6061 Qsemi_condensed
= intern ("semi-condensed");
6062 staticpro (&Qsemi_condensed
);
6063 Qsemi_expanded
= intern ("semi-expanded");
6064 staticpro (&Qsemi_expanded
);
6065 Qexpanded
= intern ("expanded");
6066 staticpro (&Qexpanded
);
6067 Qextra_expanded
= intern ("extra-expanded");
6068 staticpro (&Qextra_expanded
);
6069 Qultra_expanded
= intern ("ultra-expanded");
6070 staticpro (&Qultra_expanded
);
6071 Qbackground_color
= intern ("background-color");
6072 staticpro (&Qbackground_color
);
6073 Qforeground_color
= intern ("foreground-color");
6074 staticpro (&Qforeground_color
);
6075 Qunspecified
= intern ("unspecified");
6076 staticpro (&Qunspecified
);
6078 Qx_charset_registry
= intern ("x-charset-registry");
6079 staticpro (&Qx_charset_registry
);
6080 Qdefault
= intern ("default");
6081 staticpro (&Qdefault
);
6082 Qmodeline
= intern ("modeline");
6083 staticpro (&Qmodeline
);
6084 Qtoolbar
= intern ("toolbar");
6085 staticpro (&Qtoolbar
);
6086 Qregion
= intern ("region");
6087 staticpro (&Qregion
);
6088 Qbitmap_area
= intern ("bitmap-area");
6089 staticpro (&Qbitmap_area
);
6090 Qtop_line
= intern ("top-line");
6091 staticpro (&Qtop_line
);
6093 defsubr (&Sinternal_make_lisp_face
);
6094 defsubr (&Sinternal_lisp_face_p
);
6095 defsubr (&Sinternal_set_lisp_face_attribute
);
6096 #ifdef HAVE_X_WINDOWS
6097 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
6098 defsubr (&Sface_color_gray_p
);
6099 defsubr (&Sface_color_supported_p
);
6101 defsubr (&Sinternal_get_lisp_face_attribute
);
6102 defsubr (&Sinternal_lisp_face_attribute_values
);
6103 defsubr (&Sinternal_lisp_face_equal_p
);
6104 defsubr (&Sinternal_lisp_face_empty_p
);
6105 defsubr (&Sinternal_copy_lisp_face
);
6106 defsubr (&Sinternal_merge_in_global_face
);
6107 defsubr (&Sface_font
);
6108 defsubr (&Sframe_face_alist
);
6109 defsubr (&Sinternal_set_font_selection_order
);
6110 defsubr (&Sinternal_set_alternative_font_family_alist
);
6112 defsubr (&Sdump_face
);
6113 defsubr (&Sshow_face_resources
);
6114 #endif /* GLYPH_DEBUG */
6115 defsubr (&Sclear_face_cache
);
6117 DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults
,
6118 "List of global face definitions (for internal use only.)");
6119 Vface_new_frame_defaults
= Qnil
;
6121 DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple
,
6122 "*Default stipple pattern used on monochrome displays.\n\
6123 This stipple pattern is used on monochrome displays\n\
6124 instead of shades of gray for a face background color.\n\
6125 See `set-face-stipple' for possible values for this variable.");
6126 Vface_default_stipple
= build_string ("gray3");
6128 DEFVAR_LISP ("face-default-registry", &Vface_default_registry
,
6129 "Default registry and encoding to use.\n\
6130 This registry and encoding is used for unibyte text. It is set up\n\
6131 from the specified frame font when Emacs starts. (For internal use only.)");
6132 Vface_default_registry
= Qnil
;
6134 DEFVAR_LISP ("face-alternative-font-family-alist",
6135 &Vface_alternative_font_family_alist
, "");
6136 Vface_alternative_font_family_alist
= Qnil
;
6140 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed
,
6141 "Allowed scalable fonts.\n\
6142 A value of nil means don't allow any scalable fonts.\n\
6143 A value of t means allow any scalable font.\n\
6144 Otherwise, value must be a list of regular expressions. A font may be\n\
6145 scaled if its name matches a regular expression in the list.");
6146 Vscalable_fonts_allowed
= Qnil
;
6148 #endif /* SCALABLE_FONTS */
6150 #ifdef HAVE_X_WINDOWS
6151 defsubr (&Spixmap_spec_p
);
6152 defsubr (&Sx_list_fonts
);
6153 defsubr (&Sinternal_face_x_get_resource
);
6154 defsubr (&Sx_font_list
);
6155 defsubr (&Sx_font_family_list
);
6156 #endif /* HAVE_X_WINDOWS */
6158 /* TTY face support. */
6159 defsubr (&Sface_register_tty_color
);
6160 defsubr (&Sface_clear_tty_colors
);
6161 defsubr (&Stty_defined_colors
);
6162 Vface_tty_color_alist
= Qnil
;
6163 staticpro (&Vface_tty_color_alist
);