* bug#49797: 28.0.50; Setting face to custom fontset doesn't work @ 2021-07-31 21:37 Yuan Fu 2021-08-01 6:03 ` Eli Zaretskii 0 siblings, 1 reply; 25+ messages in thread From: Yuan Fu @ 2021-07-31 21:37 UTC (permalink / raw) To: 49797 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)) ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-07-31 21:37 bug#49797: 28.0.50; Setting face to custom fontset doesn't work Yuan Fu @ 2021-08-01 6:03 ` Eli Zaretskii 2021-08-01 15:18 ` Yuan Fu 2021-08-02 11:57 ` handa 0 siblings, 2 replies; 25+ messages in thread From: Eli Zaretskii @ 2021-08-01 6:03 UTC (permalink / raw) To: Yuan Fu, Kenichi Handa; +Cc: 49797 > From: Yuan Fu <casouri@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? ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-08-01 6:03 ` Eli Zaretskii @ 2021-08-01 15:18 ` Yuan Fu 2021-08-01 16:01 ` Eli Zaretskii 2021-08-02 11:57 ` handa 1 sibling, 1 reply; 25+ messages in thread From: Yuan Fu @ 2021-08-01 15:18 UTC (permalink / raw) To: Eli Zaretskii; +Cc: Kenichi Handa, 49797 > > 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 ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-08-01 15:18 ` Yuan Fu @ 2021-08-01 16:01 ` Eli Zaretskii 2021-08-01 16:27 ` Yuan Fu 0 siblings, 1 reply; 25+ messages in thread From: Eli Zaretskii @ 2021-08-01 16:01 UTC (permalink / raw) To: Yuan Fu; +Cc: handa, 49797 > From: Yuan Fu <casouri@gmail.com> > Date: Sun, 1 Aug 2021 11:18:50 -0400 > Cc: Kenichi Handa <handa@gnu.org>, > 49797@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. ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-08-01 16:01 ` Eli Zaretskii @ 2021-08-01 16:27 ` Yuan Fu 2021-08-01 16:42 ` Eli Zaretskii 0 siblings, 1 reply; 25+ messages in thread From: Yuan Fu @ 2021-08-01 16:27 UTC (permalink / raw) To: Eli Zaretskii; +Cc: Kenichi Handa, 49797 > On Aug 1, 2021, at 12:01 PM, Eli Zaretskii <eliz@gnu.org> wrote: > >> From: Yuan Fu <casouri@gmail.com> >> Date: Sun, 1 Aug 2021 11:18:50 -0400 >> Cc: Kenichi Handa <handa@gnu.org>, >> 49797@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 ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-08-01 16:27 ` Yuan Fu @ 2021-08-01 16:42 ` Eli Zaretskii 0 siblings, 0 replies; 25+ messages in thread From: Eli Zaretskii @ 2021-08-01 16:42 UTC (permalink / raw) To: Yuan Fu; +Cc: handa, 49797 > From: Yuan Fu <casouri@gmail.com> > Date: Sun, 1 Aug 2021 12:27:32 -0400 > Cc: Kenichi Handa <handa@gnu.org>, > 49797@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. ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-08-01 6:03 ` Eli Zaretskii 2021-08-01 15:18 ` Yuan Fu @ 2021-08-02 11:57 ` handa 2021-08-02 17:14 ` Fu Yuan 1 sibling, 1 reply; 25+ messages in thread From: handa @ 2021-08-02 11:57 UTC (permalink / raw) To: Eli Zaretskii; +Cc: casouri, 49797 > > From: Yuan Fu <casouri@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@gnu.org>, Eli Zaretskii <eliz@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@gnu.org ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-08-02 11:57 ` handa @ 2021-08-02 17:14 ` Fu Yuan 2021-10-05 15:36 ` Yuan Fu 0 siblings, 1 reply; 25+ messages in thread From: Fu Yuan @ 2021-08-02 17:14 UTC (permalink / raw) To: handa; +Cc: 49797 > 在 2021年8月2日,上午7:57,handa <handa@gnu.org> 写道: > > >> >>> From: Yuan Fu <casouri@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 ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-08-02 17:14 ` Fu Yuan @ 2021-10-05 15:36 ` Yuan Fu 2021-10-05 16:12 ` Eli Zaretskii 0 siblings, 1 reply; 25+ messages in thread From: Yuan Fu @ 2021-10-05 15:36 UTC (permalink / raw) To: handa; +Cc: 49797 [-- Attachment #1: Type: text/plain, Size: 2719 bytes --] 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 [-- Attachment #2: fontset.patch --] [-- Type: application/octet-stream, Size: 3174 bytes --] From f8b6517bf6c500a0a99161893529ba8760793a1a Mon Sep 17 00:00:00 2001 From: Yuan Fu <casouri@gmail.com> Date: Mon, 4 Oct 2021 18:47:55 -0700 Subject: [PATCH] Add commit msg later --- src/xfaces.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/xfaces.c b/src/xfaces.c index 5e63e87d75..6a04bc3433 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -3430,13 +3430,17 @@ DEFUN ("internal-set-lisp-face-attribute", Finternal_set_lisp_face_attribute, int fontset = fs_query_fontset (name, 0); if (fontset >= 0) - name = fontset_ascii (fontset); + { + name = fontset_ascii (fontset); + ASET (lface, LFACE_FONTSET_INDEX, value); + } value = font_spec_from_name (name); if (!FONTP (value)) signal_error ("Invalid font name", name); } else - signal_error ("Invalid font or font-spec", value); + signal_error ("Invalid font or font-spec or fontset", + value); } if (EQ (frame, Qt)) f1 = XFRAME (selected_frame); @@ -3720,20 +3724,31 @@ set_font_frame_param (Lisp_Object frame, Lisp_Object lface) { struct frame *f = XFRAME (frame); Lisp_Object font; + Lisp_Object fontset; - if (FRAME_WINDOW_P (f) - /* Don't do anything if the font is `unspecified'. This can - happen during frame creation. */ - && (font = LFACE_FONT (lface), - ! UNSPECIFIEDP (font))) + if (FRAME_WINDOW_P (f)) { - if (FONT_SPEC_P (font)) + font = LFACE_FONT (lface); + fontset = LFACE_FONTSET (lface); + /* Don't do anything if both font and fontset is `unspecified'. + This can happen during frame creation. */ + if (UNSPECIFIEDP (font) && UNSPECIFIEDP (fontset)) + return; + + /* If either one of FONT or FONTSET is specified, we use that + for the "font" frame parameter. */ + if (!UNSPECIFIEDP (fontset)) + font = fontset; + else if (!UNSPECIFIEDP (font) && FONT_SPEC_P (font)) { font = font_load_for_lface (f, XVECTOR (lface)->contents, font); if (NILP (font)) return; ASET (lface, LFACE_FONT_INDEX, font); } + + /* FONTSET is a fontset name (string). */ + f->default_face_done_p = false; AUTO_FRAME_ARG (arg, Qfont, font); Fmodify_frame_parameters (frame, arg); @@ -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); + } else if (EQ (keyword, QCfontset)) value = LFACE_FONTSET (lface); else -- 2.30.1 (Apple Git-130) [-- Attachment #3: fontset-test.el --] [-- Type: application/octet-stream, Size: 1083 bytes --] (progn (create-fontset-from-fontset-spec (font-xlfd-name (font-spec :family "Charter" :registry "fontset-serif"))) (set-fontset-font "fontset-serif" 'han (font-spec :family "Source Han serif")) (create-fontset-from-fontset-spec (font-xlfd-name (font-spec :family "Helvetica" :registry "fontset-sans"))) (set-fontset-font "fontset-sans" 'han (font-spec :family "Source Han Sans")) (create-fontset-from-fontset-spec (font-xlfd-name (font-spec :family "Courier" :registry "fontset-mono"))) (set-fontset-font "fontset-mono" 'han (font-spec :family "Source Han Sans")) (insert "\n\nDefault 默认\n") (insert (propertize "Highlight 高亮" 'font-lock-face 'highlight))) (progn (set-face-font 'default "fontset-mono") (set-face-font 'highlight "fontset-serif")) (progn (set-face-font 'default "fontset-serif") (set-face-font 'highlight "fontset-sans")) (progn (set-face-font 'default "fontset-sans") (set-face-font 'highlight "fontset-mono")) ^ permalink raw reply related [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-05 15:36 ` Yuan Fu @ 2021-10-05 16:12 ` Eli Zaretskii 2021-10-05 17:31 ` Yuan Fu 0 siblings, 1 reply; 25+ messages in thread From: Eli Zaretskii @ 2021-10-05 16:12 UTC (permalink / raw) To: Yuan Fu; +Cc: handa, 49797 > From: Yuan Fu <casouri@gmail.com> > Date: Tue, 5 Oct 2021 08:36:26 -0700 > Cc: Eli Zaretskii <eliz@gnu.org>, > 49797@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. ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-05 16:12 ` Eli Zaretskii @ 2021-10-05 17:31 ` Yuan Fu 2021-10-05 19:01 ` Eli Zaretskii 2021-10-05 19:26 ` Eli Zaretskii 0 siblings, 2 replies; 25+ messages in thread From: Yuan Fu @ 2021-10-05 17:31 UTC (permalink / raw) To: Eli Zaretskii; +Cc: Kenichi Handa, 49797 [-- Attachment #1: Type: text/plain, Size: 4032 bytes --] > > 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 [-- Attachment #2.1: Type: text/html, Size: 5455 bytes --] [-- Attachment #2.2: IMAGE 2021-10-05 10:19:22.jpeg --] [-- Type: image/jpeg, Size: 25732 bytes --] ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-05 17:31 ` Yuan Fu @ 2021-10-05 19:01 ` Eli Zaretskii 2021-10-05 19:15 ` Yuan Fu 2021-10-05 19:26 ` Eli Zaretskii 1 sibling, 1 reply; 25+ messages in thread From: Eli Zaretskii @ 2021-10-05 19:01 UTC (permalink / raw) To: Yuan Fu; +Cc: handa, 49797 > From: Yuan Fu <casouri@gmail.com> > Date: Tue, 5 Oct 2021 10:31:59 -0700 > Cc: Kenichi Handa <handa@gnu.org>, > 49797@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? ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-05 19:01 ` Eli Zaretskii @ 2021-10-05 19:15 ` Yuan Fu 2021-10-05 19:18 ` Eli Zaretskii 0 siblings, 1 reply; 25+ messages in thread From: Yuan Fu @ 2021-10-05 19:15 UTC (permalink / raw) To: Eli Zaretskii; +Cc: Kenichi Handa, 49797 > On Oct 5, 2021, at 12:01 PM, Eli Zaretskii <eliz@gnu.org> wrote: > >> From: Yuan Fu <casouri@gmail.com> >> Date: Tue, 5 Oct 2021 10:31:59 -0700 >> Cc: Kenichi Handa <handa@gnu.org>, >> 49797@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 ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-05 19:15 ` Yuan Fu @ 2021-10-05 19:18 ` Eli Zaretskii 0 siblings, 0 replies; 25+ messages in thread From: Eli Zaretskii @ 2021-10-05 19:18 UTC (permalink / raw) To: Yuan Fu; +Cc: handa, 49797 > From: Yuan Fu <casouri@gmail.com> > Date: Tue, 5 Oct 2021 12:15:01 -0700 > Cc: Kenichi Handa <handa@gnu.org>, > 49797@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? ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-05 17:31 ` Yuan Fu 2021-10-05 19:01 ` Eli Zaretskii @ 2021-10-05 19:26 ` Eli Zaretskii 2021-10-05 20:51 ` Yuan Fu 1 sibling, 1 reply; 25+ messages in thread From: Eli Zaretskii @ 2021-10-05 19:26 UTC (permalink / raw) To: Yuan Fu; +Cc: handa, 49797 > From: Yuan Fu <casouri@gmail.com> > Date: Tue, 5 Oct 2021 10:31:59 -0700 > Cc: Kenichi Handa <handa@gnu.org>, > 49797@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? ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-05 19:26 ` Eli Zaretskii @ 2021-10-05 20:51 ` Yuan Fu 2021-10-06 16:10 ` Eli Zaretskii 0 siblings, 1 reply; 25+ messages in thread From: Yuan Fu @ 2021-10-05 20:51 UTC (permalink / raw) To: Eli Zaretskii; +Cc: handa, 49797 > 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 ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-05 20:51 ` Yuan Fu @ 2021-10-06 16:10 ` Eli Zaretskii 2021-10-06 18:11 ` Yuan Fu 0 siblings, 1 reply; 25+ messages in thread From: Eli Zaretskii @ 2021-10-06 16:10 UTC (permalink / raw) To: Yuan Fu; +Cc: handa, 49797 > From: Yuan Fu <casouri@gmail.com> > Date: Tue, 5 Oct 2021 13:51:23 -0700 > Cc: handa@gnu.org, > 49797@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. ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-06 16:10 ` Eli Zaretskii @ 2021-10-06 18:11 ` Yuan Fu 2021-10-06 18:33 ` Eli Zaretskii 0 siblings, 1 reply; 25+ messages in thread From: Yuan Fu @ 2021-10-06 18:11 UTC (permalink / raw) To: Eli Zaretskii; +Cc: Kenichi Handa, 49797 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 ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-06 18:11 ` Yuan Fu @ 2021-10-06 18:33 ` Eli Zaretskii 2021-10-06 18:56 ` Yuan Fu 0 siblings, 1 reply; 25+ messages in thread From: Eli Zaretskii @ 2021-10-06 18:33 UTC (permalink / raw) To: Yuan Fu; +Cc: handa, 49797 > From: Yuan Fu <casouri@gmail.com> > Date: Wed, 6 Oct 2021 11:11:42 -0700 > Cc: Kenichi Handa <handa@gnu.org>, > 49797@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. ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-06 18:33 ` Eli Zaretskii @ 2021-10-06 18:56 ` Yuan Fu 2021-10-06 19:02 ` Eli Zaretskii 0 siblings, 1 reply; 25+ messages in thread From: Yuan Fu @ 2021-10-06 18:56 UTC (permalink / raw) To: Eli Zaretskii; +Cc: Kenichi Handa, 49797 > On Oct 6, 2021, at 11:33 AM, Eli Zaretskii <eliz@gnu.org> wrote: > >> From: Yuan Fu <casouri@gmail.com> >> Date: Wed, 6 Oct 2021 11:11:42 -0700 >> Cc: Kenichi Handa <handa@gnu.org>, >> 49797@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 ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-06 18:56 ` Yuan Fu @ 2021-10-06 19:02 ` Eli Zaretskii 2021-10-07 20:13 ` Yuan Fu 0 siblings, 1 reply; 25+ messages in thread From: Eli Zaretskii @ 2021-10-06 19:02 UTC (permalink / raw) To: Yuan Fu; +Cc: handa, 49797 > From: Yuan Fu <casouri@gmail.com> > Date: Wed, 6 Oct 2021 11:56:18 -0700 > Cc: Kenichi Handa <handa@gnu.org>, > 49797@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. ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-06 19:02 ` Eli Zaretskii @ 2021-10-07 20:13 ` Yuan Fu 2021-10-08 5:38 ` Eli Zaretskii 0 siblings, 1 reply; 25+ messages in thread From: Yuan Fu @ 2021-10-07 20:13 UTC (permalink / raw) To: Eli Zaretskii; +Cc: Kenichi Handa, 49797 > On Oct 6, 2021, at 12:02 PM, Eli Zaretskii <eliz@gnu.org> wrote: > >> From: Yuan Fu <casouri@gmail.com> >> Date: Wed, 6 Oct 2021 11:56:18 -0700 >> Cc: Kenichi Handa <handa@gnu.org>, >> 49797@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 ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-07 20:13 ` Yuan Fu @ 2021-10-08 5:38 ` Eli Zaretskii 2021-10-08 19:35 ` Yuan Fu 0 siblings, 1 reply; 25+ messages in thread From: Eli Zaretskii @ 2021-10-08 5:38 UTC (permalink / raw) To: Yuan Fu; +Cc: handa, 49797 > From: Yuan Fu <casouri@gmail.com> > Date: Thu, 7 Oct 2021 13:13:28 -0700 > Cc: Kenichi Handa <handa@gnu.org>, > 49797@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. ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-08 5:38 ` Eli Zaretskii @ 2021-10-08 19:35 ` Yuan Fu 2022-08-22 10:35 ` Lars Ingebrigtsen 0 siblings, 1 reply; 25+ messages in thread From: Yuan Fu @ 2021-10-08 19:35 UTC (permalink / raw) To: Eli Zaretskii; +Cc: handa, 49797 > On Oct 7, 2021, at 10:38 PM, Eli Zaretskii <eliz@gnu.org> wrote: > >> From: Yuan Fu <casouri@gmail.com> >> Date: Thu, 7 Oct 2021 13:13:28 -0700 >> Cc: Kenichi Handa <handa@gnu.org>, >> 49797@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 ^ permalink raw reply [flat|nested] 25+ messages in thread
* bug#49797: 28.0.50; Setting face to custom fontset doesn't work 2021-10-08 19:35 ` Yuan Fu @ 2022-08-22 10:35 ` Lars Ingebrigtsen 0 siblings, 0 replies; 25+ messages in thread From: Lars Ingebrigtsen @ 2022-08-22 10:35 UTC (permalink / raw) To: Yuan Fu; +Cc: handa, Eli Zaretskii, 49797 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.) ^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2022-08-22 10:35 UTC | newest] Thread overview: 25+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-07-31 21:37 bug#49797: 28.0.50; Setting face to custom fontset doesn't work Yuan Fu 2021-08-01 6:03 ` Eli Zaretskii 2021-08-01 15:18 ` Yuan Fu 2021-08-01 16:01 ` Eli Zaretskii 2021-08-01 16:27 ` Yuan Fu 2021-08-01 16:42 ` Eli Zaretskii 2021-08-02 11:57 ` handa 2021-08-02 17:14 ` Fu Yuan 2021-10-05 15:36 ` Yuan Fu 2021-10-05 16:12 ` Eli Zaretskii 2021-10-05 17:31 ` Yuan Fu 2021-10-05 19:01 ` Eli Zaretskii 2021-10-05 19:15 ` Yuan Fu 2021-10-05 19:18 ` Eli Zaretskii 2021-10-05 19:26 ` Eli Zaretskii 2021-10-05 20:51 ` Yuan Fu 2021-10-06 16:10 ` Eli Zaretskii 2021-10-06 18:11 ` Yuan Fu 2021-10-06 18:33 ` Eli Zaretskii 2021-10-06 18:56 ` Yuan Fu 2021-10-06 19:02 ` Eli Zaretskii 2021-10-07 20:13 ` Yuan Fu 2021-10-08 5:38 ` Eli Zaretskii 2021-10-08 19:35 ` Yuan Fu 2022-08-22 10:35 ` Lars Ingebrigtsen
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.