Difference between revisions of "Font configuration/Examples"

From ArchWiki
Jump to navigation Jump to search
m (→‎Chrome OS fonts: flag for removal)
(update interlanguage links)
Tag: wiki-scripts
 
(59 intermediate revisions by 15 users not shown)
Line 1: Line 1:
 
[[Category:Fonts]]
 
[[Category:Fonts]]
 
[[ja:フォント設定/サンプル]]
 
[[ja:フォント設定/サンプル]]
[[ru:Font configuration/Examples]]
+
[[ru:Font configuration (Русский)/Examples]]
 
See [[Font configuration]] for the main article.  
 
See [[Font configuration]] for the main article.  
  
Line 8: Line 8:
 
== Hinted fonts ==
 
== Hinted fonts ==
  
{{hc|$XDG_CONFIG_HOME/fontconfig/fonts.conf|<nowiki>
+
{{hc|~/.config/fontconfig/fonts.conf|<nowiki>
 
<?xml version='1.0'?>
 
<?xml version='1.0'?>
 
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
 
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
Line 35: Line 35:
 
</nowiki>}}
 
</nowiki>}}
  
== No hinting for ''italic'' or '''bold''' ==
+
== No hinting for italic or bold ==
  
 
<pre>
 
<pre>
Line 70: Line 70:
 
</fontconfig>
 
</fontconfig>
 
</pre>
 
</pre>
 
== Sharp fonts ==
 
 
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 
<fontconfig>
 
  <match target="font">
 
    <edit name="antialias" mode="assign"><bool>true</bool></edit>
 
    <edit name="hinting" mode="assign"><bool>true</bool></edit>
 
    <edit name="hintstyle" mode="assign"><const>hintfull</const></edit>
 
    <edit name="lcdfilter" mode="assign"><const>lcddefault</const></edit>
 
    <edit name="rgba" mode="assign"><const>rgb</const></edit>
 
  </match>
 
</fontconfig>
 
 
== Liberation fonts ==
 
 
For font consistency, all applications should be set to use the serif, sans-serif, and monospace aliases, which are mapped to particular fonts by fontconfig. The Liberation fonts were chosen to follow metric-compatibility of the MS Core fonts.
 
 
{{bc|1=
 
<?xml version="1.0"?>
 
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 
<fontconfig>
 
    <match target="font">
 
        <edit mode="assign" name="antialias"><bool>true</bool></edit>
 
        <edit mode="assign" name="autohint"><bool>false</bool></edit>
 
        <edit mode="assign" name="embeddedbitmap"><bool>false</bool></edit>
 
        <edit mode="assign" name="hinting"><bool>true</bool></edit>
 
        <edit mode="assign" name="hintstyle"><const>hintslight</const></edit>
 
        <edit mode="assign" name="lcdfilter"><const>lcddefault</const></edit>
 
        <edit mode="assign" name="rgba"><const>rgb</const></edit>
 
    </match>
 
 
    <match target="pattern">
 
        <test qual="any" name="family"><string>serif</string></test>
 
        <edit name="family" mode="assign" binding="same"><string>Liberation Serif</string></edit>
 
    </match>
 
    <match target="pattern">
 
        <test qual="any" name="family"><string>sans-serif</string></test>
 
        <edit name="family" mode="assign" binding="same"><string>Liberation Sans</string></edit>
 
    </match>
 
    <match target="pattern">
 
        <test qual="any" name="family"><string>monospace</string></test>
 
        <edit name="family" mode="assign" binding="same"><string>Liberation Mono</string></edit>
 
    </match>
 
 
    <match target="pattern">
 
        <edit name="dpi" mode="assign"><double>96</double></edit>
 
    </match>
 
</fontconfig>
 
}}
 
  
 
== Enable anti-aliasing only for bigger fonts ==
 
== Enable anti-aliasing only for bigger fonts ==
Line 155: Line 105:
 
</nowiki>}}
 
</nowiki>}}
  
== Chrome OS fonts ==
+
== Disable bold font ==
  
{{Remove|We can't have such section for every font in the repositories that users might prefer. Everything necessary is already in [[Font_configuration#Replace_or_set_default_fonts]].}}
+
For when a font does not present itself well in bold and you can't disable bold fonts in the application ([[st]] for example).
  
Web browser and another common applications use {{ic|Serif}}, {{ic|Sans-Serif}} and {{ic|Monospace}} as default fonts ([[Fonts#Font alias]]). The procedure to change default fonts is similar to replace them. For example, to use Chrome OS fonts {{AUR|ttf-chromeos-fonts}}:
+
{{bc|<nowiki>
 +
...
 +
<match target="pattern">
 +
    <test qual="any" name="family">
 +
        <string>Envy Code R</string>
 +
    </test>
 +
    <test name="weight" compare="more">
 +
        <const>medium</const>
 +
    </test>
 +
    <edit name="weight" mode="assign" binding="same">
 +
        <const>medium</const>
 +
    </edit>
 +
</match>
 +
...
 +
</nowiki>}}
 +
 
 +
== Disable ligatures for monospaced fonts ==
 +
 
 +
This prevents letter combinations like "ffi" from being squashed into a single-width character in some monospaced fonts.  The whole {{ic|<match>}} block needs to be duplicated to include extra fonts.
  
 
{{bc|<nowiki>
 
{{bc|<nowiki>
<?xml version="1.0"?>
+
<?xml version="1.0" encoding="UTF-8"?>
 
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 
<fontconfig>
 
<fontconfig>
   <!-- Set preferred serif, sans serif, and monospace fonts. -->
+
   <description>Disable ligatures for monospaced fonts to avoid ff, fi, ffi, etc. becoming only one character wide</description>
  <alias>
+
 
    <family>serif</family>
+
   <match target="font">
    <prefer><family>Tinos</family></prefer>
+
     <test name="family" compare="eq" ignore-blanks="true">
  </alias>
+
      <string>Nimbus Mono PS</string>
   <alias>
+
    </test>
     <family>sans-serif</family>
+
     <edit name="fontfeatures" mode="append">
    <prefer><family>Arimo</family></prefer>
+
      <string>liga off</string>
  </alias>
+
      <string>dlig off</string>
  <alias>
+
     </edit>
     <family>sans</family>
+
   </match>
    <prefer><family>Arimo</family></prefer>
 
  </alias>
 
  <alias>
 
    <family>monospace</family>
 
     <prefer><family>Cousine</family></prefer>
 
   </alias>
 
 
</fontconfig>
 
</fontconfig>
 
</nowiki>}}
 
</nowiki>}}
  
== Google Noto Fonts ==
+
You can test the effectiveness of this with the following command:
 +
 
 +
$ echo -e "| worksheet |\n| buffering |\n| difficult |\n| finishing |\n| different |\n| efficient |" | pango-view --font="Nimbus Mono PS" /dev/stdin
 +
 
 +
Some programs (such as Firefox) do not support the {{ic|fontfeatures}} tag, so for those replacing the font with another is the only option. See [[Font configuration#Replace or set default fonts]] for details.
 +
 
 +
== Default fonts ==
 +
 
 +
For font consistency, all applications should be set to use the serif, sans-serif, and monospace aliases, which are mapped to particular fonts by fontconfig. See [[Metric-compatible fonts]] for options and examples.
  
{{Remove|We can't have such section for every font in the repositories that users might prefer. Everything necessary is already in [[Font_configuration#Replace_or_set_default_fonts]].}}
+
=== Japanese ===
  
The following configuration might be necessary to make use of [https://www.google.com/get/noto/ Google's Noto Fonts] available in the [[official repositories]].
+
Example fonts.conf which also specifies a default font for the Japanese locale (ja_JP) and keeps western style fonts for Latin letters.
  
 
{{bc|<nowiki>
 
{{bc|<nowiki>
 +
<?xml version='1.0'?>
 +
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
 +
<fontconfig>
 +
 +
<!-- Default font (no fc-match pattern) -->
 +
<match>
 +
  <edit mode="prepend" name="family">
 +
  <string>Noto Sans</string>
 +
  </edit>
 +
</match>
 +
 +
<!-- Default font for the ja_JP locale (no fc-match pattern) -->
 +
<match>
 +
  <test compare="contains" name="lang">
 +
  <string>ja</string>
 +
  </test>
 +
  <edit mode="prepend" name="family">
 +
  <string>Noto Sans CJK JP</string>
 +
  </edit>
 +
</match>
 +
 +
<!-- Default sans-serif font -->
 +
<match target="pattern">
 +
  <test qual="any" name="family"><string>sans-serif</string></test>
 +
  <!--<test qual="any" name="lang"><string>ja</string></test>-->
 +
  <edit name="family" mode="prepend" binding="same"><string>Noto Sans</string>  </edit>
 +
</match>
 +
 +
<!-- Default serif fonts -->
 +
<match target="pattern">
 +
  <test qual="any" name="family"><string>serif</string></test>
 +
  <edit name="family" mode="prepend" binding="same"><string>Noto Serif</string>  </edit>
 +
  <edit name="family" mode="append" binding="same"><string>IPAPMincho</string>  </edit>
 +
  <edit name="family" mode="append" binding="same"><string>HanaMinA</string>  </edit>
 +
</match>
 +
 +
<!-- Default monospace fonts -->
 +
<match target="pattern">
 +
  <test qual="any" name="family"><string>monospace</string></test>
 +
  <edit name="family" mode="prepend" binding="same"><string>Noto Sans Mono</string></edit>
 +
  <edit name="family" mode="append" binding="same"><string>Inconsolatazi4</string></edit>
 +
  <edit name="family" mode="append" binding="same"><string>IPAGothic</string></edit>
 +
</match>
 +
 +
<!-- Fallback fonts preference order -->
 +
<alias>
 +
  <family>sans-serif</family>
 +
  <prefer>
 +
  <family>Noto Sans</family>
 +
  <family>Open Sans</family>
 +
  <family>Droid Sans</family>
 +
  <family>Ubuntu</family>
 +
  <family>Roboto</family>
 +
  <family>NotoSansCJK</family>
 +
  <family>Source Han Sans JP</family>
 +
  <family>IPAPGothic</family>
 +
  <family>VL PGothic</family>
 +
  <family>Koruri</family>
 +
  </prefer>
 +
</alias>
 +
<alias>
 +
  <family>serif</family>
 +
  <prefer>
 +
  <family>Noto Serif</family>
 +
  <family>Droid Serif</family>
 +
  <family>Roboto Slab</family>
 +
  <family>IPAPMincho</family>
 +
  </prefer>
 +
</alias>
 +
<alias>
 +
  <family>monospace</family>
 +
  <prefer>
 +
  <family>Noto Sans Mono</family>
 +
  <family>Inconsolatazi4</family>
 +
  <family>Ubuntu Mono</family>
 +
  <family>Droid Sans Mono</family>
 +
  <family>Roboto Mono</family>
 +
  <family>IPAGothic</family>
 +
  </prefer>
 +
</alias>
 +
 +
</fontconfig>
 +
</nowiki>}}
 +
 +
=== Chinese ===
 +
{{hc|~/.config/fontconfig/fonts.conf
 +
or
 +
/etc/fonts/local.conf|<nowiki>
 
<?xml version="1.0"?>
 
<?xml version="1.0"?>
 
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 
<fontconfig>
 
<fontconfig>
  <alias> <family>serif</family>     <prefer> <family>Noto Serif</family> </prefer> </alias>
+
 
  <alias> <family>sans-serif</family> <prefer> <family>Noto Sans</family> </prefer> </alias>
+
<match target="font">
  <alias> <family>sans</family>       <prefer> <family>Noto Sans</family> </prefer> </alias>
+
<edit name="embeddedbitmap" mode="assign">
  <alias> <family>monospace</family> <prefer> <family>Noto Mono</family> </prefer> </alias>
+
<bool>false</bool>
 
+
</edit>
  <match> <test name="family"> <string>Arial</string> </test>           <edit name="family" mode="assign" binding="strong"> <string>Noto Sans</string> </edit> </match>
+
</match>
  <match> <test name="family"> <string>Helvetica</string> </test>       <edit name="family" mode="assign" binding="strong"> <string>Noto Sans</string> </edit> </match>
+
 
  <match> <test name="family"> <string>Verdana</string> </test>         <edit name="family" mode="assign" binding="strong"> <string>Noto Sans</string> </edit> </match>
+
<match>
  <match> <test name="family"> <string>Tahoma</string> </test>         <edit name="family" mode="assign" binding="strong"> <string>Noto Sans</string> </edit> </match>
+
<test qual="any" name="family">
  <match> <test name="family"> <string>Times New Roman</string> </test> <edit name="family" mode="assign" binding="strong"> <string>Noto Serif</string> </edit> </match>
+
<string>serif</string>
  <match> <test name="family"> <string>Times</string> </test>           <edit name="family" mode="assign" binding="strong"> <string>Noto Serif</string> </edit> </match>
+
</test>
  <!--match> <test name="family"> <string>Georgia</string> </test>         <edit name="family" mode="assign" binding="strong"> <string>Noto Serif</string> </edit> </match-->
+
<edit name="family" mode="prepend" binding="strong">
  <match> <test name="family"> <string>Consolas</string> </test>       <edit name="family" mode="assign" binding="strong"> <string>Noto Mono</string> </edit> </match>
+
<string>Noto Serif</string>
  <match> <test name="family"> <string>Courier New</string> </test>     <edit name="family" mode="assign" binding="strong"> <string>Noto Mono</string> </edit> </match>
+
</edit>
 +
</match>
 +
<match target="pattern">
 +
<test qual="any" name="family">
 +
<string>sans-serif</string>
 +
</test>
 +
<edit name="family" mode="prepend" binding="strong">
 +
<string>Roboto</string>
 +
</edit>
 +
</match>
 +
<match target="pattern">
 +
<test qual="any" name="family">
 +
<string>monospace</string>
 +
</test>
 +
<edit name="family" mode="prepend" binding="strong">
 +
<string>DejaVu Sans Mono</string>
 +
</edit>
 +
</match>
 +
 
 +
<match>
 +
<test name="lang" compare="contains">
 +
<string>zh</string>
 +
</test>
 +
<test name="family">
 +
<string>serif</string>
 +
</test>
 +
<edit name="family" mode="prepend">
 +
<string>Source Han Serif CN</string>
 +
</edit>
 +
</match>
 +
<match>
 +
<test name="lang" compare="contains">
 +
<string>zh</string>
 +
</test>
 +
<test name="family">
 +
<string>sans-serif</string>
 +
</test>
 +
<edit name="family" mode="prepend">
 +
<string>Source Han Sans CN</string>
 +
</edit>
 +
</match>
 +
<match>
 +
<test name="lang" compare="contains">
 +
<string>zh</string>
 +
</test>
 +
<test name="family">
 +
<string>monospace</string>
 +
</test>
 +
<edit name="family" mode="prepend">
 +
<string>Noto Sans Mono CJK SC</string>
 +
</edit>
 +
</match>
 +
 
 +
<!--Windows & Linux Chinese fonts. -->
 +
<match target="pattern">
 +
<test qual="any" name="family">
 +
<string>WenQuanYi Zen Hei</string>
 +
</test>
 +
<edit name="family" mode="assign" binding="same">
 +
<string>Source Han Sans CN</string>
 +
</edit>
 +
</match>
 +
<match target="pattern">
 +
                <test qual="any" name="family">
 +
                        <string>WenQuanYi Micro Hei</string>
 +
                </test>
 +
                <edit name="family" mode="assign" binding="same">
 +
                        <string>Source Han Sans CN</string>
 +
                </edit>
 +
</match>
 +
        <match target="pattern">
 +
                <test qual="any" name="family">
 +
                        <string>WenQuanYi Micro Hei Light</string>
 +
                </test>
 +
                <edit name="family" mode="assign" binding="same">
 +
                        <string>Source Han Sans CN</string>
 +
                </edit>
 +
        </match>
 +
<match target="pattern">
 +
                <test qual="any" name="family">
 +
                        <string>Microsoft YaHei</string>
 +
                </test>
 +
                <edit name="family" mode="assign" binding="same">
 +
                        <string>Source Han Sans CN</string>
 +
                </edit>
 +
        </match>
 +
        <match target="pattern">
 +
                <test qual="any" name="family">
 +
                        <string>SimHei</string>
 +
                </test>
 +
                <edit name="family" mode="assign" binding="same">
 +
                        <string>Source Han Sans CN</string>
 +
                </edit>
 +
        </match>
 +
        <match target="pattern">
 +
                <test qual="any" name="family">
 +
                        <string>SimSun</string>
 +
                </test>
 +
                <edit name="family" mode="assign" binding="same">
 +
                        <string>Source Han Serif CN</string>
 +
                </edit>
 +
        </match>
 +
        <match target="pattern">
 +
                <test qual="any" name="family">
 +
                        <string>SimSun-18030</string>
 +
                </test>
 +
                <edit name="family" mode="assign" binding="same">
 +
                        <string>Source Han Serif CN</string>
 +
                </edit>
 +
        </match>
 
</fontconfig>
 
</fontconfig>
 
</nowiki>}}
 
</nowiki>}}
  
== Patched packages ==
+
=== Chinese in Noto Fonts ===
 +
Apply Noto Fonts, while replace Microsoft Fonts with WenQuanYi Micro Hei
 +
{{hc|~/.config/fontconfig/fonts.conf
 +
or
 +
/etc/fonts/local.conf|<nowiki>
 +
<?xml version="1.0"?>
 +
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 +
<fontconfig>
 +
    <match target="font">
 +
        <edit name="embeddedbitmap" mode="assign">
 +
            <bool>false</bool>
 +
        </edit>
 +
    </match>
 +
    <match>
 +
        <test qual="any" name="family">
 +
            <string>serif</string>
 +
        </test>
 +
        <edit name="family" mode="prepend" binding="strong">
 +
            <string>Noto Serif</string>
 +
        </edit>
 +
    </match>
 +
    <match target="pattern">
 +
        <test qual="any" name="family">
 +
            <string>sans-serif</string>
 +
        </test>
 +
        <edit name="family" mode="prepend" binding="strong">
 +
            <string>Noto Sans</string>
 +
        </edit>
 +
    </match>
 +
    <match target="pattern">
 +
        <test qual="any" name="family">
 +
            <string>monospace</string>
 +
        </test>
 +
        <edit name="family" mode="prepend" binding="strong">
 +
            <string>Noto Sans Mono</string>
 +
        </edit>
 +
    </match>
 +
    <match>
 +
        <test name="lang" compare="contains">
 +
            <string>zh</string>
 +
        </test>
 +
        <test name="family">
 +
            <string>serif</string>
 +
        </test>
 +
        <edit name="family" mode="prepend">
 +
            <string>Noto Serif CJK SC</string>
 +
        </edit>
 +
    </match>
 +
    <match>
 +
        <test name="lang" compare="contains">
 +
            <string>zh</string>
 +
        </test>
 +
        <test name="family">
 +
            <string>sans-serif</string>
 +
        </test>
 +
        <edit name="family" mode="prepend">
 +
            <string>Noto Sans CJK SC</string>
 +
        </edit>
 +
    </match>
 +
    <match>
 +
        <test name="lang" compare="contains">
 +
            <string>zh</string>
 +
        </test>
 +
        <test name="family">
 +
            <string>monospace</string>
 +
        </test>
 +
        <edit name="family" mode="prepend">
 +
            <string>Noto Sans Mono CJK SC</string>
 +
        </edit>
 +
    </match>
  
{{Warning|AUR packages are maintained separately from applications in the [[official repositories]]. The whole graphical system can become inoperable, if the user-installed core graphical libraries become incompatible.}}
+
    <!--WenQuanYi Zen Hei -> WenQuanYi Micro Hei -->
 +
    <match target="pattern">
 +
        <test qual="any" name="family">
 +
            <string>WenQuanYi Zen Hei</string>
 +
        </test>
 +
        <edit name="family" mode="assign" binding="same">
 +
            <string>WenQuanYi Micro Hei</string>
 +
        </edit>
 +
    </match>
 +
    <match target="pattern">
 +
        <test qual="any" name="family">
 +
            <string>WenQuanYi Zen Hei Lite</string>
 +
        </test>
 +
        <edit name="family" mode="assign" binding="same">
 +
            <string>WenQuanYi Micro Hei Lite</string>
 +
        </edit>
 +
    </match>
 +
    <match target="pattern">
 +
        <test qual="any" name="family">
 +
            <string>WenQuanYi Zen Hei Mono</string>
 +
        </test>
 +
        <edit name="family" mode="assign" binding="same">
 +
            <string>WenQuanYi Micro Hei Mono</string>
 +
        </edit>
 +
    </match>
  
{{Note|
+
    <!--Microsoft YaHei, SimHei, SimSun -> WenQuanYi Micro Hei -->
* Configuration is usually necessary.
+
    <match target="pattern">
* The new font rendering will not be available until applications restart.
+
        <test qual="any" name="family">
* Applications which [[Wikipedia:Static library|statically link]] to a library will not be affected by the system library, or patches applied to it.
+
            <string>Microsoft YaHei</string>
}}
+
        </test>
 +
        <edit name="family" mode="assign" binding="same">
 +
            <string>WenQuanYi Micro Hei</string>
 +
        </edit>
 +
    </match>
 +
    <match target="pattern">
 +
        <test qual="any" name="family">
 +
            <string>SimHei</string>
 +
        </test>
 +
        <edit name="family" mode="assign" binding="same">
 +
            <string>WenQuanYi Micro Hei</string>
 +
        </edit>
 +
    </match>
 +
    <match target="pattern">
 +
        <test qual="any" name="family">
 +
            <string>SimSun</string>
 +
        </test>
 +
        <edit name="family" mode="assign" binding="same">
 +
            <string>WenQuanYi Micro Hei</string>
 +
        </edit>
 +
    </match>
 +
    <match target="pattern">
 +
        <test qual="any" name="family">
 +
            <string>SimSun-18030</string>
 +
        </test>
 +
        <edit name="family" mode="assign" binding="same">
 +
            <string>WenQuanYi Micro Hei</string>
 +
        </edit>
 +
    </match>
 +
</fontconfig>
 +
</nowiki>}}
  
* {{App|freetype2-ubuntu|Font configuration shipped with Ubuntu. [http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/wily/fontconfig/wily/files/head:/debian/patches/] [http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/wily/freetype/wily/files/head:/debian/patches-freetype/]|https://launchpad.net/ubuntu/+source/freetype|{{AUR|freetype2-ubuntu}} {{AUR|fontconfig-ubuntu}}}}
+
== Alternate stylistic sets for fonts ==
* {{App|[[Infinality]]|Font configuration files, patches, and scripts.|https://github.com/bohoomil/fontconfig-ultimate|{{AUR|freetype2-infinality}} {{AUR|fontconfig-infinality}}}}
+
 
 +
Certain fonts come with alternate stylistic sets for characters through an OpenType feature.
 +
Generally these stylistic sets are named {{ic|<nowiki>ss0x</nowiki>}} and contain small changes to individual characters.
 +
This shows how to change the default dotted zero to a slashed zero for the monospace version of {{Pkg|ttf-ibm-plex}}.
 +
 
 +
{{hc|~/.config/fontconfig/fonts.conf|<nowiki>
 +
<?xml version="1.0"?>
 +
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 +
<fontconfig>
 +
    <match target='font'>
 +
        <test name='fontformat' compare='not_eq'>
 +
            <string/>
 +
        </test>
 +
        <test name='family'>
 +
            <string>IBM Plex Mono</string>
 +
        </test>
 +
        <edit name='fontfeatures' mode='assign_replace'>
 +
            <string>ss03</string>
 +
        </edit>
 +
    </match>
 +
</fontconfig>
 +
</nowiki>}}
  
To restore the original packages, reinstall {{Pkg|freetype2}}, {{pkg|cairo}}, and {{pkg|fontconfig}} as dependencies (use the {{ic|--asdeps}} flag with pacman when reinstalling). Include {{pkg|lib32-cairo}}, {{pkg|lib32-fontconfig}}, and {{pkg|lib32-freetype2}} if you also installed 32-bit versions.
+
See [https://www.typography.com/faq/question.php?faqID=157 What are "Stylistic Sets?"] for more information on this.
  
 
== See also ==
 
== See also ==
  
 
* [http://forums.gentoo.org/viewtopic-p-7273876.html#7273876 Gentoo forums]
 
* [http://forums.gentoo.org/viewtopic-p-7273876.html#7273876 Gentoo forums]
 +
* [https://wiki.ubuntu.com/BetterCJKSupportSpecification/FontConfig Ubuntu Wiki]

Latest revision as of 21:13, 24 November 2019

See Font configuration for the main article.

Configurations can vary to a degree. Please post Fontconfig configurations with an explanation for why they were done.

Hinted fonts

~/.config/fontconfig/fonts.conf
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
	<match target="font">
		<edit mode="assign" name="antialias">
			<bool>true</bool>
		</edit>
		<edit mode="assign" name="embeddedbitmap">
			<bool>false</bool>
		</edit>
		<edit mode="assign" name="hinting">
			<bool>true</bool>
		</edit>
		<edit mode="assign" name="hintstyle">
			<const>hintslight</const>
		</edit>
		<edit mode="assign" name="lcdfilter">
			<const>lcddefault</const>
		</edit>
		<edit mode="assign" name="rgba">
			<const>rgb</const>
		</edit>
	</match>
</fontconfig>

No hinting for italic or bold

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
  <match target="font" >
    <edit mode="assign" name="autohint">  <bool>true</bool></edit>
    <edit mode="assign" name="hinting">	  <bool>false</bool></edit>
    <edit mode="assign" name="lcdfilter"> <const>lcddefault</const></edit>
    <edit mode="assign" name="hintstyle"> <const>hintslight</const></edit>
    <edit mode="assign" name="antialias"> <bool>true</bool></edit>
    <edit mode="assign" name="rgba">      <const>rgb</const></edit>
  </match>

  <match target="font">
    <test name="pixelsize" qual="any" compare="more"><double>15</double></test>
    <edit mode="assign" name="lcdfilter"><const>lcdlight</const></edit>
    <edit mode="assign" name="hintstyle"><const>hintnone</const></edit>
  </match>

  <match target="font">
    <test name="weight" compare="more"><const>medium</const></test>
    <edit mode="assign" name="hintstyle"><const>hintnone</const></edit>
    <edit mode="assign" name="lcdfilter"><const>lcdlight</const></edit>
  </match>

  <match target="font">
    <test name="slant"  compare="not_eq"><double>0</double></test>
    <edit mode="assign" name="hintstyle"><const>hintnone</const></edit>
    <edit mode="assign" name="lcdfilter"><const>lcdlight</const></edit>
  </match>

</fontconfig>

Enable anti-aliasing only for bigger fonts

Some users prefer the sharper rendering that anti-aliasing does not offer:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <match target="font">
    <edit name="antialias" mode="assign">
      <bool>false</bool>
    </edit>
  </match>

  <match target="font" >
    <test name="size" qual="any" compare="more">
      <double>12</double>
    </test>
    <edit name="antialias" mode="assign">
      <bool>true</bool>
    </edit>
  </match>

  <match target="font" >
    <test name="pixelsize" qual="any" compare="more">
      <double>16</double>
    </test>
    <edit name="antialias" mode="assign">
      <bool>true</bool>
    </edit>
  </match>
</fontconfig>

Disable bold font

For when a font does not present itself well in bold and you can't disable bold fonts in the application (st for example).

...
<match target="pattern">
    <test qual="any" name="family">
        <string>Envy Code R</string>
    </test>
    <test name="weight" compare="more">
        <const>medium</const>
    </test>
    <edit name="weight" mode="assign" binding="same">
        <const>medium</const>
    </edit>
</match>
...

Disable ligatures for monospaced fonts

This prevents letter combinations like "ffi" from being squashed into a single-width character in some monospaced fonts. The whole <match> block needs to be duplicated to include extra fonts.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <description>Disable ligatures for monospaced fonts to avoid ff, fi, ffi, etc. becoming only one character wide</description>

  <match target="font">
    <test name="family" compare="eq" ignore-blanks="true">
      <string>Nimbus Mono PS</string>
    </test>
    <edit name="fontfeatures" mode="append">
      <string>liga off</string>
      <string>dlig off</string>
    </edit>
  </match>
</fontconfig>

You can test the effectiveness of this with the following command:

$ echo -e "| worksheet |\n| buffering |\n| difficult |\n| finishing |\n| different |\n| efficient |" | pango-view --font="Nimbus Mono PS" /dev/stdin

Some programs (such as Firefox) do not support the fontfeatures tag, so for those replacing the font with another is the only option. See Font configuration#Replace or set default fonts for details.

Default fonts

For font consistency, all applications should be set to use the serif, sans-serif, and monospace aliases, which are mapped to particular fonts by fontconfig. See Metric-compatible fonts for options and examples.

Japanese

Example fonts.conf which also specifies a default font for the Japanese locale (ja_JP) and keeps western style fonts for Latin letters.

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

<!-- Default font (no fc-match pattern) -->
 <match>
  <edit mode="prepend" name="family">
   <string>Noto Sans</string>
  </edit>
 </match>

<!-- Default font for the ja_JP locale (no fc-match pattern) -->
 <match>
  <test compare="contains" name="lang">
   <string>ja</string>
  </test>
  <edit mode="prepend" name="family">
   <string>Noto Sans CJK JP</string>
  </edit>
 </match>

<!-- Default sans-serif font -->
 <match target="pattern">
   <test qual="any" name="family"><string>sans-serif</string></test>
   <!--<test qual="any" name="lang"><string>ja</string></test>-->
   <edit name="family" mode="prepend" binding="same"><string>Noto Sans</string>  </edit>
 </match>
 
<!-- Default serif fonts -->
 <match target="pattern">
   <test qual="any" name="family"><string>serif</string></test>
   <edit name="family" mode="prepend" binding="same"><string>Noto Serif</string>  </edit>
   <edit name="family" mode="append" binding="same"><string>IPAPMincho</string>  </edit>
   <edit name="family" mode="append" binding="same"><string>HanaMinA</string>  </edit>
 </match>

<!-- Default monospace fonts -->
 <match target="pattern">
   <test qual="any" name="family"><string>monospace</string></test>
   <edit name="family" mode="prepend" binding="same"><string>Noto Sans Mono</string></edit>
   <edit name="family" mode="append" binding="same"><string>Inconsolatazi4</string></edit>
   <edit name="family" mode="append" binding="same"><string>IPAGothic</string></edit>
 </match>

<!-- Fallback fonts preference order -->
 <alias>
  <family>sans-serif</family>
  <prefer>
   <family>Noto Sans</family>
   <family>Open Sans</family>
   <family>Droid Sans</family>
   <family>Ubuntu</family>
   <family>Roboto</family>
   <family>NotoSansCJK</family>
   <family>Source Han Sans JP</family>
   <family>IPAPGothic</family>
   <family>VL PGothic</family>
   <family>Koruri</family>
  </prefer>
 </alias>
 <alias>
  <family>serif</family>
  <prefer>
   <family>Noto Serif</family>
   <family>Droid Serif</family>
   <family>Roboto Slab</family>
   <family>IPAPMincho</family>
  </prefer>
 </alias>
 <alias>
  <family>monospace</family>
  <prefer>
   <family>Noto Sans Mono</family>
   <family>Inconsolatazi4</family>
   <family>Ubuntu Mono</family>
   <family>Droid Sans Mono</family>
   <family>Roboto Mono</family>
   <family>IPAGothic</family>
  </prefer>
 </alias>

</fontconfig>

Chinese

~/.config/fontconfig/fonts.conf
or
/etc/fonts/local.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

	<match target="font">
		<edit name="embeddedbitmap" mode="assign">
			<bool>false</bool>
		</edit>
	</match>

	<match>
		<test qual="any" name="family">
			<string>serif</string>
		</test>
		<edit name="family" mode="prepend" binding="strong">
			<string>Noto Serif</string>
		</edit>
	</match>
	<match target="pattern">
		<test qual="any" name="family">
			<string>sans-serif</string>
		</test>
		<edit name="family" mode="prepend" binding="strong">
			<string>Roboto</string>
		</edit>
	</match>
	<match target="pattern">
		<test qual="any" name="family">
			<string>monospace</string>
		</test>
		<edit name="family" mode="prepend" binding="strong">
			<string>DejaVu Sans Mono</string>
		</edit>
	</match>

	<match>
		<test name="lang" compare="contains">
			<string>zh</string>
		</test>
		<test name="family">
			<string>serif</string>
		</test>
		<edit name="family" mode="prepend">
			<string>Source Han Serif CN</string>
		</edit>
	</match>
	<match>
		<test name="lang" compare="contains">
			<string>zh</string>
		</test>
		<test name="family">
			<string>sans-serif</string>
		</test>
		<edit name="family" mode="prepend">
			<string>Source Han Sans CN</string>
		</edit>
	</match>
	<match>
		<test name="lang" compare="contains">
			<string>zh</string>
		</test>
		<test name="family">
			<string>monospace</string>
		</test>
		<edit name="family" mode="prepend">
			<string>Noto Sans Mono CJK SC</string>
		</edit>
	</match>

<!--Windows & Linux Chinese fonts. -->
	<match target="pattern">
		<test qual="any" name="family">
			<string>WenQuanYi Zen Hei</string>
		</test>
		<edit name="family" mode="assign" binding="same">
			<string>Source Han Sans CN</string>
		</edit>
	</match>
	<match target="pattern">
                <test qual="any" name="family">
                        <string>WenQuanYi Micro Hei</string>
                </test>
                <edit name="family" mode="assign" binding="same">
                        <string>Source Han Sans CN</string>
                </edit>
	</match>
        <match target="pattern">
                <test qual="any" name="family">
                        <string>WenQuanYi Micro Hei Light</string>
                </test>
                <edit name="family" mode="assign" binding="same">
                        <string>Source Han Sans CN</string>
                </edit>
        </match>
	<match target="pattern">
                <test qual="any" name="family">
                        <string>Microsoft YaHei</string>
                </test>
                <edit name="family" mode="assign" binding="same">
                        <string>Source Han Sans CN</string>
                </edit>
        </match>
        <match target="pattern">
                <test qual="any" name="family">
                        <string>SimHei</string>
                </test>
                <edit name="family" mode="assign" binding="same">
                        <string>Source Han Sans CN</string>
                </edit>
        </match>
        <match target="pattern">
                <test qual="any" name="family">
                        <string>SimSun</string>
                </test>
                <edit name="family" mode="assign" binding="same">
                        <string>Source Han Serif CN</string>
                </edit>
        </match>
        <match target="pattern">
                <test qual="any" name="family">
                        <string>SimSun-18030</string>
                </test>
                <edit name="family" mode="assign" binding="same">
                        <string>Source Han Serif CN</string>
                </edit>
        </match>
</fontconfig>

Chinese in Noto Fonts

Apply Noto Fonts, while replace Microsoft Fonts with WenQuanYi Micro Hei

~/.config/fontconfig/fonts.conf
or
/etc/fonts/local.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <match target="font">
        <edit name="embeddedbitmap" mode="assign">
            <bool>false</bool>
        </edit>
    </match>
    <match>
        <test qual="any" name="family">
            <string>serif</string>
        </test>
        <edit name="family" mode="prepend" binding="strong">
            <string>Noto Serif</string>
        </edit>
    </match>
    <match target="pattern">
        <test qual="any" name="family">
            <string>sans-serif</string>
        </test>
        <edit name="family" mode="prepend" binding="strong">
            <string>Noto Sans</string>
        </edit>
    </match>
    <match target="pattern">
        <test qual="any" name="family">
            <string>monospace</string>
        </test>
        <edit name="family" mode="prepend" binding="strong">
            <string>Noto Sans Mono</string>
        </edit>
    </match>
    <match>
        <test name="lang" compare="contains">
            <string>zh</string>
        </test>
        <test name="family">
            <string>serif</string>
        </test>
        <edit name="family" mode="prepend">
            <string>Noto Serif CJK SC</string>
        </edit>
    </match>
    <match>
        <test name="lang" compare="contains">
            <string>zh</string>
        </test>
        <test name="family">
            <string>sans-serif</string>
        </test>
        <edit name="family" mode="prepend">
            <string>Noto Sans CJK SC</string>
        </edit>
    </match>
    <match>
        <test name="lang" compare="contains">
            <string>zh</string>
        </test>
        <test name="family">
            <string>monospace</string>
        </test>
        <edit name="family" mode="prepend">
            <string>Noto Sans Mono CJK SC</string>
        </edit>
    </match>

    <!--WenQuanYi Zen Hei -> WenQuanYi Micro Hei -->
    <match target="pattern">
        <test qual="any" name="family">
            <string>WenQuanYi Zen Hei</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>WenQuanYi Micro Hei</string>
        </edit>
    </match>
    <match target="pattern">
        <test qual="any" name="family">
            <string>WenQuanYi Zen Hei Lite</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>WenQuanYi Micro Hei Lite</string>
        </edit>
    </match>
    <match target="pattern">
        <test qual="any" name="family">
            <string>WenQuanYi Zen Hei Mono</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>WenQuanYi Micro Hei Mono</string>
        </edit>
    </match>

    <!--Microsoft YaHei, SimHei, SimSun -> WenQuanYi Micro Hei -->
    <match target="pattern">
        <test qual="any" name="family">
            <string>Microsoft YaHei</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>WenQuanYi Micro Hei</string>
        </edit>
    </match>
    <match target="pattern">
        <test qual="any" name="family">
            <string>SimHei</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>WenQuanYi Micro Hei</string>
        </edit>
    </match>
    <match target="pattern">
        <test qual="any" name="family">
            <string>SimSun</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>WenQuanYi Micro Hei</string>
        </edit>
    </match>
    <match target="pattern">
        <test qual="any" name="family">
            <string>SimSun-18030</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>WenQuanYi Micro Hei</string>
        </edit>
    </match>
</fontconfig>

Alternate stylistic sets for fonts

Certain fonts come with alternate stylistic sets for characters through an OpenType feature. Generally these stylistic sets are named ss0x and contain small changes to individual characters. This shows how to change the default dotted zero to a slashed zero for the monospace version of ttf-ibm-plex.

~/.config/fontconfig/fonts.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <match target='font'>
        <test name='fontformat' compare='not_eq'>
            <string/>
        </test>
        <test name='family'>
            <string>IBM Plex Mono</string>
        </test>
        <edit name='fontfeatures' mode='assign_replace'>
            <string>ss03</string>
        </edit>
    </match>
</fontconfig>

See What are "Stylistic Sets?" for more information on this.

See also