Solvedvoidrice Without proper default fonts, emojis crash st

On some systems, the terminal, st will crash when trying to render emojis and other unique unicode characters. This problem generally arises when users lack emoji fonts or a bad emoji font is default; at least, that seems to be the cause.

The font packages below are installed by LARBS to give pretty much full unicode overage. If you are having terminal crashes when you clone and run my dotfiles, you will want to install these. That will in most cases solve the problem:

ttf-linux-libertine # probably not actually needed, only aesthetic
ttf-inconsolata # the monospace font
ttf-emojione
ttf-symbola

You might also want to install noto-fonts; I don't think that's necessary, but I have it on my machine.

If the problem persists, you should probably explicitly state what fonts to use. Here is the LARBS fontconfig file, which with these fonts seems to avoid this crash.

I'm making this issue here because there are at least a half dozen other issues on my repos about this. I'm aware of the issue, but the original cause might be something out of my control or ken.

I suspect it has something to do with how st or one of its libraries handles fontconfig errors. If that problem persists, I might drop fontconfig usage by st and have it manually specify fonts.

26 Answers

✔️Accepted Answer

For anyone ending up here I found a very hacky solution to avoid crashes in st (LukeSmithxyz/st#37):

In the function xdrawglyphfontspecs (in x.c), change:

XftDrawGlyphFontSpec(xw.draw, fg, specs, len);

into:

FcBool b = FcFalse;
FcPatternGetBool(specs->font->pattern, FC_COLOR, 0, &b);
if (!b) {
    XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
}

The change prevents that any colorized glypth (character) to be rendered and will only fill a blank space. The other (discussed above) avoid the mapping of colorized glyphs.

I think this could be optimized, but I lack time to investigate this. Bit confused how the caching mechanism works in st.

Other Answers:

This post should serve as a summary for what has been discussed in LukeSmithxyz/LARBS#119 and via mail between @sarpik and me.

Introduction

The reason why st is crashing is that it tries to use an emoji font as fallback that provides colored emojis (which st cannot handle).

A "fallback" font is used when a specific glyph is requested that is not found within the font used by st.

The default font used by st is the default "monospace" font on the system OR the one set in .Xresources or .Xdefaults.
The latter will override whats being specified as the default monospace font in .config/fonts/fonts.conf.

LARBS installs ttf-symbola by default which is being used as the fallback font for emojis unless there is a different colored emoji font installed.
The exact order of the fallback fonts is not always clear.
However, for people experiencing st crashes this "order problem" of emoji fonts is (almost) always the reason.

Possible reasons for crashes

  • A font with colored emojis is specified as the st font in .Xresources
  • The first fallback font for emojis is a font with colored emoji support

Solutions

  • Choose a different monospace font in .Xresources
  • Delete all colorful emoji fonts AND their symlinks in /etc/fonts/conf.d and /etc/fonts/conf.d
  • double check if ttf-symbola is installed

How to still get colored emoji support without st crashing

This post shows how to set noto-fonts-emoji as the default fallback font for any kind of font family on the system.
If you follow this post, you will have colored emoji support.
Now to prevent st from crashing, you need to remove the part for the "monospace" family

<match target="pattern">
  <test name="family"><string>monospace</string></test>
  <edit name="family" mode="append"><string>Noto Color Emoji</string></edit>
</match>

and the block which blocks ttf-symbola as a possible fallback font

    <!-- Block Symbola from the list of fallback fonts. -->
    <selectfont>
        <rejectfont>
            <pattern>
                <patelt name="family">
                    <string>Symbola</string>
                </patelt>
            </pattern>
        </rejectfont>
    </selectfont>

and the part which specifies using noto-fonts-emoji over ttf-symbola

<match target="pattern">
  <test qual="any" name="family"><string>Symbola</string></test>
   <edit name="family" mode="assign" binding="same"><string>Noto Color Emoji</string></edit>
</match>

There may be different approaches of how to get colorful emojis without st crashes and with different emoji fonts. However, I am happy to finally have a working solution and I am not keen on changing anything of the setup in the near future.

I manage to make it work the emoji
first i install the colored emoji

yay  ttf-joypixels

then

sudo ln -sf /etc/fonts/conf.avail/75-joypixels.conf /etc/fonts/conf.d/

this will add a fallback to all emoji ....
install libxft-bgra , this will help prevent st from crashing

then i edit my st build
x.c

/* Render the glyphs. */
    XftDrawGlyphFontSpec(xw.draw, fg, specs, len);

i remove the conditionals for rendering the glyp to just render it

and i change my .config/font-config/fonts.conf

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>

 <alias>
    <family>serif</family>
    <prefer><family>Linux Libertine</family></prefer>
  </alias>
  <alias>
    <family>sans-serif</family>
    <prefer><family>Linux Biolinum</family></prefer>
  </alias>
  <alias>
    <family>sans</family>
    <prefer><family>Linux Biolinum</family></prefer>
  </alias>
  <alias>
    <family>monospace</family>
    <prefer><family>Inconsolata</family></prefer>
</alias>
</fontconfig>

then i edited dmenuunicode script , and change font to Monospace

Dmenu Shows None Colored Emoji while St , VSCODE allows you to see emojis

@LukeSmithxyz can u confirm this is the same process as you did?

The only problem im facing now is the initial dmenuunicode options shows no emoji
only after i start typing it will load the emojis...

Hope we can find better solution to this ....

for now i will revert back to the old config i have its better and faster even if no color emoji

I manage to make it work the emoji
first i install the colored emoji

yay  ttf-joypixels

then

sudo ln -sf /etc/fonts/conf.avail/75-joypixels.conf /etc/fonts/conf.d/

this will add a fallback to all emoji ....
install libxft-bgra , this will help prevent st from crashing

then i edit my st build
x.c

/* Render the glyphs. */
    XftDrawGlyphFontSpec(xw.draw, fg, specs, len);

i remove the conditionals for rendering the glyp to just render it

and i change my .config/font-config/fonts.conf

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>

 <alias>
    <family>serif</family>
    <prefer><family>Linux Libertine</family></prefer>
  </alias>
  <alias>
    <family>sans-serif</family>
    <prefer><family>Linux Biolinum</family></prefer>
  </alias>
  <alias>
    <family>sans</family>
    <prefer><family>Linux Biolinum</family></prefer>
  </alias>
  <alias>
    <family>monospace</family>
    <prefer><family>Inconsolata</family></prefer>
</alias>
</fontconfig>

then i edited dmenuunicode script , and change font to Monospace

Dmenu Shows None Colored Emoji while St , VSCODE allows you to see emojis

@LukeSmithxyz can u confirm this is the same process as you did?

The only problem im facing now is the initial dmenuunicode options shows no emoji
only after i start typing it will load the emojis...

Hope we can find better solution to this ....

for now i will revert back to the old config i have its better and faster even if no color emoji

thank you very much, yay -S libxft-bgra replace libxft solve this problem

@LukeSmithxyz you can close this one, a patch has been added for those who haven't fixed it yet