Handling fonts under Linux / X Window

Maniement des fontes sous Linux / X Window

by Robert L.E. Billon

fonts basics fonts management intalling TrueType resources

"One of the most obvious and painfull imperfections of Linux systems is the X Window System's cumbersome font-handling facilities." (Æleen Frisch)

The chief reason resides in a lack of an unified font manager under this environment. Not only there are a number of font standards but, and more, each application has its own font handling and configuring methods.

Here after are, very condensed, the results of my investigations and some practice restricted to a RedHat/Mandrake context. Handling fonts under X is in fact a vast topic wich will be only lightly touched here. To learn more about see resources at the end of this page.

Font : A complete set of characters of the same type.

"Une des plus évidentes et pénibles imperfections des systèmes Linux est la lourdeur du maniement des fontes sous X Window." (Æleen Frisch)

Ceci est du principalement à l'absence d'un système de gestion de fontes unifié sous cet environnement. Non seulement il existe de nombreux types de fontes mais, de plus, chaque application a son propre mode de gestion et de configuration des fontes.

Je vous livre ci-après le résultat très condensé de mes investigations et exercices pratiques restraints à un contexte RedHat/Mandrake. La manipulation des fontes sous X est en fait un vaste sujet, lequel ne sera qu'effleuré ici. Pour en savoir plus, reportez vous aux ressources citées en fin de page.

Fonte : Assortiment complet de caractères de même type. Syn. police (de caractères)
Note : Nous utilisons le terme fonte plutôt que police car ce mot est mieux compris au plan international. De plus il rappelle le temps, non si lointain et bien après la disparition des dinosaures de la surface de la terre, où un alliage de plomb et d'antimoine était fondu pour fabriquer les caractères.

There is two very distinct categories of fonts :

Bitmap fonts : Characters are encoded in a bit field, as in a picture. They do not scale well, becoming jagged as they get larger.

Outline fonts : Characters are encoded as a mathematical representation of lines and curves that make their outline. They can be scaled up and down and look good at all sizes.

The differents types of fonts generally present on Linux systems are listed in the table Fig.1 .

Il existe deux catégories de fontes bien distinctes :

Fontes Bitmap : Les caractères sont codés sous forme d'un champ de bits, comme dans une image graphique. Leur aspect se dégrade lors d'une mise à l'échelle.

Fontes Vectorielles : Les caractères sont codés en une représentation mathématique qui définit les paramètres de leur contour. Elles peuvent être mises à l'échelle sans perte de définition et leur aspect est bon dans toutes les tailles.

Les différents types de fontes généralement présents sur les systèmes Linux sont listés dans le tableau Fig.1 .

Font type Font format Extension Comment.
Portable Compiled Font Bitmap .pcf.gz Usually stored in
compressed format
Speedo Bitmap .spd  
Ghostscript font Outline .gsf  
Type 1 Outline .pfa
.pfb
.afm
 
ASCII file
Binary file
ASCII font metrics
(Based on Bezier curves)
TrueType Outline .ttf (Based on b-splines)

Fig. 1

Under X, fonts are named by their X Logical Font Descriptor (XLFD). An XLFD consists of a dash ( - ) followed by 14 fields separated by dashes. It goes like this :

-foundry-family-weight-slant-stretch- style-pixels-points-xres-yres-spacing- avgwidth-registry-encoding

Fig.2 shows how may be displayed by xfontsel an XLFD for an Adobe Utopia font. A default value is used for the fields that include a star.

Sous X, les fontes sont nommées d'après la convention XLFD (Descripteur Logique de Fonte sous X). Un XLFD consiste en un tiret ( - ) suivi de 14 champs séparés par des tirets. Il se présente comme suit :

-fondeur-famille-graisse-inclinaison-étirement- style-pixels-points-xres-yres-espacement- largeurmoyenne-registre-codage

La Fig.2 montre comment peut être affiché au moyen de xfontsel un XLFD pour une fonte Adobe Utopia. Une valeur par défaut est utilisée pour les champs comportant un astérisque.

font.png

Fig.2

The font management is not obvious at first and asks for some effort to be well understood. As installed by an Mandrake 8.0 distrib, fonts are found in the following directories

/usr/X11R6/lib/X11/fonts/
/usr/share/fonts/

Two main config files are involved :

/etc/X11/fs/config

which contains a catalogue of the directories where fonts are installed.

/etc/X11/XftConfig used for Type 1 and TrueType fonts. It contains the paths of fonts to be anti-aliased and each application scans all these directories during startup. So it may be optimal to keep here only the paths for the fonts that will be really used.

A RedHat modified version of the X font server ( xfs ), from which networking capabilities have been removed, is used. xfs is started at boot time, for runlevels 2 3 4 5, by one of the scripts in /etc/rc.d/ , as an example :

/etc/rc.d/rc3.d/S90xfs -> ../init.d/xfs

Xfs uses as default config file

/usr/X11R6/lib/X11/fs/config

(see man xfs)

../init.d/xfs includes the line
daemon xfs -port -1 -daemon -user xfs

So xfs is listening for font requests on TCP port -1 . XFree86 is informed of that by the means of the following lines in the config file

/etc/X11/XF86Config

Section "Files"
    FontPath   "unix/:-1"

If you install new fonts by hand (yes, it is possible),it is necessary to reboot the system in order to xfs re-read the config file and includes the new path in the FontPath. A more direct way is to run the following command :
/etc/rc.d/rc3.d/S90xfs restart

La gestion des fontes n'est pas évidente au premier abord et demande quelque effort pour être bien comprise. Telles qu'installées par une distrib Mandrake 8.0, on trouve des fontes dans les répertoires suivants

/usr/X11R6/lib/X11/fonts/
/usr/share/fonts/

Deux fichiers principaux de configuration sont concernés :

/etc/X11/fs/config lequel contient un catalogue des répertoires où des fontes sont installées.

/etc/X11/XftConfig utilisé pour les fontes Type 1 et TrueType. Il contient les chemins des fontes qui doivent être lissées et chaque application scrute tous ces répertoires lors de son lancement. Ainsi il peut être optimal de ne garder ici que les chemins des fontes qui seront réellement utilisées.

Une version modifiée par RedHat du serveur de fontes X ( xfs ) est utilisée, à laquelle les capacités réseau ont été retirées. xfs est démarré au moment du boot, pour les runlevels 2 3 4 5, par l'un des scripts dans /etc/rc.d/ , par exemple :

/etc/rc.d/rc3.d/S90xfs -> ../init.d/xfs

Xfs utilise comme fichier de configuration par défaut

/usr/X11R6/lib/X11/fs/config

(voir man xfs)

../init.d/xfs comporte la ligne
daemon xfs -port -1 -daemon -user xfs

Ainsi xfs écoute les requêtes pour les fontes sur le port TCP -1 . XFree86 en est informé au moyen des lignes suivantes dans le fichier de configuration

/etc/X11/XF86Config

Section "Files"
    FontPath   "unix/:-1"

Si vous installez de nouvelles fontes à la main (oui, c'est possible), il est nécessaire de rebooter le système afin que xfs puisse relire le fichier config et inclure le nouveau chemin dans le FontPath. Une méthode plus directe consiste à lancer la commande ci-après :
/etc/rc.d/rc3.d/S90xfs restart

Where to get TrueType fonts ?

Enter the keywords "TrueType fonts free download" in your favorite search engine and you have almost immediately to deal with an abundant choice. Your selection may drive you to   http://www.microsoft.com /typography/fontpack/default.htm

There, a dozen of fonts for Win 3.1 and Win 3.11, W95 and +, MacOS are proposed for free download. (Thanks B.G. , a great humanist). As I have any version of Windows® I selected the version for Win 3.1 and Win 3.11. This .exe files are auto-extractible under DOS.
Note : This program of free download has been discontinued since the first writing of this text. To get free fonts see Resources here after.

How to install ?

After extracting those files on an old DOS box, I copied the .ttf files into a newly created directory /usr/share/fonts/ttf/microsoft/ . Then from this directory I run drakfont . It installed the fonts in the directory /usr/X11R6/lib/X11/fonts/drakfont and created the corresponding fonts.dir file. So I got 17 fonts and 80 XLFD. Drakfont is a good interactive tool, it installs the fonts in .../fonts/drakfonts/. IT also converts the ttf to Type 1 , creates the .pfa , .pfb and creates or updates the fonts.dir and Fontmap files.

However it does not hurt to rename this directory and to include it in the config file /usr/X11R6/lib/X11/fs/config

Kfontinst is another tool able to install TrueType fonts.
gfontsel is a very ergonomic tool for font display and selection.

Où se procurer des fontes TrueType ?

Entrez les mots clés "TrueType fonts free download" dans votre moteur de recherche préféré et vous aurez presque immédiatement l'embarras du choix. Votre choix peut vous conduire à   http://www.microsoft.com /typography/fontpack/default.htm

Là une douzaine de fontes pour Win 3.1 and Win 3.11, W95 and +, MacOS sont proposées en libre téléchargement. (Merci B.G., un grand humaniste). Comme je ne dispose d'aucune version de Windows® , j'ai choisi les fichiers pour Windows 3.1 et 3.11 . Ces fichiers .exe sont auto-extractibles sous DOS
Note : Ce programme de fontes gratuites a été supprimé depuis la première mouture de ce texte. Voir ci-dessous Resources pour obtenir des fontes en téléchargement libre.

Comment installer ?

Après extraction de ces fichiers sur une vieille machine DOS, j'ai copié les fichiers .ttf dans un répertoire nouvellement créé /usr/share/fonts/ttf/microsoft/ . Puis depuis ce répertoire j'ai lancé drakfont. Il a installé les fontes dans /usr/X11R6/lib/X11/fonts/drakfont et créé le fichier fonts.dir correspondant. J'ai ainsi obtenu 17 fontes et 80 XLFD. Drakfont est un excellent outil interactif, il installe les fontes dans .../fonts/drakfont/. Il effectue aussi la conversion de ttf en Type 1, crée les .pfa , .pfb , et crée ou met à jour fonts.dir et Fontmap.

Cependant il n'est pas interdit de renommer ce répertoire et de l'inclure dans le script de configuration /usr/X11R6/lib/X11/fs/config

Kfontinst est un autre outil capable d'installer des fontes TrueType.
gfontsel est un outil d'affichage et de selection de fontes particulièrement ergonomique.

Linux Magazine Feb 2000, keywords : administering fonts
Linux Magazine Mar 2000, keywords : handling truetype
http://www.linux-mag.com

Unicode in the Unix environment by Roman Czyborra
http://czyborra.com

The ISO 8859 Alphabet Soup by Roman Czyborra
http://czyborra.com/charsets/iso8859.html

Using TrueType fonts with RedHat
http://www.kegel.com/linux/tt.html

The TrueType HowTo by Brion Vibber
http://leuksman.com/linux/TrueType-HOWTO.html

The comp.fonts FAQ by Norman Walsh
http://www.nwalsh.com/comp.fonts/FAQ

See also : man xfd, man xfontsel, man xset, man mkfontdir
man drakfont
Linux Magazine France Février 1999, Septembre 2001
http://www.linuxmag-france.org

Linux Pratique Novembre-Décembre 2003, p.57
http://www.linux-pratique.com

Pages pédagogiques sur la typographie et l'imprimerie
http://www.planete-typographie.com

Voir aussi : man xfd, man xfontsel, man xset, man mkfontdir
man drakfont
http://www.highfonts.com/fontsearch.asp
http://leuksman.com/linux/TrueType-HOWTO.html
http://www.kegel.com/linux/tt.html
http://www.geocities.com/jeffsfonts/
http://simplythebest.net/fonts/
http://www.thefreesite.com/Free_Fonts/
http://members.aol.com/disneyfonts/wds.html
http://www.planete-typographie.com/

Relevant information may be found in the following files

1 - /usr/share/doc/fontconfig/README.Debian

*** IMPORTANT ***
Recently, fontconfig changed to not include bitmapped fonts in the default font set. There is now a Debconf question about this.

If you wish to enable bitmapped fonts manually, either reconfigure this package (with dpkg-reconfigure fontconfig-config), or remove the symbolic link /etc/fonts/conf.d/30-debconf-no-bitmaps.conf
*****************

How fonts are handled in Debian:

Fontconfig is a library which handles font configuration and access at the system level. It is the foundation for a new font handling in X applications (but can also be useful without X).

Applications not using fontconfig are accessing their fonts through the X server. Font packages for these applications are named xfonts-*. You can also use TrueType fonts with these applications if you install the x-ttcidfont-conf package, which connects the X server to defoma, fonts included in ttf-* packages or added manually using dfontmgr can then be used in these programs. A few of these applications, using Xft1, can benefit of antialiasing with vector fonts, but it is deprecated.

The new font renderer in XFree86 is called freetype2, and applications using it access fonts on the client side. Most of them (including all GTK2/GNOME2 and KDE3 applications) do it using fontconfig, which provides listing and matching facilities for all fonts installed on the system. Any font installed in /usr/share/fonts or ~/.fonts will be accessible to these applications. This is now also true for fonts added using defoma.

These programs can all benefit from antialiasing, autohinting and sub-pixel rendering. You can configure it through fontconfig, using debconf (dpkg-reconfigure fontconfig-config), or by changing links in /etc/fonts/conf.d by hand.

Original text by:
-- Josselin Mouette <[email protected]> Wed, 8 Oct 2003 21:51:35 +0200

Changes for fontconfig 2.3 packages by:
-- Keith Packard <[email protected]> Thu, 10 Mar 2005 13:29:11 -0800


2 -/etc/fonts/conf.avail/README

conf.d/README

Each file in this directory is a fontconfig configuration file. Fontconfig scans this directory, loading all files of the form [0-9][0-9]*. These files are normally installed in ../conf.avail and then symlinked here, allowing them to be easily installed and then enabled/disabled by adjusting the symlinks.

The files are loaded in numeric order, the structure of the configuration has led to the following conventions in usage:

L'information pertinente se trouve dans les fichiers ci-après

1 - /usr/share/doc/fontconfig/README.Debian

*** IMPORTANT ***
Récemment fontconfig a changé et n'inclus plus les fontes bitmap dans le jeu de fontes par défaut. Cela soulève une question Debconf à ce sujet.

Si vous souhaitez autoriser les fontes bitmap manuellement, vous pouvez soit reconfigurez ce paquet (avec dpkg-reconfigure fontconfig-config), ou bien enlever le lien symbolique /etc/fonts/conf.d/30-debconf-no-bitmaps.conf
*****************

Comment Debian manipule les fontes:

Fontconfig est une bibliothèque qui manipule la configuration des fontes et leur accès au niveau système. Il constitue la base du maniement des fontes sous X (mais peut aussi être utile sans X).

Les applications n'utilisant pas fontconfig accèdent à leurs fontes à travers le serveur X. Les paquets de fontes pour ces applications sont nommés xfonts-*. Vous pouvez aussi utiliser des fontes TrueType avec ces applications si vous installez le paquet x-ttcidfont-conf, lequel connecte le serveur X à defoma, les fontes incluses dans les paquets ttf-* ou ajoutées manuellement en utilisant dfontmgr peuvent alors être utilisées dans ces programmes. Quelques unes de ces applications, utilisant Xft1, peuvent bénéficier de l'antialiasing avec les fontes vectorielles, mais cela est déconseillé.

Le nouveau moyen de rendu des fontes dans XFree86 est appelé freetype2, et les applications l'utilisant accèdent aux fontes côté client. La plupart d'entre elles (incluant toutes les applications GTK2/GNOME2 and KDE3) le font en utilisant fontconfig, lequel procure les moyens de listage et de correspondance pour toutes les fontes installées sur le système. N'importe quelle fonte installée dans /usr/share/fonts or ~/.fonts sera accessible à ces applications. Ceci est maintenant aussi vrai pour les fontes ajoutées en utilisant defoma.

Ces programmes peuvent aussi bénéficier de l'antialiasing, autohinting et sub-pixel rendering. Vous pouvez le configurer à travers fontconfig, en utilisant debconf (dpkg-reconfigure fontconfig-config), ou en changeant les liens dans /etc/fonts/conf.d à la main.

-- Traduit par Robert L. Billon, Nov 2007


2 -/etc/fonts/conf.avail/README

conf.d/README

Chaque fichier dans ce répertoire est un fichier de configuration de fontconfig. Fontconfig parcourt ce répertoire, chargeant tous les fichiers de la forme [0-9][0-9]*. Ces fichiers sont normalement installés dans ../conf.avail et symboliquement liés ici, leur permettant d'être aisément installés et alors autorisés/inhibés en ajustant les liens symboliques.

Ces fichiers sont chargés dans l'ordre numérique, la structure de la configuration a conduit à l'usage des conventions suivantes :

 Files begining with:   Contain:

 00 through 09          Font directories
 10 through 19          system rendering defaults (AA, etc)
        10-autohint.conf
        10-no-sub-pixel.conf
        10-sub-pixel-bgr.conf
        10-sub-pixel-rgb.conf
        10-sub-pixel-vbgr.conf
        10-sub-pixel-vrgb.conf
        10-unhinted.conf
 20 through 29          font rendering options
        20-fix-globaladvance.conf
        20-lohit-gujarati.conf
        20-unhint-small-vera.conf
 30 through 39          family substitution
        30-urw-aliases.conf
        30-amt-aliases.conf
 40 through 49          generic identification, map family->generic
        40-generic-id.conf
        49-sansserif.conf
 50 through 59          alternate config file loading
        50-user.conf    Load ~/.fonts.conf
        51-local.conf   Load local.conf
 60 through 69          generic aliases
        60-latin.conf
        65-fonts-persian.conf
        65-nonlatin.conf
        69-unifont.conf
 70 through 79          select font (adjust which fonts are available)
        70-no-bitmaps.conf
        70-yes-bitmaps.conf
 80 through 89          match target="scan" (modify scanned patterns)
        80-delicious.conf
 90 through 98          font synthesis
        90-synthetic.conf
3 - /etc/fonts/fonts.conf

We find here the font directory list

3 - /etc/fonts/fonts.conf

Nous trouvons ici la liste des répertoires de fontes

<!-- Font directory list -->

        <dir>/usr/share/fonts/<dir>
        <dir>/usr/X11R6/lib/X11/fonts/<dir> 
        <dir>/usr/local/share/fonts/<dir>
        <dir>~/.fonts/<dir>

<!-- Font cache directory list -->
[...]
index_1.png

From what we have just seen, it results :

As long as a user has in his homedir a directory .fonts. His personal fonts will be accounted for and available in his applications. As it is a matter of system font management, any modification of .fonts will be accounted for at the next boot or by running fc-cache before launching this application. It seems well that there is at last *THE VERY* font management we were all waiting for Linux. So one can keep a common base set of system fonts and each user can have his own fonts, as an example he could use his fonts for a project, then delete or archive them.

Note: There is also, in the KDE environment, kfontinst, a handy font manager.

-- Robert L. Billon, Nov 2007

index_1.png

De ce que nous venons de voir, il résulte que :

A partir du moment où un user a dans son homedir un répertoire .fonts , ses fontes sont prises en compte et disponibles pour ses applis. Comme il s'agit d'une gestion système des fontes, toute modification de .fonts sera prise en compte lors d'un reboot ou bien en lançant fc-cache avant de lancer l'application. Il semble bien que ce soit enfin *LA* gestion de fontes que nous attendions pour Linux. On peut ainsi garder un ensemble de fontes système de base commun et chaque utilisateur peut avoir ses propres fontes et, par exemple, utiliser des fontes pour un projet puis les supprimer ou les archiver.

Note : Il existe aussi, dans l'environnement KDE, kfontinst, un gestionnaire de fontes pratique.

-- Robert L. Billon, Nov 2007

Times New Roman

What about using it ? Times New Roman was designed on the year 1932 by Stanley Morisson, a renowned typographer, for the Times newspaper. This font is designed in order to comply with the constraints of a newspaper, allowing to write a text little and compact without compromising legibility. Just use it wisely.

Helvetica

The Helvetica font was created on 1957 by Max Miedinger and was designed in a way to maximalize visual harmony. Symbol of the Helvetic typography, his graphism is very neutral, allowing multiples and varied uses, so it is one most used fonts in the world. Helvetica is a variant derived from the Akzidenz-Grotesk, one of the first sans serif typography really popular, designed by the typographic foundry H. Berthold in Berlin on 1896.

Helvetica is not included in the Debian distribution and his derivatives. Whilst it can be freely distributed, it's not published under a free license, hence does not satisfy the Debian policy on licenses. Helvetica in Open Type format (.otf) can be found and are well operational under Linux. For more about Open Type, see the following link: wikipedia.org/wiki/OpenType

Clearview

The Clearview font was designed specifically in order to improve legibility on US interstate road signs. The distance of legibility, compared to the Gothic typeface, is so increased by 50%. Available under fee only.
-- American scientist 2006 Sept-Oct p.399

Esperanto

The declaration :
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> in the head part of your html code must allow your browser to decode correctly esperanto specific characters, if the related font is installed. Configure the browser : default encoding UTF8 and select among Helvetica, Free Sans, Free Serif, Nimbus Sans, Nimbus Roman, URW Bookman L, URW Palladio, URW Gothic L, Century Schoolbook, etc ... as somme fonts, Bitstream, Verdana, etc ... do not contain esperanto specific characters
-- rleb 2007-01-30

Times New Roman

Du bon usage... Times New Roman a �t� créé en 1932 par Stanley Morisson, un grand typographe, pour le journal Times. C'est une fonte prévue pour s'adapter aux contraintes d'un journal, et donc permettant d'écrire du texte petit et compact sans nuire à la lisibilité. Il faut juste l'utiliser a bon escient.
-- trouvé sur le forum ubuntu.fr , 2006-08-05

Helvetica

Helvetica est une fonte sans serif créée en 1957 par Max Miedinger qui l'a dessinée dans le but d'atteindre l'harmonie optique. Symbole de la typographie suisse, son tracé d'une grande neutralité lui permet de se prêter à tous les usages, si bien qu'elle est une des fontes les plus utilisées dans le monde. Helvetica est une variante dérivée de l'Akzidenz-Grotesk, une des premières typographies sans serif vraiment populaire, conçues par la fonderie typographique berlinoise H. Berthold en 1896.

Helvetica n'est pas incluse dans la distribution Debian ainsi que les distributions dérivé. En effet bien que cette fonte soit distribuée librement, elle n'est pas publiée sous une licence libre et donc ne satisfait pas à la politique de licences de Debian. On peut se procurer des Helvetica en format Open Type (.otf) qui sont parfaitement utilisables sous Linux. Pour plus de détails sur Open Type voir le lien suivant :
wikipedia.org/wiki/OpenType

Clearview

La fonte Clearview a été développée spécifiquement pour améliorer la lisibilité des paneaux routiers aux USA. Le gain en distance de lecture, par rapport au Gothic, est de 50%. Accesible moyennant licence payante.

Esperanto

La déclaration :
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> dans l'en-tête du code html de cette page devrait permettre au navigateur de décoder correctement les caractères esperanto spécifiques, si la fonte correspondante est installée. Configurer le navigateur : encodage par défaut UTF8 et choisir une fonte standard parmi Helvetica, Free Sans, Free Serif, Nimbus Sans, Nimbus Roman, URW Bookman L, URW Palladio, URW Gothic L, Century Schoolbook, etc ... En effet certaines fontes, Bitstream, Verdana, etc ..., ne contiennent pas les caractères spécifiques de l'esperanto.
-- rleb 2007-01-30

    
File: fonts.html - Robert L.E. Billon, 2002-01-17 - Last update: 2010-11-04