LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-08-2004, 11:08 AM   #1
zero0w
Member
 
Registered: Aug 2003
Posts: 76

Rep: Reputation: 15
How-To: Modifying UI font of gtk1 and gtk2 application


Note: This How-To is separated into several posts for clarity and easier reading.

Upgrading to Mandrake Linux 10, I have found that the UI (User interface) font of gtk1.x look rather ugly. Upon searching the web and a little experimenting by myself, I have discovered the trick to modify the UI font for gtk1 and gtk2 applications as well:

Here are my suggestions, as performed under Mandrake 10:

1) Install Microsoft web font thru corefonts package (Optional):
http://corefonts.sourceforge.net/

Mandrake Source RPM build:
http://ben.reser.org/corefonts/

Cabextract 1.0
http://www.kyz.uklinux.net/cabextract.php

2) You have to know what locale environment you are in:
To find out, in terminal you can enter:

$ locale

In English Unicode environment, it is likely en_US.UTF-8,
or in my case en_HK.UTF-8 (English for Hong Kong).

3) The trick to look up the UI font setting is in the directory /etc/gtk and /etc/gtk-2.0, for gtk1 and gtk2 applications respectively:

3.1) For gtk1 application
Eg: Mozilla X11, XMMS, Gimp-1.2.x

Now, the locale environment information you have found in step 2 became useful:

For example, if your locale is zh_TW.big5 (Taiwan Chinese, Big5 Encoding),
then you should look up the file /etc/gtk/gtkrc.zh_TW.big5

In the directory /etc/gtk

There's no such file as gtkrc.en_US.utf-8, so I would guess this means the locale setting will fall back to gtkrc.utf-8, and it does!

Examining /etc/gtk/gtkrc.utf-8 under Mandrake 10 shows this:

Quote:
style "gtk-default" {
fontset = "-*-Nimbus Sans L-medium-r-normal--14-*-*-*-p-*-iso10646-1,\
-*-clearlyu-medium-r-normal--17-*-*-*-p-*-iso10646-1,\
-*-r-*-iso10646-1,*"
}
class "GtkWidget" style "gtk-default"
The string -*-Nimbus Sans L-medium-r-normal--14-*-*-*-p-*-iso10646-1 is the old style for X11 server to display font information, before XFT/fontconfig was born last year. Whereas ,\ is the separator for adding another font.

Hence, if you want to use another UI font in gtk1 apps, you have to look up the name of that font in the old X11 style, which is recorded in the font metafile such as fonts.alias, fonts.dir or fonts.scale. They should be placed in the same directory where the fonts reside, inside the following path:

/usr/X11R6/lib/X11/fonts/
/usr/share/fonts/
/usr/share/fonts/ttf

For example, if I want to use Microsoft Arial font as the UI font for gtk1 apps, with the corefont package (see step 1) installed in this path:

/usr/X11R6/lib/X11/fonts/msttcorefonts/

Then I can look up the old style X11 font information from:

/usr/X11R6/lib/X11/fonts/msttcorefonts/fonts.dir
/usr/X11R6/lib/X11/fonts/msttcorefonts/fonts.scale

Upon examining the file fonts.dir, I have located the font information for Microsoft Arial in X11 style as:

Quote:
arial.ttf -monotype-Arial-medium-r-normal--0-0-0-0-p-0-iso10646-1
arial.ttf -monotype-Arial-medium-r-normal--0-0-0-0-p-0-dosencoding-cp850
.
.
.
Where -is10646-1 and -dosencoding-cp850 are encoding schemes, the font name is basically the same.

Hence the font name for Microsoft Arial (with Unicode encoding) in old X11 style is as this:

-monotype-Arial-medium-r-normal--0-0-0-0-p-0-iso10646-1

Hence you can modify the file /etc/gtk/gtkrc.utf-8 by adding this font name, followed by the separator ,\

Quote:
style "gtk-default" {
fontset = "-monotype-Arial-medium-r-normal--0-0-0-0-p-0-iso10646-1,\
-*-Nimbus Sans L-medium-r-normal--14-*-*-*-p-*-iso10646-1,\
-*-clearlyu-medium-r-normal--17-*-*-*-p-*-iso10646-1,\
-*-r-*-iso10646-1,*"
}
class "GtkWidget" style "gtk-default"
Save the file.
Finished!

Now launch a gtk1 application in en_US.UTF-8 locale and your UI font will look great again.
 
Old 06-08-2004, 11:09 AM   #2
zero0w
Member
 
Registered: Aug 2003
Posts: 76

Original Poster
Rep: Reputation: 15
If you are still with me, here is more detail on UI font modification in gtk1 apps:

3.2) UI font setting in gtk1 apps - ignoring locale

But wait, you don't want to bother about your locale environment, just keep all the gtk1 apps look right no matter what locale (language, encoding) setting I am using!

Sure, you can do this, just make this as a per-user account setting by:

$ cp /etc/gtk/gtkrc.utf-8 ~/.gtkrc

Or you can choose to copy another file in /etc/gtk/ if you knew about your locale environment (such as gtkrc.zh_TW.utf8 which corresponds to the locale zh_TW.utf-8.)

Then modify the file ~/.gtkrc will achieve the same result.

Pay attention to the encoding scheme -iso10646-1, which is for Unicode (utf-8).

However, if you really don't want to bother, you can just put -*-* in place of -iso10461-1, which means use whatever encoding is available from that font. However, you may see square box or garbage in the UI if you use a wrong encoding; or the font does not contain glyphs/characters required in that language.

Of course you can set ~/.gtkrc to use several fonts in a particular locale language. As an example, in a Traditional Chinese environment, you can use Microsoft Arial for English letters and numbers, and then Taipei_Ming for Traditional Chinese, by using the separator ,\ to add more font as you wish.

3.3) Using Adobe Helvetica 12pt

If you don't have or don't want to use Microsoft font, then the Adobe bitmap font Helvetica 12pt (bitmap font has fixed size) is also a good replacement. On Mandrake 10, information on Helvetica 12pt can be retrieved from this file: /usr/X11R6/lib/X11/fonts/75dpi/fonts.dir

Quote:
helvR12-ISO8859-1.pcf.gz -adobe-helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1
Hence the old style X11 font name string for Helvetica 12pt is:

-adobe-helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1

Or simplify it as

-adobe-helvetica-medium-r-normal--12-*-*-*-*-*-*-*
(which ignores encoding and all other information, only the font size -12- matters here)

Hence you can modify the file ~/.gtkrc as:

Quote:
style "gtk-default" {
fontset = "-adobe-helvetica-medium-r-normal--12-*-*-*-*-*-*-*,\
-*-Nimbus Sans L-medium-r-normal--14-*-*-*-p-*-iso10646-1,\
-*-clearlyu-medium-r-normal--17-*-*-*-p-*-iso10646-1,\
-*-r-*-iso10646-1,*"
}
class "GtkWidget" style "gtk-default"
Finish!

Last edited by zero0w; 06-09-2004 at 03:09 AM.
 
Old 06-08-2004, 11:09 AM   #3
zero0w
Member
 
Registered: Aug 2003
Posts: 76

Original Poster
Rep: Reputation: 15
Ok, so much time is wasted on changing UI font for gtk1 apps, now we are moving to gtk2 apps for good.

Example: Gimp 2.0, XSane, Azureus GTK-2+ client, and many more

Since GTK-2.x+ applications has switched to Fontconfig and Pango in processing font encoding and locale information, we no longer need to look up the old style X11 font name string, which probably caused brain damage to a lot of people trying to figure it out in the old days.

Changing UI font for GTK-2.x+ application is very easy, just create or modify this file in the home directory of your user account:

$ vi ~/.gtkrc-2.0

Then add this line:

Quote:
gtk-font-name="Sans 12"
where

Sans is the name of the font you want to use,
12 is the font size

For example, I have chosen Luxi Sans as my UI font for GTK2+XFT Firefox:

Quote:
gtk-font-name="LuxiSans 12"
Notice the space is omitted between "Luxi Sans", sometimes it is the case, sometimes it is not. Try to experiment and find out.

Ok, I think there's enough for now, any questions?
 
Old 06-09-2004, 07:34 AM   #4
IsaacKuo
Senior Member
 
Registered: Apr 2004
Location: Baton Rouge, Louisiana, USA
Distribution: Debian Stable
Posts: 2,546
Blog Entries: 8

Rep: Reputation: 465Reputation: 465Reputation: 465Reputation: 465Reputation: 465
Thank you very much for this detailed explanation! I had been struggling for weeks trying to get Mozilla Firefox and my other gtk* applications running with fonts large enough to read at 1600x1200. My only solution for some time had been to run "gnome-control-center" every time I logged in and manually select the "Font" section...
 
Old 06-11-2004, 01:24 PM   #5
zero0w
Member
 
Registered: Aug 2003
Posts: 76

Original Poster
Rep: Reputation: 15
No problem!
 
Old 07-06-2004, 05:44 AM   #6
webazoid
Member
 
Registered: Jun 2004
Posts: 224

Rep: Reputation: 30
so how do u turn off anti-aliasing in gtk apps? for some reason, my gtk apps (gaim) fonts were extremely small. i tried ur tip for the $ vi ~/.gtkrc-2.0 and it worked, but i can't seem to access the file again a second time as it's gone.

secondly, why are my gtk apps sporadically using anti-aliasing on? i could never tell when it's going to be on or off. is there a way to permanently disable it? thanks. gimp 1.25 looks fine to me so i think it's a prob w/ gtk 2.

happens to firefox, thunderbird, and gaim and occasionally kwrite. changing fonts under mdk 10 font control center doesn't change anything.

Last edited by webazoid; 07-06-2004 at 05:46 AM.
 
Old 07-26-2004, 07:02 AM   #7
zero0w
Member
 
Registered: Aug 2003
Posts: 76

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by webazoid
so how do u turn off anti-aliasing in gtk apps? for some reason, my gtk apps (gaim) fonts were extremely small. i tried ur tip for the $ vi ~/.gtkrc-2.0 and it worked, but i can't seem to access the file again a second time as it's gone.
The file ~/.gtkrc-2.0 should stay there once you created it, unless some other program is trying to delete it on purpose. Just re-create this file and make it read-only (chmod 544 ~/.gtkrc-2.0) if your programs still have problem accessing it.

Quote:
secondly, why are my gtk apps sporadically using anti-aliasing on? i could never tell when it's going to be on or off. is there a way to permanently disable it? thanks. gimp 1.25 looks fine to me so i think it's a prob w/ gtk 2.
You can temporarily disable anti-aliasing by this:
Open a terminal, enter:

$ export GDK_USE_XFT=0

Then enter the program name you want to run there.
However, disabling anti-alising could be problematic to certain programs (and look ugly on many fonts); disable it only when you know what you are doing.

To disable AA permanently, there are two ways to do this. You can read the following links to find out:

1. Disable AA as a per user account setting for GTK/Gnome apps only:
http://mandrakeusers.org/index.php?showtopic=977

2. Disable AA for all GUI application under Xft/Fontconfig:
http://www.mail-archive.com/fonts@xf.../msg01447.html

You can search on Google for a few how-tos on Linux font setup, and understand better about it.

Last edited by zero0w; 07-26-2004 at 07:04 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
The advantage of GTK2 over GTK1? beejayzed Linux - Software 5 10-22-2005 12:08 PM
compiling gtk1 app against gtk2 cs-cam Linux - Newbie 3 01-11-2005 02:53 AM
Gtk1 to Gtk2 jev-bird Linux - Software 0 08-12-2004 02:23 AM
Configuring GTK1.2 over GTK2 Faecal Linux - Software 1 09-29-2003 04:30 AM
Using gtk1 themes with gtk2 apps? n_ick2000 Linux - Software 0 03-30-2003 10:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration