Difference between revisions of "Font configuration"
(→Original LCD packages)
|Line 1:||Line 1:|
[[Category:X Server (English)]]
[[Category:X Server (English)]]
Revision as of 16:35, 1 October 2010
|Summary help replacing me|
|An overview of font configuration options and various techniques for improving the readability of fonts|
|Fonts: Information on adding fonts and font recommendations|
|Java Fonts - Sun JRE: Fonts specific to Sun's Java machine|
|MS Fonts: Adding Microsoft fonts and mimicking Windows' font settings|
- 1 Font paths
- 2 Fontconfig configuration
- 3 LCD filter patched packages
- 4 Additional fontconfig configuration
- 5 Troubleshooting
- 6 Resources
For fonts to be known to applications, they must be cataloged for easy and quick access. Fontconfig is a library designed to provide a list of available fonts to applications, and also for configuration for how fonts get rendered. Though fontconfig is the standard in today's Linux, some applications still rely on the original method of font categorization: the Xorg server configuration file (Template:Filename).
Fontconfig gathers all it's configurations in a central file (Template:Filename). Fontconfig-aware applications source this file to know available fonts and how they get rendered. This file is a conglomeration of rules from the various fontconfig configurations (the global configuration (Template:Filename), the configured presets in Template:Filename, and the user configuration file (Template:Filename).
The font paths initially known to fontconfig are: Template:Filename and Template:Filename (of which fontconfig will scan recursively). For ease of organization and installation, it is recommended to use these font paths when installing new fonts.
To see a list of known fontconfig fonts in an easy to read format, type:
fc-list | sed 's,:.*,,' | sort -u
Check for Xorg's known font paths by reviewing its log:
$ grep /fonts /var/log/Xorg.0.log
Keep in mind that Xorg does not search recursively through the Template:Filename directory like fontconfig does. To add a path, the full path must be used:
Section "Files" FontPath "/usr/share/fonts/example-font-directory" EndSection
To see a list of known Xorg fonts use Template:Codeline.
The font rendering packages on Arch Linux includes support for freetype2 with the bytecode interpreter (BCI) enabled. However, defining your own font configuration may at times be necessary. If you have an LCD monitor, consider additionally using the LCD filter packages for better readability.
Configuration can be done either per-user through Template:Filename, or globally with Template:Filename. The settings in the per-user configuration have precedence over the global configuration. Both these files use the same syntax. Remember not to edit the Template:Filename file; it is a temporary file and shouldn't be edited since it's replaced during fontconfig updates.
There are already a number of configured presets in the directory Template:Filename. These presets can be linked to both per-user and globally for quicker configuration. Take note that these presets will override matching settings in their respective configuration files.
For example, to enable sub-pixel RGB rendering globally:
# cd /etc/fonts/conf.d # ln -s ../conf.avail/10-sub-pixel-rgb.conf
To do the same but instead for a per-user configuration:
$ mkdir ~/.fonts.conf.d $ ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf ~/.fonts.conf.d
The configuration files will need informational headers before settings can be entered:
<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> ... </fontconfig>
To avoid repetition, the rest of the configuration examples in this article will omit these tags.
Anti-aliasing (aka font rasterization) converts vectors fonts to bitmap for display purposes and in doing so provides a font smoothing effect. Without anti-aliasing (even at higher DPIs) fonts will appear jagged so anti-aliasing is enabled by default.
<match target="font"> <edit name="antialias" mode="assign"> <bool>true</bool> </edit> </match>
Font hinting adjusts the spacing of fonts so that they line up with the pixel grid. Fonts will not line up correctly without hinting until displays have 300 DPI or greater. Two types of hinting are available:
- Template:Codeline - Normal, preset hinting, with several types available.
- Template:Codeline - Auto discovery for hinting.
To enable normal hinting:
<match target="font"> <edit name="hinting" mode="assign"> <bool>true</bool> </edit> </match>
To enable auto-hinting:
<match target="font"> <edit name="autohint" mode="assign"> <bool>true</bool> </edit> </match>
<match target="font"> <edit name="hintstyle" mode="assign"> <const>hintslight</const> </edit> </match>
RGB, BGR, V-RGB (vertical), or V-BGR
Most monitors manufactured today use the Red, Green, Blue (RGB) specification. Fontconfig will need to know your monitor type to be able to display your fonts correctly. If you notice unusual colors around font's borders, discover you monitor type here and define it in your font configuration:
<match target="font"> <edit name="rgba" mode="assign"> <const>rgb</const> </edit> </match>
Like the automatic settings most DE font control panels establish, it is recommended to disable subpixel rendering when using the auto hinter since the combination of the two may result in unsatisfactory rendering.
LCD filter patched packages
Some distributions choose not to use the LCD filter patches for font rendering due to patent ambiguity. If you choose, you can add these patched packages on your own. These patched packages are available in the AUR and easily installable by using an AUR helper. A few considerations:
- All of these methods are designed for LCD displays but some CRT users may see improvements using the ClearType packages.
- Configuration is sometimes necessary.
- The new font effects will not be displayed until the application restarts.
Original LCD packages
These are the vanilla LCD packages and have less pre-configured options and will not have any experimental patches applied.
Remove the conflicting packages:
pacman -Rd libxft cairo
Install the patched packages from the AUR using the AUR helper of your choice. The package names are:
Then install the patched packages from the repositories using pacman:
pacman -S libxft-lcd
Ubuntu patched packages
Ubuntu uses the original LCD patched packages and adds extra configurations, and occasionally patches.
First, the conflicting packages need to be removed:
pacman -Rd libxft cairo fontconfig freetype2
Then install the patched packages from the AUR using an AUR helper of your choice. The package names are:
freetype2-ubuntu fontconfig-ubuntu libxft-ubuntu cairo-ubuntu
Cleartype is a different type of font rendering that is used in Windows systems and is designed to work on both LCD and CRT monitors.
Remove the conflicting packages:
pacman -Rd cairo libxft freetype2
And then install the patched packages from the AUR. Package names:
freetype2-cleartype libxft-cleartype cairo-cleartype
Infinality patched package
- This patch makes Freetype's (http://www.freetype.org) Truetype interpreter render fonts similarly to MS Cleartype. It is not perfect, and needs some work on certain fonts, however, in my opinion it renders much, much better than the bi-level Freetype hinting does when doing subpixel rendering. Anything previous to this that I've worked on is simply a hack. This is the real thing finally.
Install the patched packages from the AUR. Package name:
Reverting to original packages
To restore the unpatched packages, first uninstall the patched versions then reinstall the originals:
pacman -S freetype2 libxft cairo
Additional fontconfig configuration
Disable auto-hinter for bold fonts
The auto-hinter uses sophisticated methods for font rendering, but often makes bold fonts too wide. Fortunately, a solution can be turning off the auto-hinter for bold fonts while leaving it on for the rest:
... <match target="font"> <test name="weight" compare="more"> <const>medium</const> </test> <edit name="autohint" mode="assign"> <bool>false</bool> </edit> </match> ...
Enable anti-aliasing only for bigger fonts
See also sharpfonts.co.cc for related information
Some users prefer the sharper rendering that anti-aliasing doesn't offer:
... <match target="font"> <edit name="antialias" mode="assign"> <bool>false</bool> </edit> </match> <match target="font" > <test name="size" qual="any" compare="more"> <double>12</double> </test> <edit name="antialias" mode="assign"> <bool>true</bool> </edit> </match> <match target="font" > <test name="pixelsize" qual="any" compare="more"> <double>17</double> </test> <edit name="antialias" mode="assign"> <bool>true</bool> </edit> </match> ...
The most reliable way to do this is to add an XML fragment similar to the one below. This will cause Bitstream Vera Sans to be used in place of Helvetica:
... <match target="pattern" name="family" > <test name="family" qual="any" > <string>Helvetica</string> </test> <edit name="family" mode="assign"> <string>Bitstream Vera Sans</string> </edit> </match> ...
An alternate approach is to set the "preferred" font, but this only works if the original font is not on the system, in which case the one specified will be substituted:
... < !-- Replace Helvetica with Bitstream Vera Sans Mono --> < !-- Note, an alias for Helvetica should already exist in default conf files --> <alias> <family>Helvetica</family> <prefer><family>Bitstream Vera Sans Mono</family></prefer> <default><family>fixed</family></default> </alias> ...
The fontconfig-lcd package by default uses the Template:Codeline (very possible Ubuntu's does too) filter that will work for most users. Other filters are available that can be used in special situations: Template:Codeline; a lighter filter ideal for fonts that look too bold or fuzzy, Template:Codeline, the original Cairo filter; and Template:Codeline to disable it entirely.
<match target="font"> <edit mode="assign" name="lcdfilter"> <const>lcddefault</const> </edit> </match>
Disable bitmap fonts
To disable bitmap fonts in fontconfig, use Template:Filename (which is not placed by fontconfig by default):
# rm /etc/fonts/conf.d/70-yes-bitmaps.conf # ln -s /etc/fonts/conf.avail/70-no-bitmaps.conf /etc/fonts/conf.d
Depending on the type of fontconfig you are using (default, or -lcd patched) you can choose which fonts to replace bitmaps fonts with (Helvetica, Courier and Times bitmap mapts to TTF fonts) by:
# ln -s /etc/fonts/conf.avail/29-replace-bitmap-fonts.conf /etc/fonts/conf.d
Create bold and italic styles for incomplete fonts
Freetype has the ability to automatically create italic and bold styles for fonts that do not have them, but only if explicitly required by the application. Given programs rarely send these requests, this section covers manually forcing generation of missing styles.
Assuming the Dupree font is installed:
"dupree.ttf" 0 "Dupree:style=Regular:slant=0:weight=80:width=100:foundry=unknown:index=0:outline=True:etc...
Duplicate the line, change Template:Codeline to Template:Codeline or any other style. Also change Template:Codeline to Template:Codeline for italic, Template:Codeline to Template:Codeline for bold, or combine them for bold italic:
"dupree.ttf" 0 "Dupree:style=Bold Italic:slant=100:weight=200:width=100:foundry=unknown:index=0:outline=True:etc...
Now add necessary modifications to Template:Filename:
... <match target="font"> <test name="family" qual="any"> <string>Dupree</string> <!-- other fonts here .... --> </test> <test name="weight" compare="more_eq"><int>140</int></test> <edit name="embolden" mode="assign"><bool>true</bool></edit> </match> <match target="font"> <test name="family" qual="any"> <string>Dupree</string> <!-- other fonts here .... --> </test> <test name="slant" compare="more_eq"><int>80</int></test> <edit name="matrix" mode="assign"> <times> <name>matrix</name> <matrix> <double>1</double><double>0.2</double> <double>0</double><double>1</double> </matrix> </times> </edit> </match> ...
Change rule overriding
Fontconfig processes files in Template:Filename in reverse numerical order. This enables rules or files to override one another, but often confuses users about what file gets parsed last.
To guarantee that personal settings take precedence over any other rules, change their ordering:
# cd /etc/fonts/conf.d # mv 50-user.conf 00-user.conf
This change seems however to be unnecessary for the most of the cases, because a user is given enough control by default to set up own font preferences, hinting and antialiasing properties, alias new fonts to generic font families, etc.
Example fontconfig configurations
Example fontconfig configurations can be found on this page.
Edits to improve Ubuntu lcd-patched fonts.
Blurry fonts after install
The Ubuntu fontconfig by default doesn't set sub-pixel rendering in it's global configuration. I'm not sure why exactly, I've noticed the same configurations in Template:Filename as when I've loaded and Ubuntu CD but my Ubuntu fonts have always looked blurry after the install. Perhaps it's because I'm using a different desktop environment than Gnome, but to fix this I've always had to set my sub-pixel rendering type on:
ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf /etc/fonts/conf.d/
Then logout and back in again.
Main article: Xorg#Display size and DPI
Fontconfig should be able to detect DPI parameters as discovered by the Xorg server and be able to display the fonts correctly. Those having problems can still fall back to setting it manually:
... <match target="pattern"> <edit name="dpi" mode="assign"><double>96</double></edit> </match> ...
If fonts are still unexpectedly large or small, or are poorly proportioned, the Xorg server may be incorrectly detecting the DPI setting.
Older GTK and QT applications
Modern GTK apps enable Xft by default but this was not the case before version 2.2. If it is not possible to update these applications, force Xft for old GNOME applications by adding to Template:Filename:
For older QT applications: