changeset 72505:759e19ea81e5

(x_underline_at_descent_line): New variable. (syms_of_xterm): DEFVAR_BOOL it. (x_draw_glyph_string): Use it. Draw underline and overline up to the end of line if the face extends to the end of line.
author Kim F. Storm <storm@cua.dk>
date Thu, 24 Aug 2006 20:52:00 +0000
parents 27c305d70c67
children 2434e33b748e
files src/macterm.c src/w32term.c src/xterm.c
diffstat 3 files changed, 65 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/macterm.c	Thu Aug 24 20:51:17 2006 +0000
+++ b/src/macterm.c	Thu Aug 24 20:52:00 2006 +0000
@@ -3679,14 +3679,14 @@
 
 	  if (s->face->underline_defaulted_p)
 	    mac_fill_rectangle (s->f, s->gc, s->x, s->y + dy,
-				s->width, h);
+				s->background_width, h);
 	  else
 	    {
 	      XGCValues xgcv;
 	      XGetGCValues (s->display, s->gc, GCForeground, &xgcv);
 	      XSetForeground (s->display, s->gc, s->face->underline_color);
 	      mac_fill_rectangle (s->f, s->gc, s->x, s->y + dy,
-				  s->width, h);
+				  s->background_width, h);
 	      XSetForeground (s->display, s->gc, xgcv.foreground);
 	    }
 	}
@@ -3698,14 +3698,14 @@
 
 	  if (s->face->overline_color_defaulted_p)
 	    mac_fill_rectangle (s->f, s->gc, s->x, s->y + dy,
-				s->width, h);
+				s->background_width, h);
 	  else
 	    {
 	      XGCValues xgcv;
 	      XGetGCValues (s->display, s->gc, GCForeground, &xgcv);
 	      XSetForeground (s->display, s->gc, s->face->overline_color);
 	      mac_fill_rectangle (s->f, s->gc, s->x, s->y + dy,
-				  s->width, h);
+				  s->background_width, h);
 	      XSetForeground (s->display, s->gc, xgcv.foreground);
 	    }
 	}
--- a/src/w32term.c	Thu Aug 24 20:51:17 2006 +0000
+++ b/src/w32term.c	Thu Aug 24 20:52:00 2006 +0000
@@ -91,6 +91,10 @@
    (Not yet supported, see TODO in x_draw_glyph_string.)  */
 int x_use_underline_position_properties;
 
+/* Non-zero means to draw the underline at the same place as the descent line.  */
+
+int x_underline_at_descent_line;
+
 extern unsigned int msh_mousewheel;
 
 extern void free_frame_menubar ();
@@ -2509,21 +2513,27 @@
           && (s->font->bdf || !s->font->tm.tmUnderlined))
         {
           unsigned long h = 1;
-          unsigned long dy = s->height - h;
-
-	  /* TODO: Use font information for positioning and thickness
-	     of underline.  See OUTLINETEXTMETRIC, and xterm.c.
-	     Note: If you make this work, don't forget to change the
-	     doc string of x-use-underline-position-properties below.  */
+          unsigned long dy = 0;
+
+          if (x_underline_at_descent_line)
+            dy = s->height - h;
+          else
+            {
+              /* TODO: Use font information for positioning and thickness of
+                 underline.  See OUTLINETEXTMETRIC, and xterm.c.  Note: If
+                 you make this work, don't forget to change the doc string of
+                 x-use-underline-position-properties below.  */
+              dy = s->height - h;
+            }
           if (s->face->underline_defaulted_p)
             {
               w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x,
-                             s->y + dy, s->width, 1);
+                             s->y + dy, s->background_width, 1);
             }
           else
             {
               w32_fill_area (s->f, s->hdc, s->face->underline_color, s->x,
-                             s->y + dy, s->width, 1);
+                             s->y + dy, s->background_width, 1);
             }
         }
 
@@ -2535,12 +2545,12 @@
           if (s->face->overline_color_defaulted_p)
         {
           w32_fill_area (s->f, s->hdc, s->gc->foreground, s->x,
-                         s->y + dy, s->width, h);
+                         s->y + dy, s->background_width, h);
         }
           else
             {
               w32_fill_area (s->f, s->hdc, s->face->overline_color, s->x,
-                             s->y + dy, s->width, h);
+                             s->y + dy, s->background_width, h);
             }
         }
 
@@ -6510,6 +6520,14 @@
 NOTE: Not supported on MS-Windows yet.  */);
   x_use_underline_position_properties = 0;
 
+  DEFVAR_BOOL ("x-underline-at-descent-line",
+	       &x_underline_at_descent_line,
+     doc: /* *Non-nil means to draw the underline at the same place as the descent line.
+nil means to draw the underline according to the value of the variable
+`x-use-underline-position-properties', which is usually at the baseline
+level.  The default value is nil.  */);
+  x_underline_at_descent_line = 0;
+
   DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars,
 	       doc: /* If not nil, Emacs uses toolkit scroll bars.  */);
   Vx_toolkit_scroll_bars = Qt;
--- a/src/xterm.c	Thu Aug 24 20:51:17 2006 +0000
+++ b/src/xterm.c	Thu Aug 24 20:52:00 2006 +0000
@@ -182,6 +182,10 @@
 
 int x_use_underline_position_properties;
 
+/* Non-zero means to draw the underline at the same place as the descent line.  */
+
+int x_underline_at_descent_line;
+
 /* This is a chain of structures for all the X displays currently in
    use.  */
 
@@ -2685,32 +2689,35 @@
 	  if (!XGetFontProperty (s->font, XA_UNDERLINE_THICKNESS, &h))
 	    h = 1;
 
-	  /* Get the underline position.  This is the recommended
-	     vertical offset in pixels from the baseline to the top of
-	     the underline.  This is a signed value according to the
-	     specs, and its default is
-
-	     ROUND ((maximum descent) / 2), with
-	     ROUND(x) = floor (x + 0.5)  */
-
-	  if (x_use_underline_position_properties
-	      && XGetFontProperty (s->font, XA_UNDERLINE_POSITION, &tem))
-	    y = s->ybase + (long) tem;
-	  else if (s->face->font)
-	    y = s->ybase + (s->face->font->max_bounds.descent + 1) / 2;
-	  else
+          if (x_underline_at_descent_line)
 	    y = s->y + s->height - h;
+          else
+            {
+	      /* Get the underline position.  This is the recommended
+                 vertical offset in pixels from the baseline to the top of
+                 the underline.  This is a signed value according to the
+                 specs, and its default is
+
+	         ROUND ((maximum descent) / 2), with
+	         ROUND(x) = floor (x + 0.5)  */
+
+              if (x_use_underline_position_properties
+                  && XGetFontProperty (s->font, XA_UNDERLINE_POSITION, &tem))
+                y = s->ybase + (long) tem;
+              else if (s->face->font)
+                y = s->ybase + (s->face->font->max_bounds.descent + 1) / 2;
+            }
 
 	  if (s->face->underline_defaulted_p)
 	    XFillRectangle (s->display, s->window, s->gc,
-			    s->x, y, s->width, h);
+			    s->x, y, s->background_width, h);
 	  else
 	    {
 	      XGCValues xgcv;
 	      XGetGCValues (s->display, s->gc, GCForeground, &xgcv);
 	      XSetForeground (s->display, s->gc, s->face->underline_color);
 	      XFillRectangle (s->display, s->window, s->gc,
-			      s->x, y, s->width, h);
+			      s->x, y, s->background_width, h);
 	      XSetForeground (s->display, s->gc, xgcv.foreground);
 	    }
 	}
@@ -2722,14 +2729,14 @@
 
 	  if (s->face->overline_color_defaulted_p)
 	    XFillRectangle (s->display, s->window, s->gc, s->x, s->y + dy,
-			    s->width, h);
+			    s->background_width, h);
 	  else
 	    {
 	      XGCValues xgcv;
 	      XGetGCValues (s->display, s->gc, GCForeground, &xgcv);
 	      XSetForeground (s->display, s->gc, s->face->overline_color);
 	      XFillRectangle (s->display, s->window, s->gc, s->x, s->y + dy,
-			      s->width, h);
+			      s->background_width, h);
 	      XSetForeground (s->display, s->gc, xgcv.foreground);
 	    }
 	}
@@ -10979,6 +10986,14 @@
 to 4.1, set this to nil.  */);
   x_use_underline_position_properties = 1;
 
+  DEFVAR_BOOL ("x-underline-at-descent-line",
+	       &x_underline_at_descent_line,
+     doc: /* *Non-nil means to draw the underline at the same place as the descent line.
+nil means to draw the underline according to the value of the variable
+`x-use-underline-position-properties', which is usually at the baseline
+level.  The default value is nil.  */);
+  x_underline_at_descent_line = 0;
+
   DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
 	       &x_mouse_click_focus_ignore_position,
     doc: /* Non-nil means that a mouse click to focus a frame does not move point.