Re: text size in pango



I think you need something like this:

PangoLayout *layout;
PangoFontDescription *font;
...
create Pango layout and font
...
pango_layout_set_font_description(layout, font);
PangoRectangle pos;
pango_layout_set_text(layout, s, len);
/* s should be in UTF8 I think */
pango_layout_index_to_pos(layout, len, &pos);
int width = PANGO_PIXELS(pos.x);
return width;

I admit this is a bit convoluted compared to gdk_text_width() but there
might be a simpler way which I do not know about (IANAPE *)

The Pango guys can give you a better idea if the above does not work, so
CC-ing them.

Rgds,
Biswa.

(*) I am not a Pango expert :-)

> Am Mit, 2003-05-07 um 07.23 schrieb Evan Martin:
> > On Wed, May 07, 2003 at 02:08:06AM +0200, Fritz Ganter wrote:
> > > I draw my text with gdk_draw_layout_with_colors, but need to know the
> > > size of the string. In GTK-1.2 I did this with
> > > k = gdk_text_width (smalltextfont, txt, strlen (txt));
> > > I need the same in pango, to draw a box around it and to position the
> > > text on the graphic.
> >
> > Look at the "Text Handling in GTK 2" section of
> > http://developer.gnome.org/dotplan/porting/
> I read it, but can't find the functions:
> If found here
> When asking for text metrics, such as the size of a PangoLayout, you'll
> notice that all Pango objects have a "logical size" and an "ink size."
> The logical size corresponds to the font metrics (ascent and descent),
> and should be used to position text. The logical size for a line of
> text...blablub
> 
> But with which function to use?
> 
> People, GTK2 is really cool, but documentation of this pango stuff is
> poor.
> 3 lines of example code would save hours of searching for docu. In
> gtk-demo is nothing about it.
> 
> 
> --
> Fritz "der mit dem Linux tanzt" Ganter         http://www.kraftvoll.at
>  Key fingerprint = 555A DDBB 3985 16FF CD41  2031 C485 1783 BF34 728F
> 
> 
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
> 
> 




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