Subject: Re: bug#56808: 29.0.50; Elusive display problem on macOS

From: Gerd Möllmann <[email-masked]>
Date: Fri, 29 Jul 2022 14:32:49 +0200

Gerd Möllmann <[email-masked]> writes:

>> Then how did you get 7 in the other image you posted?
>
> That's the 42€ question.

I can answer that question now.  Alas, I don't really have an idea how
to fix this yet.  Maybe someone reading this has an idea.

The story starts in the macfont_open.  This functions uses
font_build_object to allocate a new struct font. But the allocation
leaves part of the struct members uninitialized!  The member space_width
is among the uninitialized members.  I can't say that I find that a good
idea.  Mistake 1, in my book.

The function macfont_open uses

  font->space_width = macfont_glyph_extents (font, glyph, ...)

to compute font->space_width.  That would be a good idea, iff
macfont_glyph_extents and/or subroutines wouldn't use font->space_width
themselves.  Specifically, in my case with Monaco 12,
macfont_glyph_extents calls

  int multiplier = macfont_monospace_width_multiplier (font, fwidth);

and macfont_monospace_width_multiplier uses font->space_width, with that
still being some "random" value.  The result of
macfont_monospace_width_multiplier is therefore sometimes 0
(astonishingly often) and sometimes != 0.  Mistake 2.

When the result is not 0, macfont_glyph_extents does its own thing with
the unitialized font->space_width.  Mistake 3.

And so on.  I stopped debugging here.

Mabe I should initialize font->space_width to -3.  With -2, it always
fails.  ;-).