A fonts configuration file dedicated to a single program
Posted: 2024-07-31 Filed under: desktop, system | Tags: fonts, fonts.conf, viber 2 CommentsHow do you make a program use its own, customized fonts settings? Let’s say, I want to start Viber with fonts configuration that is different from what’s system-wide. The reason is that Viber seems to use an inbuilt font, for which my global hinting settings do not play nice. I also wanted to specify the Noto Emoji (Black and White) font to be used in Viber (my port includes it in the package). Here’s how it’s done. I’m on CRUX 3.7, but the strategy is the same for any Linux distribution.
I prepared a custom fonts settings file, that gets installed as /etc/fonts/viber.conf by my viber port. It has the following contents:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!--Custom fonts.conf file for Viber -->
<fontconfig>
<!-- Load fonts configuration -->
<include ignore_missing="yes">fonts.conf</include>
<!-- Reject the popular colour and B&W emojis, since they mix with Viber's inbuilt B&W ones. -->
<selectfont>
<rejectfont>
<!-- Colour -->
<pattern><patelt name="family" ><string>Noto Color Emoji</string></patelt></pattern>
<pattern><patelt name="family" ><string>Apple Color Emoji</string></patelt></pattern>
<pattern><patelt name="family" ><string>Segoe UI Emoji</string></patelt></pattern>
<pattern><patelt name="family" ><string>Twitter Color Emoji</string></patelt></pattern>
<pattern><patelt name="family" ><string>Emoji One</string></patelt></pattern>
<pattern><patelt name="family" ><string>Emoji Two</string></patelt></pattern>
<pattern><patelt name="family" ><string>JoyPixels</string></patelt></pattern>
<pattern><patelt name="family" ><string>EmojiOne Mozilla</string></patelt></pattern>
<pattern><patelt name="family" ><string>EmojiTwo Mozilla</string></patelt></pattern>
<pattern><patelt name="family" ><string>Twemoji Mozilla</string></patelt></pattern>
<!-- B&W -->
<pattern><patelt name="family" ><string>Symbola</string></patelt></pattern>
<pattern><patelt name="family" ><string>Android Emoji</string></patelt></pattern>
</rejectfont>
</selectfont>
<!-- We ship Noto Emoji, to complement Viber's for missing B&W emojis. -->
<dir>/usr/lib/viber/fonts</dir>
<alias binding="weak">
<family>monospace</family>
<prefer>
<family>Noto Emoji</family>
</prefer>
</alias>
<alias binding="weak">
<family>sans-serif</family>
<prefer>
<family>Noto Emoji</family>
</prefer>
</alias>
<alias binding="weak">
<family>serif</family>
<prefer>
<family>Noto Emoji</family>
</prefer>
</alias>
<!-- Font in Viber looks better when autohinted. -->
<match target="pattern">
<test qual="any" name="family"><string>sans-serif</string></test>
<edit name="autohint" mode="assign"><bool>false</bool></edit>
</match>
<match target="pattern">
<test qual="any" name="family"><string>serif</string></test>
<edit name="autohint" mode="assign"><bool>false</bool></edit>
</match>
<match target="pattern">
<test qual="any" name="family"><string>monospace</string></test>
<edit name="autohint" mode="assign"><bool>false</bool></edit>
</match>
</fontconfig>
To make Viber use it, you can either do it from its menu shortcut, like this:
[Desktop Entry] Name=Viber Comment=Viber VoIP and messenger Exec=env FONTCONFIG_FILE=/etc/fonts/viber.conf /usr/bin/viber %u Icon=viber Terminal=false Type=Application Categories=Network;InstantMessaging;P2P;
…or, set it up in a wrapper. My port installs the program (recently I moved to using the AppImage, works flawlessly) in /usr/lib/viber (in CRUX, packages should not put stuff in /opt) and uses a wrapper in /usr/bin:
#!/bin/sh export FONTCONFIG_FILE=/etc/fonts/viber.conf /usr/lib/viber/viber.AppImage
That’s it!

On Debian 12 and Viber 24.9 works fine. Thanks
Good to know. My reasons are just the emojis, but I noticed people report issues with fonts recently, so glad it works for that too.