Mercurial > emacs
comparison src/xfaces.c @ 30973:2f3dc355bcaf
(lface_equal_p): Compare strings differently.
(Qtty_color_alist, Vtty_defined_color_alist): New variables.
(realize_tty_face): Use them.
(syms_of_xfaces): Initialize new variables.
(map_tty_color): New function, extracted from realize_tty_face.
(map_tty_color) [MSDOS || WINDOWSNT]: If using the frame's default
foreground or background color, store the new color name in the
realized face; previous code trying to do this had no effect.
(realize_tty_face): Use map_tty_color.
(Fclear_face_cache): Set face_change_count and ensure thorough
redisplay.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Sun, 20 Aug 2000 13:23:01 +0000 |
parents | 093d1cfc207f |
children | ade2aeaf252e |
comparison
equal
deleted
inserted
replaced
30972:e3ff4aef71a1 | 30973:2f3dc355bcaf |
---|---|
281 prime number). */ | 281 prime number). */ |
282 | 282 |
283 #define FACE_CACHE_BUCKETS_SIZE 1001 | 283 #define FACE_CACHE_BUCKETS_SIZE 1001 |
284 | 284 |
285 /* A definition of XColor for non-X frames. */ | 285 /* A definition of XColor for non-X frames. */ |
286 | |
286 #ifndef HAVE_X_WINDOWS | 287 #ifndef HAVE_X_WINDOWS |
287 typedef struct { | 288 |
289 typedef struct | |
290 { | |
288 unsigned long pixel; | 291 unsigned long pixel; |
289 unsigned short red, green, blue; | 292 unsigned short red, green, blue; |
290 char flags; | 293 char flags; |
291 char pad; | 294 char pad; |
292 } XColor; | 295 } |
293 #endif | 296 XColor; |
297 | |
298 #endif /* not HAVE_X_WINDOWS */ | |
294 | 299 |
295 /* Keyword symbols used for face attribute names. */ | 300 /* Keyword symbols used for face attribute names. */ |
296 | 301 |
297 Lisp_Object QCfamily, QCheight, QCweight, QCslant, QCunderline; | 302 Lisp_Object QCfamily, QCheight, QCweight, QCslant, QCunderline; |
298 Lisp_Object QCinverse_video, QCforeground, QCbackground, QCstipple; | 303 Lisp_Object QCinverse_video, QCforeground, QCbackground, QCstipple; |
394 /* A vector mapping Lisp face Id's to face names. */ | 399 /* A vector mapping Lisp face Id's to face names. */ |
395 | 400 |
396 static Lisp_Object *lface_id_to_name; | 401 static Lisp_Object *lface_id_to_name; |
397 static int lface_id_to_name_size; | 402 static int lface_id_to_name_size; |
398 | 403 |
399 /* tty color-related functions (defined on lisp/term/tty-colors.el). */ | 404 /* TTY color-related functions (defined in tty-colors.el). */ |
405 | |
400 Lisp_Object Qtty_color_desc, Qtty_color_by_index; | 406 Lisp_Object Qtty_color_desc, Qtty_color_by_index; |
407 | |
408 /* The name of the function used to compute colors on TTYs. */ | |
409 | |
410 Lisp_Object Qtty_color_alist; | |
411 | |
412 /* An alist of defined terminal colors and their RGB values. */ | |
413 | |
414 Lisp_Object Vtty_defined_color_alist; | |
401 | 415 |
402 /* Counter for calls to clear_face_cache. If this counter reaches | 416 /* Counter for calls to clear_face_cache. If this counter reaches |
403 CLEAR_FONT_TABLE_COUNT, and a frame has more than | 417 CLEAR_FONT_TABLE_COUNT, and a frame has more than |
404 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */ | 418 CLEAR_FONT_TABLE_NFONTS load, unused fonts are freed. */ |
405 | 419 |
432 /* Function prototypes. */ | 446 /* Function prototypes. */ |
433 | 447 |
434 struct font_name; | 448 struct font_name; |
435 struct table_entry; | 449 struct table_entry; |
436 | 450 |
451 static void map_tty_color P_ ((struct frame *, struct face *, | |
452 enum lface_attribute_index, int *)); | |
437 static Lisp_Object resolve_face_name P_ ((Lisp_Object)); | 453 static Lisp_Object resolve_face_name P_ ((Lisp_Object)); |
438 static int may_use_scalable_font_p P_ ((struct font_name *, char *)); | 454 static int may_use_scalable_font_p P_ ((struct font_name *, char *)); |
439 static void set_font_frame_param P_ ((Lisp_Object, Lisp_Object)); | 455 static void set_font_frame_param P_ ((Lisp_Object, Lisp_Object)); |
440 static int better_font_p P_ ((int *, struct font_name *, struct font_name *, | 456 static int better_font_p P_ ((int *, struct font_name *, struct font_name *, |
441 int)); | 457 int)); |
937 Optional THOROUGHLY non-nil means try to free unused fonts, too.") | 953 Optional THOROUGHLY non-nil means try to free unused fonts, too.") |
938 (thorougly) | 954 (thorougly) |
939 Lisp_Object thorougly; | 955 Lisp_Object thorougly; |
940 { | 956 { |
941 clear_face_cache (!NILP (thorougly)); | 957 clear_face_cache (!NILP (thorougly)); |
958 ++face_change_count; | |
959 ++windows_or_buffers_changed; | |
942 return Qnil; | 960 return Qnil; |
943 } | 961 } |
944 | 962 |
945 | 963 |
946 | 964 |
1211 char *color_name; | 1229 char *color_name; |
1212 XColor *color_def; | 1230 XColor *color_def; |
1213 int alloc; | 1231 int alloc; |
1214 { | 1232 { |
1215 Lisp_Object color_desc; | 1233 Lisp_Object color_desc; |
1216 unsigned long color_idx = FACE_TTY_DEFAULT_COLOR, | 1234 unsigned long color_idx = FACE_TTY_DEFAULT_COLOR; |
1217 red = 0, green = 0, blue = 0; | 1235 unsigned long red = 0, green = 0, blue = 0; |
1218 int status = 1; | 1236 int status = 1; |
1219 | 1237 |
1220 if (*color_name && !NILP (Ffboundp (Qtty_color_desc))) | 1238 if (*color_name && !NILP (Ffboundp (Qtty_color_desc))) |
1221 { | 1239 { |
1222 Lisp_Object frame; | 1240 Lisp_Object frame; |
4370 if (!EQ (a, b)) | 4388 if (!EQ (a, b)) |
4371 { | 4389 { |
4372 switch (XTYPE (a)) | 4390 switch (XTYPE (a)) |
4373 { | 4391 { |
4374 case Lisp_String: | 4392 case Lisp_String: |
4375 equal_p = (XSTRING (a)->size == XSTRING (b)->size | 4393 equal_p = ((STRING_BYTES (XSTRING (a)) |
4394 == STRING_BYTES (XSTRING (b))) | |
4376 && bcmp (XSTRING (a)->data, XSTRING (b)->data, | 4395 && bcmp (XSTRING (a)->data, XSTRING (b)->data, |
4377 XSTRING (a)->size) == 0); | 4396 STRING_BYTES (XSTRING (a))) == 0); |
4378 break; | 4397 break; |
4379 | 4398 |
4380 case Lisp_Int: | 4399 case Lisp_Int: |
4381 case Lisp_Symbol: | 4400 case Lisp_Symbol: |
4382 equal_p = 0; | 4401 equal_p = 0; |
6071 return face; | 6090 return face; |
6072 #endif /* HAVE_WINDOW_SYSTEM */ | 6091 #endif /* HAVE_WINDOW_SYSTEM */ |
6073 } | 6092 } |
6074 | 6093 |
6075 | 6094 |
6095 /* Map a specified color of face FACE on frame F to a tty color index. | |
6096 IDX is either LFACE_FOREGROUND_INDEX or LFACE_BACKGROUND_INDEX, and | |
6097 specifies which color to map. Set *DEFAULTED to 1 if mapping to the | |
6098 default foreground/background colors. */ | |
6099 | |
6100 static void | |
6101 map_tty_color (f, face, idx, defaulted) | |
6102 struct frame *f; | |
6103 struct face *face; | |
6104 enum lface_attribute_index idx; | |
6105 int *defaulted; | |
6106 { | |
6107 Lisp_Object frame, color, def; | |
6108 int foreground_p = idx == LFACE_FOREGROUND_INDEX; | |
6109 unsigned long default_pixel, default_other_pixel, pixel; | |
6110 | |
6111 xassert (idx == LFACE_FOREGROUND_INDEX || idx == LFACE_BACKGROUND_INDEX); | |
6112 | |
6113 if (foreground_p) | |
6114 { | |
6115 pixel = default_pixel = FACE_TTY_DEFAULT_FG_COLOR; | |
6116 default_other_pixel = FACE_TTY_DEFAULT_BG_COLOR; | |
6117 } | |
6118 else | |
6119 { | |
6120 pixel = default_pixel = FACE_TTY_DEFAULT_BG_COLOR; | |
6121 default_other_pixel = FACE_TTY_DEFAULT_FG_COLOR; | |
6122 } | |
6123 | |
6124 XSETFRAME (frame, f); | |
6125 color = face->lface[idx]; | |
6126 | |
6127 if (STRINGP (color) | |
6128 && XSTRING (color)->size | |
6129 && CONSP (Vtty_defined_color_alist) | |
6130 && (def = assq_no_quit (color, call1 (Qtty_color_alist, frame)), | |
6131 CONSP (def))) | |
6132 { | |
6133 /* Associations in tty-defined-color-alist are of the form | |
6134 (NAME INDEX R G B). We need the INDEX part. */ | |
6135 pixel = XINT (XCAR (XCDR (def))); | |
6136 } | |
6137 | |
6138 if (pixel == default_pixel && STRINGP (color)) | |
6139 { | |
6140 pixel = load_color (f, face, color, idx); | |
6141 | |
6142 #if defined (MSDOS) || defined (WINDOWSNT) | |
6143 /* If the foreground of the default face is the default color, | |
6144 use the foreground color defined by the frame. */ | |
6145 #ifdef MSDOS | |
6146 if (FRAME_MSDOS_P (f)) | |
6147 { | |
6148 #endif /* MSDOS */ | |
6149 if (pixel == default_pixel | |
6150 || pixel == FACE_TTY_DEFAULT_COLOR) | |
6151 { | |
6152 if (foreground_p) | |
6153 pixel = FRAME_FOREGROUND_PIXEL (f); | |
6154 else | |
6155 pixel = FRAME_BACKGROUND_PIXEL (f); | |
6156 face->lface[idx] = tty_color_name (f, pixel); | |
6157 *defaulted = 1; | |
6158 } | |
6159 else if (pixel == default_other_pixel) | |
6160 { | |
6161 if (foreground_p) | |
6162 pixel = FRAME_BACKGROUND_PIXEL (f); | |
6163 else | |
6164 pixel = FRAME_FOREGROUND_PIXEL (f); | |
6165 face->lface[idx] = tty_color_name (f, pixel); | |
6166 *defaulted = 1; | |
6167 } | |
6168 #ifdef MSDOS | |
6169 } | |
6170 #endif | |
6171 #endif /* MSDOS or WINDOWSNT */ | |
6172 } | |
6173 | |
6174 if (foreground_p) | |
6175 face->foreground = pixel; | |
6176 else | |
6177 face->background = pixel; | |
6178 } | |
6179 | |
6180 | |
6076 /* Realize the fully-specified face with attributes ATTRS in face | 6181 /* Realize the fully-specified face with attributes ATTRS in face |
6077 cache CACHE for character C. Do it for TTY frame CACHE->f. Value is a | 6182 cache CACHE for character C. Do it for TTY frame CACHE->f. Value is a |
6078 pointer to the newly created realized face. */ | 6183 pointer to the newly created realized face. */ |
6079 | 6184 |
6080 static struct face * | 6185 static struct face * |
6083 Lisp_Object *attrs; | 6188 Lisp_Object *attrs; |
6084 int c; | 6189 int c; |
6085 { | 6190 { |
6086 struct face *face; | 6191 struct face *face; |
6087 int weight, slant; | 6192 int weight, slant; |
6088 Lisp_Object color; | |
6089 Lisp_Object tty_defined_color_alist | |
6090 = find_symbol_value (intern ("tty-defined-color-alist")); | |
6091 Lisp_Object tty_color_alist = intern ("tty-color-alist"); | |
6092 Lisp_Object frame; | |
6093 int face_colors_defaulted = 0; | 6193 int face_colors_defaulted = 0; |
6194 struct frame *f = cache->f; | |
6094 | 6195 |
6095 /* Frame must be a termcap frame. */ | 6196 /* Frame must be a termcap frame. */ |
6096 xassert (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f)); | 6197 xassert (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f)); |
6097 | 6198 |
6098 /* Allocate a new realized face. */ | 6199 /* Allocate a new realized face. */ |
6113 face->tty_underline_p = 1; | 6214 face->tty_underline_p = 1; |
6114 if (!NILP (attrs[LFACE_INVERSE_INDEX])) | 6215 if (!NILP (attrs[LFACE_INVERSE_INDEX])) |
6115 face->tty_reverse_p = 1; | 6216 face->tty_reverse_p = 1; |
6116 | 6217 |
6117 /* Map color names to color indices. */ | 6218 /* Map color names to color indices. */ |
6118 face->foreground = FACE_TTY_DEFAULT_FG_COLOR; | 6219 map_tty_color (f, face, LFACE_FOREGROUND_INDEX, &face_colors_defaulted); |
6119 face->background = FACE_TTY_DEFAULT_BG_COLOR; | 6220 map_tty_color (f, face, LFACE_BACKGROUND_INDEX, &face_colors_defaulted); |
6120 | 6221 |
6121 XSETFRAME (frame, cache->f); | |
6122 color = attrs[LFACE_FOREGROUND_INDEX]; | |
6123 if (STRINGP (color) | |
6124 && XSTRING (color)->size | |
6125 && CONSP (tty_defined_color_alist) | |
6126 && (color = Fassoc (color, call1 (tty_color_alist, frame)), | |
6127 CONSP (color))) | |
6128 /* Associations in tty-defined-color-alist are of the form | |
6129 (NAME INDEX R G B). We need the INDEX part. */ | |
6130 face->foreground = XINT (XCAR (XCDR (color))); | |
6131 | |
6132 if (face->foreground == FACE_TTY_DEFAULT_FG_COLOR | |
6133 && STRINGP (attrs[LFACE_FOREGROUND_INDEX])) | |
6134 { | |
6135 face->foreground = load_color (cache->f, face, | |
6136 attrs[LFACE_FOREGROUND_INDEX], | |
6137 LFACE_FOREGROUND_INDEX); | |
6138 | |
6139 #if defined (MSDOS) || defined (WINDOWSNT) | |
6140 /* If the foreground of the default face is the default color, | |
6141 use the foreground color defined by the frame. */ | |
6142 #ifdef MSDOS | |
6143 if (FRAME_MSDOS_P (cache->f)) | |
6144 { | |
6145 #endif /* MSDOS */ | |
6146 | |
6147 if (face->foreground == FACE_TTY_DEFAULT_FG_COLOR | |
6148 || face->foreground == FACE_TTY_DEFAULT_COLOR) | |
6149 { | |
6150 face->foreground = FRAME_FOREGROUND_PIXEL (cache->f); | |
6151 attrs[LFACE_FOREGROUND_INDEX] = | |
6152 tty_color_name (cache->f, face->foreground); | |
6153 face_colors_defaulted = 1; | |
6154 } | |
6155 else if (face->foreground == FACE_TTY_DEFAULT_BG_COLOR) | |
6156 { | |
6157 face->foreground = FRAME_BACKGROUND_PIXEL (cache->f); | |
6158 attrs[LFACE_FOREGROUND_INDEX] = | |
6159 tty_color_name (cache->f, face->foreground); | |
6160 face_colors_defaulted = 1; | |
6161 } | |
6162 #ifdef MSDOS | |
6163 } | |
6164 #endif | |
6165 #endif /* MSDOS or WINDOWSNT */ | |
6166 } | |
6167 | |
6168 color = attrs[LFACE_BACKGROUND_INDEX]; | |
6169 if (STRINGP (color) | |
6170 && XSTRING (color)->size | |
6171 && CONSP (tty_defined_color_alist) | |
6172 && (color = Fassoc (color, call1 (tty_color_alist, frame)), | |
6173 CONSP (color))) | |
6174 /* Associations in tty-defined-color-alist are of the form | |
6175 (NAME INDEX R G B). We need the INDEX part. */ | |
6176 face->background = XINT (XCAR (XCDR (color))); | |
6177 | |
6178 if (face->background == FACE_TTY_DEFAULT_BG_COLOR | |
6179 && STRINGP (attrs[LFACE_BACKGROUND_INDEX])) | |
6180 { | |
6181 face->background = load_color (cache->f, face, | |
6182 attrs[LFACE_BACKGROUND_INDEX], | |
6183 LFACE_BACKGROUND_INDEX); | |
6184 #if defined (MSDOS) || defined (WINDOWSNT) | |
6185 /* If the background of the default face is the default color, | |
6186 use the background color defined by the frame. */ | |
6187 #ifdef MSDOS | |
6188 if (FRAME_MSDOS_P (cache->f)) | |
6189 { | |
6190 #endif /* MSDOS */ | |
6191 | |
6192 if (face->background == FACE_TTY_DEFAULT_BG_COLOR | |
6193 || face->background == FACE_TTY_DEFAULT_COLOR) | |
6194 { | |
6195 face->background = FRAME_BACKGROUND_PIXEL (cache->f); | |
6196 attrs[LFACE_BACKGROUND_INDEX] = | |
6197 tty_color_name (cache->f, face->background); | |
6198 face_colors_defaulted = 1; | |
6199 } | |
6200 else if (face->background == FACE_TTY_DEFAULT_FG_COLOR) | |
6201 { | |
6202 face->background = FRAME_FOREGROUND_PIXEL (cache->f); | |
6203 attrs[LFACE_BACKGROUND_INDEX] = | |
6204 tty_color_name (cache->f, face->background); | |
6205 face_colors_defaulted = 1; | |
6206 } | |
6207 #ifdef MSDOS | |
6208 } | |
6209 #endif | |
6210 #endif /* MSDOS or WINDOWSNT */ | |
6211 } | |
6212 | |
6213 /* Swap colors if face is inverse-video. If the colors are taken | 6222 /* Swap colors if face is inverse-video. If the colors are taken |
6214 from the frame colors, they are already inverted, since the | 6223 from the frame colors, they are already inverted, since the |
6215 frame-creation function calls x-handle-reverse-video. */ | 6224 frame-creation function calls x-handle-reverse-video. */ |
6216 if (face->tty_reverse_p && !face_colors_defaulted) | 6225 if (face->tty_reverse_p && !face_colors_defaulted) |
6217 { | 6226 { |
6218 unsigned long tem = face->foreground; | 6227 unsigned long tem = face->foreground; |
6219 | |
6220 face->foreground = face->background; | 6228 face->foreground = face->background; |
6221 face->background = tem; | 6229 face->background = tem; |
6222 } | 6230 } |
6223 | 6231 |
6224 if (tty_suppress_bold_inverse_default_colors_p | 6232 if (tty_suppress_bold_inverse_default_colors_p |
6735 staticpro (&Qmouse); | 6743 staticpro (&Qmouse); |
6736 Qtty_color_desc = intern ("tty-color-desc"); | 6744 Qtty_color_desc = intern ("tty-color-desc"); |
6737 staticpro (&Qtty_color_desc); | 6745 staticpro (&Qtty_color_desc); |
6738 Qtty_color_by_index = intern ("tty-color-by-index"); | 6746 Qtty_color_by_index = intern ("tty-color-by-index"); |
6739 staticpro (&Qtty_color_by_index); | 6747 staticpro (&Qtty_color_by_index); |
6748 Qtty_color_alist = intern ("tty-color-alist"); | |
6749 staticpro (&Qtty_color_alist); | |
6740 | 6750 |
6741 Vface_alternative_font_family_alist = Qnil; | 6751 Vface_alternative_font_family_alist = Qnil; |
6742 staticpro (&Vface_alternative_font_family_alist); | 6752 staticpro (&Vface_alternative_font_family_alist); |
6743 | 6753 |
6744 defsubr (&Sinternal_make_lisp_face); | 6754 defsubr (&Sinternal_make_lisp_face); |
6785 This stipple pattern is used on monochrome displays\n\ | 6795 This stipple pattern is used on monochrome displays\n\ |
6786 instead of shades of gray for a face background color.\n\ | 6796 instead of shades of gray for a face background color.\n\ |
6787 See `set-face-stipple' for possible values for this variable."); | 6797 See `set-face-stipple' for possible values for this variable."); |
6788 Vface_default_stipple = build_string ("gray3"); | 6798 Vface_default_stipple = build_string ("gray3"); |
6789 | 6799 |
6800 DEFVAR_LISP ("tty-defined-color-alist", &Vtty_defined_color_alist, | |
6801 "An alist of defined terminal colors and their RGB values."); | |
6802 Vtty_defined_color_alist = Qnil; | |
6803 | |
6790 #if SCALABLE_FONTS | 6804 #if SCALABLE_FONTS |
6791 | 6805 |
6792 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed, | 6806 DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed, |
6793 "Allowed scalable fonts.\n\ | 6807 "Allowed scalable fonts.\n\ |
6794 A value of nil means don't allow any scalable fonts.\n\ | 6808 A value of nil means don't allow any scalable fonts.\n\ |