Avoid artifacts in ftx and ftcr font backend drivers

* src/ftcrfont.c (ftcrfont_open):
* src/ftfont.c (ftfont_open2): Make font->height equal to sum of font->ascent
and font->descent.  Respect :minspace property.
(ftfont_open2): Remove redundant assignment.
(syms_of_ftfont) <QCminspace>: New DEFSYM.
This commit is contained in:
YAMAMOTO Mitsuharu 2019-05-14 10:17:16 +09:00
parent 2f7e97ef48
commit 9b28a5083e
2 changed files with 37 additions and 7 deletions

View file

@ -160,8 +160,18 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
cairo_font_extents_t extents;
cairo_scaled_font_extents (ftcrfont_info->cr_scaled_font, &extents);
font->ascent = lround (extents.ascent);
font->descent = lround (extents.descent);
font->height = lround (extents.height);
Lisp_Object val = assq_no_quit (QCminspace,
AREF (entity, FONT_EXTRA_INDEX));
if (!(CONSP (val) && NILP (XCDR (val))))
{
font->descent = lround (extents.descent);
font->height = font->ascent + font->descent;
}
else
{
font->height = lround (extents.height);
font->descent = font->height - font->ascent;
}
cairo_glyph_t stack_glyph;
int n = 0;

View file

@ -1108,7 +1108,6 @@ ftfont_open2 (struct frame *f,
return Qnil;
filename = XCAR (val);
idx = XCDR (val);
val = XCDR (cache);
cache_data = xmint_pointer (XCDR (cache));
ft_face = cache_data->ft_face;
if (cache_data->face_refcount > 0)
@ -1172,20 +1171,38 @@ ftfont_open2 (struct frame *f,
font->driver = &ftfont_driver;
font->encoding_charset = font->repertory_charset = -1;
val = assq_no_quit (QCminspace, AREF (entity, FONT_EXTRA_INDEX));
bool no_leading_p = !(CONSP (val) && NILP (XCDR (val)));
upEM = ft_face->units_per_EM;
scalable = (FIXNUMP (AREF (entity, FONT_AVGWIDTH_INDEX))
&& XFIXNUM (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;
if (no_leading_p)
{
font->descent = - ft_face->descender * size / upEM + 0.5;
font->height = font->ascent + font->descent;
}
else
{
font->height = ft_face->height * size / upEM + 0.5;
font->descent = font->height - font->ascent;
}
}
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;
if (no_leading_p)
{
font->descent = - ft_face->size->metrics.descender >> 6;
font->height = font->ascent + font->descent;
}
else
{
font->height = ft_face->size->metrics.height >> 6;
font->descent = font->height - font->ascent;
}
}
if (FIXNUMP (AREF (entity, FONT_SPACING_INDEX)))
spacing = XFIXNUM (AREF (entity, FONT_SPACING_INDEX));
@ -2769,6 +2786,9 @@ syms_of_ftfont (void)
DEFSYM (Qsans, "sans");
DEFSYM (Qsans__serif, "sans serif");
/* The boolean-valued font property key specifying the use of leading. */
DEFSYM (QCminspace, ":minspace");
staticpro (&freetype_font_cache);
freetype_font_cache = list1 (Qt);