Subject: Re: bug#65803: 29.1; Noto Sans Mono CJK JP has doubled-width on Windows

From: Eli Zaretskii <[email-masked]>
Date: Sat, 09 Sep 2023 15:17:42 +0300

> From: Po Lu <[email-masked]>
> Cc: Shingo Tanaka <[email-masked]>,  [email-masked]
> Date: Fri, 08 Sep 2023 21:42:37 +0800
> 
> For a nominally monospace font, the ft*font backends infer the average
> from the width of the space glyph, instead of giving undue credence to
> its reported ``average width''.  CJK fonts customarily contain tens of
> thousands of glyphs, of which only a small subset represent ASCII
> ``monospace'' characters relevant to Emacs, but the `tmAveCharWidth'
> field, which is derived from the font's OS/2 table:
> 
>   https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html
> 
> represents the average width of all the glyphs within the font, and is
> ergo naturally biased towards the large number of CJK glyphs
> incorporated within the font.  The W32 backend should either infer the
> average width itself, or ground it upon on the width of the space glyph.
> Refer to this code in ftfont_open:
> 
>       font->min_width = font->average_width = font->space_width = 0;
>       for (i = 32, n = 0; i < 127; i++)
> 	if (FT_Load_Char (ft_face, i, FT_LOAD_DEFAULT) == 0)
> 	  {
> 	    int this_width = ft_face->glyph->metrics.horiAdvance >> 6;
> 
> 	    if (this_width > 0
> 		&& (! font->min_width || font->min_width > this_width))
> 	      font->min_width = this_width;
> 	    if (i == 32)
> 	      font->space_width = this_width;
> 	    font->average_width += this_width;
> 	    n++;
> 	  }
>       if (n > 0)
> 	font->average_width /= n;

Thanks, but the above snippet in ftfont.c is only done for
proportional fonts, not for fixed-pitch fonts.  Is the font in
question, Noto Sans Mono CJK JP, a proportional font?  That is, does
it not set the fixed-pitch attribute?