unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] Use fontconfig spec for parsing font-weight.
@ 2021-05-17  4:37 Yukio Siraichi
  2021-05-17  6:14 ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Yukio Siraichi @ 2021-05-17  4:37 UTC (permalink / raw)
  To: emacs-devel

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

Hi.

This patch addresses one of the differences between 'fontconfig' 
font-weight table, and the one inside emacs. Basically, the problem was 
that emacs wasn't listing fonts whose weight=55. However, those are 
defined to be 'semilight' in the fontconfig specification (see link below).

Reproducing this problem only requires the existence of fonts whose 
weight=55 (one can use fc-cat for that). It's possible to observe that 
such fonts are not found in 'x-list-fonts' or when running 'describe-font'.

https://www.freedesktop.org/software/fontconfig/fontconfig-user.html

I don't fully understand how emacs is using the 'weight_table' (in 
font.c), so my explanation may not be fully correct, but this patch does 
make (fontconfig) semilight fonts show up.

Regards,

Yukio


[-- Attachment #2: 0001-Use-fontconfig-spec-for-parsing-font-weight.patch --]
[-- Type: text/x-patch, Size: 857 bytes --]

From 966241a4f215c8157830405859fbae5da7a68518 Mon Sep 17 00:00:00 2001
From: Yukio Siraichi <yukio.siraichi@gmail.com>
Date: Mon, 17 May 2021 13:20:11 +0900
Subject: [PATCH] Use fontconfig spec for parsing font-weight.

---
 src/font.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/font.c b/src/font.c
index 7c1d1ff89b..b420bb14a7 100644
--- a/src/font.c
+++ b/src/font.c
@@ -69,7 +69,8 @@ #define DEFAULT_ENCODING Qiso8859_1
   { 20, { "ultra-light", "ultralight" }},
   { 40, { "extra-light", "extralight" }},
   { 50, { "light" }},
-  { 75, { "semi-light", "semilight", "demilight", "book" }},
+  { 55, { "semi-light", "semilight", "demilight" }},
+  { 75, { "book" }},
   { 100, { "normal", "medium", "regular", "unspecified" }},
   { 180, { "semi-bold", "semibold", "demibold", "demi" }},
   { 200, { "bold" }},
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use fontconfig spec for parsing font-weight.
  2021-05-17  4:37 [PATCH] Use fontconfig spec for parsing font-weight Yukio Siraichi
@ 2021-05-17  6:14 ` Eli Zaretskii
       [not found]   ` <75349245-3caa-ea30-939d-0a2b8bc32aa5@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2021-05-17  6:14 UTC (permalink / raw)
  To: Yukio Siraichi; +Cc: emacs-devel

> From: Yukio Siraichi <sir.yukio@gmail.com>
> Date: Mon, 17 May 2021 13:37:31 +0900
> 
> This patch addresses one of the differences between 'fontconfig' 
> font-weight table, and the one inside emacs. Basically, the problem was 
> that emacs wasn't listing fonts whose weight=55. However, those are 
> defined to be 'semilight' in the fontconfig specification (see link below).
> 
> Reproducing this problem only requires the existence of fonts whose 
> weight=55 (one can use fc-cat for that). It's possible to observe that 
> such fonts are not found in 'x-list-fonts' or when running 'describe-font'.

Thanks, but why is it important for these fonts to appear in those
lists?  What is the practical advantage of that for Emacs users?



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use fontconfig spec for parsing font-weight.
       [not found]   ` <75349245-3caa-ea30-939d-0a2b8bc32aa5@gmail.com>
@ 2021-05-17  7:30     ` Eli Zaretskii
  2021-05-17  7:44       ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2021-05-17  7:30 UTC (permalink / raw)
  To: Yukio Siraichi; +Cc: emacs-devel

[Please use Reply All to keep the list address on CC.]

> From: Yukio Siraichi <sir.yukio@gmail.com>
> Date: Mon, 17 May 2021 15:25:55 +0900
> 
>  > Thanks, but why is it important for these fonts to appear in those
>  > lists? What is the practical advantage of that for Emacs users?
> 
> Well, anyone that wants to use a 'semilight' defined font would benefit 
> from this patch. Without it, I believe there is no way to use those fonts.

Use those fonts how and in what situations?  IOW, could you please
describe a complete use scenario where having these fonts in the list
would be beneficial?

I'm asking because AFAIK Emacs has the following built-in :weight
values (and some aliases of them) for a face:

  ‘ultra-bold’, ‘extra-bold’, ‘bold’, ‘semi-bold’, ‘normal’,
  ‘semi-light’, ‘light’, ‘extra-light’, ‘ultra-light’

The value ‘book’ is not one of them, it is currently an alias of
‘semi-light’.  Your patch adds a separate ‘book’ value, and also
changes the numeric equivalent of ‘semi-light’.  AFAICT, this will
change the results of converting a font's weight to the corresponding
Emacs symbolic value, see the function font_style_symbolic, where you
will clearly see that the numeric values in the weight_table table are
not randomly chosen.  E.g., some fonts that are currently considered
to be of ‘normal’ weight will be considered to be of ‘book’ weight as
result of your change, because the number of entries will change, and
so indexing into the weight table will change as well.

So this small and seemingly simple change will have over-reaching
effects all over Emacs, when font selection and use in faces is
considered, and I think we need to have a good understanding of why we
are making it before we decide to do it.  (Obviously, documentation
will need to be updated as well, something your patch doesn't do.)

But maybe I'm missing something, and this is not actually such a big
problem?  Would people who have good understanding of the effect of
this change and the need to make it please chime in?

Thanks.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use fontconfig spec for parsing font-weight.
  2021-05-17  7:30     ` Eli Zaretskii
@ 2021-05-17  7:44       ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2021-05-17  7:44 UTC (permalink / raw)
  To: sir.yukio; +Cc: emacs-devel

Btw, the same reference

  https://www.freedesktop.org/software/fontconfig/fontconfig-user.html

also considers 'normal' and 'medium' different, whereas in Emacs they
are synonyms.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use fontconfig spec for parsing font-weight.
       [not found] <1b6ef436-2f32-bfed-f0a8-f55aa4852ccd@gmail.com>
@ 2021-05-17  9:54 ` Eli Zaretskii
  2021-05-17 10:11   ` Yukio Siraichi
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2021-05-17  9:54 UTC (permalink / raw)
  To: Yukio Siraichi; +Cc: emacs-devel

[Please use Reply All to repy, so that the list is CC'ed.]

> From: Yukio Siraichi <sir.yukio@gmail.com>
> Date: Mon, 17 May 2021 17:26:48 +0900
> 
> > Use those fonts how and in what situations? IOW, could you please
> > describe a complete use scenario where having these fonts in the list
> > would be beneficial? 
> 
> Sure. It happened to me yesterday, where I was trying to use "Cascadia Code SemiLight" as the default
> font. So, I tried adding:
> 
> (set-face-attribute 'default nil :family "Cascadia Code" :weight 'semilight)
> 
> to my "init.el". After restarting emacs, I noticed it wasn't using that font. Specifically, I ran "describe-char" on
> some characters that were using the default face, and noticed the font used was "normal":
> 
> -SAJA-Cascadia Code-light-normal-normal-*-13-*-*-*-m-0-
> 
> Running "describe-font" on that, I found that it was using the "Cascadia Code-Light.otf" font (not the
> semilight I wanted). In fact, no matter what I tried, I couldn't use that semilight font.

But 'semi-light' is already supported by Emacs, so why did you need to
add the 'book' attribute?

What happens if you do the above separately, that is with 2 calls
instead of just one:

 (set-face-attribute 'default nil :family "Cascadia Code")
 (set-face-attribute 'default nil :weight 'semi-light)

Does this work?



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use fontconfig spec for parsing font-weight.
  2021-05-17  9:54 ` Eli Zaretskii
@ 2021-05-17 10:11   ` Yukio Siraichi
  2021-05-17 10:29     ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Yukio Siraichi @ 2021-05-17 10:11 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

> But 'semi-light' is already supported by Emacs, so why did you need to
> add the 'book' attribute?

I didn't really add the 'book' attribute. It was already there (as the last alias of 'semi-light'). I added a new row, and moved the 'semilight' aliases with it (left 'book' there, though). My guess is that, since it doesn't recognize the weight value (55) passed by 'fontconfig', it fallbacks to other weight values. So, what I did is to add a new weight value (the number that 'fontconfig' converted to, from the OTF file).

> What happens if you do the above separately, that is with 2 calls
> instead of just one:
>
>  (set-face-attribute 'default nil :family "Cascadia Code")
>  (set-face-attribute 'default nil :weight 'semi-light)
> 
> Does this work?

Apparently, not.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use fontconfig spec for parsing font-weight.
  2021-05-17 10:11   ` Yukio Siraichi
@ 2021-05-17 10:29     ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2021-05-17 10:29 UTC (permalink / raw)
  To: Yukio Siraichi; +Cc: emacs-devel

> Cc: emacs-devel@gnu.org
> From: Yukio Siraichi <sir.yukio@gmail.com>
> Date: Mon, 17 May 2021 19:11:33 +0900
> 
> > But 'semi-light' is already supported by Emacs, so why did you need to
> > add the 'book' attribute?
> 
> I didn't really add the 'book' attribute. It was already there (as the last alias of 'semi-light'). I added a new row, and moved the 'semilight' aliases with it (left 'book' there, though). My guess is that, since it doesn't recognize the weight value (55) passed by 'fontconfig', it fallbacks to other weight values. So, what I did is to add a new weight value (the number that 'fontconfig' converted to, from the OTF file).
> 
> > What happens if you do the above separately, that is with 2 calls
> > instead of just one:
> >
> >  (set-face-attribute 'default nil :family "Cascadia Code")
> >  (set-face-attribute 'default nil :weight 'semi-light)
> > 
> > Does this work?
> 
> Apparently, not.

Thanks, I hope someone with access to such a system could debug this
and figure out why it doesn't work.  My reading of the code is that
the weight value of 55 should be interpreted as 'light', but I'm
probably missing something.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-05-17 10:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17  4:37 [PATCH] Use fontconfig spec for parsing font-weight Yukio Siraichi
2021-05-17  6:14 ` Eli Zaretskii
     [not found]   ` <75349245-3caa-ea30-939d-0a2b8bc32aa5@gmail.com>
2021-05-17  7:30     ` Eli Zaretskii
2021-05-17  7:44       ` Eli Zaretskii
     [not found] <1b6ef436-2f32-bfed-f0a8-f55aa4852ccd@gmail.com>
2021-05-17  9:54 ` Eli Zaretskii
2021-05-17 10:11   ` Yukio Siraichi
2021-05-17 10:29     ` Eli Zaretskii

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).