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

From: Eli Zaretskii <[email-masked]>
Date: Wed, 06 Nov 2024 15:11:02 +0200

> From: Tim Ruffing <[email-masked]>
> Cc: [email-masked], [email-masked], [email-masked]
> Date: Wed, 06 Nov 2024 13:02:34 +0100
> 
> > > If so, I think the code
> > > to look at is the end_hb_font method and what it does to the
> > hb_font
> > > object.  The end_hb_font method is called each time the shaper is
> > > called, so whatever it does to the hb_font object is inherited by
> > the
> > > next call to the shaper.
> > 
> > This sounds like a plausible cause, but as far as I can tell,
> > end_hb_font doesn't do anything to hb_font. The end function is
> > simply
> > necessary to call cairo_ft_scaled_font_unlock_face().
> > 
> 
> 
> Okay, I still have no idea what the root cause is, but this hack also
> makes the bug disappear for me:
> 
> diff --git a/src/ftcrfont.c b/src/ftcrfont.c
> index 3700154e44a..4f62873f8c1 100644
> --- a/src/ftcrfont.c
> +++ b/src/ftcrfont.c
> @@ -708,7 +708,6 @@ ftcrhbfont_end_hb_font (struct font *font,
> hb_font_t *hb_font)
>    struct font_info *ftcrfont_info = (struct font_info *) font;
>    cairo_scaled_font_t *scaled_font = ftcrfont_info->cr_scaled_font;
>  
> -  cairo_ft_scaled_font_unlock_face (scaled_font);
>    ftcrfont_info->ft_size = NULL;
>  }
> 
> This is consistent with your theory about end_hb_font.

Thanks.  Can you try calling hb_font_destroy in ftcrhbfont_end_hb_font
and setting ftcrfont_info->hb_font to NULL right after that?  If that
solves the problem, we could at least install this for now, until we
have a better solution (if one exists).

Also, did you see https://github.com/harfbuzz/harfbuzz/issues/4926 ?