Dugan Chen's Homepage

Various Things

Optimizing Slackware Linux’s Fonts

Getting Unicode/UTF-8 Support

Setting A Unicode Locale

Unicode support will allow Slackware to display non-Latin characters. UTF-8 is the most common Unicode character encoding. Most of Slackware’s components (including the console and X) support UTF-8-encoded characters, but this functionality needs to be turned on.

When using Slackware’s liloconfig (which is run during Slackware’s installation) to set up lilo, you will be asked whether to “USE UTF-8 TEXT CONSOLE?” Say yes. This adds the following kernel option: “vt.default_utf8=1”

Then prime Slackware to support Unicode characters by setting your locale to a Unicode one. It’s as simple as editing /etc/profile.d/lang.sh and changing the LANG variable from en_US to en_US.UTF-8.

To test, download ucs-fonts.tar.gz and untar it. Among the extracted files will be an examples directory. In an xterm, go there and cat quickbrown.txt.

Setting A Console Console Font

The Terminus font, which is included with Slackware, is a very nice Unicode font for the Linux console. Add the following to your ~/.bashrc.

if [ $TERM = "linux" ]; then
setfont ter-v16n
fi

Other shells of course have other startup files. ZSH uses ~/.zshrc, for example.

Setting Your X Font Resolution

Your X dots-per-inch resolution is, by default, queried from the display device. In some cases, you might prefer to specify a font DPI to get larger or smaller fonts, or if you feel that a specific DPI gives you better-proportioned typography. Those used to Windows might be used to the 96 DPI resolution that Windows uses by default. If your Slackware box is an HTPC, you might set it to 120dpi so that the fonts become large enough to comfortably see.

To see your font DPI, enter xdpyinfo | grep resolution. You’ll get back: resolution: 96×96 dots per inch. This is just an example; your actual value might not be 96×96. If you’d like, you can set it manually.

If you start X with startx, edit /usr/bin/startx and change

defaultserverargs=""

to

defaultserverargs="-dpi 96"

If you start X with a login manager, edit the configuration file and add -dpi 96 to the ends of the “/usr/bin/X” commands. In Slackware 14.1, the KDM configuration file is /etc/kde/kdm/kdmrc. Under Slackware 13.37, the files are /etc/X11/xdm/Xservers (for xdm) and /usr/share/config/kdm/kdmrc (for kdm). In 13.1, the file for xdm was /etc/X11/xinit/Xservers.

Other Configurations

There are two reasons to prefer a font resolution other than 96 DPI. One is visual impairment; higher-resolution fonts will be larger and easier to see. The other is software that requires another resolution. MythTV, which requires 100 DPI fonts, is an example. If you use MythTV, use the Display_Size section of its wiki to set your font resolution.

Understanding Linux’s Font Subsystem

You need to understand, at this point, what Fontconfig is and how it’s configured. Fontconfig is the font subsystem used by almost all recent Linux software, including all GTK2 and Qt applications. Its configuration is stored in /etc/fonts. One directory, /etc/fonts/conf.avail, stores available configuration files. Fontconfig does not read from conf.avail. Rather, the files there are symlinked into /etc/fonts/conf.d, which Fontconfig does read. After modifying any of those files, or a directory referenced by one of those files, you run fc-cache -f -v as root to refresh Fontconfig.

For example, symlinking /etc/fonts/conf.avail/10-autohint.conf into /etc/fonts/conf.d enables the autohinter. Removing that file from conf.d disables the autohinter. For another example, adding a font into a directory read by Fontconfig will make that font available. I recommend not enabling the autohinter; the bytecode interpreter that is used by default gives good results.

There’s a README file in /etc/fonts/conf.d with more.

Adding More Fonts

General Procedures

You can then install new fonts by putting them in ~/.local/share/fonts. The files that belong in ~/.local/share/fonts are the actual font files: .ttf, .otf, .dfont, etc. After installing them, run fc-cache -f -v.

Use the fc-list command to see which fonts your user account has available.

Edit the freetype.SlackBuild itself. Uncomment the line that applies the subpixel rendering patch. It’s the line that begins with “zcat”:

# The line below enables code patented by Microsoft, so don't uncomment it
# unless you have a license to use the code and take all legal responsibility
# for doing so.
# Please see this web site for more details:
# http://www.freetype.org/patents.html
#zcat $CWD/freetype.subpixel.rendering.diff.gz | patch -p1 --verbose || exit 1

Right under the line that applies that patch, paste in the following to also enable subpixel hinting:

Font Configuration

You may then, in one of two ways, set Fontconfig’s subpixel layout to match. The first is to symlink the appropriate file from conf.avail into conf.d. It’s one of the following:

10-sub-pixel-bgr.conf

10-sub-pixel-rgb.conf

10-sub-pixel-vbgr.conf

10-sub-pixel-vrgb.conf

The other is to set it in Xfce’s, KDE’s, and/or GNOME’s control panel. Remember, you can run xfsettingsd (Xfce 4.6), xfce-mcs-manager (Xfce 4.0–4.4), or gnome-settings-daemon to get Xfce or GNOME’s appearance settings in another DE or WM.

Default Fonts

If you want to override which fonts your system alias (such as “sans”) map to, start by removing the following symbolic link:

/etc/fonts/conf.d/44-wqy-zenhei.conf

Then create ~/.config/fontconfig/fonts.conf and override the aliases there.

You can refer to an example fonts.conf that does that, and also sets the Microsoft fonts to full hinting and the other fonts to slight hinting. This is consistent with the fact that Windows uses full hinting and OS X uses slight hinting.

To test whether your overriding worked, use fc-match. For example:

fc-match sans

Xresources

The X resource database should be made aware of your font settings. Put the following (or a variation matching your /etc/fonts settings) in your .Xresources file:

Xft.rgba, of course, is set to the value you found in the subpixel order test.

Miscellaneous

X Server

Some applications still get their fonts through the X server instead of through Fontconfig. To make your fonts available to the X server, edit /etc/X11/xorg.conf and add /usr/local/share/fonts as a FontPath.