How to configure your Anti-Aliased desktop

Various people have been asking how to configure fonts with the new Xft extension, which enables AA fonts, among other things.
This is a short tutorial on how to configure the new Xft extension.

Configuring the Xft extension (including antialiasing)
Danny Tholen ([email protected])

Xft is an interface to the freetype rasterizer written by Keith Packard,
member of the XFree86 Project, Inc. It allows applications to use fonts
from the new X render extension using a unified font naming scheme. In
/etc/X11/XftConfig (or /usr/X11R6/lib/X11/XftConfig) you will find a configuration
file which can be adapted to suit your personal taste. In this document
I will explain the syntax and demonstrate some things you can do with this
file.

Structure
The basic structure revolves around a 'pattern'. A pattern is a set of
name/valuelist pairs, each valuelist contains one or more typed values.
A certain application requests a font, for example:

family: "Arial"
size: 12
encoding: "iso8859-1"

A size 12 arial font in latin-1 encoding. The Xft extension will now
try to patch this pattern to all of the fonts available in the system.
And selecting the one with the best score. Before the matching is done
Xft looks in XftConfig. The requested pattern can here be extended before
use. An example is:

match any family == "Arial" edit antialias = true;

This will enable antialiasing for all fonts of the family Arial.

Also, the X server is queried to list all of its fonts; the XLFD contains
just enough information to match fonts roughly.

Here's a list of attributes used in matching fonts (in priority order,
this may not be up to date anymore!):

foundry        font foundry (string,
like ¨monotype¨)
encoding       font encoding (string, like ¨iso8859-1¨)

spacing        font spacing (integers or proportional
               (0), mono (100), charcell (110))

bold           is the font bold? (boolean)

italic         is the font italic? (boolean)

antialias      is the font antialiased? (boolean)

family         font family (string)

size           font size (double)

style          font style (string, like "Bold Italic")

slant          font slant (roman, italic, oblique)

weight         font weight ( integers or light, medium
               (100),demibold, bold, black)

rasterizer     not yet used (probably "TrueType",
               "Type1", ...)

outline        outlines available? (boolean)

Syntax
dir

adds a directory to the list of places Xft will look for fonts. There
is no particular order implied by the list; Xft treats all fonts about
the same.

include and includeif

cause Xft to load more configuration parameters from the indicated file.
"includeif" doesn't elicit a complaint if the file doesn't exist. If the
file name begins with a '~' character, it refers to a path relative to
the home directory of the user. This is usefull for user-specific configurations.

match edit ;

if a pattern from an application matches the pattern after match, it
is edited with the instructions in edit. The pattern match is done as follows:

match qual FIELD-NAME COMPARE CONSTANT

where qual is either any (matches one specific font) or
all
(matches all fonts). An example:

match all foundry==¨monotype¨

will match (and edit) all fonts belonging to the foundry monotype.

match any family==¨arial¨

will match (and edit) one specific font with the family name arial.

FIELD-NAME is one of the properties found above under
Structure.

COMPARE is <, >, or
==.

CONSTANT is the value of the field-name in the appropiate type (see
under Structure).

You can use multiple matches before you use the edit statement.

edit FIELD-NAME ASSIGN EXPR SEMI

FIELD-NAME can be any of the above (see Structure) plus addionally:

pixelsize        font size in
pixels (integer)
charspace        characer space
(integer)
minspace        
minimal spacing (integer)

rgba             color hinting (string ¨rgb¨ or ¨bgr¨ and
                 vertical hinting ¨vrgb¨ ¨vbgr¨)

xlfd            
x server font (string, type xlsfonts to
                 see a list of your xlfd strings)

file             the font file (string)

core            
use X core fonts? (boolean)

render           use render fonts? (boolean)

index           
I have no idea what this does:)

scalable         is the font scalable (boolean)

scale           
scale the font (integer)

charwidth        character width (integer)

charheight      
character height (integer)

matrix           no idea (not really at least)

ASSIGN can be one of =, += or
=+. With =,
the matching value in the pattern will be replaced by the given expression.
+=
or =+ will prepend/append a new value to the list of values
for the indicated field.

EXPR sets the FIELD-NAME to a value.

SEMI is a semicolon. You can use multiple instructions, separated by
a semicolon.

Examples
And now I´ll try to list a few usefull configurations and explain
them. Note that it is configured for my system, and I may use different
fonts than you, so try to adapt the examples to your own needs.

1) How do I make fonts available to Xft?

List your Type 1 and TrueType font directories with dir. On my
system (Mandrake 7.2) this becomes:

dir "/usr/X11R6/lib/X11/fonts/Type1"
dir "/usr/X11R6/lib/X11/fonts/drakfont"

2) How do I use a user specific XftConfig file?

Put an .xftconfig file in your user directory and add

includeif "~/.xftconfig"

to your standard XftConfig. This will enable a user specific configuration
file, but it will not complain if there is no such file.

3) How do I make aliases for my fonts?

I noted that my KDE console asks for ´mono´ fonts when it
is looking for a fixed font. ´console´ is used when I select
´linux´ in the font menu of the KDE konsole. Therefore, I used
two aliases for fonts which are also named ´fixed´:

match any family == "fixed" edit family =+ "mono";
match any family == "console" edit family =+ "mono";

4) Antialiasing my fonts makes me dizzy!

Although there is a big fuz around AA in X, good fonts actually look
better if they are not antialiased. The antialiasing blurs the fonts by
adding grey pixels to the edges, and this may strain your eyes if you looking
at them for a long time. (Your eyes will try to get the fonts sharper,
which ofcourse is not working because they are blurred;) However, for very
small fonts, antialiasing may increase the readability of the fonts, because
with sharp edges, there are to little pixels available for your mind to
figure out what it means. And for bigger fonts, the edges become very jagged
when not anitaliased, so here you also might want to have aliased fonts.
Ofcourse you can also turn off the antialiasing for specific fonts. In
other operating systems, most truetype fonts are not antialiased between 8 and 12
pixels, while only large Type1 fonts are antialiased.

Use the following in your XftConfig to antialias only fonts of specific sizes:

match
    any size > 8

    any size < 15

edit

    antialias = false;

5) My fixed fonts do not appear or look _very_ wrong in the KDE konsole
or similar programs!

I noted that somehow a lot of fixed font do not tell Xft that they are
fixed, and thus, mono spaced. Therefore only a part of the font is displayed.
We can manually set the spacing for these fonts (this assumes you have
fixed aliased with mono as in question 3):

match
    any family ==
"mono"

edit

    spacing = mono;

6) My Symbol, Webdings, etc. fonts do not show up!

For some reason some (symbol) fonts are not correctly recognized, and Xft will
show your default font, or a font which has the closest match (which is
generally not what you mean at all). For Adobe Symbol and MS-webdings I
did the following to get them working:

match
    any family ==
"webdings"

edit

    antialias = false;

    encoding += "glyphs-fontspecific";

match
    any family ==
"symbol"

edit

    antialias = false;

    encoding += "glyphs-fontspecific";

A usefull way of figuring out these things is to activate debuging
with

export XFT_DEBUG=1024

This will generate a lot of output, especially if you have many fonts,
because it lists the properties and scores of every font available. You
can also use other values. For a nice summary of what happens (requested font, XftConfig substitutions,
x server additions and the finally matched font), you can use XFT_DEBUG=2.

7) Why do my KDE programs start now soooo slow?

Currently, the Xft mechanism in XFree 4.0.3 has to parse the XftConfig file each time a program is started.
And the info of all these fonts has to be read. Newer versions (in CVS) will use a cache and are much faster.
Especially if you have many fonts this can be a problem, and the only real solution is to upgrade to a CVS version of XFree.

8) I have a LCD screen, can I use subpixel hinting instead of normal antialiasing?

Yes you can. Subpixel hinting uses colors instead of grey pixels to do the AA.
I do not have a LCD screen so I do not have any idea of how it looks but you can play with the
rgba setting. Try

match edit rgba=bgr;

or use rgb if you have a different type of monitor. For vertical AA you can try vbgr and vbgr.

9) My fonts still look bad!

If you do not have some good truetype fonts, it is worth to go and look
for them on the internet. Other reasons why your fonts still look bad can
be because of your build of freetype2. Snapshots versions before 2.0.2 were
compiled with an option that had some patent issues. Therefore, the standard
2.0.2 compiles without this option. To fix this, download the freetype2 source rpm
and change in include/freetype/config/ftoption.h line 314:
#undef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
to:
#define TT_CONFIG_OPTION_BYTECODE_INTERPRETER
and rebuild with this modified source. See the freetype2 README file for details.

Adobe Courier looks terrible on my system, so I made an alias so that Lucida console
is displayed instead. If anyone can get it to display nicely I would appreciate it.

10) Other resources on the web...

Here you can find more info about setting up the render and Xft extensions:
SuSE HowTo
Lars Knoll HowTo
My own XftConfig can be found here;
remember that it is specifically adapted to my system, and you will have to edit it.

Feedback is appreciated!

Dot Categories: 

Comments

by not me (not verified)

In CVS there is a Konsole Control Panel that allows you to set the system-wide default konsole font. It solves the problem for Konsole. However, there are a number of other places in KDE where this problem crops up (such as the numbers in KOffice rulers and occasionally in KHTML). I sure wish there was a way to select which font to choose in the event that the one wanted is not found.

by Ivan Petrov (not verified)

well...
and finally what I have to do to get a
good looking konsole (even without AA fonts),
and AA enabled for KDE globally.
Of course using xterm solves this, but what about
people that prefer konsole?

by Karl Garrison (not verified)

Anyone know of a good place to find a good collection of free true Type fonts? Even better would be an RPM containing several of these.

-Karl

by Moritz Moeller-... (not verified)

On SuSE run "fetchmsttfonts" (as root). It downloads and installs the MS webfonts (Arial, Times, Courier...)

Since most of us have at one time paid for a MS system, using these fonts is allowed.

by Patrice Godey (not verified)

I am searching for the TTF 'technical.' Can you offer a website address for this? I am told I have to pay $15.00 for the download which I am willing to do.
I had the 'technical' font in Microsoft Excel. After an FDISK and reinstallation this font was lost. My documents now have to be changed whenever I used that font. Is there another name for this font? Do I have to convert it to another name? Any help you could offer would be greatly appreciated. [My Excel documents are just a part of my word processing home job ... I do not publish or do anything that would require legal rights to use the font.]

by Evandro (not verified)

there's a ttfonts package in the latest redhat version. you need rpm 4.

by Rex Dieter (not verified)

FYI, to install/use the ttfonts package from redhat 7.1, you only really need rpm 3.0.5, not rpm4.

by Nick Ryberg (not verified)

The best site by far is Microsoft's:

The biggest limitation is to not distribute the fonts commercially - - -

http://www.microsoft.com/typography/fontpack/default.htm

by come on kids! (not verified)

x.themes.org

'nuf said.

by clickfurtle (not verified)

I put the following into my system-wide XftConfig, to try and fix the "can't choose any fixed font after the first" issue, and prettify small fonts. It achieved the second result but not the first.

Far worse was, when I restarted the X server, it died and retried about 5 times running and then bailed completely! Any idea why, anyone?

When I moved it to .xftconfig, KDM started and I could login normally.

I'm using SuSE7.1, XFree4.03, KDE2.1.1, all SuSE binaries.

cheers

Will

----------

match
any family == "mono"
edit
spacing = mono;

match
size > 8
size < 12
edit
antialias = false;

> Far worse was, when I restarted the X server, it >died and retried about 5 times running and then >bailed completely! Any idea why, anyone?
Trouble with most configurations is that X tries to respawn several times, upon failure, I never liked this:(
Are there some errors logged somewhere? (/var/log/XFree86.log or similar?)

There are a few bugs in the 4.0.3 implementation of Xft (that's why I use a CVS version), which can cause segfaults.

I'm not sure, but maybe it helps if you try this

match
any family == "fixed"
edit
spacing = mono;

Fixed should be aliased to mono for the other syntax to work... Maybe that solves the problem?

Danny

> Far worse was, when I restarted the X server, it >died and retried about 5 times running and then >bailed completely! Any idea why, anyone?
Trouble with most configurations is that X tries to respawn several times, upon failure, I never liked this:(
Are there some errors logged somewhere? (/var/log/XFree86.log or similar?)

There are a few bugs in the 4.0.3 implementation of Xft (that's why I use a CVS version), which can cause segfaults.

I'm not sure, but maybe it helps if you try this

match
any family == "fixed"
edit
spacing = mono;

Fixed should be aliased to mono for the other syntax to work... Maybe that solves the problem?

Danny

Very nice tutorial :)
Unfortunately, I had to switch back to 'normal' true type fonts, because for some reason antialiasing and unicode/iso8859-2 fonts totally break my system. Font server crashes and I can only cry. Nothing helps. Removing Xftconfig files, applying old XF86Config, rebooting etc., without luck. "Fixed fonts" are missing is all I get from console output. No way to log to X. I suspect that iso8859-2-100dpi fonts are reason for my trouble, but I am not sure.

Funny, I do not think this should be causing problems. Especially not if you do not add these fonts to XftConfig with the 'dir' syntax.

With 'Font server crashing' I assume you mean xfs? What happens if you simply do not use xfs?
You should add some dirs with fonts to XF86Config:
FontPath "/usr/X11R6/lib/X11/fonts/100dpi/"
and you won't need xfs anymore.

Btw, xfs of X 4.0.2 had some problems with some truetype fonts, I think 4.0.3 fixed this.

Danny

by KDE User (not verified)

Good job, Danny! We really needed this. Very well researched and very well done. Thanks for your contribution!

by Will (not verified)

I still can't get any fixed width fonts to work with any of the suggestions here.

See this bug:

http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=37494

by Danny (not verified)

If you are refering to this:
> The "fixed width" font in the KDE font
>picker module is unable to find any
>font it likes when in anti-aliased mode. The >list of available fonts contains
>only "fixed" which looks ok but if you choose >it, it will revert to the first
>truetype font on the list every time you logon.

It _will_ be fixed by doing as I said (really;-P). Otherwise there is something strange about your setup/config.
Does it work if you use mine XftConfig instead of yours (and do put it in the right directory for your distro, since that can be one source of the problem).

If it still does not work mail me the debug output (export XFT_DEBUG=1024 ) when starting
the konsole.

Danny

by Arnd Bergmann (not verified)

XFree86 4.1.0 will fix this, in the meantime you can use this patch from Linux Mandrake kdelibs:

--- kdelibs/kdecore/kcharsets.cpp.qt_xft Tue Mar 13 18:57:52 2001
+++ kdelibs/kdecore/kcharsets.cpp Tue Mar 13 19:04:04 2001
@@ -481,6 +481,18 @@
return;
}

+ // if QT_XFT is used, the font might be ok, even if it is not in the list
+
+ if(f.charSet() == charset) {
+ //kdDebug() << "KCharset::setQfont: font has correct charset" << endl;
+ return;
+ }
+
+ if(f.charSet() == QFont::Unicode) {
+ //kdDebug << "KCharset::setQfont: font is Unicode" << endl;
+ return;
+ }
+
// ok... we don't have the charset in the specified family, let's
// try to find a replacement.

--- kdelibs/kdeui/kfontdialog.cpp.qt_xft Tue Mar 13 19:06:49 2001
+++ kdelibs/kdeui/kfontdialog.cpp Tue Mar 13 19:08:51 2001
@@ -423,11 +423,9 @@
}

// Fallback.. if there are no fixed fonts found, it's probably a
- // bug in the font server or Qt. In this case, just use 'fixed'
- if (lstFixed.count() == 0)
- lstFixed.append("fixed");
-
- lstSys = lstFixed;
+ // bug in the font server or Qt. In this case, show all fonts
+ if (lstFixed.count() != 0)
+ lstSys = lstFixed;
}

lstSys.sort();

Thank you for the very informative article.

On a new Mandrake 8.0 machine, after
I installed Microsoft ttf fonts and enabled AA
all my default fonts changed to some italics font.
I went to the fonts settings in KDe control center
and custome specified the fonts and most of the
italics fonts went away. But still the default
font on Konquerror is italics, by default font
I mean for an html page with a particular font
which is not available on my system, gets
displayed using the italics font.

Has any one seen this ? How does KDE apps decide
the default font for an unmatched font request ?

Konqueror uses his own font settings, which are
kinda obscure:
Settings->Configure Konqueror->Konqueror Browser->Appearence
Here you can set a number of fonts that Konqi will use. But they are grouped per encoding, so you should select your preferred font for each of the encodings you are most likely to use (which probably include iso8859-1, iso8859-15 and iso10646-1).

Does this help?

Danny

Konqueror uses his own font settings, which are
kinda obscure:
Settings->Configure Konqueror->Konqueror Browser->Appearence
Here you can set a number of fonts that Konqi will use. But they are grouped per encoding, so you should select your preferred font for each of the encodings you are most likely to use (which probably include iso8859-1, iso8859-15 and iso10646-1).

Does this help?

Danny

I have set the Konqi fonts only for the
default encoding which I guess is iso8859-1,
I will try setting it for all encodings and see
if it helps.

Thanks a lot for your suggestion.

by Bart Simpson (not verified)

Sorry, it doesn't work. This seems to be a Mandrake 8 or KDE 2 bug!

by Robert Gelb (not verified)

Why is there a tutorial for god's sake. The XFree installer should have set it up AA to begin with. How can anyone expect a normal person with no knowledge of how to recompile the kernel or xfree or qt or kde or some other god forsaken component. Yeah, I understand that it is complicated (have to detect versions of various components), but that's what an installer is for. I friend of mine with 10 years of DOS, OS/2 & Windows programming experience recently installed Linux and wanted to enable the sound card. Various responses on the newsgroup basically came down to recompiling & adding something to the kernel. This is nuts.

by wb (not verified)

Wow, 10 years of experience and then recompiling the kernel, nuts. I use rh7.1 and I simply tell it to enable the soundcard, (mind you THE soundcard), but no kidding, most distro's come with a kernel with all modules allready compiled and they generally have some utility (on rh7.1 eg. you can run "setup" from the command line and then a liitle graphical install menu starts in which you you can , among others, configure your soundcard provided your soundcard is supported and most are) for conveniant soundcard configuration, but (I have a sb-live value) generally it is allready recognized during installation and configured.Look in /etc/modules.conf for a "alias sound-slot-0" entry.

by wb (not verified)

Besides my previous reply, I wanted to add that if y're new to linux, it might be a good idea to read the distro's manual for configuration options, simple things like sound support are generally well explained. As far as your remarks concerned on AA, if you compile xfree4.0.3 or install a distro that contains xfree4.0.3, render support is standard enabled, if applications want to use the render support for AA, they will have to built that in (qt-2.0.3 as distributed by the latest distro's has) and, lucky us, this means kde makes automagically use of that, you only have to check the appropriate box in the kde control center for that. As you see, buy the latest distro or download it from the internet, check use AA for fonts in the kde control center and the xfree86 installer automatically renders your fonts fuzzy. Peace of cookie.

by wb (not verified)

And please don't swear, god can't help it either if you don't read the manual.

by Danny (not verified)

You are a troll, or you completly miss the point. But I'll bite:
It _does_ work out of the box, just by enabling AA in KDEs control panel. But, if you want to configure it so that it does all kind of strange things that are specific for your setup: then you need to edit a file, which is not very difficult to begin with, but in the near future someone will write a nice KDE application that can do this for you.

As for adding a soundcard: in most distros this is
easy, if not that you either have an outdated distro, or you use a soundcard which is not supported due to lacking documentation of the manufacturer. Btw, this is offtopic on this list.

Danny

by Robert Gelb (not verified)

Come on. If it were as simple as setting a checkbox (and believe me, it's been tried), we wouldn't see various & numerous articles explaining how to turn it on.

As far as the soundcard, it was motherboard-based and was supported by a commercial vendor that required that the kernel be recompiled.

But you are right, time for a new distro.

I am having a strange experience with AA and KDE.
When I run kde, the fonts are not anti-aliased. But if I run gnome1.4 and then run a kde app, say konqueror, the fonts are anti-aliased! Has anyone seen this strange behaviour? Any tips to fix this?

by Waldo Bastian (not verified)

Yes, go to the Control Center->Look&Feel-Style and turn anti-aliasing on.

It's off by default since it causes crashes in some setups.

Cheers,
Waldo

by svu (not verified)

Can I use AA with XFS (font server)?
I'd like to use the single set of TT fonts on several machines.

by Rex Dieter (not verified)

AA is controlled via the XftConfig file, which requires one to list the directories in which ttfonts live.

So if you want to use AA, the short answer is no, you can't use a single set of tt fonts to be distributed via xfs to several machines. You can still use them this way in non-AA mode, however.

by Sergey Holod (not verified)

Hi All!!!

I can't say that I have problems with AA but
strange feature is. I can't see any raster fonts
in any font-choose dialogs in any kde apps.
When some app try to use for example 'fixed'
font in gets first truetype font and use it.
I wonder, if It is normal.

Best Regards!!!!

Well, Xft is not supporting bitmapped fonts yet...

Danny

by augustmiles (not verified)

This must be slightly more complicated!
It does not work here with KDE, it does work
with xterm's.

I have X4.0.3. KDE2.1.2 with QT downloaded
from the kde web site. RENDERER is shown
from xdypinfo

Under preferences I have selected
"Use anti-aliasing..." in the style section.

I re-logged out, rebooted.

Xterm's are antialiased but not KDE.
(for instance I can do
xterm -fa courier -fs 10 and check with
xmag)
hmmmm.

by Paul Boddie (not verified)

If xterm exhibits anti-aliasing then you can be sure that Xft is working. However, even if you have the anti-aliasing option set in the KDE control panel, you still need to be using a version of Qt which has been compiled/configured to use Xft.

It's quite possible that the Qt distribution you downloaded is not configured to use Xft; I solved this problem by recompiling the source, since I had the source anyway. (Can you even get the X11 version without source?) The supplied configure program should automatically detect Xft support, although you can force this option manually.

KDE should use anti-aliasing once you've replaced those Qt libraries. (I stopped X while I replaced them to make absolutely sure that nothing would screw itself up in the process.) Just make sure you backup your old libraries, or put the new versions somewhere else (before the old versions) on your library path. Then, experience the fun of configuring fonts...

by straightjacket (not verified)

Open XftConfig and add the following
#
# Don't antialias Konqueror medium fonts
#
match
any pixelsize < 18
any pixelsize > 7
edit antialias = false;

note: I have 10 as my default size and 8 as my min size so these values may have to be tweaked to your satisfaction.