Re: fonts in gtk-2.0/pango



Allin Cottrell <cottrell wfu edu> writes:

> My first observation is that the handling of font metrics seems to be
> broken in gtk-2.0/pango.  I base this on two sorts of experiment.
> 
> (1) The pango font metrics apparatus fails to return correct metrics
> for a known monospaced font (e.g. Lucida Typewriter).  The only
> function for getting the width of a character directly (i.e. short of
> creating a pango layout and measuring its size in pixels) is the
> "approximate" char_width function.  In the Lucida Typewriter case,
> where no "approximation" is called for since every glyph has the exact
> same width, the value returned is out by 14 percent (8 instead of the
> correct 7 pixel width on my system).  This is just not good enough,
> for purposes such as sizing windows that are to hold a given length of
> line in monospaced characters.  It is a marked regression from the old
> GdkFont mechanism, which gave accurate metrics with a single function
> call.

If you believe a font is monospaced, then you can determine it's
width by asking for the width of any character.
 
> (2) GTK 2.0 seems to have trouble choosing a suitable default font for
> menus, labels and so on.  I have tried GTK 2.0 on three systems, and
> on two out of three the default font has been unacceptable.  On a
> linux box running X at 800x600 resolution the default font was tiny
> and unreadable.  I was able to correct this by forcing the font to
> "Sans 12" in ~/.gtkrc-2.0.  On a Windows 98 box running at 1024x768
> the default font was much too big and clunky. On another Linux box
> running at 1024x768 the default was fine.  But my point is that gtk
> 1.2 produced a consistent look on all three systems without any need
> to fiddle with rc files.  GTK 2.0 doesn't seem to understand the
> relationship between font size and screen resolution / dpi.

It does, that's your problem. :-) GTK+-2.0 in its default configuration
bases font size on screen DPI.

I've been moving toward using a fixed DPI in recent Red Hat configuration
(set the Xft.dpi property, or you can do it in your XftConifg,
fonts.conf) because:

 - It's angular resolution rather than linear resolution that matters
   for legibility.
 - Monitors often get misprobed by X (sometimes dramatically wrong)
 - Unless you are scaling all elements of the GUI, scaling just
   the fonts can mess up designs.
 
> Second observation: Pango has an elaborate classification system for
> fonts, but this system has some serious blind spots.  So far as I can
> tell, Pango maintains no record of whether a font is monospaced or
> proportional.  (I believe the X11 backend to pango reads this
> information when it queries the X server for available fonts, but then
> throws it away.)  I presume this has something to do with its failure
> to provide correct metrics for Lucida Typewriter.  I presume, too,
> that it has something to do with the removal of the "filter" mechanism
> on the GTK font selection dialog between 1.2 and 2.0.  That is, you
> used to be able to specify that the font selection should show only
> monospaced fonts (rather essential for terminal/console type
> applications) but you can't any more -- I guess, because pango has no
> notion of what's a monospaced font and what's not.

Give us code that can distinguish reliably between monospaced and
not-monospaced fonts for Type1 and TrueType fonts and at that
point it becomes reasonable to think about such an API. It's
not all that easy to do.

Even then, there are still problems - Pango by default will
draw characters not in the main font using fallback fonts --
whose metrics almost certainly don't match your grid. So,
you'd have to be able to turn this off.
 
> Third observation: I'm on less sure ground here -- I may have missed
> something in the API -- but in the course of experimenting with fonts
> I've tried adding a font selection dialog hooked up to a call to
> gtk_widget_modify_font() on the main application window.  I can verify
> that the selection is working, in the sense that the chosen font is
> correctly recorded in the application's config file (and correctly
> printed to stdout in real time), but the gtk_widget_modify_font() call
> accomplishes nothing: the font remains unchanged.  (It is changeable
> via a modification to ~/.gtkrc-2.0 and a restart of the app.)

Test case? modify_font() definitely works in general.

Regards,
                                        Owen




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]