Mask color font in st’s source code so st does not crash when trying to display emoji
I first downloaded st and compiled its source code.
However, st crashed when trying to display emails that contained emoji in Mutt, or when running $ khal interactive
.
To fix this, I first tried to install libxft-bgra
, in vain. I documented this there: https://yctct.com/st-install-libxft-bgra.
Next, I considered removing the package fonts-noto-color-emoji
, but saw that it is tied to too many LaTeX packages. I did not want to touch that for now.
Then, finally, I went back to st’s FAQ and read this again:
## BadLength X error in Xft when trying to render emoji
Xft makes st crash when rendering color emojis with the following error:
"X Error of failed request: BadLength (poly request too large or internal Xlib length error)"
Major opcode of failed request: 139 (RENDER)
Minor opcode of failed request: 20 (RenderAddGlyphs)
Serial number of failed request: 1595
Current serial number in output stream: 1818"
This is a known bug in Xft (not st) which happens on some platforms and
combination of particular fonts and fontconfig settings.
See also:
https://gitlab.freedesktop.org/xorg/lib/libxft/issues/6
https://bugs.freedesktop.org/show_bug.cgi?id=107534
https://bugzilla.redhat.com/show_bug.cgi?id=1498269
The solution is to remove color emoji fonts or disable this in the fontconfig
XML configuration. As an ugly workaround (which may work only on newer
fontconfig versions (FC_COLOR)), the following code can be used to mask color
fonts:
FcPatternAddBool(fcpattern, FC_COLOR, FcFalse);
Please don't bother reporting this bug to st, but notify the upstream Xft
developers about fixing this bug.
As of 2022-09-05 this now seems to be finally fixed in libXft 2.3.5:
https://gitlab.freedesktop.org/xorg/lib/libxft/-/blob/libXft-2.3.5/NEWS
The bit that was useful to me is:
[...] or disable this in the fontconfig XML configuration. As an ugly
workaround (which may work only on newer fontconfig versions (FC_COLOR)), the
following code can be used to mask color fonts:
FcPatternAddBool(fcpattern, FC_COLOR, FcFalse);
So I went into ~/bin/st
, where I had extracted st’s source code, and grepped for FcPatternAddBool
$ grep FcPatternAddBool *
FAQ: FcPatternAddBool(fcpattern, FC_COLOR, FcFalse);
grep: st: binary file matches
x.c: FcPatternAddBool(fcpattern, FC_SCALABLE, 1);
grep: x.o: binary file matches
Which showed me that the pattern FcPatternAddBool
is in the file x.c
.
In x.c
I searched for FcPatternAddBool
again, and replaced:
FcPatternAddBool(fcpattern, FC_SCALABLE, 1);
by:
FcPatternAddBool(fcpattern, FC_COLOR, FcFalse);
which I copied from st’s FAQ.
Then, still in ~/bin/st
, I ran:
$ sudo make clean install
to build st again.
To test, I opened st then Mutt. Searched for emails I had received containing emojis, and browsed through a few of them.
st did not crash.
Now, instead of crashing (or trying to display an emoji) st shows a small square.
PS: at the time of writing, st’s FAQ stipulates that libXft is fixed in libXft 2.3.5; however my system shows that I don’t have that version yet. One option would have been to install 2.3.5 I suppose.
$ apt list libXft*
Listing... Done
libxft-dev/aramo,now 2.3.4-1 amd64 [installed]
libxft2/aramo,now 2.3.4-1 amd64 [installed,automatic]
personal computing command-line interface (cli) gnu linux trisquel shell literacy wiki st suckless