GNU bug report logs - #70993
set-fontset-font doesn't use specified font for some scripts

Previous Next

Package: emacs;

Reported by: Rodrigo Morales <me <at> rodrigomorales.site>

Date: Fri, 17 May 2024 03:32:02 UTC

Severity: normal

Tags: moreinfo

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Rodrigo Morales <me <at> rodrigomorales.site>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70993 <at> debbugs.gnu.org
Subject: bug#70993: set-fontset-font doesn't use specified font for some scripts
Date: Fri, 17 May 2024 09:57:47 -0500
Eli Zaretskii <eliz <at> gnu.org> writes:

> I think you need to evaluate those set-fontset-font expressions
> _before_ displaying any characters from the corresponding scripts
> (i.e., at the very beginning of the Emacs session), to get reliable
> results.

I tried setting the font for those scripts in an empty
~/.config/emacs/init.el but the hexadecimal code inside a box was not
shown.

I cleaned the file =~/.config/emacs/init.el= in my system and inserted
the following sexp:

#+HEADER: :tangle ~/.config/emacs/init.el
#+BEGIN_SRC elisp
(set-fontset-font t 'brahmi (font-spec :family "Cozette"))
(set-fontset-font t 'egyptian (font-spec :family "Cozette"))
(set-fontset-font t 'ethiopic (font-spec :family "Cozette"))
(set-fontset-font t 'tagbanwa (font-spec :family "Cozette"))
(set-fontset-font t 'han (font-spec :family "Cozette"))
#+END_SRC

I then launched =emacs= without the =-Q= flag so that
=~/.config/emacs/init.el= is read. Afterwards, I opened the file
=/tmp/a.txt= which contained the same content as in my first message in
this bug report.

#+HEADER: :tangle /tmp/a.txt
#+BEGIN_SRC text
The following lines were retrieved from the HELLO buffer which is
opened by calling view-hello-file in GNU Emacs 29.3.
Brahmi (๐‘€ฉ๐‘†๐‘€ญ๐‘€ธ๐‘€ณ๐‘†๐‘€ซ๐‘€ป)	๐‘€ฆ๐‘€ซ๐‘€ฒ๐‘†๐‘€ข๐‘‚
Egyptian Hieroglyphs (๐“‚‹๐“ค๐“ˆ–๐“†Ž๐“…“โ€Œ๐“๐“Š–)	๐“…“๐“Šต๐“๐“Šช, ๐“‡๐“‡‹๐“‚ป๐“˜๐“‡‹
Amharic (แŠ แˆ›แˆญแŠ›)	แˆ แˆ‹แˆ
Tagbanwa (แฆแชแฏ)	แซแฉแฌแฅ แฃแฎแงแฏ
Chinese (ไธญๆ–‡,ๆ™ฎ้€š่ฏ,ๆฑ‰่ฏญ)	ไฝ ๅฅฝ
#+END_SRC

The lines containing the scripts Brahmi and Egyptian Hieroglyphs showed
the hexadecimal code inside a box, while the lines containing the
scripts Amharic, Tagbanwa and Chinese didn't show the hexadecimal code
inside a box. Here's the font reported by what-cursor-position when
called with a prefix argument in each line:

Brahmi: no font available
Egyptian Hieroglyphs: no font available
Amharic: ftcrhb:-GOOG-Noto Sans Ethiopic-regular-normal-normal-*-12-*-*-*-*-0-iso10646-1 (#x2B)
Tagbanwa: ftcrhb:-GOOG-Noto Sans Tagbanwa-regular-normal-normal-*-12-*-*-*-*-0-iso10646-1 (#x12)
Chinese: ftcrhb:-GOOG-Noto Sans CJK KR-regular-normal-normal-*-12-*-*-*-*-0-iso10646-1 (#x2703)

> That's because some scripts require characters to be composed on
> display, and Emacs caches these compositions together with the font
> used to display those characters.  Changing the fontset after some
> character compositions were already cached will not change the font
> recorded in the cached compositions.
>
> IOW, set-fontset-font cannot be reliably used in the middle of an
> Emacs session.

This is a significant limitation for users that feel the need to
regularly change the font for a given script in the middle of an Emacs
session (e.g. users of the package
[[https://github.com/tumashu/cnfonts][cnfonts]], the package primarily
uses set-fontset-font for setting the font for the scripts 'kana, 'han,
'cjk-misc, 'bopomofo and 'hangul). As for me, I usually change the font
for the script 'han because I'm studying Asian languages and the glyphs
for a unique code point can be significantly different when using
different fonts, see more information in table "Same code point,
different language tags" in
https://en.wikipedia.org/wiki/Variant_Chinese_characters

I lack knowledge on how Emacs internals work to set the font for
specific scripts and how glyphs for each character are chosen so I don't
know how difficult this would be to implement but I believe that given
that Emacs is called an extensible and customizable text editor in
https://www.gnu.org/software/emacs/, set-fontset-font should have a
reliable and consistent behavior when it is run in the middle of an
Emacs session. Thus, giving users the freedom to change the font for any
script at any time reliably and making Emacs more customizable. Please
let me know your thoughts.




This bug report was last modified 82 days ago.

Previous Next


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