Font Configuration
From ArchWiki
Dansk – Deutsch – English – Español – Français – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Polski – Português – Română – Slovenský – Suomi – Svenska – Türkçe – Česky – Ελληνικά – Русский – Српски – Українська – עברית – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어
| Summary |
|---|
| Provides an overview of font configuration options and describes various techniques for improving fonts' appearance |
| Related |
| Fonts: Information on adding fonts and font recommendations |
| Java Fonts - Sun JRE: Fonts specific to Sun's Java machine |
| MS Fonts: Adding Microsoft fonts and mimicking Windows' font settings |
Contents |
Font paths
Fontconfig is used by most applications for the purposes of listing fonts and supplying other font related requests. However, for applications such as dwm which do not use fontconfig, non-standard Xorg font paths must be specified in the Xorg server configuration file, /etc/X11/xorg.conf.
Fontconfig
Settings stated in /etc/fonts/fonts.conf are used by fontconfig compatible applications. This file sources other rules which may be present in /etc/fonts/local.conf (does not exist after installation), and these are in turn influenced by other rules set in directory /etc/fonts/conf.d/.
The font paths initially known to fontconfig are /usr/share/fonts/ and ~/.fonts/. It is recommended to use these font paths when installing new fonts, although adding paths or changing them altogether is also viable.
To see a list of known fontconfig fonts, type:
$ fc-list
Seeing that this shows a great deal of information, cut through the noise by using other tools to filter the output:
fc-list | sed s,:.*,, | sort -u
Xorg
Check for Xorg's known font paths by reviewing its log:
$ grep /fonts /var/log/Xorg.0.log
and then add then any needed font paths in the configuration file.
Keep in mind that Xorg should not recurse through the /usr/share/fonts directory like fontconfig does; add the full paths instead:
Section "Files" FontPath "/usr/share/fonts/example-font-directory" EndSection
To see a list of known Xorg fonts, use xlsfonts, or xselfontsel to additionally test the fonts through live preview.
Fontconfig configuration
The font rendering packages on Arch Linux provide sufficient font support using freetype2 with the bytecode interpreter (BCI) enabled. In spite of that, defining additional font configuration may at times be necessary.
Configuration can be done either per-user through file ~/.fonts.conf, or globally with /etc/fonts/local.conf. Both locations are interchangeable since they use the same form and syntax, yet local.conf carries the distinction of overriding settings specified in its user-only counterpart. Note that /etc/fonts/fonts.conf shouldn't be edited since it's subject to being replaced during fontconfig updates.
Additionally, there is a directory-centric manner of setting rules that are intended as a complement for the main files' settings, or as a practical way of overriding them. Not unlike the original sysvinit system of symbolic link configuration, there are fontconfig files present in /etc/fonts/conf.avail that can be linked from ~/.fonts.conf.d for user setup, and /etc/fonts/conf.d for system-wide changes. These files have a small group of settings that are meant to resemble "presets".
In this example, sub-pixel-rgb is being globally enabled among the many choices available:
# cd /etc/fonts/conf.d # ln -s ../conf.avail/10-sub-pixel-rgb.conf
and for user configuration:
$ mkdir ~/.fonts.conf.d $ ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf ~/.fonts.conf.d
Important settings
The header and footer observed in /etc/fonts/fonts.conf must be present in all configuration files for them to be recognized as valid:
<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> ... </fontconfig>
Because of their ubiquity, the rest of the configuration excerpts in this article omit these tags.
Antialiasing
Without font smoothing, or better known as anti-aliasing, some users believe fonts appear to be jagged or distorted. Anti-aliasing is enabled by default, yet can be toggled-off with a fontconfig stanza:
...
<match target="font">
<edit name="antialias" mode="assign">
<bool>false</bool>
</edit>
</match>
...
Hinting
Font hinting adjusts the spacing of fonts so that they line up with the pixel grid. A common occurrence in consumer-level systems, hinting is required for displays with less than 300 DPI for font spacing to appear correctly.
Fontconfig uses BCI by default, which may be disabled:
...
<match target="font">
<edit name="hinting" mode="assign">
<bool>false</bool>
</edit>
</match>
...
or entirely replaced with the auto-hinter, offering more options at the expense of render quality:
...
<match target="font">
<edit name="autohint" mode="assign">
<bool>true</bool>
</edit>
</match>
...
Note that fontconfig does not apply BCI hinting to aliased fonts (as in those with anti-aliasing disabled; not to confuse with alias names for fonts).
Auto-hinting style
These influence the degree in which the auto-hinter pronounces itself: hintfull, hintmedium, hintslight (recommended) and hintnone.
...
<match target="font">
<edit name="hintstyle" mode="assign">
<const>hintslight</const>
</edit>
</match>
...
Subpixel rendering
RGB, BGR, V-RGB (vertical), or V-BGR
The majority of monitors tend to use the RGB specification, and Xorg will in most situations detect the correct setting and apply it without intervention. If noticing unusual color hues around font's borders, check the monitor's type here and specify it in a font configuration file:
...
<match target="font">
<edit name="rgba" mode="assign">
<const>rgb</const>
</edit>
</match>
...
Like the automatic settings most DE font control panels establish, it is recommended to disable subpixel rendering when using the auto hinter since the combination of the two may result in unsatisfactory rendering.
LCD filter patched packages
Some distributions choose not to use the LCD filter patches for font rendering due to patent ambiguity. Nevertheless, many of these patched packages are available in the AUR and easily installable by using an AUR helper.
Considerations:
- All of these methods are designed for LCD displays, yet CRT users can equally benefit by using the ClearType packages.
- The new font effects will not be displayed until affected applications restart.
'-lcd' patched packages
These packages are the most generic solution for those using LCD monitors, given that this approach is not as specific as ClearType and Ubuntu-patched packages' goals.
Remove the conflicting packages:
pacman -Rd libxft cairo
Install the patched packages from the AUR:
$ yaourt -S fontconfig-lcd cairo-lcd
And install the patched packages from the repositories:
pacman -S libxft-lcd
The fontconfig-lcd package originally uses the lcddefault filter, which was chosen as a catch-all for most scenarios. Two other filters are available that differ in accentuation: lcdlight; a lighter filter ideal for fonts that look too bold or fuzzy, and lcdlegacy, which is the old, default Cairo filter. Set lcdnone to disable it entirely.
The example LCD filter configuration may be found at /etc/fonts/conf.avail/10-lcd-filter.conf.
Ubuntu patched packages
Ubuntu has made their own LCD-related patches.
First, the conflicting packages need to be removed:
pacman -Rd libxft cairo fontconfig freetype2
Then the patched packages are installed:
yaourt -S cairo-ubuntu fontconfig-ubuntu libxft-ubuntu freetype2-ubuntu
ClearType packages
There are more effects for fonts from Windows system, a somewhat different type of font rendering.
Remove the conflicting packages:
pacman -Rd cairo libxft freetype2
And then install the patched packages from the AUR:
yaourt -S freetype2-cleartype libxft-cleartype cairo-cleartype
Reverting to original packages
To restore the unpatched packages, first uninstall the patched versions then reinstall the originals:
pacman -S freetype2 libxft cairo
Additional fontconfig configuration
Disable auto-hinter for bold fonts
The auto-hinter uses sophisticated methods for font rendering, but often makes bold fonts too wide. Fortunately, a solution can be turning off the auto-hinter for bold fonts while leaving it on for the rest:
...
<match target="font">
<test name="weight" compare="more">
<const>medium</const>
</test>
<edit name="autohint" mode="assign">
<bool>false</bool>
</edit>
</match>
...
Enable anti-aliasing only for bigger fonts
See also sharpfonts.com for related information
Some users prefer the sharper rendering that anti-aliasing doesn't offer:
...
<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>17</double>
</test>
<edit name="antialias" mode="assign">
<bool>true</bool>
</edit>
</match>
...
Replace fonts
The most reliable way to do this is to add an XML fragment similar to the one below. This will cause Bitstream Vera Sans to be used in place of Helvetica:
...
<match target="pattern" name="family" >
<test name="family" qual="any" >
<string>Helvetica</string>
</test>
<edit name="family" mode="assign">
<string>Bitstream Vera Sans</string>
</edit>
</match>
...
An alternate approach is to set the "preferred" font, but this only works if the original font is not on the system, in which case the one specified will be substituted:
...
< !-- Replace Helvetica with Bitstream Vera Sans Mono -->
< !-- Note, an alias for Helvetica should already exist in default conf files -->
<alias>
<family>Helvetica</family>
<prefer><family>Bitstream Vera Sans Mono</family></prefer>
<default><family>fixed</family></default>
</alias>
...
Disable bitmap fonts
To disable bitmap fonts in fontconfig, use 70-no-bitmaps.conf:
# rm /etc/fonts/conf.d/70-yes-bitmaps.conf # Not placed by fontconfig by default # ln -s /etc/fonts/conf.avail/70-no-bitmaps.conf /etc/fonts/conf.d # Or ~/.fonts.conf.d as target dir
Then to replace some (Helvetica, Courier and Times) bitmap fonts with TTF fonts:
# ln -s /etc/conf.avail/29-replace-bitmap-fonts.conf /etc/fonts/conf.d # Placed by default
Create bold and italic styles for incomplete fonts
Freetype has the ability to automatically create italic and bold styles for fonts that do not have them, but only if explicitly required by the application. Given programs rarely send these requests, this section covers manually forcing generation of missing styles.
Start by editing /usr/share/fonts/fonts.cache-1 as explained below. Store a copy of the modifications on another file, because a font update with fc-cache will overwrite /usr/share/fonts/fonts.cache-1.
Assuming the Dupree font is installed:
"dupree.ttf" 0 "Dupree:style=Regular:slant=0:weight=80:width=100:foundry=unknown:index=0:outline=True:etc...
Duplicate the line, change style=Regular to style=Bold or any other style. Also change slant=0 to slant=100 for italic, weight=80 to weight=200 for bold, or combine them for bold italic:
"dupree.ttf" 0 "Dupree:style=Bold Italic:slant=100:weight=200:width=100:foundry=unknown:index=0:outline=True:etc...
Now add necessary modifications to ~/.fonts.conf:
...
<match target="font">
<test name="family" qual="any">
<string>Dupree</string>
<!-- other fonts here .... -->
</test>
<test name="weight" compare="more_eq"><int>140</int></test>
<edit name="embolden" mode="assign"><bool>true</bool></edit>
</match>
<match target="font">
<test name="family" qual="any">
<string>Dupree</string>
<!-- other fonts here .... -->
</test>
<test name="slant" compare="more_eq"><int>80</int></test>
<edit name="matrix" mode="assign">
<times>
<name>matrix</name>
<matrix>
<double>1</double><double>0.2</double>
<double>0</double><double>1</double>
</matrix>
</times>
</edit>
</match>
...
Change rule overriding
Fontconfig processes files in /etc/fonts/conf.d in numeric order. This enables rules or files to override one another, but often confuses users about what file gets parsed last.
To guarantee that personal settings take precedence over any other rules, change their ordering:
# cd /etc/fonts/conf.d # mv 50-user.conf 99-user.conf
Sample fontconfig setups
Example 1
A web developer's configuration (modified) taken from the forums. Back up current settings before testing the ones below:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- The cathectic LCD tweaks, from linuxquestions.org,
http://www.linuxquestions.org/questions/showthread.php?postid=1361098#post1361098 -->
<fontconfig>
<match target="font" >
<!-- Disable sub-pixel rendering.
X detects it anyway, and if you set this as well, it just looks really horrible -->
<edit mode="assign" name="rgba" >
<const>none</const>
</edit>
<!-- Autohinter is not turned on automatically.
Only disable this if you have recompiled Freetype with the bytecode interpreter,
which is run automatically. -->
<edit mode="assign" name="autohint">
<bool>true</bool>
</edit>
<!-- Change hintstyle to full -->
<edit mode="assign" name="hintstyle">
<const>hintfull</const>
</edit>
</match>
<match target="font">
<!-- Disable auto hinting for bold fonts -->
<test name="weight" compare="more">
<const>medium</const>
</test>
<edit name="autohint" mode="assign">
<bool>false</bool>
</edit>
</match>
<!-- Helvetica is a non true type font, and will look bad.
This replaces it with whatever is the default sans-serif font -->
<match target="pattern" name="family" >
<test name="family" qual="any" >
<string>Helvetica</string>
</test>
<edit mode="assign" name="family" >
<string>sans-serif</string>
</edit>
</match>
</fontconfig>
Example 2
This configuration [1] depends on the '-lcd' packages and was made by brebs. It has been lightly edited:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!-- Info:
xeffects thread: http://forums.gentoo.org/viewtopic-t-511382.html
http://antigrain.com/research/font_rasterization/index.html
http://fontconfig.org/fontconfig-user.html -->
<!-- http://bugs.gentoo.org/show_bug.cgi?id=130466 -->
<alias>
<family>serif</family>
<prefer>
<family>DejaVu Serif</family>
<family>Bitstream Vera Serif</family>
</prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer>
<family>DejaVu Sans</family>
<family>Bitstream Vera Sans</family>
<family>Verdana</family>
<family>Arial</family>
</prefer>
</alias>
<alias>
<family>monospace</family>
<prefer>
<family>DejaVu Sans Mono</family>
<family>Bitstream Vera Sans Mono</family>
</prefer>
</alias>
<!-- Reject bitmap fonts in favour of Truetype, Postscript, etc. -->
<selectfont>
<rejectfont>
<pattern>
<patelt name="scalable">
<bool>false</bool>
</patelt>
</pattern>
</rejectfont>
</selectfont>
<!-- Replace Luxi Sans with a better-looking font - looks terrible at e.g. http://market-ticker.org/ -->
<match name="family" target="pattern">
<test name="family" qual="any">
<string>Luxi Sans</string>
</test>
<edit name="family" mode="assign">
<string>Liberation Sans</string>
</edit>
</match>
<match target="pattern" name="family">
<test qual="any" name="family"><string>fixed</string></test>
<edit name="family" mode="assign"><string>monospace</string></edit>
</match>
<!-- Ubuntu options: lcdnone, lcddefault, lcdlight, lcdlegacy -->
<!-- Blurry fonts: Try rgb, bgr, vrgb, vbgr for "rgba" -->
<!-- Blurry: http://forums.gentoo.org/viewtopic-p-5060979.html#5060979 -->
<match target="font">
<edit name="rgba" mode="assign"><const>rgb</const></edit>
<edit name="lcdfilter" mode="assign"><const>lcddefault</const></edit>
<!-- To fix Calibri font - http://forums.fedoraforum.org/showthread.php?p=1045807#post1045807 -->
<edit name="embeddedbitmap" mode="assign"><bool>false</bool></edit>
</match>
<!-- Tweak Courier -->
<match name="family" target="pattern">
<test name="family" qual="any">
<string>Courier</string>
</test>
<edit name="lcdfilter" mode="assign"><const>lcdlegacy</const></edit>
</match>
<!-- Tweak Courier New -->
<match name="family" target="pattern">
<test name="family" qual="any">
<string>Courier New</string>
</test>
<edit name="lcdfilter" mode="assign"><const>lcdlegacy</const></edit>
</match>
<!-- From http://forums.gentoo.org/viewtopic-t-511382-start-650.html
To create difference between small Candara and small Candara bold -->
<match name="family" target="pattern">
<test name="family" qual="any">
<string>Candara</string>
</test>
<test compare="less_eq" name="size">
<double>10</double>
</test>
<test name="weight" compare="more">
<const>medium</const>
</test>
<edit name="embolden" mode="assign">
<bool>true</bool>
</edit>
</match>
<!-- From http://bugs.gentoo.org/show_bug.cgi?id=233729 -->
<match target="font">
<test compare="eq" name="family">
<string>Andale Mono</string>
</test>
<test compare="less" name="weight">
<const>medium</const>
</test>
<test compare="less_eq" name="pixelsize">
<double>7</double>
</test>
<edit mode="assign" name="antialias">
<bool>false</bool>
</edit>
</match>
<match target="font">
<test compare="eq" name="family">
<string>Arial</string>
</test>
<test compare="less" name="weight">
<const>medium</const>
</test>
<test compare="less_eq" name="pixelsize">
<double>7</double>
</test>
<edit mode="assign" name="antialias">
<bool>false</bool>
</edit>
</match>
<match target="font">
<test compare="eq" name="family">
<string>Comic Sans MS</string>
</test>
<test compare="less" name="weight">
<const>medium</const>
</test>
<test compare="less_eq" name="pixelsize">
<double>7</double>
</test>
<edit mode="assign" name="antialias">
<bool>false</bool>
</edit>
</match>
<match target="font">
<test compare="eq" name="family">
<string>Georgia</string>
</test>
<test compare="less" name="weight">
<const>medium</const>
</test>
<test compare="less_eq" name="pixelsize">
<double>7</double>
</test>
<edit mode="assign" name="antialias">
<bool>false</bool>
</edit>
</match>
<match target="font">
<test compare="eq" name="family">
<string>Times New Roman</string>
</test>
<!-- Looks better with lcdlegacy, e.g. http://www.billiardworld.com/glossary.html -->
<edit name="lcdfilter" mode="assign"><const>lcdlegacy</const></edit>
</match>
<match target="font">
<test compare="eq" name="family">
<string>Trebuchet MS</string>
</test>
<test compare="less" name="weight">
<const>medium</const>
</test>
<test compare="less_eq" name="pixelsize">
<double>7</double>
</test>
<edit mode="assign" name="antialias">
<bool>false</bool>
</edit>
</match>
<match target="font">
<test compare="eq" name="family">
<string>Verdana</string>
</test>
<test compare="less" name="weight">
<const>medium</const>
</test>
<test compare="less_eq" name="pixelsize">
<double>7</double>
</test>
<edit mode="assign" name="antialias">
<bool>false</bool>
</edit>
</match>
</fontconfig>
Troubleshooting
Distorted fonts
Main article: Xorg#Display size and DPI
Fontconfig should be able to detect DPI parameters as discovered by the Xorg server and be able to display the fonts correctly. Those having problems can still fall back to setting it manually:
... <match target="pattern"> <edit name="dpi" mode="assign"><double>96</double></edit> </match> ...
If fonts are still unexpectedly large or small, or are poorly proportioned, the Xorg server may be incorrectly detecting the DPI setting.
Missing characters
If using Emacs, the xorg-fonts-75dpi and xorg-fonts-100dpi packages need to be installed.
Older GTK and QT applications
Modern GTK apps enable Xft by default but this was not the case before version 2.2. If it is not possible to update these applications, force Xft for old GNOME applications by adding to ~/.bashrc:
export GDK_USE_XFT=1
For older QT applications:
export QT_XFT=true
Resources
- Fonts in X11R6.8.2 - Official Xorg font information
- FreeType 2 Overview
- Optimal Use of Fonts on Linux