Wrestling with set-fontset-font

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Wrestling with set-fontset-font

Kévin Le Gouguec
Hello,

I would like to setup Emacs to look at Noto Color Emoji first, then at
Symbola, for characters belonging to the "symbol" script.  For a while I
thought this bit of configuration worked:



Then I realized that for some reason, one specific character (⚙ U+2699
GEAR) remains stubbornly displayed with DejaVu Sans Mono.

I think the problem may stem from fontset-startup, but even after
reading everything the manual has to say about fontsets I still feel a
bit out of my depth.  From emacs -Q, after running:



- the GEAR character is still displayed with DejaVu Sans Mono; C-u C-x =
  says:

>               display: by this font (glyph code)
>     ftcrhb:-PfEd-DejaVu Sans Mono-normal-normal-normal-*-15-*-*-*-m-0-iso10646-1 (#xAE4)

- yet for both fontset-default and fontset-startup, M-x describe-fontset
  says:

> ⚙ (#x2699)
>    -*-Noto Color Emoji-*-*-*-*-*-*-*-*-*-*-*-*

- GEAR characters displayed with an italic face (e.g. with
 (insert (propertize "\n⚙\n" 'font-lock-face 'italic))
 ) are correctly shown with Noto Color Emoji.


So far I've only had this problem with ⚙ U+2699 GEAR, though I suspect
that any character covered by DejaVu Sans Mono would show similar
symptoms.  If instead, I run (set-fontset-font t ?🤷 "Noto Color Emoji")
(i.e. using U+1F937 SHRUG) from emacs -Q, then

- before running set-fontset-font, the character is displayed with
  Symbola; C-u C-x = says

>               display: by this font (glyph code)
>     ftcrhb:-UFAS-Symbola-normal-normal-semicondensed-*-15-*-*-*-*-0-iso10646-1 (#x2630)

- after running set-fonset-font, the character is displayed with Noto
  Color Emoji; C-u C-x = says

>               display: by this font (glyph code)
>     ftcrhb:-GOOG-Noto Color Emoji-normal-normal-normal-*-15-*-*-*-m-0-iso10646-1 (#x9EB)

- and M-x describe-fontset fontset-default says

> 🤷 (#x1F937)
>     -*-Noto Color Emoji-*-*-*-*-*-*-*-*-*-*-*-*
> [-GOOG-Noto Color Emoji-normal-normal-normal-*-15-*-*-*-m-0-iso10646-1]

  (Note the third line; if I understand describe-fontset's output
  correctly, this means that no font was opened for U+2699 GEAR?)


At this point, I don't know whether I am misunderstanding something
fundamental about fontsets, or if I am facing a bug.  I'm pretty sure
it's the former.  I don't know what else I should be looking at though…

If anyone has pointers to documentation I might have missed, that would
be greatly appreciated.

Cheers!


(I'm not subscribed to the list; thanks for keeping me CC'ed!)

attachment0 (155 bytes) Download Attachment
attachment1 (120 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Wrestling with set-fontset-font

Eli Zaretskii
> From: Kévin Le Gouguec <[hidden email]>
> Date: Mon, 23 Dec 2019 19:15:25 +0100
>
> I would like to setup Emacs to look at Noto Color Emoji first, then at
> Symbola, for characters belonging to the "symbol" script.  For a while I
> thought this bit of configuration worked:
>
> (set-fontset-font t 'symbol "Symbola" nil 'prepend)
> (when (>= emacs-major-version 27)
>   (set-fontset-font t 'symbol "Noto Color Emoji" nil 'prepend))
>
> Then I realized that for some reason, one specific character (⚙ U+2699
> GEAR) remains stubbornly displayed with DejaVu Sans Mono.

Emacs by default prefers using the default font for displaying symbol
and punctuation characters, if that font supports them.  Set
use-default-font-for-symbols to nil to force Emacs always select the
font according to your fontsets, when it needs to display such
characters, even if the default font can display them.

Reply | Threaded
Open this post in threaded view
|

use-default-font-for-symbols vs. emojis (was: Wrestling with set-fontset-font)

Kévin Le Gouguec
In reply to this post by Kévin Le Gouguec
> From: Eli Zaretskii <[hidden email]>
> Emacs by default prefers using the default font for displaying symbol
> and punctuation characters, if that font supports them.  Set
> use-default-font-for-symbols to nil to force Emacs always select the
> font according to your fontsets, when it needs to display such
> characters, even if the default font can display them.

Thank you!  (Note to self: when Info and Custom fail, there's always C-h
v *keyword TAB…)

*skims comment in fontset.c:face_for_char*

How interesting!

>          However, these considerations are unlikely to be relevant to
>          punctuation and other symbols, since the latter generally
>          aren't specific to any culture, and don't require
>          sophisticated OTF features.  */

Do emojis challenge this heuristic, since

- they can typically use "sophisticated OTF features" such as color,
- combining sequences[1] are a thing?

If so, could/should there be a way to distinguish "emoji" characters
from the more general "symbol" script, using e.g. data from
<https://unicode.org/Public/emoji/12.1/>?

(I hope at least /some/ of the above makes sense.  My knowledge of
Fonts, the Unicode and Everything is anecdotal at best…)


PS: Sorry for not replying to your message Eli; I'm not subscribed to
    help-gnu-emacs, and I can't find an NNTP feed for it…


[1] E.g. 🧟‍♂️, 🧟‍♀️, 🐕‍🦺, 🏴‍☠️, from
    <https://unicode.org/Public/emoji/12.1/emoji-zwj-sequences.txt>, or
    flag sequences from
    <https://unicode.org/Public/emoji/12.1/emoji-sequences.txt>; none of
    which work inside Emacs yet AFAICT.

    To be more precise: as of commit 9ee5af31, these examples appear
    "decombined".  I have no idea what controls this (Harfbuzz? Cairo?)…

    FWIW, on Debian Buster, these combinations work for some of XFCE's
    applications (e.g. Thunar, Mousepad) but not others (e.g. Terminal).
    (Well, some of these combinations anyway.  No application seems to
    give the faithful U+1F415 U+200D U+1F9BA the love it deserves…)

Reply | Threaded
Open this post in threaded view
|

Re: use-default-font-for-symbols vs. emojis (was: Wrestling with set-fontset-font)

Eli Zaretskii
> From: Kévin Le Gouguec <[hidden email]>
> Date: Fri, 27 Dec 2019 19:52:49 +0100
>
> >          However, these considerations are unlikely to be relevant to
> >          punctuation and other symbols, since the latter generally
> >          aren't specific to any culture, and don't require
> >          sophisticated OTF features.  */
>
> Do emojis challenge this heuristic, since
>
> - they can typically use "sophisticated OTF features" such as color,
> - combining sequences[1] are a thing?

We don't yet support these features, so they are largely irrelevant
for Emacs at this point.  And (sadly) I don't see anyone around who
knows enough and has enough motivation and energy to teach Emacs to
support that.

> If so, could/should there be a way to distinguish "emoji" characters
> from the more general "symbol" script, using e.g. data from
> <https://unicode.org/Public/emoji/12.1/>?

If and when we need that, it will be almost trivial.  What's
non-trivial is to add support for color emoji.

> [1] E.g. 🧟‍♂️, 🧟‍♀️, 🐕‍🦺, 🏴‍☠️, from
>     <https://unicode.org/Public/emoji/12.1/emoji-zwj-sequences.txt>, or
>     flag sequences from
>     <https://unicode.org/Public/emoji/12.1/emoji-sequences.txt>; none of
>     which work inside Emacs yet AFAICT.
>
>     To be more precise: as of commit 9ee5af31, these examples appear
>     "decombined".  I have no idea what controls this (Harfbuzz? Cairo?)…

Could be a simple matter of defining more entries in
composition-function table to support these sequences (assuming the
font supports them).

Reply | Threaded
Open this post in threaded view
|

Re: use-default-font-for-symbols vs. emojis

Eli Zaretskii
> Date: Fri, 27 Dec 2019 22:20:57 +0200
> From: Eli Zaretskii <[hidden email]>
>
> > If so, could/should there be a way to distinguish "emoji" characters
> > from the more general "symbol" script, using e.g. data from
> > <https://unicode.org/Public/emoji/12.1/>?
>
> If and when we need that, it will be almost trivial.  What's
> non-trivial is to add support for color emoji.

Btw, the original problem was not with emoji, it was with U+2699, for
which I see no reason to use a font different from the default, except
in exceptional cases (for which you have that variable).  Emoji are
usually displayed by specialized fonts anyway, because fonts we use
for the default face are unlikely to cover emoji.

Reply | Threaded
Open this post in threaded view
|

Re: use-default-font-for-symbols vs. emojis

Kévin Le Gouguec
Eli Zaretskii <[hidden email]> writes:

> Btw, the original problem was not with emoji,

Right, I admit I changed the topic (though I took care to M-x
message-change-subject first :).

>                                               it was with U+2699, for
> which I see no reason to use a font different from the default, except
> in exceptional cases (for which you have that variable).

In my case, the reason is as trivial as "it wooks pwetty".

I do acknowledge that using e.g. Noto Color Emoji comes with a few
disadvantages though (characters have variable widths; their foreground
color cannot be set…); I plan on using color emoji mainly as mode line
lighters.

>                                                           Emoji are
> usually displayed by specialized fonts anyway, because fonts we use
> for the default face are unlikely to cover emoji.

Mmm… if I'm reading these Unicode documents right,

- the font used for the default face likely covers a few "emoji"[1]
  (e.g. I use DejaVu Sans Mono, which has U+2699 ⚙ and U+26A0 ⚠),

- although some (most?) of those will have their Emoji_Presentation
  property set to "No"[2], so it makes sense to display them with the
  default font.

[1] https://unicode.org/Public/emoji/12.1/emoji-data.txt
[2] http://www.unicode.org/reports/tr51/#Emoji_Presentation


Reply | Threaded
Open this post in threaded view
|

Re: use-default-font-for-symbols vs. emojis

Eli Zaretskii
> From: Kévin Le Gouguec <[hidden email]>
> Date: Sat, 28 Dec 2019 00:40:00 +0100
>
> >                                               it was with U+2699, for
> > which I see no reason to use a font different from the default, except
> > in exceptional cases (for which you have that variable).
>
> In my case, the reason is as trivial as "it wooks pwetty".

Then there's an alternative: change your default font.

> I do acknowledge that using e.g. Noto Color Emoji comes with a few
> disadvantages though (characters have variable widths; their foreground
> color cannot be set…)

That's exactly one of the reasons why Emacs by default prefers the
default font, which is fixed-pitch and its size matches the rest of
the text.

Reply | Threaded
Open this post in threaded view
|

Re: use-default-font-for-symbols vs. emojis

Kévin Le Gouguec
Eli Zaretskii <[hidden email]> writes:

>> From: Kévin Le Gouguec <[hidden email]>
>> Date: Sat, 28 Dec 2019 00:40:00 +0100
>>
>> >                                               it was with U+2699, for
>> > which I see no reason to use a font different from the default, except
>> > in exceptional cases (for which you have that variable).
>>
>> In my case, the reason is as trivial as "it wooks pwetty".
>
> Then there's an alternative: change your default font.
Mmm… if you mean "use Noto Color Emoji as the font family for the
default face", the results are… somewhat less "pwetty".  Also quite
unusable.



(DejaVu Sans Mono on the left; Noto Color Emoji on the right.)

Apologies if you meant something else…

Anyway, I'm happy with the following:



(I'll stop prepending Symbola to fontset-default since fontset.el
already includes it.)

noto-color-emoji-as-default-font.png (105K) Download Attachment
attachment1 (145 bytes) Download Attachment