Re: text size in pango

On Wed, 2003-05-07 at 05:14, Biswapesh Chattopadhyay wrote:
> 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;

Try instead:

 pango_layout_get_pixel_size (layout, &width, NULL);

And remember to g_object_unref() the layout.

> 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 *)

I don't think it's that much harder -- note that creating the layout
and setting the text/font on it is shared between getting the size
and drawing.


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