Friday, February 8, 2008

Adding TTF fonts to the X server

This is a little survey on how to add fonts to your Xorg server. I did this on my FreeBSD 6.2 running Xorg 6.9 and I hope that doing the same on Xorg 7.x will be quite similar.

I installed my TTF (TrueType) fonts on /usr/local/lib/X11/fonts/myfonts. So in order to get Xorg using it, edit your /etc/xorg.conf and modify it to look like the following

Section "Files"
FontPath "/usr/X11R6/lib/X11/fonts/TTF/"
FontPath "/usr/local/lib/X11/fonts/myfonts/"
...
EndSection

Once /etc/xorg.conf has been saved. Run the following commands

# cd /usr/local/lib/X11/fonts/myfonts
# /usr/X11R6/bin/mkfontscale
(on Xorg 7.x this could be /usr/local/bin/mkfontscale)
# /usr/X11R6/bin/mkfontdir
(on Xorg 7.x this could be /usr/local/bin/mkfontdir)

The last step is giving the users the oportunity to choose from the added fonts on their font chooser dialogs. Just edit /usr/X11R6/etc/fonts/local.conf (or /usr/local/etc/fonts/local.conf if you're using Xorg 7.x) and the directory to the configuration as follows:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "/etc/fonts/fonts.dtd">

<fontconfig>
<dir>/usr/local/lib/X11/fonts/myfonts</dir>
</fontconfig>

Restart X, and voilĂ !

No comments: