Subject: Re: bug#66416: 29.1; Crashes when visiting HELLO file with pgtk on Wayland

From: Eli Zaretskii <[email-masked]>
Date: Wed, 11 Oct 2023 14:31:20 +0300

> From: Yuchen Guo <[email-masked]>
> Cc: [email-masked]
> Date: Tue, 10 Oct 2023 16:26:55 +0000
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > Do the fonts that you want to use have such language tags?  If they
> > do, which language tags correspond to what language-environments in
> > Emacs?
> 
> How can I check this?  I tried `describe-font' on the font I wish to
> use, the output is the following

Try font-info instead, and look at the last, 13th, element of the
vector it returns.  The doc string of font-info describes what it can
tell you.

> > So if certain language tags should be required from Chinese fonts in
> > specific Chinese language-environments, we can express that in our
> > default fontset, so that the need for configuring fonts manually is
> > avoided in more cases.
> >
> > ...
> > See above: is it really impossible?
> 
> I'm now convinced that this is indeed possible.  Thanks for the
> detailed explanation, and apologies for not reading `(emacs)Language Environments'
> earlier.  But now I'm unsure whether this is a problem on the part of
> the font, or something that could be fixed in Emacs.

See above.

If the fonts you want to use indeed have the appropriate
language-system tags, then you can request those tags to be present
via set-fontest-font, by using the font-spec function to specify the
FONT-SPEC argument.  See the doc string of font-spec for how to
specify language-system tags.

> The selection of Free-as-in-Freedom CJK fonts is already too
> few, good ones even less, we could ill afford to lose more of them due
> to trivial configuration problems.

The beauty of using font-spec is that you don't have to name the fonts
or their family names, only specify their properties and features, and
Emacs will find the right font(s) automatically (or at least it
should).

> In the meantime, I'm using the following snippet for fallback.  I've
> removed all other configuration:
> 	
> 	(defun my-configure-font (frame)
> 	  "Configure font given initial non-daemon FRAME.
> 	Intended for `after-make-frame-functions'."
> 	  ;; 简体中文与标点。
> 	  (set-fontset-font t 'han (font-spec :family "Noto Serif CJK SC" :weight 'medium))
> 	  (set-fontset-font t 'cjk-misc (font-spec :family "Noto Serif CJK SC" :weight 'medium))
> 	  (remove-hook 'after-make-frame-functions #'my-configure-font))
> 	
> 	(add-hook 'after-make-frame-functions #'my-configure-font)
> 
> Does this make any sense?

Yes, I think so.