emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r114895: Add :distant-foreground to faces.


From: Jan D.
Subject: [Emacs-diffs] trunk r114895: Add :distant-foreground to faces.
Date: Fri, 01 Nov 2013 15:47:16 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114895
revision-id: address@hidden
parent: address@hidden
committer: Jan D. <address@hidden>
branch nick: trunk
timestamp: Fri 2013-11-01 16:47:10 +0100
message:
  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.
modified:
  doc/lispref/ChangeLog          changelog-20091113204419-o5vbwnq5f7feedwu-6155
  doc/lispref/display.texi       
display.texi-20091113204419-o5vbwnq5f7feedwu-6172
  etc/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1485
  etc/NEWS                       news-20100311060928-aoit31wvzf25yr1z-1
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/faces.el                  faces.el-20091113204419-o5vbwnq5f7feedwu-562
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/dispextern.h               
dispextern.h-20091113204419-o5vbwnq5f7feedwu-218
  src/xfaces.c                   xfaces.c-20091113204419-o5vbwnq5f7feedwu-560
=== modified file 'doc/lispref/ChangeLog'
--- a/doc/lispref/ChangeLog     2013-10-30 10:08:11 +0000
+++ b/doc/lispref/ChangeLog     2013-11-01 15:47:10 +0000
@@ -1,3 +1,7 @@
+2013-11-01  Jan Djärv  <address@hidden>
+
+       * display.texi (Face Attributes): Document :distant-foreground.
+
 2013-10-30  Xue Fuqiao  <address@hidden>
 
        * display.texi (Abstract Display): Improve indexing.

=== modified file 'doc/lispref/display.texi'
--- a/doc/lispref/display.texi  2013-10-30 10:08:11 +0000
+++ b/doc/lispref/display.texi  2013-11-01 15:47:10 +0000
@@ -2036,6 +2036,15 @@
 black-and-white displays, certain shades of gray are implemented by
 stipple patterns.
 
address@hidden :distant-foreground
+Alternative foreground color, a string.  This is like @code{:foreground}
+but the color is only used as a foreground when the background color is
+near to the foreground that would have been used.  This is useful for
+example when marking text (i.e. the region face).  If the text has a 
foreground 
+that is visible with the region face, that foreground is used.
+If the foreground is near the region face background,
address@hidden:distant-foreground} is used instead so the text is readable.
+
 @item :background
 Background color, a string.  The value can be a system-defined color
 name, or a hexadecimal color specification.  @xref{Color Names}.

=== modified file 'etc/ChangeLog'
--- a/etc/ChangeLog     2013-10-16 00:17:38 +0000
+++ b/etc/ChangeLog     2013-11-01 15:47:10 +0000
@@ -1,3 +1,7 @@
+2013-11-01  Jan Djärv  <address@hidden>
+
+       * NEWS: Mention :distant-foreground.
+
 2013-10-16  Dmitry Gutov  <address@hidden>
 
        * NEWS: Mention the homepage-related changes in package.el.

=== modified file 'etc/NEWS'
--- a/etc/NEWS  2013-10-29 16:11:50 +0000
+++ b/etc/NEWS  2013-11-01 15:47:10 +0000
@@ -788,6 +788,10 @@
 *** New face characteristic (supports :underline (:style wave))
 specifies whether or not the terminal can display a wavy line.
 
+*** New face spec attribute :distant-foreground
+specifies foreground to use if background is near the foreground that would
+otherwise have been used.
+
 ** Image API
 
 +++

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-11-01 10:27:21 +0000
+++ b/lisp/ChangeLog    2013-11-01 15:47:10 +0000
@@ -1,3 +1,8 @@
+2013-11-01  Jan Djärv  <address@hidden>
+
+       * faces.el (face-x-resources): Add :distant-foreground.
+       (region): Use :distant-foreground for gtk and ns.
+
 2013-11-01  Tassilo Horn  <address@hidden>
 
        Allow multiple bibliographies when BibLaTeX is used rathen than

=== modified file 'lisp/faces.el'
--- a/lisp/faces.el     2013-10-08 17:49:20 +0000
+++ b/lisp/faces.el     2013-11-01 15:47:10 +0000
@@ -274,6 +274,8 @@
     (:weight (".attributeWeight" . "Face.AttributeWeight"))
     (:slant (".attributeSlant" . "Face.AttributeSlant"))
     (:foreground (".attributeForeground" . "Face.AttributeForeground"))
+    (:distant-foreground
+     (".attributeDistantForeground" . "Face.AttributeDistantForeground"))
     (:background (".attributeBackground" . "Face.AttributeBackground"))
     (:overline (".attributeOverline" . "Face.AttributeOverline"))
     (:strike-through (".attributeStrikeThrough" . 
"Face.AttributeStrikeThrough"))
@@ -2255,10 +2257,10 @@
   '((((class color) (min-colors 88) (background dark))
      :background "blue3")
     (((class color) (min-colors 88) (background light) (type gtk))
-     :foreground "gtk_selection_fg_color"
+     :distant-foreground "gtk_selection_fg_color"
      :background "gtk_selection_bg_color")
     (((class color) (min-colors 88) (background light) (type ns))
-     :foreground "ns_selection_fg_color"
+     :distant-foreground "ns_selection_fg_color"
      :background "ns_selection_bg_color")
     (((class color) (min-colors 88) (background light))
      :background "lightgoldenrod2")

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-11-01 09:18:39 +0000
+++ b/src/ChangeLog     2013-11-01 15:47:10 +0000
@@ -1,3 +1,22 @@
+2013-11-01  Jan Djärv  <address@hidden>
+
+       * 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.
+
+       * dispextern.h (lface_attribute_index): Add
+       LFACE_DISTANT_FOREGROUND_INDEX.
+
 2013-11-01  Claudio Bley  <address@hidden>
 
        * image.c (pbm_next_char): New function.  See

=== modified file 'src/dispextern.h'
--- a/src/dispextern.h  2013-10-29 16:11:50 +0000
+++ b/src/dispextern.h  2013-11-01 15:47:10 +0000
@@ -1543,6 +1543,7 @@
   LFACE_FONT_INDEX,
   LFACE_INHERIT_INDEX,
   LFACE_FONTSET_INDEX,
+  LFACE_DISTANT_FOREGROUND_INDEX,
   LFACE_VECTOR_SIZE
 };
 

=== modified file 'src/xfaces.c'
--- a/src/xfaces.c      2013-10-29 16:11:50 +0000
+++ b/src/xfaces.c      2013-11-01 15:47:10 +0000
@@ -292,7 +292,7 @@
 static Lisp_Object QCfont, QCbold, QCitalic;
 static Lisp_Object QCreverse_video;
 static Lisp_Object QCoverline, QCstrike_through, QCbox, QCinherit;
-static Lisp_Object QCfontset;
+static Lisp_Object QCfontset, QCdistant_foreground;
 
 /* Symbols used for attribute values.  */
 
@@ -440,6 +440,7 @@
 static void free_face_cache (struct face_cache *);
 static int merge_face_ref (struct frame *, Lisp_Object, Lisp_Object *,
                           int, struct named_merge_point *);
+static int color_distance (XColor *x, XColor *y);
 
 #ifdef HAVE_WINDOW_SYSTEM
 static void set_font_frame_param (Lisp_Object, Lisp_Object);
@@ -910,6 +911,8 @@
                                X Colors
  ***********************************************************************/
 
+#define NEAR_SAME_COLOR_THRESHOLD 30000
+
 /* Parse RGB_LIST, and fill in the RGB fields of COLOR.
    RGB_LIST should contain (at least) 3 lisp integers.
    Return 0 if there's a problem with RGB_LIST, otherwise return 1.  */
@@ -1176,24 +1179,10 @@
 }
 
 
-/* Load color with name NAME for use by face FACE on frame F.
-   TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
-   LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
-   LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX.  Value is the
-   pixel color.  If color cannot be loaded, display a message, and
-   return the foreground, background or underline color of F, but
-   record that fact in flags of the face so that we don't try to free
-   these colors.  */
-
-#ifndef MSDOS
-static
-#endif
-unsigned long
-load_color (struct frame *f, struct face *face, Lisp_Object name,
-           enum lface_attribute_index target_index)
+static unsigned long
+load_color2 (struct frame *f, struct face *face, Lisp_Object name,
+             enum lface_attribute_index target_index, XColor *color)
 {
-  XColor color;
-
   eassert (STRINGP (name));
   eassert (target_index == LFACE_FOREGROUND_INDEX
           || target_index == LFACE_BACKGROUND_INDEX
@@ -1204,7 +1193,7 @@
 
   /* if the color map is full, defined_color will return a best match
      to the values in an existing cell. */
-  if (!defined_color (f, SSDATA (name), &color, 1))
+  if (!defined_color (f, SSDATA (name), color, 1))
     {
       add_to_log ("Unable to load color \"%s\"", name, Qnil);
 
@@ -1212,32 +1201,32 @@
        {
        case LFACE_FOREGROUND_INDEX:
          face->foreground_defaulted_p = 1;
-         color.pixel = FRAME_FOREGROUND_PIXEL (f);
+         color->pixel = FRAME_FOREGROUND_PIXEL (f);
          break;
 
        case LFACE_BACKGROUND_INDEX:
          face->background_defaulted_p = 1;
-         color.pixel = FRAME_BACKGROUND_PIXEL (f);
+         color->pixel = FRAME_BACKGROUND_PIXEL (f);
          break;
 
        case LFACE_UNDERLINE_INDEX:
          face->underline_defaulted_p = 1;
-         color.pixel = FRAME_FOREGROUND_PIXEL (f);
+         color->pixel = FRAME_FOREGROUND_PIXEL (f);
          break;
 
        case LFACE_OVERLINE_INDEX:
          face->overline_color_defaulted_p = 1;
-         color.pixel = FRAME_FOREGROUND_PIXEL (f);
+         color->pixel = FRAME_FOREGROUND_PIXEL (f);
          break;
 
        case LFACE_STRIKE_THROUGH_INDEX:
          face->strike_through_color_defaulted_p = 1;
-         color.pixel = FRAME_FOREGROUND_PIXEL (f);
+         color->pixel = FRAME_FOREGROUND_PIXEL (f);
          break;
 
        case LFACE_BOX_INDEX:
          face->box_color_defaulted_p = 1;
-         color.pixel = FRAME_FOREGROUND_PIXEL (f);
+         color->pixel = FRAME_FOREGROUND_PIXEL (f);
          break;
 
        default:
@@ -1249,7 +1238,27 @@
     ++ncolors_allocated;
 #endif
 
-  return color.pixel;
+  return color->pixel;
+}
+
+/* Load color with name NAME for use by face FACE on frame F.
+   TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX,
+   LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX,
+   LFACE_STRIKE_THROUGH_INDEX, or LFACE_BOX_INDEX.  Value is the
+   pixel color.  If color cannot be loaded, display a message, and
+   return the foreground, background or underline color of F, but
+   record that fact in flags of the face so that we don't try to free
+   these colors.  */
+
+#ifndef MSDOS
+static
+#endif
+unsigned long
+load_color (struct frame *f, struct face *face, Lisp_Object name,
+           enum lface_attribute_index target_index)
+{
+  XColor color;
+  return load_color2 (f, face, name, target_index, &color);
 }
 
 
@@ -1264,7 +1273,8 @@
 load_face_colors (struct frame *f, struct face *face,
                  Lisp_Object attrs[LFACE_VECTOR_SIZE])
 {
-  Lisp_Object fg, bg;
+  Lisp_Object fg, bg, dfg;
+  XColor xfg, xbg;
 
   bg = attrs[LFACE_BACKGROUND_INDEX];
   fg = attrs[LFACE_FOREGROUND_INDEX];
@@ -1289,8 +1299,18 @@
       face->stipple = load_pixmap (f, Vface_default_stipple);
     }
 
-  face->background = load_color (f, face, bg, LFACE_BACKGROUND_INDEX);
-  face->foreground = load_color (f, face, fg, LFACE_FOREGROUND_INDEX);
+  face->background = load_color2 (f, face, bg, LFACE_BACKGROUND_INDEX, &xbg);
+  face->foreground = load_color2 (f, face, fg, LFACE_FOREGROUND_INDEX, &xfg);
+
+  dfg = attrs[LFACE_DISTANT_FOREGROUND_INDEX];
+  if (!NILP (dfg) && !UNSPECIFIEDP (dfg)
+      && color_distance (&xbg, &xfg) < NEAR_SAME_COLOR_THRESHOLD)
+    {
+      if (EQ (attrs[LFACE_INVERSE_INDEX], Qt))
+        face->background = load_color (f, face, dfg, LFACE_BACKGROUND_INDEX);
+      else
+        face->foreground = load_color (f, face, dfg, LFACE_FOREGROUND_INDEX);
+    }
 }
 
 #ifdef HAVE_X_WINDOWS
@@ -1721,6 +1741,8 @@
 #define LFACE_FONT(LFACE)          AREF ((LFACE), LFACE_FONT_INDEX)
 #define LFACE_INHERIT(LFACE)       AREF ((LFACE), LFACE_INHERIT_INDEX)
 #define LFACE_FONTSET(LFACE)       AREF ((LFACE), LFACE_FONTSET_INDEX)
+#define LFACE_DISTANT_FOREGROUND(LFACE) \
+  AREF ((LFACE), LFACE_DISTANT_FOREGROUND_INDEX)
 
 /* Non-zero if LFACE is a Lisp face.  A Lisp face is a vector of size
    LFACE_VECTOR_SIZE which has the symbol `face' in slot 0.  */
@@ -2449,6 +2471,13 @@
                  else
                    err = 1;
                }
+             else if (EQ (keyword, QCdistant_foreground))
+               {
+                 if (STRINGP (value))
+                   to[LFACE_DISTANT_FOREGROUND_INDEX] = value;
+                 else
+                   err = 1;
+               }
              else if (EQ (keyword, QCbackground))
                {
                  if (STRINGP (value))
@@ -3005,6 +3034,23 @@
       old_value = LFACE_FOREGROUND (lface);
       ASET (lface, LFACE_FOREGROUND_INDEX, value);
     }
+  else if (EQ (attr, QCdistant_foreground))
+    {
+      /* Compatibility with 20.x.  */
+      if (NILP (value))
+       value = Qunspecified;
+      if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
+       {
+         /* Don't check for valid color names here because it depends
+            on the frame (display) whether the color will be valid
+            when the face is realized.  */
+         CHECK_STRING (value);
+         if (SCHARS (value) == 0)
+           signal_error ("Empty distant-foreground color value", value);
+       }
+      old_value = LFACE_DISTANT_FOREGROUND (lface);
+      ASET (lface, LFACE_DISTANT_FOREGROUND_INDEX, value);
+    }
   else if (EQ (attr, QCbackground))
     {
       /* Compatibility with 20.x.  */
@@ -3649,6 +3695,8 @@
     value = LFACE_INVERSE (lface);
   else if (EQ (keyword, QCforeground))
     value = LFACE_FOREGROUND (lface);
+  else if (EQ (keyword, QCdistant_foreground))
+    value = LFACE_DISTANT_FOREGROUND (lface);
   else if (EQ (keyword, QCbackground))
     value = LFACE_BACKGROUND (lface);
   else if (EQ (keyword, QCstipple))
@@ -4688,6 +4736,9 @@
       || (!UNSPECIFIEDP (attrs[LFACE_FOREGROUND_INDEX])
          && face_attr_equal_p (attrs[LFACE_FOREGROUND_INDEX],
                                def_attrs[LFACE_FOREGROUND_INDEX]))
+      || (!UNSPECIFIEDP (attrs[LFACE_DISTANT_FOREGROUND_INDEX])
+         && face_attr_equal_p (attrs[LFACE_DISTANT_FOREGROUND_INDEX],
+                               def_attrs[LFACE_DISTANT_FOREGROUND_INDEX]))
       || (!UNSPECIFIEDP (attrs[LFACE_BACKGROUND_INDEX])
          && face_attr_equal_p (attrs[LFACE_BACKGROUND_INDEX],
                                def_attrs[LFACE_BACKGROUND_INDEX]))
@@ -6361,6 +6412,7 @@
   DEFSYM (QCwidth, ":width");
   DEFSYM (QCfont, ":font");
   DEFSYM (QCfontset, ":fontset");
+  DEFSYM (QCdistant_foreground, ":distant-foreground");
   DEFSYM (QCbold, ":bold");
   DEFSYM (QCitalic, ":italic");
   DEFSYM (QCoverline, ":overline");


reply via email to

[Prev in Thread] Current Thread [Next in Thread]