Difference between revisions of "Font configuration"

From ArchWiki
Jump to: navigation, search
(Example fontconfig configurations: silly to overwrite the file that loads /etc/fonts/local.conf when the point is allowing that to be the file)
(Add a little note about the naming convetion of files residing the conf.d directory)
(48 intermediate revisions by 19 users not shown)
Line 1: Line 1:
 
[[Category:Fonts]]
 
[[Category:Fonts]]
 +
[[it:Font Configuration]]
 +
[[ru:Font Configuration]]
 +
[[sr:Font Configuration]]
 
[[tr:Yazıtipi_yapılandırması]]
 
[[tr:Yazıtipi_yapılandırması]]
{{i18n|Font Configuration}}
+
[[zh-CN:Font Configuration]]
 
{{Article summary start}}
 
{{Article summary start}}
 
{{Article summary text|An overview of font configuration options and various techniques for improving the readability of fonts}}
 
{{Article summary text|An overview of font configuration options and various techniques for improving the readability of fonts}}
 
{{Article summary heading|Related}}
 
{{Article summary heading|Related}}
 
{{Article summary wiki|Fonts}}: Information on adding fonts and font recommendations
 
{{Article summary wiki|Fonts}}: Information on adding fonts and font recommendations
 +
{{Article summary wiki|Font Configuration/fontconfig Examples}}
 
{{Article summary wiki|Java Runtime Environment Fonts}}: Fonts specific to Sun's Java machine
 
{{Article summary wiki|Java Runtime Environment Fonts}}: Fonts specific to Sun's Java machine
 
{{Article summary wiki|MS Fonts}}: Adding Microsoft fonts and mimicking Windows' font settings
 
{{Article summary wiki|MS Fonts}}: Adding Microsoft fonts and mimicking Windows' font settings
 +
{{Article summary wiki|X Logical Font Description}}: The older core font system for X
 
{{Article summary end}}
 
{{Article summary end}}
  
 
Fontconfig is a library designed to provide a list of available [[fonts]] to applications, and also for configuration for how fonts get rendered.  See package {{Pkg|fontconfig}} and [[Wikipedia:Fontconfig]].  The Free type library ({{Pkg|freetype2}} package) renders the fonts, based on this configuration.
 
Fontconfig is a library designed to provide a list of available [[fonts]] to applications, and also for configuration for how fonts get rendered.  See package {{Pkg|fontconfig}} and [[Wikipedia:Fontconfig]].  The Free type library ({{Pkg|freetype2}} package) renders the fonts, based on this configuration.
  
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 the standard in today's Linux, some applications still rely on the original method of font selection and display, the [[X Logical Font Description]].
  
 
The font rendering packages on Arch Linux includes support for ''freetype2'' with the bytecode interpreter (BCI) enabled.  Patched packages exist for better font rendering, especially with an LCD monitor.  See [[#Patched packages]] below.  The [[#Infinality]] package allows both auto-hinting and subpixel rendering, allows the LCD filter to be tweaked without recompiling, and allows the auto-hinter to work well with bold fonts.
 
The font rendering packages on Arch Linux includes support for ''freetype2'' with the bytecode interpreter (BCI) enabled.  Patched packages exist for better font rendering, especially with an LCD monitor.  See [[#Patched packages]] below.  The [[#Infinality]] package allows both auto-hinting and subpixel rendering, allows the LCD filter to be tweaked without recompiling, and allows the auto-hinter to work well with bold fonts.
Line 22: Line 27:
 
The font paths initially known to Fontconfig are: {{ic|/usr/share/fonts/}} and {{ic|~/.fonts/}} (of which Fontconfig will scan recursively). For ease of organization and installation, it is recommended to use these font paths when [[Fonts#Installation|adding fonts]].
 
The font paths initially known to Fontconfig are: {{ic|/usr/share/fonts/}} and {{ic|~/.fonts/}} (of which Fontconfig will scan recursively). For ease of organization and installation, it is recommended to use these font paths when [[Fonts#Installation|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
 +
 
 +
See {{ic|man fc-list}} for more out put format.
  
 
Check for Xorg's known font paths by reviewing its log:
 
Check for Xorg's known font paths by reviewing its log:
Line 45: Line 52:
 
Fontconfig is documented in the [http://fontconfig.org/fontconfig-user.html fonts.conf] man page.
 
Fontconfig is documented in the [http://fontconfig.org/fontconfig-user.html fonts.conf] man page.
  
Configuration can be done per-user through {{ic|~/.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.
+
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 fontconfig 2.10.1 ([http://cgit.freedesktop.org/fontconfig/commit/?id=8c255fb185d5651b57380b0a9443001e8051b29d upstream commit]) and will not be read by default in the future versions of package. Use instead {{ic|$XDG_CONFIG_HOME/fontconfig/fonts.conf}}, {{ic|$XDG_CONFIG_HOME/fontconfig/conf.d}} and {{ic|$XDG_CACHE_HOME/fontconfig/*.cache-*}} respectively. If you use the second directory, the file '''must''' follow the naming convention {{ic|NN-name.conf}} (where NN it's a two digit number like 00, 10, or 99).}}
  
Fontconfig gathers all its configurations in a central file ({{ic|/etc/fonts/fonts.conf}}).  This file is replaced during fontconfig updates and shouldn't be edited.  Fontconfig-aware applications source this file to know available fonts and how they get rendered.  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|~/.fonts.conf}}).
+
Fontconfig gathers all its configurations in a central file ({{ic|/etc/fonts/fonts.conf}}).  This file is replaced during fontconfig updates and shouldn't be edited.  Fontconfig-aware applications source this file to know available fonts and how they get rendered.  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}}).
  
 
{{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.}}
Line 73: Line 81:
 
  # cd /etc/fonts/conf.d
 
  # cd /etc/fonts/conf.d
 
  # ln -s ../conf.avail/10-sub-pixel-rgb.conf
 
  # ln -s ../conf.avail/10-sub-pixel-rgb.conf
 
To enable autohinting globally:
 
 
# cd /etc/fonts/conf.d
 
# ln -s ../conf.avail/10-autohint.conf
 
 
{{Tip|Applying the above two should help if fonts look ugly (for example on Google or Gmail) after installing [[MS Fonts]]. '''Note''': Actually, you cannot enable both of them (See [[#Subpixel_rendering]]). To help with ugly fonts, enable [[#Subpixel_rendering]] and a [[#Hint_style]] like hintslight.}}
 
  
 
To do the same but instead for a per-user configuration:
 
To do the same but instead for a per-user configuration:
  
  $ mkdir ~/.fonts.conf.d
+
  $ mkdir $XDG_CONFIG_HOME/fontconfig/conf.d
  $ ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf ~/.fonts.conf.d
+
  $ ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf $XDG_CONFIG_HOME/fontconfig/conf.d
  
 
===Anti-aliasing===
 
===Anti-aliasing===
Line 97: Line 98:
 
   </match>
 
   </match>
 
</nowiki>}}
 
</nowiki>}}
 +
 +
Note: some applications, like [[Gnome|Gnome 3]] may [[#Troubleshooting|override default anti-alias 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, 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.
  
 
====Byte-Code Interpreter (BCI)====
 
====Byte-Code Interpreter (BCI)====
Line 139: Line 142:
 
   </match>
 
   </match>
 
</nowiki>}}
 
</nowiki>}}
 +
 +
Note: some applications, like [[Gnome|Gnome 3]] may [[#Troubleshooting|override default hinting settings]].
  
 
===Subpixel rendering===
 
===Subpixel rendering===
  
Subpixel rendering effectively triples the horizontal (or vertical) resolution for fonts by making use of subpixels. The autohinter and subpixel rendering are not designed to work together and should not be used in combination.
+
Subpixel rendering effectively triples the horizontal (or vertical) resolution for fonts by making use of subpixels. The autohinter and subpixel rendering are not designed to work together and should not be used in combination without the [[#Infinality]] patch set.
  
 
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.
Line 162: Line 167:
 
====LCD filter====
 
====LCD filter====
  
When using subpixel rendering, you should enable the LCD filter, which is designed to reduce colour fringing.  This is described under [http://www.freetype.org/freetype2/docs/reference/ft2-lcd_filtering.html LCD filtering] in the Free type 2 API reference.  Different options are described under [http://www.freetype.org/freetype2/docs/reference/ft2-lcd_filtering.html#FT_LcdFilter FT_LcdFilter], and are illustrated by this [http://www.spasche.net/files/lcdfiltering/ LCD filter test] page.
+
When using subpixel rendering, you should enable the LCD filter, which is designed to reduce colour fringing.  This is described under [http://www.freetype.org/freetype2/docs/reference/ft2-lcd_filtering.html LCD filtering] in the FreeType 2 API reference.  Different options are described under [http://www.freetype.org/freetype2/docs/reference/ft2-lcd_filtering.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.
 
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.
Line 173: Line 178:
 
   </match>
 
   </match>
 
</nowiki>}}
 
</nowiki>}}
 
====Original LCD packages====
 
 
You can install {{AUR|fontconfig-lcd}} from the [[Arch User Repository|AUR]] to enable the {{ic|lcddefault}} filter automatically.
 
 
Cairo 1.10 in [extra] adds support for the LCD filter. As of {{ic|libxft-2.3.0}}, filtering is integrated upstream and a patched package is not needed.
 
  
 
====Advanced LCD filter specification====
 
====Advanced LCD filter specification====
Line 224: Line 223:
 
=== Enable anti-aliasing only for bigger fonts ===
 
=== Enable anti-aliasing only for bigger fonts ===
  
''See also [http://sharpfonts.co.cc/ sharpfonts.co.cc] for related information''
+
''See also [http://sharpfonts.co.cc/ sharpfonts.co.cc] for related information.''
  
 
Some users prefer the sharper rendering that anti-aliasing does not offer:
 
Some users prefer the sharper rendering that anti-aliasing does not offer:
Line 247: Line 246:
 
<match target="font" >
 
<match target="font" >
 
     <test name="pixelsize" qual="any" compare="more">
 
     <test name="pixelsize" qual="any" compare="more">
         <double>17</double>
+
         <double>16</double>
 
     </test>
 
     </test>
 
     <edit name="antialias" mode="assign">
 
     <edit name="antialias" mode="assign">
Line 258: Line 257:
 
===Replace fonts===
 
===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:
+
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" name="family" >
+
  <match target="pattern">
    <test name="family" qual="any" >
+
    <test qual="any" name="family"><string>georgia</string></test>
        <string>Helvetica</string>
+
    <edit name="family" mode="assign" binding="same"><string>Ubuntu</string></edit>
    </test>
+
  </match>
    <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:
 
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:
Line 288: Line 283:
 
  # ln -s ../conf.avail/70-no-bitmaps.conf
 
  # ln -s ../conf.avail/70-no-bitmaps.conf
  
You may not need to remove 70-yes-bitmaps.conf if it does not exist. You can choose which fonts to replace bitmaps fonts with (Helvetica, Courier and Times bitmap mapts to TTF fonts) by:
+
You may not need to remove {{ic|70-yes-bitmaps.conf}} if it does not exist. You can choose which fonts to replace bitmaps fonts with (Helvetica, Courier and Times bitmap mapts to TTF fonts) by:
  
 
  # cd /etc/fonts/conf.d
 
  # cd /etc/fonts/conf.d
Line 314: Line 309:
 
  "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 {{ic|~/.fonts.conf}}:
+
Now add necessary modifications to {{ic|$XDG_CONFIG_HOME/fontconfig/fonts.conf}}:
 
{{bc|<nowiki>
 
{{bc|<nowiki>
 
...
 
...
Line 348: Line 343:
 
===Change rule overriding===
 
===Change rule overriding===
  
Fontconfig processes files in {{ic|/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.
Line 367: Line 362:
 
<fontconfig>
 
<fontconfig>
 
  <match target="font">
 
  <match target="font">
 +
 
 
   <edit mode="assign" name="rgba">
 
   <edit mode="assign" name="rgba">
 
   <const>rgb</const>
 
   <const>rgb</const>
 
   </edit>
 
   </edit>
</match>
+
 
<match target="font">
+
 
   <edit mode="assign" name="hinting">
 
   <edit mode="assign" name="hinting">
 
   <bool>true</bool>
 
   <bool>true</bool>
 
   </edit>
 
   </edit>
</match>
+
 
<match target="font">
+
 
   <edit mode="assign" name="hintstyle">
 
   <edit mode="assign" name="hintstyle">
   <const>hintslight</const>
+
   <const>hintfull</const>
 
   </edit>
 
   </edit>
</match>
+
 
<match target="font">
+
 
   <edit mode="assign" name="antialias">
 
   <edit mode="assign" name="antialias">
 
   <bool>true</bool>
 
   <bool>true</bool>
 
   </edit>
 
   </edit>
 +
 +
  <edit mode="assign" name="lcdfilter">
 +
    <const>lcddefault</const>
 +
  </edit>
 +
 
  </match>
 
  </match>
  <match target="font">
 
    <edit mode="assign" name="lcdfilter">
 
      <const>lcddefault</const>
 
    </edit>
 
  </match>
 
 
</fontconfig>
 
</fontconfig>
 
</nowiki>}}
 
</nowiki>}}
Line 402: Line 395:
 
* Applications which [[Wikipedia:Static library|statically link]] to a library will not be affected by patches applied to the system library.
 
* Applications which [[Wikipedia:Static library|statically link]] to a library will not be affected by patches applied to the system library.
  
=== ClearType packages ===
+
===Infinality===
  
These packages attempt to emulate ClearType, a type of font rendering that is used in Windows systems and is designed to work on both LCD and CRT monitors.
 
 
Install the patched packages from the [[Arch User Repository|AUR]]. Package names: {{AUR|freetype2-cleartype}} {{AUR|libxft-cleartype}} {{AUR|cairo-cleartype}}
 
 
===Infinality===
 
 
The infinality patchset aims to greatly improve freetype2 font rendering. It adds multiple new capabilities.
 
The infinality patchset aims to greatly improve freetype2 font rendering. It adds multiple new capabilities.
  
Line 427: Line 415:
  
 
A number of presets are included and can be used by setting the USE_STYLE variable in {{ic|/etc/profile.d/infinality-settings.sh}}.
 
A number of presets are included and can be used by setting the USE_STYLE variable in {{ic|/etc/profile.d/infinality-settings.sh}}.
 +
 +
{{Note|1=The user bohoomil maintains a very good configuration in his [https://github.com/bohoomil/fontconf github repo] which is available as a [https://aur.archlinux.org/packages/fontconfig-infinality-ultimate/ package] in the AUR. For more information on the package see [https://bbs.archlinux.org/viewtopic.php?pid=1198888#p1198888 this] thread in the forums.}}
 +
 +
{{Note|1=Install {{AUR|grip-git}} from AUR to have a realtime preview.}}
  
 
{{AUR|freetype2-infinality}} can be installed from the [[Arch User Repository|AUR]]. Additionally, if you are using {{pkg|lib32-freetype2}} from [multilib], replace it with {{AUR|lib32-freetype2-infinality}} from the AUR. The AUR also contains a Git version of freetype2 that builds the latest development snapshot of freetype2 with the Infinality patchset: {{AUR|freetype2-git-infinality}}, {{AUR|lib32-freetype2-git-infinality}}.
 
{{AUR|freetype2-infinality}} can be installed from the [[Arch User Repository|AUR]]. Additionally, if you are using {{pkg|lib32-freetype2}} from [multilib], replace it with {{AUR|lib32-freetype2-infinality}} from the AUR. The AUR also contains a Git version of freetype2 that builds the latest development snapshot of freetype2 with the Infinality patchset: {{AUR|freetype2-git-infinality}}, {{AUR|lib32-freetype2-git-infinality}}.
Line 434: Line 426:
  
 
If you set e.g. win7 or osx you need the corresponding fonts installed.
 
If you set e.g. win7 or osx you need the corresponding fonts installed.
 +
 +
{{Note|Default infinality settings can cause some programs  to display fonts at 72 DPI instead of 96. If you notice a problem open /etc/fonts/infinality/infinality.conf search for the section on DPI and change 72 to 96. This problem can specifically affect conky causing the fonts to appear smaller than they should. Thus not aligning properly with images. }}
  
 
{{Note|''The README for {{AUR|fontconfig-infinality}} says that /etc/fonts/local.conf should either not exist, or have no infinality-related configurations in it.  The local.conf is now obsolete and completely replaced by this configuration.''}}
 
{{Note|''The README for {{AUR|fontconfig-infinality}} says that /etc/fonts/local.conf should either not exist, or have no infinality-related configurations in it.  The local.conf is now obsolete and completely replaced by this configuration.''}}
  
 
for more information see this article: http://www.infinality.net/forum/viewtopic.php?f=2&t=77
 
for more information see this article: http://www.infinality.net/forum/viewtopic.php?f=2&t=77
 +
 +
 +
*[http://www.infinality.net/blog/infinality-freetype-patches/ Home page].
  
 
===Ubuntu===
 
===Ubuntu===
  
Ubuntu uses the original LCD patched packages and adds extra configurations, and occasionally patches.
+
Ubuntu adds extra configurations, and occasionally patches to the font rendering libraries.
  
Install the patched packages from the [[Arch User Repository|AUR]], the package names are: {{AUR|freetype2-ubuntu}} {{AUR|fontconfig-ubuntu}} {{AUR|libxft-ubuntu}} {{AUR|cairo-ubuntu}}.
+
Install the patched packages from the [[Arch User Repository|AUR]], the package names are: {{AUR|freetype2-ubuntu}} {{AUR|fontconfig-ubuntu}} {{AUR|cairo-ubuntu}}.
  
 
The global configuration will need to be added. See [[#Example fontconfig configurations]] for a starting point.
 
The global configuration will need to be added. See [[#Example fontconfig configurations]] for a starting point.
 
{{Note|The maintainer of {{AUR|cairo-ubuntu}} has been requested to add {{ic|/etc/fonts/conf.avail/51-local.conf}} to the build so check if it is already present.}}
 
  
 
===Reverting to unpatched packages===
 
===Reverting to unpatched packages===
Line 453: Line 448:
 
To restore the unpatched packages, reinstall the originals:
 
To restore the unpatched packages, reinstall the originals:
  
  # pacman -S --asdeps freetype2 libxft cairo fontconfig
+
  # pacman -S --asdeps freetype2 cairo fontconfig
  
 
==Applications without fontconfig support==
 
==Applications without fontconfig support==
  
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 {{ic|~/.Xresources}}, but it is not nearly as flexible as fontconfig. Example (see [[#Fontconfig configuration]] for explanations of the options):
+
Some applications like [[URxvt]] 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 {{ic|~/.Xresources}}, but it is not nearly as flexible as fontconfig. Example (see [[#Fontconfig configuration]] for explanations of the options):
  
 
{{hc|~/.Xresources|<nowiki>
 
{{hc|~/.Xresources|<nowiki>
Line 472: Line 467:
 
==Troubleshooting==
 
==Troubleshooting==
  
===Distorted fonts===
+
=== 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 subpixels.}}
+
 
 +
{{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.
 
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 {{ic|xdpyinfo}}:
+
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):
  
 
{{hc|<nowiki>$ xdpyinfo | grep dots</nowiki>|  resolution:    102x102 dots per inch}}
 
{{hc|<nowiki>$ xdpyinfo | grep dots</nowiki>|  resolution:    102x102 dots per inch}}
 
{{Note|To use the ''xdpyinfo'' command, you must install the package {{pkg|xorg-xdpyinfo}}.}}
 
  
 
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.
 
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.
Line 494: Line 488:
 
  <!-- Setup for DPI=96 -->
 
  <!-- Setup for DPI=96 -->
 
  <match target="pattern">
 
  <match target="pattern">
     <edit name="dpi" mode="assign"><double>96</double></edit>
+
     <edit name="dpi" mode="assign"><double>102</double></edit>
 
  </match>
 
  </match>
 
  ...
 
  ...
 
===Missing characters===
 
 
If using [[Emacs]], the {{Pkg|xorg-fonts-75dpi}} and {{Pkg|xorg-fonts-100dpi}} packages need to be installed.
 
  
 
===Older GTK and QT applications===
 
===Older GTK and QT applications===
Line 511: Line 501:
  
 
  export QT_XFT=true
 
  export QT_XFT=true
 +
 +
===Applications overriding hinting===
 +
Some applications may override default fontconfig hinting and anti-aliasing settings. This may happen with [[Gnome]] 3, for example. Use the specific configuration program for the application in such cases. For gnome, try {{pkg|gnome-tweak-tool}}.
  
 
==See also==
 
==See also==

Revision as of 02:07, 27 March 2013

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki: Information on adding fonts and font recommendations Template:Article summary wiki Template:Article summary wiki: Fonts specific to Sun's Java machine Template:Article summary wiki: Adding Microsoft fonts and mimicking Windows' font settings Template:Article summary wiki: The older core font system for X Template:Article summary end

Fontconfig is a library designed to provide a list of available fonts to applications, and also for configuration for how fonts get rendered. See package fontconfig and Wikipedia:Fontconfig. The Free type library (freetype2 package) renders the fonts, based on this configuration.

Though Fontconfig is the standard in today's Linux, some applications still rely on the original method of font selection and display, the X Logical Font Description.

The font rendering packages on Arch Linux includes support for freetype2 with the bytecode interpreter (BCI) enabled. Patched packages exist for better font rendering, especially with an LCD monitor. See #Patched packages below. The #Infinality package allows both auto-hinting and subpixel rendering, allows the LCD filter to be tweaked without recompiling, and allows the auto-hinter to work well with bold fonts.

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/ and ~/.fonts/ (of which Fontconfig will scan 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 man fc-list for more out put format.

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

$ grep /fonts /var/log/Xorg.0.log
Tip: You can also check the list of Xorg's known font paths using the command xset q.

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 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 package. Use instead $XDG_CONFIG_HOME/fontconfig/fonts.conf, $XDG_CONFIG_HOME/fontconfig/conf.d and $XDG_CACHE_HOME/fontconfig/*.cache-* respectively. If you use the second directory, the file must follow the naming convention NN-name.conf (where NN it's 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 shouldn't be edited. Fontconfig-aware applications source this file to know available fonts and how they get rendered. 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).

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.

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. anti-aliasing is enabled by default and increases the apparent resolution of font edges.

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

Note: some applications, like Gnome 3 may override default anti-alias 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, such as the pixel grid in a display. Fonts will not line up correctly without hinting until displays have 300 DPI or greater. Two types of hinting are available.

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:

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

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. The autohinter and subpixel rendering are not designed to work together and should not be used in combination.

To enable auto-hinting:

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

Hint style

Hint style is the amount of influence the hinting mode has. Hinting can be set to: hintfull, hintmedium, hintslight and hintnone. With BCI hinting, hintfull should work best for most fonts. With the autohinter, hintslight is recommended.

  <match target="font">
    <edit name="hintstyle" mode="assign">
      <const>hintfull</const>
    </edit>
  </match>

Note: some applications, like Gnome 3 may override default hinting settings.

Subpixel rendering

Subpixel rendering effectively triples the horizontal (or vertical) resolution for fonts by making use of subpixels. The autohinter and subpixel rendering are not designed to work together and should not be used in combination without the #Infinality patch set.

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.

RGB (most common), BGR, V-RGB (vertical), or V-BGR

To enable subpixel rendering:

  <match target="font">
    <edit name="rgba" mode="assign">
      <const>rgb</const>
    </edit>
  </match>

If you notice unusual colors around font's borders, the wrong subpixel arrangement might be configured. The Lagom subpixel layout test web page can help identify it.

LCD filter

When using 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 mode="assign" name="lcdfilter">
      <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.

First, refresh the freetype2 PKGBUILD as root:

# abs extra/freetype2

This example uses /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
$ cp -r ../extra/freetype2 .
$ cd freetype2
$ makepkg -o

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. Save the file, build and install the custom package:

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

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

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 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>
...

Enable anti-aliasing only for bigger fonts

See also sharpfonts.co.cc for related information.

Some users prefer the sharper rendering that anti-aliasing does not 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>16</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. 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>
...

Disable bitmap fonts

To disable bitmap fonts in fontconfig, use 70-no-bitmaps.conf (which is not placed by fontconfig by default):

# cd /etc/fonts/conf.d
# rm 70-yes-bitmaps.conf
# ln -s ../conf.avail/70-no-bitmaps.conf

You may not need to remove 70-yes-bitmaps.conf if it does not exist. You can choose which fonts to replace bitmaps fonts with (Helvetica, Courier and Times bitmap mapts to TTF fonts) by:

# cd /etc/fonts/conf.d
# ln -s ../conf.avail/29-replace-bitmap-fonts.conf

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>

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

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.

Example fontconfig configurations

Example fontconfig configurations can be found on this page.

A simple starting point:

/etc/fonts/local.conf
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
 <match target="font">
  
  <edit mode="assign" name="rgba">
   <const>rgb</const>
  </edit>

  <edit mode="assign" name="hinting">
   <bool>true</bool>
  </edit>

  <edit mode="assign" name="hintstyle">
   <const>hintfull</const>
  </edit>

  <edit mode="assign" name="antialias">
   <bool>true</bool>
  </edit>

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

Patched packages

These patched packages are available in the AUR. A few considerations:

  • Configuration is usually necessary.
  • The new font rendering will not kick in until applications restart.
  • Applications which statically link to a library will not be affected by patches applied to the system library.

Infinality

The infinality patchset aims to greatly improve freetype2 font rendering. It adds multiple new capabilities.

Infinality's settings are all configurable at runtime via environment variables in /etc/profile.d/infinality-settings.sh, and include the following:

  • Emboldening Enhancement: Disables Y emboldening, producing a much nicer result on fonts without bold versions. Works on native TT hinter and autohinter.
  • 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 run-time. 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.
  • Force Slight Hinting: Force slight hinting even when programs want full hinting. If you use the local.conf I provide (included in infinality-settings fedora package) you will notice nice improvements on @font-face fonts.
  • ChromeOS Style Sharpening: ChromeOS uses a patch to sharpen the look of fonts. This is now included in the infinality patchset.

A number of presets are included and can be used by setting the USE_STYLE variable in /etc/profile.d/infinality-settings.sh.

Note: The user bohoomil maintains a very good configuration in his github repo which is available as a package in the AUR. For more information on the package see this thread in the forums.
Note: Install grip-gitAUR from AUR to have a realtime preview.

freetype2-infinalityAUR can be installed from the AUR. Additionally, if you are using lib32-freetype2 from [multilib], replace it with lib32-freetype2-infinalityAUR from the AUR. The AUR also contains a Git version of freetype2 that builds the latest development snapshot of freetype2 with the Infinality patchset: freetype2-git-infinalityAUR, lib32-freetype2-git-infinalityAUR.

It is recommended to also install fontconfig-infinalityAUR to enable selection of predefined font substitution styles and antialiasing settings, apart from the rendering settings of the engine itself. After doing so, you can select the font style (win7, winxp, osx, linux, ...) with:

# infctl setstyle

If you set e.g. win7 or osx you need the corresponding fonts installed.

Note: Default infinality settings can cause some programs to display fonts at 72 DPI instead of 96. If you notice a problem open /etc/fonts/infinality/infinality.conf search for the section on DPI and change 72 to 96. This problem can specifically affect conky causing the fonts to appear smaller than they should. Thus not aligning properly with images.
Note: The README for fontconfig-infinalityAUR says that /etc/fonts/local.conf should either not exist, or have no infinality-related configurations in it. The local.conf is now obsolete and completely replaced by this configuration.

for more information see this article: http://www.infinality.net/forum/viewtopic.php?f=2&t=77


Ubuntu

Ubuntu adds extra configurations, and occasionally patches to the font rendering libraries.

Install the patched packages from the AUR, the package names are: freetype2-ubuntuAUR fontconfig-ubuntuAUR cairo-ubuntuAUR.

The global configuration will need to be added. See #Example fontconfig configurations for a starting point.

Reverting to unpatched packages

To restore the unpatched packages, reinstall the originals:

# pacman -S --asdeps freetype2 cairo fontconfig

Applications without fontconfig support

Some applications like URxvt 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 is not nearly as flexible as fontconfig. Example (see #Fontconfig configuration for explanations of the options):

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

Make sure the settings are loaded properly when X starts with xrdb -q (see Xresources 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>
...

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

Applications overriding hinting

Some applications may override default fontconfig hinting and anti-aliasing settings. This may happen with Gnome 3, for example. Use the specific configuration program for the application in such cases. For gnome, try gnome-tweak-tool.

See also