Skip to content

Instantly share code, notes, and snippets.

@njmyers
Last active December 17, 2022 05:50
Show Gist options
  • Save njmyers/22b28cf8c3ed12639adb01ec142e267d to your computer and use it in GitHub Desktop.
Save njmyers/22b28cf8c3ed12639adb01ec142e267d to your computer and use it in GitHub Desktop.
Use apple fonts as defaults for fontconfig users
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!-- pixel alignment rgba -->
<!-- check it here http://www.lagom.nl/lcd-test/subpixel.php -->
<match target="font">
<edit name="rgba" mode="assign">
<const>rgb</const>
</edit>
</match>
<!-- end pixel alignment -->
<!-- lcd filter specification -->
<match target="font">
<edit name="lcdfilter" mode="assign">
<const>lcddefault</const>
</edit>
</match>
<!-- end lcd filter specification -->
<!-- disable auto hinting for bold fonts -->
<match target="font">
<test name="weight" compare="more">
<const>medium</const>
</test>
<edit name="autohint" mode="assign">
<bool>false</bool>
</edit>
</match>
<!-- end disable auto hinting for bold fonts -->
<!-- Map common aliases to case insensitive system aliases -->
<match target="pattern">
<test qual="any" name="family" compare="contains">
<string>mono</string>
</test>
<edit name="family" mode="assign">
<string>monospace</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family" compare="contains">
<string>Mono</string>
</test>
<edit name="family" mode="assign">
<string>monospace</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family" compare="contains">
<string>Monospace</string>
</test>
<edit name="family" mode="assign">
<string>monospace</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family" compare="eq">
<string>Serif</string>
</test>
<edit name="family" mode="assign">
<string>serif</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family" compare="eq">
<string>Sans</string>
</test>
<edit name="family" mode="assign">
<string>sans-serif</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family" compare="eq">
<string>Sans Serif</string>
</test>
<edit name="family" mode="assign">
<string>sans-serif</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family" compare="eq">
<string>Sans-Serif</string>
</test>
<edit name="family" mode="assign">
<string>sans-serif</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family" compare="eq">
<string>Sans-serif</string>
</test>
<edit name="family" mode="assign">
<string>sans-serif</string>
</edit>
</match>
<!-- Well known fonts are given 'sans-serif' -->
<match target="pattern">
<test qual="any" name="family" compare="eq">
<string>Helvetica</string>
</test>
<edit name="family" mode="assign_replace">
<string>sans-serif</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family" compare="eq">
<string>Arial</string>
</test>
<edit name="family" mode="assign_replace">
<string>sans-serif</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family" compare="eq">
<string>Monaco</string>
</test>
<edit name="family" mode="assign_replace">
<string>monospace</string>
</edit>
</match>
<!-- Load per-user customization file, but don't complain if it doesn't exist -->
<include ignore_missing="yes" prefix="xdg">fontconfig/fonts.conf</include>
<!-- Load local customization files, but don't complain if there aren't any -->
<include ignore_missing="yes">conf.d</include>
<include ignore_missing="yes">local.conf</include>
<!-- Map apple system aliases to "sans-serif" for web "system font" stack -->
<match target="pattern">
<test qual="any" name="family" compare="eq">
<string>-apple-system</string>
</test>
<edit name="family" mode="assign">
<string>sans-serif</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family" compare="eq">
<string>BlinkMacSystemFont</string>
</test>
<edit name="family" mode="assign">
<string>sans-serif</string>
</edit>
</match>
<!-- Prefer emoji font for all system aliases -->
<alias>
<family>monospace</family>
<prefer>
<family>emoji</family>
</prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer>
<family>emoji</family>
</prefer>
</alias>
<alias>
<family>serif</family>
<prefer>
<family>emoji</family>
</prefer>
</alias>
<!-- THIS IS WHERE YOU DEFINE FONTS -->
<match target="pattern">
<test qual="any" name="family">
<string>emoji</string>
</test>
<edit name="family" mode="prepend_first" binding="same">
<string>Noto Color Emoji</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family">
<string>sans-serif</string>
</test>
<edit name="family" mode="prepend_first" binding="same">
<string>SF Pro Text</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family">
<string>sans-serif</string>
</test>
<test qual="any" name="size" compare="more">
<double>19</double>
</test>
<edit name="family" mode="prepend_first" binding="same">
<string>SF Pro Display</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family">
<string>serif</string>
</test>
<edit name="family" mode="prepend_first" binding="same">
<string>Nimbus Roman Regular</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family">
<string>monospace</string>
</test>
<edit name="family" mode="prepend_first" binding="same">
<string>SF Mono Powerline</string>
</edit>
</match>
</fontconfig>
@Kikobeats
Copy link

Hey @njmyers thanks for this, very helpful!

Just I don't understand Prefer emoji font for all system aliases section is necessary 🤔

@Puxirepublic
Copy link

The rule of "SF Pro Text size >19 to SF Pro Display" doesn't work at all.

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