Subject: bug#59347: 29.0.50; `:family` face setting ignored

From: Yuan Fu <[email-masked]>
Date: Fri, 18 Nov 2022 12:12:29 -0800

> On Nov 18, 2022, at 12:00 PM, Yuan Fu <[email-masked]> wrote:
> 
> 
> 
>> On Nov 18, 2022, at 9:21 AM, Eli Zaretskii <[email-masked]> wrote:
>> 
>>> Cc: [email-masked]
>>> Date: Fri, 18 Nov 2022 18:54:02 +0200
>>> From: Eli Zaretskii <[email-masked]>
>>> 
>>>> What should I change in my recipe in order to keep the same default font
>>>> but get the DejaVu Sans that used to get?
>>> 
>>> The default font would be my guess.  Try using some other font, not
>>> from the fixed-misc family.
>> 
>> I take that back: I tried your recipe, and it works with every font I
>> tried except DejaVu Sans.  So I guess that font is the culprit, and
>> you should find some other font that you like.
>> 
>> Why DejaVu Sans is rejected, I donb't know, but that font has some
>> issues that we already discovered in the past, so it could be a good
>> idea to get rid of it regardless.
> 
> I might have some more information, and here is a reproduce of what I see: 
> 
> Load these two (open source) fonts in to your machine, and emacs -Q -l reproduce.el
> 
> The content of reproduce.el is:
> 
> (pop-to-buffer
> (let ((font1 "IBM Plex Mono")
>       (font2 "Charter"))
>   (with-current-buffer (get-buffer-create "*test*")
>     (set-face-attribute 'default nil
>                         :font (font-spec :family font1
>                                          :weight 'medium))
>     (insert (propertize "Some Text\n" 'face `(:family ,font2)))
>     (insert (propertize "Some Text"
>                         'face `(:font ,(font-spec :family font2))))
>     (current-buffer))))
> 
> It inserts two lines of text, both using font2, but the first line using :family and the second using :font. The one using :family is not displayed in font2 (it falls back to some other font), but the one using :font is.
> 
> I think this is because the default font (font1) uses medium weight, but font2 doesn’t have a medium weight. I tried with different fonts for font2, and whether that font has a medium weight correlates to whether the first line of text can be displayed in that font.
> 
> So my guess is that if the face uses the :family attribute, it inherits the weight from default, and if Emacs cannot find that weight in that font, it falls back to some other font.
> 
> I don’t know how to “fix” this, but at very least we should make it easy to figure out why the family attribute “didn’t work”. (It’s not unreasonable for someone to think: I have the font on my machine, the family settings is set to that font, why is the text not displayed in that font??)
> 
> Personally I think falling back to the same font but different weight is probably less confusing.
> 
> Yuan
> 
> <reproduce.el><IBMPlexMono-Medium.ttf><Charter Regular.otf>

Basically the culprit in Stefan’s recipe is probably semicondensed rather than Dejavu.

Yuan