Sun Java Solaris Communities My SDN Account Join SDN
 
Solaris

Adding True Type Fonts to Solaris

 

A common task faced by many people using Solaris is how to add their own custom fonts to a Solaris machine and get X11 to use them. While Solaris ships with many high quality type faces it is occasionally desirable to add additional fonts (for example type faces not shipped by Solaris). Doing this in X11 can be frought with difficulties and errors. The following is a very simplified guide to adding TrueType (.ttf) fonts to a Solaris user's account.

Requirements

ttmkfdir

ttmkfdir is a useful utility which queries fonts and extracts the necessary information to make a fonts.scale file for use with X11. This removes the necessity to create these files by hand which can be very tedious and error prone. ttmkfdir is available from http://freshmeat.net/projects/ttmkfdir.

Freetype

This is a requirement for ttmkfdir. This is available form http://www.freetype.org/.

C Compiler

You can either use gcc or Forte cc. These are only needed if you don't have a compiled ttmkfdir and freetype available.

Installing Required Software

First get the freetype-1.3.1.tar.gz and ttmkfdir.tar.gz archives from the above links. Then go into a working directory and do the following:

  1. gunzip -c freetype-1.3.1.tar.gz | tar -xf -
  2. cd freetype-1.3.1
  3. ./configure --enable-static
  4. make
  5. cd ../
  6. mkdir ttmkfdir
  7. cd ttmkfdir
  8. gunzip -c ttmkfdir.tar.gz | tar -xf -
  9. cd ttmkfdir
  10. Open up the Makefile in an editor and change the following lines:
    FREETYPE_BASE=../freetype-1.1
    FREETYPE_INCL=$(FREETYPE_BASE)/lib
    FREETYPE_LIB=-L$(FREETYPE_BASE)/lib/.libs -lttf

    to:

    FREETYPE_BASE=../freetype-1.3.1
    FREETYPE_INCL=$(FREETYPE_BASE)/lib
    FREETYPE_LIB=$(FREETYPE_BASE)/lib/.libs/libttf.a
  11. If you are using Sun's compilers instead of gcc change the following lines in the Makefile:
    CC=gcc
    CFLAGS=-Wall -pedantic -I$(FREETYPE_INCL)

    to:

    CC=cc
    CFLAGS=-I$(FREETYPE_INCL)
  12. make

The above steps should give you a ttmkfdir binary which can be used to setup fonts.

Adding Fonts to Your Account

If you have a set of TrueType fonts you wish to add to your own X session then you can simply create a directory in your home directory and add the fonts using the steps below:

  1. mkdir ~/.fonts
  2. cp fonts.ttf ~/.fonts
  3. ttkmkfdir > fonts.scale
  4. mkfontdir
  5. xset fp+ ~/.fonts
  6. xset fp rehash

This will create a directory called .fonts (hidden from view by default) in your home directory into which you can copy fonts. After the fonts have been copied a set of commands are run to create the necessary configuration files and to update your X11 session with the new fonts. Unfortunately by default your X11 session will lose the new fonts on a restart. There are a few ways to make this permanent, the simplest being creating ~/.xinitrc and adding the xset lines to it. For example add the following to your ~/.xinitrc:

if [ -d $HOME/.fonts ]
then
xset fp+ $HOME/.fonts
fi

Future

With the advent of the GNOME 2 desktop environment Sun is investing in newer font technologies which will allow automatic and transparent addition of fonts. At this time ~/.fonts will be the default directory looked in for user fonts so no additional work will be needed to use the newer technologies with your fonts.

Related Links