Anyway, here's a piece of code that I wrote in the process of fixing things.
/**
* Pick the first available monospace font in a widget's
* Pango context
*/
bool
get_monospace_font(Pango::FontDescription& font, Gtk::Widget& w)
{
bool success = false;
if (Glib::RefPtr<Pango::Context> ctxt = w.get_pango_context())
{
Glib::ArrayHandle<Glib::RefPtr<Pango::FontFamily> > ff =
ctxt->list_families();
Glib::ArrayHandle<Glib::RefPtr<
Pango::FontFamily> >::const_iterator
i = ff.begin(), end = ff.end();
for (; i != end; ++i)
{
if ((*i)->is_monospace())
{
font = Pango::FontDescription((*i)->get_name());
w.ensure_style();
if (Glib::RefPtr <Gtk::Style> style = w.get_style())
{
font.merge(style->get_font(), false);
}
if (Glib::RefPtr<Pango::Font> f = ctxt->load_font(font))
{
font = f->describe();
}
success = true;
break;
}
}
}
return success;
}
Note to self: write a sed script for "fixing" templates and pointers in code snippets posted on this blog.
Second note to self: make a custom T-shirt on Zazzle, printed with said sed script.
No comments:
Post a Comment