NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.62k stars 13.77k forks source link

DejaVu fonts take priority on Noto Color Emoji #172412

Open maxbrunet opened 2 years ago

maxbrunet commented 2 years ago

Describe the bug

The DejaVu fonts seem to contain emojis and take priority on Noto Color Emoji:

$ fc-match -s monospace
NotoSansMono-Regular.ttf: "Noto Sans Mono" "Regular"
DejaVuSans.ttf: "DejaVu Sans" "Book"
NotoSansArmenian-Regular.ttf: "Noto Sans Armenian" "Regular"
<-- TRUNCATED -->
NotoSerifTangut-Regular.ttf: "Noto Serif Tangut" "Regular"
Arimo-Regular.ttf: "Arimo" "Regular"
Tinos-Regular.ttf: "Tinos" "Regular"
NotoEmoji-Regular.ttf: "Noto Emoji" "Regular"
NotoSansTaiTham-Regular.ttf: "Noto Sans Tai Tham" "Regular"
<-- TRUNCATED -->
NotoSerifDogra-Regular.ttf: "Noto Serif Dogra" "Regular"
NotoSansAdlam-Bold.ttf: "Noto Sans Adlam" "Bold"
NotoColorEmoji.ttf: "Noto Color Emoji" "Regular"

I have removed the default fonts to try to work around it, but dejavu_fonts.minimal is still there as it seems to come with fontconfig:

https://github.com/NixOS/nixpkgs/blob/3c5ae9be1f18c790ea890ef8decbd0946c0b4c04/pkgs/development/libraries/fontconfig/default.nix#L61

Steps To Reproduce

  1. Example font config:
{
  fonts.fontconfig = {
    defaultFonts = {
      emoji = [ "Noto Color Emoji" ];
      monospace = [ "Noto Sans Mono" ];
      sansSerif = [ "Noto Sans" ];
      serif = [ "Noto Serif" ];
    };
  };
  fonts.enableDefaultFonts = false;
  fonts.fonts = with pkgs; [
    noto-fonts
    noto-fonts-emoji
  ];
}
  1. Get a family fonts list: fc-match -s monospace

Expected behavior

Only emojis from Noto Color Emoji should be displayed

Screenshots

image

Additional context

I noticed that while using Alacritty, the loaded fonts can be observed with verbosity (alacritty -vvv), for example launch it and paste an emoji into it:

[2022-05-10 16:08:33.970465199] [TRACE] [crossfont] Got font path="/nix/store/g0miv1zxd0cffl4vs3f1rikjwcmydsdg-dejavu-fonts-minimal-2.37/share/fonts/truetype/DejaVuSans.ttf", index=0
[2022-05-10 16:08:33.970589851] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Book, load_flags: NO_BITMAP | TARGET_LIGHT, render_mode: "Lcd", lcd_filter: 1 }

For now, I work around it by adding the emoji family to the other preferred font families:

{
  fonts.fontconfig = {
    defaultFonts = {
      emoji = [ "Noto Color Emoji" ];
      monospace = [
        "Noto Sans Mono"
        "emoji"
      ];
      sansSerif = [
        "Noto Sans"
        "emoji"
      ];
      serif = [
        "Noto Serif"
        "emoji"
      ];
    };
  };
}

Notify maintainers

Metadata

mightyiam commented 2 years ago

I can't seem to use alias and prefer to set a font to a higher priority for sans-serif over DejaVu.

jtojnar commented 2 years ago

Can you reproduce with pango-view --text="πŸ˜πŸ˜‡"? It might be an app-specific issue.

maxbrunet commented 2 years ago

For my part, I cannot reproduce with pango-view --text="πŸ˜πŸ˜‡" --font=monospace, but I cannot get it to display DejaVu with pango-view --text="πŸ˜πŸ˜‡" --font='DejaVu Sans' either, so it may not be a valid test.

I have seen emoji issues in Firefox too, it usually does not fallback to DejaVu tho, but something the website defines (e.g. emojipicker.com)

mightyiam commented 2 years ago

Here's why this is happening, it seems. These options set the defaults in fontconfig configuration in a way that is not trivial to override. I simply set them all to empty and made sure I have my own config.

mightyiam commented 1 year ago

This is a bug. Here's my workaround:

https://github.com/mightyiam/nixconfigs/blob/bf70574feba2483c401294b23cd1bd84a1c891c2/systems/desktop/default.nix#L22-L26

mingww64 commented 1 year ago

I rejected it using font-manager.

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
<!-- Generated by Font Manager. Do NOT edit this file. -->
<fontconfig>
  <selectfont>
    <rejectfont>
      <pattern>
        <patelt name="family">
          <string>DejaVu Sans</string>
        </patelt>
      </pattern>
    </rejectfont>
  </selectfont>
</fontconfig>