From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#49797: 28.0.50; Setting face to custom fontset doesn't work Date: Wed, 06 Oct 2021 19:10:59 +0300 Message-ID: <838rz62kx8.fsf@gnu.org> References: <87y29k2h4z.fsf@gnu.org> <3B853424-9F63-4A6B-B7A9-2E3AB71986AC@gmail.com> <835yub4fj5.fsf@gnu.org> <8FD18262-3F40-4033-A49D-F6CEA89A3A31@gmail.com> <83sfxf2ry5.fsf@gnu.org> <1AF30098-F55E-48A7-A0D4-E529DFBA6895@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7327"; mail-complaints-to="usenet@ciao.gmane.io" Cc: handa@gnu.org, 49797@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 06 18:31:19 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mY9p7-0001hi-8f for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 06 Oct 2021 18:31:17 +0200 Original-Received: from localhost ([::1]:45592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mY9p6-0003zY-5L for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 06 Oct 2021 12:31:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mY9WU-0000h7-Fv for bug-gnu-emacs@gnu.org; Wed, 06 Oct 2021 12:12:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33801) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mY9WU-0004vD-3o for bug-gnu-emacs@gnu.org; Wed, 06 Oct 2021 12:12:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mY9WT-0006Zv-PX for bug-gnu-emacs@gnu.org; Wed, 06 Oct 2021 12:12:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 06 Oct 2021 16:12:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49797 X-GNU-PR-Package: emacs Original-Received: via spool by 49797-submit@debbugs.gnu.org id=B49797.163353667825223 (code B ref 49797); Wed, 06 Oct 2021 16:12:01 +0000 Original-Received: (at 49797) by debbugs.gnu.org; 6 Oct 2021 16:11:18 +0000 Original-Received: from localhost ([127.0.0.1]:45347 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mY9Vl-0006Yk-Up for submit@debbugs.gnu.org; Wed, 06 Oct 2021 12:11:18 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:55892) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mY9Vh-0006YR-Px for 49797@debbugs.gnu.org; Wed, 06 Oct 2021 12:11:17 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:59728) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mY9Vc-0003uZ-Ht; Wed, 06 Oct 2021 12:11:08 -0400 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:3642 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mY9Va-0004tC-KW; Wed, 06 Oct 2021 12:11:08 -0400 In-Reply-To: <1AF30098-F55E-48A7-A0D4-E529DFBA6895@gmail.com> (message from Yuan Fu on Tue, 5 Oct 2021 13:51:23 -0700) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:216569 Archived-At: > From: Yuan Fu > 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.