diff options
| author | Jan Djärv | 2013-11-01 16:47:10 +0100 |
|---|---|---|
| committer | Jan Djärv | 2013-11-01 16:47:10 +0100 |
| commit | 3c334c1412e708585fddba61b7f91e0902a830f4 (patch) | |
| tree | fb063b9f306719816335d12601735648e4fbba41 /src | |
| parent | 9bc236c8263bc81f1b540579a9f98d872ab2da46 (diff) | |
| download | emacs-3c334c1412e708585fddba61b7f91e0902a830f4.tar.gz emacs-3c334c1412e708585fddba61b7f91e0902a830f4.zip | |
Add :distant-foreground to faces.
* doc/lispref/display.texi (Face Attributes): Document :distant-foreground.
* etc/NEWS: Mention :distant-foreground.
* lisp/faces.el (face-x-resources): Add :distant-foreground.
(region): Use :distant-foreground for gtk and ns.
* src/dispextern.h (lface_attribute_index): Add
LFACE_DISTANT_FOREGROUND_INDEX.
* src/xfaces.c: Declare color_distance.
(QCdistant_foreground): New variable.
(NEAR_SAME_COLOR_THRESHOLD): New define.
(load_color2): New function.
(load_color): Call load_color2.
(load_face_colors): Call load_color2 and if distant-color is specified
calculate distant and use distant-color if colors are near.
(LFACE_DISTANT_FOREGROUND): New define.
(merge_face_ref, Finternal_set_lisp_face_attribute)
(Finternal_get_lisp_face_attribute)
(x_supports_face_attributes_p): Handle distant-foreground similar to
foreground.
(syms_of_xfaces): DEFSYM QCdistant_foreground.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 19 | ||||
| -rw-r--r-- | src/dispextern.h | 1 | ||||
| -rw-r--r-- | src/xfaces.c | 110 |
3 files changed, 101 insertions, 29 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index d7cf7d47b0b..8186e220d7d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,22 @@ | |||
| 1 | 2013-11-01 Jan Djärv <jan.h.d@swipnet.se> | ||
| 2 | |||
| 3 | * xfaces.c: Declare color_distance. | ||
| 4 | (QCdistant_foreground): New variable. | ||
| 5 | (NEAR_SAME_COLOR_THRESHOLD): New define. | ||
| 6 | (load_color2): New function. | ||
| 7 | (load_color): Call load_color2. | ||
| 8 | (load_face_colors): Call load_color2 and if distant-color is specified | ||
| 9 | calculate distant and use distant-color if colors are near. | ||
| 10 | (LFACE_DISTANT_FOREGROUND): New define. | ||
| 11 | (merge_face_ref, Finternal_set_lisp_face_attribute) | ||
| 12 | (Finternal_get_lisp_face_attribute) | ||
| 13 | (x_supports_face_attributes_p): Handle distant-foreground similar to | ||
| 14 | foreground. | ||
| 15 | (syms_of_xfaces): DEFSYM QCdistant_foreground. | ||
| 16 | |||
| 17 | * dispextern.h (lface_attribute_index): Add | ||
| 18 | LFACE_DISTANT_FOREGROUND_INDEX. | ||
| 19 | |||
| 1 | 2013-11-01 Claudio Bley <claudio.bley@googlemail.com> | 20 | 2013-11-01 Claudio Bley <claudio.bley@googlemail.com> |
| 2 | 21 | ||
| 3 | * image.c (pbm_next_char): New function. See | 22 | * image.c (pbm_next_char): New function. See |
diff --git a/src/dispextern.h b/src/dispextern.h index dd64ae1921f..22357a01c84 100644 --- a/src/dispextern.h +++ b/src/dispextern.h | |||
| @@ -1543,6 +1543,7 @@ enum lface_attribute_index | |||
| 1543 | LFACE_FONT_INDEX, | 1543 | LFACE_FONT_INDEX, |
| 1544 | LFACE_INHERIT_INDEX, | 1544 | LFACE_INHERIT_INDEX, |
| 1545 | LFACE_FONTSET_INDEX, | 1545 | LFACE_FONTSET_INDEX, |
| 1546 | LFACE_DISTANT_FOREGROUND_INDEX, | ||
| 1546 | LFACE_VECTOR_SIZE | 1547 | LFACE_VECTOR_SIZE |
| 1547 | }; | 1548 | }; |
| 1548 | 1549 | ||
diff --git a/src/xfaces.c b/src/xfaces.c index f50fffc6419..72b62216abd 100644 --- a/src/xfaces.c +++ b/src/xfaces.c | |||
| @@ -292,7 +292,7 @@ Lisp_Object QCwidth; | |||
| 292 | static Lisp_Object QCfont, QCbold, QCitalic; | 292 | static Lisp_Object QCfont, QCbold, QCitalic; |
| 293 | static Lisp_Object QCreverse_video; | 293 | static Lisp_Object QCreverse_video; |
| 294 | static Lisp_Object QCoverline, QCstrike_through, QCbox, QCinherit; | 294 | static Lisp_Object QCoverline, QCstrike_through, QCbox, QCinherit; |
| 295 | static Lisp_Object QCfontset; | 295 | static Lisp_Object QCfontset, QCdistant_foreground; |
| 296 | 296 | ||
| 297 | /* Symbols used for attribute values. */ | 297 | /* Symbols used for attribute values. */ |
| 298 | 298 | ||
| @@ -440,6 +440,7 @@ static struct face_cache *make_face_cache (struct frame *); | |||
| 440 | static void free_face_cache (struct face_cache *); | 440 | static void free_face_cache (struct face_cache *); |
| 441 | static int merge_face_ref (struct frame *, Lisp_Object, Lisp_Object *, | 441 | static int merge_face_ref (struct frame *, Lisp_Object, Lisp_Object *, |
| 442 | int, struct named_merge_point *); | 442 | int, struct named_merge_point *); |
| 443 | static int color_distance (XColor *x, XColor *y); | ||
| 443 | 444 | ||
| 444 | #ifdef HAVE_WINDOW_SYSTEM | 445 | #ifdef HAVE_WINDOW_SYSTEM |
| 445 | static void set_font_frame_param (Lisp_Object, Lisp_Object); | 446 | static void set_font_frame_param (Lisp_Object, Lisp_Object); |
| @@ -910,6 +911,8 @@ load_pixmap (struct frame *f, Lisp_Object name) | |||
| 910 | X Colors | 911 | X Colors |
| 911 | ***********************************************************************/ | 912 | ***********************************************************************/ |
| 912 | 913 | ||
| 914 | #define NEAR_SAME_COLOR_THRESHOLD 30000 | ||
| 915 | |||
| 913 | /* Parse RGB_LIST, and fill in the RGB fields of COLOR. | 916 | /* Parse RGB_LIST, and fill in the RGB fields of COLOR. |
| 914 | RGB_LIST should contain (at least) 3 lisp integers. | 917 | RGB_LIST should contain (at least) 3 lisp integers. |
| 915 | Return 0 if there's a problem with RGB_LIST, otherwise return 1. */ | 918 | Return 0 if there's a problem with RGB_LIST, otherwise return 1. */ |
| @@ -1176,24 +1179,10 @@ COLOR must be a valid color name. */) | |||
| 1176 | } | 1179 | } |
| 1177 | 1180 | ||
| 1178 | 1181 | ||
| 1179 | /* Load color with name NAME for use by face FACE on frame F. | 1182 | static unsigned long |
| 1180 | TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX, | 1183 | load_color2 (struct frame *f, struct face *face, Lisp_Object name, |
| 1181 | LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX, | 1184 | enum lface_attribute_index target_index, XColor *color) |
| 1182 | LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the | ||
| 1183 | pixel color. If color cannot be loaded, display a message, and | ||
| 1184 | return the foreground, background or underline color of F, but | ||
| 1185 | record that fact in flags of the face so that we don't try to free | ||
| 1186 | these colors. */ | ||
| 1187 | |||
| 1188 | #ifndef MSDOS | ||
| 1189 | static | ||
| 1190 | #endif | ||
| 1191 | unsigned long | ||
| 1192 | load_color (struct frame *f, struct face *face, Lisp_Object name, | ||
| 1193 | enum lface_attribute_index target_index) | ||
| 1194 | { | 1185 | { |
| 1195 | XColor color; | ||
| 1196 | |||
| 1197 | eassert (STRINGP (name)); | 1186 | eassert (STRINGP (name)); |
| 1198 | eassert (target_index == LFACE_FOREGROUND_INDEX | 1187 | eassert (target_index == LFACE_FOREGROUND_INDEX |
| 1199 | || target_index == LFACE_BACKGROUND_INDEX | 1188 | || target_index == LFACE_BACKGROUND_INDEX |
| @@ -1204,7 +1193,7 @@ load_color (struct frame *f, struct face *face, Lisp_Object name, | |||
| 1204 | 1193 | ||
| 1205 | /* if the color map is full, defined_color will return a best match | 1194 | /* if the color map is full, defined_color will return a best match |
| 1206 | to the values in an existing cell. */ | 1195 | to the values in an existing cell. */ |
| 1207 | if (!defined_color (f, SSDATA (name), &color, 1)) | 1196 | if (!defined_color (f, SSDATA (name), color, 1)) |
| 1208 | { | 1197 | { |
| 1209 | add_to_log ("Unable to load color \"%s\"", name, Qnil); | 1198 | add_to_log ("Unable to load color \"%s\"", name, Qnil); |
| 1210 | 1199 | ||
| @@ -1212,32 +1201,32 @@ load_color (struct frame *f, struct face *face, Lisp_Object name, | |||
| 1212 | { | 1201 | { |
| 1213 | case LFACE_FOREGROUND_INDEX: | 1202 | case LFACE_FOREGROUND_INDEX: |
| 1214 | face->foreground_defaulted_p = 1; | 1203 | face->foreground_defaulted_p = 1; |
| 1215 | color.pixel = FRAME_FOREGROUND_PIXEL (f); | 1204 | color->pixel = FRAME_FOREGROUND_PIXEL (f); |
| 1216 | break; | 1205 | break; |
| 1217 | 1206 | ||
| 1218 | case LFACE_BACKGROUND_INDEX: | 1207 | case LFACE_BACKGROUND_INDEX: |
| 1219 | face->background_defaulted_p = 1; | 1208 | face->background_defaulted_p = 1; |
| 1220 | color.pixel = FRAME_BACKGROUND_PIXEL (f); | 1209 | color->pixel = FRAME_BACKGROUND_PIXEL (f); |
| 1221 | break; | 1210 | break; |
| 1222 | 1211 | ||
| 1223 | case LFACE_UNDERLINE_INDEX: | 1212 | case LFACE_UNDERLINE_INDEX: |
| 1224 | face->underline_defaulted_p = 1; | 1213 | face->underline_defaulted_p = 1; |
| 1225 | color.pixel = FRAME_FOREGROUND_PIXEL (f); | 1214 | color->pixel = FRAME_FOREGROUND_PIXEL (f); |
| 1226 | break; | 1215 | break; |
| 1227 | 1216 | ||
| 1228 | case LFACE_OVERLINE_INDEX: | 1217 | case LFACE_OVERLINE_INDEX: |
| 1229 | face->overline_color_defaulted_p = 1; | 1218 | face->overline_color_defaulted_p = 1; |
| 1230 | color.pixel = FRAME_FOREGROUND_PIXEL (f); | 1219 | color->pixel = FRAME_FOREGROUND_PIXEL (f); |
| 1231 | break; | 1220 | break; |
| 1232 | 1221 | ||
| 1233 | case LFACE_STRIKE_THROUGH_INDEX: | 1222 | case LFACE_STRIKE_THROUGH_INDEX: |
| 1234 | face->strike_through_color_defaulted_p = 1; | 1223 | face->strike_through_color_defaulted_p = 1; |
| 1235 | color.pixel = FRAME_FOREGROUND_PIXEL (f); | 1224 | color->pixel = FRAME_FOREGROUND_PIXEL (f); |
| 1236 | break; | 1225 | break; |
| 1237 | 1226 | ||
| 1238 | case LFACE_BOX_INDEX: | 1227 | case LFACE_BOX_INDEX: |
| 1239 | face->box_color_defaulted_p = 1; | 1228 | face->box_color_defaulted_p = 1; |
| 1240 | color.pixel = FRAME_FOREGROUND_PIXEL (f); | 1229 | color->pixel = FRAME_FOREGROUND_PIXEL (f); |
| 1241 | break; | 1230 | break; |
| 1242 | 1231 | ||
| 1243 | default: | 1232 | default: |
| @@ -1249,7 +1238,27 @@ load_color (struct frame *f, struct face *face, Lisp_Object name, | |||
| 1249 | ++ncolors_allocated; | 1238 | ++ncolors_allocated; |
| 1250 | #endif | 1239 | #endif |
| 1251 | 1240 | ||
| 1252 | return color.pixel; | 1241 | return color->pixel; |
| 1242 | } | ||
| 1243 | |||
| 1244 | /* Load color with name NAME for use by face FACE on frame F. | ||
| 1245 | TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX, | ||
| 1246 | LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX, | ||
| 1247 | LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX. Value is the | ||
| 1248 | pixel color. If color cannot be loaded, display a message, and | ||
| 1249 | return the foreground, background or underline color of F, but | ||
| 1250 | record that fact in flags of the face so that we don't try to free | ||
| 1251 | these colors. */ | ||
| 1252 | |||
| 1253 | #ifndef MSDOS | ||
| 1254 | static | ||
| 1255 | #endif | ||
| 1256 | unsigned long | ||
| 1257 | load_color (struct frame *f, struct face *face, Lisp_Object name, | ||
| 1258 | enum lface_attribute_index target_index) | ||
| 1259 | { | ||
| 1260 | XColor color; | ||
| 1261 | return load_color2 (f, face, name, target_index, &color); | ||
| 1253 | } | 1262 | } |
| 1254 | 1263 | ||
| 1255 | 1264 | ||
| @@ -1264,7 +1273,8 @@ static void | |||
| 1264 | load_face_colors (struct frame *f, struct face *face, | 1273 | load_face_colors (struct frame *f, struct face *face, |
| 1265 | Lisp_Object attrs[LFACE_VECTOR_SIZE]) | 1274 | Lisp_Object attrs[LFACE_VECTOR_SIZE]) |
| 1266 | { | 1275 | { |
| 1267 | Lisp_Object fg, bg; | 1276 | Lisp_Object fg, bg, dfg; |
| 1277 | XColor xfg, xbg; | ||
| 1268 | 1278 | ||
| 1269 | bg = attrs[LFACE_BACKGROUND_INDEX]; | 1279 | bg = attrs[LFACE_BACKGROUND_INDEX]; |
| 1270 | fg = attrs[LFACE_FOREGROUND_INDEX]; | 1280 | fg = attrs[LFACE_FOREGROUND_INDEX]; |
| @@ -1289,8 +1299,18 @@ load_face_colors (struct frame *f, struct face *face, | |||
| 1289 | face->stipple = load_pixmap (f, Vface_default_stipple); | 1299 | face->stipple = load_pixmap (f, Vface_default_stipple); |
| 1290 | } | 1300 | } |
| 1291 | 1301 | ||
| 1292 | face->background = load_color (f, face, bg, LFACE_BACKGROUND_INDEX); | 1302 | face->background = load_color2 (f, face, bg, LFACE_BACKGROUND_INDEX, &xbg); |
| 1293 | face->foreground = load_color (f, face, fg, LFACE_FOREGROUND_INDEX); | 1303 | face->foreground = load_color2 (f, face, fg, LFACE_FOREGROUND_INDEX, &xfg); |
| 1304 | |||
| 1305 | dfg = attrs[LFACE_DISTANT_FOREGROUND_INDEX]; | ||
| 1306 | if (!NILP (dfg) && !UNSPECIFIEDP (dfg) | ||
| 1307 | && color_distance (&xbg, &xfg) < NEAR_SAME_COLOR_THRESHOLD) | ||
| 1308 | { | ||
| 1309 | if (EQ (attrs[LFACE_INVERSE_INDEX], Qt)) | ||
| 1310 | face->background = load_color (f, face, dfg, LFACE_BACKGROUND_INDEX); | ||
| 1311 | else | ||
| 1312 | face->foreground = load_color (f, face, dfg, LFACE_FOREGROUND_INDEX); | ||
| 1313 | } | ||
| 1294 | } | 1314 | } |
| 1295 | 1315 | ||
| 1296 | #ifdef HAVE_X_WINDOWS | 1316 | #ifdef HAVE_X_WINDOWS |
| @@ -1721,6 +1741,8 @@ the WIDTH times as wide as FACE on FRAME. */) | |||
| 1721 | #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX) | 1741 | #define LFACE_FONT(LFACE) AREF ((LFACE), LFACE_FONT_INDEX) |
| 1722 | #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX) | 1742 | #define LFACE_INHERIT(LFACE) AREF ((LFACE), LFACE_INHERIT_INDEX) |
| 1723 | #define LFACE_FONTSET(LFACE) AREF ((LFACE), LFACE_FONTSET_INDEX) | 1743 | #define LFACE_FONTSET(LFACE) AREF ((LFACE), LFACE_FONTSET_INDEX) |
| 1744 | #define LFACE_DISTANT_FOREGROUND(LFACE) \ | ||
| 1745 | AREF ((LFACE), LFACE_DISTANT_FOREGROUND_INDEX) | ||
| 1724 | 1746 | ||
| 1725 | /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size | 1747 | /* Non-zero if LFACE is a Lisp face. A Lisp face is a vector of size |
| 1726 | LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */ | 1748 | LFACE_VECTOR_SIZE which has the symbol `face' in slot 0. */ |
| @@ -2449,6 +2471,13 @@ merge_face_ref (struct frame *f, Lisp_Object face_ref, Lisp_Object *to, | |||
| 2449 | else | 2471 | else |
| 2450 | err = 1; | 2472 | err = 1; |
| 2451 | } | 2473 | } |
| 2474 | else if (EQ (keyword, QCdistant_foreground)) | ||
| 2475 | { | ||
| 2476 | if (STRINGP (value)) | ||
| 2477 | to[LFACE_DISTANT_FOREGROUND_INDEX] = value; | ||
| 2478 | else | ||
| 2479 | err = 1; | ||
| 2480 | } | ||
| 2452 | else if (EQ (keyword, QCbackground)) | 2481 | else if (EQ (keyword, QCbackground)) |
| 2453 | { | 2482 | { |
| 2454 | if (STRINGP (value)) | 2483 | if (STRINGP (value)) |
| @@ -3005,6 +3034,23 @@ FRAME 0 means change the face on all frames, and change the default | |||
| 3005 | old_value = LFACE_FOREGROUND (lface); | 3034 | old_value = LFACE_FOREGROUND (lface); |
| 3006 | ASET (lface, LFACE_FOREGROUND_INDEX, value); | 3035 | ASET (lface, LFACE_FOREGROUND_INDEX, value); |
| 3007 | } | 3036 | } |
| 3037 | else if (EQ (attr, QCdistant_foreground)) | ||
| 3038 | { | ||
| 3039 | /* Compatibility with 20.x. */ | ||
| 3040 | if (NILP (value)) | ||
| 3041 | value = Qunspecified; | ||
| 3042 | if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value)) | ||
| 3043 | { | ||
| 3044 | /* Don't check for valid color names here because it depends | ||
| 3045 | on the frame (display) whether the color will be valid | ||
| 3046 | when the face is realized. */ | ||
| 3047 | CHECK_STRING (value); | ||
| 3048 | if (SCHARS (value) == 0) | ||
| 3049 | signal_error ("Empty distant-foreground color value", value); | ||
| 3050 | } | ||
| 3051 | old_value = LFACE_DISTANT_FOREGROUND (lface); | ||
| 3052 | ASET (lface, LFACE_DISTANT_FOREGROUND_INDEX, value); | ||
| 3053 | } | ||
| 3008 | else if (EQ (attr, QCbackground)) | 3054 | else if (EQ (attr, QCbackground)) |
| 3009 | { | 3055 | { |
| 3010 | /* Compatibility with 20.x. */ | 3056 | /* Compatibility with 20.x. */ |
| @@ -3649,6 +3695,8 @@ frames). If FRAME is omitted or nil, use the selected frame. */) | |||
| 3649 | value = LFACE_INVERSE (lface); | 3695 | value = LFACE_INVERSE (lface); |
| 3650 | else if (EQ (keyword, QCforeground)) | 3696 | else if (EQ (keyword, QCforeground)) |
| 3651 | value = LFACE_FOREGROUND (lface); | 3697 | value = LFACE_FOREGROUND (lface); |
| 3698 | else if (EQ (keyword, QCdistant_foreground)) | ||
| 3699 | value = LFACE_DISTANT_FOREGROUND (lface); | ||
| 3652 | else if (EQ (keyword, QCbackground)) | 3700 | else if (EQ (keyword, QCbackground)) |
| 3653 | value = LFACE_BACKGROUND (lface); | 3701 | value = LFACE_BACKGROUND (lface); |
| 3654 | else if (EQ (keyword, QCstipple)) | 3702 | else if (EQ (keyword, QCstipple)) |
| @@ -4688,6 +4736,9 @@ x_supports_face_attributes_p (struct frame *f, | |||
| 4688 | || (!UNSPECIFIEDP (attrs[LFACE_FOREGROUND_INDEX]) | 4736 | || (!UNSPECIFIEDP (attrs[LFACE_FOREGROUND_INDEX]) |
| 4689 | && face_attr_equal_p (attrs[LFACE_FOREGROUND_INDEX], | 4737 | && face_attr_equal_p (attrs[LFACE_FOREGROUND_INDEX], |
| 4690 | def_attrs[LFACE_FOREGROUND_INDEX])) | 4738 | def_attrs[LFACE_FOREGROUND_INDEX])) |
| 4739 | || (!UNSPECIFIEDP (attrs[LFACE_DISTANT_FOREGROUND_INDEX]) | ||
| 4740 | && face_attr_equal_p (attrs[LFACE_DISTANT_FOREGROUND_INDEX], | ||
| 4741 | def_attrs[LFACE_DISTANT_FOREGROUND_INDEX])) | ||
| 4691 | || (!UNSPECIFIEDP (attrs[LFACE_BACKGROUND_INDEX]) | 4742 | || (!UNSPECIFIEDP (attrs[LFACE_BACKGROUND_INDEX]) |
| 4692 | && face_attr_equal_p (attrs[LFACE_BACKGROUND_INDEX], | 4743 | && face_attr_equal_p (attrs[LFACE_BACKGROUND_INDEX], |
| 4693 | def_attrs[LFACE_BACKGROUND_INDEX])) | 4744 | def_attrs[LFACE_BACKGROUND_INDEX])) |
| @@ -6361,6 +6412,7 @@ syms_of_xfaces (void) | |||
| 6361 | DEFSYM (QCwidth, ":width"); | 6412 | DEFSYM (QCwidth, ":width"); |
| 6362 | DEFSYM (QCfont, ":font"); | 6413 | DEFSYM (QCfont, ":font"); |
| 6363 | DEFSYM (QCfontset, ":fontset"); | 6414 | DEFSYM (QCfontset, ":fontset"); |
| 6415 | DEFSYM (QCdistant_foreground, ":distant-foreground"); | ||
| 6364 | DEFSYM (QCbold, ":bold"); | 6416 | DEFSYM (QCbold, ":bold"); |
| 6365 | DEFSYM (QCitalic, ":italic"); | 6417 | DEFSYM (QCitalic, ":italic"); |
| 6366 | DEFSYM (QCoverline, ":overline"); | 6418 | DEFSYM (QCoverline, ":overline"); |