Xorg Fonts Setup

From Elvanör's Technical Wiki
Jump to navigation Jump to search

This is a tutorial to get good looking fonts under Xorg, with anti-aliasing. It is taken from the Gentoo wiki.

Hardware

  • It is said that having an monitor that does not do 96dpi will result in poor visual quality anyway. To know the dimension and DPI of your hardware use:
xrandr --query // this will give you the physical specifications of your monitor
xdpyinfo | grep -B1 dot // this will give you the current DPI used by X
  • The true DPI is obtained by dividing the resolution of your monitor by its width in inches.

USE flags

  • Add the global truetype USE flag.
  • Add -bindist to the media-libs/freetype package.

Installing Fonts

  • Emerge the following fonts:
    • media-fonts/corefonts
    • media-fonts/freefonts
    • media-fonts/ttf-bitstream-vera
    • media-fonts/artwiz-fonts
    • media-fonts/sharefonts
    • media-fonts/terminus-font
    • media-fonts/dejavu
    • media-fonts/liberation-fonts-ttf

Configuration Files

  • In xorg.conf you only need to change the font paths:

Section "Files"

       FontPath    "/usr/share/fonts/misc:unscaled"
       FontPath    "/usr/share/fonts/Type1"
       FontPath    "/usr/share/fonts/TTF"
       FontPath    "/usr/share/fonts/corefonts"
       FontPath    "/usr/share/fonts/freefonts"
       FontPath    "/usr/share/fonts/sharefonts"
       FontPath    "/usr/share/fonts/terminus"
       FontPath    "/usr/share/fonts/dejavu"
       FontPath    "/usr/share/fonts/cyrillic"
       FontPath    "/usr/share/fonts/ttf-bitstream-vera"
       FontPath    "/usr/share/fonts/75dpi:unscaled"
       FontPath    "/usr/share/fonts/100dpi:unscaled"
       FontPath    "/usr/share/fonts/artwiz"

EndSection

The order matters! Also make sure you are loading the freetype module. Update: The default xorg configuration file now has these paths by default.

  • /etc/fonts/local.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- /etc/fonts/local.conf file to configure system font access -->
 
<fontconfig>
 
<!-- DO NOT Use the Autohinter -->
 
	<match target="font">
       	<edit name="autohint" mode="assign"><bool>false</bool></edit>
       </match>
 
<match target="pattern" name="family">
	<test name="family" qual="any">
		<string>Courier</string>
	</test>
	<edit name="family" mode="assign">
		<!-- Other choices - Courier New, Luxi Mono -->
		<string>Bitstream Vera Sans Mono</string>
	</edit>
</match>
 
<match target="font">
<!--
	<edit name="rgba" mode="assign">
		<const>vrgb</const>
	</edit>
-->
	<edit name="autohint" mode="assign">
		<bool>false</bool>
	</edit>
	<edit name="antialias" mode="assign">
		<bool>true</bool>
	</edit>
	<edit name="hinting" mode="assign">
		<bool>true</bool>
	</edit>
	<edit name="hintstyle" mode="assign">
		<const>hintfull</const>
	</edit>
</match>
 
<!-- Reject bitmap fonts in favour of Truetype, Postscript, etc. -->
<selectfont>
	<rejectfont>
		<pattern>
			<patelt name="scalable">
				<bool>false</bool>
			</patelt>
		</pattern>
	</rejectfont>
</selectfont>
 
</fontconfig>
  • To replace Microsoft fonts (Arial, Courier...) with Liberation fonts, activate /etc/fonts/conf.avail/60-liberation.conf by symlinking it in

/etc/fonts/conf.d/. Be careful however, this can cause problems with Firefox rendering of web pages, see below.

Testing

  • To test, reload periodically xdm (/etc/init.d/xdm restart) while making changes to /etc/fonts/local.conf *and* in the KDE control center. Make the same changes in both places, then restart the X server.
  • I think "the best setup" depends on you individual preferences. What I like is anti-aliasing with full hinting (not done by the autohinter, but by TrueType's Byte Code Interpreter - BCI), and to disable any sub-pixel hinting.

Mozilla Firefox Setup

  • You can change the default fonts used in the Preferences. You should probably use Bitstream Vera, or the Red Hat Liberation family.
  • Go to about:config, experiment with values such as font.FreeType2.enable, font.FreeType2.unhinted, font.FreeType2.autohinted.
  • If you replaced Microsoft core fonts with Red Hat's Liberation ones, be aware that this causes Firefox to not recognize Arial anymore (since this is one of the replaced fonts). This is probably a bug in Firefox, but the result is that the next font in the CSS list after Arial is selected. If this results in Verdana being selected, you will probably have rendering problems in your page as the metrics seem to be different in Windows and Linux.

Additional Fonts

  • To get font support for other languages, you typically need to emerge other fonts (Chinese or Japanese ones for examples).
    • media-fonts/arphicfonts (Chinese)
    • unfonts unfonts-extra alee-fonts baekmuk-fonts (Korean)
  • Some fonts do not have ebuilds (Thai fonts for example). Once downloaded from the net, just install them in ~/.fonts (you may also have to copy a file to

/etc/fonts/, but the whole process is very simple). fontconfig should then handle automatically the new fonts.

  • Warning: I noticed that out of the box, these fonts seem to work very well with Firefox. However some KDE applications like Kate don't "see" the fonts and may not be able to display the characters correctly... although in fact the characters are there! I have to investigate this.

Web Development

  • If you are doing web development, it is recommended to set you DPI to 96 (like Windows). Thus you will get the same rendering for fonts and web pages under Firefox than under Windows Firefox. It seems Windows always sets the DPI to 96, while Linux sets this setting based on your monitor and resolution (which makes more sense). But the result is that fonts can look bigger/smaller (generally smaller) on Linux than on Windows, which can be problematic for web development.
  • Verdana as a font seems to cause problems on Gentoo. The pages can be distorted because of differences in the size of font characters with Verdana.