From 9b28a5083edecacfac3c7e16308bd8af3f4773a2 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Mitsuharu Date: Tue, 14 May 2019 10:17:16 +0900 Subject: [PATCH] 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) : New DEFSYM. --- src/ftcrfont.c | 14 ++++++++++++-- src/ftfont.c | 30 +++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/ftcrfont.c b/src/ftcrfont.c index 8a1c9a48e1f..e7c73eac4d3 100644 --- a/src/ftcrfont.c +++ b/src/ftcrfont.c @@ -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; diff --git a/src/ftfont.c b/src/ftfont.c index d0078a37701..4770c3c40b3 100644 --- a/src/ftfont.c +++ b/src/ftfont.c @@ -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); -- 2.39.2