(?) The Answer Gang (!)
By Jim Dennis, Ben Okopnik, Dan Wilder, Breen, Chris, and... (meet the Gang) ... the Editors of Linux Gazette... and You!


We have guidelines for asking and answering questions. Linux questions only, please.
We make no guarantees about answers, but you can be anonymous on request.
See also: The Answer Gang's Knowledge Base and the LG Search Engine



(?) Font rendering with GTK-2.0

From Thomas Adam

Answered By: Thomas Adam, Ben Okopnik, Bradley Chapman, Robos, Kapil Hari Paranjape

Hello TAGgers,

I am wondering if someone can help. I am having a rather interesting font issue at the moment with gtk2 apps, in that the font it uses to display in its menus, etc is not what I would like...it looks weird to me. I think the font in question is monospace but I am uncertain.

I cannot determine from using "editres/xdpyinfo/FvwmIdent" what font is being used and it is beginning to annoy me. I have tried adding:

gtk-font-name = "Sans 10 Bold"

as a crude test to: ~/.gtkrc-2.0 but this has had no effect in changing the font even when re-starting the application(s) in question. I have checked the BTS but nothing has been that useful. I am now thinking it might be a pango problem but I wouldn't know.

Ideally it would be nice if I could get the same font that gtk+-1.2 uses since I have had no problems with the font those apps use in their menus, etc.

Ideas would be welcome.

(!) [Bradley] I added:
gtk-font-name = "Luxi Sans 10"
This is what I added to my rc file and the GTK2-2.2.4 libraries that Firebird is currently using seem to honour it. Have you tried updating your GTK2 libs?

(?) Yes, I have updated them, I'm running sid so everything is bang up to date in that respect. Still no luck. I do though get the following errors printed to stdout:

Fontconfig warning: line 248: invalid edit binding "same"
Fontconfig warning: line 260: invalid edit binding "same"

According to the BTS, this error is supposedly fixed by making sure you only have one fontconfig lib installed, well, I do.

(!) [Bradley] You could try checking your GTK+-1.2 libraries to find out where their defaults are stored and then just match the font name & size decls in your GTK2 config.

(?) I fixed it in the end. I found out the defoma (DEbian FOnt MAngler) was causing all kinds of weird aliases that pango was then having trouble parsing. The fonts were the defaulting to an ugly monospace-9 font which looked horrid.

Ok, so defoma really is: DEbian FOnt MAnager, but I couldn't resist it :) -- Thomas Adam
(!) [Ben] Thomas, at some point in the sweet by-and-by, you ought to write an article on that whole system. As far as I'm concerned, you two are chatting in a particularly obscure dialect of Gibberish (and that's not a comment on what you're saying but on how well I'm understanding it. :)
(!) [Thomas] Heh, I did take notes[1]
[1] If you think gibberish is correct, you should try and interpret my handwriting.
(!) [Ben] Twiddling the font system is something I've done in the past - successfully, in some cases - by the "close your eyes, hit it with a baseball bat, run away, and read about the effect in tomorrow's papers" method.
(!) [Thomas] "O p n k. Ben plays with fonts"
I think we can say that looks like an appropriate header for tomorrow's newspapers.
(!) [Ben] As far as understanding it goes, uh-uh. Well, I actually know of a few things that do some things :), but I have no idea how the whole shmear does what it does, or even what it really does - and that's before we even mention console fonts, which seem to be a completely unrelated (and nearly as complex) system.
(!) [Thomas] Console fonts are very interesting. These are almost certainly controlled by locales (which in turn also dictate the font you need to use under X11 as well). As to how they are rendered, this is something that I have been looking into. I have to go and see a psychiatrist first though -- its just about done my head in.
(!) [Ben] Yeah, I can't wait until X is smart enough to be fully UTF8-compliant. I just love UTF8; it chops out a huge chunk of what I see as horrible and unnecessary complexity. Admittedly, the mess grew out of a need - but that's no longer current, hasn't been for a long time, and the mess is still with us.
(!) [Ben] At some point, I read some HOWTO that attempted to "explain" it all in a short, easy, step-by-step 27,500-page memo. When it got to the point about "fonts don't really define what characters look like, they just kinda hint at a glyph set which sorta doesn't mean anything either - except when it does", I had to walk off whistling with my hands in my pockets. Otherwise, I'd have gone looking for that baseball bat again.
(!) [Thomas] GTK2/pango/freetype all work in tandem with each other. The way fonts are displayed is dictated by pango which helps render them (it's actually used for internationalisation of fonts as well).
(!) [Robos] My latest incident: tried some program on my agenda vr3 pda (which I know not as much about as I would like) and the proggy proclaims: font "9x15" not known to X server (or something). Yeeeesss, ok, this is a pda! No debconf, no xfontsel or something. How the heck do I figure out what fonts are there and what their names are without later being able to write an xserver myself? Yes, X. Like in "the X files". Maybe that was their initial idea: molder and scully try to find out what fonts are installed....
(!) [Kapil] I do know that applications that try to load fonts directly from X (rather than using a toolkit / themekit like GTK) will find any font that is also found by "xlsfonts". So on my machine (slightly(!) more disk space than a PDA) I get:
command: $ xlsfonts -fn "9x15"
output:	-misc-fixed-medium-r-normal--15-140-75-75-c-90-iso8859-1
	9x15
So 9x15 is an alias for the font described in the first line of output.
You too (yes you Robos!) can define your own aliases as follows.
  1. Create a directory called (say) "$HOME/myfonts".
  2. Put whatever X fonts (AFAIK this means only BDF and PCF fonts). For example you can link the "real" fonts from wherever these are.
  3. Run "mkfontdir $HOME/myfonts", this will create fonts.* files.
  4. Create an fonts.alias file as follows. Copy any line in the fonts.dir or fonts.scale files into this file and replace the name of the file (first entry in the line) by the alias you want to use.
  5. Run "xset +fp $HOME/myfonts".
(!) [Thomas] Don't forget also to run:
xset fp rehash


This page edited and maintained by the Editors of Linux Gazette
Copyright © its authors, 2004
Published in issue 100 of Linux Gazette March 2004
HTML script maintained by Heather Stern of Starshine Technical Services, http://www.starshine.org/


[ Table Of Contents ][ Answer Guy Current Index ] greetings   Meet the Gang   1   2   3   4   5   6   7 [ Index of Past Answers ]