unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Gregory Heytings <gregory@heytings.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Eli Zaretskii <eliz@gnu.org>, 59347@debbugs.gnu.org
Subject: bug#59347: 29.0.50; `:family` face setting ignored
Date: Sun, 20 Nov 2022 13:57:48 +0000	[thread overview]
Message-ID: <7cc9e03786024fc72f3b@heytings.org> (raw)
In-Reply-To: <834juu9aya.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 169 bytes --]


Stefan, could you please try the attached patch and see if it fixes your 
problem?  (It does here, with your recipe.)

Eli, could you please review that patch?

Thanks.

[-- Attachment #2: Also-try-normal-weight-when-searching-a-font-with-me.patch --]
[-- Type: text/x-diff, Size: 4135 bytes --]

From ab7090e055b7c2043f9fdb07b760ae8b304fe02c Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Sun, 20 Nov 2022 13:50:47 +0000
Subject: [PATCH] Also try 'normal' weight when searching a font with 'medium'
 weight.

Between commits bf0d3f76dc (2014) and 6b1ed2f2c9 (2022),
realize_gui_face called font_load_for_lface with an empty or partly
emptied font spec, i.e. it ignored a part of its attrs argument.  The
rationale given in bug#17973, which led to bf0d3f76dc, is not clear.
In the meantime, commit 65fd3ca84f added support for the 'medium' font
weight, which was previously synonymous to 'normal'.

Together, the two commits 6b1ed2f2c9 and 65fd3ca84f lead to suboptimal
font choices.  When the font chosen for the default face has its
weight set to 'medium' and actually supports that weight,
font_load_for_lface will be called with a weight attribute set to
'medium' in spec for other faces.  However, fonts with an explicit
'medium' weight are much less common than fonts with an explicit
'normal' weight, which means that fonts that only support a 'normal'
weight are rejected, although they are close to the desired font.

Therefore, font_find_for_lface should also try the 'normal' weight
when the weight in spec is 'medium', after trying the 'medium' weight.

* src/font.c (font_find_for_lface): When the weight in SPEC is
'medium', also try the 'normal' weight.
---
 src/font.c | 39 +++++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/src/font.c b/src/font.c
index 6e720bc285..4222d60231 100644
--- a/src/font.c
+++ b/src/font.c
@@ -2959,9 +2959,9 @@ font_find_for_lface (struct frame *f, Lisp_Object *attrs, Lisp_Object spec, int
 {
   Lisp_Object work;
   Lisp_Object entities, val;
-  Lisp_Object foundry[3], *family, registry[3], adstyle[3];
+  Lisp_Object foundry[3], *family, registry[3], adstyle[3], weight[3];
   int pixel_size;
-  int i, j, k, l;
+  int i, j, k, l, m;
   USE_SAFE_ALLOCA;
 
   /* Registry specification alternatives: from the most specific to
@@ -3081,6 +3081,17 @@ font_find_for_lface (struct frame *f, Lisp_Object *attrs, Lisp_Object spec, int
 	}
     }
 
+  /* If weight is "medium" in SPEC, also try "normal".  Fonts with an
+     explicit "medium" weight are much less common than fonts with an
+     explicit "normal" weight, and for a long time "medium" and
+     "normal" (a.k.a. "regular" a.k.a. "book") were synonymous in
+     Emacs.  See e.g. bug#59347 and bug#57555.  */
+  weight[0] = AREF (spec, FONT_WEIGHT_INDEX);
+  if (EQ (weight[0], Qmedium))
+    weight[1] = Qnormal, weight[2] = zero_vector;
+  else
+    weight[1] = zero_vector;
+
   /* Now look up suitable fonts, from the most specific spec to the
      least specific spec.  Accept the first one that matches.  */
   for (i = 0; SYMBOLP (family[i]); i++)
@@ -3095,18 +3106,22 @@ font_find_for_lface (struct frame *f, Lisp_Object *attrs, Lisp_Object spec, int
 	      for (l = 0; SYMBOLP (adstyle[l]); l++)
 		{
 		  ASET (work, FONT_ADSTYLE_INDEX, adstyle[l]);
-		  /* Produce the list of candidates for the spec in WORK.  */
-		  entities = font_list_entities (f, work);
-		  if (! NILP (entities))
+		  for (m = 0; SYMBOLP (weight[m]); m++)
 		    {
-		      /* If there are several candidates, select the
-			 best match for PIXEL_SIZE and attributes in ATTRS.  */
-		      val = font_select_entity (f, entities,
-						attrs, pixel_size, c);
-		      if (! NILP (val))
+		      ASET (work, FONT_WEIGHT_INDEX, weight[m]);
+		      /* Produce the list of candidates for the spec in WORK.  */
+		      entities = font_list_entities (f, work);
+		      if (! NILP (entities))
 			{
-			  SAFE_FREE ();
-			  return val;
+			  /* If there are several candidates, select the
+			     best match for PIXEL_SIZE and attributes in ATTRS.  */
+			  val = font_select_entity (f, entities,
+						    attrs, pixel_size, c);
+			  if (! NILP (val))
+			    {
+			      SAFE_FREE ();
+			      return val;
+			    }
 			}
 		    }
 		}
-- 
2.35.1


  reply	other threads:[~2022-11-20 13:57 UTC|newest]

Thread overview: 123+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-18  4:57 bug#59347: 29.0.50; `:family` face setting ignored Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-18 12:37 ` Eli Zaretskii
2022-11-18 14:59   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-18 15:13     ` Eli Zaretskii
2022-11-18 15:25       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-18 16:54         ` Eli Zaretskii
2022-11-18 17:21           ` Eli Zaretskii
2022-11-18 20:00             ` Yuan Fu
2022-11-18 20:12               ` Yuan Fu
2022-11-18 21:09                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-19  7:21                   ` Eli Zaretskii
2022-11-18 19:46           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-18 19:58             ` Eli Zaretskii
2022-11-18 20:55             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-19  7:15               ` Eli Zaretskii
2022-11-19 14:55                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-19 15:31                   ` Eli Zaretskii
2022-11-19 16:01                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-19 16:16                       ` Eli Zaretskii
2022-11-20 13:57                         ` Gregory Heytings [this message]
2022-11-20 14:59                           ` Eli Zaretskii
2022-11-20 15:35                             ` Gregory Heytings
2022-11-20 15:54                               ` Eli Zaretskii
2022-11-20 16:59                                 ` Gregory Heytings
2022-11-20 17:29                                   ` Eli Zaretskii
2022-11-20 17:43                                     ` Gregory Heytings
2022-11-20 17:58                                       ` Eli Zaretskii
2022-11-20 18:11                                         ` Gregory Heytings
2022-11-20 18:19                                           ` Eli Zaretskii
2022-11-20 19:45                                             ` Gregory Heytings
2022-11-20 20:01                                               ` Eli Zaretskii
2022-11-20 20:08                                                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-20 20:45                                           ` Gregory Heytings
2022-11-21 12:27                                             ` Eli Zaretskii
2022-11-20 18:30                                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-20 18:53                                           ` Eli Zaretskii
2022-11-20 18:31                                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-20 18:54                                           ` Eli Zaretskii
2022-11-20 21:49                                         ` Gregory Heytings
2022-11-21 12:51                                           ` Eli Zaretskii
2022-11-21 14:48                                             ` Gregory Heytings
2022-11-21 15:08                                               ` Eli Zaretskii
2022-11-21 23:34                                                 ` Gregory Heytings
2022-11-22  0:34                                                   ` Gregory Heytings
2022-11-22  3:05                                                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-22  7:59                                                       ` Gregory Heytings
2022-11-22 13:38                                                         ` Eli Zaretskii
2022-11-22 13:46                                                           ` Gregory Heytings
2022-11-22 13:16                                                       ` Eli Zaretskii
2022-11-22 13:38                                                         ` Gregory Heytings
2022-11-22 14:38                                                           ` Eli Zaretskii
2022-11-22 14:45                                                             ` Gregory Heytings
2022-11-22 14:53                                                               ` Eli Zaretskii
2022-11-22 15:41                                                                 ` Gregory Heytings
2022-11-22 17:44                                                                   ` Eli Zaretskii
2022-11-22 20:52                                                                     ` Gregory Heytings
2022-11-22 20:47                                                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-23  8:13                                                               ` Gregory Heytings
2022-11-30 10:03                                                                 ` Gregory Heytings
2022-11-30 14:00                                                                   ` Eli Zaretskii
2022-11-30 15:38                                                                     ` Gregory Heytings
2022-12-04 14:21                                                                       ` Eli Zaretskii
2022-12-05 23:30                                                                         ` Gregory Heytings
2022-12-06 14:22                                                                           ` Eli Zaretskii
2022-12-07 11:00                                                                             ` Gregory Heytings
     [not found]                                                                             ` <d99c6016-3b32-1116-9ef1-43fe40a71a4@heytings.org>
2022-12-07 11:02                                                                               ` Gregory Heytings
2022-12-07 23:19                                                                             ` Gregory Heytings
2022-12-08  0:27                                                                               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08  1:07                                                                                 ` Gregory Heytings
2022-12-08  8:16                                                                                   ` Eli Zaretskii
2022-12-08 14:59                                                                                     ` Gregory Heytings
2022-12-08 15:13                                                                                       ` Eli Zaretskii
     [not found]                                                                                     ` <e1b79bb2-a3c5-2677-57d8-fb6db43dfd9@heytings.org>
2022-12-08 16:27                                                                                       ` Gregory Heytings
2022-12-08 14:12                                                                                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 15:33                                                                                     ` Gregory Heytings
2022-12-08 17:29                                                                                     ` Drew Adams
2022-12-08 17:44                                                                                       ` Eli Zaretskii
2022-12-08  5:32                                                                                 ` Yuan Fu
2022-12-08  8:09                                                                                 ` Eli Zaretskii
2022-12-08 14:17                                                                                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 14:49                                                                                     ` Eli Zaretskii
2022-12-08 15:24                                                                                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 15:45                                                                                         ` Eli Zaretskii
2022-12-08  8:03                                                                               ` Eli Zaretskii
2022-12-08 12:53                                                                                 ` Gregory Heytings
2022-12-08 14:16                                                                                   ` Eli Zaretskii
2022-12-08 15:17                                                                                     ` Gregory Heytings
2022-12-08 15:42                                                                                       ` Eli Zaretskii
2022-12-10 22:51                                                                                         ` Gregory Heytings
2022-12-12  0:57                                                                                           ` Gregory Heytings
2022-12-12  1:49                                                                                             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-12  8:54                                                                                               ` Gregory Heytings
2022-12-12 10:33                                                                                                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-12 10:51                                                                                                   ` Gregory Heytings
2022-12-12 11:18                                                                                                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-12 11:38                                                                                                       ` Gregory Heytings
2022-12-12 12:47                                                                                                         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-12 15:30                                                                                               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-12 15:45                                                                                                 ` Eli Zaretskii
2022-12-12 15:07                                                                                             ` Eli Zaretskii
2022-12-12 16:12                                                                                               ` Gregory Heytings
2022-12-12 17:10                                                                                                 ` Eli Zaretskii
2022-12-12 21:28                                                                                                   ` Gregory Heytings
2022-12-13 11:58                                                                                                     ` Eli Zaretskii
2022-12-13  1:16                                                                                               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-13 15:40                                                                                                 ` Eli Zaretskii
2022-12-04 14:23                                                                 ` Eli Zaretskii
2022-11-22  6:42                                                     ` Gregory Heytings
2022-11-22  8:01                                                       ` Gregory Heytings
2022-11-22 13:27                                                       ` Eli Zaretskii
2022-11-22 12:38                                                   ` Eli Zaretskii
2022-11-22 12:43                                                     ` Gregory Heytings
2022-11-22 14:29                                                   ` Eli Zaretskii
2022-11-22 14:39                                                     ` Gregory Heytings
2022-11-22 14:52                                                       ` Eli Zaretskii
2022-11-22 15:17                                                         ` Gregory Heytings
2022-11-20 18:16                           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-20 19:46                             ` Gregory Heytings
2022-11-19  0:20 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-19  0:28   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-19  4:37     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-19  6:01       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-19 14:17         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

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=7cc9e03786024fc72f3b@heytings.org \
    --to=gregory@heytings.org \
    --cc=59347@debbugs.gnu.org \
    --cc=eliz@gnu.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).