Text-View width (third edition)
- From: Alberto Manuel Brandao Simoes <albie alfarrabio di uminho pt>
- To: GTK-List <gtk-list gnome org>
- Subject: Text-View width (third edition)
- Date: Wed, 16 Jan 2002 14:42:07 +0000
Hello!
Hi, again Havoc, and sorry about bothering you... :)
I am trying to get the width in chars for a text-view with a monospace
font. As I said on an early mail, I'm getting:
test-console (pid:15822): ** WARNING **: Couldn't load font "monospace" falling
back to "Sans"
test-console (pid:15822): ** WARNING **: Couldn't load font "Sans" falling back
to "Sans"
test-console (pid:15822): ** WARNING **: All font failbacks failed!!!!
And the example directory of pango is being correctly installed.
I send the code in attatchment.
Thanks for any help
Alberto
--
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.
gint console_view_get_width(ConsoleView *self, GtkTextTag *tag)
{
PangoFontDescription *fdesc;
PangoFontMetrics *metrics;
PangoContext *context;
GtkWidget *widget;
GValue *value;
int char_width;
int width_in_chars;
// return 0;
widget = GTK_WIDGET(self->text_view);
context = gtk_widget_get_pango_context (widget);
g_object_get(tag, "font-desc", &fdesc, NULL);
metrics = pango_context_get_metrics (context, fdesc, pango_context_get_language (context));
char_width = pango_font_metrics_get_approximate_char_width (metrics);
width_in_chars = widget->allocation.width / char_width;
return width_in_chars;
/* 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. */
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]