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
181 #include <sys/types.h>
182 #include <sys/stat.h>
187 #ifdef HAVE_X_WINDOWS
192 #include <Xm/XmStrDefs.h>
193 #endif /* USE_MOTIF */
201 #include "dispextern.h"
202 #include "blockinput.h"
204 #include "intervals.h"
206 #ifdef HAVE_X_WINDOWS
208 /* Compensate for a bug in Xos.h on some systems, on which it requires
209 time.h. On some such systems, Xos.h tries to redefine struct
210 timeval and struct timezone if USG is #defined while it is
213 #ifdef XOS_NEEDS_TIME_H
219 #else /* not XOS_NEEDS_TIME_H */
221 #endif /* not XOS_NEEDS_TIME_H */
223 #endif /* HAVE_X_WINDOWS */
227 #include "keyboard.h"
230 #define max(A, B) ((A) > (B) ? (A) : (B))
231 #define min(A, B) ((A) < (B) ? (A) : (B))
232 #define abs(X) ((X) < 0 ? -(X) : (X))
235 /* Non-zero if face attribute ATTR is unspecified. */
237 #define UNSPECIFIEDP(ATTR) EQ ((ATTR), Qunspecified)
239 /* Value is the number of elements of VECTOR. */
241 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
243 /* Make a copy of string S on the stack using alloca. Value is a pointer
246 #define STRDUPA(S) strcpy ((char *) alloca (strlen ((S)) + 1), (S))
248 /* Make a copy of the contents of Lisp string S on the stack using
249 alloca. Value is a pointer to the copy. */
251 #define LSTRDUPA(S) STRDUPA (XSTRING ((S))->data)
253 /* Size of hash table of realized faces in face caches (should be a
256 #define FACE_CACHE_BUCKETS_SIZE 1001
258 /* Keyword symbols used for face attribute names. */
260 Lisp_Object QCfamily
, QCheight
, QCweight
, QCslant
, QCunderline
;
261 Lisp_Object QCinverse_video
, QCforeground
, QCbackground
, QCstipple
;
262 Lisp_Object QCwidth
, QCfont
, QCbold
, QCitalic
;
263 Lisp_Object QCreverse_video
;
264 Lisp_Object QCoverline
, QCstrike_through
, QCbox
;
266 /* Symbols used for attribute values. */
268 Lisp_Object Qnormal
, Qbold
, Qultra_light
, Qextra_light
, Qlight
;
269 Lisp_Object Qsemi_light
, Qsemi_bold
, Qextra_bold
, Qultra_bold
;
270 Lisp_Object Qoblique
, Qitalic
, Qreverse_oblique
, Qreverse_italic
;
271 Lisp_Object Qultra_condensed
, Qextra_condensed
, Qcondensed
;
272 Lisp_Object Qsemi_condensed
, Qsemi_expanded
, Qexpanded
, Qextra_expanded
;
273 Lisp_Object Qultra_expanded
;
274 Lisp_Object Qreleased_button
, Qpressed_button
;
275 Lisp_Object QCstyle
, QCcolor
, QCline_width
;
276 Lisp_Object Qunspecified
;
278 /* The symbol `x-charset-registry'. This property of charsets defines
279 the X registry and encoding that fonts should have that are used to
280 display characters of that charset. */
282 Lisp_Object Qx_charset_registry
;
284 /* The name of the function to call when the background of the frame
285 has changed, frame_update_face_colors. */
287 Lisp_Object Qframe_update_face_colors
;
289 /* Names of basic faces. */
291 Lisp_Object Qdefault
, Qtool_bar
, Qregion
, Qfringe
;
292 Lisp_Object Qheader_line
, Qscroll_bar
, Qcursor
, Qborder
, Qmouse
, Qmenu
;
293 extern Lisp_Object Qmode_line
;
295 /* The symbol `face-alias'. A symbols having that property is an
296 alias for another face. Value of the property is the name of
299 Lisp_Object Qface_alias
;
301 /* Names of frame parameters related to faces. */
303 extern Lisp_Object Qscroll_bar_foreground
, Qscroll_bar_background
;
304 extern Lisp_Object Qborder_color
, Qcursor_color
, Qmouse_color
;
306 /* Default stipple pattern used on monochrome displays. This stipple
307 pattern is used on monochrome displays instead of shades of gray
308 for a face background color. See `set-face-stipple' for possible
309 values for this variable. */
311 Lisp_Object Vface_default_stipple
;
313 /* Default registry and encoding to use for charsets whose charset
314 symbols don't specify one. */
316 Lisp_Object Vface_default_registry
;
318 /* Alist of alternative font families. Each element is of the form
319 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
320 try FAMILY1, then FAMILY2, ... */
322 Lisp_Object Vface_alternative_font_family_alist
;
324 /* Allowed scalable fonts. A value of nil means don't allow any
325 scalable fonts. A value of t means allow the use of any scalable
326 font. Otherwise, value must be a list of regular expressions. A
327 font may be scaled if its name matches a regular expression in the
331 Lisp_Object Vscalable_fonts_allowed
;
334 /* Maximum number of fonts to consider in font_list. If not an
335 integer > 0, DEFAULT_FONT_LIST_LIMIT is used instead. */
337 Lisp_Object Vfont_list_limit
;
338 #define DEFAULT_FONT_LIST_LIMIT 100
340 /* The symbols `foreground-color' and `background-color' which can be
341 used as part of a `face' property. This is for compatibility with
344 Lisp_Object Qforeground_color
, Qbackground_color
;
346 /* The symbols `face' and `mouse-face' used as text properties. */
349 extern Lisp_Object Qmouse_face
;
351 /* Error symbol for wrong_type_argument in load_pixmap. */
353 Lisp_Object Qbitmap_spec_p
;
355 /* Alist of global face definitions. Each element is of the form
356 (FACE . LFACE) where FACE is a symbol naming a face and LFACE
357 is a Lisp vector of face attributes. These faces are used
358 to initialize faces for new frames. */
360 Lisp_Object Vface_new_frame_defaults
;
362 /* The next ID to assign to Lisp faces. */
364 static int next_lface_id
;
366 /* A vector mapping Lisp face Id's to face names. */
368 static Lisp_Object
*lface_id_to_name
;
369 static int lface_id_to_name_size
;
371 /* An alist of elements (COLOR-NAME . INDEX) mapping color names
372 to color indices for tty frames. */
374 Lisp_Object Vface_tty_color_alist
;
376 /* Counter for calls to clear_face_cache. If this counter reaches
377 CLEAR_FONT_TABLE_COUNT, and a frame has more than
378 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */
380 static int clear_font_table_count
;
381 #define CLEAR_FONT_TABLE_COUNT 100
382 #define CLEAR_FONT_TABLE_NFONTS 10
384 /* Non-zero means face attributes have been changed since the last
385 redisplay. Used in redisplay_internal. */
387 int face_change_count
;
389 /* The total number of colors currently allocated. */
392 static int ncolors_allocated
;
393 static int npixmaps_allocated
;
399 /* Function prototypes. */
404 static Lisp_Object resolve_face_name
P_ ((Lisp_Object
));
405 static int may_use_scalable_font_p
P_ ((struct font_name
*, char *));
406 static void set_font_frame_param
P_ ((Lisp_Object
, Lisp_Object
));
407 static int better_font_p
P_ ((int *, struct font_name
*, struct font_name
*,
409 static int first_font_matching
P_ ((struct frame
*f
, char *,
410 struct font_name
*));
411 static int x_face_list_fonts
P_ ((struct frame
*, char *,
412 struct font_name
*, int, int, int));
413 static int font_scalable_p
P_ ((struct font_name
*));
414 static Lisp_Object deduce_unibyte_registry
P_ ((struct frame
*, char *));
415 static int get_lface_attributes
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
*, int));
416 static int load_pixmap
P_ ((struct frame
*, Lisp_Object
, unsigned *, unsigned *));
417 static char *xstrdup
P_ ((char *));
418 static unsigned char *xstrlwr
P_ ((unsigned char *));
419 static void signal_error
P_ ((char *, Lisp_Object
));
420 static struct frame
*frame_or_selected_frame
P_ ((Lisp_Object
, int));
421 static void load_face_font_or_fontset
P_ ((struct frame
*, struct face
*, char *, int));
422 static void load_face_colors
P_ ((struct frame
*, struct face
*, Lisp_Object
*));
423 static void free_face_colors
P_ ((struct frame
*, struct face
*));
424 static int face_color_gray_p
P_ ((struct frame
*, char *));
425 static char *build_font_name
P_ ((struct font_name
*));
426 static void free_font_names
P_ ((struct font_name
*, int));
427 static int sorted_font_list
P_ ((struct frame
*, char *,
428 int (*cmpfn
) P_ ((const void *, const void *)),
429 struct font_name
**));
430 static int font_list
P_ ((struct frame
*, char *, char *, char *, struct font_name
**));
431 static int try_font_list
P_ ((struct frame
*, Lisp_Object
*, char *, char *, char *,
432 struct font_name
**));
433 static int cmp_font_names
P_ ((const void *, const void *));
434 static struct face
*realize_face
P_ ((struct face_cache
*,
435 Lisp_Object
*, int));
436 static struct face
*realize_x_face
P_ ((struct face_cache
*,
437 Lisp_Object
*, int));
438 static struct face
*realize_tty_face
P_ ((struct face_cache
*,
439 Lisp_Object
*, int));
440 static int realize_basic_faces
P_ ((struct frame
*));
441 static int realize_default_face
P_ ((struct frame
*));
442 static void realize_named_face
P_ ((struct frame
*, Lisp_Object
, int));
443 static int lface_fully_specified_p
P_ ((Lisp_Object
*));
444 static int lface_equal_p
P_ ((Lisp_Object
*, Lisp_Object
*));
445 static unsigned hash_string_case_insensitive
P_ ((Lisp_Object
));
446 static unsigned lface_hash
P_ ((Lisp_Object
*));
447 static int lface_same_font_attributes_p
P_ ((Lisp_Object
*, Lisp_Object
*));
448 static struct face_cache
*make_face_cache
P_ ((struct frame
*));
449 static void free_realized_face
P_ ((struct frame
*, struct face
*));
450 static void clear_face_gcs
P_ ((struct face_cache
*));
451 static void free_face_cache
P_ ((struct face_cache
*));
452 static int face_numeric_weight
P_ ((Lisp_Object
));
453 static int face_numeric_slant
P_ ((Lisp_Object
));
454 static int face_numeric_swidth
P_ ((Lisp_Object
));
455 static int face_fontset
P_ ((struct frame
*, Lisp_Object
*));
456 static char *choose_face_font
P_ ((struct frame
*, Lisp_Object
*, int,
458 static char *choose_face_fontset_font
P_ ((struct frame
*, Lisp_Object
*,
460 static void merge_face_vectors
P_ ((Lisp_Object
*from
, Lisp_Object
*));
461 static void merge_face_vector_with_property
P_ ((struct frame
*, Lisp_Object
*,
463 static int set_lface_from_font_name
P_ ((struct frame
*, Lisp_Object
, char *,
465 static Lisp_Object lface_from_face_name
P_ ((struct frame
*, Lisp_Object
, int));
466 static struct face
*make_realized_face
P_ ((Lisp_Object
*, int, Lisp_Object
));
467 static void free_realized_faces
P_ ((struct face_cache
*));
468 static char *best_matching_font
P_ ((struct frame
*, Lisp_Object
*,
469 struct font_name
*, int));
470 static void cache_face
P_ ((struct face_cache
*, struct face
*, unsigned));
471 static void uncache_face
P_ ((struct face_cache
*, struct face
*));
472 static int xlfd_numeric_slant
P_ ((struct font_name
*));
473 static int xlfd_numeric_weight
P_ ((struct font_name
*));
474 static int xlfd_numeric_swidth
P_ ((struct font_name
*));
475 static Lisp_Object xlfd_symbolic_slant
P_ ((struct font_name
*));
476 static Lisp_Object xlfd_symbolic_weight
P_ ((struct font_name
*));
477 static Lisp_Object xlfd_symbolic_swidth
P_ ((struct font_name
*));
478 static int xlfd_fixed_p
P_ ((struct font_name
*));
479 static int xlfd_numeric_value
P_ ((struct table_entry
*, int, struct font_name
*,
481 static Lisp_Object xlfd_symbolic_value
P_ ((struct table_entry
*, int,
482 struct font_name
*, int, int));
483 static struct table_entry
*xlfd_lookup_field_contents
P_ ((struct table_entry
*, int,
484 struct font_name
*, int));
486 #ifdef HAVE_X_WINDOWS
488 static int split_font_name
P_ ((struct frame
*, struct font_name
*, int));
489 static int xlfd_point_size
P_ ((struct frame
*, struct font_name
*));
490 static void sort_fonts
P_ ((struct frame
*, struct font_name
*, int,
491 int (*cmpfn
) P_ ((const void *, const void *))));
492 static GC x_create_gc
P_ ((struct frame
*, unsigned long, XGCValues
*));
493 static void x_free_gc
P_ ((struct frame
*, GC
));
494 static void clear_font_table
P_ ((struct frame
*));
496 #endif /* HAVE_X_WINDOWS */
499 /***********************************************************************
501 ***********************************************************************/
503 #ifdef HAVE_X_WINDOWS
505 /* Create and return a GC for use on frame F. GC values and mask
506 are given by XGCV and MASK. */
509 x_create_gc (f
, mask
, xgcv
)
516 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, xgcv
);
523 /* Free GC which was used on frame F. */
531 xassert (--ngcs
>= 0);
532 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
536 #endif /* HAVE_X_WINDOWS */
539 /* Like strdup, but uses xmalloc. */
545 int len
= strlen (s
) + 1;
546 char *p
= (char *) xmalloc (len
);
552 /* Like stricmp. Used to compare parts of font names which are in
557 unsigned char *s1
, *s2
;
561 unsigned char c1
= tolower (*s1
);
562 unsigned char c2
= tolower (*s2
);
564 return c1
< c2
? -1 : 1;
569 return *s2
== 0 ? 0 : -1;
574 /* Like strlwr, which might not always be available. */
576 static unsigned char *
580 unsigned char *p
= s
;
589 /* Signal `error' with message S, and additional argument ARG. */
592 signal_error (s
, arg
)
596 Fsignal (Qerror
, Fcons (build_string (s
), Fcons (arg
, Qnil
)));
600 /* If FRAME is nil, return a pointer to the selected frame.
601 Otherwise, check that FRAME is a live frame, and return a pointer
602 to it. NPARAM is the parameter number of FRAME, for
603 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
604 Lisp function definitions. */
606 static INLINE
struct frame
*
607 frame_or_selected_frame (frame
, nparam
)
612 frame
= selected_frame
;
614 CHECK_LIVE_FRAME (frame
, nparam
);
615 return XFRAME (frame
);
619 /***********************************************************************
621 ***********************************************************************/
623 /* Initialize face cache and basic faces for frame F. */
629 /* Make a face cache, if F doesn't have one. */
630 if (FRAME_FACE_CACHE (f
) == NULL
)
631 FRAME_FACE_CACHE (f
) = make_face_cache (f
);
633 #ifdef HAVE_X_WINDOWS
634 /* Make the image cache. */
637 if (FRAME_X_IMAGE_CACHE (f
) == NULL
)
638 FRAME_X_IMAGE_CACHE (f
) = make_image_cache ();
639 ++FRAME_X_IMAGE_CACHE (f
)->refcount
;
641 #endif /* HAVE_X_WINDOWS */
643 /* Realize basic faces. Must have enough information in frame
644 parameters to realize basic faces at this point. */
645 #ifdef HAVE_X_WINDOWS
646 if (!FRAME_X_P (f
) || FRAME_X_WINDOW (f
))
648 if (!realize_basic_faces (f
))
653 /* Free face cache of frame F. Called from Fdelete_frame. */
659 struct face_cache
*face_cache
= FRAME_FACE_CACHE (f
);
663 free_face_cache (face_cache
);
664 FRAME_FACE_CACHE (f
) = NULL
;
667 #ifdef HAVE_X_WINDOWS
670 struct image_cache
*image_cache
= FRAME_X_IMAGE_CACHE (f
);
673 --image_cache
->refcount
;
674 if (image_cache
->refcount
== 0)
675 free_image_cache (f
);
678 #endif /* HAVE_X_WINDOWS */
682 /* Clear face caches, and recompute basic faces for frame F. Call
683 this after changing frame parameters on which those faces depend,
684 or when realized faces have been freed due to changing attributes
688 recompute_basic_faces (f
)
691 if (FRAME_FACE_CACHE (f
))
694 clear_face_cache (0);
695 realized_p
= realize_basic_faces (f
);
696 xassert (realized_p
);
701 /* Clear the face caches of all frames. CLEAR_FONTS_P non-zero means
702 try to free unused fonts, too. */
705 clear_face_cache (clear_fonts_p
)
708 #ifdef HAVE_X_WINDOWS
709 Lisp_Object tail
, frame
;
713 || ++clear_font_table_count
== CLEAR_FONT_TABLE_COUNT
)
715 /* From time to time see if we can unload some fonts. This also
716 frees all realized faces on all frames. Fonts needed by
717 faces will be loaded again when faces are realized again. */
718 clear_font_table_count
= 0;
720 FOR_EACH_FRAME (tail
, frame
)
724 && FRAME_X_DISPLAY_INFO (f
)->n_fonts
> CLEAR_FONT_TABLE_NFONTS
)
726 free_all_realized_faces (frame
);
727 clear_font_table (f
);
733 /* Clear GCs of realized faces. */
734 FOR_EACH_FRAME (tail
, frame
)
739 clear_face_gcs (FRAME_FACE_CACHE (f
));
740 clear_image_cache (f
, 0);
744 #endif /* HAVE_X_WINDOWS */
748 DEFUN ("clear-face-cache", Fclear_face_cache
, Sclear_face_cache
, 0, 1, 0,
749 "Clear face caches on all frames.\n\
750 Optional THOROUGHLY non-nil means try to free unused fonts, too.")
752 Lisp_Object thorougly
;
754 clear_face_cache (!NILP (thorougly
));
760 #ifdef HAVE_X_WINDOWS
763 /* Remove those fonts from the font table of frame F that are not used
764 by fontsets. Called from clear_face_cache from time to time. */
770 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
772 Lisp_Object rest
, frame
;
775 xassert (FRAME_X_P (f
));
777 used
= (char *) alloca (dpyinfo
->n_fonts
* sizeof *used
);
778 bzero (used
, dpyinfo
->n_fonts
* sizeof *used
);
780 /* For all frames with the same x_display_info as F, record
781 in `used' those fonts that are in use by fontsets. */
782 FOR_EACH_FRAME (rest
, frame
)
783 if (FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
785 struct frame
*f
= XFRAME (frame
);
786 struct fontset_data
*fontset_data
= FRAME_FONTSET_DATA (f
);
788 for (i
= 0; i
< fontset_data
->n_fontsets
; ++i
)
790 struct fontset_info
*info
= fontset_data
->fontset_table
[i
];
793 for (j
= 0; j
<= MAX_CHARSET
; ++j
)
795 int idx
= info
->font_indexes
[j
];
802 /* Free those fonts that are not used by fontsets. */
803 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
804 if (used
[i
] == 0 && dpyinfo
->font_table
[i
].name
)
806 struct font_info
*font_info
= dpyinfo
->font_table
+ i
;
808 /* Free names. In xfns.c there is a comment that full_name
809 should never be freed because it is always shared with
810 something else. I don't think this is true anymore---see
811 x_load_font. It's either equal to font_info->name or
812 allocated via xmalloc, and there seems to be no place in
813 the source files where full_name is transferred to another
815 if (font_info
->full_name
!= font_info
->name
)
816 xfree (font_info
->full_name
);
817 xfree (font_info
->name
);
821 XFreeFont (dpyinfo
->display
, font_info
->font
);
824 /* Mark font table slot free. */
825 font_info
->font
= NULL
;
826 font_info
->name
= font_info
->full_name
= NULL
;
831 #endif /* HAVE_X_WINDOWS */
835 /***********************************************************************
837 ***********************************************************************/
839 #ifdef HAVE_X_WINDOWS
841 DEFUN ("bitmap-spec-p", Fbitmap_spec_p
, Sbitmap_spec_p
, 1, 1, 0,
842 "Value is non-nil if OBJECT is a valid bitmap specification.\n\
843 A bitmap specification is either a string, a file name, or a list\n\
844 (WIDTH HEIGHT DATA) where WIDTH is the pixel width of the bitmap,\n\
845 HEIGHT is its height, and DATA is a string containing the bits of\n\
846 the pixmap. Bits are stored row by row, each row occupies\n\
847 (WIDTH + 7)/8 bytes.")
853 if (STRINGP (object
))
854 /* If OBJECT is a string, it's a file name. */
856 else if (CONSP (object
))
858 /* Otherwise OBJECT must be (WIDTH HEIGHT DATA), WIDTH and
859 HEIGHT must be integers > 0, and DATA must be string large
860 enough to hold a bitmap of the specified size. */
861 Lisp_Object width
, height
, data
;
863 height
= width
= data
= Qnil
;
867 width
= XCAR (object
);
868 object
= XCDR (object
);
871 height
= XCAR (object
);
872 object
= XCDR (object
);
874 data
= XCAR (object
);
878 if (NATNUMP (width
) && NATNUMP (height
) && STRINGP (data
))
880 int bytes_per_row
= ((XFASTINT (width
) + BITS_PER_CHAR
- 1)
882 if (STRING_BYTES (XSTRING (data
)) >= bytes_per_row
* height
)
887 return pixmap_p
? Qt
: Qnil
;
891 /* Load a bitmap according to NAME (which is either a file name or a
892 pixmap spec) for use on frame F. Value is the bitmap_id (see
893 xfns.c). If NAME is nil, return with a bitmap id of zero. If
894 bitmap cannot be loaded, display a message saying so, and return
895 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
896 if these pointers are not null. */
899 load_pixmap (f
, name
, w_ptr
, h_ptr
)
902 unsigned int *w_ptr
, *h_ptr
;
910 tem
= Fbitmap_spec_p (name
);
912 wrong_type_argument (Qbitmap_spec_p
, name
);
917 /* Decode a bitmap spec into a bitmap. */
922 w
= XINT (Fcar (name
));
923 h
= XINT (Fcar (Fcdr (name
)));
924 bits
= Fcar (Fcdr (Fcdr (name
)));
926 bitmap_id
= x_create_bitmap_from_data (f
, XSTRING (bits
)->data
,
931 /* It must be a string -- a file name. */
932 bitmap_id
= x_create_bitmap_from_file (f
, name
);
938 add_to_log ("Invalid or undefined bitmap %s", name
, Qnil
);
949 ++npixmaps_allocated
;
952 *w_ptr
= x_bitmap_width (f
, bitmap_id
);
955 *h_ptr
= x_bitmap_height (f
, bitmap_id
);
961 #endif /* HAVE_X_WINDOWS */
965 /***********************************************************************
967 ***********************************************************************/
969 #ifdef HAVE_X_WINDOWS
971 /* Update the line_height of frame F. Return non-zero if line height
975 frame_update_line_height (f
)
978 int fontset
, line_height
, changed_p
;
980 fontset
= f
->output_data
.x
->fontset
;
982 line_height
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
]->height
;
984 line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
986 changed_p
= line_height
!= f
->output_data
.x
->line_height
;
987 f
->output_data
.x
->line_height
= line_height
;
991 #endif /* HAVE_X_WINDOWS */
994 /***********************************************************************
996 ***********************************************************************/
998 #ifdef HAVE_X_WINDOWS
1000 /* Load font or fontset of face FACE which is used on frame F.
1001 FONTSET is the fontset FACE should use or -1, if FACE doesn't use a
1002 fontset. FONT_NAME is the name of the font to load, if no fontset
1003 is used. It is null if no suitable font name could be determined
1007 load_face_font_or_fontset (f
, face
, font_name
, fontset
)
1013 struct font_info
*font_info
= NULL
;
1015 face
->font_info_id
= -1;
1016 face
->fontset
= fontset
;
1021 font_info
= FS_LOAD_FONT (f
, FRAME_X_FONT_TABLE (f
), CHARSET_ASCII
,
1024 font_info
= FS_LOAD_FONT (f
, FRAME_X_FONT_TABLE (f
), face
->charset
,
1033 face
->font_info_id
= FONT_INFO_ID (f
, font_info
);
1034 face
->font
= font_info
->font
;
1035 face
->font_name
= font_info
->full_name
;
1037 /* Make the registry part of the font name readily accessible.
1038 The registry is used to find suitable faces for unibyte text. */
1039 s
= font_info
->full_name
+ strlen (font_info
->full_name
);
1041 while (i
< 2 && --s
>= font_info
->full_name
)
1045 if (!STRINGP (face
->registry
)
1046 || xstricmp (XSTRING (face
->registry
)->data
, s
+ 1) != 0)
1048 if (STRINGP (Vface_default_registry
)
1049 && !xstricmp (XSTRING (Vface_default_registry
)->data
, s
+ 1))
1050 face
->registry
= Vface_default_registry
;
1052 face
->registry
= build_string (s
+ 1);
1055 else if (fontset
>= 0)
1056 add_to_log ("Unable to load ASCII font of fontset %d",
1057 make_number (fontset
), Qnil
);
1059 add_to_log ("Unable to load font %s",
1060 build_string (font_name
), Qnil
);
1063 #endif /* HAVE_X_WINDOWS */
1067 /***********************************************************************
1069 ***********************************************************************/
1071 #ifdef HAVE_X_WINDOWS
1073 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
1074 black) on frame F. The algorithm is taken from 20.2 faces.el. */
1077 face_color_gray_p (f
, color_name
)
1084 if (defined_color (f
, color_name
, &color
, 0))
1085 gray_p
= ((abs (color
.red
- color
.green
)
1086 < max (color
.red
, color
.green
) / 20)
1087 && (abs (color
.green
- color
.blue
)
1088 < max (color
.green
, color
.blue
) / 20)
1089 && (abs (color
.blue
- color
.red
)
1090 < max (color
.blue
, color
.red
) / 20));
1098 /* Return non-zero if color COLOR_NAME can be displayed on frame F.
1099 BACKGROUND_P non-zero means the color will be used as background
1103 face_color_supported_p (f
, color_name
, background_p
)
1110 XSETFRAME (frame
, f
);
1111 return (!NILP (Vwindow_system
)
1112 && (!NILP (Fx_display_color_p (frame
))
1113 || xstricmp (color_name
, "black") == 0
1114 || xstricmp (color_name
, "white") == 0
1116 && face_color_gray_p (f
, color_name
))
1117 || (!NILP (Fx_display_grayscale_p (frame
))
1118 && face_color_gray_p (f
, color_name
))));
1122 DEFUN ("face-color-gray-p", Fface_color_gray_p
, Sface_color_gray_p
, 1, 2, 0,
1123 "Return non-nil if COLOR is a shade of gray (or white or black).\n\
1124 FRAME specifies the frame and thus the display for interpreting COLOR.\n\
1125 If FRAME is nil or omitted, use the selected frame.")
1127 Lisp_Object color
, frame
;
1129 struct frame
*f
= check_x_frame (frame
);
1130 CHECK_STRING (color
, 0);
1131 return face_color_gray_p (f
, XSTRING (color
)->data
) ? Qt
: Qnil
;
1135 DEFUN ("face-color-supported-p", Fface_color_supported_p
,
1136 Sface_color_supported_p
, 2, 3, 0,
1137 "Return non-nil if COLOR can be displayed on FRAME.\n\
1138 BACKGROUND-P non-nil means COLOR is used as a background.\n\
1139 If FRAME is nil or omitted, use the selected frame.\n\
1140 COLOR must be a valid color name.")
1141 (frame
, color
, background_p
)
1142 Lisp_Object frame
, color
, background_p
;
1144 struct frame
*f
= check_x_frame (frame
);
1145 CHECK_STRING (color
, 0);
1146 if (face_color_supported_p (f
, XSTRING (color
)->data
, !NILP (background_p
)))
1151 /* Load color with name NAME for use by face FACE on frame F.
1152 TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
1153 LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
1154 LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the
1155 pixel color. If color cannot be loaded, display a message, and
1156 return the foreground, background or underline color of F, but
1157 record that fact in flags of the face so that we don't try to free
1161 load_color (f
, face
, name
, target_index
)
1165 enum lface_attribute_index target_index
;
1169 xassert (STRINGP (name
));
1170 xassert (target_index
== LFACE_FOREGROUND_INDEX
1171 || target_index
== LFACE_BACKGROUND_INDEX
1172 || target_index
== LFACE_UNDERLINE_INDEX
1173 || target_index
== LFACE_OVERLINE_INDEX
1174 || target_index
== LFACE_STRIKE_THROUGH_INDEX
1175 || target_index
== LFACE_BOX_INDEX
);
1177 /* if the color map is full, defined_color will return a best match
1178 to the values in an existing cell. */
1179 if (!defined_color (f
, XSTRING (name
)->data
, &color
, 1))
1181 add_to_log ("Unable to load color %s", name
, Qnil
);
1183 switch (target_index
)
1185 case LFACE_FOREGROUND_INDEX
:
1186 face
->foreground_defaulted_p
= 1;
1187 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1190 case LFACE_BACKGROUND_INDEX
:
1191 face
->background_defaulted_p
= 1;
1192 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
1195 case LFACE_UNDERLINE_INDEX
:
1196 face
->underline_defaulted_p
= 1;
1197 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1200 case LFACE_OVERLINE_INDEX
:
1201 face
->overline_color_defaulted_p
= 1;
1202 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1205 case LFACE_STRIKE_THROUGH_INDEX
:
1206 face
->strike_through_color_defaulted_p
= 1;
1207 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1210 case LFACE_BOX_INDEX
:
1211 face
->box_color_defaulted_p
= 1;
1212 color
.pixel
= FRAME_FOREGROUND_PIXEL (f
);
1221 ++ncolors_allocated
;
1228 /* Load colors for face FACE which is used on frame F. Colors are
1229 specified by slots LFACE_BACKGROUND_INDEX and LFACE_FOREGROUND_INDEX
1230 of ATTRS. If the background color specified is not supported on F,
1231 try to emulate gray colors with a stipple from Vface_default_stipple. */
1234 load_face_colors (f
, face
, attrs
)
1241 bg
= attrs
[LFACE_BACKGROUND_INDEX
];
1242 fg
= attrs
[LFACE_FOREGROUND_INDEX
];
1244 /* Swap colors if face is inverse-video. */
1245 if (EQ (attrs
[LFACE_INVERSE_INDEX
], Qt
))
1253 /* Check for support for foreground, not for background because
1254 face_color_supported_p is smart enough to know that grays are
1255 "supported" as background because we are supposed to use stipple
1257 if (!face_color_supported_p (f
, XSTRING (bg
)->data
, 0)
1258 && !NILP (Fbitmap_spec_p (Vface_default_stipple
)))
1260 x_destroy_bitmap (f
, face
->stipple
);
1261 face
->stipple
= load_pixmap (f
, Vface_default_stipple
,
1262 &face
->pixmap_w
, &face
->pixmap_h
);
1265 face
->background
= load_color (f
, face
, bg
, LFACE_BACKGROUND_INDEX
);
1266 face
->foreground
= load_color (f
, face
, fg
, LFACE_FOREGROUND_INDEX
);
1270 /* Free color PIXEL on frame F. */
1273 unload_color (f
, pixel
)
1275 unsigned long pixel
;
1277 Display
*dpy
= FRAME_X_DISPLAY (f
);
1278 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
1280 if (pixel
== BLACK_PIX_DEFAULT (f
)
1281 || pixel
== WHITE_PIX_DEFAULT (f
))
1286 /* If display has an immutable color map, freeing colors is not
1287 necessary and some servers don't allow it. So don't do it. */
1288 if (! (class == StaticColor
|| class == StaticGray
|| class == TrueColor
))
1290 Colormap cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
1291 XFreeColors (dpy
, cmap
, &pixel
, 1, 0);
1298 /* Free colors allocated for FACE. */
1301 free_face_colors (f
, face
)
1305 int class = FRAME_X_DISPLAY_INFO (f
)->visual
->class;
1307 /* If display has an immutable color map, freeing colors is not
1308 necessary and some servers don't allow it. So don't do it. */
1309 if (class != StaticColor
1310 && class != StaticGray
1311 && class != TrueColor
)
1317 dpy
= FRAME_X_DISPLAY (f
);
1318 cmap
= DefaultColormapOfScreen (FRAME_X_SCREEN (f
));
1320 if (face
->foreground
!= BLACK_PIX_DEFAULT (f
)
1321 && face
->foreground
!= WHITE_PIX_DEFAULT (f
)
1322 && !face
->foreground_defaulted_p
)
1324 XFreeColors (dpy
, cmap
, &face
->foreground
, 1, 0);
1325 IF_DEBUG (--ncolors_allocated
);
1328 if (face
->background
!= BLACK_PIX_DEFAULT (f
)
1329 && face
->background
!= WHITE_PIX_DEFAULT (f
)
1330 && !face
->background_defaulted_p
)
1332 XFreeColors (dpy
, cmap
, &face
->background
, 1, 0);
1333 IF_DEBUG (--ncolors_allocated
);
1336 if (face
->underline_p
1337 && !face
->underline_defaulted_p
1338 && face
->underline_color
!= BLACK_PIX_DEFAULT (f
)
1339 && face
->underline_color
!= WHITE_PIX_DEFAULT (f
))
1341 XFreeColors (dpy
, cmap
, &face
->underline_color
, 1, 0);
1342 IF_DEBUG (--ncolors_allocated
);
1345 if (face
->overline_p
1346 && !face
->overline_color_defaulted_p
1347 && face
->overline_color
!= BLACK_PIX_DEFAULT (f
)
1348 && face
->overline_color
!= WHITE_PIX_DEFAULT (f
))
1350 XFreeColors (dpy
, cmap
, &face
->overline_color
, 1, 0);
1351 IF_DEBUG (--ncolors_allocated
);
1354 if (face
->strike_through_p
1355 && !face
->strike_through_color_defaulted_p
1356 && face
->strike_through_color
!= BLACK_PIX_DEFAULT (f
)
1357 && face
->strike_through_color
!= WHITE_PIX_DEFAULT (f
))
1359 XFreeColors (dpy
, cmap
, &face
->strike_through_color
, 1, 0);
1360 IF_DEBUG (--ncolors_allocated
);
1363 if (face
->box
!= FACE_NO_BOX
1364 && !face
->box_color_defaulted_p
1365 && face
->box_color
!= BLACK_PIX_DEFAULT (f
)
1366 && face
->box_color
!= WHITE_PIX_DEFAULT (f
))
1368 XFreeColors (dpy
, cmap
, &face
->box_color
, 1, 0);
1369 IF_DEBUG (--ncolors_allocated
);
1376 #else /* ! HAVE_X_WINDOWS */
1380 load_color (f
, face
, name
, target_index
)
1384 enum lface_attribute_index target_index
;
1387 int color_idx
= FACE_TTY_DEFAULT_COLOR
;
1390 return (unsigned long)FACE_TTY_DEFAULT_COLOR
;
1392 CHECK_STRING (name
, 0);
1395 if (XSTRING (name
)->size
&& !NILP (Ffboundp (Qmsdos_color_translate
)))
1397 color
= call1 (Qmsdos_color_translate
, name
);
1399 if (INTEGERP (color
))
1400 return (unsigned long)XINT (color
);
1402 add_to_log ("Unable to load color %s", name
, Qnil
);
1404 switch (target_index
)
1406 case LFACE_FOREGROUND_INDEX
:
1407 face
->foreground_defaulted_p
= 1;
1408 color_idx
= FRAME_FOREGROUND_PIXEL (f
);
1411 case LFACE_BACKGROUND_INDEX
:
1412 face
->background_defaulted_p
= 1;
1413 color_idx
= FRAME_BACKGROUND_PIXEL (f
);
1416 case LFACE_UNDERLINE_INDEX
:
1417 face
->underline_defaulted_p
= 1;
1418 color_idx
= FRAME_FOREGROUND_PIXEL (f
);
1421 case LFACE_OVERLINE_INDEX
:
1422 face
->overline_color_defaulted_p
= 1;
1423 color_idx
= FRAME_FOREGROUND_PIXEL (f
);
1426 case LFACE_STRIKE_THROUGH_INDEX
:
1427 face
->strike_through_color_defaulted_p
= 1;
1428 color_idx
= FRAME_FOREGROUND_PIXEL (f
);
1431 case LFACE_BOX_INDEX
:
1432 face
->box_color_defaulted_p
= 1;
1433 color_idx
= FRAME_FOREGROUND_PIXEL (f
);
1438 color_idx
= msdos_stdcolor_idx (XSTRING (name
)->data
);
1440 return (unsigned long)color_idx
;
1443 #endif /* ! HAVE_X_WINDOWS */
1447 /***********************************************************************
1449 ***********************************************************************/
1451 /* An enumerator for each field of an XLFD font name. */
1472 /* An enumerator for each possible slant value of a font. Taken from
1473 the XLFD specification. */
1481 XLFD_SLANT_REVERSE_ITALIC
,
1482 XLFD_SLANT_REVERSE_OBLIQUE
,
1486 /* Relative font weight according to XLFD documentation. */
1490 XLFD_WEIGHT_UNKNOWN
,
1491 XLFD_WEIGHT_ULTRA_LIGHT
, /* 10 */
1492 XLFD_WEIGHT_EXTRA_LIGHT
, /* 20 */
1493 XLFD_WEIGHT_LIGHT
, /* 30 */
1494 XLFD_WEIGHT_SEMI_LIGHT
, /* 40: SemiLight, Book, ... */
1495 XLFD_WEIGHT_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1496 XLFD_WEIGHT_SEMI_BOLD
, /* 60: SemiBold, DemiBold, ... */
1497 XLFD_WEIGHT_BOLD
, /* 70: Bold, ... */
1498 XLFD_WEIGHT_EXTRA_BOLD
, /* 80: ExtraBold, Heavy, ... */
1499 XLFD_WEIGHT_ULTRA_BOLD
/* 90: UltraBold, Black, ... */
1502 /* Relative proportionate width. */
1506 XLFD_SWIDTH_UNKNOWN
,
1507 XLFD_SWIDTH_ULTRA_CONDENSED
, /* 10 */
1508 XLFD_SWIDTH_EXTRA_CONDENSED
, /* 20 */
1509 XLFD_SWIDTH_CONDENSED
, /* 30: Condensed, Narrow, Compressed, ... */
1510 XLFD_SWIDTH_SEMI_CONDENSED
, /* 40: semicondensed */
1511 XLFD_SWIDTH_MEDIUM
, /* 50: Medium, Normal, Regular, ... */
1512 XLFD_SWIDTH_SEMI_EXPANDED
, /* 60: SemiExpanded, DemiExpanded, ... */
1513 XLFD_SWIDTH_EXPANDED
, /* 70: Expanded... */
1514 XLFD_SWIDTH_EXTRA_EXPANDED
, /* 80: ExtraExpanded, Wide... */
1515 XLFD_SWIDTH_ULTRA_EXPANDED
/* 90: UltraExpanded... */
1518 /* Structure used for tables mapping XLFD weight, slant, and width
1519 names to numeric and symbolic values. */
1525 Lisp_Object
*symbol
;
1528 /* Table of XLFD slant names and their numeric and symbolic
1529 representations. This table must be sorted by slant names in
1532 static struct table_entry slant_table
[] =
1534 {"i", XLFD_SLANT_ITALIC
, &Qitalic
},
1535 {"o", XLFD_SLANT_OBLIQUE
, &Qoblique
},
1536 {"ot", XLFD_SLANT_OTHER
, &Qitalic
},
1537 {"r", XLFD_SLANT_ROMAN
, &Qnormal
},
1538 {"ri", XLFD_SLANT_REVERSE_ITALIC
, &Qreverse_italic
},
1539 {"ro", XLFD_SLANT_REVERSE_OBLIQUE
, &Qreverse_oblique
}
1542 /* Table of XLFD weight names. This table must be sorted by weight
1543 names in ascending order. */
1545 static struct table_entry weight_table
[] =
1547 {"black", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
},
1548 {"bold", XLFD_WEIGHT_BOLD
, &Qbold
},
1549 {"book", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1550 {"demibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1551 {"extralight", XLFD_WEIGHT_EXTRA_LIGHT
, &Qextra_light
},
1552 {"extrabold", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1553 {"heavy", XLFD_WEIGHT_EXTRA_BOLD
, &Qextra_bold
},
1554 {"light", XLFD_WEIGHT_LIGHT
, &Qlight
},
1555 {"medium", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1556 {"normal", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1557 {"regular", XLFD_WEIGHT_MEDIUM
, &Qnormal
},
1558 {"semibold", XLFD_WEIGHT_SEMI_BOLD
, &Qsemi_bold
},
1559 {"semilight", XLFD_WEIGHT_SEMI_LIGHT
, &Qsemi_light
},
1560 {"ultralight", XLFD_WEIGHT_ULTRA_LIGHT
, &Qultra_light
},
1561 {"ultrabold", XLFD_WEIGHT_ULTRA_BOLD
, &Qultra_bold
}
1564 /* Table of XLFD width names. This table must be sorted by width
1565 names in ascending order. */
1567 static struct table_entry swidth_table
[] =
1569 {"compressed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1570 {"condensed", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1571 {"demiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1572 {"expanded", XLFD_SWIDTH_EXPANDED
, &Qexpanded
},
1573 {"extracondensed", XLFD_SWIDTH_EXTRA_CONDENSED
, &Qextra_condensed
},
1574 {"extraexpanded", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
},
1575 {"medium", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1576 {"narrow", XLFD_SWIDTH_CONDENSED
, &Qcondensed
},
1577 {"normal", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1578 {"regular", XLFD_SWIDTH_MEDIUM
, &Qnormal
},
1579 {"semicondensed", XLFD_SWIDTH_SEMI_CONDENSED
, &Qsemi_condensed
},
1580 {"semiexpanded", XLFD_SWIDTH_SEMI_EXPANDED
, &Qsemi_expanded
},
1581 {"ultracondensed", XLFD_SWIDTH_ULTRA_CONDENSED
, &Qultra_condensed
},
1582 {"ultraexpanded", XLFD_SWIDTH_ULTRA_EXPANDED
, &Qultra_expanded
},
1583 {"wide", XLFD_SWIDTH_EXTRA_EXPANDED
, &Qextra_expanded
}
1586 /* Structure used to hold the result of splitting font names in XLFD
1587 format into their fields. */
1591 /* The original name which is modified destructively by
1592 split_font_name. The pointer is kept here to be able to free it
1593 if it was allocated from the heap. */
1596 /* Font name fields. Each vector element points into `name' above.
1597 Fields are NUL-terminated. */
1598 char *fields
[XLFD_LAST
];
1600 /* Numeric values for those fields that interest us. See
1601 split_font_name for which these are. */
1602 int numeric
[XLFD_LAST
];
1605 /* The frame in effect when sorting font names. Set temporarily in
1606 sort_fonts so that it is available in font comparison functions. */
1608 static struct frame
*font_frame
;
1610 /* Order by which font selection chooses fonts. The default values
1611 mean `first, find a best match for the font width, then for the
1612 font height, then for weight, then for slant.' This variable can be
1613 set via set-face-font-sort-order. */
1615 static int font_sort_order
[4];
1618 /* Look up FONT.fields[FIELD_INDEX] in TABLE which has DIM entries.
1619 TABLE must be sorted by TABLE[i]->name in ascending order. Value
1620 is a pointer to the matching table entry or null if no table entry
1623 static struct table_entry
*
1624 xlfd_lookup_field_contents (table
, dim
, font
, field_index
)
1625 struct table_entry
*table
;
1627 struct font_name
*font
;
1630 /* Function split_font_name converts fields to lower-case, so there
1631 is no need to use xstrlwr or xstricmp here. */
1632 char *s
= font
->fields
[field_index
];
1633 int low
, mid
, high
, cmp
;
1640 mid
= (low
+ high
) / 2;
1641 cmp
= strcmp (table
[mid
].name
, s
);
1655 /* Return a numeric representation for font name field
1656 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
1657 has DIM entries. Value is the numeric value found or DFLT if no
1658 table entry matches. This function is used to translate weight,
1659 slant, and swidth names of XLFD font names to numeric values. */
1662 xlfd_numeric_value (table
, dim
, font
, field_index
, dflt
)
1663 struct table_entry
*table
;
1665 struct font_name
*font
;
1669 struct table_entry
*p
;
1670 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
1671 return p
? p
->numeric
: dflt
;
1675 /* Return a symbolic representation for font name field
1676 FONT.fields[FIELD_INDEX]. The field is looked up in TABLE which
1677 has DIM entries. Value is the symbolic value found or DFLT if no
1678 table entry matches. This function is used to translate weight,
1679 slant, and swidth names of XLFD font names to symbols. */
1681 static INLINE Lisp_Object
1682 xlfd_symbolic_value (table
, dim
, font
, field_index
, dflt
)
1683 struct table_entry
*table
;
1685 struct font_name
*font
;
1689 struct table_entry
*p
;
1690 p
= xlfd_lookup_field_contents (table
, dim
, font
, field_index
);
1691 return p
? *p
->symbol
: dflt
;
1695 /* Return a numeric value for the slant of the font given by FONT. */
1698 xlfd_numeric_slant (font
)
1699 struct font_name
*font
;
1701 return xlfd_numeric_value (slant_table
, DIM (slant_table
),
1702 font
, XLFD_SLANT
, XLFD_SLANT_ROMAN
);
1706 /* Return a symbol representing the weight of the font given by FONT. */
1708 static INLINE Lisp_Object
1709 xlfd_symbolic_slant (font
)
1710 struct font_name
*font
;
1712 return xlfd_symbolic_value (slant_table
, DIM (slant_table
),
1713 font
, XLFD_SLANT
, Qnormal
);
1717 /* Return a numeric value for the weight of the font given by FONT. */
1720 xlfd_numeric_weight (font
)
1721 struct font_name
*font
;
1723 return xlfd_numeric_value (weight_table
, DIM (weight_table
),
1724 font
, XLFD_WEIGHT
, XLFD_WEIGHT_MEDIUM
);
1728 /* Return a symbol representing the slant of the font given by FONT. */
1730 static INLINE Lisp_Object
1731 xlfd_symbolic_weight (font
)
1732 struct font_name
*font
;
1734 return xlfd_symbolic_value (weight_table
, DIM (weight_table
),
1735 font
, XLFD_WEIGHT
, Qnormal
);
1739 /* Return a numeric value for the swidth of the font whose XLFD font
1740 name fields are found in FONT. */
1743 xlfd_numeric_swidth (font
)
1744 struct font_name
*font
;
1746 return xlfd_numeric_value (swidth_table
, DIM (swidth_table
),
1747 font
, XLFD_SWIDTH
, XLFD_SWIDTH_MEDIUM
);
1751 /* Return a symbolic value for the swidth of FONT. */
1753 static INLINE Lisp_Object
1754 xlfd_symbolic_swidth (font
)
1755 struct font_name
*font
;
1757 return xlfd_symbolic_value (swidth_table
, DIM (swidth_table
),
1758 font
, XLFD_SWIDTH
, Qnormal
);
1762 /* Look up the entry of SYMBOL in the vector TABLE which has DIM
1763 entries. Value is a pointer to the matching table entry or null if
1764 no element of TABLE contains SYMBOL. */
1766 static struct table_entry
*
1767 face_value (table
, dim
, symbol
)
1768 struct table_entry
*table
;
1774 xassert (SYMBOLP (symbol
));
1776 for (i
= 0; i
< dim
; ++i
)
1777 if (EQ (*table
[i
].symbol
, symbol
))
1780 return i
< dim
? table
+ i
: NULL
;
1784 /* Return a numeric value for SYMBOL in the vector TABLE which has DIM
1785 entries. Value is -1 if SYMBOL is not found in TABLE. */
1788 face_numeric_value (table
, dim
, symbol
)
1789 struct table_entry
*table
;
1793 struct table_entry
*p
= face_value (table
, dim
, symbol
);
1794 return p
? p
->numeric
: -1;
1798 /* Return a numeric value representing the weight specified by Lisp
1799 symbol WEIGHT. Value is one of the enumerators of enum
1803 face_numeric_weight (weight
)
1806 return face_numeric_value (weight_table
, DIM (weight_table
), weight
);
1810 /* Return a numeric value representing the slant specified by Lisp
1811 symbol SLANT. Value is one of the enumerators of enum xlfd_slant. */
1814 face_numeric_slant (slant
)
1817 return face_numeric_value (slant_table
, DIM (slant_table
), slant
);
1821 /* Return a numeric value representing the swidth specified by Lisp
1822 symbol WIDTH. Value is one of the enumerators of enum xlfd_swidth. */
1825 face_numeric_swidth (width
)
1828 return face_numeric_value (swidth_table
, DIM (swidth_table
), width
);
1832 #ifdef HAVE_X_WINDOWS
1834 /* Return non-zero if FONT is the name of a fixed-pitch font. */
1838 struct font_name
*font
;
1840 /* Function split_font_name converts fields to lower-case, so there
1841 is no need to use tolower here. */
1842 return *font
->fields
[XLFD_SPACING
] != 'p';
1846 /* Return the point size of FONT on frame F, measured in 1/10 pt.
1848 The actual height of the font when displayed on F depends on the
1849 resolution of both the font and frame. For example, a 10pt font
1850 designed for a 100dpi display will display larger than 10pt on a
1851 75dpi display. (It's not unusual to use fonts not designed for the
1852 display one is using. For example, some intlfonts are available in
1853 72dpi versions, only.)
1855 Value is the real point size of FONT on frame F, or 0 if it cannot
1859 xlfd_point_size (f
, font
)
1861 struct font_name
*font
;
1863 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
1864 double font_resy
= atoi (font
->fields
[XLFD_RESY
]);
1865 double font_pt
= atoi (font
->fields
[XLFD_POINT_SIZE
]);
1868 if (font_resy
== 0 || font_pt
== 0)
1871 real_pt
= (font_resy
/ resy
) * font_pt
+ 0.5;
1877 /* Split XLFD font name FONT->name destructively into NUL-terminated,
1878 lower-case fields in FONT->fields. NUMERIC_P non-zero means
1879 compute numeric values for fields XLFD_POINT_SIZE, XLFD_SWIDTH,
1880 XLFD_RESY, XLFD_SLANT, and XLFD_WEIGHT in FONT->numeric. Value is
1881 zero if the font name doesn't have the format we expect. The
1882 expected format is a font name that starts with a `-' and has
1883 XLFD_LAST fields separated by `-'. (The XLFD specification allows
1884 forms of font names where certain field contents are enclosed in
1885 square brackets. We don't support that, for now. */
1888 split_font_name (f
, font
, numeric_p
)
1890 struct font_name
*font
;
1896 if (*font
->name
== '-')
1898 char *p
= xstrlwr (font
->name
) + 1;
1900 while (i
< XLFD_LAST
)
1902 font
->fields
[i
] = p
;
1905 while (*p
&& *p
!= '-')
1915 success_p
= i
== XLFD_LAST
;
1917 /* If requested, and font name was in the expected format,
1918 compute numeric values for some fields. */
1919 if (numeric_p
&& success_p
)
1921 font
->numeric
[XLFD_POINT_SIZE
] = xlfd_point_size (f
, font
);
1922 font
->numeric
[XLFD_RESY
] = atoi (font
->fields
[XLFD_RESY
]);
1923 font
->numeric
[XLFD_SLANT
] = xlfd_numeric_slant (font
);
1924 font
->numeric
[XLFD_WEIGHT
] = xlfd_numeric_weight (font
);
1925 font
->numeric
[XLFD_SWIDTH
] = xlfd_numeric_swidth (font
);
1932 /* Build an XLFD font name from font name fields in FONT. Value is a
1933 pointer to the font name, which is allocated via xmalloc. */
1936 build_font_name (font
)
1937 struct font_name
*font
;
1941 char *font_name
= (char *) xmalloc (size
);
1942 int total_length
= 0;
1944 for (i
= 0; i
< XLFD_LAST
; ++i
)
1946 /* Add 1 because of the leading `-'. */
1947 int len
= strlen (font
->fields
[i
]) + 1;
1949 /* Reallocate font_name if necessary. Add 1 for the final
1951 if (total_length
+ len
+ 1 >= size
)
1953 int new_size
= max (2 * size
, size
+ len
+ 1);
1954 int sz
= new_size
* sizeof *font_name
;
1955 font_name
= (char *) xrealloc (font_name
, sz
);
1959 font_name
[total_length
] = '-';
1960 bcopy (font
->fields
[i
], font_name
+ total_length
+ 1, len
- 1);
1961 total_length
+= len
;
1964 font_name
[total_length
] = 0;
1969 /* Free an array FONTS of N font_name structures. This frees FONTS
1970 itself and all `name' fields in its elements. */
1973 free_font_names (fonts
, n
)
1974 struct font_name
*fonts
;
1978 xfree (fonts
[--n
].name
);
1983 /* Sort vector FONTS of font_name structures which contains NFONTS
1984 elements using qsort and comparison function CMPFN. F is the frame
1985 on which the fonts will be used. The global variable font_frame
1986 is temporarily set to F to make it available in CMPFN. */
1989 sort_fonts (f
, fonts
, nfonts
, cmpfn
)
1991 struct font_name
*fonts
;
1993 int (*cmpfn
) P_ ((const void *, const void *));
1996 qsort (fonts
, nfonts
, sizeof *fonts
, cmpfn
);
2001 /* Get fonts matching PATTERN on frame F. If F is null, use the first
2002 display in x_display_list. FONTS is a pointer to a vector of
2003 NFONTS font_name structures. TRY_ALTERNATIVES_P non-zero means try
2004 alternative patterns from Valternate_fontname_alist if no fonts are
2005 found matching PATTERN. SCALABLE_FONTS_P non-zero means include
2008 For all fonts found, set FONTS[i].name to the name of the font,
2009 allocated via xmalloc, and split font names into fields. Ignore
2010 fonts that we can't parse. Value is the number of fonts found.
2012 This is similar to x_list_fonts. The differences are:
2014 1. It avoids consing.
2015 2. It never calls XLoadQueryFont. */
2018 x_face_list_fonts (f
, pattern
, fonts
, nfonts
, try_alternatives_p
,
2022 struct font_name
*fonts
;
2023 int nfonts
, try_alternatives_p
;
2024 int scalable_fonts_p
;
2026 Display
*dpy
= f
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
2030 /* Get the list of fonts matching PATTERN from the X server. */
2032 names
= XListFonts (dpy
, pattern
, nfonts
, &n
);
2037 /* Make a copy of the font names we got from X, and
2038 split them into fields. */
2039 for (i
= j
= 0; i
< n
; ++i
)
2041 /* Make a copy of the font name. */
2042 fonts
[j
].name
= xstrdup (names
[i
]);
2044 /* Ignore fonts having a name that we can't parse. */
2045 if (!split_font_name (f
, fonts
+ j
, 1))
2046 xfree (fonts
[j
].name
);
2047 else if (font_scalable_p (fonts
+ j
))
2050 if (!scalable_fonts_p
2051 || !may_use_scalable_font_p (fonts
+ j
, names
[i
]))
2052 xfree (fonts
[j
].name
);
2055 #else /* !SCALABLE_FONTS */
2056 /* Always ignore scalable fonts. */
2057 xfree (fonts
[j
].name
);
2058 #endif /* !SCALABLE_FONTS */
2066 /* Free font names. */
2068 XFreeFontNames (names
);
2073 /* If no fonts found, try patterns from Valternate_fontname_alist. */
2074 if (n
== 0 && try_alternatives_p
)
2076 Lisp_Object list
= Valternate_fontname_alist
;
2078 while (CONSP (list
))
2080 Lisp_Object entry
= XCAR (list
);
2082 && STRINGP (XCAR (entry
))
2083 && strcmp (XSTRING (XCAR (entry
))->data
, pattern
) == 0)
2090 Lisp_Object patterns
= XCAR (list
);
2093 while (CONSP (patterns
)
2094 /* If list is screwed up, give up. */
2095 && (name
= XCAR (patterns
),
2097 /* Ignore patterns equal to PATTERN because we tried that
2098 already with no success. */
2099 && (strcmp (XSTRING (name
)->data
, pattern
) == 0
2100 || (n
= x_face_list_fonts (f
, XSTRING (name
)->data
,
2104 patterns
= XCDR (patterns
);
2112 /* Determine the first font matching PATTERN on frame F. Return in
2113 *FONT the matching font name, split into fields. Value is non-zero
2114 if a match was found. */
2117 first_font_matching (f
, pattern
, font
)
2120 struct font_name
*font
;
2123 struct font_name
*fonts
;
2125 fonts
= (struct font_name
*) xmalloc (nfonts
* sizeof *fonts
);
2126 nfonts
= x_face_list_fonts (f
, pattern
, fonts
, nfonts
, 1, 0);
2130 bcopy (&fonts
[0], font
, sizeof *font
);
2132 fonts
[0].name
= NULL
;
2133 free_font_names (fonts
, nfonts
);
2140 /* Determine fonts matching PATTERN on frame F. Sort resulting fonts
2141 using comparison function CMPFN. Value is the number of fonts
2142 found. If value is non-zero, *FONTS is set to a vector of
2143 font_name structures allocated from the heap containing matching
2144 fonts. Each element of *FONTS contains a name member that is also
2145 allocated from the heap. Font names in these structures are split
2146 into fields. Use free_font_names to free such an array. */
2149 sorted_font_list (f
, pattern
, cmpfn
, fonts
)
2152 int (*cmpfn
) P_ ((const void *, const void *));
2153 struct font_name
**fonts
;
2157 /* Get the list of fonts matching pattern. 100 should suffice. */
2158 nfonts
= DEFAULT_FONT_LIST_LIMIT
;
2159 if (INTEGERP (Vfont_list_limit
) && XINT (Vfont_list_limit
) > 0)
2160 nfonts
= XFASTINT (Vfont_list_limit
);
2162 *fonts
= (struct font_name
*) xmalloc (nfonts
* sizeof **fonts
);
2164 nfonts
= x_face_list_fonts (f
, pattern
, *fonts
, nfonts
, 1, 1);
2166 nfonts
= x_face_list_fonts (f
, pattern
, *fonts
, nfonts
, 1, 0);
2169 /* Sort the resulting array and return it in *FONTS. If no
2170 fonts were found, make sure to set *FONTS to null. */
2172 sort_fonts (f
, *fonts
, nfonts
, cmpfn
);
2183 /* Compare two font_name structures *A and *B. Value is analogous to
2184 strcmp. Sort order is given by the global variable
2185 font_sort_order. Font names are sorted so that, everything else
2186 being equal, fonts with a resolution closer to that of the frame on
2187 which they are used are listed first. The global variable
2188 font_frame is the frame on which we operate. */
2191 cmp_font_names (a
, b
)
2194 struct font_name
*x
= (struct font_name
*) a
;
2195 struct font_name
*y
= (struct font_name
*) b
;
2198 /* All strings have been converted to lower-case by split_font_name,
2199 so we can use strcmp here. */
2200 cmp
= strcmp (x
->fields
[XLFD_FAMILY
], y
->fields
[XLFD_FAMILY
]);
2205 for (i
= 0; i
< DIM (font_sort_order
) && cmp
== 0; ++i
)
2207 int j
= font_sort_order
[i
];
2208 cmp
= x
->numeric
[j
] - y
->numeric
[j
];
2213 /* Everything else being equal, we prefer fonts with an
2214 y-resolution closer to that of the frame. */
2215 int resy
= FRAME_X_DISPLAY_INFO (font_frame
)->resy
;
2216 int x_resy
= x
->numeric
[XLFD_RESY
];
2217 int y_resy
= y
->numeric
[XLFD_RESY
];
2218 cmp
= abs (resy
- x_resy
) - abs (resy
- y_resy
);
2226 /* Get a sorted list of fonts of family FAMILY on frame F. If PATTERN
2227 is non-null list fonts matching that pattern. Otherwise, if
2228 REGISTRY_AND_ENCODING is non-null return only fonts with that
2229 registry and encoding, otherwise return fonts of any registry and
2230 encoding. Set *FONTS to a vector of font_name structures allocated
2231 from the heap containing the fonts found. Value is the number of
2235 font_list (f
, pattern
, family
, registry_and_encoding
, fonts
)
2239 char *registry_and_encoding
;
2240 struct font_name
**fonts
;
2242 if (pattern
== NULL
)
2247 if (registry_and_encoding
== NULL
)
2248 registry_and_encoding
= "*";
2250 pattern
= (char *) alloca (strlen (family
)
2251 + strlen (registry_and_encoding
)
2253 if (index (family
, '-'))
2254 sprintf (pattern
, "-%s-*-%s", family
, registry_and_encoding
);
2256 sprintf (pattern
, "-*-%s-*-%s", family
, registry_and_encoding
);
2259 return sorted_font_list (f
, pattern
, cmp_font_names
, fonts
);
2263 /* Remove elements from LIST whose cars are `equal'. Called from
2264 x-family-fonts and x-font-family-list to remove duplicate font
2268 remove_duplicates (list
)
2271 Lisp_Object tail
= list
;
2273 while (!NILP (tail
) && !NILP (XCDR (tail
)))
2275 Lisp_Object next
= XCDR (tail
);
2276 if (!NILP (Fequal (XCAR (next
), XCAR (tail
))))
2277 XCDR (tail
) = XCDR (next
);
2284 DEFUN ("x-family-fonts", Fx_family_fonts
, Sx_family_fonts
, 0, 2, 0,
2285 "Return a list of available fonts of family FAMILY on FRAME.\n\
2286 If FAMILY is omitted or nil, list all families.\n\
2287 Otherwise, FAMILY must be a string, possibly containing wildcards\n\
2289 If FRAME is omitted or nil, use the selected frame.\n\
2290 Each element of the result is a vector [FAMILY WIDTH POINT-SIZE WEIGHT\n\
2291 SLANT FIXED-P FULL REGISTRY-AND-ENCODING].\n\
2292 FAMILY is the font family name. POINT-SIZE is the size of the\n\
2293 font in 1/10 pt. WIDTH, WEIGHT, and SLANT are symbols describing the\n\
2294 width, weight and slant of the font. These symbols are the same as for\n\
2295 face attributes. FIXED-P is non-nil if the font is fixed-pitch.\n\
2296 FULL is the full name of the font, and REGISTRY-AND-ENCODING is a string\n\
2297 giving the registry and encoding of the font.\n\
2298 The result list is sorted according to the current setting of\n\
2299 the face font sort order.")
2301 Lisp_Object family
, frame
;
2303 struct frame
*f
= check_x_frame (frame
);
2304 struct font_name
*fonts
;
2307 struct gcpro gcpro1
;
2308 char *family_pattern
;
2311 family_pattern
= "*";
2314 CHECK_STRING (family
, 1);
2315 family_pattern
= LSTRDUPA (family
);
2320 nfonts
= font_list (f
, NULL
, family_pattern
, NULL
, &fonts
);
2321 for (i
= nfonts
- 1; i
>= 0; --i
)
2323 Lisp_Object v
= Fmake_vector (make_number (8), Qnil
);
2326 #define ASET(VECTOR, IDX, VAL) (XVECTOR (VECTOR)->contents[IDX] = (VAL))
2328 ASET (v
, 0, build_string (fonts
[i
].fields
[XLFD_FAMILY
]));
2329 ASET (v
, 1, xlfd_symbolic_swidth (fonts
+ i
));
2330 ASET (v
, 2, make_number (xlfd_point_size (f
, fonts
+ i
)));
2331 ASET (v
, 3, xlfd_symbolic_weight (fonts
+ i
));
2332 ASET (v
, 4, xlfd_symbolic_slant (fonts
+ i
));
2333 ASET (v
, 5, xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
);
2334 tem
= build_font_name (fonts
+ i
);
2335 ASET (v
, 6, build_string (tem
));
2336 sprintf (tem
, "%s-%s", fonts
[i
].fields
[XLFD_REGISTRY
],
2337 fonts
[i
].fields
[XLFD_ENCODING
]);
2338 ASET (v
, 7, build_string (tem
));
2341 result
= Fcons (v
, result
);
2346 remove_duplicates (result
);
2347 free_font_names (fonts
, nfonts
);
2353 DEFUN ("x-font-family-list", Fx_font_family_list
, Sx_font_family_list
,
2355 "Return a list of available font families on FRAME.\n\
2356 If FRAME is omitted or nil, use the selected frame.\n\
2357 Value is a list of conses (FAMILY . FIXED-P) where FAMILY\n\
2358 is a font family, and FIXED-P is non-nil if fonts of that family\n\
2363 struct frame
*f
= check_x_frame (frame
);
2365 struct font_name
*fonts
;
2367 struct gcpro gcpro1
;
2368 int count
= specpdl_ptr
- specpdl
;
2371 /* Let's consider all fonts. Increase the limit for matching
2372 fonts until we have them all. */
2375 specbind (intern ("font-list-limit"), make_number (limit
));
2376 nfonts
= font_list (f
, NULL
, "*", NULL
, &fonts
);
2378 if (nfonts
== limit
)
2380 free_font_names (fonts
, nfonts
);
2389 for (i
= nfonts
- 1; i
>= 0; --i
)
2390 result
= Fcons (Fcons (build_string (fonts
[i
].fields
[XLFD_FAMILY
]),
2391 xlfd_fixed_p (fonts
+ i
) ? Qt
: Qnil
),
2394 remove_duplicates (result
);
2395 free_font_names (fonts
, nfonts
);
2397 return unbind_to (count
, result
);
2401 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 5, 0,
2402 "Return a list of the names of available fonts matching PATTERN.\n\
2403 If optional arguments FACE and FRAME are specified, return only fonts\n\
2404 the same size as FACE on FRAME.\n\
2405 PATTERN is a string, perhaps with wildcard characters;\n\
2406 the * character matches any substring, and\n\
2407 the ? character matches any single character.\n\
2408 PATTERN is case-insensitive.\n\
2409 FACE is a face name--a symbol.\n\
2411 The return value is a list of strings, suitable as arguments to\n\
2414 Fonts Emacs can't use may or may not be excluded\n\
2415 even if they match PATTERN and FACE.\n\
2416 The optional fourth argument MAXIMUM sets a limit on how many\n\
2417 fonts to match. The first MAXIMUM fonts are reported.\n\
2418 The optional fifth argument WIDTH, if specified, is a number of columns\n\
2419 occupied by a character of a font. In that case, return only fonts\n\
2420 the WIDTH times as wide as FACE on FRAME.")
2421 (pattern
, face
, frame
, maximum
, width
)
2422 Lisp_Object pattern
, face
, frame
, maximum
, width
;
2429 CHECK_STRING (pattern
, 0);
2435 CHECK_NATNUM (maximum
, 0);
2436 maxnames
= XINT (maximum
);
2440 CHECK_NUMBER (width
, 4);
2442 /* We can't simply call check_x_frame because this function may be
2443 called before any frame is created. */
2444 f
= frame_or_selected_frame (frame
, 2);
2447 /* Perhaps we have not yet created any frame. */
2452 /* Determine the width standard for comparison with the fonts we find. */
2458 /* This is of limited utility since it works with character
2459 widths. Keep it for compatibility. --gerd. */
2460 int face_id
= lookup_named_face (f
, face
, CHARSET_ASCII
);
2461 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2464 size
= face
->font
->max_bounds
.width
;
2466 size
= FRAME_FONT (f
)->max_bounds
.width
;
2469 size
*= XINT (width
);
2473 Lisp_Object args
[2];
2475 args
[0] = x_list_fonts (f
, pattern
, size
, maxnames
);
2477 /* We don't have to check fontsets. */
2479 args
[1] = list_fontsets (f
, pattern
, size
);
2480 return Fnconc (2, args
);
2484 #endif /* HAVE_X_WINDOWS */
2488 /***********************************************************************
2490 ***********************************************************************/
2492 /* Access face attributes of face FACE, a Lisp vector. */
2494 #define LFACE_FAMILY(LFACE) \
2495 XVECTOR (LFACE)->contents[LFACE_FAMILY_INDEX]
2496 #define LFACE_HEIGHT(LFACE) \
2497 XVECTOR (LFACE)->contents[LFACE_HEIGHT_INDEX]
2498 #define LFACE_WEIGHT(LFACE) \
2499 XVECTOR (LFACE)->contents[LFACE_WEIGHT_INDEX]
2500 #define LFACE_SLANT(LFACE) \
2501 XVECTOR (LFACE)->contents[LFACE_SLANT_INDEX]
2502 #define LFACE_UNDERLINE(LFACE) \
2503 XVECTOR (LFACE)->contents[LFACE_UNDERLINE_INDEX]
2504 #define LFACE_INVERSE(LFACE) \
2505 XVECTOR (LFACE)->contents[LFACE_INVERSE_INDEX]
2506 #define LFACE_FOREGROUND(LFACE) \
2507 XVECTOR (LFACE)->contents[LFACE_FOREGROUND_INDEX]
2508 #define LFACE_BACKGROUND(LFACE) \
2509 XVECTOR (LFACE)->contents[LFACE_BACKGROUND_INDEX]
2510 #define LFACE_STIPPLE(LFACE) \
2511 XVECTOR (LFACE)->contents[LFACE_STIPPLE_INDEX]
2512 #define LFACE_SWIDTH(LFACE) \
2513 XVECTOR (LFACE)->contents[LFACE_SWIDTH_INDEX]
2514 #define LFACE_OVERLINE(LFACE) \
2515 XVECTOR (LFACE)->contents[LFACE_OVERLINE_INDEX]
2516 #define LFACE_STRIKE_THROUGH(LFACE) \
2517 XVECTOR (LFACE)->contents[LFACE_STRIKE_THROUGH_INDEX]
2518 #define LFACE_BOX(LFACE) \
2519 XVECTOR (LFACE)->contents[LFACE_BOX_INDEX]
2521 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
2522 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
2524 #define LFACEP(LFACE) \
2526 && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE \
2527 && EQ (XVECTOR (LFACE)->contents[0], Qface))
2532 /* Check consistency of Lisp face attribute vector ATTRS. */
2535 check_lface_attrs (attrs
)
2538 xassert (UNSPECIFIEDP (attrs
[LFACE_FAMILY_INDEX
])
2539 || STRINGP (attrs
[LFACE_FAMILY_INDEX
]));
2540 xassert (UNSPECIFIEDP (attrs
[LFACE_SWIDTH_INDEX
])
2541 || SYMBOLP (attrs
[LFACE_SWIDTH_INDEX
]));
2542 xassert (UNSPECIFIEDP (attrs
[LFACE_HEIGHT_INDEX
])
2543 || INTEGERP (attrs
[LFACE_HEIGHT_INDEX
]));
2544 xassert (UNSPECIFIEDP (attrs
[LFACE_WEIGHT_INDEX
])
2545 || SYMBOLP (attrs
[LFACE_WEIGHT_INDEX
]));
2546 xassert (UNSPECIFIEDP (attrs
[LFACE_SLANT_INDEX
])
2547 || SYMBOLP (attrs
[LFACE_SLANT_INDEX
]));
2548 xassert (UNSPECIFIEDP (attrs
[LFACE_UNDERLINE_INDEX
])
2549 || SYMBOLP (attrs
[LFACE_UNDERLINE_INDEX
])
2550 || STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]));
2551 xassert (UNSPECIFIEDP (attrs
[LFACE_OVERLINE_INDEX
])
2552 || SYMBOLP (attrs
[LFACE_OVERLINE_INDEX
])
2553 || STRINGP (attrs
[LFACE_OVERLINE_INDEX
]));
2554 xassert (UNSPECIFIEDP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
2555 || SYMBOLP (attrs
[LFACE_STRIKE_THROUGH_INDEX
])
2556 || STRINGP (attrs
[LFACE_STRIKE_THROUGH_INDEX
]));
2557 xassert (UNSPECIFIEDP (attrs
[LFACE_BOX_INDEX
])
2558 || SYMBOLP (attrs
[LFACE_BOX_INDEX
])
2559 || STRINGP (attrs
[LFACE_BOX_INDEX
])
2560 || INTEGERP (attrs
[LFACE_BOX_INDEX
])
2561 || CONSP (attrs
[LFACE_BOX_INDEX
]));
2562 xassert (UNSPECIFIEDP (attrs
[LFACE_INVERSE_INDEX
])
2563 || SYMBOLP (attrs
[LFACE_INVERSE_INDEX
]));
2564 xassert (UNSPECIFIEDP (attrs
[LFACE_FOREGROUND_INDEX
])
2565 || STRINGP (attrs
[LFACE_FOREGROUND_INDEX
]));
2566 xassert (UNSPECIFIEDP (attrs
[LFACE_BACKGROUND_INDEX
])
2567 || STRINGP (attrs
[LFACE_BACKGROUND_INDEX
]));
2568 #ifdef HAVE_WINDOW_SYSTEM
2569 xassert (UNSPECIFIEDP (attrs
[LFACE_STIPPLE_INDEX
])
2570 || SYMBOLP (attrs
[LFACE_STIPPLE_INDEX
])
2571 || !NILP (Fbitmap_spec_p (attrs
[LFACE_STIPPLE_INDEX
])));
2576 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
2584 xassert (LFACEP (lface
));
2585 check_lface_attrs (XVECTOR (lface
)->contents
);
2589 #else /* GLYPH_DEBUG == 0 */
2591 #define check_lface_attrs(attrs) (void) 0
2592 #define check_lface(lface) (void) 0
2594 #endif /* GLYPH_DEBUG == 0 */
2597 /* Resolve face name FACE_NAME. If FACE_NAME Is a string, intern it
2598 to make it a symvol. If FACE_NAME is an alias for another face,
2599 return that face's name. */
2602 resolve_face_name (face_name
)
2603 Lisp_Object face_name
;
2605 Lisp_Object aliased
;
2607 if (STRINGP (face_name
))
2608 face_name
= intern (XSTRING (face_name
)->data
);
2612 aliased
= Fget (face_name
, Qface_alias
);
2616 face_name
= aliased
;
2623 /* Return the face definition of FACE_NAME on frame F. F null means
2624 return the global definition. FACE_NAME may be a string or a
2625 symbol (apparently Emacs 20.2 allows strings as face names in face
2626 text properties; ediff uses that). If FACE_NAME is an alias for
2627 another face, return that face's definition. If SIGNAL_P is
2628 non-zero, signal an error if FACE_NAME is not a valid face name.
2629 If SIGNAL_P is zero, value is nil if FACE_NAME is not a valid face
2632 static INLINE Lisp_Object
2633 lface_from_face_name (f
, face_name
, signal_p
)
2635 Lisp_Object face_name
;
2640 face_name
= resolve_face_name (face_name
);
2643 lface
= assq_no_quit (face_name
, f
->face_alist
);
2645 lface
= assq_no_quit (face_name
, Vface_new_frame_defaults
);
2648 lface
= XCDR (lface
);
2650 signal_error ("Invalid face", face_name
);
2652 check_lface (lface
);
2657 /* Get face attributes of face FACE_NAME from frame-local faces on
2658 frame F. Store the resulting attributes in ATTRS which must point
2659 to a vector of Lisp_Objects of size LFACE_VECTOR_SIZE. If SIGNAL_P
2660 is non-zero, signal an error if FACE_NAME does not name a face.
2661 Otherwise, value is zero if FACE_NAME is not a face. */
2664 get_lface_attributes (f
, face_name
, attrs
, signal_p
)
2666 Lisp_Object face_name
;
2673 lface
= lface_from_face_name (f
, face_name
, signal_p
);
2676 bcopy (XVECTOR (lface
)->contents
, attrs
,
2677 LFACE_VECTOR_SIZE
* sizeof *attrs
);
2687 /* Non-zero if all attributes in face attribute vector ATTRS are
2688 specified, i.e. are non-nil. */
2691 lface_fully_specified_p (attrs
)
2696 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2697 if (UNSPECIFIEDP (attrs
[i
]))
2700 return i
== LFACE_VECTOR_SIZE
;
2704 #ifdef HAVE_X_WINDOWS
2706 /* Set font-related attributes of Lisp face LFACE from XLFD font name
2707 FONT_NAME. If FORCE_P is zero, set only unspecified attributes of
2708 LFACE. MAY_FAIL_P non-zero means return 0 if FONT_NAME isn't a
2709 valid font name; otherwise this function tries to use a reasonable
2712 Ignore fields of FONT_NAME containing wildcards. Value is zero if
2713 not successful because FONT_NAME was not in a valid format and
2714 MAY_FAIL_P was non-zero. A valid format is one that is suitable
2715 for split_font_name, see the comment there. */
2718 set_lface_from_font_name (f
, lface
, font_name
, force_p
, may_fail_p
)
2722 int force_p
, may_fail_p
;
2724 struct font_name font
;
2727 int free_font_name_p
= 0;
2728 int have_font_p
= 0;
2730 /* If FONT_NAME contains wildcards, use the first matching font. */
2731 if (index (font_name
, '*') || index (font_name
, '?'))
2733 if (first_font_matching (f
, font_name
, &font
))
2734 free_font_name_p
= have_font_p
= 1;
2738 font
.name
= STRDUPA (font_name
);
2739 if (!split_font_name (f
, &font
, 1))
2741 /* The font name may be something like `6x13'. Make
2742 sure we use the full name. */
2743 struct font_info
*font_info
;
2746 font_info
= fs_load_font (f
, FRAME_X_FONT_TABLE (f
),
2747 CHARSET_ASCII
, font_name
, -1);
2752 font
.name
= STRDUPA (font_info
->full_name
);
2753 split_font_name (f
, &font
, 1);
2759 /* If FONT_NAME is completely bogus try to use something reasonable
2760 if this function must succeed. Otherwise, give up. */
2765 else if (first_font_matching (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1",
2767 || first_font_matching (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2769 || first_font_matching (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2771 || first_font_matching (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1",
2773 || first_font_matching (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1",
2775 || first_font_matching (f
, "fixed", &font
))
2776 free_font_name_p
= 1;
2782 /* Set attributes only if unspecified, otherwise face defaults for
2783 new frames would never take effect. */
2785 if (force_p
|| UNSPECIFIEDP (LFACE_FAMILY (lface
)))
2787 buffer
= (char *) alloca (strlen (font
.fields
[XLFD_FAMILY
])
2788 + strlen (font
.fields
[XLFD_FOUNDRY
])
2790 sprintf (buffer
, "%s-%s", font
.fields
[XLFD_FOUNDRY
],
2791 font
.fields
[XLFD_FAMILY
]);
2792 LFACE_FAMILY (lface
) = build_string (buffer
);
2795 if (force_p
|| UNSPECIFIEDP (LFACE_HEIGHT (lface
)))
2797 pt
= xlfd_point_size (f
, &font
);
2799 LFACE_HEIGHT (lface
) = make_number (pt
);
2802 if (force_p
|| UNSPECIFIEDP (LFACE_SWIDTH (lface
)))
2803 LFACE_SWIDTH (lface
) = xlfd_symbolic_swidth (&font
);
2805 if (force_p
|| UNSPECIFIEDP (LFACE_WEIGHT (lface
)))
2806 LFACE_WEIGHT (lface
) = xlfd_symbolic_weight (&font
);
2808 if (force_p
|| UNSPECIFIEDP (LFACE_SLANT (lface
)))
2809 LFACE_SLANT (lface
) = xlfd_symbolic_slant (&font
);
2811 if (free_font_name_p
)
2817 #endif /* HAVE_X_WINDOWS */
2820 /* Merge two Lisp face attribute vectors FROM and TO and store the
2821 resulting attributes in TO. Every non-nil attribute of FROM
2822 overrides the corresponding attribute of TO. */
2825 merge_face_vectors (from
, to
)
2826 Lisp_Object
*from
, *to
;
2829 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
2830 if (!UNSPECIFIEDP (from
[i
]))
2835 /* Given a Lisp face attribute vector TO and a Lisp object PROP that
2836 is a face property, determine the resulting face attributes on
2837 frame F, and store them in TO. PROP may be a single face
2838 specification or a list of such specifications. Each face
2839 specification can be
2841 1. A symbol or string naming a Lisp face.
2843 2. A property list of the form (KEYWORD VALUE ...) where each
2844 KEYWORD is a face attribute name, and value is an appropriate value
2847 3. Conses or the form (FOREGROUND-COLOR . COLOR) or
2848 (BACKGROUND-COLOR . COLOR) where COLOR is a color name. This is
2849 for compatibility with 20.2.
2851 Face specifications earlier in lists take precedence over later
2855 merge_face_vector_with_property (f
, to
, prop
)
2862 Lisp_Object first
= XCAR (prop
);
2864 if (EQ (first
, Qforeground_color
)
2865 || EQ (first
, Qbackground_color
))
2867 /* One of (FOREGROUND-COLOR . COLOR) or (BACKGROUND-COLOR
2868 . COLOR). COLOR must be a string. */
2869 Lisp_Object color_name
= XCDR (prop
);
2870 Lisp_Object color
= first
;
2872 if (STRINGP (color_name
))
2874 if (EQ (color
, Qforeground_color
))
2875 to
[LFACE_FOREGROUND_INDEX
] = color_name
;
2877 to
[LFACE_BACKGROUND_INDEX
] = color_name
;
2880 add_to_log ("Invalid face color", color_name
, Qnil
);
2882 else if (SYMBOLP (first
)
2883 && *XSYMBOL (first
)->name
->data
== ':')
2885 /* Assume this is the property list form. */
2886 while (CONSP (prop
) && CONSP (XCDR (prop
)))
2888 Lisp_Object keyword
= XCAR (prop
);
2889 Lisp_Object value
= XCAR (XCDR (prop
));
2891 if (EQ (keyword
, QCfamily
))
2893 if (STRINGP (value
))
2894 to
[LFACE_FAMILY_INDEX
] = value
;
2896 add_to_log ("Illegal face font family", value
, Qnil
);
2898 else if (EQ (keyword
, QCheight
))
2900 if (INTEGERP (value
))
2901 to
[LFACE_HEIGHT_INDEX
] = value
;
2903 add_to_log ("Illegal face font height", value
, Qnil
);
2905 else if (EQ (keyword
, QCweight
))
2908 && face_numeric_weight (value
) >= 0)
2909 to
[LFACE_WEIGHT_INDEX
] = value
;
2911 add_to_log ("Illegal face weight", value
, Qnil
);
2913 else if (EQ (keyword
, QCslant
))
2916 && face_numeric_slant (value
) >= 0)
2917 to
[LFACE_SLANT_INDEX
] = value
;
2919 add_to_log ("Illegal face slant", value
, Qnil
);
2921 else if (EQ (keyword
, QCunderline
))
2926 to
[LFACE_UNDERLINE_INDEX
] = value
;
2928 add_to_log ("Illegal face underline", value
, Qnil
);
2930 else if (EQ (keyword
, QCoverline
))
2935 to
[LFACE_OVERLINE_INDEX
] = value
;
2937 add_to_log ("Illegal face overline", value
, Qnil
);
2939 else if (EQ (keyword
, QCstrike_through
))
2944 to
[LFACE_STRIKE_THROUGH_INDEX
] = value
;
2946 add_to_log ("Illegal face strike-through", value
, Qnil
);
2948 else if (EQ (keyword
, QCbox
))
2951 value
= make_number (1);
2952 if (INTEGERP (value
)
2956 to
[LFACE_BOX_INDEX
] = value
;
2958 add_to_log ("Illegal face box", value
, Qnil
);
2960 else if (EQ (keyword
, QCinverse_video
)
2961 || EQ (keyword
, QCreverse_video
))
2963 if (EQ (value
, Qt
) || NILP (value
))
2964 to
[LFACE_INVERSE_INDEX
] = value
;
2966 add_to_log ("Illegal face inverse-video", value
, Qnil
);
2968 else if (EQ (keyword
, QCforeground
))
2970 if (STRINGP (value
))
2971 to
[LFACE_FOREGROUND_INDEX
] = value
;
2973 add_to_log ("Illegal face foreground", value
, Qnil
);
2975 else if (EQ (keyword
, QCbackground
))
2977 if (STRINGP (value
))
2978 to
[LFACE_BACKGROUND_INDEX
] = value
;
2980 add_to_log ("Illegal face background", value
, Qnil
);
2982 else if (EQ (keyword
, QCstipple
))
2984 #ifdef HAVE_X_WINDOWS
2985 Lisp_Object pixmap_p
= Fbitmap_spec_p (value
);
2986 if (!NILP (pixmap_p
))
2987 to
[LFACE_STIPPLE_INDEX
] = value
;
2989 add_to_log ("Illegal face stipple", value
, Qnil
);
2992 else if (EQ (keyword
, QCwidth
))
2995 && face_numeric_swidth (value
) >= 0)
2996 to
[LFACE_SWIDTH_INDEX
] = value
;
2998 add_to_log ("Illegal face width", value
, Qnil
);
3001 add_to_log ("Invalid attribute %s in face property",
3004 prop
= XCDR (XCDR (prop
));
3009 /* This is a list of face specs. Specifications at the
3010 beginning of the list take precedence over later
3011 specifications, so we have to merge starting with the
3012 last specification. */
3013 Lisp_Object next
= XCDR (prop
);
3015 merge_face_vector_with_property (f
, to
, next
);
3016 merge_face_vector_with_property (f
, to
, first
);
3021 /* PROP ought to be a face name. */
3022 Lisp_Object lface
= lface_from_face_name (f
, prop
, 0);
3024 add_to_log ("Invalid face text property value: %s", prop
, Qnil
);
3026 merge_face_vectors (XVECTOR (lface
)->contents
, to
);
3031 DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face
,
3032 Sinternal_make_lisp_face
, 1, 2, 0,
3033 "Make FACE, a symbol, a Lisp face with all attributes nil.\n\
3034 If FACE was not known as a face before, create a new one.\n\
3035 If optional argument FRAME is specified, make a frame-local face\n\
3036 for that frame. Otherwise operate on the global face definition.\n\
3037 Value is a vector of face attributes.")
3039 Lisp_Object face
, frame
;
3041 Lisp_Object global_lface
, lface
;
3045 CHECK_SYMBOL (face
, 0);
3046 global_lface
= lface_from_face_name (NULL
, face
, 0);
3050 CHECK_LIVE_FRAME (frame
, 1);
3052 lface
= lface_from_face_name (f
, face
, 0);
3055 f
= NULL
, lface
= Qnil
;
3057 /* Add a global definition if there is none. */
3058 if (NILP (global_lface
))
3060 global_lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
3062 XVECTOR (global_lface
)->contents
[0] = Qface
;
3063 Vface_new_frame_defaults
= Fcons (Fcons (face
, global_lface
),
3064 Vface_new_frame_defaults
);
3066 /* Assign the new Lisp face a unique ID. The mapping from Lisp
3067 face id to Lisp face is given by the vector lface_id_to_name.
3068 The mapping from Lisp face to Lisp face id is given by the
3069 property `face' of the Lisp face name. */
3070 if (next_lface_id
== lface_id_to_name_size
)
3072 int new_size
= max (50, 2 * lface_id_to_name_size
);
3073 int sz
= new_size
* sizeof *lface_id_to_name
;
3074 lface_id_to_name
= (Lisp_Object
*) xrealloc (lface_id_to_name
, sz
);
3075 lface_id_to_name_size
= new_size
;
3078 lface_id_to_name
[next_lface_id
] = face
;
3079 Fput (face
, Qface
, make_number (next_lface_id
));
3083 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3084 XVECTOR (global_lface
)->contents
[i
] = Qunspecified
;
3086 /* Add a frame-local definition. */
3091 lface
= Fmake_vector (make_number (LFACE_VECTOR_SIZE
),
3093 XVECTOR (lface
)->contents
[0] = Qface
;
3094 f
->face_alist
= Fcons (Fcons (face
, lface
), f
->face_alist
);
3097 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
3098 XVECTOR (lface
)->contents
[i
] = Qunspecified
;
3101 lface
= global_lface
;
3103 xassert (LFACEP (lface
));
3104 check_lface (lface
);
3109 DEFUN ("internal-lisp-face-p", Finternal_lisp_face_p
,
3110 Sinternal_lisp_face_p
, 1, 2, 0,
3111 "Return non-nil if FACE names a face.\n\
3112 If optional second parameter FRAME is non-nil, check for the\n\
3113 existence of a frame-local face with name FACE on that frame.\n\
3114 Otherwise check for the existence of a global face.")
3116 Lisp_Object face
, frame
;
3122 CHECK_LIVE_FRAME (frame
, 1);
3123 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3126 lface
= lface_from_face_name (NULL
, face
, 0);
3132 DEFUN ("internal-copy-lisp-face", Finternal_copy_lisp_face
,
3133 Sinternal_copy_lisp_face
, 4, 4, 0,
3134 "Copy face FROM to TO.\n\
3135 If FRAME it t, copy the global face definition of FROM to the\n\
3136 global face definition of TO. Otherwise, copy the frame-local\n\
3137 definition of FROM on FRAME to the frame-local definition of TO\n\
3138 on NEW-FRAME, or FRAME if NEW-FRAME is nil.\n\
3141 (from
, to
, frame
, new_frame
)
3142 Lisp_Object from
, to
, frame
, new_frame
;
3144 Lisp_Object lface
, copy
;
3146 CHECK_SYMBOL (from
, 0);
3147 CHECK_SYMBOL (to
, 1);
3148 if (NILP (new_frame
))
3153 /* Copy global definition of FROM. We don't make copies of
3154 strings etc. because 20.2 didn't do it either. */
3155 lface
= lface_from_face_name (NULL
, from
, 1);
3156 copy
= Finternal_make_lisp_face (to
, Qnil
);
3160 /* Copy frame-local definition of FROM. */
3161 CHECK_LIVE_FRAME (frame
, 2);
3162 CHECK_LIVE_FRAME (new_frame
, 3);
3163 lface
= lface_from_face_name (XFRAME (frame
), from
, 1);
3164 copy
= Finternal_make_lisp_face (to
, new_frame
);
3167 bcopy (XVECTOR (lface
)->contents
, XVECTOR (copy
)->contents
,
3168 LFACE_VECTOR_SIZE
* sizeof (Lisp_Object
));
3174 DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute
,
3175 Sinternal_set_lisp_face_attribute
, 3, 4, 0,
3176 "Set attribute ATTR of FACE to VALUE.\n\
3177 If optional argument FRAME is given, set the face attribute of face FACE\n\
3178 on that frame. If FRAME is t, set the attribute of the default for face\n\
3179 FACE (for new frames). If FRAME is omitted or nil, use the selected\n\
3181 (face
, attr
, value
, frame
)
3182 Lisp_Object face
, attr
, value
, frame
;
3185 Lisp_Object old_value
= Qnil
;
3186 int font_related_attr_p
= 0;
3188 CHECK_SYMBOL (face
, 0);
3189 CHECK_SYMBOL (attr
, 1);
3191 face
= resolve_face_name (face
);
3193 /* Set lface to the Lisp attribute vector of FACE. */
3195 lface
= lface_from_face_name (NULL
, face
, 1);
3199 frame
= selected_frame
;
3201 CHECK_LIVE_FRAME (frame
, 3);
3202 lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
3204 /* If a frame-local face doesn't exist yet, create one. */
3206 lface
= Finternal_make_lisp_face (face
, frame
);
3209 if (EQ (attr
, QCfamily
))
3211 if (!UNSPECIFIEDP (value
))
3213 CHECK_STRING (value
, 3);
3214 if (XSTRING (value
)->size
== 0)
3215 signal_error ("Invalid face family", value
);
3217 old_value
= LFACE_FAMILY (lface
);
3218 LFACE_FAMILY (lface
) = value
;
3219 font_related_attr_p
= 1;
3221 else if (EQ (attr
, QCheight
))
3223 if (!UNSPECIFIEDP (value
))
3225 CHECK_NUMBER (value
, 3);
3226 if (XINT (value
) <= 0)
3227 signal_error ("Invalid face height", value
);
3229 old_value
= LFACE_HEIGHT (lface
);
3230 LFACE_HEIGHT (lface
) = value
;
3231 font_related_attr_p
= 1;
3233 else if (EQ (attr
, QCweight
))
3235 if (!UNSPECIFIEDP (value
))
3237 CHECK_SYMBOL (value
, 3);
3238 if (face_numeric_weight (value
) < 0)
3239 signal_error ("Invalid face weight", value
);
3241 old_value
= LFACE_WEIGHT (lface
);
3242 LFACE_WEIGHT (lface
) = value
;
3243 font_related_attr_p
= 1;
3245 else if (EQ (attr
, QCslant
))
3247 if (!UNSPECIFIEDP (value
))
3249 CHECK_SYMBOL (value
, 3);
3250 if (face_numeric_slant (value
) < 0)
3251 signal_error ("Invalid face slant", value
);
3253 old_value
= LFACE_SLANT (lface
);
3254 LFACE_SLANT (lface
) = value
;
3255 font_related_attr_p
= 1;
3257 else if (EQ (attr
, QCunderline
))
3259 if (!UNSPECIFIEDP (value
))
3260 if ((SYMBOLP (value
)
3262 && !EQ (value
, Qnil
))
3263 /* Underline color. */
3265 && XSTRING (value
)->size
== 0))
3266 signal_error ("Invalid face underline", value
);
3268 old_value
= LFACE_UNDERLINE (lface
);
3269 LFACE_UNDERLINE (lface
) = value
;
3271 else if (EQ (attr
, QCoverline
))
3273 if (!UNSPECIFIEDP (value
))
3274 if ((SYMBOLP (value
)
3276 && !EQ (value
, Qnil
))
3277 /* Overline color. */
3279 && XSTRING (value
)->size
== 0))
3280 signal_error ("Invalid face overline", value
);
3282 old_value
= LFACE_OVERLINE (lface
);
3283 LFACE_OVERLINE (lface
) = value
;
3285 else if (EQ (attr
, QCstrike_through
))
3287 if (!UNSPECIFIEDP (value
))
3288 if ((SYMBOLP (value
)
3290 && !EQ (value
, Qnil
))
3291 /* Strike-through color. */
3293 && XSTRING (value
)->size
== 0))
3294 signal_error ("Invalid face strike-through", value
);
3296 old_value
= LFACE_STRIKE_THROUGH (lface
);
3297 LFACE_STRIKE_THROUGH (lface
) = value
;
3299 else if (EQ (attr
, QCbox
))
3303 /* Allow t meaning a simple box of width 1 in foreground color
3306 value
= make_number (1);
3308 if (UNSPECIFIEDP (value
))
3310 else if (NILP (value
))
3312 else if (INTEGERP (value
))
3313 valid_p
= XINT (value
) > 0;
3314 else if (STRINGP (value
))
3315 valid_p
= XSTRING (value
)->size
> 0;
3316 else if (CONSP (value
))
3332 if (EQ (k
, QCline_width
))
3334 if (!INTEGERP (v
) || XINT (v
) <= 0)
3337 else if (EQ (k
, QCcolor
))
3339 if (!STRINGP (v
) || XSTRING (v
)->size
== 0)
3342 else if (EQ (k
, QCstyle
))
3344 if (!EQ (v
, Qpressed_button
) && !EQ (v
, Qreleased_button
))
3351 valid_p
= NILP (tem
);
3357 signal_error ("Invalid face box", value
);
3359 old_value
= LFACE_BOX (lface
);
3360 LFACE_BOX (lface
) = value
;
3362 else if (EQ (attr
, QCinverse_video
)
3363 || EQ (attr
, QCreverse_video
))
3365 if (!UNSPECIFIEDP (value
))
3367 CHECK_SYMBOL (value
, 3);
3368 if (!EQ (value
, Qt
) && !NILP (value
))
3369 signal_error ("Invalid inverse-video face attribute value", value
);
3371 old_value
= LFACE_INVERSE (lface
);
3372 LFACE_INVERSE (lface
) = value
;
3374 else if (EQ (attr
, QCforeground
))
3376 if (!UNSPECIFIEDP (value
))
3378 /* Don't check for valid color names here because it depends
3379 on the frame (display) whether the color will be valid
3380 when the face is realized. */
3381 CHECK_STRING (value
, 3);
3382 if (XSTRING (value
)->size
== 0)
3383 signal_error ("Empty foreground color value", value
);
3385 old_value
= LFACE_FOREGROUND (lface
);
3386 LFACE_FOREGROUND (lface
) = value
;
3388 else if (EQ (attr
, QCbackground
))
3390 if (!UNSPECIFIEDP (value
))
3392 /* Don't check for valid color names here because it depends
3393 on the frame (display) whether the color will be valid
3394 when the face is realized. */
3395 CHECK_STRING (value
, 3);
3396 if (XSTRING (value
)->size
== 0)
3397 signal_error ("Empty background color value", value
);
3399 old_value
= LFACE_BACKGROUND (lface
);
3400 LFACE_BACKGROUND (lface
) = value
;
3402 else if (EQ (attr
, QCstipple
))
3404 #ifdef HAVE_X_WINDOWS
3405 if (!UNSPECIFIEDP (value
)
3407 && NILP (Fbitmap_spec_p (value
)))
3408 signal_error ("Invalid stipple attribute", value
);
3409 old_value
= LFACE_STIPPLE (lface
);
3410 LFACE_STIPPLE (lface
) = value
;
3411 #endif /* HAVE_X_WINDOWS */
3413 else if (EQ (attr
, QCwidth
))
3415 if (!UNSPECIFIEDP (value
))
3417 CHECK_SYMBOL (value
, 3);
3418 if (face_numeric_swidth (value
) < 0)
3419 signal_error ("Invalid face width", value
);
3421 old_value
= LFACE_SWIDTH (lface
);
3422 LFACE_SWIDTH (lface
) = value
;
3423 font_related_attr_p
= 1;
3425 else if (EQ (attr
, QCfont
))
3427 #ifdef HAVE_X_WINDOWS
3428 /* Set font-related attributes of the Lisp face from an
3432 CHECK_STRING (value
, 3);
3434 f
= SELECTED_FRAME ();
3436 f
= check_x_frame (frame
);
3438 if (!set_lface_from_font_name (f
, lface
, XSTRING (value
)->data
, 1, 1))
3439 signal_error ("Invalid font name", value
);
3441 font_related_attr_p
= 1;
3442 #endif /* HAVE_X_WINDOWS */
3444 else if (EQ (attr
, QCbold
))
3446 old_value
= LFACE_WEIGHT (lface
);
3447 LFACE_WEIGHT (lface
) = NILP (value
) ? Qnormal
: Qbold
;
3448 font_related_attr_p
= 1;
3450 else if (EQ (attr
, QCitalic
))
3452 old_value
= LFACE_SLANT (lface
);
3453 LFACE_SLANT (lface
) = NILP (value
) ? Qnormal
: Qitalic
;
3454 font_related_attr_p
= 1;
3457 signal_error ("Invalid face attribute name", attr
);
3459 /* Changing a named face means that all realized faces depending on
3460 that face are invalid. Since we cannot tell which realized faces
3461 depend on the face, make sure they are all removed. This is done
3462 by incrementing face_change_count. The next call to
3463 init_iterator will then free realized faces. */
3465 && (EQ (attr
, QCfont
)
3466 || NILP (Fequal (old_value
, value
))))
3468 ++face_change_count
;
3469 ++windows_or_buffers_changed
;
3472 #ifdef HAVE_X_WINDOWS
3475 && !UNSPECIFIEDP (value
)
3476 && NILP (Fequal (old_value
, value
)))
3482 if (EQ (face
, Qdefault
))
3484 /* Changed font-related attributes of the `default' face are
3485 reflected in changed `font' frame parameters. */
3486 if (font_related_attr_p
3487 && lface_fully_specified_p (XVECTOR (lface
)->contents
))
3488 set_font_frame_param (frame
, lface
);
3489 else if (EQ (attr
, QCforeground
))
3490 param
= Qforeground_color
;
3491 else if (EQ (attr
, QCbackground
))
3492 param
= Qbackground_color
;
3494 else if (EQ (face
, Qscroll_bar
))
3496 /* Changing the colors of `scroll-bar' sets frame parameters
3497 `scroll-bar-foreground' and `scroll-bar-background'. */
3498 if (EQ (attr
, QCforeground
))
3499 param
= Qscroll_bar_foreground
;
3500 else if (EQ (attr
, QCbackground
))
3501 param
= Qscroll_bar_background
;
3503 else if (EQ (face
, Qborder
))
3505 /* Changing background color of `border' sets frame parameter
3507 if (EQ (attr
, QCbackground
))
3508 param
= Qborder_color
;
3510 else if (EQ (face
, Qcursor
))
3512 /* Changing background color of `cursor' sets frame parameter
3514 if (EQ (attr
, QCbackground
))
3515 param
= Qcursor_color
;
3517 else if (EQ (face
, Qmouse
))
3519 /* Changing background color of `mouse' sets frame parameter
3521 if (EQ (attr
, QCbackground
))
3522 param
= Qmouse_color
;
3525 if (SYMBOLP (param
))
3526 Fmodify_frame_parameters (frame
, Fcons (Fcons (param
, value
), Qnil
));
3529 #endif /* HAVE_X_WINDOWS */
3535 #ifdef HAVE_X_WINDOWS
3537 /* Set the `font' frame parameter of FRAME according to `default' face
3538 attributes LFACE. */
3541 set_font_frame_param (frame
, lface
)
3542 Lisp_Object frame
, lface
;
3544 struct frame
*f
= XFRAME (frame
);
3545 Lisp_Object frame_font
;
3549 /* Get FRAME's font parameter. */
3550 frame_font
= Fassq (Qfont
, f
->param_alist
);
3551 xassert (CONSP (frame_font
) && STRINGP (XCDR (frame_font
)));
3552 frame_font
= XCDR (frame_font
);
3554 fontset
= fs_query_fontset (f
, XSTRING (frame_font
)->data
);
3557 /* Frame parameter is a fontset name. Modify the fontset so
3558 that all its fonts reflect face attributes LFACE. */
3560 struct fontset_info
*fontset_info
;
3562 fontset_info
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
];
3564 for (charset
= 0; charset
< MAX_CHARSET
; ++charset
)
3565 if (fontset_info
->fontname
[charset
])
3567 font
= choose_face_fontset_font (f
, XVECTOR (lface
)->contents
,
3569 Fset_fontset_font (frame_font
, CHARSET_SYMBOL (charset
),
3570 build_string (font
), frame
);
3576 /* Frame parameter is an X font name. I believe this can
3577 only happen in unibyte mode. */
3578 font
= choose_face_font (f
, XVECTOR (lface
)->contents
,
3579 -1, Vface_default_registry
);
3582 store_frame_param (f
, Qfont
, build_string (font
));
3589 /* Update the corresponding face when frame parameter PARAM on frame F
3590 has been assigned the value NEW_VALUE. */
3593 update_face_from_frame_parameter (f
, param
, new_value
)
3595 Lisp_Object param
, new_value
;
3599 /* If there are no faces yet, give up. This is the case when called
3600 from Fx_create_frame, and we do the necessary things later in
3601 face-set-after-frame-defaults. */
3602 if (NILP (f
->face_alist
))
3605 if (EQ (param
, Qforeground_color
))
3607 lface
= lface_from_face_name (f
, Qdefault
, 1);
3608 LFACE_FOREGROUND (lface
) = (STRINGP (new_value
)
3609 ? new_value
: Qunspecified
);
3610 realize_basic_faces (f
);
3612 else if (EQ (param
, Qbackground_color
))
3616 /* Changing the background color might change the background
3617 mode, so that we have to load new defface specs. Call
3618 frame-update-face-colors to do that. */
3619 XSETFRAME (frame
, f
);
3620 call1 (Qframe_update_face_colors
, frame
);
3622 lface
= lface_from_face_name (f
, Qdefault
, 1);
3623 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3624 ? new_value
: Qunspecified
);
3625 realize_basic_faces (f
);
3627 if (EQ (param
, Qborder_color
))
3629 lface
= lface_from_face_name (f
, Qborder
, 1);
3630 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3631 ? new_value
: Qunspecified
);
3633 else if (EQ (param
, Qcursor_color
))
3635 lface
= lface_from_face_name (f
, Qcursor
, 1);
3636 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3637 ? new_value
: Qunspecified
);
3639 else if (EQ (param
, Qmouse_color
))
3641 lface
= lface_from_face_name (f
, Qmouse
, 1);
3642 LFACE_BACKGROUND (lface
) = (STRINGP (new_value
)
3643 ? new_value
: Qunspecified
);
3648 /* Get the value of X resource RESOURCE, class CLASS for the display
3649 of frame FRAME. This is here because ordinary `x-get-resource'
3650 doesn't take a frame argument. */
3652 DEFUN ("internal-face-x-get-resource", Finternal_face_x_get_resource
,
3653 Sinternal_face_x_get_resource
, 3, 3, 0, "")
3654 (resource
, class, frame
)
3655 Lisp_Object resource
, class, frame
;
3658 CHECK_STRING (resource
, 0);
3659 CHECK_STRING (class, 1);
3660 CHECK_LIVE_FRAME (frame
, 2);
3662 value
= display_x_get_resource (FRAME_X_DISPLAY_INFO (XFRAME (frame
)),
3663 resource
, class, Qnil
, Qnil
);
3669 /* Return resource string VALUE as a boolean value, i.e. nil, or t.
3670 If VALUE is "on" or "true", return t. If VALUE is "off" or
3671 "false", return nil. Otherwise, if SIGNAL_P is non-zero, signal an
3672 error; if SIGNAL_P is zero, return 0. */
3675 face_boolean_x_resource_value (value
, signal_p
)
3679 Lisp_Object result
= make_number (0);
3681 xassert (STRINGP (value
));
3683 if (xstricmp (XSTRING (value
)->data
, "on") == 0
3684 || xstricmp (XSTRING (value
)->data
, "true") == 0)
3686 else if (xstricmp (XSTRING (value
)->data
, "off") == 0
3687 || xstricmp (XSTRING (value
)->data
, "false") == 0)
3689 else if (xstricmp (XSTRING (value
)->data
, "unspecified") == 0)
3690 result
= Qunspecified
;
3692 signal_error ("Invalid face attribute value from X resource", value
);
3698 DEFUN ("internal-set-lisp-face-attribute-from-resource",
3699 Finternal_set_lisp_face_attribute_from_resource
,
3700 Sinternal_set_lisp_face_attribute_from_resource
,
3702 (face
, attr
, value
, frame
)
3703 Lisp_Object face
, attr
, value
, frame
;
3705 CHECK_SYMBOL (face
, 0);
3706 CHECK_SYMBOL (attr
, 1);
3707 CHECK_STRING (value
, 2);
3709 if (xstricmp (XSTRING (value
)->data
, "unspecified") == 0)
3710 value
= Qunspecified
;
3711 else if (EQ (attr
, QCheight
))
3713 value
= Fstring_to_number (value
, make_number (10));
3714 if (XINT (value
) <= 0)
3715 signal_error ("Invalid face height from X resource", value
);
3717 else if (EQ (attr
, QCbold
) || EQ (attr
, QCitalic
))
3718 value
= face_boolean_x_resource_value (value
, 1);
3719 else if (EQ (attr
, QCweight
) || EQ (attr
, QCslant
) || EQ (attr
, QCwidth
))
3720 value
= intern (XSTRING (value
)->data
);
3721 else if (EQ (attr
, QCreverse_video
) || EQ (attr
, QCinverse_video
))
3722 value
= face_boolean_x_resource_value (value
, 1);
3723 else if (EQ (attr
, QCunderline
)
3724 || EQ (attr
, QCoverline
)
3725 || EQ (attr
, QCstrike_through
)
3726 || EQ (attr
, QCbox
))
3728 Lisp_Object boolean_value
;
3730 /* If the result of face_boolean_x_resource_value is t or nil,
3731 VALUE does NOT specify a color. */
3732 boolean_value
= face_boolean_x_resource_value (value
, 0);
3733 if (SYMBOLP (boolean_value
))
3734 value
= boolean_value
;
3737 return Finternal_set_lisp_face_attribute (face
, attr
, value
, frame
);
3742 /***********************************************************************
3744 ***********************************************************************/
3746 #ifdef USE_X_TOOLKIT
3748 /* Structure used to pass X resources to functions called via
3749 XtApplyToWidgets. */
3760 static void xm_apply_resources
P_ ((Widget
, XtPointer
));
3761 static void xm_set_menu_resources_from_menu_face
P_ ((struct frame
*, Widget
));
3764 /* Set widget W's X resources from P which points to an x_resources
3765 structure. If W is a cascade button, apply resources to W's
3769 xm_apply_resources (w
, p
)
3774 struct x_resources
*res
= (struct x_resources
*) p
;
3776 XtSetValues (w
, res
->av
, res
->ac
);
3777 XtVaGetValues (w
, XmNsubMenuId
, &submenu
, NULL
);
3780 XtSetValues (submenu
, res
->av
, res
->ac
);
3781 XtApplyToWidgets (submenu
, xm_apply_resources
, p
);
3786 /* Set X resources of menu-widget WIDGET on frame F from face `menu'.
3787 This is the LessTif/Motif version. As of LessTif 0.88 it has the
3790 1. Setting the XmNfontList resource leads to an infinite loop
3791 somewhere in LessTif. */
3794 xm_set_menu_resources_from_menu_face (f
, widget
)
3804 lface
= lface_from_face_name (f
, Qmenu
, 1);
3805 face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
3807 if (!UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
3809 XtSetArg (av
[ac
], XmNforeground
, face
->foreground
);
3813 if (!UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
3815 XtSetArg (av
[ac
], XmNbackground
, face
->background
);
3819 /* If any font-related attribute of `menu' is set, set the font. */
3821 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
3822 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
3823 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3824 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
3825 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
3827 #if 0 /* Setting the font leads to an infinite loop somewhere
3828 in LessTif during geometry computation. */
3830 fe
= XmFontListEntryCreate ("menu_font", XmFONT_IS_FONT
, face
->font
);
3831 fl
= XmFontListAppendEntry (NULL
, fe
);
3832 XtSetArg (av
[ac
], XmNfontList
, fl
);
3837 xassert (ac
<= sizeof av
/ sizeof *av
);
3841 struct x_resources res
;
3843 XtSetValues (widget
, av
, ac
);
3844 res
.av
= av
, res
.ac
= ac
;
3845 XtApplyToWidgets (widget
, xm_apply_resources
, &res
);
3847 XmFontListFree (fl
);
3852 #endif /* USE_MOTIF */
3856 static void xl_apply_resources
P_ ((Widget
, XtPointer
));
3857 static void xl_set_menu_resources_from_menu_face
P_ ((struct frame
*, Widget
));
3860 /* Set widget W's resources from P which points to an x_resources
3864 xl_apply_resources (widget
, p
)
3868 struct x_resources
*res
= (struct x_resources
*) p
;
3869 XtSetValues (widget
, res
->av
, res
->ac
);
3873 /* On frame F, set X resources of menu-widget WIDGET from face `menu'.
3874 This is the Lucid version. */
3877 xl_set_menu_resources_from_menu_face (f
, widget
)
3886 lface
= lface_from_face_name (f
, Qmenu
, 1);
3887 face
= FACE_FROM_ID (f
, MENU_FACE_ID
);
3889 if (!UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
3891 XtSetArg (av
[ac
], XtNforeground
, face
->foreground
);
3895 if (!UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
3897 XtSetArg (av
[ac
], XtNbackground
, face
->background
);
3902 && (!UNSPECIFIEDP (LFACE_FAMILY (lface
))
3903 || !UNSPECIFIEDP (LFACE_SWIDTH (lface
))
3904 || !UNSPECIFIEDP (LFACE_WEIGHT (lface
))
3905 || !UNSPECIFIEDP (LFACE_SLANT (lface
))
3906 || !UNSPECIFIEDP (LFACE_HEIGHT (lface
))))
3908 XtSetArg (av
[ac
], XtNfont
, face
->font
);
3914 struct x_resources res
;
3916 XtSetValues (widget
, av
, ac
);
3918 /* We must do children here in case we're handling a pop-up menu
3919 in which case WIDGET is a popup shell. XtApplyToWidgets
3920 is a function from lwlib. */
3921 res
.av
= av
, res
.ac
= ac
;
3922 XtApplyToWidgets (widget
, xl_apply_resources
, &res
);
3926 #endif /* USE_LUCID */
3929 /* On frame F, set X resources of menu-widget WIDGET from face `menu'. */
3932 x_set_menu_resources_from_menu_face (f
, widget
)
3937 xl_set_menu_resources_from_menu_face (f
, widget
);
3940 xm_set_menu_resources_from_menu_face (f
, widget
);
3944 #endif /* USE_X_TOOLKIT */
3946 #endif /* HAVE_X_WINDOWS */
3950 DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute
,
3951 Sinternal_get_lisp_face_attribute
,
3953 "Return face attribute KEYWORD of face SYMBOL.\n\
3954 If SYMBOL does not name a valid Lisp face or KEYWORD isn't a valid\n\
3955 face attribute name, signal an error.\n\
3956 If the optional argument FRAME is given, report on face FACE in that\n\
3957 frame. If FRAME is t, report on the defaults for face FACE (for new\n\
3958 frames). If FRAME is omitted or nil, use the selected frame.")
3959 (symbol
, keyword
, frame
)
3960 Lisp_Object symbol
, keyword
, frame
;
3962 Lisp_Object lface
, value
= Qnil
;
3964 CHECK_SYMBOL (symbol
, 0);
3965 CHECK_SYMBOL (keyword
, 1);
3968 lface
= lface_from_face_name (NULL
, symbol
, 1);
3972 frame
= selected_frame
;
3973 CHECK_LIVE_FRAME (frame
, 2);
3974 lface
= lface_from_face_name (XFRAME (frame
), symbol
, 1);
3977 if (EQ (keyword
, QCfamily
))
3978 value
= LFACE_FAMILY (lface
);
3979 else if (EQ (keyword
, QCheight
))
3980 value
= LFACE_HEIGHT (lface
);
3981 else if (EQ (keyword
, QCweight
))
3982 value
= LFACE_WEIGHT (lface
);
3983 else if (EQ (keyword
, QCslant
))
3984 value
= LFACE_SLANT (lface
);
3985 else if (EQ (keyword
, QCunderline
))
3986 value
= LFACE_UNDERLINE (lface
);
3987 else if (EQ (keyword
, QCoverline
))
3988 value
= LFACE_OVERLINE (lface
);
3989 else if (EQ (keyword
, QCstrike_through
))
3990 value
= LFACE_STRIKE_THROUGH (lface
);
3991 else if (EQ (keyword
, QCbox
))
3992 value
= LFACE_BOX (lface
);
3993 else if (EQ (keyword
, QCinverse_video
)
3994 || EQ (keyword
, QCreverse_video
))
3995 value
= LFACE_INVERSE (lface
);
3996 else if (EQ (keyword
, QCforeground
))
3997 value
= LFACE_FOREGROUND (lface
);
3998 else if (EQ (keyword
, QCbackground
))
3999 value
= LFACE_BACKGROUND (lface
);
4000 else if (EQ (keyword
, QCstipple
))
4001 value
= LFACE_STIPPLE (lface
);
4002 else if (EQ (keyword
, QCwidth
))
4003 value
= LFACE_SWIDTH (lface
);
4005 signal_error ("Invalid face attribute name", keyword
);
4011 DEFUN ("internal-lisp-face-attribute-values",
4012 Finternal_lisp_face_attribute_values
,
4013 Sinternal_lisp_face_attribute_values
, 1, 1, 0,
4014 "Return a list of valid discrete values for face attribute ATTR.\n\
4015 Value is nil if ATTR doesn't have a discrete set of valid values.")
4019 Lisp_Object result
= Qnil
;
4021 CHECK_SYMBOL (attr
, 0);
4023 if (EQ (attr
, QCweight
)
4024 || EQ (attr
, QCslant
)
4025 || EQ (attr
, QCwidth
))
4027 /* Extract permissible symbols from tables. */
4028 struct table_entry
*table
;
4031 if (EQ (attr
, QCweight
))
4032 table
= weight_table
, dim
= DIM (weight_table
);
4033 else if (EQ (attr
, QCslant
))
4034 table
= slant_table
, dim
= DIM (slant_table
);
4036 table
= swidth_table
, dim
= DIM (swidth_table
);
4038 for (i
= 0; i
< dim
; ++i
)
4040 Lisp_Object symbol
= *table
[i
].symbol
;
4041 Lisp_Object tail
= result
;
4044 && !EQ (XCAR (tail
), symbol
))
4048 result
= Fcons (symbol
, result
);
4051 else if (EQ (attr
, QCunderline
))
4052 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4053 else if (EQ (attr
, QCoverline
))
4054 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4055 else if (EQ (attr
, QCstrike_through
))
4056 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4057 else if (EQ (attr
, QCinverse_video
) || EQ (attr
, QCreverse_video
))
4058 result
= Fcons (Qt
, Fcons (Qnil
, Qnil
));
4064 DEFUN ("internal-merge-in-global-face", Finternal_merge_in_global_face
,
4065 Sinternal_merge_in_global_face
, 2, 2, 0,
4066 "Add attributes from frame-default definition of FACE to FACE on FRAME.")
4068 Lisp_Object face
, frame
;
4070 Lisp_Object global_lface
, local_lface
;
4071 CHECK_LIVE_FRAME (frame
, 1);
4072 global_lface
= lface_from_face_name (NULL
, face
, 1);
4073 local_lface
= lface_from_face_name (XFRAME (frame
), face
, 0);
4074 if (NILP (local_lface
))
4075 local_lface
= Finternal_make_lisp_face (face
, frame
);
4076 merge_face_vectors (XVECTOR (global_lface
)->contents
,
4077 XVECTOR (local_lface
)->contents
);
4082 /* The following function is implemented for compatibility with 20.2.
4083 The function is used in x-resolve-fonts when it is asked to
4084 return fonts with the same size as the font of a face. This is
4085 done in fontset.el. */
4087 DEFUN ("face-font", Fface_font
, Sface_font
, 1, 2, 0,
4088 "Return the font name of face FACE, or nil if it is unspecified.\n\
4089 If the optional argument FRAME is given, report on face FACE in that frame.\n\
4090 If FRAME is t, report on the defaults for face FACE (for new frames).\n\
4091 The font default for a face is either nil, or a list\n\
4092 of the form (bold), (italic) or (bold italic).\n\
4093 If FRAME is omitted or nil, use the selected frame.")
4095 Lisp_Object face
, frame
;
4099 Lisp_Object result
= Qnil
;
4100 Lisp_Object lface
= lface_from_face_name (NULL
, face
, 1);
4102 if (!UNSPECIFIEDP (LFACE_WEIGHT (lface
))
4103 && !EQ (LFACE_WEIGHT (lface
), Qnormal
))
4104 result
= Fcons (Qbold
, result
);
4106 if (!NILP (LFACE_SLANT (lface
))
4107 && !EQ (LFACE_SLANT (lface
), Qnormal
))
4108 result
= Fcons (Qitalic
, result
);
4114 struct frame
*f
= frame_or_selected_frame (frame
, 1);
4115 int face_id
= lookup_named_face (f
, face
, CHARSET_ASCII
);
4116 struct face
*face
= FACE_FROM_ID (f
, face_id
);
4117 return build_string (face
->font_name
);
4122 /* Compare face vectors V1 and V2 for equality. Value is non-zero if
4123 all attributes are `equal'. Tries to be fast because this function
4124 is called quite often. */
4127 lface_equal_p (v1
, v2
)
4128 Lisp_Object
*v1
, *v2
;
4132 for (i
= 1; i
< LFACE_VECTOR_SIZE
&& equal_p
; ++i
)
4134 Lisp_Object a
= v1
[i
];
4135 Lisp_Object b
= v2
[i
];
4137 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
4138 and the other is specified. */
4139 equal_p
= XTYPE (a
) == XTYPE (b
);
4148 equal_p
= (XSTRING (a
)->size
== XSTRING (b
)->size
4149 && bcmp (XSTRING (a
)->data
, XSTRING (b
)->data
,
4150 XSTRING (a
)->size
) == 0);
4159 equal_p
= !NILP (Fequal (a
, b
));
4169 DEFUN ("internal-lisp-face-equal-p", Finternal_lisp_face_equal_p
,
4170 Sinternal_lisp_face_equal_p
, 2, 3, 0,
4171 "True if FACE1 and FACE2 are equal.\n\
4172 If the optional argument FRAME is given, report on face FACE in that frame.\n\
4173 If FRAME is t, report on the defaults for face FACE (for new frames).\n\
4174 If FRAME is omitted or nil, use the selected frame.")
4175 (face1
, face2
, frame
)
4176 Lisp_Object face1
, face2
, frame
;
4180 Lisp_Object lface1
, lface2
;
4185 /* Don't use check_x_frame here because this function is called
4186 before X frames exist. At that time, if FRAME is nil,
4187 selected_frame will be used which is the frame dumped with
4188 Emacs. That frame is not an X frame. */
4189 f
= frame_or_selected_frame (frame
, 2);
4191 lface1
= lface_from_face_name (NULL
, face1
, 1);
4192 lface2
= lface_from_face_name (NULL
, face2
, 1);
4193 equal_p
= lface_equal_p (XVECTOR (lface1
)->contents
,
4194 XVECTOR (lface2
)->contents
);
4195 return equal_p
? Qt
: Qnil
;
4199 DEFUN ("internal-lisp-face-empty-p", Finternal_lisp_face_empty_p
,
4200 Sinternal_lisp_face_empty_p
, 1, 2, 0,
4201 "True if FACE has no attribute specified.\n\
4202 If the optional argument FRAME is given, report on face FACE in that frame.\n\
4203 If FRAME is t, report on the defaults for face FACE (for new frames).\n\
4204 If FRAME is omitted or nil, use the selected frame.")
4206 Lisp_Object face
, frame
;
4213 frame
= selected_frame
;
4214 CHECK_LIVE_FRAME (frame
, 0);
4218 lface
= lface_from_face_name (NULL
, face
, 1);
4220 lface
= lface_from_face_name (f
, face
, 1);
4222 for (i
= 1; i
< LFACE_VECTOR_SIZE
; ++i
)
4223 if (!UNSPECIFIEDP (XVECTOR (lface
)->contents
[i
]))
4226 return i
== LFACE_VECTOR_SIZE
? Qt
: Qnil
;
4230 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
,
4232 "Return an alist of frame-local faces defined on FRAME.\n\
4233 For internal use only.")
4237 struct frame
*f
= frame_or_selected_frame (frame
, 0);
4238 return f
->face_alist
;
4242 /* Return a hash code for Lisp string STRING with case ignored. Used
4243 below in computing a hash value for a Lisp face. */
4245 static INLINE
unsigned
4246 hash_string_case_insensitive (string
)
4251 xassert (STRINGP (string
));
4252 for (s
= XSTRING (string
)->data
; *s
; ++s
)
4253 hash
= (hash
<< 1) ^ tolower (*s
);
4258 /* Return a hash code for face attribute vector V. */
4260 static INLINE
unsigned
4264 return (hash_string_case_insensitive (v
[LFACE_FAMILY_INDEX
])
4265 ^ hash_string_case_insensitive (v
[LFACE_FOREGROUND_INDEX
])
4266 ^ hash_string_case_insensitive (v
[LFACE_BACKGROUND_INDEX
])
4267 ^ (unsigned) v
[LFACE_WEIGHT_INDEX
]
4268 ^ (unsigned) v
[LFACE_SLANT_INDEX
]
4269 ^ (unsigned) v
[LFACE_SWIDTH_INDEX
]
4270 ^ XFASTINT (v
[LFACE_HEIGHT_INDEX
]));
4274 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
4275 considering charsets/registries). They do if they specify the same
4276 family, point size, weight, width and slant. Both LFACE1 and
4277 LFACE2 must be fully-specified. */
4280 lface_same_font_attributes_p (lface1
, lface2
)
4281 Lisp_Object
*lface1
, *lface2
;
4283 xassert (lface_fully_specified_p (lface1
)
4284 && lface_fully_specified_p (lface2
));
4285 return (xstricmp (XSTRING (lface1
[LFACE_FAMILY_INDEX
])->data
,
4286 XSTRING (lface2
[LFACE_FAMILY_INDEX
])->data
) == 0
4287 && (XFASTINT (lface1
[LFACE_HEIGHT_INDEX
])
4288 == XFASTINT (lface2
[LFACE_HEIGHT_INDEX
]))
4289 && EQ (lface1
[LFACE_SWIDTH_INDEX
], lface2
[LFACE_SWIDTH_INDEX
])
4290 && EQ (lface1
[LFACE_WEIGHT_INDEX
], lface2
[LFACE_WEIGHT_INDEX
])
4291 && EQ (lface1
[LFACE_SLANT_INDEX
], lface2
[LFACE_SLANT_INDEX
]));
4296 /***********************************************************************
4298 ***********************************************************************/
4300 /* Allocate and return a new realized face for Lisp face attribute
4301 vector ATTR, charset CHARSET, and registry REGISTRY. */
4303 static struct face
*
4304 make_realized_face (attr
, charset
, registry
)
4307 Lisp_Object registry
;
4309 struct face
*face
= (struct face
*) xmalloc (sizeof *face
);
4310 bzero (face
, sizeof *face
);
4311 face
->charset
= charset
;
4312 face
->registry
= registry
;
4313 bcopy (attr
, face
->lface
, sizeof face
->lface
);
4318 /* Free realized face FACE, including its X resources. FACE may
4322 free_realized_face (f
, face
)
4328 #ifdef HAVE_X_WINDOWS
4333 x_free_gc (f
, face
->gc
);
4337 free_face_colors (f
, face
);
4338 x_destroy_bitmap (f
, face
->stipple
);
4340 #endif /* HAVE_X_WINDOWS */
4347 /* Prepare face FACE for subsequent display on frame F. This
4348 allocated GCs if they haven't been allocated yet or have been freed
4349 by clearing the face cache. */
4352 prepare_face_for_display (f
, face
)
4356 #ifdef HAVE_X_WINDOWS
4357 xassert (FRAME_X_P (f
));
4362 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
4364 xgcv
.foreground
= face
->foreground
;
4365 xgcv
.background
= face
->background
;
4366 xgcv
.graphics_exposures
= False
;
4368 /* The font of FACE may be null if we couldn't load it. */
4371 xgcv
.font
= face
->font
->fid
;
4378 xgcv
.fill_style
= FillOpaqueStippled
;
4379 xgcv
.stipple
= x_bitmap_pixmap (f
, face
->stipple
);
4380 mask
|= GCFillStyle
| GCStipple
;
4383 face
->gc
= x_create_gc (f
, mask
, &xgcv
);
4390 /* Non-zero if FACE is suitable for displaying ISO8859-1. Used in
4391 macro FACE_SUITABLE_FOR_CHARSET_P to avoid realizing a new face for
4392 ISO8859-1 if the ASCII face suffices. */
4395 face_suitable_for_iso8859_1_p (face
)
4398 int len
= strlen (face
->font_name
);
4399 return len
>= 9 && xstricmp (face
->font_name
+ len
- 9, "iso8859-1") == 0;
4403 /* Value is non-zero if FACE is suitable for displaying characters
4404 of CHARSET. CHARSET < 0 means unibyte text. */
4407 face_suitable_for_charset_p (face
, charset
)
4415 if (EQ (face
->registry
, Vface_default_registry
)
4416 || !NILP (Fequal (face
->registry
, Vface_default_registry
)))
4419 else if (face
->charset
== charset
)
4421 else if (face
->charset
== CHARSET_ASCII
4422 && charset
== charset_latin_iso8859_1
)
4423 suitable_p
= face_suitable_for_iso8859_1_p (face
);
4424 else if (face
->charset
== charset_latin_iso8859_1
4425 && charset
== CHARSET_ASCII
)
4433 /***********************************************************************
4435 ***********************************************************************/
4437 /* Return a new face cache for frame F. */
4439 static struct face_cache
*
4443 struct face_cache
*c
;
4446 c
= (struct face_cache
*) xmalloc (sizeof *c
);
4447 bzero (c
, sizeof *c
);
4448 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4449 c
->buckets
= (struct face
**) xmalloc (size
);
4450 bzero (c
->buckets
, size
);
4452 c
->faces_by_id
= (struct face
**) xmalloc (c
->size
* sizeof *c
->faces_by_id
);
4458 /* Clear out all graphics contexts for all realized faces, except for
4459 the basic faces. This should be done from time to time just to avoid
4460 keeping too many graphics contexts that are no longer needed. */
4464 struct face_cache
*c
;
4466 if (c
&& FRAME_X_P (c
->f
))
4468 #ifdef HAVE_X_WINDOWS
4470 for (i
= BASIC_FACE_ID_SENTINEL
; i
< c
->used
; ++i
)
4472 struct face
*face
= c
->faces_by_id
[i
];
4473 if (face
&& face
->gc
)
4475 x_free_gc (c
->f
, face
->gc
);
4479 #endif /* HAVE_X_WINDOWS */
4484 /* Free all realized faces in face cache C, including basic faces. C
4485 may be null. If faces are freed, make sure the frame's current
4486 matrix is marked invalid, so that a display caused by an expose
4487 event doesn't try to use faces we destroyed. */
4490 free_realized_faces (c
)
4491 struct face_cache
*c
;
4496 struct frame
*f
= c
->f
;
4498 for (i
= 0; i
< c
->used
; ++i
)
4500 free_realized_face (f
, c
->faces_by_id
[i
]);
4501 c
->faces_by_id
[i
] = NULL
;
4505 size
= FACE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4506 bzero (c
->buckets
, size
);
4508 /* Must do a thorough redisplay the next time. Mark current
4509 matrices as invalid because they will reference faces freed
4510 above. This function is also called when a frame is
4511 destroyed. In this case, the root window of F is nil. */
4512 if (WINDOWP (f
->root_window
))
4514 clear_current_matrices (f
);
4515 ++windows_or_buffers_changed
;
4521 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
4522 This is done after attributes of a named face have been changed,
4523 because we can't tell which realized faces depend on that face. */
4526 free_all_realized_faces (frame
)
4532 FOR_EACH_FRAME (rest
, frame
)
4533 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4536 free_realized_faces (FRAME_FACE_CACHE (XFRAME (frame
)));
4540 /* Free face cache C and faces in it, including their X resources. */
4544 struct face_cache
*c
;
4548 free_realized_faces (c
);
4550 xfree (c
->faces_by_id
);
4556 /* Cache realized face FACE in face cache C. HASH is the hash value
4557 of FACE. If FACE->fontset >= 0, add the new face to the end of the
4558 collision list of the face hash table of C. This is done because
4559 otherwise lookup_face would find FACE for every charset, even if
4560 faces with the same attributes but for specific charsets exist. */
4563 cache_face (c
, face
, hash
)
4564 struct face_cache
*c
;
4568 int i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4572 if (face
->fontset
>= 0)
4574 struct face
*last
= c
->buckets
[i
];
4585 c
->buckets
[i
] = face
;
4586 face
->prev
= face
->next
= NULL
;
4592 face
->next
= c
->buckets
[i
];
4594 face
->next
->prev
= face
;
4595 c
->buckets
[i
] = face
;
4598 /* Find a free slot in C->faces_by_id and use the index of the free
4599 slot as FACE->id. */
4600 for (i
= 0; i
< c
->used
; ++i
)
4601 if (c
->faces_by_id
[i
] == NULL
)
4605 /* Maybe enlarge C->faces_by_id. */
4606 if (i
== c
->used
&& c
->used
== c
->size
)
4608 int new_size
= 2 * c
->size
;
4609 int sz
= new_size
* sizeof *c
->faces_by_id
;
4610 c
->faces_by_id
= (struct face
**) xrealloc (c
->faces_by_id
, sz
);
4615 /* Check that FACE got a unique id. */
4620 for (j
= n
= 0; j
< FACE_CACHE_BUCKETS_SIZE
; ++j
)
4621 for (face
= c
->buckets
[j
]; face
; face
= face
->next
)
4627 #endif /* GLYPH_DEBUG */
4629 c
->faces_by_id
[i
] = face
;
4635 /* Remove face FACE from cache C. */
4638 uncache_face (c
, face
)
4639 struct face_cache
*c
;
4642 int i
= face
->hash
% FACE_CACHE_BUCKETS_SIZE
;
4645 face
->prev
->next
= face
->next
;
4647 c
->buckets
[i
] = face
->next
;
4650 face
->next
->prev
= face
->prev
;
4652 c
->faces_by_id
[face
->id
] = NULL
;
4653 if (face
->id
== c
->used
)
4658 /* Look up a realized face with face attributes ATTR in the face cache
4659 of frame F. The face will be used to display characters of
4660 CHARSET. CHARSET < 0 means the face will be used to display
4661 unibyte text. The value of face-default-registry is used to choose
4662 a font for the face in that case. Value is the ID of the face
4663 found. If no suitable face is found, realize a new one. */
4666 lookup_face (f
, attr
, charset
)
4671 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
4676 xassert (c
!= NULL
);
4677 check_lface_attrs (attr
);
4679 /* Look up ATTR in the face cache. */
4680 hash
= lface_hash (attr
);
4681 i
= hash
% FACE_CACHE_BUCKETS_SIZE
;
4683 for (face
= c
->buckets
[i
]; face
; face
= face
->next
)
4684 if (face
->hash
== hash
4685 && (!FRAME_WINDOW_P (f
)
4686 || FACE_SUITABLE_FOR_CHARSET_P (face
, charset
))
4687 && lface_equal_p (face
->lface
, attr
))
4690 /* If not found, realize a new face. */
4693 face
= realize_face (c
, attr
, charset
);
4694 cache_face (c
, face
, hash
);
4698 xassert (face
== FACE_FROM_ID (f
, face
->id
));
4700 xassert (charset
< 0 || FACE_SUITABLE_FOR_CHARSET_P (face
, charset
));
4701 #endif /* GLYPH_DEBUG */
4707 /* Return the face id of the realized face for named face SYMBOL on
4708 frame F suitable for displaying characters from CHARSET. CHARSET <
4709 0 means unibyte text. */
4712 lookup_named_face (f
, symbol
, charset
)
4717 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4718 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4719 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
4721 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
4722 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
4723 merge_face_vectors (symbol_attrs
, attrs
);
4724 return lookup_face (f
, attrs
, charset
);
4728 /* Return the ID of the realized ASCII face of Lisp face with ID
4729 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
4732 ascii_face_of_lisp_face (f
, lface_id
)
4738 if (lface_id
>= 0 && lface_id
< lface_id_to_name_size
)
4740 Lisp_Object face_name
= lface_id_to_name
[lface_id
];
4741 face_id
= lookup_named_face (f
, face_name
, CHARSET_ASCII
);
4750 /* Return a face for charset ASCII that is like the face with id
4751 FACE_ID on frame F, but has a font that is STEPS steps smaller.
4752 STEPS < 0 means larger. Value is the id of the face. */
4755 smaller_face (f
, face_id
, steps
)
4759 #ifdef HAVE_X_WINDOWS
4761 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4762 int pt
, last_pt
, last_height
;
4765 struct face
*new_face
;
4767 /* If not called for an X frame, just return the original face. */
4768 if (FRAME_TERMCAP_P (f
))
4771 /* Try in increments of 1/2 pt. */
4772 delta
= steps
< 0 ? 5 : -5;
4773 steps
= abs (steps
);
4775 face
= FACE_FROM_ID (f
, face_id
);
4776 bcopy (face
->lface
, attrs
, sizeof attrs
);
4777 pt
= last_pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
4778 new_face_id
= face_id
;
4779 last_height
= FONT_HEIGHT (face
->font
);
4783 /* Give up if we cannot find a font within 10pt. */
4784 && abs (last_pt
- pt
) < 100)
4786 /* Look up a face for a slightly smaller/larger font. */
4788 attrs
[LFACE_HEIGHT_INDEX
] = make_number (pt
);
4789 new_face_id
= lookup_face (f
, attrs
, CHARSET_ASCII
);
4790 new_face
= FACE_FROM_ID (f
, new_face_id
);
4792 /* If height changes, count that as one step. */
4793 if (FONT_HEIGHT (new_face
->font
) != last_height
)
4796 last_height
= FONT_HEIGHT (new_face
->font
);
4803 #else /* not HAVE_X_WINDOWS */
4807 #endif /* not HAVE_X_WINDOWS */
4811 /* Return a face for charset ASCII that is like the face with id
4812 FACE_ID on frame F, but has height HEIGHT. */
4815 face_with_height (f
, face_id
, height
)
4820 #ifdef HAVE_X_WINDOWS
4822 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4824 if (FRAME_TERMCAP_P (f
)
4828 face
= FACE_FROM_ID (f
, face_id
);
4829 bcopy (face
->lface
, attrs
, sizeof attrs
);
4830 attrs
[LFACE_HEIGHT_INDEX
] = make_number (height
);
4831 face_id
= lookup_face (f
, attrs
, CHARSET_ASCII
);
4832 #endif /* HAVE_X_WINDOWS */
4837 /* Return the face id of the realized face for named face SYMBOL on
4838 frame F suitable for displaying characters from CHARSET (CHARSET <
4839 0 means unibyte text), and use attributes of the face FACE_ID for
4840 attributes that aren't completely specified by SYMBOL. This is
4841 like lookup_named_face, except that the default attributes come
4842 from FACE_ID, not from the default face. FACE_ID is assumed to
4843 be already realized. */
4846 lookup_derived_face (f
, symbol
, charset
, face_id
)
4852 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
4853 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
4854 struct face
*default_face
= FACE_FROM_ID (f
, face_id
);
4859 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
4860 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
4861 merge_face_vectors (symbol_attrs
, attrs
);
4862 return lookup_face (f
, attrs
, charset
);
4867 /***********************************************************************
4869 ***********************************************************************/
4871 DEFUN ("internal-set-font-selection-order",
4872 Finternal_set_font_selection_order
,
4873 Sinternal_set_font_selection_order
, 1, 1, 0,
4874 "Set font selection order for face font selection to ORDER.\n\
4875 ORDER must be a list of length 4 containing the symbols `:width',\n\
4876 `:height', `:weight', and `:slant'. Face attributes appearing\n\
4877 first in ORDER are matched first, e.g. if `:height' appears before\n\
4878 `:weight' in ORDER, font selection first tries to find a font with\n\
4879 a suitable height, and then tries to match the font weight.\n\
4888 CHECK_LIST (order
, 0);
4889 bzero (indices
, sizeof indices
);
4893 CONSP (list
) && i
< DIM (indices
);
4894 list
= XCDR (list
), ++i
)
4896 Lisp_Object attr
= XCAR (list
);
4899 if (EQ (attr
, QCwidth
))
4901 else if (EQ (attr
, QCheight
))
4902 xlfd
= XLFD_POINT_SIZE
;
4903 else if (EQ (attr
, QCweight
))
4905 else if (EQ (attr
, QCslant
))
4910 if (indices
[i
] != 0)
4916 || i
!= DIM (indices
)
4921 signal_error ("Invalid font sort order", order
);
4923 if (bcmp (indices
, font_sort_order
, sizeof indices
) != 0)
4925 bcopy (indices
, font_sort_order
, sizeof font_sort_order
);
4926 free_all_realized_faces (Qnil
);
4933 DEFUN ("internal-set-alternative-font-family-alist",
4934 Finternal_set_alternative_font_family_alist
,
4935 Sinternal_set_alternative_font_family_alist
, 1, 1, 0,
4936 "Define alternative font families to try in face font selection.\n\
4937 ALIST is an alist of (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...) entries.\n\
4938 Each ALTERNATIVE is tried in order if no fonts of font family FAMILY can\n\
4939 be found. Value is ALIST.")
4943 CHECK_LIST (alist
, 0);
4944 Vface_alternative_font_family_alist
= alist
;
4945 free_all_realized_faces (Qnil
);
4950 #ifdef HAVE_X_WINDOWS
4952 /* Return the X registry and encoding of font name FONT_NAME on frame F.
4953 Value is nil if not successful. */
4956 deduce_unibyte_registry (f
, font_name
)
4960 struct font_name font
;
4961 Lisp_Object registry
= Qnil
;
4963 font
.name
= STRDUPA (font_name
);
4964 if (split_font_name (f
, &font
, 0))
4968 /* Extract registry and encoding. */
4969 buffer
= (char *) alloca (strlen (font
.fields
[XLFD_REGISTRY
])
4970 + strlen (font
.fields
[XLFD_ENCODING
])
4972 strcpy (buffer
, font
.fields
[XLFD_REGISTRY
]);
4973 strcat (buffer
, "-");
4974 strcat (buffer
, font
.fields
[XLFD_ENCODING
]);
4975 registry
= build_string (buffer
);
4982 /* Value is non-zero if FONT is the name of a scalable font. The
4983 X11R6 XLFD spec says that point size, pixel size, and average width
4984 are zero for scalable fonts. Intlfonts contain at least one
4985 scalable font ("*-muleindian-1") for which this isn't true, so we
4986 just test average width. */
4989 font_scalable_p (font
)
4990 struct font_name
*font
;
4992 char *s
= font
->fields
[XLFD_AVGWIDTH
];
4993 return *s
== '0' && *(s
+ 1) == '\0';
4997 /* Value is non-zero if FONT1 is a better match for font attributes
4998 VALUES than FONT2. VALUES is an array of face attribute values in
4999 font sort order. COMPARE_PT_P zero means don't compare point
5003 better_font_p (values
, font1
, font2
, compare_pt_p
)
5005 struct font_name
*font1
, *font2
;
5010 for (i
= 0; i
< 4; ++i
)
5012 int xlfd_idx
= font_sort_order
[i
];
5014 if (compare_pt_p
|| xlfd_idx
!= XLFD_POINT_SIZE
)
5016 int delta1
= abs (values
[i
] - font1
->numeric
[xlfd_idx
]);
5017 int delta2
= abs (values
[i
] - font2
->numeric
[xlfd_idx
]);
5019 if (delta1
> delta2
)
5021 else if (delta1
< delta2
)
5025 /* The difference may be equal because, e.g., the face
5026 specifies `italic' but we have only `regular' and
5027 `oblique'. Prefer `oblique' in this case. */
5028 if ((xlfd_idx
== XLFD_WEIGHT
|| xlfd_idx
== XLFD_SLANT
)
5029 && font1
->numeric
[xlfd_idx
] > values
[i
]
5030 && font2
->numeric
[xlfd_idx
] < values
[i
])
5042 /* Value is non-zero if FONT is an exact match for face attributes in
5043 SPECIFIED. SPECIFIED is an array of face attribute values in font
5047 exact_face_match_p (specified
, font
)
5049 struct font_name
*font
;
5053 for (i
= 0; i
< 4; ++i
)
5054 if (specified
[i
] != font
->numeric
[font_sort_order
[i
]])
5061 /* Value is the name of a scaled font, generated from scalable font
5062 FONT on frame F. SPECIFIED_PT is the point-size to scale FONT to.
5063 Value is allocated from heap. */
5066 build_scalable_font_name (f
, font
, specified_pt
)
5068 struct font_name
*font
;
5071 char point_size
[20], pixel_size
[20];
5073 double resy
= FRAME_X_DISPLAY_INFO (f
)->resy
;
5076 /* If scalable font is for a specific resolution, compute
5077 the point size we must specify from the resolution of
5078 the display and the specified resolution of the font. */
5079 if (font
->numeric
[XLFD_RESY
] != 0)
5081 pt
= resy
/ font
->numeric
[XLFD_RESY
] * specified_pt
+ 0.5;
5082 pixel_value
= font
->numeric
[XLFD_RESY
] / 720.0 * pt
;
5087 pixel_value
= resy
/ 720.0 * pt
;
5090 /* Set point size of the font. */
5091 sprintf (point_size
, "%d", (int) pt
);
5092 font
->fields
[XLFD_POINT_SIZE
] = point_size
;
5093 font
->numeric
[XLFD_POINT_SIZE
] = pt
;
5095 /* Set pixel size. */
5096 sprintf (pixel_size
, "%d", pixel_value
);
5097 font
->fields
[XLFD_PIXEL_SIZE
] = pixel_size
;
5098 font
->numeric
[XLFD_PIXEL_SIZE
] = pixel_value
;
5100 /* If font doesn't specify its resolution, use the
5101 resolution of the display. */
5102 if (font
->numeric
[XLFD_RESY
] == 0)
5105 sprintf (buffer
, "%d", (int) resy
);
5106 font
->fields
[XLFD_RESY
] = buffer
;
5107 font
->numeric
[XLFD_RESY
] = resy
;
5110 if (strcmp (font
->fields
[XLFD_RESX
], "0") == 0)
5113 int resx
= FRAME_X_DISPLAY_INFO (f
)->resx
;
5114 sprintf (buffer
, "%d", resx
);
5115 font
->fields
[XLFD_RESX
] = buffer
;
5116 font
->numeric
[XLFD_RESX
] = resx
;
5119 return build_font_name (font
);
5123 /* Value is non-zero if we are allowed to use scalable font FONT. We
5124 can't run a Lisp function here since this function may be called
5125 with input blocked. */
5128 may_use_scalable_font_p (font
, name
)
5129 struct font_name
*font
;
5132 if (EQ (Vscalable_fonts_allowed
, Qt
))
5134 else if (CONSP (Vscalable_fonts_allowed
))
5136 Lisp_Object tail
, regexp
;
5138 for (tail
= Vscalable_fonts_allowed
; CONSP (tail
); tail
= XCDR (tail
))
5140 regexp
= XCAR (tail
);
5141 if (STRINGP (regexp
)
5142 && fast_c_string_match_ignore_case (regexp
, name
) >= 0)
5150 #endif /* SCALABLE_FONTS != 0 */
5153 /* Return the name of the best matching font for face attributes
5154 ATTRS in the array of font_name structures FONTS which contains
5155 NFONTS elements. Value is a font name which is allocated from
5156 the heap. FONTS is freed by this function. */
5159 best_matching_font (f
, attrs
, fonts
, nfonts
)
5162 struct font_name
*fonts
;
5166 struct font_name
*best
;
5174 /* Make specified font attributes available in `specified',
5175 indexed by sort order. */
5176 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
5178 int xlfd_idx
= font_sort_order
[i
];
5180 if (xlfd_idx
== XLFD_SWIDTH
)
5181 specified
[i
] = face_numeric_swidth (attrs
[LFACE_SWIDTH_INDEX
]);
5182 else if (xlfd_idx
== XLFD_POINT_SIZE
)
5183 specified
[i
] = pt
= XFASTINT (attrs
[LFACE_HEIGHT_INDEX
]);
5184 else if (xlfd_idx
== XLFD_WEIGHT
)
5185 specified
[i
] = face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
5186 else if (xlfd_idx
== XLFD_SLANT
)
5187 specified
[i
] = face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
5197 /* Start with the first non-scalable font in the list. */
5198 for (i
= 0; i
< nfonts
; ++i
)
5199 if (!font_scalable_p (fonts
+ i
))
5202 /* Find the best match among the non-scalable fonts. */
5207 for (i
= 1; i
< nfonts
; ++i
)
5208 if (!font_scalable_p (fonts
+ i
)
5209 && better_font_p (specified
, fonts
+ i
, best
, 1))
5213 exact_p
= exact_face_match_p (specified
, best
);
5222 /* Unless we found an exact match among non-scalable fonts, see if
5223 we can find a better match among scalable fonts. */
5226 /* A scalable font is better if
5228 1. its weight, slant, swidth attributes are better, or.
5230 2. the best non-scalable font doesn't have the required
5231 point size, and the scalable fonts weight, slant, swidth
5234 int non_scalable_has_exact_height_p
;
5236 if (best
&& best
->numeric
[XLFD_POINT_SIZE
] == pt
)
5237 non_scalable_has_exact_height_p
= 1;
5239 non_scalable_has_exact_height_p
= 0;
5241 for (i
= 0; i
< nfonts
; ++i
)
5242 if (font_scalable_p (fonts
+ i
))
5245 || better_font_p (specified
, fonts
+ i
, best
, 0)
5246 || (!non_scalable_has_exact_height_p
5247 && !better_font_p (specified
, best
, fonts
+ i
, 0)))
5252 if (font_scalable_p (best
))
5253 font_name
= build_scalable_font_name (f
, best
, pt
);
5255 font_name
= build_font_name (best
);
5257 #else /* !SCALABLE_FONTS */
5259 /* Find the best non-scalable font. */
5262 for (i
= 1; i
< nfonts
; ++i
)
5264 xassert (!font_scalable_p (fonts
+ i
));
5265 if (better_font_p (specified
, fonts
+ i
, best
, 1))
5269 font_name
= build_font_name (best
);
5271 #endif /* !SCALABLE_FONTS */
5273 /* Free font_name structures. */
5274 free_font_names (fonts
, nfonts
);
5280 /* Try to get a list of fonts on frame F with font family FAMILY and
5281 registry/encoding REGISTRY. Return in *FONTS a pointer to a vector
5282 of font_name structures for the fonts matched. Value is the number
5286 try_font_list (f
, attrs
, pattern
, family
, registry
, fonts
)
5289 char *pattern
, *family
, *registry
;
5290 struct font_name
**fonts
;
5295 family
= LSTRDUPA (attrs
[LFACE_FAMILY_INDEX
]);
5297 nfonts
= font_list (f
, pattern
, family
, registry
, fonts
);
5303 /* Try alternative font families from
5304 Vface_alternative_font_family_alist. */
5305 alter
= Fassoc (build_string (family
),
5306 Vface_alternative_font_family_alist
);
5308 for (alter
= XCDR (alter
);
5309 CONSP (alter
) && nfonts
== 0;
5310 alter
= XCDR (alter
))
5312 if (STRINGP (XCAR (alter
)))
5314 family
= LSTRDUPA (XCAR (alter
));
5315 nfonts
= font_list (f
, NULL
, family
, registry
, fonts
);
5319 /* Try font family of the default face or "fixed". */
5322 struct face
*dflt
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5324 family
= LSTRDUPA (dflt
->lface
[LFACE_FAMILY_INDEX
]);
5327 nfonts
= font_list (f
, NULL
, family
, registry
, fonts
);
5330 /* Try any family with the given registry. */
5332 nfonts
= font_list (f
, NULL
, "*", registry
, fonts
);
5339 /* Return the registry and encoding pattern that fonts for CHARSET
5340 should match. Value is allocated from the heap. */
5343 x_charset_registry (charset
)
5346 Lisp_Object prop
, charset_plist
;
5349 /* Get registry and encoding from the charset's plist. */
5350 charset_plist
= CHARSET_TABLE_INFO (charset
, CHARSET_PLIST_IDX
);
5351 prop
= Fplist_get (charset_plist
, Qx_charset_registry
);
5355 if (index (XSTRING (prop
)->data
, '-'))
5356 registry
= xstrdup (XSTRING (prop
)->data
);
5359 /* If registry doesn't contain a `-', make it a pattern. */
5360 registry
= (char *) xmalloc (STRING_BYTES (XSTRING (prop
)) + 5);
5361 strcpy (registry
, XSTRING (prop
)->data
);
5362 strcat (registry
, "*-*");
5365 else if (STRINGP (Vface_default_registry
))
5366 registry
= xstrdup (XSTRING (Vface_default_registry
)->data
);
5368 registry
= xstrdup ("iso8859-1");
5374 /* Return the fontset id of the fontset name or alias name given by
5375 the family attribute of ATTRS on frame F. Value is -1 if the
5376 family attribute of ATTRS doesn't name a fontset. */
5379 face_fontset (f
, attrs
)
5383 Lisp_Object name
= attrs
[LFACE_FAMILY_INDEX
];
5386 name
= Fquery_fontset (name
, Qnil
);
5390 fontset
= fs_query_fontset (f
, XSTRING (name
)->data
);
5396 /* Get the font to use for the face realizing the fully-specified Lisp
5397 face ATTRS for charset CHARSET on frame F. CHARSET < 0 means
5398 unibyte text; UNIBYTE_REGISTRY is the registry and encoding to use
5399 in this case. Value is the font name which is allocated from the
5400 heap (which means that it must be freed eventually). */
5403 choose_face_font (f
, attrs
, charset
, unibyte_registry
)
5407 Lisp_Object unibyte_registry
;
5409 struct font_name
*fonts
;
5413 /* ATTRS must be fully-specified. */
5414 xassert (lface_fully_specified_p (attrs
));
5416 if (STRINGP (unibyte_registry
))
5417 registry
= xstrdup (XSTRING (unibyte_registry
)->data
);
5419 registry
= x_charset_registry (charset
);
5421 nfonts
= try_font_list (f
, attrs
, NULL
, NULL
, registry
, &fonts
);
5423 return best_matching_font (f
, attrs
, fonts
, nfonts
);
5427 /* Choose a font to use on frame F to display CHARSET using FONTSET
5428 with Lisp face attributes specified by ATTRS. CHARSET may be any
5429 valid charset except CHARSET_COMPOSITION. CHARSET < 0 means
5430 unibyte text. If the fontset doesn't contain a font pattern for
5431 charset, use the pattern for CHARSET_ASCII. Value is the font name
5432 which is allocated from the heap and must be freed by the caller. */
5435 choose_face_fontset_font (f
, attrs
, fontset
, charset
)
5438 int fontset
, charset
;
5441 char *font_name
= NULL
;
5442 struct fontset_info
*fontset_info
;
5443 struct font_name
*fonts
;
5446 xassert (charset
!= CHARSET_COMPOSITION
);
5447 xassert (fontset
>= 0 && fontset
< FRAME_FONTSET_DATA (f
)->n_fontsets
);
5449 /* For unibyte text, use the ASCII font of the fontset. Using the
5450 ASCII font seems to be the most reasonable thing we can do in
5453 charset
= CHARSET_ASCII
;
5455 /* Get the font name pattern to use for CHARSET from the fontset. */
5456 fontset_info
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
];
5457 pattern
= fontset_info
->fontname
[charset
];
5459 pattern
= fontset_info
->fontname
[CHARSET_ASCII
];
5462 /* Get a list of fonts matching that pattern and choose the
5463 best match for the specified face attributes from it. */
5464 nfonts
= try_font_list (f
, attrs
, pattern
, NULL
, NULL
, &fonts
);
5465 font_name
= best_matching_font (f
, attrs
, fonts
, nfonts
);
5469 #endif /* HAVE_X_WINDOWS */
5473 /***********************************************************************
5475 ***********************************************************************/
5477 /* Realize basic faces on frame F. Value is zero if frame parameters
5478 of F don't contain enough information needed to realize the default
5482 realize_basic_faces (f
)
5487 if (realize_default_face (f
))
5489 realize_named_face (f
, Qmode_line
, MODE_LINE_FACE_ID
);
5490 realize_named_face (f
, Qtool_bar
, TOOL_BAR_FACE_ID
);
5491 realize_named_face (f
, Qfringe
, BITMAP_AREA_FACE_ID
);
5492 realize_named_face (f
, Qheader_line
, HEADER_LINE_FACE_ID
);
5493 realize_named_face (f
, Qscroll_bar
, SCROLL_BAR_FACE_ID
);
5494 realize_named_face (f
, Qborder
, BORDER_FACE_ID
);
5495 realize_named_face (f
, Qcursor
, CURSOR_FACE_ID
);
5496 realize_named_face (f
, Qmouse
, MOUSE_FACE_ID
);
5497 realize_named_face (f
, Qmenu
, MENU_FACE_ID
);
5505 /* Realize the default face on frame F. If the face is not fully
5506 specified, make it fully-specified. Attributes of the default face
5507 that are not explicitly specified are taken from frame parameters. */
5510 realize_default_face (f
)
5513 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5515 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5516 Lisp_Object unibyte_registry
;
5517 Lisp_Object frame_font
;
5521 /* If the `default' face is not yet known, create it. */
5522 lface
= lface_from_face_name (f
, Qdefault
, 0);
5526 XSETFRAME (frame
, f
);
5527 lface
= Finternal_make_lisp_face (Qdefault
, frame
);
5530 #ifdef HAVE_X_WINDOWS
5533 /* Set frame_font to the value of the `font' frame parameter. */
5534 frame_font
= Fassq (Qfont
, f
->param_alist
);
5535 xassert (CONSP (frame_font
) && STRINGP (XCDR (frame_font
)));
5536 frame_font
= XCDR (frame_font
);
5538 fontset
= fs_query_fontset (f
, XSTRING (frame_font
)->data
);
5541 /* If frame_font is a fontset name, don't use that for
5542 determining font-related attributes of the default face
5543 because it is just an artificial name. Use the ASCII font of
5544 the fontset, instead. */
5545 struct font_info
*font_info
;
5546 struct font_name font
;
5549 font_info
= FS_LOAD_FONT (f
, FRAME_X_FONT_TABLE (f
), CHARSET_ASCII
,
5553 /* Set weight etc. from the ASCII font. */
5554 if (!set_lface_from_font_name (f
, lface
, font_info
->full_name
, 0, 0))
5557 /* Remember registry and encoding of the frame font. */
5558 unibyte_registry
= deduce_unibyte_registry (f
, font_info
->full_name
);
5559 if (STRINGP (unibyte_registry
))
5560 Vface_default_registry
= unibyte_registry
;
5562 Vface_default_registry
= build_string ("iso8859-1");
5564 /* But set the family to the fontset alias name. Implementation
5565 note: When a font is passed to Emacs via `-fn FONT', a
5566 fontset is created in `x-win.el' whose name ends in
5567 `fontset-startup'. This fontset has an alias name that is
5568 equal to frame_font. */
5569 xassert (STRINGP (frame_font
));
5570 font
.name
= LSTRDUPA (frame_font
);
5572 if (!split_font_name (f
, &font
, 1)
5573 || xstricmp (font
.fields
[XLFD_REGISTRY
], "fontset") != 0
5574 || xstricmp (font
.fields
[XLFD_ENCODING
], "startup") != 0)
5575 LFACE_FAMILY (lface
) = frame_font
;
5579 /* Frame parameters contain a real font. Fill default face
5580 attributes from that font. */
5581 if (!set_lface_from_font_name (f
, lface
,
5582 XSTRING (frame_font
)->data
, 0, 0))
5585 /* Remember registry and encoding of the frame font. */
5587 = deduce_unibyte_registry (f
, XSTRING (frame_font
)->data
);
5588 if (STRINGP (unibyte_registry
))
5589 Vface_default_registry
= unibyte_registry
;
5591 Vface_default_registry
= build_string ("iso8859-1");
5594 #endif /* HAVE_X_WINDOWS */
5596 if (!FRAME_WINDOW_P (f
))
5598 LFACE_FAMILY (lface
) = build_string ("default");
5599 LFACE_SWIDTH (lface
) = Qnormal
;
5600 LFACE_HEIGHT (lface
) = make_number (1);
5601 LFACE_WEIGHT (lface
) = Qnormal
;
5602 LFACE_SLANT (lface
) = Qnormal
;
5605 if (UNSPECIFIEDP (LFACE_UNDERLINE (lface
)))
5606 LFACE_UNDERLINE (lface
) = Qnil
;
5608 if (UNSPECIFIEDP (LFACE_OVERLINE (lface
)))
5609 LFACE_OVERLINE (lface
) = Qnil
;
5611 if (UNSPECIFIEDP (LFACE_STRIKE_THROUGH (lface
)))
5612 LFACE_STRIKE_THROUGH (lface
) = Qnil
;
5614 if (UNSPECIFIEDP (LFACE_BOX (lface
)))
5615 LFACE_BOX (lface
) = Qnil
;
5617 if (UNSPECIFIEDP (LFACE_INVERSE (lface
)))
5618 LFACE_INVERSE (lface
) = Qnil
;
5620 if (UNSPECIFIEDP (LFACE_FOREGROUND (lface
)))
5622 /* This function is called so early that colors are not yet
5623 set in the frame parameter list. */
5624 Lisp_Object color
= Fassq (Qforeground_color
, f
->param_alist
);
5626 if (CONSP (color
) && STRINGP (XCDR (color
)))
5627 LFACE_FOREGROUND (lface
) = XCDR (color
);
5628 else if (FRAME_X_P (f
))
5630 else if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5631 /* Frame parameters for terminal frames usually don't contain
5632 a color. Use an empty string to indicate that the face
5633 should use the (unknown) default color of the terminal. */
5634 LFACE_FOREGROUND (lface
) = build_string ("");
5639 if (UNSPECIFIEDP (LFACE_BACKGROUND (lface
)))
5641 /* This function is called so early that colors are not yet
5642 set in the frame parameter list. */
5643 Lisp_Object color
= Fassq (Qbackground_color
, f
->param_alist
);
5644 if (CONSP (color
) && STRINGP (XCDR (color
)))
5645 LFACE_BACKGROUND (lface
) = XCDR (color
);
5646 else if (FRAME_X_P (f
))
5648 else if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
5649 /* Frame parameters for terminal frames usually don't contain
5650 a color. Use an empty string to indicate that the face
5651 should use the (unknown) default color of the terminal. */
5652 LFACE_BACKGROUND (lface
) = build_string ("");
5657 if (UNSPECIFIEDP (LFACE_STIPPLE (lface
)))
5658 LFACE_STIPPLE (lface
) = Qnil
;
5660 /* Realize the face; it must be fully-specified now. */
5661 xassert (lface_fully_specified_p (XVECTOR (lface
)->contents
));
5662 check_lface (lface
);
5663 bcopy (XVECTOR (lface
)->contents
, attrs
, sizeof attrs
);
5664 face
= realize_face (c
, attrs
, CHARSET_ASCII
);
5666 /* Remove the former default face. */
5667 if (c
->used
> DEFAULT_FACE_ID
)
5669 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5670 uncache_face (c
, default_face
);
5671 free_realized_face (f
, default_face
);
5674 /* Insert the new default face. */
5675 cache_face (c
, face
, lface_hash (attrs
));
5676 xassert (face
->id
== DEFAULT_FACE_ID
);
5681 /* Realize basic faces other than the default face in face cache C.
5682 SYMBOL is the face name, ID is the face id the realized face must
5683 have. The default face must have been realized already. */
5686 realize_named_face (f
, symbol
, id
)
5691 struct face_cache
*c
= FRAME_FACE_CACHE (f
);
5692 Lisp_Object lface
= lface_from_face_name (f
, symbol
, 0);
5693 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
5694 Lisp_Object symbol_attrs
[LFACE_VECTOR_SIZE
];
5695 struct face
*new_face
;
5697 /* The default face must exist and be fully specified. */
5698 get_lface_attributes (f
, Qdefault
, attrs
, 1);
5699 check_lface_attrs (attrs
);
5700 xassert (lface_fully_specified_p (attrs
));
5702 /* If SYMBOL isn't know as a face, create it. */
5706 XSETFRAME (frame
, f
);
5707 lface
= Finternal_make_lisp_face (symbol
, frame
);
5710 /* Merge SYMBOL's face with the default face. */
5711 get_lface_attributes (f
, symbol
, symbol_attrs
, 1);
5712 merge_face_vectors (symbol_attrs
, attrs
);
5714 /* Realize the face. */
5715 new_face
= realize_face (c
, attrs
, CHARSET_ASCII
);
5717 /* Remove the former face. */
5720 struct face
*old_face
= c
->faces_by_id
[id
];
5721 uncache_face (c
, old_face
);
5722 free_realized_face (f
, old_face
);
5725 /* Insert the new face. */
5726 cache_face (c
, new_face
, lface_hash (attrs
));
5727 xassert (new_face
->id
== id
);
5731 /* Realize the fully-specified face with attributes ATTRS in face
5732 cache C for character set CHARSET or for unibyte text if CHARSET <
5733 0. Value is a pointer to the newly created realized face. */
5735 static struct face
*
5736 realize_face (c
, attrs
, charset
)
5737 struct face_cache
*c
;
5743 /* LFACE must be fully specified. */
5744 xassert (c
!= NULL
);
5745 check_lface_attrs (attrs
);
5747 if (FRAME_X_P (c
->f
))
5748 face
= realize_x_face (c
, attrs
, charset
);
5749 else if (FRAME_TERMCAP_P (c
->f
) || FRAME_MSDOS_P (c
->f
))
5750 face
= realize_tty_face (c
, attrs
, charset
);
5758 /* Realize the fully-specified face with attributes ATTRS in face
5759 cache C for character set CHARSET or for unibyte text if CHARSET <
5760 0. Do it for X frame C->f. Value is a pointer to the newly
5761 created realized face. */
5763 static struct face
*
5764 realize_x_face (c
, attrs
, charset
)
5765 struct face_cache
*c
;
5769 #ifdef HAVE_X_WINDOWS
5770 struct face
*face
, *default_face
;
5771 struct frame
*f
= c
->f
;
5772 Lisp_Object stipple
, overline
, strike_through
, box
;
5773 Lisp_Object unibyte_registry
;
5774 struct gcpro gcpro1
;
5776 xassert (FRAME_X_P (f
));
5778 /* If realizing a face for use in unibyte text, get the X registry
5779 and encoding to use from Vface_default_registry. */
5781 unibyte_registry
= (STRINGP (Vface_default_registry
)
5782 ? Vface_default_registry
5783 : build_string ("iso8859-1"));
5785 unibyte_registry
= Qnil
;
5786 GCPRO1 (unibyte_registry
);
5788 /* Allocate a new realized face. */
5789 face
= make_realized_face (attrs
, charset
, unibyte_registry
);
5791 /* Determine the font to use. Most of the time, the font will be
5792 the same as the font of the default face, so try that first. */
5793 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
5795 && FACE_SUITABLE_FOR_CHARSET_P (default_face
, charset
)
5796 && lface_same_font_attributes_p (default_face
->lface
, attrs
))
5798 face
->font
= default_face
->font
;
5799 face
->fontset
= default_face
->fontset
;
5800 face
->font_info_id
= default_face
->font_info_id
;
5801 face
->font_name
= default_face
->font_name
;
5802 face
->registry
= default_face
->registry
;
5804 else if (charset
>= 0)
5806 /* For all charsets except CHARSET_COMPOSITION, we use our own
5807 font selection functions to choose a best matching font for
5808 the specified face attributes. If the face specifies a
5809 fontset alias name, the fontset determines the font name
5810 pattern, otherwise we construct a font pattern from face
5811 attributes and charset.
5813 If charset is CHARSET_COMPOSITION, we always construct a face
5814 with a fontset, even if the face doesn't specify a fontset alias
5815 (we use fontset-standard in that case). When the composite
5816 character is displayed in xterm.c, a suitable concrete font is
5817 loaded in x_get_char_font_and_encoding. */
5819 char *font_name
= NULL
;
5820 int fontset
= face_fontset (f
, attrs
);
5822 if (charset
== CHARSET_COMPOSITION
)
5823 fontset
= max (0, fontset
);
5824 else if (fontset
< 0)
5825 font_name
= choose_face_font (f
, attrs
, charset
, Qnil
);
5828 font_name
= choose_face_fontset_font (f
, attrs
, fontset
, charset
);
5832 load_face_font_or_fontset (f
, face
, font_name
, fontset
);
5837 /* Unibyte case, and font is not equal to that of the default
5838 face. UNIBYTE_REGISTRY is the X registry and encoding the
5839 font should have. What is a reasonable thing to do if the
5840 user specified a fontset alias name for the face in this
5841 case? We choose a font by taking the ASCII font of the
5842 fontset, but using UNIBYTE_REGISTRY for its registry and
5845 char *font_name
= NULL
;
5846 int fontset
= face_fontset (f
, attrs
);
5849 font_name
= choose_face_font (f
, attrs
, charset
, unibyte_registry
);
5851 font_name
= choose_face_fontset_font (f
, attrs
, fontset
, charset
);
5853 load_face_font_or_fontset (f
, face
, font_name
, -1);
5857 /* Load colors, and set remaining attributes. */
5859 load_face_colors (f
, face
, attrs
);
5862 box
= attrs
[LFACE_BOX_INDEX
];
5865 /* A simple box of line width 1 drawn in color given by
5867 face
->box_color
= load_color (f
, face
, attrs
[LFACE_BOX_INDEX
],
5869 face
->box
= FACE_SIMPLE_BOX
;
5870 face
->box_line_width
= 1;
5872 else if (INTEGERP (box
))
5874 /* Simple box of specified line width in foreground color of the
5876 xassert (XINT (box
) > 0);
5877 face
->box
= FACE_SIMPLE_BOX
;
5878 face
->box_line_width
= XFASTINT (box
);
5879 face
->box_color
= face
->foreground
;
5880 face
->box_color_defaulted_p
= 1;
5882 else if (CONSP (box
))
5884 /* `(:width WIDTH :color COLOR :shadow SHADOW)'. SHADOW
5885 being one of `raised' or `sunken'. */
5886 face
->box
= FACE_SIMPLE_BOX
;
5887 face
->box_color
= face
->foreground
;
5888 face
->box_color_defaulted_p
= 1;
5889 face
->box_line_width
= 1;
5893 Lisp_Object keyword
, value
;
5895 keyword
= XCAR (box
);
5903 if (EQ (keyword
, QCline_width
))
5905 if (INTEGERP (value
) && XINT (value
) > 0)
5906 face
->box_line_width
= XFASTINT (value
);
5908 else if (EQ (keyword
, QCcolor
))
5910 if (STRINGP (value
))
5912 face
->box_color
= load_color (f
, face
, value
,
5914 face
->use_box_color_for_shadows_p
= 1;
5917 else if (EQ (keyword
, QCstyle
))
5919 if (EQ (value
, Qreleased_button
))
5920 face
->box
= FACE_RAISED_BOX
;
5921 else if (EQ (value
, Qpressed_button
))
5922 face
->box
= FACE_SUNKEN_BOX
;
5927 /* Text underline, overline, strike-through. */
5929 if (EQ (attrs
[LFACE_UNDERLINE_INDEX
], Qt
))
5931 /* Use default color (same as foreground color). */
5932 face
->underline_p
= 1;
5933 face
->underline_defaulted_p
= 1;
5934 face
->underline_color
= 0;
5936 else if (STRINGP (attrs
[LFACE_UNDERLINE_INDEX
]))
5938 /* Use specified color. */
5939 face
->underline_p
= 1;
5940 face
->underline_defaulted_p
= 0;
5941 face
->underline_color
5942 = load_color (f
, face
, attrs
[LFACE_UNDERLINE_INDEX
],
5943 LFACE_UNDERLINE_INDEX
);
5945 else if (NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
5947 face
->underline_p
= 0;
5948 face
->underline_defaulted_p
= 0;
5949 face
->underline_color
= 0;
5952 overline
= attrs
[LFACE_OVERLINE_INDEX
];
5953 if (STRINGP (overline
))
5955 face
->overline_color
5956 = load_color (f
, face
, attrs
[LFACE_OVERLINE_INDEX
],
5957 LFACE_OVERLINE_INDEX
);
5958 face
->overline_p
= 1;
5960 else if (EQ (overline
, Qt
))
5962 face
->overline_color
= face
->foreground
;
5963 face
->overline_color_defaulted_p
= 1;
5964 face
->overline_p
= 1;
5967 strike_through
= attrs
[LFACE_STRIKE_THROUGH_INDEX
];
5968 if (STRINGP (strike_through
))
5970 face
->strike_through_color
5971 = load_color (f
, face
, attrs
[LFACE_STRIKE_THROUGH_INDEX
],
5972 LFACE_STRIKE_THROUGH_INDEX
);
5973 face
->strike_through_p
= 1;
5975 else if (EQ (strike_through
, Qt
))
5977 face
->strike_through_color
= face
->foreground
;
5978 face
->strike_through_color_defaulted_p
= 1;
5979 face
->strike_through_p
= 1;
5982 stipple
= attrs
[LFACE_STIPPLE_INDEX
];
5983 if (!NILP (stipple
))
5984 face
->stipple
= load_pixmap (f
, stipple
, &face
->pixmap_w
, &face
->pixmap_h
);
5987 xassert (face
->fontset
< 0 || face
->charset
== CHARSET_COMPOSITION
);
5988 xassert (FACE_SUITABLE_FOR_CHARSET_P (face
, charset
));
5990 #endif /* HAVE_X_WINDOWS */
5994 /* Realize the fully-specified face with attributes ATTRS in face
5995 cache C for character set CHARSET or for unibyte text if CHARSET <
5996 0. Do it for TTY frame C->f. Value is a pointer to the newly
5997 created realized face. */
5999 static struct face
*
6000 realize_tty_face (c
, attrs
, charset
)
6001 struct face_cache
*c
;
6009 /* Frame must be a termcap frame. */
6010 xassert (FRAME_TERMCAP_P (c
->f
) || FRAME_MSDOS_P (c
->f
));
6012 /* Allocate a new realized face. */
6013 face
= make_realized_face (attrs
, charset
, Qnil
);
6014 face
->font_name
= FRAME_MSDOS_P (c
->f
) ? "ms-dos" : "tty";
6016 /* Map face attributes to TTY appearances. We map slant to
6017 dimmed text because we want italic text to appear differently
6018 and because dimmed text is probably used infrequently. */
6019 weight
= face_numeric_weight (attrs
[LFACE_WEIGHT_INDEX
]);
6020 slant
= face_numeric_slant (attrs
[LFACE_SLANT_INDEX
]);
6022 if (weight
> XLFD_WEIGHT_MEDIUM
)
6023 face
->tty_bold_p
= 1;
6024 if (weight
< XLFD_WEIGHT_MEDIUM
|| slant
!= XLFD_SLANT_ROMAN
)
6025 face
->tty_dim_p
= 1;
6026 if (!NILP (attrs
[LFACE_UNDERLINE_INDEX
]))
6027 face
->tty_underline_p
= 1;
6028 if (!NILP (attrs
[LFACE_INVERSE_INDEX
]))
6029 face
->tty_reverse_p
= 1;
6031 /* Map color names to color indices. */
6032 face
->foreground
= face
->background
= FACE_TTY_DEFAULT_COLOR
;
6034 color
= attrs
[LFACE_FOREGROUND_INDEX
];
6035 if (XSTRING (color
)->size
6036 && (color
= Fassoc (color
, Vface_tty_color_alist
),
6038 face
->foreground
= XINT (XCDR (color
));
6041 if (FRAME_MSDOS_P (c
->f
) && face
->foreground
== FACE_TTY_DEFAULT_COLOR
)
6043 face
->foreground
= load_color (c
->f
, face
,
6044 attrs
[LFACE_FOREGROUND_INDEX
],
6045 LFACE_FOREGROUND_INDEX
);
6046 /* If the foreground of the default face is the default color,
6047 use the foreground color defined by the frame. */
6048 if (face
->foreground
== FACE_TTY_DEFAULT_COLOR
)
6050 face
->foreground
= FRAME_FOREGROUND_PIXEL (f
);
6051 attrs
[LFACE_FOREGROUND_INDEX
] =
6052 build_string (msdos_stdcolor_name (face
->foreground
));
6057 color
= attrs
[LFACE_BACKGROUND_INDEX
];
6058 if (XSTRING (color
)->size
6059 && (color
= Fassoc (color
, Vface_tty_color_alist
),
6061 face
->background
= XINT (XCDR (color
));
6064 if (FRAME_MSDOS_P (c
->f
) && face
->background
== FACE_TTY_DEFAULT_COLOR
)
6066 face
->background
= load_color (c
->f
, face
,
6067 attrs
[LFACE_BACKGROUND_INDEX
],
6068 LFACE_BACKGROUND_INDEX
);
6069 /* If the background of the default face is the default color,
6070 use the background color defined by the frame. */
6071 if (face
->background
== FACE_TTY_DEFAULT_COLOR
)
6073 face
->background
= FRAME_BACKGROUND_PIXEL (f
);
6074 attrs
[LFACE_BACKGROUND_INDEX
] =
6075 build_string (msdos_stdcolor_name (face
->background
));
6079 /* Swap colors if face is inverse-video. */
6080 if (face
->tty_reverse_p
)
6082 unsigned long tem
= face
->foreground
;
6084 face
->foreground
= face
->background
;
6085 face
->background
= tem
;
6093 DEFUN ("face-register-tty-color", Fface_register_tty_color
,
6094 Sface_register_tty_color
, 2, 2, 0,
6095 "Say that COLOR is color number NUMBER on the terminal.\n\
6096 COLOR is a string, the color name. Value is COLOR.")
6098 Lisp_Object color
, number
;
6102 CHECK_STRING (color
, 0);
6103 CHECK_NUMBER (number
, 1);
6104 entry
= Fassoc (color
, Vface_tty_color_alist
);
6106 Vface_tty_color_alist
= Fcons (Fcons (color
, number
),
6107 Vface_tty_color_alist
);
6109 Fsetcdr (entry
, number
);
6114 DEFUN ("face-clear-tty-colors", Fface_clear_tty_colors
,
6115 Sface_clear_tty_colors
, 0, 0, 0,
6116 "Unregister all registered tty colors.")
6119 return Vface_tty_color_alist
= Qnil
;
6123 DEFUN ("tty-defined-colors", Ftty_defined_colors
,
6124 Stty_defined_colors
, 0, 0, 0,
6125 "Return a list of registered tty colors.")
6128 Lisp_Object list
, colors
;
6131 for (list
= Vface_tty_color_alist
; CONSP (list
); list
= XCDR (list
))
6132 colors
= Fcons (XCAR (XCAR (list
)), colors
);
6139 /***********************************************************************
6141 ***********************************************************************/
6143 /* Return the ID of the face to use to display character CH with face
6144 property PROP on frame F in current_buffer. */
6147 compute_char_face (f
, ch
, prop
)
6153 int charset
= (NILP (current_buffer
->enable_multibyte_characters
)
6155 : CHAR_CHARSET (ch
));
6158 face_id
= FACE_FOR_CHARSET (f
, DEFAULT_FACE_ID
, charset
);
6161 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6162 struct face
*default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6163 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
6164 merge_face_vector_with_property (f
, attrs
, prop
);
6165 face_id
= lookup_face (f
, attrs
, charset
);
6172 /* Return the face ID associated with buffer position POS for
6173 displaying ASCII characters. Return in *ENDPTR the position at
6174 which a different face is needed, as far as text properties and
6175 overlays are concerned. W is a window displaying current_buffer.
6177 REGION_BEG, REGION_END delimit the region, so it can be
6180 LIMIT is a position not to scan beyond. That is to limit the time
6181 this function can take.
6183 If MOUSE is non-zero, use the character's mouse-face, not its face.
6185 The face returned is suitable for displaying CHARSET_ASCII if
6186 current_buffer->enable_multibyte_characters is non-nil. Otherwise,
6187 the face is suitable for displaying unibyte text. */
6190 face_at_buffer_position (w
, pos
, region_beg
, region_end
,
6191 endptr
, limit
, mouse
)
6194 int region_beg
, region_end
;
6199 struct frame
*f
= XFRAME (w
->frame
);
6200 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6201 Lisp_Object prop
, position
;
6203 Lisp_Object
*overlay_vec
;
6206 Lisp_Object propname
= mouse
? Qmouse_face
: Qface
;
6207 Lisp_Object limit1
, end
;
6208 struct face
*default_face
;
6209 int multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
6211 /* W must display the current buffer. We could write this function
6212 to use the frame and buffer of W, but right now it doesn't. */
6213 /* xassert (XBUFFER (w->buffer) == current_buffer); */
6215 XSETFRAME (frame
, f
);
6216 XSETFASTINT (position
, pos
);
6219 if (pos
< region_beg
&& region_beg
< endpos
)
6220 endpos
= region_beg
;
6222 /* Get the `face' or `mouse_face' text property at POS, and
6223 determine the next position at which the property changes. */
6224 prop
= Fget_text_property (position
, propname
, w
->buffer
);
6225 XSETFASTINT (limit1
, (limit
< endpos
? limit
: endpos
));
6226 end
= Fnext_single_property_change (position
, propname
, w
->buffer
, limit1
);
6228 endpos
= XINT (end
);
6230 /* Look at properties from overlays. */
6235 /* First try with room for 40 overlays. */
6237 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6238 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
6239 &next_overlay
, NULL
);
6241 /* If there are more than 40, make enough space for all, and try
6243 if (noverlays
> len
)
6246 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6247 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
,
6248 &next_overlay
, NULL
);
6251 if (next_overlay
< endpos
)
6252 endpos
= next_overlay
;
6257 default_face
= FACE_FROM_ID (f
, DEFAULT_FACE_ID
);
6259 /* Optimize common cases where we can use the default face. */
6262 && !(pos
>= region_beg
&& pos
< region_end
)
6264 || !FRAME_WINDOW_P (f
)
6265 || FACE_SUITABLE_FOR_CHARSET_P (default_face
, -1)))
6266 return DEFAULT_FACE_ID
;
6268 /* Begin with attributes from the default face. */
6269 bcopy (default_face
->lface
, attrs
, sizeof attrs
);
6271 /* Merge in attributes specified via text properties. */
6273 merge_face_vector_with_property (f
, attrs
, prop
);
6275 /* Now merge the overlay data. */
6276 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6277 for (i
= 0; i
< noverlays
; i
++)
6282 prop
= Foverlay_get (overlay_vec
[i
], propname
);
6284 merge_face_vector_with_property (f
, attrs
, prop
);
6286 oend
= OVERLAY_END (overlay_vec
[i
]);
6287 oendpos
= OVERLAY_POSITION (oend
);
6288 if (oendpos
< endpos
)
6292 /* If in the region, merge in the region face. */
6293 if (pos
>= region_beg
&& pos
< region_end
)
6295 Lisp_Object region_face
= lface_from_face_name (f
, Qregion
, 0);
6296 merge_face_vectors (XVECTOR (region_face
)->contents
, attrs
);
6298 if (region_end
< endpos
)
6299 endpos
= region_end
;
6304 /* Look up a realized face with the given face attributes,
6305 or realize a new one. Charset is ignored for tty frames. */
6306 return lookup_face (f
, attrs
, multibyte_p
? CHARSET_ASCII
: -1);
6310 /* Compute the face at character position POS in Lisp string STRING on
6311 window W, for charset CHARSET_ASCII.
6313 If STRING is an overlay string, it comes from position BUFPOS in
6314 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
6315 not an overlay string. W must display the current buffer.
6316 REGION_BEG and REGION_END give the start and end positions of the
6317 region; both are -1 if no region is visible. BASE_FACE_ID is the
6318 id of the basic face to merge with. It is usually equal to
6319 DEFAULT_FACE_ID but can be MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID
6320 for strings displayed in the mode or top line.
6322 Set *ENDPTR to the next position where to check for faces in
6323 STRING; -1 if the face is constant from POS to the end of the
6326 Value is the id of the face to use. The face returned is suitable
6327 for displaying CHARSET_ASCII if STRING is multibyte. Otherwise,
6328 the face is suitable for displaying unibyte text. */
6331 face_at_string_position (w
, string
, pos
, bufpos
, region_beg
,
6332 region_end
, endptr
, base_face_id
)
6336 int region_beg
, region_end
;
6338 enum face_id base_face_id
;
6340 Lisp_Object prop
, position
, end
, limit
;
6341 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
6342 Lisp_Object attrs
[LFACE_VECTOR_SIZE
];
6343 struct face
*base_face
;
6344 int multibyte_p
= STRING_MULTIBYTE (string
);
6346 /* Get the value of the face property at the current position within
6347 STRING. Value is nil if there is no face property. */
6348 XSETFASTINT (position
, pos
);
6349 prop
= Fget_text_property (position
, Qface
, string
);
6351 /* Get the next position at which to check for faces. Value of end
6352 is nil if face is constant all the way to the end of the string.
6353 Otherwise it is a string position where to check faces next.
6354 Limit is the maximum position up to which to check for property
6355 changes in Fnext_single_property_change. Strings are usually
6356 short, so set the limit to the end of the string. */
6357 XSETFASTINT (limit
, XSTRING (string
)->size
);
6358 end
= Fnext_single_property_change (position
, Qface
, string
, limit
);
6360 *endptr
= XFASTINT (end
);
6364 base_face
= FACE_FROM_ID (f
, base_face_id
);
6365 xassert (base_face
);
6367 /* Optimize the default case that there is no face property and we
6368 are not in the region. */
6370 && (base_face_id
!= DEFAULT_FACE_ID
6371 /* BUFPOS <= 0 means STRING is not an overlay string, so
6372 that the region doesn't have to be taken into account. */
6374 || bufpos
< region_beg
6375 || bufpos
>= region_end
)
6377 /* We can't realize faces for different charsets differently
6378 if we don't have fonts, so we can stop here if not working
6379 on a window-system frame. */
6380 || !FRAME_WINDOW_P (f
)
6381 || FACE_SUITABLE_FOR_CHARSET_P (base_face
, -1)))
6382 return base_face
->id
;
6384 /* Begin with attributes from the base face. */
6385 bcopy (base_face
->lface
, attrs
, sizeof attrs
);
6387 /* Merge in attributes specified via text properties. */
6389 merge_face_vector_with_property (f
, attrs
, prop
);
6391 /* If in the region, merge in the region face. */
6393 && bufpos
>= region_beg
6394 && bufpos
< region_end
)
6396 Lisp_Object region_face
= lface_from_face_name (f
, Qregion
, 0);
6397 merge_face_vectors (XVECTOR (region_face
)->contents
, attrs
);
6400 /* Look up a realized face with the given face attributes,
6401 or realize a new one. */
6402 return lookup_face (f
, attrs
, multibyte_p
? CHARSET_ASCII
: -1);
6407 /***********************************************************************
6409 ***********************************************************************/
6413 /* Print the contents of the realized face FACE to stderr. */
6416 dump_realized_face (face
)
6419 fprintf (stderr
, "ID: %d\n", face
->id
);
6420 #ifdef HAVE_X_WINDOWS
6421 fprintf (stderr
, "gc: %d\n", (int) face
->gc
);
6423 fprintf (stderr
, "foreground: 0x%lx (%s)\n",
6425 XSTRING (face
->lface
[LFACE_FOREGROUND_INDEX
])->data
);
6426 fprintf (stderr
, "background: 0x%lx (%s)\n",
6428 XSTRING (face
->lface
[LFACE_BACKGROUND_INDEX
])->data
);
6429 fprintf (stderr
, "font_name: %s (%s)\n",
6431 XSTRING (face
->lface
[LFACE_FAMILY_INDEX
])->data
);
6432 #ifdef HAVE_X_WINDOWS
6433 fprintf (stderr
, "font = %p\n", face
->font
);
6435 fprintf (stderr
, "font_info_id = %d\n", face
->font_info_id
);
6436 fprintf (stderr
, "fontset: %d\n", face
->fontset
);
6437 fprintf (stderr
, "underline: %d (%s)\n",
6439 XSTRING (Fsymbol_name (face
->lface
[LFACE_UNDERLINE_INDEX
]))->data
);
6440 fprintf (stderr
, "hash: %d\n", face
->hash
);
6441 fprintf (stderr
, "charset: %d\n", face
->charset
);
6445 DEFUN ("dump-face", Fdump_face
, Sdump_face
, 0, 1, 0, "")
6453 fprintf (stderr
, "font selection order: ");
6454 for (i
= 0; i
< DIM (font_sort_order
); ++i
)
6455 fprintf (stderr
, "%d ", font_sort_order
[i
]);
6456 fprintf (stderr
, "\n");
6458 fprintf (stderr
, "alternative fonts: ");
6459 debug_print (Vface_alternative_font_family_alist
);
6460 fprintf (stderr
, "\n");
6462 for (i
= 0; i
< FRAME_FACE_CACHE (SELECTED_FRAME ())->used
; ++i
)
6463 Fdump_face (make_number (i
));
6468 CHECK_NUMBER (n
, 0);
6469 face
= FACE_FROM_ID (SELECTED_FRAME (), XINT (n
));
6471 error ("Not a valid face");
6472 dump_realized_face (face
);
6479 DEFUN ("show-face-resources", Fshow_face_resources
, Sshow_face_resources
,
6483 fprintf (stderr
, "number of colors = %d\n", ncolors_allocated
);
6484 fprintf (stderr
, "number of pixmaps = %d\n", npixmaps_allocated
);
6485 fprintf (stderr
, "number of GCs = %d\n", ngcs
);
6489 #endif /* GLYPH_DEBUG != 0 */
6493 /***********************************************************************
6495 ***********************************************************************/
6500 Qface
= intern ("face");
6502 Qbitmap_spec_p
= intern ("bitmap-spec-p");
6503 staticpro (&Qbitmap_spec_p
);
6504 Qframe_update_face_colors
= intern ("frame-update-face-colors");
6505 staticpro (&Qframe_update_face_colors
);
6507 /* Lisp face attribute keywords. */
6508 QCfamily
= intern (":family");
6509 staticpro (&QCfamily
);
6510 QCheight
= intern (":height");
6511 staticpro (&QCheight
);
6512 QCweight
= intern (":weight");
6513 staticpro (&QCweight
);
6514 QCslant
= intern (":slant");
6515 staticpro (&QCslant
);
6516 QCunderline
= intern (":underline");
6517 staticpro (&QCunderline
);
6518 QCinverse_video
= intern (":inverse-video");
6519 staticpro (&QCinverse_video
);
6520 QCreverse_video
= intern (":reverse-video");
6521 staticpro (&QCreverse_video
);
6522 QCforeground
= intern (":foreground");
6523 staticpro (&QCforeground
);
6524 QCbackground
= intern (":background");
6525 staticpro (&QCbackground
);
6526 QCstipple
= intern (":stipple");;
6527 staticpro (&QCstipple
);
6528 QCwidth
= intern (":width");
6529 staticpro (&QCwidth
);
6530 QCfont
= intern (":font");
6531 staticpro (&QCfont
);
6532 QCbold
= intern (":bold");
6533 staticpro (&QCbold
);
6534 QCitalic
= intern (":italic");
6535 staticpro (&QCitalic
);
6536 QCoverline
= intern (":overline");
6537 staticpro (&QCoverline
);
6538 QCstrike_through
= intern (":strike-through");
6539 staticpro (&QCstrike_through
);
6540 QCbox
= intern (":box");
6543 /* Symbols used for Lisp face attribute values. */
6544 QCcolor
= intern (":color");
6545 staticpro (&QCcolor
);
6546 QCline_width
= intern (":line-width");
6547 staticpro (&QCline_width
);
6548 QCstyle
= intern (":style");
6549 staticpro (&QCstyle
);
6550 Qreleased_button
= intern ("released-button");
6551 staticpro (&Qreleased_button
);
6552 Qpressed_button
= intern ("pressed-button");
6553 staticpro (&Qpressed_button
);
6554 Qnormal
= intern ("normal");
6555 staticpro (&Qnormal
);
6556 Qultra_light
= intern ("ultra-light");
6557 staticpro (&Qultra_light
);
6558 Qextra_light
= intern ("extra-light");
6559 staticpro (&Qextra_light
);
6560 Qlight
= intern ("light");
6561 staticpro (&Qlight
);
6562 Qsemi_light
= intern ("semi-light");
6563 staticpro (&Qsemi_light
);
6564 Qsemi_bold
= intern ("semi-bold");
6565 staticpro (&Qsemi_bold
);
6566 Qbold
= intern ("bold");
6568 Qextra_bold
= intern ("extra-bold");
6569 staticpro (&Qextra_bold
);
6570 Qultra_bold
= intern ("ultra-bold");
6571 staticpro (&Qultra_bold
);
6572 Qoblique
= intern ("oblique");
6573 staticpro (&Qoblique
);
6574 Qitalic
= intern ("italic");
6575 staticpro (&Qitalic
);
6576 Qreverse_oblique
= intern ("reverse-oblique");
6577 staticpro (&Qreverse_oblique
);
6578 Qreverse_italic
= intern ("reverse-italic");
6579 staticpro (&Qreverse_italic
);
6580 Qultra_condensed
= intern ("ultra-condensed");
6581 staticpro (&Qultra_condensed
);
6582 Qextra_condensed
= intern ("extra-condensed");
6583 staticpro (&Qextra_condensed
);
6584 Qcondensed
= intern ("condensed");
6585 staticpro (&Qcondensed
);
6586 Qsemi_condensed
= intern ("semi-condensed");
6587 staticpro (&Qsemi_condensed
);
6588 Qsemi_expanded
= intern ("semi-expanded");
6589 staticpro (&Qsemi_expanded
);
6590 Qexpanded
= intern ("expanded");
6591 staticpro (&Qexpanded
);
6592 Qextra_expanded
= intern ("extra-expanded");
6593 staticpro (&Qextra_expanded
);
6594 Qultra_expanded
= intern ("ultra-expanded");
6595 staticpro (&Qultra_expanded
);
6596 Qbackground_color
= intern ("background-color");
6597 staticpro (&Qbackground_color
);
6598 Qforeground_color
= intern ("foreground-color");
6599 staticpro (&Qforeground_color
);
6600 Qunspecified
= intern ("unspecified");
6601 staticpro (&Qunspecified
);
6603 Qx_charset_registry
= intern ("x-charset-registry");
6604 staticpro (&Qx_charset_registry
);
6605 Qface_alias
= intern ("face-alias");
6606 staticpro (&Qface_alias
);
6607 Qdefault
= intern ("default");
6608 staticpro (&Qdefault
);
6609 Qtool_bar
= intern ("tool-bar");
6610 staticpro (&Qtool_bar
);
6611 Qregion
= intern ("region");
6612 staticpro (&Qregion
);
6613 Qfringe
= intern ("fringe");
6614 staticpro (&Qfringe
);
6615 Qheader_line
= intern ("header-line");
6616 staticpro (&Qheader_line
);
6617 Qscroll_bar
= intern ("scroll-bar");
6618 staticpro (&Qscroll_bar
);
6619 Qmenu
= intern ("menu");
6621 Qcursor
= intern ("cursor");
6622 staticpro (&Qcursor
);
6623 Qborder
= intern ("border");
6624 staticpro (&Qborder
);
6625 Qmouse
= intern ("mouse");
6626 staticpro (&Qmouse
);
6628 defsubr (&Sinternal_make_lisp_face
);
6629 defsubr (&Sinternal_lisp_face_p
);
6630 defsubr (&Sinternal_set_lisp_face_attribute
);
6631 #ifdef HAVE_X_WINDOWS
6632 defsubr (&Sinternal_set_lisp_face_attribute_from_resource
);
6633 defsubr (&Sface_color_gray_p
);
6634 defsubr (&Sface_color_supported_p
);
6636 defsubr (&Sinternal_get_lisp_face_attribute
);
6637 defsubr (&Sinternal_lisp_face_attribute_values
);
6638 defsubr (&Sinternal_lisp_face_equal_p
);
6639 defsubr (&Sinternal_lisp_face_empty_p
);
6640 defsubr (&Sinternal_copy_lisp_face
);
6641 defsubr (&Sinternal_merge_in_global_face
);
6642 defsubr (&Sface_font
);
6643 defsubr (&Sframe_face_alist
);
6644 defsubr (&Sinternal_set_font_selection_order
);
6645 defsubr (&Sinternal_set_alternative_font_family_alist
);
6647 defsubr (&Sdump_face
);
6648 defsubr (&Sshow_face_resources
);
6649 #endif /* GLYPH_DEBUG */
6650 defsubr (&Sclear_face_cache
);
6652 DEFVAR_LISP ("font-list-limit", &Vfont_list_limit
,
6653 "*Limit for font matching.\n\
6654 If an integer > 0, font matching functions won't load more than\n\
6655 that number of fonts when searching for a matching font.");
6656 Vfont_list_limit
= make_number (DEFAULT_FONT_LIST_LIMIT
);
6658 DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults
,
6659 "List of global face definitions (for internal use only.)");
6660 Vface_new_frame_defaults
= Qnil
;
6662 DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple
,
6663 "*Default stipple pattern used on monochrome displays.\n\
6664 This stipple pattern is used on monochrome displays\n\
6665 instead of shades of gray for a face background color.\n\
6666 See `set-face-stipple' for possible values for this variable.");
6667 Vface_default_stipple
= build_string ("gray3");
6669 DEFVAR_LISP ("face-default-registry", &Vface_default_registry
,
6670 "Default registry and encoding to use.\n\
6671 This registry and encoding is used for unibyte text. It is set up\n\
6672 from the specified frame font when Emacs starts. (For internal use only.)");
6673 Vface_default_registry
= Qnil
;
6675 DEFVAR_LISP ("face-alternative-font-family-alist",
6676 &Vface_alternative_font_family_alist
, "");
6677 Vface_alternative_font_family_alist
= Qnil
;
6681 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed
,
6682 "Allowed scalable fonts.\n\
6683 A value of nil means don't allow any scalable fonts.\n\
6684 A value of t means allow any scalable font.\n\
6685 Otherwise, value must be a list of regular expressions. A font may be\n\
6686 scaled if its name matches a regular expression in the list.");
6687 Vscalable_fonts_allowed
= Qnil
;
6689 #endif /* SCALABLE_FONTS */
6691 #ifdef HAVE_X_WINDOWS
6692 defsubr (&Sbitmap_spec_p
);
6693 defsubr (&Sx_list_fonts
);
6694 defsubr (&Sinternal_face_x_get_resource
);
6695 defsubr (&Sx_family_fonts
);
6696 defsubr (&Sx_font_family_list
);
6697 #endif /* HAVE_X_WINDOWS */
6699 /* TTY face support. */
6700 defsubr (&Sface_register_tty_color
);
6701 defsubr (&Sface_clear_tty_colors
);
6702 defsubr (&Stty_defined_colors
);
6703 Vface_tty_color_alist
= Qnil
;
6704 staticpro (&Vface_tty_color_alist
);