[Gtk-sharp-list] Gtk.Style vs Pango - I'm confused...

Federico Mena Quintero federico@ximian.com
Fri, 17 Sep 2004 20:59:21 -0500


On Thu, 2004-09-16 at 17:52 +0200, Anset wrote:

> I was looking for a way to change the font on a widget and I landed on these
> two.

Gtk.Widget label;
Pango.FontDescription font_desc;

label = new Gtk.Label ("Hello big bold world");
font_desc = Pango.FontDescription.FromString ("sans 50 bold");
label.ModifyFont (fontdesc);

> It looks like Style was there before Pango, but Pango does not replace it.
> Pango does "just text", if you allow the understatement. However Style does
> "text also"...
> 
> One example of something that puzzles me:
> 
> Gtk.Style has a Pango.FontDescription propperty.
> Pango.Context has a Pango.FontDesctiption propperty.
> 
> A Gtk.Widget has both a Gtk.Style and a  Pango.Context propperty.
> 
> So which one do I use to change the Font?

A PangoFontDescription is an object that holds a tuplet with a
particular configuration of a typeface:  ("sans", 10 points, bold).

A GtkStyle is an object that holds the style parameters for a widget.
These include some thickness parameters, colors to use for different
parts of the widget (shadow/normal/light), the font, etc.

Ignore the PangoContext for now; it's just a running instance of the
Pango engine for a particular output device.  You would have a
PangoContext for an X11 display, another one for printing, etc.

You can't build a GtkStyle by hand, because its values come from a bunch
of places:  user resource files, theme files, widget-specific code, etc.
Rather, you take an existing style and modify the bits you need.  This
is nicely wrapped by Gtk.Widget.ModifyStyle().  The Gtk.RCStyle object
you pass to it represents a set of modifications.  The example above is
equivalent to this C code:

  GtkWidget *label;
  GtkRCStyle *rc_style;

  label = gtk_label_new ("Hello big bold world");
  rc_style = gtk_rc_style_new ();
  rc_style->font_desc = pango_font_description_from_string ("sans 50 bold");
  gtk_widget_modify_style (label, rc_style);
  g_object_unref (rc_style);

Right now there seems to be no way to modify the fields of a Gtk.RCStyle
in GTK#.  Fortunately, for your specific needs you can use the
GtkWidget.ModifyFont() method.

  Federico