GNU bug report logs - #49797
28.0.50; Setting face to custom fontset doesn't work

Previous Next

Package: emacs;

Reported by: Yuan Fu <casouri <at> gmail.com>

Date: Sat, 31 Jul 2021 21:38:01 UTC

Severity: normal

Found in version 28.0.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 49797 in the body.
You can then email your comments to 49797 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Sat, 31 Jul 2021 21:38:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Yuan Fu <casouri <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 31 Jul 2021 21:38:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Bug Report Emacs <bug-gnu-emacs <at> gnu.org>
Subject: 28.0.50; Setting face to custom fontset doesn't work
Date: Sat, 31 Jul 2021 17:37:05 -0400
If I evaluate the following:

(progn
  (create-fontset-from-fontset-spec
   (font-xlfd-name
    (font-spec :registry "fontset-lunamono")))
  (set-fontset-font "fontset-lunamono" 'latin (font-spec :family "SF Mono"))
  (set-face-attribute 'default nil :fontset "fontset-lunamono”))

I expect Latin characters to be shown in SF Mono font, but that’s not what happened. If I instead set font for the default fontset, the characters in the buffer are correctly displayed in SF Mono font. I tried this code snippet with Emacs 26, 27 and 28, and all of them have this problem.

I can see that the fondest is correctly modified by looking at the result of describe-fontset, so I guess it’s the face that isn’t finding the correct font to display the character.

Yuan

In GNU Emacs 28.0.50 (build 72, x86_64-apple-darwin20.3.0, NS appkit-2022.30 Version 11.2.3 (Build 20D91))
of 2021-07-31 built on Brown
Repository revision: dd34bef7d3769a8574bcee2c1e91e8445129af75
Repository branch: master
Windowing system distributor 'Apple', version 10.3.2022
System Description:  macOS 11.2.3

Configured using:
'configure --with-pdumper=yes --with-ns --enable-checking=yes,glyphs
--enable-check-lisp-object-type 'CFLAGS=-O0 -g3''

Configured features:
ACL GLIB GNUTLS JSON LCMS2 LIBXML2 MODULES NOTIFY KQUEUE NS PDUMPER PNG
RSVG THREADS TOOLKIT_SCROLL_BARS XIM ZLIB

Important settings:
  value of $LC_CTYPE: en_US.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg epg-config gnus-util rmail
rmail-loaddefs auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map text-property-search time-date
subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
iso-transl tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel term/ns-win ns-win ucs-normalize mule-util
term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads kqueue cocoa ns lcms2
multi-tty make-network-process emacs)

Memory information:
((conses 16 51166 10427)
(symbols 48 6528 1)
(strings 32 17706 1638)
(string-bytes 1 583355)
(vectors 16 13503)
(vector-slots 8 175734 10173)
(floats 8 21 47)
(intervals 56 190 0)
(buffers 992 11))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Sun, 01 Aug 2021 06:04:01 GMT) Full text and rfc822 format available.

Message #8 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>, Kenichi Handa <handa <at> gnu.org>
Cc: 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Sun, 01 Aug 2021 09:03:31 +0300
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Sat, 31 Jul 2021 17:37:05 -0400
> 
> If I evaluate the following:
> 
> (progn
>   (create-fontset-from-fontset-spec
>    (font-xlfd-name
>     (font-spec :registry "fontset-lunamono")))
>   (set-fontset-font "fontset-lunamono" 'latin (font-spec :family "SF Mono"))
>   (set-face-attribute 'default nil :fontset "fontset-lunamono”))
> 
> I expect Latin characters to be shown in SF Mono font, but that’s not what happened. If I instead set font for the default fontset, the characters in the buffer are correctly displayed in SF Mono font. I tried this code snippet with Emacs 26, 27 and 28, and all of them have this problem.
> 
> I can see that the fondest is correctly modified by looking at the result of describe-fontset, so I guess it’s the face that isn’t finding the correct font to display the character.

CC'ing Handa-san, in the hope that he could help us with this issue.

Personally, I lack a clear understanding of how user-defined fontsets
are supposed to be used instead of the standard fontsets.  Is that
only by using the :font attribute of a face?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Sun, 01 Aug 2021 15:19:02 GMT) Full text and rfc822 format available.

Message #11 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Kenichi Handa <handa <at> gnu.org>, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Sun, 1 Aug 2021 11:18:50 -0400
> 
> Personally, I lack a clear understanding of how user-defined fontsets
> are supposed to be used instead of the standard fontsets.  Is that
> only by using the :font attribute of a face?

The documentation of face attributes doesn't mention it for some reason, but I found another face attribute :fontset when reading the code. IIUC, according to realize_gui_face, when Emacs realize a face, it combines the fontset in :fonset attribute with the :font attribute (and other font attributes like :family, etc): the :fontset one is used as the base fontset, and we make ascii characters in the base fondest to use the font specified in the :font attribute (combined with other font attributes). This is done by make_fontset_for_ascii_face (the name is slightly misleading).

But in reality, it doesn’t seem to work like that; changing the default fontset seem to have an effect but changing custom fontset doesn't. I found this function fontset_font, in it we first find a font from the custom fontset, then try to find a font in the default fontset. So if the default fontset has an effect but the custom one doesn’t, maybe the code that finds font in the custom fontset has problem. That’s my uneducated conjecture, so take with a grain of salt.

Yuan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Sun, 01 Aug 2021 16:03:02 GMT) Full text and rfc822 format available.

Message #14 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: handa <at> gnu.org, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Sun, 01 Aug 2021 19:01:57 +0300
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Sun, 1 Aug 2021 11:18:50 -0400
> Cc: Kenichi Handa <handa <at> gnu.org>,
>  49797 <at> debbugs.gnu.org
> 
> > 
> > Personally, I lack a clear understanding of how user-defined fontsets
> > are supposed to be used instead of the standard fontsets.  Is that
> > only by using the :font attribute of a face?
> 
> The documentation of face attributes doesn't mention it for some reason

Yes, it does: see the doc string of set-face-font.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Sun, 01 Aug 2021 16:28:02 GMT) Full text and rfc822 format available.

Message #17 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Kenichi Handa <handa <at> gnu.org>, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Sun, 1 Aug 2021 12:27:32 -0400

> On Aug 1, 2021, at 12:01 PM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>> From: Yuan Fu <casouri <at> gmail.com>
>> Date: Sun, 1 Aug 2021 11:18:50 -0400
>> Cc: Kenichi Handa <handa <at> gnu.org>,
>> 49797 <at> debbugs.gnu.org
>> 
>>> 
>>> Personally, I lack a clear understanding of how user-defined fontsets
>>> are supposed to be used instead of the standard fontsets.  Is that
>>> only by using the :font attribute of a face?
>> 
>> The documentation of face attributes doesn't mention it for some reason
> 
> Yes, it does: see the doc string of set-face-font.

I mean the :fontset attribute. Maybe it is supposed to be merged into the :font attribute so documentations don’t mention :fontset? But the code still refers to it (Finternal_set_lisp_face_attribute).

Yuan



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Sun, 01 Aug 2021 16:43:02 GMT) Full text and rfc822 format available.

Message #20 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: handa <at> gnu.org, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Sun, 01 Aug 2021 19:42:27 +0300
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Sun, 1 Aug 2021 12:27:32 -0400
> Cc: Kenichi Handa <handa <at> gnu.org>,
>  49797 <at> debbugs.gnu.org
> 
> >> The documentation of face attributes doesn't mention it for some reason
> > 
> > Yes, it does: see the doc string of set-face-font.
> 
> I mean the :fontset attribute. Maybe it is supposed to be merged into the :font attribute so documentations don’t mention :fontset? But the code still refers to it (Finternal_set_lisp_face_attribute).

I think the :fontset attribute isn't supposed to be set by Lisp
programs.  It's for internal use.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Mon, 02 Aug 2021 11:59:02 GMT) Full text and rfc822 format available.

Message #23 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: handa <handa <at> gnu.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: casouri <at> gmail.com, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Mon, 02 Aug 2021 20:57:48 +0900
> > From: Yuan Fu <casouri <at> gmail.com>
> > Date: Sat, 31 Jul 2021 17:37:05 -0400
> > 
> > If I evaluate the following:
> > 
> > (progn
> >   (create-fontset-from-fontset-spec
> >    (font-xlfd-name
> >     (font-spec :registry "fontset-lunamono")))
> >   (set-fontset-font "fontset-lunamono" 'latin (font-spec :family "SF Mono"))
> >   (set-face-attribute 'default nil :fontset "fontset-lunamono”))
> > 
> > I expect Latin characters to be shown in SF Mono font, but that’s not what happened. If I instead set font for the default fontset, the characters in the buffer are correctly displayed in SF Mono font. I tried this code snippet with Emacs 26, 27 and 28, and all of them have this problem.
> > 

Please try (set-face-attribute 'default nil :font "fontset-lunamono").

The docstring of set-face-attribute says:
------------------------------------------------------------
...
‘:font’

Set font-related face attributes from VALUE.
VALUE must be a valid font name or font object.  It can also
be a fontset name.  Setting this attribute will also set
^^^^^^^^^^^^^^^^^
the ‘:family’, ‘:foundry’, ‘:width’, ‘:height’, ‘:weight’,
and ‘:slant’ attributes.
------------------------------------------------------------

> Personally, I lack a clear understanding of how user-defined fontsets
> are supposed to be used instead of the standard fontsets.  Is that
> only by using the :font attribute of a face?

In article <83v94pm80c.fsf <at> gnu.org>, Eli Zaretskii <eliz <at> gnu.org> writes:
[...]
> I think the :fontset attribute isn't supposed to be set by Lisp
> programs.  It's for internal use.

I don't remember well, but I tend to agree.  RMS's request was to make
fontset acceptable at any places where a font is accepted.

---
K. Handa
handa <at> gnu.org




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Mon, 02 Aug 2021 17:15:02 GMT) Full text and rfc822 format available.

Message #26 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Fu Yuan <casouri <at> gmail.com>
To: handa <handa <at> gnu.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Mon, 2 Aug 2021 13:14:18 -0400

> 在 2021年8月2日,上午7:57,handa <handa <at> gnu.org> 写道:
> 
> 
>> 
>>> From: Yuan Fu <casouri <at> gmail.com>
>>> Date: Sat, 31 Jul 2021 17:37:05 -0400
>>> 
>>> If I evaluate the following:
>>> 
>>> (progn
>>>  (create-fontset-from-fontset-spec
>>>   (font-xlfd-name
>>>    (font-spec :registry "fontset-lunamono")))
>>>  (set-fontset-font "fontset-lunamono" 'latin (font-spec :family "SF Mono"))
>>>  (set-face-attribute 'default nil :fontset "fontset-lunamono”))
>>> 
>>> I expect Latin characters to be shown in SF Mono font, but that’s not what happened. If I instead set font for the default fontset, the characters in the buffer are correctly displayed in SF Mono font. I tried this code snippet with Emacs 26, 27 and 28, and all of them have this problem.
>>> 
> 
> Please try (set-face-attribute 'default nil :font "fontset-lunamono").
> 

Sorry for the confusion. I actually tried both :font and :fontset,  but neither works.

Yuan



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Tue, 05 Oct 2021 15:37:01 GMT) Full text and rfc822 format available.

Message #29 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: handa <handa <at> gnu.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Tue, 5 Oct 2021 08:36:26 -0700
[Message part 1 (text/plain, inline)]
I finally got myself a Linux machine and am able to use gdb and poke around in xfaces.c. I think the reason why setting custom fontset doesn’t work is at here, in Finternal_set_lisp_face_attribute at xfaces.c:3425:

		  if (STRINGP (value))
		    {
		      Lisp_Object name = value;
		      int fontset = fs_query_fontset (name, 0);

		      if (fontset >= 0)
			name = fontset_ascii (fontset);
		      value = font_spec_from_name (name);
		      if (!FONTP (value))
			signal_error ("Invalid font name", name);
		    }
		  else
		    signal_error ("Invalid font or font-spec", value);

Basically, if I try to set a custom fontset to the :font attribute, Emacs takes the ASCII font from my custom fontset, and set the :font attribute to that ASCII font. Then if the face is the default face, in set_font_frame_param, Emacs translates the font attribute to the frame’s “font" parameter. Finally in gui_set_font, Emacs looks at the “font” frame parameter and sets frame’s font.

If I try to set :fontset attribute for ‘default, Finternal_set_lisp_face_attribute works just fine, setting the fontset attribute in the face, but set_font_frame_param completely ignores the fontset attribute, still setting the “font” frame parameter with the :font attribute, and gui_set_font uses the “font” frame parameter . That’s why setting :fontset takes no effect either.

For faces other than default, setting :fontset works fine, because realize_gui_face handles :fontset attribute correctly. But it doesn’t handle the case where the :font attribute contains a fontset. It works right now because Finternal_set_lisp_face always converts the fontset passed to :font attribute to an font (as described above).

Here is my attempt to fix it:

In Finternal_set_lisp_face_attribute, if the :font attribute actually carries a fontset, set the :fontset attribute, in addition to the old logic which extracts a font from it and set the font to the :font attribute.

The, in set_font_frame_param, instead of looking at :font slot alone, we look at both :font and :fontset slot. If any of them is specified, use that for the “font” frame parameter. Prefer :fontset when both are specified.

In Finternal_get_lisp_face_attribute, if the user asks for a :font, prefer to return :fontset if both :fontset and :font are specified. (See comment for more detail.)

This scheme can hide the :fontset attribute from users, and allow them to set the fontset for a face with the :font attribute. The existing code that handles :fontset is untouched.

I am able to get the correct behavior described in the manual with this patch. WDYT? (I also attached a test file that I used.)

Yuan

[fontset.patch (application/octet-stream, attachment)]
[fontset-test.el (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Tue, 05 Oct 2021 16:13:01 GMT) Full text and rfc822 format available.

Message #32 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: handa <at> gnu.org, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Tue, 05 Oct 2021 19:12:14 +0300
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Tue, 5 Oct 2021 08:36:26 -0700
> Cc: Eli Zaretskii <eliz <at> gnu.org>,
>  49797 <at> debbugs.gnu.org
> 
> I finally got myself a Linux machine and am able to use gdb and poke around in xfaces.c. I think the reason why setting custom fontset doesn’t work is at here, in Finternal_set_lisp_face_attribute at xfaces.c:3425:
> 
> 		  if (STRINGP (value))
> 		    {
> 		      Lisp_Object name = value;
> 		      int fontset = fs_query_fontset (name, 0);
> 
> 		      if (fontset >= 0)
> 			name = fontset_ascii (fontset);
> 		      value = font_spec_from_name (name);
> 		      if (!FONTP (value))
> 			signal_error ("Invalid font name", name);
> 		    }
> 		  else
> 		    signal_error ("Invalid font or font-spec", value);
> 
> Basically, if I try to set a custom fontset to the :font attribute, Emacs takes the ASCII font from my custom fontset, and set the :font attribute to that ASCII font. Then if the face is the default face, in set_font_frame_param, Emacs translates the font attribute to the frame’s “font" parameter. Finally in gui_set_font, Emacs looks at the “font” frame parameter and sets frame’s font.
> 
> If I try to set :fontset attribute for ‘default, Finternal_set_lisp_face_attribute works just fine, setting the fontset attribute in the face, but set_font_frame_param completely ignores the fontset attribute, still setting the “font” frame parameter with the :font attribute, and gui_set_font uses the “font” frame parameter . That’s why setting :fontset takes no effect either.
> 
> For faces other than default, setting :fontset works fine, because realize_gui_face handles :fontset attribute correctly. But it doesn’t handle the case where the :font attribute contains a fontset. It works right now because Finternal_set_lisp_face always converts the fontset passed to :font attribute to an font (as described above).
> 
> Here is my attempt to fix it:

I don't think I have a clear understanding of the problem you are
trying to solve, since 2 months passed since we last talked about
this.

First, Handa-san asked to try a slightly different setting; I'm not
sure I understand whether you did and if so, what were the results.  I
also don't understand if the analysis of the code above is for the
original test case or the one suggested by Handa-san.  I'd like to see
the latter.

Next, you define a fontset for the 'latin' script, but that script
includes the ASCII characters, and AFAIR Emacs generally ignores such
settings, using the default font instead.  Did you try the same with a
script that doesn't include ASCII?

And finally, even if all of the above isn't relevant or doesn't work,
what real-life problem do you want to solve that cannot be solved by
some other setting?  Why use fontsets to define a font for the default
face?

The font selection and the fontset code in Emacs is not understood
well enough by the current active maintainers, so making non-trivial
changes there might risk breaking important use cases, and we will be
unable to catch that in time because we are not familiar with the
code.  So unless you have a grave problem that has no other good
solution, I'd prefer not to make changes in this stuff.

That said, if Handa-san reviews the change and thinks it's a good
idea, I will withdraw my objections.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Tue, 05 Oct 2021 17:33:02 GMT) Full text and rfc822 format available.

Message #35 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Kenichi Handa <handa <at> gnu.org>, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Tue, 5 Oct 2021 10:31:59 -0700
[Message part 1 (text/plain, inline)]
> 
> I don't think I have a clear understanding of the problem you are
> trying to solve, since 2 months passed since we last talked about
> this.

Basically, Emacs doesn’t do what it claims to do in the manual, see below for more explanation.

> 
> First, Handa-san asked to try a slightly different setting; I'm not
> sure I understand whether you did and if so, what were the results.  I
> also don't understand if the analysis of the code above is for the
> original test case or the one suggested by Handa-san.  I'd like to see
> the latter.

I have indeed tried and it didn’t work, maybe you missed that message. Handa-san suggests me to try setting :font attribute rather than :fontset. The test code uses what he suggests: using :font attribute.

> 
> Next, you define a fontset for the 'latin' script, but that script
> includes the ASCII characters, and AFAIR Emacs generally ignores such
> settings, using the default font instead.  Did you try the same with a
> script that doesn't include ASCII?

I have, and it doesn’t work. But that’s not really the point, I’ll explain further below.

> 
> And finally, even if all of the above isn't relevant or doesn't work,
> what real-life problem do you want to solve that cannot be solved by
> some other setting?  Why use fontsets to define a font for the default
> face?

I just want to use different CJK fonts for different faces. The use case for me is this: I want to create two fontsets, “fontset-serif” and “fontset-mono”. And I assign serif CJK and Latin fonts to “fontset-serif”, monospace CJK and Latin fonts to “fontset-mono”. Then, I assign “fontset-serif” to variable-pitch face, and “fontset-mono” to default face. This allows me to use different CJK fonts in variable-pitch face and default face, just like I have different Latin fonts for variable-pitch and default face.

The situation now is that, if I assign “fontset-serif” to variable-pitch face, Emacs strips my CJK font (and any other non-ASCII font, for that matter), turns the fontset into an ASCII font, and only sets :font attribute with that ASCII font for variable-pitch face. Effectively, I can only use one CJK font for all the faces, namely the CJK font in the default fontset.

I think you would agree that, for non-Latin speakers, using different fonts for different faces (for non-Latin) characters is an important feature. Further more, this feature is clearly documented in the manual, but doesn’t work in reality.

> 
> The font selection and the fontset code in Emacs is not understood
> well enough by the current active maintainers, so making non-trivial
> changes there might risk breaking important use cases, and we will be
> unable to catch that in time because we are not familiar with the
> code.  So unless you have a grave problem that has no other good
> solution, I'd prefer not to make changes in this stuff.

I understand, that’s why I tried to make minimal modification to the existing code. I hope by now I’ve convinced you that the feature I’m trying to fix is significant/useful enough. Not only is it useful, it (fontset) is already implemented, only hindered by a few bugs in the interface that prohibits anyone to make good use of it. 

However, I would be lying if I say there is no other solution—there is one, but it is far from a good solution. Basically, if I set the undocumented :fontset attribute for a face, I can get that face to use the CJK font in the fontset (recall that if I set the :font attribute with a fontset, the fontset is turned into an ASCII font). That comes with a catch: setting the :fontset attribute for the default face does not work. However, setting the frame parameter “font” to the fontset works. This “solution” cannot be described better than this image:


> 
> That said, if Handa-san reviews the change and thinks it's a good
> idea, I will withdraw my objections.

That’ll be the best I can hope for it seems.

Yuan
[Message part 2 (text/html, inline)]
[IMAGE 2021-10-05 10:19:22.jpeg (image/jpeg, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Tue, 05 Oct 2021 19:03:02 GMT) Full text and rfc822 format available.

Message #38 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: handa <at> gnu.org, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Tue, 05 Oct 2021 22:01:55 +0300
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Tue, 5 Oct 2021 10:31:59 -0700
> Cc: Kenichi Handa <handa <at> gnu.org>,
>  49797 <at> debbugs.gnu.org
> 
> Basically, Emacs doesn’t do what it claims to do in the manual, see below for more explanation.

It isn't the first time, and the solution could be to fix the docs.

> I just want to use different CJK fonts for different faces.

Why do you need that?  And why specifically for CJK?

> I think you would agree that, for non-Latin speakers, using different fonts for different faces (for non-Latin) characters is an important feature.

No, I don't think I understand why.

And the usual way to do this is to request a font family or foundry in
the face spec, not via fontsets.  Doesn't that work for some reason?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Tue, 05 Oct 2021 19:16:01 GMT) Full text and rfc822 format available.

Message #41 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Kenichi Handa <handa <at> gnu.org>, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Tue, 5 Oct 2021 12:15:01 -0700

> On Oct 5, 2021, at 12:01 PM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>> From: Yuan Fu <casouri <at> gmail.com>
>> Date: Tue, 5 Oct 2021 10:31:59 -0700
>> Cc: Kenichi Handa <handa <at> gnu.org>,
>> 49797 <at> debbugs.gnu.org
>> 
>> Basically, Emacs doesn’t do what it claims to do in the manual, see below for more explanation.
> 
> It isn't the first time, and the solution could be to fix the docs.

We could, but I think the current behavior is wrong (in the sense that it is against what the code is supposed to do, from what I can read). It would be worse to ratify and document the wrong behavior.

> 
>> I just want to use different CJK fonts for different faces.
> 
> Why do you need that?  And why specifically for CJK?

Because I only know Chinese? For someone else it could be Arabic characters, Japanese hiragana, etc. If you mean why I need more than one font for CJK, it’s the same reason for why I need more than one Latin font—because they look different and has different use.

> 
>> I think you would agree that, for non-Latin speakers, using different fonts for different faces (for non-Latin) characters is an important feature.
> 
> No, I don't think I understand why.
> 
> And the usual way to do this is to request a font family or foundry in
> the face spec, not via fontsets.  Doesn't that work for some reason?

Because I want to use different font for different characters for that face, isn’t that the whole point of fontsets? Maybe it is easier to understand this way:

variable-pitch -> :font "fontset-serif” -> - Latin: Charter
                                           - CJK: Source Han Serif
default -> :font "fontset-default" -> - Latin: SF Mono
                                      - CJK: Source Han Sans

Currently I am unable to use Source Han Serif for CJK characters for variable-pitch face (without the ugly solution I mentioned previously).

Yuan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Tue, 05 Oct 2021 19:20:02 GMT) Full text and rfc822 format available.

Message #44 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: handa <at> gnu.org, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Tue, 05 Oct 2021 22:18:52 +0300
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Tue, 5 Oct 2021 12:15:01 -0700
> Cc: Kenichi Handa <handa <at> gnu.org>,
>  49797 <at> debbugs.gnu.org
> 
> > And the usual way to do this is to request a font family or foundry in
> > the face spec, not via fontsets.  Doesn't that work for some reason?
> 
> Because I want to use different font for different characters for that face, isn’t that the whole point of fontsets? Maybe it is easier to understand this way:
> 
> variable-pitch -> :font "fontset-serif” -> - Latin: Charter
>                                            - CJK: Source Han Serif
> default -> :font "fontset-default" -> - Latin: SF Mono
>                                       - CJK: Source Han Sans
> 
> Currently I am unable to use Source Han Serif for CJK characters for variable-pitch face (without the ugly solution I mentioned previously).

I asked why not use :family and :foundry in the face definition.  Did
you try that?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Tue, 05 Oct 2021 19:28:02 GMT) Full text and rfc822 format available.

Message #47 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: handa <at> gnu.org, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Tue, 05 Oct 2021 22:26:58 +0300
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Tue, 5 Oct 2021 10:31:59 -0700
> Cc: Kenichi Handa <handa <at> gnu.org>,
>  49797 <at> debbugs.gnu.org
> 
> > First, Handa-san asked to try a slightly different setting; I'm not
> > sure I understand whether you did and if so, what were the results.  I
> > also don't understand if the analysis of the code above is for the
> > original test case or the one suggested by Handa-san.  I'd like to see
> > the latter.
> 
> I have indeed tried and it didn’t work, maybe you missed that message. Handa-san suggests me to try setting :font attribute rather than :fontset. The test code uses what he suggests: using :font attribute.

And the description what happens with the code is for that second
example, or is it for the first?  And the same question about your
proposed fix -- which case does it fix?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Tue, 05 Oct 2021 20:52:02 GMT) Full text and rfc822 format available.

Message #50 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: handa <at> gnu.org, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Tue, 5 Oct 2021 13:51:23 -0700
> I asked why not use :family and :foundry in the face definition.  Did
> you try that?

:family, :foundry, :font, they all realize into _one_ font. My point is, to cover all characters might be displayed, the face needs _multiple_ fonts (therefore I need to use a fontset).

Suppose you know Chinese. You want serif CJK and Latin font for variable-pitch, and sans CJK and Latin font for default. 

|                | CJK              | Latin   |
| variable-pitch | Source Han Serif | Charter |
| default	     | Source Han Sans  | SF Mono |

How do you make variable-pitch use Source Han Serif for CJK and Charter for Latin with :family or :foundry attribute? Unless I’m incredibly ignorant of something, you cannot. That’s why we have fontsets: it’s basically a mega font composed of multiple fonts that can use different fonts for different characters. Do we agree on that?

>>> First, Handa-san asked to try a slightly different setting; I'm not
>>> sure I understand whether you did and if so, what were the results.  I
>>> also don't understand if the analysis of the code above is for the
>>> original test case or the one suggested by Handa-san.  I'd like to see
>>> the latter.
>> 
>> I have indeed tried and it didn’t work, maybe you missed that message. Handa-san suggests me to try setting :font attribute rather than :fontset. The test code uses what he suggests: using :font attribute.
> 
> And the description what happens with the code is for that second
> example, or is it for the first?  And the same question about your
> proposed fix -- which case does it fix?

The description of what happens with the code explains what happens with both :font and :fontset—both has problems.

Problem 1: The following doesn’t work as intended:

(set-face-attribute 'variable-pitch nil :font "fontset-serif”)

where “fontset-serif” contains two fonts: Charter for Latin and Source Han Serif for CJK. 

The current effect is, Latin characters in ‘variable-pitch works (displayed in Charter), CJK characters don’t (not displayed in Source Han Serif). With my fix, CJK characters work (displayed in Source Han Serif).

Problem 2: ‘default face cannot use fontset. Even if problem 1 is fixed, setting the fontset for the default face still doesn’t display CJK characters correctly. With the fix, setting a fontset for ‘default works as intended.

The problems are not limited to CJK characters, any other non-ASCII character that requires a font different from the Latin characters has the same problem.

My fix is based on the assumption that we want to use :font attribute for both font and fontsets, which is what the manual says, and is what Handa-san said what RMS wanted.

Yuan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Wed, 06 Oct 2021 16:12:01 GMT) Full text and rfc822 format available.

Message #53 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: handa <at> gnu.org, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Wed, 06 Oct 2021 19:10:59 +0300
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Tue, 5 Oct 2021 13:51:23 -0700
> Cc: handa <at> gnu.org,
>  49797 <at> debbugs.gnu.org
> 
> > I asked why not use :family and :foundry in the face definition.  Did
> > you try that?
> 
> :family, :foundry, :font, they all realize into _one_ font.

:font does.  :family doesn't, AFAIK, and :foundry definitely doesn't.

But that was just a suggestion, and it doesn't help you if you want to
use very specific fonts for specific scripts.

> Problem 1: The following doesn’t work as intended:
> 
> (set-face-attribute 'variable-pitch nil :font "fontset-serif”)
> 
> where “fontset-serif” contains two fonts: Charter for Latin and Source Han Serif for CJK. 
> 
> The current effect is, Latin characters in ‘variable-pitch works (displayed in Charter), CJK characters don’t (not displayed in Source Han Serif). With my fix, CJK characters work (displayed in Source Han Serif).
> 
> Problem 2: ‘default face cannot use fontset. Even if problem 1 is fixed, setting the fontset for the default face still doesn’t display CJK characters correctly. With the fix, setting a fontset for ‘default works as intended.
> 
> The problems are not limited to CJK characters, any other non-ASCII character that requires a font different from the Latin characters has the same problem.

The thing is, what you describe as "problems" is how this stuff was
designed to work, at least AFAIU the code.  Specifically, the face we
define and see in Lisp specifies the font only for the ASCII
characters.  When Emacs needs to display a non-ASCII character with
some face (including the 'default' face), it calls face_for_char.
That function will use the same face if its font supports the
character, but if not, it will create a new "derivative" face.  That
derivative face shares all the face attributes with the original one,
but has a different font.  These derivative faces are never exposed to
Lisp, and don't have names, so a few people even know they exist, but
they are very visible on the C level: they have a distinct face ID.

You want to force Emacs to use the face's font for non-ASCII
characters, but that's not how this stuff was designed, AFAIU.  If I'm
not missing something, it means what you perceive as bugs are at best
design bugs, not implementation bugs, and they cannot be fixed with a
few lines of tweaking.  That might work in your relatively simple use
case, but I don't see how we can trust that not to break important
features, because working against the design always runs that risk.

For example, this part of your patch:

> @@ -4040,7 +4055,17 @@ DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute,
>    else if (EQ (keyword, QCextend))
>      value = LFACE_EXTEND (lface);
>    else if (EQ (keyword, QCfont))
> -    value = LFACE_FONT (lface);
> +    {
> +      /* We prefer to return fontset, if it is specified, because font
> +	 are derived from fontset when the user sets the
> +	 fontset. I.e., if the fontset is specified, that's probably
> +	 the one that the user set, and it is intuitive to get back
> +	 what you put in.  */
> +      if (!UNSPECIFIEDP (LFACE_FONTSET (lface)))
> +	value = LFACE_FONTSET (lface);
> +      else
> +	value = LFACE_FONT (lface);
> +    }

This is completely ad-hoc, and could be wrong in some cases: the
caller wanted the font, but you provide it with a fontset, which is a
completely different Lisp object.  And there are other similarly
ad-hoc changes of the semantics of the face attributes.

Maybe we can extend the design to support "face-specific" fontsets,
but I'm quite sure that will need changes in font.c and fontset.c as
well, because the current design is implicitly assumed there.

> My fix is based on the assumption that we want to use :font attribute for both font and fontsets, which is what the manual says, and is what Handa-san said what RMS wanted.

That's one way of interpreting what the manual says, but it is not the
only one.  If you look at what the code does, you will arrive at
another interpretation: Emacs allows you to specify a fontset as the
value for the :font attribute, but what it does in that case is take
from the fontset the font for ASCII characters, and then use it as if
you specified that font, not a fontset.  IOW, the fontset in that case
is just used as a method of specifying the ASCII font.

But even if your interpretation were the only correct one, the way
faces and font selection works in Emacs was not designed to support
your interpretation (again, if my reading of the code is correct).

I hope Handa-san will chime in soon and set us straight.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Wed, 06 Oct 2021 18:12:01 GMT) Full text and rfc822 format available.

Message #56 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Kenichi Handa <handa <at> gnu.org>, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Wed, 6 Oct 2021 11:11:42 -0700
Again, thanks for spending your time on this.

> 
>> Problem 1: The following doesn’t work as intended:
>> 
>> (set-face-attribute 'variable-pitch nil :font "fontset-serif”)
>> 
>> where “fontset-serif” contains two fonts: Charter for Latin and Source Han Serif for CJK. 
>> 
>> The current effect is, Latin characters in ‘variable-pitch works (displayed in Charter), CJK characters don’t (not displayed in Source Han Serif). With my fix, CJK characters work (displayed in Source Han Serif).
>> 
>> Problem 2: ‘default face cannot use fontset. Even if problem 1 is fixed, setting the fontset for the default face still doesn’t display CJK characters correctly. With the fix, setting a fontset for ‘default works as intended.
>> 
>> The problems are not limited to CJK characters, any other non-ASCII character that requires a font different from the Latin characters has the same problem.
> 
> The thing is, what you describe as "problems" is how this stuff was
> designed to work, at least AFAIU the code.  Specifically, the face we
> define and see in Lisp specifies the font only for the ASCII
> characters.  When Emacs needs to display a non-ASCII character with
> some face (including the 'default' face), it calls face_for_char.
> That function will use the same face if its font supports the
> character, but if not, it will create a new "derivative" face.  That
> derivative face shares all the face attributes with the original one,
> but has a different font.  These derivative faces are never exposed to
> Lisp, and don't have names, so a few people even know they exist, but
> they are very visible on the C level: they have a distinct face ID.
> 
> You want to force Emacs to use the face's font for non-ASCII
> characters, but that's not how this stuff was designed, AFAIU.  If I'm
> not missing something, it means what you perceive as bugs are at best
> design bugs, not implementation bugs, and they cannot be fixed with a
> few lines of tweaking.  That might work in your relatively simple use
> case, but I don't see how we can trust that not to break important
> features, because working against the design always runs that risk.

The comment in face_for_char literally says:

         ...so
         that users could still setup fontsets to force Emacs to use
         specific fonts for characters from other scripts, because
         choice of fonts is frequently affected by cultural
         preferences and font features, not by font coverage…

Later in that function, we take the fontset of that face

        fontset = FONTSET_FROM_ID (face->fontset);

Then find an appropriate font from it

        rfont_def = fontset_font (fontset, c, face, id);

So Emacs definitely is designed to support using fontsets to assign different fonts for different characters to faces. In fact, you can try this right now (without my patch):

        (set-face-attribute 'variable-pitch :fontset "fontset-serif”)

(Notice I used the :fontset attribute, not :font attribute.) And the variable-pitch face will work as intended, use CJK font for CJK characters and Latin font for Latin characters, specified in “fontset-serif”. The only problem is 1) :fontset attribute is not documented and 2) this doesn’t work with ‘default face.

> 
> For example, this part of your patch:
> 
>> @@ -4040,7 +4055,17 @@ DEFUN ("internal-get-lisp-face-attribute", Finternal_get_lisp_face_attribute,
>>   else if (EQ (keyword, QCextend))
>>     value = LFACE_EXTEND (lface);
>>   else if (EQ (keyword, QCfont))
>> -    value = LFACE_FONT (lface);
>> +    {
>> +      /* We prefer to return fontset, if it is specified, because font
>> +	 are derived from fontset when the user sets the
>> +	 fontset. I.e., if the fontset is specified, that's probably
>> +	 the one that the user set, and it is intuitive to get back
>> +	 what you put in.  */
>> +      if (!UNSPECIFIEDP (LFACE_FONTSET (lface)))
>> +	value = LFACE_FONTSET (lface);
>> +      else
>> +	value = LFACE_FONT (lface);
>> +    }
> 
> This is completely ad-hoc, and could be wrong in some cases: the
> caller wanted the font, but you provide it with a fontset, which is a
> completely different Lisp object.  And there are other similarly
> ad-hoc changes of the semantics of the face attributes.

It is ad-hoc, but that’s just to fit my interpretation of the manual that we don’t want to expose :fontset attribute and want to use :font for both :fontset and :font. If that interpretation is wrong, we can of course fix the problem in other non-ad-hoc way.

> 
> Maybe we can extend the design to support "face-specific" fontsets,
> but I'm quite sure that will need changes in font.c and fontset.c as
> well, because the current design is implicitly assumed there.

Emacs already has an elaborate implementation to support fontsets, it is just hindered by the manual and bugs in the Lisp interface.

> 
>> My fix is based on the assumption that we want to use :font attribute for both font and fontsets, which is what the manual says, and is what Handa-san said what RMS wanted.
> 
> That's one way of interpreting what the manual says, but it is not the
> only one.  If you look at what the code does, you will arrive at
> another interpretation: Emacs allows you to specify a fontset as the
> value for the :font attribute, but what it does in that case is take
> from the fontset the font for ASCII characters, and then use it as if
> you specified that font, not a fontset.  IOW, the fontset in that case
> is just used as a method of specifying the ASCII font.

I agree, another way is to document the :fontset attribute, document that passing a fontset to :font attribute only sets the ASCII font, and fix the bug where setting :fontset attribute for ‘default face doesn’t work.

Yuan



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Wed, 06 Oct 2021 18:34:02 GMT) Full text and rfc822 format available.

Message #59 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: handa <at> gnu.org, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Wed, 06 Oct 2021 21:33:46 +0300
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Wed, 6 Oct 2021 11:11:42 -0700
> Cc: Kenichi Handa <handa <at> gnu.org>,
>  49797 <at> debbugs.gnu.org
> 
> Later in that function, we take the fontset of that face
> 
>         fontset = FONTSET_FROM_ID (face->fontset);
> 
> Then find an appropriate font from it
> 
>         rfont_def = fontset_font (fontset, c, face, id);

Yes, AFAIU that's the part where we check if the current face's
fontset's font, made for the ASCII characters, happens to have a glyph
for the non-ASCII character we need to display.

> So Emacs definitely is designed to support using fontsets to assign different fonts for different characters to faces. In fact, you can try this right now (without my patch):
> 
>         (set-face-attribute 'variable-pitch :fontset "fontset-serif”)
> 
> (Notice I used the :fontset attribute, not :font attribute.) And the variable-pitch face will work as intended, use CJK font for CJK characters and Latin font for Latin characters, specified in “fontset-serif”. The only problem is 1) :fontset attribute is not documented and 2) this doesn’t work with ‘default face.

As mentioned earlier, user code is not supposed to set the :fontset
attribute directly, which is why it isn't documented.

> > Maybe we can extend the design to support "face-specific" fontsets,
> > but I'm quite sure that will need changes in font.c and fontset.c as
> > well, because the current design is implicitly assumed there.
> 
> Emacs already has an elaborate implementation to support fontsets

Not fontsets specific to faces, according to my reading of the code,
as I tried to explain.

> it is just hindered by the manual and bugs in the Lisp interface.

Or maybe by design.

> > That's one way of interpreting what the manual says, but it is not the
> > only one.  If you look at what the code does, you will arrive at
> > another interpretation: Emacs allows you to specify a fontset as the
> > value for the :font attribute, but what it does in that case is take
> > from the fontset the font for ASCII characters, and then use it as if
> > you specified that font, not a fontset.  IOW, the fontset in that case
> > is just used as a method of specifying the ASCII font.
> 
> I agree, another way is to document the :fontset attribute, document that passing a fontset to :font attribute only sets the ASCII font, and fix the bug where setting :fontset attribute for ‘default face doesn’t work.

I'm saying that fixing this will probably need more extensive changes
than in your proposed patch.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Wed, 06 Oct 2021 18:57:02 GMT) Full text and rfc822 format available.

Message #62 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Kenichi Handa <handa <at> gnu.org>, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Wed, 6 Oct 2021 11:56:18 -0700

> On Oct 6, 2021, at 11:33 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>> From: Yuan Fu <casouri <at> gmail.com>
>> Date: Wed, 6 Oct 2021 11:11:42 -0700
>> Cc: Kenichi Handa <handa <at> gnu.org>,
>> 49797 <at> debbugs.gnu.org
>> 
>> Later in that function, we take the fontset of that face
>> 
>>        fontset = FONTSET_FROM_ID (face->fontset);
>> 
>> Then find an appropriate font from it
>> 
>>        rfont_def = fontset_font (fontset, c, face, id);
> 
> Yes, AFAIU that's the part where we check if the current face's
> fontset's font, made for the ASCII characters, happens to have a glyph
> for the non-ASCII character we need to display.

That is not, the part you mentioned is before:

      if (face->ascii_face->font)
	{
	  XSETFONT (font_object, face->ascii_face->font);
	  if (font_has_char (f, font_object, c))
	    return face->ascii_face->id;
	}

And what about the comment I mentioned? Did you read it?

In any case, 

    rfont_def = fontset_font (fontset, c, face, id); 

finds a font in the fontset that can display character c. That’s hard to ignore.

> 
>> So Emacs definitely is designed to support using fontsets to assign different fonts for different characters to faces. In fact, you can try this right now (without my patch):
>> 
>>        (set-face-attribute 'variable-pitch :fontset "fontset-serif”)
>> 
>> (Notice I used the :fontset attribute, not :font attribute.) And the variable-pitch face will work as intended, use CJK font for CJK characters and Latin font for Latin characters, specified in “fontset-serif”. The only problem is 1) :fontset attribute is not documented and 2) this doesn’t work with ‘default face.
> 
> As mentioned earlier, user code is not supposed to set the :fontset
> attribute directly, which is why it isn't documented.

Finternal_set_lisp_face_attribute has code that let me set :fontset. Why is it there if Lisp is not supposed to set :fontset? Plus, Emacs doesn’t set :fontset by itself, what’s the point for this attribute, then, if Emacs doesn’t set it itself and don’t want the user to set it?

> 
>>> Maybe we can extend the design to support "face-specific" fontsets,
>>> but I'm quite sure that will need changes in font.c and fontset.c as
>>> well, because the current design is implicitly assumed there.
>> 
>> Emacs already has an elaborate implementation to support fontsets
> 
> Not fontsets specific to faces, according to my reading of the code,
> as I tried to explain.
> 
>> it is just hindered by the manual and bugs in the Lisp interface.
> 
> Or maybe by design.
> 
>>> That's one way of interpreting what the manual says, but it is not the
>>> only one.  If you look at what the code does, you will arrive at
>>> another interpretation: Emacs allows you to specify a fontset as the
>>> value for the :font attribute, but what it does in that case is take
>>> from the fontset the font for ASCII characters, and then use it as if
>>> you specified that font, not a fontset.  IOW, the fontset in that case
>>> is just used as a method of specifying the ASCII font.
>> 
>> I agree, another way is to document the :fontset attribute, document that passing a fontset to :font attribute only sets the ASCII font, and fix the bug where setting :fontset attribute for ‘default face doesn’t work.
> 
> I'm saying that fixing this will probably need more extensive changes
> than in your proposed patch.

I don’t think so. Anyway, you don’t seem convinced albeit clear evidences in my eye. Let’s wait for Handa-san to enlighten us.

Yuan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Wed, 06 Oct 2021 19:04:01 GMT) Full text and rfc822 format available.

Message #65 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: handa <at> gnu.org, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Wed, 06 Oct 2021 22:02:51 +0300
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Wed, 6 Oct 2021 11:56:18 -0700
> Cc: Kenichi Handa <handa <at> gnu.org>,
>  49797 <at> debbugs.gnu.org
> 
> >>        fontset = FONTSET_FROM_ID (face->fontset);
> >> 
> >> Then find an appropriate font from it
> >> 
> >>        rfont_def = fontset_font (fontset, c, face, id);
> > 
> > Yes, AFAIU that's the part where we check if the current face's
> > fontset's font, made for the ASCII characters, happens to have a glyph
> > for the non-ASCII character we need to display.
> 
> That is not, the part you mentioned is before:
> 
>       if (face->ascii_face->font)
> 	{
> 	  XSETFONT (font_object, face->ascii_face->font);
> 	  if (font_has_char (f, font_object, c))
> 	    return face->ascii_face->id;
> 	}

No, this is where we try to use the ASCII font for symbols and
punctuation characters.

> And what about the comment I mentioned? Did you read it?

Yes, but it has no relevance to the issue at hand.  That whole part is
about displaying symbol and punctuation characters.

> In any case, 
> 
>     rfont_def = fontset_font (fontset, c, face, id); 
> 
> finds a font in the fontset that can display character c. That’s hard to ignore.

I didn't.

> > As mentioned earlier, user code is not supposed to set the :fontset
> > attribute directly, which is why it isn't documented.
> 
> Finternal_set_lisp_face_attribute has code that let me set :fontset. Why is it there if Lisp is not supposed to set :fontset?

How is that relevant?  That something is possible doesn't mean it's
recommended.

> Plus, Emacs doesn’t set :fontset by itself

It does, via the Lisp attributes and LFACE_FONTSET_INDEX.  That's what
matters on the C level.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Thu, 07 Oct 2021 20:14:02 GMT) Full text and rfc822 format available.

Message #68 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Kenichi Handa <handa <at> gnu.org>, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Thu, 7 Oct 2021 13:13:28 -0700

> On Oct 6, 2021, at 12:02 PM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>> From: Yuan Fu <casouri <at> gmail.com>
>> Date: Wed, 6 Oct 2021 11:56:18 -0700
>> Cc: Kenichi Handa <handa <at> gnu.org>,
>> 49797 <at> debbugs.gnu.org
>> 
>>>>       fontset = FONTSET_FROM_ID (face->fontset);
>>>> 
>>>> Then find an appropriate font from it
>>>> 
>>>>       rfont_def = fontset_font (fontset, c, face, id);
>>> 
>>> Yes, AFAIU that's the part where we check if the current face's
>>> fontset's font, made for the ASCII characters, happens to have a glyph
>>> for the non-ASCII character we need to display.
>> 
>> That is not, the part you mentioned is before:
>> 
>>      if (face->ascii_face->font)
>> 	{
>> 	  XSETFONT (font_object, face->ascii_face->font);
>> 	  if (font_has_char (f, font_object, c))
>> 	    return face->ascii_face->id;
>> 	}
> 
> No, this is where we try to use the ASCII font for symbols and
> punctuation characters.

You are right.

> 
>> And what about the comment I mentioned? Did you read it?
> 
> Yes, but it has no relevance to the issue at hand.  That whole part is
> about displaying symbol and punctuation characters.

It IMO reveals the writer’s intent that fontset can be used to force a face to display certain characters with certain font. I won’t insist on proving this, tho.

> 
>> In any case, 
>> 
>>    rfont_def = fontset_font (fontset, c, face, id); 
>> 
>> finds a font in the fontset that can display character c. That’s hard to ignore.
> 
> I didn't.

Ok.

> 
>>> As mentioned earlier, user code is not supposed to set the :fontset
>>> attribute directly, which is why it isn't documented.
>> 
>> Finternal_set_lisp_face_attribute has code that let me set :fontset. Why is it there if Lisp is not supposed to set :fontset?
> 
> How is that relevant?  That something is possible doesn't mean it's
> recommended.

Ok.

> 
>> Plus, Emacs doesn’t set :fontset by itself
> 
> It does, via the Lisp attributes and LFACE_FONTSET_INDEX.  That's what
> matters on the C level.

Ok.

Still, I believe fontset is supposed to be used as I described. Let’s wait for Handa-san.

Thanks,
Yuan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Fri, 08 Oct 2021 05:39:01 GMT) Full text and rfc822 format available.

Message #71 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: handa <at> gnu.org, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Fri, 08 Oct 2021 08:38:07 +0300
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Thu, 7 Oct 2021 13:13:28 -0700
> Cc: Kenichi Handa <handa <at> gnu.org>,
>  49797 <at> debbugs.gnu.org
> 
> >>      if (face->ascii_face->font)
> >> 	{
> >> 	  XSETFONT (font_object, face->ascii_face->font);
> >> 	  if (font_has_char (f, font_object, c))
> >> 	    return face->ascii_face->id;
> >> 	}
> > 
> > No, this is where we try to use the ASCII font for symbols and
> > punctuation characters.
> 
> You are right.
> 
> > 
> >> And what about the comment I mentioned? Did you read it?
> > 
> > Yes, but it has no relevance to the issue at hand.  That whole part is
> > about displaying symbol and punctuation characters.
> 
> It IMO reveals the writer’s intent that fontset can be used to force a face to display certain characters with certain font.

I don't see how you arrived at that conclusion.  What the above
snippet does is simply check whether the face's font used for the
ASCII characters (which is the default font of the face) is capable of
displaying the given symbol or punctuation character, and if so, it
uses that default font instead of consulting the fontset (where symbol
and punctuation characters could be assigned to a different font).
There's no reference or usage of any fontset in this code snippet.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Fri, 08 Oct 2021 19:36:01 GMT) Full text and rfc822 format available.

Message #74 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: handa <at> gnu.org, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Fri, 8 Oct 2021 12:35:24 -0700

> On Oct 7, 2021, at 10:38 PM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>> From: Yuan Fu <casouri <at> gmail.com>
>> Date: Thu, 7 Oct 2021 13:13:28 -0700
>> Cc: Kenichi Handa <handa <at> gnu.org>,
>> 49797 <at> debbugs.gnu.org
>> 
>>>>     if (face->ascii_face->font)
>>>> 	{
>>>> 	  XSETFONT (font_object, face->ascii_face->font);
>>>> 	  if (font_has_char (f, font_object, c))
>>>> 	    return face->ascii_face->id;
>>>> 	}
>>> 
>>> No, this is where we try to use the ASCII font for symbols and
>>> punctuation characters.
>> 
>> You are right.
>> 
>>> 
>>>> And what about the comment I mentioned? Did you read it?
>>> 
>>> Yes, but it has no relevance to the issue at hand.  That whole part is
>>> about displaying symbol and punctuation characters.
>> 
>> It IMO reveals the writer’s intent that fontset can be used to force a face to display certain characters with certain font.
> 
> I don't see how you arrived at that conclusion.  What the above
> snippet does is simply check whether the face's font used for the
> ASCII characters (which is the default font of the face) is capable of
> displaying the given symbol or punctuation character, and if so, it
> uses that default font instead of consulting the fontset (where symbol
> and punctuation characters could be assigned to a different font).
> There's no reference or usage of any fontset in this code snippet.

Maybe you are right.

Yuan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49797; Package emacs. (Mon, 22 Aug 2022 10:36:02 GMT) Full text and rfc822 format available.

Message #77 received at 49797 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: handa <at> gnu.org, Eli Zaretskii <eliz <at> gnu.org>, 49797 <at> debbugs.gnu.org
Subject: Re: bug#49797: 28.0.50; Setting face to custom fontset doesn't work
Date: Mon, 22 Aug 2022 12:35:25 +0200
Skimming this bug report, it seems like things here are working as
designed, so I'm closing this bug report.  (I may well have
misunderstood something -- if there's something that should be done on
the Emacs side, please respond to the debbugs address and we'll reopen.)




bug closed, send any further explanations to 49797 <at> debbugs.gnu.org and Yuan Fu <casouri <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 22 Aug 2022 10:36:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 19 Sep 2022 11:24:16 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 218 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.