Nice GTK1 fonts in Ubuntu

Monday, December 15. 2008

Nice GTK1 fonts in Ubuntu

I noticed that GTK1 applications have a rather large and ugly font on my system. I searched the internet for a solution and found references to files like .gtkrc-1.2-gnome and .gtkrc-mine and some font definitions I have to put in there. But none of these solutions worked out for me. I found another reference to the program xfontsel and with all these partial information I was able to find a nice working solution. I hope it will also work for others.

The xfontsel program can be used to find a nice looking font definition which can be used in GTK1 applications. It starts with all filters set to * which means that the filter does not filter anything. I started to configure the filter like this:

  • Click rgstry and select iso10646 because we want the font to have unicode capability.
  • Click wght and select medium because we want the font to be normal and not bold.
  • Click slant and select r because we want a regular style and not italic or underlined.
  • Click spc and select p because we want a proportional font and not a monospaced one.
  • Click pxlsz and select 12 as the font size (At least this one has the best size for me).
  • Click fmly and try out which of the remaining fonts looks best. I choosed Helvetica.

After this procedure my font-definition looked like this:

-\*-helvetica-medium-r-\*-\*-12-\*-\*-\*-p-\*-iso10646-\*

So now we have the font definition but where do we put it? I first tried /.gtkrc which worked for some GTK1 apps but when I tried out lazarus-ide then I still got ugly fonts there. So I checked where this darn program looks for its GTK configuration by using this command:

strace lazarus-ide 2>&1 | grep gtkrc

I did the same with the other GTK1 apps. They all used lots of possible locations for the config file. One generic-looking one was used by all of them, so I decided to use it: ~/.gtkrc-1.2-gnome2.

So copy the definition from xfontsel to the clipboard by clicking the select button and then create the file ~/.gtkrc-1.2-gnome2 and put the following code into it (with your personal font definition):

style "default-text" {
       fontset = "-\*-helvetica-medium-r-\*-\*-12-\*-\*-\*-p-\*-iso10646-\*"
}

Now start a GTK1 application and hope that the font looks as smooth as it does on my system. Here is the difference (Left: Old ugly font, Right: New nice font):

Michael Bronzini at 2009-10-18 18:11
Thank you so much for this piece of information. I've been struggling for years with this issue and this is by far the best solution. And my old solution did not work when I recently installed Ubuntu 9.04 on my new laptop. In the past I have only used Debian and not Ubuntu so I am not sure what is different between the 2. But your solution works in both of them which is great!

The only thing I had to change in your tip was to write the .gtkrc-1.2-gnome2 this way.

style "user-font"
{
fontset = "-*-helvetica-medium-r-*--12-*--*-p-*-iso10646-*"
}

widget_class "*" style "user-font"

Maybe this is what you meant when writing (with your personal font definition)? But nevertheless THANKS FOR THE TIP!!!

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA