Re: determining character width



Allin Cottrell <cottrell wfu edu> writes:
I want to set the width of a text window in characters rather than
fixing it in pixels.  The idea is to supply the function that creates
the window with a width parameter ("hsize") in characters, then the
function computes on the fly the corresponding width in pixels.

In gtk-1.2 I did:

hsize *= gdk_char_width(fixed_font, 'X');

where "fixed_font" is the relevant (monospaced) GdkFont.

I'm trying to figure out how to do this in gtk-2.0, but I'm getting
lost in the complexities of pango.  I guess I need to go from the
current PangoFontDescription to the associated metrics, but there
doesn't seem to be any simple way of doing that.  Any help
appreciated.


Instead of creating a layout and measuring it, maybe you want to get
the font metrics:

  PangoFontMetrics *metrics;
  PangoContext *context;
  
  context = gtk_widget_get_pango_context (widget);
  metrics = pango_context_get_metrics (context,
                                       widget->style->font_desc,
                                       pango_context_get_language (context));

There's a char width field in the metrics.

Havoc




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