Alberto Manuel Brandao Simoes <[EMAIL PROTECTED]> writes:
> 
>       How can I find the width in chars for a text-view widget? Of course, this
> is only interesting for a monosized typeface!
> 

Something like this:

  PangoFontMetrics *metrics;
  GtkWidget *widget;
  int char_width;
  int width_in_chars;

  widget = GTK_WIDGET (text_view);

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

  char_width = pango_font_metrics_get_approximate_char_width (metrics);

  width_in_chars = widget->allocation.width / char_width;
    
This assumes you have set the monospace font for the text view with
gtk_widget_modify_font(), resulting in a monospace font for
widget->style->font_desc; if not you need to use the font desc of
interest, not widget->style->font_desc.

Havoc

_______________________________________________
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list

Reply via email to