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);
}