How to disable some font

I have a hand-written style Chinese font in my ~/.local/share/fonts. However, it override my system side Chinese font:

If I remove it, the Chinese font can recovery to normal:

However, I don’t want to remove it due to sometimes I need to use it. So I try to write ~/.config/fontconfig/fonts.conf.

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
<fontconfig>
  <dir prefix="xdg">fonts</dir>
  <match target="font">
    <test name="family" qual="any">
      <string>方正静蕾简体</string>
    </test>
    <edit name="priority" mode="assign">
      <priority>99</priority>
    </edit>
  </match>
</fontconfig>

I expect to decrease its priority to 99 to make system side Chinese font override it. However, nothing changed. What something wrong I did?

The following is the information of the hand-written style font:

$ exiftool 方正静蕾简体.ttf
ExifTool Version Number         : 12.62
File Name                       : 方正静蕾简体.ttf
File Size                       : 16 MB
File Modification Date/Time     : 2023:04:12 16:07:50+08:00
File Access Date/Time           : 2023:06:03 18:48:31+08:00
File Inode Change Date/Time     : 2023:06:03 19:27:43+08:00
File Permissions                : -rw-r--r--
File Type                       : TTF
File Type Extension             : ttf
MIME Type                       : application/x-font-ttf
Copyright                       : Copyright(c) Founder Corporation.2007
Font Family                     : FZJingLeiS-R-GB
Font Subfamily                  : Regular
Font Subfamily ID               : Founder:FZJingLeiS-R-GB.Regular
Font Name                       : FZJingLeiS-R-GB
Name Table Version              : 1.00
PostScript Font Name            : FZJLJW--GB1-0
Trademark                       : By Founder Corporation.
Copyright (en-US)               : Copyright(c) Founder Corporation.2007..Modified by Kelvin 2008-9-17
Font Family (en-US)             : FZJingLei
Font Subfamily (en-US)          : Regular
Font Subfamily ID (en-US)       : Founder:FZJingLei - Kelvin
Font Name (en-US)               : FZJingLei - Kelvin
Name Table Version (en-US)      : 1.00
Trademark (en-US)               : By Founder Corporation. 北大方正
Copyright (zh-CN)               : Copyright(c) Founder Corporation.2007..Modified by Kelvin 2008-9-17
Font Family (zh-CN)             : 方正静蕾简体
Font Subfamily (zh-CN)          : Regular
Font Subfamily ID (zh-CN)       : Founder:方正静蕾简体 - Kelvin
Font Name (zh-CN)               : 方正静蕾简体 - Kelvin
Name Table Version (zh-CN)      : 1.00
Trademark (zh-CN)               : By Founder Corporation. 北大方正

Have you cleared the font-cache in between?
fc-cache -r

Thanks, fc-cache -r give me some warning to let me know what something incorrect I write. The correct config referred https://wiki.archlinux.org/title/font_configuration#Whitelisting_and_blacklisting_fonts is:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
<fontconfig>
  <dir prefix="xdg">fonts</dir>
  <selectfont>
    <rejectfont>
      <pattern>
        <patelt name="family">
          <string>方正静蕾简体</string>
        </patelt>
      </pattern>
    </rejectfont>
  </selectfont>
</fontconfig>

If fontconfig’s XML have language server support like jsonschema, it will be easier to find any incorrect syntax for users :smile:

A related issue: https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/369

That’s what the DTD is for: fonts.dtd · main · fontconfig / fontconfig · GitLab

The following code provides XML language server for me. But the path is too ugly. Is there a better solution?

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "/nix/store/mj6c9ql3jvwlci2vd6smhx3b518jw1ni-fontconfig-2.14.2/share/xml/fontconfig/fonts.dtd">

You can use XML catalog to map the system ID (urn:fontconfig:fonts.dtd) to the schema path inside a package. For example, I have added one to dbus project. Or you can just create it locally in your Nix shell:

pkgs.mkShell {
  nativeBuildInputs = [
    pkgs.findXMLCatalogs

    (pkgs.writeTextFile {
      name = "fc-xml-catalog";
      text = ''
        <?xml version="1.0"?>
        <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
            <system systemId="urn:fontconfig:fonts.dtd" uri="${pkgs.fontconfig.out}/share/xml/fontconfig/fonts.dtd"/>
        </catalog>
      '';
      destination = "/share/xml/fontconfig/catalog.xml";
    })
  ];
}

Note that this requires your language server to support XML catalogs and XML_CATALOG_FILES environment variable (which will be set by findXMLCatalogs). If it is based on libxml2, it should support it out of the box.

OK, I’ll ask the upstream if can they add a catalog.xml.

https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/369