Subject: bug#51277: 27.1; menu-set-font not loading correct font

From: Robert Pluim <[email-masked]>
Date: Wed, 20 Oct 2021 17:02:23 +0200

>>>>> On Wed, 20 Oct 2021 15:36:51 +0300, Eli Zaretskii <[email-masked]> said:

    >> Date: Wed, 20 Oct 2021 07:30:21 -0400
    >> From: Jesse Sheidlower <[email-masked]>
    >> Cc: Eli Zaretskii <[email-masked]>, [email-masked]
    >> 
    >> There is no difference in the result: whether I restrict emacs to xfont,
    >> ftfont, or ftcrhb, it still loads the "Bold" file even when I select the
    >> "Book" version from menu-set-font.
    >> 
    >> Where does this leave us? It does still seem like a bug (albeit one that
    >> apparently affects very few people).

    Eli> Are you familiar with debugging with Edebug and/or with running Emacs
    Eli> under GDB?  If so, perhaps you could step into the relevant code and
    Eli> tell us what happens there with this font, so we could understand the
    Eli> root cause(s) of this.

tl;dr font weight handling is a mess

    Eli> Or maybe someone else who can install that font and sees the problem
    Eli> could do that.

Iʼve installed the fonts in question, and I can reproduce the
issue. What I see:

- the GTK font selector lets us choose 'Operator Mono Book'
- the resulting weight according to Pango is '330', which we map to
  'normal' [1]

Comparing that to what 'fc-match' tells us:

    $ fc-match 'operator mono:weight=330'
    FontsFree-Net-OperatorMono-Bold.ttf: "Operator Mono" "Bold"

    $ fc-match 'operator mono'
    FontsFree-Net-OperatorMono-Bold.ttf: "Operator Mono" "Bold"

    $ fc-match 'operator mono:style=book'
    FontsFree-Net-OperatorMono-Book.ttf: "Operator Mono" "Book"

    $ fc-match 'operator mono:light'
    FontsFree-Net-OperatorMono-Book.ttf: "Operator Mono" "Book"

So Iʼd be willing to point the finger at the font here, except that
with gedit, when I select 'Operator Mono Book', I get the 'book'
version, not 'bold'.

I then cavalierly hardcoded the weight we request to '200', which
results in us asking for 'light', and then we correctly use the 'Book'
version of the font.

This means we should adjust XG_WEIGHT_TO_SYMBOL. It currently assigns
anything in the range <100-200] to 'light', which just seems wrong. It
all depends whether the fixed values are the start or the end of the
range, but would it not make more sense to have 'light' be used for
the range [300-350> which corresponds to
[PANGO_WEIGHT_LIGHT-PANGO_WEIGHT_SEMILIGHT> ? [2]

Robert

Footnotes:
[1]  According to the pango headers, 'book' == 380

[2]  Iʼll note that 'w32_to_fc_weight' uses the various FW_* constants
     as the start of the respective range, not the end

--