[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#29078: 25.2; font issue with FreeType 2.8; should not use the rounde
From: |
Werner LEMBERG |
Subject: |
bug#29078: 25.2; font issue with FreeType 2.8; should not use the rounded ascender and descender |
Date: |
Tue, 31 Oct 2017 12:22:14 +0100 (CET) |
>> For TrueType fonts, FreeType 2.8 uses different rounding rules for
>> values in the FT_Size_Metrics structure, which is apparently used
>> by Emacs (since there are visible changes). In particular, one can
>> now have ascender + descender > height. The consequences are:
>>
>> 1. Tables look a bit ugly.
>>
>> 2. Windows (with the same number of text lines) are unnecessarily
>> higher than before.
>>
>> 3. This can break existing configurations, where Emacs would be
>> opened at start up, with an expected window size.
>>
>> I could notice changes at least with the default Mono font, which
>> appears to be DejaVu Sans Mono.
>>
>> Upstream now recommends to use the values from the FT_Face
>> structure and scale them manually:
>
> I don't have FreeType2.8 to test, but you're saying we need to do this?
>
> diff --git a/src/ftfont.c b/src/ftfont.c
> index 35f5923376..d16bf09a1e 100644
> --- a/src/ftfont.c
> +++ b/src/ftfont.c
> @@ -1153,18 +1153,9 @@ ftfont_open2 (struct frame *f,
> upEM = ft_face->units_per_EM;
> scalable = (INTEGERP (AREF (entity, FONT_AVGWIDTH_INDEX))
> && XINT (AREF (entity, FONT_AVGWIDTH_INDEX)) == 0);
> - if (scalable)
> - {
> - font->ascent = ft_face->ascender * size / upEM + 0.5;
> - font->descent = - ft_face->descender * size / upEM + 0.5;
> - font->height = ft_face->height * size / upEM + 0.5;
> - }
> - 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;
> - }
> + font->ascent = ft_face->ascender * size / upEM + 0.5;
> + font->descent = - ft_face->descender * size / upEM + 0.5;
> + font->height = ft_face->height * size / upEM + 0.5;
> if (INTEGERP (AREF (entity, FONT_SPACING_INDEX)))
> spacing = XINT (AREF (entity, FONT_SPACING_INDEX));
> else
No. The `scalable' branch must make a distinction between TrueType
and non-TrueType fonts if the font gets fully hinted (i.e., if the
TrueType bytecode gets interpreted), something like
if (scalable)
{
if (use_truetype_bytecode_hinting(font))
{
/* use TrueType rules for rounding */
font->ascent = ROUND(ft_face->ascender * size / upEM)
font->descent = ROUND(-ft_face->descender * size / upEM);
font->height = font->ascent + font->descent;
}
else
{
font->ascent = CEIL(ft_face->ascender * size / upEM);
font->descent = FLOOR(-ft_face->descender * size / upEM);
font->height = ROUND(ft_face->height * size / upEM);
}
}
...
Werner