Truetype fonts in XFree86 4.2.0 

http://www.linuxcompatible.org/forums/viewtopic.php?t=19

I am sure everyone can agree that the standard fonts of XFree are rather crappy. There are many howtos on making them look better, or using other fonts. Here you will find yet another howto, cookbook or whatever you want to call it….

The guys from Redmond have a habit of taking care of the looks quite a bit more than of security and that is actually to our advantage. We can 'borrow' their fonts for use in X. Note that the use of those fonts is only allowed if you have a valid windows license, or if you have downloaded the fonts from their site.

This text assumes you use XFree 4.2.0, that you have a reasonable knowledge of the CLI and *NIX commands, that you have a working setup of X and a reasonably recent distribution. You should also have perl and freetype on your system.

Step 1: Preparing the fonts and the directory. 

Unpack and/or move (from a windows partition) the ttf files to a directory under /usr/X11R6/lib/X11/fonts, for instance Truetype. The fontserver prefers the filenames to be in lowercase, so use this script on the files (I am reasonably sure the use is selfexplanatory?). Download the program ttmkfdir here. Unpack it and put the file ttmkfdir.linuxbin.glibc2 somewhere where you can run it from, such as /usr/local/bin. Then make a symlink to it called ttmkfdir since I am sure you don't want to type all of that every time you use it Next, download this file and also put it in the /usr/local/bin directory. Once you have all that set up, you cd into the directory with the truetype fonts. Run the command: Code:

http://www.fogdeity.com/eduni/systems/unix/fixcase.html http://www.joerg-pommnitz.de/TrueType/ttmkfdir.tar.gz http://home.c2i.net/dark/mkfontalias.py

$ cd /usr/X11/lib/X11/fonts/Truetype
$ chmod u+x /usr/local/bin/mkfontalias.py
$ ttmkfdir -o fonts.scale
$ mkfontdir
$ mkfontalias.py

The "ttmkfdir -o fonts.scale " command creates fonts.scale, which is basically a list of files with their associated filesizes. The fontsizes, I assume, are ignored, but X needs the list of fonts to be able to offer them.

This next command, mkfontdir, creates fonts.dir which is more or less a copy of fonts.scale as far as I can tell. I am sure it has some purpose, and if you know, by all means, enlighten me

After these commands you should see the following files: fonts.alias, fonts.dir and fonts.scale.

Step 2: Modifying the config files. 

Next thing to do is modifying the various configuration files to reflect the new fonts you have added and make the most of them. Go and find the file XF86Config-4 or XF86Config. If both are found, the -4 version gets used. They can usually be found at /etc/X11 or /usr/X11/lib/X11. Open it and look for the following section: Code: Section "Files"

Modify the lines under that section to look like this:

FontPath      "/usr/X11R6/lib/X11/fonts/Type1"
FontPath      "/usr/X11R6/lib/X11/fonts/util"
FontPath      "/usr/X11R6/lib/X11/fonts/misc:unscaled"
FontPath      "/usr/X11R6/lib/X11/fonts/100dpi:unscaled"
FontPath      "/usr/X11R6/lib/X11/fonts/75dpi:unscaled"
FontPath      "/usr/X11R6/lib/X11/fonts/Speedo"
FontPath      "/usr/X11R6/lib/X11/fonts/TTF"
FontPath      "/usr/X11R6/lib/X11/fonts/Truetype"
FontPath      "/usr/X11R6/lib/X11/fonts/cyrillic"
FontPath      "/usr/X11R6/lib/X11/fonts/encodings"
RgbPath      "/usr/X11R6/lib/X11/rgb"
ModulePath   "/usr/X11R6/lib/modules"

This will make sure X can find the fonts. By adding the :unscaled at the end of the line, you tell X not to scale the fonts in that directory. Why wouldn't you want to scale them, you ask? Simple: the fonts in that directory are bitmapped fonts, which means that scaling them makes them blocky. Blocky == ugly.

Next, hunt for the file called XftConfig. It can usually be found in the same directory as XF86Config. Look for the line:

dir "/usr/X11R6/lib/X11/fonts/Type1"

Modify the lines there to show: Code:

dir "/usr/X11R6/lib/X11/fonts/Type1"
dir "/usr/X11R6/lib/X11/fonts/TTF"
dir "/usr/X11R6/lib/X11/fonts/TrueType"

This will make sure the fontserver will be able to find the fonts as well.

Step 3: Sit back and enjoy your work. 

Fire up X again and you should be able to see that you now have the use of Truetype fonts in X.

Example 

I am using RH 7.3, OO 1.0.1, and here is my config file as asked for:

# $XFree86: xc/lib/Xft/XftConfig.cpp,v 1.5 2000/12/14 23:03:53 keithp Exp $

dir "/usr/X11R6/lib/X11/fonts/Type1"
dir "/usr/X11R6/lib/X11/fonts/TTF"
dir "/usr/X11R6/lib/X11/fonts/truetype"

# Red Hat additions
dir "/usr/X11R6/lib/X11/fonts/TTF"
dir "/usr/share/fonts/default/TrueType"
dir "/usr/share/fonts/default/Type1"
dir "/usr/share/fonts/ja/TrueType"
dir "/usr/share/fonts/ko/TrueType"
dir "/usr/share/fonts/zh_CN/TrueType"
dir "/usr/share/fonts/zh_TW/TrueType"

#
# alias 'fixed' for 'mono'
#
match any family == "fixed"      edit family =+ "mono";

#
# Don't antialias small fonts
#
match
        any size < 11
        any size > 8
        edit antialias=false;

#
# Don't antialias wingding symbols and similar types of symbol fontsets
#
match
        any family == "webdings"
        edit antialias = false;
        encoding += "glyphs-fontspecific";
match
        any family == "wingdings"
        edit antialias = false;
        encoding += "glyphs-fontspecific";

#
# Check users config file
#
includeif   "~/.xftconfig"

#
# Use Luxi fonts for default faces
#
match any family == "serif"      edit family += "Luxi Serif";
match any family == "sans"      edit family += "Luxi Sans";
match any family == "mono"      edit family += "Luxi Mono";

#
# Alias between XLFD families and font file family name, prefer local
# fonts
#
match any family == "charter"      edit family += "bitstream charter";
match any family == "bitstream charter" edit family =+ "charter";

#
# Alias older name for Luxi fonts
#
match any family == "LuciduxSerif"   edit family += "Luxi Serif";
match any family == "Lucidux Serif"   edit family += "Luxi Serif";

match any family == "LuciduxSans"   edit family += "Luxi Sans";
match any family == "Lucidux Sans"   edit family += "Luxi Sans";

match any family == "LuciduxMono"   edit family += "Luxi Mono";
match any family == "Lucidux Mono"   edit family += "Luxi Mono";

#
# TrueType font aliases (disabled - experimental)
#
#match any family == "Comic Sans"        edit family += "Comic Sans MS";
#match any family == "Comic Sans MS"     edit family =+ "Comic Sans";
#match any family == "Trebuchet"         edit family += "Trebuchet MS";
#match any family == "Trebuchet MS"      edit family =+ "Trebuchet";
#match any family == "Monotype"          edit family =+ "Monotype.com";
#match any family == "Andale Mono"       edit family += "Monotype.com";
#match any family == "Monotype.com"      edit family =+ "Andale Mono";

#
# Set some sane defaults for Anti-Aliased desktops
#
match any family == "helvetica"      edit family += "Nimbus Sans L";
match any family == "helv"      edit family += "Nimbus Sans L";
match any family == "verdana"      edit family += "Nimbus Sans L";
match any family == "times"      edit family += "Nimbus Roman No9 L";
match any family == "helvetica"      edit family += "Helmet";
match any family == "helv"      edit family += "Helmet";
match any family == "verdana"      edit family += "Helmet";
match any family == "times"      edit family += "Helmet";

# XFree86 default fonts
match any family == "Verdana"           edit family += "Luxi Sans";
match any family == "Times New Roman"   edit family += "Luxi Serif";

#
# Japanese
#
match any foundry == "watanabe"      edit antialias = false;
match any foundry == "wadalab"      edit antialias = false;

#
# Fixes a problem in KDE with konsole
#
match any family == "fixed"         edit antialias =+ "false";
match any family == "console"      edit antialias =+ "false";

I have also been getting errors as Xserver shuts down complaining that certain fonts don't support something.

Notes 

Netscape 

Now, you have your awesome fonts all blazing away on your screen. Looks awesome, up to the point where you fire up Netscape 4.07 (or so) and all you can recognise in the UI are little boxes where the characters are supposed to be. This is because Netscape expects a specific font and that font only, to display it's stuff. A couple more programs have this problem (VMWare is another I can think of). This perl script makes sure that fonts.alias is created, which should take care of this problem. No more boxes for you!

one logfile 

Next thing I see in the logfile, way at the end, is that it cannot find, or cannot seem to handle the directories /usr/X11R6/lib/X11/fonts/Type1, /usr/X11R6/lib/X11/fonts/Speedo, /usr/X11R6/lib/X11/fonts/TTF and /usr/X11R6/lib/X11/fonts/truetype. Double check if they are there and if you have not made any typos in the directory names. Remember that *NIX is casesensative and that truetype and TrueType are two different values. Also double check if you have done the all the steps in the original post for each of these directories that contain TT fonts. The Speedo and the Type1 directory should work all by themselves, but you do need to load the modules for them. To check if you tell X to load it, check the /etc/X11/XF86Config-4 file for lines saying something like Code:

Load   "speedo"
Load   "type1"

If the module isn't loaded, it won't handle the corresponding font directory.