How to properly configure displayed fonts in Debian GNU/Linux

One may experience strange font sizes in X Window (e.g. “logically 8 point fonts” characters that are physically displayed at 15 points or more), or when printing. For instance, in KDE problems like those described in some KDE bug reports may appear.

The problem is that the precision of the display (in dpi) is not configured, which makes Wysiwyg display of fonts impossible. Actually, it appears that most GNU/Linux distributions do not configure the display precision, which seems to be set to 75 dpi by default. This must be configured by hand.

One must define the physical dimensions of the screen, in millimeters, by adding aDisplaySize entry in the "Monitor" section of the X11 server configuration file (/etc/X11/XF86Config-4 for the XFree86 server version 4, or /etc/X11/xorg.conf for the server). For instance, the width of my IBM ThinkPad X31 is 246 mm, and its height is 185 mm (this is a 12 inch screen). Therefore, I have added the following line into my /etc/X11/xorg.conf file, in the "Monitor" section:

        DisplaySize     246 185

Depending on the screen resolution (e.g. 1024×768 dots or 800×600 dots, etc.), the precision of the display (in dpi) is automatically calculated by the X server. To get the resolution, execute:

> xdpyinfo | grep resolution

For example, for the IBM ThinkPad X31, the resolution for 1024×768 dots is 105×105 dpi (in that case, the precision is the same vertically and horizontally).

One still must configure the fontconfig system to set the resolution of fonts to display. This should be done by editing the /etc/fonts/local.conf file to add the following lines:

  <match target="pattern">
    <edit name="dpi" mode="assign"><double>105</double></edit>

Alternatively, since in Debian GNU/Linux this configuration file is modularized, one can instead create a new file in /etc/fonts/conf.d, called for instance screen-dpi.conf, that contains the following lines:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
  <match target="pattern">
    <edit name="dpi" mode="assign"><double>105</double></edit>

And a symbolic link must be created to take that new configuration file into account:

> cd /etc/fonts/conf.d
> sudo ln -s screen-dpi.conf 10-screen-dpi.conf

Then, the X server must be restarted.

After configuring the X server as described above, one gets a real Wysiwyg display, e.g. 8 point fonts characters are actually displayed physically as 8 point sized characters.