From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#49797: 28.0.50; Setting face to custom fontset doesn't work Date: Tue, 5 Oct 2021 08:36:26 -0700 Message-ID: <3B853424-9F63-4A6B-B7A9-2E3AB71986AC@gmail.com> References: <87y29k2h4z.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_6ECEFF58-F1E0-4463-8F80-E5F3079393AA" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25455"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 49797@debbugs.gnu.org To: handa Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 05 17:53:59 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 1mXmlS-0006Kp-NR for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 05 Oct 2021 17:53:58 +0200 Original-Received: from localhost ([::1]:46796 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mXmlR-0008Ot-N2 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 05 Oct 2021 11:53:57 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXmV4-0001fB-24 for bug-gnu-emacs@gnu.org; Tue, 05 Oct 2021 11:37:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58361) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mXmV3-0002HN-Qa for bug-gnu-emacs@gnu.org; Tue, 05 Oct 2021 11:37:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mXmV3-0006Qz-Lt for bug-gnu-emacs@gnu.org; Tue, 05 Oct 2021 11:37:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 05 Oct 2021 15:37: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.163344819724698 (code B ref 49797); Tue, 05 Oct 2021 15:37:01 +0000 Original-Received: (at 49797) by debbugs.gnu.org; 5 Oct 2021 15:36:37 +0000 Original-Received: from localhost ([127.0.0.1]:41674 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mXmUe-0006QG-Jr for submit@debbugs.gnu.org; Tue, 05 Oct 2021 11:36:36 -0400 Original-Received: from mail-oo1-f42.google.com ([209.85.161.42]:42921) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mXmUc-0006Py-5o for 49797@debbugs.gnu.org; Tue, 05 Oct 2021 11:36:35 -0400 Original-Received: by mail-oo1-f42.google.com with SMTP id a17-20020a4a6851000000b002b59bfbf669so6527441oof.9 for <49797@debbugs.gnu.org>; Tue, 05 Oct 2021 08:36:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=du6WoMsNfFqO6CSzqgL0OQCp6voZH5UizwYoDgfExYA=; b=oGpFHKrYOvlqVyIa7uXPV8c1aaNqoXpG6OI7t0yw6pscxJM3Npp4IcJNZR+OfkDoQh Iu2X97+kYd2A4eLKQxlyKdmD8Xke57qfE0nq0usn2zyM57UaxoSE64PcbG0I7TAEn3lK Fw2CQ4RPmEDWC7YHDJY7QQn93uaL3A025XhkyQIZ/224KqEygZm/RRmQu8FsyBj67FJb S7+mdu5OPylWday7CwyS0tZFmRa4QfU0N9hT1XU5TS2z5oGvRaL61x/sFQ7wW0+0gBMf zoX3tk1uSmnxxqTh6kKTiB/FckfBEEkQlM9JCMruCd7i6ctEJbC/DH/9uq/5j5iFChud jzyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=du6WoMsNfFqO6CSzqgL0OQCp6voZH5UizwYoDgfExYA=; b=AQVUGkjYxoE0MroMabf9uE9p692/1Wh+AUCn3YELj3aQ0gaqIUoihwj9g9c0U288mM WYZHfFb0P2zKGZb+IjeYMgPDFFUMjEUcuwTqFtC0K8EvBPr7kT5MW6Ih8SYLrUDogMry NYpxV7CFo4k1ux3M7PH0GJ11UTjUmUL+lJMVA4pYnxKi8tAhl2APgboqHElqRmvAJvHD JVRdQb1AJT6YlkbBaj9HuhALnRotk/fZJg93cTASw01hfg4lnWeFjzlm94ji2R1DzTFf 5qHlR7FCG5JWWR9zxpf1C+mAqpAq+MdJze9R7scpFLK+3FwIc0HXMwdTfGVj5X3blUKZ Q56Q== X-Gm-Message-State: AOAM531Os/y7Fy3qSUkFaT5HIFgUJmNx419H2eM4kOzFgsFFQKxkU8/r xy7hdWkHML+E7ytD0KyUeOzJowS36x0= X-Google-Smtp-Source: ABdhPJzWCgesfA460IJZoVakBL0TSzG4jhfnbJSJ4PLhGOzBUdaBAc5kPchautcdl45KUFAk9CcqLA== X-Received: by 2002:a4a:d455:: with SMTP id p21mr14027704oos.97.1633448188381; Tue, 05 Oct 2021 08:36:28 -0700 (PDT) Original-Received: from smtpclient.apple ([2600:1700:2ec7:8c9f:15f7:79b1:c151:e981]) by smtp.gmail.com with ESMTPSA id b2sm3056582ooi.25.2021.10.05.08.36.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Oct 2021 08:36:27 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3654.120.0.1.13) 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:216468 Archived-At: --Apple-Mail=_6ECEFF58-F1E0-4463-8F80-E5F3079393AA Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 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=E2=80=99t work is at here, in Finternal_set_lisp_face_attribute at = xfaces.c:3425: if (STRINGP (value)) { Lisp_Object name =3D value; int fontset =3D fs_query_fontset (name, 0); if (fontset >=3D 0) name =3D fontset_ascii (fontset); value =3D 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=E2=80=99s =E2=80=9Cfont" parameter. Finally in gui_set_font, Emacs = looks at the =E2=80=9Cfont=E2=80=9D frame parameter and sets frame=E2=80=99= s font. If I try to set :fontset attribute for =E2=80=98default, = 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 =E2=80=9Cfont=E2=80=9D frame = parameter with the :font attribute, and gui_set_font uses the =E2=80=9Cfon= t=E2=80=9D frame parameter . That=E2=80=99s 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=E2=80=99= 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 =E2=80=9Cfont=E2=80=9D 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 --Apple-Mail=_6ECEFF58-F1E0-4463-8F80-E5F3079393AA Content-Disposition: attachment; filename=fontset.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="fontset.patch" Content-Transfer-Encoding: quoted-printable =46rom=20f8b6517bf6c500a0a99161893529ba8760793a1a=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Yuan=20Fu=20=0ADate:=20Mon,=20= 4=20Oct=202021=2018:47:55=20-0700=0ASubject:=20[PATCH]=20Add=20commit=20= msg=20later=0A=0A---=0A=20src/xfaces.c=20|=2043=20= ++++++++++++++++++++++++++++++++++---------=0A=201=20file=20changed,=20= 34=20insertions(+),=209=20deletions(-)=0A=0Adiff=20--git=20= a/src/xfaces.c=20b/src/xfaces.c=0Aindex=205e63e87d75..6a04bc3433=20= 100644=0A---=20a/src/xfaces.c=0A+++=20b/src/xfaces.c=0A@@=20-3430,13=20= +3430,17=20@@=20DEFUN=20("internal-set-lisp-face-attribute",=20= Finternal_set_lisp_face_attribute,=0A=20=09=09=20=20=20=20=20=20int=20= fontset=20=3D=20fs_query_fontset=20(name,=200);=0A=20=0A=20=09=09=20=20=20= =20=20=20if=20(fontset=20>=3D=200)=0A-=09=09=09name=20=3D=20= fontset_ascii=20(fontset);=0A+=09=09=09{=0A+=09=09=09=20=20name=20=3D=20= fontset_ascii=20(fontset);=0A+=09=09=09=20=20ASET=20(lface,=20= LFACE_FONTSET_INDEX,=20value);=0A+=09=09=09}=0A=20=09=09=20=20=20=20=20=20= value=20=3D=20font_spec_from_name=20(name);=0A=20=09=09=20=20=20=20=20=20= if=20(!FONTP=20(value))=0A=20=09=09=09signal_error=20("Invalid=20font=20= name",=20name);=0A=20=09=09=20=20=20=20}=0A=20=09=09=20=20else=0A-=09=09=20= =20=20=20signal_error=20("Invalid=20font=20or=20font-spec",=20value);=0A= +=09=09=20=20=20=20signal_error=20("Invalid=20font=20or=20font-spec=20or=20= fontset",=0A+=09=09=09=09=20=20value);=0A=20=09=09}=0A=20=09=20=20=20=20=20= =20if=20(EQ=20(frame,=20Qt))=0A=20=09=09f1=20=3D=20XFRAME=20= (selected_frame);=0A@@=20-3720,20=20+3724,31=20@@=20set_font_frame_param=20= (Lisp_Object=20frame,=20Lisp_Object=20lface)=0A=20{=0A=20=20=20struct=20= frame=20*f=20=3D=20XFRAME=20(frame);=0A=20=20=20Lisp_Object=20font;=0A+=20= =20Lisp_Object=20fontset;=0A=20=0A-=20=20if=20(FRAME_WINDOW_P=20(f)=0A-=20= =20=20=20=20=20/*=20Don't=20do=20anything=20if=20the=20font=20is=20= `unspecified'.=20=20This=20can=0A-=09=20happen=20during=20frame=20= creation.=20=20*/=0A-=20=20=20=20=20=20&&=20(font=20=3D=20LFACE_FONT=20= (lface),=0A-=09=20=20!=20UNSPECIFIEDP=20(font)))=0A+=20=20if=20= (FRAME_WINDOW_P=20(f))=0A=20=20=20=20=20{=0A-=20=20=20=20=20=20if=20= (FONT_SPEC_P=20(font))=0A+=20=20=20=20=20=20font=20=3D=20LFACE_FONT=20= (lface);=0A+=20=20=20=20=20=20fontset=20=3D=20LFACE_FONTSET=20(lface);=0A= +=20=20=20=20=20=20/*=20Don't=20do=20anything=20if=20both=20font=20and=20= fontset=20is=20`unspecified'.=0A+=09=20This=20can=20happen=20during=20= frame=20creation.=20=20*/=0A+=20=20=20=20=20=20if=20(UNSPECIFIEDP=20= (font)=20&&=20UNSPECIFIEDP=20(fontset))=0A+=09return;=0A+=0A+=20=20=20=20= =20=20/*=20If=20either=20one=20of=20FONT=20or=20FONTSET=20is=20= specified,=20we=20use=20that=0A+=09=20for=20the=20"font"=20frame=20= parameter.=20=20*/=0A+=20=20=20=20=20=20if=20(!UNSPECIFIEDP=20(fontset))=0A= +=09=20=20font=20=3D=20fontset;=0A+=20=20=20=20=20=20else=20if=20= (!UNSPECIFIEDP=20(font)=20&&=20FONT_SPEC_P=20(font))=0A=20=09{=0A=20=09=20= =20font=20=3D=20font_load_for_lface=20(f,=20XVECTOR=20(lface)->contents,=20= font);=0A=20=09=20=20if=20(NILP=20(font))=0A=20=09=20=20=20=20return;=0A=20= =09=20=20ASET=20(lface,=20LFACE_FONT_INDEX,=20font);=0A=20=09}=0A+=0A+=20= =20=20=20=20=20/*=20FONTSET=20is=20a=20fontset=20name=20(string).=20=20= */=0A+=0A=20=20=20=20=20=20=20f->default_face_done_p=20=3D=20false;=0A=20= =20=20=20=20=20=20AUTO_FRAME_ARG=20(arg,=20Qfont,=20font);=0A=20=20=20=20= =20=20=20Fmodify_frame_parameters=20(frame,=20arg);=0A@@=20-4040,7=20= +4055,17=20@@=20DEFUN=20("internal-get-lisp-face-attribute",=20= Finternal_get_lisp_face_attribute,=0A=20=20=20else=20if=20(EQ=20= (keyword,=20QCextend))=0A=20=20=20=20=20value=20=3D=20LFACE_EXTEND=20= (lface);=0A=20=20=20else=20if=20(EQ=20(keyword,=20QCfont))=0A-=20=20=20=20= value=20=3D=20LFACE_FONT=20(lface);=0A+=20=20=20=20{=0A+=20=20=20=20=20=20= /*=20We=20prefer=20to=20return=20fontset,=20if=20it=20is=20specified,=20= because=20font=0A+=09=20are=20derived=20from=20fontset=20when=20the=20= user=20sets=20the=0A+=09=20fontset.=20I.e.,=20if=20the=20fontset=20is=20= specified,=20that's=20probably=0A+=09=20the=20one=20that=20the=20user=20= set,=20and=20it=20is=20intuitive=20to=20get=20back=0A+=09=20what=20you=20= put=20in.=20=20*/=0A+=20=20=20=20=20=20if=20(!UNSPECIFIEDP=20= (LFACE_FONTSET=20(lface)))=0A+=09value=20=3D=20LFACE_FONTSET=20(lface);=0A= +=20=20=20=20=20=20else=0A+=09value=20=3D=20LFACE_FONT=20(lface);=0A+=20=20= =20=20}=0A=20=20=20else=20if=20(EQ=20(keyword,=20QCfontset))=0A=20=20=20=20= =20value=20=3D=20LFACE_FONTSET=20(lface);=0A=20=20=20else=0A--=20=0A= 2.30.1=20(Apple=20Git-130)=0A=0A= --Apple-Mail=_6ECEFF58-F1E0-4463-8F80-E5F3079393AA Content-Disposition: attachment; filename=fontset-test.el Content-Type: application/octet-stream; x-unix-mode=0644; name="fontset-test.el" Content-Transfer-Encoding: quoted-printable (progn=0A=20=20(create-fontset-from-fontset-spec=0A=20=20=20= (font-xlfd-name=0A=09(font-spec=20:family=20"Charter"=0A=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20:registry=20"fontset-serif")))=0A=0A=20=20= (set-fontset-font=20"fontset-serif"=20'han=0A=09=09=09=09=09(font-spec=20= :family=20"Source=20Han=20serif"))=0A=0A=20=20= (create-fontset-from-fontset-spec=0A=20=20=20(font-xlfd-name=0A=09= (font-spec=20:family=20"Helvetica"=0A=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20:registry=20"fontset-sans")))=0A=0A=20=20(set-fontset-font=20= "fontset-sans"=20'han=0A=09=09=09=09=09(font-spec=20:family=20"Source=20= Han=20Sans"))=0A=0A=20=20(create-fontset-from-fontset-spec=0A=20=20=20= (font-xlfd-name=0A=09(font-spec=20:family=20"Courier"=0A=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20:registry=20"fontset-mono")))=0A=0A=20=20= (set-fontset-font=20"fontset-mono"=20'han=0A=09=09=09=09=09(font-spec=20= :family=20"Source=20Han=20Sans"))=0A=20=20(insert=20"\n\nDefault=20= =E9=BB=98=E8=AE=A4\n")=0A=20=20(insert=20(propertize=20"Highlight=20= =E9=AB=98=E4=BA=AE"=20'font-lock-face=20'highlight)))=0A=0A(progn=0A=20=20= (set-face-font=20'default=20"fontset-mono")=0A=20=20(set-face-font=20= 'highlight=20"fontset-serif"))=0A=0A(progn=0A=20=20(set-face-font=20= 'default=20"fontset-serif")=0A=20=20(set-face-font=20'highlight=20= "fontset-sans"))=0A=0A(progn=0A=20=20(set-face-font=20'default=20= "fontset-sans")=0A=20=20(set-face-font=20'highlight=20"fontset-mono"))=0A= --Apple-Mail=_6ECEFF58-F1E0-4463-8F80-E5F3079393AA--