Subject: bug#54646: 29.0.50; set-fontset-font and font clipping issues

From: Visuwesh <[email-masked]>
Date: Sat, 11 Jun 2022 19:24:16 +0530

[வெள்ளி ஏப்ரல் 22, 2022] Eli Zaretskii wrote:

Hello Eli, Robert

>> From: Visuwesh <[email-masked]>
>> Cc: [email-masked],  [email-masked]
>> Date: Fri, 22 Apr 2022 16:16:07 +0530
>> 
>> >> and the GOOD case for bb9 bbf is
>> >> 
>> >>     lbearing 1 rbearing 28 width 28 ascent 9 descent 5
>> >>     1 bb9 bbf xadvance 1809 yadvance 0 xoffset 0 yoffset 0
>> >>     xpos 0 yoff 0 wadjust 28
>> >> 
>> >> and the BAD case is
>> >> 
>> >>     lbearing 1 rbearing 28 width 28 ascent 9 descent 5
>> >>     1 bb9 bbf xadvance 3193 yadvance 0 xoffset 0 yoffset 0
>> >>     xpos 0 yoff 0 wadjust 50
>> >
>> > This looks like HarfBuzz is feeding us incorrect data for some reason,
>> > but I cannot imagine what that reason could be, sorry.
>> 
>> Could it be some kind of cache?  Because when Emacs rendered the entire
>> webpage, I was unable to reproduce the issue.
>
> When Emacs have rendered the entire page, we no longer call HarfBuzz,
> because the composition data is indeed cached by Emacs.
>
> The print-outs you produced are from calling HarfBuzz, so our caching
> cannot affect that, AFAIU.

I think this might be a cairo+pango problem.  My suspicion is due to
this bug report https://github.com/harfbuzz/harfbuzz/issues/1892 --
although I don't see the problem with English text as shown in the
screenshots.

I tried to turn off font metrics in cairo by applying the following
patch,

diff --git a/src/ftcrfont.c b/src/ftcrfont.c
index 6bb41110d5..77753d30f4 100644
--- a/src/ftcrfont.c
+++ b/src/ftcrfont.c
@@ -176,6 +176,7 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
   cairo_font_options_t *options = xsettings_get_font_options ();
 #else
   cairo_font_options_t *options = cairo_font_options_create ();
+  cairo_font_options_set_hint_metrics(options, CAIRO_HINT_METRICS_OFF);
 #endif
 #ifdef USE_BE_CAIRO
   if (be_use_subpixel_antialiasing ())

but that did not solve the issue.

However, I have been using the xft+harfbuzz combo for a ~week now and I
can say with confidence that I don't experience this strange issue.  I
would highly appreciate it if the decision to remove the xft backend
could be delayed until a solution comes up [1].  Although the font
rendering is worse, the text stays readable at all font sizes.

[1] ./configure --with-cairo says,

    configure: WARNING: This configuration uses libXft, which has a number of
        font rendering issues, and is being considered for removal in the
        next release of Emacs.  Please consider using Cairo graphics +
        HarfBuzz text shaping instead (they are auto-detected if the
        relevant development headers are installed).