Re: Pango FontDescription -> FontMetrics: HOW?



Thanks for your answer,
that seemed to work indeed...
until i changed the font size in my gtk rc file and realized that the size of my widget remained unchanged whatever the size of my font is..

so this solution does not seem to take into account the widget font size?

(as a reminder, i wanted to access the FontMetrics associated to the style of the widget and what i could get was the FontDescritiption (Pango))

Thanks for your help

Yannick


On Nov 29, 2007 4:08 PM, Paul Davis <paul linuxaudiosystems com> wrote:
On Thu, 2007-11-29 at 15:06 +0100, Yannick Barbeaux wrote:
> Hi,
>
> I want to get_approximate_char_width() so as to limit the width of a
> widget (TreeView) according to a given number of characters.
> The problem is I access the current font for a given widget in this
> way:

this might give you some hints:

void
Gtkmm2ext::get_ink_pixel_size (Glib::RefPtr<Pango::Layout> layout,
                              int& width,
                              int& height)
{
       Pango::Rectangle ink_rect = layout->get_ink_extents ();

       width = (ink_rect.get_width() + PANGO_SCALE / 2) / PANGO_SCALE;
       height = (ink_rect.get_height() + PANGO_SCALE / 2) / PANGO_SCALE;
}

void
Gtkmm2ext::set_size_request_to_display_given_text (Gtk::Widget &w, const
gchar *text,
                                                  gint hpadding, gint vpadding)

{
       int width, height;
       w.ensure_style ();

       get_ink_pixel_size (w.create_pango_layout (text), width, height);
       w.set_size_request(width + hpadding, height + vpadding);
}





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