emacs-devel
[Top][All Lists]
Advanced

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

Re: master 77c3d41adc: Prevent text decorations from overwriting surroun


From: Eli Zaretskii
Subject: Re: master 77c3d41adc: Prevent text decorations from overwriting surrounding areas on X
Date: Tue, 11 Jan 2022 14:42:47 +0200

> From: Po Lu <luangruo@yahoo.com>
> Cc: emacs-devel@gnu.org
> Date: Tue, 11 Jan 2022 08:37:11 +0800
> 
> >   wave_clip.x = x0;
> >   wave_clip.y = y0;
> >   wave_clip.width = width;
> >   wave_clip.height = wave_height;
> >   get_glyph_string_clip_rect (s, &string_clip);
> >
> >   if (!gui_intersect_rectangles (&wave_clip, &string_clip, &final_clip))
> >     return;
> >
> >   XSetClipRectangles (display, s->gc, 0, 0, &final_clip, 1, Unsorted);
> >
> > Isn't this the clipping?  Or what am I missing?
> 
> That's only done in x_draw_underwave, and nowhere else where text
> decorations (underlines and overlines) are drawn.

For underline, we have this:

              /* Check the sanity of thickness and position.  We should
                 avoid drawing underline out of the current line area.  */
              if (s->y + s->height <= s->ybase + position)
                position = (s->height - 1) - (s->ybase - s->y);
              if (s->y + s->height < s->ybase + position + thickness)
                thickness = (s->y + s->height) - (s->ybase + position);
              s->underline_thickness = thickness;
              s->underline_position = position;
              y = s->ybase + position;
              if (s->face->underline_defaulted_p)
                x_fill_rectangle (s->f, s->gc,
                                  s->x, y, decoration_width, thickness);
              else
                {
                  Display *display = FRAME_X_DISPLAY (s->f);
                  XGCValues xgcv;
                  XGetGCValues (display, s->gc, GCForeground, &xgcv);
                  XSetForeground (display, s->gc, s->face->underline_color);
                  x_fill_rectangle (s->f, s->gc,
                                    s->x, y, decoration_width, thickness);
                  XSetForeground (display, s->gc, xgcv.foreground);
                }

The call to x_fill_rectangle was with s->width, which you now replaced
with decoration_width, computed as follows:

      decoration_width = s->width;
      if (area_max_x < (s->x + decoration_width - 1))
        decoration_width -= (s->x + decoration_width - 1) - area_max_x;

I have a problem with this correction, because I don't understand the
need for it.  s->width is the width of the glyph string, which is
computed from the glyphs that comprise the glyph string.  Those glyphs
were laid out by display_line, which should never add a glyph to a
glyph row if that glyph doesn't fit on the screen.  So how come
s->width in your case was too large?  Or maybe it's s->x that was
wrong (does the underline start exactly under the first glyph)?

So I suspect that your fix hides a much more serious problem
elsewhere.  Please investigate the problem you saw before the change.

> > Please show some actual Lisp to try this, so we wouldn't need to guess
> > whether the problem doesn't exist or we failed to reproduce correctly.
> 
> After loading the definition of widget-field, just do this in an empty
> buffer:
> 
>   (set-face-attribute 'default nil :underline t)
>   (save-excursion
>     (insert (propertize "foo\n" 'face 'widget-field)))
>   (redisplay)
>   (insert "a")
> 
> The underline of the first line will then overwrite the right fringe.

It doesn't overwrite the fringe here on MS-Windows.  Which is what I'd
expect, given the above rationale.  There's something else at work
here, and we shouldn't so easily decide that no one thought about the
need for clipping in this case.

Thanks.



reply via email to

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