PreviousINDEXNext
Moving from Redhat 7.3 to DebianValidating XHTML

Mozilla and TrueType fonts on FreeBSD

I decided to change the window manager on my FreeBSD laptop from WindowMaker to fluxbox (bear with me here, it is kind of relevant). To install, I tried the usual ports method:

      # cd /usr/ports/x11-wm/fluxbox
      # make
    

However, the make process died trying to build one of the fluxbox dependencies, freetype. It seems that XFree86 4.3 is required to support the latest version of freetype, so that necessitated a rather larger port upgrade than I had anticipated. I decided to try the portupgrade method, as described in the OnLamp article.

First, portupgrade must be installed. This has a number of dependencies, including ruby, so the installation is not a quick process. Then, you must run portsdb -Uu to create a database (note that this must be re-run after updating the ports tree via cvsup). The portupgrade process can then be invoked - the flags shown ensure that all dependencies on all package are also upgraded:

      portupgrade -arR
    

I let this run overnight, although luckily I checked later in the evening, because one port required the user to hit return. That would have been annoying to find waiting in the morning.

Despite my forebodings that the upgrade would fail mysteriously, everything looked fine the next morning. Pretty impressive. After all that, I finally had fluxbox working. I did notice that the /usr partition was significantly fuller than before, so I ran a couple of utilities to clean up the ports:

      portsclean -DD # remove unused and out-of-date distfiles
      portsclean -C  # clean up any work areas in the ports tree
    

You can read more about managing the ports tree space in this other OnLamp article.

I discovered that I now had Mozilla 1.6b (development version), which meant it should now support TrueType fonts. There are a lot of articles on the web on how to get Mozilla to support TrueType fonts, but despite following the instructions to the letter, I could not get Mozilla to display the TrueType fonts in its font selection list. This was made more galling because I had TrueType working quite happily with Mozilla on my Debian box.

To recap, this is what you need to do to get Mozilla working with TrueType (paraphrased from the web site):

  1. Check that the version of Mozilla resident has FreeType compiled in. This can be checked by setting the environment variable NLS_FONT_DEBUG to 400 and running Mozilla from the command line. An error message will result if no TrueType support is present. Most versions of Mozilla after 1.2 will have FreeType compiled in.
  2. Check you have the FreeType2 library installed (libfreetype.so). This will usually have a link from libfreetype.so.6 (Linux) or libfreetype.so.9 (FreeBSD).
  3. Copy TrueType fonts to a convenient location (e.g. /usr/local/share/fonts/truetype).
  4. Run ttmkfdir >fonts.dir (FreeBSD) in the directory containing the TrueType fonts. This will create the fonts directory, used by X (not sure if this is required by Mozilla).
  5. Turn on TrueType for Mozilla. This can be performed on a system-wide or per-user basis through the preference setting: pref("font.FreeType2.enable", true);
    The system-wide preferences file in FreeBSD is located at /usr/X11R6/lib/mozilla/defaults/pref/unix.js. For Debian, you can find it at /etc/mozilla/unix.js. Local preferences can be set via the user.js file, located in the directory ~/.mozilla/default/salt. The directory element identified by salt is a random name, ending in .slt, generated by Mozilla. Note that in the local preferences file, the keyword pref should be replaced by user_pref.
  6. The directories where the TrueType fonts reside must also be specified to Mozilla, in the same preferences file as above. The entry will look like: (pref(""font.directory.truetype.1", "/dir");. A typical setting for TrueType could look like:
                // TrueType
                pref("font.FreeType2.enable", true);
                pref("font.freetype2.shared-library", "libfreetype.so.9");
                // if libfreetype was built without hinting compiled in
                // it is best to leave hinting off
                pref("font.FreeType2.autohinted", false);
                pref("font.FreeType2.unhinted", false);
                // below a certain pixel size anti-aliased fonts produce poor results
                pref("font.antialias.min",        10);
                pref("font.embedded_bitmaps.max", 1000000);
                pref("font.scale.tt_bitmap.dark_text.min", 64);
                pref("font.scale.tt_bitmap.dark_text.gain", "0.2");
                // sample prefs for TrueType font dirs
                pref("font.directory.truetype.1", "/usr/local/share/fonts/truetype");
                //more font dirs go here
              

So I followed this recipe, but I could not get TrueType fonts. Naturally, I should have read the FreeBSD handbook X Font section a little more carefully, since the answer was there. Font directories have to be made known to the FreeType library by adding a line to the local.conf file, located in the directory /usr/X11R6/etc/fonts under FreeBSD. The line has to be of the form: <dir>/pathname/of/font/directory</dir>. As you may surmise, the local.conf file is in XML format.

The font cache has to be re-created with the newly added fonts, using the command fc-cache -f. Following this step, I could finally see the TrueType fonts displayed in the Mozilla font list.

PreviousINDEXNext
Moving from Redhat 7.3 to DebianValidating XHTML