comparison src/xfaces.c @ 28230:8e330f701881

(Qx_charset_registry, Vface_default_registry): Variables removed. (clear_font_table, frame_update_line_height, load_face_font): Adjusted for the change of fontset implementation. (load_face_fontset_font): Function removed. (pixel_point_size): New function. (font_list): Argument type changed. Caller changed. (LFACE_FONT): New macro. (check_lface_attrs): Check attr[LFACE_FONT_INDEX]. (set_lface_from_font_name): Type of arg FONTNAME is changed to Lisp_Object. Determine the font name by actually loading a font by the specified pattern. Set LFACE_FONT (lface) to the specified pattern. Even if a font is not found, don't try alternatives. (Finternal_set_lisp_face_attribute): Handle `font' slot in lface. (set_font_frame_param): If `font' is specified in lface, use it. (Finternal_get_lisp_face_attribute): Handle `font' slot in lface. (lface_same_font_attributes_p): Likewise. (make_realized_face): Arguent changed. Caller changed. Set face->ascii_face to face itself. (free_realized_face): Free face->fontset if face is for ASCII. (face_suitable_for_iso8859_1_p, face_suitable_for_charset_p, deduce_unibyte_registry, x_charset_registry): Functions removed. (free_realized_multibyte_face): New function. (lookup_face, lookup_named_face, lookup_derived_face): Argument changed. Caller changed. (try_font_list): Argument type changed. (face_fontset): Check `font' slot of ATTRS, not `family' slot. (choose_face_font): Argument changed. Handle fontset properly. (choose_face_fontset_font): Function removed. (realize_default_face, realize_named_face): Don't remove the former face here. (realize_face): Argument changed. Caller changed. Remove face with the arg former_face_id in advance. Load font for the new face. (realize_x_face): Argument changed. Caller changed. For a multibyte character, share fontset with base_face. For a single byte character, make a new realized fontset. Don't load a font here. (realize_tty_face): Argument changed. Caller changed. (compute_char_face): Call FACE_FOR_CHAR, not FACE_FOR_CHARSET. (face_at_buffer_position): Don't check multibyte_p for returning DEFAULT_FACE_ID. (face_at_string_position): Call FACE_SUITABLE_FOR_CHAR_P, not FACE_SUITABLE_FOR_CHARSET_P. (syms_of_xfaces): Remove code for Qx_charset_registry and Vface_default_registry.
author Kenichi Handa <handa@m17n.org>
date Tue, 21 Mar 2000 00:43:10 +0000
parents 574e0b398168
children 2f636fd2f714
comparison
equal deleted inserted replaced
28229:5a0af67169a7 28230:8e330f701881
24 24
25 When using Emacs with X, the display style of characters can be 25 When using Emacs with X, the display style of characters can be
26 changed by defining `faces'. Each face can specify the following 26 changed by defining `faces'. Each face can specify the following
27 display attributes: 27 display attributes:
28 28
29 1. Font family or fontset alias name. 29 1. Font family name.
30 30
31 2. Relative proportionate width, aka character set width or set 31 2. Relative proportionate width, aka character set width or set
32 width (swidth), e.g. `semi-compressed'. 32 width (swidth), e.g. `semi-compressed'.
33 33
34 3. Font height in 1/10pt 34 3. Font height in 1/10pt.
35 35
36 4. Font weight, e.g. `bold'. 36 4. Font weight, e.g. `bold'.
37 37
38 5. Font slant, e.g. `italic'. 38 5. Font slant, e.g. `italic'.
39 39
53 color. 53 color.
54 54
55 13. Whether or not a box should be drawn around characters, the box 55 13. Whether or not a box should be drawn around characters, the box
56 type, and, for simple boxes, in what color. 56 type, and, for simple boxes, in what color.
57 57
58 14. Font or fontset pattern, or nil. This is a special attribute.
59 When this attribyte is specified, the face uses a font opened by
60 that pattern as is. In addition, all the other font-related
61 attributes (1st thru 5th) are generated from the opened font name.
62 On the other hand, if one of the other font-related attributes are
63 specified, this attribute is set to nil. In that case, the face
64 doesn't inherit this attribute from the `default' face, and uses a
65 font determined by the other attributes (those may be inherited
66 from the `default' face).
67
58 Faces are frame-local by nature because Emacs allows to define the 68 Faces are frame-local by nature because Emacs allows to define the
59 same named face (face names are symbols) differently for different 69 same named face (face names are symbols) differently for different
60 frames. Each frame has an alist of face definitions for all named 70 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 71 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 72 with the symbol `face' in slot 0, and a slot for each of the face
63 face attributes mentioned above. 73 attributes mentioned above.
64 74
65 There is also a global face alist `Vface_new_frame_defaults'. Face 75 There is also a global face alist `Vface_new_frame_defaults'. Face
66 definitions from this list are used to initialize faces of newly 76 definitions from this list are used to initialize faces of newly
67 created frames. 77 created frames.
68 78
69 A face doesn't have to specify all attributes. Those not specified 79 A face doesn't have to specify all attributes. Those not specified
70 have a value of `unspecified'. Faces specifying all attributes are 80 have a value of `unspecified'. Faces specifying all attributes but
71 called `fully-specified'. 81 the 14th are called `fully-specified'.
72 82
73 83
74 Face merging. 84 Face merging.
75 85
76 The display style of a given character in the text is determined by 86 The display style of a given character in the text is determined by
88 realization process maps face attributes to what is physically 98 realization process maps face attributes to what is physically
89 available on the system where Emacs runs. The result is a 99 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 100 `realized face' in form of a struct face which is stored in the
91 face cache of the frame on which it was realized. 101 face cache of the frame on which it was realized.
92 102
93 Face realization is done in the context of the charset of the 103 Face realization is done in the context of the character to display
94 character to display because different fonts and encodings are used 104 because different fonts may be used for different characters. In
95 for different charsets. In other words, for characters of 105 other words, for characters that have different font
96 different charsets, different realized faces are needed to display 106 specifications, different realized faces are needed to display
97 them. 107 them.
98 108
99 Faces are always realized for a specific character set and contain 109 Font specification is done by fontsets. See the comment in
100 a specific font, even if the face being realized specifies a 110 fontset.c for the details. In the current implementation, all ASCII
101 fontset (see `font selection' below). The reason is that the 111 characters share the same font in a fontset.
102 result of the new font selection stage is better than what can be 112
103 done with statically defined font name patterns in fontsets. 113 Faces are at first realized for ASCII characters, and, at that
114 time, assigned a specific realized fontset. Hereafter, we call
115 such a face as `ASCII face'. When a face for a multibyte character
116 is realized, it inherits (thus shares) a fontset of an ASCII face
117 that has the same attributes other than font-related ones.
118
119 Thus, all realzied face have a realized fontset.
104 120
105 121
106 Unibyte text. 122 Unibyte text.
107 123
108 In unibyte text, Emacs' charsets aren't applicable; function 124 Unibyte text (i.e. raw 8-bit characters) is displayed with the same
109 `char-charset' reports CHARSET_ASCII for all characters, including 125 font as ASCII characters. That is because it is expected that
110 those > 0x7f. The X registry and encoding of fonts to use is 126 unibyte text users specify a font that is suitable both for ASCII
111 determined from the variable `x-unibyte-registry-and-encoding' in 127 and raw 8-bit characters.
112 this case. The variable is initialized at Emacs startup time from 128
113 the font the user specified for Emacs.
114
115 Currently all unibyte text, i.e. all buffers with
116 enable_multibyte_characters nil are displayed with fonts of the
117 same registry and encoding `x-unibyte-registry-and-encoding'. This
118 is consistent with the fact that languages can also be set
119 globally, only.
120
121 129
122 Font selection. 130 Font selection.
123 131
124 Font selection tries to find the best available matching font for a 132 Font selection tries to find the best available matching font for a
125 given (charset, face) combination. This is done slightly 133 given (character, face) combination.
126 differently for faces specifying a fontset, or a font family name. 134
127 135 If the face specifies a fontset name, that fontset determines a
128 If the face specifies a fontset alias name, that fontset determines 136 pattern for fonts of the given character. If the face specifies a
129 a pattern for fonts of the given charset. If the face specifies a 137 font name or the other font-related attributes, a fontset is
130 font family, a font pattern is constructed. Charset symbols have a 138 realized from the default fontset. In that case, that
131 property `x-charset-registry' for that purpose that maps a charset 139 specification determines a pattern for ASCII characters and the
132 to an XLFD registry and encoding in the font pattern constructed. 140 default fontset determines a pattern for multibyte characters.
133 141
134 Available fonts on the system on which Emacs runs are then matched 142 Available fonts on the system on which Emacs runs are then matched
135 against the font pattern. The result of font selection is the best 143 against the font pattern. The result of font selection is the best
136 match for the given face attributes in this font list. 144 match for the given face attributes in this font list.
137 145
149 2. Setting face-alternative-font-family-alist allows the user to 157 2. Setting face-alternative-font-family-alist allows the user to
150 specify alternative font families to try if a family specified by a 158 specify alternative font families to try if a family specified by a
151 face doesn't exist. 159 face doesn't exist.
152 160
153 161
154 Composite characters. 162 Character compositition.
155 163
156 Realized faces for composite characters are the only ones having a 164 Usually, the realization process is already finished when Emacs
157 fontset id >= 0. When a composite character is encoded into a 165 actually reflects the desired glyph matrix on the screen. However,
158 sequence of non-composite characters (in xterm.c), a suitable font 166 on displaying a composition (sequence of characters to be composed
159 for the non-composite characters is then selected and realized, 167 on the screen), a suitable font for the components of the
160 i.e. the realization process is delayed but in principle the same. 168 composition is selected and realized while drawing them on the
169 screen, i.e. the realization process is delayed but in principle
170 the same.
161 171
162 172
163 Initialization of basic faces. 173 Initialization of basic faces.
164 174
165 The faces `default', `modeline' are considered `basic faces'. 175 The faces `default', `modeline' are considered `basic faces'.
300 Lisp_Object QCstyle, QCcolor, QCline_width; 310 Lisp_Object QCstyle, QCcolor, QCline_width;
301 Lisp_Object Qunspecified; 311 Lisp_Object Qunspecified;
302 312
303 char unspecified_fg[] = "unspecified-fg", unspecified_bg[] = "unspecified-bg"; 313 char unspecified_fg[] = "unspecified-fg", unspecified_bg[] = "unspecified-bg";
304 314
305 /* The symbol `x-charset-registry'. This property of charsets defines
306 the X registry and encoding that fonts should have that are used to
307 display characters of that charset. */
308
309 Lisp_Object Qx_charset_registry;
310
311 /* The name of the function to call when the background of the frame 315 /* The name of the function to call when the background of the frame
312 has changed, frame_update_face_colors. */ 316 has changed, frame_update_face_colors. */
313 317
314 Lisp_Object Qframe_update_face_colors; 318 Lisp_Object Qframe_update_face_colors;
315 319
334 pattern is used on monochrome displays instead of shades of gray 338 pattern is used on monochrome displays instead of shades of gray
335 for a face background color. See `set-face-stipple' for possible 339 for a face background color. See `set-face-stipple' for possible
336 values for this variable. */ 340 values for this variable. */
337 341
338 Lisp_Object Vface_default_stipple; 342 Lisp_Object Vface_default_stipple;
339
340 /* Default registry and encoding to use for charsets whose charset
341 symbols don't specify one. */
342
343 Lisp_Object Vface_default_registry;
344 343
345 /* Alist of alternative font families. Each element is of the form 344 /* Alist of alternative font families. Each element is of the form
346 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded, 345 (FAMILY FAMILY1 FAMILY2 ...). If fonts of FAMILY can't be loaded,
347 try FAMILY1, then FAMILY2, ... */ 346 try FAMILY1, then FAMILY2, ... */
348 347
434 static int first_font_matching P_ ((struct frame *f, char *, 433 static int first_font_matching P_ ((struct frame *f, char *,
435 struct font_name *)); 434 struct font_name *));
436 static int x_face_list_fonts P_ ((struct frame *, char *, 435 static int x_face_list_fonts P_ ((struct frame *, char *,
437 struct font_name *, int, int, int)); 436 struct font_name *, int, int, int));
438 static int font_scalable_p P_ ((struct font_name *)); 437 static int font_scalable_p P_ ((struct font_name *));
439 static Lisp_Object deduce_unibyte_registry P_ ((struct frame *, char *));
440 static int get_lface_attributes P_ ((struct frame *, Lisp_Object, Lisp_Object *, int)); 438 static int get_lface_attributes P_ ((struct frame *, Lisp_Object, Lisp_Object *, int));
441 static int load_pixmap P_ ((struct frame *, Lisp_Object, unsigned *, unsigned *)); 439 static int load_pixmap P_ ((struct frame *, Lisp_Object, unsigned *, unsigned *));
442 static char *xstrdup P_ ((char *)); 440 static char *xstrdup P_ ((char *));
443 static unsigned char *xstrlwr P_ ((unsigned char *)); 441 static unsigned char *xstrlwr P_ ((unsigned char *));
444 static void signal_error P_ ((char *, Lisp_Object)); 442 static void signal_error P_ ((char *, Lisp_Object));
445 static struct frame *frame_or_selected_frame P_ ((Lisp_Object, int)); 443 static struct frame *frame_or_selected_frame P_ ((Lisp_Object, int));
446 static void load_face_font_or_fontset P_ ((struct frame *, struct face *, char *, int)); 444 static void load_face_font P_ ((struct frame *, struct face *, int));
447 static void load_face_colors P_ ((struct frame *, struct face *, Lisp_Object *)); 445 static void load_face_colors P_ ((struct frame *, struct face *, Lisp_Object *));
448 static void free_face_colors P_ ((struct frame *, struct face *)); 446 static void free_face_colors P_ ((struct frame *, struct face *));
449 static int face_color_gray_p P_ ((struct frame *, char *)); 447 static int face_color_gray_p P_ ((struct frame *, char *));
450 static char *build_font_name P_ ((struct font_name *)); 448 static char *build_font_name P_ ((struct font_name *));
451 static void free_font_names P_ ((struct font_name *, int)); 449 static void free_font_names P_ ((struct font_name *, int));
452 static int sorted_font_list P_ ((struct frame *, char *, 450 static int sorted_font_list P_ ((struct frame *, char *,
453 int (*cmpfn) P_ ((const void *, const void *)), 451 int (*cmpfn) P_ ((const void *, const void *)),
454 struct font_name **)); 452 struct font_name **));
455 static int font_list P_ ((struct frame *, char *, char *, char *, struct font_name **)); 453 static int font_list P_ ((struct frame *, Lisp_Object, Lisp_Object,
456 static int try_font_list P_ ((struct frame *, Lisp_Object *, char *, char *, char *, 454 Lisp_Object, struct font_name **));
457 struct font_name **)); 455 static int try_font_list P_ ((struct frame *, Lisp_Object *, Lisp_Object,
456 Lisp_Object, Lisp_Object, struct font_name **));
458 static int cmp_font_names P_ ((const void *, const void *)); 457 static int cmp_font_names P_ ((const void *, const void *));
459 static struct face *realize_face P_ ((struct face_cache *, 458 static struct face *realize_face P_ ((struct face_cache *, Lisp_Object *, int,
460 Lisp_Object *, int)); 459 struct face *, int));
461 static struct face *realize_x_face P_ ((struct face_cache *, 460 static struct face *realize_x_face P_ ((struct face_cache *,
462 Lisp_Object *, int)); 461 Lisp_Object *, int, struct face *));
463 static struct face *realize_tty_face P_ ((struct face_cache *, 462 static struct face *realize_tty_face P_ ((struct face_cache *,
464 Lisp_Object *, int)); 463 Lisp_Object *, int));
465 static int realize_basic_faces P_ ((struct frame *)); 464 static int realize_basic_faces P_ ((struct frame *));
466 static int realize_default_face P_ ((struct frame *)); 465 static int realize_default_face P_ ((struct frame *));
467 static void realize_named_face P_ ((struct frame *, Lisp_Object, int)); 466 static void realize_named_face P_ ((struct frame *, Lisp_Object, int));
475 static void clear_face_gcs P_ ((struct face_cache *)); 474 static void clear_face_gcs P_ ((struct face_cache *));
476 static void free_face_cache P_ ((struct face_cache *)); 475 static void free_face_cache P_ ((struct face_cache *));
477 static int face_numeric_weight P_ ((Lisp_Object)); 476 static int face_numeric_weight P_ ((Lisp_Object));
478 static int face_numeric_slant P_ ((Lisp_Object)); 477 static int face_numeric_slant P_ ((Lisp_Object));
479 static int face_numeric_swidth P_ ((Lisp_Object)); 478 static int face_numeric_swidth P_ ((Lisp_Object));
480 static int face_fontset P_ ((struct frame *, Lisp_Object *)); 479 static int face_fontset P_ ((Lisp_Object *));
481 static char *choose_face_font P_ ((struct frame *, Lisp_Object *, int, 480 static char *choose_face_font P_ ((struct frame *, Lisp_Object *, int, int));
482 Lisp_Object));
483 static char *choose_face_fontset_font P_ ((struct frame *, Lisp_Object *,
484 int, int));
485 static void merge_face_vectors P_ ((Lisp_Object *from, Lisp_Object *)); 481 static void merge_face_vectors P_ ((Lisp_Object *from, Lisp_Object *));
486 static void merge_face_vector_with_property P_ ((struct frame *, Lisp_Object *, 482 static void merge_face_vector_with_property P_ ((struct frame *, Lisp_Object *,
487 Lisp_Object)); 483 Lisp_Object));
488 static int set_lface_from_font_name P_ ((struct frame *, Lisp_Object, char *, 484 static int set_lface_from_font_name P_ ((struct frame *, Lisp_Object,
489 int, int)); 485 Lisp_Object, int, int));
490 static Lisp_Object lface_from_face_name P_ ((struct frame *, Lisp_Object, int)); 486 static Lisp_Object lface_from_face_name P_ ((struct frame *, Lisp_Object, int));
491 static struct face *make_realized_face P_ ((Lisp_Object *, int, Lisp_Object)); 487 static struct face *make_realized_face P_ ((Lisp_Object *));
492 static void free_realized_faces P_ ((struct face_cache *)); 488 static void free_realized_faces P_ ((struct face_cache *));
493 static char *best_matching_font P_ ((struct frame *, Lisp_Object *, 489 static char *best_matching_font P_ ((struct frame *, Lisp_Object *,
494 struct font_name *, int)); 490 struct font_name *, int));
495 static void cache_face P_ ((struct face_cache *, struct face *, unsigned)); 491 static void cache_face P_ ((struct face_cache *, struct face *, unsigned));
496 static void uncache_face P_ ((struct face_cache *, struct face *)); 492 static void uncache_face P_ ((struct face_cache *, struct face *));
865 861
866 862
867 #ifdef HAVE_WINDOW_SYSTEM 863 #ifdef HAVE_WINDOW_SYSTEM
868 864
869 865
870 /* Remove those fonts from the font table of frame F that are not used 866 /* Remove those fonts from the font table of frame F exept for the
871 by fontsets. Called from clear_face_cache from time to time. */ 867 default ASCII font for the frame. Called from clear_face_cache
868 from time to time. */
872 869
873 static void 870 static void
874 clear_font_table (f) 871 clear_font_table (f)
875 struct frame *f; 872 struct frame *f;
876 { 873 {
877 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 874 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
878 char *used;
879 Lisp_Object rest, frame; 875 Lisp_Object rest, frame;
880 int i; 876 int i;
881 877
882 xassert (FRAME_WINDOW_P (f)); 878 xassert (FRAME_WINDOW_P (f));
883 879
884 used = (char *) alloca (dpyinfo->n_fonts * sizeof *used); 880 /* Free those fonts that are not used by the frame F as the default. */
885 bzero (used, dpyinfo->n_fonts * sizeof *used);
886
887 /* For all frames with the same x_display_info as F, record
888 in `used' those fonts that are in use by fontsets. */
889 FOR_EACH_FRAME (rest, frame)
890 if (FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo)
891 {
892 struct frame *f = XFRAME (frame);
893 struct fontset_data *fontset_data = FRAME_FONTSET_DATA (f);
894
895 for (i = 0; i < fontset_data->n_fontsets; ++i)
896 {
897 struct fontset_info *info = fontset_data->fontset_table[i];
898 int j;
899
900 for (j = 0; j <= MAX_CHARSET; ++j)
901 {
902 int idx = info->font_indexes[j];
903 if (idx >= 0)
904 used[idx] = 1;
905 }
906 }
907 }
908
909 /* Free those fonts that are not used by fontsets. */
910 for (i = 0; i < dpyinfo->n_fonts; ++i) 881 for (i = 0; i < dpyinfo->n_fonts; ++i)
911 if (used[i] == 0 && dpyinfo->font_table[i].name) 882 {
912 { 883 struct font_info *font_info = dpyinfo->font_table + i;
913 struct font_info *font_info = dpyinfo->font_table + i; 884
914 885 if (!font_info->name
915 /* Free names. In xfns.c there is a comment that full_name 886 || font_info->font == FRAME_FONT (f))
916 should never be freed because it is always shared with 887 continue;
917 something else. I don't think this is true anymore---see 888
918 x_load_font. It's either equal to font_info->name or 889 /* Free names. */
919 allocated via xmalloc, and there seems to be no place in 890 if (font_info->full_name != font_info->name)
920 the source files where full_name is transferred to another 891 xfree (font_info->full_name);
921 data structure. */ 892 xfree (font_info->name);
922 if (font_info->full_name != font_info->name) 893
923 xfree (font_info->full_name); 894 /* Free the font. */
924 xfree (font_info->name); 895 BLOCK_INPUT;
925
926 /* Free the font. */
927 BLOCK_INPUT;
928 #ifdef HAVE_X_WINDOWS 896 #ifdef HAVE_X_WINDOWS
929 XFreeFont (dpyinfo->display, font_info->font); 897 XFreeFont (dpyinfo->display, font_info->font);
930 #endif 898 #endif
931 #ifdef WINDOWSNT 899 #ifdef WINDOWSNT
932 w32_unload_font (dpyinfo, font_info->font); 900 w32_unload_font (dpyinfo, font_info->font);
933 #endif 901 #endif
934 UNBLOCK_INPUT; 902 UNBLOCK_INPUT;
935 903
936 /* Mark font table slot free. */ 904 /* Mark font table slot free. */
937 font_info->font = NULL; 905 font_info->font = NULL;
938 font_info->name = font_info->full_name = NULL; 906 font_info->name = font_info->full_name = NULL;
939 } 907 }
940 } 908 }
941
942 909
943 #endif /* HAVE_WINDOW_SYSTEM */ 910 #endif /* HAVE_WINDOW_SYSTEM */
944 911
945 912
946 913
1085 1052
1086 int 1053 int
1087 frame_update_line_height (f) 1054 frame_update_line_height (f)
1088 struct frame *f; 1055 struct frame *f;
1089 { 1056 {
1090 int fontset, line_height, changed_p; 1057 int line_height, changed_p;
1091 1058
1092 fontset = FRAME_FONTSET (f); 1059 line_height = FONT_HEIGHT (FRAME_FONT (f));
1093 if (fontset > 0)
1094 line_height = FRAME_FONTSET_DATA (f)->fontset_table[fontset]->height;
1095 else
1096 line_height = FONT_HEIGHT (FRAME_FONT (f));
1097
1098 changed_p = line_height != FRAME_LINE_HEIGHT (f); 1060 changed_p = line_height != FRAME_LINE_HEIGHT (f);
1099 FRAME_LINE_HEIGHT (f) = line_height; 1061 FRAME_LINE_HEIGHT (f) = line_height;
1100 return changed_p; 1062 return changed_p;
1101 } 1063 }
1102 1064
1107 Fonts 1069 Fonts
1108 ***********************************************************************/ 1070 ***********************************************************************/
1109 1071
1110 #ifdef HAVE_WINDOW_SYSTEM 1072 #ifdef HAVE_WINDOW_SYSTEM
1111 1073
1112 /* Load font or fontset of face FACE which is used on frame F. 1074 /* Load font of face FACE which is used on frame F to display
1113 FONTSET is the fontset FACE should use or -1, if FACE doesn't use a 1075 character C. The name of the font to load is determined by lface
1114 fontset. FONT_NAME is the name of the font to load, if no fontset 1076 and fontset of FACE. */
1115 is used. It is null if no suitable font name could be determined
1116 for the face. */
1117 1077
1118 static void 1078 static void
1119 load_face_font_or_fontset (f, face, font_name, fontset) 1079 load_face_font (f, face, c)
1120 struct frame *f; 1080 struct frame *f;
1121 struct face *face; 1081 struct face *face;
1122 char *font_name; 1082 int c;
1123 int fontset;
1124 { 1083 {
1125 struct font_info *font_info = NULL; 1084 struct font_info *font_info = NULL;
1126 1085 char *font_name;
1086
1127 face->font_info_id = -1; 1087 face->font_info_id = -1;
1128 face->fontset = fontset;
1129 face->font = NULL; 1088 face->font = NULL;
1130 1089
1090 font_name = choose_face_font (f, face->lface, face->fontset, c);
1091 if (!font_name)
1092 return;
1093
1131 BLOCK_INPUT; 1094 BLOCK_INPUT;
1132 if (fontset >= 0) 1095 font_info = FS_LOAD_FACE_FONT (f, c, font_name, face);
1133 font_info = FS_LOAD_FONT (f, FRAME_X_FONT_TABLE (f), CHARSET_ASCII,
1134 NULL, fontset);
1135 else if (font_name)
1136 font_info = FS_LOAD_FONT (f, FRAME_X_FONT_TABLE (f), face->charset,
1137 font_name, -1);
1138 UNBLOCK_INPUT; 1096 UNBLOCK_INPUT;
1139 1097
1140 if (font_info) 1098 if (font_info)
1141 { 1099 {
1142 char *s; 1100 face->font_info_id = font_info->font_idx;
1143 int i;
1144
1145 face->font_info_id = FONT_INFO_ID (f, font_info);
1146 face->font = font_info->font; 1101 face->font = font_info->font;
1147 face->font_name = font_info->full_name; 1102 face->font_name = font_info->full_name;
1148 1103 if (face->gc)
1149 /* Make the registry part of the font name readily accessible.
1150 The registry is used to find suitable faces for unibyte text. */
1151 s = font_info->full_name + strlen (font_info->full_name);
1152 i = 0;
1153 while (i < 2 && --s >= font_info->full_name)
1154 if (*s == '-')
1155 ++i;
1156
1157 if (!STRINGP (face->registry)
1158 || xstricmp (XSTRING (face->registry)->data, s + 1) != 0)
1159 { 1104 {
1160 if (STRINGP (Vface_default_registry) 1105 x_free_gc (f, face->gc);
1161 && !xstricmp (XSTRING (Vface_default_registry)->data, s + 1)) 1106 face->gc = 0;
1162 face->registry = Vface_default_registry;
1163 else
1164 face->registry = build_string (s + 1);
1165 } 1107 }
1166 } 1108 }
1167 else if (fontset >= 0) 1109 else
1168 add_to_log ("Unable to load ASCII font of fontset %d",
1169 make_number (fontset), Qnil);
1170 else if (font_name)
1171 add_to_log ("Unable to load font %s", 1110 add_to_log ("Unable to load font %s",
1172 build_string (font_name), Qnil); 1111 build_string (font_name), Qnil);
1112 xfree (font_name);
1173 } 1113 }
1174 1114
1175 #endif /* HAVE_WINDOW_SYSTEM */ 1115 #endif /* HAVE_WINDOW_SYSTEM */
1176 1116
1177 1117
2022 1962
2023 return real_pt; 1963 return real_pt;
2024 } 1964 }
2025 1965
2026 1966
1967 /* Return point size of PIXEL dots while considering Y-resultion (DPI)
1968 of frame F. This function is used to guess a point size of font
1969 when only the pixel height of the font is available. */
1970
1971 static INLINE int
1972 pixel_point_size (f, pixel)
1973 struct frame *f;
1974 int pixel;
1975 {
1976 double resy = FRAME_X_DISPLAY_INFO (f)->resy;
1977 double real_pt;
1978 int int_pt;
1979
1980 /* As one inch is 72 points, 72/RESY gives the point size of one dot. */
1981 real_pt = pixel * 72 / resy;
1982 int_pt = real_pt + 0.5;
1983
1984 return int_pt;
1985 }
1986
1987
2027 /* Split XLFD font name FONT->name destructively into NUL-terminated, 1988 /* Split XLFD font name FONT->name destructively into NUL-terminated,
2028 lower-case fields in FONT->fields. NUMERIC_P non-zero means 1989 lower-case fields in FONT->fields. NUMERIC_P non-zero means
2029 compute numeric values for fields XLFD_POINT_SIZE, XLFD_SWIDTH, 1990 compute numeric values for fields XLFD_POINT_SIZE, XLFD_SWIDTH,
2030 XLFD_RESY, XLFD_SLANT, and XLFD_WEIGHT in FONT->numeric. Value is 1991 XLFD_RESY, XLFD_SLANT, and XLFD_WEIGHT in FONT->numeric. Value is
2031 zero if the font name doesn't have the format we expect. The 1992 zero if the font name doesn't have the format we expect. The
2408 return cmp; 2369 return cmp;
2409 } 2370 }
2410 2371
2411 2372
2412 /* Get a sorted list of fonts of family FAMILY on frame F. If PATTERN 2373 /* Get a sorted list of fonts of family FAMILY on frame F. If PATTERN
2413 is non-null list fonts matching that pattern. Otherwise, if 2374 is non-nil list fonts matching that pattern. Otherwise, if
2414 REGISTRY_AND_ENCODING is non-null return only fonts with that 2375 REGISTRY is non-nil return only fonts with that registry, otherwise
2415 registry and encoding, otherwise return fonts of any registry and 2376 return fonts of any registry. Set *FONTS to a vector of font_name
2416 encoding. Set *FONTS to a vector of font_name structures allocated 2377 structures allocated from the heap containing the fonts found.
2417 from the heap containing the fonts found. Value is the number of 2378 Value is the number of fonts found. */
2418 fonts found. */
2419 2379
2420 static int 2380 static int
2421 font_list (f, pattern, family, registry_and_encoding, fonts) 2381 font_list (f, pattern, family, registry, fonts)
2422 struct frame *f; 2382 struct frame *f;
2423 char *pattern; 2383 Lisp_Object pattern, family, registry;
2424 char *family;
2425 char *registry_and_encoding;
2426 struct font_name **fonts; 2384 struct font_name **fonts;
2427 { 2385 {
2428 if (pattern == NULL) 2386 char *pattern_str, *family_str, *registry_str;
2429 { 2387
2430 if (family == NULL) 2388 if (NILP (pattern))
2431 family = "*"; 2389 {
2390 family_str = (NILP (family) ? "*" : (char *) XSTRING (family)->data);
2391 registry_str = (NILP (registry) ? "*" : (char *) XSTRING (registry)->data);
2432 2392
2433 if (registry_and_encoding == NULL) 2393 pattern_str = (char *) alloca (strlen (family_str)
2434 registry_and_encoding = "*"; 2394 + strlen (registry_str)
2435
2436 pattern = (char *) alloca (strlen (family)
2437 + strlen (registry_and_encoding)
2438 + 10); 2395 + 10);
2439 if (index (family, '-')) 2396 if (index (family_str, '-'))
2440 sprintf (pattern, "-%s-*-%s", family, registry_and_encoding); 2397 sprintf (pattern_str, "-%s-*-%s", family_str, registry_str);
2441 else 2398 else
2442 sprintf (pattern, "-*-%s-*-%s", family, registry_and_encoding); 2399 sprintf (pattern_str, "-*-%s-*-%s", family_str, registry_str);
2443 } 2400 }
2444 2401 else
2445 return sorted_font_list (f, pattern, cmp_font_names, fonts); 2402 pattern_str = (char *) XSTRING (pattern)->data;
2403
2404 return sorted_font_list (f, pattern_str, cmp_font_names, fonts);
2446 } 2405 }
2447 2406
2448 2407
2449 /* Remove elements from LIST whose cars are `equal'. Called from 2408 /* Remove elements from LIST whose cars are `equal'. Called from
2450 x-family-fonts and x-font-family-list to remove duplicate font 2409 x-family-fonts and x-font-family-list to remove duplicate font
2489 struct frame *f = check_x_frame (frame); 2448 struct frame *f = check_x_frame (frame);
2490 struct font_name *fonts; 2449 struct font_name *fonts;
2491 int i, nfonts; 2450 int i, nfonts;
2492 Lisp_Object result; 2451 Lisp_Object result;
2493 struct gcpro gcpro1; 2452 struct gcpro gcpro1;
2494 char *family_pattern; 2453
2495 2454 if (!NILP (family))
2496 if (NILP (family)) 2455 CHECK_STRING (family, 1);
2497 family_pattern = "*";
2498 else
2499 {
2500 CHECK_STRING (family, 1);
2501 family_pattern = LSTRDUPA (family);
2502 }
2503 2456
2504 result = Qnil; 2457 result = Qnil;
2505 GCPRO1 (result); 2458 GCPRO1 (result);
2506 nfonts = font_list (f, NULL, family_pattern, NULL, &fonts); 2459 nfonts = font_list (f, Qnil, family, Qnil, &fonts);
2507 for (i = nfonts - 1; i >= 0; --i) 2460 for (i = nfonts - 1; i >= 0; --i)
2508 { 2461 {
2509 Lisp_Object v = Fmake_vector (make_number (8), Qnil); 2462 Lisp_Object v = Fmake_vector (make_number (8), Qnil);
2510 char *tem; 2463 char *tem;
2511 2464
2557 /* Let's consider all fonts. Increase the limit for matching 2510 /* Let's consider all fonts. Increase the limit for matching
2558 fonts until we have them all. */ 2511 fonts until we have them all. */
2559 for (limit = 500;;) 2512 for (limit = 500;;)
2560 { 2513 {
2561 specbind (intern ("font-list-limit"), make_number (limit)); 2514 specbind (intern ("font-list-limit"), make_number (limit));
2562 nfonts = font_list (f, NULL, "*", NULL, &fonts); 2515 nfonts = font_list (f, Qnil, Qnil, Qnil, &fonts);
2563 2516
2564 if (nfonts == limit) 2517 if (nfonts == limit)
2565 { 2518 {
2566 free_font_names (fonts, nfonts); 2519 free_font_names (fonts, nfonts);
2567 limit *= 2; 2520 limit *= 2;
2641 size = 0; 2594 size = 0;
2642 else 2595 else
2643 { 2596 {
2644 /* This is of limited utility since it works with character 2597 /* This is of limited utility since it works with character
2645 widths. Keep it for compatibility. --gerd. */ 2598 widths. Keep it for compatibility. --gerd. */
2646 int face_id = lookup_named_face (f, face, CHARSET_ASCII); 2599 int face_id = lookup_named_face (f, face, 0);
2647 struct face *face = FACE_FROM_ID (f, face_id); 2600 struct face *face = FACE_FROM_ID (f, face_id);
2648 2601
2649 if (face->font) 2602 if (face->font)
2650 size = FONT_WIDTH (face->font); 2603 size = FONT_WIDTH (face->font);
2651 else 2604 else
2701 XVECTOR (LFACE)->contents[LFACE_OVERLINE_INDEX] 2654 XVECTOR (LFACE)->contents[LFACE_OVERLINE_INDEX]
2702 #define LFACE_STRIKE_THROUGH(LFACE) \ 2655 #define LFACE_STRIKE_THROUGH(LFACE) \
2703 XVECTOR (LFACE)->contents[LFACE_STRIKE_THROUGH_INDEX] 2656 XVECTOR (LFACE)->contents[LFACE_STRIKE_THROUGH_INDEX]
2704 #define LFACE_BOX(LFACE) \ 2657 #define LFACE_BOX(LFACE) \
2705 XVECTOR (LFACE)->contents[LFACE_BOX_INDEX] 2658 XVECTOR (LFACE)->contents[LFACE_BOX_INDEX]
2659 #define LFACE_FONT(LFACE) \
2660 XVECTOR (LFACE)->contents[LFACE_FONT_INDEX]
2706 2661
2707 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size 2662 /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size
2708 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */ 2663 LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */
2709 2664
2710 #define LFACEP(LFACE) \ 2665 #define LFACEP(LFACE) \
2753 || STRINGP (attrs[LFACE_BACKGROUND_INDEX])); 2708 || STRINGP (attrs[LFACE_BACKGROUND_INDEX]));
2754 #ifdef HAVE_WINDOW_SYSTEM 2709 #ifdef HAVE_WINDOW_SYSTEM
2755 xassert (UNSPECIFIEDP (attrs[LFACE_STIPPLE_INDEX]) 2710 xassert (UNSPECIFIEDP (attrs[LFACE_STIPPLE_INDEX])
2756 || SYMBOLP (attrs[LFACE_STIPPLE_INDEX]) 2711 || SYMBOLP (attrs[LFACE_STIPPLE_INDEX])
2757 || !NILP (Fbitmap_spec_p (attrs[LFACE_STIPPLE_INDEX]))); 2712 || !NILP (Fbitmap_spec_p (attrs[LFACE_STIPPLE_INDEX])));
2713 xassert (UNSPECIFIEDP (attrs[LFACE_FONT_INDEX])
2714 || NILP (attr[LFACE_FONT_INDEX]));
2715 || STRINGP (attr[LFACE_FONT_INDEX]));
2758 #endif 2716 #endif
2759 } 2717 }
2760 2718
2761 2719
2762 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */ 2720 /* Check consistency of attributes of Lisp face LFACE (a Lisp vector). */
2778 #define check_lface(lface) (void) 0 2736 #define check_lface(lface) (void) 0
2779 2737
2780 #endif /* GLYPH_DEBUG == 0 */ 2738 #endif /* GLYPH_DEBUG == 0 */
2781 2739
2782 2740
2783 /* Resolve face name FACE_NAME. If FACE_NAME Is a string, intern it 2741 /* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
2784 to make it a symvol. If FACE_NAME is an alias for another face, 2742 to make it a symvol. If FACE_NAME is an alias for another face,
2785 return that face's name. */ 2743 return that face's name. */
2786 2744
2787 static Lisp_Object 2745 static Lisp_Object
2788 resolve_face_name (face_name) 2746 resolve_face_name (face_name)
2886 return i == LFACE_VECTOR_SIZE; 2844 return i == LFACE_VECTOR_SIZE;
2887 } 2845 }
2888 2846
2889 #ifdef HAVE_WINDOW_SYSTEM 2847 #ifdef HAVE_WINDOW_SYSTEM
2890 2848
2891 /* Set font-related attributes of Lisp face LFACE from XLFD font name 2849 /* Set font-related attributes of Lisp face LFACE from the fullname of
2892 FONT_NAME. If FORCE_P is zero, set only unspecified attributes of 2850 the font opened by FONTNAME. If FORCE_P is zero, set only
2893 LFACE. MAY_FAIL_P non-zero means return 0 if FONT_NAME isn't a 2851 unspecified attributes of LFACE. The exception is `font'
2894 valid font name; otherwise this function tries to use a reasonable 2852 attribute. It is set to FONTNAME as is regardless of FORCE_P.
2895 default font. 2853
2896 2854 If FONTNAME is not available on frame F,
2897 Ignore fields of FONT_NAME containing wildcards. Value is zero if 2855 return 0 if MAY_FAIL_P is non-zero, otherwise abort.
2898 not successful because FONT_NAME was not in a valid format and 2856 If the fullname is not in a valid XLFD format,
2899 MAY_FAIL_P was non-zero. A valid format is one that is suitable 2857 return 0 if MAY_FAIL_P is non-zero, otherwise set normal values
2900 for split_font_name, see the comment there. */ 2858 in LFACE and return 1.
2859 Otherwise, return 1. */
2901 2860
2902 static int 2861 static int
2903 set_lface_from_font_name (f, lface, font_name, force_p, may_fail_p) 2862 set_lface_from_font_name (f, lface, fontname, force_p, may_fail_p)
2904 struct frame *f; 2863 struct frame *f;
2905 Lisp_Object lface; 2864 Lisp_Object lface;
2906 char *font_name; 2865 Lisp_Object fontname;
2907 int force_p, may_fail_p; 2866 int force_p, may_fail_p;
2908 { 2867 {
2909 struct font_name font; 2868 struct font_name font;
2910 char *buffer; 2869 char *buffer;
2911 int pt; 2870 int pt;
2912 int free_font_name_p = 0; 2871 int have_xlfd_p;
2913 int have_font_p = 0; 2872 int fontset;
2914 2873 char *font_name = XSTRING (fontname)->data;
2915 /* If FONT_NAME contains wildcards, use the first matching font. */ 2874 struct font_info *font_info;
2916 if (index (font_name, '*') || index (font_name, '?')) 2875
2917 { 2876 /* If FONTNAME is actually a fontset name, get ASCII font name of it. */
2918 if (first_font_matching (f, font_name, &font)) 2877 fontset = fs_query_fontset (fontname, 0);
2919 free_font_name_p = have_font_p = 1; 2878 if (fontset >= 0)
2920 } 2879 font_name = XSTRING (fontset_ascii (fontset))->data;
2921 else 2880
2922 { 2881 /* Check if FONT_NAME is surely available on the system. Usually
2923 font.name = STRDUPA (font_name); 2882 FONT_NAME is already cached for the frame F and FS_LOAD_FONT
2924 if (split_font_name (f, &font, 1)) 2883 returns quickly. But, even if FONT_NAME is not yet cached,
2925 have_font_p = 1; 2884 caching it now is not futail because we anyway load the font
2926 else 2885 later. */
2927 { 2886 BLOCK_INPUT;
2928 /* The font name may be something like `6x13'. Make 2887 font_info = FS_LOAD_FONT (f, 0, font_name, -1);
2929 sure we use the full name. */ 2888 UNBLOCK_INPUT;
2930 struct font_info *font_info; 2889
2931 2890 if (!font_info)
2932 BLOCK_INPUT;
2933 font_info = fs_load_font (f, FRAME_X_FONT_TABLE (f),
2934 CHARSET_ASCII, font_name, -1);
2935 if (font_info)
2936 {
2937 font.name = STRDUPA (font_info->full_name);
2938 split_font_name (f, &font, 1);
2939 have_font_p = 1;
2940 }
2941 UNBLOCK_INPUT;
2942 }
2943 }
2944
2945 /* If FONT_NAME is completely bogus try to use something reasonable
2946 if this function must succeed. Otherwise, give up. */
2947 if (!have_font_p)
2948 { 2891 {
2949 if (may_fail_p) 2892 if (may_fail_p)
2950 return 0; 2893 return 0;
2951 #ifdef HAVE_X_WINDOWS 2894 abort ();
2952 else if (first_font_matching (f, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1", 2895 }
2953 &font) 2896
2954 || first_font_matching (f, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1", 2897 font.name = STRDUPA (font_info->full_name);
2955 &font) 2898 have_xlfd_p = split_font_name (f, &font, 1);
2956 || first_font_matching (f, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1", 2899
2957 &font) 2900 /* Set attributes only if unspecified, otherwise face defaults for
2958 || first_font_matching (f, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1", 2901 new frames would never take effect. If we couldn't get a font
2959 &font) 2902 name conforming to XLFD, set normal values. */
2960 || first_font_matching (f, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1", 2903
2961 &font) 2904 if (force_p || UNSPECIFIEDP (LFACE_FAMILY (lface)))
2962 || first_font_matching (f, "fixed", &font)) 2905 {
2963 #endif 2906 Lisp_Object val;
2964 #ifdef WINDOWSNT 2907 if (have_xlfd_p)
2965 else if (first_font_matching (f, "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-iso8859-1", 2908 {
2966 &font) 2909 buffer = (char *) alloca (strlen (font.fields[XLFD_FAMILY])
2967 || first_font_matching (f, "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1", 2910 + strlen (font.fields[XLFD_FOUNDRY])
2968 &font) 2911 + 2);
2969 || first_font_matching (f, "-*-FixedSys-normal-r-*-*-12-*-*-*-c-*-iso8859-1", 2912 sprintf (buffer, "%s-%s", font.fields[XLFD_FOUNDRY],
2970 &font) 2913 font.fields[XLFD_FAMILY]);
2971 || first_font_matching (f, "-*-*-normal-r-*-*-*-*-*-*-c-*-iso8859-1", 2914 val = build_string (buffer);
2972 &font) 2915 }
2973 || first_font_matching (f, "FixedSys",
2974 &font))
2975 #endif
2976 free_font_name_p = 1;
2977 else 2916 else
2978 abort (); 2917 val = build_string ("*");
2979 } 2918 LFACE_FAMILY (lface) = val;
2980
2981
2982 /* Set attributes only if unspecified, otherwise face defaults for
2983 new frames would never take effect. */
2984
2985 if (force_p || UNSPECIFIEDP (LFACE_FAMILY (lface)))
2986 {
2987 buffer = (char *) alloca (strlen (font.fields[XLFD_FAMILY])
2988 + strlen (font.fields[XLFD_FOUNDRY])
2989 + 2);
2990 sprintf (buffer, "%s-%s", font.fields[XLFD_FOUNDRY],
2991 font.fields[XLFD_FAMILY]);
2992 LFACE_FAMILY (lface) = build_string (buffer);
2993 } 2919 }
2994 2920
2995 if (force_p || UNSPECIFIEDP (LFACE_HEIGHT (lface))) 2921 if (force_p || UNSPECIFIEDP (LFACE_HEIGHT (lface)))
2996 { 2922 {
2997 pt = xlfd_point_size (f, &font); 2923 if (have_xlfd_p)
2924 pt = xlfd_point_size (f, &font);
2925 else
2926 pt = pixel_point_size (f, font_info->height * 10);
2998 xassert (pt > 0); 2927 xassert (pt > 0);
2999 LFACE_HEIGHT (lface) = make_number (pt); 2928 LFACE_HEIGHT (lface) = make_number (pt);
3000 } 2929 }
3001 2930
3002 if (force_p || UNSPECIFIEDP (LFACE_SWIDTH (lface))) 2931 if (force_p || UNSPECIFIEDP (LFACE_SWIDTH (lface)))
3003 LFACE_SWIDTH (lface) = xlfd_symbolic_swidth (&font); 2932 LFACE_SWIDTH (lface)
2933 = have_xlfd_p ? xlfd_symbolic_swidth (&font) : Qnormal;
3004 2934
3005 if (force_p || UNSPECIFIEDP (LFACE_WEIGHT (lface))) 2935 if (force_p || UNSPECIFIEDP (LFACE_WEIGHT (lface)))
3006 LFACE_WEIGHT (lface) = xlfd_symbolic_weight (&font); 2936 LFACE_WEIGHT (lface)
2937 = have_xlfd_p ? xlfd_symbolic_weight (&font) : Qnormal;
3007 2938
3008 if (force_p || UNSPECIFIEDP (LFACE_SLANT (lface))) 2939 if (force_p || UNSPECIFIEDP (LFACE_SLANT (lface)))
3009 LFACE_SLANT (lface) = xlfd_symbolic_slant (&font); 2940 LFACE_SLANT (lface)
3010 2941 = have_xlfd_p ? xlfd_symbolic_slant (&font) : Qnormal;
3011 if (free_font_name_p) 2942
3012 xfree (font.name); 2943 LFACE_FONT (lface) = fontname;
3013 2944
3014 return 1; 2945 return 1;
3015 } 2946 }
3016 #endif /* HAVE_WINDOW_SYSTEM */ 2947 #endif /* HAVE_WINDOW_SYSTEM */
3017 2948
3380 (face, attr, value, frame) 3311 (face, attr, value, frame)
3381 Lisp_Object face, attr, value, frame; 3312 Lisp_Object face, attr, value, frame;
3382 { 3313 {
3383 Lisp_Object lface; 3314 Lisp_Object lface;
3384 Lisp_Object old_value = Qnil; 3315 Lisp_Object old_value = Qnil;
3316 /* Set 1 if ATTR is QCfont. */
3317 int font_attr_p = 0;
3318 /* Set 1 if ATTR is one of font-related attributes other than QCfont. */
3385 int font_related_attr_p = 0; 3319 int font_related_attr_p = 0;
3386 3320
3387 CHECK_SYMBOL (face, 0); 3321 CHECK_SYMBOL (face, 0);
3388 CHECK_SYMBOL (attr, 1); 3322 CHECK_SYMBOL (attr, 1);
3389 3323
3625 { 3559 {
3626 #ifdef HAVE_WINDOW_SYSTEM 3560 #ifdef HAVE_WINDOW_SYSTEM
3627 /* Set font-related attributes of the Lisp face from an 3561 /* Set font-related attributes of the Lisp face from an
3628 XLFD font name. */ 3562 XLFD font name. */
3629 struct frame *f; 3563 struct frame *f;
3564 Lisp_Object tmp;
3630 3565
3631 CHECK_STRING (value, 3); 3566 CHECK_STRING (value, 3);
3632 if (EQ (frame, Qt)) 3567 if (EQ (frame, Qt))
3633 f = SELECTED_FRAME (); 3568 f = SELECTED_FRAME ();
3634 else 3569 else
3635 f = check_x_frame (frame); 3570 f = check_x_frame (frame);
3636 3571
3637 if (!set_lface_from_font_name (f, lface, XSTRING (value)->data, 1, 1)) 3572 /* VALUE may be a fontset name or an alias of fontset. In such
3638 signal_error ("Invalid font name", value); 3573 a case, use the base fontset name. */
3639 3574 tmp = Fquery_fontset (value, Qnil);
3640 font_related_attr_p = 1; 3575 if (!NILP (tmp))
3576 value = tmp;
3577
3578 if (!set_lface_from_font_name (f, lface, value, 1, 1))
3579 signal_error ("Invalid font or fontset name", value);
3580
3581 font_attr_p = 1;
3641 #endif /* HAVE_WINDOW_SYSTEM */ 3582 #endif /* HAVE_WINDOW_SYSTEM */
3642 } 3583 }
3643 else if (EQ (attr, QCbold)) 3584 else if (EQ (attr, QCbold))
3644 { 3585 {
3645 old_value = LFACE_WEIGHT (lface); 3586 old_value = LFACE_WEIGHT (lface);
3652 LFACE_SLANT (lface) = NILP (value) ? Qnormal : Qitalic; 3593 LFACE_SLANT (lface) = NILP (value) ? Qnormal : Qitalic;
3653 font_related_attr_p = 1; 3594 font_related_attr_p = 1;
3654 } 3595 }
3655 else 3596 else
3656 signal_error ("Invalid face attribute name", attr); 3597 signal_error ("Invalid face attribute name", attr);
3598
3599 if (font_related_attr_p
3600 && !UNSPECIFIEDP (value))
3601 /* If a font-related attribute other than QCfont is specified, the
3602 original `font' attribute nor that of default face is useless
3603 to determine a new font. Thus, we set it to nil so that font
3604 selection mechanism doesn't use it. */
3605 LFACE_FONT (lface) = Qnil;
3657 3606
3658 /* Changing a named face means that all realized faces depending on 3607 /* Changing a named face means that all realized faces depending on
3659 that face are invalid. Since we cannot tell which realized faces 3608 that face are invalid. Since we cannot tell which realized faces
3660 depend on the face, make sure they are all removed. This is done 3609 depend on the face, make sure they are all removed. This is done
3661 by incrementing face_change_count. The next call to 3610 by incrementing face_change_count. The next call to
3680 3629
3681 if (EQ (face, Qdefault)) 3630 if (EQ (face, Qdefault))
3682 { 3631 {
3683 /* Changed font-related attributes of the `default' face are 3632 /* Changed font-related attributes of the `default' face are
3684 reflected in changed `font' frame parameters. */ 3633 reflected in changed `font' frame parameters. */
3685 if (font_related_attr_p 3634 if ((font_related_attr_p || font_attr_p)
3686 && lface_fully_specified_p (XVECTOR (lface)->contents)) 3635 && lface_fully_specified_p (XVECTOR (lface)->contents))
3687 set_font_frame_param (frame, lface); 3636 set_font_frame_param (frame, lface);
3688 else if (EQ (attr, QCforeground)) 3637 else if (EQ (attr, QCforeground))
3689 param = Qforeground_color; 3638 param = Qforeground_color;
3690 else if (EQ (attr, QCbackground)) 3639 else if (EQ (attr, QCbackground))
3721 `mouse-color'. */ 3670 `mouse-color'. */
3722 if (EQ (attr, QCbackground)) 3671 if (EQ (attr, QCbackground))
3723 param = Qmouse_color; 3672 param = Qmouse_color;
3724 } 3673 }
3725 3674
3726 if (SYMBOLP (param)) 3675 if (!NILP (param))
3727 Fmodify_frame_parameters (frame, Fcons (Fcons (param, value), Qnil)); 3676 Fmodify_frame_parameters (frame, Fcons (Fcons (param, value), Qnil));
3728 } 3677 }
3729 3678
3730 #endif /* HAVE_WINDOW_SYSTEM */ 3679 #endif /* HAVE_WINDOW_SYSTEM */
3731 3680
3733 } 3682 }
3734 3683
3735 3684
3736 #ifdef HAVE_WINDOW_SYSTEM 3685 #ifdef HAVE_WINDOW_SYSTEM
3737 3686
3738 /* Set the `font' frame parameter of FRAME according to `default' face 3687 /* Set the `font' frame parameter of FRAME determined from `default'
3739 attributes LFACE. */ 3688 face attributes LFACE. If a face or fontset name is explicitely
3689 specfied in LFACE, use it as is. Otherwise, determine a font name
3690 from the other font-related atrributes of LFACE. In that case, if
3691 there's no matching font, signals an error. */
3740 3692
3741 static void 3693 static void
3742 set_font_frame_param (frame, lface) 3694 set_font_frame_param (frame, lface)
3743 Lisp_Object frame, lface; 3695 Lisp_Object frame, lface;
3744 { 3696 {
3745 struct frame *f = XFRAME (frame); 3697 struct frame *f = XFRAME (frame);
3746 Lisp_Object frame_font; 3698 Lisp_Object font_name;
3747 int fontset;
3748 char *font; 3699 char *font;
3749 3700
3750 /* Get FRAME's font parameter. */ 3701 if (STRINGP (LFACE_FONT (lface)))
3751 frame_font = Fassq (Qfont, f->param_alist); 3702 font_name = LFACE_FONT (lface);
3752 xassert (CONSP (frame_font) && STRINGP (XCDR (frame_font)));
3753 frame_font = XCDR (frame_font);
3754
3755 fontset = fs_query_fontset (f, XSTRING (frame_font)->data);
3756 if (fontset >= 0)
3757 {
3758 /* Frame parameter is a fontset name. Modify the fontset so
3759 that all its fonts reflect face attributes LFACE. */
3760 int charset;
3761 struct fontset_info *fontset_info;
3762
3763 fontset_info = FRAME_FONTSET_DATA (f)->fontset_table[fontset];
3764
3765 for (charset = 0; charset < MAX_CHARSET; ++charset)
3766 if (fontset_info->fontname[charset])
3767 {
3768 font = choose_face_fontset_font (f, XVECTOR (lface)->contents,
3769 fontset, charset);
3770 Fset_fontset_font (frame_font, CHARSET_SYMBOL (charset),
3771 build_string (font), frame);
3772 xfree (font);
3773 }
3774 }
3775 else 3703 else
3776 { 3704 {
3777 /* Frame parameter is an X font name. I believe this can 3705 /* Choose a font name that reflects LFACE's attributes and has
3778 only happen in unibyte mode. */ 3706 the registry and encoding pattern specified in the default
3779 font = choose_face_font (f, XVECTOR (lface)->contents, 3707 fontset (3rd arg: -1) for ASCII characters (4th arg: 0). */
3780 -1, Vface_default_registry); 3708 font = choose_face_font (f, XVECTOR (lface)->contents, -1, 0);
3781 if (font) 3709 if (!font)
3782 { 3710 error ("No font matches the specified attribute");
3783 store_frame_param (f, Qfont, build_string (font)); 3711 font_name = build_string (font);
3784 xfree (font); 3712 xfree (font);
3785 } 3713 }
3786 } 3714 store_frame_param (f, Qfont, font_name);
3787 } 3715 }
3788 3716
3789 3717
3790 /* Update the corresponding face when frame parameter PARAM on frame F 3718 /* Update the corresponding face when frame parameter PARAM on frame F
3791 has been assigned the value NEW_VALUE. */ 3719 has been assigned the value NEW_VALUE. */
4210 value = LFACE_BACKGROUND (lface); 4138 value = LFACE_BACKGROUND (lface);
4211 else if (EQ (keyword, QCstipple)) 4139 else if (EQ (keyword, QCstipple))
4212 value = LFACE_STIPPLE (lface); 4140 value = LFACE_STIPPLE (lface);
4213 else if (EQ (keyword, QCwidth)) 4141 else if (EQ (keyword, QCwidth))
4214 value = LFACE_SWIDTH (lface); 4142 value = LFACE_SWIDTH (lface);
4143 else if (EQ (keyword, QCfont))
4144 value = LFACE_FONT (lface);
4215 else 4145 else
4216 signal_error ("Invalid face attribute name", keyword); 4146 signal_error ("Invalid face attribute name", keyword);
4217 4147
4218 return value; 4148 return value;
4219 } 4149 }
4321 return result; 4251 return result;
4322 } 4252 }
4323 else 4253 else
4324 { 4254 {
4325 struct frame *f = frame_or_selected_frame (frame, 1); 4255 struct frame *f = frame_or_selected_frame (frame, 1);
4326 int face_id = lookup_named_face (f, face, CHARSET_ASCII); 4256 int face_id = lookup_named_face (f, face, 0);
4327 struct face *face = FACE_FROM_ID (f, face_id); 4257 struct face *face = FACE_FROM_ID (f, face_id);
4328 return build_string (face->font_name); 4258 return build_string (face->font_name);
4329 } 4259 }
4330 } 4260 }
4331 4261
4482 } 4412 }
4483 4413
4484 4414
4485 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without 4415 /* Return non-zero if LFACE1 and LFACE2 specify the same font (without
4486 considering charsets/registries). They do if they specify the same 4416 considering charsets/registries). They do if they specify the same
4487 family, point size, weight, width and slant. Both LFACE1 and 4417 family, point size, weight, width, slant, and fontset. Both LFACE1
4488 LFACE2 must be fully-specified. */ 4418 and LFACE2 must be fully-specified. */
4489 4419
4490 static INLINE int 4420 static INLINE int
4491 lface_same_font_attributes_p (lface1, lface2) 4421 lface_same_font_attributes_p (lface1, lface2)
4492 Lisp_Object *lface1, *lface2; 4422 Lisp_Object *lface1, *lface2;
4493 { 4423 {
4497 XSTRING (lface2[LFACE_FAMILY_INDEX])->data) == 0 4427 XSTRING (lface2[LFACE_FAMILY_INDEX])->data) == 0
4498 && (XFASTINT (lface1[LFACE_HEIGHT_INDEX]) 4428 && (XFASTINT (lface1[LFACE_HEIGHT_INDEX])
4499 == XFASTINT (lface2[LFACE_HEIGHT_INDEX])) 4429 == XFASTINT (lface2[LFACE_HEIGHT_INDEX]))
4500 && EQ (lface1[LFACE_SWIDTH_INDEX], lface2[LFACE_SWIDTH_INDEX]) 4430 && EQ (lface1[LFACE_SWIDTH_INDEX], lface2[LFACE_SWIDTH_INDEX])
4501 && EQ (lface1[LFACE_WEIGHT_INDEX], lface2[LFACE_WEIGHT_INDEX]) 4431 && EQ (lface1[LFACE_WEIGHT_INDEX], lface2[LFACE_WEIGHT_INDEX])
4502 && EQ (lface1[LFACE_SLANT_INDEX], lface2[LFACE_SLANT_INDEX])); 4432 && EQ (lface1[LFACE_SLANT_INDEX], lface2[LFACE_SLANT_INDEX])
4433 && (EQ (lface1[LFACE_FONT_INDEX], lface2[LFACE_FONT_INDEX])
4434 || (STRINGP (lface1[LFACE_FONT_INDEX])
4435 && xstricmp (XSTRING (lface1[LFACE_FONT_INDEX])->data,
4436 XSTRING (lface2[LFACE_FONT_INDEX])->data))));
4503 } 4437 }
4504 4438
4505 4439
4506 4440
4507 /*********************************************************************** 4441 /***********************************************************************
4508 Realized Faces 4442 Realized Faces
4509 ***********************************************************************/ 4443 ***********************************************************************/
4510 4444
4511 /* Allocate and return a new realized face for Lisp face attribute 4445 /* Allocate and return a new realized face for Lisp face attribute
4512 vector ATTR, charset CHARSET, and registry REGISTRY. */ 4446 vector ATTR. */
4513 4447
4514 static struct face * 4448 static struct face *
4515 make_realized_face (attr, charset, registry) 4449 make_realized_face (attr)
4516 Lisp_Object *attr; 4450 Lisp_Object *attr;
4517 int charset;
4518 Lisp_Object registry;
4519 { 4451 {
4520 struct face *face = (struct face *) xmalloc (sizeof *face); 4452 struct face *face = (struct face *) xmalloc (sizeof *face);
4521 bzero (face, sizeof *face); 4453 bzero (face, sizeof *face);
4522 face->charset = charset; 4454 face->ascii_face = face;
4523 face->registry = registry;
4524 bcopy (attr, face->lface, sizeof face->lface); 4455 bcopy (attr, face->lface, sizeof face->lface);
4525 return face; 4456 return face;
4526 } 4457 }
4527 4458
4528 4459
4537 if (face) 4468 if (face)
4538 { 4469 {
4539 #ifdef HAVE_WINDOW_SYSTEM 4470 #ifdef HAVE_WINDOW_SYSTEM
4540 if (FRAME_WINDOW_P (f)) 4471 if (FRAME_WINDOW_P (f))
4541 { 4472 {
4473 /* Free fontset of FACE if it is ASCII face. */
4474 if (face->fontset >= 0 && face == face->ascii_face)
4475 free_face_fontset (f, face);
4542 if (face->gc) 4476 if (face->gc)
4543 { 4477 {
4544 x_free_gc (f, face->gc); 4478 x_free_gc (f, face->gc);
4545 face->gc = 0; 4479 face->gc = 0;
4546 } 4480 }
4602 UNBLOCK_INPUT; 4536 UNBLOCK_INPUT;
4603 } 4537 }
4604 #endif /* HAVE_WINDOW_SYSTEM */ 4538 #endif /* HAVE_WINDOW_SYSTEM */
4605 } 4539 }
4606 4540
4607
4608 /* Non-zero if FACE is suitable for displaying ISO8859-1. Used in
4609 macro FACE_SUITABLE_FOR_CHARSET_P to avoid realizing a new face for
4610 ISO8859-1 if the ASCII face suffices. */
4611
4612 int
4613 face_suitable_for_iso8859_1_p (face)
4614 struct face *face;
4615 {
4616 int len = strlen (face->font_name);
4617 return len >= 9 && xstricmp (face->font_name + len - 9, "iso8859-1") == 0;
4618 }
4619
4620
4621 /* Value is non-zero if FACE is suitable for displaying characters
4622 of CHARSET. CHARSET < 0 means unibyte text. */
4623
4624 INLINE int
4625 face_suitable_for_charset_p (face, charset)
4626 struct face *face;
4627 int charset;
4628 {
4629 int suitable_p = 0;
4630
4631 if (charset < 0)
4632 {
4633 if (EQ (face->registry, Vface_default_registry)
4634 || !NILP (Fequal (face->registry, Vface_default_registry)))
4635 suitable_p = 1;
4636 }
4637 else if (face->charset == charset)
4638 suitable_p = 1;
4639 else if (face->charset == CHARSET_ASCII
4640 && charset == charset_latin_iso8859_1)
4641 suitable_p = face_suitable_for_iso8859_1_p (face);
4642 else if (face->charset == charset_latin_iso8859_1
4643 && charset == CHARSET_ASCII)
4644 suitable_p = 1;
4645
4646 return suitable_p;
4647 }
4648
4649
4650 4541
4651 /*********************************************************************** 4542 /***********************************************************************
4652 Face Cache 4543 Face Cache
4653 ***********************************************************************/ 4544 ***********************************************************************/
4654 4545
4734 } 4625 }
4735 } 4626 }
4736 } 4627 }
4737 4628
4738 4629
4630 /* Free all faces realized for multibyte characters on frame F that
4631 has FONTSET. */
4632
4633 void
4634 free_realized_multibyte_face (f, fontset)
4635 struct frame *f;
4636 int fontset;
4637 {
4638 struct face_cache *cache = FRAME_FACE_CACHE (f);
4639 struct face *face;
4640 int i;
4641
4642 for (i = 0; i < cache->used; i++)
4643 {
4644 face = cache->faces_by_id[i];
4645 if (face
4646 && face != face->ascii_face
4647 && face->fontset == fontset)
4648 {
4649 uncache_face (cache, face);
4650 free_realized_face (f, face);
4651 }
4652 }
4653 if (WINDOWP (f->root_window))
4654 {
4655 clear_current_matrices (f);
4656 ++windows_or_buffers_changed;
4657 }
4658 }
4659
4660
4739 /* Free all realized faces on FRAME or on all frames if FRAME is nil. 4661 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
4740 This is done after attributes of a named face have been changed, 4662 This is done after attributes of a named face have been changed,
4741 because we can't tell which realized faces depend on that face. */ 4663 because we can't tell which realized faces depend on that face. */
4742 4664
4743 void 4665 void
4772 4694
4773 4695
4774 /* Cache realized face FACE in face cache C. HASH is the hash value 4696 /* Cache realized face FACE in face cache C. HASH is the hash value
4775 of FACE. If FACE->fontset >= 0, add the new face to the end of the 4697 of FACE. If FACE->fontset >= 0, add the new face to the end of the
4776 collision list of the face hash table of C. This is done because 4698 collision list of the face hash table of C. This is done because
4777 otherwise lookup_face would find FACE for every charset, even if 4699 otherwise lookup_face would find FACE for every character, even if
4778 faces with the same attributes but for specific charsets exist. */ 4700 faces with the same attributes but for specific characters exist. */
4779 4701
4780 static void 4702 static void
4781 cache_face (c, face, hash) 4703 cache_face (c, face, hash)
4782 struct face_cache *c; 4704 struct face_cache *c;
4783 struct face *face; 4705 struct face *face;
4872 --c->used; 4794 --c->used;
4873 } 4795 }
4874 4796
4875 4797
4876 /* Look up a realized face with face attributes ATTR in the face cache 4798 /* Look up a realized face with face attributes ATTR in the face cache
4877 of frame F. The face will be used to display characters of 4799 of frame F. The face will be used to display character C. Value
4878 CHARSET. CHARSET < 0 means the face will be used to display 4800 is the ID of the face found. If no suitable face is found, realize
4879 unibyte text. The value of face-default-registry is used to choose 4801 a new one. In that case, if C is a multibyte character, BASE_FACE
4880 a font for the face in that case. Value is the ID of the face 4802 is a face for ASCII characters that has the same attributes. */
4881 found. If no suitable face is found, realize a new one. */
4882 4803
4883 INLINE int 4804 INLINE int
4884 lookup_face (f, attr, charset) 4805 lookup_face (f, attr, c, base_face)
4885 struct frame *f; 4806 struct frame *f;
4886 Lisp_Object *attr; 4807 Lisp_Object *attr;
4887 int charset; 4808 int c;
4888 { 4809 struct face *base_face;
4889 struct face_cache *c = FRAME_FACE_CACHE (f); 4810 {
4811 struct face_cache *cache = FRAME_FACE_CACHE (f);
4890 unsigned hash; 4812 unsigned hash;
4891 int i; 4813 int i;
4892 struct face *face; 4814 struct face *face;
4893 4815
4894 xassert (c != NULL); 4816 xassert (cache != NULL);
4895 check_lface_attrs (attr); 4817 check_lface_attrs (attr);
4896 4818
4897 /* Look up ATTR in the face cache. */ 4819 /* Look up ATTR in the face cache. */
4898 hash = lface_hash (attr); 4820 hash = lface_hash (attr);
4899 i = hash % FACE_CACHE_BUCKETS_SIZE; 4821 i = hash % FACE_CACHE_BUCKETS_SIZE;
4900 4822
4901 for (face = c->buckets[i]; face; face = face->next) 4823 for (face = cache->buckets[i]; face; face = face->next)
4902 if (face->hash == hash 4824 if (face->hash == hash
4903 && (!FRAME_WINDOW_P (f) 4825 && (!FRAME_WINDOW_P (f)
4904 || FACE_SUITABLE_FOR_CHARSET_P (face, charset)) 4826 || FACE_SUITABLE_FOR_CHAR_P (face, c))
4905 && lface_equal_p (face->lface, attr)) 4827 && lface_equal_p (face->lface, attr))
4906 break; 4828 break;
4907 4829
4908 /* If not found, realize a new face. */ 4830 /* If not found, realize a new face. */
4909 if (face == NULL) 4831 if (face == NULL)
4910 { 4832 face = realize_face (cache, attr, c, base_face, -1);
4911 face = realize_face (c, attr, charset);
4912 cache_face (c, face, hash);
4913 }
4914 4833
4915 #if GLYPH_DEBUG 4834 #if GLYPH_DEBUG
4916 xassert (face == FACE_FROM_ID (f, face->id)); 4835 xassert (face == FACE_FROM_ID (f, face->id));
4917 if (FRAME_WINDOW_P (f)) 4836 if (FRAME_WINDOW_P (f))
4918 xassert (charset < 0 || FACE_SUITABLE_FOR_CHARSET_P (face, charset)); 4837 xassert (FACE_SUITABLE_FOR_CHAR_P (face, c));
4919 #endif /* GLYPH_DEBUG */ 4838 #endif /* GLYPH_DEBUG */
4920 4839
4921 return face->id; 4840 return face->id;
4922 } 4841 }
4923 4842
4924 4843
4925 /* Return the face id of the realized face for named face SYMBOL on 4844 /* Return the face id of the realized face for named face SYMBOL on
4926 frame F suitable for displaying characters from CHARSET. CHARSET < 4845 frame F suitable for displaying character C. */
4927 0 means unibyte text. */
4928 4846
4929 int 4847 int
4930 lookup_named_face (f, symbol, charset) 4848 lookup_named_face (f, symbol, c)
4931 struct frame *f; 4849 struct frame *f;
4932 Lisp_Object symbol; 4850 Lisp_Object symbol;
4933 int charset; 4851 int c;
4934 { 4852 {
4935 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 4853 Lisp_Object attrs[LFACE_VECTOR_SIZE];
4936 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE]; 4854 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE];
4937 struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); 4855 struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
4938 4856
4939 get_lface_attributes (f, symbol, symbol_attrs, 1); 4857 get_lface_attributes (f, symbol, symbol_attrs, 1);
4940 bcopy (default_face->lface, attrs, sizeof attrs); 4858 bcopy (default_face->lface, attrs, sizeof attrs);
4941 merge_face_vectors (symbol_attrs, attrs); 4859 merge_face_vectors (symbol_attrs, attrs);
4942 return lookup_face (f, attrs, charset); 4860 return lookup_face (f, attrs, c, NULL);
4943 } 4861 }
4944 4862
4945 4863
4946 /* Return the ID of the realized ASCII face of Lisp face with ID 4864 /* Return the ID of the realized ASCII face of Lisp face with ID
4947 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */ 4865 LFACE_ID on frame F. Value is -1 if LFACE_ID isn't valid. */
4954 int face_id; 4872 int face_id;
4955 4873
4956 if (lface_id >= 0 && lface_id < lface_id_to_name_size) 4874 if (lface_id >= 0 && lface_id < lface_id_to_name_size)
4957 { 4875 {
4958 Lisp_Object face_name = lface_id_to_name[lface_id]; 4876 Lisp_Object face_name = lface_id_to_name[lface_id];
4959 face_id = lookup_named_face (f, face_name, CHARSET_ASCII); 4877 face_id = lookup_named_face (f, face_name, 0);
4960 } 4878 }
4961 else 4879 else
4962 face_id = -1; 4880 face_id = -1;
4963 4881
4964 return face_id; 4882 return face_id;
4971 4889
4972 int 4890 int
4973 smaller_face (f, face_id, steps) 4891 smaller_face (f, face_id, steps)
4974 struct frame *f; 4892 struct frame *f;
4975 int face_id, steps; 4893 int face_id, steps;
4976 { 4894 {
4977 #ifdef HAVE_WINDOW_SYSTEM 4895 #ifdef HAVE_WINDOW_SYSTEM
4978 struct face *face; 4896 struct face *face;
4979 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 4897 Lisp_Object attrs[LFACE_VECTOR_SIZE];
4980 int pt, last_pt, last_height; 4898 int pt, last_pt, last_height;
4981 int delta; 4899 int delta;
5002 && abs (last_pt - pt) < 100) 4920 && abs (last_pt - pt) < 100)
5003 { 4921 {
5004 /* Look up a face for a slightly smaller/larger font. */ 4922 /* Look up a face for a slightly smaller/larger font. */
5005 pt += delta; 4923 pt += delta;
5006 attrs[LFACE_HEIGHT_INDEX] = make_number (pt); 4924 attrs[LFACE_HEIGHT_INDEX] = make_number (pt);
5007 new_face_id = lookup_face (f, attrs, CHARSET_ASCII); 4925 new_face_id = lookup_face (f, attrs, 0, NULL);
5008 new_face = FACE_FROM_ID (f, new_face_id); 4926 new_face = FACE_FROM_ID (f, new_face_id);
5009 4927
5010 /* If height changes, count that as one step. */ 4928 /* If height changes, count that as one step. */
5011 if (FONT_HEIGHT (new_face->font) != last_height) 4929 if (FONT_HEIGHT (new_face->font) != last_height)
5012 { 4930 {
5044 return face_id; 4962 return face_id;
5045 4963
5046 face = FACE_FROM_ID (f, face_id); 4964 face = FACE_FROM_ID (f, face_id);
5047 bcopy (face->lface, attrs, sizeof attrs); 4965 bcopy (face->lface, attrs, sizeof attrs);
5048 attrs[LFACE_HEIGHT_INDEX] = make_number (height); 4966 attrs[LFACE_HEIGHT_INDEX] = make_number (height);
5049 face_id = lookup_face (f, attrs, CHARSET_ASCII); 4967 face_id = lookup_face (f, attrs, 0, NULL);
5050 #endif /* HAVE_WINDOW_SYSTEM */ 4968 #endif /* HAVE_WINDOW_SYSTEM */
5051 4969
5052 return face_id; 4970 return face_id;
5053 } 4971 }
5054 4972
5055 /* Return the face id of the realized face for named face SYMBOL on 4973 /* Return the face id of the realized face for named face SYMBOL on
5056 frame F suitable for displaying characters from CHARSET (CHARSET < 4974 frame F suitable for displaying character C, and use attributes of
5057 0 means unibyte text), and use attributes of the face FACE_ID for 4975 the face FACE_ID for attributes that aren't completely specified by
5058 attributes that aren't completely specified by SYMBOL. This is 4976 SYMBOL. This is like lookup_named_face, except that the default
5059 like lookup_named_face, except that the default attributes come 4977 attributes come from FACE_ID, not from the default face. FACE_ID
5060 from FACE_ID, not from the default face. FACE_ID is assumed to 4978 is assumed to be already realized. */
5061 be already realized. */
5062 4979
5063 int 4980 int
5064 lookup_derived_face (f, symbol, charset, face_id) 4981 lookup_derived_face (f, symbol, c, face_id)
5065 struct frame *f; 4982 struct frame *f;
5066 Lisp_Object symbol; 4983 Lisp_Object symbol;
5067 int charset; 4984 int c;
5068 int face_id; 4985 int face_id;
5069 { 4986 {
5070 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 4987 Lisp_Object attrs[LFACE_VECTOR_SIZE];
5071 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE]; 4988 Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE];
5072 struct face *default_face = FACE_FROM_ID (f, face_id); 4989 struct face *default_face = FACE_FROM_ID (f, face_id);
5075 abort (); 4992 abort ();
5076 4993
5077 get_lface_attributes (f, symbol, symbol_attrs, 1); 4994 get_lface_attributes (f, symbol, symbol_attrs, 1);
5078 bcopy (default_face->lface, attrs, sizeof attrs); 4995 bcopy (default_face->lface, attrs, sizeof attrs);
5079 merge_face_vectors (symbol_attrs, attrs); 4996 merge_face_vectors (symbol_attrs, attrs);
5080 return lookup_face (f, attrs, charset); 4997 return lookup_face (f, attrs, c, default_face);
5081 } 4998 }
5082 4999
5083 5000
5084 5001
5085 /*********************************************************************** 5002 /***********************************************************************
5164 return alist; 5081 return alist;
5165 } 5082 }
5166 5083
5167 5084
5168 #ifdef HAVE_WINDOW_SYSTEM 5085 #ifdef HAVE_WINDOW_SYSTEM
5169
5170 /* Return the X registry and encoding of font name FONT_NAME on frame F.
5171 Value is nil if not successful. */
5172
5173 static Lisp_Object
5174 deduce_unibyte_registry (f, font_name)
5175 struct frame *f;
5176 char *font_name;
5177 {
5178 struct font_name font;
5179 Lisp_Object registry = Qnil;
5180
5181 font.name = STRDUPA (font_name);
5182 if (split_font_name (f, &font, 0))
5183 {
5184 char *buffer;
5185
5186 /* Extract registry and encoding. */
5187 buffer = (char *) alloca (strlen (font.fields[XLFD_REGISTRY])
5188 + strlen (font.fields[XLFD_ENCODING])
5189 + 10);
5190 strcpy (buffer, font.fields[XLFD_REGISTRY]);
5191 strcat (buffer, "-");
5192 strcat (buffer, font.fields[XLFD_ENCODING]);
5193 registry = build_string (buffer);
5194 }
5195
5196 return registry;
5197 }
5198
5199 5086
5200 /* Value is non-zero if FONT is the name of a scalable font. The 5087 /* Value is non-zero if FONT is the name of a scalable font. The
5201 X11R6 XLFD spec says that point size, pixel size, and average width 5088 X11R6 XLFD spec says that point size, pixel size, and average width
5202 are zero for scalable fonts. Intlfonts contain at least one 5089 are zero for scalable fonts. Intlfonts contain at least one
5203 scalable font ("*-muleindian-1") for which this isn't true, so we 5090 scalable font ("*-muleindian-1") for which this isn't true, so we
5509 5396
5510 static int 5397 static int
5511 try_font_list (f, attrs, pattern, family, registry, fonts) 5398 try_font_list (f, attrs, pattern, family, registry, fonts)
5512 struct frame *f; 5399 struct frame *f;
5513 Lisp_Object *attrs; 5400 Lisp_Object *attrs;
5514 char *pattern, *family, *registry; 5401 Lisp_Object pattern, family, registry;
5515 struct font_name **fonts; 5402 struct font_name **fonts;
5516 { 5403 {
5517 int nfonts; 5404 int nfonts;
5518 5405
5519 if (family == NULL) 5406 if (NILP (family) && STRINGP (attrs[LFACE_FAMILY_INDEX]))
5520 family = LSTRDUPA (attrs[LFACE_FAMILY_INDEX]); 5407 family = attrs[LFACE_FAMILY_INDEX];
5521 5408
5522 nfonts = font_list (f, pattern, family, registry, fonts); 5409 nfonts = font_list (f, pattern, family, registry, fonts);
5523 5410
5524 if (nfonts == 0) 5411 if (nfonts == 0 && !NILP (family))
5525 { 5412 {
5526 Lisp_Object alter; 5413 Lisp_Object alter;
5527 5414
5528 /* Try alternative font families from 5415 /* Try alternative font families from
5529 Vface_alternative_font_family_alist. */ 5416 Vface_alternative_font_family_alist. */
5530 alter = Fassoc (build_string (family), 5417 alter = Fassoc (family, Vface_alternative_font_family_alist);
5531 Vface_alternative_font_family_alist);
5532 if (CONSP (alter)) 5418 if (CONSP (alter))
5533 for (alter = XCDR (alter); 5419 for (alter = XCDR (alter);
5534 CONSP (alter) && nfonts == 0; 5420 CONSP (alter) && nfonts == 0;
5535 alter = XCDR (alter)) 5421 alter = XCDR (alter))
5536 { 5422 {
5537 if (STRINGP (XCAR (alter))) 5423 if (STRINGP (XCAR (alter)))
5538 { 5424 nfonts = font_list (f, Qnil, XCAR (alter), registry, fonts);
5539 family = LSTRDUPA (XCAR (alter));
5540 nfonts = font_list (f, NULL, family, registry, fonts);
5541 }
5542 } 5425 }
5543 5426
5544 /* Try font family of the default face or "fixed". */ 5427 /* Try font family of the default face or "fixed". */
5545 if (nfonts == 0) 5428 if (nfonts == 0)
5546 { 5429 {
5547 struct face *dflt = FACE_FROM_ID (f, DEFAULT_FACE_ID); 5430 struct face *dflt = FACE_FROM_ID (f, DEFAULT_FACE_ID);
5548 if (dflt) 5431 if (dflt)
5549 family = LSTRDUPA (dflt->lface[LFACE_FAMILY_INDEX]); 5432 family = dflt->lface[LFACE_FAMILY_INDEX];
5550 else 5433 else
5551 family = "fixed"; 5434 family = build_string ("fixed");
5552 nfonts = font_list (f, NULL, family, registry, fonts); 5435 nfonts = font_list (f, Qnil, family, registry, fonts);
5553 } 5436 }
5554 5437
5555 /* Try any family with the given registry. */ 5438 /* Try any family with the given registry. */
5556 if (nfonts == 0) 5439 if (nfonts == 0)
5557 nfonts = font_list (f, NULL, "*", registry, fonts); 5440 nfonts = font_list (f, Qnil, Qnil, registry, fonts);
5558 } 5441 }
5559 5442
5560 return nfonts; 5443 return nfonts;
5561 } 5444 }
5562 5445
5563 5446
5564 /* Return the registry and encoding pattern that fonts for CHARSET 5447 /* Return the fontset id of the base fontset name or alias name given
5565 should match. Value is allocated from the heap. */ 5448 by the fontset attribute of ATTRS. Value is -1 if the fontset
5566 5449 attribute of ATTRS doesn't name a fontset. */
5567 char *
5568 x_charset_registry (charset)
5569 int charset;
5570 {
5571 Lisp_Object prop, charset_plist;
5572 char *registry;
5573
5574 /* Get registry and encoding from the charset's plist. */
5575 charset_plist = CHARSET_TABLE_INFO (charset, CHARSET_PLIST_IDX);
5576 prop = Fplist_get (charset_plist, Qx_charset_registry);
5577
5578 if (STRINGP (prop))
5579 {
5580 if (index (XSTRING (prop)->data, '-'))
5581 registry = xstrdup (XSTRING (prop)->data);
5582 else
5583 {
5584 /* If registry doesn't contain a `-', make it a pattern. */
5585 registry = (char *) xmalloc (STRING_BYTES (XSTRING (prop)) + 5);
5586 strcpy (registry, XSTRING (prop)->data);
5587 strcat (registry, "*-*");
5588 }
5589 }
5590 else if (STRINGP (Vface_default_registry))
5591 registry = xstrdup (XSTRING (Vface_default_registry)->data);
5592 else
5593 registry = xstrdup ("iso8859-1");
5594
5595 return registry;
5596 }
5597
5598
5599 /* Return the fontset id of the fontset name or alias name given by
5600 the family attribute of ATTRS on frame F. Value is -1 if the
5601 family attribute of ATTRS doesn't name a fontset. */
5602 5450
5603 static int 5451 static int
5604 face_fontset (f, attrs) 5452 face_fontset (attrs)
5453 Lisp_Object *attrs;
5454 {
5455 Lisp_Object name;
5456 int fontset;
5457
5458 name = attrs[LFACE_FONT_INDEX];
5459 if (!STRINGP (name))
5460 return -1;
5461 return fs_query_fontset (name, 0);
5462 }
5463
5464
5465 /* Choose a name of font to use on frame F to display character C with
5466 Lisp face attributes specified by ATTRS. The font name is
5467 determined by the font-related attributes in ATTRS and the name
5468 pattern for C in FONTSET. Value is the font name which is
5469 allocated from the heap and must be freed by the caller, or NULL if
5470 we can get no information about the font name of C. It is assured
5471 that we always get some information for a single byte
5472 character. */
5473
5474 static char *
5475 choose_face_font (f, attrs, fontset, c)
5605 struct frame *f; 5476 struct frame *f;
5606 Lisp_Object *attrs; 5477 Lisp_Object *attrs;
5607 { 5478 int fontset, c;
5608 Lisp_Object name = attrs[LFACE_FAMILY_INDEX]; 5479 {
5609 int fontset; 5480 Lisp_Object pattern;
5610 5481 char *font_name = NULL;
5611 name = Fquery_fontset (name, Qnil);
5612 if (NILP (name))
5613 fontset = -1;
5614 else
5615 fontset = fs_query_fontset (f, XSTRING (name)->data);
5616
5617 return fontset;
5618 }
5619
5620
5621 /* Get the font to use for the face realizing the fully-specified Lisp
5622 face ATTRS for charset CHARSET on frame F. CHARSET < 0 means
5623 unibyte text; UNIBYTE_REGISTRY is the registry and encoding to use
5624 in this case. Value is the font name which is allocated from the
5625 heap (which means that it must be freed eventually). */
5626
5627 static char *
5628 choose_face_font (f, attrs, charset, unibyte_registry)
5629 struct frame *f;
5630 Lisp_Object *attrs;
5631 int charset;
5632 Lisp_Object unibyte_registry;
5633 {
5634 struct font_name *fonts; 5482 struct font_name *fonts;
5635 int nfonts; 5483 int nfonts;
5636 char *registry; 5484
5637 5485 /* Get (foundry and) family name and registry (and encoding) name of
5638 /* ATTRS must be fully-specified. */ 5486 a font for C. */
5639 xassert (lface_fully_specified_p (attrs)); 5487 pattern = fontset_font_pattern (f, fontset, c);
5640 5488 if (NILP (pattern))
5641 if (STRINGP (unibyte_registry)) 5489 {
5642 registry = xstrdup (XSTRING (unibyte_registry)->data); 5490 xassert (!SINGLE_BYTE_CHAR_P (c));
5643 else 5491 return NULL;
5644 registry = x_charset_registry (charset); 5492 }
5645 5493 /* If what we got is a name pattern, return it. */
5646 nfonts = try_font_list (f, attrs, NULL, NULL, registry, &fonts); 5494 if (STRINGP (pattern))
5647 xfree (registry); 5495 return xstrdup (XSTRING (pattern)->data);
5648 return best_matching_font (f, attrs, fonts, nfonts); 5496
5649 } 5497 /* Family name may be specified both in ATTRS and car part of
5650 5498 PATTERN. The former has higher priority if C is a single byte
5651 5499 character. */
5652 /* Choose a font to use on frame F to display CHARSET using FONTSET 5500 if (STRINGP (attrs[LFACE_FAMILY_INDEX])
5653 with Lisp face attributes specified by ATTRS. CHARSET may be any 5501 && SINGLE_BYTE_CHAR_P (c))
5654 valid charset. CHARSET < 0 means unibyte text. If the fontset 5502 XCAR (pattern) = Qnil;
5655 doesn't contain a font pattern for charset, use the pattern for
5656 CHARSET_ASCII. Value is the font name which is allocated from the
5657 heap and must be freed by the caller. */
5658
5659 static char *
5660 choose_face_fontset_font (f, attrs, fontset, charset)
5661 struct frame *f;
5662 Lisp_Object *attrs;
5663 int fontset, charset;
5664 {
5665 char *pattern;
5666 char *font_name = NULL;
5667 struct fontset_info *fontset_info;
5668 struct font_name *fonts;
5669 int nfonts;
5670
5671 xassert (fontset >= 0 && fontset < FRAME_FONTSET_DATA (f)->n_fontsets);
5672
5673 /* For unibyte text, use the ASCII font of the fontset. Using the
5674 ASCII font seems to be the most reasonable thing we can do in
5675 this case. */
5676 if (charset < 0)
5677 charset = CHARSET_ASCII;
5678
5679 /* Get the font name pattern to use for CHARSET from the fontset. */
5680 fontset_info = FRAME_FONTSET_DATA (f)->fontset_table[fontset];
5681 pattern = fontset_info->fontname[charset];
5682 if (!pattern)
5683 pattern = fontset_info->fontname[CHARSET_ASCII];
5684 xassert (pattern);
5685 5503
5686 /* Get a list of fonts matching that pattern and choose the 5504 /* Get a list of fonts matching that pattern and choose the
5687 best match for the specified face attributes from it. */ 5505 best match for the specified face attributes from it. */
5688 nfonts = try_font_list (f, attrs, pattern, NULL, NULL, &fonts); 5506 nfonts = try_font_list (f, attrs, Qnil, XCAR (pattern), XCDR (pattern),
5507 &fonts);
5689 font_name = best_matching_font (f, attrs, fonts, nfonts); 5508 font_name = best_matching_font (f, attrs, fonts, nfonts);
5690 return font_name; 5509 return font_name;
5691 } 5510 }
5692 5511
5693 #endif /* HAVE_WINDOW_SYSTEM */ 5512 #endif /* HAVE_WINDOW_SYSTEM */
5735 struct frame *f; 5554 struct frame *f;
5736 { 5555 {
5737 struct face_cache *c = FRAME_FACE_CACHE (f); 5556 struct face_cache *c = FRAME_FACE_CACHE (f);
5738 Lisp_Object lface; 5557 Lisp_Object lface;
5739 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 5558 Lisp_Object attrs[LFACE_VECTOR_SIZE];
5740 Lisp_Object unibyte_registry;
5741 Lisp_Object frame_font; 5559 Lisp_Object frame_font;
5742 struct face *face; 5560 struct face *face;
5743 int fontset; 5561 int fontset;
5744 5562
5745 /* If the `default' face is not yet known, create it. */ 5563 /* If the `default' face is not yet known, create it. */
5756 { 5574 {
5757 /* Set frame_font to the value of the `font' frame parameter. */ 5575 /* Set frame_font to the value of the `font' frame parameter. */
5758 frame_font = Fassq (Qfont, f->param_alist); 5576 frame_font = Fassq (Qfont, f->param_alist);
5759 xassert (CONSP (frame_font) && STRINGP (XCDR (frame_font))); 5577 xassert (CONSP (frame_font) && STRINGP (XCDR (frame_font)));
5760 frame_font = XCDR (frame_font); 5578 frame_font = XCDR (frame_font);
5761 5579 set_lface_from_font_name (f, lface, frame_font, 0, 1);
5762 fontset = fs_query_fontset (f, XSTRING (frame_font)->data);
5763 if (fontset >= 0)
5764 {
5765 /* If frame_font is a fontset name, don't use that for
5766 determining font-related attributes of the default face
5767 because it is just an artificial name. Use the ASCII font of
5768 the fontset, instead. */
5769 struct font_info *font_info;
5770 struct font_name font;
5771
5772 BLOCK_INPUT;
5773 font_info = FS_LOAD_FONT (f, FRAME_X_FONT_TABLE (f), CHARSET_ASCII,
5774 NULL, fontset);
5775 UNBLOCK_INPUT;
5776
5777 /* Set weight etc. from the ASCII font. */
5778 if (!set_lface_from_font_name (f, lface, font_info->full_name, 0, 0))
5779 return 0;
5780
5781 /* Remember registry and encoding of the frame font. */
5782 unibyte_registry = deduce_unibyte_registry (f, font_info->full_name);
5783 if (STRINGP (unibyte_registry))
5784 Vface_default_registry = unibyte_registry;
5785 else
5786 Vface_default_registry = build_string ("iso8859-1");
5787
5788 /* But set the family to the fontset alias name. Implementation
5789 note: When a font is passed to Emacs via `-fn FONT', a
5790 fontset is created in `x-win.el' whose name ends in
5791 `fontset-startup'. This fontset has an alias name that is
5792 equal to frame_font. */
5793 xassert (STRINGP (frame_font));
5794 font.name = LSTRDUPA (frame_font);
5795
5796 if (!split_font_name (f, &font, 1)
5797 || xstricmp (font.fields[XLFD_REGISTRY], "fontset") != 0
5798 || xstricmp (font.fields[XLFD_ENCODING], "startup") != 0)
5799 LFACE_FAMILY (lface) = frame_font;
5800 }
5801 else
5802 {
5803 /* Frame parameters contain a real font. Fill default face
5804 attributes from that font. */
5805 if (!set_lface_from_font_name (f, lface,
5806 XSTRING (frame_font)->data, 0, 0))
5807 return 0;
5808
5809 /* Remember registry and encoding of the frame font. */
5810 unibyte_registry
5811 = deduce_unibyte_registry (f, XSTRING (frame_font)->data);
5812 if (STRINGP (unibyte_registry))
5813 Vface_default_registry = unibyte_registry;
5814 else
5815 Vface_default_registry = build_string ("iso8859-1");
5816 }
5817 } 5580 }
5818 #endif /* HAVE_WINDOW_SYSTEM */ 5581 #endif /* HAVE_WINDOW_SYSTEM */
5819 5582
5820 if (!FRAME_WINDOW_P (f)) 5583 if (!FRAME_WINDOW_P (f))
5821 { 5584 {
5877 5640
5878 /* Realize the face; it must be fully-specified now. */ 5641 /* Realize the face; it must be fully-specified now. */
5879 xassert (lface_fully_specified_p (XVECTOR (lface)->contents)); 5642 xassert (lface_fully_specified_p (XVECTOR (lface)->contents));
5880 check_lface (lface); 5643 check_lface (lface);
5881 bcopy (XVECTOR (lface)->contents, attrs, sizeof attrs); 5644 bcopy (XVECTOR (lface)->contents, attrs, sizeof attrs);
5882 face = realize_face (c, attrs, CHARSET_ASCII); 5645 face = realize_face (c, attrs, 0, NULL, DEFAULT_FACE_ID);
5883
5884 /* Remove the former default face. */
5885 if (c->used > DEFAULT_FACE_ID)
5886 {
5887 struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
5888 uncache_face (c, default_face);
5889 free_realized_face (f, default_face);
5890 }
5891
5892 /* Insert the new default face. */
5893 cache_face (c, face, lface_hash (attrs));
5894 xassert (face->id == DEFAULT_FACE_ID);
5895 return 1; 5646 return 1;
5896 } 5647 }
5897 5648
5898 5649
5899 /* Realize basic faces other than the default face in face cache C. 5650 /* Realize basic faces other than the default face in face cache C.
5928 /* Merge SYMBOL's face with the default face. */ 5679 /* Merge SYMBOL's face with the default face. */
5929 get_lface_attributes (f, symbol, symbol_attrs, 1); 5680 get_lface_attributes (f, symbol, symbol_attrs, 1);
5930 merge_face_vectors (symbol_attrs, attrs); 5681 merge_face_vectors (symbol_attrs, attrs);
5931 5682
5932 /* Realize the face. */ 5683 /* Realize the face. */
5933 new_face = realize_face (c, attrs, CHARSET_ASCII); 5684 new_face = realize_face (c, attrs, 0, NULL, id);
5934
5935 /* Remove the former face. */
5936 if (c->used > id)
5937 {
5938 struct face *old_face = c->faces_by_id[id];
5939 uncache_face (c, old_face);
5940 free_realized_face (f, old_face);
5941 }
5942
5943 /* Insert the new face. */
5944 cache_face (c, new_face, lface_hash (attrs));
5945 xassert (new_face->id == id);
5946 } 5685 }
5947 5686
5948 5687
5949 /* Realize the fully-specified face with attributes ATTRS in face 5688 /* Realize the fully-specified face with attributes ATTRS in face
5950 cache C for character set CHARSET or for unibyte text if CHARSET < 5689 cache CACHE for character C. If C is a multibyte character,
5951 0. Value is a pointer to the newly created realized face. */ 5690 BASE_FACE is a face for ASCII characters that has the same
5691 attributes. Otherwise, BASE_FACE is ignored. If FORMER_FACE_ID is
5692 non-negative, it is an ID of face to remove before caching the new
5693 face. Value is a pointer to the newly created realized face. */
5952 5694
5953 static struct face * 5695 static struct face *
5954 realize_face (c, attrs, charset) 5696 realize_face (cache, attrs, c, base_face, former_face_id)
5955 struct face_cache *c; 5697 struct face_cache *cache;
5956 Lisp_Object *attrs; 5698 Lisp_Object *attrs;
5957 int charset; 5699 int c;
5700 struct face *base_face;
5701 int former_face_id;
5958 { 5702 {
5959 struct face *face; 5703 struct face *face;
5960 5704
5961 /* LFACE must be fully specified. */ 5705 /* LFACE must be fully specified. */
5962 xassert (c != NULL); 5706 xassert (cache != NULL);
5963 check_lface_attrs (attrs); 5707 check_lface_attrs (attrs);
5964 5708
5965 if (FRAME_WINDOW_P (c->f)) 5709 if (former_face_id >= 0 && cache->used > former_face_id)
5966 face = realize_x_face (c, attrs, charset); 5710 {
5967 else if (FRAME_TERMCAP_P (c->f) || FRAME_MSDOS_P (c->f)) 5711 /* Remove the former face. */
5968 face = realize_tty_face (c, attrs, charset); 5712 struct face *former_face = cache->faces_by_id[former_face_id];
5713 uncache_face (cache, former_face);
5714 free_realized_face (cache->f, former_face);
5715 }
5716
5717 if (FRAME_WINDOW_P (cache->f))
5718 face = realize_x_face (cache, attrs, c, base_face);
5719 else if (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f))
5720 face = realize_tty_face (cache, attrs, c);
5969 else 5721 else
5970 abort (); 5722 abort ();
5971 5723
5724 /* Insert the new face. */
5725 cache_face (cache, face, lface_hash (attrs));
5726 #ifdef HAVE_WINDOW_SYSTEM
5727 if (FRAME_X_P (cache->f) && face->font == NULL)
5728 load_face_font (cache->f, face, c);
5729 #endif /* HAVE_WINDOW_SYSTEM */
5972 return face; 5730 return face;
5973 } 5731 }
5974 5732
5975 5733
5976 /* Realize the fully-specified face with attributes ATTRS in face 5734 /* Realize the fully-specified face with attributes ATTRS in face
5977 cache C for character set CHARSET or for unibyte text if CHARSET < 5735 cache CACHE for character C. Do it for X frame CACHE->f. If C is
5978 0. Do it for X frame C->f. Value is a pointer to the newly 5736 a multibyte character, BASE_FACE is a face for ASCII characters
5737 that has the same attributes. Otherwise, BASE_FACE is ignored. If
5738 the new face doesn't share font with the default face, a fontname
5739 is allocated from the heap and set in `font_name' of the new face,
5740 but it is not yet loaded here. Value is a pointer to the newly
5979 created realized face. */ 5741 created realized face. */
5980 5742
5981 static struct face * 5743 static struct face *
5982 realize_x_face (c, attrs, charset) 5744 realize_x_face (cache, attrs, c, base_face)
5983 struct face_cache *c; 5745 struct face_cache *cache;
5984 Lisp_Object *attrs; 5746 Lisp_Object *attrs;
5985 int charset; 5747 int c;
5748 struct face *base_face;
5986 { 5749 {
5987 #ifdef HAVE_WINDOW_SYSTEM 5750 #ifdef HAVE_WINDOW_SYSTEM
5988 struct face *face, *default_face; 5751 struct face *face, *default_face;
5989 struct frame *f; 5752 struct frame *f;
5990 Lisp_Object stipple, overline, strike_through, box; 5753 Lisp_Object stipple, overline, strike_through, box;
5991 Lisp_Object unibyte_registry; 5754
5992 struct gcpro gcpro1; 5755 xassert (FRAME_WINDOW_P (cache->f));
5993 5756 xassert (SINGLE_BYTE_CHAR_P (c)
5994 xassert (FRAME_WINDOW_P (c->f)); 5757 || (base_face && base_face->ascii_face == base_face));
5995
5996 /* If realizing a face for use in unibyte text, get the X registry
5997 and encoding to use from Vface_default_registry. */
5998 if (charset < 0)
5999 unibyte_registry = (STRINGP (Vface_default_registry)
6000 ? Vface_default_registry
6001 : build_string ("iso8859-1"));
6002 else
6003 unibyte_registry = Qnil;
6004 GCPRO1 (unibyte_registry);
6005 5758
6006 /* Allocate a new realized face. */ 5759 /* Allocate a new realized face. */
6007 face = make_realized_face (attrs, charset, unibyte_registry); 5760 face = make_realized_face (attrs);
6008 5761
6009 f = c->f; 5762 f = cache->f;
5763
5764 /* If C is a multibyte character, we share all face attirbutes with
5765 BASE_FACE including the realized fontset. But, we must load a
5766 different font. */
5767 if (!SINGLE_BYTE_CHAR_P (c))
5768 {
5769 bcopy (base_face, face, sizeof *face);
5770 face->gc = 0;
5771 face->font = NULL; /* to force realize_face to load font */
5772 return face;
5773 }
5774
5775 /* Now we are realizing a face for ASCII (and unibyte) characters. */
5776
6010 /* Determine the font to use. Most of the time, the font will be 5777 /* Determine the font to use. Most of the time, the font will be
6011 the same as the font of the default face, so try that first. */ 5778 the same as the font of the default face, so try that first. */
6012 default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); 5779 default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
6013 if (default_face 5780 if (default_face
6014 && FACE_SUITABLE_FOR_CHARSET_P (default_face, charset) 5781 && FACE_SUITABLE_FOR_CHAR_P (default_face, c)
6015 && lface_same_font_attributes_p (default_face->lface, attrs)) 5782 && lface_same_font_attributes_p (default_face->lface, attrs))
6016 { 5783 {
6017 face->font = default_face->font; 5784 face->font = default_face->font;
6018 face->fontset = default_face->fontset; 5785 face->fontset = default_face->fontset;
6019 face->font_info_id = default_face->font_info_id; 5786 face->font_info_id = default_face->font_info_id;
6020 face->font_name = default_face->font_name; 5787 face->font_name = default_face->font_name;
6021 face->registry = default_face->registry; 5788 face->ascii_face = face;
6022 } 5789
6023 else if (charset >= 0) 5790 /* But, as we can't share the fontset, make a new realized
6024 { 5791 fontset that has the same base fontset as of the default
6025 /* For all charsets, we use our own font selection functions to 5792 face. */
6026 choose a best matching font for the specified face 5793 face->fontset
6027 attributes. If the face specifies a fontset alias name, the 5794 = make_fontset_for_ascii_face (f, default_face->fontset);
6028 fontset determines the font name pattern, otherwise we
6029 construct a font pattern from face attributes and charset. */
6030
6031 char *font_name = NULL;
6032 int fontset = face_fontset (f, attrs);
6033
6034 if (fontset < 0)
6035 font_name = choose_face_font (f, attrs, charset, Qnil);
6036 else
6037 {
6038 font_name = choose_face_fontset_font (f, attrs, fontset, charset);
6039 fontset = -1;
6040 }
6041
6042 load_face_font_or_fontset (f, face, font_name, fontset);
6043 xfree (font_name);
6044 } 5795 }
6045 else 5796 else
6046 { 5797 {
6047 /* Unibyte case, and font is not equal to that of the default 5798 /* If the face attribute ATTRS specifies a fontset, use it as
6048 face. UNIBYTE_REGISTRY is the X registry and encoding the 5799 the base of a new realized fontset. Otherwise, use the
6049 font should have. What is a reasonable thing to do if the 5800 default fontset as the base. The base determines registry
6050 user specified a fontset alias name for the face in this 5801 and encoding of a font. It may also determine foundry and
6051 case? We choose a font by taking the ASCII font of the 5802 family. The other fields of font name pattern are
6052 fontset, but using UNIBYTE_REGISTRY for its registry and 5803 constructed from ATTRS. */
6053 encoding. */ 5804 face->fontset
6054 5805 = make_fontset_for_ascii_face (f, face_fontset (attrs));
6055 char *font_name = NULL; 5806 face->font = NULL; /* to force realize_face to load font */
6056 int fontset = face_fontset (f, attrs);
6057
6058 if (fontset < 0)
6059 font_name = choose_face_font (f, attrs, charset, unibyte_registry);
6060 else
6061 font_name = choose_face_fontset_font (f, attrs, fontset, charset);
6062
6063 load_face_font_or_fontset (f, face, font_name, -1);
6064 xfree (font_name);
6065 } 5807 }
6066 5808
6067 /* Load colors, and set remaining attributes. */ 5809 /* Load colors, and set remaining attributes. */
6068 5810
6069 load_face_colors (f, face, attrs); 5811 load_face_colors (f, face, attrs);
6191 5933
6192 stipple = attrs[LFACE_STIPPLE_INDEX]; 5934 stipple = attrs[LFACE_STIPPLE_INDEX];
6193 if (!NILP (stipple)) 5935 if (!NILP (stipple))
6194 face->stipple = load_pixmap (f, stipple, &face->pixmap_w, &face->pixmap_h); 5936 face->stipple = load_pixmap (f, stipple, &face->pixmap_w, &face->pixmap_h);
6195 5937
6196 UNGCPRO;
6197 xassert (face->fontset < 0); 5938 xassert (face->fontset < 0);
6198 xassert (FACE_SUITABLE_FOR_CHARSET_P (face, charset)); 5939 xassert (FACE_SUITABLE_FOR_CHAR_P (face, c));
6199 return face; 5940 return face;
6200 #endif /* HAVE_WINDOW_SYSTEM */ 5941 #endif /* HAVE_WINDOW_SYSTEM */
6201 } 5942 }
6202 5943
6203 5944
6204 /* Realize the fully-specified face with attributes ATTRS in face 5945 /* Realize the fully-specified face with attributes ATTRS in face
6205 cache C for character set CHARSET or for unibyte text if CHARSET < 5946 cache CACHE for character C. Do it for TTY frame CACHE->f. Value is a
6206 0. Do it for TTY frame C->f. Value is a pointer to the newly 5947 pointer to the newly created realized face. */
6207 created realized face. */
6208 5948
6209 static struct face * 5949 static struct face *
6210 realize_tty_face (c, attrs, charset) 5950 realize_tty_face (cache, attrs, c)
6211 struct face_cache *c; 5951 struct face_cache *cache;
6212 Lisp_Object *attrs; 5952 Lisp_Object *attrs;
6213 int charset; 5953 int c;
6214 { 5954 {
6215 struct face *face; 5955 struct face *face;
6216 int weight, slant; 5956 int weight, slant;
6217 Lisp_Object color; 5957 Lisp_Object color;
6218 Lisp_Object tty_defined_color_alist = 5958 Lisp_Object tty_defined_color_alist =
6220 Lisp_Object tty_color_alist = intern ("tty-color-alist"); 5960 Lisp_Object tty_color_alist = intern ("tty-color-alist");
6221 Lisp_Object frame; 5961 Lisp_Object frame;
6222 int face_colors_defaulted = 0; 5962 int face_colors_defaulted = 0;
6223 5963
6224 /* Frame must be a termcap frame. */ 5964 /* Frame must be a termcap frame. */
6225 xassert (FRAME_TERMCAP_P (c->f) || FRAME_MSDOS_P (c->f)); 5965 xassert (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f));
6226 5966
6227 /* Allocate a new realized face. */ 5967 /* Allocate a new realized face. */
6228 face = make_realized_face (attrs, charset, Qnil); 5968 face = make_realized_face (attrs);
6229 face->font_name = FRAME_MSDOS_P (c->f) ? "ms-dos" : "tty"; 5969 face->font_name = FRAME_MSDOS_P (cache->f) ? "ms-dos" : "tty";
6230 5970
6231 /* Map face attributes to TTY appearances. We map slant to 5971 /* Map face attributes to TTY appearances. We map slant to
6232 dimmed text because we want italic text to appear differently 5972 dimmed text because we want italic text to appear differently
6233 and because dimmed text is probably used infrequently. */ 5973 and because dimmed text is probably used infrequently. */
6234 weight = face_numeric_weight (attrs[LFACE_WEIGHT_INDEX]); 5974 weight = face_numeric_weight (attrs[LFACE_WEIGHT_INDEX]);
6245 5985
6246 /* Map color names to color indices. */ 5986 /* Map color names to color indices. */
6247 face->foreground = FACE_TTY_DEFAULT_FG_COLOR; 5987 face->foreground = FACE_TTY_DEFAULT_FG_COLOR;
6248 face->background = FACE_TTY_DEFAULT_BG_COLOR; 5988 face->background = FACE_TTY_DEFAULT_BG_COLOR;
6249 5989
6250 XSETFRAME (frame, c->f); 5990 XSETFRAME (frame, cache->f);
6251 color = attrs[LFACE_FOREGROUND_INDEX]; 5991 color = attrs[LFACE_FOREGROUND_INDEX];
6252 if (STRINGP (color) 5992 if (STRINGP (color)
6253 && XSTRING (color)->size 5993 && XSTRING (color)->size
6254 && !NILP (tty_defined_color_alist) 5994 && !NILP (tty_defined_color_alist)
6255 && (color = Fassoc (color, call1 (tty_color_alist, frame)), 5995 && (color = Fassoc (color, call1 (tty_color_alist, frame)),
6259 face->foreground = XINT (XCAR (XCDR (color))); 5999 face->foreground = XINT (XCAR (XCDR (color)));
6260 6000
6261 if (face->foreground == FACE_TTY_DEFAULT_FG_COLOR 6001 if (face->foreground == FACE_TTY_DEFAULT_FG_COLOR
6262 && STRINGP (attrs[LFACE_FOREGROUND_INDEX])) 6002 && STRINGP (attrs[LFACE_FOREGROUND_INDEX]))
6263 { 6003 {
6264 face->foreground = load_color (c->f, face, 6004 face->foreground = load_color (cache->f, face,
6265 attrs[LFACE_FOREGROUND_INDEX], 6005 attrs[LFACE_FOREGROUND_INDEX],
6266 LFACE_FOREGROUND_INDEX); 6006 LFACE_FOREGROUND_INDEX);
6267 6007
6268 #if defined (MSDOS) || defined (WINDOWSNT) 6008 #if defined (MSDOS) || defined (WINDOWSNT)
6269 /* If the foreground of the default face is the default color, 6009 /* If the foreground of the default face is the default color,
6270 use the foreground color defined by the frame. */ 6010 use the foreground color defined by the frame. */
6271 #ifdef MSDOS 6011 #ifdef MSDOS
6272 if (FRAME_MSDOS_P (c->f)) 6012 if (FRAME_MSDOS_P (cache->f))
6273 { 6013 {
6274 #endif /* MSDOS */ 6014 #endif /* MSDOS */
6275 6015
6276 if (face->foreground == FACE_TTY_DEFAULT_FG_COLOR 6016 if (face->foreground == FACE_TTY_DEFAULT_FG_COLOR
6277 || face->foreground == FACE_TTY_DEFAULT_COLOR) 6017 || face->foreground == FACE_TTY_DEFAULT_COLOR)
6278 { 6018 {
6279 face->foreground = FRAME_FOREGROUND_PIXEL (c->f); 6019 face->foreground = FRAME_FOREGROUND_PIXEL (cache->f);
6280 attrs[LFACE_FOREGROUND_INDEX] = 6020 attrs[LFACE_FOREGROUND_INDEX] =
6281 tty_color_name (c->f, face->foreground); 6021 tty_color_name (cache->f, face->foreground);
6282 face_colors_defaulted = 1; 6022 face_colors_defaulted = 1;
6283 } 6023 }
6284 else if (face->foreground == FACE_TTY_DEFAULT_BG_COLOR) 6024 else if (face->foreground == FACE_TTY_DEFAULT_BG_COLOR)
6285 { 6025 {
6286 face->foreground = FRAME_BACKGROUND_PIXEL (c->f); 6026 face->foreground = FRAME_BACKGROUND_PIXEL (cache->f);
6287 attrs[LFACE_FOREGROUND_INDEX] = 6027 attrs[LFACE_FOREGROUND_INDEX] =
6288 tty_color_name (c->f, face->foreground); 6028 tty_color_name (cache->f, face->foreground);
6289 face_colors_defaulted = 1; 6029 face_colors_defaulted = 1;
6290 } 6030 }
6291 #ifdef MSDOS 6031 #ifdef MSDOS
6292 } 6032 }
6293 #endif 6033 #endif
6305 face->background = XINT (XCAR (XCDR (color))); 6045 face->background = XINT (XCAR (XCDR (color)));
6306 6046
6307 if (face->background == FACE_TTY_DEFAULT_BG_COLOR 6047 if (face->background == FACE_TTY_DEFAULT_BG_COLOR
6308 && STRINGP (attrs[LFACE_BACKGROUND_INDEX])) 6048 && STRINGP (attrs[LFACE_BACKGROUND_INDEX]))
6309 { 6049 {
6310 face->background = load_color (c->f, face, 6050 face->background = load_color (cache->f, face,
6311 attrs[LFACE_BACKGROUND_INDEX], 6051 attrs[LFACE_BACKGROUND_INDEX],
6312 LFACE_BACKGROUND_INDEX); 6052 LFACE_BACKGROUND_INDEX);
6313 #if defined (MSDOS) || defined (WINDOWSNT) 6053 #if defined (MSDOS) || defined (WINDOWSNT)
6314 /* If the background of the default face is the default color, 6054 /* If the background of the default face is the default color,
6315 use the background color defined by the frame. */ 6055 use the background color defined by the frame. */
6316 #ifdef MSDOS 6056 #ifdef MSDOS
6317 if (FRAME_MSDOS_P (c->f)) 6057 if (FRAME_MSDOS_P (cache->f))
6318 { 6058 {
6319 #endif /* MSDOS */ 6059 #endif /* MSDOS */
6320 6060
6321 if (face->background == FACE_TTY_DEFAULT_BG_COLOR 6061 if (face->background == FACE_TTY_DEFAULT_BG_COLOR
6322 || face->background == FACE_TTY_DEFAULT_COLOR) 6062 || face->background == FACE_TTY_DEFAULT_COLOR)
6323 { 6063 {
6324 face->background = FRAME_BACKGROUND_PIXEL (c->f); 6064 face->background = FRAME_BACKGROUND_PIXEL (cache->f);
6325 attrs[LFACE_BACKGROUND_INDEX] = 6065 attrs[LFACE_BACKGROUND_INDEX] =
6326 tty_color_name (c->f, face->background); 6066 tty_color_name (cache->f, face->background);
6327 face_colors_defaulted = 1; 6067 face_colors_defaulted = 1;
6328 } 6068 }
6329 else if (face->background == FACE_TTY_DEFAULT_FG_COLOR) 6069 else if (face->background == FACE_TTY_DEFAULT_FG_COLOR)
6330 { 6070 {
6331 face->background = FRAME_FOREGROUND_PIXEL (c->f); 6071 face->background = FRAME_FOREGROUND_PIXEL (cache->f);
6332 attrs[LFACE_BACKGROUND_INDEX] = 6072 attrs[LFACE_BACKGROUND_INDEX] =
6333 tty_color_name (c->f, face->background); 6073 tty_color_name (cache->f, face->background);
6334 face_colors_defaulted = 1; 6074 face_colors_defaulted = 1;
6335 } 6075 }
6336 #ifdef MSDOS 6076 #ifdef MSDOS
6337 } 6077 }
6338 #endif 6078 #endif
6367 struct frame *f; 6107 struct frame *f;
6368 int ch; 6108 int ch;
6369 Lisp_Object prop; 6109 Lisp_Object prop;
6370 { 6110 {
6371 int face_id; 6111 int face_id;
6372 int charset = (NILP (current_buffer->enable_multibyte_characters) 6112
6373 ? -1 6113 if (NILP (current_buffer->enable_multibyte_characters))
6374 : CHAR_CHARSET (ch)); 6114 ch = -1;
6375 6115
6376 if (NILP (prop)) 6116 if (NILP (prop))
6377 face_id = FACE_FOR_CHARSET (f, DEFAULT_FACE_ID, charset); 6117 {
6118 struct face *face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
6119 face_id = FACE_FOR_CHAR (f, face, ch);
6120 }
6378 else 6121 else
6379 { 6122 {
6380 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 6123 Lisp_Object attrs[LFACE_VECTOR_SIZE];
6381 struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); 6124 struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
6382 bcopy (default_face->lface, attrs, sizeof attrs); 6125 bcopy (default_face->lface, attrs, sizeof attrs);
6383 merge_face_vector_with_property (f, attrs, prop); 6126 merge_face_vector_with_property (f, attrs, prop);
6384 face_id = lookup_face (f, attrs, charset); 6127 face_id = lookup_face (f, attrs, ch, NULL);
6385 } 6128 }
6386 6129
6387 return face_id; 6130 return face_id;
6388 } 6131 }
6389 6132
6399 LIMIT is a position not to scan beyond. That is to limit the time 6142 LIMIT is a position not to scan beyond. That is to limit the time
6400 this function can take. 6143 this function can take.
6401 6144
6402 If MOUSE is non-zero, use the character's mouse-face, not its face. 6145 If MOUSE is non-zero, use the character's mouse-face, not its face.
6403 6146
6404 The face returned is suitable for displaying CHARSET_ASCII if 6147 The face returned is suitable for displaying ASCII characters. */
6405 current_buffer->enable_multibyte_characters is non-nil. Otherwise,
6406 the face is suitable for displaying unibyte text. */
6407 6148
6408 int 6149 int
6409 face_at_buffer_position (w, pos, region_beg, region_end, 6150 face_at_buffer_position (w, pos, region_beg, region_end,
6410 endptr, limit, mouse) 6151 endptr, limit, mouse)
6411 struct window *w; 6152 struct window *w;
6476 default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); 6217 default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
6477 6218
6478 /* Optimize common cases where we can use the default face. */ 6219 /* Optimize common cases where we can use the default face. */
6479 if (noverlays == 0 6220 if (noverlays == 0
6480 && NILP (prop) 6221 && NILP (prop)
6481 && !(pos >= region_beg && pos < region_end) 6222 && !(pos >= region_beg && pos < region_end))
6482 && (multibyte_p
6483 || !FRAME_WINDOW_P (f)
6484 || FACE_SUITABLE_FOR_CHARSET_P (default_face, -1)))
6485 return DEFAULT_FACE_ID; 6223 return DEFAULT_FACE_ID;
6486 6224
6487 /* Begin with attributes from the default face. */ 6225 /* Begin with attributes from the default face. */
6488 bcopy (default_face->lface, attrs, sizeof attrs); 6226 bcopy (default_face->lface, attrs, sizeof attrs);
6489 6227
6519 } 6257 }
6520 6258
6521 *endptr = endpos; 6259 *endptr = endpos;
6522 6260
6523 /* Look up a realized face with the given face attributes, 6261 /* Look up a realized face with the given face attributes,
6524 or realize a new one. Charset is ignored for tty frames. */ 6262 or realize a new one for ASCII characters. */
6525 return lookup_face (f, attrs, multibyte_p ? CHARSET_ASCII : -1); 6263 return lookup_face (f, attrs, 0, NULL);
6526 } 6264 }
6527 6265
6528 6266
6529 /* Compute the face at character position POS in Lisp string STRING on 6267 /* Compute the face at character position POS in Lisp string STRING on
6530 window W, for charset CHARSET_ASCII. 6268 window W, for ASCII characters.
6531 6269
6532 If STRING is an overlay string, it comes from position BUFPOS in 6270 If STRING is an overlay string, it comes from position BUFPOS in
6533 current_buffer, otherwise BUFPOS is zero to indicate that STRING is 6271 current_buffer, otherwise BUFPOS is zero to indicate that STRING is
6534 not an overlay string. W must display the current buffer. 6272 not an overlay string. W must display the current buffer.
6535 REGION_BEG and REGION_END give the start and end positions of the 6273 REGION_BEG and REGION_END give the start and end positions of the
6541 Set *ENDPTR to the next position where to check for faces in 6279 Set *ENDPTR to the next position where to check for faces in
6542 STRING; -1 if the face is constant from POS to the end of the 6280 STRING; -1 if the face is constant from POS to the end of the
6543 string. 6281 string.
6544 6282
6545 Value is the id of the face to use. The face returned is suitable 6283 Value is the id of the face to use. The face returned is suitable
6546 for displaying CHARSET_ASCII if STRING is multibyte. Otherwise, 6284 for displaying ASCII characters. */
6547 the face is suitable for displaying unibyte text. */
6548 6285
6549 int 6286 int
6550 face_at_string_position (w, string, pos, bufpos, region_beg, 6287 face_at_string_position (w, string, pos, bufpos, region_beg,
6551 region_end, endptr, base_face_id) 6288 region_end, endptr, base_face_id)
6552 struct window *w; 6289 struct window *w;
6595 && (multibyte_p 6332 && (multibyte_p
6596 /* We can't realize faces for different charsets differently 6333 /* We can't realize faces for different charsets differently
6597 if we don't have fonts, so we can stop here if not working 6334 if we don't have fonts, so we can stop here if not working
6598 on a window-system frame. */ 6335 on a window-system frame. */
6599 || !FRAME_WINDOW_P (f) 6336 || !FRAME_WINDOW_P (f)
6600 || FACE_SUITABLE_FOR_CHARSET_P (base_face, -1))) 6337 || FACE_SUITABLE_FOR_CHAR_P (base_face, 0)))
6601 return base_face->id; 6338 return base_face->id;
6602 6339
6603 /* Begin with attributes from the base face. */ 6340 /* Begin with attributes from the base face. */
6604 bcopy (base_face->lface, attrs, sizeof attrs); 6341 bcopy (base_face->lface, attrs, sizeof attrs);
6605 6342
6615 Lisp_Object region_face = lface_from_face_name (f, Qregion, 0); 6352 Lisp_Object region_face = lface_from_face_name (f, Qregion, 0);
6616 merge_face_vectors (XVECTOR (region_face)->contents, attrs); 6353 merge_face_vectors (XVECTOR (region_face)->contents, attrs);
6617 } 6354 }
6618 6355
6619 /* Look up a realized face with the given face attributes, 6356 /* Look up a realized face with the given face attributes,
6620 or realize a new one. */ 6357 or realize a new one for ASCII characters. */
6621 return lookup_face (f, attrs, multibyte_p ? CHARSET_ASCII : -1); 6358 return lookup_face (f, attrs, 0, NULL);
6622 } 6359 }
6623 6360
6624 6361
6625 6362
6626 /*********************************************************************** 6363 /***********************************************************************
6817 Qforeground_color = intern ("foreground-color"); 6554 Qforeground_color = intern ("foreground-color");
6818 staticpro (&Qforeground_color); 6555 staticpro (&Qforeground_color);
6819 Qunspecified = intern ("unspecified"); 6556 Qunspecified = intern ("unspecified");
6820 staticpro (&Qunspecified); 6557 staticpro (&Qunspecified);
6821 6558
6822 Qx_charset_registry = intern ("x-charset-registry");
6823 staticpro (&Qx_charset_registry);
6824 Qface_alias = intern ("face-alias"); 6559 Qface_alias = intern ("face-alias");
6825 staticpro (&Qface_alias); 6560 staticpro (&Qface_alias);
6826 Qdefault = intern ("default"); 6561 Qdefault = intern ("default");
6827 staticpro (&Qdefault); 6562 staticpro (&Qdefault);
6828 Qtool_bar = intern ("tool-bar"); 6563 Qtool_bar = intern ("tool-bar");
6887 This stipple pattern is used on monochrome displays\n\ 6622 This stipple pattern is used on monochrome displays\n\
6888 instead of shades of gray for a face background color.\n\ 6623 instead of shades of gray for a face background color.\n\
6889 See `set-face-stipple' for possible values for this variable."); 6624 See `set-face-stipple' for possible values for this variable.");
6890 Vface_default_stipple = build_string ("gray3"); 6625 Vface_default_stipple = build_string ("gray3");
6891 6626
6892 DEFVAR_LISP ("face-default-registry", &Vface_default_registry,
6893 "Default registry and encoding to use.\n\
6894 This registry and encoding is used for unibyte text. It is set up\n\
6895 from the specified frame font when Emacs starts. (For internal use only.)");
6896 Vface_default_registry = Qnil;
6897
6898 DEFVAR_LISP ("face-alternative-font-family-alist", 6627 DEFVAR_LISP ("face-alternative-font-family-alist",
6899 &Vface_alternative_font_family_alist, ""); 6628 &Vface_alternative_font_family_alist, "");
6900 Vface_alternative_font_family_alist = Qnil; 6629 Vface_alternative_font_family_alist = Qnil;
6901 6630
6902 #if SCALABLE_FONTS 6631 #if SCALABLE_FONTS