Determining the width of a GtkTextView in characters
- From: Eduardo M KALINOWSKI <ekalin bol com br>
- To: Gtk <gtk-app-devel-list gnome org>
- Subject: Determining the width of a GtkTextView in characters
- Date: Sat, 11 Jun 2005 18:31:32 -0300
Hi,
I have a GtkTextView whose contents is all in one font, a monospaced
font by the way. I want to know the width of the GtkTextView in
characters, that is, how many characters fit in a line. I've tried a
code like this:
GtkAllocation allocation;
PangoFont *font;
PangoFontDescription *fontdesc;
PangoFontMetrics *metrics;
int char_width;
allocation = GTK_WIDGET(txtView)->allocation;
/* Actually loads the correct font, stored in a variable */
fontdesc = pango_font_description_from_string("Monospace 10");
font =
pango_context_load_font(gtk_widget_get_pango_context(GTK_WIDGET(txtView)),
fontdesc);
metrics = pango_font_get_metrics(font, NULL);
char_width =
PANGO_PIXELS(pango_font_metrics_get_approximate_char_width(metrics));
columns = allocation.width / char_width;
However, the value of columns is smaller than the real value. For
example, with a width of 80 characters, the value returned is 71. How
can I do that?
--
Marriage, n.:
The evil aye.
Eduardo M KALINOWSKI
ekalin bol com br
http://move.to/hpkb
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]