From: Yuri D'Elia <wavexx@thregr.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: larsi@gnus.org, emacs-devel@gnu.org, monnier@iro.umontreal.ca,
dgutov@yandex.ru
Subject: Re: Incorrect font weight selected
Date: Wed, 05 Jan 2022 17:19:35 +0100 [thread overview]
Message-ID: <877dbe86tv.fsf@wavexx.thregr.org> (raw)
In-Reply-To: <83sfumyr9c.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1973 bytes --]
On Tue, Dec 21 2021, Eli Zaretskii wrote:
>> From: Yuri D'Elia <wavexx@thregr.org>
>> Cc: Dmitry Gutov <dgutov@yandex.ru>, monnier@iro.umontreal.ca,
>> larsi@gnus.org, emacs-devel@gnu.org
>> Date: Tue, 21 Dec 2021 13:27:03 +0100
>>
>> The annoying fact is that font selection is called in so many contexts
>> it's just time consuming to drill down and/or set a good breakpoint
>> condition.
>
> I usually set a breakpoint in xfaces.c where the face attribute(s)
> is/are being changed, and then step into the functions it calls to
> select the font. It's a bit slow, since you have a lot to step
> through, but it makes sure it's the right calls you are tracing.
After looking at this through a couple of times, I came up with the
attached patch. When changing the default face, the resulting font
name/pattern is stored as a string. Whenever a new frame is created, the
string is used to re-open the face again. I guess this is done to
support creating frames across different terminal types preserving the
closest available font.
This is done by calling font_open_by_name, which builds up a font spec
again from the stored string (which at this point _should_ be fully
specified), then calls the font_open_by_spec. The problem seems that
font_open_by_spec is _explicitly_ requesting a normal
weight/slant/width. So if multiple candidates were available while
enumerating fonts, the regular variant was always picked irregardless of
our preference.
This used to work before since only a single variant was generally
enumerated. In the patch, instead of just resetting/overriding the spec,
we just preset a normal variant if the spec is incomplete. I included
also the family/foundry in the spec, which can be used during selection
instead of blindly ignoring it.
This seems to work correctly for me now, however I'm only testing on
x11. font_open_by_name is not used in many places aside frame creation.
This change seems coherent to me looking at the other calls.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Do-not-override-the-requested-spec-in-font_open_by_s.patch --]
[-- Type: text/x-diff, Size: 1857 bytes --]
From 1e9e66541553b2a439f8748b1ae12f398040d7e5 Mon Sep 17 00:00:00 2001
From: Yuri D'Elia <wavexx@thregr.org>
Date: Wed, 5 Jan 2022 17:11:23 +0100
Subject: [PATCH] Do not override the requested spec in font_open_by_spec
* src/font.c (font_open_by_spec): Do not override the requested spec
when opening a font. Only provide default values if the spec is
underspecified.
This ensures that, when loading fonts with multiple matching
alternatives, font_load_for_lface will pick the requested variant.
---
src/font.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/font.c b/src/font.c
index 58ff1a7981..1cb20f5796 100644
--- a/src/font.c
+++ b/src/font.c
@@ -3544,11 +3544,22 @@ font_open_by_spec (struct frame *f, Lisp_Object spec)
{
Lisp_Object attrs[LFACE_VECTOR_SIZE];
- /* We set up the default font-related attributes of a face to prefer
- a moderate font. */
- attrs[LFACE_FAMILY_INDEX] = attrs[LFACE_FOUNDRY_INDEX] = Qnil;
- attrs[LFACE_SWIDTH_INDEX] = attrs[LFACE_WEIGHT_INDEX]
- = attrs[LFACE_SLANT_INDEX] = Qnormal;
+ /* Filter according to spec. */
+ attrs[LFACE_FAMILY_INDEX] = Ffont_get (spec, QCfamily);
+ attrs[LFACE_FOUNDRY_INDEX] = Ffont_get (spec, QCfoundry);
+ attrs[LFACE_SWIDTH_INDEX] = Ffont_get (spec, QCwidth);
+ attrs[LFACE_WEIGHT_INDEX] = Ffont_get (spec, QCweight);
+ attrs[LFACE_SLANT_INDEX] = Ffont_get (spec, QCslant);
+
+ /* We set up the fallback font-related attributes of a face to
+ prefer a moderate font. */
+ if (NILP (attrs[LFACE_SWIDTH_INDEX]))
+ attrs[LFACE_SWIDTH_INDEX] = Qnormal;
+ if (NILP (attrs[LFACE_WEIGHT_INDEX]))
+ attrs[LFACE_WEIGHT_INDEX] = Qnormal;
+ if (NILP (attrs[LFACE_WEIGHT_INDEX]))
+ attrs[LFACE_WEIGHT_INDEX] = Qnormal;
+
#ifndef HAVE_NS
attrs[LFACE_HEIGHT_INDEX] = make_fixnum (120);
#else
--
2.34.1
next prev parent reply other threads:[~2022-01-05 16:19 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-17 14:51 Incorrect font weight selected Yuri D'Elia
2021-12-17 18:55 ` Eli Zaretskii
2021-12-17 19:47 ` Yuri D'Elia
2021-12-17 20:27 ` Eli Zaretskii
2021-12-17 21:25 ` Yuri D'Elia
2021-12-18 6:32 ` Eli Zaretskii
2021-12-18 10:43 ` Yuri D'Elia
2021-12-18 11:41 ` Eli Zaretskii
2021-12-18 12:00 ` Yuri D'Elia
2021-12-18 12:49 ` Eli Zaretskii
2021-12-19 11:14 ` Yuri D'Elia
2021-12-19 12:46 ` Eli Zaretskii
2021-12-19 13:17 ` Yuri D'Elia
2021-12-19 13:32 ` Lars Ingebrigtsen
2021-12-19 23:24 ` Yuri D'Elia
2021-12-20 10:34 ` Lars Ingebrigtsen
2021-12-20 19:43 ` Stefan Monnier
2021-12-20 19:52 ` Eli Zaretskii
2021-12-20 20:14 ` Stefan Monnier
2021-12-20 20:19 ` Eli Zaretskii
2021-12-21 4:22 ` Dmitry Gutov
2021-12-21 12:18 ` Eli Zaretskii
2021-12-21 12:27 ` Yuri D'Elia
2021-12-21 14:19 ` Eli Zaretskii
2022-01-05 16:19 ` Yuri D'Elia [this message]
2022-01-05 17:05 ` Eli Zaretskii
2022-01-05 17:11 ` Yuri D'Elia
2022-01-05 18:04 ` Eli Zaretskii
2022-01-05 18:08 ` Yuri D'Elia
2022-01-05 19:07 ` Eli Zaretskii
2022-01-05 23:16 ` Yuri D'Elia
2022-01-06 7:09 ` Eli Zaretskii
2022-01-06 9:46 ` Yuri D'Elia
2022-01-06 12:22 ` Eli Zaretskii
2022-01-05 21:57 ` Dmitry Gutov
2022-01-05 23:15 ` Yuri D'Elia
2022-01-05 23:15 ` Yuri D'Elia
2022-01-06 5:15 ` Sean Whitton
2022-01-06 0:41 ` Po Lu
2022-01-06 0:54 ` Po Lu
2022-01-06 9:49 ` Yuri D'Elia
2022-01-06 12:21 ` Eli Zaretskii
2021-12-21 13:52 ` John ff
2021-12-20 20:05 ` Stefan Monnier
2021-12-20 15:16 ` Eli Zaretskii
2021-12-18 23:26 ` Sean Whitton
2021-12-19 6:44 ` Eli Zaretskii
2021-12-19 11:29 ` Yuri D'Elia
2021-12-19 12:52 ` Eli Zaretskii
2021-12-19 12:57 ` Yuri D'Elia
2021-12-19 13:32 ` Eli Zaretskii
2021-12-19 21:03 ` Sean Whitton
2021-12-19 22:04 ` Yuri D'Elia
2021-12-19 22:39 ` Sean Whitton
2021-12-20 21:59 ` Sean Whitton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877dbe86tv.fsf@wavexx.thregr.org \
--to=wavexx@thregr.org \
--cc=dgutov@yandex.ru \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=larsi@gnus.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).