Font configuration

From ArchWiki
Revision as of 15:37, 19 January 2010 by Madalu (talk | contribs) (Deleted claim that lcd packages in AUR do not work. They build and work fine as of Jan 19, 2010.)
Jump to: navigation, search

Template:Article summary start Template:Article summary text Template:Article summary heading Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary end

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

Seeing that this shows a great deal of information, cut through the noise by using other tools to filter the output:

fc-list | sed s,:.*,, | sort -u

Fontconfig configuration

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

Configuration can be done either per-user or globally. If you configure your fonts globally using Template:Filename, note that in some desktop environments the DE's Font Control Panel will create a user font configuration file, Template:Filename, whenever the font control panel is opened. Both Gnome and KDE do this. This local configuration file takes precedence over the global one. For these desktop environments, it is best to use their control panels and duplicate the 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 listed in Template:Filename and can be linked using commands similar to this:

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

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

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>
      <edit mode="assign" name="hinting">
         <bool>true</bool>
      </edit>
      <edit mode="assign" name="hintstyle">
         <const>hintslight</const>
      </edit>
      <edit mode="assign" name="antialias">
         <bool>true</bool>
      </edit>
   </match>
</fontconfig>

LCD filter patched packages

Some distributions choose not to use the LCD filter patches for font rendering due to patent ambiguity. If you choose, you can add these patched packages on your own. There are several options.

  • All of these methods are designed for LCD displays but some CRT users may see improvements using the ClearType packages.
  • These packages are in the Arch User Repository (AUR) and must be compiled using makepkg. If you are new to this, consider using Yaourt or another AUR helper to install them.
  • Configuration is sometimes necessary.
  • The new font effects will not be displayed until the application restarts. Restart your desktop environment (Xorg server) for the full changes to take effect; logging out and then back in will usually do this.

Installation

Three sets 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; these are found in the AUR.

First, the conflicting packages need to be removed:

pacman -Rd libxft cairo fontconfig freetype2

Then the patched packages are installed:

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

ClearType packages

There are more effects for fonts from Windows system, a somewhat 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 Template:Codeline filter which is good for most uses. Other filters are available for various different lcd types: Template:Codeline (lighter filter for fonts that look too bold or fuzzy), Template:Codeline (old, and cairo default), Template:Codeline (to disable). Example fontconfig lcd-type configuration:

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

Additional fontconfig configuration

Generally additional configuration isn't necessary but additional options are available that may improve problematic 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>

Note that the rest of the configuration excerpts ommit the bolded header and footer tags. These are required to be present.

Disable auto-hinter for bold fonts

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

First turn on auto-hinter (see above), and add the following to Template:Filename:

...
<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">
    <edit mode="assign" name="antialias">
        <bool>false</bool>
    </edit>                
</match>

<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 Template:Filename. 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

Fontconfig should be able to detect your DPI as discovered by the Xorg server and be able to display the fonts correctly. For those having problems, it can be set manually. For information on the Xorg's DPI, see: Xorg#Display_size_and_DPI.

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

Disable bitmap fonts

To disable bitmap fonts in fontconfig, use Template:Filename:

# rm /etc/fonts/conf.d/70-yes-bitmaps.conf # not enabled by fontconfig by default
# cd /etc/fonts/conf.d/
# ln -s ../conf.avail/70-no-bitmaps.conf

Then to replace some (Helvetica, Courier and Times) bitmap fonts with TTF fonts:

# ln -s ../conf.avail/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 Template:Filename (modified) 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>

    <match target="font" >
        
        <!-- Disable sub-pixel rendering.
             X detects it anyway, and if you set this as well, it just looks really horrible -->
        <edit mode="assign" name="rgba" >
            <const>none</const>
        </edit>
        
        <!-- Autohinter is not turned on automatically.
             Only disable this if you have recompiled Freetype with the bytecode interpreter,
             which is run automatically. -->
        <edit mode="assign" name="autohint">
            <bool>true</bool>
        </edit>
        <!-- Change hintstyle to full -->
        <edit mode="assign" name="hintstyle">
            <const>hintfull</const>
        </edit>
        
        <!-- 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 -->
        <edit mode="assign" name="antialias">
            <bool>true</bool>
        </edit>
    
    </match>

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

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

</fontconfig>

Example 2

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

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

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


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

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

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

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

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

    <!-- 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 and DPI for more information.

Missing Characters

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