Subject: bug#73752: 29.4; Ligatures are randomly rendered with extra spaces

From: Tim Ruffing <[email-masked]>
Date: Mon, 04 Nov 2024 01:11:39 +0100

This fixes the problem:  

diff --git a/src/ftfont.c b/src/ftfont.c
index 882d3eec256..2be443108f1 100644
--- a/src/ftfont.c
+++ b/src/ftfont.c
@@ -2994,9 +2994,8 @@ fthbfont_begin_hb_font (struct font *font, double
*position_unit)
   struct font_info *ftfont_info = (struct font_info *) font;
 
   *position_unit = 1.0 / (1 << 6);
-  if (! ftfont_info->hb_font)
-    ftfont_info->hb_font
-      = hb_ft_font_create_referenced (ftfont_info->ft_size->face);
+  ftfont_info->hb_font
+    = hb_ft_font_create_referenced (ftfont_info->ft_size->face);
   return ftfont_info->hb_font;
 }
 
That is, it makes at least the bug with Yixuan's script disappear. I
haven't yet verified if this fixes what I often see during my daily
usage.

The above patch seems to a bit crude at first glance. While I don't
notice any impact on performance, the following should be faster
according to https://harfbuzz.github.io/integration-freetype.html :

diff --git a/src/ftfont.c b/src/ftfont.c
index 882d3eec256..cd685af4d89 100644
--- a/src/ftfont.c
+++ b/src/ftfont.c
@@ -2997,6 +2997,8 @@ fthbfont_begin_hb_font (struct font *font, double
*position_unit)
   if (! ftfont_info->hb_font)
     ftfont_info->hb_font
       = hb_ft_font_create_referenced (ftfont_info->ft_size->face);
+  else
+     hb_ft_font_changed (ftfont_info->hb_font);
   return ftfont_info->hb_font;
 }

But unfortunately, that one doesn't work. With this patch, the
rendering is still bad, it's just bad in a difference way: Instead of
the last character having wadjust > width, all characters in the bad
ligature have the same wadjust > width. If we care about this, then we
may want to reach out to harfbuzz to understand why. (Or at least that
seems beyond my superficial text rendering skills, but perhaps the
experts here understand what's going on.)