Subject: bug#20628: 25.0.50; Incorrect line height for some fonts

From: Eli Zaretskii <[email-masked]>
Date: Fri, 22 May 2015 17:49:16 +0300

> From: Oleh Krehel <[email-masked]>
> Cc: [email-masked],  [email-masked]
> Date: Fri, 22 May 2015 16:20:31 +0200
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > Like this:
> >
> >   it->max_ascent = max (it->max_ascent, it->ascent);
> >   it->max_descent = max (it->max_descent, it->descent);
> >
> > IOW, it's the max value of ascent and descent of all the characters on
> > that screen line.
> 
> OK, I got this far:
> 
>     p FACE_FROM_ID(it->f,it->face_id)->font->ascent
>     $18 = 15
>     (gdb) p FACE_FROM_ID(it->f,it->face_id)->font->descent
>     $19 = 4
> 
> 15 and 4 are the eventual (wrong) values of it->max_ascent and
> it->max_descent.

Why do you think they are wrong?

> But I don't know how and where the font structure is initialized and
> how the current glyph actually is factored here: I just see a
> reference to a frame and a face, no reference to the current char.

AFAIK, they are initialized from the font data.  Here's what ftfont.c
does in ftfont_open:

  scalable = (INTEGERP (AREF (entity, FONT_AVGWIDTH_INDEX))
	      && XINT (AREF (entity, FONT_AVGWIDTH_INDEX)) == 0);
  if (scalable)
    {
      font->ascent = ft_face->ascender * size / upEM;
      font->descent = - ft_face->descender * size / upEM;
      font->height = ft_face->height * size / upEM;
    }
  else
    {
      font->ascent = ft_face->size->metrics.ascender >> 6;
      font->descent = - ft_face->size->metrics.descender >> 6;
      font->height = ft_face->size->metrics.height >> 6;
    }

And the fields of ft_face seem to be set by FreeType library, via the
call to FT_Set_Pixel_Sizes, a few lines before the above snippet.