]> git.eshelyaron.com Git - emacs.git/commitdiff
A better fix for bug#25845
authorEli Zaretskii <eliz@gnu.org>
Mon, 6 Mar 2017 16:22:53 +0000 (18:22 +0200)
committerEli Zaretskii <eliz@gnu.org>
Mon, 6 Mar 2017 16:22:53 +0000 (18:22 +0200)
* src/xdisp.c (font_for_underline_metrics): New function.
* src/dispextern.h: Add its prototype.
* src/xterm.c (x_draw_glyph_string):
* src/w32term.c (x_draw_glyph_string):
* src/nsterm.m (ns_draw_text_decoration): Call it.  This avoids
having identical code 3 times in 3 different files.

src/dispextern.h
src/nsterm.m
src/w32term.c
src/xdisp.c
src/xterm.c

index e030618a9b76501a1de9bae5bfb2d72224f3c56d..679820d506323f29dfa5df83e636bcfb5f7ef66e 100644 (file)
@@ -3293,6 +3293,7 @@ extern void dump_glyph_string (struct glyph_string *) EXTERNALLY_VISIBLE;
 
 extern void x_get_glyph_overhangs (struct glyph *, struct frame *,
                                    int *, int *);
+extern struct font *font_for_underline_metrics (struct glyph_string *);
 extern void x_produce_glyphs (struct it *);
 
 extern void x_write_glyphs (struct window *, struct glyph_row *,
index bc89925b0ef59f27b4c861e3979ef69d45c69e05..08ee0cdf6fd54c39263d7a2f39287266661f9c5f 100644 (file)
@@ -3043,28 +3043,7 @@ ns_draw_text_decoration (struct glyph_string *s, struct face *face,
             }
           else
             {
-             /* If we are drawing in the middle of a glyph row, find
-                the first glyph in the run of underlined glyphs
-                preceding the beginning of glyph string S.  This is
-                because that glyph determines the underline position
-                and thickness for the entire run of the underlined
-                glyphs.  */
-             struct glyph *g0 = s->row->glyphs[s->area], *g;
-
-             for (g = s->first_glyph - 1; g >= g0; g--)
-               {
-                 struct face *prev_face = FACE_FROM_ID (s->f, g->face_id);
-                 if (!(prev_face && prev_face->underline_p))
-                   break;
-               }
-
-             /* Now use the font of the last glyph we saw that
-                still has the underlined_p flag set.  */
-             struct face *glyph_face = FACE_FROM_ID (s->f, g[1].face_id);
-             struct font *font = glyph_face->font;
-             if (font)
-               font_prepare_for_face (s->f, glyph_face);
-
+             struct font *font = font_for_underline_metrics (s);
               unsigned long descent = s->y + s->height - s->ybase;
 
               /* Use underline thickness of font, defaulting to 1. */
index 6a98fc721cd7dfd18d6fbfb84b06af30ff36f5df..81666f5bc479aa2bbb5003fab4034130791ab8ea 100644 (file)
@@ -2433,27 +2433,7 @@ x_draw_glyph_string (struct glyph_string *s)
                 }
               else
                 {
-                 /* If we are drawing in the middle of a glyph row,
-                    find the first glyph in the run of underlined
-                    glyphs preceding the beginning of glyph string S.
-                    This is because that glyph determines the
-                    underline position and thickness for the entire
-                    run of the underlined glyphs.  */
-                 struct glyph *g0 = s->row->glyphs[s->area], *g;
-
-                 for (g = s->first_glyph - 1; g >= g0; g--)
-                   {
-                     struct face *prev_face = FACE_FROM_ID (s->f, g->face_id);
-                     if (!(prev_face && prev_face->underline_p))
-                       break;
-                   }
-
-                 /* Now use the font of the last glyph we saw that
-                    still has the underlined_p flag set.  */
-                 struct face *glyph_face = FACE_FROM_ID (s->f, g[1].face_id);
-                 struct font *font = glyph_face->font;
-                 if (font)
-                   font_prepare_for_face (s->f, glyph_face);
+                 struct font *font = font_for_underline_metrics (s);
 
                   /* Get the underline thickness.  Default is 1 pixel.  */
                   if (font && font->underline_thickness > 0)
index 82c4c775c16c0ca1dc889420adb5e16e9c8027f9..1e7cb4ec6654f7c74762be40d75ff3773e32105d 100644 (file)
@@ -25948,6 +25948,36 @@ draw_glyphs (struct window *w, int x, struct glyph_row *row,
   return x_reached;
 }
 
+/* Find the first glyph in the run of underlined glyphs preceding the
+   beginning of glyph string S, and return its font (which could be
+   NULL).  This is needed because that font determines the underline
+   position and thickness for the entire run of the underlined glyphs.
+   This function is called from the draw_glyph_string method of GUI
+   frame's redisplay interface (RIF) when it needs to draw in an
+   underlined face.  */
+struct font *
+font_for_underline_metrics (struct glyph_string *s)
+{
+  struct glyph *g0 = s->row->glyphs[s->area], *g;
+
+  for (g = s->first_glyph - 1; g >= g0; g--)
+    {
+      struct face *prev_face = FACE_FROM_ID (s->f, g->face_id);
+      if (!(prev_face && prev_face->underline_p))
+       break;
+    }
+
+  /* If preceding glyphs are not underlined, use the font of S.  */
+  if (g == s->first_glyph - 1)
+    return s->font;
+  else
+    {
+      /* Otherwise use the font of the last glyph we saw in the above
+        loop whose face had the underline_p flag set.  */
+      return FACE_FROM_ID (s->f, g[1].face_id)->font;
+    }
+}
+
 /* Expand row matrix if too narrow.  Don't expand if area
    is not present.  */
 
index 57e64c488879da291b14d065205abb6ed29134c3..28faea14a3a0391ef5d8fa44c02e7d2c8104e0cb 100644 (file)
@@ -3636,27 +3636,7 @@ x_draw_glyph_string (struct glyph_string *s)
                 }
               else
                 {
-                 /* If we are drawing in the middle of a glyph row,
-                    find the first glyph in the run of underlined
-                    glyphs preceding the beginning of glyph string S.
-                    This is because that glyph determines the
-                    underline position and thickness for the entire
-                    run of the underlined glyphs.  */
-                 struct glyph *g0 = s->row->glyphs[s->area], *g;
-
-                 for (g = s->first_glyph - 1; g >= g0; g--)
-                   {
-                     struct face *prev_face = FACE_FROM_ID (s->f, g->face_id);
-                     if (!(prev_face && prev_face->underline_p))
-                       break;
-                   }
-
-                 /* Now use the font of the last glyph we saw that
-                    still has the underlined_p flag set.  */
-                 struct face *glyph_face = FACE_FROM_ID (s->f, g[1].face_id);
-                 struct font *font = glyph_face->font;
-                 if (font)
-                   font_prepare_for_face (s->f, glyph_face);
+                 struct font *font = font_for_underline_metrics (s);
 
                   /* Get the underline thickness.  Default is 1 pixel.  */
                   if (font && font->underline_thickness > 0)