Skip to content

Instantly share code, notes, and snippets.

@IgnoredAmbience
Last active February 7, 2024 03:53
  • Star 83 You must be signed in to star a gist
  • Fork 20 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save IgnoredAmbience/7c99b6cf9a8b73c9312a71d1209d9bbb to your computer and use it in GitHub Desktop.
Noto Emoji Color fontconfig for Konsole
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!--
Noto Mono + Color Emoji Font Configuration.
Currently the only Terminal Emulator I'm aware that supports colour fonts is Konsole.
Usage:
0. Ensure that the Noto fonts are installed on your machine.
1. Install this file to ~/.config/fontconfig/conf.d/99-noto-mono-color-emoji.conf
2. Run `fc-cache`
3. Set Konsole to use "Noto Mono" as the font.
4. Restart Konsole.
-->
<fontconfig>
<match>
<test name="family"><string>Noto Mono</string></test>
<edit name="family" mode="prepend" binding="strong">
<string>Noto Color Emoji</string>
</edit>
</match>
</fontconfig>
@gysi
Copy link

gysi commented Feb 28, 2019

I love you, finally it works for me! 👍

@kmahyyg
Copy link

kmahyyg commented Mar 5, 2019

Worked fine for me, use font Noto Mono for Powerline, so I can use wttr.in now

@gsfordham
Copy link

Excellent! Saved me a lot of diggin', ya did!
I'm surprised this was needed, considering xterm didn't require anything special

@magiblot
Copy link

The following seems to work for any font:

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

    <match target="pattern">
        <test qual="any" name="family"><string>monospace</string></test>
        <edit name="family" mode="append" binding="weak"><string>Noto Color Emoji</string></edit>
    </match>
    <match target="pattern">
        <test qual="any" name="family"><string>serif</string></test>
        <edit name="family" mode="append" binding="strong"><string>Noto Color Emoji</string></edit>
    </match>
    <match target="pattern">
        <test qual="any" name="family"><string>sans-serif</string></test>
        <edit name="family" mode="append" binding="strong"><string>Noto Color Emoji</string></edit>
    </match>

</fontconfig>

I'm not sure about the difference between append and prepend, though.
Inspired by: https://github.com/AndydeCleyre/dotfiles/blob/master/.config/fontconfig/fonts.conf

@jospoortvliet
Copy link

The first one works, and an adjustment to noto-sans worked. I haven't tested the line from magiblot but I guess it'll work, too - this is really nice, took me forever to find out! Thanks a lot.

@rickysarraf
Copy link

THank you. Worked perfect.

@n4n0GH
Copy link

n4n0GH commented Oct 13, 2019

The following seems to work for any font:

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

    <match target="pattern">
        <test qual="any" name="family"><string>monospace</string></test>
        <edit name="family" mode="append" binding="weak"><string>Noto Color Emoji</string></edit>
    </match>
    <match target="pattern">
        <test qual="any" name="family"><string>serif</string></test>
        <edit name="family" mode="append" binding="strong"><string>Noto Color Emoji</string></edit>
    </match>
    <match target="pattern">
        <test qual="any" name="family"><string>sans-serif</string></test>
        <edit name="family" mode="append" binding="strong"><string>Noto Color Emoji</string></edit>
    </match>

</fontconfig>

I'm not sure about the difference between append and prepend, though.
Inspired by: https://github.com/AndydeCleyre/dotfiles/blob/master/.config/fontconfig/fonts.conf

If you use monospace as a general identifier, the fontconfig will also replace all monospace rendering in your webbrowser and elsewhere, potentially making <code> tags unreadable.

@magiblot
Copy link

If you use monospace as a general identifier, the fontconfig will also replace all monospace rendering in your webbrowser and elsewhere, potentially making <code> tags unreadable.

I was hoping Noto Color Emoji would be only used where the default font doesn't support a certain emoji. At least this is what seems to be happening for me:

Screenshot_20191013_223423

Notice how glyphs already available in the default font are preserved (which is the desired behaviour for monospace fonts, as emojis are 2 columns wide instead of 1). I wouldn't mind them being replaced in non-monospace font families, but I wasn't able to achieve this.

@n4n0GH
Copy link

n4n0GH commented Oct 14, 2019

I'm pretty sure you can achieve your desired result with minimal effort. Check out https://www.freedesktop.org/software/fontconfig/fontconfig-user.html to see what you can actually do with your fontconfigs.

@grubersjoe
Copy link

grubersjoe commented May 1, 2020

This works well for me (note the append_last).

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <match>
    <test name="family"><string>monospace</string></test>
    <edit name="family" mode="append_last" binding="strong">
      <string>Noto Color Emoji</string>
    </edit>
  </match>
</fontconfig>

@SuperSandro2000
Copy link

Everyone that lands here and wonders why there config is not working:

It is probably overwritten because you forgot to prepend a high priority like 99. You probably want to name the config something like 99-color-emoji.conf and place it under ~/.config/fontconfig/conf.d/99-color-emoji.conf

@vitorpedeo
Copy link

Thank you! I just switched Noto Sans for JetBrains Mono and it worked perfectly!

Copy link

ghost commented Aug 27, 2020

tried something similar that ended up breaking emacs, but using this config fixed it lol. thanks fam!

@yzhernand
Copy link

I think I got this to work on any monospace font without breaking code blocks. My fork is located here. The major change besides setting the font family to "Monospace" on line 17 as @magiblot did, is setting binding="weak" on line 18 (22 in my fork). I also set mode="append_last" as @grubersjoe did, but I'm not sure if its necessary (seems to work fine for me either with "append_last" or "prepend").

@rulrok
Copy link

rulrok commented Oct 25, 2020

I'm not sure what happened, but @magiblot has finally fixed an issue I had with KDE emoji picker. 🥳🥳🥳

image

@richard-swyftx-zz
Copy link

Perfect! thank you

@abcfy2
Copy link

abcfy2 commented Aug 6, 2021

But why some emojis cannot display?

image
image

@Geremia
Copy link

Geremia commented May 24, 2022

Using this 99-noto-mono-color-emoji.conf, not all my emojis are color in Konsole:
Screenshot_20220524_141210_trimmed

Also, setting the Konsole font to "Noto Mono" doesn't seem necessary. It was set to Hack in the above image.

@gunslingerfry
Copy link

gunslingerfry commented Oct 7, 2022

The reason why some of the emojis don't work for abcfy2 is because it's not handling the multi-code emojis (called grapheme clusters, or zwj sequence). For example LGBT flag 🏳️‍🌈: looks like this in konsole: 🏳<fe0f><200d>🌈
The empty flag + <fe0f> the 16th 'variation selector' character (indicating color, I believe) + <200d> is the zero width joiner + rainbow

How to fix it, I don't know.

@pabsan-0
Copy link

This distorted my terminal default font too, making it appear shorter and wider. Removing the binding="strong" from the original example worked for me.

As noted in some comment above, I also swapped the Noto Mono for my konsole's monospace.

Thanks a bunch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment