Difference between revisions of "Font configuration"

From ArchWiki
Jump to navigation Jump to search
(Distorted fonts)
m (Applications without fontconfig support: I think that was intended.)
 
(433 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
[[Category:X Server (English)]]
+
[[Category:Fonts]]
[[Category:Fonts (English)]]
+
[[es:Font configuration]]
[[Category:HOWTOs (English)]]
+
[[it:Font configuration]]
{{i18n|Font Configuration}}
+
[[ja:フォント設定]]
{{Article summary start}}
+
[[ru:Font configuration]]
{{Article summary text|An overview of font configuration options and various techniques for improving the readability of fonts}}
+
[[sr:Font configuration]]
{{Article summary heading|Related}}
+
[[zh-hans:Font configuration]]
{{Article summary wiki|Fonts}}: Information on adding fonts and font recommendations
+
{{Related articles start}}
{{Article summary wiki|Java Fonts - Sun JRE}}: Fonts specific to Sun's Java machine
+
{{Related|Font configuration/Examples}}
{{Article summary wiki|MS Fonts}}: Adding Microsoft fonts and mimicking Windows' font settings
+
{{Related|Fonts}}
{{Article summary end}}
+
{{Related|Metric-compatible fonts}}
 +
{{Related|Microsoft fonts}}
 +
{{Related|Java Runtime Environment fonts}}
 +
{{Related|X Logical Font Description}}
 +
{{Related articles end}}
  
==Font paths==
+
[http://www.freedesktop.org/wiki/Software/fontconfig/ Fontconfig] is a library designed to provide a list of available [[fonts]] to applications, and also for configuration for how fonts get rendered. The FreeType library renders the fonts, based on this configuration. The ''freetype2'' font rendering packages on Arch Linux include the bytecode interpreter (BCI) enabled for better font rendering especially with an LCD monitor. See [[#Fontconfig configuration]] and [[Font configuration/Examples]].
  
For [[fonts]] to be known to applications, they must be cataloged for easy and quick access.  [[Wikipedia:Fontconfig|Fontconfig]] is a library designed to provide a list of available fonts to applications, and also for configuration for how fonts get rendered.  Though fontconfig is the standard in today's Linux, some applications still rely on the original method of font categorization: the Xorg server configuration.
+
Though Fontconfig is used often in modern Unix and Unix-like operating systems, some applications rely on the original method of font selection and display, the [[X Logical Font Description]].
  
===Fontconfig===
+
== Font paths ==
  
Fontconfig gathers all its configurations in a central file ({{Filename|/etc/fonts/fonts.conf}}).  Fontconfig-aware applications source this file to know available fonts and how they get rendered.  This file is a conglomeration of rules from the various fontconfig configurations (the global configuration ({{Filename|/etc/fonts/local.conf}}), the configured presets in {{Filename|/etc/fonts/conf.d/}}, and the user configuration file ({{Filename|~/.fonts.conf}}).
+
For fonts to be known to applications, they must be cataloged for easy and quick access.
  
The font paths initially known to fontconfig are: {{Filename|/usr/share/fonts/}} and {{Filename|~/.fonts/}} (of which fontconfig will scan recursively). For ease of organization and installation, it is recommended to use these font paths when [[Fonts|installing new fonts]].
+
The font paths initially known to Fontconfig are: {{ic|/usr/share/fonts/}}, {{ic|~/.local/share/fonts}} (and {{ic|~/.fonts/}}, now deprecated). Fontconfig will scan these directories recursively. For ease of organization and installation, it is recommended to use these font paths when [[adding fonts]].
  
To see a list of known fontconfig fonts in an easy to read format:
+
To see a list of known Fontconfig fonts:
  
  $ fc-list | sed 's,:.*,,' | sort -u
+
  $ fc-list : file
  
===Xorg===
+
See {{man|1|fc-list}} for more output formats.
  
 
Check for Xorg's known font paths by reviewing its log:
 
Check for Xorg's known font paths by reviewing its log:
  
  $ grep /fonts /var/log/Xorg.0.log
+
  $ grep /fonts ~/.local/share/xorg/Xorg.0.log
  
Keep in mind that Xorg does not search recursively through the {{Filename|/usr/share/fonts}} directory like fontconfig does. To add a path, the full path must be used:
+
{{Tip|
 +
* You can also check the list of [[Xorg]]'s known font paths using the command {{ic|xset q}}.
 +
* Use {{ic|/var/log/Xorg.0.log}} if Xorg is run with root privileges.
 +
}}
  
<pre>
+
Keep in mind that Xorg does not search recursively through the {{ic|/usr/share/fonts/}} directory like Fontconfig does.  To add a path, the full path must be used:
Section "Files"
 
    FontPath    "/usr/share/fonts/example-font-directory"
 
EndSection
 
</pre>
 
  
To see a list of known Xorg fonts use {{Codeline|xlsfonts}}.
+
Section "Files"
 +
    FontPath    "/usr/share/fonts/local/"
 +
EndSection
  
==Fontconfig configuration==
+
If you want font paths to be set on a per-user basis, you can add and remove font paths from the default by adding the following line(s) to {{ic|~/.xinitrc}}:
  
The font rendering packages on Arch Linux includes support for ''freetype2'' with the bytecode interpreter (BCI) enabled.  However, defining your own font configuration may at times be necessary. Consider using [[#Patched_packages|patched packages]] for better font rendering, especially with an LCD monitor.
+
xset +fp /usr/share/fonts/local/          # Prepend a custom font path to Xorg's list of known font paths
 +
  xset -fp /usr/share/fonts/sucky_fonts/    # Remove the specified font path from Xorg's list of known font paths
  
Configuration can be done either per-user through {{Filename|~/.fonts.conf}}, or globally with {{Filename|/etc/fonts/local.conf}}.  The settings in the per-user configuration have precedence over the global configuration.  Both these files use the same syntax.  Remember not to edit the {{filename|/etc/fonts/fonts.conf}} file; it is a temporary file and shouldn't be edited since it's replaced during fontconfig updates.
+
To see a list of known Xorg fonts use {{ic|xlsfonts}}, from the {{Pkg|xorg-xlsfonts}} package.
  
There are already a number of configured presets in the directory {{Filename|/etc/fonts/conf.avail}}.  These presets can be linked to both per-user and globally for quicker configuration.  Take note that these presets will override matching settings in their respective configuration files.
+
== Fontconfig configuration ==
  
For example, to enable sub-pixel RGB rendering globally:
+
Fontconfig is documented in the {{man|5|fonts-conf}} man page.
 
 
# cd /etc/fonts/conf.d
 
# ln -s ../conf.avail/10-sub-pixel-rgb.conf
 
  
To do the same but instead for a per-user configuration:
+
Configuration can be done per-user through {{ic|$XDG_CONFIG_HOME/fontconfig/fonts.conf}}, and globally with {{ic|/etc/fonts/local.conf}}.  The settings in the per-user configuration have precedence over the global configuration.  Both these files use the same syntax.
 +
{{Note|Configuration files and directories: {{ic|~/.fonts.conf/}}, {{ic|~/.fonts.conf.d/}} and {{ic|~/.fontconfig/*.cache-*}} are deprecated since {{Pkg|fontconfig}} 2.10.1 ([http://cgit.freedesktop.org/fontconfig/commit/?id&#61;8c255fb185d5651b57380b0a9443001e8051b29d upstream commit]) and will not be read by default in the future versions of the package. New paths are {{ic|$XDG_CONFIG_HOME/fontconfig/fonts.conf}}, {{ic|$XDG_CONFIG_HOME/fontconfig/conf.d/NN-name.conf}} and {{ic|$XDG_CACHE_HOME/fontconfig/*.cache-*}} respectively. If using the second location, make sure the naming is valid (where {{ic|NN}} is a two digit number like {{ic|00}}, {{ic|10}}, or {{ic|99}}).}}
  
$ mkdir ~/.fonts.conf.d
+
Fontconfig gathers all its configurations in a central file ({{ic|/etc/fonts/fonts.conf}}).  This file is replaced during fontconfig updates and should not be editedFontconfig-aware applications source this file to know available fonts and how they get rendered; simply restarting such applications is sufficient to load the new configuration.  This file is a conglomeration of rules from the global configuration ({{ic|/etc/fonts/local.conf}}), the configured presets in {{ic|/etc/fonts/conf.d/}}, and the user configuration file ({{ic|$XDG_CONFIG_HOME/fontconfig/fonts.conf}}). {{ic|fc-cache}} can be used to rebuild fontconfig's configuration, although changes will only be visible in newly launched applications.
  $ ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf ~/.fonts.conf.d
 
  
{{Note|For some desktop environments (such as [[Gnome]] and [[KDE]]) using the ''Font Control Panel'' will automatically create or overwrite the user font configuration file.  For these desktop environments, it is best to match your already defined font configurations to get the expected behavior.}}
+
{{Note|For some desktop environments (such as [[GNOME]] and [[KDE]]) using the ''Font Control Panel'' will automatically create or overwrite the user font configuration file.  For these desktop environments, it is best to match your already defined font configurations to get the expected behavior. Also ensure that the desktop [[locale]] settings or ''Regional Settings'' are supported by the configured fonts, if not the font configuration could be overidden.}}
  
The configuration files will need informational headers before settings can be entered:
+
Fontconfig configuration files use [[Wikipedia:XML|XML]] format and need these headers:
  
<pre>
+
{{bc|<nowiki>
 
<?xml version="1.0"?>
 
<?xml version="1.0"?>
 
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
Line 71: Line 74:
  
 
</fontconfig>
 
</fontconfig>
</pre>
+
</nowiki>}}
 +
 
 +
The configuration examples in this article omit these tags.
 +
 
 +
=== Presets ===
 +
 
 +
There are presets installed in the directory {{ic|/etc/fonts/conf.avail}}.  They can be enabled by creating [[Wikipedia:Symbolic link|symbolic link]]s to them, both per-user and globally, as described in {{ic|/etc/fonts/conf.d/README}}.  These presets will override matching settings in their respective configuration files.
 +
 
 +
For example, to enable sub-pixel RGB rendering globally:
 +
 
 +
# cd /etc/fonts/conf.d
 +
# ln -s ../conf.avail/10-sub-pixel-rgb.conf
 +
 
 +
To do the same but instead for a per-user configuration:
  
To avoid repetition, the rest of the configuration examples in this article will omit these tags.
+
$ mkdir $XDG_CONFIG_HOME/fontconfig/conf.d
 +
$ ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf $XDG_CONFIG_HOME/fontconfig/conf.d
  
===Anti-aliasing===
+
=== Anti-aliasing ===
  
[[Wikipedia:Font rasterization|Font rasterization]] converts vector font data to bitmap data so that it can be displayed. The result will appear jagged due to [[Wikipedia:Aliasing|aliasing]], so [[Wikipedia:Anti-aliasing|anti-aliasing]] is enabled by default to increase the apparent resolution of font edges.
+
[[Wikipedia:Font rasterization|Font rasterization]] converts vector font data to bitmap data so that it can be displayed. The result can appear jagged due to [[Wikipedia:Aliasing|aliasing]]. The technique known as [[Wikipedia:Anti-aliasing|anti-aliasing]] can be used to increase the apparent resolution of font edges. Anti-aliasing is '''enabled''' by default. To disable it:
  
<pre>
+
{{bc|<nowiki>
 
   <match target="font">
 
   <match target="font">
 
     <edit name="antialias" mode="assign">
 
     <edit name="antialias" mode="assign">
       <bool>true</bool>
+
       <bool>false</bool>
 
     </edit>
 
     </edit>
 
   </match>
 
   </match>
</pre>
+
</nowiki>}}
 +
 
 +
{{Note|Some applications, like [[GNOME]] may [[#Troubleshooting|override default anti-aliasing settings]].}}
  
===Hinting===
+
=== Hinting ===
  
[[Wikipedia:Font hinting|Font hinting]] (also known as instructing) is the use of mathematical instructions to adjust the display of an outline font so that it lines up with a rasterized grid, such as the pixel grid in a display. Fonts will not line up correctly without hinting until displays have 300 [[Wikipedia:Dots Per Inch|DPI]] or greater. Two types of hinting are available.
+
[[Wikipedia:Font hinting|Font hinting]] (also known as instructing) is the use of mathematical instructions to adjust the display of an outline font so that it lines up with a rasterized grid (i.e. the pixel grid of the display). Its intended effect is to make fonts appear more crisp so that they are more readable. Fonts will line up correctly without hinting when displays have around 300 [[Wikipedia:Dots per inch|DPI]].
  
====Byte-Code Interpreter (BCI)====
+
==== Byte-Code Interpreter (BCI) ====
Using normal hinting, TrueType hinting instructions in the font are interpreted by freetype's Byte-Code Interpreter. This works best for fonts with good hinting instructions.
 
  
To enable normal hinting:
+
Using BCI hinting, instructions in TrueType fonts are rendered according to FreeTypes's interpreter. BCI hinting works well with fonts with good hinting instructions. Hinting is '''enabled''' by default. To disable it:
  
<pre>
+
{{bc|<nowiki>
 
   <match target="font">
 
   <match target="font">
 
     <edit name="hinting" mode="assign">
 
     <edit name="hinting" mode="assign">
       <bool>true</bool>
+
       <bool>false</bool>
 
     </edit>
 
     </edit>
 
   </match>
 
   </match>
</pre>
+
</nowiki>}}
 +
 
 +
{{Note|1=You can switch BCI implementations by editing {{ic|/etc/profile.d/freetype2.sh}} which includes a brief documentation. Most popular values are {{ic|1=truetype:interpreter-version=35}} (classic mode, emulates Windows 98; 2.6 default), {{ic|1=truetype:interpreter-version=38}} ("Infinality" subpixel mode), {{ic|1=truetype:interpreter-version=40}} (minimal subpixel mode; 2.7 default). If you prefer classic Windows ClearType style you can use {{ic|1=truetype:interpreter-version=36}}. Subpixel rendering should use a subpixel BCI. For details, see [https://www.freetype.org/freetype2/docs/reference/ft2-properties.html#tt_interpreter_version_xxx].}}
  
====Autohinter====
+
==== Autohinter ====
Auto-discovery for hinting. This looks worse than normal hinting for fonts with good instructions, but better for those with poor or no instructions.
 
  
To enable auto-hinting:
+
The autohinter attempts to do automatic hinting and disregards any existing hinting information. Originally it was the default because TrueType2 fonts were patent-protected but now that these patents have expired there is very little reason to use it. It does work better with fonts that have broken or no hinting information but it will be strongly sub-optimal for fonts with good hinting information. Generally common fonts are of the later kind so autohinter will not be useful. Autohinter is '''disabled''' by default. To enable it:
  
<pre>
+
{{bc|<nowiki>
 
   <match target="font">
 
   <match target="font">
 
     <edit name="autohint" mode="assign">
 
     <edit name="autohint" mode="assign">
Line 115: Line 134:
 
     </edit>
 
     </edit>
 
   </match>
 
   </match>
</pre>
+
</nowiki>}}
  
{{Note|Do not use the autohinter with subpixel rendering. The two are not designed to work together. The [[#Infinality|Infinality]] package fixes this.}}
+
==== Hintstyle ====
  
====Hint style====
+
Hintstyle is the amount of font reshaping done to line up to the grid. Hinting values are: {{ic|hintnone}}, {{ic|hintslight}}, {{ic|hintmedium}}, and {{ic|hintfull}}. {{ic|hintslight}} will make the font more fuzzy to line up to the grid but will be better in retaining font shape (see [https://www.freetype.org/freetype2/docs/text-rendering-general.html]), while {{ic|hintfull}} will be a crisp font that aligns well to the pixel grid but will lose a greater amount of font shape. {{ic|hintslight}} implicitly uses the autohinter in a vertical-only mode in favor of font-native information for non-CFF (''.otf'') fonts.
  
Hint style is the amount of influence the '''hinting''' mode has.  Hinting can be set to: {{Codeline|hintfull}}, {{Codeline|hintmedium}}, {{Codeline|hintslight}} and {{Codeline|hintnone}}. With BCI hinting, hintfull should work best for most fonts. With the autohinter, hintslight is recommended.
+
{{ic|hintslight}} is the default setting. To change it:
  
<pre>
+
{{bc|<nowiki>
 
   <match target="font">
 
   <match target="font">
 
     <edit name="hintstyle" mode="assign">
 
     <edit name="hintstyle" mode="assign">
       <const>hintfull</const>
+
       <const>hintnone</const>
 
     </edit>
 
     </edit>
 
   </match>
 
   </match>
</pre>
+
</nowiki>}}
  
===Subpixel rendering===
+
{{Note|Some applications, like [[GNOME]] may [[#Troubleshooting|override default hinting settings.]]}}
  
Subpixel rendering effectively triples the horizontal (or vertical) resolution for fonts by making use of subpixels.
+
=== Pixel alignment ===
  
Most monitors manufactured today use the Red, Green, Blue (RGB) specification. Fontconfig will need to know your monitor type to be able to display your fonts correctly.
+
Most monitors manufactured today use the Red, Green, Blue (RGB) specification. Fontconfig will need to know your monitor type to be able to display your fonts correctly.  Monitors are either: '''RGB''' (most common), '''BGR''', '''V-RGB''' (vertical), or '''V-BGR'''.  A monitor test can be found [http://www.lagom.nl/lcd-test/subpixel.php here].
  
''RGB (most common), BGR, V-RGB (vertical), or V-BGR''
+
{{bc|<nowiki>
 
 
To enable subpixel rendering:
 
 
 
<pre>
 
 
   <match target="font">
 
   <match target="font">
 
     <edit name="rgba" mode="assign">
 
     <edit name="rgba" mode="assign">
Line 147: Line 162:
 
     </edit>
 
     </edit>
 
   </match>
 
   </match>
</pre>
+
</nowiki>}}
  
If you notice unusual colors around font's borders, discover you monitor type [http://www.lagom.nl/lcd-test/subpixel.php here].
+
{{Note|Without subpixel rendering (see below), freetype will only care about the alignment (vertical or horizontal) of the subpixels. There is no difference between '''RGB''' and '''BGR''', for example.}}
  
{{Note|Do not use the autohinter with subpixel rendering. The two are not designed to work together. The [[#Infinality|Infinality]] package fixes this.}}
+
=== Subpixel rendering ===
  
====LCD filter====
+
[[wikipedia:Subpixel_rendering|Subpixel rendering]] is a technique to improve sharpness of font rendering by effectively tripling the horizontal (or vertical) resolution through the use of subpixels. On Windows machines, this technique is called "ClearType".
  
When using subpixel rendering, you should enable the lcd filter.
+
FreeType implements its own LCD-optimized rendering called [http://lists.gnu.org/archive/html/freetype-commit/2017-03/msg00012.html Harmony]. With this FreeType LCD rendering technology, the resulting output does not require additional LCD filtering, unlike Microsoft's patented Cleartype subpixel rendering where an LCD filter is recommended. See section below on how to enable LCD filter and its benefits.
  
The {{Codeline|lcddefault}} filter will work for most users. Other filters are available that can be used in special situations: {{Codeline|lcdlight}}; a lighter filter ideal for fonts that look too bold or fuzzy, {{Codeline|lcdlegacy}}, the original Cairo filter; and {{Codeline|lcdnone}} to disable it entirely.
+
Cleartype subpixel rendering is covered by Microsoft patents and '''disabled''' by default on Arch Linux. To enable it, you have to re-compile {{pkg|freetype2}} and define the {{ic|FT_CONFIG_OPTION_SUBPIXEL_RENDERING}} macro, or use e.g. the AUR package {{AUR|freetype2-cleartype}}.
  
<pre>
+
==== LCD filter ====
 +
 
 +
When using Cleartype subpixel rendering, you should enable the LCD filter, which is designed to reduce colour fringing.  This is described under [https://www.freetype.org/freetype2/docs/reference/ft2-lcd_rendering.html LCD filtering] in the FreeType 2 API reference.  Different options are described under [https://www.freetype.org/freetype2/docs/reference/ft2-lcd_rendering.html#ft_lcdfilter FT_LcdFilter], and are illustrated by this [http://www.spasche.net/files/lcdfiltering/ LCD filter test] page.
 +
 
 +
The {{ic|lcddefault}} filter will work for most users. Other filters are available that can be used in special situations: {{ic|lcdlight}}; a lighter filter ideal for fonts that look too bold or fuzzy, {{ic|lcdlegacy}}, the original Cairo filter; and {{ic|lcdnone}} to disable it entirely.
 +
 
 +
{{bc|<nowiki>
 
   <match target="font">
 
   <match target="font">
     <edit mode="assign" name="lcdfilter">
+
     <edit name="lcdfilter" mode="assign">
 
       <const>lcddefault</const>
 
       <const>lcddefault</const>
 
     </edit>
 
     </edit>
 
   </match>
 
   </match>
</pre>
+
</nowiki>}}
  
====Advanced LCD filter specification====
+
==== Advanced LCD filter specification ====
  
If the available, built-in LCD filters are not satisfactory, it is possible to tweak the font rendering very specifically by building a custom freetype2 package and modifying the hardcoded filters. If you don't know how to build and install packages from source, get acquainted with [[ABS]] first.
+
If the available built-in LCD filters are not satisfactory, it is possible to tweak the font rendering very specifically by building a custom freetype2 package and modifying the hardcoded filters. The [[Arch Build System]] can be used to build and install packages from source. This requires installation of the {{Pkg|asp}} package.
  
{{Note|The [[#Infinality|Infinality]] package allows you to tweak the filter setting with an environment variable, without recompiling.}}
+
Checkout the {{Pkg|freetype2}} PKGBUILD and download/extract the build files:
  
First, refresh the freetype2 PKGBUILD as root:
+
$ asp checkout freetype2
 
+
  $ cd freetype2/trunk
  # abs extra/freetype2
+
$ makepkg -o
 
 
This example uses {{Filename|/var/abs/build}} as the build directory, substitute it according to your personal ABS setup. Download and extract the freetype2 package as a regular user:
 
  
$ cd /var/abs/build
+
Enable subpixel rendering by editing the file {{ic|src/freetype-VERSION/include/freetype/config/ftoption.h}} and uncommenting the {{ic|FT_CONFIG_OPTION_SUBPIXEL_RENDERING}} macro.
$ cp -r ../extra/freetype2 .
 
$ cd freetype2
 
$ makepkg -o
 
  
Edit the file {{Filename|src/freetype-VERSION/src/base/ftlcdfil.c}} and look up the definition of the constant {{Filename|default_filter[5]}}:
+
Then, edit the file {{ic|src/freetype-VERSION/src/base/ftlcdfil.c}} and look up the definition of the constant {{ic|default_filter[5]}}:
  
 
  static const FT_Byte  default_filter[5] =
 
  static const FT_Byte  default_filter[5] =
 
     { 0x10, 0x40, 0x70, 0x40, 0x10 };
 
     { 0x10, 0x40, 0x70, 0x40, 0x10 };
  
This constant defines a low-pass filter applied to the rendered glyph. Modify it as needed. Save the file, build and install the custom package:
+
This constant defines a low-pass filter applied to the rendered glyph. Modify it as needed. (reference: [https://lists.nongnu.org/archive/html/freetype/2006-09/msg00069.html freetype list discussion]) Save the file, build and install the custom package:
  
 
  $ makepkg -e
 
  $ makepkg -e
  $ sudo pacman -Rd freetype2
+
  # pacman -Rd freetype2
  $ sudo pacman -U freetype2-VERSION-ARCH.pkg.tar.xz
+
  # pacman -U freetype2-VERSION-ARCH.pkg.tar.xz
  
 
Reboot or restart X. The lcddefault filter should now render fonts differently.
 
Reboot or restart X. The lcddefault filter should now render fonts differently.
  
===Disable auto-hinter for bold fonts===
+
=== Custom settings for certain fonts or font styles ===
  
 
The auto-hinter uses sophisticated methods for font rendering, but often makes bold fonts too wide. Fortunately, a solution can be turning off the autohinter for bold fonts while leaving it on for the rest:
 
The auto-hinter uses sophisticated methods for font rendering, but often makes bold fonts too wide. Fortunately, a solution can be turning off the autohinter for bold fonts while leaving it on for the rest:
 +
 
  ...
 
  ...
 
  <match target="font">
 
  <match target="font">
Line 211: Line 228:
 
  ...
 
  ...
  
{{Note|The [[#Infinality|Infinality]] package allows the autohinter to work well with bold fonts.}}
+
Some fonts may not look good with BCI hinting. It can be disabled for just those fonts:
  
=== Enable anti-aliasing only for bigger fonts ===
+
...
 +
<match target="font">
 +
    <test name="family" qual="any">
 +
        <string>My Font</string>
 +
    </test>
 +
    <edit name="hinting" mode="assign">
 +
        <bool>false</bool>
 +
    </edit>
 +
</match>
 +
...
  
''See also [http://sharpfonts.co.cc/ sharpfonts.co.cc] for related information''
+
=== Replace or set default fonts ===
  
Some users prefer the sharper rendering that anti-aliasing doesn't offer:
+
The most reliable way to do this is to add an XML fragment similar to the one below. ''Using the "binding" attribute will give you better results'', for example, in Firefox where you may not want to change properties of font being replaced. This will cause Ubuntu to be used in place of Georgia:
  
<pre>
+
{{bc|<nowiki>
 +
...
 +
<match target="pattern">
 +
  <test qual="any" name="family"><string>georgia</string></test>
 +
  <edit name="family" mode="assign" binding="same"><string>Ubuntu</string></edit>
 +
</match>
 
...
 
...
<match target="font">
+
</nowiki>}}
    <edit name="antialias" mode="assign">
 
        <bool>false</bool>
 
    </edit>
 
</match>
 
  
<match target="font" >
+
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:
    <test name="size" qual="any" compare="more">
 
        <double>12</double>
 
    </test>
 
    <edit name="antialias" mode="assign">
 
        <bool>true</bool>
 
    </edit>
 
</match>
 
  
<match target="font" >
+
{{bc|<nowiki>
    <test name="pixelsize" qual="any" compare="more">
+
...
        <double>17</double>
+
<!-- Replace Helvetica with Bitstream Vera Sans Mono -->
     </test>
+
<!-- Note, an alias for Helvetica should already exist in default conf files -->
     <edit name="antialias" mode="assign">
+
<alias>
        <bool>true</bool>
+
     <family>Helvetica</family>
     </edit>
+
     <prefer><family>Bitstream Vera Sans Mono</family></prefer>
</match>
+
     <default><family>fixed</family></default>
 +
</alias>
 
...
 
...
</pre>
+
</nowiki>}}
  
===Replace fonts===
+
=== Whitelisting and blacklisting 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:
+
The element {{ic|<selectfont>}} is used in conjunction with the {{ic|<acceptfont>}} and {{ic|<rejectfont>}} elements to selectively whitelist or blacklist fonts from the resolve list and match requests. The simplest and most typical use case it to reject one font that is needed to be installed, however is getting matched for a generic font query that is causing problems within application user interfaces.
...
+
 
<match target="pattern" name="family" >
+
First obtain the Family name as listed in the font itself:
    <test name="family" qual="any" >
+
 
        <string>Helvetica</string>
+
{{hc|1=$ fc-scan .fonts/lklug.ttf --format='%{family}\n'|2=
    </test>
+
LKLUG
    <edit name="family" mode="assign">
+
}}
        <string>Bitstream Vera Sans</string>
+
 
    </edit>
+
Then use that Family name in a {{ic|<rejectfont>}} stanza:
</match>
+
 
...
+
{{bc|<nowiki>
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:
+
<selectfont>
...
+
    <rejectfont>
< !-- Replace Helvetica with Bitstream Vera Sans Mono -->
+
        <pattern>
< !-- Note, an alias for Helvetica should already exist in default conf files -->
+
            <patelt name="family" >
<alias>
+
                <string>LKLUG</string>
    <family>Helvetica</family>
+
            </patelt>
    <prefer><family>Bitstream Vera Sans Mono</family></prefer>
+
        </pattern>
    <default><family>fixed</family></default>
+
    </rejectfont>
</alias>
+
</selectfont>
...
+
</nowiki>}}
 +
 
 +
Typically when both elements are combined, {{ic|<rejectfont>}} is first used on a more general matching glob to reject a large group (such as a whole directory), then {{ic|<acceptfont>}} is used after it to whitelist individual fonts out of the larger blacklisted group.
 +
 
 +
{{bc|<nowiki>
 +
<selectfont>
 +
    <rejectfont>
 +
        <glob>/usr/share/fonts/OTF/*</glob>
 +
    </rejectfont>
 +
    <acceptfont>
 +
        <pattern>
 +
            <patelt name="family" >
 +
                <string>Monaco</string>
 +
            </patelt>
 +
        </pattern>
 +
    </acceptfont>
 +
</selectfont>
 +
</nowiki>}}
 +
 
 +
=== Disable bitmap fonts ===
 +
 
 +
Bitmap fonts are sometimes used as fallbacks for missing fonts, which may cause text to be rendered pixelated or too large. Use the {{ic|70-no-bitmaps.conf}} [[#Presets|preset]] to disable this behavior.  
 +
 
 +
To disable embedded bitmap for all fonts:
  
===Disable bitmap fonts===
+
{{hc|~/.config/fontconfig/conf.d/20-no-embedded.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>
 +
</fontconfig>
 +
</nowiki>}}
  
To disable bitmap fonts in fontconfig, use {{filename|70-no-bitmaps.conf}} (which is not placed by fontconfig by default):
+
To disable embedded bitmap fonts for a specific font:
  
  # cd /etc/fonts/conf.d
+
  <match target="font">
# rm 70-yes-bitmaps.conf
+
  <test qual="any" name="family">
  # ln -s ../conf.avail/70-no-bitmaps.conf
+
    <string>Monaco</string>
 +
  </test>
 +
  <edit name="embeddedbitmap">
 +
    <bool>false</bool>
 +
  </edit>
 +
  </match>
  
You can choose which fonts to replace bitmaps fonts with (Helvetica, Courier and Times bitmap mapts to TTF fonts) by:
+
=== Disable scaling of bitmap fonts ===
  
# cd /etc/fonts/conf.d
+
To disable scaling of bitmap fonts (which often makes them blurry), remove {{ic|/etc/fonts/conf.d/10-scale-bitmap-fonts.conf}}.
# ln -s ../conf.avail/29-replace-bitmap-fonts.conf
 
  
===Create bold and italic styles for incomplete fonts===
+
=== 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.
+
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 {{Filename|/usr/share/fonts/fonts.cache-1}} as explained below. Store a copy of the modifications on another file, because a font update with {{Codeline|fc-cache}} will overwrite {{Filename|/usr/share/fonts/fonts.cache-1}}.
+
Start by editing {{ic|/usr/share/fonts/fonts.cache-1}} as explained below. Store a copy of the modifications on another file, because a font update with {{ic|fc-cache}} will overwrite {{ic|/usr/share/fonts/fonts.cache-1}}.
  
 
Assuming the Dupree font is installed:
 
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...''
 
  "dupree.ttf" 0 "Dupree:style=Regular:slant=0:weight=80:width=100:foundry=unknown:index=0:outline=True:''etc...''
  
Duplicate the line, change {{Codeline|<nowiki>style=Regular</nowiki>}} to {{Codeline|<nowiki>style=Bold</nowiki>}} or any other style. Also change {{Codeline|<nowiki>slant=0</nowiki>}} to {{Codeline|<nowiki>slant=100</nowiki>}} for italic, {{Codeline|<nowiki>weight=80</nowiki>}} to {{Codeline|<nowiki>weight=200</nowiki>}} for bold, or combine them for '''''bold italic''''':
+
Duplicate the line, change {{ic|1=style=Regular}} to {{ic|1=style=Bold}} or any other style. Also change {{ic|1=slant=0}} to {{ic|1=slant=100}} for italic, {{ic|1=weight=80}} to {{ic|1=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...''
 
  "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 {{Filename|~/.fonts.conf}}:
+
Now add necessary modifications to {{ic|$XDG_CONFIG_HOME/fontconfig/fonts.conf}}:
<pre>
+
 
 +
{{bc|<nowiki>
 
...
 
...
 
<match target="font">
 
<match target="font">
Line 325: Line 386:
 
</match>
 
</match>
 
...
 
...
</pre>
+
</nowiki>}}
{{Tip| Use the value 'embolden' for existing bold fonts in order to make them even bolder.}}
+
 
 +
{{Tip| Use the value {{ic|embolden}} for existing bold fonts in order to make them even bolder.}}
 +
 
 +
=== Change rule overriding ===
  
===Change rule overriding===
+
{{Accuracy|{{ic|/etc/fonts/conf.d/50-user.conf}} will be created again when {{Pkg|fontconfig}} is updated.|Talk:Font configuration#Change Rule Overriding}}
  
Fontconfig processes files in {{Filename|/etc/fonts/conf.d}} in reverse numerical order. This enables rules or files to override one another, but often confuses users about what file gets parsed last.
+
Fontconfig processes files in {{ic|/etc/fonts/conf.d}} in numerical 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:
 
To guarantee that personal settings take precedence over any other rules, change their ordering:
 +
 
  # cd /etc/fonts/conf.d
 
  # cd /etc/fonts/conf.d
  # mv 50-user.conf 00-user.conf
+
  # mv 50-user.conf 99-user.conf
  
 
This change seems however to be unnecessary for the most of the cases, because a user is given enough control by default to set up own font preferences, hinting and antialiasing properties, alias new fonts to generic font families, etc.
 
This change seems however to be unnecessary for the most of the cases, because a user is given enough control by default to set up own font preferences, hinting and antialiasing properties, alias new fonts to generic font families, etc.
  
===Example fontconfig configurations===
+
=== Query the current settings ===
  
Example fontconfig configurations can be found on this [[Font_Configuration/fontconfig_Examples|page]].
+
To find out what settings are in effect, use {{ic|fc-match --verbose}}. eg.
  
==Patched packages==
+
{{hc|$ fc-match --verbose Sans|
 +
family: "DejaVu Sans"(s)
 +
hintstyle: 3(i)(s)
 +
hinting: True(s)
 +
...
 +
}}
  
These patched packages are available in the [[AUR]] and easily installable by using an [[AUR helper]]. A few considerations:
+
Look up the meaning of the numbers at {{man|5|fonts-conf}} Eg. 'hintstyle: 3' means 'hintfull'
  
* Configuration is usually necessary.
+
== Applications without fontconfig support ==
* The new font rendering will not kick in until applications restart.
 
  
===Original LCD packages===
+
Some applications like [[URxvt]] will ignore fontconfig settings. You can work around this by using {{ic|~/.Xresources}}, but it is not as flexible as fontconfig. Example (see [[#Fontconfig configuration]] for explanations of the options):
Cairo 1.10 in [extra] adds support for the LCD filter. See [[#LCD filter]]. You can install [http://aur.archlinux.org/packages.php?ID=16458 fontconfig-lcd] from the [[AUR]] to enable the {{Codeline|lcddefault}} filter automatically.
 
  
In order to get filtering with apps using libXft for font drawing, you need to install [http://aur.archlinux.org/packages.php?ID=37044 libxft-lcd] from the [[AUR]].
+
{{hc|~/.Xresources|<nowiki>
 +
Xft.autohint: 0
 +
Xft.lcdfilter: lcddefault
 +
Xft.hintstyle: hintslight
 +
Xft.hinting: 1
 +
Xft.antialias: 1
 +
Xft.rgba: rgb
 +
</nowiki>}}
  
===Ubuntu===
+
Make sure the settings are loaded properly when X starts with {{ic|xrdb -q}} (see [[X resources]] for more information).
  
Ubuntu uses the original LCD patched packages and adds extra configurations, and occasionally patches.
+
== Troubleshooting ==
  
Install the patched packages from the [[AUR]]. The package names are:
+
=== Distorted fonts ===
  
freetype2-ubuntu fontconfig-ubuntu libxft-ubuntu cairo-ubuntu
+
{{Note|96 DPI is not a standard. You should use your monitor's actual DPI to get proper font rendering, especially when using subpixel rendering.}}
  
===Cleartype===
+
If fonts are still unexpectedly large or small, poorly proportioned or simply rendering poorly, fontconfig may be using the incorrect DPI.
  
{{Note|The -cleartype packages are out of date. Consider using the newer freetype2-infinality package instead. You can set the FIR filter environment variable to match what the cleartype patches used to give.}}
+
Fontconfig should be able to detect DPI parameters as discovered by the Xorg server. You can check the automatically discovered DPI with {{ic|xdpyinfo}} (provided by the {{pkg|xorg-xdpyinfo}} package):
  
These packages attempted to emulate ClearType, a type of subpixel rendering and filtering that is used by Windows.
+
{{hc|$ xdpyinfo {{!}} grep dots|
 +
  resolution:    102x102 dots per inch
 +
}}
  
===Infinality===
+
If the DPI is detected incorrectly (usually due to an incorrect monitor [[Wikipedia:Extended Display Identification Data|EDID]]), you can specify it manually in the Xorg configuration, see [[Xorg#Display size and DPI]]. This is the recommended solution, but it may not work with buggy drivers.
  
*[http://www.infinality.net/blog/?p=67 Homepage].
+
Fontconfig will default to the Xft.dpi variable if it is set. Xft.dpi is usually set by desktop environments (usually to Xorg's DPI setting) or manually in {{ic|~/.Xdefaults}} or {{ic|~/.Xresources}}. Use xrdb to query for the value:
*[http://www.infinality.net/forum/ Forum].
 
  
The infinality patchset aims to greatly improve freetype2 font rendering. It adds multiple new capabilities, all of which are configurable via environment variables in {{Filename|/etc/profile.d/infinality-settings.sh}}.
+
{{hc|$ xrdb -query {{!}} grep dpi|
 +
Xft.dpi: 102
 +
}}
  
*'''Emboldening Enhancement''': Disables Y emboldening, producing a much nicer result on fonts without bold versions.  Works on native TT hinter and autohinter.
+
Those still having problems can fall back to manually setting the DPI used by fontconfig:
*'''Auto-Autohint''': Automatically forces autohint on fonts that contain no TT instructions.
 
*'''Autohint Enhancement''': Makes autohint snap horizontal stems to pixels.  Gives a result that appears like a well-hinted truetype font, but is 100% patent-free (as far as I know).
 
*'''Customized FIR Filter''': Select your own filter values at runtime.  Works on native TT hinter and autohinter.
 
*'''Stem Alignment''': Aligns bitmap glyphs to optimized pixel boundaries.  Works on native TT hinter and autohinter.
 
*'''Pseudo Gamma Correction''': Lighten and darken glyphs at a given value, below a given size.  Works on native TT hinter and autohinter.
 
*'''Embolden Thin Fonts''': Embolden thin or light fonts so that they are more visible.  Works on autohinter.
 
  
[http://aur.archlinux.org/packages.php?ID=38888 freetype2-infinality] can be installed from the [[AUR]].
+
...
 +
<!-- Setup for DPI=96 -->
 +
<match target="pattern">
 +
    <edit name="dpi" mode="assign"><double>102</double></edit>
 +
</match>
 +
...
  
Additionally, if you are using lib32-freetype2 from [multilib], replace it with [http://aur.archlinux.org/packages.php?ID=40264 lib32-freetype2-infinality] from the [[AUR]].
+
=== Calibri, Cambria, Monaco, etc. not rendering properly ===
  
In order to get filtering with apps using libXft for font drawing, you need to install [http://aur.archlinux.org/packages.php?ID=37044 libxft-lcd] from the [[AUR]].
+
Some scalable fonts have embedded bitmap versions which are rendered instead, mainly at smaller sizes. Using [[Metric-compatible fonts]] as replacements can improve the rendering in these cases.  
  
{{Note|The infinality package is designed to work with [http://www.infinality.net/files/local.conf this local.conf]. You will most likely want to make changes to the configuration before using it (it makes a lot of font replacements, and sets the preferred fonts to Arial, Times New Roman and Consolas.)}}
+
You can also force using scalable fonts at all sizes by [[#Disable bitmap fonts|disabling embedded bitmap]], sacrificing some rendering quality.
  
===Reverting to unpatched packages===
+
=== Applications overriding hinting ===
  
To restore the unpatched packages, reinstall the originals:
+
Some applications or desktop environments may override default fontconfig hinting and anti-aliasing settings. This may happen with [[GNOME]] 3, for example while you are using Qt applications like {{pkg|vlc}} or {{pkg|smplayer}}. Use the specific configuration program for the application in such cases. For GNOME, try {{Pkg|gnome-tweaks}}.
  
# pacman -S --asdeps freetype2 libxft cairo fontconfig
+
=== Applications not picking up hinting from DE's settings ===
  
==Applications without fontconfig support==
+
For instance, under GNOME it sometimes happens that Firefox applies full hinting even when it's set to "none" in GNOME's settings, which results in sharp and widened fonts. In this case you would have to add hinting settings to your {{ic|fonts.conf}} file:
  
Some applications like LibreOffice will ignore fontconfig settings. This is very apparent when using the infinality patches which are heavily reliant on proper configuration. You can work around this by using ~/.Xresources, but it isn't nearly as flexible as fontconfig. Example (see [[#Fontconfig configuration]] for explanations of the options):
+
<?xml version='1.0'?>
 +
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
 +
<fontconfig>
 +
  <match target="font">
 +
  <edit mode="assign" name="hinting">
 +
    <bool>false</bool>
 +
  </edit>
 +
  </match>
 +
</fontconfig>
  
{{File|name=~/.Xresources|content=<nowiki>Xft.autohint: 0
+
In this example, hinting is set to "grayscale".
Xft.lcdfilter:  lcddefault
 
Xft.hintstyle:  hintfull
 
Xft.hinting: 1
 
Xft.antialias: 1
 
Xft.rgba: rgb
 
</nowiki>}}
 
  
Make sure the settings are loaded properly when X starts with '''xrdb -q''' (see [[Xresources]] for more info).
+
=== Incorrect hinting in GTK applications on non-Gnome systems ===
  
==Troubleshooting==
+
{{Accuracy|Mentions GTK relies on fontconfig, then claims that "some" fonts get the hinting "wrong", and ends up refering to Xft (but see e.g [http://doc.opensuse.org/documentation/html/openSUSE_113/opensuse-reference/cha.fontconfig.html#sec.fontconfig.xft]). IOW, unsupported claims and unclear relations}}
  
===Distorted fonts===
+
[[GNOME]] uses the XSETTINGS system to configure font rendering. Outside of GNOME, GTK applications rely on fontconfig, but some fonts get the hinting wrong causing them to look too bold or too light.
''Main article: [[Xorg#Display Size and DPI]]
 
  
 +
A simple solution is using {{AUR|xsettingsd-git}} to provide the configuration, for example:
  
 +
{{hc|~/.xsettingsd|
 +
Xft/Hinting 1
 +
Xft/RGBA "rgb"
 +
Xft/HintStyle "hintslight"
 +
Xft/Antialias 1
 +
}}
  
Fontconfig should be able to detect DPI parameters as discovered by the Xorg server and be able to display the fonts correctly using the Xft.dpi variable. To find out if Xft.dpi has already been set correctly, check by running the program xrdb -query:
+
Alternatively you could just write the font configuration as {{ic|Xft.*}} directives in {{ic|~/.Xresources}} without using a settings daemon. See [[#Applications without fontconfig support]].
  
# xrdb -query | grep dpi
+
=== Helvetica font problem in generated PDFs ===
  
If Xft.dpi was not set correctly try to fix the Xorg configuration to specify the correct dpi for your monitor.
+
If the following command
  
 +
fc-match helvetica
  
Those still having problems can still fall back to setting it manually:
+
produces
  
  ...
+
  helvR12-ISO8859-1.pcf.gz: "Helvetica" "Regular"
<!-- Setup for DPI=96 -->
 
<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.
+
then the bitmap font provided by {{Pkg|xorg-fonts-75dpi}} is likely to be embedded into PDFs generated by "Print to File" or "Export" in various applications. The bitmap font was probably installed as a consequence of installing the whole {{Grp|xorg}} group (which is usually NOT recommended). To solve the pixelized font problem, you can uninstall the package. Install {{Pkg|gsfonts}} (Type 1) or {{Pkg|tex-gyre-fonts}} (OpenType) for corresponding free subsitute of Helvetica (and other PostScript/PDF base fonts).
  
===Missing characters===
+
You may also experience similar problem when you open a PDF which requires Helvetica but does not have it embedded for viewing.
  
If using [[Emacs]], the {{Package Official|xorg-fonts-75dpi}} and {{Package Official|xorg-fonts-100dpi}} packages need to be installed.
+
=== FreeType Breaking Bitmap Fonts ===
  
===Older GTK and QT applications===
+
Some users are reporting problems ({{Bug|52502}}) with bitmap fonts having changed names after upgrading {{Pkg|freetype2}} to version 2.7.1, creating havok in terminal emulators and several other programs such as {{AUR|dwm}} or {{Pkg|dmenu}} by falling back to another (different) font. This was caused by the changes to the PCF font family format, which is described in their ''release notes'' [https://sourceforge.net/projects/freetype/files/freetype2/2.7.1/]. Users transitioning from the old format might want to create a ''font alias'' to remedy the problems, like the solution which is described in [https://forum.manjaro.org/t/terminus-font-name-fix-after-freetype2-update-to-2-7-1-1/15530], given here too:
  
Modern GTK apps enable Xft by default but this was not the case before version 2.2If it is not possible to update these applications, force Xft for old GNOME applications by adding to {{Filename|~/.bashrc}}:
+
Assume we want to create an alias for {{Pkg|terminus-font}}, which was renamed from {{ic|Terminus}} to {{ic|xos4 Terminus}} in the previously described {{Pkg|freetype2}} update:
 +
* Create a configuration file in {{ic|/etc/fonts/conf.avail/}} for the ''font alias'':
 +
{{hc|/etc/fonts/conf.avail/33-TerminusPCFFont.conf|<nowiki>
 +
<?xml version="1.0"?>
 +
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 +
  <fontconfig>
 +
    <alias>
 +
        <family>Terminus</family>
 +
        <prefer><family>xos4 Terminus</family></prefer>
 +
        <default><family>fixed</family></default>
 +
    </alias>
 +
</fontconfig>
 +
</nowiki>}}
 +
* Create a symbolic link towards it in the {{ic|/etc/fonts/conf.d}} directory. In our example we would link as follows: {{ic|ln -s /etc/fonts/conf.avail/33-TerminusPCFFont.conf /etc/fonts/conf.d}} to make the change permanent.
 +
Everything should now work as it did before the update, the ''font alias'' should not be in effect, but make sure to either reload {{ic|.Xresources}} or restart the display server first so the affected programs can use the alias.
  
export GDK_USE_XFT=1
+
=== Debugging FreeType Fonts ===
  
For older QT applications:
+
{{Pkg|freetype2-demos}} provides tools for debugging FreeType font configuration. {{ic|ftview}} is a GUI in which you can tweak font rendering settings with a live preview. For example:
  
  export QT_XFT=true
+
  $ ftview -e unic -d 1024x768x24 -r 96 10 /usr/share/fonts/noto/NotoSans-Regular.ttf
  
==Resources==
+
== See also ==
  
*[http://www.x.org/X11R6.8.2/doc/fonts.html Fonts in X11R6.8.2] - Official Xorg font information
+
* [[Wikipedia:Fontconfig]]
*[http://freetype.sourceforge.net/freetype2/ FreeType 2 Overview]
+
* [http://www.x.org/X11R6.8.2/doc/fonts.html Fonts in X11R6.8.2] - Official Xorg font information
 +
* [http://freetype.sourceforge.net/freetype2/ FreeType 2 overview]
 +
* [https://forums.gentoo.org/viewtopic-t-723341.html Gentoo font-rendering thread]
 +
* [http://www.freetype.org/freetype2/docs/text-rendering-general.html On slight hinting]
 +
* [https://www.freetype.org/freetype2/docs/reference/index.html#controlling-freetype-modules FreeType 2 API Reference: Controlling FreeType Modules]

Latest revision as of 02:29, 10 August 2019

Fontconfig is a library designed to provide a list of available fonts to applications, and also for configuration for how fonts get rendered. The FreeType library renders the fonts, based on this configuration. The freetype2 font rendering packages on Arch Linux include the bytecode interpreter (BCI) enabled for better font rendering especially with an LCD monitor. See #Fontconfig configuration and Font configuration/Examples.

Though Fontconfig is used often in modern Unix and Unix-like operating systems, some applications rely on the original method of font selection and display, the X Logical Font Description.

Font paths

For fonts to be known to applications, they must be cataloged for easy and quick access.

The font paths initially known to Fontconfig are: /usr/share/fonts/, ~/.local/share/fonts (and ~/.fonts/, now deprecated). Fontconfig will scan these directories recursively. For ease of organization and installation, it is recommended to use these font paths when adding fonts.

To see a list of known Fontconfig fonts:

$ fc-list : file

See fc-list(1) for more output formats.

Check for Xorg's known font paths by reviewing its log:

$ grep /fonts ~/.local/share/xorg/Xorg.0.log
Tip:
  • You can also check the list of Xorg's known font paths using the command xset q.
  • Use /var/log/Xorg.0.log if Xorg is run with root privileges.

Keep in mind that Xorg does not search recursively through the /usr/share/fonts/ directory like Fontconfig does. To add a path, the full path must be used:

Section "Files"
    FontPath     "/usr/share/fonts/local/"
EndSection

If you want font paths to be set on a per-user basis, you can add and remove font paths from the default by adding the following line(s) to ~/.xinitrc:

xset +fp /usr/share/fonts/local/           # Prepend a custom font path to Xorg's list of known font paths
xset -fp /usr/share/fonts/sucky_fonts/     # Remove the specified font path from Xorg's list of known font paths

To see a list of known Xorg fonts use xlsfonts, from the xorg-xlsfonts package.

Fontconfig configuration

Fontconfig is documented in the fonts-conf(5) man page.

Configuration can be done per-user through $XDG_CONFIG_HOME/fontconfig/fonts.conf, and globally with /etc/fonts/local.conf. The settings in the per-user configuration have precedence over the global configuration. Both these files use the same syntax.

Note: Configuration files and directories: ~/.fonts.conf/, ~/.fonts.conf.d/ and ~/.fontconfig/*.cache-* are deprecated since fontconfig 2.10.1 (upstream commit) and will not be read by default in the future versions of the package. New paths are $XDG_CONFIG_HOME/fontconfig/fonts.conf, $XDG_CONFIG_HOME/fontconfig/conf.d/NN-name.conf and $XDG_CACHE_HOME/fontconfig/*.cache-* respectively. If using the second location, make sure the naming is valid (where NN is a two digit number like 00, 10, or 99).

Fontconfig gathers all its configurations in a central file (/etc/fonts/fonts.conf). This file is replaced during fontconfig updates and should not be edited. Fontconfig-aware applications source this file to know available fonts and how they get rendered; simply restarting such applications is sufficient to load the new configuration. This file is a conglomeration of rules from the global configuration (/etc/fonts/local.conf), the configured presets in /etc/fonts/conf.d/, and the user configuration file ($XDG_CONFIG_HOME/fontconfig/fonts.conf). fc-cache can be used to rebuild fontconfig's configuration, although changes will only be visible in newly launched applications.

Note: For some desktop environments (such as GNOME and KDE) using the Font Control Panel will automatically create or overwrite the user font configuration file. For these desktop environments, it is best to match your already defined font configurations to get the expected behavior. Also ensure that the desktop locale settings or Regional Settings are supported by the configured fonts, if not the font configuration could be overidden.

Fontconfig configuration files use XML format and need these headers:

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

  <!-- settings go here -->

</fontconfig>

The configuration examples in this article omit these tags.

Presets

There are presets installed in the directory /etc/fonts/conf.avail. They can be enabled by creating symbolic links to them, both per-user and globally, as described in /etc/fonts/conf.d/README. These presets will override matching settings in their respective configuration files.

For example, to enable sub-pixel RGB rendering globally:

# cd /etc/fonts/conf.d
# ln -s ../conf.avail/10-sub-pixel-rgb.conf

To do the same but instead for a per-user configuration:

$ mkdir $XDG_CONFIG_HOME/fontconfig/conf.d
$ ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf $XDG_CONFIG_HOME/fontconfig/conf.d

Anti-aliasing

Font rasterization converts vector font data to bitmap data so that it can be displayed. The result can appear jagged due to aliasing. The technique known as anti-aliasing can be used to increase the apparent resolution of font edges. Anti-aliasing is enabled by default. To disable it:

  <match target="font">
    <edit name="antialias" mode="assign">
      <bool>false</bool>
    </edit>
  </match>
Note: Some applications, like GNOME may override default anti-aliasing settings.

Hinting

Font hinting (also known as instructing) is the use of mathematical instructions to adjust the display of an outline font so that it lines up with a rasterized grid (i.e. the pixel grid of the display). Its intended effect is to make fonts appear more crisp so that they are more readable. Fonts will line up correctly without hinting when displays have around 300 DPI.

Byte-Code Interpreter (BCI)

Using BCI hinting, instructions in TrueType fonts are rendered according to FreeTypes's interpreter. BCI hinting works well with fonts with good hinting instructions. Hinting is enabled by default. To disable it:

  <match target="font">
    <edit name="hinting" mode="assign">
      <bool>false</bool>
    </edit>
  </match>
Note: You can switch BCI implementations by editing /etc/profile.d/freetype2.sh which includes a brief documentation. Most popular values are truetype:interpreter-version=35 (classic mode, emulates Windows 98; 2.6 default), truetype:interpreter-version=38 ("Infinality" subpixel mode), truetype:interpreter-version=40 (minimal subpixel mode; 2.7 default). If you prefer classic Windows ClearType style you can use truetype:interpreter-version=36. Subpixel rendering should use a subpixel BCI. For details, see [1].

Autohinter

The autohinter attempts to do automatic hinting and disregards any existing hinting information. Originally it was the default because TrueType2 fonts were patent-protected but now that these patents have expired there is very little reason to use it. It does work better with fonts that have broken or no hinting information but it will be strongly sub-optimal for fonts with good hinting information. Generally common fonts are of the later kind so autohinter will not be useful. Autohinter is disabled by default. To enable it:

  <match target="font">
    <edit name="autohint" mode="assign">
      <bool>true</bool>
    </edit>
  </match>

Hintstyle

Hintstyle is the amount of font reshaping done to line up to the grid. Hinting values are: hintnone, hintslight, hintmedium, and hintfull. hintslight will make the font more fuzzy to line up to the grid but will be better in retaining font shape (see [2]), while hintfull will be a crisp font that aligns well to the pixel grid but will lose a greater amount of font shape. hintslight implicitly uses the autohinter in a vertical-only mode in favor of font-native information for non-CFF (.otf) fonts.

hintslight is the default setting. To change it:

  <match target="font">
    <edit name="hintstyle" mode="assign">
      <const>hintnone</const>
    </edit>
  </match>
Note: Some applications, like GNOME may override default hinting settings.

Pixel alignment

Most monitors manufactured today use the Red, Green, Blue (RGB) specification. Fontconfig will need to know your monitor type to be able to display your fonts correctly. Monitors are either: RGB (most common), BGR, V-RGB (vertical), or V-BGR. A monitor test can be found here.

  <match target="font">
    <edit name="rgba" mode="assign">
      <const>rgb</const>
    </edit>
  </match>
Note: Without subpixel rendering (see below), freetype will only care about the alignment (vertical or horizontal) of the subpixels. There is no difference between RGB and BGR, for example.

Subpixel rendering

Subpixel rendering is a technique to improve sharpness of font rendering by effectively tripling the horizontal (or vertical) resolution through the use of subpixels. On Windows machines, this technique is called "ClearType".

FreeType implements its own LCD-optimized rendering called Harmony. With this FreeType LCD rendering technology, the resulting output does not require additional LCD filtering, unlike Microsoft's patented Cleartype subpixel rendering where an LCD filter is recommended. See section below on how to enable LCD filter and its benefits.

Cleartype subpixel rendering is covered by Microsoft patents and disabled by default on Arch Linux. To enable it, you have to re-compile freetype2 and define the FT_CONFIG_OPTION_SUBPIXEL_RENDERING macro, or use e.g. the AUR package freetype2-cleartypeAUR.

LCD filter

When using Cleartype subpixel rendering, you should enable the LCD filter, which is designed to reduce colour fringing. This is described under LCD filtering in the FreeType 2 API reference. Different options are described under FT_LcdFilter, and are illustrated by this LCD filter test page.

The lcddefault filter will work for most users. Other filters are available that can be used in special situations: lcdlight; a lighter filter ideal for fonts that look too bold or fuzzy, lcdlegacy, the original Cairo filter; and lcdnone to disable it entirely.

  <match target="font">
    <edit name="lcdfilter" mode="assign">
      <const>lcddefault</const>
    </edit>
  </match>

Advanced LCD filter specification

If the available built-in LCD filters are not satisfactory, it is possible to tweak the font rendering very specifically by building a custom freetype2 package and modifying the hardcoded filters. The Arch Build System can be used to build and install packages from source. This requires installation of the asp package.

Checkout the freetype2 PKGBUILD and download/extract the build files:

$ asp checkout freetype2
$ cd freetype2/trunk
$ makepkg -o

Enable subpixel rendering by editing the file src/freetype-VERSION/include/freetype/config/ftoption.h and uncommenting the FT_CONFIG_OPTION_SUBPIXEL_RENDERING macro.

Then, edit the file src/freetype-VERSION/src/base/ftlcdfil.c and look up the definition of the constant default_filter[5]:

static const FT_Byte  default_filter[5] =
    { 0x10, 0x40, 0x70, 0x40, 0x10 };

This constant defines a low-pass filter applied to the rendered glyph. Modify it as needed. (reference: freetype list discussion) Save the file, build and install the custom package:

$ makepkg -e
# pacman -Rd freetype2
# pacman -U freetype2-VERSION-ARCH.pkg.tar.xz

Reboot or restart X. The lcddefault filter should now render fonts differently.

Custom settings for certain fonts or font styles

The auto-hinter uses sophisticated methods for font rendering, but often makes bold fonts too wide. Fortunately, a solution can be turning off the autohinter 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>
...

Some fonts may not look good with BCI hinting. It can be disabled for just those fonts:

...
<match target="font">
    <test name="family" qual="any">
        <string>My Font</string>
    </test>
    <edit name="hinting" mode="assign">
        <bool>false</bool>
    </edit>
</match>
...

Replace or set default fonts

The most reliable way to do this is to add an XML fragment similar to the one below. Using the "binding" attribute will give you better results, for example, in Firefox where you may not want to change properties of font being replaced. This will cause Ubuntu to be used in place of Georgia:

...
 <match target="pattern">
   <test qual="any" name="family"><string>georgia</string></test>
   <edit name="family" mode="assign" binding="same"><string>Ubuntu</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>
...

Whitelisting and blacklisting fonts

The element <selectfont> is used in conjunction with the <acceptfont> and <rejectfont> elements to selectively whitelist or blacklist fonts from the resolve list and match requests. The simplest and most typical use case it to reject one font that is needed to be installed, however is getting matched for a generic font query that is causing problems within application user interfaces.

First obtain the Family name as listed in the font itself:

$ fc-scan .fonts/lklug.ttf --format='%{family}\n'
LKLUG

Then use that Family name in a <rejectfont> stanza:

<selectfont>
    <rejectfont>
        <pattern>
            <patelt name="family" >
                <string>LKLUG</string>
            </patelt>
        </pattern>
    </rejectfont>
</selectfont>

Typically when both elements are combined, <rejectfont> is first used on a more general matching glob to reject a large group (such as a whole directory), then <acceptfont> is used after it to whitelist individual fonts out of the larger blacklisted group.

<selectfont>
    <rejectfont>
        <glob>/usr/share/fonts/OTF/*</glob>
    </rejectfont>
    <acceptfont>
        <pattern>
            <patelt name="family" >
                <string>Monaco</string>
            </patelt>
        </pattern>
    </acceptfont>
</selectfont>

Disable bitmap fonts

Bitmap fonts are sometimes used as fallbacks for missing fonts, which may cause text to be rendered pixelated or too large. Use the 70-no-bitmaps.conf preset to disable this behavior.

To disable embedded bitmap for all fonts:

~/.config/fontconfig/conf.d/20-no-embedded.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <match target="font">
    <edit name="embeddedbitmap" mode="assign">
      <bool>false</bool>
    </edit>
  </match>
</fontconfig>

To disable embedded bitmap fonts for a specific font:

<match target="font">
  <test qual="any" name="family">
    <string>Monaco</string>
  </test>
  <edit name="embeddedbitmap">
    <bool>false</bool>
  </edit>
</match>

Disable scaling of bitmap fonts

To disable scaling of bitmap fonts (which often makes them blurry), remove /etc/fonts/conf.d/10-scale-bitmap-fonts.conf.

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 $XDG_CONFIG_HOME/fontconfig/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>
...
Tip: Use the value embolden for existing bold fonts in order to make them even bolder.

Change rule overriding

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: /etc/fonts/conf.d/50-user.conf will be created again when fontconfig is updated. (Discuss in Talk:Font configuration#Change Rule Overriding)

Fontconfig processes files in /etc/fonts/conf.d in numerical 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

This change seems however to be unnecessary for the most of the cases, because a user is given enough control by default to set up own font preferences, hinting and antialiasing properties, alias new fonts to generic font families, etc.

Query the current settings

To find out what settings are in effect, use fc-match --verbose. eg.

$ fc-match --verbose Sans
family: "DejaVu Sans"(s)
hintstyle: 3(i)(s)
hinting: True(s)
...

Look up the meaning of the numbers at fonts-conf(5) Eg. 'hintstyle: 3' means 'hintfull'

Applications without fontconfig support

Some applications like URxvt will ignore fontconfig settings. You can work around this by using ~/.Xresources, but it is not as flexible as fontconfig. Example (see #Fontconfig configuration for explanations of the options):

~/.Xresources
Xft.autohint: 0
Xft.lcdfilter: lcddefault
Xft.hintstyle: hintslight
Xft.hinting: 1
Xft.antialias: 1
Xft.rgba: rgb

Make sure the settings are loaded properly when X starts with xrdb -q (see X resources for more information).

Troubleshooting

Distorted fonts

Note: 96 DPI is not a standard. You should use your monitor's actual DPI to get proper font rendering, especially when using subpixel rendering.

If fonts are still unexpectedly large or small, poorly proportioned or simply rendering poorly, fontconfig may be using the incorrect DPI.

Fontconfig should be able to detect DPI parameters as discovered by the Xorg server. You can check the automatically discovered DPI with xdpyinfo (provided by the xorg-xdpyinfo package):

$ xdpyinfo | grep dots
  resolution:    102x102 dots per inch

If the DPI is detected incorrectly (usually due to an incorrect monitor EDID), you can specify it manually in the Xorg configuration, see Xorg#Display size and DPI. This is the recommended solution, but it may not work with buggy drivers.

Fontconfig will default to the Xft.dpi variable if it is set. Xft.dpi is usually set by desktop environments (usually to Xorg's DPI setting) or manually in ~/.Xdefaults or ~/.Xresources. Use xrdb to query for the value:

$ xrdb -query | grep dpi
Xft.dpi:	102

Those still having problems can fall back to manually setting the DPI used by fontconfig:

...
<match target="pattern">
   <edit name="dpi" mode="assign"><double>102</double></edit>
</match>
...

Calibri, Cambria, Monaco, etc. not rendering properly

Some scalable fonts have embedded bitmap versions which are rendered instead, mainly at smaller sizes. Using Metric-compatible fonts as replacements can improve the rendering in these cases.

You can also force using scalable fonts at all sizes by disabling embedded bitmap, sacrificing some rendering quality.

Applications overriding hinting

Some applications or desktop environments may override default fontconfig hinting and anti-aliasing settings. This may happen with GNOME 3, for example while you are using Qt applications like vlc or smplayer. Use the specific configuration program for the application in such cases. For GNOME, try gnome-tweaks.

Applications not picking up hinting from DE's settings

For instance, under GNOME it sometimes happens that Firefox applies full hinting even when it's set to "none" in GNOME's settings, which results in sharp and widened fonts. In this case you would have to add hinting settings to your fonts.conf file:

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

In this example, hinting is set to "grayscale".

Incorrect hinting in GTK applications on non-Gnome systems

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: Mentions GTK relies on fontconfig, then claims that "some" fonts get the hinting "wrong", and ends up refering to Xft (but see e.g [3]). IOW, unsupported claims and unclear relations (Discuss in Talk:Font configuration#)

GNOME uses the XSETTINGS system to configure font rendering. Outside of GNOME, GTK applications rely on fontconfig, but some fonts get the hinting wrong causing them to look too bold or too light.

A simple solution is using xsettingsd-gitAUR to provide the configuration, for example:

~/.xsettingsd
Xft/Hinting 1
Xft/RGBA "rgb"
Xft/HintStyle "hintslight"
Xft/Antialias 1

Alternatively you could just write the font configuration as Xft.* directives in ~/.Xresources without using a settings daemon. See #Applications without fontconfig support.

Helvetica font problem in generated PDFs

If the following command

fc-match helvetica

produces

helvR12-ISO8859-1.pcf.gz: "Helvetica" "Regular"

then the bitmap font provided by xorg-fonts-75dpi is likely to be embedded into PDFs generated by "Print to File" or "Export" in various applications. The bitmap font was probably installed as a consequence of installing the whole xorg group (which is usually NOT recommended). To solve the pixelized font problem, you can uninstall the package. Install gsfonts (Type 1) or tex-gyre-fonts (OpenType) for corresponding free subsitute of Helvetica (and other PostScript/PDF base fonts).

You may also experience similar problem when you open a PDF which requires Helvetica but does not have it embedded for viewing.

FreeType Breaking Bitmap Fonts

Some users are reporting problems (FS#52502) with bitmap fonts having changed names after upgrading freetype2 to version 2.7.1, creating havok in terminal emulators and several other programs such as dwmAUR or dmenu by falling back to another (different) font. This was caused by the changes to the PCF font family format, which is described in their release notes [4]. Users transitioning from the old format might want to create a font alias to remedy the problems, like the solution which is described in [5], given here too:

Assume we want to create an alias for terminus-font, which was renamed from Terminus to xos4 Terminus in the previously described freetype2 update:

  • Create a configuration file in /etc/fonts/conf.avail/ for the font alias:
/etc/fonts/conf.avail/33-TerminusPCFFont.conf
<?xml version="1.0"?>
 <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 <fontconfig>
     <alias>
         <family>Terminus</family>
         <prefer><family>xos4 Terminus</family></prefer>
         <default><family>fixed</family></default>
     </alias>
 </fontconfig>
  • Create a symbolic link towards it in the /etc/fonts/conf.d directory. In our example we would link as follows: ln -s /etc/fonts/conf.avail/33-TerminusPCFFont.conf /etc/fonts/conf.d to make the change permanent.

Everything should now work as it did before the update, the font alias should not be in effect, but make sure to either reload .Xresources or restart the display server first so the affected programs can use the alias.

Debugging FreeType Fonts

freetype2-demos provides tools for debugging FreeType font configuration. ftview is a GUI in which you can tweak font rendering settings with a live preview. For example:

$ ftview -e unic -d 1024x768x24 -r 96 10 /usr/share/fonts/noto/NotoSans-Regular.ttf

See also