Re: determining character width



On 13 Jul 2002, Havoc Pennington wrote:

(re. geting the pixel width of a monospaced font in gtk-2.0)

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.

I can't get the right answer out of this approach.  When I do width =
pango_font_metrics_get_approximate_char_width (metrics); then
PANGO_PIXELS(width) is giving me 8, when I know that glyphs plus
side-bearings are 7 pixels wide in the given font.

Allin Cottrell.





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