X.Org/Fonts

This article will walk you through the steps necessary to make fonts considerably more readable.

Background
Fonts on computers, in general and on Linux's X11 in particular, are a messy affair. There are many different font formats, ranging from old bitmap fonts to TrueType fonts. In addition, many fonts have problematic licensing and embedding issues. Finally, the main font rendering programs suffers from patent issues -- which Apple, fortunately, has not enforced yet -- if you want to turn on hinting, which only adds to the confusion.

Many programs, notably Ghostscript, Mozilla, OpenOffice.org and TeX, have their own ideas about fonts and font configuration. This means that the information in this article may not be sufficient to get your fonts to work.

To give you an idea: X11 does not have one font subsystem, but two! The old "core X font subsystem" have names like -misc-fixed-medium-r-normal--10-100-75-75-c-60-iso8859-1. The newer font system is known as fontconfig, works with the Xft library and, hopefully, will eventually replace the old system entirely. In addition, there is a font server named xfs.

On DPI
Before any software based tweaks, the best thing you can do to make sure that you get good looking fonts under Linux is to use an LCD/CRT monitor with at least 96 dpi (dots per inch). To calculate this, take the horizontal resolution and divide it by the width of the LCD/CRT screen (in inches). Anything less than 96 dpi will produce noticeable problems that no amount of tweaking will fix.

CRT's will almost always render fonts blurrier than LCD's because of the inherent blurring from the electron beam scan and the phosphor coated screen.

Emerging "Essential" Packages
You will need the global USE flag for various packages.

If you plan to run the KDrive Tiny X Server, you should set.

Only if you will be running an X-Server for multiple clients should you need the USE flag.

Essential high quality fonts: Other popular fonts:

If you want to see your national characters by default, then you should use dejavu font instead of ttf-bitstream-vera. To get it perform following steps:

Enable the USE flags either by editing or running:

And, if you plan to use KDrive Tiny X Server :

If you updated your USE flags, you should reemerge world:

Then, emerge the packages (you can skip some of the unnecessary ones):

For X.Org 7.0: If you use UTF-8, you will need fonts for Eastern/CJK character sets. Some examples:

Fonts for Programmers
Programmers often need monospaced fonts that are readable at small sizes. The following fonts are not in Portage, but are freely available and worth searching Google for:


 * Aurulent Sans Mono
 * Bitstream Cyberbit
 * Monaco
 * Dina
 * Tamsyn
 * TeX Gyre Collection
 * Serif Monospaced Fonts
 * Verily Serif Mono

Windows Fonts
If you feel constrained by the free fonts, Microsoft Windows, Office, et cetera, come with some excellent fonts that are not included in media-fonts/corefonts. True Type Fonts can be installed in the directory and subdirectories below it, and are detected automatically when the X system is started. If you haven't wiped your Windows partition yet, the files you'll find there could be used with X.Org. Note that in order to use those fonts legally, you must have an appropriate license.

Some of Windows Vista's fonts deserve special mention: Candara, Consolas (monospaced) and Corbel.

One of the common problems is wrong rendering of MS Office presentations due to the use of new Vista's (and Office) ClearType fonts not available in Portage (e.g. Calibri, Cambria or the above mentioned). Search for vista-fonts.ebuild over the net in that case.

Emerging the Unnecessary Fonts
If you are the kind of person who absolutely must have every available font installed, here is the command that will do so:

Hinting Information
Hinting is part of the rendering process of a font. In general, hinting guides the rasterizer so that it produces a better looking onscreen font, especially with smaller font sizes. Due to possible patent issues, FreeType has the option of being compiled with or without TrueType's BCI, Byte Code Interpreter.

Without BCI, the default, FreeType uses its own auto-hinter to improve the quality of fonts at small sizes. The auto-hinter is still a work in progress, and improves with each release of FreeType. The auto-hinter usually produces excellent results, however, many feel that TrueType's native BCI produces results superior to the auto-hinter, especially on combined dual-head layouts, as it uses the hinting information contained in the font.

If you live in a country where software patents are not an issue or you interpret the possible patent issues as unlikely since Apple knows about FreeType and hasn't filed a lawsuit, you can enable the BCI by disabling the USE Flag. See The FreeType Project's article on FreeType and Patents for more information.

If you find out that fonts are too fuzzy on your LCD panel, please try to enable and see the difference. It might work better for you.

'EDIT 09/2010: The TrueType bytecode interpreter is no longer patented and thus no longer controlled by the bindist USE flag. Enable the auto-hinter USE flag if you want the old USE=bindist hinting behavior.'

Fixing Firefox
Firefox uses the Cairo backend for rendering graphics. Cairo is a vector graphics backend. However, fonts are rendered as bitmaps. This is why some web page text look discolored only in Firefox. There is a patch from Arch to render bitmaps correctly for LCDs. The cleartype flag is required for cairo

That's it. Restart Firefox to see the effect. Also see original article.

There appears to be a newer 'lcdfilter' use flag that overrides the cleartype flag. See the lcdfilter homepage and this forum post.

Configuration Files
With the fonts installed, you now have to modify the configuration files in order to allow the system to recognize them. These are the files you have to modify: You can use, a part of the media-libs/fontconfig package, to check which fonts are installed. For visuals on available fonts, try and, a Unicode character map viewer.

The Xft Font System
The system wide configuration file resides at, while is an optional user font configuration file which takes precedence over system wide changes, except in regards to anti-aliasing settings which cannot be overridden by users.

You do not need to set all the font directories unless you install fonts in non-standard places. includes and everything beneath that, as well as a few other directories such as.

Note that and  are XML files that and are easier to edit with an editor that supports XML syntax highlighting. Included in the following example are many options you may want to use:

Some settings should not reside in a system wide configuration file, unless it is certain that all users will approve of such tweaks. Such settings may be better set in.

Remember that all changes to are system wide and will be overridden by, except for the anti-aliasing setting which will be forced on if set in the system wide file. The syntax of is exactly the same as the local user font configuration file, therefore you may copy either file and rename it as the other.

Hinting
You will almost certainly want to use some form of font hinting. There are two forms of hinting supported by Gentoo Linux:

Auto-Hinting
By default, FreeType's auto-hinting is used, and is the default setting in the example configuration file. When using auto-hinting, however, you will most likely want to disable auto-hinting on bold fonts to prevent them from appearing too wide. The example file defaults auto-hinting on bold fonts to be off.

TrueType Bytecode Interpreter (BCI)
If you have compiled FreeType to use the TrueType bytecode interpreter (see above), and wish to use the BCI, then turn the auto-hinting off entirely. To do this, have  true  set to false instead of true. There are possible patent issues with using the TrueType BCI; if you wish to avoid the issue entirely, don't use the BCI.

Both KDE and GNOME have nice GUI's in which the user can select between 'light,' 'medium,' and 'strong' hinting. This appears to refer to the FreeType auto-hinter, and not the BCI. If you use the BCI, the only settings that seem to make any difference is to have hinting off entirely, which looks ugly. In other words light, medium, and strong hinting appear to all look identical when the BCI is used instead of the auto-hinter.

Sub-Pixel Rendering
In the above file, the sub-pixel rendering option is commented out because it is only useful for LCD panels. When enabled on a CRT display it only causes X.Org to do more rendering work. Possible values are for the sub-pixel rendering type none, rgb, bgr, vrgb and vbgr. The most common type of LCD panel is of the RGB variety, which is what the example above uses.

Anti-Aliasing
The anti-aliasing option is commented out because some people prefer to exclude or include a set of font sizes from getting anti-aliasing applied to them. It is a common tweak that makes your fonts look much more like Microsoft Windows' default fonts. When disabling anti-aliasing make sure to also disable sub-pixel rendering to achieve the best non anti-aliased fonts.

User Fonts
If you have your own fonts in a different directory than the default or, here's how to add them:

X.Org
When configuring X.Org, it is important that it has the correct understanding of the size of your screen. For the best results, have the resolution in X.Org set to the native resolution of your LCD and/or set for a comfortable resolution for your CRT that maintains an appropriate aspect ratio for your display; this is actually more important than it seems as fonts in GTK+ applications seem to be disfigured by improper screen information and may also reveal itself in other applications.

Setting Screen Resolution
The configuration file is split into sections. The following is an example of the screen section, which deals with, oddly enough, display screens.

Fonts and DPI
https://wiki.archlinux.org/index.php/Xorg#Display_Size_and_DPI

Listing Fonts
Next you have to list your font directories in. The font paths are searched in the order they are listed, so before you're done you'll have to tweak that order a bit.

Reasonably modern applications and desktop environments such as Gnome and KDE use fontconfig, so the only fonts that are actually required via the X server (or font server) is fixed and cursor.


 * /usr/share/fonts/misc:unscaled

The first path we want on our list is /usr/share/fonts/misc. This is where the all important fixed and cursor fonts are kept. These are crucial for the proper operation of X.Org. This is where the default cursor is located, and putting it first in the path keeps X from using the custom cursors that some font packages install.

The :unscaled option tells X to use the unscaled versions of these fonts whenever possible to prevent pixelization. This can apply to any bitmap font.


 * /usr/share/fonts/75dpi:unscaled
 * /usr/share/fonts/100dpi:unscaled

These are the base bitmap fonts. We usually want 75dpi to be loaded before 100dpi since a lot of themes expect it. Most modern monitors will have a high DPI however, so if you find yourself squinting to read menus, you might want to experiment switching the order.


 * /usr/share/fonts/Type1
 * /usr/share/fonts/TTF

Type1 and TrueType fonts. The order shouldn't matter much, but might be notable that both of these packages contain the Luxi Sans/Serif/Mono fonts.


 * /usr/share/fonts/corefonts
 * /usr/share/fonts/freefonts

These are Microsoft's TrueType core fonts and a collection of TrueType fonts, respectively.


 * /usr/share/fonts/artwiz
 * /usr/share/fonts/terminus
 * /usr/share/fonts/ttf-bitstream-vera
 * /usr/share/fonts/unifont

If you emerged the packages suggested above you should also have this list of fonts.


 * /usr/share/fonts/local
 * /usr/share/fonts/cyrillic

These are usually not needed, and are mostly empty or non-existent. To be sure check the file fonts.dir inside each directory. If this file contains a '0' the directory does not need to be added to the font path.


 * /usr/share/fonts/*everythingelse*

All the directories of the new fonts you just emerged. The order shouldn't matter as most of the fonts these packages provide are unique. If you're worried about a particular font, place it higher up. You can check a list of what fonts are provided in each directory's file.

Now to make a few final changes to the order. Take the base bitmap fonts and put them last. This is because we now have much better TTF or Type1 versions of some of these fonts we'd rather use. Also, contains a lot of, um, core fonts and should be pretty high on the list.

The end result should look something like this:

Listing the Unnecessary Fonts
The following Python script will find all of the fonts that you've installed and run mkfontdir on those that haven't had it done yet, and generate output that you can copy and paste into : fontlist_fix.py

Restarting Services
After modifying config files, you have to restart X.Org. If you use an X display manager such as GDM, KDM, XDM, etc., you may be able to simply log out of your session and restart X by pressing Ctrl+Alt+Backspace at the login screen. If that doesn't work, restarting X.Org is possible by restarting the xdm service.

Someone could notice a system freeze by launching the following commands in X.Org, so you should launch them in another terminal. That is press CTRL + ALT + F1 and log in. (Pressing ALT + F7 will return you to X from the console.)

After executing this command, your X display manager should restart. You should have anti-aliased fonts after logging back in.

<!-- == Applications ==

Mozilla Firefox
Make sure you have started Firefox at least once, so that you have a profile in.

Go to about:config in your browser, or alternatively, edit the user.js file in, where xxx are letters or numbers.

Firefox 1.0.4 keeps a prefs.js file in where xxx is a string of numbers and letters.

Through the about:config dialog, or in the user.js file you have to insert the following lines as shown below:

If you have followed this HOWTO you shouldn't have problem with the listed directories, otherwise you can change them.

In Firefox 1.0, go to Edit » Preferences » General » Fonts & Colors.

In Firefox 1.5, go to Edit » Preferences » Content » Fonts & Colors » Advanced.

Then, set these parameters:
 * Proportional: Serif (Size: 16)
 * Serif: Bitstream vera serif
 * Sans-serif: Bitstream vera sans
 * Monospace: Bitstream vera sans mono (Size: 12)
 * Display Resolution: System setting

You should also check that the following boxes are not ticked: Always use my: Fonts

Then restart Firefox and browse www.gentoo.org with antialiased fonts!

If you are using KDE and Firefox is not antialiased after this, go to Control Centre->Appearance and Themes->Fonts, disable anti-aliasing, hit apply, and then enable anti-aliasing and hit apply.

Mozilla Thunderbird
There are very few options in Thunderbird that relate to fonts, so all options must be applied to user.js. Create this file in (or, in newer versions, ). In user.js you have to insert the same lines as were entered for Mozilla Firefox: note: prefs.js is generated by thunderbird at runtime, you must create user.js in the same directory to make persistent changes.

Then, with Thunderbird 1.0.2 opened, go to: Edit » Preferences » Fonts Or (on 0.7) Tools » Options » Fonts and set these parameters:
 * Proportional: Serif (Size: 16)
 * Serif: Bits-bitstream vera serif
 * Sans-serif: Bits-bitstream vera sans
 * Monospace: Bits-bitstream vera sans mono (Size: 12)
 * Minimum font size: 9

You should also check that the following boxes are ticked:
 * Allow messages to use other fonts

Then restart Thunderbird and read your mail with crisp, clean fonts!

KDE Applications Size Problems
If in your kde apps the fonts are the wrong size but you don't have kde installed (you can not change it from Control Center) you just have to edit your with something like:

The number after the font name is the size.

It happened that the Firefox toolbar/menu fonts were enormous. To solve just add to your :

and do the same for Thunderbird

If somehow the '*' does not work for you, this CSS snippet covers most of the Firefox/Thunderbird GUI:

In one case, after making all those changes, the fonts for the input fields (buttons, text entry, or drop-down menus) in some web pages like Google or Amazon were way too big and still using one of the ugly fonts. To change that, go to userContent.css (that's different from the userChrome.css file we just modified), and add the following entry:

Konsole
KDE users probably know Konsole, the KDE X terminal emulator. But some users get the following error if they try to use the Linux font: Font `-misc-console-medium-r-normal--16-160-72-72-c-80-iso10646-1' not found.

You can solve this by executing the following steps:
 * 1) Start kdesu kcmshell kcmfontinst when you are in kde.
 * 2) Give the root password.
 * 3) Click on the add fonts icon (an @-sign with a +-sign on it)
 * 4) Go to the dir /usr/kde/3.2/share/fonts/ and add all fonts (files ending in .pcf.gz) available.

Blurry and Unreadable Fonts
If your fonts occasionally become unreadable in Gnome 2.12, completely disabling anti-aliasing by commenting out those sections in and  as they are in the examples above should solve this problem.

Startx Error
If you get the following when trying to startx: "Fontconfig warning: no elements found. Check configuration." "Fontconfig warning: adding /var/cache/fontconfig " "Fontconfig warning: adding ~/.fontconfig

An easy fix to this is to run:

XEmacs
If after all this work, you find that you do not have a good font for XEmacs, which does not support anti-aliasing, then try the neep fonts. The package you need is

Then add another FontPath entry in your xorg.conf, like so:

Restart the font system (exit from X), then try setting your XEmacs font to "Neep Alt". You probably want the "alt" version since the regular version has a wonky ampersand character. -->