Font configuration

From ArchWiki
Revision as of 21:02, 28 November 2009 by Thisoldman (Talk | contribs) (Disable auto-hinter for bold fonts: sp.)

Jump to: navigation, search
Summary help replacing me
Provides an overview of font configuration options and describes various techniques to improve fonts' appearance.
Available in languages

Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry

Related articles
Fonts
Java Fonts - Sun JRE

This article is about font configuration. For information about font types and recommendations, see Fonts.

Font paths

Most applications use fontconfig to provide the list of available fonts and to supply the application's requested font. However, for older applications such as urxvt, or for fonts that use a non-standard Xorg server font path, the font path must be specified in the Xorg server configuration file, Template:Filename.

Xorg server

You can check for Xorg server known font paths in the Xorg server log (Template:Filename) by:

grep /fonts /var/log/Xorg.0.log

Then add then any needed font paths in the Xorg server configuration file:

Section "Files"
   FontPath     "/usr/share/fonts/example-font-directory"
EndSection

To see a list of known Xorg server fonts use:

xlsfonts

Fontconfig

The configuration files in Template:Filename (Template:Filename and Template:Filename) are used by fontconfig compatible applications. The Template:Filename file is generated by fontconfig primarily by the aliases set in Template:Filename. The font paths known to fontconfig are Template:Filename and Template:Filename. It is recommended to use these font paths when installing new fonts (see Fonts). To see a list of known fontconfig fonts type:

fc-list

Fontconfig configuration

The font rendering packages on Arch Linux provides good font support with freetype2 with the bytecode interpreter enabled. However, defining your own font configuration may at times be necessary. If you have a LCD monitor, you might want to consider using the #LCD filter patched packages.

Configuration can either be done per-user or globally. If you choose to configure you fonts globally (the Template:Filename file), please note that some desktop environments font control panel will create a user font configuration (Template:Filename file) automatically when you enter the 'Font Control Panel' (Gnome and KDE do this). This file will take precedence over the global configuration. For these desktop environments, it is best to use their control panels to match your global settings to get your expected behavior.

If you are configuring fonts globally, there may be pre-existing font configuration files that you can link to. Available options are listing in Template:Filename and (for example) can be linked by:

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

When creating a font configuration file, some important options are:

  • Subpixel layout: RGB, BGR, V-RGB (vertical), or V-BGR. Most monitors are RGB. You can check you monitor type here.
  • Anti-aliasing (font smoothing): Fonts are created in pixels (i.e. in square blocks) without this your fonts will appear jagged.
  • Hinting: Font hinting is the use of mathematical instructions to adjust the display of an outline font so that it lines up with a rasterized grid [1]. This is necessary for font spacing to appear correct of displays with less than 300 DPI.
  • Hinting type: Hint type will be determined by your DPI too. If less than 300 DPI use 'hintslight' unless you are on a real low DPI monitor (i.e. < 50 DPI).

An example Template:Filename or Template:Filename file:

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

LCD filter patched packages

Many distributions choose not to use the LCD filter patches for font rendering packages yet because of patent ambiguity. If you choose, you can add these on your own; there are several packages/options to choose from:

  • All of these methods are LCD-oriented except "ClearType" which is designed to work on both LCD and CRT monitors.
  • These packages are in the Arch User Repository (AUR) and will need be be compiled by you. If you are new to this, consider using Yaourt or another AUR helper to help install them.
  • Configuration is sometimes necessary.
  • New font effects will not be implemented until the application restarts, restart your desktop environment (Xorg server) for full changes to take effect (logging out and it will do this most of the time).

Install

Various types of LCD filter patched-packages exist.

The original LCD packages

Remove the conflicting packages:

pacman -Rd libxft cairo

Install the patched packages from the AUR:

$ yaourt -S fontconfig-lcd cairo-lcd

And install the patched packages from the repositories:

pacman -S libxft-lcd

Ubuntu patched packages

Ubuntu has made their own LCD-related patches and can be found in the AUR. The conflicting font packages will need to be removed:

pacman -Rd libxft cairo fontconfig freetype2

And then install the patched packages from the AUR:

yaourt -S cairo-ubuntu fontconfig-ubuntu libxft-ubuntu freetype2-ubuntu

"ClearType" packages

There are more effects for fonts from Windows system, a somewhat differing type of font rendering.

Remove the conflicting packages:

pacman -Rd cairo libxft freetype2

And then install the patched packages from the AUR:

yaourt -S freetype2-cleartype libxft-cleartype cairo-cleartype

Restore the original packages

To restore the original packages, first uninstall the patched versions then reinstall the originals:

pacman -S freetype2 libxft cairo

LCD configuration

The fontconfig-lcd package originally uses the 'lcddefault' filter which is good for most uses. Other filters are available for various different lcd types:

New filter, fontconfig-lcd default:

<const>lcddefault</const>
  • Lighter filter, less aggressive (if fonts are too bold or fuzzy):
<const>lcdlight</const>
  • Legacy filter, cairo default:
<const>lcdlegacy</const>
  • None:
<const>lcdnone</const>

Additional fontconfig configuration

Generally additional configuration isn't necessary but additional options are available that may improve problem areas.

FreeType auto-hinter

You can set the FreeType autohinter:

# cd /etc/fonts/conf.d
# ln -s ../conf.avail/10-autohint.conf .

If you think fonts look too bold after enabling the auto-hinter, modify the fonts configuration file: edit (or create if it does not exist yet) the file Template:Filename with the following content:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
   <match target="font" >
      <test compare="more" name="weight">
         <const>medium</const>
      </test>
      <edit mode="assign" name="autohint">
         <bool>false</bool>
      </edit>
   </match>
</fontconfig>

Disable auto-hinter for bold fonts

The auto-hinter can give you nice font rendering, but often makes fonts too wide. This is especially annoying with bold fonts. Fortunately, you can turn off auto-hinter for bold fonts while leaving it on for the rest.

First turn on auto-hinter (see above), and add the following to ~/.fonts.conf:

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

In Template:Filename:

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

<match target="font" >
    <test compare<code>"more" name</code>"pixelsize" qual="any" >
        <double>17</double>
    </test>
    <edit mode<code>"assign" name</code>"antialias" >
        <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 to ~/.fonts.conf. This will cause Bitstream Vera Sans to be used in place of Helvetica:

...
<match target="pattern" name="family" >
    <test name="family" qual="any" >
        <string>Helvetica</string>
    </test>
    <edit mode="assign" name="family" >
        <string>Bitstream Vera Sans</string>
    </edit>
</match>
...

An alternate approach is to set the "preferred" font, but this only works if the original font is not on the system, in which case the one specified will be substituted:

...
< !-- Replace Helvetica with Bitstream Vera Sans Mono -->
< !-- Note, an alias for Helvetica should already exist in default conf files -->
<alias>
    <family>Helvetica</family>
    <prefer><family>Bitstream Vera Sans Mono</family></prefer>
    <default><family>fixed</family></default>
</alias>
...

Make font sizes match DPI settings

Edit ~/.fonts.conf with the following. This setting should match DPI settings in either xorg.conf or startx command. Use xdpyinfo to get the current DPI setting. Most users recommend/use a value of 96 or 100. For information on changing Xorg's DPI see: Xorg:DPI.

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

Bitmap fonts

Bitmap font configuration.

Disable

Most fontconfig versions (fontconfig, fontconfig-lcd...) disable the use of bitmap fonts. To be sure that they do:

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

To disable bitmaps for a single user rather than for all users, the code from Template:Filename would be added to the user's Template:Filename.

Now have fontconfig replace the bitmap fonts with TTF fonts:

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

Enable

By default, fontconfig disables the use of bitmap fonts. To enable bitmap fonts globally, these changes must be made to Template:Filename:

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

To make the above change for a single user, edit or create Template:Filename and append the contents of Template:Filename.

Be sure too the fonts aren't being replace by TTF fonts:

# rm /etc/fonts/conf.d/29-replace-bitmap-fonts.conf

Create bold and italic styles for incomplete fonts

Freetype has the ability to create italic and bold styles for fonts that do not have them, but only if required by the application. This rarely happens. To create these missing styles, you need to edit Template:Filename manually. You should store a copy of the modifications elsewhere, because a font update, with Template:Codeline, will overwrite Template:Filename.

Assuming you have the Dupree font:

"dupree.ttf" 0 "Dupree:style=Regular:slant=0:weight=80:width=100:foundry=unknown:index=0:outline=True:etc...

Duplicate the line, change Template:Codeline to Template:Codeline or any other styles you want. Also change Template:Codeline to Template:Codeline for italic, Template:Codeline to Template:Codeline 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 Template:Filename:

 
<match target="font">
    <test name="family" qual="any">
        <string>Dupree</string>
         <!-- other fonts here .... -->
     </test>
     <test compare="more_eq" name="weight"><int>140</int></test>
     <edit mode="assign" name="embolden"><bool>true</bool></edit>
</match>

<match target="font">
    <test name="family" qual="any">
        <string>Dupree</string>
        <!-- other fonts here .... -->
    </test>
    <test compare="more_eq" name="slant"><int>80</int></test>
    <edit mode="assign" name="matrix">
        <times>
            <name>matrix</name>
                <matrix>
                    <double>1</double><double>0.2</double>
                    <double>0</double><double>1</double>
                </matrix>
        </times>
    </edit>
</match>
Tip: You can use the value 'embolden' for existing bold fonts in order to make them even bolder.

Sample fontconfig setups

Save them as Template:Filename -- restart Xorg afterwards.

Example 1

A web developer's ~/.fonts.conf taken from the forums. Back up your current config before giving this one a try:

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

<!-- The cathectic LCD tweaks, from linuxquestions.org,
 http://www.linuxquestions.org/questions/showthread.php?postid=1361098#post1361098 -->

<fontconfig>

    <!-- Disable sub-pixel rendering.
         X detects it anyway, and if you set this as well, it just looks really horrible -->
    <match target="font" >
        <edit mode="assign" name="rgba" >
            <const>none</const>
        </edit>
    </match>

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

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

    <!-- The first part of the 'magic.'
         This makes the fonts start to look nice,
         but some of the shapes will be distorted, so hinting is needed still -->
    <match target="font" >
        <edit mode="assign" name="antialias">
            <bool>true</bool>
        </edit>
    </match>

    <!-- Autohinter is not turned on automatically.
         Only disable this if you have recompiled Freetype with the bytecode interpreter,
         which is run automatically. -->
    <match target="pattern" >
        <edit mode="assign" name="autohint">
            <bool>true</bool>
        </edit>
    </match>
  
    <match target="font">
        <test name="weight" compare="more">
            <const>medium</const>
        </test>
        <edit name="autohint" mode="assign">
            <bool>false</bool>
        </edit>
    </match>

    <!-- Helvetica is a non true type font, and will look bad.
         This replaces it with whatever is the default sans-serif font -->
    <match target="pattern" name="family" >
        <test name="family" qual="any" >
            <string>Helvetica</string>
        </test>
        <edit mode="assign" name="family" >
            <string>sans-serif</string>
        </edit>
    </match>
    <dir>~/.fonts</dir>
</fontconfig>

Example 2

This configuration [2] was made by brebs. It has been lightly edited:

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

    <!-- Info:
         xeffects thread: http://forums.gentoo.org/viewtopic-t-511382.html
         http://wiki.archlinux.org/index.php/XOrg_Font_Configuration
         http://antigrain.com/research/font_rasterization/index.html
         http://fontconfig.org/fontconfig-user.html -->


    <!-- http://bugs.gentoo.org/show_bug.cgi?id=130466 -->
    <alias>
        <family>serif</family>
        <prefer>
            <family>DejaVu Serif</family>
            <family>Bitstream Vera Serif</family>
        </prefer>
    </alias>

    <alias>
        <family>sans-serif</family>
        <prefer>
            <family>DejaVu Sans</family>
            <family>Bitstream Vera Sans</family>
            <family>Verdana</family>
            <family>Arial</family>
        </prefer>
    </alias>

    <alias>
        <family>monospace</family>
        <prefer>
            <family>DejaVu Sans Mono</family>
            <family>Bitstream Vera Sans Mono</family>
        </prefer>
    </alias>

    <!-- Reject bitmap fonts in favour of Truetype, Postscript, etc. -->
    <selectfont>
        <rejectfont>
            <pattern>
                <patelt name="scalable">
                    <bool>false</bool>
                </patelt>
            </pattern>
        </rejectfont>
    </selectfont>

    <!-- Replace Luxi Sans with a better-looking font - looks terrible at e.g. http://market-ticker.org/ -->
    <match name="family" target="pattern">
        <test name="family" qual="any">
            <string>Luxi Sans</string>
        </test>
        <edit name="family" mode="assign">
            <string>Liberation Sans</string>
        </edit>
    </match>

    <!-- To fix Calibri font - http://forums.fedoraforum.org/showthread.php?p=1045807#post1045807 -->
    <match target="font">
        <edit name="embeddedbitmap" mode="assign">
            <bool>false</bool>
        </edit>
    </match>

    <match target="pattern" name="family">
        <test qual="any" name="family"><string>fixed</string></test>
        <edit name="family" mode="assign"><string>monospace</string></edit>
    </match>

    <!-- Ubuntu options: lcdnone, lcddefault, lcdlight, lcdlegacy -->
    <!-- hintnone, hintslight, hintmedium, hintfull -->
    <!-- Keep autohint off -->
    <!-- Blurry fonts: Try rgb, bgr, vrgb, vbgr for "rgba" -->
    <!-- Blurry: http://forums.gentoo.org/viewtopic-p-5060979.html#5060979 -->
    <match target="font">
        <edit name="rgba" mode="assign"><const>rgb</const></edit>
        <edit name="autohint" mode="assign"><bool>false</bool></edit>
        <edit name="antialias" mode="assign"><bool>true</bool></edit>
        <edit name="hinting" mode="assign"><bool>true</bool></edit>
        <edit name="hintstyle" mode="assign"><const>hintmedium</const></edit>
        <edit name="lcdfilter" mode="assign"><const>lcddefault</const></edit>
    </match>

    <!-- Reduce hinting for bold fonts -->
    <match target="font">
        <test name="weight" compare="more"><const>medium</const></test>
        <edit name="autohint" mode="assign"><bool>false</bool></edit>
    </match>

    <!-- Tweak Courier -->
    <match name="family" target="pattern">
        <test name="family" qual="any">
            <string>Courier</string>
        </test>
        <edit name="lcdfilter" mode="assign"><const>lcdlegacy</const></edit>
    </match>

    <!-- Tweak Courier New -->
    <match name="family" target="pattern">
        <test name="family" qual="any">
            <string>Courier New</string>
        </test>
        <edit name="lcdfilter" mode="assign"><const>lcdlegacy</const></edit>
    </match>

    <!-- From http://forums.gentoo.org/viewtopic-t-511382-start-650.html
         To create difference between small Candara and small Candara bold -->
    <match name="family" target="pattern">
        <test name="family" qual="any">
            <string>Candara</string>
        </test>
        <test compare="less_eq" name="size">
            <double>10</double>
        </test>
        <test name="weight" compare="more">
            <const>medium</const>
        </test>
        <edit name="embolden" mode="assign">
            <bool>true</bool>
        </edit>
    </match>

    <!-- From http://www.fedoraforum.org/forum/showthread.php?t=186789&page=7 -->
    <match target="font">
        <test compare="eq" name="family">
            <string>Consolas</string>
        </test>
        <edit mode="assign" name="hintstyle">
            <const>hintslight</const>
        </edit>
    </match>

    <match target="font">
        <test compare="eq" name="family">
            <string>Inconsolata</string>
        </test>
        <edit mode="assign" name="hintstyle">
            <const>hintslight</const>
        </edit>
    </match>

    <!-- From http://bugs.gentoo.org/show_bug.cgi?id=233729 -->
    <match target="font">
        <test compare="eq" name="family">
            <string>Andale Mono</string>
        </test>
        <edit mode="assign" name="hintstyle">
            <const>hintfull</const>
        </edit>
        <test compare="less" name="weight">
            <const>medium</const>
        </test>
        <test compare="less_eq" name="pixelsize">
            <double>7</double>
        </test>
        <edit mode="assign" name="antialias">
            <bool>false</bool>
        </edit>
    </match>

    <match target="font">
        <test compare="eq" name="family">
            <string>Arial</string>
        </test>
        <edit mode="assign" name="hintstyle">
            <const>hintfull</const>
        </edit>
        <test compare="less" name="weight">
            <const>medium</const>
        </test>
        <test compare="less_eq" name="pixelsize">
            <double>7</double>
        </test>
        <edit mode="assign" name="antialias">
            <bool>false</bool>
        </edit>
    </match>

    <match target="font">
        <test compare="eq" name="family">
            <string>Comic Sans MS</string>
        </test>
        <edit mode="assign" name="hintstyle">
            <const>hintfull</const>
        </edit>
        <test compare="less" name="weight">
            <const>medium</const>
        </test>
        <test compare="less_eq" name="pixelsize">
            <double>7</double>
        </test>
        <edit mode="assign" name="antialias">
            <bool>false</bool>
        </edit>
    </match>

    <match target="font">
        <test compare="eq" name="family">
            <string>Georgia</string>
        </test>
        <edit mode="assign" name="hintstyle">
            <const>hintfull</const>
        </edit>
        <test compare="less" name="weight">
            <const>medium</const>
        </test>
        <test compare="less_eq" name="pixelsize">
            <double>7</double>
        </test>
        <edit mode="assign" name="antialias">
            <bool>false</bool>
        </edit>
    </match>

    <match target="font">
        <test compare="eq" name="family">
            <string>Impact</string>
        </test>
        <edit mode="assign" name="hintstyle">
            <const>hintfull</const>
        </edit>
    </match>

    <match target="font">
        <test compare="eq" name="family">
            <string>Times New Roman</string>
        </test>
        <!-- Looks better with lcdlegacy, e.g. http://www.billiardworld.com/glossary.html -->
        <edit name="lcdfilter" mode="assign"><const>lcdlegacy</const></edit>
        <edit mode="assign" name="hintstyle">
            <const>hintfull</const>
        </edit>
    </match>

    <match target="font">
        <test compare="eq" name="family">
            <string>Trebuchet MS</string>
        </test>
        <edit mode="assign" name="hintstyle">
            <const>hintfull</const>
        </edit>
        <test compare="less" name="weight">
            <const>medium</const>
        </test>
        <test compare="less_eq" name="pixelsize">
            <double>7</double>
        </test>
        <edit mode="assign" name="antialias">
            <bool>false</bool>
        </edit>
    </match>

    <match target="font">
        <test compare="eq" name="family">
            <string>Verdana</string>
        </test>
        <edit mode="assign" name="hintstyle">
            <const>hintfull</const>
        </edit>
        <test compare="less" name="weight">
            <const>medium</const>
        </test>
        <test compare="less_eq" name="pixelsize">
            <double>7</double>
        </test>
        <edit mode="assign" name="antialias">
            <bool>false</bool>
        </edit>
    </match>

    <match target="font">
        <test compare="eq" name="family">
            <string>Webdings</string>
        </test>
        <edit mode="assign" name="hintstyle">
            <const>hintfull</const>
        </edit>
    </match>

</fontconfig>

Troubleshooting

Distorted fonts

If your fonts are unexpectedly large or small, or are poorly proportioned, the Xorg server may be incorrectly detecting your DPI setting. See Xorg#Display_Size.2FDPI for more information.

Missing Characters

For an older program or for the rare program that uses them, it may help to activate bitmap fonts:

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

This will likely cause some fonts that looked fine before to become jagged so use this only if you need to.

If you are using Emacs, you will need to have the Template:Package Official and Template:Package Official packages installed.

Older GTK and QT applications

Modern GTK apps enable Xft by default but this was not the case before version 2.2. If it is not possible to update these applications, you can force Xft for old GNOME applications by adding to your Template:Filename:

export GDK_USE_XFT=1

For older QT applications:

export QT_XFT=true

Resources