HOWTO: Nice fonts

I run a light desktop, currently openbox, and prefer to set things up through config files rather than relying on settings managers.

In the case of fonts, this allows much more refined control, consistent across all apps, system wide. It's possible to control settings per font family, per weighting, per point size, to remap fonts, to supply preferences/fallbacks for unavailable fonts etc.

'Nice fonts' is of course subjective, and can depend on monitor type, geometry, dpi, antialiasing/hinting preferences etc, but here's my ~/.fonts.conf to use as a starting point. Copy it to your home directory, rebuild freetype2 if you need to, install the relevant fonts, run fc-cache, reboot/restart X and tweak from there...

XML:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

    <!--
        install ==> print/freetype2 [WITH_LCD_FILTERING=yes and assumes BCI not disabled]
        install ==> x11-fonts/dejavu
        install ==> x11-fonts/webfonts
        install ==> x11-fonts/terminus-font
    -->

    <!-- reject all bitmap fonts, with the exception of 'terminus' -->
    <selectfont>
        <acceptfont>
            <pattern>
                <patelt name="family"> <string>Terminus</string> </patelt>
            </pattern>
        </acceptfont>
        <rejectfont>
            <pattern>
                <patelt name="scalable"> <bool>false</bool> </patelt>
            </pattern>
        </rejectfont>
    </selectfont>

    <!-- preferred aliases -->
    <alias> <family>serif</family>
        <prefer>
            <family>DejaVu Serif</family>
        </prefer>
    </alias>

    <!-- preferred aliases -->
    <alias> <family>sans-serif</family>
        <prefer>
            <family>DejaVu Sans</family>
        </prefer>
    </alias>

    <!-- preferred aliases -->
    <alias> <family>monospace</family>
        <prefer>
            <family>DejaVu Sans Mono</family>
            <family>Terminus</family>
        </prefer>
    </alias>

    <!-- default quality settings -->
    <match target="font">
        <edit mode="assign" name="rgba">      <const>none</const>     </edit>
        <edit mode="assign" name="antialias"> <bool>true</bool>       </edit>
        <edit mode="assign" name="autohint">  <bool>true</bool>       </edit>
        <edit mode="assign" name="hinting">   <bool>true</bool>       </edit>
        <edit mode="assign" name="hintstyle"> <const>hintfull</const> </edit>
    </match>

    <!-- reduce ringing ==> requires freetype2 'WITH_LCD_FILTERING=yes' -->
    <match target="font">
        <edit mode="assign" name="lcdfilter"> <const>lcdlight</const> </edit>
    </match>

    <!-- disable autohinting for bold fonts -->
    <match target="font">
        <test compare="more" name="weight">   <const>medium</const> </test>
        <edit mode="assign"  name="autohint"> <bool>false</bool>    </edit>
    </match>

    <!-- disable autohinting for fonts that don't need it -->
    <match target="pattern" name="family">
        <test qual="any" name="family">
          <string>Andale Mono</string>
          <string>Arial</string>
          <string>Arial Black</string>
          <string>Comic Sans MS</string>
          <string>Courier New</string>
          <string>Georgia</string>
          <string>Impact</string>
          <string>Trebuchet MS</string>
          <string>Tahoma</string>
          <string>Times New Roman</string>
          <string>Verdana</string>
          <string>Webdings</string>
       </test>
       <edit mode="assign" name="hinting">  <bool>true</bool>  </edit>
       <edit mode="assign" name="autohint"> <bool>false</bool> </edit>
    </match>

</fontconfig>

Make sure your '.gtkrc-2.0' is including your personal '.gtkrc.mine'...
Code:
include "/home/mart/.gtkrc.mine"

And that your '.gtkrc.mine' contains font settings...
Code:
style "user-font"
{
    font_name = "Sans 9"
}
widget_class "*" style "user-font"

gtk-font-name = "Sans 9"

Finally, make sure firefox font preferences are set to defaults (ie. serif/sans-serif/monospace - no named fonts as fonts.conf takes care of all that properly).

Remember I'm not using a settings manager. If you are (check with ps aux) then make sure your manual settings aren't being overridden.

With these settings I have a very clean looking desktop, with crisp fonts that look good in all apps, and on all websites I visit, and gives me my beloved terminus for terminals :)

I'd be interested in seeing what others have in addition to these settings...
 
Last edited by a moderator:
You know that all that xml-mangling is no longer necessary?

You just have to go to /usr/local/etc/fonts/conf.d and link to all the features you want in /usr/local/etc/fonts/conf.avail.
 
kamikaze said:
You know that all that xml-mangling is no longer necessary?

You just have to go to /usr/local/etc/fonts/conf.d and link to all the features you want in /usr/local/etc/fonts/conf.avail.

Yup, and I've done that in the past, but I ended up going back to this way. I distro swapped quite a lot in the past (work/home-desktop/home-development/laptop), and was always annoyed by config differences between them, particularly when one suddenly decides to change their 'default' *cough* fedora *cough*. Doing things this way means I can quickly sync / move over my full environment, even across OSs (I still run Arch on my laptop and core dev machine).

Still, each to their own :) If you're happy with the default granularity provided, and don't think you'll ever need to transport an environment, then linking files is certainly easier (as is using a gui / settings manager).
 
mart said:
Make sure your '.gtkrc-2.0' is including your personal '.gtkrc.mine'...
Code:
include "/home/mart/.gtkrc.mine"

And that your '.gtkrc.mine' contains font settings...
Code:
style "user-font"
{
    font_name = "Sans 9"
}
widget_class "*" style "user-font"

gtk-font-name = "Sans 9"
I'd like to try but where is gtkrc-2.0?
 
If it's not there you have to create it in your home directory. And it is .gtkrc-2.0. Do not forget about the ..
 
Hi,

I had to remove the "quality settings" part otherwise the fonts are getting kinda bold here and much more grainy.

I also lost the ability to continue using bitmap fonts like Lucida Typewriter (ok this is how it is now configured in .fonts.conf). But I definitively want my Lucida Typewriter font back ;)
I saw, that there are Lucida TTF fonts shipped togther with jdk 1.6 so I tried using them by adding

FontPath "/usr/local/jdk1.6.0/jre/lib/fonts/"

to my xorg.conf without success
I also tried fc-cache -v -f /usr/local/lib/X11/fonts /usr/local/jdk1.6.0/jre/lib/fonts which prints out:

[...]
/usr/local/jdk1.6.0/jre/lib/fonts: caching, new cache contents: 8 fonts, 0 dirs
[...]

I also tried to generate a fonts.scale using ttmkfdir but all that gave me no Lucida Typewriter font back... Any idea how I get this font back?
 
oliver@ said:
I had to remove the "quality settings" part otherwise the fonts are getting kinda bold here and much more grainy.

Sounds like you prefer sharper (ms-style) fonts, without much antialiasing. Nothing wrong with that. However, once things are working a bit better for you, you might want to play around with the quality settings rather than disabling them completely. Some combinations work better for certain dpi, monitor types etc.

[ BTW: if you prefer sharp (ms-style) fonts, then you might find this interesting. I tend to have my settings somewhere in-between as I swap machines/monitors quite a lot ]

oliver@ said:
I also lost the ability to continue using bitmap fonts like Lucida Typewriter (ok this is how it is now configured in .fonts.conf). But I definitively want my Lucida Typewriter font back ;)

Easy enough. The accept/reject section works like a whitelist/blacklist. I blacklisted all bitmap fonts except Terminus, and you'd want to do the same for Lucidia (i.e. add Lucidia to the accept section, under Terminus).
 
mart said:
Sounds like you prefer sharper (ms-style) fonts, without much antialiasing. Nothing wrong with that. However, once things are working a bit better for you, you might want to play around with the quality settings rather than disabling them completely. Some combinations work better for certain dpi, monitor types etc.

[ BTW: if you prefer sharp (ms-style) fonts, then you might find this interesting. I tend to have my settings somewhere in-between as I swap machines/monitors quite a lot ]

The fonts at sharpfonts.com should be the fonts installed by webfonts already... right?

One Question regarding the font "DejaVu Sans" - The font looks extremely ugly. I normaly have a black font. Choosing this font it gets "coloured" (probably because of anti aliasing) . I mean I see green and read portions in the font and the font is extremely thin too... Is this intended?
 
They're the webfonts, yes - I guess the interesting part is that they also bundle some fontconfig settings files.
 
Is there a way to allow Lucida* fonts? When entering "Lucida" as acceptfont I don't get the other fonts from the family. Are (and if: what) wildcards are supported?
 
oliver@ said:
The fonts at sharpfonts.com should be the fonts installed by webfonts already... right?

Yes, webfonts has everything you need except the config(s). I mentioned the site as it highlights the two extremes, and provides example configs to go 'sharp' if that's what you prefer.

oliver@ said:
One Question regarding the font "DejaVu Sans" - The font looks extremely ugly. I normaly have a black font. Choosing this font it gets "coloured" (probably because of anti aliasing) . I mean I see green and read portions in the font and the font is extremely thin too... Is this intended?

DejaVu is (to me) an excellent font for general use. So much so that I use it as the exclusive preferred font for Sans and Serif (see config). It seems others find it pleasant too (see http://www.codestyle.org/css/font-family/sampler-UnixResults.shtml).

It shouldn't be 'extremely thin'. If it is, you probably want to use, and understand, the quality preferences a bit better (poor combination of hinting/antialias settings, among others, could lead to incorrect spacing etc).

Sadly, the css site above does not have an image for DejaVu, but there's one for Bitstream Vera which is very similar (see http://www.codestyle.org/servlets/FontSampler?image=unix-BitstreamVeraSansMono&class=BitstreamVeraSansMono&font=Bitstream+Vera+Sans+Mono - the Normal/Bold/Italic section is an image and your text should look similar, or even better).

It shouldn't be 'coloured'. If it is, then I suspect incorrect 'rgba' settings for your monitor, and/or not having freetype2 compiled with 'WITH_LCD_FILTERING=yes' (see 'ringing' comments in original post). Having suitable/complementary hinting settings will also help.

oliver@ said:
Is there a way to allow Lucida* fonts? When entering "Lucida" as acceptfont I don't get the other fonts from the family. Are (and if: what) wildcards are supported?

If your pattern says 'family' then it should accept 'family' (see http://fontconfig.org/fontconfig-user.html). What other fonts from the family are missing? What are you doing to test that they are missing?

It might help to provide info about your setup (reported monitor geometry/reported dpi etc), and what it is you don't like about the default font settings.
 
I personally don't consider Dejavu or Bitstream font families attractive fonts. Personally, I prefer either the Liberation type face or Microsoft's. The Sharpfonts package includes Tahoma, which webcore doesn't.
 
I tried to use 'WITH_LCD_FILTERING=yes'to build freetype2,but still it seems the "lcdfilter" doesn't work any more
 
hintfull? yuck. :P

I'm currently using hintslight with the LCD patches. I can honestly say that these are the nicest looking fonts I have ever seen.

dybnu said:
I tried to use 'WITH_LCD_FILTERING=yes'to build freetype2,but still it seems the "lcdfilter" doesn't work any more

Yes. This is because this only enables the LCD patches in freetype, while other libraries which should use it are not also patched. Here's how I installed it (warning, very hackish):

Compile print/freetype2 with WITH_LCD_FILTERING:

Code:
cd /usr/ports/print/freetype2
make -DWITH_LCD_FILTERING deinstall reinstall clean

Now you should add the setting to fontconfig. The easiest way to do this is to download a copy of 10-lcd-filter.conf (I got mine from here) and save it to /usr/local/etc/fonts/conf.avail/10-lcd-filter.conf. Then, if you want these settings to be system-wide, symlink it to conf.d/10-lcd-filter.conf.

Now cairo needs to be patched to use the freetype LCD patches. First, download lcd-filter.patch from here. Then you need to cd /usr/ports/graphics/cairo/ && make deinstall if it's already installed.

I didn't edit the actual port when I was doing this, so here are the instructions to manually patch it:

Code:
cd /usr/ports/graphics/cairo/
make extract
cd work/cairo-1.8.8/
patch -p1 </where/you/saved/lcd-filter.patch

Now, there's still one thing that needs to still be changed before cairo can be rebuilt. cd to src and edit cairo-ft-font.c by changing the line

Code:
if (options->base.hint_style == CAIRO_HINT_STYLE_DEFAULT)
to
Code:
// if (options->base.hint_style == CAIRO_HINT_STYLE_DEFAULT)

Now you finish up cairo by running

Code:
cd /usr/ports/graphics/cairo
make build install clean

You should be able to specify lcdfilter in your ~/.fonts.conf now. I am currently using these hinting settings:

Code:
<!-- Font Display Settings -->
<match target="font" >
    <edit mode="assign" name="rgba" >
        <const>rgb</const>
    </edit>
</match>
    <match target="font" >
    <edit mode="assign" name="hinting" >
        <bool>true</bool>
    </edit>
</match>
<match target="font" >
    <edit mode="assign" name="hintstyle" >
        <const>hintslight</const>
    </edit>
</match>
<match target="font" >
    <edit mode="assign" name="antialias" >
        <bool>true</bool>
    </edit>
</match>
<match target="font" >
    <edit mode="assign" name="lcdfilter" >
        <const>lcddefault</const>
    </edit>
</match>

Here's a screenshot of Helvetica from a Google search: http://imagebin.ca/img/K4vqp5s.png

I'm also using a screen with 129 DPI, so my fonts may look a bit large on some lower DPI screens. Don't worry, these patches still look good on lower DPIs as well. I use these same patches on my desktop with 96 DPI.
 
Hi,

I'd really like to try your lcd fonts technique by following the instructions you wrote on the `Nice Fonts post'. I am however, a bit confused. I'm somewhat new to tweaking fonts with xml files. I've done something like this before on one of my machines running Gentoo Linux, and had gotten some pretty good results with fonts. I've never been able to achieve those kind of results with FreeBSD, even though I've been using FreeBSD for several years.

If I followed your instructions from that post, do I just put your section of that xml file into ~/.fonts.conf, or do I have to build and add other fonts to /etc/X11/xorg.conf as well? The build procedure and font directories were just different in Gentoo, and I think that's part of what's got me baffled. At this point, the fonts on web pages in Firefox look absolutely horrible.

I understand most of your instructions from that post like patching and rebuilding cairo, etc... but I haven't tried it yet because I want to make sure that I've got proper xml data in ~/.fonts.conf

Could you send me or post what your ~/.fonts.conf looks like so I can gauge this whole issue better, and finally get some decent fonts in FreeBSD?

ThanX
 
anamnesis said:
Hi,

I'd really like to try your lcd fonts technique by following the instructions you wrote on the `Nice Fonts post'. I am however, a bit confused. I'm somewhat new to tweaking fonts with xml files. I've done something like this before on one of my machines running Gentoo Linux, and had gotten some pretty good results with fonts. I've never been able to achieve those kind of results with FreeBSD, even though I've been using FreeBSD for several years.

If I followed your instructions from that post, do I just put your section of that xml file into ~/.fonts.conf, or do I have to build and add other fonts to /etc/X11/xorg.conf as well? The build procedure and font directories were just different in Gentoo, and I think that's part of what's got me baffled. At this point, the fonts on web pages in Firefox look absolutely horrible.

I understand most of your instructions from that post like patching and rebuilding cairo, etc... but I haven't tried it yet because I want to make sure that I've got proper xml data in ~/.fonts.conf

Could you send me or post what your ~/.fonts.conf looks like so I can gauge this whole issue better, and finally get some decent fonts in FreeBSD?

ThanX

The part I pasted was just the hinting settings for your ~/.fonts.conf. Here's a complete fonts.conf with just the hinting settings:

Code:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <!-- Font Display Settings -->
    <match target="font" >
        <edit mode="assign" name="rgba" >
            <const>rgb</const>
        </edit>
    </match>
        <match target="font" >
        <edit mode="assign" name="hinting" >
            <bool>true</bool>
        </edit>
    </match>
    <match target="font" >
        <edit mode="assign" name="hintstyle" >
            <const>hintslight</const>
        </edit>
    </match>
    <match target="font" >
        <edit mode="assign" name="antialias" >
            <bool>true</bool>
        </edit>
    </match>
    <match target="font" >
        <edit mode="assign" name="lcdfilter" >
            <const>lcddefault</const>
        </edit>
    </match>
</fontconfig>

As for your /etc/X11/xorg.conf, you should have the FontPaths set for the fonts you have installed (most of the times, the ports will display a message saying what and how to edit it to add them). Which font packages do you have installed? Can you run % pkg_info -IX font to see what you have installed (this assumes that 'font' is in the package name)?
 
Thanks dude !!!

Success!!!

I got it going and I can't believe my eyes. You're right. These fonts are the best I've every seen! They even blow away Vista and 7's ClearType. The rendering is way better than what I've ever had in various distros of Linux. To me, they're about as equivalent as the vector rasterizer engine of Quartz 2D on my Mac.

Also, I went ahead and left the cairo source intact in the work folder. When I was searching in vi to find that one line to comment out, it got me interested in delving into font development.

See, I'm mainly into kernel and filesystem development and maintenance. I know a little bit conceptually about glyphs and bitmaps, but that's about it. Now, I'm a bit more curiouser and curiouser on the subject.

I'm running FreeBSD 8.0 now, so I've been doing some experimentation with the `Z' fs. Pooled storage. It tanks man!

Anyway, thanks alot for your help on the 'now resolved' font issue.
 
The difference is amazing! The LCD filter with the cairo patch and rejecting bitmap fonts did wonders for my display.

I found a second LCD filtering patch for libXft-2.1.14 here, but I'm not sure if it is necessary. Can anyone explain exactly what it does? I checked the line numbers, applied the patch, and rebuilt and installed x11-fonts/libXft. Everything still works, bit there is no visible difference in the applications I have tried so far. Still looks great.
 
Rather than touch ~/.fonts.conf why not just use ubuntu patches (orig, port)? They even have a patch (orig, port) for lcd filtering on libXft. To use it, e.g. on xterm, add to ~/.Xdefaults
Code:
Xft.rgba: rgb
 
I've been playing with fonts settings recently. I have FreeBSD 8.1-STABLE with port tree updated quite often (at least once a week).

Following this HOWTO, I just made my personal ~/.fonts.conf like:
Code:
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
    <!-- reject all bitmap fonts, with the exception of 'terminus' -->
    <selectfont>
        <acceptfont>
            <pattern>
                <patelt name="family"> <string>Terminus</string> </patelt>
            </pattern>
        </acceptfont>
        <rejectfont>
            <pattern>
                <patelt name="scalable"> <bool>false</bool> </patelt>
            </pattern>
        </rejectfont>
    </selectfont>

    <!-- preferred aliases -->
    <alias> <family>serif</family>
        <prefer>
            <family>DejaVu Serif</family>
            <family>NanumMyeongjo</family>
        </prefer>
    </alias>

    <!-- preferred aliases -->
    <alias> <family>sans-serif</family>
        <prefer>
            <family>DejaVu Sans</family>
            <family>NanumGothic</family>
        </prefer>
    </alias>

    <!-- preferred aliases -->
    <alias> <family>monospace</family>
        <prefer>
            <family>DejaVu Sans Mono</family>
            <family>Terminus</family>
            <family>NanumGothicCoding</family>
        </prefer>
    </alias>

    <!-- default quality settings -->
    <match target="font">
        <edit mode="assign" name="rgba">      <const>rgb</const>     </edit>
        <edit mode="assign" name="antialias"> <bool>true</bool>       </edit>
        <edit mode="assign" name="autohint">  <bool>false</bool>       </edit>
        <edit mode="assign" name="hinting">   <bool>true</bool>       </edit>
        <edit mode="assign" name="hintstyle"> <const>hintfull</const> </edit>
        <edit mode="assign" name="lcdfilter"> <const>lcdlight</const> </edit>
    </match>

</fontconfig>
I use DejaVu fonts for sans, serif and monospace and Nanum fonts for Korean. And I deinstalled, recompiled with "make WITH_LCD_FILTERING" and installed freetype2. I didn't do anything with .gtkrc-2.0 because I don't have it and I don't understand its purpose for my settings.

The result is amazing. I can't be more satisfied than this. The freetype2 renders Truetype fonts beautifully. If I remember correctly, freetype2 starts to support the byte interpreter by default from version 2.4. If you haven't tried it yet, upgrade to it. You'll be amazed.
 
Back
Top