From b49106c0266ffa12994686e45366c586e2be45f6 Mon Sep 17 00:00:00 2001
From: Aaron LI <aaronly.me@outlook.com>
Date: Tue, 6 Dec 2016 01:59:04 +0800
Subject: fontconfig: Rewrite user-wide font configurations

This user font configuration file should be placed at:
~/.config/fontconfig/fonts.conf
(original `~/.fonts.conf' is deprecated)
and the user fonts should locate at:
~/.local/share/fonts
(original `~/.fonts' will be deprecated)

NOTE:
The "LC_CTYPE" environment variable should be remove, because it
affects the behaviors of FontConfig!
With "LC_CTYPE=zh_CN.UTF-8", a Chinese font (or a font with Chinese
language support) is always preprended to the generic font families
(i.e., serif, sans-serif, monospace), which overrides the
<alias><prefer> configurations.
It is also tested that Fcitx works OK without "LC_CTYPE=zh_CN.UTF-8"
---
 _config/fontconfig/fonts.conf | 397 +++++++++++++++---------------------------
 1 file changed, 139 insertions(+), 258 deletions(-)

(limited to '_config')

diff --git a/_config/fontconfig/fonts.conf b/_config/fontconfig/fonts.conf
index 543c78a..cf08c22 100644
--- a/_config/fontconfig/fonts.conf
+++ b/_config/fontconfig/fonts.conf
@@ -1,272 +1,153 @@
 <?xml version="1.0"?>
 <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 <fontconfig>
-    <!--
-         Weitian LI <liweitianux@gmail.com>
-         2014/04/06
-    -->
 
-    <!--
-         system wide: /etc/fonts/local.conf
-         per-user configuration: $XDG_CONFIG_HOME/fontconfig/fonts.conf
-                                 (~/.config/fontconfig/fonts.conf)
-    -->
+  <!--
+      Custom font configurations
 
-    <!-- private font directory -->
-    <dir prefix="xdg">fonts</dir>
+      System-wide location:
+          /etc/fonts/local.conf
+      User-wide:
+          $XDG_CONFIG_HOME/fontconfig/fonts.conf
+          (default: ~/.config/fontconfig/fonts.conf)
 
-    <!-- default settings: smoothed and hinted -->
-    <match target="font" >
-        <edit name="autohint" mode="assign">
-            <bool>true</bool>
-        </edit>
-        <edit name="antialias" mode="assign">
-            <bool>true</bool>
-        </edit>
-        <edit name="hinting" mode="assign">
-            <bool>true</bool>
-        </edit>
-        <edit name="hintstyle" mode="assign">
-            <const>hintmedium</const>
-        </edit>
-        <edit name="lcdfilter" mode="assign">
-            <const>lcddefault</const>
-        </edit>
-        <edit name="rgba" mode="assign">
-            <const>rgb</const>
-        </edit>
-        <!-- enable embedded bitmap -->
-        <edit name="embeddedbitmap" mode="assign">
-            <bool>true</bool>
-        </edit>
-    </match>
+      References:
+      [1] https://freedesktop.org/software/fontconfig/fontconfig-user.html
+      [2] https://wiki.archlinux.org/index.php/font_configuration
+      [3] https://wiki.gentoo.org/wiki/Fontconfig
+      [4] https://eev.ee/blog/2015/05/20/i-stared-into-the-fontconfig-and-the-fontconfig-stared-back-at-me/
 
-    <!-- DPI -->
-    <!--
-    <match target="pattern">
-        <edit name="dpi" mode="assign">
-            <double>96</double>
-        </edit>
-    </match>
-    -->
 
-    <!-- For point size less equal than 6: only smoothed -->
-    <!--
-    <match target="font" >
-        <test name="size" compare="less_eq">
-            <double>6</double>
-        </test>
-        <edit name="antialias" mode="assign">
-            <bool>true</bool>
-        </edit>
-        <edit name="autohint" mode="assign">
-            <bool>false</bool>
-        </edit>
-        <edit name="hinting" mode="assign">
-            <bool>false</bool>
-        </edit>
-    </match>
-    -->
+      Aaron LI
+      Created: 2014-04-06
+      Updated: 2016-12-05
+  -->
 
-    <!-- font families -->
-    <!--
-        Names not including any well known alias are given 'sans-serif'
-    -->
-    <match target="pattern">
-        <test qual="all" name="family" compare="not_eq">
-            <string>sans-serif</string>
-        </test>
-        <test qual="all" name="family" compare="not_eq">
-            <string>serif</string>
-        </test>
-        <test qual="all" name="family" compare="not_eq">
-            <string>monospace</string>
-        </test>
-        <edit name="family" mode="append_last">
-            <string>sans-serif</string>
-        </edit>
-    </match>
+  <!-- General setting -->
+  <match target="font">
+    <!-- Enable anti-alias -->
+    <edit mode="assign" name="antialias">
+      <bool>true</bool>
+    </edit>
+    <!-- Enable hinting -->
+    <edit mode="assign" name="autohint">
+      <bool>true</bool>
+    </edit>
+    <edit mode="assign" name="hinting">
+      <bool>true</bool>
+    </edit>
+    <!-- Enable embedded bitmap -->
+    <edit mode="assign" name="embeddedbitmap">
+      <bool>true</bool>
+    </edit>
+  </match>
 
-    <!--
-        Alias well known font names to available TrueType fonts.
-        These substitute TrueType faces for similar Type1
-        faces to improve screen appearance.
-    -->
-    <alias>
-        <family>Times</family>
-        <prefer>
-            <family>Times New Roman</family>
-        </prefer>
-        <default>
-            <family>serif</family>
-        </default>
-    </alias>
-    <alias>
-        <family>Helvetica</family>
-        <prefer>
-            <family>Arial</family>
-        </prefer>
-        <default>
-            <family>sans-serif</family>
-        </default>
-    </alias>
-    <alias>
-        <family>Courier</family>
-        <prefer>
-            <family>Courier New</family>
-        </prefer>
-        <default>
-            <family>monospace</family>
-        </default>
-    </alias>
+  <!--
+      Set correct common families for custom "serif" and "monospace" fonts,
+      otherwise fontconfig assumes any /unrecognized/ font is "sans-serif",
+      thus cause *wrong fallback* fonts being found.
+  -->
+  <!-- "serif" faces -->
+  <alias>
+    <family>Source Serif Pro</family>
+    <default><family>serif</family></default>
+  </alias>
+  <alias>
+    <family>Noto Serif</family>
+    <default><family>serif</family></default>
+  </alias>
+  <!-- "monospace" faces -->
+  <alias>
+    <family>Source Code Pro</family>
+    <default><family>monospace</family></default>
+  </alias>
+  <alias>
+    <family>Fira Code</family>
+    <default><family>monospace</family></default>
+  </alias>
+  <alias>
+    <family>Noto Mono</family>
+    <default><family>monospace</family></default>
+  </alias>
 
-    <!--
-        The example of the requirements of OR operator;
-        If the 'family' contains 'Courier New' OR 'Courier'
-        add 'monospace' as the alternative
-    -->
-    <match target="pattern">
-        <test name="family" compare="eq">
-            <string>Courier New</string>
-        </test>
-        <edit name="family" mode="prepend">
-            <string>monospace</string>
-        </edit>
-    </match>
-    <match target="pattern">
-        <test name="family" compare="eq">
-            <string>Courier</string>
-        </test>
-        <edit name="family" mode="prepend">
-            <string>monospace</string>
-        </edit>
-    </match>
+  <!--
+      By default, fontconfig assumes any unrecognized font is "sans-serif",
+      so the above custom fonts now have *both* families.  Fix this.
+  -->
+  <match>
+    <test compare="eq" name="family">
+      <string>sans-serif</string>
+    </test>
+    <test compare="eq" name="family">
+      <string>serif</string>
+    </test>
+    <!-- The "delete" applies to the *first* match -->
+    <edit mode="delete" name="family"/>
+  </match>
+  <match>
+    <test compare="eq" name="family">
+      <string>sans-serif</string>
+    </test>
+    <test compare="eq" name="family">
+      <string>monospace</string>
+    </test>
+    <edit mode="delete" name="family"/>
+  </match>
 
-    <!-- use WenQuanYi font when serif is requested for Chinese -->
-    <match>
-        <!--
-            If you don't want to use WenQuanYi Zen Hei font for zh-tw etc,
-            you can use zh-cn instead of zh.
-            Please note, even if you set zh-cn, it still matches zh.
-            if you don't like it, you can use compare="eq"
-            instead of compare="contains".
-        -->
-        <test name="lang" compare="contains">
-            <string>zh</string>
-        </test>
-        <test name="family">
-            <string>serif</string>
-        </test>
-        <edit name="family" mode="prepend">
-            <string>WenQuanYi Micro Hei</string>
-            <string>WenQuanYi Zen Hei</string>
-        </edit>
-    </match>
-
-    <!-- font family preferences -->
-    <match>
-        <test name="family">
-            <string>serif</string>
-        </test>
-        <edit name="family" mode="prepend">
-            <string>DejaVu Serif</string>
-            <string>Liberation Serif</string>
-            <string>Linux Libertine</string>
-            <string>Linux Libertine O</string>
-            <string>Bitstream Vera Serif</string>
-            <string>Droid Serif</string>
-            <string>AR PL UMing CN</string>
-            <string>AR PL UMing TW</string>
-            <string>AR PL UMing HK</string>
-            <string>AR PL SungtiL GB</string>
-        </edit>
-    </match>
-    <match>
-        <test name="family">
-            <string>sans-serif</string>
-        </test>
-        <edit name="family" mode="prepend">
-            <string>DejaVu Sans</string>
-            <string>Liberation Sans</string>
-            <string>Linux Biolinum</string>
-            <string>Linux Biolinum O</string>
-            <string>Source Sans Pro</string>
-            <string>Droid Sans</string>
-            <string>WenQuanYi Micro Hei</string>
-            <string>WenQuanYi Zen Hei</string>
-            <string>Droid Sans Fallback</string>
-            <string>AR PL UKai CN</string>
-            <string>AR PL UKai TW</string>
-            <string>AR PL UKai HK</string>
-            <string>AR PL KaitiM GB</string>
-            <string>AR PL KaitiM Big5</string>
-        </edit>
-    </match>
-    <match>
-        <test name="family">
-            <string>monospace</string>
-        </test>
-        <edit name="family" mode="prepend">
-            <string>DejaVu Sans Mono</string>
-            <string>Liberation Mono</string>
-            <string>Source Code Pro</string>
-            <string>Inconsolata</string>
-            <string>Bitstream Vera Sans Mono</string>
-            <string>Droid Sans Mono</string>
-            <string>WenQuanYi Micro Hei Mono</string>
-            <string>WenQuanYi Zen Hei Mono</string>
-        </edit>
-    </match>
-
-    <!-- reorder the serif, sans-serif and monospace family -->
-    <alias>
-        <family>serif</family>
-        <prefer>
-            <family>DejaVu Serif</family>
-            <family>Liberation Serif</family>
-            <family>Linux Libertine</family>
-            <family>Linux Libertine O</family>
-            <family>Bitstream Vera Serif</family>
-            <family>Droid Serif</family>
-            <family>AR PL UMing CN</family>
-            <family>AR PL UMing TW</family>
-            <family>AR PL UMing HK</family>
-            <family>AR PL SungtiL GB</family>
-        </prefer>
-    </alias>
-    <alias>
-        <family>sans-serif</family>
-        <prefer>
-            <family>DejaVu Sans</family>
-            <family>Liberation Sans</family>
-            <family>Linux Biolinum</family>
-            <family>Linux Biolinum O</family>
-            <family>Source Sans Pro</family>
-            <family>Bitstream Vera Sans</family>
-            <family>Droid Sans</family>
-            <family>WenQuanYi Micro Hei</family>
-            <family>WenQuanYi Zen Hei</family>
-            <family>Droid Sans Fallback</family>
-            <family>AR PL UKai CN</family>
-            <family>AR PL UKai TW</family>
-            <family>AR PL UKai HK</family>
-            <family>AR PL KaitiM GB</family>
-            <family>AR PL KaitiM Big5</family>
-        </prefer>
-    </alias>
-    <alias>
-        <family>monospace</family>
-        <prefer>
-            <family>DejaVu Sans Mono</family>
-            <family>Liberation Mono</family>
-            <family>Source Code Pro</family>
-            <family>Inconsolata</family>
-            <family>Bitstream Vera Sans Mono</family>
-            <family>Droid Sans Mono</family>
-            <family>WenQuanYi Micro Hei Mono</family>
-            <family>WenQuanYi Zen Hei Mono</family>
-        </prefer>
-    </alias>
-    <!-- end reorder fonts -->
+  <!-- Font families preferences -->
+  <!--
+      <alias> elements provide a shorthand notation for the set of common
+      match operations needed to substitute one font family for another.
+      They contain a <family> element followed by optional <prefer>,
+      <accept> and <default> elements.
+  -->
+  <!-- "serif" font family -->
+  <alias>
+    <!-- Which font family to be edited -->
+    <family>serif</family>
+    <!-- List of font families to *prepend before* the matching family -->
+    <prefer>
+      <family>Source Serif Pro</family>
+      <family>Noto Serif</family>
+    </prefer>
+    <!-- List of font families to *append after* the matching family -->
+    <accept></accept>
+    <!-- List of font families to *append* to the *end* of matching family -->
+    <default></default>
+  </alias>
+  <!-- "sans-serif" font family -->
+  <alias>
+    <family>sans-serif</family>
+    <prefer>
+      <family>Source Sans Pro</family>
+      <family>Noto Sans</family>
+    </prefer>
+  </alias>
+  <!-- "monospace" font family -->
+  <alias>
+    <family>monospace</family>
+    <prefer>
+      <family>Source Code Pro</family>
+      <family>Fira Code</family>
+      <family>Noto Mono</family>
+    </prefer>
+  </alias>
 
+  <!-- Substitute Helvetica and Arial -->
+  <match>
+    <test name="family">
+      <string>Helvetica</string>
+    </test>
+    <edit binding="same" mode="assign" name="family">
+      <string>Source Sans Pro</string>
+    </edit>
+  </match>
+  <match>
+    <test name="family">
+      <string>Arial</string>
+    </test>
+    <edit binding="same" mode="assign" name="family">
+      <string>Source Sans Pro</string>
+    </edit>
+  </match>
 </fontconfig>
-- 
cgit v1.2.2