Re: pango text size
- From: Richard Boaz <riboaz xs4all nl>
- To: Jose Hevia <jose francisco hevia gmail com>
- Cc: gtk-list gnome org
- Subject: Re: pango text size
- Date: Wed, 29 Mar 2006 16:30:21 +0200
hi,
i have no idea if i do this correctly myself (comments?), but the way
i have achieved this is with the following code:
int fontSIZE(char *str, gboolean type)
{
int width, height, ret;
PangoFontDescription *desc;
PangoLayout *layout = pango_layout_new (gtk_widget_get_pango_context
(widget /* drawing area, e.g. */));
pango_layout_set_text(layout, str, -1);
pango_layout_set_font_description(layout, desc);
pango_layout_get_pixel_size (layout, &width, &height);
switch (type)
{
case HEIGHT:
ret = height;
break;
case WIDTH:
ret = width;
break;
}
g_object_unref (layout);
return(ret);
}
but i'm with you, it would seem to me there should be an easier way
of getting these values, in that, requiring to know the width/height
of a string strikes me as crucial information if you're rendering
text to a drawing area where the location of other stuff in the
drawing area is dependent on the size of other displayed text.
good luck, and if anyone else has any more interesting/correcter
information on this subject, i would also be very interested.
cheers,
richard
On Mar 20, 2006, at 3:38 PM, Jose Hevia wrote:
Hello,
I need to know the size of chars(width,height) written in a text view,
so I could calculate the number of "words" per line I could write.
So I downloaded "gnome-terminal" source code to see if I could
understand how can it do it, but I'm little confused.
I just want to know the width and heigth of a given monospace font
cell, looking at the documentation I only found:
pango_font_metrics_get_approximate_digit_width()
[ http://developer.gnome.org/doc/API/2.0/pango/pango-
Fonts.html#id2931730 ]
but I need the fontmetrics, I can get the metrics from a fontset, but
how do I get the fontset?
gdk functions that do it are deprecated.
Seems too complicated for something so simple.
Do you know a good pango tutorial/ebook that covers this? Any simple
program that already do this with viewable code?
Jose Hevia
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]