up

Unix/X font stuff: debugging fontconfig problems

The year 2002 saw a lot of changes for fonts in Linux. XFree86 moved to using fontconfig, which gives most common applications support for high-quality anti-aliased outline font support under the X Window System.

There's also a page about rune fonts.

If you're not yet using fontconfig, I still have a page about X Logical Font Descriptions, including my xlfd script and my xfonttol program for exploring X fonts.

This page may help you troubeshoot some common problems with fontconfig.

note: Mandrake Linux 9.x and Mandriva Cooker users, you want the following (or later):

Use
rpm -q fontconfig
to check, and
urpmi fontconfig
to upgrade.

Note that XFree86-libs-4.3-1mdk and later provides libXft, and you should not have any other libXft.so installed than the ones XFree86-libs gives you.

If you were running Mandriva Linux 2005 or 2006, and have upgraded either to Cooker or to a newer release, make sure you run fc-cache as root, and also that each user runs fc-cache -v (you could do that once with a shell script if you have lots of users).

No fonts found

Make sure that there is a fonts.cache-2 file in the /usr/X11R6/lib/X11/fonts/TTF directory (for relases of fontconfig earlier than 2.3 the file was called fonts.cache-1). If not, run
fc-cache -f -v
as root, and watch carefully to see where it found fonts. If it didn't seem to look in /usr/X11T6/lib/X11/fonts you should check your /etc/fonts/fonts.conf file carefully. even the slightest error in that file will stop all your fonts from working.

Still stuck? Try
fc-list | wc -l
which will tell you how many outline fonts were found on yuor system.

If fc-list says you have lots of fonts, but Gnome applications such as gedit can't find them (or xterm or any other programs that you know to use fontconfig), and you get a message about no fonts being found, there may be a cache problem or a permissions problem, see next two items.

fc-cache says I have fonts but gedit says, No fonts found

There are three likely causes.

  1. A cache bug
  2. File permissions
  3. One or more corrupt fonts

A cache bug

Make sure you have fontconfig release 2.1.9 or later (for Mandrake Linux, the fix is in 2.1.7 and later).

File permissions

use ls -l, or try tar cf - /dev/null TTF to check that you have permission to read all the files. If you have fonts mounted on a network drive (and the license for the fonts allows you to share them!!) remember that the root user generally can't override permissions on NFS-mounted filesystems.

One of more corrupt fonts

There are several ways to investigate this. One is to use a program like gfontview on the font directory and see if the program reports errors for any of the fonts. Start the program from a terminal (e.g. from inside gnome-terminal) so you see the errors. Another is to take half of the fonts and move them to a directory that's not under /usr/X11R6/lib/X11/fonts and then run fc-cache -f $(pwd) in the font directory, and see if the problem goes away. If it does, the bad font or fonts are all in the ones you moved away.

Programs don't run at all, I get a symbol not defined or something

Make sure your libXft.so is in /usr/X11R6/lib/ and that you don't (for example) have an older Xft package that's put a copy of that library in /usr/lib as well. On Mandrake or Red Hat or other RPM-based distributions of Linux, the command
rpm -qf /usr/lib/libXft.so
will tell you which package (if any) owns the file /usr/lib/libXft.so, if it exists.

If you have recently installed fontconfig, you might on some systems need to run (as root)
ldconfig
to update the system's idea of what libraries are available.

KDE isn't using anti-aliased fonts

KDE supports both bitmap (native X11) and scaled (fontconfig) fonts, but only antialiases fontconfig fonts. Experiment with the Settings.

Everything starts up really slowly!

There are several common causes of this.

  1. You get a message Warning: Missing charsets in String to FontSet conversion, for example if you start xclock from a console/terminal window.
  2. The disk churns for a long time but no errors

(1) Missing charsets

In the first case, the problem is that your locale setting is trying to bring in one or more fonts that are not installed. This often happens if you are using Unicode UTF-8 and you don't have some font or other. The following shell script will help you determine if this is the problem:

#! /bin/sh
 export CHARSET=
 export LC_ADDRESS=
 export LC_COLLATE=
 export LC_CTYPE=
 export LC_IDENTIFICATION=
 export LC_MEASUREMENT=
 export LC_MESSAGES=
 export LC_MONETARY=
 export LC_NAME=
 export LC_NUMERIC=
 export LC_PAPER=
 export LC_TELEPHONE=
 export LC_TIME=
 export LESSCHARSET=
 exec "$@"
 

Put the above lines in a file called nolocale, run chmod +x nolocale and then try, ./nolocale xclock

If it comes up without the message, this is your problem.

There are two ways to fix it. The best is to install fonts for Japanese, Chinese, Korean, Arabic, and so on. If this still does not work (as in my case), edit the file /usr/X11R6/lib/X11/locale/en_US.UTF-8/XLC_LOCALE (carefully) and put a # in front of some of the entries. For me, there is only one entry that causes the problem, so here is that entry shown commented out. It's best if you do this in a separate window (got to be the root user anyway): that way you can first save a copy, e.g. in your login directory, and then make the changes and save the file without quitting the editor, quickly testing in another window.

 #       fs6 class (koi8-r)
 # uncommenting this causes glacial slowness - Liam
 # fs6   {
 #       charset {
 #               name    KOI8-R:GR
 #       }
 #       font    {
 #               primary KOI8-R:GR
 #       }
 # }
 

Note: to diagnose this, I used the following command:
strace xclock 2>&1 | egrep '(open|Missing.charsets)' > /tmp/str
The strace program runs its argument as a command, but logs all system commands. I was looking for configuration files and libraries opened before the error message was printed.

(2) General slowness

Before you do anything else, try this as root:

rm /var/cache/fontconfig/*
 fc-cache -f -v
 

Then remove any .fonts.cache* files in your login directory and run
fc-cache -f -v
yourself. After that there should be a new .fonts.cache-2 file in your login directory; if not, check you have the latest fontconfig package, and also look carefully at the output of when you ran fc-cache to see if there were error messages. For example, if you don't have permission to create files in your login directory, you might need to do chmod u+w $HOME
at least for long enough for fc-cache to work. You can also use chmod -R u+w $HOME to change all of the files and directories from your login folder downwards, but you can't undo this so easily.

If you have a nice shiny fonts.cache-2 You can use the same strace technique as shown above to see what files are being opened; you might also try checking your .fonts.conf file, if you have one, or renaming it temporarily, to see if it contains an error.

Finally, note that if everything starts slowly, maybe you don't have enough memory, or are starting too many services on boot? use
top to see what's running, and press M to sort by memory usage; the VIRT, RES and SHR columns are most important. RES is the amount of memory an application has in physical memory, so if you have two gigabytes of RAM in your laptop, say, and mozilla is using 2.5G of VIRtual mempory and has 1.8G RESident, you don't have so much memory left over for other programs. The SHR column tells you how much of the VIRTual memory a program is sharing with other programs. The numbers are in kilobytes unless they have an m or g after them, in which case they are in megabytes or gigabytes.

If you don't have much memory, you can use the Mandriva Control Centre (or YaST, or chconfig on some systems) to change which services get started when the system boots; the apache Web server and MySQL are common candidates to shut down, since you can restart them when you need them (e.g. service httpd start; pressing a space and then a tab after the service command will show the list of services, if you have the package installed).

Evolution isn't antialiased!

That's probably because it's still using Gnome 1.4, not Gnome 2, and does not have support for fontconfig. This command tells me that (for example) gedit uses fontconfig:
ldd $(which gedit) | grep font
The output on my system is,
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x4048c000)
If there's no output, the program is not linked against fontconfig, and probably won't support antialiased fonts.

For Evolution, there's a newer version that uses Gnome 2 and is all antialiased and pretty. This is true for many other programs too. You could also try,
export GDK_USE_XFT=1 QT_USE_XFT=1 USE_XFT=1 LANG=en_CA
evolution &
and see if that helps. The same settings may help other programs, too.

I can't tell if it's working or not

You can use xmag (or xv or gimp) to enlarge a section of the screen. Antialiased fonts use several levels of grey, not just black. Here are links to two shots, one with no anti-aliasing and one with antialising, for you to compare. (most browsers let you opern a ilnk in a new window, often by right-clicking on the link).

It doesn't work in all programs

Not all programs are compiled to use fontconfig. For example, The Gimp needs to be version 1.3 or later (in Mandrake you can install this with urpmi if you have set up a contrib (RPMS2) source). Evolution needs to be version 1.2 or later. Mandrake 9.1 included versions of these and other programs linked with fontconfig, as do later versions of Mandrake Linux and Mandriva Linux.